Skip to content

Commit 62b8493

Browse files
committed
improve dox a bit
add dedication add -v option
1 parent 3b6ca59 commit 62b8493

File tree

6 files changed

+136
-26
lines changed

6 files changed

+136
-26
lines changed

README.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,66 @@
22

33
#### ➿ mulle-c-string-escape turns data into C-strings
44

5-
It will escape non-ASCII characters to hex or octal, and use C-escapes for the
6-
known C escapes. It will separate the output into lines not longer than
7-
80 charactes.
5+
Non-ASCII characters will be escaped to hex or octal. C-escapes are used for
6+
known C escapes like '\b'. The output is separated into lines of approximately
7+
even length and does not exceed the chosen line length. An example output
8+
is [usage.inc](src/usage.inc)
9+
You can feed it binary or text files.
810

9-
You can easily `#include` the output, or just copy/paste it.
11+
You can then easily `#include` the output as string contents, or copy/paste it
12+
into your C program like so:
1013

11-
Reads from standard input and writes to standard output. You can also use
12-
it on binary files.
14+
```
15+
static char text[] =
16+
#include "data.inc"
17+
;
18+
```
19+
20+
> #### Note
21+
>
22+
> C will append a "\0" to strings!
23+
24+
See the [usage.txt](src/usage.txt) for options.
25+
26+
## Example
27+
28+
Use mulle-c-string-escape to create a string representation of itself. We use
29+
`cmake` here instead of `mulle-sde craft --release` here too ease the fear
30+
of the unkown:
31+
32+
```
33+
mkdir -p kitchen/Release
34+
cmake -B kitchen/Release -DCMAKE_BUILD_TYPE=Release
35+
cmake --build kitchen/Release
36+
./kitchen/Release/mulle-c-string-escape \
37+
./kitchen/Release/mulle-c-string-escape \
38+
x.inc
39+
```
1340

14-
So use it with redirection like:
41+
To verify that this has actually worked:
1542

16-
```console
17-
mulle-c-string-escape < mytext.txt
43+
```
44+
cat <<EOF > x.c
45+
#include <stdio.h>
46+
47+
48+
static char text[] = "" // useful in case x.inc can be empty
49+
#include "x.inc"
50+
;
51+
52+
int main( int argc, char *argv[])
53+
{
54+
FILE *fp;
55+
56+
fp = fopen( "verify.exe", "wb");
57+
fwrite( text, sizeof( text) - 1, 1, fp); // -1 because C appends a \0
58+
return( fclose( fp));
59+
}
60+
EOF
61+
62+
cc -o x x.c
63+
./x
64+
diff verify.exe ./kitchen/Release/mulle-c-string-escape
1865
```
1966

2067
## Build
@@ -27,3 +74,7 @@ To fetch and build everything say:
2774
```
2875
mulle-sde craft
2976
```
77+
78+
## Dedication
79+
80+
This little tool is dedicated to the memory of Oliver Mondry (mondry@me.com)

src/Makefile-usage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ COMPILE=../kitchen/Debug/mulle-c-string-escape
44

55

66
usage.inc: usage.txt Makefile-usage
7-
$(COMPILE) -0 -e -l 120 < $< > $@
7+
$(COMPILE) -0 -e -l 120 $< $@
88

src/main.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
//
2+
// main.c
3+
// mulle-c-string-escape
4+
//
5+
// Created by Nat! on 03.11.21
6+
// Copyright © 2021 Mulle kybernetiK. All rights reserved.
7+
// Copyright (C) 2021 Nat!, Mulle kybernetiK.
8+
//
9+
// Redistribution and use in source and binary forms, with or without
10+
// modification, are permitted provided that the following conditions are met:
11+
//
12+
// Redistributions of source code must retain the above copyright notice, this
13+
// list of conditions and the following disclaimer.
14+
//
15+
// Redistributions in binary form must reproduce the above copyright notice,
16+
// this list of conditions and the following disclaimer in the documentation
17+
// and/or other materials provided with the distribution.
18+
//
19+
// Neither the name of Mulle kybernetiK nor the names of its contributors
20+
// may be used to endorse or promote products derived from this software
21+
// without specific prior written permission.
22+
//
23+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33+
// POSSIBILITY OF SUCH DAMAGE.
34+
//
135
#include "include-private.h"
236

337
#include <stdio.h>
@@ -14,7 +48,7 @@ static void usage( void)
1448
printf( "%s", "" // keep ""
1549
#include "usage.inc"
1650
);
17-
exit( 0);
51+
exit( 1);
1852
}
1953

2054
static inline size_t calc_emit_buf_size( size_t prefix_length,
@@ -361,6 +395,13 @@ int main( int argc, char *argv[])
361395
usage();
362396
continue;
363397

398+
case 'v' :
399+
printf( "mulle-c-string-escape %u.%u.%u\n",
400+
mulle_c_string_escape_get_version_major(),
401+
mulle_c_string_escape_get_version_minor(),
402+
mulle_c_string_escape_get_version_patch());
403+
exit( 0);
404+
364405
default:
365406
usage();
366407
}

src/mulle-c-string-escape-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/*
55
* version: major, minor, patch
66
*/
7-
#define MULLE_C_STRING_ESCAPE_VERSION ((0 << 20) | (7 << 8) | 56)
7+
#define MULLE_C_STRING_ESCAPE_VERSION ((1 << 20) | (0 << 8) | 0)
88

99

1010
static inline unsigned int mulle_c_string_escape_get_version_major( void)

src/usage.inc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,32 @@
33
"\n"
44
"\xe2\x9e\xbf mulle-c-string-escape turns data into C-strings\n"
55
"\n"
6-
"It will escape non-ASCII characters to hex or octal, and use C-escapes for the\n"
7-
"known C escapes. It will separate the output into lines so they should fit\n"
8-
"a visually pleasing line length.\n"
6+
"Non-ASCII characters will be escaped to hex or octal. C-escapes are used for\n"
7+
"known C escapes like '\\b'. The output is separated into lines of approximately\n"
8+
"even length and does not exceed the chosen line length.\n"
9+
"You can feed it binary or text files.\n"
910
"\n"
10-
"You can easily `#include` the output, or just copy/paste it.\n"
11+
"You can then easily `#include` the output, or copy/paste it into your\n"
12+
"C program like so:\n"
1113
"\n"
12-
"Reads from standard input and writes to standard output. You can also use\n"
13-
"it on binary files.\n"
14+
" static char data[] =\n"
15+
" #include \"data.inc\"\n"
16+
" ;\n"
17+
" #define s_data (sizeof( data) - 1)\n"
1418
"\n"
1519
"Example:\n"
1620
"\tmulle-c-string-escape -0 -l 120 < mytext.txt\n"
1721
"\n"
1822
"Options:\n"
1923
"\t-[01234] : zero to four space prefix (TAB)\n"
20-
"\t-h : help\n"
24+
"\t-h : this help\n"
2125
"\t-e : escape TAB characters\n"
2226
"\t-l <n> : targetted line length (80)\n"
2327
"\t-n : don't create a new line for linefeeds in text\n"
2428
"\t-p <s> : use a custom prefix instead of spaces or TAB\n"
2529
"\t-t <s> : visual size of TAB in text (8)\n"
30+
" -v : print version information and exit\n"
31+
"\n"
32+
"Dedication:\n"
33+
" This little tool is dedicated to the memory of Oliver Mondry (mondry@me.com)\n"
34+
"\n"

src/usage.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,32 @@ Usage:
33

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

6-
It will escape non-ASCII characters to hex or octal, and use C-escapes for the
7-
known C escapes. It will separate the output into lines so they should fit
8-
a visually pleasing line length.
6+
Non-ASCII characters will be escaped to hex or octal. C-escapes are used for
7+
known C escapes like '\b'. The output is separated into lines of approximately
8+
even length and does not exceed the chosen line length.
9+
You can feed it binary or text files.
910

10-
You can easily `#include` the output, or just copy/paste it.
11+
You can then easily `#include` the output, or copy/paste it into your
12+
C program like so:
1113

12-
Reads from standard input and writes to standard output. You can also use
13-
it on binary files.
14+
static char data[] =
15+
#include "data.inc"
16+
;
17+
#define s_data (sizeof( data) - 1)
1418

1519
Example:
1620
mulle-c-string-escape -0 -l 120 < mytext.txt
1721

1822
Options:
1923
-[01234] : zero to four space prefix (TAB)
20-
-h : help
24+
-h : this help
2125
-e : escape TAB characters
2226
-l <n> : targetted line length (80)
2327
-n : don't create a new line for linefeeds in text
2428
-p <s> : use a custom prefix instead of spaces or TAB
2529
-t <s> : visual size of TAB in text (8)
30+
-v : print version information and exit
31+
32+
Dedication:
33+
This little tool is dedicated to the memory of Oliver Mondry (mondry@me.com)
34+

0 commit comments

Comments
 (0)