diff --git a/UltiSnips/c.snippets b/UltiSnips/c.snippets index 9f5d463..40e5c91 100644 --- a/UltiSnips/c.snippets +++ b/UltiSnips/c.snippets @@ -8,7 +8,7 @@ snippet fun "C function" b ${1:int} ${2:main}(${3:void}) { ${0} - `!p snip.rv = returnval(t[1])` + return `!p snip.rv = returnval(t[1], t[2])`; } endsnippet @@ -46,12 +46,12 @@ endsnippet snippet malloc "Allocate memory on the heap" -${1:TYPE} *${2:NAME} = ($1 *)malloc(sizeof(*$2)); +${1:TYPE} ${2:NAME} = ($1)malloc(sizeof(*$2)); endsnippet snippet calloc "Allocate memory on the heap" -${1:TYPE} *${2:NAME} = ($1 *)calloc(${3:N}, sizeof(*$2)); +${1:TYPE} ${2:NAME} = ($1)calloc(${3:N}, sizeof(*$2)); endsnippet @@ -60,3 +60,40 @@ snippet incl "Default includes" #include endsnippet + +snippet for "For loop" +for (${1:INITIALIZER}; ${2:TEST}; ${3:INCREMENTER}) \{ + ${4:#error "incomplete for loop"} +\} +endsnippet + + +snippet while "While loop" +while (${1:TEST}) \{ + ${2:#error "incomplete while loop"} +\} +endsnippet + + +snippet if "If-Then control construct" +if (${1:TEST}) \{ + ${2:#error "incomplete if branch"} +\} +endsnippet + + +snippet ite "If-Then-Else control construct" +if (${1:TEST}) \{ + ${2:#error "incomplete if branch"} +\} else \{ + ${3:#error "incomplete else branch"} +\} +endsnippet + + +snippet elif "Else-If control construct" +else if (${1:TEST}) \{ + ${2:#error "incomplete elif branch"} +\} +endsnippet + diff --git a/pythonx/ultisnips/c.py b/pythonx/ultisnips/c.py index ba66ce4..8a77f99 100644 --- a/pythonx/ultisnips/c.py +++ b/pythonx/ultisnips/c.py @@ -1,7 +1,10 @@ -def returnval(t): - if t == "void": +def returnval(rtype, fname): + if rtype == "void": return "" + if fname == "main": + return "EXIT_SUCCESS" + ret = { "int": "0", "float": "0.0", @@ -9,10 +12,10 @@ def returnval(t): "bool": "false" } - if t in ret.keys(): - return "return " + ret[t] + ";" + if rtype in ret.keys(): + return ret[rtype] else: - return "return NULL;" + return "NULL" def getNoteCandidates(t): options = ["TODO", "FIXME", "XXX"] @@ -21,6 +24,6 @@ def getNoteCandidates(t): if len(options) == 1: return options[0] - + return "[" + ",".join(options) + "]"