Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save johnsonjh/f15c4cc9ff2646291be0a4c6af46d5ed to your computer and use it in GitHub Desktop.
Save johnsonjh/f15c4cc9ff2646291be0a4c6af46d5ed to your computer and use it in GitHub Desktop.
#pragma read_only_file
#pragma read_only_file
__declspec(__watcall) extern int *__get_errno_ptr( void );
#pragma read_only_file
#pragma pack( __push, 1 )
typedef unsigned short wchar_t;
typedef long off_t;
typedef int pid_t;
typedef unsigned short mode_t;
__declspec(__watcall) extern int open( const char *__path, int __oflag, ... );
__declspec(__watcall) extern int creat( const char *__path, mode_t __mode );
__declspec(__watcall) extern int sopen( const char *__path, int __oflag, int __share, ... );
__declspec(__watcall) extern int _open( const char *__path, int __oflag, ... );
__declspec(__watcall) extern int _creat( const char *__path, mode_t __mode );
__declspec(__watcall) extern int _sopen( const char *__path, int __oflag, int __share, ... );
__declspec(__watcall) extern int _wopen( const wchar_t *__path, int __oflag, ... );
__declspec(__watcall) extern int _wcreat( const wchar_t *, mode_t __mode );
__declspec(__watcall) extern int _wsopen( const wchar_t *, int, int, ... );
#pragma pack( __pop )
#pragma read_only_file
typedef unsigned int jmp_buf[13];
__declspec(__watcall) extern int _setjmp( jmp_buf __env );
__declspec(__watcall) __declspec(aborts) extern void longjmp( jmp_buf __env, int __val );
#pragma aux _setjmp __modify [__8087]
#pragma read_only_file
#pragma pack( __push, 1 )
typedef unsigned long time_t;
typedef time_t __w_time_t;
typedef long uid_t;
typedef int sig_atomic_t;
typedef void (__watcall *__sig_func)( int );
typedef void __watcall __sigfpe_func( int, int );
__declspec(__watcall) extern int raise( int __sig );
__declspec(__watcall) extern void (__watcall *signal( int __sig, void (__watcall *__func)(int) ) )(int);
#pragma pack( __pop )
#pragma read_only_file
#pragma pack( __push, 1 )
typedef unsigned size_t;
typedef size_t __w_size_t;
typedef signed ssize_t;
typedef char *__va_list;
struct __stream_link;
struct __iobuf {
unsigned char *_ptr;
int _cnt;
struct __stream_link *_link;
unsigned _flag;
int _handle;
unsigned _bufsize;
unsigned short _ungotten;
};
typedef struct __iobuf FILE;
typedef FILE __w_FILE;
typedef long fpos_t;
typedef unsigned short wint_t;
typedef wint_t __w_wint_t;
__declspec(__watcall) extern __w_FILE *__get_iob_ptr( void );
__declspec(__watcall) extern __w_FILE *__get_std_file(unsigned __handle);
__declspec(__watcall) extern __w_FILE __near __iob[];
__declspec(__watcall) extern void clearerr( FILE *__fp );
__declspec(__watcall) extern int fclose( FILE *__fp );
__declspec(__watcall) extern int feof( FILE *__fp );
__declspec(__watcall) extern int ferror( FILE *__fp );
__declspec(__watcall) extern int fflush( FILE *__fp );
__declspec(__watcall) extern int fgetc( FILE *__fp );
__declspec(__watcall) extern int fgetpos( FILE *__fp, fpos_t *__pos );
__declspec(__watcall) extern char *fgets( char *__s, int __n, FILE *__fp );
__declspec(__watcall) extern FILE *fopen( const char *__filename, const char *__mode );
__declspec(__watcall) extern int fprintf( FILE *__fp, const char *__format, ... );
__declspec(__watcall) extern int fputc( int __c, FILE *__fp );
__declspec(__watcall) extern int fputs( const char *__s, FILE *__fp );
__declspec(__watcall) extern size_t fread( void *__ptr, size_t __size, size_t __n, FILE *__fp );
__declspec(__watcall) extern FILE *freopen( const char *__filename, const char *__mode, FILE *__fp );
__declspec(__watcall) extern int fscanf( FILE*__fp, const char *__format, ... );
__declspec(__watcall) extern int fseek( FILE *__fp, long __offset, int __whence );
__declspec(__watcall) extern int fsetpos( FILE *__fp, const fpos_t *__pos );
__declspec(__watcall) extern long ftell( FILE *__fp );
__declspec(__watcall) extern size_t fwrite( const void *__ptr, size_t __size, size_t __n, FILE *__fp );
__declspec(__watcall) extern int getc( FILE *__fp );
__declspec(__watcall) extern int getchar( void );
__declspec(__watcall) extern ssize_t getdelim( char **__ptr1, size_t *__ptr2, int __delim, FILE *__fp);
__declspec(__watcall) extern ssize_t getline( char **__ptr1, size_t *__ptr2, FILE *__fp);
__declspec(__watcall) extern char *gets( char *__s );
__declspec(__watcall) extern void perror( const char *__s );
__declspec(__watcall) extern int printf( const char *__format, ... );
__declspec(__watcall) extern int putc( int __c, FILE *__fp );
__declspec(__watcall) extern int putchar( int __c );
__declspec(__watcall) extern int puts( const char *__s );
__declspec(__watcall) extern int remove( const char *__filename );
__declspec(__watcall) extern int rename( const char *__old, const char *__new );
__declspec(__watcall) extern void rewind( FILE *__fp );
__declspec(__watcall) extern int scanf( const char *__format, ... );
__declspec(__watcall) extern void setbuf( FILE *__fp, char *__buf );
__declspec(__watcall) extern int setvbuf( FILE *__fp, char *__buf, int __mode, size_t __size );
__declspec(__watcall) extern int sprintf( char *__s, const char *__format, ... );
__declspec(__watcall) extern int sscanf( const char *__s, const char *__format, ... );
__declspec(__watcall) extern FILE *tmpfile( void );
__declspec(__watcall) extern char *tmpnam( char *__s );
__declspec(__watcall) extern int ungetc( int __c, FILE *__fp );
__declspec(__watcall) extern int vfprintf( FILE *__fp, const char *__format, __va_list __arg );
__declspec(__watcall) extern int vprintf( const char *__format, __va_list __arg );
__declspec(__watcall) extern int vsprintf( char *__s, const char *__format, __va_list __arg );
__declspec(__watcall) extern int snprintf( char *__buf, size_t __bufsize, const char *__fmt, ... );
__declspec(__watcall) extern int vfscanf( FILE *__fp, const char *__format, __va_list __arg );
__declspec(__watcall) extern int vscanf( const char *__format, __va_list __arg );
__declspec(__watcall) extern int vsnprintf( char *__s, size_t __bufsize, const char *__format, __va_list __arg );
__declspec(__watcall) extern int vsscanf( const char *__s, const char *__format, __va_list __arg );
__declspec(__watcall) extern int _getw( __w_FILE *__fp );
__declspec(__watcall) extern int _pclose( __w_FILE *__fp );
__declspec(__watcall) extern __w_FILE *_popen( const char *__command, const char *__mode );
__declspec(__watcall) extern int _putw( int __binint, __w_FILE *__fp );
__declspec(__watcall) extern char *tempnam( const char *__dir, const char *__prefix );
__declspec(__watcall) extern char *_tempnam( const char *__dir, const char *__prefix );
__declspec(__watcall) extern wint_t getwc( FILE * );
__declspec(__watcall) extern wint_t getwchar( void );
__declspec(__watcall) extern wint_t fgetwc( FILE * );
__declspec(__watcall) extern wchar_t *fgetws( wchar_t *, int, FILE * );
__declspec(__watcall) extern wint_t fputwc( wint_t, FILE * );
__declspec(__watcall) extern int fputws( const wchar_t *, FILE * );
__declspec(__watcall) extern int fwprintf( FILE *, const wchar_t *, ... );
__declspec(__watcall) extern int fwscanf( FILE *, const wchar_t *, ... );
__declspec(__watcall) extern wint_t putwc( wint_t, FILE * );
__declspec(__watcall) extern wint_t putwchar( wint_t );
__declspec(__watcall) extern int swprintf( wchar_t *, size_t, const wchar_t *, ... );
__declspec(__watcall) extern int swscanf( const wchar_t *, const wchar_t *, ... );
__declspec(__watcall) extern wint_t ungetwc( wint_t, FILE * );
__declspec(__watcall) extern int vfwprintf( FILE *, const wchar_t *, __va_list );
__declspec(__watcall) extern int vfwscanf( FILE *, const wchar_t *, __va_list );
__declspec(__watcall) extern int vswprintf( wchar_t *, size_t, const wchar_t *, __va_list );
__declspec(__watcall) extern int vswscanf( const wchar_t *, const wchar_t *, __va_list );
__declspec(__watcall) extern int vwprintf( const wchar_t *, __va_list );
__declspec(__watcall) extern int vwscanf( const wchar_t *, __va_list );
__declspec(__watcall) extern int wprintf( const wchar_t *, ... );
__declspec(__watcall) extern int wscanf( const wchar_t *, ... );
__declspec(__watcall) extern int _fseeki64( __w_FILE *__fp, long long __offset, int __whence );
__declspec(__watcall) extern long long _ftelli64( __w_FILE *__fp );
__declspec(__watcall) extern int flushall( void );
__declspec(__watcall) extern __w_FILE *_fdopen( int __handle, const char *__mode );
__declspec(__watcall) extern __w_FILE *fdopen( int __handle, const char *__mode );
__declspec(__watcall) extern int _bprintf( char *__buf, __w_size_t __bufsize, const char *__fmt, ... );
__declspec(__watcall) extern int _fgetchar( void );
__declspec(__watcall) extern int _fileno( __w_FILE * );
__declspec(__watcall) extern int _fputchar( int __c );
__declspec(__watcall) extern __w_FILE *_fsopen( const char *__filename, const char *__mode, int __shflag );
__declspec(__watcall) extern int _grow_handles( int __new_count );
__declspec(__watcall) extern int _snprintf( char *__buf, __w_size_t __bufsize, const char *__fmt, ... );
__declspec(__watcall) extern int _vbprintf( char *__s, __w_size_t __bufsize, const char *__format, __va_list __arg );
__declspec(__watcall) extern int _vsnprintf( char *__s, __w_size_t __bufsize, const char *__format, __va_list __arg );
__declspec(__watcall) extern int fcloseall( void );
__declspec(__watcall) extern int fgetchar( void );
__declspec(__watcall) extern int fileno( __w_FILE * );
__declspec(__watcall) extern int fputchar( int __c );
__declspec(__watcall) extern int _bwprintf( wchar_t *, __w_size_t, const wchar_t *, ... );
__declspec(__watcall) extern __w_wint_t _fgetwchar( void );
__declspec(__watcall) extern __w_wint_t _fputwchar( __w_wint_t );
__declspec(__watcall) extern wchar_t *_getws( wchar_t * );
__declspec(__watcall) extern int _putws( const wchar_t * );
__declspec(__watcall) extern int _snwprintf( wchar_t *, __w_size_t, const wchar_t *, ... );
__declspec(__watcall) extern int snwprintf( wchar_t *, __w_size_t, const wchar_t *, ... );
__declspec(__watcall) extern int _swprintf( wchar_t *, const wchar_t *, ... );
__declspec(__watcall) extern __w_FILE *_wfdopen( int, const wchar_t * );
__declspec(__watcall) extern __w_FILE *_wfopen( const wchar_t *, const wchar_t * );
__declspec(__watcall) extern __w_FILE *_wfreopen( const wchar_t *, const wchar_t *, __w_FILE * );
__declspec(__watcall) extern __w_FILE *_wfsopen( const wchar_t *__filename, const wchar_t *__mode, int __shflag );
__declspec(__watcall) extern void _wperror( const wchar_t * );
__declspec(__watcall) extern __w_FILE *_wpopen( const wchar_t *__command, const wchar_t *__mode );
__declspec(__watcall) extern int _vbwprintf( wchar_t *, __w_size_t, const wchar_t *, __va_list );
__declspec(__watcall) extern int _vsnwprintf( wchar_t *, __w_size_t, const wchar_t *, __va_list );
__declspec(__watcall) extern int vsnwprintf( wchar_t *, __w_size_t, const wchar_t *, __va_list );
__declspec(__watcall) extern int _vswprintf( wchar_t *, const wchar_t *, __va_list );
__declspec(__watcall) extern __w_wint_t fgetwchar( void );
__declspec(__watcall) extern __w_wint_t fputwchar( __w_wint_t );
__declspec(__watcall) extern wchar_t *getws( wchar_t * );
__declspec(__watcall) extern int putws( const wchar_t * );
__declspec(__watcall) extern int _wremove( const wchar_t * );
__declspec(__watcall) extern int _wrename( const wchar_t *, const wchar_t * );
__declspec(__watcall) extern wchar_t *_wtempnam( const wchar_t *__dir, const wchar_t *__prefix );
__declspec(__watcall) extern wchar_t *_wtmpnam( wchar_t * );
#pragma pack( __pop )
#pragma read_only_file
#pragma pack( __push, 1 )
typedef struct {
int quot;
int rem;
} div_t;
typedef struct {
long quot;
long rem;
} ldiv_t;
typedef struct {
long long quot;
long long rem;
} lldiv_t;
__declspec(__watcall) extern int abs( int __j );
__declspec(__watcall) extern int atexit( void (__watcall *__func)( void ) );
__declspec(__watcall) extern double atof( const char *__nptr );
__declspec(__watcall) extern int atoi( const char *__nptr );
__declspec(__watcall) extern long atol( const char *__nptr );
__declspec(__watcall) extern long long atoll( const char *__nptr );
__declspec(__watcall) extern void *bsearch( const void *__key, const void *__base,
size_t __nmemb, size_t __size,
int (__watcall *__compare)(const void *__pkey, const void *__pbase) );
__declspec(__watcall) extern void *calloc( size_t __n, size_t __size );
__declspec(__watcall) extern div_t div( int __numer, int __denom );
__declspec(__watcall) extern void free( void *__ptr );
__declspec(__watcall) extern long labs( long __j );
__declspec(__watcall) extern ldiv_t ldiv( long __numer, long __denom );
__declspec(__watcall) extern long long llabs( long long __j );
__declspec(__watcall) extern lldiv_t lldiv( long long __numer, long long __denom );
__declspec(__watcall) extern void *malloc( size_t __size );
__declspec(__watcall) extern int mblen( const char *__s, size_t __n );
__declspec(__watcall) extern size_t mbstowcs( wchar_t *__pwcs, const char *__s, size_t __n );
__declspec(__watcall) extern int mbtowc( wchar_t *__pwc, const char *__s, size_t __n );
__declspec(__watcall) extern size_t wcstombs( char *__s, const wchar_t *__pwcs, size_t __n );
__declspec(__watcall) extern int wctomb( char *__s, wchar_t __wchar );
__declspec(__watcall) extern void qsort( void *__base, size_t __nmemb, size_t __size,
int (__watcall *__compare)( const void *, const void * ) );
__declspec(__watcall) extern int rand( void );
__declspec(__watcall) extern void *realloc( void *__ptr, size_t __size );
__declspec(__watcall) extern void srand( unsigned int __seed );
__declspec(__watcall) __declspec(aborts) extern void abort( void );
__declspec(__watcall) __declspec(aborts) extern void exit( int __status );
__declspec(__watcall) extern char *getenv( const char *__name );
__declspec(__watcall) extern int system( const char *__cmd );
__declspec(__watcall) extern double strtod( const char *__nptr, char **__endptr );
__declspec(__watcall) extern float strtof( const char *__nptr, char **__endptr );
__declspec(__watcall) extern long double strtold( const char *__nptr, char **__endptr );
__declspec(__watcall) extern long strtol( const char *__nptr, char **__endptr, int __base );
__declspec(__watcall) extern long long strtoll( const char *__nptr, char **__endptr, int __base );
__declspec(__watcall) extern unsigned long strtoul( const char *__nptr, char **__endptr, int __base );
__declspec(__watcall) extern unsigned long long strtoull( const char *__nptr, char **__endptr, int __base );
__declspec(__watcall) extern double wcstod( const wchar_t *, wchar_t ** );
__declspec(__watcall) extern float wcstof( const wchar_t *, wchar_t ** );
__declspec(__watcall) extern long double wcstold( const wchar_t *, wchar_t ** );
__declspec(__watcall) extern long wcstol( const wchar_t *, wchar_t **, int );
__declspec(__watcall) extern long long wcstoll( const wchar_t *, wchar_t **, int );
__declspec(__watcall) extern unsigned long wcstoul( const wchar_t *, wchar_t **, int );
__declspec(__watcall) extern unsigned long long wcstoull( const wchar_t *, wchar_t **, int );
__declspec(__watcall) __declspec(aborts) extern void _Exit( int __status );
__declspec(__watcall) __declspec(aborts) extern void _exit( int __status );
__declspec(__watcall) extern void break_on( void );
__declspec(__watcall) extern void break_off( void );
__declspec(__watcall) extern char *ecvt( double __val, int __ndig, int *__dec, int *__sign );
__declspec(__watcall) extern char *_ecvt( double __val, int __ndig, int *__dec, int *__sign );
__declspec(__watcall) extern char *fcvt( double __val, int __ndig, int *__dec, int *__sign );
__declspec(__watcall) extern char *_fcvt( double __val, int __ndig, int *__dec, int *__sign );
__declspec(__watcall) extern char *gcvt( double __val, int __ndig, char *__buf );
__declspec(__watcall) extern char *_gcvt( double __val, int __ndig, char *__buf );
__declspec(__watcall) extern char *itoa( int __value, char *__buf, int __radix );
__declspec(__watcall) extern char *_itoa( int __value, char *__buf, int __radix );
__declspec(__watcall) extern unsigned long _lrotl( unsigned long __value, unsigned int __shift );
__declspec(__watcall) extern unsigned long _lrotr( unsigned long __value, unsigned int __shift );
__declspec(__watcall) extern char *ltoa( long __value, char *__buf, int __radix );
__declspec(__watcall) extern char *lltoa( long long __value, char *__buf, int __radix );
__declspec(__watcall) extern char *_ltoa( long __value, char *__buf, int __radix );
__declspec(__watcall) extern char *_lltoa( long long __value, char *__buf, int __radix );
__declspec(__watcall) extern int mkstemp( char *__template );
__declspec(__watcall) extern unsigned int _rotl( unsigned int __value, unsigned int __shift );
__declspec(__watcall) extern unsigned int _rotr( unsigned int __value, unsigned int __shift );
__declspec(__watcall) extern int putenv( const char *__string );
__declspec(__watcall) extern int setenv( const char *__name, const char *__newvalue, int __overwrite );
__declspec(__watcall) extern int unsetenv( const char *__name );
__declspec(__watcall) extern int _putenv( const char *__string );
__declspec(__watcall) extern char *_fullpath( char *__buf, const char *__path, __w_size_t __size );
__declspec(__watcall) extern void _searchenv( const char *__name, const char *__env_var, char *__buf );
__declspec(__watcall) extern void _makepath( char *__path, const char *__drive,
const char *__dir, const char *__fname, const char *__ext );
__declspec(__watcall) extern void _splitpath( const char *__path, char *__drive,
char *__dir, char *__fname, char *__ext );
__declspec(__watcall) extern void _splitpath2( const char *__inp, char *__outp,
char **__drive, char **__dir,
char **__fn, char **__ext );
__declspec(__watcall) extern wchar_t *_wecvt( double __val, int __ndig, int *__dec, int *__sign );
__declspec(__watcall) extern wchar_t *_wfcvt( double __val, int __ndig, int *__dec, int *__sign );
__declspec(__watcall) extern wchar_t *_wgcvt( double __val, int __ndig, wchar_t *__buf );
__declspec(__watcall) extern int _wtoi( const wchar_t * );
__declspec(__watcall) extern long _wtol( const wchar_t * );
__declspec(__watcall) extern long long _wtoll( const wchar_t * );
__declspec(__watcall) extern wchar_t *_itow( int, wchar_t *, int );
__declspec(__watcall) extern wchar_t *_ltow( long, wchar_t *, int );
__declspec(__watcall) extern wchar_t *_lltow( long long, wchar_t *, int );
__declspec(__watcall) extern wchar_t *_utow( unsigned int, wchar_t *, int );
__declspec(__watcall) extern wchar_t *_ultow( unsigned long, wchar_t *, int );
__declspec(__watcall) extern wchar_t *_ulltow( unsigned long long, wchar_t *, int );
__declspec(__watcall) extern double _wtof( const wchar_t * );
__declspec(__watcall) extern double _watof( const wchar_t * );
__declspec(__watcall) extern wchar_t *_atouni( wchar_t *, const char * );
__declspec(__watcall) extern wchar_t *_wgetenv( const wchar_t *__name );
__declspec(__watcall) extern int _wputenv( const wchar_t *__env_string );
__declspec(__watcall) extern int _wsetenv( const wchar_t *__name, const wchar_t *__newvalue, int __overwrite );
__declspec(__watcall) extern int _wunsetenv( const wchar_t *__name );
__declspec(__watcall) extern int _wsystem( const wchar_t *__cmd );
__declspec(__watcall) extern wchar_t *_wfullpath( wchar_t *, const wchar_t *, __w_size_t );
__declspec(__watcall) extern void _wsearchenv( const wchar_t *__name, const wchar_t *__env_var, wchar_t *__buf );
__declspec(__watcall) extern void _wmakepath( wchar_t *__path, const wchar_t *__drive,
const wchar_t *__dir,
const wchar_t *__fname,
const wchar_t *__ext );
__declspec(__watcall) extern void _wsplitpath( const wchar_t *__path,
wchar_t *__drive, wchar_t *__dir,
wchar_t *__fname, wchar_t *__ext );
__declspec(__watcall) extern void _wsplitpath2( const wchar_t *__inp,
wchar_t *__outp, wchar_t **__drive,
wchar_t **__dir, wchar_t **__fn,
wchar_t **__ext );
__declspec(__watcall) extern void swab( char *__src, char *__dest, int __num );
__declspec(__watcall) extern char *ultoa( unsigned long __value, char *__buf, int __radix );
__declspec(__watcall) extern char *ulltoa( unsigned long long __value, char *__buf, int __radix );
__declspec(__watcall) extern char *_ultoa( unsigned long __value, char *__buf, int __radix );
__declspec(__watcall) extern char *_ulltoa( unsigned long long __value, char *__buf, int __radix );
__declspec(__watcall) extern char *utoa( unsigned int __value, char *__buf, int __radix );
__declspec(__watcall) extern char *_utoa( unsigned int __value, char *__buf, int __radix );
__declspec(__watcall) extern char *_i64toa( __int64 __value, char *__buf, int __radix );
__declspec(__watcall) extern char *_ui64toa( unsigned __int64 __value, char *__buf, int __radix );
__declspec(__watcall) extern __int64 _atoi64( const char *__nptr );
__declspec(__watcall) extern __int64 _strtoi64( const char *__nptr, char **__endptr, int __base );
__declspec(__watcall) extern unsigned __int64 _strtoui64( const char *__nptr, char **__endptr, int __base );
__declspec(__watcall) extern int _fwctomb( char __far * __s, wchar_t __wchar );
__declspec(__watcall) extern size_t _fmbstowcs( wchar_t __far * __pwcs, const char __far * __s, size_t __n );
__declspec(__watcall) extern size_t _fwcstombs( char __far * __s, const wchar_t __far * __pwcs, size_t __n );
__declspec(__watcall) extern int _fmblen( const char __far * __s, size_t __n );
__declspec(__watcall) extern int _fmbtowc( wchar_t __far * __pwc, const char __far * __s, size_t __n );
__declspec(__watcall) extern char ***__get_environ_ptr( void );
__declspec(__watcall) extern char ** __near environ;
__declspec(__watcall) extern wchar_t ***__get_wenviron_ptr( void );
__declspec(__watcall) extern wchar_t ** __near _wenviron;
__declspec(__watcall) extern char **__get_pgmptr_ptr( void );
__declspec(__watcall) extern char * __near _pgmptr;
__declspec(__watcall) extern int _doserrno;
__declspec(__watcall) extern int *__get_doserrno_ptr( void );
__declspec(__watcall) extern unsigned *__get_psp_ptr( void );
__declspec(__watcall) extern unsigned char *__get_osmode_ptr( void );
__declspec(__watcall) extern int *__get_fmode_ptr( void );
__declspec(__watcall) extern unsigned *__get_minreal_ptr( void );
__declspec(__watcall) extern unsigned long *__get_win_alloc_flags_ptr( void );
__declspec(__watcall) extern unsigned long *__get_win_realloc_flags_ptr( void );
__declspec(__watcall) extern unsigned __near _psp;
__declspec(__watcall) extern unsigned char __near _osmode;
__declspec(__watcall) extern int __near _fmode;
__declspec(__watcall) extern unsigned __near __minreal;
__declspec(__watcall) extern unsigned long __near __win_alloc_flags;
__declspec(__watcall) extern unsigned long __near __win_realloc_flags;
__declspec(__watcall) extern char **__get_sys_errlist_ptr( void );
__declspec(__watcall) extern int *__get_sys_nerr_ptr( void );
__declspec(__watcall) extern char * __near _sys_errlist[];
__declspec(__watcall) extern int __near _sys_nerr;
__declspec(__watcall) extern unsigned *__get_amblksiz_ptr( void );
__declspec(__watcall) extern unsigned char *__get_osmajor_ptr( void );
__declspec(__watcall) extern unsigned char *__get_osminor_ptr( void );
__declspec(__watcall) extern unsigned __near _amblksiz;
__declspec(__watcall) extern unsigned char __near _osmajor;
__declspec(__watcall) extern unsigned char __near _osminor;
extern int __argc;
extern char **__argv;
__declspec(__watcall) extern unsigned stackavail( void );
__declspec(__watcall) extern unsigned _stackavail( void );
#pragma aux stackavail __modify __nomemory
#pragma aux _stackavail __modify __nomemory
extern void __based(__segname("_STACK")) *__doalloca(__w_size_t __size);
#pragma aux __doalloca = \
"sub sp,ax" \
__parm __nomemory [__ax] \
__value [__sp] \
__modify __exact __nomemory [__sp]
__declspec(__watcall) extern void __near *__brk( unsigned __new_brk_value );
__declspec(__watcall) extern void __near *sbrk( int __increment );
typedef void (__watcall *onexit_t)( void );
__declspec(__watcall) extern onexit_t onexit( onexit_t __func );
typedef void (__watcall *_onexit_t)( void );
__declspec(__watcall) extern _onexit_t _onexit( _onexit_t __func );
#pragma pack( __pop )
#pragma read_only_file
__declspec(__watcall) extern void *memchr( const void *__s, int __c, size_t __n );
__declspec(__watcall) extern int memcmp( const void *__s1, const void *__s2, size_t __n );
__declspec(__watcall) extern void *memcpy( void *__s1, const void *__s2, size_t __n );
__declspec(__watcall) extern void *memmove( void *__s1, const void *__s2, size_t __n );
__declspec(__watcall) extern void *memset( void *__s, int __c, size_t __n );
__declspec(__watcall) extern char *strcat( char *__s1, const char *__s2 );
__declspec(__watcall) extern char *strchr( const char *__s, int __c );
__declspec(__watcall) extern int strcmp( const char *__s1, const char *__s2 );
__declspec(__watcall) extern int strcoll( const char *__s1, const char *__s2 );
__declspec(__watcall) extern char *strcpy( char *__s1, const char *__s2 );
__declspec(__watcall) extern size_t strcspn( const char *__s1, const char *__s2 );
__declspec(__watcall) extern size_t strlen( const char *__s );
__declspec(__watcall) extern char *strncat( char *__s1, const char *__s2, size_t __n );
__declspec(__watcall) extern int strncmp( const char *__s1, const char *__s2, size_t __n );
__declspec(__watcall) extern char *strncpy( char *__s1, const char *__s2, size_t __n );
__declspec(__watcall) extern char *strpbrk( const char *__s1, const char *__s2 );
__declspec(__watcall) extern char *strrchr( const char *__s, int __c );
__declspec(__watcall) extern size_t strspn( const char *__s1, const char *__s2 );
__declspec(__watcall) extern char *strstr( const char *__s1, const char *__s2 );
__declspec(__watcall) extern char *strtok( char *__s1, const char *__s2 );
__declspec(__watcall) extern size_t strxfrm( char *__s1, const char *__s2, size_t __n );
__declspec(__watcall) extern char *strerror( int __errnum );
__declspec(__watcall) extern int strcmpi( const char *__s1, const char *__s2 );
__declspec(__watcall) extern char *strnset( char *__string, int __c, __w_size_t __len );
__declspec(__watcall) extern int strnicmp( const char *__s1, const char *__s2, __w_size_t __n );
__declspec(__watcall) extern char *strlwr( char *__string );
__declspec(__watcall) extern char *strupr( char *__string );
__declspec(__watcall) extern int stricmp( const char *__s1, const char *__s2 );
__declspec(__watcall) extern char *strrev( char *__string );
__declspec(__watcall) extern char *strset( char *__string, int __c );
__declspec(__watcall) extern int memicmp( const void *__s1, const void *__s2, __w_size_t __n );
__declspec(__watcall) extern int _stricoll( const char *__s1, const char *__s2 );
__declspec(__watcall) extern int _strncoll( const char *__s1, const char *__s2, __w_size_t __n );
__declspec(__watcall) extern int _strnicoll( const char *__s1, const char *__s2, __w_size_t __n );
__declspec(__watcall) extern char *_strnset( char *__string, int __c, __w_size_t __len );
__declspec(__watcall) extern int _strnicmp( const char *__s1, const char *__s2, __w_size_t __n );
__declspec(__watcall) extern char *_strlwr( char *__string );
__declspec(__watcall) extern char *_strupr( char *__string );
__declspec(__watcall) extern int _stricmp( const char *__s1, const char *__s2 );
__declspec(__watcall) extern char *_strrev( char *__string );
__declspec(__watcall) extern char *_strset( char *__string, int __c );
__declspec(__watcall) extern char *_strerror( const char *__s );
__declspec(__watcall) extern char *_strdup( const char *__string );
__declspec(__watcall) extern int _memicmp( const void *__s1, const void *__s2, __w_size_t __n );
__declspec(__watcall) extern void *_memccpy( void *__s1, const void *__s2, int __c, __w_size_t __n );
__declspec(__watcall) extern char *strdup( const char *__string );
__declspec(__watcall) extern void *memccpy( void *__s1, const void *__s2, int __c, __w_size_t __n );
__declspec(__watcall) extern char *strspnp( const char *__s1, const char *__s2 );
__declspec(__watcall) extern char *strtok_r( char *__s1, const char *__s2, char **__p1 );
__declspec(__watcall) extern void __far *_fmemccpy( void __far *__s1, const void __far *__s2, int __c, __w_size_t __n );
__declspec(__watcall) extern void __far *_fmemchr( const void __far *__s, int __c, __w_size_t __n );
__declspec(__watcall) extern int _fmemcmp( const void __far *__s1, const void __far *__s2, __w_size_t __n );
__declspec(__watcall) extern void __far *_fmemcpy( void __far *__s1, const void __far *__s2, __w_size_t __n );
__declspec(__watcall) extern int _fmemicmp( const void __far *__s1, const void __far *__s2, __w_size_t __n );
__declspec(__watcall) extern void __far *_fmemmove( void __far *__s1, const void __far *__s2, __w_size_t __n );
__declspec(__watcall) extern void __far *_fmemset( void __far *__s, int __c, __w_size_t __n );
__declspec(__watcall) extern char __far *_fstrcat( char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern char __far *_fstrchr( const char __far *__s, int __c );
__declspec(__watcall) extern int _fstrcmp( const char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern char __far *_fstrcpy( char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern __w_size_t _fstrcspn( const char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern char __far *_fstrdup( const char __far *__string );
__declspec(__watcall) extern int _fstricmp( const char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern __w_size_t _fstrlen( const char __far *__s );
__declspec(__watcall) extern char __far *_fstrlwr( char __far *__string );
__declspec(__watcall) extern char __far *_fstrncat( char __far *__s1, const char __far *__s2, __w_size_t __n );
__declspec(__watcall) extern int _fstrncmp( const char __far *__s1, const char __far *__s2, __w_size_t __n );
__declspec(__watcall) extern char __far *_fstrncpy( char __far *__s1, const char __far *__s2, __w_size_t __n );
__declspec(__watcall) extern int _fstrnicmp( const char __far *__s1, const char __far *__s2, __w_size_t __n );
__declspec(__watcall) extern char __far *_fstrnset( char __far *__string, int __c, __w_size_t __len );
__declspec(__watcall) extern char __far *_fstrpbrk( const char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern char __far *_fstrrchr( const char __far *__s, int __c );
__declspec(__watcall) extern char __far *_fstrrev( char __far *__string );
__declspec(__watcall) extern char __far *_fstrset( char __far *__string, int __c );
__declspec(__watcall) extern __w_size_t _fstrspn( const char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern char __far *_fstrstr( const char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern char __far *_fstrtok( char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern char __far *_fstrupr( char __far *__string );
__declspec(__watcall) extern char __far *_fstrspnp( const char __far *__s1, const char __far *__s2 );
__declspec(__watcall) extern char __far *_fstrtok_r( char __far *__str, const char __far *__charset, char __far **__ptr );
__declspec(__watcall) extern void movedata( unsigned __srcseg, unsigned __srcoff, unsigned __tgtseg, unsigned __tgtoff, unsigned __len );
__declspec(__watcall) extern __w_size_t strlcat( char *__s1, const char *__s2, __w_size_t __n );
__declspec(__watcall) extern __w_size_t strlcpy( char *__s1, const char *__s2, __w_size_t __n );
__declspec(__watcall) extern wchar_t *wcscat( wchar_t *, const wchar_t * );
__declspec(__watcall) extern wchar_t *wcschr( const wchar_t *, wint_t );
__declspec(__watcall) extern int wcscmp( const wchar_t *, const wchar_t * );
__declspec(__watcall) extern int wcscoll( const wchar_t *__s1, const wchar_t *__s2 );
__declspec(__watcall) extern wchar_t *wcscpy( wchar_t *, const wchar_t * );
__declspec(__watcall) extern size_t wcscspn( const wchar_t *, const wchar_t * );
__declspec(__watcall) extern size_t wcslen( const wchar_t * );
__declspec(__watcall) extern wchar_t *wcsncat( wchar_t *, const wchar_t *, size_t );
__declspec(__watcall) extern int wcsncmp( const wchar_t *, const wchar_t *, size_t );
__declspec(__watcall) extern wchar_t *wcsncpy( wchar_t *, const wchar_t *, size_t );
__declspec(__watcall) extern wchar_t *wcspbrk( const wchar_t *, const wchar_t * );
__declspec(__watcall) extern wchar_t *wcsrchr( const wchar_t *, wint_t );
__declspec(__watcall) extern size_t wcsspn( const wchar_t *, const wchar_t * );
__declspec(__watcall) extern wchar_t *wcsstr( const wchar_t *, const wchar_t * );
__declspec(__watcall) extern wchar_t *wcstok( wchar_t *, const wchar_t *, wchar_t ** );
__declspec(__watcall) extern size_t wcsxfrm( wchar_t *__s1, const wchar_t *__s2, size_t __n );
__declspec(__watcall) extern wchar_t *_wcserror( int __errnum );
__declspec(__watcall) extern wchar_t *__wcserror( const wchar_t * );
__declspec(__watcall) extern wchar_t *_wcsnset( wchar_t *, int, __w_size_t );
__declspec(__watcall) extern int _wcsnicmp( const wchar_t *, const wchar_t *, __w_size_t );
__declspec(__watcall) extern wchar_t *_wcslwr( wchar_t * );
__declspec(__watcall) extern wchar_t *_wcsupr( wchar_t * );
__declspec(__watcall) extern int _wcsicmp( const wchar_t *, const wchar_t * );
__declspec(__watcall) extern wchar_t *_wcsrev( wchar_t * );
__declspec(__watcall) extern wchar_t *_wcsset( wchar_t *, wchar_t );
__declspec(__watcall) extern int _wcsicoll( const wchar_t *__s1, const wchar_t *__s2 );
__declspec(__watcall) extern int _wcsncoll( const wchar_t *__s1, const wchar_t *__s2, __w_size_t __n );
__declspec(__watcall) extern int _wcsnicoll( const wchar_t *__s1, const wchar_t *__s2, __w_size_t __n );
__declspec(__watcall) extern wchar_t *_wcsdup( const wchar_t * );
__declspec(__watcall) extern wchar_t *wcsdup( const wchar_t * );
#pragma read_only_file
#pragma pack( __push, 1 )
typedef unsigned long clock_t;
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
typedef struct tm __w_tm;
struct timespec {
__w_time_t tv_sec;
long tv_nsec;
};
__declspec(__watcall) extern char *asctime( const struct tm *__timeptr );
__declspec(__watcall) extern clock_t clock( void );
__declspec(__watcall) extern char *ctime( const time_t *__timer );
__declspec(__watcall) extern double difftime( time_t __t1, time_t __t0 );
__declspec(__watcall) extern struct tm *gmtime( const time_t *__timer );
__declspec(__watcall) extern struct tm *localtime( const time_t *__timer );
__declspec(__watcall) extern time_t mktime( struct tm *__timeptr );
__declspec(__watcall) extern size_t strftime( char *__s, size_t __maxsiz, const char *__fmt, const struct tm *__tp );
__declspec(__watcall) extern time_t time( time_t *__timer );
__declspec(__watcall) extern size_t wcsftime( wchar_t *, size_t, const wchar_t *, const struct tm * );
__declspec(__watcall) extern wchar_t *_wasctime( const __w_tm * );
__declspec(__watcall) extern wchar_t *_wctime( const __w_time_t * );
__declspec(__watcall) extern wchar_t *_wstrdate( wchar_t *__buf );
__declspec(__watcall) extern wchar_t *_wstrtime( wchar_t *__buf );
__declspec(__watcall) extern __w_size_t _wstrftime_ms( wchar_t *, __w_size_t, const char *, const __w_tm * );
__declspec(__watcall) extern char *_asctime( const __w_tm *__timeptr, char *__buf );
__declspec(__watcall) extern char *_ctime( const __w_time_t *__timer, char *__buf );
__declspec(__watcall) extern __w_tm *_gmtime( const __w_time_t *__timer, __w_tm *__tmbuf );
__declspec(__watcall) extern __w_tm *_localtime( const __w_time_t *__timer, __w_tm *__tmbuf );
__declspec(__watcall) extern char *_strdate( char *__buf );
__declspec(__watcall) extern char *_strtime( char *__buf );
__declspec(__watcall) extern wchar_t *__wctime( const __w_time_t *, wchar_t * );
__declspec(__watcall) extern wchar_t *__wasctime( const __w_tm *, wchar_t * );
__declspec(__watcall) extern void tzset( void );
__declspec(__watcall) extern char **__get_tzname_ptr( void );
__declspec(__watcall) extern char * __near tzname[2];
__declspec(__watcall) extern long *__get_timezone_ptr( void );
__declspec(__watcall) extern int *__get_daylight_ptr( void );
__declspec(__watcall) extern long __near timezone;
__declspec(__watcall) extern int __near daylight;
#pragma pack( __pop )
#pragma read_only_file
#pragma read_only_file
#pragma read_only_file
#pragma pack( __push, 1 )
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
typedef int timer_t;
typedef int clockid_t;
struct sched_param {
int sched_priority;
};
typedef int dev_t;
typedef unsigned int ino_t;
typedef unsigned short nlink_t;
typedef short gid_t;
typedef long id_t;
#pragma pack( __pop )
#pragma read_only_file
#pragma pack( __push, 1 )
struct stat {
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
off_t st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
time_t st_btime;
unsigned long st_attr;
unsigned long st_archivedID;
unsigned long st_updatedID;
unsigned short st_inheritedRightsMask;
unsigned char st_originatingNameSpace;
};
struct _stat {
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
off_t st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
time_t st_btime;
unsigned long st_attr;
unsigned long st_archivedID;
unsigned long st_updatedID;
unsigned short st_inheritedRightsMask;
unsigned char st_originatingNameSpace;
};
struct _stati64 {
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
__int64 st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
time_t st_btime;
unsigned long st_attr;
unsigned long st_archivedID;
unsigned long st_updatedID;
unsigned short st_inheritedRightsMask;
unsigned char st_originatingNameSpace;
};
__declspec(__watcall) extern int chmod( const char *__path, mode_t __pmode );
__declspec(__watcall) extern mode_t umask( mode_t __cmask );
__declspec(__watcall) extern int mkdir( const char *__path );
__declspec(__watcall) extern int stat( const char *__path, struct stat *__buf );
__declspec(__watcall) extern int fstat( int __fildes, struct stat *__buf );
__declspec(__watcall) extern int lstat( const char *__path, struct stat *__buf );
__declspec(__watcall) extern int _mkdir( const char *__path );
__declspec(__watcall) extern int _stat( const char *__path, struct stat *__buf );
__declspec(__watcall) extern int _stati64( const char *__path, struct _stati64 *__buf );
__declspec(__watcall) extern int _fstat( int __fildes, struct stat *__buf );
__declspec(__watcall) extern int _fstati64( int __fildes, struct _stati64 *__buf );
__declspec(__watcall) extern int _wmkdir( const wchar_t *__path );
__declspec(__watcall) extern int _wstat( const wchar_t *__path, struct stat *__buf );
__declspec(__watcall) extern int _wstati64( const wchar_t *__path, struct _stati64 *__buf );
#pragma pack( __pop )
#pragma pack( __push, 1 )
typedef long intptr_t;
typedef intptr_t __w_intptr_t;
typedef unsigned long _fsize_t;
struct _finddata_t {
unsigned attrib;
time_t time_create;
time_t time_access;
time_t time_write;
_fsize_t size;
char name[144];
};
struct _wfinddata_t {
unsigned attrib;
time_t time_create;
time_t time_access;
time_t time_write;
_fsize_t size;
wchar_t name[144];
};
struct _finddatai64_t {
unsigned attrib;
time_t time_create;
time_t time_access;
time_t time_write;
__int64 size;
char name[144];
};
struct _wfinddatai64_t {
unsigned attrib;
time_t time_create;
time_t time_access;
time_t time_write;
__int64 size;
wchar_t name[144];
};
__declspec(__watcall) extern ssize_t read( int fildes, void *buf, __w_size_t nbyte );
__declspec(__watcall) extern ssize_t write( int fildes, const void *buf, __w_size_t nbyte );
__declspec(__watcall) extern int access( const char *__path, int __mode );
__declspec(__watcall) extern int dup( int __handle );
__declspec(__watcall) extern int dup2( int __handle1, int __handle2 );
__declspec(__watcall) extern int close( int __fildes );
__declspec(__watcall) extern off_t lseek( int __handle, off_t __offset, int __origin );
__declspec(__watcall) extern int unlink( const char *__path );
__declspec(__watcall) extern int isatty( int __handle );
__declspec(__watcall) extern int fsync( int __handle );
__declspec(__watcall) extern int chmod( const char *__path, mode_t __pmode );
__declspec(__watcall) extern int locking( int __handle, int __mode, unsigned long __nbyte );
__declspec(__watcall) extern int eof( int __handle );
__declspec(__watcall) extern long filelength( int __handle );
__declspec(__watcall) extern off_t tell( int __handle );
__declspec(__watcall) extern int chsize( int __handle, long __size );
__declspec(__watcall) extern int setmode( int __handle, int __mode );
__declspec(__watcall) extern int open( const char *__path, int __oflag, ... );
__declspec(__watcall) extern int creat( const char *__path, mode_t __mode );
__declspec(__watcall) extern int sopen( const char *__path, int __oflag, int __share, ... );
__declspec(__watcall) extern mode_t umask( mode_t __cmask );
__declspec(__watcall) extern int lock( int __handle, unsigned long __offset, unsigned long __nbytes );
__declspec(__watcall) extern int unlock( int __handle, unsigned long __offset, unsigned long __nbytes );
__declspec(__watcall) extern int _read( int fildes, void *buf, unsigned nbyte );
__declspec(__watcall) extern int _write( int fildes, const void *buf, unsigned nbyte );
__declspec(__watcall) extern int _access( const char *__path, int __mode );
__declspec(__watcall) extern int _dup( int __handle );
__declspec(__watcall) extern int _dup2( int __handle1, int __handle2 );
__declspec(__watcall) extern int _close( int __handle );
__declspec(__watcall) extern off_t _lseek( int __handle, off_t __offset, int __origin );
__declspec(__watcall) extern long long _lseeki64( int __fildes, long long __offset, int __whence );
__declspec(__watcall) extern int _unlink( const char *__path );
__declspec(__watcall) extern int _isatty( int __handle );
__declspec(__watcall) extern int _commit( int __handle );
__declspec(__watcall) extern int _pipe( int *__phandles, unsigned __psize, int __textmode );
__declspec(__watcall) extern long _get_osfhandle( int __posixhandle );
__declspec(__watcall) extern int _hdopen( int __handle,int __mode );
__declspec(__watcall) extern int _open_osfhandle( long __osfhandle, int __flags );
__declspec(__watcall) extern int _os_handle( int __handle );
__declspec(__watcall) extern int _chmod( const char *__path, mode_t __pmode );
__declspec(__watcall) extern int _locking( int __handle, int __mode, unsigned long __nbyte );
__declspec(__watcall) extern int _eof( int __handle );
__declspec(__watcall) extern long _filelength( int __handle );
__declspec(__watcall) extern long long _filelengthi64( int __handle );
__declspec(__watcall) extern off_t _tell( int __handle );
__declspec(__watcall) extern long long _telli64( int __handle );
__declspec(__watcall) extern int _chsize( int __handle, long __size );
__declspec(__watcall) extern int _setmode( int __handle, int __mode );
__declspec(__watcall) extern int _open( const char *__path, int __oflag, ... );
__declspec(__watcall) extern int _creat( const char *__path, mode_t __mode );
__declspec(__watcall) extern int _sopen( const char *__path, int __oflag, int __share, ... );
__declspec(__watcall) extern char *_mktemp( char *__template );
__declspec(__watcall) extern mode_t _umask( mode_t __cmask );
__declspec(__watcall) extern __w_intptr_t _findfirst( const char *__filespec, struct _finddata_t *__fileinfo );
__declspec(__watcall) extern __w_intptr_t _findfirsti64( const char *__filespec, struct _finddatai64_t *__fileinfo );
__declspec(__watcall) extern int _findnext( __w_intptr_t __handle, struct _finddata_t *__fileinfo );
__declspec(__watcall) extern int _findnexti64( __w_intptr_t __handle, struct _finddatai64_t *__fileinfo );
__declspec(__watcall) extern int _findclose( __w_intptr_t __handle );
__declspec(__watcall) extern int _waccess( const wchar_t *__path, int __mode );
__declspec(__watcall) extern int _wunlink( const wchar_t *__path );
__declspec(__watcall) extern int _wchmod( const wchar_t *__path, mode_t __pmode );
__declspec(__watcall) extern wchar_t *_wmktemp( wchar_t *__template );
__declspec(__watcall) extern __w_intptr_t _wfindfirst( const wchar_t *__filespec, struct _wfinddata_t *__fileinfo );
__declspec(__watcall) extern __w_intptr_t _wfindfirsti64( const wchar_t *__filespec, struct _wfinddatai64_t *__fileinfo );
__declspec(__watcall) extern int _wfindnext( __w_intptr_t __handle, struct _wfinddata_t *__fileinfo );
__declspec(__watcall) extern int _wfindnexti64( __w_intptr_t __handle, struct _wfinddatai64_t *__fileinfo );
__declspec(__watcall) extern int _wopen( const wchar_t *__path, int __oflag, ... );
__declspec(__watcall) extern int _wcreat( const wchar_t *, mode_t __mode );
__declspec(__watcall) extern int _wsopen( const wchar_t *, int, int, ... );
#pragma pack( __pop )
__declspec(__watcall) __declspec(aborts) extern void _exit( int __status );
__declspec(__watcall) extern unsigned sleep( unsigned int __seconds );
__declspec(__watcall) extern pid_t getpid( void );
__declspec(__watcall) extern char *getcwd( char *__buf, __w_size_t __size );
__declspec(__watcall) extern int chdir( const char *__path );
__declspec(__watcall) extern int rmdir( const char *__path );
__declspec(__watcall) extern int execl( const char *__path, const char *__arg0, ... );
__declspec(__watcall) extern int execle( const char *__path, const char *__arg0, ... );
__declspec(__watcall) extern int execlp( const char *__file, const char *__arg0, ... );
__declspec(__watcall) extern int execv( const char *__path, const char *const __argv[] );
__declspec(__watcall) extern int execve( const char *__path, const char *const __argv[], const char *const __envp[] );
__declspec(__watcall) extern int execvp( const char *__file, const char *const __argv[] );
__declspec(__watcall) extern void __near *__brk( unsigned __new_brk_value );
__declspec(__watcall) extern void __near *sbrk( int __increment );
__declspec(__watcall) extern char *optarg;
__declspec(__watcall) extern int optind;
__declspec(__watcall) extern int opterr;
__declspec(__watcall) extern int optopt;
__declspec(__watcall) extern int getopt( int __argc, char * const __argv[], const char *__optstring );
__declspec(__watcall) extern pid_t _getpid( void );
__declspec(__watcall) extern char *_getcwd( char *__buf, __w_size_t __size );
__declspec(__watcall) extern int _chdir( const char *__path );
__declspec(__watcall) extern int _rmdir( const char *__path );
__declspec(__watcall) extern int _execl( const char *__path, const char *__arg0, ... );
__declspec(__watcall) extern int _execle( const char *__path, const char *__arg0, ... );
__declspec(__watcall) extern int _execlp( const char *__file, const char *__arg0, ... );
__declspec(__watcall) extern int _execv( const char *__path, const char *const __argv[] );
__declspec(__watcall) extern int _execve( const char *__path, const char *const __argv[], const char *const __envp[] );
__declspec(__watcall) extern int _execvp( const char *__file, const char *const __argv[] );
__declspec(__watcall) extern void delay(unsigned int __milliseconds);
__declspec(__watcall) extern wchar_t *_wgetcwd( wchar_t *__buf, __w_size_t __size );
__declspec(__watcall) extern int _wchdir( const wchar_t *__path );
__declspec(__watcall) extern int _wrmdir( const wchar_t *__path );
__declspec(__watcall) extern int _wexecl( const wchar_t *__path, const wchar_t *__arg0, ... );
__declspec(__watcall) extern int _wexecle( const wchar_t *__path, const wchar_t *__arg0, ... );
__declspec(__watcall) extern int _wexeclp( const wchar_t *__file, const wchar_t *__arg0, ... );
__declspec(__watcall) extern int _wexecv( const wchar_t *__path, const wchar_t *const __argv[] );
__declspec(__watcall) extern int _wexecve( const wchar_t *__path, const wchar_t *const __argv[], const wchar_t *const __envp[] );
__declspec(__watcall) extern int _wexecvp( const wchar_t *__file, const wchar_t *const __argv[] );
#pragma read_only_file
#pragma pack( __push, 1 )
struct _wdirent {
char d_dta[21];
char d_attr;
unsigned short d_time;
unsigned short d_date;
long d_size;
unsigned short d_ino;
char d_first;
wchar_t *d_openpath;
wchar_t d_name[12+1];
};
typedef struct _wdirent WDIR;
struct dirent {
char d_dta[21];
char d_attr;
unsigned short d_time;
unsigned short d_date;
long d_size;
unsigned short d_ino;
char d_first;
char *d_openpath;
char d_name[12+1];
};
typedef struct dirent DIR;
struct _diskfree_t {
unsigned total_clusters;
unsigned avail_clusters;
unsigned sectors_per_cluster;
unsigned bytes_per_sector;
};
__declspec(__watcall) extern int _chdrive( int __drive );
__declspec(__watcall) extern int _getdrive( void );
__declspec(__watcall) extern unsigned _getdiskfree( unsigned __drive, struct _diskfree_t *__diskspace );
__declspec(__watcall) extern char *getcwd( char *__buf, __w_size_t __size );
__declspec(__watcall) extern int chdir( const char *__path );
__declspec(__watcall) extern int mkdir( const char *__path );
__declspec(__watcall) extern int rmdir( const char *__path );
__declspec(__watcall) extern DIR *opendir( const char * );
__declspec(__watcall) extern struct dirent *readdir( DIR * );
__declspec(__watcall) extern void rewinddir( DIR * );
__declspec(__watcall) extern int closedir( DIR * );
__declspec(__watcall) extern char *_getdcwd( int __drive, char *__buffer, __w_size_t __maxlen );
__declspec(__watcall) extern char *_getcwd( char *__buf, __w_size_t __size );
__declspec(__watcall) extern int _chdir( const char *__path );
__declspec(__watcall) extern int _mkdir( const char *__path );
__declspec(__watcall) extern int _rmdir( const char *__path );
__declspec(__watcall) extern wchar_t *_wgetdcwd( int __drive, wchar_t *__buffer, __w_size_t __maxlen );
__declspec(__watcall) extern wchar_t *_wgetcwd( wchar_t *__buf, __w_size_t __size );
__declspec(__watcall) extern int _wchdir( const wchar_t *__path );
__declspec(__watcall) extern int _wmkdir( const wchar_t *__path );
__declspec(__watcall) extern int _wrmdir( const wchar_t *__path );
__declspec(__watcall) extern WDIR *_wopendir( const wchar_t * );
__declspec(__watcall) extern struct _wdirent *_wreaddir( WDIR * );
__declspec(__watcall) extern void _wrewinddir( WDIR * );
__declspec(__watcall) extern int _wclosedir( WDIR * );
#pragma pack( __pop )
typedef char string[2048];
typedef int *stack;
typedef char FNAME[144];
#pragma read_only_file
#pragma pack( __push, 1 )
struct WORDREGS {
unsigned short ax;
unsigned short bx;
unsigned short cx;
unsigned short dx;
unsigned short si;
unsigned short di;
unsigned int cflag;
};
struct BYTEREGS {
unsigned char al, ah;
unsigned char bl, bh;
unsigned char cl, ch;
unsigned char dl, dh;
};
union REGS {
struct WORDREGS x;
struct WORDREGS w;
struct BYTEREGS h;
};
struct SREGS {
unsigned short es, cs, ss, ds;
};
struct REGPACKB {
unsigned char al, ah;
unsigned char bl, bh;
unsigned char cl, ch;
unsigned char dl, dh;
};
struct REGPACKW {
unsigned short ax;
unsigned short bx;
unsigned short cx;
unsigned short dx;
unsigned short bp;
unsigned short si;
unsigned short di;
unsigned short ds;
unsigned short es;
unsigned int flags;
};
struct REGPACKX {
unsigned int eax, ebx, ecx, edx, ebp, esi, edi;
unsigned short ds, es, fs, gs;
unsigned int flags;
};
union REGPACK {
struct REGPACKB h;
struct REGPACKW w;
struct REGPACKW x;
};
struct INTPACKX {
unsigned gs,fs,es,ds,edi,esi,ebp,esp,ebx,edx,ecx,eax,eip,cs,flags;
};
struct INTPACKW {
unsigned short gs;
unsigned short fs;
unsigned short es;
unsigned short ds;
unsigned short di;
unsigned short si;
unsigned short bp;
unsigned short sp;
unsigned short bx;
unsigned short dx;
unsigned short cx;
unsigned short ax;
unsigned short ip;
unsigned short cs;
unsigned flags;
};
struct INTPACKB {
unsigned :16, :16,
:16, :16,
:16, :16,
:16, :16;
unsigned char bl, bh;
unsigned char dl, dh;
unsigned char cl, ch;
unsigned char al, ah;
};
union INTPACK {
struct INTPACKB h;
struct INTPACKW w;
struct INTPACKW x;
};
enum {
INTR_CF = 0x0001,
INTR_PF = 0x0004,
INTR_AF = 0x0010,
INTR_ZF = 0x0040,
INTR_SF = 0x0080,
INTR_TF = 0x0100,
INTR_IF = 0x0200,
INTR_DF = 0x0400,
INTR_OF = 0x0800
};
__declspec(__watcall) extern void _disable( void );
__declspec(__watcall) extern void _enable( void );
__declspec(__watcall) extern int int86( int, union REGS *, union REGS * );
__declspec(__watcall) extern int int86x( int, union REGS *, union REGS *, struct SREGS * );
__declspec(__watcall) extern void intr( int, union REGPACK * );
__declspec(__watcall) extern void intrf( int, union REGPACK * );
__declspec(__watcall) extern void nosound( void );
__declspec(__watcall) extern void segread( struct SREGS * );
__declspec(__watcall) extern void sound( unsigned __frequency );
#pragma pack( __pop )
static
void
wfill(void *s, const short v, int len)
{
unsigned short *p = s;
while (len--)
{
*p++ = v;
}
}
typedef struct _pp
{
unsigned char *base;
unsigned int rec;
unsigned short linked,
end_pos;
} PAGE_PTR;
typedef struct _unit
{
PAGE_PTR *list;
unsigned char *rec_start;
struct _unit *link_u;
unsigned int rec_num,
eof_rec,
page,
eof_page,
list_end;
char read;
} UNIT;
typedef char LINE[( 1022 + 2 )];
typedef struct _ml
{
const struct _ml *next;
const char *text;
char name[64 + 1];
char par_sub;
unsigned char nargs;
} MACRO;
typedef struct
{
char *in_rec, *out_rec;
int in_rec_len, out_rec_len, in_rec_num, g_rec, g_eof, i_eor, i_col, e_col, o_rec;
} SAVE_AREA;
typedef struct _fl
{
struct _fl *next, *prev;
UNIT *old_u;
SAVE_AREA save;
FNAME name;
char disp;
unsigned char trans;
} FILE_LIST;
typedef struct _tk
{
union
{
double r;
long i;
} opval,
litval;
struct _tk *next,
*snext;
const char *errp;
unsigned int id;
char fp;
char l_fp;
char group;
}
TOKEN;
typedef struct _option
{
unsigned int q;
int v;
TOKEN *e;
string s;
} OPTION;
typedef struct _verb
{
struct _verb *next, *cpar;
const char *errp;
OPTION o1;
OPTION o2;
char comm;
char dot;
} VERB;
typedef struct _verb_list
{
struct _verb_list *next, *prev;
VERB *prog;
int save_depth;
} VERB_LIST;
#pragma read_only_file
#pragma pack( __push, 1 )
struct _ibm_diskinfo_t {
unsigned drive;
unsigned head;
unsigned track;
unsigned sector;
unsigned nsectors;
void __far *buffer;
};
__declspec(__watcall) extern unsigned short _bios_disk(unsigned __cmd, struct _ibm_diskinfo_t *__diskinfo);
__declspec(__watcall) extern unsigned short _bios_equiplist(void);
__declspec(__watcall) extern unsigned short _bios_keybrd(unsigned __cmd);
__declspec(__watcall) extern unsigned short _bios_memsize(void);
__declspec(__watcall) extern unsigned short _bios_printer(unsigned __cmd,unsigned __port, unsigned __data);
__declspec(__watcall) extern unsigned short _bios_serialcom(unsigned __cmd,unsigned __port, unsigned __data);
__declspec(__watcall) extern unsigned short _bios_timeofday(unsigned __cmd,long *__timeval);
#pragma pack( __pop )
typedef unsigned short chtype;
static
unsigned int LINES, COLS;
static
void clrtoeol(void);
static
void deleteln(void);
static
unsigned short curs_getc(void);
static
void insertln(void);
static
void initscr(void);
static
void curs_chins(void);
static
void napms(const unsigned long);
typedef enum
{
A_C_UP,
A_FILE_MOVE,
A_C_DOWN,
A_C_LEFT,
A_EXP_MODE,
A_DEL_C,
A_C_HOME,
A_B_TAB,
A_PAGE_SHIFT,
A_C_STAY,
A_DEL_REST,
A_C_EOL,
A_C_TOS,
A_C_SOL,
A_C_BOS,
A_JUSTIFY,
A_RWX_FILE,
A_EXIT_EDITOR,
A_W_LEFT,
A_C_RIGHT,
A_W_RIGHT,
A_H_TAB,
A_SEARCH,
A_CHARACTER,
A_C_RETURN,
A_OPEN_LINE,
A_DEL_LINE,
A_REST_LINE,
A_HELP,
A_HIST,
A_REPEAT,
A_MISC_CE,
A_YANK,
A_COMMAND,
A_FINDC,
A_BLOCK,
A_REDRAW
} ACTION;
typedef enum
{
Q_EDIT,
Q_RAW,
Q_YORN,
Q_BLOCK
} Q_MODE;
static
int George(const VERB *);
static
void G_compile(VERB **, const char *);
static
int Disk_to_mem(char const *const, UNIT *const, const int);
static
void c_comm_u(void);
static
void Xit(VERB const *const);
static
void term(void);
static
void message(char const *const);
static
void inform(char const *const);
static
void se_execute(const ACTION, const int);
static
void alter_end(int, const int);
static
void Quit(void);
static
void Exit(void);
static
void Drive(const int);
#pragma aux main aborts;
#pragma aux Quit aborts;
#pragma aux Exit aborts;
#pragma aux g_err aborts;
#pragma aux g_intr aborts;
#pragma aux se_error aborts;
#pragma aux _exit aborts;
static const char shell_bin[] = "COMMAND", tty_file[] = "CON",
se_pcom[] = "snLPT1,te,x", shell_var[] = "COMSPEC",
se_lcom[] = ".tss:DIR /W:"
;
static const char si_file[] = "stdin", so_file[] = "stdout", t_fname[] = "*TMP*",
no_file[] = "*NEW*";
static const char se_find[] = "Find:", let_s[] = "s",
se_ep[] = "End point:", se_fin1[] = "(unchanged) ",
se_fcom1[] = "TR\177%s\177", se_hit[] = "\r\n[Enter to Continue] ",
let_col[] = ":", empty[] = "", endsent[] = ".!?;",
ft_out[] = "Output", bra_start[] = "({[<",
bra_end[] = ")}]>", hextrans[] = "0123456789ABCDEF",
ft_merge[] = "Merge", esc_symb[] = "VANTBFR0",
c_rom[] = "IXCMZVLDWixcmzvldw", line_pos[] = "Line %d.%d",
ft_in[] = "Input", pt_list[] = "\nListing from %s file %s",
ps_name[] = "%s file: %s", m_real[] = "%.14g",
eof_mess[] = "************ EOF ************";
static const char f_wc[] = "Lines Words Punct. Cntrl. Sent. L.O.C Chars.\n%-8ld%-8ld%-8ld%-8ld%-8ld%-8ld%-ld";
static const unsigned char opprio[] = {
13, 13, 13, 12, 12, 10, 10, 8, 7, 6, 2, 2, 1, 0
},
esc_char[] = "\013\007\n\t\b\f\r";
static const char g_mess[] =
"Syntax error in expression\0This command does not accept a dot part\0Y verb expects two equal length strings\0Cannot go back before beginning of file\0Use/Merge file empty\0Prior position not valid\0Divide by zero\0Illegal endpoint\0The X verb is followed by S(save) or M(merge) or T(transient)\0Verb does not support this option\0Number or { expr } expected\0Option string too long\0No more in your file\0End of line encountered\0String not found\0Start of line encountered\0Bad number\0Nothing to split\0Operation undefined for floating point operands\0Verify failure\0Merge file open\0Interactive/multi-record options not allowed\0Verb not recognised\0No macro name supplied\0\"\\digit\" out of range in RE\0Bad macro definition - subs_ch and no_of_args missing/invalid\0Bad macro definition - no_of_arguments is a single digit\0Bad macro definition - no body supplied\0Macro name not in table\0Bad macro body - argument number invalid\0Cannot edit Save/Merge files in screen mode\0Command execution failure\0Command too long\0Save file open\0No Save/Merg/Use file open\0Illegal or missing delimiter\0Environment variable not found\0Unpaired delimiter in single line multirecord insert/display\0BREAK key pressed - command discarded\0Can\'t access file\0No saved RE\0Parenthesis imbalance\0Too many \\( in RE\0More than two numbers given in \\{ \\}\0} expected after \\ in RE\0First number exceeds second in \\{ \\}\0End of edit file encountered during a multiline Insert verb\0Record(s) too long - truncated by G\0[ ] imbalance in RE\0RE overflow\0Cannot re-read from a pipe\0No transient file saved\0Transient file in use\0RE substitute too long\0Illegal RE substitute\0Last file operation was Save - use XS first and then XM\0Last file operation was Merge - use XM first and then XS\0Hex digits missing or invalid";
static const char asc_tab[][4]
= {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT",
"LF", "VT", "FF", "CR", "SO", "SI", "DLE", "DC1", "DC2", "DC3",
"DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS",
"RS", "US", "DEL"
};
static char const *const hw_mess[] = {
"Screen Editor Key Strokes.\n\n\tSINGLE KEY COMMANDS\n^A\tWord move left\t\t\t^N\tOpen blank line\n^B\tWord delete left\t\t^Pc\tEnter control character \'c\'\n^C\tPage down\t\t\t^R\tPage up\n^D\tCursor right\t\t\t^S\tCursor left\n^E\tCursor up\t\t\t^T\tWord delete right\n^F\tWord move right\t\t\t^U\tRestore deleted/saved lines\n^G\tDelete character\t\t^V/Ins\tOverwrite/insert mode\n^H\tDelete character left\t\t^W\tScroll up one line\n^I\tHorizontal tab\t\t\t^X\tCursor down\n^J\tSave current line\t\t^Y\tDelete current line\n^L\tRepeat search/replace\t\t^Z\tScroll down one line\n^M\tSplit line",
"\tQUICK COMMANDS\n^Q DEL\tErase to start of line\t\t^QA\tSearch and replace\n^QB\tJustify and move on\t\t^QC\tMove to end of file\n^QD/End\tCursor to end of line\t\t^QE\tCursor to top of screen\n^QF\tSearch for string\t\t^QGc\tFind character\n^QH/Home Cursor Home\t\t\t^QI\tMove to line number\n^QJ/F1\tDisplay help text\t\t^QK/F9\tRecall home commands\n^QQ\tRepeat command\t\t\t^QR\tMove to top of file\n^QS\tCursor to start of line\t\t^QV\tMatch brackets/strings\n^QW\tFast repeat scroll up\t\t^QX\tCursor to bottom of screen\n^QY\tErase to end of line\t\t^QZ\tFast repeat scroll down",
"\tBLOCK AND SAVE COMMANDS\n^KA\tAppend to file\t\t\t^KB/F2\tMark start of block\n^KC/F4\tCopy from marked block\t\t^KD\tContext editor\n^KE\tSpawn shell\t\t\t^KF\tList files\n^KH\tHome and move line to top\t^KK/F3\tMark end of block\n^KL\tChange directory\t\t^KO\tRe-read oldfile\n^KP\tPrint file\t\t\t^KQ/F7/ESC Abandon edit\n^KR/F4\tRead from file\t\t\t^KS/F10\tSave file\n^KU\tUse (execute) edit file\t\t^KW/F3\tWrite to file\n^KX/F8\tSave file and exit\t\t^K?\tDisplay file statistics\n\n\tJUSTIFICATION\n^OB\tJustify paragraph\t\t^OC\tCentre current line\n^OL\tSet left margin\t\t\t^OR\tSet right margin\n^OS\tSet line spacing\t\t^OJ\tToggle right adjust\n^OW\tToggle wordwrap",
((void *)0)
};
static const char u_map[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40,
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D,
0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54,
0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40,
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D,
0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A,
0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54,
0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F
};
static const unsigned char g_map[] = {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0x01, 0x00, 0x01, 0x01, 0x01,
0x01, 0x02, 0x02, 0x00, 0x01, 0x02, 0x00, 0x00, 0x01, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x01, 0x02, 0x01, 0x01, 0x01, 0x21, 0x00,
0x90, 0x50, 0x50, 0x10, 0x30, 0x30, 0x10, 0x10, 0x10, 0x50, 0x10, 0x70, 0x10,
0x10, 0x90, 0x30, 0x10, 0xD0, 0x50, 0x10, 0x90, 0x10, 0xD0, 0x10, 0x10, 0x10,
0x01, 0x00, 0x01, 0x00, 0x04, 0x01, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x80, 0x00, 0x00, 0x01, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02,
0x02, 0x00, 0x01, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
};
static const char cha[] = "(tc\177%1\177 (r\177%1\177%2\177).e t)e @";
static const char rcha[] = "(tr\177%1\177 ((rr\177\177%2\177).e t tr//)e) @";
static const char tpri[]
=
"{t=$/%1}((v%3 ix/0C0A/;) i/ / if(i/ /).o{%2/2-8}id(i/ /).o{%2-12}i/Page / n1 i{++p}i/ of / i{t*%1==$?t:t+1}(i////)*2 n10(i{#}i/ / t)%1)e(v%3 ix/0C/)";
static const char clr[] = "((ic{*&127}p.1).e t)e @((v{*<32|*>126}p.1;t.1).e t)e @";
static const char lis[] = "(tci\177%1\177 l0 t)e @";
static const char grep[] = "(tr\177%1\177(l0 t tr//)e) @";
static const char up[] = "rr/.*/\\u&/";
static const char lo[] = "rr/.*/\\l&/";
static const char hex[] = "n02X(i{*}p.1).e";
static const char num[] = "{%1=0,..=1}t.s(v{* ==43}t.1;v{* ==45}{..=-1}t.1;) t.s({%1=%1*10+(*-48)}t.1)w{*>47&&*<58}{%1*=..}";
static const char ph[] = "{..=#}# p{..}";
static const char cmain[] = "i///#include <stdio.h>//#include <stdlib.h>////int//main( int argc, char ** argv )// {//// }/////@";
static const char tss[] = "!%1";
static
const MACRO mac_tab[] = { { mac_tab + 1, cha, "c", '%', 2 },
{ mac_tab + 2, rcha, "r", '%', 2 },
{ mac_tab + 3, tpri, "tpri", '%', 3 },
{ mac_tab + 4, clr, "clea", '%', 0 },
{ mac_tab + 5, lis, "lis", '%', 1 },
{ mac_tab + 6, grep, "grep", '%', 1 },
{ mac_tab + 7, up, "u", '%', 0 },
{ mac_tab + 8, lo, "l", '%', 0 },
{ mac_tab + 9, hex, "hex", '%', 0 },
{ mac_tab + 10, num, "num", '%', 1 },
{ mac_tab + 11, ph, "ph", '%', 0 },
{ mac_tab + 12, cmain, "main", '%', 0 },
{ ((void *)0), tss, "tss", '%', 1 } };
static
int l_numbers = 0,
lon = 0;
static
char n_format[8] = "%ld";
static
const char * g_init = ((void *)0);
static
int g_rec = -1,
g_eof = 0,
i_eor = 0,
i_col = 0,
e_col = 0,
o_rec = -1,
s_g_rec = 0,
s_g_col = 0,
buff_sec = 0,
running = 1;
static
unsigned int depth = 0;
static
SAVE_AREA g_save;
static
char * i_buff, * e_buff;
static
const char * cmd_buf;
static
const char * in_fname = si_file, * out_fname = so_file;
static
int fd_in_terminal = 0, fd_out_terminal = 1;
static
int ro_mode = 0;
static
char i_mode = 'N', o_mode = 'N';
static
VERB * g_free_list = ((void *)0);
static
VERB_LIST com_stack = {
((void *)0), ((void *)0), ((void *)0), 0
};
static
VERB_LIST * com_stack_ptr = &com_stack, * par_stack_ptr = &com_stack;
static
stack * hist_top = ((void *)0);
static
FILE_LIST * c_list = ((void *)0),
* f_list = ((void *)0);
static
const MACRO * mac_list = mac_tab;
static
int infile_recs;
static
jmp_buf set_err, save_err, se_ret, se_err;
static
int l_margin = 0, r_margin = 68, line_spacing = 0;
static
int adjust = 1 ;
static
int left_right, t_margin, wordwrap = 0;
static
int se_save_eof;
static
int trunc_recs = 0;
static
stack * in_stack = ((void *)0);
static
int in_count = 0;
static
stack * del_stack = ((void *)0);
static
stack * hist_ptr = ((void *)0);
static
int last_line, last_col, text_lines, h_inc;
static
int row, col, offset, text_row, text_col,
text_offset, last_offset;
static
int qq_loop = 0;
static
int expand = 1;
static
unsigned int fscreen = 0;
static
unsigned int redisplay = 0;
static
int screen_tabs = 4;
static
char ** s_buf = ((void *)0);
static
short * eor, * s_eor;
static
FILE_LIST * f_free_list = ((void *)0);
static
int trans_open_count = 0;
static
PAGE_PTR * page_list = ((void *)0), * page_list_end = ((void *)0);
static
unsigned char * v_free_list = ((void *)0);
static
UNIT primary_out;
static
UNIT primary_in = {
((void *)0), ((void *)0), &primary_out, 0, 0, 0, 0, 200 - 1, 0
};
static
UNIT primary_out = {
((void *)0), ((void *)0), &primary_in, 0, 0, 0, 0, 200 - 1, 0
};
static
UNIT * in_u = &primary_in, * out_u = &primary_out, * comm_u = ((void *)0),
* trans_u = ((void *)0);
static
int prim_changed = 0;
static
int bin_mode = 0;
static
void
new_line(void)
{
(void)!write(2, pt_list, 1);
}
static
void
putstr(char const *const s)
{
(void)!write( 2, s, strlen(s) );
}
static
void
say(char const *const s)
{
putstr(s);
new_line();
}
static
void
wait_user(void)
{
putstr(se_hit);
(void)_bios_keybrd(0);
}
static
void *
getvec(const size_t len)
{
void *const p = malloc(len + 1);
if (p == ((void *)0))
{
term();
say("\rOut of core\r");
_exit(1);
}
return p;
}
static
void
rlsevec(void *const ptr)
{
free(ptr);
}
static
int
tabex(unsigned char *b2, const unsigned char *b1, int len)
{
const unsigned char *p, *const start = b2;
int i, gap, col, new_col;
const int maxlen = 1022;
while ( len && ( b1[len - 1] == 0x20 || b1[len - 1] == 0x09 ) )
{
--len;
}
while (len && *b1 == 0x09)
{
*b2++ = *b1++, --len;
}
while ( len >= 8 && ( *b1 == 0x20 || *b1 == 0x09 ) )
{
for (i = 0; i < 8 && b1[i] == 0x20; ++i)
{
;
}
if (i < 8)
{
if (b1[i] != 0x09)
{
break;
}
++i;
}
b1 += i;
len -= i;
*b2++ = 0x09;
}
if (len == 0)
{
return 0;
}
col = ( b2 - start ) * 8;
while ( ( p = (unsigned char *)memchr(b1, 0x09, len) ) != ((void *)0))
{
col += ( gap = p - b1 );
if (col > maxlen)
{
(void)memcpy( (void *)( b2 ), (const void *)( b1 ), ( maxlen - ( col - gap ) ) );
col = maxlen;
len = 0;
break;
}
b2 = (unsigned char *)( memcpy( (void *)( b2 ), (const void *)( b1 ), gap), (void *)( (char *)( b2 ) + gap ) );
b1 = p + 1;
len -= gap;
new_col = ( col / 8 + 1 ) * 8;
if (new_col > maxlen)
{
(void)memset( (char *)( b2 ), 0x20, maxlen - col );
col = maxlen;
len = 0;
break;
}
gap = new_col - col;
b2 = ( (void)memset( (char *)b2, 0x20, gap), b2 + gap );
--len;
col = new_col;
}
if (len + col > maxlen)
{
len = maxlen - col;
++trunc_recs;
}
(void)memcpy( (void *)( b2 ), (const void *)( b1 ), ( len ) );
return len + ( b2 - start );
}
static
int
ltabex(char *b2, const unsigned char *b1, int len)
{
char const *const start = b2;
if (!bin_mode)
{
while (len && *b1 == 0x09)
{
++b1;
b2 = ( (void)memset( (char *)( b2 ), 0x20, 8 ), b2 + 8 );
--len;
}
}
(void)memcpy( (void *)( b2 ), (const void *)( b1 ), ( len ) );
return len + ( b2 - start );
}
static
void
free_page(PAGE_PTR *const cp)
{
*(unsigned char **)cp->base = v_free_list;
v_free_list = cp->base;
}
static
void
clear_pages(UNIT const *const fp)
{
PAGE_PTR *pp;
for (pp = fp->list; pp->base != ((void *)0); ++pp)
{
if (!pp->linked)
{
free_page(pp);
}
}
}
static
unsigned char *
new_page(void)
{
unsigned char *ad = v_free_list;
if (ad != ((void *)0))
{
v_free_list = *(unsigned char **)ad;
return ad;
}
if (page_list >= page_list_end)
{
if ( ( page_list = (PAGE_PTR *)malloc(( 200 * 8 ) * sizeof ( PAGE_PTR )) ) == ((void *)0))
{
static int warned = 0;
if (!warned++)
{
inform("WARNING: Low on memory!");
}
page_list = page_list_end;
return (unsigned char *)getvec(( sizeof ( PAGE_PTR ) * 200 ));
}
page_list_end = page_list + ( 200 * 8 );
}
ad = (unsigned char *)page_list;
page_list += 200;
return ad;
}
static
unsigned char *
get_page(void)
{
PAGE_PTR *pp;
if (v_free_list != ((void *)0))
{
unsigned char *const ad = v_free_list;
v_free_list = *(unsigned char **)ad;
return ad;
}
for (pp = in_u->list + in_u->eof_page; pp->base != ((void *)0); ++pp)
{
if (!pp->linked)
{
free_page(pp);
pp->base = ((void *)0);
}
}
return new_page();
}
static
PAGE_PTR *
get_pt(const int len)
{
PAGE_PTR *const ad = page_list;
if (len > page_list_end - ad)
{
return (PAGE_PTR *)getvec(len * sizeof ( PAGE_PTR ));
}
page_list += len;
return ad;
}
static
void
free_pt(UNIT *const fp)
{
PAGE_PTR *pp = fp->list, *const last = pp + fp->list_end;
for (; pp < last; pp += 200)
{
*(unsigned char **)pp = v_free_list;
v_free_list = (unsigned char *)pp;
}
}
static
void
extend_list(UNIT *const fp)
{
const int old_end = fp->list_end + 1;
PAGE_PTR *const new_pt = get_pt(old_end + 200);
(void)memcpy( (void *)( new_pt ), (const void *)( fp->list ), ( old_end * sizeof ( PAGE_PTR ) >> 1 ) << 1 );
(void)memset( (char *)( new_pt + old_end ), 0x00, ( sizeof ( PAGE_PTR ) * ( 200 >> 1 ) ) << 1 );
free_pt(fp);
fp->list = new_pt;
fp->list_end += 200;
}
static
unsigned char *
find_rec(UNIT const *const fp, const int dest)
{
unsigned char *p;
unsigned int len, rec;
PAGE_PTR const *const cp = fp->list + fp->page;
if (dest == cp->rec)
{
return cp->base + cp->end_pos;
}
if (fp->page > 0)
{
rec = cp[-1].rec;
}
else
{
rec = 0;
}
p = cp->base;
while (rec++ < dest)
{
{ if ( ( len = *p++ ) > 254 ) { len = *(short *)p; p += 2; }; p += len; };
}
return p;
}
static
void
unlink_page(UNIT *const fp, PAGE_PTR *const cp, const unsigned int offset)
{
unsigned char const *const link_base = cp->base;
fp->rec_start = ( cp->base = get_page() ) + offset;
cp->linked = fp->link_u->list[cp->linked - 1].linked = 0;
(void)memcpy( (void *)( cp->base ), (const void *)( link_base ), ( offset ) );
}
static
void
set_link(PAGE_PTR *const cp1, PAGE_PTR *const cp2)
{
if (cp1->linked)
{
unlink_page(in_u, cp1, cp1->end_pos);
}
if (cp2->linked)
{
cp2->linked = in_u->list[cp2->linked - 1].linked = 0;
cp2->base = ((void *)0);
}
if (cp2->base != ((void *)0))
{
free_page(cp2);
}
*cp2 = *cp1;
cp1->linked = cp2 - out_u->list + 1;
cp2->linked = cp1 - in_u->list + 1;
}
static
void
page_end(UNIT *const fp)
{
PAGE_PTR *const cp = fp->list + fp->page;
const unsigned short offset = fp->rec_start - cp->base;
if (offset != cp->end_pos && cp->linked && offset != 0)
{
unlink_page(fp, cp, offset);
}
cp->rec = fp->rec_num;
cp->end_pos = offset;
}
static
UNIT *
vsopen(void)
{
UNIT *const fp = ( UNIT *)getvec(sizeof ( UNIT ) );
fp->list = (PAGE_PTR *)get_page();
(void)memset( (char *)( fp->list ), 0x00, ( sizeof ( PAGE_PTR ) * ( 200 >> 1 ) ) << 1 );
fp->rec_start = fp->list->base = get_page();
fp->rec_num = fp->page = fp->read = 0;
fp->link_u = ((void *)0);
fp->list_end = 200 - 1;
return fp;
}
static
void
vsclose(UNIT *const fp)
{
clear_pages(fp);
free_pt(fp);
rlsevec(fp);
}
static
void
vsreopen(UNIT *const fp)
{
if ( ( fp->read = !fp->read ) == 1 )
{
page_end(fp);
fp->eof_rec = fp->rec_num;
fp->eof_page = fp->page + 1;
}
( fp->rec_num = fp->page = 0, fp->rec_start = fp->list->base );
}
static
void
vsputrec(UNIT *const fp, const char *record, unsigned int len)
{
int pg, i;
PAGE_PTR *cp;
unsigned short offset;
unsigned char buf[( 1022 + 2 ) + 3], *const start = buf + 3, *p = start;
if (bin_mode)
{
(void)memcpy( (void *)( p ), (const void *)( record ), ( len ) );
}
else
{
while (len >= 8 && *record == 0x20)
{
for (i = 0; i < 8 && record[i] == 0x20; ++i)
{
;
}
if (i < 8)
{
break;
}
record += i;
len -= i;
*p++ = 0x09;
}
(void)memcpy( (void *)( p ), (const void *)( record ), ( len ) );
len += p - start;
}
p = buf + 2;
p[0] = (unsigned char)len; if (len > 254) { p -= 2; p[0] = (unsigned char)255; *(short *)( p + 1 ) = len; len += 2; };
pg = fp->page;
cp = fp->list + pg;
offset = fp->rec_start - cp->base;
if (++len > ( sizeof ( PAGE_PTR ) * 200 ) - offset)
{
page_end(fp);
if ( ( fp->page = ++pg ) >= fp->list_end )
{
extend_list(fp);
}
cp = fp->list + pg;
if (cp->base == ((void *)0))
{
cp->base = get_page();
}
fp->rec_start = cp->base;
offset = 0;
}
++fp->rec_num;
if (cp->linked)
{
if ( offset + len <= cp->end_pos && ( memcmp(fp->rec_start, p, len) == 0 ) )
{
fp->rec_start += len;
return;
}
unlink_page(fp, cp, offset);
++prim_changed;
}
else
{
UNIT *const lu = fp->link_u;
if (offset == 0 && lu == in_u && pg < lu->list_end)
{
PAGE_PTR *lp = lu->list + pg;
if (lp->base != ((void *)0) && ( memcmp(lp->base, p, len) == 0 ) && !lp->linked)
{
if (cp->base != ((void *)0))
{
free_page(cp);
}
lp->linked = pg + 1;
*cp = *lp;
fp->rec_start = cp->base + len;
return;
}
}
}
fp->rec_start = ( memcpy( (void *)( fp->rec_start ), (const void *)( p ), len), (void *)( (char *)( fp->rec_start ) + len ) );
}
static
void
vsload(UNIT *const fp, char const *const record, unsigned int len)
{
unsigned char buf[( 1022 + 2 ) + 3], *p = buf + 2;
PAGE_PTR *cp = fp->list + fp->page;
const unsigned short offset = fp->rec_start - cp->base;
if (record[len - 1] == '\r')
{
--len;
}
if (len > 1022)
{
len = 1022;
++trunc_recs;
}
if (bin_mode)
{
(void)memcpy( (void *)( buf + 3 ), (const void *)( record ), ( len ) );
}
else
{
len = tabex(buf + 3, (const unsigned char *)record, len);
}
p[0] = (unsigned char)len; if (len > 254) { p -= 2; p[0] = (unsigned char)255; *(short *)( p + 1 ) = len; len += 2; };
if (++len > ( sizeof ( PAGE_PTR ) * 200 ) - offset)
{
cp->rec = fp->rec_num;
cp->end_pos = offset;
if (++fp->page >= fp->list_end)
{
extend_list(fp);
}
cp = fp->list + fp->page;
if (cp->base == ((void *)0))
{
cp->base = (unsigned char *)new_page();
}
fp->rec_start = cp->base;
}
fp->rec_start = ( memcpy( (void *)( fp->rec_start ), (const void *)( p ), len), (void *)( (char *)( fp->rec_start ) + len ) );
++fp->rec_num;
}
static
int
vsgetrec(UNIT *const fp, unsigned char const **const rec)
{
unsigned int len;
unsigned char *cp = fp->rec_start;
if (fp->rec_num >= fp->eof_rec)
{
return (-1);
}
if (++fp->rec_num > fp->list[fp->page].rec)
{
cp = fp->list[++fp->page].base;
}
if ( ( len = *cp++ ) > 254 ) { len = *(short *)cp; cp += 2; };
*rec = cp;
fp->rec_start = cp + len;
return len;
}
static
int
block_copy(UNIT *const fp2, UNIT *const fp1, const unsigned int dst, const int one)
{
unsigned char *ep1, *irs1, *rs2 = fp2->rec_start;
PAGE_PTR *cp1 = fp1->list + fp1->page, *cp2 = fp2->list + fp2->page;
register unsigned char *rs1 = fp1->rec_start;
unsigned int rec1 = fp1->rec_num, rec2 = fp2->rec_num, offset2 = rs2 - cp2->base,
irec1, rem2, len;
UNIT *const lu = fp2->link_u;
if (cp2->linked)
{
unlink_page(fp2, cp2, offset2);
rs2 = fp2->rec_start;
}
rem2 = ( sizeof ( PAGE_PTR ) * 200 ) - offset2;
ep1 = cp1->base + cp1->end_pos;
while (cp1->rec < dst || ( ep1 = find_rec(fp1, dst) ) - rs1 > rem2)
{
irec1 = rec1;
irs1 = rs1;
if (ep1 - rs1 > rem2)
{
unsigned char const *const last = rs1 + rem2;
while (rs1 <= last)
{
{ if ( ( len = *rs1++ ) > 254 ) { len = *(short *)rs1; rs1 += 2; }; rs1 += len; };
++rec1;
}
rs1 -= len + 1;
if (len > 254)
{
rs1 -= 2;
}
--rec1;
}
else
{
rs1 = ep1;
rec1 = cp1->rec;
}
len = rs1 - irs1;
(void)memcpy( (void *)( rs2 ), (const void *)( irs1 ), ( len ) );
cp2->rec = rec2 += ( rec1 - irec1 );
cp2->end_pos = (unsigned short)( offset2 + len );
if (++fp2->page >= fp2->list_end)
{
extend_list(fp2);
}
cp2 = fp2->list + fp2->page;
if (rec1 >= cp1->rec)
{
++fp1->page;
if (one)
{
return 0;
}
rs1 = ( ++cp1 )->base;
}
if (cp2->linked)
{
cp2->linked = lu->list[cp2->linked - 1].linked = 0;
cp2->base = get_page();
}
else if(cp2->base == ((void *)0))
cp2->base = get_page();
offset2 = 0;
rs2 = cp2->base;
rem2 = ( sizeof ( PAGE_PTR ) * 200 );
ep1 = cp1->base + cp1->end_pos;
}
fp2->rec_start = ( memcpy( (void *)( rs2 ), (const void *)( rs1 ), (int)( ep1 - rs1 )), (void *)( (char *)( rs2 ) + (int)( ep1 - rs1 ) ) );
fp1->rec_start = ep1;
fp1->rec_num = dst;
fp2->rec_num = rec2 + ( dst - rec1 );
return 1;
}
static
void
vscopy(UNIT *const fp2, UNIT *const fp1, const unsigned int end_rec)
{
PAGE_PTR *cp1 = fp1->list + fp1->page, *cp2 = fp2->list + fp2->page;
const int rec_offset = fp2->rec_num - fp1->rec_num,
offset1 = fp1->rec_start - cp1->base,
slow = ( end_rec <= cp1->rec && !cp2->linked ) || fp1->link_u != fp2;
int pages;
if (offset1 != fp2->rec_start - cp2->base || slow)
{
if ( block_copy(fp2, fp1, end_rec, !slow) )
{
return;
}
cp2 = fp2->list + fp2->page;
if ( ( ++cp1 )->base != cp2->base )
{
set_link(cp1, cp2);
}
}
if (cp1->rec < end_rec)
{
if (cp1->base != cp2->base)
{
if (cp2->linked)
{
unlink_page(fp2, cp2, offset1);
}
(void)
memcpy( (void *)( fp2->rec_start ), (const void *)( fp1->rec_start ), ( cp1->end_pos - offset1 ) );
cp2->end_pos = cp1->end_pos;
}
if (end_rec == fp1->eof_rec)
{
pages = fp1->eof_page - fp1->page - 1;
}
else
{
PAGE_PTR *p = cp1;
while (p->rec < end_rec)
{
++p;
}
pages = p - cp1;
}
while (fp2->list_end <= fp2->page + pages)
{
extend_list(fp2);
cp2 = fp2->list + fp2->page;
}
while (pages--)
{
cp2->rec = cp1->rec + rec_offset;
++cp1, ++cp2;
if (cp1->base != cp2->base)
{
set_link(cp1, cp2);
}
}
fp1->page = cp1 - fp1->list;
fp2->page = cp2 - fp2->list;
}
else if(cp1->base != cp2->base)
set_link(cp1, cp2);
fp2->rec_start = fp1->rec_start = find_rec(fp1, end_rec);
fp2->rec_num = ( fp1->rec_num = end_rec ) + rec_offset;
}
static
void
vsseek(UNIT *const fp, const unsigned int offset)
{
const PAGE_PTR *p;
for (p = fp->list; p->rec < offset; ++p)
{
;
}
fp->page = p - fp->list;
fp->rec_num = offset;
fp->rec_start = find_rec(fp, offset);
}
static
void
save_all(SAVE_AREA *const save)
{
PAGE_PTR *const cp = out_u->list + out_u->page;
if (cp->rec < out_u->rec_num)
{
cp->rec = out_u->rec_num;
cp->end_pos = (short)( out_u->rec_start - cp->base );
}
save->in_rec_num = ( in_u->rec_num );
save->g_rec = g_rec;
save->g_eof = g_eof;
save->i_eor = i_eor;
save->i_col = i_col;
save->e_col = e_col;
save->o_rec = o_rec;
if (i_eor > 0)
{
if (save->in_rec_len < i_eor)
{
if (save->in_rec_len > 0)
{
rlsevec(save->in_rec);
}
save->in_rec = (char *)getvec(save->in_rec_len = i_eor);
}
(void)memcpy( (void *)( save->in_rec ), (const void *)( i_buff ), ( i_eor ) );
}
if (e_col > 0)
{
if (save->out_rec_len < e_col)
{
if (save->out_rec_len > 0)
{
rlsevec(save->out_rec);
}
save->out_rec = (char *)getvec(save->out_rec_len = e_col);
}
(void)memcpy( (void *)( save->out_rec ), (const void *)( e_buff ), ( e_col ) );
}
}
static
void
rest_in_vars(SAVE_AREA const *const save)
{
g_rec = save->g_rec;
g_eof = save->g_eof;
i_eor = save->i_eor;
i_col = save->i_col;
if (i_eor > 0) memcpy( (void *)( i_buff ), (const void *)( save->in_rec ), i_eor );
}
static
void
rest_out_vars(SAVE_AREA const *const save)
{
e_col = save->e_col;
o_rec = save->o_rec;
if (e_col > 0) memcpy( (void *)( e_buff ), (const void *)( save->out_rec ), e_col );
}
static
void
rest_all(SAVE_AREA const *const save)
{
rest_in_vars(save);
if (!in_u->read)
{
vsreopen(in_u);
}
vsseek(in_u, save->in_rec_num);
rest_out_vars(save);
if (out_u->read)
{
vsreopen(out_u);
}
vsseek(out_u, o_rec + 1);
}
static
int
fill_buff(void)
{
const unsigned char *p;
const int len = vsgetrec(in_u, &p);
i_col = 0;
if (len == (-1))
{
g_eof = 1;
i_eor = 0;
return 0;
}
++g_rec;
i_eor = ltabex(i_buff, p, len);
return 1;
}
static
void
init_line(void)
{
e_col = 0;
g_eof = 0;
g_rec = o_rec = -1;
(void)fill_buff();
save_all(&g_save);
}
static
void
vsprimary(void)
{
PAGE_PTR *pp;
const PAGE_PTR *last;
int pg;
(void)memset( (char *)( in_u->list ), 0x00, ( ( in_u->list_end + 1 ) * sizeof ( PAGE_PTR ) >> 1 ) << 1 );
out_u->rec_start = in_u->list->base = in_u->rec_start;
if (in_fname != no_file)
{
if ( ( infile_recs = Disk_to_mem(in_fname, in_u, i_mode) ) == (-1))
{
in_fname = no_file;
}
}
vsreopen(in_u);
for (pg = 0, pp = in_u->list, last = pp + in_u->eof_page; pp < last; ++pp)
{
pp->linked = ++pg;
}
pg = out_u->list_end = in_u->list_end;
out_u->list = get_pt(++pg);
(void)memcpy( (void *)( out_u->list ), (const void *)( in_u->list ), ( pg * sizeof ( PAGE_PTR ) >> 1 ) << 1 );
init_line();
}
static
void
vsreload(void)
{
PAGE_PTR *cp;
for (cp = in_u->list + 1; cp->base != ((void *)0); ++cp)
{
free_page(cp);
}
( in_u->rec_num = in_u->page = 0, in_u->rec_start = in_u->list->base );
in_u->read = 0;
clear_pages(out_u);
free_pt(out_u);
out_u->rec_num = out_u->page = 0;
vsprimary();
}
static
char
toprint(int c)
{
c = ( ( c ) & 0177U );
if ( ( c < 0x20 || c >= 0x7F ) )
{
c = ( c & 037U ) + 0x40;
}
return (char)c;
}
static
void
err_print(char *const err_text, const int code, const char *ptr)
{
char *p, c;
const char *mess = g_mess, *last;
int i = code;
while (i--)
{
mess = strchr(mess, 0x00) + 1;
}
if (code == 39 && (*__get_errno_ptr()) != 0)
{
(void)sprintf( err_text, "%s - %s.", mess, strerror((*__get_errno_ptr())) );
(*__get_errno_ptr()) = 0;
}
else
{
(void)sprintf(err_text, "%s.", mess);
}
if (ptr == ((void *)0) && com_stack_ptr->prog != ((void *)0))
{
ptr = com_stack_ptr->prog->errp;
}
if ( ptr != ((void *)0) && !( *( ptr ) == 0x00 ) )
{
p = ( strcat( (void *)err_text, (const void *)"\nCulprit: "), strchr(err_text, 0x00) );
last = p + 76 / 2;
while (p < last && ( c = *ptr++ ) != 0x00)
{
if (c == 0x7F)
{
c = 0x2F;
}
*p++ = toprint(c);
}
*p = 0x00;
}
}
static
void
g_err(const int code, char const *const ptr)
{
VERB opt;
char buf[256];
err_print(buf, code, ptr);
while (c_list != ((void *)0))
{
(void)sprintf(
strchr(buf, 0x00),
"\nCalled from edit file %s (line %d)",
c_list->name,
( comm_u->rec_num ) );
c_comm_u();
}
inform(buf);
if (fscreen)
{
while (f_list != ((void *)0))
{
opt.o1.q = ( f_list->disp == 'M' ) ? 'M' : 'Q';
Xit(&opt);
}
}
if (running)
{
rest_all(&g_save);
}
longjmp(set_err, 1);
}
static
unsigned char
xlat(const int c, char const *const s1, unsigned char const *const s2)
{
char const *const p = strchr(s1, c);
if (p == ((void *)0))
{
return (unsigned char)c;
}
return s2[p - s1];
}
static
unsigned char
xtoc(char const *const p)
{
const char *p1, *p2;
if ( ( p1 = (const char *)memchr(hextrans, u_map[*( p )], 16) ) == ((void *)0)
|| ( p2 = (const char *)memchr(hextrans, u_map[*( p + 1 )], 16) ) == ((void *)0))
{
g_err(57, ((void *)0));
}
return (unsigned char)( ( p1 - hextrans ) << 4 | ( p2 - hextrans ) );
}
static
const char * braslist[9], * braelist[9], * loc1,
* loc2 = ((void *)0);
static
int circf, low, range, l2rec;
static
char nbra;
static
unsigned char expbuf[512 + 32 + 2];
static
unsigned int cflags;
static
const unsigned char bittab[] = {
1, 2, 4, 8, 16, 32, 64, 128
};
static
unsigned char *
putrnge(unsigned char *ep, const unsigned int len)
{
*ep++ = (unsigned char)len;
if (len > 254)
{
ep[-1] = (unsigned char)255;
*ep++ = (unsigned char)( len >> 8 );
*ep++ = (unsigned char)len;
}
return ep;
}
static
const unsigned char *
getrnge(const unsigned char *ep)
{
unsigned int len;
if ( ( len = *ep++ ) > 254 )
{
len = ( unsigned int ) * ep++ << 8;
len |= *ep++;
}
low = len;
if ( ( len = *ep++ ) > 254 )
{
len = ( unsigned int ) * ep++ << 8;
len |= *ep++;
}
range = len - low;
return ep;
}
static
void
compile(char const *const instring, const int len)
{
unsigned char *ep = expbuf, *lastep = ((void *)0);
const char *sp = instring;
unsigned int c, lc;
unsigned char const *const endbuf = ep + 512;
char const *const endsp = sp + len;
char bracket[9], *bracketp = bracket;
int closed, neg, cflg, i;
circf = closed = nbra = 0;
if (*sp == '^')
{
++circf, ++sp;
}
while (sp < endsp)
{
if (ep >= endbuf)
{
g_err(49, instring);
}
c = *sp++;
if ( c != '*' && ( c != '\\' || *sp != '{' ) )
{
lastep = ep;
}
switch (c)
{
case '.':
*ep++ = 014;
continue;
case '*':
if (lastep == ((void *)0) || *lastep & 03U)
{
goto defchar;
}
*lastep |= 01U;
continue;
case '$':
if (sp < endsp)
{
goto defchar;
}
*ep++ = 03;
break;
case '[':
*ep++ = 020;
(void)memset( (char *)( ep ), 0x00, ( 32 >> 1 ) << 1 );
lc = neg = 0;
if ( ( c = *sp++ ) == '^' )
{
++neg;
c = *sp++;
}
do
{
if (c == 0x00)
{
g_err(48, instring);
}
if (c == '-' && lc != 0)
{
if ( ( c = *sp++ ) == ']' )
{
( ep['-' >> 3] |= bittab['-' & 07] );
break;
}
while (lc < c)
{
( ep[lc >> 3] |= bittab[lc & 07] );
lc++;
}
}
lc = c;
( ep[c >> 3] |= bittab[c & 07] );
}
while ( ( c = *sp++ ) != ']' );
if (neg)
{
for (i = 0; i < 32; ++i)
{
ep[i] ^= 0377U;
}
ep[0] &= 0376;
}
ep += 32;
continue;
case 0x5C:
switch (c = *sp++)
{
case '(':
if (nbra >= 9)
{
g_err(42, instring);
}
*ep++ = 01;
*bracketp++ = *ep++ = nbra++;
continue;
case ')':
if (bracketp <= bracket)
{
g_err(41, instring);
}
*ep++ = 02;
*ep++ = *--bracketp;
++closed;
continue;
case '<':
*ep++ = 06;
continue;
case '>':
*ep++ = 07;
continue;
case '{':
if (lastep == ((void *)0) || *lastep & 03U)
{
goto defchar;
}
*lastep |= 03U;
cflg = 0;
nlim:
c = *sp++;
i = 0;
do
{
if (c < '0' || c > '9')
{
g_err(16, instring);
}
i = i * 10 + c - '0';
}
while ( ( ( c = *sp++ ) != '\\' ) && ( c != ',' ) );
ep = putrnge(ep, i);
if (c == ',')
{
if (cflg++)
{
g_err(43, instring);
}
if ( ( c = *sp++ ) == 0x5C )
{
ep = putrnge(ep, ( 1022 + 2 ));
}
else
{
--sp;
goto nlim;
}
}
if (*sp++ != '}')
{
g_err(44, instring);
}
if (!cflg)
{
ep = putrnge(ep, i);
}
else
{
(void)getrnge(lastep + 2);
if (range < low)
{
g_err(45, instring);
}
}
continue;
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
if ( ( c -= '1' ) >= closed )
{
g_err(24, instring);
}
*ep++ = 024;
*ep++ = (char)c;
continue;
case 'x':
c = xtoc(sp);
sp += 2;
break;
default:
c = xlat(u_map[c], esc_symb, esc_char);
}
defchar:
default:
lastep = ep;
*ep++ = 010;
*ep++ = (char)c;
}
}
*ep++ = 05;
if (bracketp != bracket)
{
g_err(41, instring);
}
}
static
int
advance(const char *lp, const unsigned char *ep)
{
const char *curlp, *bbeg;
const unsigned char *nep;
int ct;
unsigned int c;
for (;;) switch (*ep++)
{
case 010:
if (*ep++ == *lp++)
{
continue;
}
return 0;
case 014:
if (*lp++)
{
continue;
}
return 0;
case 03:
if (*lp)
{
return 0;
}
case 05:
loc2 = lp;
l2rec = g_rec;
return 1;
case 020:
c = ( unsigned char ) * lp++;
if ( ( ep[c >> 3] & bittab[c & 07] ) )
{
ep += 32;
continue;
}
return 0;
case 01:
braslist[*ep++] = lp;
continue;
case 02:
braelist[*ep++] = lp;
continue;
case 024:
bbeg = braslist[*ep];
ct = braelist[*ep++] - bbeg;
if ( ( memcmp(bbeg, lp, ct) == 0 ) )
{
lp += ct;
continue;
}
return 0;
case 06:
if ( ( lp == loc1 || !( g_map[lp[-1]] & ( 04U | 010U | 020U ) ) ) && ( g_map[lp[0]] & ( 04U | 010U | 020U ) ) )
{
continue;
}
return 0;
case 07:
if ( lp > loc1 && ( g_map[lp[-1]] & ( 04U | 010U | 020U ) ) && !( g_map[lp[0]] & ( 04U | 010U | 020U ) ) )
{
continue;
}
return 0;
case 024 | 03U:
bbeg = braslist[*ep];
ct = braelist[*ep++] - bbeg;
ep = getrnge(ep);
curlp = lp;
while ( low-- && ( memcmp(bbeg, lp, ct) == 0 ) )
{
lp += ct;
}
while ( range-- && ( memcmp(bbeg, lp, ct) == 0 ) )
{
lp += ct;
}
goto cstar;
case 024 | 01U:
bbeg = braslist[*ep];
ct = braelist[*ep++] - bbeg;
curlp = lp;
while ( ( memcmp(bbeg, lp, ct) == 0 ) )
{
lp += ct;
}
cstar:
while (lp >= curlp)
{
if ( advance(lp, ep) )
{
return 1;
}
lp -= ct;
}
return 0;
case 010 | 03U:
c = *ep++;
ep = getrnge(ep);
while (low--)
{
if (*lp++ != c)
{
return 0;
}
}
curlp = lp;
while (range--)
{
if (*lp++ != c)
{
break;
}
}
if (range < 0)
{
++lp;
}
goto star;
case 014 | 03U:
ep = getrnge(ep);
while (low--)
{
if (*lp++ == 0x00)
{
return 0;
}
}
curlp = lp;
while (range--)
{
if (*lp++ == 0x00)
{
break;
}
}
if (range < 0)
{
++lp;
}
goto star;
case 020 | 03U:
nep = getrnge(ep + 32);
while (low--)
{
c = ( unsigned char ) * lp++;
if ( !( ( ep[c >> 3] & bittab[c & 07] ) ) )
{
return 0;
}
}
curlp = lp;
while (range--)
{
c = ( unsigned char ) * lp++;
if ( !( ( ep[c >> 3] & bittab[c & 07] ) ) )
{
break;
}
}
if (range < 0)
{
++lp;
}
ep = nep;
goto star;
case 010 | 01U:
curlp = lp;
while (*lp++ == *ep)
{
;
}
++ep;
goto star;
case 020 | 01U:
curlp = lp;
do
{
c = ( unsigned char ) * lp++;
}
while ( ( ep[c >> 3] & bittab[c & 07] ) );
ep += 32;
goto star;
case 014 | 01U:
curlp = lp;
while (*lp++)
{
;
}
star:
while (--lp >= curlp)
{
if ( advance(lp, ep) )
{
return 1;
}
}
return 0;
}
}
static
int
step(const char *lp)
{
const unsigned char *ep = expbuf;
if (circf)
{
return i_col == 0 && advance(lp, ep);
}
if (*ep == 010)
{
const int c = ep[1];
ep += 2;
while ( ( lp = strchr(lp, c) ) != ((void *)0))
{
if ( advance(++lp, ep) )
{
loc1 = lp - 1;
return 1;
}
}
return 0;
}
do
{
if ( advance(lp, ep) )
{
loc1 = lp;
return 1;
}
}
while ( *lp++ );
return 0;
}
static
char
xcase(const int c)
{
const unsigned int f = cflags;
cflags = f & ~( 4 | 8 );
return (char)( ( f & 4 || f == 1 ) ? u_map[c] : ( ( g_map[c] & 020U ) ? c + ( 'a' - 'A' ) : c ) );
}
static
char *
place(char *sp, const char *p1, const char *p2, char const *const end_buff)
{
while (p1 < p2)
{
*sp++ = cflags ? xcase(*p1++) : *p1++;
if (sp >= end_buff)
{
g_err(53, ((void *)0));
}
}
return sp;
}
static
int
re_sub(const char *ep, char *const str)
{
static char *s_save, *e_save;
static int s_save_len = -1, e_save_len = -1;
char c, *sp = str;
char const *const end_buff = str + 1022;
int len;
if ( ( *(unsigned int *)ep == '~' ) )
{
if (e_save_len < 0)
{
g_err(40, ((void *)0));
}
}
else
{
if ( ( len = ( strlen(ep) + 1 ) ) > e_save_len )
{
if (e_save_len > 0)
{
rlsevec(e_save);
}
if ( ( e_save_len = len ) > 0 )
{
e_save = (char *)getvec(len);
}
}
if (len > 0) memcpy( (void *)( e_save ), (const void *)( ep ), len );
}
ep = e_save;
if ( ( *(unsigned int *)ep == '%' ) )
{
if (s_save_len < 0)
{
g_err(40, ((void *)0));
}
if (s_save_len > 0) memcpy( (void *)( sp ), (const void *)( s_save ), s_save_len );
return s_save_len;
}
cflags = 0;
while ( ( c = *ep++ ) != 0x00 )
{
if (c == '&')
{
sp = place(sp, loc1, loc2, end_buff);
continue;
}
if (c == '\\')
{
switch (c = *ep++)
{
case 0x00:
g_err(54, ((void *)0));
case 'U':
cflags = cflags & ~8 | 4;
continue;
case 'u':
cflags = cflags & ~2 | 1;
continue;
case 'L':
cflags = cflags & ~4 | 8;
continue;
case 'l':
cflags = cflags & ~1 | 2;
continue;
case 'e':
cflags = 0;
continue;
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
if ( ( c -= '1' ) >= nbra )
{
g_err(24, str);
}
sp = place(sp, braslist[c], braelist[c], end_buff);
continue;
case 'x':
c = xtoc(ep);
ep += 2;
break;
default:
c = xlat(u_map[c], esc_symb, esc_char);
}
}
*sp++ = cflags ? xcase(c) : c;
if (sp >= end_buff)
{
g_err(53, str);
}
}
if ( ( len = (int)( sp - str ) ) > s_save_len)
{
if (s_save_len > 0)
{
rlsevec(s_save);
}
if ( ( s_save_len = len ) > 0 )
{
s_save = (char *)getvec(len);
}
}
if (len > 0) memcpy( (void *)( s_save ), (const void *)( str ), len );
return len;
}
static
void
Quit(void)
{
term();
if (lon)
{
putstr("Edit abandoned.");
}
_exit(0);
}
static
int
get_com(char *str, char const *const c_prompt)
{
const unsigned char *p;
int len;
if (c_list != ((void *)0))
{
if ( ( len = vsgetrec(comm_u, &p) ) == (-1) )
{
c_comm_u();
return 1;
}
if (len >= 2048)
{
g_err(32, ((void *)0));
}
(void)memcpy( (void *)( str ), (const void *)( p ), len ); str[len] = 0x00;;
if (lon)
{
say(str);
}
return 0;
}
if (g_init != ((void *)0))
{
(void)strcpy( (void *)( str ), (const void *)( g_init ) );
g_init = ((void *)0);
return 0;
}
lon = 1;
putstr(c_prompt);
if ( ( len = read(0, str, 2048) ) <= 0 )
{
Quit();
abort();
}
str[len - 1] = 0x00;
return 0;
}
static
int
gdss(char *const buf, int *const buf_len, char const **const ptr)
{
char ch_delim;
char const *const str = *ptr, *p;
int len;
if ( !( ( g_map[ch_delim = str[-1]] & 01U ) ) )
{
g_err(35, str - 1);
}
if ( ( p = strchr(str, ch_delim) ) == ((void *)0) )
{
p = strchr(str, 0x00);
}
if ( ( len = p - str ) > 2048 )
{
g_err(11, str);
}
(void)memcpy( (void *)( buf ), (const void *)( str ), len ); buf[len] = 0x00;;
*buf_len = len;
if (*p == 0x00)
{
*ptr = p;
return 1;
}
*ptr = p + 1;
return 0;
}
static
void
altr_line(int col, const int comm)
{
if (col + i_col > i_eor)
{
if (!depth)
{
g_err(13, ((void *)0));
}
col = i_eor - i_col;
}
if (col + i_col < 0)
{
g_err(15, ((void *)0));
}
if (comm == 'T')
{
if (col + e_col > 1022)
{
g_err(47, ((void *)0));
}
(void)memcpy( (void *)( e_buff + e_col ), (const void *)( i_buff + i_col ), ( col ) );
e_col += col;
}
i_col += col;
}
static
void
get_end(void)
{
const int i_len = i_eor - i_col;
if (e_col + i_len > 1022)
{
g_err(47, ((void *)0));
}
(void)memcpy( (void *)( e_buff + e_col ), (const void *)( i_buff + i_col ), ( i_len ) );
e_col += i_len;
i_col = i_eor;
}
static
void
out_buff(void)
{
vsputrec(out_u, e_buff, e_col);
e_col = 0;
++o_rec;
}
static
void
flush_buff(void)
{
if (e_col + i_col)
{
get_end();
out_buff();
}
else
{
vsputrec(out_u, i_buff, i_eor);
++o_rec;
}
}
static
void
printable(char *p, int len)
{
while (len--)
{
*p = toprint(*p);
++p;
}
}
static
void
n_print(char const *const line, int len, const int arrowed)
{
string buf;
char *p;
int rem = 76;
*buf = 0x00;
if (l_numbers)
{
rem -= sprintf(buf, n_format, (long)g_rec);
}
if (len > rem)
{
len = rem;
}
p = ( strcat( (void *)buf, (const void *)arrowed ? ">>" : " "), strchr(buf, 0x00) );
(void)memcpy( (void *)( p ), (const void *)( line ), len ); p[len] = 0x00;;
printable(p, len);
say(buf);
}
static
int
add_line(const int comm)
{
int rc;
if (!g_eof && comm == 'T')
{
flush_buff();
}
rc = fill_buff();
if (comm == 'L')
{
n_print(i_buff, i_eor, 0);
}
return rc;
}
static
int
contains(const char *ptr, char const *const str, const int len, char const *const last)
{
const int c = *str;
while ( ptr <= last &&
( ptr = (const char *)memchr( ptr, c, ( last - ptr ) + 1 ) )
!= ((void *)0) )
{
if ( ( memcmp(ptr, str, len) == 0 ) )
{
loc1 = ptr;
loc2 = ptr + len;
l2rec = g_rec;
return 1;
}
++ptr;
}
return 0;
}
static
int
ncontains(const char *ptr, char const *const str, const int len, char const *const i_end)
{
while ( i_end - ptr >= len && ( memcmp(ptr, str, len) == 0 ) )
{
++ptr;
}
return 1;
}
static
int
nstep(const char *p1)
{
unsigned char const *const p2 = expbuf;
int rc = 1;
if (circf)
{
rc = i_col != 0 || !advance(p1, p2);
}
else
{
while ( advance(p1++, p2) )
{
;
}
}
return rc;
}
static
int
string_search(char *const ign_buff, char const *const str, const int len,
const int comm, const unsigned int ignore, const unsigned int negate,
const unsigned int type)
{
char *b_ptr, *i_end;
int r_len;
const int regex = u_map[type] == 'R',
stay = ( type == 'r' || type == 'G' || comm == 'V' );
if (regex)
{
if (len)
{
compile(str, len);
}
else if( ( *( expbuf ) == 0x00 ) )
g_err(40, str);
}
for (;;)
{
r_len = i_eor;
if (ignore)
{
char *p1 = i_buff, *p2 = ign_buff;
int i;
for (i = 0; i < r_len; ++i)
{
*p2++ = u_map[*( p1++ )];
}
b_ptr = ign_buff;
}
else
{
b_ptr = i_buff;
}
i_end = b_ptr + r_len;
*i_end = 0x00;
switch (type)
{
case 'r':
case 'G':
case 'H':
b_ptr += i_col;
break;
case 'S':
while ( b_ptr < i_end && ( ( *b_ptr ) == 0x20 ) )
{
++b_ptr;
}
r_len = i_end - b_ptr;
case 'B':
if (len == 0)
{
if (negate + r_len == 0 || negate && r_len > 0)
{
return 1;
}
}
break;
case 'F':
if (len < r_len)
{
b_ptr = i_end - len ;
}
}
loc1 = b_ptr;
if (regex || i_end - loc1 >= len)
{
switch (type)
{
case 'R':
if (step(b_ptr) != negate)
{
return 1;
}
break;
case 'r':
if (comm == 'V')
{
return advance(b_ptr, expbuf) != negate;
}
if ( !negate && step(b_ptr) || negate && nstep(b_ptr) )
{
altr_line( (int)( loc1 - b_ptr ), comm );
return 1;
}
return 0;
case 'F':
case 'S':
case 'B':
case 'H':
if (len && ( memcmp(b_ptr, str, len) == 0 ) != negate)
{
if (!negate)
{
loc2 = b_ptr + len;
l2rec = g_rec;
}
return 1;
}
break;
case 'G':
if ( !negate && contains(b_ptr, str, len, i_end - len)
|| negate && ncontains(b_ptr, str, len, i_end) )
{
altr_line( (int)( loc1 - b_ptr ), comm );
return 1;
}
return 0;
case 'C':
if (contains(b_ptr, str, len, i_end - len) != negate)
{
return 1;
}
}
}
else if(negate)
return 1;
if (stay)
{
return 0;
}
if ( !add_line(comm) )
{
return negate;
}
}
}
static
int
findstr(char const *const str, int len, unsigned int type, const int comm)
{
const unsigned int ignore = type & 0x0200, negate = ( type & 0x0400 ) != 0;
LINE buf;
type &= 0377U;
if (type == 'G' && comm == 'V')
{
type = 'H';
}
loc2 = ((void *)0);
if ( string_search(buf, str, len, comm, ignore, negate, type) )
{
if (ignore && loc2 != ((void *)0))
{
len = loc2 - loc1;
loc1 = i_buff + ( loc1 - buf );
loc2 = loc1 + len;
}
return 0;
}
return 1;
}
static
const char *
prep_name(const char *fname)
{
static FNAME name;
const char *v;
char *p = name, *t, c;
while ( ( c = *fname++ ) != 0x00 )
{
switch (c)
{
case '%':
v = in_fname;
break;
case '~':
if ( ( *fname == 0x2F || *fname == 0x5C ) )
{
if ( ( v = getenv("HOME") ) == ((void *)0) )
{
v = empty;
}
break;
}
default:
*p++ = c;
continue;
case '$':
for (t = p; ( g_map[*fname] & ( 04U | 010U | 020U ) ); ++fname)
{
*t++ = *fname;
}
*t = 0x00;
if ( ( v = getenv(p) ) == ((void *)0) )
{
g_err(36, p);
}
}
p = ( strcpy( (void *)p, (const void *)v), strchr(p, 0x00) );
}
*p = 0x00;
return name;
}
static
int
Disk_to_mem(char const *const fname, UNIT *const vs_u, const int mode)
{
int fd;
int len = 0;
char buf[4096 + ( 1022 + 2 )], *p;
if (mode == 'F')
{
fd = fd_in_terminal;
}
else if( ( fd = open(prep_name(fname), 0x0000) ) == -1 )
return (-1);
trunc_recs = 0;
setmode(fd, 0x0200);
while ( ( len = read(fd, p = buf + len, 4096) ) > 0 )
{
const char *start = buf, *const last = p + len;
while ( ( len = last - p ) > 0 )
{
if ( ( p = (char *)memchr(p, 0x0A, len) ) == ((void *)0) )
{
if (len > 1022)
{
len = 1022 + 1;
}
(void)memcpy( (void *)( buf ), (const void *)( start ), ( len ) );
break;
}
vsload( vs_u, start, (int)( p - start ) );
start = ++p;
}
}
if (p > buf)
{
vsload( vs_u, buf, (int)( p - buf ) );
}
(void)close(fd);
return ( vs_u->rec_num );
}
static
int
Mem_to_disk(UNIT *const vs_u, char const *const fname, const int mode)
{
const unsigned char *rec;
int len, fd, fmode;
unsigned char buf[4096 + ( 1022 + 2 )], *p = buf, *const last = p + 4096;
if (mode == 'F')
{
fd = fd_out_terminal;
}
else
{
if ( ro_mode && ( strcmp(fname, in_fname) == 0 ) )
{
(*__get_errno_ptr()) = 6;
return (-1);
}
if (mode == 'N')
{
fmode = 0x0001 | 0x0020 | 0x0040;
}
else
{
fmode = 0x0001 | 0x0020 | 0x0010;
}
if ( ( fd = open(prep_name(fname), fmode, 0644) ) == -1)
{
return (-1);
}
}
setmode(fd, 0x0200);
if ( isatty(fd) )
{
term();
}
while ( ( len = vsgetrec(vs_u, &rec) ) != (-1) )
{
p = ( memcpy( (void *)( p ), (const void *)( rec ), len), (void *)( (char *)( p ) + len ) );
*p++ = '\r';
*p++ = '\n';
if (p > last)
{
if (write(fd, buf, 4096) != 4096)
{
return (-1);
}
len = p - last;
p = ( memcpy( (void *)( buf ), (const void *)( last ), len), (void *)( (char *)( buf ) + len ) );
}
}
if ( ( len = p - buf ) > 0 )
{
if (write(fd, buf, len) != len)
{
return (-1);
}
}
(void)close(fd);
return ( vs_u->rec_num );
}
static
void
push_line(stack **const line_stack, char const *const text, const int len)
{
stack *const p = (stack *)getvec(sizeof ( stack ) + sizeof ( short ) + len);
short *const start = (short *)( p + 1 );
*start = (short)len;
(void)memcpy( (void *)( start + 1 ), (const void *)( text ), ( len ) );
*p = (stack)( *line_stack );
*line_stack = p;
if (p == in_stack)
{
++in_count;
}
}
static
void
pop_line(stack **const line_stack, char *const line)
{
stack *p, *const top = *line_stack;
short *start;
if (top == ((void *)0))
{
return;
}
p = (stack *)( *top );
start = (short *)( top + 1 );
(void)memcpy( (void *)( line ), (const void *)( start + 1 ), ( *start ) );
rlsevec(top);
*line_stack = p;
if (p == in_stack)
{
--in_count;
}
}
static
void
buf_to_file(const int com)
{
int i;
const int last = ( com == 1 ) ? 3 : last_line;
for (i = 3; i <= last && eor[i] != (-1); ++i)
{
vsputrec(out_u, s_buf[i], eor[i]);
}
o_rec += i - 3;
switch (com)
{
case 5:
case 6:
case 4:
case 2:
case 7:
case 9:
while (in_stack != ((void *)0))
{
e_col = ( *(short *)( in_stack + 1 ) );
pop_line(&in_stack, e_buff);
out_buff();
}
(void)fill_buff();
}
}
static
int
wrapround(void)
{
UNIT *temp;
const int last_o_rec = o_rec + 1;
if (f_list != ((void *)0))
{
g_err(f_list->disp == 'M' ? 20 : 33, ((void *)0));
}
if (!g_eof)
{
alter_end((-1), 'T');
}
if (e_col)
{
out_buff() ;
}
vsreopen(temp = out_u);
vsreopen(out_u = in_u);
in_u = temp;
init_line();
return last_o_rec;
}
static
void
g_intr(int sig)
{
(void)signal(sig, g_intr);
g_err(38, empty);
}
static
TOKEN *c_free_list = ((void *)0);
static
TOKEN locals[27 + 1];
static
char last_was_op;
static
unsigned int
priority(const unsigned int op)
{
if ( ( op >> 8 ) == 0 )
{
return xlat(op, "*/%+-<>&^|?:=,", opprio);
}
switch (op)
{
case ( ( '=' << 8 ) | '>' ):
case ( ( '=' << 8 ) | '<' ):
return 10;
case ( ( '=' << 8 ) | 'E' ):
case ( ( '=' << 8 ) | '!' ):
return 8;
case ( ( '&' << 8 ) | '&' ):
return 4;
case ( ( '|' << 8 ) | '|' ):
return 3;
case ( ( '<' << 8 ) | '<' ):
case ( ( '>' << 8 ) | '>' ):
return 11;
}
return 1;
}
static
void
free_expr(TOKEN *const ptr)
{
TOKEN *p = ptr;
while (p->next != ((void *)0))
{
p = p->next;
}
p->next = c_free_list;
c_free_list = ptr;
}
static
void
execute(TOKEN *const rhs, TOKEN const *const action)
{
TOKEN *dest, *lhs;
char fp;
const unsigned int op = action->id;
if (rhs == ((void *)0) || rhs->snext == ((void *)0))
{
g_err(0, action->errp);
}
lhs = rhs->snext;
if (op == '=')
{
fp = lhs->fp = rhs->fp;
}
else
{
fp = lhs->fp | rhs->fp;
if (fp != rhs->fp)
{
rhs->fp = 1;
rhs->opval.r = (double)rhs->opval.i;
}
if (fp != lhs->fp)
{
lhs->fp = 1;
lhs->opval.r = (double)lhs->opval.i;
}
}
if ( ( op & 0377U ) == '=' )
{
if (lhs->id == 0177)
{
g_err(0, lhs->errp);
}
dest = &locals[lhs->id];
dest->fp = fp;
}
if (fp)
{
const double rrval = rhs->opval.r, lrval = lhs->opval.r;
switch (op)
{
default:
g_err(18, lhs->errp);
case '=':
lhs->opval.r = dest->opval.r = rrval;
return;
case '+':
lhs->opval.r += rrval;
return;
case '-':
lhs->opval.r -= rrval;
return;
case '*':
lhs->opval.r *= rrval;
return;
case '/':
lhs->opval.r /= rrval;
return;
case ( ( '+' << 8 ) | '=' ):
dest->opval.r = lhs->opval.r += rrval;
return;
case ( ( '-' << 8 ) | '=' ):
dest->opval.r = lhs->opval.r -= rrval;
return;
case ( ( '*' << 8 ) | '=' ):
dest->opval.r = lhs->opval.r *= rrval;
return;
case ( ( '/' << 8 ) | '=' ):
dest->opval.r = lhs->opval.r /= rrval;
return;
case '>':
lhs->opval.i = lrval > rrval;
break;
case '<':
lhs->opval.i = lrval < rrval;
break;
case ( ( '=' << 8 ) | '>' ):
lhs->opval.i = lrval >= rrval;
break;
case ( ( '=' << 8 ) | '<' ):
lhs->opval.i = lrval <= rrval;
break;
case ( ( '&' << 8 ) | '&' ):
lhs->opval.i = lrval && rrval;
break;
case ( ( '|' << 8 ) | '|' ):
lhs->opval.i = lrval || rrval;
break;
case ( ( '=' << 8 ) | 'E' ):
lhs->opval.i = lrval == rrval;
break;
case ( ( '=' << 8 ) | '!' ):
lhs->opval.i = lrval != rrval;
break;
}
lhs->fp = 0;
}
else
{
const long rival = rhs->opval.i, lival = lhs->opval.i;
switch (op)
{
case '=':
lhs->opval.i = dest->opval.i = rival;
break;
case '+':
lhs->opval.i += rival;
break;
case '-':
lhs->opval.i -= rival;
break;
case '*':
lhs->opval.i *= rival;
break;
case '/':
if (rival == 0)
{
g_err(6, lhs->errp);
}
lhs->opval.i /= rival;
break;
case '%':
if (rival == 0)
{
g_err(6, lhs->errp);
}
lhs->opval.i %= rival;
break;
case '&':
lhs->opval.i &= rival;
break;
case '|':
lhs->opval.i |= rival;
break;
case '^':
lhs->opval.i ^= rival;
break;
case ( ( '<' << 8 ) | '<' ):
lhs->opval.i <<= (int)( rival & 077 );
break;
case ( ( '>' << 8 ) | '>' ):
lhs->opval.i >>= (int)( rival & 077 );
break;
case '>':
lhs->opval.i = lival > rival;
break;
case '<':
lhs->opval.i = lival < rival;
break;
case ( ( '=' << 8 ) | '>' ):
lhs->opval.i = lival >= rival;
break;
case ( ( '=' << 8 ) | '<' ):
lhs->opval.i = lival <= rival;
break;
case ( ( '&' << 8 ) | '&' ):
lhs->opval.i = lival && rival;
break;
case ( ( '|' << 8 ) | '|' ):
lhs->opval.i = lival || rival;
break;
case ( ( '=' << 8 ) | 'E' ):
lhs->opval.i = lival == rival;
break;
case ( ( '=' << 8 ) | '!' ):
lhs->opval.i = lival != rival;
break;
case ( ( '+' << 8 ) | '=' ):
dest->opval.i = lhs->opval.i += rival;
break;
case ( ( '-' << 8 ) | '=' ):
dest->opval.i = lhs->opval.i -= rival;
break;
case ( ( '*' << 8 ) | '=' ):
dest->opval.i = lhs->opval.i *= rival;
break;
case ( ( '/' << 8 ) | '=' ):
if (rival == 0)
{
g_err(6, lhs->errp);
}
dest->opval.i = lhs->opval.i /= rival;
break;
case ( ( '%' << 8 ) | '=' ):
if (rival == 0)
{
g_err(6, lhs->errp);
}
dest->opval.i = lhs->opval.i %= rival;
break;
case ( ( '|' << 8 ) | '=' ):
dest->opval.i = lhs->opval.i |= rival;
break;
case ( ( '&' << 8 ) | '=' ):
dest->opval.i = lhs->opval.i &= rival;
break;
case ( ( '^' << 8 ) | '=' ):
dest->opval.i = lhs->opval.i ^= rival;
break;
case ( ( '<' << 8 ) | '=' ):
dest->opval.i = lhs->opval.i <<= (int)( rival & 077 );
break;
case ( ( '>' << 8 ) | '=' ):
dest->opval.i = lhs->opval.i >>= (int)( rival & 077 );
}
}
}
static
void
mon_exec(TOKEN *const dp, const int op, const int prefix)
{
TOKEN *dest;
int fp = dp->fp;
double rval = dp->opval.r;
const long ival = dp->opval.i;
switch (op)
{
case '-':
if (fp)
{
dp->opval.r = -rval;
}
else
{
dp->opval.i = -ival;
}
break;
case '~':
if (fp)
{
g_err(18, dp->errp);
}
dp->opval.i = ~ival;
break;
case '!':
if (fp)
{
dp->opval.i = !rval;
dp->fp = 0;
}
else
{
dp->opval.i = !ival;
}
break;
case ( ( '+' << 8 ) | '+' ):
if (dp->id == 0177)
{
g_err(0, dp->errp);
}
dest = &locals[dp->id];
if (fp)
{
dp->opval.r = prefix ? ++dest->opval.r : dest->opval.r++;
}
else
{
dp->opval.i = prefix ? ++dest->opval.i : dest->opval.i++;
}
break;
case ( ( '-' << 8 ) | '-' ):
if (dp->id == 0177)
{
g_err(0, dp->errp);
}
dest = &locals[dp->id];
if (fp)
{
dp->opval.r = prefix ? --dest->opval.r : dest->opval.r--;
}
else
{
dp->opval.i = prefix ? --dest->opval.i : dest->opval.i--;
}
}
}
static
long
rtoi(char const **const ptr)
{
long n = 0, last = 0, val;
int pow10 = 0, dec, contig;
const char *p, *const s = *ptr;
for (p = s; memchr(c_rom, *p, 18) != ((void *)0); ++p)
{
;
}
*ptr = p;
while (--p >= s)
{
switch ( u_map[*( p )] )
{
default:
g_err(16, s);
case 'I':
val = pow10 = 1;
break;
case 'V':
val = 5;
break;
case 'X':
val = 10, ++pow10;
break;
case 'L':
val = 50;
break;
case 'C':
val = 100, ++pow10;
break;
case 'D':
val = 500;
break;
case 'M':
val = 1000, ++pow10;
break;
case 'W':
val = 5000;
break;
case 'Z':
val = 10000, ++pow10;
}
if (val > last)
{
n += val;
dec = 0;
contig = 1;
last = val;
}
else if(val == last)
{
if (!pow10 || ++contig > 3)
{
g_err(16, s);
}
n += val;
}
else
{
if (!pow10 || contig != 1 || dec)
{
g_err(16, s);
}
dec = 1;
contig = 0;
n -= val;
}
}
return n;
}
static
unsigned int
get_op(char const **const ptr)
{
unsigned int c1, c2;
if ( ( c1 = *( *ptr )++ ) != 0x00 )
{
c2 = *( *ptr )++;
}
switch (c1)
{
case '}':
c1 = 0x00;
break;
case '>':
case '<':
if (c2 == '=')
{
return ( ( c2 << 8 ) | c1 );
}
if (c2 == c1)
{
if ( ( c1 = **ptr ) == '=' )
{
++( *ptr );
return ( ( c2 << 8 ) | c1 );
}
return ( ( c2 << 8 ) | c2 );
}
break;
case '!':
case '=':
if (c2 == '=')
{
if (c1 == '=')
{
c1 = 'E';
}
return ( ( c2 << 8 ) | c1 );
}
break;
case '&':
if (c2 == '&' || c2 == '=')
{
return ( ( c1 << 8 ) | c2 );
}
break;
case '|':
if (c2 == '|' || c2 == '=')
{
return ( ( c1 << 8 ) | c2 );
}
break;
case '+':
if (c2 == '+' || c2 == '=')
{
return ( ( c1 << 8 ) | c2 );
}
break;
case '-':
if (c2 == '-' || c2 == '=')
{
return ( ( c1 << 8 ) | c2 );
}
break;
case '*':
case '/':
case '%':
case '^':
if (c2 == '=')
{
return ( ( c1 << 8 ) | c2 );
}
break;
case '.':
switch (c2)
{
case '@':
case '#':
case '$':
case '&':
case '.':
return ( ( c1 << 8 ) | c2 );
}
}
--( *ptr );
return c1;
}
static
TOKEN *
lex(char const **const ptr)
{
const char *p, *e = *ptr;
int ch;
static TOKEN tok;
char base;
while ( ( ( *( e ) ) == 0x20 ) ) ++ ( e );
tok.errp = e;
if ( ( ch = get_op(&e) ) == 0x00 )
{
*ptr = e;
return ((void *)0);
}
tok.fp = tok.l_fp = 0;
tok.group = 0;
tok.id = ch;
p = e;
switch (ch)
{
case '(':
tok.group = 1;
++last_was_op;
break;
case ')':
tok.group = 2;
last_was_op = 0;
break;
case '.':
if ( !( ( g_map[*p] & 010U ) ) )
{
tok.id = 26;
break;
}
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
tok.id = 0177;
if (ch == '0')
{
base = u_map[*( p++ )];
if (base == 'R')
{
e = p;
tok.litval.i = rtoi(&e);
goto have_num;
}
if (base == 'B')
{
tok.litval.i = strtol(p, (char **)&e, 2);
goto have_num;
}
--p;
}
tok.litval.i = strtol(--p, (char **)&e, 0);
ch = u_map[*( e )];
if (ch == 'E' || ch == '.')
{
if ( ( ( *( (unsigned short *)0x410 ) ) & 0x02 ) == 0 )
{
g_err(16, p);
}
tok.litval.r = strtod(p, (char **)&e);
tok.l_fp = 1;
}
have_num:
if (e == p)
{
g_err(16, p);
}
p = e;
break;
case 0x27:
tok.id = 0177;
if ( ( ch = *p++ ) == 0x5C )
{
ch = xlat(u_map[*( p++ )], esc_symb, esc_char);
}
if (*p++ != 0x27)
{
g_err(0, p);
}
tok.litval.i = ch;
break;
case '-': case '+':
if (!last_was_op)
{
goto binops;
}
case '!': case '~': case ( ( '+' << 8 ) | '+' ): case ( ( '-' << 8 ) | '-' ):
tok.group = last_was_op ? 3 : 4;
break;
case '*':
case '&':
if (last_was_op)
{
break;
}
case '/': case '%': case '|': case '^': case '=': case '<': case '>': case ( ( '<' << 8 ) | '<' ): case ( ( '>' << 8 ) | '>' ): case ( ( '=' << 8 ) | '>' ): case ( ( '=' << 8 ) | '<' ): case ( ( '&' << 8 ) | '&' ): case ( ( '|' << 8 ) | '|' ): case ( ( '=' << 8 ) | 'E' ): case ( ( '=' << 8 ) | '!' ): case ( ( '+' << 8 ) | '=' ): case ( ( '-' << 8 ) | '=' ): case ( ( '*' << 8 ) | '=' ): case ( ( '/' << 8 ) | '=' ): case ( ( '%' << 8 ) | '=' ): case ( ( '|' << 8 ) | '=' ): case ( ( '&' << 8 ) | '=' ): case ( ( '^' << 8 ) | '=' ): case ( ( '<' << 8 ) | '=' ): case ( ( '>' << 8 ) | '=' ):
binops:
tok.group = 5;
++last_was_op;
tok.opval.i = priority(ch);
break;
case ',':
case ';':
tok.group = 6;
++last_was_op;
break;
case '?':
tok.group = 8;
++last_was_op;
break;
case ':':
tok.group = 9;
++last_was_op;
break;
case '#':
case '@':
case '$':
case ( ( '.' << 8 ) | '#' ):
case ( ( '.' << 8 ) | '@' ):
case ( ( '.' << 8 ) | '$' ):
case ( ( '.' << 8 ) | '&' ):
break;
case ( ( '.' << 8 ) | '.' ):
tok.id = 27;
break;
default:
ch = u_map[ch];
if ( !( ( g_map[ch] & 020U ) ) )
{
g_err(0, tok.errp);
}
tok.id = ch - 'A';
}
if (tok.group == 0)
{
last_was_op = 0;
}
*ptr = p;
return &tok;
}
static
int
Expr_compile(TOKEN **start, char const **const ptr)
{
TOKEN *tok, *temp;
*start = ((void *)0);
++last_was_op;
while ( ( tok = lex(ptr) ) != ((void *)0) )
{
if (c_free_list != ((void *)0))
{
temp = c_free_list;
c_free_list = temp->next;
}
else
{
temp = ( TOKEN *)getvec(sizeof ( TOKEN ) );
}
*temp = *tok;
temp->next = ((void *)0);
*start = temp;
start = &temp->next;
}
return ( *ptr )[-1] != '}';
}
static
void
get_value(TOKEN *const tok)
{
const TOKEN *tp;
long ival;
switch (tok->id)
{
default:
tp = &locals[tok->id];
tok->fp = tp->fp;
tok->opval = tp->opval;
return;
case 0177:
tok->fp = tok->l_fp;
tok->opval = tok->litval;
return;
case '*':
if (g_eof || i_col >= i_eor)
{
ival = 0;
}
else
{
ival = (long)( i_buff[i_col] & 0377U );
}
break;
case '&':
ival = o_rec + 1;
break;
case '#':
ival = g_rec;
break;
case '@':
ival = s_g_rec > 0 ? s_g_rec : 0;
break;
case '$':
ival = ( in_u->eof_rec );
break;
case ( ( '.' << 8 ) | '#' ):
ival = i_col;
break;
case ( ( '.' << 8 ) | '@' ):
ival = s_g_col > 0 ? s_g_col : 0;
break;
case ( ( '.' << 8 ) | '$' ):
ival = i_eor;
break;
case ( ( '.' << 8 ) | '&' ):
ival = e_col;
}
tok->opval.i = ival;
}
static
TOKEN *
clear_stack(TOKEN *ds, TOKEN *os)
{
while (os != ((void *)0))
{
execute(ds, os);
ds = ds->snext;;
os = os->snext;;
}
if (ds == ((void *)0))
{
g_err(0, ((void *)0));
}
return ds;
}
static
TOKEN *
match(TOKEN *tok, const int endp)
{
for (tok = tok->next; tok != ((void *)0) && tok->group != endp; tok = tok->next)
{
switch (tok->group)
{
case 1:
tok = match(tok, 2);
continue;
case 8:
tok = match(tok, 9);
continue;
case 9:
case 2:
if (endp != 7)
{
g_err(0, tok->errp);
}
return tok;
}
}
return tok;
}
static
TOKEN *
parse(TOKEN *const retval, TOKEN *tok, const int endp)
{
TOKEN *temp, *dstack = ((void *)0), *ostack = ((void *)0);
int query_value, prefix = 0;
for (; tok != ((void *)0); tok = tok->next)
{
switch (tok->group)
{
case 1:
tok = parse(temp = tok, tok->next, 2);
temp->snext = dstack; dstack = temp;
if (prefix)
{
mon_exec(dstack, prefix, 1);
prefix = 0;
}
if (tok == ((void *)0))
{
break;
}
continue;
case 0:
tok->snext = dstack; dstack = tok;
get_value(dstack);
if (prefix)
{
mon_exec(dstack, prefix, 1);
prefix = 0;
}
continue;
case 3:
prefix = tok->id;
continue;
case 4:
mon_exec(dstack, tok->id, 0);
continue;
case 5:
while (ostack != ((void *)0) && tok->opval.i <= ostack->opval.i)
{
execute(dstack, ostack);
dstack = dstack->snext;;
ostack = ostack->snext;;
}
tok->snext = ostack; ostack = tok;
continue;
case 6:
(void)clear_stack(dstack, ostack);
dstack = ostack = ((void *)0);
continue;
case 8:
dstack = clear_stack(dstack, ostack);
if (dstack->fp)
{
query_value = dstack->opval.r != 0.0;
}
else
{
query_value = dstack->opval.i != 0;
}
dstack = ostack = ((void *)0);
if (query_value)
{
tok = parse(temp = tok, tok->next, 9);
temp->snext = dstack; dstack = temp;
tok = match(tok, 7);
}
else
{
tok = match(tok, 9);
}
if (tok == ((void *)0))
{
break;
}
continue;
case 9:
case 2:
if (endp != tok->group)
{
g_err(0, tok->errp);
}
}
break;
}
dstack = clear_stack(dstack, ostack);
retval->fp = dstack->fp;
retval->opval = dstack->opval;
return tok;
}
static
char *
itor(long n)
{
static char rnum[12];
long k, rem[5], prev[5];
char const *const ones = c_rom, *const fives = c_rom + 5;
char *cp;
int i;
for (i = 0; i < 5; ++i)
{
rem[i] = n % 10;
n /= 10;
prev[i] = -1;
}
for (i = 0; i < 5; ++i)
{
if (rem[i] == 9)
{
if (prev[i] == -1)
{
prev[i + 1] = i;
}
else
{
prev[i + 1] = prev[i];
prev[i] = -1;
}
rem[i] = 0;
}
}
cp = rnum;
for (i = 5 - 1; i >= 0; --i)
{
if (rem[i] == 4)
{
if (prev[i] == -1)
{
*cp++ = ones[i];
}
else
{
*cp++ = ones[prev[i]];
}
*cp++ = fives[i];
}
else
{
k = rem[i] % 5;
if (rem[i] >= 5)
{
*cp++ = fives[i];
}
while (k--)
{
*cp++ = ones[i];
}
if (prev[i] != -1)
{
*cp++ = ones[prev[i]];
*cp++ = ones[i];
}
}
}
*cp = 0x00;
return rnum;
}
static
const char *
itoc(const long n)
{
static char str[] = "\'c\'";
if ( ( n < 0x20 || n >= 0x7F ) )
{
return asc_tab[n == 0x7F ? 32 : n];
}
str[1] = (char)n;
return (const char *)str;
}
static
char *
itob(unsigned long n)
{
static char bstr[33];
char *p = &bstr[31];
do
{
*p-- = (char)( ( n & 01U ) + '0' );
n >>= 1;
}
while ( n != 0 );
if ( ( &bstr[32] - p ) & 01U )
{
return p + 1;
}
*p = '0';
return p;
}
static
char *
itoh(const long n)
{
static char hbuf[9] = "0";
return sprintf(hbuf + 1, "%lX", n) & 01U ? hbuf : hbuf + 1;
}
static
void
print_val(void)
{
char oline[200], rstr[50], astr[20], *p;
int len;
putstr("==> ");
if (( &locals[26] )->fp)
{
(void)sprintf(oline, m_real, ( &locals[26] )->opval.r);
}
else
{
const long val = ( &locals[26] )->opval.i;
p = ( strcpy( (void *)rstr, (const void *)", Roman: "), strchr(rstr, 0x00) );
if (val == 0)
{
(void)strcpy( (void *)( p ), (const void *)( "nihil" ) );
}
else if(val > 0 && val <= 39999L)
(void)strcpy( (void *)( p ), (const void *)( itor(val) ) );
else if(val < 0 && val >= -39999L)
(void)strcpy( (void *)( ( strcat( (void *)p, (const void *)"negativus "), strchr(p, 0x00) ) ), (const void *)( itor(-val) ) );
else
{
(void)strcpy( (void *)( p ), (const void *)( "numerus negatus" ) );
}
if ( ( !( ( val ) & ~0177U ) ) )
{
(void)strcpy( (void *)( ( strcpy( (void *)astr, (const void *)", Ascii: "), strchr(astr, 0x00) ) ), (const void *)( itoc(val) ) );
}
else
{
astr[0] = 0x00;
}
len = sprintf(
oline,
"Bin: %s, Oct: %lo, Dec: %ld, Hex: %s%s%s",
itob( (unsigned long)val ),
val,
val,
itoh(val),
astr,
rstr);
if (len > 74)
{
len = sprintf(
oline,
"Oct: %lo, Dec: %ld, Hex: %s%s%s",
val,
val,
itoh(val),
astr,
rstr);
}
if (len > 74)
{
(void)sprintf(
oline, "Oct: %lo, Dec: %ld, Hex: %s",
val,
val,
itoh(val) );
}
}
say(oline);
}
static
void
Calc(TOKEN *expr)
{
string cline;
const char *p;
TOKEN *ptr = expr;
jmp_buf c_save_err;
memcpy( (void *)( c_save_err ), (const void *)( set_err ), ( sizeof ( jmp_buf ) ) );
if (lon)
{
term();
}
do
{
if (_setjmp(set_err) == 0)
{
if (ptr != ((void *)0))
{
(void)parse(( &locals[26] ), ptr, 7);
if (lon)
{
print_val();
}
}
}
if (ptr != ((void *)0) && ptr != expr)
{
free_expr(ptr);
}
if ( get_com(cline, "{ ") || ( *( cline ) == 0x00 ) )
{
break;
}
p = cline;
}
while ( Expr_compile(&ptr, &p) );
memcpy( (void *)( set_err ), (const void *)( c_save_err ), ( sizeof ( jmp_buf ) ) );
}
static
TOKEN *
Evaluate(TOKEN const *const expr, const int e_type)
{
(void)parse(( &locals[26] ), (TOKEN *)expr, 7);
if (e_type == 0 && ( &locals[26] )->fp)
{
( &locals[26] )->opval.i = (long)( &locals[26] )->opval.r;
}
return ( &locals[26] );
}
static
void
print_size(const int recs)
{
if (recs <= 0)
{
say(" - empty.");
}
else
{
(void)fprintf( ((__w_FILE *)&__iob[2]), " - %d line%s.\n", recs, ( recs > 1 ? let_s : empty ) );
}
}
static
void
print_i_size(char const *const ftype, char const *const file, UNIT const *const fp)
{
(void)fprintf(((__w_FILE *)&__iob[2]), ps_name, ftype, ( *(unsigned int *)file == '-' ) ? si_file : file);
print_size( ( fp->eof_rec ) );
}
static
void
print_o_size(char const *const ftype, char const *const file, UNIT const *const fp)
{
(void)fprintf(((__w_FILE *)&__iob[2]), ps_name, ftype, ( *(unsigned int *)file == '-' ) ? so_file : file);
print_size( ( fp->rec_num ) );
}
static
void
c_comm_u(void)
{
FILE_LIST *const cptr = c_list->next;
UNIT *const old_c = comm_u;
comm_u = c_list->old_u;
c_list->next = f_free_list;
f_free_list = c_list;
c_list = cptr;
if (f_free_list->trans)
{
rlsevec(old_c);
--trans_open_count;
}
else
{
vsclose(old_c);
}
}
static
void
pop_flist(UNIT **const vs_u, const int fflag)
{
FILE_LIST *const t = f_list->next;
UNIT *const old_u = *vs_u;
*vs_u = f_list->old_u;
f_list->next = f_free_list;
f_free_list = f_list;
f_list = t;
if (fflag)
{
if (f_free_list->trans && old_u->read)
{
rlsevec(old_u);
}
else
{
vsclose(old_u);
}
}
}
static
FILE_LIST *
get_flist(void)
{
FILE_LIST *p;
if (f_free_list != ((void *)0))
{
p = f_free_list;
f_free_list = p->next;
}
else
{
p = ( FILE_LIST *)getvec(sizeof ( FILE_LIST ) );
p->save.in_rec_len = p->save.out_rec_len = 0;
}
return p;
}
static
void
new_input_file(VERB const *const opts, FILE_LIST **const f_stack, UNIT **const vs_u)
{
FILE_LIST *list, *fptr;
UNIT *temp_u;
const char *fn;
const int temp_file = ( opts->o1.v == 0 );
if (temp_file)
{
if (trans_u == ((void *)0))
{
g_err(51, opts->errp);
}
if (( trans_u->eof_rec ) == 0)
{
g_err(4, opts->errp);
}
++trans_open_count;
temp_u = ( UNIT *)getvec(sizeof ( UNIT ) );
*temp_u = *trans_u;
fn = t_fname;
}
else
{
int recs;
temp_u = vsopen();
if ( ( recs = Disk_to_mem(fn = opts->o1.s, temp_u, 'N') ) <= 0 )
{
vsclose(temp_u);
g_err(recs == 0 ? 4 : 39, opts->errp);
}
vsreopen(temp_u);
}
fptr = *f_stack;
*f_stack = list = get_flist();
if (fptr != ((void *)0))
{
fptr->prev = list;
}
list->next = fptr;
(void)strcpy( (void *)( list->name ), (const void *)( fn ) );
list->trans = (unsigned char)temp_file;
list->old_u = *vs_u;
*vs_u = temp_u;
}
static
void
Xit(VERB const *const opts)
{
int mode = opts->o1.q, recs, fflag = 1;
const int verbose = lon && !fscreen;
if (mode == 'U')
{
if (c_list == ((void *)0))
{
g_err(34, opts->errp);
}
c_comm_u();
return;
}
if (f_list == ((void *)0))
{
g_err(34, opts->errp);
}
if (mode == 0)
{
mode = f_list->disp;
}
switch (mode)
{
default:
g_err(8, opts->errp);
case 'T':
f_list->trans = 1;
(void)strcpy( (void *)( f_list->name ), (const void *)( t_fname ) );
case 'Q':
case 'A':
case 'S':
case 'N':
if (f_list->disp == 'M')
{
g_err(56, opts->errp);
}
if (mode == 'Q')
{
break;
}
if (e_col)
{
out_buff() ;
}
if (verbose)
{
print_o_size(ft_out, f_list->name, out_u);
}
vsreopen(out_u);
recs = ( out_u->eof_rec );
if (f_list->trans)
{
if (trans_open_count > 0)
{
g_err(52, opts->errp);
}
if (mode == 'A' && trans_u != ((void *)0))
{
const int trans_recs = ( trans_u->eof_rec );
vsreopen(trans_u);
vsseek(trans_u, trans_recs);
vscopy(trans_u, out_u, recs);
vsreopen(trans_u);
f_list->trans = 0;
}
else
{
if (trans_u != ((void *)0))
{
vsclose(trans_u);
}
trans_u = out_u;
fflag = 0;
}
}
else if(Mem_to_disk(out_u, f_list->name, f_list->disp) == (-1))
g_err(39, f_list->name);
break;
case 'M':
if (f_list->disp != 'M')
{
g_err(55, opts->errp);
}
if (f_list->trans)
{
--trans_open_count;
}
}
rest_in_vars(&f_list->save);
if (mode == 'M')
{
pop_flist(&in_u, fflag);
}
else
{
vsseek(in_u, f_list->save.in_rec_num);
rest_out_vars(&f_list->save);
pop_flist(&out_u, fflag);
}
save_all(&g_save);
}
static
void
Save(VERB const *const opts)
{
FILE_LIST *sptr;
const int mode = opts->o1.q, temp_file = opts->o1.v == 0;
switch (mode)
{
default:
g_err(9, opts->errp);
case 'Q':
Xit(opts);
break;
case 'A':
case 'N':
case '!':
sptr = get_flist();
if ( ( sptr->next = f_list ) != ((void *)0) )
{
f_list->prev = sptr;
}
sptr->disp = (char)mode;
sptr->trans = (unsigned char)temp_file;
(void)strcpy( (void *)( sptr->name ), (const void *)( temp_file ? t_fname : opts->o1.s ) );
save_all(&sptr->save);
sptr->old_u = out_u;
out_u = vsopen();
i_col = e_col = 0 ;
o_rec = -1;
f_list = sptr;
save_all(&g_save);
}
}
static
void
Merge(VERB const *const opts)
{
new_input_file(opts, &f_list, &in_u);
if (lon && !fscreen)
{
print_i_size(ft_merge, f_list->name, in_u);
}
f_list->disp = 'M';
save_all(&f_list->save);
save_all(&g_save);
g_eof = 0;
g_rec = -1;
(void)fill_buff();
}
static
void
Use(VERB const *const opts)
{
new_input_file(opts, &c_list, &comm_u);
lon = 0;
Drive(2);
}
static
int
strhex(char *s, unsigned int len)
{
const char *sp = s;
if (len & 01U)
{
(void)memmove( (void *)( s + 1 ), (const void *)( s ), ( ++len ) );
*s = '0';
}
while (*sp)
{
*s++ = xtoc(sp);
sp += 2;
}
*s = 0x00;
return len >> 1;
}
static
const char *
short_num(char *t, const char *p)
{
char def = '0';
char c = p[-1];
if ( ( g_map[c] & 010U ) )
{
c = '#';
--p;
}
switch (c)
{
case '+':
case '-':
++def;
case '#':
*t++ = 'T';
*t++ = c;
if ( ( g_map[*p] & 010U ) )
{
while ( ( g_map[*p] & 010U ) )
{
*t++ = *p++;
}
}
else
{
*t++ = def;
}
*t = 0x00;
break;
case '@':
(void)strcpy(t, "T#{@}");
}
return p;
}
static
void
short_str(char *t, const char *p)
{
switch (p[-1])
{
case '/':
if ( ( *( p ) == 0x00 ) )
{
*t++ = 'T';
*t++ = 0x20;
}
break;
case '?':
t = ( memcpy( (void *)( t ), (const void *)( "T#0 " ), 4), (void *)( (char *)( t ) + 4 ) );
break;
case '^':
--p;
}
(void)sprintf(t, se_fcom1, p);
}
static
const char *
num_ep(OPTION *const o, const char *p, char const *const erp)
{
if ( ( g_map[*p] & 010U ) )
{
o->v = 0;
while ( ( g_map[*p] & 010U ) )
{
o->v = o->v * 10 + *p++ - '0';
}
}
else if(*p++ == '{')
{
if ( Expr_compile(&o->e, &p) )
{
g_err(21, erp);
}
o->q |= 0x0100;
}
else
{
g_err(10, erp);
}
return p;
}
static
const char *
string_ep(OPTION *const o, const char *p, char const *const erp)
{
int len, hex = 0;
char *sp, c;
for (;;)
{
switch ( c = u_map[*( p++ )] )
{
default:
g_err(35, erp);
case 'X':
++hex;
continue;
case 'I':
o->q |= 0x0200;
continue;
case 'N':
o->q |= 0x0400;
continue;
case 'R':
case 'C':
case 'F':
case 'S':
if ( ( o->q & 0377U ) == 'G' && c == 'R' )
{
c = 'r';
}
o->q = ( o->q & ( 0377U << 8 ) ) | c;
continue;
case '/': case ':': case '=': case '?': case '$': case '%': case '&': case '+': case '>': case '<': case '[': case ']': case '\'': case '\"': case '`': case 0x7F:
if ( gdss(o->s, &len, &p) )
{
g_err(35, erp);
}
if (hex)
{
o->v = strhex(o->s, len);
}
else
{
o->v = len;
}
if (o->q & 0x0200)
{
for (sp = o->s; len--; ++sp)
{
*sp = u_map[*( sp )];
}
}
}
break;
}
return p;
}
static
const char *
ep(const char *p, OPTION *const o, const int d, char const *const erp)
{
int c2 = o->q;
const int neg = ( c2 == '-' );
if (neg || c2 == '+')
{
o->q = c2 = u_map[*( p++ )];
}
switch (c2)
{
default:
g_err(7, erp);
case '{':
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
o->q = neg ? 3 : 2;
return num_ep(o, --p, erp);
case '#':
o->q = 6;
return num_ep(o, p, erp);
case '*':
o->q = 5;
if (( g_map[*p] & 010U ) || *p == '{')
{
p = num_ep(o, p, erp);
}
else
{
o->v = -1;
}
break;
case 'O':
o->q = 4;
return num_ep(o, p, erp);
case 'S':
if (d)
{
o->v = neg;
break;
}
case 'I':
case 'X':
case 'F':
case 'N':
case 'C':
case 'R':
case '/': case ':': case '=': case '?': case '$': case '%': case '&': case '+': case '>': case '<': case '[': case ']': case '\'': case '\"': case '`': case 0x7F:
o->q = d ? 'G' : 'B';
return string_ep(o, --p, erp);
case 'E':
o->q = 1;
}
return p;
}
static
int
get_name(char const **const ptr, char *name)
{
int i = 0;
const char *p = *ptr;
if (*p == '!')
{
g_err(9, p);
}
switch (*p)
{
case 0x60:
case 0x27:
case 0x22:
case 0x7F:
++p;
(void)gdss(name, &i, &p);
break;
default:
for (; !( g_map[*p] & 02U ); ++p)
{
if (i > 2048)
{
continue;
}
name[i++] = *p;
}
name[i] = 0x00;
}
*ptr = p;
return i;
}
static
const char *
parse_G(const char *p, VERB *const opts)
{
int o_while = 0, c2 = opts->o1.q, c3;
char const *const erp = opts->errp;
const int c1 = opts->comm;
if (c2 == 0)
{
opts->o1.q = ( c1 == ')' ? 5 : 2 );
opts->o1.v = 1;
return p - 1;
}
switch (c1)
{
case 'L':
switch (c2)
{
case 'O':
if ( ( c3 = u_map[*( p )] ) == 'N' )
{
opts->o1.q = 7;
return p + 1;
}
if (c3 == 'F')
{
if (u_map[*( ++p )] == 'F')
{
opts->o1.q = 8;
return p + 1;
}
}
g_err(9, erp);
case 'H':
case 'M':
case 'X':
case 'D':
case 'S':
return p;
}
case 'K':
case 'J':
if (c2 == '.')
{
g_err(1, erp);
}
if (c1 == 'J' && c2 == 'P')
{
return p;
}
goto standard;
case 'T':
case 'P':
case 'V':
case ')':
standard:
if (c2 == 'W' || c2 == 'U')
{
o_while = c2 == 'W' ? 0x1000 : 0x2000;
c2 = opts->o1.q = u_map[*( p++ )];
}
if (c2 == '.')
{
opts->o1.q = 0;
--p;
}
else
{
p = ep(p, &opts->o1, 0, erp);
}
if (*p == '.')
{
if (opts->comm == ')' && c2 != '.')
{
g_err(1, erp);
}
opts->dot = 1;
++p;
if ( ( g_map[*p] & 02U ) )
{
g_err(9, erp);
}
opts->o2.q = u_map[*( p )];
p = ep(++p, &opts->o2, 1, erp);
}
if (opts->o2.q == 5)
{
opts->o1 = opts->o2;
opts->dot = 0;
}
opts->o1.q |= o_while;
}
return p;
}
static
const char *
parse_I(const char *p, VERB *const opts)
{
const char *dp, *const erp = opts->errp, c2 = (char)opts->o1.q;
switch (c2)
{
default:
g_err(9, erp);
case 'X':
p = ep(p, &opts->o1, 0, opts->errp);
opts->o1.q = 'X';
break;
case 'P':
if (opts->comm != 'D')
{
g_err(9, erp);
}
case 'D':
case 'F':
break;
case 'C':
if (*p++ != '{')
{
g_err(9, erp);
}
case '{':
if ( Expr_compile(&opts->o1.e, &p) )
{
g_err(21, erp);
}
break;
case '/': case ':': case '=': case '?': case '$': case '%': case '&': case '+': case '>': case '<': case '[': case ']': case '\'': case '\"': case '`': case 0x7F:
dp = --p;
do
{
++p;
while (*p != 0x00 && *p++ != c2)
{
;
}
}
while ( *p == c2 );
opts->o1.v = (int)( p - dp );
(void)memcpy( (void *)( opts->o1.s ), (const void *)( dp ), opts->o1.v ); opts->o1.s[opts->o1.v] = 0x00;;
}
return p;
}
static
const MACRO *
get_macro(char const *const name)
{
const MACRO *macptr;
if ( ( *( name ) == 0x00 ) )
{
g_err(23, ((void *)0));
}
for (macptr = mac_list; macptr != ((void *)0); macptr = macptr->next)
{
if ( ( strcmp(name, macptr->name) == 0 ) )
{
break;
}
}
return macptr;
}
static
void
Create(const char *s)
{
MACRO *m;
int arg_count, i;
char const *const erp = s;
char name[64 + 1], subs[3], subs_ch;
while ( ( ( *( s ) ) == 0x20 ) ) ++ ( s );
for (i = 0; ( g_map[*s] & ( 04U | 010U | 020U ) ); ++s)
{
if (i >= 64)
{
continue;
}
name[i++] = *s;
}
name[i] = 0x00;
++s;
if (gdss(subs, &i, &s) || i != 2)
{
g_err(25, erp);
}
subs_ch = subs[0];
if ( !( ( g_map[subs[1]] & 010U ) ) )
{
g_err(26, erp);
}
arg_count = subs[1] - '0';
while ( ( ( *( s ) ) == 0x20 ) ) ++ ( s );
if ( ( *( s ) == 0x00 ) )
{
g_err(27, erp);
}
m = ( MACRO *)getvec(sizeof ( MACRO ) );
m->next = mac_list;
(void)strcpy( (void *)( m->name ), (const void *)( name ) );
m->par_sub = subs_ch;
m->nargs = (unsigned char)arg_count;
m->text = (const char *)getvec( ( strlen(s) + 1 ) );
(void)strcpy( (void *)( (char *)m->text ), (const void *)( s ) );
if (c_list == ((void *)0) && get_macro(name) != ((void *)0))
{
(void)sprintf(name, "Warning: macro \"%s\" redefined", m->name);
inform(name);
}
mac_list = m;
}
static
const char *
dotcallmac(char *const text, const char *p)
{
int arg_count, i, arg_len[10];
char subs_ch, ch, *t_ptr;
const char *c_ptr, *args[10], *const erp = p - 1;
const MACRO *macptr;
while ( ( ( *( p ) ) == 0x20 ) ) ++ ( p );
for (i = 0; ( g_map[*p] & ( 04U | 010U | 020U ) ); ++p)
{
if (i >= 64)
{
continue;
}
text[i++] = *p;
}
text[i] = 0x00;
(void)memset( (char *)( args ), 0x00, ( 10 * sizeof ( char * ) >> 1 ) << 1 );
if ( ( macptr = get_macro(text) ) == ((void *)0) )
{
g_err(28, erp);
}
arg_count = macptr->nargs;
subs_ch = macptr->par_sub;
c_ptr = macptr->text;
if (( g_map[ch = *p] & 01U ) != arg_count > 0)
{
g_err(29, erp);
}
if (arg_count > 0)
{
for (i = 1; i <= arg_count; ++i)
{
if ( ( p = strchr(args[i] = ++p, ch) ) == ((void *)0) )
{
g_err(35, erp);
}
arg_len[i] = p - args[i];
}
++p;
t_ptr = text;
while ( ( ch = *c_ptr++ ) != 0x00 )
{
if (ch == subs_ch)
{
i = *c_ptr - '0';
if (i < 1 || i > 9 || args[i] == ((void *)0))
{
g_err(29, erp);
}
t_ptr = ( memcpy( (void *)( t_ptr ), (const void *)( args[i] ), arg_len[i]), (void *)( (char *)( t_ptr ) + arg_len[i] ) );
++c_ptr;
}
else
{
*t_ptr++ = ch;
}
if (t_ptr - text >= 2048)
{
g_err(32, erp);
}
}
*t_ptr = 0x00;
}
else
{
(void)strcpy( (void *)( text ), (const void *)( c_ptr ) );
}
return p;
}
static
int
endpoint(VERB **const prog, char const **const ptr)
{
VERB *opts;
int c1, c2;
char com;
const char *erp, *p = *ptr;
VERB_LIST *v;
string exp;
while (*p && ( ( ( *p ) == 0x20 ) || *p == ',' ) )
{
++p;
}
if (*p == 0x00)
{
return 0;
}
erp = p;
switch ( c1 = u_map[*( p++ )] )
{
case '#':
case '+':
case '-':
case '@':
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
p = short_num(exp, p);
goto comp;
case '/':
case '?':
case '^':
short_str(exp, p);
p = strchr(p, 0x00);
goto comp;
case '.':
p = dotcallmac(exp, p);
comp:
G_compile(prog, exp);
for (opts = *prog; opts != ((void *)0); opts = opts->next)
{
opts->errp = erp;
}
*ptr = p;
return 1;
case 'C':
Create(p);
return 0;
}
if (g_free_list != ((void *)0))
{
opts = g_free_list;
g_free_list = opts->next;
}
else
{
opts = ( VERB *)getvec(sizeof ( VERB ) );
}
opts->next = ((void *)0);
*prog = opts;
opts->errp = erp;
opts->comm = (char)c1;
opts->o1.q = c2 = ( ( g_map[*p] & 02U ) ? 0 : u_map[*( p )] );
opts->o2.q = 0;
opts->dot = 0;
opts->o1.e = opts->o2.e = ((void *)0);
switch (c1)
{
default:
g_err(22, erp);
case '(':
case ';':
v = par_stack_ptr->next;
if (v == ((void *)0))
{
v = par_stack_ptr->next = ( VERB_LIST *)getvec(sizeof ( VERB_LIST ) );
v->prev = par_stack_ptr;
v->next = ((void *)0);
}
v->prog = opts;
par_stack_ptr = v;
break;
case 'Y':
case 'A':
case 'B':
case 'R':
++p;
opts->o1.q = 'G';
if (c2 == 'R')
{
if (c1 == 'Y')
{
g_err(9, erp);
}
++p;
opts->o1.q = 'r';
}
if ( gdss(opts->o1.s, &opts->o1.v, &p)
|| gdss(opts->o2.s, &opts->o2.v, &p) )
{
g_err(35, erp);
}
if (c1 == 'Y' && opts->o1.v != opts->o2.v)
{
g_err(2, erp);
}
break;
case 'X':
if (c2 != 0)
{
++p;
}
break;
case 'F':
if (c2 != 0)
{
g_err(9, erp);
}
case 'Q':
case 'E':
case ':':
while ( ( g_map[*p] & ( 04U | 010U | 020U ) ) )
{
++p;
}
break;
case 'D':
case 'I':
p = parse_I(p + 1, opts);
break;
case 'S':
switch (c2)
{
default:
g_err(9, erp);
case 'A':
case 'N':
++p;
opts->o1.v = get_name(&p, opts->o1.s);
break;
case 'Q':
++p;
break;
case 0:
opts->o1.q = 'N';
opts->o1.v = 0;
}
break;
case 'O':
case 'M':
case 'U':
opts->o1.v = get_name(&p, opts->o1.s);
break;
case 'G':
--p;
opts->comm = '!';
goto copy_com;
case '!':
if (c2 == 0)
{
if ( ( p = getenv(shell_var) ) == ((void *)0) )
{
p = shell_bin;
}
}
copy_com:
(void)strcpy( (void *)( opts->o1.s ), (const void *)( p ) );
p = strchr(p, 0x00);
break;
case 'N':
case 'J':
opts->o1.v = 0;
c2 = *p;
while (( g_map[c2] & 010U ) || c2 == '-' || c2 == '.')
{
opts->o1.s[opts->o1.v++] = (char)c2;
c2 = *++p;
}
if (opts->o1.v > 4)
{
g_err(16, erp);
}
if ( ( g_map[c2] & 02U ) )
{
c2 = 'd';
}
else
{
++p;
}
opts->o2.v = c2;
break;
case ')':
do
{
if (par_stack_ptr == com_stack_ptr)
{
g_err(41, erp);
}
com = par_stack_ptr->prog->comm;
par_stack_ptr->prog->cpar = opts;
par_stack_ptr = par_stack_ptr->prev;
}
while ( com != '(' );
case 'P':
case 'T':
case 'V':
case 'L':
case 'K':
p = parse_G(p + 1, opts);
break;
case '{':
if ( Expr_compile(&opts->o1.e, &p) )
{
if (depth)
{
g_err(21, erp);
}
opts->o1.q = 4;
}
else
{
opts->o1.q = 3;
}
break;
case 'H':
p = strchr(p, 0x00);
}
*ptr = p;
return 1;
}
static
void
G_compile(VERB **start, const char *ptr)
{
VERB *v;
while ( endpoint(start, &ptr) )
{
for (v = *start; v->next != ((void *)0); v = v->next)
{
;
}
start = &v->next;
}
}
static
void
init_screen(void)
{
char **p, **last;
int lines;
(void)initscr();
;
;
;
lines = LINES;
p = s_buf = (char **)getvec( ( sizeof ( char * ) + 4 ) * lines );
last = p++ + lines;
while (p < last)
{
*p++ = (char *)getvec(76);
}
eor = (short *)p;
eor[2] = 0;
s_eor = eor + lines;
wfill(s_eor, 76, lines);
}
static
int
set_eor(const int line, const int nsize)
{
const int asize = s_eor[line];
if (nsize > 1022)
{
message("Line too long");
qq_loop = 0;
return 1;
}
if (nsize > asize)
{
char *const temp = s_buf[line];
s_buf[line] = (char *)getvec(s_eor[line] = (short)( nsize + 76 ));
(void)memcpy( (void *)( s_buf[line] ), (const void *)( temp ), ( asize ) );
rlsevec(temp);
}
eor[line] = (short)nsize;
return 0;
}
static
int
next_line(const int line)
{
int len;
const unsigned char *p;
if (in_stack != ((void *)0))
{
(void)set_eor( line, ( *(short *)( in_stack + 1 ) ) );
pop_line(&in_stack, s_buf[line]);
}
else
{
++g_rec;
if ( ( len = vsgetrec(in_u, &p) ) == (-1) )
{
g_eof = 1;
eor[line] = (-1);
return 0;
}
len = ltabex(e_buff, p, len);
(void)set_eor(line, len);
(void)memcpy( (void *)( s_buf[line] ), (const void *)( e_buff ), ( len ) );
}
return 1;
}
static
void
file_to_buf(const int com)
{
int line = 3;
switch (com)
{
case 4:
case 5:
case 6:
case 2:
case 7:
case 8:
if (!g_eof)
{
(void)set_eor(line, i_eor);
(void)memcpy( (void *)( s_buf[line++] ), (const void *)( i_buff ), ( i_eor ) );
}
}
do
{
if (line > last_line)
{
return;
}
}
while ( next_line(line++) );
--line;
wfill(&eor[line], (-1), LINES - line);
}
static
void
move_to(int line)
{
if (line <= g_rec || g_rec <= o_rec && o_rec >= line)
{
(void)wrapround();
}
if (( in_u->eof_rec ) > 0)
{
if (line < 0)
{
line = 0;
}
alter_end(line, 'T');
}
}
static
short curs_row, curs_col;
static
chtype * v_base = (chtype *)0xb8000000;
static
chtype * h_base, * t_base;
static
void
initscr(void)
{
unsigned char rows = ( *( (unsigned char *)0x484 ) );
const unsigned int cols = COLS = ( *( (unsigned short *)0x44A ) );
if (rows != 24)
{
if (rows == 0 || ( *( (unsigned short *)0x44C ) ) <= 4096)
{
rows = 24;
}
}
LINES = rows + 1;
if (( *( (unsigned short *)0x463 ) ) == 0x3B4)
{
v_base = (chtype *)0xb0000000;
}
last_line = rows;
text_lines = rows - ( 3 + 1 );
h_inc = cols >> 1;
last_col = cols - 1;
t_base = ( h_base = v_base + cols ) + cols;
}
static
void
clrtoeol(void)
{
wfill(v_base + curs_row * COLS + curs_col, 0x0A20, COLS - curs_col);
}
static
void
bios_gotoxy(const unsigned char row, const unsigned char col)
{
union REGS regs;
regs.h.ah = 0x02;
regs.h.bh = 0;
regs.h.dh = row;
regs.h.dl = col;
int86(0x10, &regs, &regs);
}
static
unsigned short
curs_getc(void)
{
bios_gotoxy( (unsigned char)curs_row, (unsigned char)curs_col );
{
const unsigned short c = _bios_keybrd(0);
if (c & 0xFF)
{
return c & 0xFF;
}
return c;
}
}
static
void
deleteln(void)
{
chtype *const curs_y = v_base + curs_row * COLS;
(void)memcpy( (void *)( curs_y ), (const void *)( curs_y + COLS ), ( ( last_line - curs_row ) * COLS ) << 1 );
}
static
void
insertln(void)
{
chtype *const curs_y = v_base + curs_row * COLS;
(void)memmove( (void *)( curs_y + COLS ), (const void *)( curs_y ), ( ( last_line - curs_row ) * COLS ) << 1 );
wfill(curs_y, 0x0A20, COLS);
}
static
void
curs_chins(void)
{
chtype *const p = v_base + curs_row * COLS + curs_col;
(void)memmove( (void *)( p + 1 ), (const void *)( p ), ( last_col - curs_col ) << 1 );
}
static
void
napms(const unsigned long msec)
{
const clock_t goal = clock() + ( msec * 1000 ) / 1000;
while ( goal > clock() )
{
;
}
}
static
void
put_byte(const chtype c)
{
( v_base + curs_row * COLS )[curs_col++] = c | 0x1F00;
}
static
void
mv_put_byte(const int y, const int x, const chtype c)
{
v_base[y * COLS + x] = c | 0x1F00;
}
static
void
put_seq(const char *s, int n, chtype attr)
{
chtype *const curs_y = v_base + curs_row * COLS;
while (n--)
{
curs_y[curs_col++] = *s++ | attr;
}
}
static
void
cput_seq(const char *s, int n, chtype attr_print, chtype attr_cntrl)
{
chtype *const curs_y = v_base + curs_row * COLS;
while (n--)
{
const chtype c = *s++;
if ( ( c >= 0x20 && c < 0x7F ) )
{
curs_y[curs_col++] = c | attr_print;
}
else
{
curs_y[curs_col++] = toprint(c) | attr_cntrl;
}
}
}
static
void
put_text(const char *s, int len, int rem)
{
if (len > rem)
{
len = rem;
}
if (len > 0)
{
cput_seq(s, len, 0x0A00, 0x1F00);
}
if (len < rem)
{
(void)clrtoeol();
}
}
static
void
set_col(int new_col)
{
if (new_col <= 0)
{
col = offset = 0;
return;
}
if (new_col > 1022)
{
new_col = 1022;
}
col = new_col - offset;
if (col < 0 || col > last_col)
{
offset = new_col - new_col % h_inc - h_inc;
if (offset < 0)
{
offset = 0;
}
col = new_col - offset;
}
}
static
void
disp_eof(const int r)
{
(void)( curs_row = ( r ), curs_col = ( 0 ) );
put_seq(eof_mess, 29, 0x0F00);
;
(void)clrtoeol();
}
static
void
disp_template(void)
{
int i, len;
char buf[4];
string scale;
char *p = scale;
char const *const last = p + COLS;
(void)memset(p, '.', COLS);
for (i = 5; i < COLS; i += 10)
{
p[i] = '+';
}
for (i = offset; p < last; i += 10, p += 10)
{
len = sprintf(buf, "%d", i / 10);
(void)memcpy( (void *)( p ), (const void *)( buf ), ( len ) );
}
(void)( curs_row = ( 2 ), curs_col = ( 0 ) );
put_seq(scale, COLS, 0x0E00);
;
}
static
void
disp_rest(void)
{
const unsigned short f_col = ( col + offset );
(void)( curs_row = ( row ), curs_col = ( col ) );
put_text(( &s_buf[row][f_col] ), eor[row] - f_col, COLS - col);
}
static
void
disp_line(void)
{
(void)( curs_row = ( row ), curs_col = ( 0 ) );
put_text(( &s_buf[row][offset] ), eor[row] - offset, COLS);
}
static
void
disp_matched_text(const int m_row, const int m_col, int m_len)
{
if (m_len > COLS - m_col)
{
m_len = COLS - m_col;
}
if (m_len > 0)
{
(void)( curs_row = ( m_row ), curs_col = ( m_col ) );
cput_seq(s_buf[m_row] + m_col + offset, m_len, 0x4F00, 0x4900);
}
}
static
void
disp_row(const int r)
{
if (eor[r] == (-1))
{
if (r == 3 || eor[r - 1] != (-1))
{
disp_eof(r);
}
else
{
wfill(v_base + r * COLS, 0x0A20, COLS);
}
}
else
{
const int c_row = row;
row = r;
disp_line();
row = c_row;
}
}
static
void
disp_home(void)
{
(void)( curs_row = ( 1 ), curs_col = ( 0 ) );
put_text(s_buf[1] + offset, eor[1] - offset, COLS);
}
static
void
disp_text(void)
{
int i;
for (i = 3; i < LINES && eor[i] != (-1); ++i)
{
(void)( curs_row = ( i ), curs_col = ( 0 ) );
put_text(s_buf[i] + offset, eor[i] - offset, COLS);
}
if (i < LINES)
{
disp_eof(i);
while (++i < LINES)
{
(void)( curs_row = ( i ), curs_col = ( 0 ) );
(void)clrtoeol();
}
}
}
static
void
del_seg(const int end_col)
{
const int first_col = ( col + offset ), gap = end_col - first_col;
char *const p = ( &s_buf[row][first_col] );
(void)memcpy( (void *)( p ), (const void *)( p + gap ), ( eor[row] - end_col ) );
eor[row] -= gap;
disp_rest();
}
static
void
status(void)
{
static int pos_len = 0, eor_start = ( 1022 + 2 ), eof_start = 0;
int len, eol, new_eor;
const int fcol = ( col + offset ), sop = ( o_rec + 1 );
char buf[76], *p = buf;
if (row == 1)
{
p += sprintf(buf, "%d", sop);
eol = eor[3];
}
else
{
p += sprintf(buf, line_pos + 5, ( ( o_rec + 1 ) + row - 3 ), fcol);
if ( ( eol = eor[row] ) == (-1) )
{
p = ( memcpy( (void *)( p ), (const void *)( " (EOF" ), 5), (void *)( (char *)( p ) + 5 ) );
}
else if(eol > fcol)
p += sprintf(p, " (%02X", s_buf[row][fcol] & 0377U);
else
{
p = ( memcpy( (void *)( p ), (const void *)( " (EOR" ), 5), (void *)( (char *)( p ) + 5 ) );
}
*p++ = ')';
}
len = p - buf;
if (len < pos_len)
{
(void)memset( (char *)( p ), 0x20, pos_len - len );
len = pos_len;
}
pos_len = len;
(void)( curs_row = ( 0 ), curs_col = ( 5 ) );
put_seq(buf, len, 0x0B00);
for (len = last_line; eor[len] == (-1); --len)
{
;
}
len = ( ( in_u->eof_rec ) - ( in_u->rec_num ) ) + sop + in_count
+ ( len - 2 );
if (len != se_save_eof)
{
len = sprintf(buf, " EOF %d", se_save_eof = len);
eof_start = COLS - len;
(void)( curs_row = ( 0 ), curs_col = ( eof_start ) );
put_seq(buf, len, 0x0B00);
}
new_eor = eof_start;
if (eol != (-1))
{
new_eor -= ( len = sprintf(buf, "EOR %d", eol) );
(void)( curs_row = ( 0 ), curs_col = ( new_eor ) );
put_seq(buf, len, 0x0B00);
}
len = new_eor - eor_start;
if (len > 0)
{
wfill(v_base + eor_start, 0x0A20, len);
}
eor_start = new_eor;
v_base[h_inc] = ( expand ? 'I' : 'O' ) | 0x0B00;
}
static
void
init(void)
{
int len;
string buf;
char *const mid = buf + h_inc + 4;
const char *p, *last;
(void)memset( (char *)( buf ), 0x20, COLS );
(void)memcpy( (void *)( buf ), (const void *)( "LINE" ), ( 4 ) );
se_save_eof = -1;
p = last = strchr(in_fname, 0x00);
while ( p > in_fname && !( p[-1] == 0x2F || p[-1] == 0x5C ) )
{
--p;
}
if (p == last)
{
p = out_fname;
}
if ( ( len = last - p ) > 15)
{
len = 15;
}
(void)memcpy( (void *)( mid - 8 - len ), (const void *)( p ), ( len ) );
p = last = strchr(out_fname, 0x00);
while ( p > out_fname && !( p[-1] == 0x2F || p[-1] == 0x5C ) )
{
--p;
}
if (p == last)
{
p = out_fname;
}
if ( ( len = last - p ) > 15 )
{
len = 15;
}
(void)memcpy( (void *)( mid ), (const void *)( p ), ( len ) );
(void)memcpy( (void *)( mid - 6 ), (const void *)( ">GI>" ), ( 4 ) );
(void)( curs_row = ( 0 ), curs_col = ( 0 ) );
put_seq(buf, COLS, 0x0B00);
++fscreen;
status();
disp_home();
disp_template();
disp_text();
(void)( curs_row = ( row ), curs_col = ( col ) );
redisplay = 0;
}
static
void
linewrap(void)
{
if (e_col + i_col)
{
char *const t = e_buff;
get_end();
e_buff = i_buff;
i_buff = t;
i_eor = e_col;
e_col = i_col = 0;
loc2 = ((void *)0);
}
}
static
int
home_command(const int disp, const int s_start)
{
const int sop = ( o_rec + 1 );
int rc = 0;
buf_to_file(9);
(void)move_to(s_start);
lon = disp == 1;
;
if ( _setjmp(set_err) )
{
(void)move_to(sop);
rc = 1;
}
else
{
Drive(disp);
}
;
memcpy( (void *)( set_err ), (const void *)( save_err ), ( sizeof ( jmp_buf ) ) );
if (f_list != ((void *)0))
{
term();
g_err(30, cmd_buf);
}
lon = 0;
if (!g_eof)
{
linewrap();
}
file_to_buf(8);
if (redisplay)
{
if (redisplay == 2)
{
wait_user();
}
init();
}
else
{
int m_row, m_col = -1;
if (loc2 != ((void *)0))
{
m_row = l2rec - ( o_rec + 1 ) + 3;
if (m_row >= 3 && m_row <= last_line && eor[m_row] != (-1))
{
const int c_col = col, c_offset = offset;
set_col( (int)( loc1 - i_buff ) );
if (offset != c_offset)
{
disp_template();
last_offset = offset;
}
m_col = col;
if (row == 1)
{
col = c_col;
}
}
}
disp_text();
if (m_col >= 0)
{
disp_matched_text( m_row, m_col, (int)( loc2 - loc1 ) );
}
loc2 = ((void *)0);
}
return rc;
}
static
int
run_command(char const *const com, const int f_rec, const int s_rec)
{
string cline;
if (s_rec)
{
(void)sprintf(cline, "%s,T#%d", com, ( o_rec + 1 ));
}
else
{
(void)sprintf(cline, "%s,T%d", com, -( ( row == 1 ? text_row : row ) - 3 ));
}
cmd_buf = cline;
return home_command(3, ( ( o_rec + 1 ) + ( ( row == 1 ? text_row : row ) - 3 ) ) + f_rec);
}
static
int
get_key2(int *const value)
{
int c = curs_getc();
if (c <= 0xFF)
{
if ( ( c = u_map[c] ) < 0x20 )
{
c += 0x40;
}
}
*value = c;
return c;
}
static
ACTION
hand_quick(int *const value)
{
switch ( get_key2(value) )
{
case 0x7F:
case 0x5300:
*value = 1;
return A_DEL_REST;
case 'A':
case 'F':
case 'I':
return A_SEARCH;
case 'B':
*value = 'Q';
return A_JUSTIFY;
case 'C':
*value = 6;
return A_FILE_MOVE;
case 'D':
return A_C_EOL;
case 'E':
return A_C_TOS;
case 'G':
*value = curs_getc();
return A_FINDC;
case 'H':
*value = 'Q';
return A_C_HOME;
case 'J':
return A_HELP;
case 'K':
return A_HIST;
case 'Q':
*value = 0;
return A_REPEAT;
case 'V':
*value = -1;
return A_FINDC;
case 'W':
*value = 2;
return A_REPEAT;
case 'Z':
*value = 1;
return A_REPEAT;
case 'R':
*value = 5;
return A_FILE_MOVE;
case 'S':
return A_C_SOL;
case 'X':
return A_C_BOS;
case 'Y':
*value = 2;
return A_DEL_REST;
}
return A_C_STAY;
}
static
ACTION
hand_block(int *const value)
{
const int c = get_key2(value);
if ( ( g_map[c] & 0200U ) )
{
return A_RWX_FILE;
}
if (strchr("CBK", c) != ((void *)0))
{
return A_BLOCK;
}
if (c == 'H')
{
return A_C_HOME;
}
if (strchr("QXSD", c) != ((void *)0))
{
return A_EXIT_EDITOR;
}
if ( ( g_map[c] & 040U ) )
{
return A_MISC_CE;
}
if (c == 'Z')
{
return A_REDRAW;
}
return A_C_STAY;
}
static
ACTION
get_seq(int *const value)
{
const int c = curs_getc();
switch (c)
{
case ( 'A' & 037U ):
*value = 0;
return A_W_LEFT;
case ( 'B' & 037U ):
*value = 1;
return A_W_LEFT;
case ( 'C' & 037U ):
case 0x5100:
*value = 3;
return A_FILE_MOVE;
case ( 'D' & 037U ):
case 0x4D00:
return A_C_RIGHT;
case ( 'E' & 037U ):
case 0x4800:
return A_C_UP;
case ( 'F' & 037U ):
*value = 0;
return A_W_RIGHT;
case ( 'G' & 037U ):
case 0x5300:
case 0x7F:
*value = 2;
return A_DEL_C;
case ( 'H' & 037U ):
*value = 1;
return A_DEL_C;
case ( 'I' & 037U ):
return A_H_TAB;
case ( 'J' & 037U ):
return A_YANK;
case ( 'L' & 037U ):
*value = 'L';
return A_SEARCH;
case ( 'P' & 037U ):
*value = ( curs_getc() & 037U );
return A_CHARACTER;
case ( 'M' & 037U ):
return A_C_RETURN;
case ( 'N' & 037U ):
return A_OPEN_LINE;
case ( 'R' & 037U ):
case 0x4900:
*value = 4;
return A_FILE_MOVE;
case ( 'S' & 037U ):
case 0x4B00:
return A_C_LEFT;
case ( 'T' & 037U ):
*value = 1;
return A_W_RIGHT;
case ( 'U' & 037U ):
return A_REST_LINE;
case ( 'V' & 037U ):
case 0x5200:
return A_EXP_MODE;
case ( 'W' & 037U ):
*value = 2;
return A_FILE_MOVE;
case ( 'X' & 037U ):
case 0x5000:
return A_C_DOWN;
case ( 'Y' & 037U ):
return A_DEL_LINE;
case ( 'Z' & 037U ):
*value = 1;
return A_FILE_MOVE;
case 0x4F00:
return A_C_EOL;
case 0x0F00:
return A_B_TAB;
case ( ( 0x3A + ( 1 ) ) << 8 ):
return A_HELP;
case ( ( 0x3A + ( 2 ) ) << 8 ):
*value = 'B';
return A_BLOCK;
case ( ( 0x3A + ( 3 ) ) << 8 ):
*value = 'K';
return A_BLOCK;
case ( ( 0x3A + ( 4 ) ) << 8 ):
*value = 'C';
return A_BLOCK;
case ( ( 0x3A + ( 5 ) ) << 8 ):
*value = 'R';
return A_RWX_FILE;
case ( ( 0x3A + ( 6 ) ) << 8 ):
*value = 'W';
return A_RWX_FILE;
case ( ( 0x3A + ( 7 ) ) << 8 ):
case 0x1B:
*value = 'Q';
return A_EXIT_EDITOR;
case ( ( 0x3A + ( 8 ) ) << 8 ):
*value = 'X';
return A_EXIT_EDITOR;
case ( ( 0x3A + ( 9 ) ) << 8 ):
return A_HIST;
case ( ( 0x3A + ( 10 ) ) << 8 ):
*value = 'S';
return A_EXIT_EDITOR;
case 0x4700:
*value = 'Q';
return A_C_HOME;
case 0x7300:
*value = 1;
return A_PAGE_SHIFT;
case 0x7400:
*value = 2;
return A_PAGE_SHIFT;
case ( 'Q' & 037U ):
return hand_quick(value);
case ( 'O' & 037U ):
if ( ( g_map[get_key2(value)] & 0100U ) )
{
return A_JUSTIFY;
}
return A_C_STAY;
case ( 'K' & 037U ):
return hand_block(value);
default:
if ( ( c >= 0x20 && c < 0x7F ) )
{
*value = c;
return A_CHARACTER;
}
return A_C_STAY;
}
}
static
void
scroll_up(const int line)
{
char *const p = s_buf[line];
const short e = s_eor[line];
const int dist = last_line - line;
(void)( curs_row = ( line ), curs_col = ( 0 ) );
deleteln();
(void)
memcpy( (void *)( &s_buf[line] ), (const void *)( &s_buf[line + 1] ), ( dist * ( sizeof ( char * ) >> 1 ) ) << 1 );
(void)memcpy( (void *)( &s_eor[line] ), (const void *)( &s_eor[line + 1] ), ( dist ) << 1 );
(void)memcpy( (void *)( &eor[line] ), (const void *)( &eor[line + 1] ), ( dist ) << 1 );
s_buf[last_line] = p;
s_eor[last_line] = e;
}
static
void
scroll_down(const int line)
{
char *const p = s_buf[last_line];
const short e = s_eor[last_line];
const int dist = last_line - line;
insertln();
(void)
memmove( (void *)( &s_buf[line + 1] ), (const void *)( &s_buf[line] ), ( dist * ( sizeof ( char * ) >> 1 ) ) << 1 );
(void)memmove( (void *)( &s_eor[line + 1] ), (const void *)( &s_eor[line] ), ( dist ) << 1 );
(void)memmove( (void *)( &eor[line + 1] ), (const void *)( &eor[line] ), ( dist ) << 1 );
s_buf[line] = p;
s_eor[line] = e;
}
static
void
file_move(int value)
{
const int sop = ( o_rec + 1 );
int dest;
if (value <= 0)
{
dest = -value;
value = 7;
}
switch (value)
{
case 1:
if (eor[3] == (-1))
{
return;
}
break;
case 3:
if (eor[last_line] == (-1))
{
return;
}
break;
case 6:
if (eor[last_line] == (-1))
{
for (row = last_line; row > 3 && eor[row] == (-1); --row)
{
;
}
set_col(eor[row]);
return;
}
break;
case 5:
row = 3;
col = offset = 0;
case 2:
case 4:
if (sop == 0)
{
return;
}
}
buf_to_file(value);
switch (value)
{
case 1:
scroll_up(3);
(void)next_line(last_line);
disp_row(last_line);
return;
case 2:
(void)move_to(sop - 1);
(void)( curs_row = ( 3 ), curs_col = ( 0 ) );
insertln();
break;
case 4:
(void)move_to(sop - text_lines);
break;
case 5:
(void)wrapround();
break;
case 6:
(void)move_to(( in_u->eof_rec ) - ( LINES - 6 ) );
break;
case 7:
(void)move_to(dest);
}
file_to_buf(value);
if (value == 6)
{
for (row = last_line; eor[row - 1] == (-1); --row)
{
;
}
col = offset = 0;
}
if (value == 2)
{
disp_row(3);
}
else
{
disp_text();
}
}
static
void
c_home(const int value)
{
if (row == 1)
{
row = text_row;
set_col(text_col + text_offset);
}
else
{
text_row = row, text_col = col, text_offset = offset;
if (value == 'H')
{
file_move(-( ( o_rec + 1 ) + row - 3 ));
}
col = eor[row = 1], offset = 0;
while (col > 0 && s_buf[1][col - 1] == 0x20)
{
--col;
}
eor[1] = (short)col;
set_col(col);
}
}
static
void
c_up(void)
{
if (row <= 3)
{
if (( o_rec + 1 ) > 0)
{
file_move(2);
}
}
else
{
--row;
}
}
static
void
c_down(void)
{
if (row == 1)
{
text_row = 3, text_col = col;
c_home('Q');
}
else if(row == last_line)
{
if (eor[6] != (-1))
{
file_move(1);
}
}
else
{
++row;
}
}
static
void
del_line(void)
{
if (eor[row] == (-1))
{
return;
}
scroll_up(row);
(void)next_line(last_line);
disp_row(last_line);
}
static
int
se_join(const int del)
{
int len, nrow = row + 1;
const int j_col = ( col + offset ), o_eor = eor[row];
char *bs, *nbs;
if (row == 1)
{
return 1;
}
if (row == last_line)
{
(void)next_line(2);
nrow = 2;
}
if ( ( len = eor[nrow] ) == (-1) )
{
return 1;
}
nbs = bs = s_buf[nrow];
if (del)
{
while ( len && ( ( *nbs ) == 0x20 ) )
{
--len, ++nbs;
}
}
if (j_col == 0 && bs == nbs)
{
(void)del_line();
return 0;
}
if ( set_eor(row, j_col + len) )
{
if (row == last_line)
{
push_line(&in_stack, s_buf[2], len);
}
return 1;
}
bs = ( &s_buf[row][0] );
if (j_col > o_eor)
{
(void)memset( (char *)( bs + o_eor ), 0x20, j_col - o_eor );
}
(void)memcpy( (void *)( bs + j_col ), (const void *)( nbs ), ( len ) );
disp_rest();
;
if (nrow != 2)
{
++row;
(void)del_line();
--row;
}
return 0;
}
static
int
is_sow(char const *const p)
{
const char c = *p;
if ( p == ( &s_buf[row][0] ) )
{
return ( g_map[c] & ( 04U | 010U | 020U ) ) || ( !( ( g_map[c] & ( 04U | 010U | 020U ) ) || ( ( c ) == 0x20 ) ) );
}
return ( g_map[c] & ( 04U | 010U | 020U ) ) && !( g_map[p[-1]] & ( 04U | 010U | 020U ) ) || ( !( ( g_map[c] & ( 04U | 010U | 020U ) ) || ( ( c ) == 0x20 ) ) ) && !( !( ( g_map[p[-1]] & ( 04U | 010U | 020U ) ) || ( ( p[-1] ) == 0x20 ) ) );
}
static
int
find_forwards(char const *const target, const int del)
{
const int j_col = ( col + offset );
const char *p = ( &s_buf[row][j_col + 1] ), *e;
while (eor[row] != (-1))
{
for (e = ( &s_buf[row][eor[row]] ); p < e; ++p)
{
if (target != ((void *)0))
{
if (strchr(target, *p) != ((void *)0))
{
break;
}
}
else if( is_sow(p) )
break;
}
if (p < e)
{
char const *const s = ( &s_buf[row][0] );
if (del)
{
del_seg( (int)( p - s ) );
}
else
{
set_col( (int)( p - s ) );
}
return *p;
}
if (del)
{
if (se_join(1) || j_col < eor[row])
{
break;
}
p = ( &s_buf[row][j_col] );
}
else
{
if (row == 1 || row == last_line && target != ((void *)0))
{
break;
}
c_down();
col = offset = 0;
p = ( &s_buf[row][0] );
}
}
return (-1);
}
static
int
find_backwards(char const *const target, const int del)
{
char *p, *e;
int end_col, j_col;
for (;;)
{
j_col = --col + offset;
if (j_col >= eor[row])
{
set_col(eor[row] - 1);
}
end_col = j_col + 1;
if (eor[row] > 0)
{
for (e = ( &s_buf[row][0] ), p = e + j_col; p >= e; --p)
{
if (target != ((void *)0))
{
if (strchr(target, *p) != ((void *)0))
{
break;
}
}
else if( is_sow(p) )
break;
}
if (p >= e)
{
set_col( (int)( p - e ) );
if (del)
{
del_seg(end_col);
}
return *p;
}
}
if (row == 1 || row == 3 && target != ((void *)0))
{
break;
}
if (del)
{
col = offset = 0;
del_seg(end_col);
}
if (( ( o_rec + 1 ) + row - 3 ) <= 0)
{
break;
}
c_up();
set_col(eor[row]);
if (del)
{
(void)se_join(0);
}
}
col = offset = 0;
return (-1);
}
static
void
find_char(const int value)
{
char target, find_str[3];
int forwards = 1, count, found;
if ( value == ( 'M' & 037U ) )
{
if (row != 1)
{
while (eor[row] > 0)
{
c_down();
}
}
return;
}
if (value > 0)
{
find_str[0] = (char)value;
find_str[1] = 0x00;
if (find_forwards(find_str, 0) == (-1))
{
message("Character not found on screen");
}
return;
}
target = find_str[0] = *( &s_buf[row][col + offset] );
switch (target)
{
case '\'':
case '"':
case '`':
case '/':
find_str[1] = 0x00;
while (find_forwards(find_str, 0) != (-1))
{
if (( col + offset ) > 0 && *( &s_buf[row][( col + offset ) - 1] ) != 0x5C)
{
break;
}
}
return;
default:
(void)find_forwards(endsent, 0);
return;
case '(':
case '{':
case '[':
case '<':
find_str[1] = xlat(target, bra_start, (const unsigned char *)bra_end);
break;
case ')':
case '}':
case ']':
case '>':
find_str[1] = xlat(target, bra_end, (const unsigned char *)bra_start);
forwards = 0;
}
find_str[2] = 0x00;
count = 1;
while (count > 0)
{
if (forwards)
{
found = find_forwards(find_str, 0);
}
else
{
found = find_backwards(find_str, 0);
}
if (found == (-1))
{
break;
}
if (found == find_str[1])
{
if (--count == 0)
{
break;
}
}
else
{
++count;
}
}
}
static
void
term(void)
{
if (!fscreen)
{
return;
}
(void)wfill(v_base, 0x0720, LINES * COLS);
;
fscreen = 0;
(void)bios_gotoxy( (unsigned char)( LINES - 2 ), 0 );
lon = redisplay = 2;
}
static
void
Help(void)
{
char const *const *const text = hw_mess;
int line = 0;
term();
do
{
new_line();
say(text[line++]);
wait_user();
new_line();
}
while ( text[line] != ((void *)0) );
redisplay = 1;
}
static
void
wmessage(const char *text)
{
const int max_len = COLS - 8;
int i, ymax, xmax, lines, cols, begy, begx, longest = 26;
const char *p, *start;
for (lines = 5, start = p = text; *p; ++lines, start = p + 1)
{
if ( ( p = strchr(start, 0x0A) ) == ((void *)0) )
{
p = strchr(start, 0x00);
}
if (p - start > longest)
{
longest = p - start;
}
}
if (longest > max_len)
{
longest = max_len;
}
cols = longest + 8;
begx = ( COLS - cols ) / 2;
begy = ( LINES - lines ) / 2;
;
ymax = lines - 1, xmax = cols - 1;
for (i = 1; i <= xmax - 1; ++i)
{
(void)mv_put_byte(begy, i + begx, 0xC4);
(void)mv_put_byte(ymax + begy, i + begx, 0xC4);
}
for (i = 1; i <= ymax - 1; ++i)
{
(void)mv_put_byte(i + begy, begx, 0xB3);
(void)mv_put_byte(i + begy, xmax + begx, 0xB3);
}
(void)mv_put_byte(begy, begx, 0xDA);
(void)mv_put_byte(begy, xmax + begx, 0xBF);
(void)mv_put_byte(ymax + begy, begx, 0xC0);
(void)mv_put_byte(ymax + begy, xmax + begx, 0xD9);
for (i = 1; i < lines - 1; ++i)
{
int j;
(void)( curs_row = ( begy + i ), curs_col = ( begx + 1 ) );
for (j = 0; j < cols - 2; ++j)
{
(void)put_byte(0x20);
}
}
for (i = 2, start = p = text; *p; ++i, ++start)
{
if ( ( p = strchr(start, 0x0A) ) == ((void *)0) )
{
p = strchr(start, 0x00);
}
(void)( curs_row = ( i + begy ), curs_col = ( 4 + begx ) );
while (start < p)
{
(void)put_byte(*start++);
}
}
(void)( curs_row = ( i + 1 + begy ), curs_col = ( 4 + begx ) );
for (p = se_hit + 2; *p; ++p)
{
(void)put_byte(*p);
}
(void)curs_getc();
;
}
static
void
message(char const *const text)
{
wmessage(text);
disp_text();
}
static
void
inform(char const *const mess)
{
if (fscreen)
{
;
wmessage(mess);
}
else
{
new_line();
say(mess);
new_line();
}
}
static
void
se_error(const int code)
{
string buf;
err_print(buf, code, "");
message(buf);
disp_home();
longjmp(se_err, 1);
}
static
int
shift_right(void)
{
if (offset + h_inc + last_col > 1022)
{
return 0;
}
offset += h_inc;
col -= h_inc;
return 1;
}
static
int
shift_left(void)
{
if (offset - h_inc < 0)
{
return 0;
}
offset -= h_inc;
col += h_inc;
return 1;
}
static
void
set_eof(void)
{
int i;
if (row == 1)
{
return;
}
for (i = row - 1; eor[i] == (-1); --i)
{
eor[i] = 0;
}
(void)( curs_row = ( i + 1 ), curs_col = ( 0 ) );
(void)clrtoeol();
if (row < last_line)
{
disp_eof(row + 1);
}
(void)( curs_row = ( row ), curs_col = ( col ) );
}
static
void
page_shift(const int value)
{
const int c_col = col;
if (value == 2)
{
col += h_inc;
if ( !( shift_right() ) )
{
col = c_col;
}
}
else
{
col -= h_inc;
if ( !( shift_left() ) )
{
col = c_col;
}
}
}
static
void
block(const int value)
{
static int save_b_len = 0, start_col, end_col, save_len = (-1),
start_rec = (-1), end_rec = (-1), block_mode = 0;
static char *save_buf;
const int b_col = ( col + offset ), c_eor = eor[row], sop = ( o_rec + 1 ),
c_line = sop + ( row - 3 );
char *a, com[32];
int start, len, end_row;
if (value != 'C')
{
if (row == 1 || c_eor == (-1) && eor[row - 1] == (-1))
{
return;
}
disp_home();
disp_text();
}
switch (value)
{
case 'B':
start_rec = c_line;
start_col = b_col;
if (end_rec != c_line && save_len != (-1) && !block_mode)
{
end_rec = (-1);
}
if (end_rec == (-1))
{
return;
}
break;
case 'K':
end_rec = c_line;
end_col = b_col;
if (start_rec == (-1))
{
return;
}
break;
case 'C':
if (save_len == (-1))
{
message("No saved block");
return;
}
start_rec = end_rec = (-1);
if (block_mode)
{
if (row != 1)
{
(void)sprintf(com, "T#%d, m te x", c_line);
(void)run_command(com, -c_line, 1);
}
return;
}
if ( set_eor(row, ( c_eor > b_col ? c_eor : b_col ) + save_len) )
{
return;
}
a = ( &s_buf[row][b_col] );
if (b_col >= c_eor)
{
if (c_eor == (-1))
{
set_eof();
}
(void)memset( (char *)( ( &s_buf[row][c_eor] ) ), 0x20, b_col - c_eor );
}
else
{
(void)memmove( (void *)( a + save_len ), (const void *)( a ), ( c_eor - b_col ) );
}
(void)memcpy( (void *)( a ), (const void *)( save_buf ), ( save_len ) );
disp_rest();
return;
}
if (start_rec != end_rec)
{
if (end_rec < start_rec)
{
len = end_rec;
end_rec = start_rec;
start_rec = len;
}
save_len = end_rec - start_rec;
block_mode = 1;
(void)sprintf(com, "T#%d S T#%d X", start_rec, end_rec);
(void)run_command(com, -c_line, 1);
if (start_rec < sop)
{
start = 3;
}
else
{
start = start_rec - sop + 3;
}
if (end_rec > sop + text_lines)
{
end_row = LINES;
}
else
{
end_row = end_rec - sop + 3;
}
for (; start < end_row; ++start)
{
len = eor[start] - offset;
if (len > 0)
{
disp_matched_text(start, 0, len);
}
else
{
v_base[start * COLS] = 0x20 | 0x4F00;
}
}
return;
}
block_mode = 0;
if (end_col < start_col)
{
len = end_col;
end_col = start_col;
start_col = len;
}
save_len = end_col - start_col;
if (save_b_len < save_len)
{
rlsevec(save_buf);
save_buf = (char *)getvec(save_b_len = save_len);
}
if (end_col > c_eor)
{
(void)set_eor(row, end_col);
eor[row] = (short)c_eor;
(void)memset( (char *)( ( &s_buf[row][c_eor] ) ), 0x20, end_col - c_eor );
}
(void)memcpy( (void *)( save_buf ), (const void *)( ( &s_buf[row][start_col] ) ), ( save_len ) );
len = start_col - offset;
if (len > 0)
{
start = len;
len = save_len;
}
else
{
len += save_len;
start = 0;
}
disp_matched_text(row, start, len);
}
static
void
centre(void)
{
char *sol, *ls, *le;
int dif, l_cen, m_cen, f_char, len;
if (eor[row] == (-1))
{
return;
}
ls = sol = ( &s_buf[row][0] );
le = ls + eor[row];
while ( ls < le && ( ( *ls ) == 0x20 ) )
{
++ls;
}
while ( le > sol && ( ( le[-1] ) == 0x20 ) )
{
--le;
}
if (ls >= le)
{
return;
}
m_cen = l_margin + ( r_margin - l_margin ) / 2;
l_cen = ( ls - sol ) + ( le - ls ) / 2;
dif = m_cen - l_cen;
f_char = ls - sol;
if (dif > 0)
{
if (1022 - dif < le - sol)
{
dif = 1022 - ( le - sol );
}
}
else if(f_char + dif < 0)
dif = -f_char;
if ( dif == 0 || set_eor(row, ( le - sol ) + dif) )
{
return;
}
len = le - ls;
if (dif > 0)
{
ls = ( &s_buf[row][f_char] );
(void)memmove( (void *)( ls + dif ), (const void *)( ls ), ( len ) );
(void)memset( (char *)( ls ), 0x20, dif );
}
else
{
(void)memcpy( (void *)( ls + dif ), (const void *)( ls ), ( len ) );
}
disp_line();
}
static
void
disp_margins(void)
{
int m;
disp_template();
m = l_margin - offset;
if (m >= 0 && m < COLS)
{
t_base[m] = '<' | 0x0D00;
}
m = r_margin - offset;
if (m >= 0 && m < COLS)
{
t_base[m] = '>' | 0x0D00;
}
}
static
void
c_left(void)
{
if (( col + offset ) > 0)
{
set_col(( col + offset ) - 1);
}
else if(row != 1 && ( ( o_rec + 1 ) + row - 3 ) > 0)
{
c_up();
set_col(eor[row]);
}
}
static
void
open_line(void)
{
if (row == 1)
{
return;
}
if (eor[row] != (-1))
{
if (row == last_line)
{
push_line(&in_stack, ( &s_buf[row][0] ), eor[row]);
(void)( curs_row = ( row ), curs_col = ( 0 ) );
(void)clrtoeol();
}
else
{
if (eor[last_line] != (-1))
{
push_line(&in_stack, s_buf[last_line], eor[last_line]);
}
scroll_down(row);
}
}
else
{
set_eof();
}
eor[row] = 0;
}
static
void
split_line(const int margin)
{
const int n_row = row + 1, s_col = ( col + offset );
int len = eor[row] - s_col;
char const *const text = ( &s_buf[row][s_col] );
if (len < 0)
{
len = 0;
}
if (eor[row] == (-1))
{
set_eof();
eor[row] = 0;
}
else if(s_col == 0)
open_line();
else
{
(void)clrtoeol();
;
if (row == last_line)
{
push_line(&in_stack, text, len);
}
else
{
if (eor[last_line] != (-1))
{
push_line(&in_stack, s_buf[last_line], eor[last_line]);
}
(void)( curs_row = ( n_row ), curs_col = ( 0 ) );
scroll_down(n_row);
(void)set_eor(n_row, len + margin);
(void)memcpy( (void *)( ( (void)memset( (char *)s_buf[n_row], 0x20, margin), s_buf[n_row] + margin ) ), (const void *)( text ), ( len ) );
disp_row(n_row);
}
if (len > 0)
{
eor[row] = (short)s_col;
}
}
c_down();
set_col(margin);
}
static
void
wrap_text(void)
{
int ws = ( col + offset ), we;
char *const bs = ( &s_buf[row][0] );
while ( ws > 0 && !( ( ( bs[ws] ) == 0x20 ) ) )
{
--ws;
}
we = ws;
while ( ws < eor[row] && ( ( bs[ws] ) == 0x20 ) )
{
++ws;
}
while ( we > 0 && ( ( bs[we] ) == 0x20 ) )
{
--we;
}
set_col(++we);
(void)( curs_row = ( row ), curs_col = ( we ) );
(void)memcpy( (void *)( bs + we ), (const void *)( bs + ws ), ( eor[row] - ws ) );
eor[row] -= ws - we;
split_line(l_margin);
}
static
void
character(const int value)
{
const int b_col = ( col + offset );
int c_eor = eor[row];
chtype *cb;
if (b_col >= c_eor)
{
if ( set_eor(row, b_col + 1) )
{
return;
}
if (c_eor == (-1))
{
set_eof();
c_eor = 0;
}
(void)memset( (char *)( ( &s_buf[row][c_eor] ) ), 0x20, b_col - c_eor );
}
else if(expand)
{
char *bs;
if ( set_eor(row, c_eor + 1) )
{
return;
}
bs = ( &s_buf[row][b_col] );
(void)memmove( (void *)( bs + 1 ), (const void *)( bs ), ( c_eor - b_col ) );
(void)curs_chins();
}
*( &s_buf[row][b_col] ) = (char)value;
if (wordwrap && row != 1 && b_col > r_margin)
{
wrap_text();
set_col(eor[row]);
return;
}
cb = v_base + row * COLS + col;
if ( ( value >= 0x20 && value < 0x7F ) )
{
*cb = value | 0x0A00;
}
else
{
*cb = toprint(value) | 0x1F00;
}
set_col(( col + offset ) + 1);
}
static
void
yank(void)
{
const int c_eor = eor[row];
if (c_eor != (-1))
{
push_line(&del_stack, ( &s_buf[row][0] ), c_eor);
}
}
static
void
del_c(const int value)
{
int b_col;
if (value == 1)
{
const int c_line = ( ( o_rec + 1 ) + row - 3 ), c_col = col;
c_left();
if (c_line > ( ( o_rec + 1 ) + row - 3 ))
{
(void)se_join(0);
return;
}
if (c_col == col)
{
return;
}
}
if ( ( b_col = ( col + offset ) ) >= eor[row] )
{
if (value == 2)
{
(void)se_join(0);
}
return;
}
if (expand)
{
del_seg(b_col + 1);
}
else
{
*( &s_buf[row][b_col] ) = 0x20;
v_base[row * COLS + col] = 0x0A20;
}
}
static
void
rest_line(void)
{
if (del_stack == ((void *)0))
{
return;
}
open_line();
(void)set_eor( row, ( *(short *)( del_stack + 1 ) ) );
pop_line( &del_stack, ( &s_buf[row][0] ) );
disp_line();
}
static
void
del_rest(const int value)
{
int b_col = ( col + offset );
const int c_eor = eor[row];
if (value == 2)
{
if (b_col >= c_eor)
{
return;
}
if (b_col == 0)
{
yank();
}
del_seg(c_eor);
}
else
{
if (b_col >= c_eor)
{
yank();
b_col = c_eor;
}
col = offset = 0;
if (b_col > 0)
{
del_seg(b_col);
}
}
}
static
void
h_tab(void)
{
const int c_col = col;
col = ( col / screen_tabs + 1 ) * screen_tabs;
if (col >= COLS && !shift_right() || ( col + offset ) > 1022)
{
col = c_col;
}
}
static
void
b_tab(void)
{
const int c_col = col;
col -= col % screen_tabs ? col % screen_tabs : screen_tabs;
if ( col < 0 && !( shift_left() ) )
{
col = c_col;
}
}
static
void
c_return(void)
{
if (row == 1)
{
const int t_len = eor[1];
char *p = ( &s_buf[row][0] );
char const *const last = ( &s_buf[row][t_len] );
int len;
while ( p < last && ( ( *p ) == 0x20 ) )
{
++p;
}
if ( ( len = last - p ) >= 2048 )
{
se_error(32);
}
set_col(0);
if (len == 0)
{
c_down();
return;
}
(void)set_eor(1, t_len + 1);
p[len] = 0x00;
cmd_buf = p;
(void)home_command(1, ( o_rec + 1 ));
eor[1] = 0;
disp_line();
hist_ptr = hist_top;
}
else
{
split_line(0);
}
}
static
void
recall_comm(void)
{
if (hist_ptr == ((void *)0))
{
hist_ptr = hist_top;
}
if (hist_ptr != ((void *)0))
{
short const *const start = (short *)( hist_ptr + 1 );
short len = *start;
hist_ptr = (stack *)( *hist_ptr );
row = 1;
(void)set_eor(1, len);
(void)memcpy( (void *)( s_buf[1] ), (const void *)( start + 1 ), ( len ) );
disp_line();
set_col(len);
}
}
static
int
read_string(Q_MODE qtype)
{
ACTION fun;
const int c_col = col;
int value;
for (;;)
{
(void)( curs_row = ( 1 ), curs_col = ( col ) );
fun = get_seq(&value);
switch (fun)
{
case A_C_SOL:
col = c_col;
default:
continue;
case A_REST_LINE:
case A_EXIT_EDITOR:
return (-1);
case A_C_RETURN:
col = eor[1];
return 1;
case A_DEL_LINE:
(void)( curs_row = ( 1 ), curs_col = ( col = c_col ) );
del_rest(2);
continue;
case A_DEL_REST:
if (value == 2)
{
del_rest(2);
}
continue;
case A_B_TAB:
b_tab();
if (col < c_col)
{
col = c_col;
}
continue;
case A_DEL_C:
if (value == 1 && col <= c_col)
{
continue;
}
case A_C_LEFT:
if (col <= c_col)
{
continue;
}
case A_YANK:
case A_BLOCK:
case A_EXP_MODE:
case A_C_EOL:
break;
case A_H_TAB:
if ( ( col / screen_tabs + 1 ) * screen_tabs > last_col )
{
continue;
}
break;
case A_CHARACTER:
if (expand && eor[1] >= last_col)
{
continue;
}
case A_C_RIGHT:
if (col >= last_col)
{
continue;
}
}
se_execute(fun, value);
if (qtype == Q_YORN)
{
return 1;
}
}
}
static
int
query(char const *const prompt, char *const buf, Q_MODE qtype)
{
const int c_offset = offset, c_row = row, c_col = col;
const short c_eor = eor[1], c_len = s_eor[1];
char *const c_buf = s_buf[1];
int rc, p_len = strlen(prompt);
string t_buf;
(void)( curs_row = ( 1 ), curs_col = ( 0 ) );
put_seq(prompt, p_len, 0x0C00);
;
(void)clrtoeol();
s_buf[1] = t_buf;
s_eor[1] = 1022;
row = 1, offset = 0;
eor[1] = col = ++p_len;
rc = read_string(qtype);
eor[1] = c_eor;
s_eor[1] = c_len;
s_buf[1] = c_buf;
if (rc != (-1))
{
if (qtype == Q_RAW)
{
char *ip = t_buf + p_len, *op = buf, c;
const char *last = t_buf + col;
while (ip < last)
{
c = *ip++;
if (c == 0x2F)
{
*op++ = 0x5C;
}
*op++ = c;
}
*op = 0x00;
}
else
{
while ( p_len < col && ( ( t_buf[p_len] ) == 0x20 ) )
{
++p_len;
}
while ( col > p_len && ( ( t_buf[col - 1] ) == 0x20 ) )
{
--col;
}
col -= p_len;
(void)memcpy( (void *)( buf ), (const void *)( t_buf + p_len ), col ); buf[col] = 0x00;;
if (qtype == Q_YORN)
{
if (u_map[*( buf )] == 'Y')
{
rc = 0;
}
else if(u_map[*( buf )] == 'Q')
rc = (-1);
}
}
}
row = c_row, col = c_col, offset = c_offset;
return rc;
}
static
void
se_justify(const int value)
{
string buf;
const int j_col = ( col + offset );
switch (value)
{
case 'B':
case 'Q':
(void)sprintf(buf, "T.%d JP", col > eor[row] ? eor[row] : col);
(void)run_command(buf, 0, value == 'B');
break;
case 'L':
if (j_col >= r_margin)
{
message("Left margin > right margin.");
}
else
{
l_margin = j_col;
}
break;
case 'R':
if (j_col <= l_margin)
{
message("Right margin < left margin.");
}
else
{
r_margin = j_col;
}
break;
case 'W':
wordwrap = !wordwrap;
break;
case 'S':
if (query("New line spacing (0-9):", buf, Q_EDIT) == (-1))
{
return;
}
line_spacing = ( g_map[*buf] & 010U ) ? *buf - '0' : 0;
break;
case 'C':
centre();
break;
case 'J':
adjust = !adjust;
}
disp_margins();
disp_home();
}
static
void
search(const int value)
{
string buf, rhs, find_com, rep_com;
int rc, rel, neg, iter = 0, nextl = 0, line, sop;
const char *p;
switch (value)
{
case 'I':
if (query("Line:", buf, Q_EDIT) == (-1))
{
return;
}
if (row == 1)
{
c_home('Q');
}
sop = ( o_rec + 1 );
p = buf;
rel = neg = 0;
if (*p == '+' || *p == '-')
{
++rel;
if (*p == '-')
{
++neg;
}
++p;
}
line = atoi(p);
if (neg)
{
line = -line;
}
if (rel)
{
line += ( ( o_rec + 1 ) + row - 3 );
}
if (line < 0)
{
line = 0;
}
else if( line > ( in_u->eof_rec ) )
line = ( in_u->eof_rec );
if (line >= sop && line < sop + text_lines)
{
row = line - sop + 3;
return;
}
if (line < 6 - 3)
{
row = line + 3;
line = 0;
}
else
{
row = 6;
line -= 6 - 3;
}
file_move(-line);
return;
case 'F':
if (query(se_find, buf, Q_RAW) == (-1))
{
return;
}
(void)sprintf(find_com, se_fcom1, buf);
break;
case 'A':
if (query(se_find, buf, Q_RAW) == (-1))
{
return;
}
if (query("Replacement:", rhs, Q_RAW) == (-1))
{
return;
}
(void)sprintf(find_com, se_fcom1, buf);
(void)sprintf(rep_com, "RR\177%s\177%s\177", buf, rhs);
++iter;
break;
case 'L':
if (eor[row] != (-1))
{
nextl = 1;
}
(void)memcpy( (void *)( find_com ), (const void *)( "TR//" ), 5 );
}
if (row == 1)
{
c_home('Q');
}
row = 6;
while (run_command(find_com, nextl, 0) == 0 && iter)
{
status();
if ( ( rc = query("Replace (y/n) ?", buf, Q_YORN) ) == (-1) )
{
break;
}
if (rc == 0)
{
(void)run_command(rep_com, 0, 0);
}
nextl = 1;
}
if (eor[row] == (-1))
{
col = offset = 0;
}
}
static
void
exit_editor(const int value)
{
string com;
const int fl = ( ( o_rec + 1 ) + ( ( row == 1 ? text_row : row ) - 3 ) );
file_move(-( o_rec + 1 ));
switch (value)
{
case 'Q':
if ( prim_changed
&& query("File changed, abandon edit (y/n) ?", com, Q_YORN) )
{
return;
}
Quit();
abort();
case 'X':
(void)sprintf(
com,
"Save %sfile and exit (y/n) ?",
prim_changed ? empty : se_fin1);
if ( query(com, com, Q_YORN) )
{
return;
}
cmd_buf = "e";
(void)home_command(1, ( o_rec + 1 ));
break;
case 'D':
cmd_buf = let_col;
(void)home_command(1, fl);
case 'S':
(void)sprintf(
com, "Save %sfile (y/n) ?", prim_changed ? empty : se_fin1);
if ( query(com, com, Q_YORN) )
{
return;
}
(void)sprintf(com, "SN\177%s\177,TE,X", out_fname);
(void)run_command(com, -fl, 1);
prim_changed = 0;
}
}
static
void
rwx_file(const int value)
{
int sop = 1;
char optc;
string com, nlines;
FNAME fname;
switch (value)
{
case 'R':
if (query("Merge file:", fname, Q_EDIT) == (-1))
{
return;
}
(void)sprintf(com, "M\177%s\177,TE,X", fname);
break;
case '!':
case '|':
return;
case 'A':
if (query("Append to file:", fname, Q_EDIT) == (-1))
{
return;
}
optc = 'A';
goto make_com;
case 'W':
if (query("Save file:", fname, Q_EDIT) == (-1))
{
return;
}
optc = 'N';
make_com:
if (query(se_ep, nlines, Q_EDIT) == (-1))
{
return;
}
if ( ( *( nlines ) == 0x00 ) )
{
if ( ( *( fname ) == 0x00 ) )
{
return;
}
(void)sprintf(com, "S%c\177%s\177,M,TE,X,X", optc, fname);
}
else if( ( *( fname ) == 0x00 ) )
(void)sprintf(com, "S%c,T%s,X", optc, nlines);
else
{
(void)sprintf(com, "S%c\177%s\177,T%s,X", optc, fname, nlines);
}
break;
case 'U':
if (query("Use file:", fname, Q_EDIT) == (-1))
{
return;
}
(void)sprintf(com, "U\177%s\177", fname);
sop = 0;
break;
case 'O':
if (query("Old file:", fname, Q_EDIT) == (-1))
{
return;
}
(void)sprintf(com, "O\177%s\177", fname);
if (row == 1)
{
text_row = 3;
}
else
{
row = 3;
}
sop = 0;
}
(void)run_command(com, 0, sop);
}
static
void
word_count(void)
{
long rc, wc, pc, cc, sc, lc, nc;
const unsigned char *p, *last;
unsigned char c;
string res;
UNIT t_u;
int len, inword;
rc = wc = pc = cc = lc = sc = nc = 0;
t_u = *in_u;
( ( &t_u )->rec_num = ( &t_u )->page = 0, ( &t_u )->rec_start = ( &t_u )->list->base );
while ( ( len = vsgetrec(&t_u, &p) ) != (-1) )
{
cc += len;
++rc;
inword = 0;
for (last = p + len; p < last; ++p)
{
c = *p;
if ( !( ( g_map[c] & ( 04U | 010U | 020U ) ) ) )
{
inword = 0;
}
else if(!inword)
wc += ( inword = 1 );
if ( ( !( ( g_map[c] & ( 04U | 010U | 020U ) ) || ( ( c ) == 0x20 ) ) ) )
{
++pc;
switch (c)
{
case ';':
++lc;
break;
case '.':
case '!':
case '?':
++sc;
}
}
if (( c < 0x20 || c >= 0x7F ) && c != 0x09)
{
++nc;
}
}
}
(void)sprintf(res, f_wc, rc, wc, pc, nc, sc, lc, cc + rc);
inform(res);
}
static
void
misc_ops(const int value)
{
const char *com;
int start = 0;
FNAME buf;
switch (value)
{
case 'E':
com = ".tss//";
break;
case 'P':
(void)sprintf(buf, se_pcom, in_fname);
com = buf;
start = -( ( o_rec + 1 ) + ( ( row == 1 ? text_row : row ) - 3 ) );
break;
case 'L':
if (query("New directory:", buf, Q_EDIT) == (-1))
{
return;
}
if ( chdir(prep_name(buf) ) == -1 )
{
se_error(39);
}
return;
case '?':
file_move(-( o_rec + 1 ));
word_count();
disp_text();
return;
case 'F':
com = se_lcom;
}
(void)run_command(com, start, 1);
}
static
void
se_loop(int value)
{
ACTION fun;
int speed = 2;
int c, c_orec, c_row, c_col;
stack *c_in_s, *c_del_s;
if (value)
{
fun = A_FILE_MOVE;
}
else if( ( fun = get_seq(&value) ) == A_REPEAT )
return;
++qq_loop;
while (qq_loop)
{
(c = _bios_keybrd(1) ? curs_getc() : 0);
if (c != 0)
{
if ( ( g_map[c] & 010U ) )
{
if ( ( speed = c - '0' ) > 5 )
{
speed <<= 2;
}
}
else
{
break;
}
}
c_orec = o_rec, c_row = row, c_col = col;
c_in_s = in_stack, c_del_s = del_stack;
se_execute(fun, value);
if (c_orec == o_rec && c_row == row && c_col == col && c_in_s == in_stack && c_del_s == del_stack)
{
break;
}
bios_gotoxy( (unsigned char)curs_row, (unsigned char)curs_col );
if (speed > 0)
{
(void)napms(speed * 100);
}
}
qq_loop = 0;
}
static
void
se_execute(const ACTION act, const int value)
{
last_offset = offset;
switch (act)
{
case A_C_UP:
c_up();
break;
case A_FILE_MOVE:
file_move(value);
break;
case A_C_DOWN:
c_down();
break;
case A_C_LEFT:
c_left();
break;
case A_EXP_MODE:
expand = !expand;
break;
case A_DEL_C:
del_c(value);
break;
case A_C_HOME:
c_home(value);
break;
case A_B_TAB:
b_tab();
break;
case A_PAGE_SHIFT:
page_shift(value);
break;
case A_DEL_REST:
del_rest(value);
break;
case A_C_EOL:
set_col(eor[row]);
break;
case A_C_TOS:
row = 3;
break;
case A_C_SOL:
col = offset = 0;
break;
case A_C_BOS:
row = last_line;
break;
case A_JUSTIFY:
se_justify(value);
break;
case A_HELP:
Help();
init();
break;
case A_RWX_FILE:
rwx_file(value);
goto d_home;
case A_EXIT_EDITOR:
exit_editor(value);
goto d_home;
case A_MISC_CE:
misc_ops(value);
goto d_home;
case A_SEARCH:
search(value);
d_home:
disp_home();
break;
case A_W_LEFT:
(void)find_backwards(((void *)0), value);
break;
case A_C_RIGHT:
set_col(( col + offset ) + 1);
break;
case A_W_RIGHT:
(void)find_forwards(((void *)0), value);
break;
case A_H_TAB:
h_tab();
break;
case A_CHARACTER:
character(value);
break;
case A_C_RETURN:
c_return();
break;
case A_OPEN_LINE:
open_line();
break;
case A_DEL_LINE:
yank();
if (row == 1)
{
(void)( curs_row = ( 1 ), curs_col = ( 0 ) );
(void)clrtoeol();
eor[1] = 0;
set_col(0);
}
else
{
(void)del_line();
}
break;
case A_REST_LINE:
rest_line();
break;
case A_REDRAW:
term();
init();
break;
case A_YANK:
yank();
break;
case A_HIST:
recall_comm();
break;
case A_BLOCK:
block(value);
break;
case A_COMMAND:
(void)run_command(let_col, 0, 0);
break;
case A_REPEAT:
se_loop(value);
break;
case A_FINDC:
find_char(value);
default:
break;
}
status();
if (offset != last_offset)
{
disp_home();
disp_template();
disp_text();
}
(void)( curs_row = ( row ), curs_col = ( col ) );
}
static
void
Screen_ed(void)
{
int value;
if (_setjmp(se_ret) == 1)
{
term();
return;
}
if (s_buf == ((void *)0))
{
init_screen();
}
linewrap();
file_to_buf(8);
eor[row = 1] = lon = col = text_col = text_offset = offset = 0;
text_row = 3;
init();
if ( _setjmp(se_err) )
{
(void)( curs_row = ( row ), curs_col = ( col ) );
}
;
if (trunc_recs)
{
trunc_recs = 0;
se_error(47);
}
for (;;)
{
const ACTION fun = get_seq(&value);
se_execute(fun, value);
}
}
static
void
free_prog(VERB_LIST *const ptr)
{
VERB *p = ptr->prog, *last;
do
{
if (p->o1.e != ((void *)0))
{
free_expr(p->o1.e);
}
else if(p->o2.e != ((void *)0)) free_expr(p->o2.e);
last = p;
p = p->next;
}
while ( p != ((void *)0) );
last->next = g_free_list;
g_free_list = ptr->prog;
ptr->prog = ((void *)0);
}
static
void
pop_com_stack(VERB_LIST *new_ptr)
{
while (com_stack_ptr != new_ptr)
{
if (com_stack_ptr->prog != ((void *)0))
{
free_prog(com_stack_ptr);
}
com_stack_ptr = com_stack_ptr->prev;
}
depth = new_ptr->save_depth;
}
static
int
make_line(char *const buf)
{
int i_len = i_eor - i_col;
if (e_col + i_len > 1022)
{
i_len = 1022 - e_col;
}
(void)memcpy( (void *)( ( memcpy( (void *)( buf ), (const void *)( e_buff ), e_col), (void *)( (char *)( buf ) + e_col ) ) ), (const void *)( i_buff + i_col ), ( i_len ) );
return e_col + i_len;
}
static
void
hex_print(void)
{
int len, seg_len;
char *p, *rec_end, *first, *last;
LINE buf;
new_line();
if ( ( len = make_line(buf) ) == 0 )
{
say("LX: empty line.\n");
return;
}
for (first = buf, rec_end = buf + len; first < rec_end; first += 16)
{
(void)fprintf( ((__w_FILE *)&__iob[2]), "%5d | ", (int)( first - buf ) );
if ( ( last = first + 16 ) > rec_end )
{
last = rec_end;
}
for (p = first; p < last; ++p)
{
(void)fprintf(((__w_FILE *)&__iob[2]), "%02X ", *(unsigned char *)p);
}
for (p = first; p < last; ++p)
{
if ( ( *p < 0x20 || *p >= 0x7F ) )
{
*p = '.';
}
}
seg_len = last - first;
(void)fprintf(((__w_FILE *)&__iob[2]),
"%*c| %.*s", 1 + ( 16 - seg_len ) * 3, 0x20, seg_len, first);
new_line();
}
new_line();
}
static
void
get_space(const int minus, const int comm)
{
int col = i_col;
if (minus)
{
while ( col > 0 && ( ( i_buff[col - 1] ) == 0x20 ) )
{
--col;
}
if (col < i_col && comm == 'T')
{
linewrap();
}
}
else
{
while ( col < i_eor && ( ( i_buff[col] ) == 0x20 ) )
{
++col;
}
}
altr_line(col - i_col, comm);
}
static
void
alter_end(int last, const int comm)
{
const int eof_rec = ( in_u->eof_rec );
if (last == (-1) || last > eof_rec)
{
last = eof_rec;
}
if (last == g_rec)
{
return;
}
switch (comm)
{
case 'T':
if (g_eof)
{
if (depth)
{
return;
}
g_err(12, ((void *)0));
}
flush_buff();
if (last - g_rec > 1)
{
o_rec += last - ( in_u->rec_num );
vscopy(out_u, in_u, last);
g_rec = last - 1;
}
(void)fill_buff();
break;
case 'K':
if (last < g_rec)
{
g_err(5, ((void *)0));
}
case 'P':
if (g_eof)
{
if (last > g_rec)
{
if (depth)
{
return;
}
g_err(12, ((void *)0));
}
g_eof = 0;
}
vsseek(in_u, last);
g_rec = last - 1;
(void)fill_buff();
break;
case 'L':
if (last < g_rec)
{
g_err(5, ((void *)0));
}
if (g_eof)
{
return;
}
while ( g_rec < last - 1 && fill_buff() )
{
n_print(i_buff, i_eor, 0);
}
}
}
static
void
printline(char *ptr)
{
int len, sec;
LINE buf;
if (fscreen)
{
return;
}
if (buff_sec * 76 > e_col + i_eor - i_col)
{
buff_sec = e_col / 76;
}
sec = buff_sec * 76;
if (g_eof || g_rec < 0)
{
ptr += sprintf(
ptr,
g_rec > 0
? "End of file encountered following line %d.\nEOF"
: "Empty file.\nEOF",
g_rec);
}
else
{
ptr += sprintf(ptr, line_pos, g_rec, e_col);
}
if (f_list != ((void *)0))
{
char const *const file = f_list->name;
const int std = ( *(unsigned int *)file == '-' );
if (f_list->disp == 'M')
{
ptr += sprintf(ptr, ", merged from %s", std ? si_file : file);
}
else
{
ptr += sprintf(
ptr,
", to be %s to %s",
f_list->disp == 'A' ? "appended" : "saved",
std ? so_file : file);
}
}
*ptr++ = '\n';
if (g_eof)
{
(void)strcpy(ptr, "*\r");
}
else
{
char *p, c;
*ptr++ = (char)( buff_sec + '0' );
if ( ( len = make_line(buf) - sec ) > 76 )
{
len = 76;
}
printable(buf + sec, len);
(void)memcpy( (void *)( p = ( memcpy( (void *)( ptr + 1 ), (const void *)( buf + sec ), len), (void *)( (char *)( ptr + 1 ) + len ) ) ), (const void *)( "\n*\r" ), ( 4 ) );
if (e_col < sec)
{
c = '<';
}
else if(e_col > sec + 76)
c = '>';
else
{
c = 0x20;
(void)sprintf(p, "\n*%*c|\r", e_col - sec + 1, 0x20);
}
*ptr = c;
}
}
static
void
hist_write(char const *const comm)
{
int len;
if ( hist_top == ((void *)0) || ( len = *(short *)( hist_top + 1 ) )
!= strlen(comm) || !( memcmp(comm, (short *)( hist_top + 1 ) + 1, len) == 0 ) )
{
push_line( &hist_top, comm, strlen(comm) );
}
}
static
int
hist_recall(char *const comm)
{
const short *start;
if (hist_top == ((void *)0))
{
return 0;
}
start = (short *)( hist_top + 1 );
(void)memcpy( (void *)( comm ), (const void *)( start + 1 ), ( *start ) );
return *start;
}
static
void
do_ins(char const *const str, const int len)
{
if ( (unsigned long)e_col + len > 1022 )
{
g_err(47, ((void *)0));
}
(void)memcpy( (void *)( e_buff + e_col ), (const void *)( str ), ( len ) );
e_col += len;
}
static
void
ins(const unsigned int disp, const char *str, int len)
{
int l;
const unsigned int scr = disp & 01;
const char *split;
if (len < 0)
{
len = strlen(str);
}
if (len > 0)
{
while ( ( split = (const char *)memchr(str, 0x0A, len) ) != ((void *)0) )
{
l = split - str;
if (scr)
{
(void)!write(2, str, l++);
new_line();
}
else
{
do_ins(str, l++);
out_buff();
}
len -= l;
str += l;
}
if (scr)
{
(void)!write(2, str, len);
}
else
{
do_ins(str, len);
}
}
if (disp > 1)
{
if (scr)
{
new_line();
}
else
{
out_buff();
}
}
}
static
void
ABR(VERB const *const opts)
{
int len1 = opts->o1.v, len2 = opts->o2.v;
LINE buf;
if ( findstr(opts->o1.s, len1, opts->o1.q, 'T') )
{
if (depth)
{
get_end();
return;
}
g_err(14, opts->o1.s);
}
if (opts->o1.q == 'r')
{
len1 = (int)( loc2 - loc1 );
len2 = re_sub(opts->o2.s, buf);
}
if (opts->comm == 'R')
{
altr_line(len1, 'P');
}
else if(opts->comm == 'A')
altr_line(len1, 'T');
ins(0, opts->o1.q == 'r' ? buf : opts->o2.s, len2);
loc2 = ((void *)0);
}
static
int
Verify(VERB const *const opts)
{
int val;
unsigned int opt = opts->o1.q & ~0xF000;
if (opt != 0)
{
if (opt & 0x0100)
{
val = (int)Evaluate(opts->o1.e, 0)->opval.i;
}
else
{
val = opts->o1.v;
}
switch (opt & 0377U)
{
case 1:
return !g_eof;
case 2:
case 3:
return val == 0;
case 6:
return g_rec != val;
case 4:
return o_rec != val;
case 'B': case 'C': case 'G': case 'F': case 'S': case 'R': case 'r':
return findstr(opts->o1.s, val, opt, 'V');
default:
g_err(9, opts->errp);
}
}
if (opts->dot)
{
if ( ( opt = opts->o2.q ) & 0x0100 )
{
val = (int)Evaluate(opts->o2.e, 0)->opval.i;
}
else
{
val = opts->o2.v;
}
switch (opt & 0377U)
{
case 'S':
if (opts->o2.v)
{
return !( i_col > 0 || ( ( i_buff[i_col - 1] ) == 0x20 ) );
}
return !( i_col < i_eor || ( ( i_buff[i_col] ) == 0x20 ) );
case 1:
return i_col < i_eor;
case 'G':
case 'r':
return findstr(opts->o2.s, val, opt, 'V');
case 2:
case 3:
return val == 0;
case 6:
return i_col != val;
case 4:
return e_col != val;
default:
g_err(9, opts->errp);
}
}
return 0;
}
static
int
PT(VERB const *const opts)
{
int val;
unsigned int opt = opts->o1.q;
const char comm = opts->comm, *const opt2 = opts->o2.s;
if (opt & 0xF000)
{
const int endc = ( opt & 0x2000 ) == 0;
while (Verify(opts) != endc && !g_eof)
{
(void)add_line(comm);
}
return 0;
}
if (opt != 0)
{
if (opt & 0x0100)
{
val = (int)Evaluate(opts->o1.e, 0)->opval.i;
}
else
{
val = opts->o1.v;
}
switch (opt & 0377U)
{
default:
g_err(9, opts->errp);
case 5:
if (val >= 0)
{
goto do_recs;
}
case 1:
alter_end((-1), comm);
break;
case 3:
val = -val;
case 2:
do_recs:
if (val < 0 && comm != 'P')
{
val += wrapround();
}
else
{
val += g_rec;
}
if (val < 0)
{
g_err(3, opts->errp);
}
alter_end(val, comm);
break;
case 'B': case 'C': case 'G': case 'F': case 'S': case 'R': case 'r':
if ( findstr(opts->o1.s, val, opt, comm) )
{
if (comm == 'L')
{
return 0;
}
if (depth)
{
return 1;
}
g_err(12, opts->errp);
}
break;
case 4:
if (o_rec >= val)
{
break;
}
val = g_rec + ( val - o_rec );
case 6:
if (val < 0)
{
g_err(3, opts->errp);
}
if ( ( val <= g_rec || g_rec == -1 ) && comm != 'P' )
{
(void)wrapround();
}
if (g_rec >= 0)
{
alter_end(val, comm);
}
}
}
if (opts->dot)
{
if ( ( opt = opts->o2.q ) & 0x0100 )
{
val = (int)Evaluate(opts->o2.e, 0)->opval.i;
}
else
{
val = opts->o2.v;
}
switch (opt & 0377U)
{
default:
g_err(9, opts->errp);
case 'S':
get_space(val, comm);
break;
case 'G':
case 'r':
if ( findstr(opt2, val, opt, comm) )
{
if (depth)
{
altr_line(i_eor - i_col, comm);
return 1;
}
g_err(14, opts->errp);
}
break;
case 5:
if (val >= 0)
{
goto r_end;
}
case 1:
altr_line(i_eor - i_col, comm);
break;
case 4:
if ( (unsigned long)e_col >= val )
{
break;
}
val = i_col + ( val - e_col ) + 1;
case 6:
if (val <= i_col && comm == 'T')
{
val -= e_col;
}
else
{
val -= i_col;
}
goto r_end;
case 3:
val = -val;
case 2:
r_end:
if (val < 0 && comm == 'T')
{
val += e_col;
linewrap();
}
altr_line(val, comm);
}
}
return 0;
}
static
int
end_line(void)
{
const char *p = i_buff, *const last = p + i_eor;
if ( *p == '.' || ( *p < 0x20 || *p >= 0x7F ) )
{
return 1;
}
while (p < last)
{
if ( ( ( *p ) == 0x20 ) )
{
++p;
}
else
{
return 0;
}
}
return 1;
}
static
void
pad(char const *const c_type)
{
char *const eb = e_buff, *const lm = eb + l_margin,
*const rm = eb + t_margin, *ec = eb + e_col,
*p = left_right ? lm : ec;
while ( ec <= rm && ( left_right ? ++p < ec : --p > lm ) )
{
if ( ( ( *p ) == 0x20 )
&& ( c_type == ((void *)0) ? !( ( p[-1] ) == 0x20 )
: strchr(c_type, p[-1]) != ((void *)0) ) )
{
(void)memmove( (void *)( p + 1 ), (const void *)( p ), ( ec++ - p ) );
}
}
e_col = ec - eb;
}
static
int
pack(void)
{
char *const eb = e_buff, *const ib = i_buff;
const char *ip = ib + i_col,
*last = ib + i_eor,
*i_start,
*limit;
char *e_start,
*ep = eb + e_col;
while ( last > ib && ( ( last[-1] ) == 0x20 ) )
{
--last;
}
limit = eb + t_margin;
do
{
while ( ip < last && ( ( *ip ) == 0x20 ) )
{
++ip;
}
if (ip >= last)
{
return 0;
}
i_start = ip, e_start = ep;
while ( ip < last && ep <= limit && !( ( ( *ip ) == 0x20 ) ) )
{
if ( ( *ip < 0x20 || *ip >= 0x7F ) )
{
++limit, ++t_margin;
}
*ep++ = *ip++;
}
if (ep <= limit)
{
*ep++ = 0x20;
}
if (ip >= last)
{
e_col = ep - eb;
return 0;
}
}
while ( ep <= limit );
if (e_start == eb + l_margin && ep[-1] != '-')
{
while ( ip < last && !( ( ( *ip ) == 0x20 ) ) )
{
*ep++ = *ip++;
}
}
else if(!( ( *ip ) == 0x20 ) && ep[-1] != '-')
{
while ( ip < last && ( *ip < 0x20 || *ip >= 0x7F ) )
{
*ep++ = *ip++;
}
if (!( ( *ip ) == 0x20 ) && ip < last)
{
while (--ip >= i_start)
{
if ( ( *ip < 0x20 || *ip >= 0x7F ) )
{
--t_margin;
}
}
ep = e_start;
ip = i_start;
}
}
e_col = ep - eb;
i_col = ip - ib;
while ( e_col > 0 && ( ( eb[e_col - 1] ) == 0x20 ) )
{
--e_col;
}
return 1;
}
static
void
justify(void)
{
char *const eb = e_buff;
int i;
while ( end_line() )
{
if ( !(add_line('T') ) )
{
return;
}
}
if (i_col > 0)
{
char const *const ib = i_buff;
while ( i_col < i_eor && !( ( ib[i_col] ) == 0x20 ) )
{
eb[e_col++] = ib[i_col++];
}
if (i_col < i_eor)
{
eb[e_col++] = ib[i_col++];
}
}
if (e_col < l_margin)
{
(void)memset( (char *)( eb + e_col ), 0x20, l_margin - e_col );
e_col = l_margin;
}
for (;;)
{
t_margin = r_margin;
if ( pack() )
{
if (e_col <= l_margin)
{
break;
}
pad(endsent);
if (adjust)
{
pad(",:");
while (e_col <= t_margin)
{
const int s_ec = e_col;
pad(((void *)0));
if (s_ec == e_col)
{
break;
}
}
}
left_right = !left_right;
out_buff();
for (i = 0; i < line_spacing; ++i)
{
e_col = 0;
out_buff();
}
(void)memset( (char *)( eb ), 0x20, e_col = l_margin );
}
else
{
if ( !( fill_buff() ) || end_line() )
{
break;
}
}
}
if (e_col <= l_margin)
{
e_col = 0;
}
else
{
pad(endsent);
out_buff();
}
}
static
int
Join(VERB const *const opts)
{
const char *sp, *ep;
char *const eb = e_buff, *ec;
const int next = ( opts->o1.v == 0 );
if (opts->o1.q == 'P')
{
justify();
return 0;
}
get_end();
for (ec = eb + e_col; ec > eb && ( ( ec[-1] ) == 0x20 ); --ec)
{
;
}
if (next)
{
if ( !( fill_buff() ) )
{
return 1;
}
i_col = i_eor;
sp = i_buff;
ep = sp + i_eor;
while ( ep > sp && ( ( ep[-1] ) == 0x20 ) )
{
--ep;
}
}
else
{
sp = eb;
ep = ec;
}
while ( sp < ep && ( ( *sp ) == 0x20 ) )
{
++sp;
}
if (ep > sp)
{
const int len = ep - sp;
*ec++ = 0x20;
e_col = ( ec - eb ) + len;
if ( (unsigned long)e_col > 1022 )
{
g_err(47, ((void *)0));
}
(void)memcpy( (void *)( ec ), (const void *)( sp ), ( len ) );
}
return 0;
}
static
void
Insert(VERB const *const opts)
{
char ch_delim;
const char *s1p = opts->o1.s;
static char prompt[3] = " x";
int len;
time_t tm;
const TOKEN *res;
const unsigned int disp = ( opts->comm == 'D' );
string ss1;
if (disp)
{
term();
}
switch (opts->o1.q)
{
case 'C':
*ss1 = (char)Evaluate(opts->o1.e, 0)->opval.i;
ins(disp, ss1, 1);
return;
case '{':
res = Evaluate(opts->o1.e, 3);
if (res->fp)
{
len = sprintf(ss1, m_real, res->opval.r);
}
else
{
len = sprintf(ss1, n_format, res->opval.i);
}
ins(disp, ss1, len);
return;
case 'F':
ins(disp, in_fname, -1);
return;
case 'D':
(void)time(&tm);
(void)memcpy( (void *)( ss1 ), (const void *)( ctime(&tm) ), 33 ); ss1[33] = 0x00;;
ins(disp, ss1, -1);
return;
case 'X':
ins(disp, s1p, opts->o1.v);
return;
case 'P':
wait_user();
return;
}
ch_delim = *s1p++;
if ( gdss(ss1, &len, &s1p) )
{
if (depth | fscreen)
{
g_err(21, opts->errp);
}
ins(disp + 2, ss1, len);
prompt[1] = ch_delim;
for (;;)
{
if ( get_com(ss1, prompt) )
{
g_err(46, opts->errp);
}
len = strlen(ss1);
if (ss1[len - 1] == ch_delim)
{
ins(disp, ss1, len - 1);
return;
}
ins(disp + 2, ss1, len);
}
}
else
{
while (*s1p++ == ch_delim)
{
ins(disp + 2, ss1, len);
if ( gdss(ss1, &len, &s1p) )
{
g_err(37, opts->o1.s);
}
}
ins(disp, ss1, len);
}
}
static
void
Exit(void)
{
VERB xit_opts;
const FILE_LIST *fptr;
while (f_list != ((void *)0))
{
for (fptr = f_list; fptr != ((void *)0); fptr = fptr->next)
{
if (fptr->disp != 'M')
{
g_err(33, ((void *)0));
}
}
if (!g_eof)
{
alter_end((-1), 'T');
}
if (e_col)
{
out_buff() ;
}
xit_opts.o1.q = 'M';
Xit(&xit_opts);
}
if (!g_eof)
{
alter_end((-1), 'T');
}
if (e_col)
{
out_buff();
}
vsreopen(out_u);
if (Mem_to_disk(out_u, out_fname, o_mode) == (-1))
{
vsreopen(out_u);
g_err(39, out_fname);
}
term();
if (lon)
{
(void)fprintf(((__w_FILE *)&__iob[2]), ps_name, ft_in, in_fname);
print_size(infile_recs);
(void)fprintf(((__w_FILE *)&__iob[2]), ps_name, ft_out, out_fname);
print_size( ( out_u->rec_num ) );
putstr("Edit Finished.");
}
_exit(0);
}
static
void
Details(void)
{
const FILE_LIST *p = f_list;
const UNIT *u, *prim_in = ((void *)0), *prim_out = ((void *)0), *old_in = in_u,
*old_out = out_u;
while (p != ((void *)0))
{
if (p->disp == 'M')
{
if ( ( old_in->link_u != ((void *)0) ) )
{
prim_in = old_in;
}
print_i_size(ft_merge, p->name, old_in);
old_in = p->old_u;
if ( ( old_in->link_u != ((void *)0) ) )
{
prim_in = old_in;
}
}
else
{
if ( ( old_out->link_u != ((void *)0) ) )
{
prim_out = old_out;
}
print_o_size("Save", p->name, old_out);
old_out = p->old_u;
if ( ( old_out->link_u != ((void *)0) ) )
{
prim_out = old_out;
}
}
p = p->next;
}
print_i_size(ft_in, in_fname, prim_in != ((void *)0) ? prim_in : in_u);
print_o_size(ft_out, out_fname, prim_out != ((void *)0) ? prim_out : out_u);
if (trans_u != ((void *)0))
{
print_i_size("Transient", t_fname, trans_u);
}
for (u = comm_u, p = c_list; p != ((void *)0); p = p->next)
{
print_i_size("Command", p->name, u);
u = p->old_u;
}
}
static
void
Numbers(VERB const *const opts)
{
if (opts->o1.q == 0)
{
l_numbers = !l_numbers;
}
else
{
++l_numbers;
(void)sprintf(
n_format,
"%%%.*sl%c",
opts->o1.v,
opts->o1.s,
opts->o2.v);
}
}
static
void
List(VERB const *const opts)
{
const MACRO *macptr;
SAVE_AREA l_save;
stack *p;
LINE buf;
int len;
if (opts->o1.q != 8)
{
term();
}
switch (opts->o1.q)
{
case 7:
++lon;
break;
case 8:
lon = 0;
break;
case 'D':
Details();
break;
case 'H':
for ( p = hist_top; p != ((void *)0); p = (stack *)( *p ) )
{
short const *const start = (short *)( p + 1 );
(void)fprintf( ((__w_FILE *)&__iob[2]), "%.*s\n", *start, (char *)( start + 1 ) );
}
break;
case 'M':
for (macptr = mac_list; macptr != ((void *)0); macptr = macptr->next)
{
(void)fprintf(
((__w_FILE *)&__iob[2]),
"%s/%c%d/ %s\n",
macptr->name,
macptr->par_sub,
macptr->nargs,
macptr->text);
}
break;
case 'X':
hex_print();
break;
case 'S':
word_count();
break;
default:
if (g_eof)
{
return;
}
len = make_line(buf);
if (opts->o1.q == 2 && opts->o1.v == 0)
{
buf[len] = 0x00;
say(buf);
break ;
}
if (lon)
{
if (f_list != ((void *)0) && f_list->disp == 'M')
{
(void)fprintf(((__w_FILE *)&__iob[2]), pt_list, ft_merge, f_list->name);
}
else
{
(void)fprintf(((__w_FILE *)&__iob[2]), pt_list, ft_in, in_fname);
}
(void)fprintf(((__w_FILE *)&__iob[2]), ", starting at line %d\n", g_rec);
}
n_print(buf, len, 1);
l_save.in_rec_len = l_save.out_rec_len = ( 1022 + 2 );
l_save.in_rec = buf, l_save.out_rec = e_buff;
save_all(&l_save);
(void)PT(opts);
rest_all(&l_save);
if (lon)
{
if (g_eof)
{
if (f_list != ((void *)0) && f_list->disp == 'M')
{
(void)fprintf(((__w_FILE *)&__iob[2]), "End of merge file %s", f_list->name);
}
else
{
(void)fprintf(((__w_FILE *)&__iob[2]), "End of input file %s", in_fname);
}
(void)fprintf(((__w_FILE *)&__iob[2]), ", last line = %d\n", g_rec - 1);
}
new_line();
}
}
}
static
void
Xlate(VERB const *const opts)
{
char c;
if (i_col >= i_eor)
{
if (depth)
{
return;
}
g_err(13, ((void *)0));
}
c = xlat(i_buff[i_col++], opts->o1.s, (const unsigned char *)opts->o2.s);
ins(0, &c, 1);
}
static
void
Oldfile(VERB const *const opts)
{
const char *nf = opts->o1.s;
static char *old_new;
if (f_list != ((void *)0))
{
g_err(f_list->disp == 'M' ? 20 : 33, ((void *)0));
}
if (opts->o1.v == 0)
{
if (i_mode == 'F')
{
g_err(50, opts->errp);
}
if ( ( nf = in_fname ) == no_file )
{
nf = in_fname = out_fname;
}
}
else
{
rlsevec(old_new);
out_fname = in_fname = old_new = (char *)getvec(( strlen(nf) + 1 ));
(void)strcpy( (void *)( old_new ), (const void *)( nf ) );
}
i_mode = o_mode = 'N';
vsreload();
if (fscreen)
{
redisplay = 1;
}
prim_changed = 0;
}
static
int
verb(VERB const *const v)
{
int rc;
switch (v->comm)
{
case 'K':
linewrap();
case 'P':
case 'T':
return PT(v);
case 'E':
Exit();
abort();
case 'Q':
Quit();
abort();
case 'I':
case 'D':
Insert(v);
break;
case 'A':
case 'B':
case 'R':
ABR(v);
break;
case 'S':
Save(v);
break;
case 'M':
Merge(v);
break;
case 'U':
Use(v);
break;
case 'X':
Xit(v);
break;
case 'V':
if ( ( rc = Verify(v) ) != 0 && !depth )
{
g_err(19, v->errp);
}
return rc;
case 'O':
Oldfile(v);
break;
case 'Y':
Xlate(v);
break;
case 'N':
Numbers(v);
break;
case '{':
if (v->o1.q == 4)
{
Calc(v->o1.e);
}
else
{
(void)Evaluate(v->o1.e, v->o1.q);
}
break;
case '!':
term();
(void)!system( prep_name(v->o1.s) );
break;
case ':':
if (fscreen)
{
memcpy( (void *)( set_err ), (const void *)( save_err ), ( sizeof ( jmp_buf ) ) );
longjmp(se_ret, 1);
}
if (f_list != ((void *)0))
{
g_err(30, cmd_buf);
}
Screen_ed();
pop_com_stack(&com_stack);
break;
case 'J':
return Join(v);
case 'L':
List(v);
break;
case 'F':
rest_all(&g_save);
break;
case 'H':
Help();
}
return 0;
}
static
int
while_loop(VERB const *const vptr, VERB const *const prog)
{
const int endc = ( vptr->o1.q & 0x2000 ) == 0;
while (Verify(vptr) != endc)
{
if ( George(prog) )
{
return 1;
}
}
return 0;
}
static
int
rec_loop(VERB const *const vptr, VERB const *const prog)
{
int val;
const unsigned int opt = vptr->o1.q;
if (opt & 0x0100)
{
val = (int)Evaluate(vptr->o1.e, 0)->opval.i;
}
else
{
val = vptr->o1.v;
}
switch (opt & 0377U)
{
default:
g_err(7, vptr->errp);
case 3:
val = -val;
case 2:
val += g_rec;
case 6:
if (val < 0)
{
g_err(5, vptr->errp);
}
while (g_rec < val && !g_eof)
{
if ( George(prog) )
{
return 1;
}
}
break;
case 4:
while (o_rec < val)
{
if ( George(prog) )
{
return 1;
}
}
break;
case 5:
while (val--)
{
if ( George(prog) )
{
return 1;
}
}
break;
case 1:
while (!g_eof)
{
if ( George(prog) )
{
return 1;
}
}
break;
case 'B': case 'C': case 'G': case 'F': case 'S': case 'R': case 'r':
while (findstr(vptr->o1.s, val, opt, 'V') && !g_eof)
{
if ( George(prog) )
{
return 1;
}
}
}
return 0;
}
static
int
line_loop(VERB const *const vptr, VERB const *const prog)
{
int val;
const unsigned int opt = vptr->o2.q;
if (opt & 0x0100)
{
val = (int)Evaluate(vptr->o2.e, 0)->opval.i;
}
else
{
val = vptr->o2.v;
}
switch (opt & 0377U)
{
default:
g_err(7, vptr->errp);
case 3:
val = -val;
case 2:
val += i_col;
case 6:
if (val < i_col)
{
g_err(5, vptr->errp);
}
while (i_col < val && i_col < i_eor && !g_eof)
{
if ( George(prog) )
{
return 1;
}
}
break;
case 4:
while (e_col <= val && !g_eof)
{
if ( George(prog) )
{
return 1;
}
}
break;
case 1:
while (i_col < i_eor && !g_eof)
{
if ( George(prog) )
{
return 1;
}
}
break;
case 'S':
if (val)
{
g_err(5, vptr->errp);
}
while ( i_col < i_eor && !g_eof && ( ( i_buff[i_col] ) == 0x20 ) )
{
if ( George(prog) )
{
return 1;
}
}
break;
case 'G':
case 'r':
while ( i_col < i_eor && !g_eof && findstr(vptr->o2.s, val, opt, 'V') )
{
if ( George(prog) )
{
return 1;
}
}
}
return 0;
}
static
int
George(const VERB *v)
{
int rc = 0;
const VERB *prog;
while (v != ((void *)0))
{
switch (v->comm)
{
case '(':
prog = v->next;
v = v->cpar;
++depth;
if (v->o1.q & 0xF000)
{
rc = while_loop(v, prog);
}
else if(v->dot)
rc = line_loop(v, prog);
else
{
rc = rec_loop(v, prog);
}
--depth;
break;
case ';':
if (depth)
{
v = v->cpar;
}
return rc;
case ')':
return rc;
default:
rc = verb(v);
}
if (rc != 0 && depth)
{
do
{
v = v->next;
if (v->comm == ')')
{
return rc;
}
if (v->comm == '(')
{
v = v->cpar;
}
}
while ( v->comm != ';' );
rc = 0;
}
v = v->next;
}
return 0;
}
static
void
Drive(const int level)
{
char ch, *s;
int save, rc = 0, len, done = 0;
string comm;
if (level == 0 && ( rc = _setjmp(set_err) ) == 0)
{
(void)signal(4, g_intr);
memcpy( (void *)( save_err ), (const void *)( set_err ), ( sizeof ( jmp_buf ) ) );
if (g_init == ((void *)0))
{
Screen_ed();
pop_com_stack(&com_stack);
}
}
else if(rc != 0)
pop_com_stack(&com_stack);
else
{
VERB_LIST *p = com_stack_ptr->next;
if (p == ((void *)0))
{
p = com_stack_ptr->next = ( VERB_LIST *)getvec(sizeof ( VERB_LIST ) );
p->prev = com_stack_ptr;
p->next = ((void *)0);
}
com_stack_ptr->save_depth = depth;
com_stack_ptr = p;
p->prog = ((void *)0);
depth = 0;
}
for (;;)
{
running = 0;
if (com_stack_ptr->prog != ((void *)0))
{
free_prog(com_stack_ptr);
}
if (level == 1 || level == 3)
{
if (done++)
{
break;
}
(void)strcpy( (void *)( comm ), (const void *)( cmd_buf ) );
}
else
{
printline(comm);
if ( get_com(comm, comm) )
{
break;
}
}
s_g_rec = g_rec;
s_g_col = e_col;
switch (*comm)
{
case '*':
(void)add_line('T');
case '=':
if ( ( len = hist_recall(comm) ) > 0 )
{
comm[len] = 0x00;
if (!fscreen && lon)
{
say(comm);
}
}
break;
case 0x20:
if (level != 0)
{
for (s = comm; ( ( *s ) == 0x20 ); ++s)
{
;
}
(void)strcpy( (void *)( comm ), (const void *)( s ) );
}
}
if ( ( ch = u_map[*( comm )] ) == ';' )
{
continue;
}
if (level == 0)
{
switch (ch)
{
case '$':
if ( ( g_map[comm[1]] & 010U ) )
{
buff_sec = comm[1] - '0';
}
case 0x20:
continue;
case 0x00:
(void)add_line('T');
continue;
}
}
else if(ch == '$' || ch == 0x00)
continue;
save = level < 2 && ch != 'H' && ch != 'F';
if (save)
{
hist_write(comm);
}
par_stack_ptr = com_stack_ptr;
G_compile(&com_stack_ptr->prog, comm);
++running;
if (com_stack_ptr->prog != ((void *)0))
{
if (par_stack_ptr != com_stack_ptr)
{
char const *const erp = par_stack_ptr->prog->errp;
par_stack_ptr = com_stack_ptr;
g_err(41, erp);
}
if (save)
{
save_all(&g_save);
}
(void)George(com_stack_ptr->prog);
}
}
pop_com_stack(com_stack_ptr->prev);
}
void
main(int i, char const *const * argv)
{
const char *p, *files[2];
PAGE_PTR *cp;
char cvstring[255];
(void)cvstring;
i = 0;
while ( ( p = *++argv ) != ((void *)0) )
{
if (p[0] == '-' && p[1] != 0x00)
{
switch ( u_map[*( ++p )] )
{
case 'B':
++bin_mode;
continue;
case 'R':
++ro_mode;
continue;
case 'S':
if (*++p == 0x00 && argv[1])
{
p = *++argv;
}
if ( ( screen_tabs = atoi(p) ) <= 0 )
{
screen_tabs = 8;
}
continue;
case 'V':
putstr(
"G 4.7.4-dev (2022-03-30)");
_exit(0);
case 'C':
++p;
default:
if (*p != 0x00)
{
g_init = p;
}
else
{
g_init = argv[1] ? *++argv : ";";
}
continue;
}
}
if (i > 1)
{
say("Usage: g [ -rscbv ] [ file [ newfile ] ]");
_exit(1);
}
files[i++] = p;
}
switch (i)
{
case 0:
i_mode = o_mode = 'F';
break;
case 1:
in_fname = out_fname = files[0];
break;
case 2:
in_fname = files[0];
out_fname = files[1];
}
if ( ( *(unsigned int *)in_fname == '-' ) )
{
i_mode = 'F';
}
if ( ( *(unsigned int *)out_fname == '-' ) )
{
o_mode = 'F';
}
i = isatty(0);
if (!i)
{
fd_in_terminal = dup(0);
(void)close(0);
if (open(tty_file, 0x0000) == -1)
{
g_err(39, tty_file);
}
}
if (i_mode == 'F')
{
in_fname = i ? no_file : si_file;
}
if (o_mode == 'F')
{
out_fname = so_file;
fd_out_terminal = dup(1);
(void)close(1);
if (open(tty_file, 0x0001) == -1)
{
g_err(39, tty_file);
}
}
in_u->list = cp = (PAGE_PTR *)getvec(( sizeof ( PAGE_PTR ) * 200 ) * 2 + ( 1022 + 2 ) * 2);
in_u->rec_start = (unsigned char *)( cp + 200 );
i_buff = (char *)( cp + 200 * 2 );
e_buff = i_buff + ( 1022 + 2 );
vsprimary();
if (!i && i_mode != 'F' && Disk_to_mem(empty, trans_u = vsopen(), 'F') > 0)
{
vsreopen(trans_u);
g_init = "u";
}
Drive(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment