X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fapple2-main.c;h=b2fad16e0f17dc31cef4e2bbdf0f6a4817245d02;hb=ec8d2b32b63649e6d32bdfb306eda062769af823;hp=175ecb887827d90b4cc8fc172dc82d3e78203f01;hpb=07faf451b99879183ed7e909e43a0e065be1ee7f;p=xscreensaver diff --git a/hacks/apple2-main.c b/hacks/apple2-main.c index 175ecb88..b2fad16e 100644 --- a/hacks/apple2-main.c +++ b/hacks/apple2-main.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1998-2006 Jamie Zawinski +/* xscreensaver, Copyright (c) 1998-2011 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -279,7 +279,6 @@ a2_dither (unsigned int *in, unsigned char *out, int w, int h) long *temp_err; int fs_scale = 1024; int brightness = 75; - int fs_direction; #if 0 { @@ -320,7 +319,6 @@ a2_dither (unsigned int *in, unsigned char *out, int w, int h) this_berr[x] = random() % (fs_scale * 2) - fs_scale; /* (random errors in [-1 .. 1]) */ } - fs_direction = 1; for (y = 0; y < h; y++) for (x = 0; x < w; x++) @@ -569,6 +567,9 @@ image_loaded_cb (Screen *screen, Window window, Drawable p, image (regardless of whether it started as TrueColor/PseudoColor.) */ pick_a2_subimage (dpy, window, image, buf32, w, h); + free(image->data); + image->data = 0; + XDestroyImage(image); /* Then dither the 32bpp image to a 6-color Apple][ colormap. */ @@ -705,7 +706,7 @@ static void slideshow_controller(apple2_sim_t *sim, int *stepno, basename = slash+1; } { - char *dot=strchr(basename,'.'); + char *dot=strrchr(basename,'.'); if (dot) *dot=0; } if (strlen(basename)>20) basename[20]=0; @@ -784,6 +785,7 @@ static void slideshow_controller(apple2_sim_t *sim, int *stepno, free(mine->render_img); free(mine->img_filename); free(mine); + mine = 0; return; } @@ -831,12 +833,18 @@ subproc_cb (XtPointer closure, int *source, XtInputId *id) mine->input_available_p = True; } +/* The structure of closure linkage throughout this code is so amazingly + baroque that I can't get to the 'struct state' from where I need it. */ +static const char *global_program; +static Bool global_fast_p; + + static void launch_text_generator (struct terminal_controller_data *mine) { XtAppContext app = XtDisplayToApplicationContext (mine->dpy); char buf[255]; - char *oprogram = get_string_resource (mine->dpy, "program", "Program"); + char *oprogram = strdup (global_program); char *program = (char *) malloc (strlen (oprogram) + 10); strcpy (program, "( "); @@ -905,6 +913,9 @@ launch_text_generator (struct terminal_controller_data *mine) sprintf (buf, "%.100s: %.100s", progname, program); perror(buf); } + + free(oprogram); + free(program); } static void @@ -944,7 +955,10 @@ terminal_read(struct terminal_controller_data *mine, unsigned char *buf, int n) return 1; } - if (!mine->input_available_p) return 0; + if (!mine || + !mine->input_available_p || + !mine->pipe) + return 0; rc=read (fileno (mine->pipe), (void *) buf, n); if (rc>0) mine->lastc=buf[rc-1]; @@ -1470,7 +1484,7 @@ terminal_controller(apple2_sim_t *sim, int *stepno, double *next_actiontime) "Boolean"); mine->swap_bs_del_p = get_boolean_resource (mine->dpy, "swapBSDEL", "Boolean"); - mine->fast_p = get_boolean_resource (mine->dpy, "fast", "Boolean"); + mine->fast_p = global_fast_p; switch(*stepno) { @@ -1523,6 +1537,7 @@ terminal_controller(apple2_sim_t *sim, int *stepno, double *next_actiontime) case A2CONTROLLER_FREE: terminal_closegen(mine); free(mine); + mine = 0; return; } } @@ -1885,6 +1900,7 @@ basic_controller(apple2_sim_t *sim, int *stepno, double *next_actiontime) case A2CONTROLLER_FREE: free(mine); + mine = 0; break; } @@ -1897,8 +1913,6 @@ static void (* const controllers[]) (apple2_sim_t *sim, int *stepno, basic_controller }; - - struct state { int duration; Bool random_p; @@ -1935,6 +1949,23 @@ apple2_init (Display *dpy, Window window) } if (s) free (s); + global_program = get_string_resource (dpy, "program", "Program"); + global_fast_p = get_boolean_resource (dpy, "fast", "Boolean"); + + + /* Kludge for MacOS standalone mode: see OSX/SaverRunner.m. */ + { + const char *s = getenv ("XSCREENSAVER_STANDALONE"); + if (s && *s && strcmp(s, "0")) + { + st->controller = terminal_controller; + st->random_p = False; + global_program = getenv ("SHELL"); + global_fast_p = True; + } + } + + if (! st->random_p) { if (st->controller == terminal_controller || st->controller == slideshow_controller)