BOOL CSmtShell::IsFatherAdd() { if(!strcmp(m_EnvPath, m_szFile[0])){ return FALSE; } char FatherPath[255]; memset(FatherPath, 0, sizeof(FatherPath)); if(!GetFatherPath(m_szFile[0], FatherPath)){ return FALSE; } if(!strcmp(m_EnvPath, FatherPath)){ return FALSE; } string StatusStr; string StatusCmd = "svn status "; StatusCmd += "\""; StatusCmd += FatherPath; StatusCmd += "\""; StatusStr += ExeCmd((char *)StatusCmd.c_str()); if(0 == StatusStr.find("A ")){ if(IsSamePath(StatusStr, FatherPath)){ return TRUE; } } return FALSE; }
//************************************************************************************** // function name: main // Description: main function of smash. get command from user and calls command functions //************************************************************************************** int main(int argc, char *argv[]) { char cmdString[MAX_LINE_SIZE]; LIST_ELEMENT* VarList = NULL; if(signal(SIGTSTP,signal_handler) == SIG_ERR){ printf("SIGTSTP == SIG_ERR\n"); } if(signal(SIGINT,signal_handler) == SIG_ERR){ printf("SIGINT == SIG_ERR\n"); } if(signal(SIGCHLD,signal_handler) == SIG_ERR){ printf("SIGCHLD == SIG_ERR\n"); } /************************************/ // Init globals GPid = -1; Last_Bg_Pid = -1; Susp_Bg_Pid = -1; susp = 0; L_Fg_Cmd =(char*)malloc(sizeof(char)*(MAX_LINE_SIZE+1)); if (L_Fg_Cmd == NULL) exit (-1); L_Fg_Cmd[0] = '\0'; while (1) { printf("smash > "); fgets(lineSize, MAX_LINE_SIZE, stdin); strcpy(cmdString, lineSize); cmdString[strlen(lineSize)-1]='\0'; // replace $variable with it's value: if(VarRplc(VarList, lineSize)) continue; // perform a complicated Command if(!ExeComp(lineSize, &JobsList)) continue; // background command if(!BgCmd(lineSize, &JobsList)) continue; // built in commands ExeCmd(&JobsList, &VarList, lineSize, cmdString); /* initialize for next line read*/ lineSize[0]='\0'; cmdString[0]='\0'; } return 0; }
BOOL NeedProtect(string sCrtPath) { string sWcPath; int pos = sCrtPath.find("\\.svn"); if(string::npos != pos && pos > 1){ sWcPath = sCrtPath.substr(0, pos); string sStatusCmd = "svn status --non-interactive \"" + sWcPath + "\""; string strRet = ExeCmd((char *)sStatusCmd.c_str()); if(string::npos != strRet.find("K ")){ return TRUE; } } return FALSE; }
//************************************************************************************** // function name: main // Description: main function of smash. get command from user and calls command functions //************************************************************************************** int main(int argc, char *argv[]) /* * argc stands for "argument count" - argc contains the number of arguments passed to the program * argv stands for "argument vector". A vector is a one-dimensional array, * and argv is a one-dimensional array of strings */ { char cmdString[MAX_LINE_SIZE]; jobs = new list<job>; /* Adjusting new handlers for SIGTSTP, SIGINT & SIGCHLD */ struct sigaction sa; sa.sa_handler = &signal_handle; sa.sa_flags = SA_RESTART; sigfillset(&sa.sa_mask); if (sigaction(SIGTSTP, &sa, NULL) == -1) perror("Error: cannot handle SIGTSTP"); if (sigaction(SIGINT, &sa, NULL) == -1) perror("Error: cannot handle SIGINT"); signal (SIGCHLD, &child_handle); while (1) { printf("smash > "); fgets(lineSize, MAX_LINE_SIZE, stdin); strcpy(cmdString, lineSize); cmdString[strlen(lineSize)-1]='\0'; if(!BgCmd(lineSize)) continue; // Checking if CMD is bg CMD, executing if it is (can be a complicated bg CMD) // if(!ExeComp(lineSize, false)) continue; // Checking if CMD is complicated+not bg CMD, executing if it is // ExeCmd(lineSize, cmdString); // Executing built-in/external CMD // lineSize[0]='\0'; cmdString[0]='\0'; } return 0; }
BOOL IsReadOnly(string sCrtPath) { if(sCrtPath.find("\\.svn") != sCrtPath.npos){ return FALSE; } if(!memcmp(sCrtPath.c_str(), "C:\\Documents and Settings", strlen("C:\\Documents and Settings")) && (string::npos == sCrtPath.find("\\Desktop"))){ return FALSE; } if(!memcmp(sCrtPath.c_str(), "C:\\Users", strlen("C:\\Users")) && (string::npos == sCrtPath.find("\\Desktop"))){ return FALSE; } string sStatusCmd = "svn status --non-interactive \"" + sCrtPath + "\""; string strRet = ExeCmd((char *)sStatusCmd.c_str()); if(strRet.length() == 0){ return TRUE; } return FALSE; }
//************************************************************************************** // function name: main // Description: main function of smash. get command from user and calls command functions //************************************************************************************** int main(int argc, char *argv[]) { char cmdString[MAX_LINE_SIZE]; pJob* job_list_head_ptr; struct sigaction ctrl_z_act; struct sigaction ctrl_c_act; //struct sigaction sigchld_act; fill_action(&ctrl_z_act, &ctrl_z_handler); fill_action(&ctrl_c_act, &ctrl_c_handler); //fill_action(&sigchld_act, &sigchld_handler); sigaction(SIGTSTP, &ctrl_z_act,NULL); sigaction(SIGINT, &ctrl_c_act,NULL); //sigaction(SIGCHLD,&sigchld_act,NULL); int dead_pid; //signal declaretions //NOTE: the signal handlers and the function/s that sets the handler should be found in siganls.c /* add your code here */ /************************************/ //NOTE: the signal handlers and the function/s that sets the handler should be found in siganls.c //set your signal handlers here /* add your code here */ /************************************/ /************************************/ // Init globals GPid = -1; Last_Bg_Pid = -1; Susp_Bg_Pid = -1; susp = 0; job_list_head = NULL; job_list_head_ptr = &job_list_head; #if 0 L_Fg_Cmd =(char*)malloc(sizeof(char)*(MAX_LINE_SIZE+1)); if (L_Fg_Cmd == NULL) exit (-1); L_Fg_Cmd[0] = '\0'; #endif while (1) { printf("smash > "); while((dead_pid=waitpid(-1,NULL,WNOHANG))>0)// This loop is in charge of handling zombies { remove_job(&job_list_head,dead_pid); } if((dead_pid==-1) && (errno=EINTR)) { //refresh_list(job_list_head_ptr); } fgets(lineSize, MAX_LINE_SIZE, stdin); strcpy(cmdString, lineSize); cmdString[strlen(lineSize)-1]='\0'; // perform a complicated Command if(!ExeComp(lineSize)) continue; // background command if(!BgCmd(lineSize, job_list_head_ptr)) continue; // built in commands ExeCmd(&job_list_head, lineSize, cmdString); /* initialize for next line read*/ lineSize[0]='\0'; cmdString[0]='\0'; fflush(stdout); fflush(stdin); } return 0; }
BOOL CSmtShell::IsInCtr() { m_FathAddFlag = FALSE; m_CouldAdd = TRUE; if(IsFatherAdd()){ m_FathAddFlag = TRUE; for(int i = 0; i < m_NumFiles; i++){ string StatusStr; string StatusCmd = "svn status "; StatusCmd += "\""; StatusCmd += m_szFile[i]; StatusCmd += "\""; StatusStr += ExeCmd((char *)StatusCmd.c_str()); if(0 == StatusStr.find("A ")){ m_InCtrNo[m_InCtrCount] = i; m_InCtrCount++; m_CouldAdd = FALSE; } } return FALSE; } char FilePath[255]; memset(FilePath, 0, sizeof(FilePath)); sprintf(FilePath, "%s\\SmtRec.dat", m_EnvPath); FILE *fp = fopen(FilePath, "r"); if(NULL == fp){ return FALSE; } fseek(fp, 0, SEEK_END); long fileLength = ftell(fp); int CycleTimes = (int)fileLength/255 - 1; fseek(fp, 255, SEEK_SET); m_RecFileLen = fileLength; char RecPath[255]; char TmpPath[255]; m_InCtrCount = 0; memset(m_InCtrNo, 0, sizeof(m_InCtrNo)); BOOL TFlag = FALSE; for(int i = 0; i < m_NumFiles; i++){ int PathLen = strlen(m_szFile[i]); int k = 0; for(k = 0; k < CycleTimes; k++){ memset(RecPath, 0, sizeof(RecPath)); memset(TmpPath, 0, sizeof(TmpPath)); fread(RecPath, 1, sizeof(RecPath), fp); sprintf(TmpPath, "%s%s", m_EnvPath, RecPath); if((PathLen == strlen(TmpPath)) && (!memcmp(m_szFile[i], TmpPath, PathLen))){ break; } } if(k < CycleTimes){ m_InCtrNo[m_InCtrCount] = i; m_InCtrCount++; TFlag = TRUE; /*if(!m_AddFlag){ if(FILE_ATTRIBUTE_DIRECTORY != GetFileAttributes(m_szFile[i])){ string StatusStr; string StatusCmd = "svn status "; StatusCmd += "\""; StatusCmd += m_szFile[i]; StatusCmd += "\""; StatusStr += ExeCmd((char *)StatusCmd.c_str()); if(StatusStr.npos != StatusStr.find("A ")){ m_AddFlag = TRUE; } } }*/ } else{ string StatusStr; string StatusCmd = "svn status "; StatusCmd += "\""; StatusCmd += m_szFile[i]; StatusCmd += "\""; StatusStr += ExeCmd((char *)StatusCmd.c_str()); if(0 == StatusStr.find("A ")){ m_InCtrNo[m_InCtrCount] = i; m_InCtrCount++; TFlag = TRUE; m_AddFlag = TRUE; } } fseek(fp, 255, SEEK_SET); } fclose(fp); if(TFlag){ return TRUE; } for(int i = 0; i < m_NumFiles; i++){ if((!strcmp(m_EnvPath, m_szFile[i])) && m_RecFileLen > 255){ return TRUE; } } if(1 == m_NumFiles){ if(!strcmp(m_EnvPath, m_szFile[0])){ char SvnPath[255]; memset(SvnPath, 0, sizeof(SvnPath)); sprintf(SvnPath, "%s\\.svn", m_EnvPath); if(PathFileExists(SvnPath)){ return TRUE; } } } return FALSE; }