static char rcsid[] = "$Id: spawn.c,v 1.4 1992/11/08 23:23:36 mike Exp $"; /* $Log: spawn.c,v $ * Revision 1.4 1992/11/08 23:23:36 mike * - Lots'a changes. * * Revision 1.3 1992/10/02 22:31:40 mike * - Some changes for the Atari ST/TT version. * * Revision 1.2 1992/09/14 18:03:42 mike * - First set of changes for the Atari ST/TT version. * * Revision 1.1 1992/09/05 01:13:32 mike * Initial revision * */ /* * * SPAWN.C MODULE * Routines to create or run subjobs in the system command interpreter. */ /* Copyright 1990, 1991, 1992 Craig Durland * Distributed under the terms of the GNU General Public License. * Distributed "as is", without warranties of any kind, but comments, * suggestions and bug reports are welcome. */ #include #include "me2.h" #ifdef atarist #include #include #include #include "gem.h" #include "stio.h" static char *Default_shell = "c:/bin/msh.prg"; #endif #ifdef __TSC__ #include #endif extern char *getenv(); /* * Fork a shell so the user can mess around outside of ME and return to * their edit session later. * When the command interpreter exits, mark the screen as garbage so that * you do a full repaint. * Bound to "C-z" */ spawn_shell(f,n) { #if MSDOZ register char *ptr; close_display(TRUE); /* restore terminal for normal user interface */ #ifdef __TSC__ if ((ptr = getenv("SHELL")) != NULL && *ptr != '\0') spawnlp(P_WAIT,ptr,"ME",(char *)NULL); else spawnlp(P_WAIT,"command.com", "ME2", (char *)NULL); #else if ((ptr = getenv("SHELL")) != NULL && *ptr != '\0') forklp(ptr,"ME",(char *)NULL); else forklp("command.com", "ME2", (char *)NULL); #endif open_display(); /* set up terminal for editor */ return TRUE; #endif #if UX_OS register char *ptr; if (f) sig_pause(0); /* try and use job control */ else { close_display(TRUE); /* restore terminal for normal user interface */ if ((ptr = getenv("SHELL")) != NULL && *ptr != '\0') #if 1 system(ptr); /* system("/bin/ksh"); */ #else /* ??? */ { char buf[300], *strcpy(), *strcat(); system(strcat(strcpy(buf,"exec "), ptr)); /* system("exec /bin/ksh"); */ } #endif else system("exec sh"); /* default shell */ open_display(); /* set up terminal for editor */ } return TRUE; #endif #if AMIGA /* !!! this needs updating */ long newcli; newcli = Open("CON:1/1/639/199/ME Subprocess", 1006); mlwrite("[Starting new CLI]"); refresh(FALSE,1); Execute("", newcli, 0); Close(newcli); return(TRUE); #endif #if ATARI char *shell; if ((shell = getenv("ME2_ISHELL")) == NULL) { if ((shell = getenv("SHELL")) == NULL) shell = Default_shell; } mlwrite(shell); TOS_mode(); system(shell); GEM_mode(); update(); return TRUE; #endif } /* * Have the shell (or OS) run a command (such as LS). * When the command returns, wait for a single character to be typed (unless * a program is running), then mark the screen as garbage so a full * repaint is done. * Bound to "C-x !" */ shell_command(f,n) { char line[NLINE]; register int s; extern int MMask_pgm; /* in mm.c */ #if UX_OS || MSDOZ if ((s = mlreply("Shell command: ", line, NLINE,0)) !=TRUE) return s; close_display(FALSE); /* restore terminal for normal user interface */ t_putchar('\n'); /* so the cmd doesn't overwrite the minibuffer */ s = system(line); if (!MMask_pgm) { t_puts("[Return to resume editing]"); t_flush(); while ((s = t_getchar()) != '\r' && s != '\n') ; } open_display(); /* takeover terminal AFTER resuming editing! */ return !s; #endif #if AMIGA /* !!! bet this don't work anymore */ long newcli; newcli = Open("CON:1/1/639/199/ME Subprocess", 1006); if ((s = mlreply("CLI command: ", line, NLINE,0)) !=TRUE) return s; Execute(line,0,newcli); Close(newcli); if (!MMask_pgm) while (t_getchar() != '\r') ; /* Pause */ refresh(FALSE,1); return TRUE; #endif #if ATARI char *shell; if ((s = mlreply("!", line, NLINE,0)) != TRUE) return s; if ((shell = getenv("ME2_SHELL")) == NULL) { if ((shell = getenv("SHELL")) == NULL) shell = Default_shell; } TOS_mode(); s = spawnl(P_WAIT,shell,shell,"-c",line,NULL); if (!MMask_pgm) { Cconws("\n[Hit Return to resume editing]"); Cconin(); } GEM_mode(); update(); return !s; #endif } /* Filter some ME2 stuff through the OS (usually the shell). The user can't * have any interaction with the filter because i/o is redirected. * Input to the filter: * Zip: the filter will get a empty file as std input. This will keep a * filter from waiting for user input if it really wants input. * bag: the filter will get the contents of a bag as stdin. * Output from the filter: * Zip: the filters output (stdout) is thrown away. * bag: the filter output is stored in a bag. The old bag contents is * lost. * ? : insert the output of the filter at dot. * Input to os_filter: * filter_name: name of the filter to invoke. * in_bag: If !NULL, contains stuff to use as stdin. * out_bag: If !NULL, store stdout in there. * insert_output_at_dot: If TRUE, insert stdout at dot. * Returns: TRUE if everything worked, FALSE if problems. * Notes: * If !out_bag and !insert_output_at_dot then don't need to "> stdout". */ os_filter(filter_name,in_bag,out_bag, insert_output_at_dot) char *filter_name; Bag *in_bag, *out_bag; int insert_output_at_dot; { extern char *strcpy(), *strcat(), *unique_file_name(); char filter[NLINE+300], fin[150], fout[150]; FILE *fptr; #if ATARI char *shell; #endif int s; if (insert_output_at_dot && (curbp->b_flags & BFVIEW)) { view_mode_violation(); return FALSE; } strcpy(filter,filter_name); if (in_bag) { unique_file_name(fin); if (!bag_to_file(in_bag,fin)) return FALSE; strcat(filter," <"); strcat(filter,fin); } if (out_bag || insert_output_at_dot) { unique_file_name(fout); strcat(filter," >"); strcat(filter,fout); } #if ATARI if ((shell = getenv("ME2_SHELL")) == NULL) { if ((shell = getenv("SHELL")) == NULL) shell = Default_shell; } TOS_mode(); puts(filter); if (spawnl(P_WAIT,shell,shell,"-c",filter,NULL)) { s = FALSE; GEM_mode(); goto done; } else s = TRUE; GEM_mode(); #else if (system(filter)) { mlwrite("Filter failed."); s = FALSE; goto done; } #endif /* * mess with output of the filter */ if (insert_output_at_dot) /* insert the filters output at dot */ s = insfile(fout); if (out_bag) /* copy the filters output to a bag */ { clear_bag(out_bag); s = file_to_bag(fout,out_bag); } #if !ATARI if (s) refresh(FALSE,1); /* since filter might garbage screen */ #endif done: if (in_bag) unlink(fin); if (out_bag || insert_output_at_dot) unlink(fout); return s; }