Subversion Repositories SvarDOS

Rev

Rev 1719 | Details | Compare with Previous | Last modification | View Log | RSS feed

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