summaryrefslogtreecommitdiff
path: root/src/check_tmpl.c
diff options
context:
space:
mode:
authorStig Thormodsrud <stig@vyatta.com>2008-02-19 18:46:03 -0800
committerStig Thormodsrud <stig@vyatta.com>2008-02-19 18:46:03 -0800
commitd73e3f8a10192a928efc80fcf91e58218aeac4d6 (patch)
tree210c60aef7e4e4fbabda3b7d0cceb6a34dbf613e /src/check_tmpl.c
parentacb8eea0301ad69c1653b389be4a86ada8721290 (diff)
parent4e0206da1f3080f0c0729e6b6f252a147cf2a9cb (diff)
downloadvyatta-cfg-d73e3f8a10192a928efc80fcf91e58218aeac4d6.tar.gz
vyatta-cfg-d73e3f8a10192a928efc80fcf91e58218aeac4d6.zip
Merge branch 'glendale' of http://git.vyatta.com/vyatta-cfg into glendale
Diffstat (limited to 'src/check_tmpl.c')
-rw-r--r--src/check_tmpl.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/check_tmpl.c b/src/check_tmpl.c
new file mode 100644
index 0000000..8be1a7f
--- /dev/null
+++ b/src/check_tmpl.c
@@ -0,0 +1,69 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "cli_val.h"
+
+int
+check_line_continuation(FILE *ftmpl)
+{
+ char buf[256];
+ int line = 0;
+ while (fgets(buf, 256, ftmpl) != NULL) {
+ int len = strlen(buf);
+ ++line;
+ if (len < 2 || buf[len - 1] != '\n' || !isblank(buf[len - 2])) {
+ continue;
+ }
+ len -= 3;
+ while (len >= 0 && isblank(buf[len])) {
+ --len;
+ }
+ if (len >= 0 && buf[len] == '\\') {
+ printf("Warning: \"backslash + space\" detected at the end of line %d.\n"
+ " This will not work as line continuation.\n",
+ line);
+ continue;
+ }
+ }
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ int status = 0;
+ vtw_def def;
+ FILE *ftmpl = NULL;
+
+ if (argc != 2) {
+ printf("Usage: check_tmpl <tmpl_file>\n");
+ exit(-1);
+ }
+
+ memset(&def, 0, sizeof(def));
+ status = parse_def(&def, argv[1], 0);
+ if (status == -5) {
+ printf("Cannot open [%s]\n", argv[1]);
+ exit(-1);
+ } else if (status != 0) {
+ printf("Parse error in [%s]\n", argv[1]);
+ exit(-1);
+ }
+
+ if ((ftmpl = fopen(argv[1], "r")) == NULL) {
+ printf("Cannot open [%s]\n", argv[1]);
+ exit(-1);
+ }
+
+ /* check for other errors */
+ if (check_line_continuation(ftmpl) != 0) {
+ exit(-1);
+ }
+ fseek(ftmpl, 0, SEEK_SET);
+
+ fclose(ftmpl);
+
+ printf("OK\n");
+ return 0;
+}
+