Esempio n. 1
0
/*
 * normal (expression) switch.
 * rebulid case statements into if .. goto
 */
static void
exprswitch(Node *sw)
{
	Node *def;
	NodeList *cas;
	Node *a;
	Case *c0, *c, *c1;
	Type *t;
	int arg, ncase;

	casebody(sw, N);

	arg = Snorm;
	if(isconst(sw->ntest, CTBOOL)) {
		arg = Strue;
		if(sw->ntest->val.u.bval == 0)
			arg = Sfalse;
	}
	walkexpr(&sw->ntest, &sw->ninit);
	t = sw->type;
	if(t == T)
		return;

	/*
	 * convert the switch into OIF statements
	 */
	exprname = N;
	cas = nil;
	if(arg != Strue && arg != Sfalse) {
		exprname = temp(sw->ntest->type);
		cas = list1(nod(OAS, exprname, sw->ntest));
		typechecklist(cas, Etop);
	} else {
		exprname = nodbool(arg == Strue);
	}

	c0 = mkcaselist(sw, arg);
	if(c0 != C && c0->type == Tdefault) {
		def = c0->node->right;
		c0 = c0->link;
	} else {
		def = nod(OBREAK, N, N);
	}

loop:
	if(c0 == C) {
		cas = list(cas, def);
		sw->nbody = concat(cas, sw->nbody);
		sw->list = nil;
		walkstmtlist(sw->nbody);
		return;
	}

	// deal with the variables one-at-a-time
	if(!okforcmp[t->etype] || c0->type != Texprconst) {
		a = exprbsw(c0, 1, arg);
		cas = list(cas, a);
		c0 = c0->link;
		goto loop;
	}

	// do binary search on run of constants
	ncase = 1;
	for(c=c0; c->link!=C; c=c->link) {
		if(c->link->type != Texprconst)
			break;
		ncase++;
	}

	// break the chain at the count
	c1 = c->link;
	c->link = C;

	// sort and compile constants
	c0 = csort(c0, exprcmp);
	a = exprbsw(c0, ncase, arg);
	cas = list(cas, a);

	c0 = c1;
	goto loop;

}
void
test_posix_extended ()
{
  /* Intervals can only match up to RE_DUP_MAX occurences of anything.  */
  char dup_max_plus_one[6];
  sprintf (dup_max_plus_one, "%d", RE_DUP_MAX + 1);


  printf ("\nStarting POSIX extended tests.\n");
  t = posix_extended_test;
  
  re_set_syntax (RE_SYNTAX_POSIX_MINIMAL_EXTENDED);  

  test_posix_generic ();

  printf ("\nContinuing POSIX extended tests.\n");

  /* Grouping tests that differ from basic's.  */
  
  test_should_match = true;
  MATCH_SELF ("a)");

                                /* Valid use of special characters.  */
  test_match ("\\(a", "(a");
  test_match ("a\\+", "a+");
  test_match ("a\\?", "a?");
  test_match ("\\{a", "{a");
  test_match ("\\|a", "|a");
  test_match ("a\\|b", "a|b");
  test_match ("a\\|?", "a");
  test_match ("a\\|?", "a|");
  test_match ("a\\|*", "a");
  test_match ("a\\|*", "a||");
  test_match ("\\(*\\)", ")");
  test_match ("\\(*\\)", "(()");
  test_match ("a\\|+", "a|");
  test_match ("a\\|+", "a||");
  test_match ("\\(+\\)", "()");
  test_match ("\\(+\\)", "(()");
  test_match ("a\\||b", "a|");
  test_match ("\\(?\\)", ")");
  test_match ("\\(?\\)", "()");

  test_match ("a+", "a");
  test_match ("a+", "aa");
  test_match ("a?", "");
  test_match ("a?", "a");

                                                /* Bracket expressions.  */
  test_match ("[(]", "(");
  test_match ("[+]", "+");
  test_match ("[?]", "?");
  test_match ("[{]", "{");
  test_match ("[|]", "|");
                                                /* Subexpressions.  */
  test_match ("(a+)*", "");
  test_match ("(a+)*", "aa");
  test_match ("(a?)*", "");
  test_match ("(a?)*", "aa");
                                                /* (No) back references.  */
  test_match ("(a)\\1", "a1");
                                                /* Invalid as intervals,
                                                   but are valid patterns.  */
  MATCH_SELF ("{");
  test_match ("^{", "{");
  test_match ("a|{", "{");
  test_match ("({)", "{");
  MATCH_SELF ("a{");
  MATCH_SELF ("a{}");
  MATCH_SELF ("a{-1");
  MATCH_SELF ("a{-1}");
  MATCH_SELF ("a{0");            
  MATCH_SELF ("a{0,"); 
  MATCH_SELF (concat ("a{", dup_max_plus_one));
  MATCH_SELF (concat (concat ("a{", dup_max_plus_one), ","));
  MATCH_SELF ("a{1,0");
  MATCH_SELF ("a{1,0}");
  MATCH_SELF ("a{0,1");
  test_match ("[a{0,1}]", "}");
  test_match ("a{1,3}{-1}", "aaa{-1}");
  test_match (concat ("a{1,3}{", dup_max_plus_one), 
        concat ("aaa{", dup_max_plus_one));
  test_match ("a{1,3}{2,1}", "aaa{2,1}");
  test_match ("a{1,3}{1,2", "aaa{1,2");
          /* Valid consecutive repetitions.  */
  test_match ("a*+", "a");
  test_match ("a*?", "a");
  test_match ("a++", "a");
  test_match ("a+*", "a");
  test_match ("a+?", "a");
  test_match ("a??", "a");
  test_match ("a?*", "a");
  test_match ("a?+", "a");
  
  test_match ("a{2}?", "");
  test_match ("a{2}?", "aa");
  test_match ("a{2}+", "aa");
  test_match ("a{2}{2}", "aaaa");

  test_match ("a{1}?*", "");
  test_match ("a{1}?*", "aa");
  
  test_match ("(a?){0,3}b", "aaab"); 
  test_fastmap ("(a?){0,3}b", "ab", 0, 0); 
  test_match ("(a+){0,3}b", "b"); 
  test_fastmap ("(a+){0,3}b", "ab", 0, 0); 
  test_match ("(a+){0,3}b", "ab");
  test_fastmap ("(a+){0,3}b", "ab", 0, 0); 
  test_match ("(a+){1,3}b", "aaab"); 
  test_match ("(a?){1,3}b", "aaab");

  test_match ("\\\\{1}", "\\");        /* Extended only.  */

  test_match ("(a?)?", "a");
  test_match ("(a?b)?c", "abc");
  test_match ("(a+)*b", "b"); 
            /* Alternatives.  */
  test_match ("a|b", "a");
  test_match ("a|b", "b");
  test_fastmap ("a|b", "ab", 0, 0);

  TEST_SEARCH ("a|b", "cb", 0, 2);
  TEST_SEARCH ("a|b", "cb", 0, 2);

  test_match ("(a|b|c)", "a");
  test_match ("(a|b|c)", "b");
  test_match ("(a|b|c)", "c");

  test_match ("(a|b|c)*", "abccba");
  
  test_match ("(a(b*))|c", "a");  /* xx do registers.  */
  test_match ("(a(b*))|c", "ab");
  test_match ("(a(b*))|c", "c");

  test_fastmap ("(a+?*|b)", "ab", 0, 0);
  test_match ("(a+?*|b)", "b");
  TEST_REGISTERS ("(a+?*|b)", "b", 0, 1, 0, 1, -1, -1);
  
  test_fastmap ("(a+?*|b)*", "ab", 0, 0);
  test_match ("(a+?*|b)*", "bb");
  TEST_REGISTERS ("(a+?*|b)*", "bb", 0, 2, 1, 2, -1, -1);

  test_fastmap ("(a*|b)*", "ab", 0, 0);
  test_match ("(a*|b)*", "bb");
  TEST_REGISTERS ("(a*|b)*", "bb", 0, 2, 1, 2, -1, -1);

  test_fastmap ("((a*)|b)*", "ab", 0, 0);
  test_match ("((a*)|b)*", "bb");
  TEST_REGISTERS ("((a*)|b)*", "bb", 0, 2, 1, 2, 1, 1);

  test_fastmap ("(a{0,}|b)*", "ab", 0, 0);
  test_match ("(a{0,}|b)*", "bb");
  TEST_REGISTERS ("(a{0,}|b)*", "bb", 0, 2, 1, 2, -1, -1);

  test_fastmap ("((a{0,})|b)*", "ab", 0, 0);
  test_match ("((a{0,})|b)*", "bb");
  TEST_REGISTERS ("((a{0,})|b)*", "bb", 0, 2, 1, 2, 1, 1);

            /* With c's  */
  test_fastmap ("(a+?*|b)c", "abc", 0, 0);
  test_match ("(a+?*|b)c", "bc");
  TEST_REGISTERS ("(a+?*|b)c", "bc", 0, 2, 0, 1, -1, -1);
  
  test_fastmap ("(a+?*|b)*c", "abc", 0, 0);
  test_match ("(a+?*|b)*c", "bbc");
  TEST_REGISTERS ("(a+?*|b)*c", "bbc", 0, 3, 1, 2, -1, -1);

  test_fastmap ("(a*|b)*c", "abc", 0, 0);
  test_match ("(a*|b)*c", "bbc");
  TEST_REGISTERS ("(a*|b)*c", "bbc", 0, 3, 1, 2, -1, -1);

  test_fastmap ("((a*)|b)*c", "abc", 0, 0);
  test_match ("((a*)|b)*c", "bbc");
  TEST_REGISTERS ("((a*)|b)*c", "bbc", 0, 3, 1, 2, 1, 1);

  test_fastmap ("(a{0,}|b)*c", "abc", 0, 0);
  test_match ("(a{0,}|b)*c", "bbc");
  TEST_REGISTERS ("(a{0,}|b)*c", "bbc", 0, 3, 1, 2, -1, -1);

  test_fastmap ("((a{0,})|b)*c", "abc", 0, 0);
  test_match ("((a{0,})|b)*c", "bbc");
  TEST_REGISTERS ("((a{0,})|b)*c", "bbc", 0, 3, 1, 2, 1, 1);


  test_fastmap ("((a{0,}\\b\\<)|b)", "ab", 0, 0);
  test_match ("((a{0,}\\b\\<)|b)", "b");
  TEST_REGISTERS ("((a{0,}\\b\\<)|b)", "b", 
    0, 1, 0, 1, 0, 0);

  test_fastmap ("((a{0,}\\b\\<)|b)*", "ab", 0, 0);
  test_match ("((a{0,}\\b\\<)|b)*", "b");
  TEST_REGISTERS ("((a{0,}\\b\\<)|b)*", "b", 
    0, 1, 0, 1, 0, 0);

  test_fastmap ("((a+?*{0,1}\\b\\<)|b)", "ab", 0, 0);
  test_match ("((a+?*{0,1}\\b\\<)|b)", "b");
  TEST_REGISTERS ("((a+?*{0,1}\\b\\<)|b)", "b",
    0, 1, 0, 1, 0, 0);

  test_fastmap ("((a+?*{0,2}\\b\\<)|b)", "ab", 0, 0);
  test_match ("((a+?*{0,2}\\b\\<)|b)", "b");
  TEST_REGISTERS ("((a+?*{0,2}\\b\\<)|b)", "b",
    0, 1, 0, 1, 0, 0);


  test_fastmap ("((a+?*{0,4095}\\b\\<)|b)", "ab", 0, 0);
  test_match ("((a+?*{0,4095}\\b\\<)|b)", "b");
  TEST_REGISTERS ("((a+?*{0,4095}\\b\\<)|b)", "b",
    0, 1, 0, 1, 0, 0);

  test_fastmap ("((a+?*{0,5119}\\b\\<)|b)", "ab", 0, 0);
  test_match ("((a+?*{0,5119}\\b\\<)|b)", "b");
  TEST_REGISTERS ("((a+?*{0,5119}\\b\\<)|b)", "b",
    0, 1, 0, 1, 0, 0);

  test_fastmap ("((a+?*{0,6143}\\b\\<)|b)", "ab", 0, 0);
  test_match ("((a+?*{0,6143}\\b\\<)|b)", "b");
  TEST_REGISTERS ("((a+?*{0,6143}\\b\\<)|b)", "b",
    0, 1, 0, 1, 0, 0);

  test_fastmap ("((a+?*{0,8191}\\b\\<)|b)", "ab", 0, 0);
  test_match ("((a+?*{0,8191}\\b\\<)|b)", "b");
  TEST_REGISTERS ("((a+?*{0,8191}\\b\\<)|b)", "b",
    0, 1, 0, 1, 0, 0);

  test_fastmap ("((a+?*{0,16383}\\b\\<)|b)", "ab", 0, 0);
  test_match ("((a+?*{0,16383}\\b\\<)|b)", "b");
  TEST_REGISTERS ("((a+?*{0,16383}\\b\\<)|b)", "b",
    0, 1, 0, 1, 0, 0);


  test_fastmap ("((a+?*{0,}\\b\\<)|b)", "ab", 0, 0);
  test_match ("((a+?*{0,}\\b\\<)|b)", "b");
  TEST_REGISTERS ("((a+?*{0,}\\b\\<)|b)", "b",
    0, 1, 0, 1, 0, 0);

  test_fastmap ("((a+?*{0,}\\b\\<)|b)*", "ab", 0, 0);
  test_match ("((a+?*{0,}\\b\\<)|b)*", "b");
  TEST_REGISTERS ("((a+?*{0,}\\b\\<)|b)*", "b",
    0, 1, 0, 1, 0, 0);

  test_fastmap ("((a+?*{0,}\\b\\<)|b)*", "ab", 0, 0);
  test_match ("((a+?*{0,}\\b\\<)|b)*", "bb");
  TEST_REGISTERS ("((a+?*{0,}\\b\\<)|b)*", "bb",
    0, 2, 1, 2, 0, 0);


        /* `*' after group.  */
  test_match ("(a*|b*)*c", "c");  
  TEST_REGISTERS ("(a*|b*)*c", "c", 0, 1, 0, 0, -1, -1);

  test_match ("(a*|b*)*c", "ac");
  TEST_REGISTERS ("(a*|b*)*c", "ac", 0, 2, 0, 1, -1, -1);

  test_match ("(a*|b*)*c", "aac");
  TEST_REGISTERS ("(a*|b*)*c", "aac", 0, 3, 0, 2, -1, -1);

  test_match ("(a*|b*)*c", "bbc");
  TEST_REGISTERS ("(a*|b*)*c", "bbc", 0, 3, 0, 2, -1, -1);

  test_match ("(a*|b*)*c", "abc");
  TEST_REGISTERS ("(a*|b*)*c", "abc", 0, 3, 1, 2, -1, -1);

        /* No `*' after group.  */
  test_match ("(a*|b*)c", "c");
  TEST_REGISTERS ("(a*|b*)c", "c", 0, 1, 0, 0, -1, -1);

  test_match ("(a*|b*)c", "ac");
  TEST_REGISTERS ("(a*|b*)c", "ac", 0, 2, 0, 1, -1, -1);

  test_match ("(a*|b*)c", "bc");
  TEST_REGISTERS ("(a*|b*)c", "bc", 0, 2, 0, 1, -1, -1);

  test_match ("(a*|b*)c", "aac");
  TEST_REGISTERS ("(a*|b*)c", "aac", 0, 3, 0, 2, -1, -1);

  /* Same as above, but with no `*'s in alternatives. 
  
  test_match ("(a|b)*c", "c");    /* `*' after group.  */
  TEST_REGISTERS ("(a|b)*c", "c", 0, 1, -1, -1, -1, -1);

  test_match ("(a|b)*c", "ac");
  TEST_REGISTERS ("(a|b)*c", "ac", 0, 2, 0, 1, -1, -1);

  test_match ("(a|b)*c", "bc");
  TEST_REGISTERS ("(a|b)*c", "bc", 0, 2, 0, 1, -1, -1);

  test_match ("(a|b)*c", "abc");
  TEST_REGISTERS ("(a|b)*c", "abc", 0, 3, 1, 2, -1, -1);


  test_match ("(a*|b*)c", "bbc");
  TEST_REGISTERS ("(a*|b*)c", "bbc", 0, 3, 0, 2, -1, -1);

  /* Complicated second alternative.  */
  
  test_match ("(a*|(b*)*)*c", "bc");
  TEST_REGISTERS ("(a*|(b*)*)*c", "bc", 0, 2, 0, 1, 0, 1);

  test_match ("(a*|(b*|c*)*)*d", "bd");
  TEST_REGISTERS ("(a*|(b*|c*)*)*d", "bd", 0, 2, 0, 1, 0, 1);

  test_match ("(a*|(b*|c*)*)*d", "bbd");
  TEST_REGISTERS ("(a*|(b*|c*)*)*d", "bbd", 0, 3, 0, 2, 0, 2);

  test_match ("(a*|(b*|c*)*)*d", "cd");
  TEST_REGISTERS ("(a*|(b*|c*)*)*d", "cd", 0, 2, 0, 1, 0, 1);

  test_match ("(a*|(b*|c*)*)*d", "ccd");
  TEST_REGISTERS ("(a*|(b*|c*)*)*d", "ccd", 0, 3, 0, 2, 0, 2);

  test_match ("(a*|b*|c*)*d", "aad");
  TEST_REGISTERS ("(a*|b*|c*)*d", "aad", 0, 3, 0, 2, 0, 2);

  test_match ("(a*|b*|c*)*d", "bbd");
  TEST_REGISTERS ("(a*|b*|c*)*d", "bbd", 0, 3, 0, 2, 0, 2);

  test_match ("(a*|b*|c*)*d", "ccd");
  TEST_REGISTERS ("(a*|b*|c*)*d", "ccd", 0, 3, 0, 2, 0, 2);

            /* Valid anchoring.  */
  valid_pattern ("a^");
  valid_pattern ("a^b");
  valid_pattern ("$a");
  valid_pattern ("a$b");
  valid_pattern ("foo^bar");
  valid_pattern ("foo$bar");
  valid_pattern ("(^)");
  valid_pattern ("($)");
  valid_pattern ("(^$)");

      /* These are the same (but valid) as those (invalid) in other_test.c.  */
  valid_pattern 
    ("(((((((((((((((((((((((((((((((((a^)))))))))))))))))))))))))))))))))");
  valid_pattern 
    ("((((((((((((((((((((((((((((((((($a)))))))))))))))))))))))))))))))))");
  valid_pattern ("\\(^a\\)");
  valid_pattern ("a\\|^b");
  valid_pattern ("\\w^a");
  valid_pattern ("\\W^a");
  valid_pattern ("(a^)");
  valid_pattern ("($a)");
  valid_pattern ("a(^b)");
  valid_pattern ("a$(b)");
  valid_pattern ("(a)^b");
  valid_pattern ("(a)$b");
  valid_pattern ("(a)(^b)");
  valid_pattern ("(a$)(b)");
  valid_pattern ("(a|b)^c");
  valid_pattern ("(a|b)$c");
  valid_pattern ("(a$|b)c");
  valid_pattern ("(a|b$)c");
  valid_pattern ("a(b|^c)");
  valid_pattern ("a(^b|c)");
  valid_pattern ("a$(b|c)");
  valid_pattern ("(a)(^b|c)");
  valid_pattern ("(a)(b|^c)");
  valid_pattern ("(b$|c)(a)");
  valid_pattern ("(b|c$)(a)");
  valid_pattern ("(a(^b|c))");
  valid_pattern ("(a(b|^c))");
  valid_pattern ("((b$|c)a)");
  valid_pattern ("((b|c$)a)");
  valid_pattern ("((^a|^b)^c)");
  valid_pattern ("(c$(a$|b$))");
  valid_pattern ("((^a|^b)^c)");
  valid_pattern ("((a$|b$)c)");
  valid_pattern ("(c$(a$|b$))");
  valid_pattern ("((^a|^b)|^c)^d");
  valid_pattern ("((a$|b$)|c$)d$");
  valid_pattern ("d$(c$|(a$|b$))");
  valid_pattern ("((^a|^b)|^c)(^d)");
  valid_pattern ("((a$|b$)|c$)(d$)");
  valid_pattern ("(d$)((a$|b$)|c$)");
  valid_pattern ("((^a|^b)|^c)((^d))");
  valid_pattern ("((a$|b$)|c$)((d$))");
  valid_pattern ("((d$))((a$|b$)|c$)");
  valid_pattern ("(((^a|^b))c|^d)^e");
  valid_pattern ("(((a$|b$))c|d$)$e$");
  valid_pattern ("e$(d$|c((a$|b$)))");
  valid_pattern ("(^a)((^b))");
  valid_pattern ("(a$)((b$))");
  valid_pattern ("((^a))(^b)");
  valid_pattern ("((a$))(b$)");
  valid_pattern ("((^a))((^b))");
  valid_pattern ("((a$))((b$))");
  valid_pattern ("((^a)^b)");
  valid_pattern ("((a$)b$)");
  valid_pattern ("(b$(a$))");
  valid_pattern ("(((^a)b)^c)");
  valid_pattern ("(((a$)b)c$)");
  valid_pattern ("(c$(b(a$)))");
  valid_pattern ("(((^a)b)c)^d");
  valid_pattern ("(((a$)b)c)d$");
  valid_pattern ("d$(c(b(a$)))");
  valid_pattern (".^a");
  valid_pattern ("a$.");
  valid_pattern ("[a]^b");
  valid_pattern ("b$[a]");
  valid_pattern ("\\(a$\\)");
  valid_pattern ("a$\\|b");
  valid_pattern ("(^a|^b)^c");
  valid_pattern ("c$(a$|b$)");
  valid_pattern ("(^a|^b)^|^c");
  valid_pattern ("(a$|b$)$|$c$");
  valid_pattern ("(a$|$b$)$|c$");
  valid_pattern ("($a$|b$)$|c$");
  valid_pattern ("$(a$|b$)$|c$");
  valid_pattern ("^c|d(^a|^b)");
  valid_pattern ("(^a|^b)|d^c");
  valid_pattern ("c$|(a$|b$)d");
  valid_pattern ("c$d|(a$|b$)");
  valid_pattern ("c(^a|^b)|^d");
  valid_pattern ("(a$|b$)c|d$");
  valid_pattern ("c(((^a|^b))|^d)e");
  valid_pattern ("(c((^a|^b))|^d)e");
  valid_pattern ("((c(^a|^b))|^d)e");
  valid_pattern ("(((^a|^b))|c^d)e");
  valid_pattern ("(((^a|^b))|^d)^e");
  valid_pattern ("(c$((a|b))|d)e$");
  valid_pattern ("(c((a$|b$))|d)e$");
  valid_pattern ("(c((a|b)$)|d)e$");
  valid_pattern ("(c((a|b))|d$)e$");
  valid_pattern ("^d(^c|e((a|b)))");
  valid_pattern ("^d(c|^e((a|b)))");
  valid_pattern ("^d(c|e(^(a|b)))");
  valid_pattern ("^d(c|e((^a|b)))");
  valid_pattern ("^d(c|e((a|^b)))");
  valid_pattern ("^d(c|e((a|b^)))");
  valid_pattern ("^d(c|e((a|b)^))");
  valid_pattern ("^d(c|e((a|b))^)");
  valid_pattern ("^d(c|e((a|b)))^");
  valid_pattern ("d$(c$|e((a$|b$)))");
  valid_pattern ("d(c$|e$((a$|b$)))");
  valid_pattern ("(((^a|^b))^c)|^de");
  valid_pattern ("(((^a|^b))c)|^d^e");
  valid_pattern ("(((a$|b))c$)|de$");
  valid_pattern ("(((a|b$))c$)|de$");
  valid_pattern ("(((a|b))c$)|d$e$");
  valid_pattern ("^d^e|^(c((a|b)))");
  valid_pattern ("^de|^(c^((a|b)))");
  valid_pattern ("^de|^(c(^(a|b)))");
  valid_pattern ("^de|^(c((^a|b)))");
  valid_pattern ("^de|^(c((a|^b)))");
  valid_pattern ("^de|(^c(^(a|b)))");
  valid_pattern ("^de|(^c((^a|b)))");
  valid_pattern ("^de|(^c((a|^b)))");
  valid_pattern ("de$|(c($(a|b)$))");
  valid_pattern ("de$|(c$((a|b)$))");
  valid_pattern ("de$|($c((a|b)$))");
  valid_pattern ("de$|$(c((a|b)$))");
  valid_pattern ("de$|(c($(a|b))$)");
  valid_pattern ("de$|(c$((a|b))$)");
  valid_pattern ("de$|$(c((a|b))$)");
  valid_pattern ("de$|(c($(a|b)))$");
  valid_pattern ("de$|(c$((a|b)))$");
  valid_pattern ("de$|($c((a|b)))$");
  valid_pattern ("de$|$(c((a|b)))$");
  valid_pattern ("^a(^b|c)|^d");
  valid_pattern ("^a(b|^c)|^d");
  valid_pattern ("^a(b|c^)|^d");
  valid_pattern ("^a(b|c)^|^d");
  valid_pattern ("a$(b$|c$)|d$");
  valid_pattern ("^d|^a(^b|c)");
  valid_pattern ("^d|^a(b|^c)");
  valid_pattern ("d$|a$(b$|c$)");
  valid_pattern ("^d|^(b|c)^a");
  valid_pattern ("d$|(b|c$)a$");
  valid_pattern ("d$|(b$|c)a$");
  valid_pattern ("^(a)^(b|c)|^d");
  valid_pattern ("^(a)(^b|c)|^d");
  valid_pattern ("^(a)(b|^c)|^d");
  valid_pattern ("(a)$(b|c)$|d$");
  valid_pattern ("(a$)(b|c)$|d$");
  valid_pattern ("(^a)(^b|c)|^d");
  valid_pattern ("(^a)(b|^c)|^d");
  valid_pattern ("(a)$(b$|c$)|d$");
  valid_pattern ("(a$)(b$|c$)|d$");
  valid_pattern ("^d|^(b|c)^(a)");
  valid_pattern ("^d|^(b|c)(^a)");
  valid_pattern ("d$|(b|c$)(a)$");
  valid_pattern ("d$|(b$|c)(a)$");
  valid_pattern ("^d|(^b|^c)^(a)");
  valid_pattern ("^d|(^b|^c)(^a)");
  valid_pattern ("d$|(b|c)$(a$)");
  valid_pattern ("d$|(b|c$)(a$)");
  valid_pattern ("d$|(b$|c)(a$)");
  valid_pattern ("^d|^(a)^(b|c)");
  valid_pattern ("^d|^(a)(^b|c)");
  valid_pattern ("^d|^(a)(b|^c)");
  valid_pattern ("^d|(^a)^(b|c)");
  valid_pattern ("^d|(^a)(^b|c)");
  valid_pattern ("^d|(^a)(b|^c)");
  valid_pattern ("d$|(a)$(b$|c$)");
  valid_pattern ("d$|(a$)(b$|c$)");
  valid_pattern ("((e^a|^b)|^c)|^d");
  valid_pattern ("((^a|e^b)|^c)|^d");
  valid_pattern ("((^a|^b)|e^c)|^d");
  valid_pattern ("((^a|^b)|^c)|e^d");
  valid_pattern ("d$e|(c$|(a$|b$))");
  valid_pattern ("d$|(c$e|(a$|b$))");
  valid_pattern ("d$|(c$|(a$e|b$))");
  valid_pattern ("d$|(c$|(a$|b$e))");
  valid_pattern ("d$|(c$|(a$|b$)e)");
  valid_pattern ("d$|(c$|(a$|b$))e");
  valid_pattern ("(a|b)^|c");
  valid_pattern ("(a|b)|c^");
  valid_pattern ("$(a|b)|c");
  valid_pattern ("(a|b)|$c");
  valid_pattern ("(a^|^b)|^c");
  valid_pattern ("(^a|b^)|^c");
  valid_pattern ("(^a|^b)|c^");
  valid_pattern ("($a|b$)|c$");
  valid_pattern ("(a$|$b)|c$");
  valid_pattern ("(a$|b$)|$c");
  valid_pattern ("c^|(^a|^b)");
  valid_pattern ("^c|(a^|^b)");
  valid_pattern ("^c|(^a|b^)");
  valid_pattern ("$c|(a$|b$)");
  valid_pattern ("c$|($a|b$)");
  valid_pattern ("c$|(a$|$b)");
  valid_pattern ("c^|^(a|b)");
  valid_pattern ("^c|(a|b)^");
  valid_pattern ("$c|(a|b)$");
  valid_pattern ("c$|$(a|b)");
  valid_pattern ("(a^|^b)c|^d");
  valid_pattern ("(^a|b^)c|^d");
  valid_pattern ("(^a|^b)c|d^");
  valid_pattern ("(^a|^b)^c|^d");
  valid_pattern ("(a|b)c$|$d");
  valid_pattern ("(a|b)$c$|d$");
  valid_pattern ("(a|b)$c$|d$");
  valid_pattern ("(a|b$)c$|d$");
  valid_pattern ("(a$|b)c$|d$");
  valid_pattern ("($a|b)c$|d$");
  valid_pattern ("$(a|b)c$|d$");
  valid_pattern ("^d|^c^(a|b)");
  valid_pattern ("^d|^c(^a|b)");
  valid_pattern ("^d|^c(a|^b)");
  valid_pattern ("^d|^c(a|b^)");
  valid_pattern ("^d|^c(a|b)^");
  valid_pattern ("$d|c(a$|b$)");
  valid_pattern ("d$|c($a$|b$)");
  valid_pattern ("d$|c$(a$|b$)");
  valid_pattern ("d$|$c(a$|b$)");

  valid_pattern ("(((a^|^b))c|^d)e");
  valid_pattern ("(((^a|b^))c|^d)e");
  valid_pattern ("(((^a|^b))^c|^d)e");
  valid_pattern ("((^(a|b))c|d^)e");
  valid_pattern ("(^((a|b))c|^d)^e");
  valid_pattern ("(^((a|b)^)c|^d)e");
  valid_pattern ("(^((a^|b))c|^d)e");
  valid_pattern ("(^((a|b^))c|^d)e");
  valid_pattern ("(^((a|b)^)c|^d)e");
  valid_pattern ("(^((a|b))^c|^d)e");
  valid_pattern ("(^((a|b))c^|^d)e");
  valid_pattern ("(^((a|b))c|^d^)e");
  valid_pattern ("(^((a|b))c|^d)^e");
  valid_pattern ("(((a|b))c|d)$e$");
  valid_pattern ("(((a|b))c|d$)e$");
  valid_pattern ("(((a|b))c|$d)e$");
  valid_pattern ("(((a|b))c$|d)e$");
  valid_pattern ("(((a|b))$c|d)e$");
  valid_pattern ("(((a|b)$)c|d)e$");
  valid_pattern ("(((a|b$))c|d)e$");
  valid_pattern ("(((a$|b))c|d)e$");
  valid_pattern ("((($a|b))c|d)e$");
  valid_pattern ("(($(a|b))c|d)e$");
  valid_pattern ("($((a|b))c|d)e$");
  valid_pattern ("$(((a|b))c|d)e$");
  valid_pattern ("(^((a|b)^)c|^d)e");
  valid_pattern ("(^((a|b))^c|^d)e");
  valid_pattern ("(^((a|b))c|^d^)e");
  valid_pattern ("(^((a|b))c|^d)^e");

  valid_pattern ("^e(^d|c((a|b)))");
  valid_pattern ("^e(d|^c((a|b)))");
  valid_pattern ("^e(d|c^((a|b)))");
  valid_pattern ("^e(d|c(^(a|b)))");
  valid_pattern ("^e(d|c((^a|b)))");
  valid_pattern ("^e(d|c((a|^b)))");
  valid_pattern ("^e(d|c((a|b^)))");
  valid_pattern ("^e(d|c((a|b)^))");
  valid_pattern ("^e(d|c((a|b))^)");
  valid_pattern ("^e(d|c((a|b)))^");
  valid_pattern ("e$(d$|c((a$|b$)))");
  valid_pattern ("e(d$|c$((a$|b$)))");
  valid_pattern ("e(d$|c($(a$|b$)))");
  valid_pattern ("e(d$|c(($a$|b$)))");
  valid_pattern ("e$(d$|c((a|b)$))");
  valid_pattern ("e($d$|c((a|b)$))");
  valid_pattern ("e(d$|$c((a|b)$))");
  valid_pattern ("e(d$|c$((a|b)$))");
  valid_pattern ("e(d$|c($(a|b)$))");
  valid_pattern ("e(d$|c(($a|b)$))");
  valid_pattern ("e(d$|c((a|$b)$))");
  valid_pattern ("e(d$|c((a$|$b$)))");

  valid_pattern ("e$(d$|c((a|b))$)");
  valid_pattern ("e($d$|c((a|b))$)");
  valid_pattern ("e(d$|$c((a|b))$)");
  valid_pattern ("e(d$|c$((a|b))$)");
  valid_pattern ("e(d$|c($(a|b))$)");
  valid_pattern ("e(d$|c(($a|b))$)");
  valid_pattern ("e(d$|c((a|$b))$)");
  valid_pattern ("e$(d$|c((a|b)))$");
  valid_pattern ("e($d$|c((a|b)))$");
  valid_pattern ("e(d$|$c((a|b)))$");
  valid_pattern ("e(d$|c$((a|b)))$");
  valid_pattern ("e(d$|c($(a|b)))$");
  valid_pattern ("e(d$|c(($a|b)))$");
  valid_pattern ("e(d$|c((a|$b)))$");
  valid_pattern ("(((^a|^b)^)c)|^de");
  valid_pattern ("(((^a|^b))^c)|^de");
  valid_pattern ("(((^a|^b))c)^|^de");
  valid_pattern ("$(((a|b))c$)|de$");
  valid_pattern ("($((a|b))c$)|de$");
  valid_pattern ("(($(a|b))c$)|de$");
  valid_pattern ("((($a|b))c$)|de$");
  valid_pattern ("(((a|$b))c$)|de$");
  valid_pattern ("(((a|b)$)c$)|de$");
  valid_pattern ("(((a|b))$c$)|de$");
  valid_pattern ("$(((a|b))c)$|de$");
  valid_pattern ("($((a|b))c)$|de$");
  valid_pattern ("(($(a|b))c)$|de$");
  valid_pattern ("((($a|b))c)$|de$");
  valid_pattern ("(((a|$b))c)$|de$");
  valid_pattern ("(((a|b)$)c)$|de$");
  valid_pattern ("(((a|b))$c)$|de$");
  valid_pattern ("^ed|^(c((a|b)))^");
  valid_pattern ("^ed|^(c((a|b))^)");
  valid_pattern ("^ed|^(c((a|b)^))");
  valid_pattern ("^ed|^(c((a|b^)))");
  valid_pattern ("^ed|^(c((a^|b)))");
  valid_pattern ("^ed|^(c((^a|b)))");
  valid_pattern ("^ed|^(c(^(a|b)))");
  valid_pattern ("^ed|^(c^((a|b)))");
  valid_pattern ("^ed|(^c((a|b)))^");
  valid_pattern ("^ed|(^c((a|b))^)");
  valid_pattern ("^ed|(^c((a|b)^))");
  valid_pattern ("^ed|(^c((a|b^)))");
  valid_pattern ("^ed|(^c((a|^b)))");
  valid_pattern ("^ed|(^c((a^|b)))");
  valid_pattern ("^ed|(^c((^a|b)))");
  valid_pattern ("^ed|(^c(^(a|b)))");
  valid_pattern ("^ed|(^c(^(a|b)))");
  valid_pattern ("^ed|(^c^((a|b)))");
  valid_pattern ("ed$|$(c((a|b)))$");
  valid_pattern ("ed$|($c((a|b)))$");
  valid_pattern ("ed$|(c$((a|b)))$");
  valid_pattern ("ed$|(c($(a|b)))$");
  valid_pattern ("ed$|(c(($a|b)))$");
  valid_pattern ("ed$|(c((a|$b)))$");
  valid_pattern ("ed$|$(c((a|b))$)");
  valid_pattern ("ed$|($c((a|b))$)");
  valid_pattern ("ed$|(c$((a|b))$)");
  valid_pattern ("ed$|(c($(a|b))$)");
  valid_pattern ("ed$|(c(($a|b))$)");
  valid_pattern ("ed$|(c((a|$b))$)");
  valid_pattern ("ed$|$(c((a|b)$))");
  valid_pattern ("ed$|($c((a|b)$))");
  valid_pattern ("ed$|(c$((a|b)$))");
  valid_pattern ("ed$|(c($(a|b)$))");
  valid_pattern ("ed$|(c(($a|b)$))");
  valid_pattern ("ed$|(c((a|$b)$))");
  valid_pattern ("ed$|$(c((a|b)$))");
  valid_pattern ("ed$|($c((a|b)$))");
  valid_pattern ("ed$|(c$((a|b)$))");
  valid_pattern ("ed$|(c($(a|b)$))");
  valid_pattern ("ed$|(c(($a|b)$))");
  valid_pattern ("ed$|(c((a|$b)$))");
  valid_pattern ("ed$|$(c((a|b)$))");
  valid_pattern ("ed$|($c((a|b)$))");
  valid_pattern ("ed$|(c$((a|b)$))");
  valid_pattern ("ed$|(c($(a|b)$))");
  valid_pattern ("ed$|(c(($a|b)$))");
  valid_pattern ("ed$|(c((a|$b)$))");
  valid_pattern ("ed$|$(c((a|b)$))");
  valid_pattern ("ed$|($c((a|b)$))");
  valid_pattern ("ed$|(c$((a|b)$))");
  valid_pattern ("ed$|(c($(a|b)$))");
  valid_pattern ("ed$|(c(($a|b)$))");
  valid_pattern ("ed$|(c((a|$b)$))");
  valid_pattern ("ed$|$(c((a|b)$))");
  valid_pattern ("ed$|($c((a|b)$))");
  valid_pattern ("ed$|(c$((a|b)$))");
  valid_pattern ("ed$|(c($(a|b)$))");
  valid_pattern ("ed$|(c(($a|b)$))");
  valid_pattern ("ed$|(c((a|$b)$))");
  valid_pattern ("ed$|$(c((a$|b$)))");
  valid_pattern ("ed$|($c((a$|b$)))");
  valid_pattern ("ed$|(c$((a$|b$)))");
  valid_pattern ("ed$|(c($(a$|b$)))");
  valid_pattern ("ed$|(c(($a$|b$)))");
  valid_pattern ("ed$|(c((a$|$b$)))");
  valid_pattern ("^a(b|c)^|^d");
  valid_pattern ("^a(b|c^)|^d");
  valid_pattern ("^a(b|^c)|^d");
  valid_pattern ("^a(b^|c)|^d");
  valid_pattern ("^a(^b|c)|^d");
  valid_pattern ("^a^(b|c)|^d");
  valid_pattern ("$a(b$|c$)|d$");
  valid_pattern ("a$(b$|c$)|d$");
  valid_pattern ("a($b$|c$)|d$");
  valid_pattern ("a(b$|$c$)|d$");
  valid_pattern ("a(b$|c$)|$d$");
  valid_pattern ("^(a^)(b|c)|^d");
  valid_pattern ("^(a)^(b|c)|^d");
  valid_pattern ("^(a)(^b|c)|^d");
  valid_pattern ("^(a)(b^|c)|^d");
  valid_pattern ("^(a)(b|^c)|^d");
  valid_pattern ("^(a)(b|c^)|^d");
  valid_pattern ("^(a)(b|c)^|^d");
  valid_pattern ("(^a^)(b|c)|^d");
  valid_pattern ("(^a)^(b|c)|^d");
  valid_pattern ("(^a)(^b|c)|^d");
  valid_pattern ("(^a)(b^|c)|^d");
  valid_pattern ("(^a)(b|^c)|^d");
  valid_pattern ("(^a)(b|c^)|^d");
  valid_pattern ("(^a)(b|c)^|^d");
  
  valid_pattern ("(a)(b$|c$)d$");
  valid_pattern ("(a)(b|$c)$|d$");
  valid_pattern ("(a)($b|c)$|d$");
  valid_pattern ("(a)$(b|c)$|d$");
  valid_pattern ("(a$)(b|c)$|d$");
  valid_pattern ("($a)(b|c)$|d$");
  valid_pattern ("$(a)(b|c)$|d$");
  valid_pattern ("(b|c)($a)$|d$");
  valid_pattern ("(b|c)$(a)$|d$");
  valid_pattern ("(b|c$)(a)$|d$");
  valid_pattern ("(b|$c)(a)$|d$");
  valid_pattern ("(b$|c)(a)$|d$");
  valid_pattern ("($b|c)(a)$|d$");
  valid_pattern ("$(b|c)(a)$|d$");
  valid_pattern ("(b|c)($a$)|d$");
  valid_pattern ("(b|c)$(a$)|d$");
  valid_pattern ("(b|c$)(a$)|d$");
  valid_pattern ("(b|$c)(a$)|d$");
  valid_pattern ("(b$|c)(a$)|d$");
  valid_pattern ("($b|c)(a$)|d$");
  valid_pattern ("$(b|c)(a$)|d$");
  valid_pattern ("(a)$(b$|c$)|d$");
  valid_pattern ("(a$)(b$|c$)|d$");
  valid_pattern ("($a)(b$|c$)|d$");
  valid_pattern ("$(a)(b$|c$)|d$");
  valid_pattern ("^d|^(b^|c)(a)");
  valid_pattern ("^d|^(b|c^)(a)");
  valid_pattern ("^d|^(b|c)^(a)");
  valid_pattern ("^d|^(b|c)(^a)");
  valid_pattern ("^d|^(b|c)(a^)");
  valid_pattern ("^d|^(b|c)(a)^");
  valid_pattern ("^d|(^b|^c^)(a)");
  valid_pattern ("^d|(^b|^c)^(a)");
  valid_pattern ("^d|(^b|^c)(^a)");
  valid_pattern ("^d|(^b|^c)(a^)");
  valid_pattern ("^d|(^b|^c)(a)^");
  valid_pattern ("d$|(b|c)($a$)");
  valid_pattern ("d$|(b|c)$(a$)");
  valid_pattern ("d$|(b|c$)(a$)");
  valid_pattern ("d$|(b$|c)(a$)");
  valid_pattern ("d$|($b|c)(a$)");
  valid_pattern ("d$|$(b|c)(a$)");
  valid_pattern ("d$|(b|c)($a)$");
  valid_pattern ("d$|(b|c)$(a)$");
  valid_pattern ("d$|(b|c$)(a)$");
  valid_pattern ("d$|(b$|c)(a)$");
  valid_pattern ("d$|($b|c)(a)$");
  valid_pattern ("d$|$(b|c)(a)$");
  valid_pattern ("^d|^(a^)(b|c)");
  valid_pattern ("^d|^(a)^(b|c)");
  valid_pattern ("^d|^(a)(^b|c)");
  valid_pattern ("^d|^(a)(b^|c)");
  valid_pattern ("^d|^(a)(b|^c)");
  valid_pattern ("^d|^(a)(b|c^)");
  valid_pattern ("^d|^(a)(b|c)^");
  valid_pattern ("^d|(^a^)(b|c)");
  valid_pattern ("^d|(^a)^(b|c)");
  valid_pattern ("^d|(^a)(^b|c)");
  valid_pattern ("^d|(^a)(b^|c)");
  valid_pattern ("^d|(^a)(b|^c)");
  valid_pattern ("^d|(^a)(b|c^)");
  valid_pattern ("^d|(^a)(b|c)^");
  valid_pattern ("d$|(a)$(b$|c$)");
  valid_pattern ("d$|(a$)(b$|c$)");
  valid_pattern ("d$|($a)(b$|c$)");
  valid_pattern ("d$|$(a)(b$|c$)");
  valid_pattern ("d$|(a)(b|$c)$");
  valid_pattern ("d$|(a)($b|c)$");
  valid_pattern ("d$|(a)$(b|c)$");
  valid_pattern ("d$|(a$)(b|c)$");
  valid_pattern ("d$|($a)(b|c)$");
  valid_pattern ("d$|$(a)(b|c)$");
  valid_pattern ("((^a|^b)|^c)|^d^");
  valid_pattern ("((^a|^b)|^c)^|^d");
  valid_pattern ("((^a|^b)|^c^)|^d");
  valid_pattern ("((^a|^b)^|^c)|^d");
  valid_pattern ("((^a|^b^)|^c)|^d");
  valid_pattern ("((^a^|^b)|^c)|^d");
  valid_pattern ("((a|b)|c)|$d$");
  valid_pattern ("((a|b)|$c)|d$");
  valid_pattern ("((a|$b)|c)|d$");
  valid_pattern ("(($a|b)|c)|d$");
  valid_pattern ("($(a|b)|c)|d$");
  valid_pattern ("$((a|b)|c)|d$");
  valid_pattern ("^d^|(c|(a|b))");
  valid_pattern ("^d|(c^|(a|b))");
  valid_pattern ("^d|(c|(a^|b))");
  valid_pattern ("^d|(c|(a|b^))");
  valid_pattern ("^d|(c|(a|b)^)");
  valid_pattern ("^d|(c|(a|b))^");
  valid_pattern ("d$|(c$|(a$|$b$))");
  valid_pattern ("d$|(c$|($a$|b$))");
  valid_pattern ("d$|($c$|(a$|b$))");
  valid_pattern ("d$|$(c$|(a$|b$))");
  valid_pattern ("$d$|(c$|(a$|b$))");
  valid_pattern ("d$|(c$|(a|$b)$)");
  valid_pattern ("d$|(c$|($a|b)$)");
  valid_pattern ("d$|($c$|(a|b)$)");
  valid_pattern ("d$|$(c$|(a|b)$)");
  valid_pattern ("$d$|(c$|(a|b)$)");
  valid_pattern ("d$|(c$|(a|$b))$");
  valid_pattern ("d$|(c$|($a|b))$");
  valid_pattern ("d$|($c$|(a|b))$");
  valid_pattern ("d$|$(c$|(a|b))$");
  valid_pattern ("$d$|(c$|(a|b))$");
  valid_pattern ("^c^|(^a|^b)");
  valid_pattern ("^c|(^a^|^b)");
  valid_pattern ("^c|(^a|^b^)");
  valid_pattern ("^c|(^a|^b)^");
  valid_pattern ("c$|(a$|$b$)");
  valid_pattern ("c$|($a$|b$)");
  valid_pattern ("c$|$(a$|b$)");
  valid_pattern ("$c$|(a$|b$)");
  valid_pattern ("^d^(c|e((a|b)))");
  valid_pattern ("^d(^c|e((a|b)))");
  valid_pattern ("^d(c^|e((a|b)))");
  valid_pattern ("^d(c|^e((a|b)))");
  valid_pattern ("^d(c|e^((a|b)))");
  valid_pattern ("^d(c|e(^(a|b)))");
  valid_pattern ("^d(c|e((^a|b)))");
  valid_pattern ("^d(c|e((a|^b)))");
  valid_pattern ("^d(c|e((a|b^)))");
  valid_pattern ("^d(c|e((a|b)^))");
  valid_pattern ("^d(c|e((a|b))^)");
  valid_pattern ("^d(c|e((a|b)))^");
  valid_pattern ("d(c$|e($(a$|b$)))");
  valid_pattern ("d(c$|e$((a$|b$)))");
  valid_pattern ("d(c$|$e((a$|b$)))");
  valid_pattern ("d($c$|e((a$|b$)))");
  valid_pattern ("d$(c$|e((a$|b$)))");
  valid_pattern ("$d(c$|e((a$|b$)))");
  valid_pattern ("^d|^a^(b|c)");
  valid_pattern ("^d|^a(^b|c)");
  valid_pattern ("^d|^a(b^|c)");
  valid_pattern ("^d|^a(b|^c)");
  valid_pattern ("^d|^a(b|c^)");
  valid_pattern ("^d|^a(b|c)^");
  valid_pattern ("d$|a($b$|c$)");
  valid_pattern ("d$|a$(b$|c$)");
  valid_pattern ("d$|$a(b$|c$)");
  valid_pattern ("$d$|a(b$|c$)");
  valid_pattern ("^d|^(b^|c)a");
  valid_pattern ("^d|^(b|c^)a");
  valid_pattern ("^d|^(b|c)^a");
  valid_pattern ("^d|^(b|c)a^");
  valid_pattern ("d$|(b|c)$a$");
  valid_pattern ("d$|(b|c$)a$");
  valid_pattern ("d$|(b|$c)a$");
  valid_pattern ("d$|(b$|c)a$");
  valid_pattern ("d$|($b|c)a$");
  valid_pattern ("d$|$(b|c)a$");
  valid_pattern ("$d$|(b|c)a$");

   /* xx Do these use all the valid_nonposix_pattern ones in other_test.c?  */

  TEST_SEARCH ("(^a|^b)c", "ac", 0, 2);
  TEST_SEARCH ("(^a|^b)c", "bc", 0, 2);
  TEST_SEARCH ("c(a$|b$)", "ca", 0, 2);
  TEST_SEARCH ("c(a$|b$)", "cb", 0, 2);
  TEST_SEARCH ("^(a|b)|^c", "ad", 0, 2);
  TEST_SEARCH ("^(a|b)|^c", "bd", 0, 2);
  TEST_SEARCH ("(a|b)$|c$", "da", 0, 2);
  TEST_SEARCH ("(a|b)$|c$", "db", 0, 2);
  TEST_SEARCH ("(a|b)$|c$", "dc", 0, 2);
  TEST_SEARCH ("(^a|^b)|^c", "ad", 0, 2);
  TEST_SEARCH ("(^a|^b)|^c", "bd", 0, 2);
  TEST_SEARCH ("(^a|^b)|^c", "cd", 0, 2);
  TEST_SEARCH ("(a$|b$)|c$", "da", 0, 2);
  TEST_SEARCH ("(a$|b$)|c$", "db", 0, 2);
  TEST_SEARCH ("(a$|b$)|c$", "dc", 0, 2);
  TEST_SEARCH ("^c|(^a|^b)", "ad", 0, 2);
  TEST_SEARCH ("^c|(^a|^b)", "bd", 0, 2);
  TEST_SEARCH ("^c|(^a|^b)", "cd", 0, 2);
  TEST_SEARCH ("c$|(a$|b$)", "da", 0, 2);
  TEST_SEARCH ("c$|(a$|b$)", "db", 0, 2);
  TEST_SEARCH ("c$|(a$|b$)", "dc", 0, 2);
  TEST_SEARCH ("^c|^(a|b)", "ad", 0, 2);
  TEST_SEARCH ("^c|^(a|b)", "bd", 0, 2);
  TEST_SEARCH ("^c|^(a|b)", "cd", 0, 2);
  TEST_SEARCH ("c$|(a|b)$", "da", 0, 2);
  TEST_SEARCH ("c$|(a|b)$", "db", 0, 2);
  TEST_SEARCH ("c$|(a|b)$", "dc", 0, 2);
  TEST_SEARCH ("(^a|^b)c|^d", "ace", 0, 3);
  TEST_SEARCH ("(^a|^b)c|^d", "bce", 0, 3);
  TEST_SEARCH ("(^a|^b)c|^d", "de", 0, 2);
  TEST_SEARCH ("(a|b)c$|d$", "eac", 0, 3);
  TEST_SEARCH ("(a|b)c$|d$", "ebc", 0, 3);
  TEST_SEARCH ("(a|b)c$|d$", "ed", 0, 3);
  TEST_SEARCH ("^d|^c(a|b)", "cae", 0, 3);
  TEST_SEARCH ("^d|^c(a|b)", "cbe", 0, 3);
  TEST_SEARCH ("^d|^c(a|b)", "de", 0, 3);
  TEST_SEARCH ("d$|c(a$|b$)", "eca", 0, 3);
  TEST_SEARCH ("d$|c(a$|b$)", "ecb", 0, 3);
  TEST_SEARCH ("d$|c(a$|b$)", "ed", 0, 3);

  TEST_SEARCH ("(((^a|^b))c|^d)e", "acef", 0, 4);
  TEST_SEARCH ("(((^a|^b))c|^d)e", "bcef", 0, 4);
  TEST_SEARCH ("(((^a|^b))c|^d)e", "def", 0, 3);

  TEST_SEARCH ("((^(a|b))c|^d)e", "acef", 0, 4);
  TEST_SEARCH ("((^(a|b))c|^d)e", "bcef", 0, 4);
  TEST_SEARCH ("((^(a|b))c|^d)e", "def", 0, 3);

  TEST_SEARCH ("(^((a|b))c|^d)e", "acef", 0, 4);
  TEST_SEARCH ("(^((a|b))c|^d)e", "bcef", 0, 4);
  TEST_SEARCH ("(^((a|b))c|^d)e", "def", 0, 3);

  TEST_SEARCH ("(((a|b))c|d)e$", "face", 0, 4);
  TEST_SEARCH ("(((a|b))c|d)e$", "fbce", 0, 4);
  TEST_SEARCH ("(((a|b))c|d)e$", "fde", 0, 3);

  TEST_SEARCH ("^e(d|c((a|b)))", "edf", 0, 3);
  TEST_SEARCH ("^e(d|c((a|b)))", "ecaf", 0, 4);
  TEST_SEARCH ("^e(d|c((a|b)))", "ecbf", 0, 4);

  TEST_SEARCH ("e(d$|c((a$|b$)))", "fed", 0, 3);
  TEST_SEARCH ("e(d$|c((a$|b$)))", "feca", 0, 4);
  TEST_SEARCH ("e(d$|c((a$|b$)))", "fecb", 0, 4);

  TEST_SEARCH ("e(d$|c((a|b)$))", "fed", 0, 3);
  TEST_SEARCH ("e(d$|c((a|b)$))", "feca", 0, 4);
  TEST_SEARCH ("e(d$|c((a|b)$))", "fecb", 0, 4);

  TEST_SEARCH ("e(d$|c((a|b))$)", "fed", 0, 3);
  TEST_SEARCH ("e(d$|c((a|b))$)", "feca", 0, 3);
  TEST_SEARCH ("e(d$|c((a|b))$)", "fecb", 0, 3);

  TEST_SEARCH ("e(d$|c((a|b)))$", "fed", 0, 3);
  TEST_SEARCH ("e(d$|c((a|b)))$", "feca", 0, 3);
  TEST_SEARCH ("e(d$|c((a|b)))$", "fecb", 0, 3);

  TEST_SEARCH ("(((^a|^b))c)|^de", "acf", 0, 3);
  TEST_SEARCH ("(((^a|^b))c)|^de", "bcf", 0, 3);
  TEST_SEARCH ("(((^a|^b))c)|^de", "def", 0, 3);

  TEST_SEARCH ("(((a|b))c$)|de$", "fac", 0, 3);
  TEST_SEARCH ("(((a|b))c$)|de$", "fbc", 0, 3);
  TEST_SEARCH ("(((a|b))c$)|de$", "fde", 0, 3);

  TEST_SEARCH ("(((a|b))c)$|de$", "fac", 0, 3);
  TEST_SEARCH ("(((a|b))c)$|de$", "fbc", 0, 3);
  TEST_SEARCH ("(((a|b))c)$|de$", "fde", 0, 3);

  TEST_SEARCH ("^ed|^(c((a|b)))", "edf", 0, 3);
  TEST_SEARCH ("^ed|^(c((a|b)))", "caf", 0, 3);
  TEST_SEARCH ("^ed|^(c((a|b)))", "cbf", 0, 3);

  TEST_SEARCH ("^ed|(^c((a|b)))", "edf", 0, 3);
  TEST_SEARCH ("^ed|(^c((a|b)))", "caf", 0, 3);
  TEST_SEARCH ("^ed|(^c((a|b)))", "cbf", 0, 3);

  TEST_SEARCH ("ed$|(c((a|b)))$", "fed", 0, 3);
  TEST_SEARCH ("ed$|(c((a|b)))$", "fca", 0, 3);
  TEST_SEARCH ("ed$|(c((a|b)))$", "fcb", 0, 3);

  TEST_SEARCH ("ed$|(c((a|b))$)", "fed", 0, 3);
  TEST_SEARCH ("ed$|(c((a|b))$)", "fca", 0, 3);
  TEST_SEARCH ("ed$|(c((a|b))$)", "fcb", 0, 3);

  TEST_SEARCH ("ed$|(c((a|b)$))", "fed", 0, 3);
  TEST_SEARCH ("ed$|(c((a|b)$))", "fca", 0, 3);
  TEST_SEARCH ("ed$|(c((a|b)$))", "fcb", 0, 3);

  TEST_SEARCH ("ed$|(c((a$|b$)))", "fed", 0, 3);
  TEST_SEARCH ("ed$|(c((a$|b$)))", "fca", 0, 3);
  TEST_SEARCH ("ed$|(c((a$|b$)))", "fcb", 0, 3);

  TEST_SEARCH ("^a(b|c)|^d", "abe", 0, 3);
  TEST_SEARCH ("^a(b|c)|^d", "ace", 0, 3);
  TEST_SEARCH ("^a(b|c)|^d", "df", 0, 2);

  TEST_SEARCH ("a(b$|c$)|d$", "fab", 0, 3);
  TEST_SEARCH ("a(b$|c$)|d$", "fac", 0, 3);
  TEST_SEARCH ("a(b$|c$)|d$", "fd", 0, 2);

  TEST_SEARCH ("^(a)(b|c)|^d", "abe", 0, 3);
  TEST_SEARCH ("^(a)(b|c)|^d", "ace", 0, 3);
  TEST_SEARCH ("^(a)(b|c)|^d", "df", 0, 2);
  
  TEST_SEARCH ("(^a)(b|c)|^d", "abe", 0, 3);
  TEST_SEARCH ("(^a)(b|c)|^d", "ace", 0, 3);
  TEST_SEARCH ("(^a)(b|c)|^d", "df", 0, 2);
  
  TEST_SEARCH ("(a)(b|c)$|d$", "fab", 0, 3);
  TEST_SEARCH ("(a)(b|c)$|d$", "fac", 0, 3);
  TEST_SEARCH ("(a)(b|c)$|d$", "fd", 0, 2);

  TEST_SEARCH ("(b|c)(a)$|d$", "fba", 0, 3);
  TEST_SEARCH ("(b|c)(a)$|d$", "fca", 0, 3);
  TEST_SEARCH ("(b|c)(a)$|d$", "fd", 0, 2);

  TEST_SEARCH ("(b|c)(a$)|d$", "fba", 0, 3);
  TEST_SEARCH ("(b|c)(a$)|d$", "fca", 0, 3);
  TEST_SEARCH ("(b|c)(a$)|d$", "fd", 0, 2);

  TEST_SEARCH ("(a)(b$|c$)|d$", "fab", 0, 3);
  TEST_SEARCH ("(a)(b$|c$)|d$", "fac", 0, 3);
  TEST_SEARCH ("(a)(b$|c$)|d$", "fd", 0, 2);

  TEST_SEARCH ("^d|^(b|c)(a)", "df", 0, 2);
  TEST_SEARCH ("^d|^(b|c)(a)", "baf", 0, 3);
  TEST_SEARCH ("^d|^(b|c)(a)", "caf", 0, 3);
  
  TEST_SEARCH ("^d|(^b|^c)(a)", "df", 0, 2);
  TEST_SEARCH ("^d|(^b|^c)(a)", "baf", 0, 3);
  TEST_SEARCH ("^d|(^b|^c)(a)", "caf", 0, 3);
  
  TEST_SEARCH ("d$|(b|c)(a$)", "fd", 0, 2);
  TEST_SEARCH ("d$|(b|c)(a$)", "fba", 0, 3);
  TEST_SEARCH ("d$|(b|c)(a$)", "fca", 0, 3);

  TEST_SEARCH ("d$|(b|c)(a)$", "fd", 0, 2);
  TEST_SEARCH ("d$|(b|c)(a)$", "fba", 0, 3);
  TEST_SEARCH ("d$|(b|c)(a)$", "fca", 0, 3);

  TEST_SEARCH ("d$|(b|c)(a$)", "fd", 0, 2);
  TEST_SEARCH ("d$|(b|c)(a$)", "fba", 0, 3);
  TEST_SEARCH ("d$|(b|c)(a$)", "fca", 0, 3);

  TEST_SEARCH ("^d|^(a)(b|c)", "df", 0, 2);
  TEST_SEARCH ("^d|^(a)(b|c)", "abf", 0, 3);
  TEST_SEARCH ("^d|^(a)(b|c)", "acf", 0, 3);

  TEST_SEARCH ("^d|(^a)(b|c)", "df", 0, 2);
  TEST_SEARCH ("^d|(^a)(b|c)", "abf", 0, 3);
  TEST_SEARCH ("^d|(^a)(b|c)", "acf", 0, 3);

  TEST_SEARCH ("d$|(a)(b$|c$)", "fd", 0, 2);
  TEST_SEARCH ("d$|(a)(b$|c$)", "fab", 0, 3);
  TEST_SEARCH ("d$|(a)(b$|c$)", "fac", 0, 3);

  TEST_SEARCH ("d$|(a)(b|c)$", "fd", 0, 2);
  TEST_SEARCH ("d$|(a)(b|c)$", "fab", 0, 3);
  TEST_SEARCH ("d$|(a)(b|c)$", "fac", 0, 3);

  TEST_SEARCH ("((^a|^b)|^c)|^d", "ae", 0, 2);
  TEST_SEARCH ("((^a|^b)|^c)|^d", "be", 0, 2);
  TEST_SEARCH ("((^a|^b)|^c)|^d", "ce", 0, 2);
  TEST_SEARCH ("((^a|^b)|^c)|^d", "de", 0, 2);

  TEST_SEARCH ("((a|b)|c)|d$", "ed", 0, 2);
  TEST_SEARCH ("((a|b)|c)|d$", "ea", 0, 2);
  TEST_SEARCH ("((a|b)|c)|d$", "eb", 0, 2);
  TEST_SEARCH ("((a|b)|c)|d$", "ec", 0, 2);

  TEST_SEARCH ("^d|(c|(a|b))", "de", 0, 2);

  TEST_SEARCH ("d$|(c$|(a$|b$))", "ed", 0, 2);
  TEST_SEARCH ("d$|(c$|(a$|b$))", "ec", 0, 2);
  TEST_SEARCH ("d$|(c$|(a$|b$))", "ea", 0, 2);
  TEST_SEARCH ("d$|(c$|(a$|b$))", "eb", 0, 2);

  TEST_SEARCH ("d$|(c$|(a|b)$)", "ed", 0, 2);
  TEST_SEARCH ("d$|(c$|(a|b)$)", "ec", 0, 2);
  TEST_SEARCH ("d$|(c$|(a|b)$)", "ea", 0, 2);
  TEST_SEARCH ("d$|(c$|(a|b)$)", "eb", 0, 2);

  TEST_SEARCH ("d$|(c$|(a|b))$", "ed", 0, 2);
  TEST_SEARCH ("d$|(c$|(a|b))$", "ec", 0, 2);
  TEST_SEARCH ("d$|(c$|(a|b))$", "ea", 0, 2);
  TEST_SEARCH ("d$|(c$|(a|b))$", "eb", 0, 2);

  test_match ("a|^b", "b");
  test_match ("a|b$", "b");
  test_match ("^b|a", "b");
  test_match ("b$|a", "b");
  test_match ("(^a)", "a");
  test_match ("(a$)", "a");
  TEST_SEARCH ("c|^ab", "aba", 0, 3);
  TEST_SEARCH ("c|ba$", "aba", 0, 3);
  TEST_SEARCH ("^ab|c", "aba", 0, 3);
  TEST_SEARCH ("ba$|c", "aba", 0, 3);
  TEST_SEARCH ("(^a)", "ab", 0, 2);
  TEST_SEARCH ("(a$)", "ba", 0, 2);

  TEST_SEARCH ("(^a$)", "a", 0, 1);
  TEST_SEARCH ("(^a)", "ab", 0, 2);
  TEST_SEARCH ("(b$)", "ab", 0, 2);

                                                /* Backtracking.  */
  /* Per POSIX D11.1 p. 108, leftmost longest match.  */
  test_match ("(wee|week)(knights|night)", "weeknights");

  test_match ("(fooq|foo)qbar", "fooqbar");
  test_match ("(fooq|foo)(qbarx|bar)", "fooqbarx");

  /* Take first alternative that does the longest match.  */
  test_all_registers ("(fooq|(foo)|(fo))((qbarx)|(oqbarx)|bar)", "fooqbarx", 
    "", 0, 8,  0, 3,  0, 3,  -1, -1,  3, 8,  3, 8,  -1, -1,  -1, -1, -1, -1,  
    -1, -1);

  test_match ("(fooq|foo)*qbar", "fooqbar");
  test_match ("(fooq|foo)*(qbar)", "fooqbar");
  test_match ("(fooq|foo)*(qbar)*", "fooqbar"); 

  test_match ("(fooq|fo|o)*qbar", "fooqbar");
  test_match ("(fooq|fo|o)*(qbar)", "fooqbar");
  test_match ("(fooq|fo|o)*(qbar)*", "fooqbar");

  test_match ("(fooq|fo|o)*(qbar|q)*", "fooqbar");
  test_match ("(fooq|foo)*(qbarx|bar)", "fooqbarx");
  test_match ("(fooq|foo)*(qbarx|bar)*", "fooqbarx");

  test_match ("(fooq|fo|o)+(qbar|q)+", "fooqbar");
  test_match ("(fooq|foo)+(qbarx|bar)", "fooqbarx");
  test_match ("(fooq|foo)+(qbarx|bar)+", "fooqbarx");

  /* Per Mike Haertel.  */
  test_match ("(foo|foobarfoo)(bar)*", "foobarfoo");

              /* Combination.  */
  test_match ("[ab]?c", "ac");
  test_match ("[ab]*c", "ac");
  test_match ("[ab]+c", "ac");
  test_match ("(a|b)?c", "ac");
  test_match ("(a|b)*c", "ac");
  test_match ("(a|b)+c", "ac");
  test_match ("(a*c)?b", "b");
  test_match ("(a*c)+b", "aacb");
            /* Registers.  */
  /* Per David A. Willcox.  */
  test_match ("a((b)|(c))d", "acd");
  test_all_registers ("a((b)|(c))d", "acd", "", 0, 3, 1, 2, -1, -1, 1, 2,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);


  /* Extended regular expressions, continued; these don't match their strings.  */
  test_should_match = false;

#if 0
                                /* Invalid use of special characters.  */
  /* These are not invalid anymore, since POSIX says the behavior is
     undefined, and we prefer context-independent to context-invalid.  */
  invalid_pattern (REG_BADRPT, "*");
  invalid_pattern (REG_BADRPT, "a|*");
  invalid_pattern (REG_BADRPT, "(*)");
  invalid_pattern (REG_BADRPT, "^*");
  invalid_pattern (REG_BADRPT, "+");
  invalid_pattern (REG_BADRPT, "a|+");
  invalid_pattern (REG_BADRPT, "(+)");
  invalid_pattern (REG_BADRPT, "^+");

  invalid_pattern (REG_BADRPT, "?");
  invalid_pattern (REG_BADRPT, "a|?");
  invalid_pattern (REG_BADRPT, "(?)");
  invalid_pattern (REG_BADRPT, "^?");

  invalid_pattern (REG_BADPAT, "|");
  invalid_pattern (REG_BADPAT, "a|");
  invalid_pattern (REG_BADPAT, "a||");
  invalid_pattern (REG_BADPAT, "(|a)");
  invalid_pattern (REG_BADPAT, "(a|)");

  invalid_pattern (REG_BADPAT, PARENS_TO_OPS ("(|)"));

  invalid_pattern (REG_BADRPT, "{1}");
  invalid_pattern (REG_BADRPT, "a|{1}");
  invalid_pattern (REG_BADRPT, "^{1}");
  invalid_pattern (REG_BADRPT, "({1})");

  invalid_pattern (REG_BADPAT, "|b");

  invalid_pattern (REG_BADRPT, "^{0,}*");
  invalid_pattern (REG_BADRPT, "$*");
  invalid_pattern (REG_BADRPT, "${0,}*");
#endif /* 0 */

  invalid_pattern (REG_EESCAPE, "\\");

  test_match ("a?b", "a");


  test_match ("a+", "");
  test_match ("a+b", "a");
  test_match ("a?", "b");

#if 0
  /* We make empty groups valid now, since they are undefined in POSIX.
    (13 Sep 92) */
                                                /* Subexpressions.  */
  invalid_pattern (REG_BADPAT, "()");
  invalid_pattern (REG_BADPAT, "a()");
  invalid_pattern (REG_BADPAT, "()b");
  invalid_pattern (REG_BADPAT, "a()b");
  invalid_pattern (REG_BADPAT, "()*");
  invalid_pattern (REG_BADPAT, "(()*");
#endif
                                                /* Invalid intervals.  */
  test_match ("a{2}*", "aaa");
  test_match ("a{2}?", "aaa");
  test_match ("a{2}+", "aaa");
  test_match ("a{2}{2}", "aaa");
  test_match ("a{1}{1}{2}", "aaa");
  test_match ("a{1}{1}{2}", "a");
            /* Invalid alternation.  */
  test_match ("a|b", "c");

  TEST_SEARCH ("c|^ba", "aba", 0, 3);
  TEST_SEARCH ("c|ab$", "aba", 0, 3);
  TEST_SEARCH ("^ba|c", "aba", 0, 3);
  TEST_SEARCH ("ab$|c", "aba", 0, 3);
            /* Invalid anchoring.  */
  TEST_SEARCH ("(^a)", "ba", 0, 2);
  TEST_SEARCH ("(b$)", "ba", 0, 2);

  printf ("\nFinished POSIX extended tests.\n");
}
Esempio n. 3
0
/* Helpers to convert between BFD and GOLD symbol formats.  */
static enum ld_plugin_status
asymbol_from_plugin_symbol (bfd *abfd, asymbol *asym,
			    const struct ld_plugin_symbol *ldsym)
{
  flagword flags = BSF_NO_FLAGS;
  struct bfd_section *section;

  asym->the_bfd = abfd;
  asym->name = (ldsym->version
		? concat (ldsym->name, "@", ldsym->version, (const char *) NULL)
		: ldsym->name);
  asym->value = 0;
  switch (ldsym->def)
    {
    case LDPK_WEAKDEF:
      flags = BSF_WEAK;
      /* FALLTHRU */
    case LDPK_DEF:
      flags |= BSF_GLOBAL;
      if (ldsym->comdat_key)
	{
	  char *name = concat (".gnu.linkonce.t.", ldsym->comdat_key,
			       (const char *) NULL);
	  section = bfd_get_section_by_name (abfd, name);
	  if (section != NULL)
	    free (name);
	  else
	    {
	      flagword sflags;

	      sflags = (SEC_CODE | SEC_HAS_CONTENTS | SEC_READONLY
			| SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_EXCLUDE
			| SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD);
	      section = bfd_make_section_anyway_with_flags (abfd, name, sflags);
	      if (section == NULL)
		return LDPS_ERR;
	    }
	}
      else
	section = bfd_get_section_by_name (abfd, ".text");
      break;

    case LDPK_WEAKUNDEF:
      flags = BSF_WEAK;
      /* FALLTHRU */
    case LDPK_UNDEF:
      section = bfd_und_section_ptr;
      break;

    case LDPK_COMMON:
      flags = BSF_GLOBAL;
      section = bfd_com_section_ptr;
      asym->value = ldsym->size;
      /* For ELF targets, set alignment of common symbol to 1.  */
      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
	{
	  ((elf_symbol_type *) asym)->internal_elf_sym.st_shndx = SHN_COMMON;
	  ((elf_symbol_type *) asym)->internal_elf_sym.st_value = 1;
	}
      break;

    default:
      return LDPS_ERR;
    }
  asym->flags = flags;
  asym->section = section;

  /* Visibility only applies on ELF targets.  */
  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
    {
      elf_symbol_type *elfsym = elf_symbol_from (abfd, asym);
      unsigned char visibility;

      if (!elfsym)
	einfo (_("%P%F: %s: non-ELF symbol in ELF BFD!\n"), asym->name);
      switch (ldsym->visibility)
	{
	default:
	  einfo (_("%P%F: unknown ELF symbol visibility: %d!\n"),
		 ldsym->visibility);
	case LDPV_DEFAULT:
	  visibility = STV_DEFAULT;
	  break;
	case LDPV_PROTECTED:
	  visibility = STV_PROTECTED;
	  break;
	case LDPV_INTERNAL:
	  visibility = STV_INTERNAL;
	  break;
	case LDPV_HIDDEN:
	  visibility = STV_HIDDEN;
	  break;
	}
      elfsym->internal_elf_sym.st_other
	= (visibility | (elfsym->internal_elf_sym.st_other
			 & ~ELF_ST_VISIBILITY (-1)));
    }

  return LDPS_OK;
}
Esempio n. 4
0
std::string get_cegis_meta_name(const std::string &base_name)
{
  return concat(id2string(goto_functionst::entry_point()), base_name);
}
int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
{
	int counter, error_number, i;
	char to_process[40], temp[2], check_digit;
	
	if(length > 36) {
		strcpy(symbol->errtxt, "Data too long for HIBC LIC");
		return ERROR_TOO_LONG;
	}
	to_upper(source);
	error_number = is_sane(TECHNETIUM , source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	
	strcpy(to_process, "+");
	counter = 41;
	for(i = 0; i < length; i++) {
		counter += posn(TECHNETIUM, source[i]);
	}
	counter = counter % 43;
	
	if(counter < 10) {
		check_digit = itoc(counter);
	} else {
		if(counter < 36) {
			check_digit = (counter - 10) + 'A';
		} else {
			switch(counter) {
				case 36: check_digit = '-'; break;
				case 37: check_digit = '.'; break;
				case 38: check_digit = ' '; break;
				case 39: check_digit = '$'; break;
				case 40: check_digit = '/'; break;
				case 41: check_digit = '+'; break;
				case 42: check_digit = '%'; break;
				default: check_digit = ' '; break; /* Keep compiler happy */
			}
		}
	}
	
	temp[0] = check_digit;
	temp[1] = '\0';
	
	concat(to_process, (char *)source);
	concat(to_process, temp);
	length = strlen(to_process);
	
	switch(symbol->symbology) {
		case BARCODE_HIBC_128:
			error_number = code_128(symbol, (unsigned char *)to_process, length);
			ustrcpy(symbol->text, (unsigned char*)"*");
			uconcat(symbol->text, (unsigned char*)to_process);
			uconcat(symbol->text, (unsigned char*)"*");
			break;
		case BARCODE_HIBC_39:
			symbol->option_2 = 0;
			error_number = c39(symbol, (unsigned char *)to_process, length);
			ustrcpy(symbol->text, (unsigned char*)"*");
			uconcat(symbol->text, (unsigned char*)to_process);
			uconcat(symbol->text, (unsigned char*)"*");
			break;
		case BARCODE_HIBC_DM:
			error_number = dmatrix(symbol, (unsigned char *)to_process, length);
			break;
		case BARCODE_HIBC_QR:
			error_number = qr_code(symbol, (unsigned char *)to_process, length);
			break;
		case BARCODE_HIBC_PDF:
			error_number = pdf417enc(symbol, (unsigned char *)to_process, length);
			break;
		case BARCODE_HIBC_MICPDF:
			error_number = micro_pdf417(symbol, (unsigned char *)to_process, length);
			break;
		case BARCODE_HIBC_AZTEC:
			error_number = aztec(symbol, (unsigned char *)to_process, length);
			break;
	}
	
	return error_number;
}
Esempio n. 6
0
void addWord(Production p, char * word){
	p->word=concat(p->word,word);
}
Animation AnimationBuilder::spawnJobs(std::string &err, int maxTime){
	FractalLogger::getSingleton()->write(id, "Fractal Is Animated: Note Detailed progress not reported.\n");
	FractalLogger::getSingleton()->write(id, "Building Animation Data...\n");
	unsigned long genStart = time(NULL);

	Animation anim;
	anim.baseID = id;
	anim.timeStarted = genStart;
	if(maxTime > 0){
		anim.timeMustStop = time(NULL) + maxTime;
	}else{
		anim.timeMustStop = 0;
	}

	if(!p->getJson().isMember("anim") || !p->getJson()["anim"].isObject()){
		err += "No JSON Object Anim\n";
		return anim;
	}
	Json::Value animData = p->getJson()["anim"];
	p->getJson()["anim"] = Json::ValueType::nullValue;
	p->getJson()["basic"]["anim"]["selected"] = "no";
	if(!animData.isMember("frames") || !animData["frames"].isInt()){
		err += "anim.frames does not exist or non-int\n";
		return anim;
	}
	if(animData["frames"].asInt() < 1){
		err += "anim.frames out of bounds\n";
		return anim;
	}
	anim.frames = animData["frames"].asInt();

	if(!animData.isMember("fps") || !animData["fps"].isInt()){
		err += "anim.fps does not exist or non-int\n";
		return anim;
	}
	if(animData["fps"].asInt() < 1){
		err += "anim.fps out of bounds\n";
		return anim;
	}
	anim.fps = animData["fps"].asInt();

	if(!animData.isMember("keyframes") || !animData["keyframes"].isArray()){
		err += "anim.keyframes does not exist or non-array\n";
		return anim;
	}
	if(!SchemaManager::getSingleton()->validateAnimationParam(animData["keyframes"], anim.frames, err)){
		err += "Keyframe Validation Reported Error(s)!\n";
		return anim;
	}

	// first job will render frame one -- we need to render all others
	ParamsFile pnew(p->getJson().toStyledString(), false); // copy json data to interpolate
	buildAnimatedParams(animData, &pnew);

	for(int i=2; i<=anim.frames; i++){
		pnew.getJson()["internal"]["thisframe"] = i;
		std::string savepath = DirectoryManager::getSingleton()->getRootDirectory()+"renders/";
		savepath = concat(savepath, anim.baseID) + concat(".frame.", i) + ".job";

		interpolateFrame(pnew, i);

		pnew.saveToFile(savepath);
		anim.frameQueue.push_back(savepath);
	}

	p->getJson()["internal"]["thisframe"] = 1;
	p->getJson()["anim"] = animData;
	p->getJson()["basic"]["anim"]["selected"] = "yes"; // restore it :D

	// finally revalidate the parameters in case we messed up
	err += SchemaManager::getSingleton()->validateParamaters(p->getJson());

	if(err == ""){
		genStart = time(NULL) - genStart;
		FractalLogger::getSingleton()->write(id,
				concat("Animation Data Built: Took ", (float)genStart/1000)+" seconds!\n");
	}
	return anim;
}
Esempio n. 8
0
unsigned int hashFunction(int index0, int index1) {
	return concat(extractBits(index0, 0, 3), extractBits(index1, 0, 7));
	//return extractBits(index0, 0, 3) | extractBits(index1, 0, 4);
}
Esempio n. 9
0
int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len)
{
	unsigned int i, count, check_digit, glyph;
	int error_number, temp_length = src_len;
	char dest[1024]; /* 14 + 60 * 14 + 14 + 14 + 1 ~ 1024 */
	unsigned char temp[64];
	
	error_number = 0;
	count = 0;

	if(temp_length > 60) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	ustrcpy(temp, source);		
	to_upper(temp);
	error_number = is_sane(NEON, temp, temp_length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	
	/* Add a leading zero if required */
	if (temp_length & 1)
	{
		memmove(temp + 1, temp, temp_length);
		temp[0] = '0';

		temp[++temp_length] = '\0';
	}

	/* Start character */
	strcpy(dest, TeleTable['_']);

	for (i = 0; i < temp_length; i += 2)
	{
		if(temp[i] == 'X') {
			strcpy(symbol->errtxt, "Invalid position of X in Telepen data");
			return ERROR_INVALID_DATA;
		}
		
		if(temp[i + 1] == 'X') {
			glyph = ctoi(temp[i]) + 17;
			count += glyph;
		} else {
			glyph = (10 * ctoi(temp[i])) + ctoi(temp[i + 1]);
			glyph += 27;
			count += glyph;
		}
		concat(dest, TeleTable[glyph]);
	}

	check_digit = 127 - (count % 127);
	if(check_digit == 127) { check_digit = 0; }
	concat(dest, TeleTable[check_digit]);

	/* Stop character */
	concat(dest, TeleTable['z']);
	
	expand(symbol, dest);
	ustrcpy(symbol->text, temp);
	return error_number;
}
Esempio n. 10
0
struct gen_seq : gen_seq<N-1, N-1, Is...>{};
template<unsigned... Is>
struct gen_seq<0, Is...> : seq<Is...>{};

template<unsigned N1, unsigned... I1, unsigned N2, unsigned... I2>
constexpr std::array<char const, N1+N2-1> concat(char const (&a1)[N1], char const (&a2)[N2], seq<I1...>, seq<I2...>){
  return {{ a1[I1]..., a2[I2]... }};
}

template<unsigned N1, unsigned N2>
constexpr std::array<char const, N1+N2-1> concat(char const (&a1)[N1], char const (&a2)[N2]){
  return concat(a1, a2, gen_seq<N1-1>{}, gen_seq<N2>{});
}

// The string is used to retrieve the version embedded into .so file on Linux
constexpr auto rs2_api_version = concat("VERSION: ",RS2_API_VERSION_STR);

template<>
bool contains(const std::shared_ptr<librealsense::device_info>& first,
              const std::shared_ptr<librealsense::device_info>& second)
{
    auto first_data = first->get_device_data();
    auto second_data = second->get_device_data();

    for (auto&& uvc : first_data.uvc_devices)
    {
        if (std::find(second_data.uvc_devices.begin(),
            second_data.uvc_devices.end(), uvc) ==
            second_data.uvc_devices.end())
            return false;
    }
Esempio n. 11
0
constexpr std::array<char const, N1+N2-1> concat(char const (&a1)[N1], char const (&a2)[N2]){
  return concat(a1, a2, gen_seq<N1-1>{}, gen_seq<N2>{});
}
Esempio n. 12
0
// Used by test_ext_preg
static String test_preg_rep(CStrRef a, CStrRef b, CStrRef c) {
  return concat(f_strtoupper(c), a);
}
Esempio n. 13
0
int batch_process(struct zint_symbol *symbol, char *filename)
{
	FILE *file;
	unsigned char buffer[7100];
	unsigned char character;
	int posn = 0, error_number = 0, line_count = 1;
	char output_file[127];
	char number[12], reverse_number[12];
	int inpos, local_line_count;
	char format_string[127], reversed_string[127], format_char;
	int format_len, i;
	char adjusted[2];
	
	memset(buffer, 0, sizeof(unsigned char) * 7100);
	if(symbol->outfile[0] == '\0') {
		strcpy(format_string, "~~~~~.png");
	} else {
		if(strlen(format_string) < 127) {
			strcpy(format_string, symbol->outfile);
		} else {
			strcpy(symbol->errtxt, "Format string too long");
			return ZERROR_INVALID_DATA;
		}
	}
	memset(adjusted, 0, sizeof(char) * 2);
	
	if(!strcmp(filename, "-")) {
		file = stdin;
	} else {
		file = fopen(filename, "rb");
		if (!file) {
			strcpy(symbol->errtxt, "Unable to read input file");
			return ZERROR_INVALID_DATA;
		}
	}
	
	do {
		character = fgetc(file);
		if(character == '\n') {
			if(buffer[posn - 1] == '\r') {
				/* CR+LF - assume Windows formatting and remove CR */
				posn--;
				buffer[posn] = '\0';
			}
			inpos = 0;
			local_line_count = line_count;
			memset(number, 0, sizeof(char) * 12);
			memset(reverse_number, 0, sizeof(char) * 12);
			memset(reversed_string, 0, sizeof(char) * 127);
			memset(output_file, 0, sizeof(char) * 127);
			do {
				number[inpos] = itoc(local_line_count % 10);
				local_line_count /= 10;
				inpos++;
			} while (local_line_count > 0);
			number[inpos] = '\0';
			
			for(i = 0; i < inpos; i++) {
				reverse_number[i] = number[inpos - i - 1];
			}
			
			format_len = strlen(format_string);
			for(i = format_len; i > 0; i--) {
				format_char = format_string[i - 1];
				
				switch(format_char) {
					case '#':
						if (inpos > 0) {
							adjusted[0] = reverse_number[inpos - 1];
							inpos--;
						} else {
							adjusted[0] = ' ';
						}
						break;
					case '~':
						if (inpos > 0) {
							adjusted[0] = reverse_number[inpos - 1];
							inpos--;
						} else {
							adjusted[0] = '0';
						}
						break;
					case '@':
						if (inpos > 0) {
							adjusted[0] = reverse_number[inpos - 1];
							inpos--;
						} else {
							adjusted[0] = '*';
						}
						break;
					default:
						adjusted[0] = format_string[i - 1];
						break;
				}
				concat(reversed_string, adjusted);
			}
			
			for(i = 0; i < format_len; i++) {
				output_file[i] = reversed_string[format_len - i - 1];
			}
			
			strcpy(symbol->outfile, output_file);
			error_number = ZBarcode_Encode_and_Print(symbol, buffer, posn, 0);
			if(error_number != 0) {
				fprintf(stderr, "On line %d: %s\n", line_count, symbol->errtxt);
			}
			ZBarcode_Clear(symbol);
			memset(buffer, 0, sizeof(unsigned char) * 7100);
			posn = 0;
			line_count++;
		} else {
			buffer[posn] = character;
			posn++;
		}
		if(posn > 7090) {
			fprintf(stderr, "On line %d: Input data too long\n", line_count);
			do {
				character = fgetc(file);
			} while((!feof(file)) && (character != '\n'));
		}
	} while ((!feof(file)) && (line_count < 2000000000));
	
	if(character != '\n') {
		fprintf(stderr, "Warning: No newline at end of file\n");
	}
	
	fclose(file);
	return error_number;
}
Esempio n. 14
0
/*
 * convert switch of the form
 *	switch v := i.(type) { case t1: ..; case t2: ..; }
 * into if statements
 */
static void
typeswitch(Node *sw)
{
	Node *def;
	NodeList *cas, *hash;
	Node *a, *n;
	Case *c, *c0, *c1;
	int ncase;
	Type *t;
	Val v;

	if(sw->ntest == nil)
		return;
	if(sw->ntest->right == nil) {
		setlineno(sw);
		yyerror("type switch must have an assignment");
		return;
	}
	walkexpr(&sw->ntest->right, &sw->ninit);
	if(!istype(sw->ntest->right->type, TINTER)) {
		yyerror("type switch must be on an interface");
		return;
	}
	cas = nil;

	/*
	 * predeclare temporary variables
	 * and the boolean var
	 */
	facename = temp(sw->ntest->right->type);
	a = nod(OAS, facename, sw->ntest->right);
	typecheck(&a, Etop);
	cas = list(cas, a);

	casebody(sw, facename);

	boolname = temp(types[TBOOL]);
	typecheck(&boolname, Erv);

	hashname = temp(types[TUINT32]);
	typecheck(&hashname, Erv);

	t = sw->ntest->right->type;
	if(isnilinter(t))
		a = syslook("efacethash", 1);
	else
		a = syslook("ifacethash", 1);
	argtype(a, t);
	a = nod(OCALL, a, N);
	a->list = list1(facename);
	a = nod(OAS, hashname, a);
	typecheck(&a, Etop);
	cas = list(cas, a);

	c0 = mkcaselist(sw, Stype);
	if(c0 != C && c0->type == Tdefault) {
		def = c0->node->right;
		c0 = c0->link;
	} else {
		def = nod(OBREAK, N, N);
	}
	
	/*
	 * insert if statement into each case block
	 */
	for(c=c0; c!=C; c=c->link) {
		n = c->node;
		switch(c->type) {

		case Ttypenil:
			v.ctype = CTNIL;
			a = nod(OIF, N, N);
			a->ntest = nod(OEQ, facename, nodlit(v));
			typecheck(&a->ntest, Erv);
			a->nbody = list1(n->right);		// if i==nil { goto l }
			n->right = a;
			break;
		
		case Ttypevar:
		case Ttypeconst:
			n->right = typeone(n);
			break;
		}
	}

	/*
	 * generate list of if statements, binary search for constant sequences
	 */
	while(c0 != C) {
		if(c0->type != Ttypeconst) {
			n = c0->node;
			cas = list(cas, n->right);
			c0=c0->link;
			continue;
		}
		
		// identify run of constants
		c1 = c = c0;
		while(c->link!=C && c->link->type==Ttypeconst)
			c = c->link;
		c0 = c->link;
		c->link = nil;

		// sort by hash
		c1 = csort(c1, typecmp);
		
		// for debugging: linear search
		if(0) {
			for(c=c1; c!=C; c=c->link) {
				n = c->node;
				cas = list(cas, n->right);
			}
			continue;
		}

		// combine adjacent cases with the same hash
		ncase = 0;
		for(c=c1; c!=C; c=c->link) {
			ncase++;
			hash = list1(c->node->right);
			while(c->link != C && c->link->hash == c->hash) {
				hash = list(hash, c->link->node->right);
				c->link = c->link->link;
			}
			c->node->right = liststmt(hash);
		}
		
		// binary search among cases to narrow by hash
		cas = list(cas, typebsw(c1, ncase));
	}
	if(nerrors == 0) {
		cas = list(cas, def);
		sw->nbody = concat(cas, sw->nbody);
		sw->list = nil;
		walkstmtlist(sw->nbody);
	}
}
Esempio n. 15
0
 //加等
 MyString& MyString::operator+=(const MyString &rhs)
 {
     concat(rhs.size(), rhs.data);
     return *this;
 }
Esempio n. 16
0
void Panel::RefreshTitle()
{
	m_Title = concat(L'{', GetTitle(), L'}');
}
Esempio n. 17
0
 //加等
 MyString& MyString::operator+=(const char *cp)
 {
     concat(strlen(cp), cp);
     return *this;
 }
Esempio n. 18
0
static string
maketex P2C(kpse_file_format_type, format, string*, args)
{
  /* New implementation, use fork/exec pair instead of popen, since
   * the latter is virtually impossible to make safe.
   */
  unsigned len;
  string *s;
  string ret;
  string fn;
  
  if (!kpse_make_tex_discard_errors) {
    fprintf (stderr, "kpathsea: Running");
    for (s = &args[0]; *s != NULL; s++)
      fprintf (stderr, " %s", *s);
    fputc('\n', stderr);
  }

#if defined (AMIGA)
  /* Amiga has a different interface. */
  {
    string cmd;
    string newcmd;
    cmd = xstrdup(args[0]);
    for (s = &args[1];  *s != NULL; s++) {
      newcmd = concat(cmd, *s);
      free (cmd);
      cmd = newcmd;
    }
    ret = system(cmd) == 0 ? getenv ("LAST_FONT_CREATED"): NULL;
    free (cmd);
  }
#elif defined (MSDOS)
#error Implement new MSDOS mktex call interface here
#elif defined (WIN32)
  /* We would vastly prefer to link directly with mktex.c here.
     Unfortunately, it is not quite possible because kpathsea
     is not reentrant. The progname is expected to be set in mktex.c
     and various initialisations occur. So to be safe, we implement
     a call sequence equivalent to the Unix one. */
  {
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    HANDLE child_in, child_out, child_err;
    HANDLE father_in, father_out_dup;
    HANDLE current_pid;
    SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
    string new_cmd = NULL, app_name = NULL;

    char buf[1024+1];
    int num;
    extern char *quote_args(char **argv);

    if (look_for_cmd(args[0], &app_name) == FALSE) {
      ret = NULL;
      goto error_exit;
    }

    /* Compute the command line */
    new_cmd = quote_args(args);

    /* We need this handle to duplicate other handles */
    current_pid = GetCurrentProcess();

    ZeroMemory( &si, sizeof(STARTUPINFO) );
    si.cb = sizeof(STARTUPINFO);
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW ;
    si.wShowWindow = /* 0 */ SW_HIDE ;

    /* Child stdin */
    child_in = CreateFile("nul",
                          GENERIC_READ,
                          FILE_SHARE_READ | FILE_SHARE_WRITE,
                          &sa,  /* non inheritable */
                          OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL,
                          NULL);
    si.hStdInput = child_in;

    if (CreatePipe(&father_in, &child_out, NULL, 0) == FALSE) {
      fprintf(stderr, "popen: error CreatePipe\n");
      goto error_exit;
    }
    if (DuplicateHandle(current_pid, child_out,
                        current_pid, &father_out_dup,
                        0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) {
      fprintf(stderr, "popen: error DuplicateHandle father_in\n");
      CloseHandle(father_in);
      CloseHandle(child_out);
      goto error_exit;
    }
    CloseHandle(child_out);
    si.hStdOutput = father_out_dup;

    /* Child stderr */
    if (kpse_make_tex_discard_errors) {
      child_err = CreateFile("nul",
                             GENERIC_WRITE,
                             FILE_SHARE_READ | FILE_SHARE_WRITE,
                             &sa,       /* non inheritable */
                             OPEN_EXISTING,
                             FILE_ATTRIBUTE_NORMAL,
                             NULL);
    }
    else {
      DuplicateHandle(current_pid, GetStdHandle(STD_ERROR_HANDLE),
                      current_pid, &child_err,
                      0, TRUE,
                      DUPLICATE_SAME_ACCESS);
    }
    si.hStdError = child_err;

    /* creating child process */
    if (CreateProcess(app_name, /* pointer to name of executable module */
                      new_cmd,  /* pointer to command line string */
                      NULL,     /* pointer to process security attributes */
                      NULL,     /* pointer to thread security attributes */
                      TRUE,     /* handle inheritance flag */
                      0,                /* creation flags */
                      NULL,     /* pointer to environment */
                      NULL,     /* pointer to current directory */
                      &si,      /* pointer to STARTUPINFO */
                      &pi               /* pointer to PROCESS_INFORMATION */
                      ) == 0) {
      FATAL2("kpathsea: CreateProcess() failed for `%s' (Error %x)\n", new_cmd, GetLastError());
    }

    CloseHandle(child_in);
    CloseHandle(father_out_dup);
    CloseHandle(child_err);

    /* Only the process handle is needed */
    CloseHandle(pi.hThread);

    /* Get stdout of child from the pipe. */
    fn = xstrdup("");
    while (ReadFile(father_in,buf,sizeof(buf)-1, &num, NULL) != 0
           && num > 0) {
      if (num <= 0) {
        if (GetLastError() != ERROR_BROKEN_PIPE) {
          FATAL1("kpathsea: read() error code for `%s' (Error %d)", GetLastError());
          break;
        }
      } else {
        string newfn;
        buf[num] = '\0';
        newfn = concat(fn, buf);
        free(fn);
        fn = newfn;
      }
    }
    /* End of file on pipe, child should have exited at this point. */
    CloseHandle(father_in);

    if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_OBJECT_0) {
      WARNING2("kpathsea: failed to wait for process termination: %s (Error %d)\n",
               new_cmd, GetLastError());
    }

    CloseHandle(pi.hProcess);

    if (new_cmd) free(new_cmd);
    if (app_name) free(app_name);

    if (fn) {
      len = strlen(fn);

      /* Remove trailing newlines and returns.  */
      while (len && (fn[len - 1] == '\n' || fn[len - 1] == '\r')) {
        fn[len - 1] = '\0';
        len--;
      }

      ret = len == 0 ? NULL : kpse_readable_file (fn);
      if (!ret && len > 1) {
        WARNING1 ("kpathsea: mktexpk output `%s' instead of a filename", fn);
      }

      /* Free the name if we're not returning it.  */
      if (fn != ret)
        free (fn);
    }
  error_exit:
    ;
  }
#else
  {
    /* Standard input for the child.  Set to /dev/null */
    int childin;
    /* Standard output for the child, what we're interested in. */
    int childout[2];
    /* Standard error for the child, same as parent or /dev/null */
    int childerr;
    /* Child pid. */
    pid_t childpid;

    /* Open the channels that the child will use. */
    /* A fairly horrible uses of gotos for here for the error case. */
    if ((childin = open("/dev/null", O_RDONLY)) < 0) {
      perror("kpathsea: open(\"/dev/null\", O_RDONLY)");
      goto error_childin;
    }
    if (pipe(childout) < 0) {
      perror("kpathsea: pipe()");
      goto error_childout;
    }
    if ((childerr = open("/dev/null", O_WRONLY)) < 0) {
      perror("kpathsea: open(\"/dev/null\", O_WRONLY)");
      goto error_childerr;
    }
    if ((childpid = fork()) < 0) {
      perror("kpathsea: fork()");
      close(childerr);
     error_childerr:
      close(childout[0]);
      close(childout[1]);
     error_childout:
      close(childin);
     error_childin:
      fn = NULL;
    } else if (childpid == 0) {
      /* Child
       *
       * We can use vfork, provided we're careful about what we
       * do here: do not return from this function, do not modify
       * variables, call _exit if there is a problem.
       *
       * Complete setting up the file descriptors.
       * We use dup(2) so the order in which we do this matters.
       */
      close(childout[0]);
      /* stdin -- the child will not receive input from this */
      if (childin != 0) {
        close(0);
        dup(childin);
        close(childin);
      }
      /* stdout -- the output of the child's action */
      if (childout[1] != 1) {
        close(1);
        dup(childout[1]);
        close(childout[1]);
      }
      /* stderr -- use /dev/null if we discard errors */
      if (childerr != 2) {
        if (kpse_make_tex_discard_errors) {
          close(2);
          dup(childerr);
        }
        close(childerr);
      }
      /* FIXME: We could/should close all other file descriptors as well. */
      /* exec -- on failure a call of _exit(2) it is the only option */
      if (execvp(args[0], args))
        perror(args[0]);
      _exit(1);
    } else {
      /* Parent */
      char buf[1024+1];
      int num;
      int status;

      /* Clean up child file descriptors that we won't use anyway. */
      close(childin);
      close(childout[1]);
      close(childerr);
      /* Get stdout of child from the pipe. */
      fn = xstrdup("");
      while ((num = read(childout[0],buf,sizeof(buf)-1)) != 0) {
        if (num == -1) {
          if (errno != EINTR) {
            perror("kpathsea: read()");
            break;
          }
        } else {
          string newfn;
          buf[num] = '\0';
          newfn = concat(fn, buf);
          free(fn);
          fn = newfn;
        }
      }
      /* End of file on pipe, child should have exited at this point. */
      close(childout[0]);
      /* We don't really care about the exit status at this point. */
      wait(NULL);
    }

    if (fn) {
      len = strlen(fn);

      /* Remove trailing newlines and returns.  */
      while (len && (fn[len - 1] == '\n' || fn[len - 1] == '\r')) {
        fn[len - 1] = '\0';
        len--;
      }

      ret = len == 0 ? NULL : kpse_readable_file (fn);
      if (!ret && len > 1) {
        WARNING1 ("kpathsea: mktexpk output `%s' instead of a filename", fn);
      }

      /* Free the name if we're not returning it.  */
      if (fn != ret)
        free (fn);
    } else {
      ret = NULL;
    }
  }
#endif

  if (ret == NULL)
    misstex (format, args);
  else
    kpse_db_insert (ret);
  
  return ret;
}
Esempio n. 19
0
int option(char *arg) {
  	if (strncmp(arg, "-lccdir=", 8) == 0) {
		if (strcmp(cpp[0], LCCDIR "gcc/cpp") == 0)
			cpp[0] = concat(&arg[8], "/gcc/cpp");
		include[0] = concat("-I", concat(&arg[8], "/include"));
		include[1] = concat("-I", concat(&arg[8], "/gcc/include"));
		ld[9]  = concat(&arg[8], "/gcc/crtbegin.o");
		ld[12] = concat("-L", &arg[8]);
		ld[14] = concat("-L", concat(&arg[8], "/gcc"));
		ld[19] = concat(&arg[8], "/gcc/crtend.o");
		com[0] = concat(&arg[8], "/rcc");
	} else if (strcmp(arg, "-p") == 0 || strcmp(arg, "-pg") == 0) {
		ld[7] = "/usr/lib/gcrt1.o";
		ld[18] = "-lgmon";
	} else if (strcmp(arg, "-b") == 0) 
		;
	else if (strcmp(arg, "-g") == 0)
		;
	else if (strncmp(arg, "-ld=", 4) == 0)
		ld[0] = &arg[4];
	else if (strcmp(arg, "-static") == 0) {
		ld[3] = "-static";
		ld[4] = "";
	} else
		return 0;
	return 1;
}
Esempio n. 20
0
string
xgetcwd (void)
{
    /* If the system provides getcwd, use it.  If not, use getwd if
       available.  But provide a way not to use getcwd: on some systems
       getcwd forks, which is expensive and may in fact be impossible for
       large programs like tex.  If your system needs this define and it
       is not detected by configure, let me know.
                                       -- Olaf Weber <[email protected] */
#if defined (HAVE_GETCWD) && !defined (GETCWD_FORKS)
    char path[PATH_MAX + 1];
#if defined(WIN32)
    string pp;
#endif

    if (getcwd (path, PATH_MAX + 1) == NULL) {
        FATAL_PERROR ("getcwd");
    }

#if defined(WIN32)
    for (pp = path; *pp; pp++) {
        if (*pp == '\\')
            *pp = '/';
#if defined (KPSE_COMPAT_API)
        else if (IS_KANJI(pp))
            pp++;
#endif
    }
#endif

    return xstrdup (path);
#elif defined (HAVE_GETWD)
    char path[PATH_MAX + 1];

    if (getwd (path) == NULL) {
        FATAL_PERROR ("getwd");
    }

    return xstrdup (path);
#else /* (not HAVE_GETCWD || GETCWD_FORKS) && not HAVE_GETWD */
    struct stat root_stat, cwd_stat;
    string cwd_path = (string)xmalloc(2); /* In case we assign "/" below.  */

    *cwd_path = 0;

    /* Find the inodes of the root and current directories.  */
    root_stat = xstat("/");
    cwd_stat  = xstat(".");

    /* Go up the directory hierarchy until we get to root, prepending each
       directory we pass through to `cwd_path'.  */
    while (!SAME_FILE_P(root_stat, cwd_stat)) {
        struct dirent *e;
        DIR *parent_dir;
        boolean found = false;

        xchdir("..");
        parent_dir = xopendir(".");

        /* Look through the parent directory for the entry with the same
           inode, so we can get its name.  */
        while ((e = readdir (parent_dir)) != NULL && !found) {
            struct stat test_stat;
            test_stat = xlstat(e->d_name);

            if (SAME_FILE_P(test_stat, cwd_stat)) {
                /* We've found it.  Prepend the pathname.  */
                string temp = cwd_path;
                cwd_path = concat3("/", e->d_name, cwd_path);
                free(temp);

                /* Set up to test the next parent.  */
                cwd_stat = xstat(".");

                /* Stop reading this directory.  */
                found = true;
            }
        }
        if (!found)
            LIB_FATAL2("No inode %d/device %d in parent directory",
                   cwd_stat.st_ino, cwd_stat.st_dev);

        xclosedir(parent_dir);
    }

    /* If the current directory is the root, cwd_path will be the empty
       string, and we will have not gone through the loop.  */
    if (*cwd_path == 0)
        strcpy(cwd_path, "/");
    else
        /* Go back to where we were.  */
        xchdir(cwd_path);

#ifdef DOSISH
    /* Prepend the drive letter to CWD_PATH, since this technique
       never tells us what the drive is.

       Note that on MS-DOS/MS-Windows, the branch that works around
       missing `getwd' will probably only work for DJGPP (which does
       have `getwd'), because only DJGPP reports meaningful
       st_ino numbers.  But someday, somebody might need this...  */
    {
        char drive[3];
        string temp = cwd_path;

        /* Make the drive letter lower-case, unless it is beyond Z: (yes,
           there ARE such drives, in case of Novell Netware on MS-DOS).  */
        drive[0] = root_stat.st_dev + (root_stat.st_dev < 26 ? 'a' : 'A');
        drive[1] = ':';
        drive[2] = '\0';

        cwd_path = concat(drive, cwd_path);
        free(temp);
    }
#endif

    return cwd_path;
#endif /* (not HAVE_GETCWD || GETCWD_FORKS) && not HAVE_GETWD */
}
Esempio n. 21
0
static void
kgdb_trgt_open(char *filename, int from_tty)
{
	struct cleanup *old_chain;
	struct kthr *kt;
	struct inferior *inf8;
	struct program_space *pspace;
	kvm_t *nkvm;
	char *temp;
	int first_inferior = 1;

	target_preopen (from_tty);
	if (!filename)
		error ("No vmcore file specified.");
	if (!exec_bfd)
		error ("Can't open a vmcore without a kernel");

	filename = tilde_expand (filename);
	if (filename[0] != '/') {
		temp = concat (current_directory, "/", filename, NULL);
		xfree(filename);
		filename = temp;
	}

	old_chain = make_cleanup (xfree, filename);

	nkvm = kvm_openfiles(bfd_get_filename(exec_bfd), filename, NULL,
	    write_files ? O_RDWR : O_RDONLY, kvm_err);
	if (nkvm == NULL)
		error ("Failed to open vmcore: %s", kvm_err);

	/* Don't free the filename now and close any previous vmcore. */
	discard_cleanups(old_chain);
	unpush_target(&kgdb_trgt_ops);

	kvm = nkvm;
	vmcore = filename;
	old_chain = make_cleanup(kgdb_core_cleanup, NULL);

	push_target (&kgdb_trgt_ops);
	discard_cleanups (old_chain);

	kgdb_dmesg();

	init_thread_list();
	kt = kgdb_thr_init();
	while (kt != NULL) {
		if (!in_inferior_list(kt->pid)) {
                     if (first_inferior) {
                       first_inferior = 0;
                       inf8 = current_inferior();
                       inf8->pid = kt->pid;
                       inferior_appeared (inf8, kt->pid);
                       pspace = current_program_space;
                       pspace->ebfd = 0;
                       pspace->ebfd_mtime = 0;
                     } else {                    
                       inf8 = add_inferior(kt->pid);
                       pspace = add_program_space(new_address_space());
                       pspace->symfile_object_file = symfile_objfile;
                       pspace->objfiles = object_files;
                     }
                     inf8->pspace = pspace;
                     inf8->aspace = pspace->aspace;
                }
		add_thread(ptid_build(kt->pid, 0, kt->tid));
		kt = kgdb_thr_next(kt);
	}
	if (curkthr != 0)
		inferior_ptid = ptid_build(curkthr->pid, 0, curkthr->tid);

	frame_unwind_prepend_unwinder(get_frame_arch(get_current_frame()), &kgdb_trgt_trapframe_unwind);

	/* XXX: fetch registers? */
	kld_init();
	reinit_frame_cache();
	select_frame (get_current_frame());
	print_stack_frame(get_selected_frame(NULL),
	  frame_relative_level(get_selected_frame(NULL)), 1);
}
Esempio n. 22
0
static void
process_include (rtx desc, int lineno)
{
  const char *filename = XSTR (desc, 0);
  const char *old_filename;
  int old_lineno;
  char *pathname;
  FILE *input_file;

  /* If specified file name is absolute, skip the include stack.  */
  if (! IS_ABSOLUTE_PATH (filename))
    {
      struct file_name_list *stackp;

      /* Search directory path, trying to open the file.  */
      for (stackp = first_dir_md_include; stackp; stackp = stackp->next)
	{
	  static const char sep[2] = { DIR_SEPARATOR, '\0' };

	  pathname = concat (stackp->fname, sep, filename, NULL);
	  input_file = fopen (pathname, "r");
	  if (input_file != NULL)
	    goto success;
	  free (pathname);
	}
    }

  if (base_dir)
    pathname = concat (base_dir, filename, NULL);
  else
    pathname = xstrdup (filename);
  input_file = fopen (pathname, "r");
  if (input_file == NULL)
    {
      free (pathname);
      message_with_line (lineno, "include file `%s' not found", filename);
      errors = 1;
      return;
    }
 success:

  /* Save old cursor; setup new for the new file.  Note that "lineno" the
     argument to this function is the beginning of the include statement,
     while read_rtx_lineno has already been advanced.  */
  old_filename = read_rtx_filename;
  old_lineno = read_rtx_lineno;
  read_rtx_filename = pathname;
  read_rtx_lineno = 1;

  /* Read the entire file.  */
  while (1)
    {
      rtx desc;
      int c;

      c = read_skip_spaces (input_file);
      if (c == EOF)
	break;

      ungetc (c, input_file);
      lineno = read_rtx_lineno;
      desc = read_rtx (input_file);
      process_rtx (desc, lineno);
    }

  /* Do not free pathname.  It is attached to the various rtx queue
     elements.  */

  read_rtx_filename = old_filename;
  read_rtx_lineno = old_lineno;

  fclose (input_file);
}
Esempio n. 23
0
std::string get_local_meta_name(const std::string &func, const std::string &var)
{
  return concat(func, var);
}
Esempio n. 24
0
static void
process_rtx (rtx desc, int lineno)
{
  switch (GET_CODE (desc))
    {
    case DEFINE_INSN:
      queue_pattern (desc, &define_insn_tail, read_rtx_filename, lineno);
      break;

    case DEFINE_COND_EXEC:
      queue_pattern (desc, &define_cond_exec_tail, read_rtx_filename, lineno);
      break;

    case DEFINE_ATTR:
      queue_pattern (desc, &define_attr_tail, read_rtx_filename, lineno);
      break;

    case INCLUDE:
      process_include (desc, lineno);
      break;

    case DEFINE_INSN_AND_SPLIT:
      {
	const char *split_cond;
	rtx split;
	rtvec attr;
	int i;

	/* Create a split with values from the insn_and_split.  */
	split = rtx_alloc (DEFINE_SPLIT);

	i = XVECLEN (desc, 1);
	XVEC (split, 0) = rtvec_alloc (i);
	while (--i >= 0)
	  {
	    XVECEXP (split, 0, i) = copy_rtx (XVECEXP (desc, 1, i));
	    remove_constraints (XVECEXP (split, 0, i));
	  }

	/* If the split condition starts with "&&", append it to the
	   insn condition to create the new split condition.  */
	split_cond = XSTR (desc, 4);
	if (split_cond[0] == '&' && split_cond[1] == '&')
	  split_cond = concat (XSTR (desc, 2), split_cond, NULL);
	XSTR (split, 1) = split_cond;
	XVEC (split, 2) = XVEC (desc, 5);
	XSTR (split, 3) = XSTR (desc, 6);

	/* Fix up the DEFINE_INSN.  */
	attr = XVEC (desc, 7);
	PUT_CODE (desc, DEFINE_INSN);
	XVEC (desc, 4) = attr;

	/* Queue them.  */
	queue_pattern (desc, &define_insn_tail, read_rtx_filename, lineno);
	queue_pattern (split, &other_tail, read_rtx_filename, lineno);
	break;
      }

    default:
      queue_pattern (desc, &other_tail, read_rtx_filename, lineno);
      break;
    }
}
Esempio n. 25
0
size_t StreamString::write(uint8_t data) {
    return concat((char) data);
}
Esempio n. 26
0
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_CREATE:
	{
			
					HWND statik=  CreateWindowEx(0,
						  "STATIC",
						  NULL,
						  WS_CHILD | WS_VISIBLE|SS_CENTER,
						  40, 10, 300, 200,
						  hWnd,
						  NULL,
						 NULL,
						  NULL);
					
					SetWindowText(
						 statik,
						 "Pentru ctriptare introduceti textul si apasati \"Cripteaza\".\nPentru decriptare va trebui sa selectati un fisier din care textul va fi preluat automat."
						);



					  // Create an edit box
					  hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
						  "EDIT",
						  "",
						  WS_CHILD | WS_VISIBLE |
						  ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
						 40,
						  80,
						 300 ,
						  200,
						  hWnd,
						  (HMENU)IDC_MAIN_EDIT,
						  GetModuleHandle(NULL),
						  NULL);
					  HGDIOBJ hfDefault = GetStockObject(DEFAULT_GUI_FONT);
					  SendMessage(hEdit,
						  WM_SETFONT,
						  (WPARAM)hfDefault,
						  MAKELPARAM(FALSE, 0));
					  SendMessage(hEdit,
						  WM_SETTEXT,
						  NULL,
						  (LPARAM)"");

					  // Create a push button
					  HWND hWndButton = CreateWindowEx(NULL,
						  "BUTTON",
						  "CRIPTEAZA",
						  WS_TABSTOP | WS_VISIBLE |
						  WS_CHILD | BS_DEFPUSHBUTTON,
						  40,
						  300,
						  120,
						  40,
						  hWnd,
						  (HMENU)IDC_MAIN_BUTTON,
						  GetModuleHandle(NULL),
						  NULL);
					  SendMessage(hWndButton,
						  WM_SETFONT,
						  (WPARAM)hfDefault,
						  MAKELPARAM(FALSE, 0));


					  HWND hWndButton2 = CreateWindowEx(NULL,
						  "BUTTON",
						  "DECRIPTEAZA",
						  WS_TABSTOP | WS_VISIBLE |
						  WS_CHILD | BS_DEFPUSHBUTTON,
						  220,
						  300,
						  120,
						  40,
						  hWnd,
						  (HMENU)IDC_MAIN_BUTTON2,
						  GetModuleHandle(NULL),
						  NULL);
					  SendMessage(hWndButton2,
						  WM_SETFONT,
						  (WPARAM)hfDefault,
						  MAKELPARAM(FALSE, 0));
	}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDC_MAIN_BUTTON:
		{
								

								char buffer[25600];
								char bufferfin[25600];
								char lit[2];
								lit[1] = '\0';
								bufferfin[0] = '\0';
								SendMessage(hEdit,
									WM_GETTEXT,
									sizeof(buffer) / sizeof(buffer[0]),
									reinterpret_cast<LPARAM>(buffer));
								FILE*A;
								if (strlen(buffer) == 0){ MessageBox(hWnd, "Eroare,introduceti text.", "Error", MB_OK | MB_ICONERROR); break; }
								else
									MessageBox(hWnd, "Alegeti fisierul in care va fi stocata informatia rezultata.", "Browse", MB_OK | MB_ICONINFORMATION);


								int* v = NULL;
								int* rem = NULL;
								int* descris = NULL;
								int* decode = NULL;
								int i, j = 0;
								unsigned char c = char(1), b;
								
								FILE*B=NULL;
								for (int i = 0; i< strlen(buffer); i++)
								{
									c = buffer[i];
									v = encrypt(c, 3);
									concat(&rem, &v);
									descris = impartire(v, &rem);
									while (descris[0]>1)
									{

										b = char_codat(&descris);
										//fwrite(&b, sizeof(unsigned char), 1, B);
										lit[0] = b;
										strcat(bufferfin, lit);

									}
									free(descris);
								}
								restfin(&rem);
								b = char_codat(&rem);
								//fwrite(&b, sizeof(unsigned char), 1, B);
								lit[0] = b;
								strcat(bufferfin, lit);
			
								free(rem);

								OPENFILENAME ofn;
								char szFileName[MAX_PATH] = "";

								ZeroMemory(&ofn, sizeof(ofn));

								ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
								ofn.hwndOwner = hWnd;
								ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
								ofn.lpstrFile = szFileName;
								ofn.nMaxFile = MAX_PATH;
								ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
								ofn.lpstrDefExt = "txt";

								if (GetOpenFileName(&ofn))
								{
									B = fopen(szFileName, "wb");
									
									for (i = 0; i < strlen(bufferfin); i++)
									{
										
										fwrite(&(bufferfin[i]), sizeof(unsigned char), 1, B);
									}

								}
								if (B == NULL)break;
								if(B!=NULL)fclose(B);
								MessageBox(hWnd, "Criptat cu succes.", "Succes", MB_OK | MB_ICONINFORMATION);
						
							SetWindowText(hEdit, "");
								break;
		}


		case IDC_MAIN_BUTTON2:
		{
								 MessageBox(hWnd, "Alegeti fisierul din care se va incarca mesajul codat.", "Browse", MB_OK | MB_ICONINFORMATION);
								FILE*A=NULL, *B=NULL;
								OPENFILENAME ofn;
								char szFileName[MAX_PATH] = "";

								ZeroMemory(&ofn, sizeof(ofn));

								ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
								ofn.hwndOwner = hWnd;
								ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
								ofn.lpstrFile = szFileName;
								ofn.nMaxFile = MAX_PATH;
								ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
								ofn.lpstrDefExt = "txt";

								if (GetOpenFileName(&ofn))
								{
									A = fopen(szFileName, "rb");
									

								}

								if (A == NULL)break;
								
								
								MessageBox(hWnd, "Alegeti fisierul in care va fi stocata informatia rezultata.", "Browse", MB_OK | MB_ICONINFORMATION);
								ZeroMemory(&ofn, sizeof(ofn));

								ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
								ofn.hwndOwner = hWnd;
								ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
								ofn.lpstrFile = szFileName;
								ofn.nMaxFile = MAX_PATH;
								ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
								ofn.lpstrDefExt = "txt";

								if (GetOpenFileName(&ofn))
								{
									B = fopen(szFileName, "wb");
									
								}
								if (B == NULL)break;

								int* v = NULL;
								int* rem = NULL;
								int* descris = NULL;
								int* decode = NULL;
								int i, j = 0;
								unsigned char c = char(1), b;
								while (c != unsigned char(0))
								{
									decode = (int*)malloc(sizeof(int));
									decode[0] = 1;
									concat(&rem, &decode);
									while (verif_ok(decode, 3) == 0)
									{


										if (fread(&c, sizeof(unsigned char), 1, A))
										{
											if (verif_ok(decode, 3) == 0)
											{
												v = obt_vct_codat(c);
												bag_vect_la_sf(&decode, v);
											}

										}
										else { c = unsigned char(0); break; }
									}
									while (verif_ok(decode, 3) == 1 && (!rest0(decode)))
									{
										b = obt_char(decode, 3);
										fwrite(&b, sizeof(unsigned char), 1, B);
										scindare(&decode, 3);
										if (rest0(decode))c = unsigned char(0);
									}
									rem = (int*)malloc(sizeof(int));
									rem[0] = 1;
									concat(&decode, &rem);
								}
								fclose(A);
								fclose(B);
								MessageBox(hWnd, "Decriptat cu succes.", "Succes", MB_OK | MB_ICONINFORMATION);


								break;
								
		}



			break;
		}
		break;

	case WM_DESTROY:
	{
					   PostQuitMessage(0);
					   return 0;
	}
		break;
	}

	return DefWindowProc(hWnd, msg, wParam, lParam);
}
Esempio n. 27
0
int main(int argc, char *argv[])
{
	char filename[50];
	char buffer[3],c;
	filename[0]='\0';
	char str1[10]="/proc/\0";
	char str2[10]="/status\0";
	if(argc==1)
	{
		printf("Error: PID not given\n");
		exit(0);
	}
	concat(filename,str1);
	concat(filename,argv[1]);
	concat(filename,str2);
	//printf("%s",filename);
	//write(1,filename,len(filename));
	
	int ntemp,fp=open(filename,O_RDONLY);
	if(fp<0)
	{
		printf("Process ID not found");
		return 0;
	}
	char tmpstr[2],line[50],val[50];
	int tmpi=0,tmpflag=0,z=0;
	while(ntemp=read(fp, buffer, 1))
	{
		c=buffer[0];
		tmpstr[0]=c;
		tmpstr[1]='\0';
		if(tmpflag&&c=='\t')
			continue;
		if(c=='\n')
		{
			if(tmpflag)
			{
				val[z]='\0';
				if(tmpflag==1)
					write(1,"State: ",7);
				else if(tmpflag==2)
					write(1,"Parent ID: ",11);
				else if(tmpflag==3)
					write(1,"Threads: ",9);
				write(1,val,len(val));
				write(1,"\n",2);
				//write(1,line,len(line));
			}
			tmpi=0;
			z=0;
			tmpflag=0;
			line[0]='\0';
			val[0]='\0';
			continue;
		}
		if(tmpflag)
		{
			val[z++]=c;
		}
		if(c==':')
		{
			line[tmpi]='\0';
			if(compare(line,"State"))
				tmpflag=1;
			if(compare(line,"PPid"))
				tmpflag=2;
			if(compare(line,"Threads"))
				tmpflag=3;
		}
		else if(!tmpflag)
			line[tmpi++]=c;
	}
	return 0;
}
Esempio n. 28
0
/* This will be called by the spec parser in gcc.c when it sees
   a %:local_cpu_detect(args) construct.  Currently it will be called
   with either "arch" or "tune" as argument depending on if -march=native
   or -mtune=native is to be substituted.

   It returns a string containing new command line parameters to be
   put at the place of the above two options, depending on what CPU
   this is executed.  E.g. "-march=zEC12" on a zEC12 for -march=native.
   If the routine can't detect a known processor, the -march or -mtune
   option is discarded.

   ARGC and ARGV are set depending on the actual arguments given
   in the spec.  */
const char *
s390_host_detect_local_cpu (int argc, const char **argv)
{
  const char *cpu = NULL;
  char buf[256];
  FILE *f;
  bool arch;
  const char *options = "";
  unsigned int has_features;
  unsigned int has_processor;
  unsigned int is_cpu_z9_109 = 0;
  unsigned int has_highgprs = 0;
  unsigned int has_dfp = 0;
  unsigned int has_te = 0;
  unsigned int has_vx = 0;
  unsigned int has_opt_esa_zarch = 0;
  int i;

  if (argc < 1)
    return NULL;

  arch = strcmp (argv[0], "arch") == 0;
  if (!arch && strcmp (argv[0], "tune"))
    return NULL;
  for (i = 1; i < argc; i++)
    if (strcmp (argv[i], "mesa_mzarch") == 0)
      has_opt_esa_zarch = 1;

  f = fopen ("/proc/cpuinfo", "r");
  if (f == NULL)
    return NULL;

  for (has_features = 0, has_processor = 0;
       (has_features == 0 || has_processor == 0)
	 && fgets (buf, sizeof (buf), f) != NULL; )
    {
      if (has_processor == 0 && strncmp (buf, "processor", 9) == 0)
	{
	  const char *p;
	  long machine_id;

	  p = strstr (buf, "machine = ");
	  if (p == NULL)
	    continue;
	  p += 10;
	  has_processor = 1;
	  machine_id = strtol (p, NULL, 16);
	  switch (machine_id)
	    {
	      /* g5 and g6 default to z900 */
	    case 0x9672:
	    case 0x2064:
	    case 0x2066:
	      cpu = "z900";
	      break;
	    case 0x2084:
	    case 0x2086:
	      cpu = "z990";
	      break;
	    case 0x2094:
	    case 0x2096:
	      cpu = "z9-109";
	      is_cpu_z9_109 = 1;
	      break;
	    case 0x2097:
	    case 0x2098:
	      cpu = "z10";
	      break;
	    case 0x2817:
	    case 0x2818:
	      cpu = "z196";
	      break;
	    case 0x2827:
	    case 0x2828:
	      cpu = "zEC12";
	      break;
	    case 0x2964:
	      cpu = "z13";
	      break;
	    }
	}
      if (has_features == 0 && strncmp (buf, "features", 8) == 0)
	{
	  const char *p;

	  p = strchr (buf, ':');
	  if (p == NULL)
	    continue;
	  p++;
	  while (*p != 0)
	    {
	      int i;

	      while (ISSPACE (*p))
		p++;
	      for (i = 0; !ISSPACE (p[i]) && p[i] != 0; i++)
		;
	      if (i == 3 && strncmp (p, "dfp", 3) == 0)
		has_dfp = 1;
	      else if (i == 2 && strncmp (p, "te", 2) == 0)
		has_te = 1;
	      else if (i == 2 && strncmp (p, "vx", 2) == 0)
		has_vx = 1;
	      else if (i == 8 && strncmp (p, "highgprs", 8) == 0)
		has_highgprs = 1;
	      p += i;
	    }
	  has_features = 1;
	}
    }

  fclose (f);

  if (cpu == NULL)
    return NULL;

  if (arch)
    {
      const char *opt_htm = "";
      const char *opt_vx = "";
      const char *opt_esa_zarch = "";

      /* We may switch off these cpu features but never switch the on
	 explicitly.  This overrides options specified on the command line.  */
      if (!has_te)
	opt_htm = " -mno-htm";
      if (!has_vx)
	opt_vx = " -mno-vx";
      /* However, we set -mzarch only if neither -mzarch nor -mesa are used on
	 the command line.  This allows the user to switch to -mesa manually.
      */
      if (!has_opt_esa_zarch && has_highgprs)
	opt_esa_zarch = " -mzarch";
      options = concat (options, opt_htm, opt_vx, opt_esa_zarch, NULL);
    }
  if (has_dfp && is_cpu_z9_109)
    cpu = "z9-ec";

  return concat ("-m", argv[0], "=", cpu, options, NULL);
}
Esempio n. 29
0
Node *regexp(void)	/* top-level parse of reg expr */
{
	return (alt(concat(primary())));
}
Esempio n. 30
0
/*
 * build separate list of statements and cases
 * make labels between cases and statements
 * deal with fallthrough, break, unreachable statements
 */
static void
casebody(Node *sw, Node *typeswvar)
{
	Node *n, *c, *last;
	Node *def;
	NodeList *cas, *stat, *l, *lc;
	Node *go, *br;
	int32 lno, needvar;

	if(sw->list == nil)
		return;

	lno = setlineno(sw);

	cas = nil;	// cases
	stat = nil;	// statements
	def = N;	// defaults
	br = nod(OBREAK, N, N);

	for(l=sw->list; l; l=l->next) {
		n = l->n;
		setlineno(n);
		if(n->op != OXCASE)
			fatal("casebody %O", n->op);
		n->op = OCASE;
		needvar = count(n->list) != 1 || n->list->n->op == OLITERAL;

		go = nod(OGOTO, newlabel(), N);
		if(n->list == nil) {
			if(def != N)
				yyerror("more than one default case");
			// reuse original default case
			n->right = go;
			def = n;
		}

		if(n->list != nil && n->list->next == nil) {
			// one case - reuse OCASE node.
			c = n->list->n;
			n->left = c;
			n->right = go;
			n->list = nil;
			cas = list(cas, n);
		} else {
			// expand multi-valued cases
			for(lc=n->list; lc; lc=lc->next) {
				c = lc->n;
				cas = list(cas, nod(OCASE, c, go));
			}
		}

		stat = list(stat, nod(OLABEL, go->left, N));
		if(typeswvar && needvar && n->nname != N) {
			NodeList *l;

			l = list1(nod(ODCL, n->nname, N));
			l = list(l, nod(OAS, n->nname, typeswvar));
			typechecklist(l, Etop);
			stat = concat(stat, l);
		}
		stat = concat(stat, n->nbody);

		// botch - shouldn't fall thru declaration
		last = stat->end->n;
		if(last->xoffset == n->xoffset && last->op == OXFALL) {
			if(typeswvar) {
				setlineno(last);
				yyerror("cannot fallthrough in type switch");
			}
			if(l->next == nil) {
				setlineno(last);
				yyerror("cannot fallthrough final case in switch");
			}
			last->op = OFALL;
		} else
			stat = list(stat, br);
	}

	stat = list(stat, br);
	if(def)
		cas = list(cas, def);

	sw->list = cas;
	sw->nbody = stat;
	lineno = lno;
}