diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1996-08-26 07:47:07 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1996-08-26 07:47:07 +0000 |
commit | 7ca38c18a8f1c5e6ea6acf0759cac0330ea35b9f (patch) | |
tree | 4f42b3bf8a4df775a139bce5da68a13557be042c | |
parent | e18443c3ae8593a5e5931232337ad03ad01dd370 (diff) |
Add file2c from FreeBSD.
-rw-r--r-- | usr.bin/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/file2c/Makefile | 7 | ||||
-rw-r--r-- | usr.bin/file2c/file2c.1 | 48 | ||||
-rw-r--r-- | usr.bin/file2c/file2c.c | 49 |
4 files changed, 106 insertions, 2 deletions
diff --git a/usr.bin/Makefile b/usr.bin/Makefile index d4f68d55921..5cbdbaba78a 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile,v 1.21 1996/08/23 23:43:38 downsj Exp $ +# $OpenBSD: Makefile,v 1.22 1996/08/26 07:47:03 downsj Exp $ # $NetBSD: Makefile,v 1.62 1996/03/10 05:45:43 thorpej Exp $ # from: @(#)Makefile 5.8.1.1 (Berkeley) 5/8/91 SUBDIR= apply apropos arch asa at awk banner basename bdes biff cal calendar \ cap_mkdb cdio checknr chflags chpass cksum cmp col colcrt colrm \ column comm compress cpp crontab ctags cut dirname du encrypt \ - env error expand false file find finger fmt fold fpr from \ + env error expand false file file2c find finger fmt fold fpr from \ fsplit fstat ftp gencat getconf getopt head hexdump id indent \ info_mkdb ipcrm ipcs join jot kdump ktrace lam last lastcomm leave \ less lex lndir locate lock logger login logname look lorder m4 machine \ diff --git a/usr.bin/file2c/Makefile b/usr.bin/file2c/Makefile new file mode 100644 index 00000000000..d7771892270 --- /dev/null +++ b/usr.bin/file2c/Makefile @@ -0,0 +1,7 @@ +# $OpenBSD: Makefile,v 1.1 1996/08/26 07:47:05 downsj Exp $ +# $FreeBSD: Makefile,v 1.1 1995/01/29 00:49:42 phk Exp $ + +PROG= file2c +MAN1= file2c.1 + +.include <bsd.prog.mk> diff --git a/usr.bin/file2c/file2c.1 b/usr.bin/file2c/file2c.1 new file mode 100644 index 00000000000..17e3a191667 --- /dev/null +++ b/usr.bin/file2c/file2c.1 @@ -0,0 +1,48 @@ +.\"---------------------------------------------------------------------------- +.\" "THE BEER-WARE LICENSE" (Revision 42): +.\" <phk@freebsd.org> wrote this file. As long as you retain this notice, you +.\" can do whatever you want with this file. If we meet some day, and you think +.\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp +.\" --------------------------------------------------------------------------- +.\" +.\" $Id: file2c.1,v 1.1 1996/08/26 07:47:06 downsj Exp $ +.\" +.Dd Jan 28, 1995 +.Dt FILE2C 1 +.Os +.Sh NAME +.Nm file2c +.Nd convert file to c-source. +.Sh SYNOPSIS +.Nm file2c +.Op "string" +.Op "string" +.Sh DESCRIPTION +The +.Nm file2c +utility reads a file from stdin and writes it to stdout, converting each +byte to its decimal representation on the fly. +.Pp +If the first +.Op string +is present, it is printed before the data, if the second +.Op string +is present, it is printed after the data. +.Pp +This program is used to embedd binary or other files into C source files, +for instance as a char[]. +.Sh EXAMPLE +The command: +.Bd -literal -offset indent +date | file2c 'const char date[] = {' ',0};' +.Ed +.Pp +will produce: +.Bd -literal -offset indent +const char date[] = { +83,97,116,32,74,97,110,32,50,56,32,49,54,58,50,56,58,48,53, +32,80,83,84,32,49,57,57,53,10 +,0}; +.Ed + + diff --git a/usr.bin/file2c/file2c.c b/usr.bin/file2c/file2c.c new file mode 100644 index 00000000000..b5405b351a4 --- /dev/null +++ b/usr.bin/file2c/file2c.c @@ -0,0 +1,49 @@ +/* $OpenBSD: file2c.c,v 1.1 1996/08/26 07:47:06 downsj Exp $ */ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: file2c.c,v 1.1 1995/01/29 00:49:57 phk Exp $ + * + */ + +#include <stdio.h> + +int +main(argc, argv) + int argc; + char **argv; +{ + int i,j,k; + char s[10]; + + if (argc > 1) + printf("%s\n",argv[1]); + k = 0; + j = 0; + while((i = getchar()) != EOF) { + if(k++) { + putchar(','); + j++; + } + if (j > 70) { + putchar('\n'); + j = 0; + } + printf("%d",i); + if (i > 99) + j += 3; + else if (i > 9) + j += 2; + else + j++; + } + putchar('\n'); + if (argc > 2) + printf("%s\n",argv[2]); + return 0; +} |