|
|
1.1 root 1: /* ans2asc.c */
2:
3: /* Convert ANSI messages to Synchronet .asc (Ctrl-A code) format */
4:
5: /* $Id: ans2asc.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 <stdlib.h>
40: #include <ctype.h> /* isdigit */
41:
42: int main(int argc, char **argv)
43: {
44: char esc,n[25];
45: char revision[16];
46: int i,ch,ni;
47: FILE *in,*out;
48:
49: sscanf("$Revision: 1.1 $", "%*s %s", revision);
50:
51: if(argc<3) {
52: fprintf(stderr,"\nans2asc %s\n",revision);
53: fprintf(stderr,"\nusage: %s infile.ans outfile.asc\n",argv[0]);
54: return(0);
55: }
56:
57: if((in=fopen(argv[1],"rb"))==NULL) {
58: perror(argv[1]);
59: return(1);
60: }
61:
62: if((out=fopen(argv[2],"wb"))==NULL) {
63: perror(argv[2]);
64: return(1);
65: }
66:
67: esc=0;
68: while((ch=fgetc(in))!=EOF) {
69: if(ch=='[' && esc) { /* ANSI escape sequence */
70: ni=0; /* zero number index */
71: while((ch=fgetc(in))!=EOF) {
72: if(isdigit(ch)) { /* 1 digit */
73: n[ni]=ch&0xf;
74: ch=fgetc(in);
75: if(ch==EOF)
76: break;
77: if(isdigit(ch)) { /* 2 digits */
78: n[ni]*=10;
79: n[ni]+=ch&0xf;
80: ch=fgetc(in);
81: if(ch==EOF)
82: break;
83: if(isdigit(ch)) { /* 3 digits */
84: n[ni]*=10;
85: n[ni]+=ch&0xf;
86: ch=fgetc(in);
87: }
88: }
89: ni++;
90: }
91: if(ch==';')
92: continue;
93: switch(ch) {
94: case '=':
95: case '?':
96: ch=fgetc(in); /* First digit */
97: if(isdigit(ch)) ch=fgetc(in); /* l or h ? */
98: if(isdigit(ch)) ch=fgetc(in);
99: if(isdigit(ch)) fgetc(in);
100: break;
101: case 'J':
102: if(n[0]==2) /* clear screen */
103: fputs("\1l",out); /* ctrl-al */
104: break;
105: case 'K':
106: fputs("\1>",out); /* clear to eol */
107: break;
108: case 'm':
109: for(i=0;i<ni;i++) {
110: fputc(1,out); /* ctrl-ax */
111: switch(n[i]) {
112: default:
113: case 0:
114: case 2: /* no attribute */
115: fputc('n',out);
116: break;
117: case 1: /* high intensity */
118: fputc('h',out);
119: break;
120: case 3:
121: case 4:
122: case 5: /* blink */
123: case 6:
124: case 7:
125: fputc('i',out);
126: break;
127: case 8: /* concealed */
128: fputc('e',out);
129: break;
130: case 30:
131: fputc('k',out);
132: break;
133: case 31:
134: fputc('r',out);
135: break;
136: case 32:
137: fputc('g',out);
138: break;
139: case 33:
140: fputc('y',out);
141: break;
142: case 34:
143: fputc('b',out);
144: break;
145: case 35:
146: fputc('m',out);
147: break;
148: case 36:
149: fputc('c',out);
150: break;
151: case 37:
152: fputc('w',out);
153: break;
154: case 40:
155: fputc('0',out);
156: break;
157: case 41:
158: fputc('1',out);
159: break;
160: case 42:
161: fputc('2',out);
162: break;
163: case 43:
164: fputc('3',out);
165: break;
166: case 44:
167: fputc('4',out);
168: break;
169: case 45:
170: fputc('5',out);
171: break;
172: case 46:
173: fputc('6',out);
174: break;
175: case 47:
176: fputc('7',out);
177: break; } }
178: break;
179: case 'C':
180: fprintf(out,"\1%c",0x7f+n[0]);
181: break;
182: default:
183: fprintf(stderr,"Unsupported ANSI code '%c' (0x%02X)\r\n",ch,ch);
184: break;
185: }
186: break;
187: } /* end of while */
188: esc=0;
189: continue;
190: } /* end of ANSI expansion */
191: if(ch=='\x1b')
192: esc=1;
193: else {
194: esc=0;
195: fputc(ch,out);
196: }
197: }
198: return(0);
199: }
200:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.