modified for inclusion in GNO base build

This commit is contained in:
gdr 1997-10-30 03:50:04 +00:00
parent fbcef9625a
commit e7015008c4
11 changed files with 179 additions and 204 deletions

View File

@ -1,24 +1,16 @@
#
# $Id: Makefile,v 1.1 1997/09/21 22:12:26 gdr Exp $
# $Id: Makefile,v 1.2 1997/10/30 03:49:46 gdr Exp $
#
include ../../../paths.mk
include ../../constants.mk
BUILD_TARGET = $(BUILD_DIR)/fmt
CPPFLAGS += -I../../hdr
# Program name
PROG = fmt
SRCS = fmt.c head.c
build: setup $(BUILD_TARGET)
# Add -D__STACK_CHECK__ to print, on exit, the amount of stack used
CFLAGS += -DBUILD_FMT -DNO_LOCALE
STACK = 1536
BINDIR = /usr/bin
$(BUILD_TARGET): $(OBJS)
$(CC) -o $@ $(LDFLAGS) $(OBJS) $(LDLIBS)
.INCLUDE: /src/gno/prog.mk
install:
$(INSTALL) -m755 -d $(INSTROOT)/$(BUILD_DIR)/install
$(INSTALL) -m755 $(BUILD_TARGET) $(INSTROOT)/$(BUILD_DIR)/install
$(INSTALL) -m644 fmt.README $(INSTROOT)/$(BUILD_DIR)/install
clobber::
$(RM) -f *~
include ../../rules.mk
-include $(BUILD_DIR)/dependencies
head.o:: def.h extern.h

View File

@ -50,7 +50,9 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#ifndef BUILD_FMT
#include "pathnames.h"
#endif
#define APPEND /* New mail goes to end of mailbox */
@ -102,6 +104,7 @@ struct message {
* The actual table is declared and initialized
* in lex.c
*/
#ifndef BUILD_FMT
struct cmd {
char *c_name; /* Name of command */
int (*c_func)(); /* Implementor of the command */
@ -109,6 +112,7 @@ struct cmd {
short c_msgflag; /* Required flags of messages */
short c_msgmask; /* Relevant flags of messages */
};
#endif
/* Yechh, can't initialize unions */

View File

@ -33,14 +33,6 @@
* @(#)extern.h 8.1 (Berkeley) 6/6/93
*/
#ifndef __P
#ifdef __STDC__
#define __P(a) a
#else
#define __P(a) ()
#endif
#endif
struct name *cat __P((struct name *, struct name *));
struct name *delname __P((struct name *, char []));
struct name *elide __P((struct name *));
@ -208,7 +200,10 @@ void regret __P((int));
void relsesigs __P((void));
int respond __P((int *));
int retfield __P((char *[]));
#ifndef __GNO__
/* hmmm.. conflict through mutual namespace pollution */
int rexit __P((int));
#endif
int rm __P((char *));
int run_command __P((char *, int, int, int, char *, char *, char *));
int save __P((char []));

View File

@ -31,21 +31,18 @@
.\"
.\" @(#)fmt.1 8.1 (Berkeley) 6/6/93
.\"
.\" $Id: fmt.1,v 1.2 1997/09/21 22:12:26 gdr Exp $
.\" $Id: fmt.1,v 1.3 1997/10/30 03:49:47 gdr Exp $
.\"
.TH FMT 1 "2 August 1997" "GNO" "Commands and Applications"
.TH FMT 1 "19 October 1997" "GNO" "Commands and Applications"
.SH NAME
fmt \- simple text formatter
.SH SYNOPSIS
.BR fmt
[
.B -o
.I goal
[
.I maximum
]] [
.B -c
] [
.I "name ..."
]
.SH DESCRIPTION

View File

@ -31,9 +31,7 @@
* SUCH DAMAGE.
*/
#ifdef __GNUC__
#define lint
#endif
#ifndef __GNO__
#ifndef lint
static char copyright[] =
@ -45,43 +43,44 @@ static char copyright[] =
static char sccsid[] = "@(#)fmt.c 8.1 (Berkeley) 7/20/93";
#endif /* not lint */
#endif /* ! __GNO__ */
#include <stdio.h>
#include <ctype.h>
#ifndef NO_LOCALE
#include <locale.h>
#endif
#include <stdlib.h>
#include <string.h>
/* some architectures have a broken (and non-standard) realloc(3) */
#ifdef SUNOS4
#include "sunos4stdio.h"
#endif
#ifndef __P
#ifdef __STDC__
#define __P(a) a
#else
#define __P(a) ()
#endif
#endif
#define REALLOC my_realloc
static void * my_realloc __P((void *buf, size_t size));
#else
#define REALLOC realloc
#endif
/* reduce stack usage */
#ifdef __ORCAC__
#define STATIC static
#else
#define STATIC
#endif
static void fmt __P((FILE *fi));
static void prefix __P((char *line));
static void split __P((char *line));
static void setout __P((void));
static void pack __P((char *word, int wl));
static void pack __P((char *textword, int wl));
static void oflush __P((void));
static void tabulate __P((char *line));
static void leadin __P((void));
static int ispref __P((char *s1, char *s2));
static void *my_realloc __P((void *buf, size_t size));
#if 0
static char *savestr __P((char *str));
#endif
extern int ishead __P((char *));
#if defined(SOLARIS) || defined(HALOS)
#if defined(SOLARIS) || defined(HALOS) || defined(__ORCAC__)
#define INDEX(s,c) strchr((s),(c))
#else
#define INDEX index
@ -112,6 +111,14 @@ int mark; /* Last place we saw a head line */
char *headnames[] = {"To", "Subject", "Cc", 0};
#ifdef __STACK_CHECK__
#include <gno/gno.h>
static void
printStack (void) {
printf("stack usage: %d bytes\n", _endStackCheck());
}
#endif
/*
* Drive the whole formatter by managing input files. Also,
* cause initialization of the output stuff and flush it out
@ -119,15 +126,20 @@ char *headnames[] = {"To", "Subject", "Cc", 0};
*/
int
main(argc, argv)
int argc;
char **argv;
main(int argc, char **argv)
{
register FILE *fi;
register int errs = 0;
int number; /* LIZ@UOM 6/18/85 */
#ifdef __STACK_CHECK__
_beginStackCheck();
atexit(printStack);
#endif
#ifndef NO_LOCALE
(void) setlocale(LC_CTYPE, "");
#endif
goal_length = GOAL_LENGTH;
max_length = MAX_LENGTH;
@ -176,8 +188,7 @@ main(argc, argv)
* and sending each line down for analysis.
*/
static void
fmt(fi)
FILE *fi;
fmt(FILE *fi)
{
static char *linebuf = 0, *canonb = 0;
register char *cp, *cp2, cc;
@ -289,8 +300,7 @@ fmt(fi)
* it on a line by itself.
*/
static void
prefix(line)
char line[];
prefix(char *line)
{
register char *cp, **hp;
register int np, h;
@ -337,20 +347,19 @@ prefix(line)
* line packer.
*/
static void
split(line)
char line[];
split(char *line)
{
register char *cp, *cp2;
char word[BUFSIZ];
STATIC char textword[BUFSIZ];
int wordl; /* LIZ@UOM 6/18/85 */
cp = line;
while (*cp) {
cp2 = word;
cp2 = textword;
wordl = 0; /* LIZ@UOM 6/18/85 */
/*
* Collect a 'word,' allowing it to contain escaped white
* Collect a 'textword,' allowing it to contain escaped white
* space.
*/
while (*cp && *cp != ' ') {
@ -373,9 +382,9 @@ split(line)
*cp2++ = *cp++;
*cp2 = '\0';
/*
* LIZ@UOM 6/18/85 pack(word);
* LIZ@UOM 6/18/85 pack(textword);
*/
pack(word, wordl);
pack(textword, wordl);
}
}
@ -395,35 +404,33 @@ char *outp; /* Pointer in above */
* Initialize the output section.
*/
static void
setout()
setout(void)
{
outp = NOSTR;
}
/*
* Pack a word onto the output line. If this is the beginning of
* Pack a textword onto the output line. If this is the beginning of
* the line, push on the appropriately-sized string of blanks first.
* If the word won't fit on the current line, flush and begin a new
* line. If the word is too long to fit all by itself on a line,
* If the textword won't fit on the current line, flush and begin a new
* line. If the textword is too long to fit all by itself on a line,
* just give it its own and hope for the best.
*
* LIZ@UOM 6/18/85 -- If the new word will fit in at less than the
* LIZ@UOM 6/18/85 -- If the new textword will fit in at less than the
* goal length, take it. If not, then check to see if the line
* will be over the max length; if so put the word on the next
* will be over the max length; if so put the textword on the next
* line. If not, check to see if the line will be closer to the
* goal length with or without the word and take it or put it on
* goal length with or without the textword and take it or put it on
* the next line accordingly.
*/
/*
* LIZ@UOM 6/18/85 -- pass in the length of the word as well
* pack(word)
* char word[];
* LIZ@UOM 6/18/85 -- pass in the length of the textword as well
* pack(textword)
* char textword[];
*/
static void
pack(word,wl)
char word[];
int wl;
pack(char *textword, int wl)
{
register char *cp;
register int s, t;
@ -432,9 +439,9 @@ pack(word,wl)
leadin();
/*
* LIZ@UOM 6/18/85 -- change condition to check goal_length; s is the
* length of the line before the word is added; t is now the length
* of the line after the word is added
* t = strlen(word);
* length of the line before the textword is added; t is now the length
* of the line after the textword is added
* t = strlen(textword);
* if (t+s <= LENGTH)
*/
s = outp - outbuf;
@ -444,14 +451,14 @@ pack(word,wl)
/*
* In like flint!
*/
for (cp = word; *cp; *outp++ = *cp++);
for (cp = textword; *cp; *outp++ = *cp++);
return;
}
if (s > pfx) {
oflush();
leadin();
}
for (cp = word; *cp; *outp++ = *cp++);
for (cp = textword; *cp; *outp++ = *cp++);
}
/*
@ -460,7 +467,7 @@ pack(word,wl)
* line prefix.
*/
static void
oflush()
oflush(void)
{
if (outp == NOSTR)
return;
@ -474,8 +481,7 @@ oflush()
* output on standard output (finally).
*/
static void
tabulate(line)
char line[];
tabulate(char *line)
{
register char *cp;
register int b, t;
@ -514,7 +520,7 @@ tabulate(line)
* leading blanks.
*/
static void
leadin()
leadin(void)
{
register int b;
register char *cp;
@ -530,9 +536,10 @@ leadin()
* This little goodie is needed for
* a headline detector in head.c
*/
static char *savestr __P((char *str));
static char *
savestr(str)
char str[];
savestr(char *str)
{
register char *top;
@ -550,8 +557,7 @@ savestr(str)
* Is s1 a prefix of s2??
*/
static int
ispref(s1, s2)
register char *s1, *s2;
ispref(register char *s1, register char *s2)
{
while (*s1++ == *s2)
@ -560,6 +566,7 @@ ispref(s1, s2)
}
#ifndef __ORCAC__
/*
* some architectures' reallocs are too damned stupid to accept NULL
* buf arguments ...
@ -574,3 +581,4 @@ my_realloc (void *buf, size_t size)
return (void *) realloc(buf, size);
}
}
#endif

9
usr.bin/fmt/fmt.desc Normal file
View File

@ -0,0 +1,9 @@
Name: fmt
Version: 1.0 (19 Oct 97)
Shell: GNO
Author: Ported by Devin Reade.
Contact: gdr@eddore.myrias.com
Where: /usr/bin
FTP: ground.isca.uiowa.edu apple2.caltech.edu trenco.myrias.com
Simple text formatter.

17
usr.bin/fmt/fmt.rez Normal file
View File

@ -0,0 +1,17 @@
/*
* $Id: fmt.rez,v 1.1 1997/10/30 03:49:47 gdr Exp $
*/
#include "Types.Rez"
resource rVersion (0x1, purgeable3, nocrossbank) {
{ 1, 0, 0, /* version 1.0.0 */
release, /* development|alpha|beta|final|release */
0 /* non-final release number */
},
verUS,
"fmt",
"Simple text formatter\n"
"Ported by Devin Reade for GNO v2.0.6"
};

View File

@ -35,11 +35,22 @@
#define lint
#endif
#ifndef lint
#if !defined(lint) && !defined(__GNO__)
static char sccsid[] = "@(#)head.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "rcv.h"
/* save some stack space */
#ifdef __ORCAC__
#define STATIC static
#else
#define STATIC
#endif
#ifdef CHECK_RECURSION
#include <assert.h>
#endif
#include "def.h"
#include "extern.h"
/*
@ -54,36 +65,50 @@ static char sccsid[] = "@(#)head.c 8.1 (Berkeley) 6/6/93";
* accomodate all funny formats.
*/
int
ishead(linebuf)
char linebuf[];
ishead(char linebuf[])
{
register char *cp;
struct headline hl;
char parbuf[BUFSIZ];
STATIC char parbuf[BUFSIZ];
#ifdef CHECK_RECURSION
static int recursing = 0;
assert(recursing == 0);
recursing++;
#define RETURN(val) { recursing--; return val; }
#else
#define RETURN(val) return (val)
#endif
cp = linebuf;
if (*cp++ != 'F' || *cp++ != 'r' || *cp++ != 'o' || *cp++ != 'm' ||
*cp++ != ' ')
return (0);
RETURN (0);
parse(linebuf, &hl, parbuf);
if (hl.l_from == NOSTR || hl.l_date == NOSTR) {
#ifndef BUILD_FMT
fail(linebuf, "No from or date field");
return (0);
#endif
RETURN (0);
}
if (!isdate(hl.l_date)) {
#ifndef BUILD_FMT
fail(linebuf, "Date field not legal date");
return (0);
#endif
RETURN (0);
}
/*
* I guess we got it!
*/
return (1);
RETURN (1);
}
#undef RETURN
#ifndef BUILD_FMT
/*ARGSUSED*/
void
fail(linebuf, reason)
char linebuf[], reason[];
fail(char *linebuf, char *reason)
{
/*
@ -92,6 +117,7 @@ fail(linebuf, reason)
fprintf(stderr, "\"%s\"\nnot a header because %s\n", linebuf, reason);
*/
}
#endif
/*
* Split a headline into its useful components.
@ -100,13 +126,17 @@ fail(linebuf, reason)
* structure. Actually, it scans.
*/
void
parse(line, hl, pbuf)
char line[], pbuf[];
register struct headline *hl;
parse(char line[], register struct headline *hl, char pbuf[])
{
register char *cp;
char *sp;
char word[LINESIZE];
STATIC char word[LINESIZE];
#ifdef CHECK_RECURSION
static int recursing = 0;
assert(recursing == 0);
recursing++;
#endif
hl->l_from = NOSTR;
hl->l_tty = NOSTR;
@ -126,6 +156,9 @@ parse(line, hl, pbuf)
}
if (cp != NOSTR)
hl->l_date = copyin(cp, &sp);
#ifdef CHECK_RECURSION
recursing--;
#endif
}
/*
@ -135,9 +168,7 @@ parse(line, hl, pbuf)
* the left string into it.
*/
char *
copyin(src, space)
register char *src;
char **space;
copyin(register char *src, char **space)
{
register char *cp;
char *top;
@ -170,10 +201,8 @@ char ctype[] = "Aaa Aaa O0 00:00:00 0000";
char tmztype[] = "Aaa Aaa O0 00:00:00 AAA 0000";
int
isdate(date)
char date[];
isdate(char date[])
{
return cmatch(date, ctype) || cmatch(date, tmztype);
}
@ -182,8 +211,7 @@ isdate(date)
* Return 1 if they match, 0 if they don't
*/
int
cmatch(cp, tp)
register char *cp, *tp;
cmatch(register char *cp, register char *tp)
{
while (*cp && *tp)
@ -229,8 +257,7 @@ cmatch(cp, tp)
* or NOSTR if none follow.
*/
char *
nextword(wp, wbuf)
register char *wp, *wbuf;
nextword(register char *wp, register char *wbuf)
{
register c;

View File

@ -1,42 +0,0 @@
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. 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.
*
* @(#)pathnames.h 8.1 (Berkeley) 6/6/93
*/
/* #include <paths.h> */
#define _PATH_EX "/usr/bin/ex"
#define _PATH_HELP "/usr/share/misc/mail.help"
#define _PATH_TILDE "/usr/share/misc/mail.tildehelp"
#define _PATH_MASTER_RC "/etc/mail.rc"
#define _PATH_MORE "/usr/bin/more"

View File

@ -1,46 +0,0 @@
/*
* Copyright (c) 1980, 1993
* The Regents of the University of California. 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.
*
* @(#)rcv.h 8.1 (Berkeley) 6/6/93
*/
/*
* Mail -- a mail program
*
* This file is included by normal files which want both
* globals and declarations.
*/
#include "def.h"
#ifndef SUNOS4
#include "glob.h"
#endif

14
usr.bin/fmt/tests/in1 Normal file
View File

@ -0,0 +1,14 @@
now is the
time
to fribble in the glotz
And this would be a new paragraph. One that is slightly longer
and therefore should be gauranteed to wrap over on to at least a
few lines. Rickem, rackem, ruckem, get that ball and really fight!
This one is a final paragraph that *should* broken up.
This line should be indented eight characters.
This line should be attached to the previous one.
This line should also be indented eight characters.
This line should be a carry-over from the last but should only be
indented four characters.