commit 69eb6e669536bb7360bab5f1f99eddcfd4903438
Author: afify <hassan@afify.dev>
Date: Wed, 9 Mar 2022 10:20:09 +0300
first commit
Diffstat:
A | .clang-format | | | 95 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | LICENSE | | | 19 | +++++++++++++++++++ |
A | Makefile | | | 51 | +++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | config.mk | | | 14 | ++++++++++++++ |
A | nasmfm.c | | | 68 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 files changed, 247 insertions(+), 0 deletions(-)
diff --git a/.clang-format b/.clang-format
@@ -0,0 +1,95 @@
+---
+BasedOnStyle: WebKit
+---
+AccessModifierOffset: 8
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignConsecutiveMacros: 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
+ColumnLimit: 80
+CompactNamespaces: true
+UseTab: Always
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+DerivePointerAlignment: false
+DisableFormat: false
+IncludeBlocks: Regroup
+IndentCaseLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+KeepEmptyLinesAtTheStartOfBlocks: true
+Language: Cpp
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+PenaltyBreakBeforeFirstCallParameter: 1000
+PenaltyBreakComment: 10
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: true
+SpaceAfterCStyleCast: false
+TabWidth: 8
+
+IncludeCategories:
+ - Regex: '^\"opt_.*\.h\"'
+ Priority: 1
+ SortPriority: 10
+ - Regex: '^<sys/cdefs\.h>'
+ Priority: 2
+ SortPriority: 20
+ - Regex: '^<sys/types\.h>'
+ Priority: 2
+ SortPriority: 21
+ - Regex: '^<sys/param\.h>'
+ Priority: 2
+ SortPriority: 22
+ - Regex: '^<sys.*/'
+ Priority: 2
+ SortPriority: 23
+ - Regex: '^<vm/vm\.h>'
+ Priority: 3
+ SortPriority: 30
+ - Regex: '^<vm/'
+ Priority: 3
+ SortPriority: 31
+ - Regex: '^<machine/'
+ Priority: 4
+ SortPriority: 40
+ - Regex: '^<(x86|amd64|i386|xen)/'
+ Priority: 5
+ SortPriority: 50
+ - Regex: '^<dev/'
+ Priority: 6
+ SortPriority: 60
+ - Regex: '^<net.*/'
+ Priority: 7
+ SortPriority: 70
+ - Regex: '^<protocols/'
+ Priority: 7
+ SortPriority: 71
+ - Regex: '^<(fs|nfs(|client|server)|ufs)/'
+ Priority: 8
+ SortPriority: 80
+ - Regex: '^<[^/].*\.h'
+ Priority: 9
+ SortPriority: 90
+ - Regex: '^\".*\.h\"'
+ Priority: 10
+ SortPriority: 100
+...
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,19 @@
+ISC License
+
+© 2020-2021 Hassan Afify <hassan at afify dot dev>
+© 2020 Mohamed Afify <mohamed at afify dot dev>
+© 2021 Nikolay Korotkiy <sikmir@gmail.com>
+© 2021 David Kalliecharan <david@david.science>
+© 2021 Tdukv <tdukv@protonmail.com>
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/Makefile b/Makefile
@@ -0,0 +1,51 @@
+# nasmfm - simple file manager
+# See LICENSE file for copyright and license details.
+
+include config.mk
+
+SRC = nasmfm.c
+OBJ = ${SRC:.c=.o}
+
+all: options nasmfm
+
+options:
+ @echo nasmfm build options:
+ @echo "CFLAGS = ${CFLAGS}"
+ @echo "LDFLAGS = ${LDFLAGS}"
+ @echo "CC = ${CC}"
+
+.c.o:
+ ${CC} -c ${CFLAGS} $<
+
+${OBJ}: config.mk
+
+config.h:
+ cp config.def.h $@
+
+nasmfm: ${OBJ}
+ ${CC} ${LDFLAGS} -o $@ ${OBJ}
+
+clean:
+ rm -f nasmfm ${OBJ} nasmfm-${VERSION}.tar.gz
+
+dist: clean
+ mkdir -p nasmfm-${VERSION}
+ cp -R LICENSE Makefile README.md config.def.h config.mk\
+ nasmfm.1 nasmfm.png termbox.h util.h ${SRC} nasmfm-${VERSION}
+ tar -cf nasmfm-${VERSION}.tar nasmfm-${VERSION}
+ gzip nasmfm-${VERSION}.tar
+ rm -rf nasmfm-${VERSION}
+
+install: nasmfm
+ mkdir -p ${DESTDIR}${PREFIX}/bin
+ cp -f nasmfm ${DESTDIR}${PREFIX}/bin
+ chmod 755 ${DESTDIR}${PREFIX}/bin/nasmfm
+ mkdir -p ${DESTDIR}${MANPREFIX}/man1
+ sed "s/VERSION/${VERSION}/g" < nasmfm.1 > ${DESTDIR}${MANPREFIX}/man1/nasmfm.1
+ chmod 644 ${DESTDIR}${MANPREFIX}/man1/nasmfm.1
+
+uninstall:
+ rm -f ${DESTDIR}${PREFIX}/bin/nasmfm\
+ ${DESTDIR}${MANPREFIX}/man1/nasmfm.1
+
+.PHONY: all options clean dist install uninstall
diff --git a/config.mk b/config.mk
@@ -0,0 +1,14 @@
+# nasmfm version
+VERSION = 0.0
+
+# paths
+PREFIX = /usr/local
+MANPREFIX = ${PREFIX}/share/man
+
+# flags
+CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DVERSION=\"${VERSION}\"
+CFLAGS = -std=c99 -pedantic -Wextra -Wall -Wno-unused-parameter -Os ${CPPFLAGS}
+LDFLAGS = -pthread -s
+
+# compiler and linker
+CC = cc
diff --git a/nasmfm.c b/nasmfm.c
@@ -0,0 +1,68 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+
+/* macros */
+/* typedef */
+/* function declarations */
+/* global variables */
+/* function implementations */
+
+struct termios orig_termios;
+void
+die(const char *s)
+{
+ perror(s);
+ exit(1);
+}
+void
+disableRawMode()
+{
+ if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios) == -1)
+ die("tcsetattr");
+}
+
+void
+enableRawMode()
+{
+ if (tcgetattr(STDIN_FILENO, &orig_termios) == -1)
+ die("tcgetattr");
+ atexit(disableRawMode);
+ struct termios raw = orig_termios;
+
+ raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ raw.c_oflag &= ~(OPOST);
+ raw.c_cflag |= (CS8);
+ raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
+ raw.c_cc[VMIN] = 0;
+ raw.c_cc[VTIME] = 1;
+
+ if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw) == -1)
+ die("tcsetattr");
+}
+
+int
+main(int argc, char *argv[])
+{
+ enableRawMode();
+ while (1) {
+ char c = '\0';
+ if (read(STDIN_FILENO, &c, 1) == -1 && errno != EAGAIN)
+ die("read");
+ read(STDIN_FILENO, &c, 1);
+ if (iscntrl(c)) {
+ printf("%d\r\n", c);
+ } else {
+ printf("%d ('%c')\r\n", c, c);
+ }
+ if (c == 'q')
+ break;
+ }
+
+ return 0;
+}