1: #IFDEF TOTVS
2: #include "totvs.ch"
3: #ELSE
4: #IFDEF PROTHEUS
5: #include "protheus.ch"
6: #ELSE
7: //compile:
8: //http://harbour-project.sourceforge.net/
9: //set include=%include%;c:\hb32\include\
10: //c:\hb32\bin\hbmk2.exe u_regua /dHARBOUR
11: //c:\hb32\bin\upx.exe u_regua.exe
12: #include "hb.ch"
13: #include "common.ch"
14: #include "fileio.ch"
15: #ENDIF
16: #ENDIF
17: #IFNDEF CRLF
18: #IFDEF HARBOUR
19: #DEFINE CRLF HB_OsNewLine()
20: #ELSE
21: #DEFINE CRLF CHR(13)+CHR(10)
22: #ENDIF
23: #ENDIF
24: /*
25: Programa : U_Regua
26: Função : Main/U_Regua
27: Autor : Marinaldo de Jesus [ http://www.blacktdn.com.br ]
28: Data : 17/08/2012
29: Uso : Regua para Arquivo Texto
30: */
31: #IFDEF HARBOUR
32: Function Main( uBuffer )
33: #DEFINE MAX_BUFFER Int(((784384766*8)-(1073741824*3.68))/8) //( Unrecoverable error 9009: hb_xrealloc can't reallocate memory )
34: Local nBuffer
35: DEFAULT uBuffer TO 220
36: #ELSE
37: User Function Regua01( uBuffer )
38: #DEFINE MAX_BUFFER (1048575) //( + 1: String size overflow! )
39: Local nBuffer
40: DEFAULT uBuffer := 220
41: #ENDIF
42: if (ValType(uBuffer)=="C")
43: uBuffer := Val(uBuffer)
44: endif
45: nBuffer := Min(MAX_BUFFER,uBuffer)
46: Return( Regua( nBuffer ) )
47: /*
48: Programa : U_Regua
49: Função : Regua
50: Autor : Marinaldo de Jesus [ http://www.blacktdn.com.br ]
51: Data : 17/08/2012
52: Uso : Regua para Arquivo Texto
53: */
54: Static Function Regua(nBuffer)
55:
56: Local aB
57:
58: Local c05
59: Local c10
60:
61: Local cfH
62:
63: Local cCRLF
64: Local cRegua
65:
66: Local l05
67: Local l10
68:
69: Local n05
70: Local n10
71: Local n10I
72:
73: Local nfH
74: Local nRep
75:
76: n10 := (nBuffer/10)
77: n10I := Int(n10)
78: nRep := (n10I+(((n10)-n10I)*10))
79: nRep := Min(nRep,9999999999)
80: cRegua := SubStr(Replicate("1234567890",nRep),1,nBuffer)
81: aB := StrToKArr(cRegua,"0")
82:
83: aFill(aB,NIL)
84:
85: c05 := ""
86: c10 := ""
87:
88: n05 := 0
89: n10 := 0
90:
91: aEval(aB,{|x,y| n05 := (y*5) ,;
92: n10 := (y*10),;
93: l05 := ( n05 <= 99999 ),;
94: IF( l05 , c05 += Transform(n05,"99999") , NIL ),;
95: l10 := ( n10 <= 9999999999 ),;
96: IF( l10 , c10 += Transform(n10,"9999999999") , NIL );
97: };
98: )
99:
100: aEval(aB,{|x,y| l05 := ( ( n05 += 5 ) <= 99999 ),;
101: IF( l05 , c05 += Transform(n05,"99999") , NIL );
102: };
103: )
104:
105: aSize(aB,0)
106:
107: aB := NIL
108:
109: c05 := SubStr(c05,1,(Int(Min(99999,nbuffer)/5)*5))
110: c10 := SubStr(c10,1,(Int(Min(9999999999,nbuffer)/10)*10))
111:
112: #IFDEF HARBOUR
113: cfH := GetCurrentFolder()
114: IF .NOT.(subStr(cfH,-1)==hb_ps())
115: cfH += hb_ps()
116: EndIF
117: #ELSE
118: cfH := GetTempPath()
119: IF .NOT.(subStr(cfH,-1)$"\/")
120: IF ("/"$cfH)
121: cfH += "/"
122: Else
123: cfH += "\"
124: EndIF
125: EndIF
126: #ENDIF
127: cfH += ProcName()
128: cfH += "-"
129: cfH += LTrim(Str(nBuffer))
130: cfH += "-"
131: cfH += DtoS(Date())
132: cfH += "-"
133: cfH += StrTran(Time(),":","-")
134: cfH += ".txt"
135:
136: nfH := fCreate(Lower(cfH))
137:
138: if .NOT.(NtoL(fError()))
139: cCRLF := CRLF
140: fWrite( nfH , c10 + cCRLF )
141: fWrite( nfH , c05 + cCRLF )
142: fWrite( nfH , cRegua + cCRLF )
143: fWrite( nfH , c05 + cCRLF )
144: fWrite( nfH , c10 + cCRLF )
145: fClose( nfH )
146: endif
147:
148: return({cRegua,c05,c10})
149:
150: #IFDEF HARBOUR
151: /*
152: Programa : U_Regua
153: Função : StrToKArr
154: Autor : Marinaldo de Jesus [ http://www.blacktdn.com.br ]
155: Data : 17/08/2012
156: Uso : Transforma String em Array conforme Token
157: */
158: Static Function StrToKArr( cString , cToken , bEvalToken )
159:
160: Local aStrTokArr := {}
161:
162: Local cStr
163:
164: Local nATToken
165: Local nRealSize
166:
167: DEFAULT cToken TO "+"
168: DEFAULT bEvalToken TO { || .T. }
169:
170: if ( at( cToken , cString ) > 0 )
171: nRealSize := len( cToken )
172: while ( ( nATToken := at( cToken , cString ) ) > 0 )
173: if ( nATToken > 1 )
174: cStr := allTrim( subStr( cString , 1 , ( nATToken - 1 ) ) )
175: cString := subStr( cString , ( nATToken + nRealSize ) )
176: Else
177: cStr := ""
178: cString := subStr( cString , ( nATToken + nRealSize ) )
179: endif
180: if eval( bEvalToken , @cStr )
181: aAdd( aStrTokArr , cStr )
182: endif
183: end while
184: if ( len( cString ) > 0 )
185: cStr := cString
186: if eval( bEvalToken , @cStr )
187: aAdd( aStrTokArr , cStr )
188: endif
189: endif
190: Else
191: cStr := cString
192: if eval( bEvalToken , @cStr )
193: aAdd( aStrTokArr , cStr )
194: endif
195: endif
196:
197: return( aStrTokArr )
198:
199: /*
200: Programa : U_Regua
201: Função : NtoL
202: Autor : Marinaldo de Jesus [ http://www.blacktdn.com.br ]
203: Data : 17/08/2012
204: Uso : Numerico para Logico
205: */
206: Static Function NtoL(n)
207: Return(.NOT.(Empty(n)))
208:
209: /*
210: Programa : U_Regua
211: Função : GetCurrentFolder
212: Autor : Marinaldo de Jesus [ http://www.blacktdn.com.br ]
213: Data : 17/08/2012
214: Uso : Retornar o Diretorio Corrente
215: */
216: Static Function GetCurrentFolder()
217: Return( hb_CurDrive() + hb_osDriveSeparator() + hb_ps() + CurDir() )
218:
219: #ENDIF
Comentários
Postar um comentário