Commit 9e7d23ac 9e7d23acce37814dd0e21b0acf80aee9bc5dc615 by Sergey Poznyakoff

Allow to change encoding and charset at runtime

1 parent a087397f
...@@ -28,38 +28,72 @@ main (int argc, char *argv[]) ...@@ -28,38 +28,72 @@ main (int argc, char *argv[])
28 { 28 {
29 int c; 29 int c;
30 char buf[256]; 30 char buf[256];
31 char *charset = "iso-8859-1"; 31 char *charset = strdup ("iso-8859-1");
32 char *encoding = "quoted-printable"; 32 char *encoding = strdup ("quoted-printable");
33 33
34 while ((c = getopt (argc, argv, "c:e:h")) != EOF) 34 while ((c = getopt (argc, argv, "c:e:h")) != EOF)
35 switch (c) 35 switch (c)
36 { 36 {
37 case 'c': 37 case 'c':
38 charset = optarg; 38 free (charset);
39 charset = strdup (optarg);
39 break; 40 break;
41
40 case 'e': 42 case 'e':
41 encoding = optarg; 43 free (encoding);
44 encoding = strdup (optarg);
42 break; 45 break;
46
43 case 'h': 47 case 'h':
44 printf ("usage: %s [-c charset] [-e encoding]\n", argv[0]); 48 printf ("usage: %s [-c charset] [-e encoding]\n", argv[0]);
45 exit (0); 49 exit (0);
50
46 default: 51 default:
47 exit (1); 52 exit (1);
48 } 53 }
49 54
50 while (fgets (buf, sizeof (buf), stdin)) 55 while (fgets (buf, sizeof (buf), stdin))
51 { 56 {
57 int len;
52 char *p = NULL; 58 char *p = NULL;
53 int rc, len; 59
54
55 len = strlen (buf); 60 len = strlen (buf);
56 if (len > 0 && buf[len - 1] == '\n') 61 if (len > 0 && buf[len - 1] == '\n')
57 buf[len - 1] = 0; 62 buf[len - 1] = 0;
58 rc = mu_rfc2047_encode (charset, encoding, buf, &p); 63 if (buf[0] == '\\')
59 printf ("%s=> %s\n", buf, mu_strerror (rc)); 64 {
60 if (p) 65 if (buf[1] == 0)
66 {
67 fprintf (stderr, "Unfinished command\n");
68 continue;
69 }
70
71 for (p = buf + 2; *p && *p == ' '; p++)
72 ;
73 switch (buf[1])
74 {
75 case 'c':
76 free (charset);
77 charset = strdup (p);
78 break;
79
80 case 'e':
81 free (encoding);
82 encoding = strdup (p);
83 break;
84
85 default:
86 fprintf (stderr, "Unknown command\n");
87 }
88 }
89 else
90 {
91 int rc = mu_rfc2047_encode (charset, encoding, buf, &p);
92 printf ("%s=> %s\n", buf, mu_strerror (rc));
93 if (p)
61 printf ("%s\n", p); 94 printf ("%s\n", p);
62 free (p); 95 free (p);
96 }
63 } 97 }
64 return 0; 98 return 0;
65 } 99 }
......