diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2021-08-09 19:59:06 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-08-09 19:59:06 +0200 |
commit | 8ee52affe7fd4daa03e002bc06611f0a8c3bcd5b (patch) | |
tree | bf218a0a9a9a0c8c182aca16491f5063f79acce5 | |
parent | eed9616120f60ad17d5e133f505bba5c559aee89 (diff) |
patch 8.2.3320: some local functions are not staticv8.2.3320
Problem: Some local functions are not static.
Solution: Add "static". Move snprintf() related code to strings.c.
(Yegappan Lakshmanan, closes #8734)
-rw-r--r-- | src/alloc.c | 24 | ||||
-rw-r--r-- | src/channel.c | 2 | ||||
-rw-r--r-- | src/dict.c | 2 | ||||
-rw-r--r-- | src/digraph.c | 4 | ||||
-rw-r--r-- | src/edit.c | 2 | ||||
-rw-r--r-- | src/ex_docmd.c | 2 | ||||
-rw-r--r-- | src/getchar.c | 2 | ||||
-rw-r--r-- | src/job.c | 2 | ||||
-rw-r--r-- | src/list.c | 2 | ||||
-rw-r--r-- | src/message.c | 1110 | ||||
-rw-r--r-- | src/profiler.c | 36 | ||||
-rw-r--r-- | src/proto/channel.pro | 1 | ||||
-rw-r--r-- | src/proto/dict.pro | 1 | ||||
-rw-r--r-- | src/proto/digraph.pro | 2 | ||||
-rw-r--r-- | src/proto/edit.pro | 1 | ||||
-rw-r--r-- | src/proto/ex_docmd.pro | 1 | ||||
-rw-r--r-- | src/proto/getchar.pro | 1 | ||||
-rw-r--r-- | src/proto/job.pro | 1 | ||||
-rw-r--r-- | src/proto/list.pro | 1 | ||||
-rw-r--r-- | src/proto/profiler.pro | 1 | ||||
-rw-r--r-- | src/proto/spell.pro | 1 | ||||
-rw-r--r-- | src/proto/vim9compile.pro | 2 | ||||
-rw-r--r-- | src/proto/vim9script.pro | 2 | ||||
-rw-r--r-- | src/proto/vim9type.pro | 1 | ||||
-rw-r--r-- | src/spell.c | 2 | ||||
-rw-r--r-- | src/strings.c | 1122 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 4 | ||||
-rw-r--r-- | src/vim9script.c | 292 | ||||
-rw-r--r-- | src/vim9type.c | 2 | ||||
-rw-r--r-- | src/window.c | 2 |
31 files changed, 1303 insertions, 1327 deletions
diff --git a/src/alloc.c b/src/alloc.c index 817e322fd4..a2dc08067d 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -232,19 +232,15 @@ lalloc(size_t size, int message) mem_pre_alloc_l(&size); #endif - /* - * Loop when out of memory: Try to release some memfile blocks and - * if some blocks are released call malloc again. - */ + // Loop when out of memory: Try to release some memfile blocks and + // if some blocks are released call malloc again. for (;;) { - /* - * Handle three kind of systems: - * 1. No check for available memory: Just return. - * 2. Slow check for available memory: call mch_avail_mem() after - * allocating KEEP_ROOM amount of memory. - * 3. Strict check for available memory: call mch_avail_mem() - */ + // Handle three kind of systems: + // 1. No check for available memory: Just return. + // 2. Slow check for available memory: call mch_avail_mem() after + // allocating KEEP_ROOM amount of memory. + // 3. Strict check for available memory: call mch_avail_mem() if ((p = malloc(size)) != NULL) { #ifndef HAVE_AVAIL_MEM @@ -268,10 +264,8 @@ lalloc(size_t size, int message) goto theend; #endif } - /* - * Remember that mf_release_all() is being called to avoid an endless - * loop, because mf_release_all() may call alloc() recursively. - */ + // Remember that mf_release_all() is being called to avoid an endless + // loop, because mf_release_all() may call alloc() recursively. if (releasing) break; releasing = TRUE; diff --git a/src/channel.c b/src/channel.c index 47c742d830..9c23bf47b9 100644 --- a/src/channel.c +++ b/src/channel.c @@ -3025,7 +3025,7 @@ channel_has_readahead(channel_T *channel, ch_part_T part) * Return a string indicating the status of the channel. * If "req_part" is not negative check that part. */ - char * + static char * channel_status(channel_T *channel, int req_part) { ch_part_T part; diff --git a/src/dict.c b/src/dict.c index 82397d5126..9ce6dda3d2 100644 --- a/src/dict.c +++ b/src/dict.c @@ -805,7 +805,7 @@ dict2string(typval_T *tv, int copyID, int restore_copyID) * Advance over a literal key, including "-". If the first character is not a * literal key character then "key" is returned. */ - char_u * + static char_u * skip_literal_key(char_u *key) { char_u *p; diff --git a/src/digraph.c b/src/digraph.c index 4a185399da..2bc02ebed0 100644 --- a/src/digraph.c +++ b/src/digraph.c @@ -2029,7 +2029,7 @@ registerdigraph(int char1, int char2, int n) * If they are valid, returns TRUE; otherwise, give an error message and * returns FALSE. */ - int + static int check_digraph_chars_valid(int char1, int char2) { if (char2 == 0) @@ -2193,7 +2193,7 @@ digraph_getlist_appendpair(digr_T *dp, list_T *l) li2->li_tv.vval.v_string = vim_strsave(buf); } - void + static void digraph_getlist_common(int list_all, typval_T *rettv) { int i; diff --git a/src/edit.c b/src/edit.c index 6bdeded000..93b1342db0 100644 --- a/src/edit.c +++ b/src/edit.c @@ -1587,7 +1587,7 @@ ins_ctrl_v(void) * Note that this doesn't wait for characters, they must be in the typeahead * buffer already. */ - int + static int decodeModifyOtherKeys(int c) { char_u *p = typebuf.tb_buf + typebuf.tb_off; diff --git a/src/ex_docmd.c b/src/ex_docmd.c index c071a7a137..0f0e627d12 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -598,7 +598,7 @@ do_cmdline_cmd(char_u *cmd) * Execute the "+cmd" argument of "edit +cmd fname" and the like. * This allows for using a range without ":" in Vim9 script. */ - int + static int do_cmd_argument(char_u *cmd) { return do_cmdline(cmd, NULL, NULL, diff --git a/src/getchar.c b/src/getchar.c index 196a3aeebd..52c77210a2 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -631,7 +631,7 @@ stuffRedoReadbuff(char_u *s) add_buff(&readbuf2, s, -1L); } - void + static void stuffReadbuffLen(char_u *s, long len) { add_buff(&readbuf1, s, len); @@ -1582,7 +1582,7 @@ invoke_prompt_interrupt(void) /* * Return the effective prompt for the specified buffer. */ - char_u * + static char_u * buf_prompt_text(buf_T* buf) { if (buf->b_prompt_text == NULL) diff --git a/src/list.c b/src/list.c index bf24cee222..afbc7d3958 100644 --- a/src/list.c +++ b/src/list.c @@ -620,7 +620,7 @@ list_append_tv(list_T *l, typval_T *tv) * As list_append_tv() but move the value instead of copying it. * Return FAIL when out of memory. */ - int + static int list_append_tv_move(list_T *l, typval_T *tv) { listitem_T *li = listitem_alloc(); diff --git a/src/message.c b/src/message.c index 7fb7264bd8..23b84fa831 100644 --- a/src/message.c +++ b/src/message.c @@ -12,7 +12,6 @@ */ #define MESSAGE_FILE // don't include prototype for smsg() -#define USING_FLOAT_STUFF #include "vim.h" @@ -4108,1112 +4107,3 @@ vim_dialog_yesnoallcancel( } #endif // FEAT_GUI_DIALOG || FEAT_CON_DIALOG - -#if defined(FEAT_EVAL) -static char *e_printf = N_("E766: Insufficient arguments for printf()"); - -/* - * Get number argument from "idxp" entry in "tvs". First entry is 1. - */ - static varnumber_T -tv_nr(typval_T *tvs, int *idxp) -{ - int idx = *idxp - 1; - varnumber_T n = 0; - int err = FALSE; - - if (tvs[idx].v_type == VAR_UNKNOWN) - emsg(_(e_printf)); - else - { - ++*idxp; - n = tv_get_number_chk(&tvs[idx], &err); - if (err) - n = 0; - } - return n; -} - -/* - * Get string argument from "idxp" entry in "tvs". First entry is 1. - * If "tofree" is NULL tv_get_string_chk() is used. Some types (e.g. List) - * are not converted to a string. - * If "tofree" is not NULL echo_string() is used. All types are converted to - * a string with the same format as ":echo". The caller must free "*tofree". - * Returns NULL for an error. - */ - static char * -tv_str(typval_T *tvs, int *idxp, char_u **tofree) -{ - int idx = *idxp - 1; - char *s = NULL; - static char_u numbuf[NUMBUFLEN]; - - if (tvs[idx].v_type == VAR_UNKNOWN) - emsg(_(e_printf)); - else - { - ++*idxp; - if (tofree != NULL) - s = (char *)echo_string(&tvs[idx], tofree, numbuf, get_copyID()); - else - s = (char *)tv_get_string_chk(&tvs[idx]); - } - return s; -} - -# ifdef FEAT_FLOAT -/* - * Get float argument from "idxp" entry in "tvs". First entry is 1. - */ - static double -tv_float(typval_T *tvs, int *idxp) -{ - int idx = *idxp - 1; - double f = 0; - - if (tvs[idx].v_type == VAR_UNKNOWN) - emsg(_(e_printf)); - else - { - ++*idxp; - if (tvs[idx].v_type == VAR_FLOAT) - f = tvs[idx].vval.v_float; - else if (tvs[idx].v_type == VAR_NUMBER) - f = (double)tvs[idx].vval.v_number; - else - emsg(_("E807: Expected Float argument for printf()")); - } - return f; -} -# endif -#endif - -#ifdef FEAT_FLOAT -/* - * Return the representation of infinity for printf() function: - * "-inf", "inf", "+inf", " inf", "-INF", "INF", "+INF" or " INF". - */ - static const char * -infinity_str(int positive, - char fmt_spec, - int force_sign, - int space_for_positive) -{ - static const char *table[] = - { - "-inf", "inf", "+inf", " inf", - "-INF", "INF", "+INF", " INF" - }; - int idx = positive * (1 + force_sign + force_sign * space_for_positive); - - if (ASCII_ISUPPER(fmt_spec)) - idx += 4; - return table[idx]; -} -#endif - -/* - * This code was included to provide a portable vsnprintf() and snprintf(). - * Some systems may provide their own, but we always use this one for - * consistency. - * - * This code is based on snprintf.c - a portable implementation of snprintf - * by Mark Martinec <mark.martinec@ijs.si>, Version 2.2, 2000-10-06. - * Included with permission. It was heavily modified to fit in Vim. - * The original code, including useful comments, can be found here: - * http://www.ijs.si/software/snprintf/ - * - * This snprintf() only supports the following conversion specifiers: - * s, c, d, u, o, x, X, p (and synonyms: i, D, U, O - see below) - * with flags: '-', '+', ' ', '0' and '#'. - * An asterisk is supported for field width as well as precision. - * - * Limited support for floating point was added: 'f', 'F', 'e', 'E', 'g', 'G'. - * - * Length modifiers 'h' (short int) and 'l' (long int) and 'll' (long long int) - * are supported. NOTE: for 'll' the argument is varnumber_T or uvarnumber_T. - * - * The locale is not used, the string is used as a byte string. This is only - * relevant for double-byte encodings where the second byte may be '%'. - * - * It is permitted for "str_m" to be zero, and it is permitted to specify NULL - * pointer for resulting string argument if "str_m" is zero (as per ISO C99). - * - * The return value is the number of characters which would be generated - * for the given input, excluding the trailing NUL. If this value - * is greater or equal to "str_m", not all characters from the result - * have been stored in str, output bytes beyond the ("str_m"-1) -th character - * are discarded. If "str_m" is greater than zero it is guaranteed - * the resulting string will be NUL-terminated. - */ - -/* - * When va_list is not supported we only define vim_snprintf(). - * - * vim_vsnprintf_typval() can be invoked with either "va_list" or a list of - * "typval_T". When the latter is not used it must be NULL. - */ - -// When generating prototypes all of this is skipped, cproto doesn't -// understand this. -#ifndef PROTO - -// Like vim_vsnprintf() but append to the string. - int -vim_snprintf_add(char *str, size_t str_m, const char *fmt, ...) -{ - va_list ap; - int str_l; - size_t len = STRLEN(str); - size_t space; - - if (str_m <= len) - space = 0; - else - space = str_m - len; - va_start(ap, fmt); - str_l = vim_vsnprintf(str + len, space, fmt, ap); - va_end(ap); - return str_l; -} - - int -vim_snprintf(char *str, size_t str_m, const char *fmt, ...) -{ - va_list ap; - int str_l; - - va_start(ap, fmt); - str_l = vim_vsnprintf(str, str_m, fmt, ap); - va_end(ap); - return str_l; -} - - int -vim_vsnprintf( - char *str, - size_t str_m, - const char *fmt, - va_list ap) -{ - return vim_vsnprintf_typval(str, str_m, fmt, ap, NULL); -} - - int -vim_vsnprintf_typval( - char *str, - size_t str_m, - const char *fmt, - va_list ap, - typval_T *tvs) -{ - size_t str_l = 0; - const char *p = fmt; - int arg_idx = 1; - - if (p == NULL) - p = ""; - while (*p != NUL) - { - if (*p != '%') - { - char *q = strchr(p + 1, '%'); - size_t n = (q == NULL) ? STRLEN(p) : (size_t)(q - p); - - // Copy up to the next '%' or NUL without any changes. - if (str_l < str_m) - { - size_t avail = str_m - str_l; - - mch_memmove(str + str_l, p, n > avail ? avail : n); - } - p += n; - str_l += n; - } - else - { - size_t min_field_width = 0, precision = 0; - int zero_padding = 0, precision_specified = 0, justify_left = 0; - int alternate_form = 0, force_sign = 0; - - // If both the ' ' and '+' flags appear, the ' ' flag should be - // ignored. - int space_for_positive = 1; - - // allowed values: \0, h, l, L - char length_modifier = '\0'; - - // temporary buffer for simple numeric->string conversion -# if defined(FEAT_FLOAT) -# define TMP_LEN 350 // On my system 1e308 is the biggest number possible. - // That sounds reasonable to use as the maximum - // printable. -# else -# define TMP_LEN 66 -# endif - char tmp[TMP_LEN]; - - // string address in case of string argument - const char *str_arg = NULL; - - // natural field width of arg without padding and sign - size_t str_arg_l; - - // unsigned char argument value - only defined for c conversion. - // N.B. standard explicitly states the char argument for the c - // conversion is unsigned - unsigned char uchar_arg; - - // number of zeros to be inserted for numeric conversions as - // required by the precision or minimal field width - size_t number_of_zeros_to_pad = 0; - - // index into tmp where zero padding is to be inserted - size_t zero_padding_insertion_ind = 0; - - // current conversion specifier character - char fmt_spec = '\0'; - - // buffer for 's' and 'S' specs - char_u *tofree = NULL; - - - p++; // skip '%' - - // parse flags - while (*p == '0' || *p == '-' || *p == '+' || *p == ' ' - || *p == '#' || *p == '\'') - { - switch (*p) - { - case '0': zero_padding = 1; break; - case '-': justify_left = 1; break; - case '+': force_sign = 1; space_for_positive = 0; break; - case ' ': force_sign = 1; - // If both the ' ' and '+' flags appear, the ' ' - // flag should be ignored - break; - case '#': alternate_form = 1; break; - case '\'': break; - } - p++; - } - // If the '0' and '-' flags both appear, the '0' flag should be - // ignored. - - // parse field width - if (*p == '*') - { - int j; - - p++; - j = -# if defined(FEAT_EVAL) - tvs != NULL ? tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, int); - if (j >= 0) - min_field_width = j; - else - { - min_field_width = -j; - justify_left = 1; - } - } - else if (VIM_ISDIGIT((int)(*p))) - { - // size_t could be wider than unsigned int; make sure we treat - // argument like common implementations do - unsigned int uj = *p++ - '0'; - - while (VIM_ISDIGIT((int)(*p))) - uj = 10 * uj + (unsigned int)(*p++ - '0'); - min_field_width = uj; - } - - // parse precision - if (*p == '.') - { - p++; - precision_specified = 1; - if (*p == '*') - { - int j; - - j = -# if defined(FEAT_EVAL) - tvs != NULL ? tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, int); - p++; - if (j >= 0) - precision = j; - else - { - precision_specified = 0; - precision = 0; - } - } - else if (VIM_ISDIGIT((int)(*p))) - { - // size_t could be wider than unsigned int; make sure we - // treat argument like common implementations do - unsigned int uj = *p++ - '0'; - - while (VIM_ISDIGIT((int)(*p))) - uj = 10 * uj + (unsigned int)(*p++ - '0'); - precision = uj; - } - } - - // parse 'h', 'l' and 'll' length modifiers - if (*p == 'h' || *p == 'l') - { - length_modifier = *p; - p++; - if (length_modifier == 'l' && *p == 'l') - { - // double l = __int64 / varnumber_T - length_modifier = 'L'; - p++; - } - } - fmt_spec = *p; - - // common synonyms: - switch (fmt_spec) - { - case 'i': fmt_spec = 'd'; break; - case 'D': fmt_spec = 'd'; length_modifier = 'l'; break; - case 'U': fmt_spec = 'u'; length_modifier = 'l'; break; - case 'O': fmt_spec = 'o'; length_modifier = 'l'; break; - default: break; - } - -# if defined(FEAT_EVAL) - switch (fmt_spec) - { - case 'd': case 'u': case 'o': case 'x': case 'X': - if (tvs != NULL && length_modifier == '\0') - length_modifier = 'L'; - } -# endif - - // get parameter value, do initial processing - switch (fmt_spec) - { - // '%' and 'c' behave similar to 's' regarding flags and field - // widths - case '%': - case 'c': - case 's': - case 'S': - str_arg_l = 1; - switch (fmt_spec) - { - case '%': - str_arg = p; - break; - - case 'c': - { - int j; - - j = -# if defined(FEAT_EVAL) - tvs != NULL ? tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, int); - // standard demands unsigned char - uchar_arg = (unsigned char)j; - str_arg = (char *)&uchar_arg; - break; - } - - case 's': - case 'S': - str_arg = -# if defined(FEAT_EVAL) - tvs != NULL ? tv_str(tvs, &arg_idx, &tofree) : -# endif - va_arg(ap, char *); - if (str_arg == NULL) - { - str_arg = "[NULL]"; - str_arg_l = 6; - } - // make sure not to address string beyond the specified - // precision !!! - else if (!precision_specified) - str_arg_l = strlen(str_arg); - // truncate string if necessary as requested by precision - else if (precision == 0) - str_arg_l = 0; - else - { - // Don't put the #if inside memchr(), it can be a - // macro. - // memchr on HP does not like n > 2^31 !!! - char *q = memchr(str_arg, '\0', - precision <= (size_t)0x7fffffffL ? precision - : (size_t)0x7fffffffL); - str_arg_l = (q == NULL) ? precision - : (size_t)(q - str_arg); - } - if (fmt_spec == 'S') - { - if (min_field_width != 0) - min_field_width += STRLEN(str_arg) - - mb_string2cells((char_u *)str_arg, -1); - if (precision) - { - char_u *p1; - size_t i = 0; - - for (p1 = (char_u *)str_arg; *p1; - p1 += mb_ptr2len(p1)) - { - i += (size_t)mb_ptr2cells(p1); - if (i > precision) - break; - } - str_arg_l = precision = p1 - (char_u *)str_arg; - } - } - break; - - default: - break; - } - break; - - case 'd': case 'u': - case 'b': case 'B': - case 'o': - case 'x': case 'X': - case 'p': - { - // NOTE: the u, b, o, x, X and p conversion specifiers - // imply the value is unsigned; d implies a signed - // value - - // 0 if numeric argument is zero (or if pointer is - // NULL for 'p'), +1 if greater than zero (or nonzero - // for unsigned arguments), -1 if negative (unsigned - // argument is never negative) - int arg_sign = 0; - - // only set for length modifier h, or for no length - // modifiers - int int_arg = 0; - unsigned int uint_arg = 0; - - // only set for length modifier l - long int long_arg = 0; - unsigned long int ulong_arg = 0; - - // only set for length modifier ll - varnumber_T llong_arg = 0; - uvarnumber_T ullong_arg = 0; - - // only set for b conversion - uvarnumber_T bin_arg = 0; - - // pointer argument value -only defined for p - // conversion - void *ptr_arg = NULL; - - if (fmt_spec == 'p') - { - length_modifier = '\0'; - ptr_arg = -# if defined(FEAT_EVAL) - tvs != NULL ? (void *)tv_str(tvs, &arg_idx, - NULL) : -# endif - va_arg(ap, void *); - if (ptr_arg != NULL) - arg_sign = 1; - } - else if (fmt_spec == 'b' || fmt_spec == 'B') - { - bin_arg = -# if defined(FEAT_EVAL) - tvs != NULL ? - (uvarnumber_T)tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, uvarnumber_T); - if (bin_arg != 0) - arg_sign = 1; - } - else if (fmt_spec == 'd') - { - // signed - switch (length_modifier) - { - case '\0': - case 'h': - // char and short arguments are passed as int. - int_arg = -# if defined(FEAT_EVAL) - tvs != NULL ? tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, int); - if (int_arg > 0) - arg_sign = 1; - else if (int_arg < 0) - arg_sign = -1; - break; - case 'l': - long_arg = -# if defined(FEAT_EVAL) - tvs != NULL ? tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, long int); - if (long_arg > 0) - arg_sign = 1; - else if (long_arg < 0) - arg_sign = -1; - break; - case 'L': - llong_arg = -# if defined(FEAT_EVAL) - tvs != NULL ? tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, varnumber_T); - if (llong_arg > 0) - arg_sign = 1; - else if (llong_arg < 0) - arg_sign = -1; - break; - } - } - else - { - // unsigned - switch (length_modifier) - { - case '\0': - case 'h': - uint_arg = -# if defined(FEAT_EVAL) - tvs != NULL ? (unsigned) - tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, unsigned int); - if (uint_arg != 0) - arg_sign = 1; - break; - case 'l': - ulong_arg = -# if defined(FEAT_EVAL) - tvs != NULL ? (unsigned long) - tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, unsigned long int); - if (ulong_arg != 0) - arg_sign = 1; - break; - case 'L': - ullong_arg = -# if defined(FEAT_EVAL) - tvs != NULL ? (uvarnumber_T) - tv_nr(tvs, &arg_idx) : -# endif - va_arg(ap, uvarnumber_T); - if (ullong_arg != 0) - arg_sign = 1; - break; - } - } - - str_arg = tmp; - str_arg_l = 0; - - // NOTE: - // For d, i, u, o, x, and X conversions, if precision is - // specified, the '0' flag should be ignored. This is so - // with Solaris 2.6, Digital UNIX 4.0, HPUX 10, Linux, - // FreeBSD, NetBSD; but not with Perl. - if (precision_specified) - zero_padding = 0; - if (fmt_spec == 'd') - { - if (force_sign && arg_sign >= 0) - tmp[str_arg_l++] = space_for_positive ? ' ' : '+'; - // leave negative numbers for sprintf to handle, to - // avoid handling tricky cases like (short int)-32768 - } - else if (alternate_form) - { - if (arg_sign != 0 - && (fmt_spec == 'b' || fmt_spec == 'B' - || fmt_spec == 'x' || fmt_spec == 'X') ) - { - tmp[str_arg_l++] = '0'; - tmp[str_arg_l++] = fmt_spec; - } - // alternate form should have no effect for p - // conversion, but ... - } - - zero_padding_insertion_ind = str_arg_l; - if (!precision_specified) - precision = 1; // default precision is 1 - if (precision == 0 && arg_sign == 0) - { - // When zero value is formatted with an explicit - // precision 0, the resulting formatted string is - // empty (d, i, u, b, B, o, x, X, p). - } - else - { - char f[6]; - int f_l = 0; - - // construct a simple format string for sprintf - f[f_l++] = '%'; - if (!length_modifier) - ; - else if (length_modifier == 'L') - { -# ifdef MSWIN - f[f_l++] = 'I'; - f[f_l++] = '6'; - f[f_l++] = '4'; -# else - f[f_l++] = 'l'; - f[f_l++] = 'l'; -# endif - } - else - f[f_l++] = length_modifier; - f[f_l++] = fmt_spec; - f[f_l++] = '\0'; - - if (fmt_spec == 'p') - str_arg_l += sprintf(tmp + str_arg_l, f, ptr_arg); - else if (fmt_spec == 'b' || fmt_spec == 'B') - { - char b[8 * sizeof(uvarnumber_T)]; - size_t b_l = 0; - uvarnumber_T bn = bin_arg; - - do - { - b[sizeof(b) - ++b_l] = '0' + (bn & 0x1); - bn >>= 1; - } - while (bn != 0); - - memcpy(tmp + str_arg_l, b + sizeof(b) - b_l, b_l); - str_arg_l += b_l; - } - else if (fmt_spec == 'd') - { - // signed - switch (length_modifier) - { - case '\0': str_arg_l += sprintf( - tmp + str_arg_l, f, - int_arg); - break; - case 'h': str_arg_l += sprintf( - tmp + str_arg_l, f, - (short)int_arg); - break; - case 'l': str_arg_l += sprintf( - tmp + str_arg_l, f, long_arg); - break; - case 'L': str_arg_l += sprintf( - tmp + str_arg_l, f, llong_arg); - break; - } - } - else - { - // unsigned - switch (length_modifier) - { - case '\0': str_arg_l += sprintf( - tmp + str_arg_l, f, - uint_arg); - break; - case 'h': str_arg_l += sprintf( - tmp + str_arg_l, f, - (unsigned short)uint_arg); - break; - case 'l': str_arg_l += sprintf( - tmp + str_arg_l, f, ulong_arg); - break; - case 'L': str_arg_l += sprintf( - tmp + str_arg_l, f, ullong_arg); - break; - } - } - - // include the optional minus sign and possible - // "0x" in the region before the zero padding - // insertion point - if (zero_padding_insertion_ind < str_arg_l - && tmp[zero_padding_insertion_ind] == '-') - zero_padding_insertion_ind++; - if (zero_padding_insertion_ind + 1 < str_arg_l - && tmp[zero_padding_insertion_ind] == '0' - && (tmp[zero_padding_insertion_ind + 1] == 'x' - || tmp[zero_padding_insertion_ind + 1] == 'X')) - zero_padding_insertion_ind += 2; - } - - { - size_t num_of_digits = str_arg_l - - zero_padding_insertion_ind; - - if (alternate_form && fmt_spec == 'o' - // unless zero is already the first - // character - && !(zero_padding_insertion_ind < str_arg_l - && tmp[zero_padding_insertion_ind] == '0')) - { - // assure leading zero for alternate-form - // octal numbers - if (!precision_specified - || precision < num_of_digits + 1) - { - // precision |