MACRO_DATA * JReadMacro_silently(struct StateData * state) { FUNCNAME("JReadMacro_silently"); char filename[1000]; sprintf(filename, "./tools/macros/output.amc");//TODO print to same file, not new file, otherwise I might have MANY files MSG("about to shut down std out... this might cause a problem on the HPC\n"); int stdoutBackupFd; FILE *nullOut; stdoutBackupFd = CROSS_DUP(STDOUT_FILENO); fflush(stdout); nullOut = fopen(nulFileName, "w"); CROSS_DUP2(fileno(nullOut), STDOUT_FILENO); MACRO_DATA * data = read_macro(filename); //macro_test(data, "TEST.amc");//TODO: DEBUG, delete? MSG("read macro %s\n", filename); //WAIT_REALLY; fflush(stdout); fclose(nullOut); CROSS_DUP2(stdoutBackupFd, STDOUT_FILENO); close(stdoutBackupFd); MSG("std out returned\n"); return data; }
void parse_maps(ast::Environ & env) { SourceFile * code = new_source_file(SOURCE_PREFIX "grammer.ins"); code->internal = true; try { SourceStr str(code); parse_prod("S_SPACING", str, ParseInfo(env.peg), &env); while (!str.empty()) { const Syntax * p = parse_prod("SEXP", str, ParseInfo(env.peg), &env); parse_prod("S_SPACING", str, ParseInfo(env.peg), &env); read_macro(p, env); } } catch (Error * err) { fprintf(stderr, "%s\n", err->message().c_str()); exit(1); } }
static bool read_data(int dataset, VarInfo6& info) { bool bRet = false; char* ctype = getScilabTypeFromDataSet6(dataset); std::string type(ctype); FREE(ctype); info.ctype = type; if (type == g_SCILAB_CLASS_DOUBLE) { info.type = sci_matrix; return read_double(dataset, info); } if (type == g_SCILAB_CLASS_STRING) { info.type = sci_strings; return read_string(dataset, info); } if (type == g_SCILAB_CLASS_LIST) { info.type = sci_list; return read_list(dataset, info, "list"); } if (type == g_SCILAB_CLASS_TLIST) { info.type = sci_tlist; return read_list(dataset, info, "tlist"); } if (type == g_SCILAB_CLASS_MLIST) { info.type = sci_mlist; return read_list(dataset, info, "mlist"); } if (type == g_SCILAB_CLASS_BOOLEAN) { info.type = sci_boolean; return read_boolean(dataset, info); } if (type == g_SCILAB_CLASS_POLY) { info.type = sci_poly; return read_poly(dataset, info); } if (type == g_SCILAB_CLASS_INT) { info.type = sci_ints; return read_integer(dataset, info); } if (type == g_SCILAB_CLASS_SPARSE) { info.type = sci_sparse; return read_sparse(dataset, info); } if (type == g_SCILAB_CLASS_BSPARSE) { info.type = sci_boolean_sparse; return read_boolean_sparse(dataset, info); } if (type == g_SCILAB_CLASS_VOID) { info.type = sci_void; return read_void(dataset, info); } if (type == g_SCILAB_CLASS_UNDEFINED) { info.type = sci_undefined; return read_undefined(dataset, info); } if (type == g_SCILAB_CLASS_STRUCT) { info.type = sci_mlist; return read_struct(dataset, info); } if (type == g_SCILAB_CLASS_CELL) { info.type = sci_mlist; return read_cell(dataset, info); } if (type == g_SCILAB_CLASS_HANDLE) { info.type = sci_handles; return read_handles(dataset, info); } if (type == g_SCILAB_CLASS_MACRO) { info.type = sci_c_function; return read_macro(dataset, info); } Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "listvar_in_hdf5"); return false; }
char * read_string(char endch, int esc) { int ch, oldch; size_t pos, len, slen; char *name, *s, *buf; struct macro *macro; len = 24; buf = xmalloc(len + 1); pos = 0; while ((ch = lex_getc()) != endch) { switch (ch) { case EOF: yyerror("missing %c", endch); case '\\': if (!esc) break; switch (ch = lex_getc()) { case EOF: yyerror("missing %c", endch); case 'r': ch = '\r'; break; case 'n': ch = '\n'; break; case 't': ch = '\t'; break; } break; case '$': case '%': if (!esc) break; oldch = ch; ch = lex_getc(); if (ch == EOF) yyerror("missing %c", endch); if (ch != '{') { lex_ungetc(ch); ch = oldch; break; } name = read_macro(oldch, '{'); if ((macro = find_macro(name)) == NULL) { xfree(name); continue; } xfree(name); if (macro->type == MACRO_NUMBER) xasprintf(&s, "%lld", macro->value.num); else s = macro->value.str; slen = strlen(s); ENSURE_FOR(buf, len, pos, slen + 1); memcpy(buf + pos, s, slen); pos += slen; if (macro->type == MACRO_NUMBER) xfree(s); continue; } buf[pos++] = ch; ENSURE_SIZE(buf, len, pos); } buf[pos] = '\0'; return (buf); }
int read_token(int ch) { int ch2; char token[128], *name; size_t tlen; struct token *ptr; struct macro *macro; tlen = 0; token[tlen++] = ch; while ((ch = lex_getc()) != EOF) { if (!isalnum((u_char) ch) && ch != '-' && ch != '_') break; token[tlen++] = ch; if (tlen == (sizeof token) - 1) yyerror("token too long"); } token[tlen] = '\0'; lex_ungetc(ch); /* * ifdef/ifndef/endif is special-cased here since it is really really * hard to make work with yacc. */ if (strcmp(token, "ifdef") == 0 || strcmp(token, "ifndef") == 0) { while ((ch = lex_getc()) != EOF && isspace((u_char) ch)) ; if (ch != '$' && ch != '%') yyerror("syntax error"); ch2 = lex_getc(); if (ch2 != '{' && !isalnum((u_char) ch2)) yyerror("invalid macro name"); name = read_macro(ch, ch2); macro = find_macro(name); xfree(name); if (token[2] == 'n' && macro != NULL) lex_skip = 1; if (token[2] != 'n' && macro == NULL) lex_skip = 1; lex_ifdef++; return (NONE); } if (strcmp(token, "endif") == 0) { if (lex_ifdef == 0) yyerror("spurious endif"); lex_ifdef--; if (lex_ifdef == 0) lex_skip = 0; return (NONE); } if (strcmp(token, "include") == 0) { /* * This is a bit strange. * * yacc may have symbols buffered and be waiting for more to * decide which production to match, so we can't just switch * file now. So, we set a flag that tells yylex to switch files * next time it's called and return the NONE symbol. This is a * placeholder not used in any real productions, so it should * cause yacc to match using whatever it has (assuming it * can). If we don't do this, there are problems with things * like: * * $file = "abc" * include "${file}" * * The include token is seen before yacc has matched the * previous line, so the macro doesn't exist when we try to * build the include file path. */ lex_include = 1; return (NONE); } ptr = bsearch(token, tokens, (sizeof tokens)/(sizeof tokens[0]), sizeof tokens[0], cmp_token); if (ptr == NULL) yyerror("unknown token: %s", token); return (ptr->value); }
int yylex(void) { int ch, value; char *path; struct replpath rp; /* Switch to new file. See comment in read_token below. */ if (lex_include) { while ((ch = lex_getc()) != EOF && isspace((u_char) ch)) ; if (ch != '"' && ch != '\'') yyerror("syntax error"); if (ch == '"') rp.str = read_string('"', 1); else rp.str = read_string('\'', 0); path = replacepath(&rp, parse_tags, NULL, NULL, conf.user_home); xfree(rp.str); include_start(path); lex_include = 0; } restart: while ((ch = lex_getc()) != EOF) { switch (ch) { case '#': /* Comment: discard until EOL. */ while ((ch = lex_getc()) != '\n' && ch != EOF) ; parse_file->line++; break; case '\'': yylval.string = read_string('\'', 0); value = STRING; goto out; case '"': yylval.string = read_string('"', 1); value = STRING; goto out; case '$': ch = lex_getc(); if (ch == '(') { yylval.string = read_command(); value = STRCOMMAND; goto out; } if (ch == '{' || isalnum((u_char) ch)) { yylval.string = read_macro('$', ch); value = STRMACRO; goto out; } yyerror("invalid macro name"); case '%': ch = lex_getc(); if (ch == '(') { yylval.string = read_command(); value = NUMCOMMAND; goto out; } if (ch == '{' || isalnum((u_char) ch)) { yylval.string = read_macro('%', ch); value = NUMMACRO; goto out; } yyerror("invalid macro name"); case '=': ch = lex_getc(); if (ch == '=') { value = TOKEQ; goto out; } lex_ungetc(ch); value = '='; goto out; case '!': ch = lex_getc(); if (ch == '=') { value = TOKNE; goto out; } lex_ungetc(ch); value = '!'; goto out; case '~': case '+': case '(': case ')': case ',': case '<': case '>': case '{': case '}': case '*': value = ch; goto out; case '\n': parse_file->line++; break; case ' ': case '\t': break; default: if (ch != '_' && ch != '-' && !isalnum((u_char) ch)) yyerror("unexpected character: %c", ch); if (isdigit((u_char) ch)) { yylval.number = read_number(ch); value = NUMBER; goto out; } value = read_token(ch); goto out; } } if (!include_finish()) goto restart; if (lex_ifdef != 0) yyerror("missing endif"); return (EOF); out: if (lex_skip) goto restart; return (value); }
int parse_directive(struct prog_info *pi) { int directive, pragma; int ok = True; int i; char *next, *data, buf[140]; struct file_info *fi_bak; struct def *def; struct data_list *incpath, *dl; next = get_next_token(pi->fi->scratch, TERM_SPACE); my_strupr(pi->fi->scratch); directive = lookup_keyword(directive_list, pi->fi->scratch + 1, True); if(directive == -1) { print_msg(pi, MSGTYPE_ERROR, "Unknown directive: %s", pi->fi->scratch); return(True); } switch(directive) { case DIRECTIVE_BYTE: if (!next) { print_msg(pi, MSGTYPE_ERROR, ".BYTE needs a size operand"); return(True); } if (pi->segment == pi->cseg) print_msg(pi, MSGTYPE_ERROR, ".BYTE directive cannot be used within the code segment (.CSEG)"); get_next_token(next, TERM_END); if (!get_expr(pi, next, &i)) return(False); if ((pi->pass == PASS_2) && pi->list_line && pi->list_on) { fprintf(pi->list_file, "%c:%06x %s\n", pi->segment->ident, pi->segment->addr, pi->list_line); pi->list_line = NULL; } if (i > 0) { fix_orglist(pi->segment); advance_ip(pi->segment, i); def_orglist(pi->segment); } break; case DIRECTIVE_CSEG: fix_orglist(pi->segment); def_orglist(pi->cseg); break; case DIRECTIVE_CSEGSIZE: break; case DIRECTIVE_DB: if((pi->pass == PASS_2) && pi->list_line && pi->list_on) { fprintf(pi->list_file, " %s\n", pi->list_line); pi->list_line = NULL; } return(parse_db(pi, next)); // break; /* Directive .def */ case DIRECTIVE_DEF: if(!next) { print_msg(pi, MSGTYPE_ERROR, ".DEF needs an operand"); return(True); } data = get_next_token(next, TERM_EQUAL); if(!(data && (tolower(data[0]) == 'r') && isdigit(data[1]))) { print_msg(pi, MSGTYPE_ERROR, "%s needs a register (e.g. .def BZZZT = r16)", next); return(True); } i = atoi(&data[1]); /* check range of given register */ if(i > 31) print_msg(pi, MSGTYPE_ERROR, "R%d is not a valid register", i); /* check if this reg is already assigned */ for(def = pi->first_def; def; def = def->next) { if(def->reg == i && pi->pass == PASS_1 && !pi->NoRegDef) { print_msg(pi, MSGTYPE_WARNING, "r%d is already assigned to '%s'!", i, def->name); return(True); } } /* check if this regname is already defined */ for(def = pi->first_def; def; def = def->next) { if(!nocase_strcmp(def->name, next)) { if(pi->pass == PASS_1 && !pi->NoRegDef) { print_msg(pi, MSGTYPE_WARNING, "'%s' is already assigned as r%d but will now be set to r%i!", next, def->reg, i); } def->reg = i; return(True); } } /* B.A.: Check, if symbol is already defined as a label or constant */ if(pi->pass == PASS_2) { if(get_label(pi,next,NULL)) print_msg(pi, MSGTYPE_WARNING, "Name '%s' is used for a register and a label", next); if(get_constant(pi,next,NULL)) print_msg(pi, MSGTYPE_WARNING, "Name '%s' is used for a register and a constant", next); } def = malloc(sizeof(struct def)); if(!def) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } def->next = NULL; if(pi->last_def) pi->last_def->next = def; else pi->first_def = def; pi->last_def = def; def->name = malloc(strlen(next) + 1); if(!def->name) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } strcpy(def->name, next); def->reg = i; break; case DIRECTIVE_DEVICE: if(pi->pass == PASS_2) return(True); if(!next) { print_msg(pi, MSGTYPE_ERROR, ".DEVICE needs an operand"); return(True); } if (pi->device->name != NULL) { /* B.A.: Check for multiple device definitions */ print_msg(pi, MSGTYPE_ERROR, "More than one .DEVICE definition"); } if (pi->cseg->count || pi->dseg->count || pi->eseg->count) { /* B.A.: Check if something was already assembled */ print_msg(pi, MSGTYPE_ERROR, ".DEVICE definition must be before any code lines"); } else { if ((pi->cseg->addr != pi->cseg->lo_addr ) || (pi->dseg->addr != pi->dseg->lo_addr ) || (pi->eseg->addr != pi->eseg->lo_addr )) { /* B.A.: Check if something was already assembled XXX probably redundant */ print_msg(pi, MSGTYPE_ERROR, ".DEVICE definition must be before any .ORG directive"); } } get_next_token(next, TERM_END); pi->device = get_device(pi,next); if (!pi->device) { print_msg(pi, MSGTYPE_ERROR, "Unknown device: %s", next); pi->device = get_device(pi,NULL); /* B.A.: Fix segmentation fault if device is unknown */ } /* Now that we know the device type, we can * start memory allocation from the correct offsets. */ fix_orglist(pi->segment); rewind_segments(pi); def_orglist(pi->segment); break; case DIRECTIVE_DSEG: fix_orglist(pi->segment); def_orglist(pi->dseg); if (pi->dseg->hi_addr == 0) { /* XXX move to emit */ print_msg(pi, MSGTYPE_ERROR, "Can't use .DSEG directive because device has no RAM"); } break; case DIRECTIVE_DW: if (pi->segment->flags & SEG_BSS_DATA) { print_msg(pi, MSGTYPE_ERROR, "Can't use .DW directive in data segment (.DSEG)"); return(True); } while (next) { data = get_next_token(next, TERM_COMMA); if(pi->pass == PASS_2) { if(!get_expr(pi, next, &i)) return(False); if((i < -32768) || (i > 65535)) print_msg(pi, MSGTYPE_WARNING, "Value %d is out of range (-32768 <= k <= 65535). Will be masked", i); } if (pi->pass == PASS_2) { if (pi->list_line && pi->list_on) { fprintf(pi->list_file, " %s\n", pi->list_line); pi->list_line = NULL; fprintf(pi->list_file, "%c:%06x %04x\n", pi->segment->ident, pi->segment->addr, i); } if (pi->segment == pi->eseg) { write_ee_byte(pi, pi->eseg->addr, (unsigned char)i); write_ee_byte(pi, pi->eseg->addr + 1, (unsigned char)(i >> 8)); } if (pi->segment == pi->cseg) { write_prog_word(pi, pi->cseg->addr, i); } } if (pi->segment == pi->eseg) advance_ip(pi->eseg, 2); if (pi->segment == pi->cseg) advance_ip(pi->cseg, 1); next = data; } break; case DIRECTIVE_ENDM: case DIRECTIVE_ENDMACRO: print_msg(pi, MSGTYPE_ERROR, "No .MACRO found before .ENDMACRO"); break; case DIRECTIVE_EQU: if(!next) { print_msg(pi, MSGTYPE_ERROR, ".EQU needs an operand"); return(True); } data = get_next_token(next, TERM_EQUAL); if(!data) { print_msg(pi, MSGTYPE_ERROR, "%s needs an expression (e.g. .EQU BZZZT = 0x2a)", next); return(True); } get_next_token(data, TERM_END); if(!get_expr(pi, data, &i)) return(False); if(test_label(pi,next,"%s have already been defined as a label")!=NULL) return(True); if(test_variable(pi,next,"%s have already been defined as a .SET variable")!=NULL) return(True); /* B.A. : New. Forward references allowed. But check, if everything is ok ... */ if(pi->pass==PASS_1) { /* Pass 1 */ if(test_constant(pi,next,"Can't redefine constant %s, use .SET instead")!=NULL) return(True); if(def_const(pi, next, i)==False) return(False); } else { /* Pass 2 */ int j; if(get_constant(pi, next, &j)==False) { /* Defined in Pass 1 and now missing ? */ print_msg(pi, MSGTYPE_ERROR, "Constant %s is missing in pass 2", next); return(False); } if(i != j) { print_msg(pi, MSGTYPE_ERROR, "Constant %s changed value from %d in pass1 to %d in pass 2", next,j,i); return(False); } /* OK. Definition is unchanged */ } if((pi->pass == PASS_2) && pi->list_line && pi->list_on) { fprintf(pi->list_file, " %s\n", pi->list_line); pi->list_line = NULL; } break; case DIRECTIVE_ESEG: fix_orglist(pi->segment); def_orglist(pi->eseg); if(pi->device->eeprom_size == 0) { /* XXX */ print_msg(pi, MSGTYPE_ERROR, "Can't use .ESEG directive because device has no EEPROM"); } break; case DIRECTIVE_EXIT: pi->fi->exit_file = True; break; /*** .include ***/ case DIRECTIVE_INCLUDE: if(!next) { print_msg(pi, MSGTYPE_ERROR, "Nothing to include"); return(True); } next = term_string(pi, next); if((pi->pass == PASS_2) && pi->list_line && pi->list_on) { fprintf(pi->list_file, " %s\n", pi->list_line); pi->list_line = NULL; } // Test if include is in local directory ok = test_include(next); data = NULL; if(!ok) for(incpath = GET_ARG_LIST(pi->args, ARG_INCLUDEPATH); incpath && !ok; incpath = incpath->next) { i = strlen(incpath->data); if(data) free(data); data = malloc(i + strlen(next) + 2); if(!data) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } strcpy(data, incpath->data); if((data[i - 1] != '\\') && (data[i - 1] != '/')) data[i++] = '/'; strcpy(&data[i], next); //printf("testing: %s\n", data); ok = test_include(data); } if(ok) { fi_bak = pi->fi; ok = parse_file(pi, data ? data : next); pi->fi = fi_bak; } else print_msg(pi, MSGTYPE_ERROR, "Cannot find include file: %s", next); if(data) free(data); break; /*** .includepath ***/ case DIRECTIVE_INCLUDEPATH: if(!next) { print_msg(pi, MSGTYPE_ERROR, ".INCLUDEPATH needs an operand"); return(True); } data = get_next_token(next, TERM_SPACE); if(data) { print_msg(pi, MSGTYPE_ERROR, ".INCLUDEPATH needs an operand!!!"); get_next_token(data, TERM_END); if(!get_expr(pi, data, &i)) return(False); } next = term_string(pi, next); /* get arg list start pointer */ incpath = GET_ARG_LIST(pi->args, ARG_INCLUDEPATH); /* search for last element */ if(incpath == NULL) { dl = malloc(sizeof(struct data_list)); data = malloc(strlen(next)+1); if(dl && data) { dl->next = NULL; strcpy(data, next); dl->data = data; SET_ARG_LIST(pi->args, ARG_INCLUDEPATH, dl); } else { printf("Error: Unable to allocate memory\n"); return(False); } } else add_arg(&incpath, next); break; case DIRECTIVE_LIST: if(pi->pass == PASS_2) if(pi->list_file) pi->list_on = True; break; case DIRECTIVE_LISTMAC: if(pi->pass == PASS_2) SET_ARG_I(pi->args, ARG_LISTMAC, True); break; case DIRECTIVE_MACRO: return(read_macro(pi, next)); // break; case DIRECTIVE_NOLIST: if(pi->pass == PASS_2) pi->list_on = False; break; case DIRECTIVE_ORG: if(!next) { print_msg(pi, MSGTYPE_ERROR, ".ORG needs an operand"); return(True); } get_next_token(next, TERM_END); if(!get_expr(pi, next, &i)) return(False); fix_orglist(pi->segment); pi->segment->addr = i; /* XXX advance */ def_orglist(pi->segment); if(pi->fi->label) pi->fi->label->value = i; if((pi->pass == PASS_2) && pi->list_line && pi->list_on) { fprintf(pi->list_file, " %s\n", pi->list_line); pi->list_line = NULL; } break; case DIRECTIVE_SET: if(!next) { print_msg(pi, MSGTYPE_ERROR, ".SET needs an operand"); return(True); } data = get_next_token(next, TERM_EQUAL); if(!data) { print_msg(pi, MSGTYPE_ERROR, "%s needs an expression (e.g. .SET BZZZT = 0x2a)", next); return(True); } get_next_token(data, TERM_END); if(!get_expr(pi, data, &i)) return(False); if(test_label(pi,next,"%s have already been defined as a label")!=NULL) return(True); if(test_constant(pi,next,"%s have already been defined as a .EQU constant")!=NULL) return(True); return(def_var(pi, next, i)); // break; case DIRECTIVE_DEFINE: if(!next) { print_msg(pi, MSGTYPE_ERROR, ".DEFINE needs an operand"); return(True); } data = get_next_token(next, TERM_SPACE); if(data) { get_next_token(data, TERM_END); if(!get_expr(pi, data, &i)) return(False); } else i = 1; if(test_label(pi,next,"%s have already been defined as a label")!=NULL) return(True); if(test_variable(pi,next,"%s have already been defined as a .SET variable")!=NULL) return(True); /* B.A. : New. Forward references allowed. But check, if everything is ok ... */ if(pi->pass==PASS_1) { /* Pass 1 */ if(test_constant(pi,next,"Can't redefine constant %s, use .SET instead")!=NULL) return(True); if(def_const(pi, next, i)==False) return(False); } else { /* Pass 2 */ int j; if(get_constant(pi, next, &j)==False) { /* Defined in Pass 1 and now missing ? */ print_msg(pi, MSGTYPE_ERROR, "Constant %s is missing in pass 2", next); return(False); } if(i != j) { print_msg(pi, MSGTYPE_ERROR, "Constant %s changed value from %d in pass1 to %d in pass 2", next,j,i); return(False); } /* OK. Definition is unchanged */ } if((pi->pass == PASS_2) && pi->list_line && pi->list_on) { fprintf(pi->list_file, " %s\n", pi->list_line); pi->list_line = NULL; } break; case DIRECTIVE_NOOVERLAP: if (pi->pass == PASS_1) { fix_orglist(pi->segment); pi->segment_overlap = SEG_DONT_OVERLAP; def_orglist(pi->segment); } break; case DIRECTIVE_OVERLAP: if (pi->pass == PASS_1) { fix_orglist(pi->segment); pi->segment_overlap = SEG_ALLOW_OVERLAP; def_orglist(pi->segment); } break; case DIRECTIVE_PRAGMA: if (!next) { print_msg(pi, MSGTYPE_ERROR, "PRAGMA needs an operand, %s should be specified", snprint_list(buf, sizeof(buf), pragma_list)); return(True); } my_strupr(next); data = get_next_token(next, TERM_SPACE); pragma = lookup_keyword(pragma_list, next, False); switch (pragma) { case PRAGMA_OVERLAP: if (pi->pass == PASS_1) { int overlap_setting = OVERLAP_UNDEFINED; if (data) { my_strupr(data); overlap_setting = lookup_keyword(overlap_value, data, False); }; switch (overlap_setting) { case OVERLAP_DEFAULT: pi->effective_overlap = GET_ARG_I(pi->args, ARG_OVERLAP); break; case OVERLAP_IGNORE: case OVERLAP_WARNING: case OVERLAP_ERROR: pi->effective_overlap = overlap_setting; break; default: print_msg(pi, MSGTYPE_ERROR, "For PRAGMA %s directive" " %s should be specified as the parameter", next, snprint_list(buf, sizeof(buf), overlap_value)); return(False); } } return(True); break; default: if(pi->pass == PASS_2) print_msg(pi, MSGTYPE_MESSAGE, "PRAGMA %s directive currently ignored", next); return(True); } break; case DIRECTIVE_UNDEF: // TODO break; case DIRECTIVE_IFDEF: if(!next) { print_msg(pi, MSGTYPE_ERROR, ".IFDEF needs an operand"); return(True); } get_next_token(next, TERM_END); /* B.A. : Forward referenc is not allowed for ifdef and ifndef */ /* Store undefined symbols in blacklist in pass1 and check, if they are still undefined in pass2 */ if(get_symbol(pi, next, NULL)) { #if 0 // If it's not defined in the first pass, but was defined later // then it should be considered OK with regards to ifdef..endif and // ifndef..endif code sections. Removed this code. if(pi->pass==PASS_2) { /* B.A. : 'Still undefined'-test in pass 2 */ if(test_blacklist(pi,next,"Forward reference (%s) not allowed in .ifdef directive")!=NULL) return(False); } #else pi->conditional_depth++; #endif } else { if(pi->pass==PASS_1) { /* B.A. : Store undefined symbols in pass 1 */ if(def_blacklist(pi, next)==False) return(False); } if(!spool_conditional(pi, False)) return(False); } break; case DIRECTIVE_IFNDEF: if(!next) { print_msg(pi, MSGTYPE_ERROR, ".IFNDEF needs an operand"); return(True); } get_next_token(next, TERM_END); /* B.A. : Forward referenc is not allowed for ifdef and ifndef */ /* Store undefined symbols in blacklist in pass1 and check, if they are still undefined in pass2 */ if(!get_symbol(pi, next, NULL)) { #if 0 if(pi->pass==PASS_2) { /* B.A. : 'Still undefined'-test in pass 2 */ // If it's not defined in the first pass, but was defined later // then it should be considered OK with regards to ifdef..endif and // ifndef..endif code sections. Removed this code. if(test_blacklist(pi,next,"Forward reference (%s) not allowed in .ifndef directive")!=NULL) return(False); } if(!spool_conditional(pi, False)) return(False); #else pi->conditional_depth++; #endif } else { if(pi->pass==PASS_1) { /* B.A. : Store undefined symbols in pass 1 */ if(def_blacklist(pi, next)==False) return(False); } if(!spool_conditional(pi, False)) return(False); } break; case DIRECTIVE_IF: if(!next) { print_msg(pi, MSGTYPE_ERROR, ".IF needs an expression"); return(True); } get_next_token(next, TERM_END); if(!get_expr(pi, next, &i)) return(False); if(i) pi->conditional_depth++; else { if(!spool_conditional(pi, False)) return(False); } break; case DIRECTIVE_ELSE: case DIRECTIVE_ELIF: case DIRECTIVE_ELSEIF: if(!spool_conditional(pi, True)) return(False); break; case DIRECTIVE_ENDIF: if(pi->conditional_depth == 0) print_msg(pi, MSGTYPE_ERROR, "Too many .ENDIF"); else pi->conditional_depth--; break; case DIRECTIVE_MESSAGE: if(pi->pass == PASS_1) return(True); if(!next) { print_msg(pi, MSGTYPE_ERROR, "No message parameter supplied"); return(True); } /* B.A : Extended .MESSAGE. Now a comma separated list like in .db is possible and not only a string */ print_msg(pi, MSGTYPE_MESSAGE_NO_LF, NULL); /* Prints Line Header (filename, linenumber) without trailing /n */ while(next) { /* Modified code from parse_db(). Thank you :-) */ data = get_next_token(next, TERM_COMMA); if(next[0] == '\"') { /* string parsing */ next = term_string(pi, next); print_msg(pi, MSGTYPE_APPEND,"%s",next); while(*next != '\0') { next++; } } else { if(!get_expr(pi, next, &i)) { print_msg(pi, MSGTYPE_APPEND,"\n"); /* Add newline */ return(False); } print_msg(pi, MSGTYPE_APPEND,"0x%02X",i); } next = data; } print_msg(pi, MSGTYPE_APPEND,"\n"); /* Add newline */ break; case DIRECTIVE_WARNING: if(pi->pass == PASS_1) return(True); if(!next) { print_msg(pi, MSGTYPE_ERROR, "No warning string supplied"); return(True); } next = term_string(pi, next); print_msg(pi, MSGTYPE_WARNING, next); break; case DIRECTIVE_ERROR: if(!next) { /* B.A : Fix segfault bug if .error without parameter was used */ print_msg(pi, MSGTYPE_ERROR, "No error string supplied"); return(True); } next = term_string(pi, next); print_msg(pi, MSGTYPE_ERROR, "%s", next); pi->error_count = pi->max_errors; if(pi->pass == PASS_1) return(True); break; }
int read_macro(char *base_base, char *nom, int px, int py, int relatif, int mode_inclusion, int *selected_plane, struct hsearch_data *hash_table) { int i; int nbre_groupe_macro, nbre_gpes_inclus, nbre_liaison_macro; static char ligne[TAILLE_CHAINE]; char base_nom[SIZE_NO_NAME]; char base_nom_complet[SIZE_NO_NAME]; type_groupe *groupe_local, *debut_macro; type_liaison * liaison; FILE *f1; char macro_script_path[PATH_MAX]; int reverse; int mx, my; float zoom; int no_macro_used; int clipboard = 0; nbre_groupe_macro = 0; memcpy(base_nom, nom, (strlen(nom) + 1) * sizeof(char)); get_base_name(base_nom); if (strcmp(base_nom, "copy_buffer") == 0) { clipboard = 1; snprintf(macro_script_path, PATH_MAX, "%s", nom); } else { snprintf(macro_script_path, PATH_MAX, "%s/%s", sc->directory, nom); } f1 = fopen(macro_script_path, "r"); if (f1 == NULL) PRINT_WARNING("\n Error while opening the macro script file %s \n", macro_script_path); no_macro_used = sc->nbre_macro_lues; *selected_plane = (100 + sc->nbre_macro_lues * 7); if (1/*mode_inclusion==0*/) { while (plane_used(*selected_plane) == 1) { no_macro_used++; (*selected_plane) = (100 + no_macro_used * 7); } } if (clipboard) { memcpy(base_nom, "c", (strlen("c") + 1) * sizeof(char)); } if (base_base == NULL) sprintf(base_nom_complet, "%s[%d]", base_nom, no_macro_used); else memcpy(base_nom_complet, base_base, (strlen(base_base) + 1) * sizeof(char)); groupe_local = sc->fin_groupe; sc->first_comment_group = (type_noeud_comment *) read_line_with_comment(f1, sc->first_comment_group, ligne); sscanf(ligne, "nombre de groupes = %d\n", &nbre_groupe_macro); if (nbre_groupe_macro == 0) { printf("ATTENTION no group in this script: ABORT reading !!!\n"); return 0; /* aucun groupe inclus*/ } mx = my = 0; /* centre de gravite des groupes lus */ debut_macro = NULL; nbre_gpes_inclus = 0; for (i = 0; i < nbre_groupe_macro; i++) { groupe_local = (type_groupe *) creer_groupeb(groupe_local); if (sc->deb_groupe == NULL) sc->deb_groupe = groupe_local; /* c'est le 1er groupe lu */ sc->nbre_neurone += read_one_group_leto(f1, groupe_local, base_nom_complet, hash_table, NULL); if (debut_macro == NULL) debut_macro = groupe_local; sc->fin_groupe = groupe_local; /* gestion de la lecture d'un sous reseau, PB ICI ............. */ if (groupe_local->type == No_Sub_Network) { if (groupe_local->reverse > 0) reverse = 1; else reverse = -1; groupe_local->reverse = reverse * (100 + sc->nbre_macro_lues * 7); /* plan >100 pour tout bouger ensemble */ nbre_gpes_inclus = nbre_gpes_inclus + read_macro(groupe_local->no_name, groupe_local->nom, groupe_local->posx, groupe_local->posy, 1, 1, selected_plane, hash_table); } groupe_local->deja_active = mode_inclusion; /* c'est un groupe insere (a ne pas resauvegarder) */ mx = mx + groupe_local->posx; my = my + groupe_local->posy; if (relatif == 0) { groupe_local->posx = groupe_local->posx + 50; groupe_local->posy = groupe_local->posy + 50; } groupe_local->p_posx += 50; groupe_local->p_posy += 50; if (groupe_local->reverse > 0) reverse = 1; else reverse = -1; groupe_local->reverse = reverse * (*selected_plane); /* plan >100 pour tout bouger ensemble */ } /*sc->fin_groupe = groupe_local;*/ if (relatif == 1) { if (mode_inclusion == 1) zoom = 0.1; else zoom = 0.75; mx = mx / nbre_groupe_macro; my = my / nbre_groupe_macro; groupe_local = debut_macro; for (i = 0; i < nbre_groupe_macro; i++) /* tres laid PG !!! */ { groupe_local->posx = 2 + px + (int) (((float) (groupe_local->posx - mx)) * zoom); groupe_local->posy = 2 + py + (int) (((float) (groupe_local->posy - my)) * zoom); groupe_local = groupe_local->s; } } sc->first_comment_link = (type_noeud_comment *) read_line_with_comment(f1, sc->first_comment_link, ligne); sscanf(ligne, "nombre de liaisons = %d\n", &nbre_liaison_macro); liaison = sc->fin_liaison; for (i = sc->nbre_liaison; i < sc->nbre_liaison + nbre_liaison_macro; i++) { if (sc->deb_liaison == NULL) { liaison = sc->deb_liaison = sc->fin_liaison = (type_liaison *) creer_liaison(NULL); } else liaison = creer_liaison(liaison); read_one_link(f1, liaison, base_nom_complet, hash_table); liaison->deja_active = mode_inclusion; /* liaison->depart = liaison->depart + sc->nbre_groupe; *//* offset to change the connected groups (inutile maintenant)*/ /* liaison->arrivee = liaison->arrivee + sc->nbre_groupe; *//* c'est le nom compose qui evite le pb */ #ifndef AVEUGLE initialise_coudes_liaison(liaison); /*initialise les coudes de la liaison - par defaut on ne reprend pas le graphisme */ #endif } sc->fin_liaison = liaison; /* cette solution n'est valable que si le lien micro macro est toujours cree en premier: faux en ce moment ex: kohonen ce lien n'existe pas */ /* detruit_liaison(liaison1); *//* only a single link between micro and macro neuron */ sc->nbre_liaison = sc->nbre_liaison + nbre_liaison_macro; sc->nbre_groupe = nbre_groupe_macro + sc->nbre_groupe; fclose(f1); if (no_macro_used > sc->nbre_macro_lues) sc->nbre_macro_lues = no_macro_used + 1; else sc->nbre_macro_lues = sc->nbre_macro_lues + 1; /*#ifndef AVEUGLE if (sc->premiere_lecture == 0 && onglet_leto->window != NULL) regenerer_test(sc->onglet_leto); #endif*/ return (nbre_groupe_macro + nbre_gpes_inclus); }
void lecture(int recursive_load, TxDonneesFenetre *onglet_leto) { int i; type_groupe *groupe; type_liaison * liaison; FILE *f1; int nbre_liaison_provisoire; int reverse, selected_plane; char *pt; static char ligne[TAILLE_CHAINE]; #ifndef AVEUGLE int j; remove_hash_table(onglet_leto->hashtab); init_hash_table(onglet_leto->hashtab); #else hdestroy(); /* on detruit la table precedente si elle existait */ hcreate(10000); /* table de hachage pour les no de groupes symboliques */ #endif nbre_groupes_lus = 0; /* on initialise le nombre de groupes lus */ /* on place le flag_symb a 1 si le fichier est un .symb * (en esperant que l'utilisateur ne met pas de variable dans un .script !) */ if ((pt = strstr(sc->nomfich1, SYMBOLIQUE_EXTENSION)) != NULL) sc->flag_symb = 1; else sc->flag_symb = 0; f1 = fopen(sc->nomfich1, "r"); if (f1 == NULL) { printf("Cannot open file %s\n", sc->nomfich1); printf("We suppose it is a new script file \n"); return; } liaison = sc->deb_liaison = sc->fin_liaison = NULL; groupe = sc->deb_groupe = sc->fin_groupe = NULL; sc->nbre_neurone = 0; sc->nbre_liaison = 0; sc->last_groupe_number = 0; sc->first_comment_group = (type_noeud_comment *) read_line_with_comment(f1, NULL, ligne); sscanf(ligne, "nombre de groupes = %d\n", &sc->nbre_groupe); printf("Nombre de groupe = %d\n",sc->nbre_groupe); if (sc->first_comment_group != NULL && strstr(sc->first_comment_group->chaine, "!ignore_include") != NULL) { if (recursive_load != 0) { recursive_load = 0; } } sc->infos_xyz=MANY_ALLOCATIONS(1000,char*); for(i=0;i<1000;i++) { sc->infos_xyz[i]=NULL; } for (i = 0; i < sc->nbre_groupe; i++) { if (i != 0) sc->fin_groupe = groupe = creer_groupeb(sc->fin_groupe); else groupe = sc->deb_groupe = sc->fin_groupe = creer_groupeb(NULL); sc->nbre_neurone += read_one_group_leto(f1, groupe, NULL, onglet_leto->hashtab,&(sc->infos_xyz[i])); /* gestion de la lecture d'un sous reseau */ if (groupe->type == No_Sub_Network && recursive_load == 1) { /* le nbre de groupes a ete modifie dans read_macro */ i = i + read_macro(groupe->no_name, groupe->nom, groupe->posx, groupe->posy, 1, 1, &selected_plane, onglet_leto->hashtab); if (groupe->reverse > 0) reverse = 1; else reverse = -1; groupe->reverse = reverse * selected_plane; /* plan >100 pour tout bouger ensemble */ PRINT_WARNING("Les densites perso sont incompatible avec les macro-scripts pour le moment !\n"); } groupe->deja_active = 0; /* c'est un groupe en direct de ce script, non un groupe insere */ } sc->nbre_groupes_lus = nbre_groupes_lus = sc->nbre_groupe; sc->first_comment_link = (type_noeud_comment *) read_line_with_comment(f1, NULL, ligne); sscanf(ligne, "nombre de liaisons = %d\n", &nbre_liaison_provisoire); liaison = sc->fin_liaison; for (i = 0; i < nbre_liaison_provisoire; i++) { if (sc->deb_liaison == NULL) { liaison = sc->deb_liaison = sc->fin_liaison = (type_liaison *) creer_liaison(NULL); } else liaison = (type_liaison *) creer_liaison(liaison); if (onglet_leto == NULL) read_one_link(f1, liaison, NULL, NULL); else read_one_link(f1, liaison, NULL, onglet_leto->hashtab); liaison->deja_active = 0; /* liaison propre au script */ } sc->nbre_liaison = sc->nbre_liaison + nbre_liaison_provisoire; /* tenir compte des scripts inclus */ sc->fin_liaison = liaison; fclose(f1); initialise_liaisons(); #ifndef AVEUGLE j = script_load_file_xml(sc->draw); if (j == 1) { fprintf(stderr, "pb chargement fichier .draw (fichier introuvbale ou non defini) \n"); } else if (j == -1) { fprintf(stderr, "pb chargement fichier draw: no liaisons found\n"); } if (sc->premiere_lecture == 0 && onglet_leto->window != NULL) regenerer_test(onglet_leto); script_backup(sc); #endif sc->premiere_lecture = 0; }
void script_load(donnees_script *script, char *filename, int recursive_load, struct hsearch_data *hash_table) { FILE *file; int groups_nb, links_nb; int i, reverse, selected_plane; type_groupe *group; type_liaison *group_link; char* retour_xyz=NULL; static char ligne[TAILLE_CHAINE]; file = fopen(filename, "r"); if (file == NULL) EXIT_ON_ERROR("Unable to open file %s", filename); script_free_groups(script); script_free_links(script); script_free_group_comments(script); script_free_link_comments(script); remove_hash_table(hash_table); init_hash_table(hash_table); script->first_comment_group = (type_noeud_comment *) read_line_with_comment(file, NULL, ligne); sscanf(ligne, "nombre de groupes = %d\n", &script->nbre_groupe); if (script->first_comment_group != NULL && strstr(script->first_comment_group->chaine, "!ignore_include") != NULL) { recursive_load = 0; } sc->infos_xyz=MANY_ALLOCATIONS(1000,char*); // en attendant ! printf("Nombre de groupe = %d\n",sc->nbre_groupe); for(i=0;i<1000;i++) { sc->infos_xyz[i]=NULL; } for (i = 0; i < script->nbre_groupe; i++) { if (i != 0) script->fin_groupe = group = creer_groupeb(script->fin_groupe); else group = script->deb_groupe = script->fin_groupe = creer_groupeb(NULL); script->nbre_neurone += read_one_group_leto(file, group, NULL, hash_table,&(sc->infos_xyz[i])); /* gestion de la lecture d'un sous reseau */ if (group->type == No_Sub_Network && recursive_load == 1) { /* le nbre de groupes a ete modifie dans read_macro */ i = i + read_macro(group->no_name, group->nom, group->posx, group->posy, 1, 1, &selected_plane, hash_table); if (group->reverse > 0) reverse = 1; else reverse = -1; group->reverse = reverse * selected_plane; /* plan >100 pour tout bouger ensemble */ } group->deja_active = 0; /* c'est un groupe en direct de ce script, non un groupe insere */ } script->nbre_groupes_lus = groups_nb = script->nbre_groupe; script->first_comment_link = (type_noeud_comment *) read_line_with_comment(file, NULL, ligne); sscanf(ligne, "nombre de liaisons = %d\n", &links_nb); group_link = NULL; for (i = 0; i < links_nb; i++) { if (script->deb_liaison == NULL) { group_link = script->deb_liaison = script->fin_liaison = creer_liaison(NULL); } else group_link = creer_liaison(group_link); read_one_link(file, group_link, NULL, hash_table); group_link->deja_active = 0; /* liaison propre au script */ } script->nbre_liaison = script->nbre_liaison + links_nb; /* tenir compte des scripts inclus */ script->fin_liaison = group_link; fclose(file); initialise_liaisons(script); }