|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T h
Length: 9046 (0x2356) Types: TextFile Names: »helpscr.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/X/Xwanderer/helpscr.c«
#include "wand_head.h" #include <ctype.h> #define HELPFILE "wanderer.help" struct lh_f { char *line; struct lh_f *next; struct lh_f *prev; }; struct help_f { int pgnum; /* the page number */ struct lh_f *lh; /* long help */ struct help_f *next; struct help_f *prev; }; #define new(type) (type *) malloc(sizeof(type)); #define cll_insert(member, list) (member->next = list, \ member->prev = list->prev, \ list->prev->next = member, \ list->prev = member) char *make_filename(); #ifdef XWANDER extern struct fontinfo *tablefont; extern tablefonthigh; extern tablefontwide; extern tablefonta; extern GC tablegc; #endif struct help_f *helpscr = NULL; struct help_f *s_helppage = NULL; char *movekeys; do_help(keys) char *keys; { #ifndef XWANDER WINDOW *win; int rows = 24; #else int rows = (ICON_HIGH * 7) / tablefonthigh; #endif struct lh_f *p; int y, ch; int done; char lastline[255]; movekeys = keys; if (helpscr == NULL) parse_help(); if (helpscr == NULL) return; s_helppage = helpscr->next; if (s_helppage == helpscr) s_helppage = helpscr->next; #ifndef XWANDER win = newwin(rows-1, COLS, 0,0); /* window which gets the data */ wclear(win); clearok(win,1); wrefresh(win); #else XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0); erase_message(0); erase_message(1); #endif y = 0; for ( p = s_helppage->lh->next; ; p=p->next) { eswprint(win,y++,p->line); if (y == rows-5 || p->next == s_helppage->lh) { lastline[0] = 0; if (s_helppage != helpscr->next) strcat(lastline,"<-"); else strcat(lastline," "); strcat(lastline," "); if (s_helppage != helpscr->prev) strcat(lastline,"->"); else strcat(lastline," "); strcat(lastline," "); if (p->next != s_helppage->lh) { strcat(lastline,"-MORE-"); strcat(lastline," <space> for more,"); } else { strcat(lastline," "); } strcat(lastline," 'n' next page, 'p' previous page, <esc> end HELP."); #ifndef XWANDER wmove(win, rows-2, 1); waddstr(win, lastline); touchwin(win); wrefresh(win); #else table_message(rows-2, lastline); #endif done = 0; while(!done) { #ifndef XWANDER ch = getchar(); #else ch = getchar(-1); #endif switch(ch) { case ' ': /* space - continue */ #ifndef XWANDER wclear(win); #else XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0); #endif y = 1; if (p->next == s_helppage->lh && s_helppage->lh->next != helpscr->lh) { s_helppage = s_helppage->next; if (s_helppage == helpscr) s_helppage = helpscr->next; p = s_helppage->lh; y = 0; } done = 1; break; case 13: /* ctrl-M, <cr>, ctrl-J */ case 10: case 'n': case 'N': #ifndef XWANDER wclear(win); #else XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0); #endif y = 0; s_helppage = s_helppage->next; if (s_helppage == helpscr) s_helppage = helpscr->next; p = s_helppage->lh; done = 1; break; case 'p': /* 'P', 'p' or '-' = previous page */ case 'P': case '-': #ifndef XWANDER wclear(win); #else XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0); #endif y = 0; s_helppage = s_helppage->prev; if (s_helppage == helpscr) s_helppage = helpscr->prev; p = s_helppage->lh; done = 1; break; case 27: /* esc - abort */ #ifndef XWANDER delwin(win); touchwin(stdscr); clearok(stdscr,1); refresh(); #else XClearArea(dpy,win,5,5,ICON_WIDE*11,ICON_HIGH*7,0); #endif return; default: dobeep(); } } } } } parse_help() { FILE *inp; char buf[1024], buf2[1024]; int lineno, pgnum, n, i; struct help_f *th; struct lh_f *tl; char *p; strcpy(buf,make_filename(SCREENPATH,HELPFILE)); if ((inp = fopen(buf,"r")) == NULL) { #ifdef XWANDER message(0,"Cannot open help file \"%s\"",buf); #else fprintf(stderr,"Cannot open help file \"%s\"",buf); #endif helpscr = NULL; return; } pgnum = 0; lineno = 0; /* allocate the header node of the adeck list */ helpscr = new(struct help_f); helpscr->next = helpscr; helpscr->prev = helpscr; while (!feof(inp)) { if (fgets(buf,1024,inp) == NULL) break; lineno++; p = buf; /* blow off white space */ for (;isspace(*p);p++); /* did we use up all of our line ? */ if (*p == '#' || *p == 0 || *p == '\n') continue; /* look for key word */ if (*p == '$') { if (strncmp(p,"$PAGE",5) == 0) { /* got the $PAGE token */ /* allocate the page */ th = new(struct help_f); pgnum++; th->pgnum = pgnum; /* set page number */ th->lh = new(struct lh_f); /* allocate new long-help header node */ th->lh->next = th->lh; /* init new long-help header node */ th->lh->prev = th->lh; cll_insert(th,helpscr); /* insert page */ while (1) { /* get the rest of the long-help */ if (fgets(buf,1024,inp) == NULL) { #ifdef XWANDER message(0, "Illegal help file (no $END). Page: %d, Line: %d.",pgnum,lineno); #else fprintf(stderr,"Illegal help file (no $END). Page: %d, Line: %d.",pgnum,lineno); #endif helpscr = NULL; fclose(inp); return; } #ifdef XWANDER if (strncmp(buf,"$C",2)==0) continue; /* ignore $C */ if (strncmp(buf,"$X",2)==0) { buf[0] = ' '; buf[1] = ' '; } #else if (strncmp(buf,"$X",2)==0) continue; /* ignore $X */ if (strncmp(buf,"$C",2)==0) { buf[0] = ' '; buf[1] = ' '; } #endif lineno++; p = buf; if (strncmp(buf,"$END",4) == 0) { if (th->lh->next == th->lh) { #ifdef XWANDER message(0, "Illegal help file (null page). Page: %d, Line: %d.",pgnum,lineno); #else fprintf(stderr,"Illegal help file (null page). Page: %d, Line: %d.",pgnum,lineno); #endif helpscr = NULL; fclose(inp); return; } break; /* done with this page */ } else { tl = new(struct lh_f); /* new line struct */ buf[strlen(buf)-1] = 0; /* clobber trailing null */ tl->line = (char *)strcpy(malloc(strlen(buf)+1),buf); cll_insert(tl,th->lh); /* insert line */ } } } else { #ifdef XWANDER message(0,"Illegal help file (Unknown token). Page: %d, Line: %d.",pgnum,lineno); #else fprintf(stderr,"Illegal help file (Unknown token). Page: %d, Line: %d.",pgnum,lineno); #endif fclose(inp); helpscr = NULL; return; } } else { #ifdef XWANDER message(0,"Illegal help file (Bad line). Page: %d, Line: %d",pgnum,lineno); #else fprintf(stderr,"Illegal help file (Bad line). Page: %d, Line: %d",pgnum,lineno); #endif helpscr = NULL; fclose(inp); return; } } /* for (th = helpscr->next; th != helpscr; th=th->next) { int n; printf("help page: %d \"%s\"\n",th->pgnum, th->shorthelp); n = 0; for (tl = th->lh->next; tl != th->lh; tl=tl->next) { printf("%2d: %s\n",n++, tl->line); } printf("---------------------------\n"); } */ } #ifndef XWANDER eswprint(win, y, line) WINDOW *win; #else eswprint(foo, y, line) #endif int y; char *line; { char cp[3]; char *p; int x; char ch; #ifndef XWANDER WINDOW *twin = stdscr; stdscr = win; #endif p = line; x = 0; for (;*p;) { ch = *p; if (*p == '%') { p++; if (*p == 0) break; switch(*p) { case '%': break; case 'L': /* direction keys */ ch = movekeys[0]; break; case 'D': ch = movekeys[1]; break; case 'U': ch = movekeys[2]; break; case 'R': ch = movekeys[3]; break; case 'N': ch = s_helppage->pgnum + '0'; break; case '$': /* treasure */ case '*': case 'C': /* time capsule */ case '@': /* player */ case '#': /* rock */ case '=': /* brick */ case ':': /* dirt */ case '!': /* landmine */ case '+': /* cage */ case '<': /* larrow */ case '>': /* rarrow */ case '\\': /* backslope */ case '/': /* fwdslope */ case 'T': /* Teleport */ case 'O': /* boulder */ case 'S': /* sprite */ case 'X': /* Exit */ case 'M': /* monster */ xydrawsymbol(x,y,*p); ch = 0; break; default: fprintf(stderr,"illegal escape: %c\n",*p); ch = *p; break; } } if (ch) xyprintchar(x,y,ch); x++; p++; } #ifndef XWANDER stdscr = twin; #endif } xyprintchar(x,y,ch) { char buf[3]; if (ch == ' ') return; #ifndef XWANDER move(y,x); addch(ch); #else buf[0] = ch; buf[1] = 0; XDrawImageString(dpy, win, tablegc,10+tablefontwide*x, (tablefonthigh*y)+10+tablefonta, buf, 1); #endif } static char make_filenamebuf[1024]; char *make_filename(path,file) /* make a filepath from 'path' and 'file' */ char *path, *file; { strcpy(make_filenamebuf,path); strcat(make_filenamebuf,"/"); strcat(make_filenamebuf,file); return(make_filenamebuf); }