Skip to content

Commit c433a52

Browse files
Use the new public helper function from echttp
1 parent 4eff37b commit c433a52

File tree

6 files changed

+14
-45
lines changed

6 files changed

+14
-45
lines changed

Diff for: hc_clock.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ void hc_clock_initialize (int argc, const char **argv) {
107107
clockShowDrift = 0;
108108

109109
for (i = 1; i < argc; ++i) {
110-
hc_match ("-precision=", argv[i], &precision_option);
111-
clockShowDrift |= hc_present ("-drift", argv[i]);
110+
echttp_option_match ("-precision=", argv[i], &precision_option);
111+
clockShowDrift |= echttp_option_present ("-drift", argv[i]);
112112
}
113113
precision = atoi(precision_option);
114114

Diff for: hc_http.c

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "hc_ntp.h"
4343
#include "hc_http.h"
4444

45-
#include "echttp.h"
4645
#include "echttp_static.h"
4746

4847
static pid_t parent;

Diff for: hc_nmea.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ int hc_nmea_initialize (int argc, const char **argv) {
199199
gpsUseBurst = 0;
200200

201201
for (i = 1; i < argc; ++i) {
202-
hc_match ("-gps=", argv[i], &gpsDevice);
203-
hc_match ("-baud=", argv[i], &speed_option);
204-
hc_match ("-latency=", argv[i], &latency_option);
205-
if (hc_present ("-burst", argv[i])) gpsUseBurst = 1;
206-
if (hc_present ("-privacy", argv[i])) gpsPrivacy = 1;
207-
if (hc_present ("-show-nmea", argv[i])) gpsShowNmea = 1;
202+
echttp_option_match ("-gps=", argv[i], &gpsDevice);
203+
echttp_option_match ("-baud=", argv[i], &speed_option);
204+
echttp_option_match ("-latency=", argv[i], &latency_option);
205+
if (echttp_option_present ("-burst", argv[i])) gpsUseBurst = 1;
206+
if (echttp_option_present ("-privacy", argv[i])) gpsPrivacy = 1;
207+
if (echttp_option_present ("-show-nmea", argv[i])) gpsShowNmea = 1;
208208
}
209209
gpsLatency = atoi(latency_option);
210210
gpsSpeed = atoi(speed_option);

Diff for: hc_ntp.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ int hc_ntp_initialize (int argc, const char **argv) {
144144
const char *ntpperiod = "300";
145145

146146
for (i = 1; i < argc; ++i) {
147-
hc_match ("-ntp-service=", argv[i], &ntpservice);
148-
hc_match ("-ntp-period=", argv[i], &ntpperiod);
147+
echttp_option_match ("-ntp-service=", argv[i], &ntpservice);
148+
echttp_option_match ("-ntp-period=", argv[i], &ntpperiod);
149149
}
150150
if (strcmp(ntpservice, "none") == 0) {
151151
return 0; // Do not act as a NTP server.

Diff for: houseclock.c

+3-30
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@
2222
*
2323
* SYNOPSYS:
2424
*
25-
* int hc_match (const char *reference, const char *input, char **value)
26-
*
27-
* Decode the value found in the input after the reference string, if
28-
* the input matches the reference string. Otherwise just return 0.
29-
*
30-
* This is used to retrieve values from command line arguments.
31-
*
32-
* int hc_present (const char *reference, const char *input)
33-
*
34-
* Return true if the option matches the reference string. Used for
35-
* boolean options.
36-
*
3725
* int hc_debug_enabled (void)
3826
*
3927
* Return true if debug mode option (-debug) was enabled. Mostly used
@@ -60,21 +48,6 @@
6048
#include "hc_http.h"
6149

6250

63-
int hc_match (const char *reference,
64-
const char *input, const char **value) {
65-
66-
size_t length = strlen(reference);
67-
68-
if (strncmp (reference, input, length)) return 0;
69-
70-
if (value) *value = input + length;
71-
return 1;
72-
}
73-
74-
int hc_present (const char *reference, const char *input) {
75-
return strcmp (reference, input) == 0;
76-
}
77-
7851
static int HcDebug = 0;
7952
static int HcTest = 0;
8053

@@ -145,9 +118,9 @@ int main (int argc, const char **argv) {
145118
if (strcmp("-h", argv[i]) == 0) {
146119
hc_help(argv[0]);
147120
}
148-
hc_match ("-db=", argv[i], &dbsizestr);
149-
if (hc_present ("-debug", argv[i])) HcDebug = 1;
150-
if (hc_present ("-test", argv[i])) HcTest = 1;
121+
echttp_option_match ("-db=", argv[i], &dbsizestr);
122+
if (echttp_option_present ("-debug", argv[i])) HcDebug = 1;
123+
if (echttp_option_present ("-test", argv[i])) HcTest = 1;
151124
}
152125

153126
// Start the web interface.

Diff for: houseclock.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
#include <string.h>
2727
#include <sys/time.h>
2828

29-
int hc_match (const char *reference,
30-
const char *input, const char **value);
31-
32-
int hc_present (const char *reference, const char *input);
29+
#include "echttp.h"
3330

3431
int hc_test_mode (void);
3532
int hc_debug_enabled (void);

0 commit comments

Comments
 (0)