home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / XANSI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  34.6 KB  |  1,143 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.....ANSI pulldown & cursor menus         */
  33. /*  Copyright (c) 1990 by M. Kimes -- All Rights Reserved               */
  34. /*======================================================================*/
  35.  
  36. #include "msg.h"
  37. #include "xext.h"
  38.  
  39.  
  40.  
  41. char pascal ansimenu2 (char tcolor,char color,char *title,char *line, char top, char down, char *hyperhelp) {
  42.  
  43.     register word x;
  44.     register word y;
  45.     char nump;
  46.     char numpp;
  47.     char *p[10];
  48.     char *pp[10];
  49.     char s[144]="";
  50.     word pos[10];
  51.     word ppos[10];
  52.     word pdown;
  53.     word start;
  54.     char *t;
  55.     char was;
  56.     char is;
  57.     char temp;
  58.     char tempdisablesub;
  59.     char eligible;
  60.  
  61.     /* Initially display top bar */
  62.  
  63.     if(!user.graphics || user.ansimenus) eligible=0;
  64.     else eligible=1;
  65.     stripcr(line);
  66.     if (!*line) return 0;
  67.     x=0;
  68.     p[x++]=strtok(line," ");
  69.     while (x<10 && (p[x++]=strtok(0," ")));
  70.     p[--x]=NULL;
  71.     if (!*p) return 0;
  72.     nump=(char)x-1;
  73.     for (x=0;p[x];x++) while (t=strchr(p[x],'_')) *t=' ';
  74.     tempdisablesub=disablesub;
  75.     disablesub=1;
  76. AllOver:
  77.     if(!eligible) {
  78.         gprintf(0,"\n%s\n",title);
  79.     }
  80.     else {
  81.         gprintf(0,"\x1b[1;1H\x1b[K\x1b[0;1;%hum╔",color);
  82.         for(x=1;x<((79-strlen(title))/2);x++) printm("═");
  83.         gprintf(0,"\x1b[0;1;%hum%s\x1b[0;1;%hum",tcolor,title,color);
  84.         y=wherex();
  85.         for(x=y;x<79;x++) printm("═");
  86.         printm("╗\n");
  87.         start=wherey();
  88.     }
  89. Over:   /* Redisplay top bar */
  90.     is=was=0;
  91.     if(top) {
  92.         is=top-1;
  93.         if(!*variable[top-1])top=0;
  94.     }
  95.     for (x=0;x<9;x++) pos[x]=0;
  96.     if(eligible) {
  97.         gprintf(0,"\x1b[0;1;%hum",color);
  98.         if(baud)while (!fossil(TRANSMIT,'\r')) carrchk();
  99.         fputs("\r",stdout);
  100.         printm("\x1b[2;1H\x1b[K║  ");
  101.     }
  102.     *pos=3;
  103.     if(!eligible) {
  104.         for (x=0;p[x];x++) {
  105.             if((wherex()+strlen(p[x])+2+2)>(int)(user.length-3)) printm("\n");
  106.             gprintf(0,"[%c]%s  ",*p[x],&p[x][1]);
  107.         }
  108.         printm("\b\b: ");
  109.     }
  110.     else {
  111.         printm(*p);
  112.         for (x=1;p[x];x++) {
  113.             printm("  ");
  114.             printm(p[x]);
  115.             pos[x]=pos[x-1]+strlen(p[x-1])+2;
  116.         }
  117.         printm("\x1b[2;79H║\x1b[3;1H\x1b[K╚");
  118.         for(x=1;x<78;x++) printm("═");
  119.         printm("╝\x1b[2;1H");
  120.     }
  121. Next:   /* Move highlight bar */
  122.     if(eligible) {
  123.         if(baud)while (!fossil(TRANSMIT,'\r')) carrchk();
  124.         fputs("\r",stdout);
  125.         gprintf(0,"\x1b[%u;1H\x1b[0;1;%hum\x1b[%uC%s",start,color,pos[was],p[was]);
  126.         gprintf(0,"\x1b[%u;1H\x1b[7m\x1b[%uC%s\x1b[0;1;%hum",start,pos[is],p[is],color);
  127.     }
  128.     if(top) {
  129.         temp=*p[top-1];
  130.         top=0;
  131.         if(eligible) goto Interruptus;
  132.     }
  133.     was=is;
  134. None:   /* Wait for something to happen w/ top bar... */
  135.     helpnum=0;
  136.     if(!eligible) {
  137.         temp=*genin(1,0,1,1,ALLL);
  138.         if(temp)goto Direct;
  139.         else goto None;
  140.     }
  141.     else {
  142.         temp=*genin(1,0,0,0,ARROWS);
  143.     }
  144. Interruptus:
  145.     switch ((int)temp) {
  146.     case 0:
  147.     case 5:
  148.     case '2': goto GotOne;
  149.     case 1:
  150.     case 4:
  151.     case '4': if (is) is--;
  152.               else is=nump;
  153.               break;
  154.     case 2:
  155.     case '6': if (!p[is+1]) is=0;
  156.               else is++;
  157.               break;
  158.     case 11:
  159.     case 27:  cls();
  160.               *s=0;
  161.               disablesub=tempdisablesub;
  162.               return 0;
  163.     default:
  164. Direct:
  165.               if(temp=='?' || toupper(temp)==conf.helpkey) {
  166.                 if(hyperhelp) {
  167.                     if(!eligible) {
  168.                         cls();
  169.                         if(conf.debug) lprint("\n\04Help = @Main\n");
  170.                         find_help(hyperhelp,"@Main",0);
  171.                     }
  172.                     else {
  173.                         cls();
  174.                         if(conf.debug) gprintf(LOCALONLY,"\n\04Help = %s\n",p[is]);
  175.                         find_help(hyperhelp,p[is],0);
  176.                     }
  177.                     top=is+1;
  178.                     down=0;
  179.                     cls();
  180.                     goto AllOver;
  181.                 }
  182.               }
  183.               for(x=0;p[x];x++) {       /* Direct select */
  184.                 if(toupper(*p[x])==toupper(temp)) {
  185.                     if(is!=(char)x) {
  186.                         if(eligible) {
  187.                             gprintf(0,"\x1b[%u;1H\x1b[0;1;%hum\x1b[%uC%s",start,color,pos[is],p[is]);
  188.                             gprintf(0,"\x1b[%u;1H\x1b[7m\x1b[%uC%s\x1b[0;1;%hum",start,pos[x],p[x],color);
  189.                         }
  190.                     }
  191.                     is=(char)x;
  192.                     goto GotOne;
  193.                 }
  194.               }
  195.               if(!eligible) printm(BACKSPACE);
  196.               break;
  197.     }
  198.     goto Next;
  199.  
  200. GotOne:     /* Pull down actions */
  201.  
  202.     if(!eligible) {
  203.         printm("\n");
  204.         down=0;
  205.     }
  206.     if(!*variable[is]) {  /* No pull downs for this one */
  207.         disablesub=tempdisablesub;
  208.         if(eligible)printm("\x1b[5;1H");
  209.         return ((is+1)*10);
  210.     }
  211.     pdown=pos[is];
  212.     if(pdown>60) pdown=60;
  213.     if(eligible)gprintf(0,"\x1b[3;%uH╦\x1b[14C╦\x1b[0m\x1b[0;1;%hum\n",pdown-1,color);
  214.     for(x=0;x<9;x++)ppos[x]=0;
  215.     x=0;
  216.     strcpy(s,variable[is]);
  217.     pp[x++]=strtok(s," ");
  218.     while (x<10 && (pp[x++]=strtok(0," ")));
  219.     pp[--x]=NULL;
  220.     if (!*pp) return 0;
  221.     numpp=(char)x-1;
  222.     for (x=0;pp[x];x++) while (t=strchr(pp[x],'_')) *t=' ';;
  223.     if(!eligible) {
  224.         for (x=0;pp[x];x++) {
  225.             if((wherex()+strlen(pp[x])+2+2)>(int)(user.length-3)) printm("\n");
  226.             gprintf(0,"[%c]%s  ",*pp[x],&pp[x][1]);
  227.         }
  228.         printm("\b\b: ");
  229.     }
  230.     else {
  231.         for(x=0;pp[x];x++) {
  232.             ppos[x]=wherey();
  233.             gprintf(0,"\x1b[K\x1b[%u;%uH║ %-12.12s ║\n",ppos[x],pdown-1,pp[x]);
  234.         }
  235.         gprintf(0,"\x1b[%u;%uH\x1b[K╚══════════════╝",ppos[numpp]+1,pdown-1);
  236.     }
  237.     was=y=0;
  238.     if(down) {
  239.         y=down-1;
  240.         down=0;
  241.     }
  242. Over1:  /* Loop until something happens */
  243.                                   
  244.     helpnum=0;
  245.     if(eligible) {
  246.         gprintf(0,"\x1b[%u;%uH\x1b[7m %-12.12s \x1b[0;1;%hum",ppos[y],pdown,pp[y],color);
  247.         temp=*genin(1,0,0,0,ARROWS);
  248.     }
  249.     else {
  250.         temp=*genin(1,0,1,1,ALLL);
  251.         if(temp) goto Direct2;
  252.         else goto Over1;
  253.     }
  254.     switch ((int)temp) {
  255.         case 1:
  256.         case 2:
  257.         case '4':
  258.         case '6': was=is;
  259.                   for(x=0;pp[x];x++) {
  260.                     gprintf(0,"\x1b[%u;1H\x1b[K\n",ppos[x]);
  261.                   }
  262.                   gprintf(0,"\x1b[%u;1H\x1b[K\n",ppos[numpp]+1);
  263.                   gprintf(0,"\x1b[3;%uH═\x1b[14C═",pdown-1);
  264.                   if (temp==1 || temp=='4') {
  265.                     if (is) is--;
  266.                     else is=nump;
  267.                   }
  268.                   else {
  269.                     if (!p[is+1]) is=0;
  270.                     else is++;
  271.                   }
  272.                   gprintf(0,"\x1b[%u;1H\x1b[0;1;%hum\x1b[%uC%s",start,color,pos[was],p[was]);
  273.                   goto Next;
  274.         case 0:
  275. KeyPress1:
  276.                   printm("\x1b[15;1H");
  277.                   disablesub=tempdisablesub;
  278.                   return (((is+1)*10)+(y+1));
  279.         case 4:
  280.         case '8': gprintf(0,"\x1b[%u;%uH\x1b[0;1;%hum %-12.12s ",ppos[y],pdown,color,pp[y]);
  281.                   if (y) y--;
  282.                   else y=numpp;
  283.                   break;
  284.         case 5:
  285.         case '2': gprintf(0,"\x1b[%u;%uH\x1b[0;1;%hum %-12.12s ",ppos[y],pdown,color,pp[y]);
  286.                   if (!pp[y+1]) y=0;
  287.                   else y++;
  288.                   break;
  289.         case 11:
  290.         case 27:  for(x=0;pp[x];x++) {
  291.                     gprintf(0,"\x1b[%u;1H\x1b[K\n",ppos[x]);
  292.                   }
  293.                   gprintf(0,"\x1b[%u;1H\x1b[K\n",ppos[numpp]+1);
  294.                   *s=0;
  295.                   disablesub=tempdisablesub;
  296.                   gprintf(0,"\x1b[1;1H\x1b[K\x1b[0;1;%hum╔",color);
  297.                   for(x=1;x<((79-strlen(title))/2);x++) printm("═");
  298.                   gprintf(0,"\x1b[0;1;%hum%s\x1b[0;1;%hum",tcolor,title,color);
  299.                   temp=wherex();
  300.                   for(x=temp;x<79;x++) printm("═");
  301.                   printm("╗\n");
  302.                   goto Over;
  303.         default:
  304. Direct2:
  305.                   if(temp=='?' || toupper(temp)==conf.helpkey) {
  306.                     if(hyperhelp) {
  307.                         if(!eligible) {
  308.                             cls();
  309.                             if(conf.debug) gprintf(LOCALONLY,"\n\04Help = %s\n",p[is]);
  310.                             find_help(hyperhelp,p[is],0);
  311.                         }
  312.                         else {
  313.  
  314.                             char s[133];
  315.  
  316.                             sprintf(s,"%s|%s",p[is],pp[y]);
  317.                             cls();
  318.                             if(conf.debug) gprintf(LOCALONLY,"\n\04Help = %s\n",s);
  319.                             find_help(hyperhelp,s,0);
  320.                         }
  321.                         top=is+1;
  322.                         down=y+1;
  323.                         cls();
  324.                         goto AllOver;
  325.                     }
  326.                   }
  327.                   for(x=0;pp[x];x++) {  /* Direct select */
  328.                     if(toupper(*pp[x])==toupper(temp)) {
  329.                         if(y!=x) {
  330.                             if(eligible) {
  331.                                 gprintf(0,"\x1b[%u;%uH\x1b[0;1;%hum %-12.12s ",ppos[y],pdown,color,pp[y]);
  332.                                 gprintf(0,"\x1b[%u;%uH\x1b[7m %-12.12s \x1b[0;1;%hum",ppos[x],pdown,pp[x],color);
  333.                             }
  334.                         }
  335.                         y=x;
  336.                         goto KeyPress1;
  337.                     }
  338.                   }
  339.                   if(!eligible)printm(BACKSPACE);
  340.     }
  341.     goto Over1;
  342. }
  343.  
  344.  
  345.  
  346. char * pascal ansimenu (char color, char trunc, char *line) {
  347.  
  348.     /* trunc & 1=return 1st letter only */
  349.     /* trunc & 2=no graphics version */
  350.     /* trunc & 4=return position # */
  351.     /* trunc & 8=don't uppercase */
  352.  
  353.     register word x=0;
  354.     char *p[36];
  355.     char s[144]="";
  356.     word pos[36];
  357.     char *t;
  358.     char was;
  359.     char is;
  360.     char temp;
  361.     char tempdisablesub;
  362.     char nump;
  363.  
  364.     stripcr(line);
  365.     if (!strlen(line)) return s;
  366.     p[x++]=strtok(line," ");
  367.     while (x<34 && (p[x++]=strtok(0," ")));
  368.     p[--x]=NULL;
  369.     if (!*p) return *p;
  370.     nump=(char)x-1;
  371.     for (x=0;p[x];x++) while (t=strchr(p[x],'_')) *t=' ';;
  372.     tempdisablesub=disablesub;
  373.     disablesub=1;
  374.     if (!user.graphics || user.ansimenus || (trunc & 2)) goto NoGraph;
  375. Over:
  376.     is=was=0;
  377.     for (x=0;x<35;x++) pos[x]=0;
  378.     gprintf(0,"\x1b[0;1;%hum",color);
  379.     if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
  380.     fputs("\r",stdout);
  381.     *pos=1;
  382.     printm("\x1b[1C");
  383.     printm(*p);
  384.     for (x=1;p[x];x++) {
  385.         printm("  ");
  386.         printm(p[x]);
  387.         pos[x]=pos[x-1]+strlen(p[x-1])+2;
  388.     }
  389. Next:
  390.     if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
  391.     fputs("\r",stdout);
  392.     gprintf(0,"\x1b[0;1;%hum\x1b[%uC",color,pos[was]);
  393.     printm(p[was]);
  394.     if (baud) while (!fossil(TRANSMIT,'\r')) carrchk();
  395.     fputs("\r",stdout);
  396.     gprintf(0,"\x1b[7m\x1b[%uC",pos[is]);
  397.     printm(p[is]);
  398.     gprintf(0,"\x1b[0;1;%hum",color);
  399.     was=is;
  400. None:
  401.     helpnum=0;
  402.     temp=*genin(1,0,0,0,ARROWS);
  403.     switch((int)temp) {
  404.         case 1:
  405.         case 4:
  406.         case '4':   if(is)is--;
  407.                     else is=nump;
  408.                     break;
  409.         case 0:     printm("\n");
  410.                     if(trunc & 1) p[is][1]=0;
  411.                     disablesub=tempdisablesub;
  412.                     if(trunc & 4) {
  413.                         sprintf(s,"%u",is);
  414.                         return (s);
  415.                     }
  416.                     else if(!(trunc & 8)) strupr(p[is]);
  417.                     return p[is];
  418.         case 5:
  419.         case 2:
  420.         case '6':   if (!p[is+1]) is=0;
  421.                     else is++;
  422.                     break;
  423.         case 3:     printm("\n");
  424.                     goto Over;
  425.         case 11:
  426.         case 27:    printm("\n");
  427.                     *s=0;
  428.                     disablesub=tempdisablesub;
  429.                     return s;
  430.        default:     if (trunc & 1) {
  431.                         for (x=0;p[x]!=NULL;x++) {
  432.                             if (toupper(temp)==*p[x]) {
  433.                                 printm("\n");
  434.                                 p[x][1]=0;
  435.                                 disablesub=tempdisablesub;
  436.                                 if (trunc & 4) {
  437.                                     sprintf(s,"%u",x);
  438.                                     return (s);
  439.                                 }
  440.                                 else if(!(trunc & 8)) strupr(p[x]);
  441.                                 return p[x];
  442.                             }
  443.                         }
  444.                     }
  445.                     break;
  446.     }
  447.     goto Next;
  448.  
  449. NoGraph:
  450.  
  451.     is=temp=was=0;
  452.     for (x=0;p[x];x++) {
  453.         if((wherex()+strlen(p[x])+2+2)>(int)(user.length-3)) printm("\n");
  454.         if (trunc & 1) {
  455.             if (user.graphics) gprintf(0,"\x1b[0;2;%hum[\x1b[0;1;%hum%c\x1b[0;2;%hum]\x1b[0;1;%hum%s  ",color,color,*p[x],color,color,&p[x][1]);
  456.             else gprintf(0,"[%c]%s  ",*p[x],&p[x][1]);
  457.         }
  458.         else {
  459.             gprintf(0,"%s  ",p[x]);
  460.             if (strlen(p[x])>temp) temp=strlen(p[x]);
  461.         }
  462.     }
  463.     say_prompt(278);
  464.     if (trunc & 1) {
  465.         temp=1;
  466.         was=1;
  467.     }
  468.     helpnum=0;
  469.     strcpy(s,genin(temp,0,1,was,ALLL));
  470.     if (trunc & 1) {
  471.         for (x=0;p[x];x++) {
  472.             if (toupper(*s)==*p[x]) {
  473.                 p[x][1]=0;
  474.                 printm("\n");
  475.                 disablesub=tempdisablesub;
  476.                 if (trunc & 4) {
  477.                     sprintf(s,"%u",x);
  478.                     return (s);
  479.                 }
  480.                 else return strupr(p[x]);
  481.             }
  482.         }
  483.         say_prompt(277);
  484.         goto NoGraph;
  485.     }
  486.         for (x=0;p[x];x++) {
  487.             if (!stricmp(s,p[x])) {
  488.                 printm("\n");
  489.                 disablesub=tempdisablesub;
  490.                 if (trunc & 4) {
  491.                     sprintf(s,"%u",x);
  492.                     return (s);
  493.                 }
  494.                 else if(!(trunc & 8)) strupr(p[x]);
  495.                 return p[x];
  496.             }
  497.         }
  498.         say_prompt(277);
  499.         goto NoGraph;
  500. }
  501.  
  502.  
  503. char * pascal ansimenu3 (char *title, char *file, char *color) {
  504.  
  505.     int handle;
  506.     char *myvars[22];
  507.     int register x;
  508.     int y;
  509.     int z;
  510.     static char s[81];
  511.     long pos[50];
  512.     char endoffile=0;
  513.     char keyin;
  514.     char tempdisablesub;
  515.  
  516.     level=0;
  517.     handle=oopen(file,O_RDONLY | O_BINARY | O_DENYNONE);
  518.     if(handle==-1) {
  519.         level=1;
  520.         return "";
  521.     }
  522.     lseek(handle,0L,SEEK_END);
  523.     if(tell(handle)==0L) {
  524.         level=1;
  525.         cclose(handle);
  526.         return "";
  527.     }
  528.     lseek(handle,0L,SEEK_SET);
  529.     tempdisablesub=disablesub;
  530.     y=0;
  531.     for(x=0;x<22;x++) myvars[x]=NULL;
  532.  
  533. Loop:           /* Load vars with lines from file */
  534.  
  535.     for(x=0;x<22;x++) {     /* Free previously used vars */
  536.         if(myvars[x]) {
  537.             ffree(myvars[x]);
  538.             myvars[x]=NULL;
  539.         }
  540.     }
  541.     pos[y]=tell(handle);
  542.     for(x=0;x<21;x++) {
  543.         if(!fgetsx(s,81,handle)) {
  544.             endoffile=1;
  545.             break;
  546.         }
  547.         s[80]=0;
  548.         stripcr(s);
  549.         myvars[x]=(char *)mmalloc(strlen(s)+1);
  550.         if(!myvars[x]) {            /* Allocation error */
  551.             say_prompt(459);
  552.             for(x=0;x<21;x++) {     /* Free previously used vars */
  553.                 if(myvars[x]) {
  554.                     ffree(myvars[x]);
  555.                 }
  556.             }
  557.             level=1;
  558.             cclose(handle);
  559.             disablesub=tempdisablesub;
  560.             return "";
  561.         }
  562.         strcpy(myvars[x],s);
  563.     }
  564.  
  565.     /* We now have a null-terminated array of null-terminated arrays */
  566.  
  567.     gprintf(0,"\x1b[2J%s\n%s",title,color);
  568.     z=x=0;
  569.     while(myvars[x]) {
  570.         gprintf(0," %1.78s",myvars[x]);
  571.         if(wherex()<79)printm(" ");
  572.         x++;
  573.         if(myvars[x]) printm("\n");
  574.     }
  575.     if(!x) printm("     -=>No more selections available<=-");
  576.     say_prompt(578);
  577.  
  578.     /* x now equals highest available array element + 1 */
  579.  
  580.   while(1) {
  581.  
  582.     if(myvars[z]) {
  583.         gprintf(0,"\x1b[%d;1H\x1b[7m %-1.78s",z+2,myvars[z]);
  584.         if(wherex()<79)printm(" ");
  585.         printm(color);
  586.     }
  587.  
  588.     helpnum=0;
  589.     keyin=*genin(1,0,1,1,ARROWS);
  590.     switch((int)keyin) {
  591.         case 1:
  592.         case 4:
  593.         case '8':   if(myvars[z]) {
  594.                         gprintf(0,"\x1b[%d;1H %-1.78s",z+2,myvars[z]);
  595.                         if(wherex()<79)printm(" ");
  596.                     }
  597.                     if(z)z--;
  598.                     else z=x-1;
  599.                     break;
  600.         case 0:     cclose(handle);
  601.                     if(!x) *s=0;
  602.                     else strcpy(s,myvars[z]);
  603.                     for(x=0;x<22;x++) {     /* Free previously used vars */
  604.                         if(myvars[x]) {
  605.                             ffree(myvars[x]);
  606.                         }
  607.                     }
  608.                     disablesub=tempdisablesub;
  609.                     return s;
  610.         case 5:
  611.         case 2:
  612.         case '2':   if(myvars[z]) {
  613.                         gprintf(0,"\x1b[%d;1H %-1.78s",z+2,myvars[z]);
  614.                         if(wherex()<79)printm(" ");
  615.                     }
  616.                     if(z<(x-1)) z++;
  617.                     else z=0;
  618.                     break;
  619.         case 3:     lseek(handle,pos[y],SEEK_SET);
  620.                     goto Loop;
  621.         case 11:
  622.         case 27:    level=2;
  623.                     disablesub=tempdisablesub;
  624.                     cclose(handle);
  625.                     for(x=0;x<22;x++) {     /* Free previously used vars */
  626.                         if(myvars[x]) {
  627.                             ffree(myvars[x]);
  628.                         }
  629.                     }
  630.                     return "";
  631.         case 199:
  632.         case 'H':
  633.         case '7':   y=0;
  634.                     endoffile=0;
  635.                     lseek(handle,0L,SEEK_SET);
  636.                     goto Loop;
  637.         case '3':
  638.         case 209:
  639.         case 'N':   if(!endoffile) {
  640.                         y++;
  641.                         if(y>249) y=0;
  642.                     }
  643.                     else lseek(handle,pos[y],SEEK_SET);
  644.                     goto Loop;
  645.         case 201:
  646.         case '9':
  647.         case '-':
  648.         case 'P':   endoffile=0;
  649.                     if(y) y--;
  650.                     lseek(handle,pos[y],SEEK_SET);
  651.                     goto Loop;
  652.     }
  653.   }
  654.   return "";
  655. }
  656.  
  657.  
  658.  
  659. void pascal make_list (char *file,char *mask,char *includepath,char overwrite) {
  660.  
  661.     struct ffblk f;
  662.     int handle;
  663.     char *ip;
  664.  
  665.     level=0;
  666.     if(!overwrite) unlink (file);
  667.     handle=oopen(file,O_RDWR | O_DENYWRITE | O_BINARY);
  668.     if(handle==-1) handle=ccreat(file,S_IWRITE);
  669.     if(handle==-1) {
  670.         level=1;
  671.         return;
  672.     }
  673.     ip=includepath;
  674.     lseek(handle,0L,SEEK_END);
  675.     if(!ip) ip="";
  676.  
  677.     if(findfirst(mask,&f,0)) {
  678.         if(tell(handle)==0L) {
  679.             cclose(handle);
  680.             unlink(file);
  681.         }
  682.         else cclose(handle);
  683.         return;
  684.     }
  685.  
  686.     do {
  687.         ffprintf(handle,"%s%s\r\n",ip,f.ff_name);
  688.     } while(!findnext(&f));
  689.  
  690.     cclose(handle);
  691. }
  692.  
  693.  
  694. void pascal ansimenu4 (char *title, char *file, char *color, char *fileout, char *prepend,char overwrite) {
  695.  
  696.     int handle;
  697.     char *myvars[4097];
  698.     int register x;
  699.     int z,y,w;
  700.     char s[81];
  701.     char keyin;
  702.     char tempdisablesub;
  703.     char mark[4097];
  704.     char *pre;
  705.  
  706.     level=0;
  707.     handle=oopen(file,O_RDONLY | O_BINARY | O_DENYNONE);
  708.     if(handle==-1) {
  709.         level=1;
  710.         return;
  711.     }
  712.     lseek(handle,0L,SEEK_END);
  713.     if(tell(handle)==0L) {
  714.         level=1;
  715.         cclose(handle);
  716.         return;
  717.     }
  718.     lseek(handle,0L,SEEK_SET);
  719.     tempdisablesub=disablesub;
  720.     pre=prepend;
  721.     if(!pre) pre="";
  722.     for(x=0;x<4097;x++) {
  723.         myvars[x]=NULL;
  724.         mark[x]=0;
  725.     }
  726.  
  727.     /* Load vars with lines from file */
  728.  
  729.     w=0;
  730.     for(x=0;x<4096;x++) {
  731.         if(!fgetsx(s,81,handle)) {
  732.             break;
  733.         }
  734.         s[80]=0;
  735.         stripcr(s);
  736.         myvars[x]=(char *)mmalloc(strlen(s)+1);
  737.         if(!myvars[x]) {            /* Allocation error */
  738.             say_prompt(459);
  739.             for(x=0;x<4096;x++) {     /* Free previously used vars */
  740.                 if(myvars[x]) {
  741.                     ffree(myvars[x]);
  742.                 }
  743.             }
  744.             level=1;
  745.             cclose(handle);
  746.             disablesub=tempdisablesub;
  747.             return;
  748.         }
  749.         strcpy(myvars[x],s);
  750.         w++;
  751.     }
  752.     cclose(handle);
  753.     if(!w) {
  754.         level=1;
  755.         return;
  756.     }
  757.     y=0;
  758.  
  759.     /* We now have a null-terminated array of null-terminated arrays */
  760.  
  761. Loop:
  762.  
  763.     gprintf(0,"\x1b[2J%s\n%s",title,color);
  764.     x=z=0;
  765.     while(myvars[x+y] && x<21) {
  766.         gprintf(0,"\x1b[%d;1H",x+2);
  767.         if(mark[x+y]) printm("\x1A");
  768.         else printm(" ");
  769.         gprintf(0,"%-1.78s",myvars[x+y]);
  770.         if(wherex()<79)printm(" ");
  771.         x++;
  772.         printm("\n");
  773.     }
  774.     if(!x) printm("     -=>No more selections available<=-");
  775.     say_prompt(579);
  776.  
  777.   while(1) {
  778.  
  779.     if(myvars[z+y]) {
  780.         gprintf(0,"\x1b[%d;1H\x1b[7m",z+2);
  781.         if(mark[z+y]) printm("\x1A");
  782.         else printm(" ");
  783.         gprintf(0,"%-1.78s",myvars[z+y]);
  784.         if(wherex()<79)printm(" ");
  785.         printm(color);
  786.     }
  787.  
  788. SkipRedraw:
  789.  
  790.     helpnum=0;
  791.     keyin=*genin(1,0,1,1,ARROWS);
  792.     switch((int)keyin) {
  793.         case 1:
  794.         case 4:
  795.         case '8':   if(myvars[z+y]) {
  796.                         gprintf(0,"\x1b[%d;1H",z+2);
  797.                         if(mark[z+y]) printm("\x1A");
  798.                         else printm(" ");
  799.                         gprintf(0,"%-1.78s",myvars[z+y]);
  800.                         if(wherex()<79)printm(" ");
  801.                     }
  802.                     if(z)z--;
  803.                     else z=x-1;
  804.                     break;
  805.         case 0:     if(!x) goto SkipRedraw;
  806.                     mark[z+y]=1-mark[z+y];
  807.                     if(mark[z+y])gprintf(0,"\x1b[%d;1H\x1b[7m\x1A%s",z+2,color);
  808.                     else gprintf(0,"\x1b[%d;1H\x1b[7m %s",z+2,color);
  809.                     goto SkipRedraw;
  810.         case 5:
  811.         case 2:
  812.         case '2':   if(myvars[z+y]) {
  813.                         gprintf(0,"\x1b[%d;1H",z+2);
  814.                         if(mark[z+y]) printm("\x1A");
  815.                         else printm(" ");
  816.                         gprintf(0,"%-1.78s",myvars[z+y]);
  817.                         if(wherex()<79)printm(" ");
  818.                     }
  819.                     if(z<(x-1)) z++;
  820.                     else z=0;
  821.                     break;
  822.         case 'U':   for(x=0;x<4096;x++) mark[x]=0;
  823.                     goto Loop;
  824.         case 'A':   for(x=0;x<4096;x++) mark[x]=1;
  825.                     goto Loop;
  826.         case 3:     break;
  827.         case 27:    level=2;
  828.                     for(x=0;x<4096;x++) {     /* Free previously used vars */
  829.                         if(myvars[x]) {
  830.                             ffree(myvars[x]);
  831.                         }
  832.                     }
  833.                     disablesub=tempdisablesub;
  834.                     return;
  835.         case 11:    if(!overwrite) unlink(fileout);
  836.                     handle=oopen(fileout,O_RDWR | O_BINARY | O_DENYWRITE);
  837.                     if(handle==-1) handle=ccreat(fileout,S_IWRITE);
  838.                     if(handle==-1) {
  839.                         level=1;
  840.                     }
  841.                     else {
  842.                         lseek(handle,0L,SEEK_END);
  843.                         for(x=0;x<4096;x++) {     /* Free previously used vars */
  844.                             if(myvars[x]) {       /* And write marked files */
  845.                                 if(mark[x]) {
  846.                                     ffprintf(handle,"%s%s\r\n",pre,myvars[x]);
  847.                                 }
  848.                                 ffree(myvars[x]);
  849.                             }
  850.                         }
  851.                         lseek(handle,0L,SEEK_END);
  852.                         if(tell(handle)==0L) {
  853.                             cclose(handle);
  854.                             unlink(fileout);
  855.                         }
  856.                         else cclose(handle);
  857.                     }
  858.                     disablesub=tempdisablesub;
  859.                     return;
  860.         case '1':
  861.         case 'E':   if(w<21) break;
  862.                     y=w-21;
  863.                     if(y<0) y=0;
  864.                     goto Loop;
  865.         case 'H':
  866.         case '7':   if(w<21 || y<21) break;
  867.                     y=0;
  868.                     goto Loop;
  869.         case '3':
  870.         case 209:
  871.         case 'N':   if(y>(w-21)) break;
  872.                     y+=21;
  873.                     if(y>(w-21)) {
  874.                         if(w>20)y=(w-21);
  875.                         else y=0;
  876.                     }
  877.                     goto Loop;
  878.         case 201:
  879.         case '9':
  880.         case '-':
  881.         case 'P':   if(w<21 || y<21) break;
  882.                     y-=21;
  883.                     if(y<0) y=0;
  884.                     goto Loop;
  885.     }
  886.   }
  887. }
  888.  
  889.  
  890. char pascal magazine_input (char *text) {
  891.  
  892.     char prettystring[384];
  893.     char *p;
  894.     char *divie[43];
  895.     register int x;
  896.     char comval,highcommand,command,wascommand,lastcommand=0;
  897.  
  898.     strncpy(prettystring,text,384);
  899.     prettystring[383]=0;
  900.     divie[0]=strtok(prettystring," ");
  901.     while(p=strchr(divie[0],'_')) *p=' ';
  902.     if(divie[0]) {
  903.         x=1;
  904.         while((divie[x]=strtok(0," ")) && x<41) {
  905.             while(p=strchr(divie[x],'_')) *p=' ';
  906.             x++;
  907.         }
  908.         highcommand=(char)x-1;
  909.     }
  910.     else return 0;
  911.     while(1) {
  912. FancyRedo:
  913.         printm(divie[lastcommand]);
  914. FancyNull:
  915.         command=*genin(1,0,1,1,HYPER);
  916.         wascommand=lastcommand;
  917.         switch((int)command) {
  918.             case 0:   command=toupper(*divie[lastcommand]);
  919.                       backup(divie[lastcommand]);
  920.                       gprintf(0,"%c",*divie[lastcommand]);
  921.                       goto DirectEntry;
  922.             case 1:
  923.             case 4:
  924.             case '4':
  925.             case '8': if(lastcommand==0) lastcommand=highcommand;
  926.                       else lastcommand--;
  927.                       break;
  928.             case 5:
  929.             case 2:
  930.             case '6':
  931.             case '2': if(lastcommand==highcommand) lastcommand=0;
  932.                       else lastcommand++;
  933.                       break;
  934.             case 11:
  935.             case 27:  printm("\n");
  936.                       return 0;
  937.             case 3:   printm("\n");
  938.                       goto FancyRedo;
  939.             default:  backup(divie[wascommand]);
  940.                       gprintf(0,"%c",toupper(command));
  941.                       goto DirectEntry;
  942.         }
  943.         backup(divie[wascommand]);
  944.         goto FancyRedo;
  945.     }
  946. DirectEntry:
  947.     comval=0;
  948.     for(x=0;x<42;x++) {
  949.         if(!*divie[x])break;
  950.         if(command==toupper(*divie[x])) {
  951.             comval=(char)x+1;
  952.             break;
  953.         }
  954.     }
  955.     if(!comval)goto FancyRedo;
  956.     return comval;
  957. }
  958.  
  959.  
  960. void pascal do_picks (char arg,char *b, word *lastlevel) {
  961.  
  962.     char *cm,*pp;
  963.     char a;
  964.  
  965.         switch ((int)arg) {
  966.  
  967.             case '[':   /* Invoke list-pick */
  968.                 if (user.ansimenus || !user.graphics) break;
  969.                 if(*b=='e') {
  970.                     b++;
  971.                     a=lastlevel[*b-'0'];
  972.                 }
  973.                 else a=*b-'0';
  974.                 if(a<0 || a>9) {
  975.                     level=1;
  976.                     b=NULL;
  977.                     break;
  978.                 }
  979.                 b+=2;
  980.                 if(*b=='@') {
  981.                     pp=variable[b[1]-'0'];
  982.                     b+=3;
  983.                 }
  984.                 else {
  985.                     pp=strtok(b,",");
  986.                     b=strtok(0,"\n");
  987.                 }
  988.                 if(*b=='@') {
  989.                     cm=variable[b[1]-'0'];
  990.                     b+=3;
  991.                 }
  992.                 else {
  993.                     cm=strtok(b,",");
  994.                     b=strtok(0,"\n");
  995.                 }
  996.                 if(*b=='@') b=variable[b[1]-'0'];
  997.                 strcpy(variable[a],ansimenu3(pp,cm,b));
  998.                 break;
  999.  
  1000.             case ']':   /* Invoke make-list */
  1001.                 if(*b=='e') {
  1002.                     b++;
  1003.                     a=lastlevel[*b-'0'];
  1004.                 }
  1005.                 else a=*b-'0';
  1006.                 b+=2;
  1007.                 if(*b=='@') {
  1008.                     pp=variable[b[1]-'0'];
  1009.                     b+=3;
  1010.                 }
  1011.                 else {
  1012.                     pp=strtok(b,",");
  1013.                     b=strtok(0,"\n");
  1014.                 }
  1015.                 if(*b=='@') {
  1016.                     cm=variable[b[1]-'0'];
  1017.                     b+=3;
  1018.                 }
  1019.                 else {
  1020.                     cm=strtok(b,",");
  1021.                     b=strtok(0,"\n");
  1022.                 }
  1023.                 if(*b=='@') b=variable[b[1]-'0'];
  1024.                 make_list(pp,cm,b,a);
  1025.                 break;
  1026.  
  1027.             case '{':   /* Invoke list-mark */
  1028.                 {
  1029.  
  1030.                     char *p,*p1;
  1031.  
  1032.                     if (user.ansimenus || !user.graphics) break;
  1033.                     if(*b=='e') {
  1034.                         b++;
  1035.                         a=lastlevel[*b-'0'];
  1036.                     }
  1037.                     else a=*b-'0';
  1038.                     if(a<0 || a>9) {
  1039.                         level=1;
  1040.                         b=NULL;
  1041.                         break;
  1042.                     }
  1043.                     b+=2;
  1044.                     if(*b=='@') {
  1045.                         pp=variable[b[1]-'0'];
  1046.                         b+=3;
  1047.                     }
  1048.                     else {
  1049.                         pp=strtok(b,",");
  1050.                         b=strtok(0,"\n");
  1051.                     }
  1052.                     if(*b=='@') {
  1053.                         cm=variable[b[1]-'0'];
  1054.                         b+=3;
  1055.                     }
  1056.                     else {
  1057.                         cm=strtok(b,",");
  1058.                         b=strtok(0,"\n");
  1059.                     }
  1060.                     if(*b=='@') {
  1061.                         p=variable[b[1]-'0'];
  1062.                         b+=3;
  1063.                     }
  1064.                     else {
  1065.                         p=strtok(b,",");
  1066.                         b=strtok(0,"\n");
  1067.                     }
  1068.                     if(*b=='@') {
  1069.                         p1=variable[b[1]-'0'];
  1070.                         b+=3;
  1071.                     }
  1072.                     else {
  1073.                         p1=strtok(b,",");
  1074.                         b=strtok(0,"\n");
  1075.                     }
  1076.                     if(*b=='@') b=variable[b[1]-'0'];
  1077.                     ansimenu4(pp,cm,p,p1,b,a);
  1078.                 }
  1079.                 break;
  1080.  
  1081.                 case '}':
  1082.                     if(*b=='@') {
  1083.                         pp=variable[b[1]-'0'];
  1084.                         b+=3;
  1085.                     }
  1086.                     else {
  1087.                         pp=strtok(b,",");
  1088.                         b=strtok(0,"\n");
  1089.                     }
  1090.                     if(*b=='@') cm=variable[b[1]-'0'];
  1091.                     else cm=strtok(b,", \n");
  1092.                     find_help(pp,cm,0);
  1093.                     break;
  1094.                 case '`':
  1095.                     if(*b=='@') level=magazine_input(variable[b[1]-'0']);
  1096.                     else level=magazine_input(stripcr(b));
  1097.                     break;
  1098.         }
  1099. }
  1100.  
  1101.  
  1102. /*
  1103. static int av_trans[]={0,4,2,6,1,5,3,7};
  1104.  
  1105.  
  1106. char * pascal avatar2ansi (int avatar) {
  1107.  
  1108.   int foreg;
  1109.   int backg;
  1110.   static char temp[13];
  1111.   static char ansi[20];
  1112.  
  1113.   if(!user.graphics) return "";
  1114.  
  1115.   avatar &= 127;
  1116.   strcpy(ansi,"\x1b[");
  1117.   backg=avatar/16;
  1118.   avatar -= backg*16;
  1119.   foreg=avatar;
  1120.   if (foreg > 7) {
  1121.       foreg -= 8;
  1122.       strcat(ansi,"0;1;");
  1123.   }
  1124.   else strcat(ansi,"0;");
  1125.  
  1126.   sprintf(temp,"%d",av_trans[foreg]);
  1127.  
  1128.   if (!backg) {
  1129.       strcat(ansi,"3");
  1130.       strcat(ansi,temp);
  1131.   }
  1132.   else {
  1133.       strcat(ansi,"3");
  1134.       strcat(ansi,temp);
  1135.       strcat(ansi,";4");
  1136.       sprintf(temp,"%d",av_trans[backg]);
  1137.       strcat(ansi,temp);
  1138.   }
  1139.   strcat(ansi,"m");
  1140.   return ansi;
  1141. }
  1142. */
  1143.