cloog_names_read_strings: do not generate names if they cannot be read
[cloog/uuh.git] / source / input.c
blobd2fd261e519c1ed152bece866d025e0aa9e6fb8c
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "../include/cloog/cloog.h"
6 #define ALLOC(type) (type*)malloc(sizeof(type))
8 static char *next_line(FILE *input, char *line, unsigned len)
10 char *p;
12 do {
13 if (!(p = fgets(line, len, input)))
14 return NULL;
15 while (isspace(*p) && *p != '\n')
16 ++p;
17 } while (*p == '#' || *p == '\n');
19 return p;
22 /**
23 * Read input from a .cloog file, putting most of the information
24 * in the returned CloogInput. The chosen language is put in
25 * options->language.
27 CloogInput *cloog_input_read(FILE *file, CloogOptions *options)
29 char line[MAX_STRING];
30 CloogInput *input;
31 char language;
32 int nb_par;
34 input = ALLOC(CloogInput);
35 if (!input)
36 cloog_die("memory overflow.\n");
38 /* First of all, we read the language to use. */
39 if (!next_line(file, line, sizeof(line)))
40 cloog_die("Input error.\n");
41 if (sscanf(line, "%c", &language) != 1)
42 cloog_die("Input error.\n");
44 if (language == 'f')
45 options->language = LANGUAGE_FORTRAN;
46 else
47 options->language = LANGUAGE_C;
49 /* We then read the context data. */
50 input->context = cloog_domain_read_context(options->state, file);
51 nb_par = cloog_domain_parameter_dimension(input->context);
53 input->ud = cloog_union_domain_read(file, nb_par, options);
55 return input;