|
|
1.1 root 1: /*
2: * Copyright (c) 1985 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)domacro.c 1.7 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: #include "ftp_var.h"
25:
26: #include <signal.h>
27: #include <stdio.h>
28: #include <errno.h>
29: #include <ctype.h>
30: #include <sys/ttychars.h>
31:
32: domacro(argc, argv)
33: int argc;
34: char *argv[];
35: {
36: register int i, j;
37: register char *cp1, *cp2;
38: int count = 2, loopflg = 0;
39: char line2[200];
40: extern char **glob(), *globerr;
41: struct cmd *getcmd(), *c;
42: extern struct cmd cmdtab[];
43:
44: if (argc < 2) {
45: (void) strcat(line, " ");
46: printf("(macro name) ");
47: (void) gets(&line[strlen(line)]);
48: makeargv();
49: argc = margc;
50: argv = margv;
51: }
52: if (argc < 2) {
53: printf("Usage: %s macro_name.\n", argv[0]);
54: code = -1;
55: return;
56: }
57: for (i = 0; i < macnum; ++i) {
58: if (!strncmp(argv[1], macros[i].mac_name, 9)) {
59: break;
60: }
61: }
62: if (i == macnum) {
63: printf("'%s' macro not found.\n", argv[1]);
64: code = -1;
65: return;
66: }
67: (void) strcpy(line2, line);
68: TOP:
69: cp1 = macros[i].mac_start;
70: while (cp1 != macros[i].mac_end) {
71: while (isspace(*cp1)) {
72: cp1++;
73: }
74: cp2 = line;
75: while (*cp1 != '\0') {
76: switch(*cp1) {
77: case '\\':
78: *cp2++ = *++cp1;
79: break;
80: case '$':
81: if (isdigit(*(cp1+1))) {
82: j = 0;
83: while (isdigit(*++cp1)) {
84: j = 10*j + *cp1 - '0';
85: }
86: cp1--;
87: if (argc - 2 >= j) {
88: (void) strcpy(cp2, argv[j+1]);
89: cp2 += strlen(argv[j+1]);
90: }
91: break;
92: }
93: if (*(cp1+1) == 'i') {
94: loopflg = 1;
95: cp1++;
96: if (count < argc) {
97: (void) strcpy(cp2, argv[count]);
98: cp2 += strlen(argv[count]);
99: }
100: break;
101: }
102: /* intentional drop through */
103: default:
104: *cp2++ = *cp1;
105: break;
106: }
107: if (*cp1 != '\0') {
108: cp1++;
109: }
110: }
111: *cp2 = '\0';
112: makeargv();
113: c = getcmd(margv[0]);
114: if (c == (struct cmd *)-1) {
115: printf("?Ambiguous command\n");
116: code = -1;
117: }
118: else if (c == 0) {
119: printf("?Invalid command\n");
120: code = -1;
121: }
122: else if (c->c_conn && !connected) {
123: printf("Not connected.\n");
124: code = -1;
125: }
126: else {
127: if (verbose) {
128: printf("%s\n",line);
129: }
130: (*c->c_handler)(margc, margv);
131: if (bell && c->c_bell) {
132: (void) putchar('\007');
133: }
134: (void) strcpy(line, line2);
135: makeargv();
136: argc = margc;
137: argv = margv;
138: }
139: if (cp1 != macros[i].mac_end) {
140: cp1++;
141: }
142: }
143: if (loopflg && ++count < argc) {
144: goto TOP;
145: }
146: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.