libanjuta: Added "opened" signal to IAnjutaFile interface
[anjuta.git] / plugins / gdb / utilities.h
bloba72f4f8096aef2df3135403fa317d55bee82d60b
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 utilities.h
4 Copyright (C) 2000 Kh. Naba Kumar Singh
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef _UTILITIES_H_
21 #define _UTILITIES_H_
23 #include <glib.h>
24 #include <libanjuta/anjuta-plugin.h>
26 #if 0
27 #define FILE_BUFFER_SIZE 1024
29 #define FREE(x) if (x) g_free(x), x = NULL
31 #include <dirent.h>
32 #include <stdio.h>
34 #include <libanjuta/anjuta-plugin.h>
36 #define _STR(S) ((S)?(S):"")
38 /* Any addition to this enum must be synced with the
39 function get_file_ext_type() */
40 enum _FileExtType
42 FILE_TYPE_UNKNOWN,
43 FILE_TYPE_DIR,
44 FILE_TYPE_C,
45 FILE_TYPE_CPP,
46 FILE_TYPE_HEADER,
47 FILE_TYPE_PASCAL,
48 FILE_TYPE_RC,
49 FILE_TYPE_IDL,
50 FILE_TYPE_CS,
51 FILE_TYPE_JAVA,
52 FILE_TYPE_JS,
53 FILE_TYPE_CONF,
54 FILE_TYPE_HTML,
55 FILE_TYPE_XML,
56 FILE_TYPE_LATEX,
57 FILE_TYPE_LUA,
58 FILE_TYPE_PERL,
59 FILE_TYPE_SH,
60 FILE_TYPE_PYTHON,
61 FILE_TYPE_RUBY,
62 FILE_TYPE_PROPERTIES,
63 FILE_TYPE_PROJECT,
64 FILE_TYPE_BATCH,
65 FILE_TYPE_ERRORLIST,
66 FILE_TYPE_MAKEFILE,
67 FILE_TYPE_IFACE,
68 FILE_TYPE_DIFF,
69 FILE_TYPE_ICON,
70 FILE_TYPE_IMAGE,
71 FILE_TYPE_ASM,
72 FILE_TYPE_SCM,
73 FILE_TYPE_PO,
74 FILE_TYPE_SQL,
75 FILE_TYPE_PLSQL,
76 FILE_TYPE_VB,
77 FILE_TYPE_BAAN,
78 FILE_TYPE_ADA,
79 FILE_TYPE_WSCRIPT,
80 FILE_TYPE_LISP,
81 FILE_TYPE_MATLAB,
82 FILE_TYPE_END_MARK
85 typedef enum _FileExtType FileExtType;
87 /* Gets the swapped (c/h) file names */
88 gchar* get_swapped_filename(const gchar* filename);
90 /* Get a unique temporary filename */
91 /* This filename is not valid beyond the present session */
92 gchar* get_a_tmp_file(void);
94 /* Retruns the contents of the file a buffer */
95 gchar* get_file_as_buffer (const gchar* filename);
97 /* Creates a space separated string from the list of strings */
98 gchar* string_from_glist (GList* list);
101 /***********************************************************************************/
102 /* Functions that do not dynamic allocate memory. Return value should not be g_freed */
103 /***********************************************************************************/
105 /* Get a fixed font */
106 PangoFontDescription* get_fixed_font (void);
108 /* Rather tough */
109 gboolean read_string(FILE* stream, gchar* token, gchar **str);
110 gboolean read_line(FILE* stream, gchar **str);
111 gboolean write_string(FILE* stream, gchar* token, gchar *str);
112 gboolean write_line(FILE* stream, gchar *str);
114 /* Get the filename */
115 const gchar* extract_filename (const gchar* full_filename);
117 /* Get directory of file, return value must be g_freed */
118 gchar* extract_directory (const gchar* full_filename);
120 /* Adds the given string in the list, if it does not already exist. */
121 /* The added string will come at the top of the list */
122 /* The list will be then truncated to (length) items only */
123 GList* update_string_list(GList *p_list, const gchar *p_str, gint length);
125 /* Gets the extension of the file */
126 const gchar* get_file_extension(const gchar* file);
128 /* Gets the file extension type */
129 FileExtType get_file_ext_type(const gchar* file);
132 void fast_widget_repaint(GtkWidget* w);
135 /* Comapares the two data */
136 /* Don't use this func. Define your own */
137 gint compare_string_func(gconstpointer a, gconstpointer b);
139 /* Checks if the file is of the given type */
140 gboolean file_is_regular(const gchar * fn);
141 gboolean file_is_directory(const gchar * fn);
142 gboolean file_is_link(const gchar * fn);
143 gboolean file_is_char_device(const gchar * fn);
144 gboolean file_is_block_device(const gchar * fn);
145 gboolean file_is_fifo(const gchar * fn);
146 gboolean file_is_socket(const gchar * fn);
147 gboolean file_is_readable(const gchar * fn);
148 gboolean file_is_readonly(const gchar * fn);
149 gboolean file_is_readwrite(const gchar * fn);
150 gboolean file_is_writable(const gchar * fn);
151 gboolean file_is_executable(const gchar * fn);
152 gboolean file_is_suid(const gchar * fn);
153 gboolean file_is_sgid(const gchar * fn);
154 gboolean file_is_sticky(const gchar * fn);
156 /* copies src to dest */
157 /* if (show_error) is true, then a dialog box will be shown for the error */
158 gboolean copy_file(const gchar* src, const gchar* dest, gboolean show_error);
160 /* bytewise compares two files and returns true for same or false for */
161 /* different or error */
162 /* if (show_error) is true, then a dialog box will be shown for the error */
163 gboolean compare_files(const gchar* file1, const gchar* file2, gboolean show_error);
165 /* (src) will be renamed, ie moved, to (dest) if they are not same */
166 /* Used to avoid unnecessary change in modified time of the dest file */
167 /* Which may result in recompilation, etc */
168 gboolean move_file_if_not_same (const gchar* src, const gchar* dest);
170 /* Check if two files/dirs/etc are the same one */
171 gboolean is_file_same(const gchar *a, const gchar *b);
173 /* Update, flush and paint all gtk widgets */
174 void update_gtk(void);
176 /* Sets a text (chars) in the entry (w) */
177 /* Text will be selected if use_selection is true */
178 /* TODO void entry_set_text_n_select(GtkWidget* w, gchar* chars, gboolean use_selection); */
180 /* Creates a dir, if it already doesnot exists */
181 /* All the required parent dirs are also created if they don't exist */
182 gboolean force_create_dir(const gchar* d);
184 /* Checks if the (parent) is parent widget of the (child)*/
185 gboolean widget_is_child(GtkWidget *parent, GtkWidget* child);
187 /* Fast string assignment to avoid memory leaks */
188 /* Assigns a new string (value), if not NULL, with g_strdup() to (*string) */
189 /* The previous string, if not NULL, is g_freed */
190 void string_assign (gchar** string, const gchar* value);
192 /* Returns true if the e->d_name is a regular file */
193 /* Used as the callback for scandir() */
194 int select_only_file (const struct dirent *e);
196 /***********************************************/
197 /* Functions that operate on list of strings. */
198 /***********************************************/
199 void glist_strings_free(GList* list);
200 void glist_strings_prefix (GList * list, const gchar *prefix);
201 void glist_strings_sufix (GList * list, const gchar *sufix);
202 GList* glist_strings_sort (GList * list);
204 /**********************************************************/
205 /* Both the returned glist and the data should be g_freed */
206 /* Call g_list_strings_free() to do that. */
207 /**********************************************************/
208 GList* glist_from_data (guint props, const gchar* id);
209 GList* glist_from_string (const gchar* id);
210 GList* glist_strings_dup (GList * list);
212 /* Returns the alphabatically sorted list for files in dir */
213 /* select is the func that approves (returning 1)each file */
214 GList* scan_files_in_dir (const char *dir, int (*select)(const struct dirent *));
216 /* Create a new hbox with an image and a label packed into it
217 * and return the box. */
218 GtkWidget*
219 create_xpm_label_box(GtkWidget *parent,
220 const gchar *xpm_filename, gboolean gnome_pixmap,
221 const gchar *label_text );
223 /* Write in file....*/
224 gchar *WriteBufUL( gchar* szDst, const gulong ulVal);
225 gchar *WriteBufI( gchar* szDst, const gint iVal );
226 gchar *WriteBufB( gchar* szDst, const gboolean bVal );
227 gchar *WriteBufS( gchar* szDst, const gchar* szVal );
229 void
230 free_string_list ( GList * pList );
232 /********************************************************
233 * Escapes single and double quotes in the given string *
234 * Return string must be g_freed() *
235 ********************************************************/
236 gchar* anjuta_util_escape_quotes(const gchar* str);
238 /********************************************************
239 * Use this function instead of kill() to send a signal *
240 * to the process which runs in separate process group, *
241 * because normally kill() wouldn't work *
242 * Returns: status of the kill *
243 ********************************************************/
244 gint anjuta_util_kill(pid_t process_id, const gchar* signal_name);
246 /********************************************************
247 * This function parses a string and returns a GList of *
248 * program args, just like shell parses the program args*
249 ********************************************************/
250 GList* anjuta_util_parse_args_from_string (const gchar* string);
252 /* Gets the relative filename w.r.t the given directory */
253 gchar *get_relative_file_name(const gchar *dir, const gchar *file);
255 /* Checks if the file exists in the given directory or any of it's subdirectories */
256 gboolean is_file_in_dir(const gchar *file, const gchar *dir);
258 GList *glist_path_dedup(GList *list);
260 /* String integer mapping utility functions */
261 typedef struct _StringMap
263 int type;
264 char *name;
265 } StringMap;
267 int type_from_string(StringMap *map, const char *str);
268 const char *string_from_type(StringMap *map, int type);
269 GList *glist_from_map(StringMap *map);
271 /* Return must be freed. Works even if str is already UTF8 string */
272 gchar *anjuta_util_convert_to_utf8 (const gchar *str);
274 GtkWidget * anjuta_util_toolbar_append_button (GtkWidget *toolbar,
275 const gchar *iconfile,
276 const gchar *label,
277 const gchar *tooltip,
278 GCallBack callback,
279 gpointer user_data);
280 GtkWidget *
281 anjuta_util_toolbar_append_stock (GtkWidget *toolbar, const gchar *stock_icon,
282 const gchar *tooltip, GCallBack callback,
283 gpointer user_data);
285 GtkWidget*
286 anjuta_dialog_add_button (GtkDialog *dialog, const gchar* text,
287 const gchar* stock_id, gint response_id);
288 GtkWidget*
289 anjuta_button_new_with_stock_image (const gchar* text, const gchar* stock_id);
291 /* Equivalent to gnome_execute_shell(), but does not overwrite
292 * SIGCHLD handler */
293 pid_t anjuta_execute_shell (const gchar *dir, const gchar *command);
295 #endif
297 /****************************************************************************
298 * Functions that dynamic allocate memory. Return value(s) should be g_freed
299 * Removes while spaces in the text
300 ****************************************************************************/
301 gchar* gdb_util_remove_white_spaces(const gchar* text);
303 /********************************************************
304 * Use this function instead of kill() to send a signal
305 * to the process which runs in separate process group,
306 * because normally kill() wouldn't work
307 * Returns: status of the kill
308 ********************************************************/
309 gint gdb_util_kill_process (pid_t process_id, const gchar* signal_name);
312 /********************************************************
313 * Check which gnome-terminal is installed
314 * Returns: 0 -- No gnome-terminal
315 * Returns: 1 -- Gnome1 gnome-terminal
316 * Returns: 2 -- Gnome2 gnome-terminal
317 ********************************************************/
318 gint gdb_util_check_gnome_terminal (void);
320 /********************************************************
321 * Returns true if the given line is parsable for
322 * file name and line number
323 * filename is set at (*filename), line number in lineno
324 * Don't forget to g_free (*filename)
325 ********************************************************/
326 gboolean gdb_util_parse_error_line(const gchar *line, gchar **filename,
327 guint *lineno);
329 /*******************************************************************/
330 /* In this case only GList must be freed and not the data */
331 /* Because output data are the input data. Only GList is allocated */
332 /*******************************************************************/
333 GList* gdb_util_remove_blank_lines(const GList* lines);
335 /* Allocates a struct of pointers if sep = 0 use ',' */
336 gchar **gdb_util_string_parse_separator (const gint nItems, gchar *szStrIn,
337 const gchar chSep /*= ','*/ );
339 #define PARSE_STR(nItems, szStr) gdb_util_string_parse_separator (nItems, \
340 szStr, \
341 ',' );
342 gchar* gdb_util_get_str_cod (const gchar *szIn);
344 /* Excluding the final 0 */
345 gint gdb_util_calc_string_len( const gchar *szStr );
346 gint gdb_util_calc_gnum_len( void /*const gint iVal*/ );
348 void gdb_util_show_messages (AnjutaPlugin *plugin);
349 void gdb_util_clear_messages (AnjutaPlugin *plugin);
350 void gdb_util_append_message (AnjutaPlugin *plugin, const gchar* message);
352 #endif