예제 #1
0
/* ------------------------------------------------------------------ die --- */
int
die(const char *inst_name, const char *format, ...)
{
   char     buf[BUFSIZE];
   va_list  args;

   va_start(args, format);
   vsnprintf(buf, BUFSIZE, format, args);
   va_end(args);

#ifndef MAXMSP
   if (inst_name)
      fprintf(stderr, PREFIX "FATAL ERROR [%s]:  %s\n", inst_name, buf);
   else
      fprintf(stderr, PREFIX "FATAL ERROR:  %s\n", buf);

#else // MAXMSP
   if (inst_name) {
      int nchars = sprintf(get_mm_print_ptr(), "FATAL ERROR [%s]:  %s\n", inst_name, buf);
      set_mm_print_ptr(nchars+1);
   }
   else {
      int nchars = sprintf(get_mm_print_ptr(), "FATAL ERROR:  %s\n", buf);
   }
#endif // MAXMSP

   if (get_bool_option(kOptionExitOnError)) {
      if (!rtsetparams_was_called())
         closesf_noexit();
      exit(1);
      return 0;	/*NOTREACHED*/
   }
   else
      return DONT_SCHEDULE;
}
예제 #2
0
static rc_t gather_2_bool( Args * args, const char *name1, const char *name2, bool *b1, bool *b2 )
{
    rc_t rc = get_bool_option( args, name1, b1 );
    if ( rc != 0 ) return rc;

    rc = get_bool_option( args, name2, b2 );
    if ( rc != 0 ) return rc;

    if ( *b1 && *b2 )
    {
        rc = RC( rcExe, rcNoTarg, rcValidating, rcParam, rcInvalid );
        (void)PLOGERR( klogErr, ( klogErr, rc, "the parameters '--$(p1)' and '--$(p2)' are mutually exclusive", 
                      "p1=%s,p2=%s", name1, name2 ) );
    }
    return rc;
}
예제 #3
0
void spiceqxl_uinput_init(qxl_screen_t *qxl)
{
    int ret;
    int enabled;

    uinput_filename = get_str_option(qxl->options, OPTION_SPICE_VDAGENT_UINPUT_PATH,
               "XSPICE_VDAGENT_UINPUT_PATH");
    enabled = get_bool_option(qxl->options, OPTION_SPICE_VDAGENT_ENABLED, "XSPICE_VDAGENT_ENABLED");

    if (!enabled || uinput_filename == NULL) {
        return;
    }
    ret = mkfifo(uinput_filename, 0666);
    if (ret != 0) {
        fprintf(stderr, "spice: failed to create uinput fifo %s: %s\n",
                uinput_filename, strerror(errno));
        return;
    }
    spiceqxl_chown_agent_file(qxl, uinput_filename);
    uinput_fd = open(uinput_filename, O_RDONLY | O_NONBLOCK, 0666);
    if (uinput_fd == -1) {
        fprintf(stderr, "spice: failed creating uinput file %s: %s\n",
               uinput_filename, strerror(errno));
        return;
    }
}
예제 #4
0
static rc_t get_tool_options( Args * args, tool_options * options )
{
    uint32_t idx, count;

    rc_t rc = ArgsParamCount( args, &count );
    if ( rc != 0 )
    {
        PLOGERR( klogErr, ( klogErr, rc,
                 "ArgsParamCount() failed in $(func)", "func=%s", __func__ ) );
    }
    else if ( count > 0 )
    {
        for ( idx = 0; idx < count && rc == 0; ++idx )
        {
            const char *value = NULL;
            rc = ArgsParamValue( args, idx, &value );
            if ( rc != 0 )
            {
                PLOGERR( klogErr, ( klogErr, rc,
                         "ArgsParamValue( $(idx) ) failed in $(func)", "idx=%d,func=%s", idx, __func__ ) );
            }
            else if ( value != NULL )
                rc = add_tool_options_path( options, value );
        }
    }

    options->main_function = tf_unknown;
    options->detailed = get_bool_option( args, OPTION_DETAIL );
	options->tstzero = get_bool_option( args, OPTION_TSTZERO );
    options->remove_dirs = get_bool_option( args, OPTION_REMDIR );

    if ( get_bool_option( args, OPTION_CREPORT ) )
        options->main_function = tf_report;
    else if ( get_bool_option( args, OPTION_RREPORT ) )
        options->main_function = tf_rreport;
    else if ( get_bool_option( args, OPTION_UNLOCK ) )
        options->main_function = tf_unlock;
    else if ( get_bool_option( args, OPTION_CLEAR ) )
        options->main_function = tf_clear;
    else
    {
        options->category = get_repo_select( args, OPTION_ENABLE );
        if ( options->category != krepBadCategory )
            options->main_function = tf_enable;

        if ( options->category == krepBadCategory )
        {
            options->category = get_repo_select( args, OPTION_DISABLE );
            if ( options->category != krepBadCategory )
                options->main_function = tf_disable;
        }
    }

    if ( rc == 0 )
        rc = get_user_repo_name( args, &options->user_repo_name );
    if ( rc == 0 )
        rc = get_max_remove( args, &options->max_remove );
    return rc;
}
예제 #5
0
rc_t get_common_options( Args * args, common_options *opts )
{
    rc_t rc = get_str_option( args, OPTION_OUTF, &opts->output_file );

    if ( rc == 0 )
        rc = get_str_option( args, OPTION_INF, &opts->input_file );

    if ( rc == 0 )
        rc = get_bool_option( args, OPTION_GZIP, &opts->gzip_output, false );

    if ( rc == 0 )
        rc = get_bool_option( args, OPTION_BZIP, &opts->bzip_output, false );

    if ( rc == 0 )
        rc = get_bool_option( args, OPTION_NO_MT, &opts->no_mt, false );
        
    if ( rc == 0 )
        rc = get_str_option( args, OPTION_SCHEMA, &opts->schema_file );

    if ( rc == 0 )
    {
        const char * table2use = NULL;
        rc = get_str_option( args, OPTION_TABLE, &table2use );
        opts->tab_select = primary_ats;
        if ( rc == 0 && table2use != NULL )
        {
            size_t l = string_size ( table2use );
            opts->tab_select = 0;
            if ( ( string_chr ( table2use, l, 'p' ) != NULL )||
                 ( string_chr ( table2use, l, 'P' ) != NULL ) )
            { opts->tab_select |= primary_ats; };

            if ( ( string_chr ( table2use, l, 's' ) != NULL )||
                 ( string_chr ( table2use, l, 'S' ) != NULL ) )
            { opts->tab_select |= secondary_ats; };

            if ( ( string_chr ( table2use, l, 'e' ) != NULL )||
                 ( string_chr ( table2use, l, 'E' ) != NULL ) )
            { opts->tab_select |= evidence_ats; };
        }
    }

    return rc;
}
예제 #6
0
void
closesf()
{
	int i;

	for(i = 0; i<NFILES; i++) {
		if(isopen[i]) {
			if (status[i]) 
				putlength(sfname[i], sfd[i], &sfdesc[i]);
			close(sfd[i]);
		}
	}

	if (get_bool_option(kOptionExitOnError))
		exit(1);
}
예제 #7
0
파일: flock.c 프로젝트: deepfryed/flock
/* @api private */
VALUE rb_do_kcluster(int argc, VALUE *argv, VALUE self) {
    VALUE size, data, mask, weights, options;
    rb_scan_args(argc, argv, "21", &size, &data, &options);

    if (TYPE(data) != T_ARRAY)
        rb_raise(rb_eArgError, "data should be an array of arrays");

    if (NIL_P(size) || NUM2INT(rb_Integer(size)) > RARRAY_LEN(data))
        rb_raise(rb_eArgError, "size should be > 0 and <= data size");

    mask = get_value_option(options, "mask", Qnil);

    if (!NIL_P(mask) && TYPE(mask) != T_ARRAY)
        rb_raise(rb_eArgError, "mask should be an array of arrays");

    int transpose = get_bool_option(options, "transpose", 0);
    int npass     = get_int_option(options, "iterations", DEFAULT_ITERATIONS);

    // a = average, m = means
    int method    = get_int_option(options, "method", 'a');

    // e = euclidian,
    // b = city-block distance
    // c = correlation
    // a = absolute value of the correlation
    // u = uncentered correlation
    // x = absolute uncentered correlation
    // s = spearman's rank correlation
    // k = kendall's tau
    int dist      = get_int_option(options, "metric", 'e');

    // initial assignment
    int assign    = get_int_option(options, "seed",    0);

    int i,j;
    int nrows = RARRAY_LEN(data);
    int ncols = RARRAY_LEN(rb_ary_entry(data, 0));
    int nsets = NUM2INT(rb_Integer(size));

    double **cdata          = (double**)malloc(sizeof(double*)*nrows);
    int    **cmask          = (int   **)malloc(sizeof(int   *)*nrows);
    double *cweights        = (double *)malloc(sizeof(double )*ncols);

    double **ccentroid;
    int *ccluster, **ccentroid_mask, dimx = nrows, dimy = ncols, cdimx = nsets, cdimy = ncols;

    for (i = 0; i < nrows; i++) {
        cdata[i]          = (double*)malloc(sizeof(double)*ncols);
        cmask[i]          = (int   *)malloc(sizeof(int   )*ncols);
        for (j = 0; j < ncols; j++) {
            cdata[i][j] = NUM2DBL(rb_Float(rb_ary_entry(rb_ary_entry(data, i), j)));
            cmask[i][j] = NIL_P(mask) ? 1 : NUM2INT(rb_Integer(rb_ary_entry(rb_ary_entry(mask, i), j)));
        }
    }

    weights = NIL_P(options) ? Qnil : rb_hash_aref(options, ID2SYM(rb_intern("weights")));
    for (i = 0; i < ncols; i++) {
        cweights[i] = NIL_P(weights) ? 1.0 : NUM2DBL(rb_Float(rb_ary_entry(weights, i)));
    }

    if (transpose) {
        dimx  = ncols;
        dimy  = nrows;
        cdimx = nrows;
        cdimy = nsets;
    }

    ccluster       = (int    *)malloc(sizeof(int    )*dimx);
    ccentroid      = (double**)malloc(sizeof(double*)*cdimx);
    ccentroid_mask = (int   **)malloc(sizeof(int   *)*cdimx);

    for (i = 0; i < cdimx; i++) {
      ccentroid[i]      = (double*)malloc(sizeof(double)*cdimy);
      ccentroid_mask[i] = (int   *)malloc(sizeof(int   )*cdimy);
    }

    int    ifound;
    double error;

    kcluster(nsets,
        nrows, ncols, cdata, cmask, cweights, transpose, npass, method, dist, ccluster, &error, &ifound, assign);
    getclustercentroids(nsets,
        nrows, ncols, cdata, cmask, ccluster, ccentroid, ccentroid_mask, transpose, method);

    VALUE result   = rb_hash_new();
    VALUE cluster  = rb_ary_new();
    VALUE centroid = rb_ary_new();

    for (i = 0; i < dimx; i++)
        rb_ary_push(cluster, INT2NUM(ccluster[i]));

    for (i = 0; i < cdimx; i++) {
        VALUE point = rb_ary_new();
        for (j = 0; j < cdimy; j++)
            rb_ary_push(point, DBL2NUM(ccentroid[i][j]));
        rb_ary_push(centroid, point);
    }

    rb_hash_aset(result, ID2SYM(rb_intern("cluster")),   cluster);
    rb_hash_aset(result, ID2SYM(rb_intern("centroid")),  centroid);
    rb_hash_aset(result, ID2SYM(rb_intern("error")),     DBL2NUM(error));
    rb_hash_aset(result, ID2SYM(rb_intern("repeated")),  INT2NUM(ifound));

    for (i = 0; i < nrows; i++) {
        free(cdata[i]);
        free(cmask[i]);
    }

    for (i = 0; i < cdimx; i++) {
        free(ccentroid[i]);
        free(ccentroid_mask[i]);
    }

    free(cdata);
    free(cmask);
    free(ccentroid);
    free(ccentroid_mask);
    free(cweights);
    free(ccluster);

    return result;
}
void xspice_set_spice_server_options(OptionInfoPtr options)
{
    /* environment variables take precedense. If not then take
     * parameters from the config file. */
    int addr_flags;
    int len;
    spice_image_compression_t compression;
    spice_wan_compression_t wan_compr;
    int port = get_int_option(options, OPTION_SPICE_PORT, "XSPICE_PORT");
    int tls_port =
        get_int_option(options, OPTION_SPICE_TLS_PORT, "XSPICE_TLS_PORT");
    const char *password =
        get_str_option(options, OPTION_SPICE_PASSWORD, "XSPICE_PASSWORD");
    int disable_ticketing =
        get_bool_option(options, OPTION_SPICE_DISABLE_TICKETING, "XSPICE_DISABLE_TICKETING");
    const char *x509_dir =
        get_str_option(options, OPTION_SPICE_X509_DIR, "XSPICE_X509_DIR");
    int sasl = get_bool_option(options, OPTION_SPICE_SASL, "XSPICE_SASL");
    const char *x509_key_file_base =
        get_str_option(options, OPTION_SPICE_X509_KEY_FILE,
                       "XSPICE_X509_KEY_FILE");
    char *x509_key_file = NULL;
    const char *x509_cert_file_base =
        get_str_option(options, OPTION_SPICE_X509_CERT_FILE,
                       "XSPICE_X509_CERT_FILE");
    char *x509_cert_file = NULL;
    const char *x509_key_password =
        get_str_option(options, OPTION_SPICE_X509_KEY_PASSWORD,
                    "XSPICE_X509_KEY_PASSWORD");
    const char *tls_ciphers =
        get_str_option(options, OPTION_SPICE_TLS_CIPHERS,
                    "XSPICE_TLS_CIPHERS");
    const char *x509_cacert_file_base =
        get_str_option(options, OPTION_SPICE_CACERT_FILE,
                    "XSPICE_CACERT_FILE");
    char *x509_cacert_file = NULL;
    const char * addr =
        get_str_option(options, OPTION_SPICE_ADDR, "XSPICE_ADDR");
    int ipv4 =
        get_bool_option(options, OPTION_SPICE_IPV4_ONLY, "XSPICE_IPV4_ONLY");
    int ipv6 =
        get_bool_option(options, OPTION_SPICE_IPV6_ONLY, "XSPICE_IPV6_ONLY");
    const char *x509_dh_file =
        get_str_option(options, OPTION_SPICE_DH_FILE, "XSPICE_DH_FILE");
    int disable_copy_paste =
        get_bool_option(options, OPTION_SPICE_DISABLE_COPY_PASTE,
                        "XSPICE_DISABLE_COPY_PASTE");
    const char *image_compression =
        get_str_option(options, OPTION_SPICE_IMAGE_COMPRESSION,
                       "XSPICE_IMAGE_COMPRESSION");
    const char *jpeg_wan_compression =
        get_str_option(options, OPTION_SPICE_JPEG_WAN_COMPRESSION,
                       "XSPICE_JPEG_WAN_COMPRESSION");
    const char *zlib_glz_wan_compression =
        get_str_option(options, OPTION_SPICE_ZLIB_GLZ_WAN_COMPRESSION,
                       "XSPICE_ZLIB_GLZ_WAN_COMPRESSION");
    const char *streaming_video =
        get_str_option(options, OPTION_SPICE_STREAMING_VIDEO,
                       "XSPICE_STREAMING_VIDEO");
    int agent_mouse =
        get_bool_option(options, OPTION_SPICE_AGENT_MOUSE,
                        "XSPICE_AGENT_MOUSE");
    int playback_compression =
        get_bool_option(options, OPTION_SPICE_PLAYBACK_COMPRESSION,
                        "XSPICE_PLAYBACK_COMPRESSION");

    SpiceServer *spice_server = xspice_get_spice_server();

    if (!port && !tls_port) {
        printf("one of tls-port or port must be set\n");
        exit(1);
    }
    printf("xspice: port = %d, tls_port = %d\n", port, tls_port);
    spice_server_set_port(spice_server, port);
    if (disable_ticketing) {
        spice_server_set_noauth(spice_server);
    }
    if (tls_port) {
        if (NULL == x509_dir) {
            x509_dir = ".";
        }
        len = strlen(x509_dir) + 32;

        if (x509_key_file_base) {
            x509_key_file = strdup(x509_key_file_base);
        } else {
            x509_key_file = malloc(len);
            snprintf(x509_key_file, len, "%s/%s", x509_dir, X509_SERVER_KEY_FILE);
        }

        if (x509_cert_file_base) {
            x509_cert_file = strdup(x509_cert_file_base);
        } else {
            x509_cert_file = malloc(len);
            snprintf(x509_cert_file, len, "%s/%s", x509_dir, X509_SERVER_CERT_FILE);
        }

        if (x509_cacert_file_base) {
            x509_cacert_file = strdup(x509_cert_file_base);
        } else {
            x509_cacert_file = malloc(len);
            snprintf(x509_cacert_file, len, "%s/%s", x509_dir, X509_CA_CERT_FILE);
        }
    }

    addr_flags = 0;
    if (ipv4) {
        addr_flags |= SPICE_ADDR_FLAG_IPV4_ONLY;
    } else if (ipv6) {
        addr_flags |= SPICE_ADDR_FLAG_IPV6_ONLY;
    }

    spice_server_set_addr(spice_server, addr ? addr : "", addr_flags);
    if (port) {
        spice_server_set_port(spice_server, port);
    }
    if (tls_port) {
        spice_server_set_tls(spice_server, tls_port,
                             x509_cacert_file,
                             x509_cert_file,
                             x509_key_file,
                             x509_key_password,
                             x509_dh_file,
                             tls_ciphers);
    }
    if (password) {
        spice_server_set_ticket(spice_server, password, 0, 0, 0);
    }
    if (sasl) {
#if SPICE_SERVER_VERSION >= 0x000802 /* 0.8.2 */
        if (spice_server_set_sasl_appname(spice_server, "xspice") == -1 ||
            spice_server_set_sasl(spice_server, 1) == -1) {
            fprintf(stderr, "spice: failed to enable sasl\n");
            exit(1);
        }
#else
        fprintf(stderr, "spice: sasl is not available (spice >= 0.8.2 required)\n");
        exit(1);
#endif
    }
    if (disable_ticketing) {
        spice_server_set_noauth(spice_server);
    }

#if SPICE_SERVER_VERSION >= 0x000801
    /* we still don't actually support agent in xspice, but this
     * can't hurt for later, just copied from qemn/ui/spice-core.c */
    if (disable_copy_paste) {
        spice_server_set_agent_copypaste(spice_server, 0);
    }
#endif

    compression = SPICE_IMAGE_COMPRESS_AUTO_GLZ;
    if (image_compression) {
        compression = parse_compression(image_compression);
    }
    spice_server_set_image_compression(spice_server, compression);

    wan_compr = SPICE_WAN_COMPRESSION_AUTO;
    if (jpeg_wan_compression) {
        wan_compr = parse_wan_compression(jpeg_wan_compression);
    }
    spice_server_set_jpeg_compression(spice_server, wan_compr);

    wan_compr = SPICE_WAN_COMPRESSION_AUTO;
    if (zlib_glz_wan_compression) {
        wan_compr = parse_wan_compression(zlib_glz_wan_compression);
    }
    spice_server_set_zlib_glz_compression(spice_server, wan_compr);

    if (streaming_video) {
        int streaming_video_opt = parse_stream_video(streaming_video);
        spice_server_set_streaming_video(spice_server, streaming_video_opt);
    }

    spice_server_set_agent_mouse
        (spice_server, agent_mouse);
    spice_server_set_playback_compression
        (spice_server, playback_compression);

    free(x509_key_file);
    free(x509_cert_file);
    free(x509_cacert_file);
}
예제 #9
0
void display_cow(bool debug, const char *text, bool run_main, cowmode_t mode)
{
   GdkScreen *screen = gdk_screen_get_default();

   gint n_monitors = gdk_screen_get_n_monitors(screen);

   gint pick = get_int_option("monitor");
   if (pick < 0 || pick >= n_monitors)
      pick = random() % n_monitors;
   
   GdkRectangle geom;
   gdk_screen_get_monitor_geometry(screen, pick, &geom);

   xcowsay.screen_width = geom.width;
   xcowsay.screen_height = geom.height;

   g_assert(xcowsay.cow_pixbuf);
   xcowsay.cow = make_shape_from_pixbuf(xcowsay.cow_pixbuf);

   switch (mode) {
   case COWMODE_NORMAL:
   case COWMODE_THINK:
      normal_setup(text, debug, mode);
      break;
   case COWMODE_DREAM:
      dream_setup(text, debug);
      break;
   default:
      fprintf(stderr, "Error: Unsupported cow mode %d\n", mode);
      exit(1);
   }
   
   xcowsay.bubble = make_shape_from_pixbuf(xcowsay.bubble_pixbuf);   
   
   int total_width = shape_width(xcowsay.cow)
      + get_int_option("bubble_x")
      + xcowsay.bubble_width;
   int total_height = max(shape_height(xcowsay.cow), xcowsay.bubble_height);

   int bubble_off = max((xcowsay.bubble_height - shape_height(xcowsay.cow))/2, 0);

   int area_w = xcowsay.screen_width - total_width;
   int area_h = xcowsay.screen_height - total_height;

   // Fit the cow on the screen as best as we can
   // The area can't be be zero or we'd get an FPE
   if (area_w < 1)
      area_w = 1;
   if (area_h < 1)
      area_h = 1;

   int cow_x = get_int_option("at_x");
   if (cow_x < 0)
      cow_x = random() % area_w;
   else if (cow_x >= area_w)
      cow_x = area_w - 1;
   
   int cow_y = get_int_option("at_y");
   if (cow_y < 0)
      cow_y = random() % area_h;
   else if (cow_y >= area_h)
      cow_y = area_h - 1;

   if (get_bool_option("left")) {
      move_shape(xcowsay.cow,
                 geom.x + cow_x + xcowsay.bubble_width,
                 geom.y + bubble_off + cow_y);
      show_shape(xcowsay.cow);
      
      int bx = shape_x(xcowsay.cow) - xcowsay.bubble_width
         + get_int_option("bubble_x");
      int by = shape_y(xcowsay.cow)
         + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2
         + get_int_option("bubble_y");
      move_shape(xcowsay.bubble, bx, by);
   }
   else {
      move_shape(xcowsay.cow,
                 geom.x + cow_x,
                 geom.y + bubble_off + cow_y);
      show_shape(xcowsay.cow);
      
      int bx = shape_x(xcowsay.cow) + shape_width(xcowsay.cow)
         + get_int_option("bubble_x");
      int by = shape_y(xcowsay.cow)
         + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2
         + get_int_option("bubble_y");
      move_shape(xcowsay.bubble, bx, by);
   }
      
   xcowsay.state = csLeadIn;
   xcowsay.transition_timeout = get_int_option("lead_in_time");
   g_timeout_add(TICK_TIMEOUT, tick, NULL);

   close_when_clicked(xcowsay.cow);
   
   if (run_main)
      gtk_main();

   g_object_unref(xcowsay.bubble_pixbuf);
   xcowsay.bubble_pixbuf = NULL;
}
/* This routine is used in the Minc score to open up a file for
   writing by RT instruments.  pp[0] is a pointer to the soundfile
   name, disguised as a double by the crafty Minc.  (p[] is passed in
   just for fun.)  Optional string arguments follow the filename,
   and parse_rtoutput_args processes these. See the comment at the
   top of this file for the meaning of these arguments.

   If "clobber" mode is on, we delete an existing file with the
   specified file name, creating a header according to what
   parse_rtoutput_args determines.

   Returns -1.0 if a file is already open for writing. Dies if there
   is any other error.
*/
double
RTcmix::rtoutput(float p[], int n_args, double pp[])
{
   int         error;
   struct stat statbuf;

   if (rtfileit == 1) {
      rterror("rtoutput", "A soundfile is already open for writing...");
      return -1;
   }

   /* flag set to -1 until we reach end of function.  This way, if anything
      fails along the way, we leave this set as we want it.
   */
   rtfileit = -1;

   if (SR == 0) {
      die("rtoutput", "You must call rtsetparams before rtoutput.");
      return -1;
   }

   error = parse_rtoutput_args(n_args, pp);
   if (error)
      return -1;          /* already reported in parse_rtoutput_args */

   error = stat(rtoutsfname, &statbuf);

   if (error) {
      if (errno == ENOENT) { 
         ;              /* File doesn't exist -- no problem */
      }
      else {
         rterror("rtoutput", "Error accessing file \"%s\": %s",
                                                rtoutsfname, strerror(errno));
         return -1;  /* was exit() */
      }
   }
   else {               /* File exists; find out whether we can clobber it */
      if (!get_bool_option(kOptionClobber)) {
         rterror("rtoutput", "\n%s", CLOBBER_WARNING);
         return -1;
      }
      else {
         /* make sure it's a regular file */
		  //JRG commented out!
         //if (!S_ISREG(statbuf.st_mode)) {
         //   rterror("rtoutput", "\"%s\" isn't a regular file; won't clobber it",
         //                                                        rtoutsfname);
         //   return -1;
         //}
      }
   }

   // If user has chosen to turn off audio playback, we delete
   // the device that might have been created during rtsetparams().
   if (!Option::record() && !Option::play()) {
       delete audioDevice;
	   audioDevice = NULL;
   }
   AudioDevice *dev;
   if ((dev = create_audio_file_device(audioDevice,
				   				rtoutsfname, output_header_type,
                                output_data_format, NCHANS, SR,
                                normalize_output_floats,
                                get_bool_option(kOptionCheckPeaks))) == NULL)
      return -1;  /* failed! */

   audioDevice = dev;

   rtfileit = 1;  /* here we finally set this to 1 */

   return 1;
}
예제 #11
0
파일: cadaver.c 프로젝트: grimneko/cadaver
static void notifier(void *ud, ne_session_status status, const ne_session_status_info *info)
{
    int quiet = get_bool_option(opt_quiet);

    switch (out_state) {
    case out_none:
        if (quiet) break;

	switch (status) {
	case ne_status_lookup:
	    printf(_("Looking up hostname... "));
	    break;
	case ne_status_connecting:
	    printf(_("Connecting to server... "));
	    break;
	case ne_status_connected:
	    printf(_("connected.\n"));
	    break;
        default:
            break;
	}
	break;
    case out_incommand:
    case out_transfer_upload:
    case out_transfer_download:
    case out_transfer_done:
	switch (status) {
	case ne_status_connecting:
            if (!quiet) printf(_(" (reconnecting..."));
            /* FIXME: should reset out_state here if transfer_done */
	    break;
	case ne_status_connected:
	    if (!quiet) printf(_("done)"));
	    break;
        case ne_status_recving:
        case ne_status_sending:
            /* Start of transfer: */
            if ((out_state == out_transfer_download 
                 && status == ne_status_recving)
                || (out_state == out_transfer_upload 
                    && status == ne_status_sending)) {
                if (isatty(STDOUT_FILENO) && info->sr.total > 0) {
                    out_state = out_transfer_pretty;
                    putchar('\n');
                    pretty_progress_bar(info->sr.progress, info->sr.total);
                } else {
                    out_state = out_transfer_plain;
                    printf(" [.");
                }
            }
            break;                
        default:
            break;
	}
	break;
    case out_transfer_plain:
	switch (status) {
	case ne_status_connecting:
	    printf(_("] reconnecting: "));
	    break;
	case ne_status_connected:
	    printf(_("okay ["));
	    break;
        case ne_status_sending:
        case ne_status_recving:
            putchar('.');
            fflush(stdout);
            if (info->sr.progress == info->sr.total) {
                out_state = out_transfer_done;
            }
            break;
        default:
            break;
	}
	break;
    case out_transfer_pretty:
	switch (status) {
	case ne_status_connecting:
	    if (!quiet) printf(_("\rTransfer timed out, reconnecting... "));
	    break;
	case ne_status_connected:
	    if (!quiet) printf(_("okay."));
	    break;
        case ne_status_recving:
        case ne_status_sending:
	    pretty_progress_bar(info->sr.progress, info->sr.total);
            if (info->sr.progress == info->sr.total) {
                out_state = out_transfer_done;
            }
        default:
            break;
	}
	break;	
    }
    fflush(stdout);
}
예제 #12
0
파일: cadaver.c 프로젝트: grimneko/cadaver
/* FIXME: Leaky as a bucket */
void open_connection(const char *url)
{
    char *proxy_host = get_option(opt_proxy), *pnt;
    ne_server_capabilities caps;
    int ret, use_ssl = 0;
    ne_session *sess;

    if (session.connected) {
	close_connection();
    } else {
        ne_uri_free(&session.uri);
        if (session.lastwp) {
            ne_free(session.lastwp);
            session.lastwp = NULL;
        }
    }

    /* Single argument: see whether we have a path or scheme */
    if (strchr(url, '/') == NULL) {
	/* No path, no scheme -> just a hostname */
	pnt = strchr(url, ':');
	if (pnt != NULL) {
	    *pnt++ = '\0';
	    session.uri.port = atoi(pnt);
	} else {
	    session.uri.port = 80;
	}
	session.uri.host = ne_strdup(url);
	session.uri.scheme = ne_strdup("http");
    } else {
	/* Parse the URL */
	if (ne_uri_parse(url, &session.uri) || session.uri.host == NULL) {
	    printf(_("Could not parse URL `%s'\n"), url);
	    return;
	}

	if (session.uri.scheme == NULL)
	    session.uri.scheme = ne_strdup("http");

	if (!session.uri.port)
	    session.uri.port = ne_uri_defaultport(session.uri.scheme);

	if (strcasecmp(session.uri.scheme, "https") == 0) {
	    if (!ne_has_support(NE_FEATURE_SSL)) {
		printf(_("SSL is not enabled.\n"));
		return;
	    }
	    use_ssl = 1;
	}
    }

    session.sess = ne_session_create(session.uri.scheme, session.uri.host,
                                     session.uri.port);
    sess = session.sess;
    
    if (use_ssl && setup_ssl()) {
	return;
    }

    ne_lockstore_register(session.locks, sess);
    ne_redirect_register(sess);
    ne_set_notifier(sess, notifier, NULL);

    if (session.uri.path == NULL) {
	session.uri.path = ne_strdup("/");
    } else {
	if (!ne_path_has_trailing_slash(session.uri.path)) {
	    pnt = ne_concat(session.uri.path, "/", NULL);
	    free(session.uri.path);
	    session.uri.path = pnt;
	}
    }

    /* Get the proxy details */
    if (proxy_host != NULL) {
	if (get_option(opt_proxy_port) != NULL) {
	    proxy_port = atoi(get_option(opt_proxy_port));
	} else {
	    proxy_port = 8080;
	}
	proxy_hostname = proxy_host;
    }

#ifdef ENABLE_NETRC
    {
	netrc_entry *found;
	found = search_netrc(netrc_list, session.uri.host);
	if (found != NULL) {
	    if (found->account && found->password) {
		server_username = found->account;
		server_password = found->password;
	    }
	}
    }
#endif /* ENABLE_NETRC */
#ifdef NE_SESSFLAG_EXPECT100
	ne_set_session_flag(session.sess, NE_SESSFLAG_EXPECT100, get_bool_option(opt_expect100));
#endif /* NE_SESSFLAG_EXPECT100 */
    session.connected = 0;

    ne_set_useragent(session.sess, "cadaver/" PACKAGE_VERSION);
    ne_set_server_auth(session.sess, supply_creds_server, NULL);
    ne_set_proxy_auth(session.sess, supply_creds_proxy, NULL);
    
    if (proxy_host) {
	ne_session_proxy(session.sess, proxy_hostname, proxy_port);
    }

    ret = ne_options(session.sess, session.uri.path, &caps);
    
    switch (ret) {
    case NE_OK:
	session.connected = true;
	if (set_path(session.uri.path)) {
	    close_connection();
	}
	break;
    case NE_CONNECT:
	if (proxy_host) {
	    printf(_("Could not connect to `%s' on port %d:\n%s\n"),
		   proxy_hostname, proxy_port, ne_get_error(session.sess));
	} else {
	    printf(_("Could not connect to `%s' on port %d:\n%s\n"),
		   session.uri.host, session.uri.port, ne_get_error(session.sess));
	}
	break;
    case NE_LOOKUP:
	puts(ne_get_error(session.sess));
	break;
    default:
	printf(_("Could not open collection:\n%s\n"),
	       ne_get_error(session.sess));
	break;
    }

}
예제 #13
0
static rc_t gather_flag_options( Args * args, samdump_opts * opts )
{
    bool dump_prim_only;

    /* do we have to dump unaligned reads too? */
    rc_t rc = get_bool_option( args, OPT_UNALIGNED, &opts->dump_unaligned_reads );
    if ( rc != 0 ) return rc;

    /* assume we have to dump primary alignments, maybe switched off later by other option */
    opts->dump_primary_alignments = true;

    /* we are dumping secondary alignments only if the user does
       not explicitly ask for "primary only" */
    rc = get_bool_option( args, OPT_PRIM_ONLY, &dump_prim_only );
    if ( rc != 0 ) return rc;
    opts->dump_secondary_alignments = !dump_prim_only;

    /* check if we are asked to be in cga-tool compatible mode */
    rc = get_bool_option( args, OPT_CG_SAM, &opts->dump_cg_sam );
    if ( rc != 0 ) return rc;

    /* check if we have to dump "EVIDENCE_INTERVAL" against the reference */
    rc = get_bool_option( args, OPT_CG_EVIDENCE, &opts->dump_cg_evidence );
    if ( rc != 0 ) return rc;

    /* check if we have to dump "EVIDENCE_ALIGNMENT" against "EVIDENCE_INTERVAL" */
    rc = get_bool_option( args, OPT_CG_EV_DNB, &opts->dump_cg_ev_dnb );
    if ( rc != 0 ) return rc;

    {
        bool dump_cg_mappings;

        /* look if cg-mappings is requested */
        rc = get_bool_option( args, OPT_CG_MAPP, &dump_cg_mappings );
        if ( rc != 0 ) return rc;

        /* do some mode logic ... */
        if ( !dump_cg_mappings &&
             ( opts->dump_cga_tools_mode || opts->dump_cg_evidence || opts->dump_cg_ev_dnb ) )
        {
            opts->dump_primary_alignments = false;
            opts->dump_secondary_alignments = false;
            opts->dump_unaligned_reads = false;
        }
        else
        {
            opts->dump_primary_alignments = true;
            opts->dump_secondary_alignments = !dump_prim_only;
            /* opts->dump_unaligned_reads = ( opts->dump_unaligned_reads && opts->region_count == 0 ); */
        }
    }

    /* do we have to print the long-version of the cigar-string? */
    rc = get_bool_option( args, OPT_CIGAR_LONG, &opts->use_long_cigar );
    if ( rc != 0 ) return rc;

    /* print the sequence-id instead of the sequence-name */
    rc = get_bool_option( args, OPT_USE_SEQID, &opts->use_seqid_as_refname );
    if ( rc != 0 ) return rc;

    /* print the READ where matched bases are replaced with '=' */
    rc = get_bool_option( args, OPT_HIDE_IDENT, &opts->print_matches_as_equal_sign );
    if ( rc != 0 ) return rc;

    {
        bool recalc_header, dont_print_header;

        /* do we have to recalculate the header instead of printing the meta-data */
        rc = get_bool_option( args, OPT_RECAL_HDR, &recalc_header );
        if ( rc != 0 ) return rc;
        /* should we suppress the header completely */
        rc = get_bool_option( args, OPT_NO_HDR, &dont_print_header );
        if ( rc != 0 ) return rc;
        if ( dont_print_header )
            opts->header_mode = hm_none;
        else if ( recalc_header )
            opts->header_mode = hm_recalc;
        else
            opts->header_mode = hm_dump;
    }

    {
        bool cigar_cg, cigar_cg_merge;

        /* do we have to transform cigar into cg-style ( has B/N ) */
        /* do we have to transform cg-data(length of read/patterns in cigar) into valid SAM (cigar/READ/QUALITY) */
        rc = gather_2_bool( args, OPT_CIGAR_CG, OPT_CIGAR_CG, &cigar_cg, &cigar_cg_merge );
        if ( rc != 0 ) return rc;
        if ( cigar_cg )
            opts->cigar_treatment = ct_cg_style;
        if ( cigar_cg_merge )
            opts->cigar_treatment = ct_cg_merge;
    }

    {
        bool gzip, bzip2;

        /* do we have to compress the output with gzip ? */
        /* do we have to compress the output with bzip2 ? */
        rc = gather_2_bool( args, OPT_GZIP, OPT_BZIP2, &gzip, &bzip2 );
        if ( rc != 0 ) return rc;
        if ( gzip )
            opts->output_compression = oc_gzip;
        if ( bzip2 )
            opts->output_compression = oc_bzip2;
    }


    {
        bool fasta, fastq;

        /* output in FASTA - mode  ? */
        /* output in FASTQ - mode  ? */
        rc = gather_2_bool( args, OPT_FASTA, OPT_FASTQ, &fasta, &fastq );
        if ( rc != 0 ) return rc;
        if ( fasta )
            opts->output_format = of_fasta;
        if ( fastq )
            opts->output_format = of_fastq;
    }


    /* do we have to reverse unaligned reads if the flag in the row says so */
    rc = get_bool_option( args, OPT_REVERSE, &opts->reverse_unaligned_reads );
    if ( rc != 0 ) return rc;

    /* do we have to add the spotgroup to the qname-column */
    rc = get_bool_option( args, OPT_SPOTGRP, &opts->print_spot_group_in_name );
    if ( rc != 0 ) return rc;

    /* do we have to report options instead of executing */
    rc = get_bool_option( args, OPT_REPORT, &opts->report_options );
    if ( rc != 0 ) return rc;

    /* do we have to print the alignment id in column XI */
    rc = get_bool_option( args, OPT_XI_DEBUG, &opts->print_alignment_id_in_column_xi );
    if ( rc != 0 ) return rc;

    /* do we have to print the alignment id in column XI */
    rc = get_bool_option( args, OPT_CACHEREPORT, &opts->report_cache );
    if ( rc != 0 ) return rc;

    /* do we have to dump unaligned reads only */
    rc = get_bool_option( args, OPT_UNALIGNED_ONLY, &opts->dump_unaligned_only );
    if ( rc != 0 ) return rc;

    /* do we have to print the spot-group in a special way */
    rc = get_bool_option( args, OPT_CG_NAMES, &opts->print_cg_names );
    if ( rc != 0 ) return rc;

    /* do we have to merge cigar ( and read/qual ) for cg-operations in cigar */
    rc = get_bool_option( args, OPT_CIGAR_CG_M, &opts->merge_cg_cigar );

    return rc;
}
예제 #14
0
static void get_user_input( tool_ctx_t * tool_ctx, const Args * args )
{
    bool split_spot, split_file, split_3, whole_spot;
    
    /*
    tool_ctx -> compress = get_compress_t( get_bool_option( args, OPTION_GZIP ),
                                            get_bool_option( args, OPTION_BZIP2 ) ); helper.c */
    tool_ctx -> compress = ct_none;
    
    tool_ctx -> cursor_cache = get_size_t_option( args, OPTION_CURCACHE, DFLT_CUR_CACHE );            
    tool_ctx -> show_progress = get_bool_option( args, OPTION_PROGRESS );
    tool_ctx -> show_details = get_bool_option( args, OPTION_DETAILS );
    tool_ctx -> requested_temp_path = get_str_option( args, OPTION_TEMP, NULL );
    tool_ctx -> force = get_bool_option( args, OPTION_FORCE );        
    tool_ctx -> output_filename = get_str_option( args, OPTION_OUTPUT_F, NULL );
    tool_ctx -> output_dirname = get_str_option( args, OPTION_OUTPUT_D, NULL );
    tool_ctx -> buf_size = get_size_t_option( args, OPTION_BUFSIZE, DFLT_BUF_SIZE );
    tool_ctx -> mem_limit = get_size_t_option( args, OPTION_MEM, DFLT_MEM_LIMIT );
    tool_ctx -> num_threads = get_uint32_t_option( args, OPTION_THREADS, DFLT_NUM_THREADS );

    tool_ctx -> join_options . rowid_as_name = get_bool_option( args, OPTION_RIDN );
    tool_ctx -> join_options . skip_tech = !( get_bool_option( args, OPTION_INCL_TECH ) );
    tool_ctx -> join_options . print_read_nr = get_bool_option( args, OPTION_PRNR );
    tool_ctx -> join_options . print_name = true;
    tool_ctx -> join_options . min_read_len = get_uint32_t_option( args, OPTION_MINRDLEN, 0 );
    tool_ctx -> join_options . filter_bases = get_str_option( args, OPTION_BASE_FLT, NULL );
    tool_ctx -> join_options . terminate_on_invalid = get_bool_option( args, OPTION_STRICT );

    split_spot = get_bool_option( args, OPTION_SPLIT_SPOT );
    split_file = get_bool_option( args, OPTION_SPLIT_FILE );
    split_3    = get_bool_option( args, OPTION_SPLIT_3 );
    whole_spot = get_bool_option( args, OPTION_WHOLE_SPOT );
    
    tool_ctx -> fmt = get_format_t( get_str_option( args, OPTION_FORMAT, NULL ),
                            split_spot, split_file, split_3, whole_spot ); /* helper.c */
    if ( tool_ctx -> fmt == ft_fastq_split_3 )
        tool_ctx -> join_options . skip_tech = true;

    tool_ctx -> seq_tbl_name = get_str_option( args, OPTION_TABLE, dflt_seq_tabl_name );
}