Date: 2016-07-24T16:48:50+00:00

Actual source code: tv_data_display.c
petsc-3.7.3 2016-07-24
Report Typos and Errors

      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>

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

     47: volatile int TV_data_format_control = TV_FORMAT_INACTIVE;

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

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

     58:   /* Called at the wrong time */
     59:   if (TV_data_format_control == TV_FORMAT_INACTIVE) return EPERM;

     61:   if (strpbrk(field_name, "\n\t")) return EINVAL;

     63:   if (strpbrk(type_name, "\n\t")) return EINVAL;

     65:   if (TV_data_format_control == TV_FORMAT_FIRST_CALL) {
     66:     /* Zero out the buffer to avoid confusion, and set the write point
     67:        to the top of the buffer. */

     69:     memset(TV_data_format_buffer, 0, DATA_FORMAT_BUFFER_SIZE);
     70:     TV_data_buffer_ptr     = TV_data_format_buffer;
     71:     TV_data_format_control = TV_FORMAT_APPEND_CALL;
     72:   }

     74:   remaining = TV_data_buffer_ptr + DATA_FORMAT_BUFFER_SIZE - TV_data_format_buffer;

     76: #if defined(PETSC_HAVE__SNPRINTF) && !defined(PETSC_HAVE_SNPRINTF)
     77: #define snprintf _snprintf
     78: #endif
     79:   out = snprintf(TV_data_buffer_ptr,remaining, "%s\t%s\t%p\n",field_name, type_name, value);

     81:   if (out < 1) return ENOMEM;

     83:   TV_data_buffer_ptr += out;

     85:   return 0;
     86: }

     88: void TV_pre_display_callback(void)
     89: {
     90:   TV_data_format_control = TV_FORMAT_FIRST_CALL;
     91: }

     93: void TV_post_display_callback(void)
     94: {
     95:   TV_data_format_control = TV_FORMAT_INACTIVE;
     96: }