Annotation of parser3/src/types/pa_vconsole.h, revision 1.33
1.1 paf 1: /** @file
2: Parser: @b console class decl.
3:
1.32 moko 4: Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
1.28 moko 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 paf 6: */
7:
8: #ifndef PA_VCONSOLE_H
9: #define PA_VCONSOLE_H
10:
1.33 ! moko 11: #define IDENT_PA_VCONSOLE_H "$Id: pa_vconsole.h,v 1.32 2026/04/25 13:38:46 moko Exp $"
1.1 paf 12:
13: // includes
14:
15: #include "pa_sapi.h"
16: #include "pa_common.h"
1.23 moko 17: #include "pa_vstateless_class.h"
1.1 paf 18: #include "pa_string.h"
19:
20: // defines
21:
22: #define CONSOLE_LINE_NAME "line"
23:
24: /// console class
1.23 moko 25: class VConsole: public VStateless_class {
1.1 paf 26: public: // Value
27:
1.23 moko 28: const char* type() const { return "console"; }
1.1 paf 29:
1.20 misha 30: /// console: line
1.17 misha 31: Value* get_element(const String& aname) {
1.33 ! moko 32: MAYBE_GET_SPECIAL(VStateless_class::get_element(aname));
1.23 moko 33:
1.1 paf 34: // $line
35: if(aname==CONSOLE_LINE_NAME) {
36: char local_value[MAX_STRING];
1.15 misha 37: if(fgets(local_value, sizeof(local_value), stdin))
1.31 moko 38: return new VString(pa_strdup(local_value));
1.1 paf 39:
40: return 0; // EOF
41: }
42:
1.29 moko 43: return bark("%s field not found", &aname);
1.1 paf 44: }
45:
1.14 misha 46: /// console: $line
1.19 moko 47: override const VJunction* put_element(const String& aname, Value* avalue) {
1.1 paf 48: // $line
49: if(aname==CONSOLE_LINE_NAME) {
1.12 misha 50: fused=true;
1.15 misha 51: puts(avalue->as_string().cstr());
1.2 paf 52: fflush(stdout);
1.1 paf 53:
1.26 moko 54: return 0;
1.1 paf 55: }
56:
1.26 moko 57: throw Exception(PARSER_RUNTIME, &aname, "writing to invalid field");
1.1 paf 58: }
59:
1.12 misha 60: bool was_used(){
61: return fused;
62: }
63:
1.1 paf 64: public: // usage
65:
1.12 misha 66: VConsole() {
67: fused=false;
68: }
1.1 paf 69:
1.12 misha 70: private:
71: bool fused;
1.1 paf 72: };
73:
74: #endif
E-mail: