Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{
	struct reader_t rout;
	struct reader_t rsol;
	const char *pts;

	if (argc != 4)
		return 1;

	reader_init(&rsol, argv[2]);
	reader_init(&rout, argv[3]);

	if (rsol.f == NULL)
		return 1;

	if (rout.f == NULL) {
		reader_free(&rsol);
		printf("%s\n", pts_zero);
		return 0;
	}

	pts = get_answer(&rsol, &rout);
	printf("%s\n", pts);

	reader_free(&rsol);
	reader_free(&rout);
	return 0;
}
Ejemplo n.º 2
0
void dispatchKernel_cnets_osblinnikov_github_com_init(struct dispatchKernel_cnets_osblinnikov_github_com *that,
    runnablesContainer_cnets_osblinnikov_github_com* _parent,
    uint32_t _maxNumberOfKernels,
    uint32_t _threadId,
    uint32_t _countOfThreads){
  
  that->parent = _parent;
  that->maxNumberOfKernels = _maxNumberOfKernels;
  that->threadId = _threadId;
  that->countOfThreads = _countOfThreads;
  that->readers = arrayObject_init_dynamic(sizeof(reader), 1);
  int readers_i_ = 0;
  for(readers_i_=0;readers_i_<1;readers_i_++){
    reader_init(&((reader*)that->readers.array)[readers_i_]);
  }
  reader_init(&that->readerSelector);
  that->kernels = arrayObject_init_dynamic(sizeof(runnables_dispatchKernel_cnets_osblinnikov_github_com), 1);
  int kernels_i_ = 0;
  for(kernels_i_=0;kernels_i_<1;kernels_i_++){
    runnables_dispatchKernel_cnets_osblinnikov_github_com_init(&((runnables_dispatchKernel_cnets_osblinnikov_github_com*)that->kernels.array)[kernels_i_]);
  }
  
  dispatchKernel_cnets_osblinnikov_github_com_onKernels(that);
  
  that->getRunnables = dispatchKernel_cnets_osblinnikov_github_com_getRunnables;
  
    runnablesContainer_cnets_osblinnikov_github_com_init(&that->_runnables);
    RunnableStoppable_create(runnableStoppableObj,that, dispatchKernel_cnets_osblinnikov_github_com)
    that->_runnables.setCore(&that->_runnables,runnableStoppableObj, 1);
  dispatchKernel_cnets_osblinnikov_github_com_onCreate(that);
}
Ejemplo n.º 3
0
/*
** rd = buffer:reader(rd = nil, offset=0, length=all)
*/
static int lbuffer_reader(lua_State *L)
{
	int top = lua_gettop(L);
	if (top > 0) {
		Buffer *buffer = buffer_lcheck(L, 1);
		Reader *reader = NULL;
		size_t offset = 0;
		size_t length = buffer->datasiz;
		
		if (top >= 2 && lua_type(L, 2) == LUA_TUSERDATA) {
			reader = (Reader*)luaL_checkudata(L, 2, READER_META);
			lua_pushvalue(L, 2);
		} 
		
		if (reader == NULL) {
			lua_getfield(L, LUA_REGISTRYINDEX, BUFFER_READERS);
			lua_pushlightuserdata(L, buffer);
			lua_gettable(L, -2);
			
			if (lua_isnil(L, -1)) {
				lua_pop(L, 1);
				reader = lua_newuserdata(L, sizeof(Reader)); /* [readers, ud] */
				l_setmetatable(L, -1, READER_META);
				lua_pushlightuserdata(L, buffer);	/* [readers, rd, buf] */
				lua_pushvalue(L, -2);	/* [readers, rd, buf, rd] */
				lua_rawset(L, -4);
				buffer->rd = true;
			} else {
				reader = (Reader*)lua_touserdata(L, -1);
			}
		}
		
		if (top >= 3) {
			offset = (size_t)luaL_checkinteger(L, 3);
			if (offset >= buffer->datasiz)
				offset = 0;
		}
		
		if (top >= 4) {
			length = (size_t)luaL_checkinteger(L, 4);
		}
		
		if (offset + length > buffer->datasiz)
			length = buffer->datasiz - offset;
		
		reader_init(reader, buffer->data + offset, length);
	} else {
		Reader *reader = lua_newuserdata(L, sizeof(Reader)); /* [readers, ud] */
		l_setmetatable(L, -1, READER_META);
		reader_init(reader, NULL, 0);
	}
	return 1;
}
Ejemplo n.º 4
0
void conn_info_init(struct conn_info *info)
{
    info->refcount = 0;
    info->authenticated = false;

    memset(&info->addr, 0, sizeof(info->addr));
    memset(info->dsn, 0, sizeof(info->dsn));

    reader_init(&info->reader);

    info->last_active = -1;
    info->current_buf = NULL;

    STAILQ_INIT(&info->cmd_queue);
    STAILQ_INIT(&info->ready_queue);
    STAILQ_INIT(&info->waiting_queue);
    STAILQ_INIT(&info->buf_times);
    TAILQ_INIT(&info->data);
    TAILQ_INIT(&info->local_data);

    ATOMIC_SET(info->send_bytes, 0);
    ATOMIC_SET(info->recv_bytes, 0);
    ATOMIC_SET(info->completed_commands, 0);
    info->status = DISCONNECTED;
}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: HPDCS/ARC
void *run_read(void *args){
	unsigned int k,j;
	unsigned int *ll;
	struct reader_slot *rd_slt; 
	unsigned int id;
	rd_slt= reader_init(reg);
	id = get_id(rd_slt);
	printf("[%u]RD: START\n", id);
	
	//sleep(1);
	while(!start);

	while(!end || (end_read!=0 && count_read[id] >= end_read)){
		//read
		ll=reg_read(rd_slt);
		//busy loops
		k = busy_loop(busy_read);
		
		count_read[id]++;
		//if((count_read[id]%(end_read/5)) == 0) printf("[%u]RD: Iteration %10u\n",id,count_read[id]);

	}
	printf("[%u]RD: %u read operations performed\n", id,count_read[id]);
	
	pthread_exit(NULL);

}
Ejemplo n.º 6
0
void conn_free(struct connection *conn)
{
    if (conn == NULL) return;
    if (conn->fd != -1) {
        close(conn->fd);
        conn->fd = -1;
    }

    conn->registered = false;

    if (conn->ev != NULL) {
        conn->ev->info = NULL;
        conn_free(conn->ev);
        conn_recycle(conn->ctx, conn->ev);
        conn->ev = NULL;
    }

    if (conn->info == NULL) return;
    struct conn_info *info = conn->info;

    info->status = DISCONNECTED;

    reader_free(&info->reader);
    reader_init(&info->reader);

    EMPTY_CMD_QUEUE(&info->cmd_queue, cmd_next);
    EMPTY_CMD_QUEUE(&info->ready_queue, ready_next);
    EMPTY_CMD_QUEUE(&info->waiting_queue, waiting_next);
}
Ejemplo n.º 7
0
bool checkConfig(const char *urlWithOptions) {
    if (!urlWithOptions) {
        return false;
    }

    GPReader *reader = reader_init(urlWithOptions);
    if (!reader) {
        return false;
    }

    ListBucketResult result = reader->getKeyList();

    if (result.contents.empty()) {
        fprintf(stderr,
                "\nYour configuration works well, however there is no file matching your "
                "prefix.\n");
    } else {
        printBucketContents(result);
        fprintf(stderr, "\nYour configuration works well.\n");
    }

    reader_cleanup(&reader);

    return true;
}
Ejemplo n.º 8
0
/**
 * @param readers Probably should be an empty list.
 */
list *find_all_readers(struct list *readers) {
  int rc;
  struct ftdi_device_list *devlist;
  struct ftdi_context ftdi;

  ftdi_init(&ftdi);
  rc = ftdi_usb_find_all(&ftdi, &devlist, RFID1_VID, RFID1_PID);
  ftdi_deinit(&ftdi);

  if(rc < 0) return NULL;

  struct ftdi_device_list *dp = devlist;
  while(dp){
    struct ftdi_context *c = malloc(sizeof(struct ftdi_context));
    if(c == NULL){
      // Out of memory !!
      // TODO: Clean up
      return NULL;
    }
    ftdi_init(c);

    struct reader *r = reader_create();
    reader_init(r, c, dp->dev);
    list_push(readers, r);

    dp = dp->next;
  }

  ftdi_list_free(&dp);

  return readers;
}
Ejemplo n.º 9
0
/// Setup our environment (e.g., tty modes), process key strokes, then reset the environment.
static void setup_and_process_keys(bool continuous_mode) {
    is_interactive_session = 1;  // by definition this program is interactive
    set_main_thread();
    setup_fork_guards();
    proc_push_interactive(1);
    env_init();
    reader_init();
    // We need to set the shell-modes for ICRNL,
    // in fish-proper this is done once a command is run.
    tcsetattr(STDIN_FILENO, TCSANOW, &shell_modes);
    install_our_signal_handlers();

    if (continuous_mode) {
        std::fwprintf(stderr, L"\n");
        std::fwprintf(stderr,
                      L"To terminate this program type \"exit\" or \"quit\" in this window,\n");
        std::fwprintf(stderr, L"or press [ctrl-%c] or [ctrl-%c] twice in a row.\n",
                      shell_modes.c_cc[VINTR] + 0x40, shell_modes.c_cc[VEOF] + 0x40);
        std::fwprintf(stderr, L"\n");
    }

    process_input(continuous_mode);
    restore_term_mode();
    restore_term_foreground_process_group();
}
Ejemplo n.º 10
0
/// Setup our environment (e.g., tty modes), process key strokes, then reset the environment.
static void setup_and_process_keys(bool continuous_mode) {
    is_interactive_session = 1;    // by definition this program is interactive
    setenv("LC_ALL", "POSIX", 1);  // ensure we're in a single-byte locale
    set_main_thread();
    setup_fork_guards();
    env_init();
    reader_init();
    input_init();
    proc_push_interactive(1);
    signal_set_handlers();
    install_our_signal_handlers();

    if (continuous_mode) {
        printf("\n");
        printf("To terminate this program type \"exit\" or \"quit\" in this window,\n");
        printf("or press [ctrl-C] or [ctrl-D] twice in a row.\n");
        printf("\n");
    }

    process_input(continuous_mode);
    restore_term_mode();
    restore_term_foreground_process_group();
    input_destroy();
    reader_destroy();
}
Ejemplo n.º 11
0
/// Setup our environment (e.g., tty modes), process key strokes, then reset the environment.
void setup_and_process_keys(bool continuous_mode) {
    is_interactive_session = 1;  // by definition this is interactive
    set_main_thread();
    setup_fork_guards();
    wsetlocale(LC_ALL, L"POSIX");
    program_name = L"fish_key_reader";
    env_init();
    reader_init();
    input_init();

    // Installing our handler for every signal (e.g., SIGSEGV) is dubious because it means that
    // signals that might generate a core dump will not do so. On the other hand this allows us
    // to restore the tty modes so the terminal is still usable when we die.
    for (int signo = 1; signo < 32; signo++) {
        signal(signo, signal_handler);
    }

    if (continuous_mode) {
        printf("\n");
        printf("Type 'exit' or 'quit' to terminate this program.\n");
        printf("\n");
        printf("Characters such as [ctrl-D] (EOF) and [ctrl-C] (interrupt)\n");
        printf("have no special meaning and will not terminate this program.\n");
        printf("\n");
    } else {
        set_wait_on_escape_ms(500);
    }

    // TODO: We really should enable keypad mode but see issue #838.
    process_input(continuous_mode);
    restore_term_mode();
}
Ejemplo n.º 12
0
bool downloadS3(const char *urlWithOptions) {
    if (!urlWithOptions) {
        return false;
    }

    int data_len = BUF_SIZE;
    char data_buf[BUF_SIZE];
    bool ret = true;

    thread_setup();

    GPReader *reader = reader_init(urlWithOptions);
    if (!reader) {
        return false;
    }

    do {
        data_len = BUF_SIZE;

        if (!reader_transfer_data(reader, data_buf, data_len)) {
            fprintf(stderr, "Failed to read data from Amazon S3\n");
            ret = false;
            break;
        }

        fwrite(data_buf, (size_t)data_len, 1, stdout);
    } while (data_len && !S3QueryIsAbortInProgress());

    reader_cleanup(&reader);

    thread_cleanup();

    return ret;
}
Ejemplo n.º 13
0
int main(int argc, char* argv[])
{
        reader_init(); /* connect to USB dongle */
        accs_init(); /* init accelerometers */

        printf("Scanning devices...\n");
        for (int i=0; i<4; i++) {
                printf("Address %d, type %s\n", i, reader_get_name(reader_get_byte(i, 0x0F)));
        }

        /*while (1) {
                for (int i=0; i < 4; i++) {
                        unsigned char buffer[128];
                        int bytes = usb_control_msg(
                                h,             // handle obtained with usb_open()
                                USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, // bRequestType
                                i,      // bRequest -> index of acc channel
                                0,              // wValue
                                0,              // wIndex
                                buffer,             // pointer to destination buffer
                                128,  // wLength
                                6000
                                );

                        if (bytes != 7) {
                                printf("Strange report... %d\n", bytes);
                        } else {
                                static int flag_first = 1;
                                struct acc_data data, calmans;
                                calmans = data;

                                data.whoami = (unsigned int) buffer[0];
                                data.x = (short) (buffer[1] | (buffer[2] << 8));
                                data.y = (short) (buffer[3] | (buffer[4] << 8));
                                data.z = (short) (buffer[5] | (buffer[6] << 8));

                                if (flag_first) {
                                        data.x += calmans.x;
                                        data.x /= 2;
                                        data.y += calmans.y;
                                        data.y /= 2;
                                        data.z += calmans.z;
                                        data.z /= 2;
                                        flag_first = 0;
                                }

                                if (data.whoami != 0xff) {
                                        printf("Stats for %d: name %x, data (%.10g, %.10g, %.10g), total %.10g\n", i, data.whoami, (double) (data.x * 9.8 / 162 / 100), (double) (data.y * 9.8 / 162 / 100), (double) ((data.z / 100 + 23) * 9.8 / 162), (double) (sqrt((data.x / 100)*(data.x / 100) + (data.y/100)*(data.y/100) + (data.z/100 + 23)*(data.z/100 + 23)) * 9.8 / 162));
                                }
                        }
                }
                usleep(4000);

        }*/
        
        return 0;
}
Ejemplo n.º 14
0
Archivo: io.c Proyecto: fizx/node-avro
avro_reader_t avro_reader_file(FILE * fp)
{
	struct _avro_reader_file_t *file_reader =
	    malloc(sizeof(struct _avro_reader_file_t));
	if (!file_reader) {
		return NULL;
	}
	memset(file_reader, 0, sizeof(struct _avro_reader_file_t));
	file_reader->fp = fp;
	reader_init(&file_reader->reader, AVRO_FILE_IO);
	return &file_reader->reader;
}
Ejemplo n.º 15
0
Archivo: io.c Proyecto: fizx/node-avro
avro_reader_t avro_reader_memory(const char *buf, int64_t len)
{
	struct _avro_reader_memory_t *mem_reader =
	    malloc(sizeof(struct _avro_reader_memory_t));
	if (!mem_reader) {
		return NULL;
	}
	mem_reader->buf = buf;
	mem_reader->len = len;
	mem_reader->read = 0;
	reader_init(&mem_reader->reader, AVRO_MEMORY_IO);
	return &mem_reader->reader;
}
Ejemplo n.º 16
0
Archivo: io.c Proyecto: 1ack/Impala
avro_reader_t avro_reader_memory(const char *buf, int64_t len)
{
	struct _avro_reader_memory_t *mem_reader =
	    (struct _avro_reader_memory_t *) avro_new(struct _avro_reader_memory_t);
	if (!mem_reader) {
		avro_set_error("Cannot allocate new memory reader");
		return NULL;
	}
	mem_reader->buf = buf;
	mem_reader->len = len;
	mem_reader->read = 0;
	reader_init(&mem_reader->reader, AVRO_MEMORY_IO);
	return &mem_reader->reader;
}
Ejemplo n.º 17
0
Archivo: io.c Proyecto: 1ack/Impala
avro_reader_t avro_reader_file_fp(FILE * fp, int should_close)
{
	struct _avro_reader_file_t *file_reader =
	    (struct _avro_reader_file_t *) avro_new(struct _avro_reader_file_t);
	if (!file_reader) {
		avro_set_error("Cannot allocate new file reader");
		return NULL;
	}
	memset(file_reader, 0, sizeof(struct _avro_reader_file_t));
	file_reader->fp = fp;
	file_reader->should_close = should_close;
	reader_init(&file_reader->reader, AVRO_FILE_IO);
	return &file_reader->reader;
}
Ejemplo n.º 18
0
/*
 * Import data into GPDB.
 * invoked by GPDB, be careful with C++ exceptions.
 */
Datum s3_import(PG_FUNCTION_ARGS) {
    /* Must be called via the external table format manager */
    if (!CALLED_AS_EXTPROTOCOL(fcinfo))
        elog(ERROR, "extprotocol_import: not called by external protocol manager");

    /* Get our internal description of the protocol */
    GPReader *gpreader = (GPReader *)EXTPROTOCOL_GET_USER_CTX(fcinfo);

    /* last call. destroy reader */
    if (EXTPROTOCOL_IS_LAST_CALL(fcinfo)) {
        thread_cleanup();

        if (!reader_cleanup(&gpreader)) {
            ereport(ERROR, (0, errmsg("Failed to cleanup S3 extension: %s",
                                      gpReaderErrorMessage.c_str())));
        }

        EXTPROTOCOL_SET_USER_CTX(fcinfo, NULL);

        PG_RETURN_INT32(0);
    }

    /* first call. do any desired init */
    if (gpreader == NULL) {
        const char *url_with_options = EXTPROTOCOL_GET_URL(fcinfo);

        thread_setup();

        gpreader = reader_init(url_with_options);
        if (!gpreader) {
            ereport(ERROR, (0, errmsg("Failed to init S3 extension, segid = %d, "
                                      "segnum = %d, please check your "
                                      "configurations and net connection: %s",
                                      s3ext_segid, s3ext_segnum, gpReaderErrorMessage.c_str())));
        }

        check_essential_config();

        EXTPROTOCOL_SET_USER_CTX(fcinfo, gpreader);
    }

    char *data_buf = EXTPROTOCOL_GET_DATABUF(fcinfo);
    int32 data_len = EXTPROTOCOL_GET_DATALEN(fcinfo);

    if (!reader_transfer_data(gpreader, data_buf, data_len)) {
        ereport(ERROR,
                (0, errmsg("s3_import: could not read data: %s", gpReaderErrorMessage.c_str())));
    }
    PG_RETURN_INT32(data_len);
}
Ejemplo n.º 19
0
/**
   Main test 
*/
int main( int argc, char **argv )
{
	setlocale( LC_ALL, "" );
	srand( time( 0 ) );

	program_name=L"(ignore)";
	
	say( L"Testing low-level functionality");
	say( L"Lines beginning with '(ignore):' are not errors, they are warning messages\ngenerated by the fish parser library when given broken input, and can be\nignored. All actual errors begin with 'Error:'." );

	proc_init();	
	halloc_util_init();
	event_init();	
	parser_init();
	function_init();
	builtin_init();
	reader_init();
	env_init();

	test_util();
	test_escape();
	test_convert();
	test_tok();
	test_parser();
	test_expand();
	test_path();
	
	say( L"Encountered %d errors in low-level tests", err_count );

	/*
	  Skip performance tests for now, since they seem to hang when running from inside make (?)
	*/
//	say( L"Testing performance" );
//	perf_complete();
		
	env_destroy();
	reader_destroy();	
	parser_destroy();
	function_destroy();
	builtin_destroy();
	wutil_destroy();
	event_destroy();
	proc_destroy();
	halloc_util_destroy();
	
}
int net_device_platform_init() {
    config_section_t * sect = NULL;
    net_device_t * net_device = NULL;
    char type[16];

    config_cnf_t * cnf = config_get();
    if(cnf == NULL) return 1;

    for(sect = (config_section_t *)list_head(cnf->sections); sect != NULL; sect = (config_section_t *)list_item_next((void*)sect)) {
        config_section_get_str(sect, "type", NULL, type, strlen(type));
        if (type == NULL)
            return 2;

        if (strcmp(type, "led") == 0) {
            if(led_init(sect) != 0)
                return 3;

            net_device = (net_device_t *)malloc(sizeof(net_device_t));
            if(net_device == NULL)
                return 4;
            net_device_construct(net_device, sect, led_net_callback);

        } else if (strcmp(type, "button") == 0) {
            if(button_init(sect) != 0)
                return 3;

            net_device = (net_device_t *)malloc(sizeof(net_device_t));
            if(net_device == NULL)
                return 4;
            net_device_construct(net_device, sect, NULL);

        } else if (strcmp(type, "reader") == 0) {
            if(reader_init(sect) != 0)
                return 3;

            net_device = (net_device_t *)malloc(sizeof(net_device_t));
            if(net_device == NULL)
                return 4;
            net_device_construct(net_device, sect, reader_net_callback);
        }
        // etc. new drivers
    }

    return 0;
}
Ejemplo n.º 21
0
int main(int argc, char *argv[])
{
	Event event; 
	Reader reader;

	/* Init struct */
	clear_event(&event);

	reader_init(&reader, argv[1]);

	evh_register_handler(&reader, &lostRecordsHandler);
	/*
	evh_register_handler(&reader, &backInflightQueueBlockedHandler);
	evh_register_handler(&reader, &backInflightQueueUnblockedHandler);
	
	evh_register_handler(&reader, &frontSharedRingQueueBlockedHandler);
	evh_register_handler(&reader, &frontSharedRingQueueUnblockedHandler);
	
	evh_register_handler(&reader, &frontGrantQueueBlockedHandler);
	evh_register_handler(&reader, &frontGrantQueueUnblockedHandler);
	*/
	evh_register_handler(&reader, &frontRequestQueueBlockedHandler);
	evh_register_handler(&reader, &frontRequestQueueUnblockedHandler);

	evh_register_handler(&reader, &backRequestQueueBlockedHandler);
	evh_register_handler(&reader, &backRequestQueueUnblockedHandler);

	evh_register_handler(&reader, &frontSharedRingRespQueueBlockedHandler);
	evh_register_handler(&reader, &frontSharedRingRespQueueUnblockedHandler);
	
	evh_register_handler(&reader, &backRequestInterruptSendHandler);
	evh_register_handler(&reader, &backRequestInterruptReceiveHandler);

	evh_register_handler(&reader, &backResponseInterruptSendHandler);
	evh_register_handler(&reader, &backResponseInterruptReceiveHandler);
	
	reader_loop(&reader);

	reader_exit(&reader);

	return 0;
}
Ejemplo n.º 22
0
int main(int argc, char *argv[])
{
	Event event; 
	Reader reader;

	/* Init struct */
	clear_event(&event);

	reader_init(&reader, argv[1]);

	evh_register_handler(&reader, &lostRecordsHandler);
	evh_register_handler(&reader, &exitToXenHandler);
	evh_register_handler(&reader, &exitToGuestHandler);

	reader_loop(&reader);

	reader_exit(&reader);

	return 0;
}
Ejemplo n.º 23
0
/*
** line1, ... = buffer:getline(num)
** 
** content will be shifted
*/
static int lbuffer_getline(lua_State *L)
{
	Buffer *buffer = buffer_lcheck(L, 1);
	size_t num = (size_t)luaL_optint(L, 2, 1);
	Reader rd;

	reader_init(&rd, buffer->data, buffer->datasiz);

	for (size_t i = 0; i < num ; i++) {
		size_t len;
		const char *str = reader_getline(&rd, &len);
		if (str != NULL)
			lua_pushlstring(L, str, len);
		else
			lua_pushnil(L);
	}	
	
	buffer_shift(buffer, (size_t)(rd.data - rd.mem));
	
	return (int)num;
}
Ejemplo n.º 24
0
int main(int argc, char *argv[])
{
	Event event; 
	Reader reader;

	/* Init struct */
	clear_event(&event);

	reader_init(&reader, argv[1]);

	evh_register_handler(&reader, &switchInfprevHandler);
	evh_register_handler(&reader, &switchInfnextHandler);
	evh_register_handler(&reader, &switchSchedHandler);
	evh_register_handler(&reader, &domainWakeHandler);
	evh_register_handler(&reader, &lostRecordsHandler);

	reader_loop(&reader);

	reader_exit(&reader);

	return 0;
}
Ejemplo n.º 25
0
main()
{
	int	ret;
	long	a = 0xffffffffffffffff;

	if (ret = kp_init()) {
		printf("ret %d\n", ret);
	}

	reader_init();

	printf("a 0x%lx \n& 0x%lx\n s 0x%lx\n",
		a, TIME_STAMP_BYTES(a), TIME_STAMP_BYTES(a)<<TIME_SHIFT_ORDER);

	test_reader();
	// work
	dd_work();

	// read

	// exit
	dd_exit();
}
Ejemplo n.º 26
0
int main(int argc, char *argv[])
{
	Event event; 
	Reader reader;

	/* Init struct */
	clear_event(&event);

	reader_init(&reader, argv[1]);

	evh_register_handler(&reader, &numEventsHandler);
	evh_register_handler(&reader, &numExceptionsHandler);
	evh_register_handler(&reader, &numExceptionsInXenHandler);
	evh_register_handler(&reader, &numInterruptsHandler);
	evh_register_handler(&reader, &numInterruptsInXenHandler);
	evh_register_handler(&reader, &numHypercallsHandler);
	evh_register_handler(&reader, &lostRecordsHandler);

	reader_loop(&reader);

	reader_exit(&reader);

	return 0;
}
Ejemplo n.º 27
0
Archivo: main.c Proyecto: mariuz/haiku
/*-------------------------------------------------------------------------*/
int main (int argc, char *argv[])

{
  int i;

  reader_init();

  /* Get arguments, set up defaults */
  parseargs(argc, argv);
  if (!aFiles.size)
  {
    if (add_expfile(&aFiles, "*.c"))
      exit_nomem(" (main: add_expfile)");
  }
  if (!sObjExt)
    sObjExt = ".o";

  if (!aSrcExt.size)
  {
    if (array_addfile(&aSrcExt, ".c") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
    if (array_addfile(&aSrcExt, ".cc") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
    if (array_addfile(&aSrcExt, ".cp") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
    if (array_addfile(&aSrcExt, ".cpp") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
    if (array_addfile(&aSrcExt, ".cxx") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
    if (array_addfile(&aSrcExt, ".C") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
    if (array_addfile(&aSrcExt, ".CC") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
    if (array_addfile(&aSrcExt, ".CP") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
    if (array_addfile(&aSrcExt, ".CPP") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
    if (array_addfile(&aSrcExt, ".CXX") || array_addfile(&aObjExt, NULL))
      exit_nomem(" (main: add suffix)");
  }

  if (bVerbose)
  {
    printf("MkDepend %s -- Make Dependency Generator\n", VERSION);
    putchar('\n');
  }

  /* Look for the Makefile to modify */
  if (sMake)
  {
    bMakeExists = !stat(sMake, &aMakeStat);
  }
  else if (!sDepfile)
  {
    sMake = "Makefile";
    bMakeExists = !stat(sMake, &aMakeStat);
    if (!bMakeExists)
    {
      sMake = "makefile";
      bMakeExists = !stat(sMake, &aMakeStat);
    }
    if (!bMakeExists)
    {
      sMake = "Makefile.mk";
      bMakeExists = !stat(sMake, &aMakeStat);
    }
    if (!bMakeExists)
    {
      sMake = "makefile.mk";
      bMakeExists = !stat(sMake, &aMakeStat);
    }
    if (!bMakeExists)
    {
      sMake = "GNUMakefile";
      bMakeExists = !stat(sMake, &aMakeStat);
    }
    if (!bMakeExists)
      sMake = "Makefile";
  }

  /* Add the source files to the tree */
  if (!aFiles.size)
  {
    printf("%s: No files given.\n", aPgmName);
    set_rc(RETURN_WARN, TRUE);
  }
  else
  {
      struct stat aStat; /* buffer for stat() */

      for (i = 0; i < aFiles.size; i++)
      {
          if (stat(aFiles.strs[i], &aStat))
          {
              printf("%s: Warning: Can't find source '%s'.\n", aPgmName
                    , aFiles.strs[i]);
              set_rc(RETURN_WARN, FALSE);
          }
          else if (nodes_addsource(aFiles.strs[i], FALSE))
              exit_nomem(" (main: add source)");
      }

      /* If this leaves us with no source files at all, readfiles()
       * will complain.
       */
  }

  /* Mark the exceptional files */
  for (i = 0; i < aAvoid.size; i++)
  {
    if (nodes_addsource(aAvoid.strs[i], TRUE))
      exit_nomem(" (main: add avoided source)");
  }

  /* Read and analyse all those files */
  set_rc(readfiles(), 0);

  /* Handle the selection of files */
  if (IS_SELECT_MODE)
  {
    Node * pNode;

    /* First, mark all nodes with selected files */
    for (i = 0; i < aSelect.size; i++)
    {
      pNode = nodes_find(aSelect.strs[i]);
      if (pNode)
        pNode->flags |= NODE_SELECT;
    }

    /* Now walk the tree and propagate the select information */
    nodes_initwalk();
    while (NULL != (pNode = nodes_inorder()) )
    {
      if (!(pNode->flags & (NODE_IGNORE)) 
       && (pNode->flags & (NODE_SOURCE|NODE_AVOID)) == NODE_SOURCE)
      {
        NODES_UNMARK(pNode);
        nodes_mark_select(pNode);
      }
    }
  }

  if (returncode < RETURN_ERROR && sMake)
    set_rc(output(TRUE), 0);

  if (returncode < RETURN_ERROR && sMake && bVerbose)
    printf("%s '%s'.\n", bMakeExists ? "Updated" : "Created", sMake);

  if (returncode < RETURN_ERROR && sDepfile)
    set_rc(bFlat ? output(FALSE) : output_tree(), 0);

  if (returncode < RETURN_ERROR && sDepfile && bVerbose)
    printf("Created '%s'.\n", sDepfile);

  return (returncode == RETURN_WARN && bNoWarnExit) ? RETURN_OK : returncode;
}
Ejemplo n.º 28
0
int main( int argc, char **argv )
{    
    struct stat tmp;
	int res=1;
	const char *cmd=0;
	int my_optind=0;

	set_main_thread();
    setup_fork_guards();
    
	wsetlocale( LC_ALL, L"" );
	is_interactive_session=1;
	program_name=L"fish";

    stat("----------FISH_HIT_MAIN----------", &tmp);

	my_optind = fish_parse_opt( argc, argv, &cmd );

	/*
	  No-exec is prohibited when in interactive mode
	*/
	if( is_interactive_session && no_exec)
	{
		debug( 1, _(L"Can not use the no-execute mode when running an interactive session") );
		no_exec = 0;
	}
    
	const struct config_paths_t paths = determine_config_directory_paths(argv[0]);
    	
	proc_init();	
	event_init();	
	wutil_init();
	//parser_init();
	builtin_init();
	function_init();
	env_init(&paths);
	reader_init();
	history_init();

    parser_t &parser = parser_t::principal_parser();

    if (g_log_forks)
        printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);

	if( read_init(paths) )
	{
		if( cmd != 0 )
		{
			wchar_t *cmd_wcs = str2wcs( cmd );
			res = parser.eval( cmd_wcs, 0, TOP );
			free(cmd_wcs);
			reader_exit(0, 0);
		}
		else
		{
			if( my_optind == argc )
			{
				res = reader_read( STDIN_FILENO, 0 );
			}
			else
			{
				char **ptr; 
				char *file = *(argv+(my_optind++));
				int i; 
				int fd;
				wchar_t *rel_filename, *abs_filename;

                
				if( ( fd = open(file, O_RDONLY) ) == -1 )
				{
					wperror( L"open" );
					return 1;
				}
                
                // OK to not do this atomically since we cannot have gone multithreaded yet
                set_cloexec(fd);
                
				if( *(argv+my_optind))
				{
                    wcstring sb;
					for( i=1,ptr = argv+my_optind; *ptr; i++, ptr++ )
					{
						if( i != 1 )
                            sb.append( ARRAY_SEP_STR );
                        sb.append( str2wcstring( *ptr ));
					}
				
					env_set( L"argv", sb.c_str(), 0 );
				}

				rel_filename = str2wcs( file );
				abs_filename = wrealpath( rel_filename, 0 );

				if( !abs_filename )
				{
					abs_filename = wcsdup(rel_filename);
				}

				reader_push_current_filename( intern( abs_filename ) );
				free( rel_filename );
				free( abs_filename );

				res = reader_read( fd, 0 );

				if( res )
				{
					debug( 1, 
					       _(L"Error while reading file %ls\n"), 
					       reader_current_filename()?reader_current_filename(): _(L"Standard input") );
				}				
				reader_pop_current_filename();
			}
		}
	}
	
	proc_fire_event( L"PROCESS_EXIT", EVENT_EXIT, getpid(), res );
	
	history_destroy();
	proc_destroy();
	builtin_destroy();
	reader_destroy();
	parser.destroy();
	wutil_destroy();
	event_destroy();
	
	env_destroy();
	
    if (g_log_forks)
        printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
    
	return res?STATUS_UNKNOWN_COMMAND:proc_get_last_status();	
}
Ejemplo n.º 29
0
int main(int argc, char **argv) {
    int res = 1;
    int my_optind = 0;

    program_name = L"fish";
    set_main_thread();
    setup_fork_guards();
    signal_unblock_all();
    setlocale(LC_ALL, "");
    fish_setlocale();

    // struct stat tmp;
    // stat("----------FISH_HIT_MAIN----------", &tmp);

    if (!argv[0]) {
        static const char *dummy_argv[2] = {"fish", NULL};
        argv = (char **)dummy_argv;  //!OCLINT(parameter reassignment)
        argc = 1;                    //!OCLINT(parameter reassignment)
    }
    fish_cmd_opts_t opts;
    my_optind = fish_parse_opt(argc, argv, &opts);

    // No-exec is prohibited when in interactive mode.
    if (is_interactive_session && no_exec) {
        debug(1, _(L"Can not use the no-execute mode when running an interactive session"));
        no_exec = 0;
    }

    // Only save (and therefore restore) the fg process group if we are interactive. See issues
    // #197 and #1002.
    if (is_interactive_session) {
        save_term_foreground_process_group();
    }

    const struct config_paths_t paths = determine_config_directory_paths(argv[0]);
    env_init(&paths);
    // Set features early in case other initialization depends on them.
    // Start with the ones set in the environment, then those set on the command line (so the
    // command line takes precedence).
    if (auto features_var = env_get(L"fish_features")) {
        for (const wcstring &s : features_var->as_list()) {
            mutable_fish_features().set_from_string(s);
        }
    }
    mutable_fish_features().set_from_string(opts.features);
    proc_init();
    builtin_init();
    misc_init();
    reader_init();

    parser_t &parser = parser_t::principal_parser();

    const io_chain_t empty_ios;
    if (read_init(paths)) {
        // Stomp the exit status of any initialization commands (issue #635).
        proc_set_last_status(STATUS_CMD_OK);

        // Run post-config commands specified as arguments, if any.
        if (!opts.postconfig_cmds.empty()) {
            res = run_command_list(&opts.postconfig_cmds, empty_ios);
        }

        if (!opts.batch_cmds.empty()) {
            // Run the commands specified as arguments, if any.
            if (is_login) {
                // Do something nasty to support OpenSUSE assuming we're bash. This may modify cmds.
                fish_xdm_login_hack_hack_hack_hack(&opts.batch_cmds, argc - my_optind,
                                                   argv + my_optind);
            }
            res = run_command_list(&opts.batch_cmds, empty_ios);
            reader_exit(0, 0);
        } else if (my_optind == argc) {
            // Implicitly interactive mode.
            res = reader_read(STDIN_FILENO, empty_ios);
        } else {
            char *file = *(argv + (my_optind++));
            int fd = open(file, O_RDONLY);
            if (fd == -1) {
                perror(file);
            } else {
                // OK to not do this atomically since we cannot have gone multithreaded yet.
                set_cloexec(fd);

                wcstring_list_t list;
                for (char **ptr = argv + my_optind; *ptr; ptr++) {
                    list.push_back(str2wcstring(*ptr));
                }
                env_set(L"argv", ENV_DEFAULT, list);

                const wcstring rel_filename = str2wcstring(file);

                reader_push_current_filename(rel_filename.c_str());

                res = reader_read(fd, empty_ios);

                if (res) {
                    debug(1, _(L"Error while reading file %ls\n"),
                          reader_current_filename() ? reader_current_filename()
                                                    : _(L"Standard input"));
                }
                reader_pop_current_filename();
            }
        }
    }

    int exit_status = res ? STATUS_CMD_UNKNOWN : proc_get_last_status();

    // TODO: The generic process-exit event is useless and unused.
    // Remove this in future.
    proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, getpid(), exit_status);
    event_fire_generic(L"fish_exit");

    restore_term_mode();
    restore_term_foreground_process_group();

    if (g_profiling_active) {
        parser.emit_profiling(s_profiling_output_filename);
    }

    history_save_all();
    proc_destroy();
    exit_without_destructors(exit_status);
    return EXIT_FAILURE;  // above line should always exit
}
Ejemplo n.º 30
0
int main(int argc, char **argv)
{
    int res=1;
    int my_optind=0;

    set_main_thread();
    setup_fork_guards();

    wsetlocale(LC_ALL, L"");
    is_interactive_session=1;
    program_name=L"fish";

    //struct stat tmp;
    //stat("----------FISH_HIT_MAIN----------", &tmp);

    std::vector<std::string> cmds;
    my_optind = fish_parse_opt(argc, argv, &cmds);

    /*
      No-exec is prohibited when in interactive mode
    */
    if (is_interactive_session && no_exec)
    {
        debug(1, _(L"Can not use the no-execute mode when running an interactive session"));
        no_exec = 0;
    }

    /* Only save (and therefore restore) the fg process group if we are interactive. See #197, #1002 */
    if (is_interactive_session)
    {
        save_term_foreground_process_group();
    }

    const struct config_paths_t paths = determine_config_directory_paths(argv[0]);

    proc_init();
    event_init();
    wutil_init();
    builtin_init();
    function_init();
    env_init(&paths);
    reader_init();
    history_init();
    /* For setcolor to support term256 in config.fish (#1022) */
    update_fish_term256();

    parser_t &parser = parser_t::principal_parser();

    if (g_log_forks)
        printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);

    const io_chain_t empty_ios;
    if (read_init(paths))
    {
        /* Stop the exit status of any initialization commands (#635) */
        proc_set_last_status(STATUS_BUILTIN_OK);

        /* Run the commands specified as arguments, if any */
        if (! cmds.empty())
        {
            /* Do something nasty to support OpenSUSE assuming we're bash. This may modify cmds. */
            if (is_login)
            {
                fish_xdm_login_hack_hack_hack_hack(&cmds, argc - my_optind, argv + my_optind);
            }
            for (size_t i=0; i < cmds.size(); i++)
            {
                const wcstring cmd_wcs = str2wcstring(cmds.at(i));
                res = parser.eval(cmd_wcs, empty_ios, TOP);
            }
            reader_exit(0, 0);
        }
        else
        {
            if (my_optind == argc)
            {
                res = reader_read(STDIN_FILENO, empty_ios);
            }
            else
            {
                char **ptr;
                char *file = *(argv+(my_optind++));
                int i;
                int fd;


                if ((fd = open(file, O_RDONLY)) == -1)
                {
                    wperror(L"open");
                    return 1;
                }

                // OK to not do this atomically since we cannot have gone multithreaded yet
                set_cloexec(fd);

                if (*(argv+my_optind))
                {
                    wcstring sb;
                    for (i=1,ptr = argv+my_optind; *ptr; i++, ptr++)
                    {
                        if (i != 1)
                            sb.append(ARRAY_SEP_STR);
                        sb.append(str2wcstring(*ptr));
                    }

                    env_set(L"argv", sb.c_str(), 0);
                }

                const wcstring rel_filename = str2wcstring(file);
                const wchar_t *abs_filename = wrealpath(rel_filename, NULL);

                if (!abs_filename)
                {
                    abs_filename = wcsdup(rel_filename.c_str());
                }

                reader_push_current_filename(intern(abs_filename));
                free((void *)abs_filename);

                res = reader_read(fd, empty_ios);

                if (res)
                {
                    debug(1,
                          _(L"Error while reading file %ls\n"),
                          reader_current_filename()?reader_current_filename(): _(L"Standard input"));
                }
                reader_pop_current_filename();
            }
        }
    }

    proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, getpid(), res);

    restore_term_mode();
    restore_term_foreground_process_group();
    history_destroy();
    proc_destroy();
    builtin_destroy();
    reader_destroy();
    parser.destroy();
    wutil_destroy();
    event_destroy();

    env_destroy();

    if (g_log_forks)
        printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);

    exit_without_destructors(res ? STATUS_UNKNOWN_COMMAND : proc_get_last_status());
    return EXIT_FAILURE; //above line should always exit
}