Exemplo n.º 1
0
Arquivo: a_quit.c Projeto: wfp5p/elm
void exit_alias(void)
{

	int i;

	/* Clear the deletes from all aliases.  */

	for(i = 0; i < num_aliases; i++)
	  if (ison(aliases[i]->status, DELETED))
	    clearit(aliases[i]->status, DELETED);

	dprint(6, (debugfile, "\nexit_alias:  Done clearing deletes.\n"));

}
Exemplo n.º 2
0
static void
delete_function()
{
    char *str = XmTextGetString(function_name);
    int warn = !!ison(glob_flags, WARNINGS);

    ask_item = function_name;
    turnon(glob_flags, WARNINGS);
    (void) cmd_line(zmVaStr("\\function -d %s", str), NULL_GRP);
    if (!warn)
	turnoff(glob_flags, WARNINGS);
    XtFree(str);
    XmTextSetString(function_name, NULL);
    XmTextSetString(script_input, NULL);
}
Exemplo n.º 3
0
/*
 * Make the current board setup.  It picks a random pattern and
 * calls ison() to determine if the character is on that pattern
 * or not.
 */
makeboard()
{
	reg int		y, x;
	reg LOCS	*lp;

	Pattern = rand() % MAXPATTERNS;
	lp = Layout;
	for (y = 0; y < NLINES; y++)
		for (x = 0; x < NCOLS; x++)
			if (ison(y, x)) {
				lp->y = y;
				lp->x = x;
				lp++;
			}
	Numstars = lp - Layout;
}
Exemplo n.º 4
0
Arquivo: dups.c Projeto: clamiax/misc
int main(void)
{
   int tree[SIZE] = { 0 };
   int num, p = 0; /* the number and its position */

   int i; /* just a counter */

   srand( time(NULL) );

   for(i = 1; i <= SIZE; i++) {
      num = 1 + rand() % 20;
      if( !ison(num, tree, SIZE) )
	 tree[p++] = num;
   }

   for(i = 0; i < SIZE; i++)
      if(tree[i])
         printf("%d ", tree[i]);

   printf("\n");

   return 0;
} /* E0F main */
Exemplo n.º 5
0
Arquivo: alias.c Projeto: wfp5p/elm
static int add_alias(int replace, int to_replace)
{
/*
 *	Add an alias to the user alias text file.  If there
 *	are aliases tagged, the user is asked if he wants to
 *	create a group alias from the tagged files.
 *
 *	Return zero if alias not added in actuality.
 *
 *	If replace == FALSE, then we will ask for the new
 *	aliasname.
 *
 *	If replace == TRUE, then we are replacing the alias
 *	denoted by to_replace.
 *
 *	Note that even if replace == FALSE, if the user types
 *	in the name of a current alias then we can still do
 *	a replacement.
 */

	int i, ans;
	int tagged = 0;
	int leftoff = 0;
	char aliasname[SLEN], firstname[SLEN], lastname[SLEN];
	char address1[LONG_STRING], buffer[SLEN];
	char comment[LONG_STRING];
	char *ch_ptr;

/*
 *	See if there are any tagged aliases.
 */
	for (i=0; i < num_aliases; i++) {
	    if (ison(aliases[i]->status, TAGGED)) {
		if (tagged == 0) leftoff = i;
	        tagged++;
	    }
	}

	if (tagged == 1) {
	 /*
	  * There is only on alias tagged.  Ask the question
	  * but the default response is NO.
	  */
	    PutLine(LINES-2,0, catgets(elm_msg_cat,
	            AliasesSet, AliasesOneTagged,
	            "There is 1 alias tagged..."));
	    CleartoEOLN();
	    ans = enter_yn(catgets(elm_msg_cat, AliasesSet, AliasesCreateGroup,
			"Create group alias?"), FALSE, LINES-3, FALSE);
	}
	else if (tagged > 1) {
	 /*
	  * If multiple tagged aliases then we assume the user
	  * wants to create a group alias.  The default response
	  * is YES.
	  */
	    PutLine(LINES-2,0, catgets(elm_msg_cat,
	            AliasesSet, AliasesManyTagged,
	            "There are %d aliases tagged..."), tagged);
	    CleartoEOLN();
	    ans = enter_yn(catgets(elm_msg_cat, AliasesSet, AliasesCreateGroup,
			"Create group alias?"), TRUE, LINES-3, FALSE);
	} else {
	    /*
	     * Nothing tagged ... thus nothing to make a group of.
	     */
	    ans = FALSE;
	}

/*
 *	If requested above, create the group alias address.
 */
	if (ans) {
	    strcpy(address1, aliases[leftoff]->alias);
	    for (i=leftoff+1; i < num_aliases; i++) {
	        if (ison(aliases[i]->status, TAGGED)) {
	            strcat(address1, ",");
	            strcat(address1, aliases[i]->alias);
	        }
	    }
	}
	else {
	    tagged = 0;
	}

/*
 *	Only ask for an aliasname if we are NOT replacing the
 *	current alias.
 */
	if (replace) {
	    strcpy(aliasname, aliases[to_replace]->alias);
	/*
	 *  First, see if what we are replacing is a SYSTEM
	 *  alias.  If so, we need to ask a question.
	 */
	    if(aliases[to_replace]->type & SYSTEM) {
	        dprint(3, (debugfile,
	            "Aliasname [%s] is SYSTEM in add_alias\n", aliasname));
	    /*
	     *  If they don't want to superceed the SYSTEM alias then
	     *  just return.
	     */
	        if( ! superceed_system(to_replace)) {
	            ClearLine(LINES-2);
	            return(0);
	        }
	    }
	}
	else {
	    strcpy(buffer, catgets(elm_msg_cat,
	            AliasesSet, AliasesEnterAliasName, "Enter alias name: "));
	    PutLine(LINES-2,0, buffer);
	    CleartoEOLN();
	    *aliasname = '\0';
	    if ((replace = get_aliasname(aliasname, buffer, &to_replace)) < 0) {
	        dprint(3, (debugfile,
	            "Aliasname [%s] was rejected in add_alias\n", aliasname));
	        ClearLine(LINES-2);
	        return(0);
	    }
	}

/*
 *	If we are replacing an existing alias, we will assume that
 *	they might want to be just editing most of what is already
 *	there.  So we copy some defaults from the existing alias.
 */
	if (replace) {
	    strcpy(lastname, aliases[to_replace]->last_name);
	    strcpy(firstname, aliases[to_replace]->name);
	    ch_ptr = strstr(firstname, lastname);
	    *(ch_ptr-1) = '\0';
	    strcpy(comment, aliases[to_replace]->comment);
	}
	else {
	    *lastname = '\0';
	    *firstname = '\0';
	    *comment = '\0';
	}
	get_realnames(aliasname, firstname, lastname, comment, buffer);

/*
 *	Since there are no tagged aliases, we must ask for an
 *	address.  If we are replacing, a default address is
 *	presented.
 */
	if (tagged == 0) {
	    sprintf(buffer, catgets(elm_msg_cat,
	            AliasesSet, AliasesEnterAddress,
	            "Enter address for %s: "), aliasname);
	    PutLine(LINES-2, 0, buffer);
	    if (replace)
	        strcpy(address1, aliases[to_replace]->address);
	    else
	        *address1 = '\0';

	    if (enter_string(address1, sizeof(address1), -1, -1,
			ESTR_REPLACE) < 0 || address1[0] == '\0') {
		Raw(ON);
	        show_error(catgets(elm_msg_cat, AliasesSet, AliasesNoAddressSpec,
	                "No address specified!"));
	        return(0);
	    }
	    Raw(ON);

	    despace_address(address1);

	    clear_error();			/* Just in case */
	}

	if(ask_accept(aliasname, firstname, lastname, comment, address1,
	        buffer, replace, to_replace)) {
	 /*
	  * We can only clear the tags after we know that the
	  * alias was added.  This allows the user to back out
	  * and rethink without losing the tags.
	  */
	    if (tagged > 0) {
	        for (i=leftoff; i < num_aliases; i++) {
	            if (ison(aliases[i]->status, TAGGED)) {
	                clearit(aliases[i]->status, TAGGED);
	                show_msg_tag(i);
	            }
	        }
	    }
	    return(1);
	}
	else {
	    return(0);
	}

}
Exemplo n.º 6
0
Arquivo: alias.c Projeto: wfp5p/elm
static int ask_accept(char *aliasname, char *firstname, char *lastname,
	       char *comment, char *address, char *buffer,
	       int replace, int replacement)
{
	int ans;
	char *(old_alias[1]);
/*
 *	If firstname == lastname, they probably just took all
 *	the deafaults.  We *assume* they don't want lastname
 *	entered twice, so we will truncate it.
 */
	if (strcmp(firstname, lastname) == 0) {
	    *firstname = '\0';
	}

	if (strlen(firstname) == 0) {
	    strcpy(buffer, lastname);
	}
	else {
	    sprintf(buffer, "%s %s", firstname, lastname);
	}
	PutLine(LINES-1,0, catgets(elm_msg_cat, AliasesSet, AliasesAddressAs,
	        "Messages addressed as: %s (%s)"), address, buffer);
	if (strlen(comment) != 0) {
	    strcat(buffer, ", ");
	    strcat(buffer, comment);
	}

	PutLine(LINES-2,0, catgets(elm_msg_cat, AliasesSet, AliasesAddressTo,
	        "New alias: %s is '%s'."), aliasname, buffer);
	CleartoEOLN();
/*
 *	Kludge Alert:  Spaces are padded to the front of the prompt
 *	to write over the previous question.  Should probably record
 *	the end of the line, move to it, and CleartoEOLN() it.
 */
	ans = enter_yn(catgets(elm_msg_cat, AliasesSet, AliasesAcceptNew,
		"      Accept new alias?"), TRUE, LINES-3, FALSE);
	if(ans) {
	    if (replace) {
	        old_alias[0] = aliases[replacement]->alias;
	    /*
	     *  First, clear flag if this is marked to be deleted.
	     *  This prevents the problem where they marked it for
	     *  deletion and then figured out that it could be
	     *  c)hanged but didn't explicitly U)ndelete it.  Without
	     *  this test, the resync action would then delete
	     *  the new alias we just so carefully added to the
	     *  text file.
	     */
	        if (ison(aliases[replacement]->status, DELETED)) {
	            clearit(aliases[replacement]->status, DELETED);
	        }
	    /*
	     *  Changed aliases are given the NEW flag.
	     */
	        setit(aliases[replacement]->status, NEW);
	        show_msg_status(replacement);
	    /*
	     *  Now we can delete it...
	     */
	        delete_from_alias_text(old_alias, 1);
	    /*
	     *  Kludge Alert:  We need to get the trailing comma
	     *  (added in delete_from_alias_text()) off of the
	     *  alias since the display won't be re-sync'd right
	     *  away.
	     */
	        *((old_alias[0])+strlen(old_alias[0])-1) = '\0';
	    }
	    add_to_alias_text(aliasname, firstname, lastname, comment, address);
	}
	ClearLine(LINES-2);
	ClearLine(LINES-1);
	return ans;
}
Exemplo n.º 7
0
char *
REmatch(char *str,		/* string to test */
        size_t str_len,		/* ...its length */
        PTR machine,		/* compiled regular expression */
        size_t *lenp)		/* where to return matched-length */
{
    register STATE *m = (STATE *) machine;
    char *s = str;
    char *ss;
    register RT_STATE *stackp;
    int u_flag, t;
    char *str_end = s + str_len;
    RT_POS_ENTRY *sp;
    char *ts;

    /* state of current best match stored here */
    char *cb_ss;		/* the start */
    char *cb_e = 0;		/* the end , pts at first char not matched */
    STATE *m_best = 0;

    *lenp = 0;

    /* check for the easy case */
    if ((m + 1)->s_type == M_ACCEPT && m->s_type == M_STR) {
        if ((ts = str_str(s, str_len, m->s_data.str, (size_t) m->s_len)))
            *lenp = m->s_len;
        return ts;
    }

    u_flag = U_ON;
    cb_ss = ss = (char *) 0;
    stackp = RE_run_stack_empty;
    sp = RE_pos_stack_empty;
    goto reswitch;

refill:
    if (stackp == RE_run_stack_empty) {
        if (cb_ss)
            *lenp = (unsigned) (cb_e - cb_ss);
        return cb_ss;
    }
    ss = stackp->ss;
    s = (stackp--)->s;
    if (cb_ss) {		/* does new state start too late ? */
        if (ss) {
            if (cb_ss < ss || (cb_ss == ss && cb_e == str_end)) {
                goto refill;
            }
        } else if (cb_ss < s || (cb_ss == s && cb_e == str_end)) {
            goto refill;
        }
    }

    m = (stackp + 1)->m;
    sp = RE_pos_stack_base + (stackp + 1)->sp;
    sp->prev_offset = (stackp + 1)->tp;
    u_flag = (stackp + 1)->u;

reswitch:

    switch (m->s_type + u_flag) {
    case M_STR + U_OFF + END_OFF:
        if (strncmp(s, m->s_data.str, (size_t) m->s_len)) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        s += m->s_len;
        m++;
        goto reswitch;

    case M_STR + U_OFF + END_ON:
        if (strcmp(s, m->s_data.str)) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        s += m->s_len;
        m++;
        goto reswitch;

    case M_STR + U_ON + END_OFF:
        if (s >= str_end) {
            goto refill;
        }
        if (!(s = str_str(s, (size_t) (str_end - s), m->s_data.str, (size_t) m->s_len))) {
            goto refill;
        }
        if (s >= str + strlen(str)) {
            goto refill;
        }
        push(m, s + 1, sp, ss, U_ON);
        if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        s += m->s_len;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_STR + U_ON + END_ON:
        t = (int) ((str_end - s) - m->s_len);
        if (t < 0 || memcmp(ts = s + t, m->s_data.str, (size_t) m->s_len)) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && ts > cb_ss) {
                goto refill;
            } else {
                ss = ts;
            }
        }
        s = str_end;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_CLASS + U_OFF + END_OFF:
        if (s >= str_end)
            goto refill;
        if (!ison(*m->s_data.bvp, s[0])) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        s++;
        m++;
        goto reswitch;

    case M_CLASS + U_OFF + END_ON:
        if (s >= str_end)
            goto refill;
        if (s[1] || !ison(*m->s_data.bvp, s[0])) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        s++;
        m++;
        goto reswitch;

    case M_CLASS + U_ON + END_OFF:
        if (s >= str_end)
            goto refill;
        while (!ison(*m->s_data.bvp, s[0])) {
            if (s >= str_end) {
                goto refill;
            } else {
                s++;
            }
        }
        if (s >= str_end) {
            goto refill;
        }
        s++;
        push(m, s, sp, ss, U_ON);
        if (!ss) {
            if (cb_ss && s - 1 > cb_ss) {
                goto refill;
            } else {
                ss = s - 1;
            }
        }
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_CLASS + U_ON + END_ON:
        if ((s >= str_end) || !ison(*m->s_data.bvp, str_end[-1])) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && str_end - 1 > cb_ss) {
                goto refill;
            } else {
                ss = str_end - 1;
            }
        }
        s = str_end;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_ANY + U_OFF + END_OFF:
        if (s >= str_end) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        s++;
        m++;
        goto reswitch;

    case M_ANY + U_OFF + END_ON:
        if ((s >= str_end) || ((s + 1) < str_end)) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        s++;
        m++;
        goto reswitch;

    case M_ANY + U_ON + END_OFF:
        if (s >= str_end) {
            goto refill;
        }
        s++;
        push(m, s, sp, ss, U_ON);
        if (!ss) {
            if (cb_ss && s - 1 > cb_ss) {
                goto refill;
            } else {
                ss = s - 1;
            }
        }
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_ANY + U_ON + END_ON:
        if (s >= str_end) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && str_end - 1 > cb_ss) {
                goto refill;
            } else {
                ss = str_end - 1;
            }
        }
        s = str_end;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_START + U_OFF + END_OFF:
    case M_START + U_ON + END_OFF:
        if (s != str) {
            goto refill;
        }
        ss = s;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_START + U_OFF + END_ON:
    case M_START + U_ON + END_ON:
        if (s != str || (s < str_end)) {
            goto refill;
        }
        ss = s;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_END + U_OFF:
        if (s < str_end) {
            goto refill;
        }
        if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        m++;
        goto reswitch;

    case M_END + U_ON:
        s = str_end;
        if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        m++;
        u_flag = U_OFF;
        goto reswitch;

        CASE_UANY(M_U):
            if (!ss) {
            if (cb_ss && s > cb_ss) {
                goto refill;
            } else {
                ss = s;
            }
        }
        u_flag = U_ON;
        m++;
        goto reswitch;

        CASE_UANY(M_1J):
            m += m->s_data.jump;
            goto reswitch;

            CASE_UANY(M_SAVE_POS):	/* save position for a later M_2JC */
            /* see also REtest */
            sp = RE_pos_push(sp, stackp, s);
            m++;
            goto reswitch;

            CASE_UANY(M_2JA):	/* take the non jump branch */
            push(m + m->s_data.jump, s, sp, ss, u_flag);
            m++;
            goto reswitch;

            CASE_UANY(M_2JC):	/* take the jump branch if position changed */
            /* see REtest */
            if (RE_pos_pop(&sp, stackp) == s) {
            m++;
            goto reswitch;
        }
        /* fall thru */

        CASE_UANY(M_2JB):	/* take the jump branch */
            push(m + 1, s, sp, ss, u_flag);
            m += m->s_data.jump;
            goto reswitch;

        case M_ACCEPT + U_OFF:
            if (!ss)
                ss = s;
            if (!cb_ss || ss < cb_ss || (ss == cb_ss && s > cb_e)) {
            /* we have a new current best */
            cb_ss = ss;
            cb_e = s;
            m_best = m;
        }
        goto refill;

    case M_ACCEPT + U_ON:
        if (!ss) {
            ss = s;
        } else {
            s = str_end;
        }

        if (!cb_ss || ss < cb_ss || (ss == cb_ss && s > cb_e)) {
            /* we have a new current best */
            cb_ss = ss;
            cb_e = s;
            m_best = m;
        }
        goto refill;

    default:
        RE_panic("unexpected case in REmatch");
    }
}
Exemplo n.º 8
0
char *
REmatch(char *str,		/* string to test */
	unsigned str_len,	/* ...its length */
	PTR machine,		/* compiled regular expression */
	unsigned *lenp)		/* where to return matched-length */
{
    register STATE *m = (STATE *) machine;
    register char *s = str;
    char *ss;
    register RT_STATE *stackp;
    int u_flag, t;
    char *str_end = s + str_len;
    char *ts;

    /* state of current best match stored here */
    char *cb_ss;		/* the start */
    char *cb_e = 0;		/* the end , pts at first char not matched */

    *lenp = 0;

    /* check for the easy case */
    if ((m + 1)->s_type == M_ACCEPT && m->s_type == M_STR) {
	if ((ts = str_str(s, str_len, m->s_data.str, m->s_len)))
	    *lenp = m->s_len;
	return ts;
    }

    u_flag = U_ON;
    cb_ss = ss = (char *) 0;
    stackp = RE_run_stack_empty;
    goto reswitch;

  refill:
    if (stackp == RE_run_stack_empty) {
	if (cb_ss)
	    *lenp = (unsigned) (cb_e - cb_ss);
	return cb_ss;
    }
    ss = stackp->ss;
    s = (stackp--)->s;
    if (cb_ss) {		/* does new state start too late ? */
	if (ss) {
	    if (cb_ss < ss)
		goto refill;
	} else if (cb_ss < s) {
	    goto refill;
	}
    }

    m = (stackp + 1)->m;
    u_flag = (stackp + 1)->u;

  reswitch:

    switch (m->s_type + u_flag) {
    case M_STR + U_OFF + END_OFF:
	if (strncmp(s, m->s_data.str, m->s_len))
	    goto refill;
	if (!ss) {
	    if (cb_ss && s > cb_ss)
		goto refill;
	    else
		ss = s;
	}
	s += m->s_len;
	m++;
	goto reswitch;

    case M_STR + U_OFF + END_ON:
	if (strcmp(s, m->s_data.str))
	    goto refill;
	if (!ss) {
	    if (cb_ss && s > cb_ss) {
		goto refill;
	    } else {
		ss = s;
	    }
	}
	s += m->s_len;
	m++;
	goto reswitch;

    case M_STR + U_ON + END_OFF:
	if (!(s = str_str(s, str_len, m->s_data.str, m->s_len)))
	    goto refill;
	if (s >= str + strlen(str))
	    goto refill;
	push(m, s + 1, ss, U_ON);
	if (!ss) {
	    if (cb_ss && s > cb_ss) {
		goto refill;
	    } else {
		ss = s;
	    }
	}
	s += m->s_len;
	m++;
	u_flag = U_OFF;
	goto reswitch;

    case M_STR + U_ON + END_ON:
	t = (str_end - s) - m->s_len;
	if (t < 0 || memcmp(ts = s + t, m->s_data.str, m->s_len))
	    goto refill;
	if (!ss) {
	    if (cb_ss && ts > cb_ss)
		goto refill;
	    else
		ss = ts;
	}
	s = str_end;
	m++;
	u_flag = U_OFF;
	goto reswitch;

    case M_CLASS + U_OFF + END_OFF:
	if (!ison(*m->s_data.bvp, s[0]))
	    goto refill;
	if (!ss) {
	    if (cb_ss && s > cb_ss)
		goto refill;
	    else
		ss = s;
	}
	s++;
	m++;
	goto reswitch;

    case M_CLASS + U_OFF + END_ON:
	if (s[1] || !ison(*m->s_data.bvp, s[0]))
	    goto refill;
	if (!ss) {
	    if (cb_ss && s > cb_ss)
		goto refill;
	    else
		ss = s;
	}
	s++;
	m++;
	goto reswitch;

    case M_CLASS + U_ON + END_OFF:
	while (!ison(*m->s_data.bvp, s[0])) {
	    if (s[0] == 0)
		goto refill;
	    else
		s++;
	}
	s++;
	push(m, s, ss, U_ON);
	if (!ss) {
	    if (cb_ss && s - 1 > cb_ss)
		goto refill;
	    else
		ss = s - 1;
	}
	m++;
	u_flag = U_OFF;
	goto reswitch;

    case M_CLASS + U_ON + END_ON:
	if (s[0] == 0 || !ison(*m->s_data.bvp, str_end[-1]))
	    goto refill;
	if (!ss) {
	    if (cb_ss && str_end - 1 > cb_ss)
		goto refill;
	    else
		ss = str_end - 1;
	}
	s = str_end;
	m++;
	u_flag = U_OFF;
	goto reswitch;

    case M_ANY + U_OFF + END_OFF:
	if (s[0] == 0)
	    goto refill;
	if (!ss) {
	    if (cb_ss && s > cb_ss)
		goto refill;
	    else
		ss = s;
	}
	s++;
	m++;
	goto reswitch;

    case M_ANY + U_OFF + END_ON:
	if (s[0] == 0 || s[1] != 0)
	    goto refill;
	if (!ss) {
	    if (cb_ss && s > cb_ss)
		goto refill;
	    else
		ss = s;
	}
	s++;
	m++;
	goto reswitch;

    case M_ANY + U_ON + END_OFF:
	if (s[0] == 0)
	    goto refill;
	s++;
	push(m, s, ss, U_ON);
	if (!ss) {
	    if (cb_ss && s - 1 > cb_ss)
		goto refill;
	    else
		ss = s - 1;
	}
	m++;
	u_flag = U_OFF;
	goto reswitch;

    case M_ANY + U_ON + END_ON:
	if (s[0] == 0)
	    goto refill;
	if (!ss) {
	    if (cb_ss && str_end - 1 > cb_ss)
		goto refill;
	    else
		ss = str_end - 1;
	}
	s = str_end;
	m++;
	u_flag = U_OFF;
	goto reswitch;

    case M_START + U_OFF + END_OFF:
    case M_START + U_ON + END_OFF:
	if (s != str)
	    goto refill;
	ss = s;
	m++;
	u_flag = U_OFF;
	goto reswitch;

    case M_START + U_OFF + END_ON:
    case M_START + U_ON + END_ON:
	if (s != str || s[0] != 0)
	    goto refill;
	ss = s;
	m++;
	u_flag = U_OFF;
	goto reswitch;

    case M_END + U_OFF:
	if (s[0] != 0)
	    goto refill;
	if (!ss) {
	    if (cb_ss && s > cb_ss)
		goto refill;
	    else
		ss = s;
	}
	m++;
	goto reswitch;

    case M_END + U_ON:
	s = str_end;
	if (!ss) {
	    if (cb_ss && s > cb_ss)
		goto refill;
	    else
		ss = s;
	}
	m++;
	u_flag = U_OFF;
	goto reswitch;

      CASE_UANY(M_U):
	if (!ss) {
	    if (cb_ss && s > cb_ss)
		goto refill;
	    else
		ss = s;
	}
	u_flag = U_ON;
	m++;
	goto reswitch;

      CASE_UANY(M_1J):
	m += m->s_data.jump;
	goto reswitch;

      CASE_UANY(M_2JA):	/* take the non jump branch */
	push(m + m->s_data.jump, s, ss, u_flag);
	m++;
	goto reswitch;

      CASE_UANY(M_2JB):	/* take the jump branch */
	push(m + 1, s, ss, u_flag);
	m += m->s_data.jump;
	goto reswitch;

    case M_ACCEPT + U_OFF:
	if (!ss)
	    ss = s;
	if (!cb_ss || ss < cb_ss || (ss == cb_ss && s > cb_e)) {
	    /* we have a new current best */
	    cb_ss = ss;
	    cb_e = s;
	}
	goto refill;

    case M_ACCEPT + U_ON:
	if (!ss) {
	    ss = s;
	} else {
	    s = str_end;
	}

	if (!cb_ss || ss < cb_ss || (ss == cb_ss && s > cb_e)) {
	    /* we have a new current best */
	    cb_ss = ss;
	    cb_e = s;
	}
	goto refill;

    default:
	RE_panic("unexpected case in REmatch");
    }
}
Exemplo n.º 9
0
Arquivo: a_quit.c Projeto: wfp5p/elm
int delete_aliases(int newaliases, int prompt)
{
/*
 *	Update aliases by processing deletions.  Prompting is
 *	done as directed by user input and elmrc options.
 *
 *	If "prompt" is false, then no prompting is done.
 *	Otherwise prompting is dependent upon the variable
 *	ask_delete, as set by an elmrc option.  This behavior
 *	makes the 'q' command prompt just like '$', while
 *	retaining the 'Q' command for a quick exit that never
 *	prompts.
 *
 *	Return	1		Aliases were deleted
 * 		newalias	Aliases were not deleted
 *
 *	The return allows the caller to determine if the "newalias"
 *	routine should be run.
 */

	char buffer[SLEN];
	char **list;

	int to_delete = 0, to_keep = 0, i,
		     marked_deleted = 0,
		     ask_questions;
	char answer;

	dprint(1, (debugfile, "\n\n-- leaving aliases --\n\n"));

	if (num_aliases == 0)
	  return(newaliases);	/* nothing changed */

	ask_questions = ((!prompt) ? FALSE : ask_delete);

	/* Determine if deleted messages are really to be deleted */

	/* we need to know how many there are to delete */
	for (i=0; i<num_aliases; i++)
	  if (ison(aliases[i]->status, DELETED))
	    marked_deleted++;

	dprint(6, (debugfile, "Number of aliases marked deleted = %d\n",
	            marked_deleted));

        if(marked_deleted) {
	  if(ask_questions) {
	    if (marked_deleted == 1)
	      strcpy(buffer, catgets(elm_msg_cat, AliasesSet, AliasesDelete,
			"Delete 1 alias?"));
	    else
	      sprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesDeletePlural,
			"Delete %d aliases?"), marked_deleted);
	                    
	    answer = enter_yn(buffer, always_delete, LINES-3, FALSE);
	  } else {
	    answer = always_delete;
	  }

	  if(answer) {
	    list = (char **) malloc(marked_deleted*sizeof(*list));
	    for (i = 0; i < num_aliases; i++) {
	      if (ison(aliases[i]->status, DELETED)) {
		list[to_delete] = aliases[i]->alias;
	        dprint(8,(debugfile, "Alias number %d, %s is deletion %d\n",
	               i, list[to_delete], to_delete));
	        to_delete++;
	      }
	      else {
	        to_keep++;
	      }
	    }
	   /*
	    * Formulate message as to number of keeps and deletes.
	    * This is only complex so that the message is good English.
	    */
	    if (to_keep > 0) {
	      curr_alias = 1;		/* Reset current alias */
	      if (to_keep == 1)
		sprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesKeepDelete,
			  "[Keeping 1 alias and deleting %d.]"), to_delete);
	      else
		sprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesKeepDeletePlural,
			  "[Keeping %d aliases and deleting %d.]"), to_keep, to_delete);
	    }
	    else {
	      curr_alias = 0;		/* No aliases left */
	      sprintf(buffer, catgets(elm_msg_cat, AliasesSet, AliasesDeleteAll,
			  "[Deleting all aliases.]"));
	    }

	    dprint(2, (debugfile, "Action: %s\n", buffer));
	    show_error(buffer);

	    delete_from_alias_text(list, to_delete);

	    free((char *) list);
	  }
	}
	dprint(3, (debugfile, "Aliases deleted: %d\n", to_delete));

	/* If all aliases are to be kept we don't need to do anything
	 * (like run newalias for the deleted messages).
	 */

	if(to_delete == 0) {
	  dprint(3, (debugfile, "Aliases kept as is!\n"));
	  return(newaliases);
	}

	return(1);
}
Exemplo n.º 10
0
/*
 * test if str ~ /machine/
 */
int
REtest(char *str,		/* string to test */
       size_t len,		/* ...its length */
       PTR machine)		/* compiled regular-expression */
{
    register STATE *m = (STATE *) machine;
    char *s = str;
    register RT_STATE *stackp;
    int u_flag;
    char *str_end = str + len;
    RT_POS_ENTRY *sp;
    int t;			/*convenient temps */
    STATE *tm;

    /* handle the easy case quickly */
    if ((m + 1)->s_type == M_ACCEPT && m->s_type == M_STR) {
        return str_str(s, len, m->s_data.str, (size_t) m->s_len) != (char *) 0;
    } else {
        u_flag = U_ON;
        stackp = RE_run_stack_empty;
        sp = RE_pos_stack_empty;
        goto reswitch;
    }

refill:
    if (stackp == RE_run_stack_empty)
        return 0;
    m = stackp->m;
    s = stackp->s;
    sp = RE_pos_stack_base + stackp->sp;
    sp->prev_offset = stackp->tp;
    u_flag = (stackp--)->u;

reswitch:

    switch (m->s_type + u_flag) {
    case M_STR + U_OFF + END_OFF:
        if (strncmp(s, m->s_data.str, (size_t) m->s_len))
            goto refill;
        s += m->s_len;
        m++;
        goto reswitch;

    case M_STR + U_OFF + END_ON:
        if (strcmp(s, m->s_data.str))
            goto refill;
        s += m->s_len;
        m++;
        goto reswitch;

    case M_STR + U_ON + END_OFF:
        if (!(s = str_str(s, (size_t) (str_end - s), m->s_data.str, (size_t) m->s_len)))
            goto refill;
        push(m, s + 1, sp, U_ON);
        s += m->s_len;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_STR + U_ON + END_ON:
        t = (str_end - s) - m->s_len;
        if (t < 0 || memcmp(s + t, m->s_data.str, (size_t) m->s_len))
            goto refill;
        s = str_end;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_CLASS + U_OFF + END_OFF:
        if (s >= str_end || !ison(*m->s_data.bvp, s[0]))
            goto refill;
        s++;
        m++;
        goto reswitch;

    case M_CLASS + U_OFF + END_ON:
        if (s >= str_end)
            goto refill;
        if ((s + 1) < str_end || !ison(*m->s_data.bvp, s[0]))
            goto refill;
        s++;
        m++;
        goto reswitch;

    case M_CLASS + U_ON + END_OFF:
        for (;;) {
            if (s >= str_end)
                goto refill;
            else if (ison(*m->s_data.bvp, s[0]))
                break;
            s++;
        }
        s++;
        push(m, s, sp, U_ON);
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_CLASS + U_ON + END_ON:
        if (s >= str_end || !ison(*m->s_data.bvp, str_end[-1]))
            goto refill;
        s = str_end;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_ANY + U_OFF + END_OFF:
        if (s >= str_end)
            goto refill;
        s++;
        m++;
        goto reswitch;

    case M_ANY + U_OFF + END_ON:
        if (s >= str_end || (s + 1) < str_end)
            goto refill;
        s++;
        m++;
        goto reswitch;

    case M_ANY + U_ON + END_OFF:
        if (s >= str_end)
            goto refill;
        s++;
        push(m, s, sp, U_ON);
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_ANY + U_ON + END_ON:
        if (s >= str_end)
            goto refill;
        s = str_end;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_START + U_OFF + END_OFF:
    case M_START + U_ON + END_OFF:
        if (s != str)
            goto refill;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_START + U_OFF + END_ON:
    case M_START + U_ON + END_ON:
        if (s != str || s < str_end)
            goto refill;
        m++;
        u_flag = U_OFF;
        goto reswitch;

    case M_END + U_OFF:
        if (s < str_end)
            goto refill;
        m++;
        goto reswitch;

    case M_END + U_ON:
        s += strlen(s);
        m++;
        u_flag = U_OFF;
        goto reswitch;

        CASE_UANY(M_U):
            u_flag = U_ON;
            m++;
            goto reswitch;

            CASE_UANY(M_1J):
            m += m->s_data.jump;
            goto reswitch;

            CASE_UANY(M_SAVE_POS):	/* save position for a later M_2JC */
            sp = RE_pos_push(sp, stackp, s);
            m++;
            goto reswitch;

            CASE_UANY(M_2JA):	/* take the non jump branch */
            /* don't stack an ACCEPT */
            if ((tm = m + m->s_data.jump)->s_type == M_ACCEPT)
                return 1;
            push(tm, s, sp, u_flag);
            m++;
            goto reswitch;

            CASE_UANY(M_2JC):	/* take the jump branch if position changed */
            if (RE_pos_pop(&sp, stackp) == s) {
            /* did not advance: do not jump back */
            m++;
            goto reswitch;
        }
        /* fall thru */

        CASE_UANY(M_2JB):	/* take the jump branch */
            /* don't stack an ACCEPT */
            if ((tm = m + 1)->s_type == M_ACCEPT)
                return 1;
            push(tm, s, sp, u_flag);
            m += m->s_data.jump;
            goto reswitch;

            CASE_UANY(M_ACCEPT):
            return 1;

        default:
            RE_panic("unexpected case in REtest");
        }
    }