Closed Glavin001 closed 9 years ago
See http://stackoverflow.com/a/11958481/2578205 for obtaining the current Git branch.
@Frozenfire92 's dotfiles: https://github.com/Frozenfire92/dotfiles/blob/master/.bash_profile
Quick brief of how I'd do it, for anyone interested, before I go pass out: 1) Iterate linearly thru all command line args (argv[0], argv[1], argv[2]). Let's deal with argv[0] from here on, the first arg. 2) Any time where the first character (argv[0][0]) is equal to the char "~" then continue with step 3 3) use malloc to allocate a char array with the size of $HOME plus the original argv[0] length minus 1 (for the ~ that is removed in argv[0]). This will be the new length of that argv[0]. 4) Starting from the beginning, fill the char array with the chars in $HOME 5) Next, starting at the end where $HOME left off, in the new char array, continue with the original contents of the char array in argv[0], starting at argv[0][1](skipping argv[0][0] which is the ~ to be removed). You have now filled the contents of the char array with the resolved path. Your new char array for the argv[0] is now stored in your new char array. Switch the pointers of argv[0] to the new array and dealloc the old argv[0]. Apply this function to every argument, in either the parse or execute function. This will allow us to support:
~/Projects/MrShell/builds/mrsh
) cd ~/Projects/MrShell
)
Note: Remember that backslash should escape characters, such as ~ or spaces. This will be implicitly handled because we directly check only argv[0][0](the first char of the current arg) against '~'. If it was escaped by a backslash it would be a \
in the first position.All done!
cd
|
>>
,>
a\ b
should be a single stringa b
and not twoa
andb
~
support for$HOME
in path args