home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume8 / help.jn / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-19  |  1.5 KB  |  94 lines

  1. #include <sys/types.h>
  2. #include <sys/dir.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. char *zork[300];
  6. main(argc,argv)
  7. char **argv;
  8. {
  9.     int arcnt,level,k;
  10.     char line[133],fnd[133];
  11.     k=chdir(LIBDIR);
  12.     if(k<0)exit(1);
  13.     level=0;
  14.     arcnt=1;
  15.     for(;;){
  16.         if(arcnt>=argc)        {
  17.             puts("");
  18.             if(level)printf("Further ");
  19.             puts(
  20.             "Help is available for the following topics:");
  21.             if(listfd(1)<0)exit(1);
  22.             printf("\nHelp on what topic? ");
  23.             gets(line);
  24.         }
  25.         else{    
  26.             printf("%s:\n",argv[arcnt]);
  27.             if(listfd(0)<0)exit(1);
  28.             strcpy(line,argv[arcnt]);
  29.             arcnt++;
  30.         }
  31.         if(strlen(line)>0){
  32.             k=completion(line,zork); 
  33.             freezork(zork);
  34.             if(!k)continue;
  35.             if(!strcmp(line,"q") || 
  36.                 !strcmp(line,"quit") || 
  37.                 !strcmp(line,"exit"))exit(0);
  38.             if(line[0]=='!'){
  39.                 strcpy(fnd,"man ");
  40.                 strcat(fnd,&line[1]);
  41.                 system(fnd);
  42.                 continue;
  43.             }
  44.         }
  45.         if((k=strlen(line))==0 && level==0)exit(1);
  46.         if(k==0){
  47.             level--;
  48.             chdir("..");
  49.             continue;
  50.         }
  51.         strcpy(fnd,line);
  52.         strcat(line,".txt");
  53.         if(mymode(line)){
  54.             if(listit(line)<0)exit(1);
  55.         }
  56.         if(mymode(fnd)&040000){
  57.             /*            printf("\nFurther ");*/
  58.             chdir(fnd);
  59.             level++;
  60.         }
  61.     }
  62. }
  63. freezork(p)
  64. char **p;
  65. {
  66.     while(*p){
  67.         free(*p);
  68.         *p = (char *)0;
  69.         p++;
  70.     }
  71. }
  72. completion(line,p)
  73. char *line;
  74. char **p;
  75. {
  76.     int i,j,count=0;
  77.     char *q;
  78.     q=line;
  79.     if(*q=='!')q++;
  80.     for(i=0;p[i];i++)if(kindex(p[i],q)==0){
  81.         if(strcmp(p[i],q)==0)return 1;
  82.         count++;
  83.         j=i;
  84.     }
  85.     if(count!=1){
  86.         printf("ambiguous\n");
  87.         return 0;
  88.     }
  89.     strcpy(q,p[j]);
  90.     return 1;
  91.  
  92. }
  93.  
  94.