Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
f5067f47
...
f5067f47f68548f401863d16248836b5fa498b85
authored
2004-04-08 13:09:17 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Rewritten to drop the readline dependency.
1 parent
2909cbe1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
97 deletions
examples/pop3client.c
examples/pop3client.c
View file @
f5067f4
...
...
@@ -29,9 +29,12 @@
#include <stdlib.h>
#include <termios.h>
#include <signal.h>
#include <ctype.h>
#include <readline/readline.h>
#include <readline/history.h>
#ifdef WITH_READLINE
# include <readline/readline.h>
# include <readline/history.h>
#endif
#include <mailutils/pop3.h>
#include <mailutils/iterator.h>
...
...
@@ -68,7 +71,6 @@ int com_verbose (char *);
void
initialize_readline
(
void
);
char
*
stripwhite
(
char
*
);
COMMAND
*
find_command
(
char
*
);
void
*
xmalloc
(
size_t
);
char
*
dupstr
(
const
char
*
);
int
execute_line
(
char
*
);
int
valid_argument
(
const
char
*
,
char
*
);
...
...
@@ -110,30 +112,123 @@ int verbose;
/* When non-zero, this global means the user is done using this program. */
int
done
;
#if 0
void *
xmalloc (size_t size)
char
*
dupstr
(
const
char
*
s
)
{
void *m = malloc (size);
if (!m)
char
*
r
;
r
=
malloc
(
strlen
(
s
)
+
1
);
if
(
!
r
)
{
fprintf
(
stderr
,
"Memory exhausted
\n
"
);
exit
(
1
);
}
return m;
strcpy
(
r
,
s
);
return
r
;
}
#ifdef WITH_READLINE
/* Interface to Readline Completion */
char
*
command_generator
(
const
char
*
,
int
);
char
**
pop_completion
(
char
*
,
int
,
int
);
/* Tell the GNU Readline library how to complete. We want to try to complete
on command names if this is the first word in the line, or on filenames
if not. */
void
initialize_readline
()
{
/* Allow conditional parsing of the ~/.inputrc file. */
rl_readline_name
=
(
char
*
)
"pop3"
;
/* Tell the completer that we want a crack first. */
rl_attempted_completion_function
=
(
CPPFunction
*
)
pop_completion
;
}
/* Attempt to complete on the contents of TEXT. START and END bound the
region of rl_line_buffer that contains the word to complete. TEXT is
the word to complete. We can use the entire contents of rl_line_buffer
in case we want to do some simple parsing. Return the array of matches,
or NULL if there aren't any. */
char
**
pop_completion
(
char
*
text
,
int
start
,
int
end
)
{
char
**
matches
;
(
void
)
end
;
matches
=
(
char
**
)
NULL
;
/* If this word is at the start of the line, then it is a command
to complete. Otherwise it is the name of a file in the current
directory. */
if
(
start
==
0
)
matches
=
completion_matches
(
text
,
command_generator
);
return
(
matches
);
}
#endif
/* Generator function for command completion. STATE lets us know whether
to start from scratch; without any state (i.e. STATE == 0), then we
start at the top of the list. */
char
*
dupstr
(
const
char
*
s
)
command_generator
(
const
char
*
text
,
int
state
)
{
char
*
r
;
static
int
list_index
,
len
;
const
char
*
name
;
r
=
xmalloc
(
strlen
(
s
)
+
1
);
strcpy
(
r
,
s
);
return
r
;
/* If this is a new word to complete, initialize now. This includes
saving the length of TEXT for efficiency, and initializing the index
variable to 0. */
if
(
!
state
)
{
list_index
=
0
;
len
=
strlen
(
text
);
}
/* Return the next name which partially matches from the command list. */
while
((
name
=
commands
[
list_index
].
name
))
{
list_index
++
;
if
(
strncmp
(
name
,
text
,
len
)
==
0
)
return
(
dupstr
(
name
));
}
/* If no names matched, then return NULL. */
return
((
char
*
)
NULL
);
}
#else
void
initialize_readline
()
{
}
char
*
readline
(
char
*
prompt
)
{
char
buf
[
255
];
if
(
prompt
)
{
printf
(
"%s"
,
prompt
);
fflush
(
stdout
);
}
if
(
!
fgets
(
buf
,
sizeof
(
buf
),
stdin
))
return
NULL
;
return
strdup
(
buf
);
}
void
add_history
(
const
char
*
s
)
{
}
#endif
int
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -186,11 +281,11 @@ execute_line (char *line)
/* Isolate the command word. */
i
=
0
;
while
(
line
[
i
]
&&
white
space
(
line
[
i
]))
while
(
line
[
i
]
&&
is
space
(
line
[
i
]))
i
++
;
word
=
line
+
i
;
while
(
line
[
i
]
&&
!
white
space
(
line
[
i
]))
while
(
line
[
i
]
&&
!
is
space
(
line
[
i
]))
i
++
;
if
(
line
[
i
])
...
...
@@ -205,7 +300,7 @@ execute_line (char *line)
}
/* Get argument to command, if any. */
while
(
white
space
(
line
[
i
]))
while
(
is
space
(
line
[
i
]))
i
++
;
word
=
line
+
i
;
...
...
@@ -236,95 +331,20 @@ stripwhite (char *string)
{
register
char
*
s
,
*
t
;
for
(
s
=
string
;
white
space
(
*
s
);
s
++
)
for
(
s
=
string
;
is
space
(
*
s
);
s
++
)
;
if
(
*
s
==
0
)
return
(
s
);
t
=
s
+
strlen
(
s
)
-
1
;
while
(
t
>
s
&&
white
space
(
*
t
))
while
(
t
>
s
&&
is
space
(
*
t
))
t
--
;
*++
t
=
'\0'
;
return
s
;
}
/* **************************************************************** */
/* */
/* Interface to Readline Completion */
/* */
/* **************************************************************** */
char
*
command_generator
(
const
char
*
,
int
);
char
**
pop_completion
(
char
*
,
int
,
int
);
/* Tell the GNU Readline library how to complete. We want to try to complete
on command names if this is the first word in the line, or on filenames
if not. */
void
initialize_readline
()
{
/* Allow conditional parsing of the ~/.inputrc file. */
rl_readline_name
=
(
char
*
)
"pop3"
;
/* Tell the completer that we want a crack first. */
rl_attempted_completion_function
=
(
CPPFunction
*
)
pop_completion
;
}
/* Attempt to complete on the contents of TEXT. START and END bound the
region of rl_line_buffer that contains the word to complete. TEXT is
the word to complete. We can use the entire contents of rl_line_buffer
in case we want to do some simple parsing. Return the array of matches,
or NULL if there aren't any. */
char
**
pop_completion
(
char
*
text
,
int
start
,
int
end
)
{
char
**
matches
;
(
void
)
end
;
matches
=
(
char
**
)
NULL
;
/* If this word is at the start of the line, then it is a command
to complete. Otherwise it is the name of a file in the current
directory. */
if
(
start
==
0
)
matches
=
completion_matches
(
text
,
command_generator
);
return
(
matches
);
}
/* Generator function for command completion. STATE lets us know whether
to start from scratch; without any state (i.e. STATE == 0), then we
start at the top of the list. */
char
*
command_generator
(
const
char
*
text
,
int
state
)
{
static
int
list_index
,
len
;
const
char
*
name
;
/* If this is a new word to complete, initialize now. This includes
saving the length of TEXT for efficiency, and initializing the index
variable to 0. */
if
(
!
state
)
{
list_index
=
0
;
len
=
strlen
(
text
);
}
/* Return the next name which partially matches from the command list. */
while
((
name
=
commands
[
list_index
].
name
))
{
list_index
++
;
if
(
strncmp
(
name
,
text
,
len
)
==
0
)
return
(
dupstr
(
name
));
}
/* If no names matched, then return NULL. */
return
((
char
*
)
NULL
);
}
int
com_verbose
(
char
*
arg
)
{
...
...
@@ -525,8 +545,7 @@ com_stat (char *arg)
}
int
com_dele
(
arg
)
char
*
arg
;
com_dele
(
char
*
arg
)
{
unsigned
msgno
;
if
(
!
valid_argument
(
"dele"
,
arg
))
...
...
@@ -739,3 +758,4 @@ valid_argument (const char *caller, char *arg)
return
1
;
}
...
...
Please
register
or
sign in
to post a comment