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