| 1 |
/* prettyprint helpers for rpgserv */ |
| 2 |
|
| 3 |
#ifndef __RPGSERV__PRETTYPRINT_H__GUARD |
| 4 |
#define __RPGSERV__PRETTYPRINT_H__GUARD |
| 5 |
|
| 6 |
/* |
| 7 |
* Important: keys and names must line up index-wise or everything |
| 8 |
* is going to go boom. ARRAY_SIZE() must also match, but we assert |
| 9 |
* on that. |
| 10 |
*/ |
| 11 |
|
| 12 |
static const char *genre_keys[] = { |
| 13 |
"apocalypse", "anime", "antropomorph", "cyberpunk", |
| 14 |
"fantasy", "horror", "multigenre", "realistic", |
| 15 |
"scifi", "steampunk" |
| 16 |
}; |
| 17 |
|
| 18 |
static const char *genre_names[] = { |
| 19 |
"Apocalypse", "Anime", "Anthromorph", "Cyberpunk", |
| 20 |
"Fantasy", "Horror", "Multi-genre", "Realistic", |
| 21 |
"Sci-Fi", "Steampunk" |
| 22 |
}; |
| 23 |
|
| 24 |
static const char *period_keys[] = { |
| 25 |
"prehistoric", "antiquity", "middleages", "earlymodern", |
| 26 |
"modern", "future" |
| 27 |
}; |
| 28 |
|
| 29 |
static const char *period_names[] = { |
| 30 |
"Prehistoric", "Antiquity", "Middle Ages", "Early Modern", |
| 31 |
"Modern", "Future" |
| 32 |
}; |
| 33 |
|
| 34 |
static const char *ruleset_keys[] = { |
| 35 |
"adnd", "homebrew", "dnd3.0", "dnd3.5", "dnd4.0", "freeform", |
| 36 |
"other", "owod", "nwod" |
| 37 |
}; |
| 38 |
|
| 39 |
static const char *ruleset_names[] = { |
| 40 |
"Advanced Dungeons & Dragons", "Homebrew", "Dungeons & Dragons 3.0", |
| 41 |
"Dungeons & Dragons 3.5", "Dungeons & Dragons 4.0", "Freeform", |
| 42 |
"Other", "Old World of Darkness", "New World of Darkness" |
| 43 |
}; |
| 44 |
|
| 45 |
static const char *rating_keys[] = { |
| 46 |
"g", "pg", "pg13", "r", "adult" |
| 47 |
}; |
| 48 |
|
| 49 |
static const char *rating_names[] = { |
| 50 |
"G", "PG", "PG-13", "R", "Adult" |
| 51 |
}; |
| 52 |
|
| 53 |
static const char *system_keys[] = { |
| 54 |
"charapproval", "diced", "sheeted" |
| 55 |
}; |
| 56 |
|
| 57 |
static const char *system_names[] = { |
| 58 |
"Character Approval", "Diced", "Character Sheets" |
| 59 |
}; |
| 60 |
|
| 61 |
static inline const char *rs_prettyprint_keywords(metadata_t *md, const char **keys, const char **values, |
| 62 |
unsigned int arraysize) |
| 63 |
{ |
| 64 |
static char ppbuf[BUFSIZE]; |
| 65 |
char parsebuf[BUFSIZE]; |
| 66 |
char *keyword = NULL, *pos; |
| 67 |
|
| 68 |
if (md == NULL) |
| 69 |
return "<none>"; |
| 70 |
|
| 71 |
*ppbuf = '\0'; |
| 72 |
|
| 73 |
mowgli_strlcpy(parsebuf, md->value, BUFSIZE); |
| 74 |
|
| 75 |
keyword = strtok_r(parsebuf, " ", &pos); |
| 76 |
if (keyword == NULL) |
| 77 |
return "<none>"; |
| 78 |
|
| 79 |
do |
| 80 |
{ |
| 81 |
unsigned int i; |
| 82 |
|
| 83 |
for (i = 0; i < arraysize; i++) |
| 84 |
{ |
| 85 |
if (!strcasecmp(keyword, keys[i])) |
| 86 |
{ |
| 87 |
if (*ppbuf != '\0') |
| 88 |
mowgli_strlcat(ppbuf, ", ", BUFSIZE); |
| 89 |
|
| 90 |
mowgli_strlcat(ppbuf, values[i], BUFSIZE); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
while ((keyword = strtok_r(NULL, " ", &pos)) != NULL); |
| 95 |
|
| 96 |
return ppbuf; |
| 97 |
} |
| 98 |
|
| 99 |
#endif |