home *** CD-ROM | disk | FTP | other *** search
- /*
- * strxline.c
- * contains: strxline()
- *
- */
-
- #include <stdio.h>
- #include "gfuncts.h"
-
- /*
- * char *
- * strxline(outstr,instr,maxcols)
- *
- * ARGUMENT
- * (char *) outstr - destination string
- * (char *) instr - source string
- * (int) maxcols - Maximum number of characters in destination
- *
- * DESCRIPTION
- * The source string is scanned left to right, and up to one line of
- * text is extracted to a destination string. When a "gteol" (Technical
- * End Of Line) or a newline is encountered, the string up to that point
- * is terminated with a newline and EOS termination and copied to the
- * destination string.
- *
- * Also, if gmaxcol characters have been transferred without a gteol or
- * a newline being encountered (or the end of string reached), the source
- * string pointer is backed up to the first non-whitespace character
- * preceding the current word, a newline is inserted, and the string up
- * to that point is transferred as though a newline or gteol had been found.
- *
- * The utility of this function is to extract strings from a text file,
- * even though the text may not be broken into logical lines.
- *
- * RETURNS
- * Pointer to next part of string following transfer,
- * or 0 if the end of the source string was reached.
- *
- * AUTHOR
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
- char* GF_CONV strxline(outstr,instr,maxcols)
- char *outstr,*instr;
- int maxcols;
- {
- char *pi,*po,c;
- int i,k,imax;
-
- i=k=0;
- imax=(maxcols<=gmaxcol?maxcols:gmaxcol );
- po=outstr;
- pi=instr;
- while (FOREVER) {
- if (i>=imax) {
- k=0;
- while(k<25) {
- if(!gisspace(*pi)) {
- --pi;
- --po;
- ++k;
- } else
- break;
- }
- ++pi;
- *++po='\n';
- *++po='\0';
- return pi;
- } else {
- if(((c = *pi)==0)&&i==0)
- return (char *)0;
- if(c==gteol)
- c='\n';
- switch (c) {
- case '\n':
- *po++='\n';
- case '\0':
- *po='\0';
- return(c?++pi:pi);
- default:
- *po++=c;
- pi++;
- ++i;
- }
- }
- }
- return((char *)0);
- }
-