int cstrncmp(char *s, char *t, int n) { for (; n && *s && *t && DOWNCASE(*s) == DOWNCASE(*t); s++, t++, n--); if (n <= 0) return 0; else return (DOWNCASE(*s) - DOWNCASE(*t)); }
int cstrcmp(char *s, char *t) { while (*s && *t && DOWNCASE(*s) == DOWNCASE(*t)) { s++; t++; } return (DOWNCASE(*s) - DOWNCASE(*t)); }
char * cstrchr(char *s, char c) { c = DOWNCASE(c); while (*s && DOWNCASE(*s) != c) s++; if (*s || !c) return s; else return NULL; }
/* For use by abbrev_match(): Match SYMBOL's name against buffer text before point, case-insensitively. When found, return non-zero, so that map_obarray terminates mapping. */ static int abbrev_match_mapper(Lisp_Object symbol, void *arg) { struct abbrev_match_mapper_closure *closure = (struct abbrev_match_mapper_closure *)arg; Charcount abbrev_length; Lisp_Symbol *sym = XSYMBOL(symbol); Lisp_String *abbrev; /* symbol_value should be OK here, because abbrevs are not expected to contain any SYMBOL_MAGIC stuff. */ if (UNBOUNDP(symbol_value(sym)) || NILP(symbol_value(sym))) { /* The symbol value of nil means that abbrev got undefined. */ return 0; } abbrev = symbol_name(sym); abbrev_length = string_char_length(abbrev); if (abbrev_length > closure->maxlen) { /* This abbrev is too large -- it wouldn't fit. */ return 0; } /* If `bar' is an abbrev, and a user presses `fubar<SPC>', we don't normally want to expand it. OTOH, if the abbrev begins with non-word syntax (e.g. `#if'), it is OK to abbreviate it anywhere. */ if (abbrev_length < closure->maxlen && abbrev_length > 0 && (WORD_SYNTAX_P(closure->chartab, string_char(abbrev, 0))) && (WORD_SYNTAX_P(closure->chartab, BUF_FETCH_CHAR(closure->buf, closure->point - (abbrev_length + 1))))) { return 0; } /* Match abbreviation string against buffer text. */ { Bufbyte *ptr = string_data(abbrev); Charcount idx; for (idx = 0; idx < abbrev_length; idx++) { if (DOWNCASE(closure->buf, BUF_FETCH_CHAR(closure->buf, closure->point - abbrev_length + idx)) != DOWNCASE(closure->buf, charptr_emchar(ptr))) { break; } INC_CHARPTR(ptr); } if (idx == abbrev_length) { /* This is the one. */ closure->found = sym; return 1; } } return 0; }
static int cmatch(char *s1, char c1) { int truthval = FALSE; c1 = DOWNCASE(c1); if (*s1 == '^') { s1++; truthval = TRUE; } if (*s1 == '-') test(*s1++); while (*s1) { if (*s1 == '\\' && *(s1 + 1)) s1++; if (*s1 == '-') { char c, start = *(s1 - 1), end = *(s1 + 1); if (start > end) { test(*s1++); } else { for (c = start; c <= end; c++) test(c); s1 += 2; } } else test(*s1++); } return !truthval; }
/* Take the word before point (or Vabbrev_start_location, if non-nil), and look it up in OBARRAY, and return the symbol (or zero). This used to be the default method of searching, with the obvious limitation that the abbrevs may consist only of word characters. It is an order of magnitude faster than the proper abbrev_match(), but then again, vi is an order of magnitude faster than Emacs. This speed difference should be unnoticeable, though. I have tested the degenerated cases of thousands of abbrevs being defined, and abbrev_match() was still fast enough for normal operation. */ static Lisp_Symbol *abbrev_oblookup(struct buffer *buf, Lisp_Object obarray) { Bufpos wordstart, wordend; Bufbyte *word, *p; Bytecount idx; Lisp_Object lookup; CHECK_VECTOR(obarray); if (!NILP(Vabbrev_start_location)) { wordstart = get_buffer_pos_char(buf, Vabbrev_start_location, GB_COERCE_RANGE); Vabbrev_start_location = Qnil; #if 0 /* Previously, abbrev-prefix-mark crockishly inserted a dash to indicate the abbrev start point. It now uses an extent with a begin glyph so there's no dash to remove. */ if (wordstart != BUF_ZV(buf) && BUF_FETCH_CHAR(buf, wordstart) == '-') { buffer_delete_range(buf, wordstart, wordstart + 1, 0); } #endif wordend = BUF_PT(buf); } else { Bufpos point = BUF_PT(buf); wordstart = scan_words(buf, point, -1); if (!wordstart) return 0; wordend = scan_words(buf, wordstart, 1); if (!wordend) return 0; if (wordend > BUF_ZV(buf)) wordend = BUF_ZV(buf); if (wordend > point) wordend = point; /* Unlike the original function, we allow expansion only after the abbrev, not preceded by a number of spaces. This is because of consistency with abbrev_match. */ if (wordend < point) return 0; } if (wordend <= wordstart) return 0; p = word = (Bufbyte *) alloca(MAX_EMCHAR_LEN * (wordend - wordstart)); for (idx = wordstart; idx < wordend; idx++) { Emchar c = BUF_FETCH_CHAR(buf, idx); if (UPPERCASEP(buf, c)) c = DOWNCASE(buf, c); p += set_charptr_emchar(p, c); } lookup = oblookup(obarray, word, p - word); if (SYMBOLP(lookup) && !NILP(symbol_value(XSYMBOL(lookup)))) return XSYMBOL(lookup); else return NULL; }
/******************************************************************** * @作者: 揭成 * @功能: 选择锁相环信号通道 * @输入: * @输出: NONE ********************************************************************/ void measure_CTScale_select_PLL(char UI,char phase) { UI=DOWNCASE(UI);//转换成小写 if(UI=='u'&&phase=='a') m_pll_pos = 0; else if(UI=='u'&&phase=='b') m_pll_pos = 1; else if(UI=='u'&&phase=='c') m_pll_pos = 2; else if(UI=='i'&&phase=='a') m_pll_pos = 3; else if(UI=='i'&&phase=='b') m_pll_pos = 4; else if(UI=='i'&&phase=='c') m_pll_pos = 5; EXTIOLOCK(); EXTIO_buff_Bitrenew(IS_4015A,m_pll_DATA[m_pll_pos][2]); EXTIO_buff_Bitrenew(IS_4015B,m_pll_DATA[m_pll_pos][1]); EXTIO_buff_Bitrenew(IS_4015C,m_pll_DATA[m_pll_pos][0]); EXTIO_send_Ndata(); EXTIOUNLOCK(); return; }
static Lisp_Object casify_object (enum case_action flag, Lisp_Object string_or_char, Lisp_Object buffer) { struct buffer *buf = decode_buffer (buffer, 0); retry: if (CHAR_OR_CHAR_INTP (string_or_char)) { Ichar c; CHECK_CHAR_COERCE_INT (string_or_char); c = XCHAR (string_or_char); if (flag == CASE_DOWN) { c = DOWNCASE (buf, c); } else if (flag == CASE_UP) { c = UPCASE (buf, c); } else { c = CANONCASE (buf, c); } return make_char (c); } if (STRINGP (string_or_char)) { Lisp_Object syntax_table = buf->mirror_syntax_table; Ibyte *storage = alloca_ibytes (XSTRING_LENGTH (string_or_char) * MAX_ICHAR_LEN); Ibyte *newp = storage; Ibyte *oldp = XSTRING_DATA (string_or_char); Ibyte *endp = oldp + XSTRING_LENGTH (string_or_char); int wordp = 0, wordp_prev; while (oldp < endp) { Ichar c = itext_ichar (oldp); switch (flag) { case CASE_UP: c = UPCASE (buf, c); break; case CASE_DOWN: c = DOWNCASE (buf, c); break; case CASE_CANONICALIZE: c = CANONCASE (buf, c); break; case CASE_CAPITALIZE: case CASE_CAPITALIZE_UP: wordp_prev = wordp; wordp = WORD_SYNTAX_P (syntax_table, c); if (!wordp) break; if (wordp_prev) { if (flag == CASE_CAPITALIZE) c = DOWNCASE (buf, c); } else c = UPCASE (buf, c); break; } newp += set_itext_ichar (newp, c); INC_IBYTEPTR (oldp); } return make_string (storage, newp - storage); } string_or_char = wrong_type_argument (Qchar_or_string_p, string_or_char); goto retry; }
int smatch(char *s1, char *s2) { char ch, *start = s2; while (*s1) { switch (*s1) { case '\\': if (!*(s1+1)) { return 1; } else { s1++; if (DOWNCASE(*s1++) != DOWNCASE(*s2++)) return 1; } break; case '?': if (!*s2++) return 1; s1++; break; case '*': while (*s1 == '*' || (*s1 == '?' && *s2++)) s1++; if (*s1 == '?') return 1; if (*s1 == '{') { if (s2 == start) if (!smatch(s1, s2)) return 0; while ((s2 = strchr(s2, ' ')) != NULL) if (!smatch(s1, ++s2)) return 0; return 1; } else if (*s1 == '[') { while (*s2) if (!smatch(s1, s2++)) return 0; return 1; } if (*s1 == '\\' && *(s1+1)) ch = *(s1 + 1); else ch = *s1; while ((s2 = cstrchr(s2, ch)) != NULL) { if (!smatch(s1, s2)) return 0; s2++; } return 1; case '[': { char *end; int tmpflg; if (!(end = estrchr(s1, ']', '\\'))) { return 1; } *end = '\0'; tmpflg = cmatch(&s1[1], *s2++); *end = ']'; if (tmpflg) { return 1; } s1 = end + 1; } break; case '{': if (s2 != start && *(s2 - 1) != ' ') return 1; { char *end; int tmpflg = 0; if (s1[1] == '^') tmpflg = 1; if (!(end = estrchr(s1, '}', '\\'))) { return 1; } *end = '\0'; tmpflg -= (wmatch(&s1[tmpflg + 1], &s2)) ? 1 : 0; *end = '}'; if (tmpflg) { return 1; } s1 = end + 1; } break; default: if (DOWNCASE(*s1++) != DOWNCASE(*s2++)) return 1; break; } } return DOWNCASE(*s1) - DOWNCASE(*s2); }
static Lisp_Object casify_object(enum case_action flag, Lisp_Object string_or_char, Lisp_Object buffer) { struct buffer *buf = decode_buffer(buffer, 0); retry: if (CHAR_OR_CHAR_INTP(string_or_char)) { Emchar c; CHECK_CHAR_COERCE_INT(string_or_char); c = XCHAR(string_or_char); c = (flag == CASE_DOWN) ? DOWNCASE(buf, c) : UPCASE(buf, c); return make_char(c); } if (STRINGP(string_or_char)) { Lisp_Char_Table *syntax_table = XCHAR_TABLE(buf->mirror_syntax_table); Bufbyte *storage = alloca_array(Bufbyte, XSTRING_LENGTH(string_or_char) * MAX_EMCHAR_LEN); Bufbyte *newp = storage; Bufbyte *oldp = XSTRING_DATA(string_or_char); int wordp = 0, wordp_prev; while (*oldp) { Emchar c = charptr_emchar(oldp); switch (flag) { case CASE_UP: c = UPCASE(buf, c); break; case CASE_DOWN: c = DOWNCASE(buf, c); break; case CASE_CAPITALIZE: case CASE_CAPITALIZE_UP: wordp_prev = wordp; wordp = WORD_SYNTAX_P(syntax_table, c); if (!wordp) break; if (wordp_prev) { if (flag == CASE_CAPITALIZE) c = DOWNCASE(buf, c); } else c = UPCASE(buf, c); break; /* can't happen */ default: /* abort()? */ break; } newp += set_charptr_emchar(newp, c); INC_CHARPTR(oldp); } return make_string(storage, newp - storage); } string_or_char = wrong_type_argument(Qchar_or_string_p, string_or_char); goto retry; }