- int line_num = 0;
- int err = 0;
- FILE *file;
- regex_t valid_line_re, comment_re;
-#define regmatch_size 12
- regmatch_t regmatch[regmatch_size];
-
- file = fopen(filename, "r");
- if (file == NULL) {
- opkg_perror(ERROR, "Failed to open %s", filename);
- err = -1;
- goto err0;
- }
-
- opkg_msg(INFO, "Loading conf file %s.\n", filename);
-
- err = xregcomp(&comment_re,
- "^[[:space:]]*(#.*|[[:space:]]*)$",
- REG_EXTENDED);
- if (err)
- goto err1;
-
- err = xregcomp(&valid_line_re,
- "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))"
- "[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))"
- "[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))"
- "([[:space:]]+([^[:space:]]+))?[[:space:]]*$",
- REG_EXTENDED);
- if (err)
- goto err2;
-
- while(1) {
- char *line;
- char *type, *name, *value, *extra;
-
- line_num++;
-
- line = file_read_line_alloc(file);
- if (line == NULL)
- break;
-
- if (regexec(&comment_re, line, 0, 0, 0) == 0)
- goto NEXT_LINE;
-
- if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
- opkg_msg(ERROR, "%s:%d: Ignoring invalid line: `%s'\n",
- filename, line_num, line);
- goto NEXT_LINE;
- }
-
- /* This has to be so ugly to deal with optional quotation marks */
- if (regmatch[2].rm_so > 0) {
- type = xstrndup(line + regmatch[2].rm_so,
- regmatch[2].rm_eo - regmatch[2].rm_so);
- } else {
- type = xstrndup(line + regmatch[3].rm_so,
- regmatch[3].rm_eo - regmatch[3].rm_so);
- }
-
- if (regmatch[5].rm_so > 0) {
- name = xstrndup(line + regmatch[5].rm_so,
- regmatch[5].rm_eo - regmatch[5].rm_so);
- } else {
- name = xstrndup(line + regmatch[6].rm_so,
- regmatch[6].rm_eo - regmatch[6].rm_so);
- }
-
- if (regmatch[8].rm_so > 0) {
- value = xstrndup(line + regmatch[8].rm_so,
- regmatch[8].rm_eo - regmatch[8].rm_so);
- } else {
- value = xstrndup(line + regmatch[9].rm_so,
- regmatch[9].rm_eo - regmatch[9].rm_so);
- }
-
- extra = NULL;
- if (regmatch[11].rm_so > 0) {
- extra = xstrndup (line + regmatch[11].rm_so,
- regmatch[11].rm_eo - regmatch[11].rm_so);
- }
-
- /* We use the conf->tmp_dest_list below instead of
- conf->pkg_dest_list because we might encounter an
- offline_root option later and that would invalidate the
- directories we would have computed in
- pkg_dest_list_init. (We do a similar thing with
- tmp_src_nv_pair_list for sake of symmetry.) */
- if (strcmp(type, "option") == 0) {
- opkg_conf_set_option(name, value);
- } else if (strcmp(type, "src") == 0) {
- if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) {
- pkg_src_list_append (pkg_src_list, name, value, extra, 0);
- } else {
- opkg_msg(ERROR, "Duplicate src declaration (%s %s). "
- "Skipping.\n", name, value);
- }
- } else if (strcmp(type, "src/gz") == 0) {
- if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) {
- pkg_src_list_append (pkg_src_list, name, value, extra, 1);
- } else {
- opkg_msg(ERROR, "Duplicate src declaration (%s %s). "
- "Skipping.\n", name, value);
- }
- } else if (strcmp(type, "dest") == 0) {
- nv_pair_list_append(&conf->tmp_dest_list, name, value);
- } else if (strcmp(type, "lists_dir") == 0) {
- conf->lists_dir = xstrdup(value);
- } else if (strcmp(type, "arch") == 0) {
- opkg_msg(INFO, "Supported arch %s priority (%s)\n", name, value);
- if (!value) {
- opkg_msg(NOTICE, "No priority given for architecture %s,"
- "defaulting to 10\n", name);
- value = xstrdup("10");
- }
- nv_pair_list_append(&conf->arch_list, name, value);
- } else {
- opkg_msg(ERROR, "%s:%d: Ignoring invalid line: `%s'\n",
- filename, line_num, line);
- }
-
- free(type);
- free(name);
- free(value);
- if (extra)
- free(extra);
+ int line_num = 0;
+ int err = 0;
+ FILE *file;
+ regex_t valid_line_re, comment_re;
+#define regmatch_size 14
+ regmatch_t regmatch[regmatch_size];
+
+ file = fopen(filename, "r");
+ if (file == NULL) {
+ opkg_perror(ERROR, "Failed to open %s", filename);
+ err = -1;
+ goto err0;
+ }
+
+ opkg_msg(INFO, "Loading conf file %s.\n", filename);
+
+ err = xregcomp(&comment_re,
+ "^[[:space:]]*(#.*|[[:space:]]*)$", REG_EXTENDED);
+ if (err)
+ goto err1;
+
+ err = xregcomp(&valid_line_re,
+ "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))"
+ "[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))"
+ "[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))"
+ "([[:space:]]+([^[:space:]]+))?([[:space:]]+(.*))?[[:space:]]*$",
+ REG_EXTENDED);
+ if (err)
+ goto err2;
+
+ while (1) {
+ char *line;
+ char *type, *name, *value, *extra;
+
+ line_num++;
+
+ line = file_read_line_alloc(file);
+ if (line == NULL)
+ break;
+
+ if (regexec(&comment_re, line, 0, 0, 0) == 0)
+ goto NEXT_LINE;
+
+ if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) ==
+ REG_NOMATCH) {
+ opkg_msg(ERROR, "%s:%d: Ignoring invalid line: `%s'\n",
+ filename, line_num, line);
+ goto NEXT_LINE;
+ }
+
+ /* This has to be so ugly to deal with optional quotation marks */
+ if (regmatch[2].rm_so > 0) {
+ type = xstrndup(line + regmatch[2].rm_so,
+ regmatch[2].rm_eo - regmatch[2].rm_so);
+ } else {
+ type = xstrndup(line + regmatch[3].rm_so,
+ regmatch[3].rm_eo - regmatch[3].rm_so);
+ }
+
+ if (regmatch[5].rm_so > 0) {
+ name = xstrndup(line + regmatch[5].rm_so,
+ regmatch[5].rm_eo - regmatch[5].rm_so);
+ } else {
+ name = xstrndup(line + regmatch[6].rm_so,
+ regmatch[6].rm_eo - regmatch[6].rm_so);
+ }
+
+ if (regmatch[8].rm_so > 0) {
+ value = xstrndup(line + regmatch[8].rm_so,
+ regmatch[8].rm_eo - regmatch[8].rm_so);
+ } else {
+ value = xstrndup(line + regmatch[9].rm_so,
+ regmatch[9].rm_eo - regmatch[9].rm_so);
+ }
+
+ extra = NULL;
+ if (regmatch[11].rm_so > 0) {
+ if (regmatch[13].rm_so > 0
+ && regmatch[13].rm_so != regmatch[13].rm_eo)
+ extra =
+ xstrndup(line + regmatch[11].rm_so,
+ regmatch[13].rm_eo -
+ regmatch[11].rm_so);
+ else
+ extra = xstrndup(line + regmatch[11].rm_so,
+ regmatch[11].rm_eo -
+ regmatch[11].rm_so);
+ }
+
+ if (regmatch[13].rm_so != regmatch[13].rm_eo
+ && strncmp(type, "dist", 4) != 0) {
+ opkg_msg(ERROR,
+ "%s:%d: Ignoring config line with trailing garbage: `%s'\n",
+ filename, line_num, line);
+ } else {
+
+ /* We use the conf->tmp_dest_list below instead of
+ conf->pkg_dest_list because we might encounter an
+ offline_root option later and that would invalidate the
+ directories we would have computed in
+ pkg_dest_list_init. (We do a similar thing with
+ tmp_src_nv_pair_list for sake of symmetry.) */
+ if (strcmp(type, "option") == 0) {
+ opkg_conf_set_option(name, value);
+ } else if (strcmp(type, "dist") == 0) {
+ if (!nv_pair_list_find
+ ((nv_pair_list_t *) dist_src_list, name)) {
+ pkg_src_list_append(dist_src_list, name,
+ value, extra, 0);
+ } else {
+ opkg_msg(ERROR,
+ "Duplicate dist declaration (%s %s). "
+ "Skipping.\n", name, value);
+ }
+ } else if (strcmp(type, "dist/gz") == 0) {
+ if (!nv_pair_list_find
+ ((nv_pair_list_t *) dist_src_list, name)) {
+ pkg_src_list_append(dist_src_list, name,
+ value, extra, 1);
+ } else {
+ opkg_msg(ERROR,
+ "Duplicate dist declaration (%s %s). "
+ "Skipping.\n", name, value);
+ }
+ } else if (strcmp(type, "src") == 0) {
+ if (!nv_pair_list_find
+ ((nv_pair_list_t *) pkg_src_list, name)) {
+ pkg_src_list_append(pkg_src_list, name,
+ value, extra, 0);
+ } else {
+ opkg_msg(ERROR,
+ "Duplicate src declaration (%s %s). "
+ "Skipping.\n", name, value);
+ }
+ } else if (strcmp(type, "src/gz") == 0) {
+ if (!nv_pair_list_find
+ ((nv_pair_list_t *) pkg_src_list, name)) {
+ pkg_src_list_append(pkg_src_list, name,
+ value, extra, 1);
+ } else {
+ opkg_msg(ERROR,
+ "Duplicate src declaration (%s %s). "
+ "Skipping.\n", name, value);
+ }
+ } else if (strcmp(type, "dest") == 0) {
+ nv_pair_list_append(&conf->tmp_dest_list, name,
+ value);
+ } else if (strcmp(type, "lists_dir") == 0) {
+ conf->lists_dir = xstrdup(value);
+ } else if (strcmp(type, "arch") == 0) {
+ opkg_msg(INFO,
+ "Supported arch %s priority (%s)\n",
+ name, value);
+ if (!value) {
+ opkg_msg(NOTICE,
+ "No priority given for architecture %s,"
+ "defaulting to 10\n", name);
+ value = xstrdup("10");
+ }
+ nv_pair_list_append(&conf->arch_list, name,
+ value);
+ } else {
+ opkg_msg(ERROR,
+ "%s:%d: Ignoring invalid line: `%s'\n",
+ filename, line_num, line);
+ }
+
+ }
+
+ free(type);
+ free(name);
+ free(value);
+ if (extra)
+ free(extra);