2001-02-23 07:48:14 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/*
|
|
|
|
* This is free and unencumbered software released into the public domain.
|
|
|
|
*
|
|
|
|
* For more information, please refer to <https://unlicense.org>
|
|
|
|
*/
|
2001-05-16 14:39:31 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/*
|
|
|
|
* Generic implementation of HistoryFile
|
|
|
|
*/
|
2001-02-23 07:48:14 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
#ifndef __HISTORY_H
|
|
|
|
#define __HISTORY_H
|
2001-02-23 07:48:14 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
2001-02-23 07:48:14 +00:00
|
|
|
{
|
2020-09-12 16:16:42 +00:00
|
|
|
#endif
|
|
|
|
|
2020-09-14 15:51:13 +00:00
|
|
|
#include "gtkcompat.h"
|
2020-09-12 16:16:42 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
typedef struct _Whistory HistoryFile;
|
|
|
|
|
2020-09-13 15:51:04 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
HISTORY_SAVE_ALWAYS,
|
|
|
|
HISTORY_SAVE_IF_CHANGED,
|
|
|
|
};
|
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// create a new HistoryFile
|
|
|
|
/// the history is initialized using filename and the filename is stored
|
|
|
|
/// maxcount > 0 sets a maximun item count
|
|
|
|
HistoryFile * history_new (char * filename, unsigned int maxcount);
|
|
|
|
|
2020-09-13 15:51:04 +00:00
|
|
|
/// save history to file, 0 = force save / 1 = save only if history has changed
|
|
|
|
void history_save (HistoryFile * history, int save_if_changed);
|
2020-09-12 16:16:42 +00:00
|
|
|
|
|
|
|
/// history is destroyed, you must variable to NULL
|
|
|
|
void history_destroy (HistoryFile * history);
|
2002-08-16 10:30:18 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// clear history and reload from file
|
|
|
|
void history_reload (HistoryFile * history);
|
2002-08-16 10:30:18 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// print history, good for debugging
|
|
|
|
void history_print (HistoryFile * history);
|
2002-08-16 10:30:18 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// some apps might want to handle prev/next in a special way
|
|
|
|
void history_unset_current (HistoryFile * history);
|
2001-07-18 07:03:39 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// returns string with the current history item
|
|
|
|
const char * history_get_current (HistoryFile * history);
|
2002-08-16 10:30:18 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// returns current index: valid index > 0
|
|
|
|
/// assume unser current item if index <= 0
|
|
|
|
int history_get_current_index (HistoryFile * history);
|
2002-08-16 10:30:18 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// moves position to the next entry and returns text
|
|
|
|
/// if there is no next entry, the position is not moved and returns NULL
|
|
|
|
const char * history_next (HistoryFile * history);
|
2001-07-02 09:12:16 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// moves position to the previous entry and returns text
|
|
|
|
/// if there is no next entry, the position is not moved and returns NULL
|
|
|
|
const char * history_prev (HistoryFile * history);
|
2001-07-31 10:56:44 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// moves position to the first entry en returns text
|
|
|
|
/// if there are no entries, it returns NULL
|
|
|
|
const char * history_first (HistoryFile * history);
|
2001-10-19 08:59:40 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
/// moves position to the last entry en returns text
|
|
|
|
/// if there are no entries, it returns NULL
|
|
|
|
const char * history_last (HistoryFile * history);
|
2001-10-19 08:59:40 +00:00
|
|
|
|
2020-09-13 15:51:04 +00:00
|
|
|
/// add entry to history, if entry already exists, it's moved to the end of the list
|
2020-09-12 16:16:42 +00:00
|
|
|
void history_append (HistoryFile * history, const char * text);
|
2002-08-16 10:30:18 +00:00
|
|
|
|
2020-09-13 15:51:04 +00:00
|
|
|
void history_reverse (HistoryFile * history);
|
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2001-02-23 07:48:14 +00:00
|
|
|
|
2020-09-12 16:16:42 +00:00
|
|
|
#endif
|