Thu Mar 8 16:43:05 2012 UTC ()
Prevent expansion of $NetBSD$ that should be placed verbatim into output.


(jakllsch)
diff -r1.9 -r1.10 src/sys/dev/microcode/cyclades-z/cyzfirm2h.c

cvs diff -r1.9 -r1.10 src/sys/dev/microcode/cyclades-z/cyzfirm2h.c (switch to unified diff)

--- src/sys/dev/microcode/cyclades-z/cyzfirm2h.c 2012/03/08 16:40:37 1.9
+++ src/sys/dev/microcode/cyclades-z/cyzfirm2h.c 2012/03/08 16:43:04 1.10
@@ -1,141 +1,141 @@ @@ -1,141 +1,141 @@
1/* $NetBSD: cyzfirm2h.c,v 1.9 2012/03/08 16:40:37 jakllsch Exp $ */ 1/* $NetBSD: cyzfirm2h.c,v 1.10 2012/03/08 16:43:04 jakllsch Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 Zembu Labs, Inc. 4 * Copyright (c) 2000 Zembu Labs, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Author: Jason R. Thorpe <thorpej@zembu.com> 7 * Author: Jason R. Thorpe <thorpej@zembu.com>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement: 18 * must display the following acknowledgement:
19 * This product includes software developed by Zembu Labs, Inc. 19 * This product includes software developed by Zembu Labs, Inc.
20 * 4. Neither the name of Zembu Labs nor the names of its employees may 20 * 4. Neither the name of Zembu Labs nor the names of its employees may
21 * be used to endorse or promote products derived from this software 21 * be used to endorse or promote products derived from this software
22 * without specific prior written permission. 22 * without specific prior written permission.
23 * 23 *
24 * THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS 24 * THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS
25 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR- 25 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR-
26 * RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS- 26 * RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
27 * CLAIMED. IN NO EVENT SHALL ZEMBU LABS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * CLAIMED. IN NO EVENT SHALL ZEMBU LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36/* 36/*
37 * This program converts a binary Cyclades-Z firmware file into a 37 * This program converts a binary Cyclades-Z firmware file into a
38 * C header file for use in a device driver. 38 * C header file for use in a device driver.
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__RCSID("$NetBSD: cyzfirm2h.c,v 1.9 2012/03/08 16:40:37 jakllsch Exp $"); 42__RCSID("$NetBSD: cyzfirm2h.c,v 1.10 2012/03/08 16:43:04 jakllsch Exp $");
43 43
44#include <sys/types.h> 44#include <sys/types.h>
45#include <sys/mman.h> 45#include <sys/mman.h>
46#include <err.h> 46#include <err.h>
47#include <ctype.h> 47#include <ctype.h>
48#include <fcntl.h> 48#include <fcntl.h>
49#include <string.h> 49#include <string.h>
50#include <stdio.h> 50#include <stdio.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <unistd.h> 52#include <unistd.h>
53 53
54int main(int argc, char *argv[]); 54int main(int argc, char *argv[]);
55void usage(void); 55void usage(void);
56 56
57int 57int
58main(int argc, char *argv[]) 58main(int argc, char *argv[])
59{ 59{
60 off_t in_len; 60 off_t in_len;
61 u_char *in_ptr; 61 u_char *in_ptr;
62 FILE *out_file; 62 FILE *out_file;
63 char *include_name, *cp; 63 char *include_name, *cp;
64 int i; 64 int i;
65 65
66 if (argc != 3) 66 if (argc != 3)
67 usage(); 67 usage();
68 68
69 i = open(argv[1], O_RDONLY, 0644); 69 i = open(argv[1], O_RDONLY, 0644);
70 if (i < 0) 70 if (i < 0)
71 err(1, "unable to open %s", argv[1]); 71 err(1, "unable to open %s", argv[1]);
72 72
73 out_file = fopen(argv[2], "w+"); 73 out_file = fopen(argv[2], "w+");
74 if (out_file == NULL) 74 if (out_file == NULL)
75 err(1, "unable to create %s", argv[2]); 75 err(1, "unable to create %s", argv[2]);
76 76
77 /* 77 /*
78 * Create the string used in the header file for multiple 78 * Create the string used in the header file for multiple
79 * inclusion protection. 79 * inclusion protection.
80 */ 80 */
81 include_name = strdup(argv[2]); 81 include_name = strdup(argv[2]);
82 if (include_name == NULL) 82 if (include_name == NULL)
83 err(1, "unable to allocate include name"); 83 err(1, "unable to allocate include name");
84 84
85 for (cp = include_name; *cp != '\0'; cp++) { 85 for (cp = include_name; *cp != '\0'; cp++) {
86 if (isalpha((unsigned char)*cp)) 86 if (isalpha((unsigned char)*cp))
87 *cp = toupper((unsigned char)*cp); 87 *cp = toupper((unsigned char)*cp);
88 else if (*cp == '.') 88 else if (*cp == '.')
89 *cp = '_'; 89 *cp = '_';
90 } 90 }
91 91
92 in_len = lseek(i, 0, SEEK_END); 92 in_len = lseek(i, 0, SEEK_END);
93 if (in_len == (off_t) -1) 93 if (in_len == (off_t) -1)
94 err(1, "unable to determine length of input file"); 94 err(1, "unable to determine length of input file");
95 95
96 in_ptr = mmap(NULL, in_len, PROT_READ, MAP_FILE|MAP_SHARED, 96 in_ptr = mmap(NULL, in_len, PROT_READ, MAP_FILE|MAP_SHARED,
97 i, (off_t) 0); 97 i, (off_t) 0);
98 if (in_ptr == MAP_FAILED) 98 if (in_ptr == MAP_FAILED)
99 err(1, "unable to mmap input file"); 99 err(1, "unable to mmap input file");
100 (void) close(i); 100 (void) close(i);
101 101
102 fprintf(out_file, "/*\t$NetBSD: cyzfirm2h.c,v 1.9 2012/03/08 16:40:37 jakllsch Exp $\t*/\n\n"); 102 fprintf(out_file, "/*\t$""NetBSD""$\t*/\n\n");
103 fprintf(out_file, 103 fprintf(out_file,
104 "/*\n" 104 "/*\n"
105 " * Firmware for Cyclades Z series multiport serial boards.\n" 105 " * Firmware for Cyclades Z series multiport serial boards.\n"
106 " * Automatically generated from:\n" 106 " * Automatically generated from:\n"
107 " *\n" 107 " *\n"
108 " *\t%s\n" 108 " *\t%s\n"
109 " */\n\n", argv[1]); 109 " */\n\n", argv[1]);
110 fprintf(out_file, "#ifndef _%s_\n", include_name); 110 fprintf(out_file, "#ifndef _%s_\n", include_name);
111 fprintf(out_file, "#define\t_%s_\n\n", include_name); 111 fprintf(out_file, "#define\t_%s_\n\n", include_name);
112 112
113 fprintf(out_file, "static const uint8_t cycladesz_firmware[] = {\n"); 113 fprintf(out_file, "static const uint8_t cycladesz_firmware[] = {\n");
114 114
115 i = 0; 115 i = 0;
116 while (in_len != 0) { 116 while (in_len != 0) {
117 if (i == 0) 117 if (i == 0)
118 fprintf(out_file, "\t"); 118 fprintf(out_file, "\t");
119 fprintf(out_file, "0x%02x,", *in_ptr); 119 fprintf(out_file, "0x%02x,", *in_ptr);
120 in_ptr++; 120 in_ptr++;
121 in_len--; 121 in_len--;
122 i++; 122 i++;
123 if (i == 10) { 123 if (i == 10) {
124 fprintf(out_file, "\n"); 124 fprintf(out_file, "\n");
125 i = 0; 125 i = 0;
126 } else if (in_len != 0) { 126 } else if (in_len != 0) {
127 fprintf(out_file, " "); 127 fprintf(out_file, " ");
128 } 128 }
129 } 129 }
130 fprintf(out_file, "\n};\n\n"); 130 fprintf(out_file, "\n};\n\n");
131 131
132 fprintf(out_file, "#endif /* _%s_ */\n", include_name); 132 fprintf(out_file, "#endif /* _%s_ */\n", include_name);
133} 133}
134 134
135void 135void
136usage(void) 136usage(void)
137{ 137{
138 138
139 fprintf(stderr, "usage: %s infile outfile\n", getprogname()); 139 fprintf(stderr, "usage: %s infile outfile\n", getprogname());
140 exit(1); 140 exit(1);
141} 141}