Recognize #!/bin/dash as shebang for Shell files (closes #3470986)
[geany-mirror.git] / src / build.h
blob7387163cfd62f6fb29d2b1341ca4ba42288fa2b3
1 /*
2 * build.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2011 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2011 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
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.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 /* * @file build.h Interface to the Build menu functionality. */
24 #ifndef GEANY_BUILD_H
25 #define GEANY_BUILD_H 1
27 /* Order is important (see GBO_TO_GBG, GBO_TO_CMD below) */
28 /* * Geany Known Build Commands.
29 * These commands are named after their default use.
30 * Only these commands can currently have keybindings.
31 **/
32 typedef enum
34 GEANY_GBO_COMPILE, /* *< default compile file */
35 GEANY_GBO_BUILD, /* *< default build file */
36 GEANY_GBO_MAKE_ALL, /* *< default make */
37 GEANY_GBO_CUSTOM, /* *< default make user specified target */
38 GEANY_GBO_MAKE_OBJECT, /* *< default make object, make %e.o */
39 GEANY_GBO_EXEC, /* *< default execute ./%e */
40 GEANY_GBO_COUNT /* *< count of how many */
41 } GeanyBuildType;
43 /* * Groups of Build menu items. */
44 typedef enum
46 GEANY_GBG_FT, /* *< filetype items */
47 GEANY_GBG_NON_FT, /* *< non filetype items.*/
48 GEANY_GBG_EXEC, /* *< execute items */
49 GEANY_GBG_COUNT /* *< count of groups. */
50 } GeanyBuildGroup;
52 /* include the fixed widgets in an array indexed by groups */
53 #define GBG_FIXED GEANY_GBG_COUNT
55 /* * Convert @c GeanyBuildType to @c GeanyBuildGroup.
57 * This macro converts @c GeanyBuildType enum values (the "known" commands)
58 * to the group they are part of.
60 * @param gbo the @c GeanyBuildType value.
62 * @return the @c GeanyBuildGroup group that @a gbo is in.
64 * Note this is a macro so that it can be used in static initialisers.
65 **/
66 #define GBO_TO_GBG(gbo) ((gbo)>GEANY_GBO_EXEC?GEANY_GBG_COUNT:((gbo)>=GEANY_GBO_EXEC?GEANY_GBG_EXEC: \
67 ((gbo) >= GEANY_GBO_MAKE_ALL ? GEANY_GBG_NON_FT : GEANY_GBG_FT)))
69 /* * Convert @c GeanyBuildType to command index.
71 * This macro converts @c GeanyBuildType enum values (the "known" commands)
72 * to the index within the group.
74 * @param gbo the @c GeanyBuildType value.
76 * @return the index of the @a gbo command in its group.
78 * Note this is a macro so that it can be used in static initialisers.
79 **/
80 #define GBO_TO_CMD(gbo) ((gbo)>=GEANY_GBO_COUNT?(gbo)-GEANY_GBO_COUNT:((gbo)>=GEANY_GBO_EXEC?(gbo)-GEANY_GBO_EXEC: \
81 ((gbo) >= GEANY_GBO_MAKE_ALL ? (gbo)-GEANY_GBO_MAKE_ALL : (gbo))))
83 enum GeanyBuildFixedMenuItems
85 GBF_NEXT_ERROR,
86 GBF_PREV_ERROR,
87 GBF_COMMANDS,
88 GBF_SEP_1,
89 GBF_SEP_2,
90 GBF_SEP_3,
91 GBF_SEP_4,
92 GBF_COUNT
95 /* * Build menu item sources in increasing priority */
96 typedef enum
98 GEANY_BCS_DEF, /* *< Default values. */
99 GEANY_BCS_FT, /* *< System filetype values. */
100 GEANY_BCS_HOME_FT, /* *< Filetypes in ~/.config/geany/filedefs */
101 GEANY_BCS_PREF, /* *< Preferences file ~/.config/geany/geany.conf */
102 GEANY_BCS_PROJ_FT, /* *< Project file filetype command */
103 GEANY_BCS_PROJ, /* *< Project file if open. */
104 GEANY_BCS_COUNT /* *< Count of sources. */
105 } GeanyBuildSource;
107 typedef struct GeanyBuildInfo
109 GeanyBuildGroup grp;
110 guint cmd;
111 GPid pid; /* process id of the spawned process */
112 gchar *dir;
113 guint file_type_id;
114 gchar *custom_target;
115 gint message_count;
116 } GeanyBuildInfo;
118 extern GeanyBuildInfo build_info;
120 /* * The entries of a command for a menu item */
121 typedef enum GeanyBuildCmdEntries
123 GEANY_BC_LABEL, /* *< The menu item label, _ marks mnemonic */
124 GEANY_BC_COMMAND, /* *< The command to run. */
125 GEANY_BC_WORKING_DIR, /* *< The directory to run in */
126 GEANY_BC_CMDENTRIES_COUNT /* *< Count of entries */
127 } GeanyBuildCmdEntries;
129 /* * The command for a menu item. */
130 typedef struct GeanyBuildCommand
132 /* * Pointers to g_string values of the command entries.
133 * Must be freed if the pointer is changed. */
134 gchar *label; /* *< Menu item label */
135 gchar *command; /* *< Command to run */
136 gchar *working_dir; /* *< working directory */
137 gboolean exists; /* *< If the entries have valid values. */
138 gboolean changed; /* *< Save on exit if @c changed, remove if not @c exist. */
139 gboolean old; /* *< Converted from old format. */
140 } GeanyBuildCommand;
142 typedef struct BuildMenuItems
144 GtkWidget *menu;
145 GtkWidget **menu_item[GEANY_GBG_COUNT + 1]; /* +1 for fixed items */
146 } BuildMenuItems;
148 /* a structure defining the destinations for a set of groups of commands & regex */
149 typedef struct BuildDestination
151 GeanyBuildCommand **dst[GEANY_GBG_COUNT];
152 gchar **fileregexstr;
153 gchar **nonfileregexstr;
154 } BuildDestination;
156 /* opaque pointers returned from build functions and passed back to them */
157 typedef struct BuildTableFields *BuildTableData;
160 void build_init(void);
162 void build_finalize(void);
164 /* menu configuration dialog functions */
165 GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, BuildTableData *data, GeanyFiletype *ft);
167 void build_read_project(GeanyFiletype *ft, BuildTableData build_properties);
169 void build_free_fields(BuildTableData data);
171 /* build response decode assistance function */
172 gboolean build_parse_make_dir(const gchar *string, gchar **prefix);
174 /* build menu functions */
176 void build_menu_update(GeanyDocument *doc);
178 void build_toolbutton_build_clicked(GtkAction *action, gpointer user_data);
180 void build_remove_menu_item(GeanyBuildSource src, GeanyBuildGroup grp, gint cmd);
182 GeanyBuildCommand *build_get_menu_item(GeanyBuildSource src, GeanyBuildGroup grp, guint cmd);
184 GeanyBuildCommand *build_get_current_menu_item(GeanyBuildGroup grp, guint cmd, guint *src);
186 BuildMenuItems *build_get_menu_items(gint filetype_idx);
188 /* load and store menu configuration */
189 void build_load_menu(GKeyFile *config, GeanyBuildSource dst, gpointer ptr);
191 void build_save_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src);
193 void build_set_group_count(GeanyBuildGroup grp, gint count);
195 guint build_get_group_count(GeanyBuildGroup grp);
197 gchar **build_get_regex(GeanyBuildGroup grp, GeanyFiletype *ft, guint *from);
199 #endif