Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "defs.h"
00039 #include "cxx_memory.h"
00040 #include "anl_cbuf.h"
00041
00042
00043 BOOL
00044 ANL_CBUF::_Is_Splitc(char splitc)
00045 {
00046 INT i;
00047
00048 for (i = 0; _splitchars[i] != '\0' && _splitchars[i] != splitc; i++);
00049 return (_splitchars[i] == splitc);
00050
00051 }
00052
00053
00054 void
00055 ANL_CBUF::_Split()
00056 {
00057
00058
00059
00060
00061
00062
00063
00064 INT splitpt, reduction;
00065
00066 for (splitpt = _next-1;
00067 splitpt >= 0 && _buf[splitpt] != '\n' && !_Is_Splitc(_buf[splitpt]);
00068 splitpt--);
00069
00070 reduction = _next-(splitpt+1);
00071 if (strlen(_continuation)+reduction < _max_linelength &&
00072 _buf[splitpt] != '\n')
00073 {
00074
00075
00076
00077 ANL_CBUF remainder(_pool, &_buf[splitpt+1]);
00078
00079 _linelength -= reduction;
00080 _next = splitpt+1;
00081 Write_String(_continuation);
00082 Write_String(remainder.Chars());
00083 }
00084 }
00085
00086
00087 ANL_CBUF::ANL_CBUF(MEM_POOL *pool, const char *s):
00088 _splitchars(""),
00089 _continuation(""),
00090 _linelength(0),
00091 _max_linelength(UINT32_MAX),
00092 _chunk_size(CBUF_SMALLEST_ALLOC_SIZE),
00093 _pool(pool)
00094 {
00095 if (s == NULL)
00096 {
00097 _next = 0;
00098 _linelength = 0;
00099 _size = 0;
00100 _buf = NULL;
00101 }
00102 else
00103 {
00104
00105
00106
00107 _next = strlen(s);
00108 _size = _A_Number_Of_Chunks(_next+1);
00109 _buf = _Alloc(_size);
00110 for (INT i=0; i<_next; i++)
00111 {
00112 _buf[i] = s[i];
00113 if (s[i]=='\n')
00114 _linelength = 0;
00115 else
00116 _linelength++;
00117 }
00118 _buf[_next] = '\0';
00119 }
00120 }
00121
00122
00123 void
00124 ANL_CBUF::Write_Char(char c)
00125 {
00126 if (_size == 0)
00127 {
00128 _size = _chunk_size;
00129 _buf = _Alloc(_size);
00130 }
00131 else if (_next+1 >= _size)
00132 {
00133 char *reclaim = _buf;
00134
00135 _size = _size + _chunk_size;
00136 _buf = strcpy(_Alloc(_size), reclaim);
00137 CXX_DELETE_ARRAY(reclaim, _pool);
00138 }
00139 _buf[_next++] = c;
00140 _buf[_next] = '\0';
00141
00142 if (c == '\n')
00143 _linelength = 0;
00144 else if (++_linelength >= _max_linelength)
00145 _Split();
00146
00147 }
00148
00149
00150 void
00151 ANL_CBUF::Write_String(const char *s)
00152 {
00153 UINT len;
00154
00155 if (s==NULL)
00156 return;
00157
00158 len = strlen(s);
00159 if (_next+len >= _size)
00160 {
00161
00162
00163 _size = _A_Number_Of_Chunks(_next+len+1);
00164 if (_next > 0)
00165 {
00166 char *reclaim = _buf;
00167
00168 _buf = strcpy(_Alloc(_size), reclaim);
00169 CXX_DELETE_ARRAY(reclaim, _pool);
00170 }
00171 else
00172 _buf = _Alloc(_size);
00173 }
00174 for (INT i=0; i<len; i++)
00175 {
00176 _buf[_next++] = s[i];
00177
00178 if (s[i] == '\n')
00179 _linelength = 0;
00180 else if (++_linelength >= _max_linelength)
00181 {
00182 _buf[_next] = '\0';
00183 _Split();
00184
00185
00186
00187 if (i+1<len)
00188 Write_String(&s[i+1]);
00189 i = len;
00190 }
00191 }
00192 _buf[_next] = '\0';
00193 }
00194
00195
00196 void
00197 ANL_CBUF:: Append_Pragma_Preamble(BOOL is_omp, BOOL is_lower_case)
00198 {
00199
00200
00201
00202 if (is_omp)
00203 if (is_lower_case)
00204 Write_String("omp_");
00205 else
00206 Write_String(" OMP_");
00207 else
00208 if (!is_lower_case)
00209 Write_Char(' ');
00210
00211 }
00212
00213
00214