From 890998957d81b3f5693835d3546158d6093866d5 Mon Sep 17 00:00:00 2001 From: "Emden R. Gansner" Date: Fri, 12 Jul 2013 12:57:00 -0400 Subject: [PATCH] Fix bug 2305. --- cmd/lefty/lefty.1 | 3 +++ cmd/lefty/lefty.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/cmd/lefty/lefty.1 b/cmd/lefty/lefty.1 index 2427c64a3..e4079f73a 100644 --- a/cmd/lefty/lefty.1 +++ b/cmd/lefty/lefty.1 @@ -115,6 +115,9 @@ call. The default file name is .TP .B -V Prints the version. +.TP +.B -? +Prints the usage and exits. .SH SEE ALSO .I lefty user guide. diff --git a/cmd/lefty/lefty.c b/cmd/lefty/lefty.c index 03a19e22c..21b612932 100644 --- a/cmd/lefty/lefty.c +++ b/cmd/lefty/lefty.c @@ -393,6 +393,25 @@ static int processinput (int waitflag) { return rtn; } +static char* usestr = +" -x - exit after processing the input file.\n\ + -e E - parse and execute expression E.\n\ + -el N - set error reporting level. (0)\n\ + -sd N - how much of the stack to show if error is printed. (2)\n\ + -sb N - how much of each function in the stack show if error is printed. (2)\n\ + -df S - set default font.\n\ + -ps F - specify a default file name for postscript files.\n\ + - - read input from stdin.\n\ + -? - show help.\n\ + -V - print version.\n"; + +static void usage(int eval) +{ + fprintf (stderr, "Usage: lefty [options] [file]\n"); + fputs (usestr, stderr); + exit (eval); +} + static void processstr (char *buf) { char *words[100]; char *s, *s1; @@ -441,11 +460,18 @@ static void processargs (int argc, char *argv[]) { fprintf (stderr, "lefty version %s\n", LEFTYVERSION); fprintf (stderr, "graphviz version %s (%s)\n", VERSION, BUILDDATE); } + else if (strcmp (argv[0], "-?") == 0) + usage(0); else if (strcmp (argv[0], "-") == 0) fp = stdin; + else if (argv[0][0] == '-') { + fprintf (stderr, "option %s unrecognized - ignored\n", argv[0]); + } else { - if ((fp = fopen (argv[0], "r")) == NULL) - panic1 (POS, "main", "cannot open input file: %s", argv[0]); + if ((fp = fopen (argv[0], "r")) == NULL) { + fprintf (stderr, "cannot open input file: %s\n", argv[0]); + exit(2); + } } argv++, argc--; } -- 2.40.0