Example #1
0
static void unparse(const TinyDomNode* node,
		    std::ostream& ostr,
		    unsigned int indent) {

  if (node->type() == TinyDomNode::TypeElement) {
    unparse((TinyDomElement*)node, ostr, indent);
  } else {
    unparse((TinyDomCharacterData*)node, ostr, indent);
  }
  
}
Example #2
0
svn_stringbuf_t *
svn_skel__unparse(const svn_skel_t *skel, apr_pool_t *pool)
{
  svn_stringbuf_t *str
    = svn_stringbuf_create_ensure(estimate_unparsed_size(skel) + 200, pool);

  return unparse(skel, str);
}
Example #3
0
File: clamb.c Project: irori/clamb
void unparse(Cell e)
{
    if (ispair(e)) {
	putchar('`');
	unparse(car(e));
	unparse(cdr(e));
    }
    else if (e == COMB_S) putchar('S');
    else if (e == COMB_K) putchar('K');
    else if (e == COMB_I) putchar('I');
    else if (e == COMB_B) putchar('B');
    else if (e == COMB_C) putchar('C');
    else if (e == COMB_SP) printf("S'");
    else if (e == COMB_BS) printf("B*");
    else if (e == COMB_CP) printf("C'");
    else if (e == COMB_KI) printf("`ki");
    else putchar('?');
}
std::string gfx_gasoline_unparse_gsl (const GfxGslTypeSystem *ts, const GfxGslAst *ast)
{
    std::stringstream ss;
    ss << "// Vert fields read: " << ts->getVertFieldsRead() << "\n";
    ss << "// Frag fields read: " << ts->getFragFieldsRead() << "\n";
    ss << "// Material fields read: " << ts->getMatFieldsRead() << "\n";
    ss << "// Global fields read: " << ts->getGlobalFieldsRead() << "\n";
    ss << "// Trans-values: " << ts->getTrans() << "\n";
    unparse(ss, ast, 0);
    return ss.str();
}
/* Append the concrete representation of SKEL to the string STR.
   Grow S with new space from POOL as necessary.  */
static svn_stringbuf_t *
unparse(const svn_skel_t *skel, svn_stringbuf_t *str, apr_pool_t *pool)
{
  if (skel->is_atom)
    {
      /* Append an atom to STR.  */
      if (use_implicit(skel))
        svn_stringbuf_appendbytes(str, skel->data, skel->len);
      else
        {
          /* Append the length to STR.  */
          char buf[200];
          int length_len;

          length_len = putsize(buf, sizeof(buf), skel->len);

          SVN_ERR_ASSERT_NO_RETURN(length_len > 0);

          /* Make sure we have room for the length, the space, and the
             atom's contents.  */
          svn_stringbuf_ensure(str, str->len + length_len + 1 + skel->len);
          svn_stringbuf_appendbytes(str, buf, length_len);
          str->data[str->len++] = ' ';
          svn_stringbuf_appendbytes(str, skel->data, skel->len);
        }
    }
  else
    {
      /* Append a list to STR.  */
      svn_skel_t *child;

      /* Emit an opening parenthesis.  */
      svn_stringbuf_ensure(str, str->len + 1);
      str->data[str->len++] = '(';

      /* Append each element.  Emit a space between each pair of elements.  */
      for (child = skel->children; child; child = child->next)
        {
          unparse(child, str, pool);
          if (child->next)
            {
              svn_stringbuf_ensure(str, str->len + 1);
              str->data[str->len++] = ' ';
            }
        }

      /* Emit a closing parenthesis.  */
      svn_stringbuf_appendbyte(str, ')');
    }

  return str;
}
svn_stringbuf_t *
svn_skel__unparse(const svn_skel_t *skel, apr_pool_t *pool)
{
  svn_stringbuf_t *str;

  /* Allocate a string to hold the data.  */
  str = apr_palloc(pool, sizeof(*str));
  str->pool = pool;
  str->blocksize = estimate_unparsed_size(skel) + 200;
  str->data = apr_palloc(pool, str->blocksize);
  str->len = 0;

  return unparse(skel, str, pool);
}
Example #7
0
/** Return sizes for various parts of the table. See doc for SgAsmElfSection::calculate_sizes. Since EH Frame Sections are
 *  run-length encoded, we need to actually unparse the section in order to determine its size. */
rose_addr_t
SgAsmElfEHFrameSection::calculate_sizes(size_t *entsize, size_t *required, size_t *optional, size_t *entcount) const
{
    rose_addr_t whole = unparse(NULL);
    if (entsize)
        *entsize = 0;
    if (required)
        *required = 0;
    if (optional)
        *optional = 0;
    if (entcount)
        *entcount = 0;
    return whole;
}
Example #8
0
/* Append the concrete representation of SKEL to the string STR. */
static svn_stringbuf_t *
unparse(const svn_skel_t *skel, svn_stringbuf_t *str)
{
  if (skel->is_atom)
    {
      /* Append an atom to STR.  */
      if (use_implicit(skel))
        svn_stringbuf_appendbytes(str, skel->data, skel->len);
      else
        {
          /* Append the length to STR.  Ensure enough space for at least
           * one 64 bit int. */
          char buf[200 + SVN_INT64_BUFFER_SIZE];
          apr_size_t length_len;

          length_len = svn__ui64toa(buf, skel->len);

          SVN_ERR_ASSERT_NO_RETURN(length_len > 0);

          /* Make sure we have room for the length, the space, and the
             atom's contents.  */
          svn_stringbuf_ensure(str, str->len + length_len + 1 + skel->len);
          svn_stringbuf_appendbytes(str, buf, length_len);
          svn_stringbuf_appendbyte(str, ' ');
          svn_stringbuf_appendbytes(str, skel->data, skel->len);
        }
    }
  else
    {
      /* Append a list to STR: an opening parenthesis, the list elements
       * separated by a space, and a closing parenthesis.  */
      svn_skel_t *child;

      svn_stringbuf_appendbyte(str, '(');

      for (child = skel->children; child; child = child->next)
        {
          unparse(child, str);
          if (child->next)
            svn_stringbuf_appendbyte(str, ' ');
        }

      svn_stringbuf_appendbyte(str, ')');
    }

  return str;
}
Example #9
0
File: clamb.c Project: irori/clamb
int main(int argc, char *argv[])
{
    Cell root;
    clock_t start;
    char *prog_file = NULL;
    int i;
    int print_stats = 0;
    int parse_only = 0;
    
    for (i = 1; i < argc && argv[i][0] == '-'; i++) {
	if (strcmp(argv[i], "-g") == 0)
	    gc_notify = 1;
	else if (strcmp(argv[i], "-s") == 0)
	    print_stats = 1;
	else if (strcmp(argv[i], "-p") == 0)
	    parse_only = 1;
        else if (strcmp(argv[i], "-u") == 0)
	    setbuf(stdout, NULL);
	else
	    errexit("unknown option %s\n", argv[i]);
    }

    input_init(argv + i);
    storage_init(INITIAL_HEAP_SIZE);
    rs_init();

    root = load_program();
    if (parse_only) {
	unparse(root);
	return 0;
    }

    start = clock();
    eval_print(root);

    if (print_stats) {
	double evaltime = (clock() - start) / (double)CLOCKS_PER_SEC;

	printf("\n%d reductions\n", reductions);
	printf("  total eval time --- %5.2f sec.\n", evaltime - total_gc_time);
	printf("  total gc time   --- %5.2f sec.\n", total_gc_time);
	printf("  max stack depth --- %d\n", rs_max_depth());
    }
    return 0;
}
Example #10
0
static void unparse(const TinyDomElement* element,
		    std::ostream& ostr,
		    unsigned int indent) {

  for (unsigned int i=0; i<indent; ++i) {
    ostr << " ";
  }
  ostr << "<" << TinyDom::escape(element->name());

  const TinyDomElement::AttributeList& attrs = element->attributes();

  for (TinyDomElement::AttributeList::const_iterator i=attrs.begin(); i!=attrs.end(); ++i) {
    ostr << " " << TinyDom::escape(i->key) << "=\"" << TinyDom::escape(i->data) << "\"";
  }

  TinyDomElement::ChildList::const_iterator j;
  const TinyDomElement::ChildList& children = element->children();
  if (children.empty()) {
    ostr << "/>\n";
  } else if (children.size() == 1 &&
	     children.front()->type() == TinyDomNode::TypeCharData &&
	     ((TinyDomCharacterData*)children.front())->value.length() < 20) {
    ostr << ">";
    ostr << TinyDom::escape(((TinyDomCharacterData*)children.front())->trimmedValue());
    ostr << "</" << TinyDom::escape(element->name()) << ">\n";
  } else {
    ostr << ">\n";
    for (j=children.begin(); j!=children.end(); ++j) {
      unparse(*j, ostr, indent+2);
    }
    for (unsigned int i=0; i<indent; ++i) {
      ostr << " ";
    }
    ostr << "</" << TinyDom::escape(element->name()) << ">\n";
  }
  
}
Example #11
0
LyricEditDialog::LyricEditDialog(QWidget *parent,
                                 Segment *segment) :
    QDialog(parent),
    m_segment(segment),
    m_verseCount(0)
{
    QSettings settings;
    settings.beginGroup(GeneralOptionsConfigGroup);
    bool Thorn = settings.value("use_thorn_style", true).toBool();
    settings.endGroup();

    setModal(true);
    setWindowTitle(tr("Edit Lyrics"));

    QGridLayout *metagrid = new QGridLayout;
    setLayout(metagrid);
    QWidget *vbox = new QWidget(this);
    QVBoxLayout *vboxLayout = new QVBoxLayout;
    metagrid->addWidget(vbox, 0, 0);


    QGroupBox *groupBox = new QGroupBox( tr("Lyrics for this segment"), vbox );
    QVBoxLayout *groupBoxLayout = new QVBoxLayout;
    vboxLayout->addWidget(groupBox);
    vbox->setLayout(vboxLayout);

    QWidget *hbox = new QWidget(groupBox);
    QHBoxLayout *hboxLayout = new QHBoxLayout;
    groupBoxLayout->addWidget(hbox);
    hboxLayout->setSpacing(5);
//    new QLabel(tr("Verse:"), hbox);
    m_verseNumber = new QComboBox( hbox );
    hboxLayout->addWidget(m_verseNumber);
    m_verseNumber->setEditable(false);
    connect(m_verseNumber, SIGNAL(activated(int)), this, SLOT(slotVerseNumberChanged(int)));
    m_verseAddButton = new QPushButton(tr("Add Verse"), hbox );
    hboxLayout->addWidget(m_verseAddButton);
    connect(m_verseAddButton, SIGNAL(clicked()), this, SLOT(slotAddVerse()));
    m_verseRemoveButton = new QPushButton(tr("Remove Verse"), hbox );
    hboxLayout->addWidget(m_verseRemoveButton);
    connect(m_verseRemoveButton, SIGNAL(clicked()), this, SLOT(slotRemoveVerse()));
    QFrame *f = new QFrame( hbox );
    hboxLayout->addWidget(f);
    hbox->setLayout(hboxLayout);
    hboxLayout->setStretchFactor(f, 10);

    m_textEdit = new QTextEdit(groupBox);
    groupBoxLayout->addWidget(m_textEdit);
    if (Thorn) m_textEdit->setStyleSheet("background: white");

    m_textEdit->setMinimumWidth(300);
    m_textEdit->setMinimumHeight(200);

    m_currentVerse = 0;
    unparse();
    verseDialogRepopulate();

    //&&& QTextEdit has a new API, and it's not clear what the analog of this
    // function should be.  Since this setCursorPosition(0,0) looks like a very
    // default kind of thing, I'm going out on a limb and guessing that this is
    // probably now superfluous.  I figure something like the cursor position in
    // the lyric editor being messed up is much easier to address if and when we
    // can see the problem, so this is a good candidate for outright removal,
    // flagged appropriately. (dmm)
    //
    // m_textEdit->setCursorPosition(0,0);
    m_textEdit->setFocus();

    groupBox->setLayout(groupBoxLayout);

    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
    metagrid->addWidget(buttonBox, 1, 0);
    metagrid->setRowStretch(0, 10);
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
    connect(buttonBox, SIGNAL(helpRequested()), this, SLOT(slotHelpRequested()));
}
Example #12
0
/** Write data to .eh_frame section */
void
SgAsmElfEHFrameSection::unparse(std::ostream &f) const
{
    unparse(&f);
}
Example #13
0
static json_t *
provision(const clevis_provision_f *funcs,
          const json_t *cfg, const clevis_buf_t *key)
{
  struct curl_slist *headers = NULL;
  clevis_buf_t *okey = NULL;
  struct state state = {};
  const char *url = NULL;
  json_t *data = NULL;
  json_t *tmp = NULL;
  CURL *curl = NULL;
  CURLcode res;

  /* Setup the return data. */
  data = json_object();
  if (!data)
    goto error;

  tmp = json_object_get(cfg, "url");
  if (!json_is_string(tmp))
    goto error;
  url = json_string_value(tmp);
  if (strcasestr(url, "https://") != url)
    goto error;

  if (json_object_set(data, "url", tmp) < 0)
    goto error;

  if (json_object_set_new(data, "format", json_string("binary")) < 0)
    goto error;
  tmp = json_object_get(cfg, "format");
  if (json_is_string(tmp) && json_object_set(data, "format", tmp) < 0)
    goto error;

  okey = clevis_buf_rand(key->len);
  if (!okey)
    goto error;

  if (json_object_set_new(data, "ct", funcs->encrypt(okey, key)) < 0)
    goto error;

  /* Setup the transfer buffer. */
  tmp = json_object_get(cfg, "format");
  headers = header(json_string_value(tmp), content_types);
  state.buf = unparse(okey, json_string_value(tmp));
  if (!state.buf)
    goto error;

  /* Use HTTP PUT to store the key. */
  curl = curl_easy_init();
  if (!curl)
    goto error;

  curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) state.buf->len);
  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  curl_easy_setopt(curl, CURLOPT_READDATA, &state);
  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
  curl_easy_setopt(curl, CURLOPT_URL, url);

  res = curl_easy_perform(curl);
  if (res != CURLE_OK)
    goto error;

  curl_slist_free_all(headers);
  clevis_buf_free(state.buf);
  curl_easy_cleanup(curl);
  clevis_buf_free(okey);
  return data;

error:
  curl_slist_free_all(headers);
  clevis_buf_free(state.buf);
  curl_easy_cleanup(curl);
  clevis_buf_free(okey);
  json_decref(data);
  return NULL;
}
Example #14
0
void
finish(int n)
{
	Rule_t*		r;
	int		i;

	/*
	 * old error intercept
	 */

	if (!state.hold && (r = internal.error) && (r->property & (P_target|P_functional)) == P_target)
	{
		state.hold = null;
		if (n && error_info.errors && !state.compileonly && !state.interrupt)
		{
			if (r->status == NOTYET)
				maketop(r, P_dontcare|P_foreground, NiL);
			state.hold = 0;
			if (r->status == EXISTS)
			{
				r->status = NOTYET;
				return;
			}
		}
	}

	/*
	 * children exit without cleanup
	 */

	if (getpid() != state.pid)
		_exit(n);
	unparse(0);
	switch (state.finish)
	{

	case 0:
		/*
		 * disable listing and wait for any jobs to finish
		 */

		state.finish++;
		alarm(0);
		state.list = 0;
		message((-1, "%s cleanup", state.interrupt ? "interrupt" : n > 0 ? "error" : "normal"));
		complete(NiL, NiL, NiL, 0);
		/*FALLTHROUGH*/

	case 1:
		/*
		 * make the done trap
		 */

		state.finish++;
		if (!state.compileonly && (r = getrule(external.done)))
			maketop(r, P_dontcare, NiL);
		/*FALLTHROUGH*/

	case 2:
		/*
		 * make the makedone trap
		 */

		state.finish++;
		if (!state.compileonly && (r = getrule(external.makedone)))
			maketop(r, P_dontcare, NiL);
		/*FALLTHROUGH*/

	case 3:
		/*
		 * wait for any job(s) to finish
		 */

		state.finish++;
		complete(NiL, NiL, NiL, 0);
		/*FALLTHROUGH*/

	case 4:
		/*
		 * put all jobs in foreground and save state
		 */

		state.finish++;
		state.jobs = 0;
		savestate();
		/*FALLTHROUGH*/

	case 5:
		/*
		 * clean up temporaries
		 */

		state.finish++;
		remtmp(1);
		/*FALLTHROUGH*/

	case 6:
		/*
		 * drop the coshell
		 */
		
		state.finish++;
		drop();
		/*FALLTHROUGH*/

	case 7:
		/*
		 * dump
		 */

		state.finish++;
		if (state.test & 0x00002000)
		{
			Vmstat_t	vs;

			vmstat(Vmheap, &vs);
			error(0, "vm region %zu segments %zu busy %zu:%zu free %zu:%zu", vs.extent, vs.n_seg, vs.n_busy, vs.s_busy, vs.n_free, vs.s_free);
		}
		dump(sfstdout, error_info.trace <= -14);
		/*FALLTHROUGH*/

	case 8:
		/*
		 * final output
		 */

		state.finish++;
		if (state.errors && state.keepgoing && !n)
			n = 1;
		if (state.mam.out)
		{
			if (state.mam.regress)
				sfprintf(state.mam.out, "%sinfo finish regression\n", state.mam.label);
			else if (state.mam.dynamic || *state.mam.label)
				sfprintf(state.mam.out, "%sinfo finish %lu %d\n", state.mam.label, CURTIME, n);
		}
		for (i = 0; i < elementsof(state.io); i++)
			if (state.io[i] != sfstdin && state.io[i] != sfstdout && state.io[i] != sfstderr)
				sfclose(state.io[i]);
		if (state.errors && state.keepgoing)
			error(2, "*** %d action%s failed", state.errors, state.errors == 1 ? null : "s");
		message((-1, "%s exit", state.interrupt ? "interrupt" : n ? "error" : "normal"));
		break;

	}
	if (state.interrupt)
	{
		n = 3;
		signal(state.interrupt, SIG_DFL);
		kill(getpid(), state.interrupt);
		pause();
	}
	exit(n);
}
Example #15
0
 std::string toString() const
     { return unparse(); }
Example #16
0
void XML::save(const std::string& filename) const {
    std::string s;
    unparse(s);
    writeWholeFile(filename, s);
}
Example #17
0
File: main.c Project: majeski/ASM
int main() {
    puts("parsowanie");
    {
        printf("123 = %s\n", unparse(parse("123")));
        printf("-1234 = %s\n", unparse(parse("-1234")));
        printf("00001 = %s\n", unparse(parse("00001")));
        printf("-00001 = %s\n", unparse(parse("-00001")));
        printf("-0 = %s\n", unparse(parse("-0")));
        puts("");
    }

    puts("dodawanie/odejmowanie");
    {
        printf("72 + 133 = %s\n", unparse(suma(parse("72"), parse("133"))));
        printf("-1000 + 1 = %s\n", unparse(suma(parse("-1000"), parse("1"))));
        printf("-100 + 100 = %s\n", unparse(suma(parse("-100"), parse("100"))));
        printf("133 - 2 = %s\n", unparse(roznica(parse("133"), parse("2"))));
        printf("133 - (-2) = %s\n", unparse(roznica(parse("133"), parse("-2"))));
        puts("");
    }

    puts("mnozenie");
    {
        printf("0 * 133 = %s\n", unparse(iloczyn(parse("0"), parse("133"))));
        printf("-1000 * (-2) = %s\n", unparse(iloczyn(parse("-1000"), parse("-2"))));

        bcd *a = parse("11");
        printf("11 * 11 = %s\n", unparse(iloczyn(a, a)));
        puts("");
    }

    puts("dzielenie");
    {
        printf("13 / 42 = %s\n", unparse(iloraz(parse("13"), parse("42"))));
        printf("913 / 104 = %s\n", unparse(iloraz(parse("913"), parse("104"))));
        printf("1525 / 25 = %s\n", unparse(iloraz(parse("1525"), parse("25"))));
        puts("");
    }

    puts("zlozenie");
    {
        bcd *v2 = parse("2");
        bcd *vm3 = parse("-3");
        bcd *v4 = parse("4");
        printf("(2 * (4 + 4)) / 2 = %s\n", unparse(iloraz(iloczyn(v2, suma(v4, v4)), v2)));
        printf("((2 + (-3)) + (-3 + 2)) * 4 = %s\n", unparse(iloczyn(suma(suma(v2, vm3), suma(vm3, v2)), v4)));
        puts("");
    }

    puts("przyklad z tresci");
    {
        bcd *a, *b, *c;
        a = parse("12345678");
        b = parse("234567");
        c = parse("56789");
        a = suma(a, iloczyn(b, c));
        printf("%s\n", unparse(a));
    }
}
Example #18
0
File: sh.sem.c Project: lukem/tcsh
/*VARARGS 1*/
void
execute(struct command *t, volatile int wanttty, int *pipein, int *pipeout,
    int do_glob)
{
    int    forked = 0;
    const struct biltins * volatile bifunc;
    pid_t pid = 0;
    int     pv[2];
    sigset_t set;
    static sigset_t csigset;
#ifdef VFORK
    static int onosigchld = 0;
#endif /* VFORK */
    static int nosigchld = 0;

    (void) &wanttty;
    (void) &forked;
    (void) &bifunc;

    if (t == 0) 
	return;

#ifdef WINNT_NATIVE
    {
        if ((varval(STRNTslowexec) == STRNULL) &&
            !t->t_dcdr && !t->t_dcar && !t->t_dflg && !didfds &&
            (intty || intact) && (t->t_dtyp == NODE_COMMAND) &&
	    !isbfunc(t)) {
	    if ((t->t_dcom[0][0] & (QUOTE | TRIM)) == QUOTE)
		(void) Strcpy(t->t_dcom[0], t->t_dcom[0] + 1);
	    Dfix(t);
            if (nt_try_fast_exec(t) == 0)
                return;
        }
    }
#endif /* WINNT_NATIVE */

    /*
     * Ed [email protected] & Dominic [email protected]
     * Sat Feb 25 03:13:11 PST 1995
     * try implicit cd if we have a 1 word command 
     */
    if (implicit_cd && (intty || intact) && t->t_dcom && t->t_dcom[0] &&
	 t->t_dcom[0][0] && (blklen(t->t_dcom) == 1) && !noexec) {
	Char *sCName;
	struct stat stbuf;
	char *pathname;

	sCName = dollar(t->t_dcom[0]);
	if (sCName != NULL && sCName[0] == '~') {
	    struct Strbuf buf = Strbuf_INIT;
	    const Char *name_end;

	    for (name_end = sCName + 1; *name_end != '\0' && *name_end != '/';
		 name_end++)
		continue;
	    if (name_end != sCName + 1) {
		Char *name, *home;

		name = Strnsave(sCName + 1, name_end - (sCName + 1));
		home = gethdir(name);
		if (home != NULL) {
		    Strbuf_append(&buf, home);
		    xfree(home);
		} else
		    Strbuf_append(&buf, name);
		xfree(name);
	    } else
		Strbuf_append(&buf, varval(STRhome));
	    Strbuf_append(&buf, name_end);
	    xfree(sCName);
	    sCName = Strbuf_finish(&buf);
	}

	pathname = short2str(sCName);
	xfree(sCName);
	/* if this is a dir, tack a "cd" on as the first arg */
	if (pathname != NULL &&
	    ((stat(pathname, &stbuf) != -1 && S_ISDIR(stbuf.st_mode))
#ifdef WINNT_NATIVE
	     || (pathname[0] && pathname[1] == ':' && pathname[2] == '\0')
#endif /* WINNT_NATIVE */
	     )) {
	    Char *vCD[2];
	    Char **ot_dcom = t->t_dcom;
	
	    vCD[0] = Strsave(STRcd);
	    vCD[1] = NULL;
	    t->t_dcom = blkspl(vCD, ot_dcom);
	    xfree(ot_dcom);
	    if (implicit_cd > 1) {
		blkpr(t->t_dcom);
		xputchar( '\n' );
	    }
	}
    }

    /*
     * From: Michael Schroeder <*****@*****.**>
     * Don't check for wantty > 0...
     */
    if (t->t_dflg & F_AMPERSAND)
	wanttty = 0;
    switch (t->t_dtyp) {

    case NODE_COMMAND:
	if ((t->t_dcom[0][0] & (QUOTE | TRIM)) == QUOTE)
	    memmove(t->t_dcom[0], t->t_dcom[0] + 1,
		    (Strlen(t->t_dcom[0] + 1) + 1) * sizeof (*t->t_dcom[0]));
	if ((t->t_dflg & F_REPEAT) == 0)
	    Dfix(t);		/* $ " ' \ */
	if (t->t_dcom[0] == 0) {
	    return;
	}
	/*FALLTHROUGH*/

    case NODE_PAREN:
#ifdef BACKPIPE
	if (t->t_dflg & F_PIPEIN)
	    mypipe(pipein);
#else /* !BACKPIPE */
	if (t->t_dflg & F_PIPEOUT)
	    mypipe(pipeout);
#endif /* BACKPIPE */
	/*
	 * Must do << early so parent will know where input pointer should be.
	 * If noexec then this is all we do.
	 */
	if (t->t_dflg & F_READ) {
	    xclose(0);
	    heredoc(t->t_dlef);
	    if (noexec)
		xclose(0);
	}

	setcopy(STRstatus, STR0, VAR_READWRITE);

	/*
	 * This mess is the necessary kludge to handle the prefix builtins:
	 * nice, nohup, time.  These commands can also be used by themselves,
	 * and this is not handled here. This will also work when loops are
	 * parsed.
	 */
	while (t->t_dtyp == NODE_COMMAND)
	    if (eq(t->t_dcom[0], STRnice)) {
		if (t->t_dcom[1]) {
		    if (strchr("+-", t->t_dcom[1][0])) {
			if (t->t_dcom[2]) {
			    setname("nice");
			    t->t_nice = (unsigned char)getn(t->t_dcom[1]);
			    lshift(t->t_dcom, 2);
			    t->t_dflg |= F_NICE;
			}
			else
			    break;
		    }
		    else {
			t->t_nice = 4;
			lshift(t->t_dcom, 1);
			t->t_dflg |= F_NICE;
		    }
		}
		else
		    break;
	    }
	    else if (eq(t->t_dcom[0], STRnohup)) {
		if (t->t_dcom[1]) {
		    t->t_dflg |= F_NOHUP;
		    lshift(t->t_dcom, 1);
		}
		else
		    break;
	    }
	    else if (eq(t->t_dcom[0], STRhup)) {
		if (t->t_dcom[1]) {
		    t->t_dflg |= F_HUP;
		    lshift(t->t_dcom, 1);
		}
		else
		    break;
	    }
	    else if (eq(t->t_dcom[0], STRtime)) {
		if (t->t_dcom[1]) {
		    t->t_dflg |= F_TIME;
		    lshift(t->t_dcom, 1);
		}
		else
		    break;
	    }
#ifdef F_VER
	    else if (eq(t->t_dcom[0], STRver))
		if (t->t_dcom[1] && t->t_dcom[2]) {
		    setname("ver");
		    t->t_systype = getv(t->t_dcom[1]);
		    lshift(t->t_dcom, 2);
		    t->t_dflg |= F_VER;
		}
		else
		    break;
#endif  /* F_VER */
	    else
		break;

	/* is it a command */
	if (t->t_dtyp == NODE_COMMAND) {
	    /*
	     * Check if we have a builtin function and remember which one.
	     */
	    bifunc = isbfunc(t);
 	    if (noexec) {
		/*
		 * Continue for builtins that are part of the scripting language
		 */
		if (bifunc == NULL)
		    break;
		if (bifunc->bfunct != (bfunc_t)dobreak	&&
		    bifunc->bfunct != (bfunc_t)docontin	&&
		    bifunc->bfunct != (bfunc_t)doelse	&&
		    bifunc->bfunct != (bfunc_t)doend	&&
		    bifunc->bfunct != (bfunc_t)doforeach&&
		    bifunc->bfunct != (bfunc_t)dogoto	&&
		    bifunc->bfunct != (bfunc_t)doif	&&
		    bifunc->bfunct != (bfunc_t)dorepeat	&&
		    bifunc->bfunct != (bfunc_t)doswbrk	&&
		    bifunc->bfunct != (bfunc_t)doswitch	&&
		    bifunc->bfunct != (bfunc_t)dowhile	&&
		    bifunc->bfunct != (bfunc_t)dozip)
		    break;
	    }
	}
	else {			/* not a command */
	    bifunc = NULL;
	    if (noexec)
		break;
	}

	/* 
	 * GrP Executing a command - run jobcmd hook
	 * Don't run for builtins
	 * Don't run if we're not in a tty
	 * Don't run if we're not really executing 
	 */
	/*
	 * CR  -  Charles Ross Aug 2005
	 * added "isoutatty".
	 * The new behavior is that the jobcmd won't be executed
	 * if stdout (SHOUT) isnt attached to a tty.. IE when
	 * redirecting, or using backquotes etc..
	 */
	if (t->t_dtyp == NODE_COMMAND && !bifunc && !noexec && intty && isoutatty) {
	    Char *cmd = unparse(t);

	    cleanup_push(cmd, xfree);
	    job_cmd(cmd);
	    cleanup_until(cmd);
	}
	   
	/*
	 * We fork only if we are timed, or are not the end of a parenthesized
	 * list and not a simple builtin function. Simple meaning one that is
	 * not pipedout, niced, nohupped, or &'d. It would be nice(?) to not
	 * fork in some of these cases.
	 */
#ifdef BACKPIPE
	/*
	 * Can't have NOFORK for the tail of a pipe - because it is not the
	 * last command spawned (even if it is at the end of a parenthesised
	 * list).
	 */
	if (t->t_dflg & F_PIPEIN)
	    t->t_dflg &= ~(F_NOFORK);
#else
	/*
	 * "command | builtin" may cause major misbehaviour as noted in
	 * in the BUGS file entry
	 * Subject: Redirected input to built-in functions misbehaves badly
	 * forking when the builtin is the end of the pipe corrects the
	 * problem.
	 */
	if (bifunc && (t->t_dflg & F_PIPEIN))
	    t->t_dflg &= ~(F_NOFORK);
#endif /* BACKPIPE */
	/*
	 * Prevent forking cd, pushd, popd, chdir cause this will cause the
	 * shell not to change dir! (XXX: but only for nice?)
	 */
	if (bifunc && (bifunc->bfunct == (bfunc_t)dochngd ||
		       bifunc->bfunct == (bfunc_t)dopushd ||
		       bifunc->bfunct == (bfunc_t)dopopd))
	    t->t_dflg &= ~(F_NICE);

	if (((t->t_dflg & F_TIME) || ((t->t_dflg & F_NOFORK) == 0 &&
	     (!bifunc || t->t_dflg &
	      (F_PIPEOUT | F_AMPERSAND | F_NICE | F_NOHUP | F_HUP)))) ||
	/*
	 * We have to fork for eval too.
	 */
	    (bifunc && (t->t_dflg & F_PIPEIN) != 0 &&
	     bifunc->bfunct == (bfunc_t)doeval)) {
#ifdef VFORK
	    if (t->t_dtyp == NODE_PAREN ||
		t->t_dflg & (F_REPEAT | F_AMPERSAND) || bifunc)
#endif /* VFORK */
	    {
		forked++;
		/*
		 * We need to block SIGCHLD here, so that if the process does
		 * not die before we can set the process group
		 */
		if (wanttty >= 0 && !nosigchld) {
		    sigemptyset(&set);
		    sigaddset(&set, SIGCHLD);
		    (void)sigprocmask(SIG_BLOCK, &set, &csigset);

		    nosigchld = 1;
		}

		pid = pfork(t, wanttty);
		if (pid == 0 && nosigchld) {
		    sigprocmask(SIG_SETMASK, &csigset, NULL);
		    nosigchld = 0;
		}
		else if (pid != 0 && (t->t_dflg & F_AMPERSAND))
		    backpid = pid;
	    }

#ifdef VFORK
	    else {
		int     ochild, osetintr, ohaderr, odidfds;
		int     oSHIN, oSHOUT, oSHDIAG, oOLDSTD, otpgrp;
		int     oisoutatty, oisdiagatty;
		sigset_t oset, ocsigset;
# ifndef CLOSE_ON_EXEC
		int     odidcch;
# endif  /* !CLOSE_ON_EXEC */

		/*
		 * Prepare for the vfork by saving everything that the child
		 * corrupts before it exec's. Note that in some signal
		 * implementations which keep the signal info in user space
		 * (e.g. Sun's) it will also be necessary to save and restore
		 * the current sigvec's for the signals the child touches
		 * before it exec's.
		 */

		/*
		 * Sooooo true... If this is a Sun, save the sigvec's. (Skip
		 * Gilbrech - 11/22/87)
		 */
# ifdef SAVESIGVEC
		struct sigaction savesv[NSIGSAVED];
		sigset_t savesm;

# endif /* SAVESIGVEC */
		if (wanttty >= 0 && !nosigchld && !noexec) {
		    sigemptyset(&set);
		    sigaddset(&set, SIGCHLD);
		    (void)sigprocmask(SIG_BLOCK, &set, &csigset);
		    nosigchld = 1;
		}
		sigemptyset(&set);
		sigaddset(&set, SIGCHLD);
		sigaddset(&set, SIGINT);
		(void)sigprocmask(SIG_BLOCK, &set, &oset);
		ochild = child;
		osetintr = setintr;
		ohaderr = haderr;
		odidfds = didfds;
# ifndef CLOSE_ON_EXEC
		odidcch = didcch;
# endif /* !CLOSE_ON_EXEC */
		oSHIN = SHIN;
		oSHOUT = SHOUT;
		oSHDIAG = SHDIAG;
		oOLDSTD = OLDSTD;
		otpgrp = tpgrp;
		oisoutatty = isoutatty;
		oisdiagatty = isdiagatty;
		ocsigset = csigset;
		onosigchld = nosigchld;
		Vsav = Vdp = 0;
		Vexpath = 0;
		Vt = 0;
# ifdef SAVESIGVEC
		savesigvec(savesv, savesm);
# endif /* SAVESIGVEC */
		if (use_fork)
		    pid = fork();
		else
		    pid = vfork();

		if (pid < 0) {
# ifdef SAVESIGVEC
		    restoresigvec(savesv, savesm);
# endif /* SAVESIGVEC */
		    sigprocmask(SIG_SETMASK, &oset, NULL);
		    stderror(ERR_NOPROC);
		}
		forked++;
		if (pid) {	/* parent */
# ifdef SAVESIGVEC
		    restoresigvec(savesv, savesm);
# endif /* SAVESIGVEC */
		    child = ochild;
		    setintr = osetintr;
		    haderr = ohaderr;
		    didfds = odidfds;
		    SHIN = oSHIN;
# ifndef CLOSE_ON_EXEC
		    didcch = odidcch;
# endif /* !CLOSE_ON_EXEC */
		    SHOUT = oSHOUT;
		    SHDIAG = oSHDIAG;
		    OLDSTD = oOLDSTD;
		    tpgrp = otpgrp;
		    isoutatty = oisoutatty;
		    isdiagatty = oisdiagatty;
		    csigset = ocsigset;
		    nosigchld = onosigchld;

		    xfree(Vsav);
		    Vsav = 0;
		    xfree(Vdp);
		    Vdp = 0;
		    xfree(Vexpath);
		    Vexpath = 0;
		    blk_cleanup(Vt);
		    Vt = 0;
		    /* this is from pfork() */
		    palloc(pid, t);
		    sigprocmask(SIG_SETMASK, &oset, NULL);
		}
		else {		/* child */
		    /* this is from pfork() */
		    pid_t pgrp;
		    int    ignint = 0;
		    if (nosigchld) {
			sigprocmask(SIG_SETMASK, &csigset, NULL);
			nosigchld = 0;
		    }

		    if (setintr)
			ignint = (tpgrp == -1 && (t->t_dflg & F_NOINTERRUPT))
				|| (gointr && eq(gointr, STRminus));
		    pgrp = pcurrjob ? pcurrjob->p_jobid : getpid();
		    child++;
		    if (setintr) {
			setintr = 0;
/*
 * casts made right for SunOS 4.0 by Douglas C. Schmidt
 * <*****@*****.**>
 * (thanks! -- PWP)
 *
 * ignint ifs cleaned by Johan Widen <[email protected]>
 * (thanks again)
 */
			if (ignint) {
			    (void) signal(SIGINT, SIG_IGN);
			    (void) signal(SIGQUIT, SIG_IGN);
			}
			else {
			    (void) signal(SIGINT, vffree);
			    (void) signal(SIGQUIT, SIG_DFL);
			}
# ifdef BSDJOBS
			if (wanttty >= 0) {
			    (void) signal(SIGTSTP, SIG_DFL);
			    (void) signal(SIGTTIN, SIG_DFL);
			    (void) signal(SIGTTOU, SIG_DFL);
			}
# endif /* BSDJOBS */

			sigaction(SIGTERM, &parterm, NULL);
		    }
		    else if (tpgrp == -1 &&
			     (t->t_dflg & F_NOINTERRUPT)) {
			(void) signal(SIGINT, SIG_IGN);
			(void) signal(SIGQUIT, SIG_IGN);
		    }

		    pgetty(wanttty, pgrp);

		    if (t->t_dflg & F_NOHUP)
			(void) signal(SIGHUP, SIG_IGN);
		    if (t->t_dflg & F_HUP)
			(void) signal(SIGHUP, SIG_DFL);
		    if (t->t_dflg & F_NICE) {
			int nval = SIGN_EXTEND_CHAR(t->t_nice);
# if defined(HAVE_SETPRIORITY) && defined(PRIO_PROCESS)
			if (setpriority(PRIO_PROCESS, 0, nval) == -1 && errno)
				stderror(ERR_SYSTEM, "setpriority",
				    strerror(errno));
# else /* !HAVE_SETPRIORITY || !PRIO_PROCESS */
			(void) nice(nval);
# endif /* HAVE_SETPRIORITY && PRIO_PROCESS */
		    }
# ifdef F_VER
		    if (t->t_dflg & F_VER) {
			tsetenv(STRSYSTYPE, t->t_systype ? STRbsd43 : STRsys53);
			dohash(NULL, NULL);
		    }
# endif /* F_VER */
		}

	    }
#endif /* VFORK */
	}
	if (pid != 0) {
	    /*
	     * It would be better if we could wait for the whole job when we
	     * knew the last process had been started.  Pwait, in fact, does
	     * wait for the whole job anyway, but this test doesn't really
	     * express our intentions.
	     */
#ifdef BACKPIPE
	    if (didfds == 0 && t->t_dflg & F_PIPEOUT) {
		xclose(pipeout[0]);
		xclose(pipeout[1]);
	    }
	    if ((t->t_dflg & F_PIPEIN) != 0)
		break;
#else /* !BACKPIPE */
	    if (didfds == 0 && t->t_dflg & F_PIPEIN) {
		xclose(pipein[0]);
		xclose(pipein[1]);
	    }
	    if ((t->t_dflg & F_PIPEOUT) != 0)
		break;
#endif /* BACKPIPE */

	    if (nosigchld) {
		sigprocmask(SIG_SETMASK, &csigset, NULL);
		nosigchld = 0;
	    }
	    if ((t->t_dflg & F_AMPERSAND) == 0)
		pwait();
	    break;
	}

	doio(t, pipein, pipeout);
#ifdef BACKPIPE
	if (t->t_dflg & F_PIPEIN) {
	    xclose(pipein[0]);
	    xclose(pipein[1]);
	}
#else /* !BACKPIPE */
	if (t->t_dflg & F_PIPEOUT) {
	    xclose(pipeout[0]);
	    xclose(pipeout[1]);
	}
#endif /* BACKPIPE */
	/*
	 * Perform a builtin function. If we are not forked, arrange for
	 * possible stopping
	 */
	if (bifunc) {
	    if (forked) {
		func(t, bifunc);
		exitstat();
	    } else {
		jmp_buf_t oldexit;
		int ohaderr = haderr;

		getexit(oldexit);
		if (setexit() == 0)
		    func(t, bifunc);
		resexit(oldexit);
		haderr = ohaderr;

		if (adrof(STRprintexitvalue)) {
		    int rv = getn(varval(STRstatus));
		    if (rv != 0)
			xprintf(CGETS(17, 2, "Exit %d\n"), rv);
		}
	    }
	    break;
	}
	if (t->t_dtyp != NODE_PAREN) {
	    doexec(t, do_glob);
	    /* NOTREACHED */
	}
	/*
	 * For () commands must put new 0,1,2 in FSH* and recurse
	 */
	if ((OLDSTD = dcopy(0, FOLDSTD)) >= 0)
	    (void)close_on_exec(OLDSTD, 1);
	if ((SHOUT = dcopy(1, FSHOUT)) >= 0) {
	    (void)close_on_exec(SHOUT, 1);
	    isoutatty = isatty(SHOUT);
	}
	if ((SHDIAG = dcopy(2, FSHDIAG)) >= 0) {
	    (void)close_on_exec(SHDIAG, 1);
	    isdiagatty = isatty(SHDIAG);
    	}
	xclose(SHIN);
	SHIN = -1;
#ifndef CLOSE_ON_EXEC
	didcch = 0;
#else
	(void) close_on_exec(FSHOUT, 1);
	(void) close_on_exec(FSHDIAG, 1);
	(void) close_on_exec(FOLDSTD, 1);
#endif /* !CLOSE_ON_EXEC */
	didfds = 0;
	wanttty = -1;
	t->t_dspr->t_dflg |= t->t_dflg & (F_NOINTERRUPT | F_BACKQ);
	execute(t->t_dspr, wanttty, NULL, NULL, do_glob);
	exitstat();

    case NODE_PIPE:
#ifdef BACKPIPE
	t->t_dcdr->t_dflg |= F_PIPEIN | (t->t_dflg &
	    (F_PIPEOUT | F_AMPERSAND | F_NOFORK | F_NOINTERRUPT | F_BACKQ));
	execute(t->t_dcdr, wanttty, pv, pipeout, do_glob);
	t->t_dcar->t_dflg |= F_PIPEOUT | (t->t_dflg &
	    (F_PIPEIN | F_AMPERSAND | F_STDERR | F_NOINTERRUPT | F_BACKQ));
	execute(t->t_dcar, wanttty, pipein, pv, do_glob);
#else /* !BACKPIPE */
	t->t_dcar->t_dflg |= F_PIPEOUT | (t->t_dflg &
	    (F_PIPEIN | F_AMPERSAND | F_STDERR | F_NOINTERRUPT | F_BACKQ));
	execute(t->t_dcar, wanttty, pipein, pv, do_glob);
	t->t_dcdr->t_dflg |= F_PIPEIN | (t->t_dflg &
	    (F_PIPEOUT | F_AMPERSAND | F_NOFORK | F_NOINTERRUPT | F_BACKQ));
	execute(t->t_dcdr, wanttty, pv, pipeout, do_glob);
#endif /* BACKPIPE */
	break;

    case NODE_LIST:
	if (t->t_dcar) {
	    t->t_dcar->t_dflg |= t->t_dflg & (F_NOINTERRUPT | F_BACKQ);
	    execute(t->t_dcar, wanttty, NULL, NULL, do_glob);
	    /*
	     * In strange case of A&B make a new job after A
	     */
	    if (t->t_dcar->t_dflg & F_AMPERSAND && t->t_dcdr &&
		(t->t_dcdr->t_dflg & F_AMPERSAND) == 0)
		pendjob();
	}
	if (t->t_dcdr) {
	    t->t_dcdr->t_dflg |= t->t_dflg &
		(F_NOFORK | F_NOINTERRUPT | F_BACKQ);
	    execute(t->t_dcdr, wanttty, NULL, NULL, do_glob);
	}
	break;

    case NODE_OR:
    case NODE_AND:
	if (t->t_dcar) {
	    t->t_dcar->t_dflg |= t->t_dflg & (F_NOINTERRUPT | F_BACKQ);
	    execute(t->t_dcar, wanttty, NULL, NULL, do_glob);
	    if ((getn(varval(STRstatus)) == 0) !=
		(t->t_dtyp == NODE_AND)) {
		return;
	    }
	}
	if (t->t_dcdr) {
	    t->t_dcdr->t_dflg |= t->t_dflg &
		(F_NOFORK | F_NOINTERRUPT | F_BACKQ);
	    execute(t->t_dcdr, wanttty, NULL, NULL, do_glob);
	}
	break;

    default:
	break;
    }
    /*
     * Fall through for all breaks from switch
     * 
     * If there will be no more executions of this command, flush all file
     * descriptors. Places that turn on the F_REPEAT bit are responsible for
     * doing donefds after the last re-execution
     */
    if (didfds && !(t->t_dflg & F_REPEAT))
	donefds();
}
Example #19
0
void tangent_linear_code::unparse(ast_vertex* v, ofstream& tgtfile, int indent) {
  if (!v) return;
  list<ast_vertex*>::const_iterator it;
  switch (v->type) {
    case CODE_ASTV: {
      it=v->children.begin();
      unparse(*it,tgtfile,indent);
      unparse(*(++it),tgtfile,indent);
      break;
    }
    case SEQUENCE_OF_SUBROUTINES_ASTV: {
      for (it=v->children.begin();it!=v->children.end();it++) 
        unparse((*it),tgtfile,indent);
      break;
    }
    case SUBROUTINE_ASTV: {

      tgtfile << "void " << tl_var_prefix;
      it=v->children.begin();
      (*it)->unparse(tgtfile,indent);
      tgtfile << "(";
      unparse(*(++it),tgtfile,indent);
      tgtfile << ")\n";
      tgtfile << "{\n";
      indent+=3;
      unparse(*(++it),tgtfile,indent);
      unparse(*(++it),tgtfile,indent);
      indent-=3;
      tgtfile << "}\n";
      break;
    }
    case SUBROUTINE_ARG_LIST_ASTV: {
      int s=1;
      for (it=v->children.begin();it!=v->children.end();it++,s++) {
        switch (static_cast<symbol_ast_vertex*>(*it)->sym->type) {
          case FLOAT_ST : {
            if (static_cast<symbol_ast_vertex*>(*it)->sym->shape==0) 
              tgtfile << "double& ";
            else {
              tgtfile << "double";
              for (int i=0; i<static_cast<symbol_ast_vertex*>(*it)->sym->shape; i++) 
                tgtfile << "*";
              tgtfile << " ";
            }
            break;
          }
          case INT_ST : {
            if (static_cast<symbol_ast_vertex*>(*it)->sym->shape==0) {
              if (static_cast<symbol_ast_vertex*>(*it)->sym->intent==0)
                tgtfile << "int& ";
              else
                tgtfile << "int ";
            }
            else {
              tgtfile << "int";
              for (int i=0; i<static_cast<symbol_ast_vertex*>(*it)->sym->shape; i++) 
                tgtfile << "*";
              tgtfile << " ";
            }
            break;
          }
          default : {
            cerr << "ERROR: Unknown Symbol Type " << static_cast<symbol_ast_vertex*>(*it)->sym->type << endl;
            assert(false);
          }
        }
        (*it)->unparse(tgtfile,indent);
        if (static_cast<symbol_ast_vertex*>(*it)->sym->type==FLOAT_ST) {
          tgtfile << ", ";
          if (static_cast<symbol_ast_vertex*>(*it)->sym->shape==0) 
            tgtfile << "double& "  << tl_var_prefix;
          else {
            tgtfile << "double";
            for (int i=0; i<static_cast<symbol_ast_vertex*>(*it)->sym->shape; i++) 
              tgtfile << "*";
            tgtfile << " " << tl_var_prefix;
          }
          (*it)->unparse(tgtfile,indent);
        }
        if (s<v->children.size()) 
          tgtfile << ", ";
      }
      break;
    }
    case SEQUENCE_OF_DECLARATIONS_ASTV: {
      for (it=v->children.begin();it!=v->children.end();it++) {
        static_cast<symbol_ast_vertex*>(*it)->sym->unparse(tgtfile,"double",indent);
        if (static_cast<symbol_ast_vertex*>(*it)->sym->type==FLOAT_ST) {
          symbol* sym=new symbol;
          sym->name=tl_var_prefix+static_cast<symbol_ast_vertex*>(*it)->sym->name;
          sym->kind=static_cast<symbol_ast_vertex*>(*it)->sym->kind;
          sym->type=static_cast<symbol_ast_vertex*>(*it)->sym->type;
          sym->shape=static_cast<symbol_ast_vertex*>(*it)->sym->shape;
          if (static_cast<symbol_ast_vertex*>(*it)->sym->shape==1) {
            sym->val=static_cast<symbol_ast_vertex*>(*it)->sym->val;
          } else {
            sym->val=string("0");
          }
          sym->unparse(tgtfile,"double",indent);
          delete sym;
        }
      }
      break;
    }
    case SEQUENCE_OF_STATEMENTS_ASTV: {
      for (it=v->children.begin();it!=v->children.end();it++) 
        unparse((*it),tgtfile,indent);
      break;
    }
    case IF_STATEMENT_ASTV: {
      for (int i=0;i<indent;i++) 
        tgtfile << " ";
      tgtfile << "if (";
      it=v->children.begin();
      (*it)->unparse(tgtfile,indent);
      tgtfile << ") {\n";
      indent+=3;
      unparse((*(++it)),tgtfile,indent);
      indent-=3;
      for (int i=0;i<indent;i++) 
        tgtfile << " ";
      tgtfile << "}\n";
      if (v->children.size()==3) {
        for (int i=0;i<indent;i++) 
          tgtfile << " ";
        tgtfile << "else {\n";
        indent+=3;
        unparse(*(++it),tgtfile,indent);
        indent-=3;
        for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << "}\n";
      }
      break;
    }
    case WHILE_STATEMENT_ASTV: {
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << "while (";
      it=v->children.begin();
      (*it)->unparse(tgtfile,indent);
      tgtfile << ") {\n";
      indent+=3;
      unparse((*(++it)),tgtfile,indent);
      indent-=3;
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << "}\n";
      break;
    }
    case ASSIGNMENT_ASTV: {
      if (static_cast<scalar_memref_ast_vertex*>(*(v->children.begin()))->base->type==FLOAT_ST) {
          unparse((*(++(v->children.begin()))),tgtfile,indent);
          for (int i=0;i<indent;i++) tgtfile << " ";
          tgtfile << tl_var_prefix;
          (*(v->children.begin()))->unparse(tgtfile,0);
          tgtfile << "="
                   << tl_var_prefix << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() << ";";
          tgtfile << "\n"; 
          for (int i=0;i<indent;i++) tgtfile << " ";
          (*(v->children.begin()))->unparse(tgtfile,0);
          tgtfile << "="
                   << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() << ";";
          tgtfile << "\n"; 
      } else {
          v->unparse(tgtfile,indent);
      }  
      break; 
    }
    case SUBROUTINE_CALL_ASTV: {
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << tl_var_prefix;
      (*(v->children.begin()))->unparse(tgtfile,indent);
      tgtfile << "(";
      for (it=(*(++(v->children.begin())))->children.begin();it!=(*(++(v->children.begin())))->children.end();it++) {
        if (it!=(*(++(v->children.begin())))->children.begin())
          tgtfile << ',';
        (*it)->unparse(tgtfile,indent);
        if (static_cast<scalar_memref_ast_vertex*>(*(it))->base->type==FLOAT_ST) {
          tgtfile << "," << tl_var_prefix;
          (*it)->unparse(tgtfile,indent);
        }
      }
      tgtfile << ");\n";
      break;
    }
    // y=x1+x2
    case ADD_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      unparse((*(++(v->children.begin()))),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "="
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x1
                << "+" 
                << tl_var_prefix << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() // d_x2
                << ";";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=" 
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x1
               << "+" 
               << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() // x2
               << ";";
      tgtfile << endl; 
      break;
    }
    // y=x1-x2
    case SUB_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      unparse((*(++(v->children.begin()))),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "=" 
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x1
                << "-" 
                << tl_var_prefix << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() // d_x2
                << ";";

      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=" 
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x1
               << "-" 
               << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() // x2
               << ";";
      tgtfile << endl; 
      break;
    }
    // y=x1*x2
    case MUL_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      unparse((*(++(v->children.begin()))),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "=" 
                << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() // x2
                << "*" 
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x1
                << "+" 
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x1
                << "*" 
                << tl_var_prefix << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() // d_x2
                << ";";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=" 
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x1
               << "*" 
               << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() // x2
               << ";";
      tgtfile << endl; 
      break;
    }
    // y=x1/x2
    case DIV_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      unparse((*(++(v->children.begin()))),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=1/" 
               << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() // x2
               << "; ";
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "=" 
                << sac_var_prefix << v->sac_var_idx() // y
                << "*" 
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x1
                << "-" 
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x1
                << "*" 
                << sac_var_prefix << v->sac_var_idx() // y
                << "*" 
                << sac_var_prefix << v->sac_var_idx() // y
                << "*" 
                << tl_var_prefix << sac_var_prefix << (*(++(v->children.begin())))->sac_var_idx() // d_x2
                << ";";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=" 
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x1
               << "*" 
               << sac_var_prefix << v->sac_var_idx() // y
               << ";";
      tgtfile << endl; 
      break;
    }
    // y=(x);
    case PAR_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "=" 
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                << ";";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
              << "=" 
              << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
              << ";";
      tgtfile << endl; 
      break;
    }
    // y=sin(x);
    case SIN_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "=" 
                << "cos(" 
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                << ")*" 
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                << ";";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
              << "=sin(" 
              << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
              << ");";
      tgtfile << endl; 
      break;
    }
    // y=cos(x);
    case COS_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                 << "=" 
                 << "0-sin(" 
                 << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                 << ")*" 
                 << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                 << ";";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=cos(" 
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
               << ");";
      tgtfile << endl; 
      break;
    }
    // y=tan(x);
    case TAN_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y
                 << "=1/("
                 << "cos("
                 << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                 << ")*"
                 << "cos("
                 << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                 << "))*"
                 << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                 << ";";
      tgtfile << endl;
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y
               << "=tan("
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
               << ");";
      tgtfile << endl;
      break;
    }

    // y=exp(x);
    case EXP_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
              << "=exp(" 
              << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
              << ");";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "=" 
                << sac_var_prefix << v->sac_var_idx() // y
                << "*" 
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                << ";";
      tgtfile << endl; 
      break;
    }
    // y=sqrt(x);
    case SQRT_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "=" 
                << "1/(2*sqrt(" 
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                << "))*" 
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                << ";";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=sqrt(" 
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
               << ");";
      tgtfile << endl; 
      break;
    }
    // y=atan(x);
    case ATAN_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "=" 
                << "1/(1+" 
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                << "*" 
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                << ")*" 
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                << ";";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=atan(" 
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
               << ");";
      tgtfile << endl; 
      break;
    }
    // y=log(x);
    case LOG_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y
                << "="
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                << "/"
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                << ";";
      tgtfile << endl;
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y
               << "=log("
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
               << ");";
      tgtfile << endl;
      break;
    }

    // y=pow(x,c); c integer
    case POW_I_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y as aux
                << "=" 
                << static_cast<symbol_ast_vertex*>(*(++(v->children.begin())))->sym->name // c
                << "-1; ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
                << "=" 
                << static_cast<symbol_ast_vertex*>(*(++(v->children.begin())))->sym->name // c
                << "*pow(" 
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                << "," 
                << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y as aux
                << ")*" 
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                << ";";
      tgtfile << endl; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=pow(" 
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
               << ","
               << static_cast<symbol_ast_vertex*>(*(++(v->children.begin())))->sym->name // c
               << ");";
      tgtfile << endl; 
      break;
    }
    // y=pow(x,z)
    case POW_F_EXPRESSION_ASTV: {
      unparse((*(v->children.begin())),tgtfile,indent);
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y
               << "=pow("
               << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
               << ","
               << static_cast<symbol_ast_vertex*>(*(++(v->children.begin())))->sym->name // z
               << ");";
      tgtfile << endl;
      for (int i=0;i<indent;i++) tgtfile << " ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y as aux
                << "="
                << static_cast<symbol_ast_vertex*>(*(++(v->children.begin())))->sym->name // z
                << "-1; ";
        tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y
                << "="
                << static_cast<symbol_ast_vertex*>(*(++(v->children.begin())))->sym->name // z
                << "*pow("
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                << ","
                << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y as aux
                << ")*"
                << tl_var_prefix << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // d_x
                << "+"
                << sac_var_prefix << v->sac_var_idx() // y
                << "*log("
                << sac_var_prefix << (*(v->children.begin()))->sac_var_idx() // x
                << ")*"
                << tl_var_prefix << static_cast<symbol_ast_vertex*>(*(++(v->children.begin())))->sym->name // d_z
                << ";";
      tgtfile << endl;
      break;
    }

    // y=x;
    case SCALAR_MEMREF_ASTV: {
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
               << "="; 
      if (static_cast<scalar_memref_ast_vertex*>(v)->base->type==FLOAT_ST)
        tgtfile  << tl_var_prefix << static_cast<scalar_memref_ast_vertex*>(v)->base->name; // d_x
      else 
        tgtfile << "0";
      tgtfile << ";\n"; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=" 
               << static_cast<scalar_memref_ast_vertex*>(v)->base->name // x
               << ";";
      tgtfile << "\n"; 
      break;
    }
    // y=x[i]...[j];
    case ARRAY_MEMREF_ASTV: {
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y
               << "=";
      if (static_cast<array_memref_ast_vertex*>(v)->base->type==FLOAT_ST) {
        tgtfile << tl_var_prefix << static_cast<array_memref_ast_vertex*>(v)->base->name; // d_x
        for (int i=0;i<static_cast<array_memref_ast_vertex*>(v)->dim;i++)
          tgtfile << "["
                  << static_cast<array_memref_ast_vertex*>(v)->offsets[i]->name // i
                   << "]";
      }
      else 
        tgtfile << "0";
      tgtfile << ";\n"; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y
               << "="
               << static_cast<array_memref_ast_vertex*>(v)->base->name; // x
      for (int i=0;i<static_cast<array_memref_ast_vertex*>(v)->dim;i++)
        tgtfile << "["
                 << static_cast<array_memref_ast_vertex*>(v)->offsets[i]->name // i
                 << "]";
      tgtfile << ";";
      tgtfile << "\n"; 
      break;
    }
    case CONSTANT_ASTV: {
      // tangent-linear code
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << tl_var_prefix << sac_var_prefix << v->sac_var_idx() // d_y 
               << "=0;"; 
      tgtfile << "\n"; 
      for (int i=0;i<indent;i++) tgtfile << " ";
      tgtfile << sac_var_prefix << v->sac_var_idx() // y 
               << "=" 
               << static_cast<const_ast_vertex*>(v)->value->name
               << ";";
      tgtfile << "\n"; 
      break;
    }
    default: {
      cerr << "Unknown ast vertex type " << v->type;
      exit(-1);
      break;
    }
  }
}
Example #20
0
void unparse(std::ostream& out, const Node* n) {
    switch (n->Type) {
    case Node::REGEXP:
        if (!n->Left) {
            return;
        }

        unparse(out, n->Left);
        break;

    case Node::ALTERNATION:
        unparse(out, n->Left);
        out << '|';
        unparse(out, n->Right);
        break;

    case Node::CONCATENATION:
        if (n->Left->Type == Node::ALTERNATION) {
            out << '(';
            unparse(out, n->Left);
            out << ')';
        }
        else {
            unparse(out, n->Left);
        }

        if (n->Right->Type == Node::ALTERNATION) {
            out << '(';
            unparse(out, n->Right);
            out << ')';
        }
        else {
            unparse(out, n->Right);
        }
        break;

    case Node::REPETITION:
        open_paren(out, n);
        unparse(out, n->Left);
        close_paren(out, n);
        repetition(out, n->Min, n->Max);
        break;

    case Node::REPETITION_NG:
        open_paren(out, n);
        unparse(out, n->Left);
        close_paren(out, n);
        repetition(out, n->Min, n->Max);
        out << '?';
        break;

    case Node::DOT:
        out << '.';
        break;

    case Node::CHAR_CLASS:
        out << '[' << byteSetToCharacterClass(n->Bits) << ']';
        break;

    case Node::LITERAL:
        out << byteToCharacterString(n->Val);
        break;

    default:
        // WTF?
        throw std::logic_error(boost::lexical_cast<std::string>(n->Type));
    }
}
Example #21
0
int quorum_config(ConfigArgs *c) {
	int i, type;
	slap_quorum_t *q = c->be->bd_quorum;

	assert(quorum_list != QR_POISON);
	if (c->op == SLAP_CONFIG_EMIT) {
		if (q) {
			if ((q->flags & QR_ALL_LINKS) != 0
			&& value_add_one_str(&c->rvalue_vals, "all-links"))
				return 1;
			if ((q->flags & QR_AUTO_SIDS) != 0
			&& value_add_one_str(&c->rvalue_vals, "auto-sids"))
				return 1;
			if ((q->flags & QR_AUTO_RIDS) != 0
			&& value_add_one_str(&c->rvalue_vals, "auto-rids"))
				return 1;
			if (q->qr_requirements
			&& (unparse(&c->rvalue_vals, q, QR_DEMAND_RID, "require-rids")
			 || unparse(&c->rvalue_vals, q, QR_DEMAND_SID, "require-sids")
			 || unparse(&c->rvalue_vals, q, QR_VOTED_RID, "vote-rids")
			 || unparse(&c->rvalue_vals, q, QR_VOTED_SID, "vote-sids")))
				return 1;
			if (q->qr_syncrepl_limit > 0
			&& (value_add_one_str(&c->rvalue_vals, "limit-concurrent-refresh")
			 || value_add_one_int(&c->rvalue_vals, q->qr_syncrepl_limit)))
				return 1;
		}
		return 0;
	} else if ( c->op == LDAP_MOD_DELETE ) {
		lock();
		if (q) {
			q->flags = 0;
			if(q->qr_requirements) {
				ch_free(q->qr_requirements);
				q->qr_requirements = NULL;
				c->be->bd_quorum_cache = 1;
				Debug( LDAP_DEBUG_SYNC, "syncrep_quorum: %s requirements-list cleared\n",
					   q->qr_cluster );
			}
			if (q->qr_syncrepl_limit) {
				Debug( LDAP_DEBUG_SYNC, "syncrep_quorum: %s limit-concurrent-refresh cleared\n",
					   q->qr_cluster );
				q->qr_syncrepl_limit = 0;
			}
		}
		unlock();
		return 0;
	}

	lock();
	if (! q) {
		quorum_be_init(c->be);
		q = c->be->bd_quorum;
	}

	type = -1;
	for( i = 1; i < c->argc; i++ ) {
		int	id;
		if (strcasecmp(c->argv[i], "all-links") == 0) {
			type = -1;
			if (! (q->flags & QR_ALL_LINKS)) {
				q->flags |= QR_ALL_LINKS;
				quorum_invalidate(c->be);
			}
		} else if (strcasecmp(c->argv[i], "auto-sids") == 0) {
			type = -1;
			if (require_auto_sids(q))
				quorum_invalidate(c->be);
		} else if (strcasecmp(c->argv[i], "auto-rids") == 0) {
			type = -1;
			if (require_auto_rids(q))
				quorum_invalidate(c->be);
		} else if (strcasecmp(c->argv[i], "vote-sids") == 0)
			type = QR_VOTED_SID;
		else if (strcasecmp(c->argv[i], "vote-rids") == 0)
			type = QR_VOTED_RID;
		else if (strcasecmp(c->argv[i], "require-sids") == 0)
			type = QR_DEMAND_SID;
		else if (strcasecmp(c->argv[i], "require-rids") == 0)
			type = QR_DEMAND_RID;
		else if (strcasecmp(c->argv[i], "limit-concurrent-refresh") == 0) {
			if (q->qr_syncrepl_limit) {
				snprintf( c->cr_msg, sizeof( c->cr_msg ),
					"<%s> limit-concurrent-refresh was already defined for %s as %d",
					c->argv[i], q->qr_cluster,
					q->qr_syncrepl_limit );
				unlock();
				Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg );
				return 1;
			}
#define QR_FAKETYPE_max_concurrent_refresh -2
			type = QR_FAKETYPE_max_concurrent_refresh;
			q->qr_syncrepl_limit = 1;
		} else if (type == QR_FAKETYPE_max_concurrent_refresh) {
			int n;
			if ( lutil_atoi( &n, c->argv[i]) || n < 1 || n > QR_SYNCREPL_MAX ) {
				snprintf( c->cr_msg, sizeof( c->cr_msg ),
					"<%s> illegal limit-concurrent-refresh for %s (maximum is %d)",
					c->argv[i], q->qr_cluster,
					QR_SYNCREPL_MAX );
				unlock();
				Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg );
				return 1;
			}
			q->qr_syncrepl_limit = n;
			type = -1;
		} else if (type < 0) {
			snprintf( c->cr_msg, sizeof( c->cr_msg ),
				"<%s> mode-key must precede an ID for %s quorum-requirements",
				c->argv[i], q->qr_cluster );
			unlock();
			Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg );
			return 1;
		} else if (( lutil_atoi( &id, c->argv[i] ) &&
				   lutil_atoix( &id, c->argv[i], 16 ))
			|| id < 0
			|| id > (QR_IS_SID(type) ? SLAP_SYNC_SID_MAX : SLAP_SYNC_RID_MAX) )
		{
			snprintf( c->cr_msg, sizeof( c->cr_msg ),
				"<%s> illegal %s-ID or mode-key for %s quorum-requirements",
				c->argv[i], QR_IS_SID(type) ? "Server" : "Repl",
				q->qr_cluster );
			unlock();
			Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg );
			return 1;
		} else {
			if (! require_append( q, type, id )) {
				snprintf( c->cr_msg, sizeof( c->cr_msg ),
					"<%s> %s-ID already present in %s quorum-requirements",
					c->argv[i], QR_IS_SID(type) ? "Server" : "Repl",
					q->qr_cluster );
				unlock();
				Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->cr_msg );
				return 1;
			}
			quorum_invalidate(c->be);
		}
	}

	unlock();
	return 0;
}
static void unparse (std::stringstream &ss, const GfxGslAst *ast_, int indent)
{
    std::string space(4 * indent, ' ');
    if (auto ast = dynamic_cast<const GfxGslBlock*>(ast_)) {
        ss << space << "{\n";
        for (auto stmt : ast->stmts) {
            unparse(ss, stmt, indent+1);
        }
        ss << space << "}\n";
    } else if (auto ast = dynamic_cast<const GfxGslShader*>(ast_)) {
        for (auto stmt : ast->stmts) {
            unparse(ss, stmt, indent);
        }
    } else if (auto ast = dynamic_cast<const GfxGslDecl*>(ast_)) {
        ss << space << "var" << " " << ast->id << " = ";
        unparse(ss, ast->init, indent);
        ss << ";";
        if (ast->init->type != nullptr) ss << "  // " << ast->init->type;
        ss << "\n";
    } else if (auto ast = dynamic_cast<const GfxGslIf*>(ast_)) {
        ss << space << "if (";
        unparse(ss, ast->cond, indent);
        ss << ") {\n";
        unparse(ss, ast->yes, indent+1);
        if (ast->no) {
            ss << space << "} else {\n";
            unparse(ss, ast->no, indent+1);
        }
        ss << space << "}\n";
    } else if (auto ast = dynamic_cast<const GfxGslAssign*>(ast_)) {
        ss << space;
        unparse(ss, ast->target, indent);
        ss << " = ";
        unparse(ss, ast->expr, indent);
        ss << ";\n";
    } else if (dynamic_cast<const GfxGslDiscard*>(ast_)) {
        ss << space << "discard;\n";
    } else if (dynamic_cast<const GfxGslReturn*>(ast_)) {
        ss << space << "return;\n";

    } else if (auto ast = dynamic_cast<const GfxGslCall*>(ast_)) {
        ss << ast->func;
        if (ast->args.size() == 0) {
            ss << "()";
        } else {
            const char *sep = "(";
            for (auto arg : ast->args) {
                ss << sep;
                unparse(ss, arg, indent);
                sep = ", ";
            }
            ss << ")";
        }
    } else if (auto ast = dynamic_cast<const GfxGslField*>(ast_)) {
        ss << "(";
        unparse(ss, ast->target, indent);
        ss << ").";
        ss << ast->id;
    } else if (auto ast = dynamic_cast<const GfxGslLiteralInt*>(ast_)) {
        ss << ast->val;
    } else if (auto ast = dynamic_cast<const GfxGslLiteralFloat*>(ast_)) {
        ss << ast->val;
    } else if (auto ast = dynamic_cast<const GfxGslLiteralBoolean*>(ast_)) {
        ss << (ast->val ? "true" : "false");
    } else if (auto ast = dynamic_cast<const GfxGslVar*>(ast_)) {
        ss << ast->id;
    } else if (auto ast = dynamic_cast<const GfxGslBinary*>(ast_)) {
        ss << "(";
        unparse(ss, ast->a, indent);
        ss << " " << to_string(ast->op) << " ";
        unparse(ss, ast->b, indent);
        ss << ")";

    } else if (dynamic_cast<const GfxGslGlobal*>(ast_)) {
        ss << "global";
    } else if (dynamic_cast<const GfxGslMat*>(ast_)) {
        ss << "mat";
    } else if (dynamic_cast<const GfxGslVert*>(ast_)) {
        ss << "vert";
    } else if (dynamic_cast<const GfxGslFrag*>(ast_)) {
        ss << "frag";

    } else {
        EXCEPTEX << "INTERNAL ERROR: Unknown Ast." << ENDL;
    }
}
Example #23
0
std::string unparse(const ParseTree& tree) {
    std::ostringstream ss;
    unparse(ss, tree.Root);
    return ss.str();
}
Example #24
0
void tangent_linear_code::build(const string& outfile_name) {
  ofstream tgtfile(outfile_name.c_str());
  // unparse tangent-linear code
  if (the_ast.ast_root) unparse(the_ast.ast_root,tgtfile,0);
  tgtfile.close();
}