diff --git a/man/tio.1.in b/man/tio.1.in index 114a97d..631b938 100644 --- a/man/tio.1.in +++ b/man/tio.1.in @@ -148,6 +148,8 @@ Set timestamp format to any of the following timestamp formats: 24-hour format relative to previous timestamp .IP "\fBiso8601" ISO8601 format ("YYYY-MM-DDThh:mm:ss.sss") +.IP "\fBepoch" +Seconds since Unix epoch (1970-01-01) .PP Default format is \fB24hour\fR .RE diff --git a/man/tio.1.txt b/man/tio.1.txt index d0096bb..99a6e27 100644 --- a/man/tio.1.txt +++ b/man/tio.1.txt @@ -114,6 +114,8 @@ OPTIONS iso8601 ISO8601 format ("YYYY-MM-DDThh:mm:ss.sss") + epoch Seconds since Unix epoch (1970-01-01) + Default format is 24hour --timestamp-timeout diff --git a/src/options.c b/src/options.c index 22a3969..19f8c8a 100644 --- a/src/options.c +++ b/src/options.c @@ -392,6 +392,10 @@ const char* option_timestamp_format_to_string(timestamp_t timestamp) return "iso8601"; break; + case TIMESTAMP_EPOCH: + return "epoch"; + break; + default: return "unknown"; break; @@ -418,6 +422,10 @@ void option_parse_timestamp(const char *arg, timestamp_t *timestamp) { *timestamp = TIMESTAMP_ISO8601; } + else if (strcmp(arg, "epoch") == 0) + { + *timestamp = TIMESTAMP_EPOCH; + } else { tio_error_print("Invalid timestamp '%s'", arg); @@ -1151,7 +1159,7 @@ void options_parse_final(int argc, char *argv[]) if ( ((strncmp("COM", option.target, 3) == 0) || (strncmp("com", option.target, 3) == 0) ) && (sscanf(option.target + 3, "%hhu", &portnum) == 1) - && (portnum > 0) ) + && (portnum > 0) ) { asprintf(&tty_win, "/dev/ttyS%hhu", portnum - 1); option.target = tty_win; diff --git a/src/timestamp.c b/src/timestamp.c index a8d165c..6a23dc3 100644 --- a/src/timestamp.c +++ b/src/timestamp.c @@ -76,6 +76,12 @@ char *timestamp_current_time(void) tm = localtime(&tv.tv_sec); len = strftime(time_string, sizeof(time_string), "%Y-%m-%dT%H:%M:%S", tm); break; + case TIMESTAMP_EPOCH: + // "1223" (seconds since Unix epoch, 1970-01-01 00:00:00Z) + tv = tv_now; + tm = localtime(&tv.tv_sec); + len = strftime(time_string, sizeof(time_string), "%s", tm); + break; default: return NULL; } diff --git a/src/timestamp.h b/src/timestamp.h index 32d129d..48e0a76 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -28,6 +28,7 @@ typedef enum TIMESTAMP_24HOUR_START, TIMESTAMP_24HOUR_DELTA, TIMESTAMP_ISO8601, + TIMESTAMP_EPOCH, TIMESTAMP_END, } timestamp_t; diff --git a/src/tty.c b/src/tty.c index 6b92080..7dbd286 100644 --- a/src/tty.c +++ b/src/tty.c @@ -1079,6 +1079,9 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward) case TIMESTAMP_ISO8601: tio_printf("Switched timestamp mode to iso8601"); break; + case TIMESTAMP_EPOCH: + tio_printf("Switched timestamp mode to epoch"); + break; case TIMESTAMP_END: option.timestamp = TIMESTAMP_NONE; tio_printf("Switched timestamp mode off");