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

Diff for /OpenXM/src/util/oxgreph.c between version 1.1 and 1.5

version 1.1, 2006/03/04 07:48:12 version 1.5, 2020/10/03 08:24:14
Line 1 
Line 1 
 /* $OpenXM$ */  /* $OpenXM: OpenXM/src/util/oxgreph.c,v 1.4 2009/02/22 17:30:03 ohara Exp $ */
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
Line 11 
Line 11 
    It greps files and outputs an html file to browse the files.     It greps files and outputs an html file to browse the files.
    Keyword should be given in euc or utf-8 depending on the coding system of the files.     Keyword should be given in euc or utf-8 depending on the coding system of the files.
    It does not add meta section  of html file.     It does not add meta section  of html file.
      Locale must be "C" to use this program or use -f option to read keyword.
   
      Example:
      export LC_ALL="C"
      s.txt contains "insubunkai"
      oxgreph  "`nkf -w s.txt`" $OpenXM_HOME/doc/cfep/html-ja_JP.utf8/html-ja/*.html >t.html
      oxgreph --sjis "`nkf -s s.txt`" $OpenXM_HOME/doc/cfep/html-ja_JP.sjis/html-ja/*.html >t.html
 */  */
 main(int argc, char *argv[]) {  
   int Sjis = 0;
   int LeaveTag = 0;
   int main(int argc, char *argv[]) {
   int i,m,pid,n, cpos,start;    int i,m,pid,n, cpos,start;
   char *com;    char *com;
   char workf[256];    char workf[256];
Line 20  main(int argc, char *argv[]) {
Line 30  main(int argc, char *argv[]) {
   char s[SSIZE];    char s[SSIZE];
   char ss[SSIZE*2];    char ss[SSIZE*2];
   FILE *fp;    FILE *fp;
     int r;
   m = 256;    m = 256;
   pid = getpid();    pid = getpid();
     if (argc < 2) {
           fprintf(stderr,"oxgreph [--leaveTag] args_to_grep \n");
           fprintf(stderr,"Note: LC_ALL should be C on some systems or use -f to give the pattern.\n");
           fprintf(stderr,"Example 1:  oxgreph \"`nkf -w s.txt`\" $OpenXM_HOME/doc/cfep/html-ja_JP.utf8/*.html >t.html\n");
           fprintf(stderr,"Example 2:  oxgreph -f s.txt $OpenXM_HOME/doc/cfep/html-ja_JP.utf8/*.html >t.html\n");
           fprintf(stderr,"  The keyword is stored in s.txt.\n");
           exit(0);
     }
   for (i=1; i<argc; i++) {    for (i=1; i<argc; i++) {
         m += strlen(argv[i])+1;      m += strlen(argv[i])+1;
   }    }
   com = (char *)mymalloc(m);    com = (char *)mymalloc(m);
   sprintf(com,"grep ");    sprintf(com,"grep ");
   for (i=1; i<argc; i++) {    for (i=1; i<argc; i++) {
         sprintf(&(com[strlen(com)]),"%s ",argv[i]);      if (strcmp(argv[i],"--sjis")==0) {
         Sjis = 1;
       }else if (strcmp(argv[i],"--leaveTag")==0) {
         LeaveTag = 1;
       }else {
         sprintf(&(com[strlen(com)]),"%s ",argv[i]);
       }
   }    }
   sprintf(workf,"/tmp/tmp-oxgreph-%d.txt",pid);    sprintf(workf,"/tmp/tmp-oxgreph-%d.txt",pid);
   sprintf(&(com[strlen(com)]),">%s",workf);    sprintf(&(com[strlen(com)]),">%s",workf);
   system(com);    r=system(com);
   
   printf("<ol>\n");    printf("<ol>\n");
   fp = fopen(workf,"r");    fp = fopen(workf,"r");
   if (fp == NULL) {    if (fp == NULL) {
         fprintf(stderr,"Open error of the workfile.\n"); exit(1);      fprintf(stderr,"Open error of the workfile.\n"); exit(1);
   }    }
   while (fgets(s,SSIZE-1,fp)) {    while (fgets(s,SSIZE-1,fp)) {
         cpos = -1; n = strlen(s);      cpos = -1; n = strlen(s);
         for (i=0; i< n; i++) {      for (i=0; i< n; i++) {
           if (s[i] == ':') {        if (s[i] == ':') {
                 cpos = i; break;          cpos = i; break;
           }        }
         }      }
         if (cpos >= 0) {      if (cpos >= 0) {
           s[cpos] = 0; start = 0;        s[cpos] = 0; start = 0;
           for (i=cpos+1; i<n; i++) {        for (i=cpos+1; i<n; i++) {
         if (s[i] == 0x1b) {          if (Sjis && (((unsigned char)s[i]) >= 0x80)) {
                   i++;            i++;
                   while (s[i] != 0x1b) i++;            continue; /* skip the next byte. */
         }          }
                 if (s[i] == '<') { start=1; }          if (s[i] == 0x1b) { /* skip escape sequence */
                 if ((s[i] == '>') && start) { start=0; s[i] = ' '; }            i++;
                 if (start) s[i] = 0;            while (s[i] != 0x1b) i++;
                 if (s[i] == '\n') s[i] = ' ';          }
           }          if (LeaveTag) ;
           printf("<li><a href=\"%s\">%s</a> <pre>%s </pre>\n",s,s,&(s[cpos+1]));          else {
         }            if (s[i] == '<') { s[i]='{'; }
             else if (s[i] == '>') { s[i]='}'; }
           }
           if (s[i] == '\n') s[i] = ' ';
         }
         printf("<li><a href=\"%s\">%s</a> <pre>%s </pre>\n",s,s,&(s[cpos+1]));
       }
   }    }
   printf("</ol>\n");    printf("</ol>\n");
   sprintf(com,"rm -f %s",workf);    sprintf(com,"rm -f %s",workf);
   system(com);    r=system(com);
     return 0;
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

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