mirror of
https://github.com/jorisvink/kore
synced 2025-03-10 04:59:02 -04:00
84 lines
2.2 KiB
C
Executable File
84 lines
2.2 KiB
C
Executable File
/*
|
|
* Copyright (c) 2013 Joris Vink <joris@coders.se>
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <ctype.h>
|
|
#include <err.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
struct stat st;
|
|
size_t len;
|
|
FILE *fp, *hdr;
|
|
char *ext, *p, *c, buf[1024];
|
|
|
|
if (argc != 3)
|
|
err(1, "arguments");
|
|
if ((fp = fopen(argv[1], "r")) == NULL)
|
|
err(1, "fopen() %d", errno);
|
|
if ((hdr = fopen("static.h", "a+")) == NULL)
|
|
err(1, "fopen() %d", errno);
|
|
if ((ext = strchr(argv[2], '.')) != NULL)
|
|
*(ext)++ = '\0';
|
|
|
|
if (stat(argv[1], &st) == -1) {
|
|
printf("stat(%s) failed: %d\n", argv[1], errno);
|
|
exit(99);
|
|
}
|
|
|
|
printf("/**** AUTO GENERATED BY MAKEFILE - DO NOT TOUCH ****/\n");
|
|
printf("#include <sys/param.h>\n\n");
|
|
printf("u_int8_t *static_%s_%s = (u_int8_t *)", ext, argv[2]);
|
|
|
|
len = 0;
|
|
while (fgets(buf, sizeof(buf), fp)) {
|
|
if ((p = strchr(buf, '\n')) != NULL)
|
|
*p = '\0';
|
|
|
|
printf("\n\t\"");
|
|
for (c = buf; *c != '\0'; c++) {
|
|
if (*c == '"' || *c == '\\')
|
|
printf("\\");
|
|
printf("%c", *c);
|
|
len++;
|
|
}
|
|
|
|
printf("\\n\"");
|
|
len++;
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
printf(";\n\n");
|
|
printf("u_int32_t static_len_%s_%s = %ld;\n", ext, argv[2], len);
|
|
printf("time_t static_mtime_%s_%s = %ld;\n", ext, argv[2], st.st_mtime);
|
|
|
|
fprintf(hdr, "extern u_int8_t *static_%s_%s;\n", ext, argv[2]);
|
|
fprintf(hdr, "extern u_int32_t static_len_%s_%s;\n", ext, argv[2]);
|
|
fprintf(hdr, "extern time_t static_mtime_%s_%s;\n", ext, argv[2]);
|
|
fclose(hdr);
|
|
|
|
return (0);
|
|
}
|