Merge branch 'nouveau-import'
[mesa.git] / src / mesa / shader / slang / library / syn_to_c.c
1 #include <stdio.h>
2
3 static int was_space = 0;
4 static int first_char = 1;
5
6 static void put_char (int c)
7 {
8 if (c == '\n') {
9 if (!first_char) {
10 fputs ("\\n\"\n\"", stdout);
11 first_char = 1;
12 }
13 }
14 else {
15 first_char = 0;
16 if (c == '\\')
17 fputs ("\\\\", stdout);
18 else if (c == '\"')
19 fputs ("\\\"", stdout);
20 else if (!was_space || !(c == ' ' || c == '\t'))
21 fputc (c, stdout);
22 was_space = (c == ' ' || c == '\t');
23 }
24 }
25
26 int main (int argc, char *argv[])
27 {
28 int c;
29 FILE *f;
30
31 if (argc == 1)
32 return 1;
33 f = fopen (argv[1], "r");
34 if (f == NULL)
35 return 1;
36
37 fputs ("\n", stdout);
38 fputs ("/* DO NOT EDIT - THIS FILE IS AUTOMATICALLY GENERATED FROM THE .syn FILE */\n", stdout);
39 fputs ("\n", stdout);
40 fputs ("\"", stdout);
41 c = getc (f);
42 while (c != EOF) {
43 if (c == '/') {
44 int c2 = getc (f);
45 if (c2 == '*') {
46 was_space = 0;
47 c = getc (f);
48 for (;;) {
49 if (c == '*') {
50 c2 = getc (f);
51 if (c2 == '/')
52 break;
53 }
54 c = getc (f);
55 }
56 }
57 else {
58 put_char (c);
59 put_char (c2);
60 }
61 }
62 else {
63 put_char (c);
64 }
65 c = getc (f);
66 }
67 fputs ("\"\n", stdout);
68
69 fclose (f);
70 return 0;
71 }
72