| 1 |
/* |
| 2 |
* Copyright 1999 by The XFree86 Project, Inc. |
| 3 |
*/ |
| 4 |
|
| 5 |
/* |
| 6 |
* Reverse a pathname. It returns a relative path that can be used to undo |
| 7 |
* 'cd argv[1]'. |
| 8 |
* |
| 9 |
* It is impossible to do this in general, but this handles the cases that |
| 10 |
* come up in imake. Maybe imake should use an absolute path for $(TOP) |
| 11 |
* instead of a relative path so that this problem can be avoided? |
| 12 |
*/ |
| 13 |
|
| 14 |
#include <stdio.h> |
| 15 |
#include <string.h> |
| 16 |
#include <stdlib.h> |
| 17 |
|
| 18 |
int |
| 19 |
main(int argc, char *argv[]) |
| 20 |
{ |
| 21 |
int levels = 0; |
| 22 |
char *p; |
| 23 |
|
| 24 |
/* Silently ignore invalid usage */ |
| 25 |
if (argc != 2) |
| 26 |
exit(0); |
| 27 |
|
| 28 |
/* Split the path and count the levels */ |
| 29 |
p = strtok(argv[1], "/"); |
| 30 |
while (p) { |
| 31 |
if (strcmp(p, ".") == 0) |
| 32 |
; |
| 33 |
else if (strcmp(p, "..") == 0) |
| 34 |
levels--; |
| 35 |
else |
| 36 |
levels++; |
| 37 |
p = strtok(NULL, "/"); |
| 38 |
} |
| 39 |
|
| 40 |
while (levels-- > 0) |
| 41 |
printf("../"); |
| 42 |
|
| 43 |
printf("\n"); |
| 44 |
|
| 45 |
exit(0); |
| 46 |
} |