X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Flib_tparm.c;h=53205d1711bf06fb86c563edc4433e959ee9e995;hp=6a19ab9f2c3562f0b8d249812411621accf260d6;hb=5e36f11feab6f790e0cc6f2c882a67b7b65e3b6b;hpb=7a27c7d49c2e8b4a1ecbe85b4423d647cbc75ea5;ds=sidebyside diff --git a/ncurses/tinfo/lib_tparm.c b/ncurses/tinfo/lib_tparm.c index 6a19ab9f..53205d17 100644 --- a/ncurses/tinfo/lib_tparm.c +++ b/ncurses/tinfo/lib_tparm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 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.73 2007/04/21 20:43:19 tom Exp $") +MODULE_ID("$Id: lib_tparm.c,v 1.84 2011/10/22 15:48:47 tom Exp $") /* * char * @@ -140,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); @@ -154,7 +153,7 @@ save_number(const char *fmt, int number, int len) if (len < 30) len = 30; /* actually log10(MAX_INT)+1 */ - get_space((unsigned) len + 1); + get_space((size_t) len + 1); (void) sprintf(TPS(out_buff) + TPS(out_used), fmt, number); TPS(out_used) += strlen(TPS(out_buff) + TPS(out_used)); @@ -165,8 +164,8 @@ save_char(int c) { if (c == 0) c = 0200; - get_space(1); - TPS(out_buff)[TPS(out_used)++] = c; + get_space((size_t) 1); + TPS(out_buff)[TPS(out_used)++] = (char) c; } static NCURSES_INLINE void @@ -451,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(int 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; @@ -479,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 @@ -489,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); } } @@ -504,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 */ @@ -559,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; @@ -743,7 +757,7 @@ tparam_internal(const char *string, va_list ap) cp++; } /* endwhile (*cp) */ - get_space(1); + get_space((size_t) 1); TPS(out_buff)[TPS(out_used)] = '\0'; T((T_RETURN("%s"), _nc_visbuf(TPS(out_buff)))); @@ -767,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; } @@ -788,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; +}