static int buff_hdl(uint32_t tid, char* buff, size_t size, char last) { dmsg2("start %s, %d: word %s, count %d, *buff %c\n", __FUNCTION__, tid, word, count, *buff); for( ; size; size--, buff++) { if(!IS_A_LETTER(*buff)) { /*Not a letter */ if(add_sep(tid)) return -1; continue; } /* A letter */ if(add_letter(*buff)) return -1; } /* If this is the last buffer, end the word (if any)*/ if(last) { add_sep(tid); } dmsg3("end %s, %d: word %s, count %d, *buff %c\n", __FUNCTION__, tid, word, count, *buff); return 0; }
void CCalcEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { //TRACE("xxxx0 OnKeyD: sel = %x\r\n", GetSel()); in_edit_ = true; ASSERT(pp_ != NULL && pp_->IsVisible()); // Clear any result (unless arrows etc pressed) clear_result((nFlags & 0x100) == 0 && isprint(nChar)); // If editing an integer then make allowances for separator char if (pp_->state_ == CALCINTLIT) { CString ss; // Text from the window (edit control) int start, end; // Current selection in the edit control // Set selection so that arrows/Del work OK in presence of separator chars GetWindowText(ss); GetSel(start, end); char sep_char = ' '; if (pp_->radix_ == 10) sep_char = theApp.dec_sep_char_; // If no selection and character to delete is separator ... if (nChar == VK_DELETE && start == end && start < ss.GetLength() - 1 && ss[start+1] == sep_char) { // Set selection so that the separator and following digit is deleted SetSel(start, start+2); } else if (nChar == VK_LEFT && start == end && start > 0 && ss[start-1] == sep_char) { // Move cursor back one so we skip over the separator (else add_sep below makes the caret stuck) SetSel(start-1, start-1); } else if (nChar == VK_RIGHT && start == end && start < ss.GetLength() - 1 && ss[start+1] == sep_char) { // Move cursor back one so we skip over the separator (else add_sep below makes the caret stuck) SetSel(start+1, start+1); } } CEdit::OnKeyDown(nChar, nRepCnt, nFlags); if (nChar == VK_DELETE) { // This is handled similarly to OnChar since Del key changes the text get(); pp_->state_ = update_value(false); pp_->check_for_error(); add_sep(); get(); pp_->set_right(); pp_->inedit(km_user_str); pp_->ctl_calc_bits_.RedrawWindow(); } in_edit_ = false; //TRACE("xxxx1 OnKeyD: sel = %x\r\n", GetSel()); }
void CCalcEdit::OnEnChange() { if (!in_edit_) { // Update internals (state_, current_ etc) from the current edit box text get(); pp_->state_ = update_value(false); pp_->check_for_error(); add_sep(); // fix display of integers in edit box // Update the expression to be displayed get(); pp_->set_right(); pp_->ctl_calc_bits_.RedrawWindow(); // bit display pp_->inedit(km_user_str); // macro } }
void CCalcEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { //TRACE("xxxx0 OnChar: sel = %x\r\n", GetSel()); in_edit_ = true; ASSERT(pp_ != NULL && pp_->IsVisible()); clear_result(); // Clear text if previous result is displayed // If editing an integer then make allowances for separator char if (pp_->state_ == CALCINTLIT) { CString ss; // Text from the window (edit control) int start, end; // Current selection in the edit control // Set selection so that arrows/Del work OK in presence of separator chars GetWindowText(ss); GetSel(start, end); char sep_char = ' '; if (pp_->radix_ == 10) sep_char = theApp.dec_sep_char_; if (nChar == '\b' && start > 1 && start == end && ss[start-1] == sep_char) { // If deleting 1st char of group then also delete preceding sep_char SetSel(start-2, end); } } CEdit::OnChar(nChar, nRepCnt, nFlags); // Update internals (state_, current_ etc) from the current edit box text get(); pp_->state_ = update_value(false); pp_->check_for_error(); add_sep(); // fix display of integers in edit box // Update the expression to be displayed get(); pp_->set_right(); pp_->inedit(km_user_str); pp_->ctl_calc_bits_.RedrawWindow(); in_edit_ = false; //TRACE("xxxx1 OnChar: sel = %x\r\n", GetSel()); }
static int construct_ack(connection_state_t *st, char *buf) { char *buf0 = buf; buf = add_sep(buf, 1); buf += itoa(st->cmd_out, buf, 10, 1); buf = add_sep(buf, 2); buf += itoa(st->config_out.channel_id, buf, 10, 1); buf = add_sep(buf, 2); buf += itoa(st->config_out.parity, buf, 10, 1); buf = add_sep(buf, 2); buf += itoa(st->config_out.stop_bits, buf, 10, 1); buf = add_sep(buf, 2); buf += itoa(st->config_out.baud, buf, 10, 1); buf = add_sep(buf, 2); buf += itoa(st->config_out.char_len, buf, 10, 1); buf = add_sep(buf, 2); buf += itoa(st->telnet_port_out, buf, 10, 1); buf = add_sep(buf, 1); *buf++ = '@'; *buf++ = '\n'; return (buf-buf0); }
// Put the current value into the edit box // - from current_ if state_ <= CALCINTLIT, // - else from current_str_ // Note that state_/current_/current_str_ may be updated to reflect what current_str_ contained. void CCalcEdit::put() { ASSERT(pp_ != NULL); ASSERT(pp_->radix_ > 1 && pp_->radix_ <= 36); if (theApp.refresh_off_ || !pp_->IsVisible()) return; if (pp_->state_ <= CALCERROR) { if (pp_->current_str_.IsEmpty()) SetWindowText("ERROR"); else ::SetWindowTextW(m_hWnd, (LPCWSTR)pp_->current_str_); TRACE("++++++ Put: error\r\n"); return; } else if (pp_->state_ <= CALCINTLIT) { // Get value from current_ (integer) mpz_class val = pp_->get_norm(pp_->current_); // Get a buffer large enough to hold the text (may be big) int len = mpz_sizeinbase(val.get_mpz_t(), pp_->radix_) + 2 + 1; char *buf = new char[len]; buf[len-1] = '\xCD'; // Get the number as a string and add it to the text box mpz_get_str(buf, theApp.hex_ucase_? -pp_->radix_ : pp_->radix_, val.get_mpz_t()); ASSERT(buf[len-1] == '\xCD'); bool handled = false; if (len > 1000) { CString ss; ss.Format("The result of the operation has been calculated and has %d " "digits which may be too large for the Windows text box to handle.\n\n" "You may open the result in a text file, or copy it to the clipboard, or " "simply select \"Cancel\" to attempt to display it normally.", len-3); CAvoidableDialog dlg(IDS_CALC_TOO_BIG, ss, "", MLCBF_CANCEL_BUTTON); dlg.AddButton(47, "Open in File"); dlg.AddButton(48, "Copy to Clipboard"); switch (dlg.DoModal()) { case 47: theApp.FileFromString(buf); handled = true; break; case 48: if (!OpenClipboard()) AfxMessageBox("The clipboard is in use!"); else { HANDLE hh; // Windows handle for memory char *pp; if (!::EmptyClipboard() || (hh = ::GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, DWORD(len-1))) == NULL || (pp = reinterpret_cast<char *>(::GlobalLock(hh))) == NULL) { AfxMessageBox("Not enough memory to add to clipboard"); ::CloseClipboard(); break; } memcpy(pp, buf, len-1); ::SetClipboardData(CF_TEXT, hh); ::CloseClipboard(); theApp.ClipBoardAdd(len-1); // allow temp cb file to be deleted and keep track of large cb allocs so we can check if they should be deleted on close SetWindowText(""); // Clear text box to avoid confusion handled = true; } break; case IDCANCEL: break; default: ASSERT(0); } } if (!handled) { SetWindowText(buf); SetSel(len, -1, FALSE); // move caret to end } delete[] buf; } else { // Get value from current_str_ (expression (possibly integer), non-int literal, or something else) //SetWindowText(pp_->current_str_); // Put as Unicode as an expression can contain a Unicode string ::SetWindowTextW(m_hWnd, (LPCWSTR)pp_->current_str_); SetSel(pp_->current_str_.GetLength(), -1, FALSE); // move caret to end TRACE("++++++ Put: expr %s\r\n", (const char *)CString(pp_->current_str_)); #if 0 // I don't think this is necessary and makes other code more complicated // Finally we need to make sure that state_ etc match what the string contains. // Eg current_str_ may actually be an integer literal, in which case we update state_/current_ pp_->state_ = update_value(false); #endif } add_sep(); // xxx do this in idle processing??? if (pp_->ctl_calc_bits_.m_hWnd != 0) pp_->ctl_calc_bits_.RedrawWindow(); }
static error_t parse_opt (int key, char *arg, struct argp_state *state) { struct fstab_argp_params *params = state->input; error_t err; switch (key) { case ARGP_KEY_INIT: state->child_inputs[0] = params; /* pass down to fstab_argp parser */ break; #define ARGZ(call) \ err = argz_##call; \ if (err) \ argp_failure (state, 100, ENOMEM, "%s", arg); \ break case 'r': ARGZ (add (&options, &options_len, "ro")); case 'w': ARGZ (add (&options, &options_len, "rw")); case 'u': ARGZ (add (&options, &options_len, "update")); case 'B': ARGZ (add (&options, &options_len, "bind")); case 'o': ARGZ (add_sep (&options, &options_len, arg, ',')); case 'v': ++verbose; break; #undef ARGZ case 'T': { char *end; unsigned long int ms = strtoul (arg, &end, 10); if (end && *end == '\0') timeout = ms; else { argp_error (state, "--timeout needs a numeric argument (milliseconds)"); return EINVAL; } } break; case 'p': if (arg == 0 || !strcasecmp (arg, "fstab")) query_format = qf_fstab; else if (!strcasecmp (arg, "mount")) query_format = qf_standard; else if (!strcasecmp (arg, "translator") || !strcasecmp (arg, "showtrans")) query_format = qf_translator; else { argp_error (state, "invalid argument to --format"); return EINVAL; } break; case 'n': /* do nothing */ break; case 'f': fake = 1; break; case 'O': err = argz_create_sep (arg, ',', &test_opts, &test_opts_len); if (err) argp_failure (state, 100, ENOMEM, "%s", arg); break; case ARGP_KEY_ARG: if (mountpoint == 0) /* One arg: mountpoint */ mountpoint = arg; else if (device == 0) /* Two args: device, mountpoint */ { device = mountpoint; mountpoint = arg; } else /* More than two args. */ { argp_error (state, "too many arguments"); return EINVAL; } break; case ARGP_KEY_NO_ARGS: if (! params->do_all) { params->do_all = 1; mode = query; } break; case ARGP_KEY_END: if (params->do_all && mountpoint) { argp_error (state, "filesystem argument not allowed with --all"); return EINVAL; } if (mode == query && options_len != 0) { argp_error (state, "mount options not allowed without filesystem argument"); return EINVAL; } if (mountpoint) switch (argz_count (params->types, params->types_len)) { default: argp_error (state, "multiple types not allowed with filesystem argument"); return EINVAL; case 1: fstype = params->types; params->types = 0; params->types_len = 0; break; case 0: break; } break; default: return ARGP_ERR_UNKNOWN; } return 0; }