示例#1
0
文件: Window.c 项目: Absolight/Prima
void
Window_init( Handle self, HV * profile)
{
   dPROFILE;
   SV * sv;
   inherited init( self, profile);

   opt_set( optSystemSelectable);
   opt_assign( optOwnerIcon, pget_B( ownerIcon));
   opt_assign( optMainWindow, pget_B( mainWindow));
   my-> set_icon( self, pget_H( icon));
   my-> menuColorIndex( self, true, ciFore,          pget_i( menuColor)            );
   my-> menuColorIndex( self, true, ciBack,          pget_i( menuBackColor)        );
   my-> menuColorIndex( self, true, ciHiliteText,    pget_i( menuHiliteColor)      );
   my-> menuColorIndex( self, true, ciHilite,        pget_i( menuHiliteBackColor)  );
   my-> menuColorIndex( self, true, ciDisabledText,  pget_i( menuDisabledColor)    );
   my-> menuColorIndex( self, true, ciDisabled,      pget_i( menuDisabledBackColor));
   my-> menuColorIndex( self, true, ciLight3DColor,  pget_i( menuLight3DColor)     );
   my-> menuColorIndex( self, true, ciDark3DColor,   pget_i( menuDark3DColor)      );
   SvHV_Font( pget_sv( menuFont), &Font_buffer, "Window::init");
   my-> set_menu_font  ( self, Font_buffer);
   if ( SvTYPE( sv = pget_sv( menuItems)) != SVt_NULL)
      my-> set_menuItems( self, sv);
   my-> set_modalResult( self, pget_i( modalResult));
   my-> set_modalHorizon( self, pget_B( modalHorizon));
   CORE_INIT_TRANSIENT(Window);
}
示例#2
0
static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name)
{
    struct ipv6_mreq val;                   /* obj, opt-name, table */
    memset(&val, 0, sizeof(val));
    if (!lua_istable(L, 3)) auxiliar_typeerror(L,3,lua_typename(L, LUA_TTABLE));
    lua_pushstring(L, "multiaddr");
    lua_gettable(L, 3);
    if (!lua_isstring(L, -1)) 
        luaL_argerror(L, 3, "string 'multiaddr' field expected");
    if (!inet_pton(AF_INET6, lua_tostring(L, -1), &val.ipv6mr_multiaddr)) 
        luaL_argerror(L, 3, "invalid 'multiaddr' ip address");
    lua_pushstring(L, "interface");
    lua_gettable(L, 3);
    /* By default we listen to interface on default route
     * (sigh). However, interface= can override it. We should 
     * support either number, or name for it. Waiting for
     * windows port of if_nametoindex */
    if (!lua_isnil(L, -1)) {
        if (lua_isnumber(L, -1)) {
            val.ipv6mr_interface = (unsigned int) lua_tonumber(L, -1);
        } else
          luaL_argerror(L, -1, "number 'interface' field expected");
    }
    return opt_set(L, ps, level, name, (char *) &val, sizeof(val));
}
示例#3
0
/**
 *  Find the option descriptor by full name.
 *
 * @param opts      option data
 * @param opt_name  name of option to look for
 * @param state     state about current option
 *
 * @return success status
 */
LOCAL tSuccess
opt_find_long(tOptions * opts, char const * opt_name, tOptState * state)
{
    char    name_buf[128];
    char *  opt_arg;
    int     nm_len = parse_opt(&opt_name, &opt_arg, name_buf, sizeof(name_buf));

    int     idx = 0;
    bool    disable  = false;
    int     ct;

    if (nm_len <= 1) {
        if ((opts->fOptSet & OPTPROC_ERRSTOP) == 0)
            return FAILURE;
        
        fprintf(stderr, zInvalOptName, opts->pzProgName, opt_name);
        (*opts->pUsageProc)(opts, EXIT_FAILURE);
        /* NOTREACHED */
        _exit(EXIT_FAILURE); /* to be certain */
    }

    ct = opt_match_ct(opts, opt_name, nm_len, &idx, &disable);

    /*
     *  See if we found one match, no matches or multiple matches.
     */
    switch (ct) {
    case 1:  return opt_set(opts, opt_arg, idx, disable, state);
    case 0:  return opt_unknown(opts, opt_name, opt_arg, state);
    default: return opt_ambiguous(opts, opt_name, ct);
    }
}
示例#4
0
Bool
Drawable_begin_paint( Handle self)
{
   if ( var-> stage > csFrozen) return false;
   if ( is_opt( optInDrawInfo)) my-> end_paint_info( self);
   opt_set( optInDraw);
   var-> splinePrecision_saved = var-> splinePrecision;
   return true;
}
示例#5
0
int opt_set_ip_multicast_if(lua_State *L, p_socket ps)
{
    const char *address = luaL_checkstring(L, 3);    /* obj, name, ip */
    struct in_addr val;
    val.s_addr = htonl(INADDR_ANY);
    if (strcmp(address, "*") && !inet_aton(address, &val))
        luaL_argerror(L, 3, "ip expected");
    return opt_set(L, ps, IPPROTO_IP, IP_MULTICAST_IF, 
        (char *) &val, sizeof(val));
}
示例#6
0
文件: Window.c 项目: Absolight/Prima
void Window_set( Handle self, HV * profile)
{
   dPROFILE;
   Bool owner_icon = false;
   
   if ( pexist( menuFont)) {
      SvHV_Font( pget_sv( menuFont), &Font_buffer, "Window::set");
      my-> set_menu_font( self, Font_buffer);
      pdelete( menuFont);
   }

   if ( pexist( owner)) {
      owner_icon = pexist( ownerIcon) ? pget_B( ownerIcon) : my-> get_ownerIcon( self);
      pdelete( ownerIcon);
   }

   if ( pexist( frameOrigin) || pexist( frameSize)) {
      Bool io = 0, is = 0;
      Point o, s;
      if ( pexist( frameOrigin)) {
         int set[2];
         prima_read_point( pget_sv( frameOrigin), set, 2, "Array panic on 'frameOrigin'");
         pdelete( frameOrigin);
         o. x = set[0];
         o. y = set[1];
         io = 1;
      } else {
         o.x = o. y = 0;
      }
      if ( pexist( frameSize)) {
         int set[2];
         prima_read_point( pget_sv( frameSize), set, 2, "Array panic on 'frameSize'");
         pdelete( frameSize);
         s. x = set[0];
         s. y = set[1];
         is = 1;
      } else {
         s.x = s. y = 0;
      }
      if ( is && io)
         apc_widget_set_rect( self, o. x, o. y, s. x, s. y);
      else if ( io) 
         my-> set_frameOrigin( self, o);
      else
         my-> set_frameSize( self, s);
  }

   inherited set( self, profile);
   if ( owner_icon) {
      my-> set_ownerIcon( self, 1);
      opt_set( optOwnerIcon);
   }
}
示例#7
0
void
DeviceBitmap_init( Handle self, HV * profile)
{
   dPROFILE;
   inherited init( self, profile);
   var-> w = pget_i( width);
   var-> h = pget_i( height);
   var-> monochrome = pget_B( monochrome);
   if ( !apc_dbm_create( self, var-> monochrome))
      croak("RTC0110: Cannot create device bitmap");
   inherited begin_paint( self);
   opt_set( optInDraw);
   CORE_INIT_TRANSIENT(DeviceBitmap);
}
示例#8
0
文件: Window.c 项目: Absolight/Prima
Bool
Window_ownerIcon( Handle self, Bool set, Bool ownerIcon)
{
   if ( !set)
      return is_opt( optOwnerIcon);
   opt_assign( optOwnerIcon, ownerIcon);
   if ( is_opt( optOwnerIcon) && var-> owner) {
      Handle icon = ( var-> owner == application) ?
         CApplication( application)-> get_icon( application) :
         CWindow(      var-> owner)-> get_icon( var-> owner);
      my-> set_icon( self, icon);
      opt_set( optOwnerIcon);
   }
   return false;
}
示例#9
0
int opt_linger(lua_State *L, p_socket ps)
{
    struct linger li;                      /* obj, name, table */
    if (!lua_istable(L, 3)) luaL_typerror(L, 3, lua_typename(L, LUA_TTABLE));
    lua_pushstring(L, "on");
    lua_gettable(L, 3);
    if (!lua_isboolean(L, -1))
        luaL_argerror(L, 3, "boolean 'on' field expected");
    li.l_onoff = lua_toboolean(L, -1);
    lua_pushstring(L, "timeout");
    lua_gettable(L, 3);
    if (!lua_isnumber(L, -1))
        luaL_argerror(L, 3, "number 'timeout' field expected");
    li.l_linger = lua_tonumber(L, -1);
    return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li));
}
示例#10
0
/*=========================================================================*\
* Auxiliar functions
\*=========================================================================*/
static int opt_setmembership(lua_State *L, p_socket ps, int level, int name)
{
    struct ip_mreq val;                   /* obj, name, table */
    if (!lua_istable(L, 3)) luaL_typerror(L, 3, lua_typename(L, LUA_TTABLE));
    lua_pushstring(L, "multiaddr");
    lua_gettable(L, 3);
    if (!lua_isstring(L, -1))
        luaL_argerror(L, 3, "string 'multiaddr' field expected");
    if (!inet_aton(lua_tostring(L, -1), &val.imr_multiaddr))
        luaL_argerror(L, 3, "invalid 'multiaddr' ip address");
    lua_pushstring(L, "interface");
    lua_gettable(L, 3);
    if (!lua_isstring(L, -1))
        luaL_argerror(L, 3, "string 'interface' field expected");
    val.imr_interface.s_addr = htonl(INADDR_ANY);
    if (strcmp(lua_tostring(L, -1), "*") &&
            !inet_aton(lua_tostring(L, -1), &val.imr_interface))
        luaL_argerror(L, 3, "invalid 'interface' ip address");
    return opt_set(L, ps, level, name, (char *) &val, sizeof(val));
}
示例#11
0
static void append_room(struct aim_chat *chat, char *sn) {
	char filename[65536];
	char *pork_dir = opt_get_str(OPT_PORK_DIR);
	FILE *file;

	if (pork_dir == NULL) {
		sprintf(filename, ".");
		opt_set(OPT_PORK_DIR, filename);
	}

	snprintf(filename, 65535, "%s/%s", pork_dir, chat->title);

	file = fopen(filename, "ab");
	if (file == NULL) {
		screen_err_msg("Unable to append %s to list for room %s.", sn, chat->title);
		return;
	}
	fputs(sn, file);
	fclose(file);
	return;
}
示例#12
0
int
opts_parse_key(void *opts, const struct opt_def *reg, const char *key,
	       uint32_t key_len, const char **data, uint32_t errcode,
	       uint32_t field_no, struct region *region,
	       bool skip_unknown_options)
{
	for (const struct opt_def *def = reg; def->name != NULL; def++) {
		if (key_len != strlen(def->name) ||
		    memcmp(key, def->name, key_len) != 0)
			continue;

		return opt_set(opts, def, data, region, errcode, field_no);
	}
	if (! skip_unknown_options) {
		char *errmsg = tt_static_buf();
		snprintf(errmsg, TT_STATIC_BUF_LEN, "unexpected option '%.*s'",
			 key_len, key);
		diag_set(ClientError, errcode, field_no, errmsg);
		return -1;
	}
	mp_next(data);
	return 0;
}
示例#13
0
int opt_ip_multicast_ttl(lua_State *L, p_socket ps)
{
    int val = (int) luaL_checknumber(L, 3);    /* obj, name, int */
    return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &val, sizeof(val));
}
示例#14
0
int main(int argc, char **argv)
{
        while (1){
                int c;
                static struct option long_options[] =
                {
                        {"stealer", optional_argument, NULL, 's'},
                        {"moneyguy", optional_argument, NULL, 'm'},
                        {"punish-time", optional_argument, NULL, 'p'},
                        {"save-time", optional_argument, NULL, 'a'},
                        {"deposite-time", optional_argument, NULL, 'd'},
                        {0, 0, 0, 0}
                };

                int option_index = 0;
                c = getopt_long(argc, argv, "s:m:p:a:d:",
                                long_options, &option_index);
                
                if (c == -1)
                        break;
                switch (c){
                        case 's':
                                opt_set(&stealer_num, "stealer");
                                break;
                        case 'm':
                                opt_set(&moneyguy_num, "moneyguy");
                                break;
                        case 'p':
                                opt_set(&punish_time, "punish-time");
                                break;
                        case 'a':
                                opt_set(&save_time, "save-time");
                                break;
                        case 'd':
                                opt_set(&deposit_time, "deposit-time");
                                break;
                        default:
                                exit_error("invalid option\n");
                }
        }


        pthread_t steallist[stealer_num];
        pthread_t mguylist[moneyguy_num];

        /* steal_val[n][0] is money to steal each time. steal_val[n][1] is tatal
         * stolen amount.
         */
        int steal_val[stealer_num][2];
        int deposit_val[moneyguy_num];
        int ret;
        
        for (int i=0; i < stealer_num; i++){
                steal_val[i][0] = i + 1;
                ret = pthread_create(&steallist[i], NULL, stealer, &steal_val[i][0]);
                check(ret, "pthread_create");
        }

        for (int i=0; i < moneyguy_num; i++){
                deposit_val[i] = i + 1;
                ret = pthread_create(&mguylist[i], NULL, moneyguy, &deposit_val[i]);
                check(ret, "pthread_create");
        }

        for (int i=0; i < stealer_num; i++){
                int *stolen;
                pthread_join(steallist[i], (void**) &stolen);
                steal_val[i][1] = *stolen;
                free(stolen);
                check(ret, "pthread_join");
                printf("joined stealer %d\n\n", i+1);
        }

        /* some folks say that the mutex and condition variable need to be
         * destroyed (see Uderstanding and Using C Pointers, Page 188),
         * however, this guy
         * (http://www2.chrishardick.com:1099/Notes/Computing/C/pthreads/mutexes.html)
         * say it does not need to, for a statically allocated one.
         */

        fputs("\n========================\n"
              "main: all stealer joined\n"
              "========================\n\n",
              stdout);

        for (int i=0; i < moneyguy_num; i++){
                pthread_cancel(mguylist[i]);
                check(ret, "pthread_join");
        }

        fputs("\n=========================\n"
              "main: all moneyguy killed\n"
              "=========================\n\n",
              stdout);

        pthread_mutex_destroy(&acc1.mutex);
        for (int i=0; i < stealer_num; i++){
                printf("stealer %d stolen %d\n", i+1, steal_val[i][1]);
        }
}
示例#15
0
static int opt_setboolean(lua_State *L, p_socket ps, int level, int name)
{
    int val = auxiliar_checkboolean(L, 3);             /* obj, name, bool */
    return opt_set(L, ps, level, name, (char *) &val, sizeof(val));
}
示例#16
0
static int opt_setint(lua_State *L, p_socket ps, int level, int name)
{
    int val = (int) lua_tonumber(L, 3);             /* obj, name, int */
    return opt_set(L, ps, level, name, (char *) &val, sizeof(val));
}
示例#17
0
void
qp_plot_opt_scan( PlotOptions * opt, char * option )
{
	char		*p;

	memset( opt, 0, sizeof(PlotOptions) );
	p = option;
	while ( *p != 0 ) {
		/* ordering on lenght of the option string is important */
		if ( opt_set( &p, "LEGO1", &opt->lego1 ) ) continue;
		if ( opt_set( &p, "LEGO2", &opt->lego2 ) ) continue;
		if ( opt_set( &p, "PROFI", &opt->profi ) ) continue;
		if ( opt_set( &p, "PROFS", &opt->profs ) ) continue;
		if ( opt_set( &p, "SURF1", &opt->surf1 ) ) continue;
		if ( opt_set( &p, "SURF2", &opt->surf2 ) ) continue;
		if ( opt_set( &p, "SURF3", &opt->surf3 ) ) continue;
		if ( opt_set( &p, "SURF4", &opt->surf4 ) ) continue;

		if ( opt_set( &p, "CHAR", &opt->chr ) ) continue;
		if ( opt_set( &p, "CONT", &opt->cont ) ) continue;
		if ( opt_set( &p, "FUNC", &opt->func ) ) continue;
		if ( opt_set( &p, "HIST", &opt->hist ) ) continue;
		if ( opt_set( &p, "LEGO", &opt->lego ) ) continue;
		if ( opt_set( &p, "PROF", &opt->prof ) ) continue;
		if ( opt_set( &p, "SURF", &opt->surf ) ) continue;
		if ( opt_set( &p, "TEXT", &opt->text ) ) continue;

		if ( opt_set( &p, "BOX", &opt->box ) ) continue;
		if ( opt_set( &p, "COL", &opt->col ) ) continue;
		if ( opt_set( &p, "CYL", &opt->cyl ) ) continue;
		if ( opt_set( &p, "POL", &opt->pol ) ) continue;
		if ( opt_set( &p, "PSD", &opt->psd ) ) continue;
		if ( opt_set( &p, "SPH", &opt->sph ) ) continue;

		if ( opt_set( &p, "+-", &opt->diff ) ) continue;
		if ( opt_set( &p, "BB", &opt->BB ) ) continue;
		if ( opt_set( &p, "E0", &opt->e0 ) ) continue;
		if ( opt_set( &p, "E1", &opt->e1 ) ) continue;
		if ( opt_set( &p, "E2", &opt->e2 ) ) continue;
		if ( opt_set( &p, "E3", &opt->e3 ) ) continue;
		if ( opt_set( &p, "E4", &opt->e4 ) ) continue;
		if ( opt_set( &p, "FB", &opt->FB ) ) continue;

		if ( opt_set( &p, "*", &opt->star ) ) continue;
		if ( opt_set( &p, "+", &opt->add ) ) continue;
		if ( opt_set( &p, "-", &opt->sub ) ) continue;
		if ( opt_set( &p, "A", &opt->A ) ) continue;
		if ( opt_set( &p, "B", &opt->B ) ) continue;
		if ( opt_set( &p, "C", &opt->C ) ) continue;
		if ( opt_set( &p, "E", &opt->E ) ) continue;
		if ( opt_set( &p, "G", &opt->gouraud ) ) continue;
		if ( opt_set( &p, "K", &opt->K ) ) continue;
		if ( opt_set( &p, "L", &opt->line ) ) continue;
		if ( opt_set( &p, "P", &opt->P ) ) continue;
		if ( opt_set( &p, "S", &opt->S ) ) continue;
		if ( opt_set( &p, "U", &opt->U ) ) continue;
		if ( opt_set( &p, "Z", &opt->Z ) ) continue;
		if ( opt_set( &p, "N", &opt->N ) ) continue;

		/* accept ',' and ' ' as separators and 'D' as default */
		if ( *p == ',' || *p == ' ' || *p == 'D') {
			p += 1;
			continue;
		}

		sf_report( "Unknown option '%c'\n", *p );
		p += 1;
	}
}
示例#18
0
static void
validate_options()
{
    if (opt_set(CRT_OPT_IND))
        command = 1;
    else if (opt_set(DEL_OPT_IND))
        command = 2;
    else if (opt_set(GET_OPT_IND))
        command = 4;
    else if (opt_set(LST_OPT_IND))
        command = 3;
    else
        usage();


    switch (command) {
        case 1:
            if (!nh_set)
                cmd_usage();

            flags |= NH_FLAG_VALID;
            opt_set(TYPE_OPT_IND);
            opt_set(VRF_OPT_IND);

            if (opt_set(MC_OPT_IND))
                flags |= NH_FLAG_MCAST;

            if (opt_set(POL_OPT_IND))
                flags |= NH_FLAG_POLICY_ENABLED;

            if (opt_set(RPOL_OPT_IND))
                flags |= NH_FLAG_RELAXED_POLICY;


            if (type == NH_RCV) {
                if (!opt_set(OIF_OPT_IND))
                    cmd_usage();
                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type == NH_ENCAP) {
                if (!opt_set(OIF_OPT_IND)) 
                    cmd_usage();

                if (!opt_set(EL2_OPT_IND)) {
                    if (!opt_set(SMAC_OPT_IND) || !opt_set(DMAC_OPT_IND))
                        cmd_usage();
                } else
                    flags |= NH_FLAG_ENCAP_L2;

                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();

            } else if (type == NH_TUNNEL) {
                if (!opt_set(OIF_OPT_IND) || !opt_set(SMAC_OPT_IND) ||
                        !opt_set(DMAC_OPT_IND) || !opt_set(SIP_OPT_IND) ||
                        !opt_set(DIP_OPT_IND)) {
                    cmd_usage();
                }

                if (opt_set(UDP_OPT_IND)) {
                    flags |= NH_FLAG_TUNNEL_UDP;
                    if (!opt_set(SPORT_OPT_IND) || !opt_set(DPORT_OPT_IND))
                        cmd_usage();
                } else if (opt_set(VXLAN_OPT_IND)) {
                    flags |= NH_FLAG_TUNNEL_VXLAN;
                    if (!opt_set(SPORT_OPT_IND) || !opt_set(DPORT_OPT_IND))
                        cmd_usage();
                } else {
                    flags |= NH_FLAG_TUNNEL_GRE;
                }

                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type == NH_RESOLVE) {
                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type == NH_DISCARD) {
                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type == NH_COMPOSITE) {
                if (!opt_set(CNI_OPT_IND))
                    cmd_usage();

                if (opt_set(CL3_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_L3;
                if (opt_set(CL2_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_L2;
                if (opt_set(CFA_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_FABRIC;
                if (opt_set(CMP_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_MULTI_PROTO;
                if (opt_set(CEN_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_ENCAP;
                if (opt_set(CEVPN_OPT_IND))
                    flags |= NH_FLAG_COMPOSITE_EVPN;
                opt_set(LBL_OPT_IND);
                if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            } else if (type != NH_VRF_TRANSLATE) {
                cmd_usage();
            }
            break;

        case 2:
            if (!nh_set)
                cmd_usage();
            if (memcmp(opt, zero_opt, sizeof(opt)))
                    cmd_usage();
            break;

        case 3:
            if (memcmp(opt, zero_opt, sizeof(opt)))
                    usage();
            break;
        case 4:
            if (memcmp(opt, zero_opt, sizeof(opt)))
                    usage();
            break;

    }
}
示例#19
0
void
Application_init( Handle self, HV * profile)
{
   dPROFILE;
   int hintPause = pget_i( hintPause);
   Color hintColor = pget_i( hintColor), hintBackColor = pget_i( hintBackColor);
   SV * hintFont = pget_sv( hintFont);
   SV * sv;
   char * hintClass      = pget_c( hintClass);
   if ( application != nilHandle) 
      croak( "Attempt to create more than one application instance");

   CDrawable-> init( self, profile);
   list_create( &var->  widgets, 16, 16);
   list_create( &var->  modalHorizons, 0, 8);
   application = self;
   if ( !apc_application_create( self))
      croak( "Error creating application");
/* Widget init */
   SvHV_Font( pget_sv( font), &Font_buffer, "Application::init");
   my-> set_font( self, Font_buffer);
   SvHV_Font( pget_sv( popupFont), &Font_buffer, "Application::init");
   my-> set_popup_font( self, Font_buffer);
   {
      AV * av = ( AV *) SvRV( pget_sv( designScale));
      SV ** holder = av_fetch( av, 0, 0);
      if ( holder)
         var->  designScale. x = SvNV( *holder);
      else
         warn("Array panic on 'designScale'");
      holder = av_fetch( av, 1, 0);
      if ( holder)
         var->  designScale. y = SvNV( *holder);
      else
         warn("Array panic on 'designScale'");
      pdelete( designScale);
   }
   var->  text = duplicate_string("");
   opt_set( optModalHorizon);

   /* store extra info */
   {
      HV * hv = ( HV *) SvRV( var-> mate);
      (void) hv_store( hv, "PrinterClass",  12, newSVpv( pget_c( printerClass),  0), 0);
      (void) hv_store( hv, "PrinterModule", 13, newSVpv( pget_c( printerModule), 0), 0);
      (void) hv_store( hv, "HelpClass",     9,  newSVpv( pget_c( helpClass),     0), 0);
      (void) hv_store( hv, "HelpModule",    10, newSVpv( pget_c( helpModule),    0), 0);
   }

   {
      HV * profile = newHV();
      static Timer_vmt HintTimerVmt;

      pset_H( owner, self);
      pset_i( timeout, hintPause);
      pset_c( name, "HintTimer");
      var->  hintTimer = create_instance( "Prima::Timer");
      protect_object( var-> hintTimer);
      hv_clear( profile);
      memcpy( &HintTimerVmt, CTimer, sizeof( HintTimerVmt));
      HintTimerVmt. handle_event = Application_HintTimer_handle_event;
      (( PTimer) var->  hintTimer)-> self = &HintTimerVmt;

      pset_H( owner, self);
      pset_i( color, hintColor);
      pset_i( backColor, hintBackColor);
      pset_i( visible, 0);
      pset_i( selectable, 0);
      pset_i( showHint, 0);
      pset_c( name, "HintWidget");
      pset_sv( font, hintFont);
      var->  hintWidget = create_instance( hintClass);
      protect_object( var->  hintWidget);
      sv_free(( SV *) profile);
   }

   if ( SvTYPE( sv = pget_sv( accelItems)) != SVt_NULL)
      my-> set_accelItems( self, sv);
   if ( SvTYPE( sv = pget_sv( popupItems)) != SVt_NULL)
      my-> set_popupItems( self, sv);
   pdelete( accelTable);
   pdelete( accelItems);
   pdelete( popupItems);

   my-> set( self, profile);
   CORE_INIT_TRANSIENT(Application);
}
示例#20
0
bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser &cl)
{
	if (!wxApp::OnCmdLineParsed(cl))
		return false;

	wxString s;

	if (cl.Found(wxT("save-xrc"), &s))
	{
		// This was most likely done on a command line, so use
		// stderr instead of gui for messages
		wxLog::SetActiveTarget(new wxLogStderr);
		wxFileSystem fs;
		wxFSFile* f = fs.OpenFile(wxT("memory:wxvbam.xrs#zip:wxvbam.xrs$wxvbam.xrc"));

		if (!f)
		{
			wxLogError(_("Configuration/build error: can't find built-in xrc"));
			return false;
		}

		wxFileOutputStream os(s);
		os.Write(*f->GetStream());
		delete f;
		wxString lm;
		lm.Printf(_("Wrote built-in configuration to %s.\n"
		            "To override, remove all but changed root node(s).  "
		            "First found root node of correct name in any .xrc or "
		            ".xrs files in following search path overrides built-in:"),
		          s.c_str());
		tack_full_path(lm);
		wxLogMessage(lm);
		return false;
	}

	if (cl.Found(wxT("print-cfg-path")))
	{
		// This was most likely done on a command line, so use
		// stderr instead of gui for messages
		wxLog::SetActiveTarget(new wxLogStderr);
		wxString lm(_("Configuration is read from, in order:"));
		tack_full_path(lm);
		wxLogMessage(lm);
		return false;
	}

	if (cl.Found(wxT("save-over"), &s))
	{
		// This was most likely done on a command line, so use
		// stderr instead of gui for messages
		wxLog::SetActiveTarget(new wxLogStderr);
		wxFileOutputStream os(s);
		os.Write(builtin_over, sizeof(builtin_over));
		wxString lm;
		lm.Printf(_("Wrote built-in override file to %s\n"
		            "To override, delete all but changed section.  First found section is used from search path:"), s.c_str());
		wxString oi = wxFileName::GetPathSeparator();
		oi += wxT("vba-over.ini");
		tack_full_path(lm, oi);
		lm.append(_("\n\tbuilt-in"));
		wxLogMessage(lm);
		return false;
	}

	if (cl.Found(wxT("f")))
	{
		pending_fullscreen = true;
	}

	if (cl.Found(wxT("o")))
	{
		wxPrintf(_("Options set from the command line are saved if any"
		           " configuration changes are made in the user interface.\n\n"
		           "For flag options, true and false are specified as 1 and 0, respectively.\n\n"));

		for (int i = 0; i < num_opts; i++)
		{
			wxPrintf(wxT("%s (%s"), opts[i].opt,
			         opts[i].boolopt ? (const wxChar*)wxT("flag") :
			         opts[i].stropt ? (const wxChar*)wxT("string") :
			         opts[i].enumvals ? opts[i].enumvals :
			         opts[i].intopt ? (const wxChar*)wxT("int") :
			         (const wxChar*)wxT("string"));

			if (opts[i].enumvals)
			{
				const wxChar* evx = wxGetTranslation(opts[i].enumvals);

				if (wxStrcmp(evx, opts[i].enumvals))
					wxPrintf(wxT(" = %s"), evx);
			}

			wxPrintf(wxT(")\n\t%s\n\n"), opts[i].desc);

			if (opts[i].enumvals)
				opts[i].enumvals = wxGetTranslation(opts[i].enumvals);
		}

		wxPrintf(_("The commands available for the Keyboard/* option are:\n\n"));

		for (int i = 0; i < ncmds; i++)
			wxPrintf(wxT("%s (%s)\n"), cmdtab[i].cmd, cmdtab[i].name);

		return false;
	}

#if !defined(NO_LINK) && !defined(__WXMSW__)

	if (cl.Found(wxT("s")))
	{
		CleanLocalLink();
	}

#endif
	int nparm = cl.GetParamCount();
	bool complained = false, gotfile = false;

	for (int i = 0; i < nparm; i++)
	{
		wxString p = cl.GetParam(i);
		size_t eqat = p.find(wxT('='));

		if (eqat != wxString::npos)
		{
			p[eqat] = 0;

			if (!opt_set(p.c_str(), p.c_str() + eqat + 1))
			{
				p[eqat] = wxT('=');
				eqat = wxString::npos;
			}
			else
				p[eqat] = wxT('=');

			pending_optset.push_back(p);
		}

		if (eqat == wxString::npos)
		{
			if (!gotfile)
			{
				pending_load = p;
				gotfile = true;
			}
			else
			{
				if (!complained)
				{
					wxFprintf(stderr, _("Bad configuration option or multiple ROM files given:\n"));
					wxFprintf(stderr, wxT("%s\n"), pending_load.c_str());
					complained = true;
				}

				wxFprintf(stderr, wxT("%s\n"), p.c_str());
			}
		}
	}

	home = strdup((const char*)wxApp::argv[0]);
	SetHome(home);
	LoadConfig(); // Parse command line arguments (overrides ini)
	ReadOpts(argc, (char**)argv);
	return true;
}
示例#21
0
bool wxvbamApp::OnInit()
{
	// use consistent names for config
	SetAppName(_("vbam"));
#if (wxMAJOR_VERSION >= 3)
	SetAppDisplayName(_T("VisualBoyAdvance-M"));
#endif
	// load system default locale, if available
	locale.Init();
	locale.AddCatalog(_T("wxvbam"));
	// make built-in xrc file available
	// this has to be done before parent OnInit() so xrc dump works
	wxFileSystem::AddHandler(new wxMemoryFSHandler);
	wxFileSystem::AddHandler(new wxArchiveFSHandler);
	wxMemoryFSHandler::AddFileWithMimeType(wxT("wxvbam.xrs"), builtin_xrs, sizeof(builtin_xrs), wxT("application/zip"));

	if (!wxApp::OnInit())
		return false;

	// prepare for loading xrc files
	wxXmlResource* xr = wxXmlResource::Get();
	// note: if linking statically, next 2 pull in lot of unused code
	// maybe in future if not wxSHARED, load only builtin-needed handlers
	xr->InitAllHandlers();
	wxInitAllImageHandlers();
	get_config_path(config_path);
	// first, load override xrcs
	// this can only override entire root nodes
	// 2.9 has LoadAllFiles(), but this is 2.8, so we'll do it manually
	wxString cwd = wxGetCwd();

	for (int i = 0; i < config_path.size(); i++)
		if (wxDirExists(config_path[i]) && wxSetWorkingDirectory(config_path[i]))
		{
			// *.xr[cs] doesn't work (double the number of scans)
			// 2.9 gives errors for no files found, so manual precheck needed
			// (yet another double the number of scans)
			if (!wxFindFirstFile(wxT("*.xrc")).empty())
				xr->Load(wxT("*.xrc"));

			if (!wxFindFirstFile(wxT("*.xrs")).empty())
				xr->Load(wxT("*.xrs"));
		}

	wxFileName xrcDir(GetConfigurationPath() + wxT("//xrc"), wxEmptyString);

	if (xrcDir.DirExists() && wxSetWorkingDirectory(xrcDir.GetFullPath()) && !wxFindFirstFile(wxT("*.xrc")).empty())
	{
		xr->Load(wxT("*.xrc"));
	}
	else
	{
		// finally, load built-in xrc
		xr->Load(wxT("memory:wxvbam.xrs"));
	}

	wxSetWorkingDirectory(cwd);
	// set up config file
	// this needs to be in a subdir to support other config as well
	// but subdir flag behaves differently 2.8 vs. 2.9.  Oh well.
	// NOTE: this does not support XDG (freedesktop.org) paths
#if defined(__WXMSW__) || defined(__APPLE__)
	wxFileName vbamconf(GetConfigurationPath(), _T("vbam.ini"));
	cfg = new wxFileConfig(wxT("vbam"), wxEmptyString,
	                       vbamconf.GetFullPath(),
	                       wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
#else
	cfg = new wxFileConfig(wxEmptyString, wxEmptyString, wxEmptyString,
	                       wxEmptyString,
	                       // style =
	                       wxCONFIG_USE_GLOBAL_FILE | wxCONFIG_USE_LOCAL_FILE |
	                       wxCONFIG_USE_SUBDIR);
#endif
	// set global config for e.g. Windows font mapping
	wxFileConfig::Set(cfg);
	// yet another bug/deficiency in wxConfig: dirs are not created if needed
	// since a default config is always written, dirs are always needed
	// Can't figure out statically if using wxFileConfig w/o duplicating wx's
	// logic, so do it at run-time
	// wxFileConfig *f = wxDynamicCast(cfg, wxFileConfig);
	// wxConfigBase does not derive from wxObject!!! so no wxDynamicCast
	wxFileConfig* fc = dynamic_cast<wxFileConfig*>(cfg);

	if (fc)
	{
		wxFileName s(wxFileConfig::GetLocalFileName(GetAppName()));
		// at least up to 2.8.12, GetLocalFileName returns the dir if
		// SUBDIR is specified instead of actual file name
		// and SUBDIR only affects UNIX
#if defined(__UNIX__) && !wxCHECK_VERSION(2,9,0)
		s.AppendDir(s.GetFullName());
#endif
		// only the path part gets created
		// note that 0777 is default (assumes umask will do og-w)
		s.Mkdir(0777, wxPATH_MKDIR_FULL);
		s = wxFileName::DirName(GetConfigurationPath());
		s.Mkdir(0777, wxPATH_MKDIR_FULL);
	}

	load_opts();

	// process command-line options
	for (int i = 0; i < pending_optset.size(); i++)
	{
		wxString p = pending_optset[i];
		size_t eqat = p.find(wxT('='));
		p[eqat] = 0;
		opt_set(p.c_str(), p.c_str() + eqat + 1);
	}

	pending_optset.clear();
	wxFileName vba_over(GetConfigurationPath(), wxT("vba-over.ini"));
	wxFileName rdb(GetConfigurationPath(), wxT("Nintendo - Game Boy Advance*.dat"));
	wxFileName scene_rdb(GetConfigurationPath(), wxT("Nintendo - Game Boy Advance (Scene)*.dat"));
	wxFileName nointro_rdb(GetConfigurationPath(), wxT("Official No-Intro Nintendo Gameboy Advance Number (Date).xml"));
	wxString f = wxFindFirstFile(nointro_rdb.GetFullPath(), wxFILE);

	if (!f.empty() && wxFileName(f).IsFileReadable())
		rom_database_nointro = f;

	f = wxFindFirstFile(scene_rdb.GetFullPath(), wxFILE);

	if (!f.empty() && wxFileName(f).IsFileReadable())
		rom_database_scene = f;

	f = wxFindFirstFile(rdb.GetFullPath(), wxFILE);

	while (!f.empty())
	{
		if (f == rom_database_scene.GetFullPath())
		{
			f = wxFindNextFile();
		}
		else if (wxFileName(f).IsFileReadable())
		{
			rom_database = f;
			break;
		}
	}

	// load vba-over.ini
	// rather than dealing with wxConfig's broken search path, just use
	// the same one that the xrc overrides use
	// this also allows us to override a group at a time, add commments, and
	// add the file from which the group came
	wxMemoryInputStream mis(builtin_over, sizeof(builtin_over));
	overrides = new wxFileConfig(mis);
	wxRegEx cmtre;
	// not the most efficient thing to do: read entire file into a string
	// just to parse the comments out
	wxString bovs((const char*)builtin_over, wxConvUTF8, sizeof(builtin_over));
	bool cont;
	wxString s;
	long grp_idx;
#define CMT_RE_START wxT("(^|[\n\r])# ?([^\n\r]*)(\r?\n|\r)\\[")

	for (cont = overrides->GetFirstGroup(s, grp_idx); cont;
	        cont = overrides->GetNextGroup(s, grp_idx))
	{
		// apparently even MacOSX sometimes uses the old \r by itself
		wxString cmt(CMT_RE_START);
		cmt += s + wxT("\\]");

		if (cmtre.Compile(cmt) && cmtre.Matches(bovs))
			cmt = cmtre.GetMatch(bovs, 2);
		else
			cmt = wxEmptyString;

		overrides->Write(s + wxT("/comment"), cmt);
	}

	if (vba_over.FileExists())
	{
		wxStringOutputStream sos;
		wxFileInputStream fis(vba_over.GetFullPath());
		// not the most efficient thing to do: read entire file into a string
		// just to parse the comments out
		fis.Read(sos);
		// rather than assuming the file is seekable, use the string we just
		// read as an input stream
		wxStringInputStream sis(sos.GetString());
		wxFileConfig ov(sis);

		for (cont = ov.GetFirstGroup(s, grp_idx); cont;
		        cont = ov.GetNextGroup(s, grp_idx))
		{
			overrides->DeleteGroup(s);
			overrides->SetPath(s);
			ov.SetPath(s);
			overrides->Write(wxT("path"), GetConfigurationPath());
			// apparently even MacOSX sometimes uses \r by itself
			wxString cmt(CMT_RE_START);
			cmt += s + wxT("\\]");

			if (cmtre.Compile(cmt) && cmtre.Matches(sos.GetString()))
				cmt = cmtre.GetMatch(sos.GetString(), 2);
			else
				cmt = wxEmptyString;

			overrides->Write(wxT("comment"), cmt);
			long ent_idx;

			for (cont = ov.GetFirstEntry(s, ent_idx); cont;
			        cont = ov.GetNextEntry(s, ent_idx))
				overrides->Write(s, ov.Read(s, wxEmptyString));

			ov.SetPath(wxT("/"));
			overrides->SetPath(wxT("/"));
		}
	}

	// create the main window
	frame = wxDynamicCast(xr->LoadFrame(NULL, wxT("MainFrame")), MainFrame);

	if (!frame)
	{
		wxLogError(_("Could not create main window"));
		return false;
	}

	// Create() cannot be overridden easily
	if (!frame->BindControls())
		return false;

	frame->Show(true);
	return true;
}
示例#22
0
static int write_room(struct aim_chat *chat) {
	char filename[65536];
	char buf[MAXSNLEN+1024];
	char *pork_dir = opt_get_str(OPT_PORK_DIR);
	FILE *file;
	dlist_t *cur;

	if (pork_dir == NULL) {
		sprintf(filename, ".");
		opt_set(OPT_PORK_DIR, filename);
	}

	snprintf(filename, 65535, "%s/%s", pork_dir, chat->title);

	file = fopen(filename, "wb");
	if (file == NULL)
		return 0;

	cur = chat->downers;
	while (cur != NULL) {
		snprintf(buf, MAXSNLEN+3, "d:%s\n", (char*)cur->data);
		fputs(buf, file);
		buf[strcspn(buf, "\n")] = '\0';
		screen_err_msg("%s", buf);
		cur = cur->next;
	}

	cur = chat->fullops;
	while (cur != NULL) {
		snprintf(buf, MAXSNLEN+3, "f:%s\n", (char*)cur->data);
		fputs(buf, file);
		buf[strcspn(buf, "\n")] = '\0';
		screen_err_msg("%s", buf);
		cur = cur->next;
	}

	cur = chat->oparray;
	while (cur != NULL) {
		snprintf(buf, MAXSNLEN+3, "o:%s\n", (char*)cur->data);
		fputs(buf, file);
		buf[strcspn(buf, "\n")] = '\0';
		screen_err_msg("%s", buf);
		cur = cur->next;
	}

	cur = chat->halfops;
	while (cur != NULL) {
		snprintf(buf, MAXSNLEN+3, "h:%s\n", (char*)cur->data);
		fputs(buf, file);
		buf[strcspn(buf, "\n")] = '\0';
		screen_err_msg("%s", buf);
		cur = cur->next;
	}

	cur = chat->immlist;
	while (cur != NULL) {
		snprintf(buf, MAXSNLEN+3, "i:%s\n", (char*)cur->data);
		fputs(buf, file);
		buf[strcspn(buf, "\n")] = '\0';
		screen_err_msg("%s", buf);
		cur = cur->next;
	}

	cur = chat->abarray;
	while (cur != NULL) {
		snprintf(buf, MAXSNLEN+3, "b:%s\n", (char*)cur->data);
		fputs(buf, file);
		buf[strcspn(buf, "\n")] = '\0';
		screen_err_msg("%s", buf);
		cur = cur->next;
	}

	cur = chat->akarray;
	while (cur != NULL) {
		snprintf(buf, MAXSNLEN+3, "k:%s\n", (char*)cur->data);
		fputs(buf, file);
		buf[strcspn(buf, "\n")] = '\0';
		screen_err_msg("%s", buf);
		cur = cur->next;
	}

	cur = chat->awarray;
	while (cur != NULL) {
		snprintf(buf, MAXSNLEN+3, "w:%s\n", (char*)cur->data);
		fputs(buf, file);
		buf[strcspn(buf, "\n")] = '\0';
		screen_err_msg("%s", buf);
		cur = cur->next;
	}

	fclose(file);
	return 1;
}