#include #include #include int main(int ac, char *av[]) { size_t len; char *s, *t; s = av[1]; len = strlen(s); /* If string is a null string, it is unspecified whether the resulting * string is '.' or a null string. In either case, skip steps 2 through * 6. */ if (len == 0) { printf("\n"); exit(0); } /* * If string consists entirely of characters, string shall be * set to a single character. In this case, skip steps 4 to 6. */ while (*s == '/') { s++; len--; } if (*s == 0) { printf("/\n"); exit(0); } /* If there are any trailing characters in string, they shall * be removed. */ for (t = s+len-1; t > s; t--) { if (*t != '/') { break; } *t = 0; len--; } /* If there are any characters remaining in string, the prefix * of string up to and including the last character in string * shall be removed. */ for (t=s+len-1; t > s; t--) { if (*t == '/') { s = t+1; break; } } len = strlen(s); /* If the suffix operand is present, is not identical to the characters * remaining in string, and is identical to a suffix of the characters * remaining in string, the suffix suffix shall be removed from string. * Otherwise, string is not modified by this step. It shall not be * considered an error if suffix is not found in string. */ if (ac > 2) { size_t suflen; suflen = strlen(av[2]); if (suflen <= len && !strcmp(av[2], s+len-suflen)) { len -= suflen; *(s+len) = 0; } } printf("%s\n", s); return 0; }