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


Ignore:
Timestamp:
Oct 24, 2006, 8:49:18 AM (18 years ago)
Author:
Bruno Cornec
Message:

Huge patch to introduce low level functions that will bw used everywhere (mr_free, mr_asprintf, ...)
Nearly linking now due to that.

File:
1 edited

Legend:

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

    r838 r900  
    2626#include "libmondo-fork-EXT.h"
    2727#include "newt-specific-EXT.h"
     28#include "mr_mem.h"
    2829
    2930/*@unused@*/
     
    116117                    ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ",
    117118                     prompt);
    118                 (void) getline(&tmp, &n, stdin);
     119                mr_getline(&tmp, &n, stdin);
    119120                if (tmp[strlen(tmp) - 1] == '\n')
    120121                    tmp[strlen(tmp) - 1] = '\0';
     
    125126                }
    126127                if (strstr(_("yesYES"), tmp)) {
    127                     paranoid_free(tmp);
     128                    mr_free(tmp);
    128129                    return (TRUE);
    129130                } else if (strstr(_("NOno"), tmp)) {
    130                     paranoid_free(tmp);
     131                    mr_free(tmp);
    131132                    return (FALSE);
    132133                } else {
     
    161162                ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ",
    162163                 prompt);
    163             (void) getline(&tmp, &n, stdin);
     164            mr_getline(&tmp, &n, stdin);
    164165            if (tmp[strlen(tmp) - 1] == '\n')
    165166                tmp[strlen(tmp) - 1] = '\0';
     
    170171            }
    171172            if (strstr(_("okOKOkYESyes"), tmp)) {
    172                 paranoid_free(tmp);
     173                mr_free(tmp);
    173174                return (TRUE);
    174175            } else {
    175                 paranoid_free(tmp);
     176                mr_free(tmp);
    176177                return (FALSE);
    177178            }
     
    243244    char *tmp = NULL;
    244245
    245     asprintf(&tmp,"kill `ps %s | grep \" %s \" | awk '{print $1;}' | grep -vx \"\\?\"`", ps_options, str);
     246    mr_asprintf(&tmp,"kill `ps %s | grep \" %s \" | awk '{print $1;}' | grep -vx \"\\?\"`", ps_options, str);
    246247run_program_and_log_output(tmp, TRUE);
    247     paranoid_free(tmp);
     248    mr_free(tmp);
    248249}
    249250
     
    264265        /*@ end vars **************************************************** */
    265266
    266         asprintf(&fatalstr, "-------FATAL ERROR---------");
     267        mr_asprintf(&fatalstr, "-------FATAL ERROR---------");
    267268        set_signals(FALSE);     // link to external func
    268269        g_exiting = TRUE;
     
    297298        sync();
    298299        if (g_tmpfs_mountpt != NULL) {
    299             asprintf(&tmp, "umount %s", g_tmpfs_mountpt);
     300            mr_asprintf(&tmp, "umount %s", g_tmpfs_mountpt);
    300301            chdir("/");
    301302            for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) {
     
    304305                run_program_and_log_output(tmp, 5);
    305306            }
    306             paranoid_free(tmp);
     307            mr_free(tmp);
    307308        }
    308309
     
    312313
    313314        if (g_selfmounted_isodir) {
    314             asprintf(&command, "umount %s", g_selfmounted_isodir);
     315            mr_asprintf(&command, "umount %s", g_selfmounted_isodir);
    315316            run_program_and_log_output(command, 5);
    316             asprintf(&command, "rmdir %s", g_selfmounted_isodir);
     317            mr_asprintf(&command, "rmdir %s", g_selfmounted_isodir);
    317318            run_program_and_log_output(command, 5);
    318             paranoid_free(g_selfmounted_isodir);
     319            mr_free(g_selfmounted_isodir);
    319320        }
    320321
     
    322323            log_msg(0, fatalstr);
    323324            log_msg(0, error_string);
    324             //      popup_and_OK (error_string);
    325325            newtFinished();
    326326        }
    327327
    328         system
    329             ("gzip -9c "MONDO_LOGFILE" > /tmp/MA.log.gz 2> /dev/null");
    330328        printf
    331329                (_("If you require technical support, please contact the mailing list.\n"));
     
    334332                (_("The list's members can help you, if you attach that file to your e-mail.\n"));
    335333        printf(_("Log file: %s\n"), MONDO_LOGFILE);
    336         if (does_file_exist("/tmp/MA.log.gz")) {
    337             printf
    338                 (_("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n"));
    339         }
    340334        printf(_("Mondo has aborted.\n"));
    341335        register_pid(0, "mondo");   // finish() does this too, FYI
     
    357351     finish(int signal) {
    358352        char *command = NULL;
    359 
    360         /*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */
    361 
    362         /* newtPopHelpLine(); */
    363353
    364354        register_pid(0, "mondo");
     
    371361        }
    372362        if (g_selfmounted_isodir) {
    373             asprintf(&command, "umount %s", g_selfmounted_isodir);
     363            mr_asprintf(&command, "umount %s", g_selfmounted_isodir);
    374364            run_program_and_log_output(command, 1);
    375             asprintf(&command, "rmdir %s", g_selfmounted_isodir);
     365            mr_asprintf(&command, "rmdir %s", g_selfmounted_isodir);
    376366            run_program_and_log_output(command, 1);
    377             paranoid_free(g_selfmounted_isodir);
    378         }
    379 //  iamhere("foo");
    380         /* system("clear"); */
    381 //  iamhere("About to call newtFinished");
     367            mr_free(g_selfmounted_isodir);
     368        }
    382369        if (!g_text_mode) {
    383370            if (does_file_exist("/THIS-IS-A-RAMDISK")) {
     
    389376            }
    390377        }
    391 //  system("clear");
    392 //  iamhere("Finished calling newtFinished");
    393378        printf(_("Execution run ended; result=%d\n"), signal);
    394379        printf(_("Type 'less %s' to see the output log\n"), MONDO_LOGFILE);
     
    428413        }
    429414        if (grep_for_me[0] != '\0') {
    430             asprintf(&command, "grep '%s' %s | tail -n%d",
     415            mr_asprintf(&command, "grep '%s' %s | tail -n%d",
    431416                     grep_for_me, filename, g_noof_log_lines);
    432417        } else {
    433             asprintf(&command, "tail -n%d %s", g_noof_log_lines, filename);
     418            mr_asprintf(&command, "tail -n%d %s", g_noof_log_lines, filename);
    434419        }
    435420        fin = popen(command, "r");
     
    440425                for (;
    441426                    strlen(err_log_lines[i]) < 2 && !feof(fin);) {
    442                     getline(&(err_log_lines[i]), &n, fin);
     427                    mr_getline(&(err_log_lines[i]), &n, fin);
    443428                    strip_spaces(err_log_lines[i]);
    444429                    if (!strncmp(err_log_lines[i], "root:", 5)) {
    445                         asprintf(&tmp, "%s", err_log_lines[i] + 6);
    446                         paranoid_free(err_log_lines[i]);
     430                        mr_asprintf(&tmp, "%s", err_log_lines[i] + 6);
     431                        mr_free(err_log_lines[i]);
    447432                        err_log_lines[i] = tmp;
    448433                    }
     
    455440        }
    456441        refresh_log_screen();
    457         paranoid_free(command);
     442        mr_free(command);
    458443    }
    459444
     
    477462
    478463        va_start(args, fmt);
    479         vasprintf(&output, fmt, args);
     464        mr_vasprintf(&output, fmt, args);
    480465        log_msg(0, output);
    481466        if (strlen(output) > 80) {
     
    489474
    490475        if (err_log_lines) {
    491             paranoid_free(err_log_lines[0]);
     476            mr_free(err_log_lines[0]);
    492477            for (i = 1; i < g_noof_log_lines; i++) {
    493478                err_log_lines[i - 1] = err_log_lines[i];
     
    549534
    550535        assert(ttl != NULL);
    551         asprintf(&title, ttl);
     536        mr_asprintf(&title, ttl);
    552537        // BERLIOS: We need to unallocate it somewhere
    553         asprintf(&g_isoform_header_str, title);
     538        mr_asprintf(&g_isoform_header_str, title);
    554539        //  center_string (title, 80);
    555540        if (g_text_mode) {
    556541            log_msg(0, title);
    557542        } else {
    558             asprintf(&tmp, title);
     543            mr_asprintf(&tmp, title);
    559544            /* BERLIOS: center_string is now broken replace it ! */
    560545            //center_string(tmp, 80);
    561546            newtPushHelpLine(tmp);
    562             paranoid_free(tmp);
     547            mr_free(tmp);
    563548        }
    564549        /* BERLIOS: center_string is now broken replace it ! */
     
    581566        }
    582567        update_evalcall_form(0);
    583         paranoid_free(title);
     568        mr_free(title);
    584569    }
    585570
     
    613598        assert(b3 != NULL);
    614599
    615         asprintf(&blurb1, b1);
    616         asprintf(&blurb2, b2);
    617         asprintf(&blurb3, b3);
    618         asprintf(&b1c, b1);
     600        mr_asprintf(&blurb1, b1);
     601        mr_asprintf(&blurb2, b2);
     602        mr_asprintf(&blurb3, b3);
     603        mr_asprintf(&b1c, b1);
    619604        /* BERLIOS: center_string is now broken replace it ! */
    620605        //center_string(b1c, 80);
     
    627612        g_current_progress = 0;
    628613        // BERLIOS: We need to unallocate them
    629         asprintf(&g_blurb_str_1, blurb1);
    630         asprintf(&g_blurb_str_2, blurb3);
    631         asprintf(&g_blurb_str_3, blurb2);
     614        mr_asprintf(&g_blurb_str_1, blurb1);
     615        mr_asprintf(&g_blurb_str_2, blurb3);
     616        mr_asprintf(&g_blurb_str_3, blurb2);
    632617        if (g_text_mode) {
    633618            log_msg(0, blurb1);
     
    651636        }
    652637        update_progress_form_full(blurb1, blurb2, blurb3);
    653         paranoid_free(b1c);
    654         paranoid_free(blurb1);
    655         paranoid_free(blurb2);
    656         paranoid_free(blurb3);
     638        mr_free(b1c);
     639        mr_free(blurb1);
     640        mr_free(blurb2);
     641        mr_free(blurb3);
    657642    }
    658643
     
    710695                ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n-->  ",
    711696                 title, b);
    712             paranoid_free(output);
    713             (void) getline(&output, &n, stdin);
     697            mr_free(output);
     698            mr_getline(&output, &n, stdin);
    714699            if (output[strlen(output) - 1] == '\n')
    715700                output[strlen(output) - 1] = '\0';
    716701            return (ret);
    717702        }
    718         asprintf(&blurb, b);
     703        mr_asprintf(&blurb, b);
    719704        text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);
    720705
     
    732717        //center_string(blurb, 80);
    733718        newtPushHelpLine(blurb);
    734         paranoid_free(blurb);
     719        mr_free(blurb);
    735720
    736721        b_res = newtRunForm(myForm);
     
    741726            // Copy entry_value before destroying the form
    742727            // clearing potentially output before
    743             paranoid_alloc(output,*entry_value);
     728            mr_allocstr(output,*entry_value);
    744729        }
    745730        newtFormDestroy(myForm);
     
    779764                printf("%s (%s or %s) --> ", p, button1, button2);
    780765            }
    781             for (asprintf(&tmp, " ");
     766            for (mr_asprintf(&tmp, " ");
    782767                 strcmp(tmp, button1) && (strlen(button2) == 0
    783768                                          || strcmp(tmp, button2));) {
    784769                printf("--> ");
    785                 paranoid_free(tmp);
    786                 (void) getline(&tmp, &n, stdin);
     770                mr_free(tmp);
     771                mr_getline(&tmp, &n, stdin);
    787772            }
    788773            if (!strcmp(tmp, button1)) {
    789                 paranoid_free(tmp);
     774                mr_free(tmp);
    790775                return (TRUE);
    791776            } else {
    792                 paranoid_free(tmp);
     777                mr_free(tmp);
    793778                return (FALSE);
    794779            }
    795780        }
    796781
    797         asprintf(&prompt, p);
     782        mr_asprintf(&prompt, p);
    798783        text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0);
    799784        b_1 =
     
    816801        //center_string(prompt, 80);
    817802        newtPushHelpLine(prompt);
    818         paranoid_free(prompt);
     803        mr_free(prompt);
    819804        b_res = newtRunForm(myForm);
    820805        newtPopHelpLine();
     
    943928            || percentage > g_isoform_old_progress) {
    944929            g_isoform_old_progress = percentage;
    945             asprintf(&timeline_str,
     930            mr_asprintf(&timeline_str,
    946931                     _("%2ld:%02ld taken            %2ld:%02ld remaining"),
    947932                     time_taken / 60, time_taken % 60, time_remaining / 60,
     
    968953                *p = '\0';
    969954
    970                 asprintf(&pcline_str, " Working%s%s %c", tmp1, tmp2,
     955                mr_asprintf(&pcline_str, " Working%s%s %c", tmp1, tmp2,
    971956                         special_dot_char(g_mysterious_dot_counter));
    972                 paranoid_free(tmp1);
    973                 paranoid_free(tmp2);
     957                mr_free(tmp1);
     958                mr_free(tmp2);
    974959            } else {
    975                 asprintf(&pcline_str,
     960                mr_asprintf(&pcline_str,
    976961                         _(" %3d%% done              %3d%% to go"),
    977962                         percentage, 100 - percentage);
     
    992977
    993978                if (percentage >= 3) {
    994                     asprintf(&taskprogress,
     979                    mr_asprintf(&taskprogress,
    995980                             "TASK:  [%s%s] %3d%% done; %2ld:%02ld to go",
    996981                             tmp1, tmp2, percentage, time_remaining / 60,
     
    1000985                    printf("---evalcall---2--- %s\r\n", taskprogress);
    1001986                    printf("---evalcall---E---\r\n");
    1002                     paranoid_free(taskprogress);
     987                    mr_free(taskprogress);
    1003988                }
    1004989            } else {
     
    1010995                }
    1011996            }
    1012             paranoid_free(timeline_str);
    1013             paranoid_free(pcline_str);
     997            mr_free(timeline_str);
     998            mr_free(pcline_str);
    1014999        }
    10151000        if (!g_text_mode) {
     
    10321017            return;
    10331018        }
    1034         paranoid_free(g_blurb_str_2);
    1035         asprintf(&g_blurb_str_2, blurb3);
     1019        mr_free(g_blurb_str_2);
     1020        mr_asprintf(&g_blurb_str_2, blurb3);
    10361021        update_progress_form_full(g_blurb_str_1, g_blurb_str_2,
    10371022                                  g_blurb_str_3);
     
    10811066        } else {
    10821067            if (g_current_progress > g_maximum_progress) {
    1083                 asprintf(&tmp,
     1068                mr_asprintf(&tmp,
    10841069                         "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld",
    10851070                         blurb1, blurb2, blurb3, g_current_progress,
    10861071                         g_maximum_progress);
    10871072                log_msg(0, tmp);
    1088                 paranoid_free(tmp);
     1073                mr_free(tmp);
    10891074                g_current_progress = g_maximum_progress;
    10901075            }
     
    11081093        /* BERLIOS/ Is it useful here ? */
    11091094        //g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
    1110         asprintf(&timeline_str,
     1095        mr_asprintf(&timeline_str,
    11111096                 "%2ld:%02ld taken               %2ld:%02ld remaining  ",
    11121097                 time_taken / 60, time_taken % 60, time_remaining / 60,
    11131098                 time_remaining % 60);
    1114         asprintf(&percentline_str,
     1099        mr_asprintf(&percentline_str,
    11151100                 " %3d%% done                 %3d%% to go", percentage,
    11161101                 100 - percentage);
     
    11381123                log_msg(2, _("percentage = %d"), percentage);
    11391124            }
    1140             asprintf(&taskprogress,
     1125            mr_asprintf(&taskprogress,
    11411126                     _("TASK:  [%s%s] %3d%% done; %2ld:%02ld to go"), tmp1,
    11421127                     tmp2, percentage, time_remaining / 60,
     
    11441129
    11451130            printf(_("---progress-form---4--- %s\r\n"), taskprogress);
    1146             paranoid_free(taskprogress);
     1131            mr_free(taskprogress);
    11471132        } else {
    11481133            /* BERLIOS: center_string is now broken replace it ! */
     
    11621147            newtRefresh();
    11631148        }
    1164         paranoid_free(percentline_str);
    1165         paranoid_free(timeline_str);
     1149        mr_free(percentline_str);
     1150        mr_free(timeline_str);
    11661151    }
    11671152
     
    12141199                }
    12151200                printf(")\n--> ");
    1216                 (void) getline(&outstr, &n, stdin);
     1201                mr_getline(&outstr, &n, stdin);
    12171202                strip_spaces(outstr);
    12181203                for (i = 0; possible_responses[i]; i++) {
     
    12221207                }
    12231208            }
    1224             paranoid_free(outstr);
     1209            mr_free(outstr);
    12251210            return (backup_type);
    12261211        }
    12271212        newtDrawRootText(18, 0, WELCOME_STRING);
    12281213        if (restoring) {
    1229             asprintf(&title_sz,
     1214            mr_asprintf(&title_sz,
    12301215                     _("Please choose the backup media from which you want to read data."));
    1231             asprintf(&minimsg_sz, _("Read from:"));
    1232         } else {
    1233             asprintf(&title_sz,
     1216            mr_asprintf(&minimsg_sz, _("Read from:"));
     1217        } else {
     1218            mr_asprintf(&title_sz,
    12341219                     _("Please choose the backup media to which you want to archive data."));
    1235             asprintf(&minimsg_sz, _("Backup to:"));
     1220            mr_asprintf(&minimsg_sz, _("Backup to:"));
    12361221        }
    12371222        newtPushHelpLine(title_sz);
    1238         paranoid_free(title_sz);
     1223        mr_free(title_sz);
    12391224
    12401225        //  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
    12411226        newtCenteredWindow(34, 17, minimsg_sz);
    1242         paranoid_free(minimsg_sz);
     1227        mr_free(minimsg_sz);
    12431228
    12441229        b1 = newtButton(1, 1, _("CD-R disks "));
     
    13631348                break;
    13641349            }
    1365             (void) getline(&tmp, &n, fin);
     1350            mr_getline(&tmp, &n, fin);
    13661351            i = (int) strlen(tmp);
    13671352            if (i < 2) {
     
    13851370            filelist->el[filelist->entries].severity =
    13861371                severity_of_difference(tmp, reason);
    1387             paranoid_free(reason);
     1372            mr_free(reason);
    13881373            strcpy(filelist->el[filelist->entries].filename, tmp);
    13891374            if (feof(fin)) {
     
    13941379        if (filelist->entries >= ARBITRARY_MAXIMUM) {
    13951380            log_to_screen(_("Arbitrary limits suck, man!"));
    1396             paranoid_free(tmp);
     1381            mr_free(tmp);
    13971382            return (1);
    13981383        }
    1399         paranoid_free(tmp);
     1384        mr_free(tmp);
    14001385
    14011386        for (done = FALSE; !done;) {
     
    14421427        assert(flentry != NULL);
    14431428        if (flentry->severity == 0) {
    1444             asprintf(&comment, "0     %93s", flentry->filename);
     1429            mr_asprintf(&comment, "0     %93s", flentry->filename);
    14451430        } else if (flentry->severity == 1) {
    1446             asprintf(&comment, "low   %93s", flentry->filename);
     1431            mr_asprintf(&comment, "low   %93s", flentry->filename);
    14471432        } else if (flentry->severity == 2) {
    1448             asprintf(&comment, "med   %93s", flentry->filename);
    1449         } else {
    1450             asprintf(&comment, "high  %93s", flentry->filename);
     1433            mr_asprintf(&comment, "med   %93s", flentry->filename);
     1434        } else {
     1435            mr_asprintf(&comment, "high  %93s", flentry->filename);
    14511436        }
    14521437        iamhere("leaving");
     
    15251510                                   keylist[i]);
    15261511        }
    1527         asprintf(&differ_sz,
     1512        mr_asprintf(&differ_sz,
    15281513                 _("  %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list."),
    15291514                 i);
    15301515        newtPushHelpLine(differ_sz);
    1531         paranoid_free(differ_sz);
     1516        mr_free(differ_sz);
    15321517
    15331518        bClose = newtCompactButton(10, 15, _(" Close  "));
    15341519        bSelect = newtCompactButton(30, 15, _(" Select "));
    1535         asprintf(&tmp, "%-10s               %-20s", _("Priority"),
     1520        mr_asprintf(&tmp, "%-10s               %-20s", _("Priority"),
    15361521                 _("Filename"));
    15371522        headerMsg = newtLabel(2, 1, tmp);
    1538         paranoid_free(tmp);
     1523        mr_free(tmp);
    15391524
    15401525        newtOpenWindow(5, 4, 70, 16, _("Non-matching files"));
     
    15581543                        severity_of_difference(filelist->el[currline].
    15591544                                               filename, reason);
    1560                         asprintf(&tmp, "%s --- %s",
     1545                        mr_asprintf(&tmp, "%s --- %s",
    15611546                                 filelist->el[currline].filename, reason);
    15621547                        popup_and_OK(tmp);
    1563                         paranoid_free(tmp);
    1564                         paranoid_free(reason);
     1548                        mr_free(tmp);
     1549                        mr_free(reason);
    15651550                    }
    15661551                }
Note: See TracChangeset for help on using the changeset viewer.