X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=doc%2Fwebserver%2Fdeveloper-manual%2Fcoding.html;h=3e2753ed5bea9b37934aaaeb26df0cc79c589820;hp=15744c6eaa6ad3a9b60c7592cd52b21997104534;hb=1f8e678f82936f21347922e1b2428ac00cd4d34e;hpb=0114396acb2bab4918dbdf9b8f68b6e21703b2fd diff --git a/doc/webserver/developer-manual/coding.html b/doc/webserver/developer-manual/coding.html index 15744c6e..3e2753ed 100644 --- a/doc/webserver/developer-manual/coding.html +++ b/doc/webserver/developer-manual/coding.html @@ -134,7 +134,7 @@ CLASS="EMPHASIS" understand why or what is being done. A reader may spend a lot more time figuring out what is going on when a simple comment or explanation would have prevented the extra research. Please - help your brother IJB'ers out!

The comments will also help justify the intent of the code. If the comment describes something different than what the code @@ -156,13 +156,13 @@ WIDTH="100%" >

/* if page size greater than 1k ... */
-if ( page_length() > 1024 )
+if (page_length() > 1024)
 {
     ... "block" the page up ...
 }
 
 /* if page size is small, send it in blocks */
-if ( page_length() > 1024 )
+if (page_length() > 1024)
 {
     ... "block" the page up ...
 }
@@ -215,20 +215,20 @@ CLASS="PROGRAMLISTING"
 >/*********************************************************************
  * This will stand out clearly in your code!
  *********************************************************************/
-if ( this_variable == that_variable )
+if (this_variable == that_variable)
 {
    do_something_very_important();
 }
 
 
 /* unfortunately, this may not */
-if ( this_variable == that_variable )
+if (this_variable == that_variable)
 {
    do_something_very_important();
 }
 
 
-if ( this_variable == that_variable ) /* this may not either */
+if (this_variable == that_variable) /* this may not either */
 {
    do_something_very_important();
 }
if ( 1 == X )
+>if (1 == X)
 {
    do_something_very_important();
    ...some long list of commands...
@@ -439,11 +439,11 @@ CLASS="PROGRAMLISTING"
 
 or:
 
-if ( 1 == X )
+if (1 == X)
 {
    do_something_very_important();
    ...some long list of commands...
-} /* -END- if ( 1 == X ) */
Instead of:

int load_some_file( struct client_state *csp )
int load_some_file(struct client_state *csp)Instead of:

int loadsomefile( struct client_state *csp )
-int loadSomeFile( struct client_state *csp )
int loadsomefile(struct client_state *csp) +int loadSomeFile(struct client_state *csp)

(.h) extern int load_aclfile( struct client_state *csp );
-(.c) int load_aclfile( struct client_state *csp )
(.h) extern int load_aclfile(struct client_state *csp); +(.c) int load_aclfile(struct client_state *csp)Instead of: -

(.h) extern int load_aclfile( struct client_state * ); or 
-(.h) extern int load_aclfile(); 
-(.c) int load_aclfile( struct client_state *csp )
(.h) extern int load_aclfile(struct client_state *); or +(.h) extern int load_aclfile(); +(.c) int load_aclfile(struct client_state *csp)

(enumeration) : enum Boolean { FALSE, TRUE };
+>(enumeration) : enum Boolean {FALSE, TRUE};
 (#define) : #define DEFAULT_SIZE 100;
Instead of:

#define USE_IMG_LST 1 or 
+>#define USE_IMG_LST 1 or
 #define _USE_IMAGE_LIST 1 or
-#define USE_IMAGE_LIST_ 1 or 
+#define USE_IMAGE_LIST_ 1 or
 #define use_image_list 1 or
 #define UseImageList 1

if ( this == that )
+>if (this == that)
 {
    ...
 }

if ( this == that ) { ... }

if (this == that) { ... }

or

if ( this == that ) { ... }

if (this == that) { ... }

while ( more lines are read )
+>while (more lines are read)
 {
    /* Please document what is/is not a comment line here */
-   if ( it's a comment ) continue;
+   if (it's a comment) continue;
 
-   do_something( line );
+   do_something(line);
 }
if ( this == that )
+>if (this == that)
 {
    do_something();
    do_something_else();
@@ -971,11 +964,11 @@ CLASS="EMPHASIS"
 >

if ( this == that ) do_something(); do_something_else();

if (this == that) do_something(); do_something_else();

or

if ( this == that ) do_something();

if (this == that) do_something();

structure->flag = ( condition );
structure->flag = (condition);

if ( condition ) { structure->flag = 1; } else { +>if (condition) { structure->flag = 1; } else { structure->flag = 0; }

int first_value = 0; int some_value = 0; int another_value = 0; -int this_variable = 0; - -if ( this_variable == this_variable ) - -first_value = old_value + ( ( some_value - another_value ) - whatever )int function1( ... ) { ...code... - return( ret_code ); + return(ret_code); -} /* -END- function1 */ +} /* -END- function1 */ int function2( ... ) { -} /* -END- function2 */

int function1( ... ) { ...code... return( ret_code ); } int +>int function1( ... ) { ...code... return(ret_code); } int function2( ... ) { }

for ( size_t cnt = 0; cnt < block_list_length(); cnt++ )
+>for (size_t cnt = 0; cnt < block_list_length(); cnt++)
 {
    ....
 }
size_t len = block_list_length(); -for ( size_t cnt = 0; cnt < len; cnt++ ) +for (size_t cnt = 0; cnt < len; cnt++) { .... }This allows a developer to define a const pointer and call your function. If your function does not have the const keyword, we may not be able to use your function. Consider - strcmp, if it were defined as: extern int strcmp( char *s1, - char *s2 );

I could then not use it to compare argv's in main: int main( - int argc, const char *argv[] ) { strcmp( argv[0], "privoxy" - ); }

I could then not use it to compare argv's in main: int + main(int argc, const char *argv[]) { strcmp(argv[0], "privoxy"); + }

Both these pointers are *const*! If the c runtime library maintainers do it, we should too.

Most structures cannot fit onto a normal stack entry (i.e. they are not 4 bytes or less). Aka, a function declaration - like: int load_aclfile( struct client_state csp )

would not work. So, to be consistent, we should declare all - prototypes with "pass by value": int load_aclfile( struct - client_state *csp )

Exception:

/* This is not a local include, but requires a path element. */ 
+>/* This is not a local include, but requires a path element. */
 #include <sys/fileName.h>

switch( hash_string( cmd ) )
+>switch (hash_string(cmd))
 {
-   case hash_actions_file :
+   case hash_actions_file:
       ... code ...
       break;
 
-   case hash_confdir :
+   case hash_confdir:
       ... code ...
       break;
 
-   default :
+   default:
       log_error( ... );
       ... anomaly code goes here ...
       continue; / break; / exit( 1 ); / etc ...
 
-} /* end switch( hash_string( cmd ) ) */

4.7.4. Use 'long' or 'short' Instead of - 'int'

Explanation:

On 32-bit platforms, int usually has the range of long. On - 16-bit platforms, int has the range of short.

Status: open-to-debate. In the case of most FSF - projects (including X/GNU-Emacs), there are typedefs to int4, - int8, int16, (or equivalence ... I forget the exact typedefs - now). Should we add these to IJB now that we have a "configure" - script?

4.7.5. Don't mix size_t and other types4.7.4. Don't mix size_t and other types

4.7.6. Declare each variable and struct on its +>4.7.5. Declare each variable and struct on its own line.

4.7.7. Use malloc/zalloc sparingly4.7.6. Use malloc/zalloc sparingly

4.7.8. The Programmer Who Uses 'malloc' is +>4.7.7. The Programmer Who Uses 'malloc' is Responsible for Ensuring 'free'

int load_re_filterfile( struct client_state *csp ) { ... }
-static void unload_re_filterfile( void *f ) { ... }
int load_re_filterfile(struct client_state *csp) { ... } +static void unload_re_filterfile(void *f) { ... }4.7.9. Add loaders to the `file_list' structure +>4.7.8. Add loaders to the `file_list' structure and in order

4.7.10. "Uncertain" new code and/or changes to - existing code, use FIXME or XXX4.7.9. "Uncertain" new code and/or changes to + existing code, use XXX

/* FIXME: this code has a logic error on platform XYZ, * +>/* XXX: this code has a logic error on platform XYZ, * attempting to fix */ #ifdef PLATFORM ...changed code here... #endif

or:

/* FIXME: I think the original author really meant this... +>/* XXX: I think the original author really meant this... */ ...changed code here...

or:

/* FIXME: new code that *may* break something else... */ +>/* XXX: new code that *may* break something else... */ ...new code here...

const char FILENAME_rcs[] = "$Id$";
-/*********************************************************************
+>/*********************************************************************
  *
- * File        :  $Source$
+ * File        :  $Source
  *
  * Purpose     :  (Fill me in with a good description!)
  *
  * Copyright   :  Written by and Copyright (C) 2001-2009
- *                the Privoxy team. http://www.privoxy.org/
+ *                the Privoxy team. https://www.privoxy.org/
  *
  *                This program is free software; you can redistribute it
  *                and/or modify it under the terms of the GNU General
@@ -2361,7 +2314,7 @@ CLASS="PROGRAMLISTING"
  *                The GNU General Public License should be included with
  *                this file.  If not, you can view it at
  *                http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- *                or write to the Free Software Foundation, Inc., 
+ *                or write to the Free Software Foundation, Inc.,
  *                51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 ,
  *                USA
  *
@@ -2384,7 +2337,7 @@ CLASS="EMPHASIS"
 >Note: This declares the rcs variables that should be
-    added to the "show-proxy-args" page. If this is a brand new
+    added to the "show-version" page. If this is a brand new
     creation by you, you are free to change the "Copyright" section
     to represent the rights you wish to maintain.

#ifndef _FILENAME_H #define _FILENAME_H -#define FILENAME_H_VERSION "$Id$" /********************************************************************* * - * File : $Source$ + * File : $Source * * Purpose : (Fill me in with a good description!) * * Copyright : Written by and Copyright (C) 2001-2009 - * the Privoxy team. http://www.privoxy.org/ + * the Privoxy team. https://www.privoxy.org/ * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General @@ -2442,7 +2394,7 @@ CLASS="PROGRAMLISTING" * The GNU General Public License should be included with * this file. If not, you can view it at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or write to the Free Software Foundation, Inc., + * or write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 , * USA * @@ -2506,10 +2458,10 @@ CLASS="PROGRAMLISTING" * Returns : 0 => Ok, everything else is an error. * *********************************************************************/ -int FUNCTION_NAME( void *param1, const char *x ) +int FUNCTION_NAME(void *param1, const char *x) { ... - return( 0 ); + return 0; }