Changes in text.c [3bcf125:f34dd65]
Legend:
- Unmodified
- Added
- Removed
-
text.c
r3bcf125 rf34dd65 6 6 7 7 static const char fileIdent[] = "$Id$"; 8 9 /* start with line aline (where the first line is 1) and print 'lines'10 * lines11 */12 int owl_text_truncate_lines(char *out, char *in, int aline, int lines)13 {14 char *ptr1, *ptr2;15 int i;16 17 strcpy(out, "");18 19 if (aline==0) aline=1; /* really illegal use */20 21 /* find the starting line */22 ptr1=in;23 if (aline!=1) {24 for (i=0; i<aline-1; i++) {25 ptr1=strchr(ptr1, '\n');26 if (!ptr1) return(-1);27 ptr1++;28 }29 }30 /* ptr1 now holds the starting point */31 32 /* copy in the next 'lines' lines */33 if (lines<1) return(-1);34 35 for (i=0; i<lines; i++) {36 ptr2=strchr(ptr1, '\n');37 if (!ptr2) {38 strcat(out, ptr1);39 return(-1);40 }41 strncat(out, ptr1, ptr2-ptr1+1);42 ptr1=ptr2+1;43 }44 return(0);45 }46 47 48 /* the first column is column 0. The message is expected to end in a49 * new line for now */50 void owl_text_truncate_cols(char *out, char *in, int acol, int bcol)51 {52 char *ptr1, *ptr2, *tmpbuff, *last;53 int len;54 55 tmpbuff=owl_malloc(strlen(in)+20);56 57 strcpy(tmpbuff, "");58 last=in+strlen(in)-1;59 ptr1=in;60 while (ptr1<last) {61 ptr2=strchr(ptr1, '\n');62 if (!ptr2) {63 /* but this shouldn't happen if we end in a \n */64 break;65 }66 67 if (ptr2==ptr1) {68 strcat(tmpbuff, "\n");69 ptr1++;70 continue;71 }72 73 /* we need to check that we won't run over here */74 if ( (ptr2-ptr1) < (bcol-acol) ) {75 len=ptr2-(ptr1+acol);76 } else {77 len=bcol-acol;78 }79 if ((ptr1+len)>=last) {80 len-=last-(ptr1+len);81 }82 83 strncat(tmpbuff, ptr1+acol, len);84 strcat(tmpbuff, "\n");85 86 ptr1=ptr2+1;87 }88 strcpy(out, tmpbuff);89 owl_free(tmpbuff);90 }91 92 8 93 9 void owl_text_indent(char *out, char *in, int n) … … 275 191 char *stristr(char *a, char *b) 276 192 { 277 char *x, *y, *ret; 278 279 if ((x=owl_strdup(a))==NULL) return(NULL); 280 if ((y=owl_strdup(b))==NULL) return(NULL); 281 downstr(x); 282 downstr(y); 283 ret=strstr(x, y); 284 if (ret==NULL) { 285 owl_free(x); 286 owl_free(y); 287 return(NULL); 288 } 289 ret=ret-x+a; 290 owl_free(x); 291 owl_free(y); 193 char *x, *y; 194 char *ret = NULL; 195 if ((x = g_utf8_casefold(a, -1)) != NULL) { 196 if ((y = g_utf8_casefold(b, -1)) != NULL) { 197 ret = strstr(x, y); 198 if (ret != NULL) { 199 ret = ret - x + a; 200 } 201 g_free(y); 202 } 203 g_free(x); 204 } 292 205 return(ret); 293 206 } … … 296 209 int only_whitespace(char *s) 297 210 { 298 int i; 299 for (i=0; s[i]; i++) { 300 if (!isspace((int) s[i])) return(0); 211 if (g_utf8_validate(s,-1,NULL)) { 212 char *p; 213 for(p = s; p[0]; p=g_utf8_next_char(p)) { 214 if (!g_unichar_isspace(g_utf8_get_char(p))) return 0; 215 } 216 } 217 else { 218 int i; 219 for (i=0; s[i]; i++) { 220 if (!isspace((int) s[i])) return(0); 221 } 301 222 } 302 223 return(1); … … 327 248 tolen = strlen(to); 328 249 fromlen = strlen(from); 329 out = malloc(outlen);250 out = owl_malloc(outlen); 330 251 331 252 while (in[inpos]) {
Note: See TracChangeset
for help on using the changeset viewer.