/******************************************************************************/ /* */ /* svg2jdor.rex - An SVG to JDOR commands */ /* ====================================== */ /* */ /* This program is part of the Rexx Parser package */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* Copyright (c) 2024-2026 Josep Maria Blasco */ /* */ /* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) */ /* */ /* Date Version Details */ /* -------- ------- --------------------------------------------------------- */ /* 20261013 0.7 First version */ /* */ /******************************************************************************/ /* */ /* [rexx] svg2jdor [options] drawing.svg [macro.jdor] */ /* */ /* Writes the JDOR commands (JDOR: Rony G. Flatscher's drawing command */ /* handler in BSF4ooRexx850) that draw an SVG: a macro, one command per line, */ /* by default beside the SVG with the extension .jdor; "-" writes it to the */ /* standard output. --rexx writes instead a Rexx program (.rxj) that draws */ /* it with JDOR and shows it. What has no JDOR equivalent is listed. See */ /* svg2jdor.cls. */ /* */ /* Options: */ /* */ /* -h, --help this help */ /* -q, --quiet do not list what was left out */ /* --rexx a Rexx program (.rxj) instead of a macro */ /* */ /******************************************************************************/ CLIhelper = InitCLI() myName = CLIhelper~name myHelp = CLIhelper~help args = CLIhelper~args quiet = 0 rexx = 0 files = .Array~new Loop i = 1 To args~items a = args[i] Select Case Lower(a) When "-h", "--help", "-?" Then Signal Help When "-q", "--quiet" Then quiet = 1 When "--rexx" Then rexx = 1 Otherwise Do If a~left(1) == "-", a \== "-" Then Call Fail "unknown option '"a"'" files~append(a) End End End If files~items == 0 | files~items > 2 Then Signal Help in = files[1] If \SysFileExists(in) Then Call Fail "'"in"' does not exist" s = .Stream~new(in) lines = s~arrayIn s~close base = in dot = base~lastPos(".") If dot > base~lastPos("/"), dot > base~lastPos("\") Then base = base~left(dot - 1) If files~items == 2 Then out = files[2] Else out = base || rexx~?(".rxj", ".jdor") name = in~substr(Max(in~lastPos("/"), in~lastPos("\")) + 1) conv = .SVG.JDOR~new cmds = conv~convert(lines, name) If rexx Then Do prog = base~substr(Max(base~lastPos("/"), base~lastPos("\")) + 1) cmds = JDORProgram(cmds, prog) End If out == "-" Then Do line Over cmds; Say line; End Else Do Call SysFileDelete out o = .Stream~new(out) o~open("Write Replace") o~arrayOut(cmds) o~close If \quiet Then Say myName": wrote" out End If \quiet Then Do note Over conv~notes .Error~lineOut(myName": left out:" note) End Exit 0 Help: Say myName "[-q] [--rexx] drawing.svg [macro.jdor | -]" Say "Writes the JDOR commands that draw an SVG. Documentation:" myHelp Exit 1 Fail: .Error~lineOut(myName":" Arg(1)) Exit 1 ::Requires "parser/CLISupport.cls" ::Requires "svg2jdor.cls"