// Fetch and return the next char from input stream. void fetchc(void) { // terrible horrible eeprom addressing kludge if (isram(fetchptr)) { if (*fetchptr) fetchptr++; inchar = *fetchptr; } else { // fetch char from eeprom int addr = dekludge(fetchptr); inchar = eeread(addr); if ((inchar != 0) && (inchar != 255)) { inchar = eeread(++addr); fetchptr = kludge(addr); // save incremented pointer if (inchar == 255) inchar = 0; } } #ifdef PARSER_TRACE // char trace if (trace) { //spb('['); printInteger(inchar);spb(':'); if (inchar) spb(inchar); spb(']'); spb('['); if (inchar >= 0x20) spb(inchar); else { spb('\\'); printInteger(inchar); } spb(']'); } #endif //return inchar; }
///////// // // Parse mark and restore // // Interpreting the while and switch commands requires marking and resuming from // a previous point in the input stream. So does calling a function in eeprom. // These routines allow the parser to drop anchor at a point in the stream // and restore back to it. // numvar markparsepoint(void) { #if defined(SDFILE) if (fetchtype == SCRIPT_FILE) { // the location we wish to return to is the point from which we read inchar, // which is one byte before the current file pointer since it auto-advances fetchptr = scriptgetpos() - 1; } #endif // stash the fetch context type in the high nibble of fetchptr // LIMIT: longest script is 2^29-1 bytes numvar ret = ((numvar) fetchtype << 28) | (fetchptr & 0x0fffffffL); #ifdef PARSER_TRACE if (trace) { speol(); sp("mark:");printHex(fetchtype); spb(' '); printHex(fetchptr); spb('>'); printHex(ret); speol(); } #endif return ret; }
void initparsepoint(byte scripttype, numvar scriptaddress, char *scriptname) { #ifdef PARSER_TRACE if (trace) { speol(); sp("init:");printHex(scripttype); spb(' '); printHex(scriptaddress); if (scriptname) { spb(' '); sp(scriptname); } speol(); } #endif fetchtype = scripttype; fetchptr = scriptaddress; // if we're restoring to idle, we're done if (fetchtype == SCRIPT_NONE) return; #if defined(SDFILE) // handle file transition side effects here, once per transition, // rather than once per character below in primec() if (fetchtype == SCRIPT_FILE) { // ask the file glue to open and position the file for us if (!scriptopen(scriptname, scriptaddress, O_READ)) unexpected(M_oops); // TODO: error message } #endif primec(); // re-fetch inchar }
void pointToError(void) { if (isram(fetchptr)) { int i = fetchptr - lbuf; if ((i < 0) || (i >= LBUFLEN)) return; speol(); while (i-- >= 0) spb('-'); spb('^'); speol(); } }
void pointToError(void) { if (fetchtype == SCRIPT_RAM) { int i = (char *) fetchptr - lbuf; if ((i < 0) || (i >= LBUFLEN)) return; speol(); while (i-- >= 0) spb('-'); spb('^'); speol(); } }
void showTaskList(void) { byte slot; for (slot = 0; slot < NUMTASKS; slot++) { if (tasklist[slot] != SLOT_FREE) { printInteger(slot, 0, ' '); spb(':'); spb(' '); eeputs(tasklist[slot]); speol(); } } }
// Add a character to the input line buffer; overflow if needed byte putlbuf(char c) { if (lbufptr < lbuf + LBUFLEN - 2) { *lbufptr++ = c; spb(c); return 1; } else { spb(7); // beep return 0; } }
///////// // // "cat": copy file to serial out // numvar sdcat(void) { if (!scriptfileexists((char *) getarg(1))) return 0; numvar fetchmark = markparsepoint(); initparsepoint(SCRIPT_FILE, 0L, (char *) getarg(1)); while (inchar) { if (inchar == '\n') spb('\r'); spb(inchar); fetchc(); } returntoparsepoint(fetchmark, 1); return 1; }
void showdict(const prog_char *addr) { byte c; for (;;) { c = pgm_read_byte(addr++); if (c == 255) return; else if (c == 0) { if (pgm_read_byte(addr) == 0) return; else spb(' '); } else if (c != '`') spb(c); } }
///////// // // fetchc(): // advance input to next character of input stream // and set inchar to the character found there // void fetchc(void) { ++fetchptr; #ifdef PARSER_TRACE if (trace) { spb('['); printHex(fetchptr); spb(']'); } #endif primec(); }
void TraceSvcUtil::startSession(TraceSession& session, bool /*interactive*/) { m_stop = false; HalfStaticArray<UCHAR, 1024> buff(*getDefaultMemoryPool()); UCHAR* p = NULL; long len = 0; FILE* file = NULL; try { const char* fileName = session.ses_config.c_str(); file = fopen(fileName, "rb"); if (!file) { (Arg::Gds(isc_io_error) << Arg::Str("fopen") << Arg::Str(fileName) << Arg::Gds(isc_io_open_err) << Arg::OsError()).raise(); } fseek(file, 0, SEEK_END); len = ftell(file); if (len == 0) { (Arg::Gds(isc_io_error) << Arg::Str("fread") << Arg::Str(fileName) << Arg::Gds(isc_io_read_err) << Arg::OsError()).raise(); } fseek(file, 0, SEEK_SET); p = buff.getBuffer(len); if (fread(p, 1, len, file) != size_t(len)) { (Arg::Gds(isc_io_error) << Arg::Str("fread") << Arg::Str(fileName) << Arg::Gds(isc_io_read_err) << Arg::OsError()).raise(); } fclose(file); } catch (const Exception&) { if (file) fclose(file); throw; } ClumpletWriter spb(ClumpletWriter::SpbStart, MAXBUF); spb.insertTag(isc_action_svc_trace_start); spb.insertBytes(isc_spb_trc_cfg, p, len); if (session.ses_name.hasData()) { spb.insertBytes(isc_spb_trc_name, reinterpret_cast<const UCHAR*> (session.ses_name.c_str()), session.ses_name.length()); } runService(spb.getBufferLength(), spb.getBuffer()); }
void TraceSvcUtil::setAttachInfo(const string& service_name, const string& user, const string& role, const string& pwd, const AuthReader::AuthBlock& /*authBlock*/, bool isAdmin) { ISC_STATUS_ARRAY status = {0}; ClumpletWriter spb(ClumpletWriter::spbList, MAXBUF); if (user.hasData()) { spb.insertString(isc_spb_user_name, user); } if (pwd.hasData()) { spb.insertString(isc_spb_password, pwd); } if (role.hasData()) { spb.insertString(isc_spb_sql_role_name, role); } if (isAdmin) { spb.insertTag(isc_spb_trusted_auth); } if (isc_service_attach(status, 0, service_name.c_str(), &m_svcHandle, static_cast<USHORT>(spb.getBufferLength()), reinterpret_cast<const char*>(spb.getBuffer()))) { status_exception::raise(status); } }
// print the nth string from the message table, e.g., msgp(M_missing); void msgp(byte id) { const prog_char *msg = getmsg(id); for (;;) { char c = pgm_read_byte(msg++); if (!c) break; spb(c); } }
void TraceSvcUtil::listSessions() { ClumpletWriter spb(ClumpletWriter::SpbStart, MAXBUF); spb.insertTag(isc_action_svc_trace_list); runService(spb.getBufferLength(), spb.getBuffer()); }
void cmd_peep(void) { int i=0; #ifdef AVROPENDOUS_BUILD usbMouseOff(); #endif while (i <= ENDEEPROM) { if (i%64 == 0) {speol(); printHex(i+0xe000); spb(':'); } if (i%8 == 0) spb(' '); if (i%4 == 0) spb(' '); byte c = eeread(i) & 0xff; if (c == 0) spb('\\'); else if ((c == 255) || (c < 0)) spb('.'); else if (c < ' ') spb('^'); else spb(c); i++; } speol(); #ifdef AVROPENDOUS_BUILD usbMouseOn(); #endif }
void TraceSvcUtil::stopSession(ULONG id) { ClumpletWriter spb(ClumpletWriter::SpbStart, MAXBUF); spb.insertTag(isc_action_svc_trace_stop); spb.insertInt(isc_spb_trc_id, id); runService(spb.getBufferLength(), spb.getBuffer()); }
void TraceSvcUtil::setActive(ULONG id, bool active) { ClumpletWriter spb(ClumpletWriter::SpbStart, MAXBUF); spb.insertTag(active ? isc_action_svc_trace_resume : isc_action_svc_trace_suspend); spb.insertInt(isc_spb_trc_id, id); runService(spb.getBufferLength(), spb.getBuffer()); }
// Re-prime the lookahead character buffer 'inchar' void primec(void) { // terrible horrible eeprom addressing kludge if (isram(fetchptr)) inchar = *fetchptr; else { inchar = eeread(dekludge(fetchptr)); if (inchar == 255) inchar = 0; } #ifdef PARSER_TRACE // char trace if (trace) { spb('<'); if (inchar >= 0x20) spb(inchar); else { spb('\\'); printInteger(inchar); } spb('>'); } #endif }
// list the strings in the avpdb void cmd_ls(void) { int start = STARTDB; for (;;) { // find the next entry start = findoccupied(start); if (start == FAIL) return; msgp(M_function); spb(' '); eeputs(start); spb(' '); spb('{'); start = findend(start); eeputs(start); spb('}'); spb(';'); speol(); start = findend(start); } }
// Parse the next token from the input stream. void getsym(void) { // dispatch to handler for this type of char (*tokenhandlers[chartype(inchar)])(); #ifdef PARSER_TRACE if (trace) { sp(" sym="); printInteger(sym); sp(" v="); printInteger(symval); spb(' '); } #endif }
/////////////////////// // handle a character from the input stream // may execute the command, etc. // void doCharacter(char c) { if ((c == '\r') || (c == '\n')) { speol(); *lbufptr = 0; doCommand(lbuf); initlbuf(); } else if (c == 3) { // ^C break/stop msgpl(M_ctrlc); initTaskList(); initlbuf(); } #if !defined(TINY_BUILD) else if (c == 2) { // ^B suspend Background macros suspendBackground = !suspendBackground; } #endif else if ((c == 8) || (c == 0x7f)) { if (lbufptr == lbuf) spb(7); // bell else { spb(8); spb(' '); spb(8); *(--lbufptr) = 0; } } #ifdef PARSER_TRACE else if (c == 20) { // ^T toggle trace trace = !trace; //spb(7); } #endif #if !defined(TINY_BUILD) else if (c == 21) { // ^U to get last line msgpl(M_ctrlu); prompt(); sp(lbuf); lbufptr = lbuf + strlen(lbuf); } #endif else putlbuf(c); }
void returntoparsepoint(parsepoint *p, byte returntoparent) { // restore parse type and location; for script files, pass name from string pool byte ftype = p->fetchtype; char *scriptname = calleename; if (returntoparent) { if ((ftype == SCRIPT_NONE) || (ftype == SCRIPT_RAM)) scriptname = topname; else if (arg[2]) scriptname = callername; } initparsepoint(p->fetchtype, p->fetchptr, scriptname); #ifdef PARSER_TRACE if (trace) { speol(); sp("rest:"); printHex(fetchtype); spb(' '); printHex(fetchptr); spb(' ');printHex(returntoparent); speol(); } #endif }
///////// // // primec(): // fetch the current character from the input stream // set inchar to the character or zero on EOF // void primec(void) { switch (fetchtype) { case SCRIPT_RAM: inchar = *(char *) fetchptr; break; case SCRIPT_PROGMEM: inchar = pgm_read_byte(fetchptr); break; case SCRIPT_EEPROM: inchar = eeread((int) fetchptr); break; #if defined(SDFILE) case SCRIPT_FILE: inchar = scriptread(); break; #endif default: unexpected(M_oops); } #ifdef PARSER_TRACE if (trace) { spb('<'); if (inchar >= 0x20) spb(inchar); else { spb('\\'); printInteger(inchar); } spb('>'); } #endif }
bool CamuleDlg::Check_and_Init_Skin() { bool ret = true; wxString skinFileName(thePrefs::GetSkin()); if (skinFileName.IsEmpty() || skinFileName.IsSameAs(_("- default -"))) { return false; } wxString userDir(JoinPaths(GetConfigDir(), wxT("skins")) + wxFileName::GetPathSeparator()); wxStandardPathsBase &spb(wxStandardPaths::Get()); #ifdef __WINDOWS__ wxString dataDir(spb.GetPluginsDir()); #elif defined(__WXMAC__) wxString dataDir(spb.GetDataDir()); #else wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule")); #endif wxString systemDir(JoinPaths(dataDir,wxT("skins")) + wxFileName::GetPathSeparator()); skinFileName.Replace(wxT("User:"******"System:"), systemDir ); m_skinFileName.Assign(skinFileName); if (!m_skinFileName.FileExists()) { AddLogLineC(CFormat( _("Skin directory '%s' does not exist")) % skinFileName ); ret = false; } else if (!m_skinFileName.IsFileReadable()) { AddLogLineC(CFormat( _("WARNING: Unable to open skin file '%s' for read")) % skinFileName); ret = false; } wxFFileInputStream in(m_skinFileName.GetFullPath()); wxZipInputStream zip(in); wxZipEntry *entry; while ((entry = zip.GetNextEntry()) != NULL) { wxZipEntry*& current = cat[entry->GetInternalName()]; delete current; current = entry; } return ret; }
// list the strings in the avpdb void cmd_ls(void) { int start = STARTDB; for (;;) { // find the next entry start = findoccupied(start); if (start == FAIL) return; eeputs(start); msgp(M_defmacro); start = findend(start); eeputs(start); spb('"'); speol(); start = findend(start); } }
void TraceSvcUtil::setAttachInfo(const string& service_name, const string& /*user*/, const string& /*pwd*/, bool isAdmin) { ISC_STATUS_ARRAY status = {0}; ClumpletWriter spb(ClumpletWriter::spbList, MAXBUF); if (isAdmin) { spb.insertTag(isc_spb_trusted_auth); } if (isc_service_attach(status, 0, service_name.c_str(), &m_svcHandle, static_cast<USHORT>(spb.getBufferLength()), reinterpret_cast<const char*>(spb.getBuffer()))) { status_exception::raise(status); } }
void cmd_peep(void) { int i=0; while (i <= ENDEEPROM) { if (!(i&63)) {speol(); printHex(i+0xe000); spb(':'); } if (!(i&7)) spb(' '); if (!(i&3)) spb(' '); byte c = eeread(i) & 0xff; if (c == 0) spb('\\'); //else if ((c == 255) || (c < 0)) spb('.'); else if (c == 255) spb('.'); else if (c < ' ') spb('^'); else spb(c); i++; } speol(); }
Bras::Bras(int cote_, int pin_pap_step, int pin_pap_dir, int pin_bump_asc, int pin_ir, int seuil_ir, long* pulse_color, int pin_pression_): period_run(50), cote(cote_), time_out_on(false), state(INT_RANGE), coul_to_be_on(false), next_coul_on(false), asc(pin_pap_step, pin_pap_dir, pin_bump_asc, cote_), ir(pin_ir, seuil_ir), mon_ir_actif(false), trigger_to_be(T_RANGE), col(pulse_color), trigger_autre_on(false), couleur(ROUGE), trigger_attente_on(false), pression_on(false), pin_pression(pin_pression_) { if (cote == GAUCHE) { servo_rot.attach(PIN_SERVO_ROT_G); servo_retourne.attach(PIN_SERVO_RETOURNE_G); pin_pompe = PIN_POMPE_G; pinMode(pin_pompe, OUTPUT); } else { servo_rot.attach(PIN_SERVO_ROT_D); servo_retourne.attach(PIN_SERVO_RETOURNE_D); pin_pompe = PIN_POMPE_D; pinMode(pin_pompe, OUTPUT); } ir.reverse(); scn(); spb(); pf(); asc.monte(); //while(!asc.run()){ // delay(1); //} }
///////// // // Parse mark and restore // // Interpreting the while and switch commands requires marking and resuming from // a previous point in the input stream. So does calling a function in eeprom. // These routines allow the parser to drop anchor at a point in the stream // and restore back to it. // void markparsepoint(parsepoint *p) { #if defined(SDFILE) || defined(UNIX_BUILD) if (fetchtype == SCRIPT_FILE) { // the location we wish to return to is the point from which we read inchar, // which is one byte before the current file pointer since it auto-advances fetchptr = scriptgetpos() - 1; } #endif p->fetchptr = fetchptr; p->fetchtype = fetchtype; #ifdef PARSER_TRACE if (trace) { speol(); sp("mark:");printHex(fetchtype); spb(' '); printHex(fetchptr); speol(); } #endif }
real PseudoBoolean<real>::minimize_generators(vector<label>& x, int& labeled, bool heuristic) { bool should_continue; real bound; labeled = 0; int n = int( x.size() ); ASSERT(!heuristic); // TODO: should be provided by user Generators<real> generators("generators/generators.txt"); do { // Create symmetric relaxation GeneratorPseudoBoolean<real> spb(generators); spb.create_lp(*this); // Minimize relaxation int new_labeled = 0; bound = spb.minimize(x, new_labeled); // If we have more persistencies, continue should_continue = new_labeled > labeled; labeled = new_labeled; if (labeled == n) { //Nothing more to do should_continue = false; } // Reduce this function reduce(x); } while (should_continue); return bound; }