-/* $OpenBSD: main.c,v 1.32 2024/08/23 04:25:46 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.33 2024/08/23 14:50:16 deraadt Exp $ */
/* $NetBSD: main.c,v 1.4 1995/04/27 21:22:25 mycroft Exp $ */
/*-
{
FILE *fp;
static char file[256];
- char line[256], games[256];
+ char line[256], games[256], *p;
strlcpy(games, _PATH_GAMES, sizeof games);
strlcat(games, GAMES, sizeof games);
fclose(fp);
return (NULL);
}
- } while (line[0] == '#');
+ line[strcspn(line, "\n")] = '\0';
+ p = strrchr(line, '#');
+ if (p)
+ *p = '\0';
+ } while (line[0] == '\0');
fclose(fp);
- line[strcspn(line, "\n")] = '\0';
if (strlen(line) + strlen(_PATH_GAMES) >= sizeof(file)) {
warnx("default game name too long");
return (NULL);
FILE *fp;
static char file[256];
const char *ret = NULL;
- char line[256], games[256];
+ char line[256], games[256], *p;
strlcpy(games, _PATH_GAMES, sizeof games);
strlcat(games, GAMES, sizeof games);
}
while (fgets(line, sizeof(line), fp) != NULL) {
line[strcspn(line, "\n")] = '\0';
- if (line[0] == '#')
- continue;
+ p = strrchr(line, '#');
+ if (p)
+ *p = '\0';
if (strcmp(s, line) == 0) {
if (strlen(line) + strlen(_PATH_GAMES) >= sizeof(file)) {
warnx("game name too long");
list_games(void)
{
FILE *fp;
- char line[256], games[256];
+ char line[256], games[256], *p;
int num_games = 0;
strlcpy(games, _PATH_GAMES, sizeof games);
puts("available games:");
while (fgets(line, sizeof(line), fp) != NULL) {
line[strcspn(line, "\n")] = '\0';
+ p = strrchr(line, '#');
+ if (p)
+ *p = '\0';
+ if (line[0] == '\0')
+ continue;
printf(" %s\n", line);
num_games++;
}