Snippets
  • Uploaded By: maroon
  • Author: maroon
  • Added: 8 months ago
  • Last Updated: 8 months ago
  • mIRC Version: requires 7.52+
  • Hits: 450
  • Size: 3.84KB
  • Downloads: 2
  • Review By: entropy

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

    
  2    0  Login to Vote.


Source Code:
  1. ; Clip2disk 1.0 by maroon, requires feature added mIRCv7.52
  2. ; 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)
  3. ; "/clip2disk filename" is the same as '/run notepad filename' then pressing Ctrl+V, except offers ability to trim spaces
  4. ; This upload file created with: /clipboard -otb filename
  5. alias clip2disk {
  6. echo 5 -ag Clipboard to disk file, by maroon $+ $chr(169) Syntax /clip2disk [-[o|a]tb] <filename>
  7. echo 5 -ag uses binvary variable to preserve leading + trailing spaces (except when using -t switch)
  8. 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
  9. 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 }
  10. ; if you wish the default to always use the t switch, you can change the next line to have: %switches t
  11. var %writtenlines 0 , %switches
  12. if (-* iswm $1) { var %switches %switches $+ $1 | tokenize 32 $2- }
  13. 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 }
  14. 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 }
  15. 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 }
  16. if ($1- == $null) { echo -ag $+($chr(3),0,$chr(44),4) *no action: Required filename is missing. /clip2disk -switches filename $chr(3) | return }
  17. if (($cb(0) == 1) && ($cb(0).len == 0)) { echo -ag $+($chr(3),0,$chr(44),4) *no action: Clipboard is empty $chr(3) | return }
  18. if (!$regsubex(%switches,/[^tb]/gi,\t)) {
  19. ; this method works beginning v7.52
  20. noop $cb(-1,,&var)
  21. ; this also works beginning v7.52 but is limited to 4150 chars
  22. ; noop $regsubex(foo,$cb(-1),,,&var)
  23. }
  24. else {
  25. var %cblines $cb(0)
  26. var %a 1
  27. if (b isin %switches) {
  28. while ((%a < %cblines) && ($remove($cb(%a),$chr(32),$chr(9)) == $null)) { inc %a }
  29. while ((%cblines > %a) && ($remove($cb(%cblines),$chr(32),$chr(9)) == $null)) { dec %cblines }
  30. var %writtenlines $calc(%cblines - %a + 1)
  31. }
  32. while (%a <= %cblines) {
  33. noop $cb(%a,,&t)
  34. var %i $bvar(&t,0)
  35. while ((t isin %switches) && (%i isnum 2-) && ($istok(32 9,$bvar(&t,%i),32))) { dec %i }
  36. if (%i) bcopy &var -1 &t 1 %i | bset &var -1 13 10 | inc %a
  37. }
  38. inc %a
  39. }
  40. var %len $bvar(&var,0)
  41. if (!%len) { echo 5 -ag Abort: clipboard was empty! | return }
  42. if ((a isin %switches) && ($file($1-).size isnum 1-)) {
  43. ; this section inserts $crlf if appending to existing file that doesn't already end with $crlf
  44. var %crlf 0
  45. if ($file($1-).size == 1) inc %crlf
  46. else { bread $qt($1-) $calc($file($1-).size -2) 2 &crlf | if ($bvar(&crlf,1-2) != 13 10) inc %crlf }
  47. if (%crlf) { bset -c &t 1 13 10 | bcopy &t -1 &var 1 -1 | bcopy -c &var 1 &t 1 -1 }
  48. }
  49. 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 }
  50. bwrite -c $qt($1-) $iif(a isin %switches,-1,0) %len &var
  51. 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)
  52. }
  53.  


Comments
No Comments.

Login to Comment.