Changeset 1185 in MondoRescue for trunk/mondo/src/common/newt-specific.c


Ignore:
Timestamp:
Feb 19, 2007, 1:51:26 AM (17 years ago)
Author:
Bruno Cornec
Message:

Merges in trunk modifications coming from stable (common)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/src/common/newt-specific.c

    r1106 r1185  
    1919#include "my-stuff.h"
    2020#include "mr_mem.h"
     21#include "mr_msg.h"
     22#include "mr_str.h"
     23
    2124#include "mondostructures.h"
    2225#include "newt-specific.h"
     
    2730#include "libmondo-fork-EXT.h"
    2831#include "newt-specific-EXT.h"
    29 #include "mr_mem.h"
    3032
    3133/*@unused@*/
     
    3638extern char *g_mondo_home;
    3739extern char *ps_options;
    38     extern char *ps_proc_id;
     40extern char *ps_proc_id;
    3941
    4042extern void set_signals(int);
     
    6567    *g_blurb_str_2,         ///< The string for line 2 of the blurb in the progress form
    6668    *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
     70newtComponent g_isoform_main = NULL,    ///< The evalcall form component itself
    6871    g_isoform_header = NULL,    ///< The component for the evalcall form title
    6972    g_isoform_scale = NULL, ///< The progress bar component in the evalcall form
    7073    g_isoform_timeline = NULL,  ///< The line of the evalcall form that shows the time elapsed/remaining
    7174    g_isoform_pcline = NULL;    ///< The line of the evalcall form that shows the percent completed/remaining
     75
    7276long g_isoform_starttime;   ///< The time (in seconds since the epoch) that the evalcall form was opened.
    7377int g_isoform_old_progress = -1;    ///< The most recent progress update of the evalcall form (percent).
     
    7983int g_currentY = 3;         ///< The row to write background progress messages to. Incremented each time a message is written.
    8084extern int g_current_media_number;
    81     pid_t g_main_pid = 0;       ///< The PID of the main Mondo process.
     85pid_t g_main_pid = 0;       ///< The PID of the main Mondo process.
    8286long g_maximum_progress = 999;  ///< The maximum amount of progress (100%) for the currently opened progress form.
    8387long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form.
     
    8589bool g_text_mode = TRUE;    ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface.
    8690bool 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.
     91char *g_erase_tmpdir_and_scratchdir = NULL; ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo.
    8892char *g_selfmounted_isodir = NULL;  ///< Holds the NFS mountpoint if mounted via mondoarchive.
    8993
    9094/* @} - end of globalGroup */
    91 
    92 //int g_fd_in=-1, g_fd_out=-1;
    9395
    9496void popup_and_OK(char *);
     
    104106 * @return TRUE for yes; FALSE for no.
    105107 */
    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) {
     108bool 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 {
    117137                sync();
    118138                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}
    145146
    146147
     
    153154    bool ask_me_OK_or_cancel(char *prompt) {
    154155
    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';
    170170            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);
    181177        } 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}
    185185
    186186
     
    251251}
    252252
     253
    253254/**
    254255 * Exit Mondo with a fatal error.
     
    256257 * @note This function never returns.
    257258 */
    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());
     259void 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());
    276283            kill(g_main_pid, SIGTERM);
    277284            finish(1);
    278285        }
    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}
    344343
    345344
     
    350349 * @note This function never returns.
    351350 */
    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.*",
     351void 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.*",
    367358                                   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}
    402386
    403387
     
    408392 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression.
    409393 */
    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                     }
     394void 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;
    453432                }
    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}
    460443
    461444
     
    465448 * @note The message is also written to the logfile.
    466449 */
    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     }
     450void 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}
    513495
    514496
     
    538520 * @param ttl The title to use for the evalcall form.
    539521 */
    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         }
     522void 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);
    565540        /* 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}
    587566
    588567
     
    596575 * @param max_val The maximum amount of progress (number of filesets, etc.)
    597576 */
    598     void
    599      open_progress_form(char *title, char *b1, char *b2, char *b3,
     577void open_progress_form(char *title, char *b1, char *b2, char *b3,
    600578                        long max_val) {
    601579
    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
    659638
    660639/**
     
    662641 * @param prompt The message.
    663642 */
    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             printf
    673                 ("---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     }
     643void 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
    680659
    681660/**
     
    686665 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
    687666 */
    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();
     667bool 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';
    748696        return(ret);
    749697    }
     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}
    750729
    751730
     
    757736 * @return TRUE if @p button1 was pushed, FALSE otherwise.
    758737 */
    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("--> ");
     738bool 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("--> ");
    786766                mr_free(tmp);
    787767                mr_getline(&tmp, &n, stdin);
    788768            }
    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);
    825771            return (TRUE);
    826772        } else {
     773            mr_free(tmp);
    827774            return (FALSE);
    828775        }
    829776    }
    830777
    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}
    832811
    833812
     
    836815 * on the screen.
    837816 */
    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         for (i = g_noof_log_lines - 1; i >= 0; i--) {
    854             //BERLIOS : removed for now, Think it's useless : err_log_lines[i][79] = '\0';
    855             newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines,
    856                             err_log_lines[i]);
    857         }
    858         newtRefresh();
    859     }
     817void 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}
    860839
    861840
     
    864843 * only allocate some memory.
    865844 */
    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     }
     845void 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}
    895869
    896870
     
    899873 * @param num The numerator of the ratio.
    900874 */
    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;
     875void 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);
    926945        } 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            }
    935974        } 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}
    1021989
    1022990
     
    1026994 * @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.
    1027995 */
    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     }
     996void 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}
    10401005
    10411006
     
    10461011 * @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.
    10471012 */
    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;
     1013void 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;
    10661029        char *tmp1;
    10671030        char *tmp2;
    10681031        char *p;
    10691032
    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
    10981097        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,
    11141103                 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}
    11681127
    11691128
     
    11761135 * @return The backup type chosen, or @c none if the user chose "Exit to shell".
    11771136 */
    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;
     1137t_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;
    11961154        size_t n = 0;
    11971155
    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];
    12151180                }
    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);
    12401198
    12411199        //  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
     
    12431201        mr_free(minimsg_sz);
    12441202
    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}
    12791238
    12801239
     
    12841243 * @return The compression level (0-9) chosen, or -1 for "Exit".
    12851244 */
    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     }
     1245int 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}
    13321288
    13331289
     
    13381294 * @param source_file The file containing a list of filenames to load into @p filelist.
    13391295 */
    1340     int load_filelist_into_array(struct s_filelist *filelist,
     1296int load_filelist_into_array(struct s_filelist *filelist,
    13411297                                 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;
    13441304        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) {
    13631325            if (feof(fin)) {
    13641326                break;
    13651327            }
    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) {
    13901333            if (feof(fin)) {
    13911334                break;
    13921335            }
    13931336        }
    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}
    14311384
    14321385
     
    14371390 * @note The returned value points to static storage that will be overwritten with each call.
    14381391 */
    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 
     1392char *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}
    14591409
    14601410
     
    14741424
    14751425        /*@ ???? ************************************************************ */
    1476         void *curr_choice;
     1426        void *curr_choice = NULL;
    14771427        void *keylist[ARBITRARY_MAXIMUM];
    14781428
     
    14821432
    14831433        /*@ long ************************************************************ */
    1484         long i = 0;
    1485         long lng = 0;
     1434        long i = 0L;
     1435        long lng = 0L;
    14861436
    14871437        /*@ 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
    14921442        assert_string_is_neither_NULL_nor_zerolength(source_file);
    14931443        if (g_text_mode) {
     
    15631513                        popup_and_OK(tmp);
    15641514                        mr_free(tmp);
    1565                         mr_free(reason);
    15661515                    }
    15671516                }
     
    15711520        newtPopWindow();
    15721521        newtPopHelpLine();
     1522        return;
    15731523    }
    15741524
Note: See TracChangeset for help on using the changeset viewer.