summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'hfile2array/hfile2array.c')
-rw-r--r--hfile2array/hfile2array.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/hfile2array/hfile2array.c b/hfile2array/hfile2array.c
index 19e658d..a6d7a5b 100644
--- a/hfile2array/hfile2array.c
+++ b/hfile2array/hfile2array.c
@@ -43,8 +43,9 @@
43 43
44int main(int argc, char **argv) 44int main(int argc, char **argv)
45{ 45{
46 FILE *out, *in; 46 FILE *out, *in, *in_hdr;
47 char line[200] = "uint8_t "; 47 char line[200] = "uint8_t ";
48 char line_hdr[200];
48 49
49 if (argc != 4) 50 if (argc != 4)
50 { 51 {
@@ -68,12 +69,38 @@ int main(int argc, char **argv)
68 printf ("Can not open %s\n", *argv[1]); 69 printf ("Can not open %s\n", *argv[1]);
69 return (-1); 70 return (-1);
70 } 71 }
72
73 in_hdr = fopen("header.txt", "rt");
74
75 if (in_hdr == NULL)
76 {
77 printf ("Can not open header.tx\n");
78 return (-1);
79 }
80
81 while (1)
82 {
83 if (fgets(line_hdr, 200, in_hdr) != NULL)
84 {
85 if (fputs(line_hdr, out) != 0)
86 {
87 printf ("fputs %s error\n", line_hdr);
88 goto error;
89 }
90 }
91 else
92 {
93 /* EOF reached */
94 break;
95 }
96 }
97
71 strcat (line, (const char *)(*argv++)); 98 strcat (line, (const char *)(*argv++));
72 strcat (line, "[] = {\n"); 99 strcat (line, "[] = {\n");
73 100
74 if (fputs(line, out) != 0) 101 if (fputs(line, out) != 0)
75 { 102 {
76 printf ("fputs %s error\n", fputs); 103 printf ("fputs %s error\n", line);
77 goto error; 104 goto error;
78 } 105 }
79 106
@@ -101,12 +128,14 @@ int main(int argc, char **argv)
101 } 128 }
102 129
103 fclose(in); 130 fclose(in);
131 fclose(in_hdr);
104 fclose(out); 132 fclose(out);
105 133
106 return 0; 134 return 0;
107 135
108error: 136error:
109 fclose(in); 137 fclose(in);
138 fclose(in_hdr);
110 fclose(out); 139 fclose(out);
111 140
112 return (-1); 141 return (-1);