PERFORCE change 143965 for review

Gabor Kovesdan gabor at FreeBSD.org
Mon Jun 23 13:25:03 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=143965

Change 143965 by gabor at 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 <err.h>
 #include <errno.h>
 #include <getopt.h>
+#include <locale.h>
+#include <nl_types.h>
 #include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -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 <stdio.h>
 #include <zlib.h>
 
+#ifdef WITHOUT_NLS
+#define getstr(n)	 errstr[n]
+#else
+#include <nl_types.h>
+
+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);
 }


More information about the p4-projects mailing list