home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* XBBS SOURCE CODE copyright (c) 1990 by M. Kimes */
- /* All Rights Reserved */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the in the file LICENSE.XBS. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* XBBS LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES */
- /* AT THE ADDRESS LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO USE */
- /* THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING */
- /* AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH */
- /* M. KIMES */
- /* */
- /* */
- /* You can contact M. Kimes at the following address: */
- /* */
- /* M. Kimes 1:380/16.0@FidoNet */
- /* 542 Merrick (318)222-3455 data */
- /* Shreveport, LA 71104 */
- /* */
- /* */
- /* Please feel free to contact me at any time to share your comments about */
- /* my software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
- /***************************************************************************/
- /* XBBS hypertext reader */
- /***************************************************************************/
-
- #include <msg.h>
- #include <xext.h>
-
- #define MAXTOPICS 100
-
- static struct topics {
- char tname[23];
- char key;
- char type;
- word min;
- word flags;
- long tptr;
- } tps [MAXTOPICS+1];
-
- static char topicname[133];
- static int tp=0;
- static int ch=0;
-
-
- /* Load the topic definition file */
-
- int pascal load_topics (char *tn) {
-
- char lineh[128];
- int topicfp;
- char *p;
- char *pp;
-
- tp=0;
- if(!strchr(tn,':') && !strchr(tn,'\\')) sprintf(topicname,"%sHYPER\\%s",conf.homepath,tn);
- else strcpy(topicname,tn);
- if(conf.debug) gprintf(LOCALONLY,"\n\04Hyperfile: `%s'\n",topicname);
- if((topicfp=oopen(topicname,O_RDONLY | O_BINARY | O_DENYNONE))==-1) return 0;
- getlinet(lineh,topicfp);
- while(1) {
- if(tp==MAXTOPICS) break;
- if (!strncmp(lineh,"<end>",5)) break;
- if (*lineh != '<') continue;
- strncpy(tps[tp].tname,lineh+1,23);
- tps[tp].tname[22]=0;
- p=strchr(tps[tp].tname,'>');
- if(p)*p=0;
- rstrip(tps[tp].tname);
- tps[tp].type=0;
- tps[tp].key=0;
- tps[tp].min=0;
- tps[tp].flags=0;
- p=strchr(lineh,'>');
- if(p) {
- p++;
- p=lstrip(p);
- if(p) {
- tps[tp].key=toupper(*p++);
- tps[tp].type=(char)atoi(p);
- pp=strchr(p,' ');
- if(pp) {
- pp++;
- lstrip(pp);
- tps[tp].min=(word)atol(pp);
- p=strchr(p,' ');
- if(p) {
- p++;
- lstrip(p);
- tps[tp].flags=(word)atol(p);
- }
- }
- }
- }
- tps[tp].tptr=tell(topicfp);
- getlinet(lineh,topicfp);
- while (*lineh!='<') {
- getlinet(lineh,topicfp);
- }
- tp++;
- }
- cclose(topicfp);
- return 1;
- }
-
-
- /* Get a line of text from the topic file */
-
- static void pascal getlinet (char *lineh,int topicfp) {
-
- if(fgetsx(lineh,127,topicfp)==NULL)
- strcpy(lineh,"<end>");
- }
-
-
- /* Set the current active topic */
-
- int pascal set_topic (char *s) {
-
- for (ch=0;ch<tp;ch++) if (!stricmp(s,tps[ch].tname)) break;
- if(stricmp(s,tps[ch].tname)) return 0;
- return 1;
- }
-
-
- /* Display the current topic */
-
- int pascal display_topic (word secl,char **b) {
-
- register int x,y;
- int topicfp=-1;
- int links[MAXTOPICS];
- char lposx[MAXTOPICS];
- char lposy[MAXTOPICS];
- char posx,posy;
- int temp,nl,which;
- char ln[128];
- char tmp[128];
- char *p;
- char *pp;
- char selection;
-
- if(!tp) return 0;
- if(ch>=tp) ch=0;
- Over:
- cls();
- NoClear:
- which=0;
- nl=0;
- if(topicfp!=-1) {
- cclose(topicfp);
- }
- if((topicfp=oopen(topicname,O_RDONLY | O_BINARY | O_DENYNONE))==-1) return 0;
- lseek(topicfp,tps[ch].tptr,0);
- if(tps[ch].type<2) gprintf(0,"\n%s:\n",tps[ch].tname);
- while(1) {
- NextLine:
- getlinet(ln,topicfp);
- if(*ln=='<') break;
- pp=ln;
- if(tps[ch].type) pp=convertstring(ln);
-
- switch((int)tps[ch].type) {
- case 0:
- case 1: break;
- case 2: stripcr(pp);
- system(pp);
- getlinet(ln,topicfp);
- stripcr(ln);
- pp=ln;
- pp=convertstring(ln);
- if(!set_topic(pp)) {
- cclose(topicfp);
- return 0;
- }
- goto Over;
- case 3: stripcr(pp);
- strcpy(tmp,pp);
- getlinet(ln,topicfp);
- stripcr(ln);
- cclose(topicfp);
- load_topics(tmp);
- pp=ln;
- pp=convertstring(ln);
- if(!set_topic(pp)) return 0;
- goto Over;
- case 4: strcpy(tmp,pp);
- *b=tmp;
- getlinet(ln,topicfp);
- stripcr(ln);
- pp=convertstring(ln);
- set_topic(pp);
- cclose(topicfp);
- return 0;
- case 5: stripcr(pp);
- strncpy(startfile,pp,13);
- startfile[12]=0;
- getlinet(ln,topicfp);
- stripcr(ln);
- pp=convertstring(ln);
- set_topic(pp);
- longjmp(envbuf,99);
- case 6: stripcr(pp);
- readtext(pp);
- getlinet(ln,topicfp);
- stripcr(ln);
- pp=convertstring(ln);
- if(!set_topic(pp)) {
- cclose(topicfp);
- return 0;
- }
- goto Over;
- case 7: stripcr(pp);
- readfile(pp,0,0,1);
- getlinet(ln,topicfp);
- stripcr(ln);
- pp=convertstring(ln);
- if(!set_topic(pp)) {
- cclose(topicfp);
- return 0;
- }
- goto Over;
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:x=0;
- if(tps[ch].type==15) temp=DOSR;
- else if(tps[ch].type==9) temp=EXEC;
- else if(tps[ch].type==10) temp=DOS;
- else if(tps[ch].type==11) {
- temp=EXIT;
- x=(char)atoi(pp);
- pp="";
- }
- else if(tps[ch].type==12) temp=HOT;
- else if(tps[ch].type==13) temp=SWAP;
- else if(tps[ch].type==14) temp=SPAWNR;
- else temp=SPAWN;
- spawnit(pp,(char)temp,(char)x);
- getlinet(ln,topicfp);
- stripcr(ln);
- pp=convertstring(ln);
- if(!set_topic(pp)) {
- cclose(topicfp);
- return 0;
- }
- default:break;
- }
- if(pp[strlen(pp)-1]==';') pp[strlen(pp)-1]=0;
- switch((int)*pp) {
- case 28: p=center(&pp[1],user.length);
- strcpy(ln,p);
- pp=ln;
- break;
- case 25: p=r_just(&pp[1],user.length);
- strcpy(ln,p);
- pp=ln;
- break;
- case 24: p=&pp[1];
- xmenu(p);
- goto NextLine;
- case 23: p=strtok(++pp,", ");
- find_help(p,strtok(0,"\n"),0);
- goto NextLine;
- case 22: if(!user.commodore) break;
- pp++;
- goto NextLine;
- case 21: if(!user.twit) break;
- pp++;
- goto NextLine;
- case 20: say_prompt((word)atol(pp));
- goto NextLine;
- case 19: cls();
- goto NextLine;
- case 18: pp++;
- if(!set_topic(stripcr(pp))) goto NextLine;
- goto Over;
- case 17: hitreturn();
- goto NextLine;
- case 16: *b=convertstring(&pp[1]);
- goto NextLine;
- case 15: stripcr(&pp[1]);
- system(convertstring(&pp[1]));
- goto NextLine;
- case 14: stripcr(&pp[1]);
- readtext(convertstring(&pp[1]));
- goto NextLine;
- case 11: stripcr(&pp[1]);
- readfile(convertstring(&pp[1]),0,0,1);
- goto NextLine;
- case 6: if (!user.graphics) printm(convertstring(&pp[1]));
- goto NextLine;
- case 5: printg(convertstring(&pp[1]));
- goto NextLine;
- case 4: lprint(convertstring(pp));
- goto NextLine;
- case 3: addtolog(convertstring(&pp[1]));
- goto NextLine;
- case 2: *b=(&pp[1]);
- goto NextLine;
- }
- if(*pp=='[') {
- pp++;
- stripcr(pp);
- p=strchr(pp,']');
- if(p)*p=0;
- for(x=0;x<tp;x++) {
- if(!stricmp(pp,tps[x].tname)) {
- if(tps[x].min>secl) break;
- links[nl]=x;
- lposx[nl]=0; /* Can't allow cursor selection */
- lposy[nl]=0;
- nl++;
- break;
- }
- }
- continue;
- }
- do {
- p=strchr(pp,'{');
- if(!p) {
- printm(pp);
- break;
- }
- *p=0;
- gprintf(0,"%s{",pp);
- posx=(char)wherex();
- posy=(char)wherey();
- printg("\x1b[7m");
- pp=++p;
- p=strchr(pp,'}');
- if(!p) {
- gprintf(0,"%s}",pp);
- printg("\x1b[0m");
- break;
- }
- *p=0;
- for(x=0;x<tp;x++) {
- if(!stricmp(pp,tps[x].tname)) {
- if(tps[x].min>secl) break;
- for(y=0;y<nl;y++) {
- if(links[y]==x) goto Already;
- }
- links[nl]=x;
- lposx[nl]=posx; /* For cursor selection */
- lposy[nl]=posy;
- nl++;
- break;
- }
- }
- Already:
- printm(pp);
- printg("\x1b[0m");
- printm("}");
- pp=++p;
- } while (*pp);
- }
- cclose(topicfp);
- if(!nl) return 0;
- if(!user.ansimenus && user.graphics) {
- say_prompt(204);
- printg("\x1b[s");
- printm(tps[links[which]].tname);
- }
- else say_prompt(367);
- Again:
- selection=(int)*genin(1,0,1,2,HYPER);
- if(selection==27 || selection==11) return 0;
- if(!selection && (user.ansimenus || !user.graphics)) goto Over;
- if(selection<6 && (!user.ansimenus && user.graphics)) {
- switch (selection) {
- case 0: set_topic(tps[links[which]].tname);
- goto Over;
- case 4:
- case 1: which--;
- if(which<0) which=(nl-1);
- gprintf(0,"\x1b[u\x1b[s\x1b[K%s",tps[links[which]].tname);
- break;
- case 5:
- case 2: which++;
- if(which>(nl-1)) which=0;
- gprintf(0,"\x1b[u\x1b[s\x1b[K%s",tps[links[which]].tname);
- break;
- }
- goto Again;
- }
- if(selection==(int)'?') {
- say_prompt(365);
- temp=0;
- for(x=0;x<tp;x++) {
- if(tps[x].min>secl) continue;
- gprintf(0,"%2d)%-22s",x+2,tps[x].tname);
- temp++;
- if(!(temp%3)) {
- printm("\n");
- }
- else {
- printm(" ");
- }
- }
- say_prompt(366);
- selection=atoi(genin(2,0,0,0,NUM));
- if(!selection) goto Over;
- if(selection==1) return 0;
- selection-=2;
- if(selection<tp) {
- set_topic(tps[selection].tname);
- }
- goto Over;
- }
- for(x=0;x<nl;x++) {
- if(tps[links[x]].min>secl) continue;
- if((int)tps[links[x]].key==selection) {
- set_topic(tps[links[x]].tname);
- goto Over;
- }
- }
- temp=0;
- say_prompt(363);
- for(x=0;x<nl;x++) {
- if(tps[links[x]].min>secl) continue;
- gprintf(0,"[%c] %-20.20s",tps[links[x]].key,tps[links[x]].tname);
- temp++;
- if(!(temp%3)) {
- printm("\n");
- }
- else {
- printm(" ");
- }
- }
- say_prompt(364);
- if(!user.ansimenus && user.graphics) {
- printm("\x1b[s");
- printm(tps[links[which]].tname);
- }
- goto Again;
- }
-