Changeset e3d9c77
- Timestamp:
- Oct 26, 2003, 3:23:38 PM (19 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- bc08664
- Parents:
- 70b53ec
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
filter.c
r37eab7f re3d9c77 70 70 !strcasecmp(argv[i], "hostname") || 71 71 !strcasecmp(argv[i], "login")) { 72 regexstr=owl_ util_substitute(argv[i+1], "%me%", owl_zephyr_get_sender());72 regexstr=owl_text_substitute(argv[i+1], "%me%", owl_zephyr_get_sender()); 73 73 owl_filterelement_create_re(fe, argv[i], regexstr); 74 74 owl_free(regexstr); -
functions.c
reec69e1 re3d9c77 1955 1955 if (owl_global_is_smartstrip(&g)) { 1956 1956 tmp2=tmp; 1957 tmp=owl_ util_smartstripped_user(tmp2);1957 tmp=owl_zephyr_smartstripped_user(tmp2); 1958 1958 owl_free(tmp2); 1959 1959 } … … 2395 2395 downstr(filtname); 2396 2396 /* turn spaces into hyphens */ 2397 owl_ util_tr(filtname, ' ', '.');2397 owl_text_tr(filtname, ' ', '.'); 2398 2398 2399 2399 /* if it already exists then go with it. This lets users override */ … … 2405 2405 argbuff=owl_malloc(len+20); 2406 2406 tmpclass=owl_strdup(class); 2407 owl_ util_tr(tmpclass, ' ', '.');2407 owl_text_tr(tmpclass, ' ', '.'); 2408 2408 if (instance) { 2409 2409 tmpinstance=owl_strdup(instance); 2410 owl_ util_tr(tmpinstance, ' ', '.');2410 owl_text_tr(tmpinstance, ' ', '.'); 2411 2411 } 2412 2412 sprintf(argbuff, "( class ^%s$ )", tmpclass); -
logging.c
reec69e1 re3d9c77 23 23 24 24 /* expand ~ in path names */ 25 logpath = owl_ util_substitute(owl_global_get_logpath(&g), "~",25 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 26 26 owl_global_get_homedir(&g)); 27 27 … … 64 64 65 65 /* expand ~ in path names */ 66 logpath = owl_ util_substitute(owl_global_get_logpath(&g), "~",66 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 67 67 owl_global_get_homedir(&g)); 68 68 … … 105 105 106 106 /* expand ~ in path names */ 107 logpath = owl_ util_substitute(owl_global_get_logpath(&g), "~",107 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 108 108 owl_global_get_homedir(&g)); 109 109 … … 210 210 /* create the filename (expanding ~ in path names) */ 211 211 if (personal) { 212 logpath = owl_ util_substitute(owl_global_get_logpath(&g), "~",212 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 213 213 owl_global_get_homedir(&g)); 214 214 snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from); … … 216 216 217 217 } else { 218 logpath = owl_ util_substitute(owl_global_get_classlogpath(&g), "~",218 logpath = owl_text_substitute(owl_global_get_classlogpath(&g), "~", 219 219 owl_global_get_homedir(&g)); 220 220 -
stylefunc.c
r25dd31a re3d9c77 528 528 529 529 tmp=owl_strdup(owl_message_get_body(m)); 530 owl_ util_tr(tmp, '\n', ' ');530 owl_text_tr(tmp, '\n', ' '); 531 531 owl_fmtext_append_ztext(fm, tmp); 532 532 owl_fmtext_append_normal(fm, "\n"); … … 568 568 569 569 tmp=owl_strdup(owl_message_get_body(m)); 570 owl_ util_tr(tmp, '\n', ' ');570 owl_text_tr(tmp, '\n', ' '); 571 571 owl_fmtext_append_normal(fm, tmp); 572 572 owl_fmtext_append_normal(fm, "\n"); … … 583 583 584 584 tmp=owl_strdup(owl_message_get_body(m)); 585 owl_ util_tr(tmp, '\n', ' ');585 owl_text_tr(tmp, '\n', ' '); 586 586 owl_fmtext_append_normal(fm, tmp); 587 587 owl_fmtext_append_normal(fm, "\n"); … … 592 592 593 593 tmp=owl_strdup(owl_message_get_body(m)); 594 owl_ util_tr(tmp, '\n', ' ');594 owl_text_tr(tmp, '\n', ' '); 595 595 owl_fmtext_append_normal(fm, tmp); 596 596 owl_fmtext_append_normal(fm, "\n"); -
text.c
r8d24696 re3d9c77 115 115 } 116 116 117 118 117 int owl_text_num_lines(char *in) 119 118 { … … 190 189 } 191 190 192 out2=owl_ util_substitute(out, "<", "<");193 owl_free(out); 194 out=owl_ util_substitute(out2, ">", ">");191 out2=owl_text_substitute(out, "<", "<"); 192 owl_free(out); 193 out=owl_text_substitute(out2, ">", ">"); 195 194 owl_free(out2); 196 out2=owl_ util_substitute(out, "&", "&");197 owl_free(out); 198 out=owl_ util_substitute(out2, """, "\"");195 out2=owl_text_substitute(out, "&", "&"); 196 owl_free(out); 197 out=owl_text_substitute(out2, """, "\""); 199 198 owl_free(out2); 200 out2=owl_ util_substitute(out, " ", " ");201 owl_free(out); 202 out=owl_ util_substitute(out2, " ", " ");199 out2=owl_text_substitute(out, " ", " "); 200 owl_free(out); 201 out=owl_text_substitute(out2, " ", " "); 203 202 owl_free(out2); 204 out2=owl_ util_substitute(out, " ", " ");205 owl_free(out); 206 out=owl_ util_substitute(out2, "&endash;", "--");203 out2=owl_text_substitute(out, " ", " "); 204 owl_free(out); 205 out=owl_text_substitute(out2, "&endash;", "--"); 207 206 owl_free(out2); 208 out2=owl_ util_substitute(out, "&emdash;", "---");207 out2=owl_text_substitute(out, "&emdash;", "---"); 209 208 owl_free(out); 210 209 … … 257 256 return(out); 258 257 } 258 259 /* exactly like strstr but case insensitive */ 260 char *stristr(char *a, char *b) 261 { 262 char *x, *y, *ret; 263 264 if ((x=owl_strdup(a))==NULL) return(NULL); 265 if ((y=owl_strdup(b))==NULL) return(NULL); 266 downstr(x); 267 downstr(y); 268 ret=strstr(x, y); 269 if (ret==NULL) { 270 owl_free(x); 271 owl_free(y); 272 return(NULL); 273 } 274 ret=ret-x+a; 275 owl_free(x); 276 owl_free(y); 277 return(ret); 278 } 279 280 /* return 1 if a string is only whitespace, otherwise 0 */ 281 int only_whitespace(char *s) 282 { 283 int i; 284 for (i=0; s[i]; i++) { 285 if (!isspace((int) s[i])) return(0); 286 } 287 return(1); 288 } 289 290 char *owl_getquoting(char *line) 291 { 292 if (line[0]=='\0') return("'"); 293 if (strchr(line, '\'')) return("\""); 294 if (strchr(line, '"')) return("'"); 295 if (strchr(line, ' ')) return("'"); 296 return(""); 297 } 298 299 /* Return a string with any occurances of 'from' replaced with 'to'. 300 * Does not currently handle backslash quoting, but may in the future. 301 * Caller must free returned string. 302 */ 303 char *owl_text_substitute(char *in, char *from, char *to) 304 { 305 306 char *out; 307 int outlen, tolen, fromlen, inpos=0, outpos=0; 308 309 if (!*from) return owl_strdup(in); 310 311 outlen = strlen(in)+1; 312 tolen = strlen(to); 313 fromlen = strlen(from); 314 out = malloc(outlen); 315 316 while (in[inpos]) { 317 if (!strncmp(in+inpos, from, fromlen)) { 318 outlen += tolen; 319 out = owl_realloc(out, outlen); 320 strcpy(out+outpos, to); 321 inpos += fromlen; 322 outpos += tolen; 323 } else { 324 out[outpos] = in[inpos]; 325 inpos++; outpos++; 326 } 327 } 328 out[outpos] = '\0'; 329 return(out); 330 } 331 332 /* replace all instances of character a in buff with the character 333 * b. buff must be null terminated. 334 */ 335 void owl_text_tr(char *buff, char a, char b) 336 { 337 int i; 338 339 owl_function_debugmsg("In: %s", buff); 340 for (i=0; buff[i]!='\0'; i++) { 341 if (buff[i]==a) buff[i]=b; 342 } 343 owl_function_debugmsg("Out: %s", buff); 344 } 345 346 /* Return a string which is like 'in' except that every instance of 347 * any character in 'toquote' found in 'in' is preceeded by the string 348 * 'quotestr'. For example, owl_text_quote(in, "+*.", "\") would 349 * place a backslash before every '+', '*' or '.' in 'in'. It is 350 * permissable for a character in 'quotestr' to be in 'toquote'. 351 * On success returns the string, on error returns NULL. 352 */ 353 char *owl_text_quote(char *in, char *toquote, char *quotestr) 354 { 355 int i, x, r, place; 356 int in_len, toquote_len, quotestr_len; 357 char *out; 358 359 in_len=strlen(in); 360 toquote_len=strlen(toquote); 361 quotestr_len=strlen(quotestr); 362 out=owl_malloc((in_len*quotestr_len)+30); 363 place=0; 364 for (i=0; i<in_len; i++) { 365 366 /* check if it's a character that needs quoting */ 367 for (x=0; x<toquote_len; x++) { 368 if (in[i]==toquote[x]) { 369 /* quote it */ 370 for (r=0; r<quotestr_len; r++) { 371 out[place+r]=quotestr[r]; 372 } 373 place+=quotestr_len; 374 break; 375 } 376 } 377 378 /* either way, we now copy over the character */ 379 out[place]=in[i]; 380 place++; 381 } 382 out[place]='\0'; 383 return(out); 384 } -
util.c
rc15bbfb re3d9c77 2 2 #include <stdlib.h> 3 3 #include <string.h> 4 #include <unistd.h>5 4 #include <unistd.h> 6 5 #include <ctype.h> … … 306 305 } 307 306 308 309 307 /* return the index of the last char before a change from the first one */ 310 308 int owl_util_find_trans(char *in, int len) … … 317 315 } 318 316 319 320 317 /* downcase the string 'foo' */ 321 318 void downstr(char *foo) … … 325 322 foo[i]=tolower(foo[i]); 326 323 } 327 }328 329 /* exactly like strstr but case insensitive */330 char *stristr(char *a, char *b)331 {332 char *x, *y, *ret;333 334 if ((x=owl_strdup(a))==NULL) return(NULL);335 if ((y=owl_strdup(b))==NULL) return(NULL);336 downstr(x);337 downstr(y);338 ret=strstr(x, y);339 if (ret==NULL) {340 owl_free(x);341 owl_free(y);342 return(NULL);343 }344 ret=ret-x+a;345 owl_free(x);346 owl_free(y);347 return(ret);348 324 } 349 325 … … 382 358 } 383 359 384 /* return 1 if a string is only whitespace, otherwise 0 */385 int only_whitespace(char *s)386 {387 int i;388 for (i=0; s[i]; i++) {389 if (!isspace((int) s[i])) return(0);390 }391 return(1);392 }393 394 360 /* hooks for doing memory allocation et. al. in owl */ 395 361 … … 413 379 return(realloc(ptr, size)); 414 380 } 415 416 381 417 382 /* allocates memory and returns the string or null. … … 443 408 } 444 409 445 /* Strip a local realm fron the zephyr user name.446 * The caller must free the return447 */448 char *short_zuser(char *in)449 {450 char *out, *ptr;451 452 out=owl_strdup(in);453 ptr=strchr(out, '@');454 if (ptr) {455 if (!strcasecmp(ptr+1, owl_zephyr_get_realm())) {456 *ptr='\0';457 }458 }459 return(out);460 }461 462 /* Append a local realm to the zephyr user name if necessary.463 * The caller must free the return.464 */465 char *long_zuser(char *in)466 {467 char *ptr;468 469 if (NULL != (ptr=strchr(in, '@'))) {470 return owl_strdup(in);471 } else {472 return owl_sprintf("%s@%s", in, owl_zephyr_get_realm());473 }474 }475 476 477 /* strip out the instance from a zsender's principal. Preserves the478 * realm if present. daemon.webzephyr is a special case. The479 * caller must free the return480 */481 char *owl_util_smartstripped_user(char *in)482 {483 char *ptr, *realm, *out;484 485 out=owl_strdup(in);486 487 /* bail immeaditly if we don't have to do any work */488 ptr=strchr(in, '.');489 if (!strchr(in, '/') && !ptr) {490 /* no '/' and no '.' */491 return(out);492 }493 if (ptr && strchr(in, '@') && (ptr > strchr(in, '@'))) {494 /* There's a '.' but it's in the realm */495 return(out);496 }497 if (!strncasecmp(in, OWL_WEBZEPHYR_PRINCIPAL, strlen(OWL_WEBZEPHYR_PRINCIPAL))) {498 return(out);499 }500 501 /* remove the realm from ptr, but hold on to it */502 realm=strchr(out, '@');503 if (realm) realm[0]='\0';504 505 /* strip */506 ptr=strchr(out, '.');507 if (!ptr) ptr=strchr(out, '/');508 ptr[0]='\0';509 510 /* reattach the realm if we had one */511 if (realm) {512 strcat(out, "@");513 strcat(out, realm+1);514 }515 516 return(out);517 }518 519 char *owl_getquoting(char *line)520 {521 if (line[0]=='\0') return("'");522 if (strchr(line, '\'')) return("\"");523 if (strchr(line, '"')) return("'");524 if (strchr(line, ' ')) return("'");525 return("");526 }527 528 529 530 /* Return a string with any occurances of 'from' replaced with 'to'.531 * Does not currently handle backslash quoting, but may in the future.532 * Caller must free returned string.533 */534 char *owl_util_substitute(char *in, char *from, char *to)535 {536 537 char *out;538 int outlen, tolen, fromlen, inpos=0, outpos=0;539 540 if (!*from) return owl_strdup(in);541 542 outlen = strlen(in)+1;543 tolen = strlen(to);544 fromlen = strlen(from);545 out = malloc(outlen);546 547 while (in[inpos]) {548 if (!strncmp(in+inpos, from, fromlen)) {549 outlen += tolen;550 out = owl_realloc(out, outlen);551 strcpy(out+outpos, to);552 inpos += fromlen;553 outpos += tolen;554 } else {555 out[outpos] = in[inpos];556 inpos++; outpos++;557 }558 }559 out[outpos] = '\0';560 return(out);561 }562 563 /* replace all instances of character a in buff with the character564 * b. buff must be null terminated.565 */566 void owl_util_tr(char *buff, char a, char b)567 {568 int i;569 570 owl_function_debugmsg("In: %s", buff);571 for (i=0; buff[i]!='\0'; i++) {572 if (buff[i]==a) buff[i]=b;573 }574 owl_function_debugmsg("Out: %s", buff);575 }576 577 578 410 /* Return the owl color associated with the named color */ 579 411 int owl_util_string_to_color(char *color) … … 805 637 806 638 FAIL_UNLESS("owl_util_substitute 1", 807 !strcmp("foo", owl_ util_substitute("foo", "", "Y")));808 FAIL_UNLESS("owl_ util_substitute 2",809 !strcmp("fYZYZ", owl_ util_substitute("foo", "o", "YZ")));810 FAIL_UNLESS("owl_ util_substitute 3",811 !strcmp("foo", owl_ util_substitute("fYZYZ", "YZ", "o")));812 FAIL_UNLESS("owl_ util_substitute 4",813 !strcmp("/u/foo/meep", owl_ util_substitute("~/meep", "~", "/u/foo")));639 !strcmp("foo", owl_text_substitute("foo", "", "Y"))); 640 FAIL_UNLESS("owl_text_substitute 2", 641 !strcmp("fYZYZ", owl_text_substitute("foo", "o", "YZ"))); 642 FAIL_UNLESS("owl_text_substitute 3", 643 !strcmp("foo", owl_text_substitute("fYZYZ", "YZ", "o"))); 644 FAIL_UNLESS("owl_text_substitute 4", 645 !strcmp("/u/foo/meep", owl_text_substitute("~/meep", "~", "/u/foo"))); 814 646 815 647 FAIL_UNLESS("skiptokens 1", -
zephyr.c
r269ed34 re3d9c77 485 485 486 486 if (owl_global_is_smartstrip(&g)) { 487 to=owl_ util_smartstripped_user(owl_message_get_sender(m));487 to=owl_zephyr_smartstripped_user(owl_message_get_sender(m)); 488 488 } else { 489 489 to=owl_strdup(owl_message_get_sender(m)); … … 794 794 } 795 795 796 797 798 /* Strip a local realm fron the zephyr user name. 799 * The caller must free the return 800 */ 801 char *short_zuser(char *in) 802 { 803 char *out, *ptr; 804 805 out=owl_strdup(in); 806 ptr=strchr(out, '@'); 807 if (ptr) { 808 if (!strcasecmp(ptr+1, owl_zephyr_get_realm())) { 809 *ptr='\0'; 810 } 811 } 812 return(out); 813 } 814 815 /* Append a local realm to the zephyr user name if necessary. 816 * The caller must free the return. 817 */ 818 char *long_zuser(char *in) 819 { 820 char *ptr; 821 822 if (NULL != (ptr=strchr(in, '@'))) { 823 return owl_strdup(in); 824 } else { 825 return owl_sprintf("%s@%s", in, owl_zephyr_get_realm()); 826 } 827 } 828 829 830 /* strip out the instance from a zsender's principal. Preserves the 831 * realm if present. daemon.webzephyr is a special case. The 832 * caller must free the return 833 */ 834 char *owl_zephyr_smartstripped_user(char *in) 835 { 836 char *ptr, *realm, *out; 837 838 out=owl_strdup(in); 839 840 /* bail immeaditly if we don't have to do any work */ 841 ptr=strchr(in, '.'); 842 if (!strchr(in, '/') && !ptr) { 843 /* no '/' and no '.' */ 844 return(out); 845 } 846 if (ptr && strchr(in, '@') && (ptr > strchr(in, '@'))) { 847 /* There's a '.' but it's in the realm */ 848 return(out); 849 } 850 if (!strncasecmp(in, OWL_WEBZEPHYR_PRINCIPAL, strlen(OWL_WEBZEPHYR_PRINCIPAL))) { 851 return(out); 852 } 853 854 /* remove the realm from ptr, but hold on to it */ 855 realm=strchr(out, '@'); 856 if (realm) realm[0]='\0'; 857 858 /* strip */ 859 ptr=strchr(out, '.'); 860 if (!ptr) ptr=strchr(out, '/'); 861 ptr[0]='\0'; 862 863 /* reattach the realm if we had one */ 864 if (realm) { 865 strcat(out, "@"); 866 strcat(out, realm+1); 867 } 868 869 return(out); 870 }
Note: See TracChangeset
for help on using the changeset viewer.