[teqc] teqc exit codes

Lou Estey lou at unavco.org
Thu Aug 19 11:58:32 MDT 2004


Teqc users,

It has recently been suggested that teqc would be more
useful in shells and scripts if it used a more UNIX-like
exit codes, i.e. if an error is encountered, return a
non-zero exit code; return zero if no errors are encountered.

Two examples that were brought to my attention are:

> $ teqc -^; echo "-- exit($?)"
> teqc: command line option "-^" unknown ... exiting
> -- exit(255)
> 
> $ teqc abc; echo "-- exit($?)"
> cannot fopen file abc in r mode
> teqc: cannot fopen argument file "abc" in r mode
> -- exit(0)

The user was happy with the exit code on the first example
and unhappy with the exit code on the second example.

My explanation for the 2nd example was the option list is OK (it's null,
so teqc is running entirely on default options), and anything left in the
command is taken to be a list of filenames, though in this case there
is only one filename listed (which teqc cannot fopen to read for
whatever reason).  What if there had been a list of more than one
file, some of which teqc could fopen and others it could not?
Is there "success" only if teqc can fopen all of them?  (IMHO the
answer depends on the specific user wants.)  In other words, in this
2nd command, there are specific error messages detailing what (if
anything) is wrong with any specific file in the file list, and
after dealing with the list, teqc exits normally (and hence the
current exit code).

The user found this argument lacking, and their proposed solution
is along the lines of:

$ cat teqc_error.h
typedef enum {
   TE_NONE,
   TE_PROCESS_NOTICE,
   TE_PROCESS_WARNING,
   TE_PROCESS_ERROR,
   TE_FATAL_ERROR
} TeqcError;
extern void teqc_error(TeqcError error);
extern int teqc_exit(void);
$ cat teqc_error.c
#include "teqc_error.h"
#include <stdlib.h>
static int error_code = TE_NONE;
void teqc_error(TeqcError error) {
   if(error_code < error)
     error_code = error;
}
int teqc_exit(void) {
   exit(error_code);
}

 > Then call teqc_error(TE_*) wherever you write something to stderr and
 > replace all exit(CODE) by teqc_exit().

Doable?  Yes.  But a quick grep on stderr (and its internal
equivalent) in the teqc code shows over 2700 lines of code to
be looked at edited (which includes the usual errors/warnings/notices
that you are familiar with down to debugging lines for me that are
usually commented out).  Assuming I tackled this code modification,
and assuming I spent 2 minutes per instance (on average), it would
require over 2 full work-weeks to accomplish this change.  (If
it turns out to be 1 minute per instance, it's still over 1 full
work-week.)

The question is: would or could such a change make your use of teqc
more meaningful in shell scripting?  Is this worthwhile to do for
you (the user)?

BR,
--lou

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Louis H. Estey, Ph.D.              office:  [+001] 303-381-7456
UNAVCO, 6350 Nautilus Drive           FAX:  [+001] 303-381-7451
Boulder, CO  80301-5554            e-mail:  lou  unavco.org
    WWW:  http://www.unavco.org   http://jules.unavco.org

"If the universe is the answer, what is the question?"
                                                -- Leon Lederman
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the teqc mailing list