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