@@ -6,14 +6,15 @@ abbr if () {}
66 ${0: TARGET }
77 }
88
9+ # No head option in else/elseif so it can be expanded after "}"
910snippet else
10- options head
11+ abbr else {}
1112 else {
1213 ${0: TARGET }
1314 }
1415
1516snippet elseif
16- options head
17+ abbr else () {}
1718 else if (${1: #:condition } ) {
1819 ${0: TARGET }
1920 }
@@ -37,14 +38,16 @@ abbr for () {}
3738# Counter based for's (don't ask for the type or count start)
3839snippet fori
3940options head
40- abbr for(int x;...) {}
41+ abbr for (int x;...; x++) {}
4142 for (int ${1: i } = 0; $1 < ${2} ; $1 ++) {
4243 ${0: #:TARGET }
4344 }
4445
4546# For reverse counter
4647snippet forri
47- for (int ${1: i } = ${2} ; $1 > 0; $1 --) {
48+ options head
49+ abbr for (int x; ...; x--) {}
50+ for (int ${1: i } = ${2} ; $1 >= 0; $1 --) {
4851 ${0: #:TARGET }
4952 }
5053
@@ -65,11 +68,11 @@ alias do
6568snippet switch
6669options head
6770abbr switch () {}
68- switch (${1: #:var } ) {
69- case ${2: #:val } :
70- ${0: TARGET }
71- break;
72- }
71+ switch (${1: #:var } ) {
72+ case ${2: #:val } :
73+ ${0: TARGET }
74+ break;
75+ }
7376
7477snippet case
7578options head
@@ -89,7 +92,7 @@ snippet function
8992options head
9093alias func
9194abbr func() {}
92- ${1: void } ${2: #:func_name } (${3: #: void } ) {
95+ ${1: void } ${2: #:func_name } (${3: void } ) {
9396 ${0: TARGET }
9497 }
9598
@@ -151,7 +154,7 @@ snippet ifdef
151154options head
152155alias #ifdef
153156abbr #ifdef ... #endif
154- #ifdef $1
157+ #ifdef ${1 : #:SYMBOL }
155158 ${0}
156159 #endif
157160
@@ -172,7 +175,7 @@ alias #def, #define
172175snippet once
173176options head
174177abbr include-guard
175- #ifndef ${1: SYMBOL }
178+ #ifndef ${1: #: SYMBOL }
176179 #define $1
177180
178181 ${0: TARGET }
@@ -183,7 +186,11 @@ abbr include-guard
183186# Built-in function calls {{{
184187snippet printf
185188abbr printf("...\n", ...);
186- printf("${1} \n ", ${2} );
189+ printf("${1} \n "${2} );
190+
191+ snippet scanf
192+ abbr scanf("...", ...);
193+ scanf("${1} ", ${2} );
187194
188195snippet fprintf
189196abbr fprintf(..., "...\n", ...);
@@ -197,11 +204,11 @@ abbr fopen("...", "...");
197204
198205snippet fgets
199206abbr fgets(row, length, file);
200- fgets(${0: ROW } , ${1: LENGTH } , ${2: FILE } );
207+ fgets(${0: ROW } , ${1: LENGTH } , ${2: stdin } );
201208
202209snippet fscanf
203210abbr fscanf(file, "...", ...);
204- fscanf(${1: FILE } , "${2} ", ${3} );
211+ fscanf(${1: stdin } , "${2} ", ${3} );
205212
206213snippet fwrite
207214abbr fwrite(......, file)
@@ -213,8 +220,27 @@ abbr fread(......, file)
213220
214221snippet memcpy
215222abbr memcpy(dest, src, nbytes)
216- mempcy(${1: DEST } , ${2: SRC } , ${3: N_MEMBERS } )
217-
223+ memcpy(${1: DEST } , ${2: SRC } , ${3: NBYTES } )
224+
225+ snippet malloc
226+ abbr malloc(size)
227+ ($2 *)malloc(${1: N_MEMBERS } * sizeof(${2: TYPE } ));
228+ ${0}
229+ free(${3: MEM } );
230+
231+ snippet calloc
232+ abbr calloc(n, size)
233+ ($2 *)calloc(${1: N_MEMBERS } , sizeof(${2: TYPE } ));
234+ ${0}
235+ free(${3: MEM } );
236+
237+ snippet realloc
238+ abbr realloc(old, size)
239+ ($3 *)realloc(${1: OLD } , ${2: N_MEMBERS } * sizeof(${3: TYPE } ));
240+ ${0}
241+
242+ snippet seed_rand
243+ srand(time(NULL));
218244# }}}
219245
220246# Built-in operators and alias {{{
@@ -229,18 +255,26 @@ snippet sizeof_array
229255alias array_size
230256 (sizeof(${1: #:array } ) / sizeof(*($1 )))
231257
232- snippet _static_assert
258+ snippet _Static_assert
259+ alias _static_assert
233260options head
234- _Static_assert(${1: #:condition } , ${2: #:message } )
261+ _Static_assert(${1: #:condition } , ${2: #:message } );
235262
236263snippet static_assert
237264options head
238- static_assert(${1: #:condition } , ${2: #:message } )
265+ static_assert(${1: #:condition } , ${2: #:message } );
239266
240267snippet _Generic
241268alias generic, select
242269 _Generic(${1: #:expression } , ${2: #:association-list } )
243270
271+ snippet va_list
272+ options head
273+ abbr va_start(va_list, last_arg); ... ; va_end()
274+ va_list ${1: ap } ;
275+ va_start($1 , ${2: LAST_ARG } );
276+ ${0}
277+ va_end($1 );
244278# }}}
245279
246280# Comments {{{
0 commit comments