シェルスクリプト言語xyzshのソースコード。
修訂 | 219e30081f1c57d0df8328383d59588bedda6b95 (tree) |
---|---|
時間 | 2012-11-08 13:23:09 |
作者 | ab25q <ab25cq@gmai...> |
Commiter | ab25q |
v1.1.8b
@@ -1,4 +1,10 @@ | ||
1 | 1 | |
2 | +2012 8th Norvember version 1.1.8b | |
3 | + | |
4 | + Changed "exit -force" action for mfiler4. | |
5 | + | |
6 | + Modified job title more better. | |
7 | + | |
2 | 8 | 2012 5th Norvember version 1.1.8a |
3 | 9 | |
4 | 10 | Fixed errror message. |
@@ -125,6 +125,6 @@ completion git ( | ||
125 | 125 | ) |
126 | 126 | |
127 | 127 | completion kill ( |
128 | - ps | selector | split | lines 1 (|print) | |
128 | + ps | each ( | sub '^\s+' '' ) | selector | split | lines 0 (|print) | |
129 | 129 | ) |
130 | 130 |
@@ -149,6 +149,36 @@ void sCommand_sweep_runtime_info(sCommand* self) | ||
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | +void sStatment_sweep_runtime_info(sStatment* self) | |
153 | +{ | |
154 | + int j; | |
155 | + for(j=0; j<self->mCommandsNum; j++) { | |
156 | + sCommand* command = self->mCommands + j; | |
157 | + | |
158 | + int i; | |
159 | + for(i=0; i<command->mArgsNumRuntime; i++) { | |
160 | + FREE(command->mArgsRuntime[i]); | |
161 | + } | |
162 | + command->mArgsNumRuntime = 0; | |
163 | + | |
164 | + for(i=0; i<XYZSH_OPTION_MAX; i++) { | |
165 | + if(command->mOptions[i].mKey) { FREE(command->mOptions[i].mKey); } | |
166 | + if(command->mOptions[i].mArg) { FREE(command->mOptions[i].mArg); } | |
167 | + } | |
168 | + | |
169 | + memset(command->mOptions, 0, sizeof(option_hash_it)*XYZSH_OPTION_MAX); | |
170 | + | |
171 | + if(command->mRedirectsFileNamesRuntime) { | |
172 | + for(i=0; i<command->mRedirectsNum; i++) { | |
173 | + FREE(command->mRedirectsFileNamesRuntime[i]); | |
174 | + } | |
175 | + FREE(command->mRedirectsFileNamesRuntime); | |
176 | + | |
177 | + command->mRedirectsFileNamesRuntime = NULL; | |
178 | + } | |
179 | + } | |
180 | +} | |
181 | + | |
152 | 182 | void sCommand_add_redirect_to_command(sCommand* self, MANAGED char* name, int redirect) |
153 | 183 | { |
154 | 184 | if(self->mRedirectsNum >= self->mRedirectsSize) { |
@@ -32,7 +32,7 @@ BOOL cmd_jobs(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
32 | 32 | int i; |
33 | 33 | for(i=0; i<vector_count(gJobs); i++) { |
34 | 34 | sObject* job = vector_item(gJobs, i); |
35 | - int size = snprintf(buf, BUFSIZ, "[%d] name: %s pid&pgrp: %d", i+1, SJOB(job).mName, SJOB(job).mPGroup); | |
35 | + int size = snprintf(buf, BUFSIZ, "[%d] %s (pgrp: %d)", i+1, SJOB(job).mName, SJOB(job).mPGroup); | |
36 | 36 | if(!fd_write(nextout, buf, size)) { |
37 | 37 | err_msg("signal interrupt", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); |
38 | 38 | runinfo->mRCode = RCODE_SIGNAL_INTERRUPT; |
@@ -82,8 +82,6 @@ BOOL cmd_exit(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
82 | 82 | sCommand* command = runinfo->mCommand; |
83 | 83 | |
84 | 84 | if(sCommand_option_item(command, "-force")) { |
85 | - xyzsh_kill_all_jobs(); | |
86 | - | |
87 | 85 | runinfo->mRCode = RCODE_EXIT; |
88 | 86 | } |
89 | 87 | else { |
@@ -127,9 +127,7 @@ BOOL cmd_selector(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
127 | 127 | fd_split(nextin, lf); |
128 | 128 | |
129 | 129 | if(vector_count(SFD(nextin).fdbuf.mLines) > 0) { |
130 | -#if !defined(__FREEBSD__) | |
131 | 130 | msave_screen(); |
132 | -#endif | |
133 | 131 | msave_ttysettings(); |
134 | 132 | minitscr(); |
135 | 133 |
@@ -235,9 +233,7 @@ BOOL cmd_selector(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
235 | 233 | } |
236 | 234 | else if(key == 'q' || key == 3 | key == 27 || key == 7) { |
237 | 235 | mendwin(); |
238 | -#if !defined(__FREEBSD__) | |
239 | 236 | mrestore_screen(); |
240 | -#endif | |
241 | 237 | mrestore_ttysettings(); |
242 | 238 | FREE(markfiles); |
243 | 239 | return FALSE; |
@@ -329,9 +325,7 @@ BOOL cmd_selector(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
329 | 325 | FREE(markfiles); |
330 | 326 | |
331 | 327 | mendwin(); |
332 | -#if !defined(__FREEBSD__) | |
333 | 328 | mrestore_screen(); |
334 | -#endif | |
335 | 329 | mrestore_ttysettings(); |
336 | 330 | } |
337 | 331 | else { |
@@ -409,9 +403,7 @@ BOOL cmd_p(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
409 | 403 | fd_split(nextin2, lf); |
410 | 404 | |
411 | 405 | msave_ttysettings(); |
412 | -#if !defined(__FREEBSD__) | |
413 | 406 | msave_screen(); |
414 | -#endif | |
415 | 407 | minitscr(); |
416 | 408 | |
417 | 409 | const int maxx = mgetmaxx(); |
@@ -517,9 +509,7 @@ BOOL cmd_p(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
517 | 509 | else if(key == 'q' || key == 3 | key == 27 || key == 7) { |
518 | 510 | err_msg("p: canceled", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); |
519 | 511 | mendwin(); |
520 | -#if !defined(__FREEBSD__) | |
521 | 512 | mrestore_screen(); |
522 | -#endif | |
523 | 513 | mrestore_ttysettings(); |
524 | 514 | FREE(markfiles); |
525 | 515 | return FALSE; |
@@ -571,9 +561,7 @@ BOOL cmd_p(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
571 | 561 | FREE(markfiles); |
572 | 562 | |
573 | 563 | mendwin(); |
574 | -#if !defined(__FREEBSD__) | |
575 | 564 | mrestore_screen(); |
576 | -#endif | |
577 | 565 | mrestore_ttysettings(); |
578 | 566 | } |
579 | 567 |
@@ -971,9 +959,7 @@ BOOL cmd_fselector(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
971 | 959 | |
972 | 960 | if(vector_count(v) > 0) { |
973 | 961 | msave_ttysettings(); // 端末の設定の保存 |
974 | -#if !defined(__FREEBSD__) | |
975 | 962 | msave_screen(); |
976 | -#endif | |
977 | 963 | minitscr(); |
978 | 964 | |
979 | 965 | const int maxx = mgetmaxx(); |
@@ -1107,9 +1093,7 @@ BOOL cmd_fselector(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1107 | 1093 | else if(key == 'q' || key == 3 | key == 27 || key == 7) { |
1108 | 1094 | err_msg("canceled", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); |
1109 | 1095 | mendwin(); |
1110 | -#if !defined(__FREEBSD__) | |
1111 | 1096 | mrestore_screen(); |
1112 | -#endif | |
1113 | 1097 | mrestore_ttysettings(); // 端末の設定の復帰 |
1114 | 1098 | int i; |
1115 | 1099 | for(i=0; i<vector_count(v); i++) { |
@@ -1170,9 +1154,7 @@ BOOL cmd_fselector(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1170 | 1154 | //mclear(); |
1171 | 1155 | //mrefresh(); |
1172 | 1156 | mendwin(); |
1173 | -#if !defined(__FREEBSD__) | |
1174 | 1157 | mrestore_screen(); |
1175 | -#endif | |
1176 | 1158 | mrestore_ttysettings(); // 端末の設定の復帰 |
1177 | 1159 | |
1178 | 1160 | if(vector_count(mark_files) == 0) { |
@@ -386,9 +386,6 @@ void mclear_online(int y) | ||
386 | 386 | mmvprintw(y, 0, space); |
387 | 387 | } |
388 | 388 | |
389 | - | |
390 | - | |
391 | - | |
392 | 389 | void mmove(int y, int x) |
393 | 390 | { |
394 | 391 | gX = x; |
@@ -1895,18 +1892,32 @@ int mis_raw_mode() | ||
1895 | 1892 | |
1896 | 1893 | void msave_screen() |
1897 | 1894 | { |
1895 | +#if defined(__FREEBSD__) | |
1896 | +#else | |
1898 | 1897 | char* str = tigetstr("smcup"); |
1899 | 1898 | if(str) { |
1900 | 1899 | ttywrite(str); |
1901 | 1900 | } |
1901 | + str = tigetstr("sc"); | |
1902 | + if(str) { | |
1903 | + ttywrite(str); | |
1904 | + } | |
1905 | +#endif | |
1902 | 1906 | } |
1903 | 1907 | |
1904 | 1908 | void mrestore_screen() |
1905 | 1909 | { |
1910 | +#if defined(__FREEBSD__) | |
1911 | +#else | |
1906 | 1912 | char* str = tigetstr("rmcup"); |
1907 | 1913 | if(str) { |
1908 | 1914 | ttywrite(str); |
1909 | 1915 | } |
1916 | + str = tigetstr("rc"); | |
1917 | + if(str) { | |
1918 | + ttywrite(str); | |
1919 | + } | |
1920 | +#endif | |
1910 | 1921 | } |
1911 | 1922 | |
1912 | 1923 |
@@ -158,11 +158,12 @@ static void readline_insert_text(char* cmdline, int cursor_point) | ||
158 | 158 | |
159 | 159 | rl_point = n; |
160 | 160 | |
161 | +/* | |
161 | 162 | #if defined(__FREEBSD__) |
162 | -//extern int rl_reset_terminal PARAMS((const char *)); | |
163 | - mclear_immediately(); | |
163 | + puts(""); | |
164 | 164 | rl_forced_update_display(); |
165 | 165 | #endif |
166 | +*/ | |
166 | 167 | } |
167 | 168 | |
168 | 169 | static char* gCmdLine; |
@@ -38,7 +38,6 @@ int main(int argc, char** argv) | ||
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
41 | - | |
42 | 41 | if(optc) { |
43 | 42 | xyzsh_init(kATOptC, no_runtime_script); |
44 | 43 | xyzsh_opt_c(optc, argv, argc); |
@@ -51,6 +50,7 @@ int main(int argc, char** argv) | ||
51 | 50 | setenv("XYZSH_RUNNING_AS_INTRACTIVE_MODE", "1", 1); |
52 | 51 | xyzsh_init(kATConsoleApp, no_runtime_script); |
53 | 52 | xyzsh_readline_interface("", -1, argv, argc); |
53 | + xyzsh_kill_all_jobs(); | |
54 | 54 | } |
55 | 55 | |
56 | 56 | xyzsh_final(); |
@@ -802,11 +802,8 @@ BOOL cmd_readline_insert_text(sObject* nextin, sObject* nextout, sRunInfo* runin | ||
802 | 802 | |
803 | 803 | if(runinfo->mFilter) { |
804 | 804 | (void)rl_insert_text(SFD(nextin).fdbuf.mBuf); |
805 | -#if defined(__FREEBSD__) | |
806 | -//extern int rl_reset_terminal PARAMS((const char *)); | |
807 | - mclear_immediately(); | |
808 | - rl_forced_update_display(); | |
809 | -#endif | |
805 | + puts(""); | |
806 | + rl_forced_update_display(); | |
810 | 807 | |
811 | 808 | runinfo->mRCode = 0; |
812 | 809 | } |
@@ -829,10 +826,8 @@ BOOL cmd_readline_delete_text(sObject* nextin, sObject* nextout, sRunInfo* runin | ||
829 | 826 | if(rl_point < 0) { |
830 | 827 | rl_point = 0; |
831 | 828 | } |
832 | -#if defined(__FREEBSD__) | |
833 | - mclear_immediately(); | |
834 | - rl_forced_update_display(); | |
835 | -#endif | |
829 | + puts(""); | |
830 | + rl_forced_update_display(); | |
836 | 831 | |
837 | 832 | runinfo->mRCode = 0; |
838 | 833 | } |
@@ -912,15 +907,13 @@ static int readline_macro(int count, int key) | ||
912 | 907 | } |
913 | 908 | |
914 | 909 | rl_insert_text(SFD(nextout2).fdbuf.mBuf); |
915 | -#if defined(__FREEBSD__) | |
916 | - mclear_immediately(); | |
910 | + puts(""); | |
917 | 911 | rl_forced_update_display(); |
918 | -#endif | |
919 | - | |
920 | 912 | stack_end_stack(); |
921 | 913 | |
922 | 914 | return 0; |
923 | 915 | } |
916 | + | |
924 | 917 | static int skip_quoted(const char *s, int i, char q) |
925 | 918 | { |
926 | 919 | while(s[i] && s[i]!=q) |
@@ -429,6 +429,34 @@ static void nextin_writer(pid_t pid, sObject* nextin, int* pipeinfds, int* pipeo | ||
429 | 429 | *nextin_reader_pid = pid2; |
430 | 430 | } |
431 | 431 | |
432 | +void make_job_title(sStatment* statment, sCommand* command_, char* title, int title_num) | |
433 | +{ | |
434 | + title[0] = 0; | |
435 | + | |
436 | + int i; | |
437 | + for(i=0; i<statment->mCommandsNum; i++) { | |
438 | + sCommand* command = statment->mCommands + i; | |
439 | + | |
440 | + int j; | |
441 | + for(j=0; j<command->mArgsNumRuntime; j++) { | |
442 | + char* arg = command->mArgsRuntime[j]; | |
443 | + | |
444 | + xstrncat(title, arg, BUFSIZ); | |
445 | + if(j+1 < command->mArgsNumRuntime) { | |
446 | + xstrncat(title, " ", BUFSIZ); | |
447 | + } | |
448 | + } | |
449 | + | |
450 | + if(command == command_) { | |
451 | + break; | |
452 | + } | |
453 | + | |
454 | + if(i+1 < statment->mCommandsNum) { | |
455 | + xstrncat(title, "|", BUFSIZ); | |
456 | + } | |
457 | + } | |
458 | +} | |
459 | + | |
432 | 460 | static BOOL wait_child_program(pid_t pid, pid_t nextin_reader_pid, int nextout2, sRunInfo* runinfo, char* program) |
433 | 461 | { |
434 | 462 | if(nextin_reader_pid != -1) { |
@@ -522,14 +550,9 @@ static BOOL wait_child_program(pid_t pid, pid_t nextin_reader_pid, int nextout2, | ||
522 | 550 | struct termios tty; |
523 | 551 | tcgetattr(STDIN_FILENO, &tty); |
524 | 552 | |
525 | - sStatment* statment = runinfo->mStatment; | |
526 | 553 | char title[BUFSIZ]; |
527 | - title[0] = 0; | |
528 | - int i; | |
529 | - for(i=0; i<statment->mCommandsNum; i++) { | |
530 | - xstrncat(title, statment->mCommands[i].mArgsRuntime[0], BUFSIZ); | |
531 | - xstrncat(title, " ", BUFSIZ); | |
532 | - } | |
554 | + make_job_title(runinfo->mStatment, runinfo->mCommand, title, BUFSIZ); | |
555 | + | |
533 | 556 | sObject* job = JOB_NEW_GC(title, pid, tty); |
534 | 557 | } |
535 | 558 |
@@ -586,14 +609,9 @@ static BOOL wait_child_program(pid_t pid, pid_t nextin_reader_pid, int nextout2, | ||
586 | 609 | struct termios tty; |
587 | 610 | tcgetattr(STDIN_FILENO, &tty); |
588 | 611 | |
589 | - sStatment* statment = runinfo->mStatment; | |
590 | 612 | char title[BUFSIZ]; |
591 | - title[0] = 0; | |
592 | - int i; | |
593 | - for(i=0; i<statment->mCommandsNum; i++) { | |
594 | - xstrncat(title, statment->mCommands[i].mArgsRuntime[0], BUFSIZ); | |
595 | - xstrncat(title, " ", BUFSIZ); | |
596 | - } | |
613 | + make_job_title(runinfo->mStatment, runinfo->mCommand, title, BUFSIZ); | |
614 | + | |
597 | 615 | sObject* job = JOB_NEW_GC(title, pid, tty); |
598 | 616 | } |
599 | 617 |
@@ -1152,6 +1170,15 @@ static void redirect_finish(int opend_fd) | ||
1152 | 1170 | |
1153 | 1171 | static BOOL statment_tree(sStatment* statment, sObject* pipein, sObject* pipeout, sRunInfo* runinfo, sObject* current_object) |
1154 | 1172 | { |
1173 | + /// error check /// | |
1174 | + if(statment->mFlags & STATMENT_BACKGROUND) { | |
1175 | + if(gAppType == kATOptC) { | |
1176 | + err_msg("can't make a job background on script mode. you can make a job background on interactive shell", runinfo->mSName, runinfo->mSLine, NULL); | |
1177 | + return FALSE; | |
1178 | + } | |
1179 | + } | |
1180 | + | |
1181 | + /// head of statment /// | |
1155 | 1182 | sObject* nextin; |
1156 | 1183 | if(statment->mFlags & STATMENT_CONTEXTPIPE) { |
1157 | 1184 | /// read stdin /// |
@@ -1218,6 +1245,7 @@ static BOOL statment_tree(sStatment* statment, sObject* pipein, sObject* pipeout | ||
1218 | 1245 | nextin = pipein; |
1219 | 1246 | } |
1220 | 1247 | |
1248 | + /// command loop /// | |
1221 | 1249 | int i; |
1222 | 1250 | for(i=0; i<statment->mCommandsNum; i++) { |
1223 | 1251 | sCommand* command = runinfo->mCommand = statment->mCommands + i; |
@@ -1409,7 +1437,6 @@ static BOOL statment_tree(sStatment* statment, sObject* pipein, sObject* pipeout | ||
1409 | 1437 | } |
1410 | 1438 | } |
1411 | 1439 | } |
1412 | - sCommand_sweep_runtime_info(command); | |
1413 | 1440 | } |
1414 | 1441 | |
1415 | 1442 | if(opened_fd != -1) redirect_finish(opened_fd); |
@@ -1422,6 +1449,8 @@ static BOOL statment_tree(sStatment* statment, sObject* pipein, sObject* pipeout | ||
1422 | 1449 | } |
1423 | 1450 | } |
1424 | 1451 | |
1452 | + sStatment_sweep_runtime_info(statment); | |
1453 | + | |
1425 | 1454 | /// reverse the return code /// |
1426 | 1455 | if(statment->mFlags & STATMENT_REVERSE) { |
1427 | 1456 | runinfo->mRCode = !runinfo->mRCode; |
@@ -112,7 +112,7 @@ static void xyzsh_read_rc() | ||
112 | 112 | |
113 | 113 | void xyzsh_init(enum eAppType app_type, BOOL no_runtime_script) |
114 | 114 | { |
115 | - setenv("XYZSH_VERSION", "1.1.8a", 1); | |
115 | + setenv("XYZSH_VERSION", "1.1.8b", 1); | |
116 | 116 | setenv("XYZSH_DATAROOTDIR", DATAROOTDIR, 1); |
117 | 117 | |
118 | 118 | stack_init(1);; |
@@ -764,6 +764,7 @@ BOOL sCommand_put_option_with_argument(sCommand* self, MANAGED char* key, MANAGE | ||
764 | 764 | BOOL sCommand_expand_env(sCommand* command, sObject* object, sObject* nextin, sObject* nextout, sRunInfo* runinfo); |
765 | 765 | BOOL sCommand_expand_env_redirect(sCommand* command, sObject* nextin, sRunInfo* runinfo); |
766 | 766 | void sCommand_sweep_runtime_info(sCommand* command); |
767 | +void sStatment_sweep_runtime_info(sStatment* self); | |
767 | 768 | |
768 | 769 | extern sObject* gMemChecker; |
769 | 770 |