/************************************************************************ * "Epsilon", "EEL" and "Lugaru" are trademarks of Lugaru Software, Ltd. * * * * Copyright (C) 1985, 1989 Lugaru Software Ltd. All rights reserved. * * * * Limited permission is hereby granted to reproduce and modify this * * copyrighted material provided that the resulting code is used only in * * conjunction with Lugaru products and that this notice is retained in * * any such reproduction or modification. * ************************************************************************/ #include "eel.h" /* Process commands. */ char push_cmd[80] = "make"; no_running() /* make sure no process is running */ { if (!another) return 0; say("A process is already running."); locate_window("process", ""); point = size(); return 1; } char *get_cmdline(msg, buf) char *msg, *buf; { if (!has_arg) return ""; get_strdef(buf, msg, push_cmd); strcpy(push_cmd, buf); return push_cmd; } command push() on cx_tab[CTRL('E')] { char cmd[80]; #ifdef MSDOS if (no_running()) return; #endif do_push(get_cmdline("Push With Command", cmd), capture_output, 1); } do_push(cmdline, cap, show) char *cmdline; { char *s, *orig = bufname; int result; iter = 1; sayput(""); term_position(0, screen_lines - 1); term_mode(0); if (cap) zap(s = (another ? temp_buf() : "process")); result = shell("", cmdline, cap ? s : ""); if (cap && another) { bufname = "process"; point = *type_point; if (error_spot) *error_spot = point; to_begin_line(); if (cmdline[0]) bprintf("%s\n", cmdline); bufname = s; xfer("process", 0, size()); bufname = "process"; if (point > *type_point) *type_point = point; delete_buffer(s); bufname = orig; } if (cmdline[0]) { if (!cap) { if (!char_avail()) { s = "Press any key to return to Epsilon"; term_write(0, screen_lines - 1, s, strlen(s), alter_color(2, -1), 1); term_position(strlen(s), screen_lines - 1); } getkey(); } else if (show) { locate_window("process", ""); point = size(); } } build_first = 1; screen_messed(); term_mode(1); say(""); if (result == -1) { file_error(errno, "During exec", "error"); quick_abort(); } if (cmdline[0] && result) say("Process returned %d", result); return result; } command start_process() on cx_tab[CTRL('M')] { int result; char cmd[80], *cmdline; if (no_running()) return; cmdline = get_cmdline("Start Process With Command", cmd); zap("process"); result = concur_shell("", cmdline); iter = 1; if (result) error("Couldn't exec: error %d", errno); to_buffer("process"); process_mode(); } command stop_process() on reg_tab[CTRL('C')] { halt_process(has_arg); iter = 1; } command make() on cx_tab['m'] { char buf[80]; int err = 0; get_cmdline("Make using command", buf); maybe_save_all(); if (no_running()) { /* goes to end of proc buffer */ if (error_spot) *error_spot = point; if (*push_cmd) bprintf("%s\n", push_cmd); iter = 1; delay(-1, COND_PROC | COND_KEY); if (!another || !process_input()) return; /* else assume it's compiled */ } else err = do_push(push_cmd, 1, 0); if (!do_next_error(1) && err) say("Process returned %d", err); } char ignore_error[70]; /* if error matches this pattern, we will ignore it */ /* to ignore warnings, for example, set to .*warning.* */ command next_error() on cx_tab[CTRL('N')] { do_next_error(iter); iter = 1; } #define ERROR_PATTERN "(([a-z]:)*[+-0A-z\\\/]+) *%(([0-9]+)%) *.*" #define FILE_PAREN 1 #define LINE_PAREN 3 do_next_error(count) { char *orig = bufname, file[FNAMELEN], number[30], line[130], *msg; int lineno, origpt, dir, old; if (!exist("process")) error("No process buffer to read errors from."); bufname = "process"; origpt = point; case_fold = 1; if (error_spot) point = *error_spot; else { error_spot = alloc_spot(); point = 0; } msg = point ? "No more errors" : "No errors"; sayput("Searching..."); if (!count) find_error(-1), count = 1; dir = (count > 0) ? 1 : -1; for (; count; count -= dir) { if (!find_error(dir)) { point = origpt; bufname = orig; say(msg); return 0; } if (dir > 0) to_end_line(); } grab(find_group(FILE_PAREN, 1), find_group(FILE_PAREN, 0), file); grab(find_group(LINE_PAREN, 1), find_group(LINE_PAREN, 0), number); grab(find_group(0, 1), find_group(0, 0), line); *error_spot = point; point = origpt; lineno = strtoi(number, 10); absolute(file); bufname = orig; locate_window("", file); find_it(file, 1); go_line(lineno); say("=>%.78s", line); return 1; } find_error(dir) /* find next error in direction, return 1 */ { int old = point; while (search(dir, ")")) { to_begin_line(); if ((!*ignore_error || !parse_string(1, ignore_error, (char *)0)) && parse_string(1, ERROR_PATTERN, (char *)0)) return 1; if (dir > 0) nl_forward(); } *error_spot = old; return 0; } keytable process_tab; char process_mode_name[] = "Process"; command process_mode() { mode_keys = process_tab; major_mode = process_mode_name; make_mode(); } command process_enter() on process_tab['\r'] { enter_key(); if (error_spot && (*error_spot <= point)) *error_spot = point; }