date and time created 91/05/12 22:30:02 by william
[unix-history] / usr / src / old / flcopy / flcopy.c
index 789f18e..ab9da47 100644 (file)
@@ -1,7 +1,26 @@
-static char *sccsid ="@(#)flcopy.c     4.4 (Berkeley) %G%";
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)flcopy.c   5.4 (Berkeley) %G%";
+#endif /* not lint */
+
+#include <sys/file.h>
+#include <stdio.h>
+#include "pathnames.h"
 
 int    floppydes;
 
 int    floppydes;
-char   *flopname = "/dev/floppy";
+char   *flopname = _PATH_FLOPPY;
 long   dsize = 77 * 26 * 128;
 int    hflag;
 int    rflag;
 long   dsize = 77 * 26 * 128;
 int    hflag;
 int    rflag;
@@ -9,49 +28,49 @@ int  rflag;
 main(argc, argv)
        register char **argv;
 {
 main(argc, argv)
        register char **argv;
 {
+       extern char *optarg;
+       extern int optind;
        static char buff[512];
        register long count;
        register startad = -26 * 128;
        register int n, file;
        register char *cp;
        static char buff[512];
        register long count;
        register startad = -26 * 128;
        register int n, file;
        register char *cp;
+       int ch;
 
 
-       while ((cp = *++argv), --argc > 0) {
-               if (*cp++!='-')
-                       continue;
-               while (*cp)
-                       switch(*cp++) {
-
-                       case 'h':
-                               hflag++;
-                               printf("Halftime!\n");
-                               if ((file = open("floppy", 0)) < 0)
-                                       printf("can't open \"floppy\"\n"),
+       while ((ch = getopt(argc, argv, "f:hrt:")) != EOF)
+               switch(ch) {
+               case 'f':
+                       flopname = optarg;
+                       break;
+               case 'h':
+                       hflag = 1;
+                       printf("Halftime!\n");
+                       if ((file = open("floppy", 0)) < 0) {
+                               printf("can't open \"floppy\"\n");
                                exit(1);
                                exit(1);
-                               continue;
-
-                       case 't':
-                               if (*cp >= '0' && *cp <= '9')
-                                       dsize = atoi(cp);
-                               else if (argc > 1) {
-                                       dsize = atoi(*++argv);
-                                       argc--;
-                               } else
-                                       dsize = 77;
-                               if (dsize <= 0 || dsize > 77) {
-                                       printf("Bad number of tracks\n");
-                                       exit(2);
-                               }
-                               dsize *= 26 * 128;
-                               continue;
-
-                       case 'r':
-                               rflag++;
                        }
                        }
-       }
+                       break;
+               case 'r':
+                       rflag = 1;
+                       break;
+               case 't':
+                       dsize = atoi(optarg);
+                       if (dsize <= 0 || dsize > 77) {
+                               (void)fprintf(stderr,
+                                   "flcopy: bad number of tracks (0 - 77).\n");
+                               exit(2);
+                       }
+                       dsize *= 26 * 128;
+                       break;
+               case '?':
+               default:
+                       usage();
+               }
+       argc -= optind;
+       argv += optind;
+
        if (!hflag) {
        if (!hflag) {
-               file = creat("floppy", 0666);
-               close(file);
-               file = open("floppy", 2);
+               file = open("floppy", O_RDWR|O_CREAT|O_TRUNC, 0666);
                if (file < 0) {
                        printf("can't open \"floppy\"\n");
                        exit(1);
                if (file < 0) {
                        printf("can't open \"floppy\"\n");
                        exit(1);
@@ -76,6 +95,7 @@ main(argc, argv)
                lwrite(startad, n, buff);
                startad += 512;
        }
                lwrite(startad, n, buff);
                startad += 512;
        }
+       exit(0);
 }
 
 rt_init()
 }
 
 rt_init()
@@ -147,3 +167,9 @@ lwrite(startad, count, obuff)
                startad += 128;
        }
 }
                startad += 128;
        }
 }
+
+usage()
+{
+       (void)fprintf(stderr, "usage: flcopy [-hr] [-f file] [-t ntracks]\n");
+       exit(1);
+}