static msg_t uart_proto_ps(void *p) { (void)p; CANTxFrame txmsg; msg_t tmp; chRegSetThreadName("uart_proto"); while(!chThdShouldTerminate()) { GET_CHAR(tmp); switch(tmp) { case 0xCB: // Standart frame { // Make frame on fly txmsg.IDE = CAN_IDE_STD; GET_CHAR(tmp); // Get flags txmsg.DLC = tmp & 0x0F; // Extract data len from flags txmsg.SID uint8_t len = flags & 0x0F; uint16_t sid; } break; case 0xCE: // Extended frame break; } return 0; } void uartpInit(void) { sdStart(&SD_PS, &sc); chThdCreateStatic(uart_proto_wa, sizeof(uart_proto_wa), NORMALPRIO + 7, uart_proto_ps, NULL); }
void comma_reader(CL_FORM *base) { COPY(SYMVAL(Slisp, 447), ARG(2)); /* *BQ-LEVEL* */ LOAD_FIXNUM(ARG(3), 0, ARG(3)); Fle(ARG(2), 2); if(CL_TRUEP(ARG(2))) { LOAD_SMSTR((CL_FORM *)&Kcomma_reader[0], ARG(2)); /* A comma appeared outside of a backquote */ Ferror(ARG(2), 1); } COPY(SYMVAL(Slisp, 447), ARG(2)); /* *BQ-LEVEL* */ F1minus(ARG(2)); COPY(ARG(2), SYMVAL(Slisp, 447)); /* *BQ-LEVEL* */ LOAD_NIL(ARG(2)); COPY(ARG(0), ARG(3)); LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(4)); /* T */ LOAD_NIL(ARG(5)); LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(6)); /* T */ peek_char1(ARG(2)); if(CL_CHARP(ARG(2)) && GET_CHAR(ARG(2)) == '@') { COPY(ARG(0), ARG(3)); LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(4)); /* T */ LOAD_NIL(ARG(5)); LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(6)); /* T */ read_char1(ARG(3)); COPY(SYMVAL(Slisp, 437), ARG(2)); /* *COMMA-ATSIGN* */ } else { if(CL_CHARP(ARG(2)) && GET_CHAR(ARG(2)) == '.') { COPY(ARG(0), ARG(3)); LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(4)); /* T */ LOAD_NIL(ARG(5)); LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(6)); /* T */ read_char1(ARG(3)); COPY(SYMVAL(Slisp, 438), ARG(2)); /* *COMMA-DOT* */ } else { COPY(SYMVAL(Slisp, 436), ARG(2)); /* *COMMA* */ } } COPY(ARG(0), ARG(3)); LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(4)); /* T */ LOAD_NIL(ARG(5)); LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(6)); /* T */ internal_read(ARG(3)); ALLOC_CONS(ARG(4), ARG(2), ARG(3), ARG(2)); COPY(SYMVAL(Slisp, 447), ARG(3)); /* *BQ-LEVEL* */ F1plus(ARG(3)); COPY(ARG(3), SYMVAL(Slisp, 447)); /* *BQ-LEVEL* */ COPY(ARG(2), ARG(0)); }
FUNC_STATUS WORD pnm_getActualTraits ( IP_XFORM_HANDLE hXform, /* in: handle for xform */ DWORD dwInputAvail, /* in: # avail bytes in input buf */ PBYTE pbInputBuf, /* in: ptr to input buffer */ PDWORD pdwInputUsed, /* out: # bytes used from input buf */ PDWORD pdwInputNextPos,/* out: file-pos to read from next */ PIP_IMAGE_TRAITS pInTraits, /* out: input image traits */ PIP_IMAGE_TRAITS pOutTraits) /* out: output image traits */ { PPNM_INST g; HANDLE_TO_PTR (hXform, g); /* If there is no header, we'll report no usage of input */ *pdwInputUsed = 0; /* Parse the header for decode operations. */ if (!g->fIsEncode) { unsigned char c; unsigned int maxval; GET_CHAR(&c); if (c!='P') { return IP_INPUT_ERROR; } GET_CHAR(&c); if (c=='4') { /* PBM */ g->traits.iComponentsPerPixel=1; g->traits.iBitsPerPixel=1; } else if (c=='5') { /* PGM */ g->traits.iComponentsPerPixel=1; g->traits.iBitsPerPixel=0; } else if (c=='6') { /* PPM */ g->traits.iComponentsPerPixel=3; g->traits.iBitsPerPixel=0; } else { /* "Plain" (all-ASCII) formats (1-3) not (yet) supported. */ return IP_INPUT_ERROR; } GET_INT(&g->traits.iPixelsPerRow); GET_INT(&g->traits.lNumRows); if (!g->traits.iBitsPerPixel) { GET_INT(&maxval); while (maxval) { g->traits.iBitsPerPixel++; maxval>>=1; } }
char *get_tag(char *tag, int tagbuf_len) { char *tag_val, c, term; int t; t = 0; --tagbuf_len; do { GET_CHAR(c, NULL); } while (ap_isspace(c)); if (c != '"' && c != '\'') { return NULL; } term = c; while (1) { GET_CHAR(c, NULL); if (t == tagbuf_len) { /* Suppose t == tagbuf_len - 1 */ tag[t] = EOS; return NULL; } if (c == '\\') { GET_CHAR(c, NULL); if (c != term) { /* OK */ tag[t] = '\\'; t++; if (t == tagbuf_len) { /* OK */ tag[t] = EOS; return NULL; } } } else if (c == term) { break; } /* OK */ tag[t] = c; t++; /* Now t == tagbuf_len + 1 * So the bounds check (t == tagbuf_len) will fail */ } /* OK */ tag[t] = EOS; return tag; }
CELL func_char_to_integer(CELL frame) { if (!CHARP(FV0)) { return make_exception("expects a <character> argument"); } return make_int((unsigned char)GET_CHAR(FV0)); }
CELL func_char_downcase(CELL frame) { if (!CHARP(FV0)) { return make_exception("expects a <character> argument"); } return make_char(tolower(GET_CHAR(FV0))); }
int serial_getchar(void) { unsigned int Status; unsigned int Ch; Ch=0; //Ch = lib_support_getchar(); if (Ch == 0) { #if defined(SEMIHOSTED) // Use the debugger if the ports are the same if (HOST_COMPORT == OS_COMPORT) Ch = (int)SWI_READC(); else #endif { do { Status = GET_STATUS(OS_COMPORT); } while (!RX_DATA(Status)); // wait until ready Ch = GET_CHAR(OS_COMPORT); } } return ((int)Ch); }
static int cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc, CYG_ADDRWORD __vector, CYG_ADDRWORD __data) { int res = 0; channel_data_t* chan = (channel_data_t*)__ch_data; char c; cyg_uint32 status; CYGARC_HAL_SAVE_GP(); cyg_drv_interrupt_acknowledge(chan->isr_vector); *__ctrlc = 0; status = GET_STATUS(chan->base); if ( RX_DATA(status) ) { c = GET_CHAR(chan->base); if( cyg_hal_is_break( &c , 1 ) ) *__ctrlc = 1; res = CYG_ISR_HANDLED; } CYGARC_HAL_RESTORE_GP(); return res; }
CELL func_make_string(CELL frame) { if (!(INTP(FV0) && GET_INT(FV0) >= 0)) { return make_exception("1st argument expects non-negative integer"); } if (FC == 2 && !CHARP(FV1)) { return make_exception("2nd argument expects character"); } return make_string_filled(GET_INT(FV0), (FC == 2) ? GET_CHAR(FV1) : -1); }
CELL func_string_fill(CELL frame) { CELL string = FV0; CELL ch = FV1; if (!STRINGP(string)) { return make_exception("expects a string for 1st argument"); } if (!CHARP(ch)) { return make_exception("expects a character for 2nd argument"); } STRING *str = GET_STRING(string); memset(str->data, GET_CHAR(ch), str->len); return V_VOID; }
// Calculate the number of items that should be in each bucket void countBuckets(const ReadTable* pRT, int64_t* counts, int K) { for(int i = 0; i < K; ++i) counts[i] = 0; for(size_t i = 0; i < pRT->getCount(); ++i) { size_t s_len = pRT->getReadLength(i); for(size_t j = 0; j < s_len; ++j) counts[getBaseRank(GET_CHAR(i,j))]++; counts[getBaseRank('\0')]++; } }
long SDMHello::Unmarshal(const char* buf) { int cur = UnmarshalHeader(buf); if(cur == SDM_INVALID_MESSAGE || total_length != msg_length) { return SDM_INVALID_MESSAGE; } cur += source.Unmarshal(buf,cur); type = GET_CHAR(&buf[cur]); cur += sizeof(char); #ifdef BUILD_WITH_MESSAGE_LOGGING Logger.MessageReceived(*this); #endif return cur; }
static cyg_bool cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch) { cyg_uint8* base = ((channel_data_t*)__ch_data)->base; cyg_uint32 status ; long timeout = 100; // A long time... do { status = GET_STATUS(base); if (--timeout == 0) return false ; } while (!RX_DATA(status)); // wait until ready *ch = GET_CHAR(base); return true; }
int memdump2(char *memory, int len, int idx) { char buffer[4*LINE_LEN+2]; memset(buffer, ' ', 4*LINE_LEN); buffer[4*LINE_LEN] = 0; buffer[(4*LINE_LEN)+1] = 0; if (!(idx % LINE_LEN) && (idx < len)) fprintf(stderr, "0x%x\t", idx); do { sprintf(&buffer[3*(idx%LINE_LEN)], "%.2X ", (*(memory+idx)) & 0xff ); buffer[(3*LINE_LEN) + (idx%LINE_LEN) +1] = GET_CHAR(*(memory+idx)); } while ((++idx % LINE_LEN) && (idx < len)); buffer[3*((idx-1)%LINE_LEN)+3] = ' '; fprintf(stderr, "%s\n", buffer); return ((idx < len)? memdump2(memory, len, idx): 1); }
/** * putChar */ JSValueRef putCharForJSBuffer (JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { BUFFER(buffer); ARGCOUNTMIN(1); GET_JSARRAY(0, values, values_size); if (values != nullptr) { GET_NUMBER(1,index); CHECK_SIZE_AND_GROW(sizeof(char),(index + values_size - 1)); SET_JSVALUES_AS_PRIMITIVE(char, index, values, values_size); } else { GET_CHAR(0,value); GET_NUMBER(1,index); CHECK_SIZE_AND_GROW(sizeof(char),index); PRIMITIVE_SET(char,index); } return object; }
CELL func_string(CELL frame) { CELL s = V_EMPTY; gc_root_2("func_string", frame, s); s = make_string_raw(FC); CHAR* data = GET_STRING(s)->data; int argi; for(argi = 0; argi < FC; ++argi) { if (!CHARP(FV[argi])) { gc_unroot(); return make_exception("expects character arguments"); } data[argi] = GET_CHAR(FV[argi]); } gc_unroot(); return s; }
void induceSAs(const ReadTable* pRT, SuffixArray* pSA, char** p_array, int64_t* counts, int64_t* buckets, size_t n, int K, bool end) { getBuckets(counts, buckets, K, end); for(int64_t i = n - 1; i >= 0; --i) { const SAElem& elem_i = pSA->get(i); if(!elem_i.isEmpty() && elem_i.getPos() > 0) { //std::cout << "<isas>Curr: " << elem_i << "\n"; SAElem elem_j(elem_i.getID(), elem_i.getPos() - 1); if(getBit(p_array, elem_j.getID(), elem_j.getPos())) { char c = GET_CHAR(elem_j.getID(),elem_j.getPos()); //std::cout << "<iSAs>Placing " << elem_j << " at position " << buckets[GET_BKT(c)] - 1 << "\n"; pSA->set(--buckets[GET_BKT(c)], elem_j); } } } }
// FIXME - should typecheck all list elements before allocating storage? CELL func_list_to_string(CELL frame) { CELL list = FV0; int n = proper_list_length(list); if (n == -1) { return make_exception("expects list of characters"); } gc_root_1("func_list_to_string", list); CELL result = make_string_raw(n); gc_unroot(); CHAR* data = GET_STRING(result)->data; int i; for(i = 0; i < n; ++i) { CELL ch = CAR(list); list = CDR(list); if (!CHARP(ch)) { return make_exception("expects list of characters"); } data[i] = GET_CHAR(ch); } return result; }
// FIXME does not support immutable strings CELL func_string_set(CELL frame) { CELL string = FV0; CELL k = FV1; CELL ch = FV2; if (!STRINGP(string)) { return make_exception("expects a string"); } if (!INTP(k)) { return make_exception("expects a non-negative integer index"); } if (!CHARP(ch)) { return make_exception("expects a character for 3rd argument"); } STRING *str = GET_STRING(string); size_t kth = GET_INT(k); if (! (kth >= 0 && kth < str->len) ) { return make_exception("index %d out of range [0,%d]", kth, str->len - 1); } str->data[kth] = GET_CHAR(ch); return V_VOID; }
Error VisualScriptExpression::_get_token(Token &r_token) { while (true) { #define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++]) CharType cchar = GET_CHAR(); if (cchar == 0) { r_token.type = TK_EOF; return OK; } switch (cchar) { case 0: { r_token.type = TK_EOF; return OK; } break; case '{': { r_token.type = TK_CURLY_BRACKET_OPEN; return OK; }; case '}': { r_token.type = TK_CURLY_BRACKET_CLOSE; return OK; }; case '[': { r_token.type = TK_BRACKET_OPEN; return OK; }; case ']': { r_token.type = TK_BRACKET_CLOSE; return OK; }; case '(': { r_token.type = TK_PARENTHESIS_OPEN; return OK; }; case ')': { r_token.type = TK_PARENTHESIS_CLOSE; return OK; }; case ',': { r_token.type = TK_COMMA; return OK; }; case ':': { r_token.type = TK_COLON; return OK; }; case '.': { r_token.type = TK_PERIOD; return OK; }; case '=': { cchar = GET_CHAR(); if (cchar == '=') { r_token.type = TK_OP_EQUAL; } else { _set_error("Expected '='"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } return OK; }; case '!': { if (expression[str_ofs] == '=') { r_token.type = TK_OP_NOT_EQUAL; str_ofs++; } else { r_token.type = TK_OP_NOT; } return OK; }; case '>': { if (expression[str_ofs] == '=') { r_token.type = TK_OP_GREATER_EQUAL; str_ofs++; } else if (expression[str_ofs] == '>') { r_token.type = TK_OP_SHIFT_RIGHT; str_ofs++; } else { r_token.type = TK_OP_GREATER; } return OK; }; case '<': { if (expression[str_ofs] == '=') { r_token.type = TK_OP_LESS_EQUAL; str_ofs++; } else if (expression[str_ofs] == '<') { r_token.type = TK_OP_SHIFT_LEFT; str_ofs++; } else { r_token.type = TK_OP_LESS; } return OK; }; case '+': { r_token.type = TK_OP_ADD; return OK; }; case '-': { r_token.type = TK_OP_SUB; return OK; }; case '/': { r_token.type = TK_OP_DIV; return OK; }; case '*': { r_token.type = TK_OP_MUL; return OK; }; case '%': { r_token.type = TK_OP_MOD; return OK; }; case '&': { if (expression[str_ofs] == '&') { r_token.type = TK_OP_AND; str_ofs++; } else { r_token.type = TK_OP_BIT_AND; } return OK; }; case '|': { if (expression[str_ofs] == '|') { r_token.type = TK_OP_OR; str_ofs++; } else { r_token.type = TK_OP_BIT_OR; } return OK; }; case '^': { r_token.type = TK_OP_BIT_XOR; return OK; }; case '~': { r_token.type = TK_OP_BIT_INVERT; return OK; }; case '"': { String str; while (true) { CharType ch = GET_CHAR(); if (ch == 0) { _set_error("Unterminated String"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } else if (ch == '"') { break; } else if (ch == '\\') { //escaped characters... CharType next = GET_CHAR(); if (next == 0) { _set_error("Unterminated String"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } CharType res = 0; switch (next) { case 'b': res = 8; break; case 't': res = 9; break; case 'n': res = 10; break; case 'f': res = 12; break; case 'r': res = 13; break; case 'u': { //hexnumbarh - oct is deprecated for (int j = 0; j < 4; j++) { CharType c = GET_CHAR(); if (c == 0) { _set_error("Unterminated String"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { _set_error("Malformed hex constant in string"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } CharType v; if (c >= '0' && c <= '9') { v = c - '0'; } else if (c >= 'a' && c <= 'f') { v = c - 'a'; v += 10; } else if (c >= 'A' && c <= 'F') { v = c - 'A'; v += 10; } else { ERR_PRINT("BUG"); v = 0; } res <<= 4; res |= v; } } break; //case '\"': res='\"'; break; //case '\\': res='\\'; break; //case '/': res='/'; break; default: { res = next; //r_err_str="Invalid escape sequence"; //return ERR_PARSE_ERROR; } break; } str += res; } else { str += ch; } } r_token.type = TK_CONSTANT; r_token.value = str; return OK; } break; default: { if (cchar <= 32) { break; } if (cchar == '-' || (cchar >= '0' && cchar <= '9')) { //a number String num; #define READING_SIGN 0 #define READING_INT 1 #define READING_DEC 2 #define READING_EXP 3 #define READING_DONE 4 int reading = READING_INT; if (cchar == '-') { num += '-'; cchar = GET_CHAR(); } CharType c = cchar; bool exp_sign = false; bool exp_beg = false; bool is_float = false; while (true) { switch (reading) { case READING_INT: { if (c >= '0' && c <= '9') { //pass } else if (c == '.') { reading = READING_DEC; is_float = true; } else if (c == 'e') { reading = READING_EXP; } else { reading = READING_DONE; } } break; case READING_DEC: { if (c >= '0' && c <= '9') { } else if (c == 'e') { reading = READING_EXP; } else { reading = READING_DONE; } } break; case READING_EXP: { if (c >= '0' && c <= '9') { exp_beg = true; } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) { if (c == '-') is_float = true; exp_sign = true; } else { reading = READING_DONE; } } break; } if (reading == READING_DONE) break; num += String::chr(c); c = GET_CHAR(); } str_ofs--; r_token.type = TK_CONSTANT; if (is_float) r_token.value = num.to_double(); else r_token.value = num.to_int(); return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { String id; bool first = true; while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) { id += String::chr(cchar); cchar = GET_CHAR(); first = false; } str_ofs--; //go back one if (id == "in") { r_token.type = TK_OP_IN; } else if (id == "null") { r_token.type = TK_CONSTANT; r_token.value = Variant(); } else if (id == "true") { r_token.type = TK_CONSTANT; r_token.value = true; } else if (id == "false") { r_token.type = TK_CONSTANT; r_token.value = false; } else if (id == "PI") { r_token.type = TK_CONSTANT; r_token.value = Math_PI; } else if (id == "TAU") { r_token.type = TK_CONSTANT; r_token.value = Math_TAU; } else if (id == "INF") { r_token.type = TK_CONSTANT; r_token.value = Math_INF; } else if (id == "NAN") { r_token.type = TK_CONSTANT; r_token.value = Math_NAN; } else if (id == "not") { r_token.type = TK_OP_NOT; } else if (id == "or") { r_token.type = TK_OP_OR; } else if (id == "and") { r_token.type = TK_OP_AND; } else if (id == "self") { r_token.type = TK_SELF; } else { for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (id == Variant::get_type_name(Variant::Type(i))) { r_token.type = TK_BASIC_TYPE; r_token.value = i; return OK; } } VisualScriptBuiltinFunc::BuiltinFunc bifunc = VisualScriptBuiltinFunc::find_function(id); if (bifunc != VisualScriptBuiltinFunc::FUNC_MAX) { r_token.type = TK_BUILTIN_FUNC; r_token.value = bifunc; return OK; } r_token.type = TK_IDENTIFIER; r_token.value = id; } return OK; } else { _set_error("Unexpected character."); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } } } } r_token.type = TK_ERROR; return ERR_PARSE_ERROR; }
char *get_ttymode(void *frontend, const char *mode) { /* * Propagate appropriate terminal modes from the local terminal, * if any. */ if (!local_tty) return NULL; #define GET_CHAR(ourname, uxname) \ do { \ if (strcmp(mode, ourname) == 0) \ return get_ttychar(&orig_termios, uxname); \ } while(0) #define GET_BOOL(ourname, uxname, uxmemb, transform) \ do { \ if (strcmp(mode, ourname) == 0) { \ int b = (orig_termios.uxmemb & uxname) != 0; \ transform; \ return dupprintf("%d", b); \ } \ } while (0) /* * Modes that want to be the same on all terminal devices involved. */ /* All the special characters supported by SSH */ #if defined(VINTR) GET_CHAR("INTR", VINTR); #endif #if defined(VQUIT) GET_CHAR("QUIT", VQUIT); #endif #if defined(VERASE) GET_CHAR("ERASE", VERASE); #endif #if defined(VKILL) GET_CHAR("KILL", VKILL); #endif #if defined(VEOF) GET_CHAR("EOF", VEOF); #endif #if defined(VEOL) GET_CHAR("EOL", VEOL); #endif #if defined(VEOL2) GET_CHAR("EOL2", VEOL2); #endif #if defined(VSTART) GET_CHAR("START", VSTART); #endif #if defined(VSTOP) GET_CHAR("STOP", VSTOP); #endif #if defined(VSUSP) GET_CHAR("SUSP", VSUSP); #endif #if defined(VDSUSP) GET_CHAR("DSUSP", VDSUSP); #endif #if defined(VREPRINT) GET_CHAR("REPRINT", VREPRINT); #endif #if defined(VWERASE) GET_CHAR("WERASE", VWERASE); #endif #if defined(VLNEXT) GET_CHAR("LNEXT", VLNEXT); #endif #if defined(VFLUSH) GET_CHAR("FLUSH", VFLUSH); #endif #if defined(VSWTCH) GET_CHAR("SWTCH", VSWTCH); #endif #if defined(VSTATUS) GET_CHAR("STATUS", VSTATUS); #endif #if defined(VDISCARD) GET_CHAR("DISCARD", VDISCARD); #endif /* Modes that "configure" other major modes. These should probably be * considered as user preferences. */ /* Configuration of ICANON */ #if defined(ECHOK) GET_BOOL("ECHOK", ECHOK, c_lflag, ); #endif #if defined(ECHOKE) GET_BOOL("ECHOKE", ECHOKE, c_lflag, ); #endif #if defined(ECHOE) GET_BOOL("ECHOE", ECHOE, c_lflag, ); #endif #if defined(ECHONL) GET_BOOL("ECHONL", ECHONL, c_lflag, ); #endif #if defined(XCASE) GET_BOOL("XCASE", XCASE, c_lflag, ); #endif /* Configuration of ECHO */ #if defined(ECHOCTL) GET_BOOL("ECHOCTL", ECHOCTL, c_lflag, ); #endif /* Configuration of IXON/IXOFF */ #if defined(IXANY) GET_BOOL("IXANY", IXANY, c_iflag, ); #endif /* Configuration of OPOST */ #if defined(OLCUC) GET_BOOL("OLCUC", OLCUC, c_oflag, ); #endif #if defined(ONLCR) GET_BOOL("ONLCR", ONLCR, c_oflag, ); #endif #if defined(OCRNL) GET_BOOL("OCRNL", OCRNL, c_oflag, ); #endif #if defined(ONOCR) GET_BOOL("ONOCR", ONOCR, c_oflag, ); #endif #if defined(ONLRET) GET_BOOL("ONLRET", ONLRET, c_oflag, ); #endif /* * Modes that want to be set in only one place, and that we have * squashed locally. */ #if defined(ISIG) GET_BOOL("ISIG", ISIG, c_lflag, ); #endif #if defined(ICANON) GET_BOOL("ICANON", ICANON, c_lflag, ); #endif #if defined(ECHO) GET_BOOL("ECHO", ECHO, c_lflag, ); #endif #if defined(IXON) GET_BOOL("IXON", IXON, c_iflag, ); #endif #if defined(IXOFF) GET_BOOL("IXOFF", IXOFF, c_iflag, ); #endif #if defined(OPOST) GET_BOOL("OPOST", OPOST, c_oflag, ); #endif /* * We do not propagate the following modes: * - Parity/serial settings, which are a local affair and don't * make sense propagated over SSH's 8-bit byte-stream. * IGNPAR PARMRK INPCK CS7 CS8 PARENB PARODD * - Things that want to be enabled in one place that we don't * squash locally. * IUCLC * - Status bits. * PENDIN * - Things I don't know what to do with. (FIXME) * ISTRIP IMAXBEL NOFLSH TOSTOP IEXTEN * INLCR IGNCR ICRNL */ #undef GET_CHAR #undef GET_BOOL /* Fall through to here for unrecognised names, or ones that are * unsupported on this platform */ return NULL; }
char *get_tag(int tagbuf_len) { char *tag_val, c, term; t = 0; --tagbuf_len; do { GET_CHAR(c, NULL); } while (ap_isspace(c)); if (c == '-') { GET_CHAR(c, NULL); if (c == '-') { do { GET_CHAR(c, NULL); } while (ap_isspace(c)); if (c == '>') { ap_cpystrn(tag, "done", tagbuf_len); return tag; } } return NULL; } while (1) { if (t == tagbuf_len) { tag[t] = EOS; return NULL; } if (c == '=' || ap_isspace(c)) { break; } tag[t] = ap_tolower(c); t++; GET_CHAR(c, NULL); } tag[t] = EOS; t++; tag_val = tag + t; while (ap_isspace(c)) { GET_CHAR(c, NULL); } if (c != '=') { return NULL; } do { GET_CHAR(c, NULL); } while (ap_isspace(c)); if (c != '"' && c != '\'') { return NULL; } term = c; while (1) { GET_CHAR(c, NULL); if (t == tagbuf_len) { /* Suppose t == tagbuf_len - 1 */ tag[t] = EOS; return NULL; } if (c == '\\') { GET_CHAR(c, NULL); if (c != term) { /* OK */ tag[t] = '\\'; t++; if (t == tagbuf_len) { /* OK */ __TESTCLAIM_1: tag[t] = EOS; return NULL; } } } else if (c == term) { break; } /* OK */ tag[t] = c; t++; /* Now t == tagbuf_len + 1 * So the bounds check (t == tagbuf_len) will fail */ } /* OK */ tag[t] = EOS; return tag; }
void internal_generic_output(FILE* fp, CELL cell, int strict, int tab) { switch(GET_TYPE(cell)) { case T_VOID: fputs("#<void>", fp); break; case T_NULL: fputs("()", fp); break; case T_UNDEFINED: fputs("#<undefined>", fp); break; case T_EMPTY: fputs("#<empty>", fp); break; case T_BOOL: fputs(GET_BOOL(cell) ? "#t" : "#f", fp); break; case T_CHAR: { CHAR ch = GET_CHAR(cell); if (strict) { switch(ch) { case ' ': fputs("#\\space", fp); break; case 0: fputs("#\\nul", fp); break; case 27: fputs("#\\escape", fp); break; case 127: fputs("#\\rubout", fp); break; case '\a': fputs("#\\alarm", fp); break; case '\b': fputs("#\\backspace", fp); break; case '\f': fputs("#\\page", fp); break; case '\n': fputs("#\\newline", fp); break; case '\r': fputs("#\\return", fp); break; case '\t': fputs("#\\tab", fp); break; case '\v': fputs("#\\vtab", fp); break; default: fprintf(fp, "#\\%c", ch); break; } } else { fputc(ch, fp); } } break; case T_INT: fprintf(fp, "%d", GET_INT(cell)); break; case T_BIGINT: fprintf(fp, "%lld", GET_BIGINT(cell)); break; case T_FLOAT: fprintf(fp, "%f", GET_FLOAT(cell)); break; case T_STRING: { STRING* p = GET_STRING(cell); size_t len = p->len; char* data = p->data; if (strict) { // FIXME -- make this more efficient, and escape other special chars? fputc('"', fp); while(len--) { char ch = *data++; if (ch == '"' || ch == '\\') { fputc('\\', fp); } fputc(ch, fp); } fputc('"', fp); } else { fwrite(data, 1, len, fp); } } break; case T_NAME: { NAME* p = GET_NAME(cell); if (p->gensym) { fprintf(fp, "#_%d", p->gensym); } else { fwrite(GET_NAME(cell)->data, 1, GET_NAME(cell)->len, fp); } } break; case T_KEYWORD: { KEYWORD* p = GET_KEYWORD(cell); fwrite(p->data, 1, p->len, fp); fputc(':', fp); } break; case T_SLOT: fprintf(fp, "#<slot:%d>", GET_SLOT(cell)); break; // FIXME - arbitrary recursion case T_CONS: fputc('(', fp); if (tab) ++tab; int did = 0; while(1) { int pair = CONSP(CAR(cell)); if (!did && tab && pair && !CONSP(CAR(CAR(cell)))) { fprintf(fp, "\n%*s", (tab-1)*2, ""); } internal_generic_output(fp, CAR(cell), strict, tab); cell = CDR(cell); if (NULLP(cell)) { break; } did = (tab && pair); if (did) { fprintf(fp, "\n%*s", (tab-1)*2, ""); } else fputc(' ', fp); if (!CONSP(cell)) { fputs(". ", fp); internal_generic_output(fp, cell, strict, tab); break; } } fputc(')', fp); break; // FIXME - arbitrary recursion case T_VECTOR: { VECTOR *vec = GET_VECTOR(cell); fputs("#(", fp); if (vec->len > 0) { int i = 0; internal_generic_output(fp, vec->data[i++], strict, tab); while(i < vec->len) { fputc(' ', fp); internal_generic_output(fp, vec->data[i++], strict, tab); } } fputc(')', fp); break; } case T_FUNC: fprintf(fp, "#<primitive:%s>", GET_FUNC(cell)->name); break; case T_COMPILED_LAMBDA: fprintf(fp, "#<compiled-lambda:0x%08x>", AS_LITERAL(cell)); break; { if (tab) ++tab; COMPILED_LAMBDA *l = GET_COMPILED_LAMBDA(cell); fprintf(fp, "#<%s %d%s:%d/%d", l->is_macro ? "macro" : "lambda", l->argc, l->rest ? "+" : "", l->depth, l->max_slot); if (tab) { fprintf(fp, "\n%*s", (tab-1)*2, ""); } else { fputc(' ', fp); } internal_generic_output(fp, l->body, strict, tab); fputc('>', fp); } break; case T_CLOSURE: fprintf(fp, "#<closure:0x%08x>", AS_LITERAL(cell)); break; { if (tab) ++tab; CLOSURE *c = GET_CLOSURE(cell); fprintf(fp, "#<closure "); if (tab) { fprintf(fp, "\n%*s", (tab-1)*2, ""); } internal_print_env(fp, c->env); if (tab) { fprintf(fp, "\n%*s", (tab-1)*2, ""); } fputc(' ', fp); internal_generic_output(fp, c->compiled_lambda, strict, tab); fputc('>', fp); } break; case T_EXCEPTION: fputs("#<exception:", fp); fwrite(GET_EXCEPTION(cell)->data, 1, GET_EXCEPTION(cell)->len, fp); fputc('>', fp); break; case T_REIFIED_CONTINUATION: fprintf(fp, "#<continuation:0x%08x>", (int)GET_REIFIED_CONTINUATION(cell)->cont); break; case T_STACK_FRAME: { STACK_FRAME* p = GET_STACK_FRAME(cell); fputs("#<stack-frame [", fp); int i; for(i = 0; i < p->len; ++i) { if (i) fputc(' ', fp); fprintf(fp, "0x%08x", (int)p->cells[i]); } fputs("]>", fp); } break; case T_ENV: fprintf(fp, "#<env:count=%d>", GET_ENV(cell)->count); break; case T_RELOC: fprintf(fp, "#<reloc:0x%08x>", (int)GET_RELOC(cell)); break; case T_PORT: fprintf(fp, "#<port:%s>", GET_PORT(cell)->data); break; case T_DB_CONNECTION: fprintf(fp, "#<db-connection>"); break; case T_DB_RESULT: fprintf(fp, "#<db-result>"); break; case T_RECORD: fprintf(fp, "#<record>"); break; default: fprintf(fp, "#<%s-%02x:%08x>", IS_LITERAL(cell) ? "literal" : "pointer", GET_TYPE(cell), AS_LITERAL(cell) ); break; } }
static gboolean download_spawn_external(const char *uri, const char *filename, WebKitDownload *download) { char **argv; int argc; gboolean ret = true; GError *error = NULL; char *newcommand = NULL; char *command = g_strdup(GET_CHAR("download-external-command")); WebKitNetworkRequest *request = webkit_download_get_network_request(download); const char *referer = soup_get_header_from_request(request, "Referer"); const char *user_agent = soup_get_header_from_request(request, "User-Agent"); char *proxy = GET_CHAR("proxy-url"); gboolean has_proxy = GET_BOOL("proxy"); GSList *list = g_slist_prepend(NULL, dwb_navigation_new("DWB_URI", uri)); list = g_slist_prepend(list, dwb_navigation_new("DWB_FILENAME", filename)); list = g_slist_prepend(list, dwb_navigation_new("DWB_COOKIES", dwb.files[FILES_COOKIES])); if ( (newcommand = util_string_replace(command, "dwb_uri", uri)) ) { g_free(command); command = newcommand; } if ( (newcommand = util_string_replace(command, "dwb_cookies", dwb.files[FILES_COOKIES])) ) { g_free(command); command = newcommand; } if ( (newcommand = util_string_replace(command, "dwb_output", filename)) ) { g_free(command); command = newcommand; } if (referer != NULL) { list = g_slist_prepend(list, dwb_navigation_new("DWB_REFERER", referer)); } if ( (newcommand = util_string_replace(command, "dwb_referer", referer == NULL ? "" : referer)) ) { g_free(command); command = newcommand; } if ( (newcommand = util_string_replace(command, "dwb_proxy", proxy == NULL && has_proxy ? "" : proxy)) ) { g_free(command); command = newcommand; } if (user_agent != NULL) list = g_slist_prepend(list, dwb_navigation_new("DWB_USER_AGENT", user_agent)); list = g_slist_prepend(list, dwb_navigation_new("DWB_MIME_TYPE", dwb.state.mimetype_request)); if (proxy != NULL && has_proxy) list = g_slist_prepend(list, dwb_navigation_new("DWB_PROXY", proxy)); g_shell_parse_argv(command, &argc, &argv, NULL); g_free(command); if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, (GSpawnChildSetupFunc)dwb_setup_environment, list, NULL, &error)) { perror(error->message); ret = false; } g_strfreev(argv); return ret; }
VbResult input_open_editor(Client *c) { char **argv, *file_path = NULL; const char *text = NULL, *editor_command; int argc; GPid pid; gboolean success; GVariant *jsreturn; g_assert(c); /* get the editor command */ editor_command = GET_CHAR(c, "editor-command"); if (!editor_command || !*editor_command) { vb_echo(c, MSG_ERROR, TRUE, "No editor-command configured"); return RESULT_ERROR; } /* get the selected input element */ jsreturn = ext_proxy_eval_script_sync(c, "vimb_input_mode_element.value"); g_variant_get(jsreturn, "(bs)", &success, &text); if (!success || !text) { return RESULT_ERROR; } /* create a temp file to pass text to and from editor */ if (!util_create_tmp_file(text, &file_path)) { return RESULT_ERROR; } /* spawn editor */ char* command = g_strdup_printf(editor_command, file_path); if (!g_shell_parse_argv(command, &argc, &argv, NULL)) { g_critical("Could not parse editor-command '%s'", command); g_free(command); return RESULT_ERROR; } g_free(command); success = g_spawn_async( NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL ); g_strfreev(argv); if (!success) { unlink(file_path); g_free(file_path); g_warning("Could not spawn editor-command"); return RESULT_ERROR; } /* disable the active element */ ext_proxy_eval_script(c, "vimb_input_mode_element.disabled=true", NULL); /* watch the editor process */ EditorData *data = g_slice_new0(EditorData); data->file = file_path; data->c = c; g_child_watch_add(pid, (GChildWatchFunc)resume_editor, data); return RESULT_COMPLETE; }
VbResult input_open_editor(void) { char **argv, *file_path = NULL; const char *text, *editor_command; int argc; GPid pid; gboolean success; editor_command = GET_CHAR("editor-command"); if (!editor_command || !*editor_command) { vb_echo(VB_MSG_ERROR, true, "No editor-command configured"); return RESULT_ERROR; } Element* active = dom_get_active_element(vb.gui.webview); /* check if element is suitable for editing */ if (!active || !dom_is_editable(active)) { return RESULT_ERROR; } text = dom_editable_element_get_value(active); if (!text) { return RESULT_ERROR; } if (!util_create_tmp_file(text, &file_path)) { return RESULT_ERROR; } /* spawn editor */ char* command = g_strdup_printf(editor_command, file_path); if (!g_shell_parse_argv(command, &argc, &argv, NULL)) { g_critical("Could not parse editor-command '%s'", command); g_free(command); return RESULT_ERROR; } g_free(command); success = g_spawn_async( NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL ); g_strfreev(argv); if (!success) { unlink(file_path); g_free(file_path); g_warning("Could not spawn editor-command"); return RESULT_ERROR; } /* disable the active element */ dom_editable_element_set_disable(active, true); EditorData *data = g_slice_new0(EditorData); data->file = file_path; data->element = active; g_child_watch_add(pid, (GChildWatchFunc)resume_editor, data); return RESULT_COMPLETE; }
// Implementation of induced copying algorithm by // Nong, Zhang, Chan // Follows implementation given as an appendix to their 2008 paper // '\0' is the sentinenl in this algorithm void saca_induced_copying(SuffixArray* pSA, const ReadTable* pRT, int numThreads) { // In the multiple strings case, we need a 2D bit array // to hold the L/S types for the suffixes size_t num_strings = pRT->getCount(); char** type_array = new char*[num_strings]; for(size_t i = 0; i < num_strings; ++i) { size_t s_len = pRT->getReadLength(i) + 1; size_t num_bytes = (s_len / 8) + 1; type_array[i] = new char[num_bytes]; assert(type_array[i] != 0); memset(type_array[i], 0, num_bytes); } // Classify each suffix as being L or S type for(size_t i = 0; i < num_strings; ++i) { size_t s_len = pRT->getReadLength(i) + 1; // The empty suffix ($) for each string is defined to be S type // and hence the next suffix must be L type setBit(type_array, i, s_len - 1, 1); setBit(type_array, i, s_len - 2, 0); for(int64_t j = s_len - 3; j >= 0; --j) { char curr_c = GET_CHAR(i, j); char next_c = GET_CHAR(i, j + 1); bool s_type = (curr_c < next_c || (curr_c == next_c && getBit(type_array, i, j + 1) == 1)); setBit(type_array, i, j, s_type); } } // setup buckets const int ALPHABET_SIZE = 5; int64_t bucket_counts[ALPHABET_SIZE]; int64_t buckets[ALPHABET_SIZE]; // find the ends of the buckets countBuckets(pRT, bucket_counts, ALPHABET_SIZE); getBuckets(bucket_counts, buckets, ALPHABET_SIZE, true); // Initialize the suffix array size_t num_suffixes = buckets[ALPHABET_SIZE - 1]; pSA->initialize(num_suffixes, pRT->getCount()); // Copy all the LMS substrings into the first n1 places in the SA size_t n1 = 0; for(size_t i = 0; i < num_strings; ++i) { size_t s_len = pRT->getReadLength(i) + 1; for(size_t j = 0; j < s_len; ++j) { if(isLMS(i,j)) pSA->set(n1++, SAElem(i, j)); } } /* //induceSAl(pRT, pSA, type_array, bucket_counts, buckets, num_suffixes, ALPHABET_SIZE, false); //induceSAs(pRT, pSA, type_array, bucket_counts, buckets, num_suffixes, ALPHABET_SIZE, true); // Compact all the sorted substrings into the first portion of the SA size_t n1 = 0; for(size_t i = 0; i < num_suffixes; ++i) { SAElem elem = pSA->get(i); if(!elem.isEmpty() && isLMS(elem.getID(), elem.getPos())) { pSA->set(n1++, elem); } } */ double ratio = (double)n1 / (double)num_suffixes; std::cout << "[saca] calling mkqs on " << n1 << " suffixes " << ratio << " using " << numThreads << " threads \n"; // Call MKQS, first on the sequence and then on the index in the read table SuffixCompareRadix radix_compare(pRT, 6); SuffixCompareIndex index_compare; //SuffixCompareID id_compare(pRT); if(numThreads <= 1) mkqs2(&pSA->m_data[0], n1, 0, radix_compare, index_compare); else parallel_mkqs(&pSA->m_data[0], n1, numThreads, radix_compare, index_compare); std::cout << "[saca] mkqs finished\n"; // Induction sort the remaining suffixes for(size_t i = n1; i < num_suffixes; ++i) pSA->set(i, SAElem()); // Find the ends of the buckets getBuckets(bucket_counts, buckets, ALPHABET_SIZE, true); for(int64_t i = n1 - 1; i >= 0; --i) { SAElem elem_i = pSA->get(i); pSA->set(i, SAElem()); // empty char c = GET_CHAR(elem_i.getID(), elem_i.getPos()); pSA->set(--buckets[GET_BKT(c)], elem_i); } induceSAl(pRT, pSA, type_array, bucket_counts, buckets, num_suffixes, ALPHABET_SIZE, false); induceSAs(pRT, pSA, type_array, bucket_counts, buckets, num_suffixes, ALPHABET_SIZE, true); // deallocate t array for(size_t i = 0; i < num_strings; ++i) { delete [] type_array[i]; } delete [] type_array; }