Esempio n. 1
0
    /* configuration-dependent initialization */
int main_configure(char *arg1, char *arg2) {
    if(options_cmdline(arg1, arg2))
        return 1;
    options_apply();
    str_canary_init(); /* needs prng initialization from options_cmdline */
#if !defined(USE_WIN32) && !defined(__vms)
    /* syslog_open() must be called before change_root()
     * to be able to access /dev/log socket */
    syslog_open();
#endif /* !defined(USE_WIN32) && !defined(__vms) */
    if(bind_ports())
        return 1;

#ifdef HAVE_CHROOT
    /* change_root() must be called before drop_privileges()
     * since chroot() needs root privileges */
    if(change_root())
        return 1;
#endif /* HAVE_CHROOT */

    if(drop_privileges(1))
        return 1;

    /* log_open() must be be called after drop_privileges()
     * or logfile rotation won't be possible */
    /* log_open() must be be called before daemonize()
     * since daemonize() invalidates stderr */
    if(log_open())
        return 1;
#ifndef USE_FORK
    num_clients=0; /* the first valid config */
#endif
    return 0;
}
Esempio n. 2
0
int
main( int argc, char *argv[] )
{
   FILE       *out_a, *out_b;
   char       *h1, *h2, *s, *q;
   char       *id = NULL;
   char       *outname_a = NULL, *outname_b = NULL, *outdirname = NULL;
   int         i;
   struct options *o = options_new(  );
   struct tokenset *t = tokenset_new(  );
   struct fqreader *fq = fqreader_new( NULL );

   /* Get the command line options */
   options_cmdline( o, argc, argv );

   if ( _IS_NULL( o->outname ) || strlen( o->outname ) == 0 ) {
      o->outname = realloc( o->outname, 4 * sizeof ( char ) );
      strcpy( o->outname, "FQU" );
   }

   /* Create the output directory if necessary */
   outdirname = realloc( outdirname, sizeof ( char ) * ( 2 + strlen( o->outname ) ) );
   strcpy( outdirname, o->outname );
   if ( strchr( outdirname, '/' ) ) {            /* not the current directory */
      dirname( outdirname );
      mkdirp( outdirname, S_IRWXU | S_IRWXG | S_IRWXO );
   }


   /* Read the id files */
   for ( i = o->optind; i < argc; i++ ) {

      char       *line;
      struct linereader *z = linereader_new(  );

      linereader_init( z, argv[i] );

      if ( _IS_NULL( z ) ) {
         fprintf( stderr, "[ERROR] %s: Cannot open input file \"%s\"\n", _I_AM, argv[i] );
         exit( 1 );
      }

      while ( ( line = ( char * ) linereader_next( z ) ) ) {
         unsigned    len;

         stru_trim( line );

         if ( line[0] == '#' || stru_is_ws( line ) )
            continue;

         len = strcspn( line, "\f\n\r\t\v " );
         line[len] = '\0';

         tokenset_add( t, line );
      }

      linereader_free( z );
   }

   outname_a = realloc( outname_a, sizeof ( char ) * ( 6 + strlen( o->outname ) ) );
   strcpy( outname_a, o->outname );
   strcat( outname_a, "_A.fq" );
   out_a = fopen( outname_a, "wb" );
   if ( _IS_NULL( out_a ) ) {
      fprintf( stderr, "Could not open first output file \"%s\"\n", outname_a );
      exit( 1 );
   }

   outname_b = realloc( outname_b, sizeof ( char ) * ( 6 + strlen( o->outname ) ) );
   strcpy( outname_b, o->outname );
   strcat( outname_b, "_B.fq" );
   out_b = fopen( outname_b, "wb" );
   if ( _IS_NULL( out_b ) ) {
      fprintf( stderr, "Could not open second output file \"%s\"\n", outname_b );
      exit( 1 );
   }


   while ( fqreader_next( fq, &h1, &h2, &s, &q ) ) {

      utils_extract_id( &id, h1 );               /* get the identifier from header 1 */

      if ( tokenset_exists( t, id ) )
         fprintf( out_a, "@%s\n%s\n+%s\n%s\n", h1, s, h2, q );

      else
         fprintf( out_b, "@%s\n%s\n+%s\n%s\n", h1, s, h2, q );
   }

   fclose( out_a );
   fclose( out_b );

   _FREE( id );
   _FREE( outname_a );
   _FREE( outname_b );
   fqreader_free( fq );
   options_free( o );
   tokenset_free( t );

   return 0;
}
Esempio n. 3
0
int
main( int argc, char *argv[] )
{
   char       *h1, *h2, *s, *q;
   unsigned    i;
   unsigned    n;
   struct options *o = options_new(  );
   struct fqreader *z;

   /* Get the command line options */
   options_cmdline( o, argc, argv );

   words = tokenset_new(  );
   word = realloc( word, sizeof ( char ) * ( 1 + o->word_size ) );

   if ( o->optind == argc ) {                    /* read from stdin */

      z = fqreader_new( NULL );

      while ( fqreader_next( z, &h1, &h2, &s, &q ) ) {
         stru_toupper( s );
         _update_table( o->word_size, s, o->check_initial );
      }

      fqreader_free( z );
   }

   else {                                        /* read from input files */
      int         k;

      for ( k = o->optind; k < argc; k++ ) {

         z = fqreader_new( argv[k] );

         if ( _IS_NULL( z ) ) {
            fprintf( stderr, "[ERROR] %s: Cannot open input file \"%s\"\n", _I_AM, argv[k] );
            exit( 1 );
         }

         while ( fqreader_next( z, &h1, &h2, &s, &q ) ) {
            stru_toupper( s );
            _update_table( o->word_size, s, o->check_initial );
         }

         fqreader_free( z );
      }
   }

   /* Print the countlist */

   n = tokenset_count( words );

   for ( i = 0; i < n; i++ ) {
      if ( countlist[i].count < o->min_count )
         continue;
      printf( "%s\t%d\n", tokenset_get_by_id( words, countlist[i].id ), countlist[i].count );
   }

   options_free( o );
   tokenset_free( words );
   _FREE( word );
   _FREE( countlist );

   return 0;
}