From owner-p4-projects@FreeBSD.ORG Mon Jun 23 13:25:03 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 68F771065676; Mon, 23 Jun 2008 13:25:03 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 12F6A1065675 for ; Mon, 23 Jun 2008 13:25:03 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id E8A088FC20 for ; Mon, 23 Jun 2008 13:25:02 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m5NDP2Bv060559 for ; Mon, 23 Jun 2008 13:25:02 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5NDP2ro060557 for perforce@freebsd.org; Mon, 23 Jun 2008 13:25:02 GMT (envelope-from gabor@freebsd.org) Date: Mon, 23 Jun 2008 13:25:02 GMT Message-Id: <200806231325.m5NDP2ro060557@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gabor@freebsd.org using -f From: Gabor Kovesdan To: Perforce Change Reviews Cc: Subject: PERFORCE change 143965 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jun 2008 13:25:03 -0000 http://perforce.freebsd.org/chv.cgi?CH=143965 Change 143965 by gabor@gabor_server on 2008/06/23 13:24:09 - Add NLS support, a template catalog, and a Hungarian catalog Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/file.c#6 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.c#35 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.h#18 edit .. //depot/projects/soc2008/gabor_textproc/grep/nls/C.msg#1 add .. //depot/projects/soc2008/gabor_textproc/grep/nls/hu_HU.ISO8859-2.msg#1 add .. //depot/projects/soc2008/gabor_textproc/grep/util.c#32 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/file.c#6 (text+ko) ==== @@ -136,9 +136,9 @@ struct file *f; if (fd == STDIN_FILENO) - snprintf(fname, sizeof fname, "(standard input)"); + snprintf(fname, sizeof fname, getstr(1)); else - snprintf(fname, sizeof fname, "(fd %d)", fd); + snprintf(fname, sizeof fname, getstr(2), fd); f = grep_malloc(sizeof *f); @@ -216,7 +216,7 @@ return (0); default: /* NOTREACHED */ - errx(2, "invalid file type"); + errx(2, getstr(3)); } } @@ -234,7 +234,7 @@ return (bzfgetln(f->bzf, l)); default: /* NOTREACHED */ - errx(2, "invalid file type"); + errx(2, getstr(3)); } } @@ -256,7 +256,7 @@ break; default: /* NOTREACHED */ - errx(2, "invalid file type"); + errx(2, getstr(3)); } free(f); } ==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#35 (text+ko) ==== @@ -43,6 +43,8 @@ #include #include #include +#include +#include #include #include #include @@ -51,6 +53,26 @@ #include "grep.h" +#ifndef WITHOUT_NLS +char *errstr[] = { + "", + "(standard input)", + "(fd %d)", + "invalid file type", + "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n", + "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n", + "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n", + "\t[--null] [pattern] [file ...]\n", + "parentheses not balanced", + "context out of range", + "FreeBSD grep 2.5.1\n", + "Unknown binary-files option", + "Binary file %s matches\n" +}; + +nl_catd catalog; +#endif + /* Flags passed to regcomp() and regexec() */ int cflags; int eflags = REG_STARTEND; @@ -127,12 +149,11 @@ static void usage(void) { - fprintf(stderr, - "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n" - "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n" - "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n" - "\t[--null] [pattern] [file ...]\n" - , __progname); + fprintf(stderr, getstr(4), __progname); + fprintf(stderr, getstr(5)); + fprintf(stderr, getstr(5)); + fprintf(stderr, getstr(6)); + fprintf(stderr, getstr(7)); exit(2); } @@ -264,7 +285,7 @@ st = ptr + 1; } if (lbr != rbr) { - errx(2, "parentheses not balanced"); + errx(2, getstr(8)); } } @@ -344,6 +365,15 @@ char *ep; struct stat *finfo = 0; + setlocale(LC_ALL, ""); + +#ifndef WITHOUT_NLS + catalog = catopen("grep", NL_CAT_LOCALE); + if (catalog == ((nl_catd)-1)) + printf("HIBA: %d\n", errno); + +#endif + SLIST_INIT(&patfilelh); switch (__progname[0]) { case 'e': @@ -383,7 +413,7 @@ if (newarg || !isdigit(lastc)) Aflag = 0; else if (Aflag > INT_MAX / 10) - errx(2, "context out of range"); + errx(2, getstr(9)); Aflag = Bflag = (Aflag * 10) + (c - '0'); break; case 'A': @@ -391,7 +421,7 @@ l = strtol(optarg, &ep, 10); if (ep == optarg || *ep != '\0' || l <= 0 || l >= INT_MAX) - errx(2, "context out of range"); + errx(2, getstr(9)); if (c == 'A') Aflag = (int)l; else @@ -410,7 +440,7 @@ l = strtol(optarg, &ep, 10); if (ep == optarg || *ep != '\0' || l <= 0 || l >= INT_MAX) - errx(2, "context out of range"); + errx(2, getstr(9)); Aflag = Bflag = (int)l; } break; @@ -517,7 +547,7 @@ /* default, compatibility */ break; case 'V': - printf("FreeBSD grep 2.5.1\n"); + printf(getstr(10)); exit(0); case 'v': vflag = 1; @@ -539,7 +569,7 @@ else if (strcmp("text", optarg) == 0) binbehave = BIN_FILE_TEXT; else - errx(2, "Unknown binary-files option"); + errx(2, getstr(11)); break; case COLOR_OPT: if (optarg == NULL) @@ -639,6 +669,11 @@ } c+= procfile(*argv); } + +#ifndef WITHOUT_NLS + catclose(catalog); +#endif + if (c) { if (notfound && qflag) exit(0); ==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#18 (text+ko) ==== @@ -33,6 +33,18 @@ #include #include +#ifdef WITHOUT_NLS +#define getstr(n) errstr[n] +#else +#include + +extern nl_catd catalog; +#define getstr(n) catgets(catalog, 1, n, errstr[n]) +#endif + +extern char *errstr[]; + + #define BIN_FILE_BIN 0 #define BIN_FILE_SKIP 1 #define BIN_FILE_TEXT 2 ==== //depot/projects/soc2008/gabor_textproc/grep/util.c#32 (text+ko) ==== @@ -135,7 +135,7 @@ if (label != NULL) fn = label; else - fn = "(standard input)"; + fn = getstr(1); f = grep_fdopen(STDIN_FILENO, "r"); } else { f = grep_open(fn, "r"); @@ -198,7 +198,7 @@ printf("%s\n", fn); if (c && !cflag && !lflag && !Lflag && binbehave == BIN_FILE_BIN && nottext && !qflag) - printf("Binary file %s matches\n", fn); + printf(getstr(12), fn); return (c); }