home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / logo / part01 / splithelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-23  |  1.7 KB  |  76 lines

  1.  
  2. /*
  3.  * splithelp.c -- turn nroff output of logoman into help files.
  4.  *
  5.  * For this to work, there must be no em dashes in the logoman source
  6.  * except on lines which name primitives.  Also, the file which is
  7.  * nroffed isn't the actual logoman, but a version which has been edited
  8.  * by the makehelp shell script (which also runs this program) to change
  9.  * what's where.  The algorithm is that a primitive description starts
  10.  * with a line with a dash (represented here as a tilde) and continues
  11.  * until a line with a nonspace, nonempty first character.
  12.  */
  13.  
  14. #include <stdio.h>
  15.  
  16. int memb(ch,str)
  17. register char ch;
  18. register char *str;
  19. {
  20.     register char ch1;
  21.  
  22.     while (ch1 = *str++)
  23.         if (ch == ch1)
  24.             return(1);
  25.     return(0);
  26. }
  27.  
  28. main(argc,argv)
  29. char **argv;
  30. {
  31.     FILE *ip, *op;
  32.     int writing = 0;    /* nonzero when writing a file */
  33.     int empty = 0;        /* nonzero after an empty line */
  34.     register char *cp;
  35.     char line[100];
  36.     char primitive[30];
  37.  
  38.     if ((ip = fopen(argv[1],"r")) == NULL) {
  39.         printf("Splithelp: Can't read input.\n");
  40.         exit(1);
  41.     }
  42.  
  43.     while (fgets(line,100,ip)) {
  44.         if (memb('~',line)) {    /* start new file */
  45.             empty = 0;
  46.             if (writing)
  47.                 fclose(op);
  48.             sscanf(line,"%s",primitive);
  49.             if (strlen(primitive) > 9) {
  50.                 for (cp = line; *cp && *cp!=':'; cp++) ;
  51.                 sscanf(cp+2,"%s",primitive);
  52.             }
  53.             if ((op = fopen(primitive,"w")) == NULL) {
  54.                 printf("Splithelp: Can't write output.\n");
  55.                 exit(1);
  56.             }
  57.             for (cp = line; *cp != '~'; cp++) ;
  58.             *cp++ = '-';
  59.             *cp = '-';
  60.             fprintf(op,"%s",line);
  61.             writing++;
  62.         } else if (line[0] == '\n') {
  63.             empty++;
  64.         } else if (writing && line[0]==' ') {
  65.             if (empty) fprintf(op,"\n");
  66.             empty = 0;
  67.             fprintf(op,"%s",line);
  68.         } else if (writing) {
  69.             fclose(op);
  70.             writing = 0;
  71.         }
  72.     }
  73.     if (writing) fclose(op);
  74. }
  75.  
  76.