1 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset:8 -*- */
4 *This is an example that shows how to use
5 *the CSSOM api of the libcroco CSS2 parsing library.
6 *It just parses the CSS document given in argument and
7 *it dumps it (serializes) it on the screen.
9 *To compile it using gcc, type
11 *gcc -g -Wall `croco-0.6-config --cflags` `croco-0.6-config --libs` -o cssom-example-1 cssom-example-1.c
13 *Prior to that, you must have compiled and installed libcroco, of course.
15 *@author Dodji Seketeli
19 #include <libcroco/libcroco.h>
22 *Displays the usage of this program.
23 *@param prg_name the name of the program.
26 display_usage (char *prg_name)
28 printf ("\nusage: %s [options] <css file to parse>\n\n",
30 printf ("\twhere options are:\n") ;
31 printf ("\t--help|h\tdisplays this help\n") ;
38 *This function illustrates a way to use libcroco.
39 *In this example, we will use a CSS Object Model parser
40 *to parse a cascading style sheet and dump what we have parsed on stdout.
42 *The goal of the object model parser is to parse a css and build
43 *an abstract tree out of it. One can then walk the tree to perform
44 *whatever action he wants. In our case, the function used to
45 *dump the tree on stdout will walk the tree and dump each one of its
46 *components (a.k.a. css statements).
49 main (int argc, char **argv)
52 enum CRStatus status = CR_OK ;
53 CRStyleSheet *stylesheet = NULL ;
55 /*first parse command line arguments*/
56 for (i = 1 ; i < argc ; i++)
58 if (argv[i][0] != '-')
60 if (!strcmp (argv[i],"--help")
61 || !strcmp (argv[i], "-h"))
63 display_usage (argv[0]) ;
68 display_usage (argv[0]) ;
74 display_usage (argv[0]) ;
78 /*****************************************************
79 *Enough plumbering... now, the real libcroco stuffs.
80 ***************************************************/
83 *What we want here is to simply parse
84 *a CSS document using the cssom api.
86 status = cr_om_parser_simply_parse_file ((const guchar*)argv[i] /*sheet*/,
87 CR_ASCII /*the encoding*/,
89 if (status == CR_OK && stylesheet)
92 *everything went well,
93 *so dump the stylesheet on stdout.
95 cr_stylesheet_dump (stylesheet, stdout) ;
101 *free the the memory used to hold the css
104 cr_stylesheet_destroy (stylesheet) ;