Changeset tag,last-working,2
- Timestamp:
- 09/19/2007 11:06:52 PM (19 years ago)
- branch-nick:
- tui
- revision id:
- dsowen@fugue88.ws-20070919230652-gcf3h1qwf86lq8j7
- Location:
- tag/last-working
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tag/last-working/Makefile
r1 r2 1 menu2.so: menu2 1 menu2.so: menu2.c 2 rm -f menu2.so 3 gcc -shared -fPIC -o menu2.so menu2.c -lmenu -Wall -pedantic -
tag/last-working/curses.lisp
r1 r2 22 22 23 23 24 (define-foreign-library menu 25 (t (:default "libmenu")))24 (define-foreign-library menu2 25 (t "/home/dsowen/lisp/tui/menu2.so")) 26 26 27 (use-foreign-library menu )27 (use-foreign-library menu2) 28 28 29 (defctype item* :pointer) 30 (defctype menu* :pointer) 31 32 (defcfun new-item item* (name :string) (description :string)) 33 (defcfun free-item :int (item item*)) 34 (defcfun new-menu menu* (items :pointer)) 35 (defcfun post-menu :int (menu menu*)) 36 (defcfun menu-driver :int (menu menu*) (c :int)) 29 (defcfun menu2-create :int) 30 (defcfun menu2-add-item :int (menu :int) (name :string) (description :string)) 31 (defcfun menu2-destroy :int (menu :int)) 32 (defcfun menu2-post :int (menu :int)) 33 (defcfun menu2-drive :int (menu :int) (c :int)) 34 (defcfun menu2-unpost :int (menu :int)) 37 35 38 36 39 40 (defun make-menu (items)41 (let* ((items-vector42 (map 'vector43 (lambda (item)44 (etypecase item45 (string (new-item (foreign-string-alloc item) (foreign-string-alloc item)))46 (cons (new-item (foreign-string-alloc (car item)) (foreign-string-alloc (cdr item))))))47 items))48 (foreign-items (foreign-alloc 'item*49 :count (length items-vector)50 :initial-contents items-vector51 :null-terminated-p t)))52 (new-menu foreign-items)))53 37 54 38 (defun init-screen () -
tag/last-working/menu2.c
r1 r2 12 12 char *item_names[_MAX_ITEMS]; 13 13 char *item_descriptions[_MAX_ITEMS]; 14 ITEM *item_structs[_MAX_ITEMS + 1]; 14 15 int item_count; 16 17 MENU *menu_struct; /* Only set when posted. */ 15 18 }; 16 19 … … 43 46 { 44 47 struct menu2_t *m = _menus[menu - 1]; 48 int *i; 49 45 50 if(!m) return 0; 46 51 47 if(m->item_count == _MAX_ITEMS) return 0; 52 i = &(m->item_count); 53 if(*i == _MAX_ITEMS) return 0; 48 54 49 m->item_names[m->item_count] = strdup(name); 50 m->item_descriptions[m->item_count] = 51 strdup(description ? description : name); 55 m->item_names[*i] = strdup(name); 56 m->item_descriptions[*i] = strdup(description ? description : name); 57 m->item_structs[*i] = 58 new_item(m->item_names[*i], m->item_descriptions[*i]); 52 59 53 ++ m->item_count;60 ++(*i); 54 61 55 62 return 1; … … 64 71 65 72 for(i = 0; i < m->item_count; i++) { 73 free_item(m->item_structs[i]); 74 free(m->item_descriptions[i]); 66 75 free(m->item_names[i]); 67 free(m->item_descriptions[i]);68 76 } 69 77 … … 79 87 80 88 if(!m) return 0; 89 if(m->menu_struct) return 0; 81 90 82 blah 91 m->menu_struct = new_menu(m->item_structs); 92 post_menu(m->menu_struct); 93 94 return 1; 83 95 } 84 96 85 menu2_drive(int, int); 97 int menu2_drive(menu2_h menu, int c) 98 { 99 struct menu2_t *m = _menus[menu - 1]; 100 101 if(!m) return 0; 102 if(!m->menu_struct) return 0; 103 104 menu_driver(m->menu_struct, c); 105 106 return 1; 107 } 108 109 int menu2_unpost(menu2_h menu) 110 { 111 struct menu2_t *m = _menus[menu - 1]; 112 113 if(!m) return 0; 114 if(!m->menu_struct) return 0; 115 116 unpost_menu(m->menu_struct); 117 free_menu(m->menu_struct); 118 m->menu_struct = NULL; 119 120 return 1; 121 }
Note: See TracChangeset
for help on using the changeset viewer.
