File: newcmdwin32cl.h

package info (click to toggle)
sdcc 3.5.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 59,964 kB
  • ctags: 66,696
  • sloc: ansic: 422,129; cpp: 49,032; makefile: 46,849; sh: 28,496; perl: 12,125; asm: 11,748; yacc: 6,698; lisp: 1,630; lex: 747; python: 660; awk: 495; sed: 89
file content (150 lines) | stat: -rw-r--r-- 4,210 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * Simulator of microcontrollers (cmd.src/newcmdwin32cl.h)
 *
 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
 * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
 *
 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
 *
 */

/* This file is part of microcontroller simulator: ucsim.

UCSIM is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

UCSIM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with UCSIM; see the file COPYING.  If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/*@1@*/

#ifndef CMD_NEWCMDFDCL_HEADER
#define CMD_NEWCMDFDCL_HEADER

#include "newcmdcl.h"
#include "cmdutil.h"


class cl_channel
{
public:
  cl_channel(void) { set(); }
  cl_channel(HANDLE _handle, e_handle_type _type = CH_UNDEF) { set(_handle, _type); }
  cl_channel(FILE *_fp, e_handle_type _type = CH_UNDEF) { set(_fp, _type); }

  void set(void);
  void set(HANDLE _handle, e_handle_type _type = CH_UNDEF);
  void set(FILE *_fp, e_handle_type _type = CH_UNDEF);

  void close(void);
  bool input_avail(void) const { return ::input_avail(handle, type); }
  enum e_handle_type get_type(void) const { return type; }
  HANDLE get_handle(void) const { return handle; }
  FILE *get_fp(void) const { return fp; }
  bool is_tty(void) const { return CH_FILE != type; }
  bool is_eof(void) const { return get_fp() ? feof(get_fp()) : true; }

private:
  e_handle_type guess_type(void) { return get_handle_type(handle); }

  e_handle_type type;
  HANDLE handle;
  FILE *fp;
};


/*
 * Command socket console
 */

class cl_console: public cl_console_base
{
  friend class cl_commander;

protected:
  cl_channel in, out, rout/*redirected output*/;

public:
  cl_console(void) { in = cl_channel(); out = cl_channel(); rout = cl_channel(); }
  cl_console(const char *fin, const char *fout, class cl_app *the_app);
  cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
  cl_console(cl_channel _in, cl_channel _out, class cl_app *the_app);

  int cmd_do_print(const char *format, va_list ap);

  virtual ~cl_console(void);
  virtual class cl_console *clone_for_exec(char *fin);

  virtual void redirect(char *fname, char *mode);
  virtual void un_redirect(void);
  virtual bool is_tty(void) const { return CH_FILE != in.get_type(); }
  virtual bool is_eof(void) const { return in.is_eof(); }
  virtual HANDLE get_in_fd(void) { return in.get_handle(); }
  virtual bool input_avail(void) { return input_active() ? in.input_avail() : false; }
  virtual char *read_line(void);

private:
  class cl_channel *get_out(void) { return (CH_UNDEF != rout.get_type()) ? &rout : &out; }
};

class cl_listen_console: public cl_console
{
public:
  cl_listen_console(int serverport, class cl_app *the_app);

  virtual void welcome(void) {}
  virtual int proc_input(class cl_cmdset *cmdset);
};

class cl_sub_console: public cl_console
{
private:
  class cl_console_base *parent;

public:
  cl_sub_console(class cl_console_base *the_parent,
                 cl_channel _in, cl_channel _out, class cl_app *the_app);
  virtual ~cl_sub_console(void);
  virtual int init(void);
};


/*
 * Command interpreter
 */

class cl_commander: public cl_commander_base
{
private:
  fd_set read_set, active_set, console_active_set;

public:
  cl_commander(class cl_app *the_app, class cl_cmdset *acmdset)
    : cl_commander_base(the_app, acmdset)
  {
  }

  virtual int init(void);
  virtual void set_fd_set(void);
  virtual int input_avail(void) { return input_avail_timeout(0); }
  virtual int wait_input(void);
  virtual int proc_input(void);

private:
  int console_count(void);
  int console_input_avail(void);
  int socket_input_avail(long timeout, bool sleep);
  int input_avail_timeout(long timeout);
};

#endif

/* End of cmd.src/newcmdwin32cl.h */