Added number of matches
This commit is contained in:
parent
e1918e694c
commit
4b947dba10
|
@ -199,7 +199,7 @@ gm_trigger_set_actions(GmTrigger *trigger, GList *actions) {
|
|||
trigger->actions = actions;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gint
|
||||
gm_trigger_match_user(GmTrigger *trigger, gchar const *username,
|
||||
GmTriggerConditionType condition, regmatch_t *matches, gint nmatch) {
|
||||
GmTriggerData *data;
|
||||
|
@ -214,7 +214,7 @@ gm_trigger_match_user(GmTrigger *trigger, gchar const *username,
|
|||
data = (GmTriggerData *)(item->data);
|
||||
|
||||
if (cmatch >= nmatch) {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (data->type == condition) {
|
||||
|
@ -230,17 +230,17 @@ gm_trigger_match_user(GmTrigger *trigger, gchar const *username,
|
|||
cmatch++;
|
||||
}
|
||||
} else {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return cmatch;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gint
|
||||
gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
||||
gint nmatch) {
|
||||
GmTriggerData *data;
|
||||
|
@ -250,7 +250,7 @@ gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
|||
gint cmatch = 0, ret, offset, len;
|
||||
|
||||
if (!trigger->conditions) {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (item = trigger->conditions; item; item = item->next) {
|
||||
|
@ -258,7 +258,7 @@ gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
|||
len = g_utf8_strlen(data->data, -1);
|
||||
|
||||
if (cmatch >= nmatch) {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (data->type) {
|
||||
|
@ -280,7 +280,7 @@ gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case TCT_NOT_CONTAINS:
|
||||
|
@ -288,7 +288,7 @@ gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
|||
matches[cmatch].rm_so = 0;
|
||||
matches[cmatch].rm_eo = len;
|
||||
} else {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case TCT_NOT_BEGINS:
|
||||
|
@ -296,7 +296,7 @@ gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
|||
matches[cmatch].rm_so = 0;
|
||||
matches[cmatch].rm_eo = g_utf8_strlen(text, -1);
|
||||
} else {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -311,7 +311,7 @@ gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
|||
matches[cmatch].rm_so = 0;
|
||||
matches[cmatch].rm_eo = g_utf8_strlen(text, -1);
|
||||
} else {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,16 +350,16 @@ gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
|||
matches[cmatch].rm_so = 0;
|
||||
matches[cmatch].rm_eo = g_utf8_strlen(text, -1);
|
||||
} else {
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return cmatch;
|
||||
}
|
||||
|
||||
gint
|
||||
|
|
|
@ -117,9 +117,9 @@ void gm_trigger_add_action(GmTrigger *trigger, GmTriggerData *action);
|
|||
void gm_trigger_set_conditions(GmTrigger *trigger, GList *conditions);
|
||||
void gm_trigger_set_actions(GmTrigger *trigger, GList *actions);
|
||||
|
||||
gboolean gm_trigger_match_user(GmTrigger *trigger, gchar const *username,
|
||||
gint gm_trigger_match_user(GmTrigger *trigger, gchar const *username,
|
||||
GmTriggerConditionType condition, regmatch_t *matches, gint nmatch);
|
||||
gboolean gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
||||
gint gm_trigger_match(GmTrigger *trigger, gchar *text, regmatch_t *matches,
|
||||
gint nmatch);
|
||||
|
||||
GmTriggerData *gm_trigger_data_new(gint type, gchar *data);
|
||||
|
|
|
@ -743,7 +743,7 @@ gm_world_parse_legacy_editing_start(GmWorld *world, gchar *line) {
|
|||
|
||||
gchar *
|
||||
gm_world_triggers_subst(gchar const *data, gchar const *text,
|
||||
regmatch_t *matches) {
|
||||
regmatch_t *matches, gint nummatches) {
|
||||
gchar *tmp = (gchar *)data;
|
||||
gchar *p, *ptr, *tmp2;
|
||||
GString *result = NULL;
|
||||
|
@ -766,9 +766,10 @@ gm_world_triggers_subst(gchar const *data, gchar const *text,
|
|||
}
|
||||
|
||||
/* Replace it */
|
||||
if (n < MAX_MATCHES) {
|
||||
if (n < nummatches) {
|
||||
tmp2 = g_strndup(g_utf8_offset_to_pointer(text,
|
||||
matches[n].rm_so), matches[n].rm_eo);
|
||||
|
||||
g_string_append(result, tmp2);
|
||||
g_free(tmp2);
|
||||
}
|
||||
|
@ -787,7 +788,7 @@ gm_world_triggers_subst(gchar const *data, gchar const *text,
|
|||
|
||||
void
|
||||
gm_world_apply_trigger(GmWorld *world, GmTrigger *trigger, gchar const *text,
|
||||
regmatch_t *matches) {
|
||||
regmatch_t *matches, gint nummatches) {
|
||||
GList *item;
|
||||
GmTriggerData *data;
|
||||
gint i, nargs;
|
||||
|
@ -814,18 +815,21 @@ gm_world_apply_trigger(GmWorld *world, GmTrigger *trigger, gchar const *text,
|
|||
gdk_beep();
|
||||
break;
|
||||
case TAT_PLAY_SOUND:
|
||||
tmp = gm_world_triggers_subst(data->data, text, matches);
|
||||
tmp = gm_world_triggers_subst(data->data, text, matches,
|
||||
nummatches);
|
||||
// TODO
|
||||
g_free(tmp);
|
||||
break;
|
||||
case TAT_NOTIFY:
|
||||
tmp = gm_world_triggers_subst(data->data, text, matches);
|
||||
tmp = gm_world_triggers_subst(data->data, text, matches,
|
||||
nummatches);
|
||||
g_signal_emit(world, world_signals[NOTIFY_MESSAGE], 0, tmp);
|
||||
g_free(tmp);
|
||||
break;
|
||||
case TAT_RUN_SCRIPT:
|
||||
#ifdef HAVE_RUBY
|
||||
tmp = gm_world_triggers_subst(data->data, text, matches);
|
||||
tmp = gm_world_triggers_subst(data->data, text, matches,
|
||||
nummatches);
|
||||
argstr = g_utf8_strchr(tmp, -1, ' ');
|
||||
|
||||
if (argstr) {
|
||||
|
@ -840,7 +844,8 @@ gm_world_apply_trigger(GmWorld *world, GmTrigger *trigger, gchar const *text,
|
|||
#endif
|
||||
break;
|
||||
case TAT_RUN:
|
||||
tmp = gm_world_triggers_subst(data->data, text, matches);
|
||||
tmp = gm_world_triggers_subst(data->data, text, matches,
|
||||
nummatches);
|
||||
|
||||
if (g_shell_parse_argv(tmp, &nargs, &spawn_args, NULL)) {
|
||||
g_spawn_async(NULL, spawn_args, NULL, G_SPAWN_SEARCH_PATH,
|
||||
|
@ -861,14 +866,15 @@ gm_world_process_triggers(GmWorld *world, gchar *text) {
|
|||
GList const *item;
|
||||
GmTrigger *trigger;
|
||||
regmatch_t matches[MAX_MATCHES];
|
||||
gint num;
|
||||
|
||||
for (item = gm_triggers_list(world->priv->triggers); item;
|
||||
item = item->next) {
|
||||
trigger = (GmTrigger *)(item->data);
|
||||
|
||||
if (trigger->event == TT_OUTPUT) {
|
||||
if (gm_trigger_match(trigger, text, matches, MAX_MATCHES)) {
|
||||
gm_world_apply_trigger(world, trigger, text, matches);
|
||||
if ((num = gm_trigger_match(trigger, text, matches, MAX_MATCHES))) {
|
||||
gm_world_apply_trigger(world, trigger, text, matches, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ void gm_world_writeln(GmWorld *world, gchar *text);
|
|||
void gm_world_process_input(GmWorld *world, gchar *text);
|
||||
void gm_world_log(GmWorld *world, GmLogType type, gchar *text);
|
||||
void gm_world_apply_trigger(GmWorld *world, GmTrigger *trigger,
|
||||
gchar const *text, regmatch_t *matches);
|
||||
gchar const *text, regmatch_t *matches, gint nummatches);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __GM_WORLD_H__ */
|
||||
|
|
Reference in a new issue