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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #include <stdlib.h>
00064 #include <stdio.h>
00065 #include <string.h>
00066
00067 #include <osl/macros.h>
00068 #include <osl/util.h>
00069 #include <osl/interface.h>
00070 #include <osl/extensions/coordinates.h>
00071
00072
00073
00074
00075
00076
00077
00088 void osl_coordinates_idump(FILE * file, osl_coordinates_p coordinates,
00089 int level) {
00090 int j;
00091
00092
00093 for (j = 0; j < level; j++)
00094 fprintf(file, "|\t");
00095
00096 if (coordinates != NULL)
00097 fprintf(file, "+-- osl_coordinates_t\n");
00098 else
00099 fprintf(file, "+-- NULL coordinates\n");
00100
00101 if (coordinates != NULL) {
00102
00103 for(j = 0; j <= level; j++)
00104 fprintf(file, "|\t");
00105
00106
00107 if (coordinates->name != NULL)
00108 fprintf(file, "File name__: %s\n", coordinates->name);
00109 else
00110 fprintf(file, "NULL file name\n");
00111
00112
00113 for(j = 0; j <= level; j++)
00114 fprintf(file, "|\t");
00115
00116
00117 fprintf(file, "Lines______: [%d, %d]\n",
00118 coordinates->start, coordinates->end);
00119
00120
00121 for(j = 0; j <= level; j++)
00122 fprintf(file, "|\t");
00123
00124
00125 fprintf(file, "Indentation: %d\n", coordinates->indent);
00126 }
00127
00128
00129 for (j = 0; j <= level; j++)
00130 fprintf(file, "|\t");
00131 fprintf(file, "\n");
00132 }
00133
00134
00142 void osl_coordinates_dump(FILE * file, osl_coordinates_p coordinates) {
00143 osl_coordinates_idump(file, coordinates, 0);
00144 }
00145
00146
00154 char * osl_coordinates_sprint(osl_coordinates_p coordinates) {
00155 int high_water_mark = OSL_MAX_STRING;
00156 char * string = NULL;
00157 char buffer[OSL_MAX_STRING];
00158
00159 if (coordinates != NULL) {
00160 OSL_malloc(string, char *, high_water_mark * sizeof(char));
00161 string[0] = '\0';
00162
00163
00164 sprintf(buffer, "# File name\n%s\n", coordinates->name);
00165 osl_util_safe_strcat(&string, buffer, &high_water_mark);
00166
00167 sprintf(buffer, "# Starting line\n%d\n", coordinates->start);
00168 osl_util_safe_strcat(&string, buffer, &high_water_mark);
00169
00170 sprintf(buffer, "# Ending line\n%d\n", coordinates->end);
00171 osl_util_safe_strcat(&string, buffer, &high_water_mark);
00172
00173 sprintf(buffer, "# Indentation\n%d\n", coordinates->indent);
00174 osl_util_safe_strcat(&string, buffer, &high_water_mark);
00175
00176
00177 OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
00178 }
00179
00180 return string;
00181 }
00182
00183
00184
00185
00186
00187
00188
00199 osl_coordinates_p osl_coordinates_sread(char ** input) {
00200 osl_coordinates_p coordinates;
00201
00202 if (*input == NULL) {
00203 OSL_debug("no coordinates optional tag");
00204 return NULL;
00205 }
00206
00207
00208 coordinates = osl_coordinates_malloc();
00209
00210
00211 coordinates->name = osl_util_read_line(NULL, input);
00212
00213
00214 coordinates->start = osl_util_read_int(NULL, input);
00215
00216
00217 coordinates->end = osl_util_read_int(NULL, input);
00218
00219
00220 coordinates->indent = osl_util_read_int(NULL, input);
00221
00222 return coordinates;
00223 }
00224
00225
00226
00227
00228
00229
00230
00239 osl_coordinates_p osl_coordinates_malloc() {
00240 osl_coordinates_p coordinates;
00241
00242 OSL_malloc(coordinates, osl_coordinates_p, sizeof(osl_coordinates_t));
00243 coordinates->name = NULL;
00244 coordinates->start = OSL_UNDEFINED;
00245 coordinates->end = OSL_UNDEFINED;
00246 coordinates->indent = OSL_UNDEFINED;
00247
00248 return coordinates;
00249 }
00250
00251
00258 void osl_coordinates_free(osl_coordinates_p coordinates) {
00259 if (coordinates != NULL) {
00260 free(coordinates->name);
00261 free(coordinates);
00262 }
00263 }
00264
00265
00266
00267
00268
00269
00270
00278 osl_coordinates_p osl_coordinates_clone(osl_coordinates_p coordinates) {
00279 osl_coordinates_p clone;
00280
00281 if (coordinates == NULL)
00282 return NULL;
00283
00284 clone = osl_coordinates_malloc();
00285 OSL_strdup(clone->name, coordinates->name);
00286 clone->start = coordinates->start;
00287 clone->end = coordinates->end;
00288 clone->indent = coordinates->indent;
00289
00290 return clone;
00291 }
00292
00293
00302 int osl_coordinates_equal(osl_coordinates_p c1, osl_coordinates_p c2) {
00303 if (c1 == c2)
00304 return 1;
00305
00306 if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL)))
00307 return 0;
00308
00309 if (strcmp(c1->name, c2->name)) {
00310 OSL_info("file names are not the same");
00311 return 0;
00312 }
00313
00314 if (c1->start != c2->start) {
00315 OSL_info("starting lines are not the same");
00316 return 0;
00317 }
00318
00319 if (c1->indent != c2->indent) {
00320 OSL_info("indentations are not the same");
00321 return 0;
00322 }
00323
00324 return 1;
00325 }
00326
00327
00334 osl_interface_p osl_coordinates_interface() {
00335 osl_interface_p interface = osl_interface_malloc();
00336
00337 interface->URI = strdup(OSL_URI_COORDINATES);
00338 interface->idump = (osl_idump_f)osl_coordinates_idump;
00339 interface->sprint = (osl_sprint_f)osl_coordinates_sprint;
00340 interface->sread = (osl_sread_f)osl_coordinates_sread;
00341 interface->malloc = (osl_malloc_f)osl_coordinates_malloc;
00342 interface->free = (osl_free_f)osl_coordinates_free;
00343 interface->clone = (osl_clone_f)osl_coordinates_clone;
00344 interface->equal = (osl_equal_f)osl_coordinates_equal;
00345
00346 return interface;
00347 }
00348