Ignore:
Timestamp:
Feb 19, 2007, 1:51:26 AM (12 years ago)
Author:
bruno
Message:

Merges in trunk modifications coming from stable (common)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/src/common/libmondo-string.c

    r1081 r1185  
    1010#include "my-stuff.h"
    1111#include "mr_mem.h"
     12#include "mr_str.h"
     13
    1214#include "mondostructures.h"
    1315#include "libmondo-string.h"
     
    1618#include "libmondo-tools-EXT.h"
    1719#include <math.h>
    18 #include "mr_mem.h"
    1920
    2021/*@unused@*/
     
    3839char *build_partition_name(const char *drive, int partno)
    3940{
    40     char *p, *c;
    41     char *partition;
     41    char *p = NULL;
     42    char *c = NULL;
     43    char *partition = NULL;
    4244
    4345    assert_string_is_neither_NULL_nor_zerolength(drive);
    4446    assert(partno >= 0);
    4547
    46     mr_asprintf(&partition, "%s", drive);
     48    mr_asprintf(&partition, drive);
    4749    p = partition;
    4850    /* is this a devfs device path? */
     
    7981void center_string(char *in_out, int width)
    8082{
    81     char *scratch;
    82     char *out;
    83     char *p;
    84     int i;                      /* purpose */
    85     int len;                    /* purpose */
    86     int mid;                    /* purpose */
    87     int x;                      /* purpose */
     83    char *scratch = NULL;
     84    char *out = NULL;
     85    char *p = NULL;
     86    int i = 0;                      /* purpose */
     87    int len = 0;                    /* purpose */
     88    int mid = 0;                    /* purpose */
     89    int x = 0;                      /* purpose */
    8890
    8991    assert(in_out != NULL);
     
    9395        return;
    9496    }
    95     for (p = in_out; *p == ' '; p++);
    96     mr_asprintf(&scratch, p);
    97     strip_spaces (scratch);
     97    mr_asprintf(&scratch, in_out);
     98    mr_strip_spaces(scratch);
    9899    len = (int) strlen(scratch);
    99100    mid = width / 2;
     
    177178long friendly_sizestr_to_sizelong(char *incoming)
    178179{
    179     long outval;
    180     int i;
    181     char *tmp;
    182     char ch;
     180    long outval = 0L;
     181    int i = 0;
     182    char *tmp = NULL;
     183    char ch = ' ';
    183184
    184185    assert_string_is_neither_NULL_nor_zerolength(incoming);
    185186
    186187    if (!incoming[0]) {
    187         return (0);
     188        return(0L);
    188189    }
    189190    if (strchr(incoming, '.')) {
     
    225226
    226227/**
    227  * Add spaces to the right of @p incoming to make it @p width characters wide.
    228  * @param incoming The string to left-pad.
    229  * @param width The width to pad it to.
    230  * @return The left-padded string.
    231  * @note The returned string points to static storage that will be overwritten with each call.
    232  * @bug Why does center_string() modify its argument but leftpad_string() returns a modified copy?
    233  */
    234 /* BERLIOS; useless ?
    235 char *leftpad_string(char *incoming, int width)
    236 {
    237     char *output;
    238 
    239     int i;
    240 
    241     assert(incoming != NULL);
    242     assert(width > 2);
    243 
    244     mr_asprintf(&output, "%s", incoming);
    245     for (i = (int) strlen(output); i < width; i++) {
    246         output[i] = ' ';
    247     }
    248     output[i] = '\0';
    249     return (output);
    250 }
    251 */
    252 
    253 
    254 
    255 /**
    256228 * Turn a marker byte (e.g. BLK_START_OF_BACKUP) into a string (e.g. "BLK_START_OF_BACKUP").
    257229 * Unknown markers are identified as "BLK_UNKNOWN (%d)" where %d is the decimal value.
     
    353325
    354326    /*@ buffer *********************************************************** */
    355     char *output;
     327    char *output = NULL;
    356328
    357329    assert(mountlist != NULL);
     
    376348
    377349    /*@ buffers ********************************************************* */
    378     char *output;
     350    char *output = NULL;
    379351
    380352    /*@ char     ******************************************************** */
    381     char p;
     353    char p = NULL;
    382354
    383355    assert(label != NULL);
     
    415387    switch (i) {
    416388    case 0:
    417         mr_asprintf(&output, "%s", "zero");
     389        mr_asprintf(&output, "zero");
    418390        break;
    419391    case 1:
    420         mr_asprintf(&output, "%s", "one");
     392        mr_asprintf(&output, "one");
    421393        break;
    422394    case 2:
    423         mr_asprintf(&output, "%s", "two");
     395        mr_asprintf(&output, "two");
    424396        break;
    425397    case 3:
    426         mr_asprintf(&output, "%s", "three");
     398        mr_asprintf(&output, "three");
    427399        break;
    428400    case 4:
    429         mr_asprintf(&output, "%s", "four");
     401        mr_asprintf(&output, "four");
    430402        break;
    431403    case 5:
    432         mr_asprintf(&output, "%s", "five");
     404        mr_asprintf(&output, "five");
    433405        break;
    434406    case 6:
    435         mr_asprintf(&output, "%s", "six");
     407        mr_asprintf(&output, "six");
    436408        break;
    437409    case 7:
    438         mr_asprintf(&output, "%s", "seven");
     410        mr_asprintf(&output, "seven");
    439411        break;
    440412    case 8:
    441         mr_asprintf(&output, "%s", "eight");
     413        mr_asprintf(&output, "eight");
    442414        break;
    443415    case 9:
    444         mr_asprintf(&output, "%s", "nine");
     416        mr_asprintf(&output, "nine");
    445417    case 10:
    446         mr_asprintf(&output, "%s", "ten");
     418        mr_asprintf(&output, "ten");
    447419    default:
    448420        mr_asprintf(&output, "%d", i);
     
    462434{
    463435    /*@ buffers *** */
    464     char *input;
     436    char *input = NULL;
    465437
    466438    /*@ pointers * */
    467     char *p;
     439    char *p = NULL;
    468440
    469441    assert_string_is_neither_NULL_nor_zerolength(ip);
     
    516488        mr_asprintf(&suffix, ".%s", s);
    517489    } else {
    518         mr_asprintf(&suffix, "%s", "");
     490        mr_asprintf(&suffix, "");
    519491    }
    520492    mr_asprintf(&output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno,
     
    686658
    687659/**
    688  * Remove all characters whose ASCII value is less than or equal to 32
    689  * (spaces and control characters) from both sides of @p in_out.
    690  * @param in_out The string to strip spaces/control characters from (modified).
    691  */
    692 void strip_spaces(char *in_out)
    693 {
    694     /*@ buffers ***************************************************** */
    695     char *tmp;
    696     char *tmp1;
    697 
    698     /*@ pointers **************************************************** */
    699     char *p;
    700 
    701     /*@ int ******************************************************** */
    702     int i;
    703     int original_incoming_length;
    704 
    705     /*@ end vars *************************************************** */
    706 
    707     assert(in_out != NULL);
    708     original_incoming_length = (int) strlen(in_out);
    709     for (i = 0; in_out[i] <= ' ' && i < (int) strlen(in_out); i++);
    710     mr_asprintf(&tmp, "%s", in_out + i);
    711     for (i = (int) strlen(tmp); i > 0 && tmp[i - 1] <= 32; i--);
    712     tmp[i] = '\0';
    713     for (i = 0; i < original_incoming_length; i++) {
    714         in_out[i] = ' ';
    715     }
    716     in_out[i] = '\0';
    717     i = 0;
    718     p = tmp;
    719     while (*p != '\0') {
    720         in_out[i] = *(p++);
    721         in_out[i + 1] = '\0';
    722         if (in_out[i] < 32 && i > 0) {
    723             if (in_out[i] == 8) {
    724                 i--;
    725             } else if (in_out[i] == 9) {
    726                 in_out[i++] = ' ';
    727             } else if (in_out[i] == '\r') {
    728                 mr_asprintf(&tmp1, "%s", in_out + i);
    729                 strcpy(in_out, tmp1);
    730                 mr_free(tmp1);
    731                 i = -1;
    732                 continue;
    733             } else if (in_out[i] == '\t') {
    734                 for (i++; i % 5; i++);
    735             } else if (in_out[i] >= 10 && in_out[i] <= 13) {
    736                 break;
    737             } else {
    738                 i--;
    739             }
    740         } else {
    741             i++;
    742         }
    743     }
    744     in_out[i] = '\0';
    745     mr_free(tmp);
    746 }
    747 
    748 
    749 /**
    750660 * If there are double quotes "" around @p incoming then remove them.
    751661 * This does not affect other quotes that may be embedded within the string.
     
    781691{
    782692    int i = strlen(partition) - 1;
    783     char *c;
     693    char *c = NULL;
    784694
    785695#ifdef __FreeBSD__
     
    851761{
    852762    int sev = 0;
    853     char *reason;
    854     char *filename;
     763    char *reason = NULL;
     764    char *filename = NULL;
    855765
    856766    // out_reason might be null on purpose, so don't bomb if it is :) OK?
    857767    assert_string_is_neither_NULL_nor_zerolength(fn);
    858768    if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) {
    859         mr_asprintf(&filename, "%s", fn + strlen(MNT_RESTORING));
     769        mr_asprintf(&filename, fn + strlen(MNT_RESTORING));
    860770    } else if (fn[0] != '/') {
    861771        mr_asprintf(&filename, "/%s", fn);
    862772    } else {
    863         mr_asprintf(&filename, "%s", fn);
     773        mr_asprintf(&filename, fn);
    864774    }
    865775
     
    943853        sev = 1;
    944854        mr_asprintf(&reason,
    945                  "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");
     855                _("Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."));
    946856    }
    947857    mr_free(filename);
     
    956866    return (sev);
    957867}
    958 
    959868
    960869
     
    1013922    }
    1014923
    1015 /* update screen */
     924    /* update screen */
    1016925    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    1017926        percentage =
     
    1031940    }
    1032941    j = trunc(percentage / 5);
    1033     tmp1 = (char *) malloc((j + 1) * sizeof(char));
     942    tmp1 = (char *) mr_malloc((j + 1) * sizeof(char));
    1034943    for (i = 0, p = tmp1; i < j; i++, p++) {
    1035944        *p = '*';
     
    1037946    *p = '\0';
    1038947
    1039     tmp2 = (char *) malloc((20 - j + 1) * sizeof(char));
     948    tmp2 = (char *) mr_malloc((20 - j + 1) * sizeof(char));
    1040949    for (i = 0, p = tmp2; i < 20 - j; i++, p++) {
    1041950        *p = '.';
Note: See TracChangeset for help on using the changeset viewer.