Closed alexmcgilvery closed 5 years ago
Yeah, that's what's happening when I push it to github
/*
*/
// Put macros or constants here using #define
// Put global environment variables here
// Define functions declared in myshell.h here
int main(int argc, char *argv[]) { // Input buffer and and commands char buffer[BUFFER_LEN] = { 0 }; char command[BUFFER_LEN] = { 0 }; char arg[BUFFER_LEN] = { 0 }; char cwd[BUFFER_LEN] = { 0 }; char line[BUFFER_LEN] = { 0 }; char output[BUFFER_LEN] = { 0 }; char shell[BUFFER_LEN] = { 0 };
int paused = 0;
FILE *readme;
// Parse the commands provided using argc and argv
// Perform an infinite loop getting command input from users
getcwd(shell, sizeof(shell));
strcat(shell,": ");//store shells working directory
fputs(shell,stderr);
while (fgets(buffer, BUFFER_LEN, stdin) != NULL)
{
// Perform string tokenization to get the command and argument
strcpy(arg,"");
strcpy(command,"");
sscanf(buffer,"%s %s",command,arg); // Parse the commands provided using argc and argv
// Check the command and execute the operations for each command
//pause has priority, we want to check if paused or not before checking if its actually a command
if (strcmp(command,"pause")== 0 && paused != 1 && strcmp(arg, "") == 0){
paused = 1;
}
else if (paused == 1){
if (strcmp(buffer, "\n") == 0){
paused = 0;
}
}
// cd command -- change the current directory
else if (strcmp(command, "cd") == 0)
{
if (strcmp(arg,"")!= 0){
//system("cd");
//strcat(command," ~");
//strcat(command,arg);
//system(command);
chdir(arg);
}
else{
system("pwd");
}
}
// directory listingc
else if (strcmp(command, "dir") == 0 && strcmp(arg, "") == 0)
{
getcwd(cwd, sizeof(cwd)); //store cwd
strcpy(command,"cd"); //switch to cd command
strcat(command," ");
strcat(command,arg);
system(command);
system("ls"); // display all files (linux) within cwd
strcat(command," ");
strcat(command,cwd);
system(command);//cd back to stored cwd
}
//enviorment variables
else if (strcmp(command, "environ") == 0 && strcmp(arg, "") == 0)
{
system("printenv"); // again linux terminal usage
}
// clear command
else if (strcmp(command,"clr")== 0 && strcmp(arg, "") == 0){
//system("cls"); // windows terminal usage
system("reset"); // linux terminal usage
}
// quit command -- exit the shell
else if (strcmp(command, "quit") == 0 && strcmp(arg, "") == 0)
{
return EXIT_SUCCESS;
}
// echo command -- repeat back argument then move to next line with \n
else if (strcmp(command, "echo") == 0 )
{
//strcat(arg,"\n");
fputs(arg,stderr);
fputs("\n",stderr);
}
else if (strcmp(command, "help") == 0 && strcmp(arg, "") == 0){
if (access("README.md",F_OK)!=-1){
readme = fopen("README.md", "r");
fgets(line,BUFFER_LEN,readme);
strcpy(output,line);
while (!feof(readme)){
strcat(output,line);
fgets(line,BUFFER_LEN,readme);
}
fclose(readme);
}
else{
strcat(output,"Readme file was not found in cwd\n");
}
fputs(output,stderr);
strcpy(output,"");
}
// Unsupported command
else
{
fputs("Unsupported command, use help to display the manual\n", stderr);
}
getcwd(shell, sizeof(shell));
strcat(shell,": ");//store shells working directory
fputs(shell,stderr);
}
return EXIT_SUCCESS;
}
what are the #includes?
stdio.h stdlib.h unistd.h dirent.h sys/types.h string.h utility.h myshell.h
the last two have quotes " ", not <>
"utility.h", and "myshell.h"
try and do merge of my commit
I'm trying to merge, but it's not letting me
CONFLICT (content): Merge conflict in myshell.c Automatic merge failed; fix conflicts and then commit the result.
delete myshell.c from your repo, and ill try and pull again
from my local repo?
the online one click on myshell.c and there will be a trash bin
ok
ok, done
try now
Couple errors. the #include statements must have <...>. And here are the additional errors:
myshell.c: In function ‘main’: myshell.c:34:3: error: unknown type name ‘FILE’ FILE *readme; ^ myshell.c:38:3: warning: implicit declaration of function ‘getcwd’ [-Wimplicit-function-declaration] getcwd(shell, sizeof(shell)); ^ myshell.c:39:3: warning: implicit declaration of function ‘strcat’ [-Wimplicit-function-declaration] strcat(shell,": ");//store shells working directory ^ myshell.c:39:3: warning: incompatible implicit declaration of built-in function ‘strcat’ [enabled by default] myshell.c:40:3: warning: implicit declaration of function ‘fputs’ [-Wimplicit-function-declaration] fputs(shell,stderr); ^ myshell.c:40:15: error: ‘stderr’ undeclared (first use in this function) fputs(shell,stderr); ^ myshell.c:40:15: note: each undeclared identifier is reported only once for each function it appears in myshell.c:41:3: warning: implicit declaration of function ‘fgets’ [-Wimplicit-function-declaration] while (fgets(buffer, BUFFER_LEN, stdin) != NULL) ^ myshell.c:41:36: error: ‘stdin’ undeclared (first use in this function) while (fgets(buffer, BUFFER_LEN, stdin) != NULL) ^ myshell.c:41:46: error: ‘NULL’ undeclared (first use in this function) while (fgets(buffer, BUFFER_LEN, stdin) != NULL) ^ myshell.c:44:7: warning: implicit declaration of function ‘strcpy’ [-Wimplicit-function-declaration] strcpy(arg,""); ^ myshell.c:44:7: warning: incompatible implicit declaration of built-in function ‘strcpy’ [enabled by default] myshell.c:47:7: warning: implicit declaration of function ‘sscanf’ [-Wimplicit-function-declaration] sscanf(buffer,"%s %s",command,arg); // Parse the commands provided using argc and argv ^ myshell.c:47:7: warning: incompatible implicit declaration of built-in function ‘sscanf’ [enabled by default] myshell.c:51:7: warning: implicit declaration of function ‘strcmp’ [-Wimplicit-function-declaration] if (strcmp(command,"pause")== 0 && paused != 1 && strcmp(arg, "") == 0){ ^ myshell.c:68:15: warning: implicit declaration of function ‘chdir’ [-Wimplicit-function-declaration] chdir(arg); ^ myshell.c:71:15: warning: implicit declaration of function ‘system’ [-Wimplicit-function-declaration] system("pwd"); ^ myshell.c:103:18: error: ‘EXIT_SUCCESS’ undeclared (first use in this function) return EXIT_SUCCESS; ^ myshell.c:114:11: warning: implicit declaration of function ‘access’ [-Wimplicit-function-declaration] if (access("README.md",F_OK)!=-1){ ^ myshell.c:114:34: error: ‘F_OK’ undeclared (first use in this function) if (access("README.md",F_OK)!=-1){ ^ myshell.c:116:15: warning: implicit declaration of function ‘fopen’ [-Wimplicit-function-declaration] readme = fopen("README.md", "r"); ^ myshell.c:116:22: warning: assignment makes pointer from integer without a cast [enabled by default] readme = fopen("README.md", "r"); ^ myshell.c:119:15: warning: implicit declaration of function ‘feof’ [-Wimplicit-function-declaration] while (!feof(readme)){ ^ myshell.c:123:15: warning: implicit declaration of function ‘fclose’ [-Wimplicit-function-declaration] fclose(readme); ^
not sure why but I can't seem to push code properly to here
try new merge
seems to work now; no more errors
we can prob hand it in later, since the other lab got extended a week. Since different TA anyways we can just say dropbox link was denying us
the sudoku lab got extended a week?
no the assignment 1 for other lab time (group B)
oh yeah, was theirs also due today?
maybe, but originally it was due last week
ok, sounds good then
main code is super illegible