1 | /**
|
---|
2 | * @file ntstdio.h
|
---|
3 | * @author CuBeatSystems
|
---|
4 | * @author Shinichiro Nakamura
|
---|
5 | * @copyright
|
---|
6 | * ===============================================================
|
---|
7 | * Natural Tiny Shell (NT-Shell) Version 0.3.1
|
---|
8 | * ===============================================================
|
---|
9 | * Copyright (c) 2010-2016 Shinichiro Nakamura
|
---|
10 | *
|
---|
11 | * Permission is hereby granted, free of charge, to any person
|
---|
12 | * obtaining a copy of this software and associated documentation
|
---|
13 | * files (the "Software"), to deal in the Software without
|
---|
14 | * restriction, including without limitation the rights to use,
|
---|
15 | * copy, modify, merge, publish, distribute, sublicense, and/or
|
---|
16 | * sell copies of the Software, and to permit persons to whom the
|
---|
17 | * Software is furnished to do so, subject to the following
|
---|
18 | * conditions:
|
---|
19 | *
|
---|
20 | * The above copyright notice and this permission notice shall be
|
---|
21 | * included in all copies or substantial portions of the Software.
|
---|
22 | *
|
---|
23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
25 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
27 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
28 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
29 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
30 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
31 | */
|
---|
32 |
|
---|
33 | /*------------------------------------------------------------------------/
|
---|
34 | / Universal string handler for user console interface
|
---|
35 | /-------------------------------------------------------------------------/
|
---|
36 | /
|
---|
37 | / Copyright (C) 2011, ChaN, all right reserved.
|
---|
38 | /
|
---|
39 | / * This software is a free software and there is NO WARRANTY.
|
---|
40 | / * No restriction on use. You can use, modify and redistribute it for
|
---|
41 | / personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
|
---|
42 | / * Redistributions of source code must retain the above copyright notice.
|
---|
43 | /
|
---|
44 | /-------------------------------------------------------------------------*/
|
---|
45 |
|
---|
46 | #ifndef NTSTDIO_H
|
---|
47 | #define NTSTDIO_H
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * 1: Convert \n ==> \r\n in the output char.
|
---|
51 | */
|
---|
52 | #define NTSTDIO_OPTION_LF_CRLF (1 << 0)
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * 1: Echo back input chars in ntstdio_gets function.
|
---|
56 | */
|
---|
57 | #define NTSTDIO_OPTION_LINE_ECHO (1 << 1)
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * 1: canonical mode.
|
---|
61 | */
|
---|
62 | #define NTSTDIO_OPTION_CANON (1 << 2)
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * 1: Convert \r ==> \n in ntstdio_getc function.
|
---|
66 | */
|
---|
67 | #define NTSTDIO_OPTION_LF_CR (1 << 3)
|
---|
68 |
|
---|
69 | struct ntstdio_t;
|
---|
70 | typedef unsigned char (*NTSTDIO_XI)(struct ntstdio_t *handle);
|
---|
71 | typedef void (*NTSTDIO_XO)(struct ntstdio_t *handle, unsigned char c);
|
---|
72 |
|
---|
73 | typedef struct ntstdio_t {
|
---|
74 | NTSTDIO_XI xi;
|
---|
75 | NTSTDIO_XO xo;
|
---|
76 | int pos;
|
---|
77 | unsigned int option;
|
---|
78 | void *exinf;
|
---|
79 | } ntstdio_t;
|
---|
80 |
|
---|
81 | void ntstdio_init(ntstdio_t *handle, unsigned int option, NTSTDIO_XI xi, NTSTDIO_XO xo);
|
---|
82 |
|
---|
83 | void ntstdio_putc(ntstdio_t *handle, char c);
|
---|
84 | void ntstdio_puts(ntstdio_t *handle, const char *str);
|
---|
85 | void ntstdio_fputs(ntstdio_t *handle, NTSTDIO_XO xo, const char *str);
|
---|
86 | int ntstdio_printf(ntstdio_t *handle, const char *fmt, ...);
|
---|
87 | int ntstdio_snprintf(char *buf, int len, const char *fmt, ...);
|
---|
88 | int ntstdio_fprintf(ntstdio_t *handle, NTSTDIO_XO xo, const char *fmt, ...);
|
---|
89 |
|
---|
90 | int ntstdio_getc(ntstdio_t *handle);
|
---|
91 | int ntstdio_gets(ntstdio_t *handle, char *buf, int len);
|
---|
92 | int ntstdio_fgets(ntstdio_t *handle, NTSTDIO_XI xi, char *buf, int len);
|
---|
93 |
|
---|
94 | #endif
|
---|
95 |
|
---|