From c157df9c800ce22e64bcb4c6787699a4b85612fa Mon Sep 17 00:00:00 2001 From: joten Date: Fri, 12 Feb 2016 20:39:04 +0100 Subject: [PATCH] revised main --- src/Bar.ahk | 4 +-- src/Config.ahk | 2 +- src/Lib.ahk | 44 +++++++++++++++++++++++++ src/Main.ahk | 88 ++++++-------------------------------------------- 4 files changed, 57 insertions(+), 81 deletions(-) diff --git a/src/Bar.ahk b/src/Bar.ahk index 8d7d29d..933755c 100644 --- a/src/Bar.ahk +++ b/src/Bar.ahk @@ -201,13 +201,13 @@ Bar_cmdGuiEnter: Bar_cmdGuiIsVisible := False Gui, Cancel WinActivate, ahk_id %Bar_aWndId% - Main_evalCommand(Bar_#0_#0) + Cmd_eval(Bar_#0_#0) Bar_#0_#0 := "" } Else If (A_GuiControl = "Bar_#0_#1") { Gui, Submit, NoHide Debug_logMessage("DEBUG[6] Bar_cmdGuiEnter; command: " . Bar_#0_#1, 6) Loop, Parse, Bar_#0_#1, `n, `r - Main_evalCommand(A_LoopField) + Cmd_eval(A_LoopField) } Return diff --git a/src/Config.ahk b/src/Config.ahk index f85105e..d5ba92e 100644 --- a/src/Config.ahk +++ b/src/Config.ahk @@ -261,7 +261,7 @@ Config_redirectHotkey(key) If (key = Config_hotkey_#%A_index%_key) { Debug_logMessage("DEBUG[1] Config_redirectHotkey: Found " Config_hotkey_#%A_index%_key " -> " Config_hotkey_#%A_index%_command, 1) - Main_evalCommand(Config_hotkey_#%A_index%_command) + Cmd_eval(Config_hotkey_#%A_index%_command) Break } } diff --git a/src/Lib.ahk b/src/Lib.ahk index 8a90915..ad2a455 100644 --- a/src/Lib.ahk +++ b/src/Lib.ahk @@ -9,6 +9,50 @@ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ +Cmd_eval(s) { + Log_msg("**Command_eval**: '" . s . "'", 5) + c := SubStr(s, 1, 5) + If (s = "ExitApp") + ExitApp + Else If (s = "Reload") + Reload + Else If (c = "Send ") + Send % SubStr(s, 6) + Else If (c = "Run, ") { + parameters := SubStr(s, 6) + StringReplace, parameters, parameters, `,%A_Space%, `,, All + StringSplit, p, parameters, `, + If (p0 = 1) + Run, %p1% + Else If (p0 = 2) + Run, %p1%, %p2% + Else If (p0 = 3) + Run, %p1%, %p2%, %p3% + Else If (p0 = 4) + Run, %p1%, %p2%, %p3%, %p4% + } Else { + i := InStr(s, "(") + j := InStr(s, ")", False, i) + If i And j { + fun := SubStr(s, 1, i - 1) + arguments := SubStr(s, i + 1, j - (i + 1)) + StringReplace, arguments, arguments, %A_Space%, , All + StringSplit, arg, arguments, `, + If (arg0 = 0) + %fun%() + Else If (arg0 = 1) + %fun%(arg1) + Else If (arg0 = 2) + %fun%(arg1, arg2) + Else If (arg0 = 3) + %fun%(arg1, arg2, arg3) + Else If (arg0 = 4) + %fun%(arg1, arg2, arg3, arg4) + } + } + Log_msg("Command evaluated '" . s . "'", 4) +} + Int_min(a, b) { Return, a < b ? a : b } diff --git a/src/Main.ahk b/src/Main.ahk index f53c53e..4f31b14 100644 --- a/src/Main.ahk +++ b/src/Main.ahk @@ -64,84 +64,21 @@ Main_cleanup: Debug_logMessage("====== Exiting bug.n ======", 0) ExitApp -Main_evalCommand(command) -{ - type := SubStr(command, 1, 5) - If (type = "Run, ") - { - parameters := SubStr(command, 6) - If InStr(parameters, ", ") - { - StringSplit, parameter, parameters, `, - If (parameter0 = 2) - { - StringTrimLeft, parameter2, parameter2, 1 - Run, %parameter1%, %parameter2% - } - Else If (parameter0 > 2) - { - StringTrimLeft, parameter2, parameter2, 1 - StringTrimLeft, parameter3, parameter3, 1 - Run, %parameter1%, %parameter2%, %parameter3% - } - } - Else - Run, %parameters% - } - Else If (type = "Send ") - Send % SubStr(command, 6) - Else If (command = "Reload") - Reload - Else If (command = "ExitApp") - ExitApp - Else - { - i := InStr(command, "(") - j := InStr(command, ")", False, i) - If i And j - { - functionName := SubStr(command, 1, i - 1) - functionArguments := SubStr(command, i + 1, j - (i + 1)) - StringReplace, functionArguments, functionArguments, %A_SPACE%, , All - StringSplit, functionArgument, functionArguments, `, - Debug_logMessage("DEBUG[1] Main_evalCommand: " functionName "(" functionArguments ")", 1) - If (functionArgument0 = 0) - %functionName%() - Else If (functionArgument0 = 1) - %functionName%(functionArguments) - Else If (functionArgument0 = 2) - %functionName%(functionArgument1, functionArgument2) - Else If (functionArgument0 = 3) - %functionName%(functionArgument1, functionArgument2, functionArgument3) - Else If (functionArgument0 = 4) - %functionName%(functionArgument1, functionArgument2, functionArgument3, functionArgument4) - } - } -} - Main_help: Run, explore %Main_docDir% Return -;; Create bug.n-specific directories. -Main_makeDir(dirName) { - IfNotExist, %dirName% - { - FileCreateDir, %dirName% - If ErrorLevel - { - MsgBox, Error (%ErrorLevel%) when creating '%dirName%'. Aborting. - ExitApp - } - } - Else - { - FileGetAttrib, attrib, %dirName% - IfNotInString, attrib, D - { - MsgBox, The file path '%dirName%' already exists and is not a directory. Aborting. +Main_makeDir(name) { + q := FileExist(name) + If Not q { + FileCreateDir, %name% + If ErrorLevel { + MsgBox, Error (%ErrorLevel%) creating '%name%'. Aborting. ExitApp } + } Else If Not InStr(q, "D") { + MsgBox, The filepath '%name%' already exists and is not a directory. Aborting. + ExitApp } } @@ -157,15 +94,10 @@ Main_setup() { Main_docDir .= "\.." Main_docDir .= "\doc" - Main_logFile := "" - Main_dataDir := "" - Main_autoLayout := "" - Main_autoWindowState := "" - EnvGet, winAppDir, APPDATA - If (Main_appDir = "") Main_appDir := winAppDir . "\bug.n" + Main_logFile := Main_appDir . "\log.txt" Log_file := Main_appDir . "\log.md" Main_dataDir := Main_appDir . "\data"