View | Details | Raw Unified | Return to bug 1336
Collapse All | Expand All

(-)a/src/topology-read/model/rocketfuel-topology-reader.cc (-66 / +69 lines)
 Lines 331-420    Link Here 
331
      lineBuffer.clear ();
331
      lineBuffer.clear ();
332
332
333
      getline (topgen, line);
333
      getline (topgen, line);
334
      buf = (char *)line.c_str ();
334
      if( !line.empty() )
335
        {
336
          buf = (char *)line.c_str ();
335
337
336
      if (lineNumber == 1)
338
          if (lineNumber == 1)
337
        {
338
          ftype = GetFileType (buf);
339
          if (ftype == RF_UNKNOWN)
340
            {
339
            {
341
              NS_LOG_INFO ("Unknown File Format (" << GetFileName () << ")");
340
              ftype = GetFileType (buf);
342
              break;
341
              if (ftype == RF_UNKNOWN)
343
            }
342
                {
344
        }
343
                  NS_LOG_INFO ("Unknown File Format (" << GetFileName () << ")");
345
344
                  break;
346
      regmatch_t regmatch[REGMATCH_MAX];
345
                }
347
      regex_t regex;
348
349
      if (ftype == RF_MAPS)
350
        {
351
          ret = regcomp (&regex, ROCKETFUEL_MAPS_LINE, REG_EXTENDED | REG_NEWLINE);
352
          if (ret != 0)
353
            {
354
              regerror (ret, &regex, errbuf, sizeof (errbuf));
355
              regfree (&regex);
356
              break;
357
            }
346
            }
358
347
359
          ret = regexec (&regex, buf, REGMATCH_MAX, regmatch, 0);
348
          regmatch_t regmatch[REGMATCH_MAX];
360
          if (ret == REG_NOMATCH)
349
          regex_t regex;
350
351
          if (ftype == RF_MAPS)
361
            {
352
            {
362
              NS_LOG_WARN ("match failed (maps file): %s" << buf);
353
              ret = regcomp (&regex, ROCKETFUEL_MAPS_LINE, REG_EXTENDED | REG_NEWLINE);
363
              regfree (&regex);
354
              if (ret != 0)
364
              break;
355
                {
356
                  regerror (ret, &regex, errbuf, sizeof (errbuf));
357
                  regfree (&regex);
358
                  break;
359
                }
360
361
              ret = regexec (&regex, buf, REGMATCH_MAX, regmatch, 0);
362
              if (ret == REG_NOMATCH)
363
                {
364
                  NS_LOG_WARN ("match failed (maps file): %s" << buf);
365
                  regfree (&regex);
366
                  break;
367
                }
365
            }
368
            }
366
        }
369
          else if (ftype == RF_WEIGHTS)
367
      else if (ftype == RF_WEIGHTS)
368
        {
369
          ret = regcomp (&regex, ROCKETFUEL_WEIGHTS_LINE, REG_EXTENDED | REG_NEWLINE);
370
          if (ret != 0)
371
            {
370
            {
372
              regerror (ret, &regex, errbuf, sizeof (errbuf));
371
              ret = regcomp (&regex, ROCKETFUEL_WEIGHTS_LINE, REG_EXTENDED | REG_NEWLINE);
373
              regfree (&regex);
372
              if (ret != 0)
374
              break;
373
                {
374
                  regerror (ret, &regex, errbuf, sizeof (errbuf));
375
                  regfree (&regex);
376
                  break;
377
                }
378
379
              ret = regexec (&regex, buf, REGMATCH_MAX, regmatch, 0);
380
              if (ret == REG_NOMATCH)
381
                {
382
                  NS_LOG_WARN ("match failed (weights file): %s" << buf);
383
                  regfree (&regex);
384
                  break;
385
                }
375
            }
386
            }
376
387
377
          ret = regexec (&regex, buf, REGMATCH_MAX, regmatch, 0);
388
          line = buf;
378
          if (ret == REG_NOMATCH)
389
          argc = 0;
390
391
          /* regmatch[0] is the entire strings that matched */
392
          for (int i = 1; i < REGMATCH_MAX; i++)
379
            {
393
            {
380
              NS_LOG_WARN ("match failed (weights file): %s" << buf);
394
              if (regmatch[i].rm_so == -1)
381
              regfree (&regex);
395
                {
382
              break;
396
                  argv[i - 1] = NULL;
397
                }
398
              else
399
                {
400
                  line[regmatch[i].rm_eo] = '\0';
401
                  argv[i - 1] = &line[regmatch[i].rm_so];
402
                  argc = i;
403
                }
383
            }
404
            }
384
        }
385
405
386
      line = buf;
406
          if (ftype == RF_MAPS)
387
      argc = 0;
388
389
      /* regmatch[0] is the entire strings that matched */
390
      for (int i = 1; i < REGMATCH_MAX; i++)
391
        {
392
          if (regmatch[i].rm_so == -1)
393
            {
407
            {
394
              argv[i - 1] = NULL;
408
              nodes.Add (GenerateFromMapsFile (argc, argv));
409
            }
410
          else if (ftype == RF_WEIGHTS)
411
            {
412
              nodes.Add (GenerateFromWeightsFile (argc, argv));
395
            }
413
            }
396
          else
414
          else
397
            {
415
            {
398
              line[regmatch[i].rm_eo] = '\0';
416
              NS_LOG_WARN ("Unsupported file format (only Maps/Weights are supported)");
399
              argv[i - 1] = &line[regmatch[i].rm_so];
400
              argc = i;
401
            }
417
            }
418
419
          regfree (&regex);
402
        }
420
        }
403
404
      if (ftype == RF_MAPS)
405
        {
406
          nodes.Add (GenerateFromMapsFile (argc, argv));
407
        }
408
      else if (ftype == RF_WEIGHTS)
409
        {
410
          nodes.Add (GenerateFromWeightsFile (argc, argv));
411
        }
412
      else
413
        {
414
          NS_LOG_WARN ("Unsupported file format (only Maps/Weights are supported)");
415
        }
416
417
      regfree (&regex);
418
    }
421
    }
419
422
420
423

Return to bug 1336