Switch PHYSFSX_fgets to auto-sized variant where possible

This commit is contained in:
Kp 2013-11-23 00:13:36 +00:00
parent 7f5410cc8b
commit a2cec5d71f
14 changed files with 46 additions and 41 deletions

View file

@ -191,6 +191,12 @@ static inline char * PHYSFSX_fgets(char *buf, size_t n, PHYSFS_file *const fp)
return buf;
}
template <size_t n>
static inline char * PHYSFSX_fgets(char (&buf)[n], PHYSFS_file *const fp)
{
return PHYSFSX_fgets(buf, n, fp);
}
static inline int PHYSFSX_printf(PHYSFS_file *file, const char *format, ...) __attribute_format_printf(2, 3);
static inline int PHYSFSX_printf(PHYSFS_file *file, const char *format, ...)
{

View file

@ -330,7 +330,7 @@ void ui_pad_read( int n, const char * filename )
while ( linenumber < 22)
{
PHYSFSX_fgets( buffer, 100, infile );
PHYSFSX_fgets( buffer, infile );
switch( linenumber+1 )
{
@ -505,7 +505,7 @@ void ui_pad_read( int n, const char * filename )
// Get the keycodes...
while (PHYSFSX_fgets(line_buffer, 200, infile))
while (PHYSFSX_fgets(line_buffer, infile))
{
sscanf(line_buffer, " %s %s ", text, buffer);
keycode = DecodeKeyText(text);

View file

@ -778,7 +778,7 @@ void menubar_init( const char * file )
if (!infile) return;
while ( PHYSFSX_fgets( buffer, 200, infile) != NULL )
while ( PHYSFSX_fgets( buffer, infile) != NULL )
{
if ( buffer[0] == ';' ) continue;

View file

@ -390,7 +390,7 @@ int gamedata_read_tbl(int pc_shareware)
PHYSFSX_fseek( InfoFile, 0L, SEEK_SET);
while (PHYSFSX_fgets(inputline, LINEBUF_SIZE, InfoFile)) {
while (PHYSFSX_fgets(inputline, InfoFile)) {
int l;
char *temp_ptr;
int skip;

View file

@ -435,7 +435,7 @@ int gamedata_read_tbl(int pc_shareware)
PHYSFSX_fseek( InfoFile, 0L, SEEK_SET);
while (PHYSFSX_fgets(inputline, LINEBUF_SIZE, InfoFile)) {
while (PHYSFSX_fgets(inputline, InfoFile)) {
int l;
char *temp_ptr;
int skip;

View file

@ -285,7 +285,7 @@ static void medkey_init()
keyfile = PHYSFSX_openReadBuffered( "GLOBAL.KEY" );
if (keyfile)
{
while (PHYSFSX_fgets(line_buffer, 200, keyfile))
while (PHYSFSX_fgets(line_buffer, keyfile))
{
sscanf(line_buffer, " %s %s ", keypress, LispCommand);
//ReadLispMacro( keyfile, LispCommand );

View file

@ -114,7 +114,7 @@ static int credits_handler(window *wind, d_event *event, credits *cr)
#if defined(DXX_BUILD_DESCENT_II)
get_line:;
#endif
if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], 80, cr->file )) {
if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], cr->file )) {
char *p;
if (cr->have_bin_file) // is this a binary tbl file
decode_text_line (cr->buffer[cr->buffer_line]);

View file

@ -1445,7 +1445,7 @@ try_again:
var = 0;
while (PHYSFSX_fgets(line,LINE_LEN,ifile)) {
while (PHYSFSX_fgets(line,ifile)) {
if (have_binary)
decode_text_line (line);

View file

@ -832,7 +832,7 @@ static int load_game_data(PHYSFS_file *LoadFile)
if (game_top_fileinfo_version >= 31) //load mine filename
// read newline-terminated string, not sure what version this changed.
PHYSFSX_fgets(Current_level_name,sizeof(Current_level_name),LoadFile);
PHYSFSX_fgets(Current_level_name,LoadFile);
else if (game_top_fileinfo_version >= 14) { //load mine filename
// read null-terminated string
char *p=Current_level_name;
@ -1359,7 +1359,7 @@ int load_level(const char * filename_passed)
}
if (Gamesave_current_version > 1)
PHYSFSX_fgets(Current_level_palette,sizeof(Current_level_palette),LoadFile);
PHYSFSX_fgets(Current_level_palette,LoadFile);
if (Gamesave_current_version <= 1 || Current_level_palette[0]==0) // descent 1 level
strcpy(Current_level_palette, DEFAULT_LEVEL_PALETTE);

View file

@ -339,7 +339,7 @@ static char *get_parm_value(const char *parm,PHYSFS_file *f)
{
static char buf[80];
if (!PHYSFSX_fgets(buf,80,f))
if (!PHYSFSX_fgets(buf,f))
return NULL;
if (istok(buf,parm))
@ -867,7 +867,7 @@ static int load_mission(mle *mission)
snprintf(Ending_text_filename, sizeof(Ending_text_filename), "%s.txb",Current_mission_filename);
}
while (PHYSFSX_fgets(buf,sizeof(buf),mfile)) {
while (PHYSFSX_fgets(buf,mfile)) {
#if defined(DXX_BUILD_DESCENT_II)
if (istok(buf,"name") && !Current_mission->enhanced) {
Current_mission->enhanced = 0;
@ -956,7 +956,7 @@ static int load_mission(mle *mission)
}
for (i=0;i<n_levels;i++) {
PHYSFSX_fgets(buf,sizeof(buf),mfile);
PHYSFSX_fgets(buf,mfile);
add_term(buf);
if (strlen(buf) <= 12) {
strcpy(Level_names[i],buf);
@ -994,7 +994,7 @@ static int load_mission(mle *mission)
for (i=0;i<N_secret_levels;i++) {
char *t;
PHYSFSX_fgets(buf,sizeof(buf),mfile);
PHYSFSX_fgets(buf,mfile);
if ((t=strchr(buf,','))!=NULL) *t++=0;
else
break;

View file

@ -2009,7 +2009,7 @@ static void read_d1_tmap_nums_from_hog(PHYSFS_file *d1_pig)
for (i = 0; i < D1_MAX_TMAP_NUM; i++)
d1_tmap_nums[i] = -1;
while (PHYSFSX_fgets (inputline, LINEBUF_SIZE, bitmaps)) {
while (PHYSFSX_fgets (inputline, bitmaps)) {
char *arg;
if (bitmaps_tbl_is_binary)

View file

@ -183,14 +183,14 @@ static int read_player_dxx(const char *filename)
while(!Stop && !PHYSFS_eof(f))
{
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,':');
d_strupr(word);
#if defined(DXX_BUILD_DESCENT_I)
if (strstr(word,"WEAPON REORDER"))
{
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
while(!strstr(word,"END") && !PHYSFS_eof(f))
@ -207,7 +207,7 @@ static int read_player_dxx(const char *filename)
PlayerCfg.SecondaryOrder[0]=wo0; PlayerCfg.SecondaryOrder[1]=wo1; PlayerCfg.SecondaryOrder[2]=wo2; PlayerCfg.SecondaryOrder[3]=wo3; PlayerCfg.SecondaryOrder[4]=wo4; PlayerCfg.SecondaryOrder[5]=wo5;
}
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
}
@ -217,7 +217,7 @@ static int read_player_dxx(const char *filename)
if (strstr(word,"KEYBOARD"))
{
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
@ -234,7 +234,7 @@ static int read_player_dxx(const char *filename)
if(!strcmp(word,"SENSITIVITY4"))
PlayerCfg.KeyboardSens[4] = atoi(line);
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
}
@ -242,7 +242,7 @@ static int read_player_dxx(const char *filename)
else if (strstr(word,"JOYSTICK"))
{
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
@ -273,7 +273,7 @@ static int read_player_dxx(const char *filename)
if(!strcmp(word,"DEADZONE5"))
PlayerCfg.JoystickDead[5] = atoi(line);
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
}
@ -281,7 +281,7 @@ static int read_player_dxx(const char *filename)
else if (strstr(word,"MOUSE"))
{
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
@ -306,7 +306,7 @@ static int read_player_dxx(const char *filename)
if(!strcmp(word,"FSINDI"))
PlayerCfg.MouseFSIndicator = atoi(line);
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
}
@ -314,7 +314,7 @@ static int read_player_dxx(const char *filename)
else if (strstr(word,"WEAPON KEYS V2"))
{
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
while(!strstr(word,"END") && !PHYSFS_eof(f))
@ -330,7 +330,7 @@ static int read_player_dxx(const char *filename)
PlayerCfg.KeySettingsRebirth[i+1] = kc2;
PlayerCfg.KeySettingsRebirth[i+2] = kc3;
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
}
@ -338,7 +338,7 @@ static int read_player_dxx(const char *filename)
else if (strstr(word,"COCKPIT"))
{
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
@ -358,7 +358,7 @@ static int read_player_dxx(const char *filename)
else if(!strcmp(word,"RETSIZE"))
PlayerCfg.ReticleSize = atoi(line);
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
}
@ -366,7 +366,7 @@ static int read_player_dxx(const char *filename)
else if (strstr(word,"TOGGLES"))
{
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
@ -396,7 +396,7 @@ static int read_player_dxx(const char *filename)
if(!strcmp(word,"CYCLEAUTOSELECTONLY"))
PlayerCfg.CycleAutoselectOnly = atoi(line);
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
}
@ -404,7 +404,7 @@ static int read_player_dxx(const char *filename)
else if (strstr(word,"GRAPHICS"))
{
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
@ -415,7 +415,7 @@ static int read_player_dxx(const char *filename)
if(!strcmp(word,"DYNLIGHTCOLOR"))
PlayerCfg.DynLightColor = atoi(line);
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
}
@ -424,14 +424,14 @@ static int read_player_dxx(const char *filename)
{
int v1=0,v2=0,v3=0;
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
while(!strstr(word,"END") && !PHYSFS_eof(f))
{
sscanf(line,"%i.%i.%i",&v1,&v2,&v3);
d_free(word);
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,'=');
d_strupr(word);
}
@ -466,7 +466,7 @@ static int read_player_dxx(const char *filename)
{
while(!strstr(line,"END") && !PHYSFS_eof(f))
{
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
d_strupr(line);
}
}
@ -531,7 +531,7 @@ static void plyr_read_stats_v(int *k, int *d)
char line[256],*word;
if(!PHYSFS_eof(f))
{
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,':');
if(!strcmp(word,"kills"))
*k=atoi(line);
@ -539,7 +539,7 @@ static void plyr_read_stats_v(int *k, int *d)
}
if(!PHYSFS_eof(f))
{
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,':');
if(!strcmp(word,"deaths"))
*d=atoi(line);
@ -547,7 +547,7 @@ static void plyr_read_stats_v(int *k, int *d)
}
if(!PHYSFS_eof(f))
{
PHYSFSX_fgets(line,50,f);
PHYSFSX_fgets(line,f);
word=splitword(line,':');
if(!strcmp(word,"key") && strlen(line)>10){
unsigned char *p;

View file

@ -107,9 +107,8 @@ static void songs_init()
}
else
{
while (!PHYSFS_eof(fp))
while (!PHYSFS_eof(fp) && PHYSFSX_fgets(inputline, fp))
{
PHYSFSX_fgets(inputline, sizeof(inputline), fp );
if ( strlen( inputline ) )
{
BIMSongs = (struct bim_song_info *) d_realloc(BIMSongs, sizeof(bim_song_info)*(i+1));

View file

@ -80,7 +80,7 @@ static void AppendIniArgs(void)
if(f) {
char line[1024];
while(!PHYSFS_eof(f) && Args.size() < MAX_ARGS && PHYSFSX_fgets(line, sizeof(line), f))
while(!PHYSFS_eof(f) && Args.size() < MAX_ARGS && PHYSFSX_fgets(line, f))
{
static const char separator[] = " ";
for(char *token = strtok(line, separator); token != NULL; token = strtok(NULL, separator))