fmt.c (dc3001cf357baa1d3fca2f6e9b49c9b1e5919713) fmt.c (9c61e1111eceb2e2a4685ff2e3a283737e266abc)
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

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

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)fmt.c 8.1 (Berkeley) 7/20/93";
43#else
44static const char rcsid[] =
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

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

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)fmt.c 8.1 (Berkeley) 7/20/93";
43#else
44static const char rcsid[] =
45 "$Id: fmt.c,v 1.9 1997/07/03 07:19:46 charnier Exp $";
45 "$Id: fmt.c,v 1.10 1997/08/21 03:41:41 jlemon Exp $";
46#endif
47#endif /* not lint */
48
49#include <ctype.h>
50#include <err.h>
51#include <locale.h>
52#include <stdio.h>
53#include <stdlib.h>

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

334 * attached at the end. Pass these words along to the output
335 * line packer.
336 */
337void
338split(line)
339 char line[];
340{
341 register char *cp, *cp2;
46#endif
47#endif /* not lint */
48
49#include <ctype.h>
50#include <err.h>
51#include <locale.h>
52#include <stdio.h>
53#include <stdlib.h>

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

334 * attached at the end. Pass these words along to the output
335 * line packer.
336 */
337void
338split(line)
339 char line[];
340{
341 register char *cp, *cp2;
342 char word[BUFSIZ];
342 static char *word=0;
343 static int wordsize=0;
343 int wordl; /* LIZ@UOM 6/18/85 */
344
344 int wordl; /* LIZ@UOM 6/18/85 */
345
346 {
347 int l = strlen(line);
348 if (l >= wordsize) {
349 if (word)
350 free(word);
351 wordsize = (l+66)&~63;
352 word = malloc(wordsize);
353 if (word == NULL)
354 abort();
355 }
356 }
357
345 cp = line;
346 while (*cp) {
347 cp2 = word;
348 wordl = 0; /* LIZ@UOM 6/18/85 */
349
350 /*
351 * Collect a 'word,' allowing it to contain escaped white
352 * space.

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

359 }
360
361 /*
362 * Guarantee a space at end of line. Two spaces after end of
363 * sentence punctuation.
364 */
365 if (*cp == '\0') {
366 *cp2++ = ' ';
358 cp = line;
359 while (*cp) {
360 cp2 = word;
361 wordl = 0; /* LIZ@UOM 6/18/85 */
362
363 /*
364 * Collect a 'word,' allowing it to contain escaped white
365 * space.

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

372 }
373
374 /*
375 * Guarantee a space at end of line. Two spaces after end of
376 * sentence punctuation.
377 */
378 if (*cp == '\0') {
379 *cp2++ = ' ';
367 if (index(".:!", cp[-1]))
380 if (cp != line && index(".:!", cp[-1]))
368 *cp2++ = ' ';
369 }
370 while (*cp == ' ')
371 *cp2++ = *cp++;
372 *cp2 = '\0';
373 /*
374 * LIZ@UOM 6/18/85 pack(word);
375 */

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

381 * Output section.
382 * Build up line images from the words passed in. Prefix
383 * each line with correct number of blanks. The buffer "outbuf"
384 * contains the current partial line image, including prefixed blanks.
385 * "outp" points to the next available space therein. When outp is NOSTR,
386 * there ain't nothing in there yet. At the bottom of this whole mess,
387 * leading tabs are reinserted.
388 */
381 *cp2++ = ' ';
382 }
383 while (*cp == ' ')
384 *cp2++ = *cp++;
385 *cp2 = '\0';
386 /*
387 * LIZ@UOM 6/18/85 pack(word);
388 */

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

394 * Output section.
395 * Build up line images from the words passed in. Prefix
396 * each line with correct number of blanks. The buffer "outbuf"
397 * contains the current partial line image, including prefixed blanks.
398 * "outp" points to the next available space therein. When outp is NOSTR,
399 * there ain't nothing in there yet. At the bottom of this whole mess,
400 * leading tabs are reinserted.
401 */
389char outbuf[BUFSIZ]; /* Sandbagged output line image */
402char *outbuf; /* Sandbagged output line image */
390char *outp; /* Pointer in above */
403char *outp; /* Pointer in above */
404int outbuf_size; /* er, size of outbuf */
391
392/*
393 * Initialize the output section.
394 */
395void
396setout()
397{
405
406/*
407 * Initialize the output section.
408 */
409void
410setout()
411{
412 outbuf = malloc(BUFSIZ);
413 if (outbuf == 0)
414 abort();
415 outbuf_size = BUFSIZ;
398 outp = NOSTR;
399}
400
401/*
402 * Pack a word onto the output line. If this is the beginning of
403 * the line, push on the appropriately-sized string of blanks first.
404 * If the word won't fit on the current line, flush and begin a new
405 * line. If the word is too long to fit all by itself on a line,

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

421void
422pack(word,wl)
423 char word[];
424 int wl;
425{
426 register char *cp;
427 register int s, t;
428
416 outp = NOSTR;
417}
418
419/*
420 * Pack a word onto the output line. If this is the beginning of
421 * the line, push on the appropriately-sized string of blanks first.
422 * If the word won't fit on the current line, flush and begin a new
423 * line. If the word is too long to fit all by itself on a line,

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

439void
440pack(word,wl)
441 char word[];
442 int wl;
443{
444 register char *cp;
445 register int s, t;
446
447 if (((outp==NOSTR) ? wl : outp-outbuf + wl) >= outbuf_size) {
448 char *old_outbuf = outbuf;
449 outbuf_size *= 2;
450 outbuf = realloc(outbuf, outbuf_size);
451 if (outbuf == 0)
452 abort();
453 outp += outbuf-old_outbuf;
454 }
455
429 if (outp == NOSTR)
430 leadin();
431 /*
432 * LIZ@UOM 6/18/85 -- change condition to check goal_length; s is the
433 * length of the line before the word is added; t is now the length
434 * of the line after the word is added
435 * t = strlen(word);
436 * if (t+s <= LENGTH)

--- 118 unchanged lines hidden ---
456 if (outp == NOSTR)
457 leadin();
458 /*
459 * LIZ@UOM 6/18/85 -- change condition to check goal_length; s is the
460 * length of the line before the word is added; t is now the length
461 * of the line after the word is added
462 * t = strlen(word);
463 * if (t+s <= LENGTH)

--- 118 unchanged lines hidden ---