Example #1
0
static void sf_c2_MPC_framework(void)
{
  uint8_T c2_previousEvent;
  _sfTime_ = (real_T)ssGetT(chartInstance.S);
  _SFD_DATA_RANGE_CHECK(*c2_x(), 1U);
  _SFD_DATA_RANGE_CHECK(*c2_y(), 8U);
  _SFD_DATA_RANGE_CHECK(*c2_al1_c(), 3U);
  _SFD_DATA_RANGE_CHECK(*c2_al2_c(), 4U);
  _SFD_DATA_RANGE_CHECK(*c2_a1(), 5U);
  _SFD_DATA_RANGE_CHECK(*c2_a2(), 2U);
  _SFD_DATA_RANGE_CHECK(*c2_al1(), 0U);
  _SFD_DATA_RANGE_CHECK(*c2_al2(), 7U);
  _SFD_DATA_RANGE_CHECK((real_T)*c2_error(), 6U);
  c2_previousEvent = _sfEvent_;
  _sfEvent_ = CALL_EVENT;
  c2_c2_MPC_framework();
  _sfEvent_ = c2_previousEvent;
  sf_debug_check_for_state_inconsistency(_MPC_frameworkMachineNumber_,
   chartInstance.chartNumber, chartInstance.instanceNumber);
}
Example #2
0
/**
 * Parse a group in condition string.
 *
 * @return offset of next character in string
 */
static int
c2_parse_grp(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult, int level) {
  // Check for recursion levels
  if (level > C2_MAX_LEVELS)
    c2_error("Exceeded maximum recursion levels.");

  if (!pattern)
    return -1;

  // Expected end character
  const char endchar = (offset ? ')': '\0');

#undef c2_error
#define c2_error(format, ...) do { \
  printf_err("Pattern \"%s\" pos %d: " format, pattern, offset, \
      ## __VA_ARGS__); \
  goto c2_parse_grp_fail; \
} while(0)

  // We use a system that a maximum of 2 elements are kept. When we find
  // the third element, we combine the elements according to operator
  // precedence. This design limits operators to have at most two-levels
  // of precedence and fixed left-to-right associativity.

  // For storing branch operators. ops[0] is actually unused
  c2_b_op_t ops[3] = { };
  // For storing elements
  c2_ptr_t eles[2] = { C2_PTR_INIT, C2_PTR_INIT };
  // Index of next free element slot in eles
  int elei = 0;
  // Pointer to the position of next element
  c2_ptr_t *pele = eles;
  // Negation flag of next operator
  bool neg = false;
  // Whether we are expecting an element immediately, is true at first, or
  // after encountering a logical operator
  bool next_expected = true;

  // Parse the pattern character-by-character
  for (; pattern[offset]; ++offset) {
    assert(elei <= 2);

    // Jump over spaces
    if (isspace(pattern[offset]))
      continue;

    // Handle end of group
    if (')' == pattern[offset])
      break;

    // Handle "!"
    if ('!' == pattern[offset]) {
      if (!next_expected)
        c2_error("Unexpected \"!\".");

      neg = !neg;
      continue;
    }

    // Handle AND and OR
    if ('&' == pattern[offset] || '|' == pattern[offset]) {
      if (next_expected)
        c2_error("Unexpected logical operator.");

      next_expected = true;
      if (!mstrncmp("&&", pattern + offset)) {
        ops[elei] = C2_B_OAND;
        ++offset;
      }
      else if (!mstrncmp("||", pattern + offset)) {
        ops[elei] = C2_B_OOR;
        ++offset;
      }
      else
        c2_error("Illegal logical operator.");

      continue;
    }

    // Parsing an element
    if (!next_expected)
      c2_error("Unexpected expression.");

    assert(!elei || ops[elei]);

    // If we are out of space
    if (2 == elei) {
      --elei;
      // If the first operator has higher or equal precedence, combine
      // the first two elements
      if (c2h_b_opcmp(ops[1], ops[2]) >= 0) {
        eles[0] = c2h_comb_tree(ops[1], eles[0], eles[1]);
        c2_ptr_reset(&eles[1]);
        pele = &eles[elei];
        ops[1] = ops[2];
      }
      // Otherwise, combine the second and the incoming one
      else {
        eles[1] = c2h_comb_tree(ops[2], eles[1], C2_PTR_NULL);
        assert(eles[1].isbranch);
        pele = &eles[1].b->opr2;
      }
      // The last operator always needs to be reset
      ops[2] = C2_B_OUNDEFINED;
    }

    // It's a subgroup if it starts with '('
    if ('(' == pattern[offset]) {
      if ((offset = c2_parse_grp(ps, pattern, offset + 1, pele, level + 1)) < 0)
        goto c2_parse_grp_fail;
    }
    // Otherwise it's a leaf
    else {
      if ((offset = c2_parse_target(ps, pattern, offset, pele)) < 0)
        goto c2_parse_grp_fail;

      assert(!pele->isbranch && !c2_ptr_isempty(*pele));

      if ((offset = c2_parse_op(pattern, offset, pele)) < 0)
        goto c2_parse_grp_fail;

      if ((offset = c2_parse_pattern(ps, pattern, offset, pele)) < 0)
        goto c2_parse_grp_fail;

      if (!c2_l_postprocess(ps, pele->l))
        goto c2_parse_grp_fail;
    }
    // Decrement offset -- we will increment it in loop update
    --offset;

    // Apply negation
    if (neg) {
      neg = false;
      if (pele->isbranch)
        pele->b->neg = !pele->b->neg;
      else
        pele->l->neg = !pele->l->neg;
    }

    next_expected = false;
    ++elei;
    pele = &eles[elei];
  }

  // Wrong end character?
  if (pattern[offset] && !endchar)
    c2_error("Expected end of string but found '%c'.", pattern[offset]);
  if (!pattern[offset] && endchar)
    c2_error("Expected '%c' but found end of string.", endchar);

  // Handle end of group
  if (!elei) {
    c2_error("Empty group.");
  }
  else if (next_expected) {
    c2_error("Missing rule before end of group.");
  }
  else if (elei > 1) {
    assert(2 == elei);
    assert(ops[1]);
    eles[0] = c2h_comb_tree(ops[1], eles[0], eles[1]);
    c2_ptr_reset(&eles[1]);
  }

  *presult = eles[0];

  if (')' == pattern[offset])
    ++offset;

  return offset;

c2_parse_grp_fail:
  c2_freep(&eles[0]);
  c2_freep(&eles[1]);

  return -1;
}
Example #3
0
/**
 * Do postprocessing on a condition leaf.
 */
static bool
c2_l_postprocess(session_t *ps, c2_l_t *pleaf) {
  // Give a pattern type to a leaf with exists operator, if needed
  if (C2_L_OEXISTS == pleaf->op && !pleaf->ptntype) {
    pleaf->ptntype =
      (C2_L_TSTRING == pleaf->type ? C2_L_PTSTRING: C2_L_PTINT);
  }

  // Get target atom if it's not a predefined one
  if (!pleaf->predef) {
    pleaf->tgtatom = get_atom(ps, pleaf->tgt);
    if (!pleaf->tgtatom)
      c2_error("Failed to get atom for target \"%s\".", pleaf->tgt);
  }

  // Insert target Atom into atom track list
  if (pleaf->tgtatom) {
    bool found = false;
    for (latom_t *platom = ps->track_atom_lst; platom;
        platom = platom->next) {
      if (pleaf->tgtatom == platom->atom) {
        found = true;
        break;
      }
    }
    if (!found) {
      latom_t *pnew = malloc(sizeof(latom_t));
      if (!pnew)
        printf_errfq(1, "(): Failed to allocate memory for new track atom.");
      pnew->next = ps->track_atom_lst;
      pnew->atom = pleaf->tgtatom;
      ps->track_atom_lst = pnew;
    }
  }

  // Enable specific tracking options in compton if needed by the condition
  // TODO: Add track_leader
  if (pleaf->predef) {
    switch (pleaf->predef) {
      case C2_L_PFOCUSED: ps->o.track_focus = true; break;
      case C2_L_PNAME:
      case C2_L_PCLASSG:
      case C2_L_PCLASSI:
      case C2_L_PROLE:    ps->o.track_wdata = true; break;
      default:            break;
    }
  }

  // Warn about lower case characters in target name
  if (!pleaf->predef) {
    for (const char *pc = pleaf->tgt; *pc; ++pc) {
      if (islower(*pc)) {
        printf_errf("(): Warning: Lowercase character in target name \"%s\".", pleaf->tgt);
        break;
      }
    }
  }

  // PCRE patterns
  if (C2_L_PTSTRING == pleaf->ptntype && C2_L_MPCRE == pleaf->match) {
#ifdef CONFIG_REGEX_PCRE
    const char *error = NULL;
    int erroffset = 0;
    int options = 0;

    // Ignore case flag
    if (pleaf->match_ignorecase)
      options |= PCRE_CASELESS;

    // Compile PCRE expression
    pleaf->regex_pcre = pcre_compile(pleaf->ptnstr, options,
        &error, &erroffset, NULL);
    if (!pleaf->regex_pcre)
      c2_error("Pattern \"%s\": PCRE regular expression parsing failed on "
          "offset %d: %s", pleaf->ptnstr, erroffset, error);
#ifdef CONFIG_REGEX_PCRE_JIT
    pleaf->regex_pcre_extra = pcre_study(pleaf->regex_pcre,
        PCRE_STUDY_JIT_COMPILE, &error);
    if (!pleaf->regex_pcre_extra) {
      printf("Pattern \"%s\": PCRE regular expression study failed: %s",
          pleaf->ptnstr, error);
    }
#endif

    // Free the target string
    // free(pleaf->tgt);
    // pleaf->tgt = NULL;
#else
    c2_error("PCRE regular expression support not compiled in.");
#endif
  }

  return true;
}
Example #4
0
/**
 * Parse a condition with legacy syntax.
 */
static int
c2_parse_legacy(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult) {
  unsigned plen = strlen(pattern + offset);

  if (plen < 4 || ':' != pattern[offset + 1]
      || !strchr(pattern + offset + 2, ':'))
    c2_error("Legacy parser: Invalid format.");

  // Allocate memory for new leaf
  c2_l_t *pleaf = malloc(sizeof(c2_l_t));
  if (!pleaf)
    printf_errfq(1, "(): Failed to allocate memory for new leaf.");
  presult->isbranch = false;
  presult->l = pleaf;
  memcpy(pleaf, &leaf_def, sizeof(c2_l_t));
  pleaf->type = C2_L_TSTRING;
  pleaf->op = C2_L_OEQ;
  pleaf->ptntype = C2_L_PTSTRING;

  // Determine the pattern target
#define TGTFILL(pdefid) \
  (pleaf->predef = pdefid, \
   pleaf->type = C2_PREDEFS[pdefid].type, \
   pleaf->format = C2_PREDEFS[pdefid].format)
  switch (pattern[offset]) {
    case 'n': TGTFILL(C2_L_PNAME);    break;
    case 'i': TGTFILL(C2_L_PCLASSI);  break;
    case 'g': TGTFILL(C2_L_PCLASSG);  break;
    case 'r': TGTFILL(C2_L_PROLE);    break;
    default:  c2_error("Target \"%c\" invalid.\n", pattern[offset]);
  }
#undef TGTFILL

  offset += 2;

  // Determine the match type
  switch (pattern[offset]) {
    case 'e': pleaf->match = C2_L_MEXACT;       break;
    case 'a': pleaf->match = C2_L_MCONTAINS;    break;
    case 's': pleaf->match = C2_L_MSTART;       break;
    case 'w': pleaf->match = C2_L_MWILDCARD;    break;
    case 'p': pleaf->match = C2_L_MPCRE;        break;
    default:  c2_error("Type \"%c\" invalid.\n", pattern[offset]);
  }
  ++offset;

  // Determine the pattern flags
  while (':' != pattern[offset]) {
    switch (pattern[offset]) {
      case 'i': pleaf->match_ignorecase = true;  break;
      default:  c2_error("Flag \"%c\" invalid.", pattern[offset]);
    }
    ++offset;
  }
  ++offset;

  // Copy the pattern
  pleaf->ptnstr = mstrcpy(pattern + offset);

  if (!c2_l_postprocess(ps, pleaf))
    return -1;

  return offset;
}
Example #5
0
/**
 * Parse the pattern part of a leaf.
 */
static int
c2_parse_pattern(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult) {
  c2_l_t * const pleaf = presult->l;

  // Exists operator cannot have pattern
  if (!pleaf->op)
    return offset;

  C2H_SKIP_SPACES();

  char *endptr = NULL;
  // Check for boolean patterns
  if (!strcmp_wd("true", &pattern[offset])) {
    pleaf->ptntype = C2_L_PTINT;
    pleaf->ptnint = true;
    offset += strlen("true");
  }
  else if (!strcmp_wd("false", &pattern[offset])) {
    pleaf->ptntype = C2_L_PTINT;
    pleaf->ptnint = false;
    offset += strlen("false");
  }
  // Check for integer patterns
  else if (pleaf->ptnint = strtol(pattern + offset, &endptr, 0),
      pattern + offset != endptr) {
    pleaf->ptntype = C2_L_PTINT;
    offset = endptr - pattern;
    // Make sure we are stopping at the end of a word
    if (isalnum(pattern[offset]))
      c2_error("Trailing characters after a numeric pattern.");
  }
  // Check for string patterns
  else {
    bool raw = false;
    char delim = '\0';

    // String flags
    if ('r' == tolower(pattern[offset])) {
      raw = true;
      ++offset;
      C2H_SKIP_SPACES();
    }

    // Check for delimiters
    if ('\"' == pattern[offset] || '\'' == pattern[offset]) {
      pleaf->ptntype = C2_L_PTSTRING;
      delim = pattern[offset];
      ++offset;
    }

    if (C2_L_PTSTRING != pleaf->ptntype)
      c2_error("Invalid pattern type.");

    // Parse the string now
    // We can't determine the length of the pattern, so we use the length
    // to the end of the pattern string -- currently escape sequences
    // cannot be converted to a string longer than itself.
    char *tptnstr = malloc((strlen(pattern + offset) + 1) * sizeof(char));
    char *ptptnstr = tptnstr;
    pleaf->ptnstr = tptnstr;
    for (; pattern[offset] && delim != pattern[offset]; ++offset) {
      // Handle escape sequences if it's not a raw string
      if ('\\' == pattern[offset] && !raw) {
        switch(pattern[++offset]) {
          case '\\':  *(ptptnstr++) = '\\'; break;
          case '\'':  *(ptptnstr++) = '\''; break;
          case '\"':  *(ptptnstr++) = '\"'; break;
          case 'a':   *(ptptnstr++) = '\a'; break;
          case 'b':   *(ptptnstr++) = '\b'; break;
          case 'f':   *(ptptnstr++) = '\f'; break;
          case 'n':   *(ptptnstr++) = '\n'; break;
          case 'r':   *(ptptnstr++) = '\r'; break;
          case 't':   *(ptptnstr++) = '\t'; break;
          case 'v':   *(ptptnstr++) = '\v'; break;
          case 'o':
          case 'x':
                      {
                        char *tstr = mstrncpy(pattern + offset + 1, 2);
                        char *pstr = NULL;
                        long val = strtol(tstr, &pstr,
                            ('o' == pattern[offset] ? 8: 16));
                        free(tstr);
                        if (pstr != &tstr[2] || val <= 0)
                          c2_error("Invalid octal/hex escape sequence.");
                        assert(val < 256 && val >= 0);
                        *(ptptnstr++) = val;
                        offset += 2;
                        break;
                      }
          default:   c2_error("Invalid escape sequence.");
        }
      }
      else {
        *(ptptnstr++) = pattern[offset];
      }
    }
    if (!pattern[offset])
      c2_error("Premature end of pattern string.");
    ++offset;
    *ptptnstr = '\0';
    pleaf->ptnstr = mstrcpy(tptnstr);
    free(tptnstr);
  }

  C2H_SKIP_SPACES();

  if (!pleaf->ptntype)
    c2_error("Invalid pattern type.");

  // Check if the type is correct
  if (!(((C2_L_TSTRING == pleaf->type
            || C2_L_TATOM == pleaf->type)
          && C2_L_PTSTRING == pleaf->ptntype)
        || ((C2_L_TCARDINAL == pleaf->type
            || C2_L_TWINDOW == pleaf->type
            || C2_L_TDRAWABLE == pleaf->type)
          && C2_L_PTINT == pleaf->ptntype)))
    c2_error("Pattern type incompatible with target type.");

  if (C2_L_PTINT == pleaf->ptntype && pleaf->match)
    c2_error("Integer/boolean pattern cannot have operator qualifiers.");

  if (C2_L_PTINT == pleaf->ptntype && pleaf->match_ignorecase)
    c2_error("Integer/boolean pattern cannot have flags.");

  if (C2_L_PTSTRING == pleaf->ptntype
      && (C2_L_OGT == pleaf->op || C2_L_OGTEQ == pleaf->op
        || C2_L_OLT == pleaf->op || C2_L_OLTEQ == pleaf->op))
    c2_error("String pattern cannot have an arithmetic operator.");

  return offset;
}
Example #6
0
/**
 * Parse the operator part of a leaf.
 */
static int
c2_parse_op(const char *pattern, int offset, c2_ptr_t *presult) {
  c2_l_t * const pleaf = presult->l;

  // Parse negation marks
  C2H_SKIP_SPACES();
  while ('!' == pattern[offset]) {
    pleaf->neg = !pleaf->neg;
    ++offset;
    C2H_SKIP_SPACES();
  }

  // Parse qualifiers
  if ('*' == pattern[offset] || '^' == pattern[offset]
      || '%' == pattern[offset] || '~' == pattern[offset]) {
    switch (pattern[offset]) {
      case '*': pleaf->match = C2_L_MCONTAINS; break;
      case '^': pleaf->match = C2_L_MSTART;    break;
      case '%': pleaf->match = C2_L_MWILDCARD; break;
      case '~': pleaf->match = C2_L_MPCRE;     break;
      default:  assert(0);
    }
    ++offset;
    C2H_SKIP_SPACES();
  }

  // Parse flags
  while ('?' == pattern[offset]) {
    pleaf->match_ignorecase = true;
    ++offset;
    C2H_SKIP_SPACES();
  }

  // Parse operator
  while ('=' == pattern[offset] || '>' == pattern[offset]
      || '<' == pattern[offset]) {
    if ('=' == pattern[offset] && C2_L_OGT == pleaf->op)
      pleaf->op = C2_L_OGTEQ;
    else if ('=' == pattern[offset] && C2_L_OLT == pleaf->op)
      pleaf->op = C2_L_OLTEQ;
    else if (pleaf->op) {
      c2_error("Duplicate operator.");
    }
    else {
      switch (pattern[offset]) {
        case '=': pleaf->op = C2_L_OEQ; break;
        case '>': pleaf->op = C2_L_OGT; break;
        case '<': pleaf->op = C2_L_OLT; break;
        default:  assert(0);
      }
    }
    ++offset;
    C2H_SKIP_SPACES();
  }

  // Check for problems
  if (C2_L_OEQ != pleaf->op && (pleaf->match || pleaf->match_ignorecase))
    c2_error("Exists/greater-than/less-than operators cannot have a qualifier.");

  return offset;
}
Example #7
0
/**
 * Parse the target part of a rule.
 */
static int
c2_parse_target(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult) {
  // Initialize leaf
  presult->isbranch = false;
  presult->l = malloc(sizeof(c2_l_t));
  if (!presult->l)
    c2_error("Failed to allocate memory for new leaf.");

  c2_l_t * const pleaf = presult->l;
  memcpy(pleaf, &leaf_def, sizeof(c2_l_t));

  // Parse negation marks
  while ('!' == pattern[offset]) {
    pleaf->neg = !pleaf->neg;
    ++offset;
    C2H_SKIP_SPACES();
  }

  // Copy target name out
  unsigned tgtlen = 0;
  for (; pattern[offset]
      && (isalnum(pattern[offset]) || '_' == pattern[offset]); ++offset) {
    ++tgtlen;
  }
  if (!tgtlen)
    c2_error("Empty target.");
  pleaf->tgt = mstrncpy(&pattern[offset - tgtlen], tgtlen);

  // Check for predefined targets
  for (unsigned i = 1; i < sizeof(C2_PREDEFS) / sizeof(C2_PREDEFS[0]); ++i) {
    if (!strcmp(C2_PREDEFS[i].name, pleaf->tgt)) {
      pleaf->predef = i;
      pleaf->type = C2_PREDEFS[i].type;
      pleaf->format = C2_PREDEFS[i].format;
      break;
    }
  }

  // Alias for predefined targets
  if (!pleaf->predef) {
#define TGTFILL(pdefid) \
  (pleaf->predef = pdefid, \
   pleaf->type = C2_PREDEFS[pdefid].type, \
   pleaf->format = C2_PREDEFS[pdefid].format)

  // if (!strcmp("WM_NAME", tgt) || !strcmp("_NET_WM_NAME", tgt))
  //   TGTFILL(C2_L_PNAME);
#undef TGTFILL

    // Alias for custom properties
#define TGTFILL(target, type, format) \
  (pleaf->target = mstrcpy(target), \
   pleaf->type = type, \
   pleaf->format = format)

    // if (!strcmp("SOME_ALIAS"))
    //   TGTFILL("ALIAS_TEXT", C2_L_TSTRING, 32);
#undef TGTFILL
  }

  C2H_SKIP_SPACES();

  // Parse target-on-frame flag
  if ('@' == pattern[offset]) {
    pleaf->tgt_onframe = true;
    ++offset;
    C2H_SKIP_SPACES();
  }

  // Parse index
  if ('[' == pattern[offset]) {
    offset++;

    C2H_SKIP_SPACES();

    int index = -1;
    char *endptr = NULL;

    index = strtol(pattern + offset, &endptr, 0);

    if (!endptr || pattern + offset == endptr)
      c2_error("No index number found after bracket.");

    if (index < 0)
      c2_error("Index number invalid.");

    if (pleaf->predef)
      c2_error("Predefined targets can't have index.");

    pleaf->index = index;
    offset = endptr - pattern;

    C2H_SKIP_SPACES();

    if (']' != pattern[offset])
      c2_error("Index end marker not found.");

    ++offset;

    C2H_SKIP_SPACES();
  }

  // Parse target type and format
  if (':' == pattern[offset]) {
    ++offset;
    C2H_SKIP_SPACES();

    // Look for format
    bool hasformat = false;
    int format = 0;
    {
      char *endptr = NULL;
      format =  strtol(pattern + offset, &endptr, 0);
      assert(endptr);
      if ((hasformat = (endptr && endptr != pattern + offset)))
        offset = endptr - pattern;
      C2H_SKIP_SPACES();
    }

    // Look for type
    enum c2_l_type type = C2_L_TUNDEFINED;
    {
      switch (pattern[offset]) {
        case 'w': type = C2_L_TWINDOW; break;
        case 'd': type = C2_L_TDRAWABLE; break;
        case 'c': type = C2_L_TCARDINAL; break;
        case 's': type = C2_L_TSTRING; break;
        case 'a': type = C2_L_TATOM; break;
        default:  c2_error("Invalid type character.");
      }

      if (type) {
        if (pleaf->predef) {
          printf_errf("(): Warning: Type specified for a default target will be ignored.");
        }
        else {
          if (pleaf->type && type != pleaf->type)
            printf_errf("(): Warning: Default type overridden on target.");
          pleaf->type = type;
        }
      }

      offset++;
      C2H_SKIP_SPACES();
    }

    // Default format
    if (!pleaf->format) {
      switch (pleaf->type) {
        case C2_L_TWINDOW:
        case C2_L_TDRAWABLE:
        case C2_L_TATOM:
          pleaf->format = 32;  break;
        case C2_L_TSTRING:
          pleaf->format = 8;   break;
        default:
          break;
      }
    }

    // Write format
    if (hasformat) {
      if (pleaf->predef)
        printf_errf("(): Warning: Format \"%d\" specified on a default target will be ignored.", format);
      else if (C2_L_TSTRING == pleaf->type)
        printf_errf("(): Warning: Format \"%d\" specified on a string target will be ignored.", format);
      else {
        if (pleaf->format && pleaf->format != format)
          printf_err("Warning: Default format %d overridden on target.",
              pleaf->format);
        pleaf->format = format;
      }
    }
  }

  if (!pleaf->type)
    c2_error("Target type cannot be determined.");

  // if (!pleaf->predef && !pleaf->format && C2_L_TSTRING != pleaf->type)
  //   c2_error("Target format cannot be determined.");

  if (pleaf->format && 8 != pleaf->format
        && 16 != pleaf->format && 32 != pleaf->format)
    c2_error("Invalid format.");

  return offset;
}
Example #8
0
static void c2_c2_MPC_framework(void)
{
  real_T c2_b_x;
  real_T c2_b_y;
  real_T c2_b_al1_c;
  real_T c2_b_al2_c;
  real_T c2_b_a1;
  real_T c2_b_a2;
  real_T c2_al2_2;
  real_T c2_al1_al2_2;
  real_T c2_sin_al1_al2_2;
  real_T c2_cos_al1_al2_2;
  real_T c2_al2_1;
  real_T c2_al1_al2_1;
  real_T c2_sin_al1_al2_1;
  real_T c2_cos_al1_al2_1;
  real_T c2_al2_n;
  real_T c2_al2_p;
  real_T c2_al1_2;
  real_T c2_al1_1;
  real_T c2_cos_al1_n;
  real_T c2_cos_al1_p;
  real_T c2_sin_al1_n;
  real_T c2_sin_al1_p;
  real_T c2_D;
  real_T c2_cos_al2;
  real_T c2_d;
  uint8_T c2_b_error;
  real_T c2_b_al2;
  real_T c2_b_al1;
  real_T c2_c_x;
  real_T c2_c_y;
  boolean_T c2_em_b0;
  boolean_T c2_em_b1;
  real_T c2_A;
  real_T c2_B;
  real_T c2_d_x;
  real_T c2_d_y;
  real_T c2_z;
  real_T c2_e_y;
  real_T c2_e_x;
  real_T c2_f_y;
  real_T c2_b_A;
  real_T c2_b_B;
  real_T c2_f_x;
  real_T c2_g_y;
  real_T c2_b_z;
  real_T c2_h_y;
  real_T c2_g_x;
  real_T c2_i_y;
  real_T c2_c_A;
  real_T c2_c_B;
  real_T c2_h_x;
  real_T c2_j_y;
  real_T c2_c_z;
  real_T c2_k_y;
  real_T c2_i_x;
  real_T c2_l_y;
  real_T c2_d_A;
  real_T c2_d_B;
  real_T c2_j_x;
  real_T c2_m_y;
  real_T c2_d_z;
  real_T c2_n_y;
  real_T c2_k_x;
  real_T c2_o_y;
  real_T c2_e_A;
  real_T c2_e_B;
  real_T c2_l_x;
  real_T c2_p_y;
  real_T c2_e_z;
  real_T c2_q_y;
  real_T c2_m_x;
  real_T c2_k;
  real_T c2_b_k;
  real_T c2_r_y;
  real_T c2_n_x;
  real_T c2_s_y;
  real_T c2_f_A;
  real_T c2_f_B;
  real_T c2_o_x;
  real_T c2_t_y;
  real_T c2_f_z;
  real_T c2_u_y;
  real_T c2_p_x;
  real_T c2_v_y;
  real_T c2_g_A;
  real_T c2_g_B;
  real_T c2_q_x;
  real_T c2_w_y;
  real_T c2_g_z;
  real_T c2_x_y;
  real_T c2_r_x;
  real_T c2_y_y;
  real_T c2_h_A;
  real_T c2_h_B;
  real_T c2_s_x;
  real_T c2_ab_y;
  real_T c2_h_z;
  real_T c2_bb_y;
  real_T c2_t_x;
  real_T c2_cb_y;
  real_T c2_i_A;
  real_T c2_i_B;
  real_T c2_u_x;
  real_T c2_db_y;
  real_T c2_i_z;
  real_T c2_eb_y;
  real_T c2_v_x;
  real_T c2_fb_y;
  real_T c2_w_x;
  real_T c2_gb_y;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG,1);
  c2_b_x = *c2_x();
  c2_b_y = *c2_y();
  c2_b_al1_c = *c2_al1_c();
  c2_b_al2_c = *c2_al2_c();
  c2_b_a1 = *c2_a1();
  c2_b_a2 = *c2_a2();
  sf_debug_push_symbol_scope(28U, 0U);
  sf_debug_symbol_scope_add_symbol("al2_2", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U,
   0, 0U, 0, &c2_al2_2, 0);
  sf_debug_symbol_scope_add_symbol("al1_al2_2", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0,
   0U, 0, 0U, 0, &c2_al1_al2_2, 0);
  sf_debug_symbol_scope_add_symbol("sin_al1_al2_2", 0, 0U, 0U, 0U, 0U, 1.0, 0,
   0.0, 0U, 0, 0U, 0, &c2_sin_al1_al2_2, 0);
  sf_debug_symbol_scope_add_symbol("cos_al1_al2_2", 0, 0U, 0U, 0U, 0U, 1.0, 0,
   0.0, 0U, 0, 0U, 0, &c2_cos_al1_al2_2, 0);
  sf_debug_symbol_scope_add_symbol("al2_1", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U,
   0, 0U, 0, &c2_al2_1, 0);
  sf_debug_symbol_scope_add_symbol("al1_al2_1", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0,
   0U, 0, 0U, 0, &c2_al1_al2_1, 0);
  sf_debug_symbol_scope_add_symbol("sin_al1_al2_1", 0, 0U, 0U, 0U, 0U, 1.0, 0,
   0.0, 0U, 0, 0U, 0, &c2_sin_al1_al2_1, 0);
  sf_debug_symbol_scope_add_symbol("cos_al1_al2_1", 0, 0U, 0U, 0U, 0U, 1.0, 0,
   0.0, 0U, 0, 0U, 0, &c2_cos_al1_al2_1, 0);
  sf_debug_symbol_scope_add_symbol("al2_n", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U,
   0, 0U, 0, &c2_al2_n, 0);
  sf_debug_symbol_scope_add_symbol("al2_p", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U,
   0, 0U, 0, &c2_al2_p, 0);
  sf_debug_symbol_scope_add_symbol("al1_2", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U,
   0, 0U, 0, &c2_al1_2, 0);
  sf_debug_symbol_scope_add_symbol("al1_1", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U,
   0, 0U, 0, &c2_al1_1, 0);
  sf_debug_symbol_scope_add_symbol("cos_al1_n", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0,
   0U, 0, 0U, 0, &c2_cos_al1_n, 0);
  sf_debug_symbol_scope_add_symbol("cos_al1_p", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0,
   0U, 0, 0U, 0, &c2_cos_al1_p, 0);
  sf_debug_symbol_scope_add_symbol("sin_al1_n", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0,
   0U, 0, 0U, 0, &c2_sin_al1_n, 0);
  sf_debug_symbol_scope_add_symbol("sin_al1_p", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0,
   0U, 0, 0U, 0, &c2_sin_al1_p, 0);
  sf_debug_symbol_scope_add_symbol("D", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U, 0,
   0U, 0, &c2_D, 0);
  sf_debug_symbol_scope_add_symbol("cos_al2", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0,
   0U, 0, 0U, 0, &c2_cos_al2, 0);
  sf_debug_symbol_scope_add_symbol("d", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U, 0,
   0U, 0, &c2_d, 0);
  sf_debug_symbol_scope_add_symbol("error", 3, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U,
   0, 0U, 0, &c2_b_error, 0);
  sf_debug_symbol_scope_add_symbol("al2", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U, 0,
   0U, 0, &c2_b_al2, 0);
  sf_debug_symbol_scope_add_symbol("al1", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U, 0,
   0U, 0, &c2_b_al1, 0);
  sf_debug_symbol_scope_add_symbol("a2", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U, 0,
   0U, 0, &c2_b_a2, 0);
  sf_debug_symbol_scope_add_symbol("a1", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U, 0,
   0U, 0, &c2_b_a1, 0);
  sf_debug_symbol_scope_add_symbol("al2_c", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U,
   0, 0U, 0, &c2_b_al2_c, 0);
  sf_debug_symbol_scope_add_symbol("al1_c", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U,
   0, 0U, 0, &c2_b_al1_c, 0);
  sf_debug_symbol_scope_add_symbol("y", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U, 0,
   0U, 0, &c2_b_y, 0);
  sf_debug_symbol_scope_add_symbol("x", 0, 0U, 0U, 0U, 0U, 1.0, 0, 0.0, 0U, 0,
   0U, 0, &c2_b_x, 0);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,3);
  c2_c_x = c2_mpower(c2_b_x) + c2_mpower(c2_b_y);
  c2_c_y = sqrt(c2_c_x);
  c2_d = c2_c_y;
  _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,4);
  c2_em_b0 = (c2_mpower(c2_d) > c2_mpower(c2_b_a1) + c2_mpower(c2_b_a2));
  c2_em_b1 = (c2_d < c2_b_a1 - c2_b_a2);
  if(CV_EML_IF(0, 0, c2_em_b0 || c2_em_b1)) {
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,5);
    c2_b_al1 = c2_b_al1_c;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,6);
    c2_b_al2 = c2_b_al2_c;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,7);
    c2_b_error = 1U;
  } else {
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,11);
    c2_A = ((c2_mpower(c2_b_x) + c2_mpower(c2_b_y)) - c2_mpower(c2_b_a1)) -
      c2_mpower(c2_b_a2);
    c2_B = 2.0 * c2_b_a1 * c2_b_a2;
    c2_d_x = c2_A;
    c2_d_y = c2_B;
    c2_z = c2_d_x / c2_d_y;
    c2_e_y = c2_z;
    c2_cos_al2 = c2_e_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,12);
    c2_D = c2_b_a1 + c2_b_a2 * c2_cos_al2;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,14);
    c2_e_x = (c2_mpower(c2_b_x) + c2_mpower(c2_b_y)) - c2_mpower(c2_D);
    c2_f_y = sqrt(c2_e_x);
    c2_b_A = c2_D * c2_b_y + c2_b_x * c2_f_y;
    c2_b_B = c2_mpower(c2_b_x) + c2_mpower(c2_b_y);
    c2_f_x = c2_b_A;
    c2_g_y = c2_b_B;
    c2_b_z = c2_f_x / c2_g_y;
    c2_h_y = c2_b_z;
    c2_sin_al1_p = c2_h_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,15);
    c2_g_x = (c2_mpower(c2_b_x) + c2_mpower(c2_b_y)) - c2_mpower(c2_D);
    c2_i_y = sqrt(c2_g_x);
    c2_c_A = c2_D * c2_b_y - c2_b_x * c2_i_y;
    c2_c_B = c2_mpower(c2_b_x) + c2_mpower(c2_b_y);
    c2_h_x = c2_c_A;
    c2_j_y = c2_c_B;
    c2_c_z = c2_h_x / c2_j_y;
    c2_k_y = c2_c_z;
    c2_sin_al1_n = c2_k_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,17);
    c2_i_x = (c2_mpower(c2_b_x) + c2_mpower(c2_b_y)) - c2_mpower(c2_D);
    c2_l_y = sqrt(c2_i_x);
    c2_d_A = c2_D * c2_b_x + c2_b_y * c2_l_y;
    c2_d_B = c2_mpower(c2_b_x) + c2_mpower(c2_b_y);
    c2_j_x = c2_d_A;
    c2_m_y = c2_d_B;
    c2_d_z = c2_j_x / c2_m_y;
    c2_n_y = c2_d_z;
    c2_cos_al1_p = c2_n_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,18);
    c2_k_x = (c2_mpower(c2_b_x) + c2_mpower(c2_b_y)) - c2_mpower(c2_D);
    c2_o_y = sqrt(c2_k_x);
    c2_e_A = c2_D * c2_b_x - c2_b_y * c2_o_y;
    c2_e_B = c2_mpower(c2_b_x) + c2_mpower(c2_b_y);
    c2_l_x = c2_e_A;
    c2_p_y = c2_e_B;
    c2_e_z = c2_l_x / c2_p_y;
    c2_q_y = c2_e_z;
    c2_cos_al1_n = c2_q_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,20);
    c2_al1_1 = c2_atan2(c2_sin_al1_p, c2_cos_al1_n);
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,22);
    c2_al1_2 = c2_atan2(c2_sin_al1_n, c2_cos_al1_p);
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,24);
    c2_m_x = c2_cos_al2;
    c2_k = 1.0;
    c2_b_k = c2_k;
    _SFD_EML_ARRAY_BOUNDS_CHECK("x", (int32_T)_SFD_INTEGER_CHECK("k", c2_b_k),
     1, 1, 1);
    if(c2_m_x < -1.0) {
    } else {
      _SFD_EML_ARRAY_BOUNDS_CHECK("x", (int32_T)_SFD_INTEGER_CHECK("k", c2_b_k),
       1, 1, 1);
      if(c2_m_x > 1.0) {
      } else {
        goto label_1;
      }
    }
    sf_mex_call("error", 0U, 1U, 15,
     "Domain error. To compute complex results from real x, use \'acos(complex(x))\'.");
    label_1:;
    c2_r_y = acos(c2_m_x);
    c2_al2_p = c2_r_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,25);
    c2_al2_n = -c2_al2_p;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,27);
    c2_n_x = c2_al1_1;
    c2_s_y = cos(c2_n_x);
    c2_f_A = c2_b_x - c2_b_a1 * c2_s_y;
    c2_f_B = c2_b_a2;
    c2_o_x = c2_f_A;
    c2_t_y = c2_f_B;
    c2_f_z = c2_o_x / c2_t_y;
    c2_u_y = c2_f_z;
    c2_cos_al1_al2_1 = c2_u_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,28);
    c2_p_x = c2_al1_1;
    c2_v_y = sin(c2_p_x);
    c2_g_A = c2_b_y - c2_b_a1 * c2_v_y;
    c2_g_B = c2_b_a2;
    c2_q_x = c2_g_A;
    c2_w_y = c2_g_B;
    c2_g_z = c2_q_x / c2_w_y;
    c2_x_y = c2_g_z;
    c2_sin_al1_al2_1 = c2_x_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,29);
    c2_al1_al2_1 = c2_atan2(c2_sin_al1_al2_1, c2_cos_al1_al2_1);
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,30);
    c2_al2_1 = c2_al1_al2_1 - c2_al1_1;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,32);
    c2_r_x = c2_al1_2;
    c2_y_y = cos(c2_r_x);
    c2_h_A = c2_b_x - c2_b_a1 * c2_y_y;
    c2_h_B = c2_b_a2;
    c2_s_x = c2_h_A;
    c2_ab_y = c2_h_B;
    c2_h_z = c2_s_x / c2_ab_y;
    c2_bb_y = c2_h_z;
    c2_cos_al1_al2_2 = c2_bb_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,33);
    c2_t_x = c2_al1_2;
    c2_cb_y = sin(c2_t_x);
    c2_i_A = c2_b_y - c2_b_a1 * c2_cb_y;
    c2_i_B = c2_b_a2;
    c2_u_x = c2_i_A;
    c2_db_y = c2_i_B;
    c2_i_z = c2_u_x / c2_db_y;
    c2_eb_y = c2_i_z;
    c2_sin_al1_al2_2 = c2_eb_y;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,34);
    c2_al1_al2_2 = c2_atan2(c2_sin_al1_al2_2, c2_cos_al1_al2_2);
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,35);
    c2_al2_2 = c2_al1_al2_2 - c2_al1_2;
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,37);
    c2_v_x = c2_b_al1_c - c2_al1_1;
    c2_fb_y = fabs(c2_v_x);
    c2_w_x = c2_b_al1_c - c2_al1_2;
    c2_gb_y = fabs(c2_w_x);
    if(CV_EML_IF(0, 1, c2_fb_y < c2_gb_y)) {
      _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,38);
      c2_b_al1 = c2_al1_1;
      _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,39);
      c2_b_al2 = c2_al2_1;
    } else {
      _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,41);
      c2_b_al1 = c2_al1_2;
      _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,42);
      c2_b_al2 = c2_al2_2;
    }
    _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,45);
    c2_b_error = 0U;
  }
  _SFD_EML_CALL(STATE_DURING_DURING_ACTION_TAG,0,-45);
  sf_debug_pop_symbol_scope();
  *c2_al1() = c2_b_al1;
  *c2_al2() = c2_b_al2;
  *c2_error() = c2_b_error;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG,1);
}
Example #9
0
static void chart_debug_initialization(SimStruct *S)
{
  if(ssIsFirstInitCond(S)) {
    /* do this only if simulation is starting */
    if(!sim_mode_is_rtw_gen(S)) {
      {
        unsigned int chartAlreadyPresent;
        chartAlreadyPresent =
          sf_debug_initialize_chart(_MPC_frameworkMachineNumber_,
         2,
         1,
         1,
         9,
         0,
         0,
         0,
         0,
         &(chartInstance.chartNumber),
         &(chartInstance.instanceNumber),
         ssGetPath(S),
         (void *)S);
        if(chartAlreadyPresent==0) {
          /* this is the first instance */
          sf_debug_set_chart_disable_implicit_casting(_MPC_frameworkMachineNumber_,chartInstance.chartNumber,1);
          sf_debug_set_chart_event_thresholds(_MPC_frameworkMachineNumber_,
           chartInstance.chartNumber,
           0,
           0,
           0);

          _SFD_SET_DATA_PROPS(1,1,1,0,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,"x",0);
          _SFD_SET_DATA_PROPS(8,1,1,0,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,"y",0);
          _SFD_SET_DATA_PROPS(3,1,1,0,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,"al1_c",0);
          _SFD_SET_DATA_PROPS(4,1,1,0,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,"al2_c",0);
          _SFD_SET_DATA_PROPS(5,1,1,0,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,"a1",0);
          _SFD_SET_DATA_PROPS(2,1,1,0,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,"a2",0);
          _SFD_SET_DATA_PROPS(0,2,0,1,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,"al1",0);
          _SFD_SET_DATA_PROPS(7,2,0,1,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,"al2",0);
          _SFD_SET_DATA_PROPS(6,2,0,1,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,"error",0);
          _SFD_STATE_INFO(0,0,2);
          _SFD_CH_SUBSTATE_COUNT(0);
          _SFD_CH_SUBSTATE_DECOMP(0);
        }
        _SFD_CV_INIT_CHART(0,0,0,0);
        {
          _SFD_CV_INIT_STATE(0,0,0,0,0,0,NULL,NULL);
        }

        _SFD_CV_INIT_TRANS(0,0,NULL,NULL,0,NULL);

        /* Initialization of EML Model Coverage */
        _SFD_CV_INIT_EML(0,1,2,0,0,0,0,0);
        _SFD_CV_INIT_EML_FCN(0,0,"eML_blk_kernel",0,-1,1304);
        _SFD_CV_INIT_EML_IF(0,0,98,140,1126,1271);
        _SFD_CV_INIT_EML_IF(0,1,1126,1170,1217,1271);
        _SFD_TRANS_COV_WTS(0,0,0,1,0);
        if(chartAlreadyPresent==0)
        {
          _SFD_TRANS_COV_MAPS(0,
           0,NULL,NULL,
           0,NULL,NULL,
           1,NULL,NULL,
           0,NULL,NULL);
        }
        _SFD_SET_DATA_VALUE_PTR(1U, c2_x());
        _SFD_SET_DATA_VALUE_PTR(8U, c2_y());
        _SFD_SET_DATA_VALUE_PTR(3U, c2_al1_c());
        _SFD_SET_DATA_VALUE_PTR(4U, c2_al2_c());
        _SFD_SET_DATA_VALUE_PTR(5U, c2_a1());
        _SFD_SET_DATA_VALUE_PTR(2U, c2_a2());
        _SFD_SET_DATA_VALUE_PTR(0U, c2_al1());
        _SFD_SET_DATA_VALUE_PTR(7U, c2_al2());
        _SFD_SET_DATA_VALUE_PTR(6U, c2_error());
      }
    }
  } else {
    sf_debug_reset_current_state_configuration(_MPC_frameworkMachineNumber_,chartInstance.chartNumber,chartInstance.instanceNumber);
  }
}
Example #10
0
/* ***************************************************
*  Punch out STRSET                                  *
* ************************************************** */
void c2_strset(void) 
{
  if (traceflg == 1) 
  {
    strcpy(trace_1, "c2z_strset.c c2_strset");
    trace_rec_1();
  }

  char ch;
  char field1[VAR_LGTH];
  char field2[VAR_LGTH];

  int pi;
  int pi2;
  int x = 0;
  int x1 = 0;
  int x3 = 0;
  int I = 0;
  int ret = 0;

  pi = 0;
  ch = p_string[pi];
  while ((ch == ' ') || (ch == '\t')) 
  {
    pi++;
    ch = p_string[pi];
  }

  while (ch != '(') 
  {
    pi++;
    ch = p_string[pi];
  }

  pi++;
  ch = p_string[pi];
  pi2 = 0;
  while (ch != ',') 
  {
    field1[pi2] = ch;
    pi2++;
    pi++;
    ch = p_string[pi];
  }
  field1[pi2] = '\0';

  x = 0;
  for (I = 0; I < gv_ct; I++) 
  {
    ret = strcmp(field1, gw_variable[I].gv_name);
    if (ret == 0) 
    {
      x1 = strcmp(gw_variable[I].gv_type, "C");
      if (x1 != 0) 
      {
        printf("c2z_strset.c c2_strset E-513 field1 Not Character = %s\n",field1);
        c2_error();
      }
      if (x1 == 0)
      {
        x = 1;
      }
    }
  }

  if (x == 0) 
  {
    printf("c2z_strset.c c2_strset E-514 field1 Not Found = %s\n", field1);
    c2_error();
  }

  while (ch != ',') 
  {
    pi++;
    ch = p_string[pi];
  }

  pi++;
  ch = p_string[pi];
  while (ch == ' ') 
  {
    pi++;
    ch = p_string[pi];
  }

  pi2 = 0;
  while (ch != ')') 
  {
    if (ch != '\'') 
    {
      field2[pi2] = ch;
      pi2++;
    }
    pi++;
    ch = p_string[pi];
  }
  field2[pi2] = '\0';

  for (I = 0; I < gv_ct; I++) 
  {
    ret = strcmp(gw_variable[I].gv_name, field1);
    if (ret == 0) 
    {
      x3 = gw_variable[I].gv_lgth;
    }
  }

  x3--;
  strcpy(a_string, "         MVI   ");
  strcat(a_string, field1);
  strcat(a_string, ",C'");
  strcat(a_string, field2);
  strcat(a_string, "'");
  strcpy(wk_remark, " strset  */");
  write_remark();
  if (puncde == 1) 
  {
    strcpy(trace_1, "c2z_strset.c c2_strset #1");
    trace_rec_3();
  }

  strcpy(a_string, "         MVC   ");
  strcat(a_string, field1);
  strcat(a_string, "+1(");
  snprintf(wk_strg, sizeof(wk_strg), "%d", x3);
  strcat(a_string, wk_strg);
  strcat(a_string, "),");
  strcat(a_string, field1);
  src_line();
  if (puncde == 1) 
  {
    strcpy(trace_1, "c2z_strset.c c2_strset #2");
    trace_rec_3();
  }

  strcpy(a_string, "*");
  src_line();
  if (puncde == 1) 
  {
    strcpy(trace_1, "c2z_strset.c c2_strset #3");
    trace_rec_3();
  }
}