PERFORCE change 163138 for review

Gabor Kovesdan gabor at FreeBSD.org
Sun May 31 02:18:03 UTC 2009


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

Change 163138 by gabor at gabor_server on 2009/05/31 02:17:48

	- Add some GNU compatibility features
	- Document changes

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/bc/bc.1#2 edit
.. //depot/projects/soc2008/gabor_textproc/bc/bc.y#2 edit

Differences ...

==== //depot/projects/soc2008/gabor_textproc/bc/bc.1#2 (text+ko) ====

@@ -34,7 +34,7 @@
 .\"
 .\"	@(#)bc.1	6.8 (Berkeley) 8/8/91
 .\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: May 31 2009 $
 .Dt BC 1
 .Sh NAME
 .Nm bc
@@ -54,6 +54,8 @@
 Options available:
 .Bl -tag -width Ds
 .It Fl c
+.It Fl d
+.It Fl Fl debug
 .Nm
 is actually a preprocessor for
 .Xr dc 1 ,
@@ -67,17 +69,25 @@
 instead of being interpreted by a running
 .Xr dc 1
 process.
-.It Fl e Ar expression
+.It Fl e Ar exp
+.It Fl Fl expression Ar exp
 Evaluate
 .Ar expression .
 If multiple
 .Fl e
 options are specified, they are processed in the order given,
 separated by newlines.
+.It Fl h
+.It Fl Fl help
+Prints usage information.
 .It Fl l
+.It Fl Fl mathlib
 Allow specification of an arbitrary precision math library.
 The definitions in the library are available to command line
 expressions.
+.It Fl v
+.It Fl Fl version
+Prints version information.
 .El
 .Pp
 The syntax for

==== //depot/projects/soc2008/gabor_textproc/bc/bc.y#2 (text+ko) ====

@@ -40,6 +40,7 @@
 #include <ctype.h>
 #include <err.h>
 #include <errno.h>
+#include <getopt.h>
 #include <limits.h>
 #include <search.h>
 #include <signal.h>
@@ -51,6 +52,7 @@
 #include "extern.h"
 #include "pathnames.h"
 
+#define BC_VER		"1.0-FreeBSD"
 #define END_NODE	((ssize_t) -1)
 #define CONST_STRING	((ssize_t) -2)
 #define ALLOC_STRING	((ssize_t) -3)
@@ -121,6 +123,18 @@
 #define VAR_BASE	(256-4)
 #define MAX_VARIABLES	(VAR_BASE * VAR_BASE)
 
+const struct option long_options[] =
+{
+	{"debug",	no_argument,		NULL,	'd'},
+	{"expression",	required_argument,	NULL,	'e'},
+	{"help",	no_argument,		NULL,	'h'},
+	{"mathlib",	no_argument,		NULL,	'l'},
+	/* compatibility option */
+	{"quiet",	no_argument,		NULL,	'q'},
+	{"version",	no_argument,		NULL,	'v'},
+	{NULL,		no_argument,		NULL,	0}
+};
+
 %}
 
 %start program
@@ -996,7 +1010,7 @@
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: %s [-cl] [-e expression] [file ...]\n",
+	fprintf(stderr, "usage: %s [-cdhlqv] [-e expression] [file ...]\n",
 	    __progname);
 	exit(1);
 }
@@ -1094,7 +1108,8 @@
 	if ((cmdexpr = strdup("")) == NULL)
 		err(1, NULL);
 	/* The d debug option is 4.4 BSD bc(1) compatible */
-	while ((ch = getopt(argc, argv, "cde:l")) != -1) {
+	while ((ch = getopt_long(argc, argv, "cde:hlqv",
+	   long_options, NULL)) != -1) {
 		switch (ch) {
 		case 'c':
 		case 'd':
@@ -1106,9 +1121,19 @@
 				err(1, NULL);
 			free(q);
 			break;
+		case 'h':
+			usage();
+			break;
 		case 'l':
 			sargv[sargc++] = _PATH_LIBB;
 			break;
+		case 'q':
+			/* compatibility option */
+			break;
+		case 'v':
+			fprintf(stderr, "%s (BSD bc) %s\n", __progname, BC_VER);
+			exit(0);
+			break;
 		default:
 			usage();
 		}


More information about the p4-projects mailing list