mikeizbicki / ucr-cs100

open source software construction course
Other
485 stars 407 forks source link

io redirection without spaces #75

Closed katherinegallaher closed 10 years ago

katherinegallaher commented 10 years ago

I have io redirection working if there's a space in between the commands for example "echo hello > input" so now I'm trying to get it to work for the other cases where there's no spaces like if the commands are: "echo hello >input" but I'm coming across some problems. In my parsing function i'm adding a section that will look at whether the symbol is at the beginning end or middle of the word.

For now, this is what I've added: if(copy[0] == '>' && length >1) { string newstring = copy; strcpy(argv[numargs], ">"); newstring = newstring.substr(newstring.rfind(">")); newstring.erase(0,1); numargs++; char temp[100]; strcpy(temp, newstring.c_str()); argv[numargs] = temp; }

it's doing all these things and copying into argv correctly but when it hits my strtok at the end of my function something happens and ti think the program goes into an infinite loop? Here's a link to my whole parse function without this addition: https://github.com/katherinegallaher/rshell/blob/master/src/rshell.cpp

katherinegallaher commented 10 years ago

or can anyone give me hints of a different way I could parse to recognize these cases?

katherinegallaher commented 10 years ago

actually I think I may have figured out a way to do it