summaryrefslogtreecommitdiff
path: root/dselect/bindings.h
blob: dd5879bc57e3e4769c5a214e347adb35846113ed (plain)
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
/* -*- c++ -*-
 * dselect - selection of Debian packages
 * bindings.h - keybindings class header file
 *
 * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
 *
 * This 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,
 * or (at your option) any later version.
 *
 * This 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 dpkg; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef BINDINGS_H
#define BINDINGS_H

enum quitaction;

struct keybindings {
  struct interpretation;

  struct orgbinding {
    int key;
    const char *action;
  };
  
  struct keyname {
    int key;
    const char *kname;
  };
  
  struct description {
    const char *action, *desc;
  };

  struct binding {
    binding *next;
    int key;
    const struct interpretation *interp;
    const char *desc;
  };
  
 private:
  static const keyname keynames[];
  static const description descriptions[];

  binding *bindings;
  const description *iterate;
  const interpretation *interps;
  
  int bind(int key, const char *action);
  
 public:
  int name2key(const char *name);
  const char *key2name(int key);
  
  int bind(const char *name, const char *action) { return bind(name2key(name),action); }
  const interpretation *operator()(int key);
  const char *find(const char *action);

  void describestart() { iterate=descriptions; }
  const char **describenext();
  //... returns array, null-term, first element is description, rest are key strings
  // caller must delete[] the array.  Null means end.

  keybindings(const interpretation *ints, const orgbinding *orgbindings);
  ~keybindings();
};

#include "pkglist.h"
#include "method.h"

struct keybindings::interpretation {
  const char *action;
  void (methodlist::*mfn)();
  void (packagelist::*pfn)();
  quitaction qa;
};

extern const keybindings::interpretation packagelist_kinterps[];
extern const keybindings::orgbinding packagelist_korgbindings[];

extern const keybindings::interpretation methodlist_kinterps[];
extern const keybindings::orgbinding methodlist_korgbindings[];

#endif /* BINDINGS_H */