Mercurial > hg > toybox
annotate toys/posix/rmdir.c @ 1577:ac84a209cb05 draft
sed: c needs to trigger range logic like d, D works like d when there isn't anything left in the line, and more tests.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 27 Nov 2014 20:38:21 -0600 |
parents | fc1bb49e58a9 |
children |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
1 /* rmdir.c - remove directory/path |
290 | 2 * |
598
75a69d5550a0
Cosmetic tweak to command preamble.
Rob Landley <rob@landley.net>
parents:
290
diff
changeset
|
3 * Copyright 2008 Rob Landley <rob@landley.net> |
290 | 4 * |
598
75a69d5550a0
Cosmetic tweak to command preamble.
Rob Landley <rob@landley.net>
parents:
290
diff
changeset
|
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/rmdir.html |
290 | 6 |
7 USE_RMDIR(NEWTOY(rmdir, "<1p", TOYFLAG_BIN)) | |
8 | |
9 config RMDIR | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
10 bool "rmdir" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
11 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
12 help |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
13 usage: rmdir [-p] [dirname...] |
1333
fc1bb49e58a9
Help text should have a blank line after usage: lines, and a couple other whitespace tweaks.
Rob Landley <rob@landley.net>
parents:
782
diff
changeset
|
14 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
15 Remove one or more directories. |
290 | 16 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
17 -p Remove path. |
290 | 18 */ |
19 | |
20 #include "toys.h" | |
21 | |
22 static void do_rmdir(char *name) | |
23 { | |
782
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
24 char *temp; |
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
25 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
26 for (;;) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
27 if (rmdir(name)) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
28 perror_msg("%s",name); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
29 return; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
30 } |
782
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
31 |
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
32 // Each -p cycle back up one slash, ignoring trailing and repeated /. |
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
33 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
34 if (!toys.optflags) return; |
782
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
35 do { |
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
36 if (!(temp = strrchr(name, '/'))) return; |
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
37 *temp = 0; |
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
38 } while (!temp[1]); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
39 } |
290 | 40 } |
41 | |
42 void rmdir_main(void) | |
43 { | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
44 char **s; |
290 | 45 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
46 for (s=toys.optargs; *s; s++) do_rmdir(*s); |
290 | 47 } |