Changeset 45 in MondoRescue for trunk/mondo


Ignore:
Timestamp:
Oct 5, 2005, 12:51:47 AM (19 years ago)
Author:
bcornec
Message:

asprint and getline now added

Location:
trunk/mondo/mondo/common
Files:
7 edited

Legend:

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

    r42 r45  
    1 /* X-specific.c
    2 
     1/* $Id$
    32
    43- subroutines which do display-type things
    54  and use the Qt library to do them
    65
    7 10/04
    8 - took out the newt-related subroutines
    9 
    10 09/12
    11 - created
    126*/
    137
     
    2216#include "libmondo-gui-EXT.h"
    2317#include "lib-common-externs.h"
    24 
    25 
    2618
    2719
  • trunk/mondo/mondo/common/libmondo-archive.c

    r41 r45  
    1 /* libmondo-archive.c
    2    $Id$
     1/* $Id$
    32
    43subroutines to handle the archiving of files
    54
    6 
    7 
    8 07/14
    9 - moved all ACL, xattr stuff here from libmondo-filelist.c
    10 
    11 07/12
    12 - when trying to find boot loader, look for /boot's /dev, not just /'s dev
    13 
    14 07/10
    15 - better detection of changed files
    16 - added ACL, xattr support for afio
    17 
    18 06/17
    19 - backup with partimagehack if NTFS device; dd, if non-NTFS device
    20 
    21 06/14
    22 - use mondorescue.iso instead of mindi.iso
    23 
    24 04/28
    25 - cleaned up if/then architecture-specific stuff re: CD-R(W)s
    26 
    27 04/03
    28 - added star support
    29 
    30 03/12
    31 - modified offer_to_write_floppies() to support dual-disk boot/root thing
    32 
    33 01/20/2004
    34 - reformat dvd twice if necessary
    35 
    36 12/01/2003
    37 - added pause_for_N_seconds(5, "Letting DVD drive settle");
    38 
    39 11/23
    40 - added #define DVDRWFORMAT
    41 
    42 11/20
    43 - use --no-emul-boot -b isolinux.bin instead of -b mindi-boot.2880.img
    44 
    45 10/23
    46 - wipe DVD at start, whether or not disk is DVD-RW; this is
    47   just a test, to see why dvd+rw-format followed by growiosfs
    48   locks up the drive
    49 - use the singlethreaded make_afioballs_and_images_OLD()
    50   instead of the multithreaded make_afioballs_and_images()
    51   if backing up to tape
    52 
    53 10/21
    54 - if backing up to dvd, look for relevant tools;
    55   abort if missing
    56 
    57 10/15
    58 - UI tweaks
    59 
    60 10/10
    61 - eject/inject DVD after wiping it
    62 
    63 09/27
    64 - pause_and_ask_for_cdr() will now blank DVD if necessary
    65 
    66 09/26
    67 - proper reporting of media type in displayed strings
    68   (i.e. DVD if DVD, CD if CD, etc.)
    69  
    70 09/25
    71 - add DVD support
    72 
    73 09/23
    74 - malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
    75   and free_libmondo_global_strings() - which are in libmondo-tools.c
    76 
    77 09/15
    78 - changed a bunch of char[MAX_STR_LEN]'s to char*; malloc; free;
    79 
    80 09/14
    81 - cosmetic bug re: call to 'which dvdrecord'
    82 
    83 09/09
    84 - copy `locate isolinux.bin | tail -n1` to CD before calling mkisfso
    85   if file is missing (in which case, bug in Mindi.pl!)
    86 - reduced noof_threads from 3 to 2
    87 - fixed cosmetic bug in make_slices_and_images()
    88 
    89 09/02
    90 - fixed cosmetic bug in verify_data()
    91 
    92 05/01 - 08/31
    93 - added partimagehack hooks
    94 - make twice as many archives at once as before
    95 - fixed syntax error re: system(xxx,FALSE)
    96 - unmount CD-ROM before burning (necessary for RH8/9)
    97 - only ask for new media if sensible
    98 - fixed mondoarchive -Vi multi-CD verify bug (Tom Mortell)
    99 - use single-threaded make_afioballs_and_images() if FreeBSD
    100 - fixed bug on line 476 (Joshua Oreman)
    101 - re-enabled the pause, for people w/ weird CD-ROM drives
    102 - added Joshua Oreman's FreeBSD patches
    103 - don't listen to please_dont_eject_when_restoring
    104   ...after all, we're not restoring :)
    105 
    106 04/01 - 04/30
    107 - cleaned up archive_this_fileset()
    108 - decreased ARCH_THREADS from 3 to 2
    109 - pause_and_ask_for_cd() --- calls retract_CD_tray_and_defeat_autorun()
    110 - call assert() and log_OS_error() in various places
    111 - cleaned up code a bit
    112 - increased ARCH_THREADS from 2 to 3
    113 - misc clean-up (Tom Mortell)
    114 
    115 03/15/2003
    116 - fixed problem w/ multi-ISO verify cycle (Tom Mortell)
    117 
    118 11/01 - 12/31/2002
    119 - removed references to make_afioballs_and_images_OLD()
    120 - added some error-checking to make_afioballs_in_background
    121 - make_iso_and_go_on() now copies Mondo's autorun file to CD
    122 - set scratchdir dir to 1744 when burning CD
    123 - cleaned up code a bit
    124 - in call_mindi_...(), gracefully handle the user's input
    125   if they specify the boot loader but not the boot device
    126 - offer to abort if GRUB is boot loader and /dev/md* is
    127   the boot device (bug in grub-install)
    128 - if boot loader is R then write RAW as bootloader.name
    129 - multithreaded make_afioballs_and_images()
    130 - fixed slice_up_file_etc() for 0-compression users
    131 - line 1198: added call to is_this_file_compressed() to stop
    132   slice_up_file_etc() from compressing files which are
    133   already compressed
    134 - other hackery related to the above enhancement
    135 - afio no longer forcibly compresses all files (i.e. I dropped
    136   the -U following suggestions from users); let's see if
    137   it works :)
    138 
    139 10/01 - 10/31
    140 - mondoarchive (with no parameters) wasn't working
    141   if user said yes when asked if BurnProof drive; FIXED
    142 - if manual CD tray and writing to ISO's then prompt
    143   for each & every new CD
    144 - moved a lot of subroutines here
    145   from mondo-archive.c and mondo-floppies.c
    146 
    147 09/01 - 09/30
    148 - if CD not burned OK then don't try to verify
    149 - change 64k to TAPE_BLOCK_SIZE
    150 - run_program_and_log_output() now takes boolean operator to specify
    151   whether it will log its activities in the event of _success_
    152 - orig_vfy_flag_val added to write_iso_and_go_on, to restore bkpinfo->verify_data's
    153   value if altered by verify_cd_image()
    154 
    155 08/01 - 08/31
    156 - use data structure to store the fname, checksum, mods & perms of each bigfile
    157   ... biggiestruct :)
    158 - bigger tmp[]'s in a few places
    159 - cleaned up the (user-friendly) counting of biggiefiles a bit
    160 - if media_size[N]<=0 then catch it & abort, unless it's tape,
    161   in which case, allow it
    162 - cleaned up a lot of log_it() calls
    163 - fixed NULL filename-related bug in can_we_fit_these_files_on_media()
    164 - deleted can_we_fit.....() subroutine because it was causing problems
    165   --- moved its code into the one subroutine which called it
    166 - created [08/01/2002]
    1675*/
    1686
     
    352190int
    353191archive_this_fileset_with_star(struct s_bkpinfo *bkpinfo, char *filelist,
    354                            char *fname, int setno)
     192                               char *fname, int setno)
    355193{
    356194    int retval = 0;
     
    396234        asprintf(&tmp, "%s", last_line_of_file(MONDO_LOGFILE));
    397235        log_msg(1, "res=%d; tmp='%s'", res, tmp);
    398         paranoid_free(tmp);
    399236        if (bkpinfo->use_star && (res == 254 || res == 65024)
    400237            && strstr(tmp, "star: Processed all possible files")
     
    403240            res = 0;
    404241        }
     242        paranoid_free(tmp);
    405243        if (res) {
    406244            log_OS_error(command);
     
    417255        }
    418256    }
     257    paranoid_free(command);
     258
    419259    retval += res;
    420260    if (retval) {
     
    425265    }
    426266
    427     paranoid_free(command);
    428     paranoid_free(tmp);
    429267    return (retval);
    430268}
     
    475313    if (!does_file_exist(filelist)) {
    476314        asprintf(&tmp,
    477             "(archive_this_fileset) - filelist %s does not exist",
    478             filelist);
     315                "(archive_this_fileset) - filelist %s does not exist",
     316                filelist);
    479317        log_to_screen(tmp);
    480318        paranoid_free(tmp)
    481         return (1);
     319            return (1);
    482320    }
    483321    asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
     
    488326
    489327
    490     if (bkpinfo->compression_level > 0) {
     328        if (bkpinfo->compression_level > 0) {
    491329        asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home);
    492330        //       -b %ld, TAPE_BLOCK_SIZE
     
    496334            asprintf(&tmp1, "%s -E %s", zipparams, tmp);
    497335            paranoid_free(zipparams)
    498             zipparams = tmp1;
     336                zipparams = tmp1;
    499337        } else {
     338            asprintf(&zipparams, "%s", "");
    500339            log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
    501340        }
     
    541380        }
    542381    }
     382    paranoid_free(command);
     383
    543384    retval += res;
    544385    if (retval) {
     
    564405        }
    565406    }
    566     paranoid_free(command);
    567407    return (retval);
    568408}
    569 
    570 
    571 
    572 
    573409
    574410
     
    617453        { fatal_error("Failed to count filelist.full"); }
    618454*/
    619     asprintf(&tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
     455    asprintf(&tmp, "gzip -9 %s/archives/filelist.full",
     456             bkpinfo->scratchdir);
    620457    if (run_program_and_log_output(tmp, 2)) {
    621458        fatal_error("Failed to gzip filelist.full");
     
    623460    paranoid_free(tmp);
    624461    asprintf(&tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir,
    625             bkpinfo->tmpdir);
     462             bkpinfo->tmpdir);
    626463    if (run_program_and_log_output(tmp, 2)) {
    627464        fatal_error("Failed to copy to tmpdir");
     
    659496    return (retval);
    660497}
    661 
    662 
    663498
    664499
     
    724559
    725560    asprintf(&tmp,
    726             "echo \"%s\" | tr -s ' ' '\n' | grep -x \"/dev/.*\" | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
    727             bkpinfo->exclude_paths);
    728     asprintf(&devs_to_exclude, call_program_and_get_last_line_of_output(tmp));
     561             "echo \"%s\" | tr -s ' ' '\n' | grep -x \"/dev/.*\" | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
     562             bkpinfo->exclude_paths);
     563    asprintf(&devs_to_exclude,
     564             call_program_and_get_last_line_of_output(tmp));
    729565    paranoid_free(tmp);
    730566    asprintf(&tmp, "devs_to_exclude = '%s'", devs_to_exclude);
     
    732568    paranoid_free(tmp);
    733569    mvaddstr_and_log_it(g_currentY, 0,
    734                 "Calling MINDI to create boot+data disks");
     570                        "Calling MINDI to create boot+data disks");
    735571    asprintf(&tmp, "%s/filelist.full", bkpinfo->tmpdir);
    736572    if (!does_file_exist(tmp)) {
     
    777613        asprintf(&cd_recovery_sz, "no");
    778614    }
    779     /* BCO: shared between LILO/ELILO */
     615    /* Field shared between LILO/ELILO */
    780616    if (bkpinfo->make_cd_use_lilo) {
    781617        asprintf(&use_lilo_sz, "yes");
     
    790626#ifdef __FreeBSD__
    791627        asprintf(&bootdev, call_program_and_get_last_line_of_output
    792               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     628                ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    793629        if (!bootdev[0]) {
    794630            paranoid_free(bootdev);
    795631            asprintf(&bootdev, call_program_and_get_last_line_of_output
    796                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     632                    ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    797633        }
    798634#else
    799635        asprintf(&bootdev, call_program_and_get_last_line_of_output
    800               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     636                ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    801637        if (strstr(bootdev, "/dev/cciss/")) {
    802638            paranoid_free(bootdev);
    803639            asprintf(&bootdev, call_program_and_get_last_line_of_output
    804                   ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
     640                    ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    805641        }
    806642        if (!bootdev[0]) {
    807643            paranoid_free(bootdev);
    808644            asprintf(&bootdev, call_program_and_get_last_line_of_output
    809                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     645                    ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    810646            if (strstr(bootdev, "/dev/cciss/")) {
    811647                paranoid_free(bootdev);
    812648                asprintf(&bootdev, call_program_and_get_last_line_of_output
    813                       ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
     649                        ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    814650            }
    815651        }
     
    821657        if (bkpinfo->boot_loader != '\0') {
    822658            asprintf(&tmp, "User specified boot loader. It is '%c'.",
    823                     bkpinfo->boot_loader);
     659                     bkpinfo->boot_loader);
    824660            log_msg(2, tmp);
    825661            paranoid_free(tmp);
     
    829665        if (bkpinfo->boot_device[0] != '\0') {
    830666            asprintf(&tmp, "User specified boot device. It is '%s'.",
    831                     bkpinfo->boot_device);
     667                     bkpinfo->boot_device);
    832668            log_msg(2, tmp);
    833669            paranoid_free(tmp);
     
    849685    {
    850686        fatal_error
    851             ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda. Type 'man mondoarchive' to read the manual.");
     687            ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda.\nType 'man mondoarchive' to read the manual.");
    852688    }
    853689    if (bkpinfo->boot_loader == 'L') {
     
    855691        if (!does_file_exist("/etc/lilo.conf")) {
    856692            fatal_error
    857                 ("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?");
     693                ("The de facto standard location for your boot loader's config file is /etc/lilo.conf.\nBut I cannot find it there. What is wrong with your Linux distribution?");
    858694        }
    859695    } else if (bkpinfo->boot_loader == 'G') {
     
    872708        if (!does_file_exist("/etc/grub.conf")) {
    873709            fatal_error
    874                 ("The de facto standard location for your boot loader's config file is /etc/grub.conf but I cannot find it there. What is wrong with your Linux distribution? Try 'ln -s /boot/grub/menu.lst /etc/grub.conf'...");
     710                ("The de facto standard location for your boot loader's config file is /etc/grub.conf.\nBut I cannot find it there. What is wrong with your Linux distribution?\nTry 'ln -s /boot/grub/menu.lst /etc/grub.conf'...");
    875711        }
    876712    } else if (bkpinfo->boot_loader == 'E') {
    877713        asprintf(&bootldr_str, "ELILO");
    878         /* BCO: fix it for SuSE, Debian, Mandrake, ... */
     714        /* BERLIOS: fix it for SuSE, Debian, Mandrake, ... */
    879715        if (!does_file_exist("/etc/elilo.conf")
    880716            && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) {
     
    885721        if (!does_file_exist("/etc/elilo.conf")) {
    886722            fatal_error
    887                 ("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'");
     723                ("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf\nBut I cannot find it there. What is wrong with your Linux distribution?\nTry finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'");
    888724        }
    889725    } else if (bkpinfo->boot_loader == 'R') {
     
    903739    }
    904740    asprintf(&tmp, "Your boot loader is %s and it boots from %s",
    905             bootldr_str, bkpinfo->boot_device);
     741             bootldr_str, bkpinfo->boot_device);
    906742    log_to_screen(tmp);
    907743    paranoid_free(tmp);
     
    982818
    983819    asprintf(&tmp, "BTW, I'm telling Mindi your kernel is '%s'",
    984             bkpinfo->kernel_path);
     820             bkpinfo->kernel_path);
    985821    log_to_screen(tmp);
    986822    paranoid_free(tmp);
    987823
    988824    log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
    989    
     825
    990826    // Watch it! This next line adds a parameter...
    991827    if (bkpinfo->nonbootable_backup) {
     
    9998356=\"%s\" 7=%ld 8=\"%s\" 9=\"%s\" 10=\"%s\" \
    100083611=\"%s\" 12=%s 13=%ld 14=\"%s\" 15=\"%s\" 16=\"%s\" 17=\"%s\" 18=%ld 19=%d",*/
    1001             "mindi --custom %s %s/images \"%s\" \"%s\" \
     837             "mindi --custom %s %s/images \"%s\" \"%s\" \
    1002838\"%s\" %ld \"%s\" \"%s\" \"%s\" \
    1003 \"%s\" %s %ld \"%s\" \"%s\" \"%s\" \"%s\" %ld %d %s",
    1004             bkpinfo->tmpdir,    // parameter #2
    1005             bkpinfo->scratchdir,    // parameter #3
    1006             bkpinfo->kernel_path,   // parameter #4
    1007             tape_device,        // parameter #5
    1008             tape_size_sz,       // parameter #6
    1009             lines_in_filelist,  // parameter #7 (INT)
    1010             use_lzo_sz,         // parameter #8
    1011             cd_recovery_sz,     // parameter #9
    1012             bkpinfo->image_devs,    // parameter #10
    1013             broken_bios_sz,     // parameter #11
    1014             last_filelist_number,   // parameter #12 (STRING)
    1015             estimated_total_noof_slices,    // parameter #13 (INT)
    1016             devs_to_exclude,    // parameter #14
    1017             use_comp_sz,        // parameter #15
    1018             use_lilo_sz,        // parameter #16
    1019             use_star_sz,        // parameter #17
    1020             bkpinfo->internal_tape_block_size,  // parameter #18 (LONG)
    1021             bkpinfo->differential,  // parameter #19 (INT)
    1022             tmp);   
     839\"%s\" %s %ld \"%s\" \"%s\" \"%s\" \"%s\" %ld %d %s", bkpinfo->tmpdir,  // parameter #2
     840             bkpinfo->scratchdir,   // parameter #3
     841             bkpinfo->kernel_path,  // parameter #4
     842             tape_device,       // parameter #5
     843             tape_size_sz,      // parameter #6
     844             lines_in_filelist, // parameter #7 (INT)
     845             use_lzo_sz,        // parameter #8
     846             cd_recovery_sz,    // parameter #9
     847             bkpinfo->image_devs,   // parameter #10
     848             broken_bios_sz,    // parameter #11
     849             last_filelist_number,  // parameter #12 (STRING)
     850             estimated_total_noof_slices,   // parameter #13 (INT)
     851             devs_to_exclude,   // parameter #14
     852             use_comp_sz,       // parameter #15
     853             use_lilo_sz,       // parameter #16
     854             use_star_sz,       // parameter #17
     855             bkpinfo->internal_tape_block_size, // parameter #18 (LONG)
     856             bkpinfo->differential, // parameter #19 (INT)
     857             tmp);
    1023858    paranoid_free(tmp);
    1024859    paranoid_free(tape_size_sz);
     
    1038873
    1039874    res = run_program_and_log_to_screen(command,
    1040                       "Generating boot+data disks");
     875                                        "Generating boot+data disks");
    1041876    paranoid_free(command);
    1042877
     
    1052887
    1053888        asprintf(&command,
    1054             "cp -f %s/images/mindi.iso /root/images/mindi/mondorescue.iso",
    1055                 bkpinfo->scratchdir);
     889                 "cp -f %s/images/mindi.iso /root/images/mindi/mondorescue.iso",
     890                 bkpinfo->scratchdir);
    1056891        log_msg(2, command);
    1057892        run_program_and_log_output(command, FALSE);
     
    1060895        if (bkpinfo->nonbootable_backup) {
    1061896            asprintf(&command, "cp -f %s/all.tar.gz %s/images",
    1062                     bkpinfo->tmpdir, bkpinfo->scratchdir);
     897                     bkpinfo->tmpdir, bkpinfo->scratchdir);
    1063898            if (system(command)) {
    1064899                fatal_error("Unable to create temporary duff tarball");
    1065             paranoid_free(command);
     900                paranoid_free(command);
    1066901            }
    1067902        }
    1068903        asprintf(&command, "cp -f %s/mindi-*oot*.img %s/images",
    1069                 bkpinfo->tmpdir, bkpinfo->scratchdir);
     904                 bkpinfo->tmpdir, bkpinfo->scratchdir);
    1070905        log_msg(2, command);
    1071906        run_program_and_log_output(command, FALSE);
    1072907        paranoid_free(command);
    1073908
    1074         asprintf(&tmp, "cp -f %s/images/all.tar.gz %s", 
    1075                 bkpinfo->scratchdir, bkpinfo->tmpdir);
     909        asprintf(&tmp, "cp -f %s/images/all.tar.gz %s",
     910                 bkpinfo->scratchdir, bkpinfo->tmpdir);
    1076911        if (system(tmp)) {
    1077912            fatal_error("Cannot find all.tar.gz in tmpdir");
     
    1087922        log_to_screen("Mindi failed to create your boot+data disks.");
    1088923        asprintf(&command, "cat %s | grep \"Fatal error\"",
    1089                 "/var/log/mindi.log");
     924                 "/var/log/mindi.log");
    1090925        asprintf(&tmp, call_program_and_get_last_line_of_output(command));
    1091926        paranoid_free(command);
     
    1097932    return (res);
    1098933}
    1099 
    1100934
    1101935
     
    1160994
    1161995    asprintf(&archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
    1162             bkpinfo->tmpdir, 0L);
     996             bkpinfo->tmpdir, 0L);
    1163997    archiving_set_no = 0;
    1164998    while (does_file_exist(archiving_filelist_fname)) {
     
    11851019        /* backup this set of files */
    11861020        asprintf(&archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
    1187                 bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
     1021                 bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
    11881022        asprintf(&archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
    1189                 bkpinfo->tmpdir, archiving_set_no);
     1023                 bkpinfo->tmpdir, archiving_set_no);
    11901024        if (!does_file_exist(archiving_filelist_fname)) {
    11911025            log_msg(3,
    1192                 "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.",
    1193                 FORTY_SPACES, getpid(), this_thread_no,
    1194                 archiving_set_no);
     1026                    "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.",
     1027                    FORTY_SPACES, getpid(), this_thread_no,
     1028                    archiving_set_no);
    11951029            paranoid_free(archiving_filelist_fname);
    11961030            paranoid_free(archiving_afioball_fname);
     
    11991033
    12001034        asprintf(&tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1201                 archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
     1035                 archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
    12021036        if (does_file_exist(tmp)) {
    1203             log_msg(4, "%s[%d:%d] - waiting for storer", 
     1037            log_msg(4, "%s[%d:%d] - waiting for storer",
    12041038                    FORTY_SPACES, getpid(), this_thread_no);
    12051039            while (does_file_exist(tmp)) {
     
    12131047                this_thread_no, archiving_set_no);
    12141048        asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
    1215                 bkpinfo->tmpdir, archiving_set_no);
     1049                 bkpinfo->tmpdir, archiving_set_no);
    12161050        asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
    1217                 bkpinfo->tmpdir, archiving_set_no);
     1051                 bkpinfo->tmpdir, archiving_set_no);
    12181052        get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
    12191053        paranoid_free(curr_xattr_list_fname);
     
    12241058                this_thread_no, archiving_set_no);
    12251059        res = archive_this_fileset(bkpinfo, archiving_filelist_fname,
    1226                         archiving_afioball_fname,
    1227                         archiving_set_no);
     1060                                  archiving_afioball_fname,
     1061                                  archiving_set_no);
    12281062        paranoid_free(archiving_afioball_fname);
    12291063        paranoid_free(archiving_filelist_fname);
     
    12321066        if (res) {
    12331067            asprintf(&tmp,
    1234                     "Errors occurred while archiving set %ld. Please review logs.",
    1235                     archiving_set_no);
     1068                     "Errors occurred while archiving set %ld. Please review logs.",
     1069                     archiving_set_no);
    12361070            log_to_screen(tmp);
    12371071            paranoid_free(tmp);
     
    12681102    pthread_exit(NULL);
    12691103}
    1270 
    1271 
    1272 
    12731104
    12741105
     
    12961127
    12971128    log_msg(1, "Closing tape/CD ... ");
    1298     if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
     1129    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    12991130        /* write tape/cdstream */
    1300     {
    13011131        closeout_tape(bkpinfo);
    1302     } else
     1132    } else {
    13031133        /* write final ISO */
    1304     {
    13051134        res = write_final_iso_if_necessary(bkpinfo);
    13061135        retval += res;
     
    13591188hexdump | tr -s ' ' '0' | head -n1"));
    13601189    strip_spaces(g_serial_string);
    1361     asprintf(&tmp, "%s...word.",g_serial_string);
     1190    asprintf(&tmp, "%s...word.", g_serial_string);
    13621191    paranoid_free(g_serial_string);
    13631192    g_serial_string = tmp;
     
    13891218
    13901219    asprintf(&command, "rm -f %s/%s-[1-9]*.iso", bkpinfo->prefix,
    1391             bkpinfo->isodir);
     1220             bkpinfo->isodir);
    13921221    paranoid_system(command);
    13931222    paranoid_free(command);
     
    13961225    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    13971226        write_header_block_to_stream(0, "start-of-tape",
    1398                         BLK_START_OF_TAPE);
     1227                                    BLK_START_OF_TAPE);
    13991228        write_header_block_to_stream(0, "start-of-backup",
    1400                         BLK_START_OF_BACKUP);
     1229                                    BLK_START_OF_BACKUP);
    14011230    }
    14021231    return (retval);
     
    14341263    assert_string_is_neither_NULL_nor_zerolength(title);
    14351264
    1436     malloc_string(command);
    14371265#ifdef __FreeBSD__
    14381266/* Ugh. FreeBSD fdformat prints out this pretty progress indicator that's
     
    14501278    }
    14511279/* if not Debian then go ahead & use fdformat */
    1452     asprintf(&tempfile,"%s",
    1453           call_program_and_get_last_line_of_output
    1454           ("mktemp -q /tmp/mondo.XXXXXXXX"));
    1455     asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    1456             tempfile);
     1280    asprintf(&tempfile, "%s",
     1281            call_program_and_get_last_line_of_output
     1282            ("mktemp -q /tmp/mondo.XXXXXXXX"));
     1283    asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile,
     1284             tempfile, tempfile);
    14571285    log_msg(3, command);
    14581286    open_evalcall_form(title);
     
    14661294        maxtracks = 80;
    14671295    }
     1296    paranoid_free(command);
     1297
    14681298    for (sleep(1); does_file_exist(tempfile); sleep(1)) {
    14691299        trackno = get_trackno_from_logfile(tempfile);
     
    14871317    }
    14881318    unlink(tempfile);
    1489     paranoid_free(command);
    14901319    paranoid_free(tempfile);
    14911320    return (res);
    14921321}
     1322
    14931323
    14941324/**
     
    15341364    return (res);
    15351365}
     1366
    15361367
    15371368/**
     
    16321463    log_msg(5, "Go, Shorty. It's your birthday.");
    16331464    open_progress_form("Backing up filesystem",
    1634                "I am backing up your live filesystem now.",
    1635                "Please wait. This may take a couple of hours.",
    1636                "Working...",
    1637                get_last_filelist_number(bkpinfo) + 1);
     1465                       "I am backing up your live filesystem now.",
     1466                       "Please wait. This may take a couple of hours.",
     1467                       "Working...",
     1468                       get_last_filelist_number(bkpinfo) + 1);
    16381469
    16391470    log_msg(5, "We're gonna party like it's your birthday.");
     
    16541485        if ((res =
    16551486             pthread_create(&archival_thread[noof_threads], NULL,
    1656                     create_afio_files_in_background,
    1657                     (void *) transfer_block))) {
     1487                            create_afio_files_in_background,
     1488                            (void *) transfer_block))) {
    16581489            fatal_error("Unable to create an archival thread");
    16591490        }
    16601491    }
     1492    paranoid_free(transfer_block);
    16611493
    16621494    log_msg(8, "About to enter while() loop");
     
    16681500            && *p_last_set_archived == storing_set_no - 1) {
    16691501            log_msg(2,
    1670                 "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)",
    1671                 *p_last_set_archived, storing_set_no);
     1502                    "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)",
     1503                    *p_last_set_archived, storing_set_no);
    16721504            done_storing = TRUE;
    1673         } else if (!get_bit_N_of_array(p_list_of_fileset_flags, storing_set_no)) {
     1505        } else
     1506            if (!get_bit_N_of_array
     1507                (p_list_of_fileset_flags, storing_set_no)) {
    16741508            misc_counter_that_is_not_important =
    16751509                (misc_counter_that_is_not_important + 1) % 5;
     
    16771511            /* maybe : */
    16781512            asprintf(&media_usage_comment, "%s",
    1679                   percent_media_full_comment(bkpinfo));
     1513                    percent_media_full_comment(bkpinfo));
    16801514            if (!misc_counter_that_is_not_important) {
    16811515                update_progress_form(media_usage_comment);
     
    16861520            // store set N
    16871521            asprintf(&storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
    1688                     bkpinfo->tmpdir, storing_set_no);
     1522                     bkpinfo->tmpdir, storing_set_no);
    16891523            asprintf(&storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
    1690                     bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
     1524                     bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
    16911525            asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
    1692                     bkpinfo->tmpdir, storing_set_no);
     1526                     bkpinfo->tmpdir, storing_set_no);
    16931527            asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
    1694                     bkpinfo->tmpdir, storing_set_no);
     1528                     bkpinfo->tmpdir, storing_set_no);
    16951529
    16961530            log_msg(2, "Storing set %d", storing_set_no);
     
    17031537            }
    17041538            asprintf(&media_usage_comment, "%s",
    1705                   percent_media_full_comment(bkpinfo));
     1539                    percent_media_full_comment(bkpinfo));
    17061540            /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
    17071541            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    17081542                register_in_tape_catalog(fileset, storing_set_no, -1,
    1709                             storing_afioball_fname);
     1543                                        storing_afioball_fname);
    17101544                maintain_collection_of_recent_archives(bkpinfo->tmpdir,
    1711                                        storing_afioball_fname);
     1545                                                       storing_afioball_fname);
    17121546                iamhere("Writing EXAT files");
    1713                 res +=
    1714                     write_EXAT_files_to_tape(bkpinfo,
    1715                                  curr_xattr_list_fname,
    1716                                  curr_acl_list_fname);
     1547                res += write_EXAT_files_to_tape(bkpinfo,
     1548                                                curr_xattr_list_fname,
     1549                                                curr_acl_list_fname);
    17171550                // archives themselves
    17181551                res +=
    17191552                    move_files_to_stream(bkpinfo, storing_afioball_fname,
    1720                                 NULL);
     1553                                        NULL);
    17211554            } else {
    1722                 res =
    1723                     move_files_to_cd(bkpinfo, storing_filelist_fname,
    1724                              curr_xattr_list_fname,
    1725                              curr_acl_list_fname,
    1726                              storing_afioball_fname, NULL);
     1555                res = move_files_to_cd(bkpinfo, storing_filelist_fname,
     1556                                       curr_xattr_list_fname,
     1557                                       curr_acl_list_fname,
     1558                                       storing_afioball_fname, NULL);
    17271559            }
    17281560            paranoid_free(storing_filelist_fname);
     
    17371569            if (res) {
    17381570                asprintf(&tmp,
    1739                         "Failed to add archive %ld's files to CD dir\n",
    1740                         storing_set_no);
     1571                         "Failed to add archive %ld's files to CD dir\n",
     1572                         storing_set_no);
    17411573                log_to_screen(tmp);
    17421574                paranoid_free(tmp);
    1743                 fatal_error("Is your hard disk full? If not, please send the author the logfile.");
     1575                fatal_error
     1576                    ("Is your hard disk full? If not, please send the author the logfile.");
    17441577            }
    17451578            storing_set_no++;
     
    17571590    log_msg(2, "Done.");
    17581591    if (retval) {
    1759         asprintf(&tmp, "Your regular files have been archived (with errors).");
     1592        asprintf(&tmp,
     1593                 "Your regular files have been archived (with errors).");
    17601594    } else {
    1761         asprintf(&tmp, "Your regular files have been archived successfully");
     1595        asprintf(&tmp,
     1596                 "Your regular files have been archived successfully");
    17621597    }
    17631598    log_to_screen(tmp);
    17641599    paranoid_free(tmp);
    1765     paranoid_free(transfer_block);
    17661600    paranoid_free(result_str);
    17671601    return (retval);
     
    17791613    close_evalcall_form();
    17801614}
    1781 
    1782 
    17831615
    17841616
     
    18511683    if (bkpinfo->call_before_iso[0] != '\0') {
    18521684        asprintf(&message_to_screen, "Running pre-ISO call for CD#%d",
    1853                 g_current_media_number);
     1685                 g_current_media_number);
    18541686        res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_before_iso,
    1855                           destfile, g_current_media_number,
    1856                           MONDO_LOGFILE, message_to_screen);
     1687                                    destfile, g_current_media_number,
     1688                                    MONDO_LOGFILE, message_to_screen);
    18571689        if (res) {
    18581690            log_to_screen("%s...failed", message_to_screen);
     
    18681700        asprintf(&tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    18691701        asprintf(&message_to_screen, "Making an ISO (%s #%d)",
    1870                 media_descriptor_string(bkpinfo->backup_media_type),
    1871                 g_current_media_number);
     1702                 media_descriptor_string(bkpinfo->backup_media_type),
     1703                 g_current_media_number);
    18721704
    18731705        /* if g_current_media_number >= 2 then pause & ask */
    1874         pause_and_ask_for_cdr(2, &cd_is_mountable); 
     1706        pause_and_ask_for_cdr(2, &cd_is_mountable);
    18751707        if (retval) {
    18761708            log_to_screen
    18771709                ("Serious error(s) occurred already. I shan't try to write to media.");
    18781710        } else {
    1879             res =
    1880                 eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
    1881                               bkpinfo->scratchdir,
    1882                               g_current_media_number,
    1883                               MONDO_LOGFILE, message_to_screen);
     1711            res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
     1712                                        bkpinfo->scratchdir,
     1713                                        g_current_media_number,
     1714                                        MONDO_LOGFILE, message_to_screen);
    18841715            if (res) {
    18851716                log_to_screen("%s...failed to write", message_to_screen);
     
    18961727#ifdef DVDRWFORMAT
    18971728            asprintf(&tmp,
    1898                     "cat %s | tail -n8 | grep \"blank=full.*dvd-compat.*DAO\"",
    1899                     MONDO_LOGFILE);
     1729                     "cat %s | tail -n8 | grep \"blank=full.*dvd-compat.*DAO\"",
     1730                     MONDO_LOGFILE);
    19001731            if (g_backup_media_type == dvd
    19011732                && (res || !run_program_and_log_output(tmp, 1))) {
     
    19131744                }
    19141745                pause_for_N_seconds(5, "Letting DVD drive settle");
    1915                 asprintf(&sz_blank_disk, "dvd+rw-format %s", bkpinfo->media_device);
     1746                asprintf(&sz_blank_disk, "dvd+rw-format %s",
     1747                         bkpinfo->media_device);
    19161748                log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
    1917                 res =
    1918                     run_external_binary_with_percentage_indicator_NEW
     1749                res = run_external_binary_with_percentage_indicator_NEW
    19191750                    ("Blanking DVD disk", sz_blank_disk);
    19201751                if (res) {
     
    19231754                    pause_for_N_seconds(5,
    19241755                                        "Letting DVD drive settle... and trying again.");
    1925                     res =
    1926                         run_external_binary_with_percentage_indicator_NEW
     1756                    res = run_external_binary_with_percentage_indicator_NEW
    19271757                        ("Blanking DVD disk", sz_blank_disk);
    19281758                    if (res) {
     
    19681798    } else {
    19691799        asprintf(&message_to_screen, "Running mkisofs to make %s #%d",
    1970                 media_descriptor_string(bkpinfo->backup_media_type),
    1971                 g_current_media_number);
     1800                 media_descriptor_string(bkpinfo->backup_media_type),
     1801                 g_current_media_number);
    19721802        log_msg(1, message_to_screen);
    19731803        asprintf(&result_sz, "Call to mkisofs to make ISO (%s #%d) ",
    1974                 media_descriptor_string(bkpinfo->backup_media_type),
    1975                 g_current_media_number);
     1804                 media_descriptor_string(bkpinfo->backup_media_type),
     1805                 g_current_media_number);
    19761806        if (bkpinfo->nonbootable_backup) {
    19771807            log_msg(1, "Making nonbootable backup");
    19781808// FIXME --- change mkisofs string to MONDO_MKISOFS_NONBOOTABLE and add ' .' at end
    1979             res =
    1980                 eval_call_to_make_ISO(bkpinfo,
    1981                                       "mkisofs -o _ISO_ -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1982                                       destfile, g_current_media_number,
    1983                                       MONDO_LOGFILE, message_to_screen);
     1809            res = eval_call_to_make_ISO(bkpinfo,
     1810                                        "mkisofs -o _ISO_ -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     1811                                        destfile, g_current_media_number,
     1812                                        MONDO_LOGFILE, message_to_screen);
    19841813        } else {
    19851814            log_msg(1, "Making bootable backup");
     
    20101839// and add ' .' at end
    20111840                log_msg(1, "Non-ia64 --> lilo");
    2012                 res =
    2013                     eval_call_to_make_ISO(bkpinfo,
    2014                                           "mkisofs -b images/mindi-bootroot.2880.img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    2015                                           destfile, g_current_media_number,
    2016                                           MONDO_LOGFILE,
    2017                                           message_to_screen);
     1841                res = eval_call_to_make_ISO(bkpinfo,
     1842                                            "mkisofs -b images/mindi-bootroot.2880.img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     1843                                            destfile,
     1844                                            g_current_media_number,
     1845                                            MONDO_LOGFILE,
     1846                                            message_to_screen);
    20181847#endif
    20191848            } else {
     
    20211850                log_msg(1, "Isolinux");
    20221851                res = eval_call_to_make_ISO(bkpinfo,
    2023                                           "mkisofs -no-emul-boot -b isolinux.bin -boot-load-size 4 -boot-info-table -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    2024                                           destfile, g_current_media_number,
    2025                                           MONDO_LOGFILE,
    2026                                           message_to_screen);
     1852                                            "mkisofs -no-emul-boot -b isolinux.bin -boot-load-size 4 -boot-info-table -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     1853                                            destfile,
     1854                                            g_current_media_number,
     1855                                            MONDO_LOGFILE,
     1856                                            message_to_screen);
    20271857            }
    20281858        }
     
    20521882        log_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
    20531883        asprintf(&message_to_screen, "Burning %s #%d",
    2054                 media_descriptor_string(bkpinfo->backup_media_type),
    2055                 g_current_media_number);
     1884                 media_descriptor_string(bkpinfo->backup_media_type),
     1885                 g_current_media_number);
    20561886        pause_and_ask_for_cdr(2, &cd_is_mountable);
    20571887        res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_burn_iso,
    2058                                   destfile, g_current_media_number,
    2059                                   MONDO_LOGFILE, message_to_screen);
     1888                                    destfile, g_current_media_number,
     1889                                    MONDO_LOGFILE, message_to_screen);
    20601890        if (res) {
    20611891            log_to_screen("%s...failed", message_to_screen);
     
    20691899    if (bkpinfo->call_after_iso[0] != '\0') {
    20701900        asprintf(&message_to_screen, "Running post-ISO call (%s #%d)",
    2071                 media_descriptor_string(bkpinfo->backup_media_type),
    2072                 g_current_media_number);
     1901                 media_descriptor_string(bkpinfo->backup_media_type),
     1902                 g_current_media_number);
    20731903        res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_after_iso,
    2074                                   destfile, g_current_media_number,
    2075                                   MONDO_LOGFILE, message_to_screen);
     1904                                    destfile, g_current_media_number,
     1905                                    MONDO_LOGFILE, message_to_screen);
    20761906        if (res) {
    20771907            log_to_screen("%s...failed", message_to_screen);
     
    20971927    char *command;
    20981928    asprintf(&command,
    2099             "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
    2100             bigfile_fname);
     1929             "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
     1930             bigfile_fname);
    21011931    log_msg(1, "command = '%s'", command);
    2102     asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     1932    asprintf(&tmp, "%s",
     1933             call_program_and_get_last_line_of_output(command));
    21031934    log_msg(1, "--> tmp = '%s'", tmp);
    21041935    paranoid_free(command);
     
    21391970    /*@ buffers ******************************************** */
    21401971    char *tmp;
    2141     char *bigfile_fname;
     1972    char *bigfile_fname = NULL;
    21421973    char *sz_devfile;
    21431974    char *partimagehack_fifo = NULL;
     
    21501981    int retval = 0;
    21511982    int res = 0;
     1983    int n = 0;
    21521984    pid_t pid;
    21531985    FILE *ftmp = NULL;
     
    21601992    assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
    21611993
    2162     malloc_string(bigfile_fname);
    21631994    estimated_total_noof_slices =
    21641995        size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
     
    21842015        return (1);
    21852016    }
    2186     for (fgets(bigfile_fname, MAX_STR_LEN, fin); !feof(fin);
    2187          fgets(bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++) {
     2017    for (getline(&bigfile_fname, (size_t) & n, fin); !feof(fin);
     2018         getline(&bigfile_fname, (size_t) & n, fin),
     2019         biggie_file_number++) {
    21882020        use_partimagehack = FALSE;
    21892021        if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
     
    21972029            paranoid_fclose(ftmp);
    21982030            asprintf(&tmp, "bigfile %s was deleted - creating a dummy",
    2199                     bigfile_fname);
     2031                     bigfile_fname);
    22002032            delete_when_done = TRUE;
    22012033        } else {
     
    22102042                        bigfile_fname);
    22112043                asprintf(&sz_devfile, "/tmp/%d.%d.000",
    2212                         (int) (random() % 32768),
    2213                         (int) (random() % 32768));
     2044                         (int) (random() % 32768),
     2045                         (int) (random() % 32768));
    22142046                mkfifo(sz_devfile, 0x770);
    22152047                partimagehack_fifo = sz_devfile;
     
    22292061                            (long int) (pid));
    22302062
    2231                 paranoid_free(sz_devfile);
     2063                    paranoid_free(sz_devfile);
    22322064                }
    22332065            }
     
    22482080            }
    22492081            res = slice_up_file_etc(bkpinfo, bigfile_fname,
    2250                                   partimagehack_fifo, biggie_file_number,
    2251                                   noof_biggie_files, use_partimagehack);
     2082                                    partimagehack_fifo, biggie_file_number,
     2083                                    noof_biggie_files, use_partimagehack);
    22522084            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    22532085                write_header_block_to_stream(0,
     
    22832115    }
    22842116    paranoid_free(tmp);
     2117    paranoid_free(bigfile_fname);
     2118    paranoid_fclose(fin);
     2119
    22852120    log_msg(1, "Finished backing up bigfiles");
    22862121    log_msg(1, "estimated slices = %ld; actual slices = %ld",
    22872122            estimated_total_noof_slices, g_current_progress);
    22882123    close_progress_form();
    2289     paranoid_fclose(fin);
    2290     paranoid_free(bigfile_fname);
    22912124    return (retval);
    22922125}
    2293 
    2294 
    22952126
    22962127
     
    23162147
    23172148    /* BERLIOS: Useless ?
    2318     asprintf(&tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
    2319     */
     2149       asprintf(&tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
     2150     */
    23202151
    23212152    log_to_screen("Archiving regular files");
     
    23282159
    23292160    asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
    2330             0L);
     2161             0L);
    23312162
    23322163    curr_set_no = 0;
     
    23342165        /* backup this set of files */
    23352166        asprintf(&curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
    2336                 bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
     2167                 bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
    23372168
    23382169        log_msg(1, "EXAT'g set %ld", curr_set_no);
    23392170        asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
    2340                 bkpinfo->tmpdir, curr_set_no);
     2171                 bkpinfo->tmpdir, curr_set_no);
    23412172        asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
    2342                 bkpinfo->tmpdir, curr_set_no);
     2173                 bkpinfo->tmpdir, curr_set_no);
    23432174        get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
    23442175        get_acl_list(curr_filelist_fname, curr_acl_list_fname);
     
    23462177        log_msg(1, "Archiving set %ld", curr_set_no);
    23472178        res = archive_this_fileset(bkpinfo, curr_filelist_fname,
    2348                                  curr_afioball_fname, curr_set_no);
     2179                                   curr_afioball_fname, curr_set_no);
    23492180        retval += res;
    23502181        if (res) {
    23512182            asprintf(&tmp,
    2352                     "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
    2353                     curr_set_no);
     2183                     "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
     2184                     curr_set_no);
    23542185            log_to_screen(tmp);
    23552186            paranoid_free(tmp);
    23562187        }
    23572188
    2358         asprintf(&media_usage_comment, "%s", percent_media_full_comment(bkpinfo));
     2189        asprintf(&media_usage_comment, "%s",
     2190                 percent_media_full_comment(bkpinfo));
    23592191
    23602192        /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
     
    23662198            iamhere("Writing EXAT files");
    23672199            res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname,
    2368                                          curr_acl_list_fname);
     2200                                            curr_acl_list_fname);
    23692201            // archives themselves
    23702202            res = move_files_to_stream(bkpinfo, curr_afioball_fname, NULL);
    23712203        } else {
    23722204            res = move_files_to_cd(bkpinfo, curr_filelist_fname,
    2373                                  curr_xattr_list_fname,
    2374                                  curr_acl_list_fname, curr_afioball_fname,
    2375                                  NULL);
     2205                                   curr_xattr_list_fname,
     2206                                   curr_acl_list_fname,
     2207                                   curr_afioball_fname, NULL);
    23762208        }
    23772209        retval += res;
     
    23822214        if (res) {
    23832215            asprintf(&tmp, "Failed to add archive %ld's files to CD dir\n",
    2384                     curr_set_no);
     2216                     curr_set_no);
    23852217            log_to_screen(tmp);
    23862218            paranoid_free(tmp);
     
    23982230    close_progress_form();
    23992231    if (retval) {
    2400         log_to_screen("Your regular files have been archived (with errors).");
     2232        log_to_screen
     2233            ("Your regular files have been archived (with errors).");
    24012234    } else {
    2402         log_to_screen("Your regular files have been archived successfully.");
    2403     }
    2404     return(retval);
     2235        log_to_screen
     2236            ("Your regular files have been archived successfully.");
     2237    }
     2238    return (retval);
    24052239}
    24062240
     
    24802314    mvaddstr_and_log_it(g_currentY, 0,
    24812315                        "Archiving large files to media           ");
    2482     asprintf(&biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
     2316    asprintf(&biggielist, "%s/archives/biggielist.txt",
     2317             bkpinfo->scratchdir);
    24832318    asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    24842319    asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    24852320
    24862321    asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
    2487             biggielist);
     2322             biggielist);
    24882323    paranoid_system(command);
    24892324    paranoid_free(command);
     2325
    24902326    asprintf(&blah, "biggielist = %s", biggielist);
    24912327    log_msg(2, blah);
     
    24992335    get_acl_list(biggielist, acl_fname);
    25002336    asprintf(&command, "cp %s %s/archives/", xattr_fname,
    2501             bkpinfo->scratchdir);
     2337             bkpinfo->scratchdir);
    25022338    paranoid_system(command);
    25032339    paranoid_free(command);
    2504     asprintf(&command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
     2340
     2341    asprintf(&command, "cp %s %s/archives/", acl_fname,
     2342             bkpinfo->scratchdir);
    25052343    paranoid_system(command);
    25062344    paranoid_free(command);
     
    25142352    paranoid_free(xattr_fname);
    25152353    paranoid_free(acl_fname);
     2354
    25162355    res = make_slices_and_images(bkpinfo, biggielist);
    25172356    paranoid_free(biggielist);
     2357
    25182358    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    25192359        write_header_block_to_stream(0, "end-of-biggiefiles",
     
    25292369    return (retval);
    25302370}
    2531 
    25322371
    25332372
     
    25772416
    25782417    assert(bkpinfo != NULL);
    2579     tmp = malloc(1200);
    25802418    would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
    25812419    va_start(ap, files_to_add); // initialize the variable arguments
     
    26022440    if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number]) {
    26032441        /* FALSE because this is not the last CD we'll write */
    2604         res = write_iso_and_go_on(bkpinfo, FALSE); 
     2442        res = write_iso_and_go_on(bkpinfo, FALSE);
    26052443        retval += res;
    26062444        if (res) {
     
    26172455
    26182456        asprintf(&tmp, "mv -f %s %s/archives/", curr_file,
    2619                 bkpinfo->scratchdir);
     2457                 bkpinfo->scratchdir);
    26202458        res = run_program_and_log_output(tmp, 5);
    26212459        retval += res;
     
    26392477
    26402478/* @} - end of LLarchiveGroup */
    2641 
    2642 
    2643 
    2644 
    2645 
    2646 
    26472479
    26482480
     
    27162548        res += write_image_to_floppy(bootdisk_dev, tmp);
    27172549        paranoid_free(tmp);
     2550
    27182551        if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
    27192552            log_to_screen("Writing mfsroot floppy");
     
    27512584                format_disk(datadisk_dev);
    27522585            }
    2753             /*
    2754                asprintf(&tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
    2755                res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
    2756              */
    27572586            res += write_image_to_floppy(datadisk_dev, bootdisk_file);
    27582587            if (ask_me_OK_or_cancel("About to write root disk")) {
     
    28062635
    28072636
    2808 
    2809 
    28102637/**
    28112638 * Wrapper around @c offer_to_write_floppies().
     
    28392666            if (does_file_exist("/root/images/mindi/mondorescue.iso")) {
    28402667                popup_and_OK
    2841                     ("Boot+data floppy creation failed. However, FYI, you may burn /root/images/mindi/mondorescue.iso to a CD and boot from that instead if you wish.");
     2668                    ("Boot+data floppy creation failed.\nHowever, you may burn /root/images/mindi/mondorescue.iso to a CD\nand boot from that instead if you wish.");
    28422669                res++;
    28432670            }
     
    28532680    return (res);
    28542681}
    2855 
    2856 
    28572682
    28582683
     
    29432768
    29442769/* @} - end of LLarchiveGroup */
    2945 
    29462770
    29472771
     
    30002824
    30012825
    3002 
    30032826/**
    30042827 * Asks the user to put a CD-R(W) in the drive.
     
    30292852
    30302853    asprintf(&szmsg, "I am about to burn %s #%d",
    3031             media_descriptor_string(g_backup_media_type),
    3032             g_current_media_number);
     2854             media_descriptor_string(g_backup_media_type),
     2855             g_current_media_number);
    30332856    log_to_screen(szmsg);
    30342857    paranoid_free(szmsg);
     
    30382861    log_to_screen("Scanning CD-ROM drive...");
    30392862    asprintf(&mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int) random(),
    3040             (long int) random());
     2863             (long int) random());
    30412864    make_hole_for_dir(mtpt);
    30422865
     
    30562879        cd_number = -1;
    30572880        asprintf(&tmp, "mount %s %s", cdrom_dev, mtpt);
    3058         if ((attempt_to_mount_returned_this = run_program_and_log_output(tmp, 1))) {
     2881        if ((attempt_to_mount_returned_this =
     2882             run_program_and_log_output(tmp, 1))) {
    30592883            log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
    30602884            log_to_screen("If there's a CD/DVD in the drive, it's blank.");
     
    30712895               }
    30722896             */
    3073         } else if (!does_file_exist(szcdno) || !does_file_exist(szserfname)) {
    3074             log_to_screen("%s has data on it but it's probably not a Mondo CD.",
     2897        } else if (!does_file_exist(szcdno)
     2898                   || !does_file_exist(szserfname)) {
     2899            log_to_screen
     2900                ("%s has data on it but it's probably not a Mondo CD.",
    30752901                 media_descriptor_string(g_backup_media_type));
    30762902            asprintf(&our_serial_str, "%s", "");
     
    30812907            asprintf(&tmp1, "cat %s 2> /dev/null", szserfname);
    30822908            asprintf(&our_serial_str, "%s",
    3083                   call_program_and_get_last_line_of_output(tmp1));
     2909                    call_program_and_get_last_line_of_output(tmp1));
    30842910            paranoid_free(tmp1);
    30852911            // FIXME - should be able to use last_line_of_file(), surely?
     
    31352961        eject_device(cdrom_dev);
    31362962        asprintf(&tmp,
    3137                 "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
    3138                 media_descriptor_string(g_backup_media_type),
    3139                 g_current_media_number,
    3140                 media_descriptor_string(g_backup_media_type));
     2963                 "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
     2964                 media_descriptor_string(g_backup_media_type),
     2965                 g_current_media_number,
     2966                 media_descriptor_string(g_backup_media_type));
    31412967        popup_and_OK(tmp);
    31422968        paranoid_free(tmp);
     
    31652991
    31662992
    3167 
    31682993/**
    31692994 * Set the <tt>N</tt>th bit of @c array to @c true_or_false.
     
    31933018
    31943019/* @} - end of utilityGroup */
    3195 
    31963020
    31973021
     
    32513075    int retval = 0;
    32523076    int res = 0;
     3077    int n = 0;
    32533078
    32543079    /*@ structures ************************************************** */
     
    32583083    assert(bkpinfo != NULL);
    32593084    assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
    3260 
    3261     malloc_string(checksum_line);
    32623085
    32633086    biggiestruct.for_backward_compatibility = '\n';
     
    32793102    if (partimagehack_fifo) {
    32803103        file_to_openin = partimagehack_fifo;
    3281         strcpy(checksum_line, "IGNORE");
     3104        asprintf(&checksum_line, "IGNORE");
    32823105        log_msg(2,
    32833106                "Not calculating checksum for %s: it would take too long",
     
    32923115        }
    32933116        paranoid_free(command);
    3294         (void) fgets(checksum_line, MAX_STR_LEN, fin);
     3117        (void) getline(&checksum_line, (size_t) & n, fin);
    32953118        pclose(fin);
    32963119    }
     
    33073130    paranoid_free(checksum_line);
    33083131
    3309     asprintf(&tmp, "%s", slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
     3132    asprintf(&tmp, "%s",
     3133             slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
    33103134    fout = fopen(tmp, "w");
    33113135    paranoid_free(tmp);
     
    33193143        log_OS_error("Unable to openin biggie_filename");
    33203144        asprintf(&tmp, "Cannot archive bigfile '%s': not found",
    3321                 biggie_filename);
     3145                 biggie_filename);
    33223146        log_to_screen(tmp);
    33233147        paranoid_free(tmp);
     
    33283152    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    33293153        res = move_files_to_stream(bkpinfo,
    3330                                  slice_fname(biggie_file_number, 0,
    3331                                              bkpinfo->tmpdir, ""), NULL);
     3154                                   slice_fname(biggie_file_number, 0,
     3155                                               bkpinfo->tmpdir, ""), NULL);
    33323156    } else {
    33333157        res = move_files_to_cd(bkpinfo,
    3334                              slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""),
    3335                             NULL);
     3158                               slice_fname(biggie_file_number, 0,
     3159                                           bkpinfo->tmpdir, ""), NULL);
    33363160    }
    33373161    i = bkpinfo->optimal_set_size / 256;
    33383162    for (slice_num = 1; !finished; slice_num++) {
    33393163        asprintf(&curr_slice_fname_uncompressed, "%s",
    3340                slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, ""));
     3164                 slice_fname(biggie_file_number, slice_num,
     3165                             bkpinfo->tmpdir, ""));
    33413166        asprintf(&curr_slice_fname_compressed, "%s",
    3342                slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, suffix));
     3167                 slice_fname(biggie_file_number, slice_num,
     3168                             bkpinfo->tmpdir, suffix));
    33433169
    33443170        asprintf(&tmp, "%s", percent_media_full_comment(bkpinfo));
     
    33823208            if (should_I_compress_slices && bkpinfo->compression_level > 0) {
    33833209                asprintf(&command, "%s -%d %s", bkpinfo->zip_exe,
    3384                         bkpinfo->compression_level,
    3385                         curr_slice_fname_uncompressed);
     3210                         bkpinfo->compression_level,
     3211                         curr_slice_fname_uncompressed);
    33863212                log_msg(2, command);
    33873213                if ((res = system(command))) {
     
    33913217            } else {
    33923218                /* BERLIOS: Useless
    3393                 asprintf(&command, "mv %s %s 2>> %s",
    3394                         curr_slice_fname_uncompressed,
    3395                         curr_slice_fname_compressed, MONDO_LOGFILE);
    3396                 */
     3219                   asprintf(&command, "mv %s %s 2>> %s",
     3220                   curr_slice_fname_uncompressed,
     3221                   curr_slice_fname_compressed, MONDO_LOGFILE);
     3222                 */
    33973223                res = 0;        // don't do it :)
    33983224                //              did_I_compress_slice = FALSE;
     
    34113237            } else {
    34123238                asprintf(&tmp,
    3413                         "%s - Bigfile #%ld, slice #%ld compressed OK          ",
    3414                         biggie_filename, biggie_file_number + 1,
    3415                         slice_num);
     3239                         "%s - Bigfile #%ld, slice #%ld compressed OK          ",
     3240                         biggie_filename, biggie_file_number + 1,
     3241                         slice_num);
    34163242            }
    34173243#ifndef _XWIN
     
    34313257
    34323258            finished = TRUE;
    3433             asprintf(&file_to_archive, "%s", curr_slice_fname_uncompressed);
     3259            asprintf(&file_to_archive, "%s",
     3260                     curr_slice_fname_uncompressed);
    34343261            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    34353262                break;
     
    34503277        if (res) {
    34513278            asprintf(&tmp,
    3452                     "Failed to add slice %ld of bigfile %ld to scratchdir",
    3453                     slice_num, biggie_file_number + 1);
     3279                     "Failed to add slice %ld of bigfile %ld to scratchdir",
     3280                     slice_num, biggie_file_number + 1);
    34543281            log_to_screen(tmp);
    34553282            paranoid_free(tmp);
     
    34633290    paranoid_fclose(fin);
    34643291    if (retval) {
    3465         asprintf(&tmp, "Sliced bigfile #%ld...FAILED", biggie_file_number + 1);
     3292        asprintf(&tmp, "Sliced bigfile #%ld...FAILED",
     3293                 biggie_file_number + 1);
    34663294    } else {
    3467         asprintf(&tmp, "Sliced bigfile #%ld...OK!", biggie_file_number + 1);
     3295        asprintf(&tmp, "Sliced bigfile #%ld...OK!",
     3296                 biggie_file_number + 1);
    34683297    }
    34693298    log_msg(1, tmp);
     
    34983327    paranoid_free(tmp);
    34993328
    3500     asprintf(&tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", dir);
     3329    asprintf(&tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;",
     3330             dir);
    35013331    run_program_and_log_output(tmp, FALSE);
    35023332    paranoid_free(tmp);
     
    35523382    log_msg(2, tmp);
    35533383    /* BERLIOS: that function seems strange to me
    3554     center_string(tmp, 80);
    3555     */
     3384       center_string(tmp, 80);
     3385     */
    35563386#ifndef _XWIN
    35573387    if (!g_text_mode) {
     
    36243454    /* label the ISO with its number */
    36253455
    3626     asprintf(&cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
     3456    asprintf(&cdno_fname, "%s/archives/THIS-CD-NUMBER",
     3457             bkpinfo->scratchdir);
    36273458    fout = fopen(cdno_fname, "w");
    36283459    fprintf(fout, "%d", g_current_media_number);
     
    36313462
    36323463    asprintf(&tmp, "cp -f %s/autorun %s/", g_mondo_home,
    3633             bkpinfo->scratchdir);
     3464             bkpinfo->scratchdir);
    36343465    if (run_program_and_log_output(tmp, FALSE)) {
    36353466        log_msg(2, "Warning - unable to copy autorun to scratchdir");
     
    36383469
    36393470    /* last CD or not? Label accordingly */
    3640     asprintf(&lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
     3471    asprintf(&lastcd_fname, "%s/archives/NOT-THE-LAST",
     3472             bkpinfo->scratchdir);
    36413473    if (last_cd) {
    36423474        unlink(lastcd_fname);
     
    36543486        bkpinfo->media_size[g_current_media_number]) {
    36553487        asprintf(&tmp,
    3656                 "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
    3657                 (long) space_occupied_by_cd(bkpinfo->scratchdir),
    3658                 (long) bkpinfo->media_size[g_current_media_number]);
     3488                 "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
     3489                 (long) space_occupied_by_cd(bkpinfo->scratchdir),
     3490                 (long) bkpinfo->media_size[g_current_media_number]);
    36593491        log_to_screen(tmp);
    36603492        paranoid_free(tmp);
    36613493    }
    36623494    asprintf(&isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
    3663             bkpinfo->nfs_remote_dir, bkpinfo->prefix,
    3664             g_current_media_number);
     3495             bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     3496             g_current_media_number);
    36653497    for (that_one_was_ok = FALSE; !that_one_was_ok;) {
    36663498        res = make_iso_fs(bkpinfo, isofile);
     
    36893521        } else {
    36903522            asprintf(&tmp, "Failed to burn %s #%d. Retry?",
    3691                     media_descriptor_string(bkpinfo->backup_media_type),
    3692                     g_current_media_number);
     3523                     media_descriptor_string(bkpinfo->backup_media_type),
     3524                     g_current_media_number);
    36933525            res = ask_me_yes_or_no(tmp);
    36943526            paranoid_free(tmp);
     
    37213553    wipe_archives(bkpinfo->scratchdir);
    37223554    asprintf(&tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
    3723             bkpinfo->scratchdir, bkpinfo->scratchdir);
     3555             bkpinfo->scratchdir, bkpinfo->scratchdir);
    37243556    if (system(tmp)) {
    37253557        log_msg(2,
    3726              "Error occurred when I tried to delete the redundant IMGs and GZs");
     3558                "Error occurred when I tried to delete the redundant IMGs and GZs");
    37273559    }
    37283560    paranoid_free(tmp);
     
    37953627            if (res) {
    37963628                asprintf(&tmp,
    3797                         "Warnings/errors were reported while checking %s #%d",
    3798                         media_descriptor_string(bkpinfo->backup_media_type),
    3799                         g_current_media_number);
     3629                         "Warnings/errors were reported while checking %s #%d",
     3630                         media_descriptor_string(bkpinfo->
     3631                                                 backup_media_type),
     3632                         g_current_media_number);
    38003633                log_to_screen(tmp);
    38013634                paranoid_free(tmp);
     
    38103643*/
    38113644        asprintf(&tmp,
    3812                 "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> /tmp/changed.files",
    3813                 MONDO_LOGFILE);
     3645                 "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> /tmp/changed.files",
     3646                 MONDO_LOGFILE);
    38143647        system(tmp);
    38153648        paranoid_free(tmp);
    38163649
    38173650        asprintf(&tmp,
    3818                 "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> /tmp/changed.files",
    3819                 MONDO_LOGFILE);
     3651                 "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> /tmp/changed.files",
     3652                 MONDO_LOGFILE);
    38203653        system(tmp);
    38213654        paranoid_free(tmp);
     
    39253758
    39263759
    3927 
    39283760/**
    39293761 * Wrapper around @c write_image_to_floppy_SUB().
  • trunk/mondo/mondo/common/libmondo-fifo.c

    r42 r45  
    3939 */
    4040pid_t g_mastermind_pid = 0;
    41 
    42 
    4341
    4442/**
  • trunk/mondo/mondo/common/libmondo-gui.c

    r42 r45  
    1 /* libmondo-gui.c
    2  * $Id$
    3  */
     1/* $Id$ */
    42
    53/**
  • trunk/mondo/mondo/common/libmondo-raid.c

    r43 r45  
    1 /* subroutines for handling RAID
    2    $Id$
     1/* $Id$
     2   subroutines for handling RAID
    33*/
    44
     
    4848
    4949    if (raidno == -1) {
    50         asprintf(&command, "cat /proc/mdstat | grep \"linear\" > /dev/null 2> /dev/null");
     50        asprintf(&command,
     51                 "cat /proc/mdstat | grep \"linear\" > /dev/null 2> /dev/null");
    5152    } else {
    52         asprintf(&command, "cat /proc/mdstat | grep \"raid%d\" > /dev/null 2> /dev/null", raidno);
     53        asprintf(&command,
     54                 "cat /proc/mdstat | grep \"raid%d\" > /dev/null 2> /dev/null",
     55                 raidno);
    5356    }
    5457    log_it("Is raid %d registered? Command = '%s'", raidno, command);
     
    6265#endif
    6366}
     67
    6468
    6569/**
     
    378382int get_next_raidtab_line(FILE * fin, char *label, char *value)
    379383{
    380     char *incoming;
     384    char *incoming = NULL;
    381385    char *p;
     386    size_t n = 0;
    382387
    383388    assert(fin != NULL);
     
    390395    }
    391396
    392     malloc_string(incoming);
    393     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    394          fgets(incoming, MAX_STR_LEN - 1, fin)) {
     397    for (getline(&incoming, &n, fin); !feof(fin);
     398         getline(&incoming, &n, fin)) {
    395399        strip_spaces(incoming);
    396400        p = strchr(incoming, ' ');
     
    555559    int v;
    556560
    557     malloc_string(label);
    558     malloc_string(value);
    559561    assert(raidlist != NULL);
    560562    assert_string_is_neither_NULL_nor_zerolength(fname);
     
    563565        log_it("Raidtab is very small or non-existent. Ignoring it.");
    564566        raidlist->entries = 0;
    565         paranoid_free(label);
    566         paranoid_free(value);
    567567        return (0);
    568568    }
    569569    if (!(fin = fopen(fname, "r"))) {
    570570        log_it("Cannot open raidtab");
    571         paranoid_free(label);
    572         paranoid_free(value);
    573571        return (1);
    574572    }
    575573    items = 0;
    576574    log_it("Loading raidtab...");
     575    malloc_string(label);
     576    malloc_string(value);
    577577    get_next_raidtab_line(fin, label, value);
    578578    while (!feof(fin)) {
     
    671671        if (!disklist) {
    672672            asprintf(&tmp,
    673                     "Ignoring '%s %s' pair of disk %s", labelB, valueB,
    674                     label);
     673                     "Ignoring '%s %s' pair of disk %s", labelB, valueB,
     674                     label);
    675675            log_it(tmp);
    676676            paranoid_free(tmp);
     
    904904    char *tmp;
    905905    char *stub;
    906     char *incoming;
     906    char *incoming = NULL;
    907907    char *raid_devname;
    908908    char *p, *q, *r;
    909909    int diskno;
     910    size_t n = 0;
    910911
    911912    malloc_string(incoming);
     
    915916    }
    916917    mdstat->entries = 0;
    917     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    918          fgets(incoming, MAX_STR_LEN - 1, fin)) {
     918    for (getline(&incoming, &n, fin); !feof(fin);
     919         getline(&incoming, &n, fin)) {
    919920        p = incoming;
    920921        if (*p != 'm' && *(p + 1) == 'm') {
     
    964965            asprintf(&tmp, "/dev/%s", stub);
    965966            paranoid_free(stub);
     967
    966968            log_msg(8, "/dev/md%d : disk#%d : %s (%d)",
    967969                    mdstat->el[mdstat->entries].md, diskno, tmp,
    968970                    mdstat->el[mdstat->entries].disks.el[diskno].index);
    969             strcpy(mdstat->el[mdstat->entries].disks.el[diskno].device, tmp);
     971            strcpy(mdstat->el[mdstat->entries].disks.el[diskno].device,
     972                   tmp);
    970973            paranoid_free(tmp);
     974
    971975            while (*p != ' ' && *p) {
    972976                p++;
     
    979983// next line --- skip it
    980984        if (!feof(fin)) {
    981             fgets(incoming, MAX_STR_LEN - 1, fin);
     985            getline(&incoming, &n, fin);
    982986        } else {
    983987            continue;
     
    985989// next line --- the 'progress' line
    986990        if (!feof(fin)) {
    987             fgets(incoming, MAX_STR_LEN - 1, fin);
     991            getline(&incoming, &n, fin);
    988992        } else {
    989993            continue;
     
    10421046
    10431047
    1044 
    10451048/* @} - end of raidGroup */
  • trunk/mondo/mondo/common/libmondo-string.c

    r44 r45  
    6666
    6767
    68 
    6968/**
    7069 * Pad a string on both sides so it appears centered.
     
    101100
    102101
    103 
    104 
    105102inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin)
    106103{
     
    114111    *q = *p;                    // for the final '\0'
    115112}
    116 
    117113
    118114
     
    127123    char *pos_w_commas;
    128124    static char output[MAX_STR_LEN];
    129     char tmp[MAX_STR_LEN];
     125    char *tmp;
    130126    int j;
    131127
    132128    assert(input != NULL);
    133129
    134     strcpy(tmp, input);
     130    asprintf(tmp, "%s", input);
    135131    if (strlen(tmp) > 6) {
    136132        asprintf(&pos_w_commas, "%s", tmp);
     
    151147    strcpy(output, pos_w_commas);
    152148    paranoid_free(pos_w_commas);
     149    paranoid_free(tmp);
    153150    return (output);
    154151}
     
    169166
    170167    /*@ buffers ********************************************************** */
    171     static char output[MAX_STR_LEN];
     168    char *output;
    172169
    173170    assert(disklist != NULL);
    174171
    175     sprintf(output, "%-24s %8d", disklist->el[lino].device,
    176             disklist->el[lino].index);
     172    asprintf(&output, "%-24s %8d", disklist->el[lino].device,
     173             disklist->el[lino].index);
    177174    return (output);
    178175}
    179 
    180 
    181 
    182176
    183177
     
    214208    outval = atol(tmp);
    215209    paranoid_free(tmp);
     210
    216211    if (ch == 'g' || ch == 'G') {
    217212        outval = outval * 1024;
     
    563558
    564559
    565 
    566 
    567560/**
    568561 * Wrap @p flaws_str across three lines. The first two are no more than 74 characters wide.
     
    614607    }
    615608}
    616 
    617609
    618610
     
    852844    char *output;
    853845
    854 
    855 
    856846    if (raid_level >= 0) {
    857847        asprintf(&output, " RAID %-2d ", raid_level);
  • trunk/mondo/mondo/common/newt-specific.c

    r30 r45  
    1 /* newt-specific.c
    2    $Id: newt-specific.c,v 1.8 2004/06/10 17:13:33 hugo Exp $
     1/* $Id$
    32
    43  subroutines which do display-type things
    54  and use the newt library to do them
    6 .
    7 
    8 10/02
    9 - tell user not to bother mailing list unless snapshot
    10 
    11 07/09
    12 - finish() calls g_erase_tmpdir_and_scratchdir to erase
    13   tmpdir and scratchdir at end
    14 
    15 06/25
    16 - tried to fix newtFinished() segfault
    17 
    18 04/13/2004
    19 - lots of char[]'s are now *char's
    20 
    21 10/09/2003
    22 - allow DVD option for text-mode which_backup_type() too
    23 
    24 09/28
    25 - log_to_screen() now takes printf-like parameters
    26 
    27 09/26
    28 - b5 now means dvd (was udev)
    29 
    30 09/16
    31 - echo fatal error to screen before exiting
    32 - working on fatal_error()
    33 - swapped g_blurb2 and g_blurb3 in a few places to fix a GUI problem;
    34   it shouldn't have worked! :) I think there's a mem-leak somewhere
    35 
    36 09/13
    37 - changed some '\n' occurrences to '\r\n'
    38 
    39 09/09
    40 - fixed silly bug in log_to_screen()
    41 
    42 07/02
    43 - modified popup_and_get_string()
    44 
    45 05/03
    46 - cleaned up fatal_error()
    47 
    48 04/30
    49 - fixed popup_changelist_*()
    50 
    51 04/27
    52 - replace newtFinished() and newtInit() with
    53   newtSuspend() and newtResume()
    54 
    55 04/25
    56 - after comparing, popup the changelist for the user
    57 - moved the relevant code from compare_to_cds() into
    58   compare_mode(), so that tape users may benefit too
    59 
    60 04/24
    61 - added lots of assert()'s and log_OS_error()'s
    62 - cleaned up a few uninitialized strings (valgrind)
    63 
    64 04/22
    65 - line 1181 - 'read from' (not 'restoring from')
    66 
    67 03/15/2003
    68 - fixed potentially infinite loop in log_to_screen (Tom Mortell)
    69 
    70 12/04/2002
    71 - changed "Pick file" to "Non-matching files"
    72 
    73 11/28
    74 - finish() now unregisters Mondo's pid
    75 
    76 10/28
    77 - unmount tmpfs if fatal_error
    78 
    79 10/04
    80 - more XMondo-related work
    81 - added some =NULL's in a few places
    82 
    83 09/01 - 09/30
    84 - write log_to_screen()'s string to stdout if in text mode
    85 - update_progress_form_FULL(), update_evalcall_form(),
    86   popup_and_*(), ask_me_yes_or_no() now write
    87   XMondo-friendly info to stdout if in text mode
    88 - if fatal error then popup and say what the fatal error is
    89 - run_program_and_log_output() now takes boolean operator to specify
    90   whether it will log its activities in the event of _success_
    91 - added popup_changelist_from_file(char*source_file, char*topic, void*call_if_entry_selected(void*));
    92 
    93 08/07
    94 - added some functions to let user choose backup dev + format
    95 
    96 07/27
    97 - created
    985*/
    996
     
    12229
    12330/*@unused@*/
    124 //static char cvsid[] = "$Id: newt-specific.c,v 1.8 2004/06/10 17:13:33 hugo Exp $";
    125 
    126 extern pid_t g_mastermind_pid;
    127 extern char *g_tmpfs_mountpt;
    128 extern char *g_boot_mountpt;
    129 extern char *g_mondo_home;
    130 
    131 extern char g_version[];
    132 
    133 extern void set_signals(int);
     31//static char cvsid[] = "$Id$";
     32
     33    extern pid_t g_mastermind_pid;
     34    extern char *g_tmpfs_mountpt;
     35    extern char *g_boot_mountpt;
     36    extern char *g_mondo_home;
     37
     38    extern char g_version[];
     39
     40    extern void set_signals(int);
    13441
    13542/**
     
    14047 * Whether we are currently in a nested call of fatal_error().
    14148 */
    142 bool g_exiting=FALSE;
     49    bool g_exiting = FALSE;
    14350
    14451/**
    14552 * Padding below the Newt components, to overcome bugs in Newt.
    14653 */
    147 char g_haharrrrr[500];
    148 
    149 
    150 newtComponent g_timeline=NULL, ///< The line of the progress form that shows the time elapsed/remaining
    151     g_percentline=NULL, ///< The line of the progress form that shows the percent completed/remaining
    152     g_scale=NULL, ///< The progress bar component in the progress form
    153     g_progressForm=NULL, ///< The progress form component itself
    154     g_blurb1=NULL, ///< The component for line 1 of the blurb in the progress form
    155     g_blurb2=NULL, ///< The component for line 2 of the blurb in the progress form
    156     g_blurb3=NULL, ///< The component for line 3 (updated continuously) of the blurb in the progress form
    157     g_label=NULL; ///< ????? @bug ?????
     54    char g_haharrrrr[500];
     55
     56
     57    newtComponent g_timeline = NULL,    ///< The line of the progress form that shows the time elapsed/remaining
     58        g_percentline = NULL,   ///< The line of the progress form that shows the percent completed/remaining
     59        g_scale = NULL,         ///< The progress bar component in the progress form
     60        g_progressForm = NULL,  ///< The progress form component itself
     61        g_blurb1 = NULL,        ///< The component for line 1 of the blurb in the progress form
     62        g_blurb2 = NULL,        ///< The component for line 2 of the blurb in the progress form
     63        g_blurb3 = NULL,        ///< The component for line 3 (updated continuously) of the blurb in the progress form
     64        g_label = NULL;         ///< ????? @bug ?????
    15865
    15966/**
    16067 * Padding above the Newt components, to overcome bugs in Newt.
    16168 */
    162 char g_jim_lad_yarr[500];
    163 char **err_log_lines = NULL, ///< The list of log lines to show on the screen.
    164     g_blurb_str_1[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 1 of the blurb in the progress form
    165     g_blurb_str_2[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 2 of the blurb in the progress form
    166     g_blurb_str_3[MAX_NEWT_COMMENT_LEN] = ""; ///< The string for line 3 (updated continuously) of the blurb in the progress form
    167 newtComponent g_isoform_main = NULL, ///< The evalcall form component itself
    168     g_isoform_header=NULL, ///< The component for the evalcall form title
    169     g_isoform_scale=NULL, ///< The progress bar component in the evalcall form
    170     g_isoform_timeline=NULL, ///< The line of the evalcall form that shows the time elapsed/remaining
    171     g_isoform_pcline=NULL; ///< The line of the evalcall form that shows the percent completed/remaining
    172 long g_isoform_starttime; ///< The time (in seconds since the epoch) that the evalcall form was opened.
    173 int g_isoform_old_progress = -1; ///< The most recent progress update of the evalcall form (percent).
    174 char g_isoform_header_str[MAX_STR_LEN]="                                                                                                               "; ///< The string for the evalcall form title.
    175 int g_mysterious_dot_counter; ///< The counter for the twirling baton (/ | \\ - ...) on percentage less than 3
    176 int g_noof_log_lines = 6; ///< The number of lines to show in the log at the bottom of the screen.
    177 int g_noof_rows = 25; ///< The number of rows on the screen.
    178 
    179 int g_currentY = 3; ///< The row to write background progress messages to. Incremented each time a message is written.
    180 extern int g_current_media_number;
    181 pid_t g_main_pid = 0; ///< The PID of the main Mondo process.
    182 long g_maximum_progress = 999; ///< The maximum amount of progress (100%) for the currently opened progress form.
    183 long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form.
    184 long g_start_time = 0; ///< The time (in seconds since the epoch) that the progress form was opened.
    185 bool g_text_mode = TRUE; ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface.
    186 char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN], ///< ... @bug Unneeded w/current XMondo.
    187     g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo.
    188 bool g_called_by_xmondo=FALSE; ///< @bug Unneeded w/current XMondo.
    189 char *g_erase_tmpdir_and_scratchdir; ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo.
     69    char g_jim_lad_yarr[500];
     70    char **err_log_lines = NULL,    ///< The list of log lines to show on the screen.
     71        g_blurb_str_1[MAX_NEWT_COMMENT_LEN] = "",   ///< The string for line 1 of the blurb in the progress form
     72        g_blurb_str_2[MAX_NEWT_COMMENT_LEN] = "",   ///< The string for line 2 of the blurb in the progress form
     73        g_blurb_str_3[MAX_NEWT_COMMENT_LEN] = "";   ///< The string for line 3 (updated continuously) of the blurb in the progress form
     74    newtComponent g_isoform_main = NULL,    ///< The evalcall form component itself
     75        g_isoform_header = NULL,    ///< The component for the evalcall form title
     76        g_isoform_scale = NULL, ///< The progress bar component in the evalcall form
     77        g_isoform_timeline = NULL,  ///< The line of the evalcall form that shows the time elapsed/remaining
     78        g_isoform_pcline = NULL;    ///< The line of the evalcall form that shows the percent completed/remaining
     79    long g_isoform_starttime;   ///< The time (in seconds since the epoch) that the evalcall form was opened.
     80    int g_isoform_old_progress = -1;    ///< The most recent progress update of the evalcall form (percent).
     81    char g_isoform_header_str[MAX_STR_LEN] = "                                                                                                               "; ///< The string for the evalcall form title.
     82    int g_mysterious_dot_counter;   ///< The counter for the twirling baton (/ | \\ - ...) on percentage less than 3
     83    int g_noof_log_lines = 6;   ///< The number of lines to show in the log at the bottom of the screen.
     84    int g_noof_rows = 25;       ///< The number of rows on the screen.
     85
     86    int g_currentY = 3;         ///< The row to write background progress messages to. Incremented each time a message is written.
     87    extern int g_current_media_number;
     88    pid_t g_main_pid = 0;       ///< The PID of the main Mondo process.
     89    long g_maximum_progress = 999;  ///< The maximum amount of progress (100%) for the currently opened progress form.
     90    long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form.
     91    long g_start_time = 0;      ///< The time (in seconds since the epoch) that the progress form was opened.
     92    bool g_text_mode = TRUE;    ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface.
     93    char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN],  ///< ... @bug Unneeded w/current XMondo.
     94     g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo.
     95    bool g_called_by_xmondo = FALSE;    ///< @bug Unneeded w/current XMondo.
     96    char *g_erase_tmpdir_and_scratchdir;    ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo.
    19097
    19198/* @} - end of globalGroup */
     
    193100//int g_fd_in=-1, g_fd_out=-1;
    194101
    195 void popup_and_OK(char*);
     102    void popup_and_OK(char *);
    196103
    197104
     
    205112 * @return TRUE for yes; FALSE for no.
    206113 */
    207 bool
    208 ask_me_yes_or_no (char *prompt)
    209 {
    210 
    211     /*@ buffers ***********************************************************/
    212   char *tmp;
    213   int i;
    214 
    215   tmp = malloc(MAX_NEWT_COMMENT_LEN);
    216   assert_string_is_neither_NULL_nor_zerolength(prompt);
    217 
    218   if (g_text_mode)
    219     {
    220       while(1)
    221         {
    222           system("sync");
    223           printf ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ", prompt);
    224       (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
    225       if (tmp[strlen (tmp) - 1] == '\n')
    226           tmp[strlen (tmp) - 1] = '\0';
    227 
    228           i = (int) strlen(tmp);
    229           if (i>0 && tmp[i-1]<32) { tmp[i-1]='\0'; }
    230           if (strstr ("yesYES", tmp))
    231             {
    232           paranoid_free(tmp);
    233               return (TRUE);
    234             }
    235           else if (strstr ("NOno", tmp))
    236             {
    237           paranoid_free(tmp);
    238               return (FALSE);
    239         }
    240           else
    241             {
    242               system("sync");
    243               printf("Please enter either YES or NO (or yes or no, or y or n, or...)\n");
    244             }
    245         }
    246     }
    247   else
    248     {
    249       paranoid_free(tmp);
    250       return (popup_with_buttons (prompt, "Yes", "No"));
    251     }
    252 }
     114     bool ask_me_yes_or_no(char *prompt) {
     115
     116        /*@ buffers ********************************************************** */
     117        char *tmp = NULL;
     118        int i;
     119        size_t n = 0;
     120
     121        assert_string_is_neither_NULL_nor_zerolength(prompt);
     122
     123        if (g_text_mode) {
     124            while (1) {
     125                system("sync");
     126                printf
     127                    ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ",
     128                     prompt);
     129                (void) getline(&tmp, &n, stdin);
     130                if (tmp[strlen(tmp) - 1] == '\n')
     131                    tmp[strlen(tmp) - 1] = '\0';
     132
     133                i = (int) strlen(tmp);
     134                if (i > 0 && tmp[i - 1] < 32) {
     135                    tmp[i - 1] = '\0';
     136                }
     137                if (strstr("yesYES", tmp)) {
     138                    paranoid_free(tmp);
     139                    return (TRUE);
     140                } else if (strstr("NOno", tmp)) {
     141                    paranoid_free(tmp);
     142                    return (FALSE);
     143                } else {
     144                    system("sync");
     145                    printf
     146                        ("Please enter either YES or NO (or yes or no, or y or n, or...)\n");
     147                }
     148            }
     149        } else {
     150            return (popup_with_buttons(prompt, "Yes", "No"));
     151        }
     152    }
    253153
    254154
     
    259159 * @return TRUE for OK, FALSE for Cancel.
    260160 */
    261 bool
    262 ask_me_OK_or_cancel (char *prompt)
    263 {
    264 
    265     /*@ buffer ************************************************************/
    266   char *tmp;
    267   int i;
    268 
    269   tmp = malloc(MAX_NEWT_COMMENT_LEN);
    270   assert_string_is_neither_NULL_nor_zerolength(prompt);
    271   if (g_text_mode)
    272     {
    273       system("sync");
    274       printf ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ", prompt);
    275       (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
    276       if (tmp[strlen (tmp) - 1] == '\n')
    277       tmp[strlen (tmp) - 1] = '\0';
    278 
    279       i = (int) strlen(tmp);
    280       if (i>0 && tmp[i-1]<32) { tmp[i-1]='\0'; }
    281       if (strstr ("okOKOkYESyes", tmp))
    282     {
    283           paranoid_free(tmp);
    284       return (TRUE);
    285     }
    286       else
    287     {
    288           paranoid_free(tmp);
    289       return (FALSE);
    290     }
    291     }
    292   else
    293     {
    294       paranoid_free(tmp);
    295       return (popup_with_buttons (prompt, " Okay ", "Cancel"));
    296     }
     161    bool ask_me_OK_or_cancel(char *prompt) {
     162
     163        /*@ buffer *********************************************************** */
     164        char *tmp = NULL;
     165        int i;
     166        size_t n = 0;
     167
     168        assert_string_is_neither_NULL_nor_zerolength(prompt);
     169        if (g_text_mode) {
     170            system("sync");
     171            printf
     172                ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ",
     173                 prompt);
     174            (void) getline(&tmp, &n, stdin);
     175            if (tmp[strlen(tmp) - 1] == '\n')
     176                tmp[strlen(tmp) - 1] = '\0';
     177
     178            i = (int) strlen(tmp);
     179            if (i > 0 && tmp[i - 1] < 32) {
     180                tmp[i - 1] = '\0';
     181            }
     182            if (strstr("okOKOkYESyes", tmp)) {
     183                paranoid_free(tmp);
     184                return (TRUE);
     185            } else {
     186                paranoid_free(tmp);
     187                return (FALSE);
     188            }
     189        } else {
     190            return (popup_with_buttons(prompt, " Okay ", "Cancel"));
     191        }
     192    }
     193
     194
     195/**
     196 * Close the currently opened evalcall form.
     197 */
     198    void
     199     close_evalcall_form(void) {
     200        if (g_text_mode) {
     201            return;
     202        }
     203        if (g_isoform_main == NULL) {
     204            return;
     205        }
     206        update_evalcall_form(100);
     207        usleep(500000);
     208        if (g_text_mode) {
     209            log_msg(2, "Closing evalcall form");
     210            return;
     211        }
     212        newtPopHelpLine();
     213        newtFormDestroy(g_isoform_main);
     214        newtPopWindow();
     215        g_isoform_main = NULL;
     216        g_isoform_old_progress = -1;
     217    }
     218
     219
     220/**
     221 * Close the currently opened progress form.
     222 */
     223void
     224 close_progress_form() {
     225    if (g_text_mode) {
     226        return;
     227    }
     228    if (g_current_progress == -999) {
     229        log_msg(2,
     230                "Trying to close the progress form when it ain't open!");
     231        return;
     232    }
     233    g_current_progress = g_maximum_progress;
     234    update_progress_form("Complete");
     235    sleep(1);
     236    if (g_text_mode) {
     237        log_msg(2, "Closing progress form");
     238        return;
     239    }
     240    newtPopHelpLine();
     241    newtFormDestroy(g_progressForm);
     242    newtPopWindow();
     243    g_progressForm = NULL;
     244    g_current_progress = -999;
    297245}
    298 
    299 
    300 
    301 /**
    302  * Close the currently opened evalcall form.
    303  */
    304 void
    305 close_evalcall_form (void)
    306 {
    307   if (g_text_mode) {return;}
    308   if (g_isoform_main == NULL) {return; }
    309   update_evalcall_form (100);
    310   usleep (500000);
    311   if (g_text_mode)
    312     {
    313       log_msg (2, "Closing evalcall form");
    314       return;
    315     }
    316   newtPopHelpLine ();
    317   newtFormDestroy (g_isoform_main);
    318   newtPopWindow ();
    319   g_isoform_main = NULL;
    320   g_isoform_old_progress = -1;
    321 }
    322 
    323 
    324 /**
    325  * Close the currently opened progress form.
    326  */
    327 void
    328 close_progress_form ()
    329 {
    330   if (g_text_mode) {return;}
    331   if (g_current_progress == -999)
    332     {
    333       log_msg (2, "Trying to close the progress form when it ain't open!");
    334       return;
    335     }
    336   g_current_progress = g_maximum_progress;
    337   update_progress_form ("Complete");
    338   sleep (1);
    339   if (g_text_mode)
    340     {
    341       log_msg (2, "Closing progress form");
    342       return;
    343     }
    344   newtPopHelpLine ();
    345   newtFormDestroy (g_progressForm);
    346   newtPopWindow ();
    347   g_progressForm = NULL;
    348   g_current_progress = -999;
    349 }
    350 
    351 
    352246
    353247
     
    357251 * @note This function never returns.
    358252 */
    359 void
    360 fatal_error (char *error_string)
    361 {
    362     /*@ buffers ******************************************************/
    363   char fatalstr[MAX_NEWT_COMMENT_LEN] = "-------FATAL ERROR---------";
    364   char *tmp;
    365   static bool already_exiting=FALSE;
    366   int i;
    367 
    368     /*@ end vars *****************************************************/
    369 
    370   tmp = malloc(MAX_NEWT_COMMENT_LEN);
    371   set_signals(FALSE); // link to external func
    372   g_exiting = TRUE;
    373   log_msg(1, "Fatal error received - '%s'", error_string);
    374   printf("Fatal error... %s\n", error_string);
    375   if (getpid() == g_mastermind_pid)
    376     {
    377       log_msg(2, "mastermind %d is exiting", (int)getpid());
    378       kill(g_main_pid, SIGTERM);
    379       paranoid_free(tmp);
    380       finish(1);
    381     }
    382 
    383   if (getpid() != g_main_pid)
    384     {
    385       if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid)
    386     {
    387       log_msg(2, "non-m/m %d is exiting", (int)getpid());
    388       kill(g_main_pid, SIGTERM);
    389       paranoid_free(tmp);
    390       finish(1);
    391     }
    392     }
    393 
    394   log_msg (3, "OK, I think I'm the main PID.");
    395   if (already_exiting)
    396     {
    397       log_msg(3, "...I'm already exiting. Give me time, Julian!");
    398       paranoid_free(tmp);
    399       finish(1);
    400     }
    401 
    402   already_exiting = TRUE;
    403   log_msg(2, "I'm going to do some cleaning up now.");
    404   paranoid_system("killall mindi 2> /dev/null");
    405   kill_anything_like_this("/mondo/do-not");
    406   kill_anything_like_this("tmp.mondo");
    407   kill_anything_like_this("partimagehack");
    408   sync();
    409   sprintf(tmp, "umount %s", g_tmpfs_mountpt);
    410   chdir("/");
    411   for(i=0; i<10 && run_program_and_log_output(tmp, 5); i++)
    412     {
    413       log_msg(2, "Waiting for child processes to terminate");
    414       sleep(1);
    415       run_program_and_log_output(tmp, 5);
    416     }
    417 
    418   if (g_erase_tmpdir_and_scratchdir[0])
    419     { run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5); }
    420 
    421   if (!g_text_mode)
    422     {
    423       log_msg (0, fatalstr);
    424       log_msg (0, error_string);
    425       //      popup_and_OK (error_string);
    426       newtFinished ();
    427     }
    428 
    429   printf ("---FATALERROR--- %s\n", error_string);
    430   system("cat /var/log/mondo-archive.log | gzip -9 > /tmp/MA.log.gz 2> /dev/null");
    431   if (!strstr(g_version, "cvs") && !strstr(g_version, "svn"))
    432     {
    433       printf("Please try the snapshot (the version with 'cvs' and the date in its filename)");
    434       printf("to see if that fixes the problem. Please don't bother the mailing list with");
    435       printf("your problem UNTIL you've tried the snapshot. The snapshot contains bugfixes");
    436       printf("which might help you. Go to http://www.mondorescue.org/download/download.html");
    437       printf("For more information.\n");
    438       log_msg(0, "Please DON'T contact the mailing list. Try the SNAPSHOTS.");
    439     }
    440   else
    441     {
    442       printf("If you require technical support, please contact the mailing list.\n");
    443       printf("See http://www.mondorescue.org for details.\n");
    444       printf("The list's members can help you, if you attach that file to your e-mail.\n");
    445     }
    446   printf("Log file: %s\n", MONDO_LOGFILE);
    447   //  printf("VERSION=%s\n", g_version);
    448   if (does_file_exist("/tmp/MA.log.gz"))
    449     {
    450       printf("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n");
    451     }
    452   printf ("Mondo has aborted.\n");
    453   register_pid(0, "mondo"); // finish() does this too, FYI
    454   if (!g_main_pid) { log_msg(3, "FYI - g_main_pid is blank"); }
    455   paranoid_free(tmp);
    456   finish (254);
    457 }
     253    void
     254     fatal_error(char *error_string) {
     255        /*@ buffers ***************************************************** */
     256        char fatalstr[MAX_NEWT_COMMENT_LEN] =
     257            "-------FATAL ERROR---------";
     258        char *tmp;
     259        static bool already_exiting = FALSE;
     260        int i;
     261
     262        /*@ end vars **************************************************** */
     263
     264        tmp = malloc(MAX_NEWT_COMMENT_LEN);
     265        set_signals(FALSE);     // link to external func
     266        g_exiting = TRUE;
     267        log_msg(1, "Fatal error received - '%s'", error_string);
     268        printf("Fatal error... %s\n", error_string);
     269        if (getpid() == g_mastermind_pid) {
     270            log_msg(2, "mastermind %d is exiting", (int) getpid());
     271            kill(g_main_pid, SIGTERM);
     272            paranoid_free(tmp);
     273            finish(1);
     274        }
     275
     276        if (getpid() != g_main_pid) {
     277            if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid) {
     278                log_msg(2, "non-m/m %d is exiting", (int) getpid());
     279                kill(g_main_pid, SIGTERM);
     280                paranoid_free(tmp);
     281                finish(1);
     282            }
     283        }
     284
     285        log_msg(3, "OK, I think I'm the main PID.");
     286        if (already_exiting) {
     287            log_msg(3, "...I'm already exiting. Give me time, Julian!");
     288            paranoid_free(tmp);
     289            finish(1);
     290        }
     291
     292        already_exiting = TRUE;
     293        log_msg(2, "I'm going to do some cleaning up now.");
     294        paranoid_system("killall mindi 2> /dev/null");
     295        kill_anything_like_this("/mondo/do-not");
     296        kill_anything_like_this("tmp.mondo");
     297        kill_anything_like_this("partimagehack");
     298        sync();
     299        sprintf(tmp, "umount %s", g_tmpfs_mountpt);
     300        chdir("/");
     301        for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) {
     302            log_msg(2, "Waiting for child processes to terminate");
     303            sleep(1);
     304            run_program_and_log_output(tmp, 5);
     305        }
     306
     307        if (g_erase_tmpdir_and_scratchdir[0]) {
     308            run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5);
     309        }
     310
     311        if (!g_text_mode) {
     312            log_msg(0, fatalstr);
     313            log_msg(0, error_string);
     314            //      popup_and_OK (error_string);
     315            newtFinished();
     316        }
     317
     318        printf("---FATALERROR--- %s\n", error_string);
     319        system
     320            ("cat /var/log/mondo-archive.log | gzip -9 > /tmp/MA.log.gz 2> /dev/null");
     321        if (!strstr(g_version, "cvs") && !strstr(g_version, "svn")) {
     322            printf
     323                ("Please try the snapshot (the version with 'cvs' and the date in its filename)");
     324            printf
     325                ("to see if that fixes the problem. Please don't bother the mailing list with");
     326            printf
     327                ("your problem UNTIL you've tried the snapshot. The snapshot contains bugfixes");
     328            printf
     329                ("which might help you. Go to http://www.mondorescue.org/download/download.html");
     330            printf("For more information.\n");
     331            log_msg(0,
     332                    "Please DON'T contact the mailing list. Try the SNAPSHOTS.");
     333        } else {
     334            printf
     335                ("If you require technical support, please contact the mailing list.\n");
     336            printf("See http://www.mondorescue.org for details.\n");
     337            printf
     338                ("The list's members can help you, if you attach that file to your e-mail.\n");
     339        }
     340        printf("Log file: %s\n", MONDO_LOGFILE);
     341        //  printf("VERSION=%s\n", g_version);
     342        if (does_file_exist("/tmp/MA.log.gz")) {
     343            printf
     344                ("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n");
     345        }
     346        printf("Mondo has aborted.\n");
     347        register_pid(0, "mondo");   // finish() does this too, FYI
     348        if (!g_main_pid) {
     349            log_msg(3, "FYI - g_main_pid is blank");
     350        }
     351        paranoid_free(tmp);
     352        finish(254);
     353    }
    458354
    459355
     
    465361 * @note This function never returns.
    466362 */
    467 void
    468 finish (int signal)
    469 {
    470 
    471   /*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */
    472 
    473   /* newtPopHelpLine(); */
    474 
    475   register_pid(0, "mondo");
    476   chdir("/");
    477   run_program_and_log_output("umount "MNT_CDROM, FALSE);
    478   run_program_and_log_output("rm -Rf /mondo.scratch.* /tmp.mondo.*", FALSE);
    479   if (g_erase_tmpdir_and_scratchdir)
    480     {
    481       run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1);
    482     }
    483    
     363    void
     364     finish(int signal) {
     365
     366        /*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */
     367
     368        /* newtPopHelpLine(); */
     369
     370        register_pid(0, "mondo");
     371        chdir("/");
     372        run_program_and_log_output("umount " MNT_CDROM, FALSE);
     373        run_program_and_log_output("rm -Rf /mondo.scratch.* /tmp.mondo.*",
     374                                   FALSE);
     375        if (g_erase_tmpdir_and_scratchdir) {
     376            run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1);
     377        }
    484378//  iamhere("foo");
    485   /* system("clear"); */
     379        /* system("clear"); */
    486380//  iamhere("About to call newtFinished");
    487   if (!g_text_mode)
    488     {
    489       if (does_file_exist("/THIS-IS-A-RAMDISK"))
    490         {
    491       log_msg(1, "Calling newtFinished()");
    492       newtFinished();
    493     }
    494       else
    495         {
    496       log_msg(1, "Calling newtSuspend()");
    497           newtSuspend();
    498     }
    499     }
     381        if (!g_text_mode) {
     382            if (does_file_exist("/THIS-IS-A-RAMDISK")) {
     383                log_msg(1, "Calling newtFinished()");
     384                newtFinished();
     385            } else {
     386                log_msg(1, "Calling newtSuspend()");
     387                newtSuspend();
     388            }
     389        }
    500390//  system("clear");
    501391//  iamhere("Finished calling newtFinished");
    502   printf( "Execution run ended; result=%d\n", signal);
    503   printf( "Type 'less %s' to see the output log\n", MONDO_LOGFILE);
    504   free_libmondo_global_strings();
    505   exit (signal);
    506 }
     392        printf("Execution run ended; result=%d\n", signal);
     393        printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE);
     394        free_libmondo_global_strings();
     395        exit(signal);
     396    }
    507397
    508398
     
    516406 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression.
    517407 */
    518 void
    519 log_file_end_to_screen (char *filename, char *grep_for_me)
    520 {
    521 
    522     /*@ buffers ***********************************************************/
    523   char *command;
    524     char *tmp;
    525 
    526     /*@ pointers **********************************************************/
    527   FILE *fin;
    528 
    529     /*@ int ***************************************************************/
    530   int i = 0;
    531 
    532   malloc_string(command);
    533   malloc_string(tmp);
    534   assert_string_is_neither_NULL_nor_zerolength(filename);
    535   assert(grep_for_me!=NULL);
    536 
    537   if (!does_file_exist (filename))
    538     {
    539       paranoid_free(command);
    540       paranoid_free(tmp);
    541       return;
    542     }
    543   if (grep_for_me[0] != '\0')
    544     {
    545       sprintf (command, "cat %s | grep \"%s\" | tail -n%d", filename,
    546            grep_for_me, g_noof_log_lines);
    547     }
    548   else
    549     {
    550       sprintf (command, "cat %s | tail -n%d", filename, g_noof_log_lines);
    551     }
    552   fin = popen (command, "r");
    553   if (!fin)
    554     {
    555       log_OS_error(command);
    556     }
    557   else
    558     {
    559       for (i = 0; i < g_noof_log_lines; i++)
    560     {
    561       for (err_log_lines[i][0] = '\0';
    562            strlen (err_log_lines[i]) < 2 && !feof (fin);)
    563         {
    564           (void) fgets (err_log_lines[i], MAX_NEWT_COMMENT_LEN, fin);
    565           strip_spaces (err_log_lines[i]);
    566           if (!strncmp (err_log_lines[i], "root:", 5))
    567         {
    568           strcpy (tmp, err_log_lines[i] + 6);
    569           strcpy (err_log_lines[i], tmp);
    570         }
    571           if (feof (fin))
    572         {
    573           break;
    574         }
    575         }
    576     }
    577       paranoid_pclose (fin);
    578     }
    579   refresh_log_screen ();
    580   paranoid_free(command);
    581   paranoid_free(tmp);
    582 }
     408    void
     409     log_file_end_to_screen(char *filename, char *grep_for_me) {
     410
     411        /*@ buffers ********************************************************** */
     412        char *command;
     413        char *tmp;
     414
     415        /*@ pointers ********************************************************* */
     416        FILE *fin;
     417
     418        /*@ int ************************************************************** */
     419        int i = 0;
     420
     421        malloc_string(command);
     422        malloc_string(tmp);
     423        assert_string_is_neither_NULL_nor_zerolength(filename);
     424        assert(grep_for_me != NULL);
     425
     426        if (!does_file_exist(filename)) {
     427            paranoid_free(command);
     428            paranoid_free(tmp);
     429            return;
     430        }
     431        if (grep_for_me[0] != '\0') {
     432            sprintf(command, "cat %s | grep \"%s\" | tail -n%d", filename,
     433                    grep_for_me, g_noof_log_lines);
     434        } else {
     435            sprintf(command, "cat %s | tail -n%d", filename,
     436                    g_noof_log_lines);
     437        }
     438        fin = popen(command, "r");
     439        if (!fin) {
     440            log_OS_error(command);
     441        } else {
     442            for (i = 0; i < g_noof_log_lines; i++) {
     443                for (err_log_lines[i][0] = '\0';
     444                     strlen(err_log_lines[i]) < 2 && !feof(fin);) {
     445                    (void) fgets(err_log_lines[i], MAX_NEWT_COMMENT_LEN,
     446                                 fin);
     447                    strip_spaces(err_log_lines[i]);
     448                    if (!strncmp(err_log_lines[i], "root:", 5)) {
     449                        strcpy(tmp, err_log_lines[i] + 6);
     450                        strcpy(err_log_lines[i], tmp);
     451                    }
     452                    if (feof(fin)) {
     453                        break;
     454                    }
     455                }
     456            }
     457            paranoid_pclose(fin);
     458        }
     459        refresh_log_screen();
     460        paranoid_free(command);
     461        paranoid_free(tmp);
     462    }
    583463
    584464
     
    588468 * @note The message is also written to the logfile.
    589469 */
    590 void
    591 log_to_screen (const char *fmt, ...)
    592 {
    593 
    594     /*@ int ***************************************************************/
    595   int i = 0;
    596     int j = 0;
    597   va_list args;
    598 
    599     /*@ buffers ***********************************************************/
    600   char *output;
    601 
    602   malloc_string(output);
    603 
    604   va_start(args, fmt);
    605   vsprintf(output, fmt, args);
    606   log_msg(0, output);
    607   output[80] = '\0';
    608   va_end(args);
    609   i = (int) strlen (output);
    610   if (i>0 && output[i - 1] < 32)
    611     {
    612       output[i - 1] = '\0';
    613     }
    614 
    615   if (err_log_lines) {
    616     for (i = 1; i < g_noof_log_lines; i++)
    617       {
    618     strcpy (err_log_lines[i - 1],
    619         "                                                                                ");
    620     strcpy (err_log_lines[i - 1], err_log_lines[i]);
    621       }
    622   }
    623   while (strlen(output)>0 && output[strlen (output) - 1] < 32)
    624     {
    625       output[strlen (output) - 1] = '\0';
    626     }
    627   for (j = 0; j < (int) strlen (output); j++)
    628     {
    629       if (output[j] < 32)
    630     {
    631       output[j] = ' ';
    632     }
    633     }
    634   if (err_log_lines)
    635     strcpy (err_log_lines[g_noof_log_lines - 1], output);
    636   if (g_text_mode)
    637     {
    638       printf("%s\n", output);
    639     }
    640   else
    641     {
    642       refresh_log_screen ();
    643     }
    644   paranoid_free(output);
    645 }
     470    void
     471     log_to_screen(const char *fmt, ...) {
     472
     473        /*@ int ************************************************************** */
     474        int i = 0;
     475        int j = 0;
     476        va_list args;
     477
     478        /*@ buffers ********************************************************** */
     479        char *output;
     480
     481        malloc_string(output);
     482
     483        va_start(args, fmt);
     484        vsprintf(output, fmt, args);
     485        log_msg(0, output);
     486        output[80] = '\0';
     487        va_end(args);
     488        i = (int) strlen(output);
     489        if (i > 0 && output[i - 1] < 32) {
     490            output[i - 1] = '\0';
     491        }
     492
     493        if (err_log_lines) {
     494            for (i = 1; i < g_noof_log_lines; i++) {
     495                strcpy(err_log_lines[i - 1],
     496                       "                                                                                ");
     497                strcpy(err_log_lines[i - 1], err_log_lines[i]);
     498            }
     499        }
     500        while (strlen(output) > 0 && output[strlen(output) - 1] < 32) {
     501            output[strlen(output) - 1] = '\0';
     502        }
     503        for (j = 0; j < (int) strlen(output); j++) {
     504            if (output[j] < 32) {
     505                output[j] = ' ';
     506            }
     507        }
     508        if (err_log_lines)
     509            strcpy(err_log_lines[g_noof_log_lines - 1], output);
     510        if (g_text_mode) {
     511            printf("%s\n", output);
     512        } else {
     513            refresh_log_screen();
     514        }
     515        paranoid_free(output);
     516    }
    646517
    647518
     
    654525 * @param output The string to write.
    655526 */
    656 void
    657 mvaddstr_and_log_it (int y, int x, char *output)
    658 {
    659   assert_string_is_neither_NULL_nor_zerolength(output);
    660   log_msg (0, output);
    661   if (g_text_mode)
    662     {
    663       printf ("%s\n", output);
    664     }
    665   else
    666     {
    667       newtDrawRootText (x, y, output);
    668       newtRefresh ();
    669     }
    670 }
     527    void
     528     mvaddstr_and_log_it(int y, int x, char *output) {
     529        assert_string_is_neither_NULL_nor_zerolength(output);
     530        log_msg(0, output);
     531        if (g_text_mode) {
     532            printf("%s\n", output);
     533        } else {
     534            newtDrawRootText(x, y, output);
     535            newtRefresh();
     536        }
     537    }
    671538
    672539
     
    677544 * @param ttl The title to use for the evalcall form.
    678545 */
    679 void
    680 open_evalcall_form (char *ttl)
    681 {
    682 
    683     /*@ buffers **********************************************************/
    684   char *title;
    685   char *tmp;
    686 
    687     /*@ initialize *******************************************************/
    688   g_isoform_old_progress = -1;
    689   g_mysterious_dot_counter = 0;
    690   malloc_string(title);
    691   malloc_string(tmp);
    692 
    693   assert(ttl!=NULL);
    694   strcpy (title, ttl);
    695   strcpy (g_isoform_header_str, title);
     546    void
     547     open_evalcall_form(char *ttl) {
     548
     549        /*@ buffers ********************************************************* */
     550        char *title;
     551        char *tmp;
     552
     553        /*@ initialize ****************************************************** */
     554        g_isoform_old_progress = -1;
     555        g_mysterious_dot_counter = 0;
     556        malloc_string(title);
     557        malloc_string(tmp);
     558
     559        assert(ttl != NULL);
     560        strcpy(title, ttl);
     561        strcpy(g_isoform_header_str, title);
    696562//  center_string (title, 80);
    697   if (g_text_mode)
    698     {
    699       log_msg (0, title);
    700     }
    701   else
    702     {
    703       strcpy(tmp, title);
    704       center_string(tmp, 80);
    705       newtPushHelpLine (tmp);
    706     }
    707   center_string (g_isoform_header_str, 36);
    708   g_isoform_starttime = get_time ();
    709   if (g_text_mode)
    710     {
    711       log_msg (0, g_isoform_header_str);
    712     }
    713   else
    714     {
    715       g_isoform_header = newtLabel (1, 1, g_isoform_header_str);
    716       g_isoform_scale = newtScale (3, 3, 34, 100);
    717       //      newtOpenWindow (20, 6, 40, 7, title);      // "Please Wait");
    718       newtCenteredWindow (40, 7, title);
    719       g_isoform_main = newtForm (NULL, NULL, 0);
    720       g_isoform_timeline = newtLabel (1, 5, "This is the timeline");
    721       g_isoform_pcline = newtLabel (1, 6, "This is the pcline");
    722       newtFormAddComponents (g_isoform_main, g_isoform_timeline,
    723                  g_isoform_pcline, g_isoform_header,
    724                  g_isoform_scale, NULL);
    725       newtRefresh ();
    726     }
    727   update_evalcall_form (0);
    728   paranoid_free(tmp);
    729   paranoid_free(title);
    730 }
     563        if (g_text_mode) {
     564            log_msg(0, title);
     565        } else {
     566            strcpy(tmp, title);
     567            center_string(tmp, 80);
     568            newtPushHelpLine(tmp);
     569        }
     570        center_string(g_isoform_header_str, 36);
     571        g_isoform_starttime = get_time();
     572        if (g_text_mode) {
     573            log_msg(0, g_isoform_header_str);
     574        } else {
     575            g_isoform_header = newtLabel(1, 1, g_isoform_header_str);
     576            g_isoform_scale = newtScale(3, 3, 34, 100);
     577            //      newtOpenWindow (20, 6, 40, 7, title);      // "Please Wait");
     578            newtCenteredWindow(40, 7, title);
     579            g_isoform_main = newtForm(NULL, NULL, 0);
     580            g_isoform_timeline = newtLabel(1, 5, "This is the timeline");
     581            g_isoform_pcline = newtLabel(1, 6, "This is the pcline");
     582            newtFormAddComponents(g_isoform_main, g_isoform_timeline,
     583                                  g_isoform_pcline, g_isoform_header,
     584                                  g_isoform_scale, NULL);
     585            newtRefresh();
     586        }
     587        update_evalcall_form(0);
     588        paranoid_free(tmp);
     589        paranoid_free(title);
     590    }
    731591
    732592
     
    741601 * @param max_val The maximum amount of progress (number of filesets, etc.)
    742602 */
    743 void
    744 open_progress_form (char *title, char *b1, char *b2, char *b3, long max_val)
    745 {
    746 
    747     /*@ buffers **********************************************************/
    748   char *b1c;
    749     char *blurb1;
    750     char *blurb2;
    751     char *blurb3;
    752 
    753     /*@ initialize *******************************************************/
    754   g_mysterious_dot_counter = 0;
    755 
    756   malloc_string(b1c);
    757   malloc_string(blurb1);
    758   malloc_string(blurb2);
    759   malloc_string(blurb3);
    760  
    761   assert(title!=NULL);
    762   assert(b1!=NULL);
    763   assert(b2!=NULL);
    764   assert(b3!=NULL);
    765 
    766   strcpy (blurb1, b1);
    767   strcpy (blurb2, b2);
    768   strcpy (blurb3, b3);
    769   strcpy (b1c, b1);
    770   center_string (b1c, 80);
    771   if (max_val <= 0)
    772     {
    773       max_val = 1;
    774     }
    775 
    776   g_start_time = get_time ();
    777   g_maximum_progress = max_val;
    778   g_current_progress = 0;
    779   strcpy (g_blurb_str_1, blurb1);
    780   strcpy (g_blurb_str_2, blurb3);
    781   strcpy (g_blurb_str_3, blurb2);
    782   if (g_text_mode)
    783     {
    784       log_msg (0, blurb1);
    785       log_msg (0, blurb2);
    786       log_msg (0, blurb3);
    787     }
    788   else
    789     {
    790       g_blurb1 = newtLabel (2, 1, blurb1);
    791       g_blurb2 = newtLabel (2, 2, blurb3);
    792       g_blurb3 = newtLabel (2, 4, blurb2);
    793       //      newtOpenWindow (10, 4, 60, 11, title);
    794       newtCenteredWindow (60, 11, title);
    795       g_scale = newtScale (3, 6, 54, g_maximum_progress);
    796       g_progressForm = newtForm (NULL, NULL, 0);
    797       g_percentline = newtLabel (10, 9, "This is the percentline");
    798       g_timeline = newtLabel (10, 8, "This is the timeline");
    799       newtFormAddComponents (g_progressForm, g_percentline, g_timeline,
    800                  g_scale, g_blurb1, g_blurb3, g_blurb2, NULL);
    801       newtPushHelpLine (b1c);
    802       newtRefresh ();
    803     }
    804   update_progress_form_full (blurb1, blurb2, blurb3);
    805   paranoid_free(b1c);
    806   paranoid_free(blurb1);
    807   paranoid_free(blurb2);
    808   paranoid_free(blurb3);
    809 }
     603    void
     604     open_progress_form(char *title, char *b1, char *b2, char *b3,
     605                        long max_val) {
     606
     607        /*@ buffers ********************************************************* */
     608        char *b1c;
     609        char *blurb1;
     610        char *blurb2;
     611        char *blurb3;
     612
     613        /*@ initialize ****************************************************** */
     614        g_mysterious_dot_counter = 0;
     615
     616        malloc_string(b1c);
     617        malloc_string(blurb1);
     618        malloc_string(blurb2);
     619        malloc_string(blurb3);
     620
     621        assert(title != NULL);
     622        assert(b1 != NULL);
     623        assert(b2 != NULL);
     624        assert(b3 != NULL);
     625
     626        strcpy(blurb1, b1);
     627        strcpy(blurb2, b2);
     628        strcpy(blurb3, b3);
     629        strcpy(b1c, b1);
     630        center_string(b1c, 80);
     631        if (max_val <= 0) {
     632            max_val = 1;
     633        }
     634
     635        g_start_time = get_time();
     636        g_maximum_progress = max_val;
     637        g_current_progress = 0;
     638        strcpy(g_blurb_str_1, blurb1);
     639        strcpy(g_blurb_str_2, blurb3);
     640        strcpy(g_blurb_str_3, blurb2);
     641        if (g_text_mode) {
     642            log_msg(0, blurb1);
     643            log_msg(0, blurb2);
     644            log_msg(0, blurb3);
     645        } else {
     646            g_blurb1 = newtLabel(2, 1, blurb1);
     647            g_blurb2 = newtLabel(2, 2, blurb3);
     648            g_blurb3 = newtLabel(2, 4, blurb2);
     649            //      newtOpenWindow (10, 4, 60, 11, title);
     650            newtCenteredWindow(60, 11, title);
     651            g_scale = newtScale(3, 6, 54, g_maximum_progress);
     652            g_progressForm = newtForm(NULL, NULL, 0);
     653            g_percentline = newtLabel(10, 9, "This is the percentline");
     654            g_timeline = newtLabel(10, 8, "This is the timeline");
     655            newtFormAddComponents(g_progressForm, g_percentline,
     656                                  g_timeline, g_scale, g_blurb1, g_blurb3,
     657                                  g_blurb2, NULL);
     658            newtPushHelpLine(b1c);
     659            newtRefresh();
     660        }
     661        update_progress_form_full(blurb1, blurb2, blurb3);
     662        paranoid_free(b1c);
     663        paranoid_free(blurb1);
     664        paranoid_free(blurb2);
     665        paranoid_free(blurb3);
     666    }
    810667
    811668/**
     
    813670 * @param prompt The message.
    814671 */
    815 void
    816 popup_and_OK (char *prompt)
    817 {
    818     char ch;
    819 
    820   assert_string_is_neither_NULL_nor_zerolength(prompt);
    821 
    822   log_msg (0, prompt);
    823   if (g_text_mode)
    824     {
    825       printf
    826     ("---promptpopup---1--- %s\r\n---promptpopup---Q--- [OK] ---\r\n--> ", prompt);
    827       while (((ch = getchar()) != '\n') && (ch != EOF))
    828       ;
    829     }
    830   else
    831     {
    832     (void) popup_with_buttons (prompt, " OK ", "");
    833     }
    834 }
     672    void
     673     popup_and_OK(char *prompt) {
     674        char ch;
     675
     676        assert_string_is_neither_NULL_nor_zerolength(prompt);
     677
     678        log_msg(0, prompt);
     679        if (g_text_mode) {
     680            printf
     681                ("---promptpopup---1--- %s\r\n---promptpopup---Q--- [OK] ---\r\n--> ",
     682                 prompt);
     683            while (((ch = getchar()) != '\n') && (ch != EOF));
     684        } else {
     685            (void) popup_with_buttons(prompt, " OK ", "");
     686        }
     687    }
    835688
    836689/**
     
    842695 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
    843696 */
    844 bool
    845 popup_and_get_string (char *title, char *b, char *output, int maxsize)
    846 {
    847 
    848     /*@ newt *************************************************************/
    849   newtComponent myForm;
    850     newtComponent b_1;
    851     newtComponent b_2;
    852     newtComponent b_res;
    853     newtComponent text;
    854     newtComponent type_here;
    855 
    856     /*@ pointers **********************************************************/
    857   char *entry_value;
    858 
    859     /*@ buffers ***********************************************************/
    860     char *blurb;
    861     char *original_contents;
    862 
    863   blurb = malloc(MAX_NEWT_COMMENT_LEN);
    864   original_contents = malloc(MAX_NEWT_COMMENT_LEN);
    865   assert_string_is_neither_NULL_nor_zerolength(title);
    866   assert(b!=NULL);
    867   assert(output!=NULL);
    868 
    869   if (g_text_mode)
    870     {
    871       printf ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n-->  ", title, b);
    872       (void) fgets(output, maxsize, stdin);
    873       if (output[strlen (output) - 1] == '\n')
    874       output[strlen (output) - 1] = '\0';
    875       paranoid_free(blurb);
    876       paranoid_free(original_contents);
    877       return (TRUE);
    878     }
    879   strcpy (blurb, b);
    880   text = newtTextboxReflowed (2, 1, blurb, 48, 5, 5, 0);
    881   strcpy (original_contents, output);
    882   output[0] = '\0';
    883   type_here =
    884     newtEntry (2, newtTextboxGetNumLines (text) + 2, original_contents, 50,
     697    bool popup_and_get_string(char *title, char *b, char *output,
     698                              int maxsize) {
     699
     700        /*@ newt ************************************************************ */
     701        newtComponent myForm;
     702        newtComponent b_1;
     703        newtComponent b_2;
     704        newtComponent b_res;
     705        newtComponent text;
     706        newtComponent type_here;
     707
     708        /*@ pointers ********************************************************* */
     709        char *entry_value;
     710
     711        /*@ buffers ********************************************************** */
     712        char *blurb;
     713        char *original_contents;
     714
     715        blurb = malloc(MAX_NEWT_COMMENT_LEN);
     716        original_contents = malloc(MAX_NEWT_COMMENT_LEN);
     717        assert_string_is_neither_NULL_nor_zerolength(title);
     718        assert(b != NULL);
     719        assert(output != NULL);
     720
     721        if (g_text_mode) {
     722            printf
     723                ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n-->  ",
     724                 title, b);
     725            (void) fgets(output, maxsize, stdin);
     726            if (output[strlen(output) - 1] == '\n')
     727                output[strlen(output) - 1] = '\0';
     728            paranoid_free(blurb);
     729            paranoid_free(original_contents);
     730            return (TRUE);
     731        }
     732        strcpy(blurb, b);
     733        text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);
     734        strcpy(original_contents, output);
     735        output[0] = '\0';
     736        type_here =
     737            newtEntry(2, newtTextboxGetNumLines(text) + 2,
     738                      original_contents, 50,
    885739#ifdef __cplusplus
    886            0, NEWT_FLAG_RETURNEXIT
     740                      0, NEWT_FLAG_RETURNEXIT
    887741#else
    888            (void*)&entry_value, NEWT_FLAG_RETURNEXIT
     742                      (void *) &entry_value, NEWT_FLAG_RETURNEXIT
    889743#endif
    890            );
    891   b_1 = newtButton (6, newtTextboxGetNumLines (text) + 4, "  OK  ");
    892   b_2 = newtButton (18, newtTextboxGetNumLines (text) + 4, "Cancel");
    893   //  newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);
    894   newtCenteredWindow (54, newtTextboxGetNumLines (text) + 9, title);
    895   myForm = newtForm (NULL, NULL, 0);
    896   newtFormAddComponents (myForm, text, type_here, b_1, b_2, NULL);
    897   center_string (blurb, 80);
    898   newtPushHelpLine (blurb);
    899   b_res = newtRunForm (myForm);
    900   strcpy (output, entry_value);
    901   newtPopHelpLine ();
    902   newtFormDestroy (myForm);
    903   newtPopWindow ();
    904   if (b_res == b_2)
    905     {
    906       strcpy (output, original_contents);
    907       paranoid_free(blurb);
    908       paranoid_free(original_contents);
    909       return (FALSE);
    910     }
    911   else
    912     {
    913       paranoid_free(blurb);
    914       paranoid_free(original_contents);
    915       return (TRUE);
    916     }
    917 }
     744            );
     745        b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, "  OK  ");
     746        b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel");
     747        //  newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);
     748        newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
     749        myForm = newtForm(NULL, NULL, 0);
     750        newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL);
     751        center_string(blurb, 80);
     752        newtPushHelpLine(blurb);
     753        b_res = newtRunForm(myForm);
     754        strcpy(output, entry_value);
     755        newtPopHelpLine();
     756        newtFormDestroy(myForm);
     757        newtPopWindow();
     758        if (b_res == b_2) {
     759            strcpy(output, original_contents);
     760            paranoid_free(blurb);
     761            paranoid_free(original_contents);
     762            return (FALSE);
     763        } else {
     764            paranoid_free(blurb);
     765            paranoid_free(original_contents);
     766            return (TRUE);
     767        }
     768    }
    918769
    919770
     
    925776 * @return TRUE if @p button1 was pushed, FALSE otherwise.
    926777 */
    927 bool
    928 popup_with_buttons (char *p, char *button1, char *button2)
    929 {
    930 
    931     /*@ buffers ************************************************************/
    932   char *prompt, *tmp;
    933 
    934     /*@ newt ***************************************************************/
    935   newtComponent myForm;
    936     newtComponent b_1;
    937     newtComponent b_2;
    938     newtComponent b_res;
    939     newtComponent text;
    940  
    941   prompt = malloc(MAX_NEWT_COMMENT_LEN);
    942   tmp = malloc(MAX_NEWT_COMMENT_LEN);
    943   assert_string_is_neither_NULL_nor_zerolength(p);
    944   assert(button1!=NULL);
    945   assert(button2!=NULL);
    946   if (g_text_mode)
    947     {
    948       if (strlen(button2)==0)
    949         { printf("%s (%s) --> ", p, button1); }
    950       else
    951         { printf("%s (%s or %s) --> ", p, button1, button2); }
    952       for(tmp[0]='\0'; strcmp(tmp, button1) && (strlen(button2)==0 || strcmp(tmp, button2)); )
    953         {
    954           printf("--> ");
    955           (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
    956         }
    957       if (!strcmp(tmp, button1)) { paranoid_free(tmp); paranoid_free(prompt); return(TRUE); }
    958       else { paranoid_free(tmp); paranoid_free(prompt); return(FALSE); }
    959     }
    960 
    961   strcpy (prompt, p);
    962   text = newtTextboxReflowed (1, 1, prompt, 40, 5, 5, 0);
    963   b_1 =
    964     newtButton (20 -
    965         ((button2[0] !=
    966           '\0') ? strlen (button1) + 2 : strlen (button1) / 2),
    967         newtTextboxGetNumLines (text) + 3, button1);
    968   if (button2[0] != '\0')
    969     {
    970       b_2 = newtButton (24, newtTextboxGetNumLines (text) + 3, button2);
    971     }
    972   else
    973     {
    974       b_2 = NULL;
    975     }
    976   //  newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert");
    977   newtCenteredWindow (46, newtTextboxGetNumLines (text) + 7, "Alert");
    978   myForm = newtForm (NULL, NULL, 0);
    979   newtFormAddComponents (myForm, text, b_1, b_2, NULL);
    980   center_string (prompt, 80);
    981   newtPushHelpLine (prompt);
    982   b_res = newtRunForm (myForm);
    983   newtPopHelpLine ();
    984   newtFormDestroy (myForm);
    985   newtPopWindow ();
    986   if (b_res == b_1)
    987     {
    988 paranoid_free(tmp); paranoid_free(prompt);       return (TRUE);
    989     }
    990   else
    991     {
    992 paranoid_free(tmp); paranoid_free(prompt);       return (FALSE);
    993     }
    994 }
     778    bool popup_with_buttons(char *p, char *button1, char *button2) {
     779
     780        /*@ buffers *********************************************************** */
     781        char *prompt, *tmp;
     782
     783        /*@ newt ************************************************************** */
     784        newtComponent myForm;
     785        newtComponent b_1;
     786        newtComponent b_2;
     787        newtComponent b_res;
     788        newtComponent text;
     789
     790        prompt = malloc(MAX_NEWT_COMMENT_LEN);
     791        tmp = malloc(MAX_NEWT_COMMENT_LEN);
     792        assert_string_is_neither_NULL_nor_zerolength(p);
     793        assert(button1 != NULL);
     794        assert(button2 != NULL);
     795        if (g_text_mode) {
     796            if (strlen(button2) == 0) {
     797                printf("%s (%s) --> ", p, button1);
     798            } else {
     799                printf("%s (%s or %s) --> ", p, button1, button2);
     800            }
     801            for (tmp[0] = '\0';
     802                 strcmp(tmp, button1) && (strlen(button2) == 0
     803                                          || strcmp(tmp, button2));) {
     804                printf("--> ");
     805                (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
     806            }
     807            if (!strcmp(tmp, button1)) {
     808                paranoid_free(tmp);
     809                paranoid_free(prompt);
     810                return (TRUE);
     811            } else {
     812                paranoid_free(tmp);
     813                paranoid_free(prompt);
     814                return (FALSE);
     815            }
     816        }
     817
     818        strcpy(prompt, p);
     819        text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0);
     820        b_1 =
     821            newtButton(20 -
     822                       ((button2[0] !=
     823                         '\0') ? strlen(button1) +
     824                        2 : strlen(button1) / 2),
     825                       newtTextboxGetNumLines(text) + 3, button1);
     826        if (button2[0] != '\0') {
     827            b_2 =
     828                newtButton(24, newtTextboxGetNumLines(text) + 3, button2);
     829        } else {
     830            b_2 = NULL;
     831        }
     832        //  newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert");
     833        newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, "Alert");
     834        myForm = newtForm(NULL, NULL, 0);
     835        newtFormAddComponents(myForm, text, b_1, b_2, NULL);
     836        center_string(prompt, 80);
     837        newtPushHelpLine(prompt);
     838        b_res = newtRunForm(myForm);
     839        newtPopHelpLine();
     840        newtFormDestroy(myForm);
     841        newtPopWindow();
     842        if (b_res == b_1) {
     843            paranoid_free(tmp);
     844            paranoid_free(prompt);
     845            return (TRUE);
     846        } else {
     847            paranoid_free(tmp);
     848            paranoid_free(prompt);
     849            return (FALSE);
     850        }
     851    }
    995852
    996853
     
    1001858 * on the screen.
    1002859 */
    1003 void
    1004 refresh_log_screen ()
    1005 {
    1006 
    1007     /*@ int ************************************************************/
    1008   int i = 0;
    1009 
    1010 
    1011   if (g_text_mode || !err_log_lines)
    1012     {
    1013       return;
    1014     }
    1015   for (i = g_noof_log_lines - 1; i >= 0; i--)
    1016     {
    1017       newtDrawRootText (0, i + g_noof_rows - 1 - g_noof_log_lines,
    1018 "                                                                                ");
    1019     }
    1020   newtRefresh ();
    1021   for (i = g_noof_log_lines - 1; i >= 0; i--)
    1022     {
    1023       err_log_lines[i][79] = '\0';
    1024       newtDrawRootText (0, i + g_noof_rows - 1 - g_noof_log_lines, err_log_lines[i]);
    1025     }
    1026   newtRefresh ();
    1027 }
     860    void
     861     refresh_log_screen() {
     862
     863        /*@ int *********************************************************** */
     864        int i = 0;
     865
     866
     867        if (g_text_mode || !err_log_lines) {
     868            return;
     869        }
     870        for (i = g_noof_log_lines - 1; i >= 0; i--) {
     871            newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines,
     872                             "                                                                                ");
     873        }
     874        newtRefresh();
     875        for (i = g_noof_log_lines - 1; i >= 0; i--) {
     876            err_log_lines[i][79] = '\0';
     877            newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines,
     878                             err_log_lines[i]);
     879        }
     880        newtRefresh();
     881    }
    1028882
    1029883
     
    1032886 * only allocate some memory.
    1033887 */
    1034 void
    1035 setup_newt_stuff ()
    1036 {
    1037 
    1038     /*@ int ************************************************************/
    1039   int i = 0;
    1040   int cols;
    1041 
    1042   if (!g_text_mode)
    1043     {
    1044       newtInit();
    1045       newtCls();
    1046       newtPushHelpLine
    1047     ("Welcome to Mondo Rescue, by Hugo Rabson and the Internet. All rights reversed.");
    1048       /*  newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */
    1049       newtDrawRootText (18, 0, WELCOME_STRING);
    1050       newtRefresh();
    1051       newtGetScreenSize (&cols, &g_noof_rows);
    1052       g_noof_log_lines = (g_noof_rows / 5) + 1;
    1053     }
    1054 
    1055   err_log_lines = (char **) malloc (sizeof (char *) * g_noof_log_lines);
    1056   if (!err_log_lines) {
    1057     fatal_error ("Out of memory");
    1058   }
    1059 
    1060   for (i = 0; i < g_noof_log_lines; i++) {
    1061     err_log_lines[i] = (char *) malloc (MAX_NEWT_COMMENT_LEN);
    1062     if (!err_log_lines[i]) {
    1063       fatal_error ("Out of memory");
    1064     }
    1065   }
    1066 
    1067   for (i = 0; i < g_noof_log_lines; i++)
    1068     {
    1069       err_log_lines[i][0] = '\0';
    1070     }
    1071 }
     888    void
     889     setup_newt_stuff() {
     890
     891        /*@ int *********************************************************** */
     892        int i = 0;
     893        int cols;
     894
     895        if (!g_text_mode) {
     896            newtInit();
     897            newtCls();
     898            newtPushHelpLine
     899                ("Welcome to Mondo Rescue, by Hugo Rabson and the Internet. All rights reversed.");
     900            /*  newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */
     901            newtDrawRootText(18, 0, WELCOME_STRING);
     902            newtRefresh();
     903            newtGetScreenSize(&cols, &g_noof_rows);
     904            g_noof_log_lines = (g_noof_rows / 5) + 1;
     905        }
     906
     907        err_log_lines =
     908            (char **) malloc(sizeof(char *) * g_noof_log_lines);
     909        if (!err_log_lines) {
     910            fatal_error("Out of memory");
     911        }
     912
     913        for (i = 0; i < g_noof_log_lines; i++) {
     914            err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN);
     915            if (!err_log_lines[i]) {
     916                fatal_error("Out of memory");
     917            }
     918        }
     919
     920        for (i = 0; i < g_noof_log_lines; i++) {
     921            err_log_lines[i][0] = '\0';
     922        }
     923    }
    1072924
    1073925
     
    1077929 * @param denom The denomenator of the ratio.
    1078930 */
    1079 void
    1080 update_evalcall_form_ratio (int num, int denom)
    1081 {
    1082 
    1083     /*@ long *************************************************************/
    1084   long current_time = 0;
    1085     long time_taken = 0;
    1086     long time_total_est = 0;
    1087     long time_remaining = 0;
    1088 
    1089     /*@ buffers ***********************************************************/
    1090   char *timeline_str;
    1091     char *pcline_str;
    1092     char *taskprogress;
    1093 
    1094     /*@ int ***************************************************************/
    1095   int percentage = 0;
    1096     int i = 0;
    1097     int j = 0;
    1098 
    1099   malloc_string(timeline_str);
    1100   malloc_string(pcline_str);
    1101   malloc_string(taskprogress);
    1102   timeline_str[0] = '\0';
     931    void
     932     update_evalcall_form_ratio(int num, int denom) {
     933
     934        /*@ long ************************************************************ */
     935        long current_time = 0;
     936        long time_taken = 0;
     937        long time_total_est = 0;
     938        long time_remaining = 0;
     939
     940        /*@ buffers ********************************************************** */
     941        char *timeline_str;
     942        char *pcline_str;
     943        char *taskprogress;
     944
     945        /*@ int ************************************************************** */
     946        int percentage = 0;
     947        int i = 0;
     948        int j = 0;
     949
     950        malloc_string(timeline_str);
     951        malloc_string(pcline_str);
     952        malloc_string(taskprogress);
     953        timeline_str[0] = '\0';
    1103954//  log_it("update_eval_call_form called");
    1104   if (num * 100 < denom)
    1105     {
    1106       percentage = 1;
    1107     }
    1108   else
    1109     {
    1110       percentage = (num * 100 + denom / 2) / denom ;
    1111     }
    1112    
    1113   current_time = get_time ();
    1114   time_taken = current_time - g_isoform_starttime;
    1115   if (num)
    1116     {
    1117       time_total_est = time_taken * denom / num;
    1118       time_remaining = time_total_est - time_taken;
    1119     }
    1120   else
    1121     {
    1122       time_remaining = 0;
    1123     }
    1124   if (!g_text_mode)
    1125     {
    1126       newtLabelSetText (g_isoform_header, g_isoform_header_str);
    1127     }
    1128   g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
    1129   if ((percentage < 3 && g_isoform_old_progress < 3)
    1130       || percentage > g_isoform_old_progress)
    1131     {
    1132       g_isoform_old_progress = percentage;
    1133       sprintf (timeline_str,
    1134            "%2ld:%02ld taken            %2ld:%02ld remaining",
    1135            time_taken / 60, time_taken % 60, time_remaining / 60,
    1136            time_remaining % 60);
    1137       if (percentage < 3)
    1138     {
    1139       sprintf (pcline_str, " Working");
    1140       for (j = 0; j < g_mysterious_dot_counter; j++)
    1141         {
    1142           strcat (pcline_str, ".");
    1143         }
    1144       for (; j < 27; j++)
    1145         {
    1146           strcat (pcline_str, " ");
    1147         }
    1148       sprintf (pcline_str + strlen (pcline_str), " %c",
    1149            special_dot_char (g_mysterious_dot_counter));
    1150     }
    1151       else
    1152     {
    1153       sprintf (pcline_str, " %3d%% done              %3d%% to go",
    1154            percentage, 100 - percentage);
    1155     }
    1156       if (g_text_mode)
    1157     {
    1158       sprintf (taskprogress, "TASK:  [");
    1159       for (i = 0; i < percentage; i += 5)
    1160         {
    1161           strcat (taskprogress, "*");
    1162         }
    1163       for (; i < 100; i += 5)
    1164         {
    1165           strcat (taskprogress, ".");
    1166         }
    1167       if (percentage >= 3)
    1168         {
    1169           sprintf (taskprogress + strlen (taskprogress),
    1170                "] %3d%% done; %2ld:%02ld to go", percentage,
    1171                time_remaining / 60, time_remaining % 60);
    1172               printf ("---evalcall---1--- %s\r\n", g_isoform_header_str);
    1173           printf ("---evalcall---2--- %s\r\n", taskprogress);
    1174               printf ("---evalcall---E---\r\n");
    1175         }
    1176     }
    1177       else
    1178     {
    1179       newtScaleSet (g_isoform_scale, (unsigned long long) percentage);
    1180       newtLabelSetText (g_isoform_pcline, pcline_str);
    1181       if (percentage >= 3)
    1182         {
    1183           newtLabelSetText (g_isoform_timeline, timeline_str);
    1184         }
    1185     }
    1186     }
    1187   if (!g_text_mode)
    1188     {
     955        if (num * 100 < denom) {
     956            percentage = 1;
     957        } else {
     958            percentage = (num * 100 + denom / 2) / denom;
     959        }
     960
     961        current_time = get_time();
     962        time_taken = current_time - g_isoform_starttime;
     963        if (num) {
     964            time_total_est = time_taken * denom / num;
     965            time_remaining = time_total_est - time_taken;
     966        } else {
     967            time_remaining = 0;
     968        }
     969        if (!g_text_mode) {
     970            newtLabelSetText(g_isoform_header, g_isoform_header_str);
     971        }
     972        g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
     973        if ((percentage < 3 && g_isoform_old_progress < 3)
     974            || percentage > g_isoform_old_progress) {
     975            g_isoform_old_progress = percentage;
     976            sprintf(timeline_str,
     977                    "%2ld:%02ld taken            %2ld:%02ld remaining",
     978                    time_taken / 60, time_taken % 60, time_remaining / 60,
     979                    time_remaining % 60);
     980            if (percentage < 3) {
     981                sprintf(pcline_str, " Working");
     982                for (j = 0; j < g_mysterious_dot_counter; j++) {
     983                    strcat(pcline_str, ".");
     984                }
     985                for (; j < 27; j++) {
     986                    strcat(pcline_str, " ");
     987                }
     988                sprintf(pcline_str + strlen(pcline_str), " %c",
     989                        special_dot_char(g_mysterious_dot_counter));
     990            } else {
     991                sprintf(pcline_str, " %3d%% done              %3d%% to go",
     992                        percentage, 100 - percentage);
     993            }
     994            if (g_text_mode) {
     995                sprintf(taskprogress, "TASK:  [");
     996                for (i = 0; i < percentage; i += 5) {
     997                    strcat(taskprogress, "*");
     998                }
     999                for (; i < 100; i += 5) {
     1000                    strcat(taskprogress, ".");
     1001                }
     1002                if (percentage >= 3) {
     1003                    sprintf(taskprogress + strlen(taskprogress),
     1004                            "] %3d%% done; %2ld:%02ld to go", percentage,
     1005                            time_remaining / 60, time_remaining % 60);
     1006                    printf("---evalcall---1--- %s\r\n",
     1007                           g_isoform_header_str);
     1008                    printf("---evalcall---2--- %s\r\n", taskprogress);
     1009                    printf("---evalcall---E---\r\n");
     1010                }
     1011            } else {
     1012                newtScaleSet(g_isoform_scale,
     1013                             (unsigned long long) percentage);
     1014                newtLabelSetText(g_isoform_pcline, pcline_str);
     1015                if (percentage >= 3) {
     1016                    newtLabelSetText(g_isoform_timeline, timeline_str);
     1017                }
     1018            }
     1019        }
     1020        if (!g_text_mode) {
    11891021//      log_it("refreshing");
    1190       newtRefresh ();
    1191     }
    1192   paranoid_free(timeline_str);
    1193   paranoid_free(pcline_str);
    1194   paranoid_free(taskprogress);
    1195 }
     1022            newtRefresh();
     1023        }
     1024        paranoid_free(timeline_str);
     1025        paranoid_free(pcline_str);
     1026        paranoid_free(taskprogress);
     1027    }
    11961028
    11971029
     
    12011033 * @param curr The current amount of progress (percentage) in the evalcall form.
    12021034 */
    1203 void
    1204 update_evalcall_form (int curr)
    1205 {
    1206   update_evalcall_form_ratio (curr, 100);
    1207 }
     1035    void
     1036     update_evalcall_form(int curr) {
     1037        update_evalcall_form_ratio(curr, 100);
     1038    }
    12081039
    12091040
     
    12141045 * @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.
    12151046 */
    1216 void
    1217 update_progress_form (char *blurb3)
    1218 {
    1219   /*  log_it("update_progress_form --- called"); */
    1220   if (g_current_progress == -999)
    1221     {
    1222       /* 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."); */
    1223       return;
    1224     }
    1225   strcpy (g_blurb_str_2, blurb3);
    1226   update_progress_form_full (g_blurb_str_1, g_blurb_str_2, g_blurb_str_3);
    1227 }
     1047    void
     1048     update_progress_form(char *blurb3) {
     1049        /*  log_it("update_progress_form --- called"); */
     1050        if (g_current_progress == -999) {
     1051            /* 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."); */
     1052            return;
     1053        }
     1054        strcpy(g_blurb_str_2, blurb3);
     1055        update_progress_form_full(g_blurb_str_1, g_blurb_str_2,
     1056                                  g_blurb_str_3);
     1057    }
    12281058
    12291059
     
    12341064 * @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.
    12351065 */
    1236 void
    1237 update_progress_form_full (char *blurb1, char *blurb2, char *blurb3)
    1238 {
    1239     /*@ long ******************************************************/
    1240   long current_time = 0;
    1241     long time_taken = 0;
    1242     long time_remaining = 0;
    1243     long time_total_est = 0;
    1244 
    1245     /*@ int ********************************************************/
    1246   int percentage = 0;
    1247     int i = 0;
    1248 
    1249     /*@ buffers ****************************************************/
    1250   char *percentline_str;
    1251     char *timeline_str;
    1252     char *taskprogress;
    1253     char *tmp;
     1066    void
     1067     update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) {
     1068        /*@ long ***************************************************** */
     1069        long current_time = 0;
     1070        long time_taken = 0;
     1071        long time_remaining = 0;
     1072        long time_total_est = 0;
     1073
     1074        /*@ int ******************************************************* */
     1075        int percentage = 0;
     1076        int i = 0;
     1077
     1078        /*@ buffers *************************************************** */
     1079        char *percentline_str;
     1080        char *timeline_str;
     1081        char *taskprogress;
     1082        char *tmp;
    12541083
    12551084//  log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3);
    1256   percentline_str = malloc(MAX_NEWT_COMMENT_LEN);
    1257   timeline_str = malloc(MAX_NEWT_COMMENT_LEN);
    1258   taskprogress = malloc(MAX_NEWT_COMMENT_LEN);
    1259   malloc_string(tmp);
    1260   if (!g_text_mode)
    1261     {
    1262       assert(blurb1!=NULL);
    1263       assert(blurb2!=NULL);
    1264       assert(blurb3!=NULL);
    1265       assert(g_timeline!=NULL);
    1266     }
    1267 
    1268   percentline_str[0] = '\0';
    1269 
    1270   current_time = get_time ();
    1271   time_taken = current_time - g_start_time;
    1272   if (g_maximum_progress == 0)
    1273     {
    1274       percentage = 0;
    1275     }
    1276   else
    1277     {
    1278       if (g_current_progress > g_maximum_progress)
    1279     {
    1280       sprintf (tmp,
    1281            "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld",
    1282            blurb1, blurb2, blurb3, g_current_progress,
    1283            g_maximum_progress);
    1284       log_msg (0, tmp);
    1285       g_current_progress = g_maximum_progress;
    1286     }
    1287       percentage = (int) ((g_current_progress * 100L) / g_maximum_progress);
    1288     }
    1289   if (percentage < 1)
    1290     {
    1291       percentage = 1;
    1292     }
    1293   if (percentage > 100)
    1294     {
    1295       percentage = 100;
    1296     }
    1297   if (g_current_progress)
    1298     {
    1299       time_total_est = time_taken * (long) g_maximum_progress / (long) (g_current_progress);
    1300       time_remaining = time_total_est - time_taken;
    1301     }
    1302   else
    1303     {
    1304       time_remaining = 0;
    1305     }
    1306   g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
    1307   sprintf (timeline_str,
    1308        "%2ld:%02ld taken               %2ld:%02ld remaining  ",
    1309        time_taken / 60, time_taken % 60, time_remaining / 60,
    1310        time_remaining % 60);
    1311   sprintf (percentline_str, " %3d%% done                 %3d%% to go",
    1312        percentage, 100 - percentage);
    1313 
    1314   if (g_text_mode)
    1315     {
    1316       printf("---progress-form---1--- %s\r\n", blurb1);
    1317       printf("---progress-form---2--- %s\r\n", blurb2);
    1318       printf("---progress-form---3--- %s\r\n", blurb3);
    1319       printf("---progress-form---E---\n");
    1320       sprintf (taskprogress, "TASK:  [");
    1321       for (i = 0; i < percentage; i += 5)
    1322     {
    1323       strcat (taskprogress, "*");
    1324     }
    1325       for (; i < 100; i += 5)
    1326     {
    1327       strcat (taskprogress, ".");
    1328     }
    1329       if (percentage>100) { log_msg(2, "percentage = %d", percentage); }
    1330       sprintf (taskprogress + strlen (taskprogress),
    1331            "] %3d%c", percentage, '%');
    1332       sprintf (taskprogress + strlen (taskprogress),
    1333         " done; %2ld:%02ld to go",
    1334         time_remaining / 60, time_remaining % 60);
    1335       printf("---progress-form---4--- %s\r\n", taskprogress);
    1336     }
    1337   else
    1338     {
    1339       center_string (blurb1, 54);
    1340       center_string (blurb2, 54);
    1341       center_string (blurb3, 54);
    1342       newtLabelSetText (g_blurb1, blurb1);
    1343       newtLabelSetText (g_blurb2, blurb3);
    1344       newtLabelSetText (g_blurb3, blurb2);
    1345           newtScaleSet (g_scale, (unsigned long long) g_current_progress);
    1346       if (percentage >= 2)
    1347     {
    1348       newtLabelSetText (g_timeline, timeline_str);
    1349     }
    1350       newtLabelSetText (g_percentline, percentline_str);
    1351       newtRefresh ();
    1352     }
    1353   paranoid_free(percentline_str);
    1354   paranoid_free(timeline_str);
    1355   paranoid_free(taskprogress);
    1356   paranoid_free(tmp);
    1357 }
     1085        percentline_str = malloc(MAX_NEWT_COMMENT_LEN);
     1086        timeline_str = malloc(MAX_NEWT_COMMENT_LEN);
     1087        taskprogress = malloc(MAX_NEWT_COMMENT_LEN);
     1088        malloc_string(tmp);
     1089        if (!g_text_mode) {
     1090            assert(blurb1 != NULL);
     1091            assert(blurb2 != NULL);
     1092            assert(blurb3 != NULL);
     1093            assert(g_timeline != NULL);
     1094        }
     1095
     1096        percentline_str[0] = '\0';
     1097
     1098        current_time = get_time();
     1099        time_taken = current_time - g_start_time;
     1100        if (g_maximum_progress == 0) {
     1101            percentage = 0;
     1102        } else {
     1103            if (g_current_progress > g_maximum_progress) {
     1104                sprintf(tmp,
     1105                        "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld",
     1106                        blurb1, blurb2, blurb3, g_current_progress,
     1107                        g_maximum_progress);
     1108                log_msg(0, tmp);
     1109                g_current_progress = g_maximum_progress;
     1110            }
     1111            percentage =
     1112                (int) ((g_current_progress * 100L) / g_maximum_progress);
     1113        }
     1114        if (percentage < 1) {
     1115            percentage = 1;
     1116        }
     1117        if (percentage > 100) {
     1118            percentage = 100;
     1119        }
     1120        if (g_current_progress) {
     1121            time_total_est =
     1122                time_taken * (long) g_maximum_progress /
     1123                (long) (g_current_progress);
     1124            time_remaining = time_total_est - time_taken;
     1125        } else {
     1126            time_remaining = 0;
     1127        }
     1128        g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
     1129        sprintf(timeline_str,
     1130                "%2ld:%02ld taken               %2ld:%02ld remaining  ",
     1131                time_taken / 60, time_taken % 60, time_remaining / 60,
     1132                time_remaining % 60);
     1133        sprintf(percentline_str, " %3d%% done                 %3d%% to go",
     1134                percentage, 100 - percentage);
     1135
     1136        if (g_text_mode) {
     1137            printf("---progress-form---1--- %s\r\n", blurb1);
     1138            printf("---progress-form---2--- %s\r\n", blurb2);
     1139            printf("---progress-form---3--- %s\r\n", blurb3);
     1140            printf("---progress-form---E---\n");
     1141            sprintf(taskprogress, "TASK:  [");
     1142            for (i = 0; i < percentage; i += 5) {
     1143                strcat(taskprogress, "*");
     1144            }
     1145            for (; i < 100; i += 5) {
     1146                strcat(taskprogress, ".");
     1147            }
     1148            if (percentage > 100) {
     1149                log_msg(2, "percentage = %d", percentage);
     1150            }
     1151            sprintf(taskprogress + strlen(taskprogress),
     1152                    "] %3d%c", percentage, '%');
     1153            sprintf(taskprogress + strlen(taskprogress),
     1154                    " done; %2ld:%02ld to go",
     1155                    time_remaining / 60, time_remaining % 60);
     1156            printf("---progress-form---4--- %s\r\n", taskprogress);
     1157        } else {
     1158            center_string(blurb1, 54);
     1159            center_string(blurb2, 54);
     1160            center_string(blurb3, 54);
     1161            newtLabelSetText(g_blurb1, blurb1);
     1162            newtLabelSetText(g_blurb2, blurb3);
     1163            newtLabelSetText(g_blurb3, blurb2);
     1164            newtScaleSet(g_scale, (unsigned long long) g_current_progress);
     1165            if (percentage >= 2) {
     1166                newtLabelSetText(g_timeline, timeline_str);
     1167            }
     1168            newtLabelSetText(g_percentline, percentline_str);
     1169            newtRefresh();
     1170        }
     1171        paranoid_free(percentline_str);
     1172        paranoid_free(timeline_str);
     1173        paranoid_free(taskprogress);
     1174        paranoid_free(tmp);
     1175    }
    13581176
    13591177
     
    13781196 * @return The backup type chosen, or @c none if the user chose "Exit to shell".
    13791197 */
    1380 t_bkptype
    1381 which_backup_media_type (bool restoring)
    1382 {
    1383 
    1384     /*@ char *************************************************************/
    1385       t_bkptype output;
    1386 
    1387 
    1388     /*@ newt *************************************************************/
    1389   char *title_sz;
    1390   char *minimsg_sz;
    1391   static t_bkptype possible_bkptypes[] = { none,cdr,cdrw,dvd,tape,cdstream,udev,nfs,iso };
    1392   static char *possible_responses[] = {"none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", "nfs", "iso", NULL };
    1393   char *outstr;
    1394   t_bkptype backup_type;
    1395   int i;
    1396 
    1397   newtComponent b1;
    1398     newtComponent b2;
    1399     newtComponent b3;
    1400     newtComponent b4;
    1401     newtComponent b5;
    1402     newtComponent b6;
    1403     newtComponent b7;
    1404     newtComponent b8;
    1405     newtComponent b_res;
    1406     newtComponent myForm;
    1407 
    1408   title_sz = malloc(MAX_NEWT_COMMENT_LEN);
    1409   minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN);
    1410   outstr = malloc(MAX_NEWT_COMMENT_LEN);
    1411   if (g_text_mode)
    1412     {
    1413       for(backup_type = none; backup_type == none; )
    1414         {
    1415           printf("Backup type (");
    1416           for(i=0; possible_responses[i]; i++)
    1417             {
    1418               printf("%c%s", (i==0)?'\0':' ', possible_responses[i]);
    1419             }
    1420           printf(")\n--> ");
    1421           (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);
    1422           strip_spaces(outstr);
    1423           for(i=0; possible_responses[i]; i++)
    1424             {
    1425               if (!strcmp(possible_responses[i], outstr))
    1426                 { backup_type = possible_bkptypes[i]; }
    1427             }
    1428         }
    1429   paranoid_free(title_sz);
    1430   paranoid_free(minimsg_sz);
    1431   paranoid_free(outstr);
    1432       return(backup_type);
    1433     }
    1434   newtDrawRootText (18, 0, WELCOME_STRING);
    1435   if (restoring)
    1436     {
    1437       strcpy(title_sz, "Please choose the backup media from which you want to read data.");
    1438       strcpy(minimsg_sz, "Read from:");
    1439     }
    1440   else
    1441     {
    1442       strcpy(title_sz, "Please choose the backup media to which you want to archive data.");
    1443       strcpy(minimsg_sz, "Backup to:");
    1444     }
    1445   newtPushHelpLine (title_sz);
    1446   //  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
    1447   newtCenteredWindow (34, 17, minimsg_sz);
    1448   b1 = newtButton ( 1, 1, "CD-R disks ");
    1449   b2 = newtButton (17, 1, "CD-RW disks");
    1450   b3 = newtButton ( 1, 9, "Tape drive ");
    1451   b4 = newtButton (17, 5, "CD streamer");
    1452   b5 = newtButton ( 1, 5, " DVD disks ");
    1453   b6 = newtButton (17, 9, " NFS mount ");
    1454   b7 = newtButton ( 1,13, " Hard disk ");
    1455   b8 = newtButton (17,13, "    Exit   ");
    1456   myForm = newtForm (NULL, NULL, 0);
    1457   newtFormAddComponents (myForm, b1, b5, b3, b7, b2, b4, b6, b8, NULL);
    1458   b_res = newtRunForm (myForm);
    1459   newtFormDestroy (myForm);
    1460   newtPopWindow ();
    1461   if (b_res == b1)      { output = cdr; }
    1462   else if (b_res == b2) { output = cdrw; }
    1463   else if (b_res == b3) { output = tape; }
    1464   else if (b_res == b4) { output = cdstream; }
    1465   else if (b_res == b5) { output = dvd; }
    1466   else if (b_res == b6) { output = nfs; }
    1467   else if (b_res == b7) { output = iso; }
    1468   else { output = none; }
    1469   newtPopHelpLine ();
    1470   paranoid_free(title_sz);
    1471   paranoid_free(minimsg_sz);
    1472   paranoid_free(outstr);
    1473   return (output);
    1474 }
     1198    t_bkptype which_backup_media_type(bool restoring) {
     1199
     1200        /*@ char ************************************************************ */
     1201        t_bkptype output;
     1202
     1203
     1204        /*@ newt ************************************************************ */
     1205        char *title_sz;
     1206        char *minimsg_sz;
     1207        static t_bkptype possible_bkptypes[] =
     1208            { none, cdr, cdrw, dvd, tape, cdstream, udev, nfs, iso };
     1209        static char *possible_responses[] =
     1210            { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev",
     1211"nfs", "iso", NULL };
     1212        char *outstr;
     1213        t_bkptype backup_type;
     1214        int i;
     1215
     1216        newtComponent b1;
     1217        newtComponent b2;
     1218        newtComponent b3;
     1219        newtComponent b4;
     1220        newtComponent b5;
     1221        newtComponent b6;
     1222        newtComponent b7;
     1223        newtComponent b8;
     1224        newtComponent b_res;
     1225        newtComponent myForm;
     1226
     1227        title_sz = malloc(MAX_NEWT_COMMENT_LEN);
     1228        minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN);
     1229        outstr = malloc(MAX_NEWT_COMMENT_LEN);
     1230        if (g_text_mode) {
     1231            for (backup_type = none; backup_type == none;) {
     1232                printf("Backup type (");
     1233                for (i = 0; possible_responses[i]; i++) {
     1234                    printf("%c%s", (i == 0) ? '\0' : ' ',
     1235                           possible_responses[i]);
     1236                }
     1237                printf(")\n--> ");
     1238                (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);
     1239                strip_spaces(outstr);
     1240                for (i = 0; possible_responses[i]; i++) {
     1241                    if (!strcmp(possible_responses[i], outstr)) {
     1242                        backup_type = possible_bkptypes[i];
     1243                    }
     1244                }
     1245            }
     1246            paranoid_free(title_sz);
     1247            paranoid_free(minimsg_sz);
     1248            paranoid_free(outstr);
     1249            return (backup_type);
     1250        }
     1251        newtDrawRootText(18, 0, WELCOME_STRING);
     1252        if (restoring) {
     1253            strcpy(title_sz,
     1254                   "Please choose the backup media from which you want to read data.");
     1255            strcpy(minimsg_sz, "Read from:");
     1256        } else {
     1257            strcpy(title_sz,
     1258                   "Please choose the backup media to which you want to archive data.");
     1259            strcpy(minimsg_sz, "Backup to:");
     1260        }
     1261        newtPushHelpLine(title_sz);
     1262        //  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
     1263        newtCenteredWindow(34, 17, minimsg_sz);
     1264        b1 = newtButton(1, 1, "CD-R disks ");
     1265        b2 = newtButton(17, 1, "CD-RW disks");
     1266        b3 = newtButton(1, 9, "Tape drive ");
     1267        b4 = newtButton(17, 5, "CD streamer");
     1268        b5 = newtButton(1, 5, " DVD disks ");
     1269        b6 = newtButton(17, 9, " NFS mount ");
     1270        b7 = newtButton(1, 13, " Hard disk ");
     1271        b8 = newtButton(17, 13, "    Exit   ");
     1272        myForm = newtForm(NULL, NULL, 0);
     1273        newtFormAddComponents(myForm, b1, b5, b3, b7, b2, b4, b6, b8,
     1274                              NULL);
     1275        b_res = newtRunForm(myForm);
     1276        newtFormDestroy(myForm);
     1277        newtPopWindow();
     1278        if (b_res == b1) {
     1279            output = cdr;
     1280        } else if (b_res == b2) {
     1281            output = cdrw;
     1282        } else if (b_res == b3) {
     1283            output = tape;
     1284        } else if (b_res == b4) {
     1285            output = cdstream;
     1286        } else if (b_res == b5) {
     1287            output = dvd;
     1288        } else if (b_res == b6) {
     1289            output = nfs;
     1290        } else if (b_res == b7) {
     1291            output = iso;
     1292        } else {
     1293            output = none;
     1294        }
     1295        newtPopHelpLine();
     1296        paranoid_free(title_sz);
     1297        paranoid_free(minimsg_sz);
     1298        paranoid_free(outstr);
     1299        return (output);
     1300    }
    14751301
    14761302
     
    14821308 * @return The compression level (0-9) chosen, or -1 for "Exit".
    14831309 */
    1484 int
    1485 which_compression_level ()
    1486 {
    1487 
    1488     /*@ char *************************************************************/
    1489   int output = none;
    1490 
    1491 
    1492     /*@ newt *************************************************************/
    1493 
    1494   newtComponent b1;
    1495     newtComponent b2;
    1496     newtComponent b3;
    1497     newtComponent b4;
    1498     newtComponent b5;
    1499     newtComponent b_res;
    1500     newtComponent myForm;
    1501 
    1502   newtDrawRootText (18, 0, WELCOME_STRING);
    1503   newtPushHelpLine
    1504     ("   Please specify the level of compression that you want.");
    1505   //  newtOpenWindow (23, 3, 34, 13, "How much compression?");
    1506   newtCenteredWindow (34, 13, "How much compression?");
    1507   b1 = newtButton ( 4, 1, "Maximum");
    1508   b2 = newtButton (18, 1, "Average");
    1509   b3 = newtButton ( 4, 5, "Minumum");
    1510   b4 = newtButton (18, 5, " None  ");
    1511   b5 = newtButton ( 4, 9, "         Exit        ");
    1512   myForm = newtForm (NULL, NULL, 0);
    1513   newtFormAddComponents (myForm, b1, b3, b2, b4, b5, NULL);
    1514   b_res = newtRunForm (myForm);
    1515   newtFormDestroy (myForm);
    1516   newtPopWindow ();
    1517   if (b_res == b1)      { output = 9; }
    1518   else if (b_res == b2) { output = 4; }
    1519   else if (b_res == b3) { output = 1; }
    1520   else if (b_res == b4) { output = 0; }
    1521   else if (b_res == b5) { output = -1; }
    1522   newtPopHelpLine ();
    1523   return (output);
    1524 }
     1310    int
     1311     which_compression_level() {
     1312
     1313        /*@ char ************************************************************ */
     1314        int output = none;
     1315
     1316
     1317        /*@ newt ************************************************************ */
     1318
     1319        newtComponent b1;
     1320        newtComponent b2;
     1321        newtComponent b3;
     1322        newtComponent b4;
     1323        newtComponent b5;
     1324        newtComponent b_res;
     1325        newtComponent myForm;
     1326
     1327        newtDrawRootText(18, 0, WELCOME_STRING);
     1328        newtPushHelpLine
     1329            ("   Please specify the level of compression that you want.");
     1330        //  newtOpenWindow (23, 3, 34, 13, "How much compression?");
     1331        newtCenteredWindow(34, 13, "How much compression?");
     1332        b1 = newtButton(4, 1, "Maximum");
     1333        b2 = newtButton(18, 1, "Average");
     1334        b3 = newtButton(4, 5, "Minumum");
     1335        b4 = newtButton(18, 5, " None  ");
     1336        b5 = newtButton(4, 9, "         Exit        ");
     1337        myForm = newtForm(NULL, NULL, 0);
     1338        newtFormAddComponents(myForm, b1, b3, b2, b4, b5, NULL);
     1339        b_res = newtRunForm(myForm);
     1340        newtFormDestroy(myForm);
     1341        newtPopWindow();
     1342        if (b_res == b1) {
     1343            output = 9;
     1344        } else if (b_res == b2) {
     1345            output = 4;
     1346        } else if (b_res == b3) {
     1347            output = 1;
     1348        } else if (b_res == b4) {
     1349            output = 0;
     1350        } else if (b_res == b5) {
     1351            output = -1;
     1352        }
     1353        newtPopHelpLine();
     1354        return (output);
     1355    }
    15251356
    15261357
     
    15341365 * @param source_file The file containing a list of filenames to load into @p filelist.
    15351366 */
    1536 int load_filelist_into_array(struct s_filelist *filelist, char *source_file)
    1537 {
    1538   int i;
    1539   bool done;
    1540   char *tmp;
    1541   FILE*fin;
    1542   struct s_filelist_entry dummy_fle;
    1543 
    1544   malloc_string(tmp);
    1545   assert(filelist!=NULL);
    1546   assert_string_is_neither_NULL_nor_zerolength(source_file);
    1547 
    1548   iamhere("entering");
    1549   if (!(fin=fopen(source_file, "r"))) { log_OS_error(source_file); log_msg(2, "Can't open %s; therefore, cannot popup list", source_file); paranoid_free(tmp); return(1); }
    1550   log_msg(2, "Loading %s", source_file);
    1551   for(filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; filelist->entries++)
    1552     {
    1553 god_i_hate_gotos:
    1554       if (feof(fin)) { break; }
    1555       (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin);
    1556       i = (int) strlen(tmp);
    1557       if (i<2) { goto god_i_hate_gotos; }
    1558       if (tmp[i-1]<32) { tmp[--i]='\0'; }
    1559       if (i<2) { goto god_i_hate_gotos; }
    1560       if (!does_file_exist(tmp)) { goto god_i_hate_gotos; }
    1561       filelist->el[filelist->entries].severity = severity_of_difference(tmp, NULL);
    1562       strcpy(filelist->el[filelist->entries].filename, tmp);
    1563       if (feof(fin)) { break; }
    1564     }
    1565   paranoid_fclose(fin);
    1566   if (filelist->entries >= ARBITRARY_MAXIMUM)
    1567     {
    1568       log_to_screen ("Arbitrary limits suck, man!");
    1569       paranoid_free(tmp);
    1570       return(1);
    1571     }
    1572   for(done=FALSE;!done;)
    1573     {
    1574       done = TRUE;
    1575       for(i=0; i<filelist->entries-1; i++)
    1576         {
     1367    int load_filelist_into_array(struct s_filelist *filelist,
     1368                                 char *source_file) {
     1369        int i;
     1370        bool done;
     1371        char *tmp;
     1372        FILE *fin;
     1373        struct s_filelist_entry dummy_fle;
     1374
     1375        malloc_string(tmp);
     1376        assert(filelist != NULL);
     1377        assert_string_is_neither_NULL_nor_zerolength(source_file);
     1378
     1379        iamhere("entering");
     1380        if (!(fin = fopen(source_file, "r"))) {
     1381            log_OS_error(source_file);
     1382            log_msg(2, "Can't open %s; therefore, cannot popup list",
     1383                    source_file);
     1384            paranoid_free(tmp);
     1385            return (1);
     1386        }
     1387        log_msg(2, "Loading %s", source_file);
     1388        for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM;
     1389             filelist->entries++) {
     1390          god_i_hate_gotos:
     1391            if (feof(fin)) {
     1392                break;
     1393            }
     1394            (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin);
     1395            i = (int) strlen(tmp);
     1396            if (i < 2) {
     1397                goto god_i_hate_gotos;
     1398            }
     1399            if (tmp[i - 1] < 32) {
     1400                tmp[--i] = '\0';
     1401            }
     1402            if (i < 2) {
     1403                goto god_i_hate_gotos;
     1404            }
     1405            if (!does_file_exist(tmp)) {
     1406                goto god_i_hate_gotos;
     1407            }
     1408            filelist->el[filelist->entries].severity =
     1409                severity_of_difference(tmp, NULL);
     1410            strcpy(filelist->el[filelist->entries].filename, tmp);
     1411            if (feof(fin)) {
     1412                break;
     1413            }
     1414        }
     1415        paranoid_fclose(fin);
     1416        if (filelist->entries >= ARBITRARY_MAXIMUM) {
     1417            log_to_screen("Arbitrary limits suck, man!");
     1418            paranoid_free(tmp);
     1419            return (1);
     1420        }
     1421        for (done = FALSE; !done;) {
     1422            done = TRUE;
     1423            for (i = 0; i < filelist->entries - 1; i++) {
    15771424//          if (strcmp(filelist->el[i].filename, filelist->el[i+1].filename) > 0)
    1578           if (filelist->el[i].severity < filelist->el[i+1].severity || (filelist->el[i].severity==filelist->el[i+1].severity && strcmp(filelist->el[i].filename, filelist->el[i+1].filename)>0))
    1579             {
    1580               memcpy((void*)&dummy_fle, (void*)&(filelist->el[i]), sizeof(struct s_filelist_entry));
    1581               memcpy((void*)&(filelist->el[i]), (void*)&(filelist->el[i+1]), sizeof(struct s_filelist_entry));
    1582                memcpy((void*)&(filelist->el[i+1]), (void*)&dummy_fle, sizeof(struct s_filelist_entry));
    1583               log_msg(2, "Swapping %s and %s", filelist->el[i].filename, filelist->el[i+1].filename);
    1584               done = FALSE;
    1585             }
    1586         }
    1587     }
    1588   paranoid_free(tmp);
    1589   iamhere("leaving");
    1590   return(0);
    1591 }
     1425                if (filelist->el[i].severity < filelist->el[i + 1].severity
     1426                    || (filelist->el[i].severity ==
     1427                        filelist->el[i + 1].severity
     1428                        && strcmp(filelist->el[i].filename,
     1429                                  filelist->el[i + 1].filename) > 0)) {
     1430                    memcpy((void *) &dummy_fle,
     1431                           (void *) &(filelist->el[i]),
     1432                           sizeof(struct s_filelist_entry));
     1433                    memcpy((void *) &(filelist->el[i]),
     1434                           (void *) &(filelist->el[i + 1]),
     1435                           sizeof(struct s_filelist_entry));
     1436                    memcpy((void *) &(filelist->el[i + 1]),
     1437                           (void *) &dummy_fle,
     1438                           sizeof(struct s_filelist_entry));
     1439                    log_msg(2, "Swapping %s and %s",
     1440                            filelist->el[i].filename,
     1441                            filelist->el[i + 1].filename);
     1442                    done = FALSE;
     1443                }
     1444            }
     1445        }
     1446        paranoid_free(tmp);
     1447        iamhere("leaving");
     1448        return (0);
     1449    }
    15921450
    15931451
     
    15991457 * @note The returned value points to static storage that will be overwritten with each call.
    16001458 */
    1601 char*filelist_entry_to_string(struct s_filelist_entry *flentry)
    1602 {
    1603   static char comment[100];
    1604   char *tmp;
    1605 
    1606   iamhere("entering"); 
    1607   malloc_string(tmp);
    1608   assert(flentry!=NULL);
    1609   if (flentry->severity==0) { strcpy(tmp, "0   "); }
    1610   else if (flentry->severity==1) { strcpy(tmp, "low "); }
    1611   else if (flentry->severity==2) { strcpy(tmp, "med "); }
    1612   else { strcpy(tmp, "high"); }
    1613   strcat(tmp, "  ");
    1614   strncat(tmp, flentry->filename, 100);
    1615   tmp[98] = '\0';
    1616   strcpy(comment, tmp);
    1617   paranoid_free(tmp);
    1618   iamhere("leaving");
    1619   return(comment);
    1620 }
     1459    char *filelist_entry_to_string(struct s_filelist_entry *flentry) {
     1460        static char comment[100];
     1461        char *tmp;
     1462
     1463        iamhere("entering");
     1464        malloc_string(tmp);
     1465        assert(flentry != NULL);
     1466        if (flentry->severity == 0) {
     1467            strcpy(tmp, "0   ");
     1468        } else if (flentry->severity == 1) {
     1469            strcpy(tmp, "low ");
     1470        } else if (flentry->severity == 2) {
     1471            strcpy(tmp, "med ");
     1472        } else {
     1473            strcpy(tmp, "high");
     1474        }
     1475        strcat(tmp, "  ");
     1476        strncat(tmp, flentry->filename, 100);
     1477        tmp[98] = '\0';
     1478        strcpy(comment, tmp);
     1479        paranoid_free(tmp);
     1480        iamhere("leaving");
     1481        return (comment);
     1482    }
    16211483
    16221484
     
    16291491 * @param source_file The file containing a list of changed files.
    16301492 */
    1631 void popup_changelist_from_file(char*source_file)
    1632 {
    1633   char *reason;
    1634   newtComponent myForm;
    1635     newtComponent bClose;
    1636     newtComponent bSelect;
    1637     newtComponent b_res;
    1638     newtComponent fileListbox;
    1639     newtComponent headerMsg;
    1640 
    1641     /*@ ???? *************************************************************/
    1642   void *curr_choice;
    1643   void *keylist[ARBITRARY_MAXIMUM];
    1644 
    1645     /*@ int **************************************************************/
    1646   int i = 0;
    1647     int currline = 0;
    1648     int finished = FALSE;
    1649   long lng = 0;
    1650 
    1651     /*@ buffers **********************************************************/
    1652     char *tmp;
    1653     char *differ_sz;
    1654 
    1655   struct s_filelist *filelist;
    1656   malloc_string(reason);
    1657   tmp = malloc(5000);
    1658   malloc_string(differ_sz);
    1659   assert_string_is_neither_NULL_nor_zerolength(source_file);
    1660   if (g_text_mode)
    1661     {
    1662       log_msg(2, "Text mode. Therefore, no popup list.");
    1663       goto free_to_go;
    1664     }
    1665   log_msg (2, "Examining file %s", source_file);
    1666 
    1667   lng = count_lines_in_file(source_file);
    1668   if (lng < 1)
    1669     {
    1670       log_msg (2, "No lines in file. Therefore, no popup list."); paranoid_free(reason);
    1671       goto free_to_go;
    1672      }
    1673   else if (lng >= ARBITRARY_MAXIMUM)
    1674      {
    1675        log_msg(2, "Too many files differ for me to list.");
    1676        goto free_to_go;
    1677      }
    1678 
    1679   filelist = (struct s_filelist*)malloc(sizeof(struct s_filelist));
    1680   fileListbox =
    1681     newtListbox (2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1682   newtListboxClear (fileListbox);
    1683 
    1684   if (load_filelist_into_array(filelist, source_file)) { log_msg (2, "Can't open %s; therefore, cannot popup list", source_file); paranoid_free(reason); return; }
    1685   log_msg(2, "%d files loaded into filelist array", filelist->entries);
    1686   for(i=0; i<filelist->entries; i++)
    1687     {
    1688       keylist[i] = (void *) i;
    1689       newtListboxAppendEntry (fileListbox, filelist_entry_to_string(&(filelist->el[i])), keylist[i]);
    1690     }
    1691   sprintf(differ_sz, "  %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", i);
    1692   newtPushHelpLine(differ_sz);
    1693   bClose = newtCompactButton (10, 15, " Close  ");
    1694   bSelect = newtCompactButton (30, 15, " Select ");
    1695   sprintf (tmp, "%-10s               %-20s", "Priority", "Filename");
    1696   headerMsg = newtLabel (2, 1, tmp);
    1697   newtOpenWindow (5, 4, 70, 16, "Non-matching files");
    1698   myForm = newtForm (NULL, NULL, 0);
    1699   newtFormAddComponents (myForm, headerMsg, fileListbox, bClose, bSelect, NULL);
    1700   while (!finished)
    1701     {
    1702       b_res = newtRunForm (myForm);
    1703       if (b_res == bClose)
    1704     {
    1705           finished = TRUE;
    1706         }
    1707       else
    1708         {
    1709           curr_choice = newtListboxGetCurrent (fileListbox);
    1710       for (i = 0; i < filelist->entries && keylist[i] != curr_choice;
    1711            i++);
    1712       if (i == filelist->entries && filelist->entries > 0)
    1713         {
    1714           log_to_screen ("I don't know what that button does!");
    1715         }
    1716       else
    1717         {
    1718           currline = i;
    1719           if (filelist->entries > 0)
    1720             {
    1721             severity_of_difference(filelist->el[currline].filename, reason);
    1722             sprintf(tmp, "%s --- %s", filelist->el[currline].filename, reason);
    1723             popup_and_OK(tmp);
    1724             }
    1725         }
    1726     }
    1727     }
    1728   newtFormDestroy (myForm);
    1729   newtPopWindow ();
    1730   newtPopHelpLine ();
    1731 free_to_go:
    1732   paranoid_free(reason);
    1733   paranoid_free(tmp);
    1734   paranoid_free(differ_sz);
    1735   return;
    1736 }
     1493    void popup_changelist_from_file(char *source_file) {
     1494        char *reason;
     1495        newtComponent myForm;
     1496        newtComponent bClose;
     1497        newtComponent bSelect;
     1498        newtComponent b_res;
     1499        newtComponent fileListbox;
     1500        newtComponent headerMsg;
     1501
     1502        /*@ ???? ************************************************************ */
     1503        void *curr_choice;
     1504        void *keylist[ARBITRARY_MAXIMUM];
     1505
     1506        /*@ int ************************************************************* */
     1507        int i = 0;
     1508        int currline = 0;
     1509        int finished = FALSE;
     1510        long lng = 0;
     1511
     1512        /*@ buffers ********************************************************* */
     1513        char *tmp;
     1514        char *differ_sz;
     1515
     1516        struct s_filelist *filelist;
     1517        malloc_string(reason);
     1518        tmp = malloc(5000);
     1519        malloc_string(differ_sz);
     1520        assert_string_is_neither_NULL_nor_zerolength(source_file);
     1521        if (g_text_mode) {
     1522            log_msg(2, "Text mode. Therefore, no popup list.");
     1523            goto free_to_go;
     1524        }
     1525        log_msg(2, "Examining file %s", source_file);
     1526
     1527        lng = count_lines_in_file(source_file);
     1528        if (lng < 1) {
     1529            log_msg(2, "No lines in file. Therefore, no popup list.");
     1530            paranoid_free(reason);
     1531            goto free_to_go;
     1532        } else if (lng >= ARBITRARY_MAXIMUM) {
     1533            log_msg(2, "Too many files differ for me to list.");
     1534            goto free_to_go;
     1535        }
     1536
     1537        filelist = (struct s_filelist *) malloc(sizeof(struct s_filelist));
     1538        fileListbox =
     1539            newtListbox(2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1540        newtListboxClear(fileListbox);
     1541
     1542        if (load_filelist_into_array(filelist, source_file)) {
     1543            log_msg(2, "Can't open %s; therefore, cannot popup list",
     1544                    source_file);
     1545            paranoid_free(reason);
     1546            return;
     1547        }
     1548        log_msg(2, "%d files loaded into filelist array",
     1549                filelist->entries);
     1550        for (i = 0; i < filelist->entries; i++) {
     1551            keylist[i] = (void *) i;
     1552            newtListboxAppendEntry(fileListbox,
     1553                                   filelist_entry_to_string(&
     1554                                                            (filelist->
     1555                                                             el[i])),
     1556                                   keylist[i]);
     1557        }
     1558        sprintf(differ_sz,
     1559                "  %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.",
     1560                i);
     1561        newtPushHelpLine(differ_sz);
     1562        bClose = newtCompactButton(10, 15, " Close  ");
     1563        bSelect = newtCompactButton(30, 15, " Select ");
     1564        sprintf(tmp, "%-10s               %-20s", "Priority", "Filename");
     1565        headerMsg = newtLabel(2, 1, tmp);
     1566        newtOpenWindow(5, 4, 70, 16, "Non-matching files");
     1567        myForm = newtForm(NULL, NULL, 0);
     1568        newtFormAddComponents(myForm, headerMsg, fileListbox, bClose,
     1569                              bSelect, NULL);
     1570        while (!finished) {
     1571            b_res = newtRunForm(myForm);
     1572            if (b_res == bClose) {
     1573                finished = TRUE;
     1574            } else {
     1575                curr_choice = newtListboxGetCurrent(fileListbox);
     1576                for (i = 0;
     1577                     i < filelist->entries && keylist[i] != curr_choice;
     1578                     i++);
     1579                if (i == filelist->entries && filelist->entries > 0) {
     1580                    log_to_screen("I don't know what that button does!");
     1581                } else {
     1582                    currline = i;
     1583                    if (filelist->entries > 0) {
     1584                        severity_of_difference(filelist->el[currline].
     1585                                               filename, reason);
     1586                        sprintf(tmp, "%s --- %s",
     1587                                filelist->el[currline].filename, reason);
     1588                        popup_and_OK(tmp);
     1589                    }
     1590                }
     1591            }
     1592        }
     1593        newtFormDestroy(myForm);
     1594        newtPopWindow();
     1595        newtPopHelpLine();
     1596      free_to_go:
     1597        paranoid_free(reason);
     1598        paranoid_free(tmp);
     1599        paranoid_free(differ_sz);
     1600        return;
     1601    }
    17371602
    17381603/* @} - end of guiGroup */
     
    17401605
    17411606#if __cplusplus
    1742 } /* extern "C" */
     1607}                               /* extern "C" */
    17431608#endif
    17441609
    17451610
    1746 void wait_until_software_raids_are_prepped(char*mdstat_file, int wait_for_percentage);
    1747 
     1611void wait_until_software_raids_are_prepped(char *mdstat_file,
     1612                                           int wait_for_percentage);
Note: See TracChangeset for help on using the changeset viewer.