acpc_dealer 2.0.6 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -2
  3. data/lib/acpc_dealer.rb +6 -2
  4. data/lib/acpc_dealer/version.rb +1 -1
  5. data/vendor/project_acpc_server/Makefile +12 -2
  6. data/vendor/project_acpc_server/README +1 -0
  7. data/vendor/project_acpc_server/example_player.limit.2p.sh +2 -1
  8. data/vendor/project_acpc_server/example_player.limit.3p.sh +2 -1
  9. data/vendor/project_acpc_server/example_player.nolimit.2p.sh +2 -1
  10. data/vendor/project_acpc_server/example_player.nolimit.3p.sh +2 -1
  11. data/vendor/project_acpc_server/kuhn.limit.3p.game +14 -0
  12. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player.sf1.sh +3 -0
  13. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player.sf2.sh +3 -0
  14. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player.sf3.sh +3 -0
  15. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/LICENCE +23 -0
  16. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/Makefile +128 -0
  17. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/README.md +35 -0
  18. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/CExceptionConfig.h +12 -0
  19. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/dealer_connection.c +49 -0
  20. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/dealer_connection.h +22 -0
  21. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/kuhn_3p_equilibrium_player.c +483 -0
  22. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/kuhn_3p_equilibrium_player.h +107 -0
  23. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/main.c +84 -0
  24. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/player_config.c +252 -0
  25. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/player_config.h +21 -0
  26. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/support/test_helper.c +45 -0
  27. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/support/test_helper.h +27 -0
  28. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/test_kuhn_3p_equilibrium_player.c +698 -0
  29. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/test_kuhn_3p_equilibrium_player_sub_family_1.c +324 -0
  30. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/test_kuhn_3p_equilibrium_player_sub_family_2.c +262 -0
  31. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/test_kuhn_3p_equilibrium_player_sub_family_3.c +177 -0
  32. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/docs/CExceptionSummary.odt +0 -0
  33. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/docs/CExceptionSummary.pdf +0 -0
  34. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/docs/license.txt +30 -0
  35. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/docs/readme.txt +242 -0
  36. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/lib/CException.c +43 -0
  37. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/lib/CException.h +86 -0
  38. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/release/build.info +2 -0
  39. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/release/version.info +2 -0
  40. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/config/production_environment.rb +14 -0
  41. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/config/test_environment.rb +16 -0
  42. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/docs/CMock Summary.odt +0 -0
  43. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/docs/CMock Summary.pdf +0 -0
  44. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/docs/CMock_Summary.md +356 -0
  45. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/docs/license.txt +31 -0
  46. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/Resource/SAM7_FLASH.mac +71 -0
  47. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/Resource/SAM7_RAM.mac +94 -0
  48. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/Resource/SAM7_SIM.mac +67 -0
  49. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/Resource/at91SAM7X256_FLASH.xcl +185 -0
  50. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/Resource/at91SAM7X256_RAM.xcl +185 -0
  51. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/Resource/ioat91sam7x256.ddf +2259 -0
  52. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/cmock_demo.dep +3691 -0
  53. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/cmock_demo.ewd +1696 -0
  54. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/cmock_demo.ewp +2581 -0
  55. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/cmock_demo.eww +10 -0
  56. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/incIAR/AT91SAM7X-EK.h +61 -0
  57. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/incIAR/AT91SAM7X256.inc +2314 -0
  58. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/incIAR/AT91SAM7X256.rdf +4704 -0
  59. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/incIAR/AT91SAM7X256.tcl +3407 -0
  60. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/incIAR/AT91SAM7X256_inc.h +2268 -0
  61. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/incIAR/ioat91sam7x256.h +4380 -0
  62. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/incIAR/lib_AT91SAM7X256.h +4211 -0
  63. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/settings/cmock_demo.cspy.bat +32 -0
  64. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/settings/cmock_demo.dbgdt +86 -0
  65. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/settings/cmock_demo.dni +42 -0
  66. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/settings/cmock_demo.wsdt +76 -0
  67. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/srcIAR/Cstartup.s79 +266 -0
  68. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v4/srcIAR/Cstartup_SAM7.c +98 -0
  69. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/Resource/SAM7_FLASH.mac +71 -0
  70. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/Resource/SAM7_RAM.mac +94 -0
  71. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/Resource/SAM7_SIM.mac +67 -0
  72. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/Resource/at91SAM7X256_FLASH.icf +43 -0
  73. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/Resource/at91SAM7X256_RAM.icf +42 -0
  74. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/cmock_demo.dep +4204 -0
  75. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/cmock_demo.ewd +1906 -0
  76. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/cmock_demo.ewp +2426 -0
  77. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/cmock_demo.eww +26 -0
  78. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/incIAR/AT91SAM7X-EK.h +61 -0
  79. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/incIAR/AT91SAM7X256_inc.h +2268 -0
  80. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/incIAR/lib_AT91SAM7X256.h +4211 -0
  81. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/incIAR/project.h +30 -0
  82. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/BasicInterrupt_SAM7X.cspy.bat +33 -0
  83. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/BasicInterrupt_SAM7X.dbgdt +5 -0
  84. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/BasicInterrupt_SAM7X.dni +18 -0
  85. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/BasicInterrupt_SAM7X.wsdt +74 -0
  86. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/BasicInterrupt_SAM7X_FLASH_Debug.jlink +12 -0
  87. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/cmock_demo.cspy.bat +33 -0
  88. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/cmock_demo.dbgdt +85 -0
  89. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/cmock_demo.dni +44 -0
  90. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/cmock_demo.wsdt +73 -0
  91. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/cmock_demo_Binary.jlink +12 -0
  92. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/cmock_demo_FLASH_Debug.jlink +12 -0
  93. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/settings/cmock_demo_RAM_Debug.jlink +12 -0
  94. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/srcIAR/Cstartup.s +299 -0
  95. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/iar/iar_v5/srcIAR/Cstartup_SAM7.c +98 -0
  96. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock.rb +65 -0
  97. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_config.rb +129 -0
  98. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_file_writer.rb +33 -0
  99. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_generator.rb +195 -0
  100. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_generator_plugin_array.rb +57 -0
  101. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_generator_plugin_callback.rb +78 -0
  102. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_generator_plugin_cexception.rb +51 -0
  103. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_generator_plugin_expect.rb +86 -0
  104. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_generator_plugin_ignore.rb +95 -0
  105. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_generator_plugin_ignore_arg.rb +44 -0
  106. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_generator_plugin_return_thru_ptr.rb +74 -0
  107. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_generator_utils.rb +202 -0
  108. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_header_parser.rb +277 -0
  109. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_plugin_manager.rb +40 -0
  110. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/lib/cmock_unityhelper_parser.rb +75 -0
  111. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/release/build.info +2 -0
  112. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/release/version.info +2 -0
  113. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/src/cmock.c +176 -0
  114. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/src/cmock.h +31 -0
  115. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/src/cmock_internals.h +43 -0
  116. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/targets/gcc.yml +53 -0
  117. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/targets/iar_arm_v4.yml +108 -0
  118. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cmock/targets/iar_arm_v5.yml +93 -0
  119. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/History.md +27 -0
  120. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/Makefile +8 -0
  121. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/Readme.md +103 -0
  122. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/package.json +9 -0
  123. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/src/commander.c +250 -0
  124. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/src/commander.h +88 -0
  125. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/test.c +34 -0
  126. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/colour_prompt.rb +94 -0
  127. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/colour_reporter.rb +39 -0
  128. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/generate_config.yml +36 -0
  129. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/generate_module.rb +202 -0
  130. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/generate_test_runner.rb +316 -0
  131. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/test_file_filter.rb +23 -0
  132. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/unity_test_summary.rb +139 -0
  133. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/docs/Unity Summary.odt +0 -0
  134. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/docs/Unity Summary.pdf +0 -0
  135. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/docs/Unity Summary.txt +216 -0
  136. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/docs/license.txt +31 -0
  137. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/release/build.info +2 -0
  138. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/release/version.info +2 -0
  139. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/src/unity.c +1146 -0
  140. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/src/unity.h +245 -0
  141. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/src/unity_internals.h +546 -0
  142. data/vendor/project_acpc_server/net.c +0 -0
  143. data/vendor/project_acpc_server/net.h +1 -0
  144. data/vendor/project_acpc_server/tags +298 -0
  145. metadata +158 -26
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "commander",
3
+ "version": "1.2.1",
4
+ "repo": "visionmedia/commander.c",
5
+ "description": "Command-line argument parser",
6
+ "keywords": ["cli", "command", "parser", "argv", "args", "options"],
7
+ "license": "MIT",
8
+ "src": ["src/commander.h", "src/commander.c"]
9
+ }
@@ -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,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
+