free(spaces);
}
-bool option(const char* str, const char* shortopt, const char* longopt){
+bool option(const char* str, const char* shortopt, const char* longopt) {
char* dos_shortopt = __dw_strcat("/", shortopt);
char* dos_longopt = __dw_strcat("/", longopt);
char* nix_shortopt = __dw_strcat("-", shortopt);
if(option(argv[i], "V", "version")) {
printf("DataWorks version %s %s %s\n", dataworks_get_version(), dataworks_get_compile_date(), dataworks_get_platform());
return 0;
- } else if(option(argv[i], "C", "create")){
+ } else if(option(argv[i], "C", "create")) {
create = true;
} else if(option(argv[i], "NC", "noclear")) {
clear = false;
banner = false;
log = false;
clear = false;
- } else if(option(argv[i], "NB", "nobanner")){
+ } else if(option(argv[i], "NB", "nobanner")) {
banner = false;
} else if(option(argv[i], "NL", "nolog")) {
log = false;
- } else if(option(argv[i], "f", "file")){
+ } else if(option(argv[i], "f", "file")) {
fprog = argv[i + 1];
i++;
} else {
struct Node* parser_process(struct dataworks_db* db, struct Node* node, bool dolog) {
if(node->ident != NULL) {
- if(dolog) __dw_print_node(node, true);
int i;
struct Node* newnode = malloc(sizeof(*newnode));
newnode->ident = NULL;
newnode->string = NULL;
newnode->nodes = NULL;
+ newnode->type = 0;
newnode->errnum = DW_ERR_SUCCESS;
char** fields = malloc(sizeof(*fields));
fields[0] = NULL;
return newnode;
}
if(__dw_strcaseequ(node->ident, "print")) {
- if(r->string != NULL) {
+ if(r->type == 'N') {
+ printf("%f", r->number);
+ } else if(r->string != NULL) {
printf("%s", r->string);
}
fflush(stdout);
r->error = true;
r->errnum = DW_ERR_PARSER_FAIL;
} else {
+ if(dolog) {
+ __dw_print_node(node, true);
+ printf("\n");
+ }
struct Node* ret = parser_process(db, node, dolog);
if(ret->errnum == DW_ERR_SUCCESS) {
__dw_print_node(ret, true);
+ printf("\n");
} else {
r->error = true;
r->errnum = ret->errnum;
if(node->type == 'N') {
printf("%f", node->number);
fflush(stdout);
- if(top) printf("\n");
} else if(node->string != NULL) {
printf("\"%s\"", node->string);
fflush(stdout);
- if(top) printf("\n");
} else if(node->ident != NULL) {
printf("%s(", node->ident);
fflush(stdout);
}
printf(")");
fflush(stdout);
- if(top) printf("\n");
}
}