Format elfdbg source code using clang-format
authorSofian Brabez <sbz@FreeBSD.org>
Tue, 20 Jan 2015 20:00:00 +0000 (20:00 +0000)
committerSofian Brabez <sbz@FreeBSD.org>
Tue, 20 Jan 2015 20:00:00 +0000 (20:00 +0000)
.clang-format [new file with mode: 0644]
elfdbg.1
elfdbg.c

diff --git a/.clang-format b/.clang-format
new file mode 100644 (file)
index 0000000..f671569
--- /dev/null
@@ -0,0 +1,67 @@
+# $FreeBSD$
+# Basic .clang-format
+---
+BasedOnStyle: WebKit
+AlignAfterOpenBracket: DontAlign
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: false
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: InlineOnly
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterReturnType: TopLevelDefinitions
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+BinPackArguments: true
+BinPackParameters: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: WebKit
+BreakBeforeTernaryOperators: false
+BreakStringLiterals: false
+PenaltyBreakBeforeFirstCallParameter: 1000
+CompactNamespaces: true
+DerivePointerAlignment: false
+DisableFormat: false
+ForEachMacros:
+  - SLIST_FOREACH
+  - SLIST_FOREACH_SAFE
+  - LIST_FOREACH
+  - LIST_FOREACH_SAFE
+  - STAILQ_FOREACH
+  - STAILQ_FOREACH_SAFE
+  - TAILQ_FOREACH
+  - TAILQ_FOREACH_SAFE
+  - TAILQ_FOREACH_REVERSE
+  - TAILQ_FOREACH_REVERSE_SAFE
+  - RB_FOREACH
+  - RB_FOREACH_SAFE
+  - RB_FOREACH_FROM
+  - RB_FOREACH_REVERSE
+  - RB_FOREACH_REVERSE_FROM
+  - RB_FOREACH_REVERSE_SAFE
+  - FOREACH_THREAD_IN_PROC
+  - FOREACH_PROC_IN_SYSTEM
+  - FOREACH_PRISON_CHILD
+  - FOREACH_PRISON_DESCENDANT
+  - FOREACH_PRISON_DESCENDANT_LOCKED
+  - FOREACH_PRISON_DESCENDANT_LOCKED_LEVEL
+  - MNT_VNODE_FOREACH_ALL
+  - MNT_VNODE_FOREACH_ACTIVE
+IndentCaseLabels: false
+IndentPPDirectives: None
+Language: Cpp
+NamespaceIndentation: None
+PointerAlignment: Right
+ContinuationIndentWidth: 4
+IndentWidth: 8
+TabWidth: 8
+ColumnLimit: 80
+UseTab: Always
+SpaceAfterCStyleCast: false
+SortIncludes: false
+KeepEmptyLinesAtTheStartOfBlocks: true
index 30916752c7831d95efdc5077673752f311c37058..6ad6bd26ad964bcebded648624b067e21e9ac14c 100644 (file)
--- a/elfdbg.1
+++ b/elfdbg.1
@@ -39,7 +39,8 @@ known as
 .Ar -g 
 compiler toolchain flag.
 .Sh SEE ALSO
-.Xr libelf 3 ,
+.Xr elf 3 , 
+.Xr gelf 3
 .Sh AUTHORS
 .An -nosplit
 The
index 7db5ea6f606729bb547b62defde694b97dbb88f6..a3676fad63af9f7921ed7581aecc3674b0f249d7 100644 (file)
--- a/elfdbg.c
+++ b/elfdbg.c
@@ -1,7 +1,7 @@
 /*-
  * Copyright (c) 2015 Sofian Brabez <sbz@FreeBSD.org>
  * All rights reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -11,7 +11,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 #include <unistd.h>
 
 static int
-elf_debug_sections(Elf *e) {
-        Elf_Scn *scn=NULL;
-        GElf_Shdr shdr;
-        size_t n, shstrndx, sz;
-        char *name;
-        int has_debug=0;
+elf_debug_sections(Elf *e)
+{
+       Elf_Scn *scn = NULL;
+       GElf_Shdr shdr;
+       size_t n, shstrndx, sz;
+       char *name;
+       int has_debug = 0;
 
-        if (elf_getshdrstrndx(e, &shstrndx) != 0)
-                errx(EX_SOFTWARE, "elf_getshdrstrndx() failed : %s . " , elf_errmsg(-1));
+       if (elf_getshdrstrndx(e, &shstrndx) != 0)
+               errx(EX_SOFTWARE, "elf_getshdrstrndx() failed : %s . ",
+                   elf_errmsg(-1));
 
-        while ((scn = elf_nextscn(e, scn)) != NULL) {
-                gelf_getshdr(scn, &shdr);
+       while ((scn = elf_nextscn(e, scn)) != NULL) {
+               gelf_getshdr(scn, &shdr);
 
-                name = elf_strptr(e, shstrndx, shdr.sh_name);
-                if (!strstr(name, "debug_"))
-                    continue;
+               name = elf_strptr(e, shstrndx, shdr.sh_name);
+               if (!strstr(name, "debug_"))
+                       continue;
 
-                has_debug++;
+               has_debug++;
+       }
 
-        }
-
-        return (has_debug > 0);
+       return (has_debug > 0);
 }
 
-int main(int argc, char *argv[]) {
-        int fd, rc;
-        Elf *e;
-        int has_debug;
+int
+main(int argc, char *argv[])
+{
+       int fd, rc;
+       Elf *e;
+       int has_debug;
 
-        if (elf_version(EV_CURRENT) == EV_NONE )
-                errx(EX_SOFTWARE, "ELF library initialization failed : %s ", elf_errmsg(-1));
+       if (elf_version(EV_CURRENT) == EV_NONE)
+               errx(EX_SOFTWARE, "ELF library initialization failed : %s ",
+                   elf_errmsg(-1));
 
-        if ((fd =open(argv [1], O_RDONLY , 0)) < 0)
-                err(EX_NOINPUT,"open %s failed ", argv [1]);
-        if ((e = elf_begin(fd, ELF_C_READ , NULL)) == NULL)
-                errx(EX_SOFTWARE, "elf_begin () failed : %s . ", elf_errmsg(-1));
-        if (elf_kind(e) != ELF_K_ELF)
-                errx(EX_DATAERR, "%s is not an ELF object . ", argv[1]);
+       if ((fd = open(argv[1], O_RDONLY, 0)) < 0)
+               err(EX_NOINPUT, "open %s failed ", argv[1]);
+       if ((e = elf_begin(fd, ELF_C_READ, NULL)) == NULL)
+               errx(EX_SOFTWARE, "elf_begin() failed : %s", elf_errmsg(-1));
+       if (elf_kind(e) != ELF_K_ELF)
+               errx(EX_DATAERR, "%s is not an ELF object", argv[1]);
 
-        has_debug=elf_debug_sections(e);
-        printf(has_debug ? "HAS DEBUG\n" : "NO DEBUG\n");
+       has_debug = elf_debug_sections(e);
+       printf(has_debug ? "HAS DEBUG\n" : "NO DEBUG\n");
 
-       rc=close(fd);
-       rc=elf_end(e);
+       rc = close(fd);
+       rc = elf_end(e);
 
        return (rc);
 }