# HG changeset patch # User bert # Date 1110840693 0 # Node ID f73bf07ac6da8d2930986be825939493990159a3 # Parent 458111042459652b692d323edd84129de92f4c70 Actually get the directory expansion working properly... diff --git a/conversion/dcm2mnc/dcm2mnc.c b/conversion/dcm2mnc/dcm2mnc.c --- a/conversion/dcm2mnc/dcm2mnc.c +++ b/conversion/dcm2mnc/dcm2mnc.c @@ -5,7 +5,10 @@ @CREATED : June 2001 (Rick Hoge) @MODIFIED : * $Log: dcm2mnc.c,v $ - * Revision 1.5 2005-03-14 22:25:41 bert + * Revision 1.6 2005-03-14 22:51:33 bert + * Actually get the directory expansion working properly... + * + * Revision 1.5 2005/03/14 22:25:41 bert * If a directory is specified on the file list, expand it internally. This gets around shell limitations. * * Revision 1.4 2005/03/03 20:10:14 bert @@ -59,7 +62,7 @@ * ---------------------------------------------------------------------------- */ -static const char rcsid[]="$Header: /private-cvsroot/minc/conversion/dcm2mnc/dcm2mnc.c,v 1.5 2005-03-14 22:25:41 bert Exp $"; +static const char rcsid[]="$Header: /private-cvsroot/minc/conversion/dcm2mnc/dcm2mnc.c,v 1.6 2005-03-14 22:51:33 bert Exp $"; #include #include @@ -196,18 +199,33 @@ if (stat(argv[ifile + 1], &st) == 0 && S_ISDIR(st.st_mode)) { DIR *dp; struct dirent *np; + char *tmp_str; if (G.Debug) { printf("Expanding directory '%s'\n", argv[ifile + 1]); } + length = strlen(argv[ifile + 1]); + dp = opendir(argv[ifile + 1]); if (dp != NULL) { while ((np = readdir(dp)) != NULL) { - if (stat(np->d_name, &st) == 0 && S_ISREG(st.st_mode)) { + /* Generate the full path to the file. + */ + tmp_str = malloc(length + strlen(np->d_name) + 2); + strcpy(tmp_str, argv[ifile + 1]); + if (tmp_str[length-1] != '/') { + tmp_str[length++] = '/'; + } + strcpy(&tmp_str[length], np->d_name); + + if (stat(tmp_str, &st) == 0 && S_ISREG(st.st_mode)) { file_list = realloc(file_list, (num_files + 1) * sizeof(char *)); - file_list[num_files++] = strdup(np->d_name); + file_list[num_files++] = tmp_str; + } + else { + free(tmp_str); } } closedir(dp);