xref: /petsc/src/sys/totalview/tv_data_display.c (revision b55407b6c4ce3478de6c4436e540a296b50517c1)
1*b55407b6SBarry Smith /*
2*b55407b6SBarry Smith  * $Header: /home/tv/src/debugger/src/datadisp/tv_data_display.c,v 1.4 2010-04-21 15:32:50 tringali Exp $
3*b55407b6SBarry Smith  * $Locker:  $
4*b55407b6SBarry Smith 
5*b55407b6SBarry Smith    Copyright (c) 2010, Rogue Wave Software, Inc.
6*b55407b6SBarry Smith 
7*b55407b6SBarry Smith    Permission is hereby granted, free of charge, to any person obtaining a copy
8*b55407b6SBarry Smith    of this software and associated documentation files (the "Software"), to deal
9*b55407b6SBarry Smith    in the Software without restriction, including without limitation the rights
10*b55407b6SBarry Smith    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11*b55407b6SBarry Smith    copies of the Software, and to permit persons to whom the Software is
12*b55407b6SBarry Smith    furnished to do so, subject to the following conditions:
13*b55407b6SBarry Smith 
14*b55407b6SBarry Smith    The above copyright notice and this permission notice shall be included in
15*b55407b6SBarry Smith    all copies or substantial portions of the Software.
16*b55407b6SBarry Smith 
17*b55407b6SBarry Smith    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*b55407b6SBarry Smith    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*b55407b6SBarry Smith    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20*b55407b6SBarry Smith    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21*b55407b6SBarry Smith    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22*b55407b6SBarry Smith    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23*b55407b6SBarry Smith    THE SOFTWARE.
24*b55407b6SBarry Smith 
25*b55407b6SBarry Smith  * Update log
26*b55407b6SBarry Smith  *
27*b55407b6SBarry Smith  * Jan 28 2010 SJT: Bug 12100, bump base size to 16K and recognize if it is
28*b55407b6SBarry Smith  *                  resized further.
29*b55407b6SBarry Smith  * Sep 24 2009 SJT: Remove pre/post callback to reduce function call overhead.
30*b55407b6SBarry Smith  * Jul 1  2009 SJT: Created.
31*b55407b6SBarry Smith  *
32*b55407b6SBarry Smith  */
33*b55407b6SBarry Smith 
34*b55407b6SBarry Smith #include "../src/sys/totalview/tv_data_display.h"
35*b55407b6SBarry Smith 
36*b55407b6SBarry Smith #include <errno.h>
37*b55407b6SBarry Smith #include <stdlib.h>
38*b55407b6SBarry Smith #include <string.h>
39*b55407b6SBarry Smith #include <stdio.h>
40*b55407b6SBarry Smith #include <assert.h>
41*b55407b6SBarry Smith 
42*b55407b6SBarry Smith #define DATA_FORMAT_BUFFER_SIZE 1048576
43*b55407b6SBarry Smith #define TV_FORMAT_INACTIVE 0
44*b55407b6SBarry Smith #define TV_FORMAT_FIRST_CALL 1
45*b55407b6SBarry Smith #define TV_FORMAT_APPEND_CALL 2
46*b55407b6SBarry Smith 
47*b55407b6SBarry Smith volatile int TV_data_format_control = TV_FORMAT_INACTIVE;
48*b55407b6SBarry Smith 
49*b55407b6SBarry Smith /* TV_data_format_buffer should not be static for icc 11, and others */
50*b55407b6SBarry Smith char TV_data_format_buffer[DATA_FORMAT_BUFFER_SIZE];
51*b55407b6SBarry Smith static char *TV_data_buffer_ptr = TV_data_format_buffer;
52*b55407b6SBarry Smith 
53*b55407b6SBarry Smith int TV_add_row(const char *field_name,
54*b55407b6SBarry Smith                const char *type_name,
55*b55407b6SBarry Smith                const void *value)
56*b55407b6SBarry Smith {
57*b55407b6SBarry Smith   size_t remaining;
58*b55407b6SBarry Smith   int out;
59*b55407b6SBarry Smith 
60*b55407b6SBarry Smith   /* Called at the wrong time */
61*b55407b6SBarry Smith   if (TV_data_format_control == TV_FORMAT_INACTIVE)
62*b55407b6SBarry Smith     return EPERM;
63*b55407b6SBarry Smith 
64*b55407b6SBarry Smith   if (strpbrk(field_name, "\n\t") != NULL)
65*b55407b6SBarry Smith     return EINVAL;
66*b55407b6SBarry Smith 
67*b55407b6SBarry Smith   if (strpbrk(type_name, "\n\t") != NULL)
68*b55407b6SBarry Smith     return EINVAL;
69*b55407b6SBarry Smith 
70*b55407b6SBarry Smith   if (TV_data_format_control == TV_FORMAT_FIRST_CALL)
71*b55407b6SBarry Smith     {
72*b55407b6SBarry Smith       /* Zero out the buffer to avoid confusion, and set the write point
73*b55407b6SBarry Smith          to the top of the buffer. */
74*b55407b6SBarry Smith 
75*b55407b6SBarry Smith       memset(TV_data_format_buffer, 0, DATA_FORMAT_BUFFER_SIZE);
76*b55407b6SBarry Smith       TV_data_buffer_ptr = TV_data_format_buffer;
77*b55407b6SBarry Smith       TV_data_format_control = TV_FORMAT_APPEND_CALL;
78*b55407b6SBarry Smith     }
79*b55407b6SBarry Smith 
80*b55407b6SBarry Smith   remaining = TV_data_buffer_ptr + DATA_FORMAT_BUFFER_SIZE - TV_data_format_buffer;
81*b55407b6SBarry Smith 
82*b55407b6SBarry Smith   out = snprintf(TV_data_buffer_ptr,
83*b55407b6SBarry Smith                  remaining, "%s\t%s\t%p\n",
84*b55407b6SBarry Smith                  field_name, type_name, value);
85*b55407b6SBarry Smith 
86*b55407b6SBarry Smith   if (out < 1)
87*b55407b6SBarry Smith     return ENOMEM;
88*b55407b6SBarry Smith 
89*b55407b6SBarry Smith   TV_data_buffer_ptr += out;
90*b55407b6SBarry Smith 
91*b55407b6SBarry Smith   return 0;
92*b55407b6SBarry Smith };
93*b55407b6SBarry Smith 
94*b55407b6SBarry Smith void TV_pre_display_callback(void)
95*b55407b6SBarry Smith {
96*b55407b6SBarry Smith   TV_data_format_control = TV_FORMAT_FIRST_CALL;
97*b55407b6SBarry Smith }
98*b55407b6SBarry Smith 
99*b55407b6SBarry Smith void TV_post_display_callback(void)
100*b55407b6SBarry Smith {
101*b55407b6SBarry Smith   TV_data_format_control = TV_FORMAT_INACTIVE;
102*b55407b6SBarry Smith }
103