alevt (1:1.6.2-5) x11-errormessage.diff

Summary

 main.c |   21 ++++++++++++++++-
 ui.c   |   12 +++++++++
 vbi.c  |   80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 vbi.h  |    3 ++
 vt.h   |    1 
 5 files changed, 115 insertions(+), 2 deletions(-)

    
download this patch

Patch contents

Subject: Show the "device not found" error message via X11 as well

From: Dirk Schuster <dirk.schuster@web.de>

Signed-off-by: Andreas Rottmann <a.rottmann@gmx.at>
---
 main.c |   21 ++++++++++++++++-
 ui.c   |   12 ++++++++++
 vbi.c  |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 vbi.h  |    3 ++
 vt.h   |    1 +
 5 files changed, 115 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index 7a23d0e..811245b 100644
--- a/main.c
+++ b/main.c
@@ -95,10 +95,20 @@ arg_pgno(char *p, int *subno)
 static struct vtwin *
 start(int argc, char **argv, struct vtwin *parent, int pgno, int subno)
 {
+    static int valid_vbi_name = 1;
+
+    if (!valid_vbi_name)
+	return parent;
+
     if (vbi == 0)
 	vbi = vbi_open(vbi_name, cache_open(), fine_tune, newbttv, progname, txtpid);
     if (vbi == 0)
-	fatal("cannot open %s", vbi_name);
+    {
+	if (vbi_name)
+	    error("cannot open device: %s", vbi_name);
+    	valid_vbi_name = 0;
+    	vbi = open_null_vbi(cache_open());
+    }
     if (vbi->cache)
 	vbi->cache->op->mode(vbi->cache, CACHE_MODE_ERC, erc);
 
@@ -110,6 +120,15 @@ start(int argc, char **argv, struct vtwin *parent, int pgno, int subno)
     parent = vtwin_new(xio, vbi, geometry, parent, pgno, subno);
     if (parent == 0)
 	fatal("cannot create window");
+
+    if (!valid_vbi_name)
+    {
+	if (vbi_name)
+	    send_errmsg(vbi, "cannot open device: %s", vbi_name);
+	else
+	    send_errmsg(vbi, "cannot open any device", vbi_name);
+    }
+
     return parent;
 }
 
diff --git a/ui.c b/ui.c
index 04079f2..426076e 100644
--- a/ui.c
+++ b/ui.c
@@ -808,5 +808,17 @@ vtwin_event(struct vtwin *w, struct vt_event *ev)
 #endif
 	    break;
 	}
+	case EV_ERR:
+	{
+	    char *errmsg = ev->p1;
+	    if (errmsg != NULL && *errmsg != '\0')
+	    {
+	    	err(w, errmsg);
+	    	w->status = 30;
+	    	ev->p1 = NULL;
+	    	free(errmsg);
+	    }
+	    break;
+	}
     }
 }
diff --git a/vbi.c b/vbi.c
index 62a2e4a..abbc326 100644
--- a/vbi.c
+++ b/vbi.c
@@ -5,6 +5,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <errno.h>
+#include <stdarg.h>
 #include <sys/ioctl.h>
 #include <sys/poll.h>
 #include "os.h"
@@ -626,7 +627,7 @@ vbi_open(char *vbi_name, struct cache *ca, int fine_tune, int big_buf, const cha
             }
         }
 	
-	fatal("could not open any of the standard devices (%s)", tried_devices);
+	error("could not open any of the standard devices (%s)", tried_devices);
         free(tried_devices);
 	return NULL;
     }
@@ -1112,3 +1113,80 @@ static int vbi_dvb_open(struct vbi *vbi, const char *vbi_name, const char *progn
 	vbi->fd = -1;
 	return -1;
 }
+
+struct vbi *open_null_vbi(struct cache *ca)
+{
+    static int inited = 0;
+    struct vbi *vbi;
+
+    if (not inited)
+    	lang_init();
+    inited = 1;
+
+    vbi = malloc(sizeof(*vbi));
+    if (!vbi)
+    {
+		error("out of memory");
+		goto fail1;
+    }
+
+    vbi->fd = open("/dev/null", O_RDONLY);
+	if (vbi->fd == -1)
+	{
+		error("cannot open null device");
+		goto fail2;
+	}
+
+    vbi->txtpid = -1;
+
+    vbi->bpb = 0;
+    vbi->soc = 0;
+    vbi->eoc = 0;
+    vbi->bp8bl = 0;
+    vbi->bp8bh = 0;
+
+    vbi->bpl = 1;
+
+    vbi->bufsize = 8;
+    rawbuf_size = vbi->bufsize;
+	rawbuf = malloc(rawbuf_size);
+	if (!rawbuf)
+		goto fail3;
+	rawptr = 0;
+
+    vbi->cache = ca;
+
+    dl_init(vbi->clients);
+    vbi->seq = 0;
+    out_of_sync(vbi);
+    vbi->ppage = vbi->rpage;
+
+    fdset_add_fd(fds, vbi->fd, vbi_handler, vbi);
+    return vbi;
+
+fail3:
+    close(vbi->fd);
+fail2:
+    free(vbi);
+fail1:
+    return 0;
+}
+
+void send_errmsg(struct vbi *vbi, char *errmsg, ...)
+{
+	va_list args;
+
+	if (errmsg == NULL || *errmsg == '\0')
+		return;
+
+	va_start(args, errmsg);
+	char *buff = NULL;
+	if (vasprintf(&buff, errmsg, args) < 0)
+		buff = NULL;
+	va_end(args);
+
+	if(buff == NULL)
+		out_of_mem(-1);
+
+	vbi_send(vbi, EV_ERR, 0, 0, 0, buff);
+}
diff --git a/vbi.h b/vbi.h
index 06159da..eca5d94 100644
--- a/vbi.h
+++ b/vbi.h
@@ -59,4 +59,7 @@ void vbi_del_handler(struct vbi *vbi, void *handler, void *data);
 struct vt_page *vbi_query_page(struct vbi *vbi, int pgno, int subno);
 void vbi_pll_reset(struct vbi *vbi, int fine_tune);
 
+struct vbi *open_null_vbi(struct cache *ca);
+void send_errmsg(struct vbi *vbi, char *errmsg, ...);
+
 #endif
diff --git a/vt.h b/vt.h
index 0fda7a3..80edff2 100644
--- a/vt.h
+++ b/vt.h
@@ -26,6 +26,7 @@ struct vt_event
 #define EV_XPACKET	7	// i1:mag  i2:pkt  i3:errors  p1:data
 #define EV_RESET	8	// ./.
 #define EV_TIMER	9	// ./.
+#define EV_ERR		10	// p1: errmsg
 
 #define KEY_F(i)	(1000+i)
 #define KEY_LEFT	2001