kusano 7d535a
IJG JPEG LIBRARY:  CODING RULES
kusano 7d535a
shun-iwasawa 82a8f5
This file was part of the Independent JPEG Group's software:
kusano 7d535a
Copyright (C) 1991-1996, Thomas G. Lane.
shun-iwasawa 82a8f5
It was modified by The libjpeg-turbo Project to include only information
shun-iwasawa 82a8f5
relevant to libjpeg-turbo.
shun-iwasawa 82a8f5
For conditions of distribution and use, see the accompanying README.ijg file.
kusano 7d535a
kusano 7d535a
kusano 7d535a
Since numerous people will be contributing code and bug fixes, it's important
kusano 7d535a
to establish a common coding style.  The goal of using similar coding styles
kusano 7d535a
is much more important than the details of just what that style is.
kusano 7d535a
kusano 7d535a
In general we follow the recommendations of "Recommended C Style and Coding
kusano 7d535a
Standards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and
kusano 7d535a
Brader).  This document is available in the IJG FTP archive (see
kusano 7d535a
jpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl).
kusano 7d535a
kusano 7d535a
Block comments should be laid out thusly:
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 *  Block comments in this style.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
We indent statements in K&R style, e.g.,
shun-iwasawa 82a8f5
        if (test) {
shun-iwasawa 82a8f5
          then-part;
shun-iwasawa 82a8f5
        } else {
shun-iwasawa 82a8f5
          else-part;
shun-iwasawa 82a8f5
        }
kusano 7d535a
with two spaces per indentation level.  (This indentation convention is
kusano 7d535a
handled automatically by GNU Emacs and many other text editors.)
kusano 7d535a
kusano 7d535a
Multi-word names should be written in lower case with underscores, e.g.,
kusano 7d535a
multi_word_name (not multiWordName).  Preprocessor symbols and enum constants
kusano 7d535a
are similar but upper case (MULTI_WORD_NAME).  Names should be unique within
shun-iwasawa 82a8f5
the first fifteen characters.
kusano 7d535a
kusano 7d535a
Note that each function definition must begin with GLOBAL(type), LOCAL(type),
kusano 7d535a
or METHODDEF(type).  These macros expand to "static type" or just "type" as
kusano 7d535a
appropriate.  They provide a readable indication of the routine's usage and
kusano 7d535a
can readily be changed for special needs.  (For instance, special linkage
kusano 7d535a
keywords can be inserted for use in Windows DLLs.)
kusano 7d535a
shun-iwasawa 82a8f5
A similar solution is used for external function declarations (see the EXTERN
shun-iwasawa 82a8f5
macro.)
kusano 7d535a
kusano 7d535a
kusano 7d535a
The JPEG library is intended to be used within larger programs.  Furthermore,
kusano 7d535a
we want it to be reentrant so that it can be used by applications that process
kusano 7d535a
multiple images concurrently.  The following rules support these requirements:
kusano 7d535a
kusano 7d535a
1. Avoid direct use of file I/O, "malloc", error report printouts, etc;
kusano 7d535a
pass these through the common routines provided.
kusano 7d535a
kusano 7d535a
2. Minimize global namespace pollution.  Functions should be declared static
kusano 7d535a
wherever possible.  (Note that our method-based calling conventions help this
kusano 7d535a
a lot: in many modules only the initialization function will ever need to be
kusano 7d535a
called directly, so only that function need be externally visible.)  All
shun-iwasawa 82a8f5
global function names should begin with "jpeg_".
kusano 7d535a
kusano 7d535a
3. Don't use global variables; anything that must be used in another module
kusano 7d535a
should be in the common data structures.
kusano 7d535a
kusano 7d535a
4. Don't use static variables except for read-only constant tables.  Variables
kusano 7d535a
that should be private to a module can be placed into private structures (see
kusano 7d535a
the system architecture document, structure.txt).
kusano 7d535a
kusano 7d535a
5. Source file names should begin with "j" for files that are part of the
kusano 7d535a
library proper; source files that are not part of the library, such as cjpeg.c
shun-iwasawa 82a8f5
and djpeg.c, do not begin with "j".  Keep compression and decompression code in
shun-iwasawa 82a8f5
separate source files --- some applications may want only one half of the
shun-iwasawa 82a8f5
library.
kusano 7d535a
kusano 7d535a
Note: these rules (particularly #4) are not followed religiously in the
kusano 7d535a
modules that are used in cjpeg/djpeg but are not part of the JPEG library
kusano 7d535a
proper.  Those modules are not really intended to be used in other
kusano 7d535a
applications.