diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2024-08-23 14:50:17 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2024-08-23 14:50:17 +0000 |
commit | fd699e3549144942d2fb0f31c95d1a51f5aa61d5 (patch) | |
tree | b002965ec987f0fb6d60b7027bceaa403d06050e /games | |
parent | 02b051718c2c3ce5b00da94950f342f0fb00b8d8 (diff) |
slight improvement to index file parsing; ok mlarkin
Diffstat (limited to 'games')
-rw-r--r-- | games/atc/main.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/games/atc/main.c b/games/atc/main.c index d6c3c6491ef..47c51031bc9 100644 --- a/games/atc/main.c +++ b/games/atc/main.c @@ -1,4 +1,4 @@ -/* $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 $ */ /*- @@ -218,7 +218,7 @@ default_game(void) { 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); @@ -233,10 +233,13 @@ default_game(void) 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); @@ -252,7 +255,7 @@ okay_game(const char *s) 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); @@ -263,8 +266,9 @@ okay_game(const char *s) } 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"); @@ -291,7 +295,7 @@ int 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); @@ -304,6 +308,11 @@ list_games(void) 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++; } |