--- pgp/src/system.c 2018/04/24 16:40:44 1.1.1.5 +++ pgp/src/system.c 2018/04/24 16:45:12 1.1.1.9 @@ -3,7 +3,7 @@ * * Routines specific for non-MSDOS implementations of pgp. * - * (c) Copyright 1990-1994 by Philip Zimmermann. All rights reserved. + * (c) Copyright 1990-1996 by Philip Zimmermann. All rights reserved. * The author assumes no liability for damages resulting from the use * of this software, even if the damage results from defects in this * software. No warranty is expressed or implied. @@ -148,7 +148,12 @@ void ttycbreak(void) tio.c_cc[VTIME] = 0; tio.c_lflag &= ~(ECHO|ICANON); #ifndef SVR2 +#ifdef ultrix + /* Ultrix is broken and flushes the output as well! */ + tcsetattr (ttyfd, TCSANOW, &tio); +#else tcsetattr (ttyfd, TCSAFLUSH, &tio); +#endif #else ioctl(ttyfd, TCSETAF, &tio); #endif /* not SVR2 */ @@ -187,7 +192,12 @@ void ttynorm(void) #endif #ifndef NOTERMIO #ifndef SVR2 +#ifdef ultrix + /* Ultrix is broken and flushes the output as well! */ + tcsetattr (ttyfd, TCSANOW, &itio); +#else tcsetattr (ttyfd, TCSAFLUSH, &itio); +#endif #else ioctl(ttyfd, TCSETAF, &itio); #endif /* not SVR2 */ @@ -289,9 +299,10 @@ int getch(void) c = kbuf; kbuf = -1; #else + c = 0; read(ttyfd, &c, 1); #endif - return(c); + return(c & 0xFF); } #if defined(_BSD) && !defined(__STDC__) @@ -330,7 +341,8 @@ register int n; } #endif /* _BSD */ -#if (defined(MACH) || defined(SVR2) || defined(_BSD)) && !defined(NEXT) && !defined(AUX) || (defined(sun) && defined(i386)) +#if (defined(MACH) || defined(SVR2) || defined(_BSD)) && !defined(NEXT) \ +&& !defined(AUX) && !defined(__MACHTEN__) || (defined(sun) && defined(i386)) int remove(name) char *name; { @@ -357,7 +369,8 @@ register char *old, *new; long Clock() /* not a replacement for clock(), just for random number generation */ { -#if defined(_BSD) || (defined(sun) && !defined(SOLARIS)) || defined(MACH) || defined(linux) +#if defined(_BSD) || (defined(sun) && !defined(SOLARIS)) || \ +defined(MACH) || defined(linux) #include #include struct rusage ru; @@ -484,7 +497,8 @@ static volatile struct { int ExtChar; } CharBuf, OldCharBuf; -static $DESCRIPTOR (out_file_descr, "SYS$DISK:[]"); /* Default Output File Descr */ +static $DESCRIPTOR (out_file_descr, "SYS$DISK:[]"); /* Default Output + File Descr */ static int flags = FDL$M_FDL_STRING; @@ -832,7 +846,8 @@ void ttycbreak () 0, 0, &buf, - (TypCharBuf.TypAhdCnt >= 80 ? 80 : TypCharBuf.TypAhdCnt), + (TypCharBuf.TypAhdCnt >= 80 ? 80 : + TypCharBuf.TypAhdCnt), 1, &NoTerm, 0, @@ -863,7 +878,8 @@ void ttycbreak () 0, 0)) & 01) sts = iosb.sts; if (!(sts & 01)) { - fprintf(stderr,"\nttybreak()- Failed to set terminal characteristics!"); + fprintf(stderr, + "\nttybreak()- Failed to set terminal characteristics!"); (void) lib$signal(sts); exitPGP(1); } @@ -913,8 +929,8 @@ int vms_GetCmd( char *cmdtbl) */ verb_size = cmdprmt_d.dsc$w_length - 2; /* Loose '> ' characters */ cmdbuf_d.dsc$w_length = MAX_CMDSIZ-verb_size-1; - cmdbuf_d.dsc$a_pointer = strncpy(cmdbuf,cmdprmt_d.dsc$a_pointer,verb_size) + - verb_size+1; + cmdbuf_d.dsc$a_pointer = strncpy(cmdbuf,cmdprmt_d.dsc$a_pointer,verb_size) + + verb_size+1; cmdbuf[verb_size++]=' '; if ((sts = lib$get_foreign ( /* Recover command line from DCL */ &cmdbuf_d, @@ -923,7 +939,8 @@ int vms_GetCmd( char *cmdtbl) 0)) & 01) { cmdbuf_d.dsc$a_pointer = cmdbuf; cmdbuf_d.dsc$w_length = cmdsiz + verb_size; - VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled exceptions to return */ + VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled exceptions + to return */ sts = cli$dcl_parse( /* Parse Command Line */ &cmdbuf_d, cmdtbl, @@ -965,7 +982,8 @@ vms_TstOpt(char opt) struct dsc$descriptor option_d = { 1, 0, 0, &buf}; buf = _toupper(opt); - VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled exceptions to return */ + VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled exceptions + to return */ switch (sts=cli$present(&option_d)) { @@ -1010,7 +1028,8 @@ vms_GetVal( char opt, char *resval, unsi struct dsc$descriptor value_d = {maxsiz-1, 0, 0, resval }; unsigned short valsiz; - VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled exceptions to return */ + VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled exceptions + to return */ buf = _toupper(opt); if ((sts = cli$get_value( &option_d, @@ -1049,7 +1068,8 @@ vms_GetArg( unsigned short arg, char *re struct dsc$descriptor value_d = {maxsiz-1, 0, 0, resval }; unsigned short valsiz; - VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled exceptions to return */ + VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled exceptions + to return */ buf[1] = arg + '0'; if ((sts = cli$present(&option_d)) & 01) { if ((sts = cli$get_value( @@ -1092,7 +1112,8 @@ do_help(char *helptext, char *helplib) struct dsc$descriptor helptext_d = { strlen(helptext), 0, 0, helptext}; struct dsc$descriptor helplib_d = { strlen(helplib), 0, 0, helplib}; - VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled exceptions to return */ + VAXC$ESTABLISH(lib$sig_to_ret); /* Force unhandled + exceptions to return */ if (((sts = kbhit_Getchn()) & 01) || sts == 0) { helpflags = HLP$M_PROMPT|HLP$M_SYSTEM|HLP$M_GROUP|HLP$M_PROCESS; sts = lbr$output_help( @@ -1201,7 +1222,8 @@ int fdl_generate(char *in_file, char **f &badblk, len)) & 01)) { if (verbose) - fprintf(stderr,"\n(SYSTEM) Failed to generate FDL\n",in_file); + fprintf(stderr,"\n(SYSTEM) Failed to generate FDL\n", + in_file); free(fdl); } else { if (!(*fdl = malloc(*len))) return(0); @@ -1339,7 +1361,8 @@ VOID * fdl_create( char *fdl, short len, fdl_close(rab); } else sts = rab; } - fab->fab$l_nam = 0; /* I allocated NAM block, so I must deallocate it! */ + fab->fab$l_nam = 0; /* I allocated NAM block, + so I must deallocate it! */ } free(resnam); return(sts); @@ -1386,15 +1409,16 @@ int fdl_copyfile2bin( FILE *f, VOID *rab count = fread(textbuf,1,count,f); if (count > 0) { /* - * No byte order conversion required, source and target system are both VMS so have - * the same byte ordering. + * No byte order conversion required, source and target system are both + * VMS so have the same byte ordering. */ ((struct RAB *) rab)->rab$w_rsz = (unsigned short) count; if (!(sys$write ( rab, NULL, NULL) & 01)) { - lib$signal(((struct RAB *) rab)->rab$l_sts,((struct RAB *) rab)->rab$l_stv); + lib$signal(((struct RAB *) rab)->rab$l_sts, + ((struct RAB *) rab)->rab$l_stv); status = 1; break; } @@ -1518,34 +1542,130 @@ int vms_fileparse( char *outbuf, char *f #endif /* VMS */ -/*========================================================================*/ /* - * AMIGA + * ------------------------- Amiga specific routines ------------------------- */ -#ifdef AMIGA /* Amiga-specific stuff */ +#ifdef AMIGA -#include +#include +#include #include #include +#include #include -#ifdef LATTICE -#include +#include #include -#endif /* LATTICE */ -extern FILE *pgpout; -extern int aecho; +#include +#include +#include "pgp.h" +/* + * This getenv will use the WB2.0 calls if you have the 2.0 + * rom. If not, it resorts to looking in the ENV: directory. + */ -/* amiga version of getch() - Cor Bosman , jul-22-92 -*/ +/* + * I am sorry to report that SAS/C is buggy. :-( + * It doesn't recognize replacement routines if they are linked + * to the main code and not included in the file itself. I hate + * stuff like that. :-( + * -peter + */ +char *amiga_getenv(const char *name) +{ + FILE *fp; + char *ptr; + static char value[256]; + static char buf[256]; + + /* + * 2.0 style? + */ + if (DOSBase->dl_lib.lib_Version >= 36) { + if (GetVar((char *) name, value, 256, 0L) == -1) + return NULL; + } + else { + if (strlen(name) > 252) + return NULL; + strcpy(buf, "ENV:"); + strcpy(&buf[4], name); + if (!(fp = fopen(buf, "r"))) + return NULL; + for (ptr = value; (*ptr = getc(fp)) != EOF + && *ptr != '\n' + && ++ptr < &value[256];) ; + fclose(fp); + *ptr = 0; + } + return value; +} + + +extern FILE *pgpout; +char *requesterdesc; + +/* + * AmigaRequestString() is a trick to make PGP more usable from scripts. + * The problem is, that most scripts don't allow user interaction over + * the standard input. The same problem occurs when working in filter mode. + * + * This routine will be called by PGP's getstring() whenever user input + * is requested but the standard input is not interactive. Because the + * routine can't know what string to ask for, I added the Amiga-specific + * variable requesterdesc, which holds the last string printed to pgpout + * before getstring was called. + * + * This solution is not pretty, but it works. + * Peter Simons + */ + +int AmigaRequestString(char *buffer, int maxlen, int echo) +{ + struct ReqToolsBase *ReqToolsBase; + struct TagItem ti[] = { + {RTGS_Invisible, FALSE}, + {RTGS_TextFmt, 0L}, + {RTGS_Flags, GSREQF_CENTERTEXT}, + {TAG_DONE, 0L} + }; + int len = 0; + char name[64]; + + if (!maxlen) + return 0; + if (!echo) + ti[0].ti_Data = TRUE; + ti[1].ti_Data = (ULONG) (requesterdesc) ? ((*requesterdesc == '\n') ? requesterdesc+1 : requesterdesc) : "Please enter required string"; + /* This one is tricky, too. Because of the format of the + * LANG() module we have a prefacing return before most + * strings, which will make our beautiful requester look + * a bit stupid. This way, we get rid of it. :-) + */ + sprintf(name, "PGPAmiga %s", rel_version); + + if (ReqToolsBase = (struct ReqToolsBase *) OpenLibrary(REQTOOLSNAME, 38L)) + { + *buffer = '\0'; + if (rtGetStringA(buffer, maxlen, name, NULL, ti)) + len = strlen(buffer); + CloseLibrary((struct Library *) ReqToolsBase); + } + else + { fprintf(stderr,"Could not open ReqTools.library! Try using PGP " + "without -f.\n"); + exitPGP(7); /* Error exit */ + } + requesterdesc=NULL; /* Program will re-set it before next getstring() call */ + return len; +} sendpacket(struct MsgPort *rec,LONG action,LONG arg1) { struct StandardPacket *pkt; - struct msgPort *rp; + struct MsgPort *rp; LONG res1 = 0L; if (rp = (struct MsgPort *)CreatePort(NULL,0L)) { @@ -1568,125 +1688,96 @@ sendpacket(struct MsgPort *rec,LONG acti } -/* ttycbreak for amiga. - * Cor Bosman , jul-30-92 -*/ - -void ttycbreak() +void ttycbreak(void) { - BPTR in,out; - char buf[128]; struct MsgPort *ch; - in=Input(); - out=Output(); - ch = ((struct FileHandle *)BADDR(in))->fh_Type; + ch = ((struct FileHandle *)BADDR(Input()))->fh_Type; sendpacket(ch,ACTION_SCREEN_MODE,-1L); } -/* ttynorm for amiga - * Cor Bosman , jul-30-92 -*/ - -void ttynorm() +void ttynorm(void) { - - BPTR in,out; - char buf[128]; struct MsgPort *ch; - in=Input(); - out=Output(); - ch = ((struct FileHandle *)BADDR(in))->fh_Type; + ch = ((struct FileHandle *)BADDR(Input()))->fh_Type; sendpacket(ch,ACTION_SCREEN_MODE,0L); } -char getch(void) +int getch(void) { - char buf[128]; - BPTR in,out; + char buf; - in = Input(); - out = Output(); - Read(in,buf,1); - if (aecho) - Write(out, buf, 1); - return(buf[0]); + Read(Input(),&buf,1); + return((int)buf); } -/* kbhit() function for amiga. - * Cor Bosman , jul-30-92 -*/ - -int kbhit() +int kbhit(void) { if(WaitForChar(Input(), 1)) return 1; return 0; } -#ifdef LATTICE +/* GetSysTime problem with WB 1.3 fixed by A. Hartley (february@genie.com) */ + +extern struct timerequest *TimerIO; /* Defined in random.c */ + +void am_GetSysTime(struct timeval *tv) +{ + TimerIO->tr_node.io_Command=TR_GETSYSTIME; + DoIO((struct IORequest *) TimerIO); + *tv=TimerIO->tr_time; +} + +#ifdef __SASC /* - * Lattice-C ^C-Handler -*/ + * SAS/C CTRL-C handler + */ -int CXBRK() +void __regargs _CXBRK(void) { - BPTR in,out; struct MsgPort *ch; - in=Input(); - out=Output(); /* it might happen we catch a ^C while in cbreak mode. * so always set the screen to the normal mode. */ - ch = ((struct FileHandle *)BADDR(in))->fh_Type; + ch = ((struct FileHandle *)BADDR(Input()))->fh_Type; sendpacket(ch, ACTION_SCREEN_MODE, 0L); fprintf(pgpout, "\n*** Program Aborted.\n"); exitPGP(6); /* INTERRUPT */ } -#endif - -/*------------------------------------------------------------------------ - * clock.c -- time in microseconds since first call of clock() - * - * RP: this function is missing from SAS/C library. - */ - -#include - -long clock() -{ - static unsigned long oldms = -1; - unsigned long cl[2],ms; - - timer(cl); - ms = cl[0] * 1000000 + cl[1] % 1000000; - if(oldms == -1) { - oldms = ms; - return 0; - } else { - return ((long)(ms-oldms)); - } -} - +#endif /* __SASC */ #endif /* AMIGA */ - /*===========================================================================*/ /* * other stuff for non-MSDOS systems */ #ifdef ATARI -#include +#ifdef __PUREC__ +#include +#else +#include /* use GEMDOS functions for I/O */ #endif +int kbhit(void) +{ + return Cconis(); /* ret == 0 : no char available */ +} + +int getch(void) +{ + return (Cnecin() & 0x000000FF); /* ASCII-Code in Bits 0..7 */ +} /* Scan-Codes in Bits 16..23 */ +#endif /* ATARI */ + #if !defined(MSDOS) && !defined(ATARI) #include #include "charset.h" @@ -1789,3 +1880,125 @@ int getch(void) #endif /* OS2 */ #endif /* MSDOS */ + +#ifdef MACTC5 /* 203a */ + +#include "My_console.h" + +int getch(void) { + while( !kbhit() ); + return( getc(stdin) ); +} + +int kbhit(void) { + int kbuf; + + csetmode(C_RAW, stdin); + kbuf = getc(stdin); + if( kbuf != EOF ) ungetc((kbuf & 0xff), stdin); + csetmode(C_ECHO, stdin); + return( (kbuf == EOF) ? 0 : 1 ); +} + +#endif + +/*EWS Fix -f lockup on passphrase prompts for TURBO C++ */ +#if defined(MSDOS) && !defined(__GO32__) && defined(__TURBOC__) +#include +#include + +#if !defined(_KEYBRD_READY) +#define _KEYBRD_READY 1 /* To support old versions of Turbo C */ +#endif +#if !defined(_KEYBRD_READ) +#define _KEYBRD_READ 0 /* To support old versions of Turbo C */ +#endif + +int kbhit(void) +{ + int c; + c=bioskey(_KEYBRD_READY); + if (c != 0) c=1; + return c; +} /*kbhit*/ + +int getch(void) +{ + int c; + c=bioskey(_KEYBRD_READ); + if (c==11779) raise(SIGINT); /* Ctrl-C */ + return c & 0xff; +} /*getch*/ +#endif + +/*EWS Fix -f lockup on passphrase prompts for MSC */ +#if defined(MSDOS) && !defined(__GO32__) && defined(_MSC_VER) +#include +#include +#include + +int getcbrk(void) +{ + union REGS r; + + r.x.ax=0x3300; + intdos(&r, &r); + return(r.h.dl); +} + +int setcbrk(int xx) +{ + union REGS r; + + r.x.ax=0x3301; + r.h.dl=xx; + intdos(&r, &r); + return(r.h.dl); +} + +int kbhit(void) +{ + int c; + c=_bios_keybrd(_KEYBRD_READY); + if (c != 0) c=1; + return c; +} /*kbhit*/ + +int getch(void) +{ + int c; + c=_bios_keybrd(_KEYBRD_READ); + if (c==11779) raise(SIGINT); /* Ctrl-C */ + return c & 0xff; +} /*getch*/ +#endif + +#ifdef EBCDIC +static int kbuf = -1; + +int kbhit(void) +{ + int ch; + if (kbuf >= 0) + return 1; + if (ch = getchar()) { + kbuf = ch; + return 1; + } + return 0; +} + +int getch(void) +{ + int ch; + while (!kbhit()); + ch = kbuf; + kbuf = -1; + return ch; +} + +int c370_rename(char *from, char *to) +{ + return rename(from,to) == 0 ? 0 : -1; +} +#endif /* EBCDIC */