fmt.c (8bbd90727373467dcce77571238fceb192af0747) fmt.c (e6c267f18cf334713acda85263db0cf855b9d989)
1/*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 30 unchanged lines hidden (view full) ---

39
40#ifndef lint
41static char sccsid[] = "@(#)fmt.c 8.1 (Berkeley) 7/20/93";
42#endif /* not lint */
43
44#include <stdio.h>
45#include <ctype.h>
46#include <locale.h>
1/*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 30 unchanged lines hidden (view full) ---

39
40#ifndef lint
41static char sccsid[] = "@(#)fmt.c 8.1 (Berkeley) 7/20/93";
42#endif /* not lint */
43
44#include <stdio.h>
45#include <ctype.h>
46#include <locale.h>
47#include <stdlib.h>
47
48/*
49 * fmt -- format the concatenation of input files or standard input
50 * onto standard output. Designed for use with Mail ~|
51 *
52 * Syntax : fmt [ goal [ max ] ] [ name ... ]
53 * Authors: Kurt Shoens (UCB) 12/7/78;
54 * Liz Allen (UMCP) 2/24/83 [Addition of goal length concept].

--- 76 unchanged lines hidden (view full) ---

131/*
132 * Read up characters from the passed input file, forming lines,
133 * doing ^H processing, expanding tabs, stripping trailing blanks,
134 * and sending each line down for analysis.
135 */
136fmt(fi)
137 FILE *fi;
138{
48
49/*
50 * fmt -- format the concatenation of input files or standard input
51 * onto standard output. Designed for use with Mail ~|
52 *
53 * Syntax : fmt [ goal [ max ] ] [ name ... ]
54 * Authors: Kurt Shoens (UCB) 12/7/78;
55 * Liz Allen (UMCP) 2/24/83 [Addition of goal length concept].

--- 76 unchanged lines hidden (view full) ---

132/*
133 * Read up characters from the passed input file, forming lines,
134 * doing ^H processing, expanding tabs, stripping trailing blanks,
135 * and sending each line down for analysis.
136 */
137fmt(fi)
138 FILE *fi;
139{
139 char linebuf[BUFSIZ], canonb[BUFSIZ];
140 static char *linebuf = 0, *canonb = 0;
140 register char *cp, *cp2, cc;
141 register int c, col;
141 register char *cp, *cp2, cc;
142 register int c, col;
143#define CHUNKSIZE 1024
144 static int lbufsize = 0, cbufsize = 0;
142
143 c = getc(fi);
144 while (c != EOF) {
145 /*
146 * Collect a line, doing ^H processing.
147 * Leave tabs for now.
148 */
149 cp = linebuf;
145
146 c = getc(fi);
147 while (c != EOF) {
148 /*
149 * Collect a line, doing ^H processing.
150 * Leave tabs for now.
151 */
152 cp = linebuf;
150 while (c != '\n' && c != EOF && cp-linebuf < BUFSIZ-1) {
153 while (c != '\n' && c != EOF) {
154 if (cp - linebuf >= lbufsize) {
155 int offset = cp - linebuf;
156 lbufsize += CHUNKSIZE;
157 linebuf = realloc(linebuf, lbufsize);
158 if(linebuf == 0)
159 abort();
160 cp = linebuf + offset;
161 }
151 if (c == '\b') {
152 if (cp > linebuf)
153 cp--;
154 c = getc(fi);
155 continue;
156 }
157 if (!isprint(c) && c != '\t') {
158 c = getc(fi);

--- 14 unchanged lines hidden (view full) ---

173 * Expand tabs on the way to canonb.
174 */
175 col = 0;
176 cp = linebuf;
177 cp2 = canonb;
178 while (cc = *cp++) {
179 if (cc != '\t') {
180 col++;
162 if (c == '\b') {
163 if (cp > linebuf)
164 cp--;
165 c = getc(fi);
166 continue;
167 }
168 if (!isprint(c) && c != '\t') {
169 c = getc(fi);

--- 14 unchanged lines hidden (view full) ---

184 * Expand tabs on the way to canonb.
185 */
186 col = 0;
187 cp = linebuf;
188 cp2 = canonb;
189 while (cc = *cp++) {
190 if (cc != '\t') {
191 col++;
181 if (cp2-canonb < BUFSIZ-1)
182 *cp2++ = cc;
192 if (cp2 - canonb >= cbufsize) {
193 int offset = cp2 - canonb;
194 cbufsize += CHUNKSIZE;
195 canonb = realloc(canonb, cbufsize);
196 if(canonb == 0)
197 abort();
198 cp2 = canonb + offset;
199 }
200 *cp2++ = cc;
183 continue;
184 }
185 do {
201 continue;
202 }
203 do {
186 if (cp2-canonb < BUFSIZ-1)
187 *cp2++ = ' ';
204 if (cp2 - canonb >= cbufsize) {
205 int offset = cp2 - canonb;
206 cbufsize += CHUNKSIZE;
207 canonb = realloc(canonb, cbufsize);
208 if(canonb == 0)
209 abort();
210 cp2 = canonb + offset;
211 }
212 *cp2++ = ' ';
188 col++;
189 } while ((col & 07) != 0);
190 }
191
192 /*
193 * Swipe trailing blanks from the line.
194 */
195 for (cp2--; cp2 >= canonb && *cp2 == ' '; cp2--)

--- 275 unchanged lines hidden ---
213 col++;
214 } while ((col & 07) != 0);
215 }
216
217 /*
218 * Swipe trailing blanks from the line.
219 */
220 for (cp2--; cp2 >= canonb && *cp2 == ' '; cp2--)

--- 275 unchanged lines hidden ---