struct Value *handle_purgelua_command(String *args, int offset) { if(lua_state != NULL) { lua_close(lua_state); lua_state = NULL; myinfo("All LUA scripts forgotten"); return newint(1); } myinfo("No LUA scripts loaded"); return newint(0); }
void try_compact() { if (arena != 0 && freemem != 0) { struct myinfo stat = myinfo(); double fragm = ((double)(stat.freemem - stat.maxfreeblk) * 100) / stat.freemem; if (fragm > 70) compact(); } }
int main() { heap_pointer<int> pointers[10]; int size; for (int i = 0; i < 10; ++i) { pointers[i] = allocate<int>(100); pointers[i] = i; } for (int i = 0; i < 10; i += 2) { pointers[i].free(); } print_heap_dump(); struct myinfo info = myinfo(); for (int i = 1; i < 10; i+= 2) { printf("%d ", *(pointers[i])); } printf("\n"); allocate<int>(200); print_heap_dump(); info = myinfo(); for (int i = 1; i < 10; i+= 2) { printf("%d ", *(pointers[i])); } printf("\n"); }
int SMASHexec(char ** command){ int status; //printf("Hi\n"); if (0==strcmp("exit", command[0])){ free(line); free(args); exit(0); } else if (0==strcmp("myinfo", command[0])){ myinfo(); } else if (0==strcmp("cd", command[0]) && NULL == args[1]) { char * HOME=""; HOME = getenv("HOME"); if (NULL != HOME){ chdir(HOME); } else{ printf("$HOME path corrupt\n"); } }else if (0 == strcmp("cd", command[0])){ mycd(command[1]); }else { if (pipe_flag){ args[pipe_index]=NULL; //pid_t child2; int fds[2]; int buffersize = arglen - pipe_index -1; //printf("%d\n", buffersize ); char ** buffer = calloc(sizeof(char*), buffersize); for (int i = 1; i <= buffersize; ++i) { buffer[i-1] = command[pipe_index + i]; //printf("ABC%s\n", buffer[i-1] ); } //printf("%s\n", buffer[0] ); pipe(fds); //child = fork(); if (fork() == 0){ dup2(fds[0], STDIN_FILENO); //close(fds[1]); close(fds[0]); //child2 = fork(); if (fork() == 0){ dup2(fds[1], STDOUT_FILENO); close(fds[0]); //close(fds[1]); //printf("1st %s\n", command[0] ); execvp(command[0], command); } wait(NULL); close(fds[1]); execvp(buffer[0], buffer); } close(fds[1]); close(fds[0]); free(buffer); wait(NULL); } else { //printf("B\n"); child = fork(); if (child){ //parent if (0==strcmp(command[arglen-1], "&")){ char buff[PATH_MAX + 1]; char * cpath; cpath = getcwd(buff, PATH_MAX+1); printf("\n< %s SMASH >$ ", cpath); waitpid(-1, &status, WNOHANG ); } else { waitpid(child, &status, 0 ); } } else{ //child //sleep(5); used for testing of sigint handler redirect(args); if (redirect_flag){ if ( redirect_flag == 1 ){ args[input_redirect_index]=NULL; } else if ( redirect_flag == 2 ){ args[output_redirect_index]=NULL; } else if ( redirect_flag == 3){ args[output_redirect_index]=NULL; args[input_redirect_index]=NULL; } } int failure = execvp(command[0], command); if (-1 == failure){ perror("SMASH"); exit(EXIT_FAILURE); } } } } return child; }