3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
11 static const char sccsid
[] = "@(#)ip_main.c 8.3 (Berkeley) 10/13/96";
14 #include <sys/types.h>
15 #include <sys/queue.h>
17 #include <bitstring.h>
22 #include "../common/common.h"
25 static void ip_func_std
__P((GS
*));
26 static IP_PRIVATE
*ip_init
__P((GS
*, char *));
27 static void perr
__P((char *, char *));
31 * This is the main loop for the vi-as-library editor.
34 ip_main(argc
, argv
, gp
, ip_arg
)
36 char *argv
[], *ip_arg
;
44 /* Create and partially initialize the IP structure. */
45 if ((ipp
= ip_init(gp
, ip_arg
)) == NULL
)
48 /* Add the terminal type to the global structure. */
49 if ((OG_D_STR(gp
, GO_TERM
) =
50 OG_STR(gp
, GO_TERM
) = strdup("ip_curses")) == NULL
)
51 perr(gp
->progname
, NULL
);
54 * Figure out how big the screen is -- read events until we get
55 * the rows and columns.
58 if (ip_event(NULL
, &ev
, 0, 0))
60 } while (ev
.e_event
!= E_EOF
&& ev
.e_event
!= E_ERR
&&
61 ev
.e_event
!= E_QUIT
&& ev
.e_event
!= E_WRESIZE
&&
62 ev
.e_event
!= E_SIGHUP
&& ev
.e_event
!= E_SIGTERM
);
63 if (ev
.e_event
!= E_WRESIZE
)
67 rval
= editor(gp
, argc
, argv
);
69 /* Clean up the screen. */
72 /* Free the global and IP private areas. */
73 #if defined(DEBUG) || defined(PURIFY) || defined(LIBRARY)
83 * Create and partially initialize the GS structure.
93 /* Allocate the IP private structure. */
94 CALLOC_NOMSG(NULL
, ipp
, IP_PRIVATE
*, 1, sizeof(IP_PRIVATE
));
96 perr(gp
->progname
, NULL
);
100 * Crack ip_arg -- it's of the form #.#, where the first number is the
101 * file descriptor from the screen, the second is the file descriptor
104 if (!isdigit(ip_arg
[0]))
106 ipp
->i_fd
= strtol(ip_arg
, &ep
, 10);
107 if (ep
[0] != '.' || !isdigit(ep
[1]))
109 ipp
->o_fd
= strtol(++ep
, &ep
, 10);
115 /* Initialize the list of ip functions. */
123 * Initialize the standard ip functions.
129 gp
->scr_addstr
= ip_addstr
;
130 gp
->scr_attr
= ip_attr
;
131 gp
->scr_baud
= ip_baud
;
132 gp
->scr_bell
= ip_bell
;
133 gp
->scr_busy
= ip_busy
;
134 gp
->scr_clrtoeol
= ip_clrtoeol
;
135 gp
->scr_cursor
= ip_cursor
;
136 gp
->scr_deleteln
= ip_deleteln
;
137 gp
->scr_event
= ip_event
;
138 gp
->scr_ex_adjust
= ip_ex_adjust
;
139 gp
->scr_fmap
= ip_fmap
;
140 gp
->scr_insertln
= ip_insertln
;
141 gp
->scr_keyval
= ip_keyval
;
142 gp
->scr_move
= ip_move
;
144 gp
->scr_optchange
= ip_optchange
;
145 gp
->scr_refresh
= ip_refresh
;
146 gp
->scr_rename
= ip_rename
;
147 gp
->scr_screen
= ip_screen
;
148 gp
->scr_suspend
= ip_suspend
;
149 gp
->scr_usage
= ip_usage
;
154 * Print system error.
160 (void)fprintf(stderr
, "%s:", name
);
162 (void)fprintf(stderr
, "%s:", msg
);
163 (void)fprintf(stderr
, "%s\n", strerror(errno
));