chinwag 0.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f037f260def8f981e16426363f15335a45d71f62
4
- data.tar.gz: a2c237a826e5cfa1aecc65531445e2d5a737539b
3
+ metadata.gz: 3fd89d4ee2f2e3439eb95d344a7ef538911055df
4
+ data.tar.gz: 0cccb667d03b4543f09dff77de8ed74d6bd2b8f3
5
5
  SHA512:
6
- metadata.gz: 302dd52a58d2cdc8228dba88287973a0d0beed0b910b6a95e1e5f10ff9f5a3cc4bb3cc4cb29bb742b3b4f5d445efa588d6d8cf6725a4b4dd373936fad2208784
7
- data.tar.gz: 2053ca937bb4069717797531075dcd3d9aeed574f0edf850c7a46ccff52bbe94f6f3ce2f0b15293747353f0ae00867fc88caf664eec237b00eaab4570e780567
6
+ metadata.gz: 4bfd5c4396ad161bc3c2b32f10bff6922551930dca19d9fcac58b279e12b689a27aa36802d6800b5dbdec2eb7fbcd485a4fc3a5cdc7d682e6df5806ac62c2dd7
7
+ data.tar.gz: a844beae99c7f6e6fd428a8373b7b7abf9030b2830cf49dd48511a80d867d8833023293ea1a119cc814d05f8914eeaa6cffbada31c65f37b5f4b7ca10f435da8
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ Rake::ExtensionTask.new "chinwag" do |ext|
8
8
  ext.lib_dir = "lib/chinwag"
9
9
  end
10
10
 
11
- s = Gem::Specification.new "chinwag", "0.1.5" do |s|
11
+ s = Gem::Specification.new "chinwag", "1.2.0" do |s|
12
12
  s.authors = ["Chris Calo"]
13
13
  s.email = ["ccalo@vulcanca.com"]
14
14
  s.summary = "A text-synthesis library, for use in layout testing (and more)."
@@ -1,6 +1,7 @@
1
1
  #include "chinwag.h"
2
2
 
3
- char* chinwag(cw_t type, unsigned long min, unsigned long max, dict_t dict)
3
+ char* chinwag
4
+ (cw_t type, unsigned long min, unsigned long max, cwdict_t dict)
4
5
  {
5
6
  char* result = NULL;
6
7
 
@@ -27,17 +28,18 @@ char* chinwag(cw_t type, unsigned long min, unsigned long max, dict_t dict)
27
28
  exit(EXIT_FAILURE);
28
29
  }
29
30
 
30
- if(type == CW_LETTERS) result = ltr_rng(min, max, dict);
31
- else if(type == CW_WORDS) result = wrd_rng(min, max, dict);
32
- else if(type == CW_SENTENCES) result = snt_rng(min, max, dict);
33
- else if(type == CW_PARAGRAPHS) result = pgf_rng(min, max, dict);
31
+ if(type == CW_LETTERS) result = cw_ltr_rng(min, max, dict);
32
+ else if(type == CW_WORDS) result = cw_wrd_rng(min, max, dict);
33
+ else if(type == CW_SENTENCES) result = cw_snt_rng(min, max, dict);
34
+ else if(type == CW_PARAGRAPHS) result = cw_pgf_rng(min, max, dict);
34
35
 
35
36
  return result;
36
37
  }
37
38
 
38
- char* ltr_rng(unsigned long min, unsigned long max, dict_t dict)
39
+ char* cw_ltr_rng
40
+ (unsigned long min, unsigned long max, cwdict_t dict)
39
41
  {
40
- dict_t temp = open_dict();
42
+ cwdict_t temp = cwdict_open();
41
43
  I32 amount = motherr(min,max), total = 0; U32 len = 0;
42
44
  char* s = (char*)malloc(SMALL_BUFFER); char* sample = NULL;
43
45
  char* result = NULL; char* vowels = "aeiou";
@@ -54,7 +56,7 @@ char* ltr_rng(unsigned long min, unsigned long max, dict_t dict)
54
56
  }
55
57
  else
56
58
  {
57
- s = strcpy(s, sample_dict(dict));
59
+ s = strcpy(s, cwdict_sample(dict));
58
60
  len = strlen(s); total += len; s[len] = '\0';
59
61
  if(len > amount || include(s, " ") || include(s, "-")) continue;
60
62
  }
@@ -90,25 +92,26 @@ char* ltr_rng(unsigned long min, unsigned long max, dict_t dict)
90
92
  amount -= 2;
91
93
  }
92
94
 
93
- temp = place_word_in_dict(temp, s);
95
+ temp = cwdict_place_word(temp, s);
94
96
  if(amount > 0 && amount != 1) --amount;
95
97
  }
96
98
 
97
99
  // post-process dict (pass utility::capitalize function as parameter)
98
- temp = prune_dict(temp, false);
99
- temp = map_dict(temp, capitalize);
100
- result = join_dict(temp, " ");
100
+ temp = cwdict_prune(temp, false);
101
+ temp = cwdict_map(temp, capitalize);
102
+ result = cwdict_join(temp, " ");
101
103
 
102
- close_dict(temp);
104
+ cwdict_close(temp);
103
105
  free(s); s = NULL;
104
106
 
105
107
  return result;
106
108
  }
107
109
 
108
- char* wrd_rng(unsigned long min, unsigned long max, dict_t dict)
110
+ char* cw_wrd_rng
111
+ (unsigned long min, unsigned long max, cwdict_t dict)
109
112
  {
110
- dict_t temp = open_dict();
111
- U32 amount = motherr(min, max), total = total_dict(dict);
113
+ cwdict_t temp = cwdict_open();
114
+ U32 amount = motherr(min, max), total = cwdict_length(dict);
112
115
  char* sample = NULL; char* result = NULL;
113
116
  bool invalid = true;
114
117
 
@@ -117,32 +120,33 @@ char* wrd_rng(unsigned long min, unsigned long max, dict_t dict)
117
120
  {
118
121
  while(invalid)
119
122
  {
120
- sample = sample_dict(dict);
123
+ sample = cwdict_sample(dict);
121
124
 
122
125
  // valid if no space, hyphen, or duplicate (latter depends on size)
123
126
  if(exclude(sample, " ") && exclude(sample, "-"))
124
127
  {
125
128
  if(amount > total) invalid = false;
126
- else if(dict_exclude(temp, sample)) invalid = false;
129
+ else if(cwdict_exclude(temp, sample)) invalid = false;
127
130
  }
128
131
  }
129
132
 
130
- temp = place_word_in_dict(temp, sample);
133
+ temp = cwdict_place_word(temp, sample);
131
134
  invalid = true;
132
135
  }
133
136
 
134
137
  // post-process dict (pass utility::capitalize function as parameter)
135
- temp = map_dict(temp, capitalize);
136
- result = join_dict(temp, " ");
138
+ temp = cwdict_map(temp, capitalize);
139
+ result = cwdict_join(temp, " ");
137
140
 
138
- close_dict(temp);
141
+ cwdict_close(temp);
139
142
 
140
143
  return result;
141
144
  }
142
145
 
143
- char* snt_rng(unsigned long min, unsigned long max, dict_t dict)
146
+ char* cw_snt_rng
147
+ (unsigned long min, unsigned long max, cwdict_t dict)
144
148
  {
145
- dict_t master = open_dict(), temp; drow_t selected;
149
+ cwdict_t master = cwdict_open(), temp; cwdrow_t selected;
146
150
  U32 word_amount = 0, last = 0, amount = motherr(min, max), now = 0,
147
151
  len = 0, t_minus = 0; U8 comma = 0; I32 punct = 0;
148
152
  U32* no_dice = (U32*)malloc(sizeof(U32) * SMALL_BUFFER);
@@ -151,7 +155,7 @@ char* snt_rng(unsigned long min, unsigned long max, dict_t dict)
151
155
 
152
156
  for(U32 i = 0; i != amount; ++i)
153
157
  {
154
- temp = open_dict();
158
+ temp = cwdict_open();
155
159
  word_amount = motherr(SENTENCE_MIN_WORD_LENGTH,
156
160
  SENTENCE_MAX_WORD_LENGTH);
157
161
 
@@ -170,10 +174,10 @@ char* snt_rng(unsigned long min, unsigned long max, dict_t dict)
170
174
  else if(last > 10 || last <= 2) { now = motherr(6, 10); t_minus = 3; }
171
175
 
172
176
  selected = dict.drows[now];
173
- sample = sample_drow(selected);
177
+ sample = cwdrow_sample(selected);
174
178
 
175
- while(dict_include(temp, sample) && strlen(sample) != now)
176
- { sample = sample_dict(dict); }
179
+ while(cwdict_include(temp, sample) && strlen(sample) != now)
180
+ { sample = cwdict_sample(dict); }
177
181
 
178
182
  // add comma (if applicable)
179
183
  if(comma && j == comma - 1)
@@ -186,18 +190,18 @@ char* snt_rng(unsigned long min, unsigned long max, dict_t dict)
186
190
  s[len] = '\0';
187
191
 
188
192
  s = add_suffix(s, ",");
189
- temp = place_word_in_dict(temp, s);
193
+ temp = cwdict_place_word(temp, s);
190
194
 
191
195
  free(s);
192
196
  }
193
- else temp = place_word_in_dict(temp, sample);
197
+ else temp = cwdict_place_word(temp, sample);
194
198
 
195
199
  invalid = true;
196
200
  last = now;
197
201
  }
198
202
 
199
203
  // join temporary dict into a sentence; capitalize first word
200
- s = join_dict(temp, " ");
204
+ s = cwdict_join(temp, " ");
201
205
  s = capitalize(s);
202
206
 
203
207
  // determine punctuation; 1 - period, 2 - question, 3 - exclamation
@@ -209,38 +213,39 @@ char* snt_rng(unsigned long min, unsigned long max, dict_t dict)
209
213
  else if(punct >= 85 && punct <= 99) s = add_suffix(s, "!");
210
214
 
211
215
  // add sentence to master dict and cleanup
212
- master = place_word_in_dict(master, s);
216
+ master = cwdict_place_word(master, s);
213
217
 
214
- close_dict(temp);
218
+ cwdict_close(temp);
215
219
  free(s);
216
220
  }
217
221
 
218
- result = join_dict(master, " ");
219
- close_dict(master);
222
+ result = cwdict_join(master, " ");
223
+ cwdict_close(master);
220
224
  free(no_dice);
221
225
 
222
226
  return result;
223
227
  }
224
228
 
225
- char* pgf_rng(unsigned long min, unsigned long max, dict_t dict)
229
+ char* cw_pgf_rng
230
+ (unsigned long min, unsigned long max, cwdict_t dict)
226
231
  {
227
232
  char* result = NULL; char* sentences = NULL;
228
233
  U32 amount = motherr(min, max), sentence_amount = 0;
229
- dict_t master = open_dict();
234
+ cwdict_t master = cwdict_open();
230
235
 
231
236
  for(U32 i = 0; i != amount; ++i)
232
237
  {
233
238
  sentence_amount = motherr(PARAGRAPH_MIN_SENTENCE_LENGTH,
234
239
  PARAGRAPH_MAX_SENTENCE_LENGTH);
235
240
 
236
- sentences = snt(sentence_amount, dict);
237
- master = place_word_in_dict(master, sentences);
241
+ sentences = cw_snt(sentence_amount, dict);
242
+ master = cwdict_place_word(master, sentences);
238
243
 
239
244
  free(sentences);
240
245
  }
241
246
 
242
- result = join_dict(master, "\n\n");
243
- close_dict(master);
247
+ result = cwdict_join(master, "\n\n");
248
+ cwdict_close(master);
244
249
 
245
250
  return result;
246
251
  }
@@ -36,15 +36,15 @@ typedef struct dictionary_type {
36
36
  unsigned long largest;
37
37
  unsigned long largest_pos;
38
38
  char** words;
39
- } drow_t;
39
+ } cwdrow_t;
40
40
 
41
41
  // dictionary (row container)
42
42
  typedef struct dictionary_container_type {
43
43
  bool sorted;
44
44
  unsigned long count;
45
- drow_t* drows;
45
+ cwdrow_t* drows;
46
46
  char* name;
47
- } dict_t;
47
+ } cwdict_t;
48
48
 
49
49
  #include "seuss.h"
50
50
  #include "latin.h"
@@ -56,16 +56,24 @@ typedef struct dictionary_container_type {
56
56
  #include "config.h"
57
57
  #include "dict.h"
58
58
 
59
- char* chinwag(cw_t type, unsigned long min, unsigned long max, dict_t dict);
59
+ char* chinwag
60
+ (cw_t type, unsigned long min, unsigned long max, cwdict_t dict);
60
61
 
61
- #define ltr(amt, dict) ltr_rng(amt, amt, dict)
62
- #define wrd(amt, dict) wrd_rng(amt, amt, dict)
63
- #define snt(amt, dict) snt_rng(amt, amt, dict)
64
- #define pgf(amt, dict) pgf_rng(amt, amt, dict)
62
+ char* cw_ltr_rng
63
+ (unsigned long min, unsigned long max, cwdict_t dict);
65
64
 
66
- char* ltr_rng(unsigned long min, unsigned long max, dict_t dict);
67
- char* wrd_rng(unsigned long min, unsigned long max, dict_t dict);
68
- char* snt_rng(unsigned long min, unsigned long max, dict_t dict);
69
- char* pgf_rng(unsigned long min, unsigned long max, dict_t dict);
65
+ char* cw_wrd_rng
66
+ (unsigned long min, unsigned long max, cwdict_t dict);
67
+
68
+ char* cw_snt_rng
69
+ (unsigned long min, unsigned long max, cwdict_t dict);
70
+
71
+ char* cw_pgf_rng
72
+ (unsigned long min, unsigned long max, cwdict_t dict);
73
+
74
+ #define cw_ltr(amt, dict) cw_ltr_rng(amt, amt, dict)
75
+ #define cw_wrd(amt, dict) cw_wrd_rng(amt, amt, dict)
76
+ #define cw_snt(amt, dict) cw_snt_rng(amt, amt, dict)
77
+ #define cw_pgf(amt, dict) cw_pgf_rng(amt, amt, dict)
70
78
 
71
79
  #endif
data/ext/chinwag/config.c CHANGED
@@ -1,13 +1,13 @@
1
1
  #include "config.h"
2
2
 
3
3
  const unsigned MAJOR_VERSION = 1;
4
- const unsigned MINOR_VERSION = 1;
5
- const unsigned PATCH_VERSION = 4;
4
+ const unsigned MINOR_VERSION = 2;
5
+ const unsigned PATCH_VERSION = 0;
6
6
 
7
- const char* const DATE_YEAR = "2014";
8
- const char* const DATE_MONTH = "12";
9
- const char* const DATE_DAY = "02";
10
- const char* const REVISION = "743";
7
+ const char* const DATE_YEAR = "2015";
8
+ const char* const DATE_MONTH = "01";
9
+ const char* const DATE_DAY = "03";
10
+ const char* const REVISION = "914";
11
11
 
12
12
  const unsigned SMALL_BUFFER = 1024;
13
13
  const unsigned LARGE_BUFFER = 5120;