update c snippets
This commit is contained in:
parent
9fe574d716
commit
1ce695d4db
@ -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 <stdio.h>
|
||||
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
|
||||
|
||||
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user