diff options
-rw-r--r-- | .clang-format | 48 | ||||
-rw-r--r-- | CONTRIBUTING.md | 33 | ||||
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | walk.c | 20 |
5 files changed, 68 insertions, 49 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..4390d2b --- /dev/null +++ b/.clang-format @@ -0,0 +1,48 @@ +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +IndentWidth: 8 +ContinuationIndentWidth: 8 +SpacesBeforeTrailingComments: 2 +SpacesInContainerLiterals: false +UseTab: Always + +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false + +AlignAfterOpenBracket: DontAlign +AlignEscapedNewlines: DontAlign +AlignOperands: false +AlignTrailingComments: false +AllowShortIfStatementsOnASingleLine: Always +AllowShortLoopsOnASingleLine: true +BreakBeforeBinaryOperators: NonAssignment +BreakStringLiterals: false +KeepEmptyLinesAtTheStartOfBlocks: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index d0c4879..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,33 +0,0 @@ -How to contribute -================= - -We'd love to accept your patches and contributions to this project. There are -just a few small guidelines you need to follow. - - -Contributor License Agreement ------------------------------ - -Contributions to this project must be accompanied by a Contributor License -Agreement. You (or your employer) retain the copyright to your contribution; -this simply gives us permission to use and redistribute your contributions as -part of the project. Head over to <https://cla.developers.google.com/> to see -your current agreements on file or to sign a new one. - -You generally only need to submit a CLA once, so if you've already submitted one -(even if it was for a different project), you probably don't need to do it -again. - - -Submitting code ---------------- - -Submit patches either via a GitHub pull request or by sending mail to -bbaren@google.com. - - -Community Guidelines --------------------- - -This project follows -[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). @@ -13,9 +13,19 @@ # limitations under the License. CFLAGS = -Wall -O2 +prefix ?= /usr/local +bindir ?= $(prefix)/bin +mandir ?= $(prefix)/share/man .DEFAULT_GOAL := walk .PHONY: clean clean: $(RM) walk + +.PHONY: install +install: sor sor.1 walk walk.1 + mkdir -p "$(bindir)" "$(mandir)/man1" + install -c sor walk "$(bindir)" + gzip -9 <sor.1 >"$(mandir)/man1/sor.1.gz" + gzip -9 <walk.1 >"$(mandir)/man1/walk.1.gz" @@ -65,9 +65,3 @@ History [Dan Cross]: http://pub.gajendra.net/about [Plan 9 from Bell Labs]: https://web.archive.org/web/20170601064029/http://plan9.bell-labs.com/plan9/index.html [original source]: https://web.archive.org/web/http://plan9.bell-labs.com/sources/contrib/cross/ - - -Disclaimer ----------- - -This is not an official Google product. @@ -56,7 +56,8 @@ static void strcpy3(char *dest, const char *s1, const char *s2, const char *s3) stpcpy(stpcpy(stpcpy(dest, s1), s2), s3); } -static void put_filename(const char *filename, bool null_terminate) { +static void put_filename(const char *filename, bool null_terminate) +{ if (null_terminate) { fputs(filename, stdout); fputc(0, stdout); @@ -81,21 +82,20 @@ static int walk(const char dirname[], bool null_terminate) int r = 0; char *filename = NULL; for (const struct dirent *f = readdir2(dir); f; f = readdir2(dir)) { - if (strcmp(f->d_name, ".") == 0 - || strcmp(f->d_name, "..") == 0) + if (strcmp(f->d_name, ".") == 0 || strcmp(f->d_name, "..") == 0) continue; - filename = xrealloc(filename, - strlen(dirname) + 1 + strlen(f->d_name) + 1); + filename = xrealloc( + filename, strlen(dirname) + 1 + strlen(f->d_name) + 1); strcpy3(filename, dirname, "/", f->d_name); // TODO(bbaren@google.com): Emulate Plan 9's cleanname(3). put_filename(filename, null_terminate); // Walk the file if we can successfully open it as a directory. // Don't worry about it if it's not one (walk(filename) == 2). if ((f->d_type == DT_DIR || f->d_type == DT_UNKNOWN) - && walk(filename, null_terminate) == 1) + && walk(filename, null_terminate) == 1) r = 1; } - if (errno) { // from readdir + if (errno) { // from readdir perror(dirname); r = 1; } @@ -117,8 +117,7 @@ int main(const int argc, char *const argv[]) bool null_terminate = false; while (true) { const int c = getopt_long(argc, argv, "0", long_options, NULL); - if (c == -1) - break; + if (c == -1) break; switch (c) { case 'h': fputs(SHORT_USAGE, stdout); @@ -137,7 +136,8 @@ int main(const int argc, char *const argv[]) } int r = 0; - const char *const *const dirs = argc == optind ? JUST_CURRENT_DIRECTORY + const char *const *const dirs = argc == optind + ? JUST_CURRENT_DIRECTORY : (const char *const *)argv + optind; for (int i = 0; dirs[i]; ++i) { put_filename(dirs[i], null_terminate); |