Ignore:
Timestamp:
Nov 19, 2005, 2:27:41 AM (18 years ago)
Author:
bcornec
Message:

indent on all the C code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.05/mondo/mondo/common/libmondo-filelist.c

    r30 r128  
    11/* libmondo-filelist.c
    2    $Id: libmondo-filelist.c,v 1.6 2004/06/10 15:29:12 hugo Exp $
     2   $Id$
    33
    44- for subroutines which manipulate the filelist
     
    135135
    136136
    137 extern ssize_t getline(char **lineptr, size_t *n, FILE *stream);
    138 
    139 
    140 int mondo_makefilelist(char*logfile, char*tmpdir, char*scratchdir,
    141     char*include_paths, char*excp, int differential, char *userdef_filelist);
     137extern ssize_t getline(char **lineptr, size_t * n, FILE * stream);
     138
     139
     140int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,
     141                       char *include_paths, char *excp, int differential,
     142                       char *userdef_filelist);
    142143
    143144
    144145/*@unused@*/
    145 //static char cvsid[] = "$Id: libmondo-filelist.c,v 1.6 2004/06/10 15:29:12 hugo Exp $";
     146//static char cvsid[] = "$Id$";
    146147
    147148/**
     
    156157 * @ingroup globalGroup
    157158 */
    158 long g_noof_sets=0;
     159long g_noof_sets = 0;
    159160
    160161extern bool g_text_mode;
     
    180181 * @see chop_filelist
    181182 */
    182 int
    183 call_filelist_chopper (struct s_bkpinfo *bkpinfo)
    184 {
    185     /*@ buffers ************************/
    186   char *dev;
    187   char *filelist;
    188   char *tempfile;
    189   char *cksumlist;
    190   char *tmp;
    191   long noof_sets;
    192 
    193     /*@ pointers ***********************/
    194   char *ptr;
    195   FILE *fout;
    196 
    197     /*@ int ****************************/
    198   int i, retval=0;
    199 
    200   malloc_string(dev);
    201   malloc_string(filelist);
    202   malloc_string(tempfile);
    203   malloc_string(cksumlist);
    204   malloc_string(tmp);
    205   mvaddstr_and_log_it (g_currentY, 0, "Dividing filelist into sets");
    206 
    207   log_to_screen ("Dividing filelist into sets. Please wait.");
    208   i=0;
     183int call_filelist_chopper(struct s_bkpinfo *bkpinfo)
     184{
     185    /*@ buffers *********************** */
     186    char *dev;
     187    char *filelist;
     188    char *tempfile;
     189    char *cksumlist;
     190    char *tmp;
     191    long noof_sets;
     192
     193    /*@ pointers ********************** */
     194    char *ptr;
     195    FILE *fout;
     196
     197    /*@ int *************************** */
     198    int i, retval = 0;
     199
     200    malloc_string(dev);
     201    malloc_string(filelist);
     202    malloc_string(tempfile);
     203    malloc_string(cksumlist);
     204    malloc_string(tmp);
     205    mvaddstr_and_log_it(g_currentY, 0, "Dividing filelist into sets");
     206
     207    log_to_screen("Dividing filelist into sets. Please wait.");
     208    i = 0;
    209209/*
    210210  if (find_home_of_exe("getfattr"))
     
    215215    { i=0; log_to_screen ("This will take more time. Please be patient."); }
    216216*/
    217   sprintf (filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
    218   sprintf (cksumlist, "%s/cklist.full", bkpinfo->tmpdir);
    219   if (!does_file_exist(filelist)) { log_it("filelist %s not found", filelist); fatal_error("call_filelist_chopper() -- filelist not found!"); }
    220 
    221   noof_sets = chop_filelist (filelist, bkpinfo->tmpdir, bkpinfo->optimal_set_size);
    222   estimate_noof_media_required (bkpinfo, noof_sets); // for cosmetic purposes
    223 
    224   sprintf (tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
    225   if (!(fout = fopen (tempfile, "a")))
    226     {
    227       log_OS_error("Cannot append to biggielist");
    228       retval++;
    229       goto end_of_func;
    230     }
    231   log_it (bkpinfo->image_devs);
    232 
    233   ptr = bkpinfo->image_devs;
    234 
    235   while (ptr && *ptr)
    236     {
    237       strcpy (dev, ptr);
    238       log_it ("Examining imagedev %s", dev);
    239       for (i = 0; i < (int) strlen (dev) && dev[i] != ' '; i++);
    240       dev[i] = '\0';
    241       if (!strlen (dev))
    242     {
    243       continue;
    244     }
    245       fprintf (fout, "%s\n", dev);
    246       log_it ("Adding '%s' to biggielist", dev);
    247       if ((ptr = strchr (ptr, ' ')))
    248     {
    249       ptr++;
    250     }
    251     }
    252   paranoid_fclose(fout);
    253   mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    254 
    255 end_of_func:
    256   paranoid_free(filelist);
    257   paranoid_free(tempfile);
    258   paranoid_free(cksumlist);
    259   paranoid_free(dev);
    260   paranoid_free(tmp);
    261   return(retval);
    262 }
    263 
    264 
    265 
    266 int sort_file(char*orig_fname)
    267 {
    268   char *tmp_fname;
    269   char *command;
    270   int retval=0;
    271 
    272   log_msg(1, "Sorting file %s", orig_fname);
    273   malloc_string(tmp_fname);
    274   malloc_string(command);
    275   sprintf(tmp_fname, "/tmp/sort.%d.%d.%d", (int)(random()%32768), (int)(random()%32768), (int)(random()%32768));
    276  
    277   if (!does_file_exist(orig_fname))
    278     { return(0); } // no sense in trying to sort an empty file
    279 
    280   sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE);
    281   retval = system(command);
    282   if (retval)
    283     {
    284       log_msg(2, "Failed to sort %s - oh dear", orig_fname);
    285     }
    286   else
    287     {
    288       log_msg(2, "Sorted %s --> %s OK. Copying it back to %s now", orig_fname, tmp_fname, orig_fname);
    289       sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);
    290       retval += run_program_and_log_output(command, 2);
    291       if (retval)
    292         {
    293       log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname, orig_fname);
    294     }
    295       else
    296         {
    297       log_msg(2, "%s was sorted OK.", orig_fname);
    298     }
    299     }
    300   paranoid_free(tmp_fname);
    301   paranoid_free(command);
    302   log_msg(1, "Finished sorting file %s", orig_fname);
    303   return(retval);
     217    sprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
     218    sprintf(cksumlist, "%s/cklist.full", bkpinfo->tmpdir);
     219    if (!does_file_exist(filelist)) {
     220        log_it("filelist %s not found", filelist);
     221        fatal_error("call_filelist_chopper() -- filelist not found!");
     222    }
     223
     224    noof_sets =
     225        chop_filelist(filelist, bkpinfo->tmpdir,
     226                      bkpinfo->optimal_set_size);
     227    estimate_noof_media_required(bkpinfo, noof_sets);   // for cosmetic purposes
     228
     229    sprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
     230    if (!(fout = fopen(tempfile, "a"))) {
     231        log_OS_error("Cannot append to biggielist");
     232        retval++;
     233        goto end_of_func;
     234    }
     235    log_it(bkpinfo->image_devs);
     236
     237    ptr = bkpinfo->image_devs;
     238
     239    while (ptr && *ptr) {
     240        strcpy(dev, ptr);
     241        log_it("Examining imagedev %s", dev);
     242        for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++);
     243        dev[i] = '\0';
     244        if (!strlen(dev)) {
     245            continue;
     246        }
     247        fprintf(fout, "%s\n", dev);
     248        log_it("Adding '%s' to biggielist", dev);
     249        if ((ptr = strchr(ptr, ' '))) {
     250            ptr++;
     251        }
     252    }
     253    paranoid_fclose(fout);
     254    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     255
     256  end_of_func:
     257    paranoid_free(filelist);
     258    paranoid_free(tempfile);
     259    paranoid_free(cksumlist);
     260    paranoid_free(dev);
     261    paranoid_free(tmp);
     262    return (retval);
     263}
     264
     265
     266
     267int sort_file(char *orig_fname)
     268{
     269    char *tmp_fname;
     270    char *command;
     271    int retval = 0;
     272
     273    log_msg(1, "Sorting file %s", orig_fname);
     274    malloc_string(tmp_fname);
     275    malloc_string(command);
     276    sprintf(tmp_fname, "/tmp/sort.%d.%d.%d", (int) (random() % 32768),
     277            (int) (random() % 32768), (int) (random() % 32768));
     278
     279    if (!does_file_exist(orig_fname)) {
     280        return (0);
     281    }                           // no sense in trying to sort an empty file
     282
     283    sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname,
     284            MONDO_LOGFILE);
     285    retval = system(command);
     286    if (retval) {
     287        log_msg(2, "Failed to sort %s - oh dear", orig_fname);
     288    } else {
     289        log_msg(2, "Sorted %s --> %s OK. Copying it back to %s now",
     290                orig_fname, tmp_fname, orig_fname);
     291        sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);
     292        retval += run_program_and_log_output(command, 2);
     293        if (retval) {
     294            log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname,
     295                    orig_fname);
     296        } else {
     297            log_msg(2, "%s was sorted OK.", orig_fname);
     298        }
     299    }
     300    paranoid_free(tmp_fname);
     301    paranoid_free(command);
     302    log_msg(1, "Finished sorting file %s", orig_fname);
     303    return (retval);
    304304}
    305305
     
    318318 * @return number of errors encountered (0 for success).
    319319 */
    320 int
    321 chop_filelist (char *filelist, char *outdir, long maxsetsizeK)
     320int chop_filelist(char *filelist, char *outdir, long maxsetsizeK)
    322321{
    323322/*@ long ****************************************/
    324   long lino = 0;
    325   long max_sane_size_for_a_file;
    326   long curr_set_size;
    327   long noof_lines;
    328   long siz;
    329 
    330     /*@ int *****************************************/
    331   int i;
    332   long curr_set_no;
    333 
    334     /*@ buffers **************************************/
    335   char *outfname;
    336   char *biggie_fname;
    337   char *incoming;
    338   char *tmp;
    339   char *acl_fname;
    340   char *xattr_fname;
    341 
    342     /*@ pointers ************************************/
    343   FILE *fin;
    344   FILE *fout;
    345   FILE *fbig;
    346 
    347     /*@ structures **********************************/
    348   struct stat buf;
    349   int err = 0;
    350 
    351   malloc_string(outfname);
    352   malloc_string(biggie_fname);
    353   incoming = malloc(MAX_STR_LEN*2);
    354   malloc_string(tmp);
    355   malloc_string(acl_fname);
    356   malloc_string(xattr_fname);
    357  
    358   assert_string_is_neither_NULL_nor_zerolength(filelist);
    359   assert_string_is_neither_NULL_nor_zerolength(outdir);
    360   assert( maxsetsizeK > 0);
    361 
    362   max_sane_size_for_a_file = 32L*1024L;
     323    long lino = 0;
     324    long max_sane_size_for_a_file;
     325    long curr_set_size;
     326    long noof_lines;
     327    long siz;
     328
     329    /*@ int **************************************** */
     330    int i;
     331    long curr_set_no;
     332
     333    /*@ buffers ************************************* */
     334    char *outfname;
     335    char *biggie_fname;
     336    char *incoming;
     337    char *tmp;
     338    char *acl_fname;
     339    char *xattr_fname;
     340
     341    /*@ pointers *********************************** */
     342    FILE *fin;
     343    FILE *fout;
     344    FILE *fbig;
     345
     346    /*@ structures ********************************* */
     347    struct stat buf;
     348    int err = 0;
     349
     350    malloc_string(outfname);
     351    malloc_string(biggie_fname);
     352    incoming = malloc(MAX_STR_LEN * 2);
     353    malloc_string(tmp);
     354    malloc_string(acl_fname);
     355    malloc_string(xattr_fname);
     356
     357    assert_string_is_neither_NULL_nor_zerolength(filelist);
     358    assert_string_is_neither_NULL_nor_zerolength(outdir);
     359    assert(maxsetsizeK > 0);
     360
     361    max_sane_size_for_a_file = 32L * 1024L;
    363362// max_sane_size_for_a_file = maxsetsizeK*2;
    364363//  if (max_sane_size_for_a_file > 32*1024)
    365364//    { max_sane_size_for_a_file = 32*1024; }
    366  
    367   log_it("filelist=%s;", filelist);
    368   open_evalcall_form ("Dividing filelist into sets");
    369   noof_lines = count_lines_in_file (filelist);
    370   if (!(fin = fopen (filelist, "r"))) { log_OS_error("Cannot openin filelist"); return(0); }
    371   curr_set_no = 0;
    372   curr_set_size = 0;
    373   sprintf (outfname, "%s/filelist.%ld", outdir, curr_set_no);
    374   sprintf (biggie_fname, "%s/biggielist.txt", outdir);
    375   log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname);
    376   if (!(fbig = fopen (biggie_fname, "w"))) { log_OS_error("Cannot openout biggie_fname"); err++; goto end_of_func; }
    377   if (!(fout = fopen (outfname, "w"))) { log_OS_error("Cannot openout outfname"); err++; goto end_of_func; }
    378   (void) fgets (incoming, MAX_STR_LEN*2-1, fin);
    379   while (!feof (fin))
    380     {
    381       lino++;
    382       i = strlen (incoming) - 1;
    383       if (i < 0)
    384     {
    385       i = 0;
    386     }
    387       if (i > MAX_STR_LEN-1)
    388         {
    389       incoming[MAX_STR_LEN-30] = '\0';
    390       log_msg(1, "Warning - truncating file %s's name", incoming);
    391       err++;
    392     }
    393       if (incoming[i] < 32)
    394     {
    395       incoming[i] = '\0';
    396     }
    397       if (!strncmp (incoming, "/dev/", 5))
    398     {
    399       siz = 1;
    400     }
    401       else if (lstat (incoming, &buf) != 0)
    402     {
    403       siz = 0;
    404     }
    405       else
    406     {
    407       siz = (long) (buf.st_size >> 10);
    408     }
    409       if (siz > max_sane_size_for_a_file)
     365
     366    log_it("filelist=%s;", filelist);
     367    open_evalcall_form("Dividing filelist into sets");
     368    noof_lines = count_lines_in_file(filelist);
     369    if (!(fin = fopen(filelist, "r"))) {
     370        log_OS_error("Cannot openin filelist");
     371        return (0);
     372    }
     373    curr_set_no = 0;
     374    curr_set_size = 0;
     375    sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
     376    sprintf(biggie_fname, "%s/biggielist.txt", outdir);
     377    log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname);
     378    if (!(fbig = fopen(biggie_fname, "w"))) {
     379        log_OS_error("Cannot openout biggie_fname");
     380        err++;
     381        goto end_of_func;
     382    }
     383    if (!(fout = fopen(outfname, "w"))) {
     384        log_OS_error("Cannot openout outfname");
     385        err++;
     386        goto end_of_func;
     387    }
     388    (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
     389    while (!feof(fin)) {
     390        lino++;
     391        i = strlen(incoming) - 1;
     392        if (i < 0) {
     393            i = 0;
     394        }
     395        if (i > MAX_STR_LEN - 1) {
     396            incoming[MAX_STR_LEN - 30] = '\0';
     397            log_msg(1, "Warning - truncating file %s's name", incoming);
     398            err++;
     399        }
     400        if (incoming[i] < 32) {
     401            incoming[i] = '\0';
     402        }
     403        if (!strncmp(incoming, "/dev/", 5)) {
     404            siz = 1;
     405        } else if (lstat(incoming, &buf) != 0) {
     406            siz = 0;
     407        } else {
     408            siz = (long) (buf.st_size >> 10);
     409        }
     410        if (siz > max_sane_size_for_a_file)
    410411// && strcmp(incoming+strlen(incoming)-4, ".bz2") && strcmp(incoming+strlen(incoming)-4, ".tbz"))
    411     {
    412       fprintf (fbig, "%s\n", incoming);
    413     }
    414       else
    415     {
    416       curr_set_size += siz;
    417       fprintf (fout, "%s\n", incoming);
    418       if (curr_set_size > maxsetsizeK)
    419         {
    420           paranoid_fclose(fout);
    421           sort_file(outfname);
    422           curr_set_no++;
    423           curr_set_size = 0;
    424           sprintf (outfname, "%s/filelist.%ld", outdir, curr_set_no);
    425           if (!(fout = fopen (outfname, "w"))) { log_OS_error("Unable to openout outfname"); err++; goto end_of_func; }
    426           sprintf (tmp, "Fileset #%ld chopped ", curr_set_no - 1);
    427           update_evalcall_form ((int) (lino * 100 / noof_lines));
    428           /*              if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */
    429         }
    430     }
    431       (void) fgets (incoming, MAX_STR_LEN*2-1, fin);
    432     }
    433   paranoid_fclose (fin);
    434   paranoid_fclose (fout);
    435   paranoid_fclose (fbig);
    436 
    437   if (length_of_file(outfname) <= 2)
    438     {
    439       unlink(outfname);
    440       g_noof_sets --;
    441     }
    442   g_noof_sets = curr_set_no;
    443   sort_file(outfname);
    444   sort_file(biggie_fname);
    445   sprintf (outfname, "%s/LAST-FILELIST-NUMBER", outdir);
    446   sprintf (tmp, "%ld", curr_set_no);
    447   if (write_one_liner_data_file (outfname, tmp))
    448       { log_OS_error("Unable to echo write one-liner to LAST-FILELIST-NUMBER"); err = 1;}
    449   if (curr_set_no == 0)
    450     {
    451       sprintf (tmp, "Only one fileset. Fine.");
    452     }
    453   else
    454     {
    455       sprintf (tmp, "Filelist divided into %ld sets", curr_set_no + 1);
    456     }
    457   log_msg(1, tmp);
    458   close_evalcall_form ();
    459   /* This is to work around an obscure bug in Newt; open a form, close it,
    460      carry on... I don't know why it works but it works. If you don't do this
    461      then update_progress_form() won't show the "time taken / time remaining"
    462      line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
     412        {
     413            fprintf(fbig, "%s\n", incoming);
     414        } else {
     415            curr_set_size += siz;
     416            fprintf(fout, "%s\n", incoming);
     417            if (curr_set_size > maxsetsizeK) {
     418                paranoid_fclose(fout);
     419                sort_file(outfname);
     420                curr_set_no++;
     421                curr_set_size = 0;
     422                sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
     423                if (!(fout = fopen(outfname, "w"))) {
     424                    log_OS_error("Unable to openout outfname");
     425                    err++;
     426                    goto end_of_func;
     427                }
     428                sprintf(tmp, "Fileset #%ld chopped ", curr_set_no - 1);
     429                update_evalcall_form((int) (lino * 100 / noof_lines));
     430                /*              if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */
     431            }
     432        }
     433        (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
     434    }
     435    paranoid_fclose(fin);
     436    paranoid_fclose(fout);
     437    paranoid_fclose(fbig);
     438
     439    if (length_of_file(outfname) <= 2) {
     440        unlink(outfname);
     441        g_noof_sets--;
     442    }
     443    g_noof_sets = curr_set_no;
     444    sort_file(outfname);
     445    sort_file(biggie_fname);
     446    sprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir);
     447    sprintf(tmp, "%ld", curr_set_no);
     448    if (write_one_liner_data_file(outfname, tmp)) {
     449        log_OS_error
     450            ("Unable to echo write one-liner to LAST-FILELIST-NUMBER");
     451        err = 1;
     452    }
     453    if (curr_set_no == 0) {
     454        sprintf(tmp, "Only one fileset. Fine.");
     455    } else {
     456        sprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);
     457    }
     458    log_msg(1, tmp);
     459    close_evalcall_form();
     460    /* This is to work around an obscure bug in Newt; open a form, close it,
     461       carry on... I don't know why it works but it works. If you don't do this
     462       then update_progress_form() won't show the "time taken / time remaining"
     463       line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
    463464#ifndef _XWIN
    464   if (!g_text_mode)
    465     {
    466       open_progress_form ("", "", "", "", 100);
    467       newtPopHelpLine ();
    468       newtFormDestroy (g_progressForm);
    469       newtPopWindow ();
    470     }
     465    if (!g_text_mode) {
     466        open_progress_form("", "", "", "", 100);
     467        newtPopHelpLine();
     468        newtFormDestroy(g_progressForm);
     469        newtPopWindow();
     470    }
    471471#endif
    472 end_of_func:
    473   paranoid_free(outfname);
    474   paranoid_free(biggie_fname);
    475   paranoid_free(incoming);
    476   paranoid_free(tmp);
    477   paranoid_free(acl_fname);
    478   paranoid_free(xattr_fname);
    479   return (err ? 0 : curr_set_no + 1);
     472  end_of_func:
     473    paranoid_free(outfname);
     474    paranoid_free(biggie_fname);
     475    paranoid_free(incoming);
     476    paranoid_free(tmp);
     477    paranoid_free(acl_fname);
     478    paranoid_free(xattr_fname);
     479    return (err ? 0 : curr_set_no + 1);
    480480}
    481481
     
    489489 * @param filelist The filelist to free.
    490490 */
    491 void
    492 free_filelist (struct s_node *filelist)
    493 {
    494     /*@ int's ********************************************************/
    495   static int depth = 0;
    496   int percentage;
    497 
    498     /*@ long's *******************************************************/
    499   static long i = 0;
    500 
    501     /*@ end vars *****************************************************/
    502 
    503   assert(filelist!=NULL);
    504   if (depth == 0)
    505     {
    506       open_evalcall_form ("Freeing memory");
    507       log_to_screen ("Freeing memory formerly occupied by filelist");
    508     }
    509   depth++;
    510 
    511   if (filelist->ch == '\0')
    512     {
    513       if (!(i++ % 1111))
    514     {
    515       percentage = (int) (i * 100 / g_original_noof_lines_in_filelist);
    516       update_evalcall_form (percentage);
    517 
    518     }
    519     }
    520 
    521   if (filelist->right)
    522     {
    523       free_filelist (filelist->right);
    524       filelist->right = NULL;
    525     }
    526   if (filelist->down)
    527     {
     491void free_filelist(struct s_node *filelist)
     492{
     493    /*@ int's ******************************************************* */
     494    static int depth = 0;
     495    int percentage;
     496
     497    /*@ long's ****************************************************** */
     498    static long i = 0;
     499
     500    /*@ end vars **************************************************** */
     501
     502    assert(filelist != NULL);
     503    if (depth == 0) {
     504        open_evalcall_form("Freeing memory");
     505        log_to_screen("Freeing memory formerly occupied by filelist");
     506    }
     507    depth++;
     508
     509    if (filelist->ch == '\0') {
     510        if (!(i++ % 1111)) {
     511            percentage =
     512                (int) (i * 100 / g_original_noof_lines_in_filelist);
     513            update_evalcall_form(percentage);
     514
     515        }
     516    }
     517
     518    if (filelist->right) {
     519        free_filelist(filelist->right);
     520        filelist->right = NULL;
     521    }
     522    if (filelist->down) {
    528523/*      if (!(i++ %39999)) { update_evalcall_form(0); } */
    529       free_filelist (filelist->down);
    530       filelist->down = NULL;
    531     }
    532   filelist->ch = '\0';
    533   paranoid_free (filelist);
    534   depth--;
    535   if (depth == 0)
    536     {
    537       close_evalcall_form ();
    538       log_it ("Finished freeing memory");
    539     }
    540 }
    541 
    542 
    543 int call_exe_and_pipe_output_to_fd(char*syscall, FILE*pout)
    544 {
    545   FILE *pattr;
    546   char *tmp;
    547       pattr = popen(syscall, "r");
    548       if (!pattr)
    549         {
    550       log_msg(1, "Failed to open fattr() %s", syscall);
    551       return(1);
    552         }
    553       if (feof(pattr))
    554         {
    555       log_msg(1, "Failed to call fattr() %s", syscall);
    556       paranoid_pclose(pattr);
    557       return(2); 
    558     }
    559       malloc_string(tmp);
    560       for (fgets (tmp, MAX_STR_LEN, pattr); !feof (pattr);
    561        fgets (tmp, MAX_STR_LEN, pattr))
    562         {
    563       fputs(tmp, pout);
    564     }
    565       paranoid_pclose(pattr);
    566       paranoid_free(tmp);
    567       return(0);
    568 }
    569 
    570 
    571 
    572 int gen_aux_list(char*filelist, char*syscall_sprintf, char*auxlist_fname)
    573 {
    574   FILE*fin;
    575   FILE*pout;
    576   char*pout_command;
    577   char*syscall;
    578   char*file_to_analyze;
    579   int i;
    580  
    581   if (!(fin=fopen(filelist, "r")))
    582     {
    583       log_msg(1, "Cannot openin filelist %s", filelist);
    584       return(1);
    585     }
    586   malloc_string(pout_command);
    587   sprintf(pout_command, "gzip -c1 > %s", auxlist_fname);
    588   if (!(pout=popen(pout_command, "w")))
    589     {
    590       log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname);
    591       fclose(fin);
    592       paranoid_free(pout_command);
    593       return(4);
    594     }
    595   malloc_string(syscall);
    596   malloc_string(file_to_analyze);
    597   for (fgets (file_to_analyze, MAX_STR_LEN, fin); !feof (fin);
    598        fgets (file_to_analyze, MAX_STR_LEN, fin))
    599     {
    600       i = strlen(file_to_analyze);
    601       if (i>0 && file_to_analyze[i-1]<32) { file_to_analyze[i-1]='\0'; }
    602       log_msg(8, "Analyzing %s", file_to_analyze);
    603       sprintf(syscall, syscall_sprintf, file_to_analyze);
    604       strcat(syscall, " 2>> /dev/null"); // " MONDO_LOGFILE);
    605       call_exe_and_pipe_output_to_fd(syscall, pout);
    606     }
    607   paranoid_fclose(fin);
    608   paranoid_pclose(pout);
    609   paranoid_free(file_to_analyze);
    610   paranoid_free(syscall);
    611   paranoid_free(pout_command);
    612   return(0);
    613 }
    614 
    615 
    616 int get_acl_list(char*filelist, char*facl_fname)
    617 {
    618   char*command;
    619   int retval=0;
    620  
    621   malloc_string(command);
    622   sprintf(command, "touch %s", facl_fname);
    623   run_program_and_log_output(command, 8);
    624   if (find_home_of_exe("getfacl"))
    625     {
     524        free_filelist(filelist->down);
     525        filelist->down = NULL;
     526    }
     527    filelist->ch = '\0';
     528    paranoid_free(filelist);
     529    depth--;
     530    if (depth == 0) {
     531        close_evalcall_form();
     532        log_it("Finished freeing memory");
     533    }
     534}
     535
     536
     537int call_exe_and_pipe_output_to_fd(char *syscall, FILE * pout)
     538{
     539    FILE *pattr;
     540    char *tmp;
     541    pattr = popen(syscall, "r");
     542    if (!pattr) {
     543        log_msg(1, "Failed to open fattr() %s", syscall);
     544        return (1);
     545    }
     546    if (feof(pattr)) {
     547        log_msg(1, "Failed to call fattr() %s", syscall);
     548        paranoid_pclose(pattr);
     549        return (2);
     550    }
     551    malloc_string(tmp);
     552    for (fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr);
     553         fgets(tmp, MAX_STR_LEN, pattr)) {
     554        fputs(tmp, pout);
     555    }
     556    paranoid_pclose(pattr);
     557    paranoid_free(tmp);
     558    return (0);
     559}
     560
     561
     562
     563int gen_aux_list(char *filelist, char *syscall_sprintf,
     564                 char *auxlist_fname)
     565{
     566    FILE *fin;
     567    FILE *pout;
     568    char *pout_command;
     569    char *syscall;
     570    char *file_to_analyze;
     571    int i;
     572
     573    if (!(fin = fopen(filelist, "r"))) {
     574        log_msg(1, "Cannot openin filelist %s", filelist);
     575        return (1);
     576    }
     577    malloc_string(pout_command);
     578    sprintf(pout_command, "gzip -c1 > %s", auxlist_fname);
     579    if (!(pout = popen(pout_command, "w"))) {
     580        log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname);
     581        fclose(fin);
     582        paranoid_free(pout_command);
     583        return (4);
     584    }
     585    malloc_string(syscall);
     586    malloc_string(file_to_analyze);
     587    for (fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin);
     588         fgets(file_to_analyze, MAX_STR_LEN, fin)) {
     589        i = strlen(file_to_analyze);
     590        if (i > 0 && file_to_analyze[i - 1] < 32) {
     591            file_to_analyze[i - 1] = '\0';
     592        }
     593        log_msg(8, "Analyzing %s", file_to_analyze);
     594        sprintf(syscall, syscall_sprintf, file_to_analyze);
     595        strcat(syscall, " 2>> /dev/null");  // " MONDO_LOGFILE);
     596        call_exe_and_pipe_output_to_fd(syscall, pout);
     597    }
     598    paranoid_fclose(fin);
     599    paranoid_pclose(pout);
     600    paranoid_free(file_to_analyze);
     601    paranoid_free(syscall);
     602    paranoid_free(pout_command);
     603    return (0);
     604}
     605
     606
     607int get_acl_list(char *filelist, char *facl_fname)
     608{
     609    char *command;
     610    int retval = 0;
     611
     612    malloc_string(command);
     613    sprintf(command, "touch %s", facl_fname);
     614    run_program_and_log_output(command, 8);
     615    if (find_home_of_exe("getfacl")) {
    626616//      sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
    627       sprintf(command, "cat %s | getfacl --all-effective -P - 2>> %s | gzip -c1 > %s 2>> %s", filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE);
    628       iamhere(command);
    629       retval = system(command);
    630     }
    631   paranoid_free(command);
    632   return(retval);
    633 }
    634 
    635 
    636 int get_fattr_list(char*filelist, char*fattr_fname)
    637 {
    638   char *command;
    639   int retval=0;
    640  
    641   malloc_string(command);
    642   sprintf(command, "touch %s", fattr_fname);
    643   run_program_and_log_output(command, 8);
    644   if (find_home_of_exe("getfattr"))
    645     {
     617        sprintf(command,
     618                "cat %s | getfacl --all-effective -P - 2>> %s | gzip -c1 > %s 2>> %s",
     619                filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE);
     620        iamhere(command);
     621        retval = system(command);
     622    }
     623    paranoid_free(command);
     624    return (retval);
     625}
     626
     627
     628int get_fattr_list(char *filelist, char *fattr_fname)
     629{
     630    char *command;
     631    int retval = 0;
     632
     633    malloc_string(command);
     634    sprintf(command, "touch %s", fattr_fname);
     635    run_program_and_log_output(command, 8);
     636    if (find_home_of_exe("getfattr")) {
    646637//      sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
    647       retval = gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"", fattr_fname);
    648     }
    649   paranoid_free(command);
    650   return(retval);
     638        retval =
     639            gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"",
     640                         fattr_fname);
     641    }
     642    paranoid_free(command);
     643    return (retval);
    651644}
    652645
     
    674667
    675668
    676 int set_EXAT_list(char*orig_msklist, char*original_exat_fname, char*executable)
    677 {
    678   const int my_depth=8;
    679   char*command, *syscall_pin, *syscall_pout, *incoming;
    680   char*current_subset_file, *current_master_file, *masklist;
    681   int retval=0;
    682   int i;
    683   char*p,*q;
    684   FILE*pin, *pout, *faclin;
    685 
    686   malloc_string(command);
    687   log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, original_exat_fname, executable); 
    688   if (!orig_msklist || !orig_msklist[0] || !does_file_exist(orig_msklist))
    689     {
    690       log_msg(1, "No masklist provided. I shall therefore set ALL attributes.");
    691       sprintf(command, "cat %s | gzip -dc | %s --restore - 2>> %s", original_exat_fname, executable, MONDO_LOGFILE);
    692       log_msg(1, "command = %s", command);
    693       retval = system(command);
    694       paranoid_free(command);
    695       log_msg(1, "Returning w/ retval=%d", retval);
    696       return(retval);
    697     }
    698   if (length_of_file(original_exat_fname) <= 0)
    699     {
    700       log_msg(1, "original_exat_fname %s is empty or missing, so no need to set EXAT list", original_exat_fname);
    701       paranoid_free(command);
    702       return(0);
    703     }
    704   malloc_string(incoming);
    705   malloc_string(masklist);
    706   malloc_string(current_subset_file);
    707   malloc_string(current_master_file);
    708   malloc_string(syscall_pin);
    709   malloc_string(syscall_pout);
    710   sprintf(masklist, "/tmp/%d.%d.mask", (int)(random()%32768), (int)(random()%32768));
    711   sprintf(command, "cp -f %s %s", orig_msklist, masklist);
    712   run_program_and_log_output(command, 1);
    713   sort_file(masklist);
    714   current_subset_file[0] = current_master_file[0] = '\0';
    715   sprintf(syscall_pin, "cat %s | gzip -dc", original_exat_fname);
    716   sprintf(syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE);
    717 
    718   log_msg(1, "syscall_pin = %s", syscall_pin);
    719   log_msg(1, "syscall_pout = %s", syscall_pout);
    720   pout = popen(syscall_pout, "w");
    721   if (!pout)
    722     { iamhere("Unable to openout to syscall_pout"); return(1); }
    723   pin = popen(syscall_pin, "r");
    724   if (!pin)
    725     { pclose(pout); iamhere("Unable to openin from syscall"); return(1); }
    726   faclin = fopen(masklist, "r");
    727   if (!faclin)
    728     { pclose(pin); pclose(pout); iamhere("Unable to openin masklist"); return(1); }
    729 
     669int set_EXAT_list(char *orig_msklist, char *original_exat_fname,
     670                  char *executable)
     671{
     672    const int my_depth = 8;
     673    char *command, *syscall_pin, *syscall_pout, *incoming;
     674    char *current_subset_file, *current_master_file, *masklist;
     675    int retval = 0;
     676    int i;
     677    char *p, *q;
     678    FILE *pin, *pout, *faclin;
     679
     680    malloc_string(command);
     681    log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist,
     682            original_exat_fname, executable);
     683    if (!orig_msklist || !orig_msklist[0]
     684        || !does_file_exist(orig_msklist)) {
     685        log_msg(1,
     686                "No masklist provided. I shall therefore set ALL attributes.");
     687        sprintf(command, "cat %s | gzip -dc | %s --restore - 2>> %s",
     688                original_exat_fname, executable, MONDO_LOGFILE);
     689        log_msg(1, "command = %s", command);
     690        retval = system(command);
     691        paranoid_free(command);
     692        log_msg(1, "Returning w/ retval=%d", retval);
     693        return (retval);
     694    }
     695    if (length_of_file(original_exat_fname) <= 0) {
     696        log_msg(1,
     697                "original_exat_fname %s is empty or missing, so no need to set EXAT list",
     698                original_exat_fname);
     699        paranoid_free(command);
     700        return (0);
     701    }
     702    malloc_string(incoming);
     703    malloc_string(masklist);
     704    malloc_string(current_subset_file);
     705    malloc_string(current_master_file);
     706    malloc_string(syscall_pin);
     707    malloc_string(syscall_pout);
     708    sprintf(masklist, "/tmp/%d.%d.mask", (int) (random() % 32768),
     709            (int) (random() % 32768));
     710    sprintf(command, "cp -f %s %s", orig_msklist, masklist);
     711    run_program_and_log_output(command, 1);
     712    sort_file(masklist);
     713    current_subset_file[0] = current_master_file[0] = '\0';
     714    sprintf(syscall_pin, "cat %s | gzip -dc", original_exat_fname);
     715    sprintf(syscall_pout, "%s --restore - 2>> %s", executable,
     716            MONDO_LOGFILE);
     717
     718    log_msg(1, "syscall_pin = %s", syscall_pin);
     719    log_msg(1, "syscall_pout = %s", syscall_pout);
     720    pout = popen(syscall_pout, "w");
     721    if (!pout) {
     722        iamhere("Unable to openout to syscall_pout");
     723        return (1);
     724    }
     725    pin = popen(syscall_pin, "r");
     726    if (!pin) {
     727        pclose(pout);
     728        iamhere("Unable to openin from syscall");
     729        return (1);
     730    }
     731    faclin = fopen(masklist, "r");
     732    if (!faclin) {
     733        pclose(pin);
     734        pclose(pout);
     735        iamhere("Unable to openin masklist");
     736        return (1);
     737    }
    730738//  printf("Hi there. Starting the loop\n");
    731  
    732   fgets(current_subset_file, MAX_STR_LEN, faclin);
    733   fgets(incoming, MAX_STR_LEN, pin);
    734   while(!feof(pin) && !feof(faclin))
    735     {
     739
     740    fgets(current_subset_file, MAX_STR_LEN, faclin);
     741    fgets(incoming, MAX_STR_LEN, pin);
     742    while (!feof(pin) && !feof(faclin)) {
    736743//      printf("incoming = %s", incoming);
    737      
    738       strcpy(current_master_file, incoming+8);
    739      
    740       p = current_subset_file;
    741       if (*p=='/') {p++;}
    742       i = strlen(p);
    743       if (i>0 && p[i-1]<32) { p[i-1] = '\0'; }
    744 
    745            
    746       q = current_master_file;
    747       if (*q=='/') {q++;}
    748       i = strlen(q);
    749       if (i>0 && q[i-1]<32) { q[i-1] = '\0'; }
    750 
    751       i = strcmp(p,q);
    752       log_msg(my_depth, "'%s' v '%s' --> %d\n", p, q, i);
    753      
     744
     745        strcpy(current_master_file, incoming + 8);
     746
     747        p = current_subset_file;
     748        if (*p == '/') {
     749            p++;
     750        }
     751        i = strlen(p);
     752        if (i > 0 && p[i - 1] < 32) {
     753            p[i - 1] = '\0';
     754        }
     755
     756
     757        q = current_master_file;
     758        if (*q == '/') {
     759            q++;
     760        }
     761        i = strlen(q);
     762        if (i > 0 && q[i - 1] < 32) {
     763            q[i - 1] = '\0';
     764        }
     765
     766        i = strcmp(p, q);
     767        log_msg(my_depth, "'%s' v '%s' --> %d\n", p, q, i);
     768
    754769//      printf("%s v %s --> %d\n", p, q, i);
    755      
    756       if (i<0)
    757         { // read another subset file in.
    758       log_msg(my_depth, "Reading next subset line in\n\n");
    759       fgets(current_subset_file, MAX_STR_LEN, faclin);
    760       continue;
    761     }
    762 
    763       if (!i) { fputs(incoming, pout); }
    764       fgets(incoming, MAX_STR_LEN, pin);
    765       if (!i) { log_msg(my_depth, "Copying master %s", q); }
    766      
     770
     771        if (i < 0) {            // read another subset file in.
     772            log_msg(my_depth, "Reading next subset line in\n\n");
     773            fgets(current_subset_file, MAX_STR_LEN, faclin);
     774            continue;
     775        }
     776
     777        if (!i) {
     778            fputs(incoming, pout);
     779        }
     780        fgets(incoming, MAX_STR_LEN, pin);
     781        if (!i) {
     782            log_msg(my_depth, "Copying master %s", q);
     783        }
    767784//      if (!i) { printf("Match --- %s\n", q); }
    768      
    769       while (!feof(pin) && strncmp(incoming, "# file: ", 8))
    770         {
    771           if (!i) {
    772      
    773 //    printf("%s", incoming);
    774      
    775       fputs(incoming, pout); }
    776           fgets(incoming, MAX_STR_LEN, pin);
    777         }
    778       if (!i) { fgets(current_subset_file, MAX_STR_LEN, faclin); }
    779     }
    780   while(!feof(pin)) { fgets (incoming, MAX_STR_LEN, pin); }
    781   fclose(faclin);
    782   pclose(pin);
    783   pclose(pout); 
    784  
     785
     786        while (!feof(pin) && strncmp(incoming, "# file: ", 8)) {
     787            if (!i) {
     788
     789//    printf("%s", incoming);
     790
     791                fputs(incoming, pout);
     792            }
     793            fgets(incoming, MAX_STR_LEN, pin);
     794        }
     795        if (!i) {
     796            fgets(current_subset_file, MAX_STR_LEN, faclin);
     797        }
     798    }
     799    while (!feof(pin)) {
     800        fgets(incoming, MAX_STR_LEN, pin);
     801    }
     802    fclose(faclin);
     803    pclose(pin);
     804    pclose(pout);
     805
    785806//  printf("OK, loop is done\n");
    786807
    787   unlink(masklist); 
    788   paranoid_free(current_subset_file);
    789   paranoid_free(current_master_file);
    790   paranoid_free(syscall_pout);
    791   paranoid_free(syscall_pin);
    792   paranoid_free(masklist);
    793   paranoid_free(incoming);
    794   paranoid_free(command);
    795   return(retval);
    796 } 
    797 
    798 
    799 int set_fattr_list(char*masklist, char*fattr_fname)
    800 {
    801   return(set_EXAT_list(masklist, fattr_fname, "setfattr"));
    802 }
    803 
    804 
    805 
    806 int set_acl_list(char*masklist, char*acl_fname)
    807 {
    808   return(set_EXAT_list(masklist, acl_fname, "setfacl"));
     808    unlink(masklist);
     809    paranoid_free(current_subset_file);
     810    paranoid_free(current_master_file);
     811    paranoid_free(syscall_pout);
     812    paranoid_free(syscall_pin);
     813    paranoid_free(masklist);
     814    paranoid_free(incoming);
     815    paranoid_free(command);
     816    return (retval);
     817}
     818
     819
     820int set_fattr_list(char *masklist, char *fattr_fname)
     821{
     822    return (set_EXAT_list(masklist, fattr_fname, "setfattr"));
     823}
     824
     825
     826
     827int set_acl_list(char *masklist, char *acl_fname)
     828{
     829    return (set_EXAT_list(masklist, acl_fname, "setfacl"));
    809830}
    810831
     
    833854 * @note This function should only be called at restore-time.
    834855 */
    835 int
    836 get_last_filelist_number (struct s_bkpinfo *bkpinfo)
    837 {
    838     /*@ buffers ******************************************************/
    839   char val_sz[MAX_STR_LEN];
    840   char cfg_fname[MAX_STR_LEN];
     856int get_last_filelist_number(struct s_bkpinfo *bkpinfo)
     857{
     858    /*@ buffers ***************************************************** */
     859    char val_sz[MAX_STR_LEN];
     860    char cfg_fname[MAX_STR_LEN];
    841861/*  char tmp[MAX_STR_LEN]; remove stan benoit apr 2002 */
    842862
    843     /*@ long *********************************************************/
    844   int val_i;
    845 
    846     /*@ end vars *****************************************************/
    847 
    848   assert(bkpinfo!=NULL);
    849 
    850   sprintf (cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
    851   read_cfg_var (cfg_fname, "last-filelist-number", val_sz);
    852   val_i = atoi (val_sz);
    853   if (val_i <= 0)
    854     {
    855       val_i = 500;
    856     }
    857   return (val_i);
     863    /*@ long ******************************************************** */
     864    int val_i;
     865
     866    /*@ end vars **************************************************** */
     867
     868    assert(bkpinfo != NULL);
     869
     870    sprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
     871    read_cfg_var(cfg_fname, "last-filelist-number", val_sz);
     872    val_i = atoi(val_sz);
     873    if (val_i <= 0) {
     874        val_i = 500;
     875    }
     876    return (val_i);
    858877}
    859878
     
    866885 * @bug I don't understand this function. Would someone care to explain it?
    867886 */
    868 int
    869 add_string_at_node (struct s_node *startnode, char *string_to_add)
    870 {
    871 
    872 
    873     /*@ int *********************************************************/
    874   int noof_chars;
    875   int i;
    876   int res;
    877 
    878     /*@ sturctures **************************************************/
    879   struct s_node *node, *newnode;
    880 
    881     /*@ char  *******************************************************/
    882   char char_to_add;
    883 
    884     /*@ bools *******************************************************/
    885 
    886   const bool sosodef = FALSE;
    887 
    888   static int depth=0;
    889   static char original_string[MAX_STR_LEN];
    890 
    891   assert(startnode!=NULL);
    892   assert(string_to_add!=NULL);
    893 
    894   if (!depth) { strcpy(original_string, string_to_add); }
    895 
    896   noof_chars = strlen (string_to_add) + 1;  /* we include the '\0' */
     887int add_string_at_node(struct s_node *startnode, char *string_to_add)
     888{
     889
     890
     891    /*@ int ******************************************************** */
     892    int noof_chars;
     893    int i;
     894    int res;
     895
     896    /*@ sturctures ************************************************* */
     897    struct s_node *node, *newnode;
     898
     899    /*@ char  ****************************************************** */
     900    char char_to_add;
     901
     902    /*@ bools ****************************************************** */
     903
     904    const bool sosodef = FALSE;
     905
     906    static int depth = 0;
     907    static char original_string[MAX_STR_LEN];
     908
     909    assert(startnode != NULL);
     910    assert(string_to_add != NULL);
     911
     912    if (!depth) {
     913        strcpy(original_string, string_to_add);
     914    }
     915
     916    noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */
    897917
    898918/* walk across tree if necessary */
    899   node = startnode;
    900   char_to_add = string_to_add[0];
    901   if (node->right != NULL && node->ch < char_to_add)
    902     {
    903       log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth, char_to_add, node->ch, (node->right)->ch);
    904       return (add_string_at_node (node->right, string_to_add));
    905     }
     919    node = startnode;
     920    char_to_add = string_to_add[0];
     921    if (node->right != NULL && node->ch < char_to_add) {
     922        log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth,
     923                char_to_add, node->ch, (node->right)->ch);
     924        return (add_string_at_node(node->right, string_to_add));
     925    }
    906926
    907927/* walk down tree if appropriate */
    908   if (node->down != NULL && node->ch == char_to_add)
    909     {
    910       log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
    911       depth++;
    912       res = add_string_at_node (node->down, string_to_add + 1);
    913       depth--;
    914       return (res);
    915     }
    916 
    917   if (char_to_add == '\0' && node->ch =='\0')
    918     {
    919       log_msg(6, "%s already in tree", original_string);
    920       return(1);
    921     }
     928    if (node->down != NULL && node->ch == char_to_add) {
     929        log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
     930        depth++;
     931        res = add_string_at_node(node->down, string_to_add + 1);
     932        depth--;
     933        return (res);
     934    }
     935
     936    if (char_to_add == '\0' && node->ch == '\0') {
     937        log_msg(6, "%s already in tree", original_string);
     938        return (1);
     939    }
    922940
    923941/* add here */
    924   if (!(newnode = (struct s_node*)malloc (sizeof (struct s_node))))
    925             {
    926               log_to_screen ("failed to malloc");
    927               depth--;
    928               return (1);
    929             }
    930   if (char_to_add < node->ch) // add to the left of node
    931     {
    932       log_msg(7, "depth=%d char=%c --- adding (left)", depth, char_to_add);
    933       memcpy((void*)newnode, (void*)node, sizeof(struct s_node));
    934       node->right = newnode;
    935     }
    936   else if (char_to_add > node->ch) // add to the right of node
    937     {
    938       log_msg(7, "depth=%d char=%c --- adding (right)", depth, char_to_add);
    939       newnode->right = node->right; // newnode is to the RIGHT of node
    940       node->right = newnode;
    941       node = newnode;
    942     }
    943   // from now on, we're working on 'node'
    944   node->down = NULL;
    945   node->ch = char_to_add;
    946   node->expanded = node->selected = FALSE;
    947   if (char_to_add == '\0')
    948     {
    949       log_msg (6, "Added %s OK", original_string);
    950       return (0);
    951     }
    952 
     942    if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) {
     943        log_to_screen("failed to malloc");
     944        depth--;
     945        return (1);
     946    }
     947    if (char_to_add < node->ch) // add to the left of node
     948    {
     949        log_msg(7, "depth=%d char=%c --- adding (left)", depth,
     950                char_to_add);
     951        memcpy((void *) newnode, (void *) node, sizeof(struct s_node));
     952        node->right = newnode;
     953    } else if (char_to_add > node->ch)  // add to the right of node
     954    {
     955        log_msg(7, "depth=%d char=%c --- adding (right)", depth,
     956                char_to_add);
     957        newnode->right = node->right;   // newnode is to the RIGHT of node
     958        node->right = newnode;
     959        node = newnode;
     960    }
     961    // from now on, we're working on 'node'
     962    node->down = NULL;
     963    node->ch = char_to_add;
     964    node->expanded = node->selected = FALSE;
     965    if (char_to_add == '\0') {
     966        log_msg(6, "Added %s OK", original_string);
     967        return (0);
     968    }
    953969// add the rest
    954   log_msg(6, "Adding remaining chars ('%s')", string_to_add+1);
    955   for (i = 1; i < noof_chars; i++)
    956     {
    957       if (!(node->down = (struct s_node*)malloc (sizeof (struct s_node))))
    958     {
    959       log_to_screen ("%s - failed to malloc", string_to_add);
    960       return (1);
    961     }
    962       node = node->down;
    963       char_to_add = string_to_add[i];
    964       log_msg(6, "Adding '%c'", char_to_add);
    965       node->ch = char_to_add;
    966       node->right = node->down = NULL;
    967       node->expanded = node->selected = FALSE;
    968       if (!node->ch) { node->selected = sosodef; }
    969     }
    970   log_msg (6, "Finally - added %s OK", original_string);
    971   return (0);
     970    log_msg(6, "Adding remaining chars ('%s')", string_to_add + 1);
     971    for (i = 1; i < noof_chars; i++) {
     972        if (!
     973            (node->down =
     974             (struct s_node *) malloc(sizeof(struct s_node)))) {
     975            log_to_screen("%s - failed to malloc", string_to_add);
     976            return (1);
     977        }
     978        node = node->down;
     979        char_to_add = string_to_add[i];
     980        log_msg(6, "Adding '%c'", char_to_add);
     981        node->ch = char_to_add;
     982        node->right = node->down = NULL;
     983        node->expanded = node->selected = FALSE;
     984        if (!node->ch) {
     985            node->selected = sosodef;
     986        }
     987    }
     988    log_msg(6, "Finally - added %s OK", original_string);
     989    return (0);
    972990}
    973991
     
    981999 * @return A filelist tree structure.
    9821000 */
    983 struct s_node *
    984 load_filelist (char *filelist_fname)
    985 {
    986 
    987     /*@ structures **************************************************/
    988   struct s_node *filelist;
    989 
    990     /*@ pointers ****************************************************/
    991   FILE *pin;
    992 
    993     /*@ buffers *****************************************************/
    994   char command_to_open_fname[MAX_STR_LEN];
    995   char fname[MAX_STR_LEN];
    996   char tmp[MAX_STR_LEN];
    997   int pos_in_fname;
    998     /*@ int *********************************************************/
    999   int percentage;
    1000 
    1001     /*@ long ********************************************************/
    1002   long lines_in_filelist;
    1003   long lino = 0;
    1004     /*@ end vars ****************************************************/
    1005 
    1006   assert_string_is_neither_NULL_nor_zerolength(filelist_fname);
    1007 
    1008   if (!does_file_exist(filelist_fname))
    1009     { fatal_error("filelist does not exist -- cannot load it"); }
    1010   log_to_screen ("Loading filelist");
    1011   sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);
    1012   sprintf(tmp, "zcat %s | wc -l", filelist_fname);
    1013   log_msg(6, "tmp = %s", tmp);
    1014   lines_in_filelist = atol(call_program_and_get_last_line_of_output(tmp));
    1015   if (lines_in_filelist < 3) { log_to_screen("Warning - surprisingly short filelist."); }
    1016   g_original_noof_lines_in_filelist = lines_in_filelist;
    1017   if (!(filelist = (struct s_node*)malloc (sizeof (struct s_node))))
    1018     {
    1019       return (NULL);
    1020     }
    1021   filelist->ch = '/';
    1022   filelist->right = NULL;
    1023   filelist->down = malloc(sizeof(struct s_node));
    1024   filelist->expanded = filelist->selected = FALSE;
    1025   (filelist->down)->ch = '\0';
    1026   (filelist->down)->right = (filelist->down)->down = FALSE;
    1027   (filelist->down)->expanded = (filelist->down)->selected = FALSE;
    1028   if (!(pin = popen (command_to_open_fname, "r")))
    1029     {
    1030       log_OS_error("Unable to openin filelist_fname");
    1031       return (NULL);
    1032     }
    1033   open_evalcall_form ("Loading filelist from disk");
    1034   for (fgets (fname, MAX_STR_LEN, pin); !feof (pin);
    1035        fgets (fname, MAX_STR_LEN, pin))
    1036     {
    1037       if ((fname[strlen(fname)-1]==13 || fname[strlen(fname)-1]==10) && strlen(fname)>0)
    1038         { fname[strlen(fname)-1] = '\0'; }
     1001struct s_node *load_filelist(char *filelist_fname)
     1002{
     1003
     1004    /*@ structures ************************************************* */
     1005    struct s_node *filelist;
     1006
     1007    /*@ pointers *************************************************** */
     1008    FILE *pin;
     1009
     1010    /*@ buffers **************************************************** */
     1011    char command_to_open_fname[MAX_STR_LEN];
     1012    char fname[MAX_STR_LEN];
     1013    char tmp[MAX_STR_LEN];
     1014    int pos_in_fname;
     1015    /*@ int ******************************************************** */
     1016    int percentage;
     1017
     1018    /*@ long ******************************************************* */
     1019    long lines_in_filelist;
     1020    long lino = 0;
     1021    /*@ end vars *************************************************** */
     1022
     1023    assert_string_is_neither_NULL_nor_zerolength(filelist_fname);
     1024
     1025    if (!does_file_exist(filelist_fname)) {
     1026        fatal_error("filelist does not exist -- cannot load it");
     1027    }
     1028    log_to_screen("Loading filelist");
     1029    sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);
     1030    sprintf(tmp, "zcat %s | wc -l", filelist_fname);
     1031    log_msg(6, "tmp = %s", tmp);
     1032    lines_in_filelist =
     1033        atol(call_program_and_get_last_line_of_output(tmp));
     1034    if (lines_in_filelist < 3) {
     1035        log_to_screen("Warning - surprisingly short filelist.");
     1036    }
     1037    g_original_noof_lines_in_filelist = lines_in_filelist;
     1038    if (!(filelist = (struct s_node *) malloc(sizeof(struct s_node)))) {
     1039        return (NULL);
     1040    }
     1041    filelist->ch = '/';
     1042    filelist->right = NULL;
     1043    filelist->down = malloc(sizeof(struct s_node));
     1044    filelist->expanded = filelist->selected = FALSE;
     1045    (filelist->down)->ch = '\0';
     1046    (filelist->down)->right = (filelist->down)->down = FALSE;
     1047    (filelist->down)->expanded = (filelist->down)->selected = FALSE;
     1048    if (!(pin = popen(command_to_open_fname, "r"))) {
     1049        log_OS_error("Unable to openin filelist_fname");
     1050        return (NULL);
     1051    }
     1052    open_evalcall_form("Loading filelist from disk");
     1053    for (fgets(fname, MAX_STR_LEN, pin); !feof(pin);
     1054         fgets(fname, MAX_STR_LEN, pin)) {
     1055        if ((fname[strlen(fname) - 1] == 13
     1056             || fname[strlen(fname) - 1] == 10) && strlen(fname) > 0) {
     1057            fname[strlen(fname) - 1] = '\0';
     1058        }
    10391059//      strip_spaces (fname);
    1040       if (!strlen (fname))
    1041     {
    1042       continue;
    1043     }
    1044       for(pos_in_fname=0; fname[pos_in_fname]!='\0'; pos_in_fname++)
    1045         {
    1046       if (fname[pos_in_fname]!='/') { continue; }
    1047       strcpy(tmp, fname);
    1048       tmp[pos_in_fname] = '\0';
    1049       if (strlen(tmp))
    1050         { add_string_at_node (filelist, tmp); }
    1051     }
    1052       add_string_at_node (filelist, fname);
    1053       if (!(++lino % 1111))
    1054     {
    1055       percentage = (int) (lino * 100 / lines_in_filelist);
    1056       update_evalcall_form (percentage);
    1057     }
    1058     }
    1059   paranoid_pclose(pin);
    1060   close_evalcall_form ();
    1061   log_it ("Finished loading filelist");
    1062   return (filelist);
     1060        if (!strlen(fname)) {
     1061            continue;
     1062        }
     1063        for (pos_in_fname = 0; fname[pos_in_fname] != '\0'; pos_in_fname++) {
     1064            if (fname[pos_in_fname] != '/') {
     1065                continue;
     1066            }
     1067            strcpy(tmp, fname);
     1068            tmp[pos_in_fname] = '\0';
     1069            if (strlen(tmp)) {
     1070                add_string_at_node(filelist, tmp);
     1071            }
     1072        }
     1073        add_string_at_node(filelist, fname);
     1074        if (!(++lino % 1111)) {
     1075            percentage = (int) (lino * 100 / lines_in_filelist);
     1076            update_evalcall_form(percentage);
     1077        }
     1078    }
     1079    paranoid_pclose(pin);
     1080    close_evalcall_form();
     1081    log_it("Finished loading filelist");
     1082    return (filelist);
    10631083}
    10641084
     
    10681088 * @param node The toplevel node to use.
    10691089 */
    1070 void
    1071 show_filelist (struct s_node *node)
    1072 {
    1073   static int depth=0;
    1074   static char current_string[200];
    1075 
    1076   if (depth==0)
    1077     { log_msg(0, "----------------show filelist--------------"); }
    1078   current_string[depth] = node->ch;
    1079 
    1080   log_msg(3, "depth=%d", depth);
    1081   if (node->down)
    1082     {
    1083       log_msg(3, "moving down");
    1084       depth++;
    1085       show_filelist(node->down);
    1086       depth--;
    1087     }
    1088 
    1089   if (!node->ch)
    1090     {
    1091       log_msg(0, "%s\n", current_string);
    1092     }
    1093 
    1094   if (node->right)
    1095     {
    1096       log_msg(3, "moving right");
    1097       show_filelist(node->right);
    1098     }
    1099   if (depth==0)
    1100     { log_msg(0, "----------------show filelist--------------"); }
    1101   return;
     1090void show_filelist(struct s_node *node)
     1091{
     1092    static int depth = 0;
     1093    static char current_string[200];
     1094
     1095    if (depth == 0) {
     1096        log_msg(0, "----------------show filelist--------------");
     1097    }
     1098    current_string[depth] = node->ch;
     1099
     1100    log_msg(3, "depth=%d", depth);
     1101    if (node->down) {
     1102        log_msg(3, "moving down");
     1103        depth++;
     1104        show_filelist(node->down);
     1105        depth--;
     1106    }
     1107
     1108    if (!node->ch) {
     1109        log_msg(0, "%s\n", current_string);
     1110    }
     1111
     1112    if (node->right) {
     1113        log_msg(3, "moving right");
     1114        show_filelist(node->right);
     1115    }
     1116    if (depth == 0) {
     1117        log_msg(0, "----------------show filelist--------------");
     1118    }
     1119    return;
    11021120}
    11031121
     
    11101128 * @param filelist The filelist tree structure.
    11111129 */
    1112 void
    1113 reload_filelist (struct s_node *filelist)
    1114 {
    1115   assert(filelist!=NULL);
    1116   toggle_node_selection (filelist, FALSE);
    1117   toggle_path_expandability (filelist, "/", FALSE);
    1118   toggle_all_root_dirs_on (filelist);
     1130void reload_filelist(struct s_node *filelist)
     1131{
     1132    assert(filelist != NULL);
     1133    toggle_node_selection(filelist, FALSE);
     1134    toggle_path_expandability(filelist, "/", FALSE);
     1135    toggle_all_root_dirs_on(filelist);
    11191136}
    11201137
     
    11261143 * @param outfname Where to save it.
    11271144 */
    1128 void
    1129 save_filelist (struct s_node *filelist, char *outfname)
    1130 {
    1131     /*@ int **********************************************************/
    1132   static int percentage;
    1133   static int depth = 0;
    1134 
    1135     /*@ buffers ******************************************************/
    1136   static char str[MAX_STR_LEN];
    1137 
    1138     /*@ structures ***************************************************/
    1139   struct s_node *node;
    1140 
    1141     /*@ pointers *****************************************************/
    1142   static FILE *fout = NULL;
    1143 
    1144     /*@ long *********************************************************/
    1145   static long lines_in_filelist = 0;
    1146   static long lino = 0;
    1147 
    1148     /*@ end vars ****************************************************/
    1149 
    1150   assert(filelist!=NULL);
    1151   assert(outfname!=NULL); // will be zerolength if save_filelist() is called by itself
    1152   if (depth == 0)
    1153     {
    1154       log_to_screen ("Saving filelist");
    1155       if (!(fout = fopen (outfname, "w"))) { fatal_error("Cannot openout/save filelist"); }
    1156       lines_in_filelist = g_original_noof_lines_in_filelist;    /* set by load_filelist() */
    1157       open_evalcall_form ("Saving selection to disk");
    1158     }
    1159   for (node = filelist; node != NULL; node = node->right)
    1160     {
    1161       str[depth] = node->ch;
    1162       log_msg(5, "depth=%d ch=%c", depth, node->ch);
    1163       if (!node->ch)
    1164     {
    1165 //    if (node->selected)
    1166 //      {
    1167           fprintf (fout, "%s\n", str);
    1168 //      }
    1169       if (!(++lino % 1111))
    1170         {
    1171           percentage = (int) (lino * 100 / lines_in_filelist);
    1172           update_evalcall_form (percentage);
    1173         }
    1174     }
    1175       if (node->down)
    1176     {
    1177       depth++;
    1178       save_filelist (node->down, "");
    1179       depth--;
    1180     }
    1181     }
    1182   if (depth == 0)
    1183     {
    1184       paranoid_fclose (fout);
    1185       close_evalcall_form ();
    1186       log_it ("Finished saving filelist");
    1187     }
     1145void save_filelist(struct s_node *filelist, char *outfname)
     1146{
     1147    /*@ int ********************************************************* */
     1148    static int percentage;
     1149    static int depth = 0;
     1150
     1151    /*@ buffers ***************************************************** */
     1152    static char str[MAX_STR_LEN];
     1153
     1154    /*@ structures ************************************************** */
     1155    struct s_node *node;
     1156
     1157    /*@ pointers **************************************************** */
     1158    static FILE *fout = NULL;
     1159
     1160    /*@ long ******************************************************** */
     1161    static long lines_in_filelist = 0;
     1162    static long lino = 0;
     1163
     1164    /*@ end vars *************************************************** */
     1165
     1166    assert(filelist != NULL);
     1167    assert(outfname != NULL);   // will be zerolength if save_filelist() is called by itself
     1168    if (depth == 0) {
     1169        log_to_screen("Saving filelist");
     1170        if (!(fout = fopen(outfname, "w"))) {
     1171            fatal_error("Cannot openout/save filelist");
     1172        }
     1173        lines_in_filelist = g_original_noof_lines_in_filelist;  /* set by load_filelist() */
     1174        open_evalcall_form("Saving selection to disk");
     1175    }
     1176    for (node = filelist; node != NULL; node = node->right) {
     1177        str[depth] = node->ch;
     1178        log_msg(5, "depth=%d ch=%c", depth, node->ch);
     1179        if (!node->ch) {
     1180//    if (node->selected)
     1181//      {
     1182            fprintf(fout, "%s\n", str);
     1183//      }
     1184            if (!(++lino % 1111)) {
     1185                percentage = (int) (lino * 100 / lines_in_filelist);
     1186                update_evalcall_form(percentage);
     1187            }
     1188        }
     1189        if (node->down) {
     1190            depth++;
     1191            save_filelist(node->down, "");
     1192            depth--;
     1193        }
     1194    }
     1195    if (depth == 0) {
     1196        paranoid_fclose(fout);
     1197        close_evalcall_form();
     1198        log_it("Finished saving filelist");
     1199    }
    11881200}
    11891201
     
    11951207 * @bug I don't understand this function. Would someone care to explain it?
    11961208 */
    1197 void
    1198 toggle_all_root_dirs_on (struct s_node *filelist)
    1199 {
    1200     /*@ structures ***************************************************/
    1201   struct s_node *node;
    1202 
    1203     /*@ int **********************************************************/
    1204   static int depth = 0;
    1205   static int root_dirs_expanded;
    1206 
    1207     /*@ buffers ******************************************************/
    1208   static char filename[MAX_STR_LEN];
    1209 
    1210     /*@ end vars ****************************************************/
    1211 
    1212   assert(filelist!=NULL);
    1213   if (depth == 0)
    1214     {
    1215       log_it ("Toggling all root dirs ON");
    1216       root_dirs_expanded = 0;
    1217     }
    1218   for (node = filelist; node != NULL; node = node->right)
    1219     {
    1220       filename[depth] = node->ch;
    1221       if (node->ch == '\0' && strlen (filename) > 1
    1222       && (!strchr (filename + 1, '/')))
    1223     {
    1224       node->selected = FALSE;
    1225       node->expanded = TRUE;
    1226 //    log_it (filename);
    1227       root_dirs_expanded++;
    1228     }
    1229       if (node->down)
    1230     {
    1231       depth++;
    1232       toggle_all_root_dirs_on (node->down);
    1233       depth--;
    1234     }
    1235     }
    1236   if (depth == 0)
    1237     {
    1238       log_it ("Finished toggling all root dirs ON");
    1239     }
     1209void toggle_all_root_dirs_on(struct s_node *filelist)
     1210{
     1211    /*@ structures ************************************************** */
     1212    struct s_node *node;
     1213
     1214    /*@ int ********************************************************* */
     1215    static int depth = 0;
     1216    static int root_dirs_expanded;
     1217
     1218    /*@ buffers ***************************************************** */
     1219    static char filename[MAX_STR_LEN];
     1220
     1221    /*@ end vars *************************************************** */
     1222
     1223    assert(filelist != NULL);
     1224    if (depth == 0) {
     1225        log_it("Toggling all root dirs ON");
     1226        root_dirs_expanded = 0;
     1227    }
     1228    for (node = filelist; node != NULL; node = node->right) {
     1229        filename[depth] = node->ch;
     1230        if (node->ch == '\0' && strlen(filename) > 1
     1231            && (!strchr(filename + 1, '/'))) {
     1232            node->selected = FALSE;
     1233            node->expanded = TRUE;
     1234//    log_it (filename);
     1235            root_dirs_expanded++;
     1236        }
     1237        if (node->down) {
     1238            depth++;
     1239            toggle_all_root_dirs_on(node->down);
     1240            depth--;
     1241        }
     1242    }
     1243    if (depth == 0) {
     1244        log_it("Finished toggling all root dirs ON");
     1245    }
    12401246}
    12411247
     
    12491255 */
    12501256void
    1251 toggle_path_expandability (struct s_node *filelist, char *pathname,
    1252                bool on_or_off)
    1253 {
    1254 
    1255     /*@ int *********************************************************/
    1256   static int depth = 0;
    1257   static int total_expanded;
    1258   static int root_depth;
    1259   int j;
    1260     /*@ structures **************************************************/
    1261   struct s_node *node;
    1262 
    1263     /*@ buffers *****************************************************/
    1264   static char current_filename[MAX_STR_LEN];
     1257toggle_path_expandability(struct s_node *filelist, char *pathname,
     1258                          bool on_or_off)
     1259{
     1260
     1261    /*@ int ******************************************************** */
     1262    static int depth = 0;
     1263    static int total_expanded;
     1264    static int root_depth;
     1265    int j;
     1266    /*@ structures ************************************************* */
     1267    struct s_node *node;
     1268
     1269    /*@ buffers **************************************************** */
     1270    static char current_filename[MAX_STR_LEN];
    12651271
    12661272/*  char tmp[MAX_STR_LEN+2]; */
    12671273
    1268     /*@ end vars ****************************************************/
    1269 
    1270   assert(filelist!=NULL);
    1271   assert_string_is_neither_NULL_nor_zerolength(pathname);
    1272   if (depth == 0)
    1273     {
    1274       total_expanded = 0;
     1274    /*@ end vars *************************************************** */
     1275
     1276    assert(filelist != NULL);
     1277    assert_string_is_neither_NULL_nor_zerolength(pathname);
     1278    if (depth == 0) {
     1279        total_expanded = 0;
    12751280//      log_it ("Toggling path's expandability");
    1276       for (root_depth = (int) strlen (pathname);
    1277        root_depth > 0 && pathname[root_depth - 1] != '/'; root_depth--);
    1278       if (root_depth < 2)
    1279     {
    1280       root_depth = (int) strlen (pathname);
    1281     }
    1282     }
    1283   for (node = filelist; node != NULL; node = node->right)
    1284     {
    1285       current_filename[depth] = node->ch;
    1286       if (node->down)
    1287     {
    1288       depth++;
    1289       toggle_path_expandability (node->down, pathname, on_or_off);
    1290       depth--;
    1291     }
    1292       if (node->ch == '\0')
    1293     {
    1294       if (!strncmp (pathname, current_filename, strlen (pathname)))
    1295         {
    1296           for (j = root_depth;
    1297            current_filename[j] != '/' && current_filename[j] != '\0';
    1298            j++);
    1299           if (current_filename[j] != '\0')
    1300         {
    1301           for (j++;
    1302                current_filename[j] != '/'
    1303                && current_filename[j] != '\0'; j++);
    1304         }
    1305           if (current_filename[j] == '\0')
    1306         {
    1307           node->expanded =
    1308             (!strcmp (pathname, current_filename) ? TRUE : on_or_off);
    1309         }
    1310         }
    1311     }
    1312       if (node->expanded)
    1313     {
    1314       if (total_expanded < ARBITRARY_MAXIMUM - 32
    1315           || !strrchr (current_filename + strlen (pathname), '/'))
    1316         {
    1317           total_expanded++;
    1318         }
    1319       else
    1320         {
    1321           node->expanded = FALSE;
    1322         }
    1323     }
    1324     }
    1325   if (depth == 0)
    1326     {
     1281        for (root_depth = (int) strlen(pathname);
     1282             root_depth > 0 && pathname[root_depth - 1] != '/';
     1283             root_depth--);
     1284        if (root_depth < 2) {
     1285            root_depth = (int) strlen(pathname);
     1286        }
     1287    }
     1288    for (node = filelist; node != NULL; node = node->right) {
     1289        current_filename[depth] = node->ch;
     1290        if (node->down) {
     1291            depth++;
     1292            toggle_path_expandability(node->down, pathname, on_or_off);
     1293            depth--;
     1294        }
     1295        if (node->ch == '\0') {
     1296            if (!strncmp(pathname, current_filename, strlen(pathname))) {
     1297                for (j = root_depth;
     1298                     current_filename[j] != '/'
     1299                     && current_filename[j] != '\0'; j++);
     1300                if (current_filename[j] != '\0') {
     1301                    for (j++;
     1302                         current_filename[j] != '/'
     1303                         && current_filename[j] != '\0'; j++);
     1304                }
     1305                if (current_filename[j] == '\0') {
     1306                    node->expanded =
     1307                        (!strcmp(pathname, current_filename) ? TRUE :
     1308                         on_or_off);
     1309                }
     1310            }
     1311        }
     1312        if (node->expanded) {
     1313            if (total_expanded < ARBITRARY_MAXIMUM - 32
     1314                || !strrchr(current_filename + strlen(pathname), '/')) {
     1315                total_expanded++;
     1316            } else {
     1317                node->expanded = FALSE;
     1318            }
     1319        }
     1320    }
     1321    if (depth == 0) {
    13271322//      log_it ("Finished toggling expandability");
    1328     }
     1323    }
    13291324}
    13301325
     
    13371332 */
    13381333void
    1339 toggle_path_selection (struct s_node *filelist, char *pathname,
    1340                bool on_or_off)
    1341 {
    1342     /*@ int **********************************************************/
    1343   static int depth = 0;
    1344   int j;
    1345 
    1346     /*@ structures ***************************************************/
    1347   struct s_node *node;
    1348 
    1349     /*@ buffers ******************************************************/
    1350   static char current_filename[MAX_STR_LEN];
    1351   char tmp[MAX_STR_LEN + 2];
    1352 
    1353     /*@ end vars ****************************************************/
    1354   assert(filelist!=NULL);
    1355   assert_string_is_neither_NULL_nor_zerolength(pathname);
    1356   if (depth == 0)
    1357     {
    1358       log_it ("Toggling path's selection");
    1359     }
    1360   for (node = filelist; node != NULL; node = node->right)
    1361     {
    1362       current_filename[depth] = node->ch;
    1363       if (node->down)
    1364     {
    1365       depth++;
    1366       toggle_path_selection (node->down, pathname, on_or_off);
    1367       depth--;
    1368     }
    1369       if (node->ch == '\0')
    1370     {
    1371       if (!strncmp (pathname, current_filename, strlen (pathname)))
    1372         {
    1373           for (j = 0;
    1374            pathname[j] != '\0' && pathname[j] == current_filename[j];
    1375            j++);
    1376           if (current_filename[j] == '/' || current_filename[j] == '\0')
    1377         {
    1378           node->selected = on_or_off;
    1379           sprintf (tmp, "%s is now %s\n", current_filename,
    1380                (on_or_off ? "ON" : "OFF"));
    1381         }
    1382         }
    1383     }
    1384     }
    1385   if (depth == 0)
    1386     {
    1387       log_it ("Finished toggling selection");
    1388     }
     1334toggle_path_selection(struct s_node *filelist, char *pathname,
     1335                      bool on_or_off)
     1336{
     1337    /*@ int ********************************************************* */
     1338    static int depth = 0;
     1339    int j;
     1340
     1341    /*@ structures ************************************************** */
     1342    struct s_node *node;
     1343
     1344    /*@ buffers ***************************************************** */
     1345    static char current_filename[MAX_STR_LEN];
     1346    char tmp[MAX_STR_LEN + 2];
     1347
     1348    /*@ end vars *************************************************** */
     1349    assert(filelist != NULL);
     1350    assert_string_is_neither_NULL_nor_zerolength(pathname);
     1351    if (depth == 0) {
     1352        log_it("Toggling path's selection");
     1353    }
     1354    for (node = filelist; node != NULL; node = node->right) {
     1355        current_filename[depth] = node->ch;
     1356        if (node->down) {
     1357            depth++;
     1358            toggle_path_selection(node->down, pathname, on_or_off);
     1359            depth--;
     1360        }
     1361        if (node->ch == '\0') {
     1362            if (!strncmp(pathname, current_filename, strlen(pathname))) {
     1363                for (j = 0;
     1364                     pathname[j] != '\0'
     1365                     && pathname[j] == current_filename[j]; j++);
     1366                if (current_filename[j] == '/'
     1367                    || current_filename[j] == '\0') {
     1368                    node->selected = on_or_off;
     1369                    sprintf(tmp, "%s is now %s\n", current_filename,
     1370                            (on_or_off ? "ON" : "OFF"));
     1371                }
     1372            }
     1373        }
     1374    }
     1375    if (depth == 0) {
     1376        log_it("Finished toggling selection");
     1377    }
    13891378}
    13901379
     
    13961385 * @bug I don't understand this function. Would someone care to explain it?
    13971386 */
    1398 void
    1399 toggle_node_selection (struct s_node *filelist, bool on_or_off)
    1400 {
    1401     /*@ structure ***************************************************/
    1402   struct s_node *node;
    1403 
    1404     /*@ end vars ****************************************************/
    1405   assert(filelist!=NULL);
    1406   for (node = filelist; node != NULL; node = node->right)
    1407     {
    1408       if (node->ch == '/')
    1409     {
    1410       continue;
    1411     }           /* don't go deep */
    1412       if (node->ch == '\0')
    1413     {
    1414       node->selected = on_or_off;
    1415     }
    1416       if (node->down)
    1417     {
    1418       toggle_node_selection (node->down, on_or_off);
    1419     }
    1420     }
     1387void toggle_node_selection(struct s_node *filelist, bool on_or_off)
     1388{
     1389    /*@ structure ************************************************** */
     1390    struct s_node *node;
     1391
     1392    /*@ end vars *************************************************** */
     1393    assert(filelist != NULL);
     1394    for (node = filelist; node != NULL; node = node->right) {
     1395        if (node->ch == '/') {
     1396            continue;
     1397        }                       /* don't go deep */
     1398        if (node->ch == '\0') {
     1399            node->selected = on_or_off;
     1400        }
     1401        if (node->down) {
     1402            toggle_node_selection(node->down, on_or_off);
     1403        }
     1404    }
    14211405}
    14221406
     
    14301414 * The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist().
    14311415 */
    1432 char *g_skeleton_filelist=NULL;
     1416char *g_skeleton_filelist = NULL;
    14331417
    14341418/**
    14351419 * Number of entries in the skeleton filelist.
    14361420 */
    1437 long g_skeleton_entries=0;
     1421long g_skeleton_entries = 0;
    14381422
    14391423/**
     
    14491433 * @see mondo_makefilelist
    14501434 */
    1451 int
    1452 prepare_filelist (struct s_bkpinfo *bkpinfo)
    1453 {
    1454 
    1455     /*@ int *****************************************************/
    1456   int res = 0;
     1435int prepare_filelist(struct s_bkpinfo *bkpinfo)
     1436{
     1437
     1438    /*@ int **************************************************** */
     1439    int res = 0;
    14571440// patch by Herman Kuster
    14581441// end patch
    1459   int *p_res = &res;
    1460 
    1461     /*@ buffers *************************************************/
     1442    int *p_res = &res;
     1443
     1444    /*@ buffers ************************************************ */
    14621445//  char command[MAX_STR_LEN*2];
    14631446
    1464     /*@ i don't have any idea ***********************************/
    1465 
    1466   assert(bkpinfo!=NULL);
    1467   log_it ("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir,
    1468        bkpinfo->scratchdir);
    1469   if (bkpinfo->make_filelist)
    1470     {
    1471       mvaddstr_and_log_it (g_currentY, 0,
    1472                "Making catalog of files to be backed up");
    1473     }
    1474   else
    1475     {
    1476       mvaddstr_and_log_it (g_currentY, 0,
    1477                "Using supplied catalog of files to be backed up");
    1478     }
    1479 
    1480   if (bkpinfo->make_filelist)
    1481     {
    1482       res = mondo_makefilelist(
    1483        MONDO_LOGFILE, bkpinfo->tmpdir, bkpinfo->scratchdir,
    1484        bkpinfo->include_paths,
    1485        bkpinfo->exclude_paths,
    1486        bkpinfo->differential,
    1487        NULL);
    1488     }
    1489   else
    1490     {
    1491       res = mondo_makefilelist(
    1492        MONDO_LOGFILE, bkpinfo->tmpdir, bkpinfo->scratchdir,
    1493        NULL,
    1494        bkpinfo->exclude_paths,
    1495        bkpinfo->differential,
    1496        bkpinfo->include_paths);
    1497     }
    1498 
    1499   if (res)
    1500     {
    1501       log_OS_error("Call to mondo-makefilelist failed");
    1502       *p_res ++;
    1503       mvaddstr_and_log_it (g_currentY++, 74, "Failed.");
    1504     }
    1505   else
    1506     {
    1507       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1508     }
    1509   return (res);
     1447    /*@ i don't have any idea ********************************** */
     1448
     1449    assert(bkpinfo != NULL);
     1450    log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir,
     1451           bkpinfo->scratchdir);
     1452    if (bkpinfo->make_filelist) {
     1453        mvaddstr_and_log_it(g_currentY, 0,
     1454                            "Making catalog of files to be backed up");
     1455    } else {
     1456        mvaddstr_and_log_it(g_currentY, 0,
     1457                            "Using supplied catalog of files to be backed up");
     1458    }
     1459
     1460    if (bkpinfo->make_filelist) {
     1461        res =
     1462            mondo_makefilelist(MONDO_LOGFILE, bkpinfo->tmpdir,
     1463                               bkpinfo->scratchdir, bkpinfo->include_paths,
     1464                               bkpinfo->exclude_paths,
     1465                               bkpinfo->differential, NULL);
     1466    } else {
     1467        res =
     1468            mondo_makefilelist(MONDO_LOGFILE, bkpinfo->tmpdir,
     1469                               bkpinfo->scratchdir, NULL,
     1470                               bkpinfo->exclude_paths,
     1471                               bkpinfo->differential,
     1472                               bkpinfo->include_paths);
     1473    }
     1474
     1475    if (res) {
     1476        log_OS_error("Call to mondo-makefilelist failed");
     1477        *p_res++;
     1478        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1479    } else {
     1480        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1481    }
     1482    return (res);
    15101483}
    15111484
     
    15201493 * @bug Return value should be @c void.
    15211494 */
    1522 int open_and_list_dir(char*dir, char*sth, FILE*fout, time_t time_of_last_full_backup)
    1523 {
    1524   DIR             *dip;
    1525   struct dirent   *dit;
    1526   struct stat statbuf;
    1527   char new[MAX_STR_LEN];
    1528   char *tmp;
    1529   char *sth_B;
    1530   static int percentage=0;
    1531   char *ith_B;
    1532   char *skip_these;
    1533   char *new_with_spaces;
    1534   static char *name_of_evalcall_form;
    1535   int i;
    1536   static int depth=0;
    1537   char *p;
    1538   static int counter=0;
    1539   static int uberctr=0;
    1540   static char *find_skeleton_marker;
    1541   static long skeleton_lino=0;
    1542   static time_t last_time=0;
    1543   time_t this_time;
    1544  
    1545   malloc_string(tmp);
    1546   malloc_string(sth_B);
    1547   malloc_string(ith_B);
    1548   malloc_string(new_with_spaces);
    1549   p = strrchr(dir, '/');
    1550   if (p)
    1551     {
    1552       if (!strcmp(p, "/.") || !strcmp(p, "/.."))
    1553         {
    1554           return(0);
    1555         }
    1556     }
    1557 
    1558   if (!depth)
    1559     {
    1560       malloc_string(name_of_evalcall_form);
    1561       malloc_string(find_skeleton_marker);
     1495int open_and_list_dir(char *dir, char *sth, FILE * fout,
     1496                      time_t time_of_last_full_backup)
     1497{
     1498    DIR *dip;
     1499    struct dirent *dit;
     1500    struct stat statbuf;
     1501    char new[MAX_STR_LEN];
     1502    char *tmp;
     1503    char *sth_B;
     1504    static int percentage = 0;
     1505    char *ith_B;
     1506    char *skip_these;
     1507    char *new_with_spaces;
     1508    static char *name_of_evalcall_form;
     1509    int i;
     1510    static int depth = 0;
     1511    char *p;
     1512    static int counter = 0;
     1513    static int uberctr = 0;
     1514    static char *find_skeleton_marker;
     1515    static long skeleton_lino = 0;
     1516    static time_t last_time = 0;
     1517    time_t this_time;
     1518
     1519    malloc_string(tmp);
     1520    malloc_string(sth_B);
     1521    malloc_string(ith_B);
     1522    malloc_string(new_with_spaces);
     1523    p = strrchr(dir, '/');
     1524    if (p) {
     1525        if (!strcmp(p, "/.") || !strcmp(p, "/..")) {
     1526            return (0);
     1527        }
     1528    }
     1529
     1530    if (!depth) {
     1531        malloc_string(name_of_evalcall_form);
     1532        malloc_string(find_skeleton_marker);
    15621533#if linux
    1563       // 2.6 has /sys as a proc-type thing -- must be excluded
    1564       sprintf(tmp, "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -path /sys -prune -o -path /dev/shm -prune -o -path /media/floppy -prune -o -type d -a -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
     1534        // 2.6 has /sys as a proc-type thing -- must be excluded
     1535        sprintf(tmp,
     1536                "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -path /sys -prune -o -path /dev/shm -prune -o -path /media/floppy -prune -o -type d -a -print > %s 2> /dev/null",
     1537                dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
    15651538#else
    1566       // On BSD, for example, /sys is the kernel sources -- don't exclude
    1567       sprintf(tmp, "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -type d -a -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
     1539        // On BSD, for example, /sys is the kernel sources -- don't exclude
     1540        sprintf(tmp,
     1541                "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -type d -a -print > %s 2> /dev/null",
     1542                dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
    15681543#endif
    1569       system(tmp);
    1570       sprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
    1571       g_skeleton_entries = 1 + atol(call_program_and_get_last_line_of_output(tmp));
    1572       sprintf(name_of_evalcall_form, "Making catalog of %s", dir);
    1573       open_evalcall_form (name_of_evalcall_form);
    1574       find_skeleton_marker[0] = '\0';
    1575       skeleton_lino=1;
    1576       log_msg(5, "entries = %ld", g_skeleton_entries);
    1577       percentage=0;
    1578     }
    1579   else if (depth<=MAX_SKEL_DEPTH) // update evalcall form if appropriate
    1580         {
    1581       sprintf(find_skeleton_marker, "fgrep -v \"%s\" %s > %s.new 2> /dev/null", dir, g_skeleton_filelist, g_skeleton_filelist);
    1582 //    log_msg(0, "fsm = %s", find_skeleton_marker);
    1583       if (!system(find_skeleton_marker))
    1584         {
    1585           percentage = (int)(skeleton_lino*100/g_skeleton_entries);
    1586           skeleton_lino++;
    1587 //        log_msg(5, "Found %s", dir);
    1588 //        log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage);
    1589           sprintf(find_skeleton_marker, "mv -f %s.new %s", g_skeleton_filelist, g_skeleton_filelist);
    1590 //        log_msg(6, "fsm = %s", find_skeleton_marker);
    1591           run_program_and_log_output(find_skeleton_marker, 8);
    1592           time(&this_time);
    1593           if (this_time != last_time)
    1594             {
    1595             last_time = this_time;
     1544        system(tmp);
     1545        sprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
     1546        g_skeleton_entries =
     1547            1 + atol(call_program_and_get_last_line_of_output(tmp));
     1548        sprintf(name_of_evalcall_form, "Making catalog of %s", dir);
     1549        open_evalcall_form(name_of_evalcall_form);
     1550        find_skeleton_marker[0] = '\0';
     1551        skeleton_lino = 1;
     1552        log_msg(5, "entries = %ld", g_skeleton_entries);
     1553        percentage = 0;
     1554    } else if (depth <= MAX_SKEL_DEPTH) // update evalcall form if appropriate
     1555    {
     1556        sprintf(find_skeleton_marker,
     1557                "fgrep -v \"%s\" %s > %s.new 2> /dev/null", dir,
     1558                g_skeleton_filelist, g_skeleton_filelist);
     1559//    log_msg(0, "fsm = %s", find_skeleton_marker);
     1560        if (!system(find_skeleton_marker)) {
     1561            percentage = (int) (skeleton_lino * 100 / g_skeleton_entries);
     1562            skeleton_lino++;
     1563//        log_msg(5, "Found %s", dir);
     1564//        log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage);
     1565            sprintf(find_skeleton_marker, "mv -f %s.new %s",
     1566                    g_skeleton_filelist, g_skeleton_filelist);
     1567//        log_msg(6, "fsm = %s", find_skeleton_marker);
     1568            run_program_and_log_output(find_skeleton_marker, 8);
     1569            time(&this_time);
     1570            if (this_time != last_time) {
     1571                last_time = this_time;
    15961572#ifndef _XWIN
    1597                   if (!g_text_mode)
    1598                 {
    1599               sprintf(tmp, "Reading %-68s", dir);
    1600                   newtDrawRootText (0, g_noof_rows - 3, tmp);
    1601             }
     1573                if (!g_text_mode) {
     1574                    sprintf(tmp, "Reading %-68s", dir);
     1575                    newtDrawRootText(0, g_noof_rows - 3, tmp);
     1576                }
    16021577#endif
    1603           update_evalcall_form(percentage);
    1604         }
    1605         }
    1606         }
    1607 
    1608   depth++;
     1578                update_evalcall_form(percentage);
     1579            }
     1580        }
     1581    }
     1582
     1583    depth++;
    16091584
    16101585//  log_msg(0, "Cataloguing %s", dir);
    1611   if (sth[0]==' ') { skip_these = sth; }
    1612   else
    1613     {
    1614       skip_these = sth_B;
    1615       sprintf(skip_these, " %s ", sth);
    1616     }
    1617   sprintf(new_with_spaces, " %s ", dir);
    1618   if ((dip = opendir(dir)) == NULL)
    1619     {
    1620       log_OS_error("opendir");
    1621     }
    1622   else if (strstr(skip_these, new_with_spaces))
    1623     {
    1624       fprintf(fout, "%s\n", dir); // if excluded dir then print dir ONLY
    1625     }
    1626   else
    1627     {
    1628       fprintf(fout, "%s\n", dir);
    1629       while ((dit = readdir(dip)) != NULL)
    1630        {
    1631     i++;
    1632         strcpy(new, dir);
    1633         if (strcmp(dir, "/")) { strcat(new, "/"); }
    1634         strcat(new, dit->d_name);
    1635     new_with_spaces[0] = ' ';
    1636           strcpy(new_with_spaces+1, new);
    1637           strcat(new_with_spaces, " ");
    1638     if (strstr(skip_these, new_with_spaces))
    1639       {
    1640         fprintf(fout, "%s\n", new);
    1641       }
    1642     else
    1643       {
    1644         if (!lstat(new, &statbuf))
    1645           {
    1646         if (!S_ISLNK(statbuf.st_mode) && S_ISDIR(statbuf.st_mode)) {
    1647           open_and_list_dir(new, skip_these, fout, time_of_last_full_backup);
    1648         }
    1649         else {
    1650           if (time_of_last_full_backup==0 || time_of_last_full_backup<statbuf.st_ctime)
    1651             {
    1652               fprintf(fout, "%s\n", new);
    1653               if ((counter++)>128)
    1654                 {
    1655                   counter=0;
    1656               uberctr++;
    1657                   sprintf(tmp, " %c ", special_dot_char(uberctr));
     1586    if (sth[0] == ' ') {
     1587        skip_these = sth;
     1588    } else {
     1589        skip_these = sth_B;
     1590        sprintf(skip_these, " %s ", sth);
     1591    }
     1592    sprintf(new_with_spaces, " %s ", dir);
     1593    if ((dip = opendir(dir)) == NULL) {
     1594        log_OS_error("opendir");
     1595    } else if (strstr(skip_these, new_with_spaces)) {
     1596        fprintf(fout, "%s\n", dir); // if excluded dir then print dir ONLY
     1597    } else {
     1598        fprintf(fout, "%s\n", dir);
     1599        while ((dit = readdir(dip)) != NULL) {
     1600            i++;
     1601            strcpy(new, dir);
     1602            if (strcmp(dir, "/")) {
     1603                strcat(new, "/");
     1604            }
     1605            strcat(new, dit->d_name);
     1606            new_with_spaces[0] = ' ';
     1607            strcpy(new_with_spaces + 1, new);
     1608            strcat(new_with_spaces, " ");
     1609            if (strstr(skip_these, new_with_spaces)) {
     1610                fprintf(fout, "%s\n", new);
     1611            } else {
     1612                if (!lstat(new, &statbuf)) {
     1613                    if (!S_ISLNK(statbuf.st_mode)
     1614                        && S_ISDIR(statbuf.st_mode)) {
     1615                        open_and_list_dir(new, skip_these, fout,
     1616                                          time_of_last_full_backup);
     1617                    } else {
     1618                        if (time_of_last_full_backup == 0
     1619                            || time_of_last_full_backup <
     1620                            statbuf.st_ctime) {
     1621                            fprintf(fout, "%s\n", new);
     1622                            if ((counter++) > 128) {
     1623                                counter = 0;
     1624                                uberctr++;
     1625                                sprintf(tmp, " %c ",
     1626                                        special_dot_char(uberctr));
    16581627#ifndef _XWIN
    1659               if (!g_text_mode) {
    1660                   newtDrawRootText (77, g_noof_rows - 3, tmp);
    1661                   newtRefresh();
    1662               }
     1628                                if (!g_text_mode) {
     1629                                    newtDrawRootText(77, g_noof_rows - 3,
     1630                                                     tmp);
     1631                                    newtRefresh();
     1632                                }
    16631633#endif
    1664                         }
    1665             }
    1666         }
    1667           }
    1668       }
    1669        }
    1670     }
    1671   if (dip)
    1672     {
    1673       if (closedir(dip) == -1)
    1674         {
    1675       log_OS_error("closedir");
    1676         }
    1677     }
    1678   depth--;
    1679   if (!depth)
    1680     {
    1681       close_evalcall_form ();
    1682       paranoid_free (name_of_evalcall_form);
    1683       paranoid_free(find_skeleton_marker);
    1684       unlink(g_skeleton_filelist);
    1685       log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
    1686     }
    1687   paranoid_free(tmp);
    1688   paranoid_free(sth_B);
    1689   paranoid_free(ith_B);
    1690   paranoid_free(new_with_spaces);
    1691   return(0);
     1634                            }
     1635                        }
     1636                    }
     1637                }
     1638            }
     1639        }
     1640    }
     1641    if (dip) {
     1642        if (closedir(dip) == -1) {
     1643            log_OS_error("closedir");
     1644        }
     1645    }
     1646    depth--;
     1647    if (!depth) {
     1648        close_evalcall_form();
     1649        paranoid_free(name_of_evalcall_form);
     1650        paranoid_free(find_skeleton_marker);
     1651        unlink(g_skeleton_filelist);
     1652        log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
     1653    }
     1654    paranoid_free(tmp);
     1655    paranoid_free(sth_B);
     1656    paranoid_free(ith_B);
     1657    paranoid_free(new_with_spaces);
     1658    return (0);
    16921659}
    16931660
     
    17021669 * @note The returned string points to static data that will be overwritten with each call.
    17031670 */
    1704 char *next_entry(char*incoming)
    1705 {
    1706   static char sz_res[MAX_STR_LEN];
    1707   char *p;
    1708   bool in_quotes=FALSE;
    1709 
    1710   strcpy(sz_res, incoming);
    1711   p = sz_res;
    1712   while((*p!=' ' || in_quotes) && *p!='\0')
    1713     {
    1714       if (*p=='\"') { in_quotes = !in_quotes; }
    1715       p++;
    1716     }
    1717   *p = '\0';
    1718   return(sz_res);
     1671char *next_entry(char *incoming)
     1672{
     1673    static char sz_res[MAX_STR_LEN];
     1674    char *p;
     1675    bool in_quotes = FALSE;
     1676
     1677    strcpy(sz_res, incoming);
     1678    p = sz_res;
     1679    while ((*p != ' ' || in_quotes) && *p != '\0') {
     1680        if (*p == '\"') {
     1681            in_quotes = !in_quotes;
     1682        }
     1683        p++;
     1684    }
     1685    *p = '\0';
     1686    return (sz_res);
    17191687}
    17201688
     
    17341702 * @bug Return value is meaningless.
    17351703 */
    1736 int mondo_makefilelist(char*logfile, char*tmpdir, char*scratchdir,
    1737     char*include_paths, char*excp, int differential, char *userdef_filelist)
     1704int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,
     1705                       char *include_paths, char *excp, int differential,
     1706                       char *userdef_filelist)
    17381707{
    17391708    char sz_datefile_wildcard[] = "/var/cache/mondo-archive/difflevel.%d";
     
    17421711    char *sz_filelist, *exclude_paths, *tmp;
    17431712    int i;
    1744     FILE*fout;
     1713    FILE *fout;
    17451714    char *command;
    1746         time_t time_of_last_full_backup=0;
     1715    time_t time_of_last_full_backup = 0;
    17471716    struct stat statbuf;
    17481717
    1749   malloc_string(command);
    1750   malloc_string(tmp);
    1751   malloc_string(sz_filelist);
    1752   malloc_string(g_skeleton_filelist);
    1753   if (!(exclude_paths = malloc(1000))) { fatal_error("Cannot malloc exclude_paths"); }
    1754   log_msg(3, "Trying to write test string to exclude_paths");
    1755   strcpy(exclude_paths, "/blah /froo");
    1756   log_msg(3, "...Success!");
    1757   sprintf(sz_datefile, sz_datefile_wildcard, 0);
    1758   if (!include_paths && !userdef_filelist)
    1759     { fatal_error("Please supply either include_paths or userdef_filelist"); }
    1760 
     1718    malloc_string(command);
     1719    malloc_string(tmp);
     1720    malloc_string(sz_filelist);
     1721    malloc_string(g_skeleton_filelist);
     1722    if (!(exclude_paths = malloc(1000))) {
     1723        fatal_error("Cannot malloc exclude_paths");
     1724    }
     1725    log_msg(3, "Trying to write test string to exclude_paths");
     1726    strcpy(exclude_paths, "/blah /froo");
     1727    log_msg(3, "...Success!");
     1728    sprintf(sz_datefile, sz_datefile_wildcard, 0);
     1729    if (!include_paths && !userdef_filelist) {
     1730        fatal_error
     1731            ("Please supply either include_paths or userdef_filelist");
     1732    }
    17611733// make hole for filelist
    1762   sprintf(command, "mkdir -p %s/archives", scratchdir);
    1763   paranoid_system(command);
    1764   sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
    1765   make_hole_for_file(sz_filelist);
    1766 
    1767   if (differential==0)
    1768     {
    1769   // restore last good datefile if it exists
    1770       sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
    1771       run_program_and_log_output(command, 3);
    1772   // backup last known good datefile just in case :)
    1773       if (does_file_exist(sz_datefile))
    1774         {
    1775           sprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile);
    1776           paranoid_system(command);
    1777         }
    1778       make_hole_for_file(sz_datefile);
    1779       write_one_liner_data_file(sz_datefile, call_program_and_get_last_line_of_output("date +%s"));
    1780     }
    1781   else if (lstat(sz_datefile, &statbuf))
    1782     {
    1783       log_msg(2, "Warning - unable to find date of previous backup. Full backup instead.");
    1784       differential = 0;
    1785       time_of_last_full_backup = 0;
    1786     }
    1787   else
    1788     {
    1789       time_of_last_full_backup = statbuf.st_mtime;
    1790       log_msg(2, "Differential backup. Yay.");
    1791     }
     1734    sprintf(command, "mkdir -p %s/archives", scratchdir);
     1735    paranoid_system(command);
     1736    sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
     1737    make_hole_for_file(sz_filelist);
     1738
     1739    if (differential == 0) {
     1740        // restore last good datefile if it exists
     1741        sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
     1742        run_program_and_log_output(command, 3);
     1743        // backup last known good datefile just in case :)
     1744        if (does_file_exist(sz_datefile)) {
     1745            sprintf(command, "mv -f %s %s.aborted", sz_datefile,
     1746                    sz_datefile);
     1747            paranoid_system(command);
     1748        }
     1749        make_hole_for_file(sz_datefile);
     1750        write_one_liner_data_file(sz_datefile,
     1751                                  call_program_and_get_last_line_of_output
     1752                                  ("date +%s"));
     1753    } else if (lstat(sz_datefile, &statbuf)) {
     1754        log_msg(2,
     1755                "Warning - unable to find date of previous backup. Full backup instead.");
     1756        differential = 0;
     1757        time_of_last_full_backup = 0;
     1758    } else {
     1759        time_of_last_full_backup = statbuf.st_mtime;
     1760        log_msg(2, "Differential backup. Yay.");
     1761    }
    17921762
    17931763// use user-specified filelist (if specified)
    1794   if (userdef_filelist)
    1795     {
    1796       log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist);
    1797       sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
    1798       if (run_program_and_log_output(command, 3))
    1799         { fatal_error("Failed to copy user-specified filelist"); }
    1800     }
    1801   else
    1802     {
    1803       log_msg(2, "include_paths = '%s'", include_paths);
    1804       log_msg(1, "Calculating filelist");
    1805       sprintf(exclude_paths, " %s %s %s %s %s %s . .. \
    1806 "MNT_CDROM" "MNT_FLOPPY" /media/cdrom /media/cdrecorder \
    1807 /proc /sys /tmp /root/images/mondo /root/images/mindi ",
    1808         excp,
    1809         call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"),
    1810         call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"),
    1811         call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"),
    1812         (tmpdir[0]=='/' && tmpdir[1]=='/')?(tmpdir+1):tmpdir,
    1813         (scratchdir[0]=='/' && scratchdir[1]=='/')?(scratchdir+1):scratchdir
    1814                         );
    1815 
    1816     log_msg(2, "Excluding paths = '%s'", exclude_paths);
    1817     log_msg(2, "Generating skeleton filelist so that we can track our progress");
    1818     sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
    1819     make_hole_for_file(g_skeleton_filelist);
    1820     log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
    1821     log_msg(2, "Opening out filelist to %s", sz_filelist);
    1822     if (!(fout = fopen(sz_filelist, "w"))) { fatal_error("Cannot openout to sz_filelist"); }
    1823     i = 0;
    1824     if (strlen(include_paths)==0)
    1825         {
    1826           log_msg(1, "Including only '/' in %s", sz_filelist);
    1827         open_and_list_dir("/", exclude_paths, fout, time_of_last_full_backup);
    1828         }
    1829     else
    1830         {
    1831         p = include_paths;
    1832         while(*p)
    1833             {
    1834             q = next_entry(p);
    1835             log_msg(1, "Including %s in filelist %s", q, sz_filelist);
    1836             open_and_list_dir(q, exclude_paths, fout, time_of_last_full_backup);
    1837             p += strlen(q);
    1838             while(*p==' ') { p++; }
     1764    if (userdef_filelist) {
     1765        log_msg(1,
     1766                "Using the user-specified filelist - %s - instead of calculating one",
     1767                userdef_filelist);
     1768        sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
     1769        if (run_program_and_log_output(command, 3)) {
     1770            fatal_error("Failed to copy user-specified filelist");
     1771        }
     1772    } else {
     1773        log_msg(2, "include_paths = '%s'", include_paths);
     1774        log_msg(1, "Calculating filelist");
     1775        sprintf(exclude_paths, " %s %s %s %s %s %s . .. \
     1776" MNT_CDROM " " MNT_FLOPPY " /media/cdrom /media/cdrecorder \
     1777/proc /sys /tmp /root/images/mondo /root/images/mindi ", excp, call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"), call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"), call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"), (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
     1778
     1779        log_msg(2, "Excluding paths = '%s'", exclude_paths);
     1780        log_msg(2,
     1781                "Generating skeleton filelist so that we can track our progress");
     1782        sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
     1783        make_hole_for_file(g_skeleton_filelist);
     1784        log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
     1785        log_msg(2, "Opening out filelist to %s", sz_filelist);
     1786        if (!(fout = fopen(sz_filelist, "w"))) {
     1787            fatal_error("Cannot openout to sz_filelist");
     1788        }
     1789        i = 0;
     1790        if (strlen(include_paths) == 0) {
     1791            log_msg(1, "Including only '/' in %s", sz_filelist);
     1792            open_and_list_dir("/", exclude_paths, fout,
     1793                              time_of_last_full_backup);
     1794        } else {
     1795            p = include_paths;
     1796            while (*p) {
     1797                q = next_entry(p);
     1798                log_msg(1, "Including %s in filelist %s", q, sz_filelist);
     1799                open_and_list_dir(q, exclude_paths, fout,
     1800                                  time_of_last_full_backup);
     1801                p += strlen(q);
     1802                while (*p == ' ') {
     1803                    p++;
     1804                }
    18391805            }
    18401806        }
    1841     paranoid_fclose(fout);
    1842     }
    1843   log_msg(2, "Copying new filelist to scratchdir");
    1844   sprintf(command, "mkdir -p %s/archives", scratchdir);
    1845   paranoid_system(command);
    1846   sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
    1847   paranoid_system(command);
    1848   sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
    1849   paranoid_system(command);
    1850   log_msg(2, "Freeing variables");
    1851   paranoid_free(sz_filelist);
    1852   paranoid_free(command);
    1853   paranoid_free(exclude_paths);
    1854   paranoid_free(tmp);
    1855   paranoid_free(g_skeleton_filelist);
    1856   log_msg(2, "Exiting");
    1857   return(0);
     1807        paranoid_fclose(fout);
     1808    }
     1809    log_msg(2, "Copying new filelist to scratchdir");
     1810    sprintf(command, "mkdir -p %s/archives", scratchdir);
     1811    paranoid_system(command);
     1812    sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
     1813    paranoid_system(command);
     1814    sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
     1815    paranoid_system(command);
     1816    log_msg(2, "Freeing variables");
     1817    paranoid_free(sz_filelist);
     1818    paranoid_free(command);
     1819    paranoid_free(exclude_paths);
     1820    paranoid_free(tmp);
     1821    paranoid_free(g_skeleton_filelist);
     1822    log_msg(2, "Exiting");
     1823    return (0);
    18581824}
    18591825
     
    18681834 * it was not found.
    18691835 */
    1870 struct s_node *find_string_at_node (struct s_node *startnode, char *string_to_find)
    1871 {
    1872     /*@ int *********************************************************/
    1873   int noof_chars;
    1874   static int depth=0;
    1875   static char original_string[MAX_STR_LEN];
    1876 
    1877     /*@ sturctures **************************************************/
    1878   struct s_node *node;
    1879 
    1880     /*@ char  *******************************************************/
    1881   char char_to_find;
    1882 
    1883     /*@ bools *******************************************************/
    1884 
    1885   if (!depth) { strcpy(original_string, string_to_find); }
    1886 
    1887   assert(startnode!=NULL);
    1888   assert(string_to_find!=NULL);
    1889 
    1890   noof_chars = strlen (string_to_find) + 1; /* we include the '\0' */
    1891 
    1892   log_msg(7, "starting --- str=%s", string_to_find);
     1836struct s_node *find_string_at_node(struct s_node *startnode,
     1837                                   char *string_to_find)
     1838{
     1839    /*@ int ******************************************************** */
     1840    int noof_chars;
     1841    static int depth = 0;
     1842    static char original_string[MAX_STR_LEN];
     1843
     1844    /*@ sturctures ************************************************* */
     1845    struct s_node *node;
     1846
     1847    /*@ char  ****************************************************** */
     1848    char char_to_find;
     1849
     1850    /*@ bools ****************************************************** */
     1851
     1852    if (!depth) {
     1853        strcpy(original_string, string_to_find);
     1854    }
     1855
     1856    assert(startnode != NULL);
     1857    assert(string_to_find != NULL);
     1858
     1859    noof_chars = strlen(string_to_find) + 1;    /* we include the '\0' */
     1860
     1861    log_msg(7, "starting --- str=%s", string_to_find);
    18931862
    18941863/* walk across tree if necessary */
    1895   node = startnode;
    1896   char_to_find = string_to_find[0];
    1897   if (node->right != NULL && node->ch < char_to_find)
    1898     {
    1899       log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth, char_to_find, node->ch, (node->right)->ch);
    1900       return (find_string_at_node (node->right, string_to_find));
    1901     }
     1864    node = startnode;
     1865    char_to_find = string_to_find[0];
     1866    if (node->right != NULL && node->ch < char_to_find) {
     1867        log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth,
     1868                char_to_find, node->ch, (node->right)->ch);
     1869        return (find_string_at_node(node->right, string_to_find));
     1870    }
    19021871
    19031872/* walk down tree if appropriate */
    1904   if (node->down != NULL && node->ch == char_to_find)
    1905     {
    1906       log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_find);
    1907       depth++;
    1908       node = find_string_at_node (node->down, string_to_find + 1);
    1909       depth--;
    1910       return (node);
    1911     }
    1912 
    1913   if (char_to_find == '\0' && node->ch =='\0')
    1914     {
    1915       log_msg(7, "%s is in tree", original_string);
    1916       return(node);
    1917     }
    1918   else
    1919     {
    1920       log_msg(7, "%s is NOT in tree", original_string);
    1921       return(NULL);
    1922     }
     1873    if (node->down != NULL && node->ch == char_to_find) {
     1874        log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_find);
     1875        depth++;
     1876        node = find_string_at_node(node->down, string_to_find + 1);
     1877        depth--;
     1878        return (node);
     1879    }
     1880
     1881    if (char_to_find == '\0' && node->ch == '\0') {
     1882        log_msg(7, "%s is in tree", original_string);
     1883        return (node);
     1884    } else {
     1885        log_msg(7, "%s is NOT in tree", original_string);
     1886        return (NULL);
     1887    }
    19231888}
    19241889
     
    19331898 * @return The number of matches found.
    19341899 */
    1935 long save_filelist_entries_in_common(
    1936             char*needles_list_fname,
    1937             struct s_node *filelist,
    1938             char*matches_list_fname, bool use_star)
    1939 {
    1940   int retval=0;
    1941   struct s_node *found_node;
    1942   FILE*fin;
    1943   FILE*fout;
    1944   char *fname;
    1945   char *tmp;
    1946   size_t len = 0; // Scrub's patch doesn't work without that
     1900long save_filelist_entries_in_common(char *needles_list_fname,
     1901                                     struct s_node *filelist,
     1902                                     char *matches_list_fname,
     1903                                    bool use_star)
     1904{
     1905    int retval = 0;
     1906    struct s_node *found_node;
     1907    FILE *fin;
     1908    FILE *fout;
     1909    char *fname;
     1910    char *tmp;
     1911    size_t len = 0;             // Scrub's patch doesn't work without that
    19471912
    19481913//  log_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE");
    1949   malloc_string(fname);
    1950   malloc_string(tmp);
    1951   log_msg(5, "starting");
    1952   log_msg(5, "needles_list_fname = %s", needles_list_fname);
    1953   log_msg(5, "matches_list_fname = %s", matches_list_fname);
    1954   if (!(fin = fopen(needles_list_fname, "r"))) { fatal_error("Cannot openin needles_list_fname"); }
    1955   if (!(fout= fopen(matches_list_fname, "w"))) { fatal_error("Cannot openout matches_list_fname"); }
    1956   while(!feof(fin))
    1957     {
     1914    malloc_string(fname);
     1915    malloc_string(tmp);
     1916    log_msg(5, "starting");
     1917    log_msg(5, "needles_list_fname = %s", needles_list_fname);
     1918    log_msg(5, "matches_list_fname = %s", matches_list_fname);
     1919    if (!(fin = fopen(needles_list_fname, "r"))) {
     1920        fatal_error("Cannot openin needles_list_fname");
     1921    }
     1922    if (!(fout = fopen(matches_list_fname, "w"))) {
     1923        fatal_error("Cannot openout matches_list_fname");
     1924    }
     1925    while (!feof(fin)) {
    19581926//      fscanf(fin, "%s\n", fname);
    1959       len = MAX_STR_LEN-1;
    1960       getline(& fname, & len, fin); // patch by Scrub
    1961       if (!use_star)
    1962         {
    1963       if (fname[0]=='/')
    1964         { strcpy(tmp, fname); }
    1965       else
    1966         {
    1967           tmp[0]='/';
    1968           strcpy(tmp+1, fname);
    1969         }
    1970       strcpy(fname, tmp);
    1971         }
    1972       while (strlen(fname)>0 && fname[strlen(fname)-1]<32) { fname[strlen(fname)-1] = '\0'; }
     1927        len = MAX_STR_LEN - 1;
     1928        getline(&fname, &len, fin); // patch by Scrub
     1929        if (!use_star) {
     1930            if (fname[0] == '/') {
     1931                strcpy(tmp, fname);
     1932            } else {
     1933                tmp[0] = '/';
     1934                strcpy(tmp + 1, fname);
     1935            }
     1936            strcpy(fname, tmp);
     1937        }
     1938        while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) {
     1939            fname[strlen(fname) - 1] = '\0';
     1940        }
    19731941
    19741942/*
     
    19771945      sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);
    19781946      system(temporary_string);
    1979 */     
    1980      
    1981       log_msg(5, "Looking for '%s'", fname);
    1982       found_node = find_string_at_node(filelist, fname);
    1983       if (found_node)
    1984         {
    1985       if (found_node->selected)
    1986         {
     1947*/
     1948
     1949        log_msg(5, "Looking for '%s'", fname);
     1950        found_node = find_string_at_node(filelist, fname);
     1951        if (found_node) {
     1952            if (found_node->selected) {
    19871953//              if (use_star)
    1988               if (fname[0]=='/')
    1989             {
    1990           strcpy(tmp, fname+1);
    1991           strcpy(fname, tmp);
    1992         }
    1993           log_msg(5, "Found '%s'", fname);
    1994           turn_wildcard_chars_into_literal_chars(tmp, fname);
    1995           fprintf(fout, "%s\n", tmp);
    1996           retval++;
    1997         }
    1998     }
    1999     }
    2000   paranoid_fclose(fout);
    2001   paranoid_fclose(fin);
    2002   paranoid_free(fname);
    2003   paranoid_free(tmp);
    2004   return(retval);
     1954                if (fname[0] == '/') {
     1955                    strcpy(tmp, fname + 1);
     1956                    strcpy(fname, tmp);
     1957                }
     1958                log_msg(5, "Found '%s'", fname);
     1959                turn_wildcard_chars_into_literal_chars(tmp, fname);
     1960                fprintf(fout, "%s\n", tmp);
     1961                retval++;
     1962            }
     1963        }
     1964    }
     1965    paranoid_fclose(fout);
     1966    paranoid_fclose(fin);
     1967    paranoid_free(fname);
     1968    paranoid_free(tmp);
     1969    return (retval);
    20051970}
    20061971
     
    20181983 * @return 0 for success, nonzero for failure.
    20191984 */
    2020 int add_list_of_files_to_filelist(struct s_node *filelist, char*list_of_files_fname, bool flag_em)
    2021 {
    2022   FILE*fin;
    2023   char*tmp;
    2024   struct s_node *nod;
    2025 
    2026   malloc_string(tmp);
    2027   log_msg(3, "Adding %s to filelist", list_of_files_fname);
    2028   if (!(fin=fopen(list_of_files_fname,"r"))) { iamhere(list_of_files_fname); return(1); }
    2029   for (fgets (tmp, MAX_STR_LEN, fin); !feof(fin);
    2030        fgets (tmp, MAX_STR_LEN, fin))
    2031     {
    2032       if (!tmp[0]) { continue; }
    2033       if ((tmp[strlen(tmp)-1]==13 || tmp[strlen(tmp)-1]==10) && strlen(tmp)>0)
    2034         { tmp[strlen(tmp)-1] = '\0'; }
    2035       log_msg(2, "tmp = '%s'", tmp);
    2036       if (!tmp[0]) { continue; }
    2037       if ((nod = find_string_at_node (filelist, tmp)))
    2038         {
    2039       log_msg(5, "Found '%s' in filelist already. Cool.", tmp);
    2040         }
    2041       else
    2042         {
    2043       add_string_at_node (filelist, tmp);
    2044           nod = find_string_at_node (filelist, tmp);
    2045         }
    2046 
    2047       if (nod && flag_em)
    2048         {
    2049       toggle_path_selection(filelist, tmp, TRUE);
    2050       log_msg (5, "Flagged '%s'", tmp);
    2051     }
    2052     }
    2053   paranoid_fclose(fin);
    2054   paranoid_free(tmp);
    2055   return(0);
     1985int add_list_of_files_to_filelist(struct s_node *filelist,
     1986                                  char *list_of_files_fname, bool flag_em)
     1987{
     1988    FILE *fin;
     1989    char *tmp;
     1990    struct s_node *nod;
     1991
     1992    malloc_string(tmp);
     1993    log_msg(3, "Adding %s to filelist", list_of_files_fname);
     1994    if (!(fin = fopen(list_of_files_fname, "r"))) {
     1995        iamhere(list_of_files_fname);
     1996        return (1);
     1997    }
     1998    for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     1999         fgets(tmp, MAX_STR_LEN, fin)) {
     2000        if (!tmp[0]) {
     2001            continue;
     2002        }
     2003        if ((tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)
     2004            && strlen(tmp) > 0) {
     2005            tmp[strlen(tmp) - 1] = '\0';
     2006        }
     2007        log_msg(2, "tmp = '%s'", tmp);
     2008        if (!tmp[0]) {
     2009            continue;
     2010        }
     2011        if ((nod = find_string_at_node(filelist, tmp))) {
     2012            log_msg(5, "Found '%s' in filelist already. Cool.", tmp);
     2013        } else {
     2014            add_string_at_node(filelist, tmp);
     2015            nod = find_string_at_node(filelist, tmp);
     2016        }
     2017
     2018        if (nod && flag_em) {
     2019            toggle_path_selection(filelist, tmp, TRUE);
     2020            log_msg(5, "Flagged '%s'", tmp);
     2021        }
     2022    }
     2023    paranoid_fclose(fin);
     2024    paranoid_free(tmp);
     2025    return (0);
    20562026}
    20572027
Note: See TracChangeset for help on using the changeset viewer.