シェルスクリプト言語xyzshのソースコード。
修订版 | b56bf79aa8302b6c0b2629b8024c52d0366c4eb0 (tree) |
---|---|
时间 | 2013-01-31 22:03:37 |
作者 | ab25cq <ab25cq@gmai...> |
Commiter | ab25cq |
1.3.3
@@ -0,0 +1,5 @@ | ||
1 | +object a | |
2 | +co a | |
3 | + | |
4 | +pwo | |
5 | +self |
@@ -1,4 +1,3 @@ | ||
1 | - | |
2 | 1 | print "welcome to migemo.so dynamic library. You can read help type with \"migemo::help 'command name'\""\n |
3 | 2 | |
4 | 3 | compl::run( root::object migemo ) |
@@ -27,125 +26,126 @@ Compare migemo querry with input from pipe data and output the string ranges. | ||
27 | 26 | EOS | help::set_helps |
28 | 27 | ) |
29 | 28 | |
30 | -class MigemoCompletion ( | |
31 | - def common_head ( | |
32 | - | each ( | |
33 | - | chomp| length -utf8 | |
34 | - ) | max | var -local max_length | |
29 | +root::run( | |
30 | + class MigemoCompletion ( | |
31 | + def common_head ( | |
32 | + | each ( | |
33 | + | chomp| length -utf8 | |
34 | + ) | max | var -local max_length | |
35 | 35 | |
36 | - print 0 | var -local point | |
36 | + print 0 | var -local point | |
37 | 37 | |
38 | - while(true) ( | |
39 | - | each ( | |
40 | - | chomp | rows -utf8 0..$point | pomch | |
41 | - ) | sys::sort | uniq | length -line-num | strip | if(| != 1) ( | |
42 | - -- point; | |
43 | - break | |
44 | - ) | |
38 | + while(true) ( | |
39 | + | each ( | |
40 | + | chomp | rows -utf8 0..$point | pomch | |
41 | + ) | sys::sort | uniq | length -line-num | strip | if(| != 1) ( | |
42 | + -- point; | |
43 | + break | |
44 | + ) | |
45 | 45 | |
46 | - ++ point; | |
46 | + ++ point; | |
47 | 47 | |
48 | - if(point | -ge $max_length) ( | |
49 | - -- point | |
50 | - break | |
48 | + if(point | -ge $max_length) ( | |
49 | + -- point | |
50 | + break | |
51 | + ) | |
51 | 52 | ) |
52 | - ) | |
53 | 53 | |
54 | - if(point | -ne -1) ( | |
55 | - | rows -utf8 0..$point | |
54 | + if(point | -ne -1) ( | |
55 | + | rows -utf8 0..$point | |
56 | + ) | |
56 | 57 | ) |
57 | - ) | |
58 | 58 | |
59 | - def is_all_ascii ( | |
60 | - | length -byte | var -local LEN | |
59 | + def is_all_ascii ( | |
60 | + | length -byte | var -local LEN | |
61 | 61 | |
62 | - LEN | -eq $(| length -utf8) | |
63 | - ) | |
64 | - | |
65 | - def migemo_file_completion ( | |
66 | - print $ARGV[0] | var -local inputing | |
67 | - print $ARGV[1] | var -local editing_line | |
68 | - | |
69 | - | each ( | |
70 | - if (inputing | =~ '.*\/[a-zA-Z]+$') ( | |
71 | - | if(|=~ '.*\/[a-zA-Z]+[^a-zA-z/]+$') ( | |
72 | - (inputing; |print) | common_head | var -local same_head | |
62 | + LEN | -eq $(| length -utf8) | |
63 | + ) | |
73 | 64 | |
74 | - same_head | var -local no_migemo_string | |
75 | - inputing | sub -no-regex $same_head '' | var -local migemo_string | |
76 | - ) else ( | |
77 | - inputing | sub '(.*\/)[a-zA-Z]+$' '\1' | var -local no_migemo_string | |
78 | - inputing | sub '.*\/([a-zA-Z]+)$' '\1' | var -local migemo_string | |
79 | - ) | |
80 | - ) elif (inputing | =~ '.*\/[^a-zA-Z]+[a-zA-Z]+$') ( | |
81 | - inputing | sub '(.*\/[^a-zA-Z]+)[a-zA-Z]+$' '\1' | var -local no_migemo_string | |
82 | - inputing | sub '.*\/[^a-zA-Z]+([a-zA-Z]+)$' '\1' | var -local migemo_string | |
83 | - ) elif (inputing | =~ '[a-zA-Z]+$') ( | |
84 | - | if(|=~ '[a-zA-Z]+[^a-zA-z/]+$') ( | |
85 | - (inputing; |print) | common_head | var -local same_head | |
86 | - | |
87 | - same_head | var -local no_migemo_string | |
88 | - inputing | sub -no-regex $same_head '' | var -local migemo_string | |
65 | + def migemo_file_completion ( | |
66 | + print $ARGV[0] | var -local inputing | |
67 | + print $ARGV[1] | var -local editing_line | |
68 | + | |
69 | + | each ( | |
70 | + if (inputing | =~ '.*\/[a-zA-Z]+$') ( | |
71 | + | if(|=~ '.*\/[a-zA-Z]+[^a-zA-z/]+$') ( | |
72 | + (inputing; |print) | common_head | var -local same_head | |
73 | + | |
74 | + same_head | var -local no_migemo_string | |
75 | + inputing | sub -no-regex $same_head '' | var -local migemo_string | |
76 | + ) else ( | |
77 | + inputing | sub '(.*\/)[a-zA-Z]+$' '\1' | var -local no_migemo_string | |
78 | + inputing | sub '.*\/([a-zA-Z]+)$' '\1' | var -local migemo_string | |
79 | + ) | |
80 | + ) elif (inputing | =~ '.*\/[^a-zA-Z]+[a-zA-Z]+$') ( | |
81 | + inputing | sub '(.*\/[^a-zA-Z]+)[a-zA-Z]+$' '\1' | var -local no_migemo_string | |
82 | + inputing | sub '.*\/[^a-zA-Z]+([a-zA-Z]+)$' '\1' | var -local migemo_string | |
83 | + ) elif (inputing | =~ '[a-zA-Z]+$') ( | |
84 | + | if(|=~ '[a-zA-Z]+[^a-zA-z/]+$') ( | |
85 | + (inputing; |print) | common_head | var -local same_head | |
86 | + | |
87 | + same_head | var -local no_migemo_string | |
88 | + inputing | sub -no-regex $same_head '' | var -local migemo_string | |
89 | + ) else ( | |
90 | + print "" | var -local no_migemo_string | |
91 | + inputing | var -local migemo_string | |
92 | + ) | |
93 | + ) elif (inputing | =~ '[^a-zA-Z]+[a-zA-Z]+$') ( | |
94 | + inputing | sub '([^a-zA-Z]+)[a-zA-Z]+$' '\1' | var -local no_migemo_string | |
95 | + inputing | sub '[^a-zA-Z]+([a-zA-Z]+)$' '\1' | var -local migemo_string | |
89 | 96 | ) else ( |
90 | 97 | print "" | var -local no_migemo_string |
91 | - inputing | var -local migemo_string | |
98 | + print "" | var -local migemo_string | |
92 | 99 | ) |
93 | - ) elif (inputing | =~ '[^a-zA-Z]+[a-zA-Z]+$') ( | |
94 | - inputing | sub '([^a-zA-Z]+)[a-zA-Z]+$' '\1' | var -local no_migemo_string | |
95 | - inputing | sub '[^a-zA-Z]+([a-zA-Z]+)$' '\1' | var -local migemo_string | |
96 | - ) else ( | |
97 | - print "" | var -local no_migemo_string | |
98 | - print "" | var -local migemo_string | |
99 | - ) | |
100 | 100 | |
101 | - | if(| sub -no-regex $no_migemo_string '' | chomp | migemo::match $migemo_string | lines 0 | = 0\n) ( | |
102 | ||
103 | - ) | |
104 | - ) | (| common_head | var -local COMMON_HEAD; | length -line-num | var -local NUM) | |
101 | + | if(| sub -no-regex $no_migemo_string '' | chomp | migemo::match $migemo_string | lines 0 | = 0\n) ( | |
102 | ||
103 | + ) | |
104 | + ) | (| common_head | var -local COMMON_HEAD; | length -line-num | var -local NUM) | |
105 | 105 | |
106 | - if(COMMON_HEAD | chomp | -n && COMMON_HEAD | length | -gt $(inputing | length)) ( | |
107 | - rl::delete_text $(editing_line | rindex $inputing) $(rl::point) | |
108 | - rl::insert_text $COMMON_HEAD | |
109 | - if(NUM | chomp | -eq 1 && COMMON_HEAD| chomp | rows -1 | != /) ( rl::insert_text " " ) | |
110 | - ) | |
111 | - ) | |
106 | + if(COMMON_HEAD | chomp | -n && COMMON_HEAD | length | -gt $(inputing | length)) ( | |
107 | + rl::delete_text $(editing_line | rindex $inputing) $(rl::point) | |
108 | + rl::insert_text $COMMON_HEAD | |
109 | + if(NUM | chomp | -eq 1 && COMMON_HEAD| chomp | rows -1 | != /) ( rl::insert_text " " ) | |
110 | + ) | |
111 | + ) | |
112 | 112 | |
113 | - def file_completion ( | |
114 | - | split '(?<!\\) +' | lines -1 | var -local inputing | |
113 | + def file_completion ( | |
114 | + | split '(?<!\\) +' | lines -1 | var -local inputing | |
115 | 115 | |
116 | - if(inputing | index -quiet /) ( | |
117 | - sys::dirname $(inputing|chomp| if (|rows -1 | = /) ( |add aaa ) else ( | print ) ) | var -local DIR | |
116 | + if(inputing | index -quiet /) ( | |
117 | + sys::dirname $(inputing|chomp| if (|rows -1 | = /) ( |add aaa ) else ( | print ) ) | var -local DIR | |
118 | 118 | |
119 | - ls $(DIR|xyzsh_dequote|chomp) | each ( | |
120 | - | if (|chomp | add -number 0 $(DIR|xyzsh_dequote|chomp)/ | -d) ( | |
121 | - |chomp | xyzsh_quote | add -number 0 $DIR/ | add / | pomch | |
122 | - ) else ( | |
123 | - |chomp | xyzsh_quote | add -number 0 $DIR/ | pomch | |
124 | - ) | |
125 | - ) | migemo_file_completion $inputing $(|print) | |
126 | - ) else ( | |
127 | - ls | each ( | |
128 | - | if (|chomp| -d) ( | |
129 | - | chomp | xyzsh_quote | add / | pomch | |
130 | - ) else ( | |
131 | - |chomp | xyzsh_quote| pomch | |
132 | - ) | |
133 | - ) | migemo_file_completion $inputing $(|print) | |
119 | + ls $(DIR|xyzsh_dequote|chomp) | each ( | |
120 | + | if (|chomp | add -number 0 $(DIR|xyzsh_dequote|chomp)/ | -d) ( | |
121 | + |chomp | xyzsh_quote | add -number 0 $DIR/ | add / | pomch | |
122 | + ) else ( | |
123 | + |chomp | xyzsh_quote | add -number 0 $DIR/ | pomch | |
124 | + ) | |
125 | + ) | migemo_file_completion $inputing $(|print) | |
126 | + ) else ( | |
127 | + ls | each ( | |
128 | + | if (|chomp| -d) ( | |
129 | + | chomp | xyzsh_quote | add / | pomch | |
130 | + ) else ( | |
131 | + |chomp | xyzsh_quote| pomch | |
132 | + ) | |
133 | + ) | migemo_file_completion $inputing $(|print) | |
134 | + ) | |
134 | 135 | ) |
135 | - ) | |
136 | 136 | |
137 | - completion __all__ ( | |
138 | - | file_completion | |
139 | - ) | |
137 | + completion __all__ ( | |
138 | + | file_completion | |
139 | + ) | |
140 | 140 | |
141 | - root::compl::run( root::object sys ) | |
141 | + root::compl::run( root::object sys ) | |
142 | 142 | |
143 | - completion sys::__all__ ( | |
144 | - | file_completion | |
143 | + completion sys::__all__ ( | |
144 | + | file_completion | |
145 | + ) | |
145 | 146 | ) |
146 | -) | |
147 | 147 | |
148 | -readline "Do you want to use migemo completion which is Japanese ROMAJI completion?(y/n)" | chomp | if(|=~ -ignore-case ^y) ( | |
149 | - MigemoCompletion | |
148 | + if(MIGEMO_COMPLETION_AUTO_LOAD | = 1\n || readline "Do you want to use migemo completion which is Japanese ROMAJI completion?(y/n)" | chomp |=~ -ignore-case ^y) ( | |
149 | + MigemoCompletion | |
150 | + ) | |
150 | 151 | ) |
151 | - |
@@ -1130,10 +1130,11 @@ static BOOL statment_tree(sStatment* statment, sObject* pipein, sObject* pipeout | ||
1130 | 1130 | for(i=0; i<statment->mCommandsNum; i++) { |
1131 | 1131 | sCommand* command = runinfo->mCommand = statment->mCommands + i; |
1132 | 1132 | |
1133 | - runinfo->mCurrentObject = current_object; | |
1134 | 1133 | const BOOL last_program = runinfo->mLastProgram = i == statment->mCommandsNum-1; |
1135 | 1134 | runinfo->mFilter = i != 0 || (statment->mFlags & (STATMENT_FLAGS_CONTEXT_PIPE|STATMENT_FLAGS_GLOBAL_PIPE_IN)); |
1136 | 1135 | |
1136 | + runinfo->mCurrentObject = current_object; | |
1137 | + | |
1137 | 1138 | sRunInfo_command_new(runinfo); |
1138 | 1139 | |
1139 | 1140 | /// expand env /// |
@@ -1798,9 +1799,10 @@ BOOL load_so_file(char* fname, sObject* nextin, sObject* nextout, sRunInfo* runi | ||
1798 | 1799 | |
1799 | 1800 | //dlclose(handle); |
1800 | 1801 | |
1801 | - snprintf(path, PATH_MAX, "%s.xyzsh", path); | |
1802 | - if(access(path, F_OK) == 0) { | |
1803 | - if(!load_file(path, nextin, nextout, runinfo, NULL, 0)) { | |
1802 | + char path2[PATH_MAX]; | |
1803 | + snprintf(path2, PATH_MAX, "%s.xyzsh", path); | |
1804 | + if(access(path2, F_OK) == 0) { | |
1805 | + if(!load_file(path2, nextin, nextout, runinfo, NULL, 0)) { | |
1804 | 1806 | return FALSE; |
1805 | 1807 | } |
1806 | 1808 | } |