home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / httpd_source_1.3.tar.Z / httpd_source_1.3.tar / httpd_1.3 / support / inc2shtml.c < prev    next >
C/C++ Source or Header  |  1994-04-11  |  2KB  |  103 lines

  1. /*
  2.  * inc2shtml: Convert httpd <1.1 style includes to 1.2 style
  3.  * 
  4.  * Rob McCool
  5.  * 
  6.  * Usage: inc2shtml [filename]
  7.  * 
  8.  * If filename is given, this program will open filename. If not, it will 
  9.  * look on stdin. It will output the new shtml file on stdout.
  10.  */
  11.  
  12.  
  13. #include <stdio.h>
  14.  
  15. #define MAX_STRING_LEN 256
  16.  
  17. void usage(char *argv0) {
  18.     fprintf(stderr,"Usage: %s [filename]\n",argv0);
  19.     fprintf(stderr,"If filename is given, this program will open filename.\n");
  20.     fprintf(stderr,"If not, it will look on stdin for the inc file.\n");
  21.     fprintf(stderr,
  22.             "In either case, it will write the new shtml file on stdout.\n");
  23.     exit(1);
  24. }
  25.  
  26. void translate_tag(char *tag, FILE *fd) {
  27.     char *tp = tag, *tp2;
  28.     int url;
  29.  
  30.     url = (*tp == 'U' || *tp == 'u' ? 1 : 0);
  31.         
  32.     while(*tp++ != '\"');
  33.     tp2 = tp + 1;
  34.     while(*tp2 != '\"') ++tp2;
  35.     *tp2 = '\0';
  36.     if(*tp == '|') {
  37.         fprintf(fd,"<!--#exec cmd=\"%s",++tp);
  38.         if(url) fputs(" '$QUERY_STRING_UNESCAPED'",fd);
  39.         fputs("\"-->",fd);
  40.     } else
  41.         fprintf(fd,"<!--#include virtual=\"%s\"-->",tp);
  42. }
  43.  
  44. main(int argc, char *argv[]) {
  45.     FILE *f;
  46.     int c,x,p;
  47.     char c2;
  48.     char *lookfor = "<inc srv";
  49.  
  50.     switch(argc) {
  51.       case 1:
  52.         f = stdin;
  53.         break;
  54.       case 2:
  55.         if(!(f = fopen(argv[1],"r"))) {
  56.             perror("fopen");
  57.             exit(1);
  58.         }
  59.         break;
  60.       default:
  61.         usage(argv[0]);
  62.     }
  63.  
  64.     p=0;
  65.     while(1) {
  66.         c = fgetc(f);
  67.         if(c == -1) {
  68.             fflush(stdout);
  69.             exit(0);
  70.         }
  71.         c2 = (char)c;
  72.         if(isalpha((char)c))
  73.             c = tolower((char)c);
  74.         if(c == lookfor[p]) {
  75.             if(!lookfor[++p]) {
  76.                 char tag[MAX_STRING_LEN];
  77.  
  78.                 x=0;
  79.                 c = fgetc(f); /* get space */
  80.                 while(c != '>') {
  81.                     tag[x++] = c;
  82.                     c = fgetc(f);
  83.                     if(c == -1) {
  84.                         fputs("<inc srv ",stdout);
  85.                         fputs(tag,stdout);
  86.                         fflush(stdout);
  87.                         exit(1);
  88.                     }
  89.                 }
  90.                 tag[x] = '\0';
  91.                 translate_tag(tag,stdout);
  92.                 p = 0;
  93.             }
  94.         } 
  95.         else {
  96.             for(x=0;x<p;x++)
  97.                 fputc(lookfor[x],stdout);
  98.             fputc(c2,stdout);
  99.             p=0;
  100.         }
  101.     }
  102. }
  103.