PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Simple Libraries
TextDevices
libsimpletext
safe_gets.c
1
/*
2
* Small modifications for using text_t interface by Steve Denson.
3
* Super-simple text I/O for PropGCC, stripped of all stdio overhead.
4
* Copyright (c) 2012, Ted Stefanik. Concept inspired by:
5
*
6
* very simple printf, adapted from one written by me [Eric Smith]
7
* for the MiNT OS long ago
8
* placed in the public domain
9
* - Eric Smith
10
* Propeller specific adaptations
11
* Copyright (c) 2011 Parallax, Inc.
12
* Written by Eric R. Smith, Total Spectrum Software Inc.
13
*
14
* MIT licensed (see terms at end of file)
15
*/
16
#include <ctype.h>
17
#include "
simpletext.h
"
18
19
20
21
char
* _safe_gets(
text_t
*text,
char
* origBuf,
int
count
)
22
{
23
char
* buf = origBuf;
24
while
(
count
-- > 0)
25
{
26
int
ch = text->
rxChar
(text);
27
28
if
(text->
terminalEcho
)
29
{
30
if
(ch == 8 || ch == 127)
31
{
32
if
(buf > origBuf)
33
{
34
text->
txChar
(text,
'\010'
);
35
text->
txChar
(text,
' '
);
36
text->
txChar
(text,
'\010'
);
37
count
+= 1;
38
buf--;
39
}
40
count
+= 1;
41
continue
;
42
}
43
44
#ifdef SIMPLETEXT_ECS
45
/*
46
if( !( (ch == *(text->ec)) || (ch == *(text->ec+1)) ) )
47
{
48
text->txChar(text, ch);
49
}
50
else
51
{
52
char t1 = *(text->ecs);
53
char t2 = *(text->ecs+1);
54
if(t1) text->txChar(text, t1);
55
if(t2) text->txChar(text, t2);
56
}
57
*/
58
59
if
((ch != text->
ecA
) && (ch != text->ecB))
60
{
61
text->
txChar
(text, ch);
62
}
63
else
64
{
65
if
(text->ecsA) text->
txChar
(text, text->ecsA);
66
if
(text->ecsB) text->
txChar
(text, text->ecsB);
67
}
68
69
70
#endif
71
72
73
#ifdef ST_SLASH_ReturN
74
text->
txChar
(text, ch);
75
76
if
(ch ==
'\r'
)
77
text->
txChar
(text,
'\n'
);
78
#endif
79
}
80
81
#ifdef ST_NO_CHAR_SUBS
82
text->
txChar
(text, ch);
83
#endif
84
85
86
if
(ch ==
'\r'
|| ch ==
'\n'
)
87
break
;
88
89
*(buf++) = ch;
90
}
91
92
*buf = 0;
93
94
return
(origBuf);
95
}
96
97
98
/* +--------------------------------------------------------------------
99
* | TERMS OF USE: MIT License
100
* +--------------------------------------------------------------------
101
* Permission is hereby granted, free of charge, to any person obtaining
102
* a copy of this software and associated documentation files
103
* (the "Software"), to deal in the Software without restriction,
104
* including without limitation the rights to use, copy, modify, merge,
105
* publish, distribute, sublicense, and/or sell copies of the Software,
106
* and to permit persons to whom the Software is furnished to do so,
107
* subject to the following conditions:
108
*
109
* The above copyright notice and this permission notice shall be
110
* included in all copies or substantial portions of the Software.
111
*
112
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
113
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
114
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
115
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
116
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
117
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
118
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
119
* +--------------------------------------------------------------------
120
*/
text_struct::rxChar
int(* rxChar)(struct text_struct *p)
Definition:
simpletext.h:84
text_struct::txChar
int(* txChar)(struct text_struct *p, int ch)
Definition:
simpletext.h:86
count
long count(int pin, long duration)
Count number of low to high transitions an external input applies to an I/O pin over a certain period...
Definition:
count.c:19
simpletext.h
This library provides a collection of functions for communicating with text devices such as SimpleIDE...
text_struct
Structure that contains data used by simple text device libraries.
Definition:
simpletext.h:81
text_struct::terminalEcho
volatile int terminalEcho
Definition:
simpletext.h:92
text_struct::ecA
volatile char ecA
Definition:
simpletext.h:97
Generated on Fri May 20 2022 16:48:05 for PropWare by
1.8.17