home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / prprf.h < prev    next >
C/C++ Source or Header  |  1998-07-21  |  5KB  |  136 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef prprf_h___
  20. #define prprf_h___
  21.  
  22. /*
  23. ** API for PR printf like routines. Supports the following formats
  24. **    %d - decimal
  25. **    %u - unsigned decimal
  26. **    %x - unsigned hex
  27. **    %X - unsigned uppercase hex
  28. **    %o - unsigned octal
  29. **    %hd, %hu, %hx, %hX, %ho - 16-bit versions of above
  30. **    %ld, %lu, %lx, %lX, %lo - 32-bit versions of above
  31. **    %lld, %llu, %llx, %llX, %llo - 64 bit versions of above
  32. **    %s - string
  33. **    %c - character
  34. **    %p - pointer (deals with machine dependent pointer size)
  35. **    %f - float
  36. **    %g - float
  37. */
  38. #include "prtypes.h"
  39. #include "prio.h"
  40. #include <stdio.h>
  41. #include <stdarg.h>
  42.  
  43. PR_BEGIN_EXTERN_C
  44.  
  45. /*
  46. ** sprintf into a fixed size buffer. Guarantees that a NUL is at the end
  47. ** of the buffer. Returns the length of the written output, NOT including
  48. ** the NUL, or (PRUint32)-1 if an error occurs.
  49. */
  50. PR_EXTERN(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...);
  51.  
  52. /*
  53. ** sprintf into a PR_MALLOC'd buffer. Return a pointer to the malloc'd
  54. ** buffer on success, NULL on failure. Call "PR_smprintf_free" to release
  55. ** the memory returned.
  56. */
  57. PR_EXTERN(char*) PR_smprintf(const char *fmt, ...);
  58.  
  59. /*
  60. ** Free the memory allocated, for the caller, by PR_smprintf
  61. */
  62. PR_EXTERN(void) PR_smprintf_free(char *mem);
  63.  
  64. /*
  65. ** "append" sprintf into a PR_MALLOC'd buffer. "last" is the last value of
  66. ** the PR_MALLOC'd buffer. sprintf will append data to the end of last,
  67. ** growing it as necessary using realloc. If last is NULL, PR_sprintf_append
  68. ** will allocate the initial string. The return value is the new value of
  69. ** last for subsequent calls, or NULL if there is a malloc failure.
  70. */
  71. PR_EXTERN(char*) PR_sprintf_append(char *last, const char *fmt, ...);
  72.  
  73. /*
  74. ** sprintf into a function. The function "f" is called with a string to
  75. ** place into the output. "arg" is an opaque pointer used by the stuff
  76. ** function to hold any state needed to do the storage of the output
  77. ** data. The return value is a count of the number of characters fed to
  78. ** the stuff function, or (PRUint32)-1 if an error occurs.
  79. */
  80. typedef PRIntn (*PRStuffFunc)(void *arg, const char *s, PRUint32 slen);
  81.  
  82. PR_EXTERN(PRUint32) PR_sxprintf(PRStuffFunc f, void *arg, const char *fmt, ...);
  83.  
  84. /*
  85. ** fprintf to a PRFileDesc
  86. */
  87. PR_EXTERN(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char *fmt, ...);
  88.  
  89. /*
  90. ** va_list forms of the above.
  91. */
  92. PR_EXTERN(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen, const char *fmt, va_list ap);
  93. PR_EXTERN(char*) PR_vsmprintf(const char *fmt, va_list ap);
  94. PR_EXTERN(char*) PR_vsprintf_append(char *last, const char *fmt, va_list ap);
  95. PR_EXTERN(PRUint32) PR_vsxprintf(PRStuffFunc f, void *arg, const char *fmt, va_list ap);
  96. PR_EXTERN(PRUint32) PR_vfprintf(struct PRFileDesc* fd, const char *fmt, va_list ap);
  97.  
  98. /*
  99. ***************************************************************************
  100. ** FUNCTION: PR_sscanf
  101. ** DESCRIPTION:
  102. **     PR_sscanf() scans the input character string, performs data
  103. **     conversions, and stores the converted values in the data objects
  104. **     pointed to by its arguments according to the format control
  105. **     string.
  106. **
  107. **     PR_sscanf() behaves the same way as the sscanf() function in the
  108. **     Standard C Library (stdio.h), with the following exceptions:
  109. **     - PR_sscanf() handles the NSPR integer and floating point types,
  110. **       such as PRInt16, PRInt32, PRInt64, and PRFloat64, whereas
  111. **       sscanf() handles the standard C types like short, int, long,
  112. **       and double.
  113. **     - PR_sscanf() has no multibyte character support, while sscanf()
  114. **       does.
  115. ** INPUTS:
  116. **     const char *buf
  117. **         a character string holding the input to scan
  118. **     const char *fmt
  119. **         the format control string for the conversions
  120. **     ...
  121. **         variable number of arguments, each of them is a pointer to
  122. **         a data object in which the converted value will be stored
  123. ** OUTPUTS: none
  124. ** RETURNS: PRInt32
  125. **     The number of values converted and stored.
  126. ** RESTRICTIONS:
  127. **    Multibyte characters in 'buf' or 'fmt' are not allowed.
  128. ***************************************************************************
  129. */
  130.  
  131. PR_EXTERN(PRInt32) PR_sscanf(const char *buf, const char *fmt, ...);
  132.  
  133. PR_END_EXTERN_C
  134.  
  135. #endif /* prprf_h___ */
  136.