c.snippets 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. ## Main
  2. # main
  3. snippet main
  4. int main(int argc, const char *argv[])
  5. {
  6. ${1}
  7. return 0;
  8. }
  9. # main(void)
  10. snippet mainn
  11. int main(void)
  12. {
  13. ${1}
  14. return 0;
  15. }
  16. ##
  17. ## Preprocessor
  18. # #include <...>
  19. snippet inc
  20. #include <${1:stdio}.h>${2}
  21. # #include "..."
  22. snippet Inc
  23. #include "${1:`Filename("$1.h")`}"${2}
  24. # ifndef...define...endif
  25. snippet ndef
  26. #ifndef $1
  27. #define ${1:SYMBOL} ${2:value}
  28. #endif${3}
  29. # define
  30. snippet def
  31. #define
  32. # ifdef...endif
  33. snippet ifdef
  34. #ifdef ${1:FOO}
  35. ${2:#define }
  36. #endif${3}
  37. # if
  38. snippet #if
  39. #if ${1:FOO}
  40. ${2}
  41. #endif
  42. # header include guard
  43. snippet once
  44. #ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`}
  45. #define $1
  46. ${2}
  47. #endif /* end of include guard: $1 */
  48. ##
  49. ## Control Statements
  50. # if
  51. snippet if
  52. if (${1:/* condition */}) {
  53. ${2:/* code */}
  54. }${3}
  55. # else
  56. snippet el
  57. else {
  58. ${1}
  59. }${3}
  60. # else if
  61. snippet elif
  62. else if (${1:/* condition */}) {
  63. ${2:/* code */}
  64. }${3}
  65. # ternary
  66. snippet t
  67. ${1:/* condition */} ? ${2:a} : ${3:b}
  68. # switch
  69. snippet switch
  70. switch (${1:/* variable */}) {
  71. case ${2:/* variable case */}:
  72. ${3}
  73. ${4:break;}${5}
  74. default:
  75. ${6}
  76. }${7}
  77. # switch without default
  78. snippet switchndef
  79. switch (${1:/* variable */}) {
  80. case ${2:/* variable case */}:
  81. ${3}
  82. ${4:break;}${5}
  83. }${6}
  84. # case
  85. snippet case
  86. case ${1:/* variable case */}:
  87. ${2}
  88. ${3:break;}${4}
  89. ##
  90. ## Loops
  91. # for
  92. snippet for
  93. for (${2:i} = 0; $2 < ${1:count}; $2${3:++}) {
  94. ${4:/* code */}
  95. }${5}
  96. # for (custom)
  97. snippet forr
  98. for (${1:i} = ${2:0}; ${3:$1 < 10}; $1${4:++}) {
  99. ${5:/* code */}
  100. }${6}
  101. # while
  102. snippet wh
  103. while (${1:/* condition */}) {
  104. ${2:/* code */}
  105. }${3}
  106. # do... while
  107. snippet do
  108. do {
  109. ${2:/* code */}
  110. } while (${1:/* condition */});${3}
  111. ##
  112. ## Functions
  113. # function definition
  114. snippet fun
  115. ${1:void} ${2:function_name}(${3})
  116. {
  117. ${4:/* code */}
  118. }${5}
  119. # function declaration
  120. snippet fund
  121. ${1:void} ${2:function_name}(${3});${4}
  122. ##
  123. ## Types
  124. # typedef
  125. snippet td
  126. typedef ${1:int} ${2:MyCustomType};${3}
  127. # struct
  128. snippet st
  129. struct ${1:`Filename('$1_t', 'name')`} {
  130. ${2:/* data */}
  131. }${3: /* optional variable list */};${4}
  132. # typedef struct
  133. snippet tds
  134. typedef struct ${2:_$1 }{
  135. ${3:/* data */}
  136. } ${1:`Filename('$1_t', 'name')`};${4}
  137. # typedef enum
  138. snippet tde
  139. typedef enum {
  140. ${1:/* data */}
  141. } ${2:foo};${3}
  142. ##
  143. ## Input/Output
  144. # printf
  145. snippet pr
  146. printf("${1:%s}\n"${2});${3}
  147. # fprintf (again, this isn't as nice as TextMate's version, but it works)
  148. snippet fpr
  149. fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
  150. # getopt
  151. snippet getopt
  152. int choice;
  153. while (1)
  154. {
  155. static struct option long_options[] =
  156. {
  157. /* Use flags like so:
  158. {"verbose", no_argument, &verbose_flag, 'V'}*/
  159. /* Argument styles: no_argument, required_argument, optional_argument */
  160. {"version", no_argument, 0, 'v'},
  161. {"help", no_argument, 0, 'h'},
  162. ${1}
  163. {0,0,0,0}
  164. };
  165. int option_index = 0;
  166. /* Argument parameters:
  167. no_argument: " "
  168. required_argument: ":"
  169. optional_argument: "::" */
  170. choice = getopt_long( argc, argv, "vh",
  171. long_options, &option_index);
  172. if (choice == -1)
  173. break;
  174. switch( choice )
  175. {
  176. case 'v':
  177. ${2}
  178. break;
  179. case 'h':
  180. ${3}
  181. break;
  182. case '?':
  183. /* getopt_long will have already printed an error */
  184. break;
  185. default:
  186. /* Not sure how to get here... */
  187. return EXIT_FAILURE;
  188. }
  189. }
  190. /* Deal with non-option arguments here */
  191. if ( optind < argc )
  192. {
  193. while ( optind < argc )
  194. {
  195. ${4}
  196. }
  197. }
  198. ##
  199. ## Miscellaneous
  200. # This is kind of convenient
  201. snippet .
  202. [${1}]${2}
  203. # GPL
  204. snippet gpl
  205. /*
  206. * This program is free software; you can redistribute it and/or modify
  207. * it under the terms of the GNU General Public License as published by
  208. * the Free Software Foundation; either version 2 of the License, or
  209. * (at your option) any later version.
  210. *
  211. * This program is distributed in the hope that it will be useful,
  212. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  213. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  214. * GNU General Public License for more details.
  215. *
  216. * You should have received a copy of the GNU General Public License
  217. * along with this program; if not, write to the Free Software
  218. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  219. *
  220. * Copyright (C) ${1:Author}, `strftime("%Y")`
  221. */
  222. ${2}