static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream) { char *line = *lineptr; size_t slen = 0; for (;;) { int c = getc(stream); switch (c) { case '\n': if (add_byte(c, &line, slen, n) < 0) goto e_out; slen++; /* fall through */ case EOF: if (add_byte('\0', &line, slen, n) < 0) goto e_out; *lineptr = line; if (slen == 0) return -1; return slen; default: if (add_byte(c, &line, slen, n) < 0) goto e_out; slen++; } } e_out: line[slen-1] = '\0'; *lineptr = line; return -1; }
extern "C" uint64_t pNXT_submit_tx(currency::core *m_core,currency::simple_wallet *wallet,unsigned char *txbytes,int16_t size) { int i,j; crypto::hash h; uint64_t txid = 0; blobdata txb,b; transaction tx = AUTO_VAL_INIT(tx); txin_to_key input_to_key = AUTO_VAL_INIT(input_to_key); NOTIFY_NEW_TRANSACTIONS::request req; currency_connection_context fake_context = AUTO_VAL_INIT(fake_context); tx_verification_context tvc = AUTO_VAL_INIT(tvc); if ( m_core == 0 || wallet == 0 ) { printf("pNXT_submit_tx missing m_core.%p or wallet.%p\n",m_core,wallet); return(0); } tx.vin.clear(); tx.vout.clear(); tx.signatures.clear(); keypair txkey = keypair::generate(); add_tx_pub_key_to_extra(tx, txkey.pub); if ( sizeof(input_to_key.k_image) != 32 ) { printf("FATAL: expected sizeof(input_to_key.k_image) to be 32!\n"); return(0); } j = add_byte(&tx,&input_to_key,0,size&0xff); j = add_byte(&tx,&input_to_key,j,(size>>8)&0xff); for (i=0; i<size; i++) j = add_byte(&tx,&input_to_key,j,txbytes[i]); if ( j != 0 ) tx.vin.push_back(input_to_key); tx.version = 0; txb = tx_to_blob(tx); printf("FROM submit jl777\n"); if ( !m_core->handle_incoming_tx(txb,tvc,false) ) { LOG_PRINT_L0("[on_send_raw_tx]: Failed to process tx"); return(0); } if ( tvc.m_verifivation_failed ) { LOG_PRINT_L0("[on_send_raw_tx]: tx verification failed"); return(0); } if( !tvc.m_should_be_relayed ) { LOG_PRINT_L0("[on_send_raw_tx]: tx accepted, but not relayed"); return(0); } req.txs.push_back(txb); m_core->get_protocol()->relay_transactions(req,fake_context); get_transaction_hash(tx,h); txid = calc_txid((unsigned char *)&h,sizeof(h)); return(txid); }
void add_string(char *c) { add_byte(P_STRING); check_prog_space(strlen(c)+1); while (*c && *c!='\n') program[prog_pos++]=*c++; program[prog_pos++]=0; }
void add_var(short i) { add_byte(P_VAR); check_prog_space(2); *(short*)(program+prog_pos++)=i; prog_pos++; }
void add_short(short i) { add_byte(P_SHORT); check_prog_space(2); *(short*)(program+prog_pos++)=i; prog_pos++; }
void string_base::convert_to_lower_ascii(const char * src,char replace) { reset(); PFC_ASSERT(replace>0); while(*src) { unsigned c; t_size delta = utf8_decode_char(src,c); if (delta==0) {c = replace; delta = 1;} else if (c>=0x80) c = replace; add_byte((char)c); src += delta; } }
/* * Put a simple element (basic class) onto a dialog template in memory. * return a pointer to where the next item should be added. * * parameters: * lStyle = additional style flags * x,y = x & y positions IN DIALOG UNITS * w,h = width and height IN DIALOG UNITS * Id = ID used in messages * clss = class ID, e.g 0x80 for a button, 0x82 for a static * caption = usually text or resource name * * TODO: use the length information noted here to enable the dialog creation * routines to work out more exactly how much memory they need to alloc. */ static LPWORD add_dialog_element( LPWORD p, DWORD lStyle, WORD x, WORD y, WORD w, WORD h, WORD Id, BYTE clss, const char *caption) { lStyle = lStyle | WS_VISIBLE | WS_CHILD; add_word(x); add_word(y); add_word(w); add_word(h); add_word(Id); add_long(lStyle); add_byte(clss); if (((lStyle & SS_ICON) != 0) && (clss == 0x82)) { /* Use resource ID */ add_byte(0xff); add_byte(*caption); } else add_string(caption); add_byte(0); //# of extra bytes following return p; }
static bool alloc_next(KHRN_FMEM_T *fmem) { uint32_t *block; //vcos_assert(fmem->cle_pos + GAP <= (uint8_t *)fmem->junk_pos); block = (uint32_t *)khrn_nmem_group_alloc_master(&fmem->nmem_group); if (!block) return false; add_byte(&fmem->cle_pos, KHRN_HW_INSTR_BRANCH); add_pointer(&fmem->cle_pos, block); fmem->cle_pos = (uint8_t *)block; fmem->junk_pos = block + (KHRN_NMEM_GROUP_BLOCK_SIZE/4); return true; }
bool khrn_fmem_start_render(KHRN_FMEM_T *fmem) { //uint8_t *instr; vcos_assert(fmem->bin_end == NULL && fmem->render_begin == NULL); fmem->bin_end = fmem->cle_pos; #if 0 instr = khrn_fmem_cle(fmem, 1); if (!instr) { vcos_assert(0); return false; } add_byte(&instr, 0); /* Not executed. Just marks gap between bin and render list. */ #endif fmem->render_begin = fmem->cle_pos; return true; }
void string_base::end_with(char p_char) { if (!ends_with(p_char)) add_byte(p_char); }
void string_base::fix_dir_separator(char p_char) { t_size length = get_length(); if (!ends_with(p_char)) add_byte(p_char); }
int gui_mch_dialog( int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd) { FARPROC dp; LPWORD p, pnumitems; int numButtons; int *buttonWidths, *buttonPositions; int buttonYpos; int nchar, i; DWORD lStyle; int dlgwidth = 0; int dlgheight; int editboxheight; int horizWidth; int msgheight; char_u *pstart; char_u *pend; char_u *tbuffer; RECT rect; HWND hwnd; HDC hdc; HFONT oldFont; TEXTMETRIC fontInfo; int fontHeight; int textWidth, minButtonWidth, messageWidth; int maxDialogWidth; int vertical; int dlgPaddingX; int dlgPaddingY; HGLOBAL hglbDlgTemp; #ifndef NO_CONSOLE /* Don't output anything in silent mode ("ex -s") */ if (silent_mode) return dfltbutton; /* return default option */ #endif /* If there is no window yet, open it. */ if (s_hwnd == NULL && gui_mch_init() == FAIL) return dfltbutton; if ((type < 0) || (type > VIM_LAST_TYPE)) type = 0; /* allocate some memory for dialog template */ /* TODO should compute this really*/ hglbDlgTemp = GlobalAlloc(GHND, DLG_ALLOC_SIZE); if (hglbDlgTemp == NULL) return -1; p = (LPWORD) GlobalLock(hglbDlgTemp); if (p == NULL) return -1; /* * make a copy of 'buttons' to fiddle with it. compiler grizzles because * vim_strsave() doesn't take a const arg (why not?), so cast away the * const. */ tbuffer = vim_strsave(buttons); if (tbuffer == NULL) return -1; --dfltbutton; /* Change from one-based to zero-based */ /* Count buttons */ numButtons = 1; for (i = 0; tbuffer[i] != '\0'; i++) { if (tbuffer[i] == DLG_BUTTON_SEP) numButtons++; } if (dfltbutton >= numButtons) dfltbutton = 0; /* Allocate array to hold the width of each button */ buttonWidths = (int *) lalloc(numButtons * sizeof(int), TRUE); if (buttonWidths == NULL) return -1; /* Allocate array to hold the X position of each button */ buttonPositions = (int *) lalloc(numButtons * sizeof(int), TRUE); if (buttonPositions == NULL) return -1; /* * Calculate how big the dialog must be. */ hwnd = GetDesktopWindow(); hdc = GetWindowDC(hwnd); oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT)); dlgPaddingX = DLG_OLD_STYLE_PADDING_X; dlgPaddingY = DLG_OLD_STYLE_PADDING_Y; GetTextMetrics(hdc, &fontInfo); fontHeight = fontInfo.tmHeight; /* Minimum width for horizontal button */ minButtonWidth = GetTextWidth(hdc, "Cancel", 6); /* Maximum width of a dialog, if possible */ GetWindowRect(s_hwnd, &rect); maxDialogWidth = rect.right - rect.left - GetSystemMetrics(SM_CXFRAME) * 2; if (maxDialogWidth < DLG_MIN_MAX_WIDTH) maxDialogWidth = DLG_MIN_MAX_WIDTH; /* Set dlgwidth to width of message */ pstart = message; messageWidth = 0; msgheight = 0; do { pend = vim_strchr(pstart, DLG_BUTTON_SEP); if (pend == NULL) pend = pstart + STRLEN(pstart); /* Last line of message. */ msgheight += fontHeight; textWidth = GetTextWidth(hdc, pstart, pend - pstart); if (textWidth > messageWidth) messageWidth = textWidth; pstart = pend + 1; } while (*pend != NUL); dlgwidth = messageWidth; /* Add width of icon to dlgwidth, and some space */ dlgwidth += DLG_ICON_WIDTH + 3 * dlgPaddingX; if (msgheight < DLG_ICON_HEIGHT) msgheight = DLG_ICON_HEIGHT; /* * Check button names. A long one will make the dialog wider. */ vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL); if (!vertical) { // Place buttons horizontally if they fit. horizWidth = dlgPaddingX; pstart = tbuffer; i = 0; do { pend = vim_strchr(pstart, DLG_BUTTON_SEP); if (pend == NULL) pend = pstart + STRLEN(pstart); // Last button name. textWidth = GetTextWidth(hdc, pstart, pend - pstart); if (textWidth < minButtonWidth) textWidth = minButtonWidth; textWidth += dlgPaddingX; /* Padding within button */ buttonWidths[i] = textWidth; buttonPositions[i++] = horizWidth; horizWidth += textWidth + dlgPaddingX; /* Pad between buttons */ pstart = pend + 1; } while (*pend != NUL); if (horizWidth > maxDialogWidth) vertical = TRUE; // Too wide to fit on the screen. else if (horizWidth > dlgwidth) dlgwidth = horizWidth; } if (vertical) { // Stack buttons vertically. pstart = tbuffer; do { pend = vim_strchr(pstart, DLG_BUTTON_SEP); if (pend == NULL) pend = pstart + STRLEN(pstart); // Last button name. textWidth = GetTextWidth(hdc, pstart, pend - pstart); textWidth += dlgPaddingX; /* Padding within button */ textWidth += DLG_VERT_PADDING_X * 2; /* Padding around button */ if (textWidth > dlgwidth) dlgwidth = textWidth; pstart = pend + 1; } while (*pend != NUL); } if (dlgwidth < DLG_MIN_WIDTH) dlgwidth = DLG_MIN_WIDTH; /* Don't allow a really thin dialog!*/ /* start to fill in the dlgtemplate information. addressing by WORDs */ lStyle = DS_MODALFRAME | WS_CAPTION | WS_VISIBLE ; add_long(lStyle); pnumitems = p; /*save where the number of items must be stored*/ add_byte(0); // NumberOfItems(will change later) add_word(10); // x add_word(10); // y add_word(PixelToDialogX(dlgwidth)); // Dialog height. if (vertical) dlgheight = msgheight + 2 * dlgPaddingY + DLG_VERT_PADDING_Y + 2 * fontHeight * numButtons; else dlgheight = msgheight + 3 * dlgPaddingY + 2 * fontHeight; // Dialog needs to be taller if contains an edit box. editboxheight = fontHeight + dlgPaddingY + 4 * DLG_VERT_PADDING_Y; if (textfield != NULL) dlgheight += editboxheight; add_word(PixelToDialogY(dlgheight)); add_byte(0); //menu add_byte(0); //class /* copy the title of the dialog */ add_string(title ? title : ("Vim"VIM_VERSION_MEDIUM)); buttonYpos = msgheight + 2 * dlgPaddingY; if (textfield != NULL) buttonYpos += editboxheight; pstart = tbuffer; //dflt_text horizWidth = (dlgwidth - horizWidth) / 2; /* Now it's X offset */ for (i = 0; i < numButtons; i++) { /* get end of this button. */ for ( pend = pstart; *pend && (*pend != DLG_BUTTON_SEP); pend++) ; if (*pend) *pend = '\0'; /* * NOTE: * setting the BS_DEFPUSHBUTTON style doesn't work because Windows sets * the focus to the first tab-able button and in so doing makes that * the default!! Grrr. Workaround: Make the default button the only * one with WS_TABSTOP style. Means user can't tab between buttons, but * he/she can use arrow keys. * * NOTE (Thore): Setting BS_DEFPUSHBUTTON works fine when it's the * first one, so I changed the correct button to be this style. This * is necessary because when an edit box is added, we need a button to * be default. The edit box will be the default control, and when the * user presses enter from the edit box we want the default button to * be pressed. */ if (vertical) { p = add_dialog_element(p, ((i == dfltbutton || dfltbutton < 0) && textfield != NULL ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP, PixelToDialogX(DLG_VERT_PADDING_X), PixelToDialogY(buttonYpos /* TBK */ + 2 * fontHeight * i), PixelToDialogX(dlgwidth - 2 * DLG_VERT_PADDING_X), (WORD)(PixelToDialogY(2 * fontHeight) - 1), (WORD)(IDCANCEL + 1 + i), (BYTE)0x80, pstart); } else { p = add_dialog_element(p, ((i == dfltbutton || dfltbutton < 0) && textfield != NULL ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP, PixelToDialogX(horizWidth + buttonPositions[i]), PixelToDialogY(buttonYpos), /* TBK */ PixelToDialogX(buttonWidths[i]), (WORD)(PixelToDialogY(2 * fontHeight) - 1), (WORD)(IDCANCEL + 1 + i), (BYTE)0x80, pstart); } pstart = pend + 1; /*next button*/ } *pnumitems += numButtons; /* Vim icon */ p = add_dialog_element(p, SS_ICON, PixelToDialogX(dlgPaddingX), PixelToDialogY(dlgPaddingY), PixelToDialogX(DLG_ICON_WIDTH), PixelToDialogY(DLG_ICON_HEIGHT), DLG_NONBUTTON_CONTROL + 0, (BYTE)0x82, &dlg_icons[type]); /* Dialog message */ p = add_dialog_element(p, SS_LEFT, PixelToDialogX(2 * dlgPaddingX + DLG_ICON_WIDTH), PixelToDialogY(dlgPaddingY), (WORD)(PixelToDialogX(messageWidth) + 1), PixelToDialogY(msgheight), DLG_NONBUTTON_CONTROL + 1, (BYTE)0x82, message); /* Edit box */ if (textfield != NULL) { p = add_dialog_element(p, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP | WS_BORDER, PixelToDialogX(2 * dlgPaddingX), PixelToDialogY(2 * dlgPaddingY + msgheight), PixelToDialogX(dlgwidth - 4 * dlgPaddingX), PixelToDialogY(fontHeight + dlgPaddingY), DLG_NONBUTTON_CONTROL + 2, (BYTE)0x81, textfield); *pnumitems += 1; } *pnumitems += 2; SelectFont(hdc, oldFont); ReleaseDC(hwnd, hdc); dp = MakeProcInstance((FARPROC)dialog_callback, s_hinst); /* Let the dialog_callback() function know which button to make default * If we have an edit box, make that the default. We also need to tell * dialog_callback() if this dialog contains an edit box or not. We do * this by setting s_textfield if it does. */ if (textfield != NULL) { dialog_default_button = DLG_NONBUTTON_CONTROL + 2; s_textfield = textfield; } else { dialog_default_button = IDCANCEL + 1 + dfltbutton; s_textfield = NULL; } /*show the dialog box modally and get a return value*/ nchar = DialogBoxIndirect( s_hinst, (HGLOBAL) hglbDlgTemp, s_hwnd, (DLGPROC)dp); FreeProcInstance( dp ); GlobalUnlock(hglbDlgTemp); GlobalFree(hglbDlgTemp); vim_free(tbuffer); vim_free(buttonWidths); vim_free(buttonPositions); return nchar; }
void emit_mcode(Mcode *mc, u32 opcode, u32 operand_size, Arg left, Arg right) { bool is_simd = IS_SIMD_OPCODE(opcode); bool jump_opcode = JUMP_OPCODE(opcode); bool set_byte_opcode = SET_BYTE_OPCODE(opcode); bool muldiv_opcode = opcode == MUL || opcode == DIV; assert(!is_simd || operand_size == DWORD || operand_size == QWORD); assert(!jump_opcode || operand_size == BYTE || operand_size == DWORD); assert(!set_byte_opcode || operand_size == BYTE); assert(!(set_byte_opcode || muldiv_opcode) || left.type == REGISTER || left.type == STACK); assert(!jump_opcode || left.type == JUMP); assert(jump_opcode || set_byte_opcode || muldiv_opcode || right.type != UNDEFINED); u8 multibyte_operands = (operand_size == BYTE) ? 0 : 1; if (is_simd) { if (operand_size == DWORD) add_word(mc, 0x0ff3); else if (operand_size == QWORD) add_word(mc, 0x0ff2); } else { if (operand_size == WORD) add_byte(mc, 0x66); else if (operand_size == QWORD) add_byte(mc, 0x48); } if (jump_opcode || set_byte_opcode || muldiv_opcode) { if (set_byte_opcode) { add_byte(mc, 0x0f); add_byte(mc, opcode); if (left.type == REGISTER) add_byte(mc, REG_ADDRESSING << 6 | left.reg); else { if (size_of_int(left.offset) == BYTE) { add_byte(mc, BYTE_OFFSET << 6 | left.reg); add_byte(mc, left.offset); } else { add_byte(mc, DWORD_OFFSET << 6 | left.reg); add_dword(mc, left.offset); } } } else if (jump_opcode) { if (size_of_int(left.offset) == BYTE) { add_byte(mc, opcode); add_byte(mc, left.offset - 2); } else { add_byte(mc, 0x0f); add_byte(mc, opcode + 0x10); add_dword(mc, left.offset - 6); } } else { add_byte(mc, 0xf7); if (left.type == REGISTER) add_byte(mc, REG_ADDRESSING << 6 | opcode << 3 | left.reg); else if (left.type == STACK) { if (size_of_int(left.offset) == BYTE) { add_byte(mc, BYTE_OFFSET << 6 | opcode << 3 | left.reg); add_byte(mc, left.offset); } else { add_byte(mc, DWORD_OFFSET << 6 | opcode << 3 | left.reg); add_dword(mc, left.offset); } } } } else if (left.type == REGISTER && right.type == REGISTER) { if (is_simd) { add_byte(mc, opcode); add_byte(mc, REG_ADDRESSING << 6 | right.reg << 3 | left.reg); } else { add_byte(mc, opcode << 3 | multibyte_operands); add_byte(mc, REG_ADDRESSING << 6 | left.reg << 3 | right.reg); } } else if (left.type == REGISTER && right.type == STACK) { if (is_simd) { assert(opcode == MOVS); add_byte(mc, opcode | 0x1); } else add_byte(mc, opcode << 3 | multibyte_operands); if (size_of_int(right.offset) == BYTE) { add_byte(mc, BYTE_OFFSET << 6 | left.reg << 3 | right.reg); add_byte(mc, right.offset); } else { add_byte(mc, DWORD_OFFSET << 6 | left.reg << 3 | right.reg); add_dword(mc, right.offset); } } else if (left.type == STACK && right.type == REGISTER) { if (is_simd) add_byte(mc, opcode); else add_byte(mc, opcode << 3 | 0x2 | multibyte_operands); if (size_of_int(left.offset) == BYTE) { add_byte(mc, BYTE_OFFSET << 6 | right.reg << 3 | left.reg); add_byte(mc, left.offset); } else { add_byte(mc, DWORD_OFFSET << 6 | right.reg << 3 | left.reg); add_dword(mc, left.offset); } } else if (left.type == IMMEDIATE) { u8 immediate_size = size_of_int(left.immediate); u8 byte_immediate = (immediate_size == BYTE) ? 0x2 : 0x0; assert(!is_simd || right.type != REGISTER); assert(immediate_size != QWORD || opcode == MOV && right.type == REGISTER); if (right.type == REGISTER) { if (opcode == MOV) { if (operand_size == BYTE) add_byte(mc, 0xb0 | right.reg); else add_byte(mc, 0xb8 | right.reg); } else { if (operand_size == BYTE && right.reg == AX) add_byte(mc, 0x04 | opcode << 3 | AX); else { add_byte(mc, 0x80 | byte_immediate | multibyte_operands); add_byte(mc, REG_ADDRESSING << 6 | opcode << 3 | right.reg); } } } else if (right.type == STACK) { u8 opcode_part = 0x0; if (opcode == MOV) add_byte(mc, 0xc6 | multibyte_operands); else { opcode_part = opcode << 3; if (operand_size == BYTE) add_byte(mc, 0x80); else add_byte(mc, 0x80 | byte_immediate | multibyte_operands); } if (size_of_int(right.offset) == BYTE) { add_byte(mc, BYTE_OFFSET << 6 | opcode_part | right.reg); add_byte(mc, right.offset); } else { add_byte(mc, DWORD_OFFSET << 6 | opcode_part | right.reg); add_dword(mc, right.offset); } } switch ((opcode == MOV) ? operand_size : immediate_size) { case BYTE: add_byte(mc, left.immediate); break; case WORD: add_word(mc, left.immediate); break; case DWORD: add_dword(mc, left.immediate); break; case QWORD: add_qword(mc, left.immediate); break; } } else assert(false); /* emit: unhandled arg combo */ }