MCPcopy Index your code
hub / github.com/NetHack/NetHack / dump_fmtstr

Function dump_fmtstr

src/windows.c:1125–1240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1123static time_t dumplog_now;
1124
1125char *
1126dump_fmtstr(
1127 const char *fmt,
1128 char *buf,
1129 boolean fullsubs) /* True -> full substitution for file name,
1130 * False -> partial substitution for '--showpaths'
1131 * feedback where there's no game in progress */
1132{
1133 const char *fp = fmt;
1134 char *bp = buf;
1135 int slen, len = 0;
1136 char tmpbuf[BUFSZ];
1137 char verbuf[BUFSZ];
1138 long uid;
1139 time_t now;
1140
1141 now = dumplog_now;
1142 uid = (long) getuid();
1143
1144 /*
1145 * Note: %t and %T assume that time_t is a 'long int' number of
1146 * seconds since some epoch value. That's quite iffy.... The
1147 * unit of time might be different and the datum size might be
1148 * some variant of 'long long int'. [Their main purpose is to
1149 * construct a unique file name rather than record the date and
1150 * time; violating the 'long seconds since base-date' assumption
1151 * may or may not interfere with that usage.]
1152 */
1153
1154 while (fp && *fp && len < BUFSZ - 1) {
1155 if (*fp == '%') {
1156 fp++;
1157 switch (*fp) {
1158 default:
1159 goto finish;
1160 case '\0': /* fallthrough */
1161 case '%': /* literal % */
1162 Sprintf(tmpbuf, "%%");
1163 break;
1164 case 't': /* game start, timestamp */
1165 if (fullsubs)
1166 Sprintf(tmpbuf, "%lu", (unsigned long) ubirthday);
1167 else
1168 Strcpy(tmpbuf, "{game start cookie}");
1169 break;
1170 case 'T': /* current time, timestamp */
1171 if (fullsubs)
1172 Sprintf(tmpbuf, "%lu", (unsigned long) now);
1173 else
1174 Strcpy(tmpbuf, "{current time cookie}");
1175 break;
1176 case 'd': /* game start, YYYYMMDDhhmmss */
1177 if (fullsubs)
1178 Sprintf(tmpbuf, "%08ld%06ld",
1179 yyyymmdd(ubirthday), hhmmss(ubirthday));
1180 else
1181 Strcpy(tmpbuf, "{game start date+time}");
1182 break;

Callers 3

nhl_dump_fmtstrFunction · 0.85
dump_open_logFunction · 0.85
reveal_pathsFunction · 0.85

Calls 5

getuidFunction · 0.85
yyyymmddFunction · 0.85
hhmmssFunction · 0.85
version_stringFunction · 0.85
strNsubstFunction · 0.85

Tested by

no test coverage detected