home *** CD-ROM | disk | FTP | other *** search
- /*
- * strentab.c
- * contains: strentab()
- *
- */
-
- #include <stdio.h>
- #include "gfuncts.h"
-
- /*
- * char *
- * strentab(destination,source,tabs,def,opt,maxlength)
- *
- * ARGUMENT
- * (char *) destination - points to destination string
- * (char *) source - points to source string
- * (char *) tabs - tab stops string
- * (int) def - default tab stop intervals
- * (only used when tabs==NULL)
- * (int) opt - options
- * 0=Expand single spaces
- * 1=Copy Single Spaces
- * (int) maxlength - maximum length of output string
- *
- * DESCRIPTION
- * The source string is copied to the destination string except that
- * spaces are converted to tab characters (\t).
- *
- * SIDE EFFECTS
- * (none)
- *
- * RETURNS
- * pointer to destination string or NULL if source or destination are NULL
- * or tabs is NULL and default is 0.
- *
- * AUTHOR
- * "" 21-APR-1987 13:45:50.22
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- *
- * MODIFICATIONS
- *
- */
- char* GF_CONV strentab(destination,source,tabs,def,opt,maxlength)
- char *destination,*source,*tabs;
- int def,opt,maxlength;
- {
- char *orgdest,*s,*t;
- int column,tabcount;
- register int spacecount;
-
- if(!destination||!source||(!tabs&&!def)||opt<0||opt>1)
- return((char *)0);
- orgdest=destination;
- for(spacecount=column=0;*source&&maxlength;--maxlength,spacecount=0) {
- if(*source&&*source==' ')
- for(s=source;*s&&*s==' ';++s,++spacecount)
- ;
- if(spacecount>1||(spacecount==1&&opt!=YES)) {
- if(tabs) {
- for(t=tabs,tabcount=1;*t&&(*t!='t'&&*t!='T'&&
- *t!='x'&&*t!='X');++t,++tabcount)
- ;
- if(tabcount>1&&*t&&spacecount>=tabcount) {
- tabs+=tabcount;
- source+=tabcount;
- *destination++='\t';
- } else
- for(;maxlength&&spacecount;
- --maxlength,--spacecount,++tabs)
- *destination++=*source++;
- } else {
- tabcount=column;
- while(++tabcount%def)
- ;
- tabcount-=column;
- if(tabcount&&spacecount>=tabcount) {
- source+=tabcount;
- column+=tabcount;
- *destination++='\t';
- } else
- for(;maxlength&&spacecount;
- --maxlength,--spacecount,++column)
- *destination++=*source++;
- }
- } else {
- *destination++=*source++;
- tabs+=(tabs)?1:0;
- ++column;
- }
- }
- *destination='\0';
- return(orgdest);
- }
-