Пример #1
0
void keyboard::update_mapping( void )
{
	auto cookie = xcb_get_modifier_mapping_unchecked( _connection );
	if ( _keysyms )
		xcb_key_symbols_free( _keysyms );
	_keysyms = xcb_key_symbols_alloc( _connection );

	auto numlockcodes = core::wrap_cptr( xcb_key_symbols_get_keycode( _keysyms, XK_Num_Lock ) );
	auto shiftlockcodes = core::wrap_cptr( xcb_key_symbols_get_keycode( _keysyms, XK_Shift_Lock ) );
	auto capslockcodes = core::wrap_cptr( xcb_key_symbols_get_keycode( _keysyms, XK_Caps_Lock ) );
	auto modeswitchcodes = core::wrap_cptr( xcb_key_symbols_get_keycode( _keysyms, XK_Mode_switch ) );

	auto modmap_r = core::wrap_cptr( xcb_get_modifier_mapping_reply( _connection, cookie, nullptr ) );
	xcb_keycode_t *modmap = xcb_get_modifier_mapping_keycodes( modmap_r.get() );

	_numlock = 0;
	_shiftlock = 0;
	_capslock = 0;
	_modeswitch = 0;

	for( int i = 0; i < 8; i++ )
	{
		for( int j = 0; j < modmap_r->keycodes_per_modifier; j++ )
		{
			xcb_keycode_t kc = modmap[i * modmap_r->keycodes_per_modifier + j];
			look_for( _numlock, numlockcodes, kc, i );
			look_for( _shiftlock, shiftlockcodes, kc, i );
			look_for( _capslock, capslockcodes, kc, i );
			look_for( _modeswitch, modeswitchcodes, kc, i );
		}
	}
}
Пример #2
0
main()
{
	char buf[1024];
	int people;
	int comps;
	int i = 0;
	int j = 0;
	int a, b;
	int ma, mb; // the mysterious ones
	
	// setup the memoization table
	memo_tab = malloc(100 * sizeof(char *));
	for (i = 0; i < 100; ++i) {
		memo_tab[i] = malloc(100);
		for (j = 0; j < 100; ++j)
			memo_tab[i][j] = 0;
	}
	
	fgets(buf, 1024, stdin);
	sscanf(buf, "%d %d", &people, &comps);
	
	lists = malloc((people+1) * sizeof(derp_t *));
	if (!lists) {
		printf("aw snap, malloc failed\n");
		exit(1);
	}
	
	for (i = 0; i < people + 1; ++i)
		lists[i] = new_derp(i);
	
	// set up the list from known info
	for (i = 0; i < comps; ++i) {
		fgets(buf, 1024, stdin);
		sscanf(buf, "%d %d", &a, &b);
		//printf("k so %d is taller than %d kthxbye\n", a, b);
		add_child(a, b);
	}
	
	// now solve the mystery lololol
	fgets(buf, 1024, stdin);
	sscanf(buf, "%d %d", &ma, &mb);
	if (look_for(ma, mb))
		printf("yes\n");
	else if (look_for(mb, ma))
		printf("no\n");
	else
		printf("unknown\n");
	
	return 0;
}
Пример #3
0
static void step_predicate_parser(parser_context *context)
{
    enter_state(context, ST_PREDICATE);

    skip_ws(context);
    if('[' == get_char(context))
    {
        consume_char(context);
        if(!look_for(context, "]"))
        {
            context->result.code = ERR_UNBALANCED_PRED_DELIM;
            return;
        }
        skip_ws(context);
        if(']' == get_char(context))
        {
            context->result.code = ERR_EMPTY_PREDICATE;
            return;
        }

        try_predicate_parser(wildcard_predicate);
        try_predicate_parser(subscript_predicate);
        try_predicate_parser(slice_predicate);

        if(JSONPATH_SUCCESS != context->result.code && ERR_PARSER_OUT_OF_MEMORY != context->result.code)
        {
            context->result.code = ERR_UNSUPPORTED_PRED_TYPE;
        }
    }
    else
    {
        unexpected_value(context, '[');
    }
}
Пример #4
0
static void step_parser(parser_context *context)
{
    if(look_for(context, "()"))
    {
        node_type_test(context);
        if(JSONPATH_SUCCESS == context->result.code && has_more_input(context))
        {
            consume_char(context);
            consume_char(context);
        }
    }
    else
    {
        name_test(context);
    }

    if(JSONPATH_SUCCESS == context->result.code && has_more_input(context))
    {
        step_predicate_parser(context);
    }

    if(ERR_UNEXPECTED_VALUE == context->result.code && '[' == context->result.expected_char)
    {
        enter_state(context, ST_STEP);
        context->result.code = JSONPATH_SUCCESS;
    }
}
Пример #5
0
int look_for_raw(int r, int c)
{
	int i;
	
	if (check_child(r, c))
		return 1;
		
	for (i = 0; i < lists[r]->cnt; ++i)
		if (look_for(lists[r]->tt[i], c))
			return 1;
			
	return 0;
}
Пример #6
0
void
rd_particle_specs(FILE *ifp, char *input)
{
  PBC_t *PBC;
  char err_msg[MAX_CHAR_ERR_MSG], s_tmp[SLEN], s_tmp_save[SLEN_2], *s_ptr1, *s_ptr2;
  int i, j, iread;

  iread = look_for_optional(ifp, "Particle Specifications", input, '=');
  if(iread != 1)
    {
      Particle_Dynamics = 0;
      Particle_Number_Sample_Types = 0;
      Particle_Number_Samples_Existing = NULL;
      Particle_Number_Samples = NULL;
      Particle_Number_Output_Variables = NULL;
      Particle_Output_Variables = NULL;
      Particle_Filename_Template = NULL;
      Particle_Number_PBCs = 0;
      PBCs = NULL;
      return;
    }

  printf("\n--- Particle specifications ---\n");
  Particle_Dynamics = 1;	/* turn on particle dynamics */

  /* What kind of particle model do you want?  This determines all
   * kinds of things, such as FEM<->particle coupling, particle
   * trajectory calculation, etc. */
  look_for(ifp, "Particle model", input, '=');
  if(!fgets(s_tmp, SLEN-1, ifp))
    EH(-1, "Error reading Particle model card.");
  strip(s_tmp);			/* s_tmp still has '\n' at end */
  if(s_tmp[strlen(s_tmp)-1] == '\n')
    s_tmp[strlen(s_tmp)-1] = 0;
  strcpy(s_tmp_save, s_tmp);
  s_ptr1 = strpbrk(s_tmp_save, " \t\n");
  if(s_ptr1 != NULL)
    s_ptr1[0] = 0;
  if(!strncmp("INERTIAL_TRACER_EXPLICIT", s_tmp, 24))
    Particle_Model = INERTIAL_TRACER_EXPLICIT;
  else if(!strncmp("INERTIAL_TRACER_IMPLICIT", s_tmp, 24))
    Particle_Model = INERTIAL_TRACER_IMPLICIT;
  else if(!strncmp("TRACER_EXPLICIT", s_tmp, 15))
    Particle_Model = TRACER_EXPLICIT;
  else if(!strncmp("TRACER_IMPLICIT", s_tmp, 15))
    Particle_Model = TRACER_IMPLICIT;
  else if(!strncmp("SWIMMER_EXPLICIT", s_tmp, 16))
    Particle_Model = SWIMMER_EXPLICIT;
  else if(!strncmp("SWIMMER_IMPLICIT", s_tmp, 16))
    Particle_Model = SWIMMER_IMPLICIT;
  else if(!strncmp("CHARGED_TRACER_EXPLICIT", s_tmp, 23))
    Particle_Model = CHARGED_TRACER_EXPLICIT;
  else if(!strncmp("CHARGED_TRACER_IMPLICIT", s_tmp, 23))
    Particle_Model = CHARGED_TRACER_IMPLICIT;
  else if(!strncmp("DIELECTROPHORETIC_TRACER_IMPLICIT", s_tmp, 33))
    Particle_Model = DIELECTROPHORETIC_TRACER_IMPLICIT;
  else
    {
      sprintf(s_tmp_save, "Unknown Particle model: %s\n", s_tmp);
      EH(-1, s_tmp_save);
    }
  printf("Setting Particle_Model = %s\n", s_tmp_save);

  switch(Particle_Model)
    {
    case INERTIAL_TRACER_IMPLICIT:
    case INERTIAL_TRACER_EXPLICIT:
      s_ptr1 = s_tmp + 24;
      if(!(s_ptr2 = strtok(s_ptr1, " \t\n")))
	{
	  sprintf(err_msg, "Error reading random walk coefficient for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[0] = atof(s_ptr2);
      printf("Setting random walk coefficient = %g\n", Particle_Model_Data[0]);
      
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading gravity coefficient for %s particle_model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[1] = atof(s_ptr2);
      printf("Setting gravity coefficient = %g\n", Particle_Model_Data[1]);
      break;
    case TRACER_EXPLICIT:
    case TRACER_IMPLICIT:
      s_ptr1 = s_tmp + 15;
      if(!(s_ptr2 = strtok(s_ptr1, " \t\n")))
	{
	  sprintf(err_msg, "Error reading random walk coefficient for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[0] = atof(s_ptr2);
      printf("Setting random walk coefficient = %g\n", Particle_Model_Data[0]);
      break;
    case SWIMMER_EXPLICIT:
    case SWIMMER_IMPLICIT:
      s_ptr1 = s_tmp + 16;
      if(!(s_ptr2 = strtok(s_ptr1, " \t\n")))
	{
	  sprintf(err_msg, "Error reading random swimming speed coefficient for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[0] = atof(s_ptr2);
      printf("Setting random swimming speed coefficient = %g\n", Particle_Model_Data[0]);
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading random cell orientation coefficient for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[1] = atof(s_ptr2);
      printf("Setting random cell orientation coefficient = %g\n", Particle_Model_Data[1]);
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading upswimming speed for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[2] = atof(s_ptr2);
      printf("Setting particle upswimming speed = %g\n", Particle_Model_Data[2]);
      break;
    case CHARGED_TRACER_EXPLICIT:
    case CHARGED_TRACER_IMPLICIT:
      s_ptr1 = s_tmp + 23;
      if(!(s_ptr2 = strtok(s_ptr1, " \t\n")))
	{
	  sprintf(err_msg, "Error reading random walk coefficient for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[0] = atof(s_ptr2);
      printf("Setting random walk coefficient = %g\n", Particle_Model_Data[0]);
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading charge coefficient for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[1] = atof(s_ptr2);
      printf("Setting charge coefficient = %g\n", Particle_Model_Data[1]);
      break;
    case DIELECTROPHORETIC_TRACER_IMPLICIT:
      s_ptr1 = s_tmp + 33;
      if(!(s_ptr2 = strtok(s_ptr1, " \t\n")))
	{
	  sprintf(err_msg, "Error reading random walk coefficient for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[0] = atof(s_ptr2);
      printf("Setting random walk coefficient = %g\n", Particle_Model_Data[0]);
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading particle permittivity for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[1] = atof(s_ptr2);
      printf("Setting particle permittivity = %g\n", Particle_Model_Data[1]);
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading medium (fluid) permittivity for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[2] = atof(s_ptr2);
      printf("Setting medium (fluid) permittivity = %g\n", Particle_Model_Data[2]);
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading particle conductivity for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[3] = atof(s_ptr2);
      printf("Setting particle conductivity = %g\n", Particle_Model_Data[3]);
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading medium (fluid) conductivity for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[4] = atof(s_ptr2);
      printf("Setting medium (fluid) conductivity = %g\n", Particle_Model_Data[4]);
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading AC angular frequency for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[5] = atof(s_ptr2);
      printf("Setting AC angular frequency = %g\n", Particle_Model_Data[5]);
      if(!(s_ptr2 = strtok(NULL, " \t\n")))
	{
	  sprintf(err_msg, "Error reading Volt conversion factor for %s particle model.", s_tmp);
	  EH(-1, err_msg);
	}
      Particle_Model_Data[6] = atof(s_ptr2);
      printf("Setting Volt conversion factor = %g\n", Particle_Model_Data[6]);
      break;
    default:
      EH(-1, "How'd you get here?");
    }

  /* Get maximum number of particle time steps if we're running after
   * a steady-state solution... */
  if(TimeIntegration == STEADY)
    {
      if(look_for_optional(ifp, "Time steps", input, '=') == 1)
	{
	  if(fscanf(ifp, "%d", &Particle_Max_Time_Steps) != 1)
	    EH(-1, "Error reading Time steps card for post-steady problem.");
	  printf("Setting Particle_Max_Time_Steps = %d\n", Particle_Max_Time_Steps);
	}
      else
	Particle_Max_Time_Steps = 0;
    }
  else
    if(look_for_optional(ifp, "Time steps", input, '=') == 1)
      printf("CAUTION: ignoring Time steps card for transient problem.");

  /* How many particles would you like?  For now, they are always
   * introduced unformly throughout the domain. */
  look_for(ifp, "Number of particles", input, '=');
  if(fscanf(ifp, "%d", &Particle_Number) != 1)
    EH(-1, "Error reading Number of particles card.");
  printf("Setting Particle_Number = %d\n", Particle_Number);

  if(look_for_optional(ifp, "Restart file", input, '=') == 1)
    {
      char file_name_temp[MAX_PARTICLE_FILENAME_LENGTH];
      if(!fgets(file_name_temp, MAX_PARTICLE_FILENAME_LENGTH, ifp))
	EH(-1, "Error reading Restart file card.");
      strip(file_name_temp);
      strncpy(Particle_Restart_Filename, file_name_temp, MAX_PARTICLE_FILENAME_LENGTH);
      printf("Restart file = %s\n", Particle_Restart_Filename);
    }
  else
    sprintf(Particle_Restart_Filename, "<not active>");

  /* When to output particle information.  There are two ways to
   * specify this, and they are incompatible (i.e., only one can be
   * specified).  Either you can output particles every so many Goma
   * time steps, or you can have particles output every so often
   * time-wise (e.g., every 0.1 seconds), whether within a Goma time
   * step or containing many Goma time steps.*/ 
  if(look_for_optional(ifp, "Output stride", input, '=') == 1)
    {
      if(fscanf(ifp, "%d", &Particle_Output_Stride) != 1)
	EH(-1, "Error reading Output stride card.");
      printf("Setting Particle_Output_Stride = %d\n", Particle_Output_Stride);
    }
  else
    Particle_Output_Stride = -1;

  if(look_for_optional(ifp, "Output time step", input, '=') == 1)
    {
      if(fscanf(ifp, "%lf", &Particle_Output_Time_Step) != 1)
	EH(-1, "Error reading Output time step card.");
      printf("Setting Particle_Output_Time_Step = %g\n", Particle_Output_Time_Step);
      if(Particle_Output_Stride != -1)
	EH(-1, "You cannot specify both Output stride and Output time step.");
    }
  else
    Particle_Output_Time_Step = 0.0;

  if(Particle_Output_Stride == -1 &&
     Particle_Output_Time_Step == 0.0)
    EH(-1, "One of the Output stride or Output time step cards must be present.");

  if(look_for_optional(ifp, "Output format", input, '=') == 1)
    {
      if(!fgets(s_tmp, SLEN-1, ifp))
	EH(-1, "Error reading Output format card.");
      strip(s_tmp);			/* s_tmp still has '\n' at end -- don't care. */
      if(!strncmp("TECPLOT", s_tmp, 7))
	Particle_Output_Format = TECPLOT;
      else if(!strncmp("FLAT_TEXT", s_tmp, 9))
	Particle_Output_Format = FLAT_TEXT;
      else
	{
	  sprintf(s_tmp_save, "Unknown Output format: %s\n", s_tmp);
	  EH(-1, s_tmp_save);
	}
    }
  else
    Particle_Output_Format = FLAT_TEXT;

  if(look_for_optional(ifp, "Particle density", input, '=') == 1)
    {
      if(fscanf(ifp, "%lf", &Particle_Density) != 1)
	EH(-1, "Error reading Particle density card.");
    }
  else
    Particle_Density = 1.0;
  printf("Setting Particle_Density = %g\n", Particle_Density);

  if(look_for_optional(ifp, "Particle radius", input, '=') == 1)
    {
      if(fscanf(ifp, "%lf", &Particle_Radius) != 1)
	EH(-1, "Error reading Particle radius card.");
    }
  else
    Particle_Radius = 1.0;
  printf("Setting Particle_Radius = %g\n", Particle_Radius);
  if(Particle_Radius <= 0.0)
    EH(-1, "Particle radius must be > 0.0.  Non-inertial tracer particles will ignore this setting.");

  if(look_for_optional(ifp, "Particle ratio", input, '=') == 1)
    {
      if(fscanf(ifp, "%lf", &Particle_Ratio) != 1)
	EH(-1, "Error reading Particle ratio card.");
    }
  else
    Particle_Ratio = 1.0;
  printf("Setting Particle_Ratio = %g\n", Particle_Ratio);

  Particle_Show_Debug_Info = 0;
  if(look_for_optional(ifp, "Show particle debug info", input, '=') == 1)
    {
      if(fscanf(ifp, "%s", s_tmp) != 1)
	EH(-1, "Need yes or no for Show particle debug info card.");
      if(!strncmp(s_tmp, "YES", 3))
	{
	  Particle_Show_Debug_Info = 1;
	  printf("Showing particle debug info\n");
	}
    }
  if(!Particle_Show_Debug_Info)
    printf("Not showing particle debug info\n");

  /* Initialization for particle creation and move domains. */
  for(i = 0; i < MAX_DOMAIN_REAL_VALUES; i++)
    {
      Particle_Creation_Domain_Reals[i] = 1.0e+10;
      Particle_Move_Domain_Reals[i] = 1.0e+10;
    }
  Particle_Creation_Domain = UNRESTRICTED;
  Particle_Move_Domain = UNRESTRICTED;
  sprintf(Particle_Creation_Domain_Filename, "<not active>");
  sprintf(Particle_Creation_Domain_Name, "<not active>");
  sprintf(Particle_Move_Domain_Filename, "<not active>");
  sprintf(Particle_Move_Domain_Name, "<not active>");

  /* Set optional creation domain. */
  if(look_for_optional(ifp, "Particle creation domain", input, '=') == 1)
    {
      if(fscanf(ifp, "%s", s_tmp) != 1)
	EH(-1, "Error reading Particle creation domain card.");
      if(!strncmp(s_tmp, "BRICK", 5))
	{
	  Particle_Creation_Domain = BRICK;
	  if(fscanf(ifp, "%lf %lf %lf %lf %lf %lf\n", &Particle_Creation_Domain_Reals[0],
		     &Particle_Creation_Domain_Reals[1], &Particle_Creation_Domain_Reals[2],
		     &Particle_Creation_Domain_Reals[3], &Particle_Creation_Domain_Reals[4],
		     &Particle_Creation_Domain_Reals[5]) != 6)
	    EH(-1, "Error reading min/max values on Particle creation domain card.");
	  printf("Using BRICK creation domain with x in [%g,%g], y in [%g,%g], z in [%g,%g]\n",
		 Particle_Creation_Domain_Reals[0], Particle_Creation_Domain_Reals[1],
		 Particle_Creation_Domain_Reals[2], Particle_Creation_Domain_Reals[3],
		 Particle_Creation_Domain_Reals[4], Particle_Creation_Domain_Reals[5]);
	}
      else if(!strncmp(s_tmp, "ACIS", 4))
	{
	  EH(-1, "CGM not supported, ACIS");
	}
      else
	{
	  sprintf(err_msg, "Error reading Particle creation domain card, unknown domain type: %s.", s_tmp);
	  EH(-1, err_msg);
	}
    }
  else
    printf("Using unrestricted Particle_Creation_Domain\n");

  /* Set optional move domain. */
  if(look_for_optional(ifp, "Particle move domain", input, '=') == 1)
    {
      if(fscanf(ifp, "%s", s_tmp) != 1)
	EH(-1, "Error reading Particle move domain card.");
      if(!strncmp(s_tmp, "BRICK", 5))
	{
	  Particle_Move_Domain = BRICK;
	  if(fscanf(ifp, "%lf %lf %lf %lf %lf %lf\n", &Particle_Move_Domain_Reals[0],
		    &Particle_Move_Domain_Reals[1], &Particle_Move_Domain_Reals[2],
		    &Particle_Move_Domain_Reals[3], &Particle_Move_Domain_Reals[4],
		    &Particle_Move_Domain_Reals[5]) != 6)
	    EH(-1, "Error reading min/max values on Particle move domain card.");
	  printf("Using BRICK move domain with x in [%g,%g], y in [%g,%g], z in [%g,%g]\n",
		 Particle_Move_Domain_Reals[0], Particle_Move_Domain_Reals[1],
		 Particle_Move_Domain_Reals[2], Particle_Move_Domain_Reals[3],
		 Particle_Move_Domain_Reals[4], Particle_Move_Domain_Reals[5]);
	}
      else if(!strncmp(s_tmp, "ACIS", 4))
	{
	  EH(-1, "Need the CGM library to use ACIS for Particle creation domain card.");
	}
      else
	{
	  sprintf(err_msg, "Error reading Particle move domain card, unknown domain type: %s.", s_tmp);
	  EH(-1, err_msg);
	}
    }
  else
    printf("Using unrestricted Particle_Move_Domain\n");

  /* This is used for restarts, too, and ignores output file type.  If
   * we're a steady-state Goma calculation, then this applies to the
   * particle timesteps taken afterwards.  If this is a transient Goma
   * calculation, then this is a multiple of Goma steps.  In
   * particular, if particles are output on a time strided basis, that
   * will be ignored here. */
  if(look_for_optional(ifp, "Full output stride", input, '=') == 1)
    {
      char file_name_temp[MAX_PARTICLE_FILENAME_LENGTH];
      if(fscanf(ifp, "%d", &Particle_Full_Output_Stride) != 1)
	EH(-1, "Problem reading Full output stride card.");
      if(!fgets(file_name_temp, MAX_PARTICLE_FILENAME_LENGTH, ifp))
	EH(-1, "Problem reading Full output stride card.");
      strip(file_name_temp);
      strncpy(Particle_Full_Output_Filename, file_name_temp, MAX_PARTICLE_FILENAME_LENGTH);
      printf("Setting full output every %d steps to file %s\n", Particle_Full_Output_Stride, Particle_Full_Output_Filename);
    }
  else
    {
      Particle_Full_Output_Stride = 0;
      sprintf(Particle_Full_Output_Filename, "<not active>");
    }

  /* General description for number of particles to track, and how
   * many of them.  Can specify multiple selections, and the particles
   * will be separate samples.  Subject to total number of particles,
   * of course... */
  look_for(ifp, "Number of sample types", input, '=');
  if(fscanf(ifp, "%d", &Particle_Number_Sample_Types) != 1)
    EH(-1, "Problem reading Number of sample types card.");
  printf("Setting Particle_Number_Sample_Types = %d\n", Particle_Number_Sample_Types);

  if(Particle_Number_Sample_Types)
    {
      Particle_Number_Samples_Existing = (int *)array_alloc(1, Particle_Number_Sample_Types, sizeof(int));
      Particle_Number_Samples = (int *)array_alloc(1, Particle_Number_Sample_Types, sizeof(int));
      Particle_Number_Output_Variables = (int *)array_alloc(1, Particle_Number_Sample_Types, sizeof(int));
      Particle_Output_Variables = (particle_variable_s **)
	array_alloc(1, Particle_Number_Sample_Types, sizeof(particle_variable_s *));
      Particle_Filename_Template = (particle_filename_s *)array_alloc(1, Particle_Number_Sample_Types, sizeof(particle_filename_s));
    }
  else
    {
      Particle_Number_Samples_Existing = NULL;
      Particle_Number_Samples = NULL;
      Particle_Number_Output_Variables = NULL;
      Particle_Output_Variables = NULL;
      Particle_Filename_Template = NULL;
    }

  for(i = 0; i < Particle_Number_Sample_Types; i++)
    {
      look_for(ifp, "Sample", input, '=');
      if(fscanf(ifp, "%d", &Particle_Number_Samples[i]) != 1)
	EH(-1, "Error reading number of particle samples.");
      if(Particle_Number_Samples[i] > 0)
	printf("Sample %d contains %d particles", i, Particle_Number_Samples[i]);
      else
	EH(-1, "Number of particle samples must be > 0.");
      
      if(!fgets(s_tmp, SLEN-1, ifp))
	EH(-1, "Error reading sample variables and filename.");
      strncpy(s_tmp_save, s_tmp, SLEN);
      Particle_Number_Output_Variables[i] = 0;

      s_ptr1 = strtok(s_tmp, " \t\n");
      while((s_ptr1 = strtok(NULL, " \t\n")))
	Particle_Number_Output_Variables[i]++;

      s_ptr1 = strtok(s_tmp_save, " \t\n");
      if(Particle_Number_Output_Variables[i] > 0)
	{
	  printf(" tracking variable(s)");
	  Particle_Output_Variables[i] = (particle_variable_s *)calloc(Particle_Number_Output_Variables[i], sizeof(particle_variable_s));
	  /*
	    Particle_Output_Variables[i] = (char **)array_alloc(1, Particle_Number_Output_Variables[i], sizeof(char *));
	  */
	  for(j = 0; j < Particle_Number_Output_Variables[i]; j++)
	    {
	      if(strlen(s_ptr1) + 1 > MAX_PARTICLE_OUTPUT_VARIABLE_LENGTH)
		EH(-1, "Increase MAX_PARTICLE_OUTPUT_VARIABLE_LENGTH");
	      strncpy(Particle_Output_Variables[i][j], s_ptr1, strlen(s_ptr1) + 1);
	      printf(" %s", Particle_Output_Variables[i][j]);
	      s_ptr1 = strtok(NULL, " \t\n");
	    }
	}
      
      if(strlen(s_ptr1) + 1 > MAX_PARTICLE_FILENAME_LENGTH)
	EH(-1, "Increase MAX_PARTICLE_FILENAME_LENGTH");
      strncpy(Particle_Filename_Template[i], s_ptr1, strlen(s_ptr1) + 1);
      Particle_Filename_Template[i][strlen(s_ptr1)] = 0;
      printf(" to file %s.\n", Particle_Filename_Template[i]);
    }

  iread = look_for_optional(ifp, "START OF PBC", input, '=');
  if(iread == 1)
    {
      Particle_Number_PBCs = count_list(ifp, "PBC", input, '=', "END OF PBC");
      printf("Found %d PBC's\n", Particle_Number_PBCs);
      PBCs = (PBC_t *)calloc(Particle_Number_PBCs, sizeof(PBC_t));
      for(i = 0; i < Particle_Number_PBCs; i++)
	{
	  PBC = &PBCs[i];
	  look_for(ifp, "PBC", input, '=');
	  if(fscanf(ifp, "%80s", input) != 1)
	    EH(-1, "Error reading PBC.");
	  stringup(input);

	  /* I know it is stupid to do this for an unnecssary token,
	   * but it makes the input look better... */
	  if(fscanf(ifp, "%s", s_tmp) != 1)
	    EH(-1, "Missing SS token on PBC card.");
	  if(strncmp(s_tmp, "SS", 2))
	    EH(-1, "Missing SS token on PBC card.");

	  if(fscanf(ifp, "%d", &(PBC->SS_id)) != 1)
	    EH(-1, "Error reading SS_id on PBC card.");

	  if(!strncmp(input, "OUTFLOW", 7))
	    {
	      PBC->type = PBC_OUTFLOW;
	      puts("Found an OUTFLOW PBC.");
	    }
	  else if(!strncmp(input, "SOURCE", 6))
	    {
	      PBC->type = PBC_SOURCE;
	      if(fscanf(ifp, "%lf", &(PBC->real_data[0])) != 1)
		EH(-1, "Error reading SS specification and float on PBC = SOURCE card.");
	      printf("Found a SOURCE PBC with source = %g.\n",
		     PBC->real_data[0]);
	    }
	  else if(!strncmp(input, "TARGET", 6))
	    {
	      PBC->type = PBC_TARGET;
	      if(fscanf(ifp, "%s", s_tmp) != 1)
		EH(-1, "Missing filename on PBC TARGET card.");
	      if(strlen(s_tmp) + 1 > MAX_PBC_STRING_DATA_LENGTH)
		EH(-1, "Increase MAX_PBC_STRING_DATA_LENGTH");
	      strncpy(PBC->string_data, s_tmp, strlen(s_tmp) + 1);
	      printf("Found a TARGET PBC with filename = '%s'.\n",
		     PBC->string_data);
	    }
	  else if(!strncmp(input, "FREESTREAM_SOURCE", 17))
	    {
	      PBC->type = PBC_FREESTREAM_SOURCE;
	      if(fscanf(ifp, "%lf", &(PBC->real_data[0])) != 1)
		EH(-1, "Error reading SS specification and float on PBC = FREESTREAM_SOURCE card.");
	      printf("Found a FREESTREAM_SOURCE PBC with source = %g.\n",
		     PBC->real_data[0]);
	    }
	  else if(!strncmp(input, "IMPERMEABLE", 11))
	    {
	      PBC->type = PBC_IMPERMEABLE;
	      if(fscanf(ifp, "%lf", &(PBC->real_data[0])) != 1)
		EH(-1, "Error reading distance factor on PBC = IMPERMEABLE card.");
	      if(!fgets(s_tmp, SLEN-1, ifp))
		EH(-1, "Error reading geometry entity name on PBC = IMPERMEABLE card.");
	      strip(s_tmp);
	      if(s_tmp[strlen(s_tmp)-1] == '\n')
		s_tmp[strlen(s_tmp)-1] = 0;
	      if(strlen(s_tmp) + 1 > MAX_PBC_STRING_DATA_LENGTH)
		EH(-1, "Increase MAX_PBC_STRING_DATA_LENGTH");
	      strncpy(PBC->string_data, s_tmp, strlen(s_tmp) + 1);
	      printf("Found an IMPERMEABLE PBC with distance factor = %g to entity '%s'.\n",
		     PBC->real_data[0], PBC->string_data);
	    }
	  else
	    EH(-1, "Error reading PBC type.");
	}
    }
  else
    {
      Particle_Number_PBCs = 0;
      PBCs = NULL;
    }
}
Пример #7
0
// Perform a DNS query and parse the results.  Follows CNAME records.
void SipSrvLookup::res_query_and_parse(const char* in_name,
                                       int type,
                                       res_response* in_response,
                                       const char*& out_name,
                                       res_response*& out_response
   )
{
   OsSysLog::add(FAC_SIP, PRI_DEBUG,
                 "SipSrvLookup::res_query_and_parse in_name = '%s', "
                 "type = %d (%s)",
                 in_name,type,
                 type == T_CNAME ? "CNAME" :
                 type == T_SRV ? "SRV" :
                 type == T_A ? "A" :
                 type == T_NAPTR ? "NAPTR" :
                 "unknown");

   // The number of CNAMEs we have followed.
   int cname_count = 0;
   // The response currently being examined.
   res_response* response = in_response;
   // The name currently being examined.
   const char* name = in_name;
   // TRUE if 'response' was a lookup for 'name' and 'type'.
   UtlBoolean response_for_this_name = FALSE;
   // Buffer into which to read DNS replies.
   char answer[DNS_RESPONSE_SIZE];
   union u_rdata* p;

   // Loop until we find a reason to exit.  Each turn around the loop does
   // another DNS lookup.
   while (1)
   {
      // While response != NULL and there is a CNAME record for name
      // in response.
      while (response != NULL &&
             (p = look_for(response, name, T_CNAME)) != NULL)
      {
         cname_count++;
         if (cname_count > SipSrvLookup::getOption(SipSrvLookup::OptionCodeCNAMELimit))
         {
            break;
         }
         // If necessary, free the current 'name'.
         if (name != in_name)
         {
            free((void*) name);
         }
         // Copy the canonical name from the CNAME record into 'name', so
         // we can still use it after freeing 'response'.
         name = strdup(p->string);
         // Remember that we are now looking for a name that was not the one
         // that we searched for to produce this response.  Hence, if we don't
         // find any RRs for it, that is not authoritative and we have to do
         // another DNS query.
         response_for_this_name = FALSE;
         // Go back and check whether the result name of the CNAME is listed
         // in this response.
      }
      // This response does not contain a CNAME for 'name'.  So it is either
      // a final response that gives us the RRs we are looking for, or
      // we need to do a lookup on 'name'.

      // Check whether the response was for this name, or contains records
      // of the type we are looking for.  If either, then any records we
      // are looking for are in this response, so we can return.
      if (response_for_this_name ||
          (response != NULL && look_for(response, name, type) != NULL))
      {
         break;
      }

      // We must do another lookup.
      // Start by freeing 'response' if we need to.
      if (response != in_response)
      {
         res_free(response);
      }
      response = NULL;
      // Now, 'response' will be from a query for 'name'.
      response_for_this_name = TRUE;
      // Debugging print.
      if (SipSrvLookup::getOption(SipSrvLookup::OptionCodePrintAnswers))
      {
         printf("res_nquery(\"%s\", class = %d, type = %d)\n",
                name, C_IN, type);
      }

      // Initialize the res state struct and set the timeout to
      // 3 secs and retries to 2
      struct __res_state res;
      res_ninit(&res);
      res.retrans = mTimeout;
      res.retry = mRetries;

      if (!mNameserverIP.isNull())
      {
          res.nscount = 1;
          inet_aton(mNameserverIP.data(), &res.nsaddr_list[0].sin_addr);

          if (mNameserverPort > 1)
          {
             res.nsaddr_list[0].sin_port = htons(mNameserverPort);
          }
      }

      // Use res_nquery, not res_search or res_query, so defaulting rules are not
      // applied to the domain, and so that the query is thread-safe.
      int r = res_nquery(&res, name, C_IN, type,
                         (unsigned char*) answer, sizeof (answer));
      // Done with res state struct, so cleanup.
      // Must close once and only once per res_ninit, after res_nquery.
      res_nclose(&res);

      if (r == -1)
      {
         // res_query failed, return.
         OsSysLog::add(FAC_SIP, PRI_WARNING,
                       "DNS query for name '%s', "
                       "type = %d (%s): returned error",
                       name, type,
                       type == T_CNAME ? "CNAME" :
                       type == T_SRV ? "SRV" :
                       type == T_A ? "A" :
                       type == T_NAPTR ? "NAPTR" :
                       "unknown");
         break;
      }

      response = res_parse((char*) &answer);
      if (response == NULL)
      {
         // res_parse failed, return.
         OsSysLog::add(FAC_SIP, PRI_WARNING,
                       "DNS query for name '%s', "
                       "type = %d (%s): response could not be parsed",
                       name, type,
                       type == T_CNAME ? "CNAME" :
                       type == T_SRV ? "SRV" :
                       type == T_A ? "A" :
                       type == T_NAPTR ? "NAPTR" :
                       "unknown");
         break;
      }
      // If requested for testing purposes, sort the query and print it.
      // Sort first, so we see how sorting came out.
      if (SipSrvLookup::getOption(SipSrvLookup::OptionCodeSortAnswers))
      {
         sort_answers(response);
      }
      if (SipSrvLookup::getOption(SipSrvLookup::OptionCodePrintAnswers))
      {
         res_print(response);
      }
      // Now that we have a fresh DNS query to analyze, go back and check it
      // for a CNAME for 'name' and then for records of the requested type.
   }

   // Final processing:  Copy the working name and response to the output
   // variables.
   out_name = name;
   out_response = response;
   OsSysLog::add(FAC_SIP, PRI_DEBUG,
                 "SipSrvLookup::res_query_and_parse out_name = '%s', out_response = %p",
                 out_name, out_response);

}
Пример #8
0
static void slice_predicate(parser_context *context)
{
    enter_state(context, ST_SLICE_PREDICATE);

    int_fast32_t from = INT_FAST32_MIN;
    int_fast32_t to = INT_FAST32_MAX;
    int_fast32_t extent = 1;
    predicate *pred = add_predicate(context, SLICE);

    if(!look_for(context, ":"))
    {
        parser_trace("slice: uh oh! no ':' found, aborting...");
        context->result.code = ERR_UNSUPPORTED_PRED_TYPE;
        return;
    }

    skip_ws(context);
    if(isdigit(get_char(context)) || '-' == get_char(context) || '+' == get_char(context))
    {
        parser_trace("slice: parsing from value...");
        from = signed_integer(context);
        if(JSONPATH_SUCCESS != context->result.code)
        {
            parser_trace("slice: uh oh! couldn't parse from value, aborting...");
            return;
        }
        parser_trace("slice: found from value: %d", to);
        pred->slice.specified |= SLICE_FROM;
    }
    else
    {
        parser_trace("slice: no from value specified");
    }
    skip_ws(context);
    if(':' != get_char(context))
    {
        parser_trace("slice: uh oh! missing ':' between from and to, aborting...");
        unexpected_value(context, ':');
        return;
    }
    consume_char(context);
    skip_ws(context);
    if(isdigit(get_char(context)) || '-' == get_char(context) || '+' == get_char(context))
    {
        parser_trace("slice: parsing to value...");
        to = signed_integer(context);
        if(JSONPATH_SUCCESS != context->result.code)
        {
            parser_trace("slice: uh oh! couldn't parse to value, aborting...");
            return;
        }
        parser_trace("slice: found to value: %d", to);
        pred->slice.specified |= SLICE_TO;
    }
    else
    {
        parser_trace("slice: no to value specified");
    }
    skip_ws(context);
    if(':' == get_char(context))
    {
        consume_char(context);
        skip_ws(context);
        if(isdigit(get_char(context)) || '-' == get_char(context) || '+' == get_char(context))
        {
            parser_trace("slice: parsing step value...");
            extent = signed_integer(context);
            if(JSONPATH_SUCCESS != context->result.code)
            {
                parser_trace("slice: uh oh! couldn't parse step value, aborting...");
                return;
            }
            if(0 == extent)
            {
                parser_trace("slice: uh oh! couldn't parse step value, aborting...");
                context->result.code = ERR_STEP_CANNOT_BE_ZERO;
                return;
            }
            parser_trace("slice: found step value: %d", extent);
            pred->slice.specified |= SLICE_STEP;
        }
        else
        {
            parser_trace("slice: no step value specified");
        }

    }

    context->result.code = JSONPATH_SUCCESS;
    pred->slice.from = from;
    pred->slice.to = to;
    pred->slice.step = extent;
}
void main(){

FILE *infile;
SYMTAB_ENTRY **symtab=create_symbol_table_array(100);
int eof;
TOKEN *token,t;
NODE *node;
COND *cond;
COND **cond_array=create_cond_array();


                int g2_001_LHS_A;
                int g3_001_KEYWORDS_A;
                int g4_001_RHS_A;
                int g5_001_GROUP_SUBTREE_A;
      /**************************************************************************/
      /**************************************************************************/
      /******************* DRIVING PROCEDURE    B:\CONDSBLD ********************/
      /**************************************************************************/
       PROCEDURE_DIVISION:
      /**/
      /** take the output from the condition*/
      /** tokeniser, it consists of an iteration*/
      /** of condition number, left hand side,*/
      /** a relational operator ie NOT >, or >*/
      /** then the right hand side*/
      /**/
       C1_001_CONDS_BUILD:
           goto C1_002_CONDS_START;
       C1_002_CONDS_START_EX:
           goto C1_003_CONDS_BODY;
       C1_003_CONDS_BODY_EX:
           goto C1_009_CONDS_END;
       C1_009_CONDS_END_EX:
           goto veryend;
      /**/
       C1_002_CONDS_START:
  /*001*/      infile=open_input("b:cndout.dat");
  /*007*/      load_symtab(symtab,"b:symtable.out");
           cross_reference(symtab,100);
  /*005*/      token=&t;
  /*006*/      eof=get_token(infile,token);
           goto C1_002_CONDS_START_EX;
      /**/
       C1_003_CONDS_BODY:
       C1_004_COND_EX:
           if(!(
  /*C01*/         (eof==1)
))
                   goto C1_004_COND;
           goto C1_003_CONDS_BODY_EX;
      /**/
       C1_004_COND:
           goto C1_005_COND_NUM;
       C1_005_COND_NUM_EX:
           goto C1_006_LHS;
       C1_006_LHS_EX:
           goto C1_007_KEYWORDS;
       C1_007_KEYWORDS_EX:
           goto C1_008_RHS;
       C1_008_RHS_EX:
           goto C1_004_COND_EX;
      /**/
       C1_005_COND_NUM:
  /*010*/      cond=create_cond();
  /*011*/      cond_array[token->value.keyword_number]=cond;
  /*006*/      eof=get_token(infile,token);
           goto C1_005_COND_NUM_EX;
      /**/
       C1_006_LHS:
                g2_001_LHS_A=0;
           goto C2_001_LHS;
       C2_001_EXIT01:
           goto C1_006_LHS_EX;
      /**/
       C1_007_KEYWORDS:
                g3_001_KEYWORDS_A=0;
           goto C3_001_KEYWORDS;
       C3_001_EXIT01:
           goto C1_007_KEYWORDS_EX;
      /**/
       C1_008_RHS:
                g4_001_RHS_A=0;
           goto C4_001_RHS;
       C4_001_EXIT01:
           goto C1_008_RHS_EX;
      /**/
       C1_009_CONDS_END:
  /*002*/      close_file(infile);
  /*004*/      save_cond_array("b:cndout2.dat",cond_array);
           goto C1_009_CONDS_END_EX;
      /**/
       C5_001_GROUP_SUBTREE:
           if((
  /*C08*/         (token->token_type==RELATIONAL_OP)
))
                   goto C5_002_RELATIONAL;
           if((
  /*C09*/         (token->token_type==KEYWORD)
))
                   goto C5_008_VERB;
       C5_002_RELATIONAL_EX:
       C5_008_VERB_EX:
       C5_001_GROUP_SUBTREE_A:
                switch(g5_001_GROUP_SUBTREE_A){
                case 0 : goto C5_001_EXIT02;break;
                case 1 : goto C5_001_EXIT03;break;
                }
      /**/
       C5_002_RELATIONAL:
           goto C5_003_RELATIONAL_BODY;
       C5_003_RELATIONAL_BODY_EX:
           goto C5_007_RELATIONAL_END;
       C5_007_RELATIONAL_END_EX:
           goto C5_002_RELATIONAL_EX;
      /**/
       C5_003_RELATIONAL_BODY:
           if((
  /*C10*/         (token->value.keyword_number==GREATER_THAN)
))
                   goto C5_004_GREATER_SYMBOL;
           if((
  /*C11*/         (token->value.keyword_number==LESS_THAN)
))
                   goto C5_005_LESS_SYMBOL;
           if((
  /*C12*/         (token->value.keyword_number==EQUAL_TO)
))
                   goto C5_006_EQUAL_SYMBOL;
       C5_004_GREATER_SYMBOL_EX:
       C5_005_LESS_SYMBOL_EX:
       C5_006_EQUAL_SYMBOL_EX:
           goto C5_003_RELATIONAL_BODY_EX;
      /**/
       C5_004_GREATER_SYMBOL:
  /*014*/      cond->relation.relation=GREATER_THAN;
           goto C5_004_GREATER_SYMBOL_EX;
      /**/
       C5_005_LESS_SYMBOL:
  /*015*/      cond->relation.relation=LESS_THAN;
           goto C5_005_LESS_SYMBOL_EX;
      /**/
       C5_006_EQUAL_SYMBOL:
  /*016*/      cond->relation.relation=EQUAL_TO;
           goto C5_006_EQUAL_SYMBOL_EX;
      /**/
       C5_007_RELATIONAL_END:
  /*006*/      eof=get_token(infile,token);
           goto C5_007_RELATIONAL_END_EX;
      /**/
       C5_008_VERB:
           goto C5_009_VERB_BODY;
       C5_009_VERB_BODY_EX:
           goto C5_019_VERB_END;
       C5_019_VERB_END_EX:
           goto C5_008_VERB_EX;
      /**/
       C5_009_VERB_BODY:
           if((
  /*C13*/         (token->value.keyword_number==GREATER)
))
                   goto C5_010_GREATER;
           if((
  /*C14*/         (token->value.keyword_number==LESS)
))
                   goto C5_013_LESS;
           if((
  /*C15*/         (token->value.keyword_number==EQUAL)
))
                   goto C5_016_EQUAL;
       C5_010_GREATER_EX:
       C5_013_LESS_EX:
       C5_016_EQUAL_EX:
           goto C5_009_VERB_BODY_EX;
      /**/
       C5_010_GREATER:
           goto C5_011_GREATER;
       C5_011_GREATER_EX:
           goto C5_012_THAN;
       C5_012_THAN_EX:
           goto C5_010_GREATER_EX;
      /**/
       C5_011_GREATER:
  /*006*/      eof=get_token(infile,token);
           goto C5_011_GREATER_EX;
      /**/
       C5_012_THAN:
  /*014*/      cond->relation.relation=GREATER_THAN;
           goto C5_012_THAN_EX;
      /**/
       C5_013_LESS:
           goto C5_014_LESS;
       C5_014_LESS_EX:
           goto C5_015_THAN;
       C5_015_THAN_EX:
           goto C5_013_LESS_EX;
      /**/
       C5_014_LESS:
  /*006*/      eof=get_token(infile,token);
           goto C5_014_LESS_EX;
      /**/
       C5_015_THAN:
  /*015*/      cond->relation.relation=LESS_THAN;
           goto C5_015_THAN_EX;
      /**/
       C5_016_EQUAL:
           goto C5_017_EQUAL;
       C5_017_EQUAL_EX:
           goto C5_018_TO;
       C5_018_TO_EX:
           goto C5_016_EQUAL_EX;
      /**/
       C5_017_EQUAL:
  /*006*/      eof=get_token(infile,token);
           goto C5_017_EQUAL_EX;
      /**/
       C5_018_TO:
  /*016*/      cond->relation.relation=EQUAL_TO;
           goto C5_018_TO_EX;
      /**/
       C5_019_VERB_END:
  /*006*/      eof=get_token(infile,token);
           goto C5_019_VERB_END_EX;
      /**/
      /** skip the IS, take the NOT and the*/
      /** relational and build a relational part o*/
      /** f the condition*/
      /**/
       C3_001_KEYWORDS:
           goto C3_002_KSTART;
       C3_002_KSTART_EX:
           goto C3_003_POSS_IS;
       C3_003_POSS_IS_EX:
           goto C3_005_KEYWORD_GROUP;
       C3_005_KEYWORD_GROUP_EX:
       C3_001_KEYWORDS_A:
                switch(g3_001_KEYWORDS_A){
                case 0 : goto C3_001_EXIT01;break;
                }
      /**/
       C3_002_KSTART:
  /*023*/      printf("relation bit\n");
           goto C3_002_KSTART_EX;
      /**/
       C3_003_POSS_IS:
           if((
  /*C05*/         (token->token_type==KEYWORD &&
               token->value.keyword_number==IS)
))
                   goto C3_004_IS;
       C3_004_IS_EX:
           goto C3_003_POSS_IS_EX;
      /**/
       C3_004_IS:
  /*006*/      eof=get_token(infile,token);
           goto C3_004_IS_EX;
      /**/
       C3_005_KEYWORD_GROUP:
           if((
  /*C06*/         (token->token_type==KEYWORD &&
               token->value.keyword_number==NOT)
))
                   goto C3_006_NOT_GROUP;
           if((
  /*C07*/         (token->token_type==KEYWORD ||
               token->token_type==RELATIONAL_OP)
))
                   goto C3_010_NOT_NOT_GROUP;
       C3_006_NOT_GROUP_EX:
       C3_010_NOT_NOT_GROUP_EX:
           goto C3_005_KEYWORD_GROUP_EX;
      /**/
       C3_006_NOT_GROUP:
           goto C3_007_NOT;
       C3_007_NOT_EX:
           goto C3_008_GROUP;
       C3_008_GROUP_EX:
           goto C3_006_NOT_GROUP_EX;
      /**/
       C3_007_NOT:
  /*006*/      eof=get_token(infile,token);
  /*017*/      cond->relation.not=YES_STATUS;
           goto C3_007_NOT_EX;
      /**/
       C3_008_GROUP:
           goto C3_009_GROUP_SUBTREE;
       C3_009_GROUP_SUBTREE_EX:
           goto C3_008_GROUP_EX;
      /**/
       C3_009_GROUP_SUBTREE:
                g5_001_GROUP_SUBTREE_A=0;
           goto C5_001_GROUP_SUBTREE;
       C5_001_EXIT02:
           goto C3_009_GROUP_SUBTREE_EX;
      /**/
       C3_010_NOT_NOT_GROUP:
           goto C3_011_GROUP;
       C3_011_GROUP_EX:
           goto C3_010_NOT_NOT_GROUP_EX;
      /**/
       C3_011_GROUP:
           goto C3_012_GROUP_SUBTREE;
       C3_012_GROUP_SUBTREE_EX:
           goto C3_011_GROUP_EX;
      /**/
       C3_012_GROUP_SUBTREE:
                g5_001_GROUP_SUBTREE_A=1;
           goto C5_001_GROUP_SUBTREE;
       C5_001_EXIT03:
           goto C3_012_GROUP_SUBTREE_EX;
      /**/
       C4_001_RHS:
           goto C4_002_RHS_START;
       C4_002_RHS_START_EX:
           goto C4_003_RHS_BODY;
       C4_003_RHS_BODY_EX:
           goto C4_007_RHS_END;
       C4_007_RHS_END_EX:
       C4_001_RHS_A:
                switch(g4_001_RHS_A){
                case 0 : goto C4_001_EXIT01;break;
                }
      /**/
       C4_002_RHS_START:
  /*022*/      printf("right hand side\n");getchar();
  /*021*/      cond->relation.not=NO_STATUS;
           goto C4_002_RHS_START_EX;
      /**/
       C4_003_RHS_BODY:
           if((
  /*C02*/         (token->token_type==NUMERIC)
))
                   goto C4_004_INTEGER;
           if((
  /*C03*/         (token->token_type==VARIABLE_NAME)
))
                   goto C4_005_VARIABLE;
           if((
  /*C04*/         (token->token_type==NON_NUMERIC_LITERAL)
))
                   goto C4_006_STRING;
       C4_004_INTEGER_EX:
       C4_005_VARIABLE_EX:
       C4_006_STRING_EX:
           goto C4_003_RHS_BODY_EX;
      /**/
       C4_004_INTEGER:
  /*018*/      cond->rhs.type=SIDE_LITERAL;
           cond->rhs.contents.numeric_literal=token->value.keyword_number;
  /*025*/      printf("numeric value \n");
           goto C4_004_INTEGER_EX;
      /**/
       C4_005_VARIABLE:
  /*009*/      node=look_for(token->value.var_values.unique,
                         token->value.var_values.hash,
                         symtab);
  /*020*/      cond->rhs.type=SIDE_VAR;
           cond->rhs.contents.variable=node;
  /*026*/      printf("variable\n");
           goto C4_005_VARIABLE_EX;
      /**/
       C4_006_STRING:
  /*019*/      cond->rhs.type=SIDE_NON_LITERAL;
           cond->rhs.contents.non_numeric_literal=token->value.string;
  /*028*/      printf("string2\n");
           goto C4_006_STRING_EX;
      /**/
       C4_007_RHS_END:
  /*006*/      eof=get_token(infile,token);
           goto C4_007_RHS_END_EX;
      /**/
       C2_001_LHS:
           goto C2_002_LHS_START;
       C2_002_LHS_START_EX:
           goto C2_003_LHS_BODY;
       C2_003_LHS_BODY_EX:
           goto C2_007_LHS_END;
       C2_007_LHS_END_EX:
       C2_001_LHS_A:
                switch(g2_001_LHS_A){
                case 0 : goto C2_001_EXIT01;break;
                }
      /**/
       C2_002_LHS_START:
  /*024*/      printf("lefthand side\n");
           goto C2_002_LHS_START_EX;
      /**/
       C2_003_LHS_BODY:
           if((
  /*C02*/         (token->token_type==NUMERIC)
))
                   goto C2_004_INTEGER;
           if((
  /*C03*/         (token->token_type==VARIABLE_NAME)
))
                   goto C2_005_VARIABLE;
           if((
  /*C04*/         (token->token_type==NON_NUMERIC_LITERAL)
))
                   goto C2_006_STRING;
       C2_004_INTEGER_EX:
       C2_005_VARIABLE_EX:
       C2_006_STRING_EX:
           goto C2_003_LHS_BODY_EX;
      /**/
       C2_004_INTEGER:
  /*003*/      cond->lhs.type=SIDE_LITERAL;
  /*008*/      cond->lhs.contents.numeric_literal=token->value.keyword_number;
  /*025*/      printf("numeric value \n");
           goto C2_004_INTEGER_EX;
      /**/
       C2_005_VARIABLE:
  /*009*/      node=look_for(token->value.var_values.unique,
                         token->value.var_values.hash,
                         symtab);
  /*013*/      cond->lhs.contents.variable=node;
           cond->lhs.type=SIDE_VAR;  
  /*026*/      printf("variable\n");
           goto C2_005_VARIABLE_EX;
      /**/
       C2_006_STRING:
  /*012*/      cond->lhs.type=SIDE_NON_LITERAL;
           cond->lhs.contents.non_numeric_literal=token->value.string;
  /*027*/      printf("string\n");
           goto C2_006_STRING_EX;
      /**/
       C2_007_LHS_END:
  /*006*/      eof=get_token(infile,token);
           goto C2_007_LHS_END_EX;
      /**/
      /*   Data Analysis Map*/
      /**/
      /*                         ------------- Data Analysis By -------------*/
      /**/
      /*                         BOX TYPE               OPERATION  ALLOCATION*/
      /*  Tree name: CONDS-BUILD*/
      /**/
      /*                         Leaf      :   3          Operations:   9*/
      /*                                                  Quits     :   0*/
      /*                         Selections:   0*/
      /*                         Sequences :   2*/
      /*                         Iterations:   1*/
      /*                         Backtracks:   0*/
      /*                         Subtrees  :   3   -->    LHS*/
      /*                                                  KEYWORDS*/
      /*                                                  RHS*/
      /**/
      /*  Tree name: GROUP-SUBTREE*/
      /**/
      /*                         Leaf      :  11          Operations:  11*/
      /*                                                  Quits     :   0*/
      /*                         Selections:   3*/
      /*                         Sequences :   5*/
      /*                         Iterations:   0*/
      /*                         Backtracks:   0*/
      /*                         Subtrees  :   0*/
      /**/
      /*  Tree name: KEYWORDS*/
      /**/
      /*                         Leaf      :   3          Operations:   4*/
      /*                                                  Quits     :   0*/
      /*                         Selections:   2*/
      /*                         Sequences :   5*/
      /*                         Iterations:   0*/
      /*                         Backtracks:   0*/
      /*                         Subtrees  :   2   -->    GROUP-SUBTREE*/
      /*                                                  GROUP-SUBTREE*/
      /**/
      /*  Tree name: RHS*/
      /**/
      /*                         Leaf      :   5          Operations:  10*/
      /*                                                  Quits     :   0*/
      /*                         Selections:   1*/
      /*                         Sequences :   1*/
      /*                         Iterations:   0*/
      /*                         Backtracks:   0*/
      /*                         Subtrees  :   0*/
      /**/
      /*  Tree name: LHS*/
      /**/
      /*                         Leaf      :   5          Operations:  10*/
      /*                                                  Quits     :   0*/
      /*                         Selections:   1*/
      /*                         Sequences :   1*/
      /*                         Iterations:   0*/
      /*                         Backtracks:   0*/
      /*                         Subtrees  :   0*/
      /**/
      /**/
      /**/
veryend: ;
}
Пример #10
0
void do_editmode(struct block * sb) {

    if (sb->value == 'h' || sb->value == OKEY_LEFT) {  // LEFT
        inputline_pos = back_char();

    } else if (sb->value == 'l' || sb->value == OKEY_RIGHT) { // RIGHT
        inputline_pos = for_char();

    } else if (sb->value == 'x') {         // x
        del_back_char();

    } else if (sb->value == 'X') {         // X
        del_for_char();

    } else if (sb->value == ' ' && ( strlen(inputline) < (COLS - 14) ) ) {         // SPACE
        add_char(inputline, ' ', inputline_pos);

    } else if (sb->value == 'r') {         // r
        curs_set(1);
        int c = get_key();
        if (c != -1) inputline[inputline_pos] = c;
        curs_set(2);

    } else if (sb->value == 'R') {         // R
        curs_set(1);
        int c = get_key();
        while (c != OKEY_ENTER && c != -1) {
            if (isprint(c)) {
                inputline[inputline_pos] = c;
                ++inputline_pos;
                mvwprintw(input_win, 0, 1 + rescol, "%s", inputline);
                wmove(input_win, 0, inputline_pos + 1 + rescol);
                wrefresh(input_win);
            }
            c = get_key();
        }
        curs_set(2);

    } else if (sb->value == 'f') {         // f
        int c = get_key();
        if (c != -1) inputline_pos = look_for(c);

    } else if (sb->value == 'd' || sb->value == 'c') {         // d or c
        int c, d;
        if ( (c = get_key()) != -1 ) {
             switch (c) {
             case 'e':                     // de or ce
                 del_range_chars(inputline, inputline_pos, for_word(1, 0, 0));
                 break;

             case 'E':                     // dE or cE
                 del_range_chars(inputline, inputline_pos, for_word(1, 0, 1));
                 break;

             case 'w':                     // dw or cw
                 del_range_chars(inputline, inputline_pos, for_word(0, 1, 0) - 1);
                 if (inputline_pos == strlen(inputline) && inputline_pos) inputline_pos--;
                 break;

             case 'W':                     // dW or cW
                 del_range_chars(inputline, inputline_pos, for_word(0, 1, 1) - 1);
                 if (inputline_pos == strlen(inputline) && inputline_pos) inputline_pos--;
                 break;

             case 'b':                     // db or cb
                 d = back_word(0);
                 del_range_chars(inputline, d, inputline_pos-1);
                 inputline_pos = d;
                 break;

             case 'B':                     // dB or cB
                 d = back_word(1);
                 del_range_chars(inputline, d, inputline_pos-1);
                 inputline_pos = d;
                 break;

             case 'l':                     // dl or cl
             case OKEY_RIGHT:
                 del_back_char();
                 break;

             case 'h':                     // dh or ch
             case OKEY_LEFT:
                 del_for_char();
                 break;

             case 'a':
                 if ( (d = get_key()) == 'W' ) {     // daW or caW
                     c = ( inputline_pos && inputline[inputline_pos-1] == ' ' ) ? inputline_pos : back_word(1);
                     del_range_chars(inputline, c, for_word(0, 1, 1) - 1);
                     inputline_pos = (strlen(inputline) > inputline_pos) ? c : strlen(inputline)-2;
                 } else if ( d == 'w' ) { // daw or caw
                     d = ( inputline_pos && ! istext( inputline[inputline_pos-1]) ) ? inputline_pos : back_word(0);
                     del_range_chars(inputline, d, for_word(0, 1, 0) - 1);
                     inputline_pos = (strlen(inputline) > inputline_pos) ? d : strlen(inputline)-2;
                 }
                 break;
             }
             if (sb->value == 'c') chg_mode(insert_edit_submode);
        }

    } else if (find_val(sb, OKEY_ENTER)) { // ENTER
        insert_or_edit_cell(); 
        return;

    } else if (sb->value == '$') {         // $
        inputline_pos = strlen(inputline) - 1;

    } else if (sb->value == 'w') {         // w
        inputline_pos = for_word(0, 0, 0);

    } else if (sb->value == 'W') {         // W
        inputline_pos = for_word(0, 0, 1);

    } else if (sb->value == 'e') {         // e
        inputline_pos = for_word(1, 0, 0);

    } else if (sb->value == 'E') {         // E
        inputline_pos = for_word(1, 0, 1);

    } else if (sb->value == 'b') {         // b
        inputline_pos = back_word(0);

    } else if (sb->value == 'B') {         // B
        inputline_pos = back_word(1);

    } else if (sb->value == '0') {         // 0
        inputline_pos = 0;

    } else if (sb->value == 'a') {         // a
        inputline_pos++;
        chg_mode(insert_edit_submode);

    } else if (sb->value == 'i' ||  sb->value == '=') {         // i o =
        chg_mode(insert_edit_submode);

    } else if (sb->value == 's') {         // s
        if (inputline_pos <= strlen(inputline)) del_char(inputline, inputline_pos);
        chg_mode(insert_edit_submode);

    } else if (sb->value == 'A') {         // A
        inputline_pos = strlen(inputline);
        chg_mode(insert_edit_submode);

    } else if (sb->value == 'I') {         // I
        inputline_pos = 0;
        chg_mode(insert_edit_submode);

    } else if (sb->value == 'D') {         // D
        inputline_pos = 0;
        inputline[0] = '\0';
        chg_mode(insert_edit_submode);
    }

    show_header(input_win);
    return;
}