home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
dbase
/
text
/
neatness.prg
Wrap
Text File
|
1985-12-11
|
7KB
|
262 lines
* Program ID - NEATNESS.PRG
* Author - Randy Braa
* Data Image Corporation
* 3736 Eubank NE
* Albuquerque, NM 87111
* (505) 294-4094
* Rev No. - 850118 0.0
* (c) Copyright 1985, Data Image Corporation - All rights reserved.
* Comments - This program cleans up dBASE-III code. It will also
* produce a line-numbered listing.
*
* DATABASE TEXTWORK.dbf
* This database contains a single character-type element with
* a name of 'TEXT' and a size of 255 characters.
* - CHANGE HISTORY -
*=======================================================================
* Revision Modification
* ------------ --------------------------------------------------------
*
*=======================================================================
SET TALK OFF
SET SAFETY OFF
SET INTENSITY ON
STORE 0 TO IF_COUNT
STORE 0 TO DOW_COUNT
STORE 0 TO DOC_COUNT
STORE 0 TO INDENT
STORE 3 TO INDENTAMT
STORE 1 TO LINE
STORE SPACE(12) TO PROGNAME
STORE .F. TO MOLESTE
* intialize the textwork database.
CLEAR
USE TEXTWORK
ZAP
* now we find out what the user wants us to do.
@ 2,26 SAY "dBASE-III .PRG File Cleanup"
@ 3,26 SAY "==========================="
@ 6,20 SAY "What is the program name?"
DO WHILE PROGNAME = " "
@ 6,47 GET PROGNAME
READ
@ 23,0
IF AT('.',PROGNAME)=0
STORE TRIM(PROGNAME)+".PRG" TO PROGNAME
ENDIF
IF .NOT. FILE(PROGNAME)
@ 23,20 SAY "Unable to locate program " + PROGNAME
STORE SPACE(12) TO PROGNAME
ENDIF
ENDDO
*set up file to receive clean code.
CLEAR
? "Now cleaning file"
?
STORE SUBSTR(PROGNAME,1,AT('.',PROGNAME)-1) TO BASENAME
STORE BASENAME+".PRC" TO NEATNAME
STORE BASENAME+".PRP" TO PRIORNAME
SET ALTERNATE TO &NEATNAME
SET ALTERNATE ON
*append program to textwork dbf
APPEND FROM &PROGNAME SDF
*main process loop
GOTO TOP
DO WHILE .NOT. EOF()
IF LEN(TRIM(TEXT)) > 0
STORE TRIM(TEXT) TO STRING
STORE LEN(TRIM(STRING)) TO STRLEN
* left-justify the string
STORE 1 TO CHARPOS
DO WHILE SUBSTR(STRING,CHARPOS,1)=" "
CHARPOS=CHARPOS+1
ENDDO
STORE SUBSTR(STRING,CHARPOS) TO STRING
* get first word of line
STORE 1 TO CHARPOS
DO WHILE SUBSTR(STRING,CHARPOS,1)<> " " .AND. CHARPOS < 8
CHARPOS=CHARPOS+1
ENDDO
STORE UPPER(SUBSTR(STRING,1,CHARPOS))+" " TO WS
DO CASE
* make all comments lower case
CASE WS = "*"
* the moleste sw keeps comments of the front from being chnged
IF MOLESTE
STORE LOWER(STRING) TO STRING
ENDIF
* lines with quotes
CASE '"' $ STRING
STORE .T. TO MOLESTE
* locate the quotes
STORE AT('"',STRING) TO QUOTE1
STORE AT('"',SUBSTR(STRING,QUOTE1+1)) + QUOTE1 TO QUOTE2
* decide if comment comes at front, back or in the middle
IF QUOTE1 > 1 .AND. LEN(TRIM(STRING)) > QUOTE2
STORE UPPER(SUBSTR(STRING,1,QUOTE1-1)) +;
SUBSTR(STRING,QUOTE1,QUOTE2-QUOTE1+1) +;
UPPER(SUBSTR(STRING,QUOTE2+1)) TO STRING
ELSE
IF QUOTE1 = 1 .AND. QUOTE2 < LEN(TRIM(STRING))
STORE SUBSTR(STRING,1,QUOTE2) +;
UPPER(SUBSTR(STRING,QUOTE2+1)) TO STRING
ELSE
IF QUOTE1 > 1
STORE UPPER(SUBSTR(STRING,1,QUOTE1-1)) +;
SUBSTR(STRING,QUOTE1) TO STRING
ENDIF
ENDIF
ENDIF
OTHERWISE
STORE .T. TO MOLESTE
STORE UPPER(STRING) TO STRING
ENDCASE
* now do indentation
DO CASE
CASE WS = "DO "
? SPACE(INDENT) + STRING
STORE 4 TO CHARPOS
* skip leading blanks
DO WHILE SUBSTR(STRING,CHARPOS,1) = " " .AND. CHARPOS < STRLEN
CHARPOS = CHARPOS + 1
ENDDO
STORE CHARPOS TO BEGPOS
* now pick up second word of line
DO WHILE SUBSTR(STRING,CHARPOS,1) <> " " .AND. CHARPOS < STRLEN
CHARPOS=CHARPOS+1
ENDDO
STORE SUBSTR(STRING,BEGPOS,CHARPOS-BEGPOS+1)+" " TO WS
IF WS = "WHILE " .OR. WS = "CASE "
STORE INDENT + INDENTAMT TO INDENT
IF WS = "WHILE "
DOW_COUNT = DOW_COUNT + 1
ELSE
DOC_COUNT = DOC_COUNT + 1
ENDIF
ENDIF
* enddo, endif, endcase decrement
CASE WS="ENDCASE " .OR. WS="ENDDO " .OR. WS="ENDIF "
STORE INDENT - INDENTAMT TO INDENT
IF WS = "ENDCASE "
DOC_COUNT = DOC_COUNT - 1
ELSE
IF WS="ENDIF "
IF_COUNT=IF_COUNT-1
ELSE
DOW_COUNT=DOW_COUNT-1
ENDIF
ENDIF
? SPACE(INDENT) + STRING
CASE WS = "ELSE "
STORE INDENT-INDENTAMT TO INDENT
? SPACE(INDENT) + STRING
STORE INDENT+INDENTAMT TO INDENT
CASE WS = "IF "
? SPACE(INDENT) + STRING
STORE INDENT+INDENTAMT TO INDENT
IF_COUNT=IF_COUNT+1
OTHERWISE
? SPACE(INDENT) + STRING
ENDCASE
ELSE
?
ENDIF
SKIP
ENDDO
SET CONSOLE ON
SET ALTERNATE OFF
CLOSE ALTERNATE
IF FILE(PRIORNAME)
ERASE &PRIORNAME
ENDIF
RENAME &PROGNAME TO &PRIORNAME
RENAME &NEATNAME TO &PROGNAME
CLEAR
@ 5,0
IF IF_COUNT > 0
@ $+1,14 SAY STR(IF_COUNT,3) + " More IFs encountered than ENDIFs"
ELSE
IF IF_COUNT < 0
@ $+1,14 SAY STR(IF_COUNT*-1,3) + " More ENDIFs encountered than IFs"
ENDIF
ENDIF
IF DOW_COUNT > 0
@ $+1,14 SAY STR(DOW_COUNT,3) + " More DO WHILEs encountered than ENDDOs"
ELSE
IF DOW_COUNT < 0
@ $+1,14 SAY STR(DOW_COUNT*-1,3) + " More ENDDOs encountered than DO WHILEs"
ENDIF
ENDIF
IF DOC_COUNT > 0
@ $+1,14 SAY STR(DOC_COUNT,3) + " More DO CASEs encountered than ENDCASEs"
ELSE
IF DOC_COUNT < 0
@ $+1,14 SAY STR(DOC_COUNT*-1,3) + " More ENDCASEs encountered than DO CASEs"
ENDIF
ENDIF
STORE " " TO RESP
@ $+3,15 SAY "Would you like a hardcopy listing?"
@ $,$+2 GET RESP PICT "!"
READ
IF RESP <> "Y"
CLEAR ALL
RETURN
ENDIF
GOTO TOP
ZAP
APPEND FROM &PROGNAME SDF
STORE 001 TO LINE_NO
STORE 01 TO PAGE_NO
STORE 99 TO LINE_CNT
GOTO TOP
SET PRINT ON
DO WHILE .NOT. EOF()
IF LINE_CNT > 55
EJECT
?
?
? "Program-ID: "+PROGNAME+SPACE(60-LEN(PROGNAME))+"PAGE "+STR(PAGE_NO,2)
?
LINE_CNT=1
PAGE_NO=PAGE_NO+1
ENDIF
? TRIM(STR(LINE_NO,3)+" "+ TEXT)
LINE_NO=LINE_NO+1
LINE_CNT=LINE_CNT+1
SKIP
ENDDO
EJECT
SET PRINT OFF
SET TALK ON
CLEAR ALL
RETURN