summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md41
-rwxr-xr-xconfigure147
-rw-r--r--contrib/build-env-setup/README.md60
-rw-r--r--contrib/build-env-setup/setup27
-rw-r--r--src/bulk_ln.c (renamed from src/bulk_ln/bulk_ln.c)199
-rw-r--r--src/bulk_ln/bulk_ln.h10
-rw-r--r--src/bulk_ln/bulk_ln_main.c10
-rw-r--r--src/common/commonbase.h23
8 files changed, 157 insertions, 360 deletions
diff --git a/README.md b/README.md
index 286ca54..0dd9bc0 100644
--- a/README.md
+++ b/README.md
@@ -6,41 +6,30 @@ BulkLn
create many links.
-## How to build / install
-
-Classic way:
+## How to build
```sh
-curl -sSL http://git.hiddenalpha.ch/bulk-ln.git/snapshot/bulk-ln-master.tar.gz | tar xz
-cd bulk-ln-master
-./configure
-make
-make install
+git init -b none
+git fetch --depth=1 http://git.hiddenalpha.ch/bulk-ln.git master:master
+git checkout master
+lua src/bulk_ln.c
+./bulk-ln --help
```
-In case you prefer more sustainable build environments,
-"./contrib/build-env-setup/README.md"
-potentially is interesting for you.
-
-
## Stats For Nerds
```text
github.com/AlDanial/cloc
--------------------------------------------------
-Language files blank comment code
--------------------------------------------------
-C 2 66 79 294
-Bourne Shell 1 23 7 117
-Markdown 1 16 0 29
-C/C++ Header 2 13 5 15
--------------------------------------------------
-SUM: 6 118 91 455
--------------------------------------------------
+-------------------------------------
+Language files blank comment code
+-------------------------------------
+C 1 71 87 356
+Markdown 1 13 0 24
+Text 1 5 0 16
+-------------------------------------
+SUM: 3 89 87 396
+-------------------------------------
```
-
-
-
diff --git a/configure b/configure
deleted file mode 100755
index ba4317f..0000000
--- a/configure
+++ /dev/null
@@ -1,147 +0,0 @@
-#!/bin/sh
-set -e
-if test -n "$BASH_VERSION"; then set -o posix; fi
-
-# See https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
-prefix=/usr/local
-exec_prefix='$(PREFIX)'
-exec_suffix=
-bindir='$(EXEC_PREFIX)/bin'
-verbose=0
-
-
-main() {
- parseArgs "$@"
- printMakefile > Makefile
-}
-
-
-printHelp() {
- echo ''
- echo "Example usage: $0 --prefix /usr/local"
- echo ''
- echo 'Options:'
- echo ' --prefix "/usr/local"'
- echo ' --exec-prefix "$(PREFIX)"'
- echo ' --exec-suffix ""'
- echo ' --bindir "$(EXEC_PREFIX)/bin"'
- echo ' --verbose 0'
- echo ''
-}
-
-
-parseArgs() {
- # See: https://stackoverflow.com/a/14203146/4415884
- while test $# -gt 0 ; do
- case $1 in
- --help) printHelp; exit 1; ;;
- --prefix) prefix="$2" shift; shift; ;;
- --exec-prefix) exec_prefix="$2" shift; shift; ;;
- --exec-suffix) exec_suffix="$2" shift; shift; ;;
- --bindir) bindir="$2" shift; shift; ;;
- --verbose) verbose="$2" shift; shift; ;;
- *) echo "[ERROR] Unexpected argument: $1"; exit 1 ;;
- esac
- done
- if test "$verbose" != "0" -a "$verbose" != "1"; then
- echo "[ERROR] verbose expected to be 0 or 1. But is: $verbose";
- false;
- fi
-}
-
-
-printMakefile () {
- printf '\n'
- printf '%s\n' '# This file is generated by configure script. Manual changes may be lost'
- printf '%s\n' '# when calling configure again.'
- printf '\n'
- printf '%s\n' 'CC=gcc'
- printf '%s\n' 'LD=gcc'
- printf '%s\n' 'TAR=tar'
- printf '%s\n' 'MKDIRS=mkdir -p'
- printf '%s\n' 'RIMRAF=rm -rf'
- printf '%s\n' 'COPYTO=cp -t'
- printf '%s\n' "PREFIX=$prefix"
- printf '%s\n' "EXEC_PREFIX=$exec_prefix"
- printf '%s\n' "EXEC_SUFFIX=$exec_suffix"
- printf '%s\n' "BINDIR=$bindir"
-
- # If PROJECT_VERSION set, use it.
- # If not, try generate via git describe.
- # If fails (eg git not avail), create pseudo version using date.
- printf '%s' 'PROJECT_VERSION=$(shell'
- printf '%s' ' ret=$$(git describe --tags 2>/dev/null |sed -E "s;^v;;");'
- printf '%s' ' if test -n "$$ret" -a -n "$$(git status --porcelain 2>/dev/null)"; then'
- printf '%s' ' ret="$$ret+dirt";'
- printf '%s' ' fi;'
- printf '%s' ' if test -z "$$ret"; then ret=$$(date -u +0.0.0-%Y%m%d.%H%M%S); fi;'
- printf '%s\n' ' echo "$$ret")'
-
- printf '\n'
- printf '%s' 'CFLAGS= --std=c99 -Wall -Wextra -Werror -Isrc/bulk_ln -Isrc/common -Os -DPROJECT_VERSION=$(PROJECT_VERSION)'
- printf '%s\n' ''
- printf '%s\n' 'LDFLAGS= -Wl,--fatal-warnings,--gc-sections,--as-needed -s'
-
- if test "$verbose" = "0"; then
- printf '\n'
- printf '%s\n' '.SILENT:';
- fi
-
- printf '\n'
- printf '%s\n' 'default: link dist'
-
- printf '\n'
- printf '%s\n' '.PHONY: clean'
- printf '%s\n' 'clean:'
- printf '%s\n' ' echo $(RIMRAF) build dist'
- printf '%s\n' ' $(RIMRAF) build dist'
-
- printf '\n'
- printf '%s\n' '.PHONY: link'
- printf '%s\n' 'link: build/bin/bulk-ln$(EXEC_SUFFIX)'
-
- printf '\n'
- printf '%s\n' 'build/obj/%.o: src/%.c'
- printf '%s\n' ' echo " CC $@"'
- printf '%s\n' ' $(MKDIRS) "$(shell T=$@; echo $${T%/*})"'
- printf '%s\n' ' $(CC) -c -o $@ $^ $(CFLAGS)'
-
- printf '\n'
- printf '%s' 'build/bin/bulk-ln$(EXEC_SUFFIX):'
- # dependencies
- printf '%s' ' build/obj/bulk_ln/bulk_ln.o'
- printf '%s' ' build/obj/bulk_ln/bulk_ln_main.o'
- printf '\n' # commands
- printf '%s\n' ' echo " LN $@"'
- printf '%s\n' ' $(MKDIRS) "$(shell T=$@; echo $${T%/*})"'
- printf '%s\n' ' $(LD) -o $@ $(LDFLAGS) $^'
-
- printf '\n'
- printf '%s\n' '.PHONY: dist'
- printf '%s\n' 'dist: link'
- printf '%s\n' ' echo " Package"'
- printf '%s\n' ' $(RIMRAF) build/dist-* dist'
- printf '%s\n' ' $(MKDIRS) dist'
- # Create Executable bundle.
- printf '%s\n' ' $(MKDIRS) build/dist-bin && $(COPYTO) build/dist-bin \'
- printf '%s\n' ' README*'
- printf '%s\n' ' $(MKDIRS) build/dist-bin/bin && $(COPYTO) build/dist-bin/bin \'
- printf '%s\n' ' build/bin/*'
-
- printf '%s\n' ' (cd build/dist-bin && find . -type f -not -name MD5SUM -exec md5sum -b {} +) > build/dist-bin/MD5SUM'
-
- printf '%s\n' ' (cd build/dist-bin && $(TAR) --owner=0 --group=0 -czf "../../dist/BulkLn-$(PROJECT_VERSION).tgz" *)'
- printf '%s\n' ' echo "" && echo "See '\''./dist/'\'' for result." && echo ""'
- printf '%s' ' if test -n "$$(git status --porcelain 2>/dev/null)"; then'
- printf '%s' ' echo "[WARN ] Worktree dirty!"; sleep 2;'
- printf '%s\n' ' fi'
-
- printf '\n'
- printf '%s\n' '.PHONY: install'
- printf '%s\n' 'install:'
- printf '%s\n' ' $(MKDIRS) "$(BINDIR)"'
- printf '%s\n' ' $(TAR) --strip-components=1 -C "$(BINDIR)" -xzf "$(shell ls dist/BulkLn-*.tgz)" -- bin'
-}
-
-
-main "$@"
diff --git a/contrib/build-env-setup/README.md b/contrib/build-env-setup/README.md
deleted file mode 100644
index 90322f7..0000000
--- a/contrib/build-env-setup/README.md
+++ /dev/null
@@ -1,60 +0,0 @@
-
-Showcase how to build and install
-=================================
-
-WARN: Do NOT perform any of these steps on your host system! This script
- MUST only be run on a system which is a
- just-throw-it-away-if-broken system.
-
-Sometimes happy developers (like me) have no choice but using terribly
-restricted systems where setting up tools to run even something as
-trivial as configure/make/install becomes a nightmare if not impossible.
-I found it to be very handy to have some independent qemu VM at hand
-which lets me install whatever I need, neither with any special software
-nor any annoying privileges on a host machine. Qemu runs portable and in
-user mode even doesn't need any annoying permissions at all.
-
-
-## Setup a minimal system in your qemu VM
-
-This setup mainly targets debian. Nevertheless it tries to stay POSIX
-compatible as far as possible. So setup a minimal install of your system
-of choice and then as soon you've SSH access to a (posix) shell, you're
-ready for the next step.
-
-Still not sure which system to use? Link below provides some candidates.
-HINT: Windows IMHO is a terrible choice. So stop complaining if you go
-this route.
-
-https://en.wikipedia.org/wiki/POSIX#POSIX-oriented_operating_systems
-
-
-## Start VM with SSH access
-
-Easiest way to work with your machine is via SSH. Therefore if you've
-chosen to use a qemu VM, make sure you've setup and configured sshd
-properly inside the VM. Then just pass args like those to qemu:
-
- --device e1000,netdev=n0 --netdev user,id=n0,hostfwd=tcp:127.0.0.1:2222-:22
-
-Started this way, the SSHDaemon inside the VM is accessible from your
-host via "localhost" at port "2222":
-
- ssh localhost -p2222
-
-
-## Finalize by build and install whole project
-
-Run the "./setup" script (which is a posix shell script btw) inside the
-freshly setup system. This script does all the work. Like installing
-required packages, configure and build the whole project and finally
-installing it into the VM so it can be tried out right away from your
-VMs shell.
-BTW: The script is constructed so it can be copy-pasted into a terminal.
-There is no need to transfer a file to the machine beforehand.
-
-
-
-
-
-
diff --git a/contrib/build-env-setup/setup b/contrib/build-env-setup/setup
deleted file mode 100644
index f5f51ce..0000000
--- a/contrib/build-env-setup/setup
+++ /dev/null
@@ -1,27 +0,0 @@
-
-echo "WARN: read (AND UNDERSTAND) the README before running this script!"
-sleep 3
-exit 1
-
-
-true \
- && GIT_TAG="master" \
- && CONFIGURE_OPTS= \
- && WORKDIR="${HOME:?}/work" \
- && PKGS_TO_ADD="ca-certificates curl gcc git make libc-dev tar" \
- && SUDO=sudo \
- && PKGINIT="$SUDO apt update" \
- && PKGADD="$SUDO apt install -y --no-install-recommends" \
- && `# prepare` \
- && mkdir -p "${WORKDIR:?}" && cd "${WORKDIR:?}" \
- && ${PKGINIT:?} && ${PKGADD:?} $PKGS_TO_ADD \
- && git clone --depth 42 --branch "${GIT_TAG:?}" https://github.com/hiddenalpha/bulk-ln.git . \
- && git config advice.detachedHead false \
- && git checkout "${GIT_TAG:?}" \
- && ./configure $CONFIGURE_OPTS \
- && make clean && make -j$(nproc) \
- && $SUDO make install \
- && dirOfDistBundle="$(realpath dist)" \
- && printf '\n SUCCESS :) Distribution bundle is ready in:\n\n %s\n\n Tip: Before pulling out your hair about how to get that archive out of\n your qemu VM. STOP kluding around with silly tools and learn how\n basic tools do the job perfectly fine:\n\n ssh %s@localhost -p%d -T '\''true && cd "%s" && tar c *'\'' | tar x\n\n BTW: In addition bulk-ln got installed and is ready-to-use.\n\n' "${dirOfDistBundle:?}" "$USER" "$(env|grep SSH_CLIENT|cut -d' ' -f3)" "${dirOfDistBundle:?}" \
- && true
-
diff --git a/src/bulk_ln/bulk_ln.c b/src/bulk_ln.c
index ffd360a..f3cda22 100644
--- a/src/bulk_ln/bulk_ln.c
+++ b/src/bulk_ln.c
@@ -1,8 +1,59 @@
+#if 0
+--[===========================================================================[
-/* This */
-#include "bulk_ln.h"
+ How to build:
+
+ lua src/bulk_ln.c
+
+ How to use:
+
+ ./bulk-ln --help
+
+ ]===========================================================================]
+function shEsc(s)return "'".. s:gsub("'", "'\"'\"'") .."'" end
+do
+ local thisFile = debug.getinfo(1,"S").source:sub(2)
+ local sh = io.popen("sh", "w")
+ assert(sh, "Failed to launch a shell")
+ sh:write([=[set -e \
+ \
+ && CC="${CC:-gcc}" \
+ && LD="${LD:-gcc}" \
+ && OBJDUMP="${OBJDUMP:-objdump}" \
+ && RIMRAF="${RIMRAF:-rm -rf}" \
+ && BINEXT="${BINEXT:-}" \
+ && CFLAGS="${CFLAGS:- -std=c99 -Wall -Werror -pedantic -nostdlib -nodefaultlibs}" \
+ && LDFLAGS="${LDFLAGS:-}" \
+ && TMPDIR="${TMPDIR:-/tmp}" \
+ && OUTFILE="bulk-ln${BINEXT?}" \
+ \
+ && if test -z "$PROJECT_VERSION" ;then true \
+ && tag="$(git tag|grep -E '^v'|sed -E 's,^v,,'|sort -V|tail -n1)" \
+ && cnt="$(git rev-list --count "v${tag:?}"..HEAD)" \
+ && hsh="$(git rev-parse --short HEAD)" \
+ && if test -n "$tag" -a -n "$cnt" -a -n "$hsh" ;then true \
+ && PROJECT_VERSION="${tag:?}-${cnt:?}-g${hsh:?}" \
+ ;else true \
+ && PROJECT_VERSION="$(date -u +0.0.0-%Y%m%d.%H%M%S)" \
+ ;fi \
+ ;fi \
+ \
+ && ${CC:?} -c -o "${TMPDIR:?}"/YC71NcBIJMwpwUfL ]=].. shEsc(thisFile) ..[=[ ${CFLAGS?} -DPROJECT_VERSION="${PROJECT_VERSION:?}" -DEXPOSE_MAIN=1 \
+ && ${LD:?} -o ./"${OUTFILE:?}" "${TMPDIR:?}"/YC71NcBIJMwpwUfL ${LDFLAGS?} \
+ && ${RIMRAF:?} "${TMPDIR:?}"/YC71NcBIJMwpwUfL \
+ && bullshit=$(${OBJDUMP?} -p "${OUTFILE:?}"|grep DLL\ Name|egrep -v ' (KERNEL32.dll|SHELL32.dll|WS2_32.dll|ADVAPI32.dll|msvcrt.dll|GDI32.dll|USER32.dll)$'||true) \
+ && if test -n "$bullshit"; then printf '\n ERROR: Bullshit has sneaked in:\n\n%s\n\n' "$bullshit"; rm "${OUTFILE:?}"; false; fi \
+]=])
+ -- Shitty systems maybe need adaptions like:
+ -- && LDFLAGS="-Wl,-lws2_32,-l:libwinpthread.a" \
+ local ok, how, code = sh:close()
+ if not ok then os.exit(code) end
+end
+--[===========================================================================[
+#endif
+
+#define _POSIX_C_SOURCE 200809L
-/* System */
#include <assert.h>
#include <errno.h>
#include <stdio.h>
@@ -11,53 +62,69 @@
#include <sys/stat.h>
#include <unistd.h>
+#define STR_QUOT_IAHGEWIH(s) #s
+#define STR_QUOT(s) STR_QUOT_IAHGEWIH(s)
-#define DATA_FILE_FIELD_SEP_CHR '\t'
+#ifndef PRIVATE
+# define PRIVATE(T) static T
+#endif
-typedef int bool;
-typedef struct BulkLn BulkLn;
+#ifndef DATA_FILE_FIELD_SEP_CHR
+# define DATA_FILE_FIELD_SEP_CHR '\t'
+#endif
-/* Root context */
-struct BulkLn {
+typedef struct BulkLn {
+ /* Root context
+ */
- /** File (path) where we read the paths-to-link from. The special
- * value - (dash) means to use the stdin stream. */
char *dataFilePath;
+ /* File (path) where we read the paths-to-link from. The special
+ * value - (dash) means to use the stdin stream.
+ */
FILE *dataFd;
- /** Count of links we created */
int createdLinksCount;
+ /* Count of links we created
+ */
- /** Count of direcrories we created */
int createdDirsCount;
+ /* Count of direcrories we created
+ */
- /** If a dry-run got requested */
- bool dryRun;
+ int dryRun;
+ /* If a dry-run got requested
+ */
- /** If true, we will print to stdout for every link we create (like we do
- * in dry run) */
- bool isPrintEachCreateLink;
+ int isPrintEachCreateLink;
+ /* If true, we will print to stdout for every link we create (like we do
+ * in dry run)
+ 0*/
- /** print every call we make to mkdir to stdout. Usually only useful for
- * debugging */
- bool isPrintEachMkdir;
+ int isPrintEachMkdir;
+ /* print every call we make to mkdir to stdout. Usually only useful for
+ * debugging
+ */
- /** if true, we periodically print some kind of progress to stderr */
- bool isPrintStatus;
+ int isPrintStatus;
+ /* if true, we periodically print some kind of progress to stderr
+ */
- /** if true, we print a summary what we did at the end of the run to stderr */
- bool isPrintSummary;
+ int isPrintSummary;
+ /* if true, we print a summary what we did at the end of the run to stderr
+ */
- /** if true, we will override existing files. This will be enabled for
- * example if --force got specified. */
- bool isRelinkExistingFiles;
-};
+ int isRelinkExistingFiles;
+ /* if true, we will override existing files. This will be enabled for
+ * example if --force got specified.
+ */
+} BulkLn;
-static void printHelp(){
+PRIVATE(void)
+printHelp(){
printf(" \n %s @ " STR_QUOT(PROJECT_VERSION) "\n"
" \n"
" Takes paths (pairwise) from stdin (see --stdin for details) and\n"
@@ -109,7 +176,8 @@ static void printHelp(){
/** returns non-zero on errors. Error messages will already be printed
* internally. */
-static int parseArgs( int argc, char**argv, BulkLn*bulkLn ){
+PRIVATE(int)
+parseArgs( int argc, char**argv, BulkLn*bulkLn ){
/* init (aka set defaults) */
bulkLn->dataFilePath = NULL;
bulkLn->dryRun = 0;
@@ -119,7 +187,7 @@ static int parseArgs( int argc, char**argv, BulkLn*bulkLn ){
bulkLn->isPrintSummary = !0;
bulkLn->isRelinkExistingFiles = 0;
- // Parse args
+ /* Parse args */
for( int i = 1 ; i < argc ; ++i ){
char *arg = argv[i];
if( !strcmp(arg, "--help") ){
@@ -170,7 +238,8 @@ static int parseArgs( int argc, char**argv, BulkLn*bulkLn ){
* WARN: Passed 'path' might be temporarily changed during execution.
* Nevertheless will be in original state after return.
*/
-static int mkdirs( char*path, BulkLn*bulkLn ){
+PRIVATE(int)
+mkdirs( char*path, BulkLn*bulkLn ){
int err;
char *tmpEnd = path;
/* Backup original length so we later still can recognize the original end
@@ -211,7 +280,7 @@ static int mkdirs( char*path, BulkLn*bulkLn ){
/* Fine :) So just continue with the next one. */
}else{
fprintf(stderr, "mkdir(\"%s\"): %s\n", path, strerror(errno));
- err = -1; goto finally;
+ err = -1; goto resolveWithErr;
}
}else{
/* Only increment the directory counter if we really created
@@ -238,13 +307,14 @@ static int mkdirs( char*path, BulkLn*bulkLn ){
}
err = 0;
-finally:
+resolveWithErr:
return err;
}
/** Like: ln srcPath dstPath */
-static int createHardlink( char*srcPath, char*dstPath, BulkLn*bulkLn ){
+PRIVATE(int)
+createHardlink( char*srcPath, char*dstPath, BulkLn*bulkLn ){
int err;
if( bulkLn->dryRun || bulkLn->isPrintEachCreateLink ){
@@ -264,26 +334,27 @@ static int createHardlink( char*srcPath, char*dstPath, BulkLn*bulkLn ){
}else{
/* Some other (unepxected) error */
fprintf(stderr, "unlink(%s): %s\n", dstPath, strerror(errno));
- err = -1; goto finally;
+ err = -1; goto resolveWithErr;
}
}
}
err = link(srcPath, dstPath);
if( err ){
fprintf(stderr, "link(\"%s\", \"%s\"): %s\n", srcPath, dstPath, strerror(errno));
- err = -1; goto finally;
+ err = -1; goto resolveWithErr;
}
}
bulkLn->createdLinksCount += 1;
err = 0;
-finally:
+resolveWithErr:
return err;
}
-static int onPathPair( char*srcPath, char*dstPath, BulkLn*bulkLn ){
+PRIVATE(int)
+onPathPair( char*srcPath, char*dstPath, BulkLn*bulkLn ){
assert(srcPath != NULL);
assert(dstPath != NULL);
assert(bulkLn != NULL);
@@ -303,19 +374,20 @@ static int onPathPair( char*srcPath, char*dstPath, BulkLn*bulkLn ){
err = mkdirs(dstPath, bulkLn);
/* Restore path */
tmpEnd[0] = '/';
- if( err ){ err = -1; goto finally; }
+ if( err ){ err = -1; goto resolveWithErr; }
}
err = createHardlink(srcPath, dstPath, bulkLn);
- if( err ){ err = -1; goto finally; }
+ if( err ){ err = -1; goto resolveWithErr; }
err = 0;
-finally:
+resolveWithErr:
return err;
}
-static int parseDataFileAsPairPerLine( BulkLn*bulkLn ){
+PRIVATE(int)
+parseDataFileAsPairPerLine( BulkLn*bulkLn ){
int err;
size_t buf_cap = 0;
size_t buf_len = 0;
@@ -328,13 +400,13 @@ static int parseDataFileAsPairPerLine( BulkLn*bulkLn ){
/* Read input line-by-line. Not the most elegant way to parse stuff,
* but should suffice for our use-case */
err = getline(&buf, &buf_cap, bulkLn->dataFd);
- if(unlikely( err < 0 )){
+ if( err < 0 ){
/* Error handling */
if( feof(bulkLn->dataFd) ){
break; /* End-Of-File. Just break off the loop */
}else if( ferror(bulkLn->dataFd) ){
fprintf(stderr, "getline(%s): %s\n", bulkLn->dataFilePath, strerror(errno));
- err = -1; goto finally;
+ err = -1; goto resolveWithErr;
}else{
abort(); /* I don't know how this could happen */
}
@@ -347,20 +419,20 @@ static int parseDataFileAsPairPerLine( BulkLn*bulkLn ){
if( tab == NULL ){
fprintf(stderr, "Too few field separators (tab) in '%s' @ %lu\n",
bulkLn->dataFilePath, lineNum);
- err = -1; goto finally;
+ err = -1; goto resolveWithErr;
}
char *unwantedTab = memchr(tab + 1, DATA_FILE_FIELD_SEP_CHR, buf_len - (tab + 1 - buf));
if( unwantedTab != NULL ){
fprintf(stderr, "Too many field separators (tab) in '%s' line %lu\n",
bulkLn->dataFilePath, lineNum);
- err = -1; goto finally;
+ err = -1; goto resolveWithErr;
}
char *dstPath = tab + 1; /* <- path starts one char after the separator */
char *dstPath_end = buf + buf_len;
for(;; --dstPath_end ){
- if(unlikely( dstPath_end < buf )){
+ if( dstPath_end < buf ){
fprintf(stderr, "IMHO cannot happen %s:%d\n", __FILE__, __LINE__);
- err = -1; goto finally;
+ err = -1; goto resolveWithErr;
}
if( dstPath_end[0]=='\n' || dstPath_end[0]=='\0' || dstPath_end[0]=='\r' ){
continue; /* last char not found yet */
@@ -377,7 +449,7 @@ static int parseDataFileAsPairPerLine( BulkLn*bulkLn ){
/* Publish this pair for processing */
err = onPathPair(srcPath, dstPath, bulkLn);
- if( err ){ err = -1; goto finally; }
+ if( err ){ err = -1; goto resolveWithErr; }
}
if( bulkLn->isPrintStatus ){
@@ -385,19 +457,20 @@ static int parseDataFileAsPairPerLine( BulkLn*bulkLn ){
}
err = 0;
-finally:
+resolveWithErr:
free(buf);
return err;
}
-int bulk_ln_main( int argc, char**argv ){
+int
+bulk_ln_main( int argc, char**argv ){
int err;
BulkLn bulkLn = {0};
#define bulkLn (&bulkLn)
err = parseArgs(argc, argv, bulkLn);
- if( err ){ err = -1; goto finally; }
+ if( err ){ err = -1; goto resolveWithErr; }
/* Open data source */
if( !strcmp(bulkLn->dataFilePath, "-") ){
@@ -406,12 +479,12 @@ int bulk_ln_main( int argc, char**argv ){
bulkLn->dataFd = fopen(bulkLn->dataFilePath, "rb");
if( bulkLn->dataFd == NULL ){
fprintf(stderr, "fopen(%s): %s\n", bulkLn->dataFilePath, strerror(errno));
- err = -1; goto finally;
+ err = -1; goto resolveWithErr;
}
}
err = parseDataFileAsPairPerLine(bulkLn);
- if( err ){ err = -1; goto finally; }
+ if( err ){ err = -1; goto resolveWithErr; }
if( bulkLn->isPrintSummary ){
fprintf(stderr, "Created %d directories and linked %d files.\n",
@@ -419,11 +492,23 @@ int bulk_ln_main( int argc, char**argv ){
}
err = 0;
-finally:
+resolveWithErr:
if( bulkLn->dataFd != NULL && bulkLn->dataFd != stdin ){
fclose(bulkLn->dataFd);
}
- return -err;
+ return err;
#undef bulkLn
}
+
+#if EXPOSE_MAIN
+int
+main( int argc, char**argv ){
+ argc = bulk_ln_main(argc, argv);
+ if( argc < 0 ) argc = -argc;
+ return (argc >= 0 && argc <= 0x7F) ? argc : 1;
+}
+#endif
+
+
+/*]===========================================================================]--*/
diff --git a/src/bulk_ln/bulk_ln.h b/src/bulk_ln/bulk_ln.h
deleted file mode 100644
index 6054386..0000000
--- a/src/bulk_ln/bulk_ln.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef INCGUARD_87768d11a9f7d831f2a8b9d0ab7efa9c
-#define INCGUARD_87768d11a9f7d831f2a8b9d0ab7efa9c
-
-#include "commonbase.h"
-
-
-int bulk_ln_main( int argc, char**argv );
-
-
-#endif /* INCGUARD_87768d11a9f7d831f2a8b9d0ab7efa9c */
diff --git a/src/bulk_ln/bulk_ln_main.c b/src/bulk_ln/bulk_ln_main.c
deleted file mode 100644
index a3ac228..0000000
--- a/src/bulk_ln/bulk_ln_main.c
+++ /dev/null
@@ -1,10 +0,0 @@
-
-#include "bulk_ln.h"
-
-int main( int argc, char**argv ){
- int err = bulk_ln_main(argc, argv);
- /* Ensure to return 7-bit value only (See POSIX) */
- if( err < 0 ) err = -err;
- return err > 127 ? 1 : err;
-}
-
diff --git a/src/common/commonbase.h b/src/common/commonbase.h
deleted file mode 100644
index 497d3fa..0000000
--- a/src/common/commonbase.h
+++ /dev/null
@@ -1,23 +0,0 @@
-
-/*
- * common config for project. Here goes stuff like feature-test-macros etc.
- *
- * Every header file MUST include this file AS THE 1ST include.
- */
-
-
-#define _POSIX_C_SOURCE 200809L
-
-
-#define STR_QUOT_IAHGEWIH(s) #s
-#define STR_QUOT(s) STR_QUOT_IAHGEWIH(s)
-
-#define STR_CAT(a, b) a ## b
-
-#ifndef likely
-# define likely(a) (a)
-#endif
-#ifndef unlikely
-# define unlikely(a) (a)
-#endif
-