int sort_word(char **s1, char **s2) { int i; char *tmp1; char *tmp2; i = 0; tmp1 = lowerize(*s1); tmp2 = lowerize(*s2); while ((*s1)[i] != '\0' && (*s2)[i] != '\0') { if (tmp1[i] > tmp2[i]) { swap_str(s1, s2); free_lower(tmp1, tmp2); return (1); } else if (tmp1[i] == tmp2[i]) i++; else { free_lower(tmp1, tmp2); return (0); } } free_lower(tmp1, tmp2); return (0); }
static void setup_o(opcode *o) { lowerize(o->m); if(ISIMM(o->o1)) o->f |= IMM, o->immsz = GETTYPE(o->o1); else if(ISIMM(o->o2)) o->f |= IMM, o->immsz = GETTYPE(o->o2); else if(ISIMM(o->o3)) o->f |= IMM, o->immsz = GETTYPE(o->o3); if(HASMODRM(o->o1) || HASMODRM(o->o2)) o->f |= MODRM; }
void parse_options(struct high_syntax *syntax, struct high_cmd *cmd, FILE *f, unsigned char *p, int parsing_strings, unsigned char *name, int line) { unsigned char buf[1024]; unsigned char bf[256]; unsigned char bf1[256]; while (parse_ws(&p, '#'), !parse_ident(&p, bf, sizeof(bf))) { if (!zcmp(bf, USTR "buffer")) { cmd->start_buffering = 1; } else if (!zcmp(bf, USTR "hold")) { cmd->stop_buffering = 1; } else if (!zcmp(bf, USTR "save_c")) { cmd->save_c = 1; } else if (!zcmp(bf, USTR "save_s")) { cmd->save_s = 1; } else if (!zcmp(bf, USTR "recolor")) { parse_ws(&p, '#'); if (!parse_char(&p, '=')) { parse_ws(&p, '#'); if (parse_int(&p, &cmd->recolor)) { i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line); } } else if (!zcmp(bf, USTR "call")) { parse_ws(&p, '#'); if (!parse_char(&p, '=')) { parse_ws(&p, '#'); if (!parse_char(&p, '.')) { zcpy(bf, syntax->name); goto subr; } else if (parse_ident(&p, bf, sizeof(bf))) { i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line); } else { if (!parse_char(&p, '.')) { subr: if (parse_ident(&p, bf1, sizeof(bf1))) { i_printf_2((char *)joe_gettext(_("%s %d: Missing subroutine name\n")), name, line); } cmd->call = load_syntax_subr(bf, bf1, parse_params(syntax->params, &p, name, line)); } else { cmd->call = load_syntax_subr(bf, 0, parse_params(syntax->params, &p, name, line)); } } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line); } } else if (!zcmp(bf, USTR "return")) { cmd->rtn = 1; } else if (!zcmp(bf, USTR "reset")) { cmd->reset = 1; } else if (!parsing_strings && (!zcmp(bf, USTR "strings") || !zcmp(bf, USTR "istrings"))) { if (bf[0] == 'i') { cmd->ignore = 1; } while (fgets((char *)buf, 1023, f)) { ++line; p = buf; parse_ws(&p, '#'); if (*p) { if (!parse_field(&p, USTR "done")) { break; } if (parse_string(&p, bf, sizeof(bf)) >= 0) { parse_ws(&p, '#'); if (cmd->ignore) { lowerize(bf); } if (!parse_ident(&p, bf1, sizeof(bf1))) { struct high_cmd *kw_cmd = mkcmd(); kw_cmd->noeat = 1; kw_cmd->new_state = find_state(syntax, bf1); if (!zcmp(bf, USTR "&")) { cmd->delim = kw_cmd; } else { if (!cmd->keywords) { cmd->keywords = htmk(64); } htadd(cmd->keywords, zdup(bf), kw_cmd); } parse_options(syntax, kw_cmd, f, p, 1, name, line); } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing state name\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing string\n")), name, line); } } } } else if (!zcmp(bf, USTR "noeat")) { cmd->noeat = 1; } else if (!zcmp(bf, USTR "mark")) { cmd->start_mark = 1; } else if (!zcmp(bf, USTR "markend")) { cmd->stop_mark = 1; } else if (!zcmp(bf, USTR "recolormark")) { cmd->recolor_mark = 1; } else { i_printf_2((char *)joe_gettext(_("%s %d: Unknown option\n")), name, line); } } }
HIGHLIGHT_STATE parse(struct high_syntax *const syntax, line_desc *const ld, HIGHLIGHT_STATE h_state, const bool utf8) { struct high_frame *stack = h_state.stack; struct high_state *h = (stack ? stack->syntax : syntax)->states[h_state.state]; /* Current state */ unsigned char buf[24]; /* Name buffer (trunc after 23 characters) */ unsigned char lbuf[24]; /* Lower case version of name buffer */ unsigned char lsaved_s[24]; /* Lower case version of delimiter match buffer */ int buf_idx = 0; /* Index into buffer */ int c; /* Current character */ int c_len; /* Character length in bytes */ uint32_t *attr = attr_buf; uint32_t *attr_end = attr_buf + attr_size; int buf_en = 0; /* Set for name buffering */ int ofst = 0; /* record offset after we've stopped buffering */ int mark1 = 0; /* offset to mark start from current pos */ int mark2 = 0; /* offset to mark end from current pos */ int mark_en = 0; /* set if marking */ int recolor_delimiter_or_keyword; const unsigned char *p = (const unsigned char *)ld->line; unsigned char *q = (unsigned char *)(ld->line + ld->line_len); buf[0] = 0; /* Forgot this originally... took 5 months to fix! */ /* Get next character */ /* Una iterazione in più: aggiungo '\n' come ultimo carattere. */ while (p <= q) /* On the last itteration, process the virtual '\n' character. */ { struct high_cmd *cmd; struct high_cmd *kw_cmd; int x; if (p == q) { c = '\n'; } else { c = utf8 ? get_char((const char *)p, ENC_UTF8) : *p; } c_len = utf8 ? utf8seqlen(c) : 1; p += c_len; /* Hack so we can have UTF-8 characters without crashing */ if (c < 0 || c > 255) { c = 0x1F; } /* Create or expand attribute array if necessary */ if (attr == attr_end) { if (!attr_buf) { attr_size = 1024; attr_buf = joe_malloc(sizeof(int) * attr_size); attr = attr_buf; } else { attr_buf = joe_realloc(attr_buf, sizeof(int) * (attr_size * 2)); attr = attr_buf + attr_size; attr_size *= 2; } attr_end = attr_buf + attr_size; } /* Advance to next attribute position (note attr[-1] below) */ attr++; /* Loop while noeat */ do { /* Color with current state */ attr[-1] = h->color; /* Get command for this character */ if (h->delim && c == h_state.saved_s[0] && h_state.saved_s[1] == 0) { cmd = h->delim; } else { cmd = h->cmd[c]; } /* Lowerize strings for case-insensitive matching */ if (cmd->ignore) { zcpy(lbuf, buf); lowerize(lbuf); if (cmd->delim) { zcpy(lsaved_s, h_state.saved_s); lowerize(lsaved_s); } } /* Check for delimiter or keyword matches */ recolor_delimiter_or_keyword = 0; if (cmd->delim && (cmd->ignore ? !zcmp(lsaved_s, lbuf) : !zcmp(h_state.saved_s, buf))) { cmd = cmd->delim; recolor_delimiter_or_keyword = 1; } else if (cmd->keywords && (cmd->ignore ? (kw_cmd = htfind(cmd->keywords, lbuf)) : (kw_cmd = htfind(cmd->keywords, buf)))) { cmd = kw_cmd; recolor_delimiter_or_keyword = 1; } /* Determine new state */ if (cmd->call) { /* Call */ struct high_frame **frame_ptr = stack ? &stack->child : &syntax->stack_base; /* Search for an existing stack frame for this call */ while (*frame_ptr && !((*frame_ptr)->syntax == cmd->call && (*frame_ptr)->return_state == cmd->new_state)) { frame_ptr = &(*frame_ptr)->sibling; } if (*frame_ptr) { stack = *frame_ptr; } else { struct high_frame *frame = joe_malloc(sizeof(struct high_frame)); frame->parent = stack; frame->child = 0; frame->sibling = 0; frame->syntax = cmd->call; frame->return_state = cmd->new_state; *frame_ptr = frame; stack = frame; ++stack_count; } h = stack->syntax->states[0]; } else if (cmd->rtn) { /* Return */ if (stack) { h = stack->return_state; stack = stack->parent; } else /* Not in a subroutine, so ignore the return */ { h = cmd->new_state; } } else if (cmd->reset) { /* Reset the state and call stack */ h = syntax->states[0]; stack = syntax->stack_base; } else { /* Normal edge */ h = cmd->new_state; } /* Recolor if necessary */ if (recolor_delimiter_or_keyword) for (x = -(buf_idx + 1); x < -1; ++x) { attr[x - ofst] = h->color; } for (x = cmd->recolor; x < 0; ++x) if (attr + x >= attr_buf) { attr[x] = h->color; } /* Mark recoloring */ if (cmd->recolor_mark) for (x = -mark1; x < -mark2; ++x) { attr[x] = h->color; } /* Save string? */ if (cmd->save_s) { zcpy(h_state.saved_s, buf); } /* Save character? */ if (cmd->save_c) { h_state.saved_s[1] = 0; if (c == '<') { h_state.saved_s[0] = '>'; } else if (c == '(') { h_state.saved_s[0] = ')'; } else if (c == '[') { h_state.saved_s[0] = ']'; } else if (c == '{') { h_state.saved_s[0] = '}'; } else if (c == '`') { h_state.saved_s[0] = '\''; } else { h_state.saved_s[0] = c; } } /* Start buffering? */ if (cmd->start_buffering) { buf_idx = 0; buf_en = 1; ofst = 0; } /* Stop buffering? */ if (cmd->stop_buffering) { buf_en = 0; } /* Set mark begin? */ if (cmd->start_mark) { mark2 = 1; mark1 = 1; mark_en = 1; } /* Set mark end? */ if (cmd->stop_mark) { mark_en = 0; mark2 = 1; } } while (cmd->noeat); /* Save character in buffer */ if (buf_idx < 23 && buf_en) { buf[buf_idx++] = c; } if (!buf_en) { ++ofst; } buf[buf_idx] = 0; /* Update mark pointers */ ++mark1; if (!mark_en) { ++mark2; } /* if(c=='\n') break;*/ } /* Return new state */ h_state.stack = stack; h_state.state = h->no; attr_len = attr - attr_buf - 1; /* -1 because of the fake newline. */ return h_state; }