Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

bbsra.c 22.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/******************************************************************************
BBSRA.C      Implements RemoteAccess-specific BBS functions.

    Copyright 1993 - 2000 Paul J. Sidorsky

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
Deucе's avatar
Deucе committed
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716

The module contains all of the functions for interfacing with RA v2.xx.  It is
also used for some SuperBBS operations that are almost identical to RA.
******************************************************************************/

#include "top.h"

/* ra_init() - Initialize pointers to RA functions.
   Paremeters:  None.
   Returns:  Nothing.
*/
void ra_init(void)
{

bbs_call_loaduseron = ra_loaduseron;
bbs_call_saveuseron = ra_saveuseron;
bbs_call_processmsgs = ra_processmsgs;
bbs_call_page = ra_page;
bbs_call_setexistbits = ra_setexistbits;
bbs_call_login = ra_login;
bbs_call_logout = ra_logout;
bbs_call_openfiles = ra_openfiles;
bbs_call_updateopenfiles = ra_updateopenfiles;
bbs_call_pageedit = ra_longpageeditor;

}

/* ra_loaduseron() - Loads a node status from the USERON file.
   Parameters:  nodenum - Node number to load the data for.
                userdata - Pointer to generic BBS data structure to fill.
   Returns:  TRUE if an error occurred, FALSE if successful.
*/
char ra_loaduseron(XINT nodenum, bbsnodedata_typ *userdata)
{
XINT res; /* Result code. */
RA_USERON_typ rauser; /* RA USERON record. */
long n; /* 0-based node number. */

/* In the USERON file, records are 0-based (eg. node 1 is record 0). */
n = nodenum - 1L;

/* Abort if node 0 is paged, or if the USERON file is not large enough that
   it holds the information for the node (meaning the node doesn't exist). */
if (nodenum == 0 ||
    nodenum > (filelength(useronfil) / (long) sizeof(RA_USERON_typ)))
	{
    return 1;
    }

/* Load the USERON record. */
res = lseek(useronfil, n * (long) sizeof(RA_USERON_typ), SEEK_SET);
if (res == -1)
	{
    return 1;
    }
rec_locking(REC_LOCK, useronfil, n * (long) sizeof(RA_USERON_typ),
			sizeof(RA_USERON_typ));
res = read(useronfil, &rauser, sizeof(RA_USERON_typ));
rec_locking(REC_UNLOCK, useronfil, n * (long) sizeof(RA_USERON_typ),
			sizeof(RA_USERON_typ));
if (res == -1)
	{
    return 1;
    }

/* Convert Pascal strings to C. */
unbuild_pascal_string(35, rauser.name);
unbuild_pascal_string(35, rauser.handle);
unbuild_pascal_string(25, rauser.city);
unbuild_pascal_string(10, rauser.statdesc);

/* Copy the information into the Generic BBS structure. */
memset(userdata, 0, sizeof(bbsnodedata_typ) - 2);
fixname(userdata->realname, rauser.name);
strncpy(userdata->handle, rauser.handle, 30);
fixname(userdata->handle, userdata->handle);
userdata->node = rauser.line;
userdata->speed = rauser.baud;
strcpy(userdata->location, rauser.city);
/* 255 indicates a user defined status type. */
if (rauser.status == 255)
	{
    strcpy(userdata->statdesc, rauser.statdesc);
    }
else
	{
    /* Use the predefined status types from the language file. */
    if (rauser.status < 8)
        {
        strcpy(userdata->statdesc, ra_statustypes[rauser.status]);
        }
    else
        {
        /* Status type unknown.  This would occur either with a corrupt
           USERON file or with a new version of RA that uses new types. */
        userdata->statdesc[0] = 0;
        }
    }
userdata->quiet = rauser.attribute & RA_NODISTURB;
userdata->hidden = (rauser.attribute & RA_HIDDEN) ||
                   (rauser.attribute & RA_READY) ||
                   (rauser.line == 0);
userdata->attribs1 = rauser.attribute;
userdata->numcalls = rauser.numcalls;

return 0;
}

/* ra_saveuseron() - Saves a node status to the USERON file.
   Parameters:  nodenum - Node number to save the data for.
                userdata - Pointer to generic BBS data structure to use.
   Returns:  TRUE if an error occurred, FALSE if successful.
*/
char ra_saveuseron(XINT nodenum, bbsnodedata_typ *userdata)
{
XINT res; /* Result code. */
RA_USERON_typ rauser; /* RA USERON buffer. */
long n; /* 0-based node number. */

/* Copy the data from the Generic BBS buffer to the USERON record. */
memset(&rauser, 0, sizeof(RA_USERON_typ));
strncpy(rauser.name, userdata->realname, 35);
strcpy(rauser.handle, userdata->handle);
rauser.line = userdata->node;
rauser.baud = userdata->speed;
strncpy(rauser.city, userdata->location, 25);
rauser.status = 255;
rauser.attribute = userdata->attribs1;
if (userdata->quiet)
	{
    rauser.attribute |= RA_NODISTURB;
    }
else
	{
    rauser.attribute &= (0xFF - RA_NODISTURB);
    }
strncpy(rauser.statdesc, userdata->statdesc, 10);
rauser.numcalls = userdata->numcalls;

/* Convert C strings to Pascal, which RA uses. */
build_pascal_string(rauser.name);
build_pascal_string(rauser.handle);
build_pascal_string(rauser.city);
build_pascal_string(rauser.statdesc);

/* Get the 0-based node number. */
n = nodenum - 1;

/* Extend the USERON file if it's not long enough.  Done for safety when
   record locking. */
if (filelength(useronfil) < (long) nodenum * (long) sizeof(RA_USERON_typ))
    {
    chsize(useronfil, (long) nodenum * (long) sizeof(RA_USERON_typ));
    }

/* Write the USERON data. */
res = lseek(useronfil, n * (long) sizeof(RA_USERON_typ), SEEK_SET);
if (res == -1)
	{
    return 1;
    }
rec_locking(REC_LOCK, useronfil, n * (long) sizeof(RA_USERON_typ),
			sizeof(RA_USERON_typ));
res = write(useronfil, &rauser, sizeof(RA_USERON_typ));
rec_locking(REC_UNLOCK, useronfil, n * (long) sizeof(RA_USERON_typ),
			sizeof(RA_USERON_typ));
if (res == -1)
	{
    return 1;
    }

return 0;
}

/* ra_processmsgs() - Reads and displays messages from a NODEx.RA file.
   Parameters:  None.
   Returns:  Number of messages processed.  (0 on error.)
   Notes:  Also handles SuperBBS TOLINEx files.
*/
XINT ra_processmsgs(void)
{
FILE *pnfil = NULL; /* NODEx file stream. */
char filnam[256]; /* NODEx file name. */
char XFAR *buffer = NULL; /* Incoming message buffer. */
XINT pos = 0, xpos = 0; /* Position, position multiplier. */
XINT tmp, xh; /* ASCII-to-int conversion holder, length of message read. */
char sbbsmsgon = 0; /* Flag if a SuperBBS message is being processed. */

/* Select the filename based on BBS type. */
switch(cfg.bbstype)
	{
    case BBS_RA2:
        sprintf(filnam, "%snode%i.ra", cfg.bbsmultipath, od_control.od_node);
    	break;
    case BBS_SBBS11:
        sprintf(filnam, "%stoline%i", cfg.bbsmultipath, od_control.od_node);
        break;
    }

/* Abort if we don't get read access to the file. */
if (access(filnam, 4))
	{
    return 0;
    }

/* Allocate the page buffer. */
buffer = malloc(8000);
if (!buffer)
    {
    return 0;
    }

/* Open the file using a shared mode. */
pnfil = _fsopen(filnam, "rb", SH_DENYNO);
if (!pnfil)
	{
    dofree(buffer);
    return 0;
    }

/* Prepare the screen. */
delprompt(TRUE);
if (user.pref1 & PREF1_DUALWINDOW)
    {
    // Different for AVT when I find out what the store/recv codes are.
    od_disp_emu("\x1B" "[u", TRUE);
    top_output(OUT_SCREEN, getlang("DWOutputPrefix"));
    }
top_output(OUT_SCREEN, getlang("RAPageRecvPrefix"));

/* Loop until the whole file is processed. */
do
	{
    memset(buffer, 0, 8000);

    /* Read the file. */
    fseek(pnfil, (long) xpos * 7900L, SEEK_SET);
    xh = fread(buffer, 1, 8000, pnfil);

    /* If the file is quite long, it's handled in 7900 byte chunks.  This
       was done to stabilize memory requirements when I thought I was at
       the 640K limit.  A better way would be to just allocate the buffer
       the size of the entire file and read it all in at once.  Even in a
       low-memory situation there should be plenty of memory to read even the
       largest files, which rarely get above a few K. */
    if (xh > 7900)
    	{
        xh = 7900;
        }

    /* Loop for each character. */
    for (pos = 0; pos < xh; pos++)
    	{
        if (!sbbsmsgon && cfg.bbstype == BBS_SBBS11)
        	{
            /* In SuperBBS, messages start at a /MESSAGE token, so
               processing doesn't begin until one is found. */
            if (!strnicmp(&buffer[pos], "/MESSAGE", 8))
            	{
                /* Character location pointers. */
                char *eptr = NULL, *nptr = NULL;
                XINT fromnode; /* Node that sent the page. */

                /* The format of the message token is like this:
                   /MESSAGE User Name,node */
                pos += 9;
                /* Find the comma. */
                eptr = strchr(&buffer[pos], ',');
                memset(outbuf, 0, 61);
                /* Grab the name of the sender. */
                strncpy(outbuf, &buffer[pos], eptr - &buffer[pos]);
                pos += (eptr - &buffer[pos]) + 1;
                /* Detemine where this line ends. */
                eptr = strchr(&buffer[pos], '\r');
                nptr = strchr(&buffer[pos], '\n');
                if (nptr < eptr && nptr != NULL)
                	{
                    eptr = nptr;
                    }
                /* Get the node number. */
                fromnode = atoi(&buffer[pos]);
                itoa(fromnode, outnum[0], 10);
                /* Advance the position to the end of this line. */
                pos += (eptr - &buffer[pos]) - 1;
                /* Display the page header. */
                top_output(OUT_SCREEN, "@c");
                top_output(OUT_SCREEN, getlang("SBBSRecvPageHdr"),
                		   outbuf, outnum[0]);
                /* Now processing a SuperBBS message. */
                sbbsmsgon = 1;
                }
            continue;
            }
        if (sbbsmsgon && cfg.bbstype == BBS_SBBS11)
        	{
            /* In SuperBBS, messages end with /END/ so this needs to be
               scanned for. */
            if (!strnicmp(&buffer[pos], "/END/", 5))
            	{
                /* No longer processing a SuperBBS message. */
                sbbsmsgon = 0;
                pos += 4;
                /* Prompt the user to continue. */
                top_output(OUT_SCREEN, getlang("RAEnter"));
                while(od_get_key(TRUE) != 13);
                top_output(OUT_SCREEN, getlang("RAEnterSuffix"));
                continue;
                }
			}
        /* Handle Ctrl-A codes, which mean "wait for ENTER". */
        if (buffer[pos] == 1)
        	{
            while(od_get_key(TRUE) != 13);
            continue;
            }
        /* Ctrl-K codes display RA-specific information.  TOP only handles
           colour changes and a few page-specific language items. */
        if (buffer[pos] == 11)
        	{
            /* ^K] is the language item code. */
            if (buffer[pos + 1] == ']')
            	{
                /* The format of these codes is ^K]nnn, where nnn is a 3
                   digit number specifying the item number. */
                tmp = atoi(&buffer[pos + 2]);
                pos += 4;

                /* Display message based on the item number.  See the RA
                   language editor for the number of each item. */
                switch(tmp)
                	{
                    case 258: top_output(OUT_SCREEN, getlang("RAEnter")); break;
                    case 496: top_output(OUT_SCREEN, getlang("RAOnNode")); break;
                    case 497: top_output(OUT_SCREEN, getlang("RAMsgFrom")); break;
                    case 628: top_output(OUT_SCREEN, getlang("RAJustPosted")); break;
                    }
                continue;
                }
            /* ^K[ is a colour change. */
            if (buffer[pos + 1] == '[')
                {
                unsigned char fgcol, bgcol; /* Fore & background colours. */

                /* The format of these codes is ^K[bf, where b is the
                   background colour (in hex) and f is the foreground
                   colour (also in hex). */
                bgcol = toupper(buffer[pos + 2]);
                fgcol = toupper(buffer[pos + 3]);
                pos += 3;

                /* Process valid hex digits only. */
                if (isxdigit(bgcol))
                	{
                    if (bgcol >= 'A' && bgcol <= 'F')
                    	{
                        /* A through F represent colours 10 - 15. */
                        bgcol -= ('A' - 10);
                        }
                    else
                    	{
                        bgcol -= '0';
                        }
                    }
                /* Process valid hex digits only. */
				if (isxdigit(fgcol))
                	{
                    if (fgcol >= 'A' && fgcol <= 'F')
                    	{
                        /* A through F represent colours 10 - 15. */
                        fgcol -= ('A' - 10);
                        }
                    else
                    	{
                        fgcol -= '0';
                        }
                    }
                od_set_colour(fgcol, bgcol);
                continue;
            	}
            }
        od_putch(buffer[pos]);
        }
    xpos++;
    }
while((long) xpos * 7900L < filelength(fileno(pnfil)));

closefile(pnfil);

top_output(OUT_SCREEN, getlang("RAPageRecvSuffix"));
unlink(filnam);

dofree(buffer);

return 1;
}

/* ra_page() - Sends a page to a RA node.
   Parameters:  nodenum - Node number to page.
                pagebuf - Text to send.
   Returns:  TRUE if successful, FALSE if an error occurred.
   Notes:  Also pages SuperBBS nodes.
*/
char ra_page(XINT nodenum, unsigned char *pagebuf)
{
FILE *rapgfil = NULL; /* File stram of the receiving NODEx file. */
unsigned char tmp[41]; /* Buffer to hold the filtered username. */

/* Open the appropriate file. */
// This all needs better errorchecking
itoa(nodenum, outnum[0], 10);
switch(cfg.bbstype)
	{
    case BBS_RA2:
    	rapgfil = openfile(top_output(OUT_STRING, "@1node@2.ra",
						   cfg.bbsmultipath, outnum[0]), "at", 0);
        break;
    case BBS_SBBS11:
    	rapgfil = openfile(top_output(OUT_STRING, "@1toline@2",
						   cfg.bbsmultipath, outnum[0]), "at", 0);
        break;
    }

/* Abort if the file can't be opened. */
if (!rapgfil)
	{
    top_output(OUT_SCREEN, getlang("CantPage"), outnum[0]);
    return 0;
    }

/* The filtered username is used because handes can contain PubColour
   codes. */
filter_string(tmp, cfg.usehandles ? user.handle : user.realname);
itoa(od_control.od_node, outnum[0], 10);

/* Write the appropriate page header. */
switch(cfg.bbstype)
	{
    case BBS_RA2:
        strcpy(outbuf, top_output(OUT_STRING, getlang("RAPageHeader"),
               tmp, outnum[0]));
        break;
    case BBS_SBBS11:
        strcpy(outbuf, top_output(OUT_STRING, getlang("SBBSPageHeader"),
               tmp, outnum[0]));
        break;
    }
fputs(outbuf, rapgfil);

/* Write the message text. */
fputs(pagebuf, rapgfil);

/* Write the appropriate page footer. */
switch(cfg.bbstype)
	{
    case BBS_RA2:
        fputs(top_output(OUT_STRING, getlang("RAPageFooter")), rapgfil);
        break;
    case BBS_SBBS11:
        fputs(top_output(OUT_STRING, getlang("SBBSPageFooter")), rapgfil);
        break;
    }

closefile(rapgfil);

return 1;
}

/* ra_setexistbits() - Selects the node status fields to display.
   Parameters:  userdata - Pointer to generic BBS data structure to set the
                           bits in.
   Returns:  Nothing.
*/
void ra_setexistbits(bbsnodedata_typ *userdata)
{

userdata->existbits = NEX_HANDLE |
					  NEX_REALNAME |
                      NEX_NODE |
                      NEX_SPEED |
                      NEX_LOCATION |
                      NEX_STATUS |
                      NEX_PAGESTAT;

}

/* ra_login() - RA initialization when TOP is started.
   Parameters:  None.
   Returns:  Nothing.
*/
void ra_login(void)
{
/* Generic BBS data buffer, login check BBS data buffer. */
bbsnodedata_typ rutmp, logintmp;
XINT res; /* Result codes. */

/* Copy the user information into the generic BBS data buffer. */
memset(&rutmp, 0, sizeof(bbsnodedata_typ) - 2);

/* Check if the node is already logged in RA/SBBS. */
res = (*bbs_call_loaduseron)(od_control.od_node, &logintmp);
if (!res)
{
    if (!logintmp.hidden)
    {
        /* Set the do not disturb flag. */
        node->quiet = rutmp.quiet = logintmp.quiet;
        save_node_data(od_control.od_node, node);
    }
}

fixname(rutmp.realname, user.realname);
fixname(rutmp.handle, user.handle);
rutmp.node = od_control.od_node;
rutmp.speed = od_control.baud;
strcpy(rutmp.location, od_control.user_location);
strcpy(rutmp.statdesc, getlang("NodeStatus"));
rutmp.attribs1 = 0;

/* Update the USERON file to show the user is now in TOP. */
res = (*bbs_call_saveuseron)(od_control.od_node, &rutmp);
if (!res)
    {
    FILE *rnfil = NULL; /* RABUSY file stream. */

    /* Create RABUSY semaphore.  RA provides these for batch operations. */
    if (cfg.bbstype == BBS_RA2)
    	{
	    itoa(od_control.od_node, outnum[0], 10);
    	rnfil = fopen(top_output(OUT_STRING, "@1rabusy.@2", cfg.bbsmultipath,
				                 outnum[0]), "wb");
        fclose(rnfil);
        }
    node_added = TRUE;
    }

}

/* ra_logout() - RA deinitialization when TOP is exited.
   Parameters:  None.
   Returns:  Nothing.
*/
void ra_logout(void)
{
bbsnodedata_typ rutmp; /* Generic BBS data buffer. */

if (localmode || lanmode)
	{
    /* In local and LAN modes, TOP removes the user from the USERON file.
       In remote mode, TOP assumes RA will gain control immediately after
       the exit so it doesn't bother. */
    memset(&rutmp, 0, sizeof(bbsnodedata_typ) - 2);
    rutmp.quiet = 1;
	rutmp.attribs1 = RA_HIDDEN & RA_NODISTURB;
	rutmp.node = 0;
    (*bbs_call_saveuseron)(od_control.od_node, &rutmp);
    if (cfg.bbstype == BBS_RA2)
    	{
        /* Remove the RABUSY semaphore. */
        itoa(od_control.od_node, outnum[0], 10);
		unlink(top_output(OUT_STRING, "@1rabusy.@2", cfg.bbsmultipath,
					      outnum[0]));
        }
    }

}

/* ra_openfiles() - Opens RA-related files.
   Parameters:  None.
   Returns:  Number of errors that occurred, or 0 on success.
*/
XINT ra_openfiles(void)
{
XINT bbsres = 0; /* Error counter. */

switch(cfg.bbstype)
	{
    case BBS_RA2:
        /* TOP keeps the RA USERON file open while it is running. */
        useronfil = sh_open(top_output(OUT_STRING, "@1useron.bbs",
									   cfg.bbspath),
							O_RDWR | O_CREAT | O_BINARY, SH_DENYNO,
							S_IREAD | S_IWRITE);
        break;
    case BBS_SBBS11:
        /* TOP does not keep the SBBS SUSERON file open because it seemed
           to cause problems. */
        return 0;
	}
bbsres += (useronfil == -1);

return bbsres;
}

/* ra_updateopenfiles() - Re-opens files if the node changes in LAN mode.
   Parameters:  None.
   Returns:  Number of errors that occurred, or 0 on success. */
XINT ra_updateopenfiles(void)
{

/* As no node-specific files are kept open, nothing needs to be done. */

return 0;
}

/* ra_longpageeditor() - Editor for long (multi-line) pages.
   Parameters:  nodenum - Node number being paged.
                pagebuf - Pointer to buffer to hold the page text.
   Returns:  TRUE if a page was entered, FALSE if the user aborted.
   Notes:  Can be used with any BBS type that can handle long pages.
*/
char ra_longpageeditor(XINT nodenum, unsigned char *pagebuf)
    {
#ifndef __OS2__
    tODEditOptions edop; /* OpenDoors editor options. */
#endif
    unsigned char linebuf[81]; /* Line input buffer. */
    XINT writecount = 0; /* Write count, used to limit page length. */

/* Under DOS and Win32, OpenDoors provides a sophisticated text editor so
   TOP will take advantage of that. */
#ifndef __OS2__
    if (od_control.user_ansi || od_control.user_avatar)
        {
        /* The OpenDoors editor only works in ANSI and AVATAR modes. */

        /* Prepare the screen. */
        od_clr_scr();
        itoa(nodenum, outnum[0], 10);
        top_output(OUT_SCREEN, getlang("EnterPageFS"), outnum[0]);
        top_output(OUT_SCREEN, getlang("EnterPageFSSep"));

        /* Initialize the OpenDoors editor data. */
        edop.nAreaLeft = 1;
        edop.nAreaTop = 4;
        edop.nAreaRight = 80;
        edop.nAreaBottom = 23;
        edop.TextFormat = FORMAT_LINE_BREAKS;
        edop.pfMenuCallback = NULL;
        edop.pfBufferRealloc = NULL;
        edop.dwEditFlags = 0;

        /* Call the editor. */
        if (od_multiline_edit(pagebuf, 1600, &edop) ==
            OD_MULTIEDIT_SUCCESS)
            {
            /* The profanity censor can currently only handle strings of
               less than 256 characters. */
            if (strlen(pagebuf) < 256)
                {
                if (censorinput(pagebuf))
                    {
                    return 0;
                    }
                }
            return 1;
            }
        else
            {
            return 0;
            }
        }
    else
/* TOP/2 uses an older port of OpenDoors which does not have the fancy page
   editor, so TOP uses less sophisticated line-by-line editor. */
#endif
        {
        /* The line editor is also used if the user is in ASCII mode. */

        /* Prepare the screen. */
        itoa(nodenum, outnum[0], 10);
        top_output(OUT_SCREEN, getlang("EnterPage"), outnum[0]);
        top_output(OUT_SCREEN, getlang("EnterPageSep"));
        /* Put something in the input buffer to engage the loop. */
        linebuf[0] = '.';
        /* Loop until the message is too long or the user just hits ENTER. */
        while(writecount < (1600 - 81) && linebuf[0])
            {
            memset(linebuf, 0, 80);
            /* Get one line at a time.  Repeat if the input needs to be
               censored. */
            do
                {
                od_input_str(linebuf, 79, ' ',
                             MAXASCII);
                }
            while(censorinput(linebuf));
            if (linebuf[0])
                {
                /* Copy the line to the page buffer. */
                memcpy(&pagebuf[writecount], linebuf, strlen(linebuf));
                writecount += strlen(linebuf);
                memcpy(&pagebuf[writecount], "\n", 2);
                writecount++;
                }
            }
        return 1;
        }
    }