From f0fe14e289e79269eaf6460f843e6ffd38b2208e Mon Sep 17 00:00:00 2001 From: Squibid Date: Mon, 26 Jun 2023 11:42:29 -0400 Subject: more c snippets and adjust commenting --- lua/snippet/c.lua | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'lua/snippet') diff --git a/lua/snippet/c.lua b/lua/snippet/c.lua index c45f556..3c1e127 100644 --- a/lua/snippet/c.lua +++ b/lua/snippet/c.lua @@ -3,12 +3,15 @@ ls.add_snippets('c', { -- cond ? then : else statment i(1, 'cond'), t(' ? '), i(2, 'then'), t(' : '), i(3, 'else') }), + s('stdlibs', { - -- cond ? then : else statment + -- the normal stuff t('#include '), t({'', '#include '}) }), + s('die', { + -- message provieder when program is exiting t({ 'void die(const char *fmt, ...) {', '', 'va_list ap;', @@ -25,5 +28,30 @@ ls.add_snippets('c', { ' exit(1);', '}', }) - }) + }), + + s({ + name = 'get them opts!', + trig = 'getopt', + dscr = 'standard argument parser', + }, + fmta( + [[ + int c; + + while ((c = getopt(argc, argv, "")) != -1) { + switch (c) { + case '': break; + default: break; + } + } + ]], + { + OPTS = i(1, 'h'), + OPT1 = i(2, 'h'), + OPT1RUN = i(3, 'printf("help text\\n");'), + DEFRUN = i(4, 'printf("run %s -h for help\\n", argv[0]); return 1;'), + } + ) + ), }) -- cgit v1.2.1