371 lines
8.0 KiB
Plaintext
371 lines
8.0 KiB
Plaintext
snippet hello "Hello World"
|
|
Hallo
|
|
endsnippet
|
|
|
|
snippet for "For-loop head"
|
|
for (${1:int i} = ${2:0}; ${3:i}; ${4:--i}) {
|
|
$5
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet fun "New Function"
|
|
${1:int} ${2:MyFunc} (${3:void}) {
|
|
`!p
|
|
if t[1].replace('static ', '') != "void":
|
|
snip.rv = f"{t[1].replace('static ', '')} rv = 0;"
|
|
else:
|
|
snip.rv = ""`
|
|
$5
|
|
`!p
|
|
if t[1].replace('static ', '') != "void":
|
|
snip.rv = f"return rv;"
|
|
else:
|
|
snip.rv = ""`
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet "(\w+)->fun" "Struct function" r
|
|
${1:int} ${2:Name} (`!p snip.rv = match.group(1)`* self, ${4:void}) {
|
|
`!p
|
|
if t[1].replace('static ', '') != "void":
|
|
snip.rv = f"{t[1].replace('static ', '')} rv = 0;"
|
|
else:
|
|
snip.rv = ""`
|
|
$5
|
|
`!p
|
|
if t[1].replace('static ', '') != "void":
|
|
snip.rv = f"return rv;"
|
|
else:
|
|
snip.rv = ""`
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet "self.(\w+)" "Struct call" r
|
|
`!p snip.rv = match.group(1)`(self$1)$0
|
|
endsnippet
|
|
|
|
snippet pfun "prototype for function" bA
|
|
/**
|
|
* @name $2
|
|
* @return $1
|
|
* @brief ${4: Description}
|
|
* `!p
|
|
params = t[3].replace(", ", ",").split(",")
|
|
rval = ""
|
|
for param in params:
|
|
if len(param.split(' ')) >= 2:
|
|
rval += f"\n *\t@param {param}"
|
|
snip.rv = rval`
|
|
*/
|
|
${1:int} ${2:MyFunc} (${3:void});
|
|
endsnippet
|
|
|
|
snippet exfun "New Function with Documentation"
|
|
/**
|
|
* @name $2
|
|
* @return $1
|
|
* @brief ${4: Description}
|
|
* `!p
|
|
params = t[3].replace(", ", ",").split(",")
|
|
rval = ""
|
|
for param in params:
|
|
if len(param.split(' ')) >= 2:
|
|
rval += f"\n *\t@param {param}"
|
|
snip.rv = rval`
|
|
*/
|
|
${1:int} ${2:MyFunc} (${3:void}) {
|
|
/* Returns ${5:void} */
|
|
`!p
|
|
if t[1].replace('static ', '') != "void":
|
|
snip.rv = f"{t[1].replace('static ', '')} {t[5]} = 0;"
|
|
else:
|
|
snip.rv = ""`
|
|
$6
|
|
`!p
|
|
if t[1].replace('static ', '') != "void":
|
|
snip.rv = f"return {t[5]};"
|
|
else:
|
|
snip.rv = ""`
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet while "while loop head"
|
|
for (;$1;) {
|
|
$2
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet "(\w+) = malloc" "Automativ malloc error implementation" rA
|
|
/* Allocate memory for `!p snip.rv = match.group(1)` */
|
|
`!p snip.rv = match.group(1)` = ($1*)malloc(sizeof(${1:int}) * $2);
|
|
if (!`!p snip.rv = match.group(1)`) {
|
|
/* Error */
|
|
(void)printf("malloc error on memory allocation of: `!p snip.rv = match.group(1)`!\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet "(\w+) = open" "Automatic open error implementation" r
|
|
/* create descriptor `!p snip.rv = match.group(1)` for file $1 */
|
|
`!p snip.rv = match.group(1)` = open(${1:"Filename"}, ${2:"MODE"});
|
|
if (-1 == `!p snip.rv = match.group(1)`) {
|
|
/* Error */
|
|
perror(${4:"open error"});
|
|
${5:exit(EXIT_FAILURE);}
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet swap "Swap two integer or numerical variables"
|
|
/* Swap Variables $1 and $2 */
|
|
${1:Var1} = $1 + ${2:Var2};
|
|
$2 = $1 - $2;
|
|
$1 = $1 - $2;
|
|
$0
|
|
endsnippet
|
|
|
|
snippet cast "adds cast" i
|
|
(${1:void})$0
|
|
endsnippet
|
|
|
|
global !p
|
|
def complete(t, opts):
|
|
if t:
|
|
opts = [m[len(t):] for m in opts if m.startswith(t)]
|
|
if len(opts) == 1:
|
|
return opts[0]
|
|
return '(' + '|'.join(opts) + ')'
|
|
endglobal
|
|
|
|
snippet printf "Cast printf result to 'void' if heturn value is unneeded" bA
|
|
(void)printf("$1"`!p
|
|
if "%" in t[1]:
|
|
snip.rv = ", "
|
|
else:
|
|
snip.rv = ""`$2);$0
|
|
endsnippet
|
|
|
|
snippet defstruct "define a new type with a struct" A
|
|
/* define struct $1 ${2:Explaination} */
|
|
typedef struct $1 $1;
|
|
struct $1 {
|
|
$3
|
|
};
|
|
endsnippet
|
|
|
|
snippet docomment "Meta Comment for Documenation" A
|
|
/*
|
|
* Filename: `!p snip.rv = fn`
|
|
* Author: ${1:Yannick Reiss}
|
|
* Project: ${2:Project Name}
|
|
* Copyright: ${3:None}
|
|
* Description: ${4:Funny module}
|
|
*
|
|
*/$0
|
|
endsnippet
|
|
|
|
snippet templatehsrm "Program templte from HSRM" A
|
|
/* include */
|
|
$1
|
|
|
|
/* makros */
|
|
$2
|
|
|
|
/* typ definitions */
|
|
$3
|
|
|
|
/* local function prototypes */
|
|
$4
|
|
|
|
/* global constants */
|
|
$5
|
|
|
|
/* global variables */
|
|
$6
|
|
|
|
/* local constants */
|
|
$7
|
|
|
|
/* local variables */
|
|
$8
|
|
|
|
/* global and local function implementations */
|
|
$0
|
|
endsnippet
|
|
|
|
snippet let+ "Declare and initialize Variable" A
|
|
${1:int} ${2:Variable} = ${3:0}; /* ${4:Description} */
|
|
$0
|
|
endsnippet
|
|
|
|
snippet let- "Declare Variable" A
|
|
${1:int} ${2:Variable}; /* ${3:Description} */
|
|
$0
|
|
endsnippet
|
|
|
|
snippet "close\((\w+)\)" "Automatic close error implementation" brA
|
|
/* Closing file `!p snip.rv = match.group(1)` */
|
|
if (close(`!p snip.rv = match.group(1)`)) {
|
|
/* Error */
|
|
perror("${1:Could not close file!}");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet write( "Automatic write error check" A
|
|
/* Write $3 bytes from $2 to file $1 */
|
|
if (-1 == write(${1:file}, ${2:buffer}, ${3:bytes})) {
|
|
/* Error */
|
|
perror("${4:Could not write to file!}");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet /* "comment" A
|
|
/* $1 */$0
|
|
endsnippet
|
|
|
|
snippet "read\((.+), (.+), (.+)\);" "auto read" brA
|
|
/* read `!p snip.rv = match.group(3)` from file `!p snip.rv = match.group(1)` intobuffer `!p snip.rv = match.goup(2)` */
|
|
if (-1 == read(`!p snip.rv = match.group(1)`, `!p snip.rv = match.group(2)`, `!p snip.rv = match.group(3)`)) {
|
|
/* Error */
|
|
perror("${1:Could not read to file!})";
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet "fstat\((.+), (.+)\);" "auto stat" brA
|
|
/* load information about file `!p snip.rv = match.group(1)` into struct `!p snip.rv = match.group(2)` */
|
|
if (fstat(`!p snip.rv = match.group(1)`, `!p snip.rv = match.group(2)`)) {
|
|
/* Error */
|
|
perror("${1:Could not fill struct with information!}");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet "ftruncate\((.+), (.+)\);" "ftruncate auto" brA
|
|
/* Resize file `!p snip.rv = match.group(1)` to size `!p snip.rv = match.group(2)` */
|
|
if (ftruncate(`!p snip.rv = match.group(1)`, `!p snip.rv = match.group(2)`)) {
|
|
/* Error */
|
|
perror("${1:Could not resize file!}j;
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet 'system\("(.+)"\);' "Automatic system error implementation" rA
|
|
/* run system command `!p snip.rv = match.group(1)` and check for success */
|
|
if (system("`!p snip.rv = match.group(1)`")) {
|
|
/* Error */
|
|
perror(${1:"Could not execute shell command!"});
|
|
${5:exit(EXIT_FAILURE);}
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet "if \(argc" "automatically add clarg check" A
|
|
/* check for right number of arguments */
|
|
if (argc ${1:!=} $2) {
|
|
/* Error */
|
|
perror("Wrong number of arguments");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet "(\w+) = fork" "Auto fork error implementation" rA
|
|
/* create new subproccess `!p snip.rv = match.group(1)` */
|
|
`!p snip.rv = match.group(1)` = fork();
|
|
if (`!p snip.rv = match.group(1)` < 0) {
|
|
/* Error */
|
|
perror("fork error on creating new subprocess '`!p snip.rv = match.group(1)`'.");
|
|
exit(EXIT_FAILURE);
|
|
} else if (!`!p snip.rv = match.group(1)`) {
|
|
/* fork runs from here */
|
|
${1:execve(proc, args, NULL)};
|
|
}
|
|
$0
|
|
endsnippet
|
|
|
|
snippet pthread_create "pthreadcreate auto implement" A
|
|
/* Creating thread $1 running function $3 */
|
|
if (pthread_create(${1:thread}, ${2:NULL}, ${3:function}, ${4:args})) {
|
|
perror("Could not create thread $1.");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet pthread_mutex_unlock "mutex" iA
|
|
/* Unlock mutex $1 */
|
|
if ( pthread_mutex_unlock(&${1:mutex}) ) {
|
|
perror("Could not unlock mutex $1.");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet pthread_cond_wait "condition wait" iA
|
|
/* wait for condition $1 on mutex $2 */
|
|
if ( pthread_cond_wait(&${1:Condition}, &${2:mutex}) ) {
|
|
perror("Could not wait for signal $1 on mutex $2.");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet pthread_cond_signal "condition signal" iA
|
|
/* Send signal $1 */
|
|
if ( pthread_cond_signal(&${1:signal}) ) {
|
|
perror("Could not send signal $1.");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet pthread_mutex_lock "mutex" iA
|
|
/* lock the mutex $1 */
|
|
if ( pthread_mutex_lock(&${1:mutex}) ) {
|
|
perror("Could not lock mutex $1.");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet pthread_join "join thread" iA
|
|
/* join the thread $1 */
|
|
if ( pthread_join(${1:thread}, ${2:NULL}) ) {
|
|
perror("Could not join thread $1.");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet sigaction "signal action" i
|
|
/* call function $2 on signal $1 */
|
|
if ( sigaction(${1:SIGINT}, ${2:&act}, ${3:&old}) ) {
|
|
perror("Could not change function of signal $1 to $2.");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet fflush "flush stdout" iA
|
|
/* flush stdout */
|
|
if ( fflush(stdout) ) {
|
|
perror("Could not flush stdout");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
endsnippet
|
|
|
|
snippet switch "Classic C switch statement" b
|
|
switch(${1:Expression}) {
|
|
case $3:
|
|
$4
|
|
break;$5
|
|
default:
|
|
$2
|
|
}$0
|
|
endsnippet
|