void InsetMathChar::htmlize(HtmlStream & ms) const { std::string entity; switch (char_) { case '<': entity = "<"; break; case '>': entity = ">"; break; case '&': entity = "&"; break; case ' ': entity = " "; break; default: break; } bool have_entity = !entity.empty(); if (ms.inText()) { if (have_entity) ms << from_ascii(entity); else ms.os().put(char_); return; } if (have_entity) { // an operator, so give some space ms << ' ' << from_ascii(entity) << ' '; return; } if (isalpha(char_) || Encodings::isMathAlpha(char_)) // we don't use MTag and ETag because we do not want the spacing ms << MTag("i") << char_type(char_) << ETag("i"); else // an operator, so give some space ms << " " << char_type(char_) << " "; }
// We have a bit of a problem here. MathML wants to know whether the // character represents an "identifier" or an "operator", and we have // no general way of telling. So we shall guess: If it's alpha or // mathalpha, then we'll treat it as an identifier, otherwise as an // operator. // Worst case: We get bad spacing, or bad italics. void InsetMathChar::mathmlize(MathStream & ms) const { std::string entity; switch (char_) { case '<': entity = "<"; break; case '>': entity = ">"; break; case '&': entity = "&"; break; case ' ': { ms << from_ascii(" "); return; } default: break; } if (ms.inText()) { if (entity.empty()) ms.os().put(char_); else ms << from_ascii(entity); return; } if (!entity.empty()) { ms << "<mo>" << from_ascii(entity) << "</mo>"; return; } char const * type = (isalpha(char_) || Encodings::isMathAlpha(char_)) ? "mi" : "mo"; // we don't use MTag and ETag because we do not want the spacing ms << "<" << type << ">" << char_type(char_) << "</" << type << ">"; }
string_constantt::string_constantt(const irep_idt &_value): exprt(ID_string_constant) { set_value(_value); type()=array_typet(); type().subtype()=char_type(); }
void nsTSubstring_CharT::StripChars( const char_type* aChars, uint32_t aOffset ) { if (aOffset >= uint32_t(mLength)) return; if (!EnsureMutable()) // XXX do this lazily? NS_RUNTIMEABORT("OOM"); // XXX(darin): this code should defer writing until necessary. char_type* to = mData + aOffset; char_type* from = mData + aOffset; char_type* end = mData + mLength; while (from < end) { char_type theChar = *from++; const char_type* test = aChars; for (; *test && *test != theChar; ++test); if (!*test) { // Not stripped, copy this char. *to++ = theChar; } } *to = char_type(0); // add the null mLength = to - mData; }
string_constantt::string_constantt(): exprt(ID_string_constant) { set_value(irep_idt()); type()=typet(ID_array); type().subtype()=char_type(); }
int main(void) { char input[10]; char letter; int result; int char_check; while(1 == 1) { (void)printf("Enter letter, or non letter to quit: "); (void)fgets(input, sizeof(input), stdin); result = sscanf(input, "%c", &letter); if (result != 1) { break; } char_check = char_type(letter); if (char_check == 1) { (void)printf("You entered a vowel.\n"); } else if (char_check == -1) { (void)printf("You entered a consonant.\n"); } else { (void)printf("You did not enter a letter. Bye!\n"); break; } } return 0; }
string16_t::string16_t( const char_type *str, std::size_t size) : pimpl_( 0) { init(); pimpl_->str_.reserve( size + 1); pimpl_->str_.assign( str, str + size); pimpl_->str_.push_back( char_type( 0)); }
void nsACString::StripChars(const char *aSet) { nsCString copy(*this); const char_type *source, *sourceEnd; copy.BeginReading(&source, &sourceEnd); char_type *dest; BeginWriting(&dest); if (!dest) return; char_type *curDest = dest; for (; source < sourceEnd; ++source) { const char *test; for (test = aSet; *test; ++test) { if (*source == char_type(*test)) break; } if (!*test) { // not stripped, copy this char *curDest = *source; ++curDest; } } SetLength(curDest - dest); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 size_t constexpr_char_traits<_CharT>::length(const char_type* __s) { size_t __len = 0; for (; !eq(*__s, char_type(0)); ++__s) ++__len; return __len; }
code_function_callt function_to_call( symbol_tablet &symbol_table, const irep_idt &id, const irep_idt &argument) { // already there? symbol_tablet::symbolst::const_iterator s_it= symbol_table.symbols.find(id); if(s_it==symbol_table.symbols.end()) { // not there pointer_typet p(char_type()); p.subtype().set(ID_C_constant, true); code_typet function_type; function_type.return_type()=empty_typet(); function_type.parameters().push_back( code_typet::parametert(p)); symbolt new_symbol; new_symbol.name=id; new_symbol.base_name=id; new_symbol.type=function_type; symbol_table.move(new_symbol); s_it=symbol_table.symbols.find(id); assert(s_it!=symbol_table.symbols.end()); } // signature is expected to be // (type *) -> ... if(s_it->second.type.id()!=ID_code || to_code_type(s_it->second.type).parameters().size()!=1 || to_code_type(s_it->second.type).parameters()[0].type().id()!=ID_pointer) { std::string error="function `"+id2string(id)+"' has wrong signature"; throw error; } string_constantt function_id_string(argument); code_function_callt call; call.lhs().make_nil(); call.function()= symbol_exprt(s_it->second.name, s_it->second.type); call.arguments().resize(1); call.arguments()[0]= typecast_exprt( address_of_exprt( index_exprt( function_id_string, from_integer(0, index_type()))), to_code_type(s_it->second.type).parameters()[0].type()); return call; }
main() { char ch; /* get a character from the keyboard */ printf(" Please enter a charcater => "); ch = getc(stdin); char_type(ch); /* Figure out the character type */ }
void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const { frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); dim.asc = fm.maxAscent(); dim.des = 0; dim.wid = 0; docstring s; switch (kind_) { case ALLOWBREAK: dim.asc = fm.xHeight(); dim.des = fm.descent('g'); dim.wid = fm.em() / 8; break; case LIGATURE_BREAK: s = from_ascii("|"); break; case END_OF_SENTENCE: s = from_ascii("."); break; case LDOTS: s = from_ascii(". . ."); break; case MENU_SEPARATOR: // â–¹ U+25B9 WHITE RIGHT-POINTING SMALL TRIANGLE // There is a \thinspace on each side of the triangle dim.wid = 2 * fm.em() / 6 + fm.width(char_type(0x25B9)); break; case HYPHENATION: dim.wid = fm.width(from_ascii("-")); if (dim.wid > 5) dim.wid -= 2; // to make it look shorter break; case SLASH: s = from_ascii("/"); dim.des = fm.descent(s[0]); break; case NOBREAKDASH: s = from_ascii("-"); break; case PHRASE_LYX: case PHRASE_TEX: case PHRASE_LATEX2E: case PHRASE_LATEX: dim.asc = fm.maxAscent(); dim.des = fm.maxDescent(); frontend::NullPainter np; PainterInfo pi(mi.base.bv, np); pi.base.font = mi.base.font; drawLogo(pi, dim.wid, 0, kind_); break; } if (dim.wid == 0) dim.wid = fm.width(s); }
hdf5_oprimitive::write_hdf5_dataset ( signed char const* t, std::size_t data_count, std::size_t object_number ) { hdf5_datatype char_type(H5T_NATIVE_SCHAR); write_dataset_basic(t, data_count, char_type, object_number); }
void make_expr_1( MethodWriter &mw, const String &op ) { // resulting type String op_type; op_type << "Op_" << op << '_' << char_type( mw.get_type( 0 )->constructor ); mw.add_type_decl( op_type ); // default behavior -> op( a, b, ... ) mw.n << "Type *type = &metil_type_bas_" << op_type << ";"; mw.ret() << "MO( NEW( Owcp<1>, type, " << mw.arg[ 0 ] << " ), type );"; }
hdf5_iprimitive::read_hdf5_dataset ( signed char* t, std::size_t data_count, std::size_t object_number ) { hdf5_datatype char_type(H5T_NATIVE_SCHAR); read_dataset_basic(t, data_count, char_type, object_number); }
void string16_t::push_back( char_type c) { assert( pimpl_); if( !pimpl_->str_.empty()) pimpl_->str_.pop_back(); pimpl_->str_.push_back( c); pimpl_->str_.push_back( char_type( 0)); }
BOOST_ARCHIVE_OR_WARCHIVE_DECL void hdf5_oprimitive::write_hdf5_dataset ( unsigned char const* t, std::size_t data_count, std::size_t object_number ) { hdf5_datatype char_type(H5T_NATIVE_UCHAR); write_dataset_basic(t, data_count, char_type, object_number); }
bool nsTSubstring_CharT::ReplacePrepInternal(index_type cutStart, size_type cutLen, size_type fragLen, size_type newLen) { char_type* oldData; uint32_t oldFlags; if (!MutatePrep(newLen, &oldData, &oldFlags)) return false; // out-of-memory if (oldData) { // determine whether or not we need to copy part of the old string // over to the new string. if (cutStart > 0) { // copy prefix from old string char_traits::copy(mData, oldData, cutStart); } if (cutStart + cutLen < mLength) { // copy suffix from old string to new offset size_type from = cutStart + cutLen; size_type fromLen = mLength - from; uint32_t to = cutStart + fragLen; char_traits::copy(mData + to, oldData + from, fromLen); } ::ReleaseData(oldData, oldFlags); } else { // original data remains intact // determine whether or not we need to move part of the existing string // to make room for the requested hole. if (fragLen != cutLen && cutStart + cutLen < mLength) { uint32_t from = cutStart + cutLen; uint32_t fromLen = mLength - from; uint32_t to = cutStart + fragLen; char_traits::move(mData + to, mData + from, fromLen); } } // add null terminator (mutable mData always has room for the null- // terminator). mData[newLen] = char_type(0); mLength = newLen; return true; }
PRBool nsTSubstring_CharT::SetCapacity( size_type capacity ) { // capacity does not include room for the terminating null char // if our capacity is reduced to zero, then free our buffer. if (capacity == 0) { ::ReleaseData(mData, mFlags); mData = char_traits::sEmptyBuffer; mLength = 0; SetDataFlags(F_TERMINATED); } else { char_type* oldData; PRUint32 oldFlags; if (!MutatePrep(capacity, &oldData, &oldFlags)) return PR_FALSE; // out-of-memory // compute new string length size_type newLen = NS_MIN(mLength, capacity); if (oldData) { // preserve old data if (mLength > 0) char_traits::copy(mData, oldData, newLen); ::ReleaseData(oldData, oldFlags); } // adjust mLength if our buffer shrunk down in size if (newLen < mLength) mLength = newLen; // always null-terminate here, even if the buffer got longer. this is // for backwards compat with the old string implementation. mData[capacity] = char_type(0); } return PR_TRUE; }
void nsTSubstring_CharT::StripChar( char_type aChar, PRInt32 aOffset ) { if (mLength == 0 || aOffset >= PRInt32(mLength)) return; EnsureMutable(); // XXX do this lazily? // XXX(darin): this code should defer writing until necessary. char_type* to = mData + aOffset; char_type* from = mData + aOffset; char_type* end = mData + mLength; while (from < end) { char_type theChar = *from++; if (aChar != theChar) *to++ = theChar; } *to = char_type(0); // add the null mLength = to - mData; }
void message::decorate_message(const string_type& decoration, const string_type& in_message, string_type& out_message) const { ostream_type predecorated_message; ostream_type decorated_message; scm::size_t decoration_indent = decoration.size(); stream_type raw_msg_stream(in_message); string_type raw_msg_line; bool indent_decoration = false; scm::size_t log_indention_width = sending_logger().indent_level() * sending_logger().indent_width(); while (std::getline(raw_msg_stream, raw_msg_line)) { if ( (0 < decoration_indent) && indent_decoration && !raw_msg_line.empty()) { std::fill_n(std::ostreambuf_iterator<char_type>(predecorated_message.rdbuf()), decoration_indent, char_type(' ')); } if ( (0 < log_indention_width) && !raw_msg_line.empty()) { std::fill_n(std::ostreambuf_iterator<char_type>(predecorated_message.rdbuf()), log_indention_width, sending_logger().indent_fill_char()); } predecorated_message << raw_msg_line << std::endl; indent_decoration = true; } _postdec_message = predecorated_message.str(); decorated_message << decoration << predecorated_message.str(); decorated_message.str().swap(out_message); //out_message.swap(decorated_message.str()); }
void make_expr_2( MethodWriter &mw, const String &op ) { if ( op == "add" and make_expr_add( mw ) ) return; if ( op == "mul" and make_expr_mul( mw ) ) return; // op( cst, number ) or op( number, cst ) // TypeConstructor_Cst *cst_0 = dynamic_cast<TypeConstructor_Cst *>( t_0->constructor ); // TypeConstructor_Cst *cst_1 = dynamic_cast<TypeConstructor_Cst *>( t_1->constructor ); // if ( cst_0 ) { // if ( cst_1 ) { // SI64 ia, ib; // bool ca = cst_0->conversion_to( ia ); // bool cb = cst_1->conversion_to( ib ); // if ( ca and cb ) { // Val res = make_op( ia, ib, "mul" ); // mw.ret() << "NEW_Number( " << res << " );"; // mw.ret(); // return true; // } // } else { // } // } else if ( cst_1 ) { // } // resulting type String op_type; op_type << "Op_" << op << '_' << char_type( mw.get_type( 0 )->constructor ) << '_' << char_type( mw.get_type( 1 )->constructor ); mw.add_type_decl( op_type ); // default behavior -> op( a, b, ... ) mw.n << "Type *type = &metil_type_bas_" << op_type << ";"; mw.ret() << "MO( NEW( Owcp<2>, type, " << mw.arg[ 0 ] << ", " << mw.arg[ 1 ] << " ), type );"; }
/* read the next token */ static int tok_read(void) { char *s = tok; char *e = tok + sizeof(tok) - 2; int c, c2; int i; *s = '\0'; c = tok_next(); if (c <= 0) return 1; tok_prevsep = tok_cursep; tok_cursep = def_chopped(c); if (tok_cursep) tok_prevsep = 1; if (c == ' ' || c == '\n') { while (c > 0 && (c == ' ' || c == '\n')) c = tok_next(); tok_back(c); *s++ = ' '; *s = '\0'; tok_curtype = T_SPACE; return 0; } if (c == '\t') { *s++ = '\t'; *s = '\0'; tok_curtype = T_TAB; return 0; } if (tok_prevsep) { if (c == '$') { c2 = tok_next(); if (c2 >= '1' && c2 <= '9' && !src_arg(c2 - '0')) { tok_cursep = 1; return tok_read(); } tok_back(c2); } tok_back(c); if (!tok_keyword()) { tok_curtype = T_KEYWORD; tok_cursep = 1; return 0; } if (!tok_expand()) { tok_cursep = 1; return tok_read(); } c = tok_next(); } if (strchr(T_SOFTSEP, c)) { *s++ = c; if (c == '\\') { c = tok_next(); if (c == '(') { *s++ = c; *s++ = tok_next(); *s++ = tok_next(); } else if (c == '[') { while (c && c != ']') { if (s < e) *s++ = c; c = tok_next(); } *s++ = ']'; } } else if (c == '"') { c = tok_next(); while (c > 0 && c != '"') { if (c == '\\') { c2 = tok_next(); if (c2 == '"') c = '"'; else tok_back(c2); } if (s < e) *s++ = c; c = tok_next(); } *s++ = '"'; } else { /* two-character operators */ c2 = tok_next(); switch (T_BIN(c, c2)) { case T_BIN('<', '='): case T_BIN('>', '='): case T_BIN('=', '='): case T_BIN('!', '='): case T_BIN('>', '>'): case T_BIN('<', '<'): case T_BIN(':', '='): case T_BIN('-', '>'): case T_BIN('<', '-'): case T_BIN('-', '+'): *s++ = c2; break; default: tok_back(c2); } } *s = '\0'; tok_curtype = char_type(tok); return 0; } *s++ = c; i = utf8len(c); while (--i > 0 && s < e) *s++ = tok_next(); *s = '\0'; tok_curtype = char_type(tok); return 0; }
exprt c_typecheck_baset::do_initializer_list( const exprt &value, const typet &type, bool force_constant) { assert(value.id()==ID_initializer_list); const typet &full_type=follow(type); exprt result; if(full_type.id()==ID_struct || full_type.id()==ID_union || full_type.id()==ID_vector) { // start with zero everywhere result= zero_initializer( type, value.source_location(), *this, get_message_handler()); } else if(full_type.id()==ID_array) { if(to_array_type(full_type).size().is_nil()) { // start with empty array result=exprt(ID_array, full_type); result.add_source_location()=value.source_location(); } else { // start with zero everywhere result= zero_initializer( type, value.source_location(), *this, get_message_handler()); } // 6.7.9, 14: An array of character type may be initialized by a character // string literal or UTF-8 string literal, optionally enclosed in braces. if(value.operands().size()>=1 && value.op0().id()==ID_string_constant && (full_type.subtype().id()==ID_signedbv || full_type.subtype().id()==ID_unsignedbv) && full_type.subtype().get(ID_width)==char_type().get(ID_width)) { if(value.operands().size()>1) { warning().source_location=value.find_source_location(); warning() << "ignoring excess initializers" << eom; } return do_initializer_rec(value.op0(), type, force_constant); } } else { // The initializer for a scalar shall be a single expression, // * optionally enclosed in braces. * if(value.operands().size()==1) return do_initializer_rec(value.op0(), type, force_constant); err_location(value); error() << "cannot initialize `" << to_string(full_type) << "' with an initializer list" << eom; throw 0; } designatort current_designator; designator_enter(type, current_designator); forall_operands(it, value) { do_designated_initializer( result, current_designator, *it, force_constant); // increase designator -- might go up increment_designator(current_designator); }
exprt c_typecheck_baset::do_initializer_rec( const exprt &value, const typet &type, bool force_constant) { const typet &full_type=follow(type); if(full_type.id()==ID_incomplete_struct) { err_location(value); error() << "type `" << to_string(full_type) << "' is still incomplete -- cannot initialize" << eom; throw 0; } if(value.id()==ID_initializer_list) return do_initializer_list(value, type, force_constant); if(value.id()==ID_array && value.get_bool(ID_C_string_constant) && full_type.id()==ID_array && (full_type.subtype().id()==ID_signedbv || full_type.subtype().id()==ID_unsignedbv) && full_type.subtype().get(ID_width)==value.type().subtype().get(ID_width)) { exprt tmp=value; // adjust char type tmp.type().subtype()=full_type.subtype(); Forall_operands(it, tmp) it->type()=full_type.subtype(); if(full_type.id()==ID_array && to_array_type(full_type).is_complete()) { // check size mp_integer array_size; if(to_integer(to_array_type(full_type).size(), array_size)) { err_location(value); error() << "array size needs to be constant, got " << to_string(to_array_type(full_type).size()) << eom; throw 0; } if(array_size<0) { err_location(value); error() << "array size must not be negative" << eom; throw 0; } if(mp_integer(tmp.operands().size())>array_size) { // cut off long strings. gcc does a warning for this tmp.operands().resize(integer2size_t(array_size)); tmp.type()=type; } else if(mp_integer(tmp.operands().size())<array_size) { // fill up tmp.type()=type; exprt zero= zero_initializer( full_type.subtype(), value.source_location(), *this, get_message_handler()); tmp.operands().resize(integer2size_t(array_size), zero); } } return tmp; } if(value.id()==ID_string_constant && full_type.id()==ID_array && (full_type.subtype().id()==ID_signedbv || full_type.subtype().id()==ID_unsignedbv) && full_type.subtype().get(ID_width)==char_type().get(ID_width)) { // will go away, to be replaced by the above block string_constantt tmp1=to_string_constant(value); // adjust char type tmp1.type().subtype()=full_type.subtype(); exprt tmp2=tmp1.to_array_expr(); if(full_type.id()==ID_array && to_array_type(full_type).is_complete()) { // check size mp_integer array_size; if(to_integer(to_array_type(full_type).size(), array_size)) { err_location(value); error() << "array size needs to be constant, got " << to_string(to_array_type(full_type).size()) << eom; throw 0; } if(array_size<0) { err_location(value); error() << "array size must not be negative" << eom; throw 0; } if(mp_integer(tmp2.operands().size())>array_size) { // cut off long strings. gcc does a warning for this tmp2.operands().resize(integer2size_t(array_size)); tmp2.type()=type; } else if(mp_integer(tmp2.operands().size())<array_size) { // fill up tmp2.type()=type; exprt zero= zero_initializer( full_type.subtype(), value.source_location(), *this, get_message_handler()); tmp2.operands().resize(integer2size_t(array_size), zero); } } return tmp2; } if(full_type.id()==ID_array && to_array_type(full_type).size().is_nil()) { err_location(value); error() << "type `" << to_string(full_type) << "' cannot be initialized with `" << to_string(value) << "'" << eom; throw 0; } if(value.id()==ID_designated_initializer) { err_location(value); error() << "type `" << to_string(full_type) << "' cannot be initialized with designated initializer" << eom; throw 0; } exprt result=value; implicit_typecast(result, type); return result; }
int main(void) { int i; // char *ppp; /************************ initializations ****************************/ /* set up file mapped shared memory for inter process communication */ ipc_sem_init(); // setup semaphores semid = ipc_sem_id(skey); // set semaphor id /* set up shared memory */ ipc_sem_lock(semid, &sb); // wait for a lock on shared memory fd = ipc_open(ipc_file, ipc_size()); // create/open ipc file data = ipc_map(fd, ipc_size()); // map file to memory ipc_ptr = data; // overlay data with _IPC_DAT data structure ipc_sem_free(semid, &sb); // free lock on shared memory /* setup control block pointers */ cmd_fsm_cb.ipc_ptr = ipc_ptr; // set pointer to shared memory cmd_fsm_cb.sys_ptr = &(ipc_ptr->sys_data); // set pointer to system data in shared memory cmd_fsm_cb.ssch_ptr = &ipc_ptr->sys_data.sys_sch; // set pointer to active shecule in shared memory cmd_fsm_cb.wsch_ptr = &cmd_fsm_cb.w_sch; // set pointer to working schedule /* check system versions */ if (sys_comp(&(ipc_ptr->sys_data.config))) { printf("*** the system configuration in shared memory and in the application are different\n update shared memory? (y)|(n) > "); if (getchar() == 'y') { ipc_ptr->sys_data.config.major_version = _MAJOR_VERSION_system; ipc_ptr->sys_data.config.minor_version = _MINOR_VERSION_system; ipc_ptr->sys_data.config.minor_revision = _MINOR_REVISION_system; ipc_ptr->sys_data.config.channels = _NUMBER_OF_CHANNELS; ipc_ptr->sys_data.config.sensors = _NUMBER_OF_SENSORS; ipc_ptr->sys_data.config.commands = _CMD_TOKENS; ipc_ptr->sys_data.config.states = _CMD_STATES; c = fgetc(stdin); // get rid of trailing CR } else { c = fgetc(stdin); // get rid of trailing CR printf("*** application terminated\n"); exit(1); } } /* load working schedule from system schedule */ ipc_sem_lock(semid, &sb); // wait for a lock on shared memory cmd_fsm_cb.w_sch = ipc_ptr->sys_data.sys_sch; ipc_sem_free(semid, &sb); // free lock on shared memory /* initialize working sensor name and description */ cmd_fsm_cb.w_sen_dat.group[0] = '\0'; cmd_fsm_cb.w_sen_dat.description[0] = '\0'; cmd_fsm_cb.w_sen_dat.description[1] = '\0'; /* initialize state machines */ cmd_fsm_reset(&cmd_fsm_cb); // initialize the command processor fsm char_fsm_reset(); // initialize the character fsm char_state = 0; /* initialize input buffer */ memset(work_buffer, '\0', sizeof(work_buffer)); work_buffer_ptr = work_buffer; start_buff = work_buffer; input_ptr = work_buffer; end_buff = (char *)((int)start_buff + _INPUT_BUFFER_SIZE); escape = false; /* initialize ring buffer & indexs*/ for (i = 0; i < _CMD_BUFFER_DEPTH; i++) memset(&ring_buffer[i][0], '\0', _INPUT_BUFFER_SIZE); rb_in_idx = 0; rb_out_idx = 0; /* set up unbuffered io */ fflush(stdout); system("stty -echo"); //turn off terminal echo system("/bin/stty raw"); // use system call to make terminal send all keystrokes directly to stdin int flags = fcntl(STDOUT_FILENO, F_GETFL); fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK); escape = false; /* initialize user interface */ printf("Pcon %d.%d.%d starting\n\r", _MAJOR_VERSION_Pcon, _MINOR_VERSION_Pcon, _MINOR_REVISION_Pcon); printf("\nSystem configuration\r\n"); printf(" Git tag - %s\r\n", _TAG); printf(" Inter Process Commucination support %d.%d.%d\n\r", _MAJOR_VERSION_ipc, _MINOR_VERSION_ipc, _MINOR_REVISION_ipc); printf(" Dcon version %d.%d.%d\n\r", _MAJOR_VERSION_Dcon, _MINOR_VERSION_Dcon, _MINOR_REVISION_Dcon); printf(" Scon version %d.%d.%d\n\r", _MAJOR_VERSION_Scon, _MINOR_VERSION_Scon, _MINOR_REVISION_Scon); printf(" Pcon version %d.%d.%d\n\r", _MAJOR_VERSION_Pcon, _MINOR_VERSION_Pcon, _MINOR_REVISION_Pcon); printf(" char_fsm version %d.%d.%d\n\r", _MAJOR_VERSION_char_fsm, _MINOR_VERSION_char_fsm, _MINOR_REVISION_char_fsm); printf(" cmd_fsm version %d.%d.%d\n\n\r", _MAJOR_VERSION_cmd_fsm, _MINOR_VERSION_cmd_fsm, _MINOR_REVISION_cmd_fsm); printf("initializations complete\r\n\nenter ? for a list of commands\r\n\n"); /* set initial prompt */ strcpy(cmd_fsm_cb.prompt_buffer, "Pcon enter a command"); /************************************************************/ /**************** start main processing loop ****************/ /************************************************************/ while (1) { while (pop_cmd_q(cmd_fsm_cb.token)) // check the token queue { cmd_fsm(&cmd_fsm_cb); // cycle cmd fsm until queue is empty prompted = false; } if (prompted == false) // display prompt if necessary { prompted = true; prompt(cmd_fsm_cb.state); } c = fgetc(stdin); // read the keyboard switch (c) { /* NOCR */ case _NO_CHAR: break; /* ESC */ case _ESC: c = fgetc(stdin); // skip to next character c = fgetc(stdin); // skip to next character switch (c) { /* up arrow */ case 'A': if (rb_out_idx > 0) rb_out_idx--; else rb_out_idx = rb_in_idx - 1; if (rb_out_idx >= rb_in_idx) rb_out_idx = 0; arrow_reprompt(); continue; break; /* down arrow */case 'B': rb_out_idx++; if (rb_out_idx >= rb_in_idx) rb_out_idx = 0; arrow_reprompt(); continue; break; /* right arrow */case 'C': if (input_ptr < work_buffer_ptr) { input_ptr++; printf("\033[1C"); // move cursor right } continue; break; /* left arrow */case 'D': if (input_ptr > start_buff) { input_ptr--; printf("\033[1D"); // move cursor left } continue; break; /* ESC */ default: escape = true; while (pop_cmd_q(cmd_fsm_cb.token)); // empty command queue memset(work_buffer, '\0', sizeof(work_buffer)); // clean out work buffer memset(previous_work_buffer, '\0', sizeof(work_buffer)); // clean out previous command buffer work_buffer_ptr = work_buffer; // set pointer to start of buffer input_ptr = work_buffer; // set pointer to start of buffer char_fsm_reset(); // initialize the character fsm cmd_fsm_reset(&cmd_fsm_cb); // initialize the command processor fsm char_state = 0; prompted = false; // force a prompt printf("\n\rcommand processor reset\n\r"); strcpy(cmd_fsm_cb.prompt_buffer, "enter a command"); continue; break; } /* CR */ case _CR: if (work_buffer_ptr != start_buff) // skip null input lines { if (strcmp(work_buffer, previous_work_buffer) != 0) // remove duplicates { strcpy(&ring_buffer[rb_in_idx++][0], work_buffer); if (rb_in_idx > _CMD_BUFFER_DEPTH - 1) rb_in_idx = 0; rb_out_idx = rb_in_idx; memset(previous_work_buffer, '\0', sizeof(work_buffer)); strcpy(previous_work_buffer, work_buffer); } } printf("\n\r"); // move cursor to next line *work_buffer_ptr++ = _CR; // load the CR into the work buffer *work_buffer_ptr++ = '\0'; // load the NULL into the work buffer work_buffer_ptr = work_buffer; // reset pointer char_fsm_reset(); // reset char_fsm while (*work_buffer_ptr != '\0') // send characters to char_fsm { char_fsm(char_type(*work_buffer_ptr), &char_state, work_buffer_ptr); work_buffer_ptr++; } work_buffer_ptr = work_buffer; // reset pointer input_ptr = work_buffer_ptr; // reset pointer memset(work_buffer, '\0', sizeof(work_buffer)); memset(screen_buf, '\0', sizeof(screen_buf)); memset(&ring_buffer[rb_in_idx][0], '\0', _INPUT_BUFFER_SIZE); break; /* DEL */ case _DEL: if (input_ptr == start_buff) break; if (input_ptr == work_buffer_ptr) { // no arrow keys in play *work_buffer_ptr-- = '\0'; *work_buffer_ptr = '\0'; input_ptr = work_buffer_ptr; printf("\r"); del_prompt(cmd_fsm_cb.state); // display user prompt printf("%s", work_buffer); // print work_buffer printf("\033[K"); // Erase to end of line prompted = true; } else { mv = work_buffer_ptr - input_ptr; input_ptr--; hptr = input_ptr; while (input_ptr < work_buffer_ptr) // shift buffer left { *input_ptr = *(input_ptr + 1); input_ptr++; } input_ptr = hptr; *work_buffer_ptr-- = '\0'; *work_buffer_ptr = '\0'; printf("\r"); printf("\033[K"); // Erase to end of line del_prompt(cmd_fsm_cb.state); printf("%s", work_buffer); while (mv > 0) { printf("\033[1D"); // move cursor left mv--; } } break; /* OTHER */ default: if (work_buffer_ptr <= end_buff) // room to add character ? { if (input_ptr == work_buffer_ptr) // cursor is at the end of the input buffer { *work_buffer_ptr++ = c; input_ptr = work_buffer_ptr; printf("%c", c); } else // cursor is not at the end of the input buffer { move_ptr = work_buffer_ptr++; move_ptr++; *move_ptr-- = '\0'; while (move_ptr > input_ptr) { *move_ptr = *(move_ptr - 1); move_ptr--; } *input_ptr++ = c; mv = work_buffer_ptr - input_ptr; printf("\r"); printf("\033[K"); // Erase to end of line prompt(cmd_fsm_cb.state); printf("%s", work_buffer); while (mv > 0) { printf("\033[1D"); // move cursor left mv--; } } } } /* do suff while waiting or the keyboard */ } system("/bin/stty cooked"); //switch to buffered iput system("/bin/stty echo"); //turn on terminal echo printf("\f\n***normal termination - but should not happen\n\n"); return 0; }
bool XQ::set_fen(string const &fen) { clear(); uint idx = 0UL, len = (uint)fen.size(); uint y = 9UL, x = 0UL; while (idx < len) { sint32 c = fen[idx++]; uint32 type = char_type(c); if (type != InvaildPiece) { if (y >= 10UL || x >= 9UL) { //error clear(); return false; } uint32 begin = type_begin(type); uint32 end = type_end(type); while (end >= begin) { if (piece(begin) == InvaildCoordinate) { break; } ++begin; } if (begin > end) { //error clear(); return false; } uint32 sq = xy_coordinate(x++, y); m_coordinates[sq] = static_cast<uint8>(begin); m_pieces[begin] = static_cast<uint8>(sq); } else if (c == ' ') { if (y || x != 9UL || (idx == len)) { //error clear(); return false; } c = fen[idx]; m_player = ((c == 'b') ? Black : Red); for (int i = 0; i < 32; i++) { uint32 sq = piece(i); if (sq != InvaildCoordinate) { if (!(coordinate_flag(sq) & piece_flag(i))) { //error clear(); return false; } m_bitmap.setbit(sq); } } //ok return true; } else if (c == '/') { if (!y || x != 9UL) { //error clear(); return false; } --y; x = 0UL; } else if (c >= '1' && c <= '9') { x += c - '0'; } else { //error clear(); return false; } } //error clear(); return false; }
bool is_alnum(int c) const { return char_type(c) & (TOK_ALPHA | TOK_NUMERIC); }
bool is_num(int c) const { return char_type(c) & TOK_NUMERIC; }
bool is_space(int c) const { return char_type(c) & TOK_SPACE; }