X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Flib_tparm.c;h=b1d79248d0fdbfb03914a1ffb3fb0d00893633be;hp=4ff98679dde3850377984632d264ee1ab5c83980;hb=8e25fff6a5f576b6dc35eb02b9783fa58680d07b;hpb=f70db18a0c3c6a828d8a5999be37239f01c9d98a diff --git a/ncurses/tinfo/lib_tparm.c b/ncurses/tinfo/lib_tparm.c index 4ff98679..b1d79248 100644 --- a/ncurses/tinfo/lib_tparm.c +++ b/ncurses/tinfo/lib_tparm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -40,10 +40,9 @@ #include #include -#include #include -MODULE_ID("$Id: lib_tparm.c,v 1.72 2006/12/30 20:14:43 tom Exp $") +MODULE_ID("$Id: lib_tparm.c,v 1.83 2011/05/21 18:11:56 tom Exp $") /* * char * @@ -105,43 +104,9 @@ MODULE_ID("$Id: lib_tparm.c,v 1.72 2006/12/30 20:14:43 tom Exp $") * resulting in x mod y, not the reverse. */ -#define STACKSIZE 20 - -typedef struct { - union { - int num; - char *str; - } data; - bool num_type; -} stack_frame; - NCURSES_EXPORT_VAR(int) _nc_tparm_err = 0; -#define NUM_VARS 26 - -typedef struct { -#ifdef TRACE - const char *tname; -#endif - const char *tparam_base; - - stack_frame stack[STACKSIZE]; - int stack_ptr; - - char *out_buff; - size_t out_size; - size_t out_used; - - char *fmt_buff; - size_t fmt_size; - - int dynamic_var[NUM_VARS]; - int static_vars[NUM_VARS]; -} tparm_state; - -static tparm_state tps; - -#define TPS(var) tps.var +#define TPS(var) _nc_prescreen.tparm_state.var #if NO_LEAKS NCURSES_EXPORT(void) @@ -174,7 +139,7 @@ save_text(const char *fmt, const char *s, int len) { size_t s_len = strlen(s); if (len > (int) s_len) - s_len = len; + s_len = (size_t) len; get_space(s_len + 1); @@ -200,7 +165,7 @@ save_char(int c) if (c == 0) c = 0200; get_space(1); - TPS(out_buff)[TPS(out_used)++] = c; + TPS(out_buff)[TPS(out_used)++] = (char) c; } static NCURSES_INLINE void @@ -485,12 +450,13 @@ _nc_tparm_analyze(const char *string, char *p_is_s[NUM_PARM], int *popcount) } static NCURSES_INLINE char * -tparam_internal(const char *string, va_list ap) +tparam_internal(bool use_TPARM_ARG, const char *string, va_list ap) { char *p_is_s[NUM_PARM]; TPARM_ARG param[NUM_PARM]; - int popcount; + int popcount = 0; int number; + int num_args; int len; int level; int x, y; @@ -513,7 +479,13 @@ tparam_internal(const char *string, va_list ap) if (TPS(fmt_buff) == 0) return NULL; - for (i = 0; i < max(popcount, number); i++) { + if (number > NUM_PARM) + number = NUM_PARM; + if (popcount > NUM_PARM) + popcount = NUM_PARM; + num_args = max(popcount, number); + + for (i = 0; i < num_args; i++) { /* * A few caps (such as plab_norm) have string-valued parms. * We'll have to assume that the caller knows the difference, since @@ -523,8 +495,11 @@ tparam_internal(const char *string, va_list ap) */ if (p_is_s[i] != 0) { p_is_s[i] = va_arg(ap, char *); - } else { + param[i] = 0; + } else if (use_TPARM_ARG) { param[i] = va_arg(ap, TPARM_ARG); + } else { + param[i] = (TPARM_ARG) va_arg(ap, int); } } @@ -538,19 +513,24 @@ tparam_internal(const char *string, va_list ap) TPS(stack_ptr) = 0; if (popcount == 0) { popcount = number; - for (i = number - 1; i >= 0; i--) - npush(param[i]); + for (i = number - 1; i >= 0; i--) { + if (p_is_s[i]) + spush(p_is_s[i]); + else + npush((int) param[i]); + } } #ifdef TRACE - if (_nc_tracing & TRACE_CALLS) { - for (i = 0; i < popcount; i++) { + if (USE_TRACEF(TRACE_CALLS)) { + for (i = 0; i < num_args; i++) { if (p_is_s[i] != 0) save_text(", %s", _nc_visbuf(p_is_s[i]), 0); else - save_number(", %d", param[i], 0); + save_number(", %d", (int) param[i], 0); } _tracef(T_CALLED("%s(%s%s)"), TPS(tname), _nc_visbuf(cp), TPS(out_buff)); TPS(out_used) = 0; + _nc_unlock_global(tracef); } #endif /* TRACE */ @@ -593,7 +573,7 @@ tparam_internal(const char *string, va_list ap) if (p_is_s[i]) spush(p_is_s[i]); else - npush(param[i]); + npush((int) param[i]); } break; @@ -801,7 +781,7 @@ tparm_varargs(NCURSES_CONST char *string,...) #ifdef TRACE TPS(tname) = "tparm"; #endif /* TRACE */ - result = tparam_internal(string, ap); + result = tparam_internal(TRUE, string, ap); va_end(ap); return result; } @@ -822,3 +802,19 @@ tparm_proto(NCURSES_CONST char *string, return tparm_varargs(string, a1, a2, a3, a4, a5, a6, a7, a8, a9); } #endif /* NCURSES_TPARM_VARARGS */ + +NCURSES_EXPORT(char *) +tiparm(const char *string,...) +{ + va_list ap; + char *result; + + _nc_tparm_err = 0; + va_start(ap, string); +#ifdef TRACE + TPS(tname) = "tiparm"; +#endif /* TRACE */ + result = tparam_internal(FALSE, string, ap); + va_end(ap); + return result; +}