예제 #1
0
int main(int argc, char *argv[])
{
	int i;

	for (i = 1; i < argc; i++)
	{
		if (!strcmp(argv[i], "-q"))
			verbose = FALSE;

		else if (!strcmp(argv[i], "-a"))
			max_addr = str_to_uint32(argv[++i]) - 1;

		else if (!strcmp(argv[i], "-o"))
			min_addr = str_to_uint32(argv[++i]);

		else if (!strcmp(argv[i], "-f"))
			filler = str_to_uint32(argv[++i]) & 0xff;

		else if (!strncmp(argv[i], "-h", 2))			/* -h or -help */
		{
			syntax();
			return(0);
		}
		else
		{
			infilename = argv[i];
			outfilename = argv[++i];
		}
	}

	if (infilename == NULL)
	{
		syntax();
		fprintf(stderr, "\n** No input filename specified\n");
		return(1);
	}

	if (outfilename == NULL)
	{
		syntax();
		fprintf(stderr, "\n** No output filename specified\n");
		return(1);
	}

	if ((infile = fopen(infilename, "rb")) != NULL)
	{
		process();
		fclose(infile);
		return(0);
	}
	else
	{
		printf("Input file %s not found\n", infilename);
		return(2);
	}
}
예제 #2
0
파일: fsub.c 프로젝트: minus3theta/FPU
//#if 0
int main(void) {
  
  union data_32bit a,b;
  union data_32bit diff;

  int select_flag;
  char select_buf[10];
  printf("select import form :\n");
  printf("float -> 0\n");
  printf("32bit -> 1 (others)\n");
  gets(select_buf);
  sscanf(select_buf, "%d\n", &select_flag);

  if (select_flag == 0) {
    printf("a.fl32 : "); scanf("%f", &a.fl32);
    printf("b.fl32 : "); scanf("%f", &b.fl32);
  } else {
    char a_str[35], b_str[35];
    printf("詰めて入力しても可\n");
    printf("- --exp--- -------fraction--------\n");
    printf("a(32bit) :\n");
    gets(a_str);
    printf("b(32bit) :\n");
    gets(b_str);
    a.uint32 = str_to_uint32(delete_space(a_str));
    b.uint32 = str_to_uint32(delete_space(b_str));
  }
    
  printf("\n");

  printf("-- a --\n");
  print_data(a);
  
  printf("\n");

  printf("-- b --\n");
  print_data(b);

  printf("\n");

  diff.uint32 = fsub(a.uint32, b.uint32);
  
  printf("-- diff --\n");
  print_data(diff);

  printf("\n");

  union data_32bit test;

  printf(" -- correct answer --\n");
  test.fl32 = a.fl32 - b.fl32;
  print_data(test);

  return(0);
}
예제 #3
0
파일: main.c 프로젝트: GDXN/bano
static int get_cmdline_info(cmdline_info_t* ci, int ac, char** av)
{
  int i;

  if (ac & 1)
  {
    BANO_PERROR();
    return -1;
  }

  ci->flags = 0;
  ci->op_name = NULL;
  ci->op_key = 0;
  ci->op_val = 0;
  ci->node_addr = 0;

  for (i = 0; i != ac; i += 2)
  {
    const char* const k = av[i + 0];
    const char* const v = av[i + 1];

    if (strcmp(k, "-op_name") == 0)
    {
      /* list, set, get, listen */
      ci->flags |= CMDLINE_FLAG_OP_NAME;
      ci->op_name = v;
    }
    else if (strcmp(k, "-op_key") == 0)
    {
      ci->flags |= CMDLINE_FLAG_OP_KEY;
      ci->op_key = str_to_uint32(v);
    }
    else if (strcmp(k, "-op_val") == 0)
    {
      ci->flags |= CMDLINE_FLAG_OP_VAL;
      ci->op_val = str_to_uint32(v);
    }
    else if (strcmp(k, "-op_ack") == 0)
    {
      if (strcmp(v, "1") == 0) ci->flags |= CMDLINE_FLAG_OP_ACK;
    }
    else if (strcmp(k, "-node_addr") == 0)
    {
      ci->flags |= CMDLINE_FLAG_NODE_ADDR;
      ci->node_addr = str_to_uint32(v);
    }
  }

  return 0;
}
예제 #4
0
static GSList * parse_group_list(gchar *string)
{
	gchar **groups_list;
	gchar **groups_item;
	uint32_t group_id;
	GSList *result = NULL;

	if (! string) {
		RETURN_NO_LOG NULL;
	}
	groups_list = g_strsplit(string, ",", 0);
	groups_item = groups_list;
	while (*groups_item) {
		/* read group */
		if (!str_to_uint32(*groups_item, &group_id)) {
			log_message(WARNING, DEBUG_AREA_MAIN,
					"session_authtype: Invalid group identifier (%s)",
					*groups_item);
			break;
		}
		result = g_slist_append(result, GUINT_TO_POINTER(group_id));
		groups_item++;
	}
	g_strfreev(groups_list);

	return result;
}
예제 #5
0
static int
process_io_buffer_parse(const char *buf, struct mail_stats *stats)
{
	const char *const *tmp;

	tmp = t_strsplit(buf, "\n");
	for (; *tmp != NULL; tmp++) {
		if (strncmp(*tmp, "rchar: ", 7) == 0) {
			if (str_to_uint64(*tmp + 7, &stats->read_bytes) < 0)
				return -1;
		} else if (strncmp(*tmp, "wchar: ", 7) == 0) {
			if (str_to_uint64(*tmp + 7, &stats->write_bytes) < 0)
				return -1;
		} else if (strncmp(*tmp, "syscr: ", 7) == 0) {
			if (str_to_uint32(*tmp + 7, &stats->read_count) < 0)
				return -1;
		} else if (strncmp(*tmp, "syscw: ", 7) == 0) {
			if (str_to_uint32(*tmp + 7, &stats->write_count) < 0)
				return -1;
		}
	}
	return 0;
}
예제 #6
0
파일: fneg.c 프로젝트: minus3theta/FPU
int main(void) {
  
  union data_32bit a;
  union data_32bit neg;

  int select_flag;
  char select_buf[10];
  printf("select import form :\n");
  printf("float -> 0\n");
  printf("32bit -> 1 (others)\n");
  gets(select_buf);
  sscanf(select_buf, "%d\n", &select_flag);

  if (select_flag == 0) {
    printf("a.fl32 : "); scanf("%f", &a.fl32);
  } else {
    char a_str[35];
    printf("詰めて入力しても可\n");
    printf("- --exp--- -------fraction--------\n");
    printf("a(32bit) :\n");
    gets(a_str);
    a.uint32 = str_to_uint32(delete_space(a_str));
  }
    
  printf("\n");

  printf("-- a --\n");
  print_data(a);
  
  printf("\n");

  neg.uint32 = fneg(a.uint32);
  
  printf("-- neg --\n");
  print_data(neg);

  printf("\n");

  union data_32bit test;

  printf(" -- correct answer --\n");
  test.fl32 = a.fl32 * (-1);
  print_data(test);

  return(0);
}
예제 #7
0
int parse_uint32(uint32_t *x, char *payload)
{
	int errcode;

	if (bug_on(!x))
		return -err_internal;

	payload = strtok(payload, " ,");
	if (!payload)
		return -err_parse_no_args;

	errcode = str_to_uint32(payload, x, 0);
	if (errcode < 0)
		return errcode;

	return 0;
}
예제 #8
0
int CIMXML_Parser::_find_uint32_attr(
    const char** attrs,
    const char* name,
    uint32& x)
{
    const char* value;

    if (_find_required_attr(attrs, name, value) != 0)
        return -1;

    if (str_to_uint32(value, x) != 0)
    {
        raise("bad value %s attribute: %s", name, value);
        return -1;
    }

    return 0;
}
static struct mail_search_arg *
arg_new_interval(struct mail_search_build_context *ctx,
		 enum mail_search_arg_type type)
{
	struct mail_search_arg *sarg;
	const char *value;
	uint32_t interval;

	sarg = mail_search_build_new(ctx, type);
	if (mail_search_parse_string(ctx->parser, &value) < 0)
		return NULL;

	if (str_to_uint32(value, &interval) < 0 || interval == 0) {
		ctx->_error = "Invalid search interval parameter";
		return NULL;
	}
	sarg->value.search_flags = MAIL_SEARCH_ARG_FLAG_USE_TZ;
	sarg->value.time = ioloop_time - interval;
	sarg->value.date_type = MAIL_SEARCH_DATE_TYPE_RECEIVED;
	return sarg;
}
예제 #10
0
파일: req.c 프로젝트: budlover/441-bt
rcb_t *load_get_chunks(const char *get_chunk_file, int *cnt)
{
    FILE *fp = NULL;
    char buff[GET_LINE_LEN + 1];
    uint8_t hash[SHA1_HASH_SIZE]; //original hash, not hash string
    uint32_t wr_chk_id;
    chunk_map_t *map;
    int req_cnt = 0;
    
    rcb_t *head = NULL;
    rcb_t *p = NULL;

    fp = fopen(get_chunk_file, "r");
    if(!fp)
    {
        return NULL;
    }

    // load the chunks
    while(NULL != fgets(buff, GET_LINE_LEN + 1, fp))
    {
        char *str;

        p = create_rcb();
        if(NULL == p)
            goto err;

        str = strtok(buff, " \n");
        if(NULL == str)
           goto err;
        if(0 != str_to_uint32(buff, &wr_chk_id))
           goto err; 
        p->wr_chk_id = wr_chk_id;

        str = strtok(NULL, " \n");
        if(NULL == str)
           goto err;
        if(strlen(str) != SHA1_HASH_SIZE * 2)
            goto err; 
        hex2binary(str, SHA1_HASH_SIZE * 2, hash);

        HT_FIND(&g_chunkmap_ht, chunk_map_t, hash, hash, map);
        if(!map)
        {
            free(p);
        }
        else
        {
            p->chk_map = map;
            p->next = head;
            head = p;
            req_cnt++;
        }
    }
    fclose(fp);
    *cnt = req_cnt;
    return head;
    
err:
    if(fp)
        fclose(fp);

    if(p)
        free(p);
    
    *cnt = req_cnt;

    return head;
}