[m-rev.] diff: add -f option to mkinit to avoid command line overflows
Peter Ross
pro at missioncriticalit.com
Mon Jun 18 16:22:29 AEST 2007
On Fri, Jun 15, 2007 at 05:27:07PM +1000, Julien Fischer wrote:
>
> On Thu, 14 Jun 2007, Peter Ross wrote:
>
> >Estimated hours taken: 4
> >Branches: main
> >
> >Windows has a limit on the command line length. Allow mkinit
> >to be passed a list of files to be processed in a file via
> >-f to avoid this limit.
> >
> >compiler/compile_target_code.m:
> > Use the -f option to avoid overflowing the windows
> > command line.
> >
> >util/mkinit.c:
> > Add code to handle the -f option.
>
> I think the idea is that mkinit_erl's options should be kept in
> sync with those of mkinit, so you also need to add a -f option
> to mkinit_erl (which ought to abort if invoked with -f ).
>
Actually we do need to accept the -f flag as well.
===================================================================
Estimated hours taken: 1
Branches: main
Allow mkinit_erl accept the -f flag as well.
util/mkinit_erl.c:
Accept the -f flag.
util/mkinit.c:
util/mkinit_common.c:
util/mkinit_common.h:
Move the process_file_list_file into mkinit_common.c.
Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.117
diff -u -r1.117 mkinit.c
--- util/mkinit.c 14 Jun 2007 11:51:33 -0000 1.117
+++ util/mkinit.c 18 Jun 2007 05:38:39 -0000
@@ -61,10 +61,6 @@
/* --- adjustable limits --- */
#define MAXCALLS 40 /* maximum number of calls per function */
-#define MAXFILENAME 4096 /* maximimum file name length */
-#define NUMFILES 128 /* intial size of files array */
-#define FACTOR 2 /* factor to increase files array by */
-
/* --- used to collect a list of strings --- */
static const char if_need_to_init[] =
@@ -280,9 +276,6 @@
static const char *hl_entry_point = "main_2_p_0";
static const char *grade = "";
static int maxcalls = MAXCALLS;
-static int num_files;
-static int size_of_files;
-static char **files = NULL;
static MR_bool output_main_func = MR_TRUE;
static MR_bool need_initialization_code = MR_FALSE;
static MR_bool need_tracing = MR_FALSE;
@@ -533,7 +526,6 @@
/* --- function prototypes --- */
static void parse_options(int argc, char *argv[]);
-static void process_file_list_file(char *filename);
static void usage(void);
static void output_complexity_proc(const char *procname);
static void output_complexity_experiment_table(const char *filename);
@@ -856,46 +848,6 @@
if (num_files <= 0) {
usage();
- }
-}
-
-static void
-process_file_list_file(char *filename)
-{
- FILE *fp;
- char *line;
-
- fp = fopen(filename, "r");
- if (fp == NULL) {
- fprintf(stderr, "%s: error opening file `%s': %s\n",
- MR_progname, filename, strerror(errno));
- num_errors++;
- return;
- }
- /* intialize the files structure, if required */
- if (files == NULL) {
- num_files = 0;
- size_of_files = NUMFILES;
- files = (char **) checked_malloc(sizeof(char *) * NUMFILES);
- }
-
- while ((line = read_line(filename, fp, MAXFILENAME)) != NULL) {
- /* Ignore blank lines */
- if (line[0] != '\0') {
- if (num_files >= size_of_files) {
- size_of_files *= FACTOR;
- files = (char **)
- realloc(files, size_of_files * sizeof(char *));
-
- if (files == NULL) {
- fprintf(stderr, "%s: unable to realloc\n", MR_progname);
- exit(EXIT_FAILURE);
- }
- }
-
- files[num_files] = line;
- num_files++;
- }
}
}
Index: util/mkinit_common.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit_common.c,v
retrieving revision 1.1
diff -u -r1.1 mkinit_common.c
--- util/mkinit_common.c 8 Jun 2007 00:47:16 -0000 1.1
+++ util/mkinit_common.c 18 Jun 2007 05:38:39 -0000
@@ -39,6 +39,11 @@
const char *MR_progname = NULL;
int num_errors = 0;
+int num_files;
+char **files = NULL;
+
+static int size_of_files;
+
/* List of directories to search for init files */
static String_List *init_file_dirs = NULL;
@@ -46,6 +51,11 @@
/* Pointer to tail of the init_file_dirs list */
static String_List **init_file_dirs_tail = &init_file_dirs;
+/* --- adjustable limits --- */
+#define MAXFILENAME 4096 /* maximimum file name length */
+#define NUMFILES 128 /* intial size of files array */
+#define FACTOR 2 /* factor to increase files array by */
+
/* --- function prototypes --- */
static char *find_init_file(const char *base_name);
@@ -53,6 +63,48 @@
/*---------------------------------------------------------------------------*/
+void
+process_file_list_file(char *filename)
+{
+ FILE *fp;
+ char *line;
+
+ fp = fopen(filename, "r");
+ if (fp == NULL) {
+ fprintf(stderr, "%s: error opening file `%s': %s\n",
+ MR_progname, filename, strerror(errno));
+ num_errors++;
+ return;
+ }
+ /* intialize the files structure, if required */
+ if (files == NULL) {
+ num_files = 0;
+ size_of_files = NUMFILES;
+ files = (char **) checked_malloc(sizeof(char *) * NUMFILES);
+ }
+
+ while ((line = read_line(filename, fp, MAXFILENAME)) != NULL) {
+ /* Ignore blank lines */
+ if (line[0] != '\0') {
+ if (num_files >= size_of_files) {
+ size_of_files *= FACTOR;
+ files = (char **)
+ realloc(files, size_of_files * sizeof(char *));
+
+ if (files == NULL) {
+ fprintf(stderr, "%s: unable to realloc\n", MR_progname);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ files[num_files] = line;
+ num_files++;
+ }
+ }
+}
+
+/*---------------------------------------------------------------------------*/
+
/*
** If the `-o' option was used to specify the output file,
** and the file name specified is not `-' (which we take to mean stdout),
@@ -100,15 +152,15 @@
*/
void
-do_path_search(char **files, int num_files)
+do_path_search(char **lfiles, int lnum_files)
{
int filenum;
char *init_file;
- for (filenum = 0; filenum < num_files; filenum++) {
- init_file = find_init_file(files[filenum]);
+ for (filenum = 0; filenum < lnum_files; filenum++) {
+ init_file = find_init_file(lfiles[filenum]);
if (init_file != NULL) {
- files[filenum] = init_file;
+ lfiles[filenum] = init_file;
}
}
}
Index: util/mkinit_common.h
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit_common.h,v
retrieving revision 1.1
diff -u -r1.1 mkinit_common.h
--- util/mkinit_common.h 8 Jun 2007 00:47:16 -0000 1.1
+++ util/mkinit_common.h 18 Jun 2007 05:38:39 -0000
@@ -37,12 +37,15 @@
extern const char *MR_progname;
extern int num_errors;
+extern int num_files;
+extern char **files;
/* --- function prototypes --- */
+extern void process_file_list_file(char *filename);
extern void set_output_file(const char *output_file_name);
extern void add_init_file_dir(const char *dir_name);
-extern void do_path_search(char **files, int num_files);
+extern void do_path_search(char **lfiles, int lnum_files);
extern char *read_line(const char *filename, FILE *fp, int max);
extern int get_line(FILE *file, char *line, int line_max);
extern void *checked_malloc(size_t size);
Index: util/mkinit_erl.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit_erl.c,v
retrieving revision 1.2
diff -u -r1.2 mkinit_erl.c
--- util/mkinit_erl.c 14 Jun 2007 01:50:30 -0000 1.2
+++ util/mkinit_erl.c 18 Jun 2007 05:38:39 -0000
@@ -122,8 +122,6 @@
static const char *output_file_name = NULL;
static const char *grade = "";
static const char *module_name = "unknown_module_name";
-static int num_files;
-static char **files;
static Task output_task = TASK_OUTPUT_INIT_PROG;
/* --- code fragments to put in the output file --- */
@@ -291,13 +289,19 @@
int c;
int i;
String_List *tmp_slist;
+ int seen_f_option = 0;
/*
** The set of options for mkinit and mkinit_erl should be
** kept in sync, even if they may not necessarily make sense.
*/
- while ((c = getopt(argc, argv, "A:c:g:iI:lo:r:tw:xX:ksm:")) != EOF) {
+ while ((c = getopt(argc, argv, "A:c:f:g:iI:lo:r:tw:xX:ksm:")) != EOF) {
switch (c) {
+ case 'f':
+ process_file_list_file(optarg);
+ seen_f_option = 1;
+ break;
+
case 'g':
grade = optarg;
break;
@@ -343,12 +347,26 @@
}
}
- num_files = argc - optind;
+ if (seen_f_option) {
+ /*
+ ** -f could be made compatible if we copied the filenames
+ ** from argv into files.
+ **
+ */
+ if ((argc - optind) > 0) {
+ fprintf(stderr,
+ "%s: -f incompatible with filenames on the command line\n",
+ MR_progname);
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ num_files = argc - optind;
+ files = argv + optind;
+ }
+
if (num_files <= 0) {
usage();
}
-
- files = argv + optind;
}
static void
@@ -358,6 +376,7 @@
fputs("Options:\n", stderr);
fputs(" -c maxcalls:\t(error)\n", stderr);
fputs(" -g grade:\tset the grade of the executable\n", stderr);
+ fputs(" -f filename:\tprocess the files one per line in filename\n", stderr);
fputs(" -i:\t\t(error)\n", stderr);
fputs(" -l:\t\t(error)\n", stderr);
fputs(" -o file:\toutput to the named file\n", stderr);
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list