author | Olivier Brunel
<jjk@jjacky.com> 2023-06-17 16:29:52 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-06-17 16:29:52 UTC |
parent | 291b2642f7b88339ad4d6c880f233b5bcadac74d |
.gitignore | +1 | -0 |
meta/deps/limb/configure | +1 | -0 |
meta/deps/limb/files | +0 | -0 |
meta/deps/limb/git | +1 | -0 |
meta/deps/limb/incdir | +1 | -0 |
meta/deps/limb/version | +1 | -0 |
project.mk | +1 | -7 |
src/doc/gtkscrollbar.1.md | +44 | -0 |
src/gtkscrollbar/+limb | +0 | -0 |
src/gtkscrollbar/gtkscrollbar.c | +95 | -0 |
diff --git a/.gitignore b/.gitignore index 551e26d..0024ce4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /src/include/config.h /deps /build +/gtkscrollbar diff --git a/meta/deps/limb/configure b/meta/deps/limb/configure new file mode 100644 index 0000000..1661455 --- /dev/null +++ b/meta/deps/limb/configure @@ -0,0 +1 @@ +--no-doc --no-shared diff --git a/meta/deps/limb/files b/meta/deps/limb/files new file mode 100644 index 0000000..e69de29 diff --git a/meta/deps/limb/git b/meta/deps/limb/git new file mode 100644 index 0000000..109fd23 --- /dev/null +++ b/meta/deps/limb/git @@ -0,0 +1 @@ +git://lila.oss/limb.git diff --git a/meta/deps/limb/incdir b/meta/deps/limb/incdir new file mode 100644 index 0000000..30b990f --- /dev/null +++ b/meta/deps/limb/incdir @@ -0,0 +1 @@ +src/liblimb/include diff --git a/meta/deps/limb/version b/meta/deps/limb/version new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/meta/deps/limb/version @@ -0,0 +1 @@ +0.0.1 diff --git a/project.mk b/project.mk index 0d8c07b..9f39177 100644 --- a/project.mk +++ b/project.mk @@ -1,7 +1 @@ -$(error You need to edit project.mk) - -# binaries -BINS = - -# librairies -LIBS = +BINS = gtkscrollbar diff --git a/src/doc/gtkscrollbar.1.md b/src/doc/gtkscrollbar.1.md new file mode 100644 index 0000000..40bc023 --- /dev/null +++ b/src/doc/gtkscrollbar.1.md @@ -0,0 +1,44 @@ +% gtkscrollbar +% gtkscrollbar(1) + +# NAME + +gtkscrollbar - FIXME: desc here + +# SYNOPSIS + +*gtkscrollbar* [*-q*] [*-v*] [*--debug* [[@[\`level\`]:]+\`FD\`|\`FILE\`]] [*-O* [@[\`level\`]:]+\`FD\`|\`FILE\`] + +# OPTIONS + +: *--debug* [[@[\`level\`]:]+\`FD\`|\`FILE\`] +<inc autoopt_debug.md> +<inc autoopt_logdbg_level.md> + +<inc opt_help.md> + +: *-O*, *--log-file* [@[\`level\`]:]+\`FD\`|\`FILE\` +<inc autoopt_log.md> +<inc autoopt_logdbg_level.md> + +: *-q*, *--quiet* +<inc autoopt_quiet.md> + +: *-v*, *--verbose* +<inc autoopt_verbose.md> + +<inc opt_version.md> + +# DESCRIPTION + +*gtkscrollbar* is... + +<inc bugs.md> + +# REPOSITORY + +You can find the latest about *gtkscrollbar* from its official site at https://lila.oss/gtkscrollbar +Latest source code can be browsed online at https://lila.oss/code/gtkscrollbar; or you can clone its +[git](1) repo from git://lila.oss/gtkscrollbar.git + +<inc author.md> diff --git a/src/gtkscrollbar/+limb b/src/gtkscrollbar/+limb new file mode 100644 index 0000000..e69de29 diff --git a/src/gtkscrollbar/gtkscrollbar.c b/src/gtkscrollbar/gtkscrollbar.c new file mode 100644 index 0000000..5f0fa4c --- /dev/null +++ b/src/gtkscrollbar/gtkscrollbar.c @@ -0,0 +1,95 @@ +/* This file is part of gtkscrollbar https://lila.oss/gtkscrollbar + * Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <fcntl.h> /* AT_FDCWD */ +#include <limb/autoopt.h> +#include <limb/exitcode.h> +#include <limb/loadopt.h> +#include <limb/output.h> +#include <limb/stralloc.h> +#include "config.h" + +const char *PROG = "gtkscrollbar"; + +struct ctx { + stralloc sa; + size_t fileoff; +}; + +enum { + OPTID_VERSION = OPTID_FIRST, + OPTID_DEBUG, + /* arguments */ + ARGID_FILE, +}; + +static void +parse_cmdline(int argc, const char *argv[], int dirfd, const char *confdir, struct ctx *ctx) +{ + const char usage[] = "[-h] [OPTION..] FILE"; + const struct option options[] = { + OPTION_ARG_OPT( 0 , "debug", OPT_SKIP, OPTID_DEBUG), + OPTION_ARG_NONE('h', "help", OPT_SKIP, OPTID_SHORTOPT), + OPTION_ARG_REQ( 'O', "log-file", 0, OPTID_SHORTOPT), + OPTION_ARG_NONE('q', "quiet", 0, OPTID_SHORTOPT), + OPTION_ARG_NONE('v', "verbose", 0, OPTID_SHORTOPT), + OPTION_ARG_NONE( 0 , "version", OPT_SKIP, OPTID_VERSION), + LOADOPT_ARGUMENTS, + ARGUMENT_REQ( "file", OPT_PATH, ARGID_FILE), + LOADOPT_DONE + }; + struct loadopt lo = LOADOPT_ZERO; + + int c; + while ((c = loadopt(&ctx->sa, argc, argv, options, dirfd, confdir, 0, &lo))) switch (c) { + case OPTID_DEBUG: + if (!autoopt_debug(&options[LO_IDX(&lo)], LO_ARG(&lo))) + dieusage(EX_USAGE, usage); + break; + case 'h': + diehelp(0, usage, +" --debug [[@[level]:]+FD|FILE] Enable debug output (to FD|FILE)\n" +" -O, --output [@[level]:]+FD|FILE Set output log to FD|FILE\n" +"\n" +" -q, --quiet Enable quiet mode\n" +" -v, --verbose Enable verbose mode\n" +"\n" +" -h, --help Show this help screen and exit\n" +" --version Show version information and exit\n" +); + case 'O': + if (!autoopt_log(&options[LO_IDX(&lo)], LO_ARG(&lo))) + dieusage(EX_USAGE, usage); + break; + case 'q': + autoopt_quiet(&options[LO_IDX(&lo)], LO_ARG(&lo)); + break; + case 'v': + autoopt_verbose(&options[LO_IDX(&lo)], LO_ARG(&lo)); + break; + case OPTID_VERSION: + dieversion(GTKSCROLLBAR_VERSION, "2023", GTKSCROLLBAR_CURYEAR, GTKSCROLLBAR_AUTHOR, GTKSCROLLBAR_URL, NULL); + + case ARGID_FILE: + ctx->fileoff = LO_OFF(&lo); + break; + + case -1: + dieusage(EX_USAGE, usage); + default: + die(EX_SOFTWARE, "unexpected return value ", PMINT(c), " from loadopt"); + }; +} + +int +main(int argc, const char *argv[]) +{ + struct ctx ctx = { STRALLOC_ZERO, 0 }; + const char confdir[] = "/etc/gtkscrollbar/conf"; + parse_cmdline(argc, argv, AT_FDCWD, confdir, &ctx); + + out("file is ", ESC, ctx.sa.s + ctx.fileoff, ESC); + + stralloc_free(&ctx.sa); + return 0; +}