/* File names management */ #include "common.h" #include "file.h" #define FREE '-' #define BUSY '+' /* Assign unique file name */ Global(CharPtr) AssignFileName(void) { int pos,c; FILE PNTR stream; stream=FileOpen(GetParam(SFS_FILES,"NAMES"),"r+b"); /* The following code behaves differently when compiled by Borland C 3.1 and by cc (Unix) and the first char in the stream is '-'. pos=-1; fscanf(stream,"%*[+]%n",&pos); if (pos>=0) ... So we have use 'portable' solution... */ for (pos=0; (c=fgetc(stream),c!=EOF); pos++) if (c==FREE) break; if (c==FREE) fseek(stream,pos,SEEK_SET); else { fseek(stream,0,SEEK_END); pos=(int)ftell(stream); } fputc(BUSY,stream); FileClose(stream); return GetParam(SFS_FILES,"FORMAT",pos); } /* Mark given file name as free */ Global(void) FreeFileName(CharPtr name) { int num; FILE PNTR stream; stream=FileOpen(GetParam(SFS_FILES,"NAMES"),"r+b"); num=-1; sscanf(name,GetParamString(SFS_FILES,"FORMAT"),&num); if (num>=0) if (fseek(stream,num,SEEK_SET)==0) fputc(FREE,stream); FileClose(stream); }