Ignore:
Timestamp:
Nov 19, 2005, 2:27:41 AM (15 years ago)
Author:
bcornec
Message:

indent on all the C code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.05/mondo/mondo/common/libmondo-string.c

    r30 r128  
    11/* libmondo-string.c
    2    $Id: libmondo-string.c,v 1.3 2004/06/21 20:20:36 hugo Exp $
     2   $Id$
    33
    44- string manipulation
     
    7171
    7272/*@unused@*/
    73 //static char cvsid[] = "$Id: libmondo-string.c,v 1.3 2004/06/21 20:20:36 hugo Exp $";
     73//static char cvsid[] = "$Id$";
    7474
    7575extern int g_current_media_number;
     
    8989 * @note If @p drive ends in a digit, then 'p' (on Linux) or 's' (on *BSD) is added before @p partno.
    9090 */
    91 char *
    92 build_partition_name (char *partition, const char *drive, int partno)
    93 {
    94     char *p, *c;
    95 
    96   assert(partition!=NULL);
    97   assert_string_is_neither_NULL_nor_zerolength(drive);
    98   assert(partno>=0);
    99 
    100   p = strcpy(partition, drive);
    101   /* is this a devfs device path? */
    102   c = strrchr (partition, '/');
    103   if (c && strncmp (c, "/disc", 5) == 0) {
    104       /* yup it's devfs, return the "part" path */
    105       strcpy (c + 1, "part");
    106       p = c + 5;
    107   } else {
    108       p += strlen (p);
    109       if (isdigit (p[-1])) {
    110       *p++ =
     91char *build_partition_name(char *partition, const char *drive, int partno)
     92{
     93    char *p, *c;
     94
     95    assert(partition != NULL);
     96    assert_string_is_neither_NULL_nor_zerolength(drive);
     97    assert(partno >= 0);
     98
     99    p = strcpy(partition, drive);
     100    /* is this a devfs device path? */
     101    c = strrchr(partition, '/');
     102    if (c && strncmp(c, "/disc", 5) == 0) {
     103        /* yup it's devfs, return the "part" path */
     104        strcpy(c + 1, "part");
     105        p = c + 5;
     106    } else {
     107        p += strlen(p);
     108        if (isdigit(p[-1])) {
     109            *p++ =
    111110#ifdef BSD
    112          's';
     111                's';
    113112#else
    114              'p';
     113                'p';
    115114#endif
    116       }
    117     }
    118   sprintf (p, "%d", partno);
    119   return (partition);
     115        }
     116    }
     117    sprintf(p, "%d", partno);
     118    return (partition);
    120119}
    121120
     
    137136 * @param width The width of the final result.
    138137 */
    139 void center_string (char *in_out, int width)
    140 {
    141   char scratch[MAX_STR_LEN];
    142   char *p;
    143   int i;            /* purpose */
    144   int len;          /* purpose */
    145   int mid;          /* purpose */
    146   int x;            /* purpose */
    147 
    148   assert(in_out!=NULL);
    149   assert(width>2);
    150 
    151   if (strlen (in_out) == 0)
    152     {
    153       return;
    154     }
    155   for (p = in_out; *p == ' '; p++);
    156   strcpy (scratch, p);
    157   len = (int) strlen (scratch);
    158   mid = width / 2;
    159   x = mid - len / 2;
    160   for (i = 0; i < x; i++)
    161     {
    162       in_out[i] = ' ';
    163     }
    164   in_out[i] = '\0';
    165   strcat (in_out, scratch);
    166 }
    167 
    168 
    169 
    170 
    171 inline void turn_wildcard_chars_into_literal_chars(char*sout, char*sin)
     138void center_string(char *in_out, int width)
     139{
     140    char scratch[MAX_STR_LEN];
     141    char *p;
     142    int i;                      /* purpose */
     143    int len;                    /* purpose */
     144    int mid;                    /* purpose */
     145    int x;                      /* purpose */
     146
     147    assert(in_out != NULL);
     148    assert(width > 2);
     149
     150    if (strlen(in_out) == 0) {
     151        return;
     152    }
     153    for (p = in_out; *p == ' '; p++);
     154    strcpy(scratch, p);
     155    len = (int) strlen(scratch);
     156    mid = width / 2;
     157    x = mid - len / 2;
     158    for (i = 0; i < x; i++) {
     159        in_out[i] = ' ';
     160    }
     161    in_out[i] = '\0';
     162    strcat(in_out, scratch);
     163}
     164
     165
     166
     167
     168inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin)
    172169{
    173170    char *p, *q;
    174    
    175     for(p=sin, q=sout; *p!='\0'; *(q++) = *(p++) )
    176       {
    177         if (strchr("[]*?", *p)) { *(q++) = '\\'; }
    178       }
    179     *q = *p; // for the final '\0'
     171
     172    for (p = sin, q = sout; *p != '\0'; *(q++) = *(p++)) {
     173        if (strchr("[]*?", *p)) {
     174            *(q++) = '\\';
     175        }
     176    }
     177    *q = *p;                    // for the final '\0'
    180178}
    181179
     
    188186 * @note The returned string points to static storage that will be overwritten with each call.
    189187 */
    190 char* commarize(char*input)
    191 {
    192   char pos_w_commas[MAX_STR_LEN];
    193   static char output[MAX_STR_LEN];
    194   char tmp[MAX_STR_LEN];
    195   int j;
    196 
    197   assert(input!=NULL);
    198 
    199   strcpy(tmp, input);
    200   if (strlen(tmp) > 6)
    201     {
    202       strcpy(pos_w_commas, tmp);
    203       j = (int) strlen(pos_w_commas);
    204       tmp[j-6] = ',';
    205       strcpy(tmp+j-5, pos_w_commas+j-6);
     188char *commarize(char *input)
     189{
     190    char pos_w_commas[MAX_STR_LEN];
     191    static char output[MAX_STR_LEN];
     192    char tmp[MAX_STR_LEN];
     193    int j;
     194
     195    assert(input != NULL);
     196
     197    strcpy(tmp, input);
     198    if (strlen(tmp) > 6) {
     199        strcpy(pos_w_commas, tmp);
     200        j = (int) strlen(pos_w_commas);
     201        tmp[j - 6] = ',';
     202        strcpy(tmp + j - 5, pos_w_commas + j - 6);
    206203//      tmp[j-2] = ',';
    207204//      strcpy(tmp+j-1, pos_w_commas+j-3);
    208       strcpy(pos_w_commas, tmp);
    209     }
    210   if (strlen(tmp) > 3)
    211     {
    212       j = (int) strlen(tmp);
    213       strcpy(pos_w_commas, tmp);
    214       pos_w_commas[j-3] = ',';
    215       strcpy(pos_w_commas+j-2, tmp+j-3);
    216     }
    217   else
    218     {
    219       strcpy(pos_w_commas, tmp);
    220     }
    221   strcpy(output, pos_w_commas);
    222   return(output);
     205        strcpy(pos_w_commas, tmp);
     206    }
     207    if (strlen(tmp) > 3) {
     208        j = (int) strlen(tmp);
     209        strcpy(pos_w_commas, tmp);
     210        pos_w_commas[j - 3] = ',';
     211        strcpy(pos_w_commas + j - 2, tmp + j - 3);
     212    } else {
     213        strcpy(pos_w_commas, tmp);
     214    }
     215    strcpy(output, pos_w_commas);
     216    return (output);
    223217}
    224218
     
    241235 * @note The returned string points to static storage and will be overwritten with each call.
    242236 */
    243 char *
    244 disklist_entry_to_string (struct list_of_disks *disklist, int lino)
    245 {
    246 
    247     /*@ buffers ***********************************************************/
    248   static char output[MAX_STR_LEN];
    249 
    250   assert(disklist!=NULL);
    251 
    252   sprintf (output, "%-24s %8d", disklist->el[lino].device,
    253        disklist->el[lino].index);
    254   return (output);
     237char *disklist_entry_to_string(struct list_of_disks *disklist, int lino)
     238{
     239
     240    /*@ buffers ********************************************************** */
     241    static char output[MAX_STR_LEN];
     242
     243    assert(disklist != NULL);
     244
     245    sprintf(output, "%-24s %8d", disklist->el[lino].device,
     246            disklist->el[lino].index);
     247    return (output);
    255248}
    256249
     
    266259 * @return The size in megabytes.
    267260 */
    268 long
    269 friendly_sizestr_to_sizelong (char *incoming)
    270 {
    271   long outval;
    272   int i;
    273   char *tmp;
    274   char ch;
    275 
    276   assert_string_is_neither_NULL_nor_zerolength(incoming);
    277 
    278   malloc_string(tmp);
    279   if (!incoming[0]) { free(tmp); return(0); }
    280   if (strchr(incoming, '.'))
    281     { fatal_error("Please use integers only. No decimal points."); }
    282   strcpy (tmp, incoming);
    283   i = (int) strlen(tmp);
    284   if (tmp[i-1]=='B' || tmp[i-1]=='b') { tmp[i-1]='\0'; }
    285   for (i = 0; i < (int) strlen (tmp) && isdigit (tmp[i]); i++);
    286   ch = tmp[i];
    287   tmp[i] = '\0';
    288   outval = atol (tmp);
    289   if (ch == 'g' || ch == 'G')
    290     {
    291       outval = outval * 1024;
    292     }
    293   else if (ch == 'k' || ch == 'K')
    294     {
    295       outval = outval / 1024;
    296     }
    297   else if (ch == 't' || ch == 'T') // terabyte
    298     {
    299     outval *= 1048576;
    300     }
    301   else if (ch == 'Y' || ch == 'y') // yottabyte - the biggest measure in the info file
    302     {
    303     log_it ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes of data?!?!");
    304     popup_and_OK ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
    305     fatal_error ("Integer overflow.");
    306     }
    307   else if (ch != 'm' && ch != 'M')
    308     {
    309       sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')", incoming, ch);
    310       fatal_error(tmp);
    311     }
    312   paranoid_free(tmp);
    313   return (outval);
     261long friendly_sizestr_to_sizelong(char *incoming)
     262{
     263    long outval;
     264    int i;
     265    char *tmp;
     266    char ch;
     267
     268    assert_string_is_neither_NULL_nor_zerolength(incoming);
     269
     270    malloc_string(tmp);
     271    if (!incoming[0]) {
     272        free(tmp);
     273        return (0);
     274    }
     275    if (strchr(incoming, '.')) {
     276        fatal_error("Please use integers only. No decimal points.");
     277    }
     278    strcpy(tmp, incoming);
     279    i = (int) strlen(tmp);
     280    if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') {
     281        tmp[i - 1] = '\0';
     282    }
     283    for (i = 0; i < (int) strlen(tmp) && isdigit(tmp[i]); i++);
     284    ch = tmp[i];
     285    tmp[i] = '\0';
     286    outval = atol(tmp);
     287    if (ch == 'g' || ch == 'G') {
     288        outval = outval * 1024;
     289    } else if (ch == 'k' || ch == 'K') {
     290        outval = outval / 1024;
     291    } else if (ch == 't' || ch == 'T')  // terabyte
     292    {
     293        outval *= 1048576;
     294    } else if (ch == 'Y' || ch == 'y')  // yottabyte - the biggest measure in the info file
     295    {
     296        log_it
     297            ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes of data?!?!");
     298        popup_and_OK
     299            ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
     300        fatal_error("Integer overflow.");
     301    } else if (ch != 'm' && ch != 'M') {
     302        sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')",
     303                incoming, ch);
     304        fatal_error(tmp);
     305    }
     306    paranoid_free(tmp);
     307    return (outval);
    314308}
    315309
     
    324318 * @bug Why does center_string() modify its argument but leftpad_string() returns a modified copy?
    325319 */
    326 char *
    327 leftpad_string (char *incoming, int width)
    328 {
    329     /*@ buffers ******************************************************/
    330   static char output[MAX_STR_LEN];
    331 
    332     /*@ ints *********************************************************/
    333   int i;
    334 
    335     /*@ end vars *****************************************************/
    336   assert(incoming!=NULL);
    337   assert(width>2);
    338 
    339   strcpy (output, incoming);
    340   for (i = (int) strlen (output); i < width; i++)
    341     {
    342       output[i] = ' ';
    343     }
    344   output[i] = '\0';
    345   return (output);
     320char *leftpad_string(char *incoming, int width)
     321{
     322    /*@ buffers ***************************************************** */
     323    static char output[MAX_STR_LEN];
     324
     325    /*@ ints ******************************************************** */
     326    int i;
     327
     328    /*@ end vars **************************************************** */
     329    assert(incoming != NULL);
     330    assert(width > 2);
     331
     332    strcpy(output, incoming);
     333    for (i = (int) strlen(output); i < width; i++) {
     334        output[i] = ' ';
     335    }
     336    output[i] = '\0';
     337    return (output);
    346338}
    347339
     
    355347 * @note The returned string points to static storage that will be overwritten with each call.
    356348 */
    357 char *
    358 marker_to_string (int marker)
    359 {
    360     /*@ buffer *******************************************************/
    361   static char outstr[MAX_STR_LEN];
    362 
    363 
    364     /*@ end vars ****************************************************/
    365 
    366   switch (marker)
    367     {
    368     case BLK_START_OF_BACKUP:
    369       strcpy (outstr, "BLK_START_OF_BACKUP");
    370       break;
    371     case BLK_START_OF_TAPE:
    372       strcpy (outstr, "BLK_START_OF_TAPE");
    373       break;
    374     case BLK_START_AN_AFIO_OR_SLICE:
    375       strcpy (outstr, "BLK_START_AN_AFIO_OR_SLICE");
    376       break;
    377     case BLK_STOP_AN_AFIO_OR_SLICE:
    378       strcpy (outstr, "BLK_STOP_AN_AFIO_OR_SLICE");
    379       break;
    380     case BLK_START_AFIOBALLS:
    381       strcpy (outstr, "BLK_START_AFIOBALLS");
    382       break;
    383     case BLK_STOP_AFIOBALLS:
    384       strcpy (outstr, "BLK_STOP_AFIOBALLS");
    385       break;
    386     case BLK_STOP_BIGGIEFILES:
    387       strcpy (outstr, "BLK_STOP_BIGGIEFILES");
    388       break;
    389     case BLK_START_A_NORMBIGGIE:
    390       strcpy (outstr, "BLK_START_A_NORMBIGGIE");
    391       break;
    392     case BLK_START_A_PIHBIGGIE:
    393       strcpy (outstr, "BLK_START_A_PIHBIGGIE");
    394       break;
    395     case BLK_START_EXTENDED_ATTRIBUTES:
    396       strcpy (outstr, "BLK_START_EXTENDED_ATTRIBUTES");
    397       break;
    398     case BLK_STOP_EXTENDED_ATTRIBUTES:
    399       strcpy (outstr, "BLK_STOP_EXTENDED_ATTRIBUTES");
    400       break;
    401     case BLK_START_EXAT_FILE:
    402       strcpy (outstr, "BLK_START_EXAT_FILE");
    403       break;
    404     case BLK_STOP_EXAT_FILE:
    405       strcpy (outstr, "BLK_STOP_EXAT_FILE");
    406       break;
    407     case BLK_START_BIGGIEFILES:
    408       strcpy (outstr, "BLK_START_BIGGIEFILES");
    409       break;
    410     case BLK_STOP_A_BIGGIE:
    411       strcpy (outstr, "BLK_STOP_A_BIGGIE");
    412       break;
    413     case BLK_END_OF_TAPE:
    414       strcpy (outstr, "BLK_END_OF_TAPE");
    415       break;
    416     case BLK_END_OF_BACKUP:
    417       strcpy (outstr, "BLK_END_OF_BACKUP");
    418       break;
    419     case BLK_ABORTED_BACKUP:
    420       strcpy (outstr, "BLK_ABORTED_BACKUP");
    421       break;
    422     case BLK_START_FILE:
    423       strcpy (outstr, "BLK_START_FILE");
    424       break;
    425     case BLK_STOP_FILE:
    426       strcpy (outstr, "BLK_STOP_FILE");
    427       break;
    428     default:
    429       sprintf (outstr, "BLK_UNKNOWN (%d)", marker);
    430       break;
    431     }
    432   return (outstr);
     349char *marker_to_string(int marker)
     350{
     351    /*@ buffer ****************************************************** */
     352    static char outstr[MAX_STR_LEN];
     353
     354
     355    /*@ end vars *************************************************** */
     356
     357    switch (marker) {
     358    case BLK_START_OF_BACKUP:
     359        strcpy(outstr, "BLK_START_OF_BACKUP");
     360        break;
     361    case BLK_START_OF_TAPE:
     362        strcpy(outstr, "BLK_START_OF_TAPE");
     363        break;
     364    case BLK_START_AN_AFIO_OR_SLICE:
     365        strcpy(outstr, "BLK_START_AN_AFIO_OR_SLICE");
     366        break;
     367    case BLK_STOP_AN_AFIO_OR_SLICE:
     368        strcpy(outstr, "BLK_STOP_AN_AFIO_OR_SLICE");
     369        break;
     370    case BLK_START_AFIOBALLS:
     371        strcpy(outstr, "BLK_START_AFIOBALLS");
     372        break;
     373    case BLK_STOP_AFIOBALLS:
     374        strcpy(outstr, "BLK_STOP_AFIOBALLS");
     375        break;
     376    case BLK_STOP_BIGGIEFILES:
     377        strcpy(outstr, "BLK_STOP_BIGGIEFILES");
     378        break;
     379    case BLK_START_A_NORMBIGGIE:
     380        strcpy(outstr, "BLK_START_A_NORMBIGGIE");
     381        break;
     382    case BLK_START_A_PIHBIGGIE:
     383        strcpy(outstr, "BLK_START_A_PIHBIGGIE");
     384        break;
     385    case BLK_START_EXTENDED_ATTRIBUTES:
     386        strcpy(outstr, "BLK_START_EXTENDED_ATTRIBUTES");
     387        break;
     388    case BLK_STOP_EXTENDED_ATTRIBUTES:
     389        strcpy(outstr, "BLK_STOP_EXTENDED_ATTRIBUTES");
     390        break;
     391    case BLK_START_EXAT_FILE:
     392        strcpy(outstr, "BLK_START_EXAT_FILE");
     393        break;
     394    case BLK_STOP_EXAT_FILE:
     395        strcpy(outstr, "BLK_STOP_EXAT_FILE");
     396        break;
     397    case BLK_START_BIGGIEFILES:
     398        strcpy(outstr, "BLK_START_BIGGIEFILES");
     399        break;
     400    case BLK_STOP_A_BIGGIE:
     401        strcpy(outstr, "BLK_STOP_A_BIGGIE");
     402        break;
     403    case BLK_END_OF_TAPE:
     404        strcpy(outstr, "BLK_END_OF_TAPE");
     405        break;
     406    case BLK_END_OF_BACKUP:
     407        strcpy(outstr, "BLK_END_OF_BACKUP");
     408        break;
     409    case BLK_ABORTED_BACKUP:
     410        strcpy(outstr, "BLK_ABORTED_BACKUP");
     411        break;
     412    case BLK_START_FILE:
     413        strcpy(outstr, "BLK_START_FILE");
     414        break;
     415    case BLK_STOP_FILE:
     416        strcpy(outstr, "BLK_STOP_FILE");
     417        break;
     418    default:
     419        sprintf(outstr, "BLK_UNKNOWN (%d)", marker);
     420        break;
     421    }
     422    return (outstr);
    433423}
    434424
     
    447437 * @note The returned string points to static storage and will be overwritten with each call.
    448438 */
    449 char *
    450 mountlist_entry_to_string (struct mountlist_itself *mountlist, int lino)
    451 {
    452 
    453     /*@ buffer ************************************************************/
    454   static char output[MAX_STR_LEN];
    455 
    456   assert(mountlist!=NULL);
    457 
    458   sprintf (output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device,
    459        mountlist->el[lino].mountpoint, mountlist->el[lino].format,
    460        mountlist->el[lino].size / 1024);
    461   return (output);
     439char *mountlist_entry_to_string(struct mountlist_itself *mountlist,
     440                                int lino)
     441{
     442
     443    /*@ buffer *********************************************************** */
     444    static char output[MAX_STR_LEN];
     445
     446    assert(mountlist != NULL);
     447
     448    sprintf(output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device,
     449            mountlist->el[lino].mountpoint, mountlist->el[lino].format,
     450            mountlist->el[lino].size / 1024);
     451    return (output);
    462452}
    463453
     
    475465 * @note The returned string points to static storage and will be overwritten with each call.
    476466 */
    477 char *
    478 number_of_disks_as_string (int noof_disks, char *label)
    479 {
    480 
    481     /*@ buffers **********************************************************/
    482   static char output[MAX_STR_LEN];
    483 
    484     /*@ char     *********************************************************/
    485   char p;
    486 
    487   assert(label!=NULL);
    488 
    489   if (noof_disks > 1)
    490     {
    491       p = 's';
    492     }
    493   else
    494     {
    495       p = ' ';
    496     }
    497   sprintf (output, "%d %s disk%c", noof_disks, label, p);
    498   while (strlen (output) < 14)
    499     {
    500       strcat (output, " ");
    501     }
    502   return (output);
     467char *number_of_disks_as_string(int noof_disks, char *label)
     468{
     469
     470    /*@ buffers ********************************************************* */
     471    static char output[MAX_STR_LEN];
     472
     473    /*@ char     ******************************************************** */
     474    char p;
     475
     476    assert(label != NULL);
     477
     478    if (noof_disks > 1) {
     479        p = 's';
     480    } else {
     481        p = ' ';
     482    }
     483    sprintf(output, "%d %s disk%c", noof_disks, label, p);
     484    while (strlen(output) < 14) {
     485        strcat(output, " ");
     486    }
     487    return (output);
    503488}
    504489
     
    512497 * @note The returned value points to static strorage that will be overwritten with each call.
    513498 */
    514 char *
    515 number_to_text (int i)
    516 {
    517 
    518     /*@ buffers ******************************************************/
    519   static char output[MAX_STR_LEN];
    520 
    521 
    522     /*@ end vars ****************************************************/
    523 
    524   switch (i)
    525     {
    526     case 0:
    527       strcpy (output, "zero");
    528       break;
    529     case 1:
    530       strcpy (output, "one");
    531       break;
    532     case 2:
    533       strcpy (output, "two");
    534       break;
    535     case 3:
    536       strcpy (output, "three");
    537       break;
    538     case 4:
    539       strcpy (output, "four");
    540       break;
    541     case 5:
    542       strcpy (output, "five");
    543       break;
    544     case 6:
    545       strcpy (output, "six");
    546       break;
    547     case 7:
    548       strcpy (output, "seven");
    549       break;
    550     case 8:
    551       strcpy (output, "eight");
    552       break;
    553     case 9:
    554       strcpy (output, "nine");
    555     case 10:
    556       strcpy (output, "ten");
    557     default:
    558       sprintf (output, "%d", i);
    559     }
    560   return (output);
     499char *number_to_text(int i)
     500{
     501
     502    /*@ buffers ***************************************************** */
     503    static char output[MAX_STR_LEN];
     504
     505
     506    /*@ end vars *************************************************** */
     507
     508    switch (i) {
     509    case 0:
     510        strcpy(output, "zero");
     511        break;
     512    case 1:
     513        strcpy(output, "one");
     514        break;
     515    case 2:
     516        strcpy(output, "two");
     517        break;
     518    case 3:
     519        strcpy(output, "three");
     520        break;
     521    case 4:
     522        strcpy(output, "four");
     523        break;
     524    case 5:
     525        strcpy(output, "five");
     526        break;
     527    case 6:
     528        strcpy(output, "six");
     529        break;
     530    case 7:
     531        strcpy(output, "seven");
     532        break;
     533    case 8:
     534        strcpy(output, "eight");
     535        break;
     536    case 9:
     537        strcpy(output, "nine");
     538    case 10:
     539        strcpy(output, "ten");
     540    default:
     541        sprintf(output, "%d", i);
     542    }
     543    return (output);
    561544}
    562545
     
    571554 * @param value The value to replace @p token.
    572555 */
    573 void
    574 resolve_naff_tokens (char *output, char *ip, char *value, char *token)
    575 {
    576     /*@ buffers ****/
    577   char *input;
    578 
    579     /*@ pointers **/
    580   char *p;
    581 
    582   input = malloc(2000);
    583   assert_string_is_neither_NULL_nor_zerolength(ip);
    584   assert_string_is_neither_NULL_nor_zerolength(token);
    585   assert(value!=NULL);
    586 
    587   strcpy (output, ip);      /* just in case the token doesn't appear in string at all */
    588   for (strcpy (input, ip); strstr (input, token); strcpy (input, output))
    589     {
    590       strcpy (output, input);
    591       p = strstr (output, token);
    592       *p = '\0';
    593       strcat (output, value);
    594       p = strstr (input, token) + strlen (token);
    595       strcat (output, p);
    596     }
    597   paranoid_free(input);
     556void resolve_naff_tokens(char *output, char *ip, char *value, char *token)
     557{
     558    /*@ buffers *** */
     559    char *input;
     560
     561    /*@ pointers * */
     562    char *p;
     563
     564    input = malloc(2000);
     565    assert_string_is_neither_NULL_nor_zerolength(ip);
     566    assert_string_is_neither_NULL_nor_zerolength(token);
     567    assert(value != NULL);
     568
     569    strcpy(output, ip);         /* just in case the token doesn't appear in string at all */
     570    for (strcpy(input, ip); strstr(input, token); strcpy(input, output)) {
     571        strcpy(output, input);
     572        p = strstr(output, token);
     573        *p = '\0';
     574        strcat(output, value);
     575        p = strstr(input, token) + strlen(token);
     576        strcat(output, p);
     577    }
     578    paranoid_free(input);
    598579}
    599580
     
    617598 * @note The returned value points to static storage and will be overwritten with each call.
    618599 */
    619 char *
    620 slice_fname (long bigfileno, long sliceno, char *path, char *s)
    621 {
    622 
    623     /*@ buffers *****************************************************/
    624   static char output[MAX_STR_LEN];
    625   static char suffix[MAX_STR_LEN];
    626 
    627     /*@ end vars ****************************************************/
    628 
    629   assert_string_is_neither_NULL_nor_zerolength(path);
    630   if (s[0] != '\0')
    631     {
    632       sprintf (suffix, ".%s", s);
    633     }
    634   else
    635     {
    636       suffix[0] = '\0';
    637     }
    638   sprintf (output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno,
    639        suffix);
    640   return (output);
     600char *slice_fname(long bigfileno, long sliceno, char *path, char *s)
     601{
     602
     603    /*@ buffers **************************************************** */
     604    static char output[MAX_STR_LEN];
     605    static char suffix[MAX_STR_LEN];
     606
     607    /*@ end vars *************************************************** */
     608
     609    assert_string_is_neither_NULL_nor_zerolength(path);
     610    if (s[0] != '\0') {
     611        sprintf(suffix, ".%s", s);
     612    } else {
     613        suffix[0] = '\0';
     614    }
     615    sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno,
     616            suffix);
     617    return (output);
    641618}
    642619
     
    650627 * @return The character for this iteration.
    651628 */
    652 int
    653 special_dot_char (int i)
    654 {
    655   switch (i % 4)
    656     {
    657     case 0:
    658       return ('/');
    659     case 1:
    660       return ('-');
    661     case 2:
    662       return ('\\');
    663     case 3:
    664       return ('|');
    665     default:
    666       return ('.');
    667     }
    668   return ('.');
     629int special_dot_char(int i)
     630{
     631    switch (i % 4) {
     632    case 0:
     633        return ('/');
     634    case 1:
     635        return ('-');
     636    case 2:
     637        return ('\\');
     638    case 3:
     639        return ('|');
     640    default:
     641        return ('.');
     642    }
     643    return ('.');
    669644}
    670645
     
    682657 */
    683658bool
    684 spread_flaws_across_three_lines (char *flaws_str, char *flaws_str_A,
    685                  char *flaws_str_B, char *flaws_str_C,
    686                  int res)
    687 {
    688 
    689     /*@ int **************************************************************/
    690   int i = 0;
    691 
    692     /*@ initialize *******************************************************/
    693   assert(flaws_str_A!=NULL);
    694   assert(flaws_str_B!=NULL);
    695   assert(flaws_str_C!=NULL);
    696   assert(flaws_str!=NULL);
    697 
    698   flaws_str_A[0] = flaws_str_B[0] = flaws_str_C[0] = '\0';
    699 
    700 
    701   if (!res && !strlen (flaws_str))
    702     {
    703       return (TRUE);
    704     }
    705   if (strlen (flaws_str) > 0)
    706     {
    707       sprintf (flaws_str_A, "%s", flaws_str + 1);
    708     }
    709   if (strlen (flaws_str_A) >= 74)
    710     {
    711       for (i = 74; flaws_str_A[i] != ' '; i--);
    712       strcpy (flaws_str_B, flaws_str_A + i + 1);
    713       flaws_str_A[i] = '\0';
    714     }
    715   if (strlen (flaws_str_B) >= 74)
    716     {
    717       for (i = 74; flaws_str_B[i] != ' '; i--);
    718       strcpy (flaws_str_C, flaws_str_B + i + 1);
    719       flaws_str_B[i] = '\0';
    720     }
    721   if (res)
    722     {
    723       return (FALSE);
    724     }
    725   else
    726     {
    727       return (TRUE);
    728     }
     659spread_flaws_across_three_lines(char *flaws_str, char *flaws_str_A,
     660                                char *flaws_str_B, char *flaws_str_C,
     661                                int res)
     662{
     663
     664    /*@ int ************************************************************* */
     665    int i = 0;
     666
     667    /*@ initialize ****************************************************** */
     668    assert(flaws_str_A != NULL);
     669    assert(flaws_str_B != NULL);
     670    assert(flaws_str_C != NULL);
     671    assert(flaws_str != NULL);
     672
     673    flaws_str_A[0] = flaws_str_B[0] = flaws_str_C[0] = '\0';
     674
     675
     676    if (!res && !strlen(flaws_str)) {
     677        return (TRUE);
     678    }
     679    if (strlen(flaws_str) > 0) {
     680        sprintf(flaws_str_A, "%s", flaws_str + 1);
     681    }
     682    if (strlen(flaws_str_A) >= 74) {
     683        for (i = 74; flaws_str_A[i] != ' '; i--);
     684        strcpy(flaws_str_B, flaws_str_A + i + 1);
     685        flaws_str_A[i] = '\0';
     686    }
     687    if (strlen(flaws_str_B) >= 74) {
     688        for (i = 74; flaws_str_B[i] != ' '; i--);
     689        strcpy(flaws_str_C, flaws_str_B + i + 1);
     690        flaws_str_B[i] = '\0';
     691    }
     692    if (res) {
     693        return (FALSE);
     694    } else {
     695        return (TRUE);
     696    }
    729697}
    730698
     
    740708 * there are any in the middle those will be sorted ASCIIbetically.
    741709 */
    742 int
    743 strcmp_inc_numbers (char *stringA, char *stringB)
    744 {
    745     /*@ int **********************************************************/
    746   int i;
    747   int start_of_numbers_in_A;
    748   int start_of_numbers_in_B;
    749   int res;
    750 
    751     /*@ long ********************************************************/
    752   long numA;
    753   long numB;
    754 
    755     /*@ end vars ****************************************************/
    756   assert(stringA!=NULL);
    757   assert(stringB!=NULL);
    758 
    759   if (strlen (stringA) == strlen (stringB))
    760     {
    761       return (strcmp (stringA, stringB));
    762     }
    763   for (i = (int) strlen (stringA); i > 0 && isdigit (stringA[i - 1]); i--);
    764   if (i == (int) strlen (stringA))
    765     {
    766       return (strcmp (stringA, stringB));
    767     }
    768   start_of_numbers_in_A = i;
    769   for (i = (int) strlen (stringB); i > 0 && isdigit (stringB[i - 1]); i--);
    770   if (i == (int) strlen (stringB))
    771     {
    772       return (strcmp (stringA, stringB));
    773     }
    774   start_of_numbers_in_B = i;
    775   if (start_of_numbers_in_A != start_of_numbers_in_B)
    776     {
    777       return (strcmp (stringA, stringB));
    778     }
    779   res = strncmp (stringA, stringB, (size_t) i);
    780   if (res)
    781     {
    782       return (res);
    783     }
    784   numA = atol (stringA + start_of_numbers_in_A);
    785   numB = atol (stringB + start_of_numbers_in_B);
    786   /*
    787      sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB);
    788      log_to_screen(tmp);
    789    */
    790   return ((int) (numA - numB));
     710int strcmp_inc_numbers(char *stringA, char *stringB)
     711{
     712    /*@ int ********************************************************* */
     713    int i;
     714    int start_of_numbers_in_A;
     715    int start_of_numbers_in_B;
     716    int res;
     717
     718    /*@ long ******************************************************* */
     719    long numA;
     720    long numB;
     721
     722    /*@ end vars *************************************************** */
     723    assert(stringA != NULL);
     724    assert(stringB != NULL);
     725
     726    if (strlen(stringA) == strlen(stringB)) {
     727        return (strcmp(stringA, stringB));
     728    }
     729    for (i = (int) strlen(stringA); i > 0 && isdigit(stringA[i - 1]); i--);
     730    if (i == (int) strlen(stringA)) {
     731        return (strcmp(stringA, stringB));
     732    }
     733    start_of_numbers_in_A = i;
     734    for (i = (int) strlen(stringB); i > 0 && isdigit(stringB[i - 1]); i--);
     735    if (i == (int) strlen(stringB)) {
     736        return (strcmp(stringA, stringB));
     737    }
     738    start_of_numbers_in_B = i;
     739    if (start_of_numbers_in_A != start_of_numbers_in_B) {
     740        return (strcmp(stringA, stringB));
     741    }
     742    res = strncmp(stringA, stringB, (size_t) i);
     743    if (res) {
     744        return (res);
     745    }
     746    numA = atol(stringA + start_of_numbers_in_A);
     747    numB = atol(stringB + start_of_numbers_in_B);
     748    /*
     749       sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB);
     750       log_to_screen(tmp);
     751     */
     752    return ((int) (numA - numB));
    791753}
    792754
     
    801763 * @note The returned string points to static storage that will be overwritten with each call.
    802764 */
    803 char *
    804 strip_afio_output_line (char *input)
    805 {
    806     /*@ buffer *******************************************************/
    807   static char output[MAX_STR_LEN];
    808 
    809     /*@ pointers *****************************************************/
    810   char *p;
    811   char *q;
    812     /*@ end vars ****************************************************/
    813 
    814   assert(input!=NULL);
    815   strcpy (output, input);
    816   p = strchr (input, '\"');
    817   if (p)
    818     {
    819       q = strchr (++p, '\"');
    820       if (q)
    821     {
    822       strcpy (output, p);
    823       *(strchr (output, '\"')) = '\0';
    824     }
    825     }
    826   return (output);
     765char *strip_afio_output_line(char *input)
     766{
     767    /*@ buffer ****************************************************** */
     768    static char output[MAX_STR_LEN];
     769
     770    /*@ pointers **************************************************** */
     771    char *p;
     772    char *q;
     773    /*@ end vars *************************************************** */
     774
     775    assert(input != NULL);
     776    strcpy(output, input);
     777    p = strchr(input, '\"');
     778    if (p) {
     779        q = strchr(++p, '\"');
     780        if (q) {
     781            strcpy(output, p);
     782            *(strchr(output, '\"')) = '\0';
     783        }
     784    }
     785    return (output);
    827786}
    828787
     
    834793 * @param in_out The string to strip spaces/control characters from (modified).
    835794 */
    836 void
    837 strip_spaces (char *in_out)
    838 {
    839     /*@ buffers ******************************************************/
    840   char *tmp;
    841 
    842     /*@ pointers *****************************************************/
    843   char *p;
    844 
    845     /*@ int *********************************************************/
    846   int i;
    847   int original_incoming_length;
    848 
    849     /*@ end vars ****************************************************/
    850 
    851   assert(in_out!=NULL);
    852   malloc_string(tmp);
    853   original_incoming_length = (int) strlen(in_out);
    854   for (i = 0; in_out[i] <= ' ' && i < (int) strlen (in_out); i++);
    855   strcpy (tmp, in_out + i);
    856   for (i = (int) strlen (tmp); i>0 && tmp[i - 1] <= 32; i--);
    857   tmp[i] = '\0';
    858   for (i = 0; i < original_incoming_length && MAX_STR_LEN; i++)
    859     {
    860       in_out[i] = ' ';
    861     }
    862   in_out[i] = '\0';
    863   i = 0;
    864   p = tmp;
    865   while (*p != '\0')
    866     {
    867       in_out[i] = *(p++);
    868       in_out[i + 1] = '\0';
    869       if (in_out[i] < 32 && i > 0)
    870     {
    871       if (in_out[i] == 8)
    872         {
    873           i--;
    874         }
    875       else if (in_out[i] == 9)
    876         {
    877           in_out[i++] = ' ';
    878         }
    879       else if (in_out[i] == '\r') // added 1st October 2003 -- FIXME
    880         {
    881               strcpy(tmp, in_out+i);
    882           strcpy(in_out,tmp);
    883           i=-1;
    884           continue;
    885         }
    886       else if (in_out[i] == '\t')
    887         {
    888           for (i++; i % 5; i++);
    889         }
    890       else if (in_out[i] >= 10 && in_out[i] <= 13)
    891         {
    892           break;
    893         }
    894       else
    895         {
    896           i--;
    897         }
    898     }
    899       else
    900     {
    901       i++;
    902     }
    903     }
    904   in_out[i] = '\0';
    905   paranoid_free(tmp);
     795void strip_spaces(char *in_out)
     796{
     797    /*@ buffers ***************************************************** */
     798    char *tmp;
     799
     800    /*@ pointers **************************************************** */
     801    char *p;
     802
     803    /*@ int ******************************************************** */
     804    int i;
     805    int original_incoming_length;
     806
     807    /*@ end vars *************************************************** */
     808
     809    assert(in_out != NULL);
     810    malloc_string(tmp);
     811    original_incoming_length = (int) strlen(in_out);
     812    for (i = 0; in_out[i] <= ' ' && i < (int) strlen(in_out); i++);
     813    strcpy(tmp, in_out + i);
     814    for (i = (int) strlen(tmp); i > 0 && tmp[i - 1] <= 32; i--);
     815    tmp[i] = '\0';
     816    for (i = 0; i < original_incoming_length && MAX_STR_LEN; i++) {
     817        in_out[i] = ' ';
     818    }
     819    in_out[i] = '\0';
     820    i = 0;
     821    p = tmp;
     822    while (*p != '\0') {
     823        in_out[i] = *(p++);
     824        in_out[i + 1] = '\0';
     825        if (in_out[i] < 32 && i > 0) {
     826            if (in_out[i] == 8) {
     827                i--;
     828            } else if (in_out[i] == 9) {
     829                in_out[i++] = ' ';
     830            } else if (in_out[i] == '\r')   // added 1st October 2003 -- FIXME
     831            {
     832                strcpy(tmp, in_out + i);
     833                strcpy(in_out, tmp);
     834                i = -1;
     835                continue;
     836            } else if (in_out[i] == '\t') {
     837                for (i++; i % 5; i++);
     838            } else if (in_out[i] >= 10 && in_out[i] <= 13) {
     839                break;
     840            } else {
     841                i--;
     842            }
     843        } else {
     844            i++;
     845        }
     846    }
     847    in_out[i] = '\0';
     848    paranoid_free(tmp);
    906849/*  for(i=strlen(in_out); i>0 && in_out[i-1]<=32; i--) {in_out[i-1]='\0';} */
    907850}
     
    914857 * @return @p incoming.
    915858 */
    916 char *
    917 trim_empty_quotes (char *incoming)
    918 {
    919     /*@ buffer *******************************************************/
    920   static char outgoing[MAX_STR_LEN];
    921 
    922     /*@ end vars ****************************************************/
    923   assert(incoming!=NULL);
    924 
    925   if (incoming[0] == '\"' && incoming[strlen (incoming) - 1] == '\"')
    926     {
    927       strcpy (outgoing, incoming + 1);
    928       outgoing[strlen (outgoing) - 1] = '\0';
    929     }
    930   else
    931     {
    932       strcpy (outgoing, incoming);
    933     }
    934   return (outgoing);
     859char *trim_empty_quotes(char *incoming)
     860{
     861    /*@ buffer ****************************************************** */
     862    static char outgoing[MAX_STR_LEN];
     863
     864    /*@ end vars *************************************************** */
     865    assert(incoming != NULL);
     866
     867    if (incoming[0] == '\"' && incoming[strlen(incoming) - 1] == '\"') {
     868        strcpy(outgoing, incoming + 1);
     869        outgoing[strlen(outgoing) - 1] = '\0';
     870    } else {
     871        strcpy(outgoing, incoming);
     872    }
     873    return (outgoing);
    935874}
    936875
     
    943882 * @return @p partition.
    944883 */
    945 char *
    946 truncate_to_drive_name (char *partition)
    947 {
    948   int i = strlen (partition) - 1;
    949   char *c;
     884char *truncate_to_drive_name(char *partition)
     885{
     886    int i = strlen(partition) - 1;
     887    char *c;
    950888
    951889#ifdef __FreeBSD__
    952890
    953   if (islower (partition[i])) // BSD subpartition
    954       i--;
    955   if (partition[i - 1] == 's') {
    956       while (isdigit (partition[i]))
    957       i--;
    958       i--;
    959   }
    960   partition[i + 1] = '\0';
     891    if (islower(partition[i]))  // BSD subpartition
     892        i--;
     893    if (partition[i - 1] == 's') {
     894        while (isdigit(partition[i]))
     895            i--;
     896        i--;
     897    }
     898    partition[i + 1] = '\0';
    961899
    962900#else
    963901
    964   assert_string_is_neither_NULL_nor_zerolength(partition);
    965   /* first see if it's a devfs style device */
    966   c = strrchr(partition, '/');
    967   if (c && strncmp(c, "/part", 5) == 0) {
    968     /* yup it's devfs, return the "disc" path */
    969     strcpy(c + 1, "disc");
    970     return partition;
    971   }
    972 
    973   for (i = strlen (partition); isdigit (partition[i - 1]); i--)
    974     continue;
    975   if (partition[i - 1] == 'p' && isdigit (partition[i - 2]))
    976     {
    977       i--;
    978     }
    979   partition[i] = '\0';
     902    assert_string_is_neither_NULL_nor_zerolength(partition);
     903    /* first see if it's a devfs style device */
     904    c = strrchr(partition, '/');
     905    if (c && strncmp(c, "/part", 5) == 0) {
     906        /* yup it's devfs, return the "disc" path */
     907        strcpy(c + 1, "disc");
     908        return partition;
     909    }
     910
     911    for (i = strlen(partition); isdigit(partition[i - 1]); i--)
     912        continue;
     913    if (partition[i - 1] == 'p' && isdigit(partition[i - 2])) {
     914        i--;
     915    }
     916    partition[i] = '\0';
    980917
    981918#endif
    982919
    983   return partition;
     920    return partition;
    984921}
    985922
     
    996933 * @note The returned value points to static storage that will be overwritten with each call.
    997934 */
    998 char *
    999 turn_raid_level_number_to_string (int raid_level)
    1000 {
    1001 
    1002     /*@ buffer ***********************************************************/
    1003   static char output[MAX_STR_LEN];
    1004 
    1005 
    1006 
    1007   if (raid_level >= 0)
    1008     {
    1009       sprintf (output, " RAID %-2d ", raid_level);
    1010     }
    1011   else
    1012     {
    1013       sprintf (output, "Linear RAID");
    1014     }
    1015   return (output);
     935char *turn_raid_level_number_to_string(int raid_level)
     936{
     937
     938    /*@ buffer ********************************************************** */
     939    static char output[MAX_STR_LEN];
     940
     941
     942
     943    if (raid_level >= 0) {
     944        sprintf(output, " RAID %-2d ", raid_level);
     945    } else {
     946        sprintf(output, "Linear RAID");
     947    }
     948    return (output);
    1016949}
    1017950
     
    1033966int severity_of_difference(char *fn, char *out_reason)
    1034967{
    1035   int sev;
    1036   char *reason;
    1037   char *filename;
    1038 
    1039   malloc_string(reason);
    1040   malloc_string(filename);
     968    int sev;
     969    char *reason;
     970    char *filename;
     971
     972    malloc_string(reason);
     973    malloc_string(filename);
    1041974// out_reason might be null on purpose, so don't bomb if it is :) OK?
    1042   assert_string_is_neither_NULL_nor_zerolength(fn);
    1043   if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING)))
    1044     { strcpy(filename, fn+strlen(MNT_RESTORING)); }
    1045   else if (fn[0]!='/')
    1046     { sprintf(filename, "/%s", fn); }
    1047   else
    1048     { strcpy(filename, fn); }
    1049 
    1050   sev = 3;
    1051   sprintf(reason, "Changed since backup. Consider running a differential backup in a day or two.");
    1052   if (!strncmp(filename, "/var/", 5)) { sev = 2; sprintf(reason, "/var's contents will change regularly, inevitably."); }
    1053   if (!strncmp(filename, "/home", 5)) { sev = 2; sprintf(reason, "It's in your /home partiton. Therefore, it is important."); }
    1054   if (!strncmp(filename, "/usr/", 5)) { sev = 3; sprintf(reason, "You may have installed/removed software during the backup."); }
    1055   if (!strncmp(filename, "/etc/", 5)) { sev = 3; sprintf(reason, "Do not edit config files while backing up your PC."); }
    1056   if (!strcmp(filename, "/etc/adjtime") || !strcmp(filename, "/etc/mtab")) { sev = 1; sprintf(reason, "This file changes all the time. It's OK."); }
    1057   if (!strncmp(filename, "/root/", 6)) { sev = 3; sprintf(reason, "Were you compiling/editing something in /root?"); }
    1058   if (!strncmp(filename, "/root/.", 7)) { sev = 2; sprintf(reason, "Temp or 'dot' files changed in /root."); }
    1059   if (!strncmp(filename, "/var/lib/", 9)) { sev = 2; sprintf(reason, "Did you add/remove software during backing?"); }
    1060   if (!strncmp(filename, "/var/lib/rpm", 12)) { sev = 3; sprintf(reason, "Did you add/remove software during backing?"); }
    1061   if (!strncmp(filename, "/var/lib/slocate", 16)) { sev = 1; sprintf(reason, "The 'update' daemon ran during backup. This does not affect the integrity of your backup."); }
    1062   if (!strncmp(filename, "/var/log/", 9) || strstr(filename,"/.xsession") || !strcmp(filename+strlen(filename)-4, ".log")) { sev = 1; sprintf(reason, "Log files change frequently as the computer runs. Fret not."); }
    1063   if (!strncmp(filename, "/var/spool", 10)) { sev = 1; sprintf(reason, "Background processes or printers were active. This does not affect the integrity of your backup."); }
    1064   if (!strncmp(filename, "/var/spool/mail", 10)) { sev = 2; sprintf(reason, "Mail was sent/received during backup."); }
    1065   if (filename[strlen(filename)-1]== '~')
    1066     { sev = 1; sprintf(reason, "Backup copy of another file which was modified recently."); }
    1067   if (strstr(filename, "cache"))
    1068     { sev = 1; sprintf(reason, "Part of a cache of data. Caches change from time to time. Don't worry."); }
    1069   if (!strncmp(filename, "/var/run/", 9) || !strncmp(filename, "/var/lock", 8) || strstr(filename, "/.DCOPserver") || strstr(filename, "/.MCOP") || strstr(filename, "/.Xauthority"))
    1070     { sev = 1; sprintf(reason, "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."); }
    1071   if (out_reason) { strcpy(out_reason,reason); }
    1072   paranoid_free(filename);
    1073   paranoid_free(reason);
    1074   return(sev);
     975    assert_string_is_neither_NULL_nor_zerolength(fn);
     976    if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) {
     977        strcpy(filename, fn + strlen(MNT_RESTORING));
     978    } else if (fn[0] != '/') {
     979        sprintf(filename, "/%s", fn);
     980    } else {
     981        strcpy(filename, fn);
     982    }
     983
     984    sev = 3;
     985    sprintf(reason,
     986            "Changed since backup. Consider running a differential backup in a day or two.");
     987    if (!strncmp(filename, "/var/", 5)) {
     988        sev = 2;
     989        sprintf(reason,
     990                "/var's contents will change regularly, inevitably.");
     991    }
     992    if (!strncmp(filename, "/home", 5)) {
     993        sev = 2;
     994        sprintf(reason,
     995                "It's in your /home partiton. Therefore, it is important.");
     996    }
     997    if (!strncmp(filename, "/usr/", 5)) {
     998        sev = 3;
     999        sprintf(reason,
     1000                "You may have installed/removed software during the backup.");
     1001    }
     1002    if (!strncmp(filename, "/etc/", 5)) {
     1003        sev = 3;
     1004        sprintf(reason,
     1005                "Do not edit config files while backing up your PC.");
     1006    }
     1007    if (!strcmp(filename, "/etc/adjtime")
     1008        || !strcmp(filename, "/etc/mtab")) {
     1009        sev = 1;
     1010        sprintf(reason, "This file changes all the time. It's OK.");
     1011    }
     1012    if (!strncmp(filename, "/root/", 6)) {
     1013        sev = 3;
     1014        sprintf(reason, "Were you compiling/editing something in /root?");
     1015    }
     1016    if (!strncmp(filename, "/root/.", 7)) {
     1017        sev = 2;
     1018        sprintf(reason, "Temp or 'dot' files changed in /root.");
     1019    }
     1020    if (!strncmp(filename, "/var/lib/", 9)) {
     1021        sev = 2;
     1022        sprintf(reason, "Did you add/remove software during backing?");
     1023    }
     1024    if (!strncmp(filename, "/var/lib/rpm", 12)) {
     1025        sev = 3;
     1026        sprintf(reason, "Did you add/remove software during backing?");
     1027    }
     1028    if (!strncmp(filename, "/var/lib/slocate", 16)) {
     1029        sev = 1;
     1030        sprintf(reason,
     1031                "The 'update' daemon ran during backup. This does not affect the integrity of your backup.");
     1032    }
     1033    if (!strncmp(filename, "/var/log/", 9)
     1034        || strstr(filename, "/.xsession")
     1035        || !strcmp(filename + strlen(filename) - 4, ".log")) {
     1036        sev = 1;
     1037        sprintf(reason,
     1038                "Log files change frequently as the computer runs. Fret not.");
     1039    }
     1040    if (!strncmp(filename, "/var/spool", 10)) {
     1041        sev = 1;
     1042        sprintf(reason,
     1043                "Background processes or printers were active. This does not affect the integrity of your backup.");
     1044    }
     1045    if (!strncmp(filename, "/var/spool/mail", 10)) {
     1046        sev = 2;
     1047        sprintf(reason, "Mail was sent/received during backup.");
     1048    }
     1049    if (filename[strlen(filename) - 1] == '~') {
     1050        sev = 1;
     1051        sprintf(reason,
     1052                "Backup copy of another file which was modified recently.");
     1053    }
     1054    if (strstr(filename, "cache")) {
     1055        sev = 1;
     1056        sprintf(reason,
     1057                "Part of a cache of data. Caches change from time to time. Don't worry.");
     1058    }
     1059    if (!strncmp(filename, "/var/run/", 9)
     1060        || !strncmp(filename, "/var/lock", 8)
     1061        || strstr(filename, "/.DCOPserver") || strstr(filename, "/.MCOP")
     1062        || strstr(filename, "/.Xauthority")) {
     1063        sev = 1;
     1064        sprintf(reason,
     1065                "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");
     1066    }
     1067    if (out_reason) {
     1068        strcpy(out_reason, reason);
     1069    }
     1070    paranoid_free(filename);
     1071    paranoid_free(reason);
     1072    return (sev);
    10751073}
    10761074
     
    10841082 * @return The return value of strcmp().
    10851083 */
    1086 int compare_two_filelist_entries(void*va,void*vb)
    1087 {
    1088   static int res;
    1089   struct s_filelist_entry *fa, *fb;
    1090 
    1091   assert(va!=NULL);
    1092   assert(vb!=NULL);
    1093   fa = (struct s_filelist_entry*)va;
    1094   fb = (struct s_filelist_entry*)vb;
    1095   res = strcmp(fa->filename, fb->filename);
    1096   return(res);
     1084int compare_two_filelist_entries(void *va, void *vb)
     1085{
     1086    static int res;
     1087    struct s_filelist_entry *fa, *fb;
     1088
     1089    assert(va != NULL);
     1090    assert(vb != NULL);
     1091    fa = (struct s_filelist_entry *) va;
     1092    fb = (struct s_filelist_entry *) vb;
     1093    res = strcmp(fa->filename, fb->filename);
     1094    return (res);
    10971095}
    10981096
     
    11131111 * @note The returned string points to static storage that will be overwritten with each call.
    11141112 */
    1115 char *
    1116 percent_media_full_comment (struct s_bkpinfo *bkpinfo)
    1117 {
    1118     /*@ int ************************************************/
    1119   int percentage;
    1120   int j;
    1121 
    1122     /*@ buffers ********************************************/
    1123   static char outstr[MAX_STR_LEN];
    1124   char *pos_w_commas, *tmp;
    1125 
    1126   assert(bkpinfo!=NULL);
    1127   malloc_string(pos_w_commas);
    1128   malloc_string(tmp);
    1129   sprintf(tmp, "%lld", g_tape_posK);
    1130   strcpy(pos_w_commas, commarize(tmp));
    1131 
    1132 
    1133 
    1134   if (bkpinfo->media_size[g_current_media_number]<=0)
     1113char *percent_media_full_comment(struct s_bkpinfo *bkpinfo)
     1114{
     1115    /*@ int *********************************************** */
     1116    int percentage;
     1117    int j;
     1118
     1119    /*@ buffers ******************************************* */
     1120    static char outstr[MAX_STR_LEN];
     1121    char *pos_w_commas, *tmp;
     1122
     1123    assert(bkpinfo != NULL);
     1124    malloc_string(pos_w_commas);
     1125    malloc_string(tmp);
     1126    sprintf(tmp, "%lld", g_tape_posK);
     1127    strcpy(pos_w_commas, commarize(tmp));
     1128
     1129
     1130
     1131    if (bkpinfo->media_size[g_current_media_number] <= 0)
    11351132//    { fatal_error( "percentage_media_full_comment() - unknown media size"); }
    1136     {
    1137       sprintf( outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
    1138       return( outstr );
    1139     }
     1133    {
     1134        sprintf(outstr, "Volume %d: %s kilobytes archived so far",
     1135                g_current_media_number, pos_w_commas);
     1136        return (outstr);
     1137    }
    11401138
    11411139/* update screen */
    1142   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1143     {
    1144       percentage = (int) (g_tape_posK / 10 / bkpinfo->media_size[g_current_media_number]);
    1145       if (percentage > 100)
    1146     {
    1147       percentage = 100;
    1148     }
    1149       sprintf (outstr, "Volume %d: [", g_current_media_number);
    1150     }
    1151   else
    1152     {
    1153       percentage =
    1154     (int) (space_occupied_by_cd (bkpinfo->scratchdir) * 100 / 1024 /
    1155            bkpinfo->media_size[g_current_media_number]);
    1156       sprintf (outstr, "%s %d: [", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    1157     }
    1158   for (j = 0; j < percentage; j += 5)
    1159     {
    1160       strcat (outstr, "*");
    1161     }
    1162   for (; j < 100; j += 5)
    1163     {
    1164       strcat (outstr, ".");
    1165     }
    1166   j = (int) strlen (outstr);
    1167   sprintf (outstr + j, "] %d%% used", percentage);
    1168   paranoid_free(pos_w_commas);
    1169   paranoid_free(tmp);
    1170   return (outstr);
     1140    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1141        percentage =
     1142            (int) (g_tape_posK / 10 /
     1143                   bkpinfo->media_size[g_current_media_number]);
     1144        if (percentage > 100) {
     1145            percentage = 100;
     1146        }
     1147        sprintf(outstr, "Volume %d: [", g_current_media_number);
     1148    } else {
     1149        percentage =
     1150            (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 /
     1151                   bkpinfo->media_size[g_current_media_number]);
     1152        sprintf(outstr, "%s %d: [",
     1153                media_descriptor_string(bkpinfo->backup_media_type),
     1154                g_current_media_number);
     1155    }
     1156    for (j = 0; j < percentage; j += 5) {
     1157        strcat(outstr, "*");
     1158    }
     1159    for (; j < 100; j += 5) {
     1160        strcat(outstr, ".");
     1161    }
     1162    j = (int) strlen(outstr);
     1163    sprintf(outstr + j, "] %d%% used", percentage);
     1164    paranoid_free(pos_w_commas);
     1165    paranoid_free(tmp);
     1166    return (outstr);
    11711167}
    11721168
     
    11791175char *media_descriptor_string(t_bkptype type_of_bkp)
    11801176{
    1181   static char *type_of_backup=NULL;
    1182  
    1183   if (!type_of_backup)
    1184     { malloc_string(type_of_backup); }
    1185    
    1186   switch(type_of_bkp)
    1187     {
     1177    static char *type_of_backup = NULL;
     1178
     1179    if (!type_of_backup) {
     1180        malloc_string(type_of_backup);
     1181    }
     1182
     1183    switch (type_of_bkp) {
    11881184    case dvd:
    11891185        strcpy(type_of_backup, "DVD");
     
    12131209        strcpy(type_of_backup, "ISO");
    12141210    }
    1215   return(type_of_backup);
     1211    return (type_of_backup);
    12161212}
    12171213
Note: See TracChangeset for help on using the changeset viewer.