diff options
| -rw-r--r-- | parsing.c | 45 |
1 files changed, 17 insertions, 28 deletions
| @@ -71,36 +71,25 @@ static char *substr(const char *head, const char *tail) | |||
| 71 | 71 | ||
| 72 | static const char *parse_user(const char *t, char **name, char **email, unsigned long *date) | 72 | static const char *parse_user(const char *t, char **name, char **email, unsigned long *date) |
| 73 | { | 73 | { |
| 74 | const char *p = t; | 74 | const char *line_end = strchrnul(t, '\n'); |
| 75 | int mode = 1; | 75 | struct ident_split ident; |
| 76 | unsigned email_len; | ||
| 76 | 77 | ||
| 77 | while (p && *p) { | 78 | if (!split_ident_line(&ident, t, line_end - t)) { |
| 78 | if (mode == 1 && *p == '<') { | 79 | *name = substr(ident.name_begin, ident.name_end); |
| 79 | *name = substr(t, p - 1); | 80 | |
| 80 | t = p; | 81 | email_len = ident.mail_end - ident.mail_begin; |
| 81 | mode++; | 82 | *email = xmalloc(strlen("<") + email_len + strlen(">") + 1); |
| 82 | } else if (mode == 1 && *p == '\n') { | 83 | sprintf(*email, "<%.*s>", email_len, ident.mail_begin); |
| 83 | *name = substr(t, p); | 84 | |
| 84 | p++; | 85 | if (ident.date_begin) |
| 85 | break; | 86 | *date = strtoul(ident.date_begin, NULL, 10); |
| 86 | } else if (mode == 2 && *p == '>') { | ||
| 87 | *email = substr(t, p + 1); | ||
| 88 | t = p; | ||
| 89 | mode++; | ||
| 90 | } else if (mode == 2 && *p == '\n') { | ||
| 91 | *email = substr(t, p); | ||
| 92 | p++; | ||
| 93 | break; | ||
| 94 | } else if (mode == 3 && isdigit(*p)) { | ||
| 95 | *date = atol(p); | ||
| 96 | mode++; | ||
| 97 | } else if (*p == '\n') { | ||
| 98 | p++; | ||
| 99 | break; | ||
| 100 | } | ||
| 101 | p++; | ||
| 102 | } | 87 | } |
| 103 | return p; | 88 | |
| 89 | if (*line_end) | ||
| 90 | return line_end + 1; | ||
| 91 | else | ||
| 92 | return line_end; | ||
| 104 | } | 93 | } |
| 105 | 94 | ||
| 106 | #ifdef NO_ICONV | 95 | #ifdef NO_ICONV |
