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.10 1997/08/02 16:48:59 bostic Exp $ (Berkeley) $Date: 1997/08/02 16:48:59 $";
14 #include <sys/types.h>
15 #include <sys/queue.h>
17 #include <bitstring.h>
25 #include "../common/common.h"
26 #include "../ipc/ip.h"
29 int vi_ofd
; /* GLOBAL: known to vi_send(). */
31 static void ip_func_std
__P((GS
*));
32 static IP_PRIVATE
*ip_init
__P((GS
*, char *));
33 static void perr
__P((char *, char *));
37 * This is the main loop for the vi-as-library editor.
39 * PUBLIC: int ip_main __P((int, char *[], GS *, char *));
42 ip_main(argc
, argv
, gp
, ip_arg
)
44 char *argv
[], *ip_arg
;
52 /* Create and partially initialize the IP structure. */
53 if ((ipp
= ip_init(gp
, ip_arg
)) == NULL
)
56 /* Add the terminal type to the global structure. */
57 if ((OG_D_STR(gp
, GO_TERM
) =
58 OG_STR(gp
, GO_TERM
) = strdup("ip_curses")) == NULL
)
59 perr(gp
->progname
, NULL
);
62 * Figure out how big the screen is -- read events until we get
63 * the rows and columns.
66 if (ip_event(NULL
, &ev
, 0, 0))
68 if (ev
.e_event
== E_WRESIZE
)
70 if (ev
.e_event
== E_EOF
|| ev
.e_event
== E_ERR
||
71 ev
.e_event
== E_SIGHUP
|| ev
.e_event
== E_SIGTERM
)
73 if (ev
.e_event
== E_IPCOMMAND
&& ev
.e_ipcom
== VI_QUIT
)
78 rval
= editor(gp
, argc
, argv
);
80 /* Clean up the screen. */
83 /* Send the quit message. */
85 (void)vi_send(NULL
, &ipb
);
87 /* Give the screen a couple of seconds to deal with it. */
90 /* Free the global and IP private areas. */
91 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
100 * Create and partially initialize the GS structure.
110 /* Allocate the IP private structure. */
111 CALLOC_NOMSG(NULL
, ipp
, IP_PRIVATE
*, 1, sizeof(IP_PRIVATE
));
113 perr(gp
->progname
, NULL
);
114 gp
->ip_private
= ipp
;
117 * Crack ip_arg -- it's of the form #.#, where the first number is the
118 * file descriptor from the screen, the second is the file descriptor
121 if (!isdigit(ip_arg
[0]))
123 ipp
->i_fd
= strtol(ip_arg
, &ep
, 10);
124 if (ep
[0] != '.' || !isdigit(ep
[1]))
126 vi_ofd
= strtol(++ep
, &ep
, 10);
132 /* Initialize the list of ip functions. */
140 * Initialize the standard ip functions.
146 gp
->scr_addstr
= ip_addstr
;
147 gp
->scr_attr
= ip_attr
;
148 gp
->scr_baud
= ip_baud
;
149 gp
->scr_bell
= ip_bell
;
150 gp
->scr_busy
= ip_busy
;
151 gp
->scr_clrtoeol
= ip_clrtoeol
;
152 gp
->scr_cursor
= ip_cursor
;
153 gp
->scr_deleteln
= ip_deleteln
;
154 gp
->scr_discard
= ip_discard
;
155 gp
->scr_event
= ip_event
;
156 gp
->scr_ex_adjust
= ip_ex_adjust
;
157 gp
->scr_fmap
= ip_fmap
;
158 gp
->scr_insertln
= ip_insertln
;
159 gp
->scr_keyval
= ip_keyval
;
160 gp
->scr_move
= ip_move
;
162 gp
->scr_optchange
= ip_optchange
;
163 gp
->scr_refresh
= ip_refresh
;
164 gp
->scr_rename
= ip_rename
;
165 gp
->scr_reply
= ip_reply
;
166 gp
->scr_screen
= ip_screen
;
167 gp
->scr_split
= ip_split
;
168 gp
->scr_suspend
= ip_suspend
;
169 gp
->scr_usage
= ip_usage
;
174 * Print system error.
180 (void)fprintf(stderr
, "%s:", name
);
182 (void)fprintf(stderr
, "%s:", msg
);
183 (void)fprintf(stderr
, "%s\n", strerror(errno
));