lemon-project-template-glpk

annotate 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
rev   line source
alpar@9 1 /* glpenv04.c (error handling) */
alpar@9 2
alpar@9 3 /***********************************************************************
alpar@9 4 * This code is part of GLPK (GNU Linear Programming Kit).
alpar@9 5 *
alpar@9 6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
alpar@9 7 * 2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics,
alpar@9 8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
alpar@9 9 * E-mail: <mao@gnu.org>.
alpar@9 10 *
alpar@9 11 * GLPK is free software: you can redistribute it and/or modify it
alpar@9 12 * under the terms of the GNU General Public License as published by
alpar@9 13 * the Free Software Foundation, either version 3 of the License, or
alpar@9 14 * (at your option) any later version.
alpar@9 15 *
alpar@9 16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
alpar@9 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
alpar@9 18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
alpar@9 19 * License for more details.
alpar@9 20 *
alpar@9 21 * You should have received a copy of the GNU General Public License
alpar@9 22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
alpar@9 23 ***********************************************************************/
alpar@9 24
alpar@9 25 #include "glpapi.h"
alpar@9 26
alpar@9 27 /***********************************************************************
alpar@9 28 * NAME
alpar@9 29 *
alpar@9 30 * glp_error - display error message and terminate execution
alpar@9 31 *
alpar@9 32 * SYNOPSIS
alpar@9 33 *
alpar@9 34 * void glp_error(const char *fmt, ...);
alpar@9 35 *
alpar@9 36 * DESCRIPTION
alpar@9 37 *
alpar@9 38 * The routine glp_error (implemented as a macro) formats its
alpar@9 39 * parameters using the format control string fmt, writes the formatted
alpar@9 40 * message to the terminal, and abnormally terminates the program. */
alpar@9 41
alpar@9 42 static void error(const char *fmt, ...)
alpar@9 43 { ENV *env = get_env_ptr();
alpar@9 44 va_list arg;
alpar@9 45 env->term_out = GLP_ON;
alpar@9 46 va_start(arg, fmt);
alpar@9 47 xvprintf(fmt, arg);
alpar@9 48 va_end(arg);
alpar@9 49 xprintf("Error detected in file %s at line %d\n", env->err_file,
alpar@9 50 env->err_line);
alpar@9 51 if (env->err_hook != NULL)
alpar@9 52 env->err_hook(env->err_info);
alpar@9 53 abort();
alpar@9 54 exit(EXIT_FAILURE);
alpar@9 55 /* no return */
alpar@9 56 }
alpar@9 57
alpar@9 58 _glp_error glp_error_(const char *file, int line)
alpar@9 59 { ENV *env = get_env_ptr();
alpar@9 60 env->err_file = file;
alpar@9 61 env->err_line = line;
alpar@9 62 return error;
alpar@9 63 }
alpar@9 64
alpar@9 65 /***********************************************************************
alpar@9 66 * NAME
alpar@9 67 *
alpar@9 68 * glp_assert - check for logical condition
alpar@9 69 *
alpar@9 70 * SYNOPSIS
alpar@9 71 *
alpar@9 72 * #include "glplib.h"
alpar@9 73 * void glp_assert(int expr);
alpar@9 74 *
alpar@9 75 * DESCRIPTION
alpar@9 76 *
alpar@9 77 * The routine glp_assert (implemented as a macro) checks for a logical
alpar@9 78 * condition specified by the parameter expr. If the condition is false
alpar@9 79 * (i.e. the value of expr is zero), the routine writes a message to
alpar@9 80 * the terminal and abnormally terminates the program. */
alpar@9 81
alpar@9 82 void glp_assert_(const char *expr, const char *file, int line)
alpar@9 83 { glp_error_(file, line)("Assertion failed: %s\n", expr);
alpar@9 84 /* no return */
alpar@9 85 }
alpar@9 86
alpar@9 87 /***********************************************************************
alpar@9 88 * NAME
alpar@9 89 *
alpar@9 90 * glp_error_hook - install hook to intercept abnormal termination
alpar@9 91 *
alpar@9 92 * SYNOPSIS
alpar@9 93 *
alpar@9 94 * void glp_error_hook(void (*func)(void *info), void *info);
alpar@9 95 *
alpar@9 96 * DESCRIPTION
alpar@9 97 *
alpar@9 98 * The routine glp_error_hook installs a user-defined hook routine to
alpar@9 99 * intercept abnormal termination.
alpar@9 100 *
alpar@9 101 * The parameter func specifies the user-defined hook routine. It is
alpar@9 102 * called from the routine glp_error before the latter calls the abort
alpar@9 103 * function to abnormally terminate the application program because of
alpar@9 104 * fatal error. The parameter info is a transit pointer, specified in
alpar@9 105 * the corresponding call to the routine glp_error_hook; it may be used
alpar@9 106 * to pass some information to the hook routine.
alpar@9 107 *
alpar@9 108 * To uninstall the hook routine the parameters func and info should be
alpar@9 109 * specified as NULL. */
alpar@9 110
alpar@9 111 void glp_error_hook(void (*func)(void *info), void *info)
alpar@9 112 { ENV *env = get_env_ptr();
alpar@9 113 if (func == NULL)
alpar@9 114 { env->err_hook = NULL;
alpar@9 115 env->err_info = NULL;
alpar@9 116 }
alpar@9 117 else
alpar@9 118 { env->err_hook = func;
alpar@9 119 env->err_info = info;
alpar@9 120 }
alpar@9 121 return;
alpar@9 122 }
alpar@9 123
alpar@9 124 /* eof */