File: testit.c

package info (click to toggle)
editline 1.12-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge
  • size: 128 kB
  • ctags: 196
  • sloc: ansic: 1,747; makefile: 84
file content (64 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*  $Revision: 1.4 $
**
**  A "micro-shell" to test editline library.
**  If given any arguments, commands aren't executed.
*/
#include <stdio.h>
#if	defined(HAVE_STDLIB)
#include <stdlib.h>
#endif	/* defined(HAVE_STDLIB) */

extern char	*readline();
extern void	add_history();

#if	!defined(HAVE_STDLIB)
extern int	chdir();
extern int	free();
extern int	strncmp();
extern int	system();
extern void	exit();
extern char	*getenv();
#endif	/* !defined(HAVE_STDLIB) */


#if	defined(NEED_PERROR)
void
perror(s)
    char	*s;
{
    extern int	errno;

    (voidf)printf(stderr, "%s: error %d\n", s, errno);
}
#endif	/* defined(NEED_PERROR) */


/* ARGSUSED1 */
int
main(ac, av)
    int		ac;
    char	*av[];
{
    char	*prompt;
    char	*p;
    int		doit;

    doit = ac == 1;
    if ((prompt = getenv("TESTPROMPT")) == NULL)
	prompt = "testit>  ";

    while ((p = readline(prompt)) != NULL) {
	(void)printf("\t\t\t|%s|\n", p);
	if (doit)
	    if (strncmp(p, "cd ", 3) == 0) {
		if (chdir(&p[3]) < 0)
		    perror(&p[3]);
	    }
	    else if (system(p) != 0)
		perror(p);
	add_history(p);
	free(p);
    }
    exit(0);
    /* NOTREACHED */
}