Post by Robert on Sept 4, 2023 20:40:34 GMT -5
===> Jan 12 2024, incorrect keyboard command (EraseEOF) changed to (EraseEOL)
===> File in attachment link also corrected
This is raw code right now, but it appears to work.
The main mechanics are simple. The hard part is copying the data to the clipboard so that it can be edited.
The Clip Edit session only uses ANSI data. The macro needs to grab the data of the file into a ThinBasic string, and convert it to ANSI so that CLIP can use it. There are ThinBasic functions to handle this, but they keep the BOM in place, which gets treated like a junk character. That has to be chopped off. It's necessary to determine if the file is UTF-8 or UTF-16, so we know how much to chop off before converting to ANSI. Also, if the file is UTF-8, the "conversion" just consists of removing the BOM without any other changes.
The UTF-8 processing is probably wrong, but as I say, this is raw code. Maybe someone has a better idea.
R
===> Stefan has come up with an interesting way to approach this using MEDIT. I think that will end up being a better way to try this, and it won't have the issues that this macro does.
===> I uploaded a better FCLIP.MACRO which seems to work better.
===> File in attachment link also corrected
This is raw code right now, but it appears to work.
The main mechanics are simple. The hard part is copying the data to the clipboard so that it can be edited.
The Clip Edit session only uses ANSI data. The macro needs to grab the data of the file into a ThinBasic string, and convert it to ANSI so that CLIP can use it. There are ThinBasic functions to handle this, but they keep the BOM in place, which gets treated like a junk character. That has to be chopped off. It's necessary to determine if the file is UTF-8 or UTF-16, so we know how much to chop off before converting to ANSI. Also, if the file is UTF-8, the "conversion" just consists of removing the BOM without any other changes.
The UTF-8 processing is probably wrong, but as I say, this is raw code. Maybe someone has a better idea.
R
===> Stefan has come up with an interesting way to approach this using MEDIT. I think that will end up being a better way to try this, and it won't have the issues that this macro does.
===> I uploaded a better FCLIP.MACRO which seems to work better.
' FCLIP.MACRO
'
' This macro allows you to copy a file to the Windows clipboard from a line-cmd field in FM.
'
SPF_Loop_Check(0)
USES "FILE"
IF is_fm = 0 OR is_line_cmd = 0 THEN HALT("FCLIP must be entered in an FM line cmd area")
DIM Fnum AS LONG = VAL(Get_Arg$(1))
DIM Fname AS STRING = FMGet_FileName$(Fnum)
DIM Fpath AS STRING = FMGet_Path$(FNum)
DIM fullname AS STRING = Fpath + Fname
// make sure file really exists. if it didn't it would be weird
IF FILE_Exists(fullname) = %False THEN HALT("FCLIP file does not exist ?")
SPF_Post_Do("(ClipClear)(Home)(EraseEOL)[CLIP](Enter)(Home)[COPY '" + fullname + "'](Enter)")
HALT(0)