1 void getTextLine() 2 { 3 destroyCommand(); 4 while ((userInput != '\n') && (bufferChars < BUFFER_MAX_LENGTH)) { 5 buffer[bufferChars++] = userInput; 6 userInput = getchar(); 7 } 8 buffer[bufferChars] = 0x00; 9 populateCommand(); 10 } 11 void populateCommand() 12 { 13 char* bufferPointer; 14 bufferPointer = strtok(buffer, " "); 15 while (bufferPointer != NULL) { 16 commandArgv[commandArgc] = bufferPointer; 17 bufferPointer = strtok(NULL, " "); 18 commandArgc++; 19 } 20 } 21 22 void destroyCommand() 23 { 24 while (commandArgc != 0) { 25 commandArgv[commandArgc] = NULL; 26 commandArgc--; 27 } 28 bufferChars = 0; 29 } 30 31 32 t_job* insertJob(pid_t pid, pid_t pgid, char* name, char* descriptor, 33 int status) 34 { 35 usleep(10000); 36 t_job *newJob = malloc(sizeof(t_job)); 37 38 newJob->name = (char*) malloc(sizeof(name)); 39 newJob->name = strcpy(newJob->name, name); 40 newJob->pid = pid; 41 newJob->pgid = pgid; 42 newJob->status = status; 43 newJob->descriptor = (char*) malloc(sizeof(descriptor)); 44 newJob->descriptor = strcpy(newJob->descriptor, descriptor); 45 newJob->next = NULL; 46 47 if (jobsList == NULL) { 48 numActiveJobs++; 49 newJob->id = numActiveJobs; 50 return newJob; 51 } else { 52 t_job *auxNode = jobsList; 53 while (auxNode->next != NULL) { 54 auxNode = auxNode->next; 55 } 56 newJob->id = auxNode->id + 1; 57 auxNode->next = newJob; 58 numActiveJobs++; 59 return jobsList; 60 } 61 } 62 63 64 int changeJobStatus(int pid, int status) 65 { 66 usleep(10000); 67 t_job *job = jobsList; 68 if (job == NULL) { 69 return 0; 70 } else { 71 int counter = 0; 72 while (job != NULL) { 73 if (job->pid == pid) { 74 job->status = status; 75 return TRUE; 76 } 77 counter++; 78 job = job->next; 79 } 80 return FALSE; 81 } 82 } 83 84 t_job* delJob(t_job* job) 85 { 86 usleep(10000); 87 if (jobsList == NULL) 88 return NULL; 89 t_job* currentJob; 90 t_job* beforeCurrentJob; 91 92 currentJob = jobsList->next; 93 beforeCurrentJob = jobsList; 94 95 if (beforeCurrentJob->pid == job->pid) { 96 97 beforeCurrentJob = beforeCurrentJob->next; 98 numActiveJobs--; 99 return currentJob; 100 } 101 102 while (currentJob != NULL) { 103 if (currentJob->pid == job->pid) { 104 numActiveJobs--; 105 beforeCurrentJob->next = currentJob->next; 106 } 107 beforeCurrentJob = currentJob; 108 currentJob = currentJob->next; 109 } 110 return jobsList; 111 } 112 113 t_job* getJob(int searchValue, int searchParameter) 114 { 115 usleep(10000); 116 t_job* job = jobsList; 117 switch (searchParameter) { 118 case BY_PROCESS_ID: 119 while (job != NULL) { 120 if (job->pid == searchValue) 121 return job; 122 else 123 job = job->next; 124 } 125 break; 126 case BY_JOB_ID: 127 while (job != NULL) { 128 if (job->id == searchValue) 129 return job; 130 else 131 job = job->next; 132 } 133 break; 134 case BY_JOB_STATUS: 135 while (job != NULL) { 136 if (job->status == searchValue) 137 return job; 138 else 139 job = job->next; 140 } 141 break; 142 default: 143 return NULL; 144 break; 145 } 146 return NULL; 147 } 148 149 void printJobs() 150 { 151 printf("\nActive jobs:\n"); 152 printf( 153 "---------------------------------------------------------------------------\n"); 154 printf("| %7s | %30s | %5s | %10s | %6s |\n", "job no.", "name", "pid", 155 "descriptor", "status"); 156 printf( 157 "---------------------------------------------------------------------------\n"); 158 t_job* job = jobsList; 159 if (job == NULL) { 160 printf("| %s %62s |\n", "No Jobs.", ""); 161 } else { 162 while (job != NULL) { 163 printf("| %7d | %30s | %5d | %10s | %6c |\n", job->id, job->name, 164 job->pid, job->descriptor, job->status); 165 job = job->next; 166 } 167 } 168 printf( 169 "---------------------------------------------------------------------------\n"); 170 } 171 172 void welcomeScreen() 173 { 174 printf("\n-------------------------------------------------\n"); 175 printf("\tWelcome to MINI-shell version \n"); 176 //printf("\tThis is bdsh with process id: %d\n", (int) BDSH_PID); 177 puts("\tAuthor :Bharathi"); 178 printf("-------------------------------------------------\n"); 179 printf("\n\n"); 180 } 181 182 void shellPrompt() 183 { 184 printf("%s :> ",getcwd(currentDirectory, 1024)); 185 }