386BSD 0.1 development
[unix-history] / usr / src / usr.bin / fmt / fmt.c
index 97442cc..7ddc34e 100644 (file)
@@ -1,18 +1,45 @@
 /*
  * Copyright (c) 1980 Regents of the University of California.
 /*
  * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char *copyright =
+char copyright[] =
 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  All rights reserved.\n";
 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char *sccsid = "@(#)fmt.c       5.4 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)fmt.c      5.10 (Berkeley) 6/1/90";
+#endif /* not lint */
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -32,8 +59,10 @@ static char *sccsid = "@(#)fmt.c     5.4 (Berkeley) %G%";
 #define        NOSTR   ((char *) 0)    /* Null string pointer for lint */
 
 /* LIZ@UOM 6/18/85 --New variables goal_length and max_length */
 #define        NOSTR   ((char *) 0)    /* Null string pointer for lint */
 
 /* LIZ@UOM 6/18/85 --New variables goal_length and max_length */
-int    goal_length = 65;       /* Target or goal line length in output */
-int    max_length = 75;        /* Max line length in output */
+#define GOAL_LENGTH 65
+#define MAX_LENGTH 75
+int    goal_length;            /* Target or goal line length in output */
+int    max_length;             /* Max line length in output */
 int    pfx;                    /* Current leading blank count */
 int    lineno;                 /* Current input line */
 int    mark;                   /* Last place we saw a head line */
 int    pfx;                    /* Current leading blank count */
 int    lineno;                 /* Current input line */
 int    mark;                   /* Last place we saw a head line */
@@ -55,6 +84,8 @@ main(argc, argv)
        register int errs = 0;
        int number;             /* LIZ@UOM 6/18/85 */
 
        register int errs = 0;
        int number;             /* LIZ@UOM 6/18/85 */
 
+       goal_length = GOAL_LENGTH;
+       max_length = MAX_LENGTH;
        setout();
        lineno = 1;
        mark = -10;
        setout();
        lineno = 1;
        mark = -10;
@@ -207,7 +238,9 @@ prefix(line)
        if (!h && (h = (*cp == '.')))
                oflush();
        pfx = np;
        if (!h && (h = (*cp == '.')))
                oflush();
        pfx = np;
-       split(cp);
+       if (h)
+               pack(cp);
+       else    split(cp);
        if (h)
                oflush();
        lineno++;
        if (h)
                oflush();
        lineno++;
@@ -248,7 +281,7 @@ split(line)
                 */
                if (*cp == '\0') {
                        *cp2++ = ' ';
                 */
                if (*cp == '\0') {
                        *cp2++ = ' ';
-                       if (any(cp[-1], ".:!"))
+                       if (index(".:!", cp[-1]))
                                *cp2++ = ' ';
                }
                while (*cp == ' ')
                                *cp2++ = ' ';
                }
                while (*cp == ' ')
@@ -355,7 +388,7 @@ oflush()
 tabulate(line)
        char line[];
 {
 tabulate(line)
        char line[];
 {
-       register char *cp, *cp2;
+       register char *cp;
        register int b, t;
 
        /*
        register int b, t;
 
        /*