2 Copyright © 2013 Alastair Stuart
4 This program is open source software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
18 #define VERSION "0.01"
20 int main(int argc
, char* argv
[])
23 printf("%s: missing operand\n"
24 "Run '%s --help' for usage.\n",
33 for (arg
= 1; arg
< argc
; arg
++)
35 if (strcmp(argv
[arg
], "-z") == 0 || strcmp(argv
[arg
], "--zero") == 0) {
37 } else if (strcmp(argv
[arg
], "-h") == 0 || strcmp(argv
[arg
], "--help") == 0) {
38 printf("Usage: %s [options ...] [name ...]\n", argv
[0]);
39 printf("Output each [name] with its last non-slash component and trailing slashes removed.\n"
40 "If [name] contains no /'s, then output is '.' (meaning the current directory)."
42 " -z, --zero Separate output with NUL rather than newline.\n"
44 " -h, --help Print this message.\n"
45 " -v, --version Show version info.\n");
47 } else if (strcmp(argv
[arg
], "-v") == 0 || strcmp(argv
[arg
], "--version") == 0) {
48 printf("dirname (mutos) v"VERSION
"\n");
56 for ( ; arg
< argc
; arg
++)
59 for (size_t i
= 0; i
< strlen(argv
[arg
]); i
++)
61 if (argv
[arg
][i
] == '/' && i
!= strlen(argv
[arg
]) - 1) {
65 if (last_slash
== -1) {
68 argv
[arg
][last_slash
] = '\0';
70 printf("%s%c", argv
[arg
], sep
);