remove the second -lssl in the generated Makefile so that it doesn't break the build.
[AROS-Contrib.git] / dopus / Program / main4.c
blob4c0d2f0d18d7803ef1a9dbc3ae64a202688cb481
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"
32 #include <ctype.h>
33 #ifndef __AROS__
34 #include <proto/xfdmaster.h>
35 #endif
36 #include <proto/cybergraphics.h>
37 #include <cybergraphx/cybergraphics.h>
39 void makedir(rexx)
40 int rexx;
42 struct FileInfoBlock __aligned fileinfo;
43 int a,success,win,err,addicon = 0;
44 char dirname[FILEBUF_SIZE],new_directory[256];
45 BPTR lock;
47 win=data_active_window;
48 if (/*(dopus_curwin[win] == dopus_specialwin[win]) ||*/ (dopus_curwin[win]->directory[0] == 0)) return;
49 dirname[0]=new_directory[0]=0;
51 FOREVER {
52 if (rexx) {
53 for (a=0;a<256;a++) {
54 if (!rexx_args[0][a] || rexx_args[0][a]=='/' || rexx_args[0][a]==':') break;
56 if (!rexx_args[0][a]) {
57 if (!(isvalidwindow(data_active_window))) return;
58 strcpy(new_directory,str_pathbuffer[data_active_window]);
59 TackOn(new_directory,rexx_args[0],256);
60 if (rexx_args[1][0] && (rexx_args[1][0] == '1')) addicon = 1;
62 else {
63 strcpy(new_directory,rexx_args[0]);
64 win=-1;
67 else if (status_iconified) {
68 if (!(status_flags&STATUS_ISINBUTTONS) ||
69 (!(getdummypath(new_directory,STR_ENTER_DIRECTORY_NAME)))) return;
70 win=-1;
72 else {
73 if (!(isvalidwindow(data_active_window))) return;
74 strcpy(new_directory,str_pathbuffer[data_active_window]);
76 if (!(whatsit(globstring[STR_ENTER_DIRECTORY_NAME],
77 config->iconflags&ICONFLAG_MAKEDIRICON ? FILEBUF_SIZE-7 : FILEBUF_SIZE-2,
78 dirname,NULL)) ||
79 !dirname[0]) {
80 myabort();
81 return;
83 for (a=0;dirname[a];a++) {
84 if (dirname[a]=='/' || dirname[a]==':') {
85 dirname[a]=0;
86 break;
89 if (!dirname[0]) {
90 myabort();
91 return;
93 TackOn(new_directory,dirname,256);
96 if (!(lock=CreateDir(new_directory))) {
97 doerror((err=IoErr()));
98 if (rexx || (a=checkerror(globstring[STR_CREATING_DIRECTORY],
99 BaseName(new_directory),-err))==3) {
100 myabort();
101 return;
103 continue;
106 Examine(lock,&fileinfo);
107 UnLock(lock);
109 if (win>-1) {
110 addfile(dopus_curwin[win],win,fileinfo.fib_FileName,-1,
111 fileinfo.fib_DirEntryType,&fileinfo.fib_Date,
112 NULL,fileinfo.fib_Protection,0,TRUE,NULL,NULL,
113 fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
114 seename(win);
115 update_buffer_stamp(win,1);
118 success=1;
119 if ((config->iconflags&ICONFLAG_MAKEDIRICON) || addicon) {
120 strcat(new_directory,".info");
121 if ((iconwrite(ICONTYPE_DRAWER,new_directory))==1 &&
122 (lockandexamine(new_directory,&fileinfo))) {
123 if (win>-1) {
124 addfile(dopus_curwin[win],win,fileinfo.fib_FileName,
125 fileinfo.fib_Size,fileinfo.fib_DirEntryType,&fileinfo.fib_Date,
126 fileinfo.fib_Comment,fileinfo.fib_Protection,0,TRUE,NULL,NULL,
127 fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
128 seename(win);
129 update_buffer_stamp(win,1);
132 else success=0;
134 break;
136 if (success) dostatustext(globstring[STR_DIRECTORY_CREATED]);
139 int iconwrite(type,name)
140 int type;
141 char *name;
143 int suc,err;
144 struct DiskObject *diskobj;
145 char namebuf[256],*ptr,*originalicon,sourcebuf[256];
146 struct dopusfiletype *ftype;
148 if (!IconBase) return(0);
150 strcpy(namebuf,name);
151 if ((ptr=strstri(namebuf,".info"))) *ptr=0;
153 if (type==ICONTYPE_DRAWER) originalicon=config->drawericon;
154 else if (type==ICONTYPE_TRASH) originalicon=NULL;
155 else {
156 ftype=checkfiletype(namebuf,-2,0);
157 if (ftype && ftype->iconpath) originalicon=ftype->iconpath;
158 else if (type==ICONTYPE_TOOL) originalicon=config->toolicon;
159 else originalicon=config->projecticon;
162 if (originalicon) {
163 strcpy(sourcebuf,originalicon);
164 if (!(strstri(sourcebuf,".info"))) strcat(sourcebuf,".info");
167 FOREVER {
168 if (originalicon && originalicon[0] && (CheckExist(sourcebuf,NULL)<0)) {
169 if ((copyicon(originalicon,namebuf,&err))>0) return(1);
171 else {
172 if (/*system_version2 &&*/ (diskobj=GetDefDiskObject(type+2))) {
173 if (diskobj->do_Type==WBPROJECT && config->defaulttool[0]) {
174 ptr=diskobj->do_DefaultTool;
175 diskobj->do_DefaultTool=config->defaulttool;
177 else ptr=NULL;
178 suc=PutDiskObject(namebuf,diskobj);
179 if (ptr) diskobj->do_DefaultTool=ptr;
180 FreeDiskObject(diskobj);
181 if (suc) return(1);
182 err=IoErr();
184 else {
185 if (type==ICONTYPE_PROJECT)
186 icontable[ICONTYPE_PROJECT]->do_DefaultTool=config->defaulttool;
187 if (PutDiskObject(namebuf,icontable[type])) return(1);
188 err=IoErr();
191 if ((suc=checkerror(globstring[STR_ADDING_ICON],BaseName(namebuf),err))==3)
192 return(-1);
193 if (suc==0 || suc==2) return(0);
197 int copyicon(srce,dest,err)
198 char *srce,*dest;
199 int *err;
201 int suc;
202 struct DiskObject *diskobj;
203 char /*buf[256],*/buf1[256],*ptr;
205 strcpy(buf1,srce);
206 if ((ptr=strstri(buf1,".info"))) *ptr=0;
208 if ((diskobj=GetDiskObject(buf1))) {
209 suc=PutDiskObject(dest,diskobj);
210 FreeDiskObject(diskobj);
211 if (!suc || CheckExist(dest,NULL)>=0) *err=IoErr();
213 else {
214 // StrCombine(buf,dest,".info",256);
215 // suc=copyfile(srce,buf,err,/*-1,*/NULL,0);
216 SetIoErr(ERROR_OBJECT_NOT_FOUND);
217 suc = 0;
219 return(suc);
222 char *isicon(name)
223 char *name;
225 int a;
227 if ((a=strlen(name))<6) return(NULL);
228 if (Stricmp(&name[a-5],".info")==0) return(&name[a-5]);
229 return(NULL);
232 char *getarexxpath(rexx,win,num,argnum)
233 int rexx,win,num,argnum;
235 struct FileInfoBlock __aligned fblock;
236 int a,b;
237 char *ptr;
238 APTR save;
240 if (!rexx || !rexx_argcount) return(str_pathbuffer[win]);
241 if ((strchr(rexx_args[argnum],':') || strchr(rexx_args[argnum],'/')) &&
242 (a=CheckExist(rexx_args[argnum],&b))) {
243 if (!num) {
244 save=main_proc->pr_WindowPtr;
245 main_proc->pr_WindowPtr=(APTR)-1;
246 dos_global_entry.subtype=0;
247 if (lockandexamine(rexx_args[argnum],&fblock)) {
248 dos_global_entry.protection=fblock.fib_Protection;
249 dos_global_entry.comment=dos_copy_comment;
250 strcpy(dos_copy_comment,fblock.fib_Comment);
251 dos_global_entry.dispstr=NULL;
252 getprot(dos_global_entry.protection,dos_global_entry.protbuf);
253 CopyMem(&fblock.fib_Date,&dos_global_entry.date,sizeof(struct DateStamp));
254 seedate(&dos_global_entry.date,dos_global_entry.datebuf,1);
255 dos_global_entry.selected=0;
257 main_proc->pr_WindowPtr=save;
258 ptr=BaseName(rexx_args[argnum]);
259 strcpy(dos_global_entry.name,ptr);
260 if (ptr>rexx_args[argnum]) {
261 *ptr=0;
262 strcpy(rexx_pathbuffer[win],rexx_args[argnum]);
263 TackOn(rexx_pathbuffer[win],NULL,256);
265 else rexx_pathbuffer[win][argnum]=0;
266 dos_global_entry.last=dos_global_entry.next=NULL;
267 dos_global_entry.type=a;
268 dos_global_entry.size=b;
269 func_single_entry=&dos_global_entry;
270 removeargstring(argnum);
271 return(rexx_pathbuffer[win]);
273 else {
274 strcpy(rexx_pathbuffer[win],rexx_args[argnum]);
275 TackOn(rexx_pathbuffer[win],NULL,256);
276 removeargstring(argnum);
277 return(rexx_pathbuffer[win]);
280 return(str_pathbuffer[win]);
283 int readfile(name,buf,size)
284 char *name,**buf;
285 int *size;
287 BPTR in;
288 int retval /*loadpp*/ = 0;
290 if (PPBase) {
291 if ((in=ppLoadData(name,DECR_POINTER,MEMF_CLEAR,buf,size,NULL))) {
292 if (in==PP_OPENERR || in==PP_READERR) return(-1);
293 if (in==PP_NOMEMORY) return(-2);
295 else loadpp=1;
297 if (!loadpp)
299 if (CheckExist(name,size)>=0 || !(in=Open(name,MODE_OLDFILE))) return(-1);
300 if ((*buf=AllocVec(*size,MEMF_ANY)))
302 Read(in,*buf,*size);
304 #ifndef __AROS__
305 if (OpenXFDlib())
307 struct xfdBufferInfo *xfdbi;
309 if ((xfdbi = xfdAllocObject(XFDOBJ_BUFFERINFO)))
311 xfdbi->xfdbi_SourceBuffer = *buf;
312 xfdbi->xfdbi_SourceBufLen = *size;
313 // xfdbi->xfdbi_Flags = XFDFB_RECOGEXTERN;
314 if (xfdRecogBuffer(xfdbi))
316 xfdbi->xfdbi_TargetBufMemType = MEMF_ANY;
317 if (xfdDecrunchBuffer(xfdbi))
319 FreeVec(xfdbi->xfdbi_SourceBuffer);
320 // *size = xfdbi->xfdbi_TargetBufLen;
321 *size = xfdbi->xfdbi_TargetBufSaveLen;
322 if ((*buf = AllocVec(*size, MEMF_ANY))) CopyMem(xfdbi->xfdbi_TargetBuffer,*buf,*size);
323 else *buf = xfdbi->xfdbi_TargetBuffer;
325 else retval = -2;
327 xfdFreeObject(xfdbi);
330 #endif
332 else retval = -2;
333 Close(in);
334 //D(bug("readfile() ends\n");Delay(50);)
335 return(retval);
338 int getnewprot(old,new,mask)
339 int old,new,mask;
341 int val,a;
343 if (!mask) return(new);
344 val=old&(~255);
345 for (a=0;a<8;a++) {
346 if (mask&(1<<a)) {
347 if (old&(1<<a)) val|=(1<<a);
349 else if (new&(1<<a)) val|=(1<<a);
351 return(val);
354 int dateformat(flag)
355 int flag;
357 int a;
359 for (a=0;a<4;a++) {
360 if (flag&(1<<a)) return(a);
362 return(a);
365 int checkscreenmode(mode)
366 int mode;
368 DisplayInfoHandle *handle;
369 struct DimensionInfo *dimension;
370 char buf[256];
371 int flags,minw,defw;
373 if (mode==MODE_WORKBENCHUSE || mode==MODE_WORKBENCHCLONE || mode==MODE_PUBLICSCREEN)
374 return(mode);
375 /* if (!system_version2) {
376 if (mode==HIRES_KEY || mode==HIRESLACE_KEY) return(mode);
377 return(MODE_WORKBENCHCLONE);
378 } */
379 if (!(handle=FindDisplayInfo(mode)) ||
380 !(GetDisplayInfoData(handle,buf,256,DTAG_DISP,0)) ||
381 ((struct DisplayInfo *)buf)->NotAvailable)
382 return(MODE_WORKBENCHCLONE);
383 if (CyberGfxBase)
385 if (IsCyberModeID(mode))
387 if (GetCyberIDAttr(CYBRIDATTR_WIDTH,mode) >= 640) return (mode);
390 flags=((struct DisplayInfo *)buf)->PropertyFlags;
391 if (flags&DIPF_IS_DUALPF || flags&DIPF_IS_PF2PRI || flags&DIPF_IS_HAM ||
392 !(GetDisplayInfoData(handle,buf,256,DTAG_DIMS,0)))
393 return(MODE_WORKBENCHCLONE);
394 dimension=(struct DimensionInfo *)buf;
395 if (mode&HIRES_KEY || mode&HIRESLACE_KEY) minw=640;
396 else {
397 minw=dimension->MinRasterWidth;
398 if (minw<160) minw*=10;
400 defw=(dimension->TxtOScan.MaxX-dimension->TxtOScan.MinX)+1;
401 if ((minw<640 || defw<640) && dimension->MaxDepth>=5)
402 return(MODE_WORKBENCHCLONE);
403 return(mode);
406 void doarrowgadgets(gad,dir)
407 struct Gadget *gad;
408 int dir;
410 int a;
412 for (a=0;a<2;a++) {
413 if (!gad) break;
414 do3dbox(main_rp,
415 gad->LeftEdge+2,
416 gad->TopEdge+1,
417 gad->Width-4,
418 gad->Height-2);
419 DoArrow(main_rp,
420 gad->LeftEdge+2,
421 gad->TopEdge+1,
422 gad->Width-4,
423 gad->Height-2,
424 screen_pens[config->arrowfg].pen,
425 screen_pens[config->arrowbg].pen,dir);
426 gad=gad->NextGadget;
430 void makermbgad(rmbgad,gad,high)
431 struct RMBGadget *rmbgad;
432 struct Gadget *gad;
433 int high;
435 rmbgad->x=gad->LeftEdge;
436 rmbgad->y=gad->TopEdge;
437 rmbgad->w=gad->Width;
438 rmbgad->h=gad->Height;
439 if (high && gad->GadgetRender) {
440 rmbgad->flags|=RGF_ALTBORD;
441 rmbgad->high_bord[0]=gad->GadgetRender;
442 rmbgad->high_bord[1]=gad->SelectRender;
444 else rmbgad->flags&=~RGF_ALTBORD;
447 void dolittlegads(gad,txt,num)
448 struct Gadget *gad;
449 char *txt;
450 int num;
452 int a,y;
453 struct TextFont *font;
455 if (status_iconified || !Window) return;
457 font=main_rp->Font;
458 SetFont(main_rp,scr_font[FONT_GENERAL]);
459 for (a=0;a<num;a++) {
460 do3dbox(main_rp,gad->LeftEdge+2,gad->TopEdge+1,gad->Width-4,gad->Height-2);
461 SetAPen(main_rp,screen_pens[config->littlegadbg].pen);
462 rectfill(main_rp,gad->LeftEdge+2,gad->TopEdge+1,gad->Width-4,gad->Height-2);
463 SetAPen(main_rp,screen_pens[config->littlegadfg].pen);
464 SetBPen(main_rp,screen_pens[config->littlegadbg].pen);
465 y=gad->TopEdge+1+(((gad->Height-2)-scr_font[FONT_GENERAL]->tf_YSize)/2);
466 if (y<gad->TopEdge+1) y=gad->TopEdge+1;
467 y+=scr_font[FONT_GENERAL]->tf_Baseline;
468 Move(main_rp,gad->LeftEdge+((gad->Width-scr_font[FONT_GENERAL]->tf_XSize)/2),y);
469 Text(main_rp,&txt[a],1);
470 RefreshGList(gad,Window,NULL,1);
471 if (!(gad=gad->NextGadget)) break;
473 SetFont(main_rp,font);
476 void rectfill(r,x,y,w,h)
477 struct RastPort *r;
478 int x,y,w,h;
480 if (w<0 || h<0) return;
481 RectFill(r,x,y,x+w-1,y+h-1);
484 int isvalidwindow(win)
485 int win;
487 if (!str_pathbuffer[win]) return(0);
488 if (dopus_curwin[win]->total>0 && dopus_curwin[win]->firstentry->type==ENTRY_CUSTOM)
489 return(0);
490 return(1);
493 int _isdigit (unsigned char c)
495 return locale?IsDigit(locale,c):isdigit(c);
498 int _isxdigit (unsigned char c)
500 return locale?IsXDigit(locale,c):isxdigit(c);
503 int _isprint (unsigned char c)
505 return locale?IsPrint(locale,c):isprint(c);
508 int _isspace (unsigned char c)
510 return locale?IsSpace(locale,c):isspace(c);
513 int _isupper (unsigned char c)
515 return locale?IsUpper(locale,c):isupper(c);
518 int _ispunct (unsigned char c)
520 return locale?IsPunct(locale,c):ispunct(c);