Browse Source

kcontext: Add stdin, stdout, stderr

Serj Kalichev 2 years ago
parent
commit
9c8aca6cbe
2 changed files with 39 additions and 9 deletions
  1. 15 6
      klish/kcontext.h
  2. 24 3
      klish/ksession/kcontext.c

+ 15 - 6
klish/kcontext.h

@@ -12,24 +12,33 @@
 
 C_DECL_BEGIN
 
-// type
+// Type
 kcontext_type_e kcontext_type(const kcontext_t *context);
 FAUX_HIDDEN bool_t kcontext_set_type(kcontext_t *context, kcontext_type_e type);
-// retcode
+// RetCode
 int kcontext_retcode(const kcontext_t *context);
 FAUX_HIDDEN bool_t kcontext_set_retcode(kcontext_t *context, int retcode);
-// plugin
+// Plugin
 kplugin_t *kcontext_plugin(const kcontext_t *context);
 FAUX_HIDDEN bool_t kcontext_set_plugin(kcontext_t *context, kplugin_t *plugin);
-// sym
+// Sym
 ksym_t *kcontext_sym(const kcontext_t *context);
 FAUX_HIDDEN bool_t kcontext_set_sym(kcontext_t *context, ksym_t *sym);
-// action
+// Action
 kaction_t *kcontext_action(const kcontext_t *context);
 FAUX_HIDDEN bool_t kcontext_set_action(kcontext_t *context, kaction_t *action);
-// command
+// Command
 kcommand_t *kcontext_command(const kcontext_t *context);
 FAUX_HIDDEN bool_t kcontext_set_command(kcontext_t *context, kcommand_t *command);
+// STDIN
+int kcontext_stdin(const kcontext_t *context);
+FAUX_HIDDEN bool_t kcontext_set_stdin(kcontext_t *context, int stdin);
+// STDOUT
+int kcontext_stdout(const kcontext_t *context);
+FAUX_HIDDEN bool_t kcontext_set_stdout(kcontext_t *context, int stdout);
+// STDERR
+int kcontext_stderr(const kcontext_t *context);
+FAUX_HIDDEN bool_t kcontext_set_stderr(kcontext_t *context, int stderr);
 
 C_DECL_END
 

+ 24 - 3
klish/ksession/kcontext.c

@@ -15,9 +15,12 @@ struct kcontext_s {
 	kcontext_type_e type;
 	int retcode;
 	kplugin_t *plugin;
-	ksym_t *sym;
-	kaction_t *action;
 	kcommand_t *command;
+	kaction_t *action;
+	ksym_t *sym;
+	int stdin;
+	int stdout;
+	int stderr;
 };
 
 
@@ -47,6 +50,18 @@ FAUX_HIDDEN KSET(context, kaction_t *, action);
 KGET(context, kcommand_t *, command);
 FAUX_HIDDEN KSET(context, kcommand_t *, command);
 
+// STDIN
+KGET(context, int, stdin);
+FAUX_HIDDEN KSET(context, int, stdin);
+
+// STDOUT
+KGET(context, int, stdout);
+FAUX_HIDDEN KSET(context, int, stdout);
+
+// STDERR
+KGET(context, int, stderr);
+FAUX_HIDDEN KSET(context, int, stderr);
+
 
 kcontext_t *kcontext_new(kcontext_type_e type)
 {
@@ -60,8 +75,14 @@ kcontext_t *kcontext_new(kcontext_type_e type)
 	// Initialize
 	context->type = type;
 	context->plugin = NULL;
-	context->sym = NULL;
+	context->command = NULL;
 	context->action = NULL;
+	context->sym = NULL;
+
+	// I/O
+	context->stdin = -1;
+	context->stdout = -1;
+	context->stderr = -1;
 
 	return context;
 }