Changeset 1185 in MondoRescue
- Timestamp:
- Feb 19, 2007, 1:51:26 AM (18 years ago)
- Location:
- trunk/mondo/src/common
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/src/common/Makefile.am
r1079 r1185 10 10 11 11 libmondo_a_SOURCES = libmondo-archive.c libmondo-devices.c libmondo-fifo.c \ 12 libmondo-msg.c \13 12 libmondo-filelist.c libmondo-files.c libmondo-fork.c \ 14 13 libmondo-mountlist.c libmondo-raid.c \ -
trunk/mondo/src/common/libmondo-devices-EXT.h
r783 r1185 32 32 extern int interactively_obtain_media_parameters_from_user(struct s_bkpinfo 33 33 *, bool); 34 35 34 extern void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, 36 35 int cd_number_i_want); -
trunk/mondo/src/common/libmondo-devices.h
r1106 r1185 30 30 bool); 31 31 32 33 34 32 void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, 35 33 int cd_number_i_want); -
trunk/mondo/src/common/libmondo-raid-EXT.h
r561 r1185 50 50 #else 51 51 extern void add_disk_to_raid_device(struct list_of_disks *disklist, 52 char *device_to_add, int i ndex);52 char *device_to_add, int idx); 53 53 #endif 54 54 -
trunk/mondo/src/common/libmondo-string-EXT.h
r783 r1185 9 9 int lino); 10 10 extern long friendly_sizestr_to_sizelong(char *incoming); 11 extern char *leftpad_string(char *incoming, int width);12 11 extern char *marker_to_string(int marker); 13 12 extern char *mountlist_entry_to_string(struct mountlist_itself *mountlist, … … 26 25 extern int strcmp_inc_numbers(char *stringA, char *stringB); 27 26 extern char *strip_afio_output_line(char *input); 28 extern void strip_spaces(char *in_out);29 27 extern char *trim_empty_quotes(char *incoming); 30 28 extern char *truncate_to_drive_name(char *partition); -
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 = '.'; -
trunk/mondo/src/common/libmondo-string.h
r783 r1185 22 22 int strcmp_inc_numbers(char *stringA, char *stringB); 23 23 char *strip_afio_output_line(char *input); 24 void strip_spaces(char *in_out);25 24 char *trim_empty_quotes(char *incoming); 26 25 char *truncate_to_drive_name(char *partition); -
trunk/mondo/src/common/libmondo-tools-EXT.h
r1106 r1185 6 6 extern void clean_up_KDE_desktop_if_necessary(void); 7 7 extern long get_time(void); 8 extern void (*log_debug_msg) (int debug_level, const char *szFile,9 const char *szFunction, int nLine,10 const char *fmt, ...);11 extern void standard_log_debug_msg(int debug_level, const char *szFile,12 const char *szFunction, int nLine,13 const char *fmt, ...);14 8 extern int read_cfg_var(char *config_file, char *label, char *value); 15 9 extern int write_cfg_var(char *config_file, char *label, char *value); -
trunk/mondo/src/common/libmondo-tools.c
r1106 r1185 10 10 #include "my-stuff.h" 11 11 #include "mr_mem.h" 12 #include "mr_msg.h" 12 13 #include "mr_file.h" 13 14 … … 24 25 #include <arpa/inet.h> 25 26 #endif 26 #include "mr_mem.h"27 27 28 28 /*@unused@*/ … … 199 199 200 200 201 char *get_architecture( )201 char *get_architecture(void) 202 202 { 203 203 #ifdef __IA32__ … … 205 205 #endif 206 206 #ifdef __X86_64__ 207 return ("x86 -64");207 return ("x86_64"); 208 208 #endif 209 209 #ifdef __IA64__ … … 215 215 216 216 217 double get_kernel_version( )217 double get_kernel_version(void) 218 218 { 219 219 char *p, *tmp; … … 242 242 243 243 244 245 246 247 244 /** 248 245 * Get the current time. 249 246 * @return number of seconds since the epoch. 250 247 */ 251 long get_time( )248 long get_time(void) 252 249 { 253 250 return (long) time((void *) 0); 254 251 } 255 256 257 258 259 260 252 261 253 … … 298 290 } 299 291 #endif 300 301 302 292 303 293 … … 354 344 char *mondo_mkisofs_sz = NULL; 355 345 char *command = NULL; 356 char *hostname = NULL, *ip_address = NULL; 346 char *hostname = NULL; 347 char *ip_address = NULL; 357 348 int retval = 0; 358 349 long avm = 0; … … 363 354 char *call_before_iso_user = NULL; 364 355 int rdsiz_MB; 356 char *iso_dev = NULL; 357 char *iso_mnt = NULL; 358 char *iso_tmp = NULL; 365 359 char *iso_path = NULL; 366 360 FILE *fd1 = NULL; … … 400 394 avm += atol(tmp); 401 395 mr_free(tmp); 402 tmp = call_program_and_get_last_line_of_output396 tmp1 = call_program_and_get_last_line_of_output 403 397 ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"); 404 398 avm += atol(tmp); … … 412 406 mr_free(tmp); 413 407 mr_asprintf(&command, "mount /dev/shm -t tmpfs %s -o size=%d%c", 414 408 g_tmpfs_mountpt, rdsiz_MB, 'm'); 415 409 run_program_and_log_output("cat /proc/cpuinfo", 5); 416 410 /* BERLIOS: rpm is not necessarily there ! */ … … 495 489 popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 496 490 fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 497 } 491 } 498 492 mr_free(tmp); 499 493 mr_free(command); … … 507 501 || bkpinfo->backup_media_type == cdr) { 508 502 if (!bkpinfo->manual_cd_tray) { 509 mr_ asprintf(&extra_cdrom_params, "-waiti ");503 mr_strcat(extra_cdrom_params, "-waiti "); 510 504 } 511 505 if (bkpinfo->backup_media_type == cdrw) { 512 if (extra_cdrom_params != NULL) { 513 mr_asprintf(&tmp, extra_cdrom_params); 514 mr_free(extra_cdrom_params); 515 mr_asprintf(&extra_cdrom_params, "%s blank=fast ", tmp); 516 } else { 517 mr_asprintf(&extra_cdrom_params, "blank=fast "); 518 } 506 mr_strcat(extra_cdrom_params, "blank=fast "); 519 507 } 520 508 tmp = find_home_of_exe("cdrecord"); … … 600 588 601 589 fd1 = mr_fopen(MONDORESTORECFG, "a"); 602 mr_fprintf(fd1, "iso-dev 590 mr_fprintf(fd1, "iso-dev=%s\n", iso_dev); 603 591 604 592 mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", … … 611 599 612 600 log_it("res of it = %s", iso_mnt); 613 mr_fprintf(fd1, "iso-mnt 601 mr_fprintf(fd1, "iso-mnt=%s\n", iso_mnt); 614 602 log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt)); 615 603 … … 617 605 if (strlen(iso_tmp) >= strlen(iso_mnt)) { 618 606 mr_asprintf(&iso_path, "%s", iso_tmp + strlen(iso_mnt)); 607 } else { 608 mr_asprintf(&iso_path, ""); 619 609 } 620 610 mr_free(iso_tmp); … … 622 612 623 613 log_it("isodir: %s", iso_path); 624 mr_fprintf(fd1, "isodir 614 mr_fprintf(fd1, "isodir=%s\n", iso_path); 625 615 mr_free(iso_path); 626 616 627 617 log_it("iso-prefix: %s", bkpinfo->prefix); 628 mr_fprintf(fd1, "iso-prefix 618 mr_fprintf(fd1, "iso-prefix=%s\n", bkpinfo->prefix); 629 619 630 620 mr_fclose(fd1); … … 648 638 } else { 649 639 mr_asprintf(&ip_address, "%s%s", inet_ntoa((struct in_addr) 650 *((struct in_addr 651 *) hent-> 652 h_addr)), 653 strchr(bkpinfo->nfs_mount, ':')); 640 *((struct in_addr *) hent->h_addr)), 641 strchr(bkpinfo->nfs_mount, ':')); 654 642 mr_allocstr(bkpinfo->nfs_mount, ip_address); 655 643 mr_free(ip_address); … … 684 672 return (retval); 685 673 } 686 687 674 688 675 … … 710 697 } 711 698 712 unlink(MONDO_TRACEFILE);713 699 run_program_and_log_output("rm -Rf /tmp/changed.files*", FALSE); 714 700 if ((g_mondo_home = find_and_store_mondoarchives_home()) == NULL) { … … 811 797 char *command = NULL; 812 798 char *out_sz = NULL; 813 long res ;799 long res = 0L; 814 800 815 801 assert_string_is_neither_NULL_nor_zerolength(partition); … … 822 808 823 809 mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 824 810 partition); 825 811 out_sz = call_program_and_get_last_line_of_output(command); 826 812 mr_free(command); 813 827 814 if (strlen(out_sz) == 0) { 828 815 return (-1); … … 832 819 return (res); 833 820 } 834 835 821 836 822 … … 1062 1048 return (0); 1063 1049 */ } else { 1064 mr_asprintf(&command, "grep '%s .*' %s| cut -d' 1050 mr_asprintf(&command, "grep '%s .*' %s| cut -d'=' -f2,3,4,5", 1065 1051 label, config_file); 1066 1052 value = call_program_and_get_last_line_of_output(command); … … 1110 1096 void mount_boot_if_necessary() 1111 1097 { 1112 char *tmp ;1113 char *tmp1 ;1114 char *command ;1098 char *tmp = NULL; 1099 char *tmp1 = NULL; 1100 char *command = NULL; 1115 1101 1116 1102 mr_msg(1, "Started sub"); … … 1140 1126 mr_asprintf(&g_boot_mountpt, tmp); 1141 1127 mr_asprintf(&tmp1, 1142 1143 1128 "%s (your /boot partition) is not mounted. I'll mount it before backing up", 1129 g_boot_mountpt); 1144 1130 log_it(tmp1); 1145 1131 mr_free(tmp1); … … 1190 1176 1191 1177 1192 1193 1178 /** 1194 1179 * Write a line to a configuration file. Writes a line of the form, … … 1202 1187 { 1203 1188 /*@ buffers ***************************************************** */ 1204 char *command ;1205 char *tempfile ;1206 char *tmp ;1189 char *command = NULL; 1190 char *tempfile = NULL; 1191 char *tmp = NULL; 1207 1192 1208 1193 … … 1238 1223 return (0); 1239 1224 } 1225 1240 1226 1241 1227 /** -
trunk/mondo/src/common/libmondo-tools.h
r1106 r1185 9 9 10 10 long get_time(void); 11 extern void (*log_debug_msg) (int debug_level, const char *szFile,12 const char *szFunction, int nLine,13 const char *fmt, ...);14 void standard_log_debug_msg(int debug_level, const char *szFile,15 const char *szFunction, int nLine,16 const char *fmt, ...);17 11 int read_cfg_var(char *config_file, char *label, char *value); 18 12 int write_cfg_var(char *config_file, char *label, char *value); -
trunk/mondo/src/common/libmondo-verify.c
r1086 r1185 9 9 #include "my-stuff.h" 10 10 #include "mr_mem.h" 11 #include "mr_msg.h" 12 11 13 #include "mondostructures.h" 12 14 #include "libmondo-verify.h" … … 18 20 #include "libmondo-devices-EXT.h" 19 21 #include "libmondo-tools-EXT.h" 20 #include "mr_mem.h"21 22 22 23 /*@unused@*/ … … 50 51 { 51 52 /*@ buffer ********************************************************** */ 52 char *command ;53 char *afio_found_changes ;53 char *command = NULL; 54 char *afio_found_changes = NULL; 54 55 55 56 /*@ int ************************************************************* */ … … 66 67 sync(); 67 68 68 /* s-printf (command,69 "grep \"afio: \" %s | awk '{j=substr($0,8); i=index(j,\": \");printf \"/%%s\\n\",substr(j,1,i-2);}' | sort -u | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"/dev/.*\" > %s",70 stderr_fname, afio_found_changes);71 */72 69 73 70 mr_msg(1, "Now scanning log file for 'afio: ' stuff"); … … 183 180 } 184 181 185 186 182 /** 187 183 * Verify all slices stored on the inserted CD (or a mounted ISO image). … … 197 193 { 198 194 195 /*@ buffer ********************************************************** */ 199 196 char *tmp = NULL; 200 197 char *tmp1 = NULL; … … 235 232 mr_asprintf(&sz_exe, "lzop"); 236 233 } else if (bkpinfo->use_gzip) { 237 strcpy(sz_exe, "gzip"); 238 } else if (bkpinfo->use_gzip) { 239 strcpy(sz_exe, "gzip"); 234 mr_asprintf(&sz_exe, "gzip"); 240 235 } else { 241 236 mr_asprintf(&sz_exe, "bzip2"); 242 237 } 243 238 } else { 244 mr_asprintf(&sz_exe, " 239 mr_asprintf(&sz_exe, ""); 245 240 } 246 241 … … 381 376 { 382 377 /*@ buffers ********************************************************* */ 383 char *command ;384 char *outlog ;378 char *command = NULL; 379 char *outlog = NULL; 385 380 char *tmp = NULL; 386 // char *p;387 381 388 382 /*@ pointers ******************************************************* */ 389 FILE *pin ;383 FILE *pin = NULL; 390 384 391 385 size_t n = 0; … … 399 393 log_it("Verifying fileset '%s'", tarball_fname); 400 394 401 /* chdir("/"); */402 395 mr_asprintf(&outlog, "%s/afio.log", bkpinfo->tmpdir); 403 396 … … 430 423 if (strstr(tarball_fname, ".star")) { 431 424 bkpinfo->use_star = TRUE; 432 if (strstr(tarball_fname, ".bz2")) 425 if (strstr(tarball_fname, ".bz2")) { 433 426 mr_asprintf(&command, 434 427 "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", … … 436 429 (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, 437 430 outlog); 431 } else { 432 mr_asprintf(&command,""); 433 } 438 434 } else { 439 435 bkpinfo->use_star = FALSE; … … 446 442 447 443 if (length_of_file(outlog) < 10) { 444 /* BERLIOS: This seems useless !! */ 448 445 mr_asprintf(&command, "cat %s >> %s", outlog, MONDO_LOGFILE); 449 446 } else { … … 488 485 mr_free(command); 489 486 490 /* chdir(old_pwd); */491 // s-printf (tmp, "uniq -u %s >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE);492 // paranoid_system (tmp);493 // unlink ("/tmp/mondo-verify.err");494 487 return (0); 495 488 } … … 543 536 544 537 /*@ buffers ********************************************************** */ 545 char *tmp ;546 char *tarball_fname ;538 char *tmp = NULL; 539 char *tarball_fname = NULL; 547 540 548 541 /*@ pointers ********************************************************* */ 549 char *p ;542 char *p = NULL; 550 543 551 544 assert(bkpinfo != NULL); … … 563 556 564 557 mr_asprintf(&tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p); 565 /* BERLIOS : useless566 mr_asprintf(&tmp, "Temporarily copying file from tape to '%s'",567 tarball_fname);568 log_it(tmp);569 mr_free(tmp);570 */571 558 read_file_from_stream_to_file(bkpinfo, tarball_fname, size); 572 559 res = verify_a_tarball(bkpinfo, tarball_fname); 573 560 if (res) { 574 mr_asprintf(&tmp, 575 "Afioball '%s' no longer matches your live filesystem", 576 p); 577 mr_msg(0, tmp); 578 mr_free(tmp); 561 mr_msg(0, "Afioball '%s' no longer matches your live filesystem", p); 579 562 retval++; 580 563 } … … 604 587 605 588 /*@ char ************************************************************ */ 606 char *test_file ;607 char *biggie_cksum ;608 char *orig_cksum ;609 char *tmp ;589 char *test_file = NULL; 590 char *biggie_cksum = NULL; 591 char *orig_cksum = NULL; 592 char *tmp = NULL; 610 593 char *slice_fnam = (char *) &res; 611 594 … … 626 609 } 627 610 mr_asprintf(&test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); 628 mr_asprintf(&tmp,629 "Temporarily copying biggiefile %s's slices from tape to '%s'",630 p, test_file);631 log_it(tmp);632 mr_free(tmp);633 611 for (res = 634 612 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); … … 704 682 705 683 /*@ buffers ***************************************************** */ 706 char *tmp ;684 char *tmp = NULL; 707 685 char *fname = (char *) &res; /* Should NOT be NULL */ 708 char *curr_xattr_list_fname ;709 char *curr_acl_list_fname ;686 char *curr_xattr_list_fname = NULL; 687 char *curr_acl_list_fname = NULL; 710 688 711 689 /*@ long long *************************************************** */ … … 772 750 } 773 751 mr_asprintf(&tmp, "Verifying fileset #%ld", current_afioball_number); 774 /*log_it(tmp); */775 752 update_progress_form(tmp); 776 753 mr_free(tmp); … … 824 801 /*@ buffers ******************************************************** */ 825 802 char *orig_fname = (char *) &ctrl_chr; /* Should NOT be NULL */ 826 char *logical_fname ;827 char *comment ;828 char *curr_xattr_list_fname ;829 char *curr_acl_list_fname ;803 char *logical_fname = NULL; 804 char *comment = NULL; 805 char *curr_xattr_list_fname = NULL; 806 char *curr_acl_list_fname = NULL; 830 807 /*@ pointers ******************************************************* */ 831 char *p ;808 char *p = NULL; 832 809 833 810 /*@ long long size ************************************************* */ … … 931 908 932 909 /*@ buffers ******************************************************** */ 933 char *mountpoint ;934 char *command ;935 char *tmp ;936 char *fname ;910 char *mountpoint = NULL; 911 char *command = NULL; 912 char *tmp = NULL; 913 char *fname = NULL; 937 914 #ifdef __FreeBSD__ 938 915 char mdd[32]; … … 991 968 log_to_screen(tmp); 992 969 mr_free(tmp); 970 mr_free(command); 993 971 return (1); 994 972 } … … 1014 992 verify_all_slices_on_CD(bkpinfo, mountpoint); 1015 993 994 mr_asprintf(&command, "umount %s", mountpoint); 1016 995 #ifdef __FreeBSD__ 1017 996 ret = 0; 1018 mr_asprintf(&command, "umount %s", mountpoint);1019 997 ret += system(command); 1020 1021 998 ret += kick_vn(mddevice); 1022 999 if (ret) 1023 1000 #else 1024 mr_asprintf(&command, "umount %s", mountpoint);1025 1026 1001 if (system(command)) 1027 1002 #endif … … 1067 1042 1068 1043 /*@ buffers ******************************************************** */ 1069 char *tmp ;1070 char *changed_files_fname ;1044 char *tmp = NULL; 1045 char *changed_files_fname = NULL; 1071 1046 1072 1047 /*@ long *********************************************************** */ … … 1089 1064 1090 1065 /* close tape; exit */ 1091 // fclose(g_tape_stream); <-- not needed; is handled by closein_tape()1092 1066 paranoid_system 1093 1067 ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null"); -
trunk/mondo/src/common/newt-specific.c
r1106 r1185 19 19 #include "my-stuff.h" 20 20 #include "mr_mem.h" 21 #include "mr_msg.h" 22 #include "mr_str.h" 23 21 24 #include "mondostructures.h" 22 25 #include "newt-specific.h" … … 27 30 #include "libmondo-fork-EXT.h" 28 31 #include "newt-specific-EXT.h" 29 #include "mr_mem.h"30 32 31 33 /*@unused@*/ … … 36 38 extern char *g_mondo_home; 37 39 extern char *ps_options; 38 40 extern char *ps_proc_id; 39 41 40 42 extern void set_signals(int); … … 65 67 *g_blurb_str_2, ///< The string for line 2 of the blurb in the progress form 66 68 *g_blurb_str_3; ///< The string for line 3 (updated continuously) of the blurb in the progress form 67 newtComponent g_isoform_main = NULL, ///< The evalcall form component itself 69 70 newtComponent g_isoform_main = NULL, ///< The evalcall form component itself 68 71 g_isoform_header = NULL, ///< The component for the evalcall form title 69 72 g_isoform_scale = NULL, ///< The progress bar component in the evalcall form 70 73 g_isoform_timeline = NULL, ///< The line of the evalcall form that shows the time elapsed/remaining 71 74 g_isoform_pcline = NULL; ///< The line of the evalcall form that shows the percent completed/remaining 75 72 76 long g_isoform_starttime; ///< The time (in seconds since the epoch) that the evalcall form was opened. 73 77 int g_isoform_old_progress = -1; ///< The most recent progress update of the evalcall form (percent). … … 79 83 int g_currentY = 3; ///< The row to write background progress messages to. Incremented each time a message is written. 80 84 extern int g_current_media_number; 81 85 pid_t g_main_pid = 0; ///< The PID of the main Mondo process. 82 86 long g_maximum_progress = 999; ///< The maximum amount of progress (100%) for the currently opened progress form. 83 87 long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form. … … 85 89 bool g_text_mode = TRUE; ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface. 86 90 bool g_called_by_xmondo = FALSE; ///< @bug Unneeded w/current XMondo. 87 char *g_erase_tmpdir_and_scratchdir ; ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo.91 char *g_erase_tmpdir_and_scratchdir = NULL; ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo. 88 92 char *g_selfmounted_isodir = NULL; ///< Holds the NFS mountpoint if mounted via mondoarchive. 89 93 90 94 /* @} - end of globalGroup */ 91 92 //int g_fd_in=-1, g_fd_out=-1;93 95 94 96 void popup_and_OK(char *); … … 104 106 * @return TRUE for yes; FALSE for no. 105 107 */ 106 bool ask_me_yes_or_no(char *prompt) { 107 108 /*@ buffers ********************************************************** */ 109 char *tmp = NULL; 110 int i; 111 size_t n = 0; 112 113 assert_string_is_neither_NULL_nor_zerolength(prompt); 114 115 if (g_text_mode) { 116 while (1) { 108 bool ask_me_yes_or_no(char *prompt) { 109 110 /*@ buffers ********************************************************** */ 111 char *tmp = NULL; 112 int i; 113 size_t n = 0; 114 115 assert_string_is_neither_NULL_nor_zerolength(prompt); 116 117 if (g_text_mode) { 118 while (1) { 119 sync(); 120 printf 121 ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ", 122 prompt); 123 mr_getline(&tmp, &n, stdin); 124 if (tmp[strlen(tmp) - 1] == '\n') 125 tmp[strlen(tmp) - 1] = '\0'; 126 i = (int) strlen(tmp); 127 if (i > 0 && tmp[i - 1] < 32) { 128 tmp[i - 1] = '\0'; 129 } 130 if (strstr(_("yesYES"), tmp)) { 131 mr_free(tmp); 132 return (TRUE); 133 } else if (strstr(_("NOno"), tmp)) { 134 mr_free(tmp); 135 return (FALSE); 136 } else { 117 137 sync(); 118 138 printf 119 ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ", 120 prompt); 121 mr_getline(&tmp, &n, stdin); 122 if (tmp[strlen(tmp) - 1] == '\n') 123 tmp[strlen(tmp) - 1] = '\0'; 124 125 i = (int) strlen(tmp); 126 if (i > 0 && tmp[i - 1] < 32) { 127 tmp[i - 1] = '\0'; 128 } 129 if (strstr(_("yesYES"), tmp)) { 130 mr_free(tmp); 131 return (TRUE); 132 } else if (strstr(_("NOno"), tmp)) { 133 mr_free(tmp); 134 return (FALSE); 135 } else { 136 sync(); 137 printf 138 (_("Please enter either YES or NO (or yes or no, or y or n, or...)\n")); 139 } 140 } 141 } else { 142 return (popup_with_buttons(prompt, _("Yes"), _("No"))); 143 } 144 } 139 (_("Please enter either YES or NO (or yes or no, or y or n, or...)\n")); 140 } 141 } 142 } else { 143 return (popup_with_buttons(prompt, _("Yes"), _("No"))); 144 } 145 } 145 146 146 147 … … 153 154 bool ask_me_OK_or_cancel(char *prompt) { 154 155 155 /*@ buffer *********************************************************** */ 156 char *tmp = NULL; 157 int i; 158 size_t n = 0; 159 160 assert_string_is_neither_NULL_nor_zerolength(prompt); 161 if (g_text_mode) { 162 sync(); 163 printf 164 ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ", 165 prompt); 166 mr_getline(&tmp, &n, stdin); 167 if (tmp[strlen(tmp) - 1] == '\n') 168 tmp[strlen(tmp) - 1] = '\0'; 169 156 /*@ buffer *********************************************************** */ 157 char *tmp = NULL; 158 int i; 159 size_t n = 0; 160 161 assert_string_is_neither_NULL_nor_zerolength(prompt); 162 if (g_text_mode) { 163 sync(); 164 printf 165 ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ", 166 prompt); 167 mr_getline(&tmp, &n, stdin); 168 if (tmp[strlen(tmp) - 1] == '\n') 169 tmp[strlen(tmp) - 1] = '\0'; 170 170 i = (int) strlen(tmp); 171 if (i > 0 && tmp[i - 1] < 32) { 172 tmp[i - 1] = '\0'; 173 } 174 if (strstr(_("okOKOkYESyes"), tmp)) { 175 mr_free(tmp); 176 return (TRUE); 177 } else { 178 mr_free(tmp); 179 return (FALSE); 180 } 171 if (i > 0 && tmp[i - 1] < 32) { 172 tmp[i - 1] = '\0'; 173 } 174 if (strstr(_("okOKOkYESyes"), tmp)) { 175 mr_free(tmp); 176 return (TRUE); 181 177 } else { 182 return (popup_with_buttons(prompt, _(" Okay "), _("Cancel"))); 183 } 184 } 178 mr_free(tmp); 179 return (FALSE); 180 } 181 } else { 182 return (popup_with_buttons(prompt, _(" Okay "), _("Cancel"))); 183 } 184 } 185 185 186 186 … … 251 251 } 252 252 253 253 254 /** 254 255 * Exit Mondo with a fatal error. … … 256 257 * @note This function never returns. 257 258 */ 258 void 259 fatal_error(char *error_string) { 260 /*@ buffers ***************************************************** */ 261 char *fatalstr; 262 char *tmp; 263 char *command; 264 static bool already_exiting = FALSE; 265 int i; 266 267 /*@ end vars **************************************************** */ 268 269 mr_asprintf(&fatalstr, "-------FATAL ERROR---------"); 270 set_signals(FALSE); // link to external func 271 g_exiting = TRUE; 272 mr_msg(1, "%s - '%s'", fatalstr, error_string); 273 printf("%s - %s\n", fatalstr, error_string); 274 if (getpid() == g_mastermind_pid) { 275 mr_msg(2, "mastermind %d is exiting", (int) getpid()); 259 void fatal_error(char *error_string) { 260 /*@ buffers ***************************************************** */ 261 char *fatalstr = NULL; 262 char *tmp = NULL; 263 char *command = NULL; 264 static bool already_exiting = FALSE; 265 int i = 0; 266 267 /*@ end vars **************************************************** */ 268 269 mr_asprintf(&fatalstr, "-------FATAL ERROR---------"); 270 set_signals(FALSE); // link to external func 271 g_exiting = TRUE; 272 mr_msg(1, "%s - '%s'", fatalstr, error_string); 273 printf("%s - %s\n", fatalstr, error_string); 274 if (getpid() == g_mastermind_pid) { 275 mr_msg(2, "mastermind %d is exiting", (int) getpid()); 276 kill(g_main_pid, SIGTERM); 277 finish(1); 278 } 279 280 if (getpid() != g_main_pid) { 281 if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid) { 282 mr_msg(2, "non-m/m %d is exiting", (int) getpid()); 276 283 kill(g_main_pid, SIGTERM); 277 284 finish(1); 278 285 } 279 280 if (getpid() != g_main_pid) { 281 if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid) { 282 mr_msg(2, "non-m/m %d is exiting", (int) getpid()); 283 kill(g_main_pid, SIGTERM); 284 finish(1); 285 } 286 } 287 288 mr_msg(3, "OK, I think I'm the main PID."); 289 if (already_exiting) { 290 mr_msg(3, "...I'm already exiting. Give me time, Julian!"); 291 finish(1); 292 } 293 294 already_exiting = TRUE; 295 mr_msg(2, "I'm going to do some cleaning up now."); 296 paranoid_system("killall mindi 2> /dev/null"); 297 kill_anything_like_this("/mondo/do-not"); 298 kill_anything_like_this("mondo.tmp"); 299 kill_anything_like_this("ntfsclone"); 300 sync(); 301 if (g_tmpfs_mountpt != NULL) { 302 mr_asprintf(&tmp, "umount %s", g_tmpfs_mountpt); 303 chdir("/"); 304 for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) { 305 mr_msg(2, "Waiting for child processes to terminate"); 306 sleep(1); 307 run_program_and_log_output(tmp, 5); 308 } 309 mr_free(tmp); 310 } 311 312 if (g_erase_tmpdir_and_scratchdir) { 313 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5); 314 } 315 316 if (g_selfmounted_isodir) { 317 mr_asprintf(&command, "umount %s", g_selfmounted_isodir); 318 run_program_and_log_output(command, 5); 319 mr_asprintf(&command, "rmdir %s", g_selfmounted_isodir); 320 run_program_and_log_output(command, 5); 321 mr_free(g_selfmounted_isodir); 322 } 323 324 if (!g_text_mode) { 325 mr_msg(0, fatalstr); 326 mr_msg(0, error_string); 327 newtFinished(); 328 } 329 330 printf 331 (_("If you require technical support, please contact the mailing list.\n")); 332 printf(_("See http://www.mondorescue.org for details.\n")); 333 printf 334 (_("The list's members can help you, if you attach that file to your e-mail.\n")); 335 printf(_("Log file: %s\n"), MONDO_LOGFILE); 336 printf(_("Mondo has aborted.\n")); 337 register_pid(0, "mondo"); // finish() does this too, FYI 338 if (!g_main_pid) { 339 mr_msg(3, "FYI - g_main_pid is blank"); 340 } 341 finish(254); 342 } 343 286 } 287 288 mr_msg(3, "OK, I think I'm the main PID."); 289 if (already_exiting) { 290 mr_msg(3, "...I'm already exiting. Give me time, Julian!"); 291 finish(1); 292 } 293 294 already_exiting = TRUE; 295 mr_msg(2, "I'm going to do some cleaning up now."); 296 paranoid_system("killall mindi 2> /dev/null"); 297 kill_anything_like_this("/mondo/do-not"); 298 kill_anything_like_this("tmp.mondo"); 299 kill_anything_like_this("ntfsclone"); 300 sync(); 301 if (g_tmpfs_mountpt != NULL) { 302 mr_asprintf(&tmp, "umount %s", g_tmpfs_mountpt); 303 chdir("/"); 304 for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) { 305 mr_msg(2, "Waiting for child processes to terminate"); 306 sleep(1); 307 run_program_and_log_output(tmp, 5); 308 } 309 mr_free(tmp); 310 } 311 312 if (g_erase_tmpdir_and_scratchdir[0]) { 313 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5); 314 } 315 316 if (g_selfmounted_isodir) { 317 mr_asprintf(&command, "umount %s", g_selfmounted_isodir); 318 run_program_and_log_output(command, 5); 319 mr_free(command); 320 321 mr_asprintf(&command, "rmdir %s", g_selfmounted_isodir); 322 run_program_and_log_output(command, 5); 323 mr_free(command); 324 } 325 326 if (!g_text_mode) { 327 mr_msg(0, fatalstr); 328 mr_msg(0, error_string); 329 newtFinished(); 330 } 331 332 printf(_("If you require technical support, please contact the mailing list.\n")); 333 printf(_("See http://www.mondorescue.org for details.\n")); 334 printf(_("The list's members can help you, if you attach that file to your e-mail.\n")); 335 printf(_("Log file: %s\n"), MONDO_LOGFILE); 336 printf(_("Mondo has aborted.\n")); 337 register_pid(0, "mondo"); // finish() does this too, FYI 338 if (!g_main_pid) { 339 mr_msg(3, "FYI - g_main_pid is blank"); 340 } 341 finish(254); 342 } 344 343 345 344 … … 350 349 * @note This function never returns. 351 350 */ 352 void 353 finish(int signal_code) { 354 char *command = NULL; 355 356 <<<<<<< .courant 357 ======= 358 /* if (signal_code==0) { popup_and_OK("Please press <enter> to quit."); } */ 359 360 /* newtPopHelpLine(); */ 361 362 >>>>>>> .fusion-droit.r1105 363 register_pid(0, "mondo"); 364 chdir("/"); 365 run_program_and_log_output("umount " MNT_CDROM, FALSE); 366 run_program_and_log_output("rm -Rf /mondo.scratch.* /mondo.tmp.*", 351 void finish(int signal_code) { 352 char *command = NULL; 353 354 register_pid(0, "mondo"); 355 chdir("/"); 356 run_program_and_log_output("umount " MNT_CDROM, FALSE); 357 run_program_and_log_output("rm -Rf /mondo.scratch.* /mondo.tmp.*", 367 358 FALSE); 368 if (g_erase_tmpdir_and_scratchdir) { 369 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1); 370 } 371 if (g_selfmounted_isodir) { 372 mr_asprintf(&command, "umount %s", g_selfmounted_isodir); 373 run_program_and_log_output(command, 1); 374 mr_asprintf(&command, "rmdir %s", g_selfmounted_isodir); 375 run_program_and_log_output(command, 1); 376 mr_free(g_selfmounted_isodir); 377 } 378 if (!g_text_mode) { 379 if (does_file_exist("/THIS-IS-A-RAMDISK")) { 380 mr_msg(1, "Calling newtFinished()"); 381 newtFinished(); 382 } else { 383 mr_msg(1, "Calling newtSuspend()"); 384 newtSuspend(); 385 } 386 } 387 <<<<<<< .courant 388 printf(_("Execution run ended; result=%d\n"), signal); 389 printf(_("Type 'less %s' to see the output log\n"), MONDO_LOGFILE); 390 ======= 391 // system("clear"); 392 // iamhere("Finished calling newtFinished"); 393 printf("Execution run ended; result=%d\n", signal_code); 394 printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE); 395 >>>>>>> .fusion-droit.r1105 396 free_libmondo_global_strings(); 397 exit(signal_code); 398 } 399 400 401 359 if (g_erase_tmpdir_and_scratchdir) { 360 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1); 361 } 362 if (g_selfmounted_isodir) { 363 mr_asprintf(&command, "umount %s", g_selfmounted_isodir); 364 run_program_and_log_output(command, 1); 365 mr_free(command); 366 367 mr_asprintf(&command, "rmdir %s", g_selfmounted_isodir); 368 run_program_and_log_output(command, 1); 369 mr_free(command); 370 mr_free(g_selfmounted_isodir); 371 } 372 if (!g_text_mode) { 373 if (does_file_exist("/THIS-IS-A-RAMDISK")) { 374 mr_msg(1, "Calling newtFinished()"); 375 newtFinished(); 376 } else { 377 mr_msg(1, "Calling newtSuspend()"); 378 newtSuspend(); 379 } 380 } 381 printf("Execution run ended; result=%d\n", signal_code); 382 printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE); 383 free_libmondo_global_strings(); 384 exit(signal_code); 385 } 402 386 403 387 … … 408 392 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression. 409 393 */ 410 void 411 log_file_end_to_screen(char *filename, char *grep_for_me) { 412 413 /*@ buffers ********************************************************** */ 414 char *command = NULL; 415 char *tmp = NULL; 416 417 /*@ pointers ********************************************************* */ 418 FILE *fin = NULL; 419 420 /*@ int ************************************************************** */ 421 int i = 0; 422 size_t n = 0; 423 424 assert_string_is_neither_NULL_nor_zerolength(filename); 425 assert(grep_for_me != NULL); 426 427 if (!does_file_exist(filename)) { 428 return; 429 } 430 if (grep_for_me[0] != '\0') { 431 mr_asprintf(&command, "grep '%s' %s | tail -n%d", 432 grep_for_me, filename, g_noof_log_lines); 433 } else { 434 mr_asprintf(&command, "tail -n%d %s", g_noof_log_lines, filename); 435 } 436 fin = popen(command, "r"); 437 if (!fin) { 438 log_OS_error(command); 439 } else { 440 for (i = 0; i < g_noof_log_lines; i++) { 441 for (; 442 strlen(err_log_lines[i]) < 2 && !feof(fin);) { 443 mr_getline(&(err_log_lines[i]), &n, fin); 444 strip_spaces(err_log_lines[i]); 445 if (!strncmp(err_log_lines[i], "root:", 5)) { 446 mr_asprintf(&tmp, "%s", err_log_lines[i] + 6); 447 mr_free(err_log_lines[i]); 448 err_log_lines[i] = tmp; 449 } 450 if (feof(fin)) { 451 break; 452 } 394 void log_file_end_to_screen(char *filename, char *grep_for_me) { 395 396 /*@ buffers ********************************************************** */ 397 char *command = NULL; 398 char *tmp = NULL; 399 400 /*@ pointers ********************************************************* */ 401 FILE *fin = NULL; 402 403 /*@ int ************************************************************** */ 404 int i = 0; 405 size_t n = 0; 406 407 assert_string_is_neither_NULL_nor_zerolength(filename); 408 assert(grep_for_me != NULL); 409 410 if (!does_file_exist(filename)) { 411 return; 412 } 413 if (grep_for_me[0] != '\0') { 414 mr_asprintf(&command, "grep '%s' %s | tail -n%d", 415 grep_for_me, filename, g_noof_log_lines); 416 } else { 417 mr_asprintf(&command, "tail -n%d %s", g_noof_log_lines, filename); 418 } 419 fin = popen(command, "r"); 420 if (!fin) { 421 log_OS_error(command); 422 } else { 423 for (i = 0; i < g_noof_log_lines; i++) { 424 for (; 425 strlen(err_log_lines[i]) < 2 && !feof(fin);) { 426 mr_getline(&(err_log_lines[i]), &n, fin); 427 strip_spaces(err_log_lines[i]); 428 if (!strncmp(err_log_lines[i], "root:", 5)) { 429 mr_asprintf(&tmp, err_log_lines[i] + 6); 430 mr_free(err_log_lines[i]); 431 err_log_lines[i] = tmp; 453 432 } 454 } 455 paranoid_pclose(fin); 456 } 457 refresh_log_screen(); 458 mr_free(command); 459 } 433 if (feof(fin)) { 434 break; 435 } 436 } 437 } 438 paranoid_pclose(fin); 439 } 440 refresh_log_screen(); 441 mr_free(command); 442 } 460 443 461 444 … … 465 448 * @note The message is also written to the logfile. 466 449 */ 467 void 468 log_to_screen(const char *fmt, ...) { 469 470 /*@ int ************************************************************** */ 471 int i = 0; 472 int j = 0; 473 va_list args; 474 475 /*@ buffers ********************************************************** */ 476 char *output = NULL; 477 478 479 va_start(args, fmt); 480 mr_asprintf(&output, fmt, args); 481 mr_msg(0, output); 482 if (strlen(output) > 80) { 483 output[80] = '\0'; 484 } 485 va_end(args); 486 i = (int) strlen(output); 487 if (i > 0 && output[i - 1] < 32) { 488 output[i - 1] = '\0'; 489 } 490 491 if (err_log_lines) { 492 mr_free(err_log_lines[0]); 493 for (i = 1; i < g_noof_log_lines; i++) { 494 err_log_lines[i - 1] = err_log_lines[i]; 495 } 496 } 497 while (strlen(output) > 0 && output[strlen(output) - 1] < 32) { 498 output[strlen(output) - 1] = '\0'; 499 } 500 for (j = 0; j < (int) strlen(output); j++) { 501 if (output[j] < 32) { 502 output[j] = ' '; 503 } 504 } 505 if (err_log_lines) 506 err_log_lines[g_noof_log_lines - 1] = output; 507 if (g_text_mode) { 508 printf("%s\n", output); 509 } else { 510 refresh_log_screen(); 511 } 512 } 450 void log_to_screen(const char *fmt, ...) { 451 452 /*@ int ************************************************************** */ 453 int i = 0; 454 int j = 0; 455 va_list args; 456 457 /*@ buffers ********************************************************** */ 458 char *output = NULL; 459 460 461 va_start(args, fmt); 462 mr_asprintf(&output, fmt, args); 463 mr_msg(0, output); 464 if (strlen(output) > 80) { 465 output[80] = '\0'; 466 } 467 va_end(args); 468 i = (int) strlen(output); 469 if (i > 0 && output[i - 1] < 32) { 470 output[i - 1] = '\0'; 471 } 472 473 if (err_log_lines) { 474 mr_free(err_log_lines[0]); 475 for (i = 1; i < g_noof_log_lines; i++) { 476 err_log_lines[i - 1] = err_log_lines[i]; 477 } 478 } 479 while (strlen(output) > 0 && output[strlen(output) - 1] < 32) { 480 output[strlen(output) - 1] = '\0'; 481 } 482 for (j = 0; j < (int) strlen(output); j++) { 483 if (output[j] < 32) { 484 output[j] = ' '; 485 } 486 } 487 if (err_log_lines) 488 err_log_lines[g_noof_log_lines - 1] = output; 489 if (g_text_mode) { 490 printf("%s\n", output); 491 } else { 492 refresh_log_screen(); 493 } 494 } 513 495 514 496 … … 538 520 * @param ttl The title to use for the evalcall form. 539 521 */ 540 void 541 open_evalcall_form(char *ttl) { 542 543 /*@ buffers ********************************************************* */ 544 char *title; 545 char *tmp; 546 547 /*@ initialize ****************************************************** */ 548 g_isoform_old_progress = -1; 549 g_mysterious_dot_counter = 0; 550 551 assert(ttl != NULL); 552 mr_asprintf(&title, ttl); 553 // BERLIOS: We need to unallocate it somewhere 554 mr_asprintf(&g_isoform_header_str, title); 555 // center_string (title, 80); 556 if (g_text_mode) { 557 mr_msg(0, title); 558 } else { 559 mr_asprintf(&tmp, title); 560 /* BERLIOS: center_string is now broken replace it ! */ 561 //center_string(tmp, 80); 562 newtPushHelpLine(tmp); 563 mr_free(tmp); 564 } 522 void open_evalcall_form(char *ttl) { 523 524 /*@ buffers ********************************************************* */ 525 char *title = NULL; 526 char *tmp = NULL; 527 528 /*@ initialize ****************************************************** */ 529 g_isoform_old_progress = -1; 530 g_mysterious_dot_counter = 0; 531 532 assert(ttl != NULL); 533 mr_asprintf(&title, ttl); 534 // BERLIOS: We need to unallocate it somewhere 535 mr_asprintf(&g_isoform_header_str, title); 536 if (g_text_mode) { 537 mr_msg(0, title); 538 } else { 539 mr_asprintf(&tmp, title); 565 540 /* BERLIOS: center_string is now broken replace it ! */ 566 //center_string(g_isoform_header_str, 36); 567 g_isoform_starttime = get_time(); 568 if (g_text_mode) { 569 mr_msg(0, g_isoform_header_str); 570 } else { 571 g_isoform_header = newtLabel(1, 1, g_isoform_header_str); 572 g_isoform_scale = newtScale(3, 3, 34, 100); 573 // newtOpenWindow (20, 6, 40, 7, title); // "Please Wait"); 574 newtCenteredWindow(40, 7, title); 575 g_isoform_main = newtForm(NULL, NULL, 0); 576 g_isoform_timeline = newtLabel(1, 5, "This is the timeline"); 577 g_isoform_pcline = newtLabel(1, 6, "This is the pcline"); 578 newtFormAddComponents(g_isoform_main, g_isoform_timeline, 579 g_isoform_pcline, g_isoform_header, 580 g_isoform_scale, NULL); 581 newtRefresh(); 582 } 583 update_evalcall_form(0); 584 mr_free(title); 585 } 586 541 //center_string(tmp, 80); 542 newtPushHelpLine(tmp); 543 mr_free(tmp); 544 } 545 /* BERLIOS: center_string is now broken replace it ! */ 546 //center_string(g_isoform_header_str, 36); 547 g_isoform_starttime = get_time(); 548 if (g_text_mode) { 549 mr_msg(0, g_isoform_header_str); 550 } else { 551 g_isoform_header = newtLabel(1, 1, g_isoform_header_str); 552 g_isoform_scale = newtScale(3, 3, 34, 100); 553 // newtOpenWindow (20, 6, 40, 7, title); // "Please Wait"); 554 newtCenteredWindow(40, 7, title); 555 g_isoform_main = newtForm(NULL, NULL, 0); 556 g_isoform_timeline = newtLabel(1, 5, "This is the timeline"); 557 g_isoform_pcline = newtLabel(1, 6, "This is the pcline"); 558 newtFormAddComponents(g_isoform_main, g_isoform_timeline, 559 g_isoform_pcline, g_isoform_header, 560 g_isoform_scale, NULL); 561 newtRefresh(); 562 } 563 update_evalcall_form(0); 564 mr_free(title); 565 } 587 566 588 567 … … 596 575 * @param max_val The maximum amount of progress (number of filesets, etc.) 597 576 */ 598 void 599 open_progress_form(char *title, char *b1, char *b2, char *b3, 577 void open_progress_form(char *title, char *b1, char *b2, char *b3, 600 578 long max_val) { 601 579 602 /*@ buffers ********************************************************* */ 603 char *b1c; 604 char *blurb1; 605 char *blurb2; 606 char *blurb3; 607 608 /*@ initialize ****************************************************** */ 609 g_mysterious_dot_counter = 0; 610 611 assert(title != NULL); 612 assert(b1 != NULL); 613 assert(b2 != NULL); 614 assert(b3 != NULL); 615 616 mr_asprintf(&blurb1, b1); 617 mr_asprintf(&blurb2, b2); 618 mr_asprintf(&blurb3, b3); 619 mr_asprintf(&b1c, b1); 620 /* BERLIOS: center_string is now broken replace it ! */ 621 //center_string(b1c, 80); 622 if (max_val <= 0) { 623 max_val = 1; 624 } 625 626 g_start_time = get_time(); 627 g_maximum_progress = max_val; 628 g_current_progress = 0; 629 // BERLIOS: We need to unallocate them 630 mr_asprintf(&g_blurb_str_1, blurb1); 631 mr_asprintf(&g_blurb_str_2, blurb3); 632 mr_asprintf(&g_blurb_str_3, blurb2); 633 if (g_text_mode) { 634 mr_msg(0, blurb1); 635 mr_msg(0, blurb2); 636 mr_msg(0, blurb3); 637 } else { 638 g_blurb1 = newtLabel(2, 1, blurb1); 639 g_blurb2 = newtLabel(2, 2, blurb3); 640 g_blurb3 = newtLabel(2, 4, blurb2); 641 // newtOpenWindow (10, 4, 60, 11, title); 642 newtCenteredWindow(60, 11, title); 643 g_scale = newtScale(3, 6, 54, g_maximum_progress); 644 g_progressForm = newtForm(NULL, NULL, 0); 645 g_percentline = newtLabel(10, 9, "This is the percentline"); 646 g_timeline = newtLabel(10, 8, "This is the timeline"); 647 newtFormAddComponents(g_progressForm, g_percentline, 648 g_timeline, g_scale, g_blurb1, g_blurb3, 649 g_blurb2, NULL); 650 newtPushHelpLine(b1c); 651 newtRefresh(); 652 } 653 update_progress_form_full(blurb1, blurb2, blurb3); 654 mr_free(b1c); 655 mr_free(blurb1); 656 mr_free(blurb2); 657 mr_free(blurb3); 658 } 580 /*@ buffers ********************************************************* */ 581 char *b1c = NULL; 582 char *blurb1 = NULL; 583 char *blurb2 = NULL; 584 char *blurb3 = NULL; 585 586 /*@ initialize ****************************************************** */ 587 g_mysterious_dot_counter = 0; 588 589 assert(title != NULL); 590 assert(b1 != NULL); 591 assert(b2 != NULL); 592 assert(b3 != NULL); 593 594 mr_asprintf(&blurb1, b1); 595 mr_asprintf(&blurb2, b2); 596 mr_asprintf(&blurb3, b3); 597 mr_asprintf(&b1c, b1); 598 /* BERLIOS: center_string is now broken replace it ! */ 599 //center_string(b1c, 80); 600 if (max_val <= 0) { 601 max_val = 1; 602 } 603 604 g_start_time = get_time(); 605 g_maximum_progress = max_val; 606 g_current_progress = 0; 607 // BERLIOS: We need to unallocate them 608 mr_asprintf(&g_blurb_str_1, blurb1); 609 mr_asprintf(&g_blurb_str_2, blurb3); 610 mr_asprintf(&g_blurb_str_3, blurb2); 611 if (g_text_mode) { 612 mr_msg(0, blurb1); 613 mr_msg(0, blurb2); 614 mr_msg(0, blurb3); 615 } else { 616 g_blurb1 = newtLabel(2, 1, blurb1); 617 g_blurb2 = newtLabel(2, 2, blurb3); 618 g_blurb3 = newtLabel(2, 4, blurb2); 619 // newtOpenWindow (10, 4, 60, 11, title); 620 newtCenteredWindow(60, 11, title); 621 g_scale = newtScale(3, 6, 54, g_maximum_progress); 622 g_progressForm = newtForm(NULL, NULL, 0); 623 g_percentline = newtLabel(10, 9, "This is the percentline"); 624 g_timeline = newtLabel(10, 8, "This is the timeline"); 625 newtFormAddComponents(g_progressForm, g_percentline, 626 g_timeline, g_scale, g_blurb1, g_blurb3, 627 g_blurb2, NULL); 628 newtPushHelpLine(b1c); 629 newtRefresh(); 630 } 631 update_progress_form_full(blurb1, blurb2, blurb3); 632 mr_free(b1c); 633 mr_free(blurb1); 634 mr_free(blurb2); 635 mr_free(blurb3); 636 } 637 659 638 660 639 /** … … 662 641 * @param prompt The message. 663 642 */ 664 void 665 popup_and_OK(char *prompt) {666 int ch; 667 668 assert_string_is_neither_NULL_nor_zerolength(prompt); 669 670 mr_msg(0, prompt);671 if (g_text_mode) {672 printf673 ("---promptpopup---1--- %s\r\n---promptpopup---Q--- [OK] ---\r\n--> ",674 prompt);675 while (((ch = getchar()) != '\n') && (ch != EOF));676 } else {677 (void) popup_with_buttons(prompt, _(" OK "), "");678 679 } 643 void popup_and_OK(char *prompt) { 644 int ch; 645 646 assert_string_is_neither_NULL_nor_zerolength(prompt); 647 648 mr_msg(0, prompt); 649 if (g_text_mode) { 650 printf 651 ("---promptpopup---1--- %s\r\n---promptpopup---Q--- [OK] ---\r\n--> ", 652 prompt); 653 while (((ch = getchar()) != '\n') && (ch != EOF)); 654 } else { 655 (void) popup_with_buttons(prompt, _(" OK "), ""); 656 } 657 } 658 680 659 681 660 /** … … 686 665 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel. 687 666 */ 688 bool popup_and_get_string(char *title, char *b, char *output) { 689 690 /*@ newt ************************************************************ */ 691 newtComponent myForm; 692 newtComponent b_1; 693 newtComponent b_2; 694 newtComponent b_res; 695 newtComponent text; 696 newtComponent type_here; 697 698 /*@ pointers ********************************************************* */ 699 char **entry_value = NULL; 700 701 /*@ buffers ********************************************************** */ 702 char *blurb = NULL; 703 size_t n = 0; 704 bool ret = TRUE; 705 706 assert_string_is_neither_NULL_nor_zerolength(title); 707 assert(b != NULL); 708 709 if (g_text_mode) { 710 printf 711 ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n--> ", 712 title, b); 713 mr_free(output); 714 mr_getline(&output, &n, stdin); 715 if (output[strlen(output) - 1] == '\n') 716 output[strlen(output) - 1] = '\0'; 717 return (ret); 718 } 719 mr_asprintf(&blurb, b); 720 text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0); 721 722 type_here = 723 newtEntry(2, newtTextboxGetNumLines(text) + 2, 724 output, 50, 725 (void *)entry_value, NEWT_FLAG_RETURNEXIT 726 ); 727 b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, _(" OK ")); 728 b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, _("Cancel")); 729 newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title); 730 myForm = newtForm(NULL, NULL, 0); 731 newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL); 732 /* BERLIOS: center_string is now broken replace it ! */ 733 //center_string(blurb, 80); 734 newtPushHelpLine(blurb); 735 mr_free(blurb); 736 737 b_res = newtRunForm(myForm); 738 newtPopHelpLine(); 739 if (b_res == b_2) { 740 ret = FALSE; 741 } else { 742 // Copy entry_value before destroying the form 743 // clearing potentially output before 744 mr_allocstr(output,*entry_value); 745 } 746 newtFormDestroy(myForm); 747 newtPopWindow(); 667 bool popup_and_get_string(char *title, char *b, char *output) { 668 669 /*@ newt ************************************************************ */ 670 newtComponent myForm; 671 newtComponent b_1; 672 newtComponent b_2; 673 newtComponent b_res; 674 newtComponent text; 675 newtComponent type_here; 676 677 /*@ pointers ********************************************************* */ 678 char **entry_value = NULL; 679 680 /*@ buffers ********************************************************** */ 681 char *blurb = NULL; 682 size_t n = 0; 683 bool ret = TRUE; 684 685 assert_string_is_neither_NULL_nor_zerolength(title); 686 assert(b != NULL); 687 688 if (g_text_mode) { 689 printf 690 ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n--> ", 691 title, b); 692 mr_free(output); 693 mr_getline(&output, &n, stdin); 694 if (output[strlen(output) - 1] == '\n') 695 output[strlen(output) - 1] = '\0'; 748 696 return(ret); 749 697 } 698 mr_asprintf(&blurb, b); 699 text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0); 700 701 type_here = 702 newtEntry(2, newtTextboxGetNumLines(text) + 2, 703 output, 50, 704 (void *)entry_value, NEWT_FLAG_RETURNEXIT 705 ); 706 b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, _(" OK ")); 707 b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, _("Cancel")); 708 newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title); 709 myForm = newtForm(NULL, NULL, 0); 710 newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL); 711 /* BERLIOS: center_string is now broken replace it ! */ 712 //center_string(blurb, 80); 713 newtPushHelpLine(blurb); 714 mr_free(blurb); 715 716 b_res = newtRunForm(myForm); 717 newtPopHelpLine(); 718 if (b_res == b_2) { 719 ret = FALSE; 720 } else { 721 // Copy entry_value before destroying the form 722 // clearing potentially output before 723 mr_allocstr(output,*entry_value); 724 } 725 newtFormDestroy(myForm); 726 newtPopWindow(); 727 return(ret); 728 } 750 729 751 730 … … 757 736 * @return TRUE if @p button1 was pushed, FALSE otherwise. 758 737 */ 759 bool popup_with_buttons(char *p, char *button1, char *button2) { 760 761 /*@ buffers *********************************************************** */ 762 char *prompt; 763 char *tmp = NULL; 764 size_t n = 0; 765 766 /*@ newt ************************************************************** */ 767 newtComponent myForm; 768 newtComponent b_1; 769 newtComponent b_2; 770 newtComponent b_res; 771 newtComponent text; 772 773 assert_string_is_neither_NULL_nor_zerolength(p); 774 assert(button1 != NULL); 775 assert(button2 != NULL); 776 if (g_text_mode) { 777 if (strlen(button2) == 0) { 778 printf("%s (%s) --> ", p, button1); 779 } else { 780 printf("%s (%s or %s) --> ", p, button1, button2); 781 } 782 for (mr_asprintf(&tmp, " "); 783 strcmp(tmp, button1) && (strlen(button2) == 0 784 || strcmp(tmp, button2));) { 785 printf("--> "); 738 bool popup_with_buttons(char *p, char *button1, char *button2) { 739 740 /*@ buffers *********************************************************** */ 741 char *prompt; 742 char *tmp = NULL; 743 size_t n = 0; 744 745 /*@ newt ************************************************************** */ 746 newtComponent myForm; 747 newtComponent b_1; 748 newtComponent b_2; 749 newtComponent b_res; 750 newtComponent text; 751 752 assert_string_is_neither_NULL_nor_zerolength(p); 753 assert(button1 != NULL); 754 assert(button2 != NULL); 755 756 if (g_text_mode) { 757 if (strlen(button2) == 0) { 758 printf("%s (%s) --> ", p, button1); 759 } else { 760 printf("%s (%s or %s) --> ", p, button1, button2); 761 } 762 for (mr_asprintf(&tmp, ""); 763 strcmp(tmp, button1) && (strlen(button2) == 0 764 || strcmp(tmp, button2));) { 765 printf("--> "); 786 766 mr_free(tmp); 787 767 mr_getline(&tmp, &n, stdin); 788 768 } 789 if (!strcmp(tmp, button1)) { 790 mr_free(tmp); 791 return (TRUE); 792 } else { 793 mr_free(tmp); 794 return (FALSE); 795 } 796 } 797 798 mr_asprintf(&prompt, p); 799 text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0); 800 b_1 = 801 newtButton(20 - 802 ((button2[0] != 803 '\0') ? strlen(button1) + 804 2 : strlen(button1) / 2), 805 newtTextboxGetNumLines(text) + 3, button1); 806 if (button2[0] != '\0') { 807 b_2 = 808 newtButton(24, newtTextboxGetNumLines(text) + 3, button2); 809 } else { 810 b_2 = NULL; 811 } 812 // newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert"); 813 newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, _("Alert")); 814 myForm = newtForm(NULL, NULL, 0); 815 newtFormAddComponents(myForm, text, b_1, b_2, NULL); 816 /* BERLIOS: center_string is now broken replace it ! */ 817 //center_string(prompt, 80); 818 newtPushHelpLine(prompt); 819 mr_free(prompt); 820 b_res = newtRunForm(myForm); 821 newtPopHelpLine(); 822 newtFormDestroy(myForm); 823 newtPopWindow(); 824 if (b_res == b_1) { 769 if (!strcmp(tmp, button1)) { 770 mr_free(tmp); 825 771 return (TRUE); 826 772 } else { 773 mr_free(tmp); 827 774 return (FALSE); 828 775 } 829 776 } 830 777 831 778 mr_asprintf(&prompt, p); 779 text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0); 780 b_1 = 781 newtButton(20 - 782 ((button2[0] != 783 '\0') ? strlen(button1) + 784 2 : strlen(button1) / 2), 785 newtTextboxGetNumLines(text) + 3, button1); 786 if (button2[0] != '\0') { 787 b_2 = 788 newtButton(24, newtTextboxGetNumLines(text) + 3, button2); 789 } else { 790 b_2 = NULL; 791 } 792 // newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert"); 793 newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, _("Alert")); 794 myForm = newtForm(NULL, NULL, 0); 795 newtFormAddComponents(myForm, text, b_1, b_2, NULL); 796 /* BERLIOS: center_string is now broken replace it ! */ 797 //center_string(prompt, 80); 798 newtPushHelpLine(prompt); 799 mr_free(prompt); 800 801 b_res = newtRunForm(myForm); 802 newtPopHelpLine(); 803 newtFormDestroy(myForm); 804 newtPopWindow(); 805 if (b_res == b_1) { 806 return (TRUE); 807 } else { 808 return (FALSE); 809 } 810 } 832 811 833 812 … … 836 815 * on the screen. 837 816 */ 838 void 839 refresh_log_screen() { 840 841 /*@ int *********************************************************** */842 int i = 0; 843 844 845 if (g_text_mode || !err_log_lines) {846 return;847 }848 for (i = g_noof_log_lines - 1; i >= 0; i--) {849 newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines,850 " ");851 }852 newtRefresh(); 853 854 855 856 857 858 859 817 void refresh_log_screen(void) { 818 819 /*@ int *********************************************************** */ 820 int i = 0; 821 822 823 if (g_text_mode || !err_log_lines) { 824 return; 825 } 826 for (i = g_noof_log_lines - 1; i >= 0; i--) { 827 newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines, 828 " "); 829 } 830 newtRefresh(); 831 832 for (i = g_noof_log_lines - 1; i >= 0; i--) { 833 //BERLIOS : removed for now, Think it's useless : err_log_lines[i][79] = '\0'; 834 newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines, 835 err_log_lines[i]); 836 } 837 newtRefresh(); 838 } 860 839 861 840 … … 864 843 * only allocate some memory. 865 844 */ 866 void 867 setup_newt_stuff() { 868 869 /*@ int *********************************************************** */ 870 int i = 0; 871 int cols; 872 873 if (!g_text_mode) { 874 newtInit(); 875 newtCls(); 876 newtPushHelpLine 877 (_("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed.")); 878 /* newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */ 879 newtDrawRootText(18, 0, WELCOME_STRING); 880 newtRefresh(); 881 newtGetScreenSize(&cols, &g_noof_rows); 882 g_noof_log_lines = (g_noof_rows / 5) + 1; 883 } 884 885 err_log_lines = 886 (char **) mr_malloc(sizeof(char *) * g_noof_log_lines); 887 if (!err_log_lines) { 888 fatal_error("Out of memory"); 889 } 890 891 for (i = 0; i < g_noof_log_lines; i++) { 892 err_log_lines[i] = NULL; 893 } 894 } 845 void setup_newt_stuff(void) { 846 847 /*@ int *********************************************************** */ 848 int i = 0; 849 int cols; 850 851 if (!g_text_mode) { 852 newtInit(); 853 newtCls(); 854 newtPushHelpLine 855 (_("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed.")); 856 newtDrawRootText(18, 0, WELCOME_STRING); 857 newtRefresh(); 858 newtGetScreenSize(&cols, &g_noof_rows); 859 g_noof_log_lines = (g_noof_rows / 5) + 1; 860 } 861 862 err_log_lines = 863 (char **) mr_malloc(sizeof(char *) * g_noof_log_lines); 864 865 for (i = 0; i < g_noof_log_lines; i++) { 866 err_log_lines[i] = NULL; 867 } 868 } 895 869 896 870 … … 899 873 * @param num The numerator of the ratio. 900 874 */ 901 void 902 update_evalcall_form(int num) { 903 904 /*@ long ************************************************************ */ 905 long current_time = 0; 906 long time_taken = 0; 907 long time_total_est = 0; 908 long time_remaining = 0; 909 910 /*@ buffers ********************************************************** */ 911 char *timeline_str; 912 char *pcline_str; 913 char *taskprogress; 914 char *tmp1; 915 char *tmp2; 916 char *p; 917 918 /*@ int ************************************************************** */ 919 int percentage = 0; 920 int i = 0; 921 int j = 0; 922 923 //log_it("update_eval_call_form called"); 924 if (num < 1) { 925 percentage = 1; 875 void update_evalcall_form(int num) { 876 877 /*@ long ************************************************************ */ 878 long current_time = 0L; 879 long time_taken = 0L; 880 long time_total_est = 0L; 881 long time_remaining = 0L; 882 883 /*@ buffers ********************************************************** */ 884 char *timeline_str = NULL; 885 char *pcline_str = NULL; 886 char *taskprogress = NULL; 887 char *tmp1 = NULL; 888 char *tmp2 = NULL; 889 char *p = NULL; 890 891 /*@ int ************************************************************** */ 892 int percentage = 0; 893 int i = 0; 894 int j = 0; 895 896 if (num < 1) { 897 percentage = 1; 898 } else { 899 percentage = (int) trunc(num); 900 } 901 902 current_time = get_time(); 903 time_taken = current_time - g_isoform_starttime; 904 if (num) { 905 time_total_est = time_taken * 100 / num; 906 time_remaining = time_total_est - time_taken; 907 } else { 908 time_remaining = 0; 909 } 910 if (!g_text_mode) { 911 newtLabelSetText(g_isoform_header, g_isoform_header_str); 912 } 913 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 914 if ((percentage < 3 && g_isoform_old_progress < 3) 915 || percentage > g_isoform_old_progress) { 916 g_isoform_old_progress = percentage; 917 mr_asprintf(&timeline_str, 918 _("%2ld:%02ld taken %2ld:%02ld remaining"), 919 time_taken / 60, time_taken % 60, time_remaining / 60, 920 time_remaining % 60); 921 if (percentage < 3) { 922 tmp1 = 923 (char *) malloc(g_mysterious_dot_counter * 924 sizeof(char)); 925 for (i = 0, p = tmp1; i < g_mysterious_dot_counter - 1; 926 i++, p++) { 927 *p = '.'; 928 } 929 *p = '\0'; 930 931 /* BERLIOS: 27 should be a parameter */ 932 tmp2 = 933 (char *) malloc(27 - 934 g_mysterious_dot_counter * 935 sizeof(char)); 936 for (i = 0, p = tmp2; 937 i < 27 - g_mysterious_dot_counter - 1; i++, p++) { 938 *p = ' '; 939 } 940 *p = '\0'; 941 mr_asprintf(&pcline_str, " Working%s%s %c", tmp1, tmp2, 942 special_dot_char(g_mysterious_dot_counter)); 943 mr_free(tmp1); 944 mr_free(tmp2); 926 945 } else { 927 percentage = (int) trunc(num); 928 } 929 930 current_time = get_time(); 931 time_taken = current_time - g_isoform_starttime; 932 if (num) { 933 time_total_est = time_taken * 100 / num; 934 time_remaining = time_total_est - time_taken; 946 mr_asprintf(&pcline_str, 947 _(" %3d%% done %3d%% to go"), 948 percentage, 100 - percentage); 949 } 950 if (g_text_mode) { 951 j = trunc(percentage / 5); 952 tmp1 = (char *) malloc((j + 1) * sizeof(char)); 953 for (i = 0, p = tmp1; i < j; i++, p++) { 954 *p = '*'; 955 } 956 *p = '\0'; 957 tmp2 = (char *) malloc((20 - j + 1) * sizeof(char)); 958 for (i = 0, p = tmp2; i < 20 - j; i++, p++) { 959 *p = '.'; 960 } 961 *p = '\0'; 962 963 if (percentage >= 3) { 964 mr_asprintf(&taskprogress, 965 "TASK: [%s%s] %3d%% done; %2ld:%02ld to go", 966 tmp1, tmp2, percentage, time_remaining / 60, 967 time_remaining % 60); 968 printf("---evalcall---1--- %s\r\n", 969 g_isoform_header_str); 970 printf("---evalcall---2--- %s\r\n", taskprogress); 971 printf("---evalcall---E---\r\n"); 972 mr_free(taskprogress); 973 } 935 974 } else { 936 time_remaining = 0; 937 } 938 if (!g_text_mode) { 939 newtLabelSetText(g_isoform_header, g_isoform_header_str); 940 } 941 /* BERLIOS: 27 should be a parameter */ 942 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 943 if ((percentage < 3 && g_isoform_old_progress < 3) 944 || percentage > g_isoform_old_progress) { 945 g_isoform_old_progress = percentage; 946 mr_asprintf(&timeline_str, 947 _("%2ld:%02ld taken %2ld:%02ld remaining"), 948 time_taken / 60, time_taken % 60, time_remaining / 60, 949 time_remaining % 60); 950 if (percentage < 3) { 951 tmp1 = 952 (char *) malloc(g_mysterious_dot_counter * 953 sizeof(char)); 954 for (i = 0, p = tmp1; i < g_mysterious_dot_counter - 1; 955 i++, p++) { 956 *p = '.'; 957 } 958 *p = '\0'; 959 960 /* BERLIOS: 27 should be a parameter */ 961 tmp2 = 962 (char *) malloc(27 - 963 g_mysterious_dot_counter * 964 sizeof(char)); 965 for (i = 0, p = tmp2; 966 i < 27 - g_mysterious_dot_counter - 1; i++, p++) { 967 *p = ' '; 968 } 969 *p = '\0'; 970 971 mr_asprintf(&pcline_str, " Working%s%s %c", tmp1, tmp2, 972 special_dot_char(g_mysterious_dot_counter)); 973 mr_free(tmp1); 974 mr_free(tmp2); 975 } else { 976 mr_asprintf(&pcline_str, 977 _(" %3d%% done %3d%% to go"), 978 percentage, 100 - percentage); 979 } 980 if (g_text_mode) { 981 j = trunc(percentage / 5); 982 tmp1 = (char *) malloc((j + 1) * sizeof(char)); 983 for (i = 0, p = tmp1; i < j; i++, p++) { 984 *p = '*'; 985 } 986 *p = '\0'; 987 988 tmp2 = (char *) malloc((20 - j + 1) * sizeof(char)); 989 for (i = 0, p = tmp2; i < 20 - j; i++, p++) { 990 *p = '.'; 991 } 992 *p = '\0'; 993 994 if (percentage >= 3) { 995 mr_asprintf(&taskprogress, 996 "TASK: [%s%s] %3d%% done; %2ld:%02ld to go", 997 tmp1, tmp2, percentage, time_remaining / 60, 998 time_remaining % 60); 999 printf("---evalcall---1--- %s\r\n", 1000 g_isoform_header_str); 1001 printf("---evalcall---2--- %s\r\n", taskprogress); 1002 printf("---evalcall---E---\r\n"); 1003 mr_free(taskprogress); 1004 } 1005 } else { 1006 newtScaleSet(g_isoform_scale, 1007 (unsigned long long) percentage); 1008 newtLabelSetText(g_isoform_pcline, pcline_str); 1009 if (percentage >= 3) { 1010 newtLabelSetText(g_isoform_timeline, timeline_str); 1011 } 1012 } 1013 mr_free(timeline_str); 1014 mr_free(pcline_str); 1015 } 1016 if (!g_text_mode) { 1017 // log_it("refreshing"); 1018 newtRefresh(); 1019 } 1020 } 975 newtScaleSet(g_isoform_scale, 976 (unsigned long long) percentage); 977 newtLabelSetText(g_isoform_pcline, pcline_str); 978 if (percentage >= 3) { 979 newtLabelSetText(g_isoform_timeline, timeline_str); 980 } 981 } 982 mr_free(timeline_str); 983 mr_free(pcline_str); 984 } 985 if (!g_text_mode) { 986 newtRefresh(); 987 } 988 } 1021 989 1022 990 … … 1026 994 * @param blurb3 The new third line of the blurb; use @p g_blurb_str_2 (no, that's not a typo) to keep it the same. 1027 995 */ 1028 void 1029 update_progress_form(char *blurb3) { 1030 /* log_it("update_progress_form --- called"); */ 1031 if (g_current_progress == -999) { 1032 /* log_it("You're trying to update progress form when it ain't open. Aww, that's OK. I'll let it go. It's a bit naughty but it's a nonfatal error. No prob, Bob."); */ 1033 return; 1034 } 1035 mr_free(g_blurb_str_2); 1036 mr_asprintf(&g_blurb_str_2, blurb3); 1037 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, 1038 g_blurb_str_3); 1039 } 996 void update_progress_form(char *blurb3) { 997 if (g_current_progress == -999) { 998 return; 999 } 1000 mr_free(g_blurb_str_2); 1001 mr_asprintf(&g_blurb_str_2, blurb3); 1002 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, 1003 g_blurb_str_3); 1004 } 1040 1005 1041 1006 … … 1046 1011 * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same. 1047 1012 */ 1048 void 1049 update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 1050 /*@ long ***************************************************** */ 1051 long current_time = 0; 1052 long time_taken = 0; 1053 long time_remaining = 0; 1054 long time_total_est = 0; 1055 1056 /*@ int ******************************************************* */ 1057 int percentage = 0; 1058 int i = 0; 1059 int j = 0; 1060 1061 /*@ buffers *************************************************** */ 1062 char *percentline_str; 1063 char *timeline_str; 1064 char *taskprogress; 1065 char *tmp; 1013 void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 1014 /*@ long ***************************************************** */ 1015 long current_time = 0L; 1016 long time_taken = 0L; 1017 long time_remaining = 0L; 1018 long time_total_est = 0L; 1019 1020 /*@ int ******************************************************* */ 1021 int percentage = 0; 1022 int i = 0; 1023 1024 /*@ buffers *************************************************** */ 1025 char *percentline_str = NULL; 1026 char *timeline_str = NULL; 1027 char *taskprogress = NULL; 1028 char *tmp = NULL; 1066 1029 char *tmp1; 1067 1030 char *tmp2; 1068 1031 char *p; 1069 1032 1070 // mr_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3); 1071 if (!g_text_mode) { 1072 assert(blurb1 != NULL); 1073 assert(blurb2 != NULL); 1074 assert(blurb3 != NULL); 1075 assert(g_timeline != NULL); 1076 } 1077 1078 current_time = get_time(); 1079 time_taken = current_time - g_start_time; 1080 if (g_maximum_progress == 0) { 1081 percentage = 0; 1082 } else { 1083 if (g_current_progress > g_maximum_progress) { 1084 mr_asprintf(&tmp, 1085 "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", 1086 blurb1, blurb2, blurb3, g_current_progress, 1087 g_maximum_progress); 1088 mr_msg(0, tmp); 1089 mr_free(tmp); 1090 g_current_progress = g_maximum_progress; 1091 } 1092 percentage = 1093 (int) ((g_current_progress * 100L) / g_maximum_progress); 1094 } 1095 if (percentage < 1) { 1096 percentage = 1; 1097 } 1033 if (!g_text_mode) { 1034 assert(blurb1 != NULL); 1035 assert(blurb2 != NULL); 1036 assert(blurb3 != NULL); 1037 assert(g_timeline != NULL); 1038 } 1039 1040 current_time = get_time(); 1041 time_taken = current_time - g_start_time; 1042 if (g_maximum_progress == 0) { 1043 percentage = 0; 1044 } else { 1045 if (g_current_progress > g_maximum_progress) { 1046 mr_msg(0, "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", 1047 blurb1, blurb2, blurb3, g_current_progress, 1048 g_maximum_progress); 1049 g_current_progress = g_maximum_progress; 1050 } 1051 percentage = 1052 (int) ((g_current_progress * 100L) / g_maximum_progress); 1053 } 1054 if (percentage < 1) { 1055 percentage = 1; 1056 } 1057 if (percentage > 100) { 1058 percentage = 100; 1059 } 1060 if (g_current_progress) { 1061 time_total_est = 1062 time_taken * (long) g_maximum_progress / 1063 (long) (g_current_progress); 1064 time_remaining = time_total_est - time_taken; 1065 } else { 1066 time_remaining = 0; 1067 } 1068 /* BERLIOS/ Is it useful here ? */ 1069 //g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1070 mr_asprintf(&timeline_str, 1071 "%2ld:%02ld taken %2ld:%02ld remaining ", 1072 time_taken / 60, time_taken % 60, time_remaining / 60, 1073 time_remaining % 60); 1074 mr_asprintf(&percentline_str, 1075 " %3d%% done %3d%% to go", percentage, 1076 100 - percentage); 1077 1078 if (g_text_mode) { 1079 printf(_("---progress-form---1--- %s\n"), blurb1); 1080 printf(_("---progress-form---2--- %s\n"), blurb2); 1081 printf(_("---progress-form---3--- %s\n"), blurb3); 1082 printf(_("---progress-form---E---\n")); 1083 1084 j = trunc(percentage / 5); 1085 tmp1 = (char *) malloc((j + 1) * sizeof(char)); 1086 for (i = 0, p = tmp1; i < j; i++, p++) { 1087 *p = '*'; 1088 } 1089 *p = '\0'; 1090 1091 tmp2 = (char *) malloc((20 - j + 1) * sizeof(char)); 1092 for (i = 0, p = tmp2; i < 20 - j; i++, p++) { 1093 *p = '.'; 1094 } 1095 *p = '\0'; 1096 1098 1097 if (percentage > 100) { 1099 percentage = 100; 1100 } 1101 if (g_current_progress) { 1102 time_total_est = 1103 time_taken * (long) g_maximum_progress / 1104 (long) (g_current_progress); 1105 time_remaining = time_total_est - time_taken; 1106 } else { 1107 time_remaining = 0; 1108 } 1109 /* BERLIOS/ Is it useful here ? */ 1110 //g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1111 mr_asprintf(&timeline_str, 1112 "%2ld:%02ld taken %2ld:%02ld remaining ", 1113 time_taken / 60, time_taken % 60, time_remaining / 60, 1098 mr_msg(2, _("percentage = %d"), percentage); 1099 } 1100 mr_asprintf(&taskprogress, 1101 _("TASK: [%s%s] %3d%% done; %2ld:%02ld to go"), tmp1, 1102 tmp2, percentage, time_remaining / 60, 1114 1103 time_remaining % 60); 1115 mr_asprintf(&percentline_str, 1116 " %3d%% done %3d%% to go", percentage, 1117 100 - percentage); 1118 1119 if (g_text_mode) { 1120 printf(_("---progress-form---1--- %s%s"), blurb1, "\r\n"); 1121 printf(_("---progress-form---2--- %s%s"), blurb2, "\r\n"); 1122 printf(_("---progress-form---3--- %s%s"), blurb3, "\r\n"); 1123 printf(_("---progress-form---E---\n")); 1124 1125 j = trunc(percentage / 5); 1126 tmp1 = (char *) malloc((j + 1) * sizeof(char)); 1127 for (i = 0, p = tmp1; i < j; i++, p++) { 1128 *p = '*'; 1129 } 1130 *p = '\0'; 1131 1132 tmp2 = (char *) malloc((20 - j + 1) * sizeof(char)); 1133 for (i = 0, p = tmp2; i < 20 - j; i++, p++) { 1134 *p = '.'; 1135 } 1136 *p = '\0'; 1137 1138 if (percentage > 100) { 1139 mr_msg(2, _("percentage = %d"), percentage); 1140 } 1141 mr_asprintf(&taskprogress, 1142 _("TASK: [%s%s] %3d%% done; %2ld:%02ld to go"), tmp1, 1143 tmp2, percentage, time_remaining / 60, 1144 time_remaining % 60); 1145 1146 printf(_("---progress-form---4--- %s\r\n"), taskprogress); 1147 mr_free(taskprogress); 1148 } else { 1149 /* BERLIOS: center_string is now broken replace it ! */ 1150 //center_string(blurb1, 54); 1151 /* BERLIOS: center_string is now broken replace it ! */ 1152 //center_string(blurb2, 54); 1153 /* BERLIOS: center_string is now broken replace it ! */ 1154 //center_string(blurb3, 54); 1155 newtLabelSetText(g_blurb1, blurb1); 1156 newtLabelSetText(g_blurb2, blurb3); 1157 newtLabelSetText(g_blurb3, blurb2); 1158 newtScaleSet(g_scale, (unsigned long long) g_current_progress); 1159 if (percentage >= 2) { 1160 newtLabelSetText(g_timeline, timeline_str); 1161 } 1162 newtLabelSetText(g_percentline, percentline_str); 1163 newtRefresh(); 1164 } 1165 mr_free(percentline_str); 1166 mr_free(timeline_str); 1167 } 1104 1105 printf(_("---progress-form---4--- %s\r\n"), taskprogress); 1106 mr_free(taskprogress); 1107 } else { 1108 /* BERLIOS: center_string is now broken replace it ! */ 1109 //center_string(blurb1, 54); 1110 /* BERLIOS: center_string is now broken replace it ! */ 1111 //center_string(blurb2, 54); 1112 /* BERLIOS: center_string is now broken replace it ! */ 1113 //center_string(blurb3, 54); 1114 newtLabelSetText(g_blurb1, blurb1); 1115 newtLabelSetText(g_blurb2, blurb3); 1116 newtLabelSetText(g_blurb3, blurb2); 1117 newtScaleSet(g_scale, (unsigned long long) g_current_progress); 1118 if (percentage >= 2) { 1119 newtLabelSetText(g_timeline, timeline_str); 1120 } 1121 newtLabelSetText(g_percentline, percentline_str); 1122 newtRefresh(); 1123 } 1124 mr_free(percentline_str); 1125 mr_free(timeline_str); 1126 } 1168 1127 1169 1128 … … 1176 1135 * @return The backup type chosen, or @c none if the user chose "Exit to shell". 1177 1136 */ 1178 t_bkptype which_backup_media_type(bool restoring) { 1179 1180 /*@ char ************************************************************ */ 1181 t_bkptype output; 1182 1183 1184 /*@ newt ************************************************************ */ 1185 char *title_sz; 1186 char *minimsg_sz; 1187 static t_bkptype possible_bkptypes[] = 1188 { none, cdr, cdrw, dvd, tape, cdstream, udev, nfs, iso }; 1189 static char *possible_responses[] = 1190 { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", 1191 "nfs", "iso", NULL 1192 }; 1193 char *outstr = NULL; 1194 t_bkptype backup_type; 1195 int i; 1137 t_bkptype which_backup_media_type(bool restoring) { 1138 1139 /*@ char ************************************************************ */ 1140 t_bkptype output; 1141 1142 1143 /*@ newt ************************************************************ */ 1144 char *title_sz = NULL; 1145 char *minimsg_sz = NULL; 1146 static t_bkptype possible_bkptypes[] = 1147 { none, cdr, cdrw, dvd, tape, cdstream, udev, nfs, iso, usb }; 1148 static char *possible_responses[] = 1149 { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", 1150 "nfs", "iso", "usb", NULL }; 1151 char *outstr = NULL; 1152 t_bkptype backup_type; 1153 int i = 0; 1196 1154 size_t n = 0; 1197 1155 1198 newtComponent b1; 1199 newtComponent b2; 1200 newtComponent b3; 1201 newtComponent b4; 1202 newtComponent b5; 1203 newtComponent b6; 1204 newtComponent b7; 1205 newtComponent b8; 1206 newtComponent b_res; 1207 newtComponent myForm; 1208 1209 if (g_text_mode) { 1210 for (backup_type = none; backup_type == none;) { 1211 printf(_("Backup type (")); 1212 for (i = 0; possible_responses[i]; i++) { 1213 printf("%c%s", (i == 0) ? '\0' : ' ', 1214 possible_responses[i]); 1156 newtComponent b1; 1157 newtComponent b2; 1158 newtComponent b3; 1159 newtComponent b4; 1160 newtComponent b5; 1161 newtComponent b6; 1162 newtComponent b7; 1163 newtComponent b8; 1164 newtComponent b_res; 1165 newtComponent myForm; 1166 1167 if (g_text_mode) { 1168 for (backup_type = none; backup_type == none;) { 1169 printf(_("Backup type (")); 1170 for (i = 0; possible_responses[i]; i++) { 1171 printf("%c%s", (i == 0) ? '\0' : ' ', 1172 possible_responses[i]); 1173 } 1174 printf(")\n--> "); 1175 mr_getline(&outstr, &n, stdin); 1176 mr_strip_spaces(outstr); 1177 for (i = 0; possible_responses[i]; i++) { 1178 if (!strcmp(possible_responses[i], outstr)) { 1179 backup_type = possible_bkptypes[i]; 1215 1180 } 1216 printf(")\n--> "); 1217 mr_getline(&outstr, &n, stdin); 1218 strip_spaces(outstr); 1219 for (i = 0; possible_responses[i]; i++) { 1220 if (!strcmp(possible_responses[i], outstr)) { 1221 backup_type = possible_bkptypes[i]; 1222 } 1223 } 1224 } 1225 mr_free(outstr); 1226 return (backup_type); 1227 } 1228 newtDrawRootText(18, 0, WELCOME_STRING); 1229 if (restoring) { 1230 mr_asprintf(&title_sz, 1231 _("Please choose the backup media from which you want to read data.")); 1232 mr_asprintf(&minimsg_sz, _("Read from:")); 1233 } else { 1234 mr_asprintf(&title_sz, 1235 _("Please choose the backup media to which you want to archive data.")); 1236 mr_asprintf(&minimsg_sz, _("Backup to:")); 1237 } 1238 newtPushHelpLine(title_sz); 1239 mr_free(title_sz); 1181 } 1182 } 1183 mr_free(outstr); 1184 return (backup_type); 1185 } 1186 newtDrawRootText(18, 0, WELCOME_STRING); 1187 if (restoring) { 1188 mr_asprintf(&title_sz, 1189 _("Please choose the backup media from which you want to read data.")); 1190 mr_asprintf(&minimsg_sz, _("Read from:")); 1191 } else { 1192 mr_asprintf(&title_sz, 1193 _("Please choose the backup media to which you want to archive data.")); 1194 mr_asprintf(&minimsg_sz, _("Backup to:")); 1195 } 1196 newtPushHelpLine(title_sz); 1197 mr_free(title_sz); 1240 1198 1241 1199 // newtOpenWindow (23, 3, 34, 17, minimsg_sz); … … 1243 1201 mr_free(minimsg_sz); 1244 1202 1245 b1 = newtButton(1, 1, _("CD-R disks ")); 1246 b2 = newtButton(17, 1, _("CD-RW disks")); 1247 b3 = newtButton(1, 9, _("Tape drive ")); 1248 b4 = newtButton(17, 5, _("CD streamer")); 1249 b5 = newtButton(1, 5, _(" DVD disks ")); 1250 b6 = newtButton(17, 9, _(" NFS mount ")); 1251 b7 = newtButton(1, 13, _(" Hard disk ")); 1252 b8 = newtButton(17, 13, _(" Exit ")); 1253 myForm = newtForm(NULL, NULL, 0); 1254 newtFormAddComponents(myForm, b1, b5, b3, b7, b2, b4, b6, b8, 1255 NULL); 1256 b_res = newtRunForm(myForm); 1257 newtFormDestroy(myForm); 1258 newtPopWindow(); 1259 if (b_res == b1) { 1260 output = cdr; 1261 } else if (b_res == b2) { 1262 output = cdrw; 1263 } else if (b_res == b3) { 1264 output = tape; 1265 } else if (b_res == b4) { 1266 output = cdstream; 1267 } else if (b_res == b5) { 1268 output = dvd; 1269 } else if (b_res == b6) { 1270 output = nfs; 1271 } else if (b_res == b7) { 1272 output = iso; 1273 } else { 1274 output = none; 1275 } 1276 newtPopHelpLine(); 1277 return (output); 1278 } 1203 /* BERLIOS: USB ?? */ 1204 b1 = newtButton(1, 1, _("CD-R disks ")); 1205 b2 = newtButton(17, 1, _("CD-RW disks")); 1206 b3 = newtButton(1, 9, _("Tape drive ")); 1207 b4 = newtButton(17, 5, _("CD streamer")); 1208 b5 = newtButton(1, 5, _(" DVD disks ")); 1209 b6 = newtButton(17, 9, _(" NFS mount ")); 1210 b7 = newtButton(1, 13, _(" Hard disk ")); 1211 b8 = newtButton(17, 13, _(" Exit ")); 1212 myForm = newtForm(NULL, NULL, 0); 1213 newtFormAddComponents(myForm, b1, b5, b3, b7, b2, b4, b6, b8, 1214 NULL); 1215 b_res = newtRunForm(myForm); 1216 newtFormDestroy(myForm); 1217 newtPopWindow(); 1218 if (b_res == b1) { 1219 output = cdr; 1220 } else if (b_res == b2) { 1221 output = cdrw; 1222 } else if (b_res == b3) { 1223 output = tape; 1224 } else if (b_res == b4) { 1225 output = cdstream; 1226 } else if (b_res == b5) { 1227 output = dvd; 1228 } else if (b_res == b6) { 1229 output = nfs; 1230 } else if (b_res == b7) { 1231 output = iso; 1232 } else { 1233 output = none; 1234 } 1235 newtPopHelpLine(); 1236 return (output); 1237 } 1279 1238 1280 1239 … … 1284 1243 * @return The compression level (0-9) chosen, or -1 for "Exit". 1285 1244 */ 1286 int 1287 which_compression_level() { 1288 1289 /*@ char ************************************************************ */ 1290 int output = none; 1291 1292 1293 /*@ newt ************************************************************ */ 1294 1295 newtComponent b1; 1296 newtComponent b2; 1297 newtComponent b3; 1298 newtComponent b4; 1299 newtComponent b5; 1300 newtComponent b_res; 1301 newtComponent myForm; 1302 1303 newtDrawRootText(18, 0, WELCOME_STRING); 1304 newtPushHelpLine 1305 (_(" Please specify the level of compression that you want.")); 1306 // newtOpenWindow (23, 3, 34, 13, "How much compression?"); 1307 newtCenteredWindow(34, 13, _("How much compression?")); 1308 b1 = newtButton(4, 1, _("Maximum")); 1309 b2 = newtButton(18, 1, _("Average")); 1310 b3 = newtButton(4, 5, _("Minimum")); 1311 b4 = newtButton(18, 5, _(" None ")); 1312 b5 = newtButton(4, 9, _(" Exit ")); 1313 myForm = newtForm(NULL, NULL, 0); 1314 newtFormAddComponents(myForm, b1, b3, b2, b4, b5, NULL); 1315 b_res = newtRunForm(myForm); 1316 newtFormDestroy(myForm); 1317 newtPopWindow(); 1318 if (b_res == b1) { 1319 output = 9; 1320 } else if (b_res == b2) { 1321 output = 4; 1322 } else if (b_res == b3) { 1323 output = 1; 1324 } else if (b_res == b4) { 1325 output = 0; 1326 } else if (b_res == b5) { 1327 output = -1; 1328 } 1329 newtPopHelpLine(); 1330 return (output); 1331 } 1245 int which_compression_level(void) { 1246 1247 /*@ char ************************************************************ */ 1248 int output = none; 1249 1250 /*@ newt ************************************************************ */ 1251 newtComponent b1; 1252 newtComponent b2; 1253 newtComponent b3; 1254 newtComponent b4; 1255 newtComponent b5; 1256 newtComponent b_res; 1257 newtComponent myForm; 1258 1259 newtDrawRootText(18, 0, WELCOME_STRING); 1260 newtPushHelpLine 1261 (_(" Please specify the level of compression that you want.")); 1262 // newtOpenWindow (23, 3, 34, 13, "How much compression?"); 1263 newtCenteredWindow(34, 13, _("How much compression?")); 1264 b1 = newtButton(4, 1, _("Maximum")); 1265 b2 = newtButton(18, 1, _("Average")); 1266 b3 = newtButton(4, 5, _("Minimum")); 1267 b4 = newtButton(18, 5, _(" None ")); 1268 b5 = newtButton(4, 9, _(" Exit ")); 1269 myForm = newtForm(NULL, NULL, 0); 1270 newtFormAddComponents(myForm, b1, b3, b2, b4, b5, NULL); 1271 b_res = newtRunForm(myForm); 1272 newtFormDestroy(myForm); 1273 newtPopWindow(); 1274 if (b_res == b1) { 1275 output = 9; 1276 } else if (b_res == b2) { 1277 output = 4; 1278 } else if (b_res == b3) { 1279 output = 1; 1280 } else if (b_res == b4) { 1281 output = 0; 1282 } else if (b_res == b5) { 1283 output = -1; 1284 } 1285 newtPopHelpLine(); 1286 return (output); 1287 } 1332 1288 1333 1289 … … 1338 1294 * @param source_file The file containing a list of filenames to load into @p filelist. 1339 1295 */ 1340 1296 int load_filelist_into_array(struct s_filelist *filelist, 1341 1297 char *source_file) { 1342 int i; 1343 bool done; 1298 int i; 1299 bool done; 1300 char *tmp = NULL; 1301 size_t n = 0; 1302 FILE *fin = NULL; 1303 struct s_filelist_entry dummy_fle; 1344 1304 char *reason = NULL; 1345 char *tmp = NULL; 1346 size_t n = 0; 1347 FILE *fin; 1348 struct s_filelist_entry dummy_fle; 1349 1350 assert(filelist != NULL); 1351 assert_string_is_neither_NULL_nor_zerolength(source_file); 1352 1353 iamhere("entering"); 1354 if (!(fin = fopen(source_file, "r"))) { 1355 log_OS_error(source_file); 1356 mr_msg(2, "Can't open %s; therefore, cannot popup list", 1357 source_file); 1358 return (1); 1359 } 1360 mr_msg(2, "Loading %s", source_file); 1361 for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; 1362 filelist->entries++) { 1305 1306 assert(filelist != NULL); 1307 assert_string_is_neither_NULL_nor_zerolength(source_file); 1308 1309 iamhere("entering"); 1310 if (!(fin = fopen(source_file, "r"))) { 1311 log_OS_error(source_file); 1312 mr_msg(2, "Can't open %s; therefore, cannot popup list", 1313 source_file); 1314 return (1); 1315 } 1316 mr_msg(2, "Loading %s", source_file); 1317 for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; 1318 filelist->entries++) { 1319 if (feof(fin)) { 1320 break; 1321 } 1322 mr_getline(&tmp, &n, fin); 1323 i = (int) strlen(tmp); 1324 if (i < 2) { 1363 1325 if (feof(fin)) { 1364 1326 break; 1365 1327 } 1366 mr_getline(&tmp, &n, fin); 1367 i = (int) strlen(tmp); 1368 if (i < 2) { 1369 if (feof(fin)) { 1370 break; 1371 } 1372 } 1373 if (tmp[i - 1] < 32) { 1374 tmp[--i] = '\0'; 1375 } 1376 if (i < 2) { 1377 if (feof(fin)) { 1378 break; 1379 } 1380 } 1381 if (!does_file_exist(tmp)) { 1382 if (feof(fin)) { 1383 break; 1384 } 1385 } 1386 filelist->el[filelist->entries].severity = 1387 severity_of_difference(tmp, reason); 1388 mr_free(reason); 1389 strcpy(filelist->el[filelist->entries].filename, tmp); 1328 } 1329 if (tmp[i - 1] < 32) { 1330 tmp[--i] = '\0'; 1331 } 1332 if (i < 2) { 1390 1333 if (feof(fin)) { 1391 1334 break; 1392 1335 } 1393 1336 } 1394 paranoid_fclose(fin); 1395 if (filelist->entries >= ARBITRARY_MAXIMUM) { 1396 log_to_screen(_("Arbitrary limits suck, man!")); 1397 mr_free(tmp); 1398 return (1); 1399 } 1400 mr_free(tmp); 1401 1402 for (done = FALSE; !done;) { 1403 done = TRUE; 1404 for (i = 0; i < filelist->entries - 1; i++) { 1405 // if (strcmp(filelist->el[i].filename, filelist->el[i+1].filename) > 0) 1406 if (filelist->el[i].severity < filelist->el[i + 1].severity 1407 || (filelist->el[i].severity == 1408 filelist->el[i + 1].severity 1409 && strcmp(filelist->el[i].filename, 1410 filelist->el[i + 1].filename) > 0)) { 1411 memcpy((void *) &dummy_fle, 1412 (void *) &(filelist->el[i]), 1413 sizeof(struct s_filelist_entry)); 1414 memcpy((void *) &(filelist->el[i]), 1415 (void *) &(filelist->el[i + 1]), 1416 sizeof(struct s_filelist_entry)); 1417 memcpy((void *) &(filelist->el[i + 1]), 1418 (void *) &dummy_fle, 1419 sizeof(struct s_filelist_entry)); 1420 mr_msg(2, "Swapping %s and %s", 1421 filelist->el[i].filename, 1422 filelist->el[i + 1].filename); 1423 done = FALSE; 1424 } 1425 } 1426 } 1427 iamhere("leaving"); 1428 return (0); 1429 } 1430 1337 if (!does_file_exist(tmp)) { 1338 if (feof(fin)) { 1339 break; 1340 } 1341 } 1342 filelist->el[filelist->entries].severity = 1343 severity_of_difference(tmp, reason); 1344 mr_free(reason); 1345 strcpy(filelist->el[filelist->entries].filename, tmp); 1346 if (feof(fin)) { 1347 break; 1348 } 1349 } 1350 mr_free(tmp); 1351 1352 paranoid_fclose(fin); 1353 if (filelist->entries >= ARBITRARY_MAXIMUM) { 1354 log_to_screen(_("Arbitrary limits suck, man!")); 1355 return (1); 1356 } 1357 for (done = FALSE; !done;) { 1358 done = TRUE; 1359 for (i = 0; i < filelist->entries - 1; i++) { 1360 if (filelist->el[i].severity < filelist->el[i + 1].severity 1361 || (filelist->el[i].severity == 1362 filelist->el[i + 1].severity 1363 && strcmp(filelist->el[i].filename, 1364 filelist->el[i + 1].filename) > 0)) { 1365 memcpy((void *) &dummy_fle, 1366 (void *) &(filelist->el[i]), 1367 sizeof(struct s_filelist_entry)); 1368 memcpy((void *) &(filelist->el[i]), 1369 (void *) &(filelist->el[i + 1]), 1370 sizeof(struct s_filelist_entry)); 1371 memcpy((void *) &(filelist->el[i + 1]), 1372 (void *) &dummy_fle, 1373 sizeof(struct s_filelist_entry)); 1374 mr_msg(2, "Swapping %s and %s", 1375 filelist->el[i].filename, 1376 filelist->el[i + 1].filename); 1377 done = FALSE; 1378 } 1379 } 1380 } 1381 iamhere("leaving"); 1382 return (0); 1383 } 1431 1384 1432 1385 … … 1437 1390 * @note The returned value points to static storage that will be overwritten with each call. 1438 1391 */ 1439 char *filelist_entry_to_string(struct s_filelist_entry *flentry) { 1440 char *comment; 1441 1442 iamhere("entering"); 1443 assert(flentry != NULL); 1444 if (flentry->severity == 0) { 1445 mr_asprintf(&comment, "0 %93s", flentry->filename); 1446 } else if (flentry->severity == 1) { 1447 mr_asprintf(&comment, "low %93s", flentry->filename); 1448 } else if (flentry->severity == 2) { 1449 mr_asprintf(&comment, "med %93s", flentry->filename); 1450 } else { 1451 mr_asprintf(&comment, "high %93s", flentry->filename); 1452 } 1453 iamhere("leaving"); 1454 return (comment); 1455 } 1456 1457 1458 1392 char *filelist_entry_to_string(struct s_filelist_entry *flentry) { 1393 char *comment = NULL; 1394 1395 iamhere("entering"); 1396 assert(flentry != NULL); 1397 if (flentry->severity == 0) { 1398 mr_asprintf(&comment, "0 %93s", flentry->filename); 1399 } else if (flentry->severity == 1) { 1400 mr_asprintf(&comment, "low %93s", flentry->filename); 1401 } else if (flentry->severity == 2) { 1402 mr_asprintf(&comment, "med %93s", flentry->filename); 1403 } else { 1404 mr_asprintf(&comment, "high %93s", flentry->filename); 1405 } 1406 iamhere("leaving"); 1407 return(comment); 1408 } 1459 1409 1460 1410 … … 1474 1424 1475 1425 /*@ ???? ************************************************************ */ 1476 void *curr_choice ;1426 void *curr_choice = NULL; 1477 1427 void *keylist[ARBITRARY_MAXIMUM]; 1478 1428 … … 1482 1432 1483 1433 /*@ long ************************************************************ */ 1484 long i = 0 ;1485 long lng = 0 ;1434 long i = 0L; 1435 long lng = 0L; 1486 1436 1487 1437 /*@ buffers ********************************************************* */ 1488 char *tmp ;1489 char *differ_sz ;1490 1491 struct s_filelist *filelist; 1438 char *tmp = NULL; 1439 char *differ_sz = NULL; 1440 struct s_filelist *filelist = NULL; 1441 1492 1442 assert_string_is_neither_NULL_nor_zerolength(source_file); 1493 1443 if (g_text_mode) { … … 1563 1513 popup_and_OK(tmp); 1564 1514 mr_free(tmp); 1565 mr_free(reason);1566 1515 } 1567 1516 } … … 1571 1520 newtPopWindow(); 1572 1521 newtPopHelpLine(); 1522 return; 1573 1523 } 1574 1524
Note:
See TracChangeset
for help on using the changeset viewer.