150b1aaae29770c7b861a4db2d005aa4429e2e39
[libguestfs.git] / fish / completion.c
1 /* libguestfs generated file
2  * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3  * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
4  *
5  * Copyright (C) 2009 Red Hat Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <config.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #ifdef HAVE_LIBREADLINE
29 #include <readline/readline.h>
30 #endif
31
32 #include "fish.h"
33
34 #ifdef HAVE_LIBREADLINE
35
36 static const char *commands[] = {
37   "add",
38   "add-cdrom",
39   "add-drive",
40   "aug-close",
41   "aug-defnode",
42   "aug-defvar",
43   "aug-get",
44   "aug-init",
45   "aug-insert",
46   "aug-load",
47   "aug-ls",
48   "aug-match",
49   "aug-mv",
50   "aug-rm",
51   "aug-save",
52   "aug-set",
53   "autosync",
54   "cat",
55   "cdrom",
56   "chmod",
57   "chown",
58   "command",
59   "command-lines",
60   "config",
61   "exists",
62   "file",
63   "get-autosync",
64   "get-path",
65   "get-verbose",
66   "is-dir",
67   "is-file",
68   "kill-subprocess",
69   "launch",
70   "list-devices",
71   "list-partitions",
72   "ll",
73   "ls",
74   "lvcreate",
75   "lvm-remove-all",
76   "lvs",
77   "lvs-full",
78   "mkdir",
79   "mkdir-p",
80   "mkfs",
81   "mount",
82   "mounts",
83   "path",
84   "pvcreate",
85   "pvs",
86   "pvs-full",
87   "read-lines",
88   "rm",
89   "rm-rf",
90   "rmdir",
91   "run",
92   "set-autosync",
93   "set-path",
94   "set-verbose",
95   "sfdisk",
96   "sync",
97   "touch",
98   "umount",
99   "umount-all",
100   "unmount",
101   "unmount-all",
102   "verbose",
103   "vgcreate",
104   "vgs",
105   "vgs-full",
106   "write-file",
107   NULL
108 };
109
110 static char *
111 generator (const char *text, int state)
112 {
113   static int index, len;
114   const char *name;
115
116   if (!state) {
117     index = 0;
118     len = strlen (text);
119   }
120
121   while ((name = commands[index]) != NULL) {
122     index++;
123     if (strncasecmp (name, text, len) == 0)
124       return strdup (name);
125   }
126
127   return NULL;
128 }
129
130 #endif /* HAVE_LIBREADLINE */
131
132 char **do_completion (const char *text, int start, int end)
133 {
134   char **matches = NULL;
135
136 #ifdef HAVE_LIBREADLINE
137   if (start == 0)
138     matches = rl_completion_matches (text, generator);
139 #endif
140
141   return matches;
142 }