1 /*
2  * Copyright 1987, 1988 by MIT Student Information Processing Board
3  *
4  * Permission to use, copy, modify, and distribute this software and
5  * its documentation for any purpose is hereby granted, provided that
6  * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
7  * advertising or publicity pertaining to distribution of the software
8  * without specific, written prior permission.  M.I.T. and the
9  * M.I.T. S.I.P.B. make no representations about the suitability of
10  * this software for any purpose.  It is provided "as is" without
11  * express or implied warranty.
12  */
13 
14 #ifndef _ss_ss_internal_h
15 #define _ss_ss_internal_h __FILE__
16 #include <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
19 
20 #define PROTOTYPE(p) p
21 typedef void * pointer;
22 
23 #include "ss.h"
24 
25 typedef char BOOL;
26 
27 typedef struct _ss_abbrev_entry {
28     char *name;			/* abbrev name */
29     char **abbrev;		/* new tokens to insert */
30     unsigned int beginning_of_line : 1;
31 } ss_abbrev_entry;
32 
33 typedef struct _ss_abbrev_list {
34     int n_abbrevs;
35     ss_abbrev_entry *first_abbrev;
36 } ss_abbrev_list;
37 
38 typedef struct {
39 /*    char *path; */
40     ss_abbrev_list abbrevs[127];
41 } ss_abbrev_info;
42 
43 typedef struct _ss_data {	/* init values */
44     /* this subsystem */
45     const char *subsystem_name;
46     const char *subsystem_version;
47     /* current request info */
48     int argc;
49     char **argv;		/* arg list */
50     char const *current_request; /* primary name */
51     /* info directory for 'help' */
52     char **info_dirs;
53     /* to be extracted by subroutines */
54     pointer info_ptr;		/* (void *) NULL */
55     /* for ss_listen processing */
56     char *prompt;
57     ss_request_table **rqt_tables;
58     ss_abbrev_info *abbrev_info;
59     struct {
60 	unsigned int  escape_disabled : 1,
61 		      abbrevs_disabled : 1;
62     } flags;
63     /*
64      * Dynamic usage of readline library if present
65      */
66     void *readline_handle;
67     void (*readline_shutdown)(struct _ss_data *info);
68     char *(*readline)(const char *);
69     void (*add_history)(const char *);
70     void (*redisplay)(void);
71     char **(*rl_completion_matches)(const char *,
72 				    char *(*completer)(const char *, int));
73     /* to get out */
74     int abort;			/* exit subsystem */
75     int exit_status;
76 } ss_data;
77 
78 #define CURRENT_SS_VERSION 1
79 
80 #define	ss_info(sci_idx)	(_ss_table[sci_idx])
81 #define	ss_current_request(sci_idx,code_ptr)	\
82      (*code_ptr=0,ss_info(sci_idx)->current_request)
83 void ss_add_info_dir (int sci_idx, char *info_dir, int *code_ptr);
84 void ss_delete_info_dir (int sci_idx, char *info_dir, int *code_ptr);
85 int ss_execute_line(int sci_idx, char *line_ptr);
86 char **ss_parse(int sci_idx, char *line_ptr, int *argc_ptr);
87 ss_abbrev_info *ss_abbrev_initialize(char *, int *);
88 void ss_page_stdin(void);
89 void ss_list_requests(int, char const * const *, int, pointer);
90 int ss_execute_command(int sci_idx, char *argv[]);
91 int ss_pager_create(void);
92 char *ss_safe_getenv(const char *arg);
93 char **ss_rl_completion(const char *text, int start, int end);
94 
95 extern ss_data **_ss_table;
96 extern char *ss_et_msgs[];
97 extern char *_ss_pager_name;
98 
99 #ifdef USE_SIGPROCMASK
100 /* fake sigmask, sigblock, sigsetmask */
101 #include <signal.h>
102 #define sigmask(x) (1L<<(x)-1)
103 #define sigsetmask(x) sigprocmask(SIG_SETMASK,&x,NULL)
104 static int _fake_sigstore;
105 #define sigblock(x) (_fake_sigstore=x,sigprocmask(SIG_BLOCK,&_fake_sigstore,0))
106 #endif
107 #endif /* _ss_internal_h */
108