PageRenderTime 28ms CodeModel.GetById 16ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/farmR/src/glplib03.c

https://code.google.com/p/javawfm/
C | 141 lines | 44 code | 13 blank | 84 comment | 6 complexity | 9133491e911ad0d8d38558380713f899 MD5 | raw file
  1/* glplib03.c (error handling) */
  2
  3/***********************************************************************
  4*  This code is part of GLPK (GNU Linear Programming Kit).
  5*
  6*  Copyright (C) 2000,01,02,03,04,05,06,07,08,2009 Andrew Makhorin,
  7*  Department for Applied Informatics, Moscow Aviation Institute,
  8*  Moscow, Russia. All rights reserved. E-mail: <mao@mai2.rcnet.ru>.
  9*
 10*  GLPK is free software: you can redistribute it and/or modify it
 11*  under the terms of the GNU General Public License as published by
 12*  the Free Software Foundation, either version 3 of the License, or
 13*  (at your option) any later version.
 14*
 15*  GLPK is distributed in the hope that it will be useful, but WITHOUT
 16*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 17*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
 18*  License for more details.
 19*
 20*  You should have received a copy of the GNU General Public License
 21*  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
 22***********************************************************************/
 23
 24#define _GLPSTD_STDIO
 25#include "glplib.h"
 26#include "R.h"
 27
 28/***********************************************************************
 29*  NAME
 30*
 31*  xassert - check for logical condition
 32*
 33*  SYNOPSIS
 34*
 35*  #include "glplib.h"
 36*  void xassert(int expr);
 37*
 38*  DESCRIPTION
 39*
 40*  The routine xassert (implemented as a macro) checks for a logical
 41*  condition specified by the parameter expr. If the condition is false
 42*  (i.e. the value of expr is zero), the routine writes a message to
 43*  the terminal and abnormally terminates the program. */
 44
 45void lib_xassert(const char *expr, const char *file, int line)
 46{     lib_xerror1(file, line)("Assertion failed: %s\n", expr);
 47      /* no return */
 48}
 49
 50/***********************************************************************
 51*  NAME
 52*
 53*  xerror - display error message and terminate execution
 54*
 55*  SYNOPSIS
 56*
 57*  #include "glplib.h"
 58*  void xerror(const char *fmt, ...);
 59*
 60*  DESCRIPTION
 61*
 62*  The routine xerror (implemented as a macro) formats its parameters
 63*  under the format control string fmt, writes the formatted message to
 64*  the terminal, and abnormally terminates the program. */
 65
 66xerror_t lib_xerror1(const char *file, int line)
 67{     LIBENV *env = lib_link_env();
 68      env->err_file = file;
 69      env->err_line = line;
 70      return lib_xerror2;
 71}
 72
 73void lib_xerror2(const char *fmt, ...)
 74{     LIBENV *env = lib_link_env();
 75      va_list arg;
 76      va_start(arg, fmt);
 77      xvprintf(fmt, arg);
 78      va_end(arg);
 79      xprintf("Error detected in file %s at line %d\n",
 80         env->err_file, env->err_line);
 81      fflush(stdout);
 82      fflush(stderr);
 83      error("Execution aborted.");
 84      /* no return */
 85}
 86
 87void lib_fault_hook(int (*func)(void *info, char *buf), void *info)
 88{     /* (obsolete) */
 89      xassert(func == func);
 90      xassert(info == info);
 91      return;
 92}
 93
 94/***********************************************************************
 95*  NAME
 96*
 97*  lib_err_msg - save error message string
 98*
 99*  SYNOPSIS
100*
101*  #include "glplib.h"
102*  void lib_err_msg(const char *msg);
103*
104*  DESCRIPTION
105*
106*  The routine lib_err_msg saves an error message string specified by
107*  the parameter msg. The message is obtained by some library routines
108*  with a call to strerror(errno). */
109
110void lib_err_msg(const char *msg)
111{     LIBENV *env = lib_link_env();
112      int len = strlen(msg);
113      if (len >= sizeof(env->err_msg))
114         len = sizeof(env->err_msg) - 1;
115      memcpy(env->err_msg, msg, len);
116      if (len > 0 && env->err_msg[len-1] == '\n') len--;
117      env->err_msg[len] = '\0';
118      return;
119}
120
121/***********************************************************************
122*  NAME
123*
124*  xerrmsg - retrieve error message string
125*
126*  SYNOPSIS
127*
128*  #include "glplib.h"
129*  const char *xerrmsg(void);
130*
131*  RETURNS
132*
133*  The routine xerrmsg returns a pointer to an error message string
134*  previously set by some library routine to indicate an error. */
135
136const char *xerrmsg(void)
137{     LIBENV *env = lib_link_env();
138      return env->err_msg;
139}
140
141/* eof */