home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / XMISC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  25.2 KB  |  859 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*   XBBS SOURCE CODE copyright (c) 1990 by M. Kimes                        */
  4. /*   All Rights Reserved                                                    */
  5. /*                                                                          */
  6. /*    For complete details of the licensing restrictions, please refer      */
  7. /*    to the License agreement, which is published in its entirety in       */
  8. /*    the in the file LICENSE.XBS.                                          */
  9. /*                                                                          */
  10. /*    USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE      */
  11. /*    XBBS LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF            */
  12. /*    THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO       */
  13. /*    NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES         */
  14. /*    AT THE ADDRESS LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO USE   */
  15. /*    THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING     */
  16. /*    AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH      */
  17. /*    M. KIMES                                                              */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /* You can contact M. Kimes at the following address:                       */
  21. /*                                                                          */
  22. /* M. Kimes                         1:380/16.0@FidoNet                      */
  23. /* 542 Merrick                      (318)222-3455 data                      */
  24. /* Shreveport, LA  71104                                                    */
  25. /*                                                                          */
  26. /*                                                                          */
  27. /* Please feel free to contact me at any time to share your comments about  */
  28. /* my software and/or licensing policies.                                   */
  29. /*                                                                          */
  30. /*--------------------------------------------------------------------------*/
  31. /*======================================================================*/
  32. /*  XBBS Bulletin Board System.....Miscellaneous                        */
  33. /*======================================================================*/
  34.  
  35. #include "msg.h"
  36. #include "xext.h"
  37.  
  38. extern void pascal CLEAROVERLAY (void);
  39.  
  40.  
  41.  
  42. void pascal hitreturn (void) {
  43.  
  44.   char tempause;
  45.  
  46.            tempause=pauser;
  47.            pauser=0;
  48.            say_prompt(194);
  49.            fossil(FLUSHOUT,0);
  50.            fossil(PURGEIN,0);
  51.            start=getxbbstime();
  52.            while ((getxbbstime()-start)<(conf.idleseconds+1)) {
  53.              if (inkey()==13 || chatted) goto hedid;
  54.            }
  55.            say_prompt(195);
  56.            logoff();
  57.            userno=0;
  58.            leaving++;
  59.            exit (254);
  60. hedid:
  61.            chatted=0;
  62.            say_prompt(273);
  63.            pauser=tempause;
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. char * pascal say_prompt (word x) {
  71.  
  72.     static char s[257];
  73.     long pos;
  74.     char *filenamep;
  75.     char *filenamei;
  76.     char *p;
  77.  
  78.     if (conf.promptsay) {
  79.         gprintf(LOCALONLY,"\n\x4 Prompt #%u\n",x);
  80.     }
  81.  
  82.     if (prompthandle==-1) {
  83. ReOpen:
  84.         if (user.graphics) filenamep="XBBS.GXT";
  85.         else filenamep="XBBS.TXT";
  86.         if (searchpath(filenamep)==NULL) filenamep="XBBS.TXT";
  87.         if ((prompthandle=_open(searchpath(filenamep),O_RDONLY | O_TEXT | O_DENYNONE))==-1) {
  88.             lprint("\n\x4 Can't open XBBS.?XT\n");
  89.             exit(1);
  90.         }
  91.     }
  92.     if (indexhandle==-1) {
  93. ReOpen2:
  94.         if (!strcmp(filenamep,"XBBS.GXT")) filenamei="XBBS.GDX";
  95.         if (searchpath(filenamei)==NULL) filenamei="XBBS.IDX";
  96.         if ((indexhandle=_open(searchpath(filenamei),O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  97.             lprint("\n\x4 Can't open XBBS.?DX\n");
  98.             exit(1);
  99.         }
  100.     }
  101.  
  102.     if (lseek(indexhandle,(long)(x*(word)sizeof(long)),SEEK_SET)==-1) {
  103.         goto ReOpen2;
  104.     }
  105.     if (_read(indexhandle,&pos,sizeof(long))<1) {
  106.         lprint("\n\x4 Read error\n");
  107.     }
  108.     if (lseek(prompthandle,pos,SEEK_SET)==-1) {
  109.         goto ReOpen;
  110.     }
  111.     getline(s);
  112.     pos=tell(prompthandle);
  113.     lastprompt=x;
  114.     while (1) {
  115. ReLoopIt:
  116.         switch ((int)*s) {
  117.             case 1:
  118.             case 255:
  119.                         return NULL;
  120.             case 28:    printm(center(convertstring(&s[1]),user.length));
  121.                         break;
  122.             case 25:    printm(r_just(convertstring(&s[1]),user.length));
  123.                         break;
  124.             case 24:    p=&s[1];
  125.                         xmenu(p);
  126.                         break;
  127.             case 23:    p=strtok(&s[1],", ");
  128.                         find_help(p,strtok(0,"\n"),0);
  129.                         break;
  130.             case 22:    if(!user.commodore) break;
  131.                         memmove(s,&s[1],strlen(&s[1])+1);
  132.                         goto ReLoopIt;
  133.             case 21:    if(!user.twit) break;
  134.                         memmove(s,&s[1],strlen(&s[1])+1);
  135.                         goto ReLoopIt;
  136.             case 20:    if(user.expert) break;
  137.                         memmove(s,&s[1],strlen(&s[1])+1);
  138.                         goto ReLoopIt;
  139.             case 19:    cls();
  140.                         break;
  141.             case 18:    stripcr(&s[1]);
  142.                         pos=tell(prompthandle);
  143.                         p=convertstring(&s[1]);
  144.                         strtok(p," ");
  145.                         if(!load_topics(&s[1])) break;
  146.                         p=strtok(0,"\n");
  147.                         if(p)set_topic(p);
  148.                         display_topic(user.stat[0],&p);
  149.                         if(lseek(prompthandle,pos,SEEK_SET)==-1) return NULL;
  150.                         break;
  151.             case 17:    hitreturn();
  152.                         break;
  153.             case 16:    return convertstring(&s[1]);
  154.             case 15:    stripcr(&s[1]);
  155.                         system(convertstring(&s[1]));
  156.                         break;
  157.             case 14:    stripcr(&s[1]);
  158.                         pos=tell(prompthandle);
  159.                         readtext(convertstring(&s[1]));
  160.                         if(lseek(prompthandle,pos,SEEK_SET)==-1) return NULL;
  161.                         break;
  162.             case 11:    stripcr(&s[1]);
  163.                         pos=tell(prompthandle);
  164.                         readfile(convertstring(&s[1]),0,0,1);
  165.                         if(lseek(prompthandle,pos,SEEK_SET)==-1) return NULL;
  166.                         break;
  167.             case 6:        if (user.graphics) break;
  168.                         memmove(s,&s[1],strlen(&s[1])+1);
  169.                         goto ReLoopIt;
  170.             case 5:     if (!user.graphics) break;
  171.                         memmove(s,&s[1],strlen(&s[1])+1);
  172.                         goto ReLoopIt;
  173.             case 4:        lprint(convertstring(s));
  174.                         break;
  175.             case 3:     addtolog(convertstring(&s[1]));
  176.                         break;
  177.             case 2:        return &s[1];
  178.             default:    printm(convertstring(s));
  179.         }
  180.         lseek(prompthandle,pos,SEEK_SET);
  181.         getline(s);
  182.         pos=tell(prompthandle);
  183.     }
  184.     return NULL;
  185. }
  186.  
  187.  
  188. void pascal getline (char *s) {
  189.  
  190.     if (fgetsx(s,256,prompthandle)==NULL) {
  191.         *s=255;
  192.         s[1]=0;
  193.         return;
  194.     }
  195.     if (*s=='\x1' || *s==0) return;
  196.     s[strlen(s)-1]=0;
  197.     if (s[strlen(s)-1]==';') s[strlen(s)-1]=0;
  198.     else s[strlen(s)]='\n';
  199. }
  200.  
  201.  
  202.  
  203. char * pascal convertstring (char *a) {
  204.  
  205. word temp;
  206. char arg=0;
  207. char *ppp;
  208. char *pp;
  209. char *p;
  210. char strr[256];
  211. char middle[82];
  212.  
  213.    strset(strr,0);
  214.    strset(cvstr,0);
  215.    strcpy(strr,a);
  216.    p=strr;
  217.    pp=cvstr;
  218.    while(*p) {
  219.         if (*p=='*' && p[1]) {
  220.            arg=p[1];
  221.            p+=2;
  222.            switch ((int)arg) {
  223.              case 'Q':    sprintf(middle,"%08lu.%03hu",user.id,user.node);
  224.                           strcat(pp,middle);
  225.                           break;
  226.              case 'D':          /* DOWNLOAD PATH */
  227.              case 'd':    strcat(pp,fboard.dpath);
  228.                           while(*pp) pp++;
  229.                           if (arg=='d') if (*cvstr) *(--pp)=0;
  230.                           break;
  231.              case 'U':          /* UPLOAD PATH */
  232.              case 'u':    strcat(pp,fboard.upath);
  233.                           while(*pp) pp++;
  234.                           if (arg=='u') if (*cvstr) *(--pp)=0;
  235.                           break;
  236.              case 'N':          /* REAL NAME  */
  237.                           strcat(pp,user.name);
  238.                           break;
  239.              case 'F':          /* FIRST NAME */
  240.                           strcat(pp,user.handle);
  241.                           if (strchr(user.handle,' ')) {
  242.                             while(*pp!=' ') pp++;
  243.                             *pp=0;
  244.                           }
  245.                           break;
  246.              case 'L':          /* LAST NAME */
  247.                           if (strchr(user.handle,' ')) {
  248.                             ppp=user.handle;
  249.                             while(*ppp!=' ') ppp++;
  250.                             ppp++;
  251.                             strcat(pp,ppp);
  252.                           }
  253.                           break;
  254.              case 'T':           /* TIME REMAINING */
  255.                           sprintf(middle,"%u",(timelimit-(getxbbstime()/60)));
  256.                           strcat(pp,middle);
  257.                           break;
  258.              case 't':           /* TIME REMAINING -2 */
  259.                           temp=(word)((timelimit-(getxbbstime()/60))-2);
  260.                           if (temp<=0) strcpy(middle,"1");
  261.                           else sprintf(middle,"%u",temp);
  262.                           strcat(pp,middle);
  263.                           break;
  264.              case 'B':           /* BAUD RATE */
  265.                           sprintf(middle,"%u",baud);
  266.                           strcat(pp,middle);
  267.                           break;
  268.              case 'R':
  269.                           sprintf(middle,"%u",userno);
  270.                           strcat(pp,middle);
  271.                           break;
  272.              case 'G':
  273.                           sprintf(middle,"%hu",(user.graphics));
  274.                           strcat(pp,middle);
  275.                           break;
  276.              case 'P':
  277.                           sprintf(middle,"%u",conf.commport);
  278.                           strcat(pp,middle);
  279.                           break;
  280.              case 'p':
  281.                           sprintf(middle,"%u",conf.commport+1);
  282.                           strcat(pp,middle);
  283.                           break;
  284.              case 'C':
  285.                           sprintf(middle,"%d",user.credit);
  286.                           strcat(pp,middle);
  287.                           break;
  288.              case 'l':
  289.                           sprintf(middle,"%u",user.length);
  290.                           strcat(pp,middle);
  291.                           break;
  292.              case 'w':
  293.                           sprintf(middle,"%u",user.width);
  294.                           strcat(pp,middle);
  295.                           break;
  296.              case 'A':
  297.                           sprintf(middle,"%hu",user.arq);
  298.                           strcat(pp,middle);
  299.                           break;
  300.              case 'S':
  301.                           sprintf(middle,"%hu",user.commodore);
  302.                           strcat(pp,middle);
  303.                           break;
  304.              case 'a':
  305.                           sprintf(middle,"%hu",age);
  306.                           strcat(pp,middle);
  307.                           break;
  308.              case 's':
  309.                           sprintf(middle,"%u",user.stat[*p -'0']);
  310.                           p++;
  311.                           strcat(pp,middle);
  312.                           break;
  313.              case 'n':
  314.                           sprintf(middle,"%hu",nodenumber);
  315.                           strcat(pp,middle);
  316.                           break;
  317.              case '0':
  318.              case '1':
  319.              case '2':
  320.              case '3':
  321.              case '4':
  322.              case '5':
  323.              case '6':
  324.              case '7':
  325.              case '8':
  326.              case '9':
  327.                           strcat(pp,variable[arg-'0']);
  328.                           break;
  329.              case 'm':
  330.                           sprintf(middle,"%u",mboard.number);
  331.                           strcat(pp,middle);
  332.                           break;
  333.              case 'f':
  334.                           sprintf(middle,"%u",user.attr2);
  335.                           strcat(pp,middle);
  336.                           break;
  337.              case '#':
  338.                           if (*p=='2') strcat(pp,user.phone2);
  339.                           else strcat(pp,user.phone1);
  340.                           p++;
  341.                           break;
  342.              case 'c':
  343.                           strcat(pp,assocfile);
  344.                           break;
  345.              case 'k':
  346.                           sprintf(middle,"%u",keymess);
  347.                           strcat(pp,middle);
  348.                           break;
  349.              case 'M':
  350.                           arg=*p;
  351.                           p++;
  352.                           if (arg=='0') strcpy(middle,msg.from);
  353.                           else if (arg=='1') strcpy(middle,msg.to);
  354.                           else if (arg=='2') strcpy(middle,msg.subj);
  355.                           else if (arg=='3') strcpy(middle,msg.date);
  356.                           else if (arg=='4') sprintf(middle,"%u:%u/%u.%01u",msg.o_zone,msg.orig_net,msg.orig,msg.o_point);
  357.                           else if (arg=='5') sprintf(middle,"%u:%u/%u.%01u",msg.d_zone,msg.dest_net,msg.dest,msg.d_point);
  358.                           else if (arg=='6') sprintf(middle,"%u",msg.times);
  359.                           else if (arg=='7') sprintf(middle,"%d",msg.cost);
  360.                           else if (arg=='8') sprintf(middle,"%u",msg.attr);
  361.                           else if (arg=='9') sprintf(middle,"%u",msg.m_attr);
  362.                           else break;
  363.                           strcat(pp,middle);
  364.                           break;
  365.              case '!':    strcat(pp,user.city);
  366.                           break;
  367.              case '@':    strcat(pp,user.state);
  368.                           break;
  369.              case 'H':    sprintf(middle,"%X",level);
  370.                           strcat(pp,middle);
  371.                           break;
  372.              case 'e':    sprintf(middle,"%u",level);
  373.                           strcat(pp,middle);
  374.                           break;
  375.              case ':':    strcat(pp,messpath);
  376.                           break;
  377.              case 'Z':    sprintf(middle,"%u:%u/%u.0@%s",conf.zone,conf.net,conf.node,conf.domain);
  378.                           strcat(pp,middle);
  379.                           break;
  380.              case 'z':    sprintf(middle,"%u:%u/%u.0@%s",conf.alt_zone,conf.alt_net,conf.alt_node,conf.alt_domain);
  381.                           strcat(pp,middle);
  382.                           break;
  383.              case 'r':    strcat(pp,conf.lastcaller);
  384.                           break;
  385.              case 'O':    strncpy(middle,sysval(p),82);     /* Must be last; terminates */
  386.                           middle[81]=0;
  387.                           strcat(pp,middle);
  388.                           *p=0;
  389.                           break;
  390.              case 'o':    sprintf(middle,"%lx",conf.callcount);
  391.                           strcat(pp,middle);
  392.                           break;
  393.              case '*':    strcat(pp,mboard.name);
  394.                           break;
  395.              case '&':    sprintf(middle,"%u",mboard.attr);
  396.                           strcat(pp,middle);
  397.                           break;
  398.              case '$':    strcat(pp,fboard.name);
  399.                           break;
  400.              case '^':    strcat(pp,fidodate());
  401.                           break;
  402.              case '%':    strcat(pp,getdttm());
  403.                           while(*pp)pp++;
  404.                           pp--;
  405.                           *pp=0;
  406.                           break;
  407.              case '(':    strcat(pp,saydate(&user.lastdate));
  408.                           break;
  409.              case ')':    strcat(pp,saytime(&user.lasttime));
  410.                           break;
  411.              case 'V':    strcat(pp,user.variable[*p-'0']);
  412.                           p++;
  413.                           break;
  414.              case 'v':    sprintf(middle,"%u",user.numvars[*p-'0']);
  415.                           p++;
  416.                           strcat(pp,middle);
  417.                           break;
  418.              case 'g':    strcat(pp,dlstr);
  419.                           break;
  420.              case 'I':    strcat(pp,msginfo);
  421.                           break;
  422.              case 'h':    strcat(pp,conf.homepath);
  423.                           break;
  424.              case 'E':    strcat(pp,conf.menupath);
  425.                           break;
  426.              case '|':    strcat(pp,"\r\n");
  427.                           break;
  428.              case '~':    strcat(pp,"\r");
  429.                           break;
  430.              case '{':    ppp=middle;
  431.                           *ppp=0;
  432.                           while((isdigit(*p) || isalpha(*p)) && ppp<(middle+81)) {
  433.                             *ppp=*p;
  434.                             ppp++;
  435.                             p++;
  436.                             *ppp=0;
  437.                           }
  438.                           if(*p && *p==' ')p++;    /* Go past trailing blank */
  439.                           ppp=middle;
  440.                           ppp=lookup_var(ppp);
  441.                           strncat(cvstr,ppp,511-strlen(cvstr));
  442.                           cvstr[511]=0;
  443.                           break;
  444.              default:     strcat(pp,"*");
  445.                           p--;
  446.                           break;
  447.            }
  448.         }
  449.         else {
  450.             *pp=*p;
  451.             pp[1]=0;
  452.             p++;
  453.         }
  454.         while(*pp)pp++;
  455.    }
  456.    return (cvstr);
  457. }
  458.  
  459.  
  460. word pascal tellabout (char type) {
  461.  
  462.  char filename[127];
  463.  word nomess;
  464.  static char ninetyfour[48]="";
  465.  static char ninetyfive[64]="";
  466.  static char ninetysix[48]="";
  467.  static char ninetyseven[48]="";
  468.  static char threetwoeight[48]="";
  469.  
  470.  if (!strlen(ninetyfive)) {
  471.     strncpy(ninetyfour,say_prompt(94),48);
  472.     ninetyfour[47]=0;
  473.     strncpy(ninetyfive,say_prompt(95),64);
  474.     ninetyfive[63]=0;
  475.     strncpy(ninetysix,say_prompt(96),48);
  476.     ninetysix[47]=0;
  477.     strncpy(ninetyseven,say_prompt(97),48);
  478.     ninetyseven[47]=0;
  479.     strncpy(threetwoeight,say_prompt(328),48);
  480.     threetwoeight[47]=0;
  481.  }
  482.  
  483.  sprintf(filename,"%sXDATA.%03x",messpath,mboard.number);
  484.  
  485.  if (type<2) {
  486.    gprintf(0,"\n%s%-04u: %s * ",ninetyfive,mboard.number,mboard.name);
  487.  }
  488.  
  489.  if (findfirst(filename,&filestat,0)) {
  490.   if (type<2) {
  491.     printm(ninetyfour);
  492.     if (!type) printm("\n");
  493.   }
  494.   return 0;
  495.  }
  496.  nomess=(word)((filestat.ff_fsize/(long)sizeof(struct _xmsg)));
  497.  if (mboard.number<(conf.nolmrs+1)) if (lastread[mboard.number-1]>nomess) lastread[mboard.number-1]=nomess;
  498.  if (mboard.number<(conf.nolmrs+1)) if (lastread[mboard.number-1]<0) lastread[mboard.number-1]=0;
  499.  
  500.  if (type<2) {
  501.      gprintf(0,"%u%s",nomess,ninetysix);
  502.  }
  503.  if (mboard.number<(conf.nolmrs+1)) {
  504.     if ((nomess) && (lastread[mboard.number-1]<nomess)) {
  505.        if (type<2) {
  506.           gprintf(0,"%s%u",ninetyseven,lastread[mboard.number-1]+1);
  507.           if (!type) printm("\n");
  508.        }
  509.     }
  510.     else {
  511.        if (type<2) {
  512.           printm(threetwoeight);
  513.           if (!type) printm("\n");
  514.        }
  515.        return 0;
  516.     }
  517.  }
  518.  return 1;
  519. }
  520.  
  521.  
  522. void cdecl deinitialize (void) {   /*  DEINITIALIZES FOSSIL ON EXIT */
  523.  
  524.  conf.trace=0;
  525.  fossil(FLUSHOUT,0);
  526.  fossil(DEINIT,0);
  527.  fputs("\x1b[0;2;37m",stdout);
  528.  r.x.ax=0x4400;            /* Set console in (std) cooked mode */
  529.  r.x.bx=1;
  530.  int86(33,&r,&r);
  531.  r.h.dh=0;
  532.  r.h.dl=r.h.dl&(~0x20);
  533.  r.x.ax=0x4401;
  534.  int86(33,&r,&r);
  535.  ccloseall();
  536.  ffreeall();
  537.  CLEAROVERLAY();
  538. }
  539.  
  540.  
  541.  
  542. char * pascal fgetsx (char *str,int num,int handle) {
  543.  
  544.     char *p;
  545.     long pos;
  546.     int x;
  547.  
  548.     if (eof(handle)) {
  549.         *str=0;
  550.         return NULL;
  551.     }
  552.     pos=tell(handle);
  553.     x=_read(handle,str,num-1);
  554.     if (x<1) {
  555.         *str=0;
  556.         return NULL;
  557.     }
  558.     str[x]=0;
  559.     p=str;
  560.     while(*p && *p!='\r' && *p!='\n') p++;
  561.     if(!*p) return str;
  562.     if(*p=='\r') {
  563.         *p='\n';
  564.         if (p[1]=='\n') {
  565.             p++;
  566.             *p=0;
  567.         }
  568.     }
  569.     p++;
  570.     *p=0;
  571.     lseek(handle,pos+((long)((word)p-(word)str)),SEEK_SET);
  572.     return str;
  573. }
  574.  
  575.  
  576. long pascal findlabel (char *label,int handle) {
  577.  
  578.     long pos;
  579.     long len;
  580.     int x;
  581.     char *p;
  582.     char labelmaker[90];
  583.  
  584.     sprintf(labelmaker,"\x1%s\r\n",label);
  585.  while (1) {
  586.     pos=tell(handle);
  587.     if ((x=_read(handle,buffer,1024))<1) return -1L;
  588.     buffer[x]=0;
  589.     if ((p=strstr(buffer,labelmaker))!=NULL) break;
  590.     if(x<1024) return -1L;
  591.     pos=tell(handle);
  592.     lseek(handle,pos-(long)(strlen(labelmaker)+3),SEEK_SET);
  593.  }
  594.  len=(long)(((int)p-(int)buffer)+strlen(labelmaker));
  595.  return (len+pos);
  596. }
  597.  
  598.  
  599. char cdecl gprintf (char flag,char *string,...) {
  600.  
  601.  char p=0;
  602.  
  603.  va_list ap;
  604.  va_start(ap,string);
  605.  vsprintf(buffer,string,ap);
  606.  va_end(ap);
  607.  if (!flag) return printm(buffer);
  608.  if (flag & MODEMONLY) mprint(buffer);
  609.  if (flag & LOGONLY) addtolog(buffer);
  610.  if (flag & LOCALONLY) p+=lprint(buffer);
  611.  if (flag & ANSIONLY) if (user.graphics) p+=printm(buffer);
  612.  if (flag & ASCIIONLY) if (!user.graphics) p+=printm(buffer);
  613.  if (flag & BOFEM) p+=printm(buffer);
  614.  return p;
  615. }
  616.  
  617.  
  618.  
  619. int cdecl ffprintf (int handle,char *string,...) {
  620.  
  621.  va_list ap;
  622.  va_start(ap,string);
  623.  vsprintf(buffer,string,ap);
  624.  va_end(ap);
  625.  _write(handle,buffer,strlen(buffer));
  626.  return strlen(buffer);
  627. }
  628.  
  629.  
  630. void pascal saveconfig (void) {
  631.  
  632.   int fp;
  633.   char s[14];
  634.  
  635.  if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
  636.  else strcpy(s,"config.bbs");
  637.  
  638.  cclose(ccreat(s,S_IWRITE));
  639.  if ((fp=oopen(s,O_RDWR | O_BINARY | O_DENYNONE))==-1) {
  640.     if ((fp=ccreat(s,S_IWRITE))==-1) {
  641.         lprint("\n\04Can't create CONFIG.BBS\n");
  642.     }
  643.  }
  644.  else {
  645.    _write(fp,&conf,sizeof(struct _config));
  646.    cclose(fp);
  647.  }
  648. }
  649.  
  650.  
  651.  
  652. void pascal spit (odds,qfile)        /* Spit out a random quote from    */
  653.                                      /* Quote file (index one in config */
  654. char odds;
  655. char *qfile;
  656.  
  657. {
  658.  
  659.  int handle;
  660.  char isitindex=0;
  661.  long index;
  662.  struct ffblk f;
  663.  char quote[81]="";
  664.  
  665.    if (odds) if (random(10)<odds) return;
  666.    if (findfirst(qfile,&f,0)) return;
  667.    if(!strcmp(conf.quote_file,qfile)) {
  668.         isitindex=1;
  669.         if ((handle=oopen(qfile,O_RDONLY | O_TEXT | O_DENYNONE))==-1) return;
  670.         if(conf.quote_pos>=f.ff_fsize) conf.quote_pos=0;
  671.         lseek(handle,conf.quote_pos,SEEK_SET);
  672.    }
  673.    else {
  674.         if (f.ff_fsize<160L) return;
  675.         if ((handle=oopen(qfile,O_RDONLY | O_TEXT | O_DENYNONE))==-1) return;
  676.         if (f.ff_fsize<32768L) {
  677.             index=(long)random((int)f.ff_fsize-160L);
  678.         }
  679.         else {
  680.             index=(long)random((int)((f.ff_fsize/32767L)*32767L));
  681.             index+=(long)random((int)(f.ff_fsize-((f.ff_fsize/32767L)*32767L)-160L));
  682.         }
  683.         if (index>f.ff_fsize) index=0;
  684.             lseek(handle,index,SEEK_SET);
  685.         while ((*quote!='\n' && strcmp(quote,"\x1\n")) && !eof(handle)) {
  686.             index=tell(handle);
  687.             if (fgetsx(quote,81,handle)==NULL) break;
  688.         }
  689.    }
  690.    while (!eof(handle)) {
  691.     if (fgetsx(quote,81,handle)==NULL) {
  692.         if(isitindex)conf.quote_pos=0;
  693.         break;
  694.     }
  695.     if(isitindex)conf.quote_pos=tell(handle);
  696.     if (*quote=='\n' || !strcmp(quote,"\x1\n")) break;
  697.     printm(quote);
  698.    }
  699. Outtahere:
  700.    cclose(handle);
  701. }
  702.  
  703.  
  704. void pascal left (char *a,char *b,int x) {
  705.  
  706.   int i=0;
  707.  
  708.   x = (x <= strlen(b)) ? x : strlen(b);
  709.  
  710.   while (i++ < x) *a++ = *b++;
  711.  
  712.     *a = '\0';
  713.  
  714. }
  715.  
  716.  
  717. void pascal right (char *a, char *b, int x) {
  718.  
  719.   int i,l;
  720.  
  721.   l = strlen(b);
  722.   x=(x>l) ? l : x;
  723.   i = l - x;
  724.  
  725.   while (*a++ = *(b + i++));
  726.  
  727. }
  728.  
  729.  
  730. void pascal mid (char *a,char *b,int x,int y) {
  731.  
  732.   int l;
  733.  
  734.   --x;
  735.   y+=x;
  736.   l = strlen(b);
  737.  
  738.   while (x<y && x<=l) *a++ = *(b + x++);
  739.  
  740.   *a = '\0';
  741.  
  742. }
  743.  
  744.  
  745. void pascal mids (char *a,int x,int y,char *b) {
  746.  
  747.   int l;
  748.  
  749.   l = strlen(a) - 1;
  750.   y += x;
  751.   --x;
  752.  
  753.   while (x <= y && x <= l && *b != '\0') *(a + x++) = *b++;
  754.  
  755. }
  756.  
  757.  
  758.  
  759. char * pascal rstrip (char *a) {
  760.  
  761.   register int x;
  762.  
  763.   x=strlen(a);
  764.   while (x && a && a[x-1]==' ') a[--x]=0;
  765.   return a;
  766. }
  767.  
  768.  
  769.  
  770. char * pascal lstrip (char *a) {
  771.  
  772.   register int x;
  773.  
  774.   x=strlen(a);
  775.   while (x && *a==' ') memmove (a,(a+1),x--);
  776.   return (a);
  777. }
  778.  
  779.  
  780.  
  781. char * pascal stristr (char *t, char *s) {
  782.  
  783.    char *t1;
  784.    char *s1;
  785.  
  786.    while(*t) {
  787.       t1=t;
  788.       s1=s;
  789.       while(*s1) {
  790.          if (toupper(*s1)!=toupper(*t)) break;
  791.          else {
  792.             s1++;
  793.             t++;
  794.          }
  795.       }
  796.       if (!*s1) return t1;
  797.       t=t1+1;
  798.    }
  799.    return NULL;
  800. }
  801.  
  802.  
  803.  
  804. word pascal chk_scroll_lock (void) {
  805.  
  806.   if ((peekb(0,1047) & 0x10)==0) return(0);
  807.   else return(1);
  808. }
  809.  
  810.  
  811.  
  812. char * pascal r_just (char *str, int size) {
  813.  
  814.     char *s, *d;
  815.     register int len, count;
  816.  
  817.     if(size>79) size=79;
  818.     lstrip(rstrip(str));
  819.     len = strlen(str);                  /* get string length */
  820.     if (len > size) str[size] = 0x00;   /* truncate, if necessary */
  821.     else if (len < size) {
  822.         d = str + size;                 /* copy to leave room */
  823.         s = str + len;
  824.         count = len + 1;
  825.         while (count--) *d-- = *s--;
  826.         count = size - len;             /* number of blanks to insert */
  827.         s = str;
  828.         while (count--) *s++ = ' ';     /* add leading blanks */
  829.     }
  830.     return str;
  831. }
  832.  
  833.  
  834. char * pascal center (char *line, int linlen) { /* center string */
  835.  
  836.     register int count, len;
  837.     char *d,*s;
  838.  
  839.     if(linlen>79) linlen=79;
  840.     lstrip(rstrip(line));
  841.     len = strlen(line);   /* get non-blank length */
  842.     if(len>linlen) {
  843.         line[linlen-1]=0;
  844.     }
  845.     else {
  846.         /* leading blanks */
  847.         d = line + linlen;                 /* copy to leave room */
  848.         s = line + len;
  849.         count = (len + 1)/2;
  850.         while (count--) *d-- = *s--;
  851.         count = linlen - len;             /* number of blanks to insert */
  852.         s = line;
  853.         while (count--) *s++ = ' ';     /* add leading blanks */
  854.     }
  855.          /* non-blank chars */
  856.     return line;
  857. }
  858.  
  859.