/* PUTILDBASE - Imitação do dBase 1999 - José Quintas */ #include "inkey.ch" #include "directry.ch" #include "set.ch" #include "dbstruct.ch" MEMVAR DBASE_EXCLUSIVE, DBASE_ODOMETER MEMVAR DBASE_ALL, DBASE_NEXT, DBASE_FOR, DBASE_WHILE, DBASE_RECORD MEMVAR cEmptyValue MEMVAR m_Name, m_Opc, m_Row, m_Item, m_IniVet, acStructure MEMVAR m_Expr, m_Campo, lChanged, m_Posi MEMVAR m_NomVar, m_Conte, cFileName, Ret_Val, Mode MEMVAR Line, Col, m_Col, Opc, IniVet, Modo PROCEDURE pUtilDbase LOCAL nCont, GetList := {}, nKey, acCmdList := {}, nCmdPos := 0, cTextCmd, mCmd PRIVATE DBASE_EXCLUSIVE, DBASE_ODOMETER PRIVATE DBASE_ALL, DBASE_NEXT, DBASE_FOR, DBASE_WHILE, DBASE_RECORD DBASE_EXCLUSIVE := .F. DBASE_ODOMETER := 100 CLOSE DATABASES // pode ter algum aberto MsgWarning( "Atention! If you don't know Foxpro command, don't use it!" + hb_eol() + ; "Depending on changes, use REINDEX option." + hb_eol() + ; "type QUIT when work finished" ) FOR nCont = 1 TO MaxRow() SayScroll() NEXT Mensagem( "Type command and ENTER, or QUIT to exit" ) cTextCmd := "" DO WHILE .T. cTextCmd := Pad( cTextCmd, 1000 ) @ MaxRow() - 3, 0 GET cTextCmd PICTURE "@S" + Ltrim( Str( MaxCol() - 1 ) ) READ nKey := LastKey() DO CASE CASE LastKey() == K_ESC LOOP CASE nKey = K_UP IF Len( acCmdList ) >= 1 .AND. nCmdPos >= 1 cTextCmd := acCmdList[ nCmdPos ] nCmdPos := iif( nCmdPos <= 1, 1, nCmdPos - 1 ) ENDIF LOOP CASE nKey = K_DOWN IF nCmdPos < Len( acCmdList ) nCmdPos += 1 cTextCmd := acCmdList[ nCmdPos ] ENDIF LOOP CASE Empty( cTextCmd ) LOOP ENDCASE SayScroll() cTextCmd := Trim( cTextCmd ) Aadd( acCmdList, AllTrim( cTextCmd ) ) nCmdPos := Len( acCmdList ) GravaOcorrencia( ,, "(*)" + cTextCmd ) mCmd := Lower( Trim( Left( ExtractParameter( @cTextCmd, " " ), 4 ) ) ) DO CASE CASE mCmd == "!" ; cmdRun( cTextCmd ) CASE mCmd == "?" ; cmdPrint( cTextCmd ) CASE mCmd == "appe" ; cmdAppend( cTextCmd ) CASE mCmd == "brow" ; cmdBrowse() CASE mCmd == "cls" ; Scroll( 2, 0, MaxRow() - 3, MaxCol(), 0 ) CASE mCmd == "clea" ; Scroll( 2, 0, MaxRow() - 3, MaxCol(), 0 ) CASE mCmd == "clos" ; CLOSE DATABASES CASE mCmd == "cont" ; cmdContinue() CASE mCmd == "copy" ; cmdCopy( cTextCmd ) CASE mCmd == "crea" ; cmdCreate( cTextCmd ) CASE mCmd == "dele" ; cmdDelete( cTextCmd ) CASE mCmd == "dir" ; cmdDir( cTextCmd ) CASE mCmd == "disp" ; cmdList( cTextCmd ) CASE mCmd == "edit" ; cmdEdit( cTextCmd ) CASE mCmd == "ejec" ; EJECT CASE mCmd == "go" ; cmdGoTo( cTextCmd ) CASE mCmd == "goto" ; cmdGoto( cTextCmd ) CASE Type( mCmd ) == "N" .AND. ! " " $ cTextCmd ; cmdGoTo( cTextCmd ) CASE mCmd == "inde" ; cmdIndex( cTextCmd ) CASE mCmd == "list" ; cmdList( cTextCmd ) CASE mCmd == "loca" ; cmdLocate( cTextCmd ) CASE mCmd == "modi" ; cmdModify( cTextCmd ) CASE mCmd == "pack" ; cmdPack() CASE mCmd == "quit" ; EXIT CASE mCmd == "reca" ; cmdRecall( cTextCmd ) CASE mCmd == "rein" ; cmdReindex() CASE mCmd == "repl" ; cmdReplace( cTextCmd ) CASE mCmd == "run" ; cmdRun( cTextCmd ) CASE mCmd == "seek" ; cmdSeek( cTextCmd ) CASE mCmd == "sele" ; cmdSelect( cTextCmd ) CASE mCmd == "set" ; cmdSet( cTextCmd ) CASE mCmd == "skip" ; cmdSkip( cTextCmd ) CASE mCmd == "stor" ; cmdStore( cTextCmd ) CASE mCmd == "sum" ; cmdSum( cTextCmd ) CASE mCmd == "tota" ; cmdTotal( cTextCmd ) CASE mCmd == "unlo" ; cmdUnLock( cTextCmd ) CASE mCmd == "use" ; cmdUse( cTextCmd ) CASE mCmd == "zap" ; cmdZap() CASE Left( cTextCmd, 1 ) == "=" cTextCmd := Substr( cTextCmd, 2 ) + " to " + mCmd cmdStore( cTextCmd ) OTHERWISE SayScroll( "Invalid command" ) ENDCASE SayScroll() cTextCmd := "" ENDDO CLOSE DATABASES SET UNIQUE OFF SET EXCLUSIVE OFF SET DELETED ON SET CONFIRM ON MsgWarning( "Remember your changes, can be needed REINDEX option" ) RETURN STATIC FUNCTION ExtractParameter( cTextCmd, mTipo, mLista ) LOCAL mCont, mParametro, m_Procu, mContIni, mTemp, mContFim cTextCmd := AllTrim( cTextCmd ) DO CASE CASE mTipo == " " .OR. mTipo == "," mParametro := Substr( cTextCmd, 1, At( mTipo, cTextCmd + mTipo ) - 1 ) cTextCmd := Substr( cTextCmd, At( mTipo, cTextCmd + mTipo ) + 1 ) mParametro := AllTrim( mParametro ) cTextCmd := AllTrim( cTextCmd ) RETURN mParametro CASE mTipo == "alias" cTextCmd := " " + cTextCmd + " " mContini := At( " alias ", cTextCmd ) IF mContini == 0 RETURN "" ENDIF mContfim := mContini + 7 DO WHILE Substr( cTextCmd, mContfim, 1 ) == " " .AND. mContfim < len( cTextCmd ) mContFim := mContfim + 1 ENDDO mParametro := AllTrim( ExtractParameter( Substr( cTextCmd, mContfim ), " " ) ) cTextCmd := Substr( cTextCmd, 1, mContini ) + Substr( cTextCmd, mContfim + Len( mParametro ) + 1 ) cTextCmd := AllTrim( cTextCmd ) RETURN mParametro CASE mTipo == "par," mParametro := 0 mLista := {} DO WHILE Len( cTextCmd ) > 0 DO WHILE Len( cTextCmd ) > 0 mContini := At( ",", cTextCmd + "," ) mTemp := Substr( cTextCmd, 1, mContini - 1 ) cTextCmd := Substr( cTextCmd, mContini + 1 ) IF Type( mTemp ) $ "NCDLM" EXIT ENDIF ENDDO mParametro += 1 Aadd( mLista, mTemp ) ENDDO RETURN mParametro CASE mTipo == "to" cTextCmd := " " + cTextCmd + " " mParametro := "" IF " to " $ Lower( cTextCmd ) mParametro := AllTrim( Lower( substr( cTextCmd, At( " to ", Lower( cTextCmd ) ) + 4 ) ) ) IF mParametro == "prin" mParametro := "print" ENDIF cTextCmd = AllTrim( substr( cTextCmd, 1, at( " to ", Lower( cTextCmd ) ) - 1 ) ) ENDIF CASE mTipo == "structure" .OR. mTipo == "status" .OR. mTipo == "Exclusive" .OR. mTipo == "index" .OR. mTipo == "sdf" .OR. mTipo == "extended" cTextCmd := " " + cTextCmd + " " mParametro := .F. FOR mCont = 4 TO 9 m_procu := " " + substr( mTipo, 1, mCont ) + " " IF m_procu $ Lower( cTextCmd ) mParametro = .T. cTextCmd = Stuff( cTextCmd, at( m_procu, Lower( cTextCmd ) ), Len( m_procu ) - 1, "" ) ENDIF NEXT cTextCmd := Alltrim( cTextCmd ) OTHERWISE CLS SayScroll( "Syntax error" ) QUIT ENDCASE cTextCmd := AllTrim( cTextCmd ) RETURN mParametro STATIC FUNCTION cmdDelete( cTextCmd ) LOCAL m_ContDel, m_ContReg, nKey IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF ! ExtractForWhile( @cTextCmd ) RETURN Nil ENDIF IF Len( cTextCmd ) != 0 SayScroll( "Invalid " + cTextCmd ) RETURN Nil ENDIF DO CASE CASE DBASE_ALL GOTO TOP CASE DBASE_RECORD != 0 GOTO DBASE_RECORD ENDCASE m_Contreg := 0 m_Contdel := 0 nKey := 0 SayScroll() DO WHILE nKey != K_ESC .AND. ! Eof() nKey = Inkey() IF ! &( DBASE_WHILE ) EXIT ENDIF m_Contreg := m_Contreg + 1 IF &( DBASE_FOR ) RecDelete() // current m_Contdel := m_Contdel + 1 IF Mod( m_Contdel, DBASE_ODOMETER ) == 0 @ MaxRow() - 3, 0 SAY Str( m_Contdel ) + " record(s) deleted" ENDIF ENDIF IF DBASE_RECORD != 0 EXIT ENDIF SKIP IF m_Contreg == DBASE_NEXT EXIT ENDIF ENDDO @ MaxRow() - 3, 0 SAY Str( m_Contdel ) + " record(s) deleted" IF LastKey() = K_ESC SayScroll( "Interrupted" ) ENDIF RETURN Nil STATIC FUNCTION cmdEdit( cTextCmd ) LOCAL nCont, GetList := {}, m_Tela, lInsert, odbStruct, m_Ini, m_Fim, m_Grava, m_QtTela, mPageRec, oElement IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF Len( cTextCmd ) != 0 IF Type( cTextCmd ) != "N" SayScroll( "Need to be a number" ) RETURN Nil ENDIF IF &( cTextCmd ) < 1 .OR. &( cTextCmd ) > LastRec() SayScroll( "Invalid record number" ) RETURN Nil ENDIF GOTO &( cTextCmd ) ENDIF // edita registro lInsert := Eof() mPageRec := MaxRow()-6 odbStruct := dbStruct() m_QtTela := Int( ( Len( odbStruct ) + mPageRec - 1 ) / mPageRec) FOR nCont = 1 TO Len( odbStruct ) Aadd( odbStruct[ nCont ], "" ) // picture Aadd( odbStruct[ nCont ], FieldGet( nCont ) ) // value NEXT DO WHILE .T. IF ! lInsert IF ! rLock() SayScroll( "Can't lock record" ) RETURN Nil ENDIF ENDIF FOR EACH oElement IN odbStruct oElement[ 6 ] := FieldGet( oElement:__EnumIndex ) IF ValType( oElement[ 6 ] ) == "C" oElement[ 5 ] := iif( Len( oElement[ 6 ] ) > ( MaxCol() - 25 ), "@S" + Ltrim( Str( MaxCol() - 25 ) ), "@X" ) ENDIF NEXT m_grava = .F. m_tela = 1 DO WHILE .T. Cls() m_ini := m_tela * mPageRec - mPageRec + 1 m_fim := iif( m_tela = m_qttela, Len( odbStruct ), m_ini + mPageRec - 1 ) @ 2, 1 SAY iif( lInsert .OR. Eof(), "INSERT", "EDIT " ) + " - Registro.: " + STR( RecNo() ) + " " + iif( Deleted(), "(DELETED)", "" ) FOR nCont = m_ini TO m_fim @ nCont + 3 - m_ini, 1 SAY Pad( odbstruct[ nCont, 1 ], 18, "." ) + ": " GET odbStruct[ nCont, 6 ] PICTURE ( odbStruct[ nCont, 5 ] ) NEXT READ m_grava = iif( updated(), .T., m_grava ) DO CASE CASE LastKey() == K_ESC EXIT CASE LastKey() == K_CTRL_L // .OR. ( LastKey() == K_UP .AND. Pad( ReadVar(), 10 ) == Pad( GetList[ 1, 2 ], 10 ) ) m_tela := m_tela - 1 CASE LastKey() = K_CTRL_W m_grava := .T. EXIT OTHERWISE m_tela := m_tela + 1 ENDCASE IF m_tela < 1 .OR. m_tela > m_qttela EXIT ENDIF ENDDO IF LastKey() != K_ESC .AND. m_grava IF lInsert .OR. Eof() APPEND BLANK DO WHILE NetErr() Inkey(.2) APPEND BLANK ENDDO ENDIF FOR EACH oElement IN odbStruct FieldPut( oElement:__EnumIndex, oElement[ 6 ] ) NEXT ENDIF DO CASE CASE LastKey() = K_ESC .OR. LastKey() = K_CTRL_W EXIT CASE LastKey() == K_CTRL_R IF ! Bof() SKIP -1 ENDIF IF Bof() EXIT ENDIF lInsert := ! Eof() OTHERWISE IF ! Eof() SKIP ENDIF lInsert := lInsert .OR. Eof() ENDCASE ENDDO RETURN Nil STATIC FUNCTION cmdList( cTextCmd ) LOCAL m_Status, m_Struct, nCont IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF m_Status := ExtractParameter( @cTextCmd, "status" ) m_Struct := ExtractParameter( @cTextCmd, "structure" ) nCont := 0 + iif( m_status, 1, 0 ) + iif( m_struct, 1, 0 ) + iif( Len( cTextCmd ) == 0, 0, 1 ) IF nCont > 1 SayScroll( "Invalid parameters" ) RETURN Nil ENDIF DO CASE CASE m_status cmdListStatus() CASE m_struct cmdListStructure() OTHERWISE cmdListData( cTextCmd ) ENDCASE IF LastKey() == K_ESC SayScroll( "Interrupted" ) ENDIF RETURN Nil STATIC FUNCTION cmdListStatus() LOCAL nCont, nCont2, nSelect := Select() FOR nCont = 1 TO 255 IF Len( Trim( Alias( nCont ) ) ) != 0 SELECT ( nCont ) SayScroll() SayScroll( "Alias " + Str( nCont, 2 ) + " -> " + Alias() + iif( nCont == nSelect, " ==> Actual Alias", "" ) ) FOR nCont2 = 1 TO 100 IF Len( Trim( OrdKey(nCont2 ) ) ) == 0 EXIT ENDIF SayScroll( " Tag " + OrdName( nCont2 ) + " -> " + OrdKey( nCont2 ) ) NEXT IF Len( Trim( dbFilter() ) ) != 0 SayScroll( " Filter: " + dbFilter() ) ENDIF IF Len( Trim( dbRelation() ) ) != 0 SayScroll(" Relation: " + dbRelation() + " Alias: " + Alias( dbRSelect() ) ) ENDIF ENDIF NEXT SELECT ( nSelect ) SayScroll( "Current Path -> " + hb_cwd() ) SayScroll() RETURN Nil STATIC FUNCTION cmdListStructure() LOCAL nRow, aStructure, oElement IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF aStructure := dbStruct() SayScroll( "Filename........: " + Alias() ) SayScroll( "Qt.Records......: " + LTrim( Str( LastRec() ) ) ) SayScroll() SayScroll( " # ---Name--- Type Length Decimals" ) SayScroll() nRow := 5 FOR EACH oElement IN aStructure SayScroll( Str( oElement:__EnumIndex, 3 ) + " " + pad( oElement[ 1 ], 14 ) + Pad( oElement[ 2 ], 4 ) + " " + Str( oElement[ 3 ] ) + " " + Str( oElement[ 4 ] ) ) nRow += 1 IF nRow > ( MaxRow() - 8 ) SayScroll( "Hit any to continue" ) Inkey(0) IF LastKey() == K_ESC EXIT ENDIF nRow := 0 ENDIF NEXT IF LastKey() != K_ESC SayScroll() SayScroll( "Total Record Size.: " + Str( RecSize() ) + " bytes") SayScroll() ENDIF RETURN Nil STATIC FUNCTION cmdListData( cTextCmd ) LOCAL nKey, m_ContReg, m_Lista, cTxt, oElement, nCont IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF cTextCmd = " " + cTextCmd + " " IF ! ExtractForWhile( @cTextCmd ) RETURN Nil ENDIF // prepara lista dos dados cTextCmd = alltrim( cTextCmd ) m_Lista := {} IF len( cTextCmd ) = 0 FOR nCont = 1 TO FCount() Aadd( m_Lista, FieldName( nCont ) ) NEXT ELSE GetParamList( @cTextCmd, @m_lista ) ENDIF // lista do indicado DO CASE CASE DBASE_ALL GOTO TOP CASE DBASE_RECORD != 0 GOTO DBASE_RECORD ENDCASE m_Contreg = 0 nKey = 0 DO WHILE nKey != K_ESC .AND. ! Eof() nKey = Inkey() IF ! &( DBASE_WHILE ) EXIT ENDIF m_Contreg = m_Contreg + 1 cTxt := "" IF &( DBASE_FOR ) cTxt := cTxt + Str( RecNo(), 6 ) + " " + iif( Deleted(), "del", " " ) + " " FOR EACH oElement IN m_Lista IF MacroType( oElement ) $ "CLDN" cTxt += Transform( &oElement, "" ) ENDIF IF oElement:__EnumIndex != Len( m_lista ) cTxt += " " ENDIF NEXT cTxt := Trim( cTxt ) DO WHILE Len( cTxt ) != 0 SayScroll( Left( cTxt, MaxCol() + 1 ) ) cTxt := Substr( cTxt, MaxCol() + 2 ) ENDDO ENDIF IF DBASE_RECORD != 0 EXIT ENDIF SKIP IF m_Contreg = DBASE_NEXT EXIT ENDIF ENDDO RETURN Nil STATIC FUNCTION cmdModify( cTextCmd ) LOCAL m_Tipo m_Tipo = Lower( ExtractParameter( @cTextCmd, " " ) ) DO CASE CASE Empty( m_Tipo ) SayScroll( "Need more parameters" ) CASE Len( m_Tipo ) < 4 SayScroll( "Invalid parameter" ) CASE Lower( m_Tipo ) == substr( "structure", 1, len( m_Tipo ) ) cmdModifyStructure( cTextCmd ) CASE Lower( m_Tipo ) == substr( "command", 1, len( m_Tipo ) ) cmdModifyCommand( cTextCmd ) OTHERWISE SayScroll( "Invalid parameter" ) ENDCASE RETURN Nil STATIC FUNCTION cmdModifyCommand( cFileName ) IF len( trim( cFileName) ) = 0 SayScroll( "Need filename" ) RETURN Nil ENDIF IF ! "." $ cFileName cFileName = cFileName + ".pro" ENDIF wSave() cmdEditAFile( cFileName ) wRestore() SayScroll() RETURN Nil STATIC FUNCTION cmdEditAFile( cFileName ) LOCAL cTexto PRIVATE lChanged := .F., Ret_Val := 0 IF Type( "cFileName" ) != "C" cFileName = "none" ENDIF cTexto := MemoRead( cFileName ) CLS @ 1, 0 TO MaxRow() - 1, MaxCol() @ MaxRow(), 0 SAY Pad( Lower( cFileName ), 54 ) cTexto = MemoEdit( cTexto, 2, 1, MaxRow() - 2, MaxCol() - 1, .T., { | ... | FuncMemoEdit( ... ) }, 132, 3 ) IF ! cFileName == "none" .AND. ! Empty( cTexto ) .AND. ret_val == 23 lChanged = .F. RunCmd( "copy " + cFileName + " *.bak" ) HB_MemoWrit( cFileName, cTexto ) ENDIF RETURN Nil * mfunc() * memoedit user function STATIC FUNCTION FuncMemoEdit( Mode, Line, Col ) LOCAL KeyPress, Ret_Val // , Rel_Row, Rel_Col, Line_Num, Col_Num ret_val = 0 DO CASE CASE mode = 3 CASE mode = 0 * idle @ MaxRow(), MaxCol() - 20 SAY "line: " + Pad( Ltrim( Str( Line ) ), 4 ) @ MaxRow(), MaxCol() - 8 SAY "col: " + Pad( Ltrim( Str( Col ) ), 3 ) OTHERWISE * keystroke exception keypress := LastKey() * save values to possibly resume edit //line_num := line //col_num := col //rel_row := row() - 2 //rel_col := col() - 1 IF mode == 2 lChanged = .T. ENDIF DO CASE CASE keypress = K_CTRL_W * ctr-w..write file ret_val = 23 CASE keypress = K_ESC * esc..Exit IF ! lChanged * no change ret_val = K_ESC ELSE * changes have been made to memo IF MsgYesNo( "Abort?" ) ret_val = K_ESC ELSE ret_val = 32 ENDIF ENDIF ENDCASE ENDCASE RETURN ret_val STATIC FUNCTION cmdCreate( cTextCmd ) LOCAL m_From IF Empty( cTextCmd ) SayScroll( "Invalid parameters" ) RETURN Nil ENDIF IF " from " $ Lower( " " + cTextCmd + " " ) m_Posi = at( " from ", Lower( " " + cTextCmd + " " ) ) m_from = substr( cTextCmd, m_Posi + 5 ) cTextCmd = substr( cTextCmd, 1, m_Posi - 1 ) IF cTextCmd == "" SayScroll( "Need filename" ) RETURN Nil ENDIF IF ! "." $ m_from m_from = m_from + ".dbf" ENDIF IF ! File( m_from ) SayScroll( "Source filename not found" ) RETURN Nil ENDIF IF ! "." $ cTextCmd cTextCmd = cTextCmd + ".dbf" ENDIF IF File( cTextCmd ) IF ! MsgYesNo( "File exists, overwrite?" ) RETURN Nil ENDIF ENDIF CREATE ( cTextCmd ) FROM ( m_from ) RETURN Nil ENDIF IF ! "." $ cTextCmd cTextCmd = cTextCmd + ".dbf" ENDIF IF File( cTextCmd + ".dbf" ) IF ! MsgYesNo( "File exist, overwrite?" ) RETURN Nil ENDIF ENDIF cmdModifyStructure( cTextCmd ) RETURN Nil STATIC FUNCTION cmdSum( cTextCmd ) LOCAL m_ContSum, m_ContReg, nKey, m_Lista, m_Soma, oElement IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF // valida parametros //m_to = ExtractParameter( @cTextCmd, "to" ) IF ! ExtractForWhile( @cTextCmd ) RETURN Nil ENDIF m_Lista := {} GetParamList( @cTextCmd, @m_lista ) //ExtractParameter( @m_to, "par,", @m_vari ) m_Soma := Array( Len( m_Lista ) ) Afill( m_Soma, 0 ) IF Len( m_Lista ) == 0 .OR. len( cTextCmd ) != 0 // if anything more SayScroll( "Invalid parameters" ) RETURN Nil ENDIF FOR EACH oElement IN m_Lista IF Type( oElement ) != "N" SayScroll( "Field not numeric" ) RETURN Nil ENDIF NEXT // executa comando DO CASE CASE DBASE_ALL GOTO TOP CASE DBASE_RECORD != 0 GOTO DBASE_RECORD ENDCASE m_Contreg = 0 m_Contsum = 0 nKey = 0 SayScroll() DO WHILE nKey != K_ESC .AND. ! Eof() nKey = Inkey() IF ! &( DBASE_WHILE ) EXIT ENDIF m_Contreg = m_Contreg + 1 IF &( DBASE_FOR ) FOR EACH oElement IN m_Lista m_soma[ oElement:__EnumIndex ] += &( oElement ) NEXT m_Contsum += 1 IF Mod( m_Contsum, DBASE_ODOMETER ) = 0 @ MaxRow() - 3, 0 SAY Str( m_Contsum ) + " record(s) in sum" ENDIF ENDIF IF DBASE_RECORD != 0 EXIT ENDIF SKIP IF m_Contreg = DBASE_NEXT EXIT ENDIF ENDDO @ MaxRow() - 3, 0 SAY Str( m_Contsum ) + " record(s) in sum" cTextCmd := "" FOR EACH oElement IN m_Lista cTextCmd += Str( m_soma[ oElement:__EnumIndex ] ) + " " NEXT SayScroll( cTextCmd ) IF LastKey() == K_ESC SayScroll( "Interrupted" ) ENDIF RETURN Nil STATIC FUNCTION cmdSetRelation( cComando ) LOCAL cRelationInto LOCAL lAdditive := .F., cTrecho, nSelect, oElement LOCAL cOrdKeyFromType, cOrdKeyToType LOCAL acRelationTo := {}, acRelationInto := {} IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF cTrecho := ExtractParameter( cComando, " " ) IF Lower( cTrecho ) == substr( "additive", 1, Max( Len( cTrecho ), 4 ) ) lAdditive = .T. ExtractParameter( @cComando, " " ) // elimina proximo parametro ENDIF IF ! lAdditive SET RELATION TO ENDIF IF Empty( cComando ) RETURN Nil ENDIF IF ! " into " $ Lower( cComando ) SayScroll( "Invalid parameters" ) RETURN Nil ENDIF // retira parametros to, into DO WHILE Len( cComando ) != 0 .AND. Len( acRelationTo ) < 8 Aadd( acRelationTo, substr( cComando, 1, at( " into ", Lower( cComando) ) - 1 ) ) Aadd( acRelationInto, substr( cComando, at( " into ", Lower( cComando ) ) + 6 ) ) ENDDO // valida relacoes, valida alias e executa IF ! lAdditive SET RELATION TO ENDIF FOR EACH oElement IN acRelationTo cRelationInto := acRelationInto[ oElement:__EnumIndex ] IF Type( cRelationInto ) = "N" IF Alias( cRelationInto ) = 0 SayScroll( "Alias not in use " + cRelationInto ) RETURN Nil ENDIF ELSEIF Select( cRelationInto ) = 0 SayScroll( "Alias not in use " + cRelationInto ) RETURN Nil ENDIF nSelect := Select() SELECT ( Select( cRelationInto ) ) IF Empty( OrdKey() ) IF oElement != "recno()" SELECT ( nSelect ) SayScroll( "File not indexed to make relation" ) RETURN Nil ENDIF ELSE cOrdKeyFromType := Type( OrdKey( IndexOrd() ) ) SELECT ( nSelect ) cOrdKeyToType := Type( oElement ) IF cOrdKeyFromType != cOrdKeyToType SELECT ( nSelect ) SayScroll( "Key type: " + cOrdKeyToType + ", in command: " + cOrdKeyFromType ) RETURN Nil ENDIF ENDIF SELECT ( nSelect ) SET RELATION ADDITIVE TO &oElement INTO &cRelationInto NEXT RETURN Nil STATIC FUNCTION cmdStore( cTextCmd ) IF ! " to " $ Lower( cTextCmd ) SayScroll( "Need TO" ) RETURN Nil ENDIF m_nomvar := ExtractParameter( @cTextCmd, "to" ) m_Conte := cTextCmd IF ! Type( m_Conte ) $ "NCLD" SayScroll( "Invalid content" ) RETURN Nil ENDIF //declare m_lista[ 100 ] //m_qtparam = ExtractParameter( @cTextCmd, "par,", @m_lista ) //for nCont = 1 to m_qtparam // m_nomevar = m_lista[ nCont ] &m_nomvar = &m_Conte //next RETURN Nil STATIC FUNCTION cmdAppend( cTextCmd ) LOCAL mQtRec, m_Sdf PRIVATE cFileName IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF Empty( cTextCmd ) GOTO BOTTOM SKIP cmdEdit( "" ) RETURN Nil ENDIF // verifica se e' APPEND BLANK IF Lower( cTextCmd ) == "blan" .OR. Lower( cTextCmd ) == "blank" APPEND BLANK DO WHILE NetErr() Inkey(.2) APPEND BLANK ENDDO RETURN Nil ENDIF // valida APPEND FROM IF Lower( ExtractParameter( @cTextCmd, " " ) ) != "from" SayScroll( "Invalid parameter" ) RETURN Nil ENDIF // valida para append sdf m_sdf := ExtractParameter( @cTextCmd, "sdf" ) cFileName := ExtractParameter( @cTextCmd, " " ) IF ! "." $ cFileName cFileName = cFileName + iif( m_sdf, ".txt", ".dbf" ) ENDIF IF ! File( cFileName ) SayScroll( "File not found" ) RETURN Nil ENDIF IF select( cFileName ) != 0 SayScroll( "File in use" ) RETURN Nil ENDIF IF ! ExtractForWhile( @cTextCmd ) RETURN Nil ENDIF IF len( cTextCmd ) != 0 .OR. DBASE_RECORD != 0 .OR. DBASE_NEXT != 0 .OR. DBASE_WHILE != ".T." SayScroll( "Invalid parameters in APPEND" ) RETURN Nil ENDIF // executa comando mQtRec := LastRec() IF m_sdf APPEND FROM ( cFileName ) FOR &( DBASE_FOR ) WHILE ( Inkey() != K_ESC ) SDF ELSE APPEND FROM ( cFileName ) FOR &( DBASE_FOR ) WHILE ( Inkey() != K_ESC ) ENDIF SayScroll( Ltrim( Str( LastRec() - mQtRec ) ) + " Record(s) appended" ) RETURN Nil STATIC FUNCTION cmdCopy( cTextCmd ) LOCAL m_Struct, m_Extend, m_SDF, m_To IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF // valida parametros m_struct := ExtractParameter( @cTextCmd, "structure" ) m_extend := ExtractParameter( @cTextCmd, "extended" ) m_sdf := ExtractParameter( @cTextCmd, "sdf" ) m_To := ExtractParameter( @cTextCmd, "to" ) IF ! ExtractForWhile( @cTextCmd ) RETURN Nil ENDIF IF len( cTextCmd ) != 0 SayScroll( "Invalid parameter " + cTextCmd ) RETURN Nil ENDIF IF len( m_to ) = 0 SayScroll( "Need destination filename" ) RETURN Nil ENDIF IF DBASE_NEXT == 0 .AND. DBASE_RECORD == 0 DBASE_NEXT := LastRec() ENDIF IF ! "." $ m_to m_to = m_to + ".dbf" ENDIF IF File( m_to ) IF ! MsgYesNo( "Filename already exists, overwrite?") SayScroll( "Cancelled" ) RETURN Nil ENDIF ENDIF DO CASE CASE m_struct IF m_extend COPY TO ( m_to ) STRUCTURE EXTENDED ELSE COPY TO ( m_to ) STRUCTURE ENDIF CASE DBASE_RECORD != 0 IF m_Sdf COPY TO ( m_To ) SDF RECORD ( DBASE_RECORD ) ELSE COPY TO ( m_To ) RECORD ( DBASE_RECORD ) ENDIF CASE DBASE_WHILE != ".T." .OR. "while .T." $ Lower( cTextCmd ) IF m_Sdf COPY TO ( m_To ) FOR &( DBASE_FOR ) WHILE &( DBASE_WHILE ) NEXT DBASE_NEXT SDF ELSE COPY TO ( m_To ) FOR &( DBASE_FOR ) WHILE &( DBASE_WHILE ) NEXT DBASE_NEXT ENDIF CASE ! DBASE_NEXT != 0 IF m_Sdf COPY TO ( m_To ) FOR &( DBASE_FOR ) NEXT DBASE_NEXT SDF ELSE COPY TO ( m_To ) FOR &( DBASE_FOR ) NEXT DBASE_NEXT ENDIF OTHERWISE GOTO TOP IF m_sdf COPY TO ( m_to ) FOR &( DBASE_FOR ) sdf ELSE COPY TO ( m_to ) FOR &( DBASE_FOR ) ENDIF ENDCASE RETURN Nil STATIC FUNCTION cmdReplace( cTextCmd ) LOCAL nCont, m_ContRep, m_ContReg, m_Name, m_With, nKey PRIVATE m_Campo, m_Expr IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF ! ExtractForWhile( @cTextCmd ) RETURN Nil ENDIF IF Len( cTextCmd ) = 0 SayScroll( "Invalid parameters" ) RETURN Nil ENDIF m_Name := Array(100) m_With := Array(100) afill( m_name, "" ) nCont = 1 DO WHILE Len( cTextCmd ) > 0 m_expr := alltrim( substr( cTextCmd, rat( " with ", Lower( cTextCmd ) ) + 5 ) ) cTextCmd := alltrim( substr( cTextCmd, 1, rat( " with ", Lower( cTextCmd ) ) ) ) cTextCmd := "," + cTextCmd m_campo := alltrim( substr( cTextCmd, rat( ",", Lower( cTextCmd ) ) + 1 ) ) cTextCmd := alltrim( substr( cTextCmd, 2, rat( ",", Lower( cTextCmd ) ) - 2 ) ) DO CASE CASE Type( m_expr ) $ "U,UI,UE" SayScroll( "Invalid content" ) RETURN Nil CASE Type( m_campo ) $ "U,UI,UE" SayScroll( "Invalid fieldname" ) RETURN Nil CASE Type( m_campo ) != Type( m_expr ) SayScroll( "Types mismatched -> " + m_campo + " with " + m_expr) RETURN Nil ENDCASE m_name[ nCont ] = m_campo m_with[ nCont ] = m_expr nCont += 1 ENDDO // executa comando DO CASE CASE DBASE_ALL GOTO TOP CASE DBASE_RECORD != 0 GOTO DBASE_RECORD ENDCASE m_Contreg := 0 m_Contrep := 0 nKey := 0 SayScroll() DO WHILE nKey != K_ESC .AND. ! Eof() nKey = Inkey() IF ! &( DBASE_WHILE ) EXIT ENDIF m_Contreg = m_Contreg + 1 IF &( DBASE_FOR ) DO WHILE .T. IF rLock() EXIT ENDIF @ Row(), 0 SAY space(79) @ Row(), 0 SAY "Waiting lock record " + str( recno() ) ENDDO FOR nCont = 1 TO 100 IF len( m_name[ nCont ] ) = 0 EXIT ENDIF m_campo = m_name[ nCont ] m_expr = m_with[ nCont ] REPLACE &( m_campo ) WITH &( m_expr ) NEXT m_Contrep = m_Contrep + 1 IF Mod( m_Contrep, DBASE_ODOMETER ) = 0 @ Row(), 0 SAY str( m_Contrep ) + " record(s) updated" ENDIF ENDIF IF DBASE_RECORD != 0 EXIT ENDIF SKIP IF m_Contreg = DBASE_NEXT EXIT ENDIF ENDDO @ Row(), 0 SAY str( m_Contrep ) + " record(s) updated" IF LastKey() = K_ESC SayScroll( "Cancelled" ) ENDIF RETURN Nil STATIC FUNCTION cmdLocate( cTextCmd ) IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF ! ExtractForWhile( @cTextCmd ) RETURN Nil ENDIF IF len( cTextCmd ) != 0 .OR. DBASE_RECORD != 0 SayScroll( "Invalid parameter " + cTextCmd ) RETURN Nil ENDIF IF DBASE_ALL GOTO TOP ENDIF LOCATE FOR &( DBASE_FOR ) WHILE &( DBASE_WHILE ) .AND. Inkey() != K_ESC IF LastKey() = K_ESC SayScroll( "Cancelled" ) ELSE IF Eof() .OR. ! &( DBASE_WHILE ) SayScroll( "Not found" ) ENDIF ENDIF RETURN Nil STATIC FUNCTION cmdModifyStructure( cTextCmd ) LOCAL nCont, GetList := {}, m_Mudou, m_Len, m_Type, m_Dec, m_JaExiste LOCAL aStru, aStruOk, cItem PRIVATE acStructure, m_Opc, m_Name, m_Row, cEmptyValue, m_IniVet, m_Col IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF // salva configuracao atual m_row := Row() m_col := Col() wSave() Cls() // prepara tela da estrutura @ 4, 20 SAY " -------------------------------------------- " @ 5, 20 SAY "| |" @ 6, 20 SAY "|--------------------------------------------|" @ 7, 20 SAY "| Name | Type | Len | Dec |" @ 8, 20 SAY "|--------------------------------------------|" cEmptyValue = " | | | " FOR nCont = 9 TO 19 @ nCont, 20 SAY Chr(179) + cEmptyValue + Chr(179) NEXT @ 20,20 SAY "|--------------------------------------------|" @ 21,20 SAY "| < > ESC ENTER (I)nsert (D)elete (S)ave |" @ 22,20 SAY " -------------------------------------------- " IF len( cTextCmd ) = 0 cTextCmd := Alias() m_jaexiste := .T. ELSE m_jaexiste := .F. ENDIF // mostra campos na tela DECLARE acStructure[ 500 ] afill( acStructure, "" ) acStructure[ 1 ] := cEmptyValue @ 5, 20 + int( ( 38 - len( cTextCmd ) ) / 2 ) Say cTextCmd IF m_jaexiste aStru := dbStruct() IF Len( acStructure ) < Len( aStru ) aSize( acStructure, Len( aStru ) + 10 ) ENDIF FOR nCont = 1 TO Len( aStru ) acStructure[ nCont ] = " " + pad( aStru[ nCont, DBS_NAME ], 10 ) + " | " + ; Pad( aStru[ nCont, DBS_TYPE ], 9 ) + " | " + ; Str( aStru[ nCont, DBS_LEN ], 3 ) + " | " + ; Str( aStru[ nCont, DBS_DEC ], 3 ) + " " NEXT acStructure[ Len( aStru ) + 1 ] = cEmptyValue ENDIF // permite selecao e alteração m_mudou = .F. STORE 1 to m_opc, m_inivet DO WHILE .T. achoice( 9, 21, 19, 58, acStructure, .T., { | ... | FuncModiStru( ... ) }, m_opc, m_inivet ) DO CASE CASE LastKey() == K_ESC .OR. Lower( chr( LastKey() ) ) == "q" IF MsgYesNo( "Abort?" ) EXIT ENDIF CASE Lower( chr( LastKey() ) ) == "d" m_row := Row() IF acStructure[ m_opc ] # cEmptyValue adel( acStructure, m_opc ) scroll( m_row, 21, 19, 58, 1 ) @ 19, 21 Say cEmptyValue m_mudou = .T. ENDIF CASE Lower( chr( LastKey() ) ) = "s" IF acStructure[ 1 ] == cEmptyValue .OR. ! m_mudou EXIT ENDIF IF ! MsgYesNo( "Confirm?" ) LOOP ENDIF aStruOk := {} FOR EACH cItem IN acStructure IF cItem == cEmptyValue EXIT ELSE AAdd( aStruOk, { Nil, Nil, Nil, Nil } ) aTail( aStruOk )[ DBS_NAME ] := AllTrim( substr( cItem, 2, 10 ) ) aTail( aStruOk )[ DBS_TYPE ] := AllTrim( substr( cItem, 15, 9 ) ) aTail( aStruOk )[ DBS_LEN ] := val( substr( cItem, 28, 3 ) ) aTail( aStruOk )[ DBS_DEC ] := val( substr( cItem, 35, 3 ) ) ENDIF NEXT IF LastRec() > 0 IF m_jaexiste IF File( cTextCmd + ".bak" ) fErase( cTextCmd + ".bak" ) ENDIF COPY TO ( cTextCmd + ".bak" ) USE ENDIF dbCreate( AllTrim( cTextCmd ), aStruOk ) USE ( cTextCmd ) IF m_jaexiste APPEND FROM ( cTextCmd + ".bak" ) ENDIF USE ( cTextCmd ) ENDIF EXIT CASE Lower( chr( LastKey() ) ) == "i" .OR. LastKey() == K_ENTER m_row = ROW() IF Lower( chr( LastKey() ) ) == "i" .OR. ; acStructure[ m_opc ] = cEmptyValue IF m_row < 19 scroll( m_row, 21, 19, 58, -1 ) @ m_row, 21 Say cEmptyValue ENDIF ains( acStructure, m_opc ) acStructure[ m_opc ] = cEmptyValue ENDIF m_name := substr( acStructure[ m_opc ], 2, 10 ) m_type := substr( acStructure[ m_opc ], 15, 9 ) m_len := val( substr( acStructure[ m_opc ], 28, 3 ) ) m_dec := val( substr( acStructure[ m_opc ], 35, 3 ) ) m_row := row() @ m_row, 22 GET m_name PICTURE "@!" VALID StruNameOk() @ m_row, 35 GET m_type PICTURE "@A" VALID StruTypeOk( m_Type, @m_Len, @m_Dec ) @ m_row, 48 GET m_len PICTURE "999" VALID StruLenOk( m_Len, m_Type ) @ m_row, 56 GET m_dec PICTURE "99" VALID StruDecimalsOk( m_Dec, m_Type ) READ IF LastKey() # K_ESC acStructure[ m_opc ] = " " + m_name + " | " + Pad( m_Type, 9 ) + " | " + str( m_len, 3 ) + " | " + str( m_dec, 3 ) + " " m_mudou := .T. ELSE adel( acStructure, m_opc ) ENDIF ENDCASE ENDDO wRestore() RETURN Nil // funcao de movimentacao STATIC FUNCTION FuncModiStru( Modo, Opc, IniVet ) m_opc := opc m_inivet := inivet DO CASE CASE modo != 3 RETURN 2 CASE LastKey() == K_HOME KEYBOARD Chr( K_CTRL_PGUP ) RETURN 2 CASE LastKey() == K_END KEYBOARD Chr( K_CTRL_PGDN ) RETURN 2 CASE LastKey() == K_ESC .OR. LastKey() == K_ENTER RETURN 0 CASE Lower( chr( LastKey() ) ) $ "qsid" RETURN 0 ENDCASE RETURN 2 // funcao para validar nome STATIC FUNCTION StruNameOk() LOCAL cItem DO CASE CASE LastKey() == K_ESC RETURN .T. CASE Empty( m_name ) RETURN .F. ENDCASE FOR EACH cItem IN acStructure DO CASE CASE cItem = cEmptyValue EXIT CASE substr( cItem, 2, 10 ) == m_name .AND. cItem:__EnumIndex != m_opc RETURN .F. ENDCASE NEXT RETURN .T. // funcao para validar tipo STATIC FUNCTION StruTypeOk( cType, nLen, nDecimais ) LOCAL lOk := .T. cType := AllTrim( cType ) DO CASE CASE cType == "I:+" CASE cType == "C" CASE cType == "N" CASE cType == "L" nLen := 1 nDecimais := 0 CASE cType == "D" nLen := 8 nDecimais := 0 CASE cType == "M" nLen := 10 nDecimais := 0 OTHERWISE lOk := .F. ENDCASE RETURN lOk // funcao para validar tamanho STATIC FUNCTION StruLenOk( nLen, cType ) LOCAL lOk := ( nLen > 0 ) cType := AllTrim( cType ) DO CASE CASE cType == "L" lOk := ( nLen == 1 ) CASE cType == "D" lOk := ( nLen == 8 ) CASE cType == "M" lOk := ( nLen==10) ENDCASE RETURN lOk // funcao para validar decimais STATIC FUNCTION StruDecimalsOk( nDecimais, cType ) cType := AllTrim( cType ) DO CASE CASE cType $ "LDM" RETURN ( nDecimais == 0 ) CASE nDecimais < 0 RETURN .F. ENDCASE RETURN .T. STATIC FUNCTION cmdPrint( cTextCmd ) LOCAL m_Lista := {}, cTxt, oElement PRIVATE m_picture, m_picture IF Empty( cTextCmd ) SayScroll() RETURN Nil ENDIF GetParamList( @cTextCmd, @m_lista ) cTxt := "" FOR EACH oElement IN m_Lista cTxt += Transform( Macro( oElement ), "" ) + " " NEXT SayScroll( cTxt ) RETURN Nil STATIC FUNCTION cmdUse( cTextCmd ) LOCAL cDbfName, cCdxName, cAlias, lExclusive, nCont THREAD STATIC nTempAlias := 1 IF Empty( cTextCmd ) USE RETURN Nil ENDIF cDbfName = ExtractParameter( @cTextCmd, " " ) IF Len( cDbfName ) == 0 SayScroll( "Invalid filename" + cDbfName ) RETURN Nil ENDIF IF Select( cDbfName ) != 0 SayScroll( "File already open!" + cDbfName ) RETURN Nil ENDIF IF ! "." $ cDbfName cDbfName += ".dbf" ENDIF IF ! File( cDbfName ) SayScroll( "File not found " + cDbfName ) RETURN Nil ENDIF // Valida uso exclusivo lExclusive := ExtractParameter( @cTextCmd, "Exclusive" ) cAlias := ExtractParameter( @cTextCmd, "alias" ) IF ! Empty( cAlias ) IF Len( cAlias ) < 2 .OR. Len( cAlias ) > 10 .OR. Val( cAlias ) != 0 SayScroll( "Invalid ALIAS " + cAlias ) RETURN Nil ENDIF FOR nCont = 1 TO Len( cAlias ) IF ! Lower( Substr( cAlias, nCont, 1 ) ) $ "abcdefghijklmnopqrstuvwxyz_0123456789" SayScroll( "Invalid ALIAS " + cAlias ) RETURN Nil ENDIF NEXT ENDIF // Abre e confirma abertura de dbfs IF lExclusive IF Len( cAlias ) == 0 USE ( cDbfName ) ELSE USE ( cDbfName ) ALIAS ( cAlias ) EXCLUSIVE ENDIF IF NetErr() SayScroll( "Can't open exclusive" ) RETURN Nil ENDIF ELSE IF Len( cAlias ) == 0 Use ( cDbfName ) ELSE USE ( cDbfName ) ALIAS ( cAlias ) // SHARED ENDIF IF NetErr() SayScroll( "File in use" ) RETURN Nil ENDIF ENDIF nTempAlias += 1 // Valida abertura de indice IF ! ExtractParameter( @cTextCmd, "index" ) RETURN Nil ENDIF DO WHILE .T. cCdxName := ExtractParameter( @cTextCmd, "," ) IF Len( cCdxName ) = 0 EXIT ENDIF IF ! "." $ cCdxName cCdxName += ".cdx" IF ! File( cCdxName ) SayScroll( cCdxName + " not found" ) ELSE dbSetIndex( cCdxName ) ENDIF ENDIF ENDDO RETURN Nil STATIC FUNCTION cmdRecall( cTextCmd ) LOCAL nContReg := 0, nContDel := 0, nKey := 0 IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF ! ExtractForWhile( @cTextCmd ) RETURN Nil ENDIF IF Len( cTextCmd ) != 0 SayScroll( "Invalid parameter " + cTextCmd ) RETURN Nil ENDIF DO CASE CASE DBASE_ALL GOTO TOP CASE DBASE_RECORD != 0 GOTO ( DBASE_RECORD ) ENDCASE SayScroll() DO WHILE nKey != K_ESC .AND. ! Eof() nKey = Inkey() IF ! &( DBASE_WHILE ) EXIT ENDIF nContreg += 1 IF &( DBASE_FOR ) RecLock() RECALL nContDel += 1 IF Mod( nContDel, DBASE_ODOMETER ) = 0 @ MaxRow() - 3, 0 SAY Str( nContDel ) + " record(s) recalled" ENDIF ENDIF IF DBASE_RECORD != 0 EXIT ENDIF SKIP IF nContReg == DBASE_NEXT EXIT ENDIF ENDDO @ MaxRow() - 3, 0 SAY Str( nContDel ) + " record(s) recalled" IF LastKey() = K_ESC SayScroll( "Interrupted" ) ENDIF RETURN Nil STATIC FUNCTION cmdSet( cTextCmd ) LOCAL cSet, lOn cSet := Lower( Trim( ExtractParameter( @cTextCmd, " " ) ) ) DO CASE CASE Len( cSet ) < 4 SayScroll( "Min 4 letters for command" ) RETURN Nil CASE cSet $ "alternate" IF Upper( cTextCmd ) == "ON" SET ALTERNATE ON ELSEIF Upper( cTextCmd ) == "OFF" SET ALTERNATE OFF ELSE IF Lower( ExtractParameter( @cTextCmd, " " ) ) != "to" SayScroll( "Syntax error" ) RETURN Nil ENDIF SET ALTERNATE TO ( cTextCmd ) ENDIF CASE cSet $ "century,deleted,unique,confirm,exclusive" IF Upper( cTextCmd ) != "ON" .AND. Upper( cTextCmd ) != "OFF" SayScroll( "Need to be ON or OFF" ) RETURN Nil ENDIF lOn := iif( Upper( cTextCmd ) == "ON", .T., .F. ) DO CASE CASE cSet $ "century" ; __SetCentury( lOn ) CASE cSet $ "confirm" ; Set( _SET_CONFIRM, lOn ) CASE cSet $ "deleted" ; Set( _SET_DELETED, lOn ) CASE cSet $ "unique" ; Set( _SET_UNIQUE, lOn ) CASE cSet $ "exclusive" ; Set( _SET_EXCLUSIVE, lOn ); DBASE_EXCLUSIVE := lOn ENDCASE CASE cSet $ "color" cmdSetColor( cTextCmd ) CASE cSet $ "filter,history,index,order,relation" IF cSet $ "filter,index,order,relation" .AND. ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF Lower( ExtractParameter( @cTextCmd, " " ) ) != "to" SayScroll( "Syntax error" ) RETURN Nil ENDIF IF cSet == "relation" ; cmdSetRelation( cTextCmd ) ELSEIF cSet == "order" ; CmdSetOrder( cTextCmd ) ELSEIF cSet == "filter" ; CmdSetFilter( cTextCmd ) ELSEIF cSet == "index" ; CmdSetIndex( cTextCmd ) ENDIF CASE cSet $ "printer" SET PRINTER TO OTHERWISE SayScroll( "Invalid configuration" ) ENDCASE RETURN Nil STATIC FUNCTION cmdDir( cTextCmd ) LOCAL acTmpFile, nTotalSize, nLin, oElement IF Empty( cTextCmd ) acTmpFile := Directory( "*.dbf" ) nTotalSize := 0 nLin := 0 FOR EACH oElement IN acTmpFile USE ( oElement[ F_NAME ] ) ALIAS temp SayScroll( Pad( oElement[ F_NAME ], 15 ) + Transform( LastRec(), "999,999,999" ) + " " + ; Transform( oElement[ F_SIZE ], "999,999,999,999" ) + " " + Dtoc( oElement[ F_DATE ] ) + " " + oElement[ F_TIME ] ) nTotalSize += oElement[ F_SIZE ] nLin += 1 USE IF nLin > MaxRow() - 7 SayScroll( "Hit any to continue" ) IF Inkey(0) == K_ESC EXIT ENDIF nLin := 0 ENDIF NEXT SayScroll( "Total " + Str( Len( acTmpFile ) ) + " file(s) " + Transform( nTotalSize, PicVal( 9 ) ) + " byte(s)" ) ELSE acTmpFile := Directory( cTextCmd ) nTotalSize := 0 FOR EACH oElement IN acTmpFile SayScroll( Pad( oElement[ F_NAME ], 15 ) + Transform( oElement[ F_SIZE ], PicVal( 12 ) ) + " " + Dtoc( oElement[ F_DATE ] ) + " " + oElement[ F_TIME ] ) nTotalSize += oElement[ F_SIZE ] NEXT SayScroll( "Total " + Str( Len( acTmpFile ) ) + " file(s) " + Transform( nTotalSize, PicVal( 12 ) ) + " byte(s)" ) ENDIF RETURN Nil STATIC FUNCTION cmdIndex( cTextCmd ) LOCAL cKey, cFileName IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF Lower( ExtractParameter( @cTextCmd, " " ) ) != "on" SayScroll( "Syntax error" ) RETURN Nil ENDIF cKey := AllTrim( Substr( cTextCmd, 1, At( " to ", Lower( cTextCmd ) ) - 1 ) ) IF ! Type( cKey ) $ "NCD" SayScroll( "Invalid key" ) RETURN Nil ENDIF cFileName := AllTrim( Substr( cTextCmd, At( " to ", Lower( cTextCmd ) ) + 4 ) ) IF Len( cFileName ) == 0 SayScroll( "Invalid filename" ) RETURN Nil ENDIF INDEX ON &( cKey ) TAG jpa TO ( cFileName ) SayScroll( Str( LastRec() ) + " record(s) indexed" ) RETURN Nil STATIC FUNCTION cmdTotal( cTextCmd ) LOCAL cKey, cFileName IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF Lower( ExtractParameter( @cTextCmd, " " ) ) != "on" SayScroll( "Syntax error" ) RETURN Nil ENDIF cKey := AllTrim( Substr( cTextCmd, 1, At( " to ", Lower( cTextCmd ) ) - 1 ) ) IF ! Type( cKey ) $ "NCD" SayScroll( "Invalid key" ) RETURN Nil ENDIF cFileName := AllTrim( Substr( cTextCmd, At( " to ", Lower( cTextCmd ) ) + 4 ) ) IF Len( cFileName ) == 0 SayScroll( "Invalid filename" ) RETURN Nil ENDIF TOTAL ON &( cKey ) TO ( cFileName ) SayScroll( Str( LastRec()) + " record(s) Total" ) RETURN Nil STATIC FUNCTION cmdRun( cTextCmd ) wSave() RunCmd( cTextCmd ) ? @ MaxRow(), 0 SAY "Hit ESC to continue" DO WHILE Inkey(0) != K_ESC ENDDO wRestore() RETURN Nil STATIC FUNCTION cmdBrowse() IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF MsgExclamation( "Do not change in browse mode" ) wSave() Mensagem( "Select and ENTER, ESC abort, to change record exit and use EDIT" ) Browse( 2, 0, MaxRow() - 3, MaxCol() ) wRestore() RecUnlock() RETURN Nil STATIC FUNCTION cmdContinue() IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF CONTINUE IF LastKey() == K_ESC SayScroll( "Interrupted" ) ELSEIF Eof() SayScroll( "End of file" ) ENDIF RETURN Nil STATIC FUNCTION cmdPack() IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF ! DBASE_EXCLUSIVE SayScroll( "Only available in exclusive mode" ) RETURN Nil ENDIF PACK SayScroll( Str( LastRec() ) + " record(s) copyed" ) RETURN Nil STATIC FUNCTION cmdReindex() IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF ! DBASE_EXCLUSIVE SayScroll( "Only available in exclusive mode" ) RETURN Nil ENDIF REINDEX SayScroll( Str( LastRec() ) + " record(s) reindexed" ) RETURN Nil STATIC FUNCTION cmdSeek( cTextCmd ) IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF Len( Trim( OrdKey() ) ) == 0 SayScroll( "File not indexed" ) ELSEIF Type( cTextCmd ) != Type( OrdKey() ) SayScroll( "Order of file mismatch typed key" ) ELSE SEEK &cTextCmd IF Eof() SayScroll( "Not found" ) ENDIF ENDIF RETURN Nil STATIC FUNCTION cmdSetColor( cTextCmd ) IF ! Lower( ExtractParameter( @cTextCmd, " " ) ) == "to" RETURN Nil ENDIF SetColor( cTextCmd ) RETURN Nil STATIC FUNCTION CmdSetIndex( cTextCmd ) LOCAL aList, oElement SET INDEX TO IF Len( cTextCmd ) == 0 RETURN Nil ENDIF aList := GetParamList( cTextCmd ) FOR EACH oElement IN aList IF ! File( oElement + ".cdx" ) SayScroll( oElement + ".cdx not found" ) ELSE dbSetIndex( oElement ) ENDIF NEXT IF Len( aList ) != 0 SET ORDER TO 1 ENDIF RETURN Nil STATIC FUNCTION cmdSelect( cAlias ) IF Select( cAlias ) != 0 SELECT ( Select( cAlias ) ) ELSEIF SoNumero( cAlias ) == cAlias .AND. ! Empty( cAlias ) SELECT ( Val( cAlias ) ) ELSE SayScroll( "Alias not exist" ) ENDIF RETURN Nil STATIC FUNCTION CmdSetFilter( cTextCmd ) IF Empty( cTextCmd ) SET FILTER TO RETURN Nil ENDIF IF ValType( Macro( cTextCmd ) ) != "L" SayScroll( "Filter need to be true or false" ) RETURN Nil ENDIF SET FILTER TO &( cTextCmd ) RETURN Nil STATIC FUNCTION CmdSetOrder( cTextCmd ) IF Empty( cTextCmd ) SET ORDER TO 1 RETURN Nil ENDIF IF ValType( Macro( cTextCmd ) ) != "N" SayScroll( "Order need to be number" ) RETURN Nil ENDIF SET ORDER TO &( cTextCmd ) RETURN Nil STATIC FUNCTION cmdSkip( cTextCmd ) IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF Empty( cTextCmd ) SKIP ELSEIF MacroType( cTextCmd ) != "N" SayScroll( "Type mismatch" ) ELSEIF &( cTextCmd ) < 0 .AND. Bof() SayScroll( "Already in begining of file" ) ELSEIF &( cTextCmd ) > 0 .AND. Eof() SayScroll( "Already in end of file" ) ELSE SKIP &( cTextCmd ) ENDIF RETURN Nil STATIC FUNCTION cmdUnlock( cTextCmd ) IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF Empty( cTextCmd ) UNLOCK ELSEIF Lower( cTextCmd ) == "all" UNLOCK ALL ELSE ? "Invalid parameter" ENDIF RETURN Nil STATIC FUNCTION cmdZap() IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF ! DBASE_EXCLUSIVE SayScroll( "Only available in exclusive mode" ) RETURN Nil ENDIF ZAP SayScroll( "Now file is empty" ) RETURN Nil STATIC FUNCTION cmdGoTo( cTextCmd ) IF ! Used() SayScroll( "No file in use" ) RETURN Nil ENDIF IF Lower( cTextCmd ) == "top" GOTO TOP ELSEIF Len( cTextCmd ) > 4 .AND. cTextCmd $ "bottom" GOTO BOTTOM ELSEIF Type( cTextCmd ) != "N" SayScroll( "Invalid parameter" ) ELSEIF &( cTextCmd ) > LastRec() .OR. &( cTextCmd ) < 1 SayScroll( "Invalid record number" ) ELSE GOTO &( cTextCmd ) ENDIF RETURN Nil #define PARAM_NAME 1 #define PARAM_VALUE 2 #define PARAM_START 3 #define PARAM_END 4 STATIC FUNCTION ExtractForWhile( cTextCmd ) LOCAL oElement, aParameters, nPos, cWord, nCont aParameters := Array( 5 ) aParameters[ 1 ] := { "for", "", 0, 0 } aParameters[ 2 ] := { "while", "", 0, 0 } aParameters[ 3 ] := { "next", "", 0, 0 } aParameters[ 4 ] := { "record", "", 0, 0 } aParameters[ 5 ] := { Chr(205), "", 0, 0 } // so pra ter o fim cTextCmd := " " + cTextCmd + " " DBASE_ALL := ( " all " $ Lower( cTextCmd ) ) cTextCmd := StrTran( cTextCmd, " ALL ", " " ) cTextCmd := StrTran( cTextCmd, " all ", " " ) FOR EACH oElement IN aParameters cWord := oElement[ PARAM_NAME ] IF Len( cWord ) <= 4 nPos := At( " " + cWord + " ", Lower( cTextCmd ) ) ELSE FOR nCont = Len( cWord ) TO 4 STEP -1 cWord := Substr( cWord, 1, nCont ) nPos := At( " " + cWord + " ", Lower( cTextCmd ) ) IF nPos != 0 EXIT ENDIF NEXT ENDIF nPos := iif( nPos == 0, Len( cTextCmd ), nPos ) oElement[ PARAM_START ] := nPos NEXT ASort( aParameters,,, { | x, y | x[ PARAM_START ] < y[ PARAM_START ] } ) FOR nCont = 1 TO Len( aParameters ) - 1 aParameters[ nCont, PARAM_END ] := aParameters[ nCont + 1, PARAM_START ] NEXT aParameters[ 5, PARAM_END ] := Len( cTextCmd ) FOR EACH oElement IN aParameters oElement[ PARAM_VALUE ] := AllTrim( Substr( cTextCmd, oElement[ PARAM_START ] + 1, oElement[ PARAM_END ] - oElement[ PARAM_START ] ) ) DO CASE CASE oElement[ PARAM_NAME ] == "for" ; DBASE_FOR := Substr( oElement[ PARAM_VALUE ], At( " ", oElement[ PARAM_VALUE ] ) ) CASE oElement[ PARAM_NAME ] == "while" ; DBASE_WHILE := Substr( oElement[ PARAM_VALUE ], At( " ", oElement[ PARAM_VALUE ] ) ) CASE oElement[ PARAM_NAME ] == "next" ; DBASE_NEXT := Substr( oElement[ PARAM_VALUE ], At( " ", oElement[ PARAM_VALUE ] ) ) CASE oElement[ PARAM_NAME ] == "record" ; DBASE_RECORD := Substr( oElement[ PARAM_VALUE ], At( " ", oElement[ PARAM_VALUE ] ) ) ENDCASE NEXT cTextCmd := AllTrim( Substr( cTextCmd, 1, aParameters[ 1, PARAM_START ] - 1 ) ) IF Empty( DBASE_WHILE ) DBASE_WHILE := ".T." ELSEIF MacroType( DBASE_WHILE ) != "L" SayScroll( "WHILE is not a logical expression" ) RETURN .F. ENDIF IF Empty( DBASE_NEXT ) DBASE_NEXT := 0 ELSEIF MacroType( DBASE_NEXT ) != "N" SayScroll( "NEXT is not a numeric expression" ) RETURN .F. ELSE DBASE_NEXT := &( DBASE_NEXT ) ENDIF IF Empty( DBASE_RECORD ) DBASE_RECORD := 0 ELSEIF MacroType( DBASE_RECORD ) != "N" SayScroll( "RECORD is not a numeric expression" ) RETURN .F. ELSE DBASE_RECORD := &( DBASE_RECORD ) ENDIF IF Empty( DBASE_FOR ) DBASE_FOR := ".T." ELSEIF MacroType( DBASE_FOR ) != "L" SayScroll( "FOR is not a logical expression" ) RETURN .F. ELSE DBASE_ALL := .T. ENDIF IF DBASE_RECORD == 0 .AND. DBASE_NEXT == 0 .AND. DBASE_FOR == ".T." .AND. DBASE_WHILE == ".T." .AND. ! DBASE_ALL DBASE_RECORD := RecNo() ENDIF RETURN .T. STATIC FUNCTION GetParamList( cTextCmd, aList ) LOCAL aCharList := { { "(", ")" }, { "[", "]" }, { Chr(34), Chr(34) }, { "'", "'" } } LOCAL cSeparator := "", cChar aList := {} DO WHILE Len( cTextCmd ) > 0 FOR EACH cChar IN cTextCmd + " " DO CASE CASE hb_ASCan( aCharList, { | e | cChar = e[ 1 ] } ) != 0 cSeparator += cChar CASE hb_ASCan( aCharList,,, { | e | Len( cSeparator ) > 0 .AND. cChar == e[ 2 ] .AND. Right( cSeparator, 1 ) == e[ 1 ] } ) != 0 cSeparator := Left( cSeparator, Len( cSeparator ) - 1 ) CASE ( Len( cSeparator ) == 0 .AND. cChar == "," ) .OR. cChar:__EnumIsLast AAdd( aList, Substr( cTextCmd, 1, cChar:__EnumIndex - 1 ) ) cTextCmd := SUbstr( cTextCmd, cChar:__EnumIndex + 1 ) EXIT ENDCASE NEXT ENDDO RETURN aList STATIC FUNCTION Macro( cTxt ) LOCAL xValue BEGIN SEQUENCE WITH __BreakBlock() xValue := &( cTxt ) ENDSEQUENCE IF xValue == Nil xValue := "*ERRO*" ENDIF RETURN xValue