IRQ handler rewrite by Gabor Juhos, uses C no longer assembly
[openwrt/svn-archive/archive.git] / target / linux / etrax-2.6 / image / e100boot / src / sbl / cconv
1 #!/usr/bin/perl
2 #!
3 #! FILE NAME : cconv
4 #!
5 #! PARAMETERS : Name of C program array variable.
6 #!
7 #! DESCRIPTION: Converts bytes of a binary file to C source code containing
8 #! char array initialized with the binary file data.
9 #!
10 #! SUBROUTINES:
11 #!
12 #!---------------------------------------------------------------------------
13 #! HISTORY
14 #!
15 #! DATE NAME CHANGES
16 #! ---- ---- -------
17 #! Dec 15 1997 Sven Ekstrom Initial version. Rewritten to Perl from C.
18 #! Dec 16 1997 Sven Ekstrom Fixed bug that generated truncated result.
19 #!
20 #!---------------------------------------------------------------------------
21 #!
22 #! (C) Copyright 1997, Axis Communications AB, LUND, SWEDEN
23 #!
24 #!***************************************************************************
25 # @(#) cconv 1.2 12/16/97
26
27 #********************** CONSTANT SECTION ************************************
28
29 $MyName = 'cconv';
30
31 #
32 # Number of bytes per line in the result.
33 #
34 $LineLength = 8;
35
36 #********************** MAIN PROGRAM SECTION ********************************
37
38 #
39 # Make sure the command line contains the name of a C array.
40 #
41 if (scalar @ARGV != 1 || $ARGV[0] =~ /^-/)
42 {
43 die "$MyName: Usage:\n",
44 "\n",
45 " Syntax\n",
46 " $MyName <name of C char array>\n",
47 "\n",
48 " <name of C char array> : This is the name of the char array where\n",
49 " the result is placed.\n",
50 "\n",
51 " Description\n",
52 "\n",
53 " Reads input from STDIN as binary data. Each byte of input data is\n",
54 " converted to C char data in hexadecimal form. The whole file read\n",
55 " from STDIN is converted and the result, C source code definition of\n",
56 " a char array, is printed on STDOUT.\n",
57 "\n";
58 }
59
60 #
61 # Start with the name and version of this program and the name of the array.
62 #
63 print "\n",
64 "/* $MyName 1.2 12/16/97, Copyright (C) 1997, Axis Communications AB */\n",
65 "\n",
66 "const char $ARGV[0]\[\] =\n",
67 "{";
68
69 #
70 # Read all bytes from STDIN, convert them to char data and print them on
71 # STDOUT.
72 #
73 $CurrentOffset = 0;
74 while (!eof(STDIN))
75 {
76 $Byte = ord(getc);
77
78 if ($CurrentOffset % $LineLength == 0)
79 {
80 #
81 # Start of a new line.
82 #
83 if ($CurrentOffset != 0)
84 {
85 #
86 # This is not the first byte.
87 #
88 print ",";
89 }
90 #
91 # The new line is indented by 2 spaces.
92 #
93 print "\n",
94 " ";
95 }
96 else
97 {
98 #
99 # Continuing an old line.
100 #
101 print ", ";
102 }
103
104 #
105 # Print the value of the byte as hex char data.
106 #
107 printf("'\\x%02x'", $Byte);
108
109 $CurrentOffset++;
110 }
111
112 if ($CurrentOffset == 0)
113 {
114 #
115 # Initialize the array with a single byte of zero.
116 #
117 print "\n '\\x00'";
118 }
119
120 #
121 # End with the closing bracket and semicolon.
122 #
123 print "\n",
124 "};\n";
125
126 exit 0;
127
128
129 #********************** SUBROUTINE DEFINITION SECTION ***********************
130
131 #****************************************************************************
132 #*
133 #* SUBROUTINE :
134 #*
135 #* PARAMETERS :
136 #*
137 #* RETURNS :
138 #*
139 #* SIDE EFFECTS:
140 #*
141 #* DESCRIPTION :
142 #*
143 #*---------------------------------------------------------------------------
144 #* HISTORY
145 #*
146 #* DATE NAME CHANGES
147 #* ---- ---- -------
148 #* May 05, 1995 Sven Ekstrom Initial version
149 #*
150 #****************************************************************************
151
152 #sub NN
153 #{
154 # local() = @_;
155 #
156 #}
157
158 #************************ END OF FILE cconv *********************************