[BACK]Return to oxgreph.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / util

Annotation of OpenXM/src/util/oxgreph.c, Revision 1.1

1.1     ! takayama    1: /* $OpenXM$ */
        !             2: #include <stdio.h>
        !             3: #include <stdlib.h>
        !             4: #include <string.h>
        !             5: #include <sys/types.h>
        !             6: #include <unistd.h>
        !             7:
        !             8: #define mymalloc(n)  malloc(n)
        !             9:
        !            10: /*
        !            11:    It greps files and outputs an html file to browse the files.
        !            12:    Keyword should be given in euc or utf-8 depending on the coding system of the files.
        !            13:    It does not add meta section  of html file.
        !            14: */
        !            15: main(int argc, char *argv[]) {
        !            16:   int i,m,pid,n, cpos,start;
        !            17:   char *com;
        !            18:   char workf[256];
        !            19: #define SSIZE 1024
        !            20:   char s[SSIZE];
        !            21:   char ss[SSIZE*2];
        !            22:   FILE *fp;
        !            23:   m = 256;
        !            24:   pid = getpid();
        !            25:   for (i=1; i<argc; i++) {
        !            26:        m += strlen(argv[i])+1;
        !            27:   }
        !            28:   com = (char *)mymalloc(m);
        !            29:   sprintf(com,"grep ");
        !            30:   for (i=1; i<argc; i++) {
        !            31:        sprintf(&(com[strlen(com)]),"%s ",argv[i]);
        !            32:   }
        !            33:   sprintf(workf,"/tmp/tmp-oxgreph-%d.txt",pid);
        !            34:   sprintf(&(com[strlen(com)]),">%s",workf);
        !            35:   system(com);
        !            36:
        !            37:   printf("<ol>\n");
        !            38:   fp = fopen(workf,"r");
        !            39:   if (fp == NULL) {
        !            40:        fprintf(stderr,"Open error of the workfile.\n"); exit(1);
        !            41:   }
        !            42:   while (fgets(s,SSIZE-1,fp)) {
        !            43:        cpos = -1; n = strlen(s);
        !            44:        for (i=0; i< n; i++) {
        !            45:          if (s[i] == ':') {
        !            46:                cpos = i; break;
        !            47:          }
        !            48:        }
        !            49:        if (cpos >= 0) {
        !            50:          s[cpos] = 0; start = 0;
        !            51:          for (i=cpos+1; i<n; i++) {
        !            52:         if (s[i] == 0x1b) {
        !            53:                  i++;
        !            54:                  while (s[i] != 0x1b) i++;
        !            55:         }
        !            56:                if (s[i] == '<') { start=1; }
        !            57:                if ((s[i] == '>') && start) { start=0; s[i] = ' '; }
        !            58:                if (start) s[i] = 0;
        !            59:                if (s[i] == '\n') s[i] = ' ';
        !            60:          }
        !            61:          printf("<li><a href=\"%s\">%s</a> <pre>%s </pre>\n",s,s,&(s[cpos+1]));
        !            62:        }
        !            63:   }
        !            64:   printf("</ol>\n");
        !            65:   sprintf(com,"rm -f %s",workf);
        !            66:   system(com);
        !            67: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>