void _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash, const char *file_name) { FILE *glob_file; char line[255]; glob_file = fopen (file_name, "r"); if (glob_file == NULL) return; /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars. * Blah */ while (fgets (line, 255, glob_file) != NULL) { char *colon; if (line[0] == '#') continue; colon = strchr (line, ':'); if (colon == NULL) continue; *(colon++) = '\000'; colon[strlen (colon) -1] = '\000'; _xdg_glob_hash_append_glob (glob_hash, colon, line); } fclose (glob_file); }
void _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash, const char *file_name) { FILE *glob_file; char line[255]; glob_file = fopen (file_name, "r"); if (glob_file == NULL) return; /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars. * Blah */ while (fgets (line, 255, glob_file) != NULL) { char *colon, *colon2; char *mimetype, *glob; int weight; if (line[0] == '#') continue; colon = strchr (line, ':'); if (colon == NULL) continue; *(colon++) = '\0'; colon[strlen (colon) -1] = '\0'; colon2 = strchr (colon, ':'); if (colon2) { *(colon2++) = '\000'; weight = atoi (line); mimetype = colon; glob = colon2; } else { weight = 50; mimetype = line; glob = colon; } _xdg_glob_hash_append_glob (glob_hash, glob, mimetype, weight); } fclose (glob_file); }
void _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash, const char *file_name, int version_two) { FILE *glob_file; char line[255]; char *p; glob_file = fopen (file_name, "r"); if (glob_file == NULL) return; /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars. * Blah */ while (fgets (line, 255, glob_file) != NULL) { char *colon; char *mimetype, *glob, *end; int weight; int case_sensitive; if (line[0] == '#' || line[0] == 0) continue; end = line + strlen(line) - 1; if (*end == '\n') *end = 0; p = line; if (version_two) { colon = strchr (p, ':'); if (colon == NULL) continue; *colon = 0; weight = atoi (p); p = colon + 1; } else weight = 50; colon = strchr (p, ':'); if (colon == NULL) continue; *colon = 0; mimetype = p; p = colon + 1; glob = p; case_sensitive = FALSE; colon = strchr (p, ':'); if (version_two && colon != NULL) { char *flag; /* We got flags */ *colon = 0; p = colon + 1; /* Flags end at next colon */ colon = strchr (p, ':'); if (colon != NULL) *colon = 0; flag = strstr (p, "cs"); if (flag != NULL && /* Start or after comma */ (flag == p || flag[-1] == ',') && /* ends with comma or end of string */ (flag[2] == 0 || flag[2] == ',')) case_sensitive = TRUE; } _xdg_glob_hash_append_glob (glob_hash, glob, mimetype, weight, case_sensitive); } fclose (glob_file); }