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;
l = lookup_tag(p, "Name", "--");
free(p);
if (l)
return l;
if (l) {
if (!is_empty(l))
return l;
free(l);
}
err:
return strdup(d_name);
}

View file

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

View file

@ -27,6 +27,15 @@ int is_space(int c)
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 *e;

View file

@ -10,6 +10,8 @@ struct parser {
};
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 char *getpath(const char *d, const char *n);
extern char *strip(char *s);