Changeset 1168 in MondoRescue


Ignore:
Timestamp:
Feb 15, 2007, 12:27:39 AM (17 years ago)
Author:
Bruno Cornec
Message:

strip_spaces => mr_strip_spaces in mr_str.c and corrected at the same time :-)

Location:
branches/stable
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-archive.c

    r1164 r1168  
    12451245if=/dev/urandom bs=16 count=1 2> /dev/null | \
    12461246hexdump | tr -s ' ' '0' | head -n1"));
    1247     strip_spaces(g_serial_string);
     1247    mr_strip_spaces(g_serial_string);
    12481248    strcat(g_serial_string, "...word.");
    12491249    mr_msg(2, "g_serial_string = '%s'", g_serial_string);
  • branches/stable/mondo/src/common/libmondo-devices.c

    r1166 r1168  
    1919#include "mr_mem.h"
    2020#include "mr_msg.h"
     21#include "mr_str.h"
    2122
    2223#include <sys/ioctl.h>
     
    11081109
    11091110    FILE *pin = NULL;
    1110     bool retval;
     1111    bool retval = FALSE;
    11111112    size_t n = 0;
    11121113    assert_string_is_neither_NULL_nor_zerolength(format);
     
    11271128    if (!pin) {
    11281129        log_OS_error("Unable to read good formats");
    1129         retval = FALSE;
    11301130    } else {
    11311131        mr_getline(&good_formats, &n , pin);
     
    11331133            log_OS_error("Cannot pclose good formats");
    11341134        }
    1135         strip_spaces(good_formats);
     1135        mr_strip_spaces(good_formats);
    11361136        // " ntfs 7 " -- um, cheating much? :)
    11371137        mr_asprintf(&tmp, " %s swap lvm raid ntfs 7 ",good_formats);
     
    11411141        if (strstr(good_formats, format_sz)) {
    11421142            retval = TRUE;
    1143         } else {
    1144             retval = FALSE;
    11451143        }
    11461144        mr_free(good_formats);
     
    17041702            // check whether already mounted - we better remove
    17051703            // surrounding spaces and trailing '/' for this
    1706             /* BERLIOS: Useless
    1707             strip_spaces(bkpinfo->nfs_mount);
    1708             */
     1704            mr_strip_spaces(bkpinfo->nfs_mount);
    17091705            if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/')
    17101706                bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0';
     
    17681764        mr_free(tmp);
    17691765        // check whether writable - we better remove surrounding spaces for this
    1770         strip_spaces(bkpinfo->nfs_remote_dir);
     1766        mr_strip_spaces(bkpinfo->nfs_remote_dir);
    17711767        mr_asprintf(&command, "echo hi > '%s/%s/.dummy.txt'", bkpinfo->isodir,
    17721768                bkpinfo->nfs_remote_dir);
     
    17861782            mr_free(tmp);
    17871783            // check whether writable - we better remove surrounding space s for this
    1788             strip_spaces(bkpinfo->nfs_remote_dir);
     1784            mr_strip_spaces(bkpinfo->nfs_remote_dir);
    17891785
    17901786            mr_free(command);
     
    22932289    for (mr_getline(&current_drive, &n, pdrives); !feof(pdrives);
    22942290         mr_getline(&current_drive, &n, pdrives)) {
    2295         strip_spaces(current_drive);
     2291        mr_strip_spaces(current_drive);
    22962292        log_it("looking at drive %s's MBR", current_drive);
    22972293        if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
  • branches/stable/mondo/src/common/libmondo-fork.c

    r1151 r1168  
    55#include "mr_mem.h"
    66#include "mr_msg.h"
     7#include "mr_str.h"
     8
    79#include "mondostructures.h"
    810#include "libmondo-fork.h"
     
    5557        log_OS_error("Unable to popen call");
    5658    }
    57     strip_spaces(result);
     59    mr_strip_spaces(result);
    5860    mr_free(tmp);
    5961    return (result);
     
    246248            }
    247249            /* end of patch */
    248             strip_spaces(incoming);
     250            mr_strip_spaces(incoming);
    249251            if ((res == 0 && log_if_success)
    250252                || (res != 0 && log_if_failure)) {
  • branches/stable/mondo/src/common/libmondo-raid.c

    r1123 r1168  
    442442    for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    443443         fgets(incoming, MAX_STR_LEN - 1, fin)) {
    444         strip_spaces(incoming);
     444        mr_strip_spaces(incoming);
    445445        p = strchr(incoming, ' ');
    446446        if (strlen(incoming) < 3 || incoming[0] == '#' || !p) {
  • branches/stable/mondo/src/common/libmondo-string-EXT.h

    r831 r1168  
    2727extern int strcmp_inc_numbers(char *stringA, char *stringB);
    2828extern char *strip_afio_output_line(char *input);
    29 extern void strip_spaces(char *in_out);
    3029extern char *trim_empty_quotes(char *incoming);
    3130extern char *truncate_to_drive_name(char *partition);
  • branches/stable/mondo/src/common/libmondo-string.c

    r1148 r1168  
    99#include "my-stuff.h"
    1010#include "mr_mem.h"
     11#include "mr_str.h"
     12
    1113#include "mondostructures.h"
    1214#include "libmondo-string.h"
     
    98100    for (p = in_out; *p == ' '; p++);
    99101    strcpy(scratch, p);
    100     strip_spaces (scratch);
     102    mr_strip_spaces (scratch);
    101103    len = (int) strlen(scratch);
    102104    mid = width / 2;
     
    737739
    738740
    739 
    740 /**
    741  * Remove all characters whose ASCII value is less than or equal to 32
    742  * (spaces and control characters) from both sides of @p in_out.
    743  * @param in_out The string to strip spaces/control characters from (modified).
    744  */
    745 void strip_spaces(char *in_out)
    746 {
    747     /*@ buffers ***************************************************** */
    748     char *tmp = NULL;
    749 
    750     /*@ pointers **************************************************** */
    751     char *p;
    752 
    753     /*@ int ******************************************************** */
    754     int i;
    755     int j;
    756     int original_incoming_length;
    757 
    758     /*@ end vars *************************************************** */
    759 
    760     assert(in_out != NULL);
    761     original_incoming_length = (int)strlen(in_out);
    762 
    763     for (i = 0; (in_out[i] <= ' ' || in_out[i] == '\t' || in_out[i] == '\r')
    764                     && i < original_incoming_length ; i++);
    765     for (j = 0; in_out[i] > ' ' && in_out[i] != '\t' && in_out[i] != '\r'
    766                     && i < original_incoming_length ; i++, j++) {
    767         in_out[j] = in_out[i];
    768     }
    769     in_out[j] = '\0';
    770 
    771     /* BERLIOS: Old code
    772     malloc_string(tmp);
    773     strcpy(tmp, in_out + i);
    774     for (i = (int) strlen(tmp); i > 0 && tmp[i - 1] <= 32; i--);
    775     tmp[i] = '\0';
    776     for (i = 0; i < original_incoming_length && MAX_STR_LEN; i++) {
    777         in_out[i] = ' ';
    778     }
    779     in_out[i] = '\0';
    780     i = 0;
    781     p = tmp;
    782     while (*p != '\0') {
    783         in_out[i] = *p;
    784         p++;
    785         in_out[i + 1] = '\0';
    786         if (in_out[i] < 32 && i > 0) {
    787             if (in_out[i] == 8) {
    788                 i--;
    789             } else if (in_out[i] == 9) {
    790                 in_out[i++] = ' ';
    791             } else if (in_out[i] == '\r')   // added 1st October 2003 -- FIXME
    792             {
    793                 strcpy(tmp, in_out + i);
    794                 strcpy(in_out, tmp);
    795                 i = -1;
    796                 continue;
    797             } else if (in_out[i] == '\t') {
    798                 for (i++; i % 5; i++);
    799             } else if (in_out[i] >= 10 && in_out[i] <= 13) {
    800                 break;
    801             } else {
    802                 i--;
    803             }
    804         } else {
    805             i++;
    806         }
    807     }
    808     in_out[i] = '\0';
    809     mr_free(tmp);
    810     */
    811 }
    812 
    813 
    814741/**
    815742 * If there are double quotes "" around @p incoming then remove them.
  • branches/stable/mondo/src/common/libmondo-string.h

    r831 r1168  
    2222int strcmp_inc_numbers(char *stringA, char *stringB);
    2323char *strip_afio_output_line(char *input);
    24 void strip_spaces(char *in_out);
    2524char *trim_empty_quotes(char *incoming);
    2625char *truncate_to_drive_name(char *partition);
  • branches/stable/mondo/src/common/newt-specific.c

    r1123 r1168  
    2121#include "mr_mem.h"
    2222#include "mr_msg.h"
     23#include "mr_str.h"
     24
    2325#include "mondostructures.h"
    2426#include "newt-specific.h"
     
    466468                    (void) fgets(err_log_lines[i], MAX_NEWT_COMMENT_LEN,
    467469                                 fin);
    468                     strip_spaces(err_log_lines[i]);
     470                    mr_strip_spaces(err_log_lines[i]);
    469471                    if (!strncmp(err_log_lines[i], "root:", 5)) {
    470472                        strcpy(tmp, err_log_lines[i] + 6);
     
    12591261                printf(")\n--> ");
    12601262                (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);
    1261                 strip_spaces(outstr);
     1263                mr_strip_spaces(outstr);
    12621264                for (i = 0; possible_responses[i]; i++) {
    12631265                    if (!strcmp(possible_responses[i], outstr)) {
  • branches/stable/mondo/src/include/mr_str.h

    r1087 r1168  
    1414extern inline char *mr_stresc(char *instr, char *toesc, const char escchr);
    1515extern inline char *mr_date(void);
     16extern inline void mr_strip_spaces(char *in_out);
    1617
    1718#endif                          /* MR_STR_H */
  • branches/stable/mondo/src/lib/mr_str.c

    r1087 r1168  
    116116}
    117117
     118
     119/**
     120 * Remove all characters whose ASCII value is less than or equal to 32
     121 * (spaces and control characters) from both sides of @p in_out.
     122 * @param in_out The string to strip spaces/control characters from (modified).
     123 */
     124void mr_strip_spaces(char *in_out)
     125{
     126    /*@ int ******************************************************** */
     127    int i;
     128    int j;
     129    size_t length;
     130
     131    /*@ end vars *************************************************** */
     132
     133    if (in_out == NULL) {
     134        return;
     135    }
     136    length = strlen(in_out);
     137
     138    /* Skip initial spaces and special chars */
     139    for (i = 0; in_out[i] <= ' ' && i < (int)length ; i++);
     140    /* Shift the string to the begining */
     141    for (j = 0; i < (int)length ; i++, j++) {
     142        in_out[j] = in_out[i];
     143    }
     144    /* Skip final spaces and special chars */
     145    for (i = (int)strlen(in_out) - 1; in_out[i] <= ' ' && i >= 0 ; i--);
     146
     147    /* The string now ends after that char */
     148    i++;
     149    in_out[i] = '\0';
     150}
  • branches/stable/mondo/src/mondorestore/mondo-restore.c

    r1166 r1168  
    1414#include <pthread.h>
    1515#include "my-stuff.h"
    16 #include "../common/mondostructures.h"
    17 #include "../common/libmondo.h"
     16#include "mr_mem.h"
     17#include "mr_msg.h"
     18#include "mr_str.h"
     19
     20#include "mondostructures.h"
     21#include "libmondo.h"
    1822#include "mr-externs.h"
    1923#include "mondo-restore.h"
    2024#include "mondo-rstr-compare-EXT.h"
    2125#include "mondo-rstr-tools-EXT.h"
    22 #include "mr_mem.h"
    23 #include "mr_msg.h"
    2426
    2527extern void twenty_seconds_til_yikes(void);
     
    12391241                newtDrawRootText(0, g_noof_rows - 2, tmp);
    12401242                newtRefresh();
    1241                 strip_spaces(tmp);
     1243                mr_strip_spaces(tmp);
    12421244                update_progress_form(tmp);
    12431245            }
     
    14911493            newtRefresh();
    14921494        }
    1493         strip_spaces(tmp);
     1495        mr_strip_spaces(tmp);
    14941496        update_progress_form(tmp);
    14951497        if (current_slice_number == 0) {
  • branches/stable/mondo/src/mondorestore/mondo-rstr-newt.c

    r1125 r1168  
    55#include "mr_mem.h"
    66#include "mr_msg.h"
     7#include "mr_str.h"
    78
    89extern char *g_mondo_cfg_file;  // where m*ndo-restore.cfg (the config file) is stored
     
    215216        strcpy(size_str, size_here);
    216217//      log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
    217         strip_spaces(device_str);
    218         strip_spaces(mountpoint_str);
    219         strip_spaces(format_str);
    220         strip_spaces(size_str);
     218        mr_strip_spaces(device_str);
     219        mr_strip_spaces(mountpoint_str);
     220        mr_strip_spaces(format_str);
     221        mr_strip_spaces(size_str);
    221222//      log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
    222223        if (b_res == bOK) {
     
    278279        ("Add variable", "Enter the name of the variable to add", sz_out,
    279280         MAX_STR_LEN)) {
    280         strip_spaces(sz_out);
     281        mr_strip_spaces(sz_out);
    281282        items = raidrec->additional_vars.entries;
    282283        for (i = 0;
     
    498499            return;
    499500        }
    500         strip_spaces(tmp);
     501        mr_strip_spaces(tmp);
    501502        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
    502503            strcpy(sz, tmp);
     
    552553            return;
    553554        }
    554         strip_spaces(tmp);
     555        mr_strip_spaces(tmp);
    555556        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
    556557            strcpy(sz, tmp);
     
    12311232        b_res = newtRunForm(myForm);
    12321233        strcpy(device_str, device_here);
    1233         strip_spaces(device_str);
     1234        mr_strip_spaces(device_str);
    12341235        strcpy(mountpoint_str, mountpoint_here);
    1235         strip_spaces(mountpoint_str);
     1236        mr_strip_spaces(mountpoint_str);
    12361237        strcpy(format_str, format_here);
    1237         strip_spaces(format_str);
     1238        mr_strip_spaces(format_str);
    12381239        if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB)
    12391240            && strstr(device_used_to_be, RAID_DEVICE_STUB)
     
    12511252            && strcmp(mountlist->el[currline].mountpoint, "image")) {
    12521253            strcpy(size_str, size_here);
    1253             strip_spaces(size_str);
     1254            mr_strip_spaces(size_str);
    12541255        } else {
    12551256            sprintf(size_str, "%ld",
     
    18981899            raidrec->additional_vars.el[lino].label, sz_out);
    18991900    if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) {
    1900         strip_spaces(sz_out);
     1901        mr_strip_spaces(sz_out);
    19011902        strcpy(raidrec->additional_vars.el[lino].value, sz_out);
    19021903    }
     
    23062307                 "At what path on this device can the ISO files be found?",
    23072308                 isodir_path, MAX_STR_LEN / 4)) {
    2308                 strip_spaces(isodir_device);
    2309                 strip_spaces(isodir_format);
    2310                 strip_spaces(isodir_path);
     2309                mr_strip_spaces(isodir_device);
     2310                mr_strip_spaces(isodir_format);
     2311                mr_strip_spaces(isodir_path);
    23112312                log_it("%d - BBB - isodir_path = %s", isodir_path);
    23122313                return (TRUE);
  • branches/stable/mondo/src/mondorestore/mondo-rstr-newt.h

    r1103 r1168  
    1919
    2020#include "my-stuff.h"
    21 #include "../common/mondostructures.h"
    22 #include "../common/libmondo.h"
     21#include "mr_str.h"
     22
     23#include "mondostructures.h"
     24#include "libmondo.h"
    2325#ifdef   __FreeBSD__
    2426#define  raid_device_record             vinum_volume
     
    4446extern long get_phys_size_of_drive(char *);
    4547extern bool is_this_device_mounted(char *);
    46 extern void strip_spaces(char *);
    4748extern void initialize_raidrec(struct raid_device_record *);
    4849extern int make_list_of_drives(struct mountlist_itself *,
  • branches/stable/mondo/src/mondorestore/mondo-rstr-tools.c

    r1166 r1168  
    66#include <pthread.h>
    77#include "my-stuff.h"
    8 #include "../common/mondostructures.h"
    9 #include "../common/libmondo.h"
     8#include "mr_mem.h"
     9#include "mr_msg.h"
     10#include "mr_str.h"
     11
     12#include "mondostructures.h"
     13#include "libmondo.h"
    1014#include "mr-externs.h"
    1115//#include "mondo-restore.h"
    1216//#include "mondo-rstr-compare-EXT.h"
    1317#include "mondo-rstr-tools.h"
    14 #include "mr_mem.h"
    15 #include "mr_msg.h"
    1618
    1719extern bool g_sigpipe_caught;
     
    110112    for (fgets(incoming_ptr, MAX_STR_LEN, fin);
    111113         !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
    112         strip_spaces(incoming_ptr);
     114        mr_strip_spaces(incoming_ptr);
    113115
    114116        if (incoming[0] == '\0') {
  • branches/stable/mondo/src/mondorestore/mr-externs.h

    r684 r1168  
    7171extern int read_header_block_from_stream(long long *, char *, int *);
    7272extern void save_filelist(struct s_node *, char *);
    73 extern void strip_spaces(char *);
    7473extern int strcmp_inc_numbers(char *, char *);
    7574extern char *slice_fname(long, long, char *, char *);
  • branches/stable/monitas/from-mondo.c

    r353 r1168  
    66
    77#include "structs.h"
     8#include "mr_str.h"
    89
    910
     
    1314bool does_file_exist (char *);
    1415int make_hole_for_file (char *);
    15 void strip_spaces(char*);
    1616
    1717
     
    5353      pclose (fin);
    5454    }
    55   strip_spaces (result);
     55  mr_strip_spaces (result);
    5656  return (result);
    5757}
     
    124124      incoming[i]='\0';
    125125*/
    126       strip_spaces (incoming);
     126      mr_strip_spaces (incoming);
    127127      log_it (debug, incoming);
    128128    }
     
    204204}
    205205
    206 
    207 
    208 
    209 
    210 
    211 
    212 
    213 
    214 /*************************************************************************
    215  * strip_spaces() -- Hugo Rabson                                         *
    216  *                   rewitten Stefan Huebner                             *
    217  *                                                                       *
    218  * Purpose:   remove leading whitespaces and control characters, replace *
    219  *            TABs by SPACES, remove previous char when followed with BS,*
    220  *            skip control chars, terminate string with '\0' when CR or  *
    221  *            NL is detected                                             *
    222  *            afterwards remove trailing whitespace                      *
    223  * Called by:                                                            *
    224  * Returns:                                                              *
    225  *************************************************************************/
    226 void
    227 strip_spaces (char *in_out)
    228 {
    229     char *r, *w;
    230     r = w = in_out;             // initialize read and write pointer
    231 
    232     while ( *r && *r <= ' ' )
    233         ++r;                    // skip leading whitespace and control chars
    234 
    235     for ( ; *r ; ++r )          // until end of existing string do:
    236       {
    237         if (*r == '\t')                 // TAB
    238           { *w++ = ' ';                     // write SPACE instead
    239             continue; }
    240         if (*r == (char) 8)             // BACKSPACE
    241           { if (w > in_out) --w;            // remove previous character (if any ;-)
    242             continue; }
    243         if (*r == '\n' || *r == '\r')   // CR and LF
    244             break;                          // terminate copying
    245         if (*r < ' ')                   // Control chars
    246             continue;                       // are ignored (skipped)
    247         *w++ = *r;                      // all other chars are copied
    248       }
    249     // all characters are copied
    250     *w = '\0';                  // terminate the copied string
    251     for (--w; w>in_out && *w == ' '; --w)
    252         *w = '\0';              // remove trailing whitespaces
    253     return;
    254     /** buffers ******************************************************/
    255 //  char tmp[MAX_STR_LEN+1];
    256 
    257     /** pointers *****************************************************/
    258 //  char *p;
    259 
    260     /** int *********************************************************/
    261 //  int i;
    262 
    263     /** end vars ****************************************************/
    264 /*  for (i = 0; in_out[i] <= ' ' && i < strlen (in_out); i++);
    265   strcpy (tmp, in_out + i);
    266   for (i = strlen (tmp); i>0 && tmp[i - 1] <= 32; i--);
    267   tmp[i] = '\0';
    268   for (i = 0; i < 80; i++)
    269     {
    270       in_out[i] = ' ';
    271     }
    272   in_out[i] = '\0';
    273   i = 0;
    274   p = tmp;
    275   while (*p != '\0')
    276     {
    277       in_out[i] = *(p++);
    278       in_out[i + 1] = '\0';
    279       if (in_out[i] < 32 && i > 0)
    280     {
    281       if (in_out[i] == 8)
    282         {
    283           i--;
    284         }
    285       else if (in_out[i] == 9)
    286         {
    287           in_out[i++] = ' ';
    288         }
    289       else if (in_out[i] == '\t')
    290         {
    291           for (i++; i % 5; i++);
    292         }
    293       else if (in_out[i] >= 10 && in_out[i] <= 13)
    294         {
    295           break;
    296         }
    297       else
    298         {
    299           i--;
    300         }
    301     }
    302       else
    303     {
    304       i++;
    305     }
    306     }
    307   in_out[i] = '\0';
    308 */
    309 /*  for(i=strlen(in_out); i>0 && in_out[i-1]<=32; i--) {in_out[i-1]='\0';} */
    310 }
    311 
    312 
    313 
    314 
    315 
    316 
    317 
    318 
    319 
    320 
    321 
Note: See TracChangeset for help on using the changeset viewer.