コード例 #1
0
ファイル: alignment.c プロジェクト: aakrosh/indelMINER
static int find_best_del_candidate(const int q1, const int q2, 
                                    const uint32_t* cigarstring1, 
                                    const int numcigarops1, 
                                    const int q3, const int q4,
                                    const uint32_t* cigarstring2, 
                                    const int numcigarops2,
                                    const int readlength)
{
    forceassert(q1 == 0);
    forceassert(q3 <= q2);

    int i, matches, bestmatches = 0, mm, bestmm = INT_MAX, index = -1;
    for(i = q3; i <= q2; i++){
        matches = count_matches(cigarstring1, numcigarops1, q1, i,
                                cigarstring2, numcigarops2, i, q4, &mm);
//        printf("Matches: %d, Mismatches: %d\n", matches, mm);
        forceassert(matches <= readlength);    

        if(matches > bestmatches){
            bestmatches = matches;
            bestmm = mm;
            index = i;
        }else if((matches == bestmatches) && (mm < bestmm)){
            bestmatches = matches;
            bestmm = mm;
            index = i;
        }
        if((matches == readlength) && (mm == 0)) break;
    }
    forceassert(index != -1);
//    printf("%d : %d : %d\n", index, bestmatches, bestmm); 

    return index;
}
コード例 #2
0
ファイル: utility.hpp プロジェクト: javaosos/stan
void expect_matches(int n,
                    const std::string& stan_code,
                    const std::string& target,
                    bool print_model = false) {
  std::string model_cpp = model_to_cpp(stan_code);
  if (print_model)
    std::cout << model_cpp << std::endl;
  EXPECT_EQ(n, count_matches(target,model_cpp));
}
コード例 #3
0
ファイル: compiler_test.cpp プロジェクト: stan-dev/stan
TEST(LangCompiler, emptyProgram) {
  std::stringstream msgs, stan_lang_in, cpp_out;
  std::string model_name = "m";
  stan_lang_in << "";

  stan::lang::compile(&msgs, stan_lang_in, cpp_out, model_name);

  EXPECT_EQ(1,count_matches("WARNING: empty program",msgs.str()));
  EXPECT_EQ(std::string::npos, cpp_out.str().find("int main("));

  // can't test equivalence of "" and "model { }" because of the
  // recording of the positions in the file
}
コード例 #4
0
ファイル: opesys.c プロジェクト: allinurl/goaccess
/* Attempt to parse specific OS.
 *
 * On success, a malloc'd string containing the OS is returned. */
static char *
parse_os (const char *str, char *tkn, char *os_type, int idx)
{
  char *b;
  int spaces = 0;

  xstrncpy (os_type, os[idx][1], OPESYS_TYPE_LEN);
  /* Windows */
  if ((strstr (str, "Windows")) != NULL)
    return conf.real_os && (b = get_real_win (tkn)) ? b : xstrdup (os[idx][0]);
  /* Android */
  if ((strstr (tkn, "Android")) != NULL) {
    tkn = parse_android (tkn);
    return conf.real_os ? get_real_android (tkn) : xstrdup (tkn);
  }
  /* iOS */
  if (strstr (tkn, "iPad") || strstr (tkn, "iPod"))
    return xstrdup (parse_ios (tkn, 4));
  if (strstr (tkn, "iPhone"))
    return xstrdup (parse_ios (tkn, 6));
  /* Mac OS X */
  if ((strstr (tkn, "OS X")) != NULL) {
    tkn = parse_osx (tkn);
    return conf.real_os ? get_real_mac_osx (tkn) : xstrdup (tkn);
  }
  /* Darwin - capture the first part of agents such as:
   * Slack/248000 CFNetwork/808.0.2 Darwin/16.0.0 */
  if ((strstr (tkn, "Darwin")) != NULL) {
    if ((b = strchr (str, ' ')))
      *b = 0;
    return xstrdup (str);
  }
  /* all others */
  spaces = count_matches (os[idx][0], ' ');

  return alloc_string (parse_others (tkn, spaces));
}
コード例 #5
0
ファイル: opesys.c プロジェクト: carriercomm/goaccess
/* Given a user agent, determine the operating system used.
 *
 * ###NOTE: The size of the list is proportional to the run time,
 * which makes this pretty slow
 *
 * On error, NULL is returned.
 * On success, a malloc'd  string containing the OS is returned. */
char *
verify_os (const char *str, char *os_type)
{
    char *a, *b;
    int spaces = 0;
    size_t i;

    if (str == NULL || *str == '\0')
        return NULL;

    for (i = 0; i < ARRAY_SIZE (os); i++) {
        if ((a = strstr (str, os[i][0])) == NULL)
            continue;

        xstrncpy (os_type, os[i][1], OPESYS_TYPE_LEN);
        /* Windows */
        if ((strstr (str, "Windows")) != NULL) {
            return conf.real_os && (b = get_real_win (a)) ? b : xstrdup (os[i][0]);
        }
        /* Android */
        if ((strstr (a, "Android")) != NULL) {
            a = parse_android (a);
            return conf.real_os ? get_real_android (a) : xstrdup (a);
        }
        /* Mac OS X */
        if ((strstr (a, "OS X")) != NULL) {
            a = parse_osx (a);
            return conf.real_os ? get_real_mac_osx (a) : xstrdup (a);
        }
        /* all others */
        spaces = count_matches (os[i][0], ' ');
        return alloc_string (parse_others (a, spaces));
    }
    xstrncpy (os_type, "Unknown", OPESYS_TYPE_LEN);

    return alloc_string ("Unknown");
}
コード例 #6
0
ファイル: ui.c プロジェクト: nwaldispuehl/goaccess
/* render a list of agents if available */
void
load_agent_list (WINDOW * main_win, char *addr)
{
  char buf[256];
  char *ptr_value;
  GAgents *agents = NULL;
  GMenu *menu;
  int c, quit = 1, delims = 0;
  int i, n = 0, alloc = 0;
  int y, x, list_h, list_w, menu_w, menu_h;
  void *value_ptr = NULL;
  WINDOW *win;

  if (!conf.list_agents)
    return;

  getmaxyx (stdscr, y, x);
  list_h = y / 2;       /* list window - height */
  list_w = x - 4;       /* list window - width */
  menu_h = list_h - AGENTS_MENU_Y - 1;  /* menu window - height */
  menu_w = list_w - AGENTS_MENU_X - AGENTS_MENU_X;      /* menu window - width */

#ifdef HAVE_LIBTOKYOCABINET
  value_ptr = tc_db_get_str (ht_hosts_agents, addr);
#else
  value_ptr = g_hash_table_lookup (ht_hosts_agents, addr);
#endif

  if (value_ptr != NULL) {
    ptr_value = (char *) value_ptr;
    delims = count_matches (ptr_value, '|');

    n = ((strlen (ptr_value) + menu_w - 1) / menu_w) + delims + 1;
    agents = new_gagents (n);
    alloc = split_agent_str (ptr_value, agents, menu_w);
#ifdef HAVE_LIBTOKYOCABINET
    free (value_ptr);
#endif
  }

  win = newwin (list_h, list_w, (y - list_h) / 2, (x - list_w) / 2);
  keypad (win, TRUE);
  wborder (win, '|', '|', '-', '-', '+', '+', '+', '+');

  /* create a new instance of GMenu and make it selectable */
  menu = new_gmenu (win, menu_h, menu_w, AGENTS_MENU_Y, AGENTS_MENU_X);

  /* add items to GMenu */
  menu->items = (GItem *) xcalloc (alloc, sizeof (GItem));
  for (i = 0; i < alloc; ++i) {
    menu->items[i].name = alloc_string (agents[i].agents);
    menu->items[i].checked = 0;
    menu->size++;
  }
  post_gmenu (menu);

  snprintf (buf, sizeof buf, "User Agents for %s", addr);
  draw_header (win, buf, " %s", 1, 1, list_w - 2, 1, 0);
  mvwprintw (win, 2, 2, "[UP/DOWN] to scroll - [q] to close window");

  wrefresh (win);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
     case KEY_DOWN:
       gmenu_driver (menu, REQ_DOWN);
       draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0);
       break;
     case KEY_UP:
       gmenu_driver (menu, REQ_UP);
       draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0);
       break;
     case KEY_RESIZE:
     case 'q':
       quit = 0;
       break;
    }
    wrefresh (win);
  }
  /* clean stuff up */
  for (i = 0; i < alloc; ++i)
    free (menu->items[i].name);
  free (menu->items);
  free (menu);

  for (i = 0; i < alloc; ++i)
    free (agents[i].agents);
  if (agents)
    free (agents);

  touchwin (main_win);
  close_win (win);
  wrefresh (main_win);
}
コード例 #7
0
ファイル: utility.hpp プロジェクト: PerryZh/stan
void expect_matches(int n,
                    const std::string& stan_code,
                    const std::string& target) {
  std::string model_cpp = model_to_cpp(stan_code);
  EXPECT_EQ(n, count_matches(target,model_cpp));
}
コード例 #8
0
ファイル: build_seed_index.c プロジェクト: gmcvicker/mcmapper
int main(int argc, char **argv) {
  char **fasta_files;
  int seed_len, i, n_fasta_files;
  ChrTable *chr_tab;
  SeedTable *seed_tab;
  Seq *seq;
  gzFile gzf, out_gzf;
  char *out_filename;
  
  if(argc < 4) {
    fprintf(stderr, "usage: %s <seed_len> <chromInfo.txt> "
	    "<output_seed_index.gz> [chr1.fa.gz [chr2.fa.gz [...]]]\n", 
	    argv[0]);
    exit(2);
  }
  
  
  seed_len = util_parse_long(argv[1]);

  fasta_files = &argv[4];
  n_fasta_files = argc - 4;
  out_filename = argv[3];

  /* read chromosomes and make table containing offsets for both
   * forward and reverse strands (so we can represent genomic
   * coordinates with a single long integer).
   */
  chr_tab = chr_table_read(argv[2]);
  fprintf(stderr, "there are %d chromosomes, total length: %u\n",
	  chr_tab->n_chr, chr_tab->total_chr_len);

  /* create a table to hold seed matches */
  fprintf(stderr, "initializing seed table\n");
  seed_tab = seed_table_new(seed_len);

  /* open an output file to write seed table to */
  if(util_file_exists(out_filename)) {
    my_err("output file %s already exists\n", out_filename);
    exit(2);
  }
  out_gzf = util_must_gzopen(out_filename, "wb");

  /*
   * first pass: count number of matches to each seed 
   */
  seq = seq_new();
  for(i = 0; i < n_fasta_files; i++) {
    fprintf(stderr, "reading sequence from file %s\n", fasta_files[i]);
    gzf = util_must_gzopen(fasta_files[i], "rb");
    while(seq_read_fasta_record(seq, gzf)) {
      fprintf(stderr, "%s %ld\n", seq->name, seq->len);
      fprintf(stderr, "counting seed matches\n");
      count_matches(chr_tab, seed_tab, seq);
    }
    gzclose(gzf);
  }

  /*
   * second pass: store location of each match
   */
  for(i = 0; i < n_fasta_files; i++) {
    fprintf(stderr, "reading sequence from file %s\n", fasta_files[i]);
    gzf = util_must_gzopen(fasta_files[i], "rb");
    while(seq_read_fasta_record(seq, gzf)) {
      fprintf(stderr, "%s %ld\n", seq->name, seq->len);
      fprintf(stderr, "recording seed match positions\n");
      add_matches(chr_tab, seed_tab, seq);
    }
    gzclose(gzf);
  }

  seq_free(seq);

  /* write table to file in binary format */
  fprintf(stderr, "writing seed table to file %s\n", out_filename);
  seed_table_write(seed_tab, out_gzf);
  gzclose(out_gzf);

  chr_table_free(chr_tab);
  seed_table_free(seed_tab);
  
  return 0;
}
コード例 #9
0
ファイル: parser.c プロジェクト: fourks/goaccess
static int
parse_format (GLogItem * glog, const char *fmt, const char *date_format,
              char *str)
{
  const char *p;
  double serve_secs;
  int special = 0;
  struct tm tm;
  unsigned long long bandw, serve_time;

  if (str == NULL || *str == '\0')
    return 1;

  memset (&tm, 0, sizeof (tm));

  /* iterate over the log format */
  for (p = fmt; *p; p++) {
    if (*p == '%') {
      special++;
      continue;
    }
    if (special && *p != '\0') {
      char *pch, *sEnd, *bEnd, *tkn = NULL, *end = NULL;
      errno = 0;
      bandw = 0;
      serve_time = 0;
      serve_secs = 0;

      switch (*p) {
         /* date */
       case 'd':
         if (glog->date)
           return 1;
         /* parse date format including dates containing spaces,
          * i.e., syslog date format (Jul 15 20:10:56) */
         tkn = parse_string (&str, p[1], count_matches (date_format, ' ') + 1);
         if (tkn == NULL)
           return 1;
         end = strptime (tkn, date_format, &tm);
         if (end == NULL || *end != '\0') {
           free (tkn);
           return 1;
         }
         glog->date = tkn;
         break;
         /* remote hostname (IP only) */
       case 'h':
         if (glog->host)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         if (invalid_ipaddr (tkn)) {
           free (tkn);
           return 1;
         }
         glog->host = tkn;
         break;
         /* request method */
       case 'm':
         if (glog->method)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         if (!extract_method (tkn)) {
           free (tkn);
           return 1;
         }
         glog->method = tkn;
         break;
         /* request not including method or protocol */
       case 'U':
         if (glog->req)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL || *tkn == '\0')
           return 1;
         if ((glog->req = decode_url (tkn)) == NULL)
           return 1;
         free (tkn);
         break;
         /* request protocol */
       case 'H':
         if (glog->protocol)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         if (invalid_protocol (tkn)) {
           free (tkn);
           return 1;
         }
         glog->protocol = tkn;
         break;
         /* request, including method + protocol */
       case 'r':
         if (glog->req)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         glog->req = parse_req (tkn, &glog->method, &glog->protocol);
         free (tkn);
         break;
         /* Status Code */
       case 's':
         if (glog->status)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         strtol (tkn, &sEnd, 10);
         if (tkn == sEnd || *sEnd != '\0' || errno == ERANGE) {
           free (tkn);
           return 1;
         }
         glog->status = tkn;
         break;
         /* size of response in bytes - excluding HTTP headers */
       case 'b':
         if (glog->resp_size)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         bandw = strtol (tkn, &bEnd, 10);
         if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE)
           bandw = 0;
         glog->resp_size = bandw;
         conf.bandwidth = 1;
         free (tkn);
         break;
         /* referrer */
       case 'R':
         if (glog->ref)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           tkn = alloc_string ("-");
         if (tkn != NULL && *tkn == '\0') {
           free (tkn);
           tkn = alloc_string ("-");
         }
         if (strcmp (tkn, "-") != 0)
           extract_referer_site (tkn, glog->site);
         glog->ref = tkn;
         break;
         /* user agent */
       case 'u':
         if (glog->agent)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn != NULL && *tkn != '\0') {
           /* Make sure the user agent is decoded (i.e.: CloudFront)
            * and replace all '+' with ' ' (i.e.: w3c) */
           glog->agent = char_replace (decode_url (tkn), '+', ' ');
           free (tkn);
           break;
         } else if (tkn != NULL && *tkn == '\0') {
           free (tkn);
           tkn = alloc_string ("-");
         }
         /* must be null */
         else {
           tkn = alloc_string ("-");
         }
         glog->agent = tkn;
         break;
         /* time taken to serve the request, in seconds */
       case 'T':
         if (glog->serve_time)
           return 1;
         /* ignore seconds if we have microseconds */
         if (strstr (fmt, "%D") != NULL)
           break;

         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         if (strchr (tkn, '.') != NULL)
           serve_secs = strtod (tkn, &bEnd);
         else
           serve_secs = strtoull (tkn, &bEnd, 10);

         if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE)
           serve_secs = 0;
         /* convert it to microseconds */
         if (serve_secs > 0)
           glog->serve_time = serve_secs * SECS;
         else
           glog->serve_time = 0;
         conf.serve_usecs = 1;
         free (tkn);
         break;
         /* time taken to serve the request, in microseconds */
       case 'D':
         if (glog->serve_time)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         serve_time = strtoull (tkn, &bEnd, 10);
         if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE)
           serve_time = 0;
         glog->serve_time = serve_time;
         conf.serve_usecs = 1;
         free (tkn);
         break;
         /* everything else skip it */
       default:
         if ((pch = strchr (str, p[1])) != NULL)
           str += pch - str;
      }
      if ((str == NULL) || (*str == '\0'))
        return 0;
      special = 0;
    } else if (special && isspace (p[0])) {
      return 1;
    } else
      str++;
  }
  return 0;
}