Exemplo n.º 1
0
static void
skip_fixed_comments (void)
{
  locus start;
  int col;
  char c;

  for (;;)
    {
      start = gfc_current_locus;
      if (gfc_at_eof ())
	break;

      c = next_char ();
      if (c == '\n')
	{
	  gfc_advance_line ();
	  continue;
	}

      if (c == '!' || c == 'c' || c == 'C' || c == '*')
	{
	  skip_comment_line ();
	  continue;
	}

      col = 1;
      do
	{
	  c = next_char ();
	  col++;
	}
      while (gfc_is_whitespace (c));

      if (c == '\n')
	{
	  gfc_advance_line ();
	  continue;
	}

      if (col != 6 && c == '!')
	{
	  skip_comment_line ();
	  continue;
	}

      break;
    }

  gfc_current_locus = start;
}
Exemplo n.º 2
0
void read_base_number(std::istream& in, BigInt& m, long length, long maxBits) {
  char *buffer;
  int size, offset;
  int base;
  bool is_negate;

  int c, pos = 0;
  skip_comment_line(in);

  // read sign
  c = in.get();
  if (c == '-') {
    is_negate = true;
    c = in.get();
  } else
    is_negate = false;

  // read base and compute digits
  if (c == '0') {
    c = in.get();
    if (c == 'b') {
      base = 2;
      size = (maxBits == 0 || maxBits > length) ? length : maxBits;
      offset = length - size;
    } else if (c == 'x') {
      base = 16;
      size = (maxBits == 0) ? length : (maxBits+3) >> 2;
      size = (size > length) ? length : size;
      offset = (length - size) << 2;
    } else {
Exemplo n.º 3
0
static void
skip_free_comments (void)
{
  locus start;
  char c;

  for (;;)
    {
      start = gfc_current_locus;
      if (gfc_at_eof ())
	break;

      do
	{
	  c = next_char ();
	}
      while (gfc_is_whitespace (c));

      if (c == '\n')
	{
	  gfc_advance_line ();
	  continue;
	}

      if (c == '!')
	{
	  skip_comment_line ();
	  continue;
	}

      break;
    }

  gfc_current_locus = start;
}
Exemplo n.º 4
0
int	check_link_name(char *buffer)
{
  int	a;
  int	b;

  b = 0;
  a = skip_nodes(buffer, 0);
  while (buffer[a])
    {
      if (buffer[a - 1] == '\n')
	{
	  a = skip_comment_line(buffer, a);
	  check_link_name_suite(buffer, a, b);
	}
      if (buffer[a] == '#')
	a = skip_comment_line(buffer, a);
      a++;
    }
  return (1);
}
Exemplo n.º 5
0
void read_string(std::istream& in, char* &buffer, int sz) {
  int c, pos=0;
  skip_comment_line(in);

  while ( (c = in.get()) != EOF ) {
    if ( c == ' ' || c == '\t' || c == '\n' || c == '#')
      break;
    else
      append_char(buffer, sz, pos++, c);
  }
  append_char(buffer, sz, pos, '\0');
}
Exemplo n.º 6
0
static void skip_whitespace_and_comments(FILE *file)
{
    int c = fgetc(file);
    while(1) switch(c)
    {
        case '#':
            skip_comment_line(file);
            /* fall through */
        case ' ': case '\t': case '\r': case '\n':
            c = fgetc(file);
        break;
        default:
            ungetc(c, file);
            return;
    }
}
Exemplo n.º 7
0
int	check_link_name_suite(char *buffer, int a, int b)
{
  char	t[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-";

  while (buffer[a] != '\n')
    {
      if (buffer[a] == '\0')
	return (0);
      if (buffer[a] == t[b])
	{
	  b = 0;
	  a++;
	}
      else if (t[b] == '\0')
	put_error("Invalid link name");
      else
	{
	  a = skip_comment_line(buffer, a);
	  b++;
	}
    }
  return (1);
}
Exemplo n.º 8
0
int
gfc_next_char_literal (int in_string)
{
  locus old_loc;
  int i, c;

  continue_flag = 0;

restart:
  c = next_char ();
  if (gfc_at_end ())
    return c;

  if (gfc_current_form == FORM_FREE)
    {

      if (!in_string && c == '!')
	{
	  /* This line can't be continued */
	  do
	    {
	      c = next_char ();
	    }
	  while (c != '\n');

	  /* Avoid truncation warnings for comment ending lines.  */
	  gfc_current_locus.lb->truncated = 0;

	  goto done;
	}

      if (c != '&')
	goto done;

      /* If the next nonblank character is a ! or \n, we've got a
         continuation line.  */
      old_loc = gfc_current_locus;

      c = next_char ();
      while (gfc_is_whitespace (c))
	c = next_char ();

      /* Character constants to be continued cannot have commentary
         after the '&'.  */

      if (in_string && c != '\n')
	{
	  gfc_current_locus = old_loc;
	  c = '&';
	  goto done;
	}

      if (c != '!' && c != '\n')
	{
	  gfc_current_locus = old_loc;
	  c = '&';
	  goto done;
	}

      continue_flag = 1;
      if (c == '!')
	skip_comment_line ();
      else
	gfc_advance_line ();

      /* We've got a continuation line and need to find where it continues.
         First eat any comment lines.  */
      gfc_skip_comments ();

      /* Now that we have a non-comment line, probe ahead for the
         first non-whitespace character.  If it is another '&', then
         reading starts at the next character, otherwise we must back
         up to where the whitespace started and resume from there.  */

      old_loc = gfc_current_locus;

      c = next_char ();
      while (gfc_is_whitespace (c))
	c = next_char ();

      if (c != '&')
	gfc_current_locus = old_loc;

    }
  else
    {
      /* Fixed form continuation.  */
      if (!in_string && c == '!')
	{
	  /* Skip comment at end of line.  */
	  do
	    {
	      c = next_char ();
	    }
	  while (c != '\n');

	  /* Avoid truncation warnings for comment ending lines.  */
	  gfc_current_locus.lb->truncated = 0;
	}

      if (c != '\n')
	goto done;

      continue_flag = 1;
      old_loc = gfc_current_locus;

      gfc_advance_line ();
      gfc_skip_comments ();

      /* See if this line is a continuation line.  */
      for (i = 0; i < 5; i++)
	{
	  c = next_char ();
	  if (c != ' ')
	    goto not_continuation;
	}

      c = next_char ();
      if (c == '0' || c == ' ')
	goto not_continuation;
    }

  /* Ready to read first character of continuation line, which might
     be another continuation line!  */
  goto restart;

not_continuation:
  c = '\n';
  gfc_current_locus = old_loc;

done:
  continue_flag = 0;
  return c;
}
Exemplo n.º 9
0
/* see which wds devices we are getting beacons from.  (this routine doesn't
 * look at the ethernet connection or the wlan connection.  those devices
 * are added at startup, the latter only if we were told to do so from the
 * command line.  they don't come and go.  only the wds devices
 * come and go.)
 *
 * this routine manages the device_list array, which includes if_index,
 * file descriptor, etc. to support actual low-level communication.
 */
char check_devices(void)
{
    char result = 0;
    int retval;
    static struct ifreq get_index;
    struct sockaddr_ll bind_arg;
    char wds_devices[MAX_CLOUD][64];
    mac_address_t wds_macs[MAX_CLOUD];
    int wds_count = 0;
    int w, d;
    char buf[64];

    FILE *wds = fopen(wds_file, "r");
    if (wds == NULL) {
        ddprintf("check_devices; fopen failed:  %s\n", strerror(errno));
        ddprintf("    file:  '%s'\n", wds_file);
        goto finish;
    }

    /* read the mac addresses of the wds devices into
     * local array wds_devices
     */
    while (1) {
        if (wds_count >= MAX_CLOUD) {
            ddprintf("check_devices:  too many wds devices\n");
            break;
        }

        if (skip_comment_line(wds) != 0) {
            ddprintf("check_devices; problem reading file.\n");
            break;
        }


        #ifdef WRT54G
            retval = mac_read(wds, wds_macs[wds_count]);
        #else
            retval = fscanf(wds, "%s", wds_devices[wds_count]);
        #endif

        if (retval != 1) { break; }

        #ifdef WRT54G
            retval = fscanf(wds, "%s", wds_devices[wds_count]);
        #else
            retval = mac_read(wds, wds_macs[wds_count]);
        #endif

        if (retval != 1) {
            ddprintf("check_devices; could not read device name from wds\n");
            goto finish;
        }
        wds_count++;
    }

    top :
    /* see if every wds device in our list matches current truth */
    for (d = 0; d < device_list_count; d++) {
        int found = 0;

        if (device_list[d].device_type != device_type_wds
            && device_list[d].device_type != device_type_cloud_wds)
        { continue; }
        
        for (w = 0; w < wds_count; w++) {
            if (mac_equal(device_list[d].mac_address, wds_macs[w])) {
                found = 1;
                break;
            }
        }

        if (!found
            || strstr(device_list[d].device_name, wds_devices[w]) == NULL)
        {
            result = 1;
            delete_device(d);
            goto top;
        }

        if (!use_pipes) {
            /* check to see that the if_index is still the same.
             * (if "wds0.2" gets deleted and then re-created, it probably
             * has a different if_index.)
             */
            sprintf(get_index.ifr_name, device_list[d].device_name);
            retval = ioctl(device_list[d].fd, SIOCGIFINDEX, &get_index);
            if (retval == -1) {
                ddprintf("check_devices; could not get device index:  %s\n",
                        strerror(errno));
                goto finish;
            }
            if (device_list[d].if_index != get_index.ifr_ifindex) {
                device_list[d].if_index = get_index.ifr_ifindex;
                memset(&bind_arg, 0, sizeof(bind_arg));
                bind_arg.sll_family = AF_PACKET;
                bind_arg.sll_ifindex = get_index.ifr_ifindex;
                bind_arg.sll_protocol = htons(ETH_P_ALL);

                retval = bind(device_list[d].fd, (struct sockaddr *) &bind_arg,
                        sizeof(bind_arg));
                if (retval == -1) {
                    ddprintf("check_devices; bind failed:  %s\n",
                            strerror(errno));
                    goto finish;
                }
                result = 1;
                goto top;
            }
        }
    }

    /* see if every device out there is in our local table */
    for (w = 0; w < wds_count; w++) {
        int found = 0;

        for (d = 0; d < device_list_count; d++) {
            if (mac_equal(device_list[d].mac_address, wds_macs[w])) {
                found = 1;
                break;
            }
        }

        if (!found) {
            result = 1;
            add_device(
                    ad_hoc_mode ? "ad-hoc device" : wds_devices[w],
                    wds_macs[w],
                    ad_hoc_mode ? device_type_ad_hoc : device_type_wds);

            if (!ad_hoc_mode && db[47].d) {
                sprintf(buf, "%s:1", wds_devices[w]);
                add_device(buf, wds_macs[w], device_type_cloud_wds);
            }
        }
    }

    finish :

    if (wds != NULL) { fclose(wds); }

    return result;

} /* check_devices */