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

137 lines
3.7 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$
*/
//*******************************************************************
// prserr.prg: A PRSERR oszt ly implement ci¢ja.
// 1999, Csisz r Levente
//*******************************************************************
#include "objgen.ch"
//*******************************************************************
#include "token.och"
//*******************************************************************
#define _PRSERR_PRG_
#define _IMPLEMENT_ONEW_
#include "prserr.och"
//*******************************************************************
implement oinit(group_and_id,params,file,line,pos)
super:oinit()
this:group :=group_and_id[1]
this:id :=group_and_id[2]
this:params:=params
this:file :=file
this:line :=line
this:pos :=pos
return this
//*******************************************************************
implement defaultErrFormat(name)
// Egyenl“re a a $0,$1,...,$9-et cserli ki.
// $0 az ”sszes paramtert jel”li, vessz“vel elv lasztva.
// Sajnos az strtran itt nem j¢, mert az az eredmnyben is cserlne.
local str,i,c,allParam,wStr
if ("$0"$name)
allParam:=""
if (!empty(this:params))
for i:=1 to len(this:params)
if (i>1)
allParam+=","
endif
allParam+=toStr(this:params[i])
end for
endif
endif
str:=""
while(0!=(i:=at("$",name)))
str+=substr(name,1,i-1)
c:=substr(name,i+1,1)
if (!empty(c) .and. c$"0123456789")
if (val(c)==0)
str+=allParam
elseif (val(c)<=len(this:params))
str+=toStr(this:params[val(c)])
else
str+=substr(name,i,2)
endif
name:=substr(name,i+2)
else
str+=substr(name,i,1)
name:=substr(name,i+1)
endif
end for
str+=name
wStr:=this:file+"("+toStr(this:line)+")"
if (len(wStr)<20)
wStr:=padr(wStr,20)
endif
return wStr+" Error: "+str
// return padr(this:file+"("+toStr(this:line)+")",20)+" Error: "+name
//*******************************************************************
implement getErrStr()
local i, wIdt
if (0!=(i:=ascan(thisclass:errDict,{|x| x[1]==this:group})))
wIdt:=thisclass:errDict[i][2]
if (0!=(i:=ascan(wIdt,{|x| x[1]==this:id})))
if (wIdt[i][3]==nil)
return this:defaultErrFormat(wIdt[i][2])
endif
return eval(wIdt[i][3],this,wIdt[i][2])
endif
endif
return this:defaultErrFormat("Unknown error $0")
//*******************************************************************
cimplement oinitclass()
superclass:oinitclass()
class:errDict:={}
return nil
//*******************************************************************
cimplement onewFromToken(group_and_id,params,token)
return class:onew(group_and_id,params,;
TOKEN.token:file,;
TOKEN.token:line,;
TOKEN.token:pos)
//*******************************************************************
cimplement registerError(group_and_id,name,printBlock)
local i, wIdt
if (0==(i:=ascan(class:errDict,{|x| x[1]==group_and_id[1]})))
aadd(class:errDict,{group_and_id[1],{}})
i:=len(class:errDict)
endif
wIdt:=class:errDict[i][2]
if (0==(i:=ascan(wIdt,{|x| x[1]==group_and_id[2]})))
aadd(wIdt,{group_and_id[2],name,printBlock})
return group_and_id
endif
return nil
//*******************************************************************
function evalErrorStream(errorStream,bBlock,nStart,nCount)
if (!empty(errorStream))
return aeval(errorStream,;
{|x| eval(bBlock,PRSERR.x:getErrStr())},;
nStart,nCount)
endif
return nil
//*******************************************************************