Miroslav Lichvar
2012-11-06 18:00:00 UTC
Signed-off-by: Miroslav Lichvar <***@redhat.com>
---
config.c | 15 +++++++++++++--
ptp4l.8 | 3 ++-
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/config.c b/config.c
index 6444108..e0d87d5 100644
--- a/config.c
+++ b/config.c
@@ -18,6 +18,7 @@
*/
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include "config.h"
#include "ether.h"
#include "print.h"
@@ -318,7 +319,7 @@ int config_read(char *name, struct config *cfg)
{
enum config_section current_section = GLOBAL_SECTION;
FILE *fp;
- char line[1024];
+ char buf[1024], *line;
int current_port;
fp = 0 == strncmp(name, "-", 2) ? stdin : fopen(name, "r");
@@ -328,7 +329,17 @@ int config_read(char *name, struct config *cfg)
return -1;
}
- while (fgets(line, sizeof(line), fp)) {
+ while (fgets(buf, sizeof(buf), fp)) {
+ line = buf;
+
+ /* skip whitespace characters */
+ while (isspace(line[0]))
+ line++;
+
+ /* ignore empty lines and comments */
+ if (line[0] == '#' || line[0] == '\n' || line[0] == '\0')
+ continue;
+
if (scan_mode(line, ¤t_section) ) {
if (current_section == PORT_SECTION) {
char port[17];
diff --git a/ptp4l.8 b/ptp4l.8
index f496ede..1114b34 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -113,7 +113,8 @@ Display a help message.
The configuration file is divided into sections. Each section starts with a
line containing its name enclosed in brackets and it follows with settings.
Each setting is placed on a separate line, it contains the name of the
-option and the value separated by whitespace characters.
+option and the value separated by whitespace characters. Empty lines and lines
+starting with # are ignored.
The global section (indicated as
.BR [global] )
---
config.c | 15 +++++++++++++--
ptp4l.8 | 3 ++-
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/config.c b/config.c
index 6444108..e0d87d5 100644
--- a/config.c
+++ b/config.c
@@ -18,6 +18,7 @@
*/
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include "config.h"
#include "ether.h"
#include "print.h"
@@ -318,7 +319,7 @@ int config_read(char *name, struct config *cfg)
{
enum config_section current_section = GLOBAL_SECTION;
FILE *fp;
- char line[1024];
+ char buf[1024], *line;
int current_port;
fp = 0 == strncmp(name, "-", 2) ? stdin : fopen(name, "r");
@@ -328,7 +329,17 @@ int config_read(char *name, struct config *cfg)
return -1;
}
- while (fgets(line, sizeof(line), fp)) {
+ while (fgets(buf, sizeof(buf), fp)) {
+ line = buf;
+
+ /* skip whitespace characters */
+ while (isspace(line[0]))
+ line++;
+
+ /* ignore empty lines and comments */
+ if (line[0] == '#' || line[0] == '\n' || line[0] == '\0')
+ continue;
+
if (scan_mode(line, ¤t_section) ) {
if (current_section == PORT_SECTION) {
char port[17];
diff --git a/ptp4l.8 b/ptp4l.8
index f496ede..1114b34 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -113,7 +113,8 @@ Display a help message.
The configuration file is divided into sections. Each section starts with a
line containing its name enclosed in brackets and it follows with settings.
Each setting is placed on a separate line, it contains the name of the
-option and the value separated by whitespace characters.
+option and the value separated by whitespace characters. Empty lines and lines
+starting with # are ignored.
The global section (indicated as
.BR [global] )
--
1.7.11.7
1.7.11.7