シェルスクリプト言語xyzshのソースコード。
修订版 | 7945bde3b31e90d7d14a38ae8b70f4c90dae8ba5 (tree) |
---|---|
时间 | 2012-10-28 00:25:08 |
作者 | ab25q <ab25cq@gmai...> |
Commiter | ab25q |
v1.1.2 release
@@ -1,4 +1,9 @@ | ||
1 | 1 | |
2 | +2012 28th Octorber version 1.1.2 | |
3 | + | |
4 | + add function with running completion block to "completion" inner command. | |
5 | + fixed sudo completion. you can use completion to type after sudo. | |
6 | + | |
2 | 7 | 2012 18th Octorber version 1.1.1 |
3 | 8 | |
4 | 9 | add "defined" inner command. see help |
@@ -99,15 +99,16 @@ completion man ( | ||
99 | 99 | program_completion |
100 | 100 | ) |
101 | 101 | |
102 | -def get_input_num ( | |
103 | - | split '(?<!\\) +' | wc -l | |
104 | -) | |
105 | - | |
106 | 102 | completion sudo ( |
107 | - | scan 'sudo .*' | chomp| get_input_num | var -local input_num | |
103 | + | scan 'sudo .*' | chomp | split '(?<!\\) +' | wc -l | var -local input_num | |
104 | + | scan 'sudo .*' | chomp | split '(?<!\\) +' | lines 1 (|print) | var -local program_name | |
108 | 105 | |
109 | 106 | if(input_num | -eq 2) ( |
110 | 107 | program_completion |
108 | + ) elif(input_num | -ge 3 && program_name |chomp| != sudo) ( | |
109 | + try ( | |
110 | + completion $program_name | |
111 | + ) catch () | |
111 | 112 | ) |
112 | 113 | ) |
113 | 114 |
@@ -632,52 +632,131 @@ BOOL cmd_completion(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
632 | 632 | { |
633 | 633 | sCommand* command = runinfo->mCommand; |
634 | 634 | |
635 | - if(command->mArgsNumRuntime >= 2 && command->mBlocksNum == 1) { | |
636 | - sObject* block = command->mBlocks[0]; | |
635 | + if(command->mArgsNumRuntime >= 2) { | |
636 | + if(command->mBlocksNum == 1) { | |
637 | + sObject* block = command->mBlocks[0]; | |
637 | 638 | |
638 | - int i; | |
639 | - for(i=1; i<command->mArgsNumRuntime; i++) { | |
640 | - sObject* object = gCompletionObject; | |
641 | - | |
642 | - sObject* str = STRING_NEW_GC("", FALSE); | |
643 | - char* p = command->mArgsRuntime[i]; | |
644 | - while(*p) { | |
645 | - if(*p == ':' && *(p+1) == ':') { | |
646 | - if(string_c_str(str)[0] == 0) { | |
647 | - err_msg("invalid object name", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
648 | - return FALSE; | |
649 | - } | |
650 | - p+=2; | |
639 | + int i; | |
640 | + for(i=1; i<command->mArgsNumRuntime; i++) { | |
641 | + sObject* object = gCompletionObject; | |
642 | + | |
643 | + sObject* str = STRING_NEW_GC("", FALSE); | |
644 | + char* p = command->mArgsRuntime[i]; | |
645 | + while(*p) { | |
646 | + if(*p == ':' && *(p+1) == ':') { | |
647 | + if(string_c_str(str)[0] == 0) { | |
648 | + err_msg("invalid object name", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
649 | + return FALSE; | |
650 | + } | |
651 | + p+=2; | |
651 | 652 | |
652 | - sObject* object2 = uobject_item(object, string_c_str(str)); | |
653 | - if(object2 == NULL || TYPE(object2) !=T_UOBJECT) { | |
654 | - sObject* new_object = UOBJECT_NEW_GC(8, object, string_c_str(str), TRUE); | |
655 | - uobject_put(object, string_c_str(str), new_object); | |
656 | - uobject_init(new_object); | |
653 | + sObject* object2 = uobject_item(object, string_c_str(str)); | |
654 | + if(object2 == NULL || TYPE(object2) !=T_UOBJECT) { | |
655 | + sObject* new_object = UOBJECT_NEW_GC(8, object, string_c_str(str), TRUE); | |
656 | + uobject_put(object, string_c_str(str), new_object); | |
657 | + uobject_init(new_object); | |
657 | 658 | |
658 | - object = new_object; | |
659 | + object = new_object; | |
660 | + } | |
661 | + else { | |
662 | + object = object2; | |
663 | + } | |
664 | + string_put(str, ""); | |
659 | 665 | } |
660 | 666 | else { |
661 | - object = object2; | |
667 | + string_push_back2(str, *p); | |
668 | + p++; | |
662 | 669 | } |
663 | - string_put(str, ""); | |
670 | + } | |
671 | + if(object && TYPE(object) == T_UOBJECT && string_c_str(str)[0] != 0) { | |
672 | + uobject_put(object, string_c_str(str), COMPLETION_NEW_GC(block, FALSE)); | |
664 | 673 | } |
665 | 674 | else { |
666 | - string_push_back2(str, *p); | |
667 | - p++; | |
675 | + err_msg("There is no object", runinfo->mSName, runinfo->mSLine, command->mArgsRuntime[i]); | |
676 | + | |
677 | + return FALSE; | |
668 | 678 | } |
669 | 679 | } |
670 | - if(object && TYPE(object) == T_UOBJECT && string_c_str(str)[0] != 0) { | |
671 | - uobject_put(object, string_c_str(str), COMPLETION_NEW_GC(block, FALSE)); | |
672 | - } | |
673 | - else { | |
674 | - err_msg("There is no object", runinfo->mSName, runinfo->mSLine, command->mArgsRuntime[i]); | |
675 | 680 | |
676 | - return FALSE; | |
677 | - } | |
681 | + runinfo->mRCode = 0; | |
678 | 682 | } |
683 | + else if(command->mBlocksNum == 0) { | |
684 | + int i; | |
685 | + for(i=1; i<command->mArgsNumRuntime; i++) { | |
686 | + sObject* object = gCompletionObject; | |
687 | + | |
688 | + sObject* str = STRING_NEW_GC("", FALSE); | |
689 | + char* p = command->mArgsRuntime[i]; | |
690 | + while(*p) { | |
691 | + if(*p == ':' && *(p+1) == ':') { | |
692 | + if(string_c_str(str)[0] == 0) { | |
693 | + err_msg("invalid object name", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
694 | + return FALSE; | |
695 | + } | |
696 | + p+=2; | |
679 | 697 | |
680 | - runinfo->mRCode = 0; | |
698 | + sObject* object2 = uobject_item(object, string_c_str(str)); | |
699 | + if(object2 == NULL || TYPE(object2) !=T_UOBJECT) { | |
700 | + sObject* new_object = UOBJECT_NEW_GC(8, object, string_c_str(str), TRUE); | |
701 | + uobject_put(object, string_c_str(str), new_object); | |
702 | + uobject_init(new_object); | |
703 | + | |
704 | + object = new_object; | |
705 | + } | |
706 | + else { | |
707 | + object = object2; | |
708 | + } | |
709 | + string_put(str, ""); | |
710 | + } | |
711 | + else { | |
712 | + string_push_back2(str, *p); | |
713 | + p++; | |
714 | + } | |
715 | + } | |
716 | + if(object && TYPE(object) == T_UOBJECT && string_c_str(str)[0] != 0) { | |
717 | + sObject* completion = uobject_item(object, string_c_str(str)); | |
718 | + if(completion) { | |
719 | + stack_start_stack(); | |
720 | + | |
721 | + sObject* fun = FUN_NEW_STACK(NULL); | |
722 | + sObject* stackframe = UOBJECT_NEW_GC(8, gxyzshObject, "_stackframe", FALSE); | |
723 | + vector_add(gStackFrames, stackframe); | |
724 | + //uobject_init(stackframe); | |
725 | + SFUN(fun).mLocalObjects = stackframe; | |
726 | + | |
727 | + xyzsh_set_signal(); | |
728 | + int rcode = 0; | |
729 | + if(!run(SCOMPLETION(completion).mBlock, nextin, nextout, &rcode, gRootObject, fun)) { | |
730 | + if(rcode == RCODE_BREAK) { | |
731 | + } | |
732 | + else if(rcode == RCODE_RETURN) { | |
733 | + } | |
734 | + else if(rcode == RCODE_EXIT) { | |
735 | + } | |
736 | + else { | |
737 | + fprintf(stderr, "run time error\n"); | |
738 | + fprintf(stderr, "%s", string_c_str(gErrMsg)); | |
739 | + } | |
740 | + } | |
741 | + (void)vector_pop_back(gStackFrames); | |
742 | + readline_signal(); | |
743 | + stack_end_stack(); | |
744 | + } | |
745 | + else { | |
746 | + err_msg("There is no object", runinfo->mSName, runinfo->mSLine, command->mArgsRuntime[i]); | |
747 | + | |
748 | + return FALSE; | |
749 | + } | |
750 | + } | |
751 | + else { | |
752 | + err_msg("There is no object", runinfo->mSName, runinfo->mSLine, command->mArgsRuntime[i]); | |
753 | + | |
754 | + return FALSE; | |
755 | + } | |
756 | + } | |
757 | + | |
758 | + runinfo->mRCode = 0; | |
759 | + } | |
681 | 760 | } |
682 | 761 | |
683 | 762 | return TRUE; |
@@ -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.1", 1); | |
115 | + setenv("XYZSH_VERSION", "1.1.2", 1); | |
116 | 116 | setenv("XYZSH_DATAROOTDIR", DATAROOTDIR, 1); |
117 | 117 | |
118 | 118 | stack_init(1);; |