Esempio n. 1
0
File: main.c Progetto: rpreen/xcsf
int main(int argc, char *argv[0])
{    
	if(argc < 2 || argc > 4) {
		printf("Usage: xcsf inputfile [MaxTrials] [NumExp]\n");
		exit(EXIT_FAILURE);
	} 

	// initialise environment
	constants_init(argc, argv);
	random_init();
	func_init(argv[1]);
	gen_outfname(argv[1]);

	// run experiments
	double err[PERF_AVG_TRIALS];
	double terr[PERF_AVG_TRIALS];
	for(int e = 1; e < NUM_EXPERIMENTS+1; e++) {
		printf("\nExperiment: %d\n", e);
		pop_init();
		outfile_init(e);
		// each trial in an experiment
		for(int cnt = 0; cnt < MAX_TRIALS; cnt++) {
			trial(cnt, true, err); // train
			trial(cnt, false, terr);// test
			// display performance
			if(cnt%PERF_AVG_TRIALS == 0 && cnt > 0)
				disp_perf(err, terr, cnt, pop_num);
		}
		// clean up
		set_kill(&pset);
		outfile_close();
	}
	func_free();
	return EXIT_SUCCESS;
}
Esempio n. 2
0
func_t *func_script(const char *str)
{
    func_t *f=NULL;
    func_init();
    f=func_strings_char(str);
    f=func_null_script(f);    // NULL
    f=func_nan_script(f);     // nan
    f=func_inf_script(f);     // inf
    f=func_zero_script(f);    // 0
    f=func_one_script(f);     // 1
    f=func_bigint_script(f);  // Z, Q
    f=func_real_script(f);    // R
    f=func_var_script(f);     // var: #0, #1, #2, ...
    f=func_set_script(f);     // =, def
    f=func_add_script(f);     // +
    f=func_sub_script(f);     // -
    f=func_mul_script(f);     // *
    f=func_div_script(f);     // /
    f=func_pow_script(f);     // ^
    f=func_bracket_script(f); // (......)
    f=func_list_script(f);    // list: {......}, [......]
    f=func_builtin_script(f); // built-in: f, f(...)
    f=func_def_script(f);     // def: f, f(...)
    if(func_is_strings(f)) {
        printf("Error in func_script(const char *str)\n");
        printf("str='%s'\n",str);
        printf("f=");
        func_print(f);
        printf("\n");
        exit(0);
    }
    return f;
}
Esempio n. 3
0
func_t *func_end_eval(func_t *f)
{
  func_init();
  if(f==NULL || !func_is(f,"end") || func_asize(f)!=0){ FUNC_ERROR_ARG1("func_end_eval",f); }
  func_scope_end();
  f=func_del(f);
  return NULL;
}
Esempio n. 4
0
func_t *func_set_eval(func_t *f)
{
  func_init();
  if(f==NULL || !func_is(f,"set") || func_asize(f)!=1){ FUNC_ERROR_ARG1("func_set_eval",f); }
  func_scope_set(0,FR(func_aget(f,0)));
  f=func_del(f);
  return f;
}
Esempio n. 5
0
func_t *func_begin_eval(func_t *f)
{
  func_init();
  if      (f==NULL || !func_is(f,"begin"))                    { FUNC_ERROR_ARG1("func_begin_eval",f); }
  else if(func_asize(f)==0)                                   { func_scope_begin(NULL);        f=func_del(f); }
  else if(func_asize(f)==1 && func_is_strings(func_aget(f,0))){ func_scope_begin(FR(f->a[0])); f=func_del(f); }
  return f;
}
Esempio n. 6
0
void func_import_basic(int n)
{
  func_init();
  // default op for debug only
  func_scope_set(n,func_op_builtin_new());
  func_scope_set(n,func_op_def_new());
  func_scope_set(n,func_op_list_new());
  func_scope_set(n,func_op_table_new());
  func_scope_set(n,func_op_strings_new());
  func_scope_set(n,func_op_scope_new());
  // basic
  func_scope_set(n,func_op_nan_new());
  func_scope_set(n,func_op_inf_new());
  func_scope_set(n,func_op_zero_new());
  func_scope_set(n,func_op_one_new());
  func_scope_set(n,func_op_bigint_new());
  func_scope_set(n,func_op_real_new());
  func_scope_set(n,func_op_complex_new());
  func_scope_set(n,func_op_var_new());
  func_scope_set(n,func_op_add_new());
  func_scope_set(n,func_op_mul_new());
  func_scope_set(n,func_op_sqrt_new());
  func_scope_set(n,func_op_exp_new());
  func_scope_set(n,func_op_log_new());
  func_scope_set(n,func_op_pow_new());
  func_scope_set(n,func_op_sin_new());
  func_scope_set(n,func_op_cos_new());
  func_scope_set(n,func_op_tan_new());
  func_scope_set(n,func_op_asin_new());
  func_scope_set(n,func_op_acos_new());
  func_scope_set(n,func_op_atan_new());
  func_scope_set(n,func_op_sinh_new());
  func_scope_set(n,func_op_cosh_new());
  func_scope_set(n,func_op_tanh_new());
  func_scope_set(n,func_op_asinh_new());
  func_scope_set(n,func_op_acosh_new());
  func_scope_set(n,func_op_atanh_new());
  func_scope_set(n,func_op_ivec_new());
  func_scope_set(n,func_op_rvec_new());
  func_scope_set(n,func_op_cvec_new());
  func_scope_set(n,func_op_rmat_new());
  func_scope_set(n,func_op_cmat_new());
  func_scope_set(n,func_op_begin_new());
  func_scope_set(n,func_op_end_new());
  func_scope_set(n,func_op_set_new());
  func_scope_set(n,func_op_print_new());
  func_scope_set(n,func_op_eval_new());
  func_scope_set(n,func_op_evalf_new());
  func_scope_set(n,func_op_expand_new());
  func_scope_set(n,func_op_diff_new());
  func_scope_set(n,func_op_grad_new());
  func_scope_set(n,func_op_gbasis_new());
  func_scope_set(n,func_def("I", func_complex_i(),0,0));
  func_scope_set(n,func_def("i", func_sqrt(func_bigint_int(-1,1)),0,0));
  func_scope_set(n,func_def("PI",func_mul(func_atan(func_one()),func_bigint_int(4,1)),0,0));
  func_scope_set(n,func_def("Pi",func_mul(func_atan(func_one()),func_bigint_int(4,1)),0,0));
  func_scope_set(n,func_def("pi",func_mul(func_atan(func_one()),func_bigint_int(4,1)),0,0));
}
Esempio n. 7
0
 virtual bool init( ::boost::shared_ptr< osiris::IExtensionsModule > module, ::osiris::String const & title, ::osiris::UniqueID const & instance, ::osiris::String const & xml ) {
     ::osiris::PythonState __pystate(getPythonThreadState());
     if( ::osiris::PythonOverride func_init = this->get_override( "init" ) )
         return func_init( module, boost::ref(title), boost::ref(instance), boost::ref(xml) );
     else {
         __pystate.leave();
         return this->::osiris::ExtensionsModuleControl::init( module, boost::ref(title), boost::ref(instance), boost::ref(xml) );
     }
 }
Esempio n. 8
0
main ()
{

  thds = omp_get_max_threads ();
  if (thds == 1) {
    printf ("should be run this program on multi threads.\n");
    exit (0);
  }
  omp_set_dynamic (0);

  #pragma omp parallel
  {
    i = omp_get_thread_num ();
  }
  i = omp_get_thread_num ();
  
  #pragma omp parallel
  {
    if(i != omp_get_thread_num ()) {
      #pragma omp critical
      errors += 1;
    }
  }


  #pragma omp parallel 
  func_init ();
  i = omp_get_thread_num ();
  #pragma omp parallel
  func_check ();


  func_init ();
  func_check ();


  if (errors == 0) {
    printf ("threadprivate 006 : SUCCESS\n");
    return 0;
  } else {
    printf ("threadprivate 006 : FAILED\n");
    return 1;
  }
}
Esempio n. 9
0
void Plugin::init()
{ 
   if(is_loaded)
   {
	assert(is_registered);
	
	if(!is_initialized){
		func_init();
		/* fly the flag */
		is_initialized = true;
	}
	else
	{
		crusde_warning("Plugin::init() called at least twice, skipping repeated initialization!");
	}
   }	
}
Esempio n. 10
0
SQLRETURN SQL_API SQLGetFunctions(
    SQLHDBC            hdbc,
    SQLUSMALLINT       fFunction,
    SQLUSMALLINT FAR  *pfExists)
{
	if ( func_init("SQLGetFunction") != 0 ){ return SQL_ERROR; }

    if (fFunction == SQL_API_ALL_FUNCTIONS) {
        int i;

        memset(pfExists, 0, sizeof(UWORD)*100);

        for( i = 0; i < 100; i++ ) {
            pfExists[i] = is_odbc_function( (SQLSMALLINT)i );
        }
    } else {
        *pfExists = is_odbc_function( fFunction );
    }
    return SQL_SUCCESS;
}
Esempio n. 11
0
void parse_funcHead() {
    switch(next_token.type) {
        case TT_TYPE_DOUBLE:
        case TT_TYPE_INT:
        case TT_TYPE_STRING:
            func_init();
            match(next_token.type);
            func_set_return_type(curr_token.type);
            match(TT_IDENTIFICATOR);
            func_set_name(curr_token.str);
            match(TT_PARENTHESES_OPEN);
            parse_paramSpec();
            func_set_param_count(param_count);
            match(TT_PARENTHESES_CLOSE);
            symbol_t* funcRef = func_finish();
            func_table_add(funcRef);
            parse_funcBody(funcRef);
            break;
        default:
            error("Syntactic error: Failed to parse the program", ERROR_SYN);
    }
}
Esempio n. 12
0
TreeBlock *tree_simple_g_alloc(TreePool *p, void *context, void *context2, FuncSimpleInitBlocks func_init, TreeBlock *parent, BlockOffset parent_offset) {
  TreeBlock *bl = (TreeBlock *)malloc(sizeof(TreeBlock));
  tree_simple_alloc_assign_info(bl, parent, parent_offset);

  // Set the id of the tree.
  bl->id = __sync_fetch_and_add(&p->ever_allocated, 1);
  __sync_fetch_and_add(&p->allocated, 1);

  // Initialize function if there is any.
  // Note that we should not call initialization AFTER the parent connects with the child, since by then other threads might have access to
  // this child before we set up everything.
  // printf("p = %lx, bl = %lx, context = %lx, context2 = %lx\n", (uint64_t)p, (uint64_t)bl, (uint64_t)context, (uint64_t)context2);
  // fflush(stdout);
  if (func_init != NULL) {
    func_init(p, bl, context, context2);
  }

  // Now parent should connect the head of the children.
  // Note that parent->expansion should already be set (parent->expansion is used as a simple mutex).
  SET_BIT(parent->expansion, parent_offset);
  __sync_bool_compare_and_swap(&parent->children[parent_offset].child, 0, bl);
  event_count_broadcast(&parent->children[parent_offset].event_count);
  return bl;
}
Esempio n. 13
0
func_t *func_set(func_t *f)
{
  func_init();
  return func_arg1_new("set",f);
}
Esempio n. 14
0
func_t *func_begin(func_t *f)
{
  func_init();
  return func_arg1_new("begin",f);
}
Esempio n. 15
0
void init_med_functions()
{
	func_init(med_functions, (sizeof(med_functions)/sizeof(FUNCTION))-1 );
}
Esempio n. 16
0
/* Check if MAGIC is valid and print the Multiboot information structure
   pointed by ADDR. */
void
entry (unsigned long magic, unsigned long addr)
{
    /* Initialize the idt */
    init_idt();

    multiboot_info_t *mbi;

    /* Clear the screen. */
    clear();

    /* Am I booted by a Multiboot-compliant boot loader? */
    if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
    {
        printf ("Invalid magic number: 0x%#x\n", (unsigned) magic);
        return;
    }

    /* Set MBI to the address of the Multiboot information structure. */
    mbi = (multiboot_info_t *) addr;

    /* Print out the flags. */
    printf ("flags = 0x%#x\n", (unsigned) mbi->flags);

    /* Are mem_* valid? */
    if (CHECK_FLAG (mbi->flags, 0))
        printf ("mem_lower = %uKB, mem_upper = %uKB\n",
                (unsigned) mbi->mem_lower, (unsigned) mbi->mem_upper);

    /* Is boot_device valid? */
    if (CHECK_FLAG (mbi->flags, 1))
        printf ("boot_device = 0x%#x\n", (unsigned) mbi->boot_device);

    /* Is the command line passed? */
    if (CHECK_FLAG (mbi->flags, 2))
        printf ("cmdline = %s\n", (char *) mbi->cmdline);

    if (CHECK_FLAG (mbi->flags, 3)) {
        int mod_count = 0;
        int i;
        module_t* mod = (module_t*)mbi->mods_addr;

        starting_address = mod->mod_start;

        while(mod_count < mbi->mods_count) {
            printf("Module %d loaded at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_start);
            printf("Module %d ends at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_end);
            printf("First few bytes of module:\n");
            for(i = 0; i<16; i++) {
                printf("0x%x ", *((char*)(mod->mod_start+i)));
            }
            printf("\n");
            mod_count++;
            mod++;
        }
    }
    /* Bits 4 and 5 are mutually exclusive! */
    if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5))
    {
        printf ("Both bits 4 and 5 are set.\n");
        return;
    }

    /* Is the section header table of ELF valid? */
    if (CHECK_FLAG (mbi->flags, 5))
    {
        elf_section_header_table_t *elf_sec = &(mbi->elf_sec);

        printf ("elf_sec: num = %u, size = 0x%#x,"
                " addr = 0x%#x, shndx = 0x%#x\n",
                (unsigned) elf_sec->num, (unsigned) elf_sec->size,
                (unsigned) elf_sec->addr, (unsigned) elf_sec->shndx);
    }

    /* Are mmap_* valid? */
    if (CHECK_FLAG (mbi->flags, 6))
    {
        memory_map_t *mmap;

        printf ("mmap_addr = 0x%#x, mmap_length = 0x%x\n",
                (unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length);
        for (mmap = (memory_map_t *) mbi->mmap_addr;
                (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length;
                mmap = (memory_map_t *) ((unsigned long) mmap
                                         + mmap->size + sizeof (mmap->size)))
            printf (" size = 0x%x,     base_addr = 0x%#x%#x\n"
                    "     type = 0x%x,  length    = 0x%#x%#x\n",
                    (unsigned) mmap->size,
                    (unsigned) mmap->base_addr_high,
                    (unsigned) mmap->base_addr_low,
                    (unsigned) mmap->type,
                    (unsigned) mmap->length_high,
                    (unsigned) mmap->length_low);
    }

    /* Construct an LDT entry in the GDT */
    {
        seg_desc_t the_ldt_desc;
        the_ldt_desc.granularity    = 0;
        the_ldt_desc.opsize         = 1;
        the_ldt_desc.reserved       = 0;
        the_ldt_desc.avail          = 0;
        the_ldt_desc.present        = 1;
        the_ldt_desc.dpl            = 0x0;
        the_ldt_desc.sys            = 0;
        the_ldt_desc.type           = 0x2;

        SET_LDT_PARAMS(the_ldt_desc, &ldt, ldt_size);
        ldt_desc_ptr = the_ldt_desc;
        lldt(KERNEL_LDT);
    }

    /* Construct a TSS entry in the GDT */
    {
        seg_desc_t the_tss_desc;
        the_tss_desc.granularity    = 0;
        the_tss_desc.opsize         = 0;
        the_tss_desc.reserved       = 0;
        the_tss_desc.avail          = 0;
        the_tss_desc.seg_lim_19_16  = TSS_SIZE & 0x000F0000;
        the_tss_desc.present        = 1;
        the_tss_desc.dpl            = 0x0;
        the_tss_desc.sys            = 0;
        the_tss_desc.type           = 0x9;
        the_tss_desc.seg_lim_15_00  = TSS_SIZE & 0x0000FFFF;

        SET_TSS_PARAMS(the_tss_desc, &tss, tss_size);

        tss_desc_ptr = the_tss_desc;

        tss.ldt_segment_selector = KERNEL_LDT;
        tss.ss0 = KERNEL_DS;
        tss.esp0 = 0x800000;
        ltr(KERNEL_TSS);
    }

    /* Initialize the PIC */
    i8259_init();

    /* Initialize devices, memory, filesystem, enable device interrupts on the
     * PIC, any other initialization stuff... */
    initialize_paging();

    /* initialize the RTC to 2Hz */
    rtc_initialize();

    /* initialize keyboard */
    initialize_keyboard();
    /* initialize function pointers */
    func_init();
    /* TESTING FILE SYSTEMS */
    init_file_systems(starting_address);

    init_terminals();
    //printf("Init File Systems Done\n");
    //test_file_systems((uint8_t*)"frame0.txt");
    //printf("Done testing\n");
    /* FINISH FILE SYSTEMS TESTING */


    /* Enable interrupts */
    /* Do not enable the following until after you have set up your
     * IDT correctly otherwise QEMU will triple fault and simple close
     * without showing you any output */
    printf("Enabling Interrupts\n");
    sti();



    // testing for changing RTC freq

    /*int32_t * freq;
    int32_t temp = 1024;
    freq = &temp;
    rtc_write(freq, 4);
    int i;
    for(i = 0; i < 10; i ++) {
    	rtc_read();
    	printf("testing");
    }

    temp = 256;
    rtc_write(freq, 4);

    for (i = 0; i < 20; i++) {
    	rtc_read();
    	printf("\n");
    	printf("second_test");
    }*/






    /*while(1) {
    	asm volatile("int $0x28");
    }*/
    //int d = 6 / 0;

    /* Execute the first program (`shell') ... */
    clear();
    execute((uint8_t*)"shell");
    /* Spin (nicely, so we don't chew up cycles) */
    asm volatile(".1: hlt; jmp .1;");
}
Esempio n. 17
0
/*
 * Turn a scan code to characters, based on the status of keyboard
 *
 * How to handle function keys?
 * Should I mess with NumLock here?
 */
int 
kbd_scantokey(
    int key,
    u_char * chars)
{				/* chars must be able to hold at least 3 */
	/* but 255 might be safer, if Fkeys become */
	/* macros */
	int     keyssofar = 0;

	key &= 0x7f;		/* don't care about key ups */

	/* First, check for arrow keys: */
	switch (key) {
	case ADBK_LEFT:
		chars[0] = 27;	/* Left */
		chars[1] = VTCHAR;
		chars[2] = 'D';
		return (3);

	case ADBK_RIGHT:
		/* Right C */
		chars[0] = 27;
		chars[1] = VTCHAR;
		chars[2] = 'C';
		return (3);

	case ADBK_DOWN:
		/* Down B */
		chars[0] = 27;
		chars[1] = VTCHAR;
		chars[2] = 'B';
		return (3);

	case ADBK_UP:
		/* Up A */
		chars[0] = 27;
		chars[1] = VTCHAR;
		chars[2] = 'A';
		return (3);

	case ADBK_PGUP:
		/* pgup */
		chars[0] = 27;
		chars[1] = '[';
		chars[2] = '5';
		chars[3] = '~';
		return (4);

	case ADBK_PGDN:
		/* pgdn */
		chars[0] = 27;
		chars[1] = '[';
		chars[2] = '6';
		chars[3] = '~';
		return (4);

	case ADBK_HOME:
		/* home */
		chars[0] = 27;
		chars[1] = '[';
		chars[2] = '1';
		chars[3] = '~';
		return (4);

	case ADBK_END:
		/* end */
		chars[0] = 27;
		chars[1] = '[';
		chars[2] = '4';
		chars[3] = '~';
		return (4);

		/* function keys */
	case ADBK_F1:
		func_dokey(0);
		return 0;
	case ADBK_F2:
		func_dokey(1);
		return 0;
	case ADBK_F3:
		func_dokey(2);
		return 0;
	case ADBK_F4:
		func_dokey(3);
		return 0;
	case ADBK_F5:
		func_dokey(4);
		return 0;
	case ADBK_F6:
		func_dokey(5);
		return 0;
	case ADBK_F7:
		func_dokey(6);
		return 0;
	case ADBK_F8:
		func_dokey(7);
		return 0;
	case ADBK_F9:
		func_dokey(8);
		return 0;
	case ADBK_F10:
		func_dokey(9);
		return 0;
	case ADBK_F11:
		func_dokey(10);
		return 0;
	case ADBK_F12:
		func_dokey(11);
		return 0;
	case ADBK_F15:
		func_init(1);
		return 0;
	}

	if (keyboard[key][0] == 0)
		return (0);

#ifndef OPTSET
	if (ISKEYDOWN(ADBK_OPTION)) {	/* OPTION doubles for Meta */
		/* Meta means "prefix with ESC" -- Emacs */
		chars[keyssofar++] = 27;
	}
#endif				/* OPTSET */

	if (ISKEYDOWN(ADBK_CONTROL)) {	/* CTRL */
		if (keyboard[key][MAP_CTRL] == 0 && key != ADBK_SPACE)
			return 0;
		chars[keyssofar++] = keyboard[key][MAP_CTRL];
#ifdef OPTSET
	} else
		if (ISKEYDOWN(ADBK_OPTION) && ISKEYDOWN(ADBK_SHIFT)) {	/* OPTION + SHIFT */
			if (keyboard[key][MAP_OPTSHFT] == 0)
				return 0;
			chars[keyssofar++] = keyboard[key][MAP_OPTSHFT];
#endif				/* OPTSET */
		} else
			if (ISKEYDOWN(ADBK_SHIFT)) {	/* SHIFT */
				if (keyboard[key][MAP_SHIFT] == 0)
					return 0;
				chars[keyssofar++] = keyboard[key][MAP_SHIFT];
#ifdef OPTSET
			} else
				if (ISKEYDOWN(ADBK_OPTION)) {	/* OPTION */
					if (keyboard[key][MAP_OPTION] == 0)
						return 0;
					chars[keyssofar++] = keyboard[key][MAP_OPTION];
#endif				/* OPTSET */
				} else
					if (ISKEYDOWN(ADBK_CAPSLOCK)) {	/* CAPSLOCK */
						if (isealpha(keyboard[key][MAP_SHIFT]))
							chars[keyssofar++] = keyboard[key][MAP_SHIFT];
						else
							chars[keyssofar++] = keyboard[key][MAP_NORMAL];
					} else {	/* nothing */
						chars[keyssofar++] = keyboard[key][MAP_NORMAL];
					}

	return (keyssofar);
}
Esempio n. 18
0
func_t *func_end(func_t *f)
{
  func_init();
  return func_arg1_new("end",f);
}
Esempio n. 19
0
SQLRETURN SQL_API SQLGetInfo(
	SQLHDBC			hdbc,
	SQLUSMALLINT	fInfoType,
	SQLPOINTER		rgbInfoValue,
	SQLSMALLINT		cbInfoValueMax,
	SQLSMALLINT FAR	*pcbInfoValue)
{
	if ( func_init("SQLGetInfo") != 0 ){ return SQL_ERROR; }

    switch( fInfoType ) {

      case SQL_ACCESSIBLE_PROCEDURES:
        if( rgbInfoValue && cbInfoValueMax > 1 ) {
            strcpy( (char*)rgbInfoValue, "N" );  // other driver
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_ACCESSIBLE_TABLES:
        if( rgbInfoValue && cbInfoValueMax > 1 ) {
            strcpy( (char*)rgbInfoValue, "N" );  // other driver
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_ACTIVE_CONNECTIONS:
        if( rgbInfoValue ) {
            *(SQLUSMALLINT *)rgbInfoValue = 10; // other driver
            if( pcbInfoValue ) *pcbInfoValue = sizeof( SQLUSMALLINT );
        }
        return SQL_SUCCESS;

      case SQL_ACTIVE_STATEMENTS:
        if( rgbInfoValue ) {
            *(SQLUSMALLINT *)rgbInfoValue = 0;
        }
        if( pcbInfoValue ) *pcbInfoValue = sizeof( SQLUSMALLINT );
        return SQL_SUCCESS;

      case SQL_ALTER_TABLE:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue =
                SQL_AT_ADD_COLUMN | SQL_AT_DROP_COLUMN;
        }
        if( pcbInfoValue ) *pcbInfoValue = sizeof( SQLUINTEGER );
        return SQL_SUCCESS;

      case SQL_BOOKMARK_PERSISTENCE:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; // other driver
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CATALOG_LOCATION:
        if( rgbInfoValue ) {
            *(SQLUSMALLINT *)rgbInfoValue = 0; // other driver
        }
        if( pcbInfoValue ) *pcbInfoValue = sizeof( SQLUSMALLINT );
        return SQL_SUCCESS;

      case SQL_CATALOG_NAME_SEPARATOR:
        if( rgbInfoValue && cbInfoValueMax > 1 ) {
            strcpy( (char*)rgbInfoValue, "" );     // other driver
        }
        if( pcbInfoValue ) *pcbInfoValue = 0;
        return SQL_SUCCESS;

      case SQL_CATALOG_TERM:
        if( rgbInfoValue && cbInfoValueMax > 7 ) {
            strcpy( (char*)rgbInfoValue, "catalog" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 7;
        return SQL_SUCCESS;

      case SQL_CATALOG_USAGE:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0;
        }
        if( pcbInfoValue ) *pcbInfoValue = sizeof( SQLUINTEGER );
        return SQL_SUCCESS;

      case SQL_COLUMN_ALIAS:
        if( rgbInfoValue && cbInfoValueMax > 1 ) {
            strcpy( (char*)rgbInfoValue, "N" );  // other driver
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_CONCAT_NULL_BEHAVIOR:
        if( rgbInfoValue && cbInfoValueMax > 1 ) {
            *(short *)rgbInfoValue = SQL_CB_NULL; // other driver
        }
        if( pcbInfoValue ) *pcbInfoValue = sizeof(short);
        return SQL_SUCCESS;

      case SQL_CONVERT_BIGINT:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_BINARY:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_BIT:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_CHAR:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0x00008002; // other driver
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_DATE:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0x00008101; // other driver
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_DECIMAL:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_DOUBLE:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_FLOAT:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_FUNCTIONS:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; // 何もなし
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_INTEGER:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_LONGVARBINARY:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_LONGVARCHAR:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CONVERT_NUMERIC:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0x00008101; // other driver
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_CURSOR_COMMIT_BEHAVIOR:
        if( rgbInfoValue ) {
            *(SQLUSMALLINT *)rgbInfoValue = SQL_CB_PRESERVE;
            CHECK_LEN(SQLUSMALLINT);
        }
        RESULT_LEN(SQLUSMALLINT);
        return SQL_SUCCESS;

      case SQL_CURSOR_ROLLBACK_BEHAVIOR:
        if( rgbInfoValue ) {
            *(SQLUSMALLINT *)rgbInfoValue = SQL_CB_DELETE;
            CHECK_LEN(SQLUSMALLINT);
        }
        RESULT_LEN(SQLUSMALLINT);
        return SQL_SUCCESS;

      case SQL_DATABASE_NAME:
        if( rgbInfoValue && cbInfoValueMax > 10 ) {
            strcpy( (char*)rgbInfoValue, "hiveodbc" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 10;
        return SQL_SUCCESS;

      case SQL_DBMS_NAME:
        if( rgbInfoValue && cbInfoValueMax > 10 ) {
            strcpy( (char*)rgbInfoValue, "hiveodbc" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 8;
        return SQL_SUCCESS;

      case SQL_DBMS_VER:
        if( rgbInfoValue && cbInfoValueMax > 10 ) {
            strcpy( (char*)rgbInfoValue, "01.01.0000" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 10;
        return SQL_SUCCESS;

      case SQL_DATA_SOURCE_READ_ONLY:
        if( rgbInfoValue ) {
            strcpy( (char*)rgbInfoValue, "N" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_DEFAULT_TXN_ISOLATION:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = SQL_TXN_READ_COMMITTED;
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_DRIVER_ODBC_VER:
        if( rgbInfoValue && cbInfoValueMax > 5 ) {
            strcpy( (char*)rgbInfoValue, "01.00" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 5;
        return SQL_SUCCESS;

      case SQL_DRIVER_NAME:
        if( rgbInfoValue && cbInfoValueMax > 10 ) {
            strcpy( (char*)rgbInfoValue, "hiveodbc.dll" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 12;
        return SQL_SUCCESS;

      case SQL_DRIVER_VER:
        if( rgbInfoValue && cbInfoValueMax > 10 ) {
            strcpy( (char*)rgbInfoValue, "01.00.0000" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 10;
        return SQL_SUCCESS;

      case SQL_DYNAMIC_CURSOR_ATTRIBUTES1:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = SQL_CA1_NEXT;
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_EXPRESSIONS_IN_ORDERBY:
        if( rgbInfoValue && cbInfoValueMax > 1 ) {
            strcpy( (char*)rgbInfoValue, "N" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_FETCH_DIRECTION:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = SQL_FD_FETCH_NEXT;
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = SQL_CA1_NEXT;
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_GETDATA_EXTENSIONS:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue = SQL_GD_ANY_COLUMN |
            SQL_GD_ANY_ORDER | SQL_GD_BOUND |
            SQL_GD_BLOCK;
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_GROUP_BY:
        if( rgbInfoValue ) {
            *(short *)rgbInfoValue = SQL_GB_GROUP_BY_EQUALS_SELECT; 
            CHECK_LEN(SQLUSMALLINT);
        }
        RESULT_LEN(SQLUSMALLINT);
        return SQL_SUCCESS;

      case SQL_IDENTIFIER_QUOTE_CHAR:
        if( rgbInfoValue ) {
            strcpy( (char*)rgbInfoValue, "" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_IDENTIFIER_CASE:
        if( rgbInfoValue ) {
            *(short *)rgbInfoValue = SQL_IC_UPPER; 
            CHECK_LEN(SQLUSMALLINT);
        }
        RESULT_LEN(SQLUSMALLINT);
        return SQL_SUCCESS;

      case SQL_KEYSET_CURSOR_ATTRIBUTES1:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = SQL_CA1_NEXT;
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_LIKE_ESCAPE_CLAUSE:
        if( rgbInfoValue ) {
            strcpy( (char*)rgbInfoValue, "N" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_LOCK_TYPES:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue = SQL_LCK_NO_CHANGE;
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_MAX_CATALOG_NAME_LEN:
        if( rgbInfoValue ) {
            *(SQLUSMALLINT *)rgbInfoValue = 0;   // other driver
            CHECK_LEN(SQLUSMALLINT);
        }
        RESULT_LEN(SQLUSMALLINT);
        return SQL_SUCCESS;

      case SQL_MAX_COLUMN_NAME_LEN:
        if( rgbInfoValue ) {
            *(short *)rgbInfoValue = 31; 
        }
        if( pcbInfoValue ) *pcbInfoValue = 2;
        return SQL_SUCCESS;

      case SQL_MAX_CURSOR_NAME_LEN:
        if( rgbInfoValue ) {
            *(short *)rgbInfoValue = 31;  // other driver (max 18)
        }
        if( pcbInfoValue ) *pcbInfoValue = 2;
        return SQL_SUCCESS;

      case SQL_MAX_PROCEDURE_NAME_LEN:
        if( rgbInfoValue ) {
            *(SQLUSMALLINT *)rgbInfoValue = 27; // other driver 31?
            CHECK_LEN(SQLUSMALLINT);
        }
        RESULT_LEN(SQLUSMALLINT);
        return SQL_SUCCESS;

      case SQL_MAX_SCHEMA_NAME_LEN:
        if( rgbInfoValue ) {
            *(SQLUSMALLINT *)rgbInfoValue = 0;  // other driver
            CHECK_LEN(SQLUSMALLINT);
        }
        RESULT_LEN(SQLUSMALLINT);
        return SQL_SUCCESS;

      case SQL_MAX_TABLE_NAME_LEN:
        if( rgbInfoValue ) {
            *(short *)rgbInfoValue = 31; 
        }
        if( pcbInfoValue ) *pcbInfoValue = 2;
        return SQL_SUCCESS;

      case SQL_MULT_RESULT_SETS:
        if( rgbInfoValue ) {
            strcpy( (char*)rgbInfoValue, "N" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_MULTIPLE_ACTIVE_TXN:
        if( rgbInfoValue ) {
            strcpy( (char*)rgbInfoValue, "Y" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_NULL_COLLATION:
        if( rgbInfoValue ) {
            *(short *)rgbInfoValue = 0; // ?
        }
        if( pcbInfoValue ) *pcbInfoValue = 2;
        return SQL_SUCCESS;

      case SQL_NEED_LONG_DATA_LEN:
        if( rgbInfoValue ) {
            *(char *)rgbInfoValue = 'N'; 
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_NUMERIC_FUNCTIONS:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue = 0; // 何もなし
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_ODBC_API_CONFORMANCE:
        if( rgbInfoValue ) {
            *(short *)rgbInfoValue = SQL_OAC_LEVEL1;
        }
        if( pcbInfoValue ) *pcbInfoValue = sizeof( SQLUSMALLINT );
        return SQL_SUCCESS;

      case SQL_ORDER_BY_COLUMNS_IN_SELECT:
        if( rgbInfoValue && cbInfoValueMax > 1 ) {
            strcpy( (char*)rgbInfoValue, "N" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_OUTER_JOINS:
        if( rgbInfoValue && cbInfoValueMax > 1 ) {
            strcpy( (char*)rgbInfoValue, "Y" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_OWNER_TERM:
        if( rgbInfoValue && cbInfoValueMax > 5 ) {
            strcpy( (char*)rgbInfoValue, "OWNER" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 5;
        return SQL_SUCCESS;

      case SQL_POSITIONED_STATEMENTS:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_POS_OPERATIONS:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = 0; 
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_PROCEDURES:
        if( rgbInfoValue ) {
            strcpy( (char*)rgbInfoValue, "Y" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_QUOTED_IDENTIFIER_CASE:
        if( rgbInfoValue ) {
            *(short *)rgbInfoValue = SQL_IC_UPPER; 
        }
        if( pcbInfoValue ) *pcbInfoValue = 2;
        return SQL_SUCCESS;

      case SQL_ROW_UPDATES:
        if( rgbInfoValue ) {
            strcpy( (char*)rgbInfoValue, "Y" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 1;
        return SQL_SUCCESS;

      case SQL_SCROLL_CONCURRENCY:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue = SQL_SCCO_READ_ONLY;
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_SCROLL_OPTIONS:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue = SQL_SO_FORWARD_ONLY;
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_SEARCH_PATTERN_ESCAPE:
        if( rgbInfoValue && cbInfoValueMax > 1 ) {
            strcpy( (char*)rgbInfoValue, "" );
        }
        if( pcbInfoValue ) *pcbInfoValue = 0;
        return SQL_SUCCESS;

      case SQL_STATIC_CURSOR_ATTRIBUTES1: // ODBC 3.0
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = SQL_CA1_NEXT;
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;

      case SQL_STATIC_SENSITIVITY:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue = 0; // 何も出来ない
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_STRING_FUNCTIONS:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue = 0; // 何もなし
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_SYSTEM_FUNCTIONS:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue = 0; // 何もなし
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_TIMEDATE_FUNCTIONS:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue = 0; // 何もなし
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_TXN_CAPABLE:
        if( rgbInfoValue ) {
            *(short *)rgbInfoValue = SQL_TC_DDL_COMMIT;
        }
        if( pcbInfoValue ) *pcbInfoValue = 2;
        return SQL_SUCCESS;

      case SQL_TXN_ISOLATION_OPTION:
        if( rgbInfoValue ) {
            *(long *)rgbInfoValue =
                SQL_TXN_READ_COMMITTED  |
                SQL_TXN_REPEATABLE_READ |
                SQL_TXN_SERIALIZABLE    ;
        }
        if( pcbInfoValue ) *pcbInfoValue = 4;
        return SQL_SUCCESS;

      case SQL_UNION:
        if( rgbInfoValue ) {
            *(SQLUINTEGER *)rgbInfoValue = SQL_U_UNION | SQL_U_UNION_ALL;
            CHECK_LEN(SQLUINTEGER);
        }
        RESULT_LEN(SQLUINTEGER);
        return SQL_SUCCESS;
    }
    if( pcbInfoValue ) *pcbInfoValue = 0;

	debuglog("unknown SQLGetInfo(%d)", fInfoType );
	return SQL_ERROR;

}
Esempio n. 20
0
/******************************************************************************
 *                                                                            *
 * Function: load_modules                                                     *
 *                                                                            *
 * Purpose: load loadable modules (dynamic libraries)                         *
 *          It skips a module in case of any errors                           *
 *                                                                            *
 * Parameters: path - directory where modules are located                     *
 *             file_names - list of module names                              *
 *             timeout - timeout in seconds for processing of items by module *
 *             verbose - output list of loaded modules                        *
 *                                                                            *
 * Return value: SUCCEED - all modules is successfully loaded                 *
 *               FAIL - loading of modules failed                             *
 *                                                                            *
 ******************************************************************************/
int	load_modules(const char *path, char **file_names, int timeout, int verbose)
{
	const char	*__function_name = "load_modules";

	char		**file_name, *buffer = NULL;
	void		*lib;
	char		full_name[MAX_STRING_LEN], error[MAX_STRING_LEN];
	int		(*func_init)(), (*func_version)();
	ZBX_METRIC	*(*func_list)();
	void		(*func_timeout)();
	int		i, ret = FAIL;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	for (file_name = file_names; NULL != *file_name; file_name++)
	{
		zbx_snprintf(full_name, sizeof(full_name), "%s/%s", path, *file_name);

		zabbix_log(LOG_LEVEL_DEBUG, "loading module \"%s\"", full_name);

		if (NULL == (lib = dlopen(full_name, RTLD_NOW)))
		{
			zabbix_log(LOG_LEVEL_CRIT, "cannot load module \"%s\": %s", *file_name, dlerror());
			goto fail;
		}

		*(void **)(&func_version) = dlsym(lib, ZBX_MODULE_FUNC_API_VERSION);
		if (NULL == func_version)
		{
			zabbix_log(LOG_LEVEL_CRIT, "cannot find \"" ZBX_MODULE_FUNC_API_VERSION "()\""
					" function in module \"%s\": %s", *file_name, dlerror());
			dlclose(lib);
			goto fail;
		}

		if (ZBX_MODULE_API_VERSION_ONE != (i = func_version()))
		{
			zabbix_log(LOG_LEVEL_CRIT, "unsupported module \"%s\" version: %d", *file_name, i);
			dlclose(lib);
			goto fail;
		}

		*(void **)(&func_init) = dlsym(lib, ZBX_MODULE_FUNC_INIT);
		if (NULL == func_init)
		{
			zabbix_log(LOG_LEVEL_CRIT, "cannot find \"" ZBX_MODULE_FUNC_INIT "()\""
					" function in module \"%s\": %s", *file_name, dlerror());
			dlclose(lib);
			goto fail;
		}

		if (ZBX_MODULE_OK != func_init())
		{
			zabbix_log(LOG_LEVEL_CRIT, "cannot initialize module \"%s\"", *file_name);
			dlclose(lib);
			goto fail;
		}

		/* the function is optional, zabbix will load the module ieven if it is missing */
		*(void **)(&func_timeout) = dlsym(lib, ZBX_MODULE_FUNC_ITEM_TIMEOUT);
		if (NULL == func_timeout)
		{
			zabbix_log(LOG_LEVEL_DEBUG, "cannot find \"" ZBX_MODULE_FUNC_ITEM_TIMEOUT "()\""
					" function in module \"%s\": %s", *file_name, dlerror());
		}
		else
			func_timeout(timeout);

		*(void **)(&func_list) = dlsym(lib, ZBX_MODULE_FUNC_ITEM_LIST);
		if (NULL == func_list)
		{
			zabbix_log(LOG_LEVEL_WARNING, "cannot find \"" ZBX_MODULE_FUNC_ITEM_LIST "()\""
					" function in module \"%s\": %s", *file_name, dlerror());
			dlclose(lib);
			continue;
		}

		if (SUCCEED == register_module(lib))
		{
			ZBX_METRIC	*metrics;

			metrics = func_list();

			for (i = 0; NULL != metrics[i].key; i++)
			{
				/* accept only CF_HAVEPARAMS flag from module items */
				metrics[i].flags &= CF_HAVEPARAMS;
				/* the flag means that the items comes from a loadable module */
				metrics[i].flags |= CF_MODULE;
				if (SUCCEED != add_metric(&metrics[i], error, sizeof(error)))
				{
					zabbix_log(LOG_LEVEL_CRIT, "cannot load module \"%s\": %s", *file_name, error);
					exit(EXIT_FAILURE);
				}
			}

			if (1 == verbose)
			{
				if (NULL != buffer)
					buffer = zbx_strdcat(buffer, ", ");
				buffer = zbx_strdcat(buffer, *file_name);
			}
		}
	}

	if (NULL != buffer)
		zabbix_log(LOG_LEVEL_WARNING, "loaded modules: %s", buffer);

	ret = SUCCEED;
fail:
	zbx_free(buffer);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;
}
Esempio n. 21
0
File: pico.c Progetto: ctubio/alpine
/*
 * For the pine composer, we don't want to take over the whole screen
 * for editing.  the first some odd lines are to be used for message 
 * header information editing.
 */
void
edinit(char bname[])
{
    register BUFFER *bp;
    register WINDOW *wp;

    if(Pmaster)
      func_init();

    bp = bfind(bname, TRUE, BFWRAPOPEN);    /* First buffer         */
    wp = (WINDOW *) malloc(sizeof(WINDOW)); /* First window         */

    if (bp==NULL || wp==NULL){
	if(Pmaster)
	  return;
	else
	  exit(1);
    }

    curbp  = bp;                            /* Make this current    */
    wheadp = wp;
    curwp  = wp;
    wp->w_wndp  = NULL;                     /* Initialize window    */
    wp->w_bufp  = bp;
    bp->b_nwnd  = 1;                        /* Displayed.           */
    wp->w_linep = bp->b_linep;
    wp->w_dotp  = bp->b_linep;
    wp->w_doto  = 0;
    wp->w_markp = wp->w_imarkp = NULL;
    wp->w_marko = wp->w_imarko = 0;
    bp->b_linecnt = -1;

    if(Pmaster){
	term.t_mrow = Pmaster->menu_rows;
	wp->w_toprow = ComposerTopLine = COMPOSER_TOP_LINE;
	wp->w_ntrows = term.t_nrow - COMPOSER_TOP_LINE - term.t_mrow;
	fillcol = Pmaster->fillcolumn;
	strncpy(opertree,
	       (Pmaster->oper_dir && strlen(Pmaster->oper_dir) < NLINE)
	         ? Pmaster->oper_dir : "", sizeof(opertree));
	opertree[sizeof(opertree)-1] = '\0';
	input_cs = Pmaster->input_cs;
    }
    else{
	if(sup_keyhelp)
	  term.t_mrow = 0;
	else
	  term.t_mrow = 2;

        wp->w_toprow = 2;
        wp->w_ntrows = term.t_nrow - 2 - term.t_mrow;
	if(userfillcol > 0)			/* set fill column */
	  fillcol = userfillcol;
	else
	  fillcol = term.t_ncol - 6;
    }

    /*
     * MDSCUR mode implies MDTREE mode with a opertree of home directory,
     * unless opertree has been set differently.
     */
    if((gmode & MDSCUR) && !opertree[0]){
      strncpy(opertree, gethomedir(NULL), sizeof(opertree));
      opertree[sizeof(opertree)-1] = '\0';
    }

    if(*opertree)
      fixpath(opertree, sizeof(opertree));

    wp->w_force = 0;
    wp->w_flag  = WFMODE|WFHARD;            /* Full.                */
}