352 |
mateuszvis |
1 |
#ifndef HELPERS_H
|
|
|
2 |
#define HELPERS_H
|
|
|
3 |
|
|
|
4 |
/* case-insensitive comparison of strings, returns non-zero on equality */
|
|
|
5 |
int imatch(const char *s1, const char *s2);
|
|
|
6 |
|
|
|
7 |
/* returns zero if s1 starts with s2 */
|
|
|
8 |
int strstartswith(const char *s1, const char *s2);
|
|
|
9 |
|
369 |
mateuszvis |
10 |
/* outputs a NULL-terminated string to stdout */
|
|
|
11 |
void output_internal(const char *s, unsigned short nl);
|
|
|
12 |
|
|
|
13 |
#define output(x) output_internal(x, 0)
|
|
|
14 |
#define outputnl(x) output_internal(x, 1)
|
|
|
15 |
|
388 |
mateuszvis |
16 |
/*
|
|
|
17 |
* FileInfoRec (DTA) format:
|
|
|
18 |
* offset size desc
|
|
|
19 |
* +0 21 reserved
|
|
|
20 |
* +15h 1 file attr (1=RO 2=Hidden 4=System 8=VOL 16=DIR 32=Archive
|
|
|
21 |
* +16h 2 time: bits 0-4=bi-seconds (0-30), bits 5-10=minutes (0-59), bits 11-15=hour (0-23)
|
|
|
22 |
* +18h 2 date: bits 0-4=day(0-31), bits 5-8=month (1-12), bits 9-15=years since 1980
|
|
|
23 |
* +1ah 4 DWORD file size, in bytes
|
|
|
24 |
* +1eh 13 13-bytes max ASCIIZ filename
|
|
|
25 |
*/
|
|
|
26 |
_Packed struct DTA {
|
|
|
27 |
char reserved[21];
|
|
|
28 |
unsigned char attr;
|
|
|
29 |
unsigned short time;
|
|
|
30 |
unsigned short date;
|
|
|
31 |
unsigned long size;
|
|
|
32 |
char fname[13];
|
|
|
33 |
};
|
|
|
34 |
|
389 |
mateuszvis |
35 |
#define DOS_ATTR_RO 1
|
|
|
36 |
#define DOS_ATTR_HID 2
|
|
|
37 |
#define DOS_ATTR_SYS 4
|
|
|
38 |
#define DOS_ATTR_VOL 8
|
|
|
39 |
#define DOS_ATTR_DIR 16
|
|
|
40 |
#define DOS_ATTR_ARC 32
|
|
|
41 |
|
388 |
mateuszvis |
42 |
/* find first matching files using a FindFirst DOS call
|
406 |
mateuszvis |
43 |
* attr contains DOS attributes that files MUST have (ie attr=0 will match all
|
|
|
44 |
* files)
|
388 |
mateuszvis |
45 |
* returns 0 on success or a DOS err code on failure */
|
|
|
46 |
unsigned short findfirst(struct DTA *dta, const char *pattern, unsigned short attr);
|
|
|
47 |
|
|
|
48 |
/* find next matching, ie. continues an action intiated by findfirst() */
|
|
|
49 |
unsigned short findnext(struct DTA *dta);
|
|
|
50 |
|
392 |
mateuszvis |
51 |
/* print s string and wait for a single key press from stdin. accepts only
|
|
|
52 |
* key presses defined in the c ASCIIZ string. returns offset of pressed key
|
|
|
53 |
* in string. keys in c MUST BE UPPERCASE! */
|
|
|
54 |
unsigned short askchoice(const char *s, const char *c);
|
|
|
55 |
|
399 |
mateuszvis |
56 |
/* converts a path to its canonic representation, returns 0 on success
|
|
|
57 |
* or DOS err on failure (invalid drive) */
|
|
|
58 |
unsigned short file_truename(const char *src, char *dst);
|
392 |
mateuszvis |
59 |
|
|
|
60 |
/* returns DOS attributes of file, or -1 on error */
|
|
|
61 |
int file_getattr(const char *fname);
|
|
|
62 |
|
396 |
mateuszvis |
63 |
/* returns screen's width (in columns) */
|
|
|
64 |
unsigned short screen_getwidth(void);
|
|
|
65 |
|
|
|
66 |
/* returns screen's height (in rows) */
|
|
|
67 |
unsigned short screen_getheight(void);
|
|
|
68 |
|
|
|
69 |
/* displays the "Press any key to continue" msg and waits for a keypress */
|
|
|
70 |
void press_any_key(void);
|
|
|
71 |
|
399 |
mateuszvis |
72 |
/* validate a drive (A=0, B=1, etc). returns 1 if valid, 0 otherwise */
|
|
|
73 |
int isdrivevalid(unsigned char drv);
|
|
|
74 |
|
406 |
mateuszvis |
75 |
/* converts a filename into FCB format (FILENAMEEXT) */
|
|
|
76 |
void file_fname2fcb(char *dst, const char *src);
|
|
|
77 |
|
|
|
78 |
/* converts a FCB filename (FILENAMEEXT) into normal format (FILENAME.EXT) */
|
|
|
79 |
void file_fcb2fname(char *dst, const char *src);
|
|
|
80 |
|
410 |
mateuszvis |
81 |
/* converts an ASCIIZ string into an unsigned short. returns 0 on success. */
|
|
|
82 |
int atouns(unsigned short *r, const char *s);
|
|
|
83 |
|
415 |
mateuszvis |
84 |
/* appends a backslash if path is a directory
|
|
|
85 |
* returns the (possibly updated) length of path */
|
|
|
86 |
unsigned short path_appendbkslash_if_dir(char *path);
|
|
|
87 |
|
352 |
mateuszvis |
88 |
#endif
|