00001
00027
00028
00029
00030
00031
00032
00033
00034 #include "dyn.h"
00035
00036 #ifdef TOOLBOX
00037
00038 #define MAX_NUMBER_OF_INPUT_LINES 100
00039 #define MAX_NUMBER_OF_COLUMNS 180
00040 #define MAX_NUMBER_OF_OUTPUT_COLUMNS 79
00041
00042
00043
00044
00045
00046 void use_square_window_smoothing(
00047 char in_screen[MAX_NUMBER_OF_INPUT_LINES][MAX_NUMBER_OF_COLUMNS], int w)
00048 {
00049 int c;
00050 int i, j;
00051 int k;
00052 int w_tot;
00053 w_tot = 0;
00054 real radius[12];
00055 for (i= 0; i < 12; i++)
00056 radius[i] = 0;
00057
00058 bool input_flag;
00059 bool one_flag;
00060 bool two_flag;
00061 bool five_flag;
00062 for (i= 0; i < MAX_NUMBER_OF_INPUT_LINES; i++)
00063 {
00064 k = 2;
00065 input_flag = FALSE;
00066 one_flag = FALSE;
00067 two_flag = FALSE;
00068 five_flag = FALSE;
00069 for (j= 0; j < MAX_NUMBER_OF_COLUMNS; j++)
00070 {
00071 while (in_screen[i][j] == ' ' && j + 1 < MAX_NUMBER_OF_COLUMNS)
00072 j++;
00073 if (in_screen[i][j] == '`')
00074 {
00075 input_flag = TRUE;
00076 radius[0] += j;
00077 one_flag = TRUE;
00078 }
00079 if (in_screen[i][j] == '\"')
00080 {
00081 input_flag = TRUE;
00082 if (! one_flag)
00083 {
00084 radius[0] += j;
00085 one_flag = TRUE;
00086 }
00087 radius[1] += j;
00088 two_flag = TRUE;
00089 }
00090 if (in_screen[i][j] == ':')
00091 {
00092 input_flag = TRUE;
00093 if (! one_flag)
00094 {
00095 radius[0] += j;
00096 one_flag = TRUE;
00097 }
00098 if (! two_flag)
00099 {
00100 radius[1] += j;
00101 two_flag = TRUE;
00102 }
00103 radius[2] += j;
00104 five_flag = TRUE;
00105 }
00106 if (in_screen[i][j] == '|')
00107 {
00108 input_flag = TRUE;
00109 k++;
00110 if (! one_flag)
00111 {
00112 radius[0] += j;
00113 one_flag = TRUE;
00114 }
00115 if (! two_flag)
00116 {
00117 radius[1] += j;
00118 two_flag = TRUE;
00119 }
00120 if (! five_flag)
00121 {
00122 radius[2] += j;
00123 five_flag = TRUE;
00124 }
00125 radius[k] += j;
00126 }
00127 if (in_screen[i][j] == 'X')
00128 {
00129 input_flag = TRUE;
00130 k++;
00131 if (! one_flag)
00132 {
00133 radius[0] += j;
00134 one_flag = TRUE;
00135 }
00136 if (! two_flag)
00137 {
00138 radius[1] += j;
00139 two_flag = TRUE;
00140 }
00141 if (! five_flag)
00142 {
00143 radius[2] += j;
00144 five_flag = TRUE;
00145 }
00146 radius[k] += j;
00147 k++;
00148 radius[k] += j;
00149 }
00150 if (in_screen[i][j] == '@')
00151 {
00152 input_flag = TRUE;
00153 k++;
00154 if (! one_flag)
00155 {
00156 radius[0] += j;
00157 one_flag = TRUE;
00158 }
00159 if (! two_flag)
00160 {
00161 radius[1] += j;
00162 two_flag = TRUE;
00163 }
00164 if (! five_flag)
00165 {
00166 radius[2] += j;
00167 five_flag = TRUE;
00168 }
00169 radius[k] += j;
00170 k++;
00171 radius[k] += j;
00172 k++;
00173 radius[k] += j;
00174
00175 }
00176 }
00177 if (input_flag)
00178 w_tot++;
00179 }
00180
00181
00182
00183 for (i= 0; i < 12; i++)
00184 radius[i] /= w_tot;
00185
00186 j = 0;
00187 k = 3;
00188 while (j < MAX_NUMBER_OF_OUTPUT_COLUMNS)
00189 {
00190 if (radius[3] > j + 0.5)
00191 {
00192 if (radius[2] <= j + 0.5 && radius[2] > j - 0.5)
00193 printf(":");
00194 else if (radius[1] <= j + 0.5 && radius[1] > j - 0.5)
00195 printf("\"");
00196 else if (radius[0] <= j + 0.5 && radius[0] > j - 0.5)
00197 printf("`");
00198 else
00199 printf(" ");
00200 }
00201 else
00202 {
00203 if (radius[k] <= j + 0.5 && radius[k] > j - 0.5)
00204 {
00205 k++;
00206 if (radius[k] > j + 0.5)
00207 printf("|");
00208 else if (radius[k + 1] > j + 0.5)
00209 {
00210 k++;
00211 printf("X");
00212 }
00213 else
00214 {
00215 k++;
00216 k++;
00217 printf("@");
00218 }
00219 }
00220 else
00221 printf(" ");
00222 }
00223 j++;
00224 }
00225 printf("\n");
00226 }
00227
00228
00229
00230
00231
00232 main(int argc, char ** argv)
00233 {
00234 char *comment;
00235 bool c_flag = FALSE;
00236 bool w_flag = FALSE;
00237
00238
00239 check_help();
00240
00241 extern char *poptarg;
00242 int c;
00243 char* param_string = "c:w:";
00244
00245 int w;
00246
00247 while ((c = pgetopt(argc, argv, param_string)) != -1)
00248 switch(c)
00249 {
00250 case 'c': c_flag = TRUE;
00251 comment = poptarg;
00252 break;
00253 case 'w': w_flag = TRUE;
00254 w = atoi(poptarg);
00255 break;
00256 case '?': params_to_usage(cerr, argv[0], param_string);
00257 get_help();
00258 exit(1);
00259 }
00260
00261 if (w > MAX_NUMBER_OF_INPUT_LINES)
00262 {
00263 cerr << "lagradplotsmooth: w = " << w << " > " <<
00264 MAX_NUMBER_OF_INPUT_LINES << " (maximum value)\n";
00265 exit(1);
00266 }
00267
00268 char in_screen[MAX_NUMBER_OF_INPUT_LINES][MAX_NUMBER_OF_COLUMNS];
00269 int i,j;
00270 for (i= 0; i < MAX_NUMBER_OF_INPUT_LINES; i++)
00271 for (j= 0; j < MAX_NUMBER_OF_COLUMNS; j++)
00272 in_screen[i][j] = ' ';
00273
00274 c = 1;
00275
00276 int local_w;
00277
00278 while (c != EOF)
00279 {
00280 local_w = w;
00281 i = 0;
00282 while (local_w && c != EOF)
00283 {
00284
00285 j = 0;
00286 c = getchar();
00287 while (c != '\n' && c != EOF)
00288 {
00289 in_screen[i][j++] = c;
00290 c = getchar();
00291 }
00292 i++;
00293 local_w--;
00294 }
00295
00296 if (c != EOF)
00297 use_square_window_smoothing(in_screen, w);
00298 }
00299 }
00300
00301 #endif
00302
00303