Disable some misleading service tests because a test cannot determine wheter or not...
[reactos.git] / reactos / base / applications / network / 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(int argc, const char *argv[])
32 {
33 int i, j;
34 const char *cp1;
35 char *cp2;
36 int count = 2, loopflg = 0;
37 char line2[200];
38 struct cmd *getcmd(), *c;
39
40 if (argc < 2) {
41 (void) strcat(line, " ");
42 printf("(macro name) ");
43 (void) fflush(stdout);
44 (void) gets(&line[strlen(line)]);
45 makeargv();
46 argc = margc;
47 argv = margv;
48 }
49 if (argc < 2) {
50 printf("Usage: %s macro_name.\n", argv[0]);
51 (void) fflush(stdout);
52 code = -1;
53 return;
54 }
55 for (i = 0; i < macnum; ++i) {
56 if (!strncmp(argv[1], macros[i].mac_name, 9)) {
57 break;
58 }
59 }
60 if (i == macnum) {
61 printf("'%s' macro not found.\n", argv[1]);
62 (void) fflush(stdout);
63 code = -1;
64 return;
65 }
66 (void) strcpy(line2, line);
67 TOP:
68 cp1 = macros[i].mac_start;
69 while (cp1 != macros[i].mac_end) {
70 while (isspace(*cp1)) {
71 cp1++;
72 }
73 cp2 = line;
74 while (*cp1 != '\0') {
75 switch(*cp1) {
76 case '\\':
77 *cp2++ = *++cp1;
78 break;
79 case '$':
80 if (isdigit(*(cp1+1))) {
81 j = 0;
82 while (isdigit(*++cp1)) {
83 j = 10*j + *cp1 - '0';
84 }
85 cp1--;
86 if (argc - 2 >= j) {
87 (void) strcpy(cp2, argv[j+1]);
88 cp2 += strlen(argv[j+1]);
89 }
90 break;
91 }
92 if (*(cp1+1) == 'i') {
93 loopflg = 1;
94 cp1++;
95 if (count < argc) {
96 (void) strcpy(cp2, argv[count]);
97 cp2 += strlen(argv[count]);
98 }
99 break;
100 }
101 /* intentional drop through */
102 default:
103 *cp2++ = *cp1;
104 break;
105 }
106 if (*cp1 != '\0') {
107 cp1++;
108 }
109 }
110 *cp2 = '\0';
111 makeargv();
112 c = getcmd(margv[0]);
113 if (c == (struct cmd *)-1) {
114 printf("?Ambiguous command\n");
115 code = -1;
116 }
117 else if (c == 0) {
118 printf("?Invalid command\n");
119 code = -1;
120 }
121 else if (c->c_conn && !connected) {
122 printf("Not connected.\n");
123 code = -1;
124 }
125 else {
126 if (verbose) {
127 printf("%s\n",line);
128 }
129 (*c->c_handler)(margc, margv);
130 if (bell && c->c_bell) {
131 (void) putchar('\007');
132 }
133 (void) strcpy(line, line2);
134 makeargv();
135 argc = margc;
136 argv = margv;
137 }
138 if (cp1 != macros[i].mac_end) {
139 cp1++;
140 }
141 (void) fflush(stdout);
142 }
143 if (loopflg && ++count < argc) {
144 goto TOP;
145 }
146 }