[Pkg-wmaker-commits] [wmstickynotes] 35/81: Added nostore argumesn (thanks to wbk <coydog at coydogsoftware.net> for the suggestion). Also added a few bits of safety code for a few things that I noticed while I was in there.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Tue Aug 25 02:33:47 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmstickynotes.

commit b62b35744b1074987f70fea71ea6305a934ce4a8
Author: hnc <hnc at 7fc852e4-12a7-4f5b-bad7-374d67da4d19>
Date:   Tue Mar 25 17:45:15 2014 +0000

    Added nostore argumesn (thanks to wbk <coydog at coydogsoftware.net> for the suggestion).  Also added a few bits of safety code for a few things that I noticed while I was in there.
---
 Makefile.am     |   2 +-
 README          |   4 +--
 THANKS          |   3 ++
 configure.ac    |   2 +-
 wmstickynotes.c | 104 +++++++++++++++++++++++++++++++++++---------------------
 5 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 14712a7..1b9603d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -10,5 +10,5 @@ AUTOMAKE_OPTIONS = gnu
 bin_PROGRAMS = wmstickynotes
 wmstickynotes_SOURCES = wmstickynotes.c wmstickynotes.h wmstickynotes.xpm delete_button.xpm resize_button.xpm
 
-wmstickynotes_LDADD = @GTK_LIBS@
+wmstickynotes_LDADD = @GTK_LIBS@ -lX11
 EXTRA_DIST = THANKS
diff --git a/README b/README
index 5ca861e..21ca6e3 100644
--- a/README
+++ b/README
@@ -3,8 +3,8 @@ wmstickynotes
 Heath Caldwell <hncaldwell at gmail.com>
 
 This program is a Window Maker style dockapp which allows you to create note
-windows.  The notes, along with their position, size, and color, are stored on
-disk and will be restored when wmstickynotes is run again.
+windows.  By default, the notes, along with their position, size, and color,
+are stored in files and will be restored when wmstickynotes is run again.
 
 Left click the note icon to create a new note with the default color (yellow).
 
diff --git a/THANKS b/THANKS
index 39cdeda..a391b7b 100644
--- a/THANKS
+++ b/THANKS
@@ -1,3 +1,6 @@
 Thanks to David Raufeisen for this post:
 http://mail.gnome.org/archives/gtk-list/2000-January/msg00072.html
 which helped me learn how to make a gtk+ dockapp.
+
+Thanks to wbk <coydog at coydogsoftware.net> for the suggestion to add an argument
+for not storing the notes.
diff --git a/configure.ac b/configure.ac
index e79eda2..474f81c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,7 +4,7 @@
 # Heath Caldwell <hncaldwell at gmail.com>
 #
 
-AC_INIT([wmstickynotes], [0.2], [Heath Caldwell <hncaldwell at gmail.com>])
+AC_INIT([wmstickynotes], [0.3], [Heath Caldwell <hncaldwell at gmail.com>])
 AM_INIT_AUTOMAKE
 AC_CONFIG_HEADER([config.h])
 
diff --git a/wmstickynotes.c b/wmstickynotes.c
index dc73dae..ecaf9b0 100644
--- a/wmstickynotes.c
+++ b/wmstickynotes.c
@@ -29,9 +29,12 @@
 GdkColormap *colormap;
 
 /* The highest note id used so far (this is used when making a new note so
- * that no ids are clobbered */
+ * that no ids are clobbered) */
 long int highest_note_id = 0;
 
+/* Whether notes should be stored for later retrieval. */
+int store_notes = TRUE;
+
 /* The current note that the popup menu was shown for */
 Note *current_note;
 
@@ -40,11 +43,12 @@ Note *current_note;
 void usage()
 {
 	printf("Usage: wmstickynotes [options]\n");
-	printf("\toptions:\n");
-	printf("\t-d [dir], --directory=[dir]\tSet directory in which to store notes\n");
-	printf("\t\t\t\t\tDefaults to $HOME/%s\n", default_wmstickynotes_dir);
-	printf("\t-v, --version\tPrint version information\n");
-	printf("\t-h, --help\tPrint usage\n");
+	printf("    options:\n");
+	printf("        -n, --nostore                  Don't store notes (or read previously stored notes)\n");
+	printf("        -d [dir], --directory=[dir]    Set directory in which to store/read notes\n");
+	printf("                                       Defaults to $HOME/%s\n", default_wmstickynotes_dir);
+	printf("        -v, --version                  Print version information\n");
+	printf("        -h, --help                     Print usage\n");
 }
 
 int main(int argc, char *argv[])
@@ -69,17 +73,17 @@ int main(int argc, char *argv[])
 	int i = 0;
 
 	struct option long_options[] = {
+		{"nostore", no_argument, 0, 'n'},
 		{"directory", required_argument, 0, 'd'},
 		{"version", no_argument, 0, 'v'},
 		{"help", no_argument, 0, 'h'},
 		{0, 0, 0, 0}};
 
-	for(
-		i = getopt_long(argc, argv, "d:vh", long_options, &option_index);
-		i >= 0;
-		i = getopt_long(argc, argv, "d:vh", long_options, &option_index)
-	) {
+	while((i = getopt_long(argc, argv, "nd:vh", long_options, &option_index)) > -1) {
 		switch(i) {
+			case 'n':
+				store_notes = FALSE;
+				break;
 			case 'd':
 				wmstickynotes_dir = optarg;
 				use_default_dir = FALSE;
@@ -99,33 +103,39 @@ int main(int argc, char *argv[])
 
 	umask(077);
 
-	if(use_default_dir) {
-		wmstickynotes_dir = calloc(
-			strlen(default_wmstickynotes_dir) +
-			strlen(getenv("HOME")) + 2, sizeof(char));
-		strcpy(wmstickynotes_dir, getenv("HOME"));
-		strcat(wmstickynotes_dir, "/");
-		strcat(wmstickynotes_dir, default_wmstickynotes_dir);
-	}
-
-	if(chdir(wmstickynotes_dir)) {
-		if(errno == ENOENT) {
-			if(mkdir(wmstickynotes_dir, 0777)) {
-				fprintf(stderr, "Couldn't make directory: %s\n", wmstickynotes_dir);
+	if(store_notes) {
+		if(use_default_dir) {
+			wmstickynotes_dir = calloc(
+				strlen(default_wmstickynotes_dir) +
+				strlen(getenv("HOME")) + 2, sizeof(char));
+			if(!wmstickynotes_dir) {
+				fprintf(stderr, "calloc() failed for directory string.\n");
 				exit(1);
 			}
-			if(chdir(wmstickynotes_dir)) {
+			strcpy(wmstickynotes_dir, getenv("HOME"));
+			strcat(wmstickynotes_dir, "/");
+			strcat(wmstickynotes_dir, default_wmstickynotes_dir);
+		}
+	
+		if(chdir(wmstickynotes_dir)) {
+			if(errno == ENOENT) {
+				if(mkdir(wmstickynotes_dir, 0777)) {
+					fprintf(stderr, "Couldn't make directory: %s\n", wmstickynotes_dir);
+					exit(1);
+				}
+				if(chdir(wmstickynotes_dir)) {
+					fprintf(stderr, "Couldn't change to directory: %s\n", wmstickynotes_dir);
+					exit(1);
+				}
+			} else {
 				fprintf(stderr, "Couldn't change to directory: %s\n", wmstickynotes_dir);
 				exit(1);
 			}
-		} else {
-			fprintf(stderr, "Couldn't change to directory: %s\n", wmstickynotes_dir);
-			exit(1);
 		}
+	
+		if(use_default_dir) free(wmstickynotes_dir);
 	}
 
-	if(use_default_dir) free(wmstickynotes_dir);
-
 	gtk_init(&argc, &argv);
 
 	colormap = gdk_colormap_new(gdk_visual_get_system(), TRUE);
@@ -177,7 +187,9 @@ int main(int argc, char *argv[])
 	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
 	g_signal_connect(G_OBJECT(main_button_box), "button-press-event", G_CALLBACK(main_button_pressed), color_menu);
 
-	read_old_notes();
+	if(store_notes) {
+		read_old_notes();
+	}
 	gtk_main();
 
 	return 0;
@@ -186,8 +198,14 @@ int main(int argc, char *argv[])
 void delete_note(GtkWidget *widget, Note *note)
 {
 	char *filename;
-	asprintf(&filename, "%d", note->id);
-	unlink(filename);
+
+	if(store_notes) {
+		asprintf(&filename, "%d", note->id);
+		if(unlink(filename)) {
+			fprintf(stderr, "Error deleting note file '%s'.  errno: %d\n", filename, errno);
+		}
+	}
+
 	free(note);
 }
 
@@ -200,6 +218,10 @@ void save_note(GtkWidget *widget, Note *note)
 	GtkTextIter end;
 	gchar *text;
 
+	if(!store_notes) {
+		return;
+	}
+
 	text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(note->text_widget));
 	gtk_text_buffer_get_start_iter(text_buffer, &start);
 	gtk_text_buffer_get_end_iter(text_buffer, &end);
@@ -208,13 +230,19 @@ void save_note(GtkWidget *widget, Note *note)
 
 	asprintf(&filename, "%d", note->id);
 	file = fopen(filename, "w");
-	free(filename);
 
-	fprintf(
-		file, "%d,%d,%d,%d,%d,%d,%s\n%s",
-		note->x, note->y, note->width, note->height, 0, 0, note->scheme->name, text);
-	fclose(file);
+	if(file) {
+		if(fprintf(file, "%d,%d,%d,%d,%d,%d,%s\n%s",
+		           note->x, note->y, note->width, note->height, 0, 0, note->scheme->name, text)
+		   < 0) {
+			fprintf(stderr, "Error writing to note file '%s'.  errno: %d\n", filename, errno);
+		}
+		fclose(file);
+	} else {
+		fprintf(stderr, "Error opening note file '%s'.  errno: %d\n", filename, errno);
+	}
 
+	free(filename);
 	g_free(text);
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmstickynotes.git



More information about the Pkg-wmaker-commits mailing list