diff --git a/examples-v2/customization/Jamfile b/examples-v2/customization/Jamfile new file mode 100644 index 000000000..60101fb52 --- /dev/null +++ b/examples-v2/customization/Jamfile @@ -0,0 +1,2 @@ + +exe codegen : codegen.cpp class.verbatim usage.verbatim ; \ No newline at end of file diff --git a/examples-v2/customization/class.verbatim b/examples-v2/customization/class.verbatim new file mode 100644 index 000000000..5c0d7b803 --- /dev/null +++ b/examples-v2/customization/class.verbatim @@ -0,0 +1,7 @@ +class_template + +class %class_name% { +public: + %class_name%() {} + ~%class_name%() {} +}; \ No newline at end of file diff --git a/examples-v2/customization/codegen.cpp b/examples-v2/customization/codegen.cpp new file mode 100644 index 000000000..027af816e --- /dev/null +++ b/examples-v2/customization/codegen.cpp @@ -0,0 +1,37 @@ +// (C) Copyright Vladimir Prus, 2003 +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Please see 'usage.verbatim' file for usage notes. + +#include +#include +#include +using std::cout; +using std::string; +using std::strlen; + +extern const char class_template[]; +extern const char usage[]; + +int main(int ac, char* av[]) +{ + if (av[1]) { + + string class_name = av[1]; + string s = class_template; + + string::size_type n; + while((n = s.find("%class_name%")) != string::npos) { + s.replace(n, strlen("%class_name%"), class_name); + } + std::cout << "Output is:\n"; + std::cout << s << "\n"; + return 0; + } else { + std::cout << usage << "\n"; + return 1; + } +} diff --git a/examples-v2/customization/inline_file.py b/examples-v2/customization/inline_file.py new file mode 100644 index 000000000..4b8d82751 --- /dev/null +++ b/examples-v2/customization/inline_file.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +import sys +from string import strip + +def quote_line(line): + + result = "" + + for i in line: + if (i == '\\'): + result = result + '\\\\' + elif (i == '\"'): + result = result + '\\\"' + elif (i != '\r' and i != '\n'): + result = result + i; + + return '\"' + result + '\\n\"' + +def quote_file(file): + result = "" + + for i in file.readlines(): + result = result + quote_line(i) + "\n" + + return result + +if len(sys.argv) < 3: + print "Usage: inline_file.py output_c_file file_to_include" +else: + output_c_file = sys.argv[1] + out_file = open(output_c_file, "w"); + + file_to_include = sys.argv[2] + + in_file = open(file_to_include, "r"); + variable_name = strip(in_file.readline()) + out_file.write("extern const char %s[] = {\n%s};\n\n" % (variable_name, quote_file(in_file))) + in_file.close() + out_file.close() diff --git a/examples-v2/customization/project-root.jam b/examples-v2/customization/project-root.jam new file mode 100644 index 000000000..b822c673d --- /dev/null +++ b/examples-v2/customization/project-root.jam @@ -0,0 +1,2 @@ + +import verbatim ; \ No newline at end of file diff --git a/examples-v2/customization/usage.verbatim b/examples-v2/customization/usage.verbatim new file mode 100644 index 000000000..041fc12bc --- /dev/null +++ b/examples-v2/customization/usage.verbatim @@ -0,0 +1,6 @@ +usage +Usage: codegen class_name + +This program takes a template of C++ code and replaces of +occurences of %class_name% with the passed 'class_name' +parameter. diff --git a/examples-v2/customization/verbatim.jam b/examples-v2/customization/verbatim.jam new file mode 100644 index 000000000..80cce7b1c --- /dev/null +++ b/examples-v2/customization/verbatim.jam @@ -0,0 +1,11 @@ + +import type ; +type.register VERBATIM : verbatim ; + +import generators ; +generators.register-standard verbatim.inline-file : VERBATIM : CPP ; + +actions inline-file +{ + ./inline_file.py $(<) $(>) +} \ No newline at end of file diff --git a/v2/example/customization/Jamfile b/v2/example/customization/Jamfile new file mode 100644 index 000000000..60101fb52 --- /dev/null +++ b/v2/example/customization/Jamfile @@ -0,0 +1,2 @@ + +exe codegen : codegen.cpp class.verbatim usage.verbatim ; \ No newline at end of file diff --git a/v2/example/customization/class.verbatim b/v2/example/customization/class.verbatim new file mode 100644 index 000000000..5c0d7b803 --- /dev/null +++ b/v2/example/customization/class.verbatim @@ -0,0 +1,7 @@ +class_template + +class %class_name% { +public: + %class_name%() {} + ~%class_name%() {} +}; \ No newline at end of file diff --git a/v2/example/customization/codegen.cpp b/v2/example/customization/codegen.cpp new file mode 100644 index 000000000..027af816e --- /dev/null +++ b/v2/example/customization/codegen.cpp @@ -0,0 +1,37 @@ +// (C) Copyright Vladimir Prus, 2003 +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +// Please see 'usage.verbatim' file for usage notes. + +#include +#include +#include +using std::cout; +using std::string; +using std::strlen; + +extern const char class_template[]; +extern const char usage[]; + +int main(int ac, char* av[]) +{ + if (av[1]) { + + string class_name = av[1]; + string s = class_template; + + string::size_type n; + while((n = s.find("%class_name%")) != string::npos) { + s.replace(n, strlen("%class_name%"), class_name); + } + std::cout << "Output is:\n"; + std::cout << s << "\n"; + return 0; + } else { + std::cout << usage << "\n"; + return 1; + } +} diff --git a/v2/example/customization/inline_file.py b/v2/example/customization/inline_file.py new file mode 100644 index 000000000..4b8d82751 --- /dev/null +++ b/v2/example/customization/inline_file.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +import sys +from string import strip + +def quote_line(line): + + result = "" + + for i in line: + if (i == '\\'): + result = result + '\\\\' + elif (i == '\"'): + result = result + '\\\"' + elif (i != '\r' and i != '\n'): + result = result + i; + + return '\"' + result + '\\n\"' + +def quote_file(file): + result = "" + + for i in file.readlines(): + result = result + quote_line(i) + "\n" + + return result + +if len(sys.argv) < 3: + print "Usage: inline_file.py output_c_file file_to_include" +else: + output_c_file = sys.argv[1] + out_file = open(output_c_file, "w"); + + file_to_include = sys.argv[2] + + in_file = open(file_to_include, "r"); + variable_name = strip(in_file.readline()) + out_file.write("extern const char %s[] = {\n%s};\n\n" % (variable_name, quote_file(in_file))) + in_file.close() + out_file.close() diff --git a/v2/example/customization/project-root.jam b/v2/example/customization/project-root.jam new file mode 100644 index 000000000..b822c673d --- /dev/null +++ b/v2/example/customization/project-root.jam @@ -0,0 +1,2 @@ + +import verbatim ; \ No newline at end of file diff --git a/v2/example/customization/usage.verbatim b/v2/example/customization/usage.verbatim new file mode 100644 index 000000000..041fc12bc --- /dev/null +++ b/v2/example/customization/usage.verbatim @@ -0,0 +1,6 @@ +usage +Usage: codegen class_name + +This program takes a template of C++ code and replaces of +occurences of %class_name% with the passed 'class_name' +parameter. diff --git a/v2/example/customization/verbatim.jam b/v2/example/customization/verbatim.jam new file mode 100644 index 000000000..80cce7b1c --- /dev/null +++ b/v2/example/customization/verbatim.jam @@ -0,0 +1,11 @@ + +import type ; +type.register VERBATIM : verbatim ; + +import generators ; +generators.register-standard verbatim.inline-file : VERBATIM : CPP ; + +actions inline-file +{ + ./inline_file.py $(<) $(>) +} \ No newline at end of file