Subversion Repositories SvarDOS

Rev

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