Annotation of parser3/src/types/pa_vconsole.h, revision 1.27
1.1 paf 1: /** @file
2: Parser: @b console class decl.
3:
1.27 ! moko 4: Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com)
1.1 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
6: */
7:
8: #ifndef PA_VCONSOLE_H
9: #define PA_VCONSOLE_H
10:
1.27 ! moko 11: #define IDENT_PA_VCONSOLE_H "$Id: pa_vconsole.h,v 1.26 2020/10/27 10:10:09 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.24 moko 32: #ifndef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
33: // CLASS, CLASS_NAME
1.23 moko 34: if(Value* result=VStateless_class::get_element(aname))
35: return result;
1.24 moko 36: #endif
1.23 moko 37:
1.1 paf 38: // $line
39: if(aname==CONSOLE_LINE_NAME) {
40: char local_value[MAX_STRING];
1.15 misha 41: if(fgets(local_value, sizeof(local_value), stdin))
1.21 moko 42: return new VString(*new String(pa_strdup(local_value), String::L_TAINTED));
1.1 paf 43:
44: return 0; // EOF
45: }
46:
1.23 moko 47: throw Exception(PARSER_RUNTIME, &aname, "reading of invalid field");
1.1 paf 48: }
49:
1.14 misha 50: /// console: $line
1.19 moko 51: override const VJunction* put_element(const String& aname, Value* avalue) {
1.1 paf 52: // $line
53: if(aname==CONSOLE_LINE_NAME) {
1.12 misha 54: fused=true;
1.15 misha 55: puts(avalue->as_string().cstr());
1.2 paf 56: fflush(stdout);
1.1 paf 57:
1.26 moko 58: return 0;
1.1 paf 59: }
60:
1.26 moko 61: throw Exception(PARSER_RUNTIME, &aname, "writing to invalid field");
1.1 paf 62: }
63:
1.12 misha 64: bool was_used(){
65: return fused;
66: }
67:
1.1 paf 68: public: // usage
69:
1.12 misha 70: VConsole() {
71: fused=false;
72: }
1.1 paf 73:
1.12 misha 74: private:
75: bool fused;
1.1 paf 76: };
77:
78: #endif
E-mail: