Skip to content

Commit

Permalink
10.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ab25cq committed Mar 6, 2021
1 parent d8d1f71 commit adcee38
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 22 deletions.
48 changes: 33 additions & 15 deletions Command.clcl
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,14 @@ dynamic_class Command
}
}

def set_fl(fd:int, flags:int):static {
value := fcntl(fd, F_GETFL, 0);

value |= flags;

fcntl(fd, F_SETFL, value);
}

def executeCommandWithGettingStderr(method_name:String, params:List<String>, pipe_data:String?) : static Command throws Exception
{
child2parent_write_fd := 0;
Expand Down Expand Up @@ -657,23 +665,30 @@ dynamic_class Command
close(parent2child_write_fd);

child_output:Buffer = B"";

set_fl(child2parent_read_fd_err, O_NONBLOCK);

while(true) {
pipe_data := Buffer(8192.to_ulong);

readed_byte := read(child2parent_read_fd, pipe_data, 8192.to_ulong);

child_output.append(pipe_data);

pipe_data_err := Buffer(8192.to_ulong);

readed_byte_err := read(child2parent_read_fd_err, pipe_data_err, 8192.to_ulong);
readed_byte_err := 0;

child_output.append(pipe_data_err);
try {
readed_byte_err = read(child2parent_read_fd_err, pipe_data_err, 8192.to_ulong);
} catch(e:Exception) {
readed_byte_err = 0;
}

if(readed_byte == 0 && readed_byte_err == 0) {
if(readed_byte <= 0 && readed_byte_err <= 0) {
break;
}

child_output.append(pipe_data);
child_output.append(pipe_data_err);
}

close(child2parent_read_fd);
Expand Down Expand Up @@ -752,26 +767,29 @@ dynamic_class Command

child_output := B"";
child_output_error := B"";


set_fl(child2parent_read_fd_err, O_NONBLOCK);

while(true) {
pipe_data := Buffer(8192.to_ulong);
readed_byte := read(child2parent_read_fd, pipe_data, 8192.to_ulong);

if(readed_byte == 0) {
break;
}

/*
pipe_data_err := Buffer(8192.to_ulong);
readed_byte_err := read(child2parent_read_fd_err, pipe_data_err, 8192.to_ulong);

if(readed_byte == 0 && readed_byte_err == 0) {
readed_byte_err := 0;

try {
readed_byte_err = read(child2parent_read_fd_err, pipe_data_err, 8192.to_ulong);
} catch(e:Exception) {
readed_byte_err = 0;
}

if(readed_byte <= 0 && readed_byte_err <= 0) {
break;
}
*/

child_output.append(pipe_data);
# child_output_error.append(pipe_data_err);
child_output_error.append(pipe_data_err);
}

close(child2parent_read_fd);
Expand Down
5 changes: 5 additions & 0 deletions File.clcl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ inherit System

PATH_MAX: static int;

F_GETFL: static int;
F_SETFL: static int;

def initialize_file_system(): static native;

def initialize(): static {
Expand All @@ -106,6 +109,8 @@ inherit System
def read(fd:int, buf:Buffer, size:size_t): static native ssize_t throws Exception;
def write(fd:int, buf:Buffer, size:size_t): static native ssize_t throws Exception;

def fcntl(fd:int, flag:int, val:int): static native int throws Exception;

def time(): static native time_t;
def localtime(time:time_t, tm_sec:pointer@of_int, tm_min:pointer@of_int, tm_hour:pointer@of_int, tm_mday:pointer@of_int, tm_mon:pointer@of_int, tm_year:pointer@of_int, tm_wday:pointer@of_int, tm_yday:pointer@of_int, tm_isdst:pointer@of_bool): static native throws Exception;
def mktime(time:tm): static native time_t throws Exception;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

この言語はアプリケーションを作るタイプの言語ではないかもしれません。iclover2を使ってシェルとして使うといいと思います。

version 10.5.5
version 10.5.6

サポートしている機能

Expand Down
4 changes: 4 additions & 0 deletions manual/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
English page is here [>> English page](changelog-en)

version 10.5.6

Fixed getting command error bug.

version 10.5.5

Fixed shell mode bug. This can be runned. > neo\-c a.nc;
Expand Down
2 changes: 1 addition & 1 deletion manual/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ toBoolAndOutput()メソッドで出力を画面に表示しながら実行結果
/home/ab25cq
true

`write(path:STring, permission:mode_t):Command``write(path:String): Command` メソッドで出力をファイルに保存することができます。
`write(path:String, permission:mode_t):Command``write(path:String): Command` メソッドで出力をファイルに保存することができます。

> pwd().write("output_of_pwd")
/home/ab25cq
Expand Down
29 changes: 28 additions & 1 deletion src/class_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -1771,8 +1771,10 @@ BOOL System_initialize_file_system(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo*
system->mClassFields[LAST_INITIALIZE_FIELD_NUM_ON_STRING_SYSTEM+75].mValue.mIntValue = BUFSIZ;

system->mClassFields[LAST_INITIALIZE_FIELD_NUM_ON_STRING_SYSTEM+76].mValue.mIntValue = PATH_MAX;
system->mClassFields[LAST_INITIALIZE_FIELD_NUM_ON_STRING_SYSTEM+77].mValue.mIntValue = F_GETFL;
system->mClassFields[LAST_INITIALIZE_FIELD_NUM_ON_STRING_SYSTEM+78].mValue.mIntValue = F_SETFL;

#define LAST_INITIALIZE_FIELD_NUM_ON_FILE_SYSTEM (LAST_INITIALIZE_FIELD_NUM_ON_STRING_SYSTEM+77)
#define LAST_INITIALIZE_FIELD_NUM_ON_FILE_SYSTEM (LAST_INITIALIZE_FIELD_NUM_ON_STRING_SYSTEM+79)

return TRUE;
}
Expand Down Expand Up @@ -1858,6 +1860,31 @@ BOOL System_write(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info)
return TRUE;
}

BOOL System_fcntl(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info)
{
CLVALUE* fd = lvar;
CLVALUE* flag = lvar+1;
CLVALUE* val = lvar + 2;

/// Clover to c value ///
int fd_value = fd->mIntValue;
int flag_value = flag->mIntValue;
int val_value = val->mIntValue;

/// go ///
int result = fcntl(fd_value, flag_value, val_value);

if(result < 0) {
entry_exception_object_with_class_name(stack_ptr, info->current_stack, info->current_var_num, info, "Exception", "fcntl(2) is faield. The error is %s. The errno is %d", strerror(errno), errno);
return FALSE;
}

(*stack_ptr)->mIntValue = result;
(*stack_ptr)++;

return TRUE;
}

BOOL System_localtime(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info)
{
CLVALUE* time = lvar;
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,7 @@ BOOL System_initialize_string_system(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo
BOOL System_initialize_file_system(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info);
BOOL System_read(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info);
BOOL System_write(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info);
BOOL System_fcntl(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info);
BOOL System_time(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info);
BOOL System_localtime(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info);
BOOL System_mktime(CLVALUE** stack_ptr, CLVALUE* lvar, sVMInfo* info);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static BOOL class_compiler(char* fname)

int gARGC;
char** gARGV;
char* gVersion = "10.5.5";
char* gVersion = "10.5.6";

char gScriptDirPath[PATH_MAX];
BOOL gRunningCompiler = TRUE;
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,7 @@ static void compiler_final()

int gARGC;
char** gARGV;
char* gVersion = "10.5.5";
char* gVersion = "10.5.6";

char gScriptDirPath[PATH_MAX];
BOOL gRunningCompiler = FALSE;
Expand Down Expand Up @@ -2515,7 +2515,7 @@ int main(int argc, char** argv)

char* line = readline(prompt);

if(line == NULL) {
if(line == NULL || strcmp(line, "exit") == 0) {
compiler_final();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void set_signal()

int gARGC;
char** gARGV;
char* gVersion = "10.5.5";
char* gVersion = "10.5.6";
BOOL gCompilingCore = FALSE;

char gScriptDirPath[PATH_MAX];
Expand Down
1 change: 1 addition & 0 deletions src/native_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static sNativeMethod gNativeMethods[] = {
{ "System.close(int)", "System_close", System_close },
{ "System.read(int,Buffer,ulong)", "System_read", System_read },
{ "System.write(int,Buffer,ulong)", "System_write", System_write },
{ "System.fcntl(int,int,int)", "System_fcntl", System_fcntl },
{ "System.localtime(ulong,pointer,pointer,pointer,pointer,pointer,pointer,pointer,pointer,pointer)", "System_localtime", System_localtime },
{ "System.mktime(tm)", "System_mktime", System_mktime },
{ "System.lstat(String,stat)", "System_lstat", System_lstat },
Expand Down

0 comments on commit adcee38

Please sign in to comment.