1 /* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
2 * This software is quasi-public; it may be used freely with
3 * like software, but may NOT be sold or made part of licensed
4 * products without permission of the author.
7 /* EECMDS Command table lookup and profile code
12 /* Function table, see the included file for explanation. */
14 /* First must pre-declare function addrs */
15 #define EFUN(rtn,rtnstr,name) int rtn();
19 /* Now re-insert to define function table */
22 #undef EFUN /* Avoid redefinition error message */
24 #define EFUN(rtn,rtnstr,name) rtn,
28 int funmax
= sizeof(funtab
)/sizeof(funtab
[0]); /* 1st illegal function # */
30 /* Insert default command char map tables and profile structure */
34 /* EFUN: "Prefix Meta" */
35 /* Meta-prefix command.
36 * For now, very simple. Perhaps later try to hair up with
37 * time-out "M-" prompt?
40 { return(cmd_xct(cmd_read()|CB_META
));
43 /* EFUN: "Prefix Extend" */
44 /* Extended-prefix command.
45 * Likewise trivial; perhaps later hair up with timeout "^X-" prompt?
48 { return(cmd_xct(cmd_read()|CB_EXT
));
51 /* EFUN: "Universal Arg" */
52 /* This routine is also called by "Argument Digit" with a special arg
53 * of -1 in order to share code. Since that invocation always sets unrchf,
54 * it should always complete at least one digit read loop.
55 * Note that exp and exp_p are set to 1 and 0 at the top-level command
60 { register int c
, oc
, i
;
62 /* Set distinguishing exp_p value depending on whether invoked
63 * by CTRL-U or another function (Argument Digit, Negative Argument)
65 exp_p
= (ch
< 0) ? 1 : 4;
66 i
= 0; /* Read numerical arg if any follows */
68 { oc
= cmd_read(); /* Get next input char */
72 exp
= 1; /* Set in case no digits follow */
74 else if('0' <= c
&& c
<= '9') /* If it's a digit too, */
75 { i
= (i
* 10) + c
- '0'; /* add digit in. */
76 if(exp_p
>= 0) exp_p
= 1;
81 exp
*= exp_p
; /* Multiply arg appropriately */
82 unrchf
= oc
; /* Not a digit, re-read it next. */
87 /* EFUN: "Negative Argument" */
90 { f_uarg(-1); /* Invoke code from Universal Arg */
94 /* EFUN: "Argument Digit" */
97 { unrchf
= ch
; /* Re-read the digit */
98 f_uarg(-1); /* Invoke code from Universal Arg */
101 /* EFUN: "Set Profile" */
102 /* Asks for a profile file and sets profile from it.
106 hack_file("Set Profile: ", set_profile
);
110 /* EFUN: "VT100 Button Hack" */
111 /* This must be bound to Meta-O if anything, because the VT100 sends
112 * an ESC O prefix when the function buttons are used.
114 f_vtbuttons () /* vt100 function buttons */
118 return (f_uprline ());
120 return (f_dnrline ());
125 case ('Q'): /* PF1 */
126 return (f_kregion());
132 #endif /*FX_VTBUTTONS*/
134 /* CMD_WAIT() - Return TRUE if any command input waiting.
139 || km_inwait() /* Check for kbdmac input waiting */
144 /* CMD_READ() - Read a command (single char) from user, and return it.
149 if((c
= unrchf
) >= 0) /* Re-reading last char? */
153 #if FX_SKMAC /* Hacking keyboard macros? */
154 return(km_getc()); /* Yes. This calls tgetc if no kbd macro */
160 /* CMD_XCT(ch) - Command Execution dispatch routine.
161 ** Takes char and executes the function (efun) bound to that command key.
165 { register int (*funct
) ();
167 int (*(cmd_fun())) ();
169 if(funct
= cmd_fun(c
= ch
)) /* Get function to run */
170 return((*funct
) (c
&0177)); /* Invoke with char arg */
171 ring_bell(); /* Undefined command char, error. */
174 /* CMD_FUN(ch) - Return function for char, 0 if none
179 return(funtab
[cmd_idx(c
)]);
182 /* CMD_IDX(ch) - Given command char, return function index for it
190 { cp
= def_prof
.extvec
;
191 i
= def_prof
.extvcnt
;
195 { cp
= def_prof
.metavec
;
196 i
= def_prof
.metavcnt
;
197 inlup
: c
= upcase(c
);
198 do { if(*cp
++ != c
) cp
++;
203 } while(--i
); /* If counts out, will return 0! */
205 else i
= def_prof
.chrvec
[c
&0177]&0377;
211 /* Profile hacking */
214 #include <sys/file.h> /* for O_BINARY */
217 set_profile(filename
)
221 register int pfd
, len
;
223 register char *profptr
;
224 struct stored_profile st_prof
;
226 if(filename
) strcpy(pfile
,filename
);
227 else /* Check for user's profile */
229 strcat(strcat(strcpy(pfile
,homedir
),"/"),ev_profile
);
231 if((pfd
= open(pfile
,
239 { ding("Cannot open file");
243 if((len
= (int)sbx_fdlen(pfd
)) < sizeof(struct stored_profile
))
245 profptr
= memalloc((SBMO
)len
);
246 if(read(pfd
,profptr
,len
) != len
)
249 /* Have read profile into memory, now set up ptrs etc */
250 bcopy((SBMA
)profptr
,(SBMA
)&st_prof
,sizeof(struct stored_profile
));
251 def_prof
.version
= prof_upack(st_prof
.version
);
252 if(def_prof
.version
!= 1)
254 def_prof
.chrvcnt
= prof_upack(st_prof
.chrvcnt
);
255 def_prof
.chrvec
= profptr
+ prof_upack(st_prof
.chrvec
);
256 def_prof
.metavcnt
= prof_upack(st_prof
.metavcnt
);
257 def_prof
.metavec
= profptr
+ prof_upack(st_prof
.metavec
);
258 def_prof
.extvcnt
= prof_upack(st_prof
.extvcnt
);
259 def_prof
.extvec
= profptr
+ prof_upack(st_prof
.extvec
);
261 def_prof
.menuvcnt
= prof_upack(st_prof
.menuvcnt
);
262 def_prof
.menuvec
= profptr
+ prof_upack(st_prof
.menuvec
);
266 badfmt
: chkfree(profptr
);
267 badfil
: ding("Bad profile format");
272 /* SUN Menu profile hacking.
273 * This is here, instead of e_sun.c, because
274 * the profile format is still evolving and for the time being I want to
275 * keep all profile-hacking code in one place. --KLH
277 #include "suntool/tool_hs.h"
278 #include "suntool/menu.h"
282 /* Defined in eesun.c */
283 extern struct menu
*menuptr
;
284 extern struct menu menu
;
289 #define EFUN(rtn,rtnstr,name) name,
294 init_menu() /* initialize the menu for elle from user profile */
296 register struct menuitem
*mi
;
297 register int n
, i
, fni
;
299 if((n
= def_prof
.menuvcnt
) <= 0)
301 if(n
> MENUMAX
) n
= MENUMAX
;
302 mi
= menu
.m_items
= (struct menuitem
*) calloc(n
, sizeof *mi
);
304 menu
.m_itemcount
= 0;
305 for(i
= 0; i
< n
; i
++)
306 { fni
= def_prof
.menuvec
[i
]&0377;
307 if(fni
>= funmax
) continue;
308 if(funtab
[fni
] && funamtab
[fni
])
309 { mi
->mi_data
= (caddr_t
) funtab
[fni
];
310 mi
->mi_imagedata
= (caddr_t
) strdup(funamtab
[fni
]);
311 mi
->mi_imagetype
= MENU_IMAGESTRING
;