X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=doc%2Fwebserver%2Fdeveloper-manual%2Fcoding.html;h=c0fbcaa5a22a85011f6da95f769c47f9b0ec7204;hb=1c4bd7276a5f733e283c0484803bfca670f76654;hp=7d7854e3f9ab5cfaa3c727a54825d70b918c5371;hpb=6d810395712f0337682205c4ea304009c86c128f;p=privoxy.git diff --git a/doc/webserver/developer-manual/coding.html b/doc/webserver/developer-manual/coding.html index 7d7854e3..c0fbcaa5 100644 --- a/doc/webserver/developer-manual/coding.html +++ b/doc/webserver/developer-manual/coding.html @@ -2,7 +2,6 @@ Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
-The comments will also help justify the intent of the code. If @@ -104,13 +94,13 @@ Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
/* 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 ... } @@ -148,20 +138,20 @@ is actually being done. /********************************************************************* * 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(); } @@ -207,12 +197,12 @@ if ( this_variable == that_variable ) /* this may not either */ * This will stand out clearly in your code, * But the second example won't. *********************************************************************/ -if ( this_variable == this_variable ) +if (this_variable == this_variable) { do_something_very_important(); } -if ( this_variable == this_variable ) /*can you see me?*/ +if (this_variable == this_variable) /*can you see me?*/ { do_something_very_important(); /*not easily*/ } @@ -224,7 +214,7 @@ if ( this_variable == this_variable ) /*can you see me?*/ int urls_read = 0; /* # of urls read + rejected */ int urls_rejected = 0; /* # of urls rejected */ -if ( 1 == X ) +if (1 == X) { do_something_very_important(); } @@ -318,7 +308,7 @@ short do_something_very_important(@@ -999,7 +985,7 @@ is_web_page_blank();@@ -405,7 +395,7 @@ int msiis5hack = 0; int msIis5Hack = 0; -if ( 1 == X ) +if (1 == X) { do_something_very_important(); ...some long list of commands... @@ -326,11 +316,11 @@ if ( 1 == X ) or: -if ( 1 == X ) +if (1 == X) { do_something_very_important(); ...some long list of commands... -} /* -END- if ( 1 == X ) */ +} /* -END- if (1 == X) */@@ -417,8 +407,8 @@ int load_some_file( struct client_state *csp ) -int load_some_file( struct client_state *csp ) +int load_some_file(struct client_state *csp)@@ -444,8 +434,8 @@ int loadSomeFile( struct client_state *csp ) -int loadsomefile( struct client_state *csp ) -int loadSomeFile( struct client_state *csp ) +int loadsomefile(struct client_state *csp) +int loadSomeFile(struct client_state *csp)@@ -457,9 +447,9 @@ 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)@@ -485,7 +475,7 @@ int loadSomeFile( struct client_state *csp ) -(.h) extern int load_aclfile( struct client_state * ); or +(.h) extern int load_aclfile(struct client_state *); or (.h) extern int load_aclfile(); -(.c) int load_aclfile( struct client_state *csp ) +(.c) int load_aclfile(struct client_state *csp)@@ -588,7 +578,7 @@ int loadSomeFile( struct client_state *csp ) -(enumeration) : enum Boolean { FALSE, TRUE }; +(enumeration) : enum Boolean {FALSE, TRUE}; (#define) : #define DEFAULT_SIZE 100;@@ -822,7 +808,7 @@ int function2( ... ) Instead of: -if ( this == that ) +if (this == that) { ... } @@ -600,13 +590,13 @@ if ( this == that ) Instead of:- if ( this == that ) { ... } + if (this == that) { ... }
or
- if ( this == that ) { ... } + if (this == that) { ... }
Note: In @@ -627,12 +617,12 @@ if ( this == that )
@@ -660,7 +650,7 @@ while ( more lines are read ) -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); }@@ -806,14 +792,14 @@ function_name(); int function1( ... ) { ...code... - return( ret_code ); + return(ret_code); -} /* -END- function1 */ +} /* -END- function1 */ int function2( ... ) { -} /* -END- function2 */ +} /* -END- function2 */ -if ( this == that ) +if (this == that) { do_something(); do_something_else(); @@ -673,13 +663,13 @@ if ( this == that ) Instead of:- 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();
Note: The @@ -701,7 +691,7 @@ if ( this == that )
@@ -710,7 +700,7 @@ structure->flag = ( condition ); Instead of: -structure->flag = ( condition ); +structure->flag = (condition);- if ( condition ) { structure->flag = 1; } else { + if (condition) { structure->flag = 1; } else { structure->flag = 0; }
@@ -745,10 +735,6 @@ 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 ); } int + int function1( ... ) { ...code... return(ret_code); } int function2( ... ) { }
@@ -869,16 +855,16 @@ static const char * const url_code_map[256] = int function1( ... ) { - if ( 1 ) + if (1) { - return( ALWAYS_TRUE ); + return ALWAYS_TRUE; } else { - return( HOW_DID_YOU_GET_HERE ); + return HOW_DID_YOU_GET_HERE; } - return( NEVER_GETS_HERE ); + return NEVER_GETS_HERE; }
-for ( size_t cnt = 0; cnt < block_list_length(); cnt++ ) +for (size_t cnt = 0; cnt < block_list_length(); cnt++) { .... } @@ -1032,7 +1018,7 @@ 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++) { .... } @@ -1059,11 +1045,11 @@ 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 ); + 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 @@ -1081,12 +1067,12 @@ for ( size_t cnt = 0; cnt < len; cnt++ )
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 ) + 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 ) + prototypes with "pass by value": int load_aclfile(struct + client_state *csp)
@@ -1287,22 +1273,22 @@ extern file_list *xyz;@@ -1357,27 +1343,7 @@ switch( hash_string( cmd ) ) -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 ) ) */ +} /* 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 types + 4.7.4. Don't mix size_t and other types
- 4.7.6. Declare each variable and struct on its own + 4.7.5. Declare each variable and struct on its own line.
@@ -1445,7 +1411,7 @@ long c = 0;
- 4.7.7. Use malloc/zalloc sparingly + 4.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'
@@ -1498,8 +1464,8 @@ list, then it should definitely be allocated via `malloc'.
@@ -1519,7 +1485,7 @@ static void unload_re_filterfile( void *f ) { ... } -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 and + 4.7.8. Add loaders to the `file_list' structure and in order
@@ -1540,8 +1506,8 @@ static void unload_re_filterfile( void *f ) { ... }
- 4.7.10. "Uncertain" new code and/or changes to - existing code, use FIXME or XXX + 4.7.9. "Uncertain" new code and/or changes to + existing code, use XXX
- /* FIXME: this code has a logic error on platform XYZ, * - attempting to fix */ #ifdef PLATFORM ...changed code here... - #endif + /* 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... */ ...new + /* XXX: new code that *may* break something else... */ ...new code here...
@@ -1591,15 +1556,15 @@ static void unload_re_filterfile( void *f ) { ... }
-const char FILENAME_rcs[] = "$Id: coding.html,v 1.54 2010/11/13 12:50:18 fabiankeil Exp $"; +const char FILENAME_rcs[] = "$I<!-- Break CVS Substitution -->d$"; /********************************************************************* * - * File : $Source: /cvsroot/ijbswa/current/doc/webserver/developer-manual/coding.html,v $ + * File : $S<!-- Break CVS Substitution -->ource$ * * 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 @@ -1656,15 +1621,15 @@ const char FILENAME_h_rcs[] = FILENAME_H_VERSION;#ifndef _FILENAME_H #define _FILENAME_H -#define FILENAME_H_VERSION "$Id: coding.html,v 1.54 2010/11/13 12:50:18 fabiankeil Exp $" +#define FILENAME_H_VERSION "$I<!-- Break CVS Substitution -->d$" /********************************************************************* * - * File : $Source: /cvsroot/ijbswa/current/doc/webserver/developer-manual/coding.html,v $ + * File : $S<!-- Break CVS Substitution -->ource$ * * 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 @@ -1738,10 +1703,10 @@ extern const char FILENAME_h_rcs[]; * 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; }@@ -1756,7 +1721,7 @@ int FUNCTION_NAME( void *param1, const char *x )-
+