Archive-Unzip-Burst

 view release on metacpan or  search on metacpan

unzip-6.0/ttyio.c  view on Meta::CPAN

}


#else /* !ATH_BEO_UNX */
#ifndef VMS     /* VMS supplies its own variant of getch() */


int zgetch(__G__ f)
    __GDEF
    int f;    /* file descriptor from which to read (must be open already) */
{
    char c, c2;

/*---------------------------------------------------------------------------
    Get a character from the given file descriptor without echo; can't fake
    CBREAK mode (i.e., newline required), but can get rid of all chars up to
    and including newline.
  ---------------------------------------------------------------------------*/

    echoff(f);
    read(f, &c, 1);
    if (c != '\n')
        do {
            read(f, &c2, 1);   /* throw away all other chars up thru newline */
        } while (c2 != '\n');
    echon();
    return (int)c;
}

#endif /* !VMS */
#endif /* ?ATH_BEO_UNX */

#endif /* UNZIP && !FUNZIP */
#endif /* !HAVE_WORKING_GETCH */


#if CRYPT                       /* getp() is only used with full encryption */

/*
 * Simple compile-time check for source compatibility between
 * zcrypt and ttyio:
 */
#if (!defined(CR_MAJORVER) || (CR_MAJORVER < 2) || (CR_MINORVER < 7))
   error:  This Info-ZIP tool requires zcrypt 2.7 or later.
#endif

/*
 * Get a password of length n-1 or less into *p using the prompt *m.
 * The entered password is not echoed.
 */

#ifdef HAVE_WORKING_GETCH
/*
 * For the AMIGA, getch() is defined as Agetch(), which is in
 * amiga/filedate.c; SAS/C 6.x provides a getch(), but since Agetch()
 * uses the infrastructure that is already in place in filedate.c, it is
 * smaller.  With this function, echoff() and echon() are not needed.
 *
 * For the MAC, a non-echo macgetch() function is defined in the MacOS
 * specific sources which uses the event handling mechanism of the
 * desktop window manager to get a character from the keyboard.
 *
 * For the other systems in this section, a non-echo getch() function
 * is either contained the C runtime library (conio package), or getch()
 * is defined as an alias for a similar system specific RTL function.
 */

#ifndef WINDLL   /* WINDLL does not support a console interface */
#ifndef QDOS     /* QDOS supplies a variant of this function */

/* This is the getp() function for all systems (with TTY type user interface)
 * that supply a working `non-echo' getch() function for "raw" console input.
 */
char *getp(__G__ m, p, n)
    __GDEF
    ZCONST char *m;             /* prompt for password */
    char *p;                    /* return value: line input */
    int n;                      /* bytes available in p[] */
{
    char c;                     /* one-byte buffer for read() to use */
    int i;                      /* number of characters input */
    char *w;                    /* warning on retry */

    /* get password */
    w = "";
    do {
        fputs(w, stderr);       /* warning if back again */
        fputs(m, stderr);       /* display prompt and flush */
        fflush(stderr);
        i = 0;
        do {                    /* read line, keeping first n characters */
            if ((c = (char)getch()) == '\r')
                c = '\n';       /* until user hits CR */
            if (c == 8 || c == 127) {
                if (i > 0) i--; /* the `backspace' and `del' keys works */
            }
            else if (i < n)
                p[i++] = c;     /* truncate past n */
        } while (c != '\n');
        PUTC('\n', stderr);  fflush(stderr);
        w = "(line too long--try again)\n";
    } while (p[i-1] != '\n');
    p[i-1] = 0;                 /* terminate at newline */

    return p;                   /* return pointer to password */

} /* end function getp() */

#endif /* !QDOS */
#endif /* !WINDLL */


#else /* !HAVE_WORKING_GETCH */


#if (defined(ATH_BEO_UNX) || defined(__MINT__))

#ifndef _PATH_TTY
#  ifdef __MINT__
#    define _PATH_TTY ttyname(2)
#  else



( run in 1.065 second using v1.01-cache-2.11-cpan-5b529ec07f3 )