Annotation of researchv10no/ipc/bin/ftp/domacro.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.