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 #include <string.h>
00030 #include "cr-token.h"
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 static void
00042 cr_token_clear (CRToken * a_this)
00043 {
00044 g_return_if_fail (a_this);
00045
00046 switch (a_this->type) {
00047 case S_TK:
00048 case CDO_TK:
00049 case INCLUDES_TK:
00050 case DASHMATCH_TK:
00051 case PAGE_SYM_TK:
00052 case MEDIA_SYM_TK:
00053 case FONT_FACE_SYM_TK:
00054 case CHARSET_SYM_TK:
00055 case IMPORT_SYM_TK:
00056 case IMPORTANT_SYM_TK:
00057 case SEMICOLON_TK:
00058 case NO_TK:
00059 case DELIM_TK:
00060 case CBO_TK:
00061 case CBC_TK:
00062 case BO_TK:
00063 case BC_TK:
00064 break;
00065
00066 case STRING_TK:
00067 case IDENT_TK:
00068 case HASH_TK:
00069 case URI_TK:
00070 case FUNCTION_TK:
00071 case COMMENT_TK:
00072 case ATKEYWORD_TK:
00073 if (a_this->u.str) {
00074 cr_string_destroy (a_this->u.str);
00075 a_this->u.str = NULL;
00076 }
00077 break;
00078
00079 case EMS_TK:
00080 case EXS_TK:
00081 case LENGTH_TK:
00082 case ANGLE_TK:
00083 case TIME_TK:
00084 case FREQ_TK:
00085 case PERCENTAGE_TK:
00086 case NUMBER_TK:
00087 case PO_TK:
00088 case PC_TK:
00089 if (a_this->u.num) {
00090 cr_num_destroy (a_this->u.num);
00091 a_this->u.num = NULL;
00092 }
00093 break;
00094
00095 case DIMEN_TK:
00096 if (a_this->u.num) {
00097 cr_num_destroy (a_this->u.num);
00098 a_this->u.num = NULL;
00099 }
00100
00101 if (a_this->dimen) {
00102 cr_string_destroy (a_this->dimen);
00103 a_this->dimen = NULL;
00104 }
00105
00106 break;
00107
00108 case RGB_TK:
00109 if (a_this->u.rgb) {
00110 cr_rgb_destroy (a_this->u.rgb) ;
00111 a_this->u.rgb = NULL ;
00112 }
00113 break ;
00114
00115 case UNICODERANGE_TK:
00116
00117 break;
00118
00119 default:
00120 cr_utils_trace_info ("I don't know how to clear this token\n") ;
00121 break;
00122 }
00123
00124 a_this->type = NO_TK;
00125 }
00126
00127
00128
00129
00130
00131
00132 CRToken *
00133 cr_token_new (void)
00134 {
00135 CRToken *result = NULL;
00136
00137 result = g_try_malloc (sizeof (CRToken));
00138
00139 if (result == NULL) {
00140 cr_utils_trace_info ("Out of memory");
00141 return NULL;
00142 }
00143
00144 memset (result, 0, sizeof (CRToken));
00145
00146 return result;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156 enum CRStatus
00157 cr_token_set_s (CRToken * a_this)
00158 {
00159 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00160
00161 cr_token_clear (a_this);
00162
00163 a_this->type = S_TK;
00164
00165 return CR_OK;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175 enum CRStatus
00176 cr_token_set_cdo (CRToken * a_this)
00177 {
00178 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00179
00180 cr_token_clear (a_this);
00181
00182 a_this->type = CDO_TK;
00183
00184 return CR_OK;
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00194 enum CRStatus
00195 cr_token_set_cdc (CRToken * a_this)
00196 {
00197 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00198
00199 cr_token_clear (a_this);
00200
00201 a_this->type = CDC_TK;
00202
00203 return CR_OK;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213 enum CRStatus
00214 cr_token_set_includes (CRToken * a_this)
00215 {
00216 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00217
00218 cr_token_clear (a_this);
00219
00220 a_this->type = INCLUDES_TK;
00221
00222 return CR_OK;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232 enum CRStatus
00233 cr_token_set_dashmatch (CRToken * a_this)
00234 {
00235 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00236
00237 cr_token_clear (a_this);
00238
00239 a_this->type = DASHMATCH_TK;
00240
00241 return CR_OK;
00242 }
00243
00244 enum CRStatus
00245 cr_token_set_comment (CRToken * a_this, CRString * a_str)
00246 {
00247 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00248
00249 cr_token_clear (a_this);
00250 a_this->type = COMMENT_TK;
00251 a_this->u.str = a_str ;
00252 return CR_OK;
00253 }
00254
00255 enum CRStatus
00256 cr_token_set_string (CRToken * a_this, CRString * a_str)
00257 {
00258 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00259
00260 cr_token_clear (a_this);
00261
00262 a_this->type = STRING_TK;
00263
00264 a_this->u.str = a_str ;
00265
00266 return CR_OK;
00267 }
00268
00269 enum CRStatus
00270 cr_token_set_ident (CRToken * a_this, CRString * a_ident)
00271 {
00272 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00273
00274 cr_token_clear (a_this);
00275 a_this->type = IDENT_TK;
00276 a_this->u.str = a_ident;
00277 return CR_OK;
00278 }
00279
00280
00281 enum CRStatus
00282 cr_token_set_function (CRToken * a_this, CRString * a_fun_name)
00283 {
00284 g_return_val_if_fail (a_this,
00285 CR_BAD_PARAM_ERROR);
00286
00287 cr_token_clear (a_this);
00288 a_this->type = FUNCTION_TK;
00289 a_this->u.str = a_fun_name;
00290 return CR_OK;
00291 }
00292
00293 enum CRStatus
00294 cr_token_set_hash (CRToken * a_this, CRString * a_hash)
00295 {
00296 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00297
00298 cr_token_clear (a_this);
00299 a_this->type = HASH_TK;
00300 a_this->u.str = a_hash;
00301
00302 return CR_OK;
00303 }
00304
00305 enum CRStatus
00306 cr_token_set_rgb (CRToken * a_this, CRRgb * a_rgb)
00307 {
00308 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00309
00310 cr_token_clear (a_this);
00311 a_this->type = RGB_TK;
00312 a_this->u.rgb = a_rgb;
00313
00314 return CR_OK;
00315 }
00316
00317 enum CRStatus
00318 cr_token_set_import_sym (CRToken * a_this)
00319 {
00320 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00321
00322 cr_token_clear (a_this);
00323
00324 a_this->type = IMPORT_SYM_TK;
00325
00326 return CR_OK;
00327 }
00328
00329 enum CRStatus
00330 cr_token_set_page_sym (CRToken * a_this)
00331 {
00332 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00333
00334 cr_token_clear (a_this);
00335
00336 a_this->type = PAGE_SYM_TK;
00337
00338 return CR_OK;
00339 }
00340
00341 enum CRStatus
00342 cr_token_set_media_sym (CRToken * a_this)
00343 {
00344 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00345
00346 cr_token_clear (a_this);
00347
00348 a_this->type = MEDIA_SYM_TK;
00349
00350 return CR_OK;
00351 }
00352
00353 enum CRStatus
00354 cr_token_set_font_face_sym (CRToken * a_this)
00355 {
00356 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00357
00358 cr_token_clear (a_this);
00359 a_this->type = FONT_FACE_SYM_TK;
00360
00361 return CR_OK;
00362 }
00363
00364 enum CRStatus
00365 cr_token_set_charset_sym (CRToken * a_this)
00366 {
00367 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00368
00369 cr_token_clear (a_this);
00370 a_this->type = CHARSET_SYM_TK;
00371
00372 return CR_OK;
00373 }
00374
00375 enum CRStatus
00376 cr_token_set_atkeyword (CRToken * a_this, CRString * a_atname)
00377 {
00378 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00379
00380 cr_token_clear (a_this);
00381 a_this->type = ATKEYWORD_TK;
00382 a_this->u.str = a_atname;
00383 return CR_OK;
00384 }
00385
00386 enum CRStatus
00387 cr_token_set_important_sym (CRToken * a_this)
00388 {
00389 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00390 cr_token_clear (a_this);
00391 a_this->type = IMPORTANT_SYM_TK;
00392 return CR_OK;
00393 }
00394
00395 enum CRStatus
00396 cr_token_set_ems (CRToken * a_this, CRNum * a_num)
00397 {
00398 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00399 cr_token_clear (a_this);
00400 a_this->type = EMS_TK;
00401 a_this->u.num = a_num;
00402 return CR_OK;
00403 }
00404
00405 enum CRStatus
00406 cr_token_set_exs (CRToken * a_this, CRNum * a_num)
00407 {
00408 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00409 cr_token_clear (a_this);
00410 a_this->type = EXS_TK;
00411 a_this->u.num = a_num;
00412 return CR_OK;
00413 }
00414
00415 enum CRStatus
00416 cr_token_set_length (CRToken * a_this, CRNum * a_num,
00417 enum CRTokenExtraType a_et)
00418 {
00419 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00420
00421 cr_token_clear (a_this);
00422
00423 a_this->type = LENGTH_TK;
00424 a_this->extra_type = a_et;
00425 a_this->u.num = a_num;
00426
00427 return CR_OK;
00428 }
00429
00430 enum CRStatus
00431 cr_token_set_angle (CRToken * a_this, CRNum * a_num,
00432 enum CRTokenExtraType a_et)
00433 {
00434 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00435
00436 cr_token_clear (a_this);
00437
00438 a_this->type = ANGLE_TK;
00439 a_this->extra_type = a_et;
00440 a_this->u.num = a_num;
00441
00442 return CR_OK;
00443 }
00444
00445 enum CRStatus
00446 cr_token_set_time (CRToken * a_this, CRNum * a_num,
00447 enum CRTokenExtraType a_et)
00448 {
00449 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00450
00451 cr_token_clear (a_this);
00452
00453 a_this->type = TIME_TK;
00454 a_this->extra_type = a_et;
00455 a_this->u.num = a_num;
00456
00457 return CR_OK;
00458 }
00459
00460 enum CRStatus
00461 cr_token_set_freq (CRToken * a_this, CRNum * a_num,
00462 enum CRTokenExtraType a_et)
00463 {
00464 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00465
00466 cr_token_clear (a_this);
00467
00468 a_this->type = FREQ_TK;
00469 a_this->extra_type = a_et;
00470 a_this->u.num = a_num;
00471
00472 return CR_OK;
00473 }
00474
00475 enum CRStatus
00476 cr_token_set_dimen (CRToken * a_this, CRNum * a_num,
00477 CRString * a_dim)
00478 {
00479 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00480 cr_token_clear (a_this);
00481 a_this->type = DIMEN_TK;
00482 a_this->u.num = a_num;
00483 a_this->dimen = a_dim;
00484 return CR_OK;
00485
00486 }
00487
00488 enum CRStatus
00489 cr_token_set_percentage (CRToken * a_this, CRNum * a_num)
00490 {
00491 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00492
00493 cr_token_clear (a_this);
00494
00495 a_this->type = PERCENTAGE_TK;
00496 a_this->u.num = a_num;
00497
00498 return CR_OK;
00499 }
00500
00501 enum CRStatus
00502 cr_token_set_number (CRToken * a_this, CRNum * a_num)
00503 {
00504 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00505
00506 cr_token_clear (a_this);
00507
00508 a_this->type = NUMBER_TK;
00509 a_this->u.num = a_num;
00510 return CR_OK;
00511 }
00512
00513 enum CRStatus
00514 cr_token_set_uri (CRToken * a_this, CRString * a_uri)
00515 {
00516 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00517
00518 cr_token_clear (a_this);
00519
00520 a_this->type = URI_TK;
00521 a_this->u.str = a_uri;
00522
00523 return CR_OK;
00524 }
00525
00526 enum CRStatus
00527 cr_token_set_delim (CRToken * a_this, guint32 a_char)
00528 {
00529 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00530
00531 cr_token_clear (a_this);
00532
00533 a_this->type = DELIM_TK;
00534 a_this->u.unichar = a_char;
00535
00536 return CR_OK;
00537 }
00538
00539 enum CRStatus
00540 cr_token_set_semicolon (CRToken * a_this)
00541 {
00542 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00543
00544 cr_token_clear (a_this);
00545
00546 a_this->type = SEMICOLON_TK;
00547
00548 return CR_OK;
00549 }
00550
00551 enum CRStatus
00552 cr_token_set_cbo (CRToken * a_this)
00553 {
00554 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00555
00556 cr_token_clear (a_this);
00557
00558 a_this->type = CBO_TK;
00559
00560 return CR_OK;
00561 }
00562
00563 enum CRStatus
00564 cr_token_set_cbc (CRToken * a_this)
00565 {
00566 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00567
00568 cr_token_clear (a_this);
00569
00570 a_this->type = CBC_TK;
00571
00572 return CR_OK;
00573 }
00574
00575 enum CRStatus
00576 cr_token_set_po (CRToken * a_this)
00577 {
00578 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00579
00580 cr_token_clear (a_this);
00581
00582 a_this->type = PO_TK;
00583
00584 return CR_OK;
00585 }
00586
00587 enum CRStatus
00588 cr_token_set_pc (CRToken * a_this)
00589 {
00590 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00591
00592 cr_token_clear (a_this);
00593
00594 a_this->type = PC_TK;
00595
00596 return CR_OK;
00597 }
00598
00599 enum CRStatus
00600 cr_token_set_bo (CRToken * a_this)
00601 {
00602 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00603
00604 cr_token_clear (a_this);
00605
00606 a_this->type = BO_TK;
00607
00608 return CR_OK;
00609 }
00610
00611 enum CRStatus
00612 cr_token_set_bc (CRToken * a_this)
00613 {
00614 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00615
00616 cr_token_clear (a_this);
00617
00618 a_this->type = BC_TK;
00619
00620 return CR_OK;
00621 }
00622
00623
00624
00625
00626
00627 void
00628 cr_token_destroy (CRToken * a_this)
00629 {
00630 g_return_if_fail (a_this);
00631
00632 cr_token_clear (a_this);
00633
00634 g_free (a_this);
00635 }