checking for empty slot name and game name

This commit is contained in:
p.kosyh 2010-01-19 07:48:53 +00:00
parent 224f0fc2de
commit 6467673e06
4 changed files with 21 additions and 4 deletions

View file

@ -92,8 +92,11 @@ static char *game_name(const char *path, const char *d_name)
goto err; goto err;
l = lookup_tag(p, "Name", "--"); l = lookup_tag(p, "Name", "--");
free(p); free(p);
if (l) if (l) {
return l; if (!is_empty(l))
return l;
free(l);
}
err: err:
return strdup(d_name); return strdup(d_name);
} }

View file

@ -51,9 +51,12 @@ static char *slot_name(const char *path)
FILE *fd; FILE *fd;
l = lookup_tag(path, "Name", "--"); l = lookup_tag(path, "Name", "--");
if (l) { if (l) {
char *s = fromgame(l); if (!is_empty(l)) {
char *s = fromgame(l);
free(l);
return s;
}
free(l); free(l);
return s;
} }
fd = fopen(path, "r"); fd = fopen(path, "r");
if (!fd) if (!fd)

View file

@ -27,6 +27,15 @@ int is_space(int c)
return (c == ' ' || c == '\t'); return (c == ' ' || c == '\t');
} }
int is_empty(const char *str)
{
if (!str || !*str)
return 1;
while (*str && !is_space(*str++))
return 0;
return 1;
}
char *strip(char *s) char *strip(char *s)
{ {
char *e; char *e;

View file

@ -10,6 +10,8 @@ struct parser {
}; };
extern int is_space(int c); extern int is_space(int c);
extern int is_empty(const char *str);
extern int parse_ini(const char *path, struct parser *cmd_parser); extern int parse_ini(const char *path, struct parser *cmd_parser);
extern char *getpath(const char *d, const char *n); extern char *getpath(const char *d, const char *n);
extern char *strip(char *s); extern char *strip(char *s);