ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

domacro.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1985 Regents of the University of California.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms are permitted
00006  * provided that the above copyright notice and this paragraph are
00007  * duplicated in all such forms and that any documentation,
00008  * advertising materials, and other materials related to such
00009  * distribution and use acknowledge that the software was developed
00010  * by the University of California, Berkeley.  The name of the
00011  * University may not be used to endorse or promote products derived
00012  * from this software without specific prior written permission.
00013  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
00014  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
00015  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00016  */
00017 
00018 #ifndef lint
00019 static char sccsid[] = "@(#)domacro.c   1.6 (Berkeley) 2/28/89";
00020 #endif /* not lint */
00021 
00022 #include "precomp.h"
00023 //#include <errno.h>
00024 //#include <sys/ttychars.h>
00025 
00026 void domacro(int argc, const char *argv[])
00027 {
00028     int i, j;
00029     const char *cp1;
00030     char *cp2;
00031     int count = 2, loopflg = 0;
00032     char line2[200];
00033     struct cmd *getcmd(), *c;
00034 
00035     if (argc < 2) {
00036         (void) strcat(line, " ");
00037         printf("(macro name) ");
00038         (void) fflush(stdout);
00039         (void) gets(&line[strlen(line)]);
00040         makeargv();
00041         argc = margc;
00042         argv = margv;
00043     }
00044     if (argc < 2) {
00045         printf("Usage: %s macro_name.\n", argv[0]);
00046         (void) fflush(stdout);
00047         code = -1;
00048         return;
00049     }
00050     for (i = 0; i < macnum; ++i) {
00051         if (!strncmp(argv[1], macros[i].mac_name, 9)) {
00052             break;
00053         }
00054     }
00055     if (i == macnum) {
00056         printf("'%s' macro not found.\n", argv[1]);
00057         (void) fflush(stdout);
00058         code = -1;
00059         return;
00060     }
00061     (void) strcpy(line2, line);
00062 TOP:
00063     cp1 = macros[i].mac_start;
00064     while (cp1 != macros[i].mac_end) {
00065         while (isspace(*cp1)) {
00066             cp1++;
00067         }
00068         cp2 = line;
00069         while (*cp1 != '\0') {
00070               switch(*cp1) {
00071                 case '\\':
00072                  *cp2++ = *++cp1;
00073                  break;
00074                 case '$':
00075                  if (isdigit(*(cp1+1))) {
00076                     j = 0;
00077                     while (isdigit(*++cp1)) {
00078                       j = 10*j +  *cp1 - '0';
00079                     }
00080                     cp1--;
00081                     if (argc - 2 >= j) {
00082                     (void) strcpy(cp2, argv[j+1]);
00083                     cp2 += strlen(argv[j+1]);
00084                     }
00085                     break;
00086                  }
00087                  if (*(cp1+1) == 'i') {
00088                     loopflg = 1;
00089                     cp1++;
00090                     if (count < argc) {
00091                        (void) strcpy(cp2, argv[count]);
00092                        cp2 += strlen(argv[count]);
00093                     }
00094                     break;
00095                 }
00096                 /* intentional drop through */
00097                 default:
00098                 *cp2++ = *cp1;
00099                 break;
00100               }
00101               if (*cp1 != '\0') {
00102              cp1++;
00103               }
00104         }
00105         *cp2 = '\0';
00106         makeargv();
00107         c = getcmd(margv[0]);
00108         if (c == (struct cmd *)-1) {
00109             printf("?Ambiguous command\n");
00110             code = -1;
00111         }
00112         else if (c == 0) {
00113             printf("?Invalid command\n");
00114             code = -1;
00115         }
00116         else if (c->c_conn && !connected) {
00117             printf("Not connected.\n");
00118             code = -1;
00119         }
00120         else {
00121             if (verbose) {
00122                 printf("%s\n",line);
00123             }
00124             (*c->c_handler)(margc, margv);
00125             if (bell && c->c_bell) {
00126                 (void) putchar('\007');
00127             }
00128             (void) strcpy(line, line2);
00129             makeargv();
00130             argc = margc;
00131             argv = margv;
00132         }
00133         if (cp1 != macros[i].mac_end) {
00134             cp1++;
00135         }
00136         (void) fflush(stdout);
00137     }
00138     if (loopflg && ++count < argc) {
00139         goto TOP;
00140     }
00141 }

Generated on Sun May 27 2012 04:17:13 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.