00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <string.h>
00020 #include <stdio.h>
00021
00022 int main(int argc, char **argv)
00023 {
00024 char *p;
00025 char *path;
00026
00027 if (argc != 2) {
00028 fprintf(stderr, "Usage: %s path\n", argv[0]);
00029 return(1);
00030 }
00031 path = argv[1];
00032 p = path + strlen(path);
00033 while (p > path && p[-1] == '/') p--;
00034 while (p > path && p[-1] != '/') p--;
00035 while (p > path && p[-1] == '/') p--;
00036 if (p == path) {
00037 printf(path[0] == '/' ? "/\n" : ".\n");
00038 } else {
00039 printf("%.*s\n", (int) (p - path), path);
00040 }
00041 return(0);
00042 }