2 * ADF Library. (C) 1997-1999 Laurent Clevy
16 extern struct Env adfEnv
;
22 * write an ULONG value (val) (in)
23 * to an unsigned char* buffer (buf) (out)
25 * used in adfWrite----Block() functions
27 void swLong(UBYTE
* buf
, ULONG val
)
29 buf
[0]= (UBYTE
)((val
& 0xff000000) >>24UL);
30 buf
[1]= (UBYTE
)((val
& 0x00ff0000) >>16UL);
31 buf
[2]= (UBYTE
)((val
& 0x0000ff00) >>8UL);
32 buf
[3]= (UBYTE
)(val
& 0x000000ff);
35 void swShort(UBYTE
* buf
, USHORT val
)
37 buf
[0]= (val
& 0xff00) >>8UL;
38 buf
[1]= (val
& 0x00ff) ;
44 * adds a cell at the end the list
46 struct List
* newCell(struct List
* list
, void* content
)
50 cell
=(struct List
*)malloc(sizeof(struct List
));
52 (*adfEnv
.eFct
)("newCell : malloc");
55 cell
->content
= content
;
56 cell
->next
= cell
->subdir
= 0;
68 void freeList(struct List
* list
)
84 * amiga disk date format (days) to normal dd/mm/yy format (out)
88 adfDays2Date(ULONG days
, int *yy
, int *mm
, int *dd
)
92 int jm
[12]={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
94 /* 0 = 1 Jan 1978, 6988 = 18 feb 1997 */
102 while( days
>= nd
) {
116 while( days
>= jm
[m
-1] ) {
130 * true if a year (y) is leap
136 return( (BOOL
) ( !(y
%100) ? !(y
%400) : !(y
%4) ) );
143 * return the current system date and time
146 adfGiveCurrentTime( void )
153 local
=localtime(&cal
);
155 r
.year
=local
->tm_year
; /* since 1900 */
156 r
.mon
=local
->tm_mon
+1;
157 r
.day
=local
->tm_mday
;
158 r
.hour
=local
->tm_hour
;
169 * converts date and time (dt) into Amiga format : day, min, ticks
172 adfTime2AmigaTime(struct DateTime dt
, ULONG
*day
, ULONG
*min
, ULONG
*ticks
)
174 int jm
[12]={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
177 *min
= dt
.hour
*60 + dt
.min
; /* mins */
178 *ticks
= dt
.sec
*50; /* ticks */
182 *day
= dt
.day
-1; /* current month days */
184 /* previous months days downto january */
185 if (dt
.mon
>1) { /* if previous month exists */
187 if (dt
.mon
>2 && adfIsLeap(dt
.year
)) /* months after a leap february */
190 *day
=*day
+jm
[dt
.mon
-1];
195 /* years days before current year downto 1978 */
199 if (adfIsLeap(dt
.year
))
213 * debug function : to dump a block before writing the check its contents
216 void dumpBlock(unsigned char *buf
)
220 for(i
=0; i
<32; i
++) {
222 for (j
=0; j
<4; j
++) {
223 printf("%08x ",Long(buf
+j
*4+i
*16));
227 if (buf
[i
*16+j
]<32 || buf
[i
*16+j
]>127)
230 putchar(buf
[i
*16+j
]);
237 /*################################################################################*/