bash - Sharing header file between a C program and a shell script -
How do I share a C header file with a shell script?
Communicates with C program through pipelines called shell script. Suppose that enum SAMPLE_ONE, which is defined in the C header file, pipe written by the C program. Shell script reads the value of enum from the pipe. What is a way to share the header file between the C programs and shell scripts - in such a way that I only need to update the header file once and do not have to write the same header string in the shell script?
See the following example:
$ cat foo.h #define ENUM enum #define COMMA, ENUM foo_t {FOO_VALUE1 = 11 COMMA FOO_VALUE2 = 22 COMMA FOO_VALUE3 = 33}; Include $ cat foo.c # & lt; Stdio.h & gt; #include "foo.h" # print_enum (x) printf ("% s =% d \ n", #x, x) int main () {enum foo_t foo = FOO_VALUE1; Print_enum (FOO_VALUE1); Print_enum (FOO_VALUE2); Print_enum (FOO_VALUE3); Return 0; } $ Cat foo.sh #! / Bin / bash shopt -s extension_allies alias ENUM = 'true' alias COMMA = source foo.h enum_names = ($ {! FOO_ *}) for name in $ {enum_names [@]}; Do echo $ name = $ {! Name} done $ gcc foo.c $ ./a.out FOO_VALUE1 = 11 FOO_VALUE2 = 22 FOO_VALUE3 = 33 $ bash foo.sh FOO_VALUE1 = 11 FOO_VALUE2 = 22 FOO_VALUE3 = 33 $
Comments
Post a Comment