コード例 #1
0
ファイル: dump.c プロジェクト: ahaym/trumpify
void dump_params(pParam params)
{
  if(params) {
    printf("%s ", params->data);
    dump_params(params->next);
  };
};
コード例 #2
0
ファイル: dump.c プロジェクト: ahaym/trumpify
static int rule_iter(pRule r, int param)
{
  printf("%s", r->symbol); 
  if(r->params) {
    printf(" ( ");
    dump_params(r->params);
    printf(")");
  };
  printf(" : (%d options)\n", option_length(r->options));
  dump_options(r->options);
};
コード例 #3
0
void
clear_notches (FL_OBJECT *ob, long data)
{
    int i;

    for (i = 0; i < NNOTCHES; i++)
    {
        notches[i] = -1.0;
    }
    notches[0] = 1.0;
    write_notches ();
    dump_params ();
}
コード例 #4
0
ファイル: tuner-test.c プロジェクト: JiaoXianjun/osmo-sdr
static void compute_and_dump(uint32_t flo)
{
	struct e4k_pll_params params;
	int rc;

	memset(&params, 0, sizeof(params));
	rc = e4k_compute_pll_params(&params, FOSC, flo);
	if (rc < 0) {
		fprintf(stderr, "something went wrong!\n");
		exit(1);
	}

	dump_params(&params);
	e4k_tune_params(&g_e4k, &params);
}
コード例 #5
0
/*---------------------------nand probe--------------------------------------------------*/
int mtd_nand_probe_burner(MTDPartitionInfo *pinfo, nand_flash_param *nand_params,
		int nr_nand_args, int eraseall, void **title_fill, int *size)
{
	int wppin = pinfo->gpio_wp;
	nand_flash_param *nand_param = NULL;
	int ret;

	/*mtd: disable write protect*/
	if (wppin != -1)
		gpio_direction_output(wppin, 0);

	/*mtd: get nand param from params table*/
	ret = nand_params_idx(nand_params, nr_nand_args);
	if (ret < 0)
		return ret;
	nand_param = &nand_params[ret];

	/*mtd: prepare spl title*/
	ret = mtd_nand_get_spl_title(nand_param, title_fill, size);
	if (ret)
		return ret;

	/*mtd: nand probe*/
	ret = mtd_nand_auto_init(nand_param);
	if (ret) return ret;

	/*mtd: params prepare to burn*/
	mtd_nand_params = zalloc(CONFIG_SPL_PAD_TO);
	if (!mtd_nand_params) return -ENOMEM;
	memcpy(mtd_nand_params, nand_param, sizeof(nand_flash_param));
	memcpy(mtd_nand_params+sizeof(nand_flash_param), pinfo, sizeof(MTDPartitionInfo));
	dump_params();

	/*mtd: nand erase all*/
	if (eraseall == 1)
		ret = run_command("nand scrub.chip -y", 0);
	else if (eraseall == 2)
		ret = run_command("nand erase.chip", 0);

	/*mtd: partition*/
	return mtd_nand_burner_part(pinfo, eraseall);
}
コード例 #6
0
ファイル: cputests_double.c プロジェクト: jspiechowicz/mbp
int main(int argc, char **argv)
{
  int ret;
  params p = {	 	/*<<<	___default___	*/
    4.2,		/*	amp		*/
    4.9, 		/*	omega		*/
    0.0, 		/*	force		*/
    0.9,  		/*	gamma		*/
    0.001, 		/*	Dg		*/
    0.0,		/*	Dp		*/
    0.0,		/*	lambda		*/
    false,		/*	biased		*/
    32,			/*	paths		*/
    10000,		/*	periods		*/
    99,			/*	trans		*/
    200,		/*	spp		*/
    true,		/*	2nd order	*/
  };/*>>>*/	

  tic = clock();
  set_parameters(argc,argv,&p);

  /*<<<      GSL                     */
  const gsl_rng_type * R;
  gsl_rng * rg;
  gsl_rng_env_setup();
  if (!getenv("GSL_RNG_SEED")){
    gsl_rng_default_seed = time(NULL);
    fprintf(stderr,"#seed:%ld\n",gsl_rng_default_seed);
  }
  R = gsl_rng_default;
  rg = gsl_rng_alloc (R);
  /*>>>GSL*/

  dump_params(&p);

  ret = simulate(&p, rg);

  gsl_rng_free(rg);
  return ret;
}
コード例 #7
0
void
lmst_update (FL_OBJECT *ob, long data)
{
	struct tm *ltp;
	time_t now;
	unsigned char sid[6];
	char lmst_buf[64];
	FILE *fp;
	int i, j;
	FL_Coord x, y;
	FL_Coord w, h;
	double high, low;
	char *p;
	int delta;
	int hours, mins, secs;
	
	fl_add_timeout (1000.0, (FL_TIMEOUT_CALLBACK)lmst_update, 0);
	
	/*
	 * Determine current LMST
	 */
	time (&now);
	ltp = gmtime (&now);
	get_sid_time (sid, longitude, ltp);
	memcpy (current_lmst, sid, 3);
	sprintf (lmst_buf, "%02d:%02d:%02d", sid[0], sid[1], sid[2]);
	fl_set_object_label(fd_receiver_main->lmst_display, lmst_buf);
	
	delta = now - started_at;
	hours = delta / 3600;
	mins = (delta - (hours * 3600)) / 60;
	secs = (delta - ((hours * 3600) + (mins*60)));
	sprintf (lmst_buf, "%02d:%02d:%02d", hours, mins, secs);
	fl_set_object_label (fd_receiver_main->runtime_text, lmst_buf);
	
	ra_mode[0] = 0x00;
	dec_mode[0] = 0x00;
	if ((p = getenv ("RCVR_RA_MODE")) != NULL)
	{
		strcpy (ra_mode, p);
		if (strcmp (p, "transit") == 0)
		{
			ra = (float)sid[0] + (float)sid[1]/60.0 + (float)sid[2]/3600.0;
			sprintf (lmst_buf, "%f", ra);
			fl_set_input (fd_receiver_main->ra_input, lmst_buf);
		}
		else if (strncmp (p, "external", 8) == 0)
		{
			char keyword[128], filename[128];
			
			sscanf (p, "%s %s", keyword, filename);
			if ((fp = fopen (filename, "r")) != NULL)
			{
				fscanf (fp, "%f", &ra);
				sprintf (lmst_buf, "%f", ra);
				fl_set_input (fd_receiver_main->ra_input, lmst_buf);
				fclose(fp);
			}
		}
	}
	if ((p = getenv ("RCVR_DEC_MODE")) != NULL)
	{
		strcpy (dec_mode, p);
		if (strncmp (p, "external", 8) == 0)
		{
			char keyword[128], filename[128];
			
			sscanf (p, "%s %s", keyword, filename);
			if ((fp = fopen (filename, "r")) != NULL)
			{
				fscanf (fp, "%f", &declination);
				sprintf (lmst_buf, "%f", declination);
				fl_set_input (fd_receiver_main->declination_input, lmst_buf);
				fclose(fp);
			}
		}
	}
	
	dump_params ();
	
	time (&now);
	if ((startup_cleared > 0) && (last_io_time > 1000) && ((now - last_io_time) > 30))
	{
		if (no_more_input == 0)
		{
			fprintf (stderr, "Leaving from %s\n", __FUNCTION__);
			receiver_leave (NULL, -10);
		}
	}
	if (startup_cleared > 0)
	{
		time (&now);
		
		/*
		 * We know that the python script has started and can now take
		 *     XMLRPC commands, because it's sending us data, so update
		 *     some variables, *once*.
		 */
		if (writeback_flag == 0)
		{
			void write_pushed_variables(void);
			
			writeback_flag = 1;
			
			/*
			 * Write (via XMLRPC) all our "pushed" variables
			 *   into the Gnu Radio flowgraph.
			 */
			write_pushed_variables();
			write_notches ();
		}
		
		/*
		 * Set the warning levels for I/O lag from Gnu Radio flowgraph
		 */
		if ((now - last_io_time) <= 1)
		{
			fl_set_object_color (fd_receiver_main->io_status, FL_GREEN, FL_GREEN);
		}
		else if ((now - last_io_time) < 8)
		{
			fl_set_object_color (fd_receiver_main->io_status, FL_YELLOW, FL_YELLOW);
		}
		else if ((now - last_io_time) >= 8)
		{
			fl_set_object_color (fd_receiver_main->io_status, FL_RED, FL_RED);
		}
	}
}
コード例 #8
0
ファイル: pwm_test.c プロジェクト: haywoodspartan/nuttx
int main(int argc, FAR char *argv[]) {
#else
int pwm_test_main(int argc, char *argv[]) {
#endif
    struct device *dev;
    struct pwm_app_info *info = NULL;
    uint16_t count;
    uint32_t ret = 0;
    int i;

    info = zalloc(sizeof(struct pwm_app_info));
    if (!info) {
        printf("pwm_test: App initialization failed!\n");
        return EXIT_FAILURE;
    }

    default_params(info);

    if (comm_parse(info, argc, argv)) {
        print_usage();
        goto err_free_info;
    }

    dev = device_open(DEVICE_TYPE_PWM_HW, 0);
    if (!dev) {
        printf("pwm_test: Open PWM controller driver failure!\n");
        ret = EXIT_FAILURE;
        goto err_free_info;
    }

    device_pwm_get_count(dev, &count);

    if (info->index > count) {
        printf("pwm_test: pwm%u > maximum supported number %u\n", info->index,
               count);
        print_usage();
        ret =  EXIT_FAILURE;
        goto err_out;
    }

    if (!info->is_mode_test) {
        ret = pwm_configure(dev, info, false);
        if (ret) {
            printf("pwm_test: Failed to enabled PWM%u \n", info->index);
            goto err_out;
        }
    } else {
        switch (info->mode_num) {
        case PWM_PULSECOUNT_MODE:
            if (info->param < 1) {
                printf("pwm_test: mode 0 of -a must > 0\n");
                print_usage();
                ret =  EXIT_FAILURE;
                goto err_out;
            }

            info->secs = ((info->period/1000000000) * info->param) < 1 ? 1 :
                          (info->period/1000000000) * info->param;

            ret = pwm_configure(dev, info, true);
            if (ret) {
                printf("pwm_test: mode 0, set generator(%u) in mode(%u) has "
                       "failed\n", info->index, info->mode_num);
                goto err_out;
            }
            break;
        case PWM_STOP_LEVEL_MODE:
            ret = pwm_configure(dev, info, true);
            if (ret) {
                printf("pwm_test: mode1, set generator(%u) in mode(%u) has "
                       "failed\n", info->index, info->mode_num);
                goto err_out;
            }
            break;
        case PWM_SYNC_MODE:
            /**
             * This case will test all supported generstors to output waveform
             * at sametime that have same period configuration.
             */
            info->param = 1;
            for (i = 0; i < count; i++) {
                ret = device_pwm_activate(dev, i);
                if (ret) {
                    printf("pwm_test: mode2, active generator(%d) return "
                           "error(%x)\n", i, ret);
                    break;
                }

                ret = device_pwm_config(dev, i, info->period /(2+i),
                                        info->period);
                if (ret) {
                    printf("pwm_test: mode2, config generator(%d) return "
                           "error(%x)\n", i, ret);
                    break;
                }

                ret = device_pwm_set_mode(dev, i, info->mode_num, &info->param);
                if (ret) {
                    printf("pwm_test: mode 2, set generator(%d) of SELENB bit "
                           "return error(%x)\n", i, ret);
                    break;
                }
            }

            if (ret) {
                /**
                 * Make sure already activated pwm can be deactivated if has
                 * error.
                 */
                for (; i >= 0; i--) {
                    device_pwm_deactivate(dev, i);
                }
                goto err_out;
            }

            device_pwm_sync_output(dev, true);
            break;
        default:
            print_usage();
            ret = EXIT_FAILURE;
            goto err_out;
        }
    }

    dump_params(info);

    printf("pwm_test: Enabled PWM%u for a duration of %u seconds\n",
           info->index, info->secs);

    sleep((unsigned int)info->secs);

    if (info->is_mode_test && (info->mode_num == PWM_PULSECOUNT_MODE)) {
        printf("pwm_test: test completed, callback interrupt value "
               "= %u and error value = %u\n", val_int, val_err);
    } else {
        printf("pwm_test: test completed\n");
    }

err_out:
    device_close(dev);
err_free_info:
    free(info);

    return ret;
}
コード例 #9
0
ファイル: icode_dumper.cpp プロジェクト: jingqi/silk
SILK_API void dump_icode(std::ostream& os, ICode *code, size_t base_offset, bool use_basic_block)
{
    if (NULL == code)
        return;

    switch (code->op)
    {
    case IC_MODULE:
    {
        ModuleICode *mc = SILK_DYNAMIC_CAST<ModuleICode*>(code);
        assert(NULL != mc && NULL != mc->proc);

        dump_symtbl(os, mc->proc->symbol_table, base_offset);

        if (use_basic_block)
            dump_basic_blocks(os, mc->proc->blocks, base_offset);
        else
            dump_icodes(os, mc->proc->codes, base_offset, false);
        break;
    }

    case IC_LOAD:
    {
        LoadICode *lc = SILK_DYNAMIC_CAST<LoadICode*>(code);
        assert(NULL != lc);

        align_tab(os, base_offset);
        os << dump_dst(lc->dst) << "%load " << dump_value(lc->src) << std::endl;
        break;
    }

    case IC_POS:
    case IC_NEG:
    case IC_NOT:
    case IC_BIT_NOT:
    {
        UnaryOpICode *uc = SILK_DYNAMIC_CAST<UnaryOpICode*>(code);
        assert(NULL != uc);

        align_tab(os, base_offset);
        os << dump_dst(uc->dst) << unary_op_str(uc->op) << " " <<
               dump_value(uc->src) << std::endl;
        break;
    }

    case IC_GETG:
    {
        UnaryOpICode *uc = SILK_DYNAMIC_CAST<UnaryOpICode*>(code);
        assert(NULL != uc);

        align_tab(os, base_offset);
        os << dump_dst(uc->dst) << "%getg " << uc->src.get_var_name() << std::endl;
        break;
    }

    case IC_SETG:
    {
        UnaryOpICode *uc = SILK_DYNAMIC_CAST<UnaryOpICode*>(code);
        assert(NULL != uc);

        align_tab(os, base_offset);
        os << "%setg " << uc->dst.get_var_name() << " " <<
            dump_value(uc->src) << std::endl;
        break;
    }

    case IC_ADD:
    case IC_SUB:
    case IC_MUL:
    case IC_DIV:
    case IC_MOD:

    case IC_BIT_AND:
    case IC_BIT_OR:
    case IC_BIT_XOR:
    case IC_LSHIFT:
    case IC_RSHIFT:
    case IC_URSHIFT:

    case IC_EQ:
    case IC_REF_EQ:
    case IC_LESS_THAN:

    case IC_INDEX:
    {
        BinaryOpICode *bc = SILK_DYNAMIC_CAST<BinaryOpICode*>(code);
        assert(NULL != bc);

        align_tab(os, base_offset);
        os << dump_dst(bc->dst) << binary_op_str(bc->op) << " " <<
               dump_value(bc->left) << " " << dump_value(bc->right) << std::endl;
        break;
    }

    case IC_SET_INDEX:
    {
        SetIndexICode *sic = SILK_DYNAMIC_CAST<SetIndexICode*>(code);
        assert(NULL != sic);

        align_tab(os, base_offset);
        os << "%setidx " << dump_value(sic->left) << " " <<
            dump_value(sic->index) << " " << dump_value(sic->value) << std::endl;
        break;
    }

    case IC_MEMBER:
    {
        MemberICode *mc = SILK_DYNAMIC_CAST<MemberICode*>(code);
        assert(NULL != mc);

        align_tab(os, base_offset);
        os << dump_dst(mc->dst) << "%mbr " << dump_value(mc->left) <<
               " " << mc->member << std::endl;
        break;
    }

    case IC_SET_MEMBER:
    {
        SetMemberICode *smc = SILK_DYNAMIC_CAST<SetMemberICode*>(code);
        assert(NULL != smc);

        align_tab(os, base_offset);
        os << "%setmbr " << dump_value(smc->left) << " " <<
            smc->member << " " << dump_value(smc->value) << std::endl;
        break;
    }

    case IC_BS:
    {
        BinSwitchICode *bsc = SILK_DYNAMIC_CAST<BinSwitchICode*>(code);
        assert(NULL != bsc);

        align_tab(os, base_offset);
        os << dump_dst(bsc->dst) << "%bs " << dump_value(bsc->condition) <<
               " " << dump_value(bsc->true_value) << " " <<
               dump_value(bsc->false_value) << std::endl;
        break;
    }

    case IC_PUSH:
    {
        PushICode *pc = SILK_DYNAMIC_CAST<PushICode*>(code);
        assert(NULL != pc);

        align_tab(os, base_offset);
        os << "%push " << dump_value(pc->value) << std::endl;
        break;
    }

    case IC_MAKE_ARRAY:
    {
        MakeArrayICode *mac = SILK_DYNAMIC_CAST<MakeArrayICode*>(code);
        assert(NULL != mac);

        align_tab(os, base_offset);
        os << dump_dst(mac->dst) << "%mkarr " << mac->array_size << std::endl;
        break;
    }

    case IC_MAKE_MAP:
    {
        MakeMapICode *mmc = SILK_DYNAMIC_CAST<MakeMapICode*>(code);
        assert(NULL != mmc);

        align_tab(os, base_offset);
        os << dump_dst(mmc->dst) << "%mkmap " << mmc->map_size << std::endl;
        break;
    }

    case IC_MAKE_SET:
    {
        MakeSetICode *smc = SILK_DYNAMIC_CAST<MakeSetICode*>(code);
        assert(NULL != smc);

        align_tab(os, base_offset);
        os << dump_dst(smc->dst) << "%mkset " << smc->set_size << std::endl;
        break;
    }

    case IC_MAKE_LAMBDA:
    {
        MakeLambdaICode *mlc = SILK_DYNAMIC_CAST<MakeLambdaICode*>(code);
        assert(NULL != mlc && NULL != mlc->proc);

        align_tab(os, base_offset);
        os << dump_dst(mlc->dst) << "%lambda " << mlc->name <<
               dump_params(mlc->params) << " {" << std::endl;

        dump_symtbl(os, mlc->proc->symbol_table, base_offset + 1);

        if (use_basic_block)
            dump_basic_blocks(os, mlc->proc->blocks, base_offset + 1);
        else
            dump_icodes(os, mlc->proc->codes, base_offset + 1, false);

        align_tab(os, base_offset);
        os << "}" << std::endl;
        break;
    }

    case IC_MAKE_CLASS:
    {
        MakeClassICode *mcc = SILK_DYNAMIC_CAST<MakeClassICode*>(code);
        assert(NULL != mcc);
        align_tab(os, base_offset);
        os << dump_dst(mcc->dst) << "%class " << mcc->class_name << " {" << std::endl;

        // Static fields
        for (size_t i = 0, sz = mcc->static_fields.size(); i < sz; ++i)
        {
            MakeClassICode::Field &f = mcc->static_fields.at(i);
            align_tab(os, base_offset + 1);
            os << "%sfield " << Variable::get_var_type_name(f.type) << " " <<
                   f.name << std::endl;
        }

        // Instance fields
        for (size_t i = 0, sz = mcc->instance_fields.size(); i < sz; ++i)
        {
            MakeClassICode::Field &f = mcc->instance_fields.at(i);
            align_tab(os, base_offset + 1);
            os << "%field " << Variable::get_var_type_name(f.type) << " " <<
                   f.name << std::endl;
        }

        // Static init
        align_tab(os, base_offset + 1);
        os << "%cinit {" << std::endl;
        assert(NULL != mcc->static_init_code.proc);
        if (use_basic_block)
            dump_basic_blocks(os, mcc->static_init_code.proc->blocks, base_offset + 2);
        else
            dump_icodes(os, mcc->static_init_code.proc->codes, base_offset + 2, false);
        align_tab(os, base_offset + 1);
        os << "}" << std::endl;

        // Instance init
        align_tab(os, base_offset + 1);
        os << "%init {" << std::endl;
        assert(NULL != mcc->instance_init_code.proc);
        if (use_basic_block)
            dump_basic_blocks(os, mcc->instance_init_code.proc->blocks, base_offset + 2);
        else
            dump_icodes(os, mcc->instance_init_code.proc->codes, base_offset + 2, false);
        align_tab(os, base_offset + 1);
        os << "}" << std::endl;

        // Constructor
        align_tab(os, base_offset + 1);
        os << "%constructor " << dump_params(mcc->constructor.params) << " {" << std::endl;
        assert(NULL != mcc->constructor.proc);
        if (use_basic_block)
            dump_basic_blocks(os, mcc->constructor.proc->blocks, base_offset + 2);
        else
            dump_icodes(os, mcc->constructor.proc->codes, base_offset + 2, false);
        align_tab(os, base_offset + 1);
        os << "}" << std::endl;

        // Static methods
        for (size_t i = 0, sz = mcc->static_methods.size(); i < sz; ++i)
        {
            MakeClassICode::Method &m = mcc->static_methods.at(i);
            align_tab(os, base_offset + 1);
            os << "%smethod " << m.name << dump_params(m.params) << " {" << std::endl;
            assert(NULL != m.proc);
            if (use_basic_block)
                dump_basic_blocks(os, m.proc->blocks, base_offset + 2);
            else
                dump_icodes(os, m.proc->codes, base_offset + 2, false);
            align_tab(os, base_offset + 1);
            os << "}" << std::endl;
        }

        // Instance methods
        for (size_t i = 0, sz = mcc->instance_methods.size(); i < sz; ++i)
        {
            MakeClassICode::Method &m = mcc->instance_methods.at(i);
            align_tab(os, base_offset + 1);
            os << "%method " << m.name << dump_params(m.params) << " {" << std::endl;
            assert(NULL != m.proc);
            if (use_basic_block)
                dump_basic_blocks(os, m.proc->blocks, base_offset + 2);
            else
                dump_icodes(os, m.proc->codes, base_offset + 2, false);
            align_tab(os, base_offset + 1);
            os << "}" << std::endl;
        }

        align_tab(os, base_offset);
        os << "}" << std::endl;
        break;
    }

    case IC_JMP:
    {
        JumpICode *jc = SILK_DYNAMIC_CAST<JumpICode*>(code);
        assert(NULL != jc);

        align_tab(os, base_offset);
        os << "%jmp " << jc->label << std::endl;
        break;
    }

    case IC_JMP_IF:
    {
        JumpIfICode *jic = SILK_DYNAMIC_CAST<JumpIfICode*>(code);
        assert(NULL != jic);
        align_tab(os, base_offset);
        os << "%jmpif " << dump_value(jic->condition) << " " << jic->label
            << std::endl;
        break;
    }

    case IC_SWITCH:
    {
        SwitchICode *sc = SILK_DYNAMIC_CAST<SwitchICode*>(code);
        assert(NULL != sc);
        align_tab(os, base_offset);
        os << "%switch " << dump_value(sc->switch_value) << " {" << std::endl;

        for (size_t i = 0, sz = sc->cases.size(); i < sz; ++i)
        {
            SwitchICode::Case *c = sc->cases.at(i);
            assert(NULL != c);
            align_tab(os, base_offset);
            if (c->value.is_void())
                os << "default: ";
            else
                os << "case " << dump_value(c->value) << ":";
            os << c->label << std::endl;
        }
        align_tab(os, base_offset);
        os << "}" << std::endl;;
        break;
    }

    case IC_LABEL:
    {
        LabelICode *lc = SILK_DYNAMIC_CAST<LabelICode*>(code);
        assert(NULL != lc);
        align_tab(os, base_offset);
        os << lc->label << ":" << std::endl;
        break;
    }

    case IC_INVOKE:
    {
        InvokeICode *ic = SILK_DYNAMIC_CAST<InvokeICode*>(code);
        assert(NULL != ic);
        align_tab(os, base_offset);
        os << dump_dst(ic->dst) << "%invoke " << dump_value(ic->func) <<
               " " << ic->argc << std::endl;
        break;
    }

    case IC_NEW:
    {
        NewICode *nc = SILK_DYNAMIC_CAST<NewICode*>(code);
        assert(NULL != nc);
        align_tab(os, base_offset);
        os << dump_dst(nc->dst) << "%new " << dump_value(nc->clazz) <<
               " " << nc->argc << std::endl;
        break;
    }

    case IC_RETURN:
    {
        ReturnICode *rc = SILK_DYNAMIC_CAST<ReturnICode*>(code);
        assert(NULL != rc);
        align_tab(os, base_offset);
        os << "%return ";
        if (rc->retval.is_void())
            os << "void";
        else
            os << dump_value(rc->retval);
        os << std::endl;
        break;
    }

    case IC_DEF_VAR:
    {
        DefVarICode *dvc = SILK_DYNAMIC_CAST<DefVarICode*>(code);
        assert(NULL != dvc);
        align_tab(os, base_offset);
        os << "%defvar " << Variable::get_var_type_name(dvc->type) << " " <<
               dvc->name << std::endl;
        break;
    }

    case IC_CLOSE_CLOSURE:
    {
        CloseClosureICode *ccc = SILK_DYNAMIC_CAST<CloseClosureICode*>(code);
        assert(NULL != ccc);
        align_tab(os, base_offset);
        os << "%closure " << ccc->register_pos << std::endl;
        break;
    }

    case IC_CONVERT:
    {
        ConvertTypeICode *ctc = SILK_DYNAMIC_CAST<ConvertTypeICode*>(code);
        assert(NULL != ctc);
        align_tab(os, base_offset);
        os << dump_dst(ctc->dst) << "%cvt " <<
              Variable::get_var_type_name(ctc->var_type) <<
              " " << dump_value(ctc->src) << std::endl;
        break;
    }

    case IC_IMPORT:
    {
        ImportICode *mc = SILK_DYNAMIC_CAST<ImportICode*>(code);
        assert(NULL != mc);
        align_tab(os, base_offset);
        os << dump_dst(mc->dst) << "%import \"" << mc->module << "\"" << std::endl;
        break;
    }

    default:
        align_tab(os, base_offset);
        os << "!!!!unknown icode " << code->op << std::endl;
        break;
    }
}
コード例 #10
0
ファイル: mount.c プロジェクト: Agochka/klibc
int nfs_mount(const char *pathname, const char *hostname,
	      uint32_t server, const char *rem_path, const char *path,
	      struct nfs_mount_data *data)
{
	struct client *clnt = NULL;
	struct sockaddr_in addr;
	char mounted = 0;
	int sock = -1;
	int ret = 0;
	int mountflags;

	if (get_ports(server, data) != 0)
		goto bail;

	dump_params(server, rem_path, data);

	if (data->flags & NFS_MOUNT_TCP)
		clnt = tcp_client(server, mount_port, CLI_RESVPORT);
	else
		clnt = udp_client(server, mount_port, CLI_RESVPORT);

	if (clnt == NULL)
		goto bail;

	if (data->flags & NFS_MOUNT_VER3)
		ret = mount_v3(rem_path, data, clnt);
	else
		ret = mount_v2(rem_path, data, clnt);

	if (ret == -1)
		goto bail;
	mounted = 1;

	if (data->flags & NFS_MOUNT_TCP)
		sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	else
		sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);

	if (sock == -1) {
		perror("socket");
		goto bail;
	}

	if (bindresvport(sock, 0) == -1) {
		perror("bindresvport");
		goto bail;
	}

	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = server;
	addr.sin_port = htons(nfs_port);
	memcpy(&data->addr, &addr, sizeof(data->addr));

	strncpy(data->hostname, hostname, sizeof(data->hostname));

	data->fd = sock;

	mountflags = (data->flags & NFS_MOUNT_KLIBC_RONLY) ? MS_RDONLY : 0;
	data->flags = data->flags & NFS_MOUNT_FLAGMASK;
	ret = mount(pathname, path, "nfs", mountflags, data);

	if (ret == -1) {
		if (errno == ENODEV) {
			fprintf(stderr, "mount: the kernel lacks NFS v%d "
				"support\n",
				(data->flags & NFS_MOUNT_VER3) ? 3 : 2);
		} else {
			perror("mount");
		}
		goto bail;
	}

	dprintf("Mounted %s on %s\n", pathname, path);

	goto done;

bail:
	if (mounted) {
		if (data->flags & NFS_MOUNT_VER3)
			umount_v3(path, clnt);
		else
			umount_v2(path, clnt);
	}

	ret = -1;

done:
	if (clnt)
		client_free(clnt);

	if (sock != -1)
		close(sock);

	return ret;
}