summaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lua/snippet/c.lua32
1 files changed, 30 insertions, 2 deletions
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 <stdio.h>'),
t({'', '#include <stdlib.h>'})
}),
+
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, "<OPTS>")) != -1) {
+ switch (c) {
+ case '<OPT1>': <OPT1RUN> break;
+ default: <DEFRUN> 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;'),
+ }
+ )
+ ),
})