home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / BBSHYPER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-20  |  12.0 KB  |  450 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 hypertext reader                                                   */
  33. /***************************************************************************/
  34.  
  35. #include <msg.h>
  36. #include <xext.h>
  37.  
  38. #define MAXTOPICS 100
  39.  
  40. static struct topics {
  41.   char tname[23];
  42.   char key;
  43.   char type;
  44.   word min;
  45.   word flags;
  46.   long tptr;
  47. } tps [MAXTOPICS+1];
  48.  
  49. static char topicname[133];
  50. static int tp=0;
  51. static int ch=0;
  52.  
  53.  
  54. /* Load the topic definition file */
  55.  
  56. int pascal load_topics (char *tn) {
  57.  
  58.   char lineh[128];
  59.   int topicfp;
  60.   char *p;
  61.   char *pp;
  62.  
  63.   tp=0;
  64.   if(!strchr(tn,':') && !strchr(tn,'\\')) sprintf(topicname,"%sHYPER\\%s",conf.homepath,tn);
  65.   else strcpy(topicname,tn);
  66.   if(conf.debug) gprintf(LOCALONLY,"\n\04Hyperfile: `%s'\n",topicname);
  67.   if((topicfp=oopen(topicname,O_RDONLY | O_BINARY | O_DENYNONE))==-1) return 0;
  68.   getlinet(lineh,topicfp);
  69.   while(1) {
  70.     if(tp==MAXTOPICS) break;
  71.     if (!strncmp(lineh,"<end>",5)) break;
  72.     if (*lineh != '<') continue;
  73.     strncpy(tps[tp].tname,lineh+1,23);
  74.     tps[tp].tname[22]=0;
  75.     p=strchr(tps[tp].tname,'>');
  76.     if(p)*p=0;
  77.     rstrip(tps[tp].tname);
  78.     tps[tp].type=0;
  79.     tps[tp].key=0;
  80.     tps[tp].min=0;
  81.     tps[tp].flags=0;
  82.     p=strchr(lineh,'>');
  83.     if(p) {
  84.         p++;
  85.         p=lstrip(p);
  86.         if(p) {
  87.             tps[tp].key=toupper(*p++);
  88.             tps[tp].type=(char)atoi(p);
  89.             pp=strchr(p,' ');
  90.             if(pp) {
  91.                 pp++;
  92.                 lstrip(pp);
  93.                 tps[tp].min=(word)atol(pp);
  94.                 p=strchr(p,' ');
  95.                 if(p) {
  96.                     p++;
  97.                     lstrip(p);
  98.                     tps[tp].flags=(word)atol(p);
  99.                 }
  100.             }
  101.         }
  102.     }
  103.     tps[tp].tptr=tell(topicfp);
  104.     getlinet(lineh,topicfp);
  105.     while (*lineh!='<') {
  106.       getlinet(lineh,topicfp);
  107.     }
  108.     tp++;
  109.   }
  110.   cclose(topicfp);
  111.   return 1;
  112. }
  113.  
  114.  
  115. /* Get a line of text from the topic file */
  116.  
  117. static void pascal getlinet (char *lineh,int topicfp) {
  118.  
  119.   if(fgetsx(lineh,127,topicfp)==NULL)
  120.     strcpy(lineh,"<end>");
  121. }
  122.  
  123.  
  124. /* Set the current active topic */
  125.  
  126. int pascal set_topic (char *s) {
  127.  
  128.   for (ch=0;ch<tp;ch++) if (!stricmp(s,tps[ch].tname)) break;
  129.   if(stricmp(s,tps[ch].tname)) return 0;
  130.   return 1;
  131. }
  132.  
  133.  
  134. /* Display the current topic */
  135.  
  136. int pascal display_topic (word secl,char **b) {
  137.  
  138.   register int x,y;
  139.   int topicfp=-1;
  140.   int links[MAXTOPICS];
  141.   char lposx[MAXTOPICS];
  142.   char lposy[MAXTOPICS];
  143.   char posx,posy;
  144.   int temp,nl,which;
  145.   char ln[128];
  146.   char tmp[128];
  147.   char *p;
  148.   char *pp;
  149.   char selection;
  150.  
  151.     if(!tp) return 0;
  152.     if(ch>=tp) ch=0;
  153. Over:
  154.     cls();
  155. NoClear:
  156.     which=0;
  157.     nl=0;
  158.     if(topicfp!=-1) {
  159.         cclose(topicfp);
  160.     }
  161.     if((topicfp=oopen(topicname,O_RDONLY | O_BINARY | O_DENYNONE))==-1) return 0;
  162.     lseek(topicfp,tps[ch].tptr,0);
  163.     if(tps[ch].type<2) gprintf(0,"\n%s:\n",tps[ch].tname);
  164.     while(1) {
  165. NextLine:
  166.       getlinet(ln,topicfp);
  167.       if(*ln=='<') break;
  168.       pp=ln;
  169.       if(tps[ch].type) pp=convertstring(ln);
  170.  
  171.       switch((int)tps[ch].type) {
  172.         case 0:
  173.         case 1:    break;
  174.         case 2: stripcr(pp);
  175.                 system(pp);
  176.                 getlinet(ln,topicfp);
  177.                 stripcr(ln);
  178.                 pp=ln;
  179.                 pp=convertstring(ln);
  180.                 if(!set_topic(pp)) {
  181.                     cclose(topicfp);
  182.                     return 0;
  183.                 }
  184.                 goto Over;
  185.         case 3: stripcr(pp);
  186.                 strcpy(tmp,pp);
  187.                 getlinet(ln,topicfp);
  188.                 stripcr(ln);
  189.                 cclose(topicfp);
  190.                 load_topics(tmp);
  191.                 pp=ln;
  192.                 pp=convertstring(ln);
  193.                 if(!set_topic(pp)) return 0;
  194.                 goto Over;
  195.         case 4: strcpy(tmp,pp);
  196.                 *b=tmp;
  197.                 getlinet(ln,topicfp);
  198.                 stripcr(ln);
  199.                 pp=convertstring(ln);
  200.                 set_topic(pp);
  201.                 cclose(topicfp);
  202.                 return 0;
  203.         case 5: stripcr(pp);
  204.                 strncpy(startfile,pp,13);
  205.                 startfile[12]=0;
  206.                 getlinet(ln,topicfp);
  207.                 stripcr(ln);
  208.                 pp=convertstring(ln);
  209.                 set_topic(pp);
  210.                 longjmp(envbuf,99);
  211.         case 6: stripcr(pp);
  212.                 readtext(pp);
  213.                 getlinet(ln,topicfp);
  214.                 stripcr(ln);
  215.                 pp=convertstring(ln);
  216.                 if(!set_topic(pp)) {
  217.                     cclose(topicfp);
  218.                     return 0;
  219.                 }
  220.                 goto Over;
  221.         case 7: stripcr(pp);
  222.                 readfile(pp,0,0,1);
  223.                 getlinet(ln,topicfp);
  224.                 stripcr(ln);
  225.                 pp=convertstring(ln);
  226.                 if(!set_topic(pp)) {
  227.                     cclose(topicfp);
  228.                     return 0;
  229.                 }
  230.                 goto Over;
  231.         case 8:
  232.         case 9:
  233.         case 10:
  234.         case 11:
  235.         case 12:
  236.         case 13:
  237.         case 14:
  238.         case 15:x=0;
  239.                 if(tps[ch].type==15) temp=DOSR;
  240.                 else if(tps[ch].type==9) temp=EXEC;
  241.                 else if(tps[ch].type==10) temp=DOS;
  242.                 else if(tps[ch].type==11) {
  243.                     temp=EXIT;
  244.                     x=(char)atoi(pp);
  245.                     pp="";
  246.                 }
  247.                 else if(tps[ch].type==12) temp=HOT;
  248.                 else if(tps[ch].type==13) temp=SWAP;
  249.                 else if(tps[ch].type==14) temp=SPAWNR;
  250.                 else temp=SPAWN;
  251.                 spawnit(pp,(char)temp,(char)x);
  252.                 getlinet(ln,topicfp);
  253.                 stripcr(ln);
  254.                 pp=convertstring(ln);
  255.                 if(!set_topic(pp)) {
  256.                     cclose(topicfp);
  257.                     return 0;
  258.                 }
  259.         default:break;
  260.       }
  261.       if(pp[strlen(pp)-1]==';') pp[strlen(pp)-1]=0;
  262.       switch((int)*pp) {
  263.             case 28:    p=center(&pp[1],user.length);
  264.                         strcpy(ln,p);
  265.                         pp=ln;
  266.                         break;
  267.             case 25:    p=r_just(&pp[1],user.length);
  268.                         strcpy(ln,p);
  269.                         pp=ln;
  270.                         break;
  271.            case 24:     p=&pp[1];
  272.                         xmenu(p);
  273.                         goto NextLine;
  274.             case 23:    p=strtok(++pp,", ");
  275.                         find_help(p,strtok(0,"\n"),0);
  276.                         goto NextLine;
  277.             case 22:    if(!user.commodore) break;
  278.                         pp++;
  279.                         goto NextLine;
  280.             case 21:    if(!user.twit) break;
  281.                         pp++;
  282.                         goto NextLine;
  283.             case 20:    say_prompt((word)atol(pp));
  284.                         goto NextLine;
  285.             case 19:    cls();
  286.                         goto NextLine;
  287.             case 18:    pp++;
  288.                         if(!set_topic(stripcr(pp))) goto NextLine;
  289.                         goto Over;
  290.             case 17:    hitreturn();
  291.                         goto NextLine;
  292.             case 16:    *b=convertstring(&pp[1]);
  293.                         goto NextLine;
  294.             case 15:    stripcr(&pp[1]);
  295.                         system(convertstring(&pp[1]));
  296.                         goto NextLine;
  297.             case 14:    stripcr(&pp[1]);
  298.                         readtext(convertstring(&pp[1]));
  299.                         goto NextLine;
  300.             case 11:    stripcr(&pp[1]);
  301.                         readfile(convertstring(&pp[1]),0,0,1);
  302.                         goto NextLine;
  303.             case 6:     if (!user.graphics) printm(convertstring(&pp[1]));
  304.                         goto NextLine;
  305.             case 5:     printg(convertstring(&pp[1]));
  306.                         goto NextLine;
  307.             case 4:     lprint(convertstring(pp));
  308.                         goto NextLine;
  309.             case 3:     addtolog(convertstring(&pp[1]));
  310.                         goto NextLine;
  311.             case 2:     *b=(&pp[1]);
  312.                         goto NextLine;
  313.       }
  314.      if(*pp=='[') {
  315.         pp++;
  316.         stripcr(pp);
  317.         p=strchr(pp,']');
  318.         if(p)*p=0;
  319.         for(x=0;x<tp;x++) {
  320.             if(!stricmp(pp,tps[x].tname)) {
  321.                 if(tps[x].min>secl) break;
  322.                 links[nl]=x;
  323.                 lposx[nl]=0;    /* Can't allow cursor selection */
  324.                 lposy[nl]=0;
  325.                 nl++;
  326.                 break;
  327.             }
  328.         }
  329.         continue;
  330.      }
  331.      do {
  332.         p=strchr(pp,'{');
  333.         if(!p) {
  334.             printm(pp);
  335.             break;
  336.         }
  337.         *p=0;
  338.         gprintf(0,"%s{",pp);
  339.         posx=(char)wherex();
  340.         posy=(char)wherey();
  341.         printg("\x1b[7m");
  342.         pp=++p;
  343.         p=strchr(pp,'}');
  344.         if(!p) {
  345.             gprintf(0,"%s}",pp);
  346.             printg("\x1b[0m");
  347.             break;
  348.         }
  349.         *p=0;
  350.         for(x=0;x<tp;x++) {
  351.             if(!stricmp(pp,tps[x].tname)) {
  352.                 if(tps[x].min>secl) break;
  353.                 for(y=0;y<nl;y++) {
  354.                     if(links[y]==x) goto Already;
  355.                 }
  356.                 links[nl]=x;
  357.                 lposx[nl]=posx;    /* For cursor selection */
  358.                 lposy[nl]=posy;
  359.                 nl++;
  360.                 break;
  361.             }
  362.         }
  363. Already:
  364.         printm(pp);
  365.         printg("\x1b[0m");
  366.         printm("}");
  367.         pp=++p;
  368.       } while (*pp);
  369.     }
  370.     cclose(topicfp);
  371.     if(!nl) return 0;
  372.     if(!user.ansimenus && user.graphics) {
  373.         say_prompt(204);
  374.         printg("\x1b[s");
  375.         printm(tps[links[which]].tname);
  376.     }
  377.     else say_prompt(367);
  378. Again:
  379.     selection=(int)*genin(1,0,1,2,HYPER);
  380.     if(selection==27 || selection==11) return 0;
  381.     if(!selection && (user.ansimenus || !user.graphics)) goto Over;
  382.     if(selection<6 && (!user.ansimenus && user.graphics)) {
  383.         switch (selection) {
  384.             case 0:    set_topic(tps[links[which]].tname);
  385.                     goto Over;
  386.             case 4:
  387.             case 1: which--;
  388.                     if(which<0) which=(nl-1);
  389.                     gprintf(0,"\x1b[u\x1b[s\x1b[K%s",tps[links[which]].tname);
  390.                     break;
  391.             case 5:
  392.             case 2:    which++;
  393.                     if(which>(nl-1)) which=0;
  394.                     gprintf(0,"\x1b[u\x1b[s\x1b[K%s",tps[links[which]].tname);
  395.                     break;
  396.         }
  397.         goto Again;
  398.     }
  399.     if(selection==(int)'?') {
  400.         say_prompt(365);
  401.         temp=0;
  402.         for(x=0;x<tp;x++) {
  403.             if(tps[x].min>secl) continue;
  404.             gprintf(0,"%2d)%-22s",x+2,tps[x].tname);
  405.             temp++;
  406.             if(!(temp%3)) {
  407.                 printm("\n");
  408.             }
  409.             else {
  410.                 printm(" ");
  411.             }
  412.         }
  413.         say_prompt(366);
  414.         selection=atoi(genin(2,0,0,0,NUM));
  415.         if(!selection) goto Over;
  416.         if(selection==1) return 0;
  417.         selection-=2;
  418.         if(selection<tp) {
  419.             set_topic(tps[selection].tname);
  420.         }
  421.         goto Over;
  422.     }
  423.     for(x=0;x<nl;x++) {
  424.         if(tps[links[x]].min>secl) continue;
  425.         if((int)tps[links[x]].key==selection) {
  426.             set_topic(tps[links[x]].tname);
  427.             goto Over;
  428.         }
  429.     }
  430.     temp=0;
  431.     say_prompt(363);
  432.     for(x=0;x<nl;x++) {
  433.         if(tps[links[x]].min>secl) continue;
  434.         gprintf(0,"[%c] %-20.20s",tps[links[x]].key,tps[links[x]].tname);
  435.         temp++;
  436.         if(!(temp%3)) {
  437.             printm("\n");
  438.         }
  439.         else {
  440.             printm("  ");
  441.         }
  442.     }
  443.     say_prompt(364);
  444.     if(!user.ansimenus && user.graphics) {
  445.         printm("\x1b[s");
  446.         printm(tps[links[which]].tname);
  447.     }
  448.     goto Again;
  449. }
  450.