void string_terms(const char *prefix, const term_t &str, term_list_t &terms) { term_t ret(prefix); size_t pstart=0; while (pstart!=str.npos) { size_t pend=str.find_first_of(" \t\n\r", pstart); if (pend==str.npos) { add_term(prefix, term_t(str.begin()+pstart, str.end()), terms); break; } add_term(prefix, term_t(str.begin()+pstart, str.begin()+pend), terms); pstart=pend+1; } }
void nl_convert_spice_t::convert(const pstring &contents) { pstring_vector_t spnl(contents, "\n"); // Add gnd net // FIXME: Parameter out("NETLIST_START(dummy)\n"); add_term("0", "GND"); pstring line = ""; for (std::size_t i=0; i < spnl.size(); i++) { // Basic preprocessing pstring inl = spnl[i].trim().ucase(); if (inl.startsWith("+")) line = line + inl.substr(1); else { process_line(line); line = inl; } } process_line(line); dump_nl(); // FIXME: Parameter out("NETLIST_END()\n"); }
NavierStokes1D::NavierStokes1D ( const std::string& name ) : PDE ( name ) { // properties properties()["brief"] = std::string("NavierStokes 1D Partial Differential Equations"); properties()["description"] = std::string("Component that can solve the 1D NavierStokes physics right-hand-side"); options().add("gamma",1.4) .mark_basic() .description("Heat capacity ratio (Cp/Cv)"); options().add("R",287.05) .mark_basic() .description("Gas constant"); options().add("kappa",2.601e-2) .description("Thermal conduction") .mark_basic(); options().add("mu",1.806e-5) .description("Dynamic viscosity") .mark_basic(); options().add("riemann_solver",std::string("Roe")) .mark_basic() .description("Riemann Solver"); m_nb_dim = 1; m_nb_eqs = 3; add_time(); add_term("terms","cf3.sdm.equations.navierstokes.NSTerms1D"); }
void nl_convert_spice_t::convert(const pstring &contents) { std::vector<pstring> spnl(plib::psplit(contents, "\n")); // Add gnd net // FIXME: Parameter out("NETLIST_START(dummy)\n"); add_term("0", "GND"); pstring line = ""; for (const auto &i : spnl) { // Basic preprocessing pstring inl = plib::ucase(plib::trim(i)); if (plib::startsWith(inl, "+")) line = line + inl.substr(1); else { process_line(line); line = inl; } } process_line(line); dump_nl(); // FIXME: Parameter out("NETLIST_END()\n"); }
madara::logger::Logger::Logger (bool log_to_terminal) : mutex_ (), level_ (LOG_ERROR), term_added_ (log_to_terminal), syslog_added_ (false), tag_ ("madara"), timestamp_format_ ("") { if (log_to_terminal) { add_term (); } }
static eval_error shift_term (eval_token et, eval_t *v1) { eval_token op; eval_t v2; eval_error er; if ((er = add_term (et, v1)) != NO_ERROR) return er; while ((op = eval_lex (&v2)) == LSHIFT || op == RSHIFT) { et = eval_lex (&v2); if (et == ERROR) return UNKNOWN_INPUT; if ((er = add_term (et, &v2)) != NO_ERROR) return er; switch (op) { case LSHIFT: *v1 = *v1 << v2; break; case RSHIFT: *v1 = *v1 >> v2; break; default: M4ERROR ((warning_status, 0, "INTERNAL ERROR: Bad shift operator in shift_term ()")); abort (); } } if (op == ERROR) return UNKNOWN_INPUT; eval_undo (); return NO_ERROR; }
static void variable_add_terms(Context *ctx, Variable *var) { float step; int i; char name[NAME_SIZE]; step = (var->max - var->min) / AUTOMATIC_TERMS; for (i = 0; i < AUTOMATIC_TERMS; i++) { snprintf(name, NAME_SIZE, "t%d", i); add_term(ctx, var, name, var->min + i * step, var->min + (i + 1.5) * step); } }
void nl_convert_rinf_t::convert(const pstring &contents) { tokenizer tok(*this, plib::putf8_reader(plib::pistringstream(contents))); auto lm = read_lib_map(s_lib_map); out("NETLIST_START(dummy)\n"); add_term("GND", "GND"); add_term("VCC", "VCC"); tokenizer::token_t token = tok.get_token(); while (true) { if (token.is_type(tokenizer::ENDOFFILE) || token.is(tok.m_tok_END)) { dump_nl(); // FIXME: Parameter out("NETLIST_END()\n"); return; } else if (token.is(tok.m_tok_HEA)) { /* seems to be start token - ignore */ token = tok.get_token(); } else if (token.is(tok.m_tok_APP)) { /* version string */ pstring app = tok.get_string(); out("// APP: {}\n", app); token = tok.get_token(); } else if (token.is(tok.m_tok_TIM)) { /* time */ out("// TIM:"); for (int i=0; i<6; i++) { long x = tok.get_number_long(); out(" {}", x); } out("\n"); token = tok.get_token(); } else if (token.is(tok.m_tok_TYP)) { pstring id(tok.get_identifier()); out("// TYP: {}\n", id); token = tok.get_token(); } else if (token.is(tok.m_tok_ADDC)) { std::unordered_map<pstring, pstring> attr; pstring id = tok.get_identifier(); pstring s1 = tok.get_string(); pstring s2 = tok.get_string(); token = tok.get_token(); while (token.is(tok.m_tok_ATTC)) { pstring tid = tok.get_identifier(); if (tid != id) { out("Error: found {} expected {} in {}\n", tid, id, token.str()); return; } pstring at = tok.get_string(); pstring val = tok.get_string(); attr[at] = val; token = tok.get_token(); } pstring sim = attr["Simulation"]; pstring val = attr["Value"]; pstring com = attr["Comment"]; if (val == "") val = com; if (sim == "CAP") { add_device("CAP", id, get_sp_val(val)); } else if (sim == "RESISTOR") { add_device("RES", id, get_sp_val(val)); } else { pstring lib = attr["Library Reference"]; auto f = lm.find(lib); if (f != lm.end()) add_device(f->second.dev, id); else add_device(lib, id); } } else if (token.is(tok.m_tok_NET)) { pstring dev = tok.get_identifier(); pstring pin = tok.get_identifier_or_number(); pstring net = tok.get_string(); add_term(net, dev + "." + pin); token = tok.get_token(); if (token.is(tok.m_tok_TER)) { token = tok.get_token(); while (token.is_type(plib::ptokenizer::IDENTIFIER)) { pin = tok.get_identifier_or_number(); add_term(net, token.str() + "." + pin); token = tok.get_token(); } } } #if 0 token = tok.get_token(); /* skip to semicolon */ do { token = tok.get_token(); } while (!token.is(tok.m_tok_SEMICOLON)); token = tok.get_token(); pstring sval = ""; if (token.is(tok.m_tok_VALUE)) { pstring vname = tok.get_string(); sval = tok.get_string(); tok.require_token(tok.m_tok_SEMICOLON); token = tok.get_token(); } switch (name.code_at(0)) { case 'Q': { add_device("QBJT", name, sval); } break; case 'R': { double val = get_sp_val(sval); add_device("RES", name, val); } break; case 'C': { double val = get_sp_val(sval); add_device("CAP", name, val); } break; case 'P': if (sval.ucase() == "HIGH") add_device("TTL_INPUT", name, 1); else if (sval.ucase() == "LOW") add_device("TTL_INPUT", name, 0); else add_device("ANALOG_INPUT", name, sval.as_double()); add_pin_alias(name, "1", "Q"); break; case 'D': /* Pin 1 = Anode, Pin 2 = Cathode */ add_device("DIODE", name, sval); add_pin_alias(name, "1", "A"); add_pin_alias(name, "2", "K"); break; case 'U': case 'X': { pstring tname = "TTL_" + sval + "_DIP"; add_device(tname, name); break; } default: tok.error("// IGNORED " + name); } } else if (token.is(tok.m_tok_SIGNAL))
void nl_convert_spice_t::process_line(const pstring &line) { if (line != "") { //printf("// %s\n", line.c_str()); std::vector<pstring> tt(plib::psplit(line, " ", true)); double val = 0.0; switch (tt[0].at(0)) { case ';': out("// {}\n", line.substr(1)); break; case '*': out("// {}\n", line.substr(1).c_str()); break; case '.': if (tt[0] == ".SUBCKT") { m_subckt = tt[1] + "_"; out("NETLIST_START({})\n", tt[1]); for (std::size_t i=2; i<tt.size(); i++) add_ext_alias(tt[i]); } else if (tt[0] == ".ENDS") { dump_nl(); out("NETLIST_END()\n"); m_subckt = ""; } else if (tt[0] == ".MODEL") { out("NET_MODEL(\"{} {}\")\n", m_subckt + tt[1], rem(tt,2)); } else out("// {}\n", line.c_str()); break; case 'Q': { /* check for fourth terminal ... should be numeric net * including "0" or start with "N" (ltspice) */ pstring model; pstring pins ="CBE"; bool err; auto nval = plib::pstonum_ne<long, true>(tt[4], err); plib::unused_var(nval); if ((!err || plib::startsWith(tt[4], "N")) && tt.size() > 5) model = tt[5]; else model = tt[4]; std::vector<pstring> m(plib::psplit(model,"{")); if (m.size() == 2) { if (m[1].length() != 4) plib::perrlogger("error with model desc {}\n", model); pins = plib::left(m[1], 3); } add_device("QBJT_EB", tt[0], m_subckt + m[0]); add_term(tt[1], tt[0] + "." + pins.at(0)); add_term(tt[2], tt[0] + "." + pins.at(1)); add_term(tt[3], tt[0] + "." + pins.at(2)); } break; case 'R': if (plib::startsWith(tt[0], "RV")) { val = get_sp_val(tt[4]); add_device("POT", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); add_term(tt[3], tt[0] + ".3"); } else { val = get_sp_val(tt[3]); add_device("RES", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); } break; case 'C': val = get_sp_val(tt[3]); add_device("CAP", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); break; case 'B': // arbitrary behavioural current source - needs manual work afterwords add_device("CS", tt[0], "/*" + rem(tt, 3) + "*/"); add_term(tt[1], tt[0] + ".P"); add_term(tt[2], tt[0] + ".N"); break; case 'E': add_device("VCVS", tt[0]); add_term(tt[1], tt[0] + ".OP"); add_term(tt[2], tt[0] + ".ON"); add_term(tt[3], tt[0] + ".IP"); add_term(tt[4], tt[0] + ".IN"); out("PARAM({}, {})\n", tt[0] + ".G", tt[5]); break; case 'V': // just simple Voltage sources .... if (tt[2] == "0") { val = get_sp_val(tt[3]); add_device("ANALOG_INPUT", tt[0], val); add_term(tt[1], tt[0] + ".Q"); //add_term(tt[2], tt[0] + ".2"); } else plib::perrlogger("Voltage Source {} not connected to GND\n", tt[0]); break; #if 0 // This is wrong ... Need to use something else for inputs! case 'I': // Input pin special notation { val = get_sp_val(tt[2]); add_device("ANALOG_INPUT", tt[0], val); add_term(tt[1], tt[0] + ".Q"); } break; #else case 'I': { val = get_sp_val(tt[3]); add_device("CS", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); } break; #endif case 'D': add_device("DIODE", tt[0], tt[3]); /* FIXME ==> does Kicad use different notation from LTSPICE */ add_term(tt[1], tt[0] + ".K"); add_term(tt[2], tt[0] + ".A"); break; case 'U': case 'X': { // FIXME: specific code for KICAD exports // last element is component type // FIXME: Parameter pstring xname = plib::replace_all(tt[0], pstring("."), pstring("_")); pstring tname = "TTL_" + tt[tt.size()-1] + "_DIP"; add_device(tname, xname); for (std::size_t i=1; i < tt.size() - 1; i++) { pstring term = plib::pfmt("{1}.{2}")(xname)(i); add_term(tt[i], term); } break; } default: out("// IGNORED {}: {}\n", tt[0].c_str(), line.c_str()); } } }
//loads the specfied mission from the mission list. build_mission_list() //must have been called. If build_mission_list() returns 0, this function //does not need to be called. Returns true if mission loaded ok, else false. int load_mission(int mission_num) { Current_mission_num = mission_num; mprintf(( 0, "Loading mission %d\n", mission_num )); #ifndef DEST_SAT if (mission_num == 0) { //built-in mission int i; #ifdef ROCKWELL_CODE Last_level = 7; Last_secret_level = 0; //build level names for (i=0;i<Last_level;i++) sprintf(Level_names[i], "LEVEL%02d.RDL", i+1); #else Last_level = BIM_LAST_LEVEL; Last_secret_level = BIM_LAST_SECRET_LEVEL; //build level names for (i=0;i<Last_level;i++) sprintf(Level_names[i], "LEVEL%02d.RDL", i+1); for (i=0;i<-Last_secret_level;i++) sprintf(Secret_level_names[i], "LEVELS%1d.RDL", i+1); Secret_level_table[0] = 10; Secret_level_table[1] = 21; Secret_level_table[2] = 24; #endif strcpy(Briefing_text_filename,BIM_BRIEFING_FILE); strcpy(Ending_text_filename,BIM_ENDING_FILE); cfile_use_alternate_hogfile(NULL); //disable alternate } else #endif { //NOTE LINK TO ABOVE IF!!!!! //read mission from file FILE *mfile; char buf[80], tmp[80], *v; strcpy(buf,Mission_list[mission_num].filename); strcat(buf,".MSN"); strcpy(tmp,Mission_list[mission_num].filename); strcat(tmp,".HOG"); cfile_use_alternate_hogfile(tmp); mfile = fopen(buf,"rt"); #ifdef USE_CD if (mfile == NULL) { if ( strlen(destsat_cdpath) ) { char temp_spec[128]; strcpy( temp_spec, destsat_cdpath ); strcat( temp_spec, buf ); mfile = fopen( temp_spec, "rt" ); } } #endif if (mfile == NULL) { Current_mission_num = -1; return 0; //error! } //init vars Last_level = 0; Last_secret_level = 0; Briefing_text_filename[0] = 0; Ending_text_filename[0] = 0; #ifdef DEST_SAT if (!stricmp(Mission_list[mission_num].filename, "DESTSAT")) { // Destination Saturn. strcpy(Briefing_text_filename,"briefsat.tex"); strcpy(Ending_text_filename,"endsat.tex"); } #endif while (mfgets(buf,80,mfile)) { if (istok(buf,"name")) continue; //already have name, go to next line else if (istok(buf,"type")) continue; //already have name, go to next line else if (istok(buf,"hog")) { char *bufp = buf; while (*(bufp++) != '=') ; if (*bufp == ' ') while (*(++bufp) == ' ') ; cfile_use_alternate_hogfile(bufp); mprintf((0, "Hog file override = [%s]\n", bufp)); } else if (istok(buf,"briefing")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < 13) strcpy(Briefing_text_filename,v); } } else if (istok(buf,"ending")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < 13) strcpy(Ending_text_filename,v); } } else if (istok(buf,"num_levels")) { if ((v=get_value(buf))!=NULL) { int n_levels,i; n_levels = atoi(v); for (i=0;i<n_levels && mfgets(buf,80,mfile);i++) { add_term(buf); if (strlen(buf) <= 12) { strcpy(Level_names[i],buf); Last_level++; } else break; } } } else if (istok(buf,"num_secrets")) { if ((v=get_value(buf))!=NULL) { int n_secret_levels,i; n_secret_levels = atoi(v); for (i=0;i<n_secret_levels && mfgets(buf,80,mfile);i++) { char *t; if ((t=strchr(buf,','))!=NULL) *t++=0; else break; add_term(buf); if (strlen(buf) <= 12) { strcpy(Secret_level_names[i],buf); Secret_level_table[i] = atoi(t); if (Secret_level_table[i]<1 || Secret_level_table[i]>Last_level) break; Last_secret_level--; } else break; } } } } fclose(mfile); if (Last_level <= 0) { Current_mission_num = -1; //no valid mission loaded return 0; } } Current_mission_filename = Mission_list[Current_mission_num].filename; Current_mission_longname = Mission_list[Current_mission_num].mission_name; return 1; }
void add_terminal(const char *run) { add_term(SDL_GetVideoSurface()->w/26*3,SDL_GetVideoSurface()->h/26,run); }
ATTR_COLD void matrix_solver_t::setup(analog_net_t::list_t &nets) { NL_VERBOSE_OUT(("New solver setup\n")); m_nets.clear(); for (std::size_t k = 0; k < nets.size(); k++) { m_nets.add(nets[k]); } for (std::size_t k = 0; k < nets.size(); k++) { NL_VERBOSE_OUT(("setting up net\n")); analog_net_t *net = nets[k]; net->m_solver = this; for (std::size_t i = 0; i < net->m_core_terms.size(); i++) { core_terminal_t *p = net->m_core_terms[i]; NL_VERBOSE_OUT(("%s %s %d\n", p->name().cstr(), net->name().cstr(), (int) net->isRailNet())); switch (p->type()) { case terminal_t::TERMINAL: switch (p->device().family()) { case device_t::CAPACITOR: if (!m_step_devices.contains(&p->device())) m_step_devices.add(&p->device()); break; case device_t::BJT_EB: case device_t::DIODE: case device_t::LVCCS: case device_t::BJT_SWITCH: NL_VERBOSE_OUT(("found BJT/Diode/LVCCS\n")); if (!m_dynamic_devices.contains(&p->device())) m_dynamic_devices.add(&p->device()); break; default: break; } { terminal_t *pterm = dynamic_cast<terminal_t *>(p); add_term(k, pterm); } NL_VERBOSE_OUT(("Added terminal\n")); break; case terminal_t::INPUT: { analog_output_t *net_proxy_output = NULL; for (std::size_t i = 0; i < m_inps.size(); i++) if (m_inps[i]->m_proxied_net == &p->net().as_analog()) { net_proxy_output = m_inps[i]; break; } if (net_proxy_output == NULL) { net_proxy_output = palloc(analog_output_t); net_proxy_output->init_object(*this, this->name() + "." + pstring::sprintf("m%" SIZETFMT, SIZET_PRINTF(m_inps.size()))); m_inps.add(net_proxy_output); net_proxy_output->m_proxied_net = &p->net().as_analog(); } net_proxy_output->net().register_con(*p); // FIXME: repeated net_proxy_output->net().rebuild_list(); NL_VERBOSE_OUT(("Added input\n")); } break; default: netlist().error("unhandled element found\n"); break; } } NL_VERBOSE_OUT(("added net with %" SIZETFMT " populated connections\n", net->m_core_terms.size())); } }
void nl_convert_spice_t::process_line(const pstring &line) { if (line != "") { pstring_vector_t tt(line, " ", true); double val = 0.0; switch (tt[0].code_at(0)) { case ';': out("// {}\n", line.substr(1).cstr()); break; case '*': out("// {}\n", line.substr(1).cstr()); break; case '.': if (tt[0].equals(".SUBCKT")) { out("NETLIST_START({})\n", tt[1].cstr()); for (std::size_t i=2; i<tt.size(); i++) add_ext_alias(tt[i]); } else if (tt[0].equals(".ENDS")) { dump_nl(); out("NETLIST_END()\n"); } else out("// {}\n", line.cstr()); break; case 'Q': { bool cerr = false; /* check for fourth terminal ... should be numeric net * including "0" or start with "N" (ltspice) */ ATTR_UNUSED int nval =tt[4].as_long(&cerr); pstring model; pstring pins ="CBE"; if ((!cerr || tt[4].startsWith("N")) && tt.size() > 5) model = tt[5]; else model = tt[4]; pstring_vector_t m(model,"{"); if (m.size() == 2) { if (m[1].len() != 4) fprintf(stderr, "error with model desc %s\n", model.cstr()); pins = m[1].left(3); } add_device("QBJT_EB", tt[0], m[0]); add_term(tt[1], tt[0] + "." + pins.code_at(0)); add_term(tt[2], tt[0] + "." + pins.code_at(1)); add_term(tt[3], tt[0] + "." + pins.code_at(2)); } break; case 'R': if (tt[0].startsWith("RV")) { val = get_sp_val(tt[4]); add_device("POT", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); add_term(tt[3], tt[0] + ".3"); } else { val = get_sp_val(tt[3]); add_device("RES", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); } break; case 'C': val = get_sp_val(tt[3]); add_device("CAP", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); break; case 'V': // just simple Voltage sources .... if (tt[2].equals("0")) { val = get_sp_val(tt[3]); add_device("ANALOG_INPUT", tt[0], val); add_term(tt[1], tt[0] + ".Q"); //add_term(tt[2], tt[0] + ".2"); } else fprintf(stderr, "Voltage Source %s not connected to GND\n", tt[0].cstr()); break; case 'I': // Input pin special notation { val = get_sp_val(tt[2]); add_device("ANALOG_INPUT", tt[0], val); add_term(tt[1], tt[0] + ".Q"); } break; case 'D': add_device("DIODE", tt[0], tt[3]); /* FIXME ==> does Kicad use different notation from LTSPICE */ add_term(tt[1], tt[0] + ".K"); add_term(tt[2], tt[0] + ".A"); break; case 'U': case 'X': { // FIXME: specific code for KICAD exports // last element is component type // FIXME: Parameter pstring xname = tt[0].replace(".", "_"); pstring tname = "TTL_" + tt[tt.size()-1] + "_DIP"; add_device(tname, xname); for (std::size_t i=1; i < tt.size() - 1; i++) { pstring term = pfmt("{1}.{2}")(xname)(i); add_term(tt[i], term); } break; } default: out("// IGNORED {}: {}\n", tt[0].cstr(), line.cstr()); } } }
void int_terms(const char *prefix, int64_t v, term_list_t &terms) { char buf[100]; sprintf(buf, "%lld", (long long int)v); add_term(prefix, buf, terms); }
face(float x, float y, int c, int r) { add_term(c,r,"bash"); obj::t.x=x; obj::t.y=y; }
ATTR_COLD void matrix_solver_t::setup_base(analog_net_t::list_t &nets) { log().debug("New solver setup\n"); m_nets.clear(); m_terms.clear(); for (auto & net : nets) { m_nets.push_back(net); m_terms.push_back(palloc(terms_t)); m_rails_temp.push_back(palloc(terms_t)); } for (std::size_t k = 0; k < nets.size(); k++) { log().debug("setting up net\n"); analog_net_t *net = nets[k]; net->m_solver = this; for (core_terminal_t *p : net->m_core_terms) { log().debug("{1} {2} {3}\n", p->name(), net->name(), (int) net->isRailNet()); switch (p->type()) { case terminal_t::TERMINAL: switch (p->device().family()) { case device_t::CAPACITOR: if (!m_step_devices.contains(&p->device())) m_step_devices.push_back(&p->device()); break; case device_t::BJT_EB: case device_t::DIODE: case device_t::LVCCS: case device_t::BJT_SWITCH: log().debug("found BJT/Diode/LVCCS\n"); if (!m_dynamic_devices.contains(&p->device())) m_dynamic_devices.push_back(&p->device()); break; default: break; } { terminal_t *pterm = dynamic_cast<terminal_t *>(p); add_term(k, pterm); } log().debug("Added terminal\n"); break; case terminal_t::INPUT: { analog_output_t *net_proxy_output = nullptr; for (auto & input : m_inps) if (input->m_proxied_net == &p->net().as_analog()) { net_proxy_output = input; break; } if (net_proxy_output == nullptr) { //net_proxy_output = palloc(analog_output_t(*this, // this->name() + "." + pfmt("m{1}")(m_inps.size()))); net_proxy_output = palloc(analog_output_t); net_proxy_output->init_object(*this, this->name() + "." + pfmt("m{1}")(m_inps.size())); m_inps.push_back(net_proxy_output); net_proxy_output->m_proxied_net = &p->net().as_analog(); } net_proxy_output->net().register_con(*p); // FIXME: repeated net_proxy_output->net().rebuild_list(); log().debug("Added input\n"); } break; default: log().fatal("unhandled element found\n"); break; } } log().debug("added net with {1} populated connections\n", net->m_core_terms.size()); } /* now setup the matrix */ setup_matrix(); }
//loads the specfied mission from the mission list. //build_mission_list() must have been called. //Returns true if mission loaded ok, else false. int load_mission(mle *mission) { PHYSFS_file *mfile; char buf[PATH_MAX], *v; if (Current_mission) free_mission(); Current_mission = d_malloc(sizeof(Mission)); if (!Current_mission) return 0; *(mle *) Current_mission = *mission; Current_mission->path = d_strdup(mission->path); Current_mission->filename = Current_mission->path + (mission->filename - mission->path); Current_mission->n_secret_levels = 0; //init vars Last_level = 0; Last_secret_level = 0; memset(&Briefing_text_filename, '\0', sizeof(Briefing_text_filename)); memset(&Ending_text_filename, '\0', sizeof(Ending_text_filename)); Secret_level_table = NULL; Level_names = NULL; Secret_level_names = NULL; // for Descent 1 missions, load descent.hog if (!PHYSFSX_contfile_init("descent.hog", 1)) Error("descent.hog not available!\n"); if (!d_stricmp(Current_mission_filename, D1_MISSION_FILENAME)) return load_mission_d1(); //read mission from file switch (mission->location) { case ML_MISSIONDIR: strcpy(buf,MISSION_DIR); break; default: Int3(); //fall through case ML_CURDIR: strcpy(buf,""); break; } strcat(buf, mission->path); strcat(buf,".msn"); PHYSFSEXT_locateCorrectCase(buf); mfile = PHYSFSX_openReadBuffered(buf); if (mfile == NULL) { free_mission(); return 0; //error! } //for non-builtin missions, load HOG strcpy(buf+strlen(buf)-4,".hog"); //change extension PHYSFSEXT_locateCorrectCase(buf); if (PHYSFSX_exists(buf,1)) PHYSFSX_contfile_init(buf, 0); snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.tex",Current_mission_filename); if (!PHYSFSX_exists(Briefing_text_filename,1)) snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.txb",Current_mission_filename); snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.tex",Current_mission_filename); if (!PHYSFSX_exists(Ending_text_filename,1)) snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.txb",Current_mission_filename); while (PHYSFSX_fgets(buf,sizeof(buf),mfile)) { if (istok(buf,"type")) continue; //already have name, go to next line else if (istok(buf,"briefing")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < FILENAME_LEN && strlen(v) > 0) { char *tmp, *ptr; MALLOC(tmp, char, FILENAME_LEN); snprintf(tmp, FILENAME_LEN, "%s", v); if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. *ptr = '\0'; strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... else // ... otherwise ... { if ((ptr = strrchr(tmp, '.'))) *ptr = '\0'; strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... } d_free(tmp); } } } else if (istok(buf,"ending")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < FILENAME_LEN && strlen(v) > 0) { char *tmp, *ptr; MALLOC(tmp, char, FILENAME_LEN); snprintf(tmp, FILENAME_LEN, "%s", v); if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. *ptr = '\0'; strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... else // ... otherwise ... { if ((ptr = strrchr(tmp, '.'))) *ptr = '\0'; strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Ending_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... } d_free(tmp); } } } else if (istok(buf,"num_levels")) { if ((v=get_value(buf))!=NULL) { int n_levels,i; n_levels = atoi(v); Assert(n_levels <= MAX_LEVELS_PER_MISSION); n_levels = min(n_levels, MAX_LEVELS_PER_MISSION); MALLOC(Level_names, d_fname, n_levels); if (!Level_names) { free_mission(); return 0; } for (i=0;i<n_levels;i++) { PHYSFSX_fgets(buf,sizeof(buf),mfile); add_term(buf); if (strlen(buf) <= 12) { strcpy(Level_names[i],buf); Last_level++; } else break; } } } else if (istok(buf,"num_secrets")) { if ((v=get_value(buf))!=NULL) { int i; N_secret_levels = atoi(v); Assert(N_secret_levels <= MAX_SECRET_LEVELS_PER_MISSION); N_secret_levels = min(N_secret_levels, MAX_SECRET_LEVELS_PER_MISSION); MALLOC(Secret_level_names, d_fname, N_secret_levels); if (!Secret_level_names) { free_mission(); return 0; } MALLOC(Secret_level_table, ubyte, N_secret_levels); if (!Secret_level_table) { free_mission(); return 0; } for (i=0;i<N_secret_levels;i++) { char *t; PHYSFSX_fgets(buf,sizeof(buf),mfile); if ((t=strchr(buf,','))!=NULL) *t++=0; else break; add_term(buf); if (strlen(buf) <= 12) { strcpy(Secret_level_names[i],buf); Secret_level_table[i] = atoi(t); if (Secret_level_table[i]<1 || Secret_level_table[i]>Last_level) break; Last_secret_level--; } else break; } } } } PHYSFS_close(mfile); if (Last_level <= 0) { free_mission(); //no valid mission loaded return 0; } return 1; }
//loads the specfied mission from the mission list. //build_mission_list() must have been called. //Returns true if mission loaded ok, else false. static int load_mission(mle *mission) { PHYSFS_file *mfile; char buf[PATH_MAX], *v; if (Current_mission) free_mission(); MALLOC(Current_mission, Mission, 1); if (!Current_mission) return 0; *(mle *) Current_mission = *mission; Current_mission->path = d_strdup(mission->path); Current_mission->filename = Current_mission->path + (mission->filename - mission->path); Current_mission->n_secret_levels = 0; Current_mission->enhanced = 0; //init vars Last_level = 0; Last_secret_level = 0; memset(&Briefing_text_filename, '\0', sizeof(Briefing_text_filename)); memset(&Ending_text_filename, '\0', sizeof(Ending_text_filename)); // for Descent 1 missions, load descent.hog if (EMULATING_D1) { if (!PHYSFSX_contfile_init("descent.hog", 1)) Warning("descent.hog not available, this mission may be missing some files required for briefings and exit sequence\n"); if (!stricmp(Current_mission_filename, D1_MISSION_FILENAME)) return load_mission_d1(); } if (PLAYING_BUILTIN_MISSION) { switch (Current_mission->builtin_hogsize) { case SHAREWARE_MISSION_HOGSIZE: case MAC_SHARE_MISSION_HOGSIZE: strcpy(Briefing_text_filename,BIMD2_BRIEFING_FILE_SHARE); strcpy(Ending_text_filename,BIMD2_ENDING_FILE_SHARE); return load_mission_shareware(); break; case OEM_MISSION_HOGSIZE: strcpy(Briefing_text_filename,BIMD2_BRIEFING_FILE_OEM); strcpy(Ending_text_filename,BIMD2_ENDING_FILE_OEM); return load_mission_oem(); break; default: Int3(); // fall through case FULL_MISSION_HOGSIZE: case FULL_10_MISSION_HOGSIZE: case MAC_FULL_MISSION_HOGSIZE: strcpy(Briefing_text_filename,BIMD2_BRIEFING_FILE); // continue on... (use d2.mn2 from hogfile) break; } } //read mission from file switch (mission->location) { case ML_MISSIONDIR: strcpy(buf,MISSION_DIR); break; default: Int3(); //fall through case ML_CURDIR: strcpy(buf,""); break; } strcat(buf, mission->path); if (mission->descent_version == 2) strcat(buf,".mn2"); else strcat(buf,".msn"); PHYSFSEXT_locateCorrectCase(buf); mfile = PHYSFSX_openReadBuffered(buf); if (mfile == NULL) { free_mission(); return 0; //error! } //for non-builtin missions, load HOG if (!PLAYING_BUILTIN_MISSION) { strcpy(buf+strlen(buf)-4,".hog"); //change extension PHYSFSEXT_locateCorrectCase(buf); if (PHYSFSX_exists(buf,1)) PHYSFSX_contfile_init(buf, 0); snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.tex",Current_mission_filename); if (!PHYSFSX_exists(Briefing_text_filename,1)) snprintf(Briefing_text_filename, sizeof(Briefing_text_filename), "%s.txb",Current_mission_filename); snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.tex",Current_mission_filename); if (!PHYSFSX_exists(Ending_text_filename,1)) snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.txb",Current_mission_filename); } while (PHYSFSX_fgets(buf,sizeof(buf),mfile)) { if (istok(buf,"name") && !Current_mission->enhanced) { Current_mission->enhanced = 0; continue; //already have name, go to next line } if (istok(buf,"xname") && !Current_mission->enhanced) { Current_mission->enhanced = 1; continue; //already have name, go to next line } if (istok(buf,"zname") && !Current_mission->enhanced) { Current_mission->enhanced = 2; continue; //already have name, go to next line } else if (istok(buf,"type")) continue; //already have name, go to next line else if (istok(buf,"briefing")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < FILENAME_LEN && strlen(v) > 0) { char *tmp, *ptr; MALLOC(tmp, char, FILENAME_LEN); snprintf(tmp, FILENAME_LEN, "%s", v); if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. *ptr = '\0'; strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... else // ... otherwise ... { if ((ptr = strrchr(tmp, '.'))) *ptr = '\0'; strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... } d_free(tmp); } } } else if (istok(buf,"ending")) { if ((v = get_value(buf)) != NULL) { add_term(v); if (strlen(v) < FILENAME_LEN && strlen(v) > 0) { char *tmp, *ptr; MALLOC(tmp, char, FILENAME_LEN); snprintf(tmp, FILENAME_LEN, "%s", v); if ((ptr = strrchr(tmp, '.'))) // if there's a filename extension, kill it. No one knows it's the right one. *ptr = '\0'; strncat(tmp, ".tex", sizeof(char)*FILENAME_LEN); // apply tex-extenstion if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Briefing_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... else // ... otherwise ... { if ((ptr = strrchr(tmp, '.'))) *ptr = '\0'; strncat(tmp, ".txb", sizeof(char)*FILENAME_LEN); // apply txb extension if (PHYSFSX_exists(tmp,1)) // check if this file exists ... snprintf(Ending_text_filename, FILENAME_LEN, "%s", tmp); // ... and apply ... } d_free(tmp); } } } else if (istok(buf,"num_levels")) { if ((v=get_value(buf))!=NULL) { int n_levels,i; n_levels = atoi(v); for (i=0;i<n_levels;i++) { PHYSFSX_fgets(buf,sizeof(buf),mfile); add_term(buf); if (strlen(buf) <= 12) { strcpy(Level_names[i],buf); Last_level++; } else break; } } } else if (istok(buf,"num_secrets")) { if ((v=get_value(buf))!=NULL) { int i; N_secret_levels = atoi(v); Assert(N_secret_levels <= MAX_SECRET_LEVELS_PER_MISSION); for (i=0;i<N_secret_levels;i++) { char *t; PHYSFSX_fgets(buf,sizeof(buf),mfile); if ((t=strchr(buf,','))!=NULL) *t++=0; else break; add_term(buf); if (strlen(buf) <= 12) { strcpy(Secret_level_names[i],buf); Secret_level_table[i] = atoi(t); if (Secret_level_table[i]<1 || Secret_level_table[i]>Last_level) break; Last_secret_level--; } else break; } } } } PHYSFS_close(mfile); if (Last_level <= 0) { free_mission(); //no valid mission loaded return 0; } // re-read default HAM file, in case this mission brings it's own version of it free_polygon_models(); read_hamfile(); if (Current_mission->enhanced) { char t[50]; sprintf(t,"%s.ham",Current_mission_filename); bm_read_extra_robots(t, Current_mission->enhanced); init_extra_robot_movie(Current_mission_filename); } return 1; }
void double_terms(const char *prefix, double v, term_list_t &terms) { char buf[100]; sprintf(buf, "%f", v); add_term(prefix, buf, terms); }
void unusual_model::setup2(INT q, const BYTE *poly_q, const BYTE *poly_Q, INT f_sum_of_squares, INT verbose_level) { INT f_v = (verbose_level >= 1); INT f_vv = (verbose_level >= 2); INT f_vvv = (verbose_level >= 2); INT Q, i, j, b, p, h; if (f_v) { cout << "unusual_model::setup q=" << q << " f_sum_of_squares=" << f_sum_of_squares << endl; } unusual_model::q = q; Q = qq = q * q; nb_terms = 0; //const BYTE *override_poly_Q = NULL; //const BYTE *override_poly_q = NULL; is_prime_power(q, p, h); #if 0 if (h > 1) { override_poly_Q = override_polynomial_extension_field(q); override_poly_q = override_polynomial_subfield(q); F.init_override_polynomial(Q, override_poly_Q, verbose_level - 2); cout << "field of order " << Q << " initialized" << endl; f.init_override_polynomial(q, override_poly_q, verbose_level - 2); } else { if (f_vv) { cout << "initializing large field" << endl; } F.init(qq, verbose_level); if (f_vv) { cout << "initializing small field" << endl; } f.init(q, verbose_level); if (f.e > 1) { F.init(qq, 1); f.init(q, 3); cout << "need to choose the generator polynomial for the field" << endl; F.compute_subfields(verbose_level); exit(1); } } #endif if (f_vv) { cout << "initializing large field" << endl; } F.init_override_polynomial(Q, poly_Q, verbose_level - 2); if (f_vv) { cout << "field of order " << Q << " initialized" << endl; } if (f_vv) { cout << "initializing small field" << endl; } f.init_override_polynomial(q, poly_q, verbose_level - 2); if (f_vv) { cout << "field of order " << q << " initialized" << endl; } #if 0 if (q == 9) { BYTE *override_poly_Q = "110"; // X^{4} + X^{3} + 2 BYTE *override_poly_q = "17"; // X^2 - X - 1 = X^2 +2X + 2 = 2 + 2*3 + 9 = 17 //finite_field::init_override_polynomial() GF(81) = GF(3^4), polynomial = X^{4} + X^{3} + 2 = 110 //subfields of F_{81}: //subfield 3^2 : subgroup_index = 10 //0 : 0 : 1 : 1 //1 : 10 : 46 : X^{3} + 2X^{2} + 1 //2 : 20 : 47 : X^{3} + 2X^{2} + 2 F.init_override_polynomial(Q, override_poly_Q, verbose_level - 2); cout << "field of order " << Q << " initialized" << endl; f.init_override_polynomial(q, override_poly_q, verbose_level - 2); } else if (q == 25) { BYTE *override_poly_Q = "767"; // X^{4} + X^{3} + 3X + 2 BYTE *override_poly_q = "47"; // X^2 - X - 3 = X^2 +4X + 2=25+20+2=47 //subfields of F_{625}: //subfield 5^2 : subgroup_index = 26 //0 : 0 : 1 : 1 //1 : 26 : 110 : 4X^{2} + 2X //2 : 52 : 113 : 4X^{2} + 2X + 3 F.init_override_polynomial(Q, override_poly_Q, verbose_level - 2); cout << "field of order " << Q << " initialized" << endl; f.init_override_polynomial(q, override_poly_q, verbose_level - 2); } else if (q == 27) { BYTE *override_poly_Q = "974"; // X^{6} + X^{5} + 2 BYTE *override_poly_q = "34"; // X^3 - X + 1 = X^3 +2X + 1 = 27+6+1=34 //subfields of F_{729}: //subfield 3^2 : subgroup_index = 91 //0 : 0 : 1 : 1 //1 : 91 : 599 : 2X^{5} + X^{4} + X^{3} + X + 2 //2 : 182 : 597 : 2X^{5} + X^{4} + X^{3} + X //subfield 3^3 : subgroup_index = 28 //0 : 0 : 1 : 1 //1 : 28 : 158 : X^{4} + 2X^{3} + 2X^{2} + X + 2 //2 : 56 : 498 : 2X^{5} + X^{2} + X //3 : 84 : 157 : X^{4} + 2X^{3} + 2X^{2} + X + 1 F.init_override_polynomial(Q, override_poly_Q, verbose_level - 2); cout << "field of order " << Q << " initialized" << endl; f.init_override_polynomial(q, override_poly_q, verbose_level - 2); } else if (q == 49) { BYTE *override_poly_Q = "2754"; // X^{4} + X^{3} + X + 3 BYTE *override_poly_q = "94"; // X^2-X+3 = X^2+6X+3 = 49+6*7+3=94 //subfields of F_{2401}: //subfield 7^2 : subgroup_index = 50 //0 : 0 : 1 : 1 //1 : 50 : 552 : X^{3} + 4X^{2} + X + 6 //2 : 100 : 549 : X^{3} + 4X^{2} + X + 3 F.init_override_polynomial(Q, override_poly_Q, verbose_level - 2); cout << "field of order " << Q << " initialized" << endl; f.init_override_polynomial(q, override_poly_q, verbose_level - 2); } else if (q == 81) { BYTE *override_poly_Q = "6590"; // X^{8} + X^{3} + 2 BYTE *override_poly_q = "89"; // X^4-X-1=X^4+2X+2=81+2*3+2=89 //subfields of F_{6561}: //subfield 3^4 : subgroup_index = 82 //0 : 0 : 1 : 1 //1 : 82 : 5413 : 2X^{7} + X^{6} + X^{5} + 2X^{3} + X^{2} + X + 1 //2 : 164 : 1027 : X^{6} + X^{5} + 2X^{3} + 1 //3 : 246 : 3976 : X^{7} + 2X^{6} + X^{5} + X^{4} + 2X + 1 //4 : 328 : 5414 : 2X^{7} + X^{6} + X^{5} + 2X^{3} + X^{2} + X + 2 F.init_override_polynomial(Q, override_poly_Q, verbose_level - 2); cout << "field of order " << Q << " initialized" << endl; f.init_override_polynomial(q, override_poly_q, verbose_level - 2); } else if (q == 121) { BYTE *override_poly_Q = "15985"; // X^{4} + X^{3} + X + 2 BYTE *override_poly_q = "200"; // X^2-4X+2=X^2+7X+2=11^2+7*11+2=200 //subfields of F_{14641}: //subfield 11^2 : subgroup_index = 122 //0 : 0 : 1 : 1 //1 : 122 : 4352 : 3X^{3} + 2X^{2} + 10X + 7 //2 : 244 : 2380 : X^{3} + 8X^{2} + 7X + 4 F.init_override_polynomial(Q, override_poly_Q, verbose_level - 2); cout << "field of order " << Q << " initialized" << endl; f.init_override_polynomial(q, override_poly_q, verbose_level - 2); } else { } #endif alpha = f.p; if (f_vv) { cout << "primitive element alpha=" << alpha << endl; } if (f_vv) { cout << "unusual_model::setup calling subfield_embedding_2dimensional" << endl; } F.subfield_embedding_2dimensional(f, components, embedding, pair_embedding, verbose_level - 4); if (f_vvv) { cout << "unusual_model::setup subfield_embedding_2dimensional finished" << endl; F.print_embedding(f, components, embedding, pair_embedding); } T_alpha = F.retract(f, 2, F.T2(alpha), verbose_level - 2); N_alpha = F.retract(f, 2, F.N2(alpha), verbose_level - 2); if (f_vv) { cout << "T_alpha = " << T_alpha << endl; cout << "N_alpha = " << N_alpha << endl; } form_i = NEW_INT(4 * 4); form_j = NEW_INT(4 * 4); form_coeff = NEW_INT(4 * 4); Gram = NEW_INT(4 * 4); for (i = 0; i < 4 * 4; i++) Gram[i] = 0; if (f_sum_of_squares) { add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 0, 0, 1); add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 1, 1, 1); add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 2, 2, 1); add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 3, 3, 1); } else { add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 0, 0, 1); add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 0, 1, T_alpha); add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 1, 1, N_alpha); add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 2, 2, 1); add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 2, 3, T_alpha); add_term(4, F, nb_terms, form_i, form_j, form_coeff, Gram, 3, 3, N_alpha); } if (f_vv) { cout << "Gram matrix:" << endl; print_integer_matrix_width(cout, Gram, 4, 4, 4, 2); cout << "quadratic form:" << endl; print_quadratic_form_list_coded(nb_terms, form_i, form_j, form_coeff); } if (f_vv) { cout << "finding hyperbolic pair" << endl; } f.find_hyperbolic_pair(4, nb_terms, form_i, form_j, form_coeff, Gram, basis, basis + 4, 0 /*verbose_level - 3*/); f.perp(4, 2, basis, Gram); if (f_vv) { cout << "basis:" << endl; print_integer_matrix_width(cout, basis, 4, 4, 4, 2); } for (i = 0; i < 2 * 4; i++) { hyperbolic_basis[i] = basis[i]; } if (f_vvv) { for (i = 0; i < 4; i++) { b = f.evaluate_quadratic_form(4, nb_terms, form_i, form_j, form_coeff, basis + i * 4); cout << "i=" << i << " form value " << b << endl; } } f.restrict_quadratic_form_list_coding(4 - 2, 4, basis + 2 * 4, nb_terms, form_i, form_j, form_coeff, r_nb_terms, r_form_i, r_form_j, r_form_coeff, verbose_level - 2); if (f_vv) { cout << "restricted quadratic form:" << endl; print_quadratic_form_list_coded(r_nb_terms, r_form_i, r_form_j, r_form_coeff); } r_Gram = NEW_INT(2 * 2); make_Gram_matrix_from_list_coded_quadratic_form(2, f, r_nb_terms, r_form_i, r_form_j, r_form_coeff, r_Gram); if (f_vv) { cout << "restricted Gram matrix:" << endl; print_integer_matrix_width(cout, r_Gram, 2, 2, 2, 2); } f.find_hyperbolic_pair(2, r_nb_terms, r_form_i, r_form_j, r_form_coeff, r_Gram, basis_subspace, basis_subspace + 2, verbose_level - 2); if (f_vv) { cout << "basis_subspace:" << endl; print_integer_matrix_width(cout, basis_subspace, 2, 2, 2, 2); } f.mult_matrix(basis_subspace, basis + 8, hyperbolic_basis + 8, 2, 2, 4); if (f_vv) { cout << "hyperbolic basis:" << endl; print_integer_matrix_width(cout, hyperbolic_basis, 4, 4, 4, 2); for (i = 0; i < 4; i++) { b = f.evaluate_quadratic_form(4, nb_terms, form_i, form_j, form_coeff, hyperbolic_basis + i * 4); cout << "i=" << i << " quadratic form value " << b << endl; } } M = NEW_INT(4 * 4); for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { M[i * 4 + j] = f.evaluate_bilinear_form(4, hyperbolic_basis + i * 4, hyperbolic_basis + j * 4, Gram); } } if (f_vvv) { cout << "bilinear form on the hyperbolic basis:" << endl; print_integer_matrix_width(cout, M, 4, 4, 4, 2); } f.restrict_quadratic_form_list_coding(4, 4, hyperbolic_basis, nb_terms, form_i, form_j, form_coeff, rr_nb_terms, rr_form_i, rr_form_j, rr_form_coeff, verbose_level - 2); if (f_vv) { cout << "restricted quadratic form:" << endl; print_quadratic_form_list_coded(rr_nb_terms, rr_form_i, rr_form_j, rr_form_coeff); } f.matrix_inverse(hyperbolic_basis, hyperbolic_basis_inverse, 4, verbose_level - 2); if (f_vv) { cout << "inverse hyperbolic basis:" << endl; print_integer_matrix_width(cout, hyperbolic_basis_inverse, 4, 4, 4, 2); } }
//FIXME: should accept a stream as well void nl_convert_eagle_t::convert(const pstring &contents) { pistringstream istrm(contents); eagle_tokenizer tok(*this, istrm); out("NETLIST_START(dummy)\n"); add_term("GND", "GND"); add_term("VCC", "VCC"); eagle_tokenizer::token_t token = tok.get_token(); while (true) { if (token.is_type(eagle_tokenizer::ENDOFFILE)) { dump_nl(); // FIXME: Parameter out("NETLIST_END()\n"); return; } else if (token.is(tok.m_tok_SEMICOLON)) { /* ignore empty statements */ token = tok.get_token(); } else if (token.is(tok.m_tok_ADD)) { pstring name = tok.get_string(); /* skip to semicolon */ do { token = tok.get_token(); } while (!token.is(tok.m_tok_SEMICOLON)); token = tok.get_token(); pstring sval = ""; if (token.is(tok.m_tok_VALUE)) { pstring vname = tok.get_string(); sval = tok.get_string(); tok.require_token(tok.m_tok_SEMICOLON); token = tok.get_token(); } switch (name.code_at(0)) { case 'Q': { add_device("QBJT", name, sval); } break; case 'R': { double val = get_sp_val(sval); add_device("RES", name, val); } break; case 'C': { double val = get_sp_val(sval); add_device("CAP", name, val); } break; case 'P': if (sval.ucase() == "HIGH") add_device("TTL_INPUT", name, 1); else if (sval.ucase() == "LOW") add_device("TTL_INPUT", name, 0); else add_device("ANALOG_INPUT", name, sval.as_double()); add_pin_alias(name, "1", "Q"); break; case 'D': /* Pin 1 = Anode, Pin 2 = Cathode */ add_device("DIODE", name, sval); add_pin_alias(name, "1", "A"); add_pin_alias(name, "2", "K"); break; case 'U': case 'X': { pstring tname = "TTL_" + sval + "_DIP"; add_device(tname, name); break; } default: tok.error("// IGNORED " + name); } } else if (token.is(tok.m_tok_SIGNAL)) { pstring netname = tok.get_string(); token = tok.get_token(); while (!token.is(tok.m_tok_SEMICOLON)) { /* fixme: should check for string */ pstring devname = token.str(); pstring pin = tok.get_string(); add_term(netname, devname + "." + pin); token = tok.get_token(); } } else { out("Unexpected {}\n", token.str().cstr()); return; } } }
ret_code_t cmd_parser(char *mes, int as, int new_cmd, int *redirect) // as = 0 - get command // as = 1 - may be exit with empty command // new_cmd = 1 - new command // new_cmd = 0 - get added items // returned redirect value (for new_cmd = 1): // 0 - no redirect output // 1 - redirect to the empty file // 2 - add output to the existent file { char *cmd, *str, *beg, *tmp; term_t type; int i; char new_line[LINE_BUF_SIZE]; *redirect = 0; for (;;) { if (new_cmd) { new_command(); type = CMD_TERM; } else type = ITEM_TERM; cmd = get_input_line(mes, new_cmd); if (cmd == (char *)NULL) { go_to_dialog(); continue; }; strcpy(new_cmd_line, cmd); str = new_cmd_line; while (isspace(*str)) str++; if (strlen(str) == 0) { if (as) return HPI_SHELL_OK; continue; }; beg = str; if (*beg == '#') continue; while (*str != 0) { if (isspace(*str)) { *str++ = 0; if (strlen(beg) > 0) { add_term(beg, type); type = ITEM_TERM; }; while (isspace(*str)) str++; add_to_cmd_line(beg); beg = str; continue; }; if (*str == '\"') { str++; while ((*str != 0) && (*str != '\"')) str ++; if (*str == 0) { add_to_cmd_line(beg); add_term(beg, type); if (read_file) add_term(";", CMD_ERROR_TERM); break; }; if (*beg == '\"') { beg++; *str = 0; add_term(beg, type); type = ITEM_TERM; add_to_cmd_line(beg); beg = str + 1; }; str++; continue; }; if (*str == '>') { *str++ = 0; if (strlen(beg) > 0) { add_to_cmd_line(beg); add_term(beg, type); }; if (*str == '>') { add_to_cmd_line(">>"); add_term(">>", CMD_REDIR_TERM); str++; } else { add_to_cmd_line(">"); add_term(">", CMD_REDIR_TERM); }; type = ITEM_TERM; beg = str; continue; }; if ((*str == '!') && read_stdin) { if (str[1] == '!') { i = 2; tmp = get_last_history(); } else { i = 1; tmp = get_def_history(str + 1, &i); }; if (tmp == (char *)NULL) { str += i; continue; }; *str = 0; str += i; snprintf(new_line, LINE_BUF_SIZE, "%s%s%s", beg, tmp, str); str = new_cmd_line + strlen(beg); strcpy(new_cmd_line, new_line); beg = new_cmd_line; continue; }; if (*str == ';') { *str++ = 0; add_to_cmd_line(beg); break; }; str++; }; if (strlen(beg) > 0) { add_to_cmd_line(beg); add_term(beg, type); }; if (read_file) add_term(";", CMD_END_TERM); if (read_stdin) set_current_history(cmd_line); if (new_cmd == 0) return(HPI_SHELL_OK); *redirect = check_cmd_for_redirect(); return(HPI_SHELL_OK); } }
static bool read_config(const char *file_path, Context *ctx) { Variable *last_var = NULL; GList *itr; FILE *f; char line[LINE_SIZE]; char name[NAME_SIZE]; int tmp; // default values ctx->read_freq = READ_FREQ; ctx->days = DAYS; ctx->time_blocks = TIME_BLOCKS; ctx->read_counter = 0; ctx->enable_time_input = 1; ctx->enable_weekday_input = 1; ctx->inputs = NULL; ctx->outputs = NULL; ctx->expectations = NULL; ctx->expectation_blocks = NULL; ctx->time = NULL; ctx->weekday = NULL; f = fopen(file_path, "r"); if (!f) { fprintf(stderr, "Failed to open %s\n", file_path); return false; } while (fgets(line, LINE_SIZE, f)) { float min = 0, max = 0; int ret; // empty or comment line if ((line[0] == '\n') || (line[0] == '#')) continue; ret = sscanf(line, "TIME_BLOCKS %d\n", &ctx->time_blocks); if (ret > 0) { last_var = NULL; continue; } ret = sscanf(line, "DAYS %d\n", &ctx->days); if (ret > 0) { last_var = NULL; continue; } ret = sscanf(line, "READ_FREQ %d\n", &ctx->read_freq); if (ret > 0) { last_var = NULL; continue; } ret = sscanf(line, "ENABLE_TIME_INPUT %d\n", &tmp); if (ret > 0) { ctx->enable_time_input = !!tmp; last_var = NULL; continue; } ret = sscanf(line, "ENABLE_WEEKDAY_INPUT %d\n", &tmp); if (ret > 0) { ctx->enable_weekday_input = !!tmp; last_var = NULL; continue; } ret = sscanf(line, "INPUT " STR_FMT(NAME_SIZE) " %f %f\n", name, &min, &max); if (ret > 0) { last_var = add_input(ctx, name, min, max); continue; } ret = sscanf(line, "OUTPUT " STR_FMT(NAME_SIZE) " %f %f\n", name, &min, &max); if (ret > 0) { last_var = add_output(ctx, name, min, max); add_expectation(ctx, last_var, name); continue; } ret = sscanf(line, "TERM " STR_FMT(NAME_SIZE) " %f %f\n", name, &min, &max); if (ret > 0) { if (!last_var) { fprintf(stderr, "Failed to find var for term %s\n", line); goto error; } add_term(ctx, last_var, name, min, max); continue; } fprintf(stderr, "Unknow configuration %s\n", line); goto error; } ctx->reads = 24 * 60 / ctx->read_freq * ctx->days; for (itr = ctx->inputs; itr; itr = itr->next) { Variable *var = itr->data; if (!var->terms) variable_add_terms(ctx, var); } for (itr = ctx->outputs; itr; itr = itr->next) { Variable *var = itr->data; if (!var->terms) variable_add_terms(ctx, var); } fclose(f); return true; error: fclose(f); return false; }
void cmd_parser(char *mes, int as, int new_cmd) // as = 0 - get command // as = 1 - may be exit with empty command // new_cmd = 1 - new command // new_cmd = 0 - get added items { char *cmd, *str, *beg; term_t type; int len; if (debug_flag) printf("cmd_parser:\n"); for (;;) { if (new_cmd) { new_command(); type = CMD_TERM; } else type = ITEM_TERM; cmd = get_input_line(mes); if (cmd == (char *)NULL) { go_to_dialog(); continue; }; len = strlen(cmd_line); snprintf(cmd_line + len, LINE_BUF_SIZE - len, " %s",cmd); str = cmd; while (isspace(*str)) str++; if (strlen(str) == 0) { if (as) return; continue; }; beg = str; if (*beg == '#') continue; while (*str != 0) { if (isspace(*str)) { *str++ = 0; if (strlen(beg) > 0) { add_term(beg, type); type = ITEM_TERM; }; while (isspace(*str)) str++; beg = str; continue; }; if (*str == '\"') { str++; while ((*str != 0) && (*str != '\"')) str ++; if (*str == 0) { add_term(beg, type); if (read_file) add_term(";", CMD_END_TERM); return; }; if (*beg == '\"') { beg++; *str = 0; add_term(beg, type); type = ITEM_TERM; beg = str + 1; }; str++; continue; }; if (*str == 0) { if (strlen(beg) > 0) add_term(beg, type); if (read_file) add_term(";", CMD_END_TERM); return; }; if (*str == ';') { *str++ = 0; if (strlen(beg) > 0) add_term(beg, type); add_term(";", CMD_END_TERM); return; }; str++; }; if (strlen(beg) > 0) add_term(beg, type); if (read_file) add_term(";", CMD_END_TERM); return; } }