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
40 #pragma ident "%Z%%M% %I% %E% SMI"
53 domacro(int argc
, char *argv
[])
56 register char *cp1
, *cp2
;
57 int count
= 2, loopflg
= 0;
64 (void) strcat(line
, " ");
65 printf("(macro name) ");
66 (void) gets(&line
[strlen(line
)]);
73 printf("Usage: %s macro_name.\n", argv
[0]);
77 for (i
= 0; i
< macnum
; ++i
) {
78 if (strncmp(argv
[1], macros
[i
].mac_name
, 9) == 0) {
83 printf("'%s' macro not found.\n", argv
[1]);
87 (void) strcpy(line2
, line
);
89 cp1
= macros
[i
].mac_start
;
90 while (cp1
!= macros
[i
].mac_end
) {
91 while (isspace(*cp1
)) {
95 while (*cp1
!= '\0') {
99 if ((len
= mblen(cp1
, MB_CUR_MAX
)) <= 0)
101 memcpy(cp2
, cp1
, len
);
107 if (isdigit(*(cp1
+1))) {
109 while (isdigit(*++cp1
))
110 j
= 10 * j
+ *cp1
- '0';
112 (void) strcpy(cp2
, argv
[j
+1]);
113 cp2
+= strlen(argv
[j
+1]);
117 if (*(cp1
+1) == 'i') {
121 (void) strcpy(cp2
, argv
[count
]);
122 cp2
+= strlen(argv
[count
]);
126 /* intentional drop through */
128 if ((len
= mblen(cp1
, MB_CUR_MAX
)) <= 0)
130 memcpy(cp2
, cp1
, len
);
138 if (margv
[0] == NULL
) {
142 c
= getcmd(margv
[0]);
144 if (c
== (struct cmd
*)-1) {
145 printf("?Ambiguous command\n");
148 printf("?Invalid command\n");
150 } else if (c
->c_conn
&& !connected
) {
151 printf("Not connected.\n");
155 printf("%s\n", line
);
157 (*c
->c_handler
)(margc
, margv
);
158 #define CTRL(c) ((c)&037)
159 if (bell
&& c
->c_bell
) {
160 (void) putchar(CTRL('g'));
162 (void) strcpy(line
, line2
);
167 if (cp1
!= macros
[i
].mac_end
) {
171 if (loopflg
&& ++count
< argc
) {