=================================================================== RCS file: /home/cvs/OpenXM/src/util/oxgreph.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -p -r1.1 -r1.2 --- OpenXM/src/util/oxgreph.c 2006/03/04 07:48:12 1.1 +++ OpenXM/src/util/oxgreph.c 2006/03/04 10:43:38 1.2 @@ -1,4 +1,4 @@ -/* $OpenXM$ */ +/* $OpenXM: OpenXM/src/util/oxgreph.c,v 1.1 2006/03/04 07:48:12 takayama Exp $ */ #include #include #include @@ -11,7 +11,14 @@ 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. + + Example: + s.txt contains "insubunkai" + oxgreph --sjis `cat s.txt` $OpenXM_HOME/doc/cfep/html-ja_JP.sjis/html-jp/*.html >t.html */ + +int Sjis = 0; +int LeaveTag = 0; main(int argc, char *argv[]) { int i,m,pid,n, cpos,start; char *com; @@ -23,12 +30,18 @@ main(int argc, char *argv[]) { m = 256; pid = getpid(); for (i=1; i%s",workf); @@ -37,29 +50,35 @@ main(int argc, char *argv[]) { printf("
    \n"); fp = fopen(workf,"r"); 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)) { - 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= 0) { + s[cpos] = 0; start = 0; + for (i=cpos+1; i= 0x80)) { + i++; + continue; /* skip the next byte. */ } - if (s[i] == '<') { start=1; } - if ((s[i] == '>') && start) { start=0; s[i] = ' '; } - if (start) s[i] = 0; - if (s[i] == '\n') s[i] = ' '; - } - printf("
  1. %s
    %s 
    \n",s,s,&(s[cpos+1])); - } + 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("
  2. %s
    %s 
    \n",s,s,&(s[cpos+1])); + } } printf("
\n"); sprintf(com,"rm -f %s",workf);