4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
51 domacro(int argc
, char *argv
[])
54 register char *cp1
, *cp2
;
55 int count
= 2, loopflg
= 0;
62 (void) strcat(line
, " ");
63 printf("(macro name) ");
64 (void) gets(&line
[strlen(line
)]);
71 printf("Usage: %s macro_name.\n", argv
[0]);
75 for (i
= 0; i
< macnum
; ++i
) {
76 if (strncmp(argv
[1], macros
[i
].mac_name
, 9) == 0) {
81 printf("'%s' macro not found.\n", argv
[1]);
85 (void) strcpy(line2
, line
);
87 cp1
= macros
[i
].mac_start
;
88 while (cp1
!= macros
[i
].mac_end
) {
89 while (isspace(*cp1
)) {
93 while (*cp1
!= '\0') {
97 if ((len
= mblen(cp1
, MB_CUR_MAX
)) <= 0)
99 memcpy(cp2
, cp1
, len
);
105 if (isdigit(*(cp1
+1))) {
107 while (isdigit(*++cp1
))
108 j
= 10 * j
+ *cp1
- '0';
110 (void) strcpy(cp2
, argv
[j
+1]);
111 cp2
+= strlen(argv
[j
+1]);
115 if (*(cp1
+1) == 'i') {
119 (void) strcpy(cp2
, argv
[count
]);
120 cp2
+= strlen(argv
[count
]);
126 if ((len
= mblen(cp1
, MB_CUR_MAX
)) <= 0)
128 memcpy(cp2
, cp1
, len
);
136 if (margv
[0] == NULL
) {
140 c
= getcmd(margv
[0]);
142 if (c
== (struct cmd
*)-1) {
143 printf("?Ambiguous command\n");
146 printf("?Invalid command\n");
148 } else if (c
->c_conn
&& !connected
) {
149 printf("Not connected.\n");
153 printf("%s\n", line
);
155 (*c
->c_handler
)(margc
, margv
);
156 #define CTRL(c) ((c)&037)
157 if (bell
&& c
->c_bell
) {
158 (void) putchar(CTRL('g'));
160 (void) strcpy(line
, line2
);
165 if (cp1
!= macros
[i
].mac_end
) {
169 if (loopflg
&& ++count
< argc
) {