aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/sciteco.1.in5
-rw-r--r--src/core-commands.c21
-rw-r--r--src/main.c8
-rw-r--r--tests/atlocal.in1
-rw-r--r--tests/testsuite.at7
5 files changed, 42 insertions, 0 deletions
diff --git a/doc/sciteco.1.in b/doc/sciteco.1.in
index 78f5748..55fc185 100644
--- a/doc/sciteco.1.in
+++ b/doc/sciteco.1.in
@@ -16,6 +16,7 @@ Scintilla-based \fBT\fPext \fBE\fPditor and \fBCO\fPrrector
.SCITECO_TOPIC "sciteco"
.SY @PACKAGE@
.OP "-h|--help"
+.OP "-v|--version"
.OP "-e|--eval" macro
.OP "-m|--mung"
.OP "--no-profile"
@@ -183,6 +184,10 @@ option.
.IP "\fB-h\fR, \fB--help\fR"
.SCITECO_TOPIC "-h" "--help"
Display a short help text on the console.
+.IP "\fB-v\fR, \fB--version\fR"
+.SCITECO_TOPIC "-v" "--version"
+Display the \*(ST version in an easy to parse way.
+See also the \fBEO\fP command.
.IP "\fB-e\fR, \fB--eval\fR \fImacro"
.SCITECO_TOPIC "-e" "--eval"
Evaluate (execute)
diff --git a/src/core-commands.c b/src/core-commands.c
index 67eb51a..a2d3c92 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -20,6 +20,7 @@
#include <time.h>
#include <string.h>
+#include <stdio.h>
#include <glib.h>
#include <glib/gstdio.h>
@@ -2600,6 +2601,25 @@ teco_state_ecommand_encoding(teco_machine_main_t *ctx, GError **error)
teco_interface_ssm(SCI_GOTOPOS, teco_interface_glyphs2bytes(dot_glyphs), 0);
}
+/*$ EO version
+ * EO -> major*10000 + minor*100 + micro
+ *
+ * Return the version of \*(ST encoded into an integer.
+ */
+static void
+teco_state_ecommand_version(teco_machine_main_t *ctx, GError **error)
+{
+ /*
+ * FIXME: This is inefficient and could be done at build-time.
+ * Or we could have PACKAGE_MAJOR_VERSION, PACKAGE_MINOR_VERSION etc. macros.
+ * But then, who cares?
+ */
+ guint major, minor, micro;
+ G_GNUC_UNUSED gint rc = sscanf(PACKAGE_VERSION, "%u.%u.%u", &major, &minor, &micro);
+ g_assert(rc == 3);
+ teco_expressions_push(major*10000 + minor*100 + micro);
+}
+
/*$ "EX" ":EX" exit quit
* [bool]EX -- Exit program
* -EX
@@ -2715,6 +2735,7 @@ teco_state_ecommand_input(teco_machine_main_t *ctx, gunichar chr, GError **error
.modifier_colon = 1},
['E'] = {&teco_state_start, teco_state_ecommand_encoding,
.modifier_colon = 1},
+ ['O'] = {&teco_state_start, teco_state_ecommand_version},
['X'] = {&teco_state_start, teco_state_ecommand_exit,
.modifier_colon = 1},
};
diff --git a/src/main.c b/src/main.c
index a04d1d1..42e1520 100644
--- a/src/main.c
+++ b/src/main.c
@@ -108,6 +108,7 @@ teco_get_default_config_path(void)
#endif
+static gboolean teco_show_version = FALSE;
static gchar *teco_eval_macro = NULL;
static gboolean teco_mung_file = FALSE;
static gboolean teco_mung_profile = TRUE;
@@ -119,6 +120,8 @@ static gchar *
teco_process_options(gchar ***argv)
{
static const GOptionEntry option_entries[] = {
+ {"version", 'v', 0, G_OPTION_ARG_NONE, &teco_show_version,
+ "Show version"},
{"eval", 'e', 0, G_OPTION_ARG_STRING, &teco_eval_macro,
"Evaluate macro", "macro"},
{"mung", 'm', 0, G_OPTION_ARG_NONE, &teco_mung_file,
@@ -187,6 +190,11 @@ teco_process_options(gchar ***argv)
exit(EXIT_FAILURE);
}
+ if (teco_show_version) {
+ puts(PACKAGE_VERSION);
+ exit(EXIT_SUCCESS);
+ }
+
if ((*argv)[0] && !g_strcmp0((*argv)[1], "-S")) {
/* translate -S to --, this is always passed down */
(*argv)[1][1] = '-';
diff --git a/tests/atlocal.in b/tests/atlocal.in
index c693cc9..a8a5242 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -18,6 +18,7 @@ export SCITECOPATH="@abs_top_srcdir@/lib"
export srcdir
TECO_INTEGER=@TECO_INTEGER@
+SCITECO_VERSION="@PACKAGE_VERSION@"
GREP="@GREP@"
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 012ee05..78e6f48 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -360,6 +360,13 @@ AT_SETUP([Timestamps])
TE_CHECK([[::^HUa ::^H-Qa"<(0/0)']], 0, ignore, ignore)
AT_CLEANUP
+AT_SETUP([Program version])
+TE_CHECK([[EO=]], 0, stdout, ignore)
+# FIXME: The grep shouldn't be necessary if we run all tests with --quiet.
+AT_CHECK([[EO="`$GREP -v "^Info:" stdout`" && \
+ test $(($EO/10000)).$(($EO/100%100)).$(($EO%100)) = "$SCITECO_VERSION"]], 0, ignore, ignore)
+AT_CLEANUP
+
#
# Command-line editing.
#