home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0638.ZIP / CCE_0638 / UPDATE / UPDATE29.ZOO / editline / testit.c < prev    next >
C/C++ Source or Header  |  1993-03-28  |  1KB  |  63 lines

  1. /*  $Revision: 1.2 $
  2. **
  3. **  A "micro-shell" to test editline library.
  4. **  If given any arguments, commands aren't executed.
  5. */
  6. #include <stdio.h>
  7. #if    defined(HAVE_STDLIB)
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #endif    /* defined(HAVE_STDLIB) */
  11.  
  12. extern char    *readline();
  13. extern void    add_history();
  14.  
  15. #if    !defined(HAVE_STDLIB)
  16. extern int    chdir();
  17. extern int    free();
  18. extern int    strncmp();
  19. extern int    system();
  20. extern void    exit();
  21. #endif    /* !defined(HAVE_STDLIB) */
  22. #ifdef atarist
  23. #include <unistd.h>
  24. #endif
  25.  
  26. #if    defined(NEED_PERROR)
  27. void
  28. perror(s)
  29.     char    *s;
  30. {
  31.     extern int    errno;
  32.  
  33.     (voidf)printf(stderr, "%s: error %d\n", s, errno);
  34. }
  35. #endif    /* defined(NEED_PERROR) */
  36.  
  37.  
  38. /* ARGSUSED1 */
  39. int
  40. main(ac, av)
  41.     int        ac;
  42.     char    *av[];
  43. {
  44.     char    *p;
  45.     int        doit;
  46.  
  47.     doit = ac == 1;
  48.     while ((p = readline("testit> ")) != NULL) {
  49.     (void)printf("\t\t\t|%s|\n", p);
  50.     if (doit)
  51.         if (strncmp(p, "cd ", 3) == 0) {
  52.         if (chdir(&p[3]) < 0)
  53.             perror(&p[3]);
  54.         }
  55.         else if (system(p) != 0)
  56.         perror(p);
  57.     add_history(p);
  58.     free(p);
  59.     }
  60.     exit(0);
  61.     /* NOTREACHED */
  62. }
  63.