ref: b7034aeb51a99336fca2e15837c8337481964f6d
parent: 12cb1adc886078d715abbc04e80912703340f496
author: Simon Tatham <anakin@pobox.com>
date: Sun Apr 22 09:58:27 EDT 2018
Move fgetline out into misc.c. I'm about to want to use it outside the GTK front end.
--- a/gtk.c
+++ b/gtk.c
@@ -2886,25 +2886,6 @@
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)
{
int i;
--- a/misc.c
+++ b/misc.c
@@ -169,6 +169,25 @@
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,
int background, int highlight, int lowlight)
{
--- a/puzzles.h
+++ b/puzzles.h
@@ -357,6 +357,7 @@
*/
void free_cfg(config_item *cfg);
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.
* May assert (or just go wrong) if lengths are unchecked. */