Changeset 28ee32b
- Timestamp:
- Dec 24, 2007, 2:53:11 AM (17 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 762512d
- Parents:
- 5bc0f68
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
fmtext.c
rfa3290d r28ee32b 315 315 void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out) 316 316 { 317 char *ptr 1, *ptr2, *last;318 int len, offset;317 char *ptr_s, *ptr_e, *ptr_c, *last; 318 int col, cnt; 319 319 320 320 last=in->textbuff+in->textlen-1; 321 ptr 1=in->textbuff;322 while (ptr 1<=last) {323 ptr 2=strchr(ptr1, '\n');324 if (!ptr 2) {321 ptr_s=in->textbuff; 322 while (ptr_s<=last) { 323 ptr_e=strchr(ptr_s, '\n'); 324 if (!ptr_e) { 325 325 /* but this shouldn't happen if we end in a \n */ 326 326 break; 327 327 } 328 328 329 if (ptr 2==ptr1) {329 if (ptr_e==ptr_s) { 330 330 owl_fmtext_append_normal(out, "\n"); 331 ptr 1++;331 ptr_s++; 332 332 continue; 333 333 } 334 334 335 col = 0; 336 cnt = 0; 337 ptr_c = ptr_s; 338 while(col < bcol && ptr_c < ptr_e) { 339 gunichar c = g_utf8_get_char(ptr_c); 340 if (g_unichar_iswide(c)) { 341 if (col + 2 > bcol) break; 342 else col += 2; 343 } 344 else if (g_unichar_type(c) == G_UNICODE_NON_SPACING_MARK) ; /*do nothing*/ 345 /* We may need more special cases here... unicode spacing is hard. */ 346 else { 347 if (col + 1 > bcol) break; 348 else ++col; 349 } 350 ptr_c = g_utf8_next_char(ptr_c); 351 if (col >= acol) ++cnt; 352 if (col <= acol) ptr_s = ptr_c; 353 } 354 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff); 355 ptr_s=ptr_e+1; 356 357 #if 0 335 358 /* we need to check that we won't run over here */ 336 359 len=bcol-acol; 337 if (len > (ptr 2-(ptr1+acol))) {360 if (len > (ptr_e-(ptr_s+acol))) { 338 361 /* the whole line fits with room to spare, don't take a full 'len' */ 339 len=ptr 2-(ptr1+acol);340 } 341 if (len>last-ptr 1) {362 len=ptr_e-(ptr_s+acol); 363 } 364 if (len>last-ptr_s) { 342 365 /* the whole rest of the text fits with room to spare, adjust for it */ 343 len-=(last-ptr 1);366 len-=(last-ptr_s); 344 367 } 345 368 if (len<=0) { 346 369 /* saftey check */ 347 370 owl_fmtext_append_normal(out, "\n"); 348 ptr 1=ptr2+1;371 ptr_s=ptr_e+1; 349 372 continue; 350 373 } 351 374 352 offset =ptr1-in->textbuff;375 offset = ptr_s - in->textbuff; 353 376 _owl_fmtext_append_fmtext(out, in, offset+acol, offset+acol+len); 354 377 355 ptr1=ptr2+1; 378 ptr_s=ptr_e+1; 379 #endif 356 380 } 357 381 } -
functions.c
r93ee554 r28ee32b 2598 2598 } 2599 2599 /* downcase it */ 2600 downstr(filtname); 2600 { 2601 char *temp = g_utf8_strdown(filtname, -1); 2602 if (temp) { 2603 owl_free(filtname); 2604 filtname = temp; 2605 } 2606 } 2601 2607 /* turn spaces, single quotes, and double quotes into dots */ 2602 2608 owl_text_tr(filtname, ' ', '.'); -
logging.c
rd0961fe r28ee32b 155 155 to = owl_sprintf("jabber:%s", owl_message_get_recipient(m)); 156 156 } else if (owl_message_is_type_aim(m)) { 157 char *temp2; 157 158 temp = owl_aim_normalize_screenname(owl_message_get_recipient(m)); 158 downstr(temp); 159 to = owl_sprintf("aim:%s", temp); 159 temp2 = g_utf8_strdown(temp,-1); 160 to = owl_sprintf("aim:%s", temp2); 161 owl_free(temp2); 160 162 owl_free(temp); 161 163 } else { … … 267 269 } else if (owl_message_is_type_aim(m)) { 268 270 /* we do not yet handle chat rooms */ 269 char *normalto ;270 normalto=owl_aim_normalize_screenname(owl_message_get_sender(m));271 downstr(normalto);271 char *normalto, *temp; 272 temp = owl_aim_normalize_screenname(owl_message_get_sender(m)); 273 normalto = g_utf8_strdown(temp, -1); 272 274 from=frombuff=owl_sprintf("aim:%s", normalto); 273 275 owl_free(normalto); 276 owl_free(temp); 274 277 } else if (owl_message_is_type_loopback(m)) { 275 278 from=frombuff=owl_strdup("loopback"); … … 290 293 291 294 ch=frombuff[0]; 292 if (! isalnum(ch)) from="weird";295 if (!g_ascii_isalnum(ch)) from="weird"; 293 296 294 297 for (i=0; i<len; i++) { … … 299 302 300 303 if (!personal) { 301 if (strcmp(from, "weird")) downstr(from); 304 if (strcmp(from, "weird")) { 305 char* temp = g_utf8_strdown(frombuff, -1); 306 if (temp) { 307 owl_free(frombuff); 308 from = frombuff = temp; 309 } 310 } 302 311 } 303 312 -
text.c
r34509d5 r28ee32b 50 50 void owl_text_truncate_cols(char *out, char *in, int acol, int bcol) 51 51 { 52 char *ptr 1, *ptr2, *tmpbuff, *last;53 int len;54 52 char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last; 53 int col, cnt; 54 55 55 tmpbuff=owl_malloc(strlen(in)+20); 56 56 57 57 strcpy(tmpbuff, ""); 58 58 last=in+strlen(in)-1; 59 ptr 1=in;60 while (ptr 1<last) {61 ptr 2=strchr(ptr1, '\n');62 if (!ptr 2) {59 ptr_s=in; 60 while (ptr_s<last) { 61 ptr_e=strchr(ptr_s, '\n'); 62 if (!ptr_e) { 63 63 /* but this shouldn't happen if we end in a \n */ 64 64 break; 65 65 } 66 66 67 if (ptr 2==ptr1) {67 if (ptr_e==ptr_s) { 68 68 strcat(tmpbuff, "\n"); 69 ptr1++; 70 continue; 71 } 72 69 ptr_s++; 70 continue; 71 } 72 73 col = 0; 74 cnt = 0; 75 ptr_c = ptr_s; 76 while(col < bcol && ptr_c < ptr_e) { 77 gunichar c = g_utf8_get_char(ptr_c); 78 if (g_unichar_iswide(c)) { 79 if (col + 2 > bcol) break; 80 else col += 2; 81 } 82 else if (g_unichar_type(c) == G_UNICODE_NON_SPACING_MARK) ; /*do nothing*/ 83 /* We may need more special cases here... unicode spacing is hard. */ 84 else { 85 if (col + 1 > bcol) break; 86 else ++col; 87 } 88 ptr_c = g_utf8_next_char(ptr_c); 89 if (col >= acol) ++cnt; 90 if (col <= acol) ptr_s = ptr_c; 91 } 92 strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1); 93 strcat(tmpbuff, "\n"); 94 ptr_s = ptr_e + 1; 95 #if 0 73 96 /* we need to check that we won't run over here */ 74 if ( (ptr 2-ptr1) < (bcol-acol) ) {75 len=ptr 2-(ptr1+acol);97 if ( (ptr_e-ptr_s) < (bcol-acol) ) { 98 len=ptr_e-(ptr_s+acol); 76 99 } else { 77 100 len=bcol-acol; 78 101 } 79 if ((ptr 1+len)>=last) {80 len-=last-(ptr 1+len);81 } 82 83 strncat(tmpbuff, ptr 1+acol, len);102 if ((ptr_s+len)>=last) { 103 len-=last-(ptr_s+len); 104 } 105 106 strncat(tmpbuff, ptr_s+acol, len); 84 107 strcat(tmpbuff, "\n"); 85 108 86 ptr1=ptr2+1; 109 ptr_s=ptr_e+1; 110 #endif 87 111 } 88 112 strcpy(out, tmpbuff); … … 275 299 char *stristr(char *a, char *b) 276 300 { 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); 301 char *x, *y; 302 char *ret = NULL; 303 if ((x = g_utf8_casefold(a, -1)) != NULL) { 304 if ((y = g_utf8_casefold(b, -1)) != NULL) { 305 ret = strstr(x, y); 306 if (ret != NULL) { 307 ret = ret - x + a; 308 } 309 g_free(y); 310 } 311 g_free(x); 312 } 292 313 return(ret); 293 314 } … … 296 317 int only_whitespace(char *s) 297 318 { 298 int i; 299 for (i=0; s[i]; i++) { 300 if (!isspace((int) s[i])) return(0); 319 if (g_utf8_validate(s,-1,NULL)) { 320 char *p; 321 for(p = s; p[0]; p=g_utf8_next_char(p)) { 322 if (!g_unichar_isspace(g_utf8_get_char(p))) return 0; 323 } 324 } 325 else { 326 int i; 327 for (i=0; s[i]; i++) { 328 if (!isspace((int) s[i])) return(0); 329 } 301 330 } 302 331 return(1); -
util.c
r5bc0f68 r28ee32b 399 399 } 400 400 401 /* downcase the string 'foo' */402 void downstr(char *foo)403 {404 int i;405 for (i=0; foo[i]!='\0'; i++) {406 foo[i]=tolower(foo[i]);407 }408 }409 410 401 /* Caller must free response. 411 402 * Takes in strings which are space-separated lists of tokens … … 466 457 /* allocates memory and returns the string or null. 467 458 * caller must free the string. 468 * from Linux sprintf man page.469 459 */ 470 460 char *owl_sprintf(const char *fmt, ...) 471 461 { 472 int n, size = 100;473 char *p;474 462 va_list ap; 475 if ((p = owl_malloc (size)) == NULL) return (NULL); 476 while (1) { 477 /* Try to print in the allocated space. */ 478 va_start(ap, fmt); 479 n = vsnprintf (p, size, fmt, ap); 480 va_end(ap); 481 /* If that worked, return the string. */ 482 if (n > -1 && n < size) 483 return p; 484 /* Else try again with more space. */ 485 if (n > -1) /* glibc 2.1 */ 486 size = n+1; /* precisely what is needed */ 487 else /* glibc 2.0 */ 488 size *= 2; /* twice the old size */ 489 if ((p = owl_realloc (p, size)) == NULL) 490 return NULL; 491 } 492 } 463 char *ret = NULL; 464 va_start(ap, fmt); 465 ret = g_strdup_vprintf(fmt, ap); 466 va_end(ap); 467 return ret; 468 } 469 493 470 494 471 /* Return the owl color associated with the named color. Return -1
Note: See TracChangeset
for help on using the changeset viewer.