Changeset 3614 in MondoRescue
- Timestamp:
- Nov 18, 2016, 5:31:43 PM (8 years ago)
- Location:
- branches/3.2/mondo
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/common/libmondo-devices.c
r3610 r3614 24 24 #include "libmondo-stream-EXT.h" 25 25 26 extern void mr_strip_spaces(char *);27 28 #include <sys/types.h>29 26 #ifdef __FreeBSD__ 30 27 #define DKTYPENAMES … … 1040 1037 } else { 1041 1038 mr_getline(p, pin); 1042 mr_asprintf(good_formats, " %s",p);1039 good_formats = mr_strip_spaces(p); 1043 1040 mr_free(p); 1044 1041 (void)pclose(pin); 1045 mr_strip_spaces(good_formats);1046 1042 mr_strcat(good_formats, " swap lvm raid ntfs-3g ntfs 7 "); // " ntfs 7 " -- um, cheating much? :) 1047 1043 if (strstr(good_formats, format_sz)) { … … 2461 2457 } 2462 2458 mr_free(bkpinfo->netfs_mount); 2463 mr_asprintf(bkpinfo->netfs_mount, "%s", p); 2459 // check whether already mounted - we better remove 2460 // surrounding spaces and trailing '/' for this 2461 bkpinfo->netfs_mount = mr_strip_spaces(p); 2464 2462 if (!bkpinfo->restore_data) { 2465 2463 if ((compression_type = which_compression_type()) == NULL) { … … 2473 2471 } 2474 2472 } 2475 // check whether already mounted - we better remove2476 // surrounding spaces and trailing '/' for this2477 mr_strip_spaces(bkpinfo->netfs_mount);2478 2473 if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/') 2479 2474 bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0'; … … 2607 2602 } 2608 2603 mr_free(bkpinfo->netfs_remote_dir); 2609 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", tmp1);2610 2611 2604 // check whether writable - we better remove surrounding spaces for this 2612 mr_strip_spaces(bkpinfo->netfs_remote_dir);2605 bkpinfo->netfs_remote_dir = mr_strip_spaces(tmp1); 2613 2606 2614 2607 if (!popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix, MAX_STR_LEN / 4)) { -
branches/3.2/mondo/src/common/libmondo-fork-EXT.h
r1999 r3614 1 1 /* libmondo-fork-EXT.h */ 2 2 3 extern char *call_program_and_get_last_line_of_output(c har *call);3 extern char *call_program_and_get_last_line_of_output(const char *call); 4 4 extern int run_program_and_log_to_screen(char *basic_call, 5 5 char *what_i_am_doing); -
branches/3.2/mondo/src/common/libmondo-raid.c
r3610 r3614 426 426 char *incoming = NULL; 427 427 char *p = NULL; 428 char *res = NULL; 428 429 429 430 assert(fin != NULL); … … 433 434 } 434 435 435 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 436 log_msg(10,"Found in raidtab line: %s",incoming); 437 mr_strip_spaces(incoming); 436 for (mr_getline(res, fin); !feof(fin); mr_getline(res, fin)) { 437 log_msg(10,"Found in raidtab line: %s",res); 438 incoming = mr_strip_spaces(res); 439 mr_free(res); 438 440 p = strchr(incoming, ' '); 439 441 if (strlen(incoming) < 3 || incoming[0] == '#' || !p) { -
branches/3.2/mondo/src/common/libmondo-string.c
r3611 r3614 92 92 } 93 93 /* skip initial spaces */ 94 mr_asprintf(scratch, "%s", in); 95 mr_strip_spaces(scratch); 94 scratch = mr_strip_spaces(in); 96 95 len = (int)strlen(scratch); 97 96 mid = width / 2; -
branches/3.2/mondo/src/common/newt-specific.c
r3508 r3614 1234 1234 static char *possible_responses[] = { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", "netfs", "iso", NULL }; 1235 1235 char *outstr = NULL; 1236 char *instr = NULL; 1236 1237 t_bkptype backup_type; 1237 1238 int i; … … 1256 1257 } 1257 1258 printf(")\n--> "); 1258 mr_getline(outstr, stdin); 1259 mr_strip_spaces(outstr); 1259 mr_getline(instr, stdin); 1260 outstr = mr_strip_spaces(instr); 1261 mr_free(instr); 1260 1262 for (i = 0; possible_responses[i]; i++) { 1261 1263 if (!strcmp(possible_responses[i], outstr)) { -
branches/3.2/mondo/src/include/mr_str.h
r3374 r3614 18 18 extern char *mr_stresc(char *instr, char *toesc, const char escchr, const char specialchr); 19 19 extern inline char *mr_date(void); 20 extern void mr_strip_spaces(char *in_out);20 extern char *mr_strip_spaces(const char *instr); 21 21 extern char *mr_str_substitute(const char *in, const char *token, const char *subst); 22 22 /* -
branches/3.2/mondo/src/lib/mr_str.c
r3566 r3614 25 25 * @note this function allocates memory that needs to be freed by caller 26 26 **/ 27 char *mr_strtok(char *instr, const char *delims, int *lastpos) 28 { 29 30 char *token = NULL; 31 char *strptr = NULL; 32 size_t pos1 = 0; 33 size_t pos2 = 0; 34 35 if (instr == NULL) { 36 *lastpos = 0; 37 return token; 38 } 39 40 if (delims == NULL) { 41 *lastpos = 0; 42 return token; 43 } 44 45 if (strlen(instr) <= *lastpos) { 46 *lastpos = 0; 47 return token; 48 } 49 50 strptr = instr + *lastpos; 51 pos2 = strspn(strptr, delims); 52 strptr += pos2; 53 pos1 = strcspn(strptr, delims); 54 token = (char *)mr_malloc(sizeof(*token) * (pos1 + 1)); 55 strncpy(token, strptr, pos1); 56 token[pos1] = '\0'; 57 *lastpos = *lastpos + pos1 + pos2 + 1; 58 27 char *mr_strtok(char *instr, const char *delims, int *lastpos) { 28 29 char *token = NULL; 30 char *strptr = NULL; 31 size_t pos1 = 0; 32 size_t pos2 = 0; 33 34 if (instr == NULL) { 35 *lastpos = 0; 59 36 return token; 37 } 38 39 if (delims == NULL) { 40 *lastpos = 0; 41 return token; 42 } 43 44 if (strlen(instr) <= *lastpos) { 45 *lastpos = 0; 46 return token; 47 } 48 49 strptr = instr + *lastpos; 50 pos2 = strspn(strptr, delims); 51 strptr += pos2; 52 pos1 = strcspn(strptr, delims); 53 token = (char *)mr_malloc(sizeof(*token) * (pos1 + 1)); 54 strncpy(token, strptr, pos1); 55 token[pos1] = '\0'; 56 *lastpos = *lastpos + pos1 + pos2 + 1; 57 58 return token; 60 59 } 61 60 … … 71 70 **/ 72 71 char *mr_stresc(char *instr, char *toesc, const char escchr, const char specialchr) { 73 char *inptr = NULL; 74 char *retstr = NULL; 75 char *retptr = NULL; 76 char *escptr = NULL; 77 int cnt = 0; 78 bool found = FALSE; 79 80 inptr = instr; 81 // Count how many characters need escaping. 82 while (*inptr != '\0') { 83 escptr = toesc; 84 while (*escptr != '\0') { 85 if (*inptr == *escptr) { 86 // Found it, skip the rest. 87 cnt++; 88 // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars 89 if (*inptr == specialchr) { 90 cnt += 2; 91 } 92 break; 72 73 char *inptr = NULL; 74 char *retstr = NULL; 75 char *retptr = NULL; 76 char *escptr = NULL; 77 int cnt = 0; 78 bool found = FALSE; 79 80 inptr = instr; 81 // Count how many characters need escaping. 82 while (*inptr != '\0') { 83 escptr = toesc; 84 while (*escptr != '\0') { 85 if (*inptr == *escptr) { 86 // Found it, skip the rest. 87 cnt++; 88 // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars 89 if (*inptr == specialchr) { 90 cnt += 2; 93 91 } 94 escptr++;92 break; 95 93 } 96 inptr++;97 } 98 99 inptr = instr; 100 retstr = (char *) mr_malloc(strlen(inptr) + cnt + 1); 101 retptr = retstr;102 103 // Prepend specified characters with escape character. 104 while (*inptr != '\0') { 105 escptr = toesc; 106 while (*escptr != '\0') {107 if (*inptr == *escptr) {108 // Found it, skip the rest.109 // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars110 if (*inptr == specialchr) {111 *retptr = specialchr;112 retptr++;113 *retptr = escchr;114 115 found = TRUE;116 } else {117 *retptr = escchr;118 retptr++;119 }120 break;94 escptr++; 95 } 96 inptr++; 97 } 98 99 inptr = instr; 100 retstr = (char *) mr_malloc(strlen(inptr) + cnt + 1); 101 retptr = retstr; 102 103 // Prepend specified characters with escape character. 104 while (*inptr != '\0') { 105 escptr = toesc; 106 while (*escptr != '\0') { 107 if (*inptr == *escptr) { 108 // Found it, skip the rest. 109 // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars 110 if (*inptr == specialchr) { 111 *retptr = specialchr; 112 retptr++; 113 *retptr = escchr; 114 retptr++; 115 found = TRUE; 116 } else { 117 *retptr = escchr; 118 retptr++; 121 119 } 122 escptr++;120 break; 123 121 } 124 *retptr = *inptr; 122 escptr++; 123 } 124 *retptr = *inptr; 125 retptr++; 126 inptr++; 127 if (found) { 128 // finish to put the remaining specialchr 129 *retptr = specialchr; 125 130 retptr++; 126 inptr++; 127 if (found) { 128 // finish to put the remaining specialchr 129 *retptr = specialchr; 130 retptr++; 131 found = FALSE; 132 } 133 } 134 *retptr = '\0'; 135 136 return retstr; 131 found = FALSE; 132 } 133 } 134 *retptr = '\0'; 135 136 return(retstr); 137 137 } 138 138 139 139 /* Return a string containing the date */ 140 140 char *mr_date(void) { 141 142 143 144 145 141 142 time_t tcurr; 143 144 tcurr = time(NULL); 145 return(ctime(&tcurr)); 146 146 } 147 147 … … 161 161 /** 162 162 * Remove all characters whose ASCII value is less than or equal to 32 163 * (spaces and control characters) from both sides of @p in_out. 164 * @param in_out The string to strip spaces/control characters from (modified). 163 * (spaces and control characters) from both sides of @p instr. 164 * @param instr The string to strip spaces/control characters from 165 * returns a newly allocated string without the spaces that needs to be freed 166 * by the caller 165 167 */ 166 void mr_strip_spaces(char *in_out) {167 int i = 0; 168 int j = 0;169 size_t length;170 171 if (in_out == NULL) { 172 return; 173 }174 length = strlen(in_out); 175 176 /* Skip initial spaces and special chars */ 177 for (i = 0; in_out[i] <= ' ' && i < (int)length ; i++); 178 /* Shift the string to the begining if needed */ 179 if (i != 0) {180 for (j = 0; i < (int)length ; i++, j++) { 181 in_out[j] = in_out[i];182 } 183 /* Erase the end of the string if needed */ 184 in_out[j] = '\0'; 185 } 186 187 /* Skip final spaces and special chars */ 188 for (i = (int)strlen(in_out) - 1; i >= 0 && in_out[i] <= ' '; i--); 189 190 /* The string now ends after that char */ 191 i++;192 in_out[i] = '\0';168 char *mr_strip_spaces(const char *instr) { 169 170 char *p = NULL; 171 char *q = NULL; 172 char *outstr = NULL; 173 174 if (instr == NULL) { 175 return(NULL); 176 } 177 p = instr; 178 179 /* Skip initial spaces and special chars */ 180 while (*p <= ' ' && *p != '\0') { 181 p++; 182 } 183 mr_asprintf(outstr, "%s", p); 184 q = outstr + strlen(outstr) -1; 185 186 /* Skip final spaces and special chars */ 187 while (*q <= ' ' && q != outstr) { 188 q--; 189 } 190 191 /* The string now ends after that char */ 192 q++; 193 *q = '\0'; 194 return(outstr); 193 195 } 194 196 -
branches/3.2/mondo/src/mondorestore/mondo-rstr-newt.c
r3611 r3614 198 198 b_res = newtRunForm(myForm); 199 199 mr_free(device_str); 200 mr_asprintf(device_str, "%s",device_here);200 device_str = mr_strip_spaces(device_here); 201 201 202 202 mr_free(mountpoint_str); 203 mr_asprintf(mountpoint_str, "%s", mountpoint_here); 204 mr_strip_spaces(mountpoint_str); 203 mountpoint_str = mr_strip_spaces(mountpoint_here); 205 204 206 205 mr_free(format_str); 207 mr_asprintf(format_str, "%s", format_here); 208 mr_strip_spaces(format_str); 206 format_str = mr_strip_spaces(format_here); 209 207 210 208 mr_free(size_str); 211 mr_asprintf(size_str, "%s", size_here); 212 mr_strip_spaces(size_str); 213 214 mr_strip_spaces(device_str); 209 size_str = mr_strip_spaces(size_here); 210 215 211 if (b_res == bOK) { 216 212 if (device_str[strlen(device_str) - 1] == '/') { … … 1208 1204 b_res = newtRunForm(myForm); 1209 1205 mr_free(device_str); 1210 mr_asprintf(device_str, "%s", device_here); 1211 mr_strip_spaces(device_str); 1206 device_str = mr_strip_spaces(device_here); 1212 1207 1213 1208 mr_free(mountpoint_str); 1214 mr_asprintf(mountpoint_str, "%s", mountpoint_here); 1215 mr_strip_spaces(mountpoint_str); 1209 mountpoint_str = mr_strip_spaces(mountpoint_here); 1216 1210 1217 1211 mr_free(format_str); 1218 mr_asprintf(format_str, "%s", format_here); 1219 mr_strip_spaces(format_str); 1212 format_str = mr_strip_spaces(format_here); 1220 1213 1221 1214 if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB) … … 1234 1227 && strcmp(mountlist->el[currline].mountpoint, "image")) { 1235 1228 mr_free(size_str); 1236 mr_asprintf(size_str, "%s", size_here); 1237 mr_strip_spaces(size_str); 1229 size_str = mr_strip_spaces(size_here); 1238 1230 } else { 1239 1231 mr_asprintf(size_str, "%ld", calculate_raid_device_size(mountlist, raidlist, mountlist->el[currline].device) / 1024); -
branches/3.2/mondo/src/mondorestore/mondo-rstr-tools.c
r3613 r3614 140 140 fatal_error("Cannot openin outfname"); 141 141 } 142 for (mr_getline(incoming, fin); !feof(fin) && (incoming != NULL); mr_getline(incoming, fin)) { 143 mr_strip_spaces(incoming); 142 for (mr_getline(p, fin); !feof(fin) && (p != NULL); mr_getline(p, fin)) { 143 incoming = mr_strip_spaces(p); 144 mr_free(p); 144 145 145 146 if (incoming[0] == '\0') { -
branches/3.2/mondo/test/Makefile.am
r3564 r3614 4 4 ## The program 5 5 mrtestdir = $(pkglibdir)/test 6 mrtest_PROGRAMS = mrtest_mountlist mrtest_truncname mrtest_stresc mrtest_str_substitute mrtest_ mr_system6 mrtest_PROGRAMS = mrtest_mountlist mrtest_truncname mrtest_stresc mrtest_str_substitute mrtest_strip_spaces mrtest_mr_system 7 7 8 8 mrtest_mountlist_SOURCES = test-mountlist.c ${top_builddir}/src/mondorestore/mondo-prep.c ${top_builddir}/src/mondorestore/mondo-rstr-newt.c ${top_builddir}/src/mondorestore/mondo-rstr-tools.c ${top_builddir}/src/mondorestore/mondo-rstr-mountlist.c … … 18 18 mrtest_str_substitute_LDADD = ${top_builddir}/src/lib/libmr.a @MONDORESTORE_STATIC@ 19 19 20 mrtest_strip_spaces_SOURCES = test-mr_strip_spaces.c 21 mrtest_strip_spaces_LDADD = ${top_builddir}/src/lib/libmr.a @MONDORESTORE_STATIC@ 22 20 23 mrtest_mr_system_SOURCES = test-mr_system.c 21 24 mrtest_mr_system_LDADD = ${top_builddir}/src/lib/libmr.a @MONDORESTORE_STATIC@
Note:
See TracChangeset
for help on using the changeset viewer.