PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
simple
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
char
* _safe_gets(
text_t
*text,
char
* origBuf,
int
count)
20
{
21
char
* buf = origBuf;
22
while
(count-- > 0)
23
{
24
int
ch = text->
rxChar
(text);
25
26
if
(ch == 8 || ch == 127)
27
{
28
if
(buf > origBuf)
29
{
30
text->
txChar
(text,
'\010'
);
31
text->
txChar
(text,
' '
);
32
text->
txChar
(text,
'\010'
);
33
count += 1;
34
buf--;
35
}
36
count += 1;
37
continue
;
38
}
39
40
text->
txChar
(text, ch);
41
if
(ch ==
'\r'
)
42
text->
txChar
(text,
'\n'
);
43
44
if
(ch ==
'\r'
|| ch ==
'\n'
)
45
break
;
46
47
*(buf++) = ch;
48
}
49
*buf = 0;
50
51
return
(origBuf);
52
}
53
54
55
/* +--------------------------------------------------------------------
56
* | TERMS OF USE: MIT License
57
* +--------------------------------------------------------------------
58
* Permission is hereby granted, free of charge, to any person obtaining
59
* a copy of this software and associated documentation files
60
* (the "Software"), to deal in the Software without restriction,
61
* including without limitation the rights to use, copy, modify, merge,
62
* publish, distribute, sublicense, and/or sell copies of the Software,
63
* and to permit persons to whom the Software is furnished to do so,
64
* subject to the following conditions:
65
*
66
* The above copyright notice and this permission notice shall be
67
* included in all copies or substantial portions of the Software.
68
*
69
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
70
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
72
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
76
* +--------------------------------------------------------------------
77
*/
text_struct::rxChar
int(* rxChar)(struct text_struct *p)
Definition:
simpletext.h:73
text_struct::txChar
int(* txChar)(struct text_struct *p, int ch)
Definition:
simpletext.h:75
text_struct
Structure that contains data used by simple text device libraries.
Definition:
simpletext.h:70
Generated on Sat Aug 27 2016 00:58:09 for PropWare by
1.8.12