changeset 2020:f73bf07ac6da

Actually get the directory expansion working properly...
author bert <bert>
date Mon, 14 Mar 2005 22:51:33 +0000
parents 458111042459
children 573cfcb2f4d1
files conversion/dcm2mnc/dcm2mnc.c
diffstat 1 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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 <sys/types.h>
 #include <sys/stat.h>
@@ -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);