Adding better error messages and a README.
authorviric@llimona
Fri, 14 Sep 2007 23:37:11 +0200
changeset 14 286b248e402a
parent 13 aec966cdbaa2
child 15 0acf8c3c4fe0
Adding better error messages and a README.
README
error.c
main.c
main.h
usocket.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README	Fri Sep 14 23:37:11 2007 +0200
@@ -0,0 +1,46 @@
+Motivation
+-----------
+I wanted to run mplayer, and command things to it using a key bind. I could
+run "mplayer -slave", but I needed its standard input accessible from any other
+program. Then, I wrote this program to share stdin.
+
+
+What does it do
+-----------------
+It allows the standard input of a program to be accessible from other terminals
+through a unix socket, offering also a simple client for this socket.
+
+
+Exmaple of use
+-----------------
+You can try it with 'cat'. In a shell, start "stdinmix cat". Test how 'cat'
+works; write lines, and see its output.
+
+From another shell, start "stdinmix", and write there lines. See how they
+are treated as if they went to 'cat' input. In fact they went to 'cat' input.
+
+
+How does it work
+------------------
+'stdinmix [app]' allow two ways of sending commands to its child application
+stdin:
+- using the terminal stdin (as if you run the application alone)
+- using a unix socket, by default at /tmp/socket-sm.UID, overwritable by
+  the environment variable SM_SOCKET.
+
+If you don't specify any argument, it will connect to the mentioned unix socket,
+and forward the current stdin to that socket.
+
+
+How do I use it
+------------------
+I wanted a program for transcribing voice in audio tracks. I had mplayer, and
+I only needed a way to send commands to it as "-slave". By now, on need,
+I use xbindkeys [1] to map F1 to "mplayer-remote -p" (pause) and
+F2 to "mplayer-remote -b" (back a few seconds). Then I can transcribe in
+my favourite editor (vim) pausing and moving back the audio track when needed.
+
+
+References
+------------
+[1] xbindkeys: http://hocwp.free.fr/xbindkeys/xbindkeys.html
--- a/error.c	Fri Sep 14 22:27:01 2007 +0200
+++ b/error.c	Fri Sep 14 23:37:11 2007 +0200
@@ -6,12 +6,20 @@
 */
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
 
 #include "main.h"
 
-void error(const char *msg)
+void error(const char *msg, ...)
 {
-    perror(msg);
+    va_list v;
+
+    va_start(v, msg);
+    vfprintf(stderr, msg, v);
+    putc('\n', stderr);
+    fprintf(stderr, " errno %i: %s\n", errno, strerror(errno));
     exit(-1);
 }
 
--- a/main.c	Fri Sep 14 22:27:01 2007 +0200
+++ b/main.c	Fri Sep 14 23:37:11 2007 +0200
@@ -12,7 +12,7 @@
 
 #include "main.h"
 
-static const char version[] = "0.9";
+static const char version[] = "0.9.1";
 
 static int max(int a, int b)
 {
@@ -51,11 +51,9 @@
 
             execvp(command[0], command);
 
-            perror("Cannot execlp mpg321");
-            exit(-1);
+            error("Cannot execlp %s", command[0]);
         case -1:
-            perror("Failed fork");
-            exit(-1);
+            error("Failed fork");
         default: /* parent */
             close(p_input[1]);
             close(p_output[0]);
--- a/main.h	Fri Sep 14 22:27:01 2007 +0200
+++ b/main.h	Fri Sep 14 23:37:11 2007 +0200
@@ -1,6 +1,6 @@
 
 /* error.c */
-void error(const char *msg);
+void error(const char *msg, ...);
 
 /* usocket.c */
 int serve_socket();
--- a/usocket.c	Fri Sep 14 22:27:01 2007 +0200
+++ b/usocket.c	Fri Sep 14 23:37:11 2007 +0200
@@ -44,11 +44,11 @@
 
     res = bind(ls, (struct sockaddr *) & addr, sizeof(addr));
     if (res == -1)
-        error("Error binding");
+        error("Error binding to %s", socket_path);
 
     res = listen(ls, 10);
     if (res == -1)
-        error("Error listening");
+        error("Error listening on the binded unix socket");
 
     return ls;
 }
@@ -77,7 +77,7 @@
 
     res = connect(cs, (struct sockaddr *) &addr, sizeof(addr));
     if (res == -1)
-        error("Cannot connect");
+        error("Cannot connect to %s", socket_path);
     return cs;
 }