This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH] strace.cc: getopts_long, --help, --version


On Thu, Oct 18, 2001 at 06:06:51PM -0500, Gary R Van Sickle wrote:
>Unfortunately I won't be able to get the assignment forms out of here until
>at least Monday....

This is great!  Thank you.  Please get your assignment in.

cgf

>2001-10-18  Gary R. Van Sickle <g.r.vansickle@worldnet.att.net>
>
>	* strace.cc (main): Change getopt() to getopt_long().
>	Add support for help and version info.
>	(longopts): Add long options structure.
>	(opts): Move options string from getopts call to static var.
>	(usage): Print usage information.
>	(version): Stub for eventually displaying version info.
>
>
>Index: winsup/utils/strace.cc
>===================================================================
>RCS file: /cvs/src/src/winsup/utils/strace.cc,v
>retrieving revision 1.11
>diff -p -u -b -r1.11 strace.cc
>--- strace.cc	2001/03/05 17:55:23	1.11
>+++ strace.cc	2001/10/18 16:16:13
>@@ -588,6 +588,69 @@ dostrace (unsigned mask, FILE *ofile, ch
>   return;
> }
>
>+static void usage ()
>+{
>+  fprintf (stderr,
>+"\
>+Usage: strace [OPTIONS] <command-line>\n\
>+  -b, --buffer-size=SIZE        Set size of output file buffer.\n\
>+  -m, --mask=MASK               Set message filter mask.  MASK must be
>hex,\n\
>+                                (0x is optional) and can be any ORed
>combination\n\
>+                                of the following:\n\
>+\n\
>+    0x00001 (_STRACE_ALL)       All strace messages.\n\
>+    0x00002 (_STRACE_FLUSH)     Flush output buffer after every message.\n\
>+    0x00004 (_STRACE_INHERIT)   Children inherit mask from parent.\n\
>+    0x00008 (_STRACE_UHOH)      Unusual or weird phenomenon.\n\
>+    0x00010 (_STRACE_SYSCALL)   System calls.\n\
>+    0x00020 (_STRACE_STARTUP)   argc/envp printout at startup.\n\
>+    0x00040 (_STRACE_DEBUG)     Info to help debugging. \n\
>+    0x00080 (_STRACE_PARANOID)  Paranoid info.\n\
>+    0x00100 (_STRACE_TERMIOS)   Info for debugging termios stuff.\n\
>+    0x00200 (_STRACE_SELECT)    Info on ugly select internals.\n\
>+    0x00400 (_STRACE_WM)        Trace windows messages (enable
>_strace_wm).\n\
>+    0x00800 (_STRACE_SIGP)      Trace signal and process handling.\n\
>+    0x01000 (_STRACE_MINIMAL)   Very minimal strace output.\n\
>+    0x04000 (_STRACE_EXITDUMP)  Dump strace cache on exit.\n\
>+    0x08000 (_STRACE_SYSTEM)    Cache strace messages.\n\
>+    0x10000 (_STRACE_NOMUTEX)   Don't use mutex for synchronization.\n\
>+    0x20000 (_STRACE_MALLOC)    Trace malloc calls.\n\
>+    0x40000 (_STRACE_THREAD)    Thread-locking calls.\n\
>+\n\
>+  -o, --output=FILENAME         Set output file to FILENAME.\n\
>+  -f, --fork-debug              ???\n\
>+  -n, --error-number            Also output associated Windows error
>number.\n\
>+  -d, --delta                   Add a delta-t timestamp to each output
>line.\n\
>+  -u, --usecs                   Add a microsecond-resolution timestamp to
>each
>+                                output line.\n\
>+  -t, --timestamp               Add an hhmmss timestamp to each output
>line.\n\
>+  -v, --version                 Display version info.\n\
>+  -h, --help                    Display this help info.\n\
>+");
>+}
>+
>+static void version ()
>+{
>+	fprintf (stderr, "Not yet implemented.");
>+}
>+
>+struct option longopts[] =
>+{
>+  {"help", no_argument, NULL, 'h' },
>+  {"version", no_argument, NULL, 'v' },
>+  {"buffer-size", required_argument, NULL, 'b'},
>+  {"mask", required_argument, NULL, 'm'},
>+  {"output", required_argument, NULL, 'o'},
>+  {"fork-debug", no_argument, NULL, 'f'},
>+  {"error-number", no_argument, NULL, 'n'},
>+  {"delta", no_argument, NULL, 'd'},
>+  {"usecs", no_argument, NULL, 'u'},
>+  {"timestamp", no_argument, NULL, 't'},
>+  {NULL, 0, NULL, 0}
>+};
>+
>+static const char *const opts = "hvb:m:o:fndut";
>+
> int
> main (int argc, char **argv)
> {
>@@ -600,9 +663,19 @@ main (int argc, char **argv)
>   else
>     pgm++;
>
>-  while ((opt = getopt (argc, argv, "b:m:o:fndut")) != EOF)
>+  while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
>     switch (opt)
>       {
>+      case 'h':
>+    // Print help and exit
>+    usage ();
>+    return 1;
>+    break;
>+      case 'v':
>+    // Print version info and exit
>+    version ();
>+    return 1;
>+    break;
>       case 'f':
> 	forkdebug ^= 1;
> 	break;

-- 
cgf@cygnus.com                        Red Hat, Inc.
http://sources.redhat.com/            http://www.redhat.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]