home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XDEV_117.ZIP / DOORSKEL.C next >
Encoding:
C/C++ Source or Header  |  1990-10-21  |  34.0 KB  |  1,637 lines

  1. /* XBBS Door Skeleton -- TC 2.0 code
  2.    Copyright (c) 1990 by M. Kimes
  3.    All Rights Reserved
  4.    May be freely used for >>>FREE<<< programs */
  5.  
  6. /* Miscellaneous notes:
  7.     #define XBBS and the program will be compiled to read ONLINE.XBS
  8.     #define DORINFO and the program will be compiled to read DORINFO?.DEF
  9.     #define both and first ONLINE.XBS will be read, then DORINFO?.DEF
  10.     #define neither and all info must come from command line
  11.     #define FINDUSER and a routine to find a given user (by name) will
  12.             be compiled in (finduser())
  13.     #define NOREADFILE and the file reader routine (readtext()) will NOT
  14.             be compiled
  15. */
  16.  
  17.  
  18. #include "msgg.h"   /* XBBS include file */
  19.  
  20.  
  21. /* Change these to suit your Door */
  22.  
  23. #define PROGRAM_NAME "Generic XBBS Door Skeleton v1.0"
  24. #define COPY_RIGHT "Copyright (c) 1990 by M. Kimes -- All Rights Reserved"
  25.  
  26.  
  27. /* #define DORINFO "UseIt" */
  28. /* #define XBBS "UseIt" */        /* Pick your interface */
  29.  
  30.  
  31. /* Function declarations */
  32.  
  33. #ifdef XBBS
  34.     void pascal getonline(void);
  35.     void pascal readconfig(void);
  36.     void pascal prepare(void);
  37.     void pascal saveconfig(void);
  38. #endif
  39.  
  40. #ifndef NOREADFILE
  41.     char   pascal readtext(char *,char);
  42.     char * pascal write_line (char **text,word linelen);
  43.     void   pascal strip_blanklines (char *hold);
  44. #endif
  45.  
  46. #ifdef FINDUSER
  47.     struct _user *other pascal finduser(char *);
  48. #endif
  49.  
  50. #ifdef DORINFO
  51.     void pascal readinfo(void);
  52. #endif
  53.  
  54. void   pascal hitreturn(void);
  55. void   pascal cls (void);
  56. void   cdecl  debug_print(char *,...);
  57. char * pascal addtolog(char *);
  58. char   pascal inkey (void);
  59. char   pascal carrchk (void);
  60. char   pascal fossil (char function, char arg);
  61. char   pascal printm (char *text);
  62. void   pascal checkpos(void);
  63. void   cdecl  deinitialize (void);
  64. char * pascal genin (char length,char password,char caps,char hot,char type);
  65. void   pascal print_stat();
  66. char * pascal fidodate (void);
  67. ulong  pascal getxbbstime(void);
  68. char   pascal specialkey(char);
  69. int    cdecl  break_handler(void);
  70. char   pascal printg(char *);
  71. char   pascal skip_blanks(FILE *fp);
  72. void   pascal chat(void);
  73. void   pascal printinfo(void);
  74. void   pascal printhelp(void);
  75. char * pascal lstrip(char *);
  76. char * pascal rstrip(char *);
  77. int    cdecl  printfm(char *,...);
  78. char * pascal stripcr(char *);
  79.  
  80. void   pascal mainloop(void);   /* Change as required */
  81.  
  82.  
  83. /* Global variables */
  84.  
  85.  
  86. #ifdef XBBS
  87.     struct _config conf;
  88.     struct _user user;
  89.     word userno;
  90.     struct time timeon;
  91.     char timer_off;
  92.     word hold_time;
  93.     char age;
  94.     char pages;
  95.     struct _mboard mboard;
  96.     struct _fboard fboard;
  97.     struct _events event[10];
  98.     char variable[10][82];
  99. #endif
  100.  
  101. /* NOTE DEFAULTS! */
  102.  
  103. char   debug_mode=0;
  104. char   graphics=0;
  105. word   timelimit=30;
  106. word   baud=0;
  107. char   numlines=24;
  108. word   seclvl=5;
  109. ulong  startt=0;
  110. char   sysopin=0;
  111. char   fastANSI=0;
  112. char   commport=0;
  113. struct time starter;
  114. union  REGS rg;
  115. char   logfile[133]="XBBS.LOG";
  116. char   username[36]="A. Ghost";
  117. char   width=80;
  118. char   fast=0;
  119. char   chatting=0;
  120. char   chatted=0;
  121. char   nodenumber=1;
  122. char   system_name[64]="";
  123. char   sysop[36]="";
  124.  
  125.  
  126.  
  127. void cdecl main (argc,argv)
  128.  
  129.     int argc;
  130.     char *argv[];
  131.  
  132. {
  133.  
  134.     register word x;
  135.     char *p;
  136.  
  137.   /* Please leave this next line in...thanks */
  138.   fputs("\x1b[2J\x1b[0;2;37m\x1b[1;1H\04 Made using M. Kimes' DOORSKEL.C\n",stdout);
  139.  
  140.   directvideo=0;
  141.   gettime(&starter);
  142.   ctrlbrk(break_handler);
  143.  
  144.   if (argc==2 && !strcmp(strupr(argv[1]),"H")) {
  145.     printinfo();
  146.     printhelp();
  147.     exit(0);
  148.   }
  149.   rg.x.ax=0x4400;        /* Set console in raw mode */
  150.   rg.x.bx=1;
  151.   int86(33,&rg,&rg);
  152.   rg.h.dh=0;
  153.   rg.h.dl=rg.h.dl|0x20;
  154.   rg.x.ax=0x4401;
  155.   int86(33,&rg,&rg);
  156.  
  157.   atexit(deinitialize);
  158.  
  159. #ifdef XBBS
  160.     readconfig();
  161.     getonline();
  162. #endif
  163.  
  164. #ifdef DORINFO
  165.     readinfo();
  166. #endif
  167.  
  168.   for (x=1;x<argc;x++) {
  169.     strupr(argv[x]);
  170.     switch (*argv[x]) {
  171.         case 'F':    fastANSI=1;
  172.                     break;
  173.         case 'U':   strncpy(username,&argv[x][1],36);
  174.                     username[35]=0;
  175.                     break;
  176.         case 'N':    nodenumber=(char)atoi(&argv[x][1]);
  177.                     break;
  178.         case 'L':     numlines=(char)atoi(&argv[x][1]);
  179.                     break;
  180.         case 'W':    width=(char)atoi(&argv[x][1]);
  181.                     break;
  182.         case 'B':    baud=(word)atoi(&argv[x][1]);
  183.                     break;
  184.         case 'G':    if(atoi(&argv[x][1])) graphics=1;
  185.                     break;
  186.         case 'C':    commport=(char)atoi(&argv[x][1]);
  187.                     break;
  188.         case 'S':    seclvl=atoi(&argv[x][1]);
  189.                     break;
  190.         case 'T':   timelimit=atoi(&argv[x][1]);
  191.                     break;
  192.         case 'M':   directvideo=atoi(&argv[x][1]);
  193.                     break;
  194.         case '!':   debug_mode=1;
  195.                     break;
  196.         case 'X':    strcpy(logfile,&argv[x][1]);
  197.                     break;
  198.         default:    fputs("\nUnknown argument `",stdout);
  199.                     fputs(argv[x],stdout);
  200.                     fputs("'\n",stdout);
  201.                     sleep(1);
  202.     }
  203.   }
  204.   fossil(INIT,0);
  205.   cls();
  206.  
  207.   printg("\x1b[0;1;37m");
  208.   p=PROGRAM_NAME;
  209.   if(baud) while (*p++) while(!fossil(TRANSMIT,*p)) carrchk();
  210.   printinfo();
  211.   printm("\n");
  212.  
  213.   mainloop();
  214.  
  215. /* If you want to change parameters in CONFIG.BBS or ONLINE.XBS,
  216.    change them, then call saveconfig() or prepare() here or in
  217.    deinitialize() */
  218.  
  219. }
  220.  
  221.  
  222.  
  223. void pascal mainloop (void) {
  224.  
  225.     /* Here's where your main program goes.  Change declaration as req'd */
  226.  
  227.  
  228. }
  229.  
  230.  
  231.  
  232. void pascal printhelp (void) {  /* Print help screen--edit to taste
  233.                                    Add to as required */
  234.  
  235.     fputs("L<screen lines>\n",stdout);
  236.     fputs("N<nodenumber>\n",stdout);
  237.     fputs("U<user name>\n",stdout);
  238.     fputs("W<screen width>\n",stdout);
  239.     fputs("T<time in minutes>\n",stdout);
  240.     fputs("B<baudrate (0-38400...?)>\n",stdout);
  241.     fputs("G<graphics (0 or 1)>\n",stdout);
  242.     fputs("C<commport (0=COM1)>\n",stdout);
  243.     fputs("S<security level>\n",stdout);
  244.     fputs("M<mode (0=direct video, 1=BIOS, 2=DOS)>\n",stdout);
  245.     fputs("X<filename> (Log File)\n",stdout);
  246.     fputs("F (Fast ANSI writes)\n",stdout);
  247.     fputs("! (Debug mode on)\n",stdout);
  248. }
  249.  
  250.  
  251.  
  252.  
  253. int cdecl break_handler (void) {  /* Diables ctrl-break */
  254.  
  255.    return 1;
  256.  
  257. }
  258.  
  259. void pascal chat (void) {    /* Cheap chat-mode */
  260.  
  261. char a[3];
  262.  
  263.  printg("\x1b[0;1;33m");
  264.  printm("\n\nChat mode engaged\n\n");
  265.  while (chatting) {
  266.    *a=inkey();
  267.    a[1]=0;
  268.    if (chatting) {
  269.      _AH=3;
  270.      _BH=0;
  271.      geninterrupt(16);
  272.      if (*a==13) printm("\n");
  273.      if ((*a==13) || (*a==' ' && _DL>70)) printm("\n");
  274.      else printm(a);
  275.    }
  276.  }
  277.  printm("\n\nChat mode ended\n\n");
  278.  chatted++;
  279. }
  280.  
  281.  
  282.  
  283. #ifndef NOREADFILE
  284.  
  285. char pascal readtext (char *s,char paged) {  /* Displays a text file
  286.                                                 This thing's got all
  287.                                                 sorts of fancy stuff
  288.                                                 in it if you set paged=1
  289.                                                 Otherwise it does a pretty
  290.                                                 dumb dump (ok for ANSI
  291.                                                 files) */
  292.  
  293.     long place2;
  294.     long place;
  295.     struct ffblk filestat;
  296.     char dostring[181];
  297.     char eof=0;
  298.     word page;
  299.     char a;
  300.     long *pos;
  301.     word scratch;
  302.     FILE *fp;
  303.     register int x;
  304.     char prev=0;
  305.     char *here;
  306.     char *p;
  307.     char *tempo;
  308.     char temp='N';
  309.     char lastpage=0;
  310.     char searchstring[41];
  311.     char holdstring[41];
  312.     char teststring[81];
  313.     char findend=0;
  314.     char printanyway=0;
  315.     char linelen;
  316.     word lines=1;
  317.  
  318.     *searchstring=0;
  319.     *holdstring=0;
  320.  
  321.   if (findfirst(s,&filestat,0)) return 1;
  322.   if (!filestat.ff_fsize) return 1;
  323.   if (!(fp=fopen(s,"rt"))) return 1;
  324.   cls();
  325.   printg("\x1b[0;1;33m");
  326.   page=0;
  327.   place2=ftell(fp);
  328.   if (!paged) {
  329.         printm("\n");
  330.       while (!feof(fp) && !ferror(fp)) {
  331.         if (!fgets(dostring,181,fp)) break;
  332.         if(ftell(fp)<=place2) {
  333.             while(fgetc(fp)=='\n');  /* Guard against Unix files & TC bug */
  334.             continue;
  335.         }
  336.         place2=ftell(fp);
  337.         printm(dostring);
  338.         if(numlines) {
  339.             lines++;
  340.             if(lines>numlines+1) {
  341.                 lines=1;
  342.                 printm("More? (Y/n) ");
  343.                 fossil(FLUSHOUT,0);
  344.                 fossil(PURGEIN,0);
  345.                 linelen=*genin(1,0,1,1,YESNOM);
  346.                 for (x=0;x<12;x++) printm(BACKSPACE);
  347.                 if (linelen == 'N') break;
  348.             }
  349.         }
  350.         a=toupper(inkey());
  351.         if (a=='S' || a==' ') break;
  352.         if (a=='P') sleep(5);
  353.       }
  354.       fclose(fp);
  355.       if (numlines) if (lines>numlines-11) hitreturn();
  356.       return 0;
  357.   }
  358.  
  359. /*
  360.   if (!baud && *reader) {
  361.     fclose(fp);
  362.     sprintf(dostring,"%s %s",reader,s);
  363.     system(dostring);
  364.     return 0;
  365.   }
  366. */
  367.  
  368.   p=strchr(s,':');            /* Strip path off filename for display */
  369.   here=strrchr(s,'\\');
  370.   if(!p && !here) here=s;
  371.   else if (!here) here=&p[1];
  372.   else if (p) here= (p<here) ? &here[1] : &p[1];
  373.   else here++;
  374.  
  375.   pos=(long *)malloc((word)(sizeof(long)*1024));
  376.   if(!pos) {
  377.     fclose(fp);
  378.     printm("\nOut of memory\n");
  379.     exit(4);
  380.   }
  381.  
  382.   printfm(" -=-=Reading: %s=-=-  Page #%u\n",here,page+1);
  383.  
  384.   printg("\x1b[0;1;32m");
  385.   if(skip_blanks(fp)) goto Abort;
  386.   place2=pos[0]=ftell(fp);
  387.   lines=1;
  388.   while (!feof(fp) && !ferror(fp)) {
  389.     if ((*searchstring && !printanyway) || findend) goto Searcher;
  390. Domore:
  391.     if (!fgets(dostring,181,fp)) {
  392.         eof++;
  393.         goto EEOF;
  394.     }
  395.     if(ftell(fp)<=place2) {
  396.         while(fgetc(fp)=='\n');  /* Guard against Unix files & TC bug */
  397.         continue;
  398.     }
  399.     place2=ftell(fp);
  400.     stripcr(dostring);
  401.     while (p=strchr(dostring,'\xc')) memmove(p,&p[1],strlen(&p[1])+1);
  402.     while (p=strchr(dostring,'\x1b')) memmove(p,&p[1],strlen(&p[1])+1);
  403.     if (!*dostring) {
  404.         if (prev) {
  405.             prev=0;
  406.             eof=skip_blanks(fp);
  407.             if (eof) goto EEOF;
  408.             else goto Domore;
  409.         }
  410.         else prev++;
  411.     }
  412.     else prev=0;
  413.     if (*searchstring) {
  414.         strcpy(teststring,dostring);
  415.         strupr(teststring);
  416.         if (strstr(teststring,searchstring)) {
  417.             printg("\x1b[0;1;37m");
  418.             fast=2;
  419.             printm(dostring);
  420.             printg("\x1b[0;1;32m");
  421.             lines++;
  422.         }
  423.         else {
  424.             fast=1;
  425.             printm(dostring);
  426.             lines++;
  427.         }
  428.     }
  429.     else {
  430.         fast=1;
  431.         printm(dostring);
  432.         lines++;
  433.     }
  434.     scratch=strlen(dostring);
  435.     p=dostring;
  436.     while(tempo=strchr(p,'\t')) {
  437.         p=tempo+1;
  438.         scratch+=3;
  439.     }
  440.     if (scratch<79) {
  441.         printm("\n");
  442.         scratch++;
  443.     }
  444.     if (scratch>width) {
  445.         lines++;
  446.     }
  447.     a=toupper(inkey());
  448.     if (a=='S' || a==' ') break;
  449.     if (a=='P' || a=='-') if (page) goto SkipThis;
  450.     if (a=='M') goto Direct;
  451. Searcher:
  452.     if (lastpage) goto EEOF;
  453.     if ((a=='N') || (*searchstring) || (findend)) {
  454.       if (findend) {
  455.         if (++page>1024) page=1;
  456.         pos[page]=ftell(fp);
  457.       }
  458.       place2=place=ftell(fp);
  459. Domore1:
  460.       while (!feof(fp) && !ferror(fp)) {
  461. Domore2:
  462.         if (!fgets(dostring,181,fp)) {
  463.             eof++;
  464.             break;
  465.         }
  466.         if(ftell(fp)<=place2) {
  467.             while(fgetc(fp)=='\n');  /* Guard against Unix files & TC bug */
  468.             continue;
  469.         }
  470.         place2=ftell(fp);
  471.         while (p=strchr(dostring,'\xc')) memmove(p,&p[1],strlen(&p[1])+1);
  472.         while (p=strchr(dostring,'\x1b')) memmove(p,&p[1],strlen(&p[1])+1);
  473.         if (!strcmp(dostring,"\n")) {
  474.             if (prev) {
  475.                 prev=0;
  476.                 eof=skip_blanks(fp);
  477.                 if (eof) break;
  478.                 else goto Domore2;
  479.             }
  480.             else prev++;
  481.         }
  482.         else prev=0;
  483.         if (*searchstring) {
  484.             if (strstr(strupr(dostring),searchstring)) {
  485.                 printanyway++;
  486.                 break;
  487.             }
  488.         }
  489.         lines++;
  490.         scratch=strlen(dostring);
  491.         p=dostring;
  492.         while(tempo=strchr(p,'\t')) {
  493.             p=tempo+1;
  494.             scratch+=3;
  495.         }
  496.         if (scratch<79) {
  497.             scratch++;
  498.         }
  499.         if (scratch>width) lines++;
  500.         if (numlines) if ((lines>=numlines-2) || (feof(fp)) || (eof)) break;
  501.       }
  502.       fossil(PURGEIN,0);
  503.       eof=skip_blanks(fp);
  504.       if (feof(fp) || eof || printanyway) {
  505.         if (*searchstring && !printanyway) {
  506.             printm("\nNot found...\n");
  507.             goto EEOF;
  508.         }
  509.         fseek(fp,place,SEEK_SET);
  510.         clearerr(fp);
  511.         cls();
  512.         printg("\x1b[0;1;33m");
  513.         printfm(" -=-=Reading: %s=-=-  Page #%u\n",here,page+1);
  514.         printg("\x1b[0;1;32m");
  515.         findend=prev=eof=0;
  516.         lastpage=lines=1;
  517.         goto Domore;
  518.       }
  519.       if ((*searchstring || findend) && !eof) {
  520.         if (++page>1024) page=1;
  521.         pos[page]=place=place2=ftell(fp);
  522.         lines=1;
  523.         goto Domore1;
  524.       }
  525.     }
  526. EEOF:
  527.     if (numlines) if ((lines>=numlines-2) || (feof(fp)) || (eof)) {
  528. Direct:
  529.         linelen=0;
  530.         prev=0;
  531.         eof=skip_blanks(fp);
  532.         if (feof(fp) || eof) {
  533.             printg("\x1b[0;1;31m");
  534.             printm(" (END)");
  535.             linelen+=6;
  536.             printg("\x1b[0;1;33m");
  537.             temp='S';
  538.         }
  539.         else {
  540.             if (a=='M' || a=='N') goto SkipThis;
  541.             temp='N';
  542.             printg("\x1b[0;1;33m");
  543.             printm(" [F]ind [E]nd [N]ext [M]ore");
  544.             linelen+=27;
  545.         }
  546.         if (page) {
  547.             printm(" [H]ome [P]rior");
  548.             linelen+=15;
  549.         }
  550.         linelen+=sprintf(dostring," [O]ver [S]top: [%c] ",temp);
  551.         printm(dostring);
  552.         fossil(FLUSHOUT,0);
  553.         pos[page+1]=ftell(fp);
  554. Getitagain:
  555.         fossil(PURGEIN,0);
  556.         a=*genin(1,0,1,1,ALLL);
  557. SkipThis:
  558.         findend=0;
  559.         lastpage=0;
  560.         printanyway=0;
  561.         *searchstring=0;
  562.         switch (a) {
  563.             case 'S':   goto Abort;
  564.             case 'H':   if (!page) {
  565.                             printm(BACKSPACE);
  566.                             printm("\x7");
  567.                             goto Getitagain;
  568.                         }
  569.                         page=0;
  570.                         fseek(fp,0,SEEK_SET);
  571.                         break;
  572.             case 'E':   if (feof(fp) || eof) {
  573.                             printm(BACKSPACE);
  574.                             printm("\x7");
  575.                             goto Getitagain;
  576.                         }
  577.                         findend++;
  578.                         break;
  579.             case 'F':   if (feof(fp) || eof) {
  580.                             printm(BACKSPACE);
  581.                             printm("\x7");
  582.                             goto Getitagain;
  583.                         }
  584.                         printg("\x1b[0;1;35m");
  585.                         printfm("\n Search string: [%s]\n  -> ",holdstring);
  586.                         strcpy(searchstring,genin(40,0,1,0,ALLL));
  587.                         if (!*searchstring) {
  588.                             if (*holdstring) {
  589.                                 strcpy(searchstring,holdstring);
  590.                                 if (++page>1024) page=1;
  591.                                 pos[page]=ftell(fp);
  592.                             }
  593.                         }
  594.                         else strcpy(holdstring,searchstring);
  595.                         fseek(fp,pos[page],SEEK_SET);
  596.                         eof=skip_blanks(fp);
  597.                         break;
  598.             case  0:    if (feof(fp) || eof) goto Abort;
  599.             case 'N':   if (feof(fp) || eof) {
  600.                             printm(BACKSPACE);
  601.                             printm("\x7");
  602.                             goto Getitagain;
  603.                         }
  604.                         a=0;
  605.                         if (++page>1024) page=1;
  606.                         pos[page]=ftell(fp);
  607.                         break;
  608.             case 'O':   fseek(fp,pos[page],SEEK_SET);
  609.                         eof=skip_blanks(fp);
  610.                         break;
  611.             case 'P':
  612.             case '-':   if (page) {
  613.                             fseek(fp,pos[--page],SEEK_SET);
  614.                             eof=skip_blanks(fp);
  615.                             break;
  616.                         }
  617.                         printm(BACKSPACE);
  618.                         printm("\x7");
  619.                         goto Getitagain;
  620.             case 'M':   if (feof(fp) || eof) {
  621.                             printm("\x7");
  622.                             printm(BACKSPACE);
  623.                             goto Getitagain;
  624.                         }
  625.                         for (x=0;x<linelen;x++) printm(BACKSPACE);
  626.                         printg("\x1b[0;1;32m");
  627.                         if (numlines) lines=numlines-3;
  628.                         goto Domore;
  629.             default:    printm(BACKSPACE);
  630.                         goto Getitagain;
  631.         }
  632.         place2=ftell(fp);
  633.         eof=0;
  634.         cls();
  635.         printg("\x1b[0;1;33m");
  636.         if (findend || *searchstring) strcpy(teststring,"Scanning");
  637.         else strcpy(teststring,"Reading");
  638.         printfm(" -=-=%s: %s=-=-  Page #%u\n",teststring,here,page+1);
  639.         printg("\x1b[0;1;32m");
  640.         lines=1;
  641.       }
  642.   }
  643. Abort:
  644.   if(pos) free(pos);
  645.   fclose(fp);
  646.   return 0;
  647.  
  648. }
  649.  
  650.  
  651.  
  652. /*
  653.  
  654. char * pascal write_line (char **text,word linelen) {
  655.  
  656.     static char line[81];
  657.     word register x=0;
  658.     char *p;
  659.     char *pp;
  660.  
  661.     p=*text;
  662.     pp=line;
  663.     *pp=0;
  664.     while(++x<linelen && *p && *p!='\r') {
  665.         *pp++=*p++;
  666.         *pp=0;
  667.     }
  668.     while(*pp==' ' && pp>line) {
  669.         *pp=0;
  670.         --pp;
  671.     }
  672.     if(*p==' ' || *p=='\r') {
  673.         if(*p==' ') *pp=0;
  674.         else p++;
  675.         while(*p==' ') p++;
  676.     }
  677.     else if(x==linelen) {
  678.         while(p>*text && *pp!=' ') {
  679.             *pp=0;
  680.             pp--;
  681.             p--;
  682.         }
  683.         if(p==*text) {
  684.             strncpy(line,*text,linelen);
  685.             line[linelen]=0;
  686.             p=text[linelen];
  687.         }
  688.         else p++;
  689.     }
  690.     *text=p;
  691.     return line;
  692. }
  693.  
  694.  
  695. void pascal strip_blanklines (char *hold) {
  696.  
  697.     char *p;
  698.  
  699.     p=&hold[strlen(hold)-1];
  700.     while(*p=='\r' && p>hold) {
  701.         *p=0;
  702.         p--;
  703.     }
  704. }
  705.  
  706. */
  707.  
  708. #endif
  709.  
  710.  
  711.  
  712. char pascal skip_blanks (FILE *fp) {  /* Skips blank lines, what else? */
  713.  
  714.   ulong pos;
  715.   char temp[81];
  716.   char eof=0;
  717.  
  718.   do {
  719.     pos=ftell(fp);
  720.     if (!fgets(temp,81,fp)) eof++;
  721.     stripcr(temp);
  722.   } while ((!eof) && (!feof(fp)) && (!*temp));
  723.   if (!eof && !feof(fp)) fseek(fp,pos,SEEK_SET);
  724.   return eof;
  725.  
  726. }
  727.  
  728.  
  729.  
  730. char pascal printg (text)    /* Print only if user has graphics set */
  731.  
  732.     char *text;
  733.  
  734. {
  735.  
  736.    if (graphics) return (printm(text));
  737.  
  738. }
  739.  
  740.  
  741.  
  742. char pascal inkey (void)  /* MIMICS BASIC'S INKEY$ FUNCTION */
  743.  
  744. {
  745.  
  746. char arg=0;
  747. static int check=0;
  748.  
  749.    rg.h.ah=11;
  750.    int86(33,&rg,&rg);
  751.    if (rg.h.al!=0) {
  752.         rg.h.ah=8;
  753.         int86(33,&rg,&rg);
  754.         if (rg.h.al!=0)return((char)(rg.h.al));
  755.         rg.h.ah=8;
  756.         int86(33,&rg,&rg);
  757.         arg=specialkey(rg.h.al);
  758.         if (arg) return (arg);
  759.    }
  760.    if (baud) {
  761.       arg=carrchk();
  762.       if (!(arg & 1)) return (0);
  763.       return (fossil(RECVWAIT,arg));
  764.    }
  765.    if (check!=(int)(timelimit-(getxbbstime()/60))) {
  766.        check=(int)(timelimit-(getxbbstime()/60));
  767.    }
  768.    return (0);
  769. }
  770.  
  771.  
  772.  
  773. char pascal specialkey (a)    /* Handles special local-only keys
  774.                                Add anything you like (extended keys) */
  775.  
  776. char a;
  777.  
  778. {
  779.  
  780. char middle[82];
  781. int  drive;
  782. char dir[MAXDIR];
  783.  
  784.   switch (a) {
  785.     case 45:exit (0);      /* QUIT DOOR */
  786.     case 46:if (!chatting) {  /* CHAT */
  787.                 chatting++;
  788.                 chat();
  789.             }
  790.             else chatting=0;
  791.             break;
  792.     case 35:                /* HANG UP */
  793.             fossil(DTR,DOWN);
  794.             exit(1);
  795.     case 36:                /* SysOp SHELL */
  796.             printm("\nThe SysOp has jumped to DOS...please wait...\n");
  797.             fossil(FLUSHOUT,0);
  798.             drive=getdisk();
  799.             getcurdir(++drive,dir);
  800.             fossil(DEINIT,0);
  801.             fputs("\nEXIT to return\n",stdout);
  802.             system ("");
  803.             fossil(INIT,0);
  804.             setdisk (--drive);
  805.             strcpy(middle,"\\");
  806.             strcat(middle,dir);
  807.             chdir(middle);
  808.             printm("\nThe SysOp has returned...please continue...\n");
  809.             chatted++;
  810.             break;
  811.     case 72:                /* MORE TIME */
  812.             timelimit++;
  813.             break;
  814.     case 80:                /* LESS TIME */
  815.             if (timelimit<1) timelimit=0;
  816.             else timelimit--;
  817.             break;
  818.     case 73:return 'P';
  819.     case 81:return 'N';
  820.     case 71:return 'H';
  821.   }
  822.   startt=getxbbstime();
  823.   return 0;
  824. }
  825.  
  826.  
  827.  
  828. void pascal cls (void) { /* MIMICS BASIC'S CLS FUNCTION LOCAL & REMOTE */
  829.  
  830.   char clr_string[]="\x1b[0m\x1b[2J";
  831.   char *p;
  832.  
  833.   if(!graphics)strcpy(clr_string,"\xc");
  834.   p=clr_string;
  835.   if(baud) while (*p++) while(!fossil(TRANSMIT,*p)) carrchk();
  836.   fputs("\x1b[0;2m\x1b[2J",stdout);
  837.   print_stat();
  838. }
  839.  
  840.  
  841. char pascal fossil (function,arg)   /*  HANDLES MOST USEFUL FOSSIL CALLS */
  842.  
  843. char function;
  844. char arg;
  845.  
  846. {
  847.  
  848.   if(!baud) return 0;
  849.   if ((function == FLUSHOUT) && (baud>0))
  850.     {
  851.      do {
  852.        carrchk();
  853.        rg.h.ah=3;
  854.        rg.x.dx=commport;
  855.        int86(20,&rg,&rg);
  856.       }
  857.      while ((rg.h.ah & 64)==0);
  858.      return(0);
  859.     }
  860.  
  861.   if (function == WATCHDOG) rg.h.al = arg;
  862.   if (function == DTR) rg.h.al = arg;
  863.   if (function == TRANSWAIT) rg.h.al = arg;
  864.   if (function == TRANSMIT) rg.h.al = arg;
  865.   if (function == ONOFF) rg.h.al = arg;
  866.  
  867.   rg.x.dx=commport;
  868.   rg.h.ah=function;
  869.   int86(20,&rg,&rg);
  870.  
  871.   if (function == INIT)
  872.     {
  873.      if (rg.x.ax != INITOK)
  874.       {
  875.        fputs("\nFossil not responding...RTFM.\n",stdout);
  876.        exit (3);
  877.       }
  878.      return (0);
  879.     }
  880.  
  881.   if (function == GETSTAT)
  882.     {
  883.       arg = rg.h.ah;
  884.       if (rg.h.al & 128)
  885.        {
  886.         arg |= 128;
  887.     return (arg);
  888.        }
  889.       arg &= 127;
  890.       return (arg);
  891.     }
  892.  
  893.   if (function == RECVWAIT) return (rg.h.al);
  894.   if (function == TRANSMIT) return (rg.x.ax);
  895.  
  896.   return (0);
  897.  
  898. }
  899.  
  900.  
  901.  
  902. void cdecl deinitialize (void)     /*  DEINITIALIZES FOSSIL ON EXIT */
  903.  
  904. {
  905.  
  906.     register word x;
  907.  
  908.  fossil(FLUSHOUT,0);
  909.  fossil (DEINIT,0);
  910.  fcloseall();
  911.  rg.x.ax=0x4400;         /* Set console in (std) cooked mode */
  912.  rg.x.bx=1;
  913.  int86(33,&rg,&rg);
  914.  rg.h.dh=0;
  915.  rg.h.dl=rg.h.dl&(~0x20);
  916.  rg.x.ax=0x4401;
  917.  int86(33,&rg,&rg);
  918.  printm("\n");
  919.  fputs("\x1b[0;2;37m\n",stdout);
  920. }
  921.  
  922.  
  923.  
  924. char * pascal genin (length,password,caps,hot,type)  /* GENERIC INPUT ROUTINE */
  925.  
  926. char length;
  927. char password;
  928. char caps;
  929. char hot;
  930. char type;
  931.  
  932. {
  933.  
  934. static char input[257];
  935. int x=0;
  936. char one=0;
  937. char randchr[2];
  938.  
  939.  length--;
  940.  
  941. AfterChat:
  942.  
  943.  strset(input,0);
  944.  startt=getxbbstime();
  945.  
  946.  while ((getxbbstime()-startt)<241 || (chatted!=0)) {
  947.  
  948.   one=inkey();
  949.   if (one == '\r') break;
  950.  
  951. Nogo:
  952.  
  953.   if (one == 8) {
  954.       if (x>0) {
  955.          printm(BACKSPACE);
  956.          input [--x]=0;
  957.          if ((type==PHONE) && ((x==2) or (x==5))) printm(BACKSPACE);
  958.          if ((type==DATE) && ((x==1) or (x==3))) printm(BACKSPACE);
  959.       }
  960.       continue;
  961.   }
  962.   if ((caps) or (type==YESNO) or (type==YESNOM) or (type==FLE) or (type==FLEW) or (type==FLEPW) or (type==FLEP)) one=toupper(one);
  963.   if (x <= length) {
  964.       if (type==NAME) {
  965.         if((isalpha(one)==0) && (one!=' ') && (one!='.') && (one!='-') or (x==0 && one==' ')) continue;
  966.         if ((one==' ') && (strchr(input,' ')!=NULL)) continue;
  967.       }
  968.       if (type==NEAT) {
  969.         if((isalnum(one)==0) && (one!=' ') or (x==0 && one==' ')) continue;
  970.       }
  971.       if ((type==NEAT) or (type==NAME)) {
  972.         if(x==0) {
  973.             one=toupper(one);
  974.         }
  975.         else one=tolower(one);
  976.       }
  977.       if((type==NEAT) or (type==NAME)) {
  978.         if((x>0) && ((input[x-1]==' ') or (input[x-1]=='.') or (input[x-1]=='-'))) one=toupper(one);
  979.       }
  980.       if ((type==SUBJECT) && (x==0)) one=toupper(one);
  981.       if ((type==SUBJECT) && (isprint(one)==0)) continue;
  982.       if ((type==ALLL) && (isprint(one)==0)) continue;
  983.       if ((type==ALLL) && (one==127)) one=8;
  984.       if ((type==ALPHA) && (isalpha(one)==0) && (one!=' ')) continue;
  985.       if (((type==NUM) or (type==PHONE) or (type==DATE)) and (isdigit(one)==0)) continue;
  986.       if ((type==ALPHANUM) and (isalnum(one)==0) and (one!=' ')) continue;
  987.       if (((type==YESNO) or (type==YESNOM)) and (one!='Y' and one!='N')) continue;
  988.       if (type==FLE) {
  989.          if ((isalnum(one)==0) and (!strchr("._-+=!@#$%^&<>/",one))) continue;
  990.       }
  991.       if (type==FLEP) {
  992.          if ((isalnum(one)==0) and (!strchr("._-+=!@#$%^&<>/\\:",one))) continue;
  993.       }
  994.       if (type==FLEW) {
  995.           if ((isalnum(one)==0) and (!strchr("._-+=!@#$%^&<>/?*",one))) continue;
  996.       }
  997.       if (type==FLEPW) {
  998.         if ((isalnum(one)==0) and (!strchr("._-+=!@#$%^&<>/?*\\:",one))) continue;
  999.       }
  1000.       if ((type==FLE) or (type==FLEP) or (type==FLEW) or (type==FLEPW)) {
  1001.          if ((one=='.') and (strchr(input,'.')!=NULL)) continue;
  1002.       }
  1003.    }
  1004.    if (chatted>0) {
  1005.     chatted=0;
  1006.     goto AfterChat;
  1007.    }
  1008.  
  1009.    if ((one!=0) and (x <= length)) {
  1010.       input[x]=one;
  1011.       input[++x]=0;
  1012.       if (type==YESNOM) {
  1013.                         return(input);
  1014.       }
  1015.       if (password==0) printm(&input[x-1]);
  1016.       if (password!=0) {
  1017.          randchr[0]=random(10)+33;
  1018.         randchr[1]=0;
  1019.         printm(randchr);
  1020.       }
  1021.       if ((type==PHONE) and ((x==3) or (x==6))) printm("-");
  1022.       if ((type==DATE) and ((x==2) or (x==4))) printm("/");
  1023. AfterCtrl:
  1024.       if ((hot!=0)and(x >= length)) {
  1025.             return (input);
  1026.       }
  1027.       startt=getxbbstime();
  1028.    }
  1029.  
  1030.   }
  1031.   if (chatted) {
  1032.     chatted=0;
  1033.     goto AfterChat;
  1034.   }
  1035.   if ((getxbbstime()-startt)>240) {
  1036.       fputs("\nUser time-out...\n",stdout);
  1037.       exit (2);
  1038.   }
  1039.   return (input);
  1040. }
  1041.  
  1042.  
  1043. char pascal carrchk (void)  /* Checks for carrier */
  1044.  
  1045. {
  1046.    if (baud) {
  1047.      rg.x.dx=commport;
  1048.      rg.h.ah=GETSTAT;
  1049.      int86(20,&rg,&rg);
  1050.      if (!(rg.h.al & 128)) {
  1051.        sleep(1);
  1052.        rg.x.dx=commport;
  1053.        rg.h.ah=GETSTAT;
  1054.        int86(20,&rg,&rg);
  1055.        if (!(rg.h.al & 128)) {
  1056.          fossil(DTR,DOWN);
  1057.          baud=0;
  1058.          fputs("\n\04 Lost carrier...\n",stdout);
  1059.          exit (1);
  1060.        }
  1061.      }
  1062.    return (rg.h.ah);
  1063.    }
  1064.    return 0;
  1065. }
  1066.  
  1067.  
  1068. void pascal hitreturn (void)  /* Pause until [Enter] is pressed */
  1069.  
  1070. {
  1071.  
  1072.   register word x;
  1073.  
  1074.            startt=getxbbstime();
  1075.            printm("\n[Enter] to continue...");
  1076.            while ((getxbbstime()-startt)<241) {
  1077.              if (inkey()==13) goto hedid;
  1078.            }
  1079.            fputs("\n\x4 User time-out...\n",stdout);
  1080.            exit (2);
  1081. hedid:
  1082.            for(x=0;x<22;x++) printm(BACKSPACE);
  1083. }
  1084.  
  1085.  
  1086. ulong pascal getxbbstime (void) { /* GP User Timer */
  1087.  
  1088. static int hour;
  1089. static int min;
  1090. static int sec;
  1091. static int lastsec;
  1092. static int x;
  1093. static int y;
  1094. static struct time dos_time;
  1095. static ulong xbbs_time;
  1096. static char byebye=0;
  1097. static int warned;
  1098.  
  1099.  gettime(&dos_time);
  1100.  
  1101.  hour=dos_time.ti_hour-starter.ti_hour;
  1102.  min=dos_time.ti_min-starter.ti_min;
  1103.  sec=dos_time.ti_sec-starter.ti_sec;
  1104.  
  1105.  if (dos_time.ti_hour<starter.ti_hour) hour=hour+24;
  1106.  
  1107.  xbbs_time=(long)(hour*3600)+(min*60)+sec;
  1108.  if(byebye) return xbbs_time;
  1109.  
  1110.  if (((timelimit*60)<(xbbs_time+120)) && (warned==0)) {
  1111.     warned++;
  1112.     printfm("\nWARNING: %u minutes remaining.",(timelimit-(xbbs_time)/60));
  1113.   }
  1114.  
  1115.  if (((timelimit*60) > ((xbbs_time+1L)+120L)) && (warned!=0)) warned=0;
  1116.  
  1117.  if ((timelimit*60) < (xbbs_time+1)) {
  1118.     byebye=1;
  1119.     timelimit=(word)(xbbs_time/60L)+4;
  1120.     printm("\nSorry, time to logoff...\n");
  1121.     fossil(FLUSHOUT,0);
  1122.     exit(0);
  1123.   }
  1124.  
  1125. juststarting:
  1126.  
  1127.     if(dos_time.ti_sec!=lastsec) {
  1128.         lastsec=dos_time.ti_sec;
  1129.         x=wherex();
  1130.         y=wherey();
  1131.         gotoxy(68,25);
  1132.         textbackground(7);
  1133.         textcolor(0);
  1134.         cprintf("%02d:%02d:%02d|%03u",dos_time.ti_hour,dos_time.ti_min,dos_time.ti_sec,(word)(timelimit-(word)(xbbs_time/60L)));
  1135.         gotoxy(x,y);
  1136.     }
  1137.     return(xbbs_time);
  1138. }
  1139.  
  1140.  
  1141. void pascal printinfo (void)  /* Just prints prog info locally */
  1142.  
  1143. {
  1144.  
  1145.   printf("  %s\n\04 %s\n\04 Compiled: %s  %s\n",PROGRAM_NAME,COPY_RIGHT,__DATE__,__TIME__);
  1146.  
  1147. }
  1148.  
  1149.  
  1150.  
  1151. char * pascal fidodate (void)    /* Builds a Fido(tm) datestring */
  1152.  
  1153. {
  1154.  
  1155.  char months[12][4]={
  1156.     "Jan",
  1157.     "Feb",
  1158.     "Mar",
  1159.     "Apr",
  1160.     "May",
  1161.     "Jun",
  1162.     "Jul",
  1163.     "Aug",
  1164.     "Sep",
  1165.     "Oct",
  1166.     "Nov",
  1167.     "Dec"
  1168.  };
  1169.  static char fdate[20];
  1170.  struct date dos_date;
  1171.  struct time dos_time;
  1172.  
  1173. /* 26 Jul 89  06:23:47 */
  1174.  
  1175.  getdate(&dos_date);
  1176.  gettime(&dos_time);
  1177.  
  1178.  sprintf(fdate,"%02hu %s %02d  %02hu:%02hu:%02hu",dos_date.da_day,months[dos_date.da_mon-1],dos_date.da_year%100,dos_time.ti_hour,dos_time.ti_min,dos_time.ti_sec);
  1179.  return(fdate);
  1180.  
  1181. }
  1182.  
  1183.  
  1184.  
  1185. char * pascal stripcr (char *a)  /* Strips trailing CR's & LF's */
  1186.  
  1187. {
  1188.  
  1189.   while (a[strlen(a)-1]=='\n' || a[strlen(a)-1]=='\r') a[strlen(a)-1]=0;
  1190.   return a;
  1191.  
  1192. }
  1193.  
  1194.  
  1195.  
  1196.  
  1197. char * pascal lstrip (char *a) {    /* Strips leading blanks */
  1198.  
  1199.   while (*a==' ') memmove (a,(a+1),strlen(a));
  1200.   return (a);
  1201. }
  1202.  
  1203.  
  1204.  
  1205. char * pascal rstrip (char *a) {    /* Strips trailing blanks */
  1206.  
  1207.   while (*a && a[strlen(a)-1]==' ') a[strlen(a)-1]=0;
  1208.   return a;
  1209. }
  1210.  
  1211.  
  1212.  
  1213. void cdecl debug_print (char *string,...) {  /* Local-only messages only
  1214.                                                 displayed if debug-mode is
  1215.                                                 turned on by ! argument */
  1216.  
  1217.  word tempbaud;
  1218.  static char buffer[318];
  1219.  
  1220.  va_list ap;
  1221.  va_start(ap,string);
  1222.  vsprintf(buffer,string,ap);
  1223.  va_end(ap);
  1224.  if(debug_mode){
  1225.     tempbaud=baud;
  1226.     baud=0;
  1227.     printm(buffer);
  1228.     baud=tempbaud;
  1229.  }
  1230. }
  1231.  
  1232.  
  1233.  
  1234. int cdecl printfm (char *string,...) {  /* Like printf() for local
  1235.                                            and remote */
  1236.  
  1237.  static char buffer[318];
  1238.  
  1239.  va_list ap;
  1240.  va_start(ap,string);
  1241.  vsprintf(buffer,string,ap);
  1242.  va_end(ap);
  1243.  return(printm(buffer));
  1244. }
  1245.  
  1246.  
  1247.  
  1248. char pascal printm (char *text) {    /* Prints local and remote */
  1249.  
  1250.     char *p;
  1251.  
  1252.     while ((p=strstr(text,"\x1b[2J"))!=NULL) {
  1253.        memmove(&p[1],&p[4],strlen(&p[4])+1);
  1254.        *p='\xc';
  1255.     }
  1256.     while ((p=strchr(text,'\x7')) && !sysopin) memmove(p,&p[1],strlen(&p[1])+1);
  1257.     while (p=strchr(text,'\r')) *p='\n';
  1258.     if (fast) {
  1259.         if(fast==1) {
  1260.             textbackground(0);
  1261.             textcolor(10);
  1262.         }
  1263.         if(fast==2) {
  1264.             textbackground(10);
  1265.             textcolor(0);
  1266.         }
  1267.     }
  1268.     while(*text) {
  1269.         if (*text=='\xc') {           /* Clear screen */
  1270.             cls();
  1271.             text++;
  1272.             continue;
  1273.         }
  1274.         if(*text=='\t') {
  1275.             text++;
  1276.             printm("    ");
  1277.             continue;
  1278.         }
  1279.         if (fast && *text!='\n') {
  1280.             putch(*text);
  1281.         }
  1282.         else if (fastANSI) {
  1283. Again1:
  1284.             _AX=(int)*text;
  1285.             geninterrupt(0x29);
  1286.             if(baud) while (!fossil(TRANSMIT,*text)) carrchk();
  1287.             if (*text=='\n') {
  1288.                 *text='\r';
  1289.                 goto Again1;
  1290.             }
  1291.         }
  1292.         else {
  1293. Again2:
  1294.             _DL=*text;
  1295.             _AH=2;
  1296.             geninterrupt(33);
  1297.             if(baud) while (!fossil(TRANSMIT,*text)) carrchk();
  1298.             if (*text=='\n') {
  1299.                 *text='\r';
  1300.                 goto Again2;
  1301.             }
  1302.         }
  1303.         text++;
  1304.         _AH=3;
  1305.         _BH=0;
  1306.         geninterrupt(16);
  1307.         if (_DH>23) checkpos();
  1308.      }
  1309.      getxbbstime();
  1310.      fast=0;
  1311. }
  1312.  
  1313.  
  1314. void pascal checkpos (void) {       /*  Protect status line */
  1315.  
  1316.         _AH=3;
  1317.         _BH=0;
  1318.         geninterrupt(16);
  1319.         if (_DH>23) {
  1320.             _AH=6;
  1321.             _AL=1;
  1322.             _BH=7;
  1323.             _CH=0;
  1324.             _CL=0;
  1325.             _DH=23;
  1326.             _DL=79;
  1327.             geninterrupt(16);
  1328.             _AH=2;
  1329.             _BH=0;
  1330.             _DL=0;
  1331.             _DH=23;
  1332.             geninterrupt(16);
  1333.         }
  1334. }
  1335.  
  1336.  
  1337.  
  1338.  
  1339. void pascal print_stat (void) {        /* Print status line */
  1340.  
  1341.     int x;
  1342.     int y;
  1343.  
  1344.     x=wherex();
  1345.     y=wherey();
  1346.     gotoxy(1,25);
  1347.     textbackground(7);
  1348.     textcolor(0);
  1349.     cprintf("%-31.31s \04 %31.31s\04             ",PROGRAM_NAME,username);
  1350.     gotoxy(x,y);
  1351. }
  1352.  
  1353.  
  1354.  
  1355. char * pascal addtolog (text)  /* WRITE LOGFILE ENTRIES */
  1356.  
  1357.  char *text;
  1358.  
  1359. {
  1360.  
  1361.  FILE *pf;
  1362.  char p[127];
  1363.  
  1364.  pf = fopen(logfile,"a");
  1365.  if (pf == NULL) return text;
  1366.  fseek(pf,0,SEEK_END);
  1367.  if (text[0]!='*') {
  1368.    strcpy(p,fidodate());
  1369.    p[16]=0;
  1370.    strcat(p,"  ");
  1371.    strncat(p,text,126-strlen(p));
  1372.    p[126]=0;
  1373.  }
  1374.  else {
  1375.         strncpy(p,text,79);
  1376.         p[79]=0;
  1377.  }
  1378.  fputs(p,pf);
  1379.  fputs("\n",pf);
  1380.  fclose(pf);
  1381.  return text;
  1382.  
  1383. }
  1384.  
  1385.  
  1386.  
  1387. #ifdef XBBS
  1388.  
  1389. void pascal readconfig (void)    /* Read CONFIG.BBS */
  1390.  
  1391. {
  1392.  
  1393. FILE *fp;
  1394. char s[15];
  1395.  
  1396.     if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
  1397.     else strcpy(s,"config.bbs");
  1398.  
  1399.     if(!(fp=fopen(s,"rb"))) {
  1400. Fatal:
  1401.        perror("\nCONFIG ERROR");
  1402. #ifndef DORINFO
  1403.        exit(1);
  1404. #endif
  1405.     }
  1406.   if (fread(&conf,sizeof(conf),1,fp)!=1) goto Fatal;
  1407.   fclose(fp);
  1408.   strcpy(system_name,conf.system);
  1409.   strcpy(sysop,conf.sysop);
  1410.   commport=conf.commport;
  1411.   strcpy(logfile,conf.logfile);
  1412.   sysopin=conf.sysopin;
  1413.   fastANSI=conf.fastANSI;
  1414.   directvideo=conf.dvideo;
  1415. }
  1416.  
  1417.  
  1418.  
  1419. void pascal getonline (void)    /* Read ONLINE.XBS */
  1420.  
  1421. {
  1422.  
  1423.   FILE *fp;
  1424.   char s[90];
  1425.   char numnode[4]="";
  1426.  
  1427.   if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
  1428.   sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
  1429.  
  1430.   if (!((fp=fopen(s,"rb")))) {
  1431.     printf("Can't open %s!\n",s);
  1432.     goto FatalError;
  1433.   }
  1434.   else {
  1435.       fread(&user,sizeof(struct _user),1,fp);
  1436.       fread(&userno,sizeof(userno),1,fp);
  1437.       fread(&timelimit,sizeof(timelimit),1,fp);
  1438.       fread(&timeon,sizeof(timeon),1,fp);
  1439.       fread(&starter,sizeof(starter),1,fp);
  1440.       fread(&baud,sizeof(baud),1,fp);
  1441.       fread(&pages,sizeof(pages),1,fp);
  1442.       fread(&age,sizeof(age),1,fp);
  1443.       fread(&timer_off,sizeof(timer_off),1,fp);
  1444.       fread(&hold_time,sizeof(hold_time),1,fp);
  1445.       fread(variable,(sizeof(variable[0])*10),1,fp);
  1446.       fread(&mboard,sizeof(mboard),1,fp);
  1447.       fread(&fboard,sizeof(fboard),1,fp);
  1448.       if (fread(event,(sizeof(struct _events)*10),1,fp)<1) {
  1449.         printf("Came up short!\n");
  1450.         goto FatalError;
  1451.       }
  1452.   }
  1453.   if (ferror(fp)) {
  1454. FatalError:
  1455.          perror("ONLINE READ");
  1456.          fclose(fp);
  1457. #ifndef DORINFO
  1458.          exit(1);
  1459. #endif
  1460.    }
  1461.    fclose(fp);
  1462.    strcpy(username,user.name);
  1463.    seclvl=user.stat[0];
  1464.    width=user.width;
  1465.    numlines=user.length;
  1466.    graphics=user.graphics;
  1467. }
  1468.  
  1469.  
  1470.  
  1471. void pascal prepare (void)        /* Rewrite ONLINE.XBS */
  1472.  
  1473. {
  1474.  
  1475.   FILE *fp;
  1476.   char s[90];
  1477.   char numnode[4]="";
  1478.  
  1479.  if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
  1480.  sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
  1481.  if(!(fp=fopen(s,"wb"))) perror("ONLINE OPEN");
  1482.  else {
  1483.   fwrite(&user,sizeof(struct _user),1,fp);
  1484.   fwrite(&userno,sizeof(userno),1,fp);
  1485.   fwrite(&timelimit,sizeof(timelimit),1,fp);
  1486.   fwrite(&timeon,sizeof(timeon),1,fp);
  1487.   fwrite(&starter,sizeof(starter),1,fp);
  1488.   fwrite(&baud,sizeof(baud),1,fp);
  1489.   fwrite(&pages,sizeof(pages),1,fp);
  1490.   fwrite(&age,sizeof(age),1,fp);
  1491.   fwrite(&timer_off,sizeof(timer_off),1,fp);
  1492.   fwrite(&hold_time,sizeof(hold_time),1,fp);
  1493.   fwrite(variable,sizeof(variable[0]),10,fp);
  1494.   fwrite(&mboard,sizeof(struct _mboard),1,fp);
  1495.   fwrite(&fboard,sizeof(struct _fboard),1,fp);
  1496.   fwrite(event,sizeof(struct _events),10,fp);
  1497.   if (ferror(fp)) perror("ONLINE WRITE");
  1498.   fclose(fp);
  1499.  }
  1500. }
  1501.  
  1502.  
  1503.  
  1504. void pascal saveconfig (void)     /* Rewrite CONFIG.BBS */
  1505.  
  1506. {
  1507.  
  1508.   FILE *fp;
  1509.   char s[14];
  1510.  
  1511.  if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
  1512.  else strcpy(s,"config.bbs");
  1513.  
  1514.  if (!(fp=fopen(s,"wb"))) perror("CONFIG OPEN");
  1515.  else {
  1516.    fwrite(&conf,sizeof(conf),1,fp);
  1517.    fclose(fp);
  1518.  }
  1519. }
  1520.  
  1521. #endif
  1522.  
  1523.  
  1524.  
  1525.  
  1526. #ifdef DORINFO
  1527.  
  1528. void pascal readinfo (void) {        /* Read DORINFO?.DEF */
  1529.  
  1530.     register int x;
  1531.     FILE *fp;
  1532.     char s[81];
  1533.  
  1534.     sprintf(s,"DORINFO%hu.DEF",nodenumber);
  1535.     if(!((fp=fopen(s,"rt")))) return;
  1536.     if(!fgets(s,81,fp)) goto EndIt;
  1537.     stripcr(s);
  1538.     s[63]=0;
  1539.     strcpy(system_name,s);
  1540.     if(!fgets(s,81,fp)) goto EndIt;
  1541.     stripcr(s);
  1542.     s[35]=0;
  1543.     strcpy(sysop,s);
  1544.     if(!fgets(s,81,fp)) goto EndIt;
  1545.     stripcr(s);
  1546.     s[35]=0;
  1547.     x=strlen(sysop);
  1548.     if(x<35) strcat(sysop," ");
  1549.     if(x<36) strncat(sysop,s,36-x);
  1550.     sysop[35]=0;
  1551.     if(!fgets(s,81,fp)) goto EndIt;
  1552.     if(atoi(&s[3])) commport=(char)atoi(&s[3]);
  1553.     if(commport)commport--;
  1554.     if(!fgets(s,81,fp)) goto EndIt;
  1555.     baud=(word)atol(s);
  1556.     if(!fgets(s,81,fp)) goto EndIt;
  1557.     if(!fgets(s,81,fp)) goto EndIt;
  1558.     stripcr(s);
  1559.     s[35]=0;
  1560.     strcpy(username,s);
  1561.     if(!fgets(s,81,fp)) goto EndIt;
  1562.     stripcr(s);
  1563.     s[35]=0;
  1564.     x=strlen(username);
  1565.     if(x<35) strcat(username," ");
  1566.     if(x<36)strncat(username,s,36-x);
  1567.     if(!fgets(s,81,fp)) goto EndIt;
  1568.     if(!fgets(s,81,fp)) goto EndIt;
  1569.     if(atoi(s)) graphics=1;
  1570.     if(!fgets(s,81,fp)) goto EndIt;
  1571.     seclvl=(word)atol(s);
  1572.     if(!fgets(s,81,fp)) goto EndIt;
  1573.     timelimit=(word)atol(s);
  1574. EndIt:
  1575.     fclose(fp);
  1576. }
  1577.  
  1578. #endif
  1579.  
  1580.  
  1581. #ifdef FINDUSER
  1582.  
  1583. word pascal finduser (char *users_name,struct _user *other) {
  1584.  
  1585.     /* Finds user named users_name in users.bbs unless user isn't there
  1586.        or user is locked out.  Returns user # and alters structure other
  1587.        to contain user's info.  Info is undefined if 0 is returned. */
  1588.  
  1589.     FILE *fp;
  1590.     int handle;
  1591.     register word xx;
  1592.     word tempuserno=0;
  1593.  
  1594.     if(findfirst(searchpath("users.bbs"),&f,0)) {
  1595.         printm("\nCan't find userfile.\n");
  1596.         return 0;
  1597.     }
  1598.     printfm("\nSearching for %s...",users_name);
  1599.     strupr(users_name);
  1600.     xx=0;
  1601.     if (!f.ff_fsize) {
  1602.         printm("\nNull-length userfile.\n");
  1603.         return 0;
  1604.     }
  1605.     if ((handle=_open(searchpath("USERS.BBS"),O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  1606.         printm("\nError opening userfile\n");
  1607.         return 0;
  1608.     }
  1609.     fp=fdopen(handle,"rb");
  1610.     rewind(fp);
  1611.     while (!feof(fp) && !ferror(fp)) {
  1612.          xx++;
  1613.          if (!(xx%50)) printm(".");
  1614.          if (fread(other,sizeof(struct _user),1,fp)!=1) break;
  1615.          strupr(other->name);
  1616.          strupr(other->handle);
  1617.          if (!(strcmp(other->name,users_name)) && (!other->deleted)) break;
  1618.          if (!(strcmp(other->handle,users_name)) && (!other->deleted)) break;
  1619.     }
  1620.     if (((strcmp(other->name,users_name)) && (strcmp(other->handle,users_name))) || (other->deleted)) goto notfound;
  1621.     if (!other->stat[0]) goto notfound;
  1622.     tempuserno=(word)(ftell(fp)/(long)sizeof(struct _user));
  1623.     fclose(fp);
  1624.     _close(handle);
  1625.  
  1626.     if (!tempuserno) {
  1627. notfound:
  1628.         fclose(fp);
  1629.         _close(handle);
  1630.         printfm("\n%s not found.\n",users_name);
  1631.         return 0;
  1632.     }
  1633.     return tempuserno;
  1634. }
  1635.  
  1636. #endif
  1637.