Subversion Repositories SvarDOS

Rev

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

Rev 530 Rev 538
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 stdout */
37
/* outputs a NULL-terminated string to handle (hSTDOUT or hSTDERR) */
38
void output_internal(const char *s, unsigned char nl);
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);
41
void nls_output_internal(unsigned short id, unsigned char nl);
42
 
42
 
-
 
43
#define hSTDOUT 1
-
 
44
#define hSTDERR 2
-
 
45
 
43
#define output(x) output_internal(x, 0)
46
#define output(x) output_internal(x, 0, hSTDOUT)
44
#define outputnl(x) output_internal(x, 1)
47
#define outputnl(x) output_internal(x, 1, hSTDOUT)
45
#define nls_output(x,y) nls_output_internal((x << 8) | y, 0)
48
#define nls_output(x,y) nls_output_internal((x << 8) | y, 0)
46
#define nls_outputnl(x,y) nls_output_internal((x << 8) | y, 1)
49
#define nls_outputnl(x,y) nls_output_internal((x << 8) | y, 1)
47
 
50
 
-
 
51
/* output DOS error e to stderr */
-
 
52
void nls_outputnl_doserr(unsigned short e);
-
 
53
 
48
/*
54
/*
49
 * FileInfoRec (DTA) format:
55
 * FileInfoRec (DTA) format:
50
 * offset size desc
56
 * offset size desc
51
 *    +0   21  reserved
57
 *    +0   21  reserved
52
 *  +15h    1  file attr (1=RO 2=Hidden 4=System 8=VOL 16=DIR 32=Archive
58
 *  +15h    1  file attr (1=RO 2=Hidden 4=System 8=VOL 16=DIR 32=Archive
53
 *  +16h    2  time: bits 0-4=bi-seconds (0-30), bits 5-10=minutes (0-59), bits 11-15=hour (0-23)
59
 *  +16h    2  time: bits 0-4=bi-seconds (0-30), bits 5-10=minutes (0-59), bits 11-15=hour (0-23)
54
 *  +18h    2  date: bits 0-4=day(0-31), bits 5-8=month (1-12), bits 9-15=years since 1980
60
 *  +18h    2  date: bits 0-4=day(0-31), bits 5-8=month (1-12), bits 9-15=years since 1980
55
 *  +1ah    4  DWORD file size, in bytes
61
 *  +1ah    4  DWORD file size, in bytes
56
 *  +1eh   13  13-bytes max ASCIIZ filename
62
 *  +1eh   13  13-bytes max ASCIIZ filename
57
 */
63
 */
58
_Packed struct DTA {
64
_Packed struct DTA {
59
  char reserved[21];
65
  char reserved[21];
60
  unsigned char attr;
66
  unsigned char attr;
61
  unsigned short time_sec2:5;
67
  unsigned short time_sec2:5;
62
  unsigned short time_min:6;
68
  unsigned short time_min:6;
63
  unsigned short time_hour:5;
69
  unsigned short time_hour:5;
64
  unsigned short date_dy:5;
70
  unsigned short date_dy:5;
65
  unsigned short date_mo:4;
71
  unsigned short date_mo:4;
66
  unsigned short date_yr:7;
72
  unsigned short date_yr:7;
67
  unsigned long size;
73
  unsigned long size;
68
  char fname[13];
74
  char fname[13];
69
};
75
};
70
 
76
 
71
 
77
 
72
/* this is also known as the "Country Info Block" or "CountryInfoRec":
78
/* this is also known as the "Country Info Block" or "CountryInfoRec":
73
 * offset size desc
79
 * offset size desc
74
 *   +0      2   wDateFormat  0=USA (m d y), 1=Europe (d m y), 2=Japan (y m d)
80
 *   +0      2   wDateFormat  0=USA (m d y), 1=Europe (d m y), 2=Japan (y m d)
75
 *   +2      5  szCrncySymb  currency symbol (ASCIIZ)
81
 *   +2      5  szCrncySymb  currency symbol (ASCIIZ)
76
 *   +7      2  szThouSep    thousands separator (ASCIIZ)
82
 *   +7      2  szThouSep    thousands separator (ASCIIZ)
77
 *   +9      2  szDecSep     decimal separator (ASCIIZ)
83
 *   +9      2  szDecSep     decimal separator (ASCIIZ)
78
 * +0bH      2  szDateSep    date separator (ASCIIZ)
84
 * +0bH      2  szDateSep    date separator (ASCIIZ)
79
 * +0dH      2  szTimeSep    time separator (ASCIIZ)
85
 * +0dH      2  szTimeSep    time separator (ASCIIZ)
80
 * +0fH      1  bCrncyFlags  currency format flags
86
 * +0fH      1  bCrncyFlags  currency format flags
81
 * +10H      1  bCrncyDigits decimals digits in currency
87
 * +10H      1  bCrncyDigits decimals digits in currency
82
 * +11H      1  bTimeFormat  time format 0=12h 1=24h
88
 * +11H      1  bTimeFormat  time format 0=12h 1=24h
83
 * +12H      4  pfCasemap    Casemap FAR call address
89
 * +12H      4  pfCasemap    Casemap FAR call address
84
 * +16H      2  szDataSep    data list separator (ASCIIZ)
90
 * +16H      2  szDataSep    data list separator (ASCIIZ)
85
 * +18H     10  res          reserved zeros
91
 * +18H     10  res          reserved zeros
86
 *          34               total length
92
 *          34               total length
87
 */
93
 */
88
_Packed struct nls_patterns {
94
_Packed struct nls_patterns {
89
  unsigned short dateformat;
95
  unsigned short dateformat;
90
  char currency[5];
96
  char currency[5];
91
  char thousep[2];
97
  char thousep[2];
92
  char decsep[2];
98
  char decsep[2];
93
  char datesep[2];
99
  char datesep[2];
94
  char timesep[2];
100
  char timesep[2];
95
  unsigned char currflags;
101
  unsigned char currflags;
96
  unsigned char currdigits;
102
  unsigned char currdigits;
97
  unsigned char timefmt;
103
  unsigned char timefmt;
98
  void far *casemapfn;
104
  void far *casemapfn;
99
  char datalistsep[2];
105
  char datalistsep[2];
100
  char reserved[10];
106
  char reserved[10];
101
};
107
};
102
 
108
 
103
 
109
 
104
#define DOS_ATTR_RO   1
110
#define DOS_ATTR_RO   1
105
#define DOS_ATTR_HID  2
111
#define DOS_ATTR_HID  2
106
#define DOS_ATTR_SYS  4
112
#define DOS_ATTR_SYS  4
107
#define DOS_ATTR_VOL  8
113
#define DOS_ATTR_VOL  8
108
#define DOS_ATTR_DIR 16
114
#define DOS_ATTR_DIR 16
109
#define DOS_ATTR_ARC 32
115
#define DOS_ATTR_ARC 32
110
 
116
 
111
/* find first matching files using a FindFirst DOS call
117
/* find first matching files using a FindFirst DOS call
112
 * attr contains DOS attributes that files MUST have (ie attr=0 will match all
118
 * attr contains DOS attributes that files MUST have (ie attr=0 will match all
113
 * files)
119
 * files)
114
 * returns 0 on success or a DOS err code on failure */
120
 * returns 0 on success or a DOS err code on failure */
115
unsigned short findfirst(struct DTA *dta, const char *pattern, unsigned short attr);
121
unsigned short findfirst(struct DTA *dta, const char *pattern, unsigned short attr);
116
 
122
 
117
/* find next matching, ie. continues an action intiated by findfirst() */
123
/* find next matching, ie. continues an action intiated by findfirst() */
118
unsigned short findnext(struct DTA *dta);
124
unsigned short findnext(struct DTA *dta);
119
 
125
 
120
/* print s string and wait for a single key press from stdin. accepts only
126
/* print s string and wait for a single key press from stdin. accepts only
121
 * key presses defined in the c ASCIIZ string. returns offset of pressed key
127
 * key presses defined in the c ASCIIZ string. returns offset of pressed key
122
 * in string. keys in c MUST BE UPPERCASE! */
128
 * in string. keys in c MUST BE UPPERCASE! */
123
unsigned short askchoice(const char *s, const char *c);
129
unsigned short askchoice(const char *s, const char *c);
124
 
130
 
125
/* converts a path to its canonic representation, returns 0 on success
131
/* converts a path to its canonic representation, returns 0 on success
126
 * or DOS err on failure (invalid drive) */
132
 * or DOS err on failure (invalid drive) */
127
unsigned short file_truename(const char *src, char *dst);
133
unsigned short file_truename(const char *src, char *dst);
128
 
134
 
129
/* returns DOS attributes of file, or -1 on error */
135
/* returns DOS attributes of file, or -1 on error */
130
int file_getattr(const char *fname);
136
int file_getattr(const char *fname);
131
 
137
 
132
/* returns screen's width (in columns) */
138
/* returns screen's width (in columns) */
133
unsigned short screen_getwidth(void);
139
unsigned short screen_getwidth(void);
134
 
140
 
135
/* returns screen's height (in rows) */
141
/* returns screen's height (in rows) */
136
unsigned short screen_getheight(void);
142
unsigned short screen_getheight(void);
137
 
143
 
138
/* displays the "Press any key to continue" msg and waits for a keypress */
144
/* displays the "Press any key to continue" msg and waits for a keypress */
139
void press_any_key(void);
145
void press_any_key(void);
140
 
146
 
141
/* validate a drive (A=0, B=1, etc). returns 1 if valid, 0 otherwise */
147
/* validate a drive (A=0, B=1, etc). returns 1 if valid, 0 otherwise */
142
int isdrivevalid(unsigned char drv);
148
int isdrivevalid(unsigned char drv);
143
 
149
 
144
/* converts a filename into FCB format (FILENAMEEXT) */
150
/* converts a filename into FCB format (FILENAMEEXT) */
145
void file_fname2fcb(char *dst, const char *src);
151
void file_fname2fcb(char *dst, const char *src);
146
 
152
 
147
/* converts a FCB filename (FILENAMEEXT) into normal format (FILENAME.EXT) */
153
/* converts a FCB filename (FILENAMEEXT) into normal format (FILENAME.EXT) */
148
void file_fcb2fname(char *dst, const char *src);
154
void file_fcb2fname(char *dst, const char *src);
149
 
155
 
150
/* converts an ASCIIZ string into an unsigned short. returns 0 on success.
156
/* converts an ASCIIZ string into an unsigned short. returns 0 on success.
151
 * on error, result will contain all valid digits that were read until
157
 * on error, result will contain all valid digits that were read until
152
 * error occurred (0 on overflow or if parsing failed immediately) */
158
 * error occurred (0 on overflow or if parsing failed immediately) */
153
int atous(unsigned short *r, const char *s);
159
int atous(unsigned short *r, const char *s);
154
 
160
 
155
/* appends a backslash if path is a directory
161
/* appends a backslash if path is a directory
156
 * returns the (possibly updated) length of path */
162
 * returns the (possibly updated) length of path */
157
unsigned short path_appendbkslash_if_dir(char *path);
163
unsigned short path_appendbkslash_if_dir(char *path);
158
 
164
 
159
/* get current path drive d (A=1, B=2, etc - 0 is "current drive")
165
/* get current path drive d (A=1, B=2, etc - 0 is "current drive")
160
 * returns 0 on success, doserr otherwise */
166
 * returns 0 on success, doserr otherwise */
161
unsigned short curpathfordrv(char *buff, unsigned char d);
167
unsigned short curpathfordrv(char *buff, unsigned char d);
162
 
168
 
163
/* fills a nls_patterns struct with current NLS patterns, returns 0 on success, DOS errcode otherwise */
169
/* fills a nls_patterns struct with current NLS patterns, returns 0 on success, DOS errcode otherwise */
164
unsigned short nls_getpatterns(struct nls_patterns *p);
170
unsigned short nls_getpatterns(struct nls_patterns *p);
165
 
171
 
166
/* computes a formatted date based on NLS patterns found in p
172
/* computes a formatted date based on NLS patterns found in p
167
 * returns length of result */
173
 * returns length of result */
168
unsigned short nls_format_date(char *s, unsigned short yr, unsigned char mo, unsigned char dy, const struct nls_patterns *p);
174
unsigned short nls_format_date(char *s, unsigned short yr, unsigned char mo, unsigned char dy, const struct nls_patterns *p);
169
 
175
 
170
/* computes a formatted time based on NLS patterns found in p, sc are ignored if set 0xff
176
/* computes a formatted time based on NLS patterns found in p, sc are ignored if set 0xff
171
 * returns length of result */
177
 * returns length of result */
172
unsigned short nls_format_time(char *s, unsigned char ho, unsigned char mn, unsigned char sc, const struct nls_patterns *p);
178
unsigned short nls_format_time(char *s, unsigned char ho, unsigned char mn, unsigned char sc, const struct nls_patterns *p);
173
 
179
 
174
/* computes a formatted integer number based on NLS patterns found in p
180
/* computes a formatted integer number based on NLS patterns found in p
175
 * returns length of result */
181
 * returns length of result */
176
unsigned short nls_format_number(char *s, unsigned long num, const struct nls_patterns *p);
182
unsigned short nls_format_number(char *s, unsigned long num, const struct nls_patterns *p);
177
 
183
 
178
/* reload nls ressources from svarcom.lng into langblock */
184
/* reload nls ressources from svarcom.lng into langblock */
179
void nls_langreload(char *buff, unsigned short env);
185
void nls_langreload(char *buff, unsigned short env);
180
 
186
 
181
#endif
187
#endif
182
 
188