Exemple #1
0
int check_for(is_for* node, is_label* label)
{
	int errors = 0, cond_errors;
	char* typeA;

	int mylabel = ++label_counter; /* setting label for use with loops and break/continue */

	if (label)
		node->scope = scope_new(symbol_new_loop(label->name, node->line, mylabel), false);
	else
		node->scope = scope_new(symbol_new_loop(NULL, node->line, mylabel), false);
		
	scope_push(node->scope);
		if (node->init)
			errors += check_for_init(node->init);

		if (node->cond)
		{
			cond_errors = check_for_cond(node->cond);
			if (cond_errors == 0)
			{
				if (!type_native_assign_able(t_type_native_bool, node->cond->s_type))
				{
					cond_errors++;
					pretty_error(node->line, "for conditional is not boolean (is of type %s)", typeA = string_type_decl(node->cond->s_type));
					free(typeA);
				}
			}
			errors += cond_errors;
		}
	
		if (node->inc)
			errors += check_for_inc(node->inc);

		errors += check_stmt(node->body);

		if (errors == 0)
			node->terminates = (node->body ? node->body->terminates : true);
	scope_pop();
 
	return errors;
}
Exemple #2
0
/*
 * getNetBaud()
 *
 * This gets the baud of network caller -- refer to SysDep.doc
 */
char getNetBaud()
{
    extern UNS_16 intrates[];
    extern FILE *netLog;
    int		Time, baudRunner;
    extern int	BaudRate;
    char	laterMessage[100];
    char	found = FALSE, notFinished;
    extern char inNet;

	/* If anytime answer, then we already have baud rate */

    sprintf(laterMessage,
 "System will be in network mode for another %d minutes; please call back.\n",
							timeLeft());

    if (inNet == ANY_CALL || inNet == STROLL_CALL) {
	found      = TRUE;
	baudRunner = LastBaudIndex;
    }
    else if (GetFirst(&ResList)) {
	if ((baudRunner = getModemId()) != ERROR) {
	    found = TRUE;
	    setNetCallBaud(baudRunner);
	}
    }

    pause(50);	/* Pause a half second */

    if (found) {
	BaudRate = atoi(rates[baudRunner]);
	for (Time = 0; gotCarrier() && Time < 20; Time++) {
	    if (check_for_init(FALSE)) return TRUE;
	    if (cfg.BoolFlags.debug) splitF(netLog, ".\n");
	}
	if (gotCarrier()) {
	    outFlag = IMPERVIOUS;
	    mPrintf(laterMessage);
	}
    }
    else {
	while (MIReady())   Citinp();	/* Clear garbage	*/

	for (Time = 0; gotCarrier() && Time < 20; Time++) {
	    for (notFinished = TRUE, baudRunner = 0; 
					gotCarrier() && notFinished;) {
		BaudRate = intrates[baudRunner]*10;
		setNetCallBaud(baudRunner);
		if (check_for_init(FALSE)) return TRUE;  /* get connection */
		if (cfg.BoolFlags.debug) splitF(netLog, ".\n");
		notFinished = !(baudRunner == cfg.sysBaud);
		baudRunner++;
	    }
	}

	if (gotCarrier()) {
	    outFlag = IMPERVIOUS;
	    for (baudRunner = cfg.sysBaud; baudRunner > -1; baudRunner--) {
		setNetCallBaud(baudRunner);
		mPrintf(laterMessage);
	    }
	    outFlag = OUTOK;
	}
    }
    if (!gotCarrier()) splitF(netLog, "Lost carrier\n");
    killConnection("gnb");
    return FALSE;
}
int main(int argc , char *argv[])
{
  // init vehicle
  init_vehicle();

  // connect to server
  if(connect_server() != 0) {
    // error
    puts("Closing.");
    return 0;
  }

  // connected
  puts("All peachy.");
  puts("Sending hi.");


  // lets go in big loop and process incoming data
  while(veh.flag){
    // Sort of hearbeat
    //send_hi();

    // recv is blocking call
    // data from server
    veh.cnt = recv(veh.socket_desc, veh.server_reply , SERVER_MSG_SIZE , 0);
    if (veh.cnt > 0 ) {
      // we received data
      // print to terminal that a message from server came in
      printf("RECEIVED: %d BYTES\n", veh.cnt);
      printf("MSG FROM SERVER: %s\n", veh.server_reply);

      if (check_for_init() == 1){
        // wasn't init
        // check for stop
        if (check_for_stop() == 1) {
          // wasn't stop
          // check for params
          if (check_for_params() == 1) {
            // wasn't params
            // check for quit
            if (check_for_quit() == 1) {
              // it wasn't quit -> bad command
              printf("Unknown command.\n");
            }
            else {
              //it was quit -> so quit
              veh.flag = 0;
            }
          }
        }
      }

      // send proper response
      send(veh.socket_desc, veh.message, strlen(veh.message), 0);
    }
    else {
      puts("Received no data.");
      // no data -> server probably ended the connection
      veh.flag = 0;
    }

    // erase server reply
    memset(veh.server_reply, 0, SERVER_MSG_SIZE);
    // erase message
    memset(veh.message, 0, SERVER_MSG_SIZE);
    // erase counter
    veh.cnt = 0;
    // sleep 500ms
    //nanosleep((const struct timespec[]){{0, NSLEEP_TIME}}, NULL);

  } // veh.flag

  puts("Closing program.");
  shutdown(veh.socket_desc, 2); // close socket
  if (veh.state != VEH_UNINIT){
    // dont call unless properly initialized
    stop_wings();
  }
  return 0;
}