Exemplo n.º 1
0
/* add new listener port to listener port list
 * rgerhards, 2009-05-21
 */
static inline rsRetVal
addNewLstnPort(tcpsrv_t *pThis, uchar *pszPort, int bSuppOctetFram, uchar *pszAddr)
{
	tcpLstnPortList_t *pEntry;
	uchar statname[64];
	DEFiRet;

	ISOBJ_TYPE_assert(pThis, tcpsrv);

	/* create entry */
	CHKmalloc(pEntry = MALLOC(sizeof(tcpLstnPortList_t)));
	if((pEntry->pszPort = ustrdup(pszPort)) == NULL) {
		DBGPRINTF("tcpsrv/addNewLstnPort: OOM in strdup()\n");
		free(pEntry);
		ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
	}

        pEntry->pszAddr = NULL;
        /* only if a bind adress is defined copy it in struct */
        if (pszAddr != NULL) {
		if((pEntry->pszAddr = ustrdup(pszAddr)) == NULL) {
			DBGPRINTF("tcpsrv/addNewLstnPort: OOM in strdup() 2\n");
			free(pEntry->pszPort);
			free(pEntry);
			ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
		}
	}

	strcpy((char*)pEntry->dfltTZ, (char*)pThis->dfltTZ);
	pEntry->bSPFramingFix = pThis->bSPFramingFix;
	pEntry->pSrv = pThis;
	pEntry->pRuleset = pThis->pRuleset;
	pEntry->bSuppOctetFram = bSuppOctetFram;

	/* we need to create a property */ 
	CHKiRet(prop.Construct(&pEntry->pInputName));
	CHKiRet(prop.SetString(pEntry->pInputName, pThis->pszInputName, ustrlen(pThis->pszInputName)));
	CHKiRet(prop.ConstructFinalize(pEntry->pInputName));

	/* and add to list */
	pEntry->pNext = pThis->pLstnPorts;
	pThis->pLstnPorts = pEntry;

	/* support statistics gathering */
	CHKiRet(statsobj.Construct(&(pEntry->stats)));
	snprintf((char*)statname, sizeof(statname), "%s(%s)", pThis->pszInputName, pszPort);
	statname[sizeof(statname)-1] = '\0'; /* just to be on the save side... */
	CHKiRet(statsobj.SetName(pEntry->stats, statname));
	CHKiRet(statsobj.SetOrigin(pEntry->stats, pThis->pszOrigin));
	CHKiRet(ratelimitNew(&pEntry->ratelimiter, "tcperver", NULL));
	ratelimitSetLinuxLike(pEntry->ratelimiter, pThis->ratelimitInterval, pThis->ratelimitBurst);
	ratelimitSetThreadSafe(pEntry->ratelimiter);
	STATSCOUNTER_INIT(pEntry->ctrSubmit, pEntry->mutCtrSubmit);
	CHKiRet(statsobj.AddCounter(pEntry->stats, UCHAR_CONSTANT("submitted"),
		ctrType_IntCtr, CTR_FLAG_RESETTABLE, &(pEntry->ctrSubmit)));
	CHKiRet(statsobj.ConstructFinalize(pEntry->stats));

finalize_it:
	RETiRet;
}
Exemplo n.º 2
0
/* this reloads a lookup table. This is done while the engine is running,
 * as such the function must ensure proper locking and proper order of
 * operations (so that nothing can interfere). If the table cannot be loaded,
 * the old table is continued to be used.
 */
static rsRetVal
lookupReload(lookup_t *pThis)
{
	uint32_t i;
	lookup_t newlu; /* dummy to be able to use support functions without 
	                   affecting current settings. */
	DEFiRet;
	
	DBGPRINTF("reload requested for lookup table '%s'\n", pThis->name);
	memset(&newlu, 0, sizeof(newlu));
	CHKmalloc(newlu.name = ustrdup(pThis->name));
	CHKmalloc(newlu.filename = ustrdup(pThis->filename));
	CHKiRet(lookupReadFile(&newlu));
	/* all went well, copy over data members */
	pthread_rwlock_wrlock(&pThis->rwlock);
	for(i = 0 ; i < pThis->nmemb ; ++i) {
		free(pThis->d.strtab[i].key), /* we don't care about exec order of frees */
		free(pThis->d.strtab[i].val);
	}
	free(pThis->d.strtab);
	pThis->d.strtab = newlu.d.strtab; /* hand table AND ALL STRINGS over! */
	pthread_rwlock_unlock(&pThis->rwlock);
	errmsg.LogError(0, RS_RET_OK, "lookup table '%s' reloaded from file '%s'",
			pThis->name, pThis->filename);
finalize_it:
	free(newlu.name);
	free(newlu.filename);
	RETiRet;
}
Exemplo n.º 3
0
bool ctag_search(const char *ident, struct ctag_result *tag)
{
	FILE *f = fopen("tags", "r");
	if(!f)
		return false;

	bool found = false;

	char buf[256];
	while(fgets(buf, sizeof buf, f)){
		char *end = strchr(buf, '\t');
		if(!end || !end[1])
			continue;
		*end = '\0';
		if(!strcmp(buf, ident)){
			char *fname = end + 1;
			end = strchr(end + 1, '\t');
			if(!end || !end[1])
				continue;
			*end = '\0';

			char *nl = strchr(end + 1, '\n');
			if(nl)
				*nl = '\0';

			tag->fname = ustrdup(fname);
			tag->line = ustrdup(end + 1);
			found = true;
			break;
		}
	}

	fclose(f);
	return found;
}
Exemplo n.º 4
0
static void doAddConfigEntry(Config_t *conf, char *key, char *value)
{
    ConfObj_t *obj = umalloc(sizeof(*obj));
    char *myVal = (value) ? ustrdup(value) : ustrdup("");

    obj->key = ustrdup(key);
    obj->value = myVal;
    list_add_tail(&(obj->next), conf);
}
Exemplo n.º 5
0
static void dot_emit(const char *from, const char *to)
{
	char *from_ = ustrdup(from);
	char *to_ = ustrdup(to);

	dot_replace(from_);
	dot_replace(to_);

	fprintf(stderr, "%s -> %s;\n", from_, to_);

	free(from_);
	free(to_);
}
Exemplo n.º 6
0
void preproc_push(FILE *f, const char *fname)
{
	if(file_stack_idx >= 0)
		file_stack[file_stack_idx].line_no = current_line; /* save state */


	file_stack_idx++;
	if(file_stack_idx == ARRAY_LEN(file_stack))
		die("too many includes");

#ifdef DO_CHDIR
	char *wd;

	curwdfd = open(".", O_RDONLY);
	if(curwdfd == -1)
		ppdie(p, "open(\".\"): %s", strerror(errno));

	/* make sure everything is relative to the file */
	wd = udirname(p->fname);
	if(chdir(wd))
		ppdie(p, "chdir(\"%s\"): %s (for %s)", wd, strerror(errno), p->fname);
	free(wd);
#endif


	/* setup new state */
	file_stack[file_stack_idx].file    = f;
	file_stack[file_stack_idx].fname   = ustrdup(fname);
	file_stack[file_stack_idx].line_no = current_line = 1;

	preproc_out_info();
}
Exemplo n.º 7
0
/* add a counter to an object
 * ctrName is duplicated, caller must free it if requried
 * NOTE: The counter is READ-ONLY and MUST NOT be modified (most
 * importantly, it must not be initialized, so the caller must
 * ensure the counter is properly initialized before AddCounter()
 * is called.
 */
static rsRetVal
addCounter(statsobj_t *pThis, uchar *ctrName, statsCtrType_t ctrType, int8_t flags, void *pCtr)
{
	ctr_t *ctr;
	DEFiRet;

	CHKmalloc(ctr = malloc(sizeof(ctr_t)));
	ctr->next = NULL;
	ctr->prev = NULL;
	CHKmalloc(ctr->name = ustrdup(ctrName));
	ctr->flags = flags;
	ctr->ctrType = ctrType;
	switch(ctrType) {
	case ctrType_IntCtr:
		ctr->val.pIntCtr = (intctr_t*) pCtr;
		break;
	case ctrType_Int:
		ctr->val.pInt = (int*) pCtr;
		break;
	}
	addCtrToList(pThis, ctr);

finalize_it:
	RETiRet;
}
Exemplo n.º 8
0
HL_PRIM int hl_hash_gen( const uchar *name, bool cache_name ) {
	int h = 0;
	const uchar *oname = name;
	while( *name ) {
		h = 223 * h + (unsigned)*name;
		name++;
	}
	h %= 0x1FFFFF7B;
	if( cache_name ) {
		hl_field_lookup *l = hl_lookup_find(hl_cache, hl_cache_count, h);
		// check for potential conflict (see haxe#5572)
		while( l && ucmp((uchar*)l->t,oname) != 0 ) {
			h++;
			l = hl_lookup_find(hl_cache, hl_cache_count, h);
		}
		if( l == NULL ) {
			if( hl_cache_size == hl_cache_count ) {
				// resize
				int newsize = hl_cache_size ? (hl_cache_size * 3) >> 1 : 16;
				hl_field_lookup *cache = (hl_field_lookup*)malloc(sizeof(hl_field_lookup) * newsize);
				memcpy(cache,hl_cache,sizeof(hl_field_lookup) * hl_cache_count);
				free(hl_cache);
				hl_cache = cache;
				hl_cache_size = newsize;
			}
			hl_lookup_insert(hl_cache,hl_cache_count++,h,(hl_type*)ustrdup(oname),0);
		}
	}
Exemplo n.º 9
0
//sets the text
static void _label_set_text(AWE_OBJECT *obj, void *data)
{
    const char *new_text = *(const char **)data;
    free(((AWE_LABEL *)obj)->text);
    ((AWE_LABEL *)obj)->text = ustrdup(new_text ? new_text : empty_string);
    awe_set_widget_dirty((AWE_WIDGET *)obj);
}
Exemplo n.º 10
0
char *ucc_where(void)
{
	static char where[1024];

	if(!where[0]){
		char link[1024];
		ssize_t nb;

		if((nb = readlink(argv0, link, sizeof link)) == -1){
			snprintf(where, sizeof where, "%s", argv0);
		}else{
			char *argv_dup;

			link[nb] = '\0';
			/* need to tag argv0's dirname onto the start */
			argv_dup = ustrdup(argv0);

			bname(argv_dup);

			snprintf(where, sizeof where, "%s/%s", argv_dup, link);

			free(argv_dup);
		}

		/* dirname */
		bname(where);
	}

	return where;
}
Exemplo n.º 11
0
/*
 * Read the rest of a line that starts `\c'. Including nothing at
 * all (tok_word with empty text).
 */
token get_codepar_token(input * in)
{
  int c;
  token ret;
  rdstring rs = { 0, 0, NULL };
  filepos cpos;

  ret.type = tok_word;
  c = get(in, &cpos);           /* expect (and discard) one space */
  ret.pos = cpos;
  if (c == ' ')
  {
    c = get(in, &cpos);
    ret.pos = cpos;
  }
  while (!isnl(c) && c != EOF)
  {
    int c2 = c;
    c = get(in, &cpos);
    /* Discard \r just before \n. */
    if (c2 != 13 || !isnl(c))
      rdadd(&rs, (wchar_t)c2);
  }
  unget(in, c, &cpos);
  ret.text = ustrdup(rs.text);
  sfree(rs.text);
  return ret;
}
Exemplo n.º 12
0
//constructor
static void _checkbox_constructor(AWE_OBJECT *obj)
{
    int i, j;
    AWE_PUSH_BUTTON *tmp = (AWE_PUSH_BUTTON *)obj;
    tmp->text = ustrdup(empty_string);
    tmp->font = font;
    for(i = 0; i < AWE_PUSH_BUTTON_NUM_TEXTURES; i++){
        for(j = 0; j < AWE_PUSH_BUTTON_NUM_FACES; j++){
            if(i == AWE_PUSH_BUTTON_TEXTURE_HIGHLIGHTED)
                memcpy(&tmp->texture[i].face_col[j], &_face_color_highlighted, sizeof(RGB));
            else if(i == AWE_PUSH_BUTTON_TEXTURE_DISABLED)
                memcpy(&tmp->texture[i].face_col[j], &_face_color_disabled, sizeof(RGB));
            else
                memcpy(&tmp->texture[i].face_col[j], &_face_color_normal, sizeof(RGB));
        }
        for(j = 0; j < AWE_PUSH_BUTTON_NUM_EDGES; j++){
            if(j == AWE_PUSH_BUTTON_EDGE_TOP_LEFT)
                memcpy(&tmp->texture[i].edge_col[j], &_edge_color_top_left, sizeof(RGB));
            else
                memcpy(&tmp->texture[i].edge_col[j], &_edge_color_bottom_right, sizeof(RGB));
        }
        if(i == AWE_PUSH_BUTTON_TEXTURE_DISABLED){
            memcpy(&tmp->texture[i].font_col, &_font_color_disabled, sizeof(RGB));
            memcpy(&tmp->texture[i].font_sdw, &_shadow_color_disabled, sizeof(RGB));
        }
        else{
            memcpy(&tmp->texture[i].font_col, &_font_color_normal, sizeof(RGB));
            memcpy(&tmp->texture[i].font_sdw, &_shadow_color_normal, sizeof(RGB));
        }      
    }
    memcpy(&((AWE_CHECKBOX *)obj)->bg, &_face_color_highlighted, sizeof(RGB));
    ((AWE_CHECKBOX *)obj)->text_dir = AWE_TEXT_DIRECTION_RIGHT;
}
Exemplo n.º 13
0
/* Start a new thread and add it to the list of currently
 * executing threads. It is added at the end of the list.
 * rgerhards, 2007-12-14
 */
rsRetVal thrdCreate(rsRetVal (*thrdMain)(thrdInfo_t*), rsRetVal(*afterRun)(thrdInfo_t *), sbool bNeedsCancel, uchar *name)
{
    DEFiRet;
    thrdInfo_t *pThis;

    assert(thrdMain != NULL);

    CHKiRet(thrdConstruct(&pThis));
    pThis->bIsActive = 1;
    pThis->pUsrThrdMain = thrdMain;
    pThis->pAfterRun = afterRun;
    pThis->bNeedsCancel = bNeedsCancel;
    pThis->name = ustrdup(name);
    pthread_create(&pThis->thrdID,
#ifdef HAVE_PTHREAD_SETSCHEDPARAM
                   &default_thread_attr,
#else
                   NULL,
#endif
                   thrdStarter, pThis);
    CHKiRet(llAppend(&llThrds, NULL, pThis));

finalize_it:
    RETiRet;
}
Exemplo n.º 14
0
static attribute *parse_attr_single(const char *ident, symtable *scope)
{
    symtable_global *glob;
    int i;
    where attrloc;

    for(i = 0; attrs[i].ident; i++) {
        char buf[MAX_FMT_LEN];
        if(!strcmp(attrs[i].ident, ident)
                || (snprintf(buf, sizeof buf, "__%s__", attrs[i].ident), !strcmp(buf, ident)))
        {
            return attrs[i].parser(scope, attrs[i].ident);
        }
    }

    where_cc1_current(&attrloc);
    attrloc.chr -= strlen(ident);

    /* unrecognised - only do the warning (and map checking) if non system-header */
    if(cc1_warning.system_headers || !where_in_sysheader(&attrloc)) {
        glob = symtab_global(scope);
        if(!dynmap_exists(char *, glob->unrecog_attrs, (char *)ident)) {
            char *dup = ustrdup(ident);

            if(!glob->unrecog_attrs)
                glob->unrecog_attrs = dynmap_new(char *, strcmp, dynmap_strhash);

            dynmap_set(char *, void *, glob->unrecog_attrs, dup, NULL);

            cc1_warn_at(&attrloc, attr_unknown,
                        "ignoring unrecognised attribute \"%s\"", ident);
        }
    }
Exemplo n.º 15
0
/**
 * @brief Process a PSP_ACCOUNT_LOG msg.
 *
 * This message is send from the logger with information
 * only the logger knows.
 *
 * @param msg The msg to handle.
 *
 * @return No return value.
 */
static void handleAccountLog(DDTypedBufferMsg_t *msg)
{
    PStask_ID_t logger;
    Job_t *job;
    size_t used = 0;

    PSP_getTypedMsgBuf(msg, &used, __func__, "logger", &logger, sizeof(logger));

    /* get job */
    job = findJobByLogger(logger);
    if (!job) job = addJob(logger);

    uint64_t dummy;
    PSP_getTypedMsgBuf(msg, &used, __func__, "rank(skipped)", &dummy,
		       sizeof(int32_t));
    PSP_getTypedMsgBuf(msg, &used, __func__, "uid(skipped)", &dummy,
		       sizeof(uid_t));
    PSP_getTypedMsgBuf(msg, &used, __func__, "gid(skipped)", &dummy,
		       sizeof(gid_t));
    PSP_getTypedMsgBuf(msg, &used, __func__, "total children (skipped)", &dummy,
		       sizeof(int32_t));

    /* set the job ID */
    if (!job->jobid) job->jobid = ustrdup(msg->buf+used);
}
Exemplo n.º 16
0
void preproc_push(FILE *f, const char *fname, int is_sysh)
{
	if(file_stack_idx >= 0)
		file_stack[file_stack_idx].line_no = current_line; /* save state */


	file_stack_idx++;
	if(file_stack_idx == countof(file_stack))
		CPP_DIE("too many includes");

#ifdef DO_CHDIR
	char *wd;

	curwdfd = open(".", O_RDONLY);
	if(curwdfd == -1)
		ppdie(p, "open(\".\"): %s", strerror(errno));

	/* make sure everything is relative to the file */
	wd = udirname(p->fname);
	if(chdir(wd))
		ppdie(p, "chdir(\"%s\"): %s (for %s)", wd, strerror(errno), p->fname);
	free(wd);
#endif


	/* setup new state */
	set_current_fname(fname);

	file_stack[file_stack_idx].file    = f;
	file_stack[file_stack_idx].fname   = ustrdup(fname);
	file_stack[file_stack_idx].line_no = current_line = 1;
	file_stack[file_stack_idx].is_sysh = is_sysh;

	preproc_emit_line_info_top(LINEINFO_START_OF_FILE);
}
Exemplo n.º 17
0
struct ast_node*
process_function(void *opaque)
{
	char *name;
	struct ast_node_stub *stub_node;

	if (!match(TOKEN_ID)) {
		error_msg("error: function name expected after `function'");	
		sync_stream();
		goto exit;	
	}
	
	name = ustrdup(lex_prev.id);

	if (current_token != TOKEN_LPARENTH) {
		error_msg("error: `(' expected");
		sync_stream();
		goto exit;
	}
	
	process_args(name);
exit:	
	stub_node = ast_node_stub();

	return AST_NODE(stub_node);
}
Exemplo n.º 18
0
//sets the text
static void _text_set(AWE_OBJECT *obj, void *data)
{
    const char *new_text = *(const char **)data;
    AWE_TEXT *text = (AWE_TEXT *)obj;
    free(text->text);
    text->text = ustrdup(new_text ? new_text : empty_string);
}
Exemplo n.º 19
0
/* set origin (module name, etc).
 * Note that we make our own copy of the memory, caller is
 * responsible to free up name it passes in (if required).
 */
static rsRetVal
setOrigin(statsobj_t *pThis, uchar *origin)
{
	DEFiRet;
	CHKmalloc(pThis->origin = ustrdup(origin));
finalize_it:
	RETiRet;
}
Exemplo n.º 20
0
/* set name. Note that we make our own copy of the memory, caller is
 * responsible to free up name it passes in (if required).
 */
static rsRetVal
setName(statsobj_t *pThis, uchar *name)
{
	DEFiRet;
	CHKmalloc(pThis->name = ustrdup(name));
finalize_it:
	RETiRet;
}
Exemplo n.º 21
0
struct old_buffer *new_old_buf(const char *fname)
{
	struct old_buffer *b;
	b = umalloc(sizeof *b);
	memset(b, 0, sizeof *b);
	b->fname  = ustrdup(fname);
	return b;
}
Exemplo n.º 22
0
static rsRetVal
setReportingNamespace(statsobj_t *pThis, uchar *ns)
{
	DEFiRet;
	CHKmalloc(pThis->reporting_ns = ustrdup(ns));
finalize_it:
	RETiRet;
}
Exemplo n.º 23
0
/*
 * Parse the string @a maskStr containing a hex number (with or without
 * leading "0x") and set nodemask accordingly.
 *
 * If the sting is not a valid hex number, each bit in nodemask becomes set.
 */
static void parseNUMAmask(struct bitmask *nodemask, char *maskStr, int32_t rank)
{
    char *mask, *curchar, *endptr;
    size_t len;
    uint32_t curbit;
    uint16_t i, j, digit;

    mask = maskStr;

    if (strncmp(maskStr, "0x", 2) == 0) {
	/* skip "0x", treat always as hex */
	mask += 2;
    }

    mask = ustrdup(mask); /* gets destroyed */

    len = strlen(mask);
    curchar = mask + (len - 1);
    curbit = 0;
    for (i = len; i > 0; i--) {
	digit = strtol(curchar, &endptr, 16);
	if (*endptr != '\0') {
	    mlog("%s: error parsing memory mask '%s'\n", __func__, maskStr);
	    goto error;
	}

	for (j = 0; j < 4; j++) {
	    if (digit & (1 << j)) {
		if ((long int)(curbit + j) > numa_max_node()) {
		    mlog("%s: invalid memory mask entry '%s' for rank %d\n",
			    __func__, maskStr, rank);
		    fprintf(stderr, "Invalid memory mask entry '%s' for rank"
			    " %d\n", maskStr, rank);
		    goto error;
		}
		if (numa_bitmask_isbitset(numa_get_mems_allowed(),
			    curbit + j)) {
		    numa_bitmask_setbit(nodemask, curbit + j);
		} else {
		    mlog("%s: setting bit %u in memory mask not allowed in"
			    " rank %d\n", __func__, curbit + j, rank);
		    fprintf(stderr, "Not allowed to set bit %u in memory mask"
			    " of rank %d\n", curbit + j, rank);
		}
	    }
	}
	curbit += 4;
	*curchar = '\0';
	curchar--;
    }

    ufree(mask);
    return;

error:
    ufree(mask);
    numa_bitmask_setall(nodemask);
}
Exemplo n.º 24
0
/* object_enum_callback:
 *  Helper function to find out how many objects we have on the device.
 */
static BOOL CALLBACK object_enum_callback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
{
   struct DINPUT_JOYSTICK_INFO *joy = (struct DINPUT_JOYSTICK_INFO *)pvRef;
   char tmp[128];

   if (memcmp(&lpddoi->guidType, &GUID_XAxis, sizeof(GUID)) == 0) {
      joy->axis_name[0] = ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
      joy->num_axes++;
   }
   else if (memcmp(&lpddoi->guidType, &GUID_YAxis, sizeof(GUID)) == 0) {
      joy->axis_name[1] = ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
      joy->num_axes++;
   }
   else if (memcmp(&lpddoi->guidType, &GUID_ZAxis, sizeof(GUID)) == 0) {
      joy->axis_name[2] = ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
      joy->caps |= JOYCAPS_HASZ;
      joy->num_axes++;
   }
   else if (memcmp(&lpddoi->guidType, &GUID_RzAxis, sizeof(GUID)) == 0) {
      joy->axis_name[joy->num_axes] = ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
      joy->caps |= JOYCAPS_HASR;
      joy->num_axes++;
   }
   else if (memcmp(&lpddoi->guidType, &GUID_Slider, sizeof(GUID)) == 0) {
      if (joy->caps & JOYCAPS_HASV) {
         /* we support at most 2 sliders */
         return DIENUM_CONTINUE;
      }
      else {
         if (joy->caps & JOYCAPS_HASU)
            joy->caps |= JOYCAPS_HASV;
         else
            joy->caps |= JOYCAPS_HASU;

         joy->axis_name[joy->num_axes] = ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
         joy->num_axes++;
      }
   }
   else if (memcmp(&lpddoi->guidType, &GUID_POV, sizeof(GUID)) == 0) {
      if (joy->caps & JOYCAPS_HASPOV) {
         /* we support at most 1 point-of-view device */
         return DIENUM_CONTINUE;
      }
      else {
         joy->hat_name = ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
         joy->caps |= JOYCAPS_HASPOV;
      }
   }
   else if (memcmp(&lpddoi->guidType, &GUID_Button, sizeof(GUID)) == 0) {
      if (joy->num_buttons == MAX_JOYSTICK_BUTTONS-1) {
         return DIENUM_CONTINUE;
      }
      else {
         joy->button_name[joy->num_buttons] = ustrdup(uconvert_ascii(lpddoi->tszName, tmp));
         joy->num_buttons++;
      }
   }

   return DIENUM_CONTINUE;
}
Exemplo n.º 25
0
/**
 * @brief Extract key-value pairs from PMI spawn request
 *
 * @param msg Buffer containing the PMI spawn message
 *
 * @param name Identifier for the key-value pairs to extract
 *
 * @param kvpc Where to store the number key-value pairs
 *
 * @param kvpv Where to store the array of key-value pairs
 *
 * @return Returns true on success, false on error
 */
static bool getSpawnKVPs(char *msg, char *name, int *kvpc, KVP_t **kvpv)
{
    char numKVP[50];
    int count, i;

    snprintf(buffer, sizeof(buffer), "%s_num", name);
    if (!getpmiv(buffer, msg, numKVP, sizeof(numKVP))) {
	mlog("%s(r%i): missing %s count\n", __func__, rank, name);
	return false;
    }
    *kvpc = atoi(numKVP);

    if (!*kvpc) return true;

    *kvpv = umalloc(*kvpc * sizeof(KVP_t));

    for (i = 0; i < *kvpc; i++) {
	char nextkey[PMI_KEYLEN_MAX], nextvalue[PMI_VALLEN_MAX];
	snprintf(buffer, sizeof(buffer), "%s_key_%i", name, i);
	if (!getpmiv(buffer, msg, nextkey, sizeof(nextkey))) {
	    mlog("%s(r%i): invalid %s key %s\n", __func__, rank, name, buffer);
	    goto kvp_error;
	}

	snprintf(buffer, sizeof(buffer), "%s_val_%i", name, i);
	if (!getpmiv(buffer, msg, nextvalue, sizeof(nextvalue))) {
	    mlog("%s(r%i): invalid %s val %s\n", __func__, rank, name, buffer);
	    goto kvp_error;
	}

	(*kvpv)[i].key = ustrdup(nextkey);
	(*kvpv)[i].value = ustrdup(nextvalue);
    }
    return true;

kvp_error:
    count = i;
    for (i = 0; i < count; i++) {
	ufree((*kvpv)[i].key);
	ufree((*kvpv)[i].value);
    }
    ufree(*kvpv);
    return false;
}
Exemplo n.º 26
0
//constructor
static void _label_constructor(AWE_OBJECT *obj)
{
    AWE_LABEL *tmp = (AWE_LABEL *)obj;
    tmp->text = ustrdup(empty_string);
    tmp->font = font;
    memcpy(&tmp->color[AWE_LABEL_ENABLED].font_col, &_font_color_enabled, sizeof(RGB));
    memcpy(&tmp->color[AWE_LABEL_DISABLED].font_col, &_font_color_disabled, sizeof(RGB));
    memcpy(&tmp->color[AWE_LABEL_ENABLED].font_sdw, &_shadow_color_enabled, sizeof(RGB));
    memcpy(&tmp->color[AWE_LABEL_DISABLED].font_sdw, &_shadow_color_disabled, sizeof(RGB));
}
Exemplo n.º 27
0
static void handle_pragma_ucc(const char *pragma, where *loc)
{
	if(!strncmp(pragma, "namespace ", 10)){
		free(ucc_namespace);
		ucc_namespace = ustrdup(pragma + 10);
		fprintf(stderr, "namespace \"%s\"\n", ucc_namespace);
	}else{
		cc1_warn_at(loc, unknown_pragma, "unknown ucc pragma '%s'", pragma);
	}
}
Exemplo n.º 28
0
void map_add(char c, const char *cmd)
{
	struct map *m = umalloc(sizeof *m);

	m->c = c;
	m->cmd = ustrdup(cmd);
	str_escape(m->cmd);

	list_append(maps, m);
}
Exemplo n.º 29
0
static void test_canon(char *in, char *exp, int ln)
{
	char *dup = ustrdup(in);
	if(strcmp(canonicalise_path(dup), exp)){
		fprintf(stderr, "%s:%d: canon(\"%s\") = \"%s\", expected \"%s\"\n",
				__FILE__, ln, in, dup, exp);
		ec = 1;
	}
	free(dup);
}
Exemplo n.º 30
0
static void
lex_dup(void)
{
	switch (lex.token) {
	case TOKEN_DOUBLE:
		lex_prev.real = lex.real;
		break;
	case TOKEN_ID:
		lex_prev.id = ustrdup(lex.id);
		break;
	case TOKEN_STRING:
		lex_prev.string = ustrdup(lex.string);
		break;
	default:
		break;
	
	}

	lex_prev.token = current_token;
}