home *** CD-ROM | disk | FTP | other *** search
- *⌐░⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐┤
- *⌐ª Program: CONVERT.PRG ⌐ª
- *⌐ª Function: ╩╣╙├ Low-Level File ║»╩²░╤╥╗╕÷ ASCII ├ⁿ┴ε╬─╝■ ⌐ª
- *⌐ª ╫¬╗╗╡╜┴φ╥╗╕÷ ASCII ╬─╝■╡─╖╢└². ⌐ª
- *⌐╕⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐ñ⌐╝
- PROCEDURE convert
- PRIVATE in_name, out_name, in_file, out_file, ;
- blocksize, recsperblk, recsize, cblock, ;
- write_ok
-
- * ╢¿╥σ┐Θ│ñ 840, ├┐╕÷┐Θ╙╨ 9╠⌡╝╟┬╝, ╝╟┬╝│ñ 86
- #DEFINE blocksize 840
- #DEFINE recsperblk 9
- #DEFINE recsize 86
-
- * ╜¿┴ó┐Θ║═╝╟┬╝╡─╝╟╩²╞≈
- nblocks = 0
- nrecs = 0
-
- * ┤╙╗ß╗░┐≥╓╨╤í╘±╥╗╕÷ ASCII ├ⁿ┴ε╬─╝■╫≈╩Σ╚δ╬─╝■
- in_name = GETFILE("","╤í╘± ASCII ├ⁿ┴ε╬─╝■╥╘╓┤╨╨")
- IF "" = in_name && ╚τ├╗╙╨╤í╘±╬─╝■╘≥═╦│÷
- RETURN
- ENDIF
-
- * ╜¿┴ó╩Σ│÷╬─╝■, ▓ó╕°╩Σ╚δ, ╩Σ╚δ╬─╝■┐╪╓╞┬δ
- out_name = SYS(3) + ".$$$"
- in_file = 0
- out_file = 0
-
- * ╝∞▓Θ┤φ╬≤╠⌡╝■, ┤φ╬≤╨┼╧ó╘┌╕≈╝∞▓Θ╫╙│╠╨≥╓╨╧╘╩╛
- WAIT WINDOW " ╩Σ╚δ╬─╝■╓╗╘╩╨φ╙╔╫╓─╕, ╩²╫╓║═┐╒╕±╫Θ│╔, ╒²╘┌╜°╨╨╝∞▓Θ " NOWAIT
- IF !openfile(in_name, @in_file) ;
- OR filempty(in_name, in_file) ;
- OR !okchars(in_name, in_file) ;
- OR !makefile(out_name, @out_file)
- * ╚τ╣√│÷┤φ╘≥▓╗╝╠╨°╜°╨╨
- = FCLOSE(in_file)
- WAIT CLEAR
- RETURN
- ENDIF
-
- WAIT WINDOW " ╒²╘┌╢╘╩Σ╚δ╬─╝■ " + in_name + " ╫≈╫¬╗╗ " ;
- NOWAIT
- cblock = ""
- write_ok = .T.
- * ░╤╥╗╕÷┐Θ block ╢┴╡╜ cblock ╓╨, ╚╗║≤░╤╞Σ╓╨╡─ 9╠⌡╩²╛▌╝╟┬╝╨┤╡╜
- * ╩Σ│÷╬─╝■, ╝╟┬╝│ñ 90╕÷╫╓╖√, ╡½│²╚Ñ╝╟┬╝║┼╡─═╖ 4╕÷╫╓╖√.
- DO WHILE !gotblock(@cblock, in_file, blocksize, @nblocks) AND write_ok
- recpos = 17
- FOR j=1 TO recsperblk
- currec = " " + SUBSTR(cblock,recpos,recsize)
- IF !empty(currec)
- bytesout = FPUTS(out_file, currec)
- IF bytesout != recsize + 3 && " "+CR+LF
- ?? CHR(7)
- WAIT WINDOW " ╘┌░╤╝╟┬╝╨┤╡╜╩Σ│÷╬─╝■ "+;
- out_name+" ╝╟┬╝│ñ╢╚▓╗╣╗ 86 bytes !" TIMEOUT 5
- write_ok = .F.
- nrecs = nrecs+1
- EXIT
- ENDIF
- nrecs = nrecs+1
- ENDIF
-
- recpos = recpos + recsize + 4
- ENDFOR
- ENDDO
-
- * ╣╪▒╒╩Σ╚δ║═╩Σ│÷╬─╝■
- = FCLOSE(in_file)
- = FCLOSE(out_file)
-
- * ╧╘╩╛╝╟┬╝║═┐Θ╩²
- WAIT WINDOW " ╜¿┴ó┴╦ " + ltrim(str(nrecs)) + ;
- " ╠⌡╝╟┬╝, └┤╫╘ " + ltrim(str(nblocks)) + ;
- " ┐Θ." TIMEOUT 5
- IF !addords(out_name)
- WAIT WINDOW " ├╗╙╨╨▐╕─╩²╛▌┐Γ " TIMEOUT 5
- ENDIF
- ERASE (out_name)
- WAIT CLEAR
- RETURN
-
- FUNCTION openfile
- * ╝∞▓Θ╬─╝■┤≥┐¬
- PARAMETERS f_name, f_handle
- f_handle = FOPEN(f_name)
- IF f_handle < 0
- ?? CHR(7)
- WAIT WINDOW " ▓╗─▄┤≥┐¬╬─╝■ " + UPPER(f_name)+"!" TIMEOUT 5
- ENDIF
- RETURN f_handle > 0
-
- FUNCTION filempty
- * ╝∞▓Θ╬─╝■╩╟╖±╬¬┐╒
- PARAMETERS f_name, f_handle
- IF FEOF(f_handle)
- ?? CHR(7)
- WAIT WINDOW " ╬─╝■ " + UPPER(f_name) + " ╩╟┐╒╡─ !" ;
- TIMEOUT 5
- ENDIF
- RETURN FEOF(f_handle)
-
- FUNCTION okchars
- * ╝∞▓Θ╩Σ╚δ╬─╝■╩╟╖±╓╗╙╔╫╓─╕,╩²╫╓,║═┐╒╕±╫Θ│╔
- PARAMETERS f_name, f_handle
- PRIVATE b_str, all_ok, c
- all_ok = .T.
- DO WHILE !FEOF(f_handle) AND all_ok
- b_str = FGETS(f_handle, 1000)
- FOR j=1 TO len(b_str)
- c = substr(b_str,j,1)
- IF !isalpha(c) AND !isdigit(c) AND c != " "
- ?? CHR(7)
- WAIT WINDOW UPPER(f_name) + " ║¼╙╨╥╗╕÷╬▐╨º╡─╫╓╖√ " + ;
- " ("+c+")!" TIMEOUT 5
- all_ok = .F.
- EXIT
- ENDIF
- ENDFOR
- ENDDO
- * ░╤╬─╝■╓╕╒δ╥╞╡╜╬─╝■╡─┐¬═╖┤ª
- = FSEEK(f_handle, 0)
- RETURN all_ok
-
- FUNCTION makefile
- * ╝∞▓Θ╩Σ│÷╬─╝■╜¿┴ó╩╟╖±│╔╣ª
- PARAMETERS f_name, f_handle
- f_handle = FCREATE(f_name)
- IF f_handle < 0
- ?? CHR(7)
- WAIT WINDOW " ╩Σ│÷╬─╝■ " + f_name + ;
- " ▓╗─▄╜¿┴ó! " TIMEOUT 5
- ENDIF
- RETURN f_handle > 0
-
- FUNCTION gotblock
- parameters b_str, f_handle, nbytes, nblocks
- b_str = FGETS(f_handle, nbytes+10)
- nblocks = IIF(len(b_str) = 0, nblocks, nblocks+1)
- IF BETWEEN(len(b_str), 1, nbytes-1)
- * FGETS() did not return enough data.
- ?? CHR(7)
- WAIT WINDOW " ┐Θ║┼ " + ltrim(str(nblocks)) + ;
- " ╙╨ " + ltrim(str(len(b_str))) + " bytes. ╥¬╟≤╙╨ " + ;
- ltrim(str(nbytes)) + " bytes !" ;
- TIMEOUT 5
- ENDIF
- RETURN len(b_str) = nbytes
-
- FUNCTION addords
- * ╧≥╩²╛▌┐Γ TEMP.DBF ╓╨╫╖╝╙╝╟┬╝.
- PARAMETERS new_ascii
- WAIT WINDOW " ╧≥╩²╛▌┐Γ TEMP.DBF ╓╨╫╖╝╙╝╟┬╝. " NOWAIT
- USE TEMP
- APPEND FROM (new_ascii) TYPE SDF
- GO TOP
- BROW
- RETURN