From 1c3274be405c125dc9ace8450718081c35688d4d Mon Sep 17 00:00:00 2001 From: Howard Thomson Date: Fri, 20 Apr 2012 16:51:28 +0100 Subject: [PATCH] Split out common routines for C constant extraction --- library/ecrypt_make_constants.e | 85 ++------------------------------ library/make_constants_from_c.e | 87 +++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 82 deletions(-) create mode 100644 library/make_constants_from_c.e diff --git a/library/ecrypt_make_constants.e b/library/ecrypt_make_constants.e index 3bf4c85..fa43edc 100644 --- a/library/ecrypt_make_constants.e +++ b/library/ecrypt_make_constants.e @@ -10,11 +10,11 @@ indexing class ECRYPT_MAKE_CONSTANTS --- inherit +inherit --- EDP_PR + MAKE_CONSTANTS_FROM_C -creation +create make @@ -1272,84 +1272,5 @@ feature -- Status Codes process_integer_feature("CRYPT_ENVELOPE_RESOURCE") -- Need resource to proceed end - -feature -- Generic code, to be factored out .... - - class_name: STRING - file_name: STRING - - out_file: TEXT_FILE_WRITE - - set_class_name(a_name: STRING) is - -- Initialize, based on class name - do - class_name := a_name - file_name := "make_" + class_name.as_lower + ".c" - create out_file.connect_to(file_name) - -- if not out_file.is_connected then - -- die - -- end - end - - include(s: STRING) is - -- append an #include directive - do - out_file.put_string("#include %"") - out_file.put_string(s) - out_file.put_string("%"%N%N") - end - - append_head is - -- boiler-plate code for data declarations - -- and start of 'main' routine - do - out_file.put_string("[ - char *class_head = - "class %s\n" - "\n" - "feature\n" - "\n"; - - char *class_tail = - "end\n"; - - - ]") - out_file.put_string("char *class_name = %"") - out_file.put_string(class_name) - out_file.put_string("%";%N%N") - out_file.put_string("[ - int main(int ac, char **av) { - - printf(class_head, class_name); - - ]") - end - - process_integer_feature(s: STRING) is - do - out_file.put_string("%Tprintf(%"\t") - out_file.put_string(s) - out_file.put_string(": INTEGER is %%d\n%", ") - out_file.put_string(s) - out_file.put_string(");%N") - end - - process_hexadecimal_feature(s: STRING) is - do - out_file.put_string("%Tprintf(%"\t") - out_file.put_string(s) - out_file.put_string(": INTEGER is 0x%%.8x\n%", ") - out_file.put_string(s) - out_file.put_string(");%N") - end - - append_tail is - -- Append tail and close output file - do - out_file.put_string("%Tprintf(class_tail);%N") - out_file.put_string("}%N") - out_file.disconnect - end end \ No newline at end of file diff --git a/library/make_constants_from_c.e b/library/make_constants_from_c.e new file mode 100644 index 0000000..e3fc8dd --- /dev/null +++ b/library/make_constants_from_c.e @@ -0,0 +1,87 @@ +note + + description: "Base class for generating constants from a C header file ..." + +deferred class MAKE_CONSTANTS_FROM_C + +feature -- Generic code, to be factored out .... + + class_name: STRING + file_name: STRING + + out_file: TEXT_FILE_WRITE + + set_class_name(a_name: STRING) is + -- Initialize, based on class name + do + class_name := a_name + file_name := "make_" + class_name.as_lower + ".c" + create out_file.connect_to(file_name) + -- if not out_file.is_connected then + -- die + -- end + end + + include(s: STRING) is + -- append an #include directive + do + out_file.put_string("#include %"") + out_file.put_string(s) + out_file.put_string("%"%N%N") + end + + append_head is + -- boiler-plate code for data declarations + -- and start of 'main' routine + do + out_file.put_string("[ + char *class_head = + "class %s\n" + "\n" + "feature\n" + "\n"; + + char *class_tail = + "end\n"; + + + ]") + out_file.put_string("char *class_name = %"") + out_file.put_string(class_name) + out_file.put_string("%";%N%N") + out_file.put_string("[ + int main(int ac, char **av) { + + printf(class_head, class_name); + + ]") + end + + process_integer_feature(s: STRING) is + do + out_file.put_string("%Tprintf(%"\t") + out_file.put_string(s) + out_file.put_string(": INTEGER is %%d\n%", ") + out_file.put_string(s) + out_file.put_string(");%N") + end + + process_hexadecimal_feature(s: STRING) is + do + out_file.put_string("%Tprintf(%"\t") + out_file.put_string(s) + out_file.put_string(": INTEGER is 0x%%.8x\n%", ") + out_file.put_string(s) + out_file.put_string(");%N") + end + + append_tail is + -- Append tail and close output file + do + out_file.put_string("%Tprintf(class_tail);%N") + out_file.put_string("}%N") + out_file.disconnect + end + + +end -- class MAKE_CONSTANTS_FROM_C