' Small utility to format OxygenBasic Forum code snippets
' with Syntax Highlighting. (heading: OxygenBasic)
' Usage: Code_o2.exe should be copied into the directory of your code snippets.
'
' Select the code snippet and copy into the clipboard.
' In Windows Explorer call Code_o2.exe and the _.o2bas file will be created.
'
'
$ filename "Code_o2.exe"
includepath "$/inc/"
'#include "RTL32.inc"
'#include "RTL64.inc"
% CF_TEXT 1
string crlf = chr(13, 10)
! GlobalUnlock lib "kernel32.dll" (sys hMem) as bool
! GlobalLock lib "kernel32.dll" (sys hMem) as sys
! OpenClipboard lib "user32.dll" (sys hWndNewOwner) as bool
! CloseClipboard lib "user32.dll" () as bool
! GetClipboardData lib "user32.dll" (sys uFormat) as sys
' From \examples\system\clipboard.o2bas
'
'----------------------
'READING FROM CLIPBOARD
'======================
'Get exclusive access to the clipboard
'=====================================
OpenClipboard 0 'hwnd
'get data from clipboard
'=========================
h = GetClipboardData CF_TEXT
'Lock the handle.
'================
k = GlobalLock h
'Copy it
'=======
zstring z at k
string s=z
'Unlock the memory block
'=======================
GlobalUnlock h
'Release the Clipboard
'=====================
CloseClipboard '0 'hwnd
' Removing the linenumbers from captured text
' and create _.o2bas file in the current directory
int fin=len(s), num=0, pos1=1, pos2=1
string new_s = "", line, num1_s, num2_s
num1_s = str(num) & "."
nUM2_s = str(num+1) & "."
' small check
x=0
do
x += 1: if x = 10 then exit do
ns = str(x) & "."
pos2 = instr(1, s, ns)
if pos2 > 0 then
num = x-1: exit do
end if
end do
If left(s,2) <> "1." then
print "Line 1 does not begin with 1." crlf "File can be faulty / incomplete."
end if
while pos1 < fin
num += 1
num1_s = str(num) & "."
nUM2_s = str(num+1) & "."
pos1 = pos2 + len(num1_s)
pos2 = instr(pos1, s, num2_s)
if pos2 = 0 then exit while ' no number found
length = pos2-pos1
line = mid(s, pos1, length) & crlf
new_s &= line
wend
putfile("_.o2bas", new_s)
print "_.o2bas created." crlf crlf "Done"
done: