]>
git.saurik.com Git - apple/bootx.git/blob - fcode-to-c.tproj/fcode-to-c.c
c566c38a2f63bf2e7886f4dfc22989d7a43eb1ba
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * fcode-to-c.c - Takes an OF FCODE image and generates a .c file.
25 * Copyright (c) 1999-2000 Apple Computer, Inc.
37 int main(int argc
, char **argv
)
39 char varName
[256], inFileName
[256], outFileName
[256], *tmpStr
;
40 FILE *inFile
, *outFile
;
46 fprintf(stderr
, "Usage: %s var-name file.fcode\n", gToolName
);
50 strncpy(varName
, argv
[1], 255);
52 strncpy(inFileName
, argv
[2], 255);
53 strncpy(outFileName
, argv
[2], 255);
56 while ((*tmpStr
!= '.') && (*tmpStr
!= '\0')) tmpStr
++;
57 if ((*tmpStr
== '\0') || strncmp(tmpStr
, ".fcode", 6)) {
58 fprintf(stderr
, "Usage: %s var-name file.fcode\n", gToolName
);
65 inFile
= fopen(inFileName
, "rb");
67 fprintf(stderr
, "%s: failed to open %s\n", gToolName
, inFileName
);
71 outFile
= fopen(outFileName
, "w");
72 if (outFile
== NULL
) {
73 fprintf(stderr
, "%s: failed to open %s\n", gToolName
, outFileName
);
77 fprintf(outFile
, "const char %s[] = {", varName
);
80 while ((tc
= fgetc(inFile
)) != EOF
) {
81 if (cnt
== 0) fputc('\n', outFile
);
82 fprintf(outFile
, "0x%02x,", (unsigned char)tc
);
83 if (cnt
++ == 0x20) cnt
= 0;
86 fprintf(outFile
, "\n};");