got parse.y tweaks Rename things to better match their intended purpose. Tweak namespacing. Add a function for freeing config items that are dynamically allocated. Add 'struct gotconfig' to make room for potential global settings we might want to add later, instead of implementing just a list of remote repositories. ok tracey
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
diff --git a/got/got.h b/got/got.h
index e8f3306..985c532 100644
--- a/got/got.h
+++ b/got/got.h
@@ -14,19 +14,25 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-struct got_config_list_entry {
- TAILQ_ENTRY(got_config_list_entry) entry;
- const char *remote;
- const char *repository;
- const char *server;
- const char *protocol;
- const char *user;
+struct gotconfig_remote_repo {
+ TAILQ_ENTRY(gotconfig_remote_repo) entry;
+ char *name;
+ char *repository;
+ char *server;
+ char *protocol;
+ char *user;
+};
+TAILQ_HEAD(gotconfig_remote_repo_list, gotconfig_remote_repo);
+
+struct gotconfig {
+ struct gotconfig_remote_repo_list remotes;
+ int nremotes;
};
-TAILQ_HEAD(got_config_list, got_config_list_entry);
/*
* Parse individual gotconfig repository files
- * Load got_config_list_entry struct and insert to got_config_list TAILQ
*/
-const struct got_error* parse_got_config(struct got_config_list **,
- char *filename);
+const struct got_error* gotconfig_parse(struct gotconfig **,
+ const char *filename);
+
+void gotconfig_free(struct gotconfig *);
diff --git a/got/parse.y b/got/parse.y
index 8362222..c89d4f3 100644
--- a/got/parse.y
+++ b/got/parse.y
@@ -84,9 +84,9 @@ int symset(const char *, const char *, int);
char *symget(const char *);
const struct got_error* gerror = NULL;
-struct got_config_list_entry *gotconfig;
-struct got_config_list got_config_list;
-static const struct got_error* new_remote(struct got_config_list_entry **);
+struct gotconfig_remote_repo *remote;
+struct gotconfig gotconfig;
+static const struct got_error* new_remote(struct gotconfig_remote_repo **);
typedef struct {
union {
@@ -113,8 +113,8 @@ remoteopts2 : remoteopts2 remoteopts1 nl
| remoteopts1 optnl
;
remoteopts1 : REPOSITORY STRING {
- gotconfig->repository = strdup($2);
- if (gotconfig->repository == NULL) {
+ remote->repository = strdup($2);
+ if (remote->repository == NULL) {
free($2);
yyerror("strdup");
YYERROR;
@@ -122,8 +122,8 @@ remoteopts1 : REPOSITORY STRING {
free($2);
}
| SERVER STRING {
- gotconfig->server = strdup($2);
- if (gotconfig->server == NULL) {
+ remote->server = strdup($2);
+ if (remote->server == NULL) {
free($2);
yyerror("strdup");
YYERROR;
@@ -131,8 +131,8 @@ remoteopts1 : REPOSITORY STRING {
free($2);
}
| PROTOCOL STRING {
- gotconfig->protocol = strdup($2);
- if (gotconfig->protocol == NULL) {
+ remote->protocol = strdup($2);
+ if (remote->protocol == NULL) {
free($2);
yyerror("strdup");
YYERROR;
@@ -140,8 +140,8 @@ remoteopts1 : REPOSITORY STRING {
free($2);
}
| USER STRING {
- gotconfig->user = strdup($2);
- if (gotconfig->user == NULL) {
+ remote->user = strdup($2);
+ if (remote->user == NULL) {
free($2);
yyerror("strdup");
YYERROR;
@@ -152,21 +152,22 @@ remoteopts1 : REPOSITORY STRING {
remote : REMOTE STRING {
static const struct got_error* error;
- error = new_remote(&gotconfig);
+ error = new_remote(&remote);
if (error) {
free($2);
yyerror("%s", error->msg);
YYERROR;
}
- gotconfig->remote = strdup($2);
- if (gotconfig->remote == NULL) {
+ remote->name = strdup($2);
+ if (remote->name == NULL) {
free($2);
yyerror("strdup");
YYERROR;
}
free($2);
} '{' optnl remoteopts2 '}' {
- TAILQ_INSERT_TAIL(&got_config_list, gotconfig, entry);
+ TAILQ_INSERT_TAIL(&gotconfig.remotes, remote, entry);
+ gotconfig.nremotes++;
}
;
optnl : '\n' optnl
@@ -526,11 +527,12 @@ pushfile(struct file **nfile, const char *name)
}
static const struct got_error*
-new_remote(struct got_config_list_entry **gotconfig) {
- const struct got_error* error = NULL;
+new_remote(struct gotconfig_remote_repo **remote)
+{
+ const struct got_error *error = NULL;
- if (((*gotconfig) = calloc(1, sizeof(struct got_config_list_entry))) ==
- NULL)
+ *remote = calloc(1, sizeof(**remote));
+ if (*remote == NULL)
error = got_error_from_errno("calloc");
return error;
}
@@ -550,11 +552,11 @@ popfile(void)
}
const struct got_error*
-parse_got_config(struct got_config_list **conf_list, char *filename)
+gotconfig_parse(struct gotconfig **conf, const char *filename)
{
struct sym *sym, *next;
- *conf_list = NULL;
+ *conf = NULL;
/*
* We don't require that gotconfig exists
@@ -564,11 +566,10 @@ parse_got_config(struct got_config_list **conf_list, char *filename)
if (gerror && gerror->code == GOT_ERR_NO_CONFIG_FILE) {
gerror = NULL;
goto done;
- }
- else if (gerror)
+ } else if (gerror)
return gerror;
- TAILQ_INIT(&got_config_list);
+ TAILQ_INIT(&gotconfig.remotes);
topfile = file;
yyparse();
@@ -584,10 +585,27 @@ parse_got_config(struct got_config_list **conf_list, char *filename)
}
}
done:
- *conf_list = &got_config_list;
+ *conf = &gotconfig;
return gerror;
}
+void
+gotconfig_free(struct gotconfig *conf)
+{
+ struct gotconfig_remote_repo *remote;
+
+ while (!TAILQ_EMPTY(&conf->remotes)) {
+ remote = TAILQ_FIRST(&conf->remotes);
+ TAILQ_REMOVE(&conf->remotes, remote, entry);
+ free(remote->name);
+ free(remote->repository);
+ free(remote->server);
+ free(remote->protocol);
+ free(remote->user);
+ free(remote);
+ }
+}
+
int
symset(const char *nam, const char *val, int persist)
{