123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702 |
- #define __TTYIO_C
- #include "zip.h"
- #include "crypt.h"
- #if (CRYPT || (defined(UNZIP) && !defined(FUNZIP)))
- #include "ttyio.h"
- #ifndef PUTC
- # define PUTC putc
- #endif
- #ifdef ZIP
- # ifdef GLOBAL
- # undef GLOBAL
- # endif
- # define GLOBAL(g) g
- #else
- # define GLOBAL(g) G.g
- #endif
- #if (defined(__ATHEOS__) || defined(__BEOS__))
- # define HAVE_TERMIOS_H
- #endif
- #ifdef _POSIX_VERSION
- # ifndef USE_POSIX_TERMIOS
- # define USE_POSIX_TERMIOS
- # endif
- # ifndef HAVE_TERMIOS_H
- # define HAVE_TERMIOS_H
- # endif
- #endif
- #ifdef UNZIP
- # ifndef _POSIX_VERSION
- # if (defined(SYSV) || defined(CRAY)) && !defined(__MINT__)
- # ifndef USE_SYSV_TERMIO
- # define USE_SYSV_TERMIO
- # endif
- # ifdef COHERENT
- # ifndef HAVE_TERMIO_H
- # define HAVE_TERMIO_H
- # endif
- # ifdef HAVE_SYS_TERMIO_H
- # undef HAVE_SYS_TERMIO_H
- # endif
- # else
- # ifdef HAVE_TERMIO_H
- # undef HAVE_TERMIO_H
- # endif
- # ifndef HAVE_SYS_TERMIO_H
- # define HAVE_SYS_TERMIO_H
- # endif
- # endif
- # endif
- # endif
- # if !(defined(BSD4_4) || defined(SYSV) || defined(__convexc__))
- # ifndef NO_FCNTL_H
- # define NO_FCNTL_H
- # endif
- # endif
- #endif
- #ifdef HAVE_TERMIOS_H
- # ifndef USE_POSIX_TERMIOS
- # define USE_POSIX_TERMIOS
- # endif
- #endif
- #if (defined(HAVE_TERMIO_H) || defined(HAVE_SYS_TERMIO_H))
- # ifndef USE_SYSV_TERMIO
- # define USE_SYSV_TERMIO
- # endif
- #endif
- #if (defined(UNZIP) && !defined(FUNZIP) && defined(UNIX) && defined(MORE))
- # include <sys/ioctl.h>
- # define GOT_IOCTL_H
-
- #endif
- #ifndef HAVE_WORKING_GETCH
-
- # ifdef VMS
- # include <descrip.h>
- # include <iodef.h>
- # include <ttdef.h>
- # include <starlet.h>
- # include <ssdef.h>
- # else
- # ifdef HAVE_TERMIOS_H
- # include <termios.h>
- # define sgttyb termios
- # define sg_flags c_lflag
- # define GTTY(f, s) tcgetattr(f, (zvoid *) s)
- # define STTY(f, s) tcsetattr(f, TCSAFLUSH, (zvoid *) s)
- # else
- # ifdef USE_SYSV_TERMIO
- # ifdef HAVE_TERMIO_H
- # include <termio.h>
- # endif
- # ifdef HAVE_SYS_TERMIO_H
- # include <sys/termio.h>
- # endif
- # ifdef NEED_PTEM
- # include <sys/stream.h>
- # include <sys/ptem.h>
- # endif
- # define sgttyb termio
- # define sg_flags c_lflag
- # define GTTY(f,s) ioctl(f,TCGETA,(zvoid *)s)
- # define STTY(f,s) ioctl(f,TCSETAW,(zvoid *)s)
- # else
- # ifndef CMS_MVS
- # if (!defined(MINIX) && !defined(GOT_IOCTL_H))
- # include <sys/ioctl.h>
- # endif
- # include <sgtty.h>
- # define GTTY gtty
- # define STTY stty
- # ifdef UNZIP
-
-
- # endif
- # endif
- # endif
- # endif
- # ifndef NO_FCNTL_H
- # ifndef UNZIP
- # include <fcntl.h>
- # endif
- # else
- char *ttyname OF((int));
- # endif
- # endif
- #endif
- #ifndef HAVE_WORKING_GETCH
- #ifdef VMS
- static struct dsc$descriptor_s DevDesc =
- {11, DSC$K_DTYPE_T, DSC$K_CLASS_S, "SYS$COMMAND"};
-
- int echo(opt)
- int opt;
- {
-
- short DevChan, iosb[4];
- long status;
- unsigned long ttmode[2];
-
- status = sys$assign(&DevDesc, &DevChan, 0, 0);
- if (!(status & 1))
- return status;
-
- status = sys$qiow(0, DevChan, IO$_SENSEMODE, &iosb, 0, 0,
- ttmode, 8, 0, 0, 0, 0);
- if (!(status & 1))
- return status;
- status = iosb[0];
- if (!(status & 1))
- return status;
-
- if (opt == 0)
- ttmode[1] |= TT$M_NOECHO;
- else
- ttmode[1] &= ~((unsigned long) TT$M_NOECHO);
-
- status = sys$qiow(0, DevChan, IO$_SETMODE, &iosb, 0, 0,
- ttmode, 8, 0, 0, 0, 0);
- if (!(status & 1))
- return status;
- status = iosb[0];
- if (!(status & 1))
- return status;
-
- status = sys$dassgn(DevChan);
- if (!(status & 1))
- return status;
- return SS$_NORMAL;
- }
- int tt_getch()
- {
- short DevChan, iosb[4];
- long status;
- char kbbuf[16];
-
- status = sys$assign(&DevDesc, &DevChan, 0, 0);
- if (!(status & 1))
- return EOF;
-
- status = sys$qiow(0,DevChan,
- IO$_READVBLK|IO$M_NOECHO|IO$M_NOFILTR,
- &iosb, 0, 0,
- &kbbuf, 1, 0, 0, 0, 0);
- if ((status&1) == 1)
- status = iosb[0];
-
- sys$dassgn(DevChan);
-
- return (int)(((status&1) == 1) ? (uch)kbbuf[0] : EOF);
- }
- #else
- #ifndef CMS_MVS
- #ifdef ZIP
- static int echofd=(-1);
- #endif
- void Echoff(__G__ f)
- __GDEF
- int f;
- {
- struct sgttyb sg;
- GLOBAL(echofd) = f;
- GTTY(f, &sg);
- sg.sg_flags &= ~ECHO;
- STTY(f, &sg);
- }
- void Echon(__G)
- __GDEF
- {
- struct sgttyb sg;
- if (GLOBAL(echofd) != -1) {
- GTTY(GLOBAL(echofd), &sg);
- sg.sg_flags |= ECHO;
- STTY(GLOBAL(echofd), &sg);
- GLOBAL(echofd) = -1;
- }
- }
- #endif
- #endif
- #if (defined(UNZIP) && !defined(FUNZIP))
- #ifdef ATH_BEO_UNX
- #ifdef MORE
- #if (defined(TIOCGWINSZ) && !defined(M_UNIX))
- int screensize(tt_rows, tt_cols)
- int *tt_rows;
- int *tt_cols;
- {
- struct winsize wsz;
- #ifdef DEBUG_WINSZ
- static int firsttime = TRUE;
- #endif
-
- if (ioctl(1, TIOCGWINSZ, &wsz) == 0) {
- #ifdef DEBUG_WINSZ
- if (firsttime) {
- firsttime = FALSE;
- fprintf(stderr, "ttyio.c screensize(): ws_row = %d\n",
- wsz.ws_row);
- fprintf(stderr, "ttyio.c screensize(): ws_col = %d\n",
- wsz.ws_col);
- }
- #endif
-
- if (tt_rows != NULL)
- *tt_rows = (int)((wsz.ws_row > 0) ? wsz.ws_row : 24);
-
- if (tt_cols != NULL)
- *tt_cols = (int)((wsz.ws_col > 0) ? wsz.ws_col : 80);
- return 0;
- } else {
- #ifdef DEBUG_WINSZ
- if (firsttime) {
- firsttime = FALSE;
- fprintf(stderr,
- "ttyio.c screensize(): ioctl(TIOCGWINSZ) failed\n"));
- }
- #endif
-
- if (tt_rows != NULL)
- *tt_rows = 24;
- if (tt_cols != NULL)
- *tt_cols = 80;
- return 1;
- }
- }
- #else
- int screensize(tt_rows, tt_cols)
- int *tt_rows;
- int *tt_cols;
- {
- char *envptr, *getenv();
- int n;
- int errstat = 0;
-
- if (tt_rows != NULL) {
- envptr = getenv("LINES");
- if (envptr == (char *)NULL || (n = atoi(envptr)) < 5) {
-
- *tt_rows = 24;
- errstat = 1;
- } else {
- *tt_rows = n;
- }
- }
- if (tt_cols != NULL) {
- envptr = getenv("COLUMNS");
- if (envptr == (char *)NULL || (n = atoi(envptr)) < 5) {
- *tt_cols = 80;
- errstat = 1;
- } else {
- *tt_cols = n;
- }
- }
- return errstat;
- }
- #endif
- #endif
- int zgetch(__G__ f)
- __GDEF
- int f;
- {
- #if (defined(USE_SYSV_TERMIO) || defined(USE_POSIX_TERMIOS))
- char oldmin, oldtim;
- #endif
- char c;
- struct sgttyb sg;
- GTTY(f, &sg);
- #if (defined(USE_SYSV_TERMIO) || defined(USE_POSIX_TERMIOS))
- oldmin = sg.c_cc[VMIN];
- oldtim = sg.c_cc[VTIME];
- sg.c_cc[VMIN] = 1;
- sg.c_cc[VTIME] = 0;
- sg.sg_flags &= ~ICANON;
- #else
- sg.sg_flags |= CBREAK;
- #endif
- sg.sg_flags &= ~ECHO;
- STTY(f, &sg);
- GLOBAL(echofd) = f;
- read(f, &c, 1);
- #if (defined(USE_SYSV_TERMIO) || defined(USE_POSIX_TERMIOS))
- sg.c_cc[VMIN] = oldmin;
- sg.c_cc[VTIME] = oldtim;
- sg.sg_flags |= ICANON;
- #else
- sg.sg_flags &= ~CBREAK;
- #endif
- sg.sg_flags |= ECHO;
- STTY(f, &sg);
- GLOBAL(echofd) = -1;
- return (int)(uch)c;
- }
- #else
- #ifndef VMS
- int zgetch(__G__ f)
- __GDEF
- int f;
- {
- char c, c2;
- echoff(f);
- read(f, &c, 1);
- if (c != '\n')
- do {
- read(f, &c2, 1);
- } while (c2 != '\n');
- echon();
- return (int)c;
- }
- #endif
- #endif
- #endif
- #endif
- #if CRYPT
- #if (!defined(CR_MAJORVER) || (CR_MAJORVER < 2) || (CR_MINORVER < 7))
- error: This Info-ZIP tool requires zcrypt 2.7 or later.
- #endif
- #ifdef HAVE_WORKING_GETCH
- #ifndef WINDLL
- #ifndef QDOS
- char *getp(__G__ m, p, n)
- __GDEF
- ZCONST char *m;
- char *p;
- int n;
- {
- char c;
- int i;
- char *w;
-
- w = "";
- do {
- fputs(w, stderr);
- fputs(m, stderr);
- fflush(stderr);
- i = 0;
- do {
- if ((c = (char)getch()) == '\r')
- c = '\n';
- if (c == 8 || c == 127) {
- if (i > 0) i--;
- }
- else if (i < n)
- p[i++] = c;
- } while (c != '\n');
- PUTC('\n', stderr); fflush(stderr);
- w = "(line too long--try again)\n";
- } while (p[i-1] != '\n');
- p[i-1] = 0;
- return p;
- }
- #endif
- #endif
- #else
- #if (defined(ATH_BEO_UNX) || defined(__MINT__))
- #ifndef _PATH_TTY
- # ifdef __MINT__
- # define _PATH_TTY ttyname(2)
- # else
- # define _PATH_TTY "/dev/tty"
- # endif
- #endif
- char *getp(__G__ m, p, n)
- __GDEF
- ZCONST char *m;
- char *p;
- int n;
- {
- char c;
- int i;
- char *w;
- int f;
- #ifdef PASSWD_FROM_STDIN
-
- f = 0;
- #else
-
- if ((f = open(_PATH_TTY, 0)) == -1)
- return NULL;
- #endif
-
- w = "";
- do {
- fputs(w, stderr);
- fputs(m, stderr);
- fflush(stderr);
- i = 0;
- echoff(f);
- do {
- read(f, &c, 1);
- if (i < n)
- p[i++] = c;
- } while (c != '\n');
- echon();
- PUTC('\n', stderr); fflush(stderr);
- w = "(line too long--try again)\n";
- } while (p[i-1] != '\n');
- p[i-1] = 0;
- #ifndef PASSWD_FROM_STDIN
- close(f);
- #endif
- return p;
- }
- #endif
- #if (defined(VMS) || defined(CMS_MVS))
- char *getp(__G__ m, p, n)
- __GDEF
- ZCONST char *m;
- char *p;
- int n;
- {
- char c;
- int i;
- char *w;
- FILE *f;
- #ifdef PASSWD_FROM_STDIN
- f = stdin;
- #else
- if ((f = fopen(ctermid(NULL), "r")) == NULL)
- return NULL;
- #endif
-
- fflush(stdout);
- w = "";
- do {
- if (*w)
- fputs(w, stderr);
- fputs(m, stderr);
- fflush(stderr);
- i = 0;
- echoff(f);
- do {
- if ((c = (char)getc(f)) == '\r')
- c = '\n';
- if (i < n)
- p[i++] = c;
- } while (c != '\n');
- echon();
- PUTC('\n', stderr); fflush(stderr);
- w = "(line too long--try again)\n";
- } while (p[i-1] != '\n');
- p[i-1] = 0;
- #ifndef PASSWD_FROM_STDIN
- fclose(f);
- #endif
- return p;
- }
- #endif
- #endif
- #endif
- #endif
|