blob: bc0541d9fdecaeaafd3823811f25d3d240375cbe [file] [log] [blame]
Jari Aaltobb706242000-03-17 21:46:59 +00001/* pcomplete.h - structure definitions and other stuff for programmable
Jari Aalto31859422009-01-12 13:36:28 +00002n completion. */
Jari Aaltobb706242000-03-17 21:46:59 +00003
Jari Aalto31859422009-01-12 13:36:28 +00004/* Copyright (C) 1999-2009 Free Software Foundation, Inc.
Jari Aaltobb706242000-03-17 21:46:59 +00005
6 This file is part of GNU Bash, the Bourne Again SHell.
7
Jari Aalto31859422009-01-12 13:36:28 +00008 Bash is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
Jari Aaltobb706242000-03-17 21:46:59 +000012
Jari Aalto31859422009-01-12 13:36:28 +000013 Bash is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
Jari Aaltobb706242000-03-17 21:46:59 +000017
Jari Aalto31859422009-01-12 13:36:28 +000018 You should have received a copy of the GNU General Public License
19 along with Bash. If not, see <http://www.gnu.org/licenses/>.
20*/
Jari Aaltobb706242000-03-17 21:46:59 +000021
22#if !defined (_PCOMPLETE_H_)
23# define _PCOMPLETE_H_
24
25#include "stdc.h"
26#include "hashlib.h"
27
28typedef struct compspec {
29 int refcount;
30 unsigned long actions;
Jari Aalto28ef6c32001-04-06 19:14:31 +000031 unsigned long options;
Jari Aaltobb706242000-03-17 21:46:59 +000032 char *globpat;
33 char *words;
34 char *prefix;
35 char *suffix;
36 char *funcname;
37 char *command;
38 char *filterpat;
39} COMPSPEC;
40
41/* Values for COMPSPEC actions. These are things the shell knows how to
42 build internally. */
43#define CA_ALIAS (1<<0)
44#define CA_ARRAYVAR (1<<1)
45#define CA_BINDING (1<<2)
46#define CA_BUILTIN (1<<3)
47#define CA_COMMAND (1<<4)
48#define CA_DIRECTORY (1<<5)
49#define CA_DISABLED (1<<6)
50#define CA_ENABLED (1<<7)
51#define CA_EXPORT (1<<8)
52#define CA_FILE (1<<9)
53#define CA_FUNCTION (1<<10)
Jari Aaltof73dda02001-11-13 17:56:06 +000054#define CA_GROUP (1<<11)
55#define CA_HELPTOPIC (1<<12)
56#define CA_HOSTNAME (1<<13)
57#define CA_JOB (1<<14)
58#define CA_KEYWORD (1<<15)
59#define CA_RUNNING (1<<16)
Jari Aalto7117c2d2002-07-17 14:10:11 +000060#define CA_SERVICE (1<<17)
61#define CA_SETOPT (1<<18)
62#define CA_SHOPT (1<<19)
63#define CA_SIGNAL (1<<20)
64#define CA_STOPPED (1<<21)
65#define CA_USER (1<<22)
66#define CA_VARIABLE (1<<23)
Jari Aaltobb706242000-03-17 21:46:59 +000067
Jari Aalto28ef6c32001-04-06 19:14:31 +000068/* Values for COMPSPEC options field. */
69#define COPT_RESERVED (1<<0) /* reserved for other use */
70#define COPT_DEFAULT (1<<1)
71#define COPT_FILENAMES (1<<2)
72#define COPT_DIRNAMES (1<<3)
Jari Aalto7117c2d2002-07-17 14:10:11 +000073#define COPT_NOSPACE (1<<4)
Jari Aaltob80f6442004-07-27 13:29:18 +000074#define COPT_BASHDEFAULT (1<<5)
75#define COPT_PLUSDIRS (1<<6)
Jari Aaltobb706242000-03-17 21:46:59 +000076
77/* List of items is used by the code that implements the programmable
78 completions. */
79typedef struct _list_of_items {
80 int flags;
Jari Aaltof73dda02001-11-13 17:56:06 +000081 int (*list_getter) __P((struct _list_of_items *)); /* function to call to get the list */
Jari Aaltobb706242000-03-17 21:46:59 +000082
83 STRINGLIST *slist;
84
85 /* These may or may not be used. */
86 STRINGLIST *genlist; /* for handing to the completion code one item at a time */
87 int genindex; /* index of item last handed to completion code */
88
89} ITEMLIST;
90
91/* Values for ITEMLIST -> flags */
92#define LIST_DYNAMIC 0x001
93#define LIST_DIRTY 0x002
94#define LIST_INITIALIZED 0x004
95#define LIST_MUSTSORT 0x008
96#define LIST_DONTFREE 0x010
97#define LIST_DONTFREEMEMBERS 0x020
98
99extern HASH_TABLE *prog_completes;
100extern int prog_completion_enabled;
101
102/* Not all of these are used yet. */
103extern ITEMLIST it_aliases;
104extern ITEMLIST it_arrayvars;
105extern ITEMLIST it_bindings;
106extern ITEMLIST it_builtins;
107extern ITEMLIST it_commands;
108extern ITEMLIST it_directories;
109extern ITEMLIST it_disabled;
110extern ITEMLIST it_enabled;
111extern ITEMLIST it_exports;
112extern ITEMLIST it_files;
113extern ITEMLIST it_functions;
Jari Aaltof73dda02001-11-13 17:56:06 +0000114extern ITEMLIST it_groups;
Jari Aaltobb706242000-03-17 21:46:59 +0000115extern ITEMLIST it_hostnames;
116extern ITEMLIST it_jobs;
117extern ITEMLIST it_keywords;
118extern ITEMLIST it_running;
Jari Aalto7117c2d2002-07-17 14:10:11 +0000119extern ITEMLIST it_services;
Jari Aaltobb706242000-03-17 21:46:59 +0000120extern ITEMLIST it_setopts;
121extern ITEMLIST it_shopts;
122extern ITEMLIST it_signals;
123extern ITEMLIST it_stopped;
124extern ITEMLIST it_users;
125extern ITEMLIST it_variables;
126
Jari Aalto31859422009-01-12 13:36:28 +0000127extern COMPSPEC *pcomp_curcs;
128extern const char *pcomp_curcmd;
129
Jari Aaltobb706242000-03-17 21:46:59 +0000130/* Functions from pcomplib.c */
Jari Aalto7117c2d2002-07-17 14:10:11 +0000131extern COMPSPEC *compspec_create __P((void));
132extern void compspec_dispose __P((COMPSPEC *));
133extern COMPSPEC *compspec_copy __P((COMPSPEC *));
Jari Aaltobb706242000-03-17 21:46:59 +0000134
Jari Aalto7117c2d2002-07-17 14:10:11 +0000135extern void progcomp_create __P((void));
136extern void progcomp_flush __P((void));
137extern void progcomp_dispose __P((void));
Jari Aaltobb706242000-03-17 21:46:59 +0000138
Jari Aalto7117c2d2002-07-17 14:10:11 +0000139extern int progcomp_size __P((void));
Jari Aaltobb706242000-03-17 21:46:59 +0000140
Jari Aalto7117c2d2002-07-17 14:10:11 +0000141extern int progcomp_insert __P((char *, COMPSPEC *));
142extern int progcomp_remove __P((char *));
Jari Aaltobb706242000-03-17 21:46:59 +0000143
Jari Aalto7117c2d2002-07-17 14:10:11 +0000144extern COMPSPEC *progcomp_search __P((const char *));
Jari Aaltobb706242000-03-17 21:46:59 +0000145
Jari Aalto7117c2d2002-07-17 14:10:11 +0000146extern void progcomp_walk __P((hash_wfunc *));
Jari Aaltobb706242000-03-17 21:46:59 +0000147
148/* Functions from pcomplete.c */
149extern void set_itemlist_dirty __P((ITEMLIST *));
150
Jari Aaltof73dda02001-11-13 17:56:06 +0000151extern STRINGLIST *completions_to_stringlist __P((char **));
152
Jari Aalto28ef6c32001-04-06 19:14:31 +0000153extern STRINGLIST *gen_compspec_completions __P((COMPSPEC *, const char *, const char *, int, int));
154extern char **programmable_completions __P((const char *, const char *, int, int, int *));
Jari Aaltobb706242000-03-17 21:46:59 +0000155
Jari Aalto31859422009-01-12 13:36:28 +0000156extern void pcomp_set_readline_variables __P((int, int));
157extern void pcomp_set_compspec_options __P((COMPSPEC *, int, int));
Jari Aaltobb706242000-03-17 21:46:59 +0000158#endif /* _PCOMPLETE_H_ */