The first result of the shiny-new dok-tidy target.
[privoxy.git] / doc / webserver / developer-manual / coding.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
2 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4   <head>
5     <meta name="generator" content="HTML Tidy, see www.w3.org">
6     <title>
7       Coding Guidelines
8     </title>
9     <meta name="GENERATOR" content=
10     "Modular DocBook HTML Stylesheet Version 1.79">
11     <link rel="HOME" title="Privoxy Developer Manual" href="index.html">
12     <link rel="PREVIOUS" title="Documentation Guidelines" href=
13     "documentation.html">
14     <link rel="NEXT" title="Testing Guidelines" href="testing.html">
15     <link rel="STYLESHEET" type="text/css" href="../p_doc.css">
16     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
17 <style type="text/css">
18  body {
19   background-color: #EEEEEE;
20   color: #000000;
21  }
22  :link { color: #0000FF }
23  :visited { color: #840084 }
24  :active { color: #0000FF }
25  hr.c1 {text-align: left}
26 </style>
27   </head>
28   <body class="SECT1">
29     <div class="NAVHEADER">
30       <table summary="Header navigation table" width="100%" border="0"
31       cellpadding="0" cellspacing="0">
32         <tr>
33           <th colspan="3" align="center">
34             Privoxy Developer Manual
35           </th>
36         </tr>
37         <tr>
38           <td width="10%" align="left" valign="bottom">
39             <a href="documentation.html" accesskey="P">Prev</a>
40           </td>
41           <td width="80%" align="center" valign="bottom">
42           </td>
43           <td width="10%" align="right" valign="bottom">
44             <a href="testing.html" accesskey="N">Next</a>
45           </td>
46         </tr>
47       </table>
48       <hr width="100%" class="c1">
49     </div>
50     <div class="SECT1">
51       <h1 class="SECT1">
52         <a name="CODING">4. Coding Guidelines</a>
53       </h1>
54       <div class="SECT2">
55         <h2 class="SECT2">
56           <a name="S1">4.1. Introduction</a>
57         </h2>
58         <p>
59           This set of standards is designed to make our lives easier. It is
60           developed with the simple goal of helping us keep the "new and
61           improved <span class="APPLICATION">Privoxy</span>" consistent and
62           reliable. Thus making maintenance easier and increasing chances of
63           success of the project.
64         </p>
65         <p>
66           And that of course comes back to us as individuals. If we can
67           increase our development and product efficiencies then we can solve
68           more of the request for changes/improvements and in general feel
69           good about ourselves. ;-&gt;
70         </p>
71       </div>
72       <div class="SECT2">
73         <h2 class="SECT2">
74           <a name="S2">4.2. Using Comments</a>
75         </h2>
76         <div class="SECT3">
77           <h3 class="SECT3">
78             <a name="S3">4.2.1. Comment, Comment, Comment</a>
79           </h3>
80           <p>
81             <span class="emphasis"><i class=
82             "EMPHASIS">Explanation:</i></span>
83           </p>
84           <p>
85             Comment as much as possible without commenting the obvious. For
86             example do not comment "variable_a is equal to variable_b".
87             Instead explain why variable_a should be equal to the variable_b.
88             Just because a person can read code does not mean they will
89             understand why or what is being done. A reader may spend a lot
90             more time figuring out what is going on when a simple comment or
91             explanation would have prevented the extra research. Please help
92             your brother IJB'ers out!
93           </p>
94           <p>
95             The comments will also help justify the intent of the code. If
96             the comment describes something different than what the code is
97             doing then maybe a programming error is occurring.
98           </p>
99           <p>
100             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
101           </p>
102           <table border="0" bgcolor="#E0E0E0" width="100%">
103             <tr>
104               <td>
105 <pre class="PROGRAMLISTING">
106 /* if page size greater than 1k ... */
107 if ( page_length() &gt; 1024 )
108 {
109     ... "block" the page up ...
110 }
111
112 /* if page size is small, send it in blocks */
113 if ( page_length() &gt; 1024 )
114 {
115     ... "block" the page up ...
116 }
117
118 This demonstrates 2 cases of "what not to do".  The first is a
119 "syntax comment".  The second is a comment that does not fit what
120 is actually being done.
121 </pre>
122               </td>
123             </tr>
124           </table>
125         </div>
126         <div class="SECT3">
127           <h3 class="SECT3">
128             <a name="S4">4.2.2. Use blocks for comments</a>
129           </h3>
130           <p>
131             <span class="emphasis"><i class=
132             "EMPHASIS">Explanation:</i></span>
133           </p>
134           <p>
135             Comments can help or they can clutter. They help when they are
136             differentiated from the code they describe. One line comments do
137             not offer effective separation between the comment and the code.
138             Block identifiers do, by surrounding the code with a clear,
139             definable pattern.
140           </p>
141           <p>
142             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
143           </p>
144           <table border="0" bgcolor="#E0E0E0" width="100%">
145             <tr>
146               <td>
147 <pre class="PROGRAMLISTING">
148 /*********************************************************************
149  * This will stand out clearly in your code!
150  *********************************************************************/
151 if ( this_variable == that_variable )
152 {
153    do_something_very_important();
154 }
155
156
157 /* unfortunately, this may not */
158 if ( this_variable == that_variable )
159 {
160    do_something_very_important();
161 }
162
163
164 if ( this_variable == that_variable ) /* this may not either */
165 {
166    do_something_very_important();
167 }
168 </pre>
169               </td>
170             </tr>
171           </table>
172           <p>
173             <span class="emphasis"><i class="EMPHASIS">Exception:</i></span>
174           </p>
175           <p>
176             If you are trying to add a small logic comment and do not wish to
177             "disrupt" the flow of the code, feel free to use a 1 line comment
178             which is NOT on the same line as the code.
179           </p>
180         </div>
181         <div class="SECT3">
182           <h3 class="SECT3">
183             <a name="S5">4.2.3. Keep Comments on their own line</a>
184           </h3>
185           <p>
186             <span class="emphasis"><i class=
187             "EMPHASIS">Explanation:</i></span>
188           </p>
189           <p>
190             It goes back to the question of readability. If the comment is on
191             the same line as the code it will be harder to read than the
192             comment that is on its own line.
193           </p>
194           <p>
195             There are three exceptions to this rule, which should be violated
196             freely and often: during the definition of variables, at the end
197             of closing braces, when used to comment parameters.
198           </p>
199           <p>
200             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
201           </p>
202           <table border="0" bgcolor="#E0E0E0" width="100%">
203             <tr>
204               <td>
205 <pre class="PROGRAMLISTING">
206 /*********************************************************************
207  * This will stand out clearly in your code,
208  * But the second example won't.
209  *********************************************************************/
210 if ( this_variable == this_variable )
211 {
212    do_something_very_important();
213 }
214
215 if ( this_variable == this_variable ) /*can you see me?*/
216 {
217    do_something_very_important(); /*not easily*/
218 }
219
220
221 /*********************************************************************
222  * But, the encouraged exceptions:
223  *********************************************************************/
224 int urls_read     = 0;     /* # of urls read + rejected */
225 int urls_rejected = 0;     /* # of urls rejected */
226
227 if ( 1 == X )
228 {
229    do_something_very_important();
230 }
231
232
233 short do_something_very_important(
234    short firstparam,   /* represents something */
235    short nextparam     /* represents something else */ )
236 {
237    ...code here...
238
239 }   /* -END- do_something_very_important */
240 </pre>
241               </td>
242             </tr>
243           </table>
244         </div>
245         <div class="SECT3">
246           <h3 class="SECT3">
247             <a name="S6">4.2.4. Comment each logical step</a>
248           </h3>
249           <p>
250             <span class="emphasis"><i class=
251             "EMPHASIS">Explanation:</i></span>
252           </p>
253           <p>
254             Logical steps should be commented to help others follow the
255             intent of the written code and comments will make the code more
256             readable.
257           </p>
258           <p>
259             If you have 25 lines of code without a comment, you should
260             probably go back into it to see where you forgot to put one.
261           </p>
262           <p>
263             Most "for", "while", "do", etc... loops _probably_ need a
264             comment. After all, these are usually major logic containers.
265           </p>
266         </div>
267         <div class="SECT3">
268           <h3 class="SECT3">
269             <a name="S7">4.2.5. Comment All Functions Thoroughly</a>
270           </h3>
271           <p>
272             <span class="emphasis"><i class=
273             "EMPHASIS">Explanation:</i></span>
274           </p>
275           <p>
276             A reader of the code should be able to look at the comments just
277             prior to the beginning of a function and discern the reason for
278             its existence and the consequences of using it. The reader should
279             not have to read through the code to determine if a given
280             function is safe for a desired use. The proper information
281             thoroughly presented at the introduction of a function not only
282             saves time for subsequent maintenance or debugging, it more
283             importantly aids in code reuse by allowing a user to determine
284             the safety and applicability of any function for the problem at
285             hand. As a result of such benefits, all functions should contain
286             the information presented in the addendum section of this
287             document.
288           </p>
289         </div>
290         <div class="SECT3">
291           <h3 class="SECT3">
292             <a name="S8">4.2.6. Comment at the end of braces if the content
293             is more than one screen length</a>
294           </h3>
295           <p>
296             <span class="emphasis"><i class=
297             "EMPHASIS">Explanation:</i></span>
298           </p>
299           <p>
300             Each closing brace should be followed on the same line by a
301             comment that describes the origination of the brace if the
302             original brace is off of the screen, or otherwise far away from
303             the closing brace. This will simplify the debugging, maintenance,
304             and readability of the code.
305           </p>
306           <p>
307             As a suggestion , use the following flags to make the comment and
308             its brace more readable:
309           </p>
310           <p>
311             use following a closing brace: } /* -END- if() or while () or
312             etc... */
313           </p>
314           <p>
315             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
316           </p>
317           <table border="0" bgcolor="#E0E0E0" width="100%">
318             <tr>
319               <td>
320 <pre class="PROGRAMLISTING">
321 if ( 1 == X )
322 {
323    do_something_very_important();
324    ...some long list of commands...
325 } /* -END- if x is 1 */
326
327 or:
328
329 if ( 1 == X )
330 {
331    do_something_very_important();
332    ...some long list of commands...
333 } /* -END- if ( 1 == X ) */
334 </pre>
335               </td>
336             </tr>
337           </table>
338         </div>
339       </div>
340       <div class="SECT2">
341         <h2 class="SECT2">
342           <a name="S9">4.3. Naming Conventions</a>
343         </h2>
344         <div class="SECT3">
345           <h3 class="SECT3">
346             <a name="S10">4.3.1. Variable Names</a>
347           </h3>
348           <p>
349             <span class="emphasis"><i class=
350             "EMPHASIS">Explanation:</i></span>
351           </p>
352           <p>
353             Use all lowercase, and separate words via an underscore ('_'). Do
354             not start an identifier with an underscore. (ANSI C reserves
355             these for use by the compiler and system headers.) Do not use
356             identifiers which are reserved in ANSI C++. (E.g. template,
357             class, true, false, ...). This is in case we ever decide to port
358             Privoxy to C++.
359           </p>
360           <p>
361             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
362           </p>
363           <table border="0" bgcolor="#E0E0E0" width="100%">
364             <tr>
365               <td>
366 <pre class="PROGRAMLISTING">
367 int ms_iis5_hack = 0;
368 </pre>
369               </td>
370             </tr>
371           </table>
372           <p>
373             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
374           </p>
375           <table border="0" bgcolor="#E0E0E0" width="100%">
376             <tr>
377               <td>
378 <pre class="PROGRAMLISTING">
379 int msiis5hack = 0; int msIis5Hack = 0;
380 </pre>
381               </td>
382             </tr>
383           </table>
384         </div>
385         <div class="SECT3">
386           <h3 class="SECT3">
387             <a name="S11">4.3.2. Function Names</a>
388           </h3>
389           <p>
390             <span class="emphasis"><i class=
391             "EMPHASIS">Explanation:</i></span>
392           </p>
393           <p>
394             Use all lowercase, and separate words via an underscore ('_'). Do
395             not start an identifier with an underscore. (ANSI C reserves
396             these for use by the compiler and system headers.) Do not use
397             identifiers which are reserved in ANSI C++. (E.g. template,
398             class, true, false, ...). This is in case we ever decide to port
399             Privoxy to C++.
400           </p>
401           <p>
402             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
403           </p>
404           <table border="0" bgcolor="#E0E0E0" width="100%">
405             <tr>
406               <td>
407 <pre class="PROGRAMLISTING">
408 int load_some_file( struct client_state *csp )
409 </pre>
410               </td>
411             </tr>
412           </table>
413           <p>
414             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
415           </p>
416           <table border="0" bgcolor="#E0E0E0" width="100%">
417             <tr>
418               <td>
419 <pre class="PROGRAMLISTING">
420 int loadsomefile( struct client_state *csp )
421 int loadSomeFile( struct client_state *csp )
422 </pre>
423               </td>
424             </tr>
425           </table>
426         </div>
427         <div class="SECT3">
428           <h3 class="SECT3">
429             <a name="S12">4.3.3. Header file prototypes</a>
430           </h3>
431           <p>
432             <span class="emphasis"><i class=
433             "EMPHASIS">Explanation:</i></span>
434           </p>
435           <p>
436             Use a descriptive parameter name in the function prototype in
437             header files. Use the same parameter name in the header file that
438             you use in the c file.
439           </p>
440           <p>
441             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
442           </p>
443           <table border="0" bgcolor="#E0E0E0" width="100%">
444             <tr>
445               <td>
446 <pre class="PROGRAMLISTING">
447 (.h) extern int load_aclfile( struct client_state *csp );
448 (.c) int load_aclfile( struct client_state *csp )
449 </pre>
450               </td>
451             </tr>
452           </table>
453           <p>
454             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
455           </p>
456           <table border="0" bgcolor="#E0E0E0" width="100%">
457             <tr>
458               <td>
459 <pre class="PROGRAMLISTING">
460 (.h) extern int load_aclfile( struct client_state * ); or
461 (.h) extern int load_aclfile();
462 (.c) int load_aclfile( struct client_state *csp )
463 </pre>
464               </td>
465             </tr>
466           </table>
467         </div>
468         <div class="SECT3">
469           <h3 class="SECT3">
470             <a name="S13">4.3.4. Enumerations, and #defines</a>
471           </h3>
472           <p>
473             <span class="emphasis"><i class=
474             "EMPHASIS">Explanation:</i></span>
475           </p>
476           <p>
477             Use all capital letters, with underscores between words. Do not
478             start an identifier with an underscore. (ANSI C reserves these
479             for use by the compiler and system headers.)
480           </p>
481           <p>
482             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
483           </p>
484           <table border="0" bgcolor="#E0E0E0" width="100%">
485             <tr>
486               <td>
487 <pre class="PROGRAMLISTING">
488 (enumeration) : enum Boolean { FALSE, TRUE };
489 (#define) : #define DEFAULT_SIZE 100;
490 </pre>
491               </td>
492             </tr>
493           </table>
494           <p>
495             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> We
496             have a standard naming scheme for #defines that toggle a feature
497             in the preprocessor: FEATURE_&gt;, where &gt; is a short
498             (preferably 1 or 2 word) description.
499           </p>
500           <p>
501             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
502           </p>
503           <table border="0" bgcolor="#E0E0E0" width="100%">
504             <tr>
505               <td>
506 <pre class="PROGRAMLISTING">
507 #define FEATURE_FORCE 1
508
509 #ifdef FEATURE_FORCE
510 #define FORCE_PREFIX blah
511 #endif /* def FEATURE_FORCE */
512 </pre>
513               </td>
514             </tr>
515           </table>
516         </div>
517         <div class="SECT3">
518           <h3 class="SECT3">
519             <a name="S14">4.3.5. Constants</a>
520           </h3>
521           <p>
522             <span class="emphasis"><i class=
523             "EMPHASIS">Explanation:</i></span>
524           </p>
525           <p>
526             Spell common words out entirely (do not remove vowels).
527           </p>
528           <p>
529             Use only widely-known domain acronyms and abbreviations.
530             Capitalize all letters of an acronym.
531           </p>
532           <p>
533             Use underscore (_) to separate adjacent acronyms and
534             abbreviations. Never terminate a name with an underscore.
535           </p>
536           <p>
537             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
538           </p>
539           <table border="0" bgcolor="#E0E0E0" width="100%">
540             <tr>
541               <td>
542 <pre class="PROGRAMLISTING">
543 #define USE_IMAGE_LIST 1
544 </pre>
545               </td>
546             </tr>
547           </table>
548           <p>
549             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
550           </p>
551           <table border="0" bgcolor="#E0E0E0" width="100%">
552             <tr>
553               <td>
554 <pre class="PROGRAMLISTING">
555 #define USE_IMG_LST 1 or
556 #define _USE_IMAGE_LIST 1 or
557 #define USE_IMAGE_LIST_ 1 or
558 #define use_image_list 1 or
559 #define UseImageList 1
560 </pre>
561               </td>
562             </tr>
563           </table>
564         </div>
565       </div>
566       <div class="SECT2">
567         <h2 class="SECT2">
568           <a name="S15">4.4. Using Space</a>
569         </h2>
570         <div class="SECT3">
571           <h3 class="SECT3">
572             <a name="S16">4.4.1. Put braces on a line by themselves.</a>
573           </h3>
574           <p>
575             <span class="emphasis"><i class=
576             "EMPHASIS">Explanation:</i></span>
577           </p>
578           <p>
579             The brace needs to be on a line all by itself, not at the end of
580             the statement. Curly braces should line up with the construct
581             that they're associated with. This practice makes it easier to
582             identify the opening and closing braces for a block.
583           </p>
584           <p>
585             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
586           </p>
587           <table border="0" bgcolor="#E0E0E0" width="100%">
588             <tr>
589               <td>
590 <pre class="PROGRAMLISTING">
591 if ( this == that )
592 {
593    ...
594 }
595 </pre>
596               </td>
597             </tr>
598           </table>
599           <p>
600             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
601           </p>
602           <p>
603             if ( this == that ) { ... }
604           </p>
605           <p>
606             or
607           </p>
608           <p>
609             if ( this == that ) { ... }
610           </p>
611           <p>
612             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> In
613             the special case that the if-statement is inside a loop, and it
614             is trivial, i.e. it tests for a condition that is obvious from
615             the purpose of the block, one-liners as above may optically
616             preserve the loop structure and make it easier to read.
617           </p>
618           <p>
619             <span class="emphasis"><i class="EMPHASIS">Status:</i></span>
620             developer-discretion.
621           </p>
622           <p>
623             <span class="emphasis"><i class="EMPHASIS">Example
624             exception:</i></span>
625           </p>
626           <table border="0" bgcolor="#E0E0E0" width="100%">
627             <tr>
628               <td>
629 <pre class="PROGRAMLISTING">
630 while ( more lines are read )
631 {
632    /* Please document what is/is not a comment line here */
633    if ( it's a comment ) continue;
634
635    do_something( line );
636 }
637 </pre>
638               </td>
639             </tr>
640           </table>
641         </div>
642         <div class="SECT3">
643           <h3 class="SECT3">
644             <a name="S17">4.4.2. ALL control statements should have a
645             block</a>
646           </h3>
647           <p>
648             <span class="emphasis"><i class=
649             "EMPHASIS">Explanation:</i></span>
650           </p>
651           <p>
652             Using braces to make a block will make your code more readable
653             and less prone to error. All control statements should have a
654             block defined.
655           </p>
656           <p>
657             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
658           </p>
659           <table border="0" bgcolor="#E0E0E0" width="100%">
660             <tr>
661               <td>
662 <pre class="PROGRAMLISTING">
663 if ( this == that )
664 {
665    do_something();
666    do_something_else();
667 }
668 </pre>
669               </td>
670             </tr>
671           </table>
672           <p>
673             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
674           </p>
675           <p>
676             if ( this == that ) do_something(); do_something_else();
677           </p>
678           <p>
679             or
680           </p>
681           <p>
682             if ( this == that ) do_something();
683           </p>
684           <p>
685             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> The
686             first example in "Instead of" will execute in a manner other than
687             that which the developer desired (per indentation). Using code
688             braces would have prevented this "feature". The "explanation" and
689             "exception" from the point above also applies.
690           </p>
691         </div>
692         <div class="SECT3">
693           <h3 class="SECT3">
694             <a name="S18">4.4.3. Do not belabor/blow-up boolean
695             expressions</a>
696           </h3>
697           <p>
698             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
699           </p>
700           <table border="0" bgcolor="#E0E0E0" width="100%">
701             <tr>
702               <td>
703 <pre class="PROGRAMLISTING">
704 structure-&gt;flag = ( condition );
705 </pre>
706               </td>
707             </tr>
708           </table>
709           <p>
710             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
711           </p>
712           <p>
713             if ( condition ) { structure-&gt;flag = 1; } else {
714             structure-&gt;flag = 0; }
715           </p>
716           <p>
717             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> The
718             former is readable and concise. The later is wordy and
719             inefficient. Please assume that any developer new to the project
720             has at least a "good" knowledge of C/C++. (Hope I do not offend
721             by that last comment ... 8-)
722           </p>
723         </div>
724         <div class="SECT3">
725           <h3 class="SECT3">
726             <a name="S19">4.4.4. Use white space freely because it is
727             free</a>
728           </h3>
729           <p>
730             <span class="emphasis"><i class=
731             "EMPHASIS">Explanation:</i></span>
732           </p>
733           <p>
734             Make it readable. The notable exception to using white space
735             freely is listed in the next guideline.
736           </p>
737           <p>
738             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
739           </p>
740           <table border="0" bgcolor="#E0E0E0" width="100%">
741             <tr>
742               <td>
743 <pre class="PROGRAMLISTING">
744 int first_value   = 0;
745 int some_value    = 0;
746 int another_value = 0;
747 int this_variable = 0;
748
749 if ( this_variable == this_variable )
750
751 first_value = old_value + ( ( some_value - another_value ) - whatever )
752 </pre>
753               </td>
754             </tr>
755           </table>
756         </div>
757         <div class="SECT3">
758           <h3 class="SECT3">
759             <a name="S20">4.4.5. Don't use white space around structure
760             operators</a>
761           </h3>
762           <p>
763             <span class="emphasis"><i class=
764             "EMPHASIS">Explanation:</i></span>
765           </p>
766           <p>
767             - structure pointer operator ( "-&gt;" ) - member operator ( "."
768             ) - functions and parentheses
769           </p>
770           <p>
771             It is a general coding practice to put pointers, references, and
772             function parentheses next to names. With spaces, the connection
773             between the object and variable/function name is not as clear.
774           </p>
775           <p>
776             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
777           </p>
778           <table border="0" bgcolor="#E0E0E0" width="100%">
779             <tr>
780               <td>
781 <pre class="PROGRAMLISTING">
782 a_struct-&gt;a_member;
783 a_struct.a_member;
784 function_name();
785 </pre>
786               </td>
787             </tr>
788           </table>
789           <p>
790             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
791             a_struct -&gt; a_member; a_struct . a_member; function_name ();
792           </p>
793         </div>
794         <div class="SECT3">
795           <h3 class="SECT3">
796             <a name="S21">4.4.6. Make the last brace of a function stand
797             out</a>
798           </h3>
799           <p>
800             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
801           </p>
802           <table border="0" bgcolor="#E0E0E0" width="100%">
803             <tr>
804               <td>
805 <pre class="PROGRAMLISTING">
806 int function1( ... )
807 {
808    ...code...
809    return( ret_code );
810
811 }   /* -END- function1 */
812
813
814 int function2( ... )
815 {
816 }   /* -END- function2 */
817 </pre>
818               </td>
819             </tr>
820           </table>
821           <p>
822             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
823           </p>
824           <p>
825             int function1( ... ) { ...code... return( ret_code ); } int
826             function2( ... ) { }
827           </p>
828           <p>
829             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> Use 1
830             blank line before the closing brace and 2 lines afterward. This
831             makes the end of function standout to the most casual viewer.
832             Although function comments help separate functions, this is still
833             a good coding practice. In fact, I follow these rules when using
834             blocks in "for", "while", "do" loops, and long if {} statements
835             too. After all whitespace is free!
836           </p>
837           <p>
838             <span class="emphasis"><i class="EMPHASIS">Status:</i></span>
839             developer-discretion on the number of blank lines. Enforced is
840             the end of function comments.
841           </p>
842         </div>
843         <div class="SECT3">
844           <h3 class="SECT3">
845             <a name="S22">4.4.7. Use 3 character indentions</a>
846           </h3>
847           <p>
848             <span class="emphasis"><i class=
849             "EMPHASIS">Explanation:</i></span>
850           </p>
851           <p>
852             If some use 8 character TABs and some use 3 character TABs, the
853             code can look *very* ragged. So use 3 character indentions only.
854             If you like to use TABs, pass your code through a filter such as
855             "expand -t3" before checking in your code.
856           </p>
857           <p>
858             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
859           </p>
860           <table border="0" bgcolor="#E0E0E0" width="100%">
861             <tr>
862               <td>
863 <pre class="PROGRAMLISTING">
864 static const char * const url_code_map[256] =
865 {
866    NULL, ...
867 };
868
869
870 int function1( ... )
871 {
872    if ( 1 )
873    {
874       return( ALWAYS_TRUE );
875    }
876    else
877    {
878       return( HOW_DID_YOU_GET_HERE );
879    }
880
881    return( NEVER_GETS_HERE );
882
883 }
884 </pre>
885               </td>
886             </tr>
887           </table>
888         </div>
889       </div>
890       <div class="SECT2">
891         <h2 class="SECT2">
892           <a name="S23">4.5. Initializing</a>
893         </h2>
894         <div class="SECT3">
895           <h3 class="SECT3">
896             <a name="S24">4.5.1. Initialize all variables</a>
897           </h3>
898           <p>
899             <span class="emphasis"><i class=
900             "EMPHASIS">Explanation:</i></span>
901           </p>
902           <p>
903             Do not assume that the variables declared will not be used until
904             after they have been assigned a value somewhere else in the code.
905             Remove the chance of accidentally using an unassigned variable.
906           </p>
907           <p>
908             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
909           </p>
910           <table border="0" bgcolor="#E0E0E0" width="100%">
911             <tr>
912               <td>
913 <pre class="PROGRAMLISTING">
914 short a_short = 0;
915 float a_float  = 0;
916 struct *ptr = NULL;
917 </pre>
918               </td>
919             </tr>
920           </table>
921           <p>
922             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> It is
923             much easier to debug a SIGSEGV if the message says you are trying
924             to access memory address 00000000 and not 129FA012; or
925             array_ptr[20] causes a SIGSEV vs. array_ptr[0].
926           </p>
927           <p>
928             <span class="emphasis"><i class="EMPHASIS">Status:</i></span>
929             developer-discretion if and only if the variable is assigned a
930             value "shortly after" declaration.
931           </p>
932         </div>
933       </div>
934       <div class="SECT2">
935         <h2 class="SECT2">
936           <a name="S25">4.6. Functions</a>
937         </h2>
938         <div class="SECT3">
939           <h3 class="SECT3">
940             <a name="S26">4.6.1. Name functions that return a boolean as a
941             question.</a>
942           </h3>
943           <p>
944             <span class="emphasis"><i class=
945             "EMPHASIS">Explanation:</i></span>
946           </p>
947           <p>
948             Value should be phrased as a question that would logically be
949             answered as a true or false statement
950           </p>
951           <p>
952             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
953           </p>
954           <table border="0" bgcolor="#E0E0E0" width="100%">
955             <tr>
956               <td>
957 <pre class="PROGRAMLISTING">
958 should_we_block_this();
959 contains_an_image();
960 is_web_page_blank();
961 </pre>
962               </td>
963             </tr>
964           </table>
965         </div>
966         <div class="SECT3">
967           <h3 class="SECT3">
968             <a name="S27">4.6.2. Always specify a return type for a
969             function.</a>
970           </h3>
971           <p>
972             <span class="emphasis"><i class=
973             "EMPHASIS">Explanation:</i></span>
974           </p>
975           <p>
976             The default return for a function is an int. To avoid ambiguity,
977             create a return for a function when the return has a purpose, and
978             create a void return type if the function does not need to return
979             anything.
980           </p>
981         </div>
982         <div class="SECT3">
983           <h3 class="SECT3">
984             <a name="S28">4.6.3. Minimize function calls when iterating by
985             using variables</a>
986           </h3>
987           <p>
988             <span class="emphasis"><i class=
989             "EMPHASIS">Explanation:</i></span>
990           </p>
991           <p>
992             It is easy to write the following code, and a clear argument can
993             be made that the code is easy to understand:
994           </p>
995           <p>
996             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
997           </p>
998           <table border="0" bgcolor="#E0E0E0" width="100%">
999             <tr>
1000               <td>
1001 <pre class="PROGRAMLISTING">
1002 for ( size_t cnt = 0; cnt &lt; block_list_length(); cnt++ )
1003 {
1004    ....
1005 }
1006 </pre>
1007               </td>
1008             </tr>
1009           </table>
1010           <p>
1011             <span class="emphasis"><i class="EMPHASIS">Note:</i></span>
1012             Unfortunately, this makes a function call for each and every
1013             iteration. This increases the overhead in the program, because
1014             the compiler has to look up the function each time, call it, and
1015             return a value. Depending on what occurs in the
1016             block_list_length() call, it might even be creating and
1017             destroying structures with each iteration, even though in each
1018             case it is comparing "cnt" to the same value, over and over.
1019             Remember too - even a call to block_list_length() is a function
1020             call, with the same overhead.
1021           </p>
1022           <p>
1023             Instead of using a function call during the iterations, assign
1024             the value to a variable, and evaluate using the variable.
1025           </p>
1026           <p>
1027             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
1028           </p>
1029           <table border="0" bgcolor="#E0E0E0" width="100%">
1030             <tr>
1031               <td>
1032 <pre class="PROGRAMLISTING">
1033 size_t len = block_list_length();
1034
1035 for ( size_t cnt = 0; cnt &lt; len; cnt++ )
1036 {
1037    ....
1038 }
1039 </pre>
1040               </td>
1041             </tr>
1042           </table>
1043           <p>
1044             <span class="emphasis"><i class="EMPHASIS">Exceptions:</i></span>
1045             if the value of block_list_length() *may* change or could
1046             *potentially* change, then you must code the function call in the
1047             for/while loop.
1048           </p>
1049         </div>
1050         <div class="SECT3">
1051           <h3 class="SECT3">
1052             <a name="S29">4.6.4. Pass and Return by Const Reference</a>
1053           </h3>
1054           <p>
1055             <span class="emphasis"><i class=
1056             "EMPHASIS">Explanation:</i></span>
1057           </p>
1058           <p>
1059             This allows a developer to define a const pointer and call your
1060             function. If your function does not have the const keyword, we
1061             may not be able to use your function. Consider strcmp, if it were
1062             defined as: extern int strcmp( char *s1, char *s2 );
1063           </p>
1064           <p>
1065             I could then not use it to compare argv's in main: int main( int
1066             argc, const char *argv[] ) { strcmp( argv[0], "privoxy" ); }
1067           </p>
1068           <p>
1069             Both these pointers are *const*! If the c runtime library
1070             maintainers do it, we should too.
1071           </p>
1072         </div>
1073         <div class="SECT3">
1074           <h3 class="SECT3">
1075             <a name="S30">4.6.5. Pass and Return by Value</a>
1076           </h3>
1077           <p>
1078             <span class="emphasis"><i class=
1079             "EMPHASIS">Explanation:</i></span>
1080           </p>
1081           <p>
1082             Most structures cannot fit onto a normal stack entry (i.e. they
1083             are not 4 bytes or less). Aka, a function declaration like: int
1084             load_aclfile( struct client_state csp )
1085           </p>
1086           <p>
1087             would not work. So, to be consistent, we should declare all
1088             prototypes with "pass by value": int load_aclfile( struct
1089             client_state *csp )
1090           </p>
1091         </div>
1092         <div class="SECT3">
1093           <h3 class="SECT3">
1094             <a name="S31">4.6.6. Names of include files</a>
1095           </h3>
1096           <p>
1097             <span class="emphasis"><i class=
1098             "EMPHASIS">Explanation:</i></span>
1099           </p>
1100           <p>
1101             Your include statements should contain the file name without a
1102             path. The path should be listed in the Makefile, using -I as
1103             processor directive to search the indicated paths. An exception
1104             to this would be for some proprietary software that utilizes a
1105             partial path to distinguish their header files from system or
1106             other header files.
1107           </p>
1108           <p>
1109             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
1110           </p>
1111           <table border="0" bgcolor="#E0E0E0" width="100%">
1112             <tr>
1113               <td>
1114 <pre class="PROGRAMLISTING">
1115 #include &lt;iostream.h&gt;     /* This is not a local include */
1116 #include "config.h"       /* This IS a local include */
1117 </pre>
1118               </td>
1119             </tr>
1120           </table>
1121           <p>
1122             <span class="emphasis"><i class="EMPHASIS">Exception:</i></span>
1123           </p>
1124           <table border="0" bgcolor="#E0E0E0" width="100%">
1125             <tr>
1126               <td>
1127 <pre class="PROGRAMLISTING">
1128 /* This is not a local include, but requires a path element. */
1129 #include &lt;sys/fileName.h&gt;
1130 </pre>
1131               </td>
1132             </tr>
1133           </table>
1134
1135           <p>
1136             <span class="emphasis"><i class="EMPHASIS">Note:</i></span>
1137             Please! do not add "-I." to the Makefile without a _very_ good
1138             reason. This duplicates the #include "file.h" behavior.
1139           </p>
1140         </div>
1141         <div class="SECT3">
1142           <h3 class="SECT3">
1143             <a name="S32">4.6.7. Provide multiple inclusion protection</a>
1144           </h3>
1145           <p>
1146             <span class="emphasis"><i class=
1147             "EMPHASIS">Explanation:</i></span>
1148           </p>
1149           <p>
1150             Prevents compiler and linker errors resulting from redefinition
1151             of items.
1152           </p>
1153           <p>
1154             Wrap each header file with the following syntax to prevent
1155             multiple inclusions of the file. Of course, replace PROJECT_H
1156             with your file name, with "." Changed to "_", and make it
1157             uppercase.
1158           </p>
1159           <p>
1160             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
1161           </p>
1162           <table border="0" bgcolor="#E0E0E0" width="100%">
1163             <tr>
1164               <td>
1165 <pre class="PROGRAMLISTING">
1166 #ifndef PROJECT_H_INCLUDED
1167 #define PROJECT_H_INCLUDED
1168  ...
1169 #endif /* ndef PROJECT_H_INCLUDED */
1170 </pre>
1171               </td>
1172             </tr>
1173           </table>
1174         </div>
1175         <div class="SECT3">
1176           <h3 class="SECT3">
1177             <a name="S33">4.6.8. Use `extern "C"` when appropriate</a>
1178           </h3>
1179           <p>
1180             <span class="emphasis"><i class=
1181             "EMPHASIS">Explanation:</i></span>
1182           </p>
1183           <p>
1184             If our headers are included from C++, they must declare our
1185             functions as `extern "C"`. This has no cost in C, but increases
1186             the potential re-usability of our code.
1187           </p>
1188           <p>
1189             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
1190           </p>
1191           <table border="0" bgcolor="#E0E0E0" width="100%">
1192             <tr>
1193               <td>
1194 <pre class="PROGRAMLISTING">
1195 #ifdef __cplusplus
1196 extern "C"
1197 {
1198 #endif /* def __cplusplus */
1199
1200 ... function definitions here ...
1201
1202 #ifdef __cplusplus
1203 }
1204 #endif /* def __cplusplus */
1205 </pre>
1206               </td>
1207             </tr>
1208           </table>
1209         </div>
1210         <div class="SECT3">
1211           <h3 class="SECT3">
1212             <a name="S34">4.6.9. Where Possible, Use Forward Struct
1213             Declaration Instead of Includes</a>
1214           </h3>
1215           <p>
1216             <span class="emphasis"><i class=
1217             "EMPHASIS">Explanation:</i></span>
1218           </p>
1219           <p>
1220             Useful in headers that include pointers to other struct's.
1221             Modifications to excess header files may cause needless compiles.
1222           </p>
1223           <p>
1224             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
1225           </p>
1226           <table border="0" bgcolor="#E0E0E0" width="100%">
1227             <tr>
1228               <td>
1229 <pre class="PROGRAMLISTING">
1230 /*********************************************************************
1231  * We're avoiding an include statement here!
1232  *********************************************************************/
1233 struct file_list;
1234 extern file_list *xyz;
1235 </pre>
1236               </td>
1237             </tr>
1238           </table>
1239           <p>
1240             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> If
1241             you declare "file_list xyz;" (without the pointer), then
1242             including the proper header file is necessary. If you only want
1243             to prototype a pointer, however, the header file is unnecessary.
1244           </p>
1245           <p>
1246             <span class="emphasis"><i class="EMPHASIS">Status:</i></span> Use
1247             with discretion.
1248           </p>
1249         </div>
1250       </div>
1251       <div class="SECT2">
1252         <h2 class="SECT2">
1253           <a name="S35">4.7. General Coding Practices</a>
1254         </h2>
1255         <div class="SECT3">
1256           <h3 class="SECT3">
1257             <a name="S36">4.7.1. Turn on warnings</a>
1258           </h3>
1259           <p>
1260             <span class="emphasis"><i class="EMPHASIS">Explanation</i></span>
1261           </p>
1262           <p>
1263             Compiler warnings are meant to help you find bugs. You should
1264             turn on as many as possible. With GCC, the switch is "-Wall". Try
1265             and fix as many warnings as possible.
1266           </p>
1267         </div>
1268         <div class="SECT3">
1269           <h3 class="SECT3">
1270             <a name="S37">4.7.2. Provide a default case for all switch
1271             statements</a>
1272           </h3>
1273           <p>
1274             <span class="emphasis"><i class=
1275             "EMPHASIS">Explanation:</i></span>
1276           </p>
1277           <p>
1278             What you think is guaranteed is never really guaranteed. The
1279             value that you don't think you need to check is the one that
1280             someday will be passed. So, to protect yourself from the unknown,
1281             always have a default step in a switch statement.
1282           </p>
1283           <p>
1284             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
1285           </p>
1286           <table border="0" bgcolor="#E0E0E0" width="100%">
1287             <tr>
1288               <td>
1289 <pre class="PROGRAMLISTING">
1290 switch( hash_string( cmd ) )
1291 {
1292    case hash_actions_file :
1293       ... code ...
1294       break;
1295
1296    case hash_confdir :
1297       ... code ...
1298       break;
1299
1300    default :
1301       log_error( ... );
1302       ... anomaly code goes here ...
1303       continue; / break; / exit( 1 ); / etc ...
1304
1305 } /* end switch( hash_string( cmd ) ) */
1306 </pre>
1307               </td>
1308             </tr>
1309           </table>
1310           <p>
1311             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> If
1312             you already have a default condition, you are obviously exempt
1313             from this point. Of note, most of the WIN32 code calls
1314             `DefWindowProc' after the switch statement. This API call
1315             *should* be included in a default statement.
1316           </p>
1317           <p>
1318             <span class="emphasis"><i class="EMPHASIS">Another
1319             Note:</i></span> This is not so much a readability issue as a
1320             robust programming issue. The "anomaly code goes here" may be no
1321             more than a print to the STDERR stream (as in load_config). Or it
1322             may really be an abort condition.
1323           </p>
1324           <p>
1325             <span class="emphasis"><i class="EMPHASIS">Status:</i></span>
1326             Programmer discretion is advised.
1327           </p>
1328         </div>
1329         <div class="SECT3">
1330           <h3 class="SECT3">
1331             <a name="S38">4.7.3. Try to avoid falling through cases in a
1332             switch statement.</a>
1333           </h3>
1334           <p>
1335             <span class="emphasis"><i class=
1336             "EMPHASIS">Explanation:</i></span>
1337           </p>
1338           <p>
1339             In general, you will want to have a 'break' statement within each
1340             'case' of a switch statement. This allows for the code to be more
1341             readable and understandable, and furthermore can prevent unwanted
1342             surprises if someone else later gets creative and moves the code
1343             around.
1344           </p>
1345           <p>
1346             The language allows you to plan the fall through from one case
1347             statement to another simply by omitting the break statement
1348             within the case statement. This feature does have benefits, but
1349             should only be used in rare cases. In general, use a break
1350             statement for each case statement.
1351           </p>
1352           <p>
1353             If you choose to allow fall through, you should comment both the
1354             fact of the fall through and reason why you felt it was
1355             necessary.
1356           </p>
1357         </div>
1358         <div class="SECT3">
1359           <h3 class="SECT3">
1360             <a name="S39">4.7.4. Use 'long' or 'short' Instead of 'int'</a>
1361           </h3>
1362           <p>
1363             <span class="emphasis"><i class=
1364             "EMPHASIS">Explanation:</i></span>
1365           </p>
1366           <p>
1367             On 32-bit platforms, int usually has the range of long. On 16-bit
1368             platforms, int has the range of short.
1369           </p>
1370           <p>
1371             <span class="emphasis"><i class="EMPHASIS">Status:</i></span>
1372             open-to-debate. In the case of most FSF projects (including
1373             X/GNU-Emacs), there are typedefs to int4, int8, int16, (or
1374             equivalence ... I forget the exact typedefs now). Should we add
1375             these to IJB now that we have a "configure" script?
1376           </p>
1377         </div>
1378         <div class="SECT3">
1379           <h3 class="SECT3">
1380             <a name="S40">4.7.5. Don't mix size_t and other types</a>
1381           </h3>
1382           <p>
1383             <span class="emphasis"><i class=
1384             "EMPHASIS">Explanation:</i></span>
1385           </p>
1386           <p>
1387             The type of size_t varies across platforms. Do not make
1388             assumptions about whether it is signed or unsigned, or about how
1389             long it is. Do not compare a size_t against another variable of a
1390             different type (or even against a constant) without casting one
1391             of the values.
1392           </p>
1393         </div>
1394         <div class="SECT3">
1395           <h3 class="SECT3">
1396             <a name="S41">4.7.6. Declare each variable and struct on its own
1397             line.</a>
1398           </h3>
1399           <p>
1400             <span class="emphasis"><i class=
1401             "EMPHASIS">Explanation:</i></span>
1402           </p>
1403           <p>
1404             It can be tempting to declare a series of variables all on one
1405             line. Don't.
1406           </p>
1407           <p>
1408             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
1409           </p>
1410           <table border="0" bgcolor="#E0E0E0" width="100%">
1411             <tr>
1412               <td>
1413 <pre class="PROGRAMLISTING">
1414 long a = 0;
1415 long b = 0;
1416 long c = 0;
1417 </pre>
1418               </td>
1419             </tr>
1420           </table>
1421           <p>
1422             <span class="emphasis"><i class="EMPHASIS">Instead of:</i></span>
1423           </p>
1424           <p>
1425             long a, b, c;
1426           </p>
1427           <p>
1428             <span class="emphasis"><i class=
1429             "EMPHASIS">Explanation:</i></span> - there is more room for
1430             comments on the individual variables - easier to add new
1431             variables without messing up the original ones - when searching
1432             on a variable to find its type, there is less clutter to
1433             "visually" eliminate
1434           </p>
1435           <p>
1436             <span class="emphasis"><i class="EMPHASIS">Exceptions:</i></span>
1437             when you want to declare a bunch of loop variables or other
1438             trivial variables; feel free to declare them on one line. You
1439             should, although, provide a good comment on their functions.
1440           </p>
1441           <p>
1442             <span class="emphasis"><i class="EMPHASIS">Status:</i></span>
1443             developer-discretion.
1444           </p>
1445         </div>
1446         <div class="SECT3">
1447           <h3 class="SECT3">
1448             <a name="S42">4.7.7. Use malloc/zalloc sparingly</a>
1449           </h3>
1450           <p>
1451             <span class="emphasis"><i class=
1452             "EMPHASIS">Explanation:</i></span>
1453           </p>
1454           <p>
1455             Create a local struct (on the stack) if the variable will live
1456             and die within the context of one function call.
1457           </p>
1458           <p>
1459             Only "malloc" a struct (on the heap) if the variable's life will
1460             extend beyond the context of one function call.
1461           </p>
1462           <p>
1463             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
1464           </p>
1465           <table border="0" bgcolor="#E0E0E0" width="100%">
1466             <tr>
1467               <td>
1468 <pre class="PROGRAMLISTING">
1469 If a function creates a struct and stores a pointer to it in a
1470 list, then it should definitely be allocated via `malloc'.
1471 </pre>
1472               </td>
1473             </tr>
1474           </table>
1475         </div>
1476         <div class="SECT3">
1477           <h3 class="SECT3">
1478             <a name="S43">4.7.8. The Programmer Who Uses 'malloc' is
1479             Responsible for Ensuring 'free'</a>
1480           </h3>
1481           <p>
1482             <span class="emphasis"><i class=
1483             "EMPHASIS">Explanation:</i></span>
1484           </p>
1485           <p>
1486             If you have to "malloc" an instance, you are responsible for
1487             insuring that the instance is `free'd, even if the deallocation
1488             event falls within some other programmer's code. You are also
1489             responsible for ensuring that deletion is timely (i.e. not too
1490             soon, not too late). This is known as "low-coupling" and is a
1491             "good thing (tm)". You may need to offer a free/unload/destructor
1492             type function to accommodate this.
1493           </p>
1494           <p>
1495             <span class="emphasis"><i class="EMPHASIS">Example:</i></span>
1496           </p>
1497           <table border="0" bgcolor="#E0E0E0" width="100%">
1498             <tr>
1499               <td>
1500 <pre class="PROGRAMLISTING">
1501 int load_re_filterfile( struct client_state *csp ) { ... }
1502 static void unload_re_filterfile( void *f ) { ... }
1503 </pre>
1504               </td>
1505             </tr>
1506           </table>
1507           <p>
1508             <span class="emphasis"><i class="EMPHASIS">Exceptions:</i></span>
1509           </p>
1510           <p>
1511             The developer cannot be expected to provide `free'ing functions
1512             for C run-time library functions ... such as `strdup'.
1513           </p>
1514           <p>
1515             <span class="emphasis"><i class="EMPHASIS">Status:</i></span>
1516             developer-discretion. The "main" use of this standard is for
1517             allocating and freeing data structures (complex or nested).
1518           </p>
1519         </div>
1520         <div class="SECT3">
1521           <h3 class="SECT3">
1522             <a name="S44">4.7.9. Add loaders to the `file_list' structure and
1523             in order</a>
1524           </h3>
1525           <p>
1526             <span class="emphasis"><i class=
1527             "EMPHASIS">Explanation:</i></span>
1528           </p>
1529           <p>
1530             I have ordered all of the "blocker" file code to be in alpha
1531             order. It is easier to add/read new blockers when you expect a
1532             certain order.
1533           </p>
1534           <p>
1535             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> It
1536             may appear that the alpha order is broken in places by POPUP
1537             tests coming before PCRS tests. But since POPUPs can also be
1538             referred to as KILLPOPUPs, it is clear that it should come first.
1539           </p>
1540         </div>
1541         <div class="SECT3">
1542           <h3 class="SECT3">
1543             <a name="S45">4.7.10. "Uncertain" new code and/or changes to
1544             existing code, use FIXME or XXX</a>
1545           </h3>
1546           <p>
1547             <span class="emphasis"><i class=
1548             "EMPHASIS">Explanation:</i></span>
1549           </p>
1550           <p>
1551             If you have enough confidence in new code or confidence in your
1552             changes, but are not *quite* sure of the repercussions, add this:
1553           </p>
1554           <p>
1555             /* FIXME: this code has a logic error on platform XYZ, *
1556             attempting to fix */ #ifdef PLATFORM ...changed code here...
1557             #endif
1558           </p>
1559           <p>
1560             or:
1561           </p>
1562           <p>
1563             /* FIXME: I think the original author really meant this... */
1564             ...changed code here...
1565           </p>
1566           <p>
1567             or:
1568           </p>
1569           <p>
1570             /* FIXME: new code that *may* break something else... */ ...new
1571             code here...
1572           </p>
1573           <p>
1574             <span class="emphasis"><i class="EMPHASIS">Note:</i></span> If
1575             you make it clear that this may or may not be a "good thing
1576             (tm)", it will be easier to identify and include in the project
1577             (or conversely exclude from the project).
1578           </p>
1579         </div>
1580       </div>
1581       <div class="SECT2">
1582         <h2 class="SECT2">
1583           <a name="S46">4.8. Addendum: Template for files and function
1584           comment blocks:</a>
1585         </h2>
1586         <p>
1587           <span class="emphasis"><i class="EMPHASIS">Example for file
1588           comments:</i></span>
1589         </p>
1590         <table border="0" bgcolor="#E0E0E0" width="100%">
1591           <tr>
1592             <td>
1593 <pre class="PROGRAMLISTING">
1594 const char FILENAME_rcs[] = "$Id: coding.html,v 1.54 2010/11/13 12:50:18 fabiankeil Exp $";
1595 /*********************************************************************
1596  *
1597  * File        :  $Source: /cvsroot/ijbswa/current/doc/webserver/developer-manual/coding.html,v $
1598  *
1599  * Purpose     :  (Fill me in with a good description!)
1600  *
1601  * Copyright   :  Written by and Copyright (C) 2001-2009
1602  *                the Privoxy team. http://www.privoxy.org/
1603  *
1604  *                This program is free software; you can redistribute it
1605  *                and/or modify it under the terms of the GNU General
1606  *                Public License as published by the Free Software
1607  *                Foundation; either version 2 of the License, or (at
1608  *                your option) any later version.
1609  *
1610  *                This program is distributed in the hope that it will
1611  *                be useful, but WITHOUT ANY WARRANTY; without even the
1612  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
1613  *                PARTICULAR PURPOSE.  See the GNU General Public
1614  *                License for more details.
1615  *
1616  *                The GNU General Public License should be included with
1617  *                this file.  If not, you can view it at
1618  *                http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
1619  *                or write to the Free Software Foundation, Inc.,
1620  *                51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 ,
1621  *                USA
1622  *
1623  *********************************************************************/
1624
1625
1626 #include "config.h"
1627
1628    ...necessary include files for us to do our work...
1629
1630 const char FILENAME_h_rcs[] = FILENAME_H_VERSION;
1631 </pre>
1632             </td>
1633           </tr>
1634         </table>
1635         <p>
1636           <span class="emphasis"><i class="EMPHASIS">Note:</i></span> This
1637           declares the rcs variables that should be added to the
1638           "show-proxy-args" page. If this is a brand new creation by you, you
1639           are free to change the "Copyright" section to represent the rights
1640           you wish to maintain.
1641         </p>
1642         <p>
1643           <span class="emphasis"><i class="EMPHASIS">Note:</i></span> The
1644           formfeed character that is present right after the comment flower
1645           box is handy for (X|GNU)Emacs users to skip the verbiage and get to
1646           the heart of the code (via `forward-page' and `backward-page').
1647           Please include it if you can.
1648         </p>
1649         <p>
1650           <span class="emphasis"><i class="EMPHASIS">Example for file header
1651           comments:</i></span>
1652         </p>
1653         <table border="0" bgcolor="#E0E0E0" width="100%">
1654           <tr>
1655             <td>
1656 <pre class="PROGRAMLISTING">
1657 #ifndef _FILENAME_H
1658 #define _FILENAME_H
1659 #define FILENAME_H_VERSION "$Id: coding.html,v 1.54 2010/11/13 12:50:18 fabiankeil Exp $"
1660 /*********************************************************************
1661  *
1662  * File        :  $Source: /cvsroot/ijbswa/current/doc/webserver/developer-manual/coding.html,v $
1663  *
1664  * Purpose     :  (Fill me in with a good description!)
1665  *
1666  * Copyright   :  Written by and Copyright (C) 2001-2009
1667  *                the Privoxy team. http://www.privoxy.org/
1668  *
1669  *                This program is free software; you can redistribute it
1670  *                and/or modify it under the terms of the GNU General
1671  *                Public License as published by the Free Software
1672  *                Foundation; either version 2 of the License, or (at
1673  *                your option) any later version.
1674  *
1675  *                This program is distributed in the hope that it will
1676  *                be useful, but WITHOUT ANY WARRANTY; without even the
1677  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
1678  *                PARTICULAR PURPOSE.  See the GNU General Public
1679  *                License for more details.
1680  *
1681  *                The GNU General Public License should be included with
1682  *                this file.  If not, you can view it at
1683  *                http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
1684  *                or write to the Free Software Foundation, Inc.,
1685  *                51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 ,
1686  *                USA
1687  *
1688  *********************************************************************/
1689
1690
1691 #include "project.h"
1692
1693 #ifdef __cplusplus
1694 extern "C" {
1695 #endif
1696
1697    ... function headers here ...
1698
1699
1700 /* Revision control strings from this header and associated .c file */
1701 extern const char FILENAME_rcs[];
1702 extern const char FILENAME_h_rcs[];
1703
1704
1705 #ifdef __cplusplus
1706 } /* extern "C" */
1707 #endif
1708
1709 #endif /* ndef _FILENAME_H */
1710
1711 /*
1712   Local Variables:
1713   tab-width: 3
1714   end:
1715 */
1716 </pre>
1717             </td>
1718           </tr>
1719         </table>
1720         <p>
1721           <span class="emphasis"><i class="EMPHASIS">Example for function
1722           comments:</i></span>
1723         </p>
1724         <table border="0" bgcolor="#E0E0E0" width="100%">
1725           <tr>
1726             <td>
1727 <pre class="PROGRAMLISTING">
1728 /*********************************************************************
1729  *
1730  * Function    :  FUNCTION_NAME
1731  *
1732  * Description :  (Fill me in with a good description!)
1733  *
1734  * parameters  :
1735  *          1  :  param1 = pointer to an important thing
1736  *          2  :  x      = pointer to something else
1737  *
1738  * Returns     :  0 =&gt; Ok, everything else is an error.
1739  *
1740  *********************************************************************/
1741 int FUNCTION_NAME( void *param1, const char *x )
1742 {
1743    ...
1744    return( 0 );
1745
1746 }
1747 </pre>
1748             </td>
1749           </tr>
1750         </table>
1751         <p>
1752           <span class="emphasis"><i class="EMPHASIS">Note:</i></span> If we
1753           all follow this practice, we should be able to parse our code to
1754           create a "self-documenting" web page.
1755         </p>
1756       </div>
1757     </div>
1758     <div class="NAVFOOTER">
1759       <hr width="100%" class="c1">
1760       <table summary="Footer navigation table" width="100%" border="0"
1761       cellpadding="0" cellspacing="0">
1762         <tr>
1763           <td width="33%" align="left" valign="top">
1764             <a href="documentation.html" accesskey="P">Prev</a>
1765           </td>
1766           <td width="34%" align="center" valign="top">
1767             <a href="index.html" accesskey="H">Home</a>
1768           </td>
1769           <td width="33%" align="right" valign="top">
1770             <a href="testing.html" accesskey="N">Next</a>
1771           </td>
1772         </tr>
1773         <tr>
1774           <td width="33%" align="left" valign="top">
1775             Documentation Guidelines
1776           </td>
1777           <td width="34%" align="center" valign="top">
1778             &nbsp;
1779           </td>
1780           <td width="33%" align="right" valign="top">
1781             Testing Guidelines
1782           </td>
1783         </tr>
1784       </table>
1785     </div>
1786   </body>
1787 </html>
1788