Changeset 783 in MondoRescue for trunk/mondo/mondo/common/libmondo-string.c
- Timestamp:
- Aug 31, 2006, 5:09:20 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-string.c
r768 r783 14 14 #include "newt-specific-EXT.h" 15 15 #include "libmondo-tools-EXT.h" 16 #include <math.h> 16 17 17 18 /*@unused@*/ … … 136 137 137 138 138 /*139 * Add commas every third place in @p input.140 * @param input The string to commarize.141 * @return The string with commas.142 * @note The returned string points to static storage that will be overwritten with each call.143 */144 char *commarize(char *input)145 {146 char *pos_w_commas;147 static char output[MAX_STR_LEN];148 char *tmp;149 int j;150 151 assert(input != NULL);152 153 asprintf(&tmp, "%s", input);154 if (strlen(tmp) > 6) {155 asprintf(&pos_w_commas, "%s", tmp);156 j = (int) strlen(pos_w_commas);157 tmp[j - 6] = ',';158 strcpy(tmp + j - 5, pos_w_commas + j - 6);159 paranoid_free(pos_w_commas);160 asprintf(&pos_w_commas, "%s", tmp);161 }162 if (strlen(tmp) > 3) {163 j = (int) strlen(tmp);164 asprintf(&pos_w_commas, "%s", tmp);165 pos_w_commas[j - 3] = ',';166 strcpy(pos_w_commas + j - 2, tmp + j - 3);167 } else {168 asprintf(&pos_w_commas, "%s", tmp);169 }170 strcpy(output, pos_w_commas);171 paranoid_free(pos_w_commas);172 paranoid_free(tmp);173 return (output);174 }175 176 177 139 /** 178 140 * Turn an entry from the RAID editor's disklist into a GUI-friendly string. … … 601 563 602 564 /*@ initialize ****************************************************** */ 603 assert(flaws_str_A != NULL);604 assert(flaws_str_B != NULL);605 assert(flaws_str_C != NULL);606 565 assert(flaws_str != NULL); 607 566 608 flaws_str_A[0] = flaws_str_B[0] = flaws_str_C[0] = '\0'; 609 567 flaws_str_A = NULL; 568 flaws_str_B = NULL; 569 flaws_str_C = NULL; 610 570 611 571 if (!res && !strlen(flaws_str)) { … … 613 573 } 614 574 if (strlen(flaws_str) > 0) { 615 sprintf(flaws_str_A, "%s", flaws_str + 1);575 asprintf(&flaws_str_A, "%s", flaws_str + 1); 616 576 } 617 577 if (strlen(flaws_str_A) >= 74) { 618 578 for (i = 74; flaws_str_A[i] != ' '; i--); 619 strcpy(flaws_str_B, flaws_str_A + i + 1);579 asprintf(&flaws_str_B, "%s", flaws_str_A + i + 1); 620 580 flaws_str_A[i] = '\0'; 621 581 } 622 582 if (strlen(flaws_str_B) >= 74) { 623 583 for (i = 74; flaws_str_B[i] != ' '; i--); 624 strcpy(flaws_str_C, flaws_str_B + i + 1);584 asprintf(&flaws_str_C, "%s", flaws_str_B + i + 1); 625 585 flaws_str_B[i] = '\0'; 626 586 } … … 834 794 if (c && strncmp(c, "/part", 5) == 0) { 835 795 /* yup it's devfs, return the "disc" path */ 836 str cpy(c + 1, "disc");796 strncpy(c + 1, "disc", (size_t)5); 837 797 return partition; 838 798 } … … 1027 987 /*@ int *********************************************** */ 1028 988 int percentage = 0; 1029 int i ;1030 int j ;989 int i = 0; 990 int j = 0; 1031 991 1032 992 /*@ buffers ******************************************* */ 1033 char *outstr; 1034 char *tmp; 1035 char *tmp1; 1036 char *tmp2; 1037 char *prepstr; 1038 char *p; 993 char *outstr = NULL; 994 char *tmp1 = NULL; 995 char *tmp2 = NULL; 996 char *prepstr = NULL; 997 char *p = NULL; 1039 998 1040 999 assert(bkpinfo != NULL); 1041 1000 1042 1001 if (bkpinfo->media_size[g_current_media_number] <= 0) { 1043 asprintf(&tmp, "%lld", g_tape_posK); 1044 asprintf(&outstr, _("Volume %d: %s kilobytes archived so far"), 1045 g_current_media_number, commarize(tmp)); 1046 paranoid_free(tmp); 1002 asprintf(&outstr, _("Volume %d: %'lld kilobytes archived so far"), 1003 g_current_media_number, g_tape_posK); 1047 1004 1048 1005 return (outstr); … … 1060 1017 bkpinfo->media_size[g_current_media_number]); 1061 1018 asprintf(&prepstr, "%s %d: [", 1062 media_descriptor_string(bkpinfo->backup_media_type),1019 bkpinfo->backup_media_string, 1063 1020 g_current_media_number); 1064 1021 } … … 1093 1050 return (outstr); 1094 1051 } 1095 1096 /**1097 * Get a string form of @p type_of_bkp.1098 * @param type_of_bkp The backup type to stringify.1099 * @return The stringification of @p type_of_bkp.1100 * @note The returned string points to static storage that will be overwritten with each call.1101 */1102 char *media_descriptor_string(t_bkptype type_of_bkp)1103 {1104 static char *type_of_backup = NULL;1105 1106 if (!type_of_backup) {1107 malloc_string(type_of_backup);1108 }1109 1110 switch (type_of_bkp) {1111 case dvd:1112 strcpy(type_of_backup, "DVD");1113 break;1114 case cdr:1115 strcpy(type_of_backup, "CDR");1116 break;1117 case cdrw:1118 strcpy(type_of_backup, "CDRW");1119 break;1120 case tape:1121 strcpy(type_of_backup, "tape");1122 break;1123 case cdstream:1124 strcpy(type_of_backup, "CDR");1125 break;1126 case udev:1127 strcpy(type_of_backup, "udev");1128 break;1129 case iso:1130 strcpy(type_of_backup, "ISO");1131 break;1132 case nfs:1133 strcpy(type_of_backup, "nfs");1134 break;1135 default:1136 strcpy(type_of_backup, "ISO");1137 }1138 return (type_of_backup);1139 }
Note:
See TracChangeset
for help on using the changeset viewer.