Ejemplo n.º 1
0
Archivo: breaks.c Proyecto: gplv2/rlib
static void rlib_break_all_below_in_reverse_order(rlib *r, struct rlib_part *part, struct rlib_report *report, struct rlib_element *e, gboolean precalculate) {
	gint count=0,i=0,j=0;
	gint newpage = FALSE;
	gboolean t;
	struct rlib_report_break *rb;
	struct rlib_element *xxx, *be;
	struct rlib_break_fields *bf = NULL;

	for(xxx = e; xxx != NULL; xxx=xxx->next)
		count++;

	for(i=count;i > 0;i--) {
		xxx = e;
		for(j=0;j<i-1;j++)
			xxx = xxx->next;		
		rb = xxx->data;
		for(be = rb->fields; be != NULL; be=be->next) {
			bf = be->data;
			rlib_value_free(bf->rval);
			bf->rval = NULL;
		}
		if(OUTPUT(r)->do_breaks) {
			gint did_end_page = FALSE;
			
			
			if(precalculate == FALSE)
				did_end_page = rlib_end_page_if_line_wont_fit(r, part, report, rb->footer);

			if(!INPUT(r, r->current_result)->isdone(INPUT(r, r->current_result), r->results[r->current_result].result))
				rlib_navigate_previous(r, r->current_result);

			if(precalculate == FALSE) {
				if(did_end_page) {
					bf->rval = rlib_execute_pcode(r, &bf->rval2, bf->code, NULL);
					rlib_print_break_header_output(r, part, report, rb, rb->header, FALSE);
					rlib_value_free(bf->rval);
					bf->rval = NULL;		
				}

				rlib_print_break_footer_output(r, part, report, rb, rb->footer, FALSE);
			}
			if(!INPUT(r, r->current_result)->isdone(INPUT(r, r->current_result), r->results[r->current_result].result))
				rlib_navigate_next(r, r->current_result);
		}

		rlib_reset_variables_on_break(r, part, report, (gchar *)rb->xml_name.xml, precalculate);
		rlib_process_expression_variables(r, report);
		if (rlib_execute_as_boolean(r, rb->newpage_code, &t))
			newpage = t;
		
	}
	if(newpage && OUTPUT(r)->do_breaks) {
		if(!INPUT(r, r->current_result)->isdone(INPUT(r, r->current_result), r->results[r->current_result].result)) {
			if(OUTPUT(r)->paginate)
				rlib_layout_end_page(r, part, report, TRUE);
			rlib_force_break_headers(r, part, report, precalculate);
		}
	}
}
Ejemplo n.º 2
0
static gint rlib_navigate_followers(rlib *r, gint my_leader, gint way) {
	gint i, rtn = TRUE;
	gint found = FALSE;
	for(i=0;i<r->resultset_followers_count;i++) {
		found = FALSE;
		if(r->followers[i].leader == my_leader) {
			if(r->followers[i].leader_code != NULL ) {
				struct rlib_value rval_leader, rval_follower;
				rlib_execute_pcode(r, &rval_leader, r->followers[i].leader_code, NULL);
				rlib_execute_pcode(r, &rval_follower, r->followers[i].follower_code, NULL);
				if( rvalcmp(&rval_leader,&rval_follower) == 0 )  {

				} else {
					rlib_value_free(&rval_follower);
					if(rlib_do_followers(r, i, way) == TRUE) {
						rlib_execute_pcode(r, &rval_follower, r->followers[i].follower_code, NULL);
						if( rvalcmp(&rval_leader,&rval_follower) == 0 )  {
							found = TRUE;
							
						} 
					} 
					if(found == FALSE) {
						r->results[r->followers[i].follower]->navigation_failed = FALSE;
						rlib_do_followers(r, i, RLIB_NAVIGATE_FIRST);
						do {
							rlib_execute_pcode(r, &rval_follower, r->followers[i].follower_code, NULL);
							if(rvalcmp(&rval_leader,&rval_follower) == 0 ) {
								found = TRUE;
								break;											
							}
							rlib_value_free(&rval_follower);
						} while(rlib_do_followers(r, i, RLIB_NAVIGATE_NEXT) == TRUE);
					}
					if(!found)  {
						r->results[r->followers[i].follower]->navigation_failed = TRUE;	
					}
				}
				
				rlib_value_free(&rval_leader);
				rlib_value_free(&rval_follower);
			} else {
				rtn = rlib_do_followers(r, i, way);
			}
			
		}
	}
	rlib_process_input_metadata(r);
	return rtn;
}
Ejemplo n.º 3
0
Archivo: breaks.c Proyecto: gplv2/rlib
void rlib_force_break_headers(rlib *r, struct rlib_part *part, struct rlib_report *report, gboolean precalculate) {
	struct rlib_element *e;

	if(!OUTPUT(r)->do_breaks)
		return;
	
	if(report->breaks == NULL)
		return;
	
	for(e = report->breaks; e != NULL; e=e->next) {
		gint dobreak=1;
		struct rlib_report_break *rb = e->data;
		struct rlib_element *be;
		for(be = rb->fields; be != NULL; be=be->next) {
			struct rlib_break_fields *bf = be->data;
			if(dobreak && bf->rval == NULL) {
				dobreak=1;
				rlib_value_free(bf->rval);
				bf->rval = rlib_execute_pcode(r, &bf->rval2, bf->code, NULL);
			} else {
				dobreak = 0;
			}
		}	
	}
	
	for(e = report->breaks; e != NULL; e=e->next) {
		struct rlib_report_break *rb = e->data;
		if(rb->headernewpage && precalculate == FALSE) {
			rlib_print_break_header_output(r, part, report, rb, rb->header, FALSE);
		}
				
	}
}
Ejemplo n.º 4
0
Archivo: breaks.c Proyecto: gplv2/rlib
void rlib_handle_break_headers(rlib *r, struct rlib_part *part, struct rlib_report *report, gboolean precalculate) {
	gint icache=0,page,i;
	gfloat total[RLIB_MAXIMUM_PAGES_ACROSS];
	struct rlib_element *e;
	struct rlib_report_break *cache[100];

	if(report->breaks == NULL)
		return;
	
	for(i=0;i<RLIB_MAXIMUM_PAGES_ACROSS;i++) 
		total[i] = 0;

	for(e = report->breaks; e != NULL; e=e->next) {
		gint dobreak=1;
		struct rlib_report_break *rb = e->data;
		struct rlib_element *be;
		for(be = rb->fields; be != NULL; be=be->next) {
			struct rlib_break_fields *bf = be->data;
			if(dobreak && bf->rval == NULL) {
				dobreak=1;
				rlib_value_free(bf->rval);
				bf->rval = rlib_execute_pcode(r, &bf->rval2, bf->code, NULL);
			} else {
				dobreak = 0;
			}
		}
		
		if(dobreak) {
			if(rb->header != NULL) {
				cache[icache++] = rb;
			} else {
				rb->didheader = TRUE;
			}
			for(page=0;page<report->pages_across;page++) {
				total[page] += get_outputs_size(r, part, report, rb->header, page);
			}
		}				
	}
	
	if(icache && OUTPUT(r)->do_breaks && precalculate == FALSE) {	
		gint allfit = TRUE;
		for(page=0;page<report->pages_across;page++) {
			if(!rlib_will_this_fit(r, part, report, total[page], page+1))
				allfit = FALSE;
		}
		if(!allfit) {
			rlib_layout_end_page(r, part, report, TRUE);
			rlib_force_break_headers(r, part, report, precalculate);
		} else {
			for(i=0;i<icache;i++) {
				rlib_print_break_header_output(r, part, report, cache[i], cache[i]->header, FALSE);	
			}
		}
	}
}
Ejemplo n.º 5
0
Archivo: breaks.c Proyecto: gplv2/rlib
void rlib_breaks_clear(rlib *r, struct rlib_part *part, struct rlib_report *report) {
	struct rlib_element *e;
	struct rlib_break_fields *bf;

	if(report->breaks == NULL)
		return;
	for(e = report->breaks; e != NULL; e=e->next) {
		struct rlib_report_break *rb = e->data;
		struct rlib_element *be;
		for(be = rb->fields; be != NULL; be=be->next) {
			bf = be->data;
			if(bf->rval != NULL) {
				rlib_value_free(bf->rval);
				bf->rval = NULL;
			}
		}
	}
				
}
Ejemplo n.º 6
0
Archivo: breaks.c Proyecto: gplv2/rlib
/*
	Footers are complicated.... I need to go in reverse order for footers... and if I find a match...
	I need to go back down the list and force breaks for everyone.. in reverse order.. ugh

*/
void rlib_handle_break_footers(rlib *r, struct rlib_part *part, struct rlib_report *report, gboolean precalculate) {
	struct rlib_element *e;
	struct rlib_break_fields *bf;

	if(report->breaks == NULL)
		return;
	for(e = report->breaks; e != NULL; e=e->next) {
		gint dobreak=1;
		struct rlib_report_break *rb = e->data;
		struct rlib_element *be;
		for(be = rb->fields; be != NULL; be=be->next) {
			struct rlib_value rval_tmp;
			RLIB_VALUE_TYPE_NONE(&rval_tmp);
			bf = be->data;
			if(dobreak) {
				if (INPUT(r, r->current_result)->isdone(INPUT(r, r->current_result), r->results[r->current_result].result)) {
					dobreak = 1;
				} else {
					struct rlib_value *tmp = rlib_execute_pcode(r, &rval_tmp, bf->code, NULL);	
					if (rvalcmp(bf->rval, tmp)) {
					    dobreak = 1;
					} else  {
						dobreak = 0;
					}
					rlib_value_free(tmp);
				}
			} else {
				dobreak = 0;
			}
		}
		
		if(dobreak) {
			rlib_break_all_below_in_reverse_order(r, part, report, e, precalculate);
			break;
		}
				
	}
}
Ejemplo n.º 7
0
gint rlib_format_string(rlib *r, gchar **dest, struct rlib_report_field *rf, struct rlib_value *rval) {
	gchar before[MAXSTRLEN], after[MAXSTRLEN];
	gint before_len = 0, after_len = 0;
	gboolean formatted_it = FALSE;	
	
	if(r->special_locale != NULL) 
		setlocale(LC_ALL, r->special_locale);
	if(rf->xml_format.xml == NULL) {
		rlib_format_string_default(r, rf, rval, dest);
		formatted_it = TRUE;
	} else {
		gchar *formatstring;
		struct rlib_value rval_fmtstr2, *rval_fmtstr=&rval_fmtstr2;
		rval_fmtstr = rlib_execute_pcode(r, &rval_fmtstr2, rf->format_code, rval);
		if(!RLIB_VALUE_IS_STRING(rval_fmtstr)) {
			*dest = g_strdup_printf("!ERR_F_F");
			rlib_value_free(rval_fmtstr);
			if(r->special_locale != NULL) 
				setlocale(LC_ALL, r->current_locale);
			return FALSE;
		} else {
			formatstring = RLIB_VALUE_GET_AS_STRING(rval_fmtstr);
			if(formatstring == NULL) {
				rlib_format_string_default(r, rf, rval, dest);
				formatted_it = TRUE;
			} else {
				if (*formatstring == '!') {
					gboolean result;
					gchar *tfmt = formatstring + 1;
					gboolean goodfmt = TRUE;
					switch (*tfmt) {
					case '$': /* Format as money */
						if (RLIB_VALUE_IS_NUMBER(rval)) {
							result = rlib_format_money(r, dest, tfmt + 1, RLIB_VALUE_GET_AS_NUMBER(rval));
							formatted_it = TRUE;
							if(r->special_locale != NULL) 
								setlocale(LC_ALL, r->current_locale);
							return result;
						}
						++formatstring;
						break;
					case '#': /* Format as number */
						if (RLIB_VALUE_IS_NUMBER(rval)) {
							result = rlib_format_number(r, dest, tfmt + 1, RLIB_VALUE_GET_AS_NUMBER(rval));
							formatted_it = TRUE;
							if(r->special_locale != NULL) 
								setlocale(LC_ALL, r->current_locale);
							return result;
						}
						++formatstring;
						break;
					case '@': /* Format as time/date */
						if(RLIB_VALUE_IS_DATE(rval)) {
							struct rlib_datetime *dt = &RLIB_VALUE_GET_AS_DATE(rval);
							rlib_datetime_format(r, dest, dt, tfmt + 1);
							formatted_it = TRUE;
						}
						break;
					default:
						goodfmt = FALSE;
						break;
					}
					if (goodfmt) {
						if(r->special_locale != NULL) 
							setlocale(LC_ALL, r->current_locale);
						return TRUE;
					}
				}
				if(RLIB_VALUE_IS_DATE(rval)) {
					rlib_datetime_format(r, dest, &RLIB_VALUE_GET_AS_DATE(rval), formatstring);
					formatted_it = TRUE;
				} else {	
					gint i=0,/*j=0,pos=0,*/fpos=0;
					gchar fmtstr[MAX_FORMAT_STRING];
					gint special_format=0;
					gchar *idx;
					gint len_formatstring;
					idx = strchr(formatstring, ':');
					fmtstr[0] = 0;
					if(idx != NULL && RLIB_VALUE_IS_NUMBER(rval)) {
						formatstring = g_strdup(formatstring);
						idx = strchr(formatstring, ':');
						special_format=1;
						if(RLIB_VALUE_GET_AS_NUMBER(rval) >= 0)
							idx[0] = '\0';
						else
							formatstring = idx+1;				
					}

					len_formatstring = strlen(formatstring);

					for(i=0;i<len_formatstring;i++) {
						if(formatstring[i] == '%' && ((i+1) < len_formatstring && formatstring[i+1] != '%')) {
							int tchar;
							while(formatstring[i] != 's' && formatstring[i] != 'd' && i <=len_formatstring) {
								fmtstr[fpos++] = formatstring[i++];
							}
							fmtstr[fpos++] = formatstring[i];
							fmtstr[fpos] = '\0';
							tchar = fmtstr[fpos - 1];
							if ((tchar == 'd') || (tchar == 'i') || (tchar == 'n')) {
								if(RLIB_VALUE_IS_NUMBER(rval)) {
									rlib_number_sprintf(r, dest, fmtstr, rval, special_format, (gchar *)rf->xml_format.xml, rf->xml_format.line);
									formatted_it = TRUE;
								} else {
									*dest = g_strdup_printf("!ERR_F_D");
									rlib_value_free(rval_fmtstr);
									if(r->special_locale != NULL) 
										setlocale(LC_ALL, r->current_locale);
									return FALSE;
								}
							} else if (tchar == 's') {
								if(RLIB_VALUE_IS_STRING(rval)) {
									rlib_string_sprintf(r, dest, fmtstr, rval);
									formatted_it = TRUE;
								} else {
									*dest = g_strdup_printf("!ERR_F_S");
									rlib_value_free(rval_fmtstr);
									if(r->special_locale != NULL) 
										setlocale(LC_ALL, r->current_locale);
									return FALSE;
								}
							}
						} else {
							if(formatted_it == FALSE) {
								before[before_len++] = formatstring[i];
							} else {
								after[after_len++] = formatstring[i];
							}
							if(formatstring[i] == '%')
								i++;
						}
					}
				}

			}
			rlib_value_free(rval_fmtstr);
		}
	}
	
	if(before_len > 0 || after_len > 0) {
		gchar *new_str;
		before[before_len] = 0;
		after[after_len] = 0;
		new_str = g_strconcat(before, *dest, after, NULL);
		g_free(*dest);
		*dest = new_str;
	}
	if(r->special_locale != NULL) 
		setlocale(LC_ALL, r->current_locale);
	return TRUE;
}
Ejemplo n.º 8
0
Archivo: free.c Proyecto: SICOM/rlib
void rlib_free_report(rlib *r, struct rlib_report *report) {
	if (report == NULL)
		return;

	rlib_pcode_free(r, report->font_size_code);
	rlib_pcode_free(r, report->query_code);
	rlib_pcode_free(r, report->orientation_code);
	rlib_pcode_free(r, report->top_margin_code);
	rlib_pcode_free(r, report->left_margin_code);
	rlib_pcode_free(r, report->bottom_margin_code);
	rlib_pcode_free(r, report->pages_across_code);
	rlib_pcode_free(r, report->suppress_page_header_first_page_code);
	rlib_pcode_free(r, report->suppress_code);
	rlib_pcode_free(r, report->detail_columns_code);
	rlib_pcode_free(r, report->column_pad_code);
	rlib_pcode_free(r, report->uniquerow_code);

	rlib_free_output(r, report->report_header);
	report->report_header = NULL;
	rlib_free_output(r, report->page_header);
	report->page_header = NULL;
	rlib_free_output(r, report->page_footer);
	report->page_footer = NULL;
	rlib_free_output(r, report->report_footer);
	report->report_footer = NULL;
	if (report->detail) {
		rlib_free_detail(r, report->detail);
		report->detail = NULL;
	}
	rlib_free_output(r, report->alternate);
	report->alternate = NULL;
	rlib_free_graph(r, report->graph);
	report->graph = NULL;
	rlib_free_chart(r, report->chart);
	report->chart = NULL;

	g_free(report->position_top);
	g_free(report->position_bottom);
	g_free(report->bottom_size);

	rlib_value_free(&report->uniquerow);

	rlib_free_breaks(r, report->breaks);
	report->breaks = NULL;

	rlib_free_variables(r, report->variables);
	report->variables = NULL;

	xmlFree(report->xml_font_size.xml);
	xmlFree(report->xml_query.xml);
	xmlFree(report->xml_orientation.xml);
	xmlFree(report->xml_top_margin.xml);
	xmlFree(report->xml_left_margin.xml);
	xmlFree(report->xml_detail_columns.xml);
	xmlFree(report->xml_column_pad.xml);
	xmlFree(report->xml_bottom_margin.xml);
	xmlFree(report->xml_height.xml);
	xmlFree(report->xml_iterations.xml);
	xmlFree(report->xml_pages_across.xml);
	xmlFree(report->xml_suppress_page_header_first_page.xml);
	xmlFree(report->xml_suppress.xml);
	xmlFree(report->xml_uniquerow.xml);

	g_free(report);
}