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