Example #1
0
File: breaks.c Project: gplv2/rlib
static void rlib_print_break_header_output(rlib *r, struct rlib_part *part, struct rlib_report *report, struct rlib_report_break *rb, struct rlib_element *e, gint backwards) {
	gint blank = TRUE;
	gint suppress = FALSE;

	if(!OUTPUT(r)->do_breaks)
		return;
		
	if(rb->suppressblank) {
		struct rlib_element *be;
		suppress = TRUE;
		for(be = rb->fields; be != NULL; be=be->next) {
			struct rlib_break_fields *bf = be->data;
			if((bf->rval == NULL || (RLIB_VALUE_IS_STRING(bf->rval) && !strcmp(RLIB_VALUE_GET_AS_STRING(bf->rval), ""))) && blank == TRUE)
				blank = TRUE;
			else
				blank = FALSE;
		}				
	}
	if(!suppress || (suppress && !blank)) {
		rb->didheader = TRUE;
		if(e != NULL)
			rlib_layout_report_output(r, part, report, e, backwards, TRUE);
	} else {
		rb->didheader = FALSE;
	}
}
Example #2
0
static gint rlib_format_string_default(rlib *r, struct rlib_report_field *rf, struct rlib_value *rval, gchar **dest) {
	if(RLIB_VALUE_IS_NUMBER(rval)) {
		*dest = g_strdup_printf("%" PRId64, RLIB_FXP_TO_NORMAL_LONG_LONG(RLIB_VALUE_GET_AS_NUMBER(rval)));
	} else if(RLIB_VALUE_IS_STRING(rval)) {
		if(RLIB_VALUE_GET_AS_STRING(rval) == NULL)
			*dest = NULL;
		else
			*dest = g_strdup(RLIB_VALUE_GET_AS_STRING(rval));
	} else if(RLIB_VALUE_IS_DATE(rval))  {
		struct rlib_datetime *dt = &RLIB_VALUE_GET_AS_DATE(rval);
		rlib_datetime_format(r, dest, dt, "%m/%d/%Y");
	} else {
		*dest = g_strdup_printf("!ERR_F");
		return FALSE;
	}
	return TRUE;
}
Example #3
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;
}