static void
conn_main(void)
{
  const AtmAddr_t *addr;
  int main_conn;
  const char *str;
  int i;

  addr = get_var_addr(&conn_unit, "S1");
  if (addr == NULL) {
    dump_printf(EL_ERROR, "S1 (LES Address) must be specified");
    event_put(&conn_unit, CE_EXIT, NULL);
  }
  else {
    str = get_var_str(&conn_unit,"S2");
    if (str == NULL) {
      set_var_str(&conn_unit, "S2", S2_default);
    }
    i = get_var_int(&conn_unit,"S3");
    if (i == 0) {
      set_var_int(&conn_unit,"S3", S3_default);
    }
    i = get_var_int(&conn_unit,"S4");
    if (i == 0) {
      set_var_int(&conn_unit,"S4", S4_default);
    }
    i = get_var_int(&conn_unit,"S5");
    if (i == 0) {
      set_var_int(&conn_unit,"S5", S5_default);
    }
    addr = get_var_addr(&conn_unit, "S6");
    if (addr == NULL) {
      dump_printf(EL_ERROR, "S6 (BUS Address) must be specified");
      event_put(&conn_unit, CE_EXIT, NULL);
    } else {
      main_conn = atm_create_socket(CONTROL_DIRECT, 
				    get_var_addr(&conn_unit, "S1"));
      if (main_conn >= 0) {
	(void)conn_add(CT_MAIN, main_conn,0);
      }
    }
  }
}
Exemple #2
0
//Create new variable menu.
int create_var_menu(Variable *varArry, int *arrySize, int arrySpot){
	String type = (String)malloc(ARRAYLENGHT * sizeof (char));
	String name = (String)malloc(ARRAYLENGHT * sizeof (char));
	int flag;

	//Check if memory allocated properly.
	mem_check(type);
	mem_check(name);

	//Get the variable's type
	do{
		//User interaction.
		printf("%s", "\n\nGive the variable's type. Valid types are Integer, Decimal, String and Bool. To go back type <:");
		fgets(type, ARRAYLENGHT, stdin);
		
		flag = false;
		if (type[strlen(type) - 1] == '\n' && strlen(type) > 1){
			type[strcspn(type, "\n")] = 0; //Drop the \n from fgets input
			strtolower(type); //Convert the string to lowercase for ease of use.

			//Check for back input
			if (!strcmp(type, "<")){
				return false;
			}

			//Check for valid input.
			if (strcmp(type, "integer") && strcmp(type, "decimal") && strcmp(type, "string") && strcmp(type, "bool")){
				printf("%s", "\n\nInvalid type!\n\n");
			}
		}
		else{
			flag = true;
			printf("%s", "\n\nInvalid lenght. It must be between 1 and 255 characters!\n\n");
			if (strlen(type) > 1)
				clear_stdin(); //Clear stdin from extra input
		}
	
	} while (strcmp(type, "integer") && strcmp(type, "decimal") && strcmp(type, "string") && strcmp(type, "bool") || flag); //Loop until user decides to cooperate.

	//Get the variable's name.
	do{
		//User interaction.
		printf("%s", "\n\nGive a name for the variable. The max lenght is 255 characters. It can't contain whitespaces or symbols, except underscores (_):");
		fgets(name, ARRAYLENGHT, stdin);

		flag = false;
		//Check for valid lenght
		if (name[strlen(name) - 1] == '\n' && strlen(name) > 2){
			name[strcspn(name, "\n")] = 0; //Drop the \n from fgets input.

			//Check for valid input
			if (strpbrk(name, " !@#$%^&*()-+=\\|[]{};\':\",./<>?") != NULL){
				printf("%s", "\n\nInvalid name!\n\n");
			}
			else if (var_exist(varArry, name, *arrySize)){
				printf("%s", "\n\nA variable with that name already exists!\n\n");
			}
		}
		else{
			flag = true;
			printf("%s", "\n\nInvalid lenght. It must be between 1 and 255 characters!\n\n");
			if (strlen(name) > 1)
				clear_stdin(); //Clear stdin from extra input
		}
	} while (flag || strpbrk(name, " `~!@#$%^&*()-+=\\|[]{};\':\",./<>?") != NULL || var_exist(varArry, name, *arrySize)); //Loop until valid.

	//Copy the name and the type in the variables struct array.
	strcpy(varArry[arrySpot].type, type);
	strcpy(varArry[arrySpot].name, name);

	//Free the memory we don't need anymore.
	free(name);
	free(type);

	//Run the function corresponding to the entered type.
	if (!strcmp(varArry[arrySpot].type, "integer")){
		set_var_int(varArry, arrySpot);
	}
	else if (!strcmp(varArry[arrySpot].type, "decimal")){
		set_var_decimal(varArry, arrySpot);
	}
	else if (!strcmp(varArry[arrySpot].type, "string")){
		//Loop until the lenght is correct.
		do{
			//User interaction. For strings we don't need any valid input checks.
			printf("%s", "\n\nGive the variables value (String, 255 characters max):");
			fgets(varArry[arrySpot].value, ARRAYLENGHT, stdin);

			flag = false;
			if (varArry[arrySpot].value[strlen(varArry[arrySpot].value) - 1] == '\n')
				varArry[arrySpot].value[strcspn(varArry[arrySpot].value, "\n")] = 0; //Drop the \n from fgets input.
			else{
				flag = true;
				printf("%s", "\n\nInvalid lenght. It must be between 1 and 255 characters!\n\n");
				clear_stdin(); //Clear stdin from extra input
			}

		} while (flag);
	}
	else{
		set_var_bool(varArry, arrySpot);
	}

	return true;
}
Exemple #3
0
static void set_player_dir(Dir which)
{
    set_var_int("gangd", which);
}
Exemple #4
0
static void set_player_pos(const Pos &p)
{
    set_var_int("gangx", p.x + 1);
    set_var_int("gangy", p.y);
}
Exemple #5
0
void
load_vars(const char *file)
{
  const Unit_t *curr_unit = NULL;

  int ret = 0;   /* to silence gcc 2.7.2.1 */
  char *varname;
  InitPvc_t *pvc;
  LaneDestList_t *ltmp;
  int read_flag = 1;

  assert(file != NULL);
  Debug_unit(&load_unit, "Loading variables from file %s", file);
  yyin = fopen(file, "r");
  if (!yyin) {
    Debug_unit(&load_unit, "Cannot open file %s: %s", file, strerror(errno));
    return;
  }
  g_buf_index = 0;
  do {
    if (read_flag)
      ret = yylex();
    else
      read_flag =1;
    switch(ret) {
    case END:
      Debug_unit(&load_unit, "EOF");
      break;
    case UNIT:
      Debug_unit(&load_unit, "Got unit %s", g_return.stringgi);
      curr_unit = find_unit(g_return.stringgi);
      if (curr_unit == NULL) {
	Debug_unit(&load_unit, "Unknown unit %s", g_return.stringgi);
      }
      Debug_unit(&load_unit, "Got unit %s", g_return.stringgi);
      mem_free(&load_unit,g_return.stringgi);
      break;
    case VARNAME:
      varname = g_return.stringgi;
      Debug_unit(&load_unit, "Got variable name %s", varname);
      ret = yylex();
      switch(ret) {
      case STRING:
	Debug_unit(&load_unit, "Variable is string: %s", g_return.stringgi);
	set_var_str(curr_unit, varname, g_return.stringgi);
	break;
      case BOOLEAN:
	Debug_unit(&load_unit, "Variable is boolean: %s", 
		   g_return.bool==BL_TRUE?"True":"False");
	set_var_bool(curr_unit, varname, g_return.bool);
	break;
      case INTEGER:
	Debug_unit(&load_unit, "Variable is integer: %d", g_return.intti);
	set_var_int(curr_unit, varname, g_return.intti);
	break;
      case ATMADDRESS:
	Debug_unit(&load_unit, "Variable is atmaddress ");
	dump_atmaddr(g_return.atmaddress);
	set_var_addr(curr_unit, varname, g_return.atmaddress);
	break;
      case LANEDEST:
	Debug_unit(&load_unit, "Invalid variable value for %s", varname);
	mem_free(&load_unit, g_return.destaddr);
	break;
      case UNIT:
	Debug_unit(&load_unit, "Invalid variable value for %s", varname);
	mem_free(&load_unit, g_return.stringgi);
	break;
      case VCC:
	Debug_unit(&load_unit, "Variable is vcc");
	pvc = (InitPvc_t *)mem_alloc(curr_unit, sizeof(InitPvc_t));
	pvc->pvc = (LaneVcc_t *)mem_alloc(curr_unit, sizeof(LaneVcc_t));
	pvc->pvc->port = g_return.vcc.port;
	pvc->pvc->vpi = g_return.vcc.vpi;
	pvc->pvc->vci = g_return.vcc.vci;
	pvc->address = NULL;
	pvc->lecid = 0;
	pvc->destinations = NULL;
	ret = yylex();
	if (ret != ATMADDRESS) {
	  Debug_unit(&load_unit, "Invalid atm_address for pvc %d,%d,%d",
		     pvc->pvc->port, pvc->pvc->vpi, pvc->pvc->vci);
	  switch(ret) {
	  case UNIT:
	  case STRING:
	  case VARNAME:
	    mem_free(&load_unit, g_return.stringgi);
	    break;
	  case LANEDEST:
	    mem_free(&load_unit, g_return.destaddr);
	    break;
	  }
	} else {
	  pvc->address = g_return.atmaddress;
	}
	ret = yylex();
	if (ret != INTEGER) {
	  Debug_unit(&load_unit, "Invalid lecid for pvc %d,%d,%d\n",
		     pvc->pvc->port,pvc->pvc->vpi,pvc->pvc->vci);
	  switch(ret) {
	  case UNIT:
	  case STRING:
	  case VARNAME:
	    mem_free(&load_unit, g_return.stringgi);
	    break;
	  case LANEDEST:
	    mem_free(&load_unit, g_return.destaddr);
	    break;
	  case ATMADDRESS:
	    mem_free(&load_unit, g_return.atmaddress);
	    break;
	  }
	} else {
	  pvc->lecid = g_return.intti;
	}
	while((ret=yylex())==LANEDEST) {
	  ltmp=(LaneDestList_t *)mem_alloc(&load_unit, sizeof(LaneDestList_t));
	  ltmp->addr = g_return.destaddr;
	  ltmp->next = pvc->destinations;
	  pvc->destinations = ltmp;
	}
	read_flag=0;
	set_var_vcc(curr_unit, varname, pvc);
	break;	
      default:
	Debug_unit(&load_unit, "Invalid variable value for %s", varname);
	break;
      }
      break;
    case STRING:
      Debug_unit(&load_unit,"Invalid string placement %s",g_return.stringgi);
      mem_free(&load_unit, g_return.stringgi);
      break;
    case ATMADDRESS:
      Debug_unit(&load_unit, "Invalid atm address placement");
      mem_free(&load_unit, g_return.atmaddress);
      break;
    case LANEDEST:
      Debug_unit(&load_unit, "Invalid lane destination placement");
      mem_free(&load_unit, g_return.destaddr);
      break;
    case INTEGER:
      Debug_unit(&load_unit, "Invalid integer placement");
      break;
    default:
      Debug_unit(&load_unit, "Invalid input");
      break;
    }
  } while (ret != END);
  if (fclose(yyin) != 0) {
    Debug_unit(&load_unit, "Cannot close file %s: %s", file, strerror(errno));
  }
}
Exemple #6
0
//----------------------------------------------------------------------
const char* parse_args(int argc, const char** argv, int parseonly,
                       struct log2mem_handle * handle)
{
  int i = 1;
  const char* filename = 0;
  int defaultshow = 1;

  enum showbits
  {
    eSummary  = 0x01,
    eCounters = 0x02,
    eRows     = 0x04,
    eVars     = 0x08
  };
  int toshow = 0;

  for (;i < argc; i++)
  {
    if ( strcmp(argv[i], "-h")==0 || strcmp(argv[i],"--help")==0 ) help();
    else if (strcmp(argv[i], "-s")==0)
    {
      toshow |= eSummary;
    }
    else if (strcmp(argv[i], "-c")==0)
    {
      toshow |= eCounters;
    }
    else if (strcmp(argv[i], "-r")==0)
    {
      toshow |= eRows;
    }
    else if (strcmp(argv[i], "-v")==0)
    {
      toshow |= eVars;
    }
    else if (strcmp(argv[i], "-a")==0)
    {
      toshow |= ~eSummary;
    }
    else if (strcmp(argv[i], "-F")==0)
    {
      if (++i >= argc) die("missing argument to -F", NULL);
      g_delim = argv[i];
      g_showdelim = 1;
    }
    else if (strcmp(argv[i], "-z")==0)
    {
      g_showdelim = 0;
    }
    else if (strcmp(argv[i], "-t")==0)
    {
      g_terse = 1;
    }
    else if (strcmp(argv[i], "--version")==0)
    {
      printf("log2mem version: " PACKAGE_VERSION "\n");
      exit(1);
    }
    else if (strncmp(argv[i], OPT_DOUBLE, strlen(OPT_DOUBLE))==0)
    {
      set_var_double(argc, argv, &i, handle);
      defaultshow = 0;
    }
    else if (strncmp(argv[i], OPT_INT, strlen(OPT_INT))==0)
    {
      set_var_int(argc, argv, &i, handle);
      defaultshow = 0;
    }
    else if (strncmp(argv[i], OPT_STRING, strlen(OPT_STRING))==0)
    {
      set_var_string(argc, argv, &i, handle);
      defaultshow = 0;
    }
    else if ((strncmp(argv[i], "--",2)==0) && strlen(argv[i])>2 )
    {
      set_var_by_name(argc, argv, &i, handle);
      defaultshow = 0;
    }
    else
    {
      if (filename == 0)
        filename = argv[i];
      else
      {
        die("unexpected argument: ", argv[i]);
      }
    }
  }

  if (defaultshow && !toshow) toshow = 0xFFFF;

  if (!parseonly)
  {
    //if (toshow & eSummary)  print_summary(handle);
    if (toshow & eRows)     print_rows(handle);
    if (toshow & eCounters) print_counters(handle);
    if (toshow & eVars)     print_vars(handle);
  }

  return filename;
}