Subversion Repositories SvarDOS

Rev

Rev 420 | Rev 423 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 420 Rev 421
-
 
1
/* This file is part of the SvarCOM project and is published under the terms
-
 
2
 * of the MIT license.
-
 
3
 *
-
 
4
 * Copyright (C) 2021 Mateusz Viste
-
 
5
 *
-
 
6
 * Permission is hereby granted, free of charge, to any person obtaining a
-
 
7
 * copy of this software and associated documentation files (the "Software"),
-
 
8
 * to deal in the Software without restriction, including without limitation
-
 
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
-
 
10
 * and/or sell copies of the Software, and to permit persons to whom the
-
 
11
 * Software is furnished to do so, subject to the following conditions:
-
 
12
 *
-
 
13
 * The above copyright notice and this permission notice shall be included in
-
 
14
 * all copies or substantial portions of the Software.
-
 
15
 *
-
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-
 
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-
 
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-
 
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-
 
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-
 
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-
 
22
 * DEALINGS IN THE SOFTWARE.
-
 
23
 */
-
 
24
 
1
#ifndef HELPERS_H
25
#ifndef HELPERS_H
2
#define HELPERS_H
26
#define HELPERS_H
3
 
27
 
4
/* case-insensitive comparison of strings, returns non-zero on equality */
28
/* case-insensitive comparison of strings, returns non-zero on equality */
5
int imatch(const char *s1, const char *s2);
29
int imatch(const char *s1, const char *s2);
6
 
30
 
7
/* returns zero if s1 starts with s2 */
31
/* returns zero if s1 starts with s2 */
8
int strstartswith(const char *s1, const char *s2);
32
int strstartswith(const char *s1, const char *s2);
9
 
33
 
10
/* outputs a NULL-terminated string to stdout */
34
/* outputs a NULL-terminated string to stdout */
11
void output_internal(const char *s, unsigned short nl);
35
void output_internal(const char *s, unsigned short nl);
12
 
36
 
13
#define output(x) output_internal(x, 0)
37
#define output(x) output_internal(x, 0)
14
#define outputnl(x) output_internal(x, 1)
38
#define outputnl(x) output_internal(x, 1)
15
 
39
 
16
/*
40
/*
17
 * FileInfoRec (DTA) format:
41
 * FileInfoRec (DTA) format:
18
 * offset size desc
42
 * offset size desc
19
 *    +0   21  reserved
43
 *    +0   21  reserved
20
 *  +15h    1  file attr (1=RO 2=Hidden 4=System 8=VOL 16=DIR 32=Archive
44
 *  +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)
45
 *  +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
46
 *  +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
47
 *  +1ah    4  DWORD file size, in bytes
24
 *  +1eh   13  13-bytes max ASCIIZ filename
48
 *  +1eh   13  13-bytes max ASCIIZ filename
25
 */
49
 */
26
_Packed struct DTA {
50
_Packed struct DTA {
27
  char reserved[21];
51
  char reserved[21];
28
  unsigned char attr;
52
  unsigned char attr;
29
  unsigned short time_sec2:5;
53
  unsigned short time_sec2:5;
30
  unsigned short time_min:6;
54
  unsigned short time_min:6;
31
  unsigned short time_hour:5;
55
  unsigned short time_hour:5;
32
  unsigned short date_dy:5;
56
  unsigned short date_dy:5;
33
  unsigned short date_mo:4;
57
  unsigned short date_mo:4;
34
  unsigned short date_yr:7;
58
  unsigned short date_yr:7;
35
  unsigned long size;
59
  unsigned long size;
36
  char fname[13];
60
  char fname[13];
37
};
61
};
38
 
62
 
39
 
63
 
40
/* this is also known as the "Country Info Block" or "CountryInfoRec":
64
/* this is also known as the "Country Info Block" or "CountryInfoRec":
41
 * offset size desc
65
 * offset size desc
42
 *   +0      2   wDateFormat  0=USA (m d y), 1=Europe (d m y), 2=Japan (y m d)
66
 *   +0      2   wDateFormat  0=USA (m d y), 1=Europe (d m y), 2=Japan (y m d)
43
 *   +2      5  szCrncySymb  currency symbol (ASCIIZ)
67
 *   +2      5  szCrncySymb  currency symbol (ASCIIZ)
44
 *   +7      2  szThouSep    thousands separator (ASCIIZ)
68
 *   +7      2  szThouSep    thousands separator (ASCIIZ)
45
 *   +9      2  szDecSep     decimal separator (ASCIIZ)
69
 *   +9      2  szDecSep     decimal separator (ASCIIZ)
46
 * +0bH      2  szDateSep    date separator (ASCIIZ)
70
 * +0bH      2  szDateSep    date separator (ASCIIZ)
47
 * +0dH      2  szTimeSep    time separator (ASCIIZ)
71
 * +0dH      2  szTimeSep    time separator (ASCIIZ)
48
 * +0fH      1  bCrncyFlags  currency format flags
72
 * +0fH      1  bCrncyFlags  currency format flags
49
 * +10H      1  bCrncyDigits decimals digits in currency
73
 * +10H      1  bCrncyDigits decimals digits in currency
50
 * +11H      1  bTimeFormat  time format 0=12h 1=24h
74
 * +11H      1  bTimeFormat  time format 0=12h 1=24h
51
 * +12H      4  pfCasemap    Casemap FAR call address
75
 * +12H      4  pfCasemap    Casemap FAR call address
52
 * +16H      2  szDataSep    data list separator (ASCIIZ)
76
 * +16H      2  szDataSep    data list separator (ASCIIZ)
53
 * +18H     10  res          reserved zeros
77
 * +18H     10  res          reserved zeros
54
 *          34               total length
78
 *          34               total length
55
 */
79
 */
56
_Packed struct nls_patterns {
80
_Packed struct nls_patterns {
57
  unsigned short dateformat;
81
  unsigned short dateformat;
58
  char currency[5];
82
  char currency[5];
59
  char thousep[2];
83
  char thousep[2];
60
  char decsep[2];
84
  char decsep[2];
61
  char datesep[2];
85
  char datesep[2];
62
  char timesep[2];
86
  char timesep[2];
63
  unsigned char currflags;
87
  unsigned char currflags;
64
  unsigned char currdigits;
88
  unsigned char currdigits;
65
  unsigned char timefmt;
89
  unsigned char timefmt;
66
  void far *casemapfn;
90
  void far *casemapfn;
67
  char datalistsep[2];
91
  char datalistsep[2];
68
  char reserved[10];
92
  char reserved[10];
69
};
93
};
70
 
94
 
71
 
95
 
72
#define DOS_ATTR_RO   1
96
#define DOS_ATTR_RO   1
73
#define DOS_ATTR_HID  2
97
#define DOS_ATTR_HID  2
74
#define DOS_ATTR_SYS  4
98
#define DOS_ATTR_SYS  4
75
#define DOS_ATTR_VOL  8
99
#define DOS_ATTR_VOL  8
76
#define DOS_ATTR_DIR 16
100
#define DOS_ATTR_DIR 16
77
#define DOS_ATTR_ARC 32
101
#define DOS_ATTR_ARC 32
78
 
102
 
79
/* find first matching files using a FindFirst DOS call
103
/* find first matching files using a FindFirst DOS call
80
 * attr contains DOS attributes that files MUST have (ie attr=0 will match all
104
 * attr contains DOS attributes that files MUST have (ie attr=0 will match all
81
 * files)
105
 * files)
82
 * returns 0 on success or a DOS err code on failure */
106
 * returns 0 on success or a DOS err code on failure */
83
unsigned short findfirst(struct DTA *dta, const char *pattern, unsigned short attr);
107
unsigned short findfirst(struct DTA *dta, const char *pattern, unsigned short attr);
84
 
108
 
85
/* find next matching, ie. continues an action intiated by findfirst() */
109
/* find next matching, ie. continues an action intiated by findfirst() */
86
unsigned short findnext(struct DTA *dta);
110
unsigned short findnext(struct DTA *dta);
87
 
111
 
88
/* print s string and wait for a single key press from stdin. accepts only
112
/* print s string and wait for a single key press from stdin. accepts only
89
 * key presses defined in the c ASCIIZ string. returns offset of pressed key
113
 * key presses defined in the c ASCIIZ string. returns offset of pressed key
90
 * in string. keys in c MUST BE UPPERCASE! */
114
 * in string. keys in c MUST BE UPPERCASE! */
91
unsigned short askchoice(const char *s, const char *c);
115
unsigned short askchoice(const char *s, const char *c);
92
 
116
 
93
/* converts a path to its canonic representation, returns 0 on success
117
/* converts a path to its canonic representation, returns 0 on success
94
 * or DOS err on failure (invalid drive) */
118
 * or DOS err on failure (invalid drive) */
95
unsigned short file_truename(const char *src, char *dst);
119
unsigned short file_truename(const char *src, char *dst);
96
 
120
 
97
/* returns DOS attributes of file, or -1 on error */
121
/* returns DOS attributes of file, or -1 on error */
98
int file_getattr(const char *fname);
122
int file_getattr(const char *fname);
99
 
123
 
100
/* returns screen's width (in columns) */
124
/* returns screen's width (in columns) */
101
unsigned short screen_getwidth(void);
125
unsigned short screen_getwidth(void);
102
 
126
 
103
/* returns screen's height (in rows) */
127
/* returns screen's height (in rows) */
104
unsigned short screen_getheight(void);
128
unsigned short screen_getheight(void);
105
 
129
 
106
/* displays the "Press any key to continue" msg and waits for a keypress */
130
/* displays the "Press any key to continue" msg and waits for a keypress */
107
void press_any_key(void);
131
void press_any_key(void);
108
 
132
 
109
/* validate a drive (A=0, B=1, etc). returns 1 if valid, 0 otherwise */
133
/* validate a drive (A=0, B=1, etc). returns 1 if valid, 0 otherwise */
110
int isdrivevalid(unsigned char drv);
134
int isdrivevalid(unsigned char drv);
111
 
135
 
112
/* converts a filename into FCB format (FILENAMEEXT) */
136
/* converts a filename into FCB format (FILENAMEEXT) */
113
void file_fname2fcb(char *dst, const char *src);
137
void file_fname2fcb(char *dst, const char *src);
114
 
138
 
115
/* converts a FCB filename (FILENAMEEXT) into normal format (FILENAME.EXT) */
139
/* converts a FCB filename (FILENAMEEXT) into normal format (FILENAME.EXT) */
116
void file_fcb2fname(char *dst, const char *src);
140
void file_fcb2fname(char *dst, const char *src);
117
 
141
 
118
/* converts an ASCIIZ string into an unsigned short. returns 0 on success. */
142
/* converts an ASCIIZ string into an unsigned short. returns 0 on success. */
119
int atouns(unsigned short *r, const char *s);
143
int atouns(unsigned short *r, const char *s);
120
 
144
 
121
/* appends a backslash if path is a directory
145
/* appends a backslash if path is a directory
122
 * returns the (possibly updated) length of path */
146
 * returns the (possibly updated) length of path */
123
unsigned short path_appendbkslash_if_dir(char *path);
147
unsigned short path_appendbkslash_if_dir(char *path);
124
 
148
 
125
/* get current path drive d (A=1, B=2, etc - 0 is "current drive")
149
/* get current path drive d (A=1, B=2, etc - 0 is "current drive")
126
 * returns 0 on success, doserr otherwise */
150
 * returns 0 on success, doserr otherwise */
127
unsigned short curpathfordrv(char *buff, unsigned char d);
151
unsigned short curpathfordrv(char *buff, unsigned char d);
128
 
152
 
129
/* fills a nls_patterns struct with current NLS patterns, returns 0 on success, DOS errcode otherwise */
153
/* fills a nls_patterns struct with current NLS patterns, returns 0 on success, DOS errcode otherwise */
130
unsigned short nls_getpatterns(struct nls_patterns *p);
154
unsigned short nls_getpatterns(struct nls_patterns *p);
131
 
155
 
132
/* computes a formatted date based on NLS patterns found in p
156
/* computes a formatted date based on NLS patterns found in p
133
 * returns length of result */
157
 * returns length of result */
134
unsigned short nls_format_date(char *s, unsigned short yr, unsigned char mo, unsigned char dy, const struct nls_patterns *p);
158
unsigned short nls_format_date(char *s, unsigned short yr, unsigned char mo, unsigned char dy, const struct nls_patterns *p);
135
 
159
 
136
/* computes a formatted time based on NLS patterns found in p
160
/* computes a formatted time based on NLS patterns found in p
137
 * returns length of result */
161
 * returns length of result */
138
unsigned short nls_format_time(char *s, unsigned char ho, unsigned char mn, const struct nls_patterns *p);
162
unsigned short nls_format_time(char *s, unsigned char ho, unsigned char mn, const struct nls_patterns *p);
139
 
163
 
140
/* computes a formatted integer number based on NLS patterns found in p
164
/* computes a formatted integer number based on NLS patterns found in p
141
 * returns length of result */
165
 * returns length of result */
142
unsigned short nls_format_number(char *s, long num, const struct nls_patterns *p);
166
unsigned short nls_format_number(char *s, long num, const struct nls_patterns *p);
143
 
167
 
144
#endif
168
#endif
145
 
169