Changeset 2315 in MondoRescue for branches/2.2.10/mondo/src/common/libmondo-string.c
- Timestamp:
- Aug 18, 2009, 2:29:18 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-string.c
r2314 r2315 501 501 /** 502 502 * Replace all occurences of @p token with @p value while copying @p ip to @p output. 503 * @param ip The input string containing zero or more <tt>token</tt>s. 503 * @param ip The input string containing zero or more <tt>token</tt>s. The string will be altered by this function 504 504 * @param output The output string written with the <tt>token</tt>s replaced by @p value. 505 505 * @param token The token to be relaced with @p value. 506 506 * @param value The value to replace @p token. 507 507 */ 508 void resolve_naff_tokens(char *output,char *ip, char *value, char *token)508 char *resolve_naff_tokens(char *ip, char *value, char *token) 509 509 { 510 510 /*@ buffers *** */ 511 char * input;511 char *output = NULL; 512 512 513 513 /*@ pointers * */ 514 char *p; 515 516 input = malloc(2000); 517 // BERLIOS: seems to cause invalid errors 518 //assert_string_is_neither_NULL_nor_zerolength(ip); 514 char *p = NULL; /* points to token to modify */ 515 char *q = NULL; /* points to start of string/new string */ 516 519 517 assert_string_is_neither_NULL_nor_zerolength(token); 520 518 assert(value != NULL); 521 519 522 strcpy(output, ip); /* just in case the token doesn't appear in string at all */ 523 for (strcpy(input, ip); strstr(input, token); strcpy(input, output)) { 524 strcpy(output, input); 525 p = strstr(output, token); 520 q = ip; 521 while ((p = strstr(q, token) != NULL)) { 526 522 *p = '\0'; 527 strcat(output, value); 528 p = strstr(input, token) + strlen(token); 529 strcat(output, p); 530 } 531 paranoid_free(input); 523 if (output) { 524 mr_strcat(output, "%s%s", q, value); 525 } else { 526 mr_asprintf(&output, "%s%s", q, value); 527 } 528 p++; 529 q = p; 530 } 531 if (output) { 532 mr_strcat(output, "%s", q); 533 } else { 534 /* just in case the token doesn't appear in string at all */ 535 mr_asprintf(&output, "%s", q); 536 } 537 return(output); 532 538 } 533 539 … … 1085 1091 /*@ int *********************************************** */ 1086 1092 int percentage; 1093 int j; 1087 1094 1088 1095 /*@ buffers ******************************************* */
Note:
See TracChangeset
for help on using the changeset viewer.