Changeset 1185 in MondoRescue for trunk/mondo/src/common/libmondo-string.c
- Timestamp:
- Feb 19, 2007, 1:51:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/src/common/libmondo-string.c
r1081 r1185 10 10 #include "my-stuff.h" 11 11 #include "mr_mem.h" 12 #include "mr_str.h" 13 12 14 #include "mondostructures.h" 13 15 #include "libmondo-string.h" … … 16 18 #include "libmondo-tools-EXT.h" 17 19 #include <math.h> 18 #include "mr_mem.h"19 20 20 21 /*@unused@*/ … … 38 39 char *build_partition_name(const char *drive, int partno) 39 40 { 40 char *p, *c; 41 char *partition; 41 char *p = NULL; 42 char *c = NULL; 43 char *partition = NULL; 42 44 43 45 assert_string_is_neither_NULL_nor_zerolength(drive); 44 46 assert(partno >= 0); 45 47 46 mr_asprintf(&partition, "%s",drive);48 mr_asprintf(&partition, drive); 47 49 p = partition; 48 50 /* is this a devfs device path? */ … … 79 81 void center_string(char *in_out, int width) 80 82 { 81 char *scratch ;82 char *out ;83 char *p ;84 int i ; /* purpose */85 int len ; /* purpose */86 int mid ; /* purpose */87 int x ; /* purpose */83 char *scratch = NULL; 84 char *out = NULL; 85 char *p = NULL; 86 int i = 0; /* purpose */ 87 int len = 0; /* purpose */ 88 int mid = 0; /* purpose */ 89 int x = 0; /* purpose */ 88 90 89 91 assert(in_out != NULL); … … 93 95 return; 94 96 } 95 for (p = in_out; *p == ' '; p++); 96 mr_asprintf(&scratch, p); 97 strip_spaces (scratch); 97 mr_asprintf(&scratch, in_out); 98 mr_strip_spaces(scratch); 98 99 len = (int) strlen(scratch); 99 100 mid = width / 2; … … 177 178 long friendly_sizestr_to_sizelong(char *incoming) 178 179 { 179 long outval ;180 int i ;181 char *tmp ;182 char ch ;180 long outval = 0L; 181 int i = 0; 182 char *tmp = NULL; 183 char ch = ' '; 183 184 184 185 assert_string_is_neither_NULL_nor_zerolength(incoming); 185 186 186 187 if (!incoming[0]) { 187 return (0);188 return(0L); 188 189 } 189 190 if (strchr(incoming, '.')) { … … 225 226 226 227 /** 227 * Add spaces to the right of @p incoming to make it @p width characters wide.228 * @param incoming The string to left-pad.229 * @param width The width to pad it to.230 * @return The left-padded string.231 * @note The returned string points to static storage that will be overwritten with each call.232 * @bug Why does center_string() modify its argument but leftpad_string() returns a modified copy?233 */234 /* BERLIOS; useless ?235 char *leftpad_string(char *incoming, int width)236 {237 char *output;238 239 int i;240 241 assert(incoming != NULL);242 assert(width > 2);243 244 mr_asprintf(&output, "%s", incoming);245 for (i = (int) strlen(output); i < width; i++) {246 output[i] = ' ';247 }248 output[i] = '\0';249 return (output);250 }251 */252 253 254 255 /**256 228 * Turn a marker byte (e.g. BLK_START_OF_BACKUP) into a string (e.g. "BLK_START_OF_BACKUP"). 257 229 * Unknown markers are identified as "BLK_UNKNOWN (%d)" where %d is the decimal value. … … 353 325 354 326 /*@ buffer *********************************************************** */ 355 char *output ;327 char *output = NULL; 356 328 357 329 assert(mountlist != NULL); … … 376 348 377 349 /*@ buffers ********************************************************* */ 378 char *output ;350 char *output = NULL; 379 351 380 352 /*@ char ******************************************************** */ 381 char p ;353 char p = NULL; 382 354 383 355 assert(label != NULL); … … 415 387 switch (i) { 416 388 case 0: 417 mr_asprintf(&output, " %s", "zero");389 mr_asprintf(&output, "zero"); 418 390 break; 419 391 case 1: 420 mr_asprintf(&output, " %s", "one");392 mr_asprintf(&output, "one"); 421 393 break; 422 394 case 2: 423 mr_asprintf(&output, " %s", "two");395 mr_asprintf(&output, "two"); 424 396 break; 425 397 case 3: 426 mr_asprintf(&output, " %s", "three");398 mr_asprintf(&output, "three"); 427 399 break; 428 400 case 4: 429 mr_asprintf(&output, " %s", "four");401 mr_asprintf(&output, "four"); 430 402 break; 431 403 case 5: 432 mr_asprintf(&output, " %s", "five");404 mr_asprintf(&output, "five"); 433 405 break; 434 406 case 6: 435 mr_asprintf(&output, " %s", "six");407 mr_asprintf(&output, "six"); 436 408 break; 437 409 case 7: 438 mr_asprintf(&output, " %s", "seven");410 mr_asprintf(&output, "seven"); 439 411 break; 440 412 case 8: 441 mr_asprintf(&output, " %s", "eight");413 mr_asprintf(&output, "eight"); 442 414 break; 443 415 case 9: 444 mr_asprintf(&output, " %s", "nine");416 mr_asprintf(&output, "nine"); 445 417 case 10: 446 mr_asprintf(&output, " %s", "ten");418 mr_asprintf(&output, "ten"); 447 419 default: 448 420 mr_asprintf(&output, "%d", i); … … 462 434 { 463 435 /*@ buffers *** */ 464 char *input ;436 char *input = NULL; 465 437 466 438 /*@ pointers * */ 467 char *p ;439 char *p = NULL; 468 440 469 441 assert_string_is_neither_NULL_nor_zerolength(ip); … … 516 488 mr_asprintf(&suffix, ".%s", s); 517 489 } else { 518 mr_asprintf(&suffix, " %s", "");490 mr_asprintf(&suffix, ""); 519 491 } 520 492 mr_asprintf(&output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, … … 686 658 687 659 /** 688 * Remove all characters whose ASCII value is less than or equal to 32689 * (spaces and control characters) from both sides of @p in_out.690 * @param in_out The string to strip spaces/control characters from (modified).691 */692 void strip_spaces(char *in_out)693 {694 /*@ buffers ***************************************************** */695 char *tmp;696 char *tmp1;697 698 /*@ pointers **************************************************** */699 char *p;700 701 /*@ int ******************************************************** */702 int i;703 int original_incoming_length;704 705 /*@ end vars *************************************************** */706 707 assert(in_out != NULL);708 original_incoming_length = (int) strlen(in_out);709 for (i = 0; in_out[i] <= ' ' && i < (int) strlen(in_out); i++);710 mr_asprintf(&tmp, "%s", in_out + i);711 for (i = (int) strlen(tmp); i > 0 && tmp[i - 1] <= 32; i--);712 tmp[i] = '\0';713 for (i = 0; i < original_incoming_length; i++) {714 in_out[i] = ' ';715 }716 in_out[i] = '\0';717 i = 0;718 p = tmp;719 while (*p != '\0') {720 in_out[i] = *(p++);721 in_out[i + 1] = '\0';722 if (in_out[i] < 32 && i > 0) {723 if (in_out[i] == 8) {724 i--;725 } else if (in_out[i] == 9) {726 in_out[i++] = ' ';727 } else if (in_out[i] == '\r') {728 mr_asprintf(&tmp1, "%s", in_out + i);729 strcpy(in_out, tmp1);730 mr_free(tmp1);731 i = -1;732 continue;733 } else if (in_out[i] == '\t') {734 for (i++; i % 5; i++);735 } else if (in_out[i] >= 10 && in_out[i] <= 13) {736 break;737 } else {738 i--;739 }740 } else {741 i++;742 }743 }744 in_out[i] = '\0';745 mr_free(tmp);746 }747 748 749 /**750 660 * If there are double quotes "" around @p incoming then remove them. 751 661 * This does not affect other quotes that may be embedded within the string. … … 781 691 { 782 692 int i = strlen(partition) - 1; 783 char *c ;693 char *c = NULL; 784 694 785 695 #ifdef __FreeBSD__ … … 851 761 { 852 762 int sev = 0; 853 char *reason ;854 char *filename ;763 char *reason = NULL; 764 char *filename = NULL; 855 765 856 766 // out_reason might be null on purpose, so don't bomb if it is :) OK? 857 767 assert_string_is_neither_NULL_nor_zerolength(fn); 858 768 if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) { 859 mr_asprintf(&filename, "%s",fn + strlen(MNT_RESTORING));769 mr_asprintf(&filename, fn + strlen(MNT_RESTORING)); 860 770 } else if (fn[0] != '/') { 861 771 mr_asprintf(&filename, "/%s", fn); 862 772 } else { 863 mr_asprintf(&filename, "%s",fn);773 mr_asprintf(&filename, fn); 864 774 } 865 775 … … 943 853 sev = 1; 944 854 mr_asprintf(&reason, 945 "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");855 _("Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.")); 946 856 } 947 857 mr_free(filename); … … 956 866 return (sev); 957 867 } 958 959 868 960 869 … … 1013 922 } 1014 923 1015 /* update screen */924 /* update screen */ 1016 925 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1017 926 percentage = … … 1031 940 } 1032 941 j = trunc(percentage / 5); 1033 tmp1 = (char *) m alloc((j + 1) * sizeof(char));942 tmp1 = (char *) mr_malloc((j + 1) * sizeof(char)); 1034 943 for (i = 0, p = tmp1; i < j; i++, p++) { 1035 944 *p = '*'; … … 1037 946 *p = '\0'; 1038 947 1039 tmp2 = (char *) m alloc((20 - j + 1) * sizeof(char));948 tmp2 = (char *) mr_malloc((20 - j + 1) * sizeof(char)); 1040 949 for (i = 0, p = tmp2; i < 20 - j; i++, p++) { 1041 950 *p = '.';
Note:
See TracChangeset
for help on using the changeset viewer.