Files
harbour-core/harbour/samples/cccppc/cccpp_pr.prg
1999-11-09 01:37:27 +00:00

134 lines
4.2 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* $Id$
*/
//*******************************************************************
// cccpp_pr.prg: Process input
// 1999, Csisz r Levente
//*******************************************************************
//*******************************************************************
#include "debug.ch"
#include "ctoken.ch"
//*******************************************************************
#include "objgen.ch"
//*******************************************************************
#include "lreader.och"
#include "nparser.och"
#include "lparser.och"
#include "incl.och"
#include "hparser.och"
#include "mcontrol.och"
#include "parser.och"
#include "token.och"
//*******************************************************************
static function cccpp_printErrorStream(errorStream)
if (!empty(errorStream))
evalErrorStream(errorStream,{|x| outerr(x,newline())})
asize(errorStream,0)
return .t.
endif
return .f.
//*******************************************************************
function cccpp_processReader(reader,outFid,;
incArray,maxInclDeep,;
defDict,xtrdict,errorStream,;
trPrsAlg)
// Feldolgoz egy filt, Egyenl“re nem vgez hiba ellez“rzst.
local lrd,npr,lpr,hpr,mcr,t,inclObj
local line,emptyLines,hiba
hiba:=.f.
if (cccpp_printErrorStream(errorStream))
hiba:=.t.
return hiba
endif
// fr:=C.FREADER:onew(errorStream)
// FREADER.fr:open("",inputFileName)
lrd:=C.LREADER:onew(CTK_BOS,CTK_EOS,READER.reader:name,errorStream)
LREADER.lrd:pushReader(reader)
npr:=C.NPARSER:onew(lrd,READER.lrd:name,errorStream)
lpr:=C.LPARSER:onew(npr,READER.npr:name,errorStream)
inclObj:=C.INCL:onew(lrd,incArray,maxInclDeep)
// inclObj:=C.INCL:onew(lrd,{dirFName(filename)})
hpr:=C.HPARSER:onew(lpr,READER.lpr:name,;
defDict/*C.DEFDICT:onew()*/,xtrDict/*C.XTRDICT:onew()*/,;
inclObj,errorStream)
mcr:=C.MCONTROL:onew(hpr,READER.hpr:name,;
HPARSER.hpr:defDict,HPARSER.hpr:xtrdict,;
errorStream,trPrsAlg)
line:=""
emptyLines:=""
while(nil!=(t:=PARSER.mcr:read()))
// outstd(TOKEN.t:getStr())
// wStr:=TOKEN.t:getStr()
// fwrite(fid,wStr,len(wStr))
if (outFid!=nil)
// Itt kell kozmetik zni a sorokat.
/*
1. šres sorok hossz t null ra reduk ljuk.
2. #line el“tti <20>res sorokat t”r”lj<6C>k. (BOS)
3. EOS el“tti <20>res sorokat t”r”lj<6C>k.
*/
if (TOKEN.t:id==TKID_UJSOR)
// —j sor. Az <20>res sorokat az emptyLines-ban t roljuk.
if (!empty(line))
fwrite(outFid,emptyLines)
emptyLines:=""
fwrite(outFid,line)
line:=""
fwrite(outFid,TOKEN.t:getStr())
else
emptyLines+=TOKEN.t:getStr()
line:=""
endif
elseif (TOKEN.t:id==TKID_EOS .or.;
TOKEN.t:id==TKID_BOS)
// Az EOS s a BOS el“tti <20>res sorokat t”r”lni kell.
// Mj.: Itt nincs kezelve az az esetet, amikor nincs
// sorvgjel az include fil vgn.
if (!empty(line))
fwrite(outFid,emptyLines)
emptyLines:=""
fwrite(outFid,line)
line:=""
fwrite(outFid,TOKEN.t:getStr())
else
emptyLines:=""
line:=""
// Ha az EOS/BOS ¡rni akar valamit, azt kitessz<73>k.
fwrite(outFid,TOKEN.t:getStr())
endif
else
line+=TOKEN.t:getStr()
endif
endif
// Itt ki kell olvasni a hib kat.
if (cccpp_printErrorStream(errorStream))
hiba:=.t.
endif
end while
// Nem kell az utols¢ sorra figyelni, mert mindig j”n egy EOS.
// Elvgezz<7A>k a sz<73>ksges ellen“rzseket a fil vgn.
// (Lez ratlan #if, etc)
HPARSER.hpr:chkEndOfFile()
if (cccpp_printErrorStream(errorStream))
hiba:=.t.
endif
return hiba
//*******************************************************************