void workshop_hotkeys( Boolean on) { char cbuf[BUFSIZ]; /* command buffer */ MenuMap *mp; /* iterate over menuMap entries */ #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) wstrace("workshop_hotkeys(%s)\n", on ? "True" : "False"); #endif workshopHotKeysEnabled = on; if (workshopHotKeysEnabled) for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++) { if (mp->accel != NULL) { vim_snprintf(cbuf, sizeof(cbuf), "map %s :wsverb %s<CR>", mp->accel, mp->verb); coloncmd(cbuf, TRUE); } } else for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++) { if (mp->accel != NULL) { vim_snprintf(cbuf, sizeof(cbuf), "unmap %s", mp->accel); coloncmd(cbuf, TRUE); } } }
/* * Given a font name this function returns the part used in the second scroll list. */ static void style_part(char *font, char *buf) { char buf2[TEMP_BUF_SIZE]; char buf3[TEMP_BUF_SIZE]; get_part(font, 3, buf3); get_part(font, 5, buf2); if (!strcmp(buf2, "normal") && !strcmp(buf2, "Normal") && !strcmp(buf2, "NORMAL")) vim_snprintf(buf, TEMP_BUF_SIZE, "%s %s", buf3, buf2); else strcpy(buf, buf3); get_part(font, 6, buf2); if (buf2[0] != '\0') vim_snprintf(buf3, TEMP_BUF_SIZE, "%s %s", buf, buf2); else strcpy(buf3, buf); get_part(font, 4, buf2); if (!strcmp(buf2, "o") || !strcmp(buf2, "O")) vim_snprintf(buf, TEMP_BUF_SIZE, "%s oblique", buf3); else if (!strcmp(buf2, "i") || !strcmp(buf2, "I")) vim_snprintf(buf, TEMP_BUF_SIZE, "%s italic", buf3); if (!strcmp(buf, " ")) strcpy(buf, "-"); }
static PyObject * BufferRepr(PyObject *self) { static char repr[100]; BufferObject *this = (BufferObject *)(self); if (this->buf == INVALID_BUFFER_VALUE) { vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self)); return PyString_FromString(repr); } else { char *name = (char *)this->buf->b_fname; PyInt len; if (name == NULL) name = ""; len = strlen(name); if (len > 35) name = name + (35 - len); vim_snprintf(repr, 100, "<buffer %s%s>", len > 35 ? "..." : "", name); return PyString_FromString(repr); } }
void workshop_add_mark_type( int idx, char *colorspec, char *sign) { char gbuf[BUFSIZ]; /* buffer for sign name */ char cibuf[BUFSIZ]; /* color information */ char cbuf[BUFSIZ]; /* command buffer */ char *bp; #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) { char *cp; cp = strrchr(sign, '/'); if (cp == NULL) cp = sign; else cp++; /* skip '/' character */ wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx, colorspec && *colorspec ? colorspec : "<None>", cp); } #endif /* * Isolate the basename of sign in gbuf. We will use this for the * GroupName in the highlight command sent to vim. */ STRCPY(gbuf, gettail((char_u *)sign)); bp = strrchr(gbuf, '.'); if (bp != NULL) *bp = NUL; if (gbuf[0] != '-' && gbuf[1] != NUL) { if (colorspec != NULL && *colorspec) { vim_snprintf(cbuf, sizeof(cbuf), "highlight WS%s guibg=%s", gbuf, colorspec); coloncmd(cbuf, FALSE); vim_snprintf(cibuf, sizeof(cibuf), "linehl=WS%s", gbuf); } else cibuf[0] = NUL; vim_snprintf(cbuf, sizeof(cbuf), "sign define %d %s icon=%s", idx, cibuf, sign); coloncmd(cbuf, TRUE); } }
/* * Given a font name this function returns the part used in the first * scroll list. */ static void name_part(char *font, char *buf) { char buf2[TEMP_BUF_SIZE]; char buf3[TEMP_BUF_SIZE]; get_part(font, 2, buf2); get_part(font, 1, buf3); if (*buf3 != NUL) vim_snprintf(buf, TEMP_BUF_SIZE, "%s (%s)", buf2, buf3); else vim_snprintf(buf, TEMP_BUF_SIZE, "%s", buf2); }
/* * Convert a blob to a readable form: "[0x11,0x34]" */ char_u * blob2string(blob_T *blob, char_u **tofree, char_u *numbuf) { int i; garray_T ga; if (blob == NULL) { *tofree = NULL; return (char_u *)"[]"; } // Store bytes in the growarray. ga_init2(&ga, 1, 4000); ga_append(&ga, '['); for (i = 0; i < blob_len(blob); i++) { if (i > 0) ga_concat(&ga, (char_u *)","); vim_snprintf((char *)numbuf, NUMBUFLEN, "0x%02X", (int)blob_get(blob, i)); ga_concat(&ga, numbuf); } ga_append(&ga, ']'); *tofree = ga.ga_data; return *tofree; }
void wsdebug_log_init( char *log_var, /* env var with log file */ char *level_var) /* env var with ws_debug level */ { char *file; /* possible ws_debug output file */ char *cp; /* ws_dlevel pointer */ if (log_var && (file = getenv(log_var)) != NULL) { char buf[BUFSIZ]; vim_snprintf(buf, sizeof(buf), "date > %s", file); system(buf); ws_debug = fopen(file, "a"); if (level_var && (cp = getenv(level_var)) != NULL) { ws_dlevel = strtoul(cp, NULL, 0); } else { ws_dlevel = WS_TRACE; /* default level */ } #ifdef USE_WS_ERRORHANDLER XSetErrorHandler(errorHandler); #endif } } /* end wsdebug_log_init */
static void addMenu( char *menu, /* menu name */ char *accel, /* accelerator text (optional) */ char *verb) /* WorkShop action-verb */ { MenuMap *newMap; char cbuf[BUFSIZ]; if (menuMapSize >= menuMapMax) { newMap = realloc(menuMap, sizeof(MenuMap) * (menuMapMax + MENU_INC)); if (newMap != NULL) { menuMap = newMap; menuMapMax += MENU_INC; } } if (menuMapSize < menuMapMax) { menuMap[menuMapSize].name = strdup(menu); menuMap[menuMapSize].accel = accel && *accel ? strdup(accel) : NULL; menuMap[menuMapSize++].verb = strdup(verb); if (accel && workshopHotKeysEnabled) { vim_snprintf(cbuf, sizeof(cbuf), "map %s :wsverb %s<CR>", accel, verb); coloncmd(cbuf, TRUE); } } }
/// Stop using 'keymap'. static void keymap_unload(void) { char_u buf[KMAP_MAXLEN + 10]; char_u *save_cpo = p_cpo; kmap_T *kp; if (!(curbuf->b_kmap_state & KEYMAP_LOADED)) { return; } // Set 'cpoptions' to "C" to avoid line continuation. p_cpo = (char_u *)"C"; // clear the ":lmap"s kp = (kmap_T *)curbuf->b_kmap_ga.ga_data; for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from); (void)do_map(1, buf, LANGMAP, FALSE); xfree(kp[i].from); xfree(kp[i].to); } p_cpo = save_cpo; ga_clear(&curbuf->b_kmap_ga); curbuf->b_kmap_state &= ~KEYMAP_LOADED; status_redraw_curbuf(); }
static char * fixAccelText( char *ap) /* original acceleratorText */ { char buf[256]; /* build in temp buffer */ char *shift; /* shift string of "" */ if (ap == NULL) return NULL; /* If the accelerator is shifted use the vim form */ if (strncmp("Shift+", ap, 6) == 0) { shift = "S-"; ap += 6; } else shift = ""; if (*ap == 'F' && atoi(&ap[1]) > 0) { vim_snprintf(buf, sizeof(buf), "<%s%s>", shift, ap); return strdup(buf); } else return NULL; }
/* * List placed signs for "rbuf". If "rbuf" is NULL do it for all buffers. */ static void sign_list_placed(buf_T *rbuf, char_u *sign_group) { buf_T *buf; signlist_T *sign; char lbuf[MSG_BUF_LEN]; char group[MSG_BUF_LEN]; msg_puts_title(_("\n--- Signs ---")); msg_putchar('\n'); if (rbuf == NULL) buf = firstbuf; else buf = rbuf; while (buf != NULL && !got_int) { if (buf->b_signlist != NULL) { vim_snprintf(lbuf, MSG_BUF_LEN, _("Signs for %s:"), buf->b_fname); msg_puts_attr(lbuf, HL_ATTR(HLF_D)); msg_putchar('\n'); } FOR_ALL_SIGNS_IN_BUF(buf, sign) { if (got_int) break; if (!sign_in_group(sign, sign_group)) continue; if (sign->group != NULL) vim_snprintf(group, MSG_BUF_LEN, _(" group=%s"), sign->group->sg_name); else group[0] = '\0'; vim_snprintf(lbuf, MSG_BUF_LEN, _(" line=%ld id=%d%s name=%s priority=%d"), (long)sign->lnum, sign->id, group, sign_typenr2name(sign->typenr), sign->priority); msg_puts(lbuf); msg_putchar('\n'); } if (rbuf != NULL) break; buf = buf->b_next; } }
static void write_string(garray_T *gap, char_u *str) { char_u *res = str; char_u numbuf[NUMBUFLEN]; if (res == NULL) ga_concat(gap, (char_u *)"null"); else { ga_append(gap, '"'); while (*res != NUL) { int c = PTR2CHAR(res); switch (c) { case 0x08: ga_append(gap, '\\'); ga_append(gap, 'b'); break; case 0x09: ga_append(gap, '\\'); ga_append(gap, 't'); break; case 0x0a: ga_append(gap, '\\'); ga_append(gap, 'n'); break; case 0x0c: ga_append(gap, '\\'); ga_append(gap, 'f'); break; case 0x0d: ga_append(gap, '\\'); ga_append(gap, 'r'); break; case 0x22: /* " */ case 0x5c: /* \ */ ga_append(gap, '\\'); ga_append(gap, c); break; default: if (c >= 0x20) { #ifdef FEAT_MBYTE numbuf[mb_char2bytes(c, numbuf)] = NUL; #else numbuf[0] = c; numbuf[1] = NUL; #endif ga_concat(gap, numbuf); } else { vim_snprintf((char *)numbuf, NUMBUFLEN, "\\u%04lx", (long)c); ga_concat(gap, numbuf); } } mb_cptr_adv(res); } ga_append(gap, '"'); } }
static void updatePriority( Boolean subMenu) /* if True then start new submenu pri */ { int pri; /* priority of this menu/item */ char *p; p = strrchr(curMenuPriority, '.'); ASSERT(p != NULL); *p++ = NUL; pri = atoi(p) + 10; /* our new priority */ if (subMenu) vim_snprintf(curMenuPriority, sizeof(curMenuPriority), "%s.%d.0", curMenuPriority, pri); else vim_snprintf(curMenuPriority, sizeof(curMenuPriority), "%s.%d", curMenuPriority, pri); }
/// Set up key mapping tables for the 'keymap' option. /// /// @return NULL if OK, an error message for failure. This only needs to be /// used when setting the option, not later when the value has already /// been checked. char_u* keymap_init(void) { curbuf->b_kmap_state &= ~KEYMAP_INIT; if (*curbuf->b_p_keymap == NUL) { // Stop any active keymap and clear the table. Also remove // b:keymap_name, as no keymap is active now. keymap_unload(); do_cmdline_cmd("unlet! b:keymap_name"); } else { char *buf; size_t buflen; // Source the keymap file. It will contain a ":loadkeymap" command // which will call ex_loadkeymap() below. buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14; buf = xmalloc(buflen); // try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' vim_snprintf(buf, buflen, "keymap/%s_%s.vim", curbuf->b_p_keymap, p_enc); if (source_runtime((char_u *)buf, 0) == FAIL) { // try finding "keymap/'keymap'.vim" in 'runtimepath' vim_snprintf(buf, buflen, "keymap/%s.vim", curbuf->b_p_keymap); if (source_runtime((char_u *)buf, 0) == FAIL) { xfree(buf); return (char_u *)N_("E544: Keymap file not found"); } } xfree(buf); } return NULL; }
void workshop_save_file( char *filename) { char cbuf[BUFSIZ]; /* build vim command here */ #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) wstrace("workshop_save_file(%s)\n", filename); #endif /* Save the given file */ vim_snprintf(cbuf, sizeof(cbuf), "w %s", filename); coloncmd(cbuf, TRUE); }
/* * Given a font name this function returns the part used in the choice menu. */ static void encoding_part(char *font, char *buf) { char buf1[TEMP_BUF_SIZE]; char buf2[TEMP_BUF_SIZE]; *buf = '\0'; get_part(font, 13, buf1); get_part(font, 14, buf2); if (*buf1 != NUL && *buf2 != NUL) vim_snprintf(buf, TEMP_BUF_SIZE, "%s-%s", buf1, buf2); if (!strcmp(buf, " ")) strcpy(buf, "-"); }
static void load_buffer_by_name( char *filename, /* the file to load */ int lnum) /* an optional line number (or 0) */ { char lnumbuf[16]; /* make line number option for :e */ char cbuf[BUFSIZ]; /* command buffer */ if (lnum > 0) sprintf(lnumbuf, "+%d", lnum); else lnumbuf[0] = NUL; vim_snprintf(cbuf, sizeof(cbuf), "e %s %s", lnumbuf, filename); coloncmd(cbuf, False); }
static void printdigraph(digr_T *dp) { char_u buf[30]; char_u *p; int list_width; if ((dy_flags & DY_UHEX) || has_mbyte) { list_width = 13; } else { list_width = 11; } if (dp->result != 0) { if (msg_col > Columns - list_width) { msg_putchar('\n'); } if (msg_col) { while (msg_col % list_width != 0) { msg_putchar(' '); } } p = buf; *p++ = dp->char1; *p++ = dp->char2; *p++ = ' '; if (has_mbyte) { // add a space to draw a composing char on if (enc_utf8 && utf_iscomposing(dp->result)) { *p++ = ' '; } p += (*mb_char2bytes)(dp->result, p); } else { *p++ = (char_u)dp->result; } if (char2cells(dp->result) == 1) { *p++ = ' '; } assert(p >= buf); vim_snprintf((char *)p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result); msg_outtrans(buf); } }
void init_longVersion(void) { char *date_time = __DATE__ " " __TIME__; char *msg = _("%s (%s, compiled %s)"); size_t len = strlen(msg) + strlen(VIM_VERSION_LONG_ONLY) + strlen(VIM_VERSION_DATE_ONLY) + strlen(date_time); longVersion = (char *)alloc((unsigned)len); if (longVersion == NULL) longVersion = VIM_VERSION_LONG; else vim_snprintf(longVersion, len, msg, VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, date_time); }
/* * workshop_menu_begin() is passed the menu name. We determine its mnemonic * here and store its name and priority. */ void workshop_menu_begin( char *label) { vimmenu_T *menu; /* pointer to last menu */ int menuPriority = 0; /* priority of new menu */ char mnembuf[64]; /* store menubar mnemonics here */ char *name; /* label with a mnemonic */ char *p; /* used to find mnemonics */ int idx; /* index into mnembuf */ #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) wstrace("workshop_menu_begin()\n"); #endif /* * Look through all existing (non-PopUp and non-Toolbar) menus * and gather their mnemonics. Use this list to decide what * mnemonic should be used for label. */ idx = 0; mnembuf[idx++] = 'H'; /* H is mnemonic for Help */ for (menu = root_menu; menu != NULL; menu = menu->next) { if (menu_is_menubar(menu->name)) { p = strchr((char *)menu->name, '&'); if (p != NULL) mnembuf[idx++] = *++p; } if (menu->next != NULL && strcmp((char *) menu->next->dname, "Help") == 0) { menuPriority = menu->priority + 10; break; } } mnembuf[idx++] = NUL; name = addUniqueMnemonic(mnembuf, label); vim_snprintf(curMenuName, sizeof(curMenuName), "%s", name); sprintf(curMenuPriority, "%d.0", menuPriority); }
void workshop_delete_mark( char *filename, int markId) { char cbuf[BUFSIZ]; /* command buffer */ /* Delete mark */ #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) wstrace("workshop_delete_mark(%s, %d (id))\n", filename, markId); #endif vim_snprintf(cbuf, sizeof(cbuf), "sign unplace %d file=%s", markId, filename); coloncmd(cbuf, TRUE); }
void workshop_change_mark_type( char *filename, /* filename which gets the mark */ int markId, /* unique mark identifier */ int idx) /* which mark to use */ { char cbuf[BUFSIZ]; /* command buffer */ /* Change mark type */ #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) wstrace("workshop_change_mark_type(%s, %d, %d)\n", filename, markId, idx); #endif vim_snprintf(cbuf, sizeof(cbuf), "sign place %d name=%d file=%s", markId, idx, filename); coloncmd(cbuf, TRUE); }
static void printdigraph(digr_T *dp) { char_u buf[30]; char_u *p; int list_width; list_width = 13; if (dp->result != 0) { if (msg_col > Columns - list_width) { msg_putchar('\n'); } // Make msg_col a multiple of list_width by using spaces. if (msg_col % list_width != 0) { int spaces = (msg_col / list_width + 1) * list_width - msg_col; while (spaces--) { msg_putchar(' '); } } p = buf; *p++ = dp->char1; *p++ = dp->char2; *p++ = ' '; // add a space to draw a composing char on if (utf_iscomposing(dp->result)) { *p++ = ' '; } p += (*mb_char2bytes)(dp->result, p); if (char2cells(dp->result) == 1) { *p++ = ' '; } assert(p >= buf); vim_snprintf((char *)p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result); msg_outtrans(buf); } }
void workshop_set_mark( char *filename, /* filename which gets the mark */ int lineno, /* line number which gets the mark */ int markId, /* unique mark identifier */ int idx) /* which mark to use */ { char cbuf[BUFSIZ]; /* command buffer */ /* Set mark in a given file */ #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n", filename, lineno, markId, idx); #endif vim_snprintf(cbuf, sizeof(cbuf), "sign place %d line=%d name=%d file=%s", markId, lineno, idx, filename); coloncmd(cbuf, TRUE); }
/* * Goto the given mark in a file (e.g. show it). * If message is not null, display it in the footer. */ void workshop_goto_mark( char *filename, int markId, char *message) { char cbuf[BUFSIZ]; /* command buffer */ /* Goto mark */ #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) wstrace("workshop_goto_mark(%s, %d (id), %s)\n", filename, markId, message && *message && !(*message == ' ' && message[1] == NULL) ? message : "<None>"); #endif vim_snprintf(cbuf, sizeof(cbuf), "sign jump %d file=%s", markId, filename); coloncmd(cbuf, TRUE); if (message != NULL && *message != NUL) gui_mch_set_footer((char_u *)message); }
void workshop_set_option( char *option, /* name of a supported option */ char *value) /* value to set option to */ { char cbuf[BUFSIZ]; /* command buffer */ #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) { wstrace("workshop_set_option(%s, %s)\n", option, value); } #endif cbuf[0] = NUL; switch (*option) /* switch on 1st letter */ { case 's': if (strcmp(option, "syntax") == 0) vim_snprintf(cbuf, sizeof(cbuf), "syntax %s", value); else if (strcmp(option, "savefiles") == 0) ; /* XXX - Not yet implemented */ break; case 'l': if (strcmp(option, "lineno") == 0) sprintf(cbuf, "set %snu", (strcmp(value, "on") == 0) ? "" : "no"); break; case 'p': if (strcmp(option, "parentheses") == 0) sprintf(cbuf, "set %ssm", (strcmp(value, "on") == 0) ? "" : "no"); break; case 'w': /* this option is set by a direct call */ #ifdef WSDEBUG wsdebug("workshop_set_option: " "Got unexpected workshopkeys option"); #endif break; case 'b': /* these options are set from direct calls */ if (option[7] == NUL && strcmp(option, "balloon") == 0) { #ifdef WSDEBUG /* set by direct call to workshop_balloon_mode */ wsdebug("workshop_set_option: " "Got unexpected ballooneval option"); #endif } else if (strcmp(option, "balloondelay") == 0) { #ifdef WSDEBUG /* set by direct call to workshop_balloon_delay */ wsdebug("workshop_set_option: " "Got unexpected balloondelay option"); #endif } break; } if (cbuf[0] != NUL) coloncmd(cbuf, TRUE); }
static void write_string(garray_T *gap, char_u *str) { char_u *res = str; char_u numbuf[NUMBUFLEN]; if (res == NULL) ga_concat(gap, (char_u *)"\"\""); else { #if defined(FEAT_MBYTE) && defined(USE_ICONV) vimconv_T conv; char_u *converted = NULL; if (!enc_utf8) { /* Convert the text from 'encoding' to utf-8, the JSON string is * always utf-8. */ conv.vc_type = CONV_NONE; convert_setup(&conv, p_enc, (char_u*)"utf-8"); if (conv.vc_type != CONV_NONE) converted = res = string_convert(&conv, res, NULL); convert_setup(&conv, NULL, NULL); } #endif ga_append(gap, '"'); while (*res != NUL) { int c; #ifdef FEAT_MBYTE /* always use utf-8 encoding, ignore 'encoding' */ c = utf_ptr2char(res); #else c = *res; #endif switch (c) { case 0x08: ga_append(gap, '\\'); ga_append(gap, 'b'); break; case 0x09: ga_append(gap, '\\'); ga_append(gap, 't'); break; case 0x0a: ga_append(gap, '\\'); ga_append(gap, 'n'); break; case 0x0c: ga_append(gap, '\\'); ga_append(gap, 'f'); break; case 0x0d: ga_append(gap, '\\'); ga_append(gap, 'r'); break; case 0x22: /* " */ case 0x5c: /* \ */ ga_append(gap, '\\'); ga_append(gap, c); break; default: if (c >= 0x20) { #ifdef FEAT_MBYTE numbuf[utf_char2bytes(c, numbuf)] = NUL; #else numbuf[0] = c; numbuf[1] = NUL; #endif ga_concat(gap, numbuf); } else { vim_snprintf((char *)numbuf, NUMBUFLEN, "\\u%04lx", (long)c); ga_concat(gap, numbuf); } } #ifdef FEAT_MBYTE res += utf_ptr2len(res); #else ++res; #endif } ga_append(gap, '"'); #if defined(FEAT_MBYTE) && defined(USE_ICONV) vim_free(converted); #endif } }
/* * Encode "val" into "gap". * Return FAIL or OK. */ static int json_encode_item(garray_T *gap, typval_T *val, int copyID, int options) { char_u numbuf[NUMBUFLEN]; char_u *res; list_T *l; dict_T *d; switch (val->v_type) { case VAR_SPECIAL: switch (val->vval.v_number) { case VVAL_FALSE: ga_concat(gap, (char_u *)"false"); break; case VVAL_TRUE: ga_concat(gap, (char_u *)"true"); break; case VVAL_NONE: if ((options & JSON_JS) != 0 && (options & JSON_NO_NONE) == 0) /* empty item */ break; /* FALLTHROUGH */ case VVAL_NULL: ga_concat(gap, (char_u *)"null"); break; } break; case VAR_NUMBER: vim_snprintf((char *)numbuf, NUMBUFLEN, "%lld", (long long)val->vval.v_number); ga_concat(gap, numbuf); break; case VAR_STRING: res = val->vval.v_string; write_string(gap, res); break; case VAR_FUNC: case VAR_PARTIAL: case VAR_JOB: case VAR_CHANNEL: /* no JSON equivalent TODO: better error */ EMSG(_(e_invarg)); return FAIL; case VAR_LIST: l = val->vval.v_list; if (l == NULL) ga_concat(gap, (char_u *)"[]"); else { if (l->lv_copyID == copyID) ga_concat(gap, (char_u *)"[]"); else { listitem_T *li; l->lv_copyID = copyID; ga_append(gap, '['); for (li = l->lv_first; li != NULL && !got_int; ) { if (json_encode_item(gap, &li->li_tv, copyID, options & JSON_JS) == FAIL) return FAIL; if ((options & JSON_JS) && li->li_next == NULL && li->li_tv.v_type == VAR_SPECIAL && li->li_tv.vval.v_number == VVAL_NONE) /* add an extra comma if the last item is v:none */ ga_append(gap, ','); li = li->li_next; if (li != NULL) ga_append(gap, ','); } ga_append(gap, ']'); l->lv_copyID = 0; } } break; case VAR_DICT: d = val->vval.v_dict; if (d == NULL) ga_concat(gap, (char_u *)"{}"); else { if (d->dv_copyID == copyID) ga_concat(gap, (char_u *)"{}"); else { int first = TRUE; int todo = (int)d->dv_hashtab.ht_used; hashitem_T *hi; d->dv_copyID = copyID; ga_append(gap, '{'); for (hi = d->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi) if (!HASHITEM_EMPTY(hi)) { --todo; if (first) first = FALSE; else ga_append(gap, ','); if ((options & JSON_JS) && is_simple_key(hi->hi_key)) ga_concat(gap, hi->hi_key); else write_string(gap, hi->hi_key); ga_append(gap, ':'); if (json_encode_item(gap, &dict_lookup(hi)->di_tv, copyID, options | JSON_NO_NONE) == FAIL) return FAIL; } ga_append(gap, '}'); d->dv_copyID = 0; } } break; case VAR_FLOAT: #ifdef FEAT_FLOAT # if defined(HAVE_MATH_H) if (isnan(val->vval.v_float)) ga_concat(gap, (char_u *)"NaN"); else if (isinf(val->vval.v_float)) ga_concat(gap, (char_u *)"Infinity"); else # endif { vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", val->vval.v_float); ga_concat(gap, numbuf); } break; #endif case VAR_UNKNOWN: internal_error("json_encode_item()"); return FAIL; } return OK; }
/// ":loadkeymap" command: load the following lines as the keymap. /// /// @param eap void ex_loadkeymap(exarg_T *eap) { char_u *line; char_u *p; char_u *s; #define KMAP_LLEN 200 // max length of "to" and "from" together char_u buf[KMAP_LLEN + 11]; char_u *save_cpo = p_cpo; if (!getline_equal(eap->getline, eap->cookie, getsourceline)) { EMSG(_("E105: Using :loadkeymap not in a sourced file")); return; } // Stop any active keymap and clear the table. keymap_unload(); curbuf->b_kmap_state = 0; ga_init(&curbuf->b_kmap_ga, (int)sizeof(kmap_T), 20); // Set 'cpoptions' to "C" to avoid line continuation. p_cpo = (char_u *)"C"; // Get each line of the sourced file, break at the end. for (;;) { line = eap->getline(0, eap->cookie, 0); if (line == NULL) { break; } p = skipwhite(line); if ((*p != '"') && (*p != NUL)) { kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga); s = skiptowhite(p); kp->from = vim_strnsave(p, (size_t)(s - p)); p = skipwhite(s); s = skiptowhite(p); kp->to = vim_strnsave(p, (size_t)(s - p)); if ((STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN) || (*kp->from == NUL) || (*kp->to == NUL)) { if (*kp->to == NUL) { EMSG(_("E791: Empty keymap entry")); } xfree(kp->from); xfree(kp->to); --curbuf->b_kmap_ga.ga_len; } } xfree(line); } // setup ":lnoremap" to map the keys for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s %s", ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); (void)do_map(2, buf, LANGMAP, FALSE); } p_cpo = save_cpo; curbuf->b_kmap_state |= KEYMAP_LOADED; status_redraw_curbuf(); }
static void error_print(int state) { #ifndef DYNAMIC_RUBY #if !(defined(RUBY_VERSION) && RUBY_VERSION >= 19) \ && !(defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19) RUBYEXTERN VALUE ruby_errinfo; #endif #endif VALUE eclass; VALUE einfo; char buff[BUFSIZ]; #define TAG_RETURN 0x1 #define TAG_BREAK 0x2 #define TAG_NEXT 0x3 #define TAG_RETRY 0x4 #define TAG_REDO 0x5 #define TAG_RAISE 0x6 #define TAG_THROW 0x7 #define TAG_FATAL 0x8 #define TAG_MASK 0xf switch (state) { case TAG_RETURN: EMSG(_("E267: unexpected return")); break; case TAG_NEXT: EMSG(_("E268: unexpected next")); break; case TAG_BREAK: EMSG(_("E269: unexpected break")); break; case TAG_REDO: EMSG(_("E270: unexpected redo")); break; case TAG_RETRY: EMSG(_("E271: retry outside of rescue clause")); break; case TAG_RAISE: case TAG_FATAL: #ifdef RUBY19_OR_LATER eclass = CLASS_OF(rb_errinfo()); einfo = rb_obj_as_string(rb_errinfo()); #else eclass = CLASS_OF(ruby_errinfo); einfo = rb_obj_as_string(ruby_errinfo); #endif if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) { EMSG(_("E272: unhandled exception")); } else { VALUE epath; char *p; epath = rb_class_path(eclass); vim_snprintf(buff, BUFSIZ, "%s: %s", RSTRING_PTR(epath), RSTRING_PTR(einfo)); p = strchr(buff, '\n'); if (p) *p = '\0'; EMSG(buff); } break; default: vim_snprintf(buff, BUFSIZ, _("E273: unknown longjmp status %d"), state); EMSG(buff); break; } }