prettyness police
[unix-history] / usr / src / bin / sleep / sleep.c
index 171849c..714468b 100644 (file)
@@ -1,22 +1,54 @@
-static char *sccsid = "@(#)sleep.c     4.1 (Berkeley) %G%";
+/*
+ * Copyright (c) 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1988, 1993\n\
+       The Regents of the University of California.  All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)sleep.c    8.2 (Berkeley) %G%";
+#endif /* not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+void usage __P((void));
+
+int
 main(argc, argv)
 main(argc, argv)
-char **argv;
+       int argc;
+       char *argv[];
 {
 {
-       int c, n;
-       char *s;
-
-       n = 0;
-       if(argc < 2) {
-               printf("arg count\n");
-               exit(0);
-       }
-       s = argv[1];
-       while(c = *s++) {
-               if(c<'0' || c>'9') {
-                       printf("bad character\n");
-                       exit(0);
+       int ch, secs;
+
+       while ((ch = getopt(argc, argv, "")) != EOF)
+               switch(ch) {
+               case '?':
+               default:
+                       usage();
                }
                }
-               n = n*10 + c - '0';
-       }
-       sleep(n);
+       argc -= optind;
+       argv += optind;
+
+       if (argc != 1)
+               usage();
+
+       if ((secs = atoi(*argv)) > 0)
+               (void)sleep(secs);
+       exit(0);
+}
+
+void
+usage()
+{
+
+       (void)fprintf(stderr, "usage: sleep seconds\n");
+       exit(1);
 }
 }