Example #1
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;
}
Example #2
0
File: breaks.c Project: 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);
		}
				
	}
}
Example #3
0
File: breaks.c Project: 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);
		}
	}
}
Example #4
0
File: breaks.c Project: 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);	
			}
		}
	}
}
Example #5
0
File: breaks.c Project: 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;
		}
				
	}
}
Example #6
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;
}