static Errcode play_macro(int repeats) { Errcode err; close_macro(); if((err = ffopen(macro_name,&Mcb.fp,rb_str)) < Success) goto error; if((err = ffread(Mcb.fp,&Mcb.mh,sizeof(Mcb.mh))) < Success) goto error; if(Mcb.mh.id.type != MAC_MAGIC || Mcb.mh.id.size < sizeof(Machead)) { err = Err_bad_magic; goto error; } /* pre-fetch next record header flags */ if((err = ffread(Mcb.fp,&Mcb.next,sizeof(Twobytes))) < Success) goto error; Mcb.sizeleft = Mcb.mh.id.size - (sizeof(Machead)+sizeof(USHORT)); Mcb.lastmouse = *((Short_xy *)&icb.sx); icb.macro_mode = USE_MACRO; icb.macro_clocked = Mcb.mh.realtime; Mcb.repeats = repeats; return(Success); error: close_macro(); return(err); }
// ***************************************************************************************************************** void beispiele(void){ char datei[12]="TEST TXT"; // hier muss platz für 11 zeichen sein (8.3), da fat_str diesen string benutzt !! fat_str(datei); // wandelt "test.txt" in das fat format 8.3 der form: "TEST TXT" muss immer dieses Format haben, auch ordner !! // 0.) ______________löschen von dateien/ordnern (ordner rekursiv)____________________________________________ ffrm( datei ); // löschen der datei/ordner falls vorhanden // 1.) ______________anlegen und schreiben____________________________________________________________________ // öffnet datei, wenn nicht vorhanden, legt ffopen datei an (rückgabewert = 1 datei existiert, also nur öffnen, 2 = angelegt). ffopen( datei ); // schreibt string ffwrites((char*)"Hallo Datei :)"); // neue zeile in der datei ffwrite(0x0D); ffwrite(0x0A); // schließt datei ffclose(); // 2.)________________ändern von vorhandenen daten in dateien__________________________________________________ ffopen( datei ); // siehe oben... ffseek(12); // spult in datei auf position 12 vor (fängt immer bei 0 an zu zählen !) ffwrite(';'); // schreibt dann ab position 12 (überschreibt daten der datei, hier nur 1 zeichen) ffclose(); // schließt datei // 3.)________________lesen von dateien_________________________________________________________________________ ffopen( datei ); // siehe oben... unsigned long int seek=file.length; // eine variable setzen und runterzählen bis 0 geht am schnellsten ! do{ uputc(ffread()); // liest ein zeichen und gibt es über uart aus ! }while(--seek); // liest solange bytes da sind (von datei länge bis 0) ffclose(); // schließt datei uputc('\n'); // neue zeile weil neue unteraufgabe // 4.)________________anhängen von daten an datei_______________________________________________________________ ffopen( datei); // siehe oben... ffseek(file.length); // spult in datei ans ende ffwrites((char*)"Dies ist ein Test..."); // siehe oben // neue zeile in der datei ffwrite(0x0D); ffwrite(0x0A); ffclose(); // schließt datei // 3.)________________lesen von dateien_________________________________________________________________________ ffopen( datei ); // siehe oben... seek=file.length; // eine variable setzen und runterzählen bis 0 geht am schnellsten ! do{ uputc(ffread()); // liest ein zeichen und gibt es über uart aus ! }while(--seek); // liest solange bytes da sind (von datei länge bis 0) ffclose(); // schließt datei }
void nahraj_texturu_fc(FFILE f, EDIT_MATERIAL * p_mat, EDIT_TEXT * p_text, int max, int cislo_text, int save) { OLD_MULTITEXT_FLAG mt; char string[100]; int t; if (lo_je_tag(f, TEXT_TAG)) { str_read(string, f); strlwr(string); if (!strcmp(string, S_NIC)) { p_mat->p_text[cislo_text] = NULL; p_mat->textfile[cislo_text][0] = 0; } else { if (save) { if ((t = lo_najdi_texturu(p_text, max, string, FALSE)) == K_CHYBA) { if ((t = lo_najdi_volnou_texturu(p_text, max)) == K_CHYBA) chyba("Textury"); strcpy(p_text[t].jmeno, string); } p_mat->p_text[cislo_text] = p_text + t; strcpy(p_mat->textfile[cislo_text], string); } } } if (lo_je_tag(f, MULTI_TAG)) ffread(&mt, sizeof(mt), 1, f); }
static Errcode read_abort_rec() { Errcode err; int readsize; Mcb.ar.flags = Mcb.next.b[0]; if(0 != (readsize = Mcb.ar.flags & AR_ABORTLEVEL)) { ((UBYTE *)(&Mcb.ar))[1] = Mcb.next.b[1]; /* readsize = num levels counts - one byte + sizeof next */ Mcb.mab_level = (readsize /= ABORTLEVEL_1) - 1; readsize = (readsize * sizeof(USHORT)) - 1 + sizeof(USHORT); if((err = ffread(Mcb.fp,OPTR(Mcb.ar.counts,1),readsize)) < Success) return(macro_write_error(err)); Mcb.sizeleft -= readsize; Mcb.next.flags = *((USHORT *)(OPTR(&Mcb.ar,readsize))); } else /* one byte non abort poll end record move last byte * to first and fetch next byte in file */ { Mcb.next.b[0] = Mcb.next.b[1]; Mcb.next.b[1] = ffgetc(Mcb.fp); --Mcb.sizeleft; } return(Success); }
int main(int argc,char**argv) { int cm,x,y,fx,fy,j,k,l,m,n,psfType=0; FILE *fpsf; char str[161]; float **psf; if (argc<7) usage(*argv); for (j=7;j<argc;j++) { if (!strcasecmp(argv[j],"-anderson")) psfType=1; else usage(*argv); } cm=atoi(argv[2]); if (cm<0 || cm>2) { printf("Chip must be 0-2\n"); return -1; } x=atoi(argv[3]); if (x<0 || x>=wfc3_nxpsfpos[cm]) { printf("X position must be 0-%d\n",wfc3_nxpsfpos[cm]-1); return -1; } y=atoi(argv[4]); if (y<0 || y>=wfc3_nypsfpos[cm]) { printf("Y position must be 0-%d\n",wfc3_nypsfpos[cm]-1); return -1; } fx=atoi(argv[5]); fy=atoi(argv[6]); if (fx<-wfc3_n2psf[cm] || fx>wfc3_n2psf[cm] || fy<-wfc3_n2psf[cm] || fy>wfc3_n2psf[cm]) { printf("dX and dY must be -%d to %d\n",wfc3_n2psf[cm],wfc3_n2psf[cm]); return -1; } if (psfType==0) sprintf(str,"%s/wfc3/data/%s.%s.psf",BASEDIR,argv[1],wfc3_cn[cm]); else sprintf(str,"%s/wfc3/data/%s_anderson.%s.psf",BASEDIR,argv[1],wfc3_cn[cm]); if ((fpsf=fopen(str,"rb"))==NULL) { printf("Cannot open %s\n",str); return -1; } psf=(float**)calloc(sizeof(float*),wfc3_rpsf[cm]*2+1); if (!psf) merr(); psf+=wfc3_rpsf[cm]; for (j=-wfc3_rpsf[cm];j<=wfc3_rpsf[cm];j++) { psf[j]=(float*)calloc(sizeof(float),wfc3_rpsf[cm]*2+1); if (!psf[j]) merr(); psf[j]+=wfc3_rpsf[cm]; } for (j=0;j<y;j++) for (k=0;k<wfc3_nxpsfpos[cm];k++) for (l=-wfc3_n2psf[cm];l<=wfc3_n2psf[cm];l++) for (m=-wfc3_n2psf[cm];m<=wfc3_n2psf[cm];m++) for (n=-wfc3_rpsf[cm];n<=wfc3_rpsf[cm];n++) fread(psf[n]-wfc3_rpsf[cm],4,2*wfc3_rpsf[cm]+1,fpsf); for (k=0;k<x;k++) for (l=-wfc3_n2psf[cm];l<=wfc3_n2psf[cm];l++) for (m=-wfc3_n2psf[cm];m<=wfc3_n2psf[cm];m++) for (n=-wfc3_rpsf[cm];n<=wfc3_rpsf[cm];n++) fread(psf[n]-wfc3_rpsf[cm],4,2*wfc3_rpsf[cm]+1,fpsf); for (l=-wfc3_n2psf[cm];l<fy;l++) for (m=-wfc3_n2psf[cm];m<=wfc3_n2psf[cm];m++) for (n=-wfc3_rpsf[cm];n<=wfc3_rpsf[cm];n++) fread(psf[n]-wfc3_rpsf[cm],4,2*wfc3_rpsf[cm]+1,fpsf); for (m=-wfc3_n2psf[cm];m<fx;m++) for (n=-wfc3_rpsf[cm];n<=wfc3_rpsf[cm];n++) fread(psf[n]-wfc3_rpsf[cm],4,2*wfc3_rpsf[cm]+1,fpsf); for (n=-wfc3_rpsf[cm];n<=wfc3_rpsf[cm];n++) ffread(psf[n]-wfc3_rpsf[cm],4,2*wfc3_rpsf[cm]+1,fpsf); k=wfc3_rpsf[cm]; if (k>6) k=6; for (n=k;n>=-k;n--) { for (j=-k;j<=k;j++) printf("%5d ",(int)(psf[n][j]*100000+0.5)); printf("\n"); } fclose(fpsf); return 0; }
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_nahraj_konfiguraci_kontejneru_out(FFILE f, EDIT_KONTEJNER * p_kont) { KONTEJNER_KONFIG kkonf; KONTEJNER_KONFIG_OLD kkonf_old; if (lo_je_tag(f, KONFIG_TAG)) { // nacti nove info ffread(&kkonf, sizeof(kkonf), 1, f); p_kont->m1flag = kkonf.flag & 0xffff; p_kont->kflag = kkonf.flag & 0xffff0000; return (TRUE); } else if (lo_je_tag(f, KONFIG_TAG_OLD)) { // nacti stare info ffread(&kkonf_old, sizeof(kkonf_old), 1, f); p_kont->m1flag |= kkonf_old.flag ? MAT_PRUHLEDNY : 0; return (TRUE); } else return (FALSE); }
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); }
/** \brief read WAV-File. see https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ for details on the wav-file format \param f a FILE pointer \return the wavfile (freshly allocated) or NULL (failure) */ WavFile* wavfile_read( FILE *f ){ uint32_t buf; WavFile *w; int stopflag=0; if( ffread( &buf, 1, 4, f ) && buf!=0x46464952 ){ /* "RIFF" */ stopflag=1; } ffread( &buf, 1, 4, f ); /* trash */ if( ffread( &buf, 1, 4, f ) && buf!=0x45564157 ){ /* 'WAVE' */ stopflag=1; } if( ffread( &buf, 1, 4, f ) && buf!=0x20746d66 ){ /* 'fmt ' */ stopflag=1; } if( stopflag ){ fprintf( stderr, "No WAV-File\n" ); return NULL; } if( ffread( &buf, 1, 4, f ) && buf!=16 ){ /* no compression */ fprintf( stderr, "Cannot handle compression...\n" ); return NULL; } w = (WavFile*) malloc( sizeof(WavFile) ); ffread( w, 1, 16, f ); if( ffread( &buf, 1, 4, f ) && buf!=0x61746164 ){ /* 'data' */ fprintf( stderr, "No data\n" ); return NULL; } if( !ffread( &(w->data_size), 1, 4, f ) ) return NULL; w->data = (void*) malloc( w->data_size ); ffread( w->data, 1, w->data_size, f ); return w; }
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); }
size_t stdiof_ffread (void *buf, size_t recsz, size_t numrec, FILE *stream) { int fd; size_t reqdbytes; size_t repval; size_t recdone; fd = (long)stream; /* redfine it to be what it actually is */ reqdbytes = recsz * numrec; repval = ffread(fd, buf, reqdbytes); recdone = repval / recsz; return ( recdone ); }
/** Compare an array of doubles to doubles stored binary file. * The data must be stored in 32 bit floats * * \param precision to which position after comma it is compared * \return * - 0 if everything is equal * - 1 if there is an element that is not equal * \todo check it, does not seem to work properly */ int isequal_doublearray_binfile(double *d, int n, const char *filename, int precision){ FILE *f; double *d2; int i, flag=1; d2 = (double*)malloc(n*sizeof(double)); if((f=fopen(filename, "rb"))==NULL){ errprintf("opening file '%s' failed\n", filename); return -1; } ffread(d2, sizeof(double), n, f); fclose(f); flag = isequal_doublearray( d, d2, n, precision ); free(d2); return flag; }
static int ffio_pgin(ncio *const nciop, off_t const offset, const size_t extent, void *const vp, size_t *nreadp, off_t *posp) { int status; ssize_t nread; #ifdef X_ALIGN assert(offset % X_ALIGN == 0); assert(extent % X_ALIGN == 0); #endif if(*posp != offset) { if(ffseek(nciop->fd, offset, SEEK_SET) != offset) { status = errno; return status; } *posp = offset; } errno = 0; nread = ffread(nciop->fd, vp, extent); if(nread != extent) { status = errno; if(nread == -1 || status != ENOERR) return status; /* else it's okay we read 0. */ } *nreadp = nread; *posp += nread; return ENOERR; }
Errcode get_macro_input(void) /* read and process macro into input stream */ { int readsize; Errcode err; USHORT oflags; if((err = poll_macro_abort()) < Success) goto error; if(Mcb.macbuf == NULL) /* no input record in buffer read one in */ { if(Mcb.sizeleft <= 0) /* end of macro file stream */ { if(--Mcb.repeats > 0) { if((err = play_macro(Mcb.repeats)) < Success) goto error; } else { err = Err_abort; goto error; } } if(Mcb.next.b[0] & MACRO_REC) /* not an input record */ goto reuse_last; /* retrieve record head and calculate record size to read */ Mcb.ioflags = Mcb.next.flags; readsize = sizeof(USHORT); /* short for prefetch of next record head */ if(Mcb.ioflags & HAS_CCOUNT) /* get previous io state and count */ { if((err = ffread(Mcb.fp,&oflags,sizeof(USHORT))) < Success) goto error; Mcb.sizeleft -= sizeof(USHORT); if(oflags & CCOUNT_SHORT) readsize += sizeof(USHORT); else if(oflags & CCOUNT_LONG) readsize += sizeof(ULONG); else readsize += sizeof(UBYTE); if(oflags & HAS_MOUSEX) readsize += sizeof(SHORT); if(oflags & HAS_MOUSEY) readsize += sizeof(SHORT); if(oflags & HAS_HISTATE) readsize += sizeof(USHORT); } if(Mcb.ioflags & KEYHIT) readsize += sizeof(USHORT); if(Mcb.ioflags & HAS_PRESSURE) readsize += sizeof(UBYTE); if(Mcb.ioflags & HAS_MOUSEX) readsize += sizeof(SHORT); if(Mcb.ioflags & HAS_MOUSEY) readsize += sizeof(SHORT); if(Mcb.ioflags & HAS_HISTATE) readsize += sizeof(USHORT); if((Mcb.sizeleft -= readsize) < 0) readsize -= sizeof(USHORT); /* end of file, NO next record */ if( readsize != 0 && (err = ffread(Mcb.fp,Mcb.mbuf,readsize)) < Success) { goto error; } /* get last short in buffer, this is head of next rec or garbage if * end of file (previous short before buffer) */ Mcb.next.flags = *(USHORT *)&(Mcb.mbuf[readsize-sizeof(USHORT)]); Mcb.macbuf = Mcb.mbuf; /* flag record present, at start of buffer */ if(Mcb.ioflags & HAS_CCOUNT) { /* add count to possibly decremented value and get count of * polls left to do before using this record */ if(oflags & CCOUNT_SHORT) { Mcb.iocount += VGETVAL(Mcb.macbuf,USHORT); } else if(oflags & CCOUNT_LONG) { Mcb.iocount += VGETVAL(Mcb.macbuf,ULONG); } else { Mcb.iocount += VGETVAL(Mcb.macbuf,UBYTE); } if((LONG)Mcb.iocount < 0) /* oops, file corrupt or program outta sync */ { err = Err_macrosync; goto error; } /* item with poll count has to provide previous input state * to re-create recorded conditions in _poll_input() */ icb.state = oflags & MACSTATE; if(oflags & HAS_MOUSEX) { icb.sx = VGETVAL(Mcb.macbuf,SHORT); } if(oflags & HAS_MOUSEY) { icb.sy = VGETVAL(Mcb.macbuf,SHORT); } if(oflags & HAS_HISTATE) { HISTATE_WORD(icb.state) |= VGETVAL(Mcb.macbuf,USHORT); } if(Mcb.iocount == 0) /* if count is zero we must put this * iostate into the previous state * otherwise next poll will do this * in poll input */ { SET_BUPBITS(icb.state); icb.ostate = icb.state & ALL_BSTATES; get_menucursorxy(); /* recalc previous values as current */ ICB_COPYTO_LAST(); /* put them in last buffer */ } } } if(Mcb.iocount > 0) /* we have record, but keep polling */ goto reuse_last; /* count satisfied, let user have recorded input */ icb.state = Mcb.ioflags & MACSTATE; if(icb.state & KEYHIT) { icb.inkey = VGETVAL(Mcb.macbuf,USHORT); } else icb.inkey = 0; if(Mcb.ioflags & HAS_PRESSURE) { icb.pressure = VGETVAL(Mcb.macbuf,UBYTE); } else icb.pressure = PRESSURE_MAX; if(Mcb.ioflags & HAS_MOUSEX) { Mcb.lastmouse.x = VGETVAL(Mcb.macbuf,SHORT); } if(Mcb.ioflags & HAS_MOUSEY) { Mcb.lastmouse.y = VGETVAL(Mcb.macbuf,SHORT); } *((Short_xy *)&icb.sx) = Mcb.lastmouse; if(Mcb.ioflags & HAS_HISTATE) { Mcb.last_histate = VGETVAL(Mcb.macbuf,USHORT); } HISTATE_WORD(icb.state) |= Mcb.last_histate; Mcb.macbuf = NULL; /* flag macro consumed no longer present */ return(Success); reuse_last: --Mcb.iocount; /* decrement input poll counter */ icb.state &= ALL_BSTATES; /* clear changed _poll_input() unique flags */ return(Success); error: return(macro_read_error(err)); }
EDIT_MATERIAL *lo_nahraj_material_out(FFILE f, EDIT_TEXT * p_text, int max, int save) { EDIT_MATERIAL *p_mat; MATERIAL *p_dxmat; OLD_MULTITEXT_FLAG mt; char string[50]; dword tmp; if (!lo_je_tag(f, MTRL_TAG)) return (NULL); else { p_mat = vyrob_material(); str_read(p_mat->jmeno, f); } ffread(string, sizeof(char), 9, f); // nacteni grb if (save) { p_dxmat = &p_mat->dxmat; p_dxmat->ambient_r = (float) string[0] / MAX_BYTE; p_dxmat->ambient_g = (float) string[1] / MAX_BYTE; p_dxmat->ambient_b = (float) string[2] / MAX_BYTE; p_dxmat->diffuse_r = (string[3]) ? ((float) string[3]) / MAX_BYTE : 1.0f; p_dxmat->diffuse_g = (string[4]) ? ((float) string[4]) / MAX_BYTE : 1.0f; p_dxmat->diffuse_b = (string[5]) ? ((float) string[4]) / MAX_BYTE : 1.0f; p_dxmat->diffuse_a = 1.0f; p_dxmat->specular_r = (float) string[6] / MAX_BYTE; p_dxmat->specular_g = (float) string[7] / MAX_BYTE; p_dxmat->specular_b = (float) string[8] / MAX_BYTE; p_dxmat->faktor_r = 1.0f; p_dxmat->faktor_g = 1.0f; p_dxmat->faktor_b = 1.0f; p_dxmat->faktor_a = 1.0f; } // nacte soubor s animacema if (lo_je_tag(f, MATANIM_TAG)) { str_read(p_mat->anim.jmeno, f); //lo_vyrob_animaci_list(p_mat,p_mat->anim.jmeno,p_text,max,ANIM_LOAD_ALL); } // nacte alfa tag if (lo_je_tag(f, FAKTOR_TAG)) { ffread(&tmp, sizeof(dword), 1, f); } // Nacte stage blok if (lo_je_tag(f, STAG_TAG)) { ffread(string, sizeof(char), 1, f); ffread(&tmp, sizeof(dword), 1, f); ffread(&tmp, sizeof(dword), 1, f); p_mat->alfa_state = 0; p_mat->text_state[0].text_stage = 0; p_mat->text_state[1].text_stage = 0; } // nacteni nuloveho blendu if (lo_je_tag(f, MULTI_TAG)) ffread(&mt, sizeof(mt), 1, f); nahraj_texturu_fc(f, p_mat, p_text, max, 0, save); nahraj_texturu_fc(f, p_mat, p_text, max, 1, save); nahraj_texturu_fc(f, p_mat, p_text, max, 1, save); strlwr(p_mat->jmeno); if (save) return (p_mat); else { zrus_material(&p_mat); return ((EDIT_MATERIAL *) 1); } }
int lo_nahraj_objekty_out(EDIT_MATERIAL ** p_mat, int max_mat, FFILE f, EDIT_KONTEJNER * p_kont, int mat) { char string[50]; int i, j, k; word r1; for (i = 0; i < p_kont->max_objektu; i++) { if (!lo_je_tag(f, "JMOB")) break; else str_read(string, f); if (!lo_je_tag(f, "TMSH")) continue; //je to objekt ale neni to mes if ((p_kont->p_obj[i] = lo_nacti_vec_FILE_out(f)) == NULL) chyba("Nacitani objektu..."); strcpy(p_kont->p_obj[i]->jmeno, string); for (k = 0; k < 2; k++) { //nactenej jeden objekt - pricist jeste material if (!lo_je_tag(f, "FMAT")) { break; // neni material - na dalsi objekt } else str_read(string, f); if (mat) { if (!k) { if (!strcasecmp(string, S_NIC)) { p_kont->p_obj[i]->material = 0; p_kont->p_obj[i]->m1flag = 0; p_kont->p_obj[i]->m2flag = 0; p_kont->p_obj[i]->oflag = 0; } else { for (j = 0; j < max_mat; j++) { if (p_mat[j] && !strcasecmp(string, p_mat[j]->jmeno)) { p_kont->p_obj[i]->material = (word) j; p_kont->p_obj[i]->m1flag = p_mat[j]->flag; p_kont->p_obj[i]->m2flag = p_mat[j]->flag2; break; } } if (j == max_mat) { ddw("Neznamy material '%s' v objektu '%s'", string, p_kont->p_obj[i]->jmeno); p_kont->p_obj[i]->material = 0; p_kont->p_obj[i]->m1flag = 0; p_kont->p_obj[i]->m2flag = 0; } } } } else { p_kont->p_obj[i]->material = 0; p_kont->p_obj[i]->m1flag = 0; p_kont->p_obj[i]->m2flag = 0; } } if (lo_je_tag(f, "RECT")) { // sou tam recy ffread(&r1, sizeof(word), 1, f); ffread(&r1, sizeof(word), 1, f); } } return (i); }