Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

116 lines (77 sloc) 3.071 kB
`JorgeChB 2012-06-14 GitGetMethodTextById Crea un fichero con el texto de un método
` This method will retrieve the contents of the specified method as text
` With many thanks to Miloslav Bystricky for supplying the code
` $1 LONGINT IDs del recurso CC4D que contiene el método que se quiere guardar como texto
` $0 TEXT path al fichero (temporal) en el que se ha guardado el texto
`El texto está indentado con 2 espacios.
`El encoding del texto del fichero es MacRoman.
C_TEXT($0;$src;$fileName)
C_LONGINT($1;$methodSize;$lineSize;$logicalLineSize;$err;$offset;$nivelDeIndentacion)
C_BLOB($blob;$blobLineTokens)
C_TEXT($fileName)
C_TEXT($LF;$charChungo;$padding)
C_TEXT($if;$else;$endIf;$while;$endWhile;$for;$endFor;$repeat;$until;$caseOf;$endCase)
$LF:=Char(Line feed )
$fileName:=RAMDISK +"tmp_"+Replace string(Current method name;" ";"")+"_"+String($1)+"_"+String(Tickcount)+"_"+String(Random)+".txt"
$file:=AP fopen ($fileName;0)
` Get the resource data
$err:=API Get Resource ("CC4D";$1;$blob)
If ($err#0)
AP FPRINT ($file;"***Error "+String($err)+" en API Get Resource(\"CC4D\")"+$LF)
Else
`Indentar los if()s, for()s, etc
$nivelDeIndentacion:=0
$padding:=" "
$if:="If ("
$else:="Else"
$endIf:="End if"
$while:="While ("
$endWhile:="End while"
$for:="For ("
$endFor:="End for"
$repeat:="Repeat"
$until:="Until ("
$caseOf:="Case of"
$endCase:="End case"
$charChungo:=Char(0x00CA) `Es el que aparece antes de los comentarios y en algunos otros sitios
$methodSize:=BLOB size($blob)-13
$offset:=10
While ($offset<$methodSize)
$lineSize:=BLOB to integer($blob;Native byte ordering ;$offset)
$offset:=$offset+2
$logicalLineSize:=BLOB to integer($blob;Native byte ordering ;$offset)
$offset:=$offset-4
COPY BLOB($blob;$blobLineTokens;$offset;0;$lineSize)
$offset:=$offset+$lineSize
If ($logicalLineSize<2)
AP FPRINT ($file;$LF)
Else
$src:=""
$err:=API Detokenize ($blobLineTokens;$src)
If ($err#0)
AP FPRINT ($file;"***Error "+String($err)+" en API Detokenize()"+$LF)
$offset:=$methodSize ` bail out on error
Else
$estaLinea:=0
$incrementarEn:=0
If ((Position($if;$src)=1) | (Position($while;$src)=1) | (Position($for;$src)=1) | (Position($repeat;$src)=1) | (Position($caseOf;$src)=1))
$incrementarEn:=1
Else
If ((Position($endIf;$src)=1) | (Position($endWhile;$src)=1) | (Position($endFor;$src)=1) | (Position($until;$src)=1) | (Position($endCase;$src)=1))
$incrementarEn:=-1
$estaLinea:=-1
Else
If (Position($else;$src)=1)
$estaLinea:=-1
End if
End if
End if
$pre:=$padding*($nivelDeIndentacion+$estaLinea)
AP FPRINT ($file;$pre+Replace string($src;$charChungo;" ")+$LF)
$nivelDeIndentacion:=$nivelDeIndentacion+$incrementarEn
End if
End if
End while
End if
AP FCLOSE ($file)
$0:=$fileName
Jump to Line
Something went wrong with that request. Please try again.