Skip to content

Commit

Permalink
Add github ci workflow, fix build with flags
Browse files Browse the repository at this point in the history
fix build with flags -Wall -Werror -Wshadow -pedantic
  • Loading branch information
ItsZariep committed Dec 8, 2024
1 parent b8891ff commit 972e102
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 57 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Continous CI

permissions:
contents: write

on:
push:
branches: [ "stable" ]
pull_request:
branches: [ "stable" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up variables
id: date
run: |
echo "DATE=$(git log -n 1 --format='%ad' --date=format-local:'%Y%m%d.%H%M')" >> $GITHUB_ENV
echo "GH_RELEASE_FILE=sgnotes-$(cat ./VERSION)-$(ldd --version | awk '/ldd/{print "-gnu-" $NF}')" >> $GITHUB_ENV
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
libgtk-3-dev \
libgtksourceview-4-dev \
pkg-config \
clang
- name: Build with GCC
run: |
make CC=gcc
strip sgnotes
mv sgnotes ${{ env.GH_RELEASE_FILE }}
- name: Build with Clang
run: |
make CC=clang
continue-on-error: true

- name: Build with -Werror
run: |
clang `pkg-config --cflags gtk+-3.0 gtksourceview-4` -Dpver=\"1.0\" -DWITHSOURCEVIEW -c -o sgnotes.o sgnotes.c -Wall -Werror -pedantic -Wshadow --verbose
continue-on-error: true

- name: Release
uses: softprops/action-gh-release@v2
with:
name: Release ci-${{ env.DATE }}
body: ${{ github.event.head_commit.message }}
tag_name: ${{ env.DATE }}
files: |
${{ env.GH_RELEASE_FILE }}
2 changes: 1 addition & 1 deletion cfgmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void toggleautosave(void)

void closecfg(void)
{
visiblecfgmgr = 1;
visiblecfgmgr = 0;
gtk_widget_destroy(dialog);
}

Expand Down
32 changes: 15 additions & 17 deletions editor.h
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
void find (GtkTextView *text_view, const gchar *text, GtkTextIter *iter)
void find (GtkTextView *input, const gchar *text, GtkTextIter *iter)
{
GtkTextIter mstart, mend;
gboolean found;
GtkTextBuffer *buffer;
GtkTextBuffer *currentbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
GtkTextMark *last_pos;

buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
found = gtk_text_iter_forward_search (iter, text, 0, &mstart, &mend, NULL);

if (found)
{
gtk_text_buffer_select_range (buffer, &mstart, &mend);
gtk_text_buffer_select_range (currentbuffer, &mstart, &mend);
last_pos = gtk_text_buffer_create_mark (buffer, "last_pos",
&mend, FALSE);
gtk_text_view_scroll_mark_onscreen (text_view, last_pos);
gtk_text_view_scroll_mark_onscreen (input, last_pos);
}
}

void search_entry_changed(GtkEditable *editable, gpointer user_data)
{
const gchar *text;
GtkTextBuffer *buffer;
GtkTextBuffer *currentbuffer = NULL;
GtkTextIter iter;

text = gtk_entry_get_text(GTK_ENTRY(editable));

buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
gtk_text_buffer_get_start_iter(buffer, &iter);
gtk_text_buffer_get_start_iter(currentbuffer, &iter);

find(GTK_TEXT_VIEW(text_view), text, &iter);
}

void next_button_clicked(GtkWidget *next_button)
void next_button_clicked(GtkWidget *input)
{
const gchar *text;
GtkTextBuffer *buffer;
GtkTextBuffer *currentbuffer = NULL;
GtkTextMark *last_pos;
GtkTextIter iter;

text = gtk_entry_get_text(GTK_ENTRY(search_entry));

buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));

last_pos = gtk_text_buffer_get_mark(buffer, "last_pos");
last_pos = gtk_text_buffer_get_mark(currentbuffer, "last_pos");
if (last_pos == NULL)
{
return;
Expand All @@ -52,26 +51,25 @@ void next_button_clicked(GtkWidget *next_button)
find(GTK_TEXT_VIEW(text_view), text, &iter);
}

void prev_button_clicked(GtkWidget *prev_button)
void prev_button_clicked(GtkWidget *input)
{
const gchar *text;
GtkTextBuffer *buffer;
GtkTextMark *last_found;
GtkTextBuffer *currentbuffer;
GtkTextIter iter, start, end;

text = gtk_entry_get_text(GTK_ENTRY(search_entry));
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
currentbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
last_found = gtk_text_buffer_get_mark(buffer, "last_pos");

if (last_found != NULL)
{
gtk_text_buffer_get_iter_at_mark(buffer, &iter, last_found);
gtk_text_buffer_get_iter_at_mark(currentbuffer, &iter, last_found);

if (gtk_text_iter_backward_search(&iter, text, 0, &start, &end, NULL))
{
gtk_text_buffer_select_range(buffer, &start, &end);
gtk_text_buffer_select_range(currentbuffer, &start, &end);
gtk_text_mark_set_visible(last_found, FALSE);
last_found = gtk_text_buffer_create_mark(buffer, "last_pos", &start, FALSE);
last_found = gtk_text_buffer_create_mark(currentbuffer, "last_pos", &start, FALSE);
gtk_text_mark_set_visible(last_found, TRUE);
gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(text_view), last_found, 0.0, TRUE, 0.5, 0.5);
}
Expand Down
19 changes: 9 additions & 10 deletions events.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ void window_set_icon(GtkWindow *target, gchar *iconname)

gint show_warning_dialog(const gchar *message)
{
GtkWidget *dialog;

dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
Expand Down Expand Up @@ -263,7 +262,7 @@ static gboolean filelist_element_showmenu(GtkWidget *widget, GdkEventButton *eve
return FALSE;
}

void on_workspace_row_activated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer dialog)
void on_workspace_row_activated(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer output)
{
GtkTreeModel *model;
GtkTreeIter iter;
Expand All @@ -278,7 +277,7 @@ void on_workspace_row_activated(GtkTreeView *tree_view, GtkTreePath *path, GtkTr
strncpy(current_workspace, selected_workspace, sizeof(current_workspace) - 1);
g_free(selected_workspace);

gtk_widget_destroy(dialog);
gtk_widget_destroy(output);
restart_program();
}
}
Expand All @@ -301,8 +300,8 @@ void adjust_font_size(GtkWidget *widget, gpointer data)
gtk_css_provider_load_from_data(provider, css, -1, NULL);
g_free(css);

GtkStyleContext *context = gtk_widget_get_style_context(GTK_WIDGET(text_view));
gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
GtkStyleContext *currentcontext = gtk_widget_get_style_context(GTK_WIDGET(text_view));
gtk_style_context_add_provider(currentcontext, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

g_object_unref(provider);
}
Expand Down Expand Up @@ -429,11 +428,11 @@ gboolean on_list_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
return FALSE;
}
// Entry dialogs behavior
static gboolean on_entry_key_press(GtkWidget *widget, GdkEventKey *event, GtkDialog *dialog)
static gboolean on_entry_key_press(GtkWidget *widget, GdkEventKey *event, GtkDialog *input)
{
if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter)
{
gtk_dialog_response(dialog, GTK_RESPONSE_OK);
gtk_dialog_response(input, GTK_RESPONSE_OK);
return TRUE;
}
return FALSE;
Expand Down Expand Up @@ -511,13 +510,13 @@ void on_filelist_item_selected(gpointer user_data)
cooldown = 0;
}

gboolean on_treeview_clicked(GtkWidget *treeview, GdkEventButton *event, gpointer data)
gboolean on_treeview_clicked(GtkWidget *input, GdkEventButton *event, gpointer data)
{
if (event->button == 3)
{
GtkTreePath *path = NULL;
GtkTreeViewColumn *column = NULL;
if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), (gint)event->x, (gint)event->y, &path, &column, NULL, NULL))
if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(input), (gint)event->x, (gint)event->y, &path, &column, NULL, NULL))
{
gchar *path_string = gtk_tree_path_to_string(path);
selfromtreeview = atoi(path_string);
Expand All @@ -533,7 +532,7 @@ gboolean on_treeview_clicked(GtkWidget *treeview, GdkEventButton *event, gpointe
{
GtkTreePath *path = NULL;
GtkTreeViewColumn *column = NULL;
if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), (gint)event->x, (gint)event->y, &path, &column, NULL, NULL))
if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(input), (gint)event->x, (gint)event->y, &path, &column, NULL, NULL))
{
gchar *path_string = gtk_tree_path_to_string(path);
selfromtreeview = atoi(path_string);
Expand Down
38 changes: 16 additions & 22 deletions fmanip.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void on_save_button_clicked(GtkButton *button, gpointer user_data)
}
}

void on_create_new_workspace(GtkButton *button, gpointer dialog)
void on_create_new_workspace(GtkButton *button, gpointer voiddialog)
{
GtkWidget *entry, *dialog_new_workspace;
GtkWidget *dialog_content;
Expand Down Expand Up @@ -108,7 +108,7 @@ void on_workspace_menu_item_activate(GtkMenuItem *menuitem, gpointer user_data)
gchar *objetive = g_build_filename(home_dir, notes_dir, clicked_workspace, NULL);
printf("Workspace selected: %s\n", objetive);

GtkWidget *dialog = gtk_message_dialog_new
dialog = gtk_message_dialog_new
(
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(menuitem))),
GTK_DIALOG_MODAL,
Expand Down Expand Up @@ -216,14 +216,14 @@ void load_file_list(void)
{
GtkTreeViewColumn *column;
GtkTreeIter iter;
gchar *notes_path = g_build_filename(home_dir, notes_dir, current_workspace, NULL);
gchar *current_notes_path = g_build_filename(home_dir, notes_dir, current_workspace, NULL);

DIR *dir;
struct dirent *entry;

filelist_store = gtk_tree_store_new(1, G_TYPE_STRING);

if ((dir = opendir(notes_path)) != NULL)
if ((dir = opendir(current_notes_path)) != NULL)
{
while ((entry = readdir(dir)) != NULL)
{
Expand All @@ -243,7 +243,7 @@ void load_file_list(void)
gtk_tree_view_append_column(GTK_TREE_VIEW(filelist), column);
}
g_object_unref(imglist_store);
g_free(notes_path);
g_free(current_notes_path);
}

int remove_recursive(const gchar *path)
Expand Down Expand Up @@ -400,7 +400,7 @@ void on_export_button_clicked(GtkButton *button, gpointer user_data)
}

gchar *file_path = g_build_filename(home_dir, notes_dir, current_workspace, current_file, NULL);
gchar *data_path = g_build_filename(home_dir, notes_dir, current_workspace, g_strdup_printf("%s_files", current_file), NULL);
//gchar *data_path = g_build_filename(home_dir, notes_dir, current_workspace, g_strdup_printf("%s_files", current_file), NULL);

GtkWidget *file_chooser_dialog;
file_chooser_dialog = gtk_file_chooser_dialog_new("Select Destination",
Expand All @@ -414,13 +414,13 @@ void on_export_button_clicked(GtkButton *button, gpointer user_data)
{
GtkFileChooser *chooser = GTK_FILE_CHOOSER(file_chooser_dialog);
gchar *destination_file = gtk_file_chooser_get_filename(chooser);
GError *error = NULL;
GError *currenterror = NULL;

if (g_file_test(file_path, G_FILE_TEST_EXISTS))
{
if (g_file_copy(g_file_new_for_path(file_path),
g_file_new_for_path(destination_file),
G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error))
G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &currenterror))
{
GtkWidget *success_dialog = gtk_message_dialog_new(GTK_WINDOW(window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
Expand All @@ -439,7 +439,7 @@ void on_export_button_clicked(GtkButton *button, gpointer user_data)
"Failed to copy file: %s", error->message);
gtk_dialog_run(GTK_DIALOG(error_dialog));
gtk_widget_destroy(error_dialog);
g_error_free(error);
g_error_free(currenterror);
}
}
else
Expand All @@ -462,8 +462,6 @@ void save_file(const gchar *filename)
gchar *full_path;
FILE *file;

const gchar *home_dir = g_get_home_dir();

gchar *dir_path = g_build_filename(home_dir, ".local", "share", "sgnotes", current_workspace, NULL);
if (!g_file_test(dir_path, G_FILE_TEST_EXISTS))
g_mkdir_with_parents(dir_path, 0700);
Expand All @@ -488,8 +486,6 @@ void saveToFile(const gchar *text)
gchar *full_path;
FILE *file;
gint note_overwrite = 0;

const gchar *home_dir = g_get_home_dir();
gchar *dir_path = g_build_filename(home_dir, ".local", "share", "sgnotes", current_workspace, NULL);

if (!g_file_test(dir_path, G_FILE_TEST_EXISTS))
Expand All @@ -501,19 +497,19 @@ void saveToFile(const gchar *text)

if (g_file_test(full_path, G_FILE_TEST_EXISTS))
{
GtkWidget *dialog;
GtkWidget *savedialog;

if (permitoverwrite)
{
dialog = gtk_message_dialog_new(NULL,
savedialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
"The file already exists. Do you want to overwrite it?");
gtk_window_set_title(GTK_WINDOW(dialog), "Confirm");
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
gint result = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
gtk_window_set_title(GTK_WINDOW(savedialog), "Confirm");
gtk_window_set_position(GTK_WINDOW(savedialog), GTK_WIN_POS_CENTER);
gint result = gtk_dialog_run(GTK_DIALOG(savedialog));
gtk_widget_destroy(savedialog);

if (result == GTK_RESPONSE_NO || result == GTK_RESPONSE_CANCEL)
{
Expand Down Expand Up @@ -642,8 +638,6 @@ void on_rename_button_clicked(GtkButton *button, gpointer user_data)
gtk_widget_destroy(rename_dialog);
return;
}

const gchar *home_dir = g_get_home_dir();
g_autofree gchar *dir_path = g_build_filename(home_dir, ".local", "share", "sgnotes", current_workspace, NULL);

if (!g_file_test(dir_path, G_FILE_TEST_EXISTS))
Expand Down Expand Up @@ -750,7 +744,7 @@ void on_rename_button_clicked(GtkButton *button, gpointer user_data)

static void submenu_item_newnote_selected(GtkWidget *widget, gpointer data)
{
GtkWidget *dialog, *content_area, *entry;
GtkWidget *content_area, *entry;
gint result;

dialog = gtk_dialog_new_with_buttons("New Note:",
Expand Down
6 changes: 3 additions & 3 deletions img.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ void add_images_from_directory(GtkWidget *widget, gpointer user_data)
return;
}

GError *error = NULL;
GFileEnumerator *enumerator = g_file_enumerate_children(directory, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NONE, NULL, &error);
GError *currenterror = NULL;
GFileEnumerator *enumerator = g_file_enumerate_children(directory, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NONE, NULL, &currenterror);

if (error != NULL)
if (currenterror != NULL)
{
g_print("Failed to enum files on directory: %s\n", error->message);
g_error_free(error);
Expand Down
Loading

0 comments on commit 972e102

Please sign in to comment.