Formatting
This commit is contained in:
parent
f9c308765f
commit
10240c716a
|
@ -11,5 +11,5 @@
|
|||
#cmakedefine WITH_GTK
|
||||
#cmakedefine HAVE_RESIZETERM
|
||||
|
||||
#endif /* ! CONFIG_H */
|
||||
#endif // ! CONFIG_H
|
||||
|
||||
|
|
|
@ -40,43 +40,43 @@ typedef struct worker_data WorkerData;
|
|||
|
||||
struct worker_data
|
||||
{
|
||||
gchar **cmdline; //! eSpeak command line
|
||||
guint ignore_acronyms : 1; //! Don't spell out acronyms
|
||||
GRegex *re_stop; //! Regex for stop sequences
|
||||
GRegex *re_acronym; //! Regex for ACRONYMS
|
||||
gchar **cmdline; ///< eSpeak command line
|
||||
guint ignore_acronyms : 1; ///< Don't spell out acronyms
|
||||
GRegex *re_stop; ///< Regex for stop sequences
|
||||
GRegex *re_acronym; ///< Regex for ACRONYMS
|
||||
|
||||
guint32 start_entry; //! The first entry to be processed
|
||||
guint32 end_entry; //! Past the last entry to be processed
|
||||
guint32 start_entry; ///< The first entry to be processed
|
||||
guint32 end_entry; ///< Past the last entry to be processed
|
||||
|
||||
/* Reader, writer */
|
||||
GMutex *dict_mutex; //! Locks the dictionary object
|
||||
// Reader, writer
|
||||
GMutex *dict_mutex; ///< Locks the dictionary object
|
||||
|
||||
/* Reader */
|
||||
GThread *main_thread; //! A handle to the reader thread
|
||||
StardictDict *dict; //! The dictionary object
|
||||
gpointer output; //! Linked-list of pronunciation data
|
||||
// Reader
|
||||
GThread *main_thread; ///< A handle to the reader thread
|
||||
StardictDict *dict; ///< The dictionary object
|
||||
gpointer output; ///< Linked-list of pronunciation data
|
||||
|
||||
GMutex *remaining_mutex; //! Locks the progress stats
|
||||
GCond *remaining_cond; //! Signals a change in progress
|
||||
guint32 remaining; //! How many entries remain
|
||||
guint32 total; //! Total number of entries
|
||||
GMutex *remaining_mutex; ///< Locks the progress stats
|
||||
GCond *remaining_cond; ///< Signals a change in progress
|
||||
guint32 remaining; ///< How many entries remain
|
||||
guint32 total; ///< Total number of entries
|
||||
|
||||
/* Writer */
|
||||
StardictIterator *iterator; //! Iterates over the dictionary
|
||||
FILE *child_stdin; //! Standard input of eSpeak
|
||||
// Writer
|
||||
StardictIterator *iterator; ///< Iterates over the dictionary
|
||||
FILE *child_stdin; ///< Standard input of eSpeak
|
||||
};
|
||||
|
||||
/** eSpeak splits the output on certain characters. */
|
||||
/// eSpeak splits the output on certain characters.
|
||||
#define LINE_SPLITTING_CHARS ".,:;?!"
|
||||
|
||||
/** We don't want to include brackets either. */
|
||||
/// We don't want to include brackets either.
|
||||
#define OTHER_STOP_CHARS "([{<"
|
||||
|
||||
/** A void word used to make a unique "no pronunciation available" mark. */
|
||||
/// A void word used to make a unique "no pronunciation available" mark.
|
||||
#define VOID_ENTRY "not present in any dictionary"
|
||||
|
||||
|
||||
/** Adds dots between characters. */
|
||||
/// Adds dots between characters.
|
||||
static gboolean
|
||||
writer_acronym_cb (const GMatchInfo *info, GString *res,
|
||||
G_GNUC_UNUSED gpointer data)
|
||||
|
@ -99,7 +99,7 @@ writer_acronym_cb (const GMatchInfo *info, GString *res,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/** Writes to espeak's stdin. */
|
||||
/// Writes to espeak's stdin.
|
||||
static gpointer
|
||||
worker_writer (WorkerData *data)
|
||||
{
|
||||
|
@ -114,7 +114,7 @@ worker_writer (WorkerData *data)
|
|||
word += strspn (word, LINE_SPLITTING_CHARS " \t");
|
||||
gchar *x = g_strdup (word);
|
||||
|
||||
/* Cut the word if needed be */
|
||||
// Cut the word if needed be
|
||||
error = NULL;
|
||||
if (g_regex_match_full (data->re_stop,
|
||||
x, -1, 0, 0, &match_info, &error))
|
||||
|
@ -125,7 +125,7 @@ worker_writer (WorkerData *data)
|
|||
}
|
||||
g_match_info_free (match_info);
|
||||
|
||||
/* Change acronyms so that they're not pronounced as words */
|
||||
// Change acronyms so that they're not pronounced as words
|
||||
if (!error && !data->ignore_acronyms)
|
||||
{
|
||||
char *tmp = g_regex_replace_eval (data->re_acronym,
|
||||
|
@ -142,7 +142,7 @@ worker_writer (WorkerData *data)
|
|||
*x = 0;
|
||||
}
|
||||
|
||||
/* We might have accidentally cut off everything */
|
||||
// We might have accidentally cut off everything
|
||||
if (!*x)
|
||||
{
|
||||
g_free (x);
|
||||
|
@ -160,7 +160,7 @@ worker_writer (WorkerData *data)
|
|||
return GINT_TO_POINTER (fclose (data->child_stdin));
|
||||
}
|
||||
|
||||
/** Get the void entry (and test if espeak works). */
|
||||
/// Get the void entry (and test if espeak works).
|
||||
static gchar *
|
||||
get_void_entry (gchar *cmdline[])
|
||||
{
|
||||
|
@ -185,11 +185,11 @@ get_void_entry (gchar *cmdline[])
|
|||
return output;
|
||||
}
|
||||
|
||||
/** Reads from espeak's stdout. */
|
||||
/// Reads from espeak's stdout.
|
||||
static gpointer
|
||||
worker (WorkerData *data)
|
||||
{
|
||||
/* Spawn eSpeak */
|
||||
// Spawn eSpeak
|
||||
GError *error = NULL;
|
||||
gint child_in, child_out;
|
||||
if (!g_spawn_async_with_pipes (NULL, data->cmdline, NULL,
|
||||
|
@ -205,7 +205,7 @@ worker (WorkerData *data)
|
|||
if (!child_stdout)
|
||||
perror ("fdopen");
|
||||
|
||||
/* Spawn a writer thread */
|
||||
// Spawn a writer thread
|
||||
g_mutex_lock (data->dict_mutex);
|
||||
data->iterator = stardict_iterator_new (data->dict, data->start_entry);
|
||||
g_mutex_unlock (data->dict_mutex);
|
||||
|
@ -213,7 +213,7 @@ worker (WorkerData *data)
|
|||
GThread *writer = g_thread_new ("write worker",
|
||||
(GThreadFunc) worker_writer, data);
|
||||
|
||||
/* Read the output */
|
||||
// Read the output
|
||||
g_mutex_lock (data->remaining_mutex);
|
||||
guint32 remaining = data->remaining;
|
||||
g_mutex_unlock (data->remaining_mutex);
|
||||
|
@ -236,8 +236,8 @@ worker (WorkerData *data)
|
|||
*output_end = translation;
|
||||
output_end = (gpointer *) translation;
|
||||
|
||||
/* We limit progress reporting so that
|
||||
* the mutex doesn't spin like crazy */
|
||||
// We limit progress reporting so that
|
||||
// the mutex doesn't spin like crazy
|
||||
if ((--remaining & 255) != 0)
|
||||
continue;
|
||||
|
||||
|
@ -260,7 +260,7 @@ worker (WorkerData *data)
|
|||
|
||||
// --- Main --------------------------------------------------------------------
|
||||
|
||||
/** Copy the contents of one StardictInfo object into another. Ignores path. */
|
||||
/// Copy the contents of one StardictInfo object into another. Ignores path.
|
||||
static void
|
||||
stardict_info_copy (StardictInfo *dest, const StardictInfo *src)
|
||||
{
|
||||
|
@ -284,7 +284,7 @@ stardict_info_copy (StardictInfo *dest, const StardictInfo *src)
|
|||
}
|
||||
}
|
||||
|
||||
/** Write a list of data fields back to a dictionary. */
|
||||
/// Write a list of data fields back to a dictionary.
|
||||
static gboolean
|
||||
write_fields (Generator *generator, GList *fields, gboolean sts, GError **error)
|
||||
{
|
||||
|
@ -356,7 +356,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
|
||||
g_option_context_free (ctx);
|
||||
|
||||
/* See if we can run espeak */
|
||||
// See if we can run espeak
|
||||
static gchar *cmdline[] = { "espeak", "--ipa", "-q", NULL, NULL, NULL };
|
||||
|
||||
if (voice)
|
||||
|
@ -367,7 +367,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
|
||||
gchar *void_entry = g_strstrip (get_void_entry (cmdline));
|
||||
|
||||
/* Load the dictionary */
|
||||
// Load the dictionary
|
||||
printf ("Loading the original dictionary...\n");
|
||||
StardictDict *dict = stardict_dict_new (argv[1], &error);
|
||||
if (!dict)
|
||||
|
@ -395,7 +395,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
n_processes);
|
||||
}
|
||||
|
||||
/* Spawn worker threads to generate pronunciation data */
|
||||
// Spawn worker threads to generate pronunciation data
|
||||
static GMutex dict_mutex;
|
||||
|
||||
static GMutex remaining_mutex;
|
||||
|
@ -434,7 +434,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
g_thread_new ("worker", (GThreadFunc) worker, &data[i]);
|
||||
}
|
||||
|
||||
/* Loop while the threads still have some work to do and report status */
|
||||
// Loop while the threads still have some work to do and report status
|
||||
g_mutex_lock (&remaining_mutex);
|
||||
for (;;)
|
||||
{
|
||||
|
@ -460,7 +460,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
g_regex_unref (re_stop);
|
||||
g_regex_unref (re_acronym);
|
||||
|
||||
/* Put extended entries into a new dictionary */
|
||||
// Put extended entries into a new dictionary
|
||||
Generator *generator = generator_new (argv[2], &error);
|
||||
if (!generator)
|
||||
{
|
||||
|
@ -472,7 +472,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
StardictInfo *info = generator->info;
|
||||
stardict_info_copy (info, stardict_dict_get_info (dict));
|
||||
|
||||
/* This gets incremented each time an entry is finished */
|
||||
// This gets incremented each time an entry is finished
|
||||
info->word_count = 0;
|
||||
|
||||
if (info->same_type_sequence)
|
||||
|
@ -482,7 +482,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
info->same_type_sequence = new_sts;
|
||||
}
|
||||
|
||||
/* Write out all the entries together with the pronunciation */
|
||||
// Write out all the entries together with the pronunciation
|
||||
for (i = 0; i < n_processes; i++)
|
||||
{
|
||||
StardictIterator *iterator =
|
||||
|
@ -508,8 +508,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
// g_printerr ("%s /%s/\n",
|
||||
// stardict_iterator_get_word (iterator), pronunciation);
|
||||
|
||||
/* For the sake of simplicity we fake a new start;
|
||||
* write_fields() only iterates the list in one direction. */
|
||||
// For the sake of simplicity we fake a new start;
|
||||
// write_fields() only iterates the list in one direction.
|
||||
StardictEntryField field;
|
||||
field.type = 't';
|
||||
field.data = pronunciation;
|
||||
|
|
|
@ -50,7 +50,7 @@ free_gzip_header (gz_header *gzh)
|
|||
g_free (gzh->name); gzh->name = NULL;
|
||||
}
|
||||
|
||||
/* Reading the header in manually due to stupidity of the ZLIB API. */
|
||||
// Reading the header in manually due to stupidity of the ZLIB API.
|
||||
static gboolean
|
||||
read_gzip_header (GInputStream *is, gz_header *gzh,
|
||||
goffset *first_block_offset, GError **error)
|
||||
|
@ -279,19 +279,19 @@ static gssize dictzip_input_stream_skip (GInputStream *stream, gsize count,
|
|||
|
||||
struct dictzip_input_stream_private
|
||||
{
|
||||
GFileInfo * file_info; //!< File information from gzip header
|
||||
GFileInfo * file_info; ///< File information from gzip header
|
||||
|
||||
goffset first_block_offset; //!< Offset to the first block/chunk
|
||||
gsize chunk_length; //!< Uncompressed chunk length
|
||||
gsize n_chunks; //!< Number of chunks in file
|
||||
guint16 * chunks; //!< Chunk sizes after compression
|
||||
goffset first_block_offset; ///< Offset to the first block/chunk
|
||||
gsize chunk_length; ///< Uncompressed chunk length
|
||||
gsize n_chunks; ///< Number of chunks in file
|
||||
guint16 * chunks; ///< Chunk sizes after compression
|
||||
|
||||
z_stream zs; //!< zlib decompression context
|
||||
gpointer input_buffer; //!< Input buffer
|
||||
z_stream zs; ///< zlib decompression context
|
||||
gpointer input_buffer; ///< Input buffer
|
||||
|
||||
goffset offset; //!< Current offset
|
||||
gpointer * decompressed; //!< Array of decompressed chunks
|
||||
gsize last_chunk_length; //!< Size of the last chunk
|
||||
goffset offset; ///< Current offset
|
||||
gpointer * decompressed; ///< Array of decompressed chunks
|
||||
gsize last_chunk_length; ///< Size of the last chunk
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (DictzipInputStream, dictzip_input_stream,
|
||||
|
@ -422,7 +422,7 @@ get_chunk (DictzipInputStream *self, guint chunk_id, GError **error)
|
|||
gpointer chunk = priv->decompressed[chunk_id];
|
||||
if (!chunk)
|
||||
{
|
||||
/* Just inflating the file piece by piece as needed. */
|
||||
// Just inflating the file piece by piece as needed.
|
||||
gsize chunk_size;
|
||||
chunk = inflate_chunk (self, chunk_id, &chunk_size, error);
|
||||
if (!chunk)
|
||||
|
@ -452,8 +452,8 @@ dictzip_input_stream_seek (GSeekable *seekable, goffset offset,
|
|||
|
||||
if (type == G_SEEK_END)
|
||||
{
|
||||
/* This could be implemented by retrieving the last chunk
|
||||
* and deducing the filesize, should the functionality be needed. */
|
||||
// This could be implemented by retrieving the last chunk
|
||||
// and deducing the filesize, should the functionality be needed.
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||
"I don't know where the stream ends, cannot seek there");
|
||||
return FALSE;
|
||||
|
@ -541,7 +541,7 @@ dictzip_input_stream_skip (GInputStream *stream, gsize count,
|
|||
return count;
|
||||
}
|
||||
|
||||
/** Create an input stream for the underlying dictzip file. */
|
||||
/// Create an input stream for the underlying dictzip file.
|
||||
DictzipInputStream *
|
||||
dictzip_input_stream_new (GInputStream *base_stream, GError **error)
|
||||
{
|
||||
|
@ -560,7 +560,7 @@ dictzip_input_stream_new (GInputStream *base_stream, GError **error)
|
|||
"base-stream", base_stream, "close-base-stream", FALSE, NULL);
|
||||
DictzipInputStreamPrivate *priv = self->priv;
|
||||
|
||||
/* Decode the header. */
|
||||
// Decode the header.
|
||||
gz_header gzh;
|
||||
if (!read_gzip_header (G_INPUT_STREAM (base_stream),
|
||||
&gzh, &priv->first_block_offset, &err))
|
||||
|
@ -584,7 +584,7 @@ dictzip_input_stream_new (GInputStream *base_stream, GError **error)
|
|||
goto error;
|
||||
}
|
||||
|
||||
/* Store file information. */
|
||||
// Store file information.
|
||||
priv->file_info = g_file_info_new ();
|
||||
|
||||
if (gzh.time != 0)
|
||||
|
@ -596,7 +596,7 @@ dictzip_input_stream_new (GInputStream *base_stream, GError **error)
|
|||
if (gzh.name && *gzh.name)
|
||||
g_file_info_set_name (priv->file_info, (gchar *) gzh.name);
|
||||
|
||||
/* Initialise zlib. */
|
||||
// Initialise zlib.
|
||||
int z_err;
|
||||
z_err = inflateInit2 (&priv->zs, -15);
|
||||
if (z_err != Z_OK)
|
||||
|
@ -608,7 +608,7 @@ dictzip_input_stream_new (GInputStream *base_stream, GError **error)
|
|||
|
||||
priv->input_buffer = g_malloc (65536);
|
||||
priv->decompressed = g_new0 (gpointer, priv->n_chunks);
|
||||
priv->last_chunk_length = -1; // We don't know yet.
|
||||
priv->last_chunk_length = -1; // We don't know yet.
|
||||
|
||||
free_gzip_header (&gzh);
|
||||
return self;
|
||||
|
@ -619,7 +619,7 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/** Return file information for the compressed file. */
|
||||
/// Return file information for the compressed file.
|
||||
GFileInfo *
|
||||
dictzip_input_stream_get_file_info (DictzipInputStream *self)
|
||||
{
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
#ifndef DICTZIP_INPUT_STREAM_H
|
||||
#define DICTZIP_INPUT_STREAM_H
|
||||
|
||||
/** Random-access dictzip reader. */
|
||||
/// Random-access dictzip reader.
|
||||
typedef struct dictzip_input_stream DictzipInputStream;
|
||||
typedef struct dictzip_input_stream_class DictzipInputStreamClass;
|
||||
typedef struct dictzip_input_stream_private DictzipInputStreamPrivate;
|
||||
|
||||
/* GObject boilerplate. */
|
||||
// GObject boilerplate.
|
||||
#define DICTZIP_TYPE_INPUT_STREAM (dictzip_input_stream_get_type ())
|
||||
#define DICTZIP_INPUT_STREAM(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
|
@ -74,4 +74,4 @@ DictzipInputStream *dictzip_input_stream_new
|
|||
GFileInfo *dictzip_input_stream_get_file_info (DictzipInputStream *self);
|
||||
|
||||
|
||||
#endif /* ! DICTZIP_INPUT_STREAM_H */
|
||||
#endif // ! DICTZIP_INPUT_STREAM_H
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "generator.h"
|
||||
|
||||
|
||||
/** Creates an output stream for a path plus suffix. */
|
||||
/// Creates an output stream for a path plus suffix.
|
||||
static GFileOutputStream *
|
||||
replace_file_by_suffix (const gchar *base, const gchar *suffix, GError **error)
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ replace_file_by_suffix (const gchar *base, const gchar *suffix, GError **error)
|
|||
return stream;
|
||||
}
|
||||
|
||||
/** Creates a Stardict dictionary generator for the specified base. */
|
||||
/// Creates a Stardict dictionary generator for the specified basename.
|
||||
Generator *
|
||||
generator_new (const gchar *base, GError **error)
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ error_dict:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/** Finishes the dictionary and writes the .ifo file. */
|
||||
/// Finishes the dictionary and writes the .ifo file.
|
||||
gboolean
|
||||
generator_finish (Generator *self, GError **error)
|
||||
{
|
||||
|
@ -132,21 +132,21 @@ generator_finish (Generator *self, GError **error)
|
|||
return success;
|
||||
}
|
||||
|
||||
/** Start writing a dictionary entry. */
|
||||
/// Start writing a dictionary entry.
|
||||
void
|
||||
generator_begin_entry (Generator *self)
|
||||
{
|
||||
self->entry_mark = g_seekable_tell (G_SEEKABLE (self->dict_stream));
|
||||
}
|
||||
|
||||
/** Write the data type of an entry field, when there's no sametypesequence. */
|
||||
/// Write the data type of an entry field, when there's no sametypesequence.
|
||||
gboolean
|
||||
generator_write_type (Generator *self, gchar type, GError **error)
|
||||
{
|
||||
return g_data_output_stream_put_byte (self->dict_data, type, NULL, error);
|
||||
}
|
||||
|
||||
/** Write a raw binary field. */
|
||||
/// Write a raw binary field.
|
||||
gboolean
|
||||
generator_write_raw (Generator *self,
|
||||
gpointer data, gsize data_size, gboolean mark_end, GError **error)
|
||||
|
@ -160,7 +160,7 @@ generator_write_raw (Generator *self,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/** Write a text string. */
|
||||
/// Write a text string.
|
||||
gboolean
|
||||
generator_write_string (Generator *self,
|
||||
const gchar *s, gboolean mark_end, GError **error)
|
||||
|
@ -172,7 +172,7 @@ generator_write_string (Generator *self,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/** Finishes the current entry and writes it into the index. */
|
||||
/// Finishes the current entry and writes it into the index.
|
||||
gboolean
|
||||
generator_finish_entry (Generator *self, const gchar *word, GError **error)
|
||||
{
|
||||
|
@ -189,7 +189,7 @@ generator_finish_entry (Generator *self, const gchar *word, GError **error)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/** Destroys the generator object, freeing up system resources. */
|
||||
/// Destroys the generator object, freeing up system resources.
|
||||
void
|
||||
generator_free (Generator *self)
|
||||
{
|
||||
|
|
|
@ -24,20 +24,20 @@
|
|||
#ifndef GENERATOR_H
|
||||
#define GENERATOR_H
|
||||
|
||||
/** Simplifies the task of creating a StarDict dictionary. */
|
||||
/// Simplifies the task of creating a StarDict dictionary.
|
||||
typedef struct generator Generator;
|
||||
|
||||
struct generator
|
||||
{
|
||||
StardictInfo * info; //!< Dictionary information, fill it in
|
||||
StardictInfo * info; ///< Dictionary information, fill it in
|
||||
|
||||
goffset entry_mark; //!< Marks the entry's start offset
|
||||
goffset entry_mark; ///< Marks the entry's start offset
|
||||
|
||||
GFileOutputStream * dict_stream; //!< Dictionary stream
|
||||
GDataOutputStream * dict_data; //!< Dictionary data stream wrapper
|
||||
GFileOutputStream * dict_stream; ///< Dictionary stream
|
||||
GDataOutputStream * dict_data; ///< Dictionary data stream wrapper
|
||||
|
||||
GFileOutputStream * idx_stream; //!< Index file stream
|
||||
GDataOutputStream * idx_data; //!< Index file data stream wrapper
|
||||
GFileOutputStream * idx_stream; ///< Index file stream
|
||||
GDataOutputStream * idx_data; ///< Index file data stream wrapper
|
||||
};
|
||||
|
||||
Generator *generator_new (const gchar *base, GError **error);
|
||||
|
@ -53,4 +53,4 @@ gboolean generator_write_string (Generator *self,
|
|||
gboolean generator_finish_entry (Generator *self,
|
||||
const gchar *word, GError **error);
|
||||
|
||||
#endif /* ! GENERATOR_H */
|
||||
#endif // ! GENERATOR_H
|
||||
|
|
131
src/sdtui.c
131
src/sdtui.c
|
@ -48,7 +48,7 @@
|
|||
|
||||
#define CTRL_KEY(x) ((x) - 'A' + 1)
|
||||
|
||||
#define TOP_BAR_CUTOFF 2 //!< How many lines are reserved on top
|
||||
#define TOP_BAR_CUTOFF 2 ///< How many lines are reserved on top
|
||||
|
||||
// --- Utilities ---------------------------------------------------------------
|
||||
|
||||
|
@ -62,55 +62,55 @@ unichar_width (gunichar ch)
|
|||
|
||||
// --- Application -------------------------------------------------------------
|
||||
|
||||
/** Data relating to one entry within the dictionary. */
|
||||
/// Data relating to one entry within the dictionary.
|
||||
typedef struct view_entry ViewEntry;
|
||||
/** Encloses application data. */
|
||||
/// Encloses application data.
|
||||
typedef struct application Application;
|
||||
/** Application options. */
|
||||
/// Application options.
|
||||
typedef struct app_options AppOptions;
|
||||
|
||||
struct view_entry
|
||||
{
|
||||
gchar * word; //!< Word
|
||||
gchar ** definitions; //!< Word definition entries
|
||||
gsize definitions_length; //!< Length of the @a definitions array
|
||||
gchar * word; ///< Word
|
||||
gchar ** definitions; ///< Word definition entries
|
||||
gsize definitions_length; ///< Length of the @a definitions array
|
||||
};
|
||||
|
||||
struct application
|
||||
{
|
||||
GMainLoop * loop; //!< Main loop
|
||||
termo_t * tk; //!< termo handle
|
||||
guint tk_timer; //!< termo timeout timer
|
||||
GIConv ucs4_to_locale; //!< UTF-32 -> locale conversion
|
||||
gboolean locale_is_utf8; //!< The locale is Unicode
|
||||
GMainLoop * loop; ///< Main loop
|
||||
termo_t * tk; ///< termo handle
|
||||
guint tk_timer; ///< termo timeout timer
|
||||
GIConv ucs4_to_locale; ///< UTF-32 -> locale conversion
|
||||
gboolean locale_is_utf8; ///< The locale is Unicode
|
||||
|
||||
StardictDict * dict; //!< The current dictionary
|
||||
guint show_help : 1; //!< Whether help can be shown
|
||||
StardictDict * dict; ///< The current dictionary
|
||||
guint show_help : 1; ///< Whether help can be shown
|
||||
|
||||
guint32 top_position; //!< Index of the topmost dict. entry
|
||||
guint top_offset; //!< Offset into the top entry
|
||||
guint selected; //!< Offset to the selected definition
|
||||
GPtrArray * entries; //!< ViewEntry's within the view
|
||||
guint32 top_position; ///< Index of the topmost dict. entry
|
||||
guint top_offset; ///< Offset into the top entry
|
||||
guint selected; ///< Offset to the selected definition
|
||||
GPtrArray * entries; ///< ViewEntry's within the view
|
||||
|
||||
gchar * search_label; //!< Text of the "Search" label
|
||||
GArray * input; //!< The current search input
|
||||
guint input_pos; //!< Cursor position within input
|
||||
gboolean input_confirmed; //!< Input has been confirmed
|
||||
gchar * search_label; ///< Text of the "Search" label
|
||||
GArray * input; ///< The current search input
|
||||
guint input_pos; ///< Cursor position within input
|
||||
gboolean input_confirmed; ///< Input has been confirmed
|
||||
|
||||
gfloat division; //!< Position of the division column
|
||||
gfloat division; ///< Position of the division column
|
||||
|
||||
guint selection_timer; //!< Selection watcher timeout timer
|
||||
gint selection_interval; //!< Selection watcher timer interval
|
||||
gchar * selection_contents; //!< Selection contents
|
||||
guint selection_timer; ///< Selection watcher timeout timer
|
||||
gint selection_interval; ///< Selection watcher timer interval
|
||||
gchar * selection_contents; ///< Selection contents
|
||||
};
|
||||
|
||||
struct app_options
|
||||
{
|
||||
gboolean show_version; //!< Output version information and quit
|
||||
gint selection_watcher; //!< Interval in milliseconds, or -1
|
||||
gboolean show_version; ///< Output version information and quit
|
||||
gint selection_watcher; ///< Interval in milliseconds, or -1
|
||||
};
|
||||
|
||||
/** Splits the entry and adds it to a pointer array. */
|
||||
/// Splits the entry and adds it to a pointer array.
|
||||
static void
|
||||
view_entry_split_add (GPtrArray *out, const gchar *text)
|
||||
{
|
||||
|
@ -121,7 +121,7 @@ view_entry_split_add (GPtrArray *out, const gchar *text)
|
|||
g_strfreev (tmp);
|
||||
}
|
||||
|
||||
/** Decomposes a dictionary entry into the format we want. */
|
||||
/// Decomposes a dictionary entry into the format we want.
|
||||
static ViewEntry *
|
||||
view_entry_new (StardictIterator *iterator)
|
||||
{
|
||||
|
@ -178,7 +178,7 @@ view_entry_new (StardictIterator *iterator)
|
|||
return ve;
|
||||
}
|
||||
|
||||
/** Release resources associated with the view entry. */
|
||||
/// Release resources associated with the view entry.
|
||||
static void
|
||||
view_entry_free (ViewEntry *ve)
|
||||
{
|
||||
|
@ -187,7 +187,7 @@ view_entry_free (ViewEntry *ve)
|
|||
g_slice_free1 (sizeof *ve, ve);
|
||||
}
|
||||
|
||||
/** Reload view items. */
|
||||
/// Reload view items.
|
||||
static void
|
||||
app_reload_view (Application *self)
|
||||
{
|
||||
|
@ -219,7 +219,7 @@ rearm_selection_watcher (Application *self)
|
|||
}
|
||||
#endif // WITH_GTK
|
||||
|
||||
/** Initialize the application core. */
|
||||
/// Initialize the application core.
|
||||
static void
|
||||
app_init (Application *self, AppOptions *options, const gchar *filename)
|
||||
{
|
||||
|
@ -274,7 +274,7 @@ app_init (Application *self, AppOptions *options, const gchar *filename)
|
|||
app_reload_view (self);
|
||||
}
|
||||
|
||||
/** Free any resources used by the application. */
|
||||
/// Free any resources used by the application.
|
||||
static void
|
||||
app_destroy (Application *self)
|
||||
{
|
||||
|
@ -297,7 +297,7 @@ app_destroy (Application *self)
|
|||
g_iconv_close (self->ucs4_to_locale);
|
||||
}
|
||||
|
||||
/** Run the main event dispatch loop. */
|
||||
/// Run the main event dispatch loop.
|
||||
static void
|
||||
app_run (Application *self)
|
||||
{
|
||||
|
@ -309,7 +309,7 @@ app_run (Application *self)
|
|||
#endif // WITH_GTK
|
||||
}
|
||||
|
||||
/** Quit the main event dispatch loop. */
|
||||
/// Quit the main event dispatch loop.
|
||||
static void
|
||||
app_quit (Application *self)
|
||||
{
|
||||
|
@ -321,7 +321,7 @@ app_quit (Application *self)
|
|||
#endif // WITH_GTK
|
||||
}
|
||||
|
||||
/** Returns if the Unicode character is representable in the current locale. */
|
||||
/// Returns if the Unicode character is representable in the current locale.
|
||||
static gboolean
|
||||
app_is_character_in_locale (Application *self, gunichar ch)
|
||||
{
|
||||
|
@ -337,12 +337,11 @@ app_is_character_in_locale (Application *self, gunichar ch)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/** Write the given UTF-8 string padded with spaces.
|
||||
* @param[in] n The number of characters to write, or -1 for the whole string.
|
||||
* @param[in] attrs Text attributes for the text, without padding.
|
||||
* To change the attributes of all output, use attrset().
|
||||
* @return The number of characters output.
|
||||
*/
|
||||
/// Write the given UTF-8 string padded with spaces.
|
||||
/// @param[in] n The number of characters to write, or -1 for the whole string.
|
||||
/// @param[in] attrs Text attributes for the text, without padding.
|
||||
/// To change the attributes of all output, use attrset().
|
||||
/// @return The number of characters output.
|
||||
static gsize
|
||||
app_add_utf8_string (Application *self, const gchar *str, int attrs, int n)
|
||||
{
|
||||
|
@ -412,7 +411,7 @@ app_add_utf8_string (Application *self, const gchar *str, int attrs, int n)
|
|||
return n;
|
||||
}
|
||||
|
||||
/** Render the top bar. */
|
||||
/// Render the top bar.
|
||||
static void
|
||||
app_redraw_top (Application *self)
|
||||
{
|
||||
|
@ -445,7 +444,7 @@ app_redraw_top (Application *self)
|
|||
refresh ();
|
||||
}
|
||||
|
||||
/** Computes width for the left column. */
|
||||
/// Computes width for the left column.
|
||||
static guint
|
||||
app_get_left_column_width (Application *self)
|
||||
{
|
||||
|
@ -457,7 +456,7 @@ app_get_left_column_width (Application *self)
|
|||
return width;
|
||||
}
|
||||
|
||||
/** Display a message in the view area. */
|
||||
/// Display a message in the view area.
|
||||
static void
|
||||
app_show_message (Application *self, const gchar *lines[], gsize len)
|
||||
{
|
||||
|
@ -491,7 +490,7 @@ app_show_message (Application *self, const gchar *lines[], gsize len)
|
|||
refresh ();
|
||||
}
|
||||
|
||||
/** Show some information about the program. */
|
||||
/// Show some information about the program.
|
||||
static void
|
||||
app_show_help (Application *self)
|
||||
{
|
||||
|
@ -507,7 +506,7 @@ app_show_help (Application *self)
|
|||
app_show_message (self, lines, G_N_ELEMENTS (lines));
|
||||
}
|
||||
|
||||
/** Redraw the dictionary view. */
|
||||
/// Redraw the dictionary view.
|
||||
static void
|
||||
app_redraw_view (Application *self)
|
||||
{
|
||||
|
@ -549,7 +548,7 @@ done:
|
|||
refresh ();
|
||||
}
|
||||
|
||||
/** Just prepends a new view entry into the entries array. */
|
||||
/// Just prepends a new view entry into the entries array.
|
||||
static ViewEntry *
|
||||
prepend_entry (Application *self, guint32 position)
|
||||
{
|
||||
|
@ -563,7 +562,7 @@ prepend_entry (Application *self, guint32 position)
|
|||
return g_ptr_array_index (self->entries, 0) = ve;
|
||||
}
|
||||
|
||||
/** Just appends a new view entry to the entries array. */
|
||||
/// Just appends a new view entry to the entries array.
|
||||
static ViewEntry *
|
||||
append_entry (Application *self, guint32 position)
|
||||
{
|
||||
|
@ -579,7 +578,7 @@ append_entry (Application *self, guint32 position)
|
|||
return ve;
|
||||
}
|
||||
|
||||
/** Counts the number of definitions available for seeing. */
|
||||
/// Counts the number of definitions available for seeing.
|
||||
static guint
|
||||
app_count_view_items (Application *self)
|
||||
{
|
||||
|
@ -592,7 +591,7 @@ app_count_view_items (Application *self)
|
|||
return n_definitions;
|
||||
}
|
||||
|
||||
/** Scroll up @a n entries. */
|
||||
/// Scroll up @a n entries.
|
||||
static gboolean
|
||||
app_scroll_up (Application *self, guint n)
|
||||
{
|
||||
|
@ -606,7 +605,7 @@ app_scroll_up (Application *self, guint n)
|
|||
continue;
|
||||
}
|
||||
|
||||
/* We've reached the top */
|
||||
// We've reached the top
|
||||
if (self->top_position == 0)
|
||||
{
|
||||
success = FALSE;
|
||||
|
@ -617,7 +616,7 @@ app_scroll_up (Application *self, guint n)
|
|||
self->top_offset = ve->definitions_length - 1;
|
||||
n_definitions += ve->definitions_length;
|
||||
|
||||
/* Remove the last entry if not shown */
|
||||
// Remove the last entry if not shown
|
||||
ViewEntry *last_entry =
|
||||
g_ptr_array_index (self->entries, self->entries->len - 1);
|
||||
if ((gint) (n_definitions - self->top_offset
|
||||
|
@ -633,7 +632,7 @@ app_scroll_up (Application *self, guint n)
|
|||
return success;
|
||||
}
|
||||
|
||||
/** Scroll down @a n entries. */
|
||||
/// Scroll down @a n entries.
|
||||
static gboolean
|
||||
app_scroll_down (Application *self, guint n)
|
||||
{
|
||||
|
@ -667,7 +666,7 @@ app_scroll_down (Application *self, guint n)
|
|||
}
|
||||
}
|
||||
|
||||
/* Fix cursor to not point below the view items */
|
||||
// Fix cursor to not point below the view items
|
||||
if (self->selected >= n_definitions - self->top_offset)
|
||||
self->selected = n_definitions - self->top_offset - 1;
|
||||
|
||||
|
@ -675,7 +674,7 @@ app_scroll_down (Application *self, guint n)
|
|||
return success;
|
||||
}
|
||||
|
||||
/** Moves the selection one entry up. */
|
||||
/// Moves the selection one entry up.
|
||||
static gboolean
|
||||
app_one_entry_up (Application *self)
|
||||
{
|
||||
|
@ -711,7 +710,7 @@ app_one_entry_up (Application *self)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/** Moves the selection one entry down. */
|
||||
/// Moves the selection one entry down.
|
||||
static void
|
||||
app_one_entry_down (Application *self)
|
||||
{
|
||||
|
@ -738,7 +737,7 @@ app_one_entry_down (Application *self)
|
|||
}
|
||||
}
|
||||
|
||||
/** Redraw everything. */
|
||||
/// Redraw everything.
|
||||
static void
|
||||
app_redraw (Application *self)
|
||||
{
|
||||
|
@ -746,7 +745,7 @@ app_redraw (Application *self)
|
|||
app_redraw_top (self);
|
||||
}
|
||||
|
||||
/** Search for the current entry. */
|
||||
/// Search for the current entry.
|
||||
static void
|
||||
app_search_for_entry (Application *self)
|
||||
{
|
||||
|
@ -776,7 +775,7 @@ app_search_for_entry (Application *self)
|
|||
move (last_y, last_x); \
|
||||
refresh ();
|
||||
|
||||
/** The terminal has been resized, make appropriate changes. */
|
||||
/// The terminal has been resized, make appropriate changes.
|
||||
static gboolean
|
||||
app_process_resize (Application *self)
|
||||
{
|
||||
|
@ -798,7 +797,7 @@ app_process_resize (Application *self)
|
|||
|
||||
// --- User input handling -----------------------------------------------------
|
||||
|
||||
/** All the actions that can be performed by the user. */
|
||||
/// All the actions that can be performed by the user.
|
||||
typedef enum user_action UserAction;
|
||||
|
||||
enum user_action
|
||||
|
@ -1160,7 +1159,7 @@ app_process_left_mouse_click (Application *self, int line, int column)
|
|||
}
|
||||
}
|
||||
|
||||
/** Process mouse input. */
|
||||
/// Process mouse input.
|
||||
static gboolean
|
||||
app_process_mouse (Application *self, termo_key_t *event)
|
||||
{
|
||||
|
@ -1181,7 +1180,7 @@ app_process_mouse (Application *self, termo_key_t *event)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/** Process input events from the terminal. */
|
||||
/// Process input events from the terminal.
|
||||
static gboolean
|
||||
app_process_termo_event (Application *self, termo_key_t *event)
|
||||
{
|
||||
|
@ -1200,7 +1199,7 @@ app_process_termo_event (Application *self, termo_key_t *event)
|
|||
|
||||
// --- SIGWINCH ----------------------------------------------------------------
|
||||
|
||||
static int g_winch_pipe[2]; /**< SIGWINCH signalling pipe. */
|
||||
static int g_winch_pipe[2]; ///< SIGWINCH signalling pipe.
|
||||
|
||||
static void
|
||||
winch_handler (int signum)
|
||||
|
@ -1456,7 +1455,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
|
||||
app_redraw (&app);
|
||||
|
||||
/* Message loop. */
|
||||
// Message loop.
|
||||
g_io_add_watch (g_io_channel_unix_new (STDIN_FILENO),
|
||||
G_IO_IN, process_stdin_input, &app);
|
||||
g_io_add_watch (g_io_channel_unix_new (g_winch_pipe[0]),
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
#ifndef STARDICTPRIVATE_H
|
||||
#define STARDICTPRIVATE_H
|
||||
|
||||
/** Describes a single entry in the dictionary index. */
|
||||
/// Describes a single entry in the dictionary index.
|
||||
typedef struct stardict_index_entry StardictIndexEntry;
|
||||
|
||||
/** Describes a single entry in the synonyms index. */
|
||||
/// Describes a single entry in the synonyms index.
|
||||
typedef struct stardict_synonym_entry StardictSynonymEntry;
|
||||
|
||||
|
||||
|
@ -53,31 +53,31 @@ struct stardict_info
|
|||
|
||||
struct stardict_index_entry
|
||||
{
|
||||
gchar * name; //!< The word in utf-8
|
||||
guint64 data_offset; //!< Offset of the definition
|
||||
guint32 data_size; //!< Size of the definition
|
||||
gchar * name; ///< The word in utf-8
|
||||
guint64 data_offset; ///< Offset of the definition
|
||||
guint32 data_size; ///< Size of the definition
|
||||
};
|
||||
|
||||
struct stardict_synonym_entry
|
||||
{
|
||||
gchar * word; //!< A synonymous word
|
||||
guint32 original_word; //!< The original word's index
|
||||
gchar * word; ///< A synonymous word
|
||||
guint32 original_word; ///< The original word's index
|
||||
};
|
||||
|
||||
struct stardict_ifo_key
|
||||
{
|
||||
const gchar *name; //!< Name of the key
|
||||
const gchar *name; ///< Name of the key
|
||||
enum {
|
||||
IFO_STRING, //!< A @code gchar * @endcode value
|
||||
IFO_NUMBER //!< A @code gulong @endcode value
|
||||
} type; //!< Type of the value
|
||||
size_t offset; //!< Offset within StardictInfo
|
||||
IFO_STRING, ///< A @code gchar * @endcode value
|
||||
IFO_NUMBER ///< A @code gulong @endcode value
|
||||
} type; ///< Type of the value
|
||||
size_t offset; ///< Offset within StardictInfo
|
||||
};
|
||||
|
||||
/** Lists all the entries in StardictInfo. */
|
||||
/// Lists all the entries in StardictInfo.
|
||||
extern const struct stardict_ifo_key _stardict_ifo_keys[];
|
||||
|
||||
/** Denotes the length of _stardict_ifo_keys. */
|
||||
/// Denotes the length of _stardict_ifo_keys.
|
||||
extern gsize _stardict_ifo_keys_length;
|
||||
|
||||
#endif /* ! STARDICTPRIVATE_H */
|
||||
#endif // ! STARDICTPRIVATE_H
|
||||
|
|
115
src/stardict.c
115
src/stardict.c
|
@ -42,7 +42,7 @@
|
|||
|
||||
// --- Utilities ---------------------------------------------------------------
|
||||
|
||||
/** String compare function used for StarDict indexes. */
|
||||
/// String compare function used for StarDict indexes.
|
||||
static inline gint
|
||||
stardict_strcmp (const gchar *s1, const gchar *s2)
|
||||
{
|
||||
|
@ -60,18 +60,18 @@ stardict_error_quark (void)
|
|||
|
||||
// --- IFO reader --------------------------------------------------------------
|
||||
|
||||
/** Helper class for reading .ifo files. */
|
||||
/// Helper class for reading .ifo files.
|
||||
typedef struct ifo_reader IfoReader;
|
||||
|
||||
struct ifo_reader
|
||||
{
|
||||
gchar * data; //!< File data terminated with \0
|
||||
gchar * data_end; //!< Where the final \0 char. is
|
||||
gchar * data; ///< File data terminated with \0
|
||||
gchar * data_end; ///< Where the final \0 char. is
|
||||
|
||||
gchar * start; //!< Start of the current token
|
||||
gchar * start; ///< Start of the current token
|
||||
|
||||
gchar * key; //!< The key (points into @a data)
|
||||
gchar * value; //!< The value (points into @a data)
|
||||
gchar * key; ///< The key (points into @a data)
|
||||
gchar * value; ///< The value (points into @a data)
|
||||
};
|
||||
|
||||
static gboolean
|
||||
|
@ -148,31 +148,30 @@ ifo_reader_read (IfoReader *ir)
|
|||
|
||||
// --- StardictInfo ------------------------------------------------------------
|
||||
|
||||
/** Return the filesystem path for the dictionary. */
|
||||
/// Return the filesystem path for the dictionary.
|
||||
const gchar *
|
||||
stardict_info_get_path (StardictInfo *sdi)
|
||||
{
|
||||
return sdi->path;
|
||||
}
|
||||
|
||||
/** Return the name of the dictionary. */
|
||||
/// Return the name of the dictionary.
|
||||
const gchar *
|
||||
stardict_info_get_book_name (StardictInfo *sdi)
|
||||
{
|
||||
return sdi->book_name;
|
||||
}
|
||||
|
||||
/** Return the word count of the dictionary. Note that this information comes
|
||||
* from the .ifo file, while the dictionary could successfully load with
|
||||
* a different count of word entries.
|
||||
*/
|
||||
/// Return the word count of the dictionary. Note that this information comes
|
||||
/// from the .ifo file, while the dictionary could successfully load with
|
||||
/// a different count of word entries.
|
||||
gsize
|
||||
stardict_info_get_word_count (StardictInfo *sdi)
|
||||
{
|
||||
return sdi->word_count;
|
||||
}
|
||||
|
||||
/** Destroy the dictionary info object. */
|
||||
/// Destroy the dictionary info object.
|
||||
void
|
||||
stardict_info_free (StardictInfo *sdi)
|
||||
{
|
||||
|
@ -328,12 +327,11 @@ error:
|
|||
return ret_val;
|
||||
}
|
||||
|
||||
/** List all dictionary files located in a path.
|
||||
* @return GList<StardictInfo *>. Deallocate the list with:
|
||||
* @code
|
||||
* g_list_free_full ((GDestroyNotify) stardict_info_free);
|
||||
* @endcode
|
||||
*/
|
||||
/// List all dictionary files located in a path.
|
||||
/// @return GList<StardictInfo *>. Deallocate the list with:
|
||||
/// @code
|
||||
/// g_list_free_full ((GDestroyNotify) stardict_info_free);
|
||||
/// @endcode
|
||||
GList *
|
||||
stardict_list_dictionaries (const gchar *path)
|
||||
{
|
||||
|
@ -369,18 +367,17 @@ struct stardict_dict_private
|
|||
GArray * index; //!< Word index
|
||||
GArray * synonyms; //!< Synonyms
|
||||
|
||||
/* The collated indexes are only permutations of their normal selves. */
|
||||
// The collated indexes are only permutations of their normal selves.
|
||||
|
||||
UCollator * collator; //!< ICU index collator
|
||||
GArray * collated_index; //!< Sorted indexes into @a index
|
||||
GArray * collated_synonyms; //!< Sorted indexes into @a synonyms
|
||||
|
||||
/* There are currently three ways the dictionary data can be read:
|
||||
* through mmap(), from a seekable GInputStream, or from a preallocated
|
||||
* chunk of memory that the whole dictionary has been decompressed into.
|
||||
*
|
||||
* It wouldn't be unreasonable to drop the support for regular gzip files.
|
||||
*/
|
||||
// There are currently three ways the dictionary data can be read:
|
||||
// through mmap(), from a seekable GInputStream, or from a preallocated
|
||||
// chunk of memory that the whole dictionary has been decompressed into.
|
||||
//
|
||||
// It wouldn't be unreasonable to drop the support for regular gzip files.
|
||||
|
||||
GInputStream * dict_stream; //!< Dictionary input stream handle
|
||||
GMappedFile * mapped_dict; //!< Dictionary memory map handle
|
||||
|
@ -432,9 +429,8 @@ stardict_dict_init (StardictDict *self)
|
|||
STARDICT_TYPE_DICT, StardictDictPrivate);
|
||||
}
|
||||
|
||||
/** Load a StarDict dictionary.
|
||||
* @param[in] filename Path to the .ifo file
|
||||
*/
|
||||
/// Load a StarDict dictionary.
|
||||
/// @param[in] filename Path to the .ifo file
|
||||
StardictDict *
|
||||
stardict_dict_new (const gchar *filename, GError **error)
|
||||
{
|
||||
|
@ -450,9 +446,8 @@ stardict_dict_new (const gchar *filename, GError **error)
|
|||
return sd;
|
||||
}
|
||||
|
||||
/** Return information about a loaded dictionary. The returned reference is
|
||||
* only valid for the lifetime of the dictionary object.
|
||||
*/
|
||||
/// Return information about a loaded dictionary. The returned reference is
|
||||
/// only valid for the lifetime of the dictionary object.
|
||||
StardictInfo *
|
||||
stardict_dict_get_info (StardictDict *sd)
|
||||
{
|
||||
|
@ -460,7 +455,7 @@ stardict_dict_get_info (StardictDict *sd)
|
|||
return sd->priv->info;
|
||||
}
|
||||
|
||||
/** Load a StarDict index from a GIO input stream. */
|
||||
/// Load a StarDict index from a GIO input stream.
|
||||
static gboolean
|
||||
load_idx_internal (StardictDict *sd, GInputStream *is, GError **error)
|
||||
{
|
||||
|
@ -503,7 +498,7 @@ error:
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/** Load a StarDict index. */
|
||||
/// Load a StarDict index.
|
||||
static gboolean
|
||||
load_idx (StardictDict *sd, const gchar *filename,
|
||||
gboolean gzipped, GError **error)
|
||||
|
@ -577,7 +572,7 @@ cannot_open:
|
|||
return ret_val;
|
||||
}
|
||||
|
||||
/** Destroy an index entry. */
|
||||
/// Destroy an index entry.
|
||||
static void
|
||||
index_destroy_cb (gpointer sde)
|
||||
{
|
||||
|
@ -585,7 +580,7 @@ index_destroy_cb (gpointer sde)
|
|||
g_free (e->name);
|
||||
}
|
||||
|
||||
/** Destroy a synonym entry. */
|
||||
/// Destroy a synonym entry.
|
||||
static void
|
||||
syn_destroy_cb (gpointer sde)
|
||||
{
|
||||
|
@ -593,7 +588,7 @@ syn_destroy_cb (gpointer sde)
|
|||
g_free (e->word);
|
||||
}
|
||||
|
||||
/** Load StarDict dictionary data. */
|
||||
/// Load StarDict dictionary data.
|
||||
static gboolean
|
||||
load_dict (StardictDict *sd, const gchar *filename, gboolean gzipped,
|
||||
GError **error)
|
||||
|
@ -667,7 +662,7 @@ cannot_open:
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
/** Compare the two strings by collation rules. */
|
||||
/// Compare the two strings by collation rules.
|
||||
static inline gint
|
||||
stardict_dict_strcoll (gconstpointer s1, gconstpointer s2, gpointer data)
|
||||
{
|
||||
|
@ -699,7 +694,7 @@ stardict_dict_strcoll (gconstpointer s1, gconstpointer s2, gpointer data)
|
|||
#endif // U_ICU_VERSION_MAJOR_NUM >= 50
|
||||
}
|
||||
|
||||
/** Stricter stardict_dict_strcoll() used to sort the collated index. */
|
||||
/// Stricter stardict_dict_strcoll() used to sort the collated index.
|
||||
static inline gint
|
||||
stardict_dict_strcoll_for_sorting
|
||||
(gconstpointer s1, gconstpointer s2, gpointer data)
|
||||
|
@ -772,9 +767,8 @@ stardict_dict_set_collation (StardictDict *sd, const gchar *collation)
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
/** Load a StarDict dictionary.
|
||||
* @param[in] sdi Parsed .ifo data. The dictionary assumes ownership.
|
||||
*/
|
||||
/// Load a StarDict dictionary.
|
||||
/// @param[in] sdi Parsed .ifo data. The dictionary assumes ownership.
|
||||
StardictDict *
|
||||
stardict_dict_new_from_info (StardictInfo *sdi, GError **error)
|
||||
{
|
||||
|
@ -870,9 +864,8 @@ stardict_dict_cmp_synonym (StardictDict *sd, const gchar *word, gint i)
|
|||
g_array_index (synonyms, StardictSynonymEntry, i).word);
|
||||
}
|
||||
|
||||
/** Return words for which the argument is a synonym of or NULL
|
||||
* if there are no such words.
|
||||
*/
|
||||
/// Return words for which the argument is a synonym of or NULL
|
||||
/// if there are no such words.
|
||||
gchar **
|
||||
stardict_dict_get_synonyms (StardictDict *sd, const gchar *word)
|
||||
{
|
||||
|
@ -916,11 +909,10 @@ stardict_dict_cmp_index (StardictDict *sd, const gchar *word, gint i)
|
|||
g_array_index (index, StardictIndexEntry, i).name);
|
||||
}
|
||||
|
||||
/** Search for a word. The search is ASCII-case-insensitive.
|
||||
* @param[in] word The word in utf-8 encoding
|
||||
* @param[out] success TRUE if found
|
||||
* @return An iterator object pointing to the word, or where it would be
|
||||
*/
|
||||
/// Search for a word. The search is ASCII-case-insensitive.
|
||||
/// @param[in] word The word in utf-8 encoding
|
||||
/// @param[out] success TRUE if found
|
||||
/// @return An iterator object pointing to the word, or where it would be
|
||||
StardictIterator *
|
||||
stardict_dict_search (StardictDict *sd, const gchar *word, gboolean *success)
|
||||
{
|
||||
|
@ -1053,7 +1045,7 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/** Read entry data from GInputStream. */
|
||||
/// Read entry data from GInputStream.
|
||||
static gchar *
|
||||
read_entry_data_from_stream
|
||||
(GInputStream *stream, guint32 offset, StardictIndexEntry *sie)
|
||||
|
@ -1089,7 +1081,7 @@ read_entry_data_from_stream
|
|||
return data;
|
||||
}
|
||||
|
||||
/** Return the data for the specified offset in the index. Unsafe. */
|
||||
/// Return the data for the specified offset in the index. Unsafe.
|
||||
static StardictEntry *
|
||||
stardict_dict_get_entry (StardictDict *sd, guint32 offset)
|
||||
{
|
||||
|
@ -1164,9 +1156,8 @@ stardict_entry_init (G_GNUC_UNUSED StardictEntry *sde)
|
|||
{
|
||||
}
|
||||
|
||||
/** Return the entries present within the entry.
|
||||
* @return GList<StardictEntryField *>
|
||||
*/
|
||||
/// Return the entries present within the entry.
|
||||
/// @return GList<StardictEntryField *>
|
||||
const GList *
|
||||
stardict_entry_get_fields (StardictEntry *sde)
|
||||
{
|
||||
|
@ -1199,7 +1190,7 @@ stardict_iterator_init (G_GNUC_UNUSED StardictIterator *sd)
|
|||
{
|
||||
}
|
||||
|
||||
/** Create a new iterator for the dictionary with offset @a offset. */
|
||||
/// Create a new iterator for the dictionary with offset @a offset.
|
||||
StardictIterator *
|
||||
stardict_iterator_new (StardictDict *sd, guint32 offset)
|
||||
{
|
||||
|
@ -1218,7 +1209,7 @@ stardict_iterator_get_real_offset (StardictIterator *sdi)
|
|||
(sdi->owner->priv->collated_index, guint32, sdi->offset) : sdi->offset;
|
||||
}
|
||||
|
||||
/** Return the word in the index that the iterator points at, or NULL. */
|
||||
/// Return the word in the index that the iterator points at, or NULL.
|
||||
const gchar *
|
||||
stardict_iterator_get_word (StardictIterator *sdi)
|
||||
{
|
||||
|
@ -1229,7 +1220,7 @@ stardict_iterator_get_word (StardictIterator *sdi)
|
|||
StardictIndexEntry, stardict_iterator_get_real_offset (sdi)).name;
|
||||
}
|
||||
|
||||
/** Return the dictionary entry that the iterator points at, or NULL. */
|
||||
/// Return the dictionary entry that the iterator points at, or NULL.
|
||||
StardictEntry *
|
||||
stardict_iterator_get_entry (StardictIterator *sdi)
|
||||
{
|
||||
|
@ -1240,7 +1231,7 @@ stardict_iterator_get_entry (StardictIterator *sdi)
|
|||
stardict_iterator_get_real_offset (sdi));
|
||||
}
|
||||
|
||||
/** Return whether the iterator points to a valid index entry. */
|
||||
/// Return whether the iterator points to a valid index entry.
|
||||
gboolean
|
||||
stardict_iterator_is_valid (StardictIterator *sdi)
|
||||
{
|
||||
|
@ -1248,7 +1239,7 @@ stardict_iterator_is_valid (StardictIterator *sdi)
|
|||
return sdi->offset >= 0 && sdi->offset < sdi->owner->priv->index->len;
|
||||
}
|
||||
|
||||
/** Return the offset of the iterator within the dictionary index. */
|
||||
/// Return the offset of the iterator within the dictionary index.
|
||||
gint64
|
||||
stardict_iterator_get_offset (StardictIterator *sdi)
|
||||
{
|
||||
|
@ -1256,7 +1247,7 @@ stardict_iterator_get_offset (StardictIterator *sdi)
|
|||
return sdi->offset;
|
||||
}
|
||||
|
||||
/** Set the offset of the iterator. */
|
||||
/// Set the offset of the iterator.
|
||||
void
|
||||
stardict_iterator_set_offset
|
||||
(StardictIterator *sdi, gint64 offset, gboolean relative)
|
||||
|
|
|
@ -25,26 +25,26 @@
|
|||
#ifndef STARDICT_H
|
||||
#define STARDICT_H
|
||||
|
||||
/** An object intended for interacting with a dictionary. */
|
||||
/// An object intended for interacting with a dictionary.
|
||||
typedef struct stardict_dict StardictDict;
|
||||
typedef struct stardict_dict_class StardictDictClass;
|
||||
typedef struct stardict_dict_private StardictDictPrivate;
|
||||
|
||||
/** Overall information about a particular dictionary. */
|
||||
/// Overall information about a particular dictionary.
|
||||
typedef struct stardict_info StardictInfo;
|
||||
|
||||
/** Handles the task of moving around the dictionary. */
|
||||
/// Handles the task of moving around the dictionary.
|
||||
typedef struct stardict_iterator StardictIterator;
|
||||
typedef struct stardict_iterator_class StardictIteratorClass;
|
||||
|
||||
/** Contains the decoded data for a single word definition. */
|
||||
/// Contains the decoded data for a single word definition.
|
||||
typedef struct stardict_entry StardictEntry;
|
||||
typedef struct stardict_entry_class StardictEntryClass;
|
||||
|
||||
/** A single field of a word definition. */
|
||||
/// A single field of a word definition.
|
||||
typedef struct stardict_entry_field StardictEntryField;
|
||||
|
||||
/* GObject boilerplate. */
|
||||
// GObject boilerplate.
|
||||
#define STARDICT_TYPE_DICT (stardict_dict_get_type ())
|
||||
#define STARDICT_DICT(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
|
@ -98,7 +98,7 @@ typedef struct stardict_entry_field StardictEntryField;
|
|||
|
||||
// --- Errors ------------------------------------------------------------------
|
||||