int reexec_to_match_lp64ness(bool isLP64)
{
	cpu_type_t kernarch, progarch, targetarch;
	char *alreadyenv;
	
	alreadyenv = getenv(kReExecToMatchLP64);
	if (alreadyenv) {
		/* we've done this at least once, assume
		   another try won't help */
		return 0;
	}

	kernarch = current_kernel_arch();
	progarch = current_program_arch();

	if (kernarch == 0) {
		/* could not determine kernel arch */
		errno = EINVAL;
		return -1;
	}

	if (isLP64) {
		targetarch = kernarch | CPU_ARCH_ABI64;
	} else {
		targetarch = kernarch & ~CPU_ARCH_ABI64;
	}

	if (targetarch == progarch) {
		/* nothing to do here */
		return 0;
	}

	/* Now we need to re-exec */
	return reexec(targetarch, kReExecToMatchLP64);
}
int reexec_to_match_kernel(void)
{
	cpu_type_t kernarch, progarch;
	char *alreadyenv;
	
	alreadyenv = getenv(kReExecToMatchKernel);
	if (alreadyenv) {
		/* we've done this at least once, assume
		   another try won't help */
		return 0;
	}

	kernarch = current_kernel_arch();
	progarch = current_program_arch();

	if (kernarch == 0) {
		/* could not determine kernel arch */
		errno = EINVAL;
		return -1;
	}

	if (kernarch == progarch) {
		/* nothing to do here */
		return 0;
	}

	/* Now we need to re-exec */
	return reexec(kernarch, kReExecToMatchKernel);
}
Beispiel #3
0
static void help(cbot_event_t event, cbot_actions_t actions)
{
  // Make sure the message is addressed to the bot.
  int increment = actions.addressed(event.bot, event.message);
  if (!increment)
    return;

  // Make sure the message matches our regex.
  if (reexec(r, event.message + increment, NULL) == -1)
    return;

  // Send the help text.
  size_t i;
  for (i = 0; i < sizeof(help_lines)/sizeof(char*); i++) {
    actions.send(event.bot, event.username, help_lines[i]);
  }
}
Beispiel #4
0
int
substitute(regex_t *re, Text *data)
{
	word n;
	int c;
	regmatch_t matches[100];
	if(reexec(re, (char*)data->s, data->w - data->s, elementsof(matches), matches, 0))
		return 0;
	if(c = regsubexec(re, (char*)data->s, elementsof(matches), matches)) {
		reerror(re, c);
		return 0;
	}
	n = re->re_sub->re_len;
	assure(data, n+1);
	memcpy(data->s, re->re_sub->re_buf, n+1);
	data->w = data->s + n;
	return 1;
}
Beispiel #5
0
static void emote(cbot_event_t event, cbot_actions_t actions)
{
  size_t *captures = NULL;
  int incr = actions.addressed(event.bot, event.message);

  if (!incr)
    return;

  event.message += incr;

  if (reexec(r, event.message, &captures) == -1) {
    return;
  }

  Captures c = recap(event.message, captures, renumsaves(r));

  actions.me(event.bot, event.channel, c.cap[0]);

  recapfree(c);
}
Beispiel #6
0
int
main(int argc, char *argv[])
{
    re_cod cod;
    re_mat mat[10];
    int line, ecode, i, len, group, failed;
    long eo, so;
    char buf[8192];
    char str[8192];
    FILE *fp = fopen("tests.txt", "r");

    if (fp == NULL) {
	fprintf(stderr, "failed to open tests.txt\n");
	exit(1);
    }

    ecode = line = group = failed = 0;
    cod.cod = NULL;
    while (fgets(buf, sizeof(buf), fp)) {
	++line;
	if (buf[0] == '#' || buf[0] == '\n')
	    continue;
	else if (buf[0] == '/') {
	    char *ptr = strrchr(buf, '/');

	    if (ptr == buf) {
		fprintf(stderr, "syntax error at line %d\n", line);
		break;
	    }
	    else {
		int flags = 0;

		refree(&cod);
		for (*ptr++ = '\0'; *ptr; ptr++) {
		    if (*ptr == 'i')
			flags |= RE_ICASE;
		    else if (*ptr == 'n')
			flags |= RE_NEWLINE;
		}
		ecode = recomp(&cod, buf + 1, flags);
		failed = ecode;
	    }
	}
	else if (buf[0] == '>') {
	    if (cod.cod == NULL) {
		fprintf(stderr, "no previous pattern at line %d\n", line);
		break;
	    }
	    len = strlen(buf) - 1;
	    buf[len] = '\0';
	    strcpy(str, buf + 1);
	    for (i = 0, --len; i < len - 1; i++) {
		if (str[i] == '\\') {
		    memmove(str + i, str + i + 1, len);
		    --len;
		    switch (str[i]) {
			case 'a':
			    str[i] = '\a';
			    break;
			case 'b':
			    str[i] = '\b';
			    break;
			case 'f':
			    str[i] = '\f';
			    break;
			case 'n':
			    str[i] = '\n';
			    break;
			case 'r':
			    str[i] = '\r';
			    break;
			case 't':
			    str[i] = '\t';
			    break;
			case 'v':
			    str[i] = '\v';
			    break;
			default:
			    break;
		    }
		}
	    }
	    group = 0;
	    ecode = reexec(&cod, str, 10, &mat[0], 0);
	    if (ecode && ecode != RE_NOMATCH) {
		reerror(failed, &cod, buf, sizeof(buf));
		fprintf(stderr, "%s, at line %d\n", buf, line);
		break;
	    }
	}
	else if (buf[0] == ':') {
	    if (failed) {
		len = strlen(buf) - 1;
		buf[len] = '\0';
		if (failed == RE_EESCAPE && strcmp(buf, ":EESCAPE") == 0)
		    continue;
		if (failed == RE_ESUBREG && strcmp(buf, ":ESUBREG") == 0)
		    continue;
		if (failed == RE_EBRACK && strcmp(buf, ":EBRACK") == 0)
		    continue;
		if (failed == RE_EPAREN && strcmp(buf, ":EPAREN") == 0)
		    continue;
		if (failed == RE_EBRACE && strcmp(buf, ":EBRACE") == 0)
		    continue;
		if (failed == RE_EBADBR && strcmp(buf, ":EBADBR") == 0)
		    continue;
		if (failed == RE_ERANGE && strcmp(buf, ":ERANGE") == 0)
		    continue;
		if (failed == RE_ESPACE && strcmp(buf, ":ESPACE") == 0)
		    continue;
		if (failed == RE_BADRPT && strcmp(buf, ":BADRPT") == 0)
		    continue;
		if (failed == RE_EMPTY && strcmp(buf, ":EMPTY") == 0)
		    continue;
		reerror(failed, &cod, buf, sizeof(buf));
		fprintf(stderr, "Error value %d doesn't match: %s, at line %d\n",
			failed, buf, line);
		break;
	    }
	    else if (!ecode) {
		fprintf(stderr, "found match when shoudn't, at line %d\n", line);
		break;
	    }
	}
	else {
	    if (failed) {
		reerror(failed, &cod, buf, sizeof(buf));
		fprintf(stderr, "%s, at line %d\n", buf, line);
		break;
	    }
	    if (sscanf(buf, "%ld,%ld:", &so, &eo) != 2) {
		fprintf(stderr, "expecting match offsets at line %d\n", line);
		break;
	    }
	    else if (ecode) {
		fprintf(stderr, "didn't match, at line %d\n", line);
		break;
	    }
	    else if (group >= 10) {
		fprintf(stderr, "syntax error at line %d (too many groups)\n",
			line);
		break;
	    }
	    else if (so != mat[group].rm_so || eo != mat[group].rm_eo) {
		fprintf(stderr, "match failed at line %d, got %ld,%ld: ",
			line, mat[group].rm_so, mat[group].rm_eo);
		if (mat[group].rm_so < mat[group].rm_eo)
		    fwrite(str + mat[group].rm_so,
		 	   mat[group].rm_eo - mat[group].rm_so, 1, stderr);
		fputc('\n', stderr);
		break;
	    }
	    ++group;
	}
    }

    fclose(fp);

    return (ecode);
}
Beispiel #7
0
/* SIGUSR2 handling.  Creates a new master/worker set as a
 * slave of the current * master without affecting old workers.
 * Use this to do live deployment with the ability to backout a change. */
void handleUsr2()
{
    wheatLog(WHEAT_NOTICE, "Signal usr2: %s reexec", Server.master_name);
    reexec();
}
Beispiel #8
0
Datei: regex.c Projekt: 8l/xedit
LispObj *
Lisp_Reexec(LispBuiltin *builtin)
/*
 re-exec regex string &key count start end notbol noteol
 */
{
    size_t nmatch;
    re_mat match[10];
    long start, end, length;
    int code, cflags, eflags;
    char *string;
    LispObj *result;
    re_cod *regexp;

    LispObj *regex, *ostring, *count, *ostart, *oend, *notbol, *noteol;

    noteol = ARGUMENT(6);
    notbol = ARGUMENT(5);
    oend = ARGUMENT(4);
    ostart = ARGUMENT(3);
    count = ARGUMENT(2);
    ostring = ARGUMENT(1);
    regex = ARGUMENT(0);

    if (STRINGP(regex))
	regexp = LispRecomp(builtin, THESTR(regex), cflags = 0);
    else {
	CHECK_REGEX(regex);
	regexp = regex->data.regex.regex;
	cflags = regex->data.regex.options;
    }

    CHECK_STRING(ostring);

    if (count == UNSPEC)
	nmatch = 1;
    else {
	CHECK_INDEX(count);
	nmatch = FIXNUM_VALUE(count);
	if (nmatch > 10)
	    LispDestroy("%s: COUNT cannot be larger than 10", STRFUN(builtin));
    }
    if (nmatch && (cflags & RE_NOSUB))
	nmatch = 1;

    eflags = RE_STARTEND;
    if (notbol != UNSPEC && notbol != NIL)
	eflags |= RE_NOTBOL;
    if (noteol != UNSPEC && noteol != NIL)
	eflags |= RE_NOTEOL;

    string = THESTR(ostring);
    LispCheckSequenceStartEnd(builtin, ostring, ostart, oend,
			      &start, &end, &length);

    match[0].rm_so = start;
    match[0].rm_eo = end;
    code = reexec(regexp, string, nmatch, &match[0], eflags);

    if (code == 0) {
	if (nmatch && match[0].rm_eo >= match[0].rm_so) {
	    result = CONS(CONS(FIXNUM(match[0].rm_so),
			       FIXNUM(match[0].rm_eo)), NIL);
	    if (nmatch > 1 && match[1].rm_eo >= match[1].rm_so) {
		int i;
		GC_ENTER();
		LispObj *cons = result;

		GC_PROTECT(result);
		for (i = 1;
		     i < nmatch && match[i].rm_eo >= match[i].rm_so;
		     i++) {
		    RPLACD(cons, CONS(CONS(FIXNUM(match[i].rm_so),
					   FIXNUM(match[i].rm_eo)), NIL));
		    cons = CDR(cons);
		}
		GC_LEAVE();
	    }
	}
	else
	    result = NIL;
    }
    else
	result = Knomatch;

    /* Maybe shoud cache compiled regex, but better the caller do it */
    if (!XREGEXP(regex)) {
	refree(regexp);
	LispFree(regexp);
    }

    return (result);
}