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