c_project 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +18 -0
  7. data/bin/c_project +77 -0
  8. data/c_project.gemspec +25 -0
  9. data/lib/c_project/version.rb +3 -0
  10. data/lib/c_project.rb +5 -0
  11. data/templates/LICENCE.tt +23 -0
  12. data/templates/Makefile.tt +74 -0
  13. data/templates/README.md.tt +15 -0
  14. data/templates/src/CExceptionConfig.h.tt +8 -0
  15. data/templates/src/c_project.c.tt +16 -0
  16. data/templates/src/c_project.h.tt +8 -0
  17. data/templates/src/main.c.tt +15 -0
  18. data/templates/test/support/test_helper.c.tt +2 -0
  19. data/templates/test/support/test_helper.h.tt +13 -0
  20. data/templates/test/test_c_project.c.tt +41 -0
  21. data/templates/vendor/cexception/docs/license.txt +30 -0
  22. data/templates/vendor/cexception/docs/readme.txt +242 -0
  23. data/templates/vendor/cexception/lib/CException.c +43 -0
  24. data/templates/vendor/cexception/lib/CException.h +86 -0
  25. data/templates/vendor/cexception/release/build.info +2 -0
  26. data/templates/vendor/cexception/release/version.info +2 -0
  27. data/templates/vendor/commander.c/History.md +27 -0
  28. data/templates/vendor/commander.c/Makefile +8 -0
  29. data/templates/vendor/commander.c/Readme.md +103 -0
  30. data/templates/vendor/commander.c/package.json +9 -0
  31. data/templates/vendor/commander.c/src/commander.c +250 -0
  32. data/templates/vendor/commander.c/src/commander.h +88 -0
  33. data/templates/vendor/commander.c/test.c +34 -0
  34. data/templates/vendor/unity/.gitignore +1 -0
  35. data/templates/vendor/unity/auto/colour_prompt.rb +94 -0
  36. data/templates/vendor/unity/auto/colour_reporter.rb +39 -0
  37. data/templates/vendor/unity/auto/generate_config.yml +36 -0
  38. data/templates/vendor/unity/auto/generate_module.rb +202 -0
  39. data/templates/vendor/unity/auto/generate_test_runner.rb +316 -0
  40. data/templates/vendor/unity/auto/test_file_filter.rb +23 -0
  41. data/templates/vendor/unity/auto/unity_test_summary.rb +139 -0
  42. data/templates/vendor/unity/docs/Unity Summary.txt +216 -0
  43. data/templates/vendor/unity/docs/license.txt +31 -0
  44. data/templates/vendor/unity/release/build.info +2 -0
  45. data/templates/vendor/unity/release/version.info +2 -0
  46. data/templates/vendor/unity/src/unity.c +1146 -0
  47. data/templates/vendor/unity/src/unity.h +245 -0
  48. data/templates/vendor/unity/src/unity_internals.h +546 -0
  49. metadata +135 -0
@@ -0,0 +1,250 @@
1
+
2
+ //
3
+ // commander.c
4
+ //
5
+ // Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
6
+ //
7
+
8
+ #include <stdio.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+ #include <assert.h>
12
+ #include "commander.h"
13
+
14
+ /*
15
+ * Output error and exit.
16
+ */
17
+
18
+ static void
19
+ error(char *msg) {
20
+ fprintf(stderr, "%s\n", msg);
21
+ exit(1);
22
+ }
23
+
24
+ /*
25
+ * Output command version.
26
+ */
27
+
28
+ static void
29
+ command_version(command_t *self) {
30
+ printf("%s\n", self->version);
31
+ exit(0);
32
+ }
33
+
34
+ /*
35
+ * Output command help.
36
+ */
37
+
38
+ void
39
+ command_help(command_t *self) {
40
+ printf("\n");
41
+ printf(" Usage: %s %s\n", self->name, self->usage);
42
+ printf("\n");
43
+ printf(" Options:\n");
44
+ printf("\n");
45
+ for (int i = 0; i < self->option_count; ++i) {
46
+ command_option_t *option = &self->options[i];
47
+ printf(" %s, %-25s %s\n"
48
+ , option->small
49
+ , option->large_with_arg
50
+ , option->description);
51
+ }
52
+ printf("\n");
53
+ exit(0);
54
+ }
55
+
56
+ /*
57
+ * Initialize with program `name` and `version`.
58
+ */
59
+
60
+ void
61
+ command_init(command_t *self, const char *name, const char *version) {
62
+ self->arg = NULL;
63
+ self->name = name;
64
+ self->version = version;
65
+ self->option_count = self->argc = 0;
66
+ self->usage = "[options]";
67
+ self->nargv = NULL;
68
+ command_option(self, "-V", "--version", "output program version", command_version);
69
+ command_option(self, "-h", "--help", "output help information", command_help);
70
+ }
71
+
72
+ /*
73
+ * Free up commander after use.
74
+ */
75
+
76
+ void
77
+ command_free(command_t *self) {
78
+ for (int i = 0; i < self->option_count; ++i) {
79
+ command_option_t *option = &self->options[i];
80
+ free(option->argname);
81
+ free(option->large);
82
+ }
83
+
84
+ if (self->nargv) {
85
+ for (int i = 0; self->nargv[i]; ++i) {
86
+ free(self->nargv[i]);
87
+ }
88
+ free(self->nargv);
89
+ }
90
+ }
91
+
92
+ /*
93
+ * Parse argname from `str`. For example
94
+ * Take "--required <arg>" and populate `flag`
95
+ * with "--required" and `arg` with "<arg>".
96
+ */
97
+
98
+ static void
99
+ parse_argname(const char *str, char *flag, char *arg) {
100
+ int buffer = 0;
101
+ size_t flagpos = 0;
102
+ size_t argpos = 0;
103
+ size_t len = strlen(str);
104
+
105
+ for (int i = 0; i < len; ++i) {
106
+ if (buffer || '[' == str[i] || '<' == str[i]) {
107
+ buffer = 1;
108
+ arg[argpos++] = str[i];
109
+ } else {
110
+ if (' ' == str[i]) continue;
111
+ flag[flagpos++] = str[i];
112
+ }
113
+ }
114
+
115
+ arg[argpos] = '\0';
116
+ flag[flagpos] = '\0';
117
+ }
118
+
119
+ /*
120
+ * Normalize the argument vector by exploding
121
+ * multiple options (if any). For example
122
+ * "foo -abc --scm git" -> "foo -a -b -c --scm git"
123
+ */
124
+
125
+ static char **
126
+ normalize_args(int *argc, char **argv) {
127
+ int size = 0;
128
+ int alloc = *argc + 1;
129
+ char **nargv = malloc(alloc * sizeof(char *));
130
+
131
+ for (int i = 0; argv[i]; ++i) {
132
+ const char *arg = argv[i];
133
+ int len = strlen(arg);
134
+
135
+ // short flag
136
+ if (len > 2 && '-' == arg[0] && !strchr(arg + 1, '-')) {
137
+ alloc += len - 2;
138
+ nargv = realloc(nargv, alloc * sizeof(char *));
139
+ for (int j = 1; j < len; ++j) {
140
+ nargv[size] = malloc(3);
141
+ sprintf(nargv[size], "-%c", arg[j]);
142
+ size++;
143
+ }
144
+ continue;
145
+ }
146
+
147
+ // regular arg
148
+ nargv[size] = malloc(len + 1);
149
+ strcpy(nargv[size], arg);
150
+ size++;
151
+ }
152
+
153
+ nargv[size] = NULL;
154
+ *argc = size;
155
+ return nargv;
156
+ }
157
+
158
+ /*
159
+ * Define an option.
160
+ */
161
+
162
+ void
163
+ command_option(command_t *self, const char *small, const char *large, const char *desc, command_callback_t cb) {
164
+ int n = self->option_count++;
165
+ if (n == COMMANDER_MAX_OPTIONS) error("Maximum option definitions exceeded");
166
+ command_option_t *option = &self->options[n];
167
+ option->cb = cb;
168
+ option->small = small;
169
+ option->description = desc;
170
+ option->required_arg = option->optional_arg = 0;
171
+ option->large_with_arg = large;
172
+ option->argname = malloc(strlen(large) + 1);
173
+ assert(option->argname);
174
+ option->large = malloc(strlen(large) + 1);
175
+ assert(option->large);
176
+ parse_argname(large, option->large, option->argname);
177
+ if ('[' == option->argname[0]) option->optional_arg = 1;
178
+ if ('<' == option->argname[0]) option->required_arg = 1;
179
+ }
180
+
181
+ /*
182
+ * Parse `argv` (internal).
183
+ * Input arguments should be normalized first
184
+ * see `normalize_args`.
185
+ */
186
+
187
+ static void
188
+ command_parse_args(command_t *self, int argc, char **argv) {
189
+ int literal = 0;
190
+
191
+ for (int i = 1; i < argc; ++i) {
192
+ const char *arg = argv[i];
193
+ for (int j = 0; j < self->option_count; ++j) {
194
+ command_option_t *option = &self->options[j];
195
+
196
+ // match flag
197
+ if (!strcmp(arg, option->small) || !strcmp(arg, option->large)) {
198
+ self->arg = NULL;
199
+
200
+ // required
201
+ if (option->required_arg) {
202
+ arg = argv[++i];
203
+ if (!arg || '-' == arg[0]) {
204
+ fprintf(stderr, "%s %s argument required\n", option->large, option->argname);
205
+ exit(1);
206
+ }
207
+ self->arg = arg;
208
+ }
209
+
210
+ // optional
211
+ if (option->optional_arg) {
212
+ if (argv[i + 1] && '-' != argv[i + 1][0]) {
213
+ self->arg = argv[++i];
214
+ }
215
+ }
216
+
217
+ // invoke callback
218
+ option->cb(self);
219
+ goto match;
220
+ }
221
+ }
222
+
223
+ // --
224
+ if ('-' == arg[0] && '-' == arg[1] && 0 == arg[2]) {
225
+ literal = 1;
226
+ goto match;
227
+ }
228
+
229
+ // unrecognized
230
+ if ('-' == arg[0] && !literal) {
231
+ fprintf(stderr, "unrecognized flag %s\n", arg);
232
+ exit(1);
233
+ }
234
+
235
+ int n = self->argc++;
236
+ if (n == COMMANDER_MAX_ARGS) error("Maximum number of arguments exceeded");
237
+ self->argv[n] = (char *) arg;
238
+ match:;
239
+ }
240
+ }
241
+
242
+ /*
243
+ * Parse `argv` (public).
244
+ */
245
+
246
+ void
247
+ command_parse(command_t *self, int argc, char **argv) {
248
+ self->nargv = normalize_args(&argc, argv);
249
+ command_parse_args(self, argc, self->nargv);
250
+ }
@@ -0,0 +1,88 @@
1
+
2
+ //
3
+ // commander.h
4
+ //
5
+ // Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
6
+ //
7
+
8
+ #ifndef COMMANDER_H
9
+ #define COMMANDER_H
10
+
11
+ /*
12
+ * Max options that can be defined.
13
+ */
14
+
15
+ #ifndef COMMANDER_MAX_OPTIONS
16
+ #define COMMANDER_MAX_OPTIONS 32
17
+ #endif
18
+
19
+ /*
20
+ * Max arguments that can be passed.
21
+ */
22
+
23
+ #ifndef COMMANDER_MAX_ARGS
24
+ #define COMMANDER_MAX_ARGS 32
25
+ #endif
26
+
27
+ /*
28
+ * Command struct.
29
+ */
30
+
31
+ struct command;
32
+
33
+ /*
34
+ * Option callback.
35
+ */
36
+
37
+ typedef void (* command_callback_t)(struct command *self);
38
+
39
+ /*
40
+ * Command option.
41
+ */
42
+
43
+ typedef struct {
44
+ int optional_arg;
45
+ int required_arg;
46
+ char *argname;
47
+ char *large;
48
+ const char *small;
49
+ const char *large_with_arg;
50
+ const char *description;
51
+ command_callback_t cb;
52
+ } command_option_t;
53
+
54
+ /*
55
+ * Command.
56
+ */
57
+
58
+ typedef struct command {
59
+ void *data;
60
+ const char *usage;
61
+ const char *arg;
62
+ const char *name;
63
+ const char *version;
64
+ int option_count;
65
+ command_option_t options[COMMANDER_MAX_OPTIONS];
66
+ int argc;
67
+ char *argv[COMMANDER_MAX_ARGS];
68
+ char **nargv;
69
+ } command_t;
70
+
71
+ // prototypes
72
+
73
+ void
74
+ command_init(command_t *self, const char *name, const char *version);
75
+
76
+ void
77
+ command_free(command_t *self);
78
+
79
+ void
80
+ command_help(command_t *self);
81
+
82
+ void
83
+ command_option(command_t *self, const char *small, const char *large, const char *desc, command_callback_t cb);
84
+
85
+ void
86
+ command_parse(command_t *self, int argc, char **argv);
87
+
88
+ #endif /* COMMANDER_H */
@@ -0,0 +1,34 @@
1
+
2
+ #include <stdio.h>
3
+ #include "src/commander.h"
4
+
5
+ static void
6
+ verbose(command_t *self) {
7
+ printf("verbose: enabled\n");
8
+ }
9
+
10
+ static void
11
+ required(command_t *self) {
12
+ printf("required: %s\n", self->arg);
13
+ }
14
+
15
+ static void
16
+ optional(command_t *self) {
17
+ printf("optional: %s\n", self->arg);
18
+ }
19
+
20
+ int
21
+ main(int argc, char **argv){
22
+ command_t cmd;
23
+ command_init(&cmd, argv[0], "0.0.1");
24
+ command_option(&cmd, "-v", "--verbose", "enable verbose stuff", verbose);
25
+ command_option(&cmd, "-r", "--required <arg>", "required arg", required);
26
+ command_option(&cmd, "-o", "--optional [arg]", "optional arg", optional);
27
+ command_parse(&cmd, argc, argv);
28
+ printf("additional args:\n");
29
+ for (int i = 0; i < cmd.argc; ++i) {
30
+ printf(" - '%s'\n", cmd.argv[i]);
31
+ }
32
+ command_free(&cmd);
33
+ return 0;
34
+ }
@@ -0,0 +1 @@
1
+ build/
@@ -0,0 +1,94 @@
1
+ # ==========================================
2
+ # Unity Project - A Test Framework for C
3
+ # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
4
+ # [Released under MIT License. Please refer to license.txt for details]
5
+ # ==========================================
6
+
7
+ if RUBY_PLATFORM =~/(win|w)32$/
8
+ begin
9
+ require 'Win32API'
10
+ rescue LoadError
11
+ puts "ERROR! \"Win32API\" library not found"
12
+ puts "\"Win32API\" is required for colour on a windows machine"
13
+ puts " try => \"gem install Win32API\" on the command line"
14
+ puts
15
+ end
16
+ # puts
17
+ # puts 'Windows Environment Detected...'
18
+ # puts 'Win32API Library Found.'
19
+ # puts
20
+ end
21
+
22
+ class ColourCommandLine
23
+ def initialize
24
+ if RUBY_PLATFORM =~/(win|w)32$/
25
+ get_std_handle = Win32API.new("kernel32", "GetStdHandle", ['L'], 'L')
26
+ @set_console_txt_attrb =
27
+ Win32API.new("kernel32","SetConsoleTextAttribute",['L','N'], 'I')
28
+ @hout = get_std_handle.call(-11)
29
+ end
30
+ end
31
+
32
+ def change_to(new_colour)
33
+ if RUBY_PLATFORM =~/(win|w)32$/
34
+ @set_console_txt_attrb.call(@hout,self.win32_colour(new_colour))
35
+ else
36
+ "\033[30;#{posix_colour(new_colour)};22m"
37
+ end
38
+ end
39
+
40
+ def win32_colour(colour)
41
+ case colour
42
+ when :black then 0
43
+ when :dark_blue then 1
44
+ when :dark_green then 2
45
+ when :dark_cyan then 3
46
+ when :dark_red then 4
47
+ when :dark_purple then 5
48
+ when :dark_yellow, :narrative then 6
49
+ when :default_white, :default, :dark_white then 7
50
+ when :silver then 8
51
+ when :blue then 9
52
+ when :green, :success then 10
53
+ when :cyan, :output then 11
54
+ when :red, :failure then 12
55
+ when :purple then 13
56
+ when :yellow then 14
57
+ when :white then 15
58
+ else
59
+ 0
60
+ end
61
+ end
62
+
63
+ def posix_colour(colour)
64
+ case colour
65
+ when :black then 30
66
+ when :red, :failure then 31
67
+ when :green, :success then 32
68
+ when :yellow then 33
69
+ when :blue, :narrative then 34
70
+ when :purple, :magenta then 35
71
+ when :cyan, :output then 36
72
+ when :white, :default_white, :default then 37
73
+ else
74
+ 30
75
+ end
76
+ end
77
+
78
+ def out_c(mode, colour, str)
79
+ case RUBY_PLATFORM
80
+ when /(win|w)32$/
81
+ change_to(colour)
82
+ $stdout.puts str if mode == :puts
83
+ $stdout.print str if mode == :print
84
+ change_to(:default_white)
85
+ else
86
+ $stdout.puts("#{change_to(colour)}#{str}\033[0m") if mode == :puts
87
+ $stdout.print("#{change_to(colour)}#{str}\033[0m") if mode == :print
88
+ end
89
+ end
90
+ end # ColourCommandLine
91
+
92
+ def colour_puts(role,str) ColourCommandLine.new.out_c(:puts, role, str) end
93
+ def colour_print(role,str) ColourCommandLine.new.out_c(:print, role, str) end
94
+
@@ -0,0 +1,39 @@
1
+ # ==========================================
2
+ # Unity Project - A Test Framework for C
3
+ # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
4
+ # [Released under MIT License. Please refer to license.txt for details]
5
+ # ==========================================
6
+
7
+ require "#{File.expand_path(File.dirname(__FILE__))}/colour_prompt"
8
+
9
+ $colour_output = true
10
+
11
+ def report(message)
12
+ if not $colour_output
13
+ $stdout.puts(message)
14
+ else
15
+ message = message.join('\n') if (message.class == Array)
16
+ message.each_line do |line|
17
+ line.chomp!
18
+ colour = case(line)
19
+ when /(?:total\s+)?tests:?\s+(\d+)\s+(?:total\s+)?failures:?\s+\d+\s+Ignored:?/i
20
+ ($1.to_i == 0) ? :green : :red
21
+ when /PASS/
22
+ :green
23
+ when /^OK$/
24
+ :green
25
+ when /(?:FAIL|ERROR)/
26
+ :red
27
+ when /IGNORE/
28
+ :yellow
29
+ when /^(?:Creating|Compiling|Linking)/
30
+ :white
31
+ else
32
+ :silver
33
+ end
34
+ colour_puts(colour, line)
35
+ end
36
+ end
37
+ $stdout.flush
38
+ $stderr.flush
39
+ end
@@ -0,0 +1,36 @@
1
+ #this is a sample configuration file for generate_module
2
+ #you would use it by calling generate_module with the -ygenerate_config.yml option
3
+ #files like this are useful for customizing generate_module to your environment
4
+ :generate_module:
5
+ :defaults:
6
+ #these defaults are used in place of any missing options at the command line
7
+ :path_src: ../src/
8
+ :path_inc: ../src/
9
+ :path_tst: ../test/
10
+ :update_svn: true
11
+ :includes:
12
+ #use [] for no additional includes, otherwise list the includes on separate lines
13
+ :src:
14
+ - Defs.h
15
+ - Board.h
16
+ :inc: []
17
+ :tst:
18
+ - Defs.h
19
+ - Board.h
20
+ - Exception.h
21
+ :boilerplates:
22
+ #these are inserted at the top of generated files.
23
+ #just comment out or remove if not desired.
24
+ #use %1$s where you would like the file name to appear (path/extension not included)
25
+ :src: |
26
+ //-------------------------------------------
27
+ // %1$s.c
28
+ //-------------------------------------------
29
+ :inc: |
30
+ //-------------------------------------------
31
+ // %1$s.h
32
+ //-------------------------------------------
33
+ :tst: |
34
+ //-------------------------------------------
35
+ // Test%1$s.c : Units tests for %1$s.c
36
+ //-------------------------------------------