fixed warnings when compiled with -Wmissing-declarations
[reactos.git] / reactos / apps / utils / net / ftp / domacro.c
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 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.
16 */
17
18 #ifndef lint
19 static char sccsid[] = "@(#)domacro.c 1.6 (Berkeley) 2/28/89";
20 #endif /* not lint */
21
22 #include "ftp_var.h"
23 #include "prototypes.h"
24
25 #include <signal.h>
26 #include <stdio.h>
27 //#include <errno.h>
28 #include <ctype.h>
29 //#include <sys/ttychars.h>
30
31 void domacro(argc, argv)
32 int argc;
33 char *argv[];
34 {
35 register int i, j;
36 register char *cp1, *cp2;
37 int count = 2, loopflg = 0;
38 char line2[200];
39 struct cmd *getcmd(), *c;
40
41 if (argc < 2) {
42 (void) strcat(line, " ");
43 printf("(macro name) ");
44 (void) fflush(stdout);
45 (void) gets(&line[strlen(line)]);
46 makeargv();
47 argc = margc;
48 argv = margv;
49 }
50 if (argc < 2) {
51 printf("Usage: %s macro_name.\n", argv[0]);
52 (void) fflush(stdout);
53 code = -1;
54 return;
55 }
56 for (i = 0; i < macnum; ++i) {
57 if (!strncmp(argv[1], macros[i].mac_name, 9)) {
58 break;
59 }
60 }
61 if (i == macnum) {
62 printf("'%s' macro not found.\n", argv[1]);
63 (void) fflush(stdout);
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 (void) fflush(stdout);
143 }
144 if (loopflg && ++count < argc) {
145 goto TOP;
146 }
147 }