示例#1
0
文件: lwsd_conf.c 项目: Qiware/tanlz
/******************************************************************************
 **函数名称: lwsd_conf_load_comm
 **功    能: 加载公共配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_load_comm(xml_tree_t *xml, lwsd_conf_t *conf, log_cycle_t *log)
{
    xml_node_t *node, *fix;

    /* > 加载结点ID */
    node = xml_query(xml, ".LISTEND.ID");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Get node id failed!");
        return -1;
    }

    conf->nid = str_to_num(node->value.str);

    /* > 加载工作路径 */
    node = xml_query(xml, ".LISTEND.WORKDIR");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Get work directory failed!");
        return -1;
    }

    snprintf(conf->wdir, sizeof(conf->wdir), "%s/%d", node->value.str, conf->nid);  /* 工作路径 */

    /* > 分发队列配置 */
    fix = xml_query(xml, ".LISTEND.DISTQ");
    if (NULL == fix) {
        log_error(log, "Get distribute queue failed!");
        return -1;
    }

    node = xml_search(xml, fix, "NUM");
    if (NULL == node) {
        log_error(log, "Get number of distribue queue failed!");
        return -1;
    }

    conf->distq.num = str_to_num(node->value.str);

    node = xml_search(xml, fix, "MAX");
    if (NULL == node) {
        log_error(log, "Get the max container of distribue queue failed!");
        return -1;
    }

    conf->distq.max = str_to_num(node->value.str);

    node = xml_search(xml, fix, "SIZE");
    if (NULL == node) {
        log_error(log, "Get the size of distribue queue failed!");
        return -1;
    }

    conf->distq.size = str_to_num(node->value.str);

    return 0;
}
示例#2
0
var ini_read_var(STRING *filename, char* section, STRING *entry, var defaultValue)
{
	STRING *tmp = "#64";
	STRING *def = "#64";
	ini_read(tmp, filename, section, entry, str_for_num(def, defaultValue));
	return str_to_num(tmp);
}
示例#3
0
文件: monitor.c 项目: huguesb/mipsim
/*!
    \brief Syscall handler
    
    Support for some syscalls required by project spec.
*/
int mips_syscall(MIPS *m, int code)
{
    switch ( code )
    {
        case 1 :
        {
            MIPS_Native a0 = mips_get_reg(m, A0);
            mipsim_printf(IO_MONITOR, "%d", a0);
            break;
        }
            
        case 4 :
        {
            MIPS_Native a0 = mips_get_reg(m, A0);
            char *s = fetch_str(m, a0);
            mipsim_printf(IO_MONITOR, "%s", s);
            free(s);
            break;
        }
            
        case 5 :
        {
            char buf[SYSCALL_BUF_SZ];
            mipsim_read(IO_MONITOR, 0, buf, SYSCALL_BUF_SZ);
            
            mips_set_reg(m, V0, str_to_num(buf, NULL, NULL));
            break;
        }
            
        case 8 :
        {
            MIPS_Native a0 = mips_get_reg(m, A0);
            MIPS_Native a1 = mips_get_reg(m, A1);
            
            char *buffer = (char*)malloc(a1);
            mipsim_read(IO_MONITOR, 0, buffer, a1);
            for ( MIPS_Native i = 0; i < a1; ++i )
                mips_write_b(m, a0 + i, buffer[i], NULL);
            free(buffer);
            
            break;
        }
            
        case 10 :
            mips_stop(m, MIPS_QUIT);
            return MIPS_QUIT;
            break;
            
        default:
            mipsim_printf(IO_WARNING, "Unknown syscall %d\n", code);
            break;
    }
    
    return MIPS_OK;
}
示例#4
0
int main()
{
    std::ifstream in("in.txt");
    std::ofstream out("out.txt");
    std::string as, bs;
    while (in >> as)
    {
        in >> bs;
        if (bs == "0")
        {
            out << "<error>\n\n\n";
            continue;
        }
        std::vector<int> a, b;
        a = str_to_num(as);
        b = str_to_num(bs);
        std::pair<std::vector<int>, std::vector<int>> res = divide(a, b);
        out << num_to_str(res.first) << "\n" << num_to_str(res.second) << "\n\n";
    }
}
示例#5
0
文件: BBS.C 项目: jeske/GTalk
int load_board_info(int board, struct board_info *new_board, char *directory)
 {
   FILE *fileptr;
   char filename[40];
   char s[12];
   char *data;

   new_board->limit_messages = MAX_MESG_LIMIT;
   new_board->priv_access = HANDLE_PRV;
   strcpy(new_board->title,"Board");
   find_bbs_directory(directory,board);
   sprintf(filename,"%s\\DESCRIPT",directory);

   lock_dos();
   if (!(fileptr = g_fopen(filename,"rb","BBS#5")))
    {
      unlock_dos();
#ifdef DEBUG
      log_error(filename);
#endif
      return 2;
    }
    else
    {
      fgets(s,10,fileptr);
      new_board->limit_messages = str_to_num(s,&data);
      fgets(s,10,fileptr);
      new_board->priv_access = str_to_num(s,&data);
      fgets(s,10,fileptr);
      new_board->user_moderator = str_to_num(s,&data);
      fgets(new_board->title,29,fileptr);
      if (strlen(new_board->title)>2)
       *(new_board->title+strlen(new_board->title)-2) = 0;
      g_fclose(fileptr);
      unlock_dos();
    };
   if (new_board->limit_messages > MAX_MESG_LIMIT)
    new_board->limit_messages = MAX_MESG_LIMIT;
   return (!(test_bit(user_options[tswitch].privs,new_board->priv_access)));
 };
示例#6
0
文件: lwsd_conf.c 项目: Qiware/tanlz
/******************************************************************************
 **函数名称: lwsd_conf_parse_lws_connections
 **功    能: 解析LWS并发配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_parse_lws_connections(xml_tree_t *xml, lws_conf_t *conf, log_cycle_t *log)
{
    xml_node_t *fix, *node;

    /* > 定位并发配置 */
    fix = xml_query(xml, ".LISTEND.LWS.CONNECTIONS");
    if (NULL == fix) {
        log_error(log, "Didn't configure connections!");
        return -1;
    }

    node = xml_search(xml, fix, "MAX");         /* > 获取最大并发数 */
    if (NULL == node) {
        log_error(log, "Get max number of connections failed!");
        return -1;
    }

    conf->connections.max = str_to_num(node->value.str);

    node = xml_search(xml, fix, "TIMEOUT");     /* > 获取连接超时时间 */
    if (NULL == node) {
        log_error(log, "Get timeout of connection failed!");
        return -1;
    }

    conf->connections.timeout = str_to_num(node->value.str);

    /* > 获取侦听端口 */
    node = xml_search(xml, fix, "PORT");
    if (NULL == node) {
        log_error(log, "Get port of connection failed!");
        return -1;
    }

    conf->connections.port = str_to_num(node->value.str);

    return 0;
}
示例#7
0
文件: BBS.C 项目: jeske/GTalk
void edit_bbs_message(char *directory, struct bbs_board_info *bbs_info,
    int *num_files, struct board_info *new_board)
 {
   int which_fl;
   char s[40];
   char *data;

   if (!num_files) {print_str_cr("No messages to edit"); return;}
   sprintf(s,"Which mail message to edit: (1-%d): ",*num_files);
   print_cr();
   print_string(s);
   get_editor_string(s,5);
   which_fl=str_to_num(s,&data);
   edit_a_bbs_message(directory,bbs_info,num_files,which_fl,new_board);
 };
示例#8
0
文件: BBS.C 项目: jeske/GTalk
void read_bbs_message(char *directory, struct bbs_board_info *bbs_info,
     int *num_files, struct board_info *new_board, int board_num,
     struct bbs_user_account *bbs_user)
 {
   int which_fl;
   char s[40];
   char *data;
   if (!(*num_files)) {print_str_cr("No messages to read"); return; }

   sprintf(s,"Which mail message to read: (1-%d): ",*num_files);
   print_cr();
   print_string(s);
   get_editor_string(s,5);
   which_fl=str_to_num(s,&data);
   if ((which_fl<1) || (which_fl>(*num_files))) return;
   /* which_fl--; */

   read_a_bbs_message(directory,bbs_info,num_files,which_fl,
             new_board,board_num,bbs_user);
 };
示例#9
0
文件: mips.c 项目: huguesb/mipsim
/*!
    \brief Convert a register name into a register ID
*/
int mips_reg_id(const char *name)
{
    if ( name == NULL )
        return INVALID_REG;
    
    if ( *name == '$' )
        ++name;
    
    if ( is_number(*name) )
    {
        // simple atoi from reg number
        
        int error;
        const char *end;
        int id = str_to_num(name, &end, &error);
        
        if ( !*end && !error && id >= 0 && id < 32 )
            return id;
        
    } else if ( is_letter(*name) ) {
        // string lookup from reg name
        
        for ( int i = 0; i < 32; ++i )
            if ( !strcmp(name, mips_gpr_names[i]) )
                return i;
        
        for ( int i = 0; i < 3; ++i )
            if ( !strcmp(name, mips_spr_names[i]) )
                return i | SPR;
        
        for ( int i = 0; i < 32; ++i )
            if ( !strcmp(name, mips_fpr_names[i]) )
                return i | CP1;
    }
    
    return INVALID_REG;
}
示例#10
0
文件: BBS.C 项目: jeske/GTalk
void delete_a_bbs_message(char *directory,struct bbs_board_info *bbs_info,
   int *num_files, int which_fl, struct board_info *new_board)
{
   char s[40];
   char *data;
   int owner;

   if ((which_fl<1) || (which_fl>*num_files)) return;

   owner = str_to_num(bbs_info[which_fl-1].filename+1,&data);
   if (!((owner == user_lines[tswitch].number) ||
         (test_bit(user_options[tswitch].privs,BBS_EDIT_PRV)) ||
         (user_lines[tswitch].number == new_board->user_moderator)))
    {
      print_str_cr("You do not have delete privilege to that message.");
      return;
    };
   sprintf(s,"%s\\%s",directory,bbs_info[which_fl-1].filename);
   print_cr();
   lock_dos();
   remove(s);
   unlock_dos();
   print_str_cr("Message deleted.");
}
示例#11
0
/* compress or decompress from stdin to stdout */
int main(int argc, char **argv)
{
	int rc = Z_OK;
	bool compress = true;
	int list_contents = 0;
	bool force = false;
	bool quiet __attribute__((unused)) = false;
	int window_bits = 31;	/* GZIP */
	int level = Z_DEFAULT_COMPRESSION;
	char *prog = basename(argv[0]);
	const char *in_f = NULL;
	char out_f[PATH_MAX];
	FILE *i_fp = stdin;
	FILE *o_fp = NULL;
	const char *suffix = "gz";
	int force_software = 0;
	int cpu = -1;
	unsigned char *in = NULL;
	unsigned char *out = NULL;
	z_stream strm;
	const char *name = NULL;
	char *comment = NULL;
	const char *extra_fname = NULL;
	uint8_t *extra = NULL;
	int extra_len = 0;
	struct stat s;
	const char *accel = "GENWQE";
	const char *accel_env = getenv("ZLIB_ACCELERATOR");
	int card_no = 0;
	const char *card_no_env = getenv("ZLIB_CARD");

	/* Use environment variables as defaults. Command line options
	   can than overrule this. */
	if (accel_env != NULL)
		accel = accel_env;

	if (card_no_env != NULL)
		card_no = atoi(card_no_env);

	/* avoid end-of-line conversions */
	SET_BINARY_MODE(stdin);
	SET_BINARY_MODE(stdout);

	if (strstr(prog, "gunzip") != 0)
		compress = false;

	while (1) {
		int ch;
		int option_index = 0;
		static struct option long_options[] = {
			{ "stdout",	 no_argument,       NULL, 'c' },
			{ "decompress",  no_argument,       NULL, 'd' },
			{ "force",       no_argument,       NULL, 'f' },
			{ "help",	 no_argument,       NULL, 'h' },

			/* list */
			{ "list",	 no_argument,	    NULL, 'l' },
			{ "license",     no_argument,       NULL, 'L' },
			{ "suffix",      required_argument, NULL, 'S' },
			{ "verbose",	 no_argument,       NULL, 'v' },
			{ "version",	 no_argument,       NULL, 'V' },
			{ "fast",	 no_argument,       NULL, '1' },
			{ "best",	 no_argument,       NULL, '9' },

			/* our own options */
			{ "cpu",	 required_argument, NULL, 'X' },
			{ "accelerator-type", required_argument, NULL, 'A' },
			{ "card_no",	 required_argument, NULL, 'B' },
			{ "software",	 no_argument,	    NULL, 's' },
			{ "extra",	 required_argument, NULL, 'E' },
			{ "name",	 required_argument, NULL, 'N' },
			{ "comment",	 required_argument, NULL, 'C' },
			{ "i_bufsize",   required_argument, NULL, 'i' },
			{ "o_bufsize",   required_argument, NULL, 'o' },
			{ 0,		 no_argument,       NULL, 0   },
		};

		ch = getopt_long(argc, argv,
				 "E:N:C:cdfqhlLsS:vV123456789?i:o:X:A:B:",
				 long_options, &option_index);
		if (ch == -1)    /* all params processed ? */
			break;

		switch (ch) {

		case 'X':
			cpu = strtoul(optarg, NULL, 0);
			break;
		case 'A':
			accel = optarg;
			break;
		case 'B':
			card_no = strtol(optarg, (char **)NULL, 0);
			break;

		case 'E':
			extra_fname = optarg;
			break;
		case 'N':
			name = optarg;
			break;
		case 'C':
			comment = optarg;
			break;
		case 'd':
			compress = false;
			break;
		case 'f':
			force = true;
			break;
		case 'q':
			/* Currently does nothing, zless needs it */
			quiet = true;
			break;
		case 'c':
			o_fp = stdout;
			break;
		case 'S':
			suffix = optarg;
			break;
		case 's':
			force_software = true;
			break;
		case 'l':
			list_contents++;
			break;
		case '1':
			level = Z_BEST_SPEED;
			break;
		case '2':
			level = 2;
			break;
		case '3':
			level = 3;
			break;
		case '4':
			level = 4;
			break;
		case '5':
			level = 5;
			break;
		case '6':
			level = 6;
			break;
		case '7':
			level = 7;
			break;
		case '8':
			level = 8;
			break;
		case '9':
			level = Z_BEST_COMPRESSION;
			break;
		case 'v':
			verbose++;
			break;
		case 'V':
			fprintf(stdout, "%s\n", version);
			exit(EXIT_SUCCESS);
			break;
		case 'i':
			CHUNK_i = str_to_num(optarg);
			break;
		case 'o':
			CHUNK_o = str_to_num(optarg);
			break;
		case 'L':
			userinfo(stdout, prog, version);
			exit(EXIT_SUCCESS);
			break;
		case 'h':
		case '?':
			usage(stdout, prog, argc, argv);
			exit(EXIT_SUCCESS);
			break;
		}
	}

	if (cpu != -1)
		pin_to_cpu(cpu);

	if (force_software) {
		zlib_set_inflate_impl(ZLIB_SW_IMPL);
		zlib_set_deflate_impl(ZLIB_SW_IMPL);
	} else {
		zlib_set_accelerator(accel, card_no);
		zlib_set_inflate_impl(ZLIB_HW_IMPL);
		zlib_set_deflate_impl(ZLIB_HW_IMPL);
	}

	/* FIXME loop over this ... */
	if (optind < argc) {      /* input file */
		in_f = argv[optind++];

		i_fp = fopen(in_f, "r");
		if (!i_fp) {
			pr_err("%s\n", strerror(errno));
			print_args(stderr, argc, argv);
			exit(EX_ERRNO);
		}

		rc = lstat(in_f, &s);
		if ((rc == 0) && S_ISLNK(s.st_mode)) {
			pr_err("%s: Too many levels of symbolic links\n",
			       in_f);
			exit(EXIT_FAILURE);
		}

		if (list_contents) {
			rc = strip_ending(out_f, in_f, PATH_MAX, suffix);
			if (rc < 0) {
				pr_err("No .%s file!\n", suffix);
				print_args(stderr, argc, argv);
				exit(EXIT_FAILURE);
			}

			rc = do_list_contents(i_fp, out_f, list_contents);
			if (rc != 0) {
				pr_err("Unable to list contents.\n");
				print_args(stderr, argc, argv);
				exit(EXIT_FAILURE);
			}
			fclose(i_fp);
			exit(EXIT_SUCCESS);
		}
	}

	if (in_f == NULL)
		o_fp = stdout;	/* should not be a terminal! */

	if (o_fp == NULL) {
		if (compress)
			snprintf(out_f, PATH_MAX, "%s.%s", in_f, suffix);
		else {
			rc = strip_ending(out_f, in_f, PATH_MAX, suffix);
			if (rc < 0) {
				pr_err("No .%s file!\n", suffix);
				print_args(stderr, argc, argv);
				exit(EXIT_FAILURE);
			}
		}

		rc = stat(out_f, &s);
		if (!force && (rc == 0)) {
			pr_err("File %s already exists!\n", out_f);
			print_args(stderr, argc, argv);
			exit(EX_ERRNO);
		}

		o_fp = fopen(out_f, "w+");
		if (!o_fp) {
			pr_err("Cannot open output file %s: %s\n", out_f,
			       strerror(errno));
			print_args(stderr, argc, argv);
			exit(EX_ERRNO);
		}

		/* get mode settings for existing file and ... */
		rc = fstat(fileno(i_fp), &s);
		if (rc == 0) {
			rc = fchmod(fileno(o_fp), s.st_mode);
			if (rc != 0) {
				pr_err("Cannot set mode %s: %s\n", out_f,
				       strerror(errno));
				exit(EX_ERRNO);
			}
		} else /* else ignore ... */
			pr_err("Cannot set mode %s: %s\n", out_f,
			       strerror(errno));


		/* If output does not go to stdout and a filename is
		   given, set it */
		if (name == NULL)
			name = in_f;
	}

	if (isatty(fileno(o_fp))) {
		pr_err("Output must not be a terminal!\n");
		print_args(stderr, argc, argv);
		exit(EXIT_FAILURE);
	}

	if (optind != argc) {   /* now it must fit */
		usage(stderr, prog, argc, argv);
		exit(EXIT_FAILURE);
	}

	in = malloc(CHUNK_i);	/* This is the bigger Buffer by default */
	if (NULL == in) {
		pr_err("%s\n", strerror(errno));
		print_args(stderr, argc, argv);
		exit(EXIT_FAILURE);
	}

	out = malloc(CHUNK_o);	/* This is the smaller Buffer by default */
	if (NULL == out) {
		pr_err("%s\n", strerror(errno));
		print_args(stderr, argc, argv);
		exit(EXIT_FAILURE);
	}

	/* allocate inflate state */
	memset(&strm, 0, sizeof(strm));
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;

	if (compress) {
		gz_header head;
		struct timeval tv;

		if (extra_fname) {
			extra_len = file_size(extra_fname);
			if (extra_len <= 0) {
				rc = extra_len;
				goto err_out;
			}

			extra = malloc(extra_len);
			if (extra == NULL) {
				rc = -ENOMEM;
				goto err_out;
			}

			rc = file_read(extra_fname, extra, extra_len);
			if (rc != 1) {
				fprintf(stderr, "err: Unable to read extra "
					"data rc=%d\n", rc);
				free(extra);
				goto err_out;
			}

			hexdump(stderr, extra, extra_len);
		}

		/* --------------- DEFALTE ----------------- */
		rc = deflateInit2(&strm, level, Z_DEFLATED, window_bits, 8,
				  Z_DEFAULT_STRATEGY);
		if (Z_OK != rc)
			goto err_out;

		memset(&head, 0, sizeof(head));

		gettimeofday(&tv, NULL);
		head.time = tv.tv_sec;
		head.os = 0x03;

		if (extra != NULL) {
			head.extra = extra;
			head.extra_len = extra_len;
			head.extra_max = extra_len;
		}
		if (comment != NULL) {
			head.comment = (Bytef *)comment;
			head.comm_max = strlen(comment) + 1;
		}
		if (name != NULL) {
			head.name = (Bytef *)name;
			head.name_max = strlen(name) + 1;
		}

		rc = deflateSetHeader(&strm, &head);
		if (Z_OK != rc) {
			fprintf(stderr, "err: Cannot set gz header! rc=%d\n",
				rc);
			deflateEnd(&strm);
			goto err_out;
		}

		/* do compression if no arguments */
		rc = def(i_fp, o_fp, &strm, in, out);
		if (Z_OK != rc)
			zerr(rc);

		if (extra != NULL)
			free(extra);

		deflateEnd(&strm);
	} else {
		/* --------------- INFALTE ----------------- */
		strm.avail_in = 0;
		strm.next_in = Z_NULL;
		rc = inflateInit2(&strm, window_bits);
		if (Z_OK != rc)
			goto err_out;

		do {
			rc = inf(i_fp, o_fp, &strm, in, out);
			if (Z_STREAM_END != rc) {
				zerr(rc);
				break;
			}
		} while (!feof(i_fp) && !ferror(i_fp));

		inflateEnd(&strm);
	}

 err_out:
	/* Delete the input file, only if input is not stdin and if
	   output is not stdout */
	if ((rc == EXIT_SUCCESS) && (i_fp != stdin) && (o_fp != stdout)) {
		rc = unlink(in_f);
		if (rc != 0) {
			pr_err("%s\n", strerror(errno));
			print_args(stderr, argc, argv);
			exit(EXIT_FAILURE);
		}
	}

	fclose(i_fp);
	fclose(o_fp);
	free(in);
	free(out);

	exit(rc);
}
示例#12
0
文件: lwsd_conf.c 项目: Qiware/tanlz
/******************************************************************************
 **函数名称: lwsd_conf_load_frwder
 **功    能: 加载转发配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_load_frwder(xml_tree_t *xml, lwsd_conf_t *lcf, log_cycle_t *log)
{
    xml_node_t *parent, *node;
    rtmq_proxy_conf_t *conf = &lcf->frwder;

    parent = xml_query(xml, ".LISTEND.FRWDER");
    if (NULL == parent) {
        log_error(log, "Didn't find invertd configuation!");
        return -1;
    }

    /* > 设置结点ID */
    conf->nid = lcf->nid;
    snprintf(conf->path, sizeof(conf->path), "%s", lcf->wdir);

    /* > 服务端IP */
    node = xml_search(xml, parent, "SERVER.IP");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SERVER.IP!");
        return -1;
    }

    snprintf(conf->ipaddr, sizeof(conf->ipaddr), "%s", node->value.str);

    node = xml_search(xml, parent, "SERVER.PORT");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SERVER.PORT!");
        return -1;
    }

    conf->port = str_to_num(node->value.str);

    /* > 鉴权信息 */
    node = xml_search(xml, parent, "AUTH.USR");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find AUTH.USR!");
        return -1;
    }

    snprintf(conf->auth.usr, sizeof(conf->auth.usr), "%s", node->value.str);

    node = xml_search(xml, parent, "AUTH.PASSWD");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find AUTH.PASSWD!");
        return -1;
    }

    snprintf(conf->auth.passwd, sizeof(conf->auth.passwd), "%s", node->value.str);

    /* > 线程数目 */
    node = xml_search(xml, parent, "THREAD-POOL.SEND_THD_NUM");  /* 发送线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find THREAD-POOL.SEND_THD_NUM!");
        return -1;
    }

    conf->send_thd_num = str_to_num(node->value.str);
    if (0 == conf->send_thd_num) {
        log_error(log, "THREAD-POOL.SEND_THD_NUM is zero!");
        return -1;
    }

    node = xml_search(xml, parent, "THREAD-POOL.WORK_THD_NUM");  /* 工作线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find THREAD-POOL.WORK_THD_NUM!");
        return -1;
    }

    conf->work_thd_num = str_to_num(node->value.str);
    if (0 == conf->work_thd_num) {
        log_error(log, "THREAD-POOL.WORK_THD_NUM is zero!");
        return -1;
    }

    /* > 缓存大小配置 */
    node = xml_search(xml, parent, "BUFFER-POOL-SIZE.RECV");  /* 接收缓存(MB) */
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find BUFFER-POOL-SIZE.RECV!");
        return -1;
    }

    conf->recv_buff_size = str_to_num(node->value.str) * MB;
    if (0 == conf->recv_buff_size) {
        return -1;
    }

    /* > 接收队列 */
    node = xml_search(xml, parent, "RECVQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find RECVQ.MAX!");
        return -1;
    }

    conf->recvq.max = str_to_num(node->value.str);
    if (0 == conf->recvq.max) {
        log_error(log, "RECVQ.MAX is zero!");
        return -1;
    }

    node = xml_search(xml, parent, "RECVQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find RECVQ.SIZE!");
        return -1;
    }

    conf->recvq.size = str_to_num(node->value.str);
    if (0 == conf->recvq.size) {
        log_error(log, "RECVQ.SIZE is zero!");
        return -1;
    }

    /* > 发送队列 */
    node = xml_search(xml, parent, "SENDQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SENDQ.MAX!");
        return -1;
    }

    conf->sendq.max = str_to_num(node->value.str);
    if (0 == conf->sendq.max) {
        log_error(log, "SENDQ.MAX is zero!");
        return -1;
    }

    node = xml_search(xml, parent, "SENDQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SENDQ.SIZE!");
        return -1;
    }

    conf->sendq.size = str_to_num(node->value.str);
    if (0 == conf->sendq.size) {
        log_error(log, "SENDQ.SIZE is zero!");
        return -1;
    }

    return 0;
}
示例#13
0
文件: GFILES.C 项目: jeske/GTalk
void last_ten_callers(char *string, char *name, int portnum)
 {
   FILE *fileptr;
   char s[80];
   int num;
   int not_abort = 1;
   int key;
   char *data;
   int num_last = str_to_num(string,&data);

   if (num_last == -1) num_last = 10;
   if (num_last>99) num_last = 99;

   while( (*data==' ' || *data=='-' )&& *data!=0)
      data++;
   if (*data=='K' || *data=='k')
     {
     last_ten_kills(num_last,portnum);
     return;
     }




   print_cr();
   sprintf(s,"Last %d callers",num_last);
   print_str_cr(s);
   num_last++;
   print_cr();

   lock_dos(276);
   if (!(fileptr=g_fopen(USER_LOG_FILE,"rb","FILES#4")))       /* open the user log */
    {
      log_error(USER_LOG_FILE);
      unlock_dos();
      return;
    };
   call_on_logoff(close_last_ten_callers,(void *)fileptr);
   num = 1;
   while (not_abort && (num<num_last))
    {
      fseek(fileptr,-80*(long int)(num),SEEK_END);
      not_abort = (ftell(fileptr) != 0);
      if (not_abort)
       {
         sprintf(s,"%2d: ",num);
         unlock_dos();
         print_string(s);
         lock_dos(276);
         fread(s,1,80,fileptr);
         unlock_dos();
         print_str_cr(s);
         key = get_first_char(portnum);
         if ((key == 3) || (key == 27))
          {
            int_char(portnum);
            not_abort = 0;
          };
         lock_dos(277);
       };
      num++;
    };
   g_fclose(fileptr);
   clear_call_on_logoff();
   unlock_dos();
   print_cr();
 };
int main(int argc, char *argv[]) {
 srand(time(NULL));
 bool output_random = false;
 bool use_lower = false;
 bool use_upper = false;
 int desired_uniques = 0;
 int min_uniques = 0;
 int slot1_start_at = 0;
 int slot1_stop_at = 0;
 bool starts_with_letter = false;
 bool make_next_start_at = false;
 bool make_next_stop_at = false;
 int make_next_start_at_cnt = 0;
 int make_next_stop_at_cnt = 0;
 unsigned long long int start_at = 0;
 unsigned long long int stop_at = 0;
 if (argc > 1) {
  for (int i=1;i<argc;++i) {
   if (stricmp(argv[i], "-random") == 0) { output_random = true; }
   if (stricmp(argv[i], "-lower") == 0) { use_lower = true; }
   if (stricmp(argv[i], "-upper") == 0) { use_upper = true; }
   if (stricmp(argv[i], "-1unique") == 0) { desired_uniques = 1; }
   if (stricmp(argv[i], "-2uniques") == 0) { desired_uniques = 2; }
   if (stricmp(argv[i], "-3uniques") == 0) { desired_uniques = 3; }
   if (stricmp(argv[i], "-4uniques") == 0) { desired_uniques = 4; }
   if (stricmp(argv[i], "-5uniques") == 0) { desired_uniques = 5; }
   if (stricmp(argv[i], "-6uniques") == 0) { desired_uniques = 6; }
   if (stricmp(argv[i], "-7uniques") == 0) { desired_uniques = 7; }
   if (stricmp(argv[i], "-8uniques") == 0) { desired_uniques = 8; }
   if (stricmp(argv[i], "-1minunique") == 0) { min_uniques = 1; }  if (stricmp(argv[i], "-minunique1") == 0) { min_uniques = 1; }  if (stricmp(argv[i], "-min1unique") == 0) { min_uniques = 1; }
   if (stricmp(argv[i], "-2minuniques") == 0) { min_uniques = 2; } if (stricmp(argv[i], "-minuniques2") == 0) { min_uniques = 2; } if (stricmp(argv[i], "-min2uniques") == 0) { min_uniques = 2; }
   if (stricmp(argv[i], "-3minuniques") == 0) { min_uniques = 3; } if (stricmp(argv[i], "-minuniques3") == 0) { min_uniques = 3; } if (stricmp(argv[i], "-min3uniques") == 0) { min_uniques = 3; }
   if (stricmp(argv[i], "-4minuniques") == 0) { min_uniques = 4; } if (stricmp(argv[i], "-minuniques4") == 0) { min_uniques = 4; } if (stricmp(argv[i], "-min4uniques") == 0) { min_uniques = 4; }
   if (stricmp(argv[i], "-5minuniques") == 0) { min_uniques = 5; } if (stricmp(argv[i], "-minuniques5") == 0) { min_uniques = 5; } if (stricmp(argv[i], "-min5uniques") == 0) { min_uniques = 5; }
   if (stricmp(argv[i], "-6minuniques") == 0) { min_uniques = 6; } if (stricmp(argv[i], "-minuniques6") == 0) { min_uniques = 6; } if (stricmp(argv[i], "-min6uniques") == 0) { min_uniques = 6; }
   if (stricmp(argv[i], "-7minuniques") == 0) { min_uniques = 7; } if (stricmp(argv[i], "-minuniques7") == 0) { min_uniques = 7; } if (stricmp(argv[i], "-min7uniques") == 0) { min_uniques = 7; }
   if (stricmp(argv[i], "-8minuniques") == 0) { min_uniques = 8; } if (stricmp(argv[i], "-minuniques8") == 0) { min_uniques = 8; } if (stricmp(argv[i], "-min8uniques") == 0) { min_uniques = 8; }
   if (stricmp(argv[i], "-startswithA") == 0) { slot1_start_at = 0; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithB") == 0) { slot1_start_at = 1; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithC") == 0) { slot1_start_at = 2; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithD") == 0) { slot1_start_at = 3; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithE") == 0) { slot1_start_at = 4; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithF") == 0) { slot1_start_at = 5; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithG") == 0) { slot1_start_at = 6; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithH") == 0) { slot1_start_at = 7; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithJ") == 0) { slot1_start_at = 8; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithK") == 0) { slot1_start_at = 9; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithL") == 0) { slot1_start_at = 10; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithM") == 0) { slot1_start_at = 11; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithN") == 0) { slot1_start_at = 12; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithP") == 0) { slot1_start_at = 13; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithQ") == 0) { slot1_start_at = 14; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithR") == 0) { slot1_start_at = 15; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithS") == 0) { slot1_start_at = 16; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithT") == 0) { slot1_start_at = 17; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithU") == 0) { slot1_start_at = 18; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithV") == 0) { slot1_start_at = 19; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithW") == 0) { slot1_start_at = 20; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithX") == 0) { slot1_start_at = 21; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithY") == 0) { slot1_start_at = 22; starts_with_letter = true; }
   if (stricmp(argv[i], "-startswithZ") == 0) { slot1_start_at = 23; starts_with_letter = true; }
   if (stricmp(argv[i], "-start") == 0) { make_next_start_at = true; make_next_start_at_cnt = i; }
   if (stricmp(argv[i], "-stop") == 0) { make_next_stop_at = true; make_next_stop_at_cnt = i; }
   if ((make_next_start_at) && (i == (make_next_start_at_cnt+1))) { std::istringstream str_to_num(argv[i]); str_to_num >> start_at; if (!str_to_num) {std::cout << "ERROR: start is not a number" << std::endl; return 1;} make_next_start_at = false; }
   if ((make_next_stop_at) && (i == (make_next_stop_at_cnt+1))) { std::istringstream str_to_num(argv[i]); str_to_num >> stop_at; if (!str_to_num) {std::cout << "ERROR: stop is not a number" << std::endl; return 1;} make_next_stop_at = false; }
  }
示例#15
0
文件: BBS.C 项目: jeske/GTalk
void bbs_system(const char *str,const char *name, int portnum)
 {
   char directory[20];
   struct bbs_board_info bbs_info[MAX_MESG_LIMIT];
   struct board_info new_board;
   struct bbs_user_account bbs_user;
   int mail_pieces;
   int board_num = 1;
   int flag = 1;
   int num;
   char *point;
   char command[7];
   char s[100];

   if (user_lines[tswitch].number<0)
     { print_str_cr("--> BBS access denied. Guests not allowed.");
       return;
     }

   if (enter_board(board_num,&new_board,bbs_info,directory,
                &bbs_user,&mail_pieces))
    {
      print_str_cr("--> BBS access denied.");
      return;
    };
   while (flag)
    {
      check_for_privates();
      print_cr();
      sprintf(s,"#|*f2|*h1%02d|*r1 [|*f2|*h1%s|*r1] [|*f2|*h11-%d|*r1] BBS Command (|*h1?|*h0 for Menu): ",board_num,new_board.title,mail_pieces);

      prompt_get_string(s,command,4);

      if (*command>'Z') *command -= 32;

      if ((num=str_to_num(command,&point))>0)
       { if (num<=mail_pieces)
           {
            read_a_bbs_message(directory,bbs_info,&mail_pieces,num,
                               &new_board,board_num,&bbs_user);
           };
        }
       else
      switch (*command)
       {
         case 'N': new_messages(directory,bbs_info,&mail_pieces,
                        &new_board,board_num,&bbs_user);
                   break;
         case 'G': global_newscan(&board_num,&new_board,bbs_info,directory,
                        &bbs_user,&mail_pieces);
                   break;
         case 'Q': flag = 0;
                   break;
         case 'J': jump_board(&board_num,&new_board,bbs_info,directory,
                      &bbs_user,&mail_pieces,str_to_num(command+1,&point));
                   break;
         case 'L': list_bbs(directory,bbs_info,mail_pieces,&bbs_user);
                   break;
         case 'R': if ((num=str_to_num(command+1,&point))==-1)
                      read_bbs_message(directory,bbs_info,&mail_pieces,
                         &new_board,board_num,&bbs_user);
                    else read_a_bbs_message(directory,bbs_info,
                         &mail_pieces,num,&new_board,board_num,&bbs_user);
                   break;
         case 'X': reset_bbs_message_date(&bbs_user,mail_pieces,
                      bbs_info,directory);
                   break;
         case 'P': send_a_bbs_message(board_num,&new_board,
                      mail_pieces,bbs_info);
                   find_bbs(directory,bbs_info,&mail_pieces,
                      new_board.limit_messages);
                   break;
         case 'D': if ((num=str_to_num(command+1,&point))==-1)
                     delete_bbs_message(directory,bbs_info,
                         &mail_pieces,&new_board);
                     else delete_a_bbs_message(directory,bbs_info,
                         &mail_pieces,num,&new_board);
                   find_bbs(directory,bbs_info,&mail_pieces,
                      new_board.limit_messages);
                   break;
         case 'E': if ((num=str_to_num(command+1,&point))==-1)
                     edit_bbs_message(directory,bbs_info,
                          &mail_pieces,&new_board);
                     else edit_a_bbs_message(directory,bbs_info,
                          &mail_pieces,num,&new_board);
                   break;
         case 'T': toggle_global_on(directory,&bbs_user,board_num);
                   break;
         case '?': print_file("help\\bbs.hlp");
        };
    };
    print_str_cr("--> GinsuTalk: Returning to System");
 };
示例#16
0
int main(int argc, const char *argv[])
{
	program = argv[0];
	rtc_time_t tm;
	reg_data_t regv;
	reg_temp_mode_t mode;
	int ret = -1;
	int fd = -1;
	//const char *dev_name = "/dev/hi_rtc";
	const char *dev_name = "/dev/rtc0";
	char string[50];

	if (argc < 2){
		usage();
		return 0;
	}

	fd = open(dev_name, O_RDWR);
	if (!fd) {
		printf("open %s failed\n", dev_name);
		return -1;
	}

	if (!strcmp(argv[1],"-s")) {
		if (argc < 3) {
			usage();
			goto err1;	
		}

		if (!strcmp(argv[2], "time")) {

			strcpy(string, argv[3]);

			ret = parse_string(string, &tm);
			if (ret < 0)
			{
				printf("parse time param failed\n");
				goto err1;
			}
			printf("set time\n");
#if 1			
			/* code */
			printf("year:%d\n", tm.year);
			printf("month:%d\n",tm.month);
			printf("date:%d\n", tm.date); 
			printf("hour:%d\n", tm.hour);
			printf("minute:%d\n", tm.minute);
			printf("second:%d\n", tm.second);
#endif			
			ret = ioctl(fd, HI_RTC_SET_TIME, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_SET_TIME failed\n");
				goto err1;
			}	
		} else if (!strcmp(argv[2], "alarm")) {

			strcpy(string, argv[3]);

			ret = parse_string(string, &tm);
			if (ret < 0) {
				printf("parse alarm param failed\n");
				goto err1;
			}
			printf("set alarm\n");
#if 1			
			printf("year:%d\n", tm.year);
			printf("month:%d\n",tm.month);
			printf("date:%d\n", tm.date); 
			printf("hour:%d\n", tm.hour);
			printf("minute:%d\n", tm.minute);
			printf("second:%d\n", tm.second);
#endif			
			ret = ioctl(fd, HI_RTC_ALM_SET, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_ALM_SET failed\n");
				goto err1;
			}	
	 	} else {
			printf("unknown options %s\n", argv[2]);
			goto err1;
		}
	} else if (!strcmp(argv[1],"-g")) {
		if (argc < 3) {
			usage();
			goto err1;	
		}

		if (!strcmp(argv[2], "time")) {

			printf("[RTC_RD_TIME]\n");
			
			ret = ioctl(fd, HI_RTC_RD_TIME, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_RD_TIME failed\n");
				goto err1;
			}
			
			printf("Current time value: \n");
		} else if (!strcmp(argv[2], "alarm")) {
		
			printf("[RTC_RD_ALM]\n");

			ret = ioctl(fd, HI_RTC_ALM_READ, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_ALM_READ failed\n");
				goto err1;
			}
			
			printf("Current alarm value: \n");
		} else {
			printf("unknow options %s\n", argv[2]);
			goto err1;
		}
#ifdef DEBUG_TIME
		printf("year %d\n", tm.year);
		printf("month %d\n", tm.month);
		printf("date %d\n", tm.date);
		printf("hour %d\n", tm.hour);
		printf("minute %d\n", tm.minute);
		printf("second %d\n", tm.second);
		printf("weekday %d\n", tm.weekday);
#endif
		
	} else if (!strcmp(argv[1],"-w")) {

		time_t sys_time;
		struct tm *p_time;
		rtc_time_t rtc_time;
		time(&sys_time);
		p_time = gmtime(&sys_time);
#ifdef DEBUG_TIME
		printf("time year:%d\n"
				"month :%d\n"
				"day : %d\n"
				"h :%d\n"
				"min :%d\n"
				"second %d\n",
				p_time->tm_year+1900,
				p_time->tm_mon+1,
				p_time->tm_mday,
				p_time->tm_hour + 8,
				p_time->tm_min,
				p_time->tm_sec);
		printf("system date :\r\n");
		system("date");
#endif
		rtc_time.year	= p_time->tm_year + 1900;
		rtc_time.month	= p_time->tm_mon + 1;
		rtc_time.date	= p_time->tm_mday;
		rtc_time.hour	= p_time->tm_hour;
		rtc_time.minute = p_time->tm_min;
		rtc_time.second	= p_time->tm_sec;

		ret = ioctl(fd, HI_RTC_SET_TIME, &rtc_time);
		if(ret < 0){
			printf("set rtc of localtime error!\r\n");
			goto err1;
		}

	} else if (!strcmp(argv[1],"-i")) {

	rtc_time_t	rtc_time;
	struct timeval		val_time;
	struct tm	tm_time;
	// 1 get the time from rtc
	// ioctl HI_RTC_RD_TIME	
			
	ret = ioctl(fd, HI_RTC_RD_TIME, &rtc_time);
	if (ret < 0) {
		printf("ioctl: HI_RTC_RD_TIME failed\n");
		goto err1;
	}

	tm_time.tm_year	= rtc_time.year - 1900;
	tm_time.tm_mon	= rtc_time.month -1;
	tm_time.tm_mday	= rtc_time.date;
	tm_time.tm_hour	= rtc_time.hour;
	tm_time.tm_min	= rtc_time.minute;
	tm_time.tm_sec	= rtc_time.second;
	tm_time.tm_wday	= rtc_time.weekday;

	val_time.tv_sec		= mktime(&tm_time);
	val_time.tv_usec	= 0;
	settimeofday(&val_time,NULL);

#ifdef DEBUG_TIME
	printf("the value will write to the RTC is:"
			"year:%d\n"
			"month%d\n"
			"day:%d\n"
			"hour:%d\n"
			"min:%d\n"
			"sec:%d\n",
			tm_time.tm_yday,
			tm_time.tm_mon,
			tm_time.tm_mday,
			tm_time.tm_hour,
			tm_time.tm_min,
			tm_time.tm_sec);
#endif

	} else if (!strcmp(argv[1],"-r")) {

		if (argc < 3) {
			usage();
			goto err1;
		}
		
		ret = str_to_num(argv[2], &(regv.reg));
		if (ret != 0) {
			printf("reg 0x%08x invalid\n", regv.reg);
			goto err1;
		}

		regv.val = 0;

		ret = ioctl(fd, HI_RTC_REG_READ, &regv);
		if (ret < 0) {
			printf("ioctl: HI_RTC_REG_READ failed\n");
			goto err1;
		}

		printf("\n");
		printf("[RTC_REG_GET] reg:0x%02x, val:0x%02x\n", regv.reg, regv.val);
		printf("\n");
	} else if (!strcmp(argv[1],"-a")) {

		if (argc < 3) {
			usage();
			goto err1;
		}

		if (!strcmp(argv[2], "ON")) {
			ret = ioctl(fd, HI_RTC_AIE_ON);
		} else if (!strcmp(argv[2], "OFF")) {
			ret = ioctl(fd, HI_RTC_AIE_OFF);
		}

		if (ret < 0) {
			printf("ioctl: HI_RTC_AIE_ON/OFF failed\n");
			goto err1;
		}

	} else if (!strcmp(argv[1],"-reset")) {

		printf("[RTC_RESET]\n");

		ret = ioctl(fd, HI_RTC_RESET);
		if(ret){
			printf("reset err\n");
			goto err1;
		}
	} else if (!strcmp(argv[1], "-m")) {

		int mod, value;	
		
		if (argc < 3) {
			usage();
			goto err1;
		}

		mod = atoi(argv[2]);

		if (mod > 2 || mod < 0) {
			printf("invalid mode %d\n", mod);
			goto err1;
		}
		
		if (mod == 0) {
			if (argc < 4) {
				usage();
				goto err1;
			}

			value = atoi(argv[3]);
		}	
		else {
			value = 0;
		}
		
		printf("[RTC_SET_TEMP_MODE] %d\n", mod);

		mode.mode = (enum temp_sel_mode)mod;	
		mode.value = value;

		ret = ioctl(fd, HI_RTC_SET_TEMP_MODE, &mode);
		if(ret) {
			printf("ioctl: HI_RTC_SET_TEMP_MODE failed\n");
			goto err1;
		}
	} else {
		printf("unknown download mode.\n");
		goto err1;
	}

err1:
	close(fd);

	return 0;
}
示例#17
0
文件: compute_test.c 项目: zhuxu/code
int main(void)
{
    char buffer[7] = {0};
    int count;
    int point_num = 0;
    char num_ans[126];

    struct node *phead = NULL;

    while (scanf("%s %d",buffer,&count) == 2){
        buffer[6] = '\0';
        point_num = str_to_num(buffer);
	struct node *ptemp = (struct node *)malloc(sizeof(struct node));
	strncpy(ptemp->num_str,buffer,strlen(buffer) + 1);
	ptemp->num = point_num * count;
	while (count > 1){
	    str_mul(buffer,ptemp->num_str,num_ans);
	    count--;
	}
	ptemp->next = phead;
	phead = ptemp;
    }

    if (phead->next != NULL)
        phead = sll_reverse(phead);

    struct node *p_index = phead;
    int flag;
    int sum_bit = 0;
    while (phead != NULL){
        sum_bit = strlen(phead->num_str);
	flag = 0;
        for (count = 125; count > 0; count--){
	    if ((phead->num_str[count] - 48) > 0){
		if (count < sum_bit - phead->num){
		    phead->num_str[sum_bit - phead->num] = '\0';
		    break;
		}
	        phead->num_str[count+1] = '\0';
	        break;
	    }
	}
	for (count = 0; phead->num_str[count] != '\0'; count++){
	    if ((phead->num_str[count] > 48) || (count == (sum_bit - phead->num))){
	        flag = 1;
	    }
	    if (count == sum_bit - phead->num)
	        putchar('.');
	    if (flag == 1)
	        putchar(phead->num_str[count]);
	}
	putchar('\n');

	phead = phead->next;
    }

    phead = p_index;
    while (phead != NULL){
        p_index = phead;
	phead = phead->next;
	p_index->next = NULL;
	free(p_index);
    }

    return 0;
}
示例#18
0
/*
 * NOTE: We should consider to install an exit handler which does the
 * unlink() of the output file. In case of error we just do exit() and
 * forget about all the clumsy error handling free/close code, which
 * blows up the code significantly and makes it hard to read.
 */
int
main(int argc, char *argv[])
{
	int conf_file, rc;
	struct ffs_chain_t ffs_chain;
	int c;
	int smart_pad = 0;	/* default */
	int notime = 0;
	const char *config_file = "boot_rom.ffs";
	const char *output_file = "boot_rom.bin";

	memset((void *) &ffs_chain, 0, sizeof(struct ffs_chain_t));

	while (1) {
		int option_index = 0;
		static struct option long_options[] = {
			{"romfs-size", 1, 0, 's'},
			{"smart-pad", 0, 0, 'p'},
			{"notime", 0, 0, 'n'},
			{"verbose", 0, 0, 'v'},
			{"help", 1, 0, 'h'},
			{0, 0, 0, 0}
		};
		c = getopt_long(argc, argv, "s:ph?nv", long_options,
				&option_index);
		if (c == -1)
			break;

		switch (c) {
		case 's':
			ffs_chain.romfs_size = str_to_num(optarg);
			break;
		case 'p':
			smart_pad = 1;
			break;
		case 'n':
			notime = 1;
			break;
		case 'v':
			verbose = 1;
			break;
		case '?':
		case 'h':
			print_usage();
			return EXIT_SUCCESS;
		default:
			printf("?? getopt returned character code 0%o ??\n", c);
		}
	}

	/* two files must always be specified: config-file and output-file */
	if (optind + 2 != argc) {
		print_usage();
		return EXIT_FAILURE;
	}

	config_file = argv[optind++];
	output_file = argv[optind++];

	dprintf("ROMFS FILESYSTEM CREATION V0.3 (bad parser)\n"
		"Build directory structure...\n"
		"  smart padding %s, maximum romfs size %d bytes\n",
		smart_pad ? "enabled" : "disabled", ffs_chain.romfs_size);

	conf_file = open(config_file, O_RDONLY);
	if (0 >= conf_file) {
		perror("load config file:");
		return EXIT_FAILURE;
	}

	rc = read_config(conf_file, &ffs_chain);
	close(conf_file);
	if (rc < 1) {
		fprintf(stderr, "flash cannot be built due to config errors\n");
		return EXIT_FAILURE;
	}

	rc = EXIT_SUCCESS;

	if (verbose)
		dump_fs_contents(&ffs_chain);
	if (smart_pad)
		/* FIXME: size is only verified during reorder */
		rc = reorder_ffs_chain(&ffs_chain);

	if (rc == EXIT_FAILURE)
		goto out;

	dprintf("Build ffs and write to image file...\n");
	if (build_ffs(&ffs_chain, output_file, notime) != 0) {
		fprintf(stderr, "build ffs failed\n");
		rc = EXIT_FAILURE;
	} else {
		rc = EXIT_SUCCESS;
	}

	/* Check if there are any duplicate entries in the image,
	   print warning if this is the case. */
	find_duplicates(&ffs_chain);
	free_chain_memory(&ffs_chain);
	dprintf("\n");

      out:
	/* If the build failed, remove the target image file */
	if (rc == EXIT_FAILURE)
		unlink(output_file);

	return rc;
}
示例#19
0
文件: rtc_test.c 项目: msggood/test
int main(int argc, const char *argv[])
{
	rtc_time_t tm;
	reg_data_t regv;
	reg_temp_mode_t mode;
	int ret = -1;
	int fd = -1;
	const char *dev_name = "/dev/hi_rtc";
	char string[50] = {0};

	memset(&tm, 0, sizeof(tm));

	if (argc < 2){
		usage();
		return 0;
	}

	fd = open(dev_name, O_RDWR);
	if (fd < 0) {
		printf("open %s failed\n", dev_name);
		return -1;
	}

	if (!strcmp(argv[1],"-s")) {
		if (argc < 4) {
			usage();
			goto err1;	
		}

		if (!strcmp(argv[2], "time")) {

			strncpy(string, argv[3], sizeof(string)-1);

			ret = parse_string(string, &tm);
			if (ret < 0)
			{
				printf("parse time param failed\n");
				goto err1;
			}
			printf("set time\n");
#if 1			
			/* code */
			printf("year:%d\n", tm.year);
			printf("month:%d\n",tm.month);
			printf("date:%d\n", tm.date); 
			printf("hour:%d\n", tm.hour);
			printf("minute:%d\n", tm.minute);
			printf("second:%d\n", tm.second);
#endif			
			ret = ioctl(fd, HI_RTC_SET_TIME, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_SET_TIME failed\n");
				goto err1;
			}	
		} else if (!strcmp(argv[2], "alarm")) {

			strncpy(string, argv[3], sizeof(string)-1);

			ret = parse_string(string, &tm);
			if (ret < 0) {
				printf("parse alarm param failed\n");
				goto err1;
			}
			printf("set alarm\n");
#if 1			
			printf("year:%d\n", tm.year);
			printf("month:%d\n",tm.month);
			printf("date:%d\n", tm.date); 
			printf("hour:%d\n", tm.hour);
			printf("minute:%d\n", tm.minute);
			printf("second:%d\n", tm.second);
#endif			
			ret = ioctl(fd, HI_RTC_ALM_SET, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_ALM_SET failed\n");
				goto err1;
			}	
	 	} else {
			printf("unknown options %s\n", argv[2]);
			goto err1;
		}
	} else if (!strcmp(argv[1],"-g")) {
		if (argc < 3) {
			usage();
			goto err1;	
		}

		if (!strcmp(argv[2], "time")) {

			printf("[RTC_RD_TIME]\n");
			
			ret = ioctl(fd, HI_RTC_RD_TIME, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_RD_TIME failed\n");
				goto err1;
			}
			
			printf("Current time value: \n");
		} else if (!strcmp(argv[2], "alarm")) {
		
			printf("[RTC_RD_ALM]\n");

			ret = ioctl(fd, HI_RTC_ALM_READ, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_ALM_READ failed\n");
				goto err1;
			}
			
			printf("Current alarm value: \n");
		} else {
			printf("unknow options %s\n", argv[2]);
			goto err1;
		}

		printf("year %d\n", tm.year);
		printf("month %d\n", tm.month);
		printf("date %d\n", tm.date);
		printf("hour %d\n", tm.hour);
		printf("minute %d\n", tm.minute);
		printf("second %d\n", tm.second);
		printf("weekday %d\n", tm.weekday);
		
	} else if (!strcmp(argv[1],"-w")) {

		if (argc < 4) {
			usage();
			goto err1;
		}

		ret = str_to_num(argv[2], &(regv.reg));
		if (ret != 0) {
			printf("reg 0x%08x invalid\n", regv.reg);
			goto err1;
		}

		ret = str_to_num(argv[3], &(regv.val));
		if (ret != 0) {
			printf("val 0x%08x invalid\n", regv.val);
			goto err1;
		}
		
		printf("\n");
		printf("[RTC_REG_SET] reg:%02x, val:%02x\n", regv.reg, regv.val);
		printf("\n");

		ret = ioctl(fd, HI_RTC_REG_SET, &regv);
		if (ret < 0) {
			printf("ioctl: HI_RTC_REG_SET failed\n");
			goto err1;
		}

	} else if (!strcmp(argv[1],"-r")) {

		if (argc < 3) {
			usage();
			goto err1;
		}
		
		ret = str_to_num(argv[2], &(regv.reg));
		if (ret != 0) {
			printf("reg 0x%08x invalid\n", regv.reg);
			goto err1;
		}

		regv.val = 0;

		ret = ioctl(fd, HI_RTC_REG_READ, &regv);
		if (ret < 0) {
			printf("ioctl: HI_RTC_REG_READ failed\n");
			goto err1;
		}

		printf("\n");
		printf("[RTC_REG_GET] reg:0x%02x, val:0x%02x\n", regv.reg, regv.val);
		printf("\n");
	} else if (!strcmp(argv[1],"-a")) {

		if (argc < 3) {
			usage();
			goto err1;
		}

		if (!strcmp(argv[2], "ON")) {
			ret = ioctl(fd, HI_RTC_AIE_ON);
		} else if (!strcmp(argv[2], "OFF")) {
			ret = ioctl(fd, HI_RTC_AIE_OFF);
		}

		if (ret < 0) {
			printf("ioctl: HI_RTC_AIE_ON/OFF failed\n");
			goto err1;
		}

	} else if (!strcmp(argv[1],"-reset")) {

		printf("[RTC_RESET]\n");

		ret = ioctl(fd, HI_RTC_RESET);
		if(ret){
			printf("reset err\n");
			goto err1;
		}
	} else if (!strcmp(argv[1], "-c")) {

		if (argc < 3) {
			usage();
			goto err1;
		}

		if (!strcmp(argv[2], "ON")) {
			//printf("RTC temperature compensation on!\n");
			ret = ioctl(fd, HI_RTC_COMP_ON);
		} else if (!strcmp(argv[2], "OFF")) {
			//printf("RTC temperature compensation off!\n");
			ret = ioctl(fd, HI_RTC_COMP_OFF);
		}

		if (ret < 0) {
			printf("ioctl: HI_RTC_COMP_ON/OFF failed\n");
			goto err1;
		}
	} else if (!strcmp(argv[1], "-f")) {
		
		unsigned int freq;
		rtc_freq_t value;
		
		// print current frequency value
		if (argc  < 3)
		{
			ret = ioctl(fd, HI_RTC_GET_FREQ, &value);
			if (ret < 0)
			{
				printf("get current frequency failed\n");
				goto err1;
			}	
			
			freq = value.freq_l;
#if 0
			if (freq > 3277000 || freq < 3276000)
			{
				printf("get invalid freq %d\n", freq);
				goto err1;
			}
#endif
			printf("current frequency : %d\n", freq);	
		}	
		// set frequency 
		else if (argc == 3)
		{
			freq = atoi(argv[2]);
			
			if (freq > 3277000 || freq < 3276000)
			{
				printf("invalid freq %d\n", freq);
				goto err1;
			}
		
			value.freq_l = freq;
			
			ret = ioctl(fd, HI_RTC_SET_FREQ, &value);
			if (ret < 0)
			{
				printf("get current frequency failed\n");
				goto err1;
			}
		}

	} else if (!strcmp(argv[1], "-m")) {

		int mod, value;	
		
		if (argc < 3) {
			usage();
			goto err1;
		}

		mod = atoi(argv[2]);

		if (mod > 2 || mod < 0) {
			printf("invalid mode %d\n", mod);
			goto err1;
		}
		
		if (mod == 0) {
			if (argc < 4) {
				usage();
				goto err1;
			}

			value = atoi(argv[3]);
		}	
		else {
			value = 0;
		}
		
		printf("[RTC_SET_TEMP_MODE] %d\n", mod);

		mode.mode = (enum temp_sel_mode)mod;	
		mode.value = value;

		ret = ioctl(fd, HI_RTC_SET_TEMP_MODE, &mode);
		if(ret) {
			printf("ioctl: HI_RTC_SET_TEMP_MODE failed\n");
			goto err1;
		}
	} else {
		printf("unknown download mode.\n");
		goto err1;
	}

err1:
	close(fd);

	return 0;
}