From 0bf28391b00b1e28c44324bcd7647df416314667 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 25 Mar 2010 06:29:54 -0400 Subject: lots and lots of vim stuff for c development... --- .vim/c-support/templates/c.idioms.template | 133 +++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 .vim/c-support/templates/c.idioms.template (limited to '.vim/c-support/templates/c.idioms.template') diff --git a/.vim/c-support/templates/c.idioms.template b/.vim/c-support/templates/c.idioms.template new file mode 100644 index 0000000..4565fab --- /dev/null +++ b/.vim/c-support/templates/c.idioms.template @@ -0,0 +1,133 @@ +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.function == +/* + * === FUNCTION ====================================================================== + * Name: |?FUNCTION_NAME| + * Description: + * ===================================================================================== + */ +void +|FUNCTION_NAME| ( <+argument list+> ) +{ + return <+return value+>; +} /* ----- end of function |FUNCTION_NAME| ----- */ +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.function-static == +/* + * === FUNCTION ====================================================================== + * Name: |?FUNCTION_NAME| + * Description: + * ===================================================================================== + */ +static void +|FUNCTION_NAME| ( <+argument list+> ) +{ + return <+return value+>; +} /* ----- end of static function |FUNCTION_NAME| ----- */ +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.main == +#include + +/* + * === FUNCTION ====================================================================== + * Name: main + * Description: + * ===================================================================================== + */ +int +main ( int argc, char *argv[] ) +{ + return EXIT_SUCCESS; +} /* ---------- end of function main ---------- */ +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.enum == +enum |?ENUM_NAME| { +}; /* ---------- end of enum |ENUM_NAME| ---------- */ + +typedef enum |ENUM_NAME| |ENUM_NAME:c|; +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.struct == +struct |?STRUCT_NAME| { +}; /* ---------- end of struct |STRUCT_NAME| ---------- */ + +typedef struct |STRUCT_NAME| |STRUCT_NAME:c|; +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.union == +union |?UNION_NAME| { +}; /* ---------- end of union |UNION_NAME| ---------- */ + +typedef union |UNION_NAME| |UNION_NAME:c|; +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.printf == insert == +printf ( "\n" ); +== idioms.scanf == insert == +scanf ( "", & ); +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.calloc == +|?POINTER| = calloc ( (size_t)(<+COUNT+>), sizeof(<+TYPE+>) ); +if ( |POINTER|==NULL ) { + fprintf ( stderr, "\ndynamic memory allocation failed\n" ); + exit (EXIT_FAILURE); +} + +free (|POINTER|); +|POINTER| = NULL; + +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.malloc == +|?POINTER| = malloc ( sizeof(<+TYPE+>) ); +if ( |POINTER|==NULL ) { + fprintf ( stderr, "\ndynamic memory allocation failed\n" ); + exit (EXIT_FAILURE); +} + +free (|POINTER|); +|POINTER| = NULL; + +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.sizeof == insert == +sizeof() +== idioms.assert == insert == +assert(); +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.open-input-file == +FILE *|?FILEPOINTER|; /* input-file pointer */ +char *|FILEPOINTER|_file_name = ""; /* input-file name */ + +|FILEPOINTER| = fopen( |FILEPOINTER|_file_name, "r" ); +if ( |FILEPOINTER| == NULL ) { + fprintf ( stderr, "couldn't open file '%s'; %s\n", + |FILEPOINTER|_file_name, strerror(errno) ); + exit (EXIT_FAILURE); +} +{-continue here-} +if( fclose(|FILEPOINTER|) == EOF ) { /* close input file */ + fprintf ( stderr, "couldn't close file '%s'; %s\n", + |FILEPOINTER|_file_name, strerror(errno) ); + exit (EXIT_FAILURE); +} + +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.open-output-file == +FILE *|?FILEPOINTER|; /* output-file pointer */ +char *|FILEPOINTER|_file_name = ""; /* output-file name */ + +|FILEPOINTER| = fopen( |FILEPOINTER|_file_name, "w" ); +if ( |FILEPOINTER| == NULL ) { + fprintf ( stderr, "couldn't open file '%s'; %s\n", + |FILEPOINTER|_file_name, strerror(errno) ); + exit (EXIT_FAILURE); +} +{-continue here-} +if( fclose(|FILEPOINTER|) == EOF ) { /* close output file */ + fprintf ( stderr, "couldn't close file '%s'; %s\n", + |FILEPOINTER|_file_name, strerror(errno) ); + exit (EXIT_FAILURE); +} + +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +== idioms.fprintf == insert == +fprintf ( |?FILEPOINTER|, "\n", ); +== idioms.fscanf == insert == +fscanf ( |?FILEPOINTER|, "", & ); +$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -- cgit v1.2.3