|
|
1.1 root 1: /* asc2ans.c */
2:
3: /* Converts Synchronet Ctrl-A codes into ANSI escape sequences */
4:
5: /* $Id: asc2ans.c,v 1.4 2006/05/09 23:03:09 deuce 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: #include <string.h> /* strcmp */
41:
42: #define ANSI fprintf(out,"\x1b[")
43:
44: int main(int argc, char **argv)
45: {
46: char revision[16];
47: int ch;
48: FILE* in;
49: FILE* out;
50:
51: sscanf("$Revision: 1.4 $", "%*s %s", revision);
52:
53: if(argc<2) {
54: fprintf(stderr,"\nasc2ans %s\n",revision);
55: fprintf(stderr,"\nusage: %s infile.asc [outfile.ans]\n",argv[0]);
56: return(0);
57: }
58:
59: if(strcmp(argv[1],"-")) {
60: if((in=fopen(argv[1],"rb"))==NULL) {
61: perror(argv[1]);
62: return(1);
63: }
64: }
65: else
66: in=stdin;
67:
68: if(argc > 2 && (strcmp(argv[2],"-"))) {
69: if((out=fopen(argv[2],"wb"))==NULL) {
70: perror(argv[2]);
71: return(1);
72: }
73: }
74: else
75: out=stdout;
76:
77: while((ch=fgetc(in))!=EOF) {
78: if(ch==1) { /* ctrl-a */
79: ch=fgetc(in);
80: if(ch==EOF)
81: break;
82: if(ch>=0x7f) { /* move cursor right x columns */
83: ANSI;
84: fprintf(out,"%uC",ch-0x7f);
85: continue;
86: }
87: switch(toupper(ch)) {
88: case 'A':
89: fputc('\1',out);
90: break;
91: case '<':
92: fputc('\b',out);
93: break;
94: case '>':
95: ANSI;
96: fputc('K',out);
97: break;
98: case '[':
99: fputc('\r',out);
100: break;
101: case ']':
102: fputc('\n',out);
103: break;
104: case 'L':
105: ANSI;
106: fprintf(out,"2J");
107: break;
108: case '-':
109: case '_':
110: case 'N':
111: ANSI;
112: fprintf(out,"0m");
113: break;
114: case 'H':
115: ANSI;
116: fprintf(out,"1m");
117: break;
118: case 'I':
119: ANSI;
120: fprintf(out,"5m");
121: break;
122: case 'K':
123: ANSI;
124: fprintf(out,"30m");
125: break;
126: case 'R':
127: ANSI;
128: fprintf(out,"31m");
129: break;
130: case 'G':
131: ANSI;
132: fprintf(out,"32m");
133: break;
134: case 'Y':
135: ANSI;
136: fprintf(out,"33m");
137: break;
138: case 'B':
139: ANSI;
140: fprintf(out,"34m");
141: break;
142: case 'M':
143: ANSI;
144: fprintf(out,"35m");
145: break;
146: case 'C':
147: ANSI;
148: fprintf(out,"36m");
149: break;
150: case 'W':
151: ANSI;
152: fprintf(out,"37m");
153: break;
154: case '0':
155: ANSI;
156: fprintf(out,"40m");
157: break;
158: case '1':
159: ANSI;
160: fprintf(out,"41m");
161: break;
162: case '2':
163: ANSI;
164: fprintf(out,"42m");
165: break;
166: case '3':
167: ANSI;
168: fprintf(out,"43m");
169: break;
170: case '4':
171: ANSI;
172: fprintf(out,"44m");
173: break;
174: case '5':
175: ANSI;
176: fprintf(out,"45m");
177: break;
178: case '6':
179: ANSI;
180: fprintf(out,"46m");
181: break;
182: case '7':
183: ANSI;
184: fprintf(out,"47m");
185: break;
186: default:
187: fprintf(out,"\1%c",ch);
188: break;
189: }
190: }
191: else
192: fputc(ch,out);
193: }
194:
195: return(0);
196: }
197:
198:
199:
200:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.