Diff

Differences From Artifact [4d749dd593]:

To Artifact [fc4f4efc0c]:


42
43
44
45
46
47
48

49
50
51
52
53
54
55
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56







+








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;
82
83
84
85
86
87
88


89
90
91
92
93
94
95
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98







+
+








	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;
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
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







+
+
+
+





+
+















+
+







		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);
	if (lc_pv_ret == 0) {
		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;

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
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







+











+
+
+







				} 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) {
1094
1095
1096
1097
1098
1099
1100

1101
1102
1103
1104
1105
1106
1107
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123







+







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";
1135
1136
1137
1138
1139
1140
1141






1142

1143
1144

1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163

1164
1165

1166
1167
1168
1169
1170
1171
1172







+
+
+
+
+
+
-
+

-
+






	 * 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", "<no file>", lc_errline, errmsg);
		snprintf(retval, sizeof(retval), "%s:%i: \"%s\": %s", local_lc_errfile, lc_errline, lc_erroptname, errmsg);
	} else {
		snprintf(retval, sizeof(retval), "%s:%i: %s", lc_errfile, lc_errline, errmsg);
		snprintf(retval, sizeof(retval), "%s:%i: %s", local_lc_errfile, lc_errline, errmsg);
	}

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

	return(retval);
}