exposurses

Check-in [cf92beadf9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Split out ITEM creation into separate func so can clean on exit As otherwise can't free up the memory, etc. This makes clean up work Yay, pretty much done.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk | temp
Files: files | file ages | folders
SHA3-256: cf92beadf96dd867d8220f8131a3e2ff5bf77cea38d475ea75ed31f9521625ab
User & Date: base@atomicules.co.uk 2013-09-17 22:43:51
Context
2013-09-17
22:43
Split out ITEM creation into separate func so can clean on exit As otherwise can't free up the memory, etc. This makes clean up work Yay, pretty much done. Leaf check-in: cf92beadf9 user: base@atomicules.co.uk tags: trunk, temp
2013-09-15
21:25
Ignore selection of OVER/UNDER check-in: d4b0749e89 user: base@atomicules.co.uk tags: trunk, temp
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to exposurses.c.

    85     85   WINDOW *iso_win;
    86     86   WINDOW *shutter_win;
    87     87   WINDOW *aperture_win;
    88     88   
    89     89   void selection(char *name);
    90     90   void remove_menu(ITEM **items, MENU *men, int n);
    91     91   void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
    92         -MENU *add_menu(char **array, ITEM **items, int n);
           92  +MENU *add_menu(ITEM **items);
    93     93   WINDOW *add_window(int xpos, char *title);
           94  +ITEM **add_item(char **array, int n);
    94     95   int exposure(int iso);
    95     96   double shutter(int exposure, double aperture);
    96     97   double aperture(int exposure, double shutter);
    97     98   int nearest_match(double x, int menu, int n_array);
    98     99   double fraction_to_double(char *fraction);
    99    100   /* No one will ever need more than 9 bytes! */
   100    101   char exposure_sel[9] = "";
................................................................................
   126    127   	/* Create items */
   127    128   	/* Can't really avoid finding array sizes here */
   128    129   	n_exposure = ARRAY_SIZE(exposure_array);
   129    130   	n_iso = ARRAY_SIZE(iso_array);
   130    131   	n_shutter = ARRAY_SIZE(shutter_array);
   131    132   	n_aperture = ARRAY_SIZE(aperture_array);
   132    133   	/* http://stackoverflow.com/a/2620158/208793 */
   133         -	exposure_menu = add_menu(exposure_array, exposure_items, n_exposure);
   134         -	iso_menu = add_menu(iso_array, iso_items, n_iso);
   135         -	shutter_menu = add_menu(shutter_array, shutter_items, n_shutter);
   136         -	aperture_menu = add_menu(aperture_array, aperture_items, n_aperture);
          134  +	exposure_items = add_item(exposure_array, n_exposure);
          135  +	iso_items = add_item(iso_array, n_iso);
          136  +	aperture_items = add_item(aperture_array, n_aperture);
          137  +	shutter_items = add_item(shutter_array, n_shutter);
          138  +	exposure_menu = add_menu(exposure_items);
          139  +	iso_menu = add_menu(iso_items);
          140  +	shutter_menu = add_menu(shutter_items);
          141  +	aperture_menu = add_menu(aperture_items);
   137    142   	exposure_win = add_window(4, "EV");
   138    143   	iso_win = add_window(45, "ISO");
   139    144   	shutter_win = add_window(86, "Shutter");
   140    145   	aperture_win = add_window(127, "Aperture");
   141    146   	/* Don't know how to avoid the repition below */
   142    147   	set_menu_win(exposure_menu, exposure_win);
   143    148   	set_menu_win(iso_menu, iso_win);
................................................................................
   294    299   	remove_menu(exposure_items, exposure_menu, n_exposure);
   295    300   	remove_menu(iso_items, iso_menu, n_iso);
   296    301   	remove_menu(shutter_items, shutter_menu, n_shutter);
   297    302   	remove_menu(aperture_items, aperture_menu, n_aperture);
   298    303   	endwin();
   299    304   }
   300    305   
   301         -MENU *add_menu(char **array, ITEM **items, int n) {
          306  +ITEM **add_item(char **array, int n) {
   302    307   	int i;
          308  +	ITEM **local_items;
          309  +
          310  +	local_items = (ITEM **)calloc(n, sizeof(ITEM *));
          311  +	for(i = 0; i<n; ++i) {
          312  +		local_items[i] = new_item(array[i], array[i]);
          313  +		set_item_userptr(local_items[i], selection);
          314  +	}
          315  +	return local_items;
          316  +}
          317  +
          318  +MENU *add_menu(ITEM **items) {
   303    319   	MENU *local_menu;
   304    320   
   305         -	items = (ITEM **)calloc(n, sizeof(ITEM *));
   306         -	for(i = 0; i<n; ++i) {
   307         -		items[i] = new_item(array[i], array[i]);
   308         -		set_item_userptr(items[i], selection);
   309         -	}
   310    321   	local_menu = new_menu((ITEM **)items);
   311    322   	set_menu_format(local_menu, 5, 1);
   312    323   	set_menu_mark(local_menu, " * ");
   313    324   	return local_menu;
   314    325   }
   315    326   
   316    327   WINDOW *add_window(int xpos, char *title) {