Melhorar a rotina
Enviado: 17 Fev 2016 15:19
Estou querendo melhorar esta rotina.
O que ela faz, um texto do tipo
LIST "FOR CODIGO=5 WHILE RecNo() < 100 NEXT 10"
A rotina serve pra separar os blocos FOR, WHILE, NEXT, RECORD, e ALL, se existirem, e em qualquer ordem.
Está funcionando, mas queria dar uma melhorada.
Por enquanto a idéia é deixar parecida, mas fazer tudo de uma vez, sem precisar de várias passagens.
Tem alguma coisa no Harbour que ajude nisso?
O que ela faz, um texto do tipo
LIST "FOR CODIGO=5 WHILE RecNo() < 100 NEXT 10"
A rotina serve pra separar os blocos FOR, WHILE, NEXT, RECORD, e ALL, se existirem, e em qualquer ordem.
Está funcionando, mas queria dar uma melhorada.
Por enquanto a idéia é deixar parecida, mas fazer tudo de uma vez, sem precisar de várias passagens.
Tem alguma coisa no Harbour que ajude nisso?
Código: Selecionar todos
CASE mTipo == "escopo"
DBASE_FOR := ".T."
DBASE_WHILE := ".T."
DBASE_NEXT := 0
DBASE_RECORD := 0
DBASE_ALL := .F.
FOR mCont = 1 TO 5
DO CASE
CASE mCont = 1 ; mTipo := "all"
CASE mCont = 2 ; mTipo := "next"
CASE mCont = 3 ; mTipo := "record"
CASE mCont = 4 ; mTipo := "for"
CASE mCont = 5 ; mTipo := "while"
ENDCASE
cTextCmd := " " + cTextCmd + " "
m_Posi := Array(6)
mContfor := At( " for ", Lower( cTextCmd ) )
mContwhil := At( " while ", Lower( cTextCmd ) )
IF mContwhil == 0
mContwhil := At( " whil ", Lower( cTextCmd ) )
ENDIF
mContall := At( " all ", Lower( cTextCmd ) )
mContnext := At( " next ", Lower( cTextCmd ) )
mContReco := At( " record ", Lower( cTextCmd ) )
IF mContReco == 0
mContReco := At( " recor ", Lower( cTextCmd ) )
IF mContReco == 0
mContReco := At( " reco ", Lower( cTextCmd ) )
ENDIF
ENDIF
m_Posi[ 1 ] := mContall
m_Posi[ 2 ] := mContnext
m_Posi[ 3 ] := mContReco
m_Posi[ 4 ] := mContfor
m_Posi[ 5 ] := mContwhil
m_Posi[ 6 ] := Len( cTextCmd )
aSort( m_Posi )
// retira parametro all
DO CASE
CASE mTipo == "all" .AND. mContall != 0
DBASE_ALL := .T.
//m_Inicio := aScan( m_Posi, mContall )
//m_Final := m_Posi[ m_Inicio + 1 ]
cTextCmd := Stuff( cTextCmd, mContall, 4, "" )
// retira e valida parametro next
CASE mTipo == "next" .AND. mContnext != 0
m_Inicio := aScan( m_Posi, mContnext )
m_Final := m_Posi[ m_Inicio + 1 ]
DBASE_NEXT := Substr( cTextCmd, mContnext + 1, m_Final - mContnext )
cTextCmd := Stuff( cTextCmd, mContnext, m_Final - mContnext, "" )
DBASE_NEXT := Substr( DBASE_NEXT, At( " ", DBASE_NEXT ) )
DBASE_ALL := .F.
IF MacroType( DBASE_NEXT ) != "N"
SayScroll( "Invalid NEXT" )
RETURN .F.
ENDIF
IF &( DBASE_NEXT ) < 0
SayScroll( "Invalid NEXT" )
RETURN .F.
ENDIF
DBASE_NEXT = &( DBASE_NEXT )
// retira e valida parametro record
CASE mTipo=="record" .AND. mContReco != 0
m_Inicio := aScan( m_Posi, mContReco )
m_Final := m_Posi[ m_Inicio + 1 ]
DBASE_RECORD := Substr( cTextCmd, mContReco + 1, m_Final - mContReco )
cTextCmd := Stuff( cTextCmd, mContReco, m_Final - mContReco, "" )
DBASE_RECORD := Substr( DBASE_RECORD, At( " ", DBASE_RECORD ) )
IF MacroType( DBASE_RECORD ) != "N"
SayScroll( "Invalid RECORD" )
RETURN .F.
ENDIF
DBASE_RECORD := &( DBASE_RECORD )
IF DBASE_RECORD < 1 .OR. DBASE_RECORD > LastRec()
SayScroll( "Record not exist" )
RETURN .F.
ENDIF
// retira e valida parametro for
CASE mTipo=="for" .AND. mContfor != 0
m_Inicio := aScan( m_Posi, mContfor )
m_Final := m_Posi[ m_Inicio + 1 ]
DBASE_FOR := Substr( cTextCmd, mContfor + 1, m_Final - mContfor )
cTextCmd := Stuff( cTextCmd, mContfor, m_Final - mContfor, "" )
DBASE_FOR := Substr( DBASE_FOR, At( " ", DBASE_FOR ) )
DBASE_ALL := .T.
IF MacroType( DBASE_FOR ) != "L"
SayScroll( "Invalid FOR" )
RETURN .F.
ENDIF
// retira e valida parametro while
CASE mTipo=="while" .AND. mContwhil != 0
m_Inicio := aScan( m_Posi, mContwhil )
m_Final := m_Posi[ m_Inicio + 1 ]
DBASE_WHILE := Substr( cTextCmd, mContwhil + 1, m_Final - mContwhil )
cTextCmd := Stuff( cTextCmd, mContwhil, m_Final - mContwhil, "" )
DBASE_WHILE := Substr( DBASE_WHILE, At( " ", DBASE_WHILE ) )
DBASE_ALL := .F.
IF MacroType( DBASE_WHILE ) != "L"
SayScroll( "Invalid WHILE" )
RETURN .F.
ENDIF
ENDCASE
cTextCmd := Alltrim( cTextCmd )
NEXT
mParametro := .T.