00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef lint
00038 static char sccsid[] = "@(#)miscbltin.c 5.2 (Berkeley) 3/13/91";
00039 #endif
00040
00041
00042
00043
00044
00045 #include "shell.h"
00046 #include "options.h"
00047 #include "var.h"
00048 #include "output.h"
00049 #include "memalloc.h"
00050 #include "error.h"
00051 #include "mystring.h"
00052
00053 #undef eflag
00054
00055 extern char **argptr;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 readcmd(argc, argv) char **argv; {
00066 char **ap;
00067 int backslash;
00068 char c;
00069 int eflag;
00070 char *prompt;
00071 char *ifs;
00072 char *p;
00073 int startword;
00074 int status;
00075 int i;
00076
00077 eflag = 0;
00078 prompt = NULL;
00079 while ((i = nextopt("ep:")) != '\0') {
00080 if (i == 'p')
00081 prompt = optarg;
00082 else
00083 eflag = 1;
00084 }
00085 if (prompt && isatty(0)) {
00086 out2str(prompt);
00087 flushall();
00088 }
00089 if (*(ap = argptr) == NULL)
00090 error("arg count");
00091 if ((ifs = bltinlookup("IFS", 1)) == NULL)
00092 ifs = nullstr;
00093 status = 0;
00094 startword = 1;
00095 backslash = 0;
00096 STARTSTACKSTR(p);
00097 for (;;) {
00098 if (read(0, &c, 1) != 1) {
00099 status = 1;
00100 break;
00101 }
00102 if (c == '\0')
00103 continue;
00104 if (backslash) {
00105 backslash = 0;
00106 if (c != '\n')
00107 STPUTC(c, p);
00108 continue;
00109 }
00110 if (eflag && c == '\\') {
00111 backslash++;
00112 continue;
00113 }
00114 if (c == '\n')
00115 break;
00116 if (startword && *ifs == ' ' && strchr(ifs, c)) {
00117 continue;
00118 }
00119 startword = 0;
00120 if (backslash && c == '\\') {
00121 if (read(0, &c, 1) != 1) {
00122 status = 1;
00123 break;
00124 }
00125 STPUTC(c, p);
00126 } else if (ap[1] != NULL && strchr(ifs, c) != NULL) {
00127 STACKSTRNUL(p);
00128 setvar(*ap, stackblock(), 0);
00129 ap++;
00130 startword = 1;
00131 STARTSTACKSTR(p);
00132 } else {
00133 STPUTC(c, p);
00134 }
00135 }
00136 STACKSTRNUL(p);
00137 setvar(*ap, stackblock(), 0);
00138 while (*++ap != NULL)
00139 setvar(*ap, nullstr, 0);
00140 return status;
00141 }
00142
00143
00144
00145 umaskcmd(argc, argv) char **argv; {
00146 int mask;
00147 char *p;
00148 int i;
00149
00150 if ((p = argv[1]) == NULL) {
00151 INTOFF;
00152 mask = umask(0);
00153 umask(mask);
00154 INTON;
00155 out1fmt("%.4o\n", mask);
00156 } else {
00157 mask = 0;
00158 do {
00159 if ((unsigned)(i = *p - '0') >= 8)
00160 error("Illegal number: %s", argv[1]);
00161 mask = (mask << 3) + i;
00162 } while (*++p != '\0');
00163 umask(mask);
00164 }
00165 return 0;
00166 }