Nguyen Anh Quynh | 6023ef7 | 2014-04-29 11:21:04 +0800 | [diff] [blame] | 1 | /* Capstone Disassembly Engine */ |
| 2 | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */ |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <stdarg.h> |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | #include "SStream.h" |
Nguyen Anh Quynh | edeeb04 | 2014-01-15 20:44:03 +0800 | [diff] [blame] | 9 | #include "cs_priv.h" |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 10 | |
| 11 | void SStream_Init(SStream *ss) |
| 12 | { |
| 13 | ss->index = 0; |
| 14 | ss->buffer[0] = '\0'; |
| 15 | } |
| 16 | |
| 17 | void SStream_concat(SStream *ss, const char *fmt, ...) |
| 18 | { |
Nguyen Anh Quynh | fc83a43 | 2014-02-22 23:26:27 +0800 | [diff] [blame] | 19 | #ifndef CAPSTONE_DIET |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 20 | va_list ap; |
Nguyen Anh Quynh | bb0744d | 2014-05-12 13:41:49 +0800 | [diff] [blame] | 21 | int ret; |
| 22 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 23 | va_start(ap, fmt); |
Axel 0vercl0k Souchet | 779d4c7 | 2014-05-08 23:44:49 +0100 | [diff] [blame] | 24 | ret = cs_vsnprintf(ss->buffer + ss->index, sizeof(ss->buffer) - (ss->index + 1), fmt, ap); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 25 | va_end(ap); |
| 26 | ss->index += ret; |
Nguyen Anh Quynh | fc83a43 | 2014-02-22 23:26:27 +0800 | [diff] [blame] | 27 | #endif |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /* |
| 31 | int main() |
| 32 | { |
| 33 | SStream ss; |
| 34 | int64_t i; |
| 35 | |
| 36 | SStream_Init(&ss); |
| 37 | |
| 38 | SStream_concat(&ss, "hello "); |
| 39 | SStream_concat(&ss, "%d - 0x%x", 200, 16); |
| 40 | |
| 41 | i = 123; |
| 42 | SStream_concat(&ss, " + %ld", i); |
| 43 | SStream_concat(&ss, "%s", "haaaaa"); |
| 44 | |
| 45 | printf("%s\n", ss.buffer); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | */ |