Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

cr-token.c

Go to the documentation of this file.
00001 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
00002 
00003 /*
00004  * This file is part of The Croco Library
00005  *
00006  * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of version 2.1 of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00020  * USA
00021  */
00022 
00023 /*
00024  *$Id: cr-token.c,v 1.2 2003/04/21 18:05:13 dodji Exp $
00025  */
00026 
00027 /**
00028  *@file
00029  *The definition of the #CRToken class.
00030  *Abstracts a css2 token.
00031  */
00032 #include <string.h>
00033 #include "cr-token.h"
00034 
00035 
00036 /**
00037  *Frees the attributes of the current instance
00038  *of #CRtoken.
00039  *@param a_this the current instance of #CRToken.
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         {
00048         case S_TK:
00049         case CDO_TK:
00050         case INCLUDES_TK:
00051         case DASHMATCH_TK:
00052         case PAGE_SYM_TK:
00053         case MEDIA_SYM_TK:
00054         case FONT_FACE_SYM_TK:
00055         case CHARSET_SYM_TK:
00056         case IMPORT_SYM_TK:
00057         case IMPORTANT_SYM_TK:        
00058                 break ;
00059 
00060         case STRING_TK:
00061         case IDENT_TK:
00062         case HASH_TK:
00063         case URI_TK:
00064         case FUNCTION_TK:
00065         case COMMENT_TK:
00066                 if (a_this->u.str)
00067                 {
00068                         g_string_free (a_this->u.str, TRUE) ;
00069                         a_this->u.str = NULL ;
00070                 }
00071                 break ;
00072         
00073         case EMS_TK:
00074         case EXS_TK:
00075         case LENGTH_TK:
00076         case ANGLE_TK:
00077         case TIME_TK:
00078         case FREQ_TK:
00079         case PERCENTAGE_TK:
00080         case NUMBER_TK:
00081                 if (a_this->u.num)
00082                 {
00083                         cr_num_destroy (a_this->u.num) ;
00084                         a_this->u.num = NULL ;
00085                 }
00086                 break ;
00087         
00088         case DIMEN_TK:
00089                 if (a_this->u.num)
00090                 {
00091                         cr_num_destroy (a_this->u.num) ;
00092                         a_this->u.num = NULL ;
00093                 }
00094         
00095                 if (a_this->dimen)
00096                 {
00097                         g_string_free (a_this->dimen, TRUE) ;
00098                         a_this->dimen = NULL ;
00099                 }
00100         
00101                 break ;
00102                 
00103         case UNICODERANGE_TK:
00104                 /*not supported yet.*/
00105                 break ; 
00106         
00107         default:
00108                 break ;
00109         }
00110     
00111         a_this->type = NO_TK ;
00112 }
00113 
00114 
00115 /**
00116  *Default constructor of
00117  *the #CRToken class.
00118  *@return the newly built instance of #CRToken.
00119  */
00120 CRToken*
00121 cr_token_new (void)
00122 {
00123         CRToken *result = NULL ;
00124 
00125         result = g_try_malloc (sizeof (CRToken)) ;
00126 
00127         if (result == NULL)
00128         {
00129                 cr_utils_trace_info ("Out of memory") ;
00130                 return NULL ;
00131         }
00132 
00133         memset (result, 0, sizeof (CRToken)) ;
00134 
00135         return result ;
00136 }
00137 
00138 
00139 /**
00140  *Sets the type of curren instance of
00141  *#CRToken to 'S_TK' (S in the css2 spec)
00142  *@param a_this the current instance of #CRToken.
00143  *@return CR_OK upon successfull completion, an error
00144  *code otherwise.
00145  */
00146 enum CRStatus
00147 cr_token_set_s (CRToken *a_this)
00148 {
00149         g_return_val_if_fail (a_this,
00150                               CR_BAD_PARAM_ERROR) ;
00151         
00152         cr_token_clear (a_this) ;
00153 
00154         a_this->type = S_TK ;
00155         
00156         return CR_OK ;
00157 }
00158 
00159 
00160 /**
00161  *Sets the type of the current instance of
00162  *#CRToken to 'CDO_TK' (CDO as said by the css2 spec)
00163  *@param a_this the current instance of #CRToken.
00164  *@return CR_OK upon successfull completion, an error
00165  *code otherwise.
00166  */
00167 enum CRStatus
00168 cr_token_set_cdo (CRToken *a_this)
00169 {
00170         g_return_val_if_fail (a_this,
00171                               CR_BAD_PARAM_ERROR) ;
00172         
00173         cr_token_clear (a_this) ;
00174 
00175         a_this->type = CDO_TK ;
00176 
00177         return CR_OK ;
00178 }
00179 
00180 /**
00181  *Sets the type of the current token to
00182  *CDC_TK (CDC as said by the css2 spec).
00183  *@param a_this the current instance of #CRToken.
00184  *@return CR_OK upon successfull completion, an error
00185  *code otherwise.
00186  */
00187 enum CRStatus
00188 cr_token_set_cdc (CRToken *a_this)
00189 {
00190         g_return_val_if_fail (a_this,
00191                               CR_BAD_PARAM_ERROR) ;
00192         
00193         cr_token_clear (a_this) ;
00194 
00195         a_this->type = CDC_TK ;
00196 
00197         return CR_OK ;
00198 }
00199 
00200 
00201 /**
00202  *Sets the type of the current instance of
00203  *#CRToken to INCLUDES_TK (INCLUDES as said by the css2 spec).
00204  *@param a_this the current instance of #CRToken.
00205  *@return CR_OK upon successfull completion, an error
00206  *code otherwise.
00207  */
00208 enum CRStatus
00209 cr_token_set_includes (CRToken *a_this)
00210 {
00211         g_return_val_if_fail (a_this,
00212                               CR_BAD_PARAM_ERROR) ;
00213         
00214         cr_token_clear (a_this) ;
00215 
00216         a_this->type = INCLUDES_TK ;
00217 
00218         return CR_OK ;
00219 }
00220 
00221 
00222 /**
00223  *Sets the type of the current instance of
00224  *#CRToken to DASHMATCH_TK (DASHMATCH as said by the css2 spec).
00225  *@param a_this the current instance of #CRToken.
00226  *@return CR_OK upon successfull completion, an error
00227  *code otherwise.
00228  */
00229 enum CRStatus
00230 cr_token_set_dashmatch (CRToken *a_this)
00231 {
00232         g_return_val_if_fail (a_this,
00233                               CR_BAD_PARAM_ERROR) ;
00234         
00235         cr_token_clear (a_this) ;
00236 
00237         a_this->type = DASHMATCH_TK ;
00238 
00239         return CR_OK ;
00240 }
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 
00272 enum CRStatus
00273 cr_token_set_ident (CRToken *a_this, GString * a_ident)
00274 {
00275         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00276 
00277         cr_token_clear (a_this) ;
00278 
00279         a_this->type = IDENT_TK ;
00280 
00281         a_this->u.str = a_ident ;
00282 
00283         return CR_OK ;
00284 }
00285 
00286 
00287 enum CRStatus
00288 cr_token_set_function (CRToken *a_this, GString *a_fun_name)
00289 {
00290         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00291 
00292         cr_token_clear (a_this) ;
00293 
00294         a_this->type = FUNCTION_TK ;
00295 
00296         a_this->u.str = a_fun_name ;
00297 
00298         return CR_OK ;
00299 }
00300 
00301 enum CRStatus
00302 cr_token_set_hash (CRToken *a_this, GString *a_hash)
00303 {
00304         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00305 
00306         cr_token_clear (a_this) ;
00307 
00308         a_this->type = HASH_TK ;
00309 
00310         a_this->u.str = a_hash ;
00311 
00312         return CR_OK ;
00313 }
00314 
00315 enum CRStatus
00316 cr_token_set_rgb (CRToken *a_this, CRRgb *a_rgb)
00317 {
00318         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00319 
00320         cr_token_clear (a_this) ;
00321 
00322         a_this->type = RGB_TK ;
00323 
00324         a_this->u.rgb = a_rgb ;
00325 
00326         return CR_OK ;
00327 }
00328 
00329 enum CRStatus
00330 cr_token_set_import_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 = IMPORT_SYM_TK ;
00337 
00338         return CR_OK ;
00339 }
00340 
00341 enum CRStatus
00342 cr_token_set_page_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 = PAGE_SYM_TK ;
00349 
00350         return CR_OK ;
00351 }
00352 
00353 
00354 enum CRStatus
00355 cr_token_set_media_sym (CRToken *a_this)
00356 {
00357         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00358 
00359         cr_token_clear (a_this) ;
00360 
00361         a_this->type = MEDIA_SYM_TK ;
00362 
00363         return CR_OK ;
00364 }
00365 
00366 enum CRStatus
00367 cr_token_set_font_face_sym (CRToken *a_this)
00368 {
00369         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00370 
00371         cr_token_clear (a_this) ;
00372 
00373         a_this->type = FONT_FACE_SYM_TK ;
00374 
00375         return CR_OK ;
00376 }
00377 
00378 
00379 enum CRStatus
00380 cr_token_set_charset_sym (CRToken *a_this)
00381 {
00382         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00383 
00384         cr_token_clear (a_this) ;
00385 
00386         a_this->type = CHARSET_SYM_TK ;
00387 
00388         return CR_OK ;
00389 }
00390 
00391 enum CRStatus
00392 cr_token_set_atkeyword (CRToken *a_this, GString *a_atname)
00393 {
00394         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00395 
00396         cr_token_clear (a_this) ;
00397 
00398         a_this->type = ATKEYWORD_TK ;
00399 
00400         a_this->u.str = a_atname ;
00401 
00402         return CR_OK ;
00403 }
00404 
00405 enum CRStatus
00406 cr_token_set_important_sym (CRToken *a_this)
00407 {
00408         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00409 
00410         cr_token_clear (a_this) ;
00411 
00412         a_this->type = IMPORTANT_SYM_TK ;
00413 
00414         return CR_OK ;
00415 }
00416 
00417 enum CRStatus
00418 cr_token_set_ems (CRToken *a_this, CRNum *a_num)
00419 {
00420         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00421 
00422         cr_token_clear (a_this) ;
00423 
00424         a_this->type = EMS_TK ;
00425 
00426         a_this->u.num = a_num ;
00427 
00428         return CR_OK ;
00429 }
00430 
00431 
00432 enum CRStatus
00433 cr_token_set_exs (CRToken *a_this, CRNum *a_num)
00434 {
00435         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00436 
00437         cr_token_clear (a_this) ;
00438 
00439         a_this->type = EXS_TK ;
00440 
00441         a_this->u.num = a_num ;
00442 
00443         return CR_OK ;
00444 }
00445 
00446 enum CRStatus
00447 cr_token_set_length (CRToken *a_this, CRNum *a_num,
00448                      enum CRTokenExtraType a_et)
00449 {
00450         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00451 
00452         cr_token_clear (a_this) ;
00453 
00454         a_this->type = LENGTH_TK ;
00455         
00456         a_this->extra_type = a_et ;
00457         a_this->u.num = a_num ;
00458 
00459         return CR_OK ;
00460 }
00461 
00462 enum CRStatus
00463 cr_token_set_angle (CRToken *a_this, CRNum *a_num,
00464                     enum CRTokenExtraType a_et)
00465 {
00466         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00467 
00468         cr_token_clear (a_this) ;
00469 
00470         a_this->type = ANGLE_TK ;
00471         a_this->extra_type = a_et ;
00472         a_this->u.num = a_num ;
00473 
00474         return CR_OK ;
00475 }
00476 
00477 enum CRStatus
00478 cr_token_set_time (CRToken *a_this, CRNum *a_num,
00479                    enum CRTokenExtraType a_et)
00480 {
00481         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00482 
00483         cr_token_clear (a_this) ;
00484 
00485         a_this->type = TIME_TK ;
00486         a_this->extra_type = a_et;
00487         a_this->u.num = a_num ;
00488 
00489         return CR_OK ;
00490 }
00491 
00492 enum CRStatus
00493 cr_token_set_freq (CRToken *a_this, CRNum *a_num,
00494                    enum CRTokenExtraType a_et)
00495 {
00496         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00497 
00498         cr_token_clear (a_this) ;
00499 
00500         a_this->type = FREQ_TK ;
00501         a_this->extra_type = a_et ;
00502         a_this->u.num = a_num ;
00503 
00504         return CR_OK ;
00505 }
00506 
00507 enum CRStatus
00508 cr_token_set_dimen (CRToken *a_this, CRNum *a_num,
00509                     GString *a_dim)
00510 {
00511         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00512 
00513         cr_token_clear (a_this) ;
00514 
00515         a_this->type = DIMEN_TK ;
00516         a_this->u.num = a_num ;
00517         a_this->dimen = a_dim ;
00518 
00519         return CR_OK ;
00520         
00521 }
00522 
00523 
00524 enum CRStatus
00525 cr_token_set_percentage (CRToken *a_this, CRNum *a_num)
00526 {
00527         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00528 
00529         cr_token_clear (a_this) ;
00530 
00531         a_this->type = PERCENTAGE_TK ;
00532         a_this->u.num = a_num ;
00533 
00534         return CR_OK ;
00535 }
00536 
00537 enum CRStatus
00538 cr_token_set_number (CRToken *a_this, CRNum *a_num)
00539 {
00540         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00541 
00542         cr_token_clear (a_this) ;
00543 
00544         a_this->type = NUMBER_TK ;
00545         a_this->u.num = a_num ;
00546 
00547         return CR_OK ;
00548 }
00549 
00550 enum CRStatus
00551 cr_token_set_uri (CRToken *a_this, GString *a_uri)
00552 {
00553         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00554 
00555         cr_token_clear (a_this) ;
00556 
00557         a_this->type = URI_TK ;
00558         a_this->u.str = a_uri ;
00559 
00560         return CR_OK ;
00561 }
00562 
00563 
00564 enum CRStatus
00565 cr_token_set_delim (CRToken *a_this, guint32 a_char)
00566 {
00567         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00568 
00569         cr_token_clear (a_this) ;
00570 
00571         a_this->type = DELIM_TK ;
00572         a_this->u.unichar = a_char ;
00573 
00574         return CR_OK ;
00575 }
00576 
00577 enum CRStatus
00578 cr_token_set_semicolon (CRToken *a_this)
00579 {
00580         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00581 
00582         cr_token_clear (a_this) ;
00583 
00584         a_this->type = SEMICOLON_TK ;
00585 
00586         return CR_OK ;
00587 }
00588 
00589 enum CRStatus
00590 cr_token_set_cbo (CRToken *a_this)
00591 {
00592         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00593 
00594         cr_token_clear (a_this) ;
00595 
00596         a_this->type = CBO_TK ;
00597 
00598         return CR_OK ;
00599 }
00600 
00601 enum CRStatus
00602 cr_token_set_cbc (CRToken *a_this)
00603 {
00604         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00605 
00606         cr_token_clear (a_this) ;
00607 
00608         a_this->type = CBC_TK ;
00609 
00610         return CR_OK ;
00611 }
00612 
00613 enum CRStatus
00614 cr_token_set_po (CRToken *a_this)
00615 {
00616         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00617 
00618         cr_token_clear (a_this) ;
00619 
00620         a_this->type = PO_TK ;
00621 
00622         return CR_OK ;
00623 }
00624 
00625 enum CRStatus
00626 cr_token_set_pc (CRToken *a_this)
00627 {
00628         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00629 
00630         cr_token_clear (a_this) ;
00631 
00632         a_this->type = PC_TK ;
00633 
00634         return CR_OK ;
00635 }
00636 
00637 enum CRStatus
00638 cr_token_set_bo (CRToken *a_this)
00639 {
00640         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00641 
00642         cr_token_clear (a_this) ;
00643 
00644         a_this->type = BO_TK ;
00645 
00646         return CR_OK ;
00647 }
00648 
00649 enum CRStatus
00650 cr_token_set_bc (CRToken *a_this)
00651 {
00652         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00653 
00654         cr_token_clear (a_this) ;
00655 
00656         a_this->type = BC_TK ;
00657 
00658         return CR_OK ;
00659 }
00660 
00661 
00662 /**
00663  *The destructor of the #CRToken class.
00664  *@param a_this the current instance of #CRToken.
00665  */
00666 void
00667 cr_token_destroy (CRToken *a_this)
00668 {
00669         g_return_if_fail (a_this) ;
00670 
00671         cr_token_clear (a_this) ;
00672 
00673         g_free (a_this) ;
00674 }

Generated on Wed Oct 1 01:36:49 2003 for Libcroco by doxygen 1.3.3