int write_file(void) { static unsigned pos,size; ozcls(); ozputs0(0,"Writing..."); if(open1(filename,O_WRONLY)<0) { ozcls(); ozputs0(0,"Error opening file!"); ozgetch(); return -1; } pos=0; clear_wrap_to_end(0); while(pos<file_length) { if(pos+LINE_BUF_LEN<=file_length) size=LINE_BUF_LEN; else size=file_length-pos; ozreadauxmem(pos,line_buf,size); if(write1(line_buf,size)<size) { ozcls(); ozputs0(0,"Error writing!"); close1(); return -1; } pos+=size; } close1(); }
int loadhighscores(int level) { if(level==4) { open1("ozcp20/highscore0",O_RDONLY); read1(randspeed,14); close1(); open1("ozcp20/highscore1",O_RDONLY); read1(dreispeed,14); close1(); open1("ozcp20/highscore2",O_RDONLY); read1(zweispeed,14); close1(); open1("ozcp20/highscore3",O_RDONLY); read1(einspeed,14); close1(); return 0; } if(level==0) { open1("ozcp20/highscore0",O_RDONLY); read1(randspeed,14); close1(); sscanf(randspeed,"%3c %ld",&initials,&score0); return 0; } if(level==1) { open1("ozcp20/highscore1",O_RDONLY); read1(dreispeed,14); close1(); sscanf(dreispeed,"%3c %ld",&initials,&score0); return 0; } if(level==2) { open1("ozcp20/highscore2",O_RDONLY); read1(zweispeed,14); close1(); sscanf(zweispeed,"%3c %ld",&initials,&score0); return 0; } if(level==3) { open1("ozcp20/highscore3",O_RDONLY); read1(einspeed,14); close1(); sscanf(einspeed,"%3c %ld",&initials,&score0); return 0; } return -1; }
int savehighscores(char *name) { if(open1(name,O_WRONLY)==-1) { ozputs(0,0,"Error opening file. Press any key."); ozngetch(); close1(); return -1; } sprintf(savechar,"%s %ld",initials,score); if(write1(savechar,14)==-1) { ozputs(0,0,"Error writing file. Press any key."); ozngetch(); close1(); return -1; } close1(); return 0; }
void savebookmarks(void) { if(!bookmarksmod || strncmp(directory,filename,3)) return; close1(); /* just in case */ _ozfilledbox(0,0,WIDTH,line_height,0); ozputs(0,0,"Saving bookmarks..."); filename[0]='b'; filename[1]='m'; if(open1(filename,O_WRONLY)<0) return; write1("BookMrkA",8); last=screen_offset+buffer_offset; write1(&last,4); write1(&numbookmarks,1); write1(bookmarks,sizeof bookmarks); write1(&line_height,1); write1(&show_bar,1); write1(&positionptr,1); write1(&numpositions,1); write1(positions,sizeof positions); close1(); }
loadconfig() { ozputs(0,70,"Loading configuration..."); if(open1("ozcp20/config",O_RDONLY)==-1) { makenewconfigfile(); if(makenewconfigfile()==-1) return; } read1(config,5); close1(); loadconfigswitch(); load=0; }
void read_file(void) { static int r; static byte i; static byte b; ozcls(); ozputs0(0,"Reading..."); file_length=0; if(open1(filename,O_RDONLY)<0) { ozputs0(20,"Cannot open! Create new? [Y/n]"); if(ozgetch()=='n') exit(0); return; } do { r=read1(line_buf,LINE_BUF_LEN); if(file_length+r>MAX_FILE_LENGTH) { ozcls(); ozputs0(0,"File too long!"); ozputs0(10,"Truncate? [y/N]"); if(ozgetch()!='y') exit(0); r=MAX_FILE_LENGTH-file_length; } for(i=0;i<r;i++) { b=line_buf[i]; b&=0x7f; if(b<32) b='*'; line_buf[i]=b; } if(r>0) { ozwriteauxmem(file_length,line_buf,r); file_length+=r; } } while(r==LINE_BUF_LEN && file_length<MAX_FILE_LENGTH); /* note: LINE_BUF_LEN does not divide MAX_FILE_LENGTH, and this is important for truncate message to work */ close1(); }
int makenewconfigfile() { if(open1("ozcp20/config",O_WRONLY)==-1) { ozcls(); ozputs(0,70,"Error opening file. Press any key."); ozngetch(); return -1; } configswitch(); sprintf(config,"%d %d %d",mov,spd,sound); if(write1(config,6)==-1) { ozcls(); ozputs(0,70,"Error writing file. Press any key."); ozngetch(); return -1; } close1(); return 0; }
void frommemo(void) #endif { static unsigned loc,page,offset,recnum; register char *p; static char filename[32]; static char parthead[21]; static char continued; static unsigned int sum; static byte val; static byte version2; static int i; static unsigned j; static int c; static int partnumber; static char checksum[6]; page=0; offset=0; while(loc=ozfindnext(TYPE_MEMO,&page,&offset,&recnum)) { partnumber=0; p=ozloadcluster(loc); if(p[24]!='~' || p[25]!='~' || p[26]!='z' || strncmp(p+2+13+9+15,"00000",5) || strncmp(p+2+13+9+21,"**LIBOZ_UPLOAD*",15)) continue; do { strcpy(parthead,p+24); if(ozopenfile(loc)==-1) { ozwarn("Error opening memo!",anykey); return; } for(i=0;i<13+9+21+15;i++) ozreadfilebyte(); continued=ozreadfilebyte(); p=filename; while('\r'!=(c=ozreadfilebyte()) && '\n'!=c && p-filename<MAX_FILENAMELEN) { if(partnumber) { if(c!=*p) { ozputs(0,70,"You may have the remains of " "another download."); ozclosefile(); close1(); unlink(filename); ozgetch(); return; } } else *p=c; p++; } if(p-filename>MAX_FILENAMELEN) { ozwarn("Filename too long!",anykey); return; } *p=0; ozputs(0,10,filename); ozputs(0,20,parthead); if(!partnumber) { ozsetowner(atoi(parthead+3)); if(open1(filename,O_WRONLY)==-1) { ozwarn("Error opening file!",anykey); return; } } sum=0; p=filebuf; if(!partnumber) { c=ozreadfilebyte(); if(c==TOMEMO2_MARKER) { version2=1; for(j=0;j<NUMSPECIALS;j++) { c=ozreadfilebyte(); table[j]=(c-HEX)|((ozreadfilebyte()-HEX)<<4); } } else { version2=0; goto PROCESS_VERSION1; } } if(version2) { while(-1!=(c=ozreadfilebyte()) && (byte)c!=EOF_MARKER) { if((byte)c>=SPECIAL) val=table[c-SPECIAL]; else val=(c-HEX)|((ozreadfilebyte()-HEX)<<4); sum+=val; *p++=val; } if(c==EOF_MARKER) c='*'; } else { while(-1!=(c=ozreadfilebyte())) { PROCESS_VERSION1: if((byte)c=='*') break; if((byte)c=='~') { while(-1!=(c=ozreadfilebyte()) && '~'!=(byte)c) { sum+=(byte)c; *p++=c; } } else { if('0'<=(byte)c && (byte)c<='9') val=(c-'0')<<4; else val=(c+(10-'a'))<<4; c=ozreadfilebyte(); if('0'<=(byte)c && (byte)c<='9') val+=(c-'0'); else val+=(c+(10-'a')); *p++=val; sum+=(byte)val; } } c=ozreadfilebyte(); } if('*'==c) { for(i=0;i<5;i++) checksum[i]=ozreadfilebyte(); checksum[5]=0; } if('*'!=c || (unsigned)(atoi(checksum))!=sum) { ozclosefile(); close1(); unlink(filename); ozwarn("Error in memo!",anykey); return; } ozclosefile(); if(write1(filebuf,p-filebuf) < (p-filebuf) ) { close1(); unlink(filename); ozwarn("Error in writing!",anykey); return; } if(ozunlink(TYPENUM_MEMO,recnum)) { if(ozwarn("Error unlinking! Continue?",yn)!=KEY_LOWER_ENTER) return; } /* ozputch(0,0,continued); */ if(continued=='L') break; partnumber++; strcpy(parthead+15,utoa_0n(partnumber,5)); page=offset=0; while(loc=ozfindmemo(parthead,&page,&offset,&recnum)) { p=ozloadcluster(loc); if(strncmp(p+2+13+9+21,"**LIBOZ_UPLOAD*",15)) continue; break; } if(loc==0) { close1(); unlink(filename); ozwarn("Error: Cannot find next part!",anykey); return; } } while(loc); close1(); page=offset=0; } }
void load_headers(void) { static char hdr[8]; static unsigned i,n; static byte j,c; static struct ozfontheader fheader; bookmarksmod=0; backandforth=0; numbookmarks=last=0; show_bar=1; ozcls(); x=0; if(!strncmp(directory,filename,3)) { x=ozputs(0,x,"[bookmarks]"); filename[0]='b'; filename[1]='m'; if(open1(filename,O_RDONLY)>=0) { if(read1(hdr,8)==8 && !strncmp(hdr,"BookMrkA",8) && read1(&last,4)==4 && read1(&numbookmarks,1)==1 && read1(bookmarks,sizeof bookmarks)==sizeof bookmarks ) { if(numbookmarks) bookmarkptr=numbookmarks-1; read1(&line_height,1); if(line_height<8 || line_height>10) line_height=8; if(line_height!=9) num_lines=80/line_height; else num_lines=9; if(read1(&show_bar,1)<1 || show_bar>1) { show_bar=1; } if(read1(&positionptr,1)<1 || positionptr>MAX_POSITIONS || read1(&numpositions,1)<1 || numpositions>MAX_POSITIONS || read1(positions,sizeof positions)<sizeof positions) { numpositions=positionptr=0; } else backandforth=1; } else { numbookmarks=last=0; show_bar=1; none(); } close1(); } else { none(); } filename[0]='w'; filename[1]='b'; } else { none(); } x=ozputs(x,0,"[header]"); if(open1(filename,O_RDONLY)<0) err("Cannot open!"); if(read1(hdr,8)<8 || strncmp(hdr,"WizBookA",8) || read1(&header_length,2)<2 || read1(&length,4)<4 || read1(&numwords,2)<2 || read1(&dictionary_length,2)<2 || header_length>16384 || header_length<dictionary_length+10) err(error_header); header_length+=10; if(last==0) last=header_length; x=ozputs(x,0,"[dictionary]"); for(i=0;i<dictionary_length;i+=n) { n=dictionary_length-i; if(n>FILEBUF_LEN) n=FILEBUF_LEN; if(read1(filebuf,n)<n) err(error_dict); ozwriteauxmem(i,filebuf,n); } if(read1(&index_length,1)<1 || read1(&indentnum,1)<1) err(error_header); myfont=0xFF; if(indentnum&0x80) myfont=FONT_CUSTOM0; else if(indentnum&0x40) { x=ozputs(x,0,"[font]"); if(read1(&fheader,sizeof fheader)<sizeof fheader) err(error_font); for(i=0;i<sizeof fheader;i++) ozwritecustomfontbyte(0,i,((byte*)&fheader)[i]); for(i=sizeof fheader;i<fheader.length;i++) { if(read1(&c,1)<1) err(error_font); ozwritecustomfontbyte(0,i,c); } myfont=FONT_CUSTOM0; } if(myfont!=0xFF) { ozscancustomfonts(); line_height=ozgetfontheight(myfont); num_lines=80/line_height; } else { num_lines=line_height=9; myfont=FONT_OZ_NORMAL; } indentnum&=0x3f; for(n=i=0;i<numwords;i++) { j=0; while(!(0x80 & (c=ozreadauxbyte(n+j))) && j<MAX_WORD_LENGTH) j++; if(j==MAX_WORD_LENGTH) err(error_dict); ozwriteauxbyte(n+j,c&0x7f); j++; dict_idx[i]=n; dict_lens[i]=j; n+=j; } buffer_offset=header_length; ozputs(x,0,"[file]"); }
void close(BOOST_IOS::openmode which = BOOST_IOS::in | BOOST_IOS::out) { detail::external_closer<Sink2> close2(sink2_, which); detail::external_closer<Sink1> close1(sink1_, which); }