Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Main
Synchronet
Commits
f9ef90f9
Commit
f9ef90f9
authored
Feb 21, 2002
by
rswindell
Browse files
Created a simple getstr() function to use in place of fgets().
parent
a9637026
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
5 deletions
+43
-5
src/uifc/uifcx.c
src/uifc/uifcx.c
+43
-5
No files found.
src/uifc/uifcx.c
View file @
f9ef90f9
...
...
@@ -37,6 +37,13 @@
#include "uifc.h"
#include <sys/types.h>
#ifdef __unix__
/* #include <sys/time.h> why? */
#include <unistd.h>
#endif
static
char
*
helpfile
=
0
;
static
uint
helpline
=
0
;
static
uifcapi_t
*
api
;
...
...
@@ -99,6 +106,34 @@ int uscrn(char *str)
return
(
0
);
}
static
int
getstr
(
char
*
str
,
int
maxlen
)
{
char
ch
;
int
len
=
0
;
int
istty
;
istty
=
isatty
(
fileno
(
stdin
));
while
(
1
)
{
fread
(
&
ch
,
1
,
1
,
stdin
);
if
(
!
istty
)
{
printf
(
"%c"
,
ch
);
fflush
(
stdout
);
}
if
(
ch
==
'\r'
||
ch
==
'\n'
)
/* enter */
break
;
if
(
ch
==
'\b'
)
{
/* backspace */
if
(
len
)
len
--
;
continue
;
}
if
(
len
<
maxlen
)
str
[
len
++
]
=
ch
;
}
str
[
len
]
=
0
;
/* we need The Terminator */
return
(
len
);
}
/****************************************************************************/
/* Local utility function. */
/****************************************************************************/
...
...
@@ -110,7 +145,7 @@ static int which(char* prompt, int max)
while
(
1
)
{
printf
(
"%s which (1-%d): "
,
prompt
,
max
);
str
[
0
]
=
0
;
f
gets
(
str
,
sizeof
(
str
)
-
1
,
stdin
);
gets
tr
(
str
,
sizeof
(
str
)
-
1
);
i
=
atoi
(
str
);
if
(
i
>
0
&&
i
<=
max
)
return
(
i
-
1
);
...
...
@@ -160,7 +195,7 @@ int ulist(int mode, char left, int top, char width, int *cur, int *bar
if
(
!
(
lines
%
api
->
scrn_len
))
{
printf
(
"More? "
);
str
[
0
]
=
0
;
f
gets
(
str
,
sizeof
(
str
)
-
1
,
stdin
);
gets
tr
(
str
,
sizeof
(
str
)
-
1
);
if
(
toupper
(
*
str
)
==
'N'
)
break
;
}
...
...
@@ -177,7 +212,7 @@ int ulist(int mode, char left, int top, char width, int *cur, int *bar
printf
(
"
\n
Which (Help%s or Quit): "
,
str
);
}
str
[
0
]
=
0
;
f
gets
(
str
,
sizeof
(
str
)
-
1
,
stdin
);
gets
tr
(
str
,
sizeof
(
str
)
-
1
);
truncsp
(
str
);
i
=
atoi
(
str
);
...
...
@@ -252,7 +287,8 @@ int uinput(int mode, char left, char top, char *prompt, char *outstr,
while
(
1
)
{
printf
(
"%s (maxlen=%u): "
,
prompt
,
max
);
fgets
(
str
,
max
,
stdin
);
getstr
(
str
,
max
);
truncsp
(
str
);
if
(
strcmp
(
str
,
"?"
))
break
;
...
...
@@ -260,6 +296,8 @@ int uinput(int mode, char left, char top, char *prompt, char *outstr,
}
if
(
strcmp
(
outstr
,
str
))
api
->
changes
=
1
;
if
(
kmode
&
K_UPPER
)
/* convert to uppercase? */
strupr
(
str
);
strcpy
(
outstr
,
str
);
return
(
strlen
(
outstr
));
}
...
...
@@ -349,7 +387,7 @@ void help()
puts
(
hbuf
);
if
(
strlen
(
hbuf
)
>
200
)
{
printf
(
"Hit enter"
);
f
gets
(
str
,
sizeof
(
str
)
-
1
,
stdin
);
gets
tr
(
str
,
sizeof
(
str
)
-
1
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment