fmt.c (57c6bd978f417d03539a569bc132aec138825983) fmt.c (ccb8bea4f004ee996833c323bdefce0f86943296)
1/* $OpenBSD: fmt.c,v 1.16 2000/06/25 15:35:42 pjanzen Exp $ */
2
3/* Sensible version of fmt
4 *
5 * Syntax: fmt [ options ] [ goal [ max ] ] [ filename ... ]
6 *
7 * Since the documentation for the original fmt is so poor, here
8 * is an accurate description of what this one does. It's usually

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

197get_positive(const char *s, const char *err_mess, int fussyP) {
198 char *t;
199 long result = strtol(s,&t,0);
200 if (*t) { if (fussyP) goto Lose; else return 0; }
201 if (result<=0) { Lose: errx(EX_USAGE, "%s", err_mess); }
202 return (size_t) result;
203}
204
1/* $OpenBSD: fmt.c,v 1.16 2000/06/25 15:35:42 pjanzen Exp $ */
2
3/* Sensible version of fmt
4 *
5 * Syntax: fmt [ options ] [ goal [ max ] ] [ filename ... ]
6 *
7 * Since the documentation for the original fmt is so poor, here
8 * is an accurate description of what this one does. It's usually

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

197get_positive(const char *s, const char *err_mess, int fussyP) {
198 char *t;
199 long result = strtol(s,&t,0);
200 if (*t) { if (fussyP) goto Lose; else return 0; }
201 if (result<=0) { Lose: errx(EX_USAGE, "%s", err_mess); }
202 return (size_t) result;
203}
204
205static size_t
206get_nonnegative(const char *s, const char *err_mess, int fussyP) {
207 char *t;
208 long result = strtol(s,&t,0);
209 if (*t) { if (fussyP) goto Lose; else return 0; }
210 if (result<0) { Lose: errx(EX_USAGE, "%s", err_mess); }
211 return (size_t) result;
212}
213
205/* Global variables */
206
207static int centerP=0; /* Try to center lines? */
208static size_t goal_length=0; /* Target length for output lines */
209static size_t max_length=0; /* Maximum length for output lines */
210static int coalesce_spaces_P=0; /* Coalesce multiple whitespace -> ' ' ? */
211static int allow_indented_paragraphs=0; /* Can first line have diff. ind.? */
212static int tab_width=8; /* Number of spaces per tab stop */
214/* Global variables */
215
216static int centerP=0; /* Try to center lines? */
217static size_t goal_length=0; /* Target length for output lines */
218static size_t max_length=0; /* Maximum length for output lines */
219static int coalesce_spaces_P=0; /* Coalesce multiple whitespace -> ' ' ? */
220static int allow_indented_paragraphs=0; /* Can first line have diff. ind.? */
221static int tab_width=8; /* Number of spaces per tab stop */
213static size_t output_tab_width=0; /* Ditto, when squashing leading spaces */
222static size_t output_tab_width=8; /* Ditto, when squashing leading spaces */
214static const char *sentence_enders=".?!"; /* Double-space after these */
215static int grok_mail_headers=0; /* treat embedded mail headers magically? */
216
217static int n_errors=0; /* Number of failed files. Return on exit. */
218static char *output_buffer=0; /* Output line will be built here */
219static size_t x; /* Horizontal position in output line */
220static size_t x0; /* Ditto, ignoring leading whitespace */
221static size_t pending_spaces; /* Spaces to add before next word */

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

253 case 'c':
254 centerP = 1;
255 continue;
256 case 'd':
257 sentence_enders = optarg;
258 continue;
259 case 'l':
260 output_tab_width
223static const char *sentence_enders=".?!"; /* Double-space after these */
224static int grok_mail_headers=0; /* treat embedded mail headers magically? */
225
226static int n_errors=0; /* Number of failed files. Return on exit. */
227static char *output_buffer=0; /* Output line will be built here */
228static size_t x; /* Horizontal position in output line */
229static size_t x0; /* Ditto, ignoring leading whitespace */
230static size_t pending_spaces; /* Spaces to add before next word */

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

262 case 'c':
263 centerP = 1;
264 continue;
265 case 'd':
266 sentence_enders = optarg;
267 continue;
268 case 'l':
269 output_tab_width
261 = get_positive(optarg, "output tab width must be positive", 1);
270 = get_nonnegative(optarg, "output tab width must be non-negative", 1);
262 continue;
263 case 'm':
264 grok_mail_headers = 1;
265 continue;
266 case 'p':
267 allow_indented_paragraphs = 1;
268 continue;
269 case 's':

--- 345 unchanged lines hidden ---
271 continue;
272 case 'm':
273 grok_mail_headers = 1;
274 continue;
275 case 'p':
276 allow_indented_paragraphs = 1;
277 continue;
278 case 's':

--- 345 unchanged lines hidden ---