From decwrl!sdd.hp.com!cs.utexas.edu!uunet!allbery Mon May 7 07:37:28 PDT 1990 Article 1500 of comp.sources.misc: Path: decwrl!sdd.hp.com!cs.utexas.edu!uunet!allbery From: istewart@datlog.co.uk Newsgroups: comp.sources.misc Subject: v12i021: MS_SH 1.6 Upgrade Kit - Part 03 of 08 Message-ID: <87523@uunet.UU.NET> Date: 5 May 90 17:06:13 GMT Sender: allbery@uunet.UU.NET Lines: 1709 Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) Posting-number: Volume 12, Issue 21 Submitted-by: istewart@datlog.co.uk Archive-name: ms_sh-1.6/part03 #!/bin/sh # this is part 3 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # file Patch1.6 continued # CurArch=3 if test ! -r s2_seq_.tmp then echo "Please unpack part 1 first!" exit 1; fi ( read Scheck if test "$Scheck" != $CurArch then echo "Please unpack part $Scheck next!" exit 1; else exit 0; fi ) < s2_seq_.tmp || exit 1 echo "x - Continuing file Patch1.6" sed 's/^X//' << 'SHAR_EOF' >> Patch1.6 X+ DELETE (local_path); X+ return FALSE; X+ } X+ X+ res = (access (local_path, X_OK) == 0) ? TRUE : FALSE; X+ DELETE (local_path); X+ return res; X+ } X+ X /* X * Run the command produced by generator `f' applied to stream `arg'. X */ X X! int run (argp, f, f_loop) X IO_Args *argp; X int (*f)(IO_State *); X+ bool f_loop; X { X Word_B *swdlist = wdlist; X Word_B *siolist = iolist; X*************** X*** 853,868 **** X int rv = -1; X Break_C *S_RList = Return_List; /* Save loval links */ X Break_C *S_BList = Break_List; X- Break_C *S_SList = SShell_List; X- Break_C bc; X int LS_depth = Execute_stack_depth; X C_Op *outtree; X X- /* Create a new environment in which to run */ X- X- if (Create_NG_VL () == -1) X- return -1; X- X /* Create a new save area */ X X areanum++; X--- 1039,1049 ---- X int rv = -1; X Break_C *S_RList = Return_List; /* Save loval links */ X Break_C *S_BList = Break_List; X int LS_depth = Execute_stack_depth; X+ int sjr; X C_Op *outtree; X+ int s_execflg = execflg; X X /* Create a new save area */ X X areanum++; X*************** X*** 877,900 **** X iolist = (Word_B *)NULL; X X pushio (argp, f); X! e.iobase = e.iop; X! yynerrs = 0; X X! X! if ((setjmp (failpt = rt) == 0) && X! ((outtree = yyparse ()) != (C_Op *)NULL)) X { X! if (setjmp (bc.brkpt) == 0) X! { X! bc.nextlev = SShell_List; X! SShell_List = &bc; X! rv = execute (outtree, NOPIPE, NOPIPE, 0); X! } X X! else X! rv = getn (lookup ("?", FALSE)->value); X! } X X quitenv (); X } X X--- 1058,1091 ---- X iolist = (Word_B *)NULL; X X pushio (argp, f); X! e.iobase = e.iop; X! e.eof_p = (bool)!f_loop; /* Set EOF processing */ X! SW_intr = 0; X! multiline = 0; X! inparse = 0; X! execflg = (!f_loop) ? 1 : execflg; X X! /* Read Input (if f_loop is not set, we are processing a . file command) X! * either for one line or until end of file. X! */ X! do X { X! yynerrs = 0; X X! if (((sjr = setjmp (failpt = rt)) == 0) && X! ((outtree = yyparse ()) != (C_Op *)NULL)) X! rv = execute (outtree, NOPIPE, NOPIPE, 0); X! X! /* Fail or no loop - zap any files if necessary */ X X+ else if (sjr || f_loop) X+ { X+ Clear_Extended_File (); X+ break; X+ } X+ X+ } while (!f_loop); X+ X quitenv (); X } X X*************** X*** 902,908 **** X X Return_List = S_RList; X Break_List = S_BList; X! SShell_List = S_SList; X wdlist = swdlist; X iolist = siolist; X failpt = ofail; X--- 1093,1099 ---- X X Return_List = S_RList; X Break_List = S_BList; X! execflg = s_execflg; X wdlist = swdlist; X iolist = siolist; X failpt = ofail; X*************** X*** 938,944 **** X int res, serrno; X struct MCB_list *mp = (struct MCB_list *)((unsigned long)c_cur << 16L); X X- X /* Check to see if the file exists */ X X strcpy (path_line, path); X--- 1129,1134 ---- X*************** X*** 965,971 **** X X else if ((stricmp (ep1, ".exe") != 0) && (stricmp (ep1, ".com") != 0)) X { X! errno = ENOEXEC; X return -1; X } X X--- 1155,1163 ---- X X else if ((stricmp (ep1, ".exe") != 0) && (stricmp (ep1, ".com") != 0)) X { X! if (access (path_line, F_OK) == 0) X! errno = ENOEXEC; X! X return -1; X } X X*************** X*** 1010,1026 **** X * function to swap us out X */ X X! get_sys_info (); X X! /* Ok - 3 methods of swapping */ X X /* If expanded memory - try that */ X X! if (Swap_Mode & SWAP_EXPAND) X { X int cr; X- SW_Mode = 3; /* Set Expanded memory swap */ X X res = SA_spawn (envp); X cr = EMS_Close (); /* Close EMS */ X X--- 1202,1222 ---- X * function to swap us out X */ X X! /* Save the interrupt 0 and 23 addresses */ X X! SW_I0_V = _dos_getvect (0x00); X! SW_I23_V = _dos_getvect (0x23); X X+ /* Ok - 3 methods of swapping */ X+ X /* If expanded memory - try that */ X X! if ((Swap_Mode & SWAP_EXPAND) && Get_EMS_Driver ()) X { X int cr; X X+ SW_Mode = 3; /* Set Expanded memory swap */ X+ X res = SA_spawn (envp); X cr = EMS_Close (); /* Close EMS */ X X*************** X*** 1044,1063 **** X Swap_Mode &= (~SWAP_EXPAND); X } X X! if (Swap_Mode & SWAP_EXTEND) X { X! SW_Mode = 2; /* Set Extended memory swap */ X X! if ((SW_EMsize <= SW_Blocks) || X! ((SW_EMstart - 0x100000L + X! ((long)(SW_Blocks - SW_EMsize) * 16L * 1024L)) < 0L)) X! print_warn ("Not enough Extended memory for swap\n"); X X! else if ((res = SA_spawn (envp)) == -2) X! print_warn ("Extended memory swap failed (%x)\n", errno); X X! else X { X Clear_Extended_File (); X return res; X } X--- 1240,1267 ---- X Swap_Mode &= (~SWAP_EXPAND); X } X X! if ((Swap_Mode & SWAP_EXTEND) && Get_XMS_Driver ()) X { X! int cr; X X! /* Set Extended memory or XMS driver */ X X! SW_Mode = (SW_fp == -1) ? 2 : 4; X X! res = SA_spawn (envp); X! cr = XMS_Close (); /* Close XMS */ X! X! if ((res != -2) && cr) /* Report Close error ? */ X { X+ res = -2; X+ errno = cr; X+ } X+ X+ if (res == -2) X+ XMS_error ("Extended memory swap failed (%x)\n", errno); X+ X+ else X+ { X Clear_Extended_File (); X return res; X } X*************** X*** 1073,1078 **** X--- 1277,1283 ---- X { X if ((SW_fp = S_open (TRUE, g_tempname (), O_SMASK, 0600)) < 0) X { X+ Swap_Mode &= (~SWAP_DISK); X print_error ("No Swap files\n"); X errno = ENOSPC; X return -1; X*************** X*** 1088,1093 **** X--- 1293,1299 ---- X X if (res == -2) X { X+ Swap_Mode &= (~SWAP_DISK); X print_warn ("Swap file write failed\n"); X errno = ENOSPC; X res = -1; X*************** X*** 1109,1145 **** X return -1; X } X X! /* Get some system info */ X X! static void get_sys_info () X { X union REGS or; X struct SREGS sr; X! char *sp; X X- /* Save the interrupt 0 address */ X- X- SW_I0_V = _dos_getvect (0x00); X- X- /* Save the interrupt 23 address */ X- X- SW_I23_V = _dos_getvect (0x23); X- X /* Get max Extended memory pages, and convert to 16K blocks. If Extended X * memory swapping disabled, set to zero X */ X X! or.x.ax = 0x8800; X! int86 (0x15, &or, &or); X! SW_EMsize = (Swap_Mode & SWAP_EXTEND) ? or.x.ax / 16 : 0; X X! /* Check for the Expand Memory System */ X X! if (!(Swap_Mode & SWAP_EXPAND)) X! return; X X! SW_fp = -1; /* Set EMS handler not defined */ X X or.x.ax = 0x3567; X intdosx (&or, &or, &sr); X X--- 1315,1382 ---- X return -1; X } X X! /* Get the XMS Driver information */ X X! static bool Get_XMS_Driver () X { X union REGS or; X struct SREGS sr; X! unsigned int SW_EMsize; /* Number of extend memory blks */ X X /* Get max Extended memory pages, and convert to 16K blocks. If Extended X * memory swapping disabled, set to zero X */ X X! SW_fp = -1; /* Set EMS/XMS handler not */ X! /* defined */ X X! /* Is a XMS memory driver installed */ X X! or.x.ax = 0x4300; X! int86 (0x2f, &or, &or); X X! if (or.h.al != 0x80) X! { X! or.x.ax = 0x8800; X! int86 (0x15, &or, &or); X! SW_EMsize = or.x.ax / 16; X X+ if ((SW_EMsize <= SW_Blocks) || X+ ((SW_EMstart - 0x100000L + X+ ((long)(SW_Blocks - SW_EMsize) * 16L * 1024L)) < 0L)) X+ return XMS_error ("Not enough Extended memory for swap\n", 0); X+ X+ else X+ return TRUE; X+ } X+ X+ /* Get the driver interface */ X+ X+ or.x.ax = 0x4310; X+ int86x (0x2f, &or, &or, &sr); X+ SW_XMS_Driver = (void (*)())((unsigned long)(sr.es) << 16L | or.x.bx); X+ X+ if ((SW_XMS_Gversion () & 0xff00) != 0x0200) X+ return XMS_error ("Warning: XMS Version != 2\n", 0); X+ X+ else if ((SW_fp = SW_XMS_Allocate (SW_Blocks * 16)) == -1) X+ return XMS_error (XMS_emsg, errno); X+ X+ return TRUE; X+ } X+ X+ /* Get the EMS Driver information */ X+ X+ static bool Get_EMS_Driver () X+ { X+ union REGS or; X+ struct SREGS sr; X+ char *sp; X+ X+ /* Set EMS/XMS handler not defined */ X+ X+ SW_fp = -1; X+ X or.x.ax = 0x3567; X intdosx (&or, &or, &sr); X X*************** X*** 1148,1166 **** X /* If not there - disable */ X X if (memcmp ("EMMXXXX0", sp, 8) != 0) X! { X! EMS_error ("Warning: EMS not available\n", 0); X! return; X! } X X or.h.ah = 0x40; /* Check status */ X int86 (0x67, &or, &or); X X if (or.h.ah != 0) X! { X! EMS_error (EMS_emsg, or.h.ah); X! return; X! } X X /* Check version greater than 3.2 */ X X--- 1385,1397 ---- X /* If not there - disable */ X X if (memcmp ("EMMXXXX0", sp, 8) != 0) X! return EMS_error ("Warning: EMS not available\n", 0); X X or.h.ah = 0x40; /* Check status */ X int86 (0x67, &or, &or); X X if (or.h.ah != 0) X! return EMS_error (EMS_emsg, or.h.ah); X X /* Check version greater than 3.2 */ X X*************** X*** 1168,1177 **** X int86 (0x67, &or, &or); X X if ((or.h.ah != 0) || (or.h.al < 0x32)) X! { X! EMS_error ("Warning: EMS Version < 3.2\n", 0); X! return; X! } X X /* get page frame address */ X X--- 1399,1405 ---- X int86 (0x67, &or, &or); X X if ((or.h.ah != 0) || (or.h.al < 0x32)) X! return EMS_error ("Warning: EMS Version < 3.2\n", 0); X X /* get page frame address */ X X*************** X*** 1179,1188 **** X int86 (0x67, &or, &or); X X if (or.h.ah != 0) X! { X! EMS_error (EMS_emsg, or.h.ah); X! return; X! } X X SW_EMSFrame = or.x.bx; /* Save the page frame */ X X--- 1407,1413 ---- X int86 (0x67, &or, &or); X X if (or.h.ah != 0) X! return EMS_error (EMS_emsg, or.h.ah); X X SW_EMSFrame = or.x.bx; /* Save the page frame */ X X*************** X*** 1193,1202 **** X int86 (0x67, &or, &or); X X if (or.h.ah != 0) X! { X! EMS_error (EMS_emsg, or.h.ah); X! return; X! } X X /* Save the EMS Handler */ X X--- 1418,1424 ---- X int86 (0x67, &or, &or); X X if (or.h.ah != 0) X! return EMS_error (EMS_emsg, or.h.ah); X X /* Save the EMS Handler */ X X*************** X*** 1208,1236 **** X or.x.dx = SW_fp; X int86 (0x67, &or, &or); X X! if (or.h.ah != 0) X! { X! EMS_error (EMS_emsg, or.h.ah); X! return; X! } X } X X /* Print EMS error message */ X X! static void EMS_error (s, v) X char *s; X int v; X { X print_warn (s, v); X Swap_Mode &= ~(SWAP_EXPAND); X EMS_Close (); X } X X X! /* If the handler is defined - close it */ X! X! static int EMS_Close () X { X union REGS or; X int res = 0; X X--- 1430,1481 ---- X or.x.dx = SW_fp; X int86 (0x67, &or, &or); X X! return (or.h.ah != 0) ? EMS_error (EMS_emsg, or.h.ah) : TRUE; X } X X /* Print EMS error message */ X X! static bool EMS_error (s, v) X char *s; X int v; X { X print_warn (s, v); X Swap_Mode &= ~(SWAP_EXPAND); X EMS_Close (); X+ return FALSE; X } X X+ /* Print XMS error message */ X X! static bool XMS_error (s, v) X! char *s; X! int v; X { X+ print_warn (s, v); X+ Swap_Mode &= ~(SWAP_EXTEND); X+ XMS_Close (); X+ return FALSE; X+ } X+ X+ /* If the XMS handler is defined - close it */ X+ X+ static int XMS_Close () X+ { X+ int res = 0; X+ X+ /* Release XMS page */ X+ X+ if (SW_fp != -1) X+ res = SW_XMS_Free (SW_fp); X+ X+ SW_fp = -1; X+ return res; X+ } X+ X+ /* If the EMS handler is defined - close it */ X+ X+ static int EMS_Close () X+ { X union REGS or; X int res = 0; X X*************** X*** 1285,1292 **** X X /* Translate process name to MSDOS format */ X X! Convert_Slashes (path); X! strupr (path); X X /* Extended command line processing */ X X--- 1530,1537 ---- X X /* Translate process name to MSDOS format */ X X! if ((argv[0] = Gen_Full_Path_Name (path)) == (char *)NULL) X! return -1; X X /* Extended command line processing */ X X*************** X*** 1337,1342 **** X--- 1582,1591 ---- X ((fd = S_open (FALSE, Extend_file = g_tempname (), O_CMASK, X 0600)) >= 0)) X { X+ if ((ep = space (strlen (Extend_file) + 1)) != (char *)NULL) X+ strcpy (ep, Extend_file); X+ X+ Extend_file = ep; X X /* Copy to end of list */ X X*************** X*** 1362,1375 **** X /* Set up cmd_line[1] to contain the filename */ X X memset (cmd_line, 0, CMD_LINE_MAX); X! cmd_line[1] = '@'; X! strcpy (&cmd_line[2], Extend_file); X! cmd_line[0] = (char)(strlen (Extend_file) + 1); X X /* Correctly terminate cmd_line in no swap mode */ X X if (Swap_Mode != SWAP_OFF) X! cmd_line[cmd_line[0] + 1] = '\r'; X X /* If the name in the file is in upper case - use \ for separators */ X X--- 1611,1625 ---- X /* Set up cmd_line[1] to contain the filename */ X X memset (cmd_line, 0, CMD_LINE_MAX); X! cmd_line[1] = ' '; X! cmd_line[2] = '@'; X! strcpy (&cmd_line[3], Extend_file); X! cmd_line[0] = (char)(strlen (Extend_file) + 2); X X /* Correctly terminate cmd_line in no swap mode */ X X if (Swap_Mode != SWAP_OFF) X! cmd_line[cmd_line[0] + 2] = '\r'; X X /* If the name in the file is in upper case - use \ for separators */ X X*************** X*** 1396,1422 **** X res = 0; X cmd_line[0] = 0; X cmd_line[1] = '\r'; X- ep = cmd_line; X X /* Skip the first parameter and get the length of the rest */ X X if (*argv != (char *)NULL) X { X while (*pl != (char *)NULL) X { X! if ((res += (strlen (*pl) + 1)) >= CMD_LINE_MAX) X! { X! errno = E2BIG; X! return -1; X! } X X! strcat (strcat (ep, " "), *(pl++)); X! } X X! if (res) X! cmd_line[res--] = '\r'; X! } X X /* Terminate the line and insert the line length */ X X cmd_line[0] = (char)res; X--- 1646,1678 ---- X res = 0; X cmd_line[0] = 0; X cmd_line[1] = '\r'; X X /* Skip the first parameter and get the length of the rest */ X X if (*argv != (char *)NULL) X { X+ *(ep = cmd_line + 1) = 0; X+ X while (*pl != (char *)NULL) X { X! res += white_space_len (*pl, &found); X X! if (res >= CMD_LINE_MAX) X! { X! errno = E2BIG; X! return -1; X! } X! X! if (found) X! strcat (strcat (strcat (ep, " \""), *(pl++)), "\""); X X! else X! strcat (strcat (ep, " "), *(pl++)); X! } X X+ cmd_line[res + 1] = '\r'; X+ } X+ X /* Terminate the line and insert the line length */ X X cmd_line[0] = (char)res; X*************** X*** 1426,1437 **** X return (Swap_Mode == SWAP_OFF) ? spawnve (P_WAIT, path, argv, envp) : 0; X } X X! /* Clear Extended command line file */ X X! static void Clear_Extended_File () X { X if (Extend_file != (char *)NULL) X unlink (Extend_file); X X Extend_file = (char *)NULL; X } X--- 1682,1769 ---- X return (Swap_Mode == SWAP_OFF) ? spawnve (P_WAIT, path, argv, envp) : 0; X } X X! /* Check string for white space */ X X! static size_t white_space_len (s, wsf) X! char *s; X! bool *wsf; X { X+ char *os = s; X+ X+ *wsf = FALSE; X+ X+ while (*s) X+ { X+ if (isspace (*s)) X+ *wsf = TRUE; X+ X+ ++s; X+ } X+ X+ return (size_t)(s - os) + (*wsf ? 3 : 1); X+ } X+ X+ /* Clear Extended command line file */ X+ X+ void Clear_Extended_File () X+ { X if (Extend_file != (char *)NULL) X+ { X unlink (Extend_file); X+ DELETE (Extend_file); X+ } X X Extend_file = (char *)NULL; X+ } X+ X+ /* Convert the executable path to the full path name */ X+ X+ static char *Gen_Full_Path_Name (path) X+ char *path; X+ { X+ char cpath[PATH_MAX + 4]; X+ char npath[PATH_MAX + NAME_MAX + 4]; X+ char *p; X+ unsigned int dummy; X+ X+ Convert_Slashes (path); X+ strupr (path); X+ X+ /* Get the current path */ X+ X+ getcwd (cpath, PATH_MAX + 3); X+ strcpy (npath, cpath); X+ X+ /* In current directory ? */ X+ X+ if ((p = strrchr (path, '\\')) == (char *)NULL) X+ p = path; X+ X+ else X+ { X+ *(p++) = 0; X+ X+ /* Change to the directory containing the executable */ X+ X+ if (*(path + 1) == ':') X+ _dos_setdrive (tolower (*path) - 'a' + 1, &dummy); X+ X+ if (chdir (path) < 0) X+ return (char *)NULL; X+ X+ getcwd (npath, PATH_MAX + 3); X+ X+ /* Restore our original directory */ X+ X+ _dos_setdrive (tolower (*cpath) - 'a' + 1, &dummy); X+ X+ if (chdir (cpath) < 0) X+ return (char *)NULL; X+ } X+ X+ if (npath[strlen (npath) - 1] != '\\') X+ strcat (npath, "\\"); X+ X+ strcat (npath, p); X+ return strcpy (path, npath); X } XIndex: shell/sh10.c XPrereq: 1.1 X*** ../sh15/shell/sh10.c Fri Feb 16 19:19:05 1990 X--- shell/sh10.c Tue May 1 19:48:22 1990 X*************** X*** 12,20 **** X * 2. The sources (or parts thereof) or objects generated from the sources X * (or parts of sources) cannot be sold under any circumstances. X * X! * $Header: sh10.c 1.1 90/01/25 13:40:54 MS_user Exp $ X * X * $Log: sh10.c $ X * Revision 1.1 90/01/25 13:40:54 MS_user X * Initial revision X * X--- 12,23 ---- X * 2. The sources (or parts thereof) or objects generated from the sources X * (or parts of sources) cannot be sold under any circumstances. X * X! * $Header: sh10.c 1.2 90/04/25 22:34:04 MS_user Exp $ X * X * $Log: sh10.c $ X+ * Revision 1.2 90/04/25 22:34:04 MS_user X+ * Fix case in TELIF where then and else parts are not defined X+ * X * Revision 1.1 90/01/25 13:40:54 MS_user X * Initial revision X * X*************** X*** 145,164 **** X X Print_ExTree (t->left); X X! Print_indent -= 1; X! Print_IString ("then\n", 1); X! Print_ExTree (t->right->left); X! X! if (t->right->right != (C_Op *)NULL) X { X Print_indent -= 1; X X! if (t->right->right->type != TELIF) X! Print_IString ("else\n", 1); X X! Print_ExTree (t->right->right); X! } X X if (t->type == TIF) X Print_IString ("fi\n", -1); X X--- 148,170 ---- X X Print_ExTree (t->left); X X! if (t->right != (C_Op *)NULL) X { X Print_indent -= 1; X+ Print_IString ("then\n", 1); X+ Print_ExTree (t->right->left); X X! if (t->right->right != (C_Op *)NULL) X! { X! Print_indent -= 1; X X! if (t->right->right->type != TELIF) X! Print_IString ("else\n", 1); X X+ Print_ExTree (t->right->right); X+ } X+ } X+ X if (t->type == TIF) X Print_IString ("fi\n", -1); X X*************** X*** 508,516 **** X X case TIF: /* IF and ELSE IF functions */ X case TELIF: X! Set_Free_ExTree (t->right->left, func); X! Set_Free_ExTree (t->right->right, func); X! (*func)((char *)t->right); X X case TBRACE: /* {} statement */ X Set_Free_ExTree (t->left, func); X--- 514,525 ---- X X case TIF: /* IF and ELSE IF functions */ X case TELIF: X! if (t->right != (C_Op *)NULL) X! { X! Set_Free_ExTree (t->right->left, func); X! Set_Free_ExTree (t->right->right, func); X! (*func)((char *)t->right); X! } X X case TBRACE: /* {} statement */ X Set_Free_ExTree (t->left, func); XIndex: shell/sh5.c XPrereq: 1.1 X*** ../sh15/shell/sh5.c Fri Feb 16 19:20:07 1990 X--- shell/sh5.c Tue May 1 19:49:12 1990 X*************** X*** 13,21 **** X * 2. The sources (or parts thereof) or objects generated from the sources X * (or parts of sources) cannot be sold under any circumstances. X * X! * $Header: sh5.c 1.1 90/01/25 13:41:50 MS_user Exp $ X * X * $Log: sh5.c $ X * Revision 1.1 90/01/25 13:41:50 MS_user X * Initial revision X * X--- 13,45 ---- X * 2. The sources (or parts thereof) or objects generated from the sources X * (or parts of sources) cannot be sold under any circumstances. X * X! * $Header: sh5.c 1.8 90/04/25 10:58:41 MS_user Exp $ X * X * $Log: sh5.c $ X+ * Revision 1.8 90/04/25 10:58:41 MS_user X+ * Fix re-reading re-assigned buffers correctly. X+ * X+ * Revision 1.7 90/04/25 09:20:08 MS_user X+ * Fix lseek problem and TAG problem on here documents X+ * X+ * Revision 1.6 90/04/09 17:04:50 MS_user X+ * g_tempname must check for slash or backslash X+ * X+ * Revision 1.5 90/03/21 14:03:47 MS_user X+ * Add new gravechar procedure for handling here documents X+ * X+ * Revision 1.4 90/03/14 19:31:28 MS_user X+ * Add buffered output for here document processing. X+ * Fix here document processing so it works correctly. X+ * Add missing IOTHERE (<<-) processing for here documents. X+ * X+ * Revision 1.3 90/03/06 16:49:58 MS_user X+ * Add disable history option X+ * X+ * Revision 1.2 90/03/05 13:51:45 MS_user X+ * Add functionality to readc to support dot command via run function X+ * Add $HOME as a temporary file directory X+ * X * Revision 1.1 90/01/25 13:41:50 MS_user X * Initial revision X * X*************** X*** 47,53 **** X static Here_D *acthere = (Here_D *)NULL; X X static int dol1_char (IO_State *); X! static void readhere (char **, char *, int); X static int herechar (IO_State *); X X int Getc (ec) X--- 71,77 ---- X static Here_D *acthere = (Here_D *)NULL; X X static int dol1_char (IO_State *); X! static void readhere (char **, char *, int, int); X static int herechar (IO_State *); X X int Getc (ec) X*************** X*** 170,184 **** X if (multiline) X return e.iop->prev = 0; X X! if (talking && e.iop == iostack + 1) X put_prompt (ps1->value); X } X } X } X X! if (e.iop >= iostack) X! return 0; X X leave(); X /* NOTREACHED */ X } X--- 194,212 ---- X if (multiline) X return e.iop->prev = 0; X X! if (talking && (e.iop == iostack + 1) && !e.eof_p) X put_prompt (ps1->value); X } X } X } X X! /* End of file detected. If more data on stack and the special EOF X! * processing is not enabled - return 0 X! */ X X+ if ((e.iop >= iostack) && !e.eof_p) X+ return 0; X+ X leave(); X /* NOTREACHED */ X } X*************** X*** 210,216 **** X X if ((isatty (e.iop->argp->afile) == 0) && X ((e.iop == &iostack[0]) || X! (lseek (e.iop->argp->afile, 0L, 1) != -1L))) X { X if (++bufid == AFID_NOBUF) X bufid = AFID_ID; X--- 238,244 ---- X X if ((isatty (e.iop->argp->afile) == 0) && X ((e.iop == &iostack[0]) || X! (lseek (e.iop->argp->afile, 0L, SEEK_CUR) != -1L))) X { X if (++bufid == AFID_NOBUF) X bufid = AFID_ID; X*************** X*** 227,233 **** X if ((fn == filechar) || (fn == linechar)) X e.iop->task = XIO; X X! else if ((fn == gravechar) || (fn == qgravechar)) X e.iop->task = XGRAVE; X X else X--- 255,261 ---- X if ((fn == filechar) || (fn == linechar)) X e.iop->task = XIO; X X! else if ((fn == gravechar) || (fn == qgravechar) || (fn == sgravechar)) X e.iop->task = XGRAVE; X X else X*************** X*** 402,410 **** X--- 430,452 ---- X { X if ((i = (ap->afid != bp->id)) || (bp->bufp == bp->ebufp)) X { X+ X+ /* Are we re-reading a corrupted buffer? */ X+ X if (i) X lseek (ap->afile, ap->afpos, SEEK_SET); X X+ /* No, filling so set offset to zero */ X+ X+ else X+ ap->afoff = 0; X+ X+ /* Save the start of the next buffer */ X+ X+ ap->afpos = lseek (ap->afile, 0L, SEEK_CUR); X+ X+ /* Read in the next buffer */ X+ X if ((i = read (ap->afile, bp->buf, sizeof (bp->buf))) <= 0) X { X if (ap->afile > STDERR_FILENO) X*************** X*** 413,431 **** X return 0; X } X X! bp->id = ap->afid; X! bp->ebufp = (bp->bufp = bp->buf) + i; X! } X X! ap->afpos++; X X return *bp->bufp++ & 0177; X } X X /* If this is the terminal, there is special input processing */ X X else if ((ap->afile == 0) && isatty (ap->afile)) X return Get_stdin (ap); X X if ((i = read (ap->afile, &c, sizeof(c))) == sizeof (c)) X return (int)c & 0177; X--- 455,479 ---- X return 0; X } X X! /* Set up buffer id, start and end */ X X! bp->id = ap->afid; X! bp->bufp = bp->buf + ap->afoff; X! bp->ebufp = bp->buf + i; X! } X! X! /* Return the next character from the buffer */ X X+ ++(ap->afoff); X return *bp->bufp++ & 0177; X } X X /* If this is the terminal, there is special input processing */ X X+ #ifndef NO_HISTORY X else if ((ap->afile == 0) && isatty (ap->afile)) X return Get_stdin (ap); X+ #endif X X if ((i = read (ap->afile, &c, sizeof(c))) == sizeof (c)) X return (int)c & 0177; X*************** X*** 456,467 **** X X /* X * Return the characters produced by a process (`...`). X! * Quote them if required, and remove any trailing newline characters. X */ X X! int gravechar (iop) X IO_State *iop; X { X register int c; X X if ((c = qgravechar (iop) & ~QUOTE) == NL) X--- 504,526 ---- X X /* X * Return the characters produced by a process (`...`). X! * De-quote them if required. Use in here documents. X */ X X! int sgravechar (iop) X IO_State *iop; X { X+ return qgravechar (iop) & ~QUOTE; X+ } X+ X+ /* X+ * Return the characters produced by a process (`...`). X+ * De-quote them if required, and converting NL to space. X+ */ X+ X+ int gravechar (iop) X+ IO_State *iop; X+ { X register int c; X X if ((c = qgravechar (iop) & ~QUOTE) == NL) X*************** X*** 501,513 **** X iop->xchar = (char)c; X X if (c == 0) X! return(c); X X iop->nlcount--; X c = NL; X } X X! return (c != 0) ? (c | QUOTE): 0; X } X X /* X--- 560,572 ---- X iop->xchar = (char)c; X X if (c == 0) X! return c; X X iop->nlcount--; X c = NL; X } X X! return (c != 0) ? (c | QUOTE) : 0; X } X X /* X*************** X*** 631,637 **** X /* Scan here files first leaving inhere list in place */ X X for (hp = h = inhere; h != (Here_D *)NULL; hp = h, h = h->h_next) X! readhere (&h->h_iop->io_name, h->h_tag, h->h_dosub ? 0 : '\''); X X /* Make inhere list active - keep list intact for scraphere */ X X--- 690,697 ---- X /* Scan here files first leaving inhere list in place */ X X for (hp = h = inhere; h != (Here_D *)NULL; hp = h, h = h->h_next) X! readhere (&h->h_iop->io_name, h->h_tag, h->h_dosub ? 0 : '\'', X! h->h_iop->io_flag); X X /* Make inhere list active - keep list intact for scraphere */ X X*************** X*** 643,660 **** X } X } X X! static void readhere (name, s, ec) X char **name; X register char *s; X { X int tf; X register int c; X jmp_buf ev; X char *line; X char *next; X X! *name = strsave (g_tempname (), areanum); X X if ((tf = S_open (FALSE, *name, O_CMASK | O_NOINHERIT, 0600)) < 0) X return; X X--- 703,727 ---- X } X } X X! static void readhere (name, s, ec, ioflag) X char **name; X register char *s; X+ int ec; X+ int ioflag; X { X int tf; X register int c; X jmp_buf ev; X char *line; X char *next; X+ int stop_len; X+ int c_len; X+ Out_Buf *bp; X X! /* Create a temporary file and open it */ X X+ *name = strsave (g_tempname (), areanum); X+ X if ((tf = S_open (FALSE, *name, O_CMASK | O_NOINHERIT, 0600)) < 0) X return; X X*************** X*** 663,700 **** X X else X { X- line = space (LINE_MAX + 1); X pushio (e.iop->argp, e.iop->iofn); X e.iobase = e.iop; X X! while (1) X! { X! if (talking && e.iop <= iostack) X! put_prompt (ps2->value); X X! next = line; X while ((c = Getc (ec)) != NL && c) X { X if (ec == '\'') X c &= ~ QUOTE; X X! if (next >= &line[LINE_MAX]) X! { X! c = 0; X! break; X! } X X! *next++ = (char)c; X! } X X *next = 0; X if (strcmp (s, line) == 0 || c == 0) X break; X X! *next++ = NL; X! write (tf, line, (int)(next-line)); X! } X X if (c == 0) X print_error ("here document `%s' unclosed\n", s); X X--- 730,814 ---- X X else X { X pushio (e.iop->argp, e.iop->iofn); X e.iobase = e.iop; X X! /* Strip leading tabs? */ X X! if (ioflag & IOTHERE) X! { X! while (*s && (*s == '\t')) X! ++s; X! } X! X! /* Open the Output buffer */ X! X! line = space ((stop_len = strlen (s) + 2) + 1); X! bp = Open_buffer (tf, TRUE); X! X! /* Read in */ X! X! while (1) X! { X! next = line; X! c_len = 0; X! X! if (talking && e.iop <= iostack + 1) X! { X! #ifndef NO_HISTORY X! Add_History (FALSE); X! #endif X! put_prompt (ps2->value); X! } X! X! /* Read the here document */ X! X while ((c = Getc (ec)) != NL && c) X { X+ X+ /* Strip leading tabs? */ X+ X+ if ((ioflag & IOTHERE) && (c == '\t') && (next == line)) X+ continue; X+ X if (ec == '\'') X c &= ~ QUOTE; X X! /* If not end of search string, add to search string */ X X! if ((++c_len) < stop_len) X! *(next++) = (char)c; X X+ /* If one greater that search string, buffer search string */ X+ X+ else X+ { X+ if (c_len == stop_len) X+ { X+ *next = 0; X+ Adds_buffer (line, bp); X+ } X+ X+ /* Buffer the current character */ X+ X+ Add_buffer ((char)c, bp); X+ } X+ } X+ X+ /* Check for end of document */ X+ X *next = 0; X if (strcmp (s, line) == 0 || c == 0) X break; X X! if (c_len < stop_len) X! Adds_buffer (line, bp); X X+ Add_buffer (NL, bp); X+ } X+ X+ Close_buffer (bp); X+ X if (c == 0) X print_error ("here document `%s' unclosed\n", s); X X*************** X*** 715,730 **** X { X register int hf, tf; X X if (hname == (char *)NULL) X return -1; X X if ((hf = S_open (FALSE, hname, O_RDONLY)) < 0) X return -1; X X if (xdoll) X { X char c; X! char *tname = g_tempname(); X jmp_buf ev; X X if ((tf = S_open (FALSE, tname, O_CMASK | O_NOINHERIT, 0600)) < 0) X--- 829,849 ---- X { X register int hf, tf; X X+ /* If the here document is invalid or does not exist, return */ X+ X if (hname == (char *)NULL) X return -1; X X if ((hf = S_open (FALSE, hname, O_RDONLY)) < 0) X return -1; X X+ /* If processing for $, ` and ' is required, do it */ X+ X if (xdoll) X { X char c; X! char *tname = strsave (g_tempname (), areanum); X! Out_Buf *bp; X jmp_buf ev; X X if ((tf = S_open (FALSE, tname, O_CMASK | O_NOINHERIT, 0600)) < 0) X*************** X*** 732,752 **** X X if (newenv (setjmp (errpt = ev)) == FALSE) X { X PUSHIO (afile, hf, herechar); X e.iobase = e.iop; X X! while ((c = (char)subgetc(0, 0)) != 0) X { X- c &= ~ QUOTE; X- write (tf, &c, sizeof c); X- } X X quitenv (); X } X X else X S_Delete (tf); X X S_close (tf, TRUE); X return S_open (TRUE, tname, O_RDONLY); X } X--- 851,880 ---- X X if (newenv (setjmp (errpt = ev)) == FALSE) X { X+ bp = Open_buffer (tf, TRUE); X PUSHIO (afile, hf, herechar); X e.iobase = e.iop; X X! while ((c = (char)subgetc (0, 0)) != 0) X { X X+ /* Determine how many characters to write. If MSB set, write \x. X+ * Otherwise, write x X+ */ X+ X+ if ((c & QUOTE) && !any ((c & ~QUOTE), "$`\\")) X+ Add_buffer ('\\', bp); X+ X+ Add_buffer ((char)(c & (~QUOTE)), bp); X+ } X+ X quitenv (); X } X X else X S_Delete (tf); X X+ Close_buffer (bp); X S_close (tf, TRUE); X return S_open (TRUE, tname, O_RDONLY); X } X*************** X*** 798,818 **** X static char tmpfile[FFNAME_MAX]; X char *tmpdir; /* Points to directory prefix of pipe */ X static int temp_count = 0; X X /* Find out where we should put temporary files */ X X! if ((tmpdir = lookup ("TMPDIR", FALSE)->value) == null) X! tmpdir = lookup ("TMP", FALSE)->value; X X /* Get a unique temporary file name */ X X while (1) X { X! sprintf (tmpfile, "%s/sht%.5u.tmp", tmpdir, temp_count++); X X if (access (tmpfile, F_OK) != 0) X break; X } X X return tmpfile; X } X--- 926,959 ---- X static char tmpfile[FFNAME_MAX]; X char *tmpdir; /* Points to directory prefix of pipe */ X static int temp_count = 0; X+ char *sep = "/"; X X /* Find out where we should put temporary files */ X X! if (((tmpdir = lookup ("TMP", FALSE)->value) == null) && X! ((tmpdir = lookup (home, FALSE)->value) == null)) X! tmpdir = lookup ("TMPDIR", FALSE)->value; X! X! if (any (tmpdir[strlen (tmpdir) - 1], "/\\")) X! sep = null; X X /* Get a unique temporary file name */ X X while (1) X { X! sprintf (tmpfile, "%s%ssht%.5u.tmp", tmpdir, sep, temp_count++); X X if (access (tmpfile, F_OK) != 0) X break; X } X X return tmpfile; X+ } X+ X+ /* Test to see if the current Input device is the console */ X+ X+ bool Interactive () X+ { X+ return (talking && (e.iop->task == XIO) && isatty (e.iop->argp->afile)) X+ ? TRUE : FALSE; X } XIndex: shell/sh7.c XPrereq: 1.2 X*** ../sh15/shell/sh7.c Fri Feb 16 19:16:21 1990 X--- shell/sh7.c Tue May 1 19:49:34 1990 X*************** X*** 15,23 **** X * 2. The sources (or parts thereof) or objects generated from the sources X * (or parts of sources) cannot be sold under any circumstances. X * X! * $Header: sh7.c 1.2 90/01/30 14:43:34 MS_user Exp $ X * X * $Log: sh7.c $ X * Revision 1.2 90/01/30 14:43:34 MS_user X * Add missing author note X * X--- 15,67 ---- X * 2. The sources (or parts thereof) or objects generated from the sources X * (or parts of sources) cannot be sold under any circumstances. X * X! * $Header: sh7.c 1.16 90/04/30 19:50:44 MS_user Exp $ X * X * $Log: sh7.c $ X+ * Revision 1.16 90/04/30 19:50:44 MS_user X+ * Stop search path if second character of name is colon X+ * X+ * Revision 1.15 90/04/25 22:35:53 MS_user X+ * Fix bug in doread to stop multi-line reads X+ * X+ * Revision 1.14 90/04/25 09:21:11 MS_user X+ * Change version message processing X+ * X+ * Revision 1.13 90/04/03 17:59:43 MS_user X+ * type didnot check for functions before searching PATH X+ * X+ * Revision 1.12 90/03/27 20:33:58 MS_user X+ * Clear extended file name on interrupt X+ * X+ * Revision 1.11 90/03/26 20:57:38 MS_user X+ * Change I/O restore so that "exec >filename" works X+ * X+ * Revision 1.10 90/03/14 19:32:05 MS_user X+ * Change buffered output to be re-entrant and add it to getopt X+ * X+ * Revision 1.9 90/03/14 16:45:52 MS_user X+ * New Open_buffer parameter X+ * X+ * Revision 1.8 90/03/13 21:19:50 MS_user X+ * Use the new Buffered Output routines in doecho X+ * X+ * Revision 1.7 90/03/12 20:43:52 MS_user X+ * Change bell test to check initialisation file X+ * X+ * Revision 1.6 90/03/12 17:09:38 MS_user X+ * Add a missing cast X+ * X+ * Revision 1.5 90/03/09 16:06:41 MS_user X+ * Add SH_BELL processing X+ * X+ * Revision 1.4 90/03/06 16:50:10 MS_user X+ * Add disable history option X+ * X+ * Revision 1.3 90/03/05 13:52:49 MS_user X+ * Changes to eval and dot functionality X+ * Fix bug in escape processing in doecho X+ * Add some array size checks X+ * X * Revision 1.2 90/01/30 14:43:34 MS_user X * Add missing author note X * X*************** X*** 172,178 **** X static int dohistory (C_Op *); X static void setsig (int, int (*)()); X static int rdexp (char **, int, char *); X- static void v1_putsn (char *, int); X X static char **test_alist; X static struct test_op *test_op; X--- 216,221 ---- X*************** X*** 198,203 **** X--- 241,248 ---- X int argc; X char **argv = t->words; X int c; X+ Out_Buf *bp; X+ char *c_s = "-c "; X X /* Count arguments */ X X*************** X*** 212,217 **** X--- 257,270 ---- X return 2; X } X X+ /* Get some memory for the buffer */ X+ X+ if ((bp = Open_buffer (1, FALSE)) == (Out_Buf *)NULL) X+ { X+ print_error ("getopt: %s\n", strerror (ENOMEM)); X+ return 1; X+ } X+ X argc -= 2; X argv += 2; X X*************** X*** 222,247 **** X if (c == '?') X return 2; X X! v1printf ("-%c ", c); X X /* Check for addition parameter */ X X if (*(strchr (t->words[1], c) + 1) == ':') X { X! v1_puts (optarg); X! v1_putc (SP); X } X } X X! v1_puts ("-- "); X! argv += optind; X X while (optind++ < argc) X { X! v1_puts (*argv++); X! v1_putc ((char)((optind == argc) ? NL : SP)); X } X X return 0; X } X X--- 275,306 ---- X if (c == '?') X return 2; X X! *(c_s + 1) = (char)c; X! Adds_buffer (c_s, bp); X X /* Check for addition parameter */ X X if (*(strchr (t->words[1], c) + 1) == ':') X { X! Adds_buffer (optarg, bp); X! Add_buffer (SP, bp); X } X } X X! /* Output the separator */ X X+ Adds_buffer ("-- ", bp); X+ argv += optind; X+ X+ /* Output the arguments */ X+ X while (optind++ < argc) X { X! Adds_buffer (*argv++, bp); X! Add_buffer ((char)((optind == argc) ? NL : SP), bp); X } X X+ Close_buffer (bp); X return 0; X } X X*************** X*** 252,269 **** X static int doecho (t) X register C_Op *t; X { X! int n = 1; X int no_eol = 0; /* No EOL */ X char *ip; /* Input pointer */ X int c_val; /* Current character */ X char c; X bool end_s; X! char *cp = e.linep; SHAR_EOF echo "End of part 3" echo "File Patch1.6 is continued in part 4" echo "4" > s2_seq_.tmp exit 0