Annotation of parser3/src/types/pa_vconsole.h, revision 1.25
1.1 paf 1: /** @file
2: Parser: @b console class decl.
3:
1.25 ! moko 4: Copyright (c) 2001-2017 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.25 ! moko 11: #define IDENT_PA_VCONSOLE_H "$Id: pa_vconsole.h,v 1.24 2016/04/08 22:34:37 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.6 paf 58: return PUT_ELEMENT_REPLACED_ELEMENT;
1.1 paf 59: }
60:
1.13 misha 61: throw Exception(PARSER_RUNTIME,
1.1 paf 62: &aname,
63: "writing to invalid field");
64: }
65:
1.12 misha 66: bool was_used(){
67: return fused;
68: }
69:
1.1 paf 70: public: // usage
71:
1.12 misha 72: VConsole() {
73: fused=false;
74: }
1.1 paf 75:
1.12 misha 76: private:
77: bool fused;
1.1 paf 78: };
79:
80: #endif
E-mail: