シェルスクリプト言語xyzshのソースコード。
修訂 | b2dda1a4320e086b85b3633654b5f34203b686a1 (tree) |
---|---|
時間 | 2012-10-18 22:00:35 |
作者 | ab25q <ab25cq@gmai...> |
Commiter | ab25q |
v1.0.9b release
@@ -2,6 +2,18 @@ | ||
2 | 2 | 2012 18th Octorber version 1.0.9b |
3 | 3 | |
4 | 4 | fixed break in while loop bug |
5 | + fixed output pipe bug | |
6 | + | |
7 | + > (print aaa\n; print bbb\n > b; print ccc\n ) > a | |
8 | + | |
9 | + can be worked just as one intended | |
10 | + | |
11 | + > cat a | |
12 | + aaa | |
13 | + ccc | |
14 | + | |
15 | + > cat b | |
16 | + bbb | |
5 | 17 | |
6 | 18 | 2012 17th Octorber version 1.0.9a |
7 | 19 |
@@ -1269,7 +1269,7 @@ BOOL sCommand_expand_env(sCommand* command, sObject* fun, sObject* nextin, sObje | ||
1269 | 1269 | return TRUE; |
1270 | 1270 | } |
1271 | 1271 | |
1272 | -BOOL sCommand_expand_env_redirect(sCommand* command, sObject* nextin, sObject* nextout, sRunInfo* runinfo) | |
1272 | +BOOL sCommand_expand_env_redirect(sCommand* command, sObject* nextin, sRunInfo* runinfo) | |
1273 | 1273 | { |
1274 | 1274 | if(command->mRedirectsNum > 0) { |
1275 | 1275 | command->mRedirectsFileNamesRuntime = MALLOC(sizeof(char*)*command->mRedirectsNum); |
@@ -66,19 +66,15 @@ static BOOL entry_fun(sObject* nextin, sObject* nextout, sRunInfo* runinfo, sObj | ||
66 | 66 | if(sCommand_option_item(command, "-inherit")) { |
67 | 67 | sObject* parent = hash_item(object, command->mArgsRuntime[1]); |
68 | 68 | if(parent) { |
69 | -/* | |
70 | - if(SFUN(parent).mParentCount > XYZSH_INHERIT_MAX) { | |
71 | - err_msg("can't inherit a parent function because of a parent function number limit", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
72 | - return FALSE; | |
69 | + if(type == T_FUN && (TYPE(parent) == T_FUN || TYPE(parent) == T_NFUN) | |
70 | + || type == T_CLASS && TYPE(parent) == T_CLASS) | |
71 | + { | |
72 | + SFUN(block).mParent = parent; | |
73 | 73 | } |
74 | -*/ | |
75 | - if(type == T_CLASS && (TYPE(parent) == T_FUN || TYPE(parent) == T_NFUN) || type == T_FUN && TYPE(parent) == T_CLASS) { | |
74 | + else { | |
76 | 75 | err_msg("can't inherit a parent function beacuse of the different type", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); |
77 | 76 | return FALSE; |
78 | 77 | } |
79 | - | |
80 | - SFUN(block).mParent = parent; | |
81 | -// SFUN(block).mParentCount = SFUN(parent).mParentCount + 1; | |
82 | 78 | } |
83 | 79 | else { |
84 | 80 | err_msg("can't inherit. There is not a parent", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); |
@@ -467,6 +463,14 @@ BOOL cmd_var(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
467 | 463 | int i; |
468 | 464 | int max = vector_count(SFD(nextin).fdbuf.mLines); |
469 | 465 | for(i=1; i<command->mArgsNumRuntime; i++) { |
466 | + sObject* current = runinfo->mCurrentObject; | |
467 | + sObject* tmp = access_object3(command->mArgsRuntime[i], ¤t); | |
468 | + | |
469 | + if(tmp && !sCommand_option_item(command, "-force")) { | |
470 | + err_msg("can't overwrite other the same name variable. Use -force option", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
471 | + return FALSE; | |
472 | + } | |
473 | + | |
470 | 474 | if(i-1 < max) { |
471 | 475 | sObject* new_var = STRING_NEW_GC(vector_item(SFD(nextin).fdbuf.mLines, i-1), TRUE); |
472 | 476 | string_chomp(new_var); |
@@ -951,6 +955,15 @@ BOOL cmd_ary(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
951 | 955 | int i; |
952 | 956 | int max = vector_count(SFD(nextin).fdbuf.mLines); |
953 | 957 | sObject* new_ary = VECTOR_NEW_GC(16, TRUE); |
958 | + | |
959 | + sObject* current = runinfo->mCurrentObject; | |
960 | + sObject* tmp = access_object3(command->mArgsRuntime[1], ¤t); | |
961 | + | |
962 | + if(tmp && !sCommand_option_item(command, "-force")) { | |
963 | + err_msg("can't overwrite other the same name variable. Use -force option", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
964 | + return FALSE; | |
965 | + } | |
966 | + | |
954 | 967 | hash_put(object, command->mArgsRuntime[1], new_ary); |
955 | 968 | for(i=0; i<max; i++) { |
956 | 969 | sObject* new_var = STRING_NEW_GC(vector_item(SFD(nextin).fdbuf.mLines, i), FALSE); |
@@ -1150,6 +1163,15 @@ BOOL cmd_hash(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1150 | 1163 | int i; |
1151 | 1164 | int max = vector_count(SFD(nextin).fdbuf.mLines); |
1152 | 1165 | sObject* new_hash = HASH_NEW_GC(16, TRUE); |
1166 | + | |
1167 | + sObject* current = runinfo->mCurrentObject; | |
1168 | + sObject* tmp = access_object3(command->mArgsRuntime[1], ¤t); | |
1169 | + | |
1170 | + if(tmp && !sCommand_option_item(command, "-force")) { | |
1171 | + err_msg("can't overwrite other the same name variable. Use -force option", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
1172 | + return FALSE; | |
1173 | + } | |
1174 | + | |
1153 | 1175 | hash_put(object, command->mArgsRuntime[1], new_hash); |
1154 | 1176 | sObject* key = STRING_NEW_STACK(""); |
1155 | 1177 | for(i=0; i<max; i++) { |
@@ -124,33 +124,6 @@ BOOL bufsiz_write(int fd, char* buf, int buf_size) | ||
124 | 124 | return TRUE; |
125 | 125 | } |
126 | 126 | |
127 | -// TRUE: Success | |
128 | -// FALSE: signal interrupt. set RCODE_SIGNAL_INTERRUPT on rcode and err message | |
129 | -/* | |
130 | -BOOL globalin_read(sObject* self, sObject* out, unsigned int line_number, enum eLineField lf) | |
131 | -{ | |
132 | - assert(TYPE(self) == T_FD && SFD(self).mKind == kFDKindBuf); | |
133 | - assert(TYPE(out) == T_FD && SFD(out).mKind == kFDKindBuf); | |
134 | - | |
135 | - fd_split(self, lf); | |
136 | - | |
137 | - if(line_number == 0) line_number = vector_count(SFD(self).fdbuf.mLines); | |
138 | - | |
139 | - int i; | |
140 | - for(i=gGlobalPipeInReadNumber; i < vector_count(SFD(self).fdbuf.mLines) && i < line_number+gGlobalPipeInReadNumber; i++) { | |
141 | - char* line = vector_item(SFD(self).fdbuf.mLines, i); | |
142 | - | |
143 | - if(!fd_write(out, line, strlen(line))) { | |
144 | - return FALSE; | |
145 | - } | |
146 | - } | |
147 | - | |
148 | - gGlobalPipeInReadNumber += line_number; | |
149 | - | |
150 | - return TRUE; | |
151 | -} | |
152 | -*/ | |
153 | - | |
154 | 127 | void fd_split(sObject* self, enum eLineField lf) |
155 | 128 | { |
156 | 129 | assert(TYPE(self) == T_FD && SFD(self).mKind == kFDKindBuf); |
@@ -1124,7 +1097,7 @@ static BOOL redirect_ready(sObject** nextout, sObject** nextin, int* opened_fd, | ||
1124 | 1097 | break; |
1125 | 1098 | |
1126 | 1099 | case REDIRECT_APPEND: |
1127 | - if(SFD(*nextout).mKind == kFDKindBuf) { | |
1100 | + if(*nextout == NULL) { | |
1128 | 1101 | fd = open(command->mRedirectsFileNamesRuntime[i], O_WRONLY|O_APPEND|O_CREAT, 0644); |
1129 | 1102 | if(fd < 0) { |
1130 | 1103 | char buf[BUFSIZ]; |
@@ -1139,7 +1112,7 @@ static BOOL redirect_ready(sObject** nextout, sObject** nextin, int* opened_fd, | ||
1139 | 1112 | break; |
1140 | 1113 | |
1141 | 1114 | case REDIRECT_OUT: |
1142 | - if(SFD(*nextout).mKind == kFDKindBuf) { | |
1115 | + if(*nextout == NULL) { | |
1143 | 1116 | fd = open(command->mRedirectsFileNamesRuntime[i], O_WRONLY|O_CREAT|O_TRUNC, 0644); |
1144 | 1117 | if(fd < 0) { |
1145 | 1118 | char buf[BUFSIZ]; |
@@ -1239,30 +1212,33 @@ static BOOL statment_tree(sStatment* statment, sObject* pipein, sObject* pipeout | ||
1239 | 1212 | const BOOL last_program = runinfo->mLastProgram = i == statment->mCommandsNum-1; |
1240 | 1213 | runinfo->mFilter = i != 0 || (statment->mFlags & (STATMENT_CONTEXTPIPE|STATMENT_GLOBALPIPEIN)); |
1241 | 1214 | |
1242 | - sObject* nextout; | |
1243 | - if(last_program) { | |
1244 | - if(statment->mFlags & STATMENT_GLOBALPIPEOUT) { | |
1245 | - fd_clear(gGlobalPipe); | |
1246 | - nextout = gGlobalPipe; | |
1247 | - } | |
1248 | - else { | |
1249 | - nextout = pipeout; | |
1250 | - } | |
1251 | - } | |
1252 | - else { | |
1253 | - nextout = FD_NEW_STACK(kFDKindBuf, 0); | |
1254 | - } | |
1255 | - | |
1256 | 1215 | /// expand env /// |
1257 | - if(!sCommand_expand_env_redirect(command, nextin, nextout, runinfo)) | |
1216 | + if(!sCommand_expand_env_redirect(command, nextin, runinfo)) | |
1258 | 1217 | { |
1259 | 1218 | return FALSE; |
1260 | 1219 | } |
1261 | 1220 | |
1221 | + sObject* nextout = NULL; | |
1222 | + | |
1262 | 1223 | int opened_fd = -1; |
1263 | 1224 | if(!redirect_ready(&nextout, &nextin, &opened_fd, pipeout, last_program, statment, command, runinfo)) { |
1264 | 1225 | return TRUE; |
1265 | 1226 | } |
1227 | + | |
1228 | + if(nextout == NULL) { | |
1229 | + if(last_program) { | |
1230 | + if(statment->mFlags & STATMENT_GLOBALPIPEOUT) { | |
1231 | + fd_clear(gGlobalPipe); | |
1232 | + nextout = gGlobalPipe; | |
1233 | + } | |
1234 | + else { | |
1235 | + nextout = pipeout; | |
1236 | + } | |
1237 | + } | |
1238 | + else { | |
1239 | + nextout = FD_NEW_STACK(kFDKindBuf, 0); | |
1240 | + } | |
1241 | + } | |
1266 | 1242 | |
1267 | 1243 | if(command->mArgsNum > 0) { |
1268 | 1244 | if(command->mArgsEnv[0]) { |
@@ -741,7 +741,7 @@ char* sCommand_option_with_argument_item(sCommand* self, char* key); | ||
741 | 741 | BOOL sCommand_put_option(sCommand* self, MANAGED char* key); |
742 | 742 | BOOL sCommand_put_option_with_argument(sCommand* self, MANAGED char* key, MANAGED char* argument); |
743 | 743 | BOOL sCommand_expand_env(sCommand* command, sObject* object, sObject* nextin, sObject* nextout, sRunInfo* runinfo); |
744 | -BOOL sCommand_expand_env_redirect(sCommand* command, sObject* nextin, sObject* nextout, sRunInfo* runinfo); | |
744 | +BOOL sCommand_expand_env_redirect(sCommand* command, sObject* nextin, sRunInfo* runinfo); | |
745 | 745 | void sCommand_sweep_runtime_info(sCommand* command); |
746 | 746 | |
747 | 747 | extern sObject* gMemChecker; |
@@ -13,7 +13,7 @@ print ~/.xyzsh | if(| -e) ( | ||
13 | 13 | print 1000 | export XYZSH_HISTSIZE |
14 | 14 | print ~/.xyzsh/history | export XYZSH_HISTFILE |
15 | 15 | |
16 | -print "diff seq env sleep ps kill killall pkill autoconf automake od nm gcc uname chgrp chmod chown sed awk make git ssh scp tar sudo gzip bash cat ls pwd cp mv rm rmdir ln vi vim grep egrep find less wc echo which whoami head tail uniq mkdir touch man" | split | each ( | |
16 | +print "find unzip diff seq env sleep ps kill killall pkill autoconf automake od nm gcc uname chgrp chmod chown sed awk make git ssh scp tar sudo gzip bash cat ls pwd cp mv rm rmdir ln vi vim grep egrep find less wc echo which whoami head tail uniq mkdir touch man" | split | each ( | |
17 | 17 | | chomp | var -local prog |
18 | 18 | |
19 | 19 | try ( sys::run ( root::ref $prog ) | ref $prog) catch () |