As suggested by Theo, also handle syslogc -nnn (like tail does).
Code borrowed from tail with some changes as syslogc only deals with
lines (and I see no need to extend that).

Index: syslogc.8
===================================================================
RCS file: /cvs/src/usr.sbin/syslogc/syslogc.8,v
retrieving revision 1.9
diff -u -p -r1.9 syslogc.8
--- syslogc.8   12 Jul 2011 11:28:31 -0000      1.9
+++ syslogc.8   12 Jul 2011 11:44:03 -0000
@@ -22,7 +22,10 @@
 .Sh SYNOPSIS
 .Nm syslogc
 .Op Fl Ccfo
-.Op Fl n Ar lines
+.Oo
+.Fl n Ar lines |
+.Fl Ns Ar number
+.Oc
 .Op Fl s Ar reporting_socket
 .Ar logname
 .Nm syslogc
Index: syslogc.c
===================================================================
RCS file: /cvs/src/usr.sbin/syslogc/syslogc.c,v
retrieving revision 1.16
diff -u -p -r1.16 syslogc.c
--- syslogc.c   12 Jul 2011 11:28:31 -0000      1.16
+++ syslogc.c   12 Jul 2011 11:44:03 -0000
@@ -1,4 +1,4 @@
-/* $OpenBSD: syslogc.c,v 1.16 2011/07/12 11:28:31 sthen Exp $ */
+/* $OpenBSD: syslogc.c,v 1.15 2011/07/04 20:23:09 mpf Exp $ */
 
 /*
  * Copyright (c) 2004 Damien Miller
@@ -64,11 +64,69 @@ usage(void)
        extern char *__progname;
 
        fprintf(stderr,
-           "usage: %s [-Ccfo] [-n lines] [-s reporting_socket] logname\n"
+           "usage: %s [-Ccfo] [-n lines | -lines] [-s reporting_socket] "
+           "logname\n"
            "       %s -q\n", __progname, __progname);
        exit(1);
 }
 
+/*
+ * Convert the obsolete argument form into something that getopt can handle.
+ * This means that anything of the form -[0-9][0-9]* that isn't the option
+ * argument for -n gets converted.
+ */
+static void
+obsolete(char *argv[])
+{
+       char *ap, *p, *t;
+       size_t len;
+       char *start;
+
+       while ((ap = *++argv)) {
+               /* Return if "--" or not an option of any form. */
+               if ((ap[0] != '-') || (ap[1] == '-'))
+                       return;
+
+               switch(*++ap) {
+               /* Old-style option. */
+               case '0': case '1': case '2': case '3': case '4':
+               case '5': case '6': case '7': case '8': case '9':
+
+                       /* Malloc space for new option and argument. */
+                       len = strlen(*argv);
+                       if ((start = p = malloc(len + 2)) == NULL)
+                               err(1, NULL);
+
+                       *p++ = *argv[0];
+                       *p++ = 'n';
+                       (void)strlcpy(p, ap, start + len + 2 - p);
+                       *argv = start;
+                       continue;
+
+               /*
+                * Options w/ arguments, skip the argument and continue
+                * with the next option.
+                */
+               case 's':
+               case 'n':
+                       if (!ap[1])
+                               ++argv;
+                       /* FALLTHROUGH */
+               /* Options w/o arguments, continue with the next option. */
+               case 'C':
+               case 'c':
+               case 'f':
+               case 'o':
+               case 'q':
+                       continue;
+
+               /* Illegal option, return and let getopt handle it. */
+               default:
+                       return;
+               }
+       }
+}
+
 int
 main(int argc, char **argv)
 {
@@ -85,6 +143,7 @@ main(int argc, char **argv)
 
        memset(&cc, '\0', sizeof(cc));
 
+       obsolete(argv);
        ctlsock_path = DEFAULT_CTLSOCK;
        rval = oflag = 0;
        while ((ch = getopt(argc, argv, "Ccfhon:qs:")) != -1) {

Reply via email to