Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > dcb57bc1f616cf3a8072df2efbbf2767 > files > 31

elinks-0.12-18.mga7.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 7.1.2" />
<style type="text/css">
/* Debug borders */
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
/*
  border: 1px solid red;
*/
}

body {
  margin: 1em 5% 1em 5%;
}

a {
  color: blue;
  text-decoration: underline;
}
a:visited {
  color: fuchsia;
}

em {
  font-style: italic;
}

strong {
  font-weight: bold;
}

tt {
  color: navy;
}

h1, h2, h3, h4, h5, h6 {
  color: #527bbd;
  font-family: sans-serif;
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

h1 {
  border-bottom: 2px solid silver;
}
h2 {
  border-bottom: 2px solid silver;
  padding-top: 0.5em;
}

div.sectionbody {
  font-family: serif;
  margin-left: 0;
}

hr {
  border: 1px solid silver;
}

p {
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

pre {
  padding: 0;
  margin: 0;
}

span#author {
  color: #527bbd;
  font-family: sans-serif;
  font-weight: bold;
  font-size: 1.2em;
}
span#email {
}
span#revision {
  font-family: sans-serif;
}

div#footer {
  font-family: sans-serif;
  font-size: small;
  border-top: 2px solid silver;
  padding-top: 0.5em;
  margin-top: 4.0em;
}
div#footer-text {
  float: left;
  padding-bottom: 0.5em;
}
div#footer-badges {
  float: right;
  padding-bottom: 0.5em;
}

div#preamble,
div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
  margin-right: 10%;
  margin-top: 1.5em;
  margin-bottom: 1.5em;
}
div.admonitionblock {
  margin-top: 2.5em;
  margin-bottom: 2.5em;
}

div.content { /* Block element content. */
  padding: 0;
}

/* Block element titles. */
div.title, caption.title {
  font-family: sans-serif;
  font-weight: bold;
  text-align: left;
  margin-top: 1.0em;
  margin-bottom: 0.5em;
}
div.title + * {
  margin-top: 0;
}

td div.title:first-child {
  margin-top: 0.0em;
}
div.content div.title:first-child {
  margin-top: 0.0em;
}
div.content + div.title {
  margin-top: 0.0em;
}

div.sidebarblock > div.content {
  background: #ffffee;
  border: 1px solid silver;
  padding: 0.5em;
}

div.listingblock > div.content {
  border: 1px solid silver;
  background: #f4f4f4;
  padding: 0.5em;
}

div.quoteblock > div.content {
  padding-left: 2.0em;
}

div.attribution {
  text-align: right;
}
div.verseblock + div.attribution {
  text-align: left;
}

div.admonitionblock .icon {
  vertical-align: top;
  font-size: 1.1em;
  font-weight: bold;
  text-decoration: underline;
  color: #527bbd;
  padding-right: 0.5em;
}
div.admonitionblock td.content {
  padding-left: 0.5em;
  border-left: 2px solid silver;
}

div.exampleblock > div.content {
  border-left: 2px solid silver;
  padding: 0.5em;
}

div.verseblock div.content {
  white-space: pre;
}

div.imageblock div.content { padding-left: 0; }
div.imageblock img { border: 1px solid silver; }
span.image img { border-style: none; }

dl {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
dt {
  margin-top: 0.5em;
  margin-bottom: 0;
  font-style: italic;
}
dd > *:first-child {
  margin-top: 0;
}

ul, ol {
    list-style-position: outside;
}
ol.olist2 {
  list-style-type: lower-alpha;
}

div.tableblock > table {
  border: 3px solid #527bbd;
}
thead {
  font-family: sans-serif;
  font-weight: bold;
}
tfoot {
  font-weight: bold;
}

div.hlist {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
td.hlist1 {
  vertical-align: top;
  font-style: italic;
  padding-right: 0.8em;
}
td.hlist2 {
  vertical-align: top;
}

@media print {
  div#footer-badges { display: none; }
}
/* Workarounds for IE6's broken and incomplete CSS2. */

div.sidebar-content {
  background: #ffffee;
  border: 1px solid silver;
  padding: 0.5em;
}
div.sidebar-title, div.image-title {
  font-family: sans-serif;
  font-weight: bold;
  margin-top: 0.0em;
  margin-bottom: 0.5em;
}

div.listingblock div.content {
  border: 1px solid silver;
  background: #f4f4f4;
  padding: 0.5em;
}

div.quoteblock-content {
  padding-left: 2.0em;
}

div.exampleblock-content {
  border-left: 2px solid silver;
  padding-left: 0.5em;
}
</style>
<title>Hacking ELinks</title>
</head>
<body>
<div id="header">
<h1>Hacking ELinks</h1>
</div>
<div id="preamble">
<div class="sectionbody">
<p>Welcome, mere mortal, to the realm of evil unindented code, heaps of one or
two-letter variables, seas of gotos accompanied with 30-letters labels in Czech
language with absolutely no meaning, welcome to the realm of ELinks code!</p>
<p>Don't take this file as a law. We may or may not be right in these issues.</p>
<p>Motto: I didn't expect someone to look at the source, so it's unreadable.
       &#8212;Mikulas</p>
</div>
</div>
<h2>Language files</h2>
<div class="sectionbody">
<p>Each UI output should use language files in order to be able to translate the
messages to a desired language.  Those language files reside in the po/ subdir. If
you want to update a .po file, please read the gettext manual available at
&lt;http://www.gnu.org/manual/gettext&gt;. In order to actually use your updates on
your own system, you have to have the gettext tools installed.</p>
</div>
<h2>ELinks philosophy</h2>
<div class="sectionbody">
<p>ELinks is based on the philosophy of asynchronism.  That means, you pass a
callback to each function, and when the requested task finishes sometime in the
unclear future, the callback will be called in order to notify you that you can
go on.</p>
<p>When you use multiple elinks instances at once, normally only one of them is a
<em>master</em>, and the rest of them are just kinda dumb terminals.  So if you want
to test some new feature, you have to start elinks with the <em>-no-connect</em>
parameter, otherwise it will just connect to an already running elinks and you
won't see your great new feature that you just added with such much pain.</p>
<p>There are two basic structures in ELinks.  Connection and session - their names
should be self-descriptive.  Only note that connections may or may not have
sessions attached.  I.e. if you type some URL, then start loading it and then
press ACT_BACK (KEY_LEFT), the connection will lose its session.  So you should
never pretend that it has one.</p>
<p>The UI plainly needs a rewrite as it's extremely ugly ;-).  Cut'n'paste from
some existing code and modify appropriately, if you want one :).</p>
<p>Some common used functions (e.g., malloc() or free()) have their own clones
inside ELinks and you should use them (e.g., mem_alloc() or mem_free()) instead.</p>
<p>If you want to have anything else documented here, write a description and send
us a patch.</p>
<p>Various parts are described either below or in README* file(s) of appropriate
directory.</p>
</div>
<h2>HTML parser</h2>
<div class="sectionbody">
<p>The following was found in the mailing list archive - Mikulas wrote it:</p>
<p>The entry of the parser is parse_html.  This function gets an html source to
parse (pointers html and eof) and the functions it should call when it wants to
produce output (put_chars, line_break, init, special).  f is a pointer that is
passed to that function, head is the HTTP header (for refresh).  The function
uses a stack (struct list_head html_stack; it is set up by the caller of
parse_html), places formatting info into it, and calls output functions.
put_chars to write text, line_break for new line, init (currently unused),
special (tags, forms, etc&#8230;).  These functions read the parameters from the
stack (struct html_element) and do the actual rendering (some while ago, people
wanted to use the parser for a graphics browser, so I wrote it so that it could
produce graphics output by replacing the output functions).</p>
<p>Html renderer is in html_r.c.  html_interpret formats the whole screen.  It
calls cached_format_html which formats one document (frame) or returns directly
a formatted document from the cache.  cached_format_html then calls
format_html, which sets up rendering and calls format_html_part.
format_html_part is used for formatting the whole document or formatting parts
of tables. It calls parse_html.</p>
<p>The rendering functions put_chars_conv, line_break, html_special receive struct
part * from the parser.  They render the text or calculate the size of the text
(in case of tables).  struct part has a pointer to struct f_data - a structure
that holds the actual formatted data.  If the pointer is NULL, rendering
functions only calculate size.</p>
</div>
<h2>Documents management</h2>
<div class="sectionbody">
<p>Just a few words regarding the document structures. To understand the code, it
is important to note the difference between rendered documents and document
views.</p>
<p>A document is rendered (or formatted) one time once it is loaded - then it
stays formatted in a cache for some time, and whoever opens the document just
attaches that formatted document. That is, if you open the same document in
three tabs, they all show contents of the same single underlying struct
document and family.</p>
<p>However, each of the tabs gets own struct document_view. That structure
contains information about the currently active link, the position in the document,
the size of the viewport, search terms currently highlighted etc. This structure
stays around only when the document is displayed in some session, thus its
lifespan is always shorter than struct document's. document_view to document
mapping is many to one.</p>
<p>There is a third structure, struct view_state. This structure contains
information about the current link and position, contents of forms fields,
and so. Like struct document_view, it contains information specific to
a certain view of the document, and the mapping to document is many to one.
Unlike document_view, though, its lifespan is much longer. When you chain
those view_states up, you get a session history.</p>
</div>
<h2>Lua support</h2>
<div class="sectionbody">
<p>Peter Wang wrote this on the mailing list:</p>
<p>The parts of the Links-Lua and ELinks code that related to Lua are mostly
wrapped inside #ifdef HAVE_LUA &#8230;  #endif conditions, so they're easy to find.
And also lua.c.</p>
<p>In certain situations, I put some hooks into the C code.  These prepare the C
code to run some Lua code, run it, then translate the return values to
something meaningful to the C code.  They are really simple, but I had to put
in some cruft.</p>
<div class="listingblock">
<div class="title">Example: The code implementing the Go To URL dialog box hook :</div>
<div class="content">
<pre><tt>void goto_url_with_hook(struct session *ses, unsigned char *url)
{
#ifndef HAVE_LUA
        goto_url(ses, url);
#else
        lua_State *L = lua_state;
        int err;

        lua_getglobal(L, "goto_url_hook");                                 <b>(1)</b>
        if (lua_isnil(L, -1)) {
                lua_pop(L, 1);
                goto_url(ses, url);
                return;
        }
        lua_pushstring(L, url);                                            <b>(2)</b>
        if (list_empty(ses-&gt;history)) lua_pushnil(L);
        else lua_pushstring(L, cur_loc(ses)-&gt;vs.url);

        if (prepare_lua(ses)) return;                                      <b>(3)</b>
        err = lua_call(L, 2, 1);                                           <b>(4)</b>
        finish_lua();                                                      <b>(5)</b>
        if (err) return;

        if (lua_isstring(L, -1))                                           <b>(6)</b>
                goto_url(ses, (unsigned char *) lua_tostring(L, -1));
        else if (!lua_isnil(L, -1))
                alert_lua_error("goto_url_hook must return a string or nil");
        lua_pop(L, 1);
#endif
}</tt></pre>
</div></div>
<p>Quick description of what it does:</p>
<ol>
<li>
<p>
Get the value named `goto_url_hook' from the Lua state.  If it doesn't
    exist, the user hasn't installed a hook so continue the normal way.
</p>
</li>
<li>
<p>
Push the arguments onto the Lua stack for the function call.
    `goto_url_hook' takes two parameters, the new URL and the current URL, so
    we push them on.
</p>
</li>
<li>
<p>
Some stuff to prepare for running Lua.  This is in case, for example, the
    Lua function contains bugs, we want to trap some of that.  It's supposed to
    enable a mechanism where ^C will break out of infinite loops and such, but
    that's not working so good.
</p>
</li>
<li>
<p>
Call the Lua function, i.e. goto_url_hook
</p>
</li>
<li>
<p>
Disable the error trapping stuff.
</p>
</li>
<li>
<p>
Look at the return value of goto_url_hook and do something appropriate.
</p>
</li>
</ol>
<p>[ If you want to know the lua_* functions, you're going to have to read the
  Lua API manual ]</p>
<p>That's basically all the Links-Lua stuff is, a bunch of hooks that pass
arguments to some arbitrary Lua code, then read in return values and interpret
them.  But it works because Lua is a programming language, and that enables you
to do what you would from C, as long as you stick to the C&lt;-&gt;Lua interface.</p>
<p>The code to allow binding Lua code to a keypress is slightly different then the
hooks, but not much.  Instead of branching off to some C code when a key is
pressed, we branch off to some Lua code.</p>
</div>
<h2>Coding style</h2>
<div class="sectionbody">
<p>Mikulas once said that <em>it was hard to code, so it should be hard to read</em> -
and he drove by this when he was writing links.  However, we do NOT drive by
this rule anymore ;-).  We strongly welcome cleanup patches and you have 99%
chance that they will be applied, if they are correct.</p>
<p>Variable names should be descriptive.  Well, in worst case we'll accept <em>i</em> for
index, but if possible don't do even this :).  You should try to declare them
on the lowest level possible, so their declaration and initialization will be
near their usage and you will also prevent reuse of one variable for two
completely different things.  Yes, that's another thing you shouldn't do.  If
reasonable, initialize variables during their declaration and don't group too
many variables in one line.  ALWAYS make a blank line after the declaration
part.</p>
<p>Be sure to prefix all local functions with <em>static</em>.</p>
<p>Indent shift width is 8 characters&#8212;that means one tab character.</p>
<p><em>{</em> should be on the same line as conditions near for, if, while, switch etc.,
but on separate lines near function headers in function definitions.</p>
<p>Please _USE_ one tab instead of 8 spaces!  It makes things easier.</p>
<p>Always place spaces around <em>=</em>, after <em>,</em> and - if reasonable - around other
operators as well.  You shouldn't make assignments in conditionals:</p>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>foo = mem_alloc(1234);
if (!foo) panic("out of memory");</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>if (!(foo = mem_alloc(1234))) panic("out of memory");</tt></pre>
</div></div>
<p>Note that thou shalt ALWAYS test for success on everything - we are supposed
to die with honor if we are to die!</p>
<p>One good point is regarding what language we actually code in. We use C89
_exclusively_ (if we don't, we provide a fall-back way for survival in C89
environment). ELinks is supposed to work on a large number of more or less
weird and ancient systems and we are already used to C89 anyway. The most
remarkable implication of no C99 are no C++ (//) comments and declarations
at the start of block only.</p>
</div>
<h2>Inline functions</h2>
<div class="sectionbody">
<p>Various standards and compilers set restrictions on inline functions:</p>
<ul>
<li>
<p>
C89 doesn't support them at all.
</p>
</li>
<li>
<p>
According to C99 6.7.4p6, if a translation unit declares a function
  as inline and not static, then it must also define that function.
</p>
</li>
<li>
<p>
According to C99 6.7.4p3, an inline definition of a non-static
  function must not contain any non-const static variables, and must
  not refer to anything static outside of it.  According to C99
  6.7.4p6 however, if the function is ever declared without inline or
  with extern, then its definition is not an inline definition even if
  the definition includes the inline keyword.
</p>
</li>
<li>
<p>
Sun Studio 11 on Solaris 9 does not let non-static inline functions
  refer to static identifiers.  Unlike C99 6.7.4p3, this seems to
  apply to all definitions of inline functions, not only inline
  definitions.  See ELinks bug 1047.
</p>
</li>
<li>
<p>
GCC 4.3.1 warns if a function is declared inline after being called.
  Perhaps it means such calls cannot be inlined.
</p>
</li>
<li>
<p>
In C99, a function definition with extern inline means the compiler
  should inline calls to that function and must also emit out-of-line
  code that other translation units can call.  In GCC 4.3.1, it
  instead means the out-of-line definition is elsewhere.
</p>
</li>
</ul>
<p>So to be portable to all of those, we use inline functions in only
these ways:</p>
<ul>
<li>
<p>
Define as static inline in a *.c file.  Perhaps declare in that same
  file.  On C89, we #define inline to nothing.
</p>
</li>
<li>
<p>
Define as static inline in a *.h file.  Perhaps declare in that same
  file.  On C89, we #define inline to nothing, and extra copies of the
  function may then get emitted but anyway it'll work.
</p>
</li>
<li>
<p>
Declare without inline in a <strong>.h file, and define with NONSTATIC_INLINE
  in a </strong>.c file.  Perhaps also declare with NONSTATIC_INLINE in the same
  *.c file.  On Sun Studio 11, we #define NONSTATIC_INLINE to nothing.
</p>
</li>
</ul>
</div>
<h2>Comments</h2>
<div class="sectionbody">
<p>Use blank lines frequently to separate chunks of code.  And use magic <tt>/*</tt> and
<tt>*/</tt> to give others an idea about what it does and about possible pitfalls.
(Do not use //, as that is not a feature of ANSI C a.k.a. C89.)</p>
<p>Keep in mind that if there's an object and verb in the comment (and it is, in
most cases), it is a sentence, so it has to start with a capital letter and end
with a fullstop ;-).  If you want to share your opinion or investigations, you
should sign yourself; e.g.,</p>
<div class="literalblock">
<div class="content">
<pre><tt>/* TODO: Move this far away! --pasky */</tt></pre>
</div></div>
<p>Comments should be written in _ENGLISH_ only.</p>
<p>All three following styles of comments are acceptable:</p>
<div class="listingblock">
<div class="content">
<pre><tt>/*
 * Bla bla bla.
 * blabla?
 */

/* Bla bla bla.
 * blabla?
 */

/* Bla bla bla.
 * blabla? */</tt></pre>
</div></div>
<p>The best one usually depends on the actual context.</p>
<p>If you describe a structure, make either:</p>
<div class="listingblock">
<div class="content">
<pre><tt>char *name; /* name of the tag */
void (*func)(unsigned char *); /* function hopefully handling the
                                * content of the tag */
int linebreak; /* needed for break of a line? */</tt></pre>
</div></div>
<p>or</p>
<div class="listingblock">
<div class="content">
<pre><tt>/* Name of the tag */
char *name;
/* Function hopefully handling the content of the tag */
void (*func)(unsigned char *);

/* Do we need to break a line? */
int linebreak;</tt></pre>
</div></div>
<p>Same if you comment the code.  If the comment is</p>
<div class="literalblock">
<div class="content">
<pre><tt>/* then do it now! */</tt></pre>
</div></div>
<p>place it on the same line as the command, if it's</p>
<div class="literalblock">
<div class="content">
<pre><tt>/* We have to parse this crap now, as it is going to be freed in free_crap() */</tt></pre>
</div></div>
<p>place it on the preceding line.</p>
</div>
<h2>More about style</h2>
<div class="sectionbody">
<p>Note: We use short variables names and stupid examples here, do not take that
      as a guideline for _REAL_ coding.  Always use descriptive variables
      names and do not write stupid code ;).</p>
<h3>General style is:</h3>
<div class="listingblock">
<div class="content">
<pre><tt>[blank line]
/* This is a comment about that function */
int
func(int a, int b)
{
        int c;

        c = a * b;
        if (c) {
                int d;

                ...
        } else {
                int e;

                ...
        }

        return (c * d);
}</tt></pre>
</div></div>
<h3>You should observe the following rules:</h3>
<p>Always have a blank line before a function declaration or comment.</p>
<p>Please add a comment about what the function does.</p>
<p>A function's type must be on first line while the function's name is on the
second line.</p>
<p>If the parameters list exceeds 80 columns then wrap them after a comma to
the next line and align them using tabs and/or spaces with the first
parameter.</p>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>int
func(int p1, int p2, int p3,
     struct very_long_name_for_a_structure *s,
     unsigned long last_parameter)
{
        int v;

        ...
}</tt></pre>
</div></div>
<p>The start of a function's body should be alone on the first column.</p>
<p>Always have a blank line after declarations.</p>
<p>Always have spaces around operators.</p>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>c = a * b - (a + b);</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>c=a*b-(a+b);</tt></pre>
</div></div>
<ul>
<li>
<p>
Keep affectation outside of conditional tests.
</p>
</li>
</ul>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>c = a;
if (c == b) {...</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>if ((c = a) == b) {...</tt></pre>
</div></div>
<p>Never use spaces within ().</p>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>if (a) ...</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>if ( a ) ...</tt></pre>
</div></div>
<p>Indent.</p>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>foreach (a, b)
        if (a == c)
                ...
        else
                ...</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>foreach(a, b) if (a == c) ...  else ...</tt></pre>
</div></div>
<p>If you have a chain of if () { .. } else if () { .. } else { .. } with longer
statements, you can insert a blank line before each else line.</p>
<p>Label names should start on the first column and a blank line should be
inserted before it.</p>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>        some_code(aaa);

label:
        some_other_code(bbb);</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>        some_code(aaa);
        label:
        some_other_code(bbb);</tt></pre>
</div></div>
<p>Wrap conditions on spaces before operators like &amp;&amp; or ||.</p>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>if (some_very_long_thing1 == some_very_long_thing2
    &amp;&amp; (test1 == test2
        || some_very_long_thing3 == some_very_long_thing4)) {
        ....
}</tt></pre>
</div></div>
<p>Please remove useless spaces or tabs at the end of lines.  Vim has a syntax
file called "Whitespace (add)" &#8230;</p>
<p>Please keep includes in alphabetical order unless a specific order is required
for compilation on weird systems (then please at least make a proper comment
about that).</p>
<p>Please declare functions without parameters as taking void parameter:</p>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>int
func(void)
{
        some_code();
}</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>int
func()
{
        some_code();
}</tt></pre>
</div></div>
<p>Please write if (), while (), switch (), for (), &#8230;. instead of if(),
while(), switch(), for()&#8230;  Same thing apply for all iterators and tests
(e.g. foreach, foreachback).</p>
<p>Please write sizeof(something) instead of sizeof something.</p>
<p>Use assert() and assertm() where applicable. It will prevent hidden bugs.</p>
<p>Names of enum constants should be in upper case.</p>
<p>Please call the charset "utf8" or "UTF8" in identifiers, "UTF-8"
elsewhere, and "utf_8" only for compatibility.</p>
<p>If you see code in ELinks that doesn't follow these rules, fix it or tell us
about it.</p>
<p>All the .c files MUST start by a short one-line description:</p>
<div class="literalblock">
<div class="content">
<pre><tt>/* &lt;short one-line description&gt; */</tt></pre>
</div></div>
<p>All the .h files MUST start by an anti-reinclusion ifdef.
The macro is</p>
<div class="literalblock">
<div class="content">
<pre><tt>EL_&lt;path_relative_to_src:s/[\/.]/_/&gt;.</tt></pre>
</div></div>
<p>There are obviously exceptions to these rules, but don't make a rule from your
exception and be prepared to defend your exception at anytime ;).</p>
</div>
<h2>Coding practices</h2>
<div class="sectionbody">
<h3>Use bitfields to store boolean values</h3>
<p>If speed is not critical and especially if you are messing with some struct
where size might matter, feel encouraged to use bitfields to store boolean (or
tristate or tetrastate ;) values (e.g. unsigned int foo:1 for one-bit field).
HOWEVER please ALWAYS specify signedness of all such fields. It is very easy
to reach the top bit in these cases, and with int foo:1, foo would be either 0
or -1, which is probably not what you want.</p>
<h3>Wrap hard initializations of structures with macros</h3>
<p>This should be done if the structure's initializers are going to be spread
widely (so that we can grep for them easily), there are massive typecasts
needed in most of the initializers, you feel that order of the fields in
structure is unstable yet and it is likely to change (and you don't want to
change the initializers everytime you do so), or in similar cases.</p>
<div class="listingblock">
<div class="title">Example: You can do it like:</div>
<div class="content">
<pre><tt>struct example {
        int a;
        int b;
        char *c;
};
#define INIT_EXAMPLE(a, b, c) {a, b, c}
#define NULL_EXAMPLE {0, 0, NULL}

struct example t[] = {
        INIT_EXAMPLE(1, 2, "abc"),
        INIT_EXAMPLE(3, 4, "def"),
        NULL_EXAMPLE
};

struct example t = NULL_EXAMPLE;</tt></pre>
</div></div>
<h3>Please try to keep order of fields</h3>
<p>Please try to keep order of fields from max. to min. of size of each type of
fields, especially in structures:</p>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>long a;
int b;
char c;</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>char c;
int b;
long b;</tt></pre>
</div></div>
<p>It will help to reduce memory padding on some architectures. Note that this
applies only if this will not affect logical division of the structure. The
logical composition always takes precedence over this optimization, modulo
some very rare critical structures.</p>
<h3>Please do not use sizeof(struct item_struct_name)</h3>
<p>Instead use sizeof(*item) when possible.</p>
<div class="listingblock">
<div class="content">
<pre><tt>struct example {
        int *integers;
        void **pointers;
}

struct example *item;</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>item = mem_alloc(sizeof(*item));
memset(item, 0, sizeof(*item));
item-&gt;integers = mem_calloc(10, sizeof(*item-&gt;integers));
item-&gt;pointers = mem_calloc(10, sizeof(*item-&gt;pointers));</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>item = mem_alloc(sizeof(struct example));
memset(item, 0, sizeof(struct example));
item-&gt;integers = mem_calloc(10, sizeof(int));
item-&gt;pointers = mem_calloc(10, sizeof(void *));</tt></pre>
</div></div>
<p>The preferred form eases future changes in types, and maintain size vs type
coherence.</p>
<h3>Please postfix defined types with _T</h3>
<div class="listingblock">
<div class="content">
<pre><tt>typedef int (some_func_T)(void *);
typedef long long our_long_T;</tt></pre>
</div></div>
<h3>Please use mode_t and S_I???? macros instead of numeric modes</h3>
<div class="listingblock">
<div class="title">Example: Use:</div>
<div class="content">
<pre><tt>mode_t mode = S_IRWXU | S_IRGRP | S_IROTH;</tt></pre>
</div></div>
<div class="listingblock">
<div class="title">Example: Instead of:</div>
<div class="content">
<pre><tt>int mode = 0744;</tt></pre>
</div></div>
<p>Note that S_IREAD, S_IWRITE and S_IEXEC are obsolete, you should use S_IRUSR,
S_IWUSR, S_IXUSR instead.</p>
</div>
<h2>Patches</h2>
<div class="sectionbody">
<p>Please send unified patches only.</p>
<div class="listingblock">
<div class="title">Example: The recommended way is:</div>
<div class="content">
<pre><tt>cp -a elinks/ elinks+mysuperfeature/
cd elinks+mysuperfeature/
*clap clap*
*clickety clickey*
make
./elinks -no-connect
*goto clap*
cd ..
diff -ru elinks/ elinks+mysuperfeature/ &gt;elinks-mysuperfeature.patch</tt></pre>
</div></div>
<p>Please manually remove any bloat like changes in ./configure, whitespace
changes etc. ;-).</p>
<p>We also accept output from <tt>git diff</tt> :).  The statement about bloat
removing above still applies.</p>
<p>Big patches are hard to review so if your feature involves a lot of changes
please consider splitting it in appropriate bits. Appropriate could mean:</p>
<ul>
<li>
<p>
Keep trivial changes like indenting, renaming, fixing comments separate.
</p>
</li>
<li>
<p>
Keep movements of (bigger) code snippets separate from changes in them.
</p>
</li>
</ul>
<p>Note that it makes no sense to separate patches by directories. The
important thing is to separate big changes to smaller ones and smaller ones,
breaking it to the "thinnest" possible level where the change is still
sufficiently self-contained.</p>
</div>
<h2>Advantages of <tt>&#8212;enable-debug</tt> configure option</h2>
<div class="sectionbody">
<p>Since ELinks 0.4pre11, a memory debugger can be enabled using the
<tt>&#8212;enable-debug</tt> configure script option.  It may help to find memleaks and more
which is why everybody concerned with ELinks develepment should use it:</p>
<p>In 0.5 versions <tt>&#8212;enable-debug</tt> add some fancy things:
- many data integrity checking (see <tt>lists.h</tt>)
- hotkey debugging: especially cool for translators, it highlights redundant
  hotkeys in a menu.  (See also po/perl/README.)
- more errors messages
- low bug tolerance: it will core dump on some errors instead of just writing
  an error description.
- internal backtrace feature (always enabled if possible)
- and more&#8230;</p>
<p>Before sending a patch, always try to compile and test it with
<tt>&#8212;enable-debug</tt>, then in normal mode, then in <tt>&#8212;fast-mem</tt> mode. If it fails
to compile or execute in one of these modes, then rework it.</p>
<p>Happy hacking!</p>
</div>
<div id="footer">
<div id="footer-text">
Last updated 28-Oct-2012 15:01:59 EEST
</div>
</div>
</body>
</html>