Path: galaxy.trc.rwcp.or.jp!coconuts.jaist!wnoc-tyo-news!etlnews.etl.go.jp!etlinn.etl.go.jp!etl.go.jp!trc.rwcp!rwc-tyo!nf4.iij.ad.jp!news.iij.ad.jp!sranha.sra.co.jp!sranhc.sra.co.jp!sran230.sra.co.jp!kawabe
From: kawabe@sra.CO.JP (Yoshikatsu &)
Newsgroups: fj.questions.unix
Subject: Re: grep Japanese strings
Date: 24 Sep 1996 11:24:43 GMT
Organization: Software Research Associates, Inc., Japan
Lines: 79
Message-ID: <KAWABE.96Sep24202443@sramhc.sra.CO.JP>
References: <xond8zm1eha.fsf@socio1.socio.kyoto-u.ac.jp> <51kvdf$adl@fse3.aist-nara.ac.jp>
NNTP-Posting-Host: sramhc.sra.co.jp
In-reply-to: tomoak-i@is.aist-nara.ac.jp's message of 17 Sep 1996 01:37:51 GMT
Xref: galaxy.trc.rwcp.or.jp fj.questions.unix:6152
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.questions.unix&nb=6152&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.


>>>>> In article <51kvdf$adl@fse3.aist-nara.ac.jp>,
tomoak-i@is.aist-nara.ac.jp (Tomoaki Imamura) writes:
  | 
  | $B;d$O(B jvim2.0r+onew2.2.10$B$KIUB0$N(Bjgrep$B$r;H$C$F$$$^$9!#(B
  | $B8!:w%Q%?!<%s$O(BEUC$B$GF~NO$9$k$H!"BP>]%U%!%$%kFb$N%3!<%I$,(Bsjis$B$G$b(Bjis$B$G$b(B
  | $BEvA3(Beuc$B$G$b8!:w$G$-$^$9!#(B
  | 
jvim $B$O;H$C$F$$$^$9$,(B jvim $B$N%=!<%9$K(B jgrep $B$,ImB0$7$F$$$k$H$O(B
$BCN$j$^$;$s$G$7$?!#(B $B$A$g$C$H;H$C$F$_$h$&$+$J!#(B

  | $B$=$NBe$o$j!"(B-n$B%*%W%7%g%s$,$J$$$J$I!"$+$J$j5!G=$,8B$i$l$F$$$^$9$N$G(B
  | GNU Grep$B$HN>J}%$%s%9%H!<%k$7$F;H$$J,$1$k$3$H$r$*4+$a$7$^$9!#(B
  |

-n $B%*%W%7%g%s$@$1$J$i<!$N%Q%C%A$GDI2C$G$-$^$7$?!#(B

____ Y. Kawabe ____


--- jgrep.c.origTue Sep 24 20:14:32 1996
+++ jgrep.cTue Sep 24 20:12:00 1996
@@ -38,6 +38,7 @@
 static int o_nomat = FALSE;/* -v */
 static int o_wsrch = FALSE;/* -w */
 static int o_scode = FALSE;/* -C */
+static int o_sline = FALSE;/* -n */
 
 static void
 usage()
@@ -49,6 +50,7 @@
 fprintf(stderr, "-l     Print only file name.\n");
 fprintf(stderr, "-s     Suppress error message.\n");
 fprintf(stderr, "-v     Print lines not match with the pattern.\n");
+fprintf(stderr, "-n     Print line number.\n");
 fprintf(stderr, "-w     Search \\<pattern\\>.\n");
 fprintf(stderr, "-C     Print kanji code.\n");
 fprintf(stderr, "-N -J -E -S -X\n");
@@ -104,7 +106,7 @@
 jread = jdisp = JP_NONE;
 #endif
 
-if (argc > 1 && argv[0][0] == '-')
+while (argc > 1 && argv[0][0] == '-')
 {
 char *cp;
 for(cp = argv[0] + 1; *cp; cp++)
@@ -272,9 +274,11 @@
 char *fname;
 {
 int count;
+int nline;
 
 reg_ic = o_icase;
 count = 0;
+nline = 0;
 
 reset_jcount();
 
@@ -286,6 +290,9 @@
 if (fgets(Line, IOSIZE, fp) == NULL)
 break;
 
+if (strchr(Line, '\n'))
+    nline++;
+
 len = strlen(Line);
 len = kanjiconvsfrom(Line, len, IObuff, IOSIZE * 2, NULL,
 jread, NULL);
@@ -298,6 +305,8 @@
 {
 if (fname)
 printf("%s:", fname);
+if (o_sline)
+printf("%d:", nline);
 if (o_scode)
 printf("(%c)", judge_jcode(jread));
 if (o_nonly)

