mbox(char *fmt,...) { va_list args; if(Mcb.fp) printf("ct %d p %d ", Mcb.iocount, fftell(Mcb.fp)); va_start(args,fmt); vprintf(fmt,args); va_end(args); printf("\n"); }
int lo_je_tag(FFILE f, char *p_tag) { long t = fftell(f); char string[10]; ffgets(string, 5, f); string[4] = 0; if (strcmp(string, p_tag) != 0) { ffseek(f, t, SEEK_SET); return ((int) NULL); } return (TRUE); }
int lo_nacti_vertexlist_out(FFILE f, OBJEKT_BOD ** p_vert) { GENERIC_HEAD head; long t = fftell(f); float v[3]; int i; if (*p_vert != NULL) { return ((int) NULL); } if (!ffread(&head, sizeof(head), 1, f)) { ffseek(f, t, SEEK_SET); return ((int) NULL); } if ((head.h[0] != 'V') || (head.h[1] != 'V') || (head.h[2] != 'V') || (head.h[3] != 'V')) { ffseek(f, t, SEEK_SET); return ((int) NULL); } if ((*p_vert = (OBJEKT_BOD *) mmalloc(sizeof(OBJEKT_BOD) * head.pocet)) == NULL) { chyba("Nedostatek pameti..."); } memset(*p_vert, 0, sizeof(OBJEKT_BOD) * head.pocet); for (i = 0; i < head.pocet; i++) { if (!ffread(&v, sizeof(v), 1, f)) { ffseek(f, t, SEEK_SET); null_free((void **) p_vert); return ((int) NULL); } (*p_vert)[i].x = v[0]; (*p_vert)[i].y = v[1]; (*p_vert)[i].z = v[2]; (*p_vert)[i].dr = (*p_vert)[i].dg = (*p_vert)[i].db = 1.0f; } return (head.pocet); }
int lo_nacti_word_matrix_out(FFILE f, GLMATRIX * p_mat) { GENERIC_HEAD head; int t = fftell(f); if (!ffread(&head, sizeof(head), 1, f)) { ffseek(f, t, SEEK_SET); return (FALSE); } if (head.h[0] != 'W' || head.h[1] != 'W' || head.h[2] != 'W' || head.h[3] != 'W') { ffseek(f, t, SEEK_SET); return (FALSE); } if (!ffread(p_mat, sizeof(GLMATRIX), 1, f)) { ffseek(f, t, SEEK_SET); return (FALSE); } return (TRUE); }
int lo_nacti_maplist_out(FFILE f, OBJEKT_BOD ** p_vert, int c_text) { GENERIC_HEAD head; long t = fftell(f); float *p_map; float m[2]; int i; if (*p_vert == NULL) return ((int) NULL); if (!ffread(&head, sizeof(head), 1, f)) { ffseek(f, t, SEEK_SET); return ((int) NULL); } if ((head.h[0] != 'M') || (head.h[1] != 'M') || (head.h[2] != 'M') || (head.h[3] != 'M')) { ffseek(f, t, SEEK_SET); return ((int) NULL); } if (c_text >= 2) { c_text = 1; } for (i = 0; i < head.pocet; i++) { if (!ffread(&m, sizeof(m), 1, f)) { ffseek(f, t, SEEK_SET); return ((int) NULL); } p_map = &(*p_vert)[i].tu1; p_map[0 + c_text * 2] = m[0]; p_map[1 + c_text * 2] = -m[1]; } return (head.pocet); }
int lo_nacti_barvy_out(FFILE f, OBJ_VERTEX * p_vert, word pocet) { GENERIC_HEAD head; dword barva; long t = fftell(f); int i; if (p_vert == NULL) return (FALSE); for (i = 0; i < pocet; i++) { p_vert[i].dr = p_vert[i].dg = p_vert[i].db = 1.0f; } if (!ffread(&head, sizeof(head), 1, f)) { ffseek(f, t, SEEK_SET); return (FALSE); } if ((head.h[0] != 'D') || (head.h[1] != 'D') || (head.h[2] != 'D') || (head.h[3] != 'D')) { ffseek(f, t, SEEK_SET); return (FALSE); } for (i = 0; i < head.pocet; i++) { if (!ffread(&barva, sizeof(dword), 1, f)) { ffseek(f, t, SEEK_SET); return (FALSE); } else { rgb_float(barva, &p_vert[i].dr); } } return (head.pocet); }
void close_macro(void) { BYTE olevel; static UBYTE eoflags[2] = {(MACRO_REC|MR_EOF),(MACRO_REC|MR_EOF)}; if(Mcb.fp != NULL) { if(icb.macro_mode == MAKE_MACRO) { Mcb.mh.id.size = fftell(Mcb.fp); ffwrite(Mcb.fp,&eoflags,sizeof(eoflags)); /* two bytes of eof */ ffwriteoset(Mcb.fp,&Mcb.mh,0,sizeof(Mcb.mh)); } ffclose(&Mcb.fp); } /* clear all but abort nesting level count */ olevel = Mcb.ab_level; clear_struct(&Mcb); Mcb.ab_level = olevel; icb.macro_clocked = 0; icb.macro_mode = 0; }
int lo_nacti_facelist_out(FFILE f, FACE ** p_face) { GENERIC_HEAD head; long t = fftell(f); if (*p_face != NULL) return ((int) NULL); if (!ffread(&head, sizeof(head), 1, f)) { ffseek(f, t, SEEK_SET); return ((int) NULL); } if ((head.h[0] != 'F') || (head.h[1] != 'F') || (head.h[2] != 'F') || (head.h[3] != 'F')) { ffseek(f, t, SEEK_SET); return ((int) NULL); } head.pocet *= 3; if (!head.pocet) chyba("load facelist -> 0 facu !"); if ((*p_face = (FACE *) mmalloc(sizeof(FACE) * head.pocet)) == NULL) { chyba("Nedostatek pameti..."); } if (!ffread(*p_face, sizeof(FACE), head.pocet, f)) { null_free((void **) p_face); ffseek(f, t, SEEK_SET); return ((int) NULL); } return (head.pocet); }
Errcode poll_abort() /* use whenever you wish to poll if user has requested an abort using a * key hit or right pen click */ { Errcode ret; ULONG time; static ULONG last_time; BYTE macro_mode; SHORT *pcount; Abortnest *an; macro_mode = icb.macro_mode; ret = Success; /* non abort most common case */ if(abort.nest > 0) { switch(macro_mode) { case MAKE_MACRO: { if(Mcb.ar.flags & AR_ABORTLEVEL) /* only one abort per atom */ goto done; icb.macro_mode &= ~MACRO_OK; /* dont record polling input */ ++abort.count; /* one more poll */ } case USE_MACRO: { if(poll_macro_abort() < Success) goto error; ++abort.count; if(!Mcb.ar.flags) /* havnt read abort rec yet */ { if(!IS_MRTYPE(Mcb.next.b[0],MR_POLLABORT)) goto done; /* not yet, go on */ if(read_abort_rec() < Success) goto error; goto done; } if(!(Mcb.ar.flags & AR_ABORTLEVEL)) goto done; if(Mcb.ab_level != Mcb.mab_level) /* not on aborted level */ goto done; /* if all counts match counts on all levels ABORT! */ pcount = Mcb.ar.counts; for(an = &abort;an != NULL;an = an->pop) { if(*pcount++ != an->count) /* no match */ goto done; } Mcb.ar.flags &= ~AR_ABORTLEVEL; /* took care of this */ _poll_input(0); /* get input that was recorded */ verify_abort(); /* macro WILL abort, we don't record cancels */ goto aborted; } default: break; } } time = (ULONG)pj_clock_1000(); if(macro_mode == USE_MACRO || (time-last_time) > POLL_INTERVAL) { last_time = time; icb.waithit = KEYHIT|MBRIGHT; if(0 == (icb.waithit = _poll_input(0))) /* will clear waithit */ goto done; icb.waithit = 0; if(macro_mode == MAKE_MACRO && abort.nest > 0) { LONG foffset; if((foffset = fftell(Mcb.fp)) < 0) { macro_read_error((Errcode)foffset); goto error; } /* flag to write record for abort at this level */ Mcb.ar.flags |= AR_ABORTLEVEL; if(write_abort_rec() < Success) goto error; if(put_macro(TRUE) < Success) /* write input that caused abort */ goto error; if(verify_abort()) goto aborted; /* Abort canceled! disregard aborting an cancelling input * unflag abort done */ Mcb.ar.flags &= ~AR_ABORTLEVEL; if((foffset = ffseek(Mcb.fp,foffset,SEEK_SET)) < 0) { macro_read_error(foffset); goto aborted; } } else if(verify_abort()) goto aborted; } else if(icb.macro_mode == MAKE_MACRO) { /* always increment macro count if making a macro. * NOTE: that above we always check the input when using * a macro and macro will always be ~MACRO_OK when polling in * an abort atom NOTE: put_macro with FALSE will never return * error */ put_macro(FALSE); } goto done; error: if(!verify_abort()) /* error will be reported already */ goto done; aborted: ret = Err_abort; done: icb.macro_mode |= MACRO_OK; return(ret); }