1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/lib/libast/include/error.h
Martijn Dekker a1f5c99204 INIT: remove proto, ratz (re: 46593a89, 6137b99a); major cleanup
This takes another step towards cleaning up the build system. We
now do not even pretend to be theoretically compatible with
pre-1989 K&R C compilers or with C++ compilers. In practice, this
had already been broken for many years due to bit rot.

Commit 46593a89 already removed the license handling enormity that
depended on proto, so now we can cleanly remove it altogether. But
we do need to leave some backwards compatibility stubs to keep the
build system compatible with older AST code; it should remain
possible to build older ksh versions with the current build system
(the bin/ and src/cmd/INIT/ directories) for testing purposes.

So as of now there is no more __MANGLE__d rubbish in your generated
header files. This is only about a quarter of a century overdue...

This commit also includes a huge amount of code cleanup to remove
thousands of unused K&R C fallbacks and other cruft, particularly
in libast. This code base should now be a little easier to
understand for people who are familiar with a modern(ish) C
standard.

ratz is now also removed; this was a standalone and simplified 2005
version of gunzip. As of 6137b99a, none of our code uses it, even
theoretically. And the real g(un)zip is now everywhere.

src/cmd/INIT/proto.c, src/cmd/INIT/ratz.c:
- Removed.

COPYRIGHT:
- Remove zlib license; this only applied to ratz.

bin/package, src/cmd/INIT/package.sh:
- Related cleanups.
- Unset LC_ALL before invoking a new shell, respecting the user's
  locale again and avoiding multibyte character corruption on the
  command line.

src/cmd/INIT/proto.sh:
- Add stub for backwards compatibility with Mamfiles that depend on
  proto. It does nothing but pass input without modification and is
  now installed as the new arch/*/bin/proto by src/cmd/INIT/Mamfile.

src/cmd/INIT/iffe.sh:
- Ignore the proto-related -e (--package) and -p (--prototyped)
  options; keep parsing them for backwards compatibility.
- Trim the macros passed to every test to their standard C
  versions, removing K&R C and C++ versions. These are now
  considered to be for backwards compatibility only.

src/cmd/INIT/iffe.tst:
- Remove proto(1) mangling code.
  By the way, iffe can be regression-tested as follows:
        $ bin/package use   # set up environment in a child shell
        $ regress src/cmd/INIT/iffe.tst
        $ exit              # leave package environment

src/cmd/INIT/make.probe, src/cmd/INIT/probe.win32:
- Remove code to handle C++.

src/lib/libast/features/common:
- As in iffe.sh above, trim macros designed for compatibility with
  C++ and ancient C compilers to their standard C versions and
  comment that they are for backwards compatibility with AST code.
  This is needed to keep all the old ast and ksh code compiling.

src/cmd/ksh93/sh/init.c,
src/cmd/ksh93/sh/name.c:
- Clarify libshell ABI compatibility function versions of macros.
  A "proto workaround" comment in the original code mislead me into
  thinking this had something to do with the removed proto(1), but
  it's unrelated. Call the workaround macro BYPASS_MACRO instead.

src/cmd/ksh93/include/defs.h:
- sh_sigcheck() macro: allow &sh as an argument: parenthesise shp.

src/cmd/ksh93/sh/nvtype.c:
- Remove unused nv_mkstruct() function. (re: d0a5cab1)

**/features/*:
- Remove obsolete iffe 'set prototyped' option.

**/Mamfile:
- Remove all references to the ast/prototyped.h header.
- Remove all use of the proto command. Simply copy instead.

*** 850-ish source files: ***
- Remove all '#pragma prototyped' directives.
- Remove all C++ compat code conditional upon defined(__cplusplus).
- Remove all use of the _ARG_ macro, which on standard C expands to
  its argument:
        #define _ARG_(x)        x
  (on K&R C, it expanded to nothing)
- Remove all use of _BEGIN_EXTERNS_ and _END_EXTERNS_ macros (empty
  on standard C; this was for C++ compatibility)
- Reduce all #if __STD_C (standard code) #else (K&R code) #endif
  blocks to the standard code only, without use of the macro.
- Same for _STD_ macro which seems to have had the same function.
- Change all instances of 'Void_t' to standard 'void'.
2021-12-24 07:05:22 +00:00

226 lines
6.9 KiB
C

/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.eclipse.org/org/documents/epl-v10.html *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
/*
* Glenn Fowler
* AT&T Research
*
* option, error and message formatter external definitions
*/
#ifndef _ERROR_H
#define _ERROR_H
#include <ast.h>
#include <option.h>
#include <errno.h>
#define ERROR_VERSION 20070319L
#if !defined(errno) && defined(__DYNAMIC__)
#define errno __DYNAMIC__(errno)
#endif
#define ERROR_debug(n) (-(n))
#define ERROR_exit(n) ((n)+ERROR_ERROR)
#define ERROR_system(n) (((n)+ERROR_ERROR)|ERROR_SYSTEM)
#define ERROR_usage(n) ((((n)?2:0)+ERROR_ERROR)|ERROR_USAGE)
#define ERROR_warn(n) (ERROR_WARNING)
#ifndef ERROR_catalog
#define ERROR_catalog(t) t
#endif
#ifndef ERROR_dictionary
#define ERROR_dictionary(t) t
#endif
#ifndef ERROR_translate
#define ERROR_translating() (error_info.translate&&(ast.locale.set&(1<<AST_LC_MESSAGES)))
#define ERROR_translate(l,i,d,m) (ERROR_translating()?errorx((const char*)(l),(const char*)(i),(const char*)(d),(const char*)(m)):(char*)(m))
#endif
#define ERROR_INFO 0 /* info message -- no err_id */
#define ERROR_WARNING 1 /* warning message */
#define ERROR_ERROR 2 /* error message -- no err_exit */
#define ERROR_FATAL 3 /* error message with err_exit */
#define ERROR_NOEXEC EXIT_NOEXEC /* shell convention */
#define ERROR_NOENT EXIT_NOTFOUND /* shell convention */
#define ERROR_PANIC 77 /* panic message with err_exit */
#define ERROR_LEVEL 0x00ff /* level portion of status */
#define ERROR_SYSTEM 0x0100 /* report system errno message */
#define ERROR_OUTPUT 0x0200 /* next arg is error fd */
#define ERROR_SOURCE 0x0400 /* next 2 args are FILE,LINE */
#define ERROR_USAGE 0x0800 /* usage message */
#define ERROR_PROMPT 0x1000 /* omit trailing newline */
#define ERROR_NOID 0x2000 /* omit err_id */
#define ERROR_LIBRARY 0x4000 /* library routine error */
#define ERROR_INTERACTIVE 0x0001 /* context is interactive */
#define ERROR_SILENT 0x0002 /* context is silent */
#define ERROR_NOTIFY 0x0004 /* main(-sig,0,ctx) on signal */
#define ERROR_FREE 0x0010 /* free context on pop */
#define ERROR_POP 0x0020 /* pop context */
#define ERROR_PUSH 0x0040 /* push context */
#define ERROR_SET 0x0080 /* set context */
#ifdef ECONNRESET
#define ERROR_PIPE(e) ((e)==EPIPE||(e)==ECONNRESET||(e)==EIO)
#else
#define ERROR_PIPE(e) ((e)==EPIPE||(e)==EIO)
#endif
/*
* errorpush()/errorpop() are obsolete -- use errorctx() instead
*/
#ifndef ERROR_CONTEXT_T
#define ERROR_CONTEXT_T Error_info_t
#endif
#define ERROR_CONTEXT_BASE ((Error_context_t*)&error_info.context)
#define errorpush(p,f) (*(p)=*ERROR_CONTEXT_BASE,*ERROR_CONTEXT_BASE=error_info.empty,error_info.context=(Error_context_t*)(p),error_info.flags=(f))
#define errorpop(p) (*ERROR_CONTEXT_BASE=*(p))
typedef struct Error_info_s Error_info_t;
typedef struct Error_context_s Error_context_t;
#define ERROR_CONTEXT \
ERROR_CONTEXT_T* context; /* prev context stack element */ \
int errors; /* >= ERROR_ERROR count */ \
int flags; /* context flags */ \
int line; /* input|output line number */ \
int warnings; /* ERROR_WARNING count */ \
char* file; /* input|output file name */ \
char* id; /* command id */
struct Error_context_s /* context stack element */
{
ERROR_CONTEXT
};
struct Error_info_s /* error state */
{
int fd; /* write(2) fd */
void (*exit)(int); /* error exit */
ssize_t (*write)(int, const void*, size_t); /* error output */
/* the rest are implicitly initialized */
int clear; /* default clear ERROR_* flags */
int core; /* level>=core -> core dump */
int indent; /* debug trace indent level */
int init; /* initialized */
int last_errno; /* last reported errno */
int mask; /* multi level debug trace mask */
int set; /* default set ERROR_* flags */
int trace; /* debug trace level */
char* version; /* ERROR_SOURCE command version */
int (*auxilliary)(Sfio_t*, int, int); /* aux info to append */
ERROR_CONTEXT /* top of context stack */
Error_context_t empty; /* empty context stack element */
unsigned long time; /* debug time trace */
char* (*translate)(const char*, const char*, const char*, const char*); /* format translator */
const char* catalog; /* message catalog */
};
#ifndef errno
extern int errno; /* system call error status */
#endif
#ifndef E2BIG
#define E2BIG ENOMEM
#endif
#ifndef EAGAIN
#define EAGAIN 11
#endif
#ifndef EBADF
#define EBADF 9
#endif
#ifndef EBUSY
#define EBUSY 16
#endif
#ifndef EDEADLK
#define EDEADLK 45
#endif
#ifndef EINTR
#define EINTR 4
#endif
#ifndef EILSEQ
#define EILSEQ EIO
#endif
#ifndef EINVAL
#define EINVAL 22
#endif
#ifndef ENOMEM
#define ENOMEM 12
#endif
#ifndef ENOSYS
#define ENOSYS EINVAL
#endif
#ifndef EPERM
#define EPERM 1
#endif
#ifndef ERANGE
#define ERANGE E2BIG
#endif
#ifndef ESPIPE
#define ESPIPE 29
#endif
#if _BLD_ast && defined(__EXPORT__)
#define extern extern __EXPORT__
#endif
#if !_BLD_ast && defined(__IMPORT__)
#define extern extern __IMPORT__
#endif
extern Error_info_t* _error_infop_;
#define error_info (*_error_infop_)
#undef extern
#if _BLD_ast && defined(__EXPORT__)
#define extern __EXPORT__
#endif
extern void error(int, ...);
extern int errormsg(const char*, int, ...);
extern int errorf(void*, void*, int, ...);
extern void errorv(const char*, int, va_list);
#ifndef errorx
extern char* errorx(const char*, const char*, const char*, const char*);
#endif
extern Error_info_t* errorctx(Error_info_t*, int, int);
#undef extern
#endif