/* * Given a pointer to a LINE's text where we have a "nonprinting" character, * and the limit on remaining chars to display, return the number of columns * which are needed to display it, e.g., in hex or octal. As a side-effect, * set the *used parameter to the number of chars needed for a multibyte * character if we have one. */ int column_sizes(WINDOW *wp, const char *text, unsigned limit, int *used) { int rc = NonPrintingCols(*text); *used = 1; #if OPT_MULTIBYTE if (b_is_utfXX(wp->w_bufp)) { *used = vl_conv_to_utf32((UINT *) 0, text, (B_COUNT) limit); if (*used > 1) { rc = COLS_UTF8; /* "\uXXXX" */ } else if (*used < 1) { *used = 1; /* probably a broken character... */ } else if (isPrint(*text)) { rc = 1; } } else #else (void) wp; (void) limit; #endif if (isPrint(*text)) { rc = 1; } return rc; }
void parseFun(char *buf,table_t *table,FILE *file) { //做你们该做的 if(forBegin == true){ //在for循环中 char printContent[256]; if(isPrint(printContent,buf) == true){ printf("In for, print content is %s\n",printContent); }else if(isForEnd(buf) == true){ forBegin = false; printf("For is end\n"); } }else{ //没有进入for循环 if(isVariableDef(buf) == true){ doVariableParse(buf); }else{ if(isForBeg(buf) == true){ doFroParse(buf); forBegin = true; }else{ //这种情况在你们的输入中不存在 printf("I can not parse other condition\n"); } } } }
/* * Return the next column index, given the current char and column. */ int next_column(LINE *lp, int off, int col) { int rc = 1; int c; if (off < llength(lp)) { c = lgetc(lp, off); if (c == '\t') { rc = next_tabcol(col) - col; } #if OPT_MULTIBYTE else if (b_is_utfXX(curbp)) { if (bytes_at(lp, off) > 1) { rc = mb_cellwidth(curwp, lvalue(lp) + off, llength(lp) - off); } } #endif else if (!isPrint(c)) { rc = NonPrintingCols(c); } } else { rc = 0; } return col + rc; }
void PrimeSieve::doSmallPrime(const SmallPrime& sp) { if (sp.firstPrime >= start_ && sp.lastPrime <= stop_) { // callback prime numbers if (sp.index == 0) { if (isFlag(CALLBACK_PRIMES_OBJ)) cb_->callback(sp.firstPrime); if (isFlag(CALLBACK_PRIMES_OBJ_TN)) cb_tn_->callback(sp.firstPrime, threadNum_); if (isFlag(CALLBACK_PRIMES)) callback_(sp.firstPrime); if (isFlag(CALLBACK_PRIMES_TN)) callback_tn_(sp.firstPrime, threadNum_); if (isFlag(CALLBACK_PRIMES_C)) reinterpret_cast<callback_c_t>(callback_)(sp.firstPrime); if (isFlag(CALLBACK_PRIMES_C_TN)) reinterpret_cast<callback_c_tn_t>(callback_tn_)(sp.firstPrime, threadNum_); } if (isCount(sp.index)) counts_[sp.index]++; if (isPrint(sp.index)) std::cout << sp.str << '\n'; } }
bool KCharSelectData::isDisplayable(CharSelectData* charselect, uint16_t unicode) { // Qt internally uses U+FDD0 and U+FDD1 to mark the beginning and the end of frames. // They should be seen as non-printable characters, as trying to display them leads // to a crash caused by a Qt "noBlockInString" assertion. if(c == 0xFDD0 || c == 0xFDD1) return false; return !isIgnorable(c) && isPrint(c); }
int mb_cellwidth(WINDOW *wp, const char *text, int limit) { UINT value; int rc = COLS_UTF8; /* "\uXXXX" */ vl_conv_to_utf32(&value, text, (B_COUNT) limit); if (isPrint(value) && FoldTo8bits((int) value)) { rc = 1; if (w_val(wp, WMDUNICODE_AS_HEX)) { rc = COLS_UTF8; } else if (!isPrint(value)) { rc = COLS_8BIT; } } else if (term_is_utfXX()) { rc = vl_wcwidth((int) value); if (rc <= 0) rc = COLS_UTF8; } return rc; }
/* * Given a char to add, and the current column, return the next column index, */ int column_after(int c, int col, int list) { int rc = (col + 1); if (!list && (c == '\t')) { rc = next_tabcol(col); } #if OPT_MULTIBYTE else if (b_is_utfXX(curbp)) { if (vl_conv_to_utf8((UCHAR *) 0, (UINT) c, (B_COUNT) 10) > 1) rc = col + COLS_UTF8; /* "\uXXXX" */ } #endif else if (!isPrint(c)) { rc = col + NonPrintingCols(c); } return rc; }
static void filtered_fwrite(FILE *f, const char *buf, int len, int use_isprint) { const char *s, *end = buf + len; for (s = buf; s < end; s++) { if ((s < end - 4 && *s == '\\' && s[1] == '#' && isDigit(s + 2) && isDigit(s + 3) && isDigit(s + 4)) || (*s != '\t' && ((use_isprint && !isPrint(s)) || *(uchar*)s < ' '))) { if (s != buf && fwrite(buf, s - buf, 1, f) != 1) exit_cleanup(RERR_MESSAGEIO); fprintf(f, "\\#%03o", *(uchar*)s); buf = s + 1; } } if (buf != end && fwrite(buf, end - buf, 1, f) != 1) exit_cleanup(RERR_MESSAGEIO); }
static Statement *statement(void) { if (isId()) { Statement *p = NEW(Statement); p->kind = sAssignment; p->assignName = getId(); consume(); if (!isEq()) error(); consume(); p->assignValue = expression(); if (isSemi()) { consume(); } return p; } else if (isReturn()) { Statement *p = NEW(Statement); p->kind = sReturn; consume(); p->returnValue = expression(); if (isSemi()) { consume(); } return p; } else if (isLeftBlock()) { Statement *p = NEW(Statement); p->kind = sBlock; consume(); p->block = block(); if (!isRightBlock()) error(); consume(); return p; } else if (isPrint()) { Statement *p = NEW(Statement); p->kind = sPrint; consume(); p->printValue = expression(); if (isSemi()) { consume(); } return p; } else if (isIf()) { Statement *p = NEW(Statement); p->kind = sIf; consume(); p->ifCondition = expression(); p->ifThen = statement(); if (isElse()) { consume(); p->ifElse = statement(); } else { p->ifElse = 0; } return p; } else if (isWhile()) { Statement *p = NEW(Statement); p->kind = sWhile; consume(); /* while */ p->whileCondition = expression(); p->whileBody = statement(); return p; } else if (isSemi()) { Statement *p = NEW(Statement); p->kind = sBlock; p->block = 0; consume(); return p; } else { return 0; } }
/* also called later, if charset-affecting modes change, for instance */ void vl_ctype_init(int print_lo, int print_hi) { #if OPT_LOCALE char *save_ctype = setlocale(LC_CTYPE, NULL); #endif int c; TRACE((T_CALLED "vl_ctype_init() lo=%d, hi=%d\n", print_lo, print_hi)); /* If we're using the locale functions, set our flags based on its * tables. Note that just because you have 'setlocale()' doesn't mean * that the tables are present or correct. But this is a start. * * NOTE: Solaris8 and some versions of M$ incorrectly classify tab as a * printable character (ANSI C says control characters are not printable). * Ignore that (the former fixes it in Solaris9). */ #if OPT_LOCALE TRACE(("wide_locale:%s\n", NonNull(vl_wide_enc.locale))); TRACE(("narrow_locale:%s\n", NonNull(vl_narrow_enc.locale))); TRACE(("current_locale:%s\n", NonNull(save_ctype))); if (vl_narrow_enc.locale) setlocale(LC_CTYPE, vl_narrow_enc.locale); else if (vl_wide_enc.locale) setlocale(LC_CTYPE, vl_wide_enc.locale); for (c = 0; c < N_chars; c++) { if (print_hi > 0 && c > print_hi) { vlCTYPE(c) = 0; } else if (okCTYPE2(vl_narrow_enc)) { vlCTYPE(c) = vl_ctype_bits(c, -TRUE); vl_uppercase[c] = (char) toupper(c); vl_lowercase[c] = (char) tolower(c); } else { /* fallback to built-in character tables */ if (okCTYPE2(vl_wide_enc)) { vlCTYPE(c) = vl_ctype_latin1[c]; } else { vlCTYPE(c) = vl_ctype_ascii[c]; } vl_uppercase[c] = (char) c; vl_lowercase[c] = (char) c; if (isAlpha(c)) { if (isUpper(c)) { vl_lowercase[c] = (char) (c ^ DIFCASE); } else { vl_uppercase[c] = (char) (c ^ DIFCASE); } } } } #else /* ! OPT_LOCALE */ (void) memset((char *) vl_chartypes_, 0, sizeof(vl_chartypes_)); /* control characters */ for (c = 0; c < ' '; c++) vlCTYPE(c) |= vl_cntrl; vlCTYPE(127) |= vl_cntrl; /* lowercase */ for (c = 'a'; c <= 'z'; c++) vlCTYPE(c) |= vl_lower; #if OPT_ISO_8859 for (c = 0xc0; c <= 0xd6; c++) vlCTYPE(c) |= vl_lower; for (c = 0xd8; c <= 0xde; c++) vlCTYPE(c) |= vl_lower; #endif /* uppercase */ for (c = 'A'; c <= 'Z'; c++) vlCTYPE(c) |= vl_upper; #if OPT_ISO_8859 for (c = 0xdf; c <= 0xf6; c++) vlCTYPE(c) |= vl_upper; for (c = 0xf8; c <= 0xff; c++) vlCTYPE(c) |= vl_upper; #endif /* * If you want to do this properly, compile-in locale support. */ for (c = 0; c < N_chars; c++) { vl_uppercase[c] = (char) c; vl_lowercase[c] = (char) c; if (isAlpha(c)) { if (isUpper(c)) { vl_lowercase[c] = (char) (c ^ DIFCASE); } else { vl_uppercase[c] = (char) (c ^ DIFCASE); } } } /* digits */ for (c = '0'; c <= '9'; c++) vlCTYPE(c) |= vl_digit; #ifdef vl_xdigit /* hex digits */ for (c = '0'; c <= '9'; c++) vlCTYPE(c) |= vl_xdigit; for (c = 'a'; c <= 'f'; c++) vlCTYPE(c) |= vl_xdigit; for (c = 'A'; c <= 'F'; c++) vlCTYPE(c) |= vl_xdigit; #endif /* punctuation */ for (c = '!'; c <= '/'; c++) vlCTYPE(c) |= vl_punct; for (c = ':'; c <= '@'; c++) vlCTYPE(c) |= vl_punct; for (c = '['; c <= '`'; c++) vlCTYPE(c) |= vl_punct; for (c = L_CURLY; c <= '~'; c++) vlCTYPE(c) |= vl_punct; #if OPT_ISO_8859 for (c = 0xa1; c <= 0xbf; c++) vlCTYPE(c) |= vl_punct; #endif /* printable */ for (c = ' '; c <= '~'; c++) vlCTYPE(c) |= vl_print; /* whitespace */ vlCTYPE(' ') |= vl_space; #if OPT_ISO_8859 vlCTYPE(0xa0) |= vl_space; #endif vlCTYPE('\t') |= vl_space; vlCTYPE('\r') |= vl_space; vlCTYPE('\n') |= vl_space; vlCTYPE('\f') |= vl_space; #endif /* OPT_LOCALE */ /* legal in pathnames */ vlCTYPE('.') |= vl_pathn; vlCTYPE('_') |= vl_pathn; vlCTYPE('~') |= vl_pathn; vlCTYPE('-') |= vl_pathn; vlCTYPE('/') |= vl_pathn; /* legal in "identifiers" */ vlCTYPE('_') |= vl_ident | vl_qident; vlCTYPE(':') |= vl_qident; #if SYS_VMS vlCTYPE('$') |= vl_ident | vl_qident; #endif c = print_lo; /* * Guard against setting printing-high before printing-low while we have a * buffer which may be repainted and possibly trashing the display. */ if (c == 0 && print_hi >= 254) c = 160; if (c < HIGHBIT) c = HIGHBIT; TRACE(("Forcing printable for [%d..min(%d,%d)]\n", c, print_hi - 1, N_chars - 1)); while (c <= print_hi && c < N_chars) vlCTYPE(c++) |= vl_print; #if DISP_X11 for (c = 0; c < N_chars; c++) { if (isPrint(c) && !gui_isprint(c)) { vlCTYPE(c) &= ~vl_print; } } #endif /* backspacers: ^H, rubout */ vlCTYPE('\b') |= vl_bspace; vlCTYPE(127) |= vl_bspace; /* wildcard chars for most shells */ vlCTYPE('*') |= vl_wild; vlCTYPE('?') |= vl_wild; #if !OPT_VMS_PATH #if SYS_UNIX vlCTYPE('~') |= vl_wild; #endif vlCTYPE(L_BLOCK) |= vl_wild; vlCTYPE(R_BLOCK) |= vl_wild; vlCTYPE(L_CURLY) |= vl_wild; vlCTYPE(R_CURLY) |= vl_wild; vlCTYPE('$') |= vl_wild; vlCTYPE('`') |= vl_wild; #endif /* ex mode line specifiers */ vlCTYPE(',') |= vl_linespec; vlCTYPE('%') |= vl_linespec; vlCTYPE('-') |= vl_linespec; vlCTYPE('+') |= vl_linespec; vlCTYPE(';') |= vl_linespec; vlCTYPE('.') |= vl_linespec; vlCTYPE('$') |= vl_linespec; vlCTYPE('\'') |= vl_linespec; /* fences */ vlCTYPE(L_CURLY) |= vl_fence; vlCTYPE(R_CURLY) |= vl_fence; vlCTYPE(L_PAREN) |= vl_fence; vlCTYPE(R_PAREN) |= vl_fence; vlCTYPE(L_BLOCK) |= vl_fence; vlCTYPE(R_BLOCK) |= vl_fence; #if OPT_VMS_PATH vlCTYPE(L_BLOCK) |= vl_pathn; vlCTYPE(R_BLOCK) |= vl_pathn; vlCTYPE(L_ANGLE) |= vl_pathn; vlCTYPE(R_ANGLE) |= vl_pathn; vlCTYPE('$') |= vl_pathn; vlCTYPE(':') |= vl_pathn; vlCTYPE(';') |= vl_pathn; #endif #if OPT_MSDOS_PATH vlCTYPE(BACKSLASH) |= vl_pathn; vlCTYPE(':') |= vl_pathn; #endif #if OPT_WIDE_CTYPES /* scratch-buffer-names (usually superset of vl_pathn) */ vlCTYPE(SCRTCH_LEFT[0]) |= vl_scrtch; vlCTYPE(SCRTCH_RIGHT[0]) |= vl_scrtch; vlCTYPE(' ') |= vl_scrtch; /* ...to handle "[Buffer List]" */ #endif for (c = 0; c < N_chars; c++) { if (!(isSpace(c))) vlCTYPE(c) |= vl_nonspace; if (isDigit(c)) vlCTYPE(c) |= vl_linespec; if (isAlpha(c) || isDigit(c)) vlCTYPE(c) |= vl_ident | vl_pathn | vl_qident; #if OPT_WIDE_CTYPES if (isSpace(c) || isPrint(c)) vlCTYPE(c) |= vl_shpipe; if (ispath(c)) vlCTYPE(c) |= vl_scrtch; #endif } #if OPT_LOCALE if (save_ctype != 0) (void) setlocale(LC_CTYPE, save_ctype); #endif returnVoid(); }
/* ARGSUSED */ static int isearch(int f GCC_UNUSED, int n) { static TBUFF *pat_save = 0; /* Saved copy of the old pattern str */ int status; /* Search status */ register int cpos; /* character number in search string */ register int c; /* current input character */ MARK curpos, curp; /* Current point on entry */ int init_direction; /* The initial search direction */ /* Initialize starting conditions */ cmd_reexecute = -1; /* We're not re-executing (yet?) */ itb_init(&cmd_buff, EOS); /* Init the command buffer */ /* Save the old pattern string */ (void) tb_copy(&pat_save, searchpat); curpos = DOT; /* Save the current pointer */ init_direction = n; /* Save the initial search direction */ ignorecase = window_b_val(curwp, MDIGNCASE); scanboundry(FALSE, DOT, FORWARD); /* keep scanner() finite */ /* This is a good place to start a re-execution: */ start_over: /* ask the user for the text of a pattern */ promptpattern("ISearch: "); status = TRUE; /* Assume everything's cool */ /* * Get the first character in the pattern. If we get an initial * Control-S or Control-R, re-use the old search string and find the * first occurrence */ c = kcod2key(get_char()); /* Get the first character */ if ((c == IS_FORWARD) || (c == IS_REVERSE)) { /* Reuse old search string? */ for (cpos = 0; cpos < (int) tb_length(searchpat); ++cpos) echochar(tb_values(searchpat)[cpos]); /* and re-echo the string */ curp = DOT; if (c == IS_REVERSE) { /* forward search? */ n = -1; /* No, search in reverse */ last_srch_direc = REVERSE; backchar(TRUE, 1); /* Be defensive about EOB */ } else { n = 1; /* Yes, search forward */ last_srch_direc = FORWARD; forwchar(TRUE, 1); } unget_char(); status = scanmore(searchpat, n); /* Do the search */ if (status != TRUE) DOT = curp; c = kcod2key(get_char()); /* Get another character */ } else { tb_init(&searchpat, EOS); } /* Top of the per character loop */ for_ever { /* ISearch per character loop */ /* Check for special characters, since they might change the * search to be done */ if (ABORTED(c) || c == '\r') /* search aborted? */ return (TRUE); /* end the search */ if (isbackspace(c)) c = '\b'; if (c == quotec) /* quote character? */ c = kcod2key(get_char()); /* Get the next char */ switch (c) { /* dispatch on the input char */ case IS_REVERSE: /* If backward search */ case IS_FORWARD: /* If forward search */ curp = DOT; if (c == IS_REVERSE) { /* forward search? */ last_srch_direc = REVERSE; n = -1; /* No, search in reverse */ backchar(TRUE, 1); /* Be defensive about * EOB */ } else { n = 1; /* Yes, search forward */ last_srch_direc = FORWARD; forwchar(TRUE, 1); } status = scanmore(searchpat, n); /* Do the search */ if (status != TRUE) DOT = curp; c = kcod2key(get_char()); /* Get the next char */ continue; /* Go continue with the search */ case '\t': /* Generically allowed */ case '\n': /* controlled characters */ break; /* Make sure we use it */ case '\b': /* or if a Rubout: */ if (itb_length(cmd_buff) <= 1) /* Anything to delete? */ return (TRUE); /* No, just exit */ unget_char(); DOT = curpos; /* Reset the pointer */ n = init_direction; /* Reset the search direction */ (void) tb_copy(&searchpat, pat_save); /* Restore the old search str */ cmd_reexecute = 0; /* Start the whole mess over */ goto start_over; /* Let it take care of itself */ /* Presumably a quasi-normal character comes here */ default: /* All other chars */ if (!isPrint(c)) { /* Is it printable? */ /* Nope. */ unkeystroke(c); /* Re-eat the char */ return (TRUE); /* And return the last status */ } } /* Switch */ /* I guess we got something to search for, so search for it */ tb_append(&searchpat, c); /* put the char in the buffer */ echochar(c); /* Echo the character */ if (!status) { /* If we lost last time */ kbd_alarm(); /* Feep again */ } else /* Otherwise, we must have won */ status = scanmore(searchpat, n); /* or find the next * match */ c = kcod2key(get_char()); /* Get the next char */ } /* for_ever */ }