Description
Given a line consists of two path, separated by a blank.
For example, ./a/b/c.html ./d/e/f/g.html.
Each path,
- begins with ./.
- consists of a directory and a filename part.
Given the line,
./pr1/sub1/slide2.html ./pr1/sub3/sub31/slide1.html,
we want to find the shortest path,
../sub3/sub31/,
to change from the first directory to the second one.
|
| Raw Input
|
| Desired Output
| ./pr1/sub3/sub31/slide1.html ./pr1/sub1/slide2.html
./top/index.html ./top/lecture1.html
./top/lecture1.html ./welcome.html
./top/lecture2.html ./pr1/sub1/slide1.html
./pr1/sub3/sub31/slide1.html ./pr2/slide1.html
|
| ../../sub1/
../
../pr1/sub1/
../../../pr2/
|
|
Script and Comments
Script1 [ 1] s#/[^/ ]*( |$)#/\1#g
[ 2] s#^(\./[^ ]+/)([^ ]*) \1#\2 #
[ 3] s#^\./##
[ 4] :loop
[ 5] s#(/|^)[^/]+/ #\1 ../#
[ 6] t loop
[ 7] s#/./#/#
[ 8] s# ##
| |
|