/* * syn0 * syn1 * syn1 & syntax */ static struct command * syn0(struct wordent *p1, struct wordent *p2, int flags) { struct wordent *p; struct command *t, *t1; int l; l = 0; for (p = p1; p != p2; p = p->next) switch (p->word[0]) { case '(': l++; continue; case ')': l--; if (l < 0) seterror(ERR_TOOMANYRP); continue; case '|': if (p->word[1] == '|') continue; /* fall into ... */ case '>': if (p->next != p2 && eq(p->next->word, STRand)) p = p->next; continue; case '&': if (l != 0) break; if (p->word[1] == '&') continue; t1 = syn1(p1, p, flags); if (t1->t_dtyp == NODE_LIST || t1->t_dtyp == NODE_AND || t1->t_dtyp == NODE_OR) { t = (struct command *) xcalloc(1, sizeof(*t)); t->t_dtyp = NODE_PAREN; t->t_dflg = F_AMPERSAND | F_NOINTERRUPT; t->t_dspr = t1; t1 = t; } else t1->t_dflg |= F_AMPERSAND | F_NOINTERRUPT; t = (struct command *) xcalloc(1, sizeof(*t)); t->t_dtyp = NODE_LIST; t->t_dflg = 0; t->t_dcar = t1; t->t_dcdr = syntax(p, p2, flags); return (t); } if (l == 0) return (syn1(p1, p2, flags)); seterror(ERR_TOOMANYLP); return (0); }
// 输入文件 bool myflexer::inputfile(const char * filename) { m_filename = filename; FILE * file = fopen(filename, "r"); if (!file) { seterror(m_fk, efk_open_file_fail, "open %s fail", filename); return false; } int8_t readbuff[100]; size_t len = 0; while (!feof(file)) { len = fread((void*)readbuff, 1, sizeof(readbuff)-1, file); readbuff[len] = 0; m_content += (char *)readbuff; } fclose(file); if (m_content.empty()) { seterror(m_fk, efk_open_file_empty, "open %s empty", filename); return false; } m_num = m_content.size(); m_pos = 0; return true; }
int initread(int fdread, int fdwrite, int signo, char *buf, int bufsize) { int error; sigset_t oldset, fullset; if ((sigfillset(&fullset) == -1) || (sigprocmask(SIG_SETMASK, &fullset, &oldset) == -1)) { seterror(errno); return -1; } aiocb.aio_fildes = fdread; /* set up structure */ aiocb.aio_offset = 0; aiocb.aio_buf = (void *)buf; aiocb.aio_nbytes = bufsize; aiocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocb.aio_sigevent.sigev_signo = signo; aiocb.aio_sigevent.sigev_value.sival_ptr = &aiocb; fdout = fdwrite; doneflag = 0; globalerror = 0; totalbytes = 0; error = readstart(); /* start first read */ if (sigprocmask(SIG_SETMASK, &oldset, NULL) == -1) { seterror(errno); return -1; } return error; }
/* ARGSUSED */ static void aiohandler(int signo, siginfo_t *info, void *context) { int myerrno, mystatus, serrno; serrno = errno; myerrno = aio_error(&aiocb_read); if (myerrno == EINPROGRESS) { errno = serrno; return; } if (myerrno) { seterror(myerrno); errno = serrno; return; } mystatus = aio_return(&aiocb_read); totalbytes += mystatus; aiocb_read.aio_offset += mystatus; aiocb_write.aio_nbytes = mystatus; if (mystatus == 0) doneflag = 1; else if (aio_write(&aiocb_write) == -1) seterror(errno); else if (readstart() == -1) seterror(errno); errno = serrno; }
int gsopen(Modem *m) { int n; char bytes[Gshdrsize]; /* * Is this gs output */ n = Bread(m->bp, bytes, Gshdrsize); if(n != Gshdrsize) return seterror(m, Esys); if(bytes[0]!='\0' || strcmp(bytes+1, "PC Research, Inc")!=0){ Bseek(m->bp, 0, 0); return seterror(m, Esys); } m->valid |= Vtype; if(bytes[0x1d]) m->vr = 1; else m->vr = 0; m->wd = 0; m->ln = 2; m->df = 0; return Eok; }
/* skip entries until found search or dict end. skipped does not include the found key */ bool TorrentBase::try_next_dict_entry(BufferString search, BufferString prev, bool &error, BufferString *skipped) { size_t start = m_buffer.pos(); error = true; if (m_buffer.pos() >= m_buffer.m_len) return seterror("expected dict, found eof"); BufferString cur; while (m_buffer.m_data[m_buffer.pos()] != 'e') { size_t curpos = m_buffer.pos();; if (!read_utf8(cur)) return errorcontext("parsing dict key failed"); if (cur <= prev) return seterror("(previous) dict entries in wrong order"); if (cur == search) { error = false; if (0 != skipped) *skipped = BufferString(m_buffer.data() + start, curpos - start); return true; } if (cur > search) { m_buffer.m_pos = curpos; error = false; if (0 != skipped) *skipped = BufferString(m_buffer.data() + start, m_buffer.pos() - start); return false; } prev = cur; if (m_buffer.pos() >= m_buffer.m_len) return seterror("expected dict value, found eof"); if (!skip_value()) return errorcontext("parsing dict value failed"); if (m_buffer.pos() >= m_buffer.m_len) return seterror("expected dict entry or 'e', found eof"); } /* dict end found, don't skip the 'e' */ error = false; if (0 != skipped) *skipped = BufferString(m_buffer.data() + start, m_buffer.pos() - start); return false; }
static void fixDolMod(void) { int c; c = DgetC(0); if (c == ':') { do { c = DgetC(0), dolmcnt = 1, dolwcnt = 1; if (c == 'g' || c == 'a') { if (c == 'g') dolmcnt = 10000; else dolwcnt = 10000; c = DgetC(0); } if ((c == 'g' && dolmcnt != 10000) || (c == 'a' && dolwcnt != 10000)) { if (c == 'g') dolmcnt = 10000; else dolwcnt = 10000; c = DgetC(0); } if (c == 's') { /* [eichin:19910926.0755EST] */ int delimcnt = 2; int delim = DgetC(0); dolmod[dolnmod++] = c; dolmod[dolnmod++] = delim; if (!delim || letter(delim) || Isdigit(delim) || any(" \t\n", delim)) { seterror(ERR_BADSUBST); break; } while ((c = DgetC(0)) != (-1)) { dolmod[dolnmod++] = c; if(c == delim) delimcnt--; if(!delimcnt) break; } if(delimcnt) { seterror(ERR_BADSUBST); break; } continue; } if (!any("htrqxes", c)) stderror(ERR_BADMOD, c); dolmod[dolnmod++] = c; if (c == 'q') dolmcnt = 10000; } while ((c = DgetC(0)) == ':'); unDredc(c); } else unDredc(c); }
static void fixDolMod(void) { eChar c; c = DgetC(0); if (c == ':') { do { c = DgetC(0), dolmcnt = 1, dol_flag_a = 0; if (c == 'g' || c == 'a') { if (c == 'g') dolmcnt = INT_MAX; else dol_flag_a = 1; c = DgetC(0); } if ((c == 'g' && dolmcnt != INT_MAX) || (c == 'a' && dol_flag_a == 0)) { if (c == 'g') dolmcnt = INT_MAX; else dol_flag_a = 1; c = DgetC(0); } if (c == 's') { /* [eichin:19910926.0755EST] */ int delimcnt = 2; eChar delim = DgetC(0); Strbuf_append1(&dolmod, (Char) c); Strbuf_append1(&dolmod, (Char) delim); if (delim == DEOF || !delim || letter(delim) || Isdigit(delim) || any(" \t\n", delim)) { seterror(ERR_BADSUBST); break; } while ((c = DgetC(0)) != DEOF) { Strbuf_append1(&dolmod, (Char) c); if(c == delim) delimcnt--; if(!delimcnt) break; } if(delimcnt) { seterror(ERR_BADSUBST); break; } continue; } if (!any("luhtrqxes", c)) stderror(ERR_BADMOD, (int)c); Strbuf_append1(&dolmod, (Char) c); if (c == 'q') dolmcnt = INT_MAX; } while ((c = DgetC(0)) == ':'); unDredc(c); } else unDredc(c); }
/* Receives bytes on a socket up to the first new-line character (\n) or until the number of bytes received is equal to n-1, whichever comes first. Stores the result in string and adds a null character (\0) to the end of the string. If n is equal to 1, the string is empty. Returns a pointer to the string buffer if successful. A NULL return value indicates an error or that the connection is closed.*/ char* XIOsocket::gets(char* buffer, unsigned int size) { unsigned int done = 0; char* p = buffer; DEBUGLOG(("XIOsocket(%p{%d})::gets(%p, %d)\n", this, s_handle, buffer, size)); while (done < size - 1) { #ifdef TCPV40HDRS // Work around for missing SO_RCVTIMEO in 16 bit IP stack. struct timeval timeout = {0}; timeout.tv_sec = xio_socket_timeout(); if (timeout.tv_sec) { fd_set waitlist; FD_ZERO(&waitlist); FD_SET (s_handle, &waitlist); switch (select(s_handle+1, &waitlist, NULL, NULL, &timeout)) { case 0: // Timeout seterror(SOCETIMEDOUT); return NULL; case -1: // Error seterror(); return NULL; } } #endif int rc = recv(s_handle, p, 1, 0); if( rc == 1 ) { if (*p == '\r') continue; else if(*p == '\n') break; else { ++p; ++done; } } else { DEBUGLOG(("XIOsocket::gets: error %d\n", sock_errno())); if (!done) { if (rc == 0) eof = true; else seterror(); return NULL; } else break; } } *p = 0; DEBUGLOG(("XIOsocket::gets: %s\n", buffer)); return buffer; }
bool TorrentBase::skip_value() { char c; if (m_buffer.pos() >= m_buffer.m_len) return seterror("expected value, found eof"); c = m_buffer.m_data[m_buffer.pos()]; if (c >= '0' && c <= '9') return skip_string(); if (c == 'i') return skip_number(); if (c == 'l') return skip_list(); if (c == 'd') return skip_dict(); return seterror("expected value"); }
bool vectrex_cart_slot_device::call_load() { if (m_cart) { UINT32 size = (software_entry() == nullptr) ? length() : get_software_region_length("rom"); UINT8 *ROM; if (size > 0x10000) { seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size"); return IMAGE_INIT_FAIL; } m_cart->rom_alloc((size < 0x1000) ? 0x1000 : size, tag()); ROM = m_cart->get_rom_base(); if (software_entry() == nullptr) fread(ROM, size); else memcpy(ROM, get_software_region("rom"), size); // Verify the file is accepted by the Vectrex bios if (memcmp(ROM, "g GCE", 5)) { seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid image"); return IMAGE_INIT_FAIL; } // determine type m_type = VECTREX_STD; if (!memcmp(ROM + 0x06, "SRAM", 4)) m_type = VECTREX_SRAM; if (size > 0x8000) m_type = VECTREX_64K; //printf("Type: %s\n", vectrex_get_slot(m_type)); // determine 3D setup (to help video setup at machine_start) if (!memcmp(ROM + 0x11, "NARROW", 6) && (ROM[0x39] == 0x0c)) m_vec3d = VEC3D_NARROW; if (!memcmp(ROM + 0x11, "CRAZY COASTER", 13)) m_vec3d = VEC3D_CCOAST; if (!memcmp(ROM + 0x11, "3D MINE STORM", 13)) m_vec3d = VEC3D_MINEST; return IMAGE_INIT_PASS; } return IMAGE_INIT_PASS; }
bool TorrentBase::read_string(BufferString &str) { char c; int64_t pos = m_buffer.pos(), len = m_buffer.m_len; int64_t slen = 0; str.m_data = 0; str.m_len = 0; if (pos >= len) return seterror("expected string length, found eof"); c = m_buffer.m_data[pos++]; if (c < '0' || c > '9') return seterror("expected digit for string length, found eof"); if (pos >= len) return seterror("expected string length, found eof"); if (c == '0' && m_buffer.m_data[pos] != ':') return seterror("expected string length, found leading zero of non zero length (no following ':')"); slen = (c - '0'); for (;;) { c = m_buffer.m_data[pos++]; if (c == ':') break; if (c < '0' || c > '9') return seterror("expected digit or colon for string length, found eof"); if (pos >= len) return seterror("expected string length, found eof"); if (slen > std::numeric_limits<int32_t>::max()) return seterror("string length overflow"); slen = 10*slen + (c - '0'); } if (slen > len || slen > len - pos) return seterror("file not large enough for string length"); /* overflow */ str.m_data = m_buffer.m_data + pos; str.m_len = slen; m_buffer.m_pos = pos + slen; return true; }
bool TorrentBase::skip_list() { if (m_buffer.pos() >= m_buffer.m_len) return seterror("expected list, found eof"); if (m_buffer.m_data[m_buffer.pos()] != 'l') return seterror("expected 'l' for list"); m_buffer.next(); if (m_buffer.pos() >= m_buffer.m_len) return seterror("expected list entry or 'e', found eof"); while (m_buffer.m_data[m_buffer.pos()] != 'e') { if (!skip_value()) return errorcontext("parsing list entry failed");; if (m_buffer.pos() >= m_buffer.m_len) return seterror("expected list entry or 'e', found eof"); } m_buffer.next(); return true; }
variant * assembler_get_classmem_call(fake * fk, variant * classvar, variant * callpos) { bool err = false; variant * n = fk->con.newvariant(); void * classptr = 0; const char * classprefix = 0; // prefix V_GET_POINTER(classvar, classptr, classprefix); if (UNLIKE(err)) { return 0; } const char * funcname = 0; V_GET_STRING(callpos, funcname); if (UNLIKE(err)) { return 0; } if (UNLIKE(!classptr)) { err = true; seterror(fk, efk_jit_error, fkgetcurfile(fk), fkgetcurline(fk), fkgetcurfunc(fk), "jit class mem call error, the class ptr is null, type %s", classprefix); return 0; } // whole name char wholename[MAX_FAKE_REG_FUNC_NAME_LEN]; if (UNLIKE(classvar->data.ponter->typesz + callpos->data.str->sz >= MAX_FAKE_REG_FUNC_NAME_LEN)) { err = true; seterror(fk, efk_jit_error, fkgetcurfile(fk), fkgetcurline(fk), fkgetcurfunc(fk), "jit class mem call error, the name is too long, func %s %s", classprefix, funcname); return 0; } memcpy(wholename, classprefix, classvar->data.ponter->typesz); memcpy(wholename + classvar->data.ponter->typesz, funcname, callpos->data.str->sz); wholename[classvar->data.ponter->typesz + callpos->data.str->sz] = 0; // call it V_SET_STRING(n, wholename); return n; }
int enqueue(queue_t *q, RTP_header *h, unsigned ft, unsigned char *p, unsigned l, unsigned scale) { unsigned j = 0; double t = h->timestamp / (double)scale; if (q->mode & MODE_STREAM || .99 * t <= curtime()) { if (!lock(&q->lock)) return 0; if (l > sizeof q->packets[q->s].p) goto PS; while (j++ < q->n && q->packets[q->s].blocked) INC(q); if (q->packets[q->s].blocked) goto PS; q->packets[q->s].id = h->id; q->packets[q->s].tstamp = t; q->packets[q->s].frame = ft; q->packets[q->s].size = l; q->packets[q->s].next = 0; q->packets[q->s].prev = 0; q->packets[q->s].blocked = 1; memcpy(q->packets[q->s].p, p, l); addpacket(q, &q->packets[q->s]); INC(q); unlock(&q->lock); return 1; } else { return 0; } PS: seterror(err_PS); unlock(&q->lock); return 0; }
int putmchar(Modem *m, char *p) { if(write(m->fd, p, 1) < 0) return seterror(m, Esys); return Eok; }
bool CallRemote(int handle, char s[]) { if(handle < 0 || handle >= ObjectCount || stack[handle]->tag != LIST) return False; if(seterror() == 0) { Cell *res, *params, *list = stack[handle]; list->left = template_nil; push(list->right->right->left); push(template_nil); for(params=list->right; params->left->tag==LIST; params->left=params->left->right) { push(params->left->left); make(LIST); } buildstring(s); push(list->right->right->right->left); make(APPLY); make(APPLY); make(APPLY); eval(); res = pop(); list->right->right->left = res->left; list->left = res->right->left; return True; } else { setstackheight(ObjectCount); stack[handle] = template_nil; interrupted = False; return False; } }
void Interpret(char expr[]) { SetIntSignal(True); if(commandline(expr)) ; else if(seterror()==0) { initstack(); restoretemplates(); CloseAllIOFiles(); interrupted = False; if(parseinput(expr)) checkexpression(top(), True); else { checkexpression(top(), False); settop(modify_expression(top())); starttiming(); toplevel(); stoptiming(); } } SetIntSignal(False); initstack(); restoretemplates(); CloseAllIOFiles(); interrupted = False; Write("\n"); }
bool floppy_image_device::call_create(int format_type, option_resolution *format_options) { image = global_alloc(floppy_image(tracks, sides, form_factor)); output_format = 0; // search for a suitable format based on the extension for(floppy_image_format_t *i = fif_list; i; i = i->next) { // only consider formats that actually support saving if(!i->supports_save()) continue; if (i->extension_matches(basename())) { output_format = i; break; } } // did we find a suitable format? if (output_format == 0) { seterror(IMAGE_ERROR_INVALIDIMAGE, "Unable to identify the image format"); return IMAGE_INIT_FAIL; } return IMAGE_INIT_PASS; }
int XIOsocket::open(const char* uri, XOFLAGS oflags) { DEBUGLOG(("XIOsocket(%p)::open(%s, %x)\n", this, uri, oflags)); if (strnicmp(uri, "tcpip://", 8) == 0) uri += 8; const char* cp = strchr(uri, ':'); if (cp == NULL) { seterror(SOCESOCKTNOSUPPORT); return -1; } char* host = (char*)alloca(cp-uri+1); memcpy(host, uri, cp-uri); host[cp-uri] = 0; u_long address = get_address(host); if (address == (u_long)-1L) { error = errno; return -1; } int port = get_service(cp+1); if (port == -1) { error = errno; return -1; } error = 0; return open(address, port); }
floppy_image_format_t *floppy_image_device::identify(std::string filename) { core_file *fd; std::string revised_path; file_error err = zippath_fopen(filename.c_str(), OPEN_FLAG_READ, fd, revised_path); if(err) { seterror(IMAGE_ERROR_INVALIDIMAGE, "Unable to open the image file"); return 0; } io_generic io; io.file = fd; io.procs = &corefile_ioprocs_noclose; io.filler = 0xff; int best = 0; floppy_image_format_t *best_format = 0; for(floppy_image_format_t *format = fif_list; format; format = format->next) { int score = format->identify(&io, form_factor); if(score > best) { best = score; best_format = format; } } core_fclose(fd); return best_format; }
variant * interpreter::get_container_variant(const func_binary & fb, int conpos) { variant * v = 0; assert(conpos >= 0 && conpos < (int)fb.m_container_addr_list_num); const container_addr & ca = fb.m_container_addr_list[conpos]; bool & err = m_isend; USE(err); variant * conv = 0; do {GET_VARIANT_BY_CMD(fb, m_bp, conv, ca.con);}while(0); const variant * keyv = 0; do {GET_VARIANT_BY_CMD(fb, m_bp, keyv, ca.key);}while(0); if (UNLIKE(m_isend)) { return 0; } if (UNLIKE(!(conv->type == variant::ARRAY || conv->type == variant::MAP))) { m_isend = true; seterror(m_fk, efk_run_inter_error, fkgetcurfile(m_fk), fkgetcurline(m_fk), fkgetcurfunc(m_fk), "interpreter get container variant fail, container type error, type %s", vartypetostring(conv->type)); return 0; } if (conv->type == variant::MAP) { v = con_map_get(m_fk, conv->data.vm, keyv); } else if (conv->type == variant::ARRAY) { v = con_array_get(m_fk, conv->data.va, keyv); } return v; }
void *computethread(void *arg1) { int error; int localdone = 0; struct timespec sleeptime; double val; sleeptime.tv_sec = 0; sleeptime.tv_nsec = TEN_MILLION; while(!localdone) { if (error = randsafe(&val)) break; if (error = add( sin(val) )) break; if (error = getdone(&localdone)) break; nanosleep(&sleeptime, NULL); } seterror(error); return NULL; }
bool TorrentBase::read_utf8(std::string &str) { size_t pos = m_buffer.pos(); BufferString tmp; if (!read_string(tmp)) return false; if (!tmp.validUTF8Text()) { m_buffer.m_pos = pos; return seterror("string not valid utf-8"); } str = tmp.toString(); return true; }
/* Shuts down a socket and frees resources allocated to the socket. Retuns value 0 indicates success; the value -1 indicates an error. */ int XIOsocket::close() { DEBUGLOG(("XIOsocket(%p{%d})::close()\n", this, s_handle)); int r = soclose(s_handle); s_handle = -1; if (r) seterror(); return r; }
int command(Modem *m, char *s) { verbose("m->: %s", s); if(fprint(m->fd, "%s\r", s) < 0) return seterror(m, Esys); return Eok; }
/* Receives data on a socket with descriptor s and stores it in the buffer. When successful, the number of bytes of data received into the buffer is returned. The value 0 indicates that the connection is closed. The value -1 indicates an error. */ int XIOsocket::read(void* buffer, unsigned int size) { unsigned int read = 0; DEBUGLOG2(("XIOsocket(%p{%d})::read(%p, %d)\n", this, s_handle, buffer, size)); while (read < size) { #ifdef TCPV40HDRS // Work around for missing SO_RCVTIMEO in 16 bit IP stack. struct timeval timeout = {0}; timeout.tv_sec = xio_socket_timeout(); if (timeout.tv_sec) { fd_set waitlist; FD_ZERO(&waitlist); FD_SET (s_handle, &waitlist); switch (select(s_handle+1, &waitlist, NULL, NULL, &timeout)) { case 0: // Timeout seterror(SOCETIMEDOUT); return -1; case -1: // Error seterror(); return -1; } } #endif int done = recv(s_handle, (char*)buffer + read, size - read, 0); DEBUGLOG2(("XIOsocket::read: %d, %d\n", done, sock_errno())); if (done < 0) { seterror(); break; } else if (done == 0) { eof = true; break; } else { read += done; } } return read; }
void compiler::compile_seterror(syntree_node * node, fake * fk, efkerror err, const char *fmt, ...) { char errorstr[128]; va_list ap; va_start(ap, fmt); vsnprintf(errorstr, sizeof(errorstr) - 1, fmt, ap); va_end(ap); errorstr[sizeof(errorstr) - 1] = 0; seterror(fk, err, m_mf->getfilename(), node->lineno(), m_cur_compile_func.c_str(), "compile func(%s), %s", m_cur_compile_func.c_str(), errorstr); }
void assembler::compile_seterror(const func_binary & fb, command cmd, efkerror err, const char *fmt, ...) { char errorstr[512]; va_list ap; va_start(ap, fmt); vsnprintf(errorstr, sizeof(errorstr) - 1, fmt, ap); va_end(ap); errorstr[sizeof(errorstr) - 1] = 0; seterror(m_fk, err, FUNC_BINARY_FILENAME(fb), FUNC_BINARY_LINENO(fb, m_pos), FUNC_BINARY_NAME(fb), "assembler %llu, %s", cmd, errorstr); }
int openfaxfile(Modem *m, char *file) { if((m->bp = Bopen(file, OREAD)) == 0) return seterror(m, Esys); m->valid &= ~(Vtype); if(gsopen(m) == Eok) return Eok; return picopen(m); }