Made UAE buildable again.
[AROS-Contrib.git] / gfx / lcms / filter.c
blob8661bfd5ab8c8b05910c734508c20005366b7440
1 /*
2 //
3 // Little cms sources filter utility
4 // Copyright (C) 1998-2001 Marti Maria
5 //
6 // THIS SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
7 // EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
8 // WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
9 //
10 // IN NO EVENT SHALL MARTI MARIA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
11 // INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
12 // OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
13 // WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
14 // LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
15 // OF THIS SOFTWARE.
18 // This library is free software; you can redistribute it and/or
19 // modify it under the terms of the GNU Lesser General Public
20 // License as published by the Free Software Foundation; either
21 // version 2 of the License, or (at your option) any later version.
23 // This library is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 // Lesser General Public License for more details.
28 // You should have received a copy of the GNU Lesser General Public
29 // License along with this library; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 // A simple filter to strip CR and ^Z, and replace //-like comments to old style
37 #include <stdio.h>
38 #include <io.h>
41 static int ch;
42 static int IsEof;
43 static FILE *In, *Out;
46 static
47 void NextCh(void)
49 if (IsEof)
50 ch = 0;
51 else {
52 do {
54 ch = getc(In);
56 } while (ch == '\r' || ch == '\032'); /* Ignore CR and ^Z */
58 IsEof = (ch == EOF);
59 if (IsEof) ch = 0;
64 static
65 void Translate(void)
67 IsEof = 0;
68 while (!IsEof) {
70 NextCh();
71 switch (ch) {
73 case '/':
74 NextCh();
75 if (ch == '/') { /* Found comment */
77 NextCh();
79 /* Cleanup white spaces */
80 while (ch == ' ' && !IsEof)
81 NextCh();
83 if (ch == '\n' && !IsEof) /* Comment is empty */
84 break;
86 /* Comment contains something */
88 putc('/', Out);
89 putc('*', Out);
90 putc(' ', Out);
92 while (ch != '\n' && !IsEof) {
94 putc(ch, Out);
95 NextCh();
97 putc(' ', Out);
98 putc('*', Out);
99 putc('/', Out);
101 else
102 putc('/', Out);
103 break;
106 default:;
109 if (ch != 0)
110 putc(ch, Out);
115 int main(int argc, char *argv[])
118 if (argc != 3)
120 fprintf(stderr, "Usage: %s infile outfile\n", argv[0]);
121 return 1;
125 if (access(argv[2], 0) == 0)
127 fprintf(stderr, "%s already exist, please erase manually\n", argv[2]);
128 return 1;
131 In = fopen(argv[1], "rb");
132 if (!In) { perror(argv[1]); return 1;};
134 Out = fopen(argv[2], "wb");
135 if (!Out) { perror(argv[2]); return 2;};
137 Translate();
139 fclose(In); fclose(Out);
141 return 0;