lemon-project-template-glpk

diff deps/glpk/src/glpenv04.c @ 9:33de93886c88

Import GLPK 4.47
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 20:59:10 +0100
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/deps/glpk/src/glpenv04.c	Sun Nov 06 20:59:10 2011 +0100
     1.3 @@ -0,0 +1,124 @@
     1.4 +/* glpenv04.c (error handling) */
     1.5 +
     1.6 +/***********************************************************************
     1.7 +*  This code is part of GLPK (GNU Linear Programming Kit).
     1.8 +*
     1.9 +*  Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
    1.10 +*  2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics,
    1.11 +*  Moscow Aviation Institute, Moscow, Russia. All rights reserved.
    1.12 +*  E-mail: <mao@gnu.org>.
    1.13 +*
    1.14 +*  GLPK is free software: you can redistribute it and/or modify it
    1.15 +*  under the terms of the GNU General Public License as published by
    1.16 +*  the Free Software Foundation, either version 3 of the License, or
    1.17 +*  (at your option) any later version.
    1.18 +*
    1.19 +*  GLPK is distributed in the hope that it will be useful, but WITHOUT
    1.20 +*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    1.21 +*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
    1.22 +*  License for more details.
    1.23 +*
    1.24 +*  You should have received a copy of the GNU General Public License
    1.25 +*  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
    1.26 +***********************************************************************/
    1.27 +
    1.28 +#include "glpapi.h"
    1.29 +
    1.30 +/***********************************************************************
    1.31 +*  NAME
    1.32 +*
    1.33 +*  glp_error - display error message and terminate execution
    1.34 +*
    1.35 +*  SYNOPSIS
    1.36 +*
    1.37 +*  void glp_error(const char *fmt, ...);
    1.38 +*
    1.39 +*  DESCRIPTION
    1.40 +*
    1.41 +*  The routine glp_error (implemented as a macro) formats its
    1.42 +*  parameters using the format control string fmt, writes the formatted
    1.43 +*  message to the terminal, and abnormally terminates the program. */
    1.44 +
    1.45 +static void error(const char *fmt, ...)
    1.46 +{     ENV *env = get_env_ptr();
    1.47 +      va_list arg;
    1.48 +      env->term_out = GLP_ON;
    1.49 +      va_start(arg, fmt);
    1.50 +      xvprintf(fmt, arg);
    1.51 +      va_end(arg);
    1.52 +      xprintf("Error detected in file %s at line %d\n", env->err_file,
    1.53 +         env->err_line);
    1.54 +      if (env->err_hook != NULL)
    1.55 +         env->err_hook(env->err_info);
    1.56 +      abort();
    1.57 +      exit(EXIT_FAILURE);
    1.58 +      /* no return */
    1.59 +}
    1.60 +
    1.61 +_glp_error glp_error_(const char *file, int line)
    1.62 +{     ENV *env = get_env_ptr();
    1.63 +      env->err_file = file;
    1.64 +      env->err_line = line;
    1.65 +      return error;
    1.66 +}
    1.67 +
    1.68 +/***********************************************************************
    1.69 +*  NAME
    1.70 +*
    1.71 +*  glp_assert - check for logical condition
    1.72 +*
    1.73 +*  SYNOPSIS
    1.74 +*
    1.75 +*  #include "glplib.h"
    1.76 +*  void glp_assert(int expr);
    1.77 +*
    1.78 +*  DESCRIPTION
    1.79 +*
    1.80 +*  The routine glp_assert (implemented as a macro) checks for a logical
    1.81 +*  condition specified by the parameter expr. If the condition is false
    1.82 +*  (i.e. the value of expr is zero), the routine writes a message to
    1.83 +*  the terminal and abnormally terminates the program. */
    1.84 +
    1.85 +void glp_assert_(const char *expr, const char *file, int line)
    1.86 +{     glp_error_(file, line)("Assertion failed: %s\n", expr);
    1.87 +      /* no return */
    1.88 +}
    1.89 +
    1.90 +/***********************************************************************
    1.91 +*  NAME
    1.92 +*
    1.93 +*  glp_error_hook - install hook to intercept abnormal termination
    1.94 +*
    1.95 +*  SYNOPSIS
    1.96 +*
    1.97 +*  void glp_error_hook(void (*func)(void *info), void *info);
    1.98 +*
    1.99 +*  DESCRIPTION
   1.100 +*
   1.101 +*  The routine glp_error_hook installs a user-defined hook routine to
   1.102 +*  intercept abnormal termination.
   1.103 +*
   1.104 +*  The parameter func specifies the user-defined hook routine. It is
   1.105 +*  called from the routine glp_error before the latter calls the abort
   1.106 +*  function to abnormally terminate the application program because of
   1.107 +*  fatal error. The parameter info is a transit pointer, specified in
   1.108 +*  the corresponding call to the routine glp_error_hook; it may be used
   1.109 +*  to pass some information to the hook routine.
   1.110 +*
   1.111 +*  To uninstall the hook routine the parameters func and info should be
   1.112 +*  specified as NULL. */
   1.113 +
   1.114 +void glp_error_hook(void (*func)(void *info), void *info)
   1.115 +{     ENV *env = get_env_ptr();
   1.116 +      if (func == NULL)
   1.117 +      {  env->err_hook = NULL;
   1.118 +         env->err_info = NULL;
   1.119 +      }
   1.120 +      else
   1.121 +      {  env->err_hook = func;
   1.122 +         env->err_info = info;
   1.123 +      }
   1.124 +      return;
   1.125 +}
   1.126 +
   1.127 +/* eof */