简单的glib测试(三)

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <glib.h>
//#include <glib-2.0/glib.h>


static gint repeats = 2; 
static gint max_size = 8; 
static gboolean verbose = FALSE; 
static gboolean beep = FALSE; 
static gboolean grand = FALSE; 
static gchar *string; 

/*
glib.h头文件中定义
typedef   struct  { 
  const  gchar *long_name;   // 完整命令 如:--name  
  gchar        short_name;    // 简写命令 如:-n  
  gint         flags;           // GOptionFlags枚举的值  
  GOptionArg   arg;    // GOptionArg枚举的值  
  gpointer     arg_data; // 解析出来的数据,所要存储的位置  
   
  const  gchar *description;   // 参数描述,--help可以查看到  
  const  gchar *arg_description;  
} GOptionEntry; 
*/

static GOptionEntry entries[] = 

  { "repeats", 'r', 0, G_OPTION_ARG_INT, &repeats, "Average over N repetitions", "N" }, 
  { "max-size", 'm', 0, G_OPTION_ARG_INT, &max_size, "Test up to 2^M items", "M" }, 
  { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, 
  { "beep", 'b', 0, G_OPTION_ARG_NONE, &beep, "Beep when done", NULL }, 
  { "rand", 0, 0, G_OPTION_ARG_NONE, &grand, "Randomize the data", NULL }, 
  { "str_test", 's', 0, G_OPTION_ARG_STRING, &string, "test the stirng", NULL}, 
  { NULL } 
}; 

int 
main (int argc, char *argv[]) 

  GError *error = NULL; 
  GOptionContext *context; 
  context = g_option_context_new ("- test tree model performance"); 
  g_option_context_add_main_entries (context, entries, NULL); 
  // g_option_context_add_group (context, gtk_get_option_group (TRUE)); 
  if (!g_option_context_parse (context, &argc, &argv, &error)) 
    { 
      g_print ("option parsing failed: %s/n", error->message); 
      exit (1); 
    } 
  /* ... */ 

转载于:https://www.cnblogs.com/xuyh/p/4530860.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值