Esempio n. 1
0
linked_list* build_list_from_file(FILE* file, bool reverse) {
    linked_list* new_list = new_linked_list();
    int ch;
    bool still_reading = true;
    bool first_val_read = false;
    int number = 0;
    while (!first_val_read && still_reading && (ch = getc(file)) != EOF) {
        switch(ch) {
            case SPACE:
                break; // ignore spaces
            case RETURN:
            case NEWLINE:
                still_reading = false;
                break;
            case COMMA:
                ll_init_add(new_list, number);
                number = 0;
                first_val_read = true;
                break;

            // NUMBER ENCOUNTERED
            default: 
                number = number*10 + char_to_num(ch); 
        }
    }
    while (still_reading && (ch = getc(file)) != EOF) {
        switch(ch) {
            case SPACE:
                break; // ignore spaces
            case RETURN:
            case NEWLINE:
                still_reading = false;
                break;
            case COMMA:
                if (reverse) {
                    ll_add_to_head(new_list, number);
                }
                else {
                    ll_add_to_tail(new_list, number);
                }
                number = 0;
                break;

            // NUMBER ENCOUNTERED
            default: 
                number = number*10 + char_to_num(ch); 
        }
    }
    if (reverse) {
        ll_add_to_head(new_list, number);
    }
    else {
        ll_add_to_tail(new_list, number);
    }
    return new_list;
}
Esempio n. 2
0
/* AUTELAN-Added-End : [email protected] */
static int ath_iw_sethwaddr(struct net_device *dev, struct iw_request_info *info, void *w, char *extra)
{
    int retval;
    unsigned char addr[IEEE80211_ADDR_LEN];
    struct sockaddr sa;
    int i = 0;
    char *buf = extra;
    struct ath_softc_net80211 *scn = ath_netdev_priv(dev);
    struct ieee80211com *ic = &scn->sc_ic;

    do {
        retval = char_to_num(*buf++);
        if ( retval < 0 )
            break;

        addr[i] = retval << 4;

        retval = char_to_num(*buf++);
        if ( retval < 0 )
            break;

        addr[i++] += retval;

        if ( i < IEEE80211_ADDR_LEN && *buf++ != ':' ) {
            retval = -EINVAL;
            break;
        }
        retval = 0;
    } while ( i < IEEE80211_ADDR_LEN );

    if ( !retval ) {
        if ( !TAILQ_EMPTY(&ic->ic_vaps) ) {
            retval = -EBUSY; //We do not set the MAC address if there are VAPs present
        } else {
            IEEE80211_ADDR_COPY(&sa.sa_data, addr);
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30)
            retval = dev->netdev_ops->ndo_set_mac_address(dev, &sa);
#else
            retval = dev->set_mac_address(dev, &sa);
#endif
        }
    }

    return retval;
}
Esempio n. 3
0
int build_sequence(char *sequence, char *filename)
{
  int i, j;
  char c;
  FILE *fp;

  if( (fp = fopen(filename, "r")) == NULL)
  {
    fprintf(stderr,"Could not open input file %s\n", filename);  exit(1);
  }
  for(i=0; i<PADLENGTH; i++) sequence[i] = 99;
  i = 0;
  while( !feof(fp) && (i<MAXLENGTH) )
  { /* process one line of file */
    c = getc(fp);
    if(c == EOF) continue;
    if(c == '\n') continue;
    if(c == '>')
    {
      for(j=0; (getc(fp) != '\n') && !feof(fp); j++)
        ;
    }
    else
    {
      if(c > 64) 
      {
        sequence[i+PADLENGTH] = char_to_num(c);
        i++;
      }
      for(j=0; ((c = getc(fp)) != '\n') && !feof(fp) && (i<MAXLENGTH); j++)
      {
        if(c > 64) 
        {
          sequence[i+PADLENGTH] = char_to_num(c);
          i++;
        }
      }
    }
  }
  fclose(fp);
  return (i+PADLENGTH); /* length of genome */
}
Esempio n. 4
0
int char_to_freq(char c, unsigned int *f) {
	
	unsigned int n;
	
	if (f != NULL && char_to_num(c, &n) == 0) {
		
		unsigned int ff;
		
		if (num_to_freq(n, &ff) == 0) {
			
			*f = ff;
			return 0;
		}
	}
	
	return -1;
}
Esempio n. 5
0
U32 Get_U32(char *p_message)
{

	U32 invalid_digit = 1;
	U32 number = 0;
	char next_char = 0;
	U32 next_value;
	#define	MAX_DIGITS 3
	char Digits[MAX_DIGITS+1] = {0};
	U32	cDigits = 0;

	while(invalid_digit)
	{
		Tracef(p_message);
		invalid_digit = 0;
		while (invalid_digit == 0)
		{
			next_char = getchar();
			switch (next_char)
			{
			case '\n':
			case '\r':
				return char_to_num( Digits );
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				if (cDigits < MAX_DIGITS)
				{
					Digits[cDigits] = next_char;
					Digits[++cDigits] = '\0';
				}
				else
					putchar(7);		// BEEP!
				
				break;
    		case 0x08:	 /* BACKSPACE */
    			if (cDigits)
				{
					printf(" \b");	// BACKSPACE
					Digits[--cDigits] = '\0';
				}
				else
					putchar(7);		// BEEP!
				break;
			case 0x1B:  /* ESC */
        		if (cDigits)
					while (cDigits--)
						printf("\008 \008");
        		break;						
			default:
				invalid_digit = 1;
				Tracef("\nInvalid digit");
				putchar(7);		// BEEP!
				break;
			}
		}
	}		
}
Esempio n. 6
0
 string Diamond::print(char c)
 {
   return boost::accumulate(impl::all_lines(char_to_num(c)), ""s, _1 + _2 + '\n');
 }