Author: maroon
Added: 6y
Updated: 6y
mIRC: requires 7.52+
Hits: 1,557
Downloads: 9
Review: entropy
Size: 3.84KB
1 0
Login to vote.
clip2disk - saves clipboard to disk
v1.0
Creates (or appends to) disk file the text contents of the clipboard while preserving leading/trailing spaces
Won't overwrite file without -o switch.
-o overwrite file
-a append to file
-b remove blank lines at top+bottom
-t remove trailing spaces
Size of file limited to size of &binvar, which should be 100's of millions depending on avail resources. (Divide resources in half when using -t or -b because it needs to create 2nd &binvars)
Reports the # lines and # bytes written to disk, and the resulting file size
Codepoints 128+ are UTF-8 encoded because that's what mIRC says is in the clipboard
This upload file was created with: /clip2disk -otb filename
; Clip2disk 1.0 by maroon, requires feature added mIRCv7.52 ; size of file limited by ability to create long-enough &binvar, but should be well over 1mb (-tb switches make 2nd &binvar, so cut that in half) ; "/clip2disk filename" is the same as '/run notepad filename' then pressing Ctrl+V, except offers ability to trim spaces ; This upload file created with: /clipboard -otb filename alias clip2disk { echo 5 -ag Clipboard to disk file, by maroon $+ $chr(169) Syntax /clip2disk [-[o|a]tb] <filename> echo 5 -ag uses binvary variable to preserve leading + trailing spaces (except when using -t switch) echo 5 -ag outputs clipboard contents to 'filename', -o = overwrite, -a = append, -t = trim trailing spaces/tabs (assumes each line ends with $ $+ crlf), -b also trims blank rows from top/bottom if ($version !isnum 7.52-) { echo -ag $+($chr(3),0,$chr(44),4) sorry you're using $version but this uses $ $+ cb(-1,,binvar) feature added in v7.52 $chr(3) | return } ; if you wish the default to always use the t switch, you can change the next line to have: %switches t var %writtenlines 0 , %switches if (-* iswm $1) { var %switches %switches $+ $1 | tokenize 32 $2- } if ((a isin %switches) && (o isin %switches)) { echo -ag $+($chr(3),0,$chr(44),4) Halted! can't overwrite AND apppend, chose ONE $chr(3) | return } if ($regsubex(%switches,/[oatb-]/gi,\t)) { echo -ag $+($chr(3),0,$chr(44),4) no action: invalid switch $regsubex(%switches,/[oatb-]/gi,\t) in %switches $chr(3) | return } if (($isfile($1-)) && (o !isin %switches) && (a !isin %switches)) { echo -ag $+($chr(3),0,$chr(44),4) no action: need -o to overwrite existing file $1- $chr(3) | return } if ($1- == $null) { echo -ag $+($chr(3),0,$chr(44),4) *no action: Required filename is missing. /clip2disk -switches filename $chr(3) | return } if (($cb(0) == 1) && ($cb(0).len == 0)) { echo -ag $+($chr(3),0,$chr(44),4) *no action: Clipboard is empty $chr(3) | return } if (!$regsubex(%switches,/[^tb]/gi,\t)) { ; this method works beginning v7.52 noop $cb(-1,,&var) ; this also works beginning v7.52 but is limited to 4150 chars ; noop $regsubex(foo,$cb(-1),,,&var) } else { var %cblines $cb(0) var %a 1 if (b isin %switches) { while ((%a < %cblines) && ($remove($cb(%a),$chr(32),$chr(9)) == $null)) { inc %a } while ((%cblines > %a) && ($remove($cb(%cblines),$chr(32),$chr(9)) == $null)) { dec %cblines } var %writtenlines $calc(%cblines - %a + 1) } while (%a <= %cblines) { noop $cb(%a,,&t) var %i $bvar(&t,0) while ((t isin %switches) && (%i isnum 2-) && ($istok(32 9,$bvar(&t,%i),32))) { dec %i } if (%i) bcopy &var -1 &t 1 %i | bset &var -1 13 10 | inc %a } inc %a } var %len $bvar(&var,0) if (!%len) { echo 5 -ag Abort: clipboard was empty! | return } if ((a isin %switches) && ($file($1-).size isnum 1-)) { ; this section inserts $crlf if appending to existing file that doesn't already end with $crlf var %crlf 0 if ($file($1-).size == 1) inc %crlf else { bread $qt($1-) $calc($file($1-).size -2) 2 &crlf | if ($bvar(&crlf,1-2) != 13 10) inc %crlf } if (%crlf) { bset -c &t 1 13 10 | bcopy &t -1 &var 1 -1 | bcopy -c &var 1 &t 1 -1 } } if ($bvar(&var,0) >= $disk($longfn($1-)).free) { echo -ag $+($chr(3),0,$chr(44),5) Clip2disk: Halt! Not enough disk space available to write $longfn($1-) $chr(3) | halt } bwrite -c $qt($1-) $iif(a isin %switches,-1,0) %len &var echo -ag $+($chr(3),0,$chr(44),5) writing clipboard: $iif(%writtenlines,$v1,$cb(0)) lines $bvar(&var,0) bytes to $iif(a isin %switches,append to) disk. $qt($1-) now with filesize $file($1-).size $chr(3) }
1st time the whole file didn't paste
This snippet works as expected, with little detailed notes about the file and highlights the text matching the parameter.
Well done maroon!