![]() |
|||
|
|
|
|
|
boby |
|
|
|
D |
|
d |
|
india |
|
|
|
cygdrive |
|
cygdrive |
|
boby.txt |
|
|
pcRelPath = “..\..\”
Step 5: Repeat the same process till the end of stacks.
tmpStackAbsPath tmpStackCurrPath tmpStackOutput tmpMatchQueue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d |
|
|
|
|
|
|
|
|
|
|
|
|
|
boby |
|
|
|
|
|
|
|
india |
|
|
|
cygdrive |
|
cygdrive |
|
boby.txt |
|
|
pcRelPath = “..\..\”
Step 6: Repeat the same process till the end of stacks.
tmpStackAbsPath tmpStackCurrPath tmpStackOutput tmpMatchQueue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cygdrive |
|
|
|
|
|
|
|
d |
|
|
|
|
|
|
|
|
|
|
|
|
|
boby |
|
|
|
|
|
|
|
india |
|
|
|
|
|
|
|
boby.txt |
|
|
pcRelPath = “..\..\”
Step 7: Once the “tmpStackAbsPath” and “tmpStackCurrPath” are exhausted, move the content of “tmpStackOutput” to the output string pcRelPath .
tmpStackAbsPath tmpStackCurrPath tmpStackOutput tmpMatchQueue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cygdrive |
|
|
|
|
|
|
|
d |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
india |
|
|
|
|
|
|
|
boby.txt |
|
|
pcRelPath = “..\..\boby\”
Step 8: Once the “tmpStackAbsPath” and “tmpStackCurrPath” are exhausted, move the content of “tmpStackOutput” to the output string pcRelPath .
tmpStackAbsPath tmpStackCurrPath tmpStackOutput tmpMatchQueue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cygdrive |
|
|
|
|
|
|
|
d |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boby.txt |
|
|
pcRelPath = “..\..\boby\India\”
Step 9: Continue the process till the “tmpStackOutput” exhausts.
tmpStackAbsPath tmpStackCurrPath tmpStackOutput tmpMatchQueue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cygdrive |
|
|
|
|
|
|
|
d |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pcRelPath = “..\..\boby\india\ boby.txt”
Abs2Rel path function takes absolute path as input and returns relative path.
//------------------------------------------------------------------------------ // Method : Rel2Abs // Description : Convert absolute path to relative path. // Parameter : pcRelPath - Input - Relative path // Parameter : pcAbsPath - Output - Absolute path // Parameter : pcCurrDir - Input - Current Dir/Reference dir path // Return : Absolute path // Author : Boby Thomas Pazheparampil April 2006 //------------------------------------------------------------------------------ char * Rel2Abs(char *pcRelPath, char *pcAbsPath, char* pcCurrDir)
Following sequence will explain the conversion process.
For example consider the relative path “../../boby/../temp.txt" and reference directory “/cygdrive/d/try/path_conv”
Step 1: First extract the relative path into queue “tmpQueueRelPath”.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp.txt |
|
|
|
|
|
.. |
|
|
|
|
|
boby |
|
|
|
|
|
.. |
|
|
|
|
|
.. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Step 2: Then convert the reference path into stack “tmpStackCurrPath”.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp.txt |
|
|
|
|
|
.. |
|
|
|
|
|
boby |
|
|
|
|
|
.. |
|
path_conv |
|
|
|
.. |
|
try |
|
|
|
|
|
d |
|
|
|
|
|
cygdrive |
|
|
Step 3: Take entries from the front of the queue “tmpQueueRelPath”. If it is an ellipse, pop out the last entry in the stack “tmpStackCurrPath”. If the front entry in the queue “tmpQueueRelPath” is not ellipse, push the entry into stack “tmpStackCurrPath”.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp.txt |
|
|
|
|
|
.. |
|
|
|
|
|
boby |
|
|
|
|
|
.. |
|
|
|
|
|
|
|
try |
|
|
|
|
|
d |
|
|
|
|
|
cygdrive |
|
|
Step 4: Continue the same process until the queue “tmpQueueRelPath” exhausts.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp.txt |
|
|
|
|
|
.. |
|
|
|
|
|
boby |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d |
|
|
|
|
|
cygdrive |
|
|
Step 5: Continue the same process until the queue “tmpQueueRelPath” exhausts.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp.txt |
|
|
|
|
|
.. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boby |
|
|
|
|
|
d |
|
|
|
|
|
cygdrive |
|
|
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp.txt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d |
|
|
|
|
|
cygdrive |
|
|
Step 7: Continue the same process until the queue “tmpQueueRelPath” exhausts.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp.txt |
|
|
|
|
|
d |
|
|
|
|
|
cygdrive |
|
|
Step 8: Once the queue “tmpQueueRelPath” exhausts, pop the content of the stack “tmpStackCurrPath” and push it to the stack “tmpStackOutput”.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d |
|
|
|
|
|
cygdrive |
|
temp.txt |
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d |
|
|
|
cygdrive |
|
temp.txt |
Step 10: Repeat the process till the stack “tmpStackCurrPath” exhausts.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cygdrive |
|
|
|
|
|
d |
|
|
|
|
|
temp.txt |
Step 11: Once the stack “tmpStackCurrPath” is empty, take the content into absolute return path string.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d |
|
|
|
|
|
temp.txt |
pcAbsPath = “/cygdrive/”
Step 12: Repeat the process till stack “tmpStackOutput” is empty.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temp.txt |
pcAbsPath = “/cygdrive/d/”
Step 13: Repeat the process till stack “tmpStackOutput” is empty.
tmpQueueRelPath tmpStackCurrPath tmpStackOutput
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pcAbsPath = “/cygdrive/d/ temp.txt”
We can think of lots of different methods for the above implementation. Feedback about this method will be greatly appreciated. Contact me at bobypt@gmail.com.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
![]() |
Boby Thomas P
Australia
![]() Member
|
| You must Sign In to use this message board. | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
General
News
Suggestion
Question
Bug
Answer
Joke
Rant
Admin
| Type | Article |
| Licence | |
| First Posted | 15 Apr 2006 |
| Views | 35,679 |
| Downloads | 647 |
| Bookmarked | 35 times |
Votes of 3 or less require a comment