Ejemplo n.º 1
0
static void add_to_help(COMMAND *cmd, char *helpline)
{
    PCMACRO *mac, *ptr;

    if (cmd == (COMMAND *)NULL) {
      wipoutput(stderr, "Define the command before assigning help to it.\n");
      return;
    }

    if ((mac = (PCMACRO *)Malloc(sizeof(PCMACRO))) == (PCMACRO *)NULL) {
      wipoutput(stderr, "Could not allocate memory for the help text.\n");
      return;
    }

    if ((mac->line = wipnewstring(helpline)) == (char *)NULL) {
      wipoutput(stderr, "Could not allocate memory for the help string.\n");
      Free(mac);
      return;
    }

    mac->next = (PCMACRO *)NULL;

    if (cmd->help == (PCMACRO *)NULL) {
      cmd->help = mac;
    } else {                          /* Find the end of the help list. */
      for (ptr = cmd->help; ptr->next != (PCMACRO *)NULL; ptr = ptr->next)
        /* NULL */ ;
      ptr->next = mac;
    }
    return;
}
Ejemplo n.º 2
0
/*
 *  Returns -1 if an error seeking; otherwise the routine
 *  returns the size of a file in bytes and leaves the file
 *  at the beginning when finished (successful).
 *
 *  This routine assumes FSEEK and FTELL are present on the system.
 */
long int filesize(FILE *fp)
{
      long int fsize;

      if (Fseek(fp, 0L, SEEK_END) != 0) {
        wipoutput(stderr, "Error searching for the end of the file.\n");
        return(-1L);
      }
      fsize = Ftell(fp);
      if (Fseek(fp, 0L, SEEK_SET) != 0) {
        wipoutput(stderr, "Error finding the beginning of the file.\n");
        return(-1L);
      }
      return(fsize);
}
Ejemplo n.º 3
0
/*
 * This routine takes the current input command line "line" and
 * searches for any possible macro declarations.  These are
 * present in the line as "$#" where '#' is a single digit
 * number from 0 to 9.  If a macro argument is found, it is
 * either substituted with the value on the same line as the
 * macro call (if it was present) or silently replaced with an
 * empty string.
 *
 * The user order of macro substitutions runs from the 1st to 9th
 * and then the 0th value.  Internally, the array runs from 0 to 9.
 * Thus, when a macro argument is found, it's integer value
 * will need to be shifted to account for the difference.  This
 * is done with a simple mod operation:
 * Internal order is: $0, $1, ..., $8, $9;
 * User sees order as: $1, $2, ..., $9, $0.
 *
 * This routine uses the input string "string" to copy the argument
 * substituted line into, so make sure it is large enough to hold
 * everything!  Also, this function returns a pointer to "string"
 * in the same fashion as strcpy().  There is no check to make sure
 * that the size of macarg[] is sufficient to cover all input
 * arguments.  This is a quiet assumption.  Also, macarg should
 * be declared "const char *macarg[]" but because it is a pointer to
 * an open array, I have trouble doing this.
 *
 */
static char *domacsubs(char *string, const char *line, char *macarg[])
{
    register int j, k;
    register char *s, *ptr, *arg;

    if (Strchr(line, '$') == (char *)NULL) {   /* No arguments to sub. */
      (void)Strcpy(string, line);     /* Simply return a copy of line. */
    } else {
      s = (char *)line;
      ptr = string;
      while (*s) {                      /* Parse through input string. */
        if (*s != '$') {                /* If not special character... */
          *ptr++ = *s++;                /* ...copy regular characters; */
        } else {                /* otherwise, get the argument number. */
          j = (*(s+1)) - '0';      /* Convert next char to an integer. */
          if ((j < 0) || (j > 9)) {       /* Not a macro substitution. */
            *ptr++ = *s++;                      /* Just a regular '$'. */
          } else {
#if 1
            if ( *(s+2) ) {             /* see if next char */
                k = *(s+2) - '0';       /* is a digit */
                if (k>=0 && k<=9) {     /* and if so */
                    j = j*10 + k;       /* allow two digit parameters */
                    k = 1;              /* remember we had 2 digits */
                } else
                    k = 0;
            } else 
                k = 0;
            if (j >= MAXARG) {
                wipoutput(stderr, "$%d too large a reference\n",j);
                return NULL;
            }
            j = (j==0 ? 9 : j-1);
#else
            j = (j + 9) % 10;       /* This is where order is shifted. */
            k = 0;
#endif
            /*
             *  If the macro argument is not present, then quietly
             *  skip over the request.  If it is present (macarg[j]
             *  != Null), then substitute the argument value now.
             */
            if (macarg[j] != Null) {     /* If a value exists, then... */
              arg = (char *)macarg[j];  /* ...substitute the argument. */
              while (*arg)
                *ptr++ = *arg++;
            }
            s++;                                 /* Skip over the '$'. */
            s++;                                 /* Skip over the '#'. */
            if (k) s++;                     /* and one more if needed. */
          }                           /* If (0 <= j <= 9) conditional. */
        }                               /* If (*s != '$') conditional. */
      }                                            /* While (*s) loop. */
      *ptr = Null;                   /* Make sure it ends with a Null. */
    }                               /* if (!Strchr(line, '$')) branch. */

    return(string);
}
Ejemplo n.º 4
0
void wipdecode(const char *string, char *outstr, size_t maxout)
{
    char *ptr, *tmptr, *savptr;
    char ch;
    char tempstr[BUFSIZ], variable[BUFSIZ];
    int nsig, nopen;
    double arg;
    LOGICAL error;

    ptr = (char *)string;
    if (Strchr(string, ESC) != (char *)NULL) {
      arg = wipgetvar("nsig", &error);
      nsig = NINT(arg);        /* Tells how to format a user variable. */
      tmptr = tempstr;
      while (*ptr) {
        if (*ptr != ESC) {
          *tmptr++ = *ptr++;               /* Just copy the character. */
          continue;                         /* Get the next character. */
        }            /* At this point an ESC character has been found. */
        ch = *ptr++;                        /* save the ESC character. */
        if (*ptr != '[') {  /* No user variable here, so just store... */
          *tmptr++ = ch;        /* ...the two characters and continue. */
          *tmptr++ = *ptr++;           /* This is so "\\" gets passed. */
          continue;                         /* Get the next character. */
        }        /* At this point a user variable flag has been found. */
        ptr++;                          /* Increment ptr past the '['. */
        savptr = variable;       /* Set up user variable name pointer. */
        nopen = 1;              /* Initialize the number of open '['s. */
        while ((*ptr) && (nopen)) {         /* Get user variable name. */
          if (*ptr == '[') nopen++;
          if (*ptr == ']') nopen--;
          if (nopen) *savptr++ = *ptr++;
        }
        if (*ptr != Null) ptr++;                 /* Skip over last ']' */
        *savptr = Null;        /* Skip last ']'; add terminating Null. */
        if (wipisstring(variable)) {          /* User string variable. */
          savptr = wipgetstring(variable);    /* Find string variable. */
          if (savptr == (char *)NULL) savptr = "";     /* Error check. */
        } else {                            /* Standard user variable. */
          arg = wipevaluate(variable, &error);  /* Find user variable. */
          savptr = wipfpfmt(arg, nsig);           /* Format the value. */
        }
        while ((*savptr != Null) && (isspace(*savptr)))
          savptr++;                       /* Strip off leading blanks. */
        while (*savptr) *tmptr++ = *savptr++;    /* Include the value. */
      }                                 /* End of "while (*ptr)" loop. */
      *tmptr = Null;              /* Terminate the string with a Null. */
      ptr = tempstr;        /* Assign the work pointer to this string. */
    }                           /* End of "(domacs == TRUE)" if block. */

    if (Strlen(ptr) >= maxout)
      wipoutput(stderr, "Decoded string overflows output string size.\n");

    (void)Strncpy(outstr, ptr, maxout);
    outstr[maxout-1] = Null;       /* Make sure it is Null terminated. */

    return;
}
Ejemplo n.º 5
0
/*  Returns 0 on success; 1 on error. */
int wipcommand(const char *command)
{
    char outbuf[BUFSIZ];

    Strcpy(outbuf, command);
    if (System(outbuf)) {
        wipoutput(stderr, "Error sending command:\n%s\n", command);
        return(1);
    }
    return(0);
}
Ejemplo n.º 6
0
/* Returns 0 on success; 1 on error. */
int wipquarter(int quadrant)
{
    void *curimage;
    int nx, ny;
    int x1, x2, y1, y2;

    if (((curimage = wipimcur("curimage")) == (char *)NULL) ||
        (wipimagexists(curimage) == 0)) {
      wipoutput(stderr, "You must specify an image first!\n");
      return(1);
    }

    wipimagenxy(curimage, &nx, &ny);      /* Get the image dimensions. */
    switch (quadrant) {
      case  1: x1 = 1;    x2 = nx/2;   y1 = 1;    y2 = ny/2;   break;
      case  2: x1 = nx/2; x2 = nx;     y1 = 1;    y2 = ny/2;   break;
      case  3: x1 = 1;    x2 = nx/2;   y1 = ny/2; y2 = ny;     break;
      case  4: x1 = nx/2; x2 = nx;     y1 = ny/2; y2 = ny;     break;
      default: x1 = nx/4; x2 = 3*nx/4; y1 = ny/4; y2 = 3*ny/4; break;
    }

    wipsetsub(x1, x2, y1, y2);
    return(0);
}
Ejemplo n.º 7
0
/*  Returns 0 on success; 1 on error. */
int wipspool(const char *file)
{
    char *lpr, *ptr;
    char fmt[BUFSIZ];
    char outbuf[BUFSIZ];
    int okayState;

#ifdef WIPVMS
    okayState = 1;
#else
    okayState = 0;
#endif /* WIPVMS */

    if ((ptr = wipgetstring("print")) == (char *)NULL) {
        wipoutput(stderr, "HARDCOPY: Error finding printing command.\n");
        return(1);
    }

    if (wiplenc(ptr) < 1)  /* If string is empty, no printing desired. */
        return(0);

    if (Strncmp(ptr, "ignore", 6) == 0) /* Still, no printing desired. */
        return(0);

    lpr = Strcpy(outbuf, ptr);

    if ((ptr = Strchr(lpr, '&')) != (char *)NULL) {
        while(*ptr) {                      /* Remove all '&' characters. */
            if (*ptr == '&') *ptr = ' ';
            ptr++;
        }
    }

#ifdef WIPVMS
    if (Strstr(lpr, "%s") == (char *)NULL) {
        SPrintf(fmt, "%s %%s", lpr);
    } else {
        SPrintf(fmt, "%s", lpr);
    }
#else
    if (Strstr(lpr, "%s") == (char *)NULL) {
        SPrintf(fmt, "%s %%s &\n", lpr);
    } else {
        SPrintf(fmt, "%s &\n", lpr);
    }
#endif /* WIPVMS */

    /*
     *  "fmt" now contains the printer command along with a "%s" for
     *  the file name.
     */

    if ((ptr = wipleading(file)) == (char *)NULL) {
        wipoutput(stderr, "HARDCOPY: Can't get the name of the file to spool.\n");
        return(1);
    }

    SPrintf(outbuf, fmt, ptr);
    wipoutput(stdout, "HARDCOPY: Spooling command:\n %s", outbuf);
    if (System(outbuf) != okayState) {
        wipoutput(stderr, "HARDCOPY: Error spooling WIP printer file.\n");
        return(1);
    }

    return(0);
}
Ejemplo n.º 8
0
/*  Returns 0 if successful; 1 on error. */
int wiphelp(char *line)
{
    char *ptr, *pstr;
    char string[STRINGSIZE], save[STRINGSIZE];
    static char *lastname = (char *)NULL;
    int inflag;
    FILE *fp;
    COMMAND *vb;
    PCMACRO *pc;
    LOGICAL trash;

    if ((ptr = wipgetstring("helpfile")) == (char *)NULL) {
      wipoutput(stderr, "Trouble finding help file string variable.\n");
      return(1);
    }

    if (lastname == (char *)NULL) /* Force a mismatch below. */
      lastname = wipnewstring("?");

    if (Strcmp(lastname, ptr) != 0) {        /* Read the new help file. */
      wipoutput(stdout, "Reading contents of help file...\n");
      Free(lastname);                   /* Release storage of old name. */
      if ((fp = Fopen(ptr, "r")) == (FILE *)NULL) {
        wipoutput(stderr, "Trouble opening help file %s.\n", ptr);
        lastname = (char *)NULL;
        return(1);
      }

      lastname = wipnewstring(ptr);      /* Save the current file name. */
      if (lastname == (char *)NULL) {
        wipoutput(stderr,
          "Trouble allocating local storage for the help file name.\n");
        return(1);
      }

      trash = TRUE;
      while ((inflag = wipinput(fp, (char *)NULL, string, STRINGSIZE)) != EOF) {
        if (inflag == Null) continue;
        pstr = string;
        if ((*pstr) != '\t') {
          ptr = Strcpy(save, pstr);
          trash = FALSE;
          if ((vb = wipinterpret(&ptr)) == (COMMAND *)NULL) trash = TRUE;
        }
        if (trash == TRUE) {
          wipoutput(stderr, "Help ?? %s\n", pstr);
        } else {
          add_to_help(vb, pstr);
        }
      }
      Fclose(fp);
      wipoutput(stdout, "...done.\n");
    }

    if ((ptr = wipparse(&line)) == (char *)NULL) {
      for (vb = HEAD; vb != (COMMAND *)NULL; vb = vb->next) {
        if ((vb->macro != TRUE) && (vb->help != (PCMACRO *)NULL)) {
          wipoutput(stdout, " %s\n", (vb->help)->line);
        } else if (vb->macro != TRUE) {
          wipoutput(stdout, " %s (No help for this command)\n", vb->name);
        } else {
          wipoutput(stdout, " %s (macro)\n", vb->name);
        }
      }
      wipoutput(stderr, "Use `Help ?' or `Help command'; List a `macro'.\n");
    } else if (Strcmp(ptr, "?") == 0) {
      wipoutput(stdout, "%s%s\n", dash, dash);
      wipoutput(stdout, "Commands:\n");
      wipoutput(stdout, "%s%s\n", dash, dash);
      inflag = 1;
      for (vb = HEAD; vb != BUFFER; vb = vb->next) {
        if (vb->name == (char *)NULL) continue; /* No command name??? */
        inflag += 16;
        if (inflag > 80) {
          wipoutput(stdout, "%-15s\n", vb->name);
          inflag = 1;
        } else {
          wipoutput(stdout, "%-16s", vb->name);
        }
      }
      if (inflag > 1) wipoutput(stdout, "\n");
      wipoutput(stdout, "%s%s\n", dash, dash);
      wipoutput(stdout, "Macros:\n");
      wipoutput(stdout, "%s%s\n", dash, dash);
      inflag = 1;
      for (vb = BUFFER; vb != (COMMAND *)NULL; vb = vb->next) {
        if (vb->name == (char *)NULL) continue; /* No command name??? */
        inflag += 16;
        if (inflag > 80) {
          wipoutput(stdout, "%-15s\n", vb->name);
          inflag = 1;
        } else {
          wipoutput(stdout, "%-16s", vb->name);
        }
      }
      if (inflag > 1) wipoutput(stdout, "\n");
      wipoutput(stdout, "%s%s\n", dash, dash);
    } else {
      if (((vb = wipinterpret(&ptr)) == (COMMAND *)NULL) ||
          ((vb->macro == TRUE) && (Strcmp(vb->name, "buffer")))) {
        wipoutput(stderr, "Use `Help ?' or `Help command'; List a `macro'.\n");
        return(1);
      }
      wipoutput(stdout, "%s%s\n", dash, dash);
      for (pc = vb->help; pc != (PCMACRO *)NULL; pc = pc->next) {
        wipoutput(stdout, " %s\n", pc->line);
      }
      wipoutput(stdout, "%s%s\n", dash, dash);
    }

    return(0);
}
Ejemplo n.º 9
0
/*  Returns 0 if no error; 1 otherwise. */
int wipmaxecute(COMMAND *comm, int count, const char *rest)
{
    char *ptr;
    char *macarg[MAXARG];              /* Pointers to macro arguments. */
    char restcopy[STRINGSIZE];          /* Private copy of input rest. */
    char substring[STRINGSIZE]; /* Command with arguments substituted. */
    int j;
    register int nloop;
    COMMAND *vb;
    register PCMACRO *pc;

    nloop = count;
    for (j = 0; j < MAXARG; j++)
      macarg[j] = Null;   /* Initialize the pointers to the arguments. */

    ptr = Strcpy(restcopy, rest);   /* Make a local copy of the input. */
    for (j = 0; j < MAXARG; j++)          /* Get the macro arguments. */
      if ((macarg[j] = wipparse(&ptr)) == (char *)NULL)
        break;

    for (nloop = 0; nloop < count; nloop++) {  /* Execute repeatively. */
      for (pc = comm->pcmac; pc != (PCMACRO *)NULL; pc = pc->next) {
        ptr = domacsubs(substring, pc->line, macarg);
        if ((vb = wipinterpret(&ptr)) == (COMMAND *)NULL) {
          wipoutput(stderr, "Error interpreting macro line: [%s]\n", pc->line);
          goto INPERR;
        }

        j = 1;                       /* Set up a temporary loop value. */
        if (Strcmp("loop", vb->name) == 0) {
          if ((vb = wiploopxecute(&ptr, &j)) == (COMMAND *)NULL) {
            goto INPERR;
          }
        } else if (Strcmp("if", vb->name) == 0) {
          if ((vb = wipifxecute(&ptr)) == (COMMAND *)NULL) goto INPERR;
          if (vb == ENDIF) continue;
          if (Strcmp("end", vb->name) == 0) break;
          if (Strcmp("loop", vb->name) == 0) {
            if ((vb = wiploopxecute(&ptr, &j)) == (COMMAND *)NULL) goto INPERR;
          }
        }

        if (Strcmp("define", vb->name) == 0) {
          wipoutput(stderr, "DEFINE not allowed within a macro.\n");
          goto INPERR;
        }

        if (Strcmp("insert", vb->name) == 0) {
          wipoutput(stderr, "INSERT not allowed within a macro.\n");
          goto INPERR;
        }

        if (Strcmp("playback", vb->name) == 0) {
          wipoutput(stderr, "PLAYBACK not allowed within a macro.\n");
          goto INPERR;
        }

        if (Strcmp("putlabel", vb->name) == 0)
          ptr = fixputlabel(vb->name, ptr, FALSE);

        if (Strcmp("cursor", vb->name) == 0)
          wipfixcurs(vb->name, ptr, FALSE);

        if (vb->macro == TRUE) {
          if (wipmaxecute(vb, j, ptr)) goto INPERR;
        } else {
          if (wipexecute(vb->name, ptr)) goto INPERR;
        }

      }                     /* End of for(pc != (PCMACRO *)NULL) loop. */
    }                               /* End of for(nloop < count) loop. */

    return(0);

INPERR:
    return(1);
}