Subversion Repositories SvarDOS

Rev

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

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