txt2Cstring

Command for converting text to C string notation \n for new line, hexadecimal notation for non printable characters
git clone https://noulin.net/git/txt2Cstring.git
Log | Files | Refs

commit c61c3c81d23a776b1e5e7160e70f4dea60a097f7
Author: Remy Noulin <loader2x@gmail.com>
Date:   Sun, 13 Sep 2020 06:47:33 -0400

simple version

.gitignore    | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package.yml   | 37 +++++++++++++++++++++++++++++++++++
txt2Cstring.c | 40 +++++++++++++++++++++++++++++++++++++
3 files changed, 140 insertions(+)

Diffstat:
A.gitignore | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apackage.yml | 37+++++++++++++++++++++++++++++++++++++
Atxt2Cstring.c | 40++++++++++++++++++++++++++++++++++++++++
3 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,63 @@ +# Vim +*.sw* + +# Debug +.gdb_history + +# Coverage +*.gcov +*.gcda +*.gcno + +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/package.yml b/package.yml @@ -0,0 +1,37 @@ +--- + name: txt2Cstring + version: 0.0.1 + description: "Convert text file to C string to be inclueded in C code" + bin: ./txt2Cstring.c + #cflags: -DA -g3 -std=gnu11 -fPIC -pipe + #lflags: -lpcre + repository: + type: git + url: git+https://github.com/USER/txt2Cstring.git + keywords: + - utility + - command + author: Remy + license: MIT + bugs: + url: https://github.com/USER/txt2Cstring/issues + homepage: https://github.com/USER/txt2Cstring#readme + #compileHelp: # text displayed when there is a compilation error + #dependencies: + # md4c: + # Test configuration: + #testBin: ./testTxt2Cstring.c + #testCflags: -g3 -std=gnu11 -fPIC -pipe -fprofile-arcs -ftest-coverage -Wall -Wextra + #testLflags: -lcheck_pic -lrt -lm -lsubunit -fprofile-arcs -ftest-coverage -rdynamic + # Memcheck configuration (sheepy -m): + #memcheckBin: ./memcheckTxt2Cstring.c + #memcheckCmd: valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 + #memcheckCflags: -g3 -std=gnu11 -fPIC -pipe + #memcheckLflags: -rdynamic + # The asan* are the options for building the libsasan tests (sheepy -a): + #asanBin: ./asanTxt2Cstring.c + #asanCmd: env ASAN_OPTIONS="detect_leaks=1:detect_stack_use_after_return=1:halt_on_error=0:log_path=stdout:color=always:print_cmdline=1" + #asanCflags: -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address # these flags are overriden by package.yml + #asanLflags: -rdynamic -fsanitize=address -lasan # these flags are overriden by package.yml + #documentationCmd: # command for generating the documentation with spm doc + private: false # true for private package diff --git a/txt2Cstring.c b/txt2Cstring.c @@ -0,0 +1,40 @@ +#! /usr/bin/env sheepy +/* or direct path to sheepy: #! /usr/local/bin/sheepy */ + +/* Libsheepy documentation: https://spartatek.se/libsheepy/ */ +#include "libsheepyObject.h" + +int argc; char **argv; + +/* enable/disable logging */ +/* #undef pLog */ +/* #define pLog(...) */ + +int main(int ARGC, char** ARGV) { + + argc = ARGC; argv = ARGV; + + initLibsheepy(ARGV[0]); + setLogMode(LOG_VERBOSE); + + if (argc < 2) { + logXFailure("Filename missing"); + } + + if (not isPath(argv[1])) { + logXFailure(formatS("File "BLD RED UDL "'%s'"RST" not found ", argv[1])); + } + + createAllocateSmallArray(lines); + readFileG(lines, argv[1]); + + iter(lines, L) { + castS(l,L); + replaceG(l, "\"", "\\\"", 0); + prependG(l, "\""); + appendG(l, "\\n\""); + setPG(lines, iterIndexG(lines), l); + } + logG(lines); +} +// vim: set expandtab ts=2 sw=2: