2012-08-28 14:41:46 -04:00
|
|
|
## Main
|
|
|
|
# main
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet main
|
|
|
|
int main(int argc, const char *argv[])
|
|
|
|
{
|
2013-07-25 17:17:32 -04:00
|
|
|
${0}
|
2011-06-20 13:40:28 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-08-28 14:41:46 -04:00
|
|
|
# main(void)
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet mainn
|
|
|
|
int main(void)
|
|
|
|
{
|
2013-07-25 17:17:32 -04:00
|
|
|
${0}
|
2011-06-20 13:40:28 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-08-28 14:41:46 -04:00
|
|
|
##
|
2013-06-20 17:39:31 -04:00
|
|
|
## Preprocessor
|
2011-06-20 13:40:28 -04:00
|
|
|
# #include <...>
|
|
|
|
snippet inc
|
2013-07-25 17:17:32 -04:00
|
|
|
#include <${1:stdio}.h>
|
2011-06-20 13:40:28 -04:00
|
|
|
# #include "..."
|
|
|
|
snippet Inc
|
2013-07-25 17:17:32 -04:00
|
|
|
#include "${1:`vim_snippets#Filename("$1.h")`}"
|
2012-08-28 14:41:46 -04:00
|
|
|
# ifndef...define...endif
|
|
|
|
snippet ndef
|
2011-06-20 13:40:28 -04:00
|
|
|
#ifndef $1
|
|
|
|
#define ${1:SYMBOL} ${2:value}
|
2013-07-25 17:17:32 -04:00
|
|
|
#endif
|
2012-08-28 14:41:46 -04:00
|
|
|
# define
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet def
|
|
|
|
#define
|
2012-08-28 14:41:46 -04:00
|
|
|
# ifdef...endif
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet ifdef
|
|
|
|
#ifdef ${1:FOO}
|
|
|
|
${2:#define }
|
2013-07-25 17:17:32 -04:00
|
|
|
#endif
|
2012-08-28 14:41:46 -04:00
|
|
|
# if
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet #if
|
|
|
|
#if ${1:FOO}
|
2013-07-25 17:17:32 -04:00
|
|
|
${0}
|
2012-08-28 14:41:46 -04:00
|
|
|
#endif
|
|
|
|
# header include guard
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet once
|
2013-07-07 21:41:11 -04:00
|
|
|
#ifndef ${1:`toupper(vim_snippets#Filename('$1_H', 'UNTITLED_H'))`}
|
2011-06-20 13:40:28 -04:00
|
|
|
|
|
|
|
#define $1
|
|
|
|
|
2013-07-25 17:17:32 -04:00
|
|
|
${0}
|
2011-06-20 13:40:28 -04:00
|
|
|
|
|
|
|
#endif /* end of include guard: $1 */
|
2012-08-28 14:41:46 -04:00
|
|
|
##
|
|
|
|
## Control Statements
|
|
|
|
# if
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet if
|
2015-04-26 14:44:26 -04:00
|
|
|
if (${1:true}) {
|
|
|
|
${0}
|
|
|
|
}
|
|
|
|
snippet ife
|
|
|
|
if (${1:true}) {
|
2013-06-20 17:33:44 -04:00
|
|
|
${2}
|
2015-04-26 14:44:26 -04:00
|
|
|
} else {
|
|
|
|
${0}
|
2013-07-25 17:17:32 -04:00
|
|
|
}
|
2012-08-28 14:41:46 -04:00
|
|
|
# else
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet el
|
|
|
|
else {
|
2015-04-26 14:44:26 -04:00
|
|
|
${0}
|
2013-07-25 17:17:32 -04:00
|
|
|
}
|
2012-08-28 14:41:46 -04:00
|
|
|
# else if
|
2012-08-28 13:34:24 -04:00
|
|
|
snippet elif
|
2015-04-26 14:44:26 -04:00
|
|
|
else if (${1:true}) {
|
|
|
|
${0}
|
2013-07-25 17:17:32 -04:00
|
|
|
}
|
2013-07-06 10:17:27 -04:00
|
|
|
# ifi
|
|
|
|
snippet ifi
|
2015-04-26 14:44:26 -04:00
|
|
|
if (${1:true}) ${0};
|
2012-08-28 14:41:46 -04:00
|
|
|
# ternary
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet t
|
|
|
|
${1:/* condition */} ? ${2:a} : ${3:b}
|
2012-10-18 17:27:02 -04:00
|
|
|
# switch
|
|
|
|
snippet switch
|
|
|
|
switch (${1:/* variable */}) {
|
|
|
|
case ${2:/* variable case */}:
|
|
|
|
${3}
|
|
|
|
${4:break;}${5}
|
|
|
|
default:
|
|
|
|
${6}
|
2013-07-25 17:17:32 -04:00
|
|
|
}
|
2012-10-18 17:27:02 -04:00
|
|
|
# switch without default
|
|
|
|
snippet switchndef
|
|
|
|
switch (${1:/* variable */}) {
|
|
|
|
case ${2:/* variable case */}:
|
|
|
|
${3}
|
|
|
|
${4:break;}${5}
|
2013-07-25 17:17:32 -04:00
|
|
|
}
|
2012-10-18 17:27:02 -04:00
|
|
|
# case
|
|
|
|
snippet case
|
|
|
|
case ${1:/* variable case */}:
|
|
|
|
${2}
|
2013-07-25 17:17:32 -04:00
|
|
|
${3:break;}
|
2012-08-28 14:41:46 -04:00
|
|
|
##
|
|
|
|
## Loops
|
|
|
|
# for
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet for
|
|
|
|
for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
|
2013-06-20 17:33:44 -04:00
|
|
|
${4}
|
2013-07-25 17:17:32 -04:00
|
|
|
}
|
2012-08-28 14:41:46 -04:00
|
|
|
# for (custom)
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet forr
|
|
|
|
for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
|
2013-06-20 17:33:44 -04:00
|
|
|
${5}
|
2013-07-25 17:17:32 -04:00
|
|
|
}
|
2012-08-28 14:41:46 -04:00
|
|
|
# while
|
|
|
|
snippet wh
|
|
|
|
while (${1:/* condition */}) {
|
2013-06-20 17:33:44 -04:00
|
|
|
${2}
|
2013-07-25 17:17:32 -04:00
|
|
|
}
|
2012-08-28 14:41:46 -04:00
|
|
|
# do... while
|
|
|
|
snippet do
|
|
|
|
do {
|
2013-06-20 17:33:44 -04:00
|
|
|
${2}
|
2013-07-25 17:17:32 -04:00
|
|
|
} while (${1:/* condition */});
|
2012-08-28 14:41:46 -04:00
|
|
|
##
|
|
|
|
## Functions
|
|
|
|
# function definition
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet fun
|
|
|
|
${1:void} ${2:function_name}(${3})
|
|
|
|
{
|
2013-06-20 17:33:44 -04:00
|
|
|
${4}
|
2013-07-25 17:17:32 -04:00
|
|
|
}
|
2012-08-28 14:41:46 -04:00
|
|
|
# function declaration
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet fund
|
2013-07-25 17:17:32 -04:00
|
|
|
${1:void} ${2:function_name}(${3});
|
2012-08-28 14:41:46 -04:00
|
|
|
##
|
|
|
|
## Types
|
|
|
|
# typedef
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet td
|
2013-07-25 17:17:32 -04:00
|
|
|
typedef ${1:int} ${2:MyCustomType};
|
2012-08-28 14:41:46 -04:00
|
|
|
# struct
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet st
|
2013-07-07 21:41:11 -04:00
|
|
|
struct ${1:`vim_snippets#Filename('$1_t', 'name')`} {
|
2011-06-20 13:40:28 -04:00
|
|
|
${2:/* data */}
|
2013-07-25 17:17:32 -04:00
|
|
|
}${3: /* optional variable list */};
|
2012-08-28 14:41:46 -04:00
|
|
|
# typedef struct
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet tds
|
|
|
|
typedef struct ${2:_$1 }{
|
|
|
|
${3:/* data */}
|
2013-07-25 17:17:32 -04:00
|
|
|
} ${1:`vim_snippets#Filename('$1_t', 'name')`};
|
2012-08-28 14:41:46 -04:00
|
|
|
# typedef enum
|
2011-06-20 13:40:28 -04:00
|
|
|
snippet tde
|
|
|
|
typedef enum {
|
|
|
|
${1:/* data */}
|
2013-07-25 17:17:32 -04:00
|
|
|
} ${2:foo};
|
2012-08-28 14:41:46 -04:00
|
|
|
##
|
|
|
|
## Input/Output
|
2011-06-20 13:40:28 -04:00
|
|
|
# printf
|
|
|
|
snippet pr
|
2013-07-25 17:17:32 -04:00
|
|
|
printf("${1:%s}\n"${2});
|
2011-06-20 13:40:28 -04:00
|
|
|
# fprintf (again, this isn't as nice as TextMate's version, but it works)
|
|
|
|
snippet fpr
|
2013-07-25 17:17:32 -04:00
|
|
|
fprintf(${1:stderr}, "${2:%s}\n"${3});
|
2012-12-07 09:11:55 -05:00
|
|
|
# getopt
|
|
|
|
snippet getopt
|
|
|
|
int choice;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
|
|
|
/* Use flags like so:
|
|
|
|
{"verbose", no_argument, &verbose_flag, 'V'}*/
|
|
|
|
/* Argument styles: no_argument, required_argument, optional_argument */
|
|
|
|
{"version", no_argument, 0, 'v'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
${1}
|
|
|
|
{0,0,0,0}
|
|
|
|
};
|
|
|
|
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
/* Argument parameters:
|
|
|
|
no_argument: " "
|
|
|
|
required_argument: ":"
|
|
|
|
optional_argument: "::" */
|
|
|
|
|
|
|
|
choice = getopt_long( argc, argv, "vh",
|
|
|
|
long_options, &option_index);
|
|
|
|
|
|
|
|
if (choice == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch( choice )
|
|
|
|
{
|
|
|
|
case 'v':
|
|
|
|
${2}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
${3}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
/* getopt_long will have already printed an error */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Not sure how to get here... */
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Deal with non-option arguments here */
|
|
|
|
if ( optind < argc )
|
|
|
|
{
|
|
|
|
while ( optind < argc )
|
|
|
|
{
|
2013-07-25 17:17:32 -04:00
|
|
|
${0}
|
2012-12-07 09:11:55 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-28 14:41:46 -04:00
|
|
|
##
|
|
|
|
## Miscellaneous
|
2011-06-20 13:40:28 -04:00
|
|
|
# This is kind of convenient
|
|
|
|
snippet .
|
2013-07-25 17:17:32 -04:00
|
|
|
[${1}]
|
2011-06-20 13:40:28 -04:00
|
|
|
# GPL
|
|
|
|
snippet gpl
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2012-12-03 07:35:56 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2011-06-20 13:40:28 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) ${1:Author}, `strftime("%Y")`
|
|
|
|
*/
|
2013-06-20 17:39:31 -04:00
|
|
|
|
2013-07-25 17:17:32 -04:00
|
|
|
${0}
|