| 1046 | } |
| 1047 | |
| 1048 | static int git_parse_source(struct config_source *cs, config_fn_t fn, |
| 1049 | struct key_value_info *kvi, void *data, |
| 1050 | const struct config_options *opts) |
| 1051 | { |
| 1052 | int comment = 0; |
| 1053 | size_t baselen = 0; |
| 1054 | struct strbuf *var = &cs->var; |
| 1055 | int error_return = 0; |
| 1056 | char *error_msg = NULL; |
| 1057 | |
| 1058 | /* U+FEFF Byte Order Mark in UTF8 */ |
| 1059 | const char *bomptr = utf8_bom; |
| 1060 | |
| 1061 | /* For the parser event callback */ |
| 1062 | struct parse_event_data event_data = { |
| 1063 | CONFIG_EVENT_EOF, 0, opts |
| 1064 | }; |
| 1065 | |
| 1066 | for (;;) { |
| 1067 | int c; |
| 1068 | |
| 1069 | c = get_next_char(cs); |
| 1070 | if (bomptr && *bomptr) { |
| 1071 | /* We are at the file beginning; skip UTF8-encoded BOM |
| 1072 | * if present. Sane editors won't put this in on their |
| 1073 | * own, but e.g. Windows Notepad will do it happily. */ |
| 1074 | if (c == (*bomptr & 0377)) { |
| 1075 | bomptr++; |
| 1076 | continue; |
| 1077 | } else { |
| 1078 | /* Do not tolerate partial BOM. */ |
| 1079 | if (bomptr != utf8_bom) |
| 1080 | break; |
| 1081 | /* No BOM at file beginning. Cool. */ |
| 1082 | bomptr = NULL; |
| 1083 | } |
| 1084 | } |
| 1085 | if (c == '\n') { |
| 1086 | if (cs->eof) { |
| 1087 | if (do_event(cs, CONFIG_EVENT_EOF, &event_data) < 0) |
| 1088 | return -1; |
| 1089 | return 0; |
| 1090 | } |
| 1091 | if (do_event(cs, CONFIG_EVENT_WHITESPACE, &event_data) < 0) |
| 1092 | return -1; |
| 1093 | comment = 0; |
| 1094 | continue; |
| 1095 | } |
| 1096 | if (comment) |
| 1097 | continue; |
| 1098 | if (isspace(c)) { |
| 1099 | if (do_event(cs, CONFIG_EVENT_WHITESPACE, &event_data) < 0) |
| 1100 | return -1; |
| 1101 | continue; |
| 1102 | } |
| 1103 | if (c == '#' || c == ';') { |
| 1104 | if (do_event(cs, CONFIG_EVENT_COMMENT, &event_data) < 0) |
| 1105 | return -1; |
no test coverage detected