SOP 001-Programmation » Historique » Version 64
Patrice Nadeau, 2018-03-31 15:33
| 1 | 17 | Patrice Nadeau | # SOP 001-Programmation |
|---|---|---|---|
| 2 | 1 | Patrice Nadeau | |
| 3 | Mes standards autant au niveau du style que de la documentation. |
||
| 4 | |||
| 5 | 11 | Patrice Nadeau | La plate-forme (logiciel et matériel) est documenté dans le [[SOP_002-Environnement_informatique]]. |
| 6 | 1 | Patrice Nadeau | |
| 7 | {{lastupdated_at}} {{lastupdated_by}} |
||
| 8 | |||
| 9 | --- |
||
| 10 | |||
| 11 | {{toc}} |
||
| 12 | |||
| 13 | 17 | Patrice Nadeau | ## Diagrammes |
| 14 | 1 | Patrice Nadeau | |
| 15 | Les représentations des différents processus d’un programme ou d’un circuit. |
||
| 16 | |||
| 17 | Les diagrammes DOIVENT être faits avec le logiciel Dia. |
||
| 18 | Ils PEUVENT être exportés en d’autre format. |
||
| 19 | |||
| 20 | 17 | Patrice Nadeau | ### LibreOffice Draw |
| 21 | 14 | Patrice Nadeau | |
| 22 | Icônes : |
||
| 23 | 17 | Patrice Nadeau | |
| 24 | 15 | Patrice Nadeau | * Cisco : http://www.cisco.com/web/about/ac50/ac47/3015_jpeg.zip |
| 25 | 16 | Patrice Nadeau | * http://www.vrt.com.au/downloads/vrt-network-equipment ou http://extensions.libreoffice.org/extension-center/vrt-network-equipment/ |
| 26 | 14 | Patrice Nadeau | |
| 27 | 17 | Patrice Nadeau | ## Système de gestion de version |
| 28 | 1 | Patrice Nadeau | |
| 29 | 42 | Patrice Nadeau | Le logiciel [Git](http://www.git-scm.com/) DOIT être utilisé. |
| 30 | 1 | Patrice Nadeau | |
| 31 | 42 | Patrice Nadeau | La version DOIT être en format: *majeur*.*mineur*.*revision*. |
| 32 | Les nombres *majeur*, *mineur* NE DOIVENT PAS contenir de zéro non significatif et DEVRAIT se limiter à deux chiffres. |
||
| 33 | 1 | Patrice Nadeau | |
| 34 | Ex. |
||
| 35 | > Version 1.2.06 |
||
| 36 | |||
| 37 | 42 | Patrice Nadeau | Les modifications DOIVENT se faire avec **git commit**, de la manière suivante : |
| 38 | 17 | Patrice Nadeau | |
| 39 | 1 | Patrice Nadeau | * nom du fichier modifié, |
| 40 | * 1 espace, |
||
| 41 | * nom de l’item modifié entre parenthèses, |
||
| 42 | * un deux- points (<notextile>:</notextile>) sans espace avec l’item précédent, |
||
| 43 | * 1 espace, |
||
| 44 | * le texte du changement en anglais, commençant par une majuscule, au présent, |
||
| 45 | * un point (.) |
||
| 46 | |||
| 47 | Ex. : |
||
| 48 | > Modification ajouté manuellement |
||
| 49 | 40 | Patrice Nadeau | |
| 50 | |||
| 51 | git commit -m "usart.c (usart_Init): Add a new variable ctr." |
||
| 52 | |||
| 53 | 1 | Patrice Nadeau | > Modification par un éditeur texte |
| 54 | |||
| 55 | 40 | Patrice Nadeau | git commit |
| 56 | |||
| 57 | 17 | Patrice Nadeau | Si les commit sont fait sans l’option **-m**, chaque fichier DOIT être séparé par une ligne vide. |
| 58 | 1 | Patrice Nadeau | |
| 59 | 17 | Patrice Nadeau | ## Code source |
| 60 | 1 | Patrice Nadeau | |
| 61 | Les différents type de langage et de script décrit dans ce SOP. |
||
| 62 | |||
| 63 | 17 | Patrice Nadeau | ### Généralités |
| 64 | 1 | Patrice Nadeau | |
| 65 | 17 | Patrice Nadeau | #### Langue |
| 66 | 1 | Patrice Nadeau | |
| 67 | La langue (macros, variables, fonctions, commentaires, etc...) DOIT être l’anglais. |
||
| 68 | |||
| 69 | 17 | Patrice Nadeau | #### Commentaires |
| 70 | 1 | Patrice Nadeau | |
| 71 | Les commentaires DOIVENT être : |
||
| 72 | 17 | Patrice Nadeau | |
| 73 | 1 | Patrice Nadeau | * sur la ligne précédent l’item à documenter |
| 74 | * en minuscules et commencer par une majuscule |
||
| 75 | |||
| 76 | 17 | Patrice Nadeau | |
| 77 | 1 | Patrice Nadeau | #### Nombre magique |
| 78 | 17 | Patrice Nadeau | |
| 79 | 40 | Patrice Nadeau | L’utilisation de [nombre magique](:http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Unnamed_numerical_constants) ne DOIT PAS être utilisé directement dans le code. |
| 80 | 1 | Patrice Nadeau | Il DOIVENT être définis dans une macro ou une variable globale. |
| 81 | |||
| 82 | 17 | Patrice Nadeau | ## C |
| 83 | 1 | Patrice Nadeau | |
| 84 | Le langage C, version C99 (ISO/IEC 9899:1999) utilisé avec le compilateur GCC. |
||
| 85 | |||
| 86 | 17 | Patrice Nadeau | ### Commentaires |
| 87 | 1 | Patrice Nadeau | |
| 88 | Les commentaires ne devant pas être inclus dans une documentation, DOIVENT être de style « C » : |
||
| 89 | |||
| 90 | 17 | Patrice Nadeau | /* Une seule ligne... */ |
| 91 | 1 | Patrice Nadeau | |
| 92 | 17 | Patrice Nadeau | ... |
| 93 | 1 | Patrice Nadeau | |
| 94 | 17 | Patrice Nadeau | /* |
| 95 | * Sur |
||
| 96 | * plusieurs |
||
| 97 | * lignes |
||
| 98 | 1 | Patrice Nadeau | */ |
| 99 | |||
| 100 | 17 | Patrice Nadeau | ### Doxygen |
| 101 | 1 | Patrice Nadeau | |
| 102 | 17 | Patrice Nadeau | Chaque item DOIT être documentés de manière à générer une documentation avec le logiciel [Doxygen](http://www.stack.nl/~dimitri/doxygen/index.html). |
| 103 | 1 | Patrice Nadeau | |
| 104 | Seulement les items définis dans les fichiers d’en-tête sont documentés par défaut. |
||
| 105 | Un commentaire Doxygen commence par *<notextile> /** </notextile>* , le compilateur le comprenant comme un commentaire ordinaire. |
||
| 106 | |||
| 107 | Les règles typographiques du [[SOP_000-Documentation]] s’appliquent : |
||
| 108 | 17 | Patrice Nadeau | |
| 109 | 44 | Patrice Nadeau | * Gras (**@b**) : Items devant être inscrit tel quel. |
| 110 | * Italique & emphase (**@e**) : Items à remplacer par un choix ou nécessitant une attention particulière. |
||
| 111 | 1 | Patrice Nadeau | |
| 112 | > Doxygen version ≥ 1.8.8 : Le bogue "737472":https://bugzilla.gnome.org/show_bug.cgi?id=737472 oblige de forcer le langage de la fonction dans l’exemple si on ne veut pas de numéro de ligne. |
||
| 113 | |||
| 114 | Les items DOIVENT être inscrit dans cet ordre : |
||
| 115 | 6 | Patrice Nadeau | |
| 116 | 55 | Patrice Nadeau | ``` c |
| 117 | /** |
||
| 118 | * @brief Short description |
||
| 119 | * @param[in,out] var Description. @n Possible values : |
||
| 120 | * − @b value1 |
||
| 121 | * − @b value2 |
||
| 122 | * @return |
||
| 123 | * @retval @b value Description |
||
| 124 | * @par Example : |
||
| 125 | * Example Title |
||
| 126 | * @code{.c} |
||
| 127 | * ... |
||
| 128 | * @endcode |
||
| 129 | * @pre Requirements |
||
| 130 | * @post Changes after the call to this function |
||
| 131 | * @see See also ... |
||
| 132 | * @note |
||
| 133 | * @warning |
||
| 134 | * @bug |
||
| 135 | * @todo |
||
| 136 | */ |
||
| 137 | ``` |
||
| 138 | 1 | Patrice Nadeau | |
| 139 | 45 | Patrice Nadeau | Des **@todo**, **@warning** et **@bug** supplémentaires PEUVENT être ajoutés dans le code. |
| 140 | L’item **@brief** DOIT toujours exister. |
||
| 141 | 1 | Patrice Nadeau | |
| 142 | 17 | Patrice Nadeau | ### Code |
| 143 | 1 | Patrice Nadeau | |
| 144 | Le code est dans le style K&R, variante 1TBS |
||
| 145 | 17 | Patrice Nadeau | |
| 146 | 1 | Patrice Nadeau | * Le « tab » DOIT être équivalent à 4 espaces. |
| 147 | * Le « backslah » DOIT être utilisé pour les lignes de plus de 80 caractères. |
||
| 148 | * Une instruction par ligne. |
||
| 149 | 46 | Patrice Nadeau | * Un espace avant et après un opérateur sauf pour les opérateurs « [unary](http://en.wikipedia.org/wiki/Unary_operation). |
| 150 | 1 | Patrice Nadeau | |
| 151 | One True Brace Style |
||
| 152 | 25 | Patrice Nadeau | |
| 153 | 56 | Patrice Nadeau | ``` c |
| 154 | int fonction (void) |
||
| 155 | { |
||
| 156 | int x; |
||
| 157 | /* the comment goes here, before the loop */ |
||
| 158 | if (var != 1) { |
||
| 159 | x = x + 1; |
||
| 160 | y++; |
||
| 161 | printf("This is a long\ |
||
| 162 | line that should be splitted"); |
||
| 163 | } else { |
||
| 164 | /** @warning this is a Doxygen warning */ |
||
| 165 | x--; |
||
| 166 | } |
||
| 167 | return(0); |
||
| 168 | } |
||
| 169 | ``` |
||
| 170 | 17 | Patrice Nadeau | |
| 171 | 1 | Patrice Nadeau | #### Fichier entête |
| 172 | 17 | Patrice Nadeau | |
| 173 | 1 | Patrice Nadeau | Avertissement |
| 174 | 46 | Patrice Nadeau | >Le gabarit **template.h** DOIT être utilisé. |
| 175 | 1 | Patrice Nadeau | |
| 176 | 25 | Patrice Nadeau | Les fichiers « header » DOIVENT contenir les déclarations des fonctions, macros et la partie « mainpage » de Doxygen. |
| 177 | 1 | Patrice Nadeau | |
| 178 | Le nom du fichier DOIT être composé de la manière suivante : |
||
| 179 | |||
| 180 | 17 | Patrice Nadeau | * en minuscule |
| 181 | 1 | Patrice Nadeau | * 8 caractères maximum |
| 182 | 47 | Patrice Nadeau | * l’extension DOIT être **.h** |
| 183 | 1 | Patrice Nadeau | |
| 184 | Une définition macro DOIT être faite pour éviter de ré-inclure le fichier. |
||
| 185 | La macro DOIT être dans le format *_fichier_h* |
||
| 186 | 25 | Patrice Nadeau | |
| 187 | 57 | Patrice Nadeau | ``` c |
| 188 | #ifndef _usart_h |
||
| 189 | #define _usart_h |
||
| 190 | ... |
||
| 191 | 58 | Patrice Nadeau | |
| 192 | 57 | Patrice Nadeau | #endif /*_usart.h*/ |
| 193 | ``` |
||
| 194 | 25 | Patrice Nadeau | |
| 195 | 1 | Patrice Nadeau | #### Fichier source |
| 196 | 17 | Patrice Nadeau | |
| 197 | 1 | Patrice Nadeau | Le nom du fichier DOIT être composé de la manière suivante : |
| 198 | 25 | Patrice Nadeau | |
| 199 | 1 | Patrice Nadeau | * en minuscule |
| 200 | * 8 caractères maximum |
||
| 201 | 60 | Patrice Nadeau | * l’extension DOIT être **.c** |
| 202 | 1 | Patrice Nadeau | |
| 203 | 17 | Patrice Nadeau | #### Librairies |
| 204 | 1 | Patrice Nadeau | |
| 205 | Fichiers comprenant plusieurs déclarations et définitions reliés entre eux. |
||
| 206 | |||
| 207 | * Le nom DOIT respecter les standards ([[SOP_001-Programmation#Fichiers-Entêtes|1]] & [[SOP_001-Programmation#Fichiers-Sources|2]]) et être significatifs. |
||
| 208 | * Un fichier d’entête DOIT toujours exister. |
||
| 209 | * Les items sont précédés du nom de la librairie (minuscule) et séparés par un « underscore » (_). |
||
| 210 | |||
| 211 | L’utilisation de macros DOIT être utilisé au lieu de constates globales. |
||
| 212 | Il NE DEVRAIT PAS exister de de variables globales. |
||
| 213 | |||
| 214 | #### Déclarations locales |
||
| 215 | 17 | Patrice Nadeau | |
| 216 | 1 | Patrice Nadeau | Une déclaration n’ayant qu’une visibilité locale DOIT être précédé d’un « underscore » (_) et être de classe *static*. |
| 217 | |||
| 218 | 59 | Patrice Nadeau | ``` c |
| 219 | 58 | Patrice Nadeau | /** |
| 220 | * @brief Local function |
||
| 221 | **/ |
||
| 222 | static void _LocalFunc(void) |
||
| 223 | { |
||
| 224 | ... |
||
| 225 | return; |
||
| 226 | } |
||
| 227 | ``` |
||
| 228 | 1 | Patrice Nadeau | |
| 229 | 17 | Patrice Nadeau | #### Items désuets |
| 230 | 1 | Patrice Nadeau | |
| 231 | Les déclarations ne devant plus être utilisés, DOIVENT générer un message lors de la compilation (*-Wall*) si un appel est effectué. |
||
| 232 | 48 | Patrice Nadeau | |
| 233 | 1 | Patrice Nadeau | L’attribut **__attribute\_\_((deprecated))** DOIT être ajouté à la déclaration. |
| 234 | La documentation DOIT indiquer les substituts à utiliser. |
||
| 235 | 25 | Patrice Nadeau | |
| 236 | 58 | Patrice Nadeau | ``` |
| 237 | /** |
||
| 238 | * @brief OldFunction |
||
| 239 | * @detail will generate a warning if used |
||
| 240 | * @see @b NewFunction |
||
| 241 | */ |
||
| 242 | int OldFunction(void) __attribute__((deprecated)); |
||
| 243 | ``` |
||
| 244 | 1 | Patrice Nadeau | |
| 245 | #### Constantes |
||
| 246 | |||
| 247 | La déclaration DOIT inclure aussi la définition. |
||
| 248 | 29 | Patrice Nadeau | |
| 249 | Utilisé au lieu d’une macro quand le type ou la visibilité de la variable doit être définis. |
||
| 250 | 26 | Patrice Nadeau | |
| 251 | * En majuscule |
||
| 252 | * Séparé par un «underscore» (_) si contient plusieurs mots |
||
| 253 | * De classe _static_ ou _extern_ selon le besoin |
||
| 254 | 1 | Patrice Nadeau | |
| 255 | 26 | Patrice Nadeau | Ex. : |
| 256 | |||
| 257 | 58 | Patrice Nadeau | ``` |
| 258 | /** |
||
| 259 | * @name List of constants |
||
| 260 | * @{ |
||
| 261 | */ |
||
| 262 | 26 | Patrice Nadeau | |
| 263 | 58 | Patrice Nadeau | /** |
| 264 | * @brief Local const |
||
| 265 | */ |
||
| 266 | static int _PI = 3.15; |
||
| 267 | /** |
||
| 268 | * @brief The initialization string of the project |
||
| 269 | */ |
||
| 270 | static const char INIT_STR[6] = {'P', 'O', 'W', 'E', 'R'}; |
||
| 271 | /** |
||
| 272 | * @brief Global const in the random library |
||
| 273 | */ |
||
| 274 | extern int random_MAX = 25; |
||
| 275 | 30 | Patrice Nadeau | |
| 276 | 58 | Patrice Nadeau | /** |
| 277 | * @} |
||
| 278 | */ |
||
| 279 | ``` |
||
| 280 | 30 | Patrice Nadeau | |
| 281 | #### Typedef |
||
| 282 | |||
| 283 | Format : |
||
| 284 | 31 | Patrice Nadeau | |
| 285 | * En minuscule, suivie de *_t* |
||
| 286 | |||
| 287 | Définition de typedef |
||
| 288 | |||
| 289 | /** Unsigned integer 8 bits */ |
||
| 290 | typedef unsigned int new_t |
||
| 291 | /** Type of structure in the ds1305 library */ |
||
| 292 | typedef struct { |
||
| 293 | /** @brief last two digits : ≥ 00, ≤ 99 */ |
||
| 294 | uint8_t year; |
||
| 295 | /** @brief 01 - 12 */ |
||
| 296 | uint8_t month; |
||
| 297 | /** @brief 01 - 31 */ |
||
| 298 | 30 | Patrice Nadeau | uint8_t date; |
| 299 | 1 | Patrice Nadeau | /** @brief 1 - 7 */ |
| 300 | uint8_t day; |
||
| 301 | /** @brief 00 - 23 */ |
||
| 302 | 49 | Patrice Nadeau | uint8_t hours; |
| 303 | /** @brief 00 - 59 */ |
||
| 304 | 1 | Patrice Nadeau | uint8_t minutes; |
| 305 | /** @brief 00 - 59 */ |
||
| 306 | uint8_t seconds; |
||
| 307 | } ds1305_time_t; |
||
| 308 | |||
| 309 | 40 | Patrice Nadeau | #### Variables |
| 310 | |||
| 311 | Format : |
||
| 312 | |||
| 313 | * En minuscule. |
||
| 314 | 1 | Patrice Nadeau | * Séparé par un « underscore » (_) si contient plusieurs mots. |
| 315 | |||
| 316 | Définition de variables |
||
| 317 | |||
| 318 | /** @brief Local variable */ |
||
| 319 | int _ctr; |
||
| 320 | /** @brief Global variable from the random librairy */ |
||
| 321 | 40 | Patrice Nadeau | int random_ctr; |
| 322 | |||
| 323 | #### Structures |
||
| 324 | |||
| 325 | Format |
||
| 326 | * En minuscule, séparé par des «underscores» si nécessaire. |
||
| 327 | |||
| 328 | Définition de structures |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @brief Structure for a local menu |
||
| 332 | 17 | Patrice Nadeau | * @see MenuSelect |
| 333 | 1 | Patrice Nadeau | */ |
| 334 | struct menu { |
||
| 335 | 5 | Patrice Nadeau | /** @brief Character used for the item */ |
| 336 | char choice; |
||
| 337 | 32 | Patrice Nadeau | /** @brief Description of the item */ |
| 338 | 5 | Patrice Nadeau | char *item; |
| 339 | 1 | Patrice Nadeau | }; |
| 340 | 5 | Patrice Nadeau | |
| 341 | 1 | Patrice Nadeau | #### Fonctions |
| 342 | |||
| 343 | Le nom est formé d’une lettre majuscule pour chacune des premières lettres des mots. |
||
| 344 | |||
| 345 | Le nom DOIT être dans un deux formats suivants : |
||
| 346 | |||
| 347 | * ActionItemAttribut, où _Action_ signifie : |
||
| 348 | ** *Get* : Lis un registre |
||
| 349 | ** *Read*, *Write* : Lis ou écris dans un fichier |
||
| 350 | ** *Set* : Écris une valeur prédéfini dans un registre |
||
| 351 | ** *Init* : Fonction d’initialisation |
||
| 352 | * isItemEtat |
||
| 353 | 32 | Patrice Nadeau | ** *is* : Verifie si _Item_ est dans l’état _Etat_ |
| 354 | |||
| 355 | Exception |
||
| 356 | 50 | Patrice Nadeau | > Les fonctions définies dans une librairie de bas niveau pour du matériel (« driver »). Dans ce cas, le nom définis dans le « datasheet » aura préséance. Ex. ReadRegister. |
| 357 | 32 | Patrice Nadeau | |
| 358 | 1 | Patrice Nadeau | Une fonction DEVRAIT retourner une valeur. |
| 359 | |||
| 360 | 32 | Patrice Nadeau | Dans le cas d'un « oui/non », la valeur DOIT être : |
| 361 | |||
| 362 | 1 | Patrice Nadeau | * Succès : **0** |
| 363 | 32 | Patrice Nadeau | * Erreur : **1** |
| 364 | 1 | Patrice Nadeau | |
| 365 | 32 | Patrice Nadeau | > L'utilisation d'un type booléen (*true* & *false*) est permise avec la librairie **\<stbool.h\>** (C99). |
| 366 | |||
| 367 | Dans le cas d'une fonction retournant un pointeur : |
||
| 368 | |||
| 369 | * Erreur : **NULL** |
||
| 370 | * Autre valeur : adresse du pointeur |
||
| 371 | |||
| 372 | |||
| 373 | Définition de fonctions |
||
| 374 | |||
| 375 | 63 | Patrice Nadeau | ``` c |
| 376 | /** |
||
| 377 | * @brief Check if a timer is set |
||
| 378 | * @param[in] nb Timer number. @n Possible values : |
||
| 379 | * − @b TIMER_1 |
||
| 380 | * − @b TIMER_2 |
||
| 381 | * @return |
||
| 382 | * @retval true Timer @e nb is set |
||
| 383 | * @retval false Timer @e nb is NOT set |
||
| 384 | * @par Example : |
||
| 385 | * Check if the timer is set |
||
| 386 | * @code{.c} |
||
| 387 | * ... |
||
| 388 | * result = isTimerSet(); |
||
| 389 | * ... |
||
| 390 | * @endcode |
||
| 391 | * @pre TimerInit |
||
| 392 | **/ |
||
| 393 | |||
| 394 | static bool isTimerSet(uint8_t nb); |
||
| 395 | /** |
||
| 396 | * @brief Set the led to green |
||
| 397 | **/ |
||
| 398 | SetLedColor(GREEN); |
||
| 399 | /** |
||
| 400 | * @brief Set register of the chip XYZ |
||
| 401 | * |
||
| 402 | * The name does not follow the standards but does match the datatsheet |
||
| 403 | * This is a local function not meant to be called outside this librairy |
||
| 404 | **/ |
||
| 405 | static void _WriteReg(void); |
||
| 406 | ``` |
||
| 407 | |||
| 408 | 1 | Patrice Nadeau | ### Macros |
| 409 | |||
| 410 | Les directives du préprocesseur C. |
||
| 411 | |||
| 412 | 23 | Patrice Nadeau | * Utilisé dans le code source et les fichiers entête. |
| 413 | * DOIT toujours commencer à la colonne 0. |
||
| 414 | |||
| 415 | 1 | Patrice Nadeau | #### #include |
| 416 | 40 | Patrice Nadeau | |
| 417 | 1 | Patrice Nadeau | Pour inclure d’autres fichier comme les fichiers entête. |
| 418 | 40 | Patrice Nadeau | >N’est pas documenté dans Doxygen. |
| 419 | 24 | Patrice Nadeau | |
| 420 | 17 | Patrice Nadeau | #### ifdef / ifndef |
| 421 | 1 | Patrice Nadeau | |
| 422 | 52 | Patrice Nadeau | Surtout utiliser pour des options de compilation sur différentes plateforme. |
| 423 | 1 | Patrice Nadeau | >N’est pas documenté dans Doxygen. |
| 424 | |||
| 425 | 64 | Patrice Nadeau | ``` c |
| 426 | #ifndef usart_AVR |
||
| 427 | 1 | Patrice Nadeau | |
| 428 | 64 | Patrice Nadeau | #error "usart.h is not supported on this AVR !" |
| 429 | 34 | Patrice Nadeau | |
| 430 | 64 | Patrice Nadeau | #endif |
| 431 | ``` |
||
| 432 | 33 | Patrice Nadeau | |
| 433 | 37 | Patrice Nadeau | #### #error |
| 434 | 1 | Patrice Nadeau | |
| 435 | Affiche une erreur et arrête la compilation |
||
| 436 | >N’est pas documenté dans Doxygen. |
||
| 437 | |||
| 438 | ``` c |
||
| 439 | 64 | Patrice Nadeau | |
| 440 | 62 | Patrice Nadeau | #ifndef __test__ |
| 441 | 1 | Patrice Nadeau | |
| 442 | 62 | Patrice Nadeau | #error "Error !" |
| 443 | 1 | Patrice Nadeau | |
| 444 | 62 | Patrice Nadeau | #endif |
| 445 | 38 | Patrice Nadeau | |
| 446 | 53 | Patrice Nadeau | #### #warning |
| 447 | 17 | Patrice Nadeau | |
| 448 | 53 | Patrice Nadeau | Affiche une erreur mais n’arrête la compilation |
| 449 | >N’est pas documenté dans Doxygen. |
||
| 450 | 1 | Patrice Nadeau | |
| 451 | #ifndef __test__ |
||
| 452 | 39 | Patrice Nadeau | |
| 453 | 1 | Patrice Nadeau | #warning "Warning !" |
| 454 | 39 | Patrice Nadeau | |
| 455 | #endif |
||
| 456 | 1 | Patrice Nadeau | |
| 457 | 39 | Patrice Nadeau | |
| 458 | #### #define |
||
| 459 | 1 | Patrice Nadeau | |
| 460 | Définis une valeur au moment de la compilation. |
||
| 461 | 39 | Patrice Nadeau | |
| 462 | * Format |
||
| 463 | * En majuscule. |
||
| 464 | * Séparé par un «underscore» si contient plusieurs mots. |
||
| 465 | * Doxygen |
||
| 466 | * @brief |
||
| 467 | * @name pour les listes de macros (regroupement dans la documentation) |
||
| 468 | 40 | Patrice Nadeau | |
| 469 | Définition de macros |
||
| 470 | |||
| 471 | /** |
||
| 472 | * @name Mathematical macros listed together |
||
| 473 | * @{ |
||
| 474 | */ |
||
| 475 | 1 | Patrice Nadeau | /** @brief Value for PI */ |
| 476 | |||
| 477 | 17 | Patrice Nadeau | #define _PI 3.14 |
| 478 | 1 | Patrice Nadeau | /** @brief Another number */ |
| 479 | #define _MAGIC_NUMBER 42 |
||
| 480 | 3 | Patrice Nadeau | /** |
| 481 | 1 | Patrice Nadeau | * @} |
| 482 | */ |
||
| 483 | /** @brief Even parity */ |
||
| 484 | |||
| 485 | #define usart_PARITY_EVEN 'e' |
||
| 486 | |||
| 487 | ### Atmel AVR |
||
| 488 | |||
| 489 | 22 | Patrice Nadeau | Particularités pour les micro-contrôleurs AVR d’Atmel. |
| 490 | |||
| 491 | * Progmem : Pour mettre une fonction en Flash au lieu de SRAM. |
||
| 492 | ** Le nom de la fonction est suivie de *_P*. |
||
| 493 | * main : Ne revient jamais à un niveau supérieur. |
||
| 494 | 1 | Patrice Nadeau | ** Définir la fonction main avec l’attribut *noreturn*. |
| 495 | 22 | Patrice Nadeau | ** La boucle sans fin la plus optimisé est le *for (;;)*. |
| 496 | * Atomic : Opérations ne devant pas être interrompus. |
||
| 497 | |||
| 498 | Particularités pour AVR |
||
| 499 | |||
| 500 | /** |
||
| 501 | * @brief Progmem function |
||
| 502 | 1 | Patrice Nadeau | * @return An unsigned 8 bits integer |
| 503 | */ |
||
| 504 | 22 | Patrice Nadeau | uint_8t PrintString_P() |
| 505 | 21 | Patrice Nadeau | |
| 506 | 1 | Patrice Nadeau | /* main function */ |
| 507 | void main(void) __atribute__((noreturn)) |
||
| 508 | 40 | Patrice Nadeau | { |
| 509 | ... |
||
| 510 | /* never return */ |
||
| 511 | for (;;) { |
||
| 512 | } |
||
| 513 | } |
||
| 514 | |||
| 515 | 18 | Patrice Nadeau | /* atomic operations */ |
| 516 | 17 | Patrice Nadeau | |
| 517 | 18 | Patrice Nadeau | #ifndef S_SPLINT_S |
| 518 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { |
||
| 519 | 1 | Patrice Nadeau | /* |
| 520 | * operations that must not be interupted |
||
| 521 | * like loading a 16 bit register with a 8 bit register |
||
| 522 | */ |
||
| 523 | } |
||
| 524 | #endif |
||
| 525 | |||
| 526 | ### Distribution |
||
| 527 | |||
| 528 | Les fichiers suivants DOIVENT être inclus dans une distribution en format *tar.gz* : |
||
| 529 | |||
| 530 | * ChangeLog |
||
| 531 | 18 | Patrice Nadeau | * README |
| 532 | * Files.lst |
||
| 533 | 1 | Patrice Nadeau | * Makefile |
| 534 | * Makefile.mk |
||
| 535 | * LICENSE.txt |
||
| 536 | * *.c |
||
| 537 | * *.h |
||
| 538 | * projet.pdf (généré par Doxygen) |
||
| 539 | 18 | Patrice Nadeau | |
| 540 | Avec mon makefile : |
||
| 541 | |||
| 542 | 1 | Patrice Nadeau | make dist |
| 543 | 18 | Patrice Nadeau | |
| 544 | 1 | Patrice Nadeau | ### Modifications |
| 545 | |||
| 546 | Un changement à un fichier (source ou en-tête), doit se refléter dans _Git_. |
||
| 547 | |||
| 548 | 18 | Patrice Nadeau | Chaque changement est fait avec : |
| 549 | 1 | Patrice Nadeau | |
| 550 | git add nom_fichier |
||
| 551 | 18 | Patrice Nadeau | git commit |
| 552 | |||
| 553 | La ligne DOIT |
||
| 554 | |||
| 555 | * être au temps présent |
||
| 556 | 17 | Patrice Nadeau | * être en anglais |
| 557 | 1 | Patrice Nadeau | * se termine par un point |
| 558 | * être dans le format suivant : |
||
| 559 | > La partie _section_ est facultative |
||
| 560 | |||
| 561 | 18 | Patrice Nadeau | |
| 562 | 1 | Patrice Nadeau | fichier1 (fonction) <section>: |
| 563 | 18 | Patrice Nadeau | Ajoute une description au temps présent. |
| 564 | Décrire les bogues réglés si il y en avaient. |
||
| 565 | 1 | Patrice Nadeau | |
| 566 | |||
| 567 | 17 | Patrice Nadeau | ### Changelog |
| 568 | 18 | Patrice Nadeau | |
| 569 | 1 | Patrice Nadeau | La somme de toutes les modification doivent apparaitre dans un fichier « changelog ». |
| 570 | > Le standard seras celui GNU : http://www.gnu.org/prep/standards/html_node/Change-Logs.html#Change-Logs |
||
| 571 | |||
| 572 | Ce fichier doit s'appeler **ChangeLog** et DOIT être généré à partir de _Git_ (les doubles espaces ne sont pas une erreur de frappe : |
||
| 573 | |||
| 574 | 17 | Patrice Nadeau | git log --no-merges --format="%ad %an <%aE> %n * %B" --date=short > ChangeLog |
| 575 | 1 | Patrice Nadeau | |
| 576 | 17 | Patrice Nadeau | ### Validation du code |
| 577 | 1 | Patrice Nadeau | |
| 578 | 17 | Patrice Nadeau | Le logiciel _splint_ est utilisé. |
| 579 | 1 | Patrice Nadeau | |
| 580 | * Un « typecast » DOIT être utilisé lorsque détecté. |
||
| 581 | * L’utilisation du typecast *void* DOIT être utilisé lorsque qu’une fonction retourne un résultat non utilisé. |
||
| 582 | |||
| 583 | 18 | Patrice Nadeau | ## Makefile |
| 584 | |||
| 585 | 1 | Patrice Nadeau | ## Nagios |
| 586 | |||
| 587 | ### Plugins |
||
| 588 | |||
| 589 | https://nagios-plugins.org/doc/guidelines.html |
||
| 590 | |||
| 591 | 18 | Patrice Nadeau | Un message d'une ligne (< 80 caractères) DOIT être retourné via _STDOUT_ dans le format |
| 592 | > *SERVICE STATUS:* texte |
||
| 593 | 1 | Patrice Nadeau | |
| 594 | Les codes de retour sont les suivants : |
||
| 595 | |||
| 596 | |_. Valeur |_. Service Status |_. Description | |
||
| 597 | | 0 | OK | Le service fonctionne | |
||
| 598 | | 1 | Warning | Le service fonctionne, problème avec le seuil de la valeur _Warning_ | |
||
| 599 | | 2 | Critical | Le service ne fonctionne pas ou problème avec le seuil de la valeur _Critical_ | |
||
| 600 | | 3 | Unknow | Arguments non valides ou erreur interne (fork, tcp socket)| |
||
| 601 | |||
| 602 | 18 | Patrice Nadeau | Les arguments suivants DOIVENT être fournis : |
| 603 | 1 | Patrice Nadeau | |
| 604 | 17 | Patrice Nadeau | * *-H* (*--hostname*) : |
| 605 | 1 | Patrice Nadeau | * *-w* (*--warning*) : |
| 606 | * *-c* (*--critical*) : |
||
| 607 | * *-V* (*--version*) : |
||
| 608 | * *-h* (*--help*) : |
||
| 609 | |||
| 610 | L'argument _--help_ DOIT aussi appeler l'argument _--version_. |
||
| 611 | |||
| 612 | 18 | Patrice Nadeau | En _C_, les fonctions suivantes DOIT être utilisées : |
| 613 | 1 | Patrice Nadeau | |
| 614 | 18 | Patrice Nadeau | * _print_revision_ (utils.c) |
| 615 | 1 | Patrice Nadeau | * _print_help_ |
| 616 | * _getopt_long_ (getopt.h) |
||
| 617 | 18 | Patrice Nadeau | |
| 618 | ## Puppet |
||
| 619 | |||
| 620 | 1 | Patrice Nadeau | ### Généralités |
| 621 | |||
| 622 | Inspiré des recommandations disponible au http://docs.puppetlabs.com/guides/style_guide.html. |
||
| 623 | |||
| 624 | * Tabulation : 2 espaces |
||
| 625 | * Largeur : 80 caractères (« backslah » (\) pour séparer une longue ligne). |
||
| 626 | * Commentaires : Style # |
||
| 627 | * Guillemets |
||
| 628 | * Simple : Pour une « string » sans variables. |
||
| 629 | * Double : Pour une « string » avec variables ayant besoin d’être extrapolé. |
||
| 630 | 18 | Patrice Nadeau | * La variable doit être entourée des symboles *<notextile>{</notextile>* et *<notextile>}</notextile>*. |
| 631 | * Nom des ressources : DOIVENT être entouré du symbole *<notextile> ’ </notextile>*. |
||
| 632 | 1 | Patrice Nadeau | * Alignement de => : DOIT être aligné dans un même paragraphe. |
| 633 | * Ordre : Si l’attribut _ensure_ doit être inclus, il DOIT être le premier. |
||
| 634 | * Lien symbolique : DOIT être déclaré avec *ensure => link* |
||
| 635 | |||
| 636 | Ex. : |
||
| 637 | 18 | Patrice Nadeau | |
| 638 | file { '/var/log/syslog': |
||
| 639 | 1 | Patrice Nadeau | ensure => link, |
| 640 | target => '/var/log/messages', |
||
| 641 | } |
||
| 642 | |||
| 643 | 18 | Patrice Nadeau | * File mode : |
| 644 | * 4 chiffres |
||
| 645 | * simple guillemet |
||
| 646 | 1 | Patrice Nadeau | * Variables |
| 647 | 18 | Patrice Nadeau | * lettres |
| 648 | * chiffres |
||
| 649 | * « underscore » |
||
| 650 | |||
| 651 | 1 | Patrice Nadeau | ### Documentation |
| 652 | 18 | Patrice Nadeau | |
| 653 | 1 | Patrice Nadeau | http://docs.puppetlabs.com/learning/modules2.html#module-documentation |
| 654 | |||
| 655 | Format Rdoc (http://rdoc.rubyforge.org/RDoc/Markup.html) : |
||
| 656 | |||
| 657 | * Bloc de commentaires qui commence sur la première ligne du fichier |
||
| 658 | 18 | Patrice Nadeau | * Titre avec le symbole *<notextile>=</notextile>* |
| 659 | * Séparation avec le symbole *<notextile>-</notextile>* |
||
| 660 | 1 | Patrice Nadeau | * Emphase (mot entouré du symbole) |
| 661 | * * : gras |
||
| 662 | * _ : souligné |
||
| 663 | 17 | Patrice Nadeau | * + : Police de caractères pour le code |
| 664 | 1 | Patrice Nadeau | * Sections |
| 665 | * = Class: |
||
| 666 | * == Parameters: |
||
| 667 | 40 | Patrice Nadeau | * == Requires: |
| 668 | 1 | Patrice Nadeau | * == Sample Usage: |
| 669 | 40 | Patrice Nadeau | * Classe |
| 670 | * Une classe par fichier « manifest » |
||
| 671 | 1 | Patrice Nadeau | |
| 672 | 40 | Patrice Nadeau | ## Script |
| 673 | |||
| 674 | ### Bash |
||
| 675 | |||
| 676 | 61 | Patrice Nadeau | ``` bash |
| 677 | #/bin/bash |
||
| 678 | 1 | Patrice Nadeau | |
| 679 | 61 | Patrice Nadeau | function print_revision { |
| 680 | } |
||
| 681 | 17 | Patrice Nadeau | |
| 682 | 61 | Patrice Nadeau | function print_help { |
| 683 | print_revision |
||
| 684 | } |
||
| 685 | ``` |
||
| 686 | 1 | Patrice Nadeau | |
| 687 | 17 | Patrice Nadeau | ### Perl |
| 688 | 1 | Patrice Nadeau | |
| 689 | ### PowerShell |
||
| 690 | |||
| 691 | Version 4.0. Supporte : |
||
| 692 | 41 | Patrice Nadeau | |
| 693 | * Windows 8.1 (natif) |
||
| 694 | 1 | Patrice Nadeau | * Windows Server 2012 R2 (natif) |
| 695 | * Windows 7 SP1 |
||
| 696 | * Windows Server 2008 R2 SP1 |
||
| 697 | * Windows Server 2012 |
||
| 698 | |||
| 699 | 20 | Patrice Nadeau | #### Fichier |
| 700 | |||
| 701 | Le fichier DOIT être composé de la manière suivante : |
||
| 702 | |||
| 703 | * L’extension est .ps1 |
||
| 704 | * Une longue ligne peux être séparée avec un « back tick » (‘). |
||
| 705 | |||
| 706 | #### Commentaires |
||
| 707 | |||
| 708 | L’aide est accéder par _Get-Help_ |
||
| 709 | |||
| 710 | |||
| 711 | #REQUIRES -Version 2.0 |
||
| 712 | <# |
||
| 713 | .SYNOPSIS |
||
| 714 | A brief description of the function or script. |
||
| 715 | This keyword can be used only once in each topic. |
||
| 716 | .DESCRIPTION |
||
| 717 | A detailed description of the function or script. |
||
| 718 | This keyword can be used only once in each topic. |
||
| 719 | .NOTES |
||
| 720 | File Name |
||
| 721 | : xxxx.ps1 |
||
| 722 | Author |
||
| 723 | : |
||
| 724 | Prerequisite |
||
| 725 | : PowerShell V2 over Vista and upper. |
||
| 726 | Copyright 2011 - |
||
| 727 | 1 | Patrice Nadeau | .LINK |
| 728 | 19 | Patrice Nadeau | Script posted over: |
| 729 | http:// |
||
| 730 | .EXAMPLE |
||
| 731 | Example 1 |
||
| 732 | 1 | Patrice Nadeau | .EXAMPLE |
| 733 | 19 | Patrice Nadeau | Example 2 |
| 734 | #> |
||
| 735 | |||
| 736 | ## Vim |
||
| 737 | 1 | Patrice Nadeau | |
| 738 | * Entête (en commentaires) |
||
| 739 | * Titre |
||
| 740 | * Last Change: |
||
| 741 | * Maintainer: |
||
| 742 | 20 | Patrice Nadeau | * License: This file is placed in the public domain. |
| 743 | 19 | Patrice Nadeau | * Autre mots reconnus |
| 744 | 1 | Patrice Nadeau | * BUG: (Error:) |
| 745 | * TODO: |
||
| 746 | * Note: |
||
| 747 | * FIXME |
||
| 748 | |||
| 749 | ## Références |
||
| 750 | |||
| 751 | Références ayant servis à ce document. |
||
| 752 | |||
| 753 | [ChangeLog](http://www.gnu.org/prep/standards/html_node/Change-Logs.html#Change-Logs) |
||
| 754 | [GNU deprecated attribute](http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Type-Attributes.html) |