2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
5 Copyright (c) 2012 Tim Blechmann. All rights reserved.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 int rtf2txt(char* txt
)
31 if (strncmp(txt
,"{\\rtf",5)!=0) return 0; // OK, not an RTF file
33 switch (txt
[wrpos
]=txt
[rdpos
++])
38 sprintf(fname, "rtf2txt_out%d.txt", bugctr++);
39 FILE *fp = fopen(fname, "w");
40 fwrite(txt,wrpos,1,fp);
48 if (strncmp(txt
+rdpos
,"fonttbl",7)==0
49 || strncmp(txt
+rdpos
,"filetbl",7)==0
50 || strncmp(txt
+rdpos
,"colortbl",8)==0
51 || strncmp(txt
+rdpos
,"stylesheet",10)==0
55 while(level
&& (c
=txt
[rdpos
++]) != 0) {
56 if (c
== OPENCURLY
) level
++;
57 else if (c
== CLOSCURLY
) level
--;
59 } else if (strncmp(txt
+rdpos
,"\'a0",3)==0 || (strncmp(txt
+rdpos
,"\'A0",3)==0))
61 txt
[wrpos
++] = ' '; rdpos
= rdpos
+ 3;
63 if (txt
[rdpos
]==CLOSCURLY
|| txt
[rdpos
]==OPENCURLY
64 || txt
[rdpos
]=='\\' || txt
[rdpos
]=='\t'|| txt
[rdpos
]=='\n')
65 { txt
[wrpos
++] = txt
[rdpos
++]; goto text
; }
66 if (strncmp(txt
+rdpos
,"tab",3)==0) { txt
[wrpos
++] = '\t'; }
67 if (strncmp(txt
+rdpos
,"par",3)==0) { txt
[wrpos
++] = '\n'; }
69 while((c
=txt
[rdpos
++]) && c
!=' ' && c
!='\\');
79 // strips HTML down to plaintext tags in a fairly simple-minded way
80 int html2txt(char* txt
)
82 int rdpos
=-1, wrpos
=0, bodypos
=-1;
85 // First check if we can find a BODY tag to start at
86 while(bodypos
== -1 && txt
[++rdpos
] != 0){
87 if(strncmp(txt
+rdpos
, "<body", 5) == 0) // FIXME: should be case-insensitive, ideally
95 // Now we start from our start, and add the non-tag text to the result
96 while(txt
[rdpos
] != 0){
98 if(txt
[rdpos
++] == '>')
101 if(txt
[rdpos
] == '<'){
106 if(strncmp(txt+rdpos, "&", 5)==0){
109 }else if(strncmp(txt+rdpos, " ", 6)==0){
112 }else if(strncmp(txt+rdpos, "<", 4)==0){
115 }else if(strncmp(txt+rdpos, ">", 4)==0){
120 txt
[wrpos
++] = txt
[rdpos
++];