Esempio n. 1
0
dsc* EVAL_parameter(qli_par* parameter)
{
/**************************************
 *
 *	E V A L _ p a r a m e t e r
 *
 **************************************
 *
 * Functional description
 *	Compute the descriptor for a parameter.
 *
 **************************************/
	qli_par* missing_parameter;

	dsc* desc = &parameter->par_desc;
	desc->dsc_missing = FALSE;
	qli_msg* message = parameter->par_message;

	if (missing_parameter = parameter->par_missing)
	{
		const USHORT* missing_flag = (USHORT*) (message->msg_buffer + missing_parameter->par_offset);
		desc->dsc_missing = *missing_flag ? DSC_missing : 0;
	}

	desc->dsc_address = message->msg_buffer + parameter->par_offset;
	QLI_validate_desc(desc);

	return desc;
}
Esempio n. 2
0
static void gen_any( qli_nod* node, qli_req* request)
{
/**************************************
 *
 *	g e n _ a n y
 *
 **************************************
 *
 * Functional description
 *	Generate the BLR for a statistical expresionn.
 *
 **************************************/
	qli_rlb* rlb;

	// If there is a request associated with the statement, prepare to
	// generate BLR.  Otherwise assume that a request is alrealdy initialized.

	qli_req* new_request = (qli_req*) node->nod_arg[e_any_request];
	if (new_request)
	{
		request = new_request;
		gen_request(request);
		const qli_msg* receive = (qli_msg*) node->nod_arg[e_any_send];
		if (receive)
			gen_send_receive(receive, blr_receive);
		const qli_msg* send = (qli_msg*) node->nod_arg[e_any_receive];
		gen_send_receive(send, blr_send);
		rlb = CHECK_RLB(request->req_blr);
		STUFF(blr_if);
	}
	else
		rlb = CHECK_RLB(request->req_blr);

	STUFF(blr_any);
	gen_rse(node->nod_arg[e_any_rse], request);

	USHORT value; // not feasible to change it to bool.
	dsc desc;
	if (new_request)
	{
		desc.dsc_dtype = dtype_short;
		desc.dsc_length = sizeof(SSHORT);
		desc.dsc_scale = 0;
		desc.dsc_sub_type = 0;
		desc.dsc_address = (UCHAR*) &value;
		QLI_validate_desc(desc);

		STUFF(blr_assignment);
		value = TRUE;
		gen_literal(&desc, request);
		gen_parameter(node->nod_import, request);

		STUFF(blr_assignment);
		value = FALSE;
		gen_literal(&desc, request);
		gen_parameter(node->nod_import, request);
		gen_compile(request);
	}
}
Esempio n. 3
0
static void gen_for( qli_nod* node, qli_req* request)
{
/**************************************
 *
 *	g e n _ f o r
 *
 **************************************
 *
 * Functional description
 *	Generate BLR for a FOR loop, included synchronization messages.
 *
 **************************************/

	// If there is a request associated with the statement, prepare to
	// generate BLR.  Otherwise assume that a request is alrealdy initialized.

	if (node->nod_arg[e_for_request])
	{
		request = (qli_req*) node->nod_arg[e_for_request];
		gen_request(request);
	}

	qli_rlb* rlb = CHECK_RLB(request->req_blr);

	// If the statement requires an end of file marker, build a BEGIN/END around
	// the whole statement.

	const qli_msg* message = (qli_msg*) node->nod_arg[e_for_receive];
	if (message)
		STUFF(blr_begin);

	// If there is a message to be sent, build a receive for it

	if (node->nod_arg[e_for_send])
		gen_send_receive((qli_msg*) node->nod_arg[e_for_send], blr_receive);

	// Generate the FOR loop proper.

	STUFF(blr_for);
	gen_rse(node->nod_arg[e_for_rse], request);
	STUFF(blr_begin);

	// If data is to be received (included EOF), build a send

	const qli_par* eof = 0;
	dsc desc;
	USHORT value;

	if (message)
	{
		gen_send_receive(message, blr_send);
		STUFF(blr_begin);

		// Build assigments for all values referenced.

		for (const qli_par* parameter = message->msg_parameters; parameter;
			parameter = parameter->par_next)
		{
			if (parameter->par_value)
			{
				STUFF(blr_assignment);
				gen_expression(parameter->par_value, request);
				gen_parameter(parameter, request);
			}
		}

		// Next, make a FALSE for the end of file parameter

		eof = (qli_par*) node->nod_arg[e_for_eof];
		desc.dsc_dtype = dtype_short;
		desc.dsc_length = sizeof(SSHORT);
		desc.dsc_scale = 0;
		desc.dsc_sub_type = 0;
		desc.dsc_address = (UCHAR*) &value;
		QLI_validate_desc(desc);

		STUFF(blr_assignment);
		value = FALSE;
		gen_literal(&desc, request);
		gen_parameter(eof, request);

		STUFF(blr_end);
	}

	// Build  the body of the loop.

	const qli_msg* continuation = request->req_continue;
	if (continuation)
	{
		STUFF(blr_label);
		const USHORT label = request->req_label++;
		STUFF(label);
		STUFF(blr_loop);
		STUFF(blr_select);
		gen_send_receive(continuation, blr_receive);
		STUFF(blr_leave);
		STUFF(label);
	}

	qli_nod* sub = node->nod_arg[e_for_statement];
	gen_statement(sub, request);

	STUFF(blr_end);

	if (continuation)
		STUFF(blr_end);

	// Finish off by building a SEND to indicate end of file

	if (message)
	{
		gen_send_receive(message, blr_send);
		STUFF(blr_assignment);
		value = TRUE;
		gen_literal(&desc, request);
		gen_parameter(eof, request);
		STUFF(blr_end);
	}

	// If this is our request, compile it.

	if (node->nod_arg[e_for_request])
		gen_compile(request);
}
static void edit_date( const dsc* desc, pics* picture, TEXT** output)
{
/**************************************
 *
 *	e d i t _ d a t e
 *
 **************************************
 *
 * Functional description
 *	Edit data from a descriptor through an edit string to a running
 *	output pointer.
 *
 **************************************/
	SLONG date[2];
	DSC temp_desc;
	TEXT d, temp[256];

	temp_desc.dsc_dtype = dtype_timestamp;
	temp_desc.dsc_scale = 0;
	temp_desc.dsc_sub_type = 0;
	temp_desc.dsc_length = sizeof(date);
	temp_desc.dsc_address = (UCHAR*) date;
	QLI_validate_desc(temp_desc);
	MOVQ_move(desc, &temp_desc);

    tm times;
	isc_decode_date((ISC_QUAD*) date, &times);
	TEXT* p = temp;

	const TEXT* nmonth = p;
	p = cvt_to_ascii((SLONG) times.tm_mon + 1, p, picture->pic_nmonths);

	const TEXT* day = p;
	p = cvt_to_ascii((SLONG) times.tm_mday, p, picture->pic_days);

	const TEXT* year = p;
	p = cvt_to_ascii((SLONG) times.tm_year + 1900, p, picture->pic_years);

	const TEXT* julians = p;
	p = cvt_to_ascii((SLONG) times.tm_yday + 1, p, picture->pic_julians);

	const TEXT* meridian = "";
	if (picture->pic_meridian)
	{
		if (times.tm_hour >= 12)
		{
			meridian = "PM";
			if (times.tm_hour > 12)
				times.tm_hour -= 12;
		}
		else
			meridian = "AM";
	}

	const SLONG seconds = date[1] % (60 * PRECISION);

	TEXT* hours = p;
	p = cvt_to_ascii((SLONG) times.tm_hour, p, picture->pic_hours);
	p = cvt_to_ascii((SLONG) times.tm_min, --p, picture->pic_minutes);
	p = cvt_to_ascii((SLONG) seconds, --p, 6);

	if (*hours == '0')
		*hours = ' ';

	SLONG rel_day = (date[0] + 3) % 7;
	if (rel_day < 0)
		rel_day += 7;
	const TEXT* weekday = alpha_weekdays[rel_day];
	const TEXT* month = alpha_months[times.tm_mon];

	picture->pic_pointer = picture->pic_string;
	picture->pic_count = 0;
	TEXT* out = *output;

	bool sig_day = false;
	bool blank = true;

	for (;;)
	{
		TEXT c = generate(picture);
		if (!c || c == '?')
			break;
		c = UPPER(c);

		switch (c)
		{
		case 'Y':
			*out++ = *year++;
			break;

		case 'M':
			if (*month)
				*out++ = *month++;
			break;

		case 'N':
			*out++ = *nmonth++;
			break;

		case 'D':
			d = *day++;
			if (!sig_day && d == '0' && blank)
				*out++ = ' ';
			else
			{
				sig_day = true;
				*out++ = d;
			}
			break;

		case 'J':
			if (*julians)
				*out++ = *julians++;
			break;

		case 'W':
			if (*weekday)
				*out++ = *weekday++;
			break;

		case 'B':
			*out++ = ' ';
			break;

		case 'P':
			if (*meridian)
				*out++ = *meridian++;
			break;

		case 'T':
			if (*hours)
				*out++ = *hours++;
			break;

		case '"':
		case '\'':
		case '\\':
			literal(picture, c, &out);
			break;

		default:
			*out++ = c;
			break;
		}
		if (c != 'B')
			blank = false;
	}

	*output = out;
}