2 * Copyright (c) 1985 Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static char sccsid
[] = "@(#)domacro.c 1.6 (Berkeley) 2/28/89";
26 void domacro(int argc
, const char *argv
[])
31 int count
= 2, loopflg
= 0;
33 struct cmd
*getcmd(), *c
;
36 (void) strcat(line
, " ");
37 printf("(macro name) ");
38 (void) fflush(stdout
);
39 (void) gets(&line
[strlen(line
)]);
45 printf("Usage: %s macro_name.\n", argv
[0]);
46 (void) fflush(stdout
);
50 for (i
= 0; i
< macnum
; ++i
) {
51 if (!strncmp(argv
[1], macros
[i
].mac_name
, 9)) {
56 printf("'%s' macro not found.\n", argv
[1]);
57 (void) fflush(stdout
);
61 (void) strcpy(line2
, line
);
63 cp1
= macros
[i
].mac_start
;
64 while (cp1
!= macros
[i
].mac_end
) {
65 while (isspace(*cp1
)) {
69 while (*cp1
!= '\0') {
75 if (isdigit(*(cp1
+1))) {
77 while (isdigit(*++cp1
)) {
78 j
= 10*j
+ *cp1
- '0';
82 (void) strcpy(cp2
, argv
[j
+1]);
83 cp2
+= strlen(argv
[j
+1]);
87 if (*(cp1
+1) == 'i') {
91 (void) strcpy(cp2
, argv
[count
]);
92 cp2
+= strlen(argv
[count
]);
96 /* intentional drop through */
107 c
= getcmd(margv
[0]);
108 if (c
== (struct cmd
*)-1) {
109 printf("?Ambiguous command\n");
113 printf("?Invalid command\n");
116 else if (c
->c_conn
&& !connected
) {
117 printf("Not connected.\n");
124 (*c
->c_handler
)(margc
, margv
);
125 if (bell
&& c
->c_bell
) {
126 (void) putchar('\007');
128 (void) strcpy(line
, line2
);
133 if (cp1
!= macros
[i
].mac_end
) {
136 (void) fflush(stdout
);
138 if (loopflg
&& ++count
< argc
) {