#include <stdio.h>
#include <stdarg.h>
/* This should probably be standardized by now... */
#ifdef _WIN32
# define PRIuSIZET "Iu"
# define PRIuOFFT "Id"
#else
# define PRIuSIZET "zu"
# define PRIuOFFT "zd"
#endif
void D (const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
fflush(stdout);
}
#include "stringy.h"
int main (void) {
/* this syntax is definitely going to be undocumented. */
string one = &(struct string){ "success", strlen("success") };
printf("direct initialization: %s\n", unstringify(one));
fflush(stdout);
/* this throws a warning without the typecast
* but it still works, just as planned. */
printf("direct access: %s\n", *(char **)one);
fflush(stdout);
/* do not string_free, it was allocated on the stack */
/* everything below here is how its *meant* to be used. :b */
string two = stringify("success");
printf("stringify: %s\n", unstringify(two));
fflush(stdout);
/* this is the most problematic part of this thing.
* using a string uninitialized is still detected,
* but the warning is cryptic at best, and crashes at runtime. */
string three = NULL;
/* or "static string *three;", but beware side-effects */
string_cpy(&three, &two);
printf("stringcpy: %s\n", unstringify(three));
fflush(stdout);
string_free(two);
string_free(three);
two = stringify("suc");
three = stringify("cess");
string_cat(&two, &three);
string_free(three);
printf("stringcat: %s\n", unstringify(two));
string_free(two);
return 0;
}