Mercurial > trustbridge
changeset 119:24ca8e2ceecf
First step of simple mozilla ini parser
extracts profile path configuration lines and prints them to stdout
for debugging..
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Sat, 22 Mar 2014 17:46:12 +0100 |
parents | d6a74464430b |
children | 702033705bb8 |
files | cinst/mozilla.c |
diffstat | 1 files changed, 51 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/cinst/mozilla.c Sat Mar 22 17:28:55 2014 +0100 +++ b/cinst/mozilla.c Sat Mar 22 17:46:12 2014 +0100 @@ -46,8 +46,13 @@ * encoded. * */ +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + #include <errorcodes.h> -#include <stdlib.h> +#include <strhelp.h> #ifndef _WIN32 #define UNIX 1 @@ -55,9 +60,18 @@ #define UNIX 0 #endif +/** + * @brief Global Return Code + * + * This will be retuned by the programm and might be set to an + * error code on fatal errors and to and warning code on non-fatal + * errors. In case of mor than one warning the warning codes will be + * ORed together. + */ +int return_code = 0; /** - * @brief Get a list of all mozilla profile directories + * @brief Get a list of all mozilla profile directories * * Read the profiles.ini and extract all profile paths from that. * @@ -66,12 +80,43 @@ * absolute path of the profile directories. The array needs to * be freed by the caller. */ -//char** -//get_profile_dirs(char* inifile) +static char ** +get_profile_dirs (char *inifile_name) +{ + char **dirs = NULL; + FILE *inifile; + char line[1000]; + bool inprofile = false; + if ((inifile = fopen(inifile_name, "r")) != NULL) + { + while (fgets(line, 1000, inifile) != NULL) + { + if (strncmp(line, "[Profile", 8) == 0) + inprofile = true; + else if (line[0] == '[') + inprofile = false; + if (inprofile && + (strncmp(line, "Path=", 5) == 0)) + strv_append(&dirs, line, strlen(line)); + } + } + else + { + return_code |= WARN_MOZ_FAILED_TO_OPEN_INI; + } + + return dirs; +} int -main() +main () { - exit(0); + int x = 0; + char **pdirs = + get_profile_dirs("/home/wilde/.mozilla/firefox/profiles.ini"); + while (pdirs[x] != NULL) + puts(pdirs[x++]); + strv_free(pdirs); + exit(return_code); }