Commits

Sebastian Freundt  committed 4fcc190 Merge

Merge branch 'tool/strptime'

* tool/strptime:
minor, distribute mularg patch files
minor, provide -e to allow for backslash escapes
minor, patch gengetopt generated code to allow for unescaped commas

  • Participants
  • Parent commits 83e8423, 7d3109f
  • Tags v0.1.0

Comments (0)

Files changed (5)

File src/Makefile.am

 BUILT_SOURCES =
 CLEANFILES =
 EXTRA_DIST = $(BUILT_SOURCES)
+EXTRA_DIST += __gengetopt-mularg.h __gengetopt-mularg.sed
 
 bin_PROGRAMS += dseq
 dseq_SOURCES = dseq.c dseq-clo.ggo
 BUILT_SOURCES += strptime-clo.c strptime-clo.h
 
 ## ggo rule
-%.c %.h: %.ggo
+%.c %.h: %.ggo $(srcdir)/__gengetopt-mularg.sed
 	gengetopt -l -i $< -F $*
+## patch the multiple arg thingie dingie
+	sed -i -f $(srcdir)/__gengetopt-mularg.sed -- $*.c
 
 # 
 # Help the developers get nice post-processed source files

File src/__gengetopt-mularg.h

+/* used to overcome the comma-separated-multiarg feature,
+ * since we need to allow to put commas unescaped as arguments */
+#if !defined INCLUDED___gengetopt_mularg_h_
+#define INCLUDED___gengetopt_mularg_h_
+
+static char*
+get_multiple_arg_token(const char *arg)
+{
+	return gengetopt_strdup(arg);
+}
+
+static const char*
+get_multiple_arg_token_next(const char *arg)
+{
+	FIX_UNUSED(arg);
+	return 0;
+}
+
+#endif	/* INCLUDED___gengetopt_mularg_h_ */

File src/__gengetopt-mularg.sed

+/^gengetopt_strdup (const char \*s);/ {
+	s/$/\n#include "__gengetopt-mularg.h"/
+}
+s/^get_multiple_arg_token/__attribute__((unused)) g_m_a_t/

File src/strptime-clo.ggo

 	string optional
 
 option "input-format" i
-	"input format as passed to strptime(), can be used multiple times
-(or comma-separated).  If used dates can be specified on the command line,
-or if left empty they are read from stdin"
+	"input format as passed to strptime(), can be used multiple times.
+If used dates can be specified on the command line, or if left empty they
+are read from stdin"
 	string optional multiple
 
+option "escape-backslash-sequences" e
+	"enable interpretation of backslash escapes in the output and
+input format strings"
+	optional

File src/strptime.c

 	return;
 }
 
+static void
+unescape(char *s)
+{
+	static const char esc_map[] = "\a\bcd\e\fghijklm\nopq\rs\tu\v";
+	char *p, *q;
+
+	if ((p = q = strchr(s, '\\'))) {
+		do {
+			if (*p != '\\' || !*++p) {
+				*q++ = *p++;
+			} else if (*p < 'a' || *p > 'v') {
+				*q++ = *p++;
+			} else {
+				*q++ = esc_map[*p++ - 'a'];
+			}
+		} while (*p);
+		*q = '\0';
+	}
+	return;
+}
+
 
 #if defined __INTEL_COMPILER
 # pragma warning (disable:593)
 
 	if (argi->format_given) {
 		outfmt = argi->format_arg;
+		/* unescape sequences, maybe */
+		if (argi->escape_backslash_sequences_given) {
+			unescape(outfmt);
+		}
 	} else if (argi->time_given) {
 		outfmt[8] = ' ';
 		outfmt[9] = '%';