~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to corelib/tsprintf.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   07/10/96
31
31
*
32
 
* $Revision: 6.8 $
 
32
* $Revision: 6.10 $
33
33
*
34
34
* File Description:
35
35
*       Memory- and MT-safe "sprintf()"
37
37
* Modifications:
38
38
* --------------------------------------------------------------------------
39
39
*
40
 
 * $Log: tsprintf.c,v $
41
 
 * Revision 6.8  2001/04/17 13:49:55  beloslyu
42
 
 * changes for Linux PPC, contributed by Gary Bader <gary.bader@utoronto.ca>
43
 
 *
44
 
 * Revision 6.7  2001/03/23 14:04:14  beloslyu
45
 
 * fix the name of strnlen to my_strnlen. It appears IBM's AIX has it's own function with this name
46
 
 *
47
 
 * Revision 6.6  2000/12/28 21:25:14  vakatov
48
 
 * Comment fixed
49
 
 *
50
 
 * Revision 6.5  2000/12/28 21:16:44  vakatov
51
 
 * va_args():  use "int" to fetch a "short int" argument
52
 
 *
53
 
 * Revision 6.4  2000/07/19 20:54:48  vakatov
54
 
 * minor cleanup
55
 
 *
56
 
 * Revision 6.3  1998/01/28 15:57:24  vakatov
57
 
 * Nlm_TSPrintfArgs():  always ignore the "vsprintf()"'s return value;
58
 
 * count the resultant string length using StrLen
59
 
 *
60
 
 * Revision 6.2  1997/12/04 22:05:35  vakatov
61
 
 * Check for NULL string arg;  cut the output instead of crashing the program
62
 
 *
63
 
 * Revision 6.1  1997/11/26 21:26:33  vakatov
64
 
 * Fixed errors and warnings issued by C and C++ (GNU and Sun) compilers
65
 
 *
66
 
 * Revision 6.0  1997/08/25 18:17:40  madden
67
 
 * Revision changed to 6.0
68
 
 *
69
 
 * Revision 1.5  1997/07/15 16:51:48  vakatov
70
 
 * vsprintf_count_args() -- allow "fmt" be NULL(just return 0, don't crash)
71
 
 *
72
 
 * Revision 1.4  1996/12/03 21:48:33  vakatov
73
 
 * Adopted for 32-bit MS-Windows DLLs
74
 
 *
75
 
 * Revision 1.3  1996/07/23  16:23:20  epstein
76
 
 * fix for non-SYSV UNIX systems (e.g., SunOS 4)
77
 
 *
78
 
 * Revision 1.2  1996/07/22  15:27:31  vakatov
79
 
 * Fixed "%c"-formatting bug
80
 
 *
81
 
 * Revision 1.1  1996/07/16  20:02:06  vakatov
82
 
 * Initial revision
83
 
 *
 
40
* $Log: tsprintf.c,v $
 
41
* Revision 6.10  2003/12/12 23:28:25  dondosha
 
42
* Correction for Opteron, at suggestion from Nicolas Joly
 
43
*
 
44
* Revision 6.9  2002/03/11 16:55:43  ivanov
 
45
* Fixed fp_count() -- error with round-up numbers
 
46
*
 
47
* Revision 6.8  2001/04/17 13:49:55  beloslyu
 
48
* changes for Linux PPC, contributed by Gary Bader <gary.bader@utoronto.ca>
 
49
*
 
50
* Revision 6.7  2001/03/23 14:04:14  beloslyu
 
51
* fix the name of strnlen to my_strnlen. It appears IBM's AIX has it's own 
 
52
* function with this name
 
53
*
 
54
* Revision 6.6  2000/12/28 21:25:14  vakatov
 
55
* Comment fixed
 
56
*
 
57
* Revision 6.5  2000/12/28 21:16:44  vakatov
 
58
* va_args():  use "int" to fetch a "short int" argument
 
59
*
 
60
* Revision 6.4  2000/07/19 20:54:48  vakatov
 
61
* minor cleanup
 
62
*
 
63
* Revision 6.3  1998/01/28 15:57:24  vakatov
 
64
* Nlm_TSPrintfArgs():  always ignore the "vsprintf()"'s return value;
 
65
* count the resultant string length using StrLen
 
66
*
 
67
* Revision 6.2  1997/12/04 22:05:35  vakatov
 
68
* Check for NULL string arg;  cut the output instead of crashing the program
 
69
*
 
70
* Revision 6.1  1997/11/26 21:26:33  vakatov
 
71
* Fixed errors and warnings issued by C and C++ (GNU and Sun) compilers
 
72
*
 
73
* Revision 6.0  1997/08/25 18:17:40  madden
 
74
* Revision changed to 6.0
 
75
*
 
76
* Revision 1.5  1997/07/15 16:51:48  vakatov
 
77
* vsprintf_count_args() -- allow "fmt" be NULL(just return 0, don't crash)
 
78
*
 
79
* Revision 1.4  1996/12/03 21:48:33  vakatov
 
80
* Adopted for 32-bit MS-Windows DLLs
 
81
*
 
82
* Revision 1.3  1996/07/23  16:23:20  epstein
 
83
* fix for non-SYSV UNIX systems (e.g., SunOS 4)
 
84
*
 
85
* Revision 1.2  1996/07/22  15:27:31  vakatov
 
86
* Fixed "%c"-formatting bug
 
87
*
 
88
* Revision 1.1  1996/07/16  20:02:06  vakatov
 
89
* Initial revision
84
90
*
85
91
* ==========================================================================
86
92
*/
94
100
 
95
101
#include <tsprintf.h>
96
102
 
 
103
#ifndef va_copy
 
104
# ifdef __va_copy
 
105
#  define va_copy __va_copy
 
106
# else
 
107
#  define va_copy(d,s) ((d) = (s))
 
108
# endif
 
109
#endif
97
110
 
98
111
/***********************************************************************
99
112
 *  INTERNAL
156
169
      counter = 1 + 1 + precision + 5;
157
170
      break;
158
171
    case 'f':
159
 
      counter = (power10 > 0.0 ? (int)power10 : 0) + 1 + 1 + precision;
 
172
      counter = (power10 > 0.0 ? (int)power10 + 1 : 0) + 1 + 1 + precision;
160
173
      break;
161
174
    case 'g':
162
175
      {
163
176
        int e_count = 1 + precision + 5;
164
177
        int f_count = 1 + precision +
165
 
          ((power10 < 0.0) ? (int)(-power10) + 1 : 0);
 
178
          ((power10 < 0.0) ? (int)(-power10) + 2 : 0);
166
179
        counter = (f_count < e_count) ? f_count : e_count;
167
180
        break;
168
181
      }
174
187
  if (precision == 0)
175
188
    counter--;
176
189
 
177
 
  if ((counter >= size)  &&
178
 
      (((fp > 0)  &&  (flags & (PLUS|SPACE)))  ||  (fp < 0)))
 
190
  if (((fp > 0)  &&  (flags & (PLUS|SPACE)))  ||  (fp < 0))
179
191
    counter++;
180
192
 
181
193
  return ((counter > size) ? counter : size);
471
483
  CharPtr temp_buf;
472
484
  size_t  cut_fmt;
473
485
  char   *x_fmt;
 
486
  va_list save;
474
487
 
475
488
#ifdef OS_UNIX_PPCLINUX
476
489
/*
481
494
  parsed_size = 2048;
482
495
  cut_fmt = 0;
483
496
#else
484
 
  parsed_size = vsprintf_count_args(fmt, args, &cut_fmt);
 
497
  va_copy(save, args);
 
498
  parsed_size = vsprintf_count_args(fmt, save, &cut_fmt);
 
499
  va_end(save);
485
500
  if (parsed_size == 0)
486
501
    return NULL;
487
502
#endif