[1178] | 1 | /*
|
---|
| 2 | $Id: libmondo-string.c 1178 2007-02-17 01:27:26Z bruno $
|
---|
| 3 | */
|
---|
[1] | 4 |
|
---|
| 5 | /**
|
---|
| 6 | * @file
|
---|
| 7 | * Functions for handling strings.
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | #include "my-stuff.h"
|
---|
[1080] | 11 | #include "mr_mem.h"
|
---|
[1168] | 12 | #include "mr_str.h"
|
---|
| 13 |
|
---|
[1] | 14 | #include "mondostructures.h"
|
---|
| 15 | #include "libmondo-string.h"
|
---|
| 16 | #include "libmondo-files-EXT.h"
|
---|
[1178] | 17 | #include "newt-specific-EXT.h"
|
---|
[1] | 18 | #include "libmondo-tools-EXT.h"
|
---|
[1178] | 19 | #include <math.h>
|
---|
[1] | 20 |
|
---|
| 21 | /*@unused@*/
|
---|
[128] | 22 | //static char cvsid[] = "$Id: libmondo-string.c 1178 2007-02-17 01:27:26Z bruno $";
|
---|
[1] | 23 |
|
---|
| 24 | extern int g_current_media_number;
|
---|
| 25 | extern long long g_tape_posK;
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | * @addtogroup stringGroup
|
---|
| 29 | * @{
|
---|
| 30 | */
|
---|
| 31 | /**
|
---|
| 32 | * Build a partition name from a drive and a partition number.
|
---|
| 33 | * @param drive The drive basename of the partition name (e.g. /dev/hda)
|
---|
| 34 | * @param partno The partition number (e.g. 1)
|
---|
| 35 | * @param partition Where to put the partition name (e.g. /dev/hda1)
|
---|
| 36 | * @return @p partition.
|
---|
| 37 | * @note If @p drive ends in a digit, then 'p' (on Linux) or 's' (on *BSD) is added before @p partno.
|
---|
| 38 | */
|
---|
[128] | 39 | char *build_partition_name(char *partition, const char *drive, int partno)
|
---|
[1] | 40 | {
|
---|
[1178] | 41 | char *p = NULL;
|
---|
| 42 | char *c = NULL;
|
---|
[1] | 43 |
|
---|
[128] | 44 | assert(partition != NULL);
|
---|
| 45 | assert_string_is_neither_NULL_nor_zerolength(drive);
|
---|
| 46 | assert(partno >= 0);
|
---|
[1] | 47 |
|
---|
[128] | 48 | p = strcpy(partition, drive);
|
---|
| 49 | /* is this a devfs device path? */
|
---|
| 50 | c = strrchr(partition, '/');
|
---|
| 51 | if (c && strncmp(c, "/disc", 5) == 0) {
|
---|
| 52 | /* yup it's devfs, return the "part" path */
|
---|
[1178] | 53 | /* format /dev/.../disc */
|
---|
[128] | 54 | strcpy(c + 1, "part");
|
---|
| 55 | p = c + 5;
|
---|
| 56 | } else {
|
---|
| 57 | p += strlen(p);
|
---|
| 58 | if (isdigit(p[-1])) {
|
---|
| 59 | *p++ =
|
---|
[1] | 60 | #ifdef BSD
|
---|
[128] | 61 | 's';
|
---|
[1] | 62 | #else
|
---|
[128] | 63 | 'p';
|
---|
[1] | 64 | #endif
|
---|
[128] | 65 | }
|
---|
| 66 | }
|
---|
| 67 | sprintf(p, "%d", partno);
|
---|
| 68 | return (partition);
|
---|
[1] | 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | /**
|
---|
| 73 | * Pad a string on both sides so it appears centered.
|
---|
| 74 | * @param in_out The string to be center-padded (modified).
|
---|
| 75 | * @param width The width of the final result.
|
---|
| 76 | */
|
---|
[128] | 77 | void center_string(char *in_out, int width)
|
---|
[1] | 78 | {
|
---|
[1178] | 79 | char *scratch = NULL;
|
---|
| 80 | char *out = NULL;
|
---|
| 81 | char *p = NULL;
|
---|
| 82 | int i = 0; /* purpose */
|
---|
| 83 | int len = 0; /* purpose */
|
---|
| 84 | int mid = 0; /* purpose */
|
---|
| 85 | int x = 0; /* purpose */
|
---|
[1] | 86 |
|
---|
[128] | 87 | assert(in_out != NULL);
|
---|
| 88 | assert(width > 2);
|
---|
[1] | 89 |
|
---|
[128] | 90 | if (strlen(in_out) == 0) {
|
---|
| 91 | return;
|
---|
| 92 | }
|
---|
[1178] | 93 | mr_asprintf(&scratch, in_out);
|
---|
| 94 | mr_strip_spaces(scratch);
|
---|
[128] | 95 | len = (int) strlen(scratch);
|
---|
| 96 | mid = width / 2;
|
---|
| 97 | x = mid - len / 2;
|
---|
| 98 | for (i = 0; i < x; i++) {
|
---|
| 99 | in_out[i] = ' ';
|
---|
| 100 | }
|
---|
| 101 | in_out[i] = '\0';
|
---|
| 102 | strcat(in_out, scratch);
|
---|
[841] | 103 | for (i = x + len ; i < width - 1; i++) {
|
---|
| 104 | in_out[i] = ' ';
|
---|
| 105 | }
|
---|
| 106 | in_out[i] = '\0';
|
---|
[1] | 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 |
|
---|
[128] | 112 | inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin)
|
---|
[1] | 113 | {
|
---|
| 114 | char *p, *q;
|
---|
[128] | 115 |
|
---|
| 116 | for (p = sin, q = sout; *p != '\0'; *(q++) = *(p++)) {
|
---|
| 117 | if (strchr("[]*?", *p)) {
|
---|
| 118 | *(q++) = '\\';
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | *q = *p; // for the final '\0'
|
---|
[1] | 122 | }
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | /**
|
---|
| 126 | * Turn an entry from the RAID editor's disklist into a GUI-friendly string.
|
---|
| 127 | * The format is: the device left-aligned and padded to 24 places, followed by a space and the
|
---|
| 128 | * index, right-aligned and padded to eight places. The total string length
|
---|
| 129 | * is exactly 33.
|
---|
| 130 | * @param disklist The disklist to operate on.
|
---|
| 131 | * @param lino The line number from @p disklist to convert to a string.
|
---|
| 132 | * @return The string form of the disklist entry.
|
---|
| 133 | * @note The returned string points to static storage and will be overwritten with each call.
|
---|
| 134 | */
|
---|
[128] | 135 | char *disklist_entry_to_string(struct list_of_disks *disklist, int lino)
|
---|
[1] | 136 | {
|
---|
| 137 |
|
---|
[128] | 138 | /*@ buffers ********************************************************** */
|
---|
| 139 | static char output[MAX_STR_LEN];
|
---|
[1] | 140 |
|
---|
[128] | 141 | assert(disklist != NULL);
|
---|
[1] | 142 |
|
---|
[128] | 143 | sprintf(output, "%-24s %8d", disklist->el[lino].device,
|
---|
| 144 | disklist->el[lino].index);
|
---|
| 145 | return (output);
|
---|
[1] | 146 | }
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | /**
|
---|
| 150 | * Turn a "friendly" sizestring into a number of megabytes.
|
---|
| 151 | * Supports the suffixes 'k'/'K', 'm'/'M', and 'g'/'G'. Calls
|
---|
| 152 | * fatal_error() if an unknown suffix is encountered.
|
---|
| 153 | * @param incoming The sizestring to convert (e.g. "40m", "2g").
|
---|
| 154 | * @return The size in megabytes.
|
---|
| 155 | */
|
---|
[128] | 156 | long friendly_sizestr_to_sizelong(char *incoming)
|
---|
[1] | 157 | {
|
---|
[1178] | 158 | long outval = 0L;
|
---|
| 159 | int i = 0;
|
---|
| 160 | char *tmp = NULL;
|
---|
| 161 | char ch = ' ';
|
---|
[1] | 162 |
|
---|
[128] | 163 | assert_string_is_neither_NULL_nor_zerolength(incoming);
|
---|
[1] | 164 |
|
---|
[128] | 165 | if (!incoming[0]) {
|
---|
[1178] | 166 | return(0L);
|
---|
[128] | 167 | }
|
---|
| 168 | if (strchr(incoming, '.')) {
|
---|
| 169 | fatal_error("Please use integers only. No decimal points.");
|
---|
| 170 | }
|
---|
[1178] | 171 | mr_asprintf(&tmp, "%s", incoming);
|
---|
[128] | 172 | i = (int) strlen(tmp);
|
---|
| 173 | if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') {
|
---|
| 174 | tmp[i - 1] = '\0';
|
---|
| 175 | }
|
---|
| 176 | for (i = 0; i < (int) strlen(tmp) && isdigit(tmp[i]); i++);
|
---|
| 177 | ch = tmp[i];
|
---|
| 178 | tmp[i] = '\0';
|
---|
| 179 | outval = atol(tmp);
|
---|
[1178] | 180 | mr_free(tmp);
|
---|
| 181 |
|
---|
[128] | 182 | if (ch == 'g' || ch == 'G') {
|
---|
| 183 | outval = outval * 1024;
|
---|
| 184 | } else if (ch == 'k' || ch == 'K') {
|
---|
| 185 | outval = outval / 1024;
|
---|
| 186 | } else if (ch == 't' || ch == 'T') // terabyte
|
---|
| 187 | {
|
---|
| 188 | outval *= 1048576;
|
---|
| 189 | } else if (ch == 'Y' || ch == 'y') // yottabyte - the biggest measure in the info file
|
---|
| 190 | {
|
---|
| 191 | log_it
|
---|
| 192 | ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes of data?!?!");
|
---|
| 193 | popup_and_OK
|
---|
[1178] | 194 | (_("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)"));
|
---|
[128] | 195 | fatal_error("Integer overflow.");
|
---|
| 196 | } else if (ch != 'm' && ch != 'M') {
|
---|
[1178] | 197 | mr_asprintf(&tmp, "Re: parameter '%s' - bad multiplier ('%c')",
|
---|
| 198 | incoming, ch);
|
---|
[128] | 199 | fatal_error(tmp);
|
---|
| 200 | }
|
---|
| 201 | return (outval);
|
---|
[1] | 202 | }
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | /**
|
---|
| 206 | * Turn a marker byte (e.g. BLK_START_OF_BACKUP) into a string (e.g. "BLK_START_OF_BACKUP").
|
---|
| 207 | * Unknown markers are identified as "BLK_UNKNOWN (%d)" where %d is the decimal value.
|
---|
| 208 | * @param marker The marker byte to stringify.
|
---|
| 209 | * @return @p marker as a string.
|
---|
| 210 | * @note The returned string points to static storage that will be overwritten with each call.
|
---|
| 211 | */
|
---|
[128] | 212 | char *marker_to_string(int marker)
|
---|
[1] | 213 | {
|
---|
[128] | 214 | /*@ buffer ****************************************************** */
|
---|
| 215 | static char outstr[MAX_STR_LEN];
|
---|
[1] | 216 |
|
---|
| 217 |
|
---|
[128] | 218 | /*@ end vars *************************************************** */
|
---|
[1] | 219 |
|
---|
[128] | 220 | switch (marker) {
|
---|
| 221 | case BLK_START_OF_BACKUP:
|
---|
| 222 | strcpy(outstr, "BLK_START_OF_BACKUP");
|
---|
| 223 | break;
|
---|
| 224 | case BLK_START_OF_TAPE:
|
---|
| 225 | strcpy(outstr, "BLK_START_OF_TAPE");
|
---|
| 226 | break;
|
---|
| 227 | case BLK_START_AN_AFIO_OR_SLICE:
|
---|
| 228 | strcpy(outstr, "BLK_START_AN_AFIO_OR_SLICE");
|
---|
| 229 | break;
|
---|
| 230 | case BLK_STOP_AN_AFIO_OR_SLICE:
|
---|
| 231 | strcpy(outstr, "BLK_STOP_AN_AFIO_OR_SLICE");
|
---|
| 232 | break;
|
---|
| 233 | case BLK_START_AFIOBALLS:
|
---|
| 234 | strcpy(outstr, "BLK_START_AFIOBALLS");
|
---|
| 235 | break;
|
---|
| 236 | case BLK_STOP_AFIOBALLS:
|
---|
| 237 | strcpy(outstr, "BLK_STOP_AFIOBALLS");
|
---|
| 238 | break;
|
---|
| 239 | case BLK_STOP_BIGGIEFILES:
|
---|
| 240 | strcpy(outstr, "BLK_STOP_BIGGIEFILES");
|
---|
| 241 | break;
|
---|
| 242 | case BLK_START_A_NORMBIGGIE:
|
---|
| 243 | strcpy(outstr, "BLK_START_A_NORMBIGGIE");
|
---|
| 244 | break;
|
---|
| 245 | case BLK_START_A_PIHBIGGIE:
|
---|
| 246 | strcpy(outstr, "BLK_START_A_PIHBIGGIE");
|
---|
| 247 | break;
|
---|
| 248 | case BLK_START_EXTENDED_ATTRIBUTES:
|
---|
| 249 | strcpy(outstr, "BLK_START_EXTENDED_ATTRIBUTES");
|
---|
| 250 | break;
|
---|
| 251 | case BLK_STOP_EXTENDED_ATTRIBUTES:
|
---|
| 252 | strcpy(outstr, "BLK_STOP_EXTENDED_ATTRIBUTES");
|
---|
| 253 | break;
|
---|
| 254 | case BLK_START_EXAT_FILE:
|
---|
| 255 | strcpy(outstr, "BLK_START_EXAT_FILE");
|
---|
| 256 | break;
|
---|
| 257 | case BLK_STOP_EXAT_FILE:
|
---|
| 258 | strcpy(outstr, "BLK_STOP_EXAT_FILE");
|
---|
| 259 | break;
|
---|
| 260 | case BLK_START_BIGGIEFILES:
|
---|
| 261 | strcpy(outstr, "BLK_START_BIGGIEFILES");
|
---|
| 262 | break;
|
---|
| 263 | case BLK_STOP_A_BIGGIE:
|
---|
| 264 | strcpy(outstr, "BLK_STOP_A_BIGGIE");
|
---|
| 265 | break;
|
---|
| 266 | case BLK_END_OF_TAPE:
|
---|
| 267 | strcpy(outstr, "BLK_END_OF_TAPE");
|
---|
| 268 | break;
|
---|
| 269 | case BLK_END_OF_BACKUP:
|
---|
| 270 | strcpy(outstr, "BLK_END_OF_BACKUP");
|
---|
| 271 | break;
|
---|
| 272 | case BLK_ABORTED_BACKUP:
|
---|
| 273 | strcpy(outstr, "BLK_ABORTED_BACKUP");
|
---|
| 274 | break;
|
---|
| 275 | case BLK_START_FILE:
|
---|
| 276 | strcpy(outstr, "BLK_START_FILE");
|
---|
| 277 | break;
|
---|
| 278 | case BLK_STOP_FILE:
|
---|
| 279 | strcpy(outstr, "BLK_STOP_FILE");
|
---|
| 280 | break;
|
---|
| 281 | default:
|
---|
| 282 | sprintf(outstr, "BLK_UNKNOWN (%d)", marker);
|
---|
| 283 | break;
|
---|
| 284 | }
|
---|
| 285 | return (outstr);
|
---|
[1] | 286 | }
|
---|
| 287 |
|
---|
| 288 |
|
---|
| 289 | /**
|
---|
| 290 | * Turn a line from the mountlist into a GUI-friendly string.
|
---|
| 291 | * The format is as follows: the left-aligned @p device field padded to 24 places,
|
---|
| 292 | * a space, the left-aligned @p mountpoint field again padded to 24 places, a space,
|
---|
| 293 | * the left-aligned @p format field padded to 10 places, a space, and the right-aligned
|
---|
| 294 | * @p size field (in MB) padded to 8 places. The total string length is exactly 69.
|
---|
| 295 | * @param mountlist The mountlist to operate on.
|
---|
| 296 | * @param lino The line number in @p mountlist to stringify.
|
---|
| 297 | * @return The string form of <tt>mountlist</tt>-\>el[<tt>lino</tt>].
|
---|
| 298 | * @note The returned string points to static storage and will be overwritten with each call.
|
---|
| 299 | */
|
---|
[128] | 300 | char *mountlist_entry_to_string(struct mountlist_itself *mountlist,
|
---|
| 301 | int lino)
|
---|
[1] | 302 | {
|
---|
| 303 |
|
---|
[128] | 304 | /*@ buffer *********************************************************** */
|
---|
| 305 | static char output[MAX_STR_LEN];
|
---|
[1] | 306 |
|
---|
[128] | 307 | assert(mountlist != NULL);
|
---|
[1] | 308 |
|
---|
[128] | 309 | sprintf(output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device,
|
---|
| 310 | mountlist->el[lino].mountpoint, mountlist->el[lino].format,
|
---|
| 311 | mountlist->el[lino].size / 1024);
|
---|
| 312 | return (output);
|
---|
[1] | 313 | }
|
---|
| 314 |
|
---|
| 315 |
|
---|
| 316 | /**
|
---|
| 317 | * Generate a friendly string containing "X blah blah disk(s)"
|
---|
| 318 | * @param noof_disks The number of disks (the X).
|
---|
| 319 | * @param label The "blah blah" part in the middle. If you leave this blank
|
---|
| 320 | * there will be a weird double space in the middle, so pass *something*.
|
---|
| 321 | * @return The string containing "X blah blah disk(s)".
|
---|
| 322 | * @note The returned string points to static storage and will be overwritten with each call.
|
---|
| 323 | */
|
---|
[128] | 324 | char *number_of_disks_as_string(int noof_disks, char *label)
|
---|
[1] | 325 | {
|
---|
| 326 |
|
---|
[128] | 327 | /*@ buffers ********************************************************* */
|
---|
| 328 | static char output[MAX_STR_LEN];
|
---|
[1] | 329 |
|
---|
[128] | 330 | /*@ char ******************************************************** */
|
---|
[1178] | 331 | char p = NULL;
|
---|
[1] | 332 |
|
---|
[128] | 333 | assert(label != NULL);
|
---|
[1] | 334 |
|
---|
[128] | 335 | if (noof_disks > 1) {
|
---|
| 336 | p = 's';
|
---|
| 337 | } else {
|
---|
| 338 | p = ' ';
|
---|
| 339 | }
|
---|
| 340 | sprintf(output, "%d %s disk%c", noof_disks, label, p);
|
---|
| 341 | while (strlen(output) < 14) {
|
---|
| 342 | strcat(output, " ");
|
---|
| 343 | }
|
---|
| 344 | return (output);
|
---|
[1] | 345 | }
|
---|
| 346 |
|
---|
| 347 |
|
---|
| 348 |
|
---|
| 349 | /**
|
---|
| 350 | * Change @p i into a friendly string. If @p i is \<= 10 then write out the
|
---|
| 351 | * number (e.g. "one", "two", ..., "nine", "ten", "11", ...).
|
---|
| 352 | * @param i The number to stringify.
|
---|
| 353 | * @return The string form of @p i.
|
---|
| 354 | * @note The returned value points to static strorage that will be overwritten with each call.
|
---|
| 355 | */
|
---|
[128] | 356 | char *number_to_text(int i)
|
---|
[1] | 357 | {
|
---|
| 358 |
|
---|
[128] | 359 | /*@ buffers ***************************************************** */
|
---|
| 360 | static char output[MAX_STR_LEN];
|
---|
[1] | 361 |
|
---|
| 362 |
|
---|
[128] | 363 | /*@ end vars *************************************************** */
|
---|
[1] | 364 |
|
---|
[128] | 365 | switch (i) {
|
---|
| 366 | case 0:
|
---|
| 367 | strcpy(output, "zero");
|
---|
| 368 | break;
|
---|
| 369 | case 1:
|
---|
| 370 | strcpy(output, "one");
|
---|
| 371 | break;
|
---|
| 372 | case 2:
|
---|
| 373 | strcpy(output, "two");
|
---|
| 374 | break;
|
---|
| 375 | case 3:
|
---|
| 376 | strcpy(output, "three");
|
---|
| 377 | break;
|
---|
| 378 | case 4:
|
---|
| 379 | strcpy(output, "four");
|
---|
| 380 | break;
|
---|
| 381 | case 5:
|
---|
| 382 | strcpy(output, "five");
|
---|
| 383 | break;
|
---|
| 384 | case 6:
|
---|
| 385 | strcpy(output, "six");
|
---|
| 386 | break;
|
---|
| 387 | case 7:
|
---|
| 388 | strcpy(output, "seven");
|
---|
| 389 | break;
|
---|
| 390 | case 8:
|
---|
| 391 | strcpy(output, "eight");
|
---|
| 392 | break;
|
---|
| 393 | case 9:
|
---|
| 394 | strcpy(output, "nine");
|
---|
| 395 | case 10:
|
---|
| 396 | strcpy(output, "ten");
|
---|
| 397 | default:
|
---|
| 398 | sprintf(output, "%d", i);
|
---|
| 399 | }
|
---|
| 400 | return (output);
|
---|
[1] | 401 | }
|
---|
| 402 |
|
---|
| 403 |
|
---|
| 404 | /**
|
---|
| 405 | * Replace all occurences of @p token with @p value while copying @p ip to @p output.
|
---|
| 406 | * @param ip The input string containing zero or more <tt>token</tt>s.
|
---|
| 407 | * @param output The output string written with the <tt>token</tt>s replaced by @p value.
|
---|
| 408 | * @param token The token to be relaced with @p value.
|
---|
| 409 | * @param value The value to replace @p token.
|
---|
| 410 | */
|
---|
[128] | 411 | void resolve_naff_tokens(char *output, char *ip, char *value, char *token)
|
---|
[1] | 412 | {
|
---|
[128] | 413 | /*@ buffers *** */
|
---|
| 414 | char *input;
|
---|
[1] | 415 |
|
---|
[128] | 416 | /*@ pointers * */
|
---|
| 417 | char *p;
|
---|
[1] | 418 |
|
---|
[1080] | 419 | input = mr_malloc(2000);
|
---|
[128] | 420 | assert_string_is_neither_NULL_nor_zerolength(ip);
|
---|
| 421 | assert_string_is_neither_NULL_nor_zerolength(token);
|
---|
| 422 | assert(value != NULL);
|
---|
[1] | 423 |
|
---|
[128] | 424 | strcpy(output, ip); /* just in case the token doesn't appear in string at all */
|
---|
| 425 | for (strcpy(input, ip); strstr(input, token); strcpy(input, output)) {
|
---|
| 426 | strcpy(output, input);
|
---|
| 427 | p = strstr(output, token);
|
---|
| 428 | *p = '\0';
|
---|
| 429 | strcat(output, value);
|
---|
| 430 | p = strstr(input, token) + strlen(token);
|
---|
| 431 | strcat(output, p);
|
---|
| 432 | }
|
---|
[1080] | 433 | mr_free(input);
|
---|
[1] | 434 | }
|
---|
| 435 |
|
---|
| 436 |
|
---|
| 437 | /**
|
---|
| 438 | * Generate the filename of slice @p sliceno of biggiefile @p bigfileno
|
---|
| 439 | * in @p path with suffix @p s. The format is as follows: @p path, followed
|
---|
| 440 | * by "/slice-" and @p bigfileno zero-padded to 7 places, followed by
|
---|
| 441 | * a dot and @p sliceno zero-padded to 5 places, followed by ".dat" and the
|
---|
| 442 | * suffix. The string is a minimum of 24 characters long.
|
---|
| 443 | * @param bigfileno The biggiefile number. Starts from 0.
|
---|
| 444 | * @param sliceno The slice number of biggiefile @p bigfileno. 0 is a "header"
|
---|
| 445 | * slice (no suffix) containing the biggiestruct, then are the compressed
|
---|
| 446 | * slices, then an empty uncompressed "trailer" slice.
|
---|
| 447 | * @param path The path to append (with a / in the middle) to the slice filename.
|
---|
| 448 | * @param s If not "" then add a "." and this to the end.
|
---|
| 449 | * @return The slice filename.
|
---|
| 450 | * @note The returned value points to static storage and will be overwritten with each call.
|
---|
| 451 | */
|
---|
[128] | 452 | char *slice_fname(long bigfileno, long sliceno, char *path, char *s)
|
---|
[1] | 453 | {
|
---|
| 454 |
|
---|
[128] | 455 | /*@ buffers **************************************************** */
|
---|
| 456 | static char output[MAX_STR_LEN];
|
---|
[1178] | 457 | char *suffix = NULL;
|
---|
[1] | 458 |
|
---|
[128] | 459 | /*@ end vars *************************************************** */
|
---|
[1] | 460 |
|
---|
[128] | 461 | assert_string_is_neither_NULL_nor_zerolength(path);
|
---|
| 462 | if (s[0] != '\0') {
|
---|
[1178] | 463 | mr_asprintf(&suffix, ".%s", s);
|
---|
[128] | 464 | } else {
|
---|
[1178] | 465 | mr_asprintf(&suffix, "");
|
---|
[128] | 466 | }
|
---|
| 467 | sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno,
|
---|
| 468 | suffix);
|
---|
[1178] | 469 | mr_free(suffix);
|
---|
[128] | 470 | return (output);
|
---|
[1] | 471 | }
|
---|
| 472 |
|
---|
| 473 |
|
---|
| 474 | /**
|
---|
| 475 | * Generate a spinning symbol based on integer @p i.
|
---|
| 476 | * The symbol rotates through the characters / - \ | to form an ASCII "spinner"
|
---|
| 477 | * if successively written to the same location on screen.
|
---|
| 478 | * @param i The amount of progress or whatever else to use to determine the character
|
---|
| 479 | * for this iteration of the spinner.
|
---|
| 480 | * @return The character for this iteration.
|
---|
| 481 | */
|
---|
[128] | 482 | int special_dot_char(int i)
|
---|
[1] | 483 | {
|
---|
[128] | 484 | switch (i % 4) {
|
---|
| 485 | case 0:
|
---|
| 486 | return ('/');
|
---|
| 487 | case 1:
|
---|
| 488 | return ('-');
|
---|
| 489 | case 2:
|
---|
| 490 | return ('\\');
|
---|
| 491 | case 3:
|
---|
| 492 | return ('|');
|
---|
| 493 | default:
|
---|
| 494 | return ('.');
|
---|
| 495 | }
|
---|
| 496 | return ('.');
|
---|
[1] | 497 | }
|
---|
| 498 |
|
---|
| 499 |
|
---|
| 500 | /**
|
---|
| 501 | * Wrap @p flaws_str across three lines. The first two are no more than 74 characters wide.
|
---|
| 502 | * @param flaws_str The original string to split.
|
---|
| 503 | * @param flaws_str_A Where to put the first 74-or-less characters.
|
---|
| 504 | * @param flaws_str_B Where to put the second 74-or-less characters.
|
---|
| 505 | * @param flaws_str_C Where to put the rest.
|
---|
| 506 | * @param res The result of the original evaluate_mountlist() operation.
|
---|
| 507 | * @return TRUE if res == 0, FALSE otherwise.
|
---|
| 508 | */
|
---|
| 509 | bool
|
---|
[128] | 510 | spread_flaws_across_three_lines(char *flaws_str, char *flaws_str_A,
|
---|
| 511 | char *flaws_str_B, char *flaws_str_C,
|
---|
| 512 | int res)
|
---|
[1] | 513 | {
|
---|
| 514 |
|
---|
[128] | 515 | /*@ int ************************************************************* */
|
---|
| 516 | int i = 0;
|
---|
[1] | 517 |
|
---|
[128] | 518 | /*@ initialize ****************************************************** */
|
---|
| 519 | assert(flaws_str_A != NULL);
|
---|
| 520 | assert(flaws_str_B != NULL);
|
---|
| 521 | assert(flaws_str_C != NULL);
|
---|
| 522 | assert(flaws_str != NULL);
|
---|
[1] | 523 |
|
---|
[128] | 524 | flaws_str_A[0] = flaws_str_B[0] = flaws_str_C[0] = '\0';
|
---|
[1] | 525 |
|
---|
| 526 |
|
---|
[128] | 527 | if (!res && !strlen(flaws_str)) {
|
---|
| 528 | return (TRUE);
|
---|
| 529 | }
|
---|
| 530 | if (strlen(flaws_str) > 0) {
|
---|
| 531 | sprintf(flaws_str_A, "%s", flaws_str + 1);
|
---|
| 532 | }
|
---|
| 533 | if (strlen(flaws_str_A) >= 74) {
|
---|
| 534 | for (i = 74; flaws_str_A[i] != ' '; i--);
|
---|
| 535 | strcpy(flaws_str_B, flaws_str_A + i + 1);
|
---|
| 536 | flaws_str_A[i] = '\0';
|
---|
| 537 | }
|
---|
| 538 | if (strlen(flaws_str_B) >= 74) {
|
---|
| 539 | for (i = 74; flaws_str_B[i] != ' '; i--);
|
---|
| 540 | strcpy(flaws_str_C, flaws_str_B + i + 1);
|
---|
| 541 | flaws_str_B[i] = '\0';
|
---|
| 542 | }
|
---|
| 543 | if (res) {
|
---|
| 544 | return (FALSE);
|
---|
| 545 | } else {
|
---|
| 546 | return (TRUE);
|
---|
| 547 | }
|
---|
[1] | 548 | }
|
---|
| 549 |
|
---|
| 550 |
|
---|
| 551 | /**
|
---|
| 552 | * Compare @p stringA and @p stringB. This uses an ASCII sort for everything
|
---|
| 553 | * up to the digits on the end but a numerical sort for the digits on the end.
|
---|
| 554 | * @param stringA The first string to compare.
|
---|
| 555 | * @param stringB The second string to compare.
|
---|
| 556 | * @return The same as strcmp() - <0 if A<B, 0 if A=B, >0 if A>B.
|
---|
| 557 | * @note This function only does a numerical sort on the @e last set of numbers. If
|
---|
| 558 | * there are any in the middle those will be sorted ASCIIbetically.
|
---|
| 559 | */
|
---|
[128] | 560 | int strcmp_inc_numbers(char *stringA, char *stringB)
|
---|
[1] | 561 | {
|
---|
[128] | 562 | /*@ int ********************************************************* */
|
---|
| 563 | int i;
|
---|
| 564 | int start_of_numbers_in_A;
|
---|
| 565 | int start_of_numbers_in_B;
|
---|
| 566 | int res;
|
---|
[1] | 567 |
|
---|
[128] | 568 | /*@ long ******************************************************* */
|
---|
| 569 | long numA;
|
---|
| 570 | long numB;
|
---|
[1] | 571 |
|
---|
[128] | 572 | /*@ end vars *************************************************** */
|
---|
| 573 | assert(stringA != NULL);
|
---|
| 574 | assert(stringB != NULL);
|
---|
[1] | 575 |
|
---|
[128] | 576 | if (strlen(stringA) == strlen(stringB)) {
|
---|
| 577 | return (strcmp(stringA, stringB));
|
---|
| 578 | }
|
---|
| 579 | for (i = (int) strlen(stringA); i > 0 && isdigit(stringA[i - 1]); i--);
|
---|
| 580 | if (i == (int) strlen(stringA)) {
|
---|
| 581 | return (strcmp(stringA, stringB));
|
---|
| 582 | }
|
---|
| 583 | start_of_numbers_in_A = i;
|
---|
| 584 | for (i = (int) strlen(stringB); i > 0 && isdigit(stringB[i - 1]); i--);
|
---|
| 585 | if (i == (int) strlen(stringB)) {
|
---|
| 586 | return (strcmp(stringA, stringB));
|
---|
| 587 | }
|
---|
| 588 | start_of_numbers_in_B = i;
|
---|
| 589 | if (start_of_numbers_in_A != start_of_numbers_in_B) {
|
---|
| 590 | return (strcmp(stringA, stringB));
|
---|
| 591 | }
|
---|
| 592 | res = strncmp(stringA, stringB, (size_t) i);
|
---|
| 593 | if (res) {
|
---|
| 594 | return (res);
|
---|
| 595 | }
|
---|
| 596 | numA = atol(stringA + start_of_numbers_in_A);
|
---|
| 597 | numB = atol(stringB + start_of_numbers_in_B);
|
---|
| 598 | return ((int) (numA - numB));
|
---|
[1] | 599 | }
|
---|
| 600 |
|
---|
| 601 |
|
---|
| 602 |
|
---|
| 603 | /**
|
---|
| 604 | * Strip excess baggage from @p input, which should be a line from afio.
|
---|
| 605 | * For now this copies the whole line unless it finds a set of quotes, in which case
|
---|
| 606 | * it copies their contents only.
|
---|
| 607 | * @param input The input line (presumably from afio).
|
---|
| 608 | * @return The stripped line.
|
---|
| 609 | * @note The returned string points to static storage that will be overwritten with each call.
|
---|
| 610 | */
|
---|
[128] | 611 | char *strip_afio_output_line(char *input)
|
---|
[1] | 612 | {
|
---|
[128] | 613 | /*@ buffer ****************************************************** */
|
---|
| 614 | static char output[MAX_STR_LEN];
|
---|
[1] | 615 |
|
---|
[128] | 616 | /*@ pointers **************************************************** */
|
---|
| 617 | char *p;
|
---|
| 618 | char *q;
|
---|
| 619 | /*@ end vars *************************************************** */
|
---|
[1] | 620 |
|
---|
[128] | 621 | assert(input != NULL);
|
---|
| 622 | strcpy(output, input);
|
---|
| 623 | p = strchr(input, '\"');
|
---|
| 624 | if (p) {
|
---|
| 625 | q = strchr(++p, '\"');
|
---|
| 626 | if (q) {
|
---|
| 627 | strcpy(output, p);
|
---|
| 628 | *(strchr(output, '\"')) = '\0';
|
---|
| 629 | }
|
---|
[1] | 630 | }
|
---|
[128] | 631 | return (output);
|
---|
[1] | 632 | }
|
---|
| 633 |
|
---|
| 634 |
|
---|
| 635 | /**
|
---|
| 636 | * If there are double quotes "" around @p incoming then remove them.
|
---|
| 637 | * This does not affect other quotes that may be embedded within the string.
|
---|
| 638 | * @param incoming The string to trim quotes from (modified).
|
---|
| 639 | * @return @p incoming.
|
---|
| 640 | */
|
---|
[128] | 641 | char *trim_empty_quotes(char *incoming)
|
---|
[1] | 642 | {
|
---|
[128] | 643 | /*@ buffer ****************************************************** */
|
---|
| 644 | static char outgoing[MAX_STR_LEN];
|
---|
[1] | 645 |
|
---|
[128] | 646 | /*@ end vars *************************************************** */
|
---|
| 647 | assert(incoming != NULL);
|
---|
[1] | 648 |
|
---|
[128] | 649 | if (incoming[0] == '\"' && incoming[strlen(incoming) - 1] == '\"') {
|
---|
| 650 | strcpy(outgoing, incoming + 1);
|
---|
| 651 | outgoing[strlen(outgoing) - 1] = '\0';
|
---|
| 652 | } else {
|
---|
| 653 | strcpy(outgoing, incoming);
|
---|
| 654 | }
|
---|
| 655 | return (outgoing);
|
---|
[1] | 656 | }
|
---|
| 657 |
|
---|
| 658 |
|
---|
| 659 |
|
---|
| 660 |
|
---|
| 661 | /**
|
---|
| 662 | * Remove any partition info from @p partition, leaving just the drive name.
|
---|
| 663 | * @param partition The partition name soon-to-become drive name. (modified)
|
---|
| 664 | * @return @p partition.
|
---|
| 665 | */
|
---|
[128] | 666 | char *truncate_to_drive_name(char *partition)
|
---|
[1] | 667 | {
|
---|
[128] | 668 | int i = strlen(partition) - 1;
|
---|
[1178] | 669 | char *c = NULL;
|
---|
[1] | 670 |
|
---|
| 671 | #ifdef __FreeBSD__
|
---|
| 672 |
|
---|
[128] | 673 | if (islower(partition[i])) // BSD subpartition
|
---|
| 674 | i--;
|
---|
| 675 | if (partition[i - 1] == 's') {
|
---|
| 676 | while (isdigit(partition[i]))
|
---|
| 677 | i--;
|
---|
| 678 | i--;
|
---|
| 679 | }
|
---|
| 680 | partition[i + 1] = '\0';
|
---|
[1] | 681 |
|
---|
| 682 | #else
|
---|
| 683 |
|
---|
[128] | 684 | assert_string_is_neither_NULL_nor_zerolength(partition);
|
---|
| 685 | /* first see if it's a devfs style device */
|
---|
| 686 | c = strrchr(partition, '/');
|
---|
| 687 | if (c && strncmp(c, "/part", 5) == 0) {
|
---|
| 688 | /* yup it's devfs, return the "disc" path */
|
---|
[1178] | 689 | strncpy(c + 1, "disc", (size_t)5);
|
---|
[128] | 690 | return partition;
|
---|
| 691 | }
|
---|
[1] | 692 |
|
---|
[128] | 693 | for (i = strlen(partition); isdigit(partition[i - 1]); i--)
|
---|
| 694 | continue;
|
---|
| 695 | if (partition[i - 1] == 'p' && isdigit(partition[i - 2])) {
|
---|
| 696 | i--;
|
---|
| 697 | }
|
---|
| 698 | partition[i] = '\0';
|
---|
[1] | 699 |
|
---|
| 700 | #endif
|
---|
| 701 |
|
---|
[128] | 702 | return partition;
|
---|
[1] | 703 | }
|
---|
| 704 |
|
---|
| 705 |
|
---|
| 706 | /**
|
---|
| 707 | * Turn a RAID level number (-1 to 5) into a friendly string. The string
|
---|
| 708 | * is either "Linear RAID" for -1, or " RAID %-2d " (%d = @p raid_level)
|
---|
| 709 | * for anything else.
|
---|
| 710 | * @param raid_level The RAID level to stringify.
|
---|
| 711 | * @return The string form of @p raid_level.
|
---|
| 712 | * @note The returned value points to static storage that will be overwritten with each call.
|
---|
| 713 | */
|
---|
[128] | 714 | char *turn_raid_level_number_to_string(int raid_level)
|
---|
[1] | 715 | {
|
---|
| 716 |
|
---|
[128] | 717 | /*@ buffer ********************************************************** */
|
---|
| 718 | static char output[MAX_STR_LEN];
|
---|
[1] | 719 |
|
---|
| 720 |
|
---|
| 721 |
|
---|
[128] | 722 | if (raid_level >= 0) {
|
---|
| 723 | sprintf(output, " RAID %-2d ", raid_level);
|
---|
| 724 | } else {
|
---|
| 725 | sprintf(output, "Linear RAID");
|
---|
| 726 | }
|
---|
| 727 | return (output);
|
---|
[1] | 728 | }
|
---|
| 729 |
|
---|
| 730 |
|
---|
| 731 | /**
|
---|
| 732 | * Determine the severity (1-3, 1 being low) of the fact that
|
---|
| 733 | * @p fn changed in the live filesystem (verify/compare).
|
---|
| 734 | * @param fn The filename that changed.
|
---|
| 735 | * @param out_reason If non-NULL, a descriptive reason for the difference will be copied here.
|
---|
| 736 | * @return The severity (1-3).
|
---|
| 737 | */
|
---|
| 738 | int severity_of_difference(char *fn, char *out_reason)
|
---|
| 739 | {
|
---|
[1178] | 740 | int sev = 0;
|
---|
| 741 | char *reason = NULL;
|
---|
| 742 | char *filename = NULL;
|
---|
[1] | 743 |
|
---|
[1178] | 744 | // out_reason might be null on purpose, so don't bomb if it is :) OK?
|
---|
[128] | 745 | assert_string_is_neither_NULL_nor_zerolength(fn);
|
---|
| 746 | if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) {
|
---|
[1178] | 747 | mr_asprintf(&filename, fn + strlen(MNT_RESTORING));
|
---|
[128] | 748 | } else if (fn[0] != '/') {
|
---|
[1178] | 749 | mr_asprintf(&filename, "/%s", fn);
|
---|
[128] | 750 | } else {
|
---|
[1178] | 751 | mr_asprintf(&filename, fn);
|
---|
[128] | 752 | }
|
---|
[1] | 753 |
|
---|
[128] | 754 | if (!strncmp(filename, "/var/", 5)) {
|
---|
| 755 | sev = 2;
|
---|
[1178] | 756 | mr_asprintf(&reason,
|
---|
| 757 | _("/var's contents will change regularly, inevitably."));
|
---|
[128] | 758 | }
|
---|
| 759 | if (!strncmp(filename, "/home", 5)) {
|
---|
| 760 | sev = 2;
|
---|
[1178] | 761 | mr_asprintf(&reason,
|
---|
| 762 | _("It's in your /home partiton. Therefore, it is important."));
|
---|
[128] | 763 | }
|
---|
| 764 | if (!strncmp(filename, "/usr/", 5)) {
|
---|
| 765 | sev = 3;
|
---|
[1178] | 766 | mr_asprintf(&reason,
|
---|
| 767 | _("You may have installed/removed software during the backup."));
|
---|
[128] | 768 | }
|
---|
| 769 | if (!strncmp(filename, "/etc/", 5)) {
|
---|
| 770 | sev = 3;
|
---|
[1178] | 771 | mr_asprintf(&reason,
|
---|
| 772 | _("Do not edit config files while backing up your PC."));
|
---|
[128] | 773 | }
|
---|
| 774 | if (!strcmp(filename, "/etc/adjtime")
|
---|
| 775 | || !strcmp(filename, "/etc/mtab")) {
|
---|
| 776 | sev = 1;
|
---|
[1178] | 777 | mr_asprintf(&reason, _("This file changes all the time. It's OK."));
|
---|
[128] | 778 | }
|
---|
| 779 | if (!strncmp(filename, "/root/", 6)) {
|
---|
| 780 | sev = 3;
|
---|
[1178] | 781 | mr_asprintf(&reason,
|
---|
| 782 | _("Were you compiling/editing something in /root?"));
|
---|
[128] | 783 | }
|
---|
| 784 | if (!strncmp(filename, "/root/.", 7)) {
|
---|
| 785 | sev = 2;
|
---|
[1178] | 786 | mr_asprintf(&reason, _("Temp or 'dot' files changed in /root."));
|
---|
[128] | 787 | }
|
---|
| 788 | if (!strncmp(filename, "/var/lib/", 9)) {
|
---|
| 789 | sev = 2;
|
---|
[1178] | 790 | mr_asprintf(&reason, _("Did you add/remove software during backing?"));
|
---|
[128] | 791 | }
|
---|
| 792 | if (!strncmp(filename, "/var/lib/rpm", 12)) {
|
---|
| 793 | sev = 3;
|
---|
[1178] | 794 | mr_asprintf(&reason, _("Did you add/remove software during backing?"));
|
---|
[128] | 795 | }
|
---|
| 796 | if (!strncmp(filename, "/var/lib/slocate", 16)) {
|
---|
| 797 | sev = 1;
|
---|
[1178] | 798 | mr_asprintf(&reason,
|
---|
| 799 | _("The 'update' daemon ran during backup. This does not affect the integrity of your backup."));
|
---|
[128] | 800 | }
|
---|
| 801 | if (!strncmp(filename, "/var/log/", 9)
|
---|
| 802 | || strstr(filename, "/.xsession")
|
---|
| 803 | || !strcmp(filename + strlen(filename) - 4, ".log")) {
|
---|
| 804 | sev = 1;
|
---|
[1178] | 805 | mr_asprintf(&reason,
|
---|
| 806 | _("Log files change frequently as the computer runs. Fret not."));
|
---|
[128] | 807 | }
|
---|
| 808 | if (!strncmp(filename, "/var/spool", 10)) {
|
---|
| 809 | sev = 1;
|
---|
[1178] | 810 | mr_asprintf(&reason,
|
---|
| 811 | _("Background processes or printers were active. This does not affect the integrity of your backup."));
|
---|
[128] | 812 | }
|
---|
| 813 | if (!strncmp(filename, "/var/spool/mail", 10)) {
|
---|
| 814 | sev = 2;
|
---|
[1178] | 815 | mr_asprintf(&reason, _("Mail was sent/received during backup."));
|
---|
[128] | 816 | }
|
---|
| 817 | if (filename[strlen(filename) - 1] == '~') {
|
---|
| 818 | sev = 1;
|
---|
[1178] | 819 | mr_asprintf(&reason,
|
---|
| 820 | _("Backup copy of another file which was modified recently."));
|
---|
[128] | 821 | }
|
---|
| 822 | if (strstr(filename, "cache")) {
|
---|
| 823 | sev = 1;
|
---|
[1178] | 824 | mr_asprintf(&reason,
|
---|
| 825 | _("Part of a cache of data. Caches change from time to time. Don't worry."));
|
---|
[128] | 826 | }
|
---|
| 827 | if (!strncmp(filename, "/var/run/", 9)
|
---|
| 828 | || !strncmp(filename, "/var/lock", 8)
|
---|
| 829 | || strstr(filename, "/.DCOPserver") || strstr(filename, "/.MCOP")
|
---|
| 830 | || strstr(filename, "/.Xauthority")) {
|
---|
| 831 | sev = 1;
|
---|
[1178] | 832 | mr_asprintf(&reason,
|
---|
| 833 | _("Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."));
|
---|
[128] | 834 | }
|
---|
[1178] | 835 | mr_free(filename);
|
---|
| 836 |
|
---|
| 837 | if (sev == 0) {
|
---|
| 838 | sev = 3;
|
---|
| 839 | mr_asprintf(&reason,
|
---|
| 840 | _("Changed since backup. Consider running a differential backup in a day or two."));
|
---|
| 841 | }
|
---|
[128] | 842 | if (out_reason) {
|
---|
| 843 | strcpy(out_reason, reason);
|
---|
| 844 | }
|
---|
[1178] | 845 |
|
---|
[1080] | 846 | mr_free(reason);
|
---|
[128] | 847 | return (sev);
|
---|
[1] | 848 | }
|
---|
| 849 |
|
---|
| 850 |
|
---|
| 851 | /**
|
---|
| 852 | * Compare the filenames in two filelist entries (s_filelist_entry*) casted
|
---|
| 853 | * to void*.
|
---|
| 854 | * @param va The first filelist entry, cast as a @c void pointer.
|
---|
| 855 | * @param vb The second filelist entry, cast as a @c void pointer.
|
---|
| 856 | * @return The return value of strcmp().
|
---|
| 857 | */
|
---|
[128] | 858 | int compare_two_filelist_entries(void *va, void *vb)
|
---|
[1] | 859 | {
|
---|
[128] | 860 | static int res;
|
---|
| 861 | struct s_filelist_entry *fa, *fb;
|
---|
[1] | 862 |
|
---|
[128] | 863 | assert(va != NULL);
|
---|
| 864 | assert(vb != NULL);
|
---|
| 865 | fa = (struct s_filelist_entry *) va;
|
---|
| 866 | fb = (struct s_filelist_entry *) vb;
|
---|
| 867 | res = strcmp(fa->filename, fb->filename);
|
---|
| 868 | return (res);
|
---|
[1] | 869 | }
|
---|
| 870 |
|
---|
| 871 |
|
---|
| 872 | /**
|
---|
| 873 | * Generate a line intended to be passed to update_evalcall_form(), indicating
|
---|
| 874 | * the current media fill percentage (or number of kilobytes if size is not known).
|
---|
| 875 | * @param bkpinfo The backup media structure. Fields used:
|
---|
| 876 | * - @c bkpinfo->backup_media_type
|
---|
| 877 | * - @c bkpinfo->media_size
|
---|
| 878 | * - @c bkpinfo->scratchdir
|
---|
| 879 | * @return The string indicating media fill.
|
---|
| 880 | * @note The returned string points to static storage that will be overwritten with each call.
|
---|
| 881 | */
|
---|
[128] | 882 | char *percent_media_full_comment(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 883 | {
|
---|
[128] | 884 | /*@ int *********************************************** */
|
---|
[1178] | 885 | int percentage = 0;
|
---|
| 886 | int i = 0;
|
---|
| 887 | int j = 0;
|
---|
[1] | 888 |
|
---|
[128] | 889 | /*@ buffers ******************************************* */
|
---|
| 890 | static char outstr[MAX_STR_LEN];
|
---|
[1] | 891 |
|
---|
[128] | 892 | assert(bkpinfo != NULL);
|
---|
[1] | 893 |
|
---|
[1178] | 894 | if (bkpinfo->media_size[g_current_media_number] <= 0) {
|
---|
| 895 | sprintf(outstr, _("Volume %d: %'lld kilobytes archived so far"),
|
---|
| 896 | g_current_media_number, g_tape_posK);
|
---|
[128] | 897 | return (outstr);
|
---|
| 898 | }
|
---|
[1] | 899 |
|
---|
[1178] | 900 | /* update screen */
|
---|
[128] | 901 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 902 | percentage =
|
---|
| 903 | (int) (g_tape_posK / 10 /
|
---|
| 904 | bkpinfo->media_size[g_current_media_number]);
|
---|
| 905 | if (percentage > 100) {
|
---|
| 906 | percentage = 100;
|
---|
| 907 | }
|
---|
[1178] | 908 | sprintf(outstr, _("Volume %d: ["), g_current_media_number);
|
---|
[128] | 909 | } else {
|
---|
| 910 | percentage =
|
---|
| 911 | (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 /
|
---|
| 912 | bkpinfo->media_size[g_current_media_number]);
|
---|
| 913 | sprintf(outstr, "%s %d: [",
|
---|
[1178] | 914 | bkpinfo->backup_media_string,
|
---|
[128] | 915 | g_current_media_number);
|
---|
[1] | 916 | }
|
---|
[128] | 917 | for (j = 0; j < percentage; j += 5) {
|
---|
| 918 | strcat(outstr, "*");
|
---|
| 919 | }
|
---|
| 920 | for (; j < 100; j += 5) {
|
---|
| 921 | strcat(outstr, ".");
|
---|
| 922 | }
|
---|
| 923 | j = (int) strlen(outstr);
|
---|
[541] | 924 | sprintf(outstr + j, "] %d%% used", percentage);
|
---|
[128] | 925 | return (outstr);
|
---|
[1] | 926 | }
|
---|
| 927 |
|
---|
[1178] | 928 |
|
---|
| 929 |
|
---|
[1] | 930 | /**
|
---|
| 931 | * Get a string form of @p type_of_bkp.
|
---|
| 932 | * @param type_of_bkp The backup type to stringify.
|
---|
| 933 | * @return The stringification of @p type_of_bkp.
|
---|
| 934 | * @note The returned string points to static storage that will be overwritten with each call.
|
---|
| 935 | */
|
---|
| 936 | char *media_descriptor_string(t_bkptype type_of_bkp)
|
---|
| 937 | {
|
---|
[1178] | 938 | static char *type_of_backup = NULL;
|
---|
[128] | 939 |
|
---|
[1178] | 940 | if (!type_of_backup) {
|
---|
| 941 | malloc_string(type_of_backup);
|
---|
| 942 | }
|
---|
[128] | 943 |
|
---|
[1178] | 944 | switch (type_of_bkp) {
|
---|
| 945 | case dvd:
|
---|
| 946 | strcpy(type_of_backup, "DVD");
|
---|
| 947 | break;
|
---|
| 948 | case cdr:
|
---|
| 949 | strcpy(type_of_backup, "CDR");
|
---|
| 950 | break;
|
---|
| 951 | case cdrw:
|
---|
| 952 | strcpy(type_of_backup, "CDRW");
|
---|
| 953 | break;
|
---|
| 954 | case tape:
|
---|
| 955 | strcpy(type_of_backup, "tape");
|
---|
| 956 | break;
|
---|
| 957 | case cdstream:
|
---|
| 958 | strcpy(type_of_backup, "CDR");
|
---|
| 959 | break;
|
---|
| 960 | case udev:
|
---|
| 961 | strcpy(type_of_backup, "udev");
|
---|
| 962 | break;
|
---|
| 963 | case iso:
|
---|
| 964 | strcpy(type_of_backup, "ISO");
|
---|
| 965 | break;
|
---|
| 966 | case nfs:
|
---|
| 967 | strcpy(type_of_backup, "nfs");
|
---|
| 968 | break;
|
---|
| 969 | case usb:
|
---|
| 970 | strcpy(type_of_backup, "USB");
|
---|
| 971 | break;
|
---|
| 972 | default:
|
---|
| 973 | strcpy(type_of_backup, "ISO");
|
---|
| 974 | }
|
---|
| 975 | return (type_of_backup);
|
---|
[1] | 976 | }
|
---|
[1178] | 977 |
|
---|