From ab08409bf562ecfacf7cd87812c8f9c0e043c457 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sat, 29 Dec 2018 23:47:06 -0500 Subject: [PATCH] fixed a bug in pickfile and added debug tracing to the fetch command --- TODO.md | 4 ++-- bin/pickfile | 2 +- inc/stdc.h | 2 +- src/fetch.c | 35 +++++++++++++++++++++++++++++++---- 4 files changed, 35 insertions(+), 8 deletions(-) mode change 100644 => 100755 bin/pickfile diff --git a/TODO.md b/TODO.md index 6360bb9..8ad4946 100644 --- a/TODO.md +++ b/TODO.md @@ -3,13 +3,13 @@ ## VERIFYING * paste of selection doesnt occur till next event +* simultaneously write and read in tide sub commands ## STAGING +* initialize pick query from argument * group by hostname or group env var in registrar -* add debug Trace to fetch command * daemonize registrar and tide executables -* simultaneously write and read in tide sub commands * Ctrl+D should not pass tag name as arg when executing tag commands * 'Get' tag with argument currently segfaults * registrar doesnt match open windows when new file created and is then opened for edit or line number diff --git a/bin/pickfile b/bin/pickfile old mode 100644 new mode 100755 index cd483ac..e04c77d --- a/bin/pickfile +++ b/bin/pickfile @@ -6,4 +6,4 @@ fi export PICKTITLE="Pick File ($PWD)" file="$(find $1 -not -path '*/\.*' -type f | sed 's|^\./||' | pick)" -edit "$file" +[ "" != "$file" ] && edit "$file" diff --git a/inc/stdc.h b/inc/stdc.h index d42b1df..12f80a0 100644 --- a/inc/stdc.h +++ b/inc/stdc.h @@ -99,7 +99,7 @@ static inline char* _getopt_(int* p_argc, char*** p_argv) { ) { \ int brk_; char argc_ , **argv_, *optarg_; \ if (argv[0][1] == '-' && !argv[0][2]) { \ - argv++, argc--; break; \ + (void)optarg_; argv++, argc--; break; \ } \ for (brk_=0, argv[0]++, argv_=argv; argv[0][0] && !brk_; argv[0]++) { \ if (argv_ != argv) break; \ diff --git a/src/fetch.c b/src/fetch.c index 19e21cc..931e45d 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -8,6 +8,8 @@ #include #include +char* ARGV0; + typedef struct { enum { COMPLETE=0, MATCHES, IS, ISSET, ISDIR, ISFILE, @@ -177,17 +179,42 @@ void usage(char* pname) { exit(1); } +char* type2str(int type) { + switch (type) { + case COMPLETE: return "COMPLETE"; + case MATCHES: return "MATCHES"; + case IS: return "IS"; + case ISSET: return "ISSET"; + case ISDIR: return "ISDIR"; + case ISFILE: return "ISFILE"; + case SET: return "SET"; + case UNSET: return "UNSET"; + case FINDFILE: return "FINDFILE"; + case EXEC: return "EXEC"; + case LAUNCH: return "LAUNCH"; + } + return "UNKNOWN"; +} + int main(int argc, char** argv) { - if (argc != 2) usage(argv[0]); - setenv("data", argv[1], 1); + int debug = 0; + OPTBEGIN { case 'd': debug = 1; } OPTEND; + + if (!argc) usage(ARGV0); + setenv("data", *argv, 1); + + if (debug) + printf("Data: '%s'\n", *argv); for (unsigned int i = 0; i < nelem(BuiltinRules); i++) { Rule* rule = BuiltinRules[i]; + if (debug) + printf("\nRuleset %d:\n", i); for (; rule->type != COMPLETE; rule++) { - //printf("%d '%s' '%s'\n", rule->type, rule->arg1, rule->arg2); + if (debug) + printf(" %s '%s' '%s'\n", type2str(rule->type), rule->arg1, rule->arg2); if (!apply_rule(rule)) break; } - //puts(""); if (rule->type == COMPLETE) exit(0); } -- 2.51.0