Esempio n. 1
0
        void INSession::notify(const Wt::WEvent & e)
        {
            try
            {
                Wt::WApplication::notify(e);
            }
            catch (exception & exp)
            {
                if (m_MessageBox == NULL)
                {
                    m_MessageBox = new Wt::WMessageBox();

                    m_MessageBox->setId("MessageBox");
                    m_MessageBox->setStyleClass("MessageBox Error");
                    m_MessageBox->addButton(localize("MESSAGE_BOX_BUTTON_OK"), Wt::StandardButton::Ok);
                    m_MessageBox->buttonClicked().connect(std::bind([=]()
                        {
                            if (m_MessageBox->buttonResult() == Wt::StandardButton::Ok)
                                m_MessageBox->hide();
                        }));
                }
                m_MessageBox->setText(exp.what());
                m_MessageBox->setWindowTitle(localize("MESSAGE_BOX_TITLE_CRITICAL_ERROR"));
                m_MessageBox->setIcon(Wt::Icon::Critical);
                m_MessageBox->show();
            }
        }
Esempio n. 2
0
//-------------------------------------------------------****MAIN FUNCTION ****------------------------------------------------
int main()
{
	
	init_devices();
	lcd_set_4bit();
	lcd_init();
    lcd_cursor(1,1);
	lcd_string("START");
	_delay_ms(rand());
//--*** GRIPPER INITAL POSITION ***---
	S2 = 0x73;
	cli();
	timer0_init();
	TIMSK |= (1 << OCIE0) | (1 << TOIE0); // timer 0 compare match and overflow interrupt enable 
	sei();
	pickup();
	
	while(1)
	{
	if( bot_id_set == 1)
	{	
	
		init_devices2();
		init_grid();
		dispersion();
		localize();
		region_division();
		break;
	}
	
 }
 }
Esempio n. 3
0
void drive_to_point2(int x, int y) {
    //m_green(ON);
    //m_wait(500);

    //while(1) {
        //localize(data);
        localize(data);
        //Set angle difference to be between -180 and 180
        angle_dif = (((int) (((data[2] + 90.0) * -1.0) - (float)(atan2((double)y-data[1],(double)x-data[0]))*180.0/3.14)) + 900) % 360 - 180;
//         if (abs(angle_dif) < 7) {
//             shoot();
//             //game_pause();
               state = 2;
//         }
        if (angle_dif > 0) {
            dir = RIGHT;
        }
        else {
            dir = LEFT;
        }
       
        //Angle of 180 corresponds to deg of 0; angle of 0 corresponds to deg of 1
        deg = exp(-1.0* ((double)fabs(angle_dif))/30.0);
        //Set distance
        distance = (int) sqrt(((double)y - data[1])*((double)y - data[1])+((double)x - data[0])*((double)x - data[0]));
        spd = ((float)distance)/70.0;
        //*****************************************************************************
//             rx_buffer = m_usb_rx_char();      //grab the computer packet
//
//             m_usb_rx_flush();                  //clear buffer
//
//             if(rx_buffer == 1) {              //computer wants ir buffer
//                 //write ir buffer as concatenated hex:  i.e. f0f1f4f5
//                 data[3] = angle_dif;
//                 data[4] = deg*100.0;
//                 data[5] = distance;
//                 data[6] = spd*100.0;
//                 for (int i = 0 ; i < 7 ; i++){
//                     m_usb_tx_int((int)data[i]);
//                     m_usb_tx_char('\t');
//
//                 }
//
//                 m_usb_tx_char('\n');  //MATLAB serial command reads 1 line at a time
//             }
           
        //*********************************************************************************
       
        if (spd > speed_cap) spd = speed_cap;
        turn(dir, 1, deg);
       
    //}
//     if (distance < 10) {
//         m_red(ON);
//         reverse();
//         OCR1B = 0;
//         OCR3A = 0;
//         state = 0;
//     }
}
Esempio n. 4
0
void DistributedVector<T>::localize (NumericVector<T>& v_local_in) const

{
  libmesh_assert (this->initialized());
  libmesh_assert_equal_to (_values.size(), _local_size);
  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);

  DistributedVector<T>* v_local = libmesh_cast_ptr<DistributedVector<T>*>(&v_local_in);

  v_local->_first_local_index = 0;

  v_local->_global_size =
    v_local->_local_size =
    v_local->_last_local_index = size();

  v_local->_is_initialized =
    v_local->_is_closed = true;

  // Call localize on the vector's values.  This will help
  // prevent code duplication
  localize (v_local->_values);

#ifndef LIBMESH_HAVE_MPI

  libmesh_assert_equal_to (local_size(), size());

#endif
}
Esempio n. 5
0
 static GlobalAddress<GlobalBag> create(size_t total_capacity) {
   auto self = symmetric_global_alloc<GlobalBag>();
   auto n = total_capacity / cores()
            + total_capacity % cores();
   call_on_all_cores([=]{
     new (self.localize()) GlobalBag(self, n);
   });
   return self;
 }
Esempio n. 6
0
 static GlobalAddress<GlobalHashSet> create(size_t total_capacity) {
   auto base = global_alloc<Cell>(total_capacity);
   auto self = symmetric_global_alloc<GlobalHashSet>();
   call_on_all_cores([self,base,total_capacity]{
     new (self.localize()) GlobalHashSet(self, base, total_capacity);
   });
   forall(base, total_capacity, [](int64_t i, Cell& c) { new (&c) Cell(); });
   return self;
 }
Esempio n. 7
0
void DistributedVector<T>::localize (NumericVector<T>& v_local_in,
                                     const std::vector<numeric_index_type>&) const
{
  libmesh_assert (this->initialized());
  libmesh_assert_equal_to (_values.size(), _local_size);
  libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);

  // TODO: We don't yet support the send list; this is inefficient:
  localize (v_local_in);
}
Esempio n. 8
0
wxInt32 CDlgEventLog::FormatMessage(wxInt32 item, wxString& strBuffer) const {
    MESSAGE*   message = wxGetApp().GetDocument()->message(item);
    
    if (message) {
        strBuffer = wxString(message->body.c_str(), wxConvUTF8);
        remove_eols(strBuffer);
        localize(strBuffer);
    }

    return 0;
}
Esempio n. 9
0
void MENUS::render_loading(float percent)
{
	static int64 last_load_render = 0;

	// make sure that we don't render for each little thing we load
	// because that will slow down loading if we have vsync
	if(time_get()-last_load_render < time_freq()/60)
		return;
		
	last_load_render = time_get();
	
	// need up date this here to get correct
	vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f));
	gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f);
	
    RECT screen = *ui_screen();
	gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
	
	render_background();

	float tw;

	float w = 700;
	float h = 200;
	float x = screen.w/2-w/2;
	float y = screen.h/2-h/2;

	gfx_blend_normal();

	gfx_texture_set(-1);
	gfx_quads_begin();
	gfx_setcolor(0,0,0,0.50f);
	draw_round_rect(x, y, w, h, 40.0f);
	gfx_quads_end();


	const char *caption = localize("Loading");

	tw = gfx_text_width(0, 48.0f, caption, -1);
	RECT r;
	r.x = x;
	r.y = y+20;
	r.w = w;
	r.h = h;
	ui_do_label(&r, caption, 48.0f, 0, -1);

	gfx_texture_set(-1);
	gfx_quads_begin();
	gfx_setcolor(1,1,1,0.75f);
	draw_round_rect(x+40, y+h-75, (w-80)*percent, 25, 5.0f);
	gfx_quads_end();

	gfx_swap();
}
Esempio n. 10
0
int main()
{
	localize(std::string("UTF-8"));

	std::string ini_path = "F://Smarthouse//config.ini";
	IniConfigurator_test(ini_path);
	
	std::string xml_path = "F://Smarthouse//config.xml";
	XmlConfigurator_test(xml_path);

	return 0;
}
Esempio n. 11
0
 void sync() {
   CompletionEvent ce(keys_to_insert.size()+lookups.size());
   auto cea = make_global(&ce);
   
   for (auto& k : keys_to_insert) {
     ++hashset_insert_msgs;
     auto cell = owner->base+owner->computeIndex(k);
     send_heap_message(cell.core(), [cell,k,cea]{
       Cell * c = cell.localize();
       bool found = false;
       for (auto& e : c->entries) if (e.key == k) { found = true; break; }
       if (!found) c->entries.emplace_back(k);
       complete(cea);
     });
   }
   for (auto& e : lookups) { auto k = e.first;
     ++hashset_lookup_msgs;
     auto re = e.second;
     DVLOG(3) << "lookup " << k << " with re = " << re;
     auto cell = owner->base+owner->computeIndex(k);
     
     send_heap_message(cell.core(), [cell,k,cea,re]{
       Cell * c = cell.localize();
       bool found = false;
       for (auto& e : c->entries) if (e.key == k) { found = true; break; }
       
       send_heap_message(cea.core(), [cea,re,found]{
         ResultEntry * r = re;
         while (r != nullptr) {
           r->result = found;
           r = r->next;
         }
         complete(cea);
       });
     });
   }
   ce.wait();
 }
Esempio n. 12
0
/*
 * Opens for read the localized version of 'filename'
 * from the connected 'wgt'.
 *
 * Returns the file descriptor as returned by openat
 * system call or -1 in case of error.
 */
int wgt_locales_open_read(struct wgt *wgt, const char *filename)
{
    char path[PATH_MAX];
    const char *loc;

    assert(wgt);
    assert(wgt_is_connected(wgt));

    loc = localize(wgt, filename, path);
    if (!loc)
        return -1;

    return openat(wgt->rootfd, loc, O_RDONLY);
}
Esempio n. 13
0
File: value.c Progetto: kebekus/srt
static inline m34sf value(i4sf l, struct ray ray, float a)
{
	v4su test = localize(&l, ray, a);
//	v4sf n = l.min;
//	v4sf n = bisect(l, ray, a);
//	v4sf n = newton(l.min, ray, a);
	v4sf n = newton(bisect(l, ray, a), ray, a);
//	v4sf n = newton_bisect(l, ray, a);
//	v4sf n = newton_forward(l.min, ray, a);
//	return color(n, sign_test(n, ray, a) & int_test(n, l), ray, a);
//	return color(n, zero_test(n, ray, a) & int_test(n, l), ray, a);
//	return color(n, (sign_test(n, ray, a) | zero_test(n, ray, a)) & int_test(n, l), ray, a);
//	return color(n, (sign_test(n, ray, a) | epsilon_test(n, ray, a)) & int_test(n, l), ray, a);
	return color(n, test, ray, a);
}
Esempio n. 14
0
int main() {
  int test;
  int n, m;
  scanf("%d", &test);

  while (test != 0) {
    scanf("%d %d", &n, &m);
    
    int i = 0;
    for (i = 0; i < test; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      localize(n, m, x, y);
    }
    scanf("%d", &test);
  }
}
Esempio n. 15
0
/*
 * Gets the localized file of 'filename' within 'wgt'.
 *
 * Returns a fresh allocated string for the found 'filename'.
 * Returns NULL if file is not found (ENOENT) or memory
 * exhausted (ENOMEM).
 */
char *wgt_locales_locate(struct wgt *wgt, const char *filename)
{
    char path[PATH_MAX];
    char * result;
    const char * loc;

    assert(wgt);
    assert(wgt_is_connected(wgt));

    loc = localize(wgt, filename, path);
    if (!loc)
        result = NULL;
    else {
        result = strdup(loc);
        if (!result)
            errno = ENOMEM;
    }
    return result;
}
Esempio n. 16
0
int8_t cmd_localize(uint8_t argc, char **argv)
{
    int8_t rc;
    ir_graph_t *ir_graph;
    node_id_t ref_node = this_node_id;

    if (!(argc == 1 || argc == 2)) {
        OUT("usage: loc [<ref_node>]\r\n");
        return NRK_ERROR;
    }

    if (argc == 2)
        ref_node = atoi(argv[1]);

    ir_graph = get_ir_graph();

    rc = localize(ir_graph, ref_node);
    if (rc == NRK_OK)
        print_locations();
    return rc;
}
Esempio n. 17
0
void
caselc_ctype(void)
{
#ifdef	EUC
	char	c, *buf = NULL;
	int	i = 0, sz = 0;

	skip(1);
	do {
		c = getach()&0377;
		if (i >= sz)
			buf = realloc(buf, (sz += 8) * sizeof *buf);
		buf[i++] = c;
	} while (c && c != ' ' && c != '\n');
	buf[i-1] = 0;
	setlocale(LC_CTYPE, buf);
	mb_cur_max = MB_CUR_MAX;
	localize();
#ifndef	NROFF
	ptlocale(buf);
#endif
	free(buf);
#endif
}
Esempio n. 18
0
static void
localize(http_t       *http,		/* I - Connection to destination */
         cups_dest_t  *dest,		/* I - Destination */
	 cups_dinfo_t *dinfo,		/* I - Destination information */
         const char   *option,		/* I - Option */
	 const char   *value)		/* I - Value, if any */
{
  ipp_attribute_t	*attr;		/* Attribute */
  int			i,		/* Looping var */
			count;		/* Number of values */


  if (!option)
  {
    attr = cupsFindDestSupported(http, dest, dinfo, "job-creation-attributes");
    if (attr)
    {
      count = ippGetCount(attr);
      for (i = 0; i < count; i ++)
        localize(http, dest, dinfo, ippGetString(attr, i, NULL), NULL);
    }
    else
    {
      static const char * const options[] =
      {					/* List of standard options */
        CUPS_COPIES,
	CUPS_FINISHINGS,
	CUPS_MEDIA,
	CUPS_NUMBER_UP,
	CUPS_ORIENTATION,
	CUPS_PRINT_COLOR_MODE,
	CUPS_PRINT_QUALITY,
	CUPS_SIDES
      };

      puts("No job-creation-attributes-supported attribute, probing instead.");

      for (i = 0; i < (int)(sizeof(options) / sizeof(options[0])); i ++)
        if (cupsCheckDestSupported(http, dest, dinfo, options[i], NULL))
	  localize(http, dest, dinfo, options[i], NULL);
    }
  }
  else if (!value)
  {
    printf("%s (%s)\n", option, cupsLocalizeDestOption(http, dest, dinfo, option));

    if ((attr = cupsFindDestSupported(http, dest, dinfo, option)) != NULL)
    {
      count = ippGetCount(attr);

      switch (ippGetValueTag(attr))
      {
        case IPP_TAG_INTEGER :
	    for (i = 0; i < count; i ++)
              printf("  %d\n", ippGetInteger(attr, i));
	    break;

        case IPP_TAG_ENUM :
	    for (i = 0; i < count; i ++)
              printf("  %s\n", ippEnumString(option, ippGetInteger(attr, i)));
	    break;

        case IPP_TAG_RANGE :
	    for (i = 0; i < count; i ++)
	    {
	      int upper, lower = ippGetRange(attr, i, &upper);

              printf("  %d-%d\n", lower, upper);
	    }
	    break;

        case IPP_TAG_RESOLUTION :
	    for (i = 0; i < count; i ++)
	    {
	      int xres, yres;
	      ipp_res_t units;
	      xres = ippGetResolution(attr, i, &yres, &units);

              if (xres == yres)
                printf("  %d%s\n", xres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
	      else
                printf("  %dx%d%s\n", xres, yres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
	    }
	    break;

	case IPP_TAG_TEXTLANG :
	case IPP_TAG_NAMELANG :
	case IPP_TAG_TEXT :
	case IPP_TAG_NAME :
	case IPP_TAG_KEYWORD :
	case IPP_TAG_URI :
	case IPP_TAG_URISCHEME :
	case IPP_TAG_CHARSET :
	case IPP_TAG_LANGUAGE :
	case IPP_TAG_MIMETYPE :
	    for (i = 0; i < count; i ++)
              printf("  %s (%s)\n", ippGetString(attr, i, NULL), cupsLocalizeDestValue(http, dest, dinfo, option, ippGetString(attr, i, NULL)));
	    break;

        case IPP_TAG_STRING :
	    for (i = 0; i < count; i ++)
	    {
	      int j, len;
	      unsigned char *data = ippGetOctetString(attr, i, &len);

              fputs("  ", stdout);
	      for (j = 0; j < len; j ++)
	      {
	        if (data[j] < ' ' || data[j] >= 0x7f)
		  printf("<%02X>", data[j]);
		else
		  putchar(data[j]);
              }
              putchar('\n');
	    }
	    break;

        case IPP_TAG_BOOLEAN :
	    break;

        default :
	    printf("  %s\n", ippTagString(ippGetValueTag(attr)));
	    break;
      }
    }

  }
  else
    puts(cupsLocalizeDestValue(http, dest, dinfo, option, value));
}
Esempio n. 19
0
int execute_arguments(char *program_name, struct hash_map_t *arguments) {
    /* allocates space for the possible argument
    to be executed from the arguments map */
    void *value;

    /* allocates the value to be used to verify the
    exitence of error from the function */
    ERROR_CODE return_value;

    /* sets space for the flag that will control if
    the service should be run or not, this is used
    for certain situations (mostyle test) where the
    service is not meant to be run */
    char run_service = TRUE;

    /* tries to retrieve the help argument from the arguments
    map in case the value exists prints the help value and then
    exits the current system */
    get_value_string_hash_map(arguments, (unsigned char *) "help", &value);
    if(value != NULL) {
        return help();
    }

    /* tries to retrieve the version argument from the arguments
    map in case the value exists prints the version value and then
    exits the current system */
    get_value_string_hash_map(arguments, (unsigned char *) "version", &value);
    if(value != NULL) {
        return version();
    }

    /* retrieves the test argument value from the arguments map
    and in case it's set starts the test process runing a series
    of test functions in sequence */
    get_value_string_hash_map(arguments, (unsigned char *) "test", &value);
    if(value != NULL) {
        return test();
    }

    /* retrieves the speed argument value from the arguments map
    and in case it's set starts the speed measuring and disables
    the runnig of the service */
    get_value_string_hash_map(arguments, (unsigned char *) "speed", &value);
    if(value != NULL) {
        return speed();
    }

    /* tries to retrieve the daemon argument from the
    arguments map in case the value is set daemonizes
    the current process so that it remains in background
    and returns to the caller process immediately, otherwise
    prints the viriatum information into the standard
    output "file", the label should be standard */
    get_value_string_hash_map(arguments, (unsigned char *) "daemon", &value);
    if(value != NULL) {
        daemonize();
    }
    else {
        print_information();
    }

    /* tries to retrieve the local argument from the arguments
    map in case the value exists localizes the current service
    so that any file read is read from the current directory */
    get_value_string_hash_map(arguments, (unsigned char *) "local", &value);
    if(value != NULL) {
        localize();
    }

    /* in cas the flag that control if the service must be run is
    unset the control flow must be returned immediately (avoids
    running service) */
    if(run_service == FALSE) {
        RAISE_NO_ERROR;
    }

    /* runs the service, with the given arguments, this call
    should block the program control flow until an event
    stop the running of the main loop */
    return_value = run_service_s(program_name, arguments);

    /* tests the error code for error in case it exists
    prints a message indicating the problem that occurred */
    if(IS_ERROR_CODE(return_value)) {
        V_ERROR_F("Problem running service (%s)\n", (char *) GET_ERROR());
        RAISE_AGAIN(return_value);
    }

    /* returns the normal result value as no problems has
    occured during the execution of the command */
    RAISE_NO_ERROR;
}
Esempio n. 20
0
/*char isStuck() {
    m_wait(100);
    //localize(data);
    distfrombound = data[1] + ((float)BOUNDARYTHRESHOLD)*sin((data[2]+90.0)*3.14/180.0*-1.0);
    if (distfrombound > 60.0 || distfrombound < -60.0) {
        return 1;
    }
    m_usb_tx_int((int)distfrombound);
    m_usb_tx_char('\n');
}

long loccounter = 0;
float prevx = 0.0;
float prevy = 0.0;
*/
int main(void)
{
	//goal side
	clear(DDRB,1);
	clear(PORTB,1);
	if (check(PINB,1)) {
		goal = 1;
	}
	
    set(DDRB,0);
    set(PORTB,0);
    set(DDRD,5);
    set(DDRD,3);
    //wireless stuffs
    m_bus_init();
    
    m_rf_open(CHANNEL, RXADDRESS, PACKET_LENGTH);

    int counter = 0;
    //
    
    //m_num_init();
    int flag;
    
    m_clockdivide(0);
    
    m_disableJTAG();
    
    //TIMER 0: For Controlling the solenoid
//     
//     set(TCCR0B, WGM02);
//     set(TCCR0A, WGM01);
//     set(TCCR0A, WGM01);
//     
//     set(TCCR0A, COM0B1);
//     clear(TCCR0A, COM0B0);
//     
//     set(TCCR0B, CS02);
//     set(TCCR0B, CS01);
//     set(TCCR0B, CS00);
//     
    set(DDRB,7);
    
//     OCR0A = 0xFF;
//     OCR0B = 0xff;
//     
    //TIMER 1: For Controlling the left wheel
    
    set(TCCR1B, WGM13);
    set(TCCR1B, WGM12);
    set(TCCR1A, WGM11);
    set(TCCR1A, WGM10);
    
    set(TCCR1A, COM1B1);
    clear(TCCR1A, COM1B0);
    
    clear(TCCR1B, CS12);
    clear(TCCR1B, CS11);
    set(TCCR1B, CS10);
    
    set(DDRB,6);
    
    OCR1A = 0xFFFF;
    OCR1B = 0;
    
    //TIMER 3: For Controlling the right wheel
    //up to ICR3, clear at OCR3A & set at rollover
    
    set(TCCR3B, WGM33);
    set(TCCR3B, WGM32);
    set(TCCR3A, WGM31);
    clear(TCCR3A, WGM30);
    
    set(TCCR3A, COM3A1);
    clear(TCCR3A, COM3A0);
    
    clear(TCCR3B, CS32);
    clear(TCCR3B, CS31);
    set(TCCR3B, CS30);
    
    ICR3 = 0xFFFF;
    OCR3A = 0;
    
//     //Set TCNT0 to go up to OCR0A
//     clear(TCCR0B, WGM02);
//     set    (TCCR0A, WGM01);
//     clear(TCCR0A, WGM00);
//     
//     // Don't change pin upon hitting OCR0B
//     clear(TCCR0A, COM0A1);
//     clear(TCCR0A, COM0A0);
//     
//     // Set clock scale to /1024
//     set(TCCR0B, CS02);
//     clear(TCCR0B, CS01);
//     set(TCCR0B, CS00);
//     
//     // Set Frequency of readings to 1/SAMPLERATE; dt = 1/SAMPLERATE
//     OCR0A = (unsigned int) ((float) F_CPU / 1024 / REPORTRATE);
//      OCR0B = 1;
    
    // Set up interrupt for reading values at sampling rate

    
    //Pin for controlling solenoid pulse
    set(DDRB,7);
    
    //Pins for controlling speed of left and right wheel
    set(DDRB,6);
    set(DDRC,6);
    
    //Pins for determining direction of wheels
    set(DDRB,2);
    set(DDRB,3);
    
    //Blue LED for Comm Test
    //set(DDRB,5);
    
    //ADC's
    sei();                    //Set up interrupts
    set(ADCSRA, ADIE);
    
    clear(ADMUX, REFS1);    //Voltage reference is AR pin (5V)
    clear(ADMUX, REFS0);    //^
    
    set(ADCSRA, ADPS2);    //Set scale to /128
    set(ADCSRA, ADPS1);    //^
    set(ADCSRA, ADPS0);    //^
    
    set(DIDR0, ADC0D);    //Disable digital input for F0
    set(DIDR0, ADC1D),
    set(DIDR0, ADC4D);
    set(DIDR0, ADC5D);
    set(DIDR0, ADC6D);
    set(DIDR0, ADC7D);
    set(DIDR2, ADC8D);
    set(DIDR2, ADC9D);
    
    set(ADCSRA, ADATE);    //Set trigger to free-running mode
    
    chooseInput(0);
    
    set(ADCSRA, ADEN);    //Enable/Start conversion
    set(ADCSRA, ADSC);    //^
    
    set(ADCSRA, ADIF);    //Enable reading results
    
    
    //Limit Switch stuffs
//     clear(DDRB,0); //set to input, RIGHT LIMIT SWITCH
//     clear(DDRB,1); //set to input, LEFT LIMIT SWITCH
//     
//     clear(PORTB,0); //disable internal pull up resistor
//     clear(PORTB,1); //disable internal pull up resistor
    
    //int state; // state variable
    state = 0; //set state
    play = 0;
    long count = 0;
    
    if (state == 70) {
            m_usb_init(); // connect usb
            while(!m_usb_isconnected());  //wait for connection
    }

    //m_bus_init();
    m_wii_open();
    //m_usb_init();
    m_red(ON);
    local_init();
    localize(data);
    m_red(OFF);

    //set(TIMSK0, OCIE0A);
    while(1)
    {
		if (play) {m_red(ON);}
		else {m_red(OFF);}
// 		m_wait(100);
// 		m_red(TOGGLE);
// 		localize(data);
        /*if (loccounter == LOCCOUNT) {
            if (sqrt((data[0]-prevx)*(data[0]-prevx)+(data[1]-prevy)-(data[1]-prevy)) < 1.0) {
                m_red(ON);
                reverse();
                m_wait(100);
                state = 6;
            }
            else {
                m_red(OFF);
                state = 2;
            }
            prevx = data[0];
            prevy = data[1];
            loccounter = 0;
        }*/
        //loccounter++;
//         localize(data);
//         locdata[1] = (char)data[0];
//         locdata[2] = (char)data[1];
//         toggle(PORTD,3);
        changedState = 0;
        angle_dif = 0;
       
        //Detect weather we have the puck
        getADC();
        //if (!play) game_pause();
        if (ADCarr[7] > 500) {
            //set(PORTD,5);
			//set(PORTD,5);
            iHaveThePuck = 1;
			m_green(ON);
			if (play && goal == A) state = 3;
			if (play && goal == B) state = 4;
        } else {
            //clear(PORTD,5);
            iHaveThePuck = 0;
			m_green(OFF);
			if (play) state = 2;
        }
       
        if(iHaveThePuck && state == 2) {
            //set(PORTB,5);
			//drive_to_goalA();
        }
        else {
            //clear(PORTB,5);
            //if (state != 0) state = 2;
        }
//         if(isStuck()) {
//             //set(PORTD,5);u
//         }
//         else {
//             //clear(PORTD,5);
//         }

        //localize(data);
       
//         if (check(PINB,0)) {
//             set(PORTD,5);
//             state = 0x1A;
//         } else {
//             clear(PORTD,5);
//             state = 2;
//         }
    
		if (!play) state = buffer[0];
        //switch states
        switch (state) {
           
            case -2:
            getADC();
            if (ADCarr[0] > 500) {
                m_green(ON);
            }
            else {m_green(OFF)}
            break;
           
            case -1: //test Limit switches
                //m_green(ON);
                if (check(PINB,1)) {
                   
                    m_green(ON);
                }
               
                else if (check(PINB,0)) {
                   
                    m_red(ON);
                }
               
                else {
                    m_red(OFF);
                    m_green(OFF);
                }
               
            break;

            case 0:
            //drive_to_point2(-100,0);
            game_pause();
            break;
           
            case 1:
            findPuck();
            break;
           
            case 2:
            //m_red(ON);
			if (!iHaveThePuck) {
				if (play)
            drive_to_puck();
			}
            break;
           
            case 3:
			if (play)
            drive_to_goalA();
            break;
           
            case 4:
			if (play)
            drive_to_goalB();
            break;    
           
            case 5:
           
            getADC();
            if (ADCarr[7] > 500) {
                //set(PORTD,5);
            } else {
                //clear(PORTD,5);
            }
           
            break;
           
            case 6:
            if (data[2] > 0) {
                rotate(RIGHT,1);
            } else {
                rotate(LEFT,1);
            }
            break;
			
            case 7:
		    drive_to_point2(-50,0);
		    break;
           
           
            case 0xA0:
            comm_test();
            break;
           
            case 0xA1:
            play = 1;
            drive_to_puck();
            break;
           
            case 0xA2:
			play = 0;
            game_pause();
            break;
           
            case 0xA3:
			play = 0;
            game_pause();
            break;
           
            case 0xA4:
			play = 0;
            game_pause();
            break;
           
            case 0xA6:
			play = 0;
            game_pause();
            break;
           
            case 0xA7:
            game_pause();
            break;
           
            case 69:
                set(PORTB,2);
                set(PORTB,3);
                OCR1B = OCR1A;
                OCR3A = ICR3;
                break;
               
            case 70:
                reportADC();
                break;
           
            default:
            game_pause();
            break;
        }
        
    }
}
Esempio n. 21
0
      DVLOG(6) << "Done reading at " << start_offset << " end_offset " << end_offset;
      
      // collect sizes
      local_offset = read_edges.size();
      DVLOG(7) << "Read " << local_offset << " edges";
    } );

  auto nedge = Grappa::reduce<int64_t,collective_add>(&local_offset);
  
  TupleGraph tg( nedge );
  auto edges = tg.edges;
  //auto leftovers = GlobalVector<int64_t>::create(N);

  on_all_cores( [=] {
      Edge * local_ptr = edges.localize();
      Edge * local_end = (edges+nedge).localize();
      auto local_count = local_end - local_ptr;
      auto read_count = read_edges.size();

      DVLOG(7) << "local_count " << local_count
               << " read_count " << read_count;
      
      // copy everything in our read buffer that fits locally
      auto local_max = MIN( local_count, read_count );
      std::memcpy( local_ptr, &read_edges[0], local_max * sizeof(Edge) );
      local_offset = local_max;
      Grappa::barrier();

      // get rid of remaining edges
      auto mycore = Grappa::mycore();
Esempio n. 22
0
		// handle command
		// /log read user startline
		// /log find user substr startline
		extern int handle_log_command(t_connection * c, char const *text)
		{
			const char *subcommand, *username;
			long startline = 0;
			std::map<long, char*> lines;

			// split command args
			std::vector<std::string> args = split_command(text, 4);
			if (args[1].empty() || args[2].empty() 
				|| (args[1].at(0) != 'r' && args[1].at(0) != 'f')) // check start symbols for subcommand
			{
				describe_command(c, args[0].c_str());
				return -1;
			}
			subcommand = args[1].c_str(); // sub command
			username = args[2].c_str(); // username

			if (!accountlist_find_account(username))
			{
				message_send_text(c, message_type_error, c, localize(c, "Invalid user."));
				return -1;
			}

			std::string title = localize(c, "{}'s log output", username);
			// read
			if (subcommand[0] == 'r')
			{
				if (!args[3].empty())
					startline = atoi(args[3].c_str());

				lines = userlog_read(username, startline);
			}
			// find
			else if (subcommand[0] == 'f')
			{
				if (args[3].empty())
				{
					describe_command(c, args[0].c_str());
					return -1;
				}
				const char * search = args[3].c_str();
				title += localize(c, " by occurrence \"{}\"", search);

				if (!args[4].empty())
					startline = atoi(args[4].c_str());

				lines = userlog_find_text(username, search, startline);
			}

			title += ":";
			message_send_text(c, message_type_info, c, title);

			int linelen = 0;
			int paddedlen = 0;
			std::string linenum;

			// send each log line to user
			for (std::map<long, char*>::reverse_iterator it = lines.rbegin(); it != lines.rend(); ++it)
			{
				int linelen = floor(log10(static_cast<double>(abs(it->first)))) + 1; // get length of integer (line number)
				if (linelen > paddedlen)
					paddedlen = linelen;

				linenum = std_to_string(it->first);
				// pad left to max line length
				linenum.insert(linenum.begin(), paddedlen - linenum.size(), '0');

				message_send_text(c, message_type_info, c, linenum + ": " + std::string(it->second));
			}

			return 0;
		}
Esempio n. 23
0
int main(void) {
	m_clockdivide(0);

	gen_setup();

	unsigned int wii_data[12] = {0};

	sei();
	m_rf_open(chan,rf_address,p_len);
	m_wii_read(wii_data);
	localize( wii_data , position, b_angle); // <--- takes in wii_data and updates position in place to house {x,y,angle} of robot 

	int enemy_goalX; 
	int enemy_goalY = 0;
	int own_goalX;
	int own_goalY = 0;
	int goalXPosition = 120;

	if ((int)(position[0])<0){ 	enemy_goalX = goalXPosition; 
		own_goalX = -goalXPosition;}

	else { 			enemy_goalX = -goalXPosition; 
		own_goalX = goalXPosition;}


	find_puck();
	set_motors(800,800);
	//bool  toggle = true;

	int lastX = 0;
	int lastY = 0;
	int lastAng = 0;

	while (1) {
		//find angle to own Goal
		rxOG = own_goalX - (int)position[0];
		ryOG = own_goalY - (int)position[1];
		psiOG = (int)(b_angle[0] *  RAD_DEG_RATIO) - 90; 
		if (psiOG<-180) { psiOG +=360; }
		if (psiOG>180) { psiOG -=360; }

		//error in angle, factoring in rotational velocity should be taken care of by kalman filter
		phi_robotOG = (int)(atan2(ryOG,rxOG) * RAD_DEG_RATIO); // compute angle from robot to target (in global coordinates)	
		theta_angleOG = (psiOG-phi_robotOG);
		//make sure the data within -180 to 180 degrees for ease of calculation
		if (theta_angleOG>180) { theta_angleOG-=360; }
		if (theta_angleOG<=-180) { theta_angleOG+=360;}

		/*if (debug_goto) {
		  m_usb_tx_string("\n\r");
		  m_usb_tx_int(theta_angleOG);
		// m_usb_tx_string("\t");
		//m_usb_tx_int(OCR1B);
		m_usb_tx_string("\n\r"); 
		}*/

		last_Super_state = Super_state;
		if (comm_cmd  == true)	{ get_command(); }
		if (check(TIFR3,OCF3A)){		 ///// timer 3 runs at 100Hz
			set(TIFR3,OCF3A);			
			if (timer_3_cnt == 1000){ timer_3_cnt = 0 ;   } else{ timer_3_cnt++;} // timer_3_cnt counts 10 seconds and then rolls over

			m_wii_read(wii_data);
			localize( wii_data , position, b_angle); // <--- takes in wii_data and updates position in place to house {x,y,angle} of robot 
			m_rf_open(chan,rf_address,p_len);


			find_puck();
			if (get_unstuck && timer_3_cnt%100 == 0){
				if ( (( lastX < position[0]+pos_change) && lastX > position[0]-pos_change)   
						&& ( lastY < position[1]+pos_change && (lastY > position[1]-pos_change)  ) ){
					//	&& ( ((int)lastAng < (int)b_angle*100 +20) && ((int)lastAng > (int)b_angle*100 - 20) )){
					Super_state = New_Loc_super;
					set_motors(-700,-700);
					m_wait(200);
					set_motors(0,0);
				}
				lastX = (int)position[0]; 
				lastY = (int)position[1];
				lastAng = (int)b_angle*100.0;
				}

				switch (Super_state){			
					case PT_super: 
						break;
					case ADC_super: 
						ADC_go_to_puck();
						break;
					case To_Goal_super: 
						drivePuck(enemy_goalX,  enemy_goalY ,position, b_angle[0]);
						break; 
					case New_Loc_super:	 
						break;
				}
				if (Super_state != To_Goal_super) keepSpin = 0;

				if ( Matlab_pos_tracking ){ matlab_output( position, b_angle , wii_data ); }
			}
		}
	}
Esempio n. 24
0
 const NString INSession::localize(const NString & name)
 {
     return localize(name, locale().name());
 }
Esempio n. 25
0
int MENUS::render()
{
    RECT screen = *ui_screen();
	gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);

	static bool first = true;
	if(first)
	{
		if(config.ui_page == PAGE_INTERNET)
			client_serverbrowse_refresh(0);
		else if(config.ui_page == PAGE_LAN)
			client_serverbrowse_refresh(1);
		first = false;
	}
	
	if(client_state() == CLIENTSTATE_ONLINE)
	{
		color_tabbar_inactive = color_tabbar_inactive_ingame;
		color_tabbar_active = color_tabbar_active_ingame;
	}
	else
	{
		render_background();
		color_tabbar_inactive = color_tabbar_inactive_outgame;
		color_tabbar_active = color_tabbar_active_outgame;
	}
	
	RECT tab_bar;
	RECT main_view;

	// some margin around the screen
	ui_margin(&screen, 10.0f, &screen);
	
	if(popup == POPUP_NONE)
	{
		// do tab bar
		ui_hsplit_t(&screen, 24.0f, &tab_bar, &main_view);
		ui_vmargin(&tab_bar, 20.0f, &tab_bar);
		render_menubar(tab_bar);
		
		// news is not implemented yet
		if(config.ui_page <= PAGE_NEWS || config.ui_page > PAGE_SETTINGS || (client_state() == CLIENTSTATE_OFFLINE && config.ui_page >= PAGE_GAME && config.ui_page <= PAGE_CALLVOTE))
		{
			client_serverbrowse_refresh(BROWSETYPE_INTERNET);
			config.ui_page = PAGE_INTERNET;
		}
		
		// render current page
		if(client_state() != CLIENTSTATE_OFFLINE)
		{
			if(game_page == PAGE_GAME)
				render_game(main_view);
			else if(game_page == PAGE_SERVER_INFO)
				render_serverinfo(main_view);
			else if(game_page == PAGE_CALLVOTE)
				render_servercontrol(main_view);
			else if(game_page == PAGE_SETTINGS)
				render_settings(main_view);
		}
		else if(config.ui_page == PAGE_NEWS)
			render_news(main_view);
		else if(config.ui_page == PAGE_INTERNET)
			render_serverbrowser(main_view);
		else if(config.ui_page == PAGE_LAN)
			render_serverbrowser(main_view);
		else if(config.ui_page == PAGE_DEMOS)
			render_demolist(main_view);
		else if(config.ui_page == PAGE_FAVORITES)
			render_serverbrowser(main_view);
		else if(config.ui_page == PAGE_SETTINGS)
			render_settings(main_view);
//		else if(config.ui_page == PAGE_TEE-NG)
//			renger_settings(main_teeng);
	}
	else
	{
		// make sure that other windows doesn't do anything funnay!
		//ui_set_hot_item(0);
		//ui_set_active_item(0);
		char buf[128];
		const char *title = "";
		const char *extra_text = "";
		const char *button_text = "";
		int extra_align = 0;
		
		if(popup == POPUP_MESSAGE)
		{
			title = message_topic;
			extra_text = message_body;
			button_text = message_button;
		}
		else if(popup == POPUP_CONNECTING)
		{
			title = localize("Connecting to");
			extra_text = config.ui_server_address;  // TODO: query the client about the address
			button_text = localize("Abort");
			if(client_mapdownload_totalsize() > 0)
			{
				title = localize("Downloading map");
				str_format(buf, sizeof(buf), "%d/%d KiB", client_mapdownload_amount()/1024, client_mapdownload_totalsize()/1024);
				extra_text = buf;
			}
		}
		else if(popup == POPUP_DISCONNECTED)
		{

			title = localize("Disconnected");
			extra_text = client_error_string();
			button_text = localize("Ok");
			extra_align = -1;
		}
		else if(popup == POPUP_PURE)
		{
			title = localize("Disconnected");
			extra_text = localize("The server is running a non-standard tuning on a pure game type.");
			button_text = localize("Ok");
			extra_align = -1;
		}
		else if(popup == POPUP_PASSWORD)
		{
			title = localize("Password Incorrect");
			extra_text = client_error_string();
			button_text = localize("Try again");
		}
		else if(popup == POPUP_QUIT)
		{
			title = localize("Quit");
			extra_text = localize("Are you sure that you want to quit?");
		}
		else if(popup == POPUP_FIRST_LAUNCH)
		{
			title = localize("Welcome to Teeworlds");
			extra_text = localize("As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server.");
			button_text = localize("Ok");
			extra_align = -1;
		}
		
		RECT box, part;
		box = screen;
		ui_vmargin(&box, 150.0f, &box);
		ui_hmargin(&box, 150.0f, &box);
		
		// render the box
		ui_draw_rect(&box, vec4(0,0,0,0.5f), CORNER_ALL, 15.0f);
		 
		ui_hsplit_t(&box, 20.f, &part, &box);
		ui_hsplit_t(&box, 24.f, &part, &box);
		ui_do_label(&part, title, 24.f, 0);
		ui_hsplit_t(&box, 20.f, &part, &box);
		ui_hsplit_t(&box, 24.f, &part, &box);
		ui_vmargin(&part, 20.f, &part);
		
		if(extra_align == -1)
			ui_do_label(&part, extra_text, 20.f, -1, (int)part.w);
		else
			ui_do_label(&part, extra_text, 20.f, 0, -1);

		if(popup == POPUP_QUIT)
		{
			RECT yes, no;
			ui_hsplit_b(&box, 20.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			ui_vmargin(&part, 80.0f, &part);
			
			ui_vsplit_mid(&part, &no, &yes);
			
			ui_vmargin(&yes, 20.0f, &yes);
			ui_vmargin(&no, 20.0f, &no);

			static int button_abort = 0;
			if(ui_do_button(&button_abort, localize("No"), 0, &no, ui_draw_menu_button, 0) || escape_pressed)
				popup = POPUP_NONE;

			static int button_tryagain = 0;
			if(ui_do_button(&button_tryagain, localize("Yes"), 0, &yes, ui_draw_menu_button, 0) || enter_pressed)
				client_quit();
		}
		else if(popup == POPUP_PASSWORD)
		{
			RECT label, textbox, tryagain, abort;
			
			ui_hsplit_b(&box, 20.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			ui_vmargin(&part, 80.0f, &part);
			
			ui_vsplit_mid(&part, &abort, &tryagain);
			
			ui_vmargin(&tryagain, 20.0f, &tryagain);
			ui_vmargin(&abort, 20.0f, &abort);
			
			static int button_abort = 0;
			if(ui_do_button(&button_abort, localize("Abort"), 0, &abort, ui_draw_menu_button, 0) || escape_pressed)
			{
				if(config.cl_autoconnect)
				config.cl_autoconnect == 0;
				else
				popup = POPUP_NONE;
			}

			static int button_tryagain = 0;
			if(ui_do_button(&button_tryagain, localize("Try again"), 0, &tryagain, ui_draw_menu_button, 0) || enter_pressed)
			{
				client_connect(config.ui_server_address);
			}
			
			ui_hsplit_b(&box, 60.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			
			ui_vsplit_l(&part, 60.0f, 0, &label);
			ui_vsplit_l(&label, 100.0f, 0, &textbox);
			ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
			ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
			ui_do_label(&label, localize("Password"), 20, -1);
			ui_do_edit_box(&config.password, &textbox, config.password, sizeof(config.password), 14.0f, true);
		}
		else if(popup == POPUP_FIRST_LAUNCH)
		{
			RECT label, textbox;
			
			ui_hsplit_b(&box, 20.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			ui_vmargin(&part, 80.0f, &part);
			
			static int enter_button = 0;
			if(ui_do_button(&enter_button, localize("Enter"), 0, &part, ui_draw_menu_button, 0) || enter_pressed)
				popup = POPUP_NONE;
			
			ui_hsplit_b(&box, 40.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			
			ui_vsplit_l(&part, 60.0f, 0, &label);
			ui_vsplit_l(&label, 100.0f, 0, &textbox);
			ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
			ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
			ui_do_label(&label, localize("Nickname"), 20, -1);
			ui_do_edit_box(&config.player_name, &textbox, config.player_name, sizeof(config.player_name), 14.0f);
		}
		else
		{
			ui_hsplit_b(&box, 20.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			ui_vmargin(&part, 120.0f, &part);

			static int button = 0;
			if(ui_do_button(&button, button_text, 0, &part, ui_draw_menu_button, 0) || escape_pressed || enter_pressed)
			{
				if(popup == POPUP_CONNECTING)
					client_disconnect();
				popup = POPUP_NONE;
			}
		}
	}
	
	return 0;
}
Esempio n. 26
0
void optfunc()
{
#if !HTOD
    block *b;
    int iter;           // iteration count
    clock_t starttime;

    cmes ("optfunc()\n");
    dbg_optprint("optfunc\n");
#ifdef DEBUG
    if (debugb)
    {
        dbg_printf("................Before optimization.........\n");
        WRfunc();
    }
#endif
    iter = 0;

    if (localgot)
    {   // Initialize with:
        //      localgot = OPgot;
        elem *e = el_long(TYnptr, 0);
        e->Eoper = OPgot;
        e = el_bin(OPeq, TYnptr, el_var(localgot), e);
        startblock->Belem = el_combine(e, startblock->Belem);
    }

    // Each pass through the loop can reduce only one level of comma expression.
    // The infinite loop check needs to take this into account.
    int iterationLimit = 0;
    for (b = startblock; b; b = b->Bnext)
    {
        if (!b->Belem)
            continue;
        int d = el_countCommas(b->Belem);
        if (d > iterationLimit)
            iterationLimit = d;
    }

    // Some functions can take enormous amounts of time to optimize.
    // We try to put a lid on it.
    starttime = clock();
    do
    {
        //printf("iter = %d\n", iter);
#if TX86
        if (++iter > 200)
        {   assert(iter < iterationLimit);      // infinite loop check
            break;
        }
#else
     L1:
#endif
#if MARS
        util_progress();
#else
        file_progress();
#endif

        //printf("optelem\n");
        /* canonicalize the trees        */
        for (b = startblock; b; b = b->Bnext)
            if (b->Belem)
            {
#if DEBUG
                if(debuge)
                {
                    dbg_printf("before\n");
                    elem_print(b->Belem);
                    //el_check(b->Belem);
                }
#endif
                b->Belem = doptelem(b->Belem,bc_goal[b->BC] | GOALagain);
#if DEBUG
                if(0 && debugf)
                {
                    dbg_printf("after\n");
                    elem_print(b->Belem);
                }
#endif
            }
        //printf("blockopt\n");
#if TX86
        if (mfoptim & MFdc)
            blockopt(0);                // do block optimization
        out_regcand(&globsym);          // recompute register candidates
        changes = 0;                    /* no changes yet                */
        if (mfoptim & MFcnp)
            constprop();                /* make relationals unsigned     */
        if (mfoptim & (MFli | MFliv))
#else
        if (config.optimized && (mfoptim & MFdc))
            blockopt(0);                // do block optimization

        dbg_optprint("blockopt\n");
        out_regcand();                  // recompute register candidates
        changes = 0;                    /* no changes yet                */

        dbg_optprint("constprop\n");
        if (config.optimized && (mfoptim & MFcnp))
            constprop();                /* make relationals unsigned     */

        dbg_optprint("loopopt\n");
        if (config.optimized && (mfoptim & (MFli | MFliv)))
#endif
            loopopt();                  /* remove loop invariants and    */
                                        /* induction vars                */
                                        /* do loop rotation              */
        else
            for (b = startblock; b; b = b->Bnext)
                b->Bweight = 1;
        dbg_optprint("boolopt\n");
#if TX86
        if (mfoptim & MFcnp)
            boolopt();                  // optimize boolean values
        if (changes && mfoptim & MFloop && (clock() - starttime) < 30 * CLOCKS_PER_SEC)
            continue;

        if (mfoptim & MFcnp)
            constprop();                /* constant propagation          */
        if (mfoptim & MFcp)
            copyprop();                 /* do copy propagation           */

        /* Floating point constants and string literals need to be
         * replaced with loads from variables in read-only data.
         * This can result in localgot getting needed.
         */
        symbol *localgotsave = localgot;
        for (b = startblock; b; b = b->Bnext)
        {
            if (b->Belem)
            {
                b->Belem = doptelem(b->Belem,bc_goal[b->BC] | GOALstruct);
                if (b->Belem)
                    b->Belem = el_convert(b->Belem);
            }
        }
        if (localgot != localgotsave)
        {   /* Looks like we did need localgot, initialize with:
             *  localgot = OPgot;
             */
            elem *e = el_long(TYnptr, 0);
            e->Eoper = OPgot;
            e = el_bin(OPeq, TYnptr, el_var(localgot), e);
            startblock->Belem = el_combine(e, startblock->Belem);
        }

        /* localize() is after localgot, otherwise we wind up with
         * more than one OPgot in a function, which mucks up OSX
         * code generation which assumes at most one (localgotoffset).
         */
        if (mfoptim & MFlocal)
            localize();                 // improve expression locality
        if (mfoptim & MFda)
            rmdeadass();                /* remove dead assignments       */

        cmes2 ("changes = %d\n", changes);
        if (!(changes && mfoptim & MFloop && (clock() - starttime) < 30 * CLOCKS_PER_SEC))
            break;
    } while (1);
    cmes2("%d iterations\n",iter);
    if (mfoptim & MFdc)
        blockopt(1);                    // do block optimization
#else
        if (config.optimized && (mfoptim & MFcnp))
            boolopt();                  // optimize boolean values
        util_progress();
        if (changes)
            goto L1;

        dbg_optprint("constprop\n");
        if (config.optimized && (mfoptim & MFcnp))
            constprop();                /* constant propagation          */

        dbg_optprint("copyprop\n");
        if (config.optimized && (mfoptim & MFcp))
            copyprop();                 /* do copy propagation           */

        dbg_optprint("localize\n");
        if (config.optimized && (mfoptim & MFlocal))
            localize();                 // improve expression locality

        dbg_optprint("rmdeadass\n");
        if (config.optimized && (mfoptim & MFda))
            rmdeadass();                /* remove dead assignments       */
        cmes2 ("changes = %d\n", changes);
        iter++;
        assert (iter < 80);             /* infinite loop check           */
    } while (changes && (config.optimized) && (mfoptim & MFloop));
Esempio n. 27
0
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line arguments */
     char *argv[])			/* I - Command-line arguments */
{
  http_t	*http;			/* Connection to destination */
  cups_dest_t	*dest = NULL;		/* Destination */
  cups_dinfo_t	*dinfo;			/* Destination info */


  if (argc < 2)
    usage(NULL);

  if (!strcmp(argv[1], "--enum"))
  {
    int			i;		/* Looping var */
    cups_ptype_t	type = 0,	/* Printer type filter */
			mask = 0;	/* Printer type mask */


    for (i = 2; i < argc; i ++)
    {
      if (!strcmp(argv[i], "grayscale"))
      {
        type |= CUPS_PRINTER_BW;
	mask |= CUPS_PRINTER_BW;
      }
      else if (!strcmp(argv[i], "color"))
      {
        type |= CUPS_PRINTER_COLOR;
	mask |= CUPS_PRINTER_COLOR;
      }
      else if (!strcmp(argv[i], "duplex"))
      {
        type |= CUPS_PRINTER_DUPLEX;
	mask |= CUPS_PRINTER_DUPLEX;
      }
      else if (!strcmp(argv[i], "staple"))
      {
        type |= CUPS_PRINTER_STAPLE;
	mask |= CUPS_PRINTER_STAPLE;
      }
      else if (!strcmp(argv[i], "small"))
      {
        type |= CUPS_PRINTER_SMALL;
	mask |= CUPS_PRINTER_SMALL;
      }
      else if (!strcmp(argv[i], "medium"))
      {
        type |= CUPS_PRINTER_MEDIUM;
	mask |= CUPS_PRINTER_MEDIUM;
      }
      else if (!strcmp(argv[i], "large"))
      {
        type |= CUPS_PRINTER_LARGE;
	mask |= CUPS_PRINTER_LARGE;
      }
      else
        usage(argv[i]);
    }

    cupsEnumDests(CUPS_DEST_FLAGS_NONE, 5000, NULL, type, mask, enum_cb, NULL);

    return (0);
  }
  else if (!strncmp(argv[1], "ipp://", 6) || !strncmp(argv[1], "ipps://", 7))
    dest = cupsGetDestWithURI(NULL, argv[1]);
  else
    dest = cupsGetNamedDest(CUPS_HTTP_DEFAULT, argv[1], NULL);

  if (!dest)
  {
    printf("testdest: Unable to get destination \"%s\": %s\n", argv[1], cupsLastErrorString());
    return (1);
  }

  if ((http = cupsConnectDest(dest, CUPS_DEST_FLAGS_NONE, 30000, NULL, NULL, 0, NULL, NULL)) == NULL)
  {
    printf("testdest: Unable to connect to destination \"%s\": %s\n", argv[1], cupsLastErrorString());
    return (1);
  }

  if ((dinfo = cupsCopyDestInfo(http, dest)) == NULL)
  {
    printf("testdest: Unable to get information for destination \"%s\": %s\n", argv[1], cupsLastErrorString());
    return (1);
  }

  if (argc == 2 || (!strcmp(argv[2], "supported") && argc < 6))
  {
    if (argc > 3)
      show_supported(http, dest, dinfo, argv[3], argv[4]);
    else if (argc > 2)
      show_supported(http, dest, dinfo, argv[3], NULL);
    else
      show_supported(http, dest, dinfo, NULL, NULL);
  }
  else if (!strcmp(argv[2], "conflicts") && argc > 3)
  {
    int			i,		/* Looping var */
			num_options = 0;/* Number of options */
    cups_option_t	*options = NULL;/* Options */

    for (i = 3; i < argc; i ++)
      num_options = cupsParseOptions(argv[i], num_options, &options);

    show_conflicts(http, dest, dinfo, num_options, options);
  }
  else if (!strcmp(argv[2], "default") && argc == 4)
  {
    show_default(http, dest, dinfo, argv[3]);
  }
  else if (!strcmp(argv[2], "localize") && argc < 6)
  {
    if (argc > 3)
      localize(http, dest, dinfo, argv[3], argv[4]);
    else if (argc > 2)
      localize(http, dest, dinfo, argv[3], NULL);
    else
      localize(http, dest, dinfo, NULL, NULL);
  }
  else if (!strcmp(argv[2], "media"))
  {
    int		i;			/* Looping var */
    const char	*name = NULL;		/* Media name, if any */
    unsigned	flags = CUPS_MEDIA_FLAGS_DEFAULT;
					/* Media selection flags */

    for (i = 3; i < argc; i ++)
    {
      if (!strcmp(argv[i], "borderless"))
	flags = CUPS_MEDIA_FLAGS_BORDERLESS;
      else if (!strcmp(argv[i], "duplex"))
	flags = CUPS_MEDIA_FLAGS_DUPLEX;
      else if (!strcmp(argv[i], "exact"))
	flags = CUPS_MEDIA_FLAGS_EXACT;
      else if (!strcmp(argv[i], "ready"))
	flags = CUPS_MEDIA_FLAGS_READY;
      else if (name)
        usage(argv[i]);
      else
        name = argv[i];
    }

    show_media(http, dest, dinfo, flags, name);
  }
  else if (!strcmp(argv[2], "print") && argc > 3)
  {
    int			i,		/* Looping var */
			num_options = 0;/* Number of options */
    cups_option_t	*options = NULL;/* Options */

    for (i = 4; i < argc; i ++)
      num_options = cupsParseOptions(argv[i], num_options, &options);

    print_file(http, dest, dinfo, argv[3], num_options, options);
  }
  else
    usage(argv[2]);

  return (0);
}
Esempio n. 28
0
/** Main function.
 * @param argc
 * @param argv
 * @return A return code indicating success, failure, etc.
 */
int main(int argc, char *argv[])
{
	int ret = 0;
	size_t i;
	struct sigaction new_action, old_action;
	const int signals[] = { SIGHUP, SIGINT, SIGTERM, SIGSEGV, SIGWINCH };
	uid_t myuid = getuid();

	/* Set signal handlers */
	/* Set up the structure to specify the new action. */
	new_action.sa_handler = handler;
	sigemptyset(&new_action.sa_mask);
	new_action.sa_flags = SA_RESTART;

	/* assign our handler to any signals we care about */
	for(i = 0; i < sizeof(signals) / sizeof(signals[0]); i++) {
		int signal = signals[i];
		sigaction(signal, NULL, &old_action);
		if(old_action.sa_handler != SIG_IGN) {
			sigaction(signal, &new_action, NULL);
		}
	}

	/* i18n init */
#if defined(ENABLE_NLS)
	localize();
#endif

	/* set user agent for downloading */
	setuseragent();

	/* init config data */
	if(!(config = config_new())) {
		/* config_new prints the appropriate error message */
		cleanup(1);
	}

	/* disable progressbar if the output is redirected */
	if(!isatty(fileno(stdout))) {
		config->noprogressbar = 1;
	}

	/* Priority of options:
	 * 1. command line
	 * 2. config file
	 * 3. compiled-in defaults
	 * However, we have to parse the command line first because a config file
	 * location can be specified here, so we need to make sure we prefer these
	 * options over the config file coming second.
	 */

	/* parse the command line */
	ret = parseargs(argc, argv);
	if(ret != 0) {
		cleanup(ret);
	}

	/* we support reading targets from stdin if a cmdline parameter is '-' */
	if(alpm_list_find_str(pm_targets, "-")) {
		if(!isatty(fileno(stdin))) {
			int target_found = 0;
			size_t current_size = PATH_MAX;
			char *vdata, *line = malloc(current_size);
			int c;

			/* remove the '-' from the list */
			pm_targets = alpm_list_remove_str(pm_targets, "-", &vdata);
			free(vdata);

			i = 0;
			do {
				c = fgetc(stdin);
				if(c == EOF || isspace(c)) {
					/* avoid adding zero length arg when multiple spaces separate args */
					if(i > 0) {
						line[i] = '\0';
						pm_targets = alpm_list_add(pm_targets, strdup(line));
						target_found = 1;
						i = 0;
					}
				} else {
					line[i++] = (char)c;
					/* we may be at the end of our allocated buffer now */
					if(i >= current_size) {
						char *new = realloc(line, current_size * 2);
						if(new) {
							line = new;
							current_size *= 2;
						} else {
							free(line);
							pm_printf(ALPM_LOG_ERROR,
									_("memory exhausted in argument parsing\n"));
							cleanup(EXIT_FAILURE);
						}
					}
				}
			} while(c != EOF);
Esempio n. 29
0
int MENUS::render_menubar(RECT r)
{
	RECT box = r;
	RECT button;
	
	int active_page = config.ui_page;
	int new_page = -1;
	
	if(client_state() != CLIENTSTATE_OFFLINE)
		active_page = game_page;
	
	if(client_state() == CLIENTSTATE_OFFLINE)
	{
		/* offline menus */
		if(0) // this is not done yet
		{
			ui_vsplit_l(&box, 90.0f, &button, &box);
			static int news_button=0;
			if (ui_do_button(&news_button, localize("News"), active_page==PAGE_NEWS, &button, ui_draw_menu_tab_button, 0))
				new_page = PAGE_NEWS;
			ui_vsplit_l(&box, 30.0f, 0, &box); 
		}

		ui_vsplit_l(&box, 100.0f, &button, &box);
		static int internet_button=0;
		int corners = CORNER_TL;
		if (ui_do_button(&internet_button, localize("Internet"), active_page==PAGE_INTERNET, &button, ui_draw_menu_tab_button, &corners))
		{
			client_serverbrowse_refresh(BROWSETYPE_INTERNET);
			new_page = PAGE_INTERNET;
		}

		//ui_vsplit_l(&box, 4.0f, 0, &box);
		ui_vsplit_l(&box, 80.0f, &button, &box);
		static int lan_button=0;
		corners = 0;
		if (ui_do_button(&lan_button, localize("LAN"), active_page==PAGE_LAN, &button, ui_draw_menu_tab_button, &corners))
		{
			client_serverbrowse_refresh(BROWSETYPE_LAN);
			new_page = PAGE_LAN;
		}

		//ui_vsplit_l(&box, 4.0f, 0, &box);
		ui_vsplit_l(&box, 110.0f, &button, &box);
		static int favorites_button=0;
		corners = CORNER_TR;
		if (ui_do_button(&favorites_button, localize("Favorites"), active_page==PAGE_FAVORITES, &button, ui_draw_menu_tab_button, &corners))
		{
			client_serverbrowse_refresh(BROWSETYPE_FAVORITES);
			new_page  = PAGE_FAVORITES;
		}
		
		ui_vsplit_l(&box, 4.0f*5, 0, &box);
		ui_vsplit_l(&box, 100.0f, &button, &box);
		static int demos_button=0;
		if (ui_do_button(&demos_button, localize("Demos"), active_page==PAGE_DEMOS, &button, ui_draw_menu_tab_button, 0))
		{
			demolist_populate();
			new_page  = PAGE_DEMOS;
		}		
	}
	else
	{
		/* online menus */
		ui_vsplit_l(&box, 90.0f, &button, &box);
		static int game_button=0;
		if (ui_do_button(&game_button, localize("Game"), active_page==PAGE_GAME, &button, ui_draw_menu_tab_button, 0))
			new_page = PAGE_GAME;

		ui_vsplit_l(&box, 4.0f, 0, &box);
		ui_vsplit_l(&box, 140.0f, &button, &box);
		static int server_info_button=0;
		if (ui_do_button(&server_info_button, localize("Server info"), active_page==PAGE_SERVER_INFO, &button, ui_draw_menu_tab_button, 0))
			new_page = PAGE_SERVER_INFO;

		ui_vsplit_l(&box, 4.0f, 0, &box);
		ui_vsplit_l(&box, 140.0f, &button, &box);
		static int callvote_button=0;
		if (ui_do_button(&callvote_button, localize("Call vote"), active_page==PAGE_CALLVOTE, &button, ui_draw_menu_tab_button, 0))
			new_page = PAGE_CALLVOTE;
			
		ui_vsplit_l(&box, 30.0f, 0, &box);
	}
		
	/*
	ui_vsplit_r(&box, 110.0f, &box, &button);
	static int system_button=0;
	if (ui_do_button(&system_button, "System", config.ui_page==PAGE_SYSTEM, &button, ui_draw_menu_tab_button, 0))
		config.ui_page = PAGE_SYSTEM;
		
	ui_vsplit_r(&box, 30.0f, &box, 0);
	*/
	
	ui_vsplit_r(&box, 90.0f, &box, &button);
	static int quit_button=0;
	if (ui_do_button(&quit_button, localize("Quit"), 0, &button, ui_draw_menu_tab_button, 0))
		popup = POPUP_QUIT;

	ui_vsplit_r(&box, 10.0f, &box, &button);
	ui_vsplit_r(&box, 130.0f, &box, &button);
	static int settings_button=0;
	if (ui_do_button(&settings_button, localize("Settings"), active_page==PAGE_SETTINGS, &button, ui_draw_menu_tab_button, 0))
		new_page = PAGE_SETTINGS;
	
	if(new_page != -1)
	{
		if(client_state() == CLIENTSTATE_OFFLINE)
			config.ui_page = new_page;
		else
			game_page = new_page;
	}
		
	return 0;
}