update isl to version 0.10
[ppcg.git] / rewrite.c
blobfa472cf7bfce9dd298365fccd65380330283aff6
1 /*
2 * Copyright 2010 INRIA Saclay
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8 * 91893 Orsay, France
9 */
11 #include <ctype.h>
12 #include <limits.h>
13 #include <string.h>
15 #include "rewrite.h"
17 static char *skip_spaces(char *s)
19 while (isspace(*s))
20 ++s;
21 return s;
24 static int is_begin_scop(char *line)
26 line = skip_spaces(line);
27 if (*line != '#')
28 return 0;
29 line = skip_spaces(line + 1);
30 if (strncmp(line, "pragma", sizeof("pragma") - 1))
31 return 0;
32 line = skip_spaces(line + sizeof("pragma") - 1);
33 if (strncmp(line, "scop", sizeof("scop") - 1))
34 return 0;
35 return 1;
38 static int is_end_scop(char *line)
40 line = skip_spaces(line);
41 if (*line != '#')
42 return 0;
43 line = skip_spaces(line + 1);
44 if (strncmp(line, "pragma", sizeof("pragma") - 1))
45 return 0;
46 line = skip_spaces(line + sizeof("pragma") - 1);
47 if (strncmp(line, "endscop", sizeof("endscop") - 1))
48 return 0;
49 return 1;
52 void copy_before_scop(FILE *input, FILE *output)
54 char line[1024];
55 while (fgets(line, sizeof(line), input)) {
56 fprintf(output, "%s", line);
57 if (is_begin_scop(line))
58 break;
62 void copy_after_scop(FILE *input, FILE *output)
64 char line[1024];
65 while (fgets(line, sizeof(line), input)) {
66 if (is_end_scop(line)) {
67 fprintf(output, "%s", line);
68 break;
71 while (fgets(line, sizeof(line), input)) {
72 fprintf(output, "%s", line);