comparison cinst/mozilla.c @ 156:f09a0817e3bc

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 25 Mar 2014 09:23:47 +0100
parents fc9af77b06b9
children a46a4b443410
comparison
equal deleted inserted replaced
155:c0fdb8d336cf 156:f09a0817e3bc
52 #include <stdio.h> 52 #include <stdio.h>
53 #include <stdlib.h> 53 #include <stdlib.h>
54 #include <string.h> 54 #include <string.h>
55 55
56 #include <errorcodes.h> 56 #include <errorcodes.h>
57 #include <portpath.h>
57 #include <strhelp.h> 58 #include <strhelp.h>
58 59
59 #ifndef _WIN32 60 #ifndef _WIN32
60 #define UNIX 1 61 #define UNIX 1
61 #else 62 #else
62 #define UNIX 0 63 #define UNIX 0
63 #endif 64 #endif
65
66 #define LINEBUFLEN 1000
64 67
65 /** 68 /**
66 * @brief Global Return Code 69 * @brief Global Return Code
67 * 70 *
68 * This will be retuned by the programm and might be set to an 71 * This will be retuned by the programm and might be set to an
84 */ 87 */
85 static char ** 88 static char **
86 get_profile_dirs (char *inifile_name) 89 get_profile_dirs (char *inifile_name)
87 { 90 {
88 char **dirs = NULL; 91 char **dirs = NULL;
92 char *inifile_dirname;
89 FILE *inifile; 93 FILE *inifile;
90 char line[1000]; 94 char line[LINEBUFLEN];
95 char *key;
96 char *value;
97 char path[LINEBUFLEN];
98 char *fqpath;
91 bool inprofile = false; 99 bool inprofile = false;
100 bool relative_path = false;
92 101
93 if ((inifile = fopen(inifile_name, "r")) != NULL) 102 if ((inifile = fopen(inifile_name, "r")) != NULL)
94 { 103 {
95 while (fgets(line, 1000, inifile) != NULL) 104 inifile_dirname = port_dirname(inifile_name);
105 while (fgets(line, LINEBUFLEN, inifile) != NULL)
96 { 106 {
97 if (strncmp(line, "[Profile", 8) == 0) 107 /* Determine if we are in an profile section */
98 inprofile = true; 108 if (str_starts_with(line, "[Profile"))
109 {
110 relative_path = false;
111 inprofile = true;
112 }
99 else if (line[0] == '[') 113 else if (line[0] == '[')
100 inprofile = false; 114 inprofile = false;
101 if (inprofile && 115
102 (strncmp(line, "Path=", 5) == 0)) 116 /* If we are in a profile parse path related stuff */
103 strv_append(&dirs, line, strlen(line)); 117 if (inprofile)
118 {
119 value = line;
120 key = strsep(&value, "=");
121 str_trim(&value);
122 if (str_equal(key, "Path"))
123 {
124 if (relative_path)
125 snprintf(path, LINEBUFLEN, "%s/%s", inifile_dirname, value);
126 else
127 strncpy(path, value, LINEBUFLEN);
128 if ((fqpath = port_realpath(path)) != NULL)
129 {
130 strv_append(&dirs, fqpath, strlen(fqpath));
131 free (fqpath);
132 }
133 else
134 return_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST;
135 }
136 else if (str_equal(key, "IsRelative") &&
137 str_starts_with(value, "1"))
138 relative_path = true;
139 }
104 } 140 }
105 } 141 }
106 else 142 else
107 { 143 {
108 return_code |= WARN_MOZ_FAILED_TO_OPEN_INI; 144 return_code |= WARN_MOZ_FAILED_TO_OPEN_INI;
109 } 145 }
110
111 return dirs; 146 return dirs;
112 } 147 }
113 148
114 int 149 int
115 main () 150 main (int argc, char *argv[])
116 { 151 {
117 int x = 0; 152 int x = 0;
118 char **pdirs = 153 if (argc == 2)
119 get_profile_dirs("/home/wilde/.mozilla/firefox/profiles.ini"); 154 {
120 while (pdirs[x] != NULL) 155 char **pdirs =
121 puts(pdirs[x++]); 156 get_profile_dirs(argv[1]);
122 strv_free(pdirs); 157 if (pdirs != NULL)
158 {
159 while (pdirs[x] != NULL)
160 puts(pdirs[x++]);
161 strv_free(pdirs);
162 }
163 }
123 exit(return_code); 164 exit(return_code);
124 } 165 }

http://wald.intevation.org/projects/trustbridge/