]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/clients/xzwrite/xzwrite.c
318e5e9df40da1c5e72ff09071d19134fed5ff2a
[1ts-debian.git] / zephyr / clients / xzwrite / xzwrite.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <pwd.h>
4 #include <dyn.h>
5
6 #include "xzwrite.h"
7
8 extern Defaults defs;
9 DynObject zsigs = NULL;
10
11 static void set_signature __P((void));
12 static Boolean set_random_zsigs __P((void));
13
14 int main(argc, argv)
15    int  argc;
16    char **argv;
17 {
18      zeph_init();
19
20      build_interface(&argc, argv);
21
22      if (argc > 1) usage();
23
24      set_signature();
25      dest_init();
26      yank_init();
27      edit_win_init();
28      menu_match_defs();
29      (void) load_default_dest();
30      display_dest();
31
32      if (defs.track_logins)
33           logins_subscribe();
34      if (defs.auto_reply)
35           zeph_subto_replies();
36
37      go();
38      return 0;
39 }
40
41 static void set_signature()
42 {
43      char *sig, sigbfr[BUFSIZ];
44      
45      /* Do magic with signature */
46      if (defs.zsigfile)
47        if (strcmp(defs.zsigfile, "*"))
48          if (set_random_zsigs()) return;
49
50      if (*defs.signature)
51           return;
52
53      sig = (char *) zeph_get_signature();
54      if (!sig) {
55           /* try to find name in the password file */
56           register struct passwd *pwd;
57           register char *cp = sigbfr;
58           register char *cp2, *pp;
59           
60           pwd = getpwuid(getuid());
61           if (pwd) {
62                cp2 = pwd->pw_gecos;
63                for (; *cp2 && *cp2 != ',' ; cp2++) {
64                     if (*cp2 == '&') {
65                          pp = pwd->pw_name;
66                          *cp++ = islower(*pp) ? toupper(*pp) : *pp;
67                          pp++;
68                          while (*pp)
69                               *cp++ = *pp++;
70                     } else
71                          *cp++ = *cp2;
72                }
73                *cp = '\0';
74                sig = sigbfr;
75           }
76      }  
77      
78      if (sig) {
79           defs.signature = (char *) Malloc(strlen(sig) + 1,
80                                            "getting signature",
81                                            NULL);
82           strcpy(defs.signature, sig);
83      }
84 }
85          
86
87
88 void usage()
89 {
90      fprintf(stderr, "Usage:  xzwrite [ -toolkitoption ... ] [-s signature] [+d | -d] [+n | -n]\n\t[+v | -v] [+yd | -yd] [+av | -av] [+ci | -ci] [-my yanks]\n\t[+l | -l] [+a | -a] [+x | -x] [+z | -z] [+pong | -pong] [+reply | -reply]\n");
91      exit(1);
92 }
93
94 #define BUF_SIZE 1024
95
96 static Boolean set_random_zsigs()
97 { int x, n;
98   char z[BUF_SIZE], *z2;
99   FILE *fp;
100
101   fp = fopen(defs.zsigfile, "r");
102   if (!fp) {
103     fprintf(stderr, "xzwrite: cant open file \"%s\".\n", defs.zsigfile);
104     return False; }
105   
106   zsigs = DynCreate(sizeof(char*), 5);
107   
108   while ( fgets(z, BUF_SIZE, fp) != NULL) {
109     if (z[0] == '#' || z[0] == 0) continue;
110     n = strlen(z);
111     z2 = (char *) calloc (sizeof(char), n);
112     if (!z2) {
113       fprintf(stderr, "xzwrite: out of memory.\n"); exit(1); }
114     if (z[n-1] == '\n') { n--; z[n] = 0; }
115     for (x = 0; x <= n; x++) {
116       if (z[x] != '\\') z2[x] = z[x];
117       else z2[x] = '\n'; }
118     DynAdd(zsigs, (DynPtr) &z2); }
119
120   fclose(fp);
121   return True;
122 }