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 #define _PPRINT_SOURCE_
00028
00029 #include <stdio.h>
00030 #define _STDIO_INCLUDED_
00031 #include <string.h>
00032 #include <ctype.h>
00033
00034 #include "setup.h"
00035
00036 #include "constant.h"
00037 #include "envrnmnt.h"
00038 #include "memalloc.h"
00039 #include "sysdep.h"
00040 #include "utility.h"
00041
00042 #include "pprint.h"
00043
00044
00045
00046
00047
00048 static void DeallocatePrettyPrintData(void *);
00049
00050
00051
00052
00053
00054 globle void InitializePrettyPrintData(
00055 void *theEnv)
00056 {
00057 AllocateEnvironmentData(theEnv,PRETTY_PRINT_DATA,sizeof(struct prettyPrintData),DeallocatePrettyPrintData);
00058
00059 PrettyPrintData(theEnv)->PPBufferEnabled = TRUE;
00060 }
00061
00062
00063
00064
00065
00066 static void DeallocatePrettyPrintData(
00067 void *theEnv)
00068 {
00069 if (PrettyPrintData(theEnv)->PrettyPrintBuffer != NULL)
00070 { rm(theEnv,PrettyPrintData(theEnv)->PrettyPrintBuffer,PrettyPrintData(theEnv)->PPBufferMax); }
00071 }
00072
00073
00074
00075
00076 globle void FlushPPBuffer(
00077 void *theEnv)
00078 {
00079 if (PrettyPrintData(theEnv)->PrettyPrintBuffer == NULL) return;
00080 PrettyPrintData(theEnv)->PPBackupOnce = 0;
00081 PrettyPrintData(theEnv)->PPBackupTwice = 0;
00082 PrettyPrintData(theEnv)->PPBufferPos = 0;
00083 PrettyPrintData(theEnv)->PrettyPrintBuffer[0] = EOS;
00084 return;
00085 }
00086
00087
00088
00089
00090 globle void DestroyPPBuffer(void *theEnv)
00091 {
00092 PrettyPrintData(theEnv)->PPBackupOnce = 0;
00093 PrettyPrintData(theEnv)->PPBackupTwice = 0;
00094 PrettyPrintData(theEnv)->PPBufferPos = 0;
00095 if (PrettyPrintData(theEnv)->PrettyPrintBuffer != NULL) rm(theEnv,PrettyPrintData(theEnv)->PrettyPrintBuffer,PrettyPrintData(theEnv)->PPBufferMax);
00096 PrettyPrintData(theEnv)->PrettyPrintBuffer = NULL;
00097 PrettyPrintData(theEnv)->PPBufferMax = 0;
00098 }
00099
00100
00101
00102
00103
00104 globle void SavePPBuffer(
00105 void *theEnv,
00106 char *str)
00107 {
00108 size_t increment;
00109
00110
00111
00112
00113
00114
00115 if ((PrettyPrintData(theEnv)->PPBufferStatus == OFF) || (! PrettyPrintData(theEnv)->PPBufferEnabled))
00116 { return; }
00117
00118
00119
00120
00121
00122 increment = 512;
00123 if (PrettyPrintData(theEnv)->PPBufferPos > increment)
00124 { increment = PrettyPrintData(theEnv)->PPBufferPos * 3; }
00125
00126
00127
00128
00129
00130
00131 if (strlen(str) + PrettyPrintData(theEnv)->PPBufferPos + 1 >= PrettyPrintData(theEnv)->PPBufferMax)
00132 {
00133 PrettyPrintData(theEnv)->PrettyPrintBuffer =
00134 (char *) genrealloc(theEnv,PrettyPrintData(theEnv)->PrettyPrintBuffer,
00135 PrettyPrintData(theEnv)->PPBufferMax,
00136 PrettyPrintData(theEnv)->PPBufferMax + increment);
00137 PrettyPrintData(theEnv)->PPBufferMax += increment;
00138 }
00139
00140
00141
00142
00143
00144
00145 PrettyPrintData(theEnv)->PPBackupTwice = PrettyPrintData(theEnv)->PPBackupOnce;
00146 PrettyPrintData(theEnv)->PPBackupOnce = PrettyPrintData(theEnv)->PPBufferPos;
00147
00148
00149
00150
00151
00152 PrettyPrintData(theEnv)->PrettyPrintBuffer = AppendToString(theEnv,str,PrettyPrintData(theEnv)->PrettyPrintBuffer,&PrettyPrintData(theEnv)->PPBufferPos,&PrettyPrintData(theEnv)->PPBufferMax);
00153 }
00154
00155
00156
00157
00158
00159
00160 globle void PPBackup(
00161 void *theEnv)
00162 {
00163 if ((PrettyPrintData(theEnv)->PPBufferStatus == OFF) ||
00164 (PrettyPrintData(theEnv)->PrettyPrintBuffer == NULL) ||
00165 (! PrettyPrintData(theEnv)->PPBufferEnabled))
00166 { return; }
00167
00168 PrettyPrintData(theEnv)->PPBufferPos = PrettyPrintData(theEnv)->PPBackupOnce;
00169 PrettyPrintData(theEnv)->PPBackupOnce = PrettyPrintData(theEnv)->PPBackupTwice;
00170 PrettyPrintData(theEnv)->PrettyPrintBuffer[PrettyPrintData(theEnv)->PPBufferPos] = EOS;
00171 }
00172
00173
00174
00175
00176
00177 globle char *CopyPPBuffer(
00178 void *theEnv)
00179 {
00180 size_t length;
00181 char *newString;
00182
00183 length = (1 + strlen(PrettyPrintData(theEnv)->PrettyPrintBuffer)) * (int) sizeof (char);
00184 newString = (char *) gm2(theEnv,length);
00185
00186 genstrcpy(newString,PrettyPrintData(theEnv)->PrettyPrintBuffer);
00187 return(newString);
00188 }
00189
00190
00191
00192
00193 globle char *GetPPBuffer(
00194 void *theEnv)
00195 {
00196 return(PrettyPrintData(theEnv)->PrettyPrintBuffer);
00197 }
00198
00199
00200
00201
00202
00203 globle void PPCRAndIndent(
00204 void *theEnv)
00205 {
00206 int i;
00207 char buffer[120];
00208
00209 if ((PrettyPrintData(theEnv)->PPBufferStatus == OFF) ||
00210 (! PrettyPrintData(theEnv)->PPBufferEnabled))
00211 { return; }
00212
00213 buffer[0] = '\n';
00214
00215 for (i = 1 ; i <= PrettyPrintData(theEnv)->IndentationDepth ; i++)
00216 { buffer[i] = ' '; }
00217 buffer[i] = EOS;
00218
00219 SavePPBuffer(theEnv,buffer);
00220 }
00221
00222
00223
00224
00225
00226 globle void IncrementIndentDepth(
00227 void *theEnv,
00228 int value)
00229 {
00230 PrettyPrintData(theEnv)->IndentationDepth += value;
00231 }
00232
00233
00234
00235
00236
00237 globle void DecrementIndentDepth(
00238 void *theEnv,
00239 int value)
00240 {
00241 PrettyPrintData(theEnv)->IndentationDepth -= value;
00242 }
00243
00244
00245
00246
00247
00248 globle void SetIndentDepth(
00249 void *theEnv,
00250 int value)
00251 {
00252 PrettyPrintData(theEnv)->IndentationDepth = value;
00253 }
00254
00255
00256
00257
00258
00259 globle void SetPPBufferStatus(
00260 void *theEnv,
00261 int value)
00262 {
00263 PrettyPrintData(theEnv)->PPBufferStatus = value;
00264 }
00265
00266
00267
00268
00269
00270 globle int GetPPBufferStatus(
00271 void *theEnv)
00272 {
00273 return(PrettyPrintData(theEnv)->PPBufferStatus);
00274 }
00275
00276
00277
00278
00279 globle int SetPPBufferEnabled(
00280 void *theEnv,
00281 int value)
00282 {
00283 int oldValue;
00284
00285 oldValue = PrettyPrintData(theEnv)->PPBufferEnabled;
00286 PrettyPrintData(theEnv)->PPBufferEnabled = value;
00287 return(oldValue);
00288 }
00289
00290
00291
00292
00293 globle int GetPPBufferEnabled(
00294 void *theEnv)
00295 {
00296 return(PrettyPrintData(theEnv)->PPBufferEnabled);
00297 }
00298