Esempio n. 1
0
static void
three_digits( char * buf, size_t buflen, const char * name, const uint8_t * digits )
{
    tr_snprintf( buf, buflen, "%s %d.%d.%d", name,
                 charint( digits[0] ),
                 charint( digits[1] ),
                 charint( digits[2] ) );
}
Esempio n. 2
0
void build_scenery( int matrix[][50], char filename[]) // this function will open the scenery.txt file and convert into a matrix
{
    record = 0;
    int i,j; // generic counters
    char rec[5]; // the vector with the characters of record
    FILE *scenery;
    scenery = fopen(filename,"r");
    if(scenery==NULL) {
        zeroing(matrix);
    }
    else
    {
        for(i=0; i<25; i++)
        {
            for(j=0; j<=50; j++)
            {
                if(j==50) {
                    rec[0] = getc(scenery);
                }
                else
                {
                    matrix[i][j] = charint(getc(scenery));
                    if(matrix[i][j]==1) {
                        portal1[0] = i;
                        portal1[1] = j;
                    }
                    else if(matrix[i][j]==2) {
                        portal2[0] = i;
                        portal2[1] = j;
                    }
                }
            }
        }
    }
    for(i=0; i<5; i++) {
        rec[i] = getc(scenery);   // at this point, the function knows all characters of record
    }
    for(i=0; i<5; i++) {
        record += (charint((int)rec[i]))*pow(10,4-i);   // now, the function will convert the string into a  integer
    }
    fclose(scenery);
}
Esempio n. 3
0
void
tr_clientForId( char * buf, size_t buflen, const void * id_in )
{
    const uint8_t * id = id_in;

    *buf = '\0';

    if( !id )
        return;

    /* Azureus-style */
    if( id[0] == '-' && id[7] == '-' )
    {
        if( !memcmp( id+1, "UT", 2 ) )
        {
            tr_snprintf( buf, buflen, "\xc2\xb5Torrent %d.%d.%d%s",
                         strint(id+3,1), strint(id+4,1), strint(id+5,1), getMnemonicEnd(id[6]) );
        }
        if( !memcmp( id+1, "UM", 2 ) )
        {
            tr_snprintf( buf, buflen, "\xc2\xb5Torrent Mac %d.%d.%d%s",
                         strint(id+3,1), strint(id+4,1), strint(id+5,1), getMnemonicEnd(id[6]) );
        }

        else if( !memcmp( id+1, "TR", 2 ) )
        {
            if( !memcmp( id+3, "000", 3 ) ) /* very old client style: -TR0006- is 0.6 */
                tr_snprintf( buf, buflen, "Transmission 0.%c", id[6] );
            else if( !memcmp( id+3, "00", 2) ) /* previous client style: -TR0072- is 0.72 */
                tr_snprintf( buf, buflen, "Transmission 0.%02d", strint(id+5,2) );
            else /* current client style: -TR111Z- is 1.11+ */
                tr_snprintf( buf, buflen, "Transmission %d.%02d%s", strint(id+3,1), strint(id+4,2),
                          id[6]=='Z' || id[6]=='X' ? "+" : "" );
        }
        
        else if( !memcmp( id+1, "AZ", 2 ) )
        {
            if( id[3] > '3' || ( id[3] == '3' && id[4] >= '1' ) ) /* Vuze starts at version 3.1.0.0 */
                four_digits( buf, buflen, "Vuze", id+3 );
            else
                four_digits( buf, buflen, "Azureus", id+3 );
        }
        
        else if( !memcmp( id+1, "KT", 2 ) )
        {
            if( id[5] == 'D' )
                tr_snprintf( buf, buflen, "KTorrent %d.%d Dev %d", charint(id[3]), charint(id[4]), charint(id[6]) );
            else if( id[5] == 'R' )
                tr_snprintf( buf, buflen, "KTorrent %d.%d RC %d", charint(id[3]), charint(id[4]), charint(id[6]) );
            else
                three_digits( buf, buflen, "KTorrent", id+3 );
        }

        else if( !memcmp( id+1, "AR", 2 ) ) four_digits( buf, buflen, "Ares", id+3 );
        else if( !memcmp( id+1, "AT", 2 ) ) four_digits( buf, buflen, "Artemis", id+3 );
        else if( !memcmp( id+1, "AV", 2 ) ) four_digits( buf, buflen, "Avicora", id+3 );
        else if( !memcmp( id+1, "BG", 2 ) ) four_digits( buf, buflen, "BTGetit", id+3 );
        else if( !memcmp( id+1, "BM", 2 ) ) four_digits( buf, buflen, "BitMagnet", id+3 );
        else if( !memcmp( id+1, "BP", 2 ) ) four_digits( buf, buflen, "BitTorrent Pro (Azureus + Spyware)", id+3 );
        else if( !memcmp( id+1, "BX", 2 ) ) four_digits( buf, buflen, "BittorrentX", id+3 );
        else if( !memcmp( id+1, "bk", 2 ) ) four_digits( buf, buflen, "BitKitten (libtorrent)", id+3 );
        else if( !memcmp( id+1, "BS", 2 ) ) four_digits( buf, buflen, "BTSlave", id+3 );
        else if( !memcmp( id+1, "BW", 2 ) ) four_digits( buf, buflen, "BitWombat", id+3 );
        else if( !memcmp( id+1, "BX", 2 ) ) four_digits( buf, buflen, "BittorrentX", id+3 );
        else if( !memcmp( id+1, "EB", 2 ) ) four_digits( buf, buflen, "EBit", id+3 );
        else if( !memcmp( id+1, "DE", 2 ) ) four_digits( buf, buflen, "Deluge", id+3 );
        else if( !memcmp( id+1, "DP", 2 ) ) four_digits( buf, buflen, "Propogate Data Client", id+3 );
        else if( !memcmp( id+1, "FC", 2 ) ) four_digits( buf, buflen, "FileCroc", id+3 );
        else if( !memcmp( id+1, "FT", 2 ) ) four_digits( buf, buflen, "FoxTorrent/RedSwoosh", id+3 );
        else if( !memcmp( id+1, "GR", 2 ) ) four_digits( buf, buflen, "GetRight", id+3 );
        else if( !memcmp( id+1, "HN", 2 ) ) four_digits( buf, buflen, "Hydranode", id+3 );
        else if( !memcmp( id+1, "LC", 2 ) ) four_digits( buf, buflen, "LeechCraft", id+3 );
        else if( !memcmp( id+1, "LH", 2 ) ) four_digits( buf, buflen, "LH-ABC", id+3 );
        else if( !memcmp( id+1, "NX", 2 ) ) four_digits( buf, buflen, "Net Transport", id+3 );
        else if( !memcmp( id+1, "MO", 2 ) ) four_digits( buf, buflen, "MonoTorrent", id+3 );
        else if( !memcmp( id+1, "MR", 2 ) ) four_digits( buf, buflen, "Miro", id+3 );
        else if( !memcmp( id+1, "MT", 2 ) ) four_digits( buf, buflen, "Moonlight", id+3 );
        else if( !memcmp( id+1, "OT", 2 ) ) four_digits( buf, buflen, "OmegaTorrent", id+3 );
        else if( !memcmp( id+1, "PD", 2 ) ) four_digits( buf, buflen, "Pando", id+3 );
        else if( !memcmp( id+1, "QD", 2 ) ) four_digits( buf, buflen, "QQDownload", id+3 );
        else if( !memcmp( id+1, "RS", 2 ) ) four_digits( buf, buflen, "Rufus", id+3 );
        else if( !memcmp( id+1, "RT", 2 ) ) four_digits( buf, buflen, "Retriever", id+3 );
        else if( !memcmp( id+1, "SS", 2 ) ) four_digits( buf, buflen, "SwarmScope", id+3 );
        else if( !memcmp( id+1, "SZ", 2 ) ) four_digits( buf, buflen, "Shareaza", id+3 );
        else if( !memcmp( id+1, "S~", 2 ) ) four_digits( buf, buflen, "Shareaza", id+3 );
        else if( !memcmp( id+1, "st", 2 ) ) four_digits( buf, buflen, "SharkTorrent", id+3 );
        else if( !memcmp( id+1, "TN", 2 ) ) four_digits( buf, buflen, "Torrent .NET", id+3 );
        else if( !memcmp( id+1, "TS", 2 ) ) four_digits( buf, buflen, "TorrentStorm", id+3 );
        else if( !memcmp( id+1, "UL", 2 ) ) four_digits( buf, buflen, "uLeecher!", id+3 );
        else if( !memcmp( id+1, "VG", 2 ) ) four_digits( buf, buflen, "Vagaa", id+3 );
        else if( !memcmp( id+1, "WT", 2 ) ) four_digits( buf, buflen, "BitLet", id+3 );
        else if( !memcmp( id+1, "WY", 2 ) ) four_digits( buf, buflen, "Wyzo", id+3 );
        else if( !memcmp( id+1, "XL", 2 ) ) four_digits( buf, buflen, "Xunlei", id+3 );
        else if( !memcmp( id+1, "XT", 2 ) ) four_digits( buf, buflen, "XanTorrent", id+3 );
        else if( !memcmp( id+1, "ZT", 2 ) ) four_digits( buf, buflen, "Zip Torrent", id+3 );

        else if( !memcmp( id+1, "AG", 2 ) ) three_digits( buf, buflen, "Ares", id+3 );
        else if( !memcmp( id+1, "A~", 2 ) ) three_digits( buf, buflen, "Ares", id+3 );
        else if( !memcmp( id+1, "ES", 2 ) ) three_digits( buf, buflen, "Electric Sheep", id+3 );
        else if( !memcmp( id+1, "HL", 2 ) ) three_digits( buf, buflen, "Halite", id+3 );
        else if( !memcmp( id+1, "LT", 2 ) ) three_digits( buf, buflen, "libtorrent (Rasterbar)", id+3 );
        else if( !memcmp( id+1, "lt", 2 ) ) three_digits( buf, buflen, "libTorrent (Rakshasa)", id+3 );
        else if( !memcmp( id+1, "MP", 2 ) ) three_digits( buf, buflen, "MooPolice", id+3 );
        else if( !memcmp( id+1, "TT", 2 ) ) three_digits( buf, buflen, "TuoTu", id+3 );
        else if( !memcmp( id+1, "qB", 2 ) ) three_digits( buf, buflen, "qBittorrent", id+3 );

        else if( !memcmp( id+1, "AX", 2 ) ) two_major_two_minor( buf, buflen, "BitPump", id+3 );
        else if( !memcmp( id+1, "BC", 2 ) ) two_major_two_minor( buf, buflen, "BitComet", id+3 );
        else if( !memcmp( id+1, "CD", 2 ) ) two_major_two_minor( buf, buflen, "Enhanced CTorrent", id+3 );
        else if( !memcmp( id+1, "LP", 2 ) ) two_major_two_minor( buf, buflen, "Lphant", id+3 );

        else if( !memcmp( id+1, "BF", 2 ) ) no_version( buf, buflen, "BitFlu" );
        else if( !memcmp( id+1, "LW", 2 ) ) no_version( buf, buflen, "LimeWire" );

        else if( !memcmp( id+1, "BB", 2 ) )
        {
            tr_snprintf( buf, buflen, "BitBuddy %c.%c%c%c", id[3], id[4], id[5], id[6] );
        }
        else if( !memcmp( id+1, "BR", 2 ) )
        {
            tr_snprintf( buf, buflen, "BitRocket %c.%c (%c%c)", id[3], id[4], id[5], id[6] );
        }
        else if( !memcmp( id+1, "CT", 2 ) )
        {
            tr_snprintf( buf, buflen, "CTorrent %d.%d.%02d", charint(id[3]), charint(id[4]), strint(id+5,2) );
        }
        else if( !memcmp( id+1, "XX", 2 ) )
        {
            tr_snprintf( buf, buflen, "Xtorrent %d.%d (%d)", charint(id[3]), charint(id[4]), strint(id+5,2) );
        }
        else if( !memcmp( id+1, "BOW", 3 ) )
        {
                 if( !memcmp( &id[4], "A0B", 3 ) ) tr_snprintf( buf, buflen, "Bits on Wheels 1.0.5" );
            else if( !memcmp( &id[4], "A0C", 3 ) ) tr_snprintf( buf, buflen, "Bits on Wheels 1.0.6" );
            else                                   tr_snprintf( buf, buflen, "Bits on Wheels %c.%c.%c", id[4], id[5], id[5] );
        }

        if( *buf )
            return;
    }

    /* Mainline */
    if( isMainlineStyle( id ) )
    {
        if( *id=='M' ) mainline_style( buf, buflen, "BitTorrent", id );
        if( *id=='Q' ) mainline_style( buf, buflen, "Queen Bee", id );
        if( *buf ) return;
    }

    if( decodeBitCometClient( buf, buflen, id ) )
        return;
    if( decodeBitSpiritClient( buf, buflen, id ) )
        return;

    /* Clients with no version */
         if( !memcmp( id, "AZ2500BT", 8 ) )  no_version( buf, buflen, "BitTyrant (Azureus Mod)" );
    else if( !memcmp( id, "LIME", 4 ) )      no_version( buf, buflen, "Limewire" );
    else if( !memcmp( id, "martini", 7 ) )   no_version( buf, buflen, "Martini Man" );
    else if( !memcmp( id, "Pando", 5 ) )     no_version( buf, buflen, "Pando" );
    else if( !memcmp( id, "a00---0", 7 ) )   no_version( buf, buflen, "Swarmy" );
    else if( !memcmp( id, "a02---0", 7 ) )   no_version( buf, buflen, "Swarmy" );
    else if( !memcmp( id, "-G3", 3 ) )       no_version( buf, buflen, "G3 Torrent" );
    else if( !memcmp( id, "10-------", 9 ) ) no_version( buf, buflen, "JVtorrent" );
    else if( !memcmp( id, "346-", 4 ) )      no_version( buf, buflen, "TorrentTopia" );
    else if( !memcmp( id, "eX", 2 ) )        no_version( buf, buflen, "eXeem" );
    else if( !memcmp( id, "-FG", 3 ) )       two_major_two_minor( buf, buflen, "FlashGet", id+3 );
   
    /* Everything else */ 
    else if( !memcmp( id, "S3", 2 ) && id[2] == '-' && id[4] == '-' && id[6] == '-' )
    {
        tr_snprintf( buf, buflen, "Amazon S3 %c.%c.%c", id[3], id[5], id[7] );
    }
    else if( !memcmp( id, "OP", 2 ) )
    {
        tr_snprintf( buf, buflen, "Opera (Build %c%c%c%c)", id[2], id[3], id[4], id[5] );
    }
    else if( !memcmp( id, "-ML", 3 ) )
    {
        tr_snprintf( buf, buflen, "MLDonkey %c%c%c%c%c", id[3], id[4], id[5], id[6], id[7] );
    }
    else if( !memcmp( id, "DNA", 3 ) )
    {
        tr_snprintf( buf, buflen, "BitTorrent DNA %d.%d.%d", strint(id+3,2),
                                                             strint(id+5,2),
                                                             strint(id+7,2) );
    }
    else if( !memcmp( id, "Plus", 4 ) )
    {
        tr_snprintf( buf, buflen, "Plus! v2 %c.%c%c", id[4], id[5], id[6] );
    }
    else if( !memcmp( id, "XBT", 3 ) )
    {
        tr_snprintf( buf, buflen, "XBT Client %c.%c.%c%s", id[3], id[4], id[5], getMnemonicEnd(id[6]) );
    }
    else if( !memcmp( id, "Mbrst", 5 ) )
    {
        tr_snprintf( buf, buflen, "burst! %c.%c.%c", id[5], id[7], id[9] );
    }
    else if( !memcmp( id, "btpd", 4 ) )
    {
        tr_snprintf( buf, buflen, "BT Protocol Daemon %c%c%c", id[5], id[6], id[7] );
    }
    else if( !memcmp( id, "BLZ", 3 ) )
    {
        tr_snprintf( buf, buflen, "Blizzard Downloader %d.%d", id[3]+1, id[4] );
    }
    else if( '\0' == id[0] && !memcmp( &id[1], "BS", 2 ) )
    {
        tr_snprintf( buf, buflen, "BitSpirit %u", ( id[1] == 0 ? 1 : id[1] ) );
    }
    else if( !memcmp( id, "QVOD", 4 ) )
    {
        four_digits( buf, buflen, "QVOD", id+4 );
    }
    else if( !memcmp( id, "-NE", 3 ) )
    {
        four_digits( buf, buflen, "BT Next Evolution", id+3 );
    }

    /* Shad0w-style */
    {
        int a, b, c;
        if( strchr( "AOQRSTU", id[0] )
            && getShadowInt( id[1], &a )
            && getShadowInt( id[2], &b )
            && getShadowInt( id[3], &c ) )
        {
            const char * name = NULL;

            switch( id[0] )
            {
                case 'A': name = "ABC"; break;
                case 'O': name = "Osprey"; break;
                case 'Q': name = "BTQueue"; break;
                case 'R': name = "Tribler"; break;
                case 'S': name = "Shad0w"; break;
                case 'T': name = "BitTornado"; break;
                case 'U': name = "UPnP NAT Bit Torrent"; break;
            }

            if( name )
            {
                tr_snprintf( buf, buflen, "%s %d.%d.%d", name, a, b, c );
                return;
            }
        }
    }

    /* No match */
    if( !*buf )
    {
        struct evbuffer * out = evbuffer_new( );
        const char *in, *in_end;
        for( in=(const char*)id, in_end=in+8; in!=in_end; ++in ) {
            if( isprint( *in ) )
                evbuffer_add_printf( out, "%c", *in );
            else
                evbuffer_add_printf( out, "%%%02X", (unsigned int)*in );
        }

        tr_strlcpy( buf, EVBUFFER_DATA( out ), buflen );
        evbuffer_free( out );
    }
}
Esempio n. 4
0
partition_t parse_partition(FILE* datei,int all,int paras){
  int i = 0;   /* loop variable */
  int j = 0;   /* loop variable */
  int c = 0;   /* Read Character */
  int current_pos = 0; /* Current Position for Start/End */
  int temp = 0;/* loop variable */
  int charset_flag = 0;/* Flag to check when charset starts */
  int charpart_flag = 0;/* Flag to check when charpartition starts */   
  size_t current_set_len = 0;  /* number of charsets currently read. */
  size_t partition_counter = 0; /* number of charpartitionlines currently read */
  size_t set_leng = SET_LENG; /* Maximum number of Charsets */
  size_t part_leng = PART_LENG; /*Maximum number of Charpartitionlines */
  int true_nexus = 0;   /* Flag to check if file is a Nexusfile */
  int set_start = 0;    
  int end_counter = 0;
  partition_t ret;   /* Returned struct */
  int part_var_names_str_len[2];
  int temp_summe; /* Current_pos + temp_sum = new starting point for partition */
  char vname[100]; /* String for a name */
  char first_number[100]; /* String for a name */
  char second_number[100]; /* String for a name */
  char step_number[100]; /* String for a name */
  char **lookup; /*Array of Strings for Charsets */
  char mod_name[100]; /* String for a name */
  char mod_v_name[100];/* String for a name */
  char pname[2000];/* String for a name */
  char **ppart_name; /* Array of Strings for Charpartitions */
  char **ppart_var_name; /* Array of Strings for Charpartitions */
  char **ppart_model_name; /* Array of Strings for Charpartitions */
  char **ppart_parameter_name; /* Array of Strings for Charpartitions */
  int fn,sn,st; /* Calculation of length */
  int name_right;
  int more_numbone;
  int more_mv_names[3];
  int* ind;
  int doto[2];
  size_t* pset_fn;
  size_t* pset_sn;
  size_t* pset_st;
  size_t* pset_leng;
  size_t* ppart_fn;
  size_t* ppart_sn;
  char * str;
  int str_len = STR_LEN;
  int c_read = -1;
  /* Allocate arrays */
  str = (char*) malloc(sizeof(char)*str_len);
  str = fgets(str,str_len,datei);
  pset_fn = (size_t*) malloc(sizeof(size_t)*set_leng);
  pset_sn = (size_t*) malloc(sizeof(size_t)*set_leng);
  pset_st = (size_t*) malloc(sizeof(size_t)*set_leng);
  pset_leng = (size_t*) malloc(sizeof(size_t)*set_leng);
  ppart_fn = (size_t*) malloc(sizeof(size_t)*part_leng);
  ppart_sn = (size_t*) malloc(sizeof(size_t)*part_leng);
  ppart_name = (char **) malloc(sizeof(char*)*part_leng);
  ppart_var_name = (char **) malloc(sizeof(char*)*part_leng);
  ppart_model_name = (char **) malloc(sizeof(char*)*part_leng);
  ppart_parameter_name = (char **) malloc(sizeof(char*)*part_leng);
  lookup = (char **) malloc(sizeof(char*)*set_leng);
  
  /* Here the fun begins */
  while( (c=mygetc(str,str_len,datei,&c_read)) != EOF && true_nexus != 6){
    while(isspace(c)) c = mygetc(str,str_len,datei,&c_read);
    if (c<91 && c>64) c+= 32;
    if(true_nexus == 0 && c=='#') true_nexus++;
    else if(true_nexus == 1 && c=='n') true_nexus++;
    else if(true_nexus == 2 && c=='e') true_nexus++;
    else if(true_nexus == 3 && c=='x') true_nexus++;
    else if(true_nexus == 4 && c=='u') true_nexus++;
    else if(true_nexus == 5 && c=='s') {
      true_nexus++;
      break;
    }
    else true_nexus = 0;
  }
  if(true_nexus != 6) {
    printf("No '#nexus' was found. Is this a nexus file?\n");
    exit(EXIT_FAILURE);
  }
  else {
    while( (c=mygetc(str,str_len,datei,&c_read)) != EOF){
      if(set_start == 0 && c=='b') set_start++;
      else if(set_start == 1 && c=='e') set_start++;
      else if(set_start == 2 && c=='g') set_start++;
      else if(set_start == 3 && c=='i') set_start++;
      else if(set_start == 4 && c=='n') set_start++;
      else if(set_start == 5 && c==' ') set_start++;
      else if(set_start == 6 && c=='s') set_start++;
      else if(set_start == 7 && c=='e') set_start++;
      else if(set_start == 8 && c=='t') set_start++;
      else if(set_start == 9 && c=='s') set_start++;
      else if(set_start == 10 && c==';') {
        set_start++;
        break;
      }
      else set_start = 0;
    }
  }
  if(set_start != 11) {
    printf("No sets have been found\n");
    exit(EXIT_FAILURE);
  }
  while( (c=mygetc(str,str_len,datei,&c_read)) != EOF){
    if(charset_flag == 0 && c=='e' && end_counter==0) end_counter++;
    else if(charset_flag == 0 && c=='n' && end_counter==1) end_counter++;
    else if(charset_flag == 0 && c=='d' && end_counter==2) end_counter++;
    else if(charset_flag == 0 && c==';' && end_counter==3) end_counter++;
    else end_counter=0;
    if(end_counter==4) break;
    if(charset_flag == 0 && c=='c') charset_flag++;
    else if(charset_flag == 1 && c=='h') charset_flag++;
    else if(charset_flag == 2 && c=='a') charset_flag++;
    else if(charset_flag == 3 && c=='r') charset_flag++;
    else if(charset_flag == 4 && c=='s') charset_flag++;
    else if(charset_flag == 5 && c=='e') charset_flag++;
    else if(charset_flag == 6 && c=='t') charset_flag++;
    else if(charset_flag == 7 && c==' ') charset_flag++;
    else if(charset_flag == 8){
/*      fseek(datei, -1L, SEEK_CUR); */
      name_right = grepName(c,datei,vname,str,str_len,&c_read);
      if( name_right == -1) exit(EXIT_FAILURE);
      lookup[i]=(char *) malloc(sizeof(char)*name_right);
      for(temp=0;vname[temp]!='\0';temp++){
        lookup[i][temp]=vname[temp];
      }
      lookup[i][temp]='\0';
      grepFirstNumber(doto,c,datei,first_number,str,str_len,&c_read);
      fn = charint(first_number);
      pset_fn[i]=charint(first_number);
      more_numbone = grepSecondNumber(c,datei,first_number,str,str_len,&c_read);
      pset_sn[i]=charint(first_number);
      sn = charint(first_number);
      grepSteps(doto,c,datei,first_number,str,str_len,&c_read);
      st = charint(first_number);
      pset_st[i]=charint(first_number);
      pset_leng[i]=(sn-fn)/st+1;
      i++;
      current_set_len++;
      /* Extend Array if needed */
      if(current_set_len==set_leng){
        set_leng=set_leng *2;
        expand_set_table( set_leng, current_set_len, &lookup, &pset_leng, &pset_fn, &pset_sn, &pset_st);
      }
      while(more_numbone == 77 || doto[0] == 77){
/*        fseek(datei, -1L, SEEK_CUR); */
        grepFirstNumber(doto,c,datei,first_number,str,str_len,&c_read);
        more_numbone = grepSecondNumber(c,datei,second_number,str,str_len,&c_read);
        grepSteps(doto,c,datei,step_number,str,str_len,&c_read);
        temp = 0;
        lookup[i]=(char *) malloc(sizeof(char)*name_right);
        for(temp=0;vname[temp]!='\0';temp++){
          lookup[i][temp]=vname[temp];
        }
        lookup[i][temp]='\0';
        pset_fn[i]=charint(first_number);
        pset_sn[i]=charint(second_number);
        pset_st[i]=charint(step_number);
        pset_leng[i]=(pset_sn[i]-pset_fn[i])/pset_st[i]+1;
        i++;
        current_set_len++;
        /* Extend Array if needed */
        if(current_set_len==set_leng){
          set_leng=set_leng *2;
          expand_set_table( set_leng, current_set_len, &lookup, &pset_leng, &pset_fn, &pset_sn, &pset_st);
        }
      }
      charset_flag = 0;
    }
    else
      charset_flag = 0;
    /* Looking for 'charpartition' */
    if(charpart_flag == 0 && c=='c') charpart_flag++;
    else if(charpart_flag == 1 && c=='h') charpart_flag++;
    else if(charpart_flag == 2 && c=='a') charpart_flag++;
    else if(charpart_flag == 3 && c=='r') charpart_flag++;
    else if(charpart_flag == 4 && c=='p') charpart_flag++;
    else if(charpart_flag == 5 && c=='a') charpart_flag++;
    else if(charpart_flag == 6 && c=='r') charpart_flag++;
    else if(charpart_flag == 7 && c=='t') charpart_flag++;
    else if(charpart_flag == 8 && c=='i') charpart_flag++;
    else if(charpart_flag == 9 && c=='t') charpart_flag++;
    else if(charpart_flag == 10 && c=='i') charpart_flag++;
    else if(charpart_flag == 11 && c=='o') charpart_flag++;
    else if(charpart_flag == 12 && c=='n') charpart_flag++;
    else if(charpart_flag == 13 && c==' '){
      if(all!=1)current_pos =0;
      temp = 0;
    /*  fseek(datei, -1L, SEEK_CUR); */
      name_right = grepName(c,datei,vname,str,str_len,&c_read);
      /* check if 'all' is set */
      if(all==1){
        vname[0] = 'a';
        vname[1] = 'l';
        vname[2] = 'l';
        vname[3] = '\0';
        name_right=4;
      }
      if( name_right == -1) exit(EXIT_FAILURE);
      grepModName(c,datei,mod_name, pname,part_var_names_str_len,str,str_len,&c_read);
      grepVName(c,datei,mod_v_name,more_mv_names,str,str_len,&c_read);
      while (more_mv_names[0] != 0){

        ppart_name[j]=(char*) malloc(sizeof(char)*name_right);
        for(temp=0;vname[temp]!='\0';temp++)ppart_name[j][temp] = vname[temp];
        ppart_name[j][temp]='\0';

        ppart_model_name[j]=(char*) malloc(sizeof(char)*part_var_names_str_len[0]);
        for(temp=0;mod_name[temp]!='\0';temp++)ppart_model_name[j][temp] = mod_name[temp];
        ppart_model_name[j][temp]='\0';
        
        ppart_parameter_name[j]=(char*) malloc(sizeof(char)*part_var_names_str_len[1]);
        for(temp=0;pname[temp]!='\0';temp++) ppart_parameter_name[j][temp]= pname[temp];
        ppart_parameter_name[j][temp]='\0';
        
        if( more_mv_names[0] == -1 ) exit(EXIT_FAILURE);
        else if( more_mv_names[0] == 66){
          
          ppart_var_name[j]=(char*) malloc(sizeof(char)*more_mv_names[1]);
          for(temp=0;mod_v_name[temp]!='\0';temp++) ppart_var_name[j][temp]=mod_v_name[temp];
          ppart_var_name[j][temp]='\0';
/*          fprintf(stderr,"COMPARE:\n......%s\n......%s\n",mod_v_name,lookup[0]); */
          ind = find_set(mod_v_name,lookup,current_set_len);
          temp_summe =0;
          for(temp=1;temp<ind[0]+1;temp++)temp_summe+= pset_leng[ind[temp]];
          free(ind);
          ppart_fn[j]=current_pos+1;
          current_pos += temp_summe;
          ppart_sn[j]=current_pos;
          partition_counter++;
          j++;
          /* Extend Array if needed */
          if(j==part_leng){
            part_leng = part_leng*2;
            expand_part_table(&ppart_name,&ppart_var_name,&ppart_model_name,&ppart_parameter_name,partition_counter,part_leng,&ppart_fn,&ppart_sn);
          }
          grepVName(more_mv_names[2],datei,mod_v_name,more_mv_names,str,str_len,&c_read);
        }
        else if( more_mv_names[0] == 77) {
          
          ppart_var_name[j]=(char*) malloc(sizeof(char)*more_mv_names[1]);
          for(temp=0;mod_v_name[temp]!='\0';temp++) ppart_var_name[j][temp]=mod_v_name[temp];
          ppart_var_name[j][temp]='\0';
          
/*          fprintf(stderr,"COMPARE:\n......%s\n......%s\n",mod_v_name,lookup[0]); */
          ind = find_set(mod_v_name,lookup,current_set_len);
          temp_summe =0;
          for(temp=1;temp<ind[0]+1;temp++)temp_summe+= pset_leng[ind[temp]];
          free(ind);
          ppart_fn[j]=current_pos+1;
          current_pos += temp_summe;
          ppart_sn[j]=current_pos;
          j++;
          partition_counter++;
          /* Extend Array if needed */
          if(j==part_leng){
            part_leng = part_leng *2;
/* fprintf(stderr,"(%s:%d)\n",__FILE__,__LINE__); */
            expand_part_table(&ppart_name,&ppart_var_name,&ppart_model_name,&ppart_parameter_name,partition_counter,part_leng,&ppart_fn,&ppart_sn);
          }
          grepModName(c,datei,mod_name, pname,part_var_names_str_len,str,str_len,&c_read);
          grepVName(c,datei,mod_v_name,more_mv_names,str,str_len,&c_read);
        }
      }
      /* Get new Memory and save char[] */
      ppart_var_name[j]=(char*) malloc(sizeof(char)*more_mv_names[1]);
      for(temp=0;mod_v_name[temp]!='\0';temp++) ppart_var_name[j][temp]=mod_v_name[temp];
      ppart_var_name[j][temp]='\0';
      
      ppart_name[j]=(char*) malloc(sizeof(char)*name_right);
      for(temp=0;vname[temp]!='\0';temp++)ppart_name[j][temp] = vname[temp];
      ppart_name[j][temp]='\0';

      ppart_model_name[j]=(char*) malloc(sizeof(char)*part_var_names_str_len[0]);
      for(temp=0;mod_name[temp]!='\0';temp++)ppart_model_name[j][temp] = mod_name[temp];
      ppart_model_name[j][temp]='\0';
      
      ppart_parameter_name[j]=(char*) malloc(sizeof(char)*part_var_names_str_len[1]);
      for(temp=0;pname[temp]!='\0';temp++) ppart_parameter_name[j][temp]= pname[temp];
      ppart_parameter_name[j][temp]='\0';
      
/*           fprintf(stderr,"COMPARE:\n......%s\n......%s\n",mod_v_name,lookup[0]); */ 
      ind = find_set(mod_v_name,lookup,current_set_len);
      temp_summe =0;
      for(temp=1;temp<ind[0]+1;temp++)temp_summe+= pset_leng[ind[temp]];
      free(ind);
      ppart_fn[j]=current_pos+1;
      current_pos += temp_summe;
      ppart_sn[j]= current_pos;
      j++;
      partition_counter++;
      /* Extend Array if needed */
      if(j==part_leng){
        part_leng = part_leng *2;
/* fprintf(stderr,"(%s:%d)\n",__FILE__,__LINE__); */
        expand_part_table(&ppart_name,&ppart_var_name,&ppart_model_name,&ppart_parameter_name,partition_counter,part_leng,&ppart_fn,&ppart_sn);
      }
      charpart_flag = 0;
    }
    else
      charpart_flag = 0;
  }
  if(end_counter != 4) {
    printf("No 'end;' for 'begin sets;' was found.\n");
    exit(EXIT_FAILURE);
  }
  ret.start = ppart_fn;
  ret.end = ppart_sn;
  ret.model_names=ppart_model_name;
  if(paras)
    ret.parameter_names=ppart_parameter_name;
  else{
    ret.parameter_names=NULL;
    for(i=0;i<partition_counter;i++)
      free(ppart_parameter_name[i]);
    free(ppart_parameter_name);
/* fprintf(stderr,"ERROR %s:%d\n",__FILE__,__LINE__); */
  }
  ret.partition_names=ppart_name;
  ret.gene_names=ppart_var_name;
  ret.part_len=partition_counter;
  ret.max_part_len=part_leng;
  for(i=0;i<current_set_len;i++){
     printf("%s ",lookup[i]);
     printf("%lu...%lu...%lu...%lu",pset_fn[i],pset_sn[i],pset_st[i],pset_leng[i]);
     printf("\n");
  }
  for(i=0;i<current_set_len;i++)
    free(lookup[i]);
  free(lookup);
  free(pset_fn);
  free(pset_sn);
  free(pset_st);
  free(pset_leng);
  return ret;
} /* parse_partition */
Esempio n. 5
0
void select_stage( int matrix[][50]) // if wall mode is off
{
    int k = 0, i,j,s=0;
    char button;
    char address[13] = "sceneryx.txt";  // the generic address to some scenery
    BITMAP *buffer2 = create_bitmap(600,272);
    BITMAP *mb = load_bitmap("Image/Miniblock.bmp",NULL);// load the miniblock
    FILE *scenery; // pointer of file
    while(s != 1)
    {
        clear_to_color(buffer2,0x6F6F6F);
        rect(buffer2,173,71,425,198,0x000000);// boot the rectangle
        rect(buffer2,172,70,426,199,0x000000);// boot the rectangle
        rectfill(buffer2,174,72,424,197,0xFFFFFF);// boot the rectangle
        address[7] = intchar(k);
        scenery = fopen(address,"r");
        if(scenery==NULL) {
            zeroing(matrix);
        }
        else
        {
            for(i=0; i<25; i++)
            {
                for(j=0; j<=50; j++)
                {
                    if(j==50) {
                        getc(scenery);
                    }
                    else matrix[i][j] = charint(getc(scenery));
                }
            }
            fclose(scenery);
        }
        for(i=0; i<25; i++)
        {
            for(j=0; j<50; j++)
            {
                if(matrix[i][j]==8) {
                    blit(mb,buffer2,0,0,(177+j*5)-2,(75+i*5)-2,5,5);
                }
            }
        }
        blit(buffer2,screen,0,0,0,0,600,272);
        outnumber(240,210,k);
        textout_ex(screen,font,"Field ",185,210,0xFFFFFF,0x6F6F6F);
        button = readkey();
        rest(20);
        if((button==enter)&&(scenery!=NULL)&&(k!=0)) {
            clear_to_color(screen,0xFFFFFF);
            build_scenery(matrix,address);
            s = 1;
            scenery_number = k;
        }
        else if((button==enter)&&(scenery==NULL)) {
            build_scenery(matrix,"scenery_.txt");
            s = 1;
            scenery_number = 0;
        }
        else if((button==l)||(button==d)) {
            if(k>0) {
                k--;
            }
        }
        else {
            if(k<9) {
                k++;
            }
        }
    }
}