void postorder(struct node *p, void (* item_print)(any item)) { if (p!=NULL) { postorder(p->left,item_print); postorder(p->right,item_print); item_print(p->item); } }
/* Prints the contents of LIST on stdout, for debugging purposes. */ static void list_print (const struct list *list) { int i; for (i = 0; i < list->n; i++) { if (i != 0) printf (", "); item_print (&list->contents[i]); } }
int main(void) { Item x = 5, y = 2, x2 = 6, y2 = 3; mat m1, m2, k1, k2; int i, j; printf("\nItems: "); item_print(x); printf(" "); item_print(y); printf("\n"); printf("Item Addition: "); item_print(item_add(x, y)); printf("\n"); printf("Item Multiplication: "); item_print(item_mul(x, y)); printf("\n"); printf("Item Substraction: "); item_print(item_sub(x, y)); printf("\n"); printf("Item Division: "); item_print(item_div(x, y)); printf("\n\n"); m1 = mat_create(3, 2); m2 = mat_create(2, 3); k1 = mat_create(2, 2); k2 = mat_create(2, 2); for (i = 0; i < mat_rows(m1); i++) for (j = 0; j < mat_cols(m1); j++) mat_add_elem(m1, i, j, x); for (i = 0; i < mat_rows(m2); i++) for (j = 0; j < mat_cols(m2); j++) mat_add_elem(m2, i, j, y); for (i = 0; i < mat_rows(k1); i++) for (j = 0; j < mat_cols(k1); j++) { mat_add_elem(k1, i, j, x2); mat_add_elem(k2, i, j, y2); } printf("k1 Matrix: \n"); mat_print(k1); printf("k2 Matrix: \n"); mat_print(k2); printf("Addition: \n"); mat_print(mat_add(k1, k2)); printf("Substraction: \n"); mat_print(mat_sub(k1, k2)); printf("m1 Matrix: \n"); mat_print(m1); printf("m2 Matrix: \n"); mat_print(m2); printf("Multiplication: \n"); mat_print(mat_mul(m1, m2)); return 0; }
void simple_print(struct node *p, int ind, void (* item_print)(any item)) { int i; if (p!=NULL) { simple_print(p->right,ind+4,item_print); for(i=0;i<ind;i++) putchar(' '); item_print(p->item); printf(" (h=%i).... %p", ((int)(p->height)), p); putchar('\n'); simple_print(p->left,ind+4,item_print); } else { for(i=0;i<ind;i++) putchar(' '); printf("%p\n", p); } }
void wd_hndlmenu(int item, int keystate) { WINDOW *w; int object; char path[4]; /* DjV 020 120103 drive path only */ int ii,jj; /* DjV 020 120103 do nothing */ int n, *list; /* DjV 029 160203 moved here from several places below */ switch (item) { case MOPEN: w = selection.w; object = selection.selected; if ((w != NULL) || (object >= 0)) { if (itm_open(w, object, keystate) == TRUE) itm_select(w, object, 2, TRUE); itm_set_menu(selection.w); } /* DjV 028 280103 ---vvv--- */ /* If nothing else is selected, open form to enter item specification */ else item_open( NULL, 0, 0 ); /* DjV 028 280103 ---^^^--- */ break; case MSHOWINF: if ((w = selection.w) != NULL) { if ((itm_list(w, &n, &list) == TRUE) && (n > 0)) { ((ITM_WINDOW *) w)->itm_func->itm_showinfo(w, n, list, FALSE); /* DjV 017 150103 (FALSE) */ free(list); } } /* DjV 020 120103 * Show info on drive for top window if nothing else selected; * TOS >=2.06 does it this way; info on current folder would * have been better but somewhat more complicated; even more so * info on file open in a text window? */ else if ( ( w=xw_top() ) != NULL && xw_type(w) == DIR_WIND ) { strsncpy (path, wd_toppath(), sizeof(path)); /* HR 120203: secure cpy */ si_drive( path, &ii, &jj ); closeinfo(); /* DjV 022 120103 */ } break; case MSEARCH: /* DjV 016 050103 */ if ((w = selection.w) != NULL) { if ((itm_list(w, &n, &list) == TRUE) && (n > 0)) { ((ITM_WINDOW *) w)->itm_func->itm_showinfo(w, n, list, TRUE); free(list); } } break; case MNEWDIR: if (((w = xw_top()) != NULL) && (xw_type(w) == DIR_WIND)) ((ITM_WINDOW *) w)->itm_func->wd_newfolder(w); break; /* DjV 029 030103 150203 160203 ---vvv--- */ case MPRINT: if ((w = selection.w) != NULL) { if ((itm_list(w, &n, &list) == TRUE) && (n > 0)) { boolean item_print(WINDOW *w, int n, int *list); item_print(w, n, list); free(list); } } else if ( ( w=xw_top() ) != NULL ) { if ( xw_type(w) == DIR_WIND ) { itm_select(w, 0, 4, TRUE); if ( itm_list(w, &n, &list) ) { dir_print(w, n, list); free(list); } wd_deselect_all(); dir_always_update(w); } else if ( xw_type(w) == TEXT_WIND ) { /* Perhaps here print the file currently in a text window ? */ } } break; /* DJV 029 030103 150203 160203 ---^^^--- */ case MDELETE: /* HR 151102 */ if ((w = selection.w) != NULL) { if ((itm_list(w, &n, &list) == TRUE) && (n > 0)) { itm_delete(w, n, list); free(list); } } break; case MCLOSE: case MCLOSEW: if ((w = xw_top()) != NULL) { switch(xw_type(w)) { case DIR_WIND : dir_close(w, (item == MCLOSEW) ? 1 : 0); break; case TEXT_WIND : txt_closed(w); break; } } break; case MSELALL: if (((w = xw_top()) != NULL) && (xw_type(w) == DIR_WIND)) { if (selection.w != w) desel_old(); itm_select(w, 0, 4, TRUE); itm_set_menu(w); } break; case MCYCLE: xw_cycle(); break; #if MFFORMAT /* HR 050303 */ case MFCOPY: /* DjV 006 291202 */ formatfloppy(floppy, FALSE); break; case MFFORMAT: /* DjV 006 291202 */ formatfloppy(floppy,TRUE); break; #endif case MSETMASK: if (((w = xw_top()) != NULL) && (xw_type(w) == DIR_WIND)) wd_set_filemask(w); else /* DjV 004 290103 */ wd_filemask(NULL); /* DjV 004 290103 */ break; case MSHOWTXT: case MSHOWICN: wd_mode(item - MSHOWTXT); break; case MSNAME: case MSEXT: case MSDATE: case MSSIZE: case MSUNSORT: wd_sort(item - MSNAME); break; /* DjV 010 261202 ---vvv--- */ case MSHSIZ: options.V2_2.fields ^= WD_SHSIZ; wd_fields(); break; case MSHDAT: options.V2_2.fields ^= WD_SHDAT; wd_fields(); break; case MSHTIM: options.V2_2.fields ^= WD_SHTIM; wd_fields(); break; case MSHATT: options.V2_2.fields ^= WD_SHATT; wd_fields(); break; /* DjV 010 261202 ---^^^--- */ /* DjV 004 020103 ---vvv--- case MHIDDEN: options.attribs ^= FA_HIDDEN; wd_attrib(); break; case MSYSTEM: options.attribs ^= FA_SYSTEM; wd_attrib(); break; DjV 004 020103 ---^^^--- */ } }