Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes to allow building the module with Microsoft VC compiler #3

Open
wants to merge 2 commits into from

2 participants

@juntalis

MSVC is stupid and throws an error during build if you declare a variable anywhere but at the top of a function. Additionally, strncmp is not defined in the MSVC standard headers. To fix these two issues, I moved a couple of variable declarations to the top of their function, and threw in a quick macro so that if the user is compiling the source code from MSVC, it will use _strnicmp instead of strncmp. (Same thing)

@jaredly
Owner

Hey would you like to update this PR? Sorry I didn't get at it earlier; I was serving a mission in germany when you submitted this, but now I'm back in the real world.

Charles Grun... added some commits
Charles Grunwald (Juntalis) Fix for issue #3 daf714e
Charles Grunwald Update parser.c 1202ff8
@juntalis

Sorry for getting back to you a year later on this, but I just now noticed your response. Anyways, I've gone ahead and updated the PR.

Also, sorry for the double commit. Didn't notice the formatting issue in parser.c until after the fact, and made my changes in the web interface. If you'd prefer, I can merge the two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 22, 2014
  1. Fix for issue #3

    Charles Grunwald (Juntalis) authored
  2. Update parser.c

    Charles Grunwald authored
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 21 deletions.
  1. +10 −3 codetalker/c/_speed_tokens.c
  2. +19 −18 codetalker/c/parser.c
View
13 codetalker/c/_speed_tokens.c
@@ -7,6 +7,12 @@
#include "string.h"
#include "_speed_tokens.h"
+#if defined(_WIN32) || defined(_WIN64) || defined(_MSC_VERS)
+#ifndef strncasecmp
+#define strncasecmp _strnicmp
+#endif
+#endif
+
/**
* Backend code for tokenizing strings
*/
@@ -20,11 +26,12 @@
* Returns the number of characters consumed (0 for invalid)
*/
int t_tstring(int at, char* text, int ln) {
+ char which;
int i = at;
if (ln < at + 6 || (text[i] != '\'' && text[i] != '"')) {
return 0;
}
- char which = text[i];
+ which = text[i];
if (text[i+1] != which || text[i+2] != which) {
return 0;
}
@@ -124,7 +131,7 @@ int t_id(int at, char* text, int ln, char* idchars) {
* Returns the number of characters consumed (0 for invalid)
*/
int t_number(int at, char* text, int ln) {
- int i = at;
+ int pre, i = at;
if (text[i] == '-') i++;
if (i >= ln) return 0;
if (text[i] == '.') {
@@ -148,7 +155,7 @@ int t_number(int at, char* text, int ln) {
} else {
return 0;
}
- int pre = i;
+ pre = i;
if (i < ln-2 && (text[i] == 'e' || text[i] == 'E')) {
i++;
if (text[i] == '+' || text[i] == '-') {
View
37 codetalker/c/parser.c
@@ -100,14 +100,16 @@ struct cParseNode* check_special(unsigned int rule, struct RuleSpecial special,
struct cParseNode* _new_parsenode(unsigned int rule);
struct cParseNode* _get_parse_tree(int start, struct Grammar* grammar, struct TokenStream* tokens, struct Error* error) {
+ int m, ignore;
+ int rule = start;
+ struct cParseNode* current, *tmp;
struct cParseNode* parent = parse_rule(start, grammar, tokens, error);
if (parent == NULL) {
return NULL;
}
- struct cParseNode* current = parent->child;
- struct cParseNode* tmp;
- int m, ignore;
- int rule = start;
+ current = parent->child;
+
+
LOG("ignore any trailing ignores\n");
while (tokens->at < tokens->num) {
ignore = 0;
@@ -147,8 +149,9 @@ struct cParseNode* parse_rule(unsigned int rule, struct Grammar* grammar, struct
struct cParseNode* node = _new_parsenode(rule);
struct cParseNode* tmp;
int i;
- LOG("parsing rule #%d %s (token at %d)\n", rule, grammar->rules.rules[rule].name, tokens->at);
int at = tokens->at;
+ LOG("parsing rule #%d %s (token at %d)\n", rule, grammar->rules.rules[rule].name, tokens->at);
+
INDENT();
for (i=0; i < grammar->rules.rules[rule].num; i++) {
tokens->at = at;
@@ -170,13 +173,14 @@ struct cParseNode* parse_rule(unsigned int rule, struct Grammar* grammar, struct
// clean
struct cParseNode* parse_children(unsigned int rule, struct RuleOption* option, struct Grammar* grammar, struct TokenStream* tokens, struct Error* error) {
- LOG("parsing children of %d (token at %d)\n", rule, tokens->at);
struct cParseNode* current = UNINITIALIZED;
unsigned int i = 0, m = 0;
unsigned int at = 0;
struct cParseNode* tmp = NULL;
struct RuleItem* item = NULL;
int ignore;
+ LOG("parsing children of %d (token at %d)\n", rule, tokens->at);
+
INDENT();
for (i=0;i<option->num;i++) {
item = &option->items[i];
@@ -409,8 +413,8 @@ struct cParseNode* check_special(unsigned int rule, struct RuleSpecial special,
DEDENT();
return current;
} else if (special.type == NOIGNORE) {
- LOG("no ignore (initial %d)\n", grammar->rules.rules[rule].dont_ignore);
int before_ignore = grammar->rules.rules[rule].dont_ignore;
+ LOG("no ignore (initial %d)\n", grammar->rules.rules[rule].dont_ignore);
at = tokens->at;
grammar->rules.rules[rule].dont_ignore = 1;
tmp = parse_children(rule, special.option, grammar, tokens, error);
@@ -460,6 +464,7 @@ struct cParseNode* check_special(unsigned int rule, struct RuleSpecial special,
}
struct cParseNode* append_nodes(struct cParseNode* one, struct cParseNode* two) {
+ struct cParseNode* tmp;
LOG("appending nodes; %d to %d\n", (int)one, (int)two);
if (one == UNINITIALIZED) {
LOG("good (noone)\n");
@@ -471,7 +476,7 @@ struct cParseNode* append_nodes(struct cParseNode* one, struct cParseNode* two)
} else if (two == UNINITIALIZED) {
return one;
}
- struct cParseNode* tmp = two;
+ tmp = two;
LOG("getting prev\n");
while (tmp->prev != NULL) {
tmp = tmp->prev;
@@ -503,8 +508,13 @@ struct Token* c_get_tokens(struct Grammar* grammar, char* text, int indent, stru
struct Token* start = NULL;
struct Token* current = NULL;
struct Token* tmp = NULL;
+ struct PToken ptoken;
+ int ID_t = grammar->tokens.num;
+ int DD_t = grammar->tokens.num+1;
+ int res = 0;
+ int dirty;
- struct TokenState state;
+ struct TokenState state;
state.at = 0;
state.ln = strlen(text);
// state.text = text;
@@ -515,15 +525,6 @@ struct Token* c_get_tokens(struct Grammar* grammar, char* text, int indent, stru
state.max_indents = 100;
state.num_indents = 1;
- struct PToken ptoken;
-
- int ID_t = grammar->tokens.num;
- int DD_t = grammar->tokens.num+1;
-
- int res = 0;
-
- int dirty;
-
// printf("with text:: %s\n\n", text);
while (state.at < state.ln) {
Something went wrong with that request. Please try again.