REBOL [ Title: "Ingo Hohmanns Tools collection" Date: 6-9-99 File: %iho-tools.r Needs: 2.1.90 Author: "Ingo Hohmann" Email: ingo@2b1.de Purpose: {Collection of tools} Category: 'utility FIXME_LIST: [] ] ;I-am iho-tools.r ; The following two functions are an attempt at creating an automatic ; list of things, still to be done ; An empty FIXME_LIST block must be part of the scripts header to use this FIXME: func [ "Add a fixme string to the FIXME_LIST block" string ] [ if not found? find system/script/header/FIXME_LIST string [ append system/script/header/FIXME_LIST string ] ] FIXMES: func [ "Print all the scripts fixmes" /local fixme] [ foreach fixme system/script/header/FIXME_LIST [ print fixme ] ] ; ; Debugging object ; dbg: make object! [ debug: true on: func [] [ debug: true ] off: func [] [ debug: false ] out: func[ "print's value, if debug = true" value ] [ if debug [print ["" value]] ] ou: func[ "prin's value, if debug = true" value ] [ if debug [prin value] ] wait: func [ "waits for key press" /local k] [ if debug [ k: ask " Press " if k = "q" [make error! "exit"] ] ] ow: func [ "Prints value, and waits" value ] [ if debug [ out value wait ] ] assert: func[ "Tests, if test is true" [catch] test [block!] /named name [string!] "Name to show in message" ] [ if debug [ if not do test [ either named [throw make error! rejoin [{Assert "} name {" failed}]] [throw make error! rejoin ["Assert failed on: " test ]] ] ] ] ] do-sec: func [ "do with error trapping" todo "what to do" ] [ if error? err: try [ do todo true ] [ if confirm "Error, do you want to inspect? (y/N) " [ print mold disarm err ask "Press " ] ] ] ; The next two functions are for integer arithmetic, with none ; integer arguments div: func [ "integer division" dividend divisor ] [ to-integer (to-integer dividend) / to-integer divisor ] mod: func [ "integer remainder" dividend divisor ] [ (to-integer dividend) // to-integer divisor ] ; ; try to run a script, with words saved ; do-script: func [ {EXPERIMENTAL: run a script, global words will be saved before, and restored after it runs} rfile [file! block!] "File/block to do" words [block!] "block of words to save" /local svw] [ svw: save-words (words-of words) if error? try [do rfile] [print "Error in Script!"] do svw ] ; ; Text alignment ; ; author: Bohdan Lechnowsky align: function [ "Forms data into a specified number of columns with optional alignment" data length /left /right /center] [len] [ if right [ return head copy/part tail insert/dup head form data " " length (length * -1) ] if center [ data: head insert/dup head form data " " len: (length / 2) data: head insert/dup tail data " " len return copy/part at data ((length? data) / 2 - len + 1) length ] return copy/part head insert/dup tail form data " " length length ] ; author Ole Friis revert: function ["Reverts a series" ser [series!]] [len b] [ len: length? ser for i 1 to-integer (len / 2) 1 [ b: pick ser i poke ser i pick ser (len - i + 1) poke ser (len - i + 1) b ] ]