/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
#include        <stdio.h>
#include        <sys/types.h>
#include        <sys/wait.h>
#include        <signal.h>

#define MAXLINE 4096                    /* max line length */


/* signal-catching function */
void sig_int(int signo) {
        printf("interrupt\n%% ");
}


int main() {
        char    buf[MAXLINE];
        pid_t   pid;
        int             status;

        if (signal(SIGINT, sig_int) == SIG_ERR) {
           printf("signal error\n");
           exit(-1);
        }

        printf("%% ");  /* print prompt (printf requires %% to print %) */
        while (fgets(buf, MAXLINE, stdin) != NULL) {
                buf[strlen(buf) - 1] = 0;       /* replace newline with null */

                if ( (pid = fork()) < 0) {
                    printf("fork error\n");
                    exit(-1);
                }

                else if (pid == 0) {            /* child */
                        execlp(buf, buf, (char *) 0);
                        printf("couldn't execute: %s\n", buf);
                        exit(127);
                }

                /* parent */
                if ( (pid = waitpid(pid, &status, 0)) < 0) {
                        printf("waitpid error\n");
                        exit(127);
                }
                printf("%% ");
        }
        exit(0);
}

