Giter VIP home page Giter VIP logo

mulle-c-string-escape's Introduction

mulle-c-string-escape

➿ mulle-c-string-escape turns data into C strings

Non-ASCII characters will be escaped to hex or octal. C escape sequences are used for the predefined sequences like '\b'. The output is separated into lines of approximately even length and does not exceed the chosen line length. An example of a conversion is usage.txt being turned into usage.inc. You can feed it binary or text files.

You can copy/paste the output as string contents into your C source or #include the output like so:

static char  data[] =
#include "data.inc"
;
#define s_data ( sizeof( data) - 1)

Note

C will append a '\0' character to strings! So the actual data length is sizeof( data) - 1.

Options

See usage.txt for options.

Example

Let's use mulle-c-string-escape to create a C string representation of itself into a file "x.inc". We use cmake here, instead of mulle-sde craft --release, to ease the developer's fear of the unknown:

mkdir -p kitchen/Release
cmake -B kitchen/Release -DCMAKE_BUILD_TYPE=Release
cmake --build kitchen/Release --config Release
./kitchen/Release/mulle-c-string-escape \
   ./kitchen/Release/mulle-c-string-escape \
   x.inc

To verify that this has actually worked:

cat <<EOF > x.c
#include <stdio.h>


static char  text[] = "" // useful in case x.inc can be empty
#include "x.inc"
;

int  main( int argc, char *argv[])
{
   FILE   *fp;

   fp = fopen( "verify.exe", "wb");
   fwrite( text, sizeof( text) - 1, 1, fp); // -1 because C appends a \0
   return( fclose( fp));
}
EOF

cc -o x x.c
./x
diff verify.exe ./kitchen/Release/mulle-c-string-escape

Build

This is a mulle-sde project.

It comes with its own virtual environment and list of dependencies. To fetch and build everything say:

mulle-sde craft

Dedication

To the memory of Oliver "General" Mondry ([email protected])

Author

Nat! for Mulle kybernetiK.

mulle-c-string-escape's People

Contributors

codeon-nat avatar mulle-nat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.