|
|
1.1 root 1: /* asc2ans.c */
2:
3: /* Converts Synchronet Ctrl-A codes into ANSI escape sequences */
4:
5: /* $Id: asc2ans.c,v 1.1 2003/09/19 01:47:17 rswindell Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include <stdio.h>
39: #include <ctype.h> /* toupper */
40:
41: #define ANSI fprintf(out,"\x1b[")
42:
43: int main(int argc, char **argv)
44: {
45: char revision[16];
46: int ch;
47: FILE* in;
48: FILE* out;
49:
50: sscanf("$Revision: 1.1 $", "%*s %s", revision);
51:
52: if(argc<3) {
53: fprintf(stderr,"\nasc2ans %s\n",revision);
54: fprintf(stderr,"\nusage: %s infile.asc outfile.ans\n",argv[0]);
55: return(0);
56: }
57:
58: if((in=fopen(argv[1],"rb"))==NULL) {
59: perror(argv[1]);
60: return(1);
61: }
62:
63: if((out=fopen(argv[2],"wb"))==NULL) {
64: perror(argv[2]);
65: return(1);
66: }
67:
68: while((ch=fgetc(in))!=EOF) {
69: if(ch==1) { /* ctrl-a */
70: ch=fgetc(in);
71: if(ch==EOF)
72: break;
73: if(ch>=0x7f) { /* move cursor right x columns */
74: ANSI;
75: fprintf(out,"%uC",ch-0x7f);
76: continue;
77: }
78: switch(toupper(ch)) {
79: case 'A':
80: fputc('\1',out);
81: break;
82: case '<':
83: fputc('\b',out);
84: break;
85: case '>':
86: ANSI;
87: fputc('K',out);
88: break;
89: case '[':
90: fputc('\r',out);
91: break;
92: case ']':
93: fputc('\n',out);
94: break;
95: case 'L':
96: ANSI;
97: fprintf(out,"2J");
98: break;
99: case '-':
100: case '_':
101: case 'N':
102: ANSI;
103: fprintf(out,"0m");
104: break;
105: case 'H':
106: ANSI;
107: fprintf(out,"1m");
108: break;
109: case 'I':
110: ANSI;
111: fprintf(out,"5m");
112: break;
113: case 'K':
114: ANSI;
115: fprintf(out,"30m");
116: break;
117: case 'R':
118: ANSI;
119: fprintf(out,"31m");
120: break;
121: case 'G':
122: ANSI;
123: fprintf(out,"32m");
124: break;
125: case 'Y':
126: ANSI;
127: fprintf(out,"33m");
128: break;
129: case 'B':
130: ANSI;
131: fprintf(out,"34m");
132: break;
133: case 'M':
134: ANSI;
135: fprintf(out,"35m");
136: break;
137: case 'C':
138: ANSI;
139: fprintf(out,"36m");
140: break;
141: case 'W':
142: ANSI;
143: fprintf(out,"37m");
144: break;
145: case '0':
146: ANSI;
147: fprintf(out,"40m");
148: break;
149: case '1':
150: ANSI;
151: fprintf(out,"41m");
152: break;
153: case '2':
154: ANSI;
155: fprintf(out,"42m");
156: break;
157: case '3':
158: ANSI;
159: fprintf(out,"43m");
160: break;
161: case '4':
162: ANSI;
163: fprintf(out,"44m");
164: break;
165: case '5':
166: ANSI;
167: fprintf(out,"45m");
168: break;
169: case '6':
170: ANSI;
171: fprintf(out,"46m");
172: break;
173: case '7':
174: ANSI;
175: fprintf(out,"47m");
176: break;
177: default:
178: fprintf(out,"\1%c",ch);
179: break;
180: }
181: }
182: else
183: fputc(ch,out);
184: }
185:
186: return(0);
187: }
188:
189:
190:
191:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.