changeset 2545:4b26fb8b776c

* added a patch from Steve Robbins removing references to PATH_MAX
author Andrew L Janke <a.janke@gmail.com>
date Wed, 22 Feb 2012 00:53:41 +1000
parents 8793cdffd21c
children f99952fb216f
files Makefile.am libsrc/read_file_names.c libsrc/read_file_names.h progs/mincaverage/mincaverage.c progs/minccalc/minccalc.c progs/mincconcat/mincconcat.c progs/mincmath/mincmath.c
diffstat 7 files changed, 123 insertions(+), 355 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am
+++ b/Makefile.am
@@ -67,6 +67,7 @@
 # not part of the installation.
 #
 noinst_HEADERS = \
+	libsrc/read_file_names.h \
 	libsrc/minc_basic.h \
 	libsrc/minc_config.h \
 	libsrc/minc_error.h \
@@ -425,6 +426,7 @@
 libminc2_la_LDFLAGS = -version-info 2:3:1
 libminc2_la_SOURCES = \
 	libsrc/ParseArgv.c \
+	libsrc/read_file_names.c \
 	libsrc/dim_conversion.c \
 	libsrc/image_conversion.c \
 	libsrc/minc_convenience.c \
new file mode 100644
--- /dev/null
+++ b/libsrc/read_file_names.c
@@ -0,0 +1,99 @@
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "read_file_names.h"
+
+#define FILE_NAME_ALLOC_SIZE 10
+#define FILE_PATH_MAX 2046
+
+
+
+/* ----------------------------- MNI Header -----------------------------------
+@NAME       : read_file_names
+@INPUT      : filelist - name of file from which to read names
+@OUTPUT     : num_files - number of files read in
+@RETURNS    : Pointer to a NULL-terminated array of file names
+@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
+              "-" is specified. Returns NULL if an error occurs. If
+              no error occurs, then a pointer to an empty array is 
+              returned and num_files is zero.
+@METHOD     : 
+@GLOBALS    : 
+@CALLS      : 
+@CREATED    : March 8, 1995 (Peter Neelin)
+@MODIFIED   : 
+---------------------------------------------------------------------------- */
+char **read_file_names(char *filelist, int *num_files)
+{
+   char **files;
+   int array_size;
+   int nfiles;
+   FILE *fp;
+   char line[FILE_PATH_MAX+1];
+   int length;
+
+   /* Open the file */
+   if (strcmp(filelist, "-") == 0) {
+      fp = stdin;
+   }
+   else {
+      fp = fopen(filelist, "r");
+      if (fp == NULL) {
+         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
+         return NULL;
+      }
+   }
+
+   /* Allocate an initial array and NULL-terminate it */
+   array_size = FILE_NAME_ALLOC_SIZE;
+   files = malloc(sizeof(*files) * array_size);
+   if (files == NULL) {
+      (void) fprintf(stderr, "Error allocating memory\n");
+      return NULL;
+   }
+   nfiles = 0;
+   files[nfiles] = NULL;
+
+   /* Read in file names */
+   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
+
+      /* Remove a trailing newline and check that there is a name */
+      length = strlen(line);
+      if ((length > 0) && (line[length-1] == '\n')) {
+         line[length-1] = '\0';
+         length--;
+      }
+      if (length == 0) continue;
+
+      /* Make room for names if needed */
+      while (nfiles >= array_size-1) {
+         array_size += FILE_NAME_ALLOC_SIZE;
+         files = realloc(files, sizeof(*files) * array_size);
+         if (files == NULL) {
+            (void) fprintf(stderr, "Error allocating memory\n");
+            return NULL;
+         }
+      }
+
+      /* Save the name, making sure that the list is NULL-terminated */
+      files[nfiles] = strdup(line);
+      if (files[nfiles] == NULL) {
+         (void) fprintf(stderr, "Error allocating memory\n");
+         return NULL;
+      }
+      nfiles++;
+      files[nfiles] = NULL;
+   }
+
+   /* Close the file */
+   (void) fclose(fp);
+
+   /* Return the number of files */
+   *num_files = nfiles;
+
+   return files;
+}
new file mode 100644
--- /dev/null
+++ b/libsrc/read_file_names.h
@@ -0,0 +1,18 @@
+
+
+/* ----------------------------- MNI Header -----------------------------------
+@NAME       : read_file_names
+@INPUT      : filelist - name of file from which to read names
+@OUTPUT     : num_files - number of files read in
+@RETURNS    : Pointer to a NULL-terminated array of file names
+@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
+              "-" is specified. Returns NULL if an error occurs. If
+              no error occurs, then a pointer to an empty array is 
+              returned and num_files is zero.
+@METHOD     : 
+@GLOBALS    : 
+@CALLS      : 
+@CREATED    : March 8, 1995 (Peter Neelin)
+@MODIFIED   : 
+---------------------------------------------------------------------------- */
+char **read_file_names(char *filelist, int *num_files);
--- a/progs/mincaverage/mincaverage.c
+++ b/progs/mincaverage/mincaverage.c
@@ -105,6 +105,7 @@
 #include <ParseArgv.h>
 #include <time_stamp.h>
 #include <voxel_loop.h>
+#include "read_file_names.h"
 
 /* Constants */
 
@@ -165,7 +166,6 @@
                           double *output_data[],
                           Loop_Info *loop_info);
 static int get_double_list(char *dst, char *key, char *nextarg);
-static char **read_file_names(char *filelist, int *num_files);
 
 /* Argument variables */
 static int clobber = FALSE;
@@ -1010,91 +1010,3 @@
 
    return TRUE;
 }
-
-/* ----------------------------- MNI Header -----------------------------------
-@NAME       : read_file_names
-@INPUT      : filelist - name of file from which to read names
-@OUTPUT     : num_files - number of files read in
-@RETURNS    : Pointer to a NULL-terminated array of file names
-@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
-              "-" is specified. Returns NULL if an error occurs. If
-              no error occurs, then a pointer to an empty array is 
-              returned and num_files is zero.
-@METHOD     : 
-@GLOBALS    : 
-@CALLS      : 
-@CREATED    : March 8, 1995 (Peter Neelin)
-@MODIFIED   : 
----------------------------------------------------------------------------- */
-static char **read_file_names(char *filelist, int *num_files)
-{
-#define FILE_NAME_ALLOC_SIZE 10
-   char **files;
-   int array_size;
-   int nfiles;
-   FILE *fp;
-   char line[PATH_MAX+1];
-   int length;
-
-   /* Open the file */
-   if (strcmp(filelist, "-") == 0) {
-      fp = stdin;
-   }
-   else {
-      fp = fopen(filelist, "r");
-      if (fp == NULL) {
-         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
-         return NULL;
-      }
-   }
-
-   /* Allocate an initial array and NULL-terminate it */
-   array_size = FILE_NAME_ALLOC_SIZE;
-   files = malloc(sizeof(*files) * array_size);
-   if (files == NULL) {
-      (void) fprintf(stderr, "Error allocating memory\n");
-      return NULL;
-   }
-   nfiles = 0;
-   files[nfiles] = NULL;
-
-   /* Read in file names */
-   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
-
-      /* Remove a trailing newline and check that there is a name */
-      length = strlen(line);
-      if ((length > 0) && (line[length-1] == '\n')) {
-         line[length-1] = '\0';
-         length--;
-      }
-      if (length == 0) continue;
-
-      /* Make room for names if needed */
-      while (nfiles >= array_size-1) {
-         array_size += FILE_NAME_ALLOC_SIZE;
-         files = realloc(files, sizeof(*files) * array_size);
-         if (files == NULL) {
-            (void) fprintf(stderr, "Error allocating memory\n");
-            return NULL;
-         }
-      }
-
-      /* Save the name, making sure that the list is NULL-terminated */
-      files[nfiles] = strdup(line);
-      if (files[nfiles] == NULL) {
-         (void) fprintf(stderr, "Error allocating memory\n");
-         return NULL;
-      }
-      nfiles++;
-      files[nfiles] = NULL;
-   }
-
-   /* Close the file */
-   (void) fclose(fp);
-
-   /* Return the number of files */
-   *num_files = nfiles;
-
-   return files;
-}
-
--- a/progs/minccalc/minccalc.c
+++ b/progs/minccalc/minccalc.c
@@ -121,6 +121,7 @@
 #include <voxel_loop.h>
 #include <time_stamp.h>
 #include "node.h"
+#include "read_file_names.h"
 
 /* Constants */
 
@@ -143,7 +144,6 @@
                     int input_vector_length, double *input_data[],
                     int output_num_buffers, int output_vector_length,
                     double *output_data[], Loop_Info *loop_info);
-static char **read_file_names(char *filelist, int *num_files);
 static char *read_expression_file(char *filename);
 static int get_list_option(char *dst, char *key, int argc, char **argv);
 
@@ -521,93 +521,6 @@
 }
 
 /* ----------------------------- MNI Header -----------------------------------
-@NAME       : read_file_names
-@INPUT      : filelist - name of file from which to read names
-@OUTPUT     : num_files - number of files read in
-@RETURNS    : Pointer to a NULL-terminated array of file names
-@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
-              "-" is specified. Returns NULL if an error occurs. If
-              no error occurs, then a pointer to an empty array is 
-              returned and num_files is zero.
-@METHOD     : 
-@GLOBALS    : 
-@CALLS      : 
-@CREATED    : March 8, 1995 (Peter Neelin)
-@MODIFIED   : 
----------------------------------------------------------------------------- */
-static char **read_file_names(char *filelist, int *num_files)
-{
-#define FILE_NAME_ALLOC_SIZE 10
-   char **files;
-   int array_size;
-   int nfiles;
-   FILE *fp;
-   char line[PATH_MAX+1];
-   int length;
-
-   /* Open the file */
-   if (strcmp(filelist, "-") == 0) {
-      fp = stdin;
-   }
-   else {
-      fp = fopen(filelist, "r");
-      if (fp == NULL) {
-         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
-         return NULL;
-      }
-   }
-
-   /* Allocate an initial array and NULL-terminate it */
-   array_size = FILE_NAME_ALLOC_SIZE;
-   files = malloc(sizeof(*files) * array_size);
-   if (files == NULL) {
-      (void) fprintf(stderr, "Error allocating memory\n");
-      return NULL;
-   }
-   nfiles = 0;
-   files[nfiles] = NULL;
-
-   /* Read in file names */
-   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
-
-      /* Remove a trailing newline and check that there is a name */
-      length = strlen(line);
-      if ((length > 0) && (line[length-1] == '\n')) {
-         line[length-1] = '\0';
-         length--;
-      }
-      if (length == 0) continue;
-
-      /* Make room for names if needed */
-      while (nfiles >= array_size-1) {
-         array_size += FILE_NAME_ALLOC_SIZE;
-         files = realloc(files, sizeof(*files) * array_size);
-         if (files == NULL) {
-            (void) fprintf(stderr, "Error allocating memory\n");
-            return NULL;
-         }
-      }
-
-      /* Save the name, making sure that the list is NULL-terminated */
-      files[nfiles] = strdup(line);
-      if (files[nfiles] == NULL) {
-         (void) fprintf(stderr, "Error allocating memory\n");
-         return NULL;
-      }
-      nfiles++;
-      files[nfiles] = NULL;
-   }
-
-   /* Close the file */
-   (void) fclose(fp);
-
-   /* Return the number of files */
-   *num_files = nfiles;
-
-   return files;
-}
-
-/* ----------------------------- MNI Header -----------------------------------
 @NAME       : read_expression_file
 @INPUT      : filename - Name of file from which to read expression
 @OUTPUT     : (none)
--- a/progs/mincconcat/mincconcat.c
+++ b/progs/mincconcat/mincconcat.c
@@ -129,6 +129,7 @@
 #include <ParseArgv.h>
 #include <time_stamp.h>
 #include <voxel_loop.h>
+#include "read_file_names.h"
 
 /* Constants */
 #ifndef TRUE
@@ -213,7 +214,6 @@
 static int sort_function(const void *value1, const void *value2);
 static void create_concat_file(int inmincid, Concat_Info *concat_info);
 static void update_history(int mincid, char *arg_string);
-static char **read_file_names(char *filelist, int *num_files);
 
 /* Globals */
 static int Sort_ascending = TRUE;
@@ -1457,91 +1457,3 @@
    free(string);
 
 }
-
-/* ----------------------------- MNI Header -----------------------------------
-@NAME       : read_file_names
-@INPUT      : filelist - name of file from which to read names
-@OUTPUT     : num_files - number of files read in
-@RETURNS    : Pointer to a NULL-terminated array of file names
-@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
-              "-" is specified. Returns NULL if an error occurs. If
-              no error occurs, then a pointer to an empty array is 
-              returned and num_files is zero.
-@METHOD     : 
-@GLOBALS    : 
-@CALLS      : 
-@CREATED    : March 8, 1995 (Peter Neelin)
-@MODIFIED   : 
----------------------------------------------------------------------------- */
-static char **read_file_names(char *filelist, int *num_files)
-{
-#define FILE_NAME_ALLOC_SIZE 10
-   char **files;
-   int array_size;
-   int nfiles;
-   FILE *fp;
-   char line[PATH_MAX+1];
-   int length;
-
-   /* Open the file */
-   if (strcmp(filelist, "-") == 0) {
-      fp = stdin;
-   }
-   else {
-      fp = fopen(filelist, "r");
-      if (fp == NULL) {
-         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
-         return NULL;
-      }
-   }
-
-   /* Allocate an initial array and NULL-terminate it */
-   array_size = FILE_NAME_ALLOC_SIZE;
-   files = malloc(sizeof(*files) * array_size);
-   if (files == NULL) {
-      (void) fprintf(stderr, "Error allocating memory\n");
-      return NULL;
-   }
-   nfiles = 0;
-   files[nfiles] = NULL;
-
-   /* Read in file names */
-   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
-
-      /* Remove a trailing newline and check that there is a name */
-      length = strlen(line);
-      if ((length > 0) && (line[length-1] == '\n')) {
-         line[length-1] = '\0';
-         length--;
-      }
-      if (length == 0) continue;
-
-      /* Make room for names if needed */
-      while (nfiles >= array_size-1) {
-         array_size += FILE_NAME_ALLOC_SIZE;
-         files = realloc(files, sizeof(*files) * array_size);
-         if (files == NULL) {
-            (void) fprintf(stderr, "Error allocating memory\n");
-            return NULL;
-         }
-      }
-
-      /* Save the name, making sure that the list is NULL-terminated */
-      files[nfiles] = strdup(line);
-      if (files[nfiles] == NULL) {
-         (void) fprintf(stderr, "Error allocating memory\n");
-         return NULL;
-      }
-      nfiles++;
-      files[nfiles] = NULL;
-   }
-
-   /* Close the file */
-   (void) fclose(fp);
-
-   /* Return the number of files */
-   *num_files = nfiles;
-
-   return files;
-}
-
--- a/progs/mincmath/mincmath.c
+++ b/progs/mincmath/mincmath.c
@@ -123,6 +123,7 @@
 #include <ParseArgv.h>
 #include <time_stamp.h>
 #include <voxel_loop.h>
+#include "read_file_names.h"
 
 /* Constants */
 
@@ -219,7 +220,6 @@
                      int output_num_buffers, int output_vector_length,
                      double *output_data[],
                      Loop_Info *loop_info);
-static char **read_file_names(char *filelist, int *num_files);
 
 /* Argument variables */
 static int clobber = FALSE;
@@ -929,91 +929,3 @@
 
    return;
 }
-
-/* ----------------------------- MNI Header -----------------------------------
-@NAME       : read_file_names
-@INPUT      : filelist - name of file from which to read names
-@OUTPUT     : num_files - number of files read in
-@RETURNS    : Pointer to a NULL-terminated array of file names
-@DESCRIPTION: Reads in a list of file names from file filelist or stdin if 
-              "-" is specified. Returns NULL if an error occurs. If
-              no error occurs, then a pointer to an empty array is 
-              returned and num_files is zero.
-@METHOD     : 
-@GLOBALS    : 
-@CALLS      : 
-@CREATED    : March 8, 1995 (Peter Neelin)
-@MODIFIED   : 
----------------------------------------------------------------------------- */
-static char **read_file_names(char *filelist, int *num_files)
-{
-#define FILE_NAME_ALLOC_SIZE 10
-   char **files;
-   int array_size;
-   int nfiles;
-   FILE *fp;
-   char line[PATH_MAX+1];
-   int length;
-
-   /* Open the file */
-   if (strcmp(filelist, "-") == 0) {
-      fp = stdin;
-   }
-   else {
-      fp = fopen(filelist, "r");
-      if (fp == NULL) {
-         (void) fprintf(stderr, "Error opening file \"%s\"\n", filelist);
-         return NULL;
-      }
-   }
-
-   /* Allocate an initial array and NULL-terminate it */
-   array_size = FILE_NAME_ALLOC_SIZE;
-   files = malloc(sizeof(*files) * array_size);
-   if (files == NULL) {
-      (void) fprintf(stderr, "Error allocating memory\n");
-      return NULL;
-   }
-   nfiles = 0;
-   files[nfiles] = NULL;
-
-   /* Read in file names */
-   while (fgets(line, sizeof(line)/sizeof(line[0]), fp) != NULL) {
-
-      /* Remove a trailing newline and check that there is a name */
-      length = strlen(line);
-      if ((length > 0) && (line[length-1] == '\n')) {
-         line[length-1] = '\0';
-         length--;
-      }
-      if (length == 0) continue;
-
-      /* Make room for names if needed */
-      while (nfiles >= array_size-1) {
-         array_size += FILE_NAME_ALLOC_SIZE;
-         files = realloc(files, sizeof(*files) * array_size);
-         if (files == NULL) {
-            (void) fprintf(stderr, "Error allocating memory\n");
-            return NULL;
-         }
-      }
-
-      /* Save the name, making sure that the list is NULL-terminated */
-      files[nfiles] = strdup(line);
-      if (files[nfiles] == NULL) {
-         (void) fprintf(stderr, "Error allocating memory\n");
-         return NULL;
-      }
-      nfiles++;
-      files[nfiles] = NULL;
-   }
-
-   /* Close the file */
-   (void) fclose(fp);
-
-   /* Return the number of files */
-   *num_files = nfiles;
-
-   return files;
-}
-