Changeset e4eebe8
- Timestamp:
- Jun 22, 2003, 1:58:18 PM (21 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 9c4ec91
- Parents:
- 53f421b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
util.c
r73624b4 re4eebe8 8 8 static const char fileIdent[] = "$Id$"; 9 9 10 void sepbar(char *in) { 10 void sepbar(char *in) 11 { 11 12 char buff[1024]; 12 13 WINDOW *sepwin; … … 117 118 118 119 119 void pophandler_quit(int ch) { 120 void pophandler_quit(int ch) 121 { 120 122 if (ch=='q') { 121 123 owl_popwin_close(owl_global_get_popwin(&g)); … … 123 125 } 124 126 125 char **atokenize(char *buffer, char *sep, int *i) { 127 char **atokenize(char *buffer, char *sep, int *i) 128 { 126 129 /* each element of return must be freed by user */ 127 130 char **args; … … 171 174 } 172 175 173 void atokenize_free(char **tok, int nels) { 176 void atokenize_free(char **tok, int nels) 177 { 174 178 int i; 175 179 for (i=0; i<nels; i++) { … … 180 184 181 185 182 void owl_parsefree(char **argv, int argc) { 186 void owl_parsefree(char **argv, int argc) 187 { 183 188 int i; 184 189 … … 191 196 } 192 197 193 char **owl_parseline(char *line, int *argc) { 198 char **owl_parseline(char *line, int *argc) 199 { 194 200 /* break a command line up into argv, argc. The caller must free 195 201 the returned values. If there is an error argc will be set to … … 275 281 276 282 277 278 int owl_util_find_trans(char *in, int len) { 279 /* return the index of the last char before a change from the first 280 one */ 283 /* return the index of the last char before a change from the first one */ 284 int owl_util_find_trans(char *in, int len) 285 { 281 286 int i; 282 287 for (i=1; i<len; i++) { … … 287 292 288 293 289 void downstr(char *foo) { 294 /* downcase the string 'foo' */ 295 void downstr(char *foo) 296 { 290 297 int i; 291 298 for (i=0; foo[i]!='\0'; i++) { … … 294 301 } 295 302 296 char *stristr(char *a, char *b) { 297 /* exactly like strstr but it's case insensitive */ 303 /* exactly like strstr but case insensitive */ 304 char *stristr(char *a, char *b) 305 { 298 306 char *x, *y, *ret; 299 307 … … 314 322 } 315 323 316 char *owl_util_uniq(char *A, char *B, char *prohibit) { 317 /* Caller must free response. 318 Takes in strings which are space-separated lists of tokens 319 and returns a single string containing no token more than once. 320 If prohibit is non-null, no token may start with a character 321 in prohibit. 322 */ 324 /* Caller must free response. 325 * Takes in strings which are space-separated lists of tokens 326 * and returns a single string containing no token more than once. 327 * If prohibit is non-null, no token may start with a character 328 * in prohibit. 329 */ 330 char *owl_util_uniq(char *A, char *B, char *prohibit) 331 { 323 332 324 333 char *cat, **tok; … … 347 356 } 348 357 349 int only_whitespace(char *s) { 350 /* returns if a string is only whitespace */ 351 358 /* return 1 if a string is only whitespace, otherwise 0 */ 359 int only_whitespace(char *s) 360 { 352 361 int i; 353 362 for (i=0; s[i]; i++) { … … 359 368 /* hooks for doing memory allocation et. al. in owl */ 360 369 361 void *owl_malloc(size_t size) { 370 void *owl_malloc(size_t size) 371 { 362 372 return(malloc(size)); 363 373 } 364 374 365 void owl_free(void *ptr) { 375 void owl_free(void *ptr) 376 { 366 377 free(ptr); 367 378 } 368 379 369 char *owl_strdup(const char *s1) { 380 char *owl_strdup(const char *s1) 381 { 370 382 return(strdup(s1)); 371 383 } 372 384 373 void *owl_realloc(void *ptr, size_t size) { 385 void *owl_realloc(void *ptr, size_t size) 386 { 374 387 return(realloc(ptr, size)); 375 388 } 376 389 377 char *owl_sprintf(const char *fmt, ...) { 378 /* allocates memory and returns the string or null. 379 * caller must free the string. 380 * from Linux sprintf man page. 381 */ 382 390 391 /* allocates memory and returns the string or null. 392 * caller must free the string. 393 * from Linux sprintf man page. 394 */ 395 char *owl_sprintf(const char *fmt, ...) 396 { 383 397 int n, size = 100; 384 398 char *p; … … 403 417 } 404 418 405 /* the caller must free the return */ 406 char *short_zuser(char *in) { 419 /* Strip a local realm fron the zephyr user name. 420 * The caller must free the return 421 */ 422 char *short_zuser(char *in) 423 { 407 424 char *out, *ptr; 408 425 … … 417 434 } 418 435 419 /* the caller must free the return */ 420 char *long_zuser(char *in) { 436 /* Append a local realm to the zephyr user name if necessary. 437 * The caller must free the return. 438 */ 439 char *long_zuser(char *in) 440 { 421 441 char *ptr; 422 442 … … 429 449 430 450 431 char *owl_util_smartstripped_user(char *in) { 432 /* strip out the instance from a zsender's principal. Preserves the 433 * realm if present. daemon.webzephyr is a special case. The 434 * caller must free the return */ 435 451 /* strip out the instance from a zsender's principal. Preserves the 452 * realm if present. daemon.webzephyr is a special case. The 453 * caller must free the return 454 */ 455 char *owl_util_smartstripped_user(char *in) 456 { 436 457 char *ptr, *realm, *out; 437 458 … … 452 473 } 453 474 454 455 475 /* remove the realm from ptr, but hold on to it */ 456 476 realm=strchr(out, '@'); … … 471 491 } 472 492 473 char *owl_getquoting(char *line) { 493 char *owl_getquoting(char *line) 494 { 474 495 if (line[0]=='\0') return("'"); 475 496 if (strchr(line, '\'')) return("\""); … … 479 500 } 480 501 481 char *owl_util_substitute(char *in, char *from, char *to) { 482 /* Caller must free returned string. 483 * Returns a string with any occurances of 'from' replaced with 'to'. 484 * Does not currently handle backslash quoting, but may in the future. 485 */ 502 503 504 /* Return a string with any occurances of 'from' replaced with 'to'. 505 * Does not currently handle backslash quoting, but may in the future. 506 * Caller must free returned string. 507 */ 508 char *owl_util_substitute(char *in, char *from, char *to) 509 { 486 510 487 511 char *out; … … 511 535 } 512 536 513 void owl_util_tr(char *buff, char a, char b) { 514 /* replace all instances of character a in buff with the character 515 b. buff must be null terminated */ 537 /* replace all instances of character a in buff with the character 538 * b. buff must be null terminated. 539 */ 540 void owl_util_tr(char *buff, char a, char b) 541 { 516 542 int i; 517 543 … … 523 549 } 524 550 525 int owl_util_string_to_color(char *color) { 551 552 /* Return the owl color associated with the named color */ 553 int owl_util_string_to_color(char *color) 554 { 526 555 if (!strcasecmp(color, "black")) { 527 556 return(OWL_COLOR_BLACK); … … 546 575 } 547 576 548 char *owl_util_color_to_string(int color) { 577 /* Return a string name of the given owl color */ 578 char *owl_util_color_to_string(int color) 579 { 549 580 if (color==OWL_COLOR_BLACK) return("black"); 550 581 if (color==OWL_COLOR_RED) return("red"); … … 559 590 } 560 591 561 char *owl_util_get_default_tty() { 562 /* call must free the return */ 592 /* Get the default tty name. Caller must free the return */ 593 char *owl_util_get_default_tty() 594 { 563 595 char *out, *tmp; 564 596 … … 578 610 579 611 580 void owl_hack_animate() { 612 /* Animation hack */ 613 void owl_hack_animate() 614 { 581 615 owl_messagelist *ml; 582 616 owl_message *m; … … 631 665 } 632 666 633 char *owl_util_stripnewlines(char *in) { 634 /* strip leading and trailing new lines. 635 caller must free the return */ 667 /* strip leading and trailing new lines. Caller must free the 668 * return. 669 */ 670 char *owl_util_stripnewlines(char *in) 671 { 636 672 637 673 char *tmp, *ptr1, *ptr2, *out; … … 733 769 #define FAIL_UNLESS(desc,pred) printf("\t%-4s: %s\n", (pred)?"ok":(numfailed++,"FAIL"), desc) 734 770 735 int owl_util_regtest(void) { 771 int owl_util_regtest(void) 772 { 736 773 int numfailed=0; 737 774
Note: See TracChangeset
for help on using the changeset viewer.