*put the bin/chars in a string cBinFile=REPLICATE(CHR(0),2)+CHR(2)+CHR(0)+CHR(1)+CHR(0); +REPLICATE(CHR(32),2)+CHR(2)+CHR(0)+CHR(5)+REPLICATE(CHR(0),3); +"0"+CHR(1)+REPLICATE(CHR(0),2)+CHR(22)+REPLICATE(CHR(0),3); +CHR(40)+REPLICATE(CHR(0),3)+CHR(32)+REPLICATE(CHR(0),3); +"@"+REPLICATE(CHR(0),3)+CHR(1)+CHR(0)+CHR(1); +REPLICATE(CHR(0),6)+CHR(1)+REPLICATE(CHR(0),10); +CHR(2)+REPLICATE(CHR(0),11)+REPLICATE(CHR(255),3); +REPLICATE(CHR(0),45)+CHR(3)+CHR(252)+REPLICATE(CHR(0),2); +CHR(3)+CHR(252)+REPLICATE(CHR(0),2)+CHR(7)+CHR(254); +REPLICATE(CHR(0),2)+CHR(7)+CHR(254)+REPLICATE(CHR(0),2); +CHR(15)+CHR(254)+REPLICATE(CHR(0),2)+CHR(15)+CHR(255); +REPLICATE(CHR(0),2)+CHR(31)+CHR(255)+REPLICATE(CHR(0),2); +CHR(31)+CHR(255)+REPLICATE(CHR(0),2)+"7"+CHR(255); +REPLICATE(CHR(0),2)+"w"+CHR(255)+REPLICATE(CHR(0),2); +"g"+CHR(251)+REPLICATE(CHR(0),2)+CHR(6)+CHR(219); +REPLICATE(CHR(0),2)+CHR(6)+CHR(218)+REPLICATE(CHR(0),2); +CHR(6)+CHR(216)+REPLICATE(CHR(0),2)+CHR(6)+CHR(192); +REPLICATE(CHR(0),2)+CHR(6)+REPLICATE(CHR(0),3); +CHR(6)+REPLICATE(CHR(0),3)+CHR(6)+REPLICATE(CHR(0),3); +CHR(6)+REPLICATE(CHR(0),3)+CHR(6)+REPLICATE(CHR(0),7); +REPLICATE(CHR(255),40)+CHR(248)+CHR(1)+REPLICATE(CHR(255),2); +CHR(248)+CHR(1)+REPLICATE(CHR(255),2)+CHR(248)+CHR(1); +REPLICATE(CHR(255),2)+CHR(240)+CHR(0)+REPLICATE(CHR(255),2); +CHR(240)+CHR(0)+REPLICATE(CHR(255),2)+CHR(224)+CHR(0); +REPLICATE(CHR(255),2)+CHR(224)+CHR(0)+CHR(127)+CHR(255); +CHR(192)+CHR(0)+CHR(127)+CHR(255)+CHR(192)+CHR(0)+CHR(127); +CHR(255)+CHR(128)+CHR(0)+CHR(127)+CHR(255)+REPLICATE(CHR(0),2); +CHR(127)+CHR(255)+REPLICATE(CHR(0),2)+CHR(127)+CHR(255); +CHR(16)+CHR(0)+CHR(127)+CHR(255)+CHR(240)+CHR(0)+REPLICATE(CHR(255),2); +CHR(240)+CHR(1)+REPLICATE(CHR(255),2)+CHR(240)+CHR(7); +REPLICATE(CHR(255),2)+CHR(240)+"?"+REPLICATE(CHR(255),2); +CHR(240)+REPLICATE(CHR(255),3)+CHR(240)+REPLICATE(CHR(255),3); +CHR(240)+REPLICATE(CHR(255),3)+CHR(240)+REPLICATE(CHR(255),3); +CHR(249)+REPLICATE(CHR(255),3) *Create the file on the disk STRTOFILE(cBinFile,"link.cur")
*function bintocode ************************ * take a file as input and generate the * vfp code to write back the file to disk * output to _cliptext * * this can be used to create bin files * on the fly. ie a mouse cursor file * or a small BMP * ************************ lparam inputfile local pos,i,fhandle,nfsize,cOutput,cChar,cNextChar,nLineChars,curLen,nLastChar,nOccurs * cut the line with a ";"+chr(13)+CHR(9) when this value was reached nLineChars=50 *no error msg, just return .f. if !file(inputfile) return .f. endif *open the file fhandle=fopen(inputfile) if fhandle=-1 return .f. endif *-- nfSize = FSEEK(fhandle, 0, 2) && eof cOutPut="" curLen=0 nLastChar=-1 nOccurs=0 FSEEK(fHandle, 0, 0) && bof *read the file char by char FOR pos=0 TO nfSize-1 FSEEK(fHandle, pos, 0) cChar=FREAD(fHandle,1) IF ASC(cChar) = nLastChar *repeated char nOccurs=nOccurs+1 LOOP &&NEXT && pos ELSE IF curlen > nLineChars *new line cOutput=cOutput+[;]+CHR(13)+CHR(9) lStringOpen=.F. curLen=0 ENDIF *new char IF nOccurs > 1 *write ntimes the same char cOutput=cOutput+"+REPLICATE(CHR("+; ALLTRIM(STR(nLastChar))+"),"+ALLTRIM(STR(nOccurs))+")" curlen=curlen+23 ENDIF nOccurs=1 nLastChar = ASC(cChar) * test the next to see if it is a repeated char, loop if .t. IF pos < nfSize-2 FSEEK(fHandle, pos+1, 0) cNextChar=FREAD(fHandle,1) IF ASC(cChar)=ASC(cNextChar) LOOP &&NEXT pos ENDIF ENDIF ENDIF IF curlen > nLineChars *new line cOutput=cOutput+[;]+CHR(13)+CHR(9) lStringOpen=.F. curLen=0 ENDIF cOutput=cOutput+"+CHR("+ALLTRIM(STR(ASC(cChar)))+")" curlen=curlen+8 ENDFOR IF nOccurs > 1 *write ntimes the same char cOutput=cOutput+"+REPLICATE(CHR("+; ALLTRIM(STR(nLastChar))+"),"+ALLTRIM(STR(nOccurs))+")" ENDIF *close the source file FCLOSE(fHandle) *replace CHR(n) by the printable character for some values FOR i=48 TO 122 cOutPut=STRTRAN(cOutPut, "CHR("+ALLTRIM(STR(i))+")",["]+CHR(i)+["]) ENDFOR *shorten the lines again if one printable char follow another one cOutPut=STRTRAN(cOutPut, ["+"],[]) *create the code, strip out the first "+" and copy to clipboard cOutPut=[*put the bin/chars in a string]+CHR(13)+[cBinFile=]+SUBSTR(cOutPut,2)+; CHR(13)+[*Create the file on the disk]+CHR(13)+[STRTOFILE(cBinFile,"]+inputfile+[")] _CLIPTEXT= cOutPut RETURN .T. *---------------------
select mytable cCursorFile=myTable.BinMemo STRTOFILE(cursorFile,"link.cur")