Changeset 2315 in MondoRescue


Ignore:
Timestamp:
Aug 18, 2009, 2:29:18 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3326@localhost: bruno | 2009-08-01 23:53:09 +0200
resolve_naff_tokens now returns an allocated char

Location:
branches/2.2.10/mondo/src/common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/libmondo-fork.c

    r2296 r2315  
    101101
    102102    /*@ buffers      *** */
    103     char *midway_call, *ultimate_call, *tmp, *incoming, *old_stderr;
     103    char *midway_call = NULL;
     104    char *ultimate_call = NULL;
     105    char *tmp = NULL;
     106    char *incoming, *old_stderr;
    104107       
    105108    char *cd_number_str = NULL;
     
    113116    log_msg(3, "Starting");
    114117    assert(bkpinfo != NULL);
    115     // BERLIOS: doesn't work even if the string is correct !
    116     //assert_string_is_neither_NULL_nor_zerolength(basic_call);
    117118    assert_string_is_neither_NULL_nor_zerolength(isofile);
    118119    assert_string_is_neither_NULL_nor_zerolength(logstub);
    119     if (!(midway_call = malloc(1200))) {
    120         fatal_error("Cannot malloc midway_call");
    121     }
    122     if (!(ultimate_call = malloc(1200))) {
    123         fatal_error("Cannot malloc ultimate_call");
    124     }
    125     if (!(tmp = malloc(1200))) {
    126         fatal_error("Cannot malloc tmp");
    127     }
    128120    malloc_string(incoming);
    129121    malloc_string(old_stderr);
     
    139131
    140132    mr_asprintf(&cd_number_str, "%d", cd_no);
    141     resolve_naff_tokens(midway_call, tmp1, isofile, "_ISO_");
    142     resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_");
     133    log_msg(4, "basic call = '%s'", tmp1);
     134    midway_call = resolve_naff_tokens(tmp1, isofile, "_ISO_");
     135    mr_free(tmp1);
     136
     137    log_msg(4, "midway_call = '%s'", midway_call);
     138    tmp = resolve_naff_tokens(midway_call, cd_number_str, "_CD#_");
    143139    mr_free(cd_number_str);
    144 
    145     resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_");
    146     log_msg(4, "basic call = '%s'", tmp1);
    147     log_msg(4, "midway_call = '%s'", midway_call);
     140    mr_free(midway_call);
     141
    148142    log_msg(4, "tmp = '%s'", tmp);
     143    ultimate_call = resolve_naff_tokens(tmp, MONDO_LOGFILE, "_ERR_");
     144    mr_free(tmp);
     145
    149146    log_msg(4, "ultimate call = '%s'", ultimate_call);
    150147    mr_asprintf(&command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
     148    mr_free(ultimate_call);
    151149
    152150    log_to_screen
     
    181179        }
    182180        if (retval) {
    183             log_msg(2, "Basic call '%s' returned an error.", tmp1);
    184             popup_and_OK("Press ENTER to continue.");
    185181            popup_and_OK("mkisofs and/or cdrecord returned an error. CD was not created");
    186182        }
     
    192188    }
    193189    mr_free(command);
    194     mr_free(tmp1);
    195     paranoid_free(midway_call);
    196     paranoid_free(ultimate_call);
    197     paranoid_free(tmp);
    198190    paranoid_free(incoming);
    199191    paranoid_free(old_stderr);
  • branches/2.2.10/mondo/src/common/libmondo-string-EXT.h

    r1647 r2315  
    1616extern char *number_of_disks_as_string(int noof_disks, char *label);
    1717extern char *number_to_text(int i);
    18 extern void resolve_naff_tokens(char *output, char *ip, char *value,
    19                                 char *token);
     18extern char *resolve_naff_tokens(char *ip, char *value, char *token);
    2019extern char *slice_fname(long bigfileno, long sliceno, char *path,
    2120                         char *s);
  • branches/2.2.10/mondo/src/common/libmondo-string.c

    r2314 r2315  
    501501/**
    502502 * 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
    504504 * @param output The output string written with the <tt>token</tt>s replaced by @p value.
    505505 * @param token The token to be relaced with @p value.
    506506 * @param value The value to replace @p token.
    507507 */
    508 void resolve_naff_tokens(char *output, char *ip, char *value, char *token)
     508char *resolve_naff_tokens(char *ip, char *value, char *token)
    509509{
    510510    /*@ buffers *** */
    511     char *input;
     511    char *output = NULL;
    512512
    513513    /*@ 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
    519517    assert_string_is_neither_NULL_nor_zerolength(token);
    520518    assert(value != NULL);
    521519
    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)) {
    526522        *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);
    532538}
    533539
     
    10851091    /*@ int *********************************************** */
    10861092    int percentage;
     1093    int j;
    10871094
    10881095    /*@ buffers ******************************************* */
  • branches/2.2.10/mondo/src/common/libmondo-string.h

    r1647 r2315  
    1414char *number_of_disks_as_string(int noof_disks, char *label);
    1515char *number_to_text(int i);
    16 void resolve_naff_tokens(char *output, char *ip, char *value, char *token);
     16char *resolve_naff_tokens(char *ip, char *value, char *token);
    1717char *slice_fname(long bigfileno, long sliceno, char *path, char *s);
    1818int special_dot_char(int i);
Note: See TracChangeset for help on using the changeset viewer.