1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
|
/******************************************************************************
* program: wp2latex *
* function: module for conversion Text602 files into LaTeX *
* modul: pass1602.cc *
* description: This module contains parser for T602 documents. It could be *
* optionally not compiled with WP2LaTeX package. *
* licency: GPL *
******************************************************************************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stringa.h>
#include<lists.h>
#include<dbllist.h>
#include"wp2latex.h"
#include "cp_lib/cptran.h"
#include "images/img_futi.h"
#define T602Version "0.06"
class TconvertedPass1_602: public TconvertedPass1
{
public:
string cmd,args;
int color;
int beg_par; /* is begining of paragraph ? */
int is_link; /* is this a link ? */
int wendl; /* is this end of line only ? */
int nsp; /* nmuber of spaces */
virtual int Convert_first_pass(void);
void ChangeEncoding(void);
void ProcessKey602(void);
void HeaderFooter602(const string &args, char He_Fo=0);
void Image602(void);
};
/*Register translators here*/
TconvertedPass1 *Factory_602(void) {return new TconvertedPass1_602;}
FFormatTranslator Format602("T602",Factory_602);
/* Definition of special characters */
#define CR '\xd'
#define ENDL 141
#define NNSP 10
/* Known text styles */
#define BLD 2
#define ITL 4
#define UND 19
#define ENL 15
#define HIG 16
#define BIG 29
#define SUB 22
#define SUP 20
#define COLOR_SIZE 6
void TconvertedPass1_602::ChangeEncoding(void)
{
#ifdef DEBUG
fprintf(log,"\n#ChangeEncoding() ");fflush(log);
#endif
long value;
string translator;
args.trim();
value = atol(args());
switch(value)
{
case 0:translator="kam";break; //"895"
case 1:translator="cp852";break; //latin2
case 2:translator="koi8cs";break; //koi8cs
default:ConvertCpg = NULL;
}
if(!translator.isEmpty())
{
translator+="TOinternal";
ConvertCpg = GetTranslator(translator);
}
}
void TconvertedPass1_602::HeaderFooter602(const string &args, char He_Fo)
{
#ifdef DEBUG
fprintf(log,"\n#HeaderFooter602() ");fflush(log);
#endif
attribute OldAttr;
string s;
unsigned char OldFlag,OldEnvir;
int i;
const char *Header_Text = args();
if(Header_Text==NULL) return;
OldFlag = flag;
OldEnvir= envir;
recursion++;
line_term = 's'; //Soft return
if(char_on_line == LEAVE_ONE_EMPTY_LINE) /* Left one empty line for new enviroment */
{
fputc('%', table);
fputc('%', strip);
NewLine(this);
}
if(char_on_line==CHAR_PRESENT)
{
NewLine(this);
}
Close_All_Attr(attr,strip);
OldAttr=attr; /* Backup all attributes */
/* Any of section's attr cannot be opened */
for(i=First_com_section;i<=Last_com_section;i++)
_AttrOff(attr,i,s); // !!!!!! toto predelat!
InitHeaderFooter(this,He_Fo,1);
envir = '!'; //Ignore enviroments after header/footer
NewLine(this);
attr.InitAttr(); //Turn all attributes in the header/footer off
flag = HeaderText;
envir = ' ';
ActualPos = ftell(wpd);
char_on_line = FIRST_CHAR_MINIPAGE;
while(*Header_Text!=0)
{
by=*Header_Text++;
if(by=='#') PageNumber(this);
else ProcessKey602();
}
Close_All_Attr(attr,strip);
if(char_on_line==CHAR_PRESENT)
{
line_term = 's'; //Soft return
NewLine(this);
}
putc('}', strip);
line_term = 's'; //Soft return
envir = '^'; //Ignore enviroments after header/footer
NewLine(this);
attr = OldAttr; // Restore backuped attributes
flag = OldFlag;
envir = OldEnvir;
char_on_line = FIRST_CHAR_MINIPAGE; // stronger false;
recursion--;
strcpy(ObjType,(He_Fo & 3)<=1?"Header":"Footer");
}
void TconvertedPass1_602::Image602(void)
{
#ifdef DEBUG
fprintf(log,"\n#TconvertedPass1_602::Image602() ");fflush(log);
#endif
TBox Box;
char *str,ch;
char CommaCount;
CommaCount=0;
str = args();
if(str==NULL) return;
initBox(Box);
while((ch=*str)!=0)
{
switch(CommaCount)
{
case 0:if(isspace(ch) || ch==',') *str=0;
break;
case 4:if(isdigit(ch)) //4'th argument is rotation angle
{
Box.RotAngle=atoi(str);
goto skip;
}
break;
case 5:goto skip;
}
if(ch==',') CommaCount++;
str++;
}
skip:
Box.Image_type = 0; //Image on disk
Box.Contents = 3;
Box.HorizontalPos=3; //Full
ImageWP(this,this->args,Box);
*str = ch;
}
void TconvertedPass1_602::ProcessKey602(void)
{
#ifdef DEBUG
fprintf(log,"\n#ProcessKey602() ");fflush(log);
#endif
string TAG;
const char *tag;
*ObjType = 0;
if(by==0) by=fgetc(wpd);
switch(by)
{
case '@':if(char_on_line<=0)
{
cmd.erase();
while(!feof(wpd))
{
const char c = fgetc(wpd);
if(isspace(c)) break;
cmd += c;
}
fGets2(wpd, args);
char_on_line=0;
if(cmd=="CT") ChangeEncoding();
if(cmd=="FO") HeaderFooter602(args,2);
if(cmd=="HE") HeaderFooter602(args,1);
if(cmd=="PA") HardPage(this);
break;
}
goto DEFAULT;
case '{':if(!is_link)
{
const char tmp = fgetc(wpd);
if(tmp=='#')
{
//scanf("%s", cmd);
printf("<A NAME=\"POS%s\">", cmd());
is_link=1;
}
else if(tmp=='!')
{
//scanf("%s", cmd());
printf("<A HREF=\"#POS%s\">", cmd());
is_link=1;
}
else
{
ungetc(tmp, wpd);
goto DEFAULT;
}
}
break;
case '}' :if(is_link)
{
is_link=0;
printf("</A>");
}
else goto DEFAULT;
break;
case CR : break;
case ENDL : SoftReturn(this);
wendl=1;
break;
case BLD : if(IsAttrOn(attr,12)<0) Attr_ON(this,12);
else Attr_OFF(this,12);
break;
case ITL : if(IsAttrOn(attr,8)<0) Attr_ON(this,8);
else Attr_OFF(this,8);
break;
case UND : if(IsAttrOn(attr,14)<0) Attr_ON(this,14);
else Attr_OFF(this,14);
break;
case ENL : if(IsAttrOn(attr,2)<0) Attr_ON(this,2);
else Attr_OFF(this,2);
break; //<FONT SIZE=+1>
case HIG : if(IsAttrOn(attr,1)<0) Attr_ON(this,1);
else Attr_OFF(this,1);
break; //<FONT SIZE=+3>
case BIG : if(IsAttrOn(attr,0)<0) Attr_ON(this,0);
else Attr_OFF(this,0);
break; //<FONT SIZE=+4>
case SUB : if(IsAttrOn(attr,6)<0) Attr_ON(this,6);
else Attr_OFF(this,6);
break;
case SUP : if(IsAttrOn(attr,5)<0) Attr_ON(this,5);
else Attr_OFF(this,5);
break;
case '\n' : beg_par=1;
if(!wendl) HardReturn(this);
wendl=0;
break;
case ' ' : if(char_on_line<=0) nsp++;
else fputc(' ',strip);
break;
case '.' : if(char_on_line<=0)
{
cmd.erase();
while(!feof(wpd))
{
const char c = fgetc(wpd);
if(isspace(c)) break;
cmd += c;
}
fGets2(wpd, args);
if(cmd=="PI") Image602();
else {
fprintf(strip,"%% .%s %s",cmd(),args());
}
char_on_line=0;
break;
}
goto DEFAULT;
default :
DEFAULT: if(beg_par)
{
if(nsp > NNSP)
{if(toupper(envir)!='C') Justification(this,0x82);} //center
else if(char_on_line<=0 && toupper(envir)=='C')
Justification(this,0x81); //full
}
if(nsp>0) fputc(' ',strip);
if((unsigned)by > ' ')
{ //Normal character
tag = Ext_chr_str(by,this,ConvertCpg);
CharacterStr(this,tag);
}
char_on_line=1;
beg_par=nsp=wendl=0;
break;
}
ActualPos = ftell(wpd);
}
int TconvertedPass1_602::Convert_first_pass(void)
{
#ifdef DEBUG
fprintf(log,"\n#Convert_pass1_602() ");fflush(log);
#endif
DWORD fsize;
if(Verbosing >= 1)
printf(_("\n>>>T602toLaTeX<<< Conversion program: From T602 to LaTeX Version %s\n"
" Made by J.Fojtik (Hosted on WP2LaTeX :))))\n\n"),
T602Version);
DocumentStart=ftell(wpd);
fsize = FileSize(wpd);
perc.Init(ftell(wpd), fsize,_("First pass T602:") );
color=1;
beg_par=1;
is_link=0;
wendl=0;
nsp=0;
ActualPos = ftell(wpd);
while (ActualPos < fsize)
{
if(Verbosing >= 1) //actualise a procentage counter
perc.Actualise(ActualPos);
by = 0;
ProcessKey602();
}
Finalise_Conversion(this);
return(1);
}
/*------------------------------------------------------------------------*/
|