]> mj.ucw.cz Git - misc.git/commitdiff
Fix.
authorMartin Mares <mj@ucw.cz>
Thu, 18 Oct 2007 09:37:00 +0000 (11:37 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 18 Oct 2007 09:37:00 +0000 (11:37 +0200)
morse.c

diff --git a/morse.c b/morse.c
index 50f957b190ddc01189e995d6c542f03f4fbc5858..a1d949e62d9daf5c31c0282342ec7048d5efcba1 100644 (file)
--- a/morse.c
+++ b/morse.c
@@ -5,7 +5,7 @@
 
 #define MAXLEN 256
 
-static unsigned char decode[] = "**etianmsurwdkgohvf*l*p*bxcyzq*";
+static unsigned char decode[] = "**etianmsurwdkgohvf*l*pjbxcyzq*";
 static unsigned char encode[256];
 
 static void init(void)
@@ -171,15 +171,28 @@ int main(int argc, char **argv)
     die("Usage: morse <dict> <string>");
   init();
   load(argv[1]);
-  int N = strlen(argv[2]);
+
+  char *in, mbuf[MAXLEN+1];
+  if (argv[2][0] == '.' || argv[2][0] == '-')
+    in = argv[2];
+  else
+    {
+      strencode(mbuf, argv[2], 0);
+      puts(mbuf);
+      if (strchr(mbuf, '?'))
+       die("Unable to encode");
+      in = mbuf;
+    }
+
+  int N = strlen(in);
   if (N > MAXLEN)
     die("Oops, too long for my memory!");
-  map(argv[2], N);
+  map(in, N);
 
   char buf[MAXLEN+1];
   for (int j=1; j<=N; j++)
     if (M[0][j])
-      print(buf+1, buf, argv[2], 0, N, j);
+      print(buf+1, buf, in, 0, N, j);
 
   return 0;
 }