1409 |
mateusz.vi |
1 |
/*
|
|
|
2 |
* Functions interacting with DOS
|
|
|
3 |
*
|
|
|
4 |
* This file is part of the Mateusz' DOS Routines (MDR): http://mdr.osdn.io
|
|
|
5 |
* Published under the terms of the MIT License, as stated below.
|
|
|
6 |
*
|
|
|
7 |
* Copyright (C) 2014-2023 Mateusz Viste
|
|
|
8 |
*
|
|
|
9 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
10 |
* of this software and associated documentation files (the "Software"), to
|
|
|
11 |
* deal in the Software without restriction, including without limitation the
|
|
|
12 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
13 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
14 |
* furnished to do so, subject to the following conditions:
|
|
|
15 |
*
|
|
|
16 |
* The above copyright notice and this permission notice shall be included in
|
|
|
17 |
* all copies or substantial portions of the Software.
|
|
|
18 |
*
|
|
|
19 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
20 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
21 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
22 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
23 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
24 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
25 |
* IN THE SOFTWARE.
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
#ifndef MDR_DOS_H
|
|
|
29 |
#define MDR_DOS_H
|
|
|
30 |
|
|
|
31 |
#include <time.h> /* time_t */
|
|
|
32 |
|
|
|
33 |
/* returns a far pointer to the current process PSP structure */
|
|
|
34 |
void far *mdr_dos_psp(void);
|
|
|
35 |
|
|
|
36 |
/* returns a far pointer to the environment block of the current process */
|
|
|
37 |
char far *mdr_dos_env(void);
|
|
|
38 |
|
|
|
39 |
/* looks for varname in the DOS environment and fills result with its value if
|
|
|
40 |
* found. returns NULL if not found or if value is too big to fit in result
|
|
|
41 |
* (reslimit exceeded). returns result on success.
|
|
|
42 |
* NOTE: this function performs case-sensitive matches */
|
|
|
43 |
char *mdr_dos_getenv(char *result, const char *varname, unsigned short reslimit);
|
|
|
44 |
|
|
|
45 |
/* fetches directory where the program was loaded from and return its length.
|
|
|
46 |
* path string is never longer than 128 (incl. the null terminator) and it is
|
|
|
47 |
* always terminated with a backslash separator, unless it is an empty string */
|
|
|
48 |
unsigned char mdr_dos_exepath(char *path);
|
|
|
49 |
|
|
|
50 |
/* returns a far pointer to the full path and filename of the running program.
|
|
|
51 |
* returns NULL on error. */
|
|
|
52 |
const char far *mdr_dos_selfexe(void);
|
|
|
53 |
|
|
|
54 |
/* waits for a keypress and returns it
|
|
|
55 |
* extended keys are returned ORed with 0x100 (example: PGUP is 0x149) */
|
|
|
56 |
int mdr_dos_getkey(void);
|
|
|
57 |
|
|
|
58 |
/* Same as mdr_dos_getkey(), but this call cannot be aborted by CTRL+C */
|
|
|
59 |
int mdr_dos_getkey2(void);
|
|
|
60 |
|
|
|
61 |
/* flush the keyboard buffer */
|
|
|
62 |
void mdr_dos_flushkeyb(void);
|
|
|
63 |
|
|
|
64 |
/* poll stdin status, returns 0 if no character is pending in the keyboard
|
|
|
65 |
* buffer, non-zero otherwise */
|
|
|
66 |
int mdr_dos_keypending(void);
|
|
|
67 |
|
1413 |
mateusz.vi |
68 |
/* sets up the CTRL+C handler for the running program to a no-op - in other
|
|
|
69 |
* words, after this call DOS will no longer abort the program on CTRL+C.
|
|
|
70 |
* this is only valid for the duration of the program because DOS will restore
|
|
|
71 |
* the original handler after the program exits.
|
|
|
72 |
*
|
|
|
73 |
* an alternative is mdr_dos_ctrlc_off(), but this does not inhibit the
|
|
|
74 |
* handler, it sets DOS to not react to CTRL+C in the first place, and this
|
|
|
75 |
* setting stays active after the program quits so the program should remember
|
|
|
76 |
* to restore the original setting before quitting. */
|
|
|
77 |
void mdr_dos_ctrlc_inhibit(void);
|
1409 |
mateusz.vi |
78 |
|
1413 |
mateusz.vi |
79 |
/* sets the DOS BREAK control OFF, ie. instructs DOS not to check for CTRL+C
|
|
|
80 |
* during most input operations. returns the previous state of the break
|
|
|
81 |
* control flag (0=disabled 1=enabled). this changes a global DOS flag that can
|
|
|
82 |
* be checked on command line with the "BREAK" command, so the program should
|
|
|
83 |
* take care to restore the initial setting before quitting. */
|
|
|
84 |
unsigned char mdr_dos_ctrlc_disable(void);
|
|
|
85 |
|
|
|
86 |
/* sets the DOS BREAK control ON. see mdr_dos_ctrlc_disable() for details. */
|
|
|
87 |
void mdr_dos_ctrlc_enable(void);
|
|
|
88 |
|
1409 |
mateusz.vi |
89 |
/* converts a "DOS format" 16-bit packed date into a standard (time_t)
|
|
|
90 |
* unix timestamp. A DOS date is a 16-bit value:
|
|
|
91 |
* YYYYYYYM MMMDDDDD
|
|
|
92 |
*
|
|
|
93 |
* day of month is always within 1-31 range;
|
|
|
94 |
* month is always within 1-12 range;
|
|
|
95 |
* year starts at 1980 and continues for 127 years */
|
|
|
96 |
time_t mdr_dos_date2unix(unsigned short d);
|
|
|
97 |
|
|
|
98 |
/* converts a "DOS format" 16-bit packed time into hours, minutes and seconds
|
|
|
99 |
*
|
|
|
100 |
* A DOS time is a 16-bit value:
|
|
|
101 |
* HHHHHMMM MMMSSSSS
|
|
|
102 |
*
|
|
|
103 |
* HHHHH = hours, always within 0-23 range
|
|
|
104 |
* MMMMMM = minutes, always within 0-59 range
|
|
|
105 |
* SSSSS = seconds/2 (always within 0-29 range) */
|
|
|
106 |
void mdr_dos_time2hms(unsigned char *h, unsigned char *m, unsigned char *s, unsigned short t);
|
|
|
107 |
|
1443 |
mateusz.vi |
108 |
/* Determine the canonical name of the specified filename or path and writes
|
|
|
109 |
* the result into result. The input path does not need to actually exist.
|
|
|
110 |
* result is zeroed to an empty string on error. */
|
|
|
111 |
void mdr_dos_truename(char *result, const char *name);
|
|
|
112 |
|
1409 |
mateusz.vi |
113 |
#endif
|