2013-04-13 13:45:21 -04:00
|
|
|
## Main
|
|
|
|
# main
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet main
|
2020-04-25 21:56:16 -04:00
|
|
|
int main(int argc, char *argv[])
|
2012-08-16 23:41:25 -04:00
|
|
|
{
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2012-08-16 23:41:25 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
# main(void)
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet mainn
|
|
|
|
int main(void)
|
|
|
|
{
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2012-08-16 23:41:25 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
##
|
2013-07-17 19:06:05 -04:00
|
|
|
## Preprocessor
|
2012-08-16 23:41:25 -04:00
|
|
|
# #include <...>
|
|
|
|
snippet inc
|
2013-11-16 14:45:48 -05:00
|
|
|
#include <${1:stdio}.h>
|
2012-08-16 23:41:25 -04:00
|
|
|
# #include "..."
|
|
|
|
snippet Inc
|
2013-11-16 14:45:48 -05:00
|
|
|
#include "${1:`vim_snippets#Filename("$1.h")`}"
|
2013-04-13 13:45:21 -04:00
|
|
|
# ifndef...define...endif
|
|
|
|
snippet ndef
|
2012-08-16 23:41:25 -04:00
|
|
|
#ifndef $1
|
|
|
|
#define ${1:SYMBOL} ${2:value}
|
2015-12-08 08:20:04 -05:00
|
|
|
#endif /* ifndef $1 */
|
2013-04-13 13:45:21 -04:00
|
|
|
# define
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet def
|
|
|
|
#define
|
2013-04-13 13:45:21 -04:00
|
|
|
# ifdef...endif
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet ifdef
|
|
|
|
#ifdef ${1:FOO}
|
|
|
|
${2:#define }
|
2013-11-16 14:45:48 -05:00
|
|
|
#endif
|
2013-04-13 13:45:21 -04:00
|
|
|
# if
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet #if
|
|
|
|
#if ${1:FOO}
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2012-08-16 23:41:25 -04:00
|
|
|
#endif
|
2013-04-13 13:45:21 -04:00
|
|
|
# header include guard
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet once
|
2013-07-17 19:06:05 -04:00
|
|
|
#ifndef ${1:`toupper(vim_snippets#Filename('$1_H', 'UNTITLED_H'))`}
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
#define $1
|
|
|
|
|
2013-11-16 14:45:48 -05:00
|
|
|
${0}
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
#endif /* end of include guard: $1 */
|
2018-02-04 06:35:08 -05:00
|
|
|
# Disable C++ name mangling in C headers
|
|
|
|
snippet nocxx
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
${0}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
2013-04-13 13:45:21 -04:00
|
|
|
##
|
|
|
|
## Control Statements
|
|
|
|
# if
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet if
|
2015-07-13 06:22:46 -04:00
|
|
|
if (${1:true}) {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2015-07-13 06:22:46 -04:00
|
|
|
}
|
|
|
|
snippet ife
|
|
|
|
if (${1:true}) {
|
2017-02-11 08:01:38 -05:00
|
|
|
${2:${VISUAL}}
|
2015-07-13 06:22:46 -04:00
|
|
|
} else {
|
|
|
|
${0}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
# else
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet el
|
|
|
|
else {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
# else if
|
|
|
|
snippet elif
|
2015-07-13 06:22:46 -04:00
|
|
|
else if (${1:true}) {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2013-07-17 19:06:05 -04:00
|
|
|
# ifi
|
|
|
|
snippet ifi
|
2015-07-13 06:22:46 -04:00
|
|
|
if (${1:true}) ${0};
|
2013-04-13 13:45:21 -04:00
|
|
|
# ternary
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet t
|
|
|
|
${1:/* condition */} ? ${2:a} : ${3:b}
|
2013-04-13 13:45:21 -04:00
|
|
|
# switch
|
|
|
|
snippet switch
|
|
|
|
switch (${1:/* variable */}) {
|
|
|
|
case ${2:/* variable case */}:
|
|
|
|
${3}
|
|
|
|
${4:break;}${5}
|
|
|
|
default:
|
|
|
|
${6}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
# switch without default
|
|
|
|
snippet switchndef
|
|
|
|
switch (${1:/* variable */}) {
|
|
|
|
case ${2:/* variable case */}:
|
|
|
|
${3}
|
|
|
|
${4:break;}${5}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
# case
|
|
|
|
snippet case
|
|
|
|
case ${1:/* variable case */}:
|
|
|
|
${2}
|
2013-11-16 14:45:48 -05:00
|
|
|
${3:break;}
|
2015-12-08 08:20:04 -05:00
|
|
|
snippet ret
|
|
|
|
return ${0};
|
2013-04-13 13:45:21 -04:00
|
|
|
##
|
|
|
|
## Loops
|
|
|
|
# for
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet for
|
2016-11-09 12:22:55 -05:00
|
|
|
for (int ${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
|
2013-07-17 19:06:05 -04:00
|
|
|
${4}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
# for (custom)
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet forr
|
2016-11-09 12:22:55 -05:00
|
|
|
for (int ${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
|
2013-07-17 19:06:05 -04:00
|
|
|
${5}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
# while
|
|
|
|
snippet wh
|
|
|
|
while (${1:/* condition */}) {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
# do... while
|
|
|
|
snippet do
|
|
|
|
do {
|
2017-02-11 08:01:38 -05:00
|
|
|
${0:${VISUAL}}
|
2013-11-16 14:45:48 -05:00
|
|
|
} while (${1:/* condition */});
|
2013-04-13 13:45:21 -04:00
|
|
|
##
|
|
|
|
## Functions
|
|
|
|
# function definition
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet fun
|
|
|
|
${1:void} ${2:function_name}(${3})
|
|
|
|
{
|
2013-07-17 19:06:05 -04:00
|
|
|
${4}
|
2013-11-16 14:45:48 -05:00
|
|
|
}
|
2017-03-07 12:04:28 -05:00
|
|
|
# function definition with zero parameters
|
|
|
|
snippet fun0
|
|
|
|
${1:void} ${2:function_name}()
|
|
|
|
{
|
|
|
|
${3}
|
|
|
|
}
|
|
|
|
# function definition with Doxygen documentation
|
|
|
|
snippet dfun0
|
|
|
|
/*! \brief ${1:Brief function description here}
|
|
|
|
*
|
|
|
|
* ${2:Detailed description of the function}
|
2017-04-01 07:22:06 -04:00
|
|
|
*
|
2017-03-07 12:04:28 -05:00
|
|
|
* \return ${3:Return parameter description}
|
|
|
|
*/
|
|
|
|
${4:void} ${5:function_name}()
|
|
|
|
{
|
|
|
|
${6}
|
|
|
|
}
|
|
|
|
# function definition with one parameter
|
|
|
|
snippet fun1
|
|
|
|
${1:void} ${2:function_name}(${3:Type} ${4:Parameter})
|
|
|
|
{
|
|
|
|
${5}
|
|
|
|
}
|
|
|
|
# function definition with one parameter with Doxygen documentation
|
|
|
|
snippet dfun1
|
|
|
|
/*! \brief ${1:Brief function description here}
|
|
|
|
*
|
|
|
|
* ${2:Detailed description of the function}
|
2017-04-01 07:22:06 -04:00
|
|
|
*
|
2017-03-07 12:04:28 -05:00
|
|
|
* \param $3 ${4:Parameter description}
|
|
|
|
* \return ${5:Return parameter description}
|
|
|
|
*/
|
|
|
|
${6:void} ${7:function_name}(${8:Type} ${3:Parameter})
|
|
|
|
{
|
|
|
|
${9}
|
|
|
|
}
|
|
|
|
# function definition with two parameters
|
|
|
|
snippet fun2
|
|
|
|
${1:void} ${2:function_name}(${3:Type} ${4:Parameter}, ${5:Type} ${6:Parameter})
|
|
|
|
{
|
|
|
|
${7}
|
|
|
|
}
|
|
|
|
# function definition with two parameters with Doxygen documentation
|
|
|
|
snippet dfun2
|
|
|
|
/*! \brief ${1:Brief function description here}
|
|
|
|
*
|
|
|
|
* ${2:Detailed description of the function}
|
2017-04-01 07:22:06 -04:00
|
|
|
*
|
2017-03-07 12:04:28 -05:00
|
|
|
* \param $3 ${4:Parameter description}
|
|
|
|
* \param $5 ${6:Parameter description}
|
|
|
|
* \return ${7:Return parameter description}
|
|
|
|
*/
|
|
|
|
${8:void} ${9:function_name}(${10:Type} ${3:Parameter}, ${11:Type} ${5:Parameter})
|
|
|
|
{
|
|
|
|
${12}
|
|
|
|
}
|
2018-06-14 06:31:12 -04:00
|
|
|
# function definition with three parameters
|
2017-03-07 12:04:28 -05:00
|
|
|
snippet fun3
|
|
|
|
${1:void} ${2:function_name}(${3:Type} ${4:Parameter}, ${5:Type} ${6:Parameter}, ${7:Type} ${8:Parameter})
|
|
|
|
{
|
|
|
|
${9}
|
|
|
|
}
|
2018-06-14 06:31:12 -04:00
|
|
|
# function definition with three parameters with Doxygen documentation
|
2017-03-07 12:04:28 -05:00
|
|
|
snippet dfun3
|
|
|
|
/*! \brief ${1:Brief function description here}
|
|
|
|
*
|
|
|
|
* ${2:Detailed description of the function}
|
2017-04-01 07:22:06 -04:00
|
|
|
*
|
2017-03-07 12:04:28 -05:00
|
|
|
* \param $3 ${4:Parameter description}
|
|
|
|
* \param $5 ${6:Parameter description}
|
|
|
|
* \param $7 ${8:Parameter description}
|
|
|
|
* \return ${9:Return parameter description}
|
|
|
|
*/
|
|
|
|
${10:void} ${11:function_name}(${12:Type} ${3:Parameter}, ${13:Type} ${5:Parameter}, ${14:Type} ${7:Parameter})
|
|
|
|
{
|
|
|
|
${15}
|
|
|
|
}
|
2013-04-13 13:45:21 -04:00
|
|
|
# function declaration
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet fund
|
2013-11-16 14:45:48 -05:00
|
|
|
${1:void} ${2:function_name}(${3});
|
2013-04-13 13:45:21 -04:00
|
|
|
##
|
|
|
|
## Types
|
|
|
|
# typedef
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet td
|
2013-11-16 14:45:48 -05:00
|
|
|
typedef ${1:int} ${2:MyCustomType};
|
2013-04-13 13:45:21 -04:00
|
|
|
# struct
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet st
|
2017-04-01 07:22:06 -04:00
|
|
|
/*! \struct $1
|
2017-03-07 12:04:28 -05:00
|
|
|
* \brief ${3:Brief struct description}
|
2017-04-01 07:22:06 -04:00
|
|
|
*
|
|
|
|
* ${4:Detailed description}
|
2017-03-07 12:04:28 -05:00
|
|
|
*/
|
2013-07-17 19:06:05 -04:00
|
|
|
struct ${1:`vim_snippets#Filename('$1_t', 'name')`} {
|
2017-03-07 12:04:28 -05:00
|
|
|
${2:Data} /*!< ${4:Description} */
|
|
|
|
}${5: /* optional variable list */};
|
2013-04-13 13:45:21 -04:00
|
|
|
# typedef struct
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet tds
|
2017-04-01 07:22:06 -04:00
|
|
|
/*! \struct $2
|
2017-03-07 12:04:28 -05:00
|
|
|
* \brief ${5:Brief struct description}
|
2017-04-01 07:22:06 -04:00
|
|
|
*
|
|
|
|
* ${6:Detailed description}
|
2017-03-07 12:04:28 -05:00
|
|
|
*/
|
2012-08-16 23:41:25 -04:00
|
|
|
typedef struct ${2:_$1 }{
|
2017-03-07 12:04:28 -05:00
|
|
|
m_${3:Data} /*!< ${4:Description} */
|
2013-11-16 14:45:48 -05:00
|
|
|
} ${1:`vim_snippets#Filename('$1_t', 'name')`};
|
2015-12-08 08:20:04 -05:00
|
|
|
|
|
|
|
snippet enum
|
2017-03-07 12:04:28 -05:00
|
|
|
/*! \enum $1
|
2017-04-01 07:22:06 -04:00
|
|
|
*
|
|
|
|
* ${2:Detailed description}
|
2017-03-07 12:04:28 -05:00
|
|
|
*/
|
2015-12-08 08:20:04 -05:00
|
|
|
enum ${1:name} { ${0} };
|
2013-04-13 13:45:21 -04:00
|
|
|
# typedef enum
|
2012-08-16 23:41:25 -04:00
|
|
|
snippet tde
|
2017-03-07 12:04:28 -05:00
|
|
|
/*! \enum $2
|
2017-04-01 07:22:06 -04:00
|
|
|
*
|
|
|
|
* ${4:Detailed description}
|
2017-03-07 12:04:28 -05:00
|
|
|
*/
|
2012-08-16 23:41:25 -04:00
|
|
|
typedef enum {
|
2017-03-07 12:04:28 -05:00
|
|
|
${1:Data} /*!< ${3:Description} */
|
2013-11-16 14:45:48 -05:00
|
|
|
} ${2:foo};
|
2013-04-13 13:45:21 -04:00
|
|
|
##
|
|
|
|
## Input/Output
|
2012-08-16 23:41:25 -04:00
|
|
|
# printf
|
|
|
|
snippet pr
|
2013-11-16 14:45:48 -05:00
|
|
|
printf("${1:%s}\n"${2});
|
2012-08-16 23:41:25 -04:00
|
|
|
# fprintf (again, this isn't as nice as TextMate's version, but it works)
|
|
|
|
snippet fpr
|
2013-11-16 14:45:48 -05:00
|
|
|
fprintf(${1:stderr}, "${2:%s}\n"${3});
|
2016-11-09 12:22:55 -05:00
|
|
|
snippet prd
|
|
|
|
printf("${1:} = %d\n", $1);
|
|
|
|
snippet prf
|
|
|
|
printf("${1:} = %f\n", $1);
|
|
|
|
snippet prx
|
|
|
|
printf("${1:} = %${2}\n", $1);
|
2013-04-13 13:45:21 -04: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-11-16 14:45:48 -05:00
|
|
|
${0}
|
2013-04-13 13:45:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
##
|
2017-03-07 12:04:28 -05:00
|
|
|
# TODO section
|
|
|
|
snippet todo
|
|
|
|
/*! TODO: ${1:Todo description here}
|
|
|
|
* \todo $1
|
|
|
|
*/
|
2013-04-13 13:45:21 -04:00
|
|
|
## Miscellaneous
|
2012-08-16 23:41:25 -04:00
|
|
|
# This is kind of convenient
|
|
|
|
snippet .
|
2013-11-16 14:45:48 -05:00
|
|
|
[${1}]
|