Classes | Functions

cbf_context.h File Reference

#include "cbf_file.h"
#include <stdio.h>
Include dependency graph for cbf_context.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cbf_context

Functions

int cbf_make_context (cbf_context **context)
int cbf_free_context (cbf_context **context)
int cbf_add_contextconnection (cbf_context **context)
int cbf_delete_contextconnection (cbf_context **context)
int cbf_open_temporary (cbf_context *context, cbf_file **temporary)
int cbf_close_temporary (cbf_context *context, cbf_file **temporary)
const char * cbf_copy_string (cbf_context *context, const char *string, char type)
void cbf_free_string (cbf_context *context, const char *string)

Function Documentation

int cbf_add_contextconnection ( cbf_context **  context)

Definition at line 183 of file cbf_context.c.

References CBF_ARGUMENT, and cbf_make_context().

Referenced by cbf_make_new_node(), and cbf_make_node().

{
    /* Does the context pointer exist? */

  if (!context)

    return CBF_ARGUMENT;


    /* Does the context exist? */

  if (*context)
  {
    (*context)->connections++;

    return 0;
  }


    /* Create a new context */

  return cbf_make_context (context);
}
int cbf_close_temporary ( cbf_context context,
cbf_file **  temporary 
)

Definition at line 300 of file cbf_context.c.

References CBF_ARGUMENT, cbf_delete_fileconnection(), cbf_failnez, cbf_file_connections(), cbf_free_file(), CBF_NOTFOUND, and cbf_context::temporary.

Referenced by cbf_free_value().

{
    /* Check the arguments */

  if (!context || !temporary)

    return CBF_ARGUMENT;

  if (!*temporary)

    return CBF_ARGUMENT;


    /* Check that the temporary file matches */

  if (context->temporary != *temporary)

    return CBF_NOTFOUND;
    

    /* Delete the connection */

  cbf_failnez (cbf_delete_fileconnection (&context->temporary))

  *temporary = NULL;


    /* Is there only one connection left? */

  if (context->temporary)

    if (cbf_file_connections (context->temporary) == 1)

      cbf_failnez (cbf_free_file (&context->temporary))


    /* Success */

  return 0;
}
const char* cbf_copy_string ( cbf_context context,
const char *  string,
char  type 
)

Definition at line 344 of file cbf_context.c.

References cbf_alloc().

Referenced by cbf_force_new_category(), cbf_force_new_datablock(), cbf_new_category(), cbf_new_column(), cbf_new_datablock(), cbf_return_text(), cbf_set_bintext(), cbf_set_datablockname(), and cbf_set_value().

{
  char *new_string;

  if (string)

    if (type)
    {
      if (cbf_alloc ((void **) &new_string, NULL, 
                      sizeof (char), strlen (string) + 2) == 0)
      {
        *new_string = type;
        
        strcpy (new_string + 1, string);

        return new_string;
      }
    }
    else

      if (cbf_alloc ((void **) &new_string, NULL, \
                      sizeof (char), strlen (string) + 1) == 0)
      {
        strcpy (new_string, string);

        return new_string;
      }

 
    /* Fail */

  return NULL;
}
int cbf_delete_contextconnection ( cbf_context **  context)

Definition at line 210 of file cbf_context.c.

References CBF_ARGUMENT, and cbf_free_context().

Referenced by cbf_free_node().

{
    /* Does the context pointer exist? */

  if (!context)

    return CBF_ARGUMENT;


    /* Does the context exist? */

  if (!*context)

    return CBF_ARGUMENT;


    /* Remove a connection */

  (*context)->connections--;


    /* Delete the context? */

  if ((*context)->connections == 0)

    return cbf_free_context (context);


    /* Success */

  return 0;
}
int cbf_free_context ( cbf_context **  context)

Definition at line 157 of file cbf_context.c.

References cbf_free(), and cbf_free_file().

Referenced by cbf_delete_contextconnection(), cbf_make_new_node(), and cbf_make_node().

{
  int errorcode;

  errorcode = 0;

  if (context)

    if (*context)
    {
      if ((*context)->temporary)

        errorcode = cbf_free_file (&(*context)->temporary);

      errorcode |= cbf_free ((void **) context, NULL);
    }


    /* Success? */

  return errorcode;
}
void cbf_free_string ( cbf_context context,
const char *  string 
)
int cbf_make_context ( cbf_context **  context)

Definition at line 135 of file cbf_context.c.

References cbf_alloc(), and cbf_failnez.

Referenced by cbf_add_contextconnection().

{
    /* Allocate the memory */

  cbf_failnez (cbf_alloc ((void **) context, NULL, sizeof (cbf_context), 1))


    /* Initialise */
    
  (*context)->temporary = NULL;

  (*context)->connections = 1;


    /* Success */

  return 0;
}
int cbf_open_temporary ( cbf_context context,
cbf_file **  temporary 
)

Definition at line 246 of file cbf_context.c.

References cbf_add_fileconnection(), CBF_ARGUMENT, cbf_failnez, CBF_FILECLOSE, CBF_FILEOPEN, cbf_make_file(), cbf_open_temporary(), and cbf_context::temporary.

Referenced by cbf_mime_temp(), cbf_open_temporary(), and cbf_set_binary().

{
  FILE *stream;

  int errorcode;

  
    /* Check the arguments */

  if (!context || !temporary)

    return CBF_ARGUMENT;


    /* Does a temporary file already exist? */

  if (context->temporary)
  {
    cbf_failnez (cbf_add_fileconnection (&context->temporary, NULL))

    *temporary = context->temporary;

    return 0;
  }


    /* Create the temporary file */

  stream = tmpfile ();

  if (!stream)

    return CBF_FILEOPEN;

  errorcode = cbf_make_file (&context->temporary, stream);
  
  if (errorcode)
  {
    if (fclose (stream))

      errorcode |= CBF_FILECLOSE;

    return errorcode;
  }


    /* Open a connection */
    
  return cbf_open_temporary (context, temporary);
}