more c snippets and adjust commenting
This commit is contained in:
@ -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;'),
|
||||
}
|
||||
)
|
||||
),
|
||||
})
|
||||
|
Reference in New Issue
Block a user