X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fxsublim.c;h=ca4fb9e0d0a02f4d423398777cbeed092a76d0b7;hb=06e9a7886a77cad92f9ddbc169d6d199a4d8b76d;hp=231bddc4c6f5ae4a10864e0aef4d8a5d97881ec3;hpb=af290bcdf2d1c61efc8aaaff653745c900cbe98c;p=xscreensaver diff --git a/hacks/xsublim.c b/hacks/xsublim.c index 231bddc4..ca4fb9e0 100644 --- a/hacks/xsublim.c +++ b/hacks/xsublim.c @@ -31,6 +31,7 @@ /* Arguments ****************************************************************** -font font Font to use + -file filename New-line delimited phrase file -delayShow ms Microsecs for display of each word -delayWord ms Microsecs for blank between words -delayPhraseMin ms Microsecs for min blank between phrases @@ -41,6 +42,18 @@ -no-screensaver Draw over active windows -outline Draw a contrasting outline around words (Default) -no-outline Draw words without an outline + -center Draw words in the center of the screen (Default) + -no-center Draw words randomly around the screen +*/ + + +/* Changelog ****************************************************************** + + 1.1.0 19991221 Added -file + 1.0.1 19990716 Assume that XGetImage()/XDestroyImage() don't leak, + which they apparently don't. I have no idea how I + convinced myself that they did. Huh. (greg@eod.com) + 1.0.0 19990716 Initial release */ @@ -71,6 +84,7 @@ #include #include #include +#include #include #include #include @@ -87,6 +101,7 @@ #endif #include "usleep.h" +#include "yarandom.h" #include "resources.h" @@ -103,10 +118,12 @@ char* defaults[] = "Submit.\\n" "Conform.\\n" "Obey.\\n" + "OBEY. OBEY. OBEY.\\n" "Consume.\\n" "Be silent.\\n" "Fear.\\n" "Waste.\\n" + "Money.\\n" "Watch TV.\\n" "Hate yourself.\\n" "Buy needlessly.\\n" @@ -117,6 +134,9 @@ char* defaults[] = "You serve no purpose.\\n" "Your contributions are ignored.\\n" "They are laughing at you.\\n" + "They lied to you.\\n" + "They read your mail.\\n" + "They know.\\n" "Surrender.\\n" "You will fail.\\n" "Never question.\\n" @@ -380,7 +400,6 @@ int main(int argc,char* argv[]) "-*-times-*-r-*-*-*-600-*-*-p-*-*-*", "-*-*-*-r-*-sans-*-600-*-*-p-*-*-*", "-*-*-*-r-*-*-*-600-*-*-m-*-*-*", - "-*-helvetica-*-r-*-*-*-240-*-*-p-*-*-*", "-*-lucida-*-r-*-*-*-240-*-*-p-*-*-*", "-*-times-*-r-*-*-*-240-*-*-p-*-*-*", @@ -441,8 +460,10 @@ int main(int argc,char* argv[]) signal(sig_Number,xsublim_Sig_Catch); } - /* Randomize */ - srandom((int)time((time_t*)0)); + /* Randomize -- only need to do this here because this program + doesn't use the `screenhack.h' or `lockmore.h' APIs. */ +# undef ya_rand_init + ya_rand_init ((int) time ((time_t *) 0)); /* Handle all the X nonsense */ #if defined(__sgi) @@ -511,10 +532,47 @@ int main(int argc,char* argv[]) text_Item = 0; text_Count = 0; memset(text_Used,0,sizeof(text_Used)); - arg_Text = get_string_resource(XSUBLIM_ARG_PHRASES,"Phrases"); + arg_Text = get_string_resource(XSUBLIM_ARG_FILE,"Filename"); + if (arg_Text != NULL) + { + FILE* file_Fs; + struct stat file_Stat; + + file_Fs = fopen(arg_Text,"rb"); + if (file_Fs == NULL) + { + fprintf(stderr,"%s: Could not open '%s'\n",progname, + arg_Text); + exit(-1); + } + if (fstat(fileno(file_Fs),&file_Stat) != 0) + { + fprintf(stderr,"%s: Could not stat '%s'\n",progname, + arg_Text); + exit(-1); + } + arg_Text = calloc(1,file_Stat.st_size+1); + if (arg_Text != NULL) + { + if (fread(arg_Text,file_Stat.st_size,1,file_Fs) != 1) + { + fprintf(stderr,"%s: Could not read '%s'\n", + progname,arg_Text); + exit(-1); + } + } + fclose(file_Fs); + } + else + { + arg_Text = get_string_resource(XSUBLIM_ARG_PHRASES,"Phrases"); + if (arg_Text != NULL) + { + arg_Text = strdup(arg_Text); + } + } if (arg_Text != NULL) { - arg_Text = strdup(arg_Text); while (((text_Phrase = strtok(arg_Text,"\n")) != NULL) && (text_Count < XSUBLIM_TEXT_COUNT)) { @@ -522,8 +580,8 @@ int main(int argc,char* argv[]) text_List[text_Count] = text_Phrase; text_Count++; } + text_List[text_Count] = NULL; } - text_List[text_Count] = NULL; if (text_Count == 0) { fprintf(stderr,"%s: No text to display\n",progname); @@ -734,18 +792,15 @@ int main(int argc,char* argv[]) image_Y,image_Width,image_Height); } - /* Free the image (and it's goddamned structure - -- the man page for XCreateImage() lies, - lies, lies!) */ + /* Free the image */ XDestroyImage(image_Image); - XFree(image_Image); } /* Restore the error handler, ungrab the server */ - XSync(disp_Display, FALSE); + XSync(disp_Display,FALSE); XSetErrorHandler(Xsublim_Sh_Handler); XUngrabServer(disp_Display); - XSync(disp_Display, FALSE); + XSync(disp_Display,FALSE); /* Pause between words */ if (Xsublim_Sig_Last == -1)