diff options
Diffstat (limited to 'sh.c')
-rw-r--r-- | sh.c | 39 |
1 files changed, 22 insertions, 17 deletions
@@ -37,6 +37,9 @@ | |||
37 | #include <sys/ioctl.h> | 37 | #include <sys/ioctl.h> |
38 | #include <sys/wait.h> | 38 | #include <sys/wait.h> |
39 | #include <unistd.h> | 39 | #include <unistd.h> |
40 | #ifdef BB_FEATURE_SH_COMMAND_EDITING | ||
41 | #include "cmdedit.h" | ||
42 | #endif | ||
40 | 43 | ||
41 | 44 | ||
42 | #define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n" | 45 | #define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n" |
@@ -132,6 +135,16 @@ static const char shell_usage[] = | |||
132 | static char cwd[1024]; | 135 | static char cwd[1024]; |
133 | static char *prompt = "# "; | 136 | static char *prompt = "# "; |
134 | 137 | ||
138 | #ifdef BB_FEATURE_SH_COMMAND_EDITING | ||
139 | void win_changed(int sig) | ||
140 | { | ||
141 | struct winsize win = { 0, 0 }; | ||
142 | ioctl(0, TIOCGWINSZ, &win); | ||
143 | if (win.ws_col > 0) { | ||
144 | cmdedit_setwidth( win.ws_col - 1); | ||
145 | } | ||
146 | } | ||
147 | #endif | ||
135 | 148 | ||
136 | 149 | ||
137 | /* built-in 'cd <path>' handler */ | 150 | /* built-in 'cd <path>' handler */ |
@@ -398,7 +411,7 @@ static int getCommand(FILE * source, char *command) | |||
398 | fflush(stdout); | 411 | fflush(stdout); |
399 | promptStr=(char*)malloc(sizeof(char)*(len+1)); | 412 | promptStr=(char*)malloc(sizeof(char)*(len+1)); |
400 | sprintf(promptStr, "%s %s", cwd, prompt); | 413 | sprintf(promptStr, "%s %s", cwd, prompt); |
401 | cmdedit_read_input(promptStr, fileno(stdin), fileno(stdout), command); | 414 | cmdedit_read_input(promptStr, command); |
402 | free( promptStr); | 415 | free( promptStr); |
403 | return 0; | 416 | return 0; |
404 | #else | 417 | #else |
@@ -696,7 +709,6 @@ static int parseCommand(char **commandPtr, struct job *job, int *isBg) | |||
696 | strcpy(job->text, *commandPtr); | 709 | strcpy(job->text, *commandPtr); |
697 | } else { | 710 | } else { |
698 | /* This leaves any trailing spaces, which is a bit sloppy */ | 711 | /* This leaves any trailing spaces, which is a bit sloppy */ |
699 | |||
700 | count = returnCommand - *commandPtr; | 712 | count = returnCommand - *commandPtr; |
701 | job->text = malloc(count + 1); | 713 | job->text = malloc(count + 1); |
702 | strncpy(job->text, *commandPtr, count); | 714 | strncpy(job->text, *commandPtr, count); |
@@ -793,14 +805,12 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg) | |||
793 | if (inBg) { | 805 | if (inBg) { |
794 | /* we don't wait for background jobs to return -- append it | 806 | /* we don't wait for background jobs to return -- append it |
795 | to the list of backgrounded jobs and leave it alone */ | 807 | to the list of backgrounded jobs and leave it alone */ |
796 | |||
797 | printf("[%d] %d\n", job->jobId, | 808 | printf("[%d] %d\n", job->jobId, |
798 | newJob.progs[newJob.numProgs - 1].pid); | 809 | newJob.progs[newJob.numProgs - 1].pid); |
799 | } else { | 810 | } else { |
800 | jobList->fg = job; | 811 | jobList->fg = job; |
801 | 812 | ||
802 | /* move the new process group into the foreground */ | 813 | /* move the new process group into the foreground */ |
803 | |||
804 | if (tcsetpgrp(0, newJob.pgrp)) | 814 | if (tcsetpgrp(0, newJob.pgrp)) |
805 | perror("tcsetpgrp"); | 815 | perror("tcsetpgrp"); |
806 | } | 816 | } |
@@ -938,29 +948,24 @@ int shell_main(int argc, char **argv) | |||
938 | /* initialize the cwd */ | 948 | /* initialize the cwd */ |
939 | getcwd(cwd, sizeof(cwd)); | 949 | getcwd(cwd, sizeof(cwd)); |
940 | 950 | ||
951 | #ifdef BB_FEATURE_SH_COMMAND_EDITING | ||
952 | signal(SIGWINCH, win_changed); | ||
953 | win_changed(0); | ||
954 | #endif | ||
941 | 955 | ||
942 | //if (argv[0] && argv[0][0] == '-') { | 956 | //if (argv[0] && argv[0][0] == '-') { |
943 | // shell_source("/etc/profile"); | 957 | // shell_source("/etc/profile"); |
944 | //} | 958 | //} |
945 | 959 | ||
946 | if (argc < 2) { | 960 | if (argc < 2) { |
947 | fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, | 961 | fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, BB_BT); |
948 | BB_BT); | 962 | fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n"); |
949 | fprintf(stdout, | ||
950 | "Enter 'help' for a list of built-in commands.\n\n"); | ||
951 | } else { | 963 | } else { |
952 | input = fopen(argv[1], "r"); | 964 | input = fopen(argv[1], "r"); |
953 | if (!input) | 965 | if (!input) { |
954 | fatalError("A: Couldn't open file '%s': %s\n", argv[1], | 966 | fatalError("A: Couldn't open file '%s': %s\n", argv[1], |
955 | strerror(errno)); | 967 | strerror(errno)); |
956 | // else | 968 | } |
957 | // fatalError("Got it.\n"); | ||
958 | //exit(shell_source(argv[1])); | ||
959 | |||
960 | /* Set terminal IO to canonical mode, and save old term settings. */ | ||
961 | #ifdef BB_FEATURE_SH_COMMAND_EDITING | ||
962 | cmdedit_init(); | ||
963 | #endif | ||
964 | } | 969 | } |
965 | 970 | ||
966 | return (busy_loop(input)); | 971 | return (busy_loop(input)); |