/** * @brief Parses io_line buffer for a number and stores it in io_parsed * @param void * @return void */ bool io_parse_number(int* res) { glyph_t* curr_glyph = NULL; int i = 0, curr_digit = 0; *res = 0; curr_glyph = io_parsed[0]; if (curr_glyph->pattern != NUMSIGN) { play_mp3(lang_fileset, MP3_NUMSIGN_MISSED); return false; } if (io_parsed[1] == NULL || is_blank(io_parsed[1])){ play_mp3(lang_fileset, MP3_NO_NUMBER); return false; } for (i = 1; io_parsed[i] != NULL && is_blank(io_parsed[i]) == false; i++) { curr_glyph = io_parsed[i]; curr_digit = get_digit(curr_glyph); if (curr_digit < 0) { play_mp3(lang_fileset, MP3_INVALID_PATTERN); return false; } else { *res *= 10; *res += curr_digit; } } io_parsed[i] = NULL; return true; }
// 按照单词反转 void reverse_word(char str[]) { char *p, *q; p = q = str; while(*q != '\0'){ // 用p q框住一个word,然后用reverse_str处理 while(!is_blank(*q) && *q != '\0'){ q++; } q--; // 反转 reverse_str(p,q); // q指向下一个非空白字符 q++; while(is_blank(*q) && *q != '\0'){ q++; } p = q; } }
char *ft_strtrim(char const *s) { int a; int c; int i; char *str; a = ft_strlen(s); c = 0; i = 0; str = ft_memalloc(a + 1); a--; while (is_blank(s[c])) c++; if (s[c] == '\0') return (ft_strnew(0)); while (is_blank(s[a])) a--; while (c != (a + 1)) { str[i] = s[c]; c++; i++; } str[i] = '\0'; return (str); }
static tree parse_enunciation (string s) { int i= 0, n= N(s); string kind= parse_command_name (s, i); while (i<n && is_blank (s[i])) i++; string name= parse_identifier (s, i); while (i<n && is_blank (s[i])) i++; tree body= parse_subcommand (s (i, n)); tree r= compound ("coq-enunciation", "", "dark grey"); r << kind << name << body; return r; }
/** * @internal * @param pg Formatted vbi_page to be optimized. * @param column First column, 0 ... pg->columns - 1. * @param row First row, 0 ... pg->rows - 1. * @param width Number of columns to optimize, 1 ... pg->columns. * @param height Number of rows to optimize, 1 ... pg->rows. * * Experimental. */ void vbi_optimize_page(vbi_page *pg, int column, int row, int width, int height) { vbi_char c, l, *cp; int column0, row0; int column1, row1; column0 = column; row0 = row; column1 = column + width; row1 = row + height; l = pg->text[pg->columns * row + column]; for (row = row0; row < row1; row++) for (column = column0; column < column1; column++) { cp = pg->text + pg->columns * row + column; c = *cp; if (is_blank(c)) { c.bold = l.bold; c.italic = l.italic; c.foreground = l.foreground; } else if (is_full(c)) { c.bold = l.bold; c.italic = l.italic; c.background = l.background; } *cp = l = c; } for (row = row1 - 1; row >= row0; row--) for (column = column1 - 1; column >= column0; column--) { cp = pg->text + pg->columns * row + column; c = *cp; if (is_blank(c)) { c.bold = l.bold; c.italic = l.italic; c.foreground = l.foreground; } else if (is_full(c)) { c.bold = l.bold; c.italic = l.italic; c.background = l.background; } *cp = l = c; } }
static int expand(fdja_value *v, fdja_value *node, fdja_value *msg) { if (v == NULL) return 0; int r = 0; // expanded? no if (v->key && strstr(v->key, "$(")) { char *k = v->key; v->key = fdol_expand(k, &(lup){ node, msg }, dol_lookup); free(k); r = 1; // expanded? yes } if (v->type == 's' || v->type == 'q' || v->type == 'y') { char *s = fdja_to_string(v); char *dol = strstr(s, "$("); if (dol) { char *ss = fdol_expand(s, &(lup){ node, msg }, dol_lookup); fdja_value *vv = NULL; if (is_blank(*ss) || is_blank(*(ss + strlen(ss) - 1))) vv = fdja_s(ss); if (vv == NULL) vv = fdja_v(ss); if (vv == NULL) vv = fdja_s(ss); fdja_replace(v, vv); free(ss); r = 1; // expanded? yes } free(s); } else if (v->type == 'o' || v->type == 'a') { for (fdja_value *c = v->child; c; c = c->sibling) { if (expand(c, node, msg)) r = 1; // expanded? yes } } //else // do not expand return r; }
static int read_model_lines (const char *s, FILE *fp) { char line[128]; int err = 0; int blank_count = 0; if (verbose) { printf("%s\n", s); } while (fgets(line, sizeof line, fp) && !err) { tail_strip(line); if (is_blank(line)) { blank_count++; } if (blank_count == 0) { if (verbose) { printf("%s\n", line); } } else if (blank_count == 1) { err = parse_model_line(line); } else { break; } } trim_error(tester.model_spec); if (verbose) { printf("model_spec: '%s'\n", tester.model_spec); } return 0; }
static int make_file_list (void) { const char *datlist = "datalist"; FILE *fp; char line[32]; int err = 0; fp = fopen(datlist, "r"); if (fp == NULL) { fprintf(stderr, "Couldn't open '%s'\n", datlist); return 1; } while (fgets(line, sizeof line, fp)) { tail_strip(line); if (!is_blank(line)) { if (add_file_to_list(line)) { err = 1; break; } } } fclose(fp); return err; }
unsigned int mz_quoted_printable_encode_close (const unsigned char *inbuf, unsigned int inlen, unsigned char *outbuf, int *state, unsigned int *save) { register unsigned char *outptr = outbuf; int last; if (inlen > 0) outptr += mz_quoted_printable_encode_step(inbuf, inlen, outptr, state, save); last = *state; if (last != -1) { /* space/tab must be encoded if its the last character on the line */ if (is_qpsafe(last) && !is_blank(last)) { *outptr++ = last; } else { *outptr++ = '='; *outptr++ = tohex[(last >> 4) & 0xf]; *outptr++ = tohex[last & 0xf]; } } *outptr++ = '\n'; *save = 0; *state = -1; return (outptr - outbuf); }
/** * 拆分如 "test, quiet" 的字符串为 ["test", "quiet"] */ static void split_groups(const char *groups, std::vector<std::string> *rs) { assert(NULL != groups && NULL != rs); const char GROUP_SPLITER = ','; // 分组分隔符 std::string s; for (size_t i = 0; 0 != groups[i]; ++i) { const char c = groups[i]; if (GROUP_SPLITER == c) { // 去除尾部空格 s = trim_end(s); // 添加到结果 if (s.length() > 0) { rs->push_back(s); s.clear(); } } else if (s.length() > 0 || !is_blank(c)) { s.push_back(c); } } s = trim_end(s); if (s.length() > 0) rs->push_back(s); }
static void add_line(tree &c, tree &d) { tree tmp= trim_spaces (simplify_concat (c)); if (!is_blank (tmp)) d << copy (tmp); c= tree (CONCAT); }
/* removes all empty text, comments and other insignoficant nodes */ static void cleanup_xml_node(xmlNodePtr node) { xmlNodePtr trav; xmlNodePtr del = NULL; trav = node->children; while (trav != NULL) { if (del != NULL) { xmlUnlinkNode(del); xmlFreeNode(del); del = NULL; } if (trav->type == XML_TEXT_NODE) { if (is_blank(trav->content)) { del = trav; } } else if ((trav->type != XML_ELEMENT_NODE) && (trav->type != XML_CDATA_SECTION_NODE)) { del = trav; } else if (trav->children != NULL) { cleanup_xml_node(trav); } trav = trav->next; } if (del != NULL) { xmlUnlinkNode(del); xmlFreeNode(del); } }
void load(list<Expression*>& expressions) { /* load expressions from file, NO shell subst */ char line[256]; int iline = 0; while(fgets(line, sizeof(line), fp)){ chomp(line); dbg(2, "[%2d] \"%s\"", ++iline, line); if (is_key(line)){ char *equals = index(line, '='); if (equals == 0){ err("NOT key=value \"%s\"", line); continue; }else{ *equals = '\0'; char* key = line; char* value = equals + 1; expressions.push_front( new RootExpression( key, value, NOSUBS)); } }else if (is_comment(line) || is_blank(line)){ continue; }else{ err("continuation not supported at this time"); } } }
// 冒頭末尾の空白を削除 char* trim(char *str) { //冒頭 char *head = str; while ( is_blank(*head) ) { head++; } //末尾 char *tail = str + strlen(str) -1; while ( is_blank(*tail) && tail > head ) { *tail = '\0'; tail--; } return head; }
static bool is_blank (tree t) { if (is_atomic (t)) return is_blank (as_string (t)); int i= 0, n= N(t); if (is_compound (t, "with")) return is_blank (t[n-1]); else if (is_document (t) || is_concat (t)) { while (i<n) if (!is_blank (t[i++])) return false; return true; } else return false; }
/* do analysis and call alpheios print routine */ int alpheiosCheckstring(const char* string, PrntFlags prntflags, FILE* fout) { gk_word * gkword = NULL; if (is_blank(string)) return(0); if (strlen(string) >= MAXWORDSIZE) return(0); gkword = (gk_word*) CreatGkword(1); set_dialect(gkword,WantDialects); set_workword(gkword,string); set_prntflags(gkword,prntflags); set_rawword(gkword,workword_of(gkword)); if (cur_lang() != ITALIAN) standword(workword_of(gkword)); stand_phonetics(gkword); checkstring1(gkword); int nanals = totanal_of(gkword); if (prntflags && (nanals > 0)) { alpheiosPrintWord(gkword, prntflags, fout); } FreeGkword(gkword); return(nanals); }
main() { char s[100], wt[100], *nt; long i; do { queryn("template: ", wt, 100); if (has_wildcards(wt)) printf("template has wildcards\n"); chop_nl(wt); if (is_blank(wt)) break; nt = expand_ranges(wt); printf("expanded template: %s\n", nt); do { queryn("string: ", s, 100); chop_nl(s); if (s[0]=='q') break; if ((i=wild_match(s, nt))) printf("%s is matched by %s--return value %ld\n", s, wt, i); else printf("%s is not matched by %s\n", s, wt); } while (1); } while (1); }
int main() { int c, i, blank_count; char result[MAXLINE]; blank_count = 0; i = 0; while((c = getchar()) != EOF) { if(is_blank(c)) { blank_count++; // Start count } else { // check counter i = replace_str(i, blank_count ,result); blank_count = 0; result[i] = c; if(c == '\n') { /* Print final result, reset for the next line after line break */ printf("%s \n", result); i = 0; strcpy(result," "); } i++; } } return 0; }
void ListParser::proc_plain(const std::string &line, std::vector<std::string> &result) { if (!ignore_now) { if ((!is_blank(line)) && (!is_preproc(line))) result.push_back(line); } }
static tree parse_item (string s, int &i, int item_indent) { int text_indent= item_indent, n= N(s); while (i<n && is_blank (s[i])) i++; if (is_new_item (s, i)) { text_indent++; while (s[i] == '-') i++; } while (i<n && is_spacing (s[i])) { if (s[i] == ' ') text_indent++; i++; } tree r (CONCAT); r << compound ("item"); string line= ""; string tmp= parse_line (s, i, text_indent); if (tmp != "") line << tmp; while (can_parse_line (s, i, text_indent)) { tmp= parse_line (s, i, text_indent); if (tmp != "") line << "\n" << tmp; } r << coqdoc_to_tree (line); return r; }
int get_io_redir_file(const char* command, int io) { int i = 0, len, fnsize = 0, file; char* filename; if (io != SLSH_INPUT && io != SLSH_OUTPUT) return -1; len = strlen(command); filename = (char*) malloc(sizeof(char)*(len+1)); error(filename == NULL, -1); while (i < len && command[i] != io) i++; if (i == len) { free(filename); return -1; } i++; while (i < len && is_blank(command[i])) i++; if (i == len) { free(filename); return -1; } while (i < len && !is_blank(command[i])) { filename[fnsize++] = command[i]; i++; } filename[fnsize] = '\0'; if (io == SLSH_INPUT) file = open(filename, O_RDONLY); else file = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); free(filename); return file; }
void parser_base::skip_blanks() { for (; has_char(); next()) { if (!is_blank(*mp_char)) break; } }
static bool is_blank (string s) { int i= 0, n= N(s); while (i<n) if (!is_blank (s[i++])) return false; return true; }
void parser_base::skip_blanks_reverse() { const char* p = mp_char + remaining_size(); for (; p != mp_char; --p, --mp_end) { if (!is_blank(*p)) break; } }
static bool empty_section(struct doc_section *d) { unsigned int i; for (i = 0; i < d->num_lines; i++) if (!is_blank(d->lines[i])) return false; return true; }
/* function: "_one_color_bg(frame)->b\n True if the frame background consists of a single color." name: "_one_color_bg" */ static bool one_color_bg(const Image* image){ return image->GetBackground().Visit( [](const Bitmap& bmp){ return is_blank(bmp); }, [](const ColorSpan&){ return true; }); }
/* ** Find the first position in the string ** that is not blank (white space or tab) */ int get_first_non_blank_pos(char *string) { int first_non_white_space_letter = -1; char c; do { c = string[++first_non_white_space_letter]; } while (is_blank(c)); return first_non_white_space_letter; }
void parser_base::skip_to_or_blank(const char*&p, size_t& len, const char* chars) { p = mp_char; len = 0; for (; has_char(); next(), ++len) { if (is_blank(*mp_char) || is_in(*mp_char, chars)) return; } }
static string get_section_name (tree t) { if (N(t) != 3) return ""; string s= as_string (t[2]); int i= 0, n= N(s); string cmd= parse_command_name (s, i); if (cmd != "Section" && cmd != "End") return ""; while (i<n && is_blank (s[i])) i++; string ident= parse_identifier (s, i); return ident; }
int main() { int c; char transformed_str[MAXLINE]; while((c = getchar()) != EOF) { if(is_blank(c)) { putchar(c); } } return 0; }