/** * cr_om_parser_parse_paths_to_cascade: *@a_this: the current instance of #CROMParser *@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_parse_paths_to_cascade (CROMParser * a_this, 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; /*0->author sheet, 1->user sheet, 2->UA sheet */ CRStyleSheet *sheets[3]; guchar *paths[3]; CRCascade *result = NULL; gint i = 0; g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); memset (sheets, 0, sizeof (CRStyleSheet*) * 3); paths[0] = (guchar *) a_author_path; paths[1] = (guchar *) a_user_path; paths[2] = (guchar *) a_ua_path; for (i = 0; i < 3; i++) { status = cr_om_parser_parse_file (a_this, paths[i], a_encoding, &sheets[i]); if (status != CR_OK) { if (sheets[i]) { cr_stylesheet_unref (sheets[i]); sheets[i] = NULL; } continue; } } result = cr_cascade_new (sheets[0], sheets[1], sheets[2]); if (!result) { for (i = 0; i < 3; i++) { cr_stylesheet_unref (sheets[i]); sheets[i] = 0; } return CR_ERROR; } *a_result = result; return CR_OK; }
/** *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; }
/** * 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; }