2 * ADF Library. (C) 1997-1999 Laurent Clevy
15 extern struct Env adfEnv
;
21 * write an unsigned long value (val) (in)
22 * to an unsigned char* buffer (buf) (out)
24 * used in adfWrite----Block() functions
26 void swLong(unsigned char* buf
, unsigned long val
)
28 buf
[0]= (unsigned char)((val
& 0xff000000) >>24UL);
29 buf
[1]= (unsigned char)((val
& 0x00ff0000) >>16UL);
30 buf
[2]= (unsigned char)((val
& 0x0000ff00) >>8UL);
31 buf
[3]= (unsigned char)(val
& 0x000000ff);
34 void swShort(unsigned char* buf
, unsigned short val
)
36 buf
[0]= (val
& 0xff00) >>8UL;
37 buf
[1]= (val
& 0x00ff) ;
43 * adds a cell at the end the list
45 struct List
* newCell(struct List
* list
, void* content
)
49 cell
=(struct List
*)malloc(sizeof(struct List
));
51 (*adfEnv
.eFct
)("newCell : malloc");
54 cell
->content
= content
;
55 cell
->next
= cell
->subdir
= 0;
67 void freeList(struct List
* list
)
83 * amiga disk date format (days) to normal dd/mm/yy format (out)
87 adfDays2Date(long days
, int *yy
, int *mm
, int *dd
)
91 int jm
[12]={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
93 /* 0 = 1 Jan 1978, 6988 = 18 feb 1997 */
101 while( days
>= nd
) {
115 while( days
>= jm
[m
-1] ) {
129 * true if a year (y) is leap
135 return( (BOOL
) ( !(y
%100) ? !(y
%400) : !(y
%4) ) );
142 * return the current system date and time
145 adfGiveCurrentTime( void )
152 local
=localtime(&cal
);
154 r
.year
=local
->tm_year
; /* since 1900 */
155 r
.mon
=local
->tm_mon
+1;
156 r
.day
=local
->tm_mday
;
157 r
.hour
=local
->tm_hour
;
168 * converts date and time (dt) into Amiga format : day, min, ticks
171 adfTime2AmigaTime(struct DateTime dt
, long *day
, long *min
, long *ticks
)
173 int jm
[12]={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
176 *min
= dt
.hour
*60 + dt
.min
; /* mins */
177 *ticks
= dt
.sec
*50; /* ticks */
181 *day
= dt
.day
-1; /* current month days */
183 /* previous months days downto january */
184 if (dt
.mon
>1) { /* if previous month exists */
186 if (dt
.mon
>2 && adfIsLeap(dt
.year
)) /* months after a leap february */
189 *day
=*day
+jm
[dt
.mon
-1];
194 /* years days before current year downto 1978 */
198 if (adfIsLeap(dt
.year
))
212 * debug function : to dump a block before writing the check its contents
215 void dumpBlock(unsigned char *buf
)
219 for(i
=0; i
<32; i
++) {
221 for (j
=0; j
<4; j
++) {
222 printf("%08x ",Long(buf
+j
*4+i
*16));
226 if (buf
[i
*16+j
]<32 || buf
[i
*16+j
]>127)
229 putchar(buf
[i
*16+j
]);
236 /*################################################################################*/