NEXT CASE(SMOD) { ON_OP(); updateIOGas(); m_SPP[0] = m_SP[1] ? s2u(modWorkaround(u2s(m_SP[0]), u2s(m_SP[1]))) : 0; }
NEXT CASE(SGT) { ON_OP(); updateIOGas(); m_SPP[0] = u2s(m_SP[0]) > u2s(m_SP[1]) ? 1 : 0; }
NEXT CASE(SDIV) { ON_OP(); updateIOGas(); m_SPP[0] = m_SP[1] ? s2u(divWorkaround(u2s(m_SP[0]), u2s(m_SP[1]))) : 0; --m_SP; }
static char * d2s(intmax_t x, char sign, char *s, size_t *slen_p) { bool neg; if ((neg = (x < 0))) x = -x; s = u2s(x, 10, false, s, slen_p); if (neg) sign = '-'; switch (sign) { case '-': if (neg == false) break; /* Fall through. */ case ' ': case '+': s--; (*slen_p)++; *s = sign; break; default: not_reached(); } return (s); }
string SearchTreeNode::i2s(int i) { string result(_T("")); if(i<0) result << _T('-'); result << u2s(abs(i)); return result; }
static char * x2s(uintmax_t x, bool alt_form, bool uppercase, char *s, size_t *slen_p) { s = u2s(x, 16, uppercase, s, slen_p); if (alt_form) { s -= 2; (*slen_p) += 2; memcpy(s, uppercase ? "0X" : "0x", 2); } return (s); }
static char * o2s(uintmax_t x, bool alt_form, char *s, size_t *slen_p) { s = u2s(x, 8, false, s, slen_p); if (alt_form && *s != '0') { s--; (*slen_p)++; *s = '0'; } return (s); }
string SearchTreeNode::Serialize(BasicSearchTree* tree,nSearchTreeNode node_id,bool withchildren) { string result,children,sparent,sdepth,slabelno,slabelstart,slabellen; SearchTreeLinkMap::iterator link; SearchTreeItemsMap::iterator item; sparent = u2s(m_parent); sdepth = u2s(m_depth); slabelno = u2s(m_label); slabelstart = u2s(m_labelstart); slabellen = u2s(m_labellen); result << _T(" <node id=\"") << node_id << _T("\" parent=\"") << sparent << _T("\""); result << _T(" depth=\"") << sdepth << _T("\" label=\""); result << slabelno << _T(',') << slabelstart << _T(',') << slabellen; result << _T("\">\n"); result << _T(" <items>\n"); for(item = m_Items.begin();item != m_Items.end();item++) { if(item->second) { result << _T(" <item depth=\"") << u2s(item->first) << _T("\" itemid=\"") << u2s(item->second) << _T("\"") << _T(" />\n"); } } result << _T(" </items>\n"); result << _T(" <children>\n"); for(link = m_Children.begin();link != m_Children.end();link++) { if(link->second) { result << _T(" <child char=\"") << SerializeString(string(link->first)) << _T("\" nodeid=\"") << u2s(link->second) << _T("\"") << _T(" />\n"); } } result << _T(" </children>\n"); result << _T(" </node>\n"); if(withchildren) { for(link = m_Children.begin();link != m_Children.end();link++) { if(link->second) { result << tree->GetNode(link->second,false)->Serialize(tree,link->second,true); } } } return result; }
void SearchTreeNode::dump(BasicSearchTree* tree,nSearchTreeNode node_id,const string& prefix,string& result) { string suffix(_T("")); suffix << _T("- \"") << SerializeString(GetLabel(tree)) << _T("\" (") << u2s(node_id) << _T(")"); if(prefix.length() && prefix[prefix.length()-1]=='|') result << prefix.substr(0,prefix.length()-1) << _T('+') << suffix << _T('\n'); else if(prefix.length() && prefix[prefix.length()-1]==' ') result << prefix.substr(0,prefix.length()-1) << _T('\\') << suffix << _T('\n'); else result << prefix << suffix << _T('\n'); string newprefix(prefix); newprefix.append(suffix.length() - 2, _T(' ')); newprefix << _T("|"); SearchTreeLinkMap::iterator i; unsigned int cnt = 0; for(i = m_Children.begin(); i!= m_Children.end(); i++) { if(cnt == m_Children.size() - 1) newprefix[newprefix.length() - 1] = _T(' '); tree->GetNode(i->second,false)->dump(tree,i->second,newprefix,result); cnt++; } }
int malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap) { int ret; size_t i; const char *f; #define APPEND_C(c) do { \ if (i < size) \ str[i] = (c); \ i++; \ } while (0) #define APPEND_S(s, slen) do { \ if (i < size) { \ size_t cpylen = (slen <= size - i) ? slen : size - i; \ memcpy(&str[i], s, cpylen); \ } \ i += slen; \ } while (0) #define APPEND_PADDED_S(s, slen, width, left_justify) do { \ /* Left padding. */ \ size_t pad_len = (width == -1) ? 0 : ((slen < (size_t)width) ? \ (size_t)width - slen : 0); \ if (left_justify == false && pad_len != 0) { \ size_t j; \ for (j = 0; j < pad_len; j++) \ APPEND_C(' '); \ } \ /* Value. */ \ APPEND_S(s, slen); \ /* Right padding. */ \ if (left_justify && pad_len != 0) { \ size_t j; \ for (j = 0; j < pad_len; j++) \ APPEND_C(' '); \ } \ } while (0) #define GET_ARG_NUMERIC(val, len) do { \ switch (len) { \ case '?': \ val = va_arg(ap, int); \ break; \ case '?' | 0x80: \ val = va_arg(ap, unsigned int); \ break; \ case 'l': \ val = va_arg(ap, long); \ break; \ case 'l' | 0x80: \ val = va_arg(ap, unsigned long); \ break; \ case 'q': \ val = va_arg(ap, long long); \ break; \ case 'q' | 0x80: \ val = va_arg(ap, unsigned long long); \ break; \ case 'j': \ val = va_arg(ap, intmax_t); \ break; \ case 't': \ val = va_arg(ap, ptrdiff_t); \ break; \ case 'z': \ val = va_arg(ap, ssize_t); \ break; \ case 'z' | 0x80: \ val = va_arg(ap, size_t); \ break; \ case 'p': /* Synthetic; used for %p. */ \ val = va_arg(ap, uintptr_t); \ break; \ default: not_reached(); \ } \ } while (0) i = 0; f = format; while (true) { switch (*f) { case '\0': goto label_out; case '%': { bool alt_form = false; bool zero_pad = false; bool left_justify = false; bool plus_space = false; bool plus_plus = false; int prec = -1; int width = -1; unsigned char len = '?'; f++; if (*f == '%') { /* %% */ APPEND_C(*f); break; } /* Flags. */ while (true) { switch (*f) { case '#': assert(alt_form == false); alt_form = true; break; case '0': assert(zero_pad == false); zero_pad = true; break; case '-': assert(left_justify == false); left_justify = true; break; case ' ': assert(plus_space == false); plus_space = true; break; case '+': assert(plus_plus == false); plus_plus = true; break; default: goto label_width; } f++; } /* Width. */ label_width: switch (*f) { case '*': width = va_arg(ap, int); f++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { uintmax_t uwidth; set_errno(0); uwidth = malloc_strtoumax(f, (char **)&f, 10); assert(uwidth != UINTMAX_MAX || get_errno() != ERANGE); width = (int)uwidth; if (*f == '.') { f++; goto label_precision; } else goto label_length; break; } case '.': f++; goto label_precision; default: goto label_length; } /* Precision. */ label_precision: switch (*f) { case '*': prec = va_arg(ap, int); f++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { uintmax_t uprec; set_errno(0); uprec = malloc_strtoumax(f, (char **)&f, 10); assert(uprec != UINTMAX_MAX || get_errno() != ERANGE); prec = (int)uprec; break; } default: break; } /* Length. */ label_length: switch (*f) { case 'l': f++; if (*f == 'l') { len = 'q'; f++; } else len = 'l'; break; case 'j': len = 'j'; f++; break; case 't': len = 't'; f++; break; case 'z': len = 'z'; f++; break; default: break; } /* Conversion specifier. */ switch (*f) { char *s; size_t slen; case 'd': case 'i': { intmax_t val JEMALLOC_CC_SILENCE_INIT(0); char buf[D2S_BUFSIZE]; GET_ARG_NUMERIC(val, len); s = d2s(val, (plus_plus ? '+' : (plus_space ? ' ' : '-')), buf, &slen); APPEND_PADDED_S(s, slen, width, left_justify); f++; break; } case 'o': { uintmax_t val JEMALLOC_CC_SILENCE_INIT(0); char buf[O2S_BUFSIZE]; GET_ARG_NUMERIC(val, len | 0x80); s = o2s(val, alt_form, buf, &slen); APPEND_PADDED_S(s, slen, width, left_justify); f++; break; } case 'u': { uintmax_t val JEMALLOC_CC_SILENCE_INIT(0); char buf[U2S_BUFSIZE]; GET_ARG_NUMERIC(val, len | 0x80); s = u2s(val, 10, false, buf, &slen); APPEND_PADDED_S(s, slen, width, left_justify); f++; break; } case 'x': case 'X': { uintmax_t val JEMALLOC_CC_SILENCE_INIT(0); char buf[X2S_BUFSIZE]; GET_ARG_NUMERIC(val, len | 0x80); s = x2s(val, alt_form, *f == 'X', buf, &slen); APPEND_PADDED_S(s, slen, width, left_justify); f++; break; } case 'c': { unsigned char val; char buf[2]; assert(len == '?' || len == 'l'); assert_not_implemented(len != 'l'); val = va_arg(ap, int); buf[0] = val; buf[1] = '\0'; APPEND_PADDED_S(buf, 1, width, left_justify); f++; break; } case 's': assert(len == '?' || len == 'l'); assert_not_implemented(len != 'l'); s = va_arg(ap, char *); slen = (prec == -1) ? strlen(s) : prec; APPEND_PADDED_S(s, slen, width, left_justify); f++; break; case 'p': { uintmax_t val; char buf[X2S_BUFSIZE]; GET_ARG_NUMERIC(val, 'p'); s = x2s(val, true, false, buf, &slen); APPEND_PADDED_S(s, slen, width, left_justify); f++; break; } default: not_implemented(); } break; } default: { APPEND_C(*f); f++; break; }} } label_out: if (i < size) str[i] = '\0'; else str[size - 1] = '\0'; ret = i; #undef APPEND_C #undef APPEND_S #undef APPEND_PADDED_S #undef GET_ARG_NUMERIC return (ret); }
void EditBoxCollection::draw() { if(!current()) return; current()->draw(); char* str = statusline; char* ptr = cName; if(!str || !ptr) return; int fminlen = 0; char cNum[16]; for(;*str; str++) { if(*str == '%') { char *out = 0; int minlen = 0; str++; if(!*str) break; while(__isdd(*str)) { minlen *= 10; minlen += *str++ - '0'; } switch(*str) { case 'n': out = u2s(current()->number(), 0, cNum); break; case 'r': out = u2s(current()->get_edit_row(), minlen, cNum); break; case 'c': out = u2s(current()->get_edit_col(), minlen, cNum); break; case 'd': out = u2s(current()->get_cur_char(), minlen, cNum); break; case 'p': out = u2s(current()->get_rel_pos() , minlen, cNum); break; case 'x': out = c2x(current()->get_cur_char(), cNum); break; case 'h': out = Parser::NameByKey(current()->get_hiliting()); break; case 'l': out = current()->get_cur_cp(); break; case 'a': out = (current()->get_auto_indent() ? cStInd:cStNoInd); break; case 'o': out = (current()->get_auto_completion() ? cStAcOn:cStAcOff); break; case 'u': out = (current()->get_saved() ? cStNoChg:cStChange); break; case 't': out = (current()->get_unix() ? cStUnix:cStDOS); break; case 'm': out = (current()->get_column_block() ? cStColumn:cStStream); break; case 'f': out = current()->get_fmt_name(minlen, '°'); fminlen = minlen; break; case 'w': if(!(current()->ww_get() & WW_STATE)) out = cStUnwrap; else out = (current()->ww_get() & WW_MERGE ? cStMerge:cStWrap); break; default: if(*str) *ptr++ = *str; break; } if(out) while(*out) *ptr++ = *out++; continue; } *ptr++ = *str; } *ptr = 0; int sRow = (iUpperStatus) ? (0):(Rows - 1); vio_print2(sRow, 0, cName, Cols, MK_CLR(CL_STATUSLINE)); if(recording) vio_print2(sRow, Cols - 1, "R", 1, 0xF0); strcpy(cName, "FED-"); strcat(cName, current()->get_fmt_name(fminlen)); set_title(cName); }