Skip to content

Commit

Permalink
Use the new public helper function from echttp
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fb-martin committed May 17, 2020
1 parent 4eff37b commit c433a52
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 45 deletions.
4 changes: 2 additions & 2 deletions hc_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ void hc_clock_initialize (int argc, const char **argv) {
clockShowDrift = 0;

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

Expand Down
1 change: 0 additions & 1 deletion hc_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "hc_ntp.h"
#include "hc_http.h"

#include "echttp.h"
#include "echttp_static.h"

static pid_t parent;
Expand Down
12 changes: 6 additions & 6 deletions hc_nmea.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ int hc_nmea_initialize (int argc, const char **argv) {
gpsUseBurst = 0;

for (i = 1; i < argc; ++i) {
hc_match ("-gps=", argv[i], &gpsDevice);
hc_match ("-baud=", argv[i], &speed_option);
hc_match ("-latency=", argv[i], &latency_option);
if (hc_present ("-burst", argv[i])) gpsUseBurst = 1;
if (hc_present ("-privacy", argv[i])) gpsPrivacy = 1;
if (hc_present ("-show-nmea", argv[i])) gpsShowNmea = 1;
echttp_option_match ("-gps=", argv[i], &gpsDevice);
echttp_option_match ("-baud=", argv[i], &speed_option);
echttp_option_match ("-latency=", argv[i], &latency_option);
if (echttp_option_present ("-burst", argv[i])) gpsUseBurst = 1;
if (echttp_option_present ("-privacy", argv[i])) gpsPrivacy = 1;
if (echttp_option_present ("-show-nmea", argv[i])) gpsShowNmea = 1;
}
gpsLatency = atoi(latency_option);
gpsSpeed = atoi(speed_option);
Expand Down
4 changes: 2 additions & 2 deletions hc_ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ int hc_ntp_initialize (int argc, const char **argv) {
const char *ntpperiod = "300";

for (i = 1; i < argc; ++i) {
hc_match ("-ntp-service=", argv[i], &ntpservice);
hc_match ("-ntp-period=", argv[i], &ntpperiod);
echttp_option_match ("-ntp-service=", argv[i], &ntpservice);
echttp_option_match ("-ntp-period=", argv[i], &ntpperiod);
}
if (strcmp(ntpservice, "none") == 0) {
return 0; // Do not act as a NTP server.
Expand Down
33 changes: 3 additions & 30 deletions houseclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@
*
* SYNOPSYS:
*
* int hc_match (const char *reference, const char *input, char **value)
*
* Decode the value found in the input after the reference string, if
* the input matches the reference string. Otherwise just return 0.
*
* This is used to retrieve values from command line arguments.
*
* int hc_present (const char *reference, const char *input)
*
* Return true if the option matches the reference string. Used for
* boolean options.
*
* int hc_debug_enabled (void)
*
* Return true if debug mode option (-debug) was enabled. Mostly used
Expand All @@ -60,21 +48,6 @@
#include "hc_http.h"


int hc_match (const char *reference,
const char *input, const char **value) {

size_t length = strlen(reference);

if (strncmp (reference, input, length)) return 0;

if (value) *value = input + length;
return 1;
}

int hc_present (const char *reference, const char *input) {
return strcmp (reference, input) == 0;
}

static int HcDebug = 0;
static int HcTest = 0;

Expand Down Expand Up @@ -145,9 +118,9 @@ int main (int argc, const char **argv) {
if (strcmp("-h", argv[i]) == 0) {
hc_help(argv[0]);
}
hc_match ("-db=", argv[i], &dbsizestr);
if (hc_present ("-debug", argv[i])) HcDebug = 1;
if (hc_present ("-test", argv[i])) HcTest = 1;
echttp_option_match ("-db=", argv[i], &dbsizestr);
if (echttp_option_present ("-debug", argv[i])) HcDebug = 1;
if (echttp_option_present ("-test", argv[i])) HcTest = 1;
}

// Start the web interface.
Expand Down
5 changes: 1 addition & 4 deletions houseclock.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
#include <string.h>
#include <sys/time.h>

int hc_match (const char *reference,
const char *input, const char **value);

int hc_present (const char *reference, const char *input);
#include "echttp.h"

int hc_test_mode (void);
int hc_debug_enabled (void);
Expand Down

0 comments on commit c433a52

Please sign in to comment.