# FIXPATH -- Remove trailing ".." from directory path, if present # B.Simon 04-Aug-92 original procedure fixpath (path) char path[ARB] # u: Directory pathname #-- int ic, nc, ipos, jpos, slash[3] int strncmp() begin # Save position of last three slashes in the directory path do ipos = 1, 3 slash[ipos] = 0 ipos = 1 for (ic = 1; path[ic] != EOS; ic = ic + 1) { if (path[ic] == '/') { ipos = mod (ipos, 3) + 1 slash[ipos] = ic } } # If the path does not terminate in a slash, # pretend there is one beyond the end of the string if (path[ic-1] != '/') { ipos = mod (ipos, 3) + 1 slash[ipos] = ic } # See if the string between the last two slashes is a ".." jpos = ipos - 1 if (jpos == 0) jpos = 3 ic = slash[jpos] + 1 nc = slash[ipos] - ic if (nc == 2) { if (strncmp ("..", path[ic], nc) == 0) { # If it is, truncate the string one more slash back jpos = jpos - 1 if (jpos == 0) jpos = 3 ic = slash[jpos] + 1 if (ic != 1) path[ic] = EOS } } end