Changeset 300

Show
Ignore:
Timestamp:
11/21/05 12:37:55
Author:
rachel
Message:

Removed redundant ops_errors.c, all error code now in errors.c
Tidied up error output

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/examples/packet-dump.c

    r299 r300  
    292292 
    293293    case OPS_PARSER_ERRCODE: 
    294         printf("parse error: %s (0x%x): %s\n", 
    295                ops_errcode(content->errcode.errcode, OPS_LANG_ENGLISH), 
    296                content->errcode.errcode, 
    297                ops_error(content->errcode.errcode, OPS_LANG_ENGLISH)); 
     294        printf("parse error: %s\n", 
     295               ops_errcode(content->errcode.errcode)); 
    298296        break; 
    299297 
  • openpgpsdk/trunk/include/openpgpsdk/errors.h

    r299 r300  
    1313 
    1414    OPS_E_FAIL=0x0001,  /* general error */ 
     15 
     16    OPS_E_SYSTEM_ERROR=0x0002, /* system error, look at errno for details */ 
    1517 
    1618    /* reader errors */ 
     
    3032    } ops_errcode_t; 
    3133 
    32 /** ops_error_map_t */ 
    33 typedef ops_map_t ops_error_map_t; 
    34  
    3534/** ops_errcode_name_map_t */ 
    3635typedef ops_map_t ops_errcode_name_map_t; 
    3736 
    38 /** ops_lang_t */ 
    39 typedef enum  
    40     { 
    41     OPS_LANG_ENGLISH=1 
    42     } ops_lang_t; 
    43  
    44 /* Function Declarations */ 
    45  
    46 char *ops_error(ops_errcode_t errcode, ops_lang_t lang); 
    47 char *ops_errcode(ops_errcode_t errcode, ops_lang_t lang); 
    48  
    49 /** ops_error_code_t 
    50  \todo Not sure why we have this as well as ops_errcode_t above, 
    51         will probably combine. RW  
    52 */ 
    53 typedef enum 
    54     { 
    55     OPS_E_READ_FAILED=1, 
    56     OPS_E_SYSTEM_ERROR=2, 
    57     } ops_error_code_t; 
    58      
    5937/** one entry in a linked list of errors */ 
    6038typedef struct ops_error 
    6139    { 
    62     ops_error_code_t errcode; 
     40    ops_errcode_t errcode; 
    6341    int errno;  /*!< irrelevent unless errcode == OPS_E_SYSTEM_ERROR */ 
    6442    char *comment; 
     
    6846    } ops_error_t; 
    6947 
    70 void push_error(ops_error_t **errstack,ops_error_code_t errcode,int errno, 
     48char *ops_errcode(const ops_errcode_t errcode); 
     49 
     50void push_error(ops_error_t **errstack,ops_errcode_t errcode,int errno, 
    7151                const char *file,int line,const char *comment,...); 
    7252void print_error(ops_error_t *err); 
  • openpgpsdk/trunk/src/Makefile.template

    r282 r300  
    1111LIBOBJS = packet-parse.o util.o openssl_crypto.o accumulate.o \ 
    1212        memory.o fingerprint.o hash.o keyring.o signature.o compress.o \ 
    13         packet-show.o create.o validate.o lists.o ops_errors.o armour.o \ 
    14         errors.o 
     13        packet-show.o create.o validate.o lists.o armour.o errors.o 
    1514 
    1615headers: 
  • openpgpsdk/trunk/src/errors.c

    r299 r300  
    99#include <stdio.h> 
    1010#include <stdlib.h> 
     11 
     12#include "openpgpsdk/util.h" 
     13 
     14static ops_errcode_name_map_t errcode_name_map[] =  
     15    { 
     16    { OPS_E_OK, "OPS_E_OK" }, 
     17    { OPS_E_FAIL, "OPS_E_FAIL" }, 
     18    { OPS_E_SYSTEM_ERROR, "OPS_E_SYSTEM_ERROR" }, 
     19 
     20    { OPS_E_R,  "OPS_E_R" }, 
     21    { OPS_E_R_READ_FAILED, "OPS_E_R_READ_FAILED" }, 
     22    { OPS_E_R_EARLY_EOF, "OPS_E_R_EARLY_EOF" }, 
     23 
     24    { OPS_E_W,  "OPS_E_W" }, 
     25 
     26    { OPS_E_P,  "OPS_E_P" }, 
     27    { OPS_E_P_NOT_ENOUGH_DATA, "OPS_E_P_NOT_ENOUGH_DATA" }, 
     28 
     29    { OPS_E_C,  "OPS_E_C" }, 
     30 
     31    { (int) NULL,               (char *)NULL }, /* this is the end-of-array marker */ 
     32    }; 
     33 
     34/** 
     35 * \ingroup Errors 
     36 * 
     37 * returns string representing error code name 
     38 * \param errcode 
     39 * \return string or "Unknown" 
     40 */ 
     41char *ops_errcode(const ops_errcode_t errcode) 
     42    { 
     43    return(ops_str_from_map((int) errcode, (ops_map_t *) errcode_name_map)); 
     44    } 
    1145 
    1246/**  
     
    2256 */ 
    2357 
    24 void push_error(ops_error_t **errstack,ops_error_code_t errcode,int errno, 
     58void push_error(ops_error_t **errstack,ops_errcode_t errcode,int errno, 
    2559                const char *file,int line,const char *fmt,...) 
    2660    { 
     
    5993    printf("%s:%d: ",err->file,err->line); 
    6094    if (err->errcode==OPS_E_SYSTEM_ERROR) 
    61         printf("system error %d returned from %s\n",err->errno, err->comment); 
     95        printf("system error %d returned from %s()\n",err->errno, err->comment); 
    6296    else 
    63         printf("errcode=%d, errno=%d, comment=%s\n",err->errcode,err->errno,err->comment); 
     97        printf("%s, %s\n", 
     98               ops_errcode(err->errcode), 
     99               err->comment); 
    64100    } 
    65101 
  • openpgpsdk/trunk/src/util.c

    r299 r300  
    114114    if(n == -1) 
    115115        { 
    116         ops_system_error_1(&parse_info->errors,OPS_E_READ_FAILED,"read", 
     116        ops_system_error_1(&parse_info->errors,OPS_E_R_READ_FAILED,"read", 
    117117                           "file descriptor %d",arg->fd); 
    118118        return OPS_R_ERROR;