Updated Spanish translation
[anjuta-git-plugin.git] / plugins / search / search-replace_backend.h
blob6ea583b68226e669b2a80ba500a52dfab4c6e7bc
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #ifndef _SEARCH_REPLACE_BACKEND_H
18 #define _SEARCH_REPLACE_BACKEND_H
20 #ifdef __cplusplus
21 extern "C"
23 #endif
25 #include <pcre.h>
27 #include <libanjuta/interfaces/ianjuta-document-manager.h>
28 #include <libanjuta/interfaces/ianjuta-editor.h>
31 /* PCRE search compiled pattern and other info */
32 typedef struct _PcreInfo
34 gint ovec_count;;
35 gint *ovector;
36 pcre *re;
37 pcre_extra *extra;
38 } PcreInfo;
40 /* Search expression options */
41 typedef struct _SearchExpression
43 gchar *search_str;
44 gboolean regex;
45 gboolean greedy;
46 gboolean ignore_case;
47 gboolean whole_word;
48 gboolean whole_line;
49 gboolean word_start;
50 gboolean no_limit;
51 gint actions_max;
52 PcreInfo *re;
53 } SearchExpression;
56 /* Direction to search (only valid for the current buffer). Note that backward
57 search does not work for regular expressions. */
58 typedef enum _SearchDirection
60 SD_FORWARD, /* Forward from the cursor */
61 SD_BACKWARD, /* Backward from the cursor */
62 SD_BEGINNING /* From the beginning of the buffer */
63 } SearchDirection;
65 /* Where to search - type */
66 typedef enum _SearchRangeType
68 SR_BUFFER, /* Current buffer */
69 SR_SELECTION, /* Selected text only */
70 SR_BLOCK, /* Current block */
71 SR_FUNCTION, /* Current function */
72 SR_OPEN_BUFFERS, /* All open buffers */
73 SR_PROJECT, /* All project files */
74 SR_FILES /* A set of patterns specifying which files to search */
75 } SearchRangeType;
78 ** Search variable is a string which is expanded using the properties interface
80 typedef gchar *SearchVar;
82 /* Specify files to search in. Note that each GList is a list of strings which
83 can be fixed strings or contain globbing patterns (the type used by ls). */
84 typedef struct _SearchFiles
86 gchar *top_dir;
87 GList *match_files;
88 GList *match_dirs;
89 GList *ignore_files;
90 GList *ignore_dirs;
91 gboolean ignore_hidden_files;
92 gboolean ignore_hidden_dirs;
93 gboolean recurse;
94 } SearchFiles;
96 /* Search range - used to create search list of files */
97 typedef struct _SearchRange
99 SearchRangeType type;
100 SearchDirection direction; /* type = SR_BUFFER */
101 gboolean whole;
102 SearchVar var; /* type = SR_VARIABLE */
103 SearchFiles files; /* type = SR_FILES */
104 } SearchRange;
106 /* What to do with the result of the search */
107 typedef enum _SearchAction
109 SA_SELECT, /* Jump to the next match and select it (current buffer only)*/
110 SA_BOOKMARK, /* Bookmark all lines containing a match (open buffers only) */
111 SA_HIGHLIGHT, /* Highlight all matched strings (open buffers only) */
112 SA_FIND_PANE, /* Show result in find pane */
113 SA_REPLACE, /* Replace next match with specified string */
114 SA_REPLACEALL /* Replace all matches with specified string */
115 } SearchAction;
117 /* Search master option structure */
118 typedef struct _Search
120 SearchExpression expr;
121 SearchRange range;
122 SearchAction action;
123 GList *expr_history;
124 gint incremental_pos;
125 gboolean incremental_wrap;
126 gboolean basic_search;
127 } Search;
129 /* Contains information about replacement */
130 typedef struct _Replace
132 gchar *repl_str;
133 gboolean regex;
134 gboolean confirm;
135 gboolean load_file;
136 GList *expr_history;
137 } Replace;
139 typedef struct _SearchReplace
141 Search search;
142 Replace replace;
143 IAnjutaDocumentManager *docman;
145 } SearchReplace;
147 typedef enum _FileBufferType
149 FB_NONE,
150 FB_FILE, /* File loaded from disk */
151 FB_EDITOR /* Corresponding to a TextEditor structure */
152 } FileBufferType;
154 typedef struct _FileBuffer
156 FileBufferType type;
157 /* The following are valid only for files loaded from disk */
158 gchar *name; /* Name of the file */
159 gchar *path; /* Full path to the file */
160 gchar *buf; /* Contents of the file */
161 gint len; /* Length of the buffer */
162 gint pos; /* Current position */
163 gint endpos; /* Restrict action upto this position */
164 gint line; /* Current line */
165 GList *lines; /* List of integers specifying line start positions */
166 /* The following are valid only for files corresponding to a TextEditor */
167 IAnjutaEditor *te;
168 } FileBuffer;
171 /* A search entry is a file or buffer to search. This can be a file,
172 a buffer or part of a buffer (such as selected text) */
173 typedef enum _SearchEntryType
175 SE_FILE,
176 SE_BUFFER,
177 } SearchEntryType;
179 typedef struct _SearchEntry
181 SearchEntryType type;
182 gchar *path;
183 IAnjutaEditor *te;
184 SearchDirection direction;
185 gint start_pos;
186 gint end_pos;
187 } SearchEntry;
189 typedef struct _MatchInfo
191 gint pos;
192 gint len;
193 gint line;
194 GList *subs; /* <MatchSubStr *> */
195 } MatchInfo;
198 // void search_and_replace_backend_init (AnjutaDocman *dm);
200 void function_select (IAnjutaEditor *te);
202 GList *create_search_entries(Search *s);
204 FileBuffer *file_buffer_new_from_te (IAnjutaEditor *te);
206 FileBuffer *
207 file_buffer_new_from_path(const char *path, const char *buf, int len, int pos);
209 FileBuffer *
210 file_buffer_new_from_path(const char *path, const char *buf, int len, int pos);
212 gchar *file_match_line_from_pos(FileBuffer *fb, int pos);
214 MatchInfo *get_next_match(FileBuffer *fb, SearchDirection direction, SearchExpression *s);
216 gchar *regex_backref(MatchInfo *mi, FileBuffer *fb);
218 void match_info_free (MatchInfo *mi);
220 void file_buffer_free (FileBuffer *fb);
222 SearchReplace *create_search_replace_instance(IAnjutaDocumentManager *docman);
224 void clear_pcre(void);
226 #ifdef __cplusplus
228 #endif
230 #endif /* _SEARCH_REPLACE_H */