src/ui-prefs.c
static void remove_old_dump(const char *cur_fname, const char *mark)
{
	bool between_marks = FALSE;
	bool changed = FALSE;
	bool skip_one = FALSE;

	char buf[1024];

	char start_line[1024];
	char end_line[1024];

	char new_fname[1024];

	ang_file *new_file;
	ang_file *cur_file;

	/* Format up some filenames */
	strnfmt(new_fname, sizeof(new_fname), "%s.new", cur_fname);

	/* Work out what we expect to find */
	strnfmt(start_line, sizeof(start_line), "%s begin %s",
			dump_separator, mark);
	strnfmt(end_line,   sizeof(end_line),   "%s end %s",
			dump_separator, mark);


	/* Open current file */
	cur_file = file_open(cur_fname, MODE_READ, FTYPE_TEXT);
	if (!cur_file) return;

	/* Open new file */
	new_file = file_open(new_fname, MODE_WRITE, FTYPE_TEXT);
	if (!new_file) {
		msg("Failed to create file %s", new_fname);
		return;
	}

	/* Loop for every line */
	while (file_getl(cur_file, buf, sizeof(buf))) {
		/* Turn on at the start line, turn off at the finish line */
		if (!strcmp(buf, start_line))
			between_marks = TRUE;
		else if (!strcmp(buf, end_line)) {
			between_marks = FALSE;
			skip_one = TRUE;
			changed = TRUE;
		}

		if (!between_marks && !skip_one)
			file_putf(new_file, "%s\n", buf);

		skip_one = FALSE;
	}

	/* Close files */
	file_close(cur_file);
	file_close(new_file);

	/* If there are changes use the new file. otherwise just destroy it */
	if (changed) {
		char old_fname[1024];
		strnfmt(old_fname, sizeof(old_fname), "%s.old", cur_fname);

		if (file_move(cur_fname, old_fname)) {
			file_move(new_fname, cur_fname);
			file_delete(old_fname);
		}
	} else {
		file_delete(new_fname);
	}
}
/**
 * Remove old lines from pref files
 *
 * If you are using setgid, make sure privileges were raised prior
 * to calling this.
 */
Remove old lines from pref files
If you are using setgid, make sure privileges were raised prior
to calling this.
Remove old lines from pref files If you are using setgid make sure privileges were raised prior to calling this .
static void remove_old_dump(const char *cur_fname, const char *mark)
{
	bool between_marks = FALSE;
	bool changed = FALSE;
	bool skip_one = FALSE;
	char buf[1024];
	char start_line[1024];
	char end_line[1024];
	char new_fname[1024];
	ang_file *new_file;
	ang_file *cur_file;
	strnfmt(new_fname, sizeof(new_fname), "%s.new", cur_fname);
	strnfmt(start_line, sizeof(start_line), "%s begin %s",
			dump_separator, mark);
	strnfmt(end_line,   sizeof(end_line),   "%s end %s",
			dump_separator, mark);
	cur_file = file_open(cur_fname, MODE_READ, FTYPE_TEXT);
	if (!cur_file) return;
	new_file = file_open(new_fname, MODE_WRITE, FTYPE_TEXT);
	if (!new_file) {
		msg("Failed to create file %s", new_fname);
		return;
	}
	while (file_getl(cur_file, buf, sizeof(buf))) {
		if (!strcmp(buf, start_line))
			between_marks = TRUE;
		else if (!strcmp(buf, end_line)) {
			between_marks = FALSE;
			skip_one = TRUE;
			changed = TRUE;
		}
		if (!between_marks && !skip_one)
			file_putf(new_file, "%s\n", buf);
		skip_one = FALSE;
	}
	file_close(cur_file);
	file_close(new_file);
	if (changed) {
		char old_fname[1024];
		strnfmt(old_fname, sizeof(old_fname), "%s.old", cur_fname);
		if (file_move(cur_fname, old_fname)) {
			file_move(new_fname, cur_fname);
			file_delete(old_fname);
		}
	} else {
		file_delete(new_fname);
	}
}
static void remove_old_dump ( const char * cur_fname , const char * mark ) { bool between_marks = FALSE ; bool changed = FALSE ; bool skip_one = FALSE ; char buf [ 1024 ] ; char start_line [ 1024 ] ; char end_line [ 1024 ] ; char new_fname [ 1024 ] ; ang_file * new_file ; ang_file * cur_file ; strnfmt ( new_fname , sizeof ( new_fname ) , " " , cur_fname ) ; strnfmt ( start_line , sizeof ( start_line ) , " " , dump_separator , mark ) ; strnfmt ( end_line , sizeof ( end_line ) , " " , dump_separator , mark ) ; cur_file = file_open ( cur_fname , MODE_READ , FTYPE_TEXT ) ; if ( ! cur_file ) return ; new_file = file_open ( new_fname , MODE_WRITE , FTYPE_TEXT ) ; if ( ! new_file ) { msg ( " " , new_fname ) ; return ; } while ( file_getl ( cur_file , buf , sizeof ( buf ) ) ) { if ( ! strcmp ( buf , start_line ) ) between_marks = TRUE ; else if ( ! strcmp ( buf , end_line ) ) { between_marks = FALSE ; skip_one = TRUE ; changed = TRUE ; } if ( ! between_marks && ! skip_one ) file_putf ( new_file , " \n " , buf ) ; skip_one = FALSE ; } file_close ( cur_file ) ; file_close ( new_file ) ; if ( changed ) { char old_fname [ 1024 ] ; strnfmt ( old_fname , sizeof ( old_fname ) , " " , cur_fname ) ; if ( file_move ( cur_fname , old_fname ) ) { file_move ( new_fname , cur_fname ) ; file_delete ( old_fname ) ; } } else { file_delete ( new_fname ) ; } }
Remove old lines from pref files
 If you are using setgid, make sure privileges were raised prior
 to calling this.
Remove old lines from pref files If you are using setgid make sure privileges were raised prior to calling this .
/* Format up some filenames */ /* Work out what we expect to find */ /* Open current file */ /* Open new file */ /* Loop for every line */ /* Turn on at the start line, turn off at the finish line */ /* Close files */ /* If there are changes use the new file. otherwise just destroy it */