/** * cr_om_parser_simply_parse_buf: *@a_buf: the css2 in memory buffer. *@a_len: the length of the in memory buffer. *@a_enc: the encoding of the in memory buffer. *@a_result: out parameter. The resulting css2 style sheet. * *The simpler way to parse an in memory css2 buffer. * *Returns CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus cr_om_parser_simply_parse_buf (const guchar * a_buf, gulong a_len, enum CREncoding a_enc, CRStyleSheet ** a_result) { CROMParser *parser = NULL; enum CRStatus status = CR_OK; parser = cr_om_parser_new (NULL); if (!parser) { cr_utils_trace_info ("Could not create om parser"); cr_utils_trace_info ("System possibly out of memory"); return CR_ERROR; } status = cr_om_parser_parse_buf (parser, a_buf, a_len, a_enc, a_result); if (parser) { cr_om_parser_destroy (parser); parser = NULL; } return status; }
/** * cr_om_parser_simply_parse_paths_to_cascade: *@a_author_path: the path to the author stylesheet *@a_user_path: the path to the user stylesheet *@a_ua_path: the path to the User Agent stylesheet *@a_encoding: the encoding of the sheets. *@a_result: out parameter. The resulting cascade if the parsing *was okay * *Parses three sheets located by their paths and build a cascade * *Returns CR_OK upon successful completion, an error code otherwise */ enum CRStatus cr_om_parser_simply_parse_paths_to_cascade (const guchar * a_author_path, const guchar * a_user_path, const guchar * a_ua_path, enum CREncoding a_encoding, CRCascade ** a_result) { enum CRStatus status = CR_OK; CROMParser *parser = NULL; parser = cr_om_parser_new (NULL); if (!parser) { cr_utils_trace_info ("could not allocated om parser"); cr_utils_trace_info ("System may be out of memory"); return CR_ERROR; } status = cr_om_parser_parse_paths_to_cascade (parser, a_author_path, a_user_path, a_ua_path, a_encoding, a_result); if (parser) { cr_om_parser_destroy (parser); parser = NULL; } return status; }
/** * cr_om_parser_new: *@a_input: the input stream. * *Constructor of the CROMParser. *Returns the newly built instance of #CROMParser. */ CROMParser * cr_om_parser_new (CRInput * a_input) { CROMParser *result = NULL; enum CRStatus status = CR_OK; result = g_try_malloc (sizeof (CROMParser)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CROMParser)); PRIVATE (result) = g_try_malloc (sizeof (CROMParserPriv)); if (!PRIVATE (result)) { cr_utils_trace_info ("Out of memory"); goto error; } memset (PRIVATE (result), 0, sizeof (CROMParserPriv)); PRIVATE (result)->parser = cr_parser_new_from_input (a_input); if (!PRIVATE (result)->parser) { cr_utils_trace_info ("parsing instanciation failed"); goto error; } status = cr_om_parser_init_default_sac_handler (result); if (status != CR_OK) { goto error; } return result; error: if (result) { cr_om_parser_destroy (result); } return NULL; }
/** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the *cr_input_read_byte() method. Each byte is send to *stdout. *@param a_file_uri the file to read. *@return CR_OK upon successfull completion of the *function, an error code otherwise. */ static enum CRStatus test_cr_parser_parse (guchar * a_file_uri) { enum CRStatus status = CR_OK; CROMParser *parser = NULL; CRStyleSheet *stylesheet = NULL; g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); parser = cr_om_parser_new (NULL); status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, &stylesheet); if (status == CR_OK && stylesheet) { cr_stylesheet_dump (stylesheet, stdout); cr_stylesheet_destroy (stylesheet); } cr_om_parser_destroy (parser); return status; }
/** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the *cr_input_read_byte() method. Each byte is send to *stdout. *@param a_file_uri the file to read. *@return CR_OK upon successfull completion of the *function, an error code otherwise. */ static enum CRStatus test_cr_parser_parse (void) { enum CRStatus status = CR_OK; CROMParser *parser = NULL; CRStyleSheet *stylesheet = NULL; parser = cr_om_parser_new (NULL); status = cr_om_parser_parse_buf (parser, (guchar *) gv_cssbuf, strlen (gv_cssbuf), CR_ASCII, &stylesheet); if (status == CR_OK && stylesheet) { cr_stylesheet_dump (stylesheet, stdout); cr_stylesheet_destroy (stylesheet); } cr_om_parser_destroy (parser); return status; }
/** * cr_om_parser_simply_parse_file: *@a_file_path: the css2 local file path. *@a_enc: the file encoding. *@a_result: out parameter. The returned css stylesheet. *Must be freed by the caller using cr_stylesheet_destroy. * *The simpler method to parse a css2 file. * *Returns CR_OK upon successfull completion, an error code otherwise. *Note that this method uses cr_om_parser_parse_file() so both methods *have the same return values. */ enum CRStatus cr_om_parser_simply_parse_file (const guchar * a_file_path, enum CREncoding a_enc, CRStyleSheet ** a_result) { CROMParser *parser = NULL; enum CRStatus status = CR_OK; parser = cr_om_parser_new (NULL); if (!parser) { cr_utils_trace_info ("Could not allocate om parser"); cr_utils_trace_info ("System may be out of memory"); return CR_ERROR; } status = cr_om_parser_parse_file (parser, a_file_path, a_enc, a_result); if (parser) { cr_om_parser_destroy (parser); parser = NULL; } return status; }