finally the biggest changes together with makefile. hardcoded flag removed.
[AROS-Contrib.git] / dopus / Program / main13.c
blob8b1e8d1f562ae56f2285968ff56efa17c938e534
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 #ifdef __SASC__
34 #include <i64.h>
35 #endif
37 void seedate(ds,date,pad)
38 struct DateStamp *ds;
39 char *date;
40 int pad;
42 char timebuf[16],datebuf[16]/*,buf[40]*/;
43 struct DOpusDateTime dt;
45 copy_datestamp(ds,&dt.dat_Stamp);
46 initdatetime(&dt,datebuf,timebuf,1);
48 lsprintf(date,"%s %s",datebuf,timebuf);
49 //D(bug("date: %s, time: %s\n",datebuf,timebuf));
51 strncpy(buf,datebuf,9);
52 buf[9]=0;
53 strcat(buf," ");
54 strcat(buf,timebuf);
55 buf[19]=0;
57 if (pad) {
58 if (config->dateformat&DATE_12HOUR) lsprintf(date,"%19s",buf);
59 else lsprintf(date,"%18s",buf);
61 else strcpy(date,buf);
65 int setdate(name,date)
66 char *name;
67 struct DateStamp *date;
69 /* char __aligned bstrname[FILEBUF_SIZE+4];
70 struct MsgPort *handler;
71 ULONG arg[4];
72 BPTR lock,parentlock;
73 APTR wsave;
75 int rc=/*0*/SetFileDate(name,date);
77 wsave=main_proc->pr_WindowPtr;
78 main_proc->pr_WindowPtr=(APTR)-1;
80 if (handler=(struct MsgPort *)DeviceProc(name)) {
81 if (lock=Lock(name,ACCESS_READ)) {
82 parentlock=ParentDir(lock);
83 UnLock(lock);
85 strcpy(&bstrname[1],FilePart(name));
86 bstrname[0]=strlen(&bstrname[1]);
88 arg[0]=0;
89 arg[1]=(IPTR)parentlock;
90 arg[2]=(IPTR)MKBADDR(bstrname);
91 arg[3]=(IPTR)date;
92 rc=SendPacket(handler,ACTION_SET_DATE,arg,4);
93 UnLock(parentlock);
97 main_proc->pr_WindowPtr=wsave;
99 return(rc?1:IoErr());
102 void seename(win)
103 int win;
105 long long tot;
106 int bl,a;
107 static char buf[256];
109 if (win<0 || status_iconified) return;
110 if (!dopus_curwin[win]->firstentry ||
111 (dopus_curwin[win]->firstentry->type!=ENTRY_DEVICE &&
112 dopus_curwin[win]->firstentry->type!=ENTRY_CUSTOM)) {
113 if (str_pathbuffer[win][0]==0) {
114 if (win==data_active_window)
115 SetAPen(main_rp,screen_pens[config->disknameselbg].pen);
116 else SetAPen(main_rp,screen_pens[config->disknamebg].pen);
117 rectfill(main_rp,
118 scrdata_diskname_xpos[win]+2,scrdata_diskname_ypos,
119 scrdata_diskname_width[win],scrdata_diskname_height-2);
120 SetAPen(main_rp,screen_pens[1].pen);
121 return;
123 else {
124 if (dopus_curwin[win]->flags & DWF_ARCHIVE)
126 if (dopus_curwin[win]->arcname)
128 char *c;
130 //D(bug("path: %s",dopus_curwin[win]->arcname));
131 c = strstr(dopus_curwin[win]->directory,FilePart(dopus_curwin[win]->arcname));
132 if (c) for (a = 0; c && (*c != '/') && (a < 31); c++) dopus_curwin[win]->diskname[a++] = *c;
133 dopus_curwin[win]->diskname[a] = 0;
134 displayname(win,1);
135 return;
138 strcpy(buf,str_pathbuffer[win]);
139 dopus_curwin[win]->diskname[0]=0;
140 main_proc->pr_WindowPtr=(APTR)-1;
141 if (!(a=getroot(buf,NULL))) {
142 strcpy(dopus_curwin[win]->diskname,globstring[STR_DIR_NOT_AVAILABLE_TITLE]);
143 #ifdef __SASC__
144 dopus_curwin[win]->disktot = i64_atoi( "-1" );
145 dopus_curwin[win]->diskfree = i64_atoi( "-1" );
146 dopus_curwin[win]->diskblock = -1;
147 #else
148 dopus_curwin[win]->disktot=dopus_curwin[win]->diskfree=dopus_curwin[win]->diskblock=-1;
149 #endif
150 displayname(win,1);
151 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
152 return;
154 strcpy(dopus_curwin[win]->diskname,buf);
155 /* */
156 strcpy(dopus_curwin[win]->volumename,buf);
157 /* */
158 dopus_curwin[win]->diskfree=bytes(str_pathbuffer[win],&tot,&bl);
159 dopus_curwin[win]->disktot=tot;
160 dopus_curwin[win]->diskblock=bl;
161 if (a==ID_WRITE_PROTECTED) dopus_curwin[win]->flags|=DWF_READONLY;
162 else dopus_curwin[win]->flags&=~DWF_READONLY;
163 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
166 displayname(win,0);
169 void displayname(win,clear)
170 int win,clear;
172 #ifdef __SASC__
173 bigint free, tot, temp1;
174 #else
175 long long free, tot;
176 #endif
177 int b,x,nn=0,len,len2,len3,x1,cx1,cx2;
178 static char buf[30],buf2[80],buf3[20];
179 double pct;
181 if (status_iconified || win<0) return;
182 if (str_pathbuffer[win][0]==0) {
183 #ifdef __SASC__
184 bigint temp1;
186 temp1 = i64_atoi( "-1" );
188 if ( i64_cmp( dopus_curwin[win]->disktot, temp1 ) != I64_EQUAL &&
189 #else
190 if (dopus_curwin[win]->disktot!=-1 &&
191 #endif
192 (!dopus_curwin[win]->firstentry || dopus_curwin[win]->firstentry->type!=ENTRY_DEVICE)) nn=2;
193 else nn=1;
195 if (nn!=2) {
196 free=dopus_curwin[win]->diskfree; tot=dopus_curwin[win]->disktot;
197 SetDrMd(main_rp,JAM2);
199 StrCombine(buf2,dopus_curwin[win]->diskname,str_space_string,80);
200 SetFont(main_rp,scr_font[FONT_NAMES]);
202 len=30;
203 x1=dotextlength(main_rp,buf2,&len,scrdata_diskname_width[win]-4);
205 #ifdef __SASC__
206 temp1 = i64_atoi( "-1" );
207 if (!nn && ( i64_cmp( tot, temp1 ) == I64_GREATER )) {
208 #else
209 if (!nn && tot>-1) {
210 #endif
211 if (config->showfree&SHOWFREE_BYTES || config->showfree==0) {
212 #ifdef __SASC__
213 char buf1[30];
215 i64_itoa( free, buf1, 30 );
216 if (dopus_curwin[win]->flags&DWF_READONLY)
217 lsprintf(buf," (%s)",buf1);
218 else lsprintf(buf," %s",buf1);
219 #else
220 if (dopus_curwin[win]->flags&DWF_READONLY) sprintf(buf," (%qd)",free);
221 else sprintf(buf," %qd",free);
222 #endif
224 else if (config->showfree&SHOWFREE_KILO) {
225 getsizestring(buf,free);
226 if (dopus_curwin[win]->flags&DWF_READONLY)
228 char buf1[30];
230 lsprintf(buf1,"(%s)",buf);
231 strcpy(buf,buf1);
234 else if (config->showfree&SHOWFREE_BLOCKS) {
235 if (dopus_curwin[win]->flags&DWF_READONLY)
236 lsprintf(buf," (%ld)",dopus_curwin[win]->diskblock);
237 else lsprintf(buf," %ld",dopus_curwin[win]->diskblock);
239 else if (config->showfree&SHOWFREE_PERCENT) {
240 #ifdef __SASC__
241 temp1 = i64_atoi( "0" );
243 if ( i64_cmp( tot, temp1 ) == I64_EQUAL ) b=100;
244 else {
245 pct=free.lo; pct*=100; // HUX ??
246 b=(int)(pct/(double)tot.lo); // HUX ??
248 #else
249 if (tot==0) b=100;
250 else {
251 pct=free; pct*=100;
252 b=(int)(pct/(double)tot);
254 #endif
255 if (b>100) b=100;
256 if (dopus_curwin[win]->flags&DWF_READONLY)
257 lsprintf(buf," (%ld%%)",b);
258 else lsprintf(buf," %ld%%",b);
260 StrCombine(buf3,buf,str_space_string,14);
261 len2=12; len3=strlen(buf);
262 FOREVER {
263 x=dotextlength(main_rp,buf3,&len2,scrdata_diskname_width[win]-x1-4);
264 if (len2>=len3 || (--len)==0) break;
265 len2=12; x1=dotextlength(main_rp,buf2,&len,scrdata_diskname_width[win]-4);
267 strncpy(buf3,str_space_string,13);
268 strcpy(&buf3[len2-len3],buf);
270 else x=0;
273 if (clear) {
274 if (win==data_active_window)
275 SetAPen(main_rp,screen_pens[config->disknameselbg].pen);
276 else SetAPen(main_rp,screen_pens[config->disknamebg].pen);
277 rectfill(main_rp,
278 scrdata_diskname_xpos[win]+2,
279 scrdata_diskname_ypos,
280 scrdata_diskname_width[win],
281 scrdata_diskname_height-2);
284 if (nn!=2) {
285 if (win==data_active_window) {
286 SetAPen(main_rp,screen_pens[config->disknameselfg].pen);
287 SetBPen(main_rp,screen_pens[config->disknameselbg].pen);
289 else {
290 SetAPen(main_rp,screen_pens[config->disknamefg].pen);
291 SetBPen(main_rp,screen_pens[config->disknamebg].pen);
294 Move(main_rp,
295 scrdata_diskname_xpos[win]+4,
296 scrdata_diskname_ypos+scr_font[FONT_NAMES]->tf_Baseline);
297 Text(main_rp,buf2,len);
299 cx1=main_rp->cp_x;
300 if (x) {
301 x1=(scrdata_diskname_xpos[win]+scrdata_diskname_width[win])-x;
302 if (x1<scrdata_diskname_xpos[win]+2) x1=scrdata_diskname_xpos[win]+2;
303 cx2=x1-1;
304 Move(main_rp,x1,scrdata_diskname_ypos+scr_font[FONT_NAMES]->tf_Baseline);
305 Text(main_rp,buf3,len2);
307 else cx2=scrdata_diskname_xpos[win]+scrdata_diskname_width[win]+1;
308 if (!clear && cx1<=cx2) {
309 SetAPen(main_rp,main_rp->BgPen);
310 RectFill(main_rp,cx1,scrdata_diskname_ypos,cx2,scrdata_diskname_height+scrdata_diskname_ypos-3);
312 SetFont(main_rp,scr_font[FONT_GENERAL]);
316 void relabel_disk(rexx,path)
317 int rexx;
318 char *path;
320 // struct MsgPort *port;
321 char oldname[36],name[36]/*,*bstr*/;
322 // ULONG arg;
323 char buf[256];
324 // int a;
326 strcpy(buf,rexx?rexx_args[0]:path);
327 D(bug("relabel(%ld,%s)\n",rexx,buf));
328 if (!(getroot(buf,NULL))) {
329 doerror(-1);
330 return;
332 strcat(buf,":");
333 // if (!(port=(struct MsgPort *) DeviceProc(buf))) return;
334 getroot(buf,NULL);
336 strcpy(name,buf); strcpy(oldname,name);
337 if (!rexx) {
338 if (!(whatsit(globstring[STR_ENTER_NEW_DISK_NAME],30,name,NULL))) return;
340 else strcpy(name,rexx_args[1]);
342 if (name[strlen(name)-1] == ':') name[strlen(name)-1] = 0;
344 strcat(buf,":");
345 D(bug("Relabel(%s,%s)\n",buf,name));
346 if (! Relabel(buf,name)) doerror(-1);
348 a=strlen(name);
349 bstr=(char *) AllocMem(a+2,MEMF_CLEAR))
350 bstr[0]=(char)a;
351 strcpy(bstr+1,name);
352 arg=(IPTR)MKBADDR(bstr);
353 if (!(SendPacket(port,ACTION_RENAME_DISK,&arg,1))) doerror(-1);
355 else if ((!status_iconified) && (dopus_curwin[data_active_window] != dopus_specialwin[data_active_window])) {
356 if ((Strnicmp(str_pathbuffer[data_active_window],oldname,strlen(oldname)))==0 &&
357 str_pathbuffer[data_active_window][strlen(oldname)]==':') {
358 strcpy(buf,name);
359 StrConcat(buf,&str_pathbuffer[data_active_window][strlen(oldname)],256);
360 strcpy(str_pathbuffer[data_active_window],buf);
361 checkdir(str_pathbuffer[data_active_window],&path_strgadget[data_active_window]);
362 strcpy(dopus_curwin[data_active_window]->directory,str_pathbuffer[data_active_window]);
364 seename(data_active_window);
366 // FreeMem(bstr,a+2);
369 int getroot(name,ds)
370 char *name;
371 struct DateStamp *ds;
373 struct InfoData __aligned info;
374 BPTR lock1;
375 struct FileLock *lock2;
376 char *p;
377 struct DeviceList *dl;
378 int a;
380 if (!(lock1=Lock(name,ACCESS_READ))) return(0);
381 lock2=(struct FileLock *) BADDR(lock1);
382 for (a=0;a<FILEBUF_SIZE;a++) name[a]=0;
383 dl=(struct DeviceList *)BADDR(lock2->fl_Volume);
384 p=(char *) BADDR(dl->dl_Name);
385 #ifdef __AROS__
386 if (p) LStrnCpy(name,AROS_BSTR_ADDR(p),AROS_BSTR_strlen(p));
387 #else
388 if (p) LStrnCpy(name,p+1,*p);
389 #endif
390 if (ds) CopyMem((char *)&dl->dl_VolumeDate,(char *)ds,sizeof(struct DateStamp));
391 Info(lock1,&info);
392 UnLock(lock1);
393 return(info.id_DiskState);
396 BPTR getrootlock(lock1)
397 BPTR lock1;
399 BPTR lock2;
401 while ((lock2=ParentDir(lock1))) {
402 UnLock(lock1);
403 lock1=lock2;
405 return(lock1);
408 void strtostamp(date,time,ds)
409 char *date,*time;
410 struct DateStamp *ds;
412 struct DOpusDateTime datetime;
414 datetime.dat_Stamp.ds_Days = 0;
415 datetime.dat_Stamp.ds_Minute = 0;
416 datetime.dat_Stamp.ds_Tick = 0;
418 datetime.dat_Format=dateformat(config->dateformat);
419 datetime.dat_Flags=0/*DDTF_SUBST|DDTF_CUSTOM*/;
420 datetime.dat_StrDate=date;
421 datetime.dat_StrTime=time;
422 // datetime.custom_months=date_months;
423 // datetime.custom_shortmonths=date_shortmonths;
424 // datetime.custom_weekdays=date_weekdays;
425 // datetime.custom_shortweekdays=date_shortweekdays;
426 // datetime.custom_special_days=date_special;
427 // StrToStamp(&datetime);
428 StrToDate((struct DateTime *)&datetime);
429 // D(bug("strtostamp(%s,%s)=%ld\n",date,time,StrToDate((struct DateTime *)&datetime)));
430 copy_datestamp(&datetime.dat_Stamp,ds);