1 /* -*- Mode: C++-C -*-
2 *
3 *
4 * Copyright 1994 Christopher B. Liebman
5 *
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and that
9 * both that copyright notice and this permission notice appear in
10 * supporting documentation, and that the name Christopher B. Liebman not
11 * be used in advertising or publicity pertaining to distribution of this
12 * software without specific, written prior permission.
13 *
14 * THIS SOFTWARE IS PROVIDED `AS-IS'. CHRISTOPHER B. LIEBMAN, DISCLAIMS
15 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
16 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17 * PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL CHRISTOPHER
18 * B. LIEBMAN, BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING SPECIAL,
19 * INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA, OR
20 * PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
21 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF
22 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 *
24 *
25 *
26 * Author : Chris Liebman
27 * Created On : Sat Feb 12 21:40:50 1994
28 * Last Modified By: Chris Liebman
29 * Last Modified On: Sun Feb 13 17:00:44 1994
30 * Update Count : 24
31 * Status : Released
32 *
33 * HISTORY
34 *
35 * PURPOSE
36 * Handle commands.
37 */
38
39 #ifndef lint
40 static char *RCSid = "$Id: face_command.c,v 1.1 1994/02/13 22:00:52 liebman Exp $";
41 #endif
42
43 #include "faces.h"
44 #include "face_command.h"
45 #include "face_search.h"
46
47 static FaceCommand* TheCommands;
48
49 /*
50 * Create face command data for face.
51 */
52
53 FaceCommand *
FaceCommandCreate(file)54 FaceCommandCreate(file)
55 char *file;
56 {
57 FaceCommand *fc;
58
59 /*
60 * First see if we already have this command.
61 */
62
63 for (fc = TheCommands; fc != NULL; fc = fc->next)
64 {
65 if (strcmp(fc->command, file) == 0)
66 {
67 /*
68 * Yep!
69 */
70
71 fc->refs += 1;
72
73 return(fc);
74 }
75 }
76
77 /*
78 * Ok, create a face command struct.
79 */
80
81 fc = (FaceCommand *)XtCalloc(1, sizeof(FaceCommand));
82 fc->command = XtNewString(file);
83
84 fc->refs = 1;
85
86 /*
87 * Put the new command on the list.
88 */
89
90 fc->next = TheCommands;
91 fc->prev = NULL;
92
93 if (fc->next != NULL)
94 {
95 fc->next->prev = fc;
96 }
97
98 TheCommands = fc;
99
100 /*
101 * and return it.
102 */
103
104 return(fc);
105 }
106
107 /*
108 * Free a command.
109 */
110
111 void
FaceCommandFree(fc)112 FaceCommandFree(fc)
113 FaceCommand *fc;
114 {
115 if (!fc)
116 {
117 return;
118 }
119
120 /*
121 * First remove one reference. If there are still more refs just
122 * return.
123 */
124
125 fc->refs -= 1;
126 if (fc->refs != 0)
127 {
128 return;
129 }
130
131 /*
132 * The previous command is now previous to the next command.
133 */
134
135 if (fc->next != NULL)
136 {
137 fc->next->prev = fc->prev;
138 }
139
140 /*
141 * The next face is now next from the previous face.
142 */
143
144 if (fc->prev != NULL)
145 {
146 fc->prev->next = fc->next;
147 }
148
149 /*
150 * If this was the first command then the next command is
151 * first.
152 */
153
154 if (fc == TheCommands)
155 {
156 TheCommands = fc->next;
157 }
158
159 /*
160 * Ok, free the name.
161 */
162
163 XtFree(fc->command);
164
165 /*
166 * Free the struct.
167 */
168
169 XtFree((void *)fc);
170 }
171
172
173 int
FaceCommandLoad(file,item,data)174 FaceCommandLoad(file, item, data)
175 char* file;
176 MailItem* item;
177 FaceSearchData* data;
178 {
179 /*
180 * We always succeed!
181 */
182
183 item->command = FaceCommandCreate(file);
184
185 return 1;
186 }
187
188 /*
189 * Execute a command.
190 */
191
192 void
FaceCommandRun(fc)193 FaceCommandRun(fc)
194 FaceCommand *fc;
195 {
196 /*
197 * No command!
198 */
199
200 if (!fc)
201 {
202 return;
203 }
204
205 system(fc->command);
206 }
207
208 void
FaceCommandFind(item)209 FaceCommandFind(item)
210 MailItem* item;
211 {
212 if (TheFacesResources.use_commands)
213 {
214 FaceSearch(item, TheFacesResources.command_search);
215 }
216 }
217