ZBar bar code reader . http://zbar.sourceforge.net/ ZBar is licensed under the GNU LGPL 2.1 to enable development of both open source and commercial projects.
Dependents: GR-PEACH_Camera_in_barcode levkov_ov7670
error.c
00001 /*------------------------------------------------------------------------ 00002 * Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> 00003 * 00004 * This file is part of the ZBar Bar Code Reader. 00005 * 00006 * The ZBar Bar Code Reader is free software; you can redistribute it 00007 * and/or modify it under the terms of the GNU Lesser Public License as 00008 * published by the Free Software Foundation; either version 2.1 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * The ZBar Bar Code Reader is distributed in the hope that it will be 00012 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00013 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser Public License 00017 * along with the ZBar Bar Code Reader; if not, write to the Free 00018 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, 00019 * Boston, MA 02110-1301 USA 00020 * 00021 * http://sourceforge.net/projects/zbar 00022 *------------------------------------------------------------------------*/ 00023 00024 #include "error.h" 00025 #include <string.h> 00026 00027 int _zbar_verbosity = 0; 00028 00029 static const char * const sev_str[] = { 00030 "FATAL ERROR", "ERROR", "OK", "WARNING", "NOTE" 00031 }; 00032 #define SEV_MAX (strlen(sev_str[0])) 00033 00034 static const char * const mod_str[] = { 00035 "processor", "video", "window", "image scanner", "<unknown>" 00036 }; 00037 #define MOD_MAX (strlen(mod_str[ZBAR_MOD_IMAGE_SCANNER])) 00038 00039 static const char const * err_str[] = { 00040 "no error", /* OK */ 00041 "out of memory", /* NOMEM */ 00042 "internal library error", /* INTERNAL */ 00043 "unsupported request", /* UNSUPPORTED */ 00044 "invalid request", /* INVALID */ 00045 "system error", /* SYSTEM */ 00046 "locking error", /* LOCKING */ 00047 "all resources busy", /* BUSY */ 00048 "X11 display error", /* XDISPLAY */ 00049 "X11 protocol error", /* XPROTO */ 00050 "output window is closed", /* CLOSED */ 00051 "windows system error", /* WINAPI */ 00052 "unknown error" /* NUM */ 00053 }; 00054 #define ERR_MAX (strlen(err_str[ZBAR_ERR_CLOSED])) 00055 00056 int zbar_version (unsigned *major, 00057 unsigned *minor) 00058 { 00059 if(major) 00060 *major = ZBAR_VERSION_MAJOR; 00061 if(minor) 00062 *minor = ZBAR_VERSION_MINOR; 00063 return(0); 00064 } 00065 00066 void zbar_set_verbosity (int level) 00067 { 00068 _zbar_verbosity = level; 00069 } 00070 00071 void zbar_increase_verbosity () 00072 { 00073 if(!_zbar_verbosity) 00074 _zbar_verbosity++; 00075 else 00076 _zbar_verbosity <<= 1; 00077 } 00078 00079 int _zbar_error_spew (const void *container, 00080 int verbosity) 00081 { 00082 const errinfo_t *err = container; 00083 assert(err->magic == ERRINFO_MAGIC); 00084 fprintf(stderr, "%s", _zbar_error_string(err, verbosity)); 00085 return(-err->sev); 00086 } 00087 00088 zbar_error_t _zbar_get_error_code (const void *container) 00089 { 00090 const errinfo_t *err = container; 00091 assert(err->magic == ERRINFO_MAGIC); 00092 return(err->type); 00093 } 00094 00095 /* ERROR: zbar video in v4l1_set_format(): 00096 * system error: blah[: blah] 00097 */ 00098 00099 const char *_zbar_error_string (const void *container, 00100 int verbosity) 00101 { 00102 errinfo_t *err = (errinfo_t*)container; 00103 assert(err->magic == ERRINFO_MAGIC); 00104 00105 const char *sev; 00106 if(err->sev >= SEV_FATAL && err->sev <= SEV_NOTE) 00107 sev = sev_str[err->sev + 2]; 00108 else 00109 sev = sev_str[1]; 00110 00111 const char *mod; 00112 if(err->module >= ZBAR_MOD_PROCESSOR && 00113 err->module < ZBAR_MOD_UNKNOWN) 00114 mod = mod_str[err->module]; 00115 else 00116 mod = mod_str[ZBAR_MOD_UNKNOWN]; 00117 00118 const char *func = (err->func) ? err->func : "<unknown>"; 00119 00120 const char *type; 00121 if(err->type >= 0 && err->type < ZBAR_ERR_NUM) 00122 type = err_str[err->type]; 00123 else 00124 type = err_str[ZBAR_ERR_NUM]; 00125 00126 char basefmt[] = "%s: zbar %s in %s():\n %s: "; 00127 int len = SEV_MAX + MOD_MAX + ERR_MAX + strlen(func) + sizeof(basefmt); 00128 err->buf = realloc(err->buf, len); 00129 len = sprintf(err->buf, basefmt, sev, mod, func, type); 00130 if(len <= 0) 00131 return("<unknown>"); 00132 00133 if(err->detail) { 00134 int newlen = len + strlen(err->detail) + 1; 00135 if(strstr(err->detail, "%s")) { 00136 #if (0) 00137 if(!err->arg_str) 00138 err->arg_str = strdup("<?>"); 00139 #endif 00140 err->buf = realloc(err->buf, newlen + strlen(err->arg_str)); 00141 len += sprintf(err->buf + len, err->detail, err->arg_str); 00142 } 00143 else if(strstr(err->detail, "%d") || strstr(err->detail, "%x")) { 00144 err->buf = realloc(err->buf, newlen + 32); 00145 len += sprintf(err->buf + len, err->detail, err->arg_int); 00146 } 00147 else { 00148 err->buf = realloc(err->buf, newlen); 00149 len += sprintf(err->buf + len, "%s", err->detail); 00150 } 00151 if(len <= 0) 00152 return("<unknown>"); 00153 } 00154 00155 if(err->type == ZBAR_ERR_SYSTEM) { 00156 char sysfmt[] = ": %s (%d)\n"; 00157 const char *syserr = strerror(err->errnum); 00158 err->buf = realloc(err->buf, len + strlen(sysfmt) + strlen(syserr)); 00159 len += sprintf(err->buf + len, sysfmt, syserr, err->errnum); 00160 } 00161 #ifdef _WIN32 00162 else if(err->type == ZBAR_ERR_WINAPI) { 00163 char *syserr = NULL; 00164 if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | 00165 FORMAT_MESSAGE_ALLOCATE_BUFFER | 00166 FORMAT_MESSAGE_IGNORE_INSERTS, 00167 NULL, err->errnum, 0, (LPTSTR)&syserr, 1, NULL) && 00168 syserr) { 00169 char sysfmt[] = ": %s (%d)\n"; 00170 err->buf = realloc(err->buf, len + strlen(sysfmt) + strlen(syserr)); 00171 len += sprintf(err->buf + len, sysfmt, syserr, err->errnum); 00172 LocalFree(syserr); 00173 } 00174 } 00175 #endif 00176 else { 00177 err->buf = realloc(err->buf, len + 2); 00178 len += sprintf(err->buf + len, "\n"); 00179 } 00180 return(err->buf); 00181 } 00182
Generated on Tue Jul 12 2022 18:54:12 by 1.7.2