BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / vis / foldit.c
CommitLineData
03b0bbc4
MT
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
1c15e888
C
5 * Redistribution and use in source and binary forms are permitted
6 * provided that: (1) source distributions retain this entire copyright
7 * notice and comment, and (2) distributions including binaries display
8 * the following acknowledgement: ``This product includes software
9 * developed by the University of California, Berkeley and its contributors''
10 * in the documentation or other materials provided with the distribution
11 * and in all advertising materials mentioning features or use of this
12 * software. Neither the name of the University nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
03b0bbc4
MT
18 */
19
20#ifndef lint
1c15e888 21static char sccsid[] = "@(#)foldit.c 1.1 (Berkeley) 5/23/90";
03b0bbc4
MT
22#endif /* not lint */
23
24foldit(chunk, col, max)
25 char *chunk;
26{
27 register char *cp;
28
29 /*
30 * Keep track of column position. Insert hidden newline
31 * if this chunk puts us over the limit.
32 */
33again:
34 cp = chunk;
35 while (*cp) {
36 switch(*cp) {
37 case '\n':
38 case '\r':
39 col = 0;
40 break;
41 case '\t':
42 col = col + 8 &~ 07;
43 break;
44 case '\b':
45 col = col ? col - 1 : 0;
46 break;
47 default:
48 col++;
49 }
50 if (col > (max - 2)) {
51 printf("\\\n");
52 col = 0;
53 goto again;
54 }
55 cp++;
56 }
57 return (col);
58}