Mercurial > trustbridge
comparison cinst/mozilla.c @ 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 | 02ad0922c01f |
children | 4bb5f295987b |
comparison
equal
deleted
inserted
replaced
118:d6a74464430b | 119:24ca8e2ceecf |
---|---|
44 * | 44 * |
45 * Mozilla also accepts the ini file on Windows even if it is UTF-16 | 45 * Mozilla also accepts the ini file on Windows even if it is UTF-16 |
46 * encoded. | 46 * encoded. |
47 * */ | 47 * */ |
48 | 48 |
49 #include <stdbool.h> | |
50 #include <stdio.h> | |
51 #include <stdlib.h> | |
52 #include <string.h> | |
53 | |
49 #include <errorcodes.h> | 54 #include <errorcodes.h> |
50 #include <stdlib.h> | 55 #include <strhelp.h> |
51 | 56 |
52 #ifndef _WIN32 | 57 #ifndef _WIN32 |
53 #define UNIX 1 | 58 #define UNIX 1 |
54 #else | 59 #else |
55 #define UNIX 0 | 60 #define UNIX 0 |
56 #endif | 61 #endif |
57 | 62 |
63 /** | |
64 * @brief Global Return Code | |
65 * | |
66 * This will be retuned by the programm and might be set to an | |
67 * error code on fatal errors and to and warning code on non-fatal | |
68 * errors. In case of mor than one warning the warning codes will be | |
69 * ORed together. | |
70 */ | |
71 int return_code = 0; | |
58 | 72 |
59 /** | 73 /** |
60 * @brief Get a list of all mozilla profile directories | 74 * @brief Get a list of all mozilla profile directories |
61 * | 75 * |
62 * Read the profiles.ini and extract all profile paths from that. | 76 * Read the profiles.ini and extract all profile paths from that. |
63 * | 77 * |
64 * @param[inifile] path of the profile.ini to read. | 78 * @param[inifile] path of the profile.ini to read. |
65 * @return NULL terminated array of strings containing containing the | 79 * @return NULL terminated array of strings containing containing the |
66 * absolute path of the profile directories. The array needs to | 80 * absolute path of the profile directories. The array needs to |
67 * be freed by the caller. | 81 * be freed by the caller. |
68 */ | 82 */ |
69 //char** | 83 static char ** |
70 //get_profile_dirs(char* inifile) | 84 get_profile_dirs (char *inifile_name) |
85 { | |
86 char **dirs = NULL; | |
87 FILE *inifile; | |
88 char line[1000]; | |
89 bool inprofile = false; | |
71 | 90 |
91 if ((inifile = fopen(inifile_name, "r")) != NULL) | |
92 { | |
93 while (fgets(line, 1000, inifile) != NULL) | |
94 { | |
95 if (strncmp(line, "[Profile", 8) == 0) | |
96 inprofile = true; | |
97 else if (line[0] == '[') | |
98 inprofile = false; | |
99 if (inprofile && | |
100 (strncmp(line, "Path=", 5) == 0)) | |
101 strv_append(&dirs, line, strlen(line)); | |
102 } | |
103 } | |
104 else | |
105 { | |
106 return_code |= WARN_MOZ_FAILED_TO_OPEN_INI; | |
107 } | |
108 | |
109 return dirs; | |
110 } | |
72 | 111 |
73 int | 112 int |
74 main() | 113 main () |
75 { | 114 { |
76 exit(0); | 115 int x = 0; |
116 char **pdirs = | |
117 get_profile_dirs("/home/wilde/.mozilla/firefox/profiles.ini"); | |
118 while (pdirs[x] != NULL) | |
119 puts(pdirs[x++]); | |
120 strv_free(pdirs); | |
121 exit(return_code); | |
77 } | 122 } |