mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Move fgetline out into misc.c.
I'm about to want to use it outside the GTK front end.
This commit is contained in:
19
gtk.c
19
gtk.c
@ -2886,25 +2886,6 @@ static frontend *new_window(char *arg, int argtype, char **error)
|
|||||||
return fe;
|
return fe;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *fgetline(FILE *fp)
|
|
||||||
{
|
|
||||||
char *ret = snewn(512, char);
|
|
||||||
int size = 512, len = 0;
|
|
||||||
while (fgets(ret + len, size - len, fp)) {
|
|
||||||
len += strlen(ret + len);
|
|
||||||
if (ret[len-1] == '\n')
|
|
||||||
break; /* got a newline, we're done */
|
|
||||||
size = len + 512;
|
|
||||||
ret = sresize(ret, size, char);
|
|
||||||
}
|
|
||||||
if (len == 0) { /* first fgets returned NULL */
|
|
||||||
sfree(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
ret[len] = '\0';
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void list_presets_from_menu(struct preset_menu *menu)
|
static void list_presets_from_menu(struct preset_menu *menu)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
19
misc.c
19
misc.c
@ -169,6 +169,25 @@ unsigned char *hex2bin(const char *in, int outlen)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *fgetline(FILE *fp)
|
||||||
|
{
|
||||||
|
char *ret = snewn(512, char);
|
||||||
|
int size = 512, len = 0;
|
||||||
|
while (fgets(ret + len, size - len, fp)) {
|
||||||
|
len += strlen(ret + len);
|
||||||
|
if (ret[len-1] == '\n')
|
||||||
|
break; /* got a newline, we're done */
|
||||||
|
size = len + 512;
|
||||||
|
ret = sresize(ret, size, char);
|
||||||
|
}
|
||||||
|
if (len == 0) { /* first fgets returned NULL */
|
||||||
|
sfree(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ret[len] = '\0';
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void game_mkhighlight_specific(frontend *fe, float *ret,
|
void game_mkhighlight_specific(frontend *fe, float *ret,
|
||||||
int background, int highlight, int lowlight)
|
int background, int highlight, int lowlight)
|
||||||
{
|
{
|
||||||
|
@ -357,6 +357,7 @@ char *dupstr(const char *s);
|
|||||||
*/
|
*/
|
||||||
void free_cfg(config_item *cfg);
|
void free_cfg(config_item *cfg);
|
||||||
void obfuscate_bitmap(unsigned char *bmp, int bits, int decode);
|
void obfuscate_bitmap(unsigned char *bmp, int bits, int decode);
|
||||||
|
char *fgetline(FILE *fp);
|
||||||
|
|
||||||
/* allocates output each time. len is always in bytes of binary data.
|
/* allocates output each time. len is always in bytes of binary data.
|
||||||
* May assert (or just go wrong) if lengths are unchecked. */
|
* May assert (or just go wrong) if lengths are unchecked. */
|
||||||
|
Reference in New Issue
Block a user