Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
/*
|
2016-08-09 19:29:04 -04:00
|
|
|
* Copyright (c) 2014, 2016 Jonas 'Sortie' Termansen.
|
Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* carray.c
|
|
|
|
* Convert a binary file to a C array.
|
|
|
|
*/
|
2014-04-21 16:37:44 -04:00
|
|
|
|
2016-08-09 19:29:04 -04:00
|
|
|
#include <err.h>
|
2014-04-21 16:37:44 -04:00
|
|
|
#include <errno.h>
|
2016-02-28 10:46:24 -05:00
|
|
|
#include <stdbool.h>
|
2014-04-21 16:37:44 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static void compact_arguments(int* argc, char*** argv)
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < *argc; i++ )
|
|
|
|
{
|
|
|
|
while ( i < *argc && !(*argv)[i] )
|
|
|
|
{
|
|
|
|
for ( int n = i; n < *argc; n++ )
|
|
|
|
(*argv)[n] = (*argv)[n+1];
|
|
|
|
(*argc)--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 12:34:19 -04:00
|
|
|
bool get_option_variable(const char* option, const char** varptr,
|
|
|
|
const char* arg, int argc, char** argv, int* ip)
|
2014-04-21 16:37:44 -04:00
|
|
|
{
|
|
|
|
size_t option_len = strlen(option);
|
|
|
|
if ( strncmp(option, arg, option_len) != 0 )
|
|
|
|
return false;
|
|
|
|
if ( arg[option_len] == '=' )
|
|
|
|
{
|
2016-08-12 12:34:19 -04:00
|
|
|
*varptr = arg + option_len + 1;
|
2014-04-21 16:37:44 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ( arg[option_len] != '\0' )
|
|
|
|
return false;
|
|
|
|
if ( *ip + 1 == argc )
|
2016-10-03 10:00:00 -04:00
|
|
|
errx(1, "expected operand after `%s'", option);
|
2016-08-12 12:34:19 -04:00
|
|
|
*varptr = argv[++*ip];
|
|
|
|
argv[*ip] = NULL;
|
2014-04-21 16:37:44 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_OPTION_VARIABLE(str, varptr) \
|
2016-08-12 12:34:19 -04:00
|
|
|
get_option_variable(str, varptr, arg, argc, argv, &i)
|
2014-04-21 16:37:44 -04:00
|
|
|
|
2016-08-12 12:34:19 -04:00
|
|
|
void get_short_option_variable(char c, const char** varptr,
|
|
|
|
const char* arg, int argc, char** argv, int* ip)
|
2014-04-21 16:37:44 -04:00
|
|
|
{
|
|
|
|
if ( *(arg+1) )
|
2016-08-12 12:34:19 -04:00
|
|
|
*varptr = arg + 1;
|
2014-04-21 16:37:44 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( *ip + 1 == argc )
|
2016-08-12 12:34:19 -04:00
|
|
|
errx(1, "option requires an argument -- '%c'", c);
|
|
|
|
*varptr = argv[*ip + 1];
|
2014-04-21 16:37:44 -04:00
|
|
|
argv[++(*ip)] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_SHORT_OPTION_VARIABLE(c, varptr) \
|
2016-08-12 12:34:19 -04:00
|
|
|
get_short_option_variable(c, varptr, arg, argc, argv, &i)
|
2014-04-21 16:37:44 -04:00
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
bool flag_const = false;
|
|
|
|
bool flag_extern_c = false;
|
|
|
|
bool flag_extern = false;
|
|
|
|
bool flag_forward = false;
|
|
|
|
bool flag_guard = false;
|
2016-08-12 12:34:19 -04:00
|
|
|
bool flag_headers = false;
|
2014-04-21 16:37:44 -04:00
|
|
|
bool flag_raw = false;
|
|
|
|
bool flag_static = false;
|
|
|
|
bool flag_volatile = false;
|
|
|
|
|
2016-08-12 12:34:19 -04:00
|
|
|
const char* guard = NULL;
|
|
|
|
const char* identifier = NULL;
|
|
|
|
const char* includes = NULL;
|
|
|
|
const char* output = NULL;
|
|
|
|
const char* type = NULL;
|
2014-04-21 16:37:44 -04:00
|
|
|
|
|
|
|
for ( int i = 1; i < argc; i++ )
|
|
|
|
{
|
|
|
|
const char* arg = argv[i];
|
|
|
|
if ( arg[0] != '-' || !arg[1] )
|
|
|
|
continue;
|
|
|
|
argv[i] = NULL;
|
|
|
|
if ( !strcmp(arg, "--") )
|
|
|
|
break;
|
|
|
|
if ( arg[1] != '-' )
|
|
|
|
{
|
2016-02-28 10:46:24 -05:00
|
|
|
char c;
|
|
|
|
while ( (c = *++arg) ) switch ( c )
|
2014-04-21 16:37:44 -04:00
|
|
|
{
|
|
|
|
case 'c': flag_const = true; break;
|
|
|
|
case 'e': flag_extern = true; break;
|
2016-08-12 12:34:19 -04:00
|
|
|
case 'E': flag_extern_c = true; break;
|
2014-04-21 16:37:44 -04:00
|
|
|
case 'f': flag_forward = true; break;
|
|
|
|
case 'g': flag_guard = true; break;
|
2016-08-12 12:34:19 -04:00
|
|
|
case 'G': GET_SHORT_OPTION_VARIABLE('G', &guard); arg = "G"; flag_guard = true; break;
|
|
|
|
case 'H': flag_headers = true; break;
|
|
|
|
// TODO: After releasing Sortix 1.1, change -i to --identifier
|
|
|
|
// rather than -H (--headers).
|
|
|
|
#if 0 // Future behavior:
|
|
|
|
case 'i': GET_SHORT_OPTION_VARIABLE('i', &identifier); arg = "i"; break;
|
|
|
|
#else // Compatibility:
|
|
|
|
case 'i': flag_headers = true; break;
|
|
|
|
#endif
|
|
|
|
case 'o': GET_SHORT_OPTION_VARIABLE('o', &output); arg = "o"; break;
|
2014-04-21 16:37:44 -04:00
|
|
|
case 'r': flag_raw = true; break;
|
|
|
|
case 's': flag_static = true; break;
|
2016-08-12 12:34:19 -04:00
|
|
|
case 't': GET_SHORT_OPTION_VARIABLE('t', &type); arg = "t"; break;
|
2014-04-21 16:37:44 -04:00
|
|
|
case 'v': flag_volatile = true; break;
|
|
|
|
default:
|
2016-10-03 10:00:00 -04:00
|
|
|
errx(1, "unknown option -- '%c'", c);
|
2014-04-21 16:37:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( !strcmp(arg, "--const") )
|
|
|
|
flag_const = true;
|
|
|
|
else if ( !strcmp(arg, "--extern") )
|
|
|
|
flag_extern = true;
|
2016-08-12 12:34:19 -04:00
|
|
|
else if ( !strcmp(arg, "--extern-c") )
|
|
|
|
flag_extern_c = true;
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( !strcmp(arg, "--forward") )
|
|
|
|
flag_forward = true;
|
|
|
|
else if ( !strcmp(arg, "--use-guard") )
|
|
|
|
flag_guard = true;
|
2016-08-12 12:34:19 -04:00
|
|
|
else if ( !strcmp(arg, "--headers") )
|
|
|
|
flag_headers = true;
|
|
|
|
// TODO: After releasing Sortix 1.1, remove --include.
|
|
|
|
#if 1 // Compatibility:
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( !strcmp(arg, "--include") )
|
2016-08-12 12:34:19 -04:00
|
|
|
flag_headers = true;
|
|
|
|
#endif
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( !strcmp(arg, "--raw") )
|
|
|
|
flag_raw = true;
|
|
|
|
else if ( !strcmp(arg, "--static") )
|
|
|
|
flag_static = true;
|
|
|
|
else if ( !strcmp(arg, "--volatile") )
|
|
|
|
flag_volatile = true;
|
|
|
|
else if ( !strcmp(arg, "--char") )
|
2016-08-12 12:34:19 -04:00
|
|
|
type = "char";
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( !strcmp(arg, "--signed-char") )
|
2016-08-12 12:34:19 -04:00
|
|
|
type = "signed char";
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( !strcmp(arg, "--unsigned-char") )
|
2016-08-12 12:34:19 -04:00
|
|
|
type = "unsigned char";
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( !strcmp(arg, "--int8_t") )
|
2016-08-12 12:34:19 -04:00
|
|
|
type = "int8_t";
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( !strcmp(arg, "--uint8_t") )
|
2016-08-12 12:34:19 -04:00
|
|
|
type = "uint8_t";
|
|
|
|
else if ( GET_OPTION_VARIABLE("--guard", &guard) )
|
2014-04-21 16:37:44 -04:00
|
|
|
flag_guard = true;
|
2016-08-12 12:34:19 -04:00
|
|
|
else if ( GET_OPTION_VARIABLE("--identifier", &identifier) ) { }
|
|
|
|
else if ( GET_OPTION_VARIABLE("--includes", &includes) )
|
|
|
|
flag_headers = true;
|
|
|
|
else if ( GET_OPTION_VARIABLE("--output", &output) ) { }
|
|
|
|
else if ( GET_OPTION_VARIABLE("--type", &type) ) { }
|
2014-04-21 16:37:44 -04:00
|
|
|
else
|
2016-10-03 10:00:00 -04:00
|
|
|
errx(1, "unknown option: %s", arg);
|
2014-04-21 16:37:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
compact_arguments(&argc, &argv);
|
|
|
|
|
|
|
|
if ( flag_extern && flag_static )
|
2016-08-12 12:34:19 -04:00
|
|
|
errx(1, "the --extern and --static options are mutually incompatible");
|
2014-04-21 16:37:44 -04:00
|
|
|
if ( flag_forward && flag_raw )
|
2016-08-12 12:34:19 -04:00
|
|
|
errx(1, "the --forward and --raw options are mutually incompatible");
|
2014-04-21 16:37:44 -04:00
|
|
|
|
2016-08-12 12:34:19 -04:00
|
|
|
if ( !type )
|
|
|
|
type = "unsigned char";
|
2014-04-21 16:37:44 -04:00
|
|
|
|
|
|
|
if ( !guard )
|
|
|
|
{
|
2016-08-12 12:34:19 -04:00
|
|
|
char* new_guard;
|
|
|
|
if ( output )
|
|
|
|
new_guard = strdup(output);
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( 2 <= argc && strcmp(argv[1], "-") != 0 )
|
2016-08-12 12:34:19 -04:00
|
|
|
{
|
|
|
|
if ( asprintf(&new_guard, "%s_H", argv[1]) < 0 )
|
|
|
|
err(1, "asprintf");
|
|
|
|
}
|
2014-04-21 16:37:44 -04:00
|
|
|
else
|
2016-08-12 12:34:19 -04:00
|
|
|
new_guard = strdup("CARRAY_H");
|
|
|
|
if ( !new_guard )
|
|
|
|
err(1, "strdup");
|
2014-04-21 16:37:44 -04:00
|
|
|
|
2016-08-12 12:34:19 -04:00
|
|
|
for ( size_t i = 0; new_guard[i]; i++ )
|
2014-04-21 16:37:44 -04:00
|
|
|
{
|
2016-08-12 12:34:19 -04:00
|
|
|
if ( 'A' <= new_guard[i] && new_guard[i] <= 'Z' )
|
2014-04-21 16:37:44 -04:00
|
|
|
continue;
|
2016-08-12 12:34:19 -04:00
|
|
|
else if ( 'a' <= new_guard[i] && new_guard[i] <= 'z' )
|
|
|
|
new_guard[i] = 'A' + new_guard[i] - 'a';
|
|
|
|
else if ( i != 0 && '0' <= new_guard[i] && new_guard[i] <= '9' )
|
2014-04-21 16:37:44 -04:00
|
|
|
continue;
|
2016-08-12 12:34:19 -04:00
|
|
|
else if ( new_guard[i] == '+' )
|
|
|
|
new_guard[i] = 'X';
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( i == 0 )
|
2016-08-12 12:34:19 -04:00
|
|
|
new_guard[i] = 'X';
|
2014-04-21 16:37:44 -04:00
|
|
|
else
|
2016-08-12 12:34:19 -04:00
|
|
|
new_guard[i] = '_';
|
2014-04-21 16:37:44 -04:00
|
|
|
}
|
2016-08-12 12:34:19 -04:00
|
|
|
|
|
|
|
guard = new_guard;
|
2014-04-21 16:37:44 -04:00
|
|
|
}
|
|
|
|
|
2016-08-12 12:34:19 -04:00
|
|
|
if ( flag_headers && !includes )
|
2014-04-21 16:37:44 -04:00
|
|
|
{
|
2016-08-12 12:34:19 -04:00
|
|
|
if ( !strcmp(type, "int8_t") ||
|
|
|
|
!strcmp(type, "uint8_t") )
|
|
|
|
includes = "#include <stdint.h>";
|
2014-04-21 16:37:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !identifier )
|
|
|
|
{
|
2016-08-12 12:34:19 -04:00
|
|
|
char* new_identifier;
|
|
|
|
if ( output )
|
|
|
|
new_identifier = strdup(output);
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( 2 <= argc && strcmp(argv[1], "-") != 0 )
|
2016-08-12 12:34:19 -04:00
|
|
|
new_identifier = strdup(argv[1]);
|
2014-04-21 16:37:44 -04:00
|
|
|
else
|
2016-08-12 12:34:19 -04:00
|
|
|
new_identifier = strdup("carray");
|
|
|
|
if ( !new_identifier )
|
|
|
|
err(1, "strdup");
|
2014-04-21 16:37:44 -04:00
|
|
|
|
2016-08-12 12:34:19 -04:00
|
|
|
for ( size_t i = 0; new_identifier[i]; i++ )
|
2014-04-21 16:37:44 -04:00
|
|
|
{
|
2016-08-12 12:34:19 -04:00
|
|
|
if ( i && new_identifier[i] == '.' && !strchr(new_identifier + i, '/') )
|
|
|
|
new_identifier[i] = '\0';
|
|
|
|
else if ( 'a' <= new_identifier[i] && new_identifier[i] <= 'z' )
|
2014-04-21 16:37:44 -04:00
|
|
|
continue;
|
2016-08-12 12:34:19 -04:00
|
|
|
else if ( 'A' <= new_identifier[i] && new_identifier[i] <= 'Z' )
|
|
|
|
new_identifier[i] = 'a' + new_identifier[i] - 'A';
|
|
|
|
else if ( i != 0 && '0' <= new_identifier[i] && new_identifier[i] <= '9' )
|
2014-04-21 16:37:44 -04:00
|
|
|
continue;
|
|
|
|
else if ( guard[i] == '+' )
|
2016-08-12 12:34:19 -04:00
|
|
|
new_identifier[i] = 'x';
|
2014-04-21 16:37:44 -04:00
|
|
|
else if ( i == 0 )
|
2016-08-12 12:34:19 -04:00
|
|
|
new_identifier[i] = 'x';
|
2014-04-21 16:37:44 -04:00
|
|
|
else
|
2016-08-12 12:34:19 -04:00
|
|
|
new_identifier[i] = '_';
|
2014-04-21 16:37:44 -04:00
|
|
|
}
|
2016-08-12 12:34:19 -04:00
|
|
|
|
|
|
|
identifier = new_identifier;
|
2014-04-21 16:37:44 -04:00
|
|
|
}
|
|
|
|
|
2016-08-12 12:34:19 -04:00
|
|
|
if ( output && !freopen(output, "w", stdout) )
|
|
|
|
err(1, "%s", output);
|
2014-04-21 16:37:44 -04:00
|
|
|
|
|
|
|
if ( flag_guard && guard )
|
|
|
|
{
|
|
|
|
printf("#ifndef %s\n", guard);
|
|
|
|
printf("#define %s\n", guard);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2016-08-12 12:34:19 -04:00
|
|
|
if ( flag_headers && includes )
|
2014-04-21 16:37:44 -04:00
|
|
|
{
|
2016-08-12 12:34:19 -04:00
|
|
|
printf("%s\n", includes);
|
2014-04-21 16:37:44 -04:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !flag_raw )
|
|
|
|
{
|
|
|
|
if ( flag_extern_c )
|
|
|
|
{
|
|
|
|
printf("#if defined(__cplusplus)\n");
|
|
|
|
printf("extern \"C\" {\n");
|
|
|
|
printf("#endif\n");
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
if ( flag_extern )
|
|
|
|
printf("extern ");
|
|
|
|
if ( flag_static )
|
|
|
|
printf("static ");
|
|
|
|
if ( flag_const )
|
|
|
|
printf("const ");
|
|
|
|
if ( flag_volatile )
|
|
|
|
printf("volatile ");
|
2016-08-12 12:34:19 -04:00
|
|
|
printf("%s %s[]", type, identifier);
|
2014-04-21 16:37:44 -04:00
|
|
|
if ( flag_forward )
|
|
|
|
printf(";\n");
|
|
|
|
else
|
|
|
|
printf(" = {\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !flag_forward )
|
|
|
|
{
|
|
|
|
bool begun_row = false;
|
|
|
|
unsigned int position = 0;
|
|
|
|
|
|
|
|
for ( int i = 0; i < argc; i++ )
|
|
|
|
{
|
|
|
|
if ( i == 0 && 2 <= argc )
|
|
|
|
continue;
|
|
|
|
FILE* fp;
|
|
|
|
const char* arg;
|
|
|
|
if ( argc == 1 || !strcmp(argv[i], "-") )
|
|
|
|
{
|
|
|
|
arg = "<stdin>";
|
|
|
|
fp = stdin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arg = argv[i];
|
|
|
|
fp = fopen(arg, "r");
|
|
|
|
}
|
|
|
|
if ( !fp )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "%s", arg);
|
2014-04-21 16:37:44 -04:00
|
|
|
int ic;
|
|
|
|
while ( (ic = fgetc(fp)) != EOF )
|
|
|
|
{
|
|
|
|
printf("%c0x%02X,", position++ ? ' ' : '\t', ic);
|
|
|
|
begun_row = true;
|
|
|
|
if ( position == (80 - 8) / 6 )
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
position = 0;
|
|
|
|
begun_row = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( ferror(fp) )
|
2016-08-09 19:29:04 -04:00
|
|
|
err(1, "fgetc: %s", arg);
|
2014-04-21 16:37:44 -04:00
|
|
|
if ( fp != stdin )
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( begun_row )
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !flag_raw )
|
|
|
|
{
|
|
|
|
if ( !flag_forward )
|
|
|
|
printf("};\n");
|
|
|
|
if ( flag_extern_c )
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
printf("#if defined(__cplusplus)\n");
|
|
|
|
printf("} /* extern \"C\" */\n");
|
|
|
|
printf("#endif\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( flag_guard && guard )
|
|
|
|
{
|
|
|
|
printf("\n");
|
|
|
|
printf("#endif\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ferror(stdout) || fflush(stdout) == EOF )
|
2016-08-12 12:34:19 -04:00
|
|
|
err(1, "%s", output ? output : "stdout");
|
2014-04-21 16:37:44 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|