361 lines
9.6 KiB
JSON
361 lines
9.6 KiB
JSON
{
|
|
"for": {
|
|
"prefix": "for",
|
|
"body": [
|
|
"for (${1:size_t} ${2:i} = ${3:0}; $2 < ${4:length}; $2++) {",
|
|
"\t$0",
|
|
"}"
|
|
],
|
|
"description": "Code snippet for 'for' loop"
|
|
},
|
|
"_FOREACH": {
|
|
"prefix": "_FOREACH",
|
|
"body": [
|
|
"#define foreach(item, array) \\",
|
|
"\tfor(int keep = 1, \\",
|
|
"\tcount = 0,\\",
|
|
"\tsize = sizeof (array) / sizeof *(array); \\",
|
|
"\tkeep && count != size; \\",
|
|
"\tkeep = !keep, count++) \\",
|
|
"\tfor(item = (array) + count; keep; keep = !keep)"
|
|
],
|
|
"description": "foreach loop C"
|
|
},
|
|
"*": {
|
|
"prefix": "*",
|
|
"body": ["/* $0 */"],
|
|
"description": "Block comment"
|
|
},
|
|
"glfw330win": {
|
|
"prefix": "glfw330win",
|
|
"body": [
|
|
"if (!glfwInit()) {",
|
|
"log_warn(\"GLFW failed\");",
|
|
"glfwTerminate();",
|
|
"return 1;",
|
|
"}",
|
|
"glfwWindowHint(GLFW_SAMPLES, 4);",
|
|
"glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);",
|
|
"glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);",
|
|
"glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);"
|
|
],
|
|
"description": "Glfw window hint for opengl v3.3"
|
|
},
|
|
"gl_vertex_arr": {
|
|
"prefix": "gl_vertex_arr",
|
|
"body": [
|
|
"glGenVertexArrays(${1:size}, &$2);",
|
|
"glBindVertexArray($2);"
|
|
],
|
|
"description": "GL generate vertex array"
|
|
},
|
|
"gl_vertex_buffer": {
|
|
"prefix": "gl_vertex_buffer",
|
|
"body": [
|
|
"glGenBuffers(${1:1}, &$2);",
|
|
"glBindBuffer(${3:buffer_type}, $2);",
|
|
"glBufferData($3, sizeof($4), $4, $5)"
|
|
],
|
|
"description": "gl generate buffer"
|
|
},
|
|
"DBG": {
|
|
"prefix": "DBG",
|
|
"body": ["#define WHERE fprintf(stderr,\"[LOG]%s:%d\\n\",__FILE__,__LINE__);"],
|
|
"description": "Debug code line"
|
|
},
|
|
"forr": {
|
|
"prefix": "forr",
|
|
"body": [
|
|
"for (${1:size_t} ${2:i} = ${3:length} - 1; $2 >= ${4:0}; $2--) {",
|
|
"\t$0",
|
|
"}"
|
|
],
|
|
"description": "Code snippet for reverse 'for' loop"
|
|
},
|
|
"mod": {
|
|
"prefix": "_MOD",
|
|
"body": ["#define MOD(N,M)\t((N)%(M) < 0 ? (N)%(M) + (M) : (N)%(M))\n"],
|
|
"description": "mod of N,M"
|
|
},
|
|
"between": {
|
|
"prefix": "_BETWEEN",
|
|
"body": ["#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))\n"],
|
|
"description": "x is between a, b"
|
|
},
|
|
"length" : {
|
|
"prefix": "_LENGTH",
|
|
"body": ["#define LENGTH(x) sizeof(x)/sizeof(x[0])\n"],
|
|
"description": "Array size macro"
|
|
},
|
|
"max" : {
|
|
"prefix": "_MAX",
|
|
"body": ["#define MAX(x,y) (x) > (y) ? (x) : (y)","$0"],
|
|
"description": "Get max element"
|
|
},
|
|
"min" : {
|
|
"prefix": "_MIN",
|
|
"body": ["#define MIN(x,y) (x) < (y) ? (x) : (y)","$0"],
|
|
"description": "Get min element"
|
|
},
|
|
"getbit": {
|
|
"prefix": "_GETBIT",
|
|
"body": ["#define GETBIT(x,i) (x&(1<<i)))", "$0"],
|
|
"description": "Get bit of number"
|
|
},
|
|
"safemin": {
|
|
"prefix": "_SAFEMIN",
|
|
"body": [
|
|
"#define MIN(a, b) ({\\",
|
|
" __typeof__ (a) _a = (a); \\",
|
|
" __typeof__ (b) _b = (b); \\",
|
|
" _a < _b ? _a : _b; })"
|
|
],
|
|
"description": "Typesafe min"
|
|
},
|
|
"safemax": {
|
|
"prefix": "_SAFEMAX",
|
|
"body": [
|
|
"#define MAX(a, b) ({\\",
|
|
" __typeof__ (a) _a = (a); \\",
|
|
" __typeof__ (b) _b = (b); \\",
|
|
" _a < _b ? _a : _b; })"
|
|
],
|
|
"description": "Typesafe min"
|
|
},
|
|
"#ifdef": {
|
|
"prefix": "#ifdef",
|
|
"body": ["#ifdef ${1:DEBUG}", "$0", "#endif /* $1 */"],
|
|
"description": "Code snippet for #ifdef"
|
|
},
|
|
"#ifndef": {
|
|
"prefix": "#ifndef",
|
|
"body": ["#ifndef ${1:DEBUG}", "$0", "#endif /* !$1 */"],
|
|
"description": "Code snippet for #ifndef"
|
|
},
|
|
"#if": {
|
|
"prefix": "#if",
|
|
"body": ["#if ${1:0}", "$0", "#endif /* $1 */"],
|
|
"description": "Code snippet for #if"
|
|
},
|
|
"struct": {
|
|
"prefix": "struct",
|
|
"body": ["struct ${1:MyStruct} {", "\t$0", "};"],
|
|
"description": "Code snippet for struct"
|
|
},
|
|
"union": {
|
|
"prefix": "union",
|
|
"body": ["union ${1:MyUnion} {", "\t$0", "};"],
|
|
"description": "Code snippet for union"
|
|
},
|
|
"#inc": {
|
|
"prefix": "#inc",
|
|
"body": ["#include \"$0\""],
|
|
"description": "Code snippet for #include \" \""
|
|
},
|
|
"#inc<": {
|
|
"prefix": "#inc<",
|
|
"body": ["#include <$0>"],
|
|
"description": "Code snippet for #include < >"
|
|
},
|
|
"#def": {
|
|
"prefix": "def",
|
|
"body": ["#define $0"],
|
|
"description": "Code snippet for #define \" \""
|
|
},
|
|
"Main function template": {
|
|
"prefix": "main",
|
|
"body": [
|
|
"int main (int argc, char *argv[])",
|
|
"{",
|
|
"\t$0",
|
|
"\treturn 0;",
|
|
"}"
|
|
],
|
|
"description": "A standard main function for a C program"
|
|
},
|
|
"Standard Starter Template": {
|
|
"prefix": "sst",
|
|
"body": [
|
|
"#include <stdio.h>",
|
|
"",
|
|
"int main ()",
|
|
"{",
|
|
"\t$0",
|
|
"\treturn 0;",
|
|
"}"
|
|
],
|
|
"description": "A standard starter template for a C program"
|
|
},
|
|
"Stdlib Variant Starter Template": {
|
|
"prefix": "libsst",
|
|
"body": [
|
|
"#include <stdio.h>",
|
|
"#include <stdlib.h>",
|
|
"",
|
|
"int main (int argc, char *argv[])",
|
|
"{",
|
|
"\t$0",
|
|
"\treturn 0;",
|
|
"}"
|
|
],
|
|
"description": "A standard starter template for a C program with stdlib included"
|
|
},
|
|
"Create linked list": {
|
|
"prefix": "clist",
|
|
"body": [
|
|
"typedef struct _node * Link;",
|
|
"typedef struct _node node;",
|
|
"struct _node {",
|
|
"\tint value;",
|
|
"\tLink next;",
|
|
"};"
|
|
],
|
|
"description": "Creates a linked list template"
|
|
},
|
|
"Scan integer": {
|
|
"prefix": "sci",
|
|
"body": ["scanf(\"%d\", &$1);"],
|
|
"description": "Scan int"
|
|
},
|
|
"Scan 2 integer": {
|
|
"prefix": "sci2",
|
|
"body": ["scanf(\"%d %d\", &$1, &$2);"],
|
|
"description": "Scan 2 int"
|
|
},
|
|
"Scan unsigned integer": {
|
|
"prefix": "scui",
|
|
"body": ["scanf(\"%d\", &$1);"],
|
|
"description": "Scan unsigned int"
|
|
},
|
|
"Scan float": {
|
|
"prefix": "scf",
|
|
"body": ["scanf(\"%f\", &$1);"],
|
|
"description": "Scan float"
|
|
},
|
|
"Scan 2 float": {
|
|
"prefix": "scf2",
|
|
"body": ["scanf(\"%f %f\", &$1, &$2);"],
|
|
"description": "Scan 2 float"
|
|
},
|
|
"Scan long": {
|
|
"prefix": "scl",
|
|
"body": ["scanf(\"%ld\", &$1);"],
|
|
"description": "Scan long"
|
|
},
|
|
"Scan 2 long": {
|
|
"prefix": "scl2",
|
|
"body": ["scanf(\"%ld %ld\", &$1, &$2);"],
|
|
"description": "Scan 2 long"
|
|
},
|
|
"Scan unsigned long": {
|
|
"prefix": "scul",
|
|
"body": ["scanf(\"%lu\", &$1);"],
|
|
"description": "Scan unsigned long"
|
|
},
|
|
"Scan unsigned long long": {
|
|
"prefix": "scull",
|
|
"body": ["scanf(\"%llu\", &$1);"],
|
|
"description": "Scan unsigned long long"
|
|
},
|
|
"Print variable of type float (2 decimal places)": {
|
|
"prefix": "pflo",
|
|
"body": ["printf(\"$1 :>> %.2f\\n\", $1);"],
|
|
"description": "Calls printf() to log value of variable of type float rounded to 2 decimal places"
|
|
},
|
|
"Print variable of type integer": {
|
|
"prefix": "pint",
|
|
"body": ["printf(\"$1 : %d\\n\", $1);"],
|
|
"description": "Calls printf() to log value of variable of type signed integer"
|
|
},
|
|
"Print variable of type char": {
|
|
"prefix": "pcha",
|
|
"body": ["printf(\"$1 : %c\\n\", $1);"],
|
|
"description": "Calls printf() to log value of variable of type char"
|
|
},
|
|
"Print variable of type pointer": {
|
|
"prefix": "ppoint",
|
|
"body": ["printf(\"$1 : %p\\n\", (void *) $1);"],
|
|
"description": "Calls printf() to log value of variable of type pointer"
|
|
},
|
|
"Print variable of type size_t": {
|
|
"prefix": "psiz",
|
|
"body": ["printf(\"$1 : %zu\\n\", $1);"],
|
|
"description": "Calls printf() to log value of variable of type size_t"
|
|
},
|
|
"printf": {
|
|
"prefix": "printf",
|
|
"body": ["printf(\"$1\\n\"$0);"],
|
|
"description": "Generic printf() snippet"
|
|
},
|
|
"sprintf": {
|
|
"prefix": "sprintf",
|
|
"body": ["sprintf($1, \"$2\\n\"$0);"],
|
|
"description": "Generic sprintf() snippet"
|
|
},
|
|
"fprintf": {
|
|
"prefix": "fprintf",
|
|
"body": ["fprintf(${1:stderr}, \"$2\\n\"$0);"],
|
|
"description": "Generic fprintf() snippet"
|
|
},
|
|
"scanf": {
|
|
"prefix": "scanf",
|
|
"body": ["scanf(\"$1\"$0);"],
|
|
"description": "Generic scanf() snippet"
|
|
},
|
|
"sscanf": {
|
|
"prefix": "sscanf",
|
|
"body": ["sscanf($1, \"$2\"$0);"],
|
|
"description": "Generic sscanf() snippet"
|
|
},
|
|
"fscanf": {
|
|
"prefix": "fscanf",
|
|
"body": ["fscanf($1, \"$2\"$0);"],
|
|
"description": "Generic fscanf() snippet"
|
|
},
|
|
"Allocate memory using malloc": {
|
|
"prefix": "mal",
|
|
"body": [
|
|
"${1:int} *${2:v} = malloc(${3:1} * sizeof($1));",
|
|
"",
|
|
"if (!$2) {",
|
|
"\tfprintf(stderr, \"Memory allocation failed!\\n\");",
|
|
"\t$4;",
|
|
"}",
|
|
"$0",
|
|
"free($2);"
|
|
],
|
|
"description": "Allocates memory to a pointer variable using malloc(), then deallocates using free()."
|
|
},
|
|
"Allocate memory using calloc": {
|
|
"prefix": "cal",
|
|
"body": [
|
|
"${1:int} *${2:v} = calloc(${3:1}, sizeof($1));",
|
|
"",
|
|
"if (!$2) {",
|
|
"\tfprintf(stderr, \"Memory allocation failed!\\n\");",
|
|
"\t$4;",
|
|
"}",
|
|
"$0",
|
|
"free($2);"
|
|
],
|
|
"description": "Allocates memory to a pointer variable using calloc(), then deallocates using free()."
|
|
},
|
|
"X11 default incs": {
|
|
"prefix": "_X11",
|
|
"body": ["#include <X11/X.h>\n#include <X11/Xlib.h>\n#include <X11/Xutil.h>\n#include <X11/XKBlib.h>\n"],
|
|
"description": "X11 default library headers"
|
|
},
|
|
"Primitive macros": {
|
|
"prefix": "_PRIMITIVE",
|
|
"body": [
|
|
"#define i16 short",
|
|
"#define ui16 unsigned short",
|
|
"#define i32 int",
|
|
"#define ui32 unsigned int",
|
|
"#define i64 long long",
|
|
"#define ui64 unsigned long long"
|
|
],
|
|
"description": "Primitive macros for int type"
|
|
}
|
|
}
|