/* (headers) */
/* File handle. */
-struct file_handle
+struct file_handle
{
struct file_handle *next; /* Next in global list. */
int open_cnt; /* 0=not open, otherwise # of openers. */
const char *name, enum fh_referent);
/* File handle initialization routine. */
-void
+void
fh_init (void)
{
inline_file = create_handle ("INLINE", "INLINE", FH_REF_INLINE);
/* Free HANDLE and remove it from the global list. */
static void
-free_handle (struct file_handle *handle)
+free_handle (struct file_handle *handle)
{
/* Remove handle from global list. */
if (file_handles == handle)
file_handles = handle->next;
- else
+ else
{
struct file_handle *iter = file_handles;
while (iter->next != handle)
}
/* Frees all the file handles. */
-void
+void
fh_done (void)
{
- while (file_handles != NULL)
+ while (file_handles != NULL)
free_handle (file_handles);
}
/* Returns the handle with the given ID, or a null pointer if
there is none. */
struct file_handle *
-fh_from_id (const char *id)
+fh_from_id (const char *id)
{
struct file_handle *iter;
{
struct file_identity *identity;
struct file_handle *iter;
-
+
/* First check for a file with the same identity. */
identity = fn_get_identity (file_name);
- if (identity != NULL)
+ if (identity != NULL)
{
for (iter = file_handles; iter != NULL; iter = iter->next)
if (!iter->deleted
&& !fn_compare_file_identities (identity, iter->identity))
{
fn_free_identity (identity);
- return iter;
+ return iter;
}
fn_free_identity (identity);
}
for (iter = file_handles; iter != NULL; iter = iter->next)
if (!iter->deleted
&& iter->referent == FH_REF_FILE && !strcmp (file_name, iter->file_name))
- return iter;
+ return iter;
return NULL;
}
responsible for completing its initialization. */
static struct file_handle *
create_handle (const char *id, const char *handle_name,
- enum fh_referent referent)
+ enum fh_referent referent)
{
struct file_handle *handle = xzalloc (sizeof *handle);
assert (id == NULL || fh_from_id (id) == NULL);
which refers to the "inline file" that represents character
data in the command file between BEGIN DATA and END DATA. */
struct file_handle *
-fh_inline_file (void)
+fh_inline_file (void)
{
return inline_file;
}
unique among existing file identifiers. The new handle is
associated with a scratch file (initially empty). */
struct file_handle *
-fh_create_scratch (const char *id)
+fh_create_scratch (const char *id)
{
struct file_handle *handle;
assert (id != NULL);
destroyed later when it is closed.
Normally needed only if a file_handle needs to be re-assigned.
Otherwise, just let fh_done() destroy the handle. */
-void
+void
fh_free (struct file_handle *handle)
{
if (handle == fh_inline_file () || handle == NULL || handle->deleted)
/* Returns an English description of MODE,
which is in the format of the MODE argument to fh_open(). */
static const char *
-mode_name (const char *mode)
+mode_name (const char *mode)
{
assert (mode != NULL);
assert (mode[0] == 'r' || mode[0] == 'w');
sharers are active. */
void **
fh_open (struct file_handle *h, enum fh_referent mask UNUSED,
- const char *type, const char *mode)
+ const char *type, const char *mode)
{
assert (h != NULL);
assert ((fh_get_referent (h) & mask) != 0);
assert (mode[1] == 's' || mode[1] == 'e');
assert (mode[2] == '\0');
- if (h->open_cnt != 0)
+ if (h->open_cnt != 0)
{
- if (strcmp (h->type, type))
+ if (strcmp (h->type, type))
{
msg (SE, _("Can't open %s as a %s because it is "
"already open as a %s."),
fh_get_name (h), type, h->type);
- return NULL;
+ return NULL;
}
- else if (strcmp (h->open_mode, mode))
+ else if (strcmp (h->open_mode, mode))
{
msg (SE, _("Can't open %s as a %s for %s because it is "
"already open for %s."),
return NULL;
}
}
- else
+ else
{
h->type = type;
strcpy (h->open_mode, mode);
assert (mode != NULL);
assert (!strcmp (mode, h->open_mode));
- if (--h->open_cnt == 0)
+ if (--h->open_cnt == 0)
{
h->type = NULL;
h->aux = NULL;
/* Is the file open? BEGIN DATA...END DATA uses this to detect
whether the inline file is actually in use. */
bool
-fh_is_open (const struct file_handle *handle)
+fh_is_open (const struct file_handle *handle)
{
return handle->open_cnt > 0;
}
Return value is owned by the file handle.*/
const char *
-fh_get_id (const struct file_handle *handle)
+fh_get_id (const struct file_handle *handle)
{
return handle->id[0] != '\0' ? handle->id : NULL;
}
/* Returns the type of object that HANDLE refers to. */
enum fh_referent
-fh_get_referent (const struct file_handle *handle)
+fh_get_referent (const struct file_handle *handle)
{
return handle->referent;
}
/* Returns the name of the file associated with HANDLE. */
const char *
-fh_get_file_name (const struct file_handle *handle)
+fh_get_file_name (const struct file_handle *handle)
{
assert (handle->referent == FH_REF_FILE);
return handle->file_name;
/* Returns the mode of HANDLE. */
enum fh_mode
-fh_get_mode (const struct file_handle *handle)
+fh_get_mode (const struct file_handle *handle)
{
assert (handle->referent == FH_REF_FILE);
return handle->mode;
zero if tabs are not to be expanded. Applicable only to
FH_MODE_TEXT files. */
size_t
-fh_get_tab_width (const struct file_handle *handle)
+fh_get_tab_width (const struct file_handle *handle)
{
assert (handle->referent & (FH_REF_FILE | FH_REF_INLINE));
return handle->tab_width;
/* Returns the scratch file handle associated with HANDLE.
Applicable to only FH_REF_SCRATCH files. */
struct scratch_handle *
-fh_get_scratch_handle (struct file_handle *handle)
+fh_get_scratch_handle (struct file_handle *handle)
{
assert (handle->referent == FH_REF_SCRATCH);
return handle->sh;
/* Returns the current default handle. */
struct file_handle *
-fh_get_default_handle (void)
+fh_get_default_handle (void)
{
return default_handle ? default_handle : fh_inline_file ();
}
/* Sets NEW_DEFAULT_HANDLE as the default handle. */
void
-fh_set_default_handle (struct file_handle *new_default_handle)
+fh_set_default_handle (struct file_handle *new_default_handle)
{
assert (new_default_handle == NULL
|| (new_default_handle->referent & (FH_REF_INLINE | FH_REF_FILE)));