Check-in [63a4e29f38]
Overview
Comment:Work on improving error handling
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:63a4e29f38fa4624901e3250c771df45f1259c67
User & Date: rkeene on 2014-11-24 22:35:25
Other Links: manifest | tags
Context
2014-11-24
22:35
Updated to use ABI version for soname check-in: d26243325f user: rkeene tags: trunk
22:35
Work on improving error handling check-in: 63a4e29f38 user: rkeene tags: trunk
20:12
Updated to build man pages into wiki check-in: 8659e921b0 user: rkeene tags: trunk
Changes

Modified libconfig.c from [4d749dd593] to [fc4f4efc0c].

42
43
44
45
46
47
48

49
50
51
52
53
54
55
..
82
83
84
85
86
87
88


89
90
91
92
93
94
95
...
132
133
134
135
136
137
138




139
140
141
142
143


144
145
146
147
148
149
150
...
152
153
154
155
156
157
158


159
160
161
162
163
164
165
...
721
722
723
724
725
726
727

728
729
730
731
732
733
734
735
736
737
738



739
740
741
742
743
744
745
....
1094
1095
1096
1097
1098
1099
1100

1101
1102
1103
1104
1105
1106
1107
....
1135
1136
1137
1138
1139
1140
1141






1142
1143
1144
1145
1146
1147
1148
1149
1150

struct lc_varhandler_st *varhandlers = NULL;
lc_err_t lc_errno = LC_ERR_NONE;
const char *lc_err_usererrmsg = NULL;
const char *lc_errfile = NULL;
int lc_optind = 0;
int lc_errline = 0;


extern char **environ;

static int lc_process_var_string(void *data, const char *value, const char **endptr) {
	char **dataval;

	dataval = data;
................................................................................

	memcpy(data, ghbn_ret->h_addr_list[0], sizeof(*data));

	return(0);
}

static int lc_process_var_hostname6(void *data, const char *value, const char **endptr) {


	return(-1);
}

static int lc_process_var_ip4(uint32_t *data, const char *value, const char **endptr) {
	uint32_t ipval = 0, curr_ipval = 0;
	const char *valptr;
	int retval = 0;
................................................................................
		retval = -1;
	}

	if (retval == 0) {
		ipval |= curr_ipval << 24;
		*data = ipval;
	}





	return(retval);
}

static int lc_process_var_ip6(void *data, const char *value, const char **endptr) {


	return(-1);
}

static int lc_process_var_addr4(uint32_t *data, const char *value, const char **endptr) {
	int lc_pv_ret;

	lc_pv_ret = lc_process_var_ip4(data, value, endptr);
................................................................................
		return(lc_pv_ret);
	}

	lc_pv_ret = lc_process_var_hostname4(data, value, endptr);
	if (lc_pv_ret == 0) {
		return(lc_pv_ret);
	}



	return(-1);
}

static int lc_process_var_addr6(void *data, const char *value, const char **endptr) {
	int lc_pv_ret;

................................................................................
				} else {
					cmdargidx++;
					if (cmdargidx >= argc) {
						fprintf(stderr, "Argument required.\n");
						lc_errfile = local_lc_errfile;
						lc_errline = local_lc_errline;
						lc_errno = LC_ERR_BADFORMAT;

						free(usedargv);
						free(newargv);
						return(-1);
					}
					cmdoptarg = argv[cmdargidx];
					newargv[newargvidx++] = cmdoptarg;
					usedargv[cmdargidx] = 1;
				}

				chkretval = lc_handle(handler, handler->var, NULL, cmdoptarg, LC_FLAGS_CMDLINE);
				if (chkretval < 0) {



					retval = -1;
				}

				break;
			}

			if (handler == NULL) {
................................................................................
void lc_seterrstr(const char *usererrmsg) {
	lc_err_usererrmsg = strdup(usererrmsg);
}

char *lc_geterrstr(void) {
	static char retval[512];
	const char *errmsg = NULL;


	switch (lc_errno) {
		case LC_ERR_NONE:
			errmsg = "Success";
			break;
		case LC_ERR_INVCMD:
			errmsg = "Invalid command or option";
................................................................................
	 * about unhandled enum values.
	 */
	if (errmsg == NULL) {
		errmsg = "Unknown error";
	}

	if (lc_errfile == NULL) {






		snprintf(retval, sizeof(retval), "%s:%i: %s", "<no file>", lc_errline, errmsg);
	} else {
		snprintf(retval, sizeof(retval), "%s:%i: %s", lc_errfile, lc_errline, errmsg);
	}

	retval[sizeof(retval) - 1] = '\0';

	return(retval);
}







>







 







>
>







 







>
>
>
>





>
>







 







>
>







 







>











>
>
>







 







>







 







>
>
>
>
>
>
|

|






42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
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
...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
....
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
....
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172

struct lc_varhandler_st *varhandlers = NULL;
lc_err_t lc_errno = LC_ERR_NONE;
const char *lc_err_usererrmsg = NULL;
const char *lc_errfile = NULL;
int lc_optind = 0;
int lc_errline = 0;
char *lc_erroptname =  NULL;

extern char **environ;

static int lc_process_var_string(void *data, const char *value, const char **endptr) {
	char **dataval;

	dataval = data;
................................................................................

	memcpy(data, ghbn_ret->h_addr_list[0], sizeof(*data));

	return(0);
}

static int lc_process_var_hostname6(void *data, const char *value, const char **endptr) {
	lc_errno = LC_ERR_BADFORMAT;

	return(-1);
}

static int lc_process_var_ip4(uint32_t *data, const char *value, const char **endptr) {
	uint32_t ipval = 0, curr_ipval = 0;
	const char *valptr;
	int retval = 0;
................................................................................
		retval = -1;
	}

	if (retval == 0) {
		ipval |= curr_ipval << 24;
		*data = ipval;
	}

	if (retval < 0) {
		lc_errno = LC_ERR_BADFORMAT;
	}

	return(retval);
}

static int lc_process_var_ip6(void *data, const char *value, const char **endptr) {
	lc_errno = LC_ERR_BADFORMAT;

	return(-1);
}

static int lc_process_var_addr4(uint32_t *data, const char *value, const char **endptr) {
	int lc_pv_ret;

	lc_pv_ret = lc_process_var_ip4(data, value, endptr);
................................................................................
		return(lc_pv_ret);
	}

	lc_pv_ret = lc_process_var_hostname4(data, value, endptr);
	if (lc_pv_ret == 0) {
		return(lc_pv_ret);
	}

	lc_errno = LC_ERR_BADFORMAT;

	return(-1);
}

static int lc_process_var_addr6(void *data, const char *value, const char **endptr) {
	int lc_pv_ret;

................................................................................
				} else {
					cmdargidx++;
					if (cmdargidx >= argc) {
						fprintf(stderr, "Argument required.\n");
						lc_errfile = local_lc_errfile;
						lc_errline = local_lc_errline;
						lc_errno = LC_ERR_BADFORMAT;
						lc_erroptname = strdup(cmdarg);
						free(usedargv);
						free(newargv);
						return(-1);
					}
					cmdoptarg = argv[cmdargidx];
					newargv[newargvidx++] = cmdoptarg;
					usedargv[cmdargidx] = 1;
				}

				chkretval = lc_handle(handler, handler->var, NULL, cmdoptarg, LC_FLAGS_CMDLINE);
				if (chkretval < 0) {
					lc_errfile = local_lc_errfile;
					lc_errline = local_lc_errline;
					lc_erroptname = strdup(cmdarg);
					retval = -1;
				}

				break;
			}

			if (handler == NULL) {
................................................................................
void lc_seterrstr(const char *usererrmsg) {
	lc_err_usererrmsg = strdup(usererrmsg);
}

char *lc_geterrstr(void) {
	static char retval[512];
	const char *errmsg = NULL;
	const char *local_lc_errfile;

	switch (lc_errno) {
		case LC_ERR_NONE:
			errmsg = "Success";
			break;
		case LC_ERR_INVCMD:
			errmsg = "Invalid command or option";
................................................................................
	 * about unhandled enum values.
	 */
	if (errmsg == NULL) {
		errmsg = "Unknown error";
	}

	if (lc_errfile == NULL) {
		local_lc_errfile = "<no file>";
	} else {
		local_lc_errfile = lc_errfile;
	}

	if (lc_erroptname != NULL) {
		snprintf(retval, sizeof(retval), "%s:%i: \"%s\": %s", local_lc_errfile, lc_errline, lc_erroptname, errmsg);
	} else {
		snprintf(retval, sizeof(retval), "%s:%i: %s", local_lc_errfile, lc_errline, errmsg);
	}

	retval[sizeof(retval) - 1] = '\0';

	return(retval);
}