aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1990-12-25 23:11:33 +0000
committerRichard M. Stallman1990-12-25 23:11:33 +0000
commit7942b8aeb70be250a05fd2ff793c0c402bbb67d0 (patch)
tree6097accb889383cf79de77d472fa0cc563e09c01
parent0f91ee7e0170c018b412d1c012590b66e0a579e8 (diff)
downloademacs-7942b8aeb70be250a05fd2ff793c0c402bbb67d0.tar.gz
emacs-7942b8aeb70be250a05fd2ff793c0c402bbb67d0.zip
Initial revision
-rw-r--r--src/abbrev.c540
-rw-r--r--src/vmsfns.c961
2 files changed, 1501 insertions, 0 deletions
diff --git a/src/abbrev.c b/src/abbrev.c
new file mode 100644
index 00000000000..0412a062bcf
--- /dev/null
+++ b/src/abbrev.c
@@ -0,0 +1,540 @@
1/* Primitives for word-abbrev mode.
2 Copyright (C) 1985, 1986 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21#include "config.h"
22#include <stdio.h>
23#undef NULL
24#include "lisp.h"
25#include "commands.h"
26#include "buffer.h"
27#include "window.h"
28
29/* An abbrev table is an obarray.
30 Each defined abbrev is represented by a symbol in that obarray
31 whose print name is the abbreviation.
32 The symbol's value is a string which is the expansion.
33 If its function definition is non-nil, it is called
34 after the expansion is done.
35 The plist slot of the abbrev symbol is its usage count. */
36
37/* List of all abbrev-table name symbols:
38 symbols whose values are abbrev tables. */
39
40Lisp_Object Vabbrev_table_name_list;
41
42/* The table of global abbrevs. These are in effect
43 in any buffer in which abbrev mode is turned on. */
44
45Lisp_Object Vglobal_abbrev_table;
46
47/* The local abbrev table used by default (in Fundamental Mode buffers) */
48
49Lisp_Object Vfundamental_mode_abbrev_table;
50
51/* Set nonzero when an abbrev definition is changed */
52
53int abbrevs_changed;
54
55int abbrev_all_caps;
56
57/* Non-nil => use this location as the start of abbrev to expand
58 (rather than taking the word before point as the abbrev) */
59
60Lisp_Object Vabbrev_start_location;
61
62/* Buffer that Vabbrev_start_location applies to */
63Lisp_Object Vabbrev_start_location_buffer;
64
65/* The symbol representing the abbrev most recently expanded */
66
67Lisp_Object Vlast_abbrev;
68
69/* A string for the actual text of the abbrev most recently expanded.
70 This has more info than Vlast_abbrev since case is significant. */
71
72Lisp_Object Vlast_abbrev_text;
73
74/* Character address of start of last abbrev expanded */
75
76int last_abbrev_point;
77
78
79DEFUN ("make-abbrev-table", Fmake_abbrev_table, Smake_abbrev_table, 0, 0, 0,
80 "Create a new, empty abbrev table object.")
81 ()
82{
83 return Fmake_vector (make_number (59), make_number (0));
84}
85
86DEFUN ("clear-abbrev-table", Fclear_abbrev_table, Sclear_abbrev_table, 1, 1, 0,
87 "Undefine all abbrevs in abbrev table TABLE, leaving it empty.")
88 (table)
89 Lisp_Object table;
90{
91 int i, size;
92
93 CHECK_VECTOR (table, 0);
94 size = XVECTOR (table)->size;
95 abbrevs_changed = 1;
96 for (i = 0; i < size; i++)
97 XVECTOR (table)->contents[i] = make_number (0);
98 return Qnil;
99}
100
101DEFUN ("define-abbrev", Fdefine_abbrev, Sdefine_abbrev, 3, 5, 0,
102 "Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK.\n\
103NAME and EXPANSION are strings.\n\
104To undefine an abbrev, define it with EXPANSION = nil.\n\
105If HOOK is non-nil, it should be a function of no arguments;\n\
106it is called after EXPANSION is inserted.")
107 (table, name, expansion, hook, count)
108 Lisp_Object table, name, expansion, hook, count;
109{
110 Lisp_Object sym, oexp, ohook, tem;
111 CHECK_VECTOR (table, 0);
112 CHECK_STRING (name, 1);
113 if (!NULL (expansion))
114 CHECK_STRING (expansion, 2);
115 if (NULL (count))
116 count = make_number (0);
117 else
118 CHECK_NUMBER (count, 0);
119
120 sym = Fintern (name, table);
121
122 oexp = XSYMBOL (sym)->value;
123 ohook = XSYMBOL (sym)->function;
124 if (!((EQ (oexp, expansion)
125 || (XTYPE (oexp) == Lisp_String && XTYPE (expansion) == Lisp_String
126 && (tem = Fstring_equal (oexp, expansion), !NULL (tem))))
127 &&
128 (EQ (ohook, hook)
129 || (tem = Fequal (ohook, hook), !NULL (tem)))))
130 abbrevs_changed = 1;
131
132 Fset (sym, expansion);
133 Ffset (sym, hook);
134 Fsetplist (sym, count);
135
136 return name;
137}
138
139DEFUN ("define-global-abbrev", Fdefine_global_abbrev, Sdefine_global_abbrev, 2, 2,
140 "sDefine global abbrev: \nsExpansion for %s: ",
141 "Define ABBREV as a global abbreviation for EXPANSION.")
142 (name, expansion)
143 Lisp_Object name, expansion;
144{
145 Fdefine_abbrev (Vglobal_abbrev_table, Fdowncase (name),
146 expansion, Qnil, make_number (0));
147 return name;
148}
149
150DEFUN ("define-mode-abbrev", Fdefine_mode_abbrev, Sdefine_mode_abbrev, 2, 2,
151 "sDefine mode abbrev: \nsExpansion for %s: ",
152 "Define ABBREV as a mode-specific abbreviation for EXPANSION.")
153 (name, expansion)
154 Lisp_Object name, expansion;
155{
156 if (NULL (current_buffer->abbrev_table))
157 error ("Major mode has no abbrev table");
158
159 Fdefine_abbrev (current_buffer->abbrev_table, Fdowncase (name),
160 expansion, Qnil, make_number (0));
161 return name;
162}
163
164DEFUN ("abbrev-symbol", Fabbrev_symbol, Sabbrev_symbol, 1, 2, 0,
165 "Return the symbol representing abbrev named ABBREV.\n\
166This symbol's name is ABBREV, but it is not the canonical symbol of that name;\n\
167it is interned in an abbrev-table rather than the normal obarray.\n\
168The value is nil if that abbrev is not defined.\n\
169Optional second arg TABLE is abbrev table to look it up in.\n\
170The default is to try buffer's mode-specific abbrev table, then global table.")
171 (abbrev, table)
172 Lisp_Object abbrev, table;
173{
174 Lisp_Object sym;
175 CHECK_STRING (abbrev, 0);
176 if (!NULL (table))
177 sym = Fintern_soft (abbrev, table);
178 else
179 {
180 sym = Qnil;
181 if (!NULL (current_buffer->abbrev_table))
182 sym = Fintern_soft (abbrev, current_buffer->abbrev_table);
183 if (NULL (XSYMBOL (sym)->value))
184 sym = Qnil;
185 if (NULL (sym))
186 sym = Fintern_soft (abbrev, Vglobal_abbrev_table);
187 }
188 if (NULL (XSYMBOL (sym)->value)) return Qnil;
189 return sym;
190}
191
192DEFUN ("abbrev-expansion", Fabbrev_expansion, Sabbrev_expansion, 1, 2, 0,
193 "Return the string that ABBREV expands into in the current buffer.\n\
194Optionally specify an abbrev table as second arg;\n\
195then ABBREV is looked up in that table only.")
196 (abbrev, table)
197 Lisp_Object abbrev, table;
198{
199 Lisp_Object sym;
200 sym = Fabbrev_symbol (abbrev, table);
201 if (NULL (sym)) return sym;
202 return Fsymbol_value (sym);
203}
204
205/* Expand the word before point, if it is an abbrev.
206 Returns 1 if an expansion is done. */
207
208DEFUN ("expand-abbrev", Fexpand_abbrev, Sexpand_abbrev, 0, 0, "",
209 "Expand the abbrev before point, if there is an abbrev there.\n\
210Effective when explicitly called even when `abbrev-mode' is nil.\n\
211Returns t if expansion took place.")
212 ()
213{
214 register char *buffer, *p;
215 register int wordstart, wordend, idx;
216 int whitecnt;
217 int uccount = 0, lccount = 0;
218 register Lisp_Object sym;
219 Lisp_Object expansion, hook, tem;
220
221 if (XBUFFER (Vabbrev_start_location_buffer) != current_buffer)
222 Vabbrev_start_location = Qnil;
223 if (!NULL (Vabbrev_start_location))
224 {
225 tem = Vabbrev_start_location;
226 CHECK_NUMBER_COERCE_MARKER (tem, 0);
227 wordstart = XINT (tem);
228 Vabbrev_start_location = Qnil;
229 if (FETCH_CHAR (wordstart) == '-')
230 del_range (wordstart, wordstart + 1);
231 }
232 else
233 wordstart = scan_words (point, -1);
234
235 if (!wordstart)
236 return Qnil;
237
238 wordend = scan_words (wordstart, 1);
239 if (!wordend)
240 return Qnil;
241
242 if (wordend > point)
243 wordend = point;
244 whitecnt = point - wordend;
245 if (wordend <= wordstart)
246 return Qnil;
247
248 p = buffer = (char *) alloca (wordend - wordstart);
249
250 for (idx = wordstart; idx < point; idx++)
251 {
252 register int c = FETCH_CHAR (idx);
253 if (UPPERCASEP (c))
254 c = DOWNCASE (c), uccount++;
255 else if (! NOCASEP (c))
256 lccount++;
257 *p++ = c;
258 }
259
260 if (XTYPE (current_buffer->abbrev_table) == Lisp_Vector)
261 sym = oblookup (current_buffer->abbrev_table, buffer, p - buffer);
262 else
263 XFASTINT (sym) = 0;
264 if (XTYPE (sym) == Lisp_Int || NULL (XSYMBOL (sym)->value))
265 sym = oblookup (Vglobal_abbrev_table, buffer, p - buffer);
266 if (XTYPE (sym) == Lisp_Int || NULL (XSYMBOL (sym)->value))
267 return Qnil;
268
269 if (INTERACTIVE && !EQ (minibuf_window, selected_window))
270 {
271 SET_PT (wordend);
272 Fundo_boundary ();
273 }
274 SET_PT (wordstart);
275 Vlast_abbrev_text
276 = Fbuffer_substring (make_number (wordstart), make_number (wordend));
277 del_range (wordstart, wordend);
278
279 /* Now sym is the abbrev symbol. */
280 Vlast_abbrev = sym;
281 last_abbrev_point = wordstart;
282
283 if (XTYPE (XSYMBOL (sym)->plist) == Lisp_Int)
284 XSETINT (XSYMBOL (sym)->plist,
285 XINT (XSYMBOL (sym)->plist) + 1); /* Increment use count */
286
287 expansion = XSYMBOL (sym)->value;
288 insert_from_string (expansion, 0, XSTRING (expansion)->size);
289 SET_PT (point + whitecnt);
290
291 if (uccount && !lccount)
292 {
293 /* Abbrev was all caps */
294 /* If expansion is multiple words, normally capitalize each word */
295 /* This used to be if (!... && ... >= ...) Fcapitalize; else Fupcase
296 but Megatest 68000 compiler can't handle that */
297 if (!abbrev_all_caps)
298 if (scan_words (point, -1) > scan_words (wordstart, 1))
299 {
300 upcase_initials_region (make_number (wordstart),
301 make_number (point));
302 goto caped;
303 }
304 /* If expansion is one word, or if user says so, upcase it all. */
305 Fupcase_region (make_number (wordstart), make_number (point));
306 caped: ;
307 }
308 else if (uccount)
309 {
310 /* Abbrev included some caps. Cap first initial of expansion */
311 idx = point;
312 SET_PT (wordstart);
313 Fcapitalize_word (make_number (1));
314 SET_PT (idx);
315 }
316
317 hook = XSYMBOL (sym)->function;
318 if (!NULL (hook))
319 call0 (hook);
320
321 return Qt;
322}
323
324DEFUN ("unexpand-abbrev", Funexpand_abbrev, Sunexpand_abbrev, 0, 0, "",
325 "Undo the expansion of the last abbrev that expanded.\n\
326This differs from ordinary undo in that other editing done since then\n\
327is not undone.")
328 ()
329{
330 int opoint = point;
331 int adjust = 0;
332 if (last_abbrev_point < BEGV
333 || last_abbrev_point > ZV)
334 return Qnil;
335 SET_PT (last_abbrev_point);
336 if (XTYPE (Vlast_abbrev_text) == Lisp_String)
337 {
338 /* This isn't correct if Vlast_abbrev->function was used
339 to do the expansion */
340 Lisp_Object val;
341 XSET (val, Lisp_String, XSYMBOL (Vlast_abbrev)->value);
342 adjust = XSTRING (val)->size;
343 del_range (point, point + adjust);
344 insert_from_string (Vlast_abbrev_text, 0,
345 XSTRING (Vlast_abbrev_text)->size);
346 adjust -= XSTRING (Vlast_abbrev_text)->size;
347 Vlast_abbrev_text = Qnil;
348 }
349 SET_PT (last_abbrev_point < opoint ? opoint - adjust : opoint);
350 return Qnil;
351}
352
353static
354write_abbrev (sym, stream)
355 Lisp_Object sym, stream;
356{
357 Lisp_Object name;
358 if (NULL (XSYMBOL (sym)->value))
359 return;
360 insert (" (", 5);
361 XSET (name, Lisp_String, XSYMBOL (sym)->name);
362 Fprin1 (name, stream);
363 insert (" ", 1);
364 Fprin1 (XSYMBOL (sym)->value, stream);
365 insert (" ", 1);
366 Fprin1 (XSYMBOL (sym)->function, stream);
367 insert (" ", 1);
368 Fprin1 (XSYMBOL (sym)->plist, stream);
369 insert (")\n", 2);
370}
371
372static
373describe_abbrev (sym, stream)
374 Lisp_Object sym, stream;
375{
376 Lisp_Object one;
377
378 if (NULL (XSYMBOL (sym)->value))
379 return;
380 one = make_number (1);
381 Fprin1 (Fsymbol_name (sym), stream);
382 Findent_to (make_number (15), one);
383 Fprin1 (XSYMBOL (sym)->plist, stream);
384 Findent_to (make_number (20), one);
385 Fprin1 (XSYMBOL (sym)->value, stream);
386 if (!NULL (XSYMBOL (sym)->function))
387 {
388 Findent_to (make_number (45), one);
389 Fprin1 (XSYMBOL (sym)->function, stream);
390 }
391 Fterpri (stream);
392}
393
394DEFUN ("insert-abbrev-table-description",
395 Finsert_abbrev_table_description, Sinsert_abbrev_table_description,
396 1, 2, 0,
397 "Insert before point a full description of abbrev table named NAME.\n\
398NAME is a symbol whose value is an abbrev table.\n\
399If optional 2nd arg HUMAN is non-nil, a human-readable description is inserted.\n\
400Otherwise the description is an expression,\n\
401a call to `define-abbrev-table', which would\n\
402define the abbrev table NAME exactly as it is currently defined.")
403 (name, readable)
404 Lisp_Object name, readable;
405{
406 Lisp_Object table;
407 Lisp_Object stream;
408
409 CHECK_SYMBOL (name, 0);
410 table = Fsymbol_value (name);
411 CHECK_VECTOR (table, 0);
412
413 XSET (stream, Lisp_Buffer, current_buffer);
414
415 if (!NULL (readable))
416 {
417 insert_string ("(");
418 Fprin1 (name, stream);
419 insert_string (")\n\n");
420 map_obarray (table, describe_abbrev, stream);
421 insert_string ("\n\n");
422 }
423 else
424 {
425 insert_string ("(define-abbrev-table '");
426 Fprin1 (name, stream);
427 insert_string (" '(\n");
428 map_obarray (table, write_abbrev, stream);
429 insert_string (" ))\n\n");
430 }
431
432 return Qnil;
433}
434
435DEFUN ("define-abbrev-table", Fdefine_abbrev_table, Sdefine_abbrev_table,
436 2, 2, 0,
437 "Define TABNAME (a symbol) as an abbrev table name.\n\
438Define abbrevs in it according to DEFINITIONS, which is a list of elements\n\
439of the form (ABBREVNAME EXPANSION HOOK USECOUNT).")
440 (tabname, defns)
441 Lisp_Object tabname, defns;
442{
443 Lisp_Object name, exp, hook, count;
444 Lisp_Object table, elt;
445
446 CHECK_SYMBOL (tabname, 0);
447 table = Fboundp (tabname);
448 if (NULL (table) || (table = Fsymbol_value (tabname), NULL (table)))
449 {
450 table = Fmake_abbrev_table ();
451 Fset (tabname, table);
452 Vabbrev_table_name_list =
453 Fcons (tabname, Vabbrev_table_name_list);
454 }
455 CHECK_VECTOR (table, 0);
456
457 for (;!NULL (defns); defns = Fcdr (defns))
458 {
459 elt = Fcar (defns);
460 name = Fcar (elt);
461 elt = Fcdr (elt);
462 exp = Fcar (elt);
463 elt = Fcdr (elt);
464 hook = Fcar (elt);
465 elt = Fcdr (elt);
466 count = Fcar (elt);
467 Fdefine_abbrev (table, name, exp, hook, count);
468 }
469 return Qnil;
470}
471
472syms_of_abbrev ()
473{
474 DEFVAR_LISP ("abbrev-table-name-list", &Vabbrev_table_name_list,
475 "List of symbols whose values are abbrev tables.");
476 Vabbrev_table_name_list = Fcons (intern ("fundamental-mode-abbrev-table"),
477 Fcons (intern ("global-abbrev-table"),
478 Qnil));
479
480 DEFVAR_LISP ("global-abbrev-table", &Vglobal_abbrev_table,
481 "The abbrev table whose abbrevs affect all buffers.\n\
482Each buffer may also have a local abbrev table.\n\
483If it does, the local table overrides the global one\n\
484for any particular abbrev defined in both.");
485 Vglobal_abbrev_table = Fmake_abbrev_table ();
486
487 DEFVAR_LISP ("fundamental-mode-abbrev-table", &Vfundamental_mode_abbrev_table,
488 "The abbrev table of mode-specific abbrevs for Fundamental Mode.");
489 Vfundamental_mode_abbrev_table = Fmake_abbrev_table ();
490 current_buffer->abbrev_table = Vfundamental_mode_abbrev_table;
491
492 DEFVAR_LISP ("last-abbrev", &Vlast_abbrev,
493 "The abbrev-symbol of the last abbrev expanded. See `abbrev-symbol'.");
494
495 DEFVAR_LISP ("last-abbrev-text", &Vlast_abbrev_text,
496 "The exact text of the last abbrev expanded.\n\
497nil if the abbrev has already been unexpanded.");
498
499 DEFVAR_INT ("last-abbrev-location", &last_abbrev_point,
500 "The location of the start of the last abbrev expanded.");
501
502 Vlast_abbrev = Qnil;
503 Vlast_abbrev_text = Qnil;
504 last_abbrev_point = 0;
505
506 DEFVAR_LISP ("abbrev-start-location", &Vabbrev_start_location,
507 "Buffer position for `expand-abbrev' to use as the start of the abbrev.\n\
508nil means use the word before point as the abbrev.\n\
509Calling `expand-abbrev' sets this to nil.");
510 Vabbrev_start_location = Qnil;
511
512 DEFVAR_LISP ("abbrev-start-location-buffer", &Vabbrev_start_location_buffer,
513 "Buffer that `abbrev-start-location' has been set for.\n\
514Trying to expand an abbrev in any other buffer clears `abbrev-start-location'.");
515 Vabbrev_start_location_buffer = Qnil;
516
517 DEFVAR_PER_BUFFER ("local-abbrev-table", &current_buffer->abbrev_table,
518 "Local (mode-specific) abbrev table of current buffer.");
519
520 DEFVAR_BOOL ("abbrevs-changed", &abbrevs_changed,
521 "Set non-nil by defining or altering any word abbrevs.\n\
522This causes `save-some-buffers' to offer to save the abbrevs.");
523 abbrevs_changed = 0;
524
525 DEFVAR_BOOL ("abbrev-all-caps", &abbrev_all_caps,
526 "*Set non-nil means expand multi-word abbrevs all caps if abbrev was so.");
527 abbrev_all_caps = 0;
528
529 defsubr (&Smake_abbrev_table);
530 defsubr (&Sclear_abbrev_table);
531 defsubr (&Sdefine_abbrev);
532 defsubr (&Sdefine_global_abbrev);
533 defsubr (&Sdefine_mode_abbrev);
534 defsubr (&Sabbrev_expansion);
535 defsubr (&Sabbrev_symbol);
536 defsubr (&Sexpand_abbrev);
537 defsubr (&Sunexpand_abbrev);
538 defsubr (&Sinsert_abbrev_table_description);
539 defsubr (&Sdefine_abbrev_table);
540}
diff --git a/src/vmsfns.c b/src/vmsfns.c
new file mode 100644
index 00000000000..68b941abe2f
--- /dev/null
+++ b/src/vmsfns.c
@@ -0,0 +1,961 @@
1/* VMS subprocess and command interface.
2 Copyright (C) 1987, 1988 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20/* Written by Mukesh Prasad. */
21
22/*
23 * INTERFACE PROVIDED BY EMACS FOR VMS SUBPROCESSES:
24 *
25 * Emacs provides the following functions:
26 *
27 * "spawn-subprocess", which takes as arguments:
28 *
29 * (i) an integer to identify the spawned subprocess in future
30 * operations,
31 * (ii) A function to process input from the subprocess, and
32 * (iii) A function to be called upon subprocess termination.
33 *
34 * First argument is required. If second argument is missing or nil,
35 * the default action is to insert all received messages at the current
36 * location in the current buffer. If third argument is missing or nil,
37 * no action is taken upon subprocess termination.
38 * The input-handler is called as
39 * (input-handler num string)
40 * where num is the identifying integer for the subprocess and string
41 * is a string received from the subprocess. exit-handler is called
42 * with the identifying integer as the argument.
43 *
44 * "send-command-to-subprocess" takes two arguments:
45 *
46 * (i) Subprocess identifying integer.
47 * (ii) String to send as a message to the subprocess.
48 *
49 * "stop-subprocess" takes the subprocess identifying integer as
50 * argument.
51 *
52 * Implementation is done by spawning an asynchronous subprocess, and
53 * communicating to it via mailboxes.
54 */
55
56#ifdef VMS
57
58#include <stdio.h>
59#include <ctype.h>
60#undef NULL
61
62#include "config.h"
63#include "lisp.h"
64#include <descrip.h>
65#include <dvidef.h>
66#include <prvdef.h>
67/* #include <clidef.h> */
68#include <iodef.h>
69#include <ssdef.h>
70#include <errno.h>
71
72#ifdef VMS4_4 /* I am being cautious; perhaps this exists in older versions */
73#include <jpidef.h>
74#endif
75
76/* #include <syidef.h> */
77
78#define CLI$M_NOWAIT 1 /* clidef.h is missing from C library */
79#define SYI$_VERSION 4096 /* syidef.h is missing from C library */
80#define JPI$_CLINAME 522 /* JPI$_CLINAME is missing from jpidef.h */
81#define JPI$_MASTER_PID 805 /* JPI$_MASTER_PID missing from jpidef.h */
82#define LIB$_NOSUCHSYM 1409892 /* libclidef.h missing */
83
84#define MSGSIZE 160 /* Maximum size for mailbox operations */
85
86#ifndef PRV$V_ACNT
87
88/* these defines added as hack for VMS 5.1-1. SJones, 8-17-89 */
89/* this is _really_ nasty and needs to be changed ASAP - should see about
90 using the union defined in SYS$LIBRARY:PRVDEF.H under v5 */
91
92#define PRV$V_ACNT 0x09
93#define PRV$V_ALLSPOOL 0x04
94#define PRV$V_ALTPRI 0x0D
95#define PRV$V_BUGCHK 0x17
96#define PRV$V_BYPASS 0x1D
97#define PRV$V_CMEXEC 0x01
98#define PRV$V_CMKRNL 0x00
99#define PRV$V_DETACH 0x05
100#define PRV$V_DIAGNOSE 0x06
101#define PRV$V_DOWNGRADE 0x21
102#define PRV$V_EXQUOTA 0x13
103#define PRV$V_GROUP 0x08
104#define PRV$V_GRPNAM 0x03
105#define PRV$V_GRPPRV 0x22
106#define PRV$V_LOG_IO 0x07
107#define PRV$V_MOUNT 0x11
108#define PRV$V_NETMBX 0x14
109#define PRV$V_NOACNT 0x09
110#define PRV$V_OPER 0x12
111#define PRV$V_PFNMAP 0x1A
112#define PRV$V_PHY_IO 0x16
113#define PRV$V_PRMCEB 0x0A
114#define PRV$V_PRMGBL 0x18
115#define PRV$V_PRMJNL 0x25
116#define PRV$V_PRMMBX 0x0B
117#define PRV$V_PSWAPM 0x0C
118#define PRV$V_READALL 0x23
119#define PRV$V_SECURITY 0x26
120#define PRV$V_SETPRI 0x0D
121#define PRV$V_SETPRV 0x0E
122#define PRV$V_SHARE 0x1F
123#define PRV$V_SHMEM 0x1B
124#define PRV$V_SYSGBL 0x19
125#define PRV$V_SYSLCK 0x1E
126#define PRV$V_SYSNAM 0x02
127#define PRV$V_SYSPRV 0x1C
128#define PRV$V_TMPJNL 0x24
129#define PRV$V_TMPMBX 0x0F
130#define PRV$V_UPGRADE 0x20
131#define PRV$V_VOLPRO 0x15
132#define PRV$V_WORLD 0x10
133#endif
134
135/* IO status block for mailbox operations. */
136struct mbx_iosb
137{
138 short status;
139 short size;
140 int pid;
141};
142
143/* Structure for maintaining linked list of subprocesses. */
144struct process_list
145{
146 int name; /* Numeric identifier for subprocess */
147 int process_id; /* VMS process address */
148 int process_active; /* 1 iff process has not exited yet */
149 int mbx_chan; /* Mailbox channel to write to process */
150 struct mbx_iosb iosb; /* IO status block for write operations */
151 Lisp_Object input_handler; /* Input handler for subprocess */
152 Lisp_Object exit_handler; /* Exit handler for subprocess */
153 struct process_list * next; /* Linked list chain */
154};
155
156/* Structure for privilege list. */
157struct privilege_list
158{
159 char * name;
160 int mask;
161};
162
163/* Structure for finding VMS related information. */
164struct vms_objlist
165{
166 char * name; /* Name of object */
167 Lisp_Object (* objfn)(); /* Function to retrieve VMS object */
168};
169
170static int exit_ast (); /* Called upon subprocess exit */
171static int create_mbx (); /* Creates mailbox */
172static void mbx_msg (); /* Writes null terminated string to mbx */
173static void write_to_mbx (); /* Writes message to string */
174static void start_mbx_input (); /* Queues I/O request to mailbox */
175
176static int input_mbx_chan = 0; /* Channel to read subprocess input on */
177static char input_mbx_name[20];
178 /* Storage for mailbox device name */
179static struct dsc$descriptor_s input_mbx_dsc;
180 /* Descriptor for mailbox device name */
181static struct process_list * process_list = 0;
182 /* Linked list of subprocesses */
183static char mbx_buffer[MSGSIZE];
184 /* Buffer to read from subprocesses */
185static struct mbx_iosb input_iosb;
186 /* IO status block for mailbox reads */
187
188int have_process_input, /* Non-zero iff subprocess input pending */
189 process_exited; /* Non-zero iff suprocess exit pending */
190
191/* List of privilege names and mask offsets */
192static struct privilege_list priv_list[] = {
193
194 { "ACNT", PRV$V_ACNT },
195 { "ALLSPOOL", PRV$V_ALLSPOOL },
196 { "ALTPRI", PRV$V_ALTPRI },
197 { "BUGCHK", PRV$V_BUGCHK },
198 { "BYPASS", PRV$V_BYPASS },
199 { "CMEXEC", PRV$V_CMEXEC },
200 { "CMKRNL", PRV$V_CMKRNL },
201 { "DETACH", PRV$V_DETACH },
202 { "DIAGNOSE", PRV$V_DIAGNOSE },
203 { "DOWNGRADE", PRV$V_DOWNGRADE }, /* Isn't VMS as low as you can go? */
204 { "EXQUOTA", PRV$V_EXQUOTA },
205 { "GRPPRV", PRV$V_GRPPRV },
206 { "GROUP", PRV$V_GROUP },
207 { "GRPNAM", PRV$V_GRPNAM },
208 { "LOG_IO", PRV$V_LOG_IO },
209 { "MOUNT", PRV$V_MOUNT },
210 { "NETMBX", PRV$V_NETMBX },
211 { "NOACNT", PRV$V_NOACNT },
212 { "OPER", PRV$V_OPER },
213 { "PFNMAP", PRV$V_PFNMAP },
214 { "PHY_IO", PRV$V_PHY_IO },
215 { "PRMCEB", PRV$V_PRMCEB },
216 { "PRMGBL", PRV$V_PRMGBL },
217 { "PRMJNL", PRV$V_PRMJNL },
218 { "PRMMBX", PRV$V_PRMMBX },
219 { "PSWAPM", PRV$V_PSWAPM },
220 { "READALL", PRV$V_READALL },
221 { "SECURITY", PRV$V_SECURITY },
222 { "SETPRI", PRV$V_SETPRI },
223 { "SETPRV", PRV$V_SETPRV },
224 { "SHARE", PRV$V_SHARE },
225 { "SHMEM", PRV$V_SHMEM },
226 { "SYSGBL", PRV$V_SYSGBL },
227 { "SYSLCK", PRV$V_SYSLCK },
228 { "SYSNAM", PRV$V_SYSNAM },
229 { "SYSPRV", PRV$V_SYSPRV },
230 { "TMPJNL", PRV$V_TMPJNL },
231 { "TMPMBX", PRV$V_TMPMBX },
232 { "UPGRADE", PRV$V_UPGRADE },
233 { "VOLPRO", PRV$V_VOLPRO },
234 { "WORLD", PRV$V_WORLD },
235
236 };
237
238static Lisp_Object
239 vms_account(), vms_cliname(), vms_owner(), vms_grp(), vms_image(),
240 vms_parent(), vms_pid(), vms_prcnam(), vms_terminal(), vms_uic_int(),
241 vms_uic_str(), vms_username(), vms_version_fn(), vms_trnlog(),
242 vms_symbol(), vms_proclist();
243
244/* Table of arguments to Fvms_object, and the handlers that get the data. */
245
246static struct vms_objlist vms_object [] = {
247 { "ACCOUNT", vms_account }, /* Returns account name as a string */
248 { "CLINAME", vms_cliname }, /* Returns CLI name (string) */
249 { "OWNER", vms_owner }, /* Returns owner process's PID (int) */
250 { "GRP", vms_grp }, /* Returns group number of UIC (int) */
251 { "IMAGE", vms_image }, /* Returns executing image (string) */
252 { "PARENT", vms_parent }, /* Returns parent proc's PID (int) */
253 { "PID", vms_pid }, /* Returns process's PID (int) */
254 { "PRCNAM", vms_prcnam }, /* Returns process's name (string) */
255 { "TERMINAL", vms_terminal }, /* Returns terminal name (string) */
256 { "UIC", vms_uic_int }, /* Returns UIC as integer */
257 { "UICGRP", vms_uic_str }, /* Returns UIC as string */
258 { "USERNAME", vms_username }, /* Returns username (string) */
259 { "VERSION", vms_version_fn },/* Returns VMS version (string) */
260 { "LOGICAL", vms_trnlog }, /* Translates VMS logical name */
261 { "DCL-SYMBOL", vms_symbol }, /* Translates DCL symbol */
262 { "PROCLIST", vms_proclist }, /* Returns list of all PIDs on system */
263 };
264
265Lisp_Object Qdefault_subproc_input_handler;
266
267extern int process_ef; /* Event flag for subprocess operations */
268
269DEFUN ("default-subprocess-input-handler",
270 Fdefault_subproc_input_handler, Sdefault_subproc_input_handler,
271 2, 2, 0,
272 "Default input handler for input from spawned subprocesses.")
273 (name, input)
274 Lisp_Object name, input;
275{
276 /* Just insert in current buffer */
277 insert1 (input);
278 insert ("\n", 1);
279}
280
281DEFUN ("spawn-subprocess", Fspawn_subprocess, Sspawn_subprocess, 1, 3, 0,
282 "Spawn an asynchronous VMS suprocess for command processing.")
283 (name, input_handler, exit_handler)
284 Lisp_Object name, input_handler, exit_handler;
285{
286 int status;
287 char output_mbx_name[20];
288 struct dsc$descriptor_s output_mbx_dsc;
289 struct process_list *ptr, *p, *prev;
290
291 CHECK_NUMBER (name, 0);
292 if (! input_mbx_chan)
293 {
294 if (! create_mbx (&input_mbx_dsc, input_mbx_name, &input_mbx_chan, 1))
295 return Qnil;
296 start_mbx_input ();
297 }
298 ptr = 0;
299 prev = 0;
300 while (ptr)
301 {
302 struct process_list *next = ptr->next;
303 if (ptr->name == XFASTINT (name))
304 {
305 if (ptr->process_active)
306 return Qt;
307
308 /* Delete this process and run its exit handler. */
309 if (prev)
310 prev->next = next;
311 else
312 process_list = next;
313 if (! NULL (ptr->exit_handler))
314 Feval (Fcons (ptr->exit_handler, Fcons (make_number (ptr->name),
315 Qnil)));
316 sys$dassgn (ptr->mbx_chan);
317 break;
318 }
319 else
320 prev = ptr;
321 ptr = next;
322 }
323 if (! ptr)
324 ptr = xmalloc (sizeof (struct process_list));
325 if (! create_mbx (&output_mbx_dsc, output_mbx_name, &ptr->mbx_chan, 2))
326 {
327 free (ptr);
328 return Qnil;
329 }
330 if (NULL (input_handler))
331 input_handler = Qdefault_subproc_input_handler;
332 ptr->input_handler = input_handler;
333 ptr->exit_handler = exit_handler;
334 message ("Creating subprocess...");
335 status = lib$spawn (0, &output_mbx_dsc, &input_mbx_dsc, &CLI$M_NOWAIT, 0,
336 &ptr->process_id, 0, 0, exit_ast, &ptr->process_active);
337 if (! (status & 1))
338 {
339 sys$dassgn (ptr->mbx_chan);
340 free (ptr);
341 error ("Unable to spawn subprocess");
342 return Qnil;
343 }
344 ptr->name = XFASTINT (name);
345 ptr->next = process_list;
346 ptr->process_active = 1;
347 process_list = ptr;
348 message ("Creating subprocess...done");
349 return Qt;
350}
351
352static void
353mbx_msg (ptr, msg)
354 struct process_list *ptr;
355 char *msg;
356{
357 write_to_mbx (ptr, msg, strlen (msg));
358}
359
360DEFUN ("send-command-to-subprocess",
361 Fsend_command_to_subprocess, Ssend_command_to_subprocess, 2, 2,
362 "sSend command to subprocess: \nsSend subprocess %s command: ",
363 "Send to VMS subprocess named NAME the string COMMAND.")
364 (name, command)
365 Lisp_Object name, command;
366{
367 struct process_list * ptr;
368
369 CHECK_NUMBER (name, 0);
370 CHECK_STRING (command, 1);
371 for (ptr = process_list; ptr; ptr = ptr->next)
372 if (XFASTINT (name) == ptr->name)
373 {
374 write_to_mbx (ptr, XSTRING (command)->data,
375 XSTRING (command)->size);
376 return Qt;
377 }
378 return Qnil;
379}
380
381DEFUN ("stop-subprocess", Fstop_subprocess, Sstop_subprocess, 1, 1,
382 "sStop subprocess: ", "Stop VMS subprocess named NAME.")
383 (name)
384 Lisp_Object name;
385{
386 struct process_list * ptr;
387
388 CHECK_NUMBER (name, 0);
389 for (ptr = process_list; ptr; ptr = ptr->next)
390 if (XFASTINT (name) == ptr->name)
391 {
392 ptr->exit_handler = Qnil;
393 if (sys$delprc (&ptr->process_id, 0) & 1)
394 ptr->process_active = 0;
395 return Qt;
396 }
397 return Qnil;
398}
399
400static int
401exit_ast (active)
402 int * active;
403{
404 process_exited = 1;
405 *active = 0;
406 sys$setef (process_ef);
407}
408
409/* Process to handle input on the input mailbox.
410 * Searches through the list of processes until the matching PID is found,
411 * then calls its input handler.
412 */
413
414process_command_input ()
415{
416 struct process_list * ptr;
417 char * msg;
418 int msglen;
419 Lisp_Object expr;
420
421 msg = mbx_buffer;
422 msglen = input_iosb.size;
423 /* Hack around VMS oddity of sending extraneous CR/LF characters for
424 * some of the commands (but not most).
425 */
426 if (msglen > 0 && *msg == '\r')
427 {
428 msg++;
429 msglen--;
430 }
431 if (msglen > 0 && msg[msglen - 1] == '\n')
432 msglen--;
433 if (msglen > 0 && msg[msglen - 1] == '\r')
434 msglen--;
435 /* Search for the subprocess in the linked list.
436 */
437 expr = Qnil;
438 for (ptr = process_list; ptr; ptr = ptr->next)
439 if (ptr->process_id == input_iosb.pid)
440 {
441 expr = Fcons (ptr->input_handler,
442 Fcons (make_number (ptr->name),
443 Fcons (make_string (msg, msglen),
444 Qnil)));
445 break;
446 }
447 have_process_input = 0;
448 start_mbx_input ();
449 clear_waiting_for_input (); /* Otherwise Ctl-g will cause crash. JCB */
450 if (! NULL (expr))
451 Feval (expr);
452}
453
454/* Searches process list for any processes which have exited. Calls their
455 * exit handlers and removes them from the process list.
456 */
457
458process_exit ()
459{
460 struct process_list * ptr, * prev, * next;
461
462 process_exited = 0;
463 prev = 0;
464 ptr = process_list;
465 while (ptr)
466 {
467 next = ptr->next;
468 if (! ptr->process_active)
469 {
470 if (prev)
471 prev->next = next;
472 else
473 process_list = next;
474 if (! NULL (ptr->exit_handler))
475 Feval (Fcons (ptr->exit_handler, Fcons (make_number (ptr->name),
476 Qnil)));
477 sys$dassgn (ptr->mbx_chan);
478 free (ptr);
479 }
480 else
481 prev = ptr;
482 ptr = next;
483 }
484}
485
486/* Called at emacs exit.
487 */
488
489kill_vms_processes ()
490{
491 struct process_list * ptr;
492
493 for (ptr = process_list; ptr; ptr = ptr->next)
494 if (ptr->process_active)
495 {
496 sys$dassgn (ptr->mbx_chan);
497 sys$delprc (&ptr->process_id, 0);
498 }
499 sys$dassgn (input_mbx_chan);
500 process_list = 0;
501 input_mbx_chan = 0;
502}
503
504/* Creates a temporary mailbox and retrieves its device name in 'buf'.
505 * Makes the descriptor pointed to by 'dsc' refer to this device.
506 * 'buffer_factor' is used to allow sending messages asynchronously
507 * till some point.
508 */
509
510static int
511create_mbx (dsc, buf, chan, buffer_factor)
512 struct dsc$descriptor_s *dsc;
513 char *buf;
514 int *chan;
515 int buffer_factor;
516{
517 int strval[2];
518 int status;
519
520 status = sys$crembx (0, chan, MSGSIZE, MSGSIZE * buffer_factor, 0, 0, 0);
521 if (! (status & 1))
522 {
523 message ("Unable to create mailbox. Need TMPMBX privilege.");
524 return 0;
525 }
526 strval[0] = 16;
527 strval[1] = buf;
528 status = lib$getdvi (&DVI$_DEVNAM, chan, 0, 0, strval,
529 &dsc->dsc$w_length);
530 if (! (status & 1))
531 return 0;
532 dsc->dsc$b_dtype = DSC$K_DTYPE_T;
533 dsc->dsc$b_class = DSC$K_CLASS_S;
534 dsc->dsc$a_pointer = buf;
535 return 1;
536} /* create_mbx */
537
538/* AST routine to be called upon receiving mailbox input.
539 * Sets flag telling keyboard routines that input is available.
540 */
541
542static int
543mbx_input_ast ()
544{
545 have_process_input = 1;
546}
547
548/* Issue a QIO request on the input mailbox.
549 */
550static void
551start_mbx_input ()
552{
553 sys$qio (process_ef, input_mbx_chan, IO$_READVBLK, &input_iosb,
554 mbx_input_ast, 0, mbx_buffer, sizeof (mbx_buffer),
555 0, 0, 0, 0);
556}
557
558/* Send a message to the subprocess input mailbox, without blocking if
559 * possible.
560 */
561static void
562write_to_mbx (ptr, buf, len)
563 struct process_list *ptr;
564 char *buf;
565 int len;
566{
567 sys$qiow (0, ptr->mbx_chan, IO$_WRITEVBLK | IO$M_NOW, &ptr->iosb,
568 0, 0, buf, len, 0, 0, 0, 0);
569}
570
571DEFUN ("setprv", Fsetprv, Ssetprv, 1, 3, 0,
572 "Set or reset a VMS privilege. First arg is privilege name.\n\
573Second arg is t or nil, indicating whether the privilege is to be\n\
574set or reset. Default is nil. Returns t if success, nil if not.\n\
575If third arg is non-nil, does not change privilege, but returns t\n\
576or nil depending upon whether the privilege is already enabled.")
577 (priv, value, getprv)
578 Lisp_Object priv, value, getprv;
579{
580 int prvmask[2], prvlen, newmask[2];
581 char * prvname;
582 int found, i;
583 struct privilege_list * ptr;
584
585 CHECK_STRING (priv, 0);
586 priv = Fupcase (priv);
587 prvname = XSTRING (priv)->data;
588 prvlen = XSTRING (priv)->size;
589 found = 0;
590 prvmask[0] = 0;
591 prvmask[1] = 0;
592 for (i = 0; i < sizeof (priv_list) / sizeof (priv_list[0]); i++)
593 {
594 ptr = &priv_list[i];
595 if (prvlen == strlen (ptr->name) &&
596 bcmp (prvname, ptr->name, prvlen) == 0)
597 {
598 if (ptr->mask >= 32)
599 prvmask[1] = 1 << (ptr->mask % 32);
600 else
601 prvmask[0] = 1 << ptr->mask;
602 found = 1;
603 break;
604 }
605 }
606 if (! found)
607 error ("Unknown privilege name %s", XSTRING (priv)->data);
608 if (NULL (getprv))
609 {
610 if (sys$setprv (NULL (value) ? 0 : 1, prvmask, 0, 0) == SS$_NORMAL)
611 return Qt;
612 return Qnil;
613 }
614 /* Get old priv value */
615 if (sys$setprv (0, 0, 0, newmask) != SS$_NORMAL)
616 return Qnil;
617 if ((newmask[0] & prvmask[0])
618 || (newmask[1] & prvmask[1]))
619 return Qt;
620 return Qnil;
621}
622
623/* Retrieves VMS system information. */
624
625#ifdef VMS4_4 /* I don't know whether these functions work in old versions */
626
627DEFUN ("vms-system-info", Fvms_system_info, Svms_system_info, 1, 3, 0,
628 "Retrieve VMS process and system information.\n\
629The first argument (a string) specifies the type of information desired.\n\
630The other arguments depend on the type you select.\n\
631For information about a process, the second argument is a process ID\n\
632or a process name, with the current process as a default.\n\
633These are the possibilities for the first arg (upper or lower case ok):\n\
634 account Returns account name\n\
635 cliname Returns CLI name\n\
636 owner Returns owner process's PID\n\
637 grp Returns group number\n\
638 parent Returns parent process's PID\n\
639 pid Returns process's PID\n\
640 prcnam Returns process's name\n\
641 terminal Returns terminal name\n\
642 uic Returns UIC number\n\
643 uicgrp Returns formatted [UIC,GRP]\n\
644 username Returns username\n\
645 version Returns VMS version\n\
646 logical Translates VMS logical name (second argument)\n\
647 dcl-symbol Translates DCL symbol (second argument)\n\
648 proclist Returns list of all PIDs on system (needs WORLD privilege)." )
649 (type, arg1, arg2)
650 Lisp_Object type, arg1, arg2;
651{
652 int i, typelen;
653 char * typename;
654 struct vms_objlist * ptr;
655
656 CHECK_STRING (type, 0);
657 type = Fupcase (type);
658 typename = XSTRING (type)->data;
659 typelen = XSTRING (type)->size;
660 for (i = 0; i < sizeof (vms_object) / sizeof (vms_object[0]); i++)
661 {
662 ptr = &vms_object[i];
663 if (typelen == strlen (ptr->name)
664 && bcmp (typename, ptr->name, typelen) == 0)
665 return (* ptr->objfn)(arg1, arg2);
666 }
667 error ("Unknown object type %s", typename);
668}
669
670/* Given a reference to a VMS process, returns its process id. */
671
672static int
673translate_id (pid, owner)
674 Lisp_Object pid;
675 int owner; /* if pid is null/0, return owner. If this
676 * flag is 0, return self. */
677{
678 int status, code, id, i, numeric, size;
679 char * p;
680 int prcnam[2];
681
682 if (NULL (pid)
683 || XTYPE (pid) == Lisp_String && XSTRING (pid)->size == 0
684 || XTYPE (pid) == Lisp_Int && XFASTINT (pid) == 0)
685 {
686 code = owner ? JPI$_OWNER : JPI$_PID;
687 status = lib$getjpi (&code, 0, 0, &id);
688 if (! (status & 1))
689 error ("Cannot find %s: %s",
690 owner ? "owner process" : "process id",
691 vmserrstr (status));
692 return (id);
693 }
694 if (XTYPE (pid) == Lisp_Int)
695 return (XFASTINT (pid));
696 CHECK_STRING (pid, 0);
697 pid = Fupcase (pid);
698 size = XSTRING (pid)->size;
699 p = XSTRING (pid)->data;
700 numeric = 1;
701 id = 0;
702 for (i = 0; i < size; i++, p++)
703 if (isxdigit (*p))
704 {
705 id *= 16;
706 if (*p >= '0' && *p <= '9')
707 id += *p - '0';
708 else
709 id += *p - 'A' + 10;
710 }
711 else
712 {
713 numeric = 0;
714 break;
715 }
716 if (numeric)
717 return (id);
718 prcnam[0] = XSTRING (pid)->size;
719 prcnam[1] = XSTRING (pid)->data;
720 status = lib$getjpi (&JPI$_PID, 0, prcnam, &id);
721 if (! (status & 1))
722 error ("Cannot find process id: %s",
723 vmserrstr (status));
724 return (id);
725} /* translate_id */
726
727/* VMS object retrieval functions. */
728
729static Lisp_Object
730getjpi (jpicode, arg, numeric)
731 int jpicode; /* Type of GETJPI information */
732 Lisp_Object arg;
733 int numeric; /* 1 if numeric value expected */
734{
735 int id, status, numval;
736 char str[128];
737 int strdsc[2] = { sizeof (str), str };
738 short strlen;
739
740 id = translate_id (arg, 0);
741 status = lib$getjpi (&jpicode, &id, 0, &numval, strdsc, &strlen);
742 if (! (status & 1))
743 error ("Unable to retrieve information: %s",
744 vmserrstr (status));
745 if (numeric)
746 return (make_number (numval));
747 return (make_string (str, strlen));
748}
749
750static Lisp_Object
751vms_account (arg1, arg2)
752 Lisp_Object arg1, arg2;
753{
754 return getjpi (JPI$_ACCOUNT, arg1, 0);
755}
756
757static Lisp_Object
758vms_cliname (arg1, arg2)
759 Lisp_Object arg1, arg2;
760{
761 return getjpi (JPI$_CLINAME, arg1, 0);
762}
763
764static Lisp_Object
765vms_grp (arg1, arg2)
766 Lisp_Object arg1, arg2;
767{
768 return getjpi (JPI$_GRP, arg1, 1);
769}
770
771static Lisp_Object
772vms_image (arg1, arg2)
773 Lisp_Object arg1, arg2;
774{
775 return getjpi (JPI$_IMAGNAME, arg1, 0);
776}
777
778static Lisp_Object
779vms_owner (arg1, arg2)
780 Lisp_Object arg1, arg2;
781{
782 return getjpi (JPI$_OWNER, arg1, 1);
783}
784
785static Lisp_Object
786vms_parent (arg1, arg2)
787 Lisp_Object arg1, arg2;
788{
789 return getjpi (JPI$_MASTER_PID, arg1, 1);
790}
791
792static Lisp_Object
793vms_pid (arg1, arg2)
794 Lisp_Object arg1, arg2;
795{
796 return getjpi (JPI$_PID, arg1, 1);
797}
798
799static Lisp_Object
800vms_prcnam (arg1, arg2)
801 Lisp_Object arg1, arg2;
802{
803 return getjpi (JPI$_PRCNAM, arg1, 0);
804}
805
806static Lisp_Object
807vms_terminal (arg1, arg2)
808 Lisp_Object arg1, arg2;
809{
810 return getjpi (JPI$_TERMINAL, arg1, 0);
811}
812
813static Lisp_Object
814vms_uic_int (arg1, arg2)
815 Lisp_Object arg1, arg2;
816{
817 return getjpi (JPI$_UIC, arg1, 1);
818}
819
820static Lisp_Object
821vms_uic_str (arg1, arg2)
822 Lisp_Object arg1, arg2;
823{
824 return getjpi (JPI$_UIC, arg1, 0);
825}
826
827static Lisp_Object
828vms_username (arg1, arg2)
829 Lisp_Object arg1, arg2;
830{
831 return getjpi (JPI$_USERNAME, arg1, 0);
832}
833
834static Lisp_Object
835vms_version_fn (arg1, arg2)
836 Lisp_Object arg1, arg2;
837{
838 char str[40];
839 int status;
840 int strdsc[2] = { sizeof (str), str };
841 short strlen;
842
843 status = lib$getsyi (&SYI$_VERSION, 0, strdsc, &strlen, 0, 0);
844 if (! (status & 1))
845 error ("Unable to obtain version: %s", vmserrstr (status));
846 return (make_string (str, strlen));
847}
848
849static Lisp_Object
850vms_trnlog (arg1, arg2)
851 Lisp_Object arg1, arg2;
852{
853 char str[100];
854 int status, symdsc[2];
855 int strdsc[2] = { sizeof (str), str };
856 short length, level;
857
858 CHECK_STRING (arg1, 0);
859 symdsc[0] = XSTRING (arg1)->size;
860 symdsc[1] = XSTRING (arg1)->data;
861 status = lib$sys_trnlog (symdsc, &length, strdsc);
862 if (! (status & 1))
863 error ("Unable to translate logical name: %s", vmserrstr (status));
864 if (status == SS$_NOTRAN)
865 return (Qnil);
866 return (make_string (str, length));
867}
868
869static Lisp_Object
870vms_symbol (arg1, arg2)
871 Lisp_Object arg1, arg2;
872{
873 char str[100];
874 int status, symdsc[2];
875 int strdsc[2] = { sizeof (str), str };
876 short length, level;
877
878 CHECK_STRING (arg1, 0);
879 symdsc[0] = XSTRING (arg1)->size;
880 symdsc[1] = XSTRING (arg1)->data;
881 status = lib$get_symbol (symdsc, strdsc, &length, &level);
882 if (! (status & 1)) {
883 if (status == LIB$_NOSUCHSYM)
884 return (Qnil);
885 else
886 error ("Unable to translate symbol: %s", vmserrstr (status));
887 }
888 return (make_string (str, length));
889}
890
891static Lisp_Object
892vms_proclist (arg1, arg2)
893 Lisp_Object arg1, arg2;
894{
895 Lisp_Object retval;
896 int id, status, pid;
897
898 retval = Qnil;
899 pid = -1;
900 for (;;)
901 {
902 status = lib$getjpi (&JPI$_PID, &pid, 0, &id);
903 if (status == SS$_NOMOREPROC)
904 break;
905 if (! (status & 1))
906 error ("Unable to get process ID: %s", vmserrstr (status));
907 retval = Fcons (make_number (id), retval);
908 }
909 return (Fsort (retval, intern ("<")));
910}
911
912DEFUN ("shrink-to-icon", Fshrink_to_icon, Sshrink_to_icon, 0, 0, 0,
913 "If emacs is running in a workstation window, shrink to an icon.")
914 ()
915{
916 static char result[128];
917 static $DESCRIPTOR (result_descriptor, result);
918 static $DESCRIPTOR (tt_name, "TT:");
919 static int chan = 0;
920 static int buf = 0x9d + ('2'<<8) + ('2'<<16) + (0x9c<<24);
921 int status;
922 static int temp = JPI$_TERMINAL;
923
924 status = lib$getjpi (&temp, 0, 0, 0, &result_descriptor, 0);
925 if (status != SS$_NORMAL)
926 error ("Unable to determine terminal type.");
927 if (result[0] != 'W' || result[1] != 'T') /* see if workstation */
928 error ("Can't shrink-to-icon on a non workstation terminal");
929 if (!chan) /* assign channel if not assigned */
930 if ((status = sys$assign (&tt_name, &chan, 0, 0)) != SS$_NORMAL)
931 error ("Can't assign terminal, %d", status);
932 status = sys$qiow (0, chan, IO$_WRITEVBLK+IO$M_BREAKTHRU, 0, 0, 0,
933 &buf, 4, 0, 0, 0, 0);
934 if (status != SS$_NORMAL)
935 error ("Can't shrink-to-icon, %d", status);
936}
937
938#endif /* VMS4_4 */
939
940init_vmsfns ()
941{
942 process_list = 0;
943 input_mbx_chan = 0;
944}
945
946syms_of_vmsfns ()
947{
948 defsubr (&Sdefault_subproc_input_handler);
949 defsubr (&Sspawn_subprocess);
950 defsubr (&Ssend_command_to_subprocess);
951 defsubr (&Sstop_subprocess);
952 defsubr (&Ssetprv);
953#ifdef VMS4_4
954 defsubr (&Svms_system_info);
955 defsubr (&Sshrink_to_icon);
956#endif /* VMS4_4 */
957 Qdefault_subproc_input_handler = intern ("default-subprocess-input-handler");
958 staticpro (&Qdefault_subproc_input_handler);
959}
960#endif /* VMS */
961