|
|
1.1 ! root 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 ! 4: * License Version 1.1 (the "License"); you may not use this file ! 5: * except in compliance with the License. You may obtain a copy of ! 6: * the License at http://www.mozilla.org/NPL/ ! 7: * ! 8: * Software distributed under the License is distributed on an "AS ! 9: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or ! 10: * implied. See the License for the specific language governing ! 11: * rights and limitations under the License. ! 12: * ! 13: * The Original Code is Mozilla Communicator client code, released ! 14: * March 31, 1998. ! 15: * ! 16: * The Initial Developer of the Original Code is Netscape ! 17: * Communications Corporation. Portions created by Netscape are ! 18: * Copyright (C) 1998 Netscape Communications Corporation. All ! 19: * Rights Reserved. ! 20: * ! 21: * Contributor(s): ! 22: * ! 23: * Alternatively, the contents of this file may be used under the ! 24: * terms of the GNU Public License (the "GPL"), in which case the ! 25: * provisions of the GPL are applicable instead of those above. ! 26: * If you wish to allow use of your version of this file only ! 27: * under the terms of the GPL and not to allow others to use your ! 28: * version of this file under the NPL, indicate your decision by ! 29: * deleting the provisions above and replace them with the notice ! 30: * and other provisions required by the GPL. If you do not delete ! 31: * the provisions above, a recipient may use your version of this ! 32: * file under either the NPL or the GPL. ! 33: */ ! 34: ! 35: #ifndef jsprf_h___ ! 36: #define jsprf_h___ ! 37: ! 38: /* ! 39: ** API for PR printf like routines. Supports the following formats ! 40: ** %d - decimal ! 41: ** %u - unsigned decimal ! 42: ** %x - unsigned hex ! 43: ** %X - unsigned uppercase hex ! 44: ** %o - unsigned octal ! 45: ** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above ! 46: ** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above ! 47: ** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above ! 48: ** %s - string ! 49: ** %c - character ! 50: ** %p - pointer (deals with machine dependent pointer size) ! 51: ** %f - float ! 52: ** %g - float ! 53: */ ! 54: #include "jstypes.h" ! 55: #include <stdio.h> ! 56: #include <stdarg.h> ! 57: ! 58: JS_BEGIN_EXTERN_C ! 59: ! 60: /* ! 61: ** sprintf into a fixed size buffer. Guarantees that a NUL is at the end ! 62: ** of the buffer. Returns the length of the written output, NOT including ! 63: ** the NUL, or (JSUint32)-1 if an error occurs. ! 64: */ ! 65: extern JS_PUBLIC_API(JSUint32) JS_snprintf(char *out, JSUint32 outlen, const char *fmt, ...); ! 66: ! 67: /* ! 68: ** sprintf into a malloc'd buffer. Return a pointer to the malloc'd ! 69: ** buffer on success, NULL on failure. Call "JS_smprintf_free" to release ! 70: ** the memory returned. ! 71: */ ! 72: extern JS_PUBLIC_API(char*) JS_smprintf(const char *fmt, ...); ! 73: ! 74: /* ! 75: ** Free the memory allocated, for the caller, by JS_smprintf ! 76: */ ! 77: extern JS_PUBLIC_API(void) JS_smprintf_free(char *mem); ! 78: ! 79: /* ! 80: ** "append" sprintf into a malloc'd buffer. "last" is the last value of ! 81: ** the malloc'd buffer. sprintf will append data to the end of last, ! 82: ** growing it as necessary using realloc. If last is NULL, JS_sprintf_append ! 83: ** will allocate the initial string. The return value is the new value of ! 84: ** last for subsequent calls, or NULL if there is a malloc failure. ! 85: */ ! 86: extern JS_PUBLIC_API(char*) JS_sprintf_append(char *last, const char *fmt, ...); ! 87: ! 88: /* ! 89: ** sprintf into a function. The function "f" is called with a string to ! 90: ** place into the output. "arg" is an opaque pointer used by the stuff ! 91: ** function to hold any state needed to do the storage of the output ! 92: ** data. The return value is a count of the number of characters fed to ! 93: ** the stuff function, or (JSUint32)-1 if an error occurs. ! 94: */ ! 95: typedef JSIntn (*JSStuffFunc)(void *arg, const char *s, JSUint32 slen); ! 96: ! 97: extern JS_PUBLIC_API(JSUint32) JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...); ! 98: ! 99: /* ! 100: ** va_list forms of the above. ! 101: */ ! 102: extern JS_PUBLIC_API(JSUint32) JS_vsnprintf(char *out, JSUint32 outlen, const char *fmt, va_list ap); ! 103: extern JS_PUBLIC_API(char*) JS_vsmprintf(const char *fmt, va_list ap); ! 104: extern JS_PUBLIC_API(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap); ! 105: extern JS_PUBLIC_API(JSUint32) JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap); ! 106: ! 107: /* ! 108: *************************************************************************** ! 109: ** FUNCTION: JS_sscanf ! 110: ** DESCRIPTION: ! 111: ** JS_sscanf() scans the input character string, performs data ! 112: ** conversions, and stores the converted values in the data objects ! 113: ** pointed to by its arguments according to the format control ! 114: ** string. ! 115: ** ! 116: ** JS_sscanf() behaves the same way as the sscanf() function in the ! 117: ** Standard C Library (stdio.h), with the following exceptions: ! 118: ** - JS_sscanf() handles the NSPR integer and floating point types, ! 119: ** such as JSInt16, JSInt32, JSInt64, and JSFloat64, whereas ! 120: ** sscanf() handles the standard C types like short, int, long, ! 121: ** and double. ! 122: ** - JS_sscanf() has no multibyte character support, while sscanf() ! 123: ** does. ! 124: ** INPUTS: ! 125: ** const char *buf ! 126: ** a character string holding the input to scan ! 127: ** const char *fmt ! 128: ** the format control string for the conversions ! 129: ** ... ! 130: ** variable number of arguments, each of them is a pointer to ! 131: ** a data object in which the converted value will be stored ! 132: ** OUTPUTS: none ! 133: ** RETURNS: JSInt32 ! 134: ** The number of values converted and stored. ! 135: ** RESTRICTIONS: ! 136: ** Multibyte characters in 'buf' or 'fmt' are not allowed. ! 137: *************************************************************************** ! 138: */ ! 139: ! 140: extern JS_PUBLIC_API(JSInt32) JS_sscanf(const char *buf, const char *fmt, ...); ! 141: ! 142: JS_END_EXTERN_C ! 143: ! 144: #endif /* jsprf_h___ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.