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