]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/clients/xzwrite/dest_window.c
Initial revision
[1ts-debian.git] / zephyr / clients / xzwrite / dest_window.c
1 #include <X11/Intrinsic.h>
2 #include <X11/StringDefs.h>
3 #include <X11/Shell.h>
4 #include <X11/Xaw/Command.h>
5 #include <X11/Xaw/Form.h>
6 #include <X11/Xaw/Toggle.h>
7 #include <X11/Xaw/List.h>
8
9 #include "xzwrite.h"
10 #include "GetString.h"
11
12 extern Widget toplevel, getString, destList;
13 extern DestRec current_dest;
14 extern Defaults defs;
15
16 void display_dest()
17 {
18      XawListChange(destList, (String *) dest_text(), dest_num(), 0, True);
19 }
20
21 void delete_dest()
22 {
23      XawListReturnStruct *item;
24
25      item = XawListShowCurrent(destList);
26      if (item->list_index == XAW_LIST_NONE)
27           return;
28
29      dest_delete_string(item->string);
30      display_dest();
31 }
32
33 void create_dest()
34 {
35      char buf[ZLEN*3+2], *s;
36      int ret;
37
38      ret = GetString(getString, "Enter new <class,instance,recipient> triple:",
39                      "", 0, buf, ZLEN*3+2);
40      if (ret == GETSTRING_ACCEPT) {
41           s = (char *) malloc(strlen(buf)+1);
42           strcpy(s, buf);
43           if (dest_add_string(s) == NULL) {
44                XBell(XtDisplay(toplevel), 0);
45                free(s);
46           }
47           else
48                display_dest();
49      }
50 }
51
52 void select_dest()
53 {
54      DestRec dest;
55      XawListReturnStruct *item;
56      int ret, used_global = 0;
57
58      item = XawListShowCurrent(destList);
59      if (item->list_index == XAW_LIST_NONE)
60           return;
61      
62      parse_into_dest(&dest, item->string);
63
64      if (! strcmp(dest.zclass, "...")) {
65           ret = GetString(getString, "Enter CLASS to send to:", "", 0,
66                           dest.zclass, ZLEN);
67           if (ret != GETSTRING_ACCEPT) return;
68           used_global = 1;
69      }
70
71      if (! strcmp(dest.zinst, "...")) {
72           ret = GetString(getString, "Enter INSTANCE to send to:", "", 0,
73                           dest.zinst, ZLEN);
74           if (ret != GETSTRING_ACCEPT) return;
75           used_global = 1;
76      }
77
78      if (! strcmp(dest.zrecip, "...")) {
79           ret = GetString(getString, "Enter RECIPIENT to send to:", "", 0,
80                           dest.zrecip, ZLEN);
81           if (ret != GETSTRING_ACCEPT) return;
82           used_global = 1;
83      }
84
85      if (defs.add_globals && used_global) {
86           /* A hack so using "..." looks pretty */
87           if (! strcmp(dest.zclass, DEFAULT_CLASS) &&
88               ! strcmp(dest.zinst, DEFAULT_INST)) {
89                char *temp;
90
91                temp = (char *) malloc(strlen(dest.zrecip) + 1);
92                strcpy(temp, dest.zrecip);
93                dest_add_string(temp);
94           }
95           else
96                dest_add(&dest);
97           display_dest();
98      }
99
100      if (defs.ping && *dest.zrecip) {
101           ret = zeph_ping(&dest);
102           switch (ret) {
103           case SEND_OK:
104                edit_set_title(&dest);
105                (void) memcpy((char *) &current_dest, (char *) &dest,
106                               sizeof(DestRec));
107                break;
108           case SENDFAIL_SEND:
109           case SENDFAIL_RECV:
110           case SENDFAIL_ACK:
111                XBell(XtDisplay(toplevel), 0);
112                return;
113           }
114      }
115      else {
116           edit_set_title(&dest);
117           (void) memcpy((char *) &current_dest, (char *) &dest,
118                          sizeof(DestRec));
119      }
120 }