/* * amiopenwin - opens a window if we don't already have one. */ void amiopenwin(char *termtype) { if (!IsInteractive(Input())) { /* open our own window in RAW mode */ if (isOldDOS() || (BPTR) 0 == (fh = Open(title, MODE_READWRITE))) { PutStr((UBYTE *) "Couldn't open RAW: window"); clean_exit(2); } else { oldinputFH = SelectInput(fh); oldoutputFH = SelectOutput(fh); } } inputFH = Input(); outputFH = Output(); if (!strcmp(termtype, TERMTYPE)) { amigaterm = 1; Write(outputFH, AUTOWRAP_OFF, sizeof(AUTOWRAP_OFF)); } return; }
/* * ttyshutdown - console shutdown routine for Amiga Computers. * * Resets raw mode and disables resize notifications. */ void ttyshutdown() { if (amigaterm) { Write(outputFH, RAW_EVENTS_OFF, sizeof(RAW_EVENTS_OFF)); } if (isOldDOS()) { setRawCon(DOSFALSE); } else { SetMode(inputFH, 0); /* Leave RAW mode */ } return; }
/* * ttysetup - console initalization routine for Amiga Computers. * * Sets raw mode and enables resize notifications. */ void ttysetup() { if (isOldDOS()) { setRawCon(DOSTRUE); } else { SetMode(inputFH, 1); /* Enter RAW mode */ } if (amigaterm) { Write(outputFH, RAW_EVENTS_ON, sizeof(RAW_EVENTS_ON)); } return; }
/* * matchwild - pushes filenames which match the given pattern. * it also returns a count of the matches found. */ int matchwild(char *pattern) { static char *special = "#?*%([|"; /* )] */ struct AnchorPath *APath; int matches = 0; LONG error; /* Check if correct OS */ if (isOldDOS()) return; /* Check if pattern is special */ if (!(strpbrk(pattern, special))) return; APath = AllocMem(sizeof(struct AnchorPath) + BLKSIZE, MEMF_CLEAR); if (!(APath)) return; APath->ap_Strlen = BLKSIZE; APath->ap_BreakBits = SIGBREAKF_CTRL_C; if ((error = MatchFirst((UBYTE *) pattern, APath)) == 0) { do { ++matches; push(strdup((char *) APath->ap_Buf)); } while ((error = MatchNext(APath)) == 0); } MatchEnd(APath); if (error != ERROR_NO_MORE_ENTRIES) { PrintFault(error, NULL); } FreeMem(APath, sizeof(struct AnchorPath) + BLKSIZE); return matches; }
/* * Aztec's library getenv() doesn't allow for Environment variables larger than * 256 bytes. It also doesn't check the local environment, which would make * elvis running on an AUX: port more useful. */ char * getenv(char *var) { static char *buf; buf = (char *) malloc(sizeof(*buf) * (ENVSIZE + 1)); if ((char *) 0 == buf) { return 0; } if (isOldDOS()) { int bytes; BPTR fh; strcpy(buf, "env:"); strcat(buf, var); fh = Open((UBYTE *) buf, MODE_OLDFILE); if ((BPTR) 0 == fh) { _free_(buf); return (char *) 0; /* return null for not defined */ } bytes = Read(fh, (UBYTE *) buf, ENVSIZE); Close(fh); if (bytes == -1) { _free_(buf); return (char *) 0; /* return null for not defined */ } buf[bytes] = '\000'; } else if (-1 == GetVar((UBYTE *) var, (UBYTE *) buf, ENVSIZE, GVF_BINARY_VAR)) { /* no varible defined, free memory */ _free_(buf); return (char *) 0; /* return null for not defined */ } return (char *) buf; }
/* * rpipe() - gets a `cmd' to run and a `file descriptor' to use as its stdin. */ int rpipe(UBYTE * cmd, int fd) { BPTR fdFH = 0, /* FileHandle of passed file descriptor */ outPH = 0, /* Pipe (File) Handle for child to write to. */ inPH = 0, /* Pipe (File) Handle for child to read from. */ lock = 0; int fdr = 0; char pname[32], *pc; extern char o_shell[]; if (isOldDOS()) return -1; /*- * Sorry, I'm playing with an AZTEC internal here: * _devtab[fd].fd is Aztec's FileHandle for the file descriptor `fd'. * * HINT: For your compiler, look in your compiler's fcntl.h. */ switch (fd) { case 0: inPH = Open((UBYTE *) "*", MODE_READWRITE); break; default: #ifdef AZTEC_C fdFH = _devtab[fd].fd; /* Grab FileHandle from fd */ #elif _DCC fdFH = fdtofh(fd); /* DCC does it right! */ #else return -1; /* Sorry, can't help you. */ #endif /* * Get a FileHandle to use for the child's stdin. * The only reason we Dup is because we'll run the child ASynch, * and it will close its Input and Output on exit. */ lock = DupLockFromFH(fdFH); if (!lock) return -1; inPH = OpenFromLock(lock); } if (!inPH) { if (lock) UnLock(lock); return -1; } /* * Get a pipe to use for the child's stdout, which we will read from. */ strcpy(pname, "PIPE:ElvisXXX.XXX"); pc = mktemp(pname); /* Get a unique PIPE: */ if (!*pc) { Close(inPH); return -1; /* Failure. */ } /* * Get a FileHandle to use for the child's stdout. */ if ((BPTR) 0 == (outPH = Open((UBYTE *) pc, MODE_NEWFILE))) { Close(inPH); return -1; /* Failure. */ } /* Get a file descriptor to return to the calling function */ if ((fdr = open(pc, O_RDONLY)) < 0) { Close(inPH); Close(outPH); return -1; /* Failure. */ } /* exec the cmd */ systags[0].ti_Data = inPH; /* Input FileHandle for child */ systags[1].ti_Data = outPH; /* Output FileHandle for child */ systags[2].ti_Data = (long) o_shell;/* which shell to use */ if (System((UBYTE *) cmd, systags)) { close(fdr); return -1; /* Failure. */ } return fdr; /* Success! */ }
int system(UBYTE * command) { return (isOldDOS()) ? -1 : System((UBYTE *) command, TAG_DONE); }