File: acompile.sl

package info (click to toggle)
jed 0.99.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,312 kB
  • ctags: 4,736
  • sloc: ansic: 36,879; sh: 8,660; makefile: 379
file content (105 lines) | stat: -rw-r--r-- 2,142 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
% Asynchronous compilation

static variable Compile_Last_Compile_Cmd = "";
public variable Compile_Process_Id = -1;

static define compile_set_status_line (state)
{
   set_mode ("compile: " + state, 0);
}

static define compile_signal_handler (pid, flags, status)
{
   variable str = aprocess_stringify_status (pid, flags, status);

   push_spot ();
   eob ();
   vinsert ("\n\nProcess no longer running: %s\n", str);
   pop_spot ();
   
   compile_set_status_line (str);
   
   if (flags != 2) Compile_Process_Id = -1;
}

	
static define compile_start_process (cmd)
{
   variable dir, name, file, flags;
   variable shell, shopt;

   if (cmd == NULL)
     cmd = read_mini ("Compile command:", "", Compile_Last_Compile_Cmd);
   !if (strlen (cmd))
     return;

   (,dir,,) = getbuf_info ();
   if (change_default_dir (dir)) 
     error ("Unable to chdir.");
   
   pop2buf (Compile_Output_Buffer);

   set_readonly (0);
   erase_buffer ();
   (file,,name,flags) = getbuf_info ();
   setbuf_info (file, dir, name, flags);
   Compile_Line_Mark = 0;
   
   compile_set_status_line ("");
   insert (cmd); newline ();

#ifdef WIN32
   shopt = "";
   shell = "";
#else
   shell = getenv ("SHELL");
   if (shell == NULL) shell = "sh";
   shopt = "-c";   
#endif

   Compile_Process_Id = open_process (shell,shopt, cmd, 2);

   if (Compile_Process_Id == -1)
     error ("Unable to start subprocess.");
   
   compile_set_status_line ("run");
   Compile_Last_Compile_Cmd = cmd;
   
   set_process (Compile_Process_Id, "signal", &compile_signal_handler);
   set_process (Compile_Process_Id, "output", "@");
}



public define compile ()
{
   variable b, n;
   variable cmd = NULL;

   if (_NARGS == 1)
     cmd = ();

   Compile_Output_Buffer = "*compile*";
   
   if (Compile_Process_Id != -1)
     {
	if (bufferp (Compile_Output_Buffer))
	  error ("A compile process is already running.");
	ERROR_BLOCK
	  {
	     _clear_error ();
	  }
	kill_process (Compile_Process_Id);
	Compile_Process_Id = -1;
     }
	
   
   b = whatbuf();
   call ("save_some_buffers");
   
   compile_start_process (cmd);
   
   pop2buf(b);
   
   %compile_parse_errors ();
}