home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 103_01 / help.c < prev    next >
Text File  |  1985-03-10  |  3KB  |  138 lines

  1. /* 29-APRIL-81 */
  2. /* this should be the latest version of the help program */
  3. /* currently set up to read HELP.EDI for Scott's QED */
  4.  
  5. #include "bdscio.h"
  6.  
  7. #define MAXHELP 20
  8. #define MAXNAME 15
  9. #define CR 0X0D
  10. #define LF 0X0A
  11. #define NUL'\000'
  12. #define ESC 0X1B
  13.  
  14. #define TVI_C_SCREEN {putch(ESC); putch('Z'); putch(ESC); putch('\''); }
  15.  
  16. main(argc,argv)
  17. char **argv;
  18. int argc;
  19. {
  20. struct _buf iobuf;
  21. char hlpnm [MAXHELP] [MAXNAME] ;
  22. char answer [MAXLINE];
  23. char ttt [MAXLINE];
  24. char uuu [MAXLINE];
  25. int i,j,k,l, n;
  26.  
  27. char crlf[3];
  28.  
  29. crlf[0]=CR;
  30. crlf[1]=LF;
  31. crlf[2]=NUL;
  32.  
  33. fopen("HELP.EDI",&iobuf);
  34.  
  35. TVI_C_SCREEN
  36.  
  37.  
  38.     fgets(ttt,&iobuf);
  39.     while (index(ttt,"$$")==-1)
  40.         {
  41.              if (argc==1) puts(ttt);
  42.                fgets(ttt,&iobuf);
  43.         }
  44.     fgets(ttt,&iobuf);
  45.     i=0;
  46.     while (index(ttt,"$$")==-1)
  47.         {
  48.           transform(ttt,"$"," ");
  49.         transform(ttt,crlf,"   ");
  50.           strcpy(hlpnm[i],ttt);
  51.           i++;
  52.           fgets(ttt,&iobuf);
  53.         }
  54.     i--;
  55.     n = 3;
  56.     if (argc==1)
  57.           {
  58.         for(j=0;j<i;j++)
  59.               {
  60.             printf("\t%-15.15s",hlpnm[j]);
  61.             if (((j+1) %n) == 0)
  62.                 puts("\n");
  63.               }
  64.         puts("\n");
  65.         puts("\n\n\t\t\t");
  66.         gets(ttt);
  67.         k=strlen(ttt);
  68.         for(l=0;l<k;l++) ttt[l]=toupper(ttt[l]);
  69.         strcpy(answer,ttt);
  70.           }
  71.     else     {
  72.         strcpy(answer,*++argv);
  73.         }
  74.  
  75.     for ( j=0; j< (i); j++ )
  76.           { if ( index( hlpnm[j], answer) != -1)  break;
  77.           }
  78.     if (j==i)
  79.           { puts("unrecognized");
  80.         exit();
  81.           }
  82.     strcpy(ttt,"$");
  83.     strcat(ttt,answer);
  84.     strcpy(answer,ttt);
  85.     fgets(ttt,&iobuf);
  86.  
  87.     while(index(ttt,answer)==-1)
  88.         if (-1==fgets(ttt,&iobuf)) exit();
  89.  
  90.     if (-1==fgets(ttt,&iobuf)) exit();
  91.     while(ttt[0]!='$')
  92.           {
  93.         puts(ttt);
  94.         if (-1==fgets(ttt,&iobuf)) exit();
  95.         if (index(ttt,"$$$")!=-1)
  96.                     {
  97.             gets(ttt);
  98.             if (-1==fgets(ttt,&iobuf)) exit();
  99.               }
  100.           }
  101.     exit();
  102. }
  103. /* replace search[] in string[] with replace[] */
  104. transform(string, search, replace )
  105. char *string, *search, *replace;
  106. {
  107.     int i,m,x;
  108.     char q[2];
  109.  
  110.     q[1] = '\0';
  111.     x=0;
  112.  
  113.     i = strlen(search);    m = strlen(replace);
  114.     if (i<m)    m=i;
  115.     while (q[0] = string[x] )
  116.          { if(-1 != (i = index(search,q)))
  117.             if ( i<m ) string[x] = replace[i];
  118.         x++;
  119.           }
  120.     return;
  121. }
  122.  
  123. index(s,t)
  124. char s[], t[];
  125. {    int i,j,k;
  126.     for (i=0; s[i] != '\0'; i++)
  127.           { for (j=i, k=0; t[k] != '\0' && s[j]==t[k]; j++,k++);
  128.         if (t[k] == '\0')
  129.             return(i);
  130.           }
  131.     return(-1);
  132. }
  133. 
  134.           { for (j=i, k=0; t[k] != '\0' && s[j]==t[k]; j++,k++);
  135.         if (t[k] == '\0')
  136.             return(i);
  137.           }
  138.     re