aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-08-31 12:07:27 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-08-31 12:07:50 -0800
commit711ee500f1afd676959b21e781ded451755b369e (patch)
treea0295008c2908a03e7093fe6ee5eba2850b3492a
parent4be0d8395e673d46cdbaeff44e661cb7bb796a48 (diff)
downloadbindletools-711ee500f1afd676959b21e781ded451755b369e.tar.gz
bindletools-711ee500f1afd676959b21e781ded451755b369e.tar.bz2
bindletools-711ee500f1afd676959b21e781ded451755b369e.tar.xz
bindletools-711ee500f1afd676959b21e781ded451755b369e.zip
examples: adding example-decode
-rw-r--r--Makefile.am9
-rw-r--r--examples/.gitignore1
-rw-r--r--examples/Makefile1
-rw-r--r--examples/example-decode.c117
4 files changed, 128 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 5b23638..1ccf138 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -98,6 +98,7 @@ bin_PROGRAMS =
98bin_SCRIPTS = 98bin_SCRIPTS =
99sbin_SCRIPTS = 99sbin_SCRIPTS =
100EXTRA_PROGRAMS = examples/example-bsearch \ 100EXTRA_PROGRAMS = examples/example-bsearch \
101 examples/example-decode \
101 examples/example-queue \ 102 examples/example-queue \
102 examples/example-stack \ 103 examples/example-stack \
103 src/bindletools 104 src/bindletools
@@ -158,10 +159,12 @@ if ENABLE_UTILITY
158endif 159endif
159if ENABLE_EXAMPLES 160if ENABLE_EXAMPLES
160 noinst_PROGRAMS += examples/example-bsearch 161 noinst_PROGRAMS += examples/example-bsearch
162 noinst_PROGRAMS += examples/example-decode
161 noinst_PROGRAMS += examples/example-queue 163 noinst_PROGRAMS += examples/example-queue
162 noinst_PROGRAMS += examples/example-stack 164 noinst_PROGRAMS += examples/example-stack
163 examples_DATA += examples/Makefile 165 examples_DATA += examples/Makefile
164 examples_DATA += examples/example-bsearch.c 166 examples_DATA += examples/example-bsearch.c
167 examples_DATA += examples/example-decode.c
165 examples_DATA += examples/example-queue.c 168 examples_DATA += examples/example-queue.c
166 examples_DATA += examples/example-stack.c 169 examples_DATA += examples/example-stack.c
167endif 170endif
@@ -173,6 +176,12 @@ examples_example_bsearch_LDADD = lib/libbindle.la
173examples_example_bsearch_SOURCES = examples/example-bsearch.c 176examples_example_bsearch_SOURCES = examples/example-bsearch.c
174 177
175 178
179# macros for examples/example-decode
180examples_example_decode_DEPENDENCIES = lib/libbindle.la
181examples_example_decode_LDADD = lib/libbindle.la
182examples_example_decode_SOURCES = examples/example-decode.c
183
184
176# macros for examples/example-queue 185# macros for examples/example-queue
177examples_example_queue_DEPENDENCIES = lib/libbindle.la 186examples_example_queue_DEPENDENCIES = lib/libbindle.la
178examples_example_queue_LDADD = lib/libbindle.la 187examples_example_queue_LDADD = lib/libbindle.la
diff --git a/examples/.gitignore b/examples/.gitignore
index fca4963..7ba6da3 100644
--- a/examples/.gitignore
+++ b/examples/.gitignore
@@ -1,4 +1,5 @@
1/*.o 1/*.o
2/example-bsearch 2/example-bsearch
3/example-decode
3/example-queue 4/example-queue
4/example-stack 5/example-stack
diff --git a/examples/Makefile b/examples/Makefile
index 771dad2..9620b49 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -33,6 +33,7 @@
33CFLAGS += -Wall -Werror 33CFLAGS += -Wall -Werror
34LDLIBS += -lbindle 34LDLIBS += -lbindle
35PROGS = example-bsearch \ 35PROGS = example-bsearch \
36 example-decode \
36 example-queue \ 37 example-queue \
37 example-stack 38 example-stack
38 39
diff --git a/examples/example-decode.c b/examples/example-decode.c
new file mode 100644
index 0000000..e16631c
--- /dev/null
+++ b/examples/example-decode.c
@@ -0,0 +1,117 @@
1/*
2 * Bindle Binaries Tools
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of David M. Syzdek nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#define _EXAMPLES_EXAMPLE_DECODE_C 1
32
33
34///////////////
35// //
36// Headers //
37// //
38///////////////
39#pragma mark - Headers
40
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <errno.h>
45#include <bindle.h>
46
47
48///////////////////
49// //
50// Definitions //
51// //
52///////////////////
53#pragma mark - Definitions
54
55#undef PROGRAM_NAME
56#define PROGRAM_NAME "example-decode"
57
58
59//////////////////
60// //
61// Prototypes //
62// //
63//////////////////
64#pragma mark - Prototypes
65
66int
67main(
68 int argc,
69 char * argv[] );
70
71
72/////////////////
73// //
74// Functions //
75// //
76/////////////////
77#pragma mark - Functions
78
79int
80main(
81 int argc,
82 char * argv[] )
83{
84 int i;
85 ssize_t rc;
86 char buff[1024];
87
88 for(i = 1; (i < argc); i++)
89 {
90 if ((rc = bindle_encoding_verify(BNDL_BASE32, argv[i], strlen(argv[i]))) == -1)
91 {
92 fprintf(stderr, "bindle_encoding_verify(): %s\n", strerror(errno));
93 return(1);
94 };
95 if ((rc = bindle_decode_size(BNDL_BASE32, strlen(argv[i]))) == -1)
96 {
97 fprintf(stderr, "bindle_decode_size(): %s\n", strerror(errno));
98 return(1);
99 };
100 if ((size_t)rc > (sizeof(buff) - 1))
101 {
102 fprintf(stderr, "error: buffer is too small for decoded string\n");
103 return(1);
104 };
105 if ((rc = bindle_decode(BNDL_BASE32, buff, sizeof(buff), argv[i], strlen(argv[i]))) == -1)
106 {
107 fprintf(stderr, "bindle_decode(): %s\n", strerror(errno));
108 return(1);
109 };
110 printf("%i: %s\n", i, buff);
111 };
112
113 return(0);
114}
115
116/* end of source */
117