Example #1
0
void
output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
{
	fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
	if (st == ECPGst_execute || st == ECPGst_exec_immediate)
	{
		fprintf(yyout, "%s, %s, ", ecpg_statement_type_name[st], stmt);
	}
	else
	{
		if (st == ECPGst_prepnormal && auto_prepare)
			fputs("ECPGst_prepnormal, \"", yyout);
		else
			fputs("ECPGst_normal, \"", yyout);

		output_escaped_str(stmt, false);
		fputs("\", ", yyout);
	}

	/* dump variables to C file */
	dump_variables(argsinsert, 1);
	fputs("ECPGt_EOIT, ", yyout);
	dump_variables(argsresult, 1);
	fputs("ECPGt_EORT);", yyout);
	reset_variables();

	whenever_action(whenever_mode | 2);
	free(stmt);
	if (connection != NULL)
		free(connection);
}
Example #2
0
void
output_statement(char *stmt, int mode, char *con)
{
    int			i,
                j = strlen(stmt);

    fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, \"", compat, force_indicator, con ? con : "NULL");

    /* output this char by char as we have to filter '\"' */
    for (i = 0; i < j; i++)
    {
        if (stmt[i] != '"')
            fputc(stmt[i], yyout);
        else
            fputs("\\\"", yyout);
    }

    fputs("\", ", yyout);

    /* dump variables to C file */
    dump_variables(argsinsert, 1);
    fputs("ECPGt_EOIT, ", yyout);
    dump_variables(argsresult, 1);
    fputs("ECPGt_EORT);", yyout);
    reset_variables();

    mode |= 2;
    whenever_action(mode);
    free(stmt);
    if (connection != NULL)
        free(connection);
}
Example #3
0
void
output_statement(char *stmt, int mode, char *con)
{
	fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, \"", compat, force_indicator, con ? con : "NULL");
	output_escaped_str(stmt);
	fputs("\", ", yyout);

	/* dump variables to C file */
	dump_variables(argsinsert, 1);
	fputs("ECPGt_EOIT, ", yyout);
	dump_variables(argsresult, 1);
	fputs("ECPGt_EORT);", yyout);
	reset_variables();

	mode |= 2;
	whenever_action(mode);
	free(stmt);
	if (connection != NULL)
		free(connection);
}
Example #4
0
void Z3BitVector::dump_problem(string& filename_base){


	FILE* file = fopen(filename_base.c_str(), "w");
	dump_header(file);
	dump_variables(file);
	dump_extra(file);
	dump_conditions(file);
	dump_check_sat(file);
	dump_get(file);
	dump_tail(file);
	fclose(file);

}
unsigned char menu_input(unsigned char cmd)
{
	static unsigned char state = 'q';
	static unsigned char substate = 0;
	static unsigned char input_idx=0;
	static unsigned char cyl_counter =0;
	unsigned int tmpi = 0;
	float tmpf = 0;

	unsigned char i = 0;
	static unsigned char subst = 0;
	
	//just dump the menu if we're at the top level
	//and user hit enter
	if(state == 'q' || state == 'm' )
	{
	switch( cmd )
		{	
			//set rpm points for knock table
			case 'r':	state = 'r'; cyl_counter = 0; substate = 0; break;
			//set voltage points for knock table
			//will be dumped to eeprom when done
			case 'v':	state = 'v'; cyl_counter = 0; substate = 0; break;
			//get the current engine settings
			case 'g':	state = 'g'; break;
			//configure the engine settings 
			//will be dumped to eeprom when done
			case 'c':	state = 'c'; break;
			//dump the status of internal variables
			case 'd':	state = 'd'; break;
			//if we get a 'q' shut down the menu
			case 'q':  return 0;
			//set the state to main menu
			default:	state = 'm'; print_main_menu(); break;
		}

	return 1;
	}
	else
	{

		switch(state)
		{
		
			case 'g':
			dump_config();
			newline();
			print_main_menu();
			state = 'm';
			break;

			case 'd':
			dump_variables();
			newline();
			print_main_menu();
			state = 'm';
			break;

			case 'r':
			switch(substate)
			{
				case 0:
				newline();
				snprintf_P(output, OUTPUT_LEN, cylinder_prompt, cfg.firing_order[cyl_counter]);
				print_str(output);
				substate++;
				input_idx = 0;
				break;

				case 1:
				//set value from substate 0 query
				//if \r\n our work here is done
				if(cmd == '\n' || cmd == '\r')
				{
					if(input_idx > 0)
					{

						output[input_idx] = '\0';
						subst = 0;
						input_idx = 0;
						for(i = 0; i < OUTPUT_LEN && output[i] != '\0'; i++)
						{
								if(output[i] == ',')
								{
									output[i] = '\0';
									//this is actually stored in timer ticks to avoid division in code
									//introduces +/- 8 rpm error around 10k rpm
									cfg.rpm_points[cyl_counter][input_idx++] = (TICKS_PER_MIN / atoi( (output+subst) ) );
									subst = i+1;
								}	
	
						}
						cfg.rpm_points[cyl_counter][input_idx] = (TICKS_PER_MIN / atoi( (output+subst) ) );
					} 
					if(++cyl_counter == cfg.num_cyls )
					{
						print_str_P(table_layout);
						for(i = 0; i < cfg.num_cyls; i++)
						{
							calculate_fslopes(i);
							newline();
							newline();
							snprintf_P(output, OUTPUT_LEN, table_header, cfg.firing_order[i]);
							print_str(output);
							newline();
							dump_rpm_table(i);
							newline();
							dump_voltage_table(i);
							newline();
							dump_fslopes(i);
						}
						print_str_P(prompt);
						substate++;
						input_idx = 0;
					}
					else
					{
						newline();
						input_idx = 0;
						snprintf_P(output, OUTPUT_LEN, cylinder_prompt, cfg.firing_order[cyl_counter]);
						print_str(output);
					}
				}
				else if( input_idx < OUTPUT_LEN -1  && (isdigit(cmd) || cmd == ',' ) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;

				break;

				case 2:
				if( cmd == 'y' || cmd == 'Y')
				{
					write_cfg_to_eep();
					setup();
				}
				else if( cmd == 'n' || cmd == 'N' )
				{
					substate = 0;
					input_idx = 0;
					cyl_counter = 0;
					break;
				}
				else if( cmd == 'q' || cmd == 'Q')
				{	
					read_cfg_from_eep();
				}
				else
				{ 
					print_str_P(prompt);
					break;
				}
				state = 'm';

				default: substate =0; input_idx = 0; cyl_counter = 0; break;
			}	
			break;
		

			case 'v':
			switch(substate)
			{
				case 0:
				newline();
				snprintf_P(output, OUTPUT_LEN, voltage_prompt , cfg.firing_order[cyl_counter]);
				print_str(output);
				substate++;
				break;
				
				
				case 1:
				//set value from substate 0 query
				//if \n our work here is done
				if(cmd == '\n' || cmd == '\r')
				{
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						subst = 0;
						input_idx = 0;
						for(i = 0; i < OUTPUT_LEN && output[i] != '\0'; i++)
						{
								if(output[i] == ',')
								{
									output[i] = '\0';
									cfg.knock_voltage[cyl_counter][input_idx++] = (unsigned int ) (atof((output+subst)) /TEN_BIT_LSB) ;
									subst = i+1;
								}	
						} 
							cfg.knock_voltage[cyl_counter][input_idx] = (unsigned int ) (atof((output+subst)) /TEN_BIT_LSB) ;
					}
					if(++cyl_counter == cfg.num_cyls)
					{
						print_str_P(table_layout);
						for(i = 0; i < cfg.num_cyls; i++)
						{
							calculate_fslopes(i);
							newline();
							newline();
							snprintf_P(output, OUTPUT_LEN, table_header, cfg.firing_order[i]);
							print_str(output);
							newline();
							dump_rpm_table(i);
							newline();
							dump_voltage_table(i);
							newline();
							dump_fslopes(i);
						}
						print_str_P(prompt);
						substate++;
						input_idx = 0;
					}
					else
					{
						newline();
						snprintf_P(output, OUTPUT_LEN, voltage_prompt, cfg.firing_order[cyl_counter]);
						print_str(output);
						input_idx = 0;
					}
				}
				else if( input_idx < OUTPUT_LEN -1  && (isdigit(cmd) || cmd == ','|| cmd == '.' ) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;

				
				break;

				case 2:
				if( cmd == 'y' || cmd == 'Y')
				{
					write_cfg_to_eep();
					setup();
				}
				else if( cmd == 'n' || cmd == 'N' )
				{
					substate = 0;
					input_idx = 0;
					cyl_counter = 0;
					break;
				}
				else if( cmd == 'q' || cmd == 'Q')
				{	
					read_cfg_from_eep();
				}
				else 
				{
					print_str_P(prompt);
					break;
				}
				state = 'm';

				default: substate = 0; input_idx = 0; cyl_counter = 0; break;					

			}	
			break;

			case 'c':
			switch(substate)
			{
				case 0:
				newline();
				print_str_P(dump_cfg[substate++] );
				break;

				case 1:
				if(cmd == '\n' || cmd == '\r')
				{   
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						cfg.num_cyls = (unsigned char)atoi(output);
                        			input_idx=0;    
                    			}   
					newline();
					print_str_P(dump_cfg[substate++]);
				}
               			else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
               			 	output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;

				case 2:
                                if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                        cfg.window_length_deg = (unsigned char)atoi(output);
                                        input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 3:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                        cfg.window_open_deg_atdc = (unsigned char)atoi(output);
                                        input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 4:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                        cfg.mech_advance_deg_btdc = (unsigned char)atoi(output);
                                        input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 5:
				if(cmd == '\n' || cmd == '\r')
				{
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
					cfg.window_integ_div = (unsigned char)atoi(output);
       		             		input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
				else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                			output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                		break;


				case 6:
				if(cmd == '\n' || cmd == '\r')
				{
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
					tmpi = (unsigned int)atoi(output);
					//search for the next largest bandpass frequenc and 
					//set the index of the current center frequency in the cfg section
					for(i = 0; i < NUM_BANDPASS_FREQS && pgm_read_word(&bandpass_freq_value[i]) < tmpi ; i++);
					cfg.tpic_freq = i;
					input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
				else if( input_idx < OUTPUT_LEN	&& isdigit(cmd) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;


				case 7:
				if(cmd == '\n' || cmd == '\r' )
				{
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						tmpf = (float)atof(output);
						//search for the next smallest gain
						//set the index of the gain in the cfg section
						for(i = 0; i < NUM_GAIN && pgm_read_float(&gain_value[i]) > tmpf ; i++);
						cfg.tpic_gain = i;
						input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
				else if( input_idx < OUTPUT_LEN && (isdigit(cmd) || cmd == '.' ) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;

				case 8:
				if(cmd == '\n' || cmd == '\r')
				{	
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						subst = 0;
					input_idx = 0;
						for(i = 0; i < OUTPUT_LEN && output[i] != '\0'; i++)
					{
							if(output[i] == ',')
						{
								output[i] = '\0';
								cfg.firing_order[input_idx++] = atoi( (output+subst) );
								subst = i+1;
						}

					}
						cfg.firing_order[input_idx] = atoi( (output+subst) );
                    			input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
				else if( input_idx < OUTPUT_LEN  && (isdigit(cmd) || cmd == ',' ) )
                			output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
              			break;
				case 9:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                        cfg.datalog_frequency = MAX_DATALOGS_PER_SEC/(unsigned char)atoi(output);
										if(cfg.datalog_frequency < 2)
											cfg.datalog_frequency = 1;
										else
											cfg.datalog_frequency--;
                                        input_idx=0;
	                                }
					newline();
					print_str_P(dump_cfg[substate++]);

				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 10:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                       		cfg.datalog_header_count = (unsigned char)atoi(output);

						if(cfg.datalog_header_count == 0)
							cfg.datalog_header_count = 1;

                                       		input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 11:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                       		cfg.wheelmode = (unsigned char)atoi(output);
						if(cfg.wheelmode != HEP && cfg.wheelmode != FOURTWENTYA )
							cfg.wheelmode = 0;

                                       		input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 12:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                                       		cfg.tpic_chan = ( (unsigned char)atoi(output) -1 );
						if(cfg.tpic_chan != 1 )
							cfg.tpic_chan = 0;

                                       		input_idx=0;
                                	}
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                                                output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
                                break;

				case 13:
				if(cmd == '\n' || cmd == '\r')
                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
                        cfg.datalogmode = ( (unsigned char)atoi(output)  );
						if( cfg.datalogmode )
							cfg.datalogmode = 1;

                        input_idx=0;
                    }
					newline();
					print_str_P(dump_cfg[substate++]);
				}
                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
					output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
                                
				break;

				case 14:
				if(cmd == '\n' || cmd == '\r')
                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						strncpy(cfg.seperator, output, MAX_SEP_LEN-1);
						cfg.seperator[MAX_SEP_LEN - 1] = '\0';
 						input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);

				}
                else if( input_idx < OUTPUT_LEN )
                    output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;

				case 15:
				if(cmd == '\n' || cmd == '\r')
                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						cfg.pulse_events = (unsigned char) atoi(output);
 						input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);

				}
                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                    output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;


				case 16:
				if(cmd == '\n' || cmd == '\r')
                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						cfg.pulse_tenms = (unsigned char) atoi(output);
 						input_idx=0;
					}
					newline();
					print_str_P(dump_cfg[substate++]);

				}
                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                    output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;


				case 17:
				if(cmd == '\n' || cmd == '\r')
                                {
					if(input_idx > 0)
					{
						output[input_idx] = '\0';
						cfg.pulse_timer_select = (unsigned char) atoi(output);
						if(cfg.pulse_timer_select)
							cfg.pulse_timer_select = 1;
 						input_idx=0;
					}
					print_str_P(config_done);
					dump_config();
					print_str_P(prompt);
					newline();
					substate++;
				}
                else if( input_idx < OUTPUT_LEN  && isdigit(cmd) )
                    output[input_idx++]=cmd;
				else if ( input_idx > 0 && ( cmd == '\b' || cmd == 0x7F || cmd == 0x08 ) )
					input_idx--;
				break;



				case 18:
				if( cmd == 'y' || cmd == 'Y')
				{
					write_cfg_to_eep();
					setup();
				}
				else if( cmd == 'n' || cmd == 'N' )
				{
					substate = 0;
					input_idx = 0;
					cyl_counter = 0;
					break;
				}
				else if( cmd == 'q' || cmd == 'Q')
				{	
					read_cfg_from_eep();
				}
				else
				{
					print_str_P(prompt);
					break;
				}
				state = 'm';

				default: substate = 0; input_idx = 0; cyl_counter = 0; break;					

			}//switch(substate)
			
		}//switch(state)

	}//else
return 1;
}//void menu_input()