Selaa lähdekoodia

plugin-klish: Store compiled regex within ACTION's udata.

Architecturally it's right way to store such information. Previously this data
was stored within ENTRY udata. But one ENTRY can contain multiple ACTIONs. It
can be conflict.
Serj Kalichev 4 kuukautta sitten
vanhempi
commit
e2794a087e
3 muutettua tiedostoa jossa 14 lisäystä ja 12 poistoa
  1. 1 1
      klish/kcontext.h
  2. 2 2
      klish/ksession/kcontext.c
  3. 11 9
      plugins/klish/ptype_string.c

+ 1 - 1
klish/kcontext.h

@@ -116,7 +116,7 @@ int kcontext_printf(const kcontext_t *context, const char *fmt, ...);
 kparg_t *kcontext_candidate_parg(const kcontext_t *context);
 kentry_t *kcontext_candidate_entry(const kcontext_t *context);
 const char *kcontext_candidate_value(const kcontext_t *context);
-const kaction_t *kcontext_action(const kcontext_t *context);
+kaction_t *kcontext_action(const kcontext_t *context);
 const char *kcontext_script(const kcontext_t *context);
 bool_t kcontext_named_udata_new(kcontext_t *context,
 	const char *name, void *data, kudata_data_free_fn free_fn);

+ 2 - 2
klish/ksession/kcontext.c

@@ -230,7 +230,7 @@ const char *kcontext_candidate_value(const kcontext_t *context)
 }
 
 
-const kaction_t *kcontext_action(const kcontext_t *context)
+kaction_t *kcontext_action(const kcontext_t *context)
 {
 	faux_list_node_t *node = NULL;
 
@@ -242,7 +242,7 @@ const kaction_t *kcontext_action(const kcontext_t *context)
 	if (!node)
 		return NULL;
 
-	return (const kaction_t *)faux_list_data(node);
+	return (kaction_t *)faux_list_data(node);
 }
 
 

+ 11 - 9
plugins/klish/ptype_string.c

@@ -38,16 +38,18 @@ static void klish_ptype_STRING_free(void *data)
 }
 
 
-klish_ptype_STRING_t *klish_ptype_STRING_init(kentry_t *entry,
-	const char *pattern)
+klish_ptype_STRING_t *klish_ptype_STRING_init(kaction_t *action)
 {
 	klish_ptype_STRING_t *udata = NULL;
+	const char *pattern = NULL;
 
 	udata = faux_malloc(sizeof(*udata));
 	assert(udata);
 	if (!udata)
 		return NULL;
 
+	pattern = kaction_script(action);
+
 	if (faux_str_is_empty(pattern)) {
 		udata->is_regex = BOOL_FALSE;
 	} else {
@@ -60,27 +62,27 @@ klish_ptype_STRING_t *klish_ptype_STRING_init(kentry_t *entry,
 		}
 	}
 
-	kentry_set_udata(entry, udata, klish_ptype_STRING_free);
+	kaction_set_udata(action, udata, klish_ptype_STRING_free);
 
 	return udata;
 }
 
-/** @brief PTYPE: Arbitrary string
+
+/** @brief PTYPE: String
  */
 int klish_ptype_STRING(kcontext_t *context)
 {
-	kentry_t *entry = NULL;
+	kaction_t *action = NULL;
 	const char *value = NULL;
 	klish_ptype_STRING_t *udata = NULL;
 	size_t len = 0;
 
-	entry = kcontext_candidate_entry(context);
+	action = kcontext_action(context);
 	value = kcontext_candidate_value(context);
 
-	udata = (klish_ptype_STRING_t *)kentry_udata(entry);
+	udata = (klish_ptype_STRING_t *)kaction_udata(action);
 	if (!udata) {
-		const char *pattern = kcontext_script(context);
-		udata = klish_ptype_STRING_init(entry, pattern);
+		udata = klish_ptype_STRING_init(action);
 		if (!udata)
 			return -1;
 	}