/* $OpenXM: OpenXM/src/util/oxgreph.c,v 1.5 2020/10/03 08:24:14 takayama Exp $ */ #include #include #include #include #include #define mymalloc(n) malloc(n) /* 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. 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 */ int Sjis = 0; int LeaveTag = 0; int main(int argc, char *argv[]) { int i,m,pid,n, cpos,start; char *com; char workf[256]; #define SSIZE 1024 char s[SSIZE]; char ss[SSIZE*2]; FILE *fp; int r; m = 256; 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%s",workf); r=system(com); printf("
    \n"); fp = fopen(workf,"r"); if (fp == NULL) { fprintf(stderr,"Open error of the workfile.\n"); exit(1); } while (fgets(s,SSIZE-1,fp)) { cpos = -1; n = strlen(s); for (i=0; i< n; i++) { if (s[i] == ':') { cpos = i; break; } } if (cpos >= 0) { s[cpos] = 0; start = 0; for (i=cpos+1; i= 0x80)) { i++; continue; /* skip the next byte. */ } if (s[i] == 0x1b) { /* skip escape sequence */ i++; while (s[i] != 0x1b) i++; } if (LeaveTag) ; else { if (s[i] == '<') { s[i]='{'; } else if (s[i] == '>') { s[i]='}'; } } if (s[i] == '\n') s[i] = ' '; } printf("
  1. %s
    %s 
    \n",s,s,&(s[cpos+1])); } } printf("
\n"); sprintf(com,"rm -f %s",workf); r=system(com); return 0; }