3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
11 static const char sccsid
[] = "$Id: ip_main.c,v 8.7 1996/12/11 13:34:22 bostic Exp $ (Berkeley) $Date: 1996/12/11 13:34:22 $";
14 #include <sys/types.h>
15 #include <sys/queue.h>
17 #include <bitstring.h>
24 #include "../common/common.h"
26 #include "../include/ipc_extern.h"
28 int vi_ofd
; /* GLOBAL: known to __vi_send(). */
30 static void ip_func_std
__P((GS
*));
31 static IP_PRIVATE
*ip_init
__P((GS
*, char *));
32 static void perr
__P((char *, char *));
36 * This is the main loop for the vi-as-library editor.
38 * PUBLIC: int ip_main __P((int, char *[], GS *, char *));
41 ip_main(argc
, argv
, gp
, ip_arg
)
43 char *argv
[], *ip_arg
;
51 /* Create and partially initialize the IP structure. */
52 if ((ipp
= ip_init(gp
, ip_arg
)) == NULL
)
55 /* Add the terminal type to the global structure. */
56 if ((OG_D_STR(gp
, GO_TERM
) =
57 OG_STR(gp
, GO_TERM
) = strdup("ip_curses")) == NULL
)
58 perr(gp
->progname
, NULL
);
61 * Figure out how big the screen is -- read events until we get
62 * the rows and columns.
65 if (ip_event(NULL
, &ev
, 0, 0))
67 if (ev
.e_event
== E_WRESIZE
)
69 if (ev
.e_event
== E_EOF
|| ev
.e_event
== E_ERR
||
70 ev
.e_event
== E_SIGHUP
|| ev
.e_event
== E_SIGTERM
)
72 if (ev
.e_event
== E_IPCOMMAND
&& ev
.e_ipcom
== VI_QUIT
)
77 rval
= editor(gp
, argc
, argv
);
79 /* Clean up the screen. */
82 /* Send the quit message. */
84 (void)__vi_send(NULL
, &ipb
);
86 /* Give the screen a couple of seconds to deal with it. */
89 /* Free the global and IP private areas. */
90 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
99 * Create and partially initialize the GS structure.
109 /* Allocate the IP private structure. */
110 CALLOC_NOMSG(NULL
, ipp
, IP_PRIVATE
*, 1, sizeof(IP_PRIVATE
));
112 perr(gp
->progname
, NULL
);
113 gp
->ip_private
= ipp
;
116 * Crack ip_arg -- it's of the form #.#, where the first number is the
117 * file descriptor from the screen, the second is the file descriptor
120 if (!isdigit(ip_arg
[0]))
122 ipp
->i_fd
= strtol(ip_arg
, &ep
, 10);
123 if (ep
[0] != '.' || !isdigit(ep
[1]))
125 vi_ofd
= strtol(++ep
, &ep
, 10);
131 /* Initialize the list of ip functions. */
139 * Initialize the standard ip functions.
145 gp
->scr_addstr
= ip_addstr
;
146 gp
->scr_attr
= ip_attr
;
147 gp
->scr_baud
= ip_baud
;
148 gp
->scr_bell
= ip_bell
;
149 gp
->scr_busy
= ip_busy
;
150 gp
->scr_clrtoeol
= ip_clrtoeol
;
151 gp
->scr_cursor
= ip_cursor
;
152 gp
->scr_deleteln
= ip_deleteln
;
153 gp
->scr_discard
= ip_discard
;
154 gp
->scr_event
= ip_event
;
155 gp
->scr_ex_adjust
= ip_ex_adjust
;
156 gp
->scr_fmap
= ip_fmap
;
157 gp
->scr_insertln
= ip_insertln
;
158 gp
->scr_keyval
= ip_keyval
;
159 gp
->scr_move
= ip_move
;
161 gp
->scr_optchange
= ip_optchange
;
162 gp
->scr_refresh
= ip_refresh
;
163 gp
->scr_rename
= ip_rename
;
164 gp
->scr_screen
= ip_screen
;
165 gp
->scr_split
= ip_split
;
166 gp
->scr_suspend
= ip_suspend
;
167 gp
->scr_usage
= ip_usage
;
172 * Print system error.
178 (void)fprintf(stderr
, "%s:", name
);
180 (void)fprintf(stderr
, "%s:", msg
);
181 (void)fprintf(stderr
, "%s\n", strerror(errno
));