remove the second -lssl in the generated Makefile so that it doesn't break the build.
[AROS-Contrib.git] / dopus / Program / makelinkdata.c
blob68b16a7e5d393da0f99dd434aab7904dfbbe8d9c
1 /*
3 Directory Opus 4
4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
31 #include "dopus.h"
33 enum {
34 MAKELINK_CANCEL,
35 MAKELINK_OKAY,
36 MAKELINK_NAME,
37 MAKELINK_DESTNAME,
38 MAKELINK_DESTSELECT,
39 MAKELINK_TYPE};
41 static struct RequesterBase makelink_req={
42 46,7,48,27,
43 8,6,
44 0,0,0,0,NULL,NULL,NULL,NULL,
45 NULL,NULL,NULL,
46 0,0,NULL,IDCMP_MOUSEBUTTONS|IDCMP_GADGETUP,NULL};
48 static struct TagItem
49 makelink_type_gadget[]={
50 {RO_Type,OBJECT_GADGET},
51 {RO_GadgetType,GADGET_CYCLE},
52 {RO_GadgetID,MAKELINK_TYPE},
53 {RO_Top,1},
54 {RO_TopFine,2},
55 {RO_Width,8},
56 {RO_WidthFine,24},
57 {RO_Height,1},
58 {RO_HeightFine,6},
59 {RO_HighRecess,TRUE},
60 {TAG_END,0}},
62 makelink_name_gadget[]={
63 {RO_Type,OBJECT_GADGET},
64 {RO_GadgetType,GADGET_STRING},
65 {RO_GadgetID,MAKELINK_NAME},
66 {RO_Top,1},
67 {RO_TopFine,4},
68 {RO_Height,1},
69 {RO_HeightFine,2},
70 {RO_Left,8},
71 {RO_LeftFine,28},
72 {RO_Width,38},
73 {RO_StringBuf,0},
74 {RO_StringLen,107},
75 {RO_StringUndo,(IPTR)str_undobuffer},
76 {TAG_END,0}},
78 makelink_destname_gadget[]={
79 {RO_Type,OBJECT_GADGET},
80 {RO_GadgetType,GADGET_STRING},
81 {RO_GadgetID,MAKELINK_DESTNAME},
82 {RO_Top,4},
83 {RO_TopFine,8},
84 {RO_Height,1},
85 {RO_HeightFine,2},
86 // {RO_Left,8},
87 {RO_LeftFine,4},
88 {RO_Width,46},
89 {RO_WidthFine,2},
90 {RO_StringBuf,0},
91 {RO_StringLen,255},
92 {RO_StringUndo,(IPTR)str_undobuffer},
93 {TAG_END,0}},
95 makelink_glass_gadget[]={
96 {RO_Type,OBJECT_GADGET},
97 {RO_GadgetType,GADGET_TINYGLASS},
98 {RO_GadgetID,MAKELINK_DESTSELECT},
99 {RO_Top,4},
100 {RO_TopFine,6},
101 {RO_Left,47},
102 {RO_LeftFine,2},
103 // {RO_Width,2},
104 {RO_WidthFine,24},
105 {RO_Height,1},
106 {RO_HeightFine,6},
107 {RO_HighRecess,TRUE},
108 {TAG_END,0}},
110 makelink_okay_gadget[]={
111 {RO_Type,OBJECT_GADGET},
112 {RO_GadgetType,GADGET_BOOLEAN},
113 {RO_GadgetID,MAKELINK_OKAY},
114 {RO_Top,6},
115 {RO_TopFine,11},
116 {RO_Height,1},
117 {RO_HeightFine,6},
118 {RO_Width,10},
119 {RO_TextNum,STR_OKAY},
120 {RO_TextPos,TEXTPOS_CENTER},
121 {RO_HighRecess,TRUE},
122 {TAG_END,0}},
124 makelink_cancel_gadget[]={
125 {RO_Type,OBJECT_GADGET},
126 {RO_GadgetType,GADGET_BOOLEAN},
127 {RO_GadgetID,MAKELINK_CANCEL},
128 {RO_Top,6},
129 {RO_TopFine,11},
130 {RO_Height,1},
131 {RO_HeightFine,6},
132 {RO_Width,10},
133 {RO_Left,36},
134 {RO_LeftFine,32},
135 {RO_TextNum,STR_CANCEL},
136 {RO_TextPos,TEXTPOS_CENTER},
137 {RO_HighRecess,TRUE},
138 {TAG_END,0}},
140 makelink_type_text[]={
141 {RO_Type,OBJECT_BORDER},
142 {RO_BorderType,BORDER_NONE},
143 {RO_Width,8},
144 {RO_WidthFine,24},
145 {RO_TopFine,-1},
146 {RO_Height,1},
147 {RO_TextNum,STR_MAKELINK_TYPE},
148 {RO_TextPos,TEXTPOS_CENTER},
149 {TAG_END,0}},
151 makelink_name_text[]={
152 {RO_Type,OBJECT_BORDER},
153 {RO_BorderType,BORDER_NONE},
154 {RO_Left,8},
155 {RO_LeftFine,28},
156 {RO_Width,38},
157 {RO_TopFine,-1},
158 {RO_Height,1},
159 {RO_TextNum,STR_MAKELINK_NAME},
160 {RO_TextPos,TEXTPOS_CENTER},
161 {TAG_END,0}},
163 makelink_dest_text[]={
164 {RO_Type,OBJECT_BORDER},
165 {RO_BorderType,BORDER_NONE},
166 {RO_Width,46},
167 {RO_WidthFine,26},
168 {RO_Top,3},
169 {RO_TopFine,3},
170 {RO_Height,1},
171 {RO_TextNum,STR_MAKELINK_DESTINATION},
172 {RO_TextPos,TEXTPOS_CENTER},
173 {TAG_END,0}},
175 *makelink_gadgets[]={
176 makelink_name_gadget,
177 makelink_type_gadget,
178 makelink_destname_gadget,
179 makelink_glass_gadget,
180 makelink_okay_gadget,
181 makelink_cancel_gadget,
182 NULL};
184 int getmakelinkdata(char *namebuf, char *destbuf, int *type)
186 ULONG class;
187 UWORD gadgetid,__unused code;
188 struct Window *swindow;
189 struct Gadget *name_gad,*makelink_type_gad, *makelink_destname_gad;
190 char *makelink_type_array[3] = {globstring[STR_MAKELINK_TYPE_SOFT], globstring[STR_MAKELINK_TYPE_HARD], NULL};
191 char makelink_namebuf[108], makelink_destbuf[256];
192 int makelink_type;
193 int ret=0;
195 strcpy(makelink_namebuf,namebuf);
196 strcpy(makelink_destbuf,destbuf);
197 makelink_type = type ? 1: 0;
199 fix_requester(&makelink_req,globstring[STR_ENTER_MAKELINK_PARAMS]);
201 set_reqobject(makelink_name_gadget,RO_StringBuf,(IPTR)makelink_namebuf);
202 set_reqobject(makelink_destname_gadget,RO_StringBuf,(IPTR)makelink_destbuf);
204 if (!(swindow=OpenRequester(&makelink_req)) ||
205 !(name_gad=addreqgadgets(&makelink_req,makelink_gadgets,0,NULL)) ||
206 !(AddRequesterObject(&makelink_req,makelink_type_text)) ||
207 !(AddRequesterObject(&makelink_req,makelink_name_text)) ||
208 !(AddRequesterObject(&makelink_req,makelink_dest_text))) {
209 CloseRequester(&makelink_req);
210 return(0);
212 RefreshRequesterObject(&makelink_req,NULL);
214 makelink_type_gad=name_gad->NextGadget;
215 makelink_destname_gad=makelink_type_gad->NextGadget;
216 DoCycleGadget(makelink_type_gad,swindow,makelink_type_array,makelink_type);
218 ActivateStrGad(name_gad,swindow);
220 FOREVER {
221 Wait(1<<swindow->UserPort->mp_SigBit);
222 while ((IMsg=(struct IntuiMessage *)GetMsg(swindow->UserPort))) {
223 class=IMsg->Class;
224 code=IMsg->Code;
225 switch (class)
227 case IDCMP_GADGETUP:
228 gadgetid=((struct Gadget *) IMsg->IAddress)->GadgetID;
229 break;
231 ReplyMsg((struct Message *) IMsg);
233 switch (class) {
234 case IDCMP_MOUSEBUTTONS:
235 ActivateStrGad(name_gad,swindow);
236 break;
238 case IDCMP_GADGETUP:
239 switch (gadgetid) {
241 case SELECT_SELECTBASE:
242 strcpy(buffer[select_base],sel_patternbuf);
243 if (++select_base>3) select_base=0;
244 DoCycleGadget(gadlist,swindow,select_base_array,select_base);
245 strcpy(sel_patternbuf,buffer[select_base]);
246 RefreshStrGad(gadlist->NextGadget,swindow);
247 ActivateStrGad(gadlist->NextGadget,swindow);
248 break;
249 case SELECT_PATTERN:
250 if (code==0) // RETURN
251 ret=select_type+1;
252 else if (code!=0xFFFF) // ESC
253 break;
255 case MAKELINK_TYPE:
256 if (++makelink_type>1) makelink_type=0;
257 DoCycleGadget(makelink_type_gad,swindow,makelink_type_array,makelink_type);
258 ActivateStrGad(name_gad,swindow);
259 break;
260 case MAKELINK_DESTSELECT:
262 struct DOpusFileReq filereq;
263 char dirbuf[256],filebuf[FILEBUF_SIZE],*ptr;
265 filereq.dirbuf=dirbuf;
266 filereq.filebuf=filebuf;
267 filereq.window=swindow;
268 filereq.x=-2;
269 filereq.y=-2;
270 filereq.lines=15;
271 filereq.flags=0;
272 filereq.title=globstring[STR_FILE_REQUEST];
273 filereq.filearraykey=NULL;
275 LStrCpy(dirbuf,makelink_destbuf);
276 if ((ptr=BaseName(dirbuf))>dirbuf) {
277 LStrCpy(filebuf,ptr);
278 *ptr=0;
280 else if (CheckExist(dirbuf,NULL)<1) {
281 dirbuf[0]=0;
282 LStrCpy(filebuf,makelink_destbuf);
284 else filebuf[0]=0;
285 if (FileRequest(&filereq)) {
286 LStrCpy(makelink_destbuf,dirbuf);
287 TackOn(makelink_destbuf,filebuf,256);
289 RefreshStrGad(makelink_destname_gad,swindow);
290 ActivateStrGad(makelink_destname_gad,swindow);
291 break;
293 case MAKELINK_OKAY:
294 ret=1;
295 strcpy(namebuf,str_pathbuffer[data_active_window]);
296 TackOn(namebuf,makelink_namebuf,256);
297 strcpy(destbuf,makelink_destbuf);
298 *type=makelink_type;
299 case MAKELINK_CANCEL:
300 CloseRequester(&makelink_req);
301 return(ret);
303 break;
309 int makelink(int rexx)
311 char name[256], path[256];
312 int mode;
314 name[0]=path[0]=mode=0;
316 if (rexx)
318 strcpy(name,rexx_args[0]);
319 strcpy(path,rexx_args[1]);
320 if (atoi(rexx_args[2])) mode = 1;
322 else if (!(getmakelinkdata(name,path,&mode))) return 0;
324 if (name[0] && path[0])
326 BPTR lock;
328 if (mode)
330 if ((lock = Lock(path,ACCESS_READ)))
332 if (MakeLink(name,(SIPTR)lock,FALSE))
334 dostatustext(str_okaystring);
335 return 1;
338 doerror(-1);
339 return 0;
341 else
343 if (MakeLink(name,(SIPTR)path,TRUE))
345 dostatustext(str_okaystring);
346 return 1;
348 doerror(-1);
349 return 0;
352 doerror(ERROR_REQUIRED_ARG_MISSING);
353 return 0;