2008-06-07 18:28:36 +08:00
|
|
|
/* $Revision: 5 $
|
|
|
|
**
|
|
|
|
** A "micro-shell" to test editline library.
|
|
|
|
** If given any arguments, commands aren't executed.
|
|
|
|
*/
|
2008-12-03 02:09:17 +08:00
|
|
|
#include <config.h>
|
2008-06-07 18:28:36 +08:00
|
|
|
#include <stdio.h>
|
2010-07-18 04:23:21 +08:00
|
|
|
#ifdef HAVE_STDLIB_H
|
2008-06-07 18:28:36 +08:00
|
|
|
#include <stdlib.h>
|
2008-12-03 02:09:17 +08:00
|
|
|
#endif
|
2010-07-18 04:23:21 +08:00
|
|
|
#ifdef HAVE_STRING_H
|
2008-12-03 02:09:17 +08:00
|
|
|
#include <string.h>
|
|
|
|
#endif
|
2010-07-18 04:23:21 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2008-12-03 02:09:17 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2010-07-18 04:23:21 +08:00
|
|
|
#include "editline.h"
|
2008-06-07 18:28:36 +08:00
|
|
|
|
2010-07-18 04:23:21 +08:00
|
|
|
#ifndef HAVE_PERROR
|
|
|
|
void perror(char *s)
|
2008-06-07 18:28:36 +08:00
|
|
|
{
|
2010-07-18 04:23:21 +08:00
|
|
|
extern int errno;
|
2008-06-07 18:28:36 +08:00
|
|
|
|
2010-07-18 04:23:21 +08:00
|
|
|
(void)fprintf(stderr, "%s: error %d\n", s, errno);
|
2008-06-07 18:28:36 +08:00
|
|
|
}
|
2010-07-18 04:23:21 +08:00
|
|
|
#endif /* !HAVE_PERROR */
|
2008-06-07 18:28:36 +08:00
|
|
|
|
2010-07-18 04:23:21 +08:00
|
|
|
int main(int argc, char *argv[] __attribute__ ((unused)))
|
2008-06-07 18:28:36 +08:00
|
|
|
{
|
|
|
|
char *prompt;
|
|
|
|
char *p;
|
|
|
|
int doit;
|
|
|
|
|
2010-07-18 04:23:21 +08:00
|
|
|
doit = argc == 1;
|
2008-06-07 18:28:36 +08:00
|
|
|
if ((prompt = getenv("TESTPROMPT")) == NULL)
|
2008-12-03 02:09:17 +08:00
|
|
|
prompt = "testit> ";
|
2008-06-07 18:28:36 +08:00
|
|
|
|
|
|
|
while ((p = readline(prompt)) != NULL) {
|
|
|
|
(void)printf("\t\t\t|%s|\n", p);
|
2008-06-09 05:45:07 +08:00
|
|
|
if (doit) {
|
2008-06-07 18:28:36 +08:00
|
|
|
if (strncmp(p, "cd ", 3) == 0) {
|
2008-06-09 05:45:07 +08:00
|
|
|
if (chdir(&p[3]) < 0) {
|
2008-06-07 18:28:36 +08:00
|
|
|
perror(&p[3]);
|
2008-06-09 05:45:07 +08:00
|
|
|
}
|
2008-06-07 18:28:36 +08:00
|
|
|
}
|
2008-06-09 05:45:07 +08:00
|
|
|
else if (system(p) != 0) {
|
2008-06-07 18:28:36 +08:00
|
|
|
perror(p);
|
2008-06-09 05:45:07 +08:00
|
|
|
}
|
|
|
|
}
|
2008-06-07 18:28:36 +08:00
|
|
|
add_history(p);
|
|
|
|
free(p);
|
|
|
|
}
|
2008-06-09 05:45:07 +08:00
|
|
|
|
|
|
|
return 0;
|
2008-06-07 18:28:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* $PchId: testit.c,v 1.3 1996/02/22 21:18:51 philip Exp $
|
|
|
|
*/
|