diff --git a/README.md b/README.md index df3969d..d22c89e 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ Several variations are available but the following is recommended: ## Installation - wget "https://github.com/simonlaszcz/vidtex/blob/master/releases/vidtex-1.0.0.tar.gz" - tar xvf vidtex-1.0.0.tar.gz - cd vidtex-1.0.0 + wget "https://github.com/simonlaszcz/vidtex/blob/master/releases/vidtex-1.1.0.tar.gz" + tar xvf vidtex-1.1.0.tar.gz + cd vidtex-1.1.0 ./configure sudo make install diff --git a/configure.ac b/configure.ac index d3cdde2..30886a6 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([vidtex], [1.0.0]) +AC_INIT([vidtex], [1.1.0]) AX_WITH_CURSES AC_ARG_WITH([ncursesw], AC_MSG_ERROR([ncursesw not installed])) AC_CONFIG_SRCDIR([src/main.c]) diff --git a/releases/vidtex-1.1.0.tar.gz b/releases/vidtex-1.1.0.tar.gz new file mode 100644 index 0000000..46fcf99 Binary files /dev/null and b/releases/vidtex-1.1.0.tar.gz differ diff --git a/src/decoder.c b/src/decoder.c index 086f1ff..4a22ef3 100644 --- a/src/decoder.c +++ b/src/decoder.c @@ -559,7 +559,6 @@ vt_trace(struct vt_decoder_state *state, char *format, ...) } } - static void vt_cursor(struct vt_decoder_state *state) { diff --git a/src/main.c b/src/main.c index 6b98423..d5a950f 100644 --- a/src/main.c +++ b/src/main.c @@ -3,11 +3,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -25,6 +27,12 @@ const char *sys_conf_dir = SYSCONFDIR; const char *sys_conf_dir = NULL; #endif +#ifdef VERSION +const char *version = VERSION; +#else +const char *version = "0.0.0"; +#endif + #define vt_perror() fprintf(stderr, \ "Error: %s (%d)\n\tat %s line %d\n", strerror(errno), errno, __FILE__, __LINE__) #define vt_is_ctrl(x) ((x) & 0x1F) @@ -33,16 +41,15 @@ const char *sys_conf_dir = NULL; #define BUFFER_LEN 1024 #define MAX_AMBLE_LEN 10 #define POLL_PERIOD_MS -1 -#define VERSION "1.0.0" struct vt_rc_entry { char *name; char *host; char *port; - int preamble[MAX_AMBLE_LEN]; + uint8_t preamble[MAX_AMBLE_LEN]; int preamble_length; - int postamble[MAX_AMBLE_LEN]; + uint8_t postamble[MAX_AMBLE_LEN]; int postamble_length; }; @@ -66,7 +73,7 @@ static void vt_terminate(int signal); static void vt_cleanup(struct vt_session_state *session); static int vt_get_rc(const char *dir, struct vt_rc_entry ***rc_data, int *rc_data_count); static char *vt_duplicate_token(char *token); -static int vt_scan_array(char *token, int buffer[]); +static int vt_scan_array(char *token, uint8_t buffer[]); static void vt_free_rc(struct vt_rc_entry *rc_data[], int rc_data_count); static int vt_parse_options(int argc, char *argv[], struct vt_session_state *session); static struct vt_rc_entry *vt_show_rc_menu(struct vt_rc_entry **rc_data, int rc_data_count); @@ -74,6 +81,7 @@ static int vt_connect(struct vt_session_state *session); static bool vt_is_valid_fd(int fd); static int vt_transform_input(int ch); static void vt_usage(); +static void vt_trace(struct vt_session_state *session, char *format, ...); volatile sig_atomic_t terminate_received = false; volatile sig_atomic_t socket_closed = false; @@ -295,8 +303,8 @@ vt_cleanup(struct vt_session_state *session) endwin(); if (session->socket_fd > -1) { - int default_buffer[4] = {'*', '9', '0', '_'}; - int *buffer = default_buffer; + uint8_t default_buffer[4] = {'*', '9', '0', '_'}; + uint8_t *buffer = default_buffer; int len = 4; if (session->selected_rc != NULL && session->selected_rc->postamble_length > 0) { @@ -306,6 +314,12 @@ vt_cleanup(struct vt_session_state *session) // If write fails it was closed by the host first if (write(session->socket_fd, buffer, len) == len) { + vt_trace(session, "postamble: "); + for (int i = 0; i < len; ++i) { + vt_trace(session, "%d '%c' ", buffer[i], buffer[i]); + } + vt_trace(session, "\n"); + if (shutdown(session->socket_fd, SHUT_RDWR) == -1) { vt_perror(); } @@ -498,9 +512,10 @@ vt_duplicate_token(char *token) } static int -vt_scan_array(char *token, int buffer[]) +vt_scan_array(char *token, uint8_t buffer[]) { - int count = sscanf(token, "%d %d %d %d %d %d %d %d %d %d", + int count = sscanf(token, + "%"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8 " %"SCNu8, &buffer[0], &buffer[1], &buffer[2], &buffer[3], &buffer[4], &buffer[5], &buffer[6], &buffer[7], &buffer[8], &buffer[9]); @@ -691,14 +706,16 @@ vt_connect(struct vt_session_state *session) goto abend; } - int preamble[MAX_AMBLE_LEN + 1] = {0}; + uint8_t preamble[MAX_AMBLE_LEN + 1] = {0}; preamble[0] = 22; int preamble_len = 1; if (session->selected_rc != NULL && session->selected_rc->preamble_length > 0) { - int n = sizeof(int) * session->selected_rc->preamble_length; - memcpy(&preamble[1], session->selected_rc->preamble, n); preamble_len += session->selected_rc->preamble_length; + + for (int i = 0; i < session->selected_rc->preamble_length; ++i) { + preamble[i + 1] = session->selected_rc->preamble[i]; + } } int sz = write(session->socket_fd, preamble, preamble_len); @@ -713,6 +730,12 @@ vt_connect(struct vt_session_state *session) goto abend; } + vt_trace(session, "preamble: "); + for (int i = 0; i < preamble_len; ++i) { + vt_trace(session, "%d '%c' ", preamble[i], preamble[i]); + } + vt_trace(session, "\n"); + return EXIT_SUCCESS; abend: @@ -743,7 +766,7 @@ vt_transform_input(int ch) static void vt_usage() { - fprintf(stderr, "Version: %s\n", VERSION); + fprintf(stderr, "Version: %s\n", version); fprintf(stderr, "SYSCONFDIR=%s\n", sys_conf_dir); fprintf(stderr, "Usage: vidtex [options]\nOptions:\n"); fprintf(stderr, "%-16s\tOutput bold brighter colours\n", "--bold"); @@ -756,3 +779,14 @@ vt_usage() fprintf(stderr, "%-16s\tViewdata service host port\n", "--port number"); fprintf(stderr, "%-16s\tWrite trace to file\n", "--trace filename"); } + +static void +vt_trace(struct vt_session_state *session, char *format, ...) +{ + if (session->decoder_state.trace_file != NULL) { + va_list args; + va_start(args, format); + vfprintf(session->decoder_state.trace_file, format, args); + va_end(args); + } +} diff --git a/src/vidtex.1 b/src/vidtex.1 index fa9177c..4edcd3d 100644 --- a/src/vidtex.1 +++ b/src/vidtex.1 @@ -100,7 +100,7 @@ Use 'whereis vidtex' to locate vidtexrc. Typically it will exist at /usr/local/e .PP The program will also look in the user's HOME directory and the current working directory (in that order) for vidtexrc files. All will be read and when displaying the menu, all entries will be listed. .PP -Service hosts are listed one per line in the file. Lines may be commented by placing a '#' at the start of the line. Fields are tab delimited and are as follows: +Service hosts are listed one per line in the file. Lines may be commented by placing a '#' at the start of the line. Fields are delimited by either tab, ',' or '|' and are as follows: .TP \fBDisplay name .TP @@ -109,7 +109,7 @@ Service hosts are listed one per line in the file. Lines may be commented by pla \fBPort number .TP \fBPreamble (optional) -Upto 20 bytes may be specified in decimal, separated by spaces. These are sent to the host on connection. +Upto 20 bytes may be specified in decimal, separated by spaces. These are sent to the host on connection. If there is no preamble but there is postamble, use a space for preamble. .TP \fBPostamble (optional) Upto 20 bytes may be specified in decimal, separated by spaces. These are sent to the host on termination. Typically this might be the standard Viewdata logoff sequence of '*90#', although note that '#' should be translated to '_' so in effect this would be '*90_'. diff --git a/src/vidtexrc b/src/vidtexrc index 6aa8222..3b20ace 100644 --- a/src/vidtexrc +++ b/src/vidtexrc @@ -1,12 +1,12 @@ -#name host port preamble postamble -ccl4 fish.ccl4.org 23 42 81 81 -nxtel nx.nxtel.org 23280 -teefax pegasus.matrixnetwork.co.uk 6502 70 70 70 -telstar-fast-1 glasstty.com 6502 255 253 3 42 57 48 95 95 -telstar-fast-2 glasstty.com 6503 255 253 3 42 57 48 95 95 -telstar-slow-1 glasstty.com 6502 42 57 48 95 95 -telstar-slow-2 glasstty.com 6503 42 57 48 95 95 -prestel demo viewdata.org.uk 6522 -linkline demo viewdata.org.uk 6854 +#name,host,port,preamble,postamble +ccl4,fish.ccl4.org,23, ,42 81 81 +nxtel,nx.nxtel.org,23280 +teefax,pegasus.matrixnetwork.co.uk,6502, ,70 70 70 +telstar-fast-1,glasstty.com,6502,255 253 3,42 57 48 95 95 +telstar-fast-2,glasstty.com,6503,255 253 3,42 57 48 95 95 +telstar-slow-1,glasstty.com,6502, ,42 57 48 95 95 +telstar-slow-2,glasstty.com,6503, ,42 57 48 95 95 +prestel demo,viewdata.org.uk,6522 +linkline demo,viewdata.org.uk,6854 #offline for a long time -ringworld rw1.m63.co.uk 23 +ringworld,rw1.m63.co.uk,23