#!/usr/bin/env rexx /*************************************************************************** * Rexx Address Book * * * * A simple application for storing, maintaining, and browsing contact * * information. * * * * Backend: Object Rexx with unix system, and sqlite extensions. * * Frontend: Object Rexx with ncurses extensions. * **************************************************************************/ signal on HALT name ProgramHalt signal on ERROR name ProgramError .environment~home = SysGetpwuid(SysGetuid(), "d") .environment['STOPNOW'] = 0 rc = setEnv(.nil) if rc \= 0 then do say "Configuration failed." exit rc end app = .AddressBookApp~new() app~run() Do forever if .environment['STOPNOW'] = 1 then do app~cleanup() /* Clean up before exiting */ call SysCls exit 0 end app~reloop() end Exit signal on ERROR name ProgramError ::CLASS AddressBookApp PUBLIC ::METHOD Init expose ui db db = .AddressBookDB~new() ui = .AddressBookUI~new(db) return ::method run expose ui ui~initialize ui~mainLoop ui~cleanup return ::method reloop expose ui ui~mainLoop RETURN ::method cleanup expose db db~closeDb() return /******** HELPER FUNCTIONS ****************/ /* Configuration Retrieval */ ::ROUTINE setConfig use arg filespec file = .Stream~new(filespec) json_string = "" do file~lines json_string = json_string||file~lineIn end json_config = .json~new()~fromJSON(json_string) Do index over json_config~allIndexes val = json_config[index] INTERPRET '.environment~'index' = "'val'"' END return 0 /** SET ENV **/ ::ROUTINE setEnv use arg configFilePath rc = 0 .environment~home = SysGetpwuid(SysGetuid(), "d") if configFilePath = .nil | configFilePath = '' then do configFilePath = .environment~home||"/.config/rexx-address-book/config.json" /* assume its in the same location */ Say "No config specified. Default will be used at : "configFilePath END if SysFileExists(configFilePath) then do call setConfig(configFilePath) /* set up the database config */ IF .environment~dbFile = .nil then do .environment~dbFile = .environment~home||"/.local/share/rexx-address-book/rexx-address-book/contacts.db" say "Config has no detabase specified. A default will be created at: ".environment~dbFile END IF \SysFileExists(.environment~dbFile) then do say "Specified database not found. A new database will be created." END END else do say "No config file Not Found at: "configFilePath rc = -1 END return rc ProgramError: say 'An error has occurred' say rc say signal Exit rc /** External Libraries **/ ::requires 'appdb.cls' ::requires 'appui.cls' ::requires 'utils.rex' ::requires 'ooSQLite.cls' ::requires "rxunixsys" LIBRARY ::requires 'ncurses.cls' ::requires 'json.cls'