From: Michael D. Lowis Date: Wed, 28 Mar 2018 01:30:35 +0000 (-0400) Subject: added command line flags for changing settings X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=5e48317b0a4939229052b3ba1704f91c4194d4bb;p=projs%2Ftide.git added command line flags for changing settings --- diff --git a/inc/edit.h b/inc/edit.h index c16b6e8..4b8d67e 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -184,14 +184,15 @@ void job_start(char** cmd, char* data, size_t ndata, View* dest); /* Configuration Data *****************************************************************************/ +enum { OFF = 0, ON = 1 }; + typedef struct { int fg, bg; } CPair; -extern char TagString[], FontString[]; +extern char *TagString, *FontString; +extern CPair Colors[28]; extern int Palette[16]; -extern int WinWidth, WinHeight, LineSpacing, RulerPos, Timeout, TabWidth, ScrollBy, +extern int WinWidth, WinHeight, LineSpacing, Timeout, TabWidth, ScrollBy, ClickTime, MaxScanDist, Syntax, CopyIndent, TrimOnSave, ExpandTabs, DosLineFeed; -extern CPair Colors[28]; - enum { /* Color Variables */ ClrScrollNor = 0, ClrGutterNor, ClrGutterSel, ClrStatusNor, ClrTagsNor, ClrTagsSel, ClrTagsCsr, ClrEditNor, ClrEditSel, ClrEditCsr, ClrEditRul, diff --git a/lib/config.c b/lib/config.c index f42c8f7..a3a588c 100644 --- a/lib/config.c +++ b/lib/config.c @@ -4,8 +4,6 @@ #include #include -enum { OFF = 0, ON = 1 }; - #ifdef __MACH__ #define FONT "Monaco:size=10" #define LNSPACE 0 @@ -14,14 +12,13 @@ enum { OFF = 0, ON = 1 }; #define LNSPACE 1 #endif -char TagString[] = "Del Put Undo Redo Find "; -char FontString[] = FONT; +char* TagString = "Del Put Undo Redo Find "; +char* FontString = FONT; int /* Integer config options */ WinWidth = 640, WinHeight = 480, LineSpacing = LNSPACE, - RulerPos = 80, Timeout = 50, TabWidth = 4, ScrollBy = 4, diff --git a/tide.c b/tide.c index e95c44b..bcdee93 100644 --- a/tide.c +++ b/tide.c @@ -615,8 +615,38 @@ static void oninput(Rune rune) { view_insert(win_view(FOCUSED), true, rune); } + +char* ARGV0; +static void usage(void) { + printf( + "Usage: %s [FLAGS] [FILE]\n" + "\n -S 0,1 Enable/disable syntax highlighting" + "\n -I 0,1 Enable/disable automatic indenting" + "\n -W 0,1 Enable/disable trimming whitespace on save" + "\n -E 0,1 Enable/disable expanding tabs to spaces" + "\n -N 0,1 Enable/disable dos line ending style" + "\n -F str Set the font to use" + "\n -T str String to use for the tags region" + "\n -C str Set the shell to use for command execution\n", + ARGV0); + exit(1); +} + #ifndef TEST int main(int argc, char** argv) { + #define BOOLARG() (EOPTARG(usage()), optarg_[0] == '0' ? 0 : 1) + #define STRARG() (EOPTARG(usage())) + OPTBEGIN { + case 'S': Syntax = BOOLARG(); break; + case 'I': CopyIndent = BOOLARG(); break; + case 'W': TrimOnSave = BOOLARG(); break; + case 'E': ExpandTabs = BOOLARG(); break; + case 'N': DosLineFeed = BOOLARG(); break; + case 'F': FontString = STRARG(); break; + case 'T': TagString = STRARG(); break; + case 'C': ShellCmd[0] = STRARG(); break; + } OPTEND; + /* setup the shell */ if (!ShellCmd[0]) ShellCmd[0] = getenv("SHELL"); if (!ShellCmd[0]) ShellCmd[0] = "/bin/sh"; @@ -625,10 +655,6 @@ int main(int argc, char** argv) { win_init(ondiagmsg); x11_window("tide", WinWidth, WinHeight); - /* open all but the last file in new instances */ - for (argc--, argv++; argc > 1; argc--, argv++) - cmd_execwitharg(CMD_TIDE, *argv); - /* if we still have args left we're going to open it in this instance */ if (*argv) view_init(win_view(EDIT), *argv, ondiagmsg);