Actual source code: tv_data_display.c

  1: /* 
  2:  * $Header: /home/tv/src/debugger/src/datadisp/tv_data_display.c,v 1.4 2010-04-21 15:32:50 tringali Exp $
  3:  * $Locker:  $

  5:    Copyright (c) 2010, Rogue Wave Software, Inc.

  7:    Permission is hereby granted, free of charge, to any person obtaining a copy
  8:    of this software and associated documentation files (the "Software"), to deal
  9:    in the Software without restriction, including without limitation the rights
 10:    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11:    copies of the Software, and to permit persons to whom the Software is
 12:    furnished to do so, subject to the following conditions:

 14:    The above copyright notice and this permission notice shall be included in
 15:    all copies or substantial portions of the Software.

 17:    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18:    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19:    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20:    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21:    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22:    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23:    THE SOFTWARE.

 25:  * Update log
 26:  *
 27:  * Jan 28 2010 SJT: Bug 12100, bump base size to 16K and recognize if it is
 28:  *                  resized further.
 29:  * Sep 24 2009 SJT: Remove pre/post callback to reduce function call overhead.
 30:  * Jul 1  2009 SJT: Created.
 31:  *
 32:  */

 34: #include <../src/sys/totalview/tv_data_display.h>
 35: #include <petscconf.h>

 37: #include <errno.h>
 38: #include <stdlib.h>
 39: #include <string.h>
 40: #include <stdio.h>
 41: #include <assert.h>

 43: #define DATA_FORMAT_BUFFER_SIZE 1048576
 44: #define TV_FORMAT_INACTIVE 0
 45: #define TV_FORMAT_FIRST_CALL 1
 46: #define TV_FORMAT_APPEND_CALL 2

 48: volatile int TV_data_format_control = TV_FORMAT_INACTIVE;
 49: 
 50: /* TV_data_format_buffer should not be static for icc 11, and others */
 51: char TV_data_format_buffer[DATA_FORMAT_BUFFER_SIZE];
 52: static char *TV_data_buffer_ptr = TV_data_format_buffer;

 54: int TV_add_row(const char *field_name,
 55:                const char *type_name,
 56:                const void *value)
 57: {
 58:   size_t remaining;
 59:   int out;

 61:   /* Called at the wrong time */
 62:   if (TV_data_format_control == TV_FORMAT_INACTIVE)
 63:     return EPERM;
 64: 
 65:   if (strpbrk(field_name, "\n\t") != NULL)
 66:     return EINVAL;

 68:   if (strpbrk(type_name, "\n\t") != NULL)
 69:     return EINVAL;

 71:   if (TV_data_format_control == TV_FORMAT_FIRST_CALL)
 72:     {
 73:       /* Zero out the buffer to avoid confusion, and set the write point 
 74:          to the top of the buffer. */

 76:       memset(TV_data_format_buffer, 0, DATA_FORMAT_BUFFER_SIZE);
 77:       TV_data_buffer_ptr = TV_data_format_buffer;
 78:       TV_data_format_control = TV_FORMAT_APPEND_CALL;
 79:     }
 80: 
 81:   remaining = TV_data_buffer_ptr + DATA_FORMAT_BUFFER_SIZE - TV_data_format_buffer;
 82: 
 83: #if defined(PETSC_HAVE__SNPRINTF) && !defined(PETSC_HAVE_SNPRINTF)
 84: #define snprintf _snprintf
 85: #endif
 86:   out = snprintf(TV_data_buffer_ptr,remaining, "%s\t%s\t%p\n",field_name, type_name, value);
 87: 
 88:   if (out < 1)
 89:     return ENOMEM;
 90: 
 91:   TV_data_buffer_ptr += out;
 92: 
 93:   return 0;
 94: }

 96: void TV_pre_display_callback(void)
 97: {
 98:   TV_data_format_control = TV_FORMAT_FIRST_CALL;
 99: }

101: void TV_post_display_callback(void)
102: {
103:   TV_data_format_control = TV_FORMAT_INACTIVE;
104: }