Пример #1
0
void msIO_resetHandlers()

{
  msIOContextGroup *group = msIO_GetContextGroup();

  if( group == NULL )
    return;

  if( strcmp(group->stdin_context.label,"buffer") == 0 ) {
    msIOBuffer *buf = (msIOBuffer *) group->stdin_context.cbData;

    if( buf->data != NULL )
      free( buf->data );
    free( buf );
  }

  if( strcmp(group->stdout_context.label,"buffer") == 0 ) {
    msIOBuffer *buf = (msIOBuffer *) group->stdout_context.cbData;

    if( buf->data != NULL )
      free( buf->data );
    free( buf );
  }

  if( strcmp(group->stderr_context.label,"buffer") == 0 ) {
    msIOBuffer *buf = (msIOBuffer *) group->stderr_context.cbData;

    if( buf->data != NULL )
      free( buf->data );
    free( buf );
  }

  msIO_installHandlers( NULL, NULL, NULL );
}
Пример #2
0
int msIO_installHandlers( msIOContext *stdin_context,
                          msIOContext *stdout_context,
                          msIOContext *stderr_context )

{
  msIOContextGroup *group;

  msIO_Initialize();

  group = msIO_GetContextGroup();

  if( stdin_context == NULL )
    group->stdin_context = default_contexts.stdin_context;
  else if( stdin_context != &group->stdin_context )
    group->stdin_context = *stdin_context;

  if( stdout_context == NULL )
    group->stdout_context = default_contexts.stdout_context;
  else if( stdout_context != &group->stdout_context )
    group->stdout_context = *stdout_context;

  if( stderr_context == NULL )
    group->stderr_context = default_contexts.stderr_context;
  else if( stderr_context != &group->stderr_context )
    group->stderr_context = *stderr_context;

  return MS_TRUE;
}
Пример #3
0
msIOContext* msIO_pushStdoutToBufferAndGetOldContext()

{
  msIOContextGroup *group = msIO_GetContextGroup();
  msIOContext *old_context;

  /* Backup current context */
  old_context = (msIOContext*) msSmallMalloc(sizeof(msIOContext));
  memcpy(old_context, &group->stdout_context, sizeof(msIOContext));

  msIO_installStdoutToBuffer();

  return old_context;
}
Пример #4
0
void msIO_installStdinFromBuffer()

{
  msIOContextGroup *group = msIO_GetContextGroup();
  msIOContext  context;

  context.label = "buffer";
  context.write_channel = MS_FALSE;
  context.readWriteFunc = msIO_bufferRead;
  context.cbData = calloc(sizeof(msIOBuffer),1);

  msIO_installHandlers( &context,
                        &group->stdout_context,
                        &group->stderr_context );
}
Пример #5
0
/* returns MS_TRUE if the msIO standard output hasn't been redirected */
int msIO_isStdContext() {
  msIOContextGroup *group = io_context_list;
  int nThreadId = msGetThreadId();
  if(!group || group->thread_id != nThreadId) {
    group = msIO_GetContextGroup();
    if(!group) {
      return MS_FALSE; /* probably a bug */
    }
  }
  if(group->stderr_context.cbData == (void*)stderr &&
      group->stdin_context.cbData == (void*)stdin &&
      group->stdout_context.cbData == (void*)stdout)
    return MS_TRUE;
  return MS_FALSE;
}
Пример #6
0
void msIO_restoreOldStdoutContext(msIOContext *context_to_restore)
{
  msIOContextGroup *group = msIO_GetContextGroup();
  msIOContext *prev_context = &group->stdout_context;
  msIOBuffer* buffer;
  
  /* Free memory associated to our temporary context */
  assert( strcmp(prev_context->label, "buffer") == 0 );

  buffer = (msIOBuffer* )prev_context->cbData;
  msFree(buffer->data);
  msFree(buffer);

  /* Restore old context */
  msIO_installHandlers( &group->stdin_context,
                        context_to_restore,
                        &group->stderr_context );

  msFree(context_to_restore);
}
Пример #7
0
msIOContext *msIO_getHandler( FILE * fp )

{
  int nThreadId = msGetThreadId();
  msIOContextGroup *group = io_context_list;

  msIO_Initialize();

  if( group == NULL || group->thread_id != nThreadId ) {
    group = msIO_GetContextGroup();
    if( group == NULL )
      return NULL;
  }

  if( fp == stdin || fp == NULL || strcmp((const char *)fp,"stdin") == 0 )
    return &(group->stdin_context);
  else if( fp == stdout || strcmp((const char *)fp,"stdout") == 0 )
    return &(group->stdout_context);
  else if( fp == stderr || strcmp((const char *)fp,"stderr") == 0 )
    return &(group->stderr_context);
  else
    return NULL;
}