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/textual.h>
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00091 void osl_textual_idump(FILE * file, osl_textual_p textual, int level) {
00092 int j;
00093 char * tmp;
00094
00095
00096 for (j = 0; j < level; j++)
00097 fprintf(file, "|\t");
00098
00099 if (textual != NULL) {
00100 fprintf(file, "+-- osl_textual_t: ");
00101
00102
00103 tmp = strdup(textual->textual);
00104 for (j = 0; j < strlen(tmp); j++)
00105 if (tmp[j] == '\n')
00106 tmp[j] = ' ';
00107
00108 if (strlen(tmp) > 40) {
00109 for (j = 0; j < 20; j++)
00110 fprintf(file, "%c", tmp[j]);
00111 fprintf(file, " ... ");
00112 for (j = strlen(tmp) - 20; j < strlen(tmp); j++)
00113 fprintf(file, "%c", tmp[j]);
00114 fprintf(file, "\n");
00115 }
00116 else {
00117 fprintf(file,"%s\n", tmp);
00118 }
00119 free(tmp);
00120 }
00121 else {
00122 fprintf(file, "+-- NULL textual\n");
00123 }
00124
00125
00126 for (j = 0; j <= level; j++)
00127 fprintf(file, "|\t");
00128 fprintf(file, "\n");
00129 }
00130
00131
00139 void osl_textual_dump(FILE * file, osl_textual_p textual) {
00140 osl_textual_idump(file, textual, 0);
00141 }
00142
00143
00144
00145 #if 0
00146
00153 char * osl_textual_sprint(osl_textual_p textual) {
00154 char * string = NULL;
00155
00156 if ((textual != NULL) && (textual->textual != NULL)) {
00157 if (strlen(textual->textual) > OSL_MAX_STRING)
00158 OSL_error("textual too long");
00159
00160 string = strdup(textual->textual);
00161 if (string == NULL)
00162 OSL_error("memory overflow");
00163 }
00164
00165 return string;
00166 }
00167 #else
00168
00176 char * osl_textual_sprint(osl_textual_p textual) {
00177
00178 return NULL;
00179 }
00180 #endif
00181
00182
00183
00184
00185
00186
00187
00197 osl_textual_p osl_textual_sread(char ** extensions) {
00198 osl_textual_p textual = NULL;
00199
00200 if (*extensions != NULL) {
00201 textual = osl_textual_malloc();
00202 OSL_strdup(textual->textual, *extensions);
00203
00204
00205
00206 *extensions = *extensions + strlen(*extensions);
00207 }
00208
00209 return textual;
00210 }
00211
00212
00213
00214
00215
00216
00217
00226 osl_textual_p osl_textual_malloc() {
00227 osl_textual_p textual;
00228
00229 OSL_malloc(textual, osl_textual_p, sizeof(osl_textual_t));
00230 textual->textual = NULL;
00231
00232 return textual;
00233 }
00234
00235
00242 void osl_textual_free(osl_textual_p textual) {
00243 if (textual != NULL) {
00244 if(textual->textual != NULL)
00245 free(textual->textual);
00246 free(textual);
00247 }
00248 }
00249
00250
00251
00252
00253
00254
00255
00263 osl_textual_p osl_textual_clone(osl_textual_p textual) {
00264 osl_textual_p clone;
00265
00266 if (textual == NULL)
00267 return NULL;
00268
00269 clone = osl_textual_malloc();
00270 OSL_strdup(clone->textual, textual->textual);
00271
00272 return clone;
00273 }
00274
00275
00276 #if 0
00277
00285 int osl_textual_equal(osl_textual_p f1, osl_textual_p f2) {
00286
00287 if (f1 == f2)
00288 return 1;
00289
00290 if (((f1 == NULL) && (f2 != NULL)) || ((f1 != NULL) && (f2 == NULL)))
00291 return 0;
00292
00293 if (strcmp(f1->textual, f2->textual))
00294 return 0;
00295
00296 return 1;
00297 }
00298 #else
00299
00308 int osl_textual_equal(osl_textual_p f1, osl_textual_p f2) {
00309
00310 return 1;
00311 }
00312 #endif
00313
00314
00321 osl_interface_p osl_textual_interface() {
00322 osl_interface_p interface = osl_interface_malloc();
00323
00324 interface->URI = strdup(OSL_URI_TEXTUAL);
00325 interface->idump = (osl_idump_f)osl_textual_idump;
00326 interface->sprint = (osl_sprint_f)osl_textual_sprint;
00327 interface->sread = (osl_sread_f)osl_textual_sread;
00328 interface->malloc = (osl_malloc_f)osl_textual_malloc;
00329 interface->free = (osl_free_f)osl_textual_free;
00330 interface->clone = (osl_clone_f)osl_textual_clone;
00331 interface->equal = (osl_equal_f)osl_textual_equal;
00332
00333 return interface;
00334 }
00335