1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * x || y - concatenate strings x and y.
   5:  */
   6: 
   7: cat(nargs, arg2, arg1, arg0)
   8: int nargs;
   9: struct descrip arg2, arg1, arg0;
  10:    {
  11:    DclSave
  12:    char sbuf1[MAXSTRING], sbuf2[MAXSTRING];
  13:    extern char *alcstr();
  14: 
  15:    SetBound;
  16:    /*
  17:     * x and y must be strings.
  18:     */
  19:    if (cvstr(&arg1, sbuf1) == NULL)
  20:       runerr(103, &arg1);
  21:    if (cvstr(&arg2, sbuf2) == NULL)
  22:       runerr(103, &arg2);
  23: 
  24:    /*
  25:     * Ensure space for the resulting string.
  26:     */
  27:    sneed(STRLEN(arg1)+STRLEN(arg2));
  28:    if (STRLOC(arg1) + STRLEN(arg1) == sfree)
  29:       /*
  30:        * The end of x is at the end of the string space, hence, x was the
  31:        *  last string allocated.  x is not recopied, rather, y is appended
  32:        *  to the string space and the result is pointed at the start of x.
  33:        */
  34:       STRLOC(arg0) = STRLOC(arg1);
  35:    else
  36:       /*
  37:        * Append x to the end of the string space and point the result
  38:        *  at the start of x.
  39:        */
  40:       STRLOC(arg0) = alcstr(STRLOC(arg1),STRLEN(arg1));
  41:    /*
  42:     * Append y to the end of the string space.
  43:     */
  44:    alcstr(STRLOC(arg2),STRLEN(arg2));
  45:    /*
  46:     *  Set the length of the result and return.
  47:     */
  48:    STRLEN(arg0) = STRLEN(arg1) + STRLEN(arg2);
  49:    ClearBound;
  50:    }
  51: 
  52: Opblock(cat,2,"||")

Defined functions

cat defined in line 7; used 1 times
  • in line 52
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 385
Valid CSS Valid XHTML 1.0 Strict