Changeset 3611 in MondoRescue for branches/3.2/mondo/src/common/libmondo-string.c
- Timestamp:
- Nov 10, 2016, 9:09:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/common/libmondo-string.c
r3413 r3611 147 147 148 148 /** 149 * Add commas every third place in @p input.150 * @param input The string to commarize.151 * @return The string with commas.152 * @note The returned string points to static storage that will be overwritten with each call.153 */154 char *commarize(char *input)155 {156 char pos_w_commas[MAX_STR_LEN];157 static char output[MAX_STR_LEN];158 char tmp[MAX_STR_LEN];159 int j;160 161 assert(input != NULL);162 163 strcpy(tmp, input);164 if (strlen(tmp) > 6) {165 strcpy(pos_w_commas, tmp);166 j = (int) strlen(pos_w_commas);167 tmp[j - 6] = ',';168 strcpy(tmp + j - 5, pos_w_commas + j - 6);169 strcpy(pos_w_commas, tmp);170 }171 if (strlen(tmp) > 3) {172 j = (int) strlen(tmp);173 strcpy(pos_w_commas, tmp);174 pos_w_commas[j - 3] = ',';175 strcpy(pos_w_commas + j - 2, tmp + j - 3);176 } else {177 strcpy(pos_w_commas, tmp);178 }179 strcpy(output, pos_w_commas);180 return (output);181 }182 183 184 /**185 149 * Turn an entry from the RAID editor's disklist into a GUI-friendly string. 186 150 * The format is: the device left-aligned and padded to 24 places, followed by a space and the … … 190 154 * @param lino The line number from @p disklist to convert to a string. 191 155 * @return The string form of the disklist entry. 192 * @note The returned string points to static storage and will be overwritten with each call. 156 * @note The returned string points to storage that needs to be freed by 157 * caller 193 158 */ 194 159 char *disklist_entry_to_string(struct list_of_disks *disklist, int lino) … … 196 161 197 162 /*@ buffers ********************************************************** */ 198 static char output[MAX_STR_LEN];163 char *output = NULL; 199 164 200 165 assert(disklist != NULL); 201 166 202 sprintf(output, "%-24s %8d", disklist->el[lino].device, 203 disklist->el[lino].index); 204 return (output); 167 mr_asprintf(output, "%-24s %8d", disklist->el[lino].device, disklist->el[lino].index); 168 return(output); 205 169 } 206 170 … … 301 265 * @param marker The marker byte to stringify. 302 266 * @return @p marker as a string. 303 * @note The returned string points to static storage that will be overwritten with each call. 267 * @note The returned string points to storage that needs to be freed by 268 * caller 304 269 */ 305 270 char *marker_to_string(int marker) 306 271 { 307 272 /*@ buffer ****************************************************** */ 308 static char outstr[MAX_STR_LEN];273 char *outstr = NULL; 309 274 310 275 … … 313 278 switch (marker) { 314 279 case BLK_START_OF_BACKUP: 315 strcpy(outstr, "BLK_START_OF_BACKUP");280 mr_asprintf(outstr, "BLK_START_OF_BACKUP"); 316 281 break; 317 282 case BLK_START_OF_TAPE: 318 strcpy(outstr, "BLK_START_OF_TAPE");283 mr_asprintf(outstr, "BLK_START_OF_TAPE"); 319 284 break; 320 285 case BLK_START_AN_AFIO_OR_SLICE: 321 strcpy(outstr, "BLK_START_AN_AFIO_OR_SLICE");286 mr_asprintf(outstr, "BLK_START_AN_AFIO_OR_SLICE"); 322 287 break; 323 288 case BLK_STOP_AN_AFIO_OR_SLICE: 324 strcpy(outstr, "BLK_STOP_AN_AFIO_OR_SLICE");289 mr_asprintf(outstr, "BLK_STOP_AN_AFIO_OR_SLICE"); 325 290 break; 326 291 case BLK_START_AFIOBALLS: 327 strcpy(outstr, "BLK_START_AFIOBALLS");292 mr_asprintf(outstr, "BLK_START_AFIOBALLS"); 328 293 break; 329 294 case BLK_STOP_AFIOBALLS: 330 strcpy(outstr, "BLK_STOP_AFIOBALLS");295 mr_asprintf(outstr, "BLK_STOP_AFIOBALLS"); 331 296 break; 332 297 case BLK_STOP_BIGGIEFILES: 333 strcpy(outstr, "BLK_STOP_BIGGIEFILES");298 mr_asprintf(outstr, "BLK_STOP_BIGGIEFILES"); 334 299 break; 335 300 case BLK_START_A_NORMBIGGIE: 336 strcpy(outstr, "BLK_START_A_NORMBIGGIE");301 mr_asprintf(outstr, "BLK_START_A_NORMBIGGIE"); 337 302 break; 338 303 case BLK_START_A_PIHBIGGIE: 339 strcpy(outstr, "BLK_START_A_PIHBIGGIE");304 mr_asprintf(outstr, "BLK_START_A_PIHBIGGIE"); 340 305 break; 341 306 case BLK_START_EXTENDED_ATTRIBUTES: 342 strcpy(outstr, "BLK_START_EXTENDED_ATTRIBUTES");307 mr_asprintf(outstr, "BLK_START_EXTENDED_ATTRIBUTES"); 343 308 break; 344 309 case BLK_STOP_EXTENDED_ATTRIBUTES: 345 strcpy(outstr, "BLK_STOP_EXTENDED_ATTRIBUTES");310 mr_asprintf(outstr, "BLK_STOP_EXTENDED_ATTRIBUTES"); 346 311 break; 347 312 case BLK_START_EXAT_FILE: 348 strcpy(outstr, "BLK_START_EXAT_FILE");313 mr_asprintf(outstr, "BLK_START_EXAT_FILE"); 349 314 break; 350 315 case BLK_STOP_EXAT_FILE: 351 strcpy(outstr, "BLK_STOP_EXAT_FILE");316 mr_asprintf(outstr, "BLK_STOP_EXAT_FILE"); 352 317 break; 353 318 case BLK_START_BIGGIEFILES: 354 strcpy(outstr, "BLK_START_BIGGIEFILES");319 mr_asprintf(outstr, "BLK_START_BIGGIEFILES"); 355 320 break; 356 321 case BLK_STOP_A_BIGGIE: 357 strcpy(outstr, "BLK_STOP_A_BIGGIE");322 mr_asprintf(outstr, "BLK_STOP_A_BIGGIE"); 358 323 break; 359 324 case BLK_END_OF_TAPE: 360 strcpy(outstr, "BLK_END_OF_TAPE");325 mr_asprintf(outstr, "BLK_END_OF_TAPE"); 361 326 break; 362 327 case BLK_END_OF_BACKUP: 363 strcpy(outstr, "BLK_END_OF_BACKUP");328 mr_asprintf(outstr, "BLK_END_OF_BACKUP"); 364 329 break; 365 330 case BLK_ABORTED_BACKUP: 366 strcpy(outstr, "BLK_ABORTED_BACKUP");331 mr_asprintf(outstr, "BLK_ABORTED_BACKUP"); 367 332 break; 368 333 case BLK_START_FILE: 369 strcpy(outstr, "BLK_START_FILE");334 mr_asprintf(outstr, "BLK_START_FILE"); 370 335 break; 371 336 case BLK_STOP_FILE: 372 strcpy(outstr, "BLK_STOP_FILE");337 mr_asprintf(outstr, "BLK_STOP_FILE"); 373 338 break; 374 339 default: 375 sprintf(outstr, "BLK_UNKNOWN (%d)", marker);340 mr_asprintf(outstr, "BLK_UNKNOWN (%d)", marker); 376 341 break; 377 342 } 378 343 return (outstr); 379 344 } 380 381 382 345 383 346 … … 391 354 * @param lino The line number in @p mountlist to stringify. 392 355 * @return The string form of <tt>mountlist</tt>-\>el[<tt>lino</tt>]. 393 * @note The returned string points to static storage and will be overwritten with each call. 394 */ 395 char *mountlist_entry_to_string(struct mountlist_itself *mountlist, 396 int lino) 397 { 356 * @note The returned string points to storage that needs to be freed by 357 * caller 358 */ 359 char *mountlist_entry_to_string(struct mountlist_itself *mountlist, int lino) { 398 360 399 361 /*@ buffer *********************************************************** */ 400 static char output[MAX_STR_LEN];362 char *output = NULL; 401 363 402 364 assert(mountlist != NULL); 403 365 404 sprintf(output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device, 405 mountlist->el[lino].mountpoint, mountlist->el[lino].format, 406 mountlist->el[lino].size / 1024L); 407 return (output); 366 mr_asprintf(output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, mountlist->el[lino].size / 1024L); 367 return(output); 408 368 } 409 369 … … 453 413 * @param i The number to stringify. 454 414 * @return The string form of @p i. 455 * @note The returned value points to static strorage that will be overwritten with each call. 415 * @note The returned value points to strorage that needs to be freed by 416 * caller 456 417 */ 457 418 char *number_to_text(int i) … … 459 420 460 421 /*@ buffers ***************************************************** */ 461 static char output[MAX_STR_LEN];422 char *output = NULL; 462 423 463 424 … … 466 427 switch (i) { 467 428 case 0: 468 strcpy(output, "zero");429 mr_asprintf(output, "zero"); 469 430 break; 470 431 case 1: 471 strcpy(output, "one");432 mr_asprintf(output, "one"); 472 433 break; 473 434 case 2: 474 strcpy(output, "two");435 mr_asprintf(output, "two"); 475 436 break; 476 437 case 3: 477 strcpy(output, "three");438 mr_asprintf(output, "three"); 478 439 break; 479 440 case 4: 480 strcpy(output, "four");441 mr_asprintf(output, "four"); 481 442 break; 482 443 case 5: 483 strcpy(output, "five");444 mr_asprintf(output, "five"); 484 445 break; 485 446 case 6: 486 strcpy(output, "six");447 mr_asprintf(output, "six"); 487 448 break; 488 449 case 7: 489 strcpy(output, "seven");450 mr_asprintf(output, "seven"); 490 451 break; 491 452 case 8: 492 strcpy(output, "eight");453 mr_asprintf(output, "eight"); 493 454 break; 494 455 case 9: 495 strcpy(output, "nine");456 mr_asprintf(output, "nine"); 496 457 case 10: 497 strcpy(output, "ten");458 mr_asprintf(output, "ten"); 498 459 default: 499 sprintf(output, "%d", i);460 mr_asprintf(output, "%d", i); 500 461 } 501 462 return (output); … … 875 836 * @param raid_level The RAID level to stringify. 876 837 * @return The string form of @p raid_level. 877 * @note The returned value points to st atic storage that will be overwritten with each call.838 * @note The returned value points to storage that needs to be freed by caller 878 839 */ 879 840 char *turn_raid_level_number_to_string(int raid_level) … … 881 842 882 843 /*@ buffer ********************************************************** */ 883 static char output[MAX_STR_LEN];844 char *output = NULL; 884 845 885 846 886 847 887 848 if (raid_level >= 0) { 888 sprintf(output, " RAID %-2d ", raid_level);849 mr_asprintf(output, " RAID %-2d ", raid_level); 889 850 } else { 890 sprintf(output, "Linear RAID");891 } 892 return 851 mr_asprintf(output, "Linear RAID"); 852 } 853 return(output); 893 854 } 894 855 … … 1068 1029 char *pos_w_commas = NULL; 1069 1030 char *mds = NULL; 1070 char *tmp = NULL;1071 1031 1072 1032 assert(bkpinfo != NULL); 1073 1033 1074 1034 if (bkpinfo->media_size <= 0) { 1075 mr_asprintf(tmp, "%lld", g_tape_posK); 1076 mr_asprintf(pos_w_commas, "%s", commarize(tmp)); 1077 mr_free(tmp); 1035 mr_asprintf(pos_w_commas, "%lld", g_tape_posK); 1078 1036 mr_asprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas); 1079 1037 mr_free(pos_w_commas);
Note:
See TracChangeset
for help on using the changeset viewer.