| 1 | /* |
| 2 | * Copyright (C) 2005 Olaf Freyer ([email protected]) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef ASNPRINTF_H |
| 20 | #define ASNPRINTF_H |
| 21 | |
| 22 | #include <cstdarg> |
| 23 | #include <cstddef> |
| 24 | |
| 25 | #define ZEROPAD 1 /* pad with zero */ |
| 26 | #define SIGN 2 /* unsigned/signed long */ |
| 27 | #define PLUS 4 /* show plus */ |
| 28 | #define SPACE 8 /* space if plus */ |
| 29 | #define LEFT 16 /* left justified */ |
| 30 | #define SPECIAL 32 /* 0x */ |
| 31 | #define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ |
| 32 | |
| 33 | namespace pvpgn |
| 34 | { |
| 35 | |
| 36 | typedef struct { |
| 37 | const char* trans; /* points to the translation of the format */ |
| 38 | unsigned translen; /* how many chars in this translation */ |
| 39 | const char* fmt; /* points to the fmt location of this format spec */ |
| 40 | unsigned fmtlen; /* how many chars in this fmt spec */ |
| 41 | } t_fmtentry; |
| 42 | |
| 43 | /* "array" snprintf - this function prints all vargs into the prepared buffer, |
| 44 | * each of them as a \0 terminated string. The prepared char* [] locations will |
| 45 | * contain the starting position of each seperate string afterwards. |
| 46 | * The function returns the number of vargs that have been printed. |
| 47 | */ |
| 48 | int asnprintf(char * buffer, std::size_t size, t_fmtentry *entries, unsigned entlen, const char *fmt, ...); |
| 49 | int vasnprintf(char * buffer, std::size_t size, t_fmtentry *entries, unsigned entlen, const char *fmt, std::va_list args); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | #endif |