+#define EMAX 256
+
+char *envp[EMAX+1];
+
+/*
+ * This routine edits the PATH environment variable so that
+ * special commands that learners may need will be found.
+ * EXINIT is modified so that the editor will always prompt,
+ * will not print \r's, and will be usable with open mode.
+ */
+
+chgenv()
+{
+ register char **p;
+ register int i;
+ extern char **environ;
+ extern char *direct;
+ char path[BUFSIZ], exinit[BUFSIZ];
+ char *malloc();
+
+ sprintf(path, "PATH=%s/bin:/usr/cc/bin:/usr/ucb/bin:", direct);
+ sprintf(exinit, "EXINIT=set prompt noopt open");
+#if vax
+ system("stty old");
+ for (p=environ,i=3; *p != 0 && i < EMAX; p++,i++) {
+#else
+ for (p=environ,i=2; *p != 0 && i < EMAX; p++,i++) {
+#endif
+ envp[i] = *p;
+ if (**p != 'P' && **p != 'E')
+ continue;
+ if (strncmp(*p, "PATH=", 5) == 0)
+ sprintf(path, "PATH=%s/bin:%s", direct, &envp[i--][5]);
+ else if (strncmp(*p, "EXINIT=", 7) == 0)
+ sprintf(exinit, "%s|set prompt noopt open", envp[i--]);
+#if vax
+ else if (strncmp(*p, "PS1=", 4) == 0);
+ i--;
+ }
+ envp[2] = malloc(7);
+ strcpy(envp[2], "PS1=% ");
+#else
+ }
+#endif
+ envp[0] = malloc(strlen(path) + 1);
+ strcpy(envp[0], path);
+ envp[1] = malloc(strlen(exinit) + 1);
+ strcpy(envp[1], exinit);
+ envp[i] = 0;
+ environ = envp;
+}