aboutsummaryrefslogtreecommitdiff
path: root/dot_vim/c-support/templates/c.idioms.template
blob: 09bc0b76cc67f542977533ef118d8aa397e20ab7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.function ==
void<CURSOR>
|?FUNCTION_NAME| (  )
{
<SPLIT>	return ;
}		/* -----  end of function |FUNCTION_NAME|  ----- */
$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.function-static ==
static void<CURSOR>
|?FUNCTION_NAME| (  )
{
<SPLIT>	return ;
}		/* -----  end of static function |FUNCTION_NAME|  ----- */
$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.main ==
int
main ( int argc, char *argv[] )
{<CURSOR>
<SPLIT>	return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.enum ==
enum |?ENUM_NAME| {<CURSOR>
<SPLIT>};				/* ----------  end of enum |ENUM_NAME|  ---------- */
$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.struct ==
struct |?STRUCT_NAME| {<CURSOR>
<SPLIT>};				/* ----------  end of struct |STRUCT_NAME|  ---------- */
$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.union ==
union |?UNION_NAME| {<CURSOR>
<SPLIT>};				/* ----------  end of union |UNION_NAME|  ---------- */
$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.calloc ==
|?POINTER|	= (<CURSOR>TYPE*)calloc ( (size_t)(COUNT), sizeof(TYPE) );
if ( |POINTER|==NULL ) {
	fprintf ( stderr, "\ndynamic memory allocation failed\n" );
	exit (EXIT_FAILURE);
}

free (|POINTER|);

$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.malloc ==
|?POINTER|	= (<CURSOR>TYPE*)malloc ( sizeof(TYPE) );
if ( |POINTER|==NULL ) {
	fprintf ( stderr, "\ndynamic memory allocation failed\n" );
	exit (EXIT_FAILURE);
}

free (|POINTER|);

$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.open-input-file ==
FILE	*|?FILEPOINTER|;										/* input-file pointer */
char	*|FILEPOINTER|_file_name = "<CURSOR>";		/* 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);
}


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 = "<CURSOR>";		/* 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);
}


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 ==
fprintf ( |?FILEPOINTER|, "<CURSOR>\n",  );
$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
== idioms.fscanf ==
fscanf ( |?FILEPOINTER|, "<CURSOR>", & );
$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%