home *** CD-ROM | disk | FTP | other *** search
- /*
- BreakLines.c
-
- char *BreakLines(char *string,long lineLength);
-
- Takes a long C string and judiciously changes spaces to '\n' to yield lines
- shorter than lineLength, but words are never broken, even if they are longer
- than lineLength. All characters other than space and '\n' are treated as letters.
-
- The default THINK C console width is 80, so use printf(BreakLines(string,80));
- */
- #include "VideoToolbox.h"
- char *BreakLines(char *string,long lineLength);
-
- char *BreakLines(char *string,long lineLength)
- {
- long i,leftMargin,rightMargin,length;
- Boolean here;
-
- leftMargin=0;
- length=strlen(string);
- while(1){
- rightMargin=leftMargin+lineLength;
- if(rightMargin>=length)return string; // successful completion
- here=0;
- if(!here)for(i=leftMargin;i<rightMargin;i++)if(string[i]=='\n'){
- here=1;
- break;
- }
- if(!here)for(;i>=leftMargin;i--)if(string[i]==' ' || string[i]=='\n'){
- here=1;
- break;
- }
- if(!here)for(i=leftMargin;i<length;i++)if(string[i]==' ' || string[i]=='\n'){
- here=1;
- break;
- }
- if(!here)return string;
- string[i]='\n';
- leftMargin=i+1;
- }
- }