Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
prerrortable.c File Reference
#include <string.h>
#include <assert.h>
#include <errno.h>
#include "prmem.h"
#include "prerror.h"

Go to the source code of this file.

Classes

struct  PRErrorTableList

Defines

#define ERRCODE_RANGE   8 /* # of bits to shift table number */
#define BITS_PER_CHAR   6 /* # bits to shift per character in name */

Functions

static const char * error_table_name (PRErrorCode num)
 PR_ErrorToString (PRErrorCode code, PRLanguageCode language)
 PR_ErrorToName (PRErrorCode code)
 PR_ErrorLanguages (void)
 PR_ErrorInstallTable (const struct PRErrorTable *table)
 PR_ErrorInstallCallback (const char *const *languages, PRErrorCallbackLookupFn *lookup, PRErrorCallbackNewTableFn *newtable, struct PRErrorCallbackPrivate *cb_private)

Variables

static struct PRErrorTableListTable_List = (struct PRErrorTableList *) NULL
static const char * default_languages [] = { "i-default", "en", 0 }
static const char *constcallback_languages = default_languages
static struct
PRErrorCallbackPrivate * 
callback_private = 0
static PRErrorCallbackLookupFncallback_lookup = 0
static PRErrorCallbackNewTableFncallback_newtable = 0
static const char char_set [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"

Class Documentation

struct PRErrorTableList

Definition at line 77 of file prerrortable.c.

Collaboration diagram for PRErrorTableList:
Class Members
struct PRErrorTableList * next
struct PRErrorTable * table
struct
PRErrorCallbackTablePrivate *
table_private

Define Documentation

#define BITS_PER_CHAR   6 /* # bits to shift per character in name */

Definition at line 69 of file prerrortable.c.

#define ERRCODE_RANGE   8 /* # of bits to shift table number */

Definition at line 68 of file prerrortable.c.


Function Documentation

static const char* error_table_name ( PRErrorCode  num) [static]

Definition at line 98 of file prerrortable.c.

{
    static char buf[6];     /* only used if internal code problems exist */

    long ch;
    int i;
    char *p;

    /* num = aa aaa abb bbb bcc ccc cdd ddd d?? ??? ??? */
    p = buf;
    num >>= ERRCODE_RANGE;
    /* num = ?? ??? ??? aaa aaa bbb bbb ccc ccc ddd ddd */
    num &= 077777777;
    /* num = 00 000 000 aaa aaa bbb bbb ccc ccc ddd ddd */
    for (i = 4; i >= 0; i--) {
       ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1);
       if (ch != 0)
           *p++ = char_set[ch-1];
    }
    *p = '\0';
    return(buf);
}

Here is the caller graph for this function:

PR_ErrorInstallCallback ( const char *const languages,
PRErrorCallbackLookupFn lookup,
PRErrorCallbackNewTableFn newtable,
struct PRErrorCallbackPrivate *  cb_private 
)

Definition at line 220 of file prerrortable.c.

{
    struct PRErrorTableList *et;

    assert(strcmp(languages[0], "i-default") == 0);
    assert(strcmp(languages[1], "en") == 0);
    
    callback_languages = languages;
    callback_lookup = lookup;
    callback_newtable = newtable;
    callback_private = cb_private;

    if (callback_newtable) {
       for (et = Table_List; et; et = et->next) {
           et->table_private = callback_newtable(et->table, callback_private);
       }
    }
}

Definition at line 200 of file prerrortable.c.

{
    struct PRErrorTableList * new_et;

    new_et = (struct PRErrorTableList *)
                                   PR_Malloc(sizeof(struct PRErrorTableList));
    if (!new_et)
       return errno; /* oops */
    new_et->table = table;
    if (callback_newtable) {
       new_et->table_private = callback_newtable(table, callback_private);
    } else {
       new_et->table_private = 0;
    }
    new_et->next = Table_List;
    Table_List = new_et;
    return 0;
}

Here is the caller graph for this function:

Definition at line 194 of file prerrortable.c.

{
    return callback_languages;
}

Definition at line 178 of file prerrortable.c.

{
    struct PRErrorTableList *et;

    for (et = Table_List; et; et = et->next) {
       if (et->table->base <= code &&
           et->table->base + et->table->n_msgs > code) {
           /* This is the right table */
           return(et->table->msgs[code - et->table->base].name);
       }
    }

    return 0;
}
PR_ErrorToString ( PRErrorCode  code,
PRLanguageCode  language 
)

Definition at line 122 of file prerrortable.c.

{
    /* static buffer only used if code is using inconsistent error message
     * numbers, so just ignore the possible thread contention
     */
    static char buffer[25];

    const char *msg;
    int offset;
    PRErrorCode table_num;
    struct PRErrorTableList *et;
    int started = 0;
    char *cp;

    for (et = Table_List; et; et = et->next) {
       if (et->table->base <= code &&
           et->table->base + et->table->n_msgs > code) {
           /* This is the right table */
           if (callback_lookup) {
              msg = callback_lookup(code, language, et->table,
                  callback_private, et->table_private);
              if (msg) return msg;
           }
    
           return(et->table->msgs[code - et->table->base].en_text);
       }
    }

    if (code >= 0 && code < 256) {
       return strerror(code);
    }

    offset = (int) (code & ((1<<ERRCODE_RANGE)-1));
    table_num = code - offset;
    strcpy (buffer, "Unknown code ");
    if (table_num) {
       strcat(buffer, error_table_name (table_num));
       strcat(buffer, " ");
    }
    for (cp = buffer; *cp; cp++)
       ;
    if (offset >= 100) {
       *cp++ = (char)('0' + offset / 100);
       offset %= 100;
       started++;
    }
    if (started || offset >= 10) {
       *cp++ = (char)('0' + offset / 10);
       offset %= 10;
    }
    *cp++ = (char)('0' + offset);
    *cp = '\0';
    return(buffer);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 86 of file prerrortable.c.

Definition at line 90 of file prerrortable.c.

Definition at line 91 of file prerrortable.c.

struct PRErrorCallbackPrivate* callback_private = 0 [static]

Definition at line 89 of file prerrortable.c.

const char char_set[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" [static]

Definition at line 94 of file prerrortable.c.

const char* default_languages[] = { "i-default", "en", 0 } [static]

Definition at line 85 of file prerrortable.c.

struct PRErrorTableList* Table_List = (struct PRErrorTableList *) NULL [static]

Definition at line 82 of file prerrortable.c.