File:  [MW Coherent from dump] / coherent / g / usr / lib / misc / splitter.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:35 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/*
 * Split output lines with \ along whitespace boundarys.
 * Adds a \n at end of line if none exists.
 */
#include <misc.h>

void
splitter(ofp, line, limit)
FILE *ofp;
char *line;
{
	int	pos,	/* display location on line */
		i,	/* data location on line */
		j,	/* location of last white space on 0 */
		c, w;	/* current char and work */

	for (pos = j = i = 0; c = line[i]; i++) {
		if ((pos >= limit) && j) { /* split condition */
			w = line[j];
			line[j] = '\0';
			fprintf(ofp, "%s \\\n", line);
			line += j;
			line[pos = i = j = 0] = w;
		}
		switch (c) {
		case '\n':
			j = pos = 0;
			break;
		case '\t':
			pos |= 7;
		case ' ':
			j = i;
		default:
			pos++;
		}
	}
	fprintf(ofp, "%s", line);
	if(pos)
		fputc('\n', ofp);
}
#ifdef TEST
main()
{
	char buf[100];

	while (NULL != ask(buf, "string"))
		splitter(stdout, buf, 20);
}
#endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.