Annotation of sbbs/src/sbbs3/js_sprintf.c, revision 1.1

1.1     ! root        1: /* js_sprintf.c */
        !             2: 
        !             3: /* Synchronet JavaScript "[s]printf" implementation */
        !             4: 
        !             5: /* $Id: js_sprintf.c,v 1.3 2006/12/21 21:27:19 deuce Exp $ */
        !             6: 
        !             7: /****************************************************************************
        !             8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
        !             9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
        !            10:  *                                                                                                                                                     *
        !            11:  * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            12:  *                                                                                                                                                     *
        !            13:  * This program is free software; you can redistribute it and/or                       *
        !            14:  * modify it under the terms of the GNU General Public License                         *
        !            15:  * as published by the Free Software Foundation; either version 2                      *
        !            16:  * of the License, or (at your option) any later version.                                      *
        !            17:  * See the GNU General Public License for more details: gpl.txt or                     *
        !            18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
        !            19:  *                                                                                                                                                     *
        !            20:  * Anonymous FTP access to the most recent released source is available at     *
        !            21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
        !            22:  *                                                                                                                                                     *
        !            23:  * Anonymous CVS access to the development source and modification history     *
        !            24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
        !            25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
        !            26:  *     (just hit return, no password is necessary)                                                     *
        !            27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
        !            28:  *                                                                                                                                                     *
        !            29:  * For Synchronet coding style and modification guidelines, see                                *
        !            30:  * http://www.synchro.net/source.html                                                                          *
        !            31:  *                                                                                                                                                     *
        !            32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
        !            33:  * format) via e-mail to [email protected]                                                                      *
        !            34:  *                                                                                                                                                     *
        !            35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
        !            36:  ****************************************************************************/
        !            37: 
        !            38: #include "sbbs.h"
        !            39: #include "xpprintf.h"  /* Hurrah for Deuce! */
        !            40: 
        !            41: char* DLLCALL
        !            42: js_sprintf(JSContext *cx, uint argn, uintN argc, jsval *argv)
        !            43: {
        !            44:        char*           p;
        !            45:     JSString*  str;
        !            46: 
        !            47:        if((p=js_ValueToStringBytes(cx, argv[argn++], NULL))==NULL)
        !            48:                return(NULL);
        !            49: 
        !            50:        p=xp_asprintf_start(p);
        !            51:     for(; argn<argc; argn++) {
        !            52:                if(JSVAL_IS_DOUBLE(argv[argn]))
        !            53:                        p=xp_asprintf_next(p,XP_PRINTF_CONVERT|XP_PRINTF_TYPE_DOUBLE,*JSVAL_TO_DOUBLE(argv[argn]));
        !            54:                else if(JSVAL_IS_INT(argv[argn]))
        !            55:                        p=xp_asprintf_next(p,XP_PRINTF_CONVERT|XP_PRINTF_TYPE_INT,JSVAL_TO_INT(argv[argn]));
        !            56:                else if(JSVAL_IS_BOOLEAN(argv[argn]) && xp_printf_get_type(p)!=XP_PRINTF_TYPE_CHARP)
        !            57:                        p=xp_asprintf_next(p,XP_PRINTF_CONVERT|XP_PRINTF_TYPE_INT,JSVAL_TO_BOOLEAN(argv[argn]));
        !            58:                else {
        !            59:                        if((str=JS_ValueToString(cx, argv[argn]))==NULL)
        !            60:                            return(NULL);
        !            61:                        p=xp_asprintf_next(p,XP_PRINTF_CONVERT|XP_PRINTF_TYPE_CHARP,JS_GetStringBytes(str));
        !            62:                }
        !            63:        }
        !            64: 
        !            65:        return xp_asprintf_end(p, NULL);
        !            66: 
        !            67: }
        !            68: 
        !            69: void DLLCALL
        !            70: js_sprintf_free(char* p)
        !            71: {
        !            72:        xp_asprintf_free(p);
        !            73: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.