コード例 #1
0
ファイル: dit_access_utils.c プロジェクト: bahamas10/openzfs
/*
 * Split 'dn' into rdn and parentdn based on the first
 * occurrence of unescaped 'comma' or 'semicolon'. rdn
 * lies on the LHS while parentdn lies on the RHS of the
 * split. If none found, then an empty string ("") is
 * assigned to parentdn
 */
int
splitDN(char *dn, char **rdn, char **parentdn) {
	char	*value, *name;
	char	*myself = "splitDN";

	if ((name = sdup(myself, T, dn)) == 0)
		return (-1);

	for (value = name; *value != '\0'; value++) {
		if (*value == ',' || *value == ';')
			if (value == name || *(value - 1) != '\\')
				break;
	}

	if (*value != '\0') {
		*value = '\0';
		value++;
	} else
		value = 0;

	if (parentdn) {
		if ((*parentdn = sdup(myself, T, value)) == 0) {
			sfree(name);
			return (-1);
		}
	}
	if (rdn)
		*rdn = name;
	else
		sfree(name);

	return (1);
}
コード例 #2
0
ファイル: ks.c プロジェクト: JohnEarnest/kona
S sp(S k)//symbol from phrase: string interning, Ks(sp("aaa")). This should be called before introducing any sym to the instance
{ //We are using this to ensure any two 'character-identical' symbols are in fact represented by the same pointer S
  //See Knuth Algorithm 6.2.2T
  #define LINK(n,x) (n)->c[((x)+1)/2] // -1 => 0 , 1 => 1
  if(!k)R 0;//used in glue. used in _2m_4. used in parse. Probably a good argument to keep since it's exposed for libraries via 2: dyadic
  N t=SYMBOLS, s=t->c[1],p=s,q=p,r; I a,x;
  if(!s){s=t->c[1]=newN();P(!s,(S)ME);s->k=sdup(k); if(!s->k){free(s);t->c[1]=0;ME;} R s->k;} // <-- strdup here and below 
  while(q)
  { if(!(a=SC(k,p->k))){R p->k;}//In the usual tree put: p->k=k,p->v=v before returning
    if(!(q=LINK(p,a))){q=newN();P(!q,(S)ME);q->k=sdup(k);if(!q->k){free(q);ME; R 0;} LINK(p,a)=q;break;}//Usual tree would q->v=v. mmo
    else if(q->b){t=p;s=q;}
    p=q;
  }
  a=0>SC(k,s->k)?-1:1;
  r=p=LINK(s,a);
  while(p!=q){x=SC(k,p->k); p->b=x;p=LINK(p,x);}
  if(!s->b){s->b=a;R p->k;}
  else if(s->b==-a){s->b=0; R p->k;}
  if(r->b==a){p=r; LINK(s,a)=LINK(r,-a); LINK(r,-a)=s; s->b=r->b=0;}
  else if(r->b==-a)
  { p=LINK(r,-a); LINK(r,-a)=LINK(p,a); 
    LINK(p,a)=r; LINK(s,a)=LINK(p,-a); LINK(p,-a)=s;
    if     (p->b== a){s->b=-a; r->b=0;}
    else if(p->b== 0){s->b= 0; r->b=0;}
    else if(p->b==-a){s->b= 0; r->b=a;}
    p->b=0;
  }
  t->c[s==t->c[1]?1:0]=p;
  R q->k; 
}
コード例 #3
0
ファイル: API.cpp プロジェクト: ChaosPower/OBS
    virtual void SetSourceRender(CTSTR lpSource, bool render)
    {
        if(!lpSource || !*lpSource)
            return;

        PostMessage(hwndMain, OBS_SETSOURCERENDER, (WPARAM)sdup(lpSource), (LPARAM) render);
    }
コード例 #4
0
ファイル: dit_access_utils.c プロジェクト: bahamas10/openzfs
/*
 * Convert rule-value to datum using namefield information
 */
datum *
ruleValueToDatum(__nis_table_mapping_t *t, __nis_rule_value_t *rv, int *statP) {
	__nis_value_t	*val;
	datum		*value;
	char		*str, *cstr, commentSep[3] = {' ', 0, 0};
	char		*myself = "ruleValueToDatum";

	/* No error yet */
	*statP = 0;

	/* Return empty datum if no namefield information available */
	if (t->e == 0) {
		if ((value = am(myself, sizeof (*value))) == 0)
			*statP = MAP_NO_MEMORY;
		return (value);
	}

	val = getMappingFormatArray(t->e->element.match.fmt, rv,
				fa_item, t->e->element.match.numItems,
				t->e->element.match.item);

	if (val && val->val && val->val->value) {
		if ((value = am(myself, sizeof (*value))) == 0) {
			*statP = MAP_NO_MEMORY;
			freeValue(val, 1);
			return (0);
		}

		/* Strip trailing whitespaces */
		cstr = (char *)val->val->value + val->val->length;
		for (; cstr >= (char *)val->val->value &&
			(*cstr == ' ' || *cstr == '\t'); *cstr-- = '\0');

		if (t->commentChar != '\0' &&
		    (str = findVal(N2LCOMMENT, rv, mit_nisplus)) != 0 &&
		    *str != '\0') {
			commentSep[1] = t->commentChar;
			cstr = scat(myself, F, commentSep, str);
			if (cstr) {
				value->dptr = scat(myself, F,
						val->val->value, cstr);
				sfree(cstr);
			}
		} else {
			value->dptr = sdup(myself, T, val->val->value);
		}
		freeValue(val, 1);
		if (value->dptr) {
			value->dsize = strlen(value->dptr);
			return (value);
		} else {
			*statP = MAP_NO_MEMORY;
			sfree(value);
			return (0);
		}
	}

	*statP = MAP_NAMEFIELD_MATCH_ERROR;
	return (0);
}
コード例 #5
0
ファイル: files.cpp プロジェクト: JohannesBuchner/multitalk
char *expand_tilde(const char *s)
{
	char *t;
	struct passwd *pw;
	
	if(s[0] != '~')
		return NULL;
	if(s[1] == '/')
	{
		pw = getpwuid(getuid());
		t = new char[strlen(s) + strlen(pw->pw_dir) + 1];
		sprintf(t, "%s/%s", pw->pw_dir, s + 2);
	}
	else
	{
		s++;
		char *name = sdup(s);
		
		int pos = 0;
		while(s[pos] != '/' && s[pos] != '\0')
			pos++;
		if(s[pos] == '\0')
			return NULL; // Could be a directory, can't be a file
		name[pos] = '\0';
		pw = getpwnam(name);
		delete[] name;
		if(pw == NULL)
			return NULL;
		t = new char[strlen(s) + strlen(pw->pw_dir) + 1];
		sprintf(t, "%s/%s", pw->pw_dir, s + pos + 1);
	}
	return t;
}
コード例 #6
0
ファイル: eval.c プロジェクト: linwukang/pcp
int
host_state_changed(char *host, int state)
{
    hstate_t	*hsp;

    for (hsp = host_map; hsp != NULL; hsp = hsp->next) {
	if (strcmp(host, hsp->name) == 0)
	    break;
    }

    if (hsp == NULL) {
	hsp = (hstate_t *)alloc(sizeof(*hsp));
	hsp->next = host_map;
	hsp->name = sdup(host);
	hsp->state = STATE_INIT;
	host_map = hsp;
    }

    if (state == hsp->state) return 0;

    if (quiet)
	; /* be quiet */
    else if (state == STATE_FAILINIT)
	__pmNotifyErr(LOG_INFO, "Cannot connect to pmcd on host %s\n", host);
    else if (state == STATE_RECONN && hsp->state != STATE_INIT)
	__pmNotifyErr(LOG_INFO, "Re-established connection to pmcd on host %s\n", host);
    else if (state == STATE_LOSTCONN)
	__pmNotifyErr(LOG_INFO, "Lost connection to pmcd on host %s\n", host);

    hsp->state = state;
    return 1;
}
コード例 #7
0
ファイル: macro.c プロジェクト: scarabeusiv/ucpp
/*
 * add the special macros to the macro table
 */
static void add_special_macros(void)
{
	struct macro *m;

	HTT_put(&macros, new_macro(), "__LINE__");
	HTT_put(&macros, new_macro(), "__FILE__");
	HTT_put(&macros, new_macro(), "__DATE__");
	HTT_put(&macros, new_macro(), "__TIME__");
	HTT_put(&macros, new_macro(), "__STDC__");
	m = new_macro(); m->narg = 1;
	m->arg = getmem(sizeof(char *)); m->arg[0] = sdup("foo");
	HTT_put(&macros, m, "_Pragma");
	if (c99_compliant) {

		m = new_macro();
		m->cval.t = getmem(9);
		m->cval.t[0] = NUMBER;
		mmv(m->cval.t + 1, "199901L", 8);
		m->cval.length = 9;
		HTT_put(&macros, m, "__STDC_VERSION__");
	}
	if (c99_hosted) {
		m = new_macro();
		m->cval.t = getmem(3);
		m->cval.t[0] = NUMBER;
		mmv(m->cval.t + 1, "1", 2);
		m->cval.length = 3;
	}
}
コード例 #8
0
ファイル: mem.c プロジェクト: KevinFei/dnsReflector
int main(int argc, char *argv[]) {
	static const unsigned primes[] =
		{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
		  59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
		  127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
		  191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251 };
	struct page page;
	char word[256], *str;
	int opt, fflag = 0;
	unsigned i;

	setlocale(LC_ALL, "C");

	memset(&page, 0, sizeof page);

	while (-1 != (opt = getopt(argc, argv, "bfzh"))) {
		switch (opt) {
                case 'b':
                        page.flags |= BESTFIT;
                        break;
		case 'f':
			fflag = 1;

			for (i = 0; i < sizeof primes / sizeof primes[0] && i < SLOTCOUNT; i++)
				setbit(page.index, primes[i]);

			break;
		case 'z':
                	printf("(struct page)  : %zu\n", sizeof page);
                	printf("offsetof(data) : %zu\n", offsetof(struct page, data));

                	return 0;
		default:
			fprintf(stderr,
				"%s [-bfzh]\n"
				"  -b  Best fit\n"
				"  -f  Fragment memory\n"
				"  -z  Print data structure sizes\n"
				"  -h  Print usage\n\n"
				"Report bugs to <*****@*****.**>\n", argv[0]);
			return (opt == 'h')? 0 : EXIT_FAILURE;
		} /* switch() */
	}

	while (EOF != scanf("%256s", word)) {
		if (!(str = sdup(&page, word)))
			perror("sdup");
	}

	if (fflag) {
		for (i = 0; i < sizeof primes / sizeof primes[0] && i < SLOTCOUNT; i++)
			clrbit(page.index, primes[i]);
	}

	printpage(&page, stdout);

	return 0;
} /* main() */
コード例 #9
0
ファイル: server.c プロジェクト: Frankie-666/flashdevelop
static void set_option(char **options, const char *name, const char *value) {
  int i;

  for (i = 0; i < MAX_OPTIONS - 3; i++) {
    if (options[i] == NULL) {
      options[i] = sdup(name);
      options[i + 1] = sdup(value);
      options[i + 2] = NULL;
      break;
    } else if (!strcmp(options[i], name)) {
      free(options[i + 1]);
      options[i + 1] = sdup(value);
      break;
    }
  }

  if (i == MAX_OPTIONS - 3) {
    die("%s", "Too many options specified");
  }
}
コード例 #10
0
ファイル: main.c プロジェクト: GerHobbelt/mongoose-vanilla
static void set_option(char **options, const char *name, const char *value) {
  int i;

  if (!strcmp(name, "document_root") || !(strcmp(name, "r"))) {
    verify_document_root(value);
  }

  for (i = 0; i < MAX_OPTIONS - 3; i++) {
    if (options[i] == NULL) {
      options[i] = sdup(name);
      options[i + 1] = sdup(value);
      options[i + 2] = NULL;
      break;
    }
  }

  if (i == MAX_OPTIONS - 3) {
    die("%s", "Too many options specified");
  }
}
コード例 #11
0
ファイル: API.cpp プロジェクト: ChaosPower/OBS
    virtual bool SetScene(CTSTR lpScene, bool bPost)
    {
        assert(lpScene && *lpScene);

        if(!lpScene || !*lpScene)
            return false;

        if(bPost)
        {
            PostMessage(hwndMain, OBS_SETSCENE, 0, (LPARAM)sdup(lpScene));
            return true;
        }

        return App->SetScene(lpScene);
    }
コード例 #12
0
ファイル: files.cpp プロジェクト: JohannesBuchner/multitalk
char *get_file(const char *s)
{
	int len = strlen(s);
	char *path;
	
	for(int pos = len - 1; pos >= 0; pos--)
	{
		if(s[pos] == '/')
		{
			path = new char[len];
			strcpy(path, s + pos + 1);
			return path;
		}
	}
	path = sdup(s);
	return path;
}
コード例 #13
0
ファイル: files.cpp プロジェクト: JohannesBuchner/multitalk
char *replace_extension(const char *s, const char *extension)
{
	int len = strlen(s);
	char *extended;
	
	for(int pos = len - 1; pos >= 0; pos--)
	{
		if(s[pos] == '/')
		{
			// No extension
			extended = new char[len + strlen(extension) + 2];
			sprintf(extended, "%s.%s", s, extension);
			return extended;
		}
		if(s[pos] == '.')
		{
			if(pos == len - 1)
			{
				// No extension
				extended = new char[len + strlen(extension) + 2];
				sprintf(extended, "%s%s", s, extension);
				return extended;
			}
			if(!strcmp(extension, s + pos + 1))
			{
				// Extension OK
				extended = sdup(s);
				return extended;
			}
			else
			{
				// Different extension (replace):
				extended = new char[pos + strlen(extension) + 2];
				strncpy(extended, s, pos + 1);
				strcpy(extended + pos + 1, extension);
				return extended;
			}
		}
	}
	// No extension
	extended = new char[len + strlen(extension) + 2];
	sprintf(extended, "%s.%s", s, extension);
	return extended;
}
コード例 #14
0
ファイル: syntax.c プロジェクト: ColeJackes/pcp
/* action argument */
Expr *
actArgList(Expr *arg1, char *str)
{
    Expr    *x;

    /* construct expression node for an action argument string */
    x = (Expr *) zalloc(sizeof(Expr));
    x->op = NOP;
    x->smpls[0].ptr = x->ring = sdup(str);
    x->valid = x->nsmpls = x->nvals = 1;
    x->tspan = strlen(str);
    x->sem = SEM_CHAR;
    if (arg1) {
	x->arg1 = arg1;
	arg1->parent = x;
    }

    return x;
}
コード例 #15
0
ファイル: assert.c プロジェクト: certik/nwcc
/*
 * Remove the given assertion (as string).
 */
int destroy_assertion(char *aval)
{
	struct lexer_state lls;
	size_t n = strlen(aval) + 1;
	char *c = sdup(aval);
	int ret;

	*(c + n - 1) = '\n';
	init_buf_lexer_state(&lls, 0);
	lls.flags = DEFAULT_LEXER_FLAGS;
	lls.input = 0;
	lls.input_string = (unsigned char *)c;
	lls.pbuf = 0;
	lls.ebuf = n;
	lls.line = -1;
	ret = handle_unassert(&lls);
	freemem(c);
	free_lexer_state(&lls);
	return ret;
}
コード例 #16
0
ファイル: macro.c プロジェクト: scarabeusiv/ucpp
/*
 * Send a token to the output (a token_fifo in lexer mode, the output
 * buffer in stand alone mode).
 */
void print_token(struct lexer_state *ls, struct token *t, long uz_line)
{
	char *x = t->name;

	if (uz_line && t->line < 0) t->line = uz_line;
	if (ls->flags & LEXER) {
		struct token at;

		at = *t;
		if (S_TOKEN(t->type)) {
			at.name = sdup(at.name);
			throw_away(ls->gf, at.name);
		}
		aol(ls->output_fifo->t, ls->output_fifo->nt, at,
			TOKEN_LIST_MEMG);
		return;
	}
	if (ls->flags & KEEP_OUTPUT) {
		for (; ls->oline < ls->line;) put_char(ls, '\n');
	}
	if (!S_TOKEN(t->type)) x = operators_name[t->type];
	for (; *x; x ++) put_char(ls, *x);
}
コード例 #17
0
ファイル: ConfigFile.cpp プロジェクト: 373137461/OBS
void ConfigFile::LoadData()
{
    TSTR lpCurLine = lpFileData, lpNextLine;
    ConfigSection *lpCurSection=NULL;
    DWORD i;

    lpNextLine = schr(lpCurLine, '\r');

    while(*(lpCurLine = (lpNextLine+2)))
    {
        lpNextLine = schr(lpCurLine, '\r');
        if (!lpNextLine)
            CrashError(TEXT("Your %s file is corrupt, please delete it and re-launch OBS."), strFileName.Array());
        *lpNextLine = 0;

        if((*lpCurLine == '[') && (*(lpNextLine-1) == ']'))
        {
            lpCurSection = Sections.CreateNew();

            lpCurSection->name = sfix(sdup(lpCurLine+1));
            lpCurSection->name[lpNextLine-lpCurLine-2] = 0;
        }
        else if(lpCurSection && *lpCurLine && (*(LPWORD)lpCurLine != '//'))
        {
            TSTR lpValuePtr = schr(lpCurLine, '=');
            if (!lpValuePtr)
                CrashError(TEXT("Your %s file is corrupt, please delete it and re-launch OBS."), strFileName.Array());

            if(lpValuePtr[1] != 0)
            {
                ConfigKey *key=NULL;

                *lpValuePtr = 0;

                for(i=0; i<lpCurSection->Keys.Num(); i++)
                {
                    if(scmpi(lpCurLine, lpCurSection->Keys[i].name) == 0)
                    {
                        key = &lpCurSection->Keys[i];
                        break;
                    }
                }

                if(!key)
                {
                    key = lpCurSection->Keys.CreateNew();
                    key->name = sfix(sdup(lpCurLine));
                }

                *lpValuePtr = '=';

                lpCurLine = lpValuePtr+1;

                TSTR value = sfix(sdup(lpCurLine));
                key->ValueList << value;
            }
        }

        *lpNextLine = '\r';
    }
}
コード例 #18
0
int main()
{
	int idx, idx2;
	int cnt[10] = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100};

	srandom(time(NULL));

	/* reset counter */

	TotalAlloc		= 0;
	TotalFree		= 0;
	NullAlloc			= 0;
	NullFree			= 0;
	TotalAllocSize	= 0;

	TITLE(Test Start);

	for (idx = 0 ; idx < DESTROY_COUNT ; idx ++)
	{
		int i;

		/* Init mm spool */
		for (i = 0 ; i < 10 ; i ++)
			cnt [i] = (random() % 100);

		/* Init */
		upnp_mm_init(cnt);

		SUBSUBTITLE(Start Round......);

		/* Dump */
		upnp_mm_dump();


		for (idx2 = 0 ; idx2 < REINIT_COUNT ; idx2 ++)
		{
			int i;

			SUBSUBTITLE(Reinit mm system......);
			
			bzero(my_alloc, (sizeof(void *) * MAX_ALLOC));

			for (i = 0 ; i < MAX_TEST_COUNT ; i ++)
			{
				allo();
				callo();
				reallo();
				sdup();
				hybrid();
				ran();
			}
			/* Reinit */
			upnp_mm_reinit();
		}

		SUBSUBTITLE(One Round Complete......);

		/* Dump */
		upnp_mm_dump();

		/* Destroy */
		upnp_mm_destroy();
	}

	/* Dump counter */
	TITLE(Test Complete);
	printf("\tTotalAlloc\t(Total Allocation Count)\t:\t%u\n", TotalAlloc);
	printf("\tTotalFree\t(Total Free Count)\t\t:\t%u\n", TotalFree);

	printf("\tNullAlloc\t(Total Count of out-of-memory)\t:\t%u", NullAlloc);
	if (NullAlloc)
		printf("\t(This COULD cause daemon stop!)\n");
	else
		printf("\n");
	
	printf("\tNullFree\t(Free with the NULL pointer)\t:\t%u\n", NullFree);
	printf("\tTotalAllocSize\t(Total Allocated memory size)\t:\t%u\n", TotalAllocSize);
	printf("\n");
	return 0;
}
コード例 #19
0
ファイル: files.cpp プロジェクト: JohannesBuchner/multitalk
Config *init_paths(const char *talk_ref)
{
	Config *config = new Config();
	const char *sys_prefix = "/usr/local/share";
	
	config->talk_path = replace_extension(talk_ref, "talk");
	config->graph_path = replace_extension(talk_ref, "graph");
	config->project_dir = get_path(talk_ref);
	config->latex_dir = replace_extension(talk_ref, "latex");
	config->html_dir = replace_extension(talk_ref, "html");
	config->sys_dir = combine_path(sys_prefix, "multitalk");
	config->sys_image_dir = combine_path(config->sys_dir, "gfx");
	config->sys_style_dir = combine_path(config->sys_dir, "styles");
	config->sys_font_dir = combine_path(config->sys_dir, "fonts");
	config->proj_style_dir = combine_path(config->project_dir, "styles");
	config->proj_font_dir = combine_path(config->project_dir, "fonts");
	config->sys_rc_dir = sdup("/etc");

	config->caption = new char[strlen(config->talk_path) + 20];
	sprintf(config->caption, "Multitalk - %s", config->talk_path);
	
	char *e = getenv("MULTITALK_DIR");
	if(e == NULL)
	{
		config->env_dir = NULL;
		config->env_style_dir = NULL;
		config->env_font_dir = NULL;
		config->env_image_dir = NULL;
	}
	else
	{
		config->env_dir = sdup(e);
		config->env_style_dir = combine_path(config->env_dir, "styles");
		config->env_font_dir = combine_path(config->env_dir, "fonts");
		config->env_image_dir = combine_path(config->env_dir, "gfx");
	}
	
	uid_t id;
	struct passwd *pw;
	
	id = getuid();
	pw = getpwuid(id);
	if(pw == NULL)
		error("Can't lookup home directory");
	config->home_dir = sdup(pw->pw_dir);
	config->home_style_dir = combine_path(config->home_dir, ".multitalk/styles");
	config->home_font_dir = combine_path(config->home_dir, ".multitalk/fonts");
	config->home_image_dir = combine_path(config->home_dir, ".multitalk/gfx");
	config->home_rc_dir = combine_path(config->home_dir, ".multitalk");

	if(debug & DEBUG_PATHS)
	{	
		printf("=== Directories ===\n");
		printf("talk_path = %s\n", config->talk_path);
		printf("project_dir = %s\n", config->project_dir);
		printf("latex_dir = %s\n", config->latex_dir);
		printf("html_dir = %s\n", config->html_dir);
		printf("sys_style_dir = %s\n", config->sys_style_dir);
		printf("home_style_dir = %s\n", config->home_style_dir);
		printf("===================\n");
	}
	
	return config;
}
コード例 #20
0
ファイル: AboutBox.cpp プロジェクト: fedor4ever/packaging
// Creates ScrollTextData reflecting the current registration state
static 
ScrollTextData* 
TitleCreateScrollData(
    HWND hWnd, 
    RegProduct * product)
{
    ScrollTextData* data = (ScrollTextData*)malloc(sizeof(ScrollTextData));
    if (data)
    {
        BOOL registered = (REG_ProductStatus(product) == RegRegistered);
        ZeroMemory(data, sizeof(*data));
        data->hFont = GetWindowFont(hWnd);
        data->bOneTime = registered;
        if (GetObject(data->hFont,sizeof(data->font),&data->font))
        {
            if (data->font.lfHeight == 0)
            {
                data->font.lfHeight = 11;
            } 
            else if (data->font.lfHeight < 0) 
            {
                data->font.lfHeight *= -1;
            }
            data->lineCount = 3;
            data->lines = (LPSTR*)malloc(sizeof(LPSTR)*data->lineCount);
            if (data->lines)
            {
                int i = 0;
                data->lines[i] = sdup("Product key:");
                if (data->lines[i])
                {
                    data->lines[++i] = sdup(REG_ProductKey(product));
                    if (data->lines[i]) {
                        if (registered)
                        {
                            data->lines[++i] = sdup("Registered");
                        } 
                        else
                        {
                            int n1 = REG_DaysSinceFirstRun(product);
                            int n2 = REG_FreeTrialPeriod(product);
                            if (n2 > n1) {
                                int n = n2-n1;
                                if (n2 == n1)
                                {
                                    data->lines[++i] = sdup("Expires today");
                                }
                                else
                                {
                                    // This code won't survive localization.
                                    // It's very specific to the English
                                    // grammar.
                                    char buf[128];
                                    if (n != 11 && (n%10) == 1)
                                    {
                                        sprintf(buf, "Expires in %d day",n);
                                    }
                                    else
                                    {
                                        sprintf(buf, "Expires in %d days",n);
                                    }
                                    data->lines[++i] = sdup(buf);
                                }
                            }
                            else
                            {
                                data->lines[++i] = sdup("Trial period has expired");
                            }
                        }
                        if (data->lines[i])
                        {
                            return data;
                        }
                        free(data->lines[--i]);
                    }
                    free(data->lines[--i]);
                }
                free(data->lines);
            }
        }
        free(data);
    }
    return NULL;
}
コード例 #21
0
ファイル: ldap_xdr.c プロジェクト: bahamas10/openzfs
nis_object *
unmakePseudoEntryObj(entry_obj *e, nis_object *tobj) {
	nis_object	*o;
	XDR		xdrs;
	bool_t		stat;
	char		*myself = "unmakePseudoEntryObj";

	if (e == 0 || e->en_cols.en_cols_val == 0 ||
			e->en_cols.en_cols_len == 0)
		return (0);

	o = am(myself, sizeof (*o));
	if (o == 0)
		return (0);

	xdrmem_create(&xdrs, e->en_cols.en_cols_val[0].ec_value.ec_value_val,
			e->en_cols.en_cols_val[0].ec_value.ec_value_len,
			XDR_DECODE);

	if (tobj != 0 && (e->en_type == 0 || e->en_type[0] == '\0')) {
		stat = xdr_nis_fetus_object(&xdrs, o, tobj);
	} else {
		stat = xdr_nis_object(&xdrs, o);
	}

	if (!stat) {
		sfree(o);
		o = 0;
	}

	/*
	 * If it's an entry object, construct the column information.
	 * We make this a copy, so that 'o' can be freed using
	 * nis_destroy_object().
	 */
	if (o != 0 && o->zo_data.zo_type == NIS_ENTRY_OBJ &&
			o->zo_data.objdata_u.en_data.en_cols.en_cols_val == 0 &&
			e->en_cols.en_cols_len > 1) {
		entry_col	*ec, *oec;
		uint_t		i, *ocl;

		ec = am(myself, (e->en_cols.en_cols_len - 1) * sizeof (ec[0]));
		if (ec == 0) {
			nis_destroy_object(o);
			return (0);
		}

		o->zo_data.objdata_u.en_data.en_cols.en_cols_val = ec;
		o->zo_data.objdata_u.en_data.en_cols.en_cols_len = 0;
		ocl = &o->zo_data.objdata_u.en_data.en_cols.en_cols_len;
		oec = e->en_cols.en_cols_val;

		for (i = 1; i < e->en_cols.en_cols_len; i++) {
			uint_t	len;

			if (oec[i].ec_value.ec_value_val != 0) {
				len = oec[i].ec_value.ec_value_len;
				if (len == 0)
					len++;
				ec[i-1].ec_value.ec_value_val = am(myself, len);
				if (ec[i-1].ec_value.ec_value_val == 0) {
					nis_destroy_object(o);
					return (0);
				}
				(void) memcpy(ec[i-1].ec_value.ec_value_val,
						oec[i].ec_value.ec_value_val,
						oec[i].ec_value.ec_value_len);
				ec[i-1].ec_value.ec_value_len =
						oec[i].ec_value.ec_value_len;
			} else {
				ec[i-1].ec_value.ec_value_val = 0;
				ec[i-1].ec_value.ec_value_len = 0;
			}
			*ocl += 1;
		}
	}

	/*
	 * If it's an entry, and we have the table object, make sure
	 * zo_name and en_type either already are set, or get them
	 * from the table.
	 */
	if (o != 0 && o->zo_data.zo_type == NIS_ENTRY_OBJ && tobj != 0) {
		if (o->zo_name == 0)
			o->zo_name = sdup(myself, T, tobj->zo_name);
		if (o->zo_data.objdata_u.en_data.en_type == 0)
			o->zo_data.objdata_u.en_data.en_type = sdup(myself, T,
				tobj->zo_data.objdata_u.ta_data.ta_type);
	}

	return (o);
}
コード例 #22
0
std::string MongooseNDK::MGstart(const std::string& arg) {
	int res = 0;
	char *options[MAX_OPTIONS];
	Json::Reader reader;
	Json::FastWriter writer;
	Json::Value root;
	Json::Value rval;


	m_pParent->getLog()->debug("MgStartRunning");

	char ptemp[MAXPATHLEN]; // Build default document root in case missing
	getcwd(ptemp, MAXPATHLEN);
	strcat(ptemp,"/data");


	bool parse = reader.parse(arg, root);
	for(unsigned int i=0; i<MAX_OPTIONS; i++) {
		options[i] = NULL;
	}
	if(is_running) {
		rval["status"] = false;
		rval["error"] = "Already Running";
	} else {

 	if (parse) {
 		int xops = 0;

  		if(!root.isMember("document_root")) {
   		  options[xops++] = sdup("document_root");
   		  options[xops++] = sdup(ptemp);
 		}

  		if(!root.isMember("enable_directory_listing")) {
  			options[xops++] = sdup("enable_directory_listing");
     		options[xops++] = sdup("no");
 		}
 		Json::Value::Members memberNames = root.getMemberNames();
 		int ecount = 0;

  		for(unsigned int i=0; i<memberNames.size(); i++) {
  			std::string memberName = memberNames[i];
			options[xops++] = sdup(memberName.c_str());
			options[xops++] = urldecode(root[memberName].asCString());
  		}

  		m_pParent->getLog()->info("Starting Mongoose");
		ecount = start_mongoose(options);

	    for (int idx = 0; options[idx] != NULL; idx++) {
 		  free(options[idx]);
 		  }

 		if(ecount >= 0) {
 			rval["status"] = true;
 			rval["error"] = false;
 			rval["command_errors"] = ecount;

 	 	 	rval["document_root"] = mongoose_get_option("document_root");
 	 	 	rval["listening_ports"] = mongoose_get_option("listening_ports");

 	 	 	is_running = true;

 		} else {
 			ecount = 0 - (ecount + 1);
 			rval["status"] = false;
 			rval["error"] = "Unable to start server";
 			rval["command_errors"] = ecount;
 		}

	} else {
		rval["status"] = false;
		rval["error"] = "Unable to parse JSON";
	}

	}

	return writer.write(rval);
}
コード例 #23
0
ファイル: pragmatics.c プロジェクト: linwukang/pcp
/* reinitialize Metric - only for live host */
int      /* 1: ok, 0: try again later, -1: fail */
reinitMetric(Metric *m)
{
    char	*hname = symName(m->hname);
    char	*mname = symName(m->mname);
    char	**inames;
    int		*iids;
    int		handle;
    int		ret = 1;
    int		sts;
    int		i, j;

    /* set up temporary context */
    if ((handle = newContext(hname)) < 0)
	return 0;

    host_state_changed(hname, STATE_RECONN);

    if ((sts = pmLookupName(1, &mname, &m->desc.pmid)) < 0) {
	ret = 0;
	goto end;
    }

    /* fill in performance metric descriptor */
    if ((sts = pmLookupDesc(m->desc.pmid, &m->desc)) < 0) {
	ret = 0;
        goto end;
    }

    if (m->desc.type == PM_TYPE_STRING ||
	m->desc.type == PM_TYPE_AGGREGATE ||
	m->desc.type == PM_TYPE_AGGREGATE_STATIC ||
	m->desc.type == PM_TYPE_EVENT ||
	m->desc.type == PM_TYPE_HIGHRES_EVENT ||
	m->desc.type == PM_TYPE_UNKNOWN) {
	fprintf(stderr, "%s: metric %s has non-numeric type\n", pmProgname, mname);
	ret = -1;
    }
    else if (m->desc.indom == PM_INDOM_NULL) {
	if (m->specinst != 0) {
	    fprintf(stderr, "%s: metric %s has no instances\n", pmProgname, mname);
	    ret = -1;
	}
	else
	    m->m_idom = 1;
    }
    else {
	if ((sts = pmGetInDom(m->desc.indom, &iids, &inames)) < 0) { /* full profile */
	    ret = 0;
	}
	else {
	    if (m->specinst == 0) {
		/* all instances */
		m->iids = iids;
		m->m_idom = sts;
		m->inames = alloc(m->m_idom*sizeof(char *));
		for (i = 0; i < m->m_idom; i++) {
		    m->inames[i] = sdup(inames[i]);
		}
	    }
	    else {
		/* explicit instance profile */
		m->m_idom = 0;
		for (i = 0; i < m->specinst; i++) {
		    /* look for first matching instance name */
		    for (j = 0; j < sts; j++) {
			if (eqinst(m->inames[i], inames[j])) {
			    m->iids[i] = iids[j];
			    m->m_idom++;
			    break;
			}
		    }
		    if (j == sts) {
			m->iids[i] = PM_IN_NULL;
			ret = 0;
		    }
		}
		if (sts > 0) {
		    /*
		     * pmGetInDom or pmGetInDomArchive returned some
		     * instances above
		     */
		    free(iids);
		}

		/* 
		 * if specinst != m_idom, then some not found ... move these
		 * to the end of the list
		 */
		for (j = m->specinst-1; j >= 0; j--) {
		    if (m->iids[j] != PM_IN_NULL)
			break;
		}
		for (i = 0; i < j; i++) {
		    if (m->iids[i] == PM_IN_NULL) {
			/* need to swap */
			char	*tp;
			tp = m->inames[i];
			m->inames[i] = m->inames[j];
			m->iids[i] = m->iids[j];
			m->inames[j] = tp;
			m->iids[j] = PM_IN_NULL;
			j--;
		    }
		}
	    }

#if PCP_DEBUG
	    if (pmDebug & DBG_TRACE_APPL1) {
		int	numinst;
		fprintf(stderr, "reinitMetric: %s from %s: instance domain specinst=%d\n",
			mname, hname, m->specinst);
		if (m->m_idom < 1) fprintf(stderr, "  %d instances!\n", m->m_idom);
		if (m->specinst == 0) numinst = m->m_idom;
		else numinst = m->specinst;
		for (i = 0; i < numinst; i++) {
		    fprintf(stderr, "  indom[%d]", i);
		    if (m->iids[i] == PM_IN_NULL) 
			fprintf(stderr, " ?missing");
		    else
			fprintf(stderr, " %d", m->iids[i]);
		    fprintf(stderr, " \"%s\"\n", m->inames[i]);
		}
	    }
#endif
	    if (sts > 0) {
		/*
		 * pmGetInDom or pmGetInDomArchive returned some instances
		 * above
		 */
		free(inames);
	    }
	}
    }

    if (ret == 1) {
	/* compute conversion factor into canonical units
	   - non-zero conversion factor flags initialized metric */
	m->conv = scale(m->desc.units);

	/* automatic rate computation */
	if (m->desc.sem == PM_SEM_COUNTER) {
	    m->vals = (double *) ralloc(m->vals, m->m_idom * sizeof(double));
	    for (j = 0; j < m->m_idom; j++)
		m->vals[j] = 0;
	}
    }

    if (ret >= 0) {
	/*
	 * re-shape, starting here are working up the expression until
	 * we reach the top of the tree or the designated metrics
	 * associated with the node are not the same
	 */
	Expr	*x = m->expr;
	while (x) {
	    /*
	     * only re-shape expressions that may have set values
	     */
	    if (x->op == CND_FETCH ||
		x->op == CND_NEG || x->op == CND_ADD || x->op == CND_SUB ||
		x->op == CND_MUL || x->op == CND_DIV ||
		x->op == CND_SUM_HOST || x->op == CND_SUM_INST ||
		x->op == CND_SUM_TIME ||
		x->op == CND_AVG_HOST || x->op == CND_AVG_INST ||
		x->op == CND_AVG_TIME ||
		x->op == CND_MAX_HOST || x->op == CND_MAX_INST ||
		x->op == CND_MAX_TIME ||
		x->op == CND_MIN_HOST || x->op == CND_MIN_INST ||
		x->op == CND_MIN_TIME ||
		x->op == CND_EQ || x->op == CND_NEQ ||
		x->op == CND_LT || x->op == CND_LTE ||
		x->op == CND_GT || x->op == CND_GTE ||
		x->op == CND_NOT || x->op == CND_AND || x->op == CND_OR ||
		x->op == CND_RISE || x->op == CND_FALL || x->op == CND_INSTANT ||
		x->op == CND_MATCH || x->op == CND_NOMATCH) {
		instFetchExpr(x);
		findEval(x);
#if PCP_DEBUG
		if (pmDebug & DBG_TRACE_APPL1) {
		    fprintf(stderr, "reinitMetric: re-shaped ...\n");
		    dumpExpr(x);
		}
#endif
	    }
	    if (x->parent) {
		x = x->parent;
		if (x->metrics == m)
		    continue;
	    }
	    break;
	}
    }

end:
    /* destroy temporary context */
    pmDestroyContext(handle);

    return ret;
}
コード例 #24
0
ファイル: macro.c プロジェクト: scarabeusiv/ucpp
/*
 * We found a #define directive; parse the end of the line, perform
 * sanity checks, store the new macro into the "macros" hash table.
 *
 * In case of a redefinition of a macro: we enforce the rule that a
 * macro should be redefined identically, including the spelling of
 * parameters. We emit an error on offending code; dura lex, sed lex.
 * After all, it is easy to avoid such problems, with a #undef directive.
 */
int handle_define(struct lexer_state *ls)
{
	struct macro *m = 0, *n;
	struct token_fifo mv;
	int ltwws = 1, redef = 0;
	char *mname = 0;
	int narg;
	size_t nt;
	long l = ls->line;

	mv.art = mv.nt = 0;
	mv.t = NULL;
	/* find the next non-white token on the line, this should be
	   the macro name */
	while (!next_token(ls) && ls->ctok->type != NEWLINE) {
		if (ttMWS(ls->ctok->type)) continue;
		if (ls->ctok->type == NAME) mname = sdup(ls->ctok->name);
		break;
	}
	if (mname == 0) {
		error(l, "missing macro name");
		return 1;
	}
	if (check_special_macro(mname)) {
		error(l, "trying to redefine the special macro %s", mname);
		goto warp_error;
	}
	/*
	 * If a macro with this name was already defined: the K&R
	 * states that the new macro should be identical to the old one
	 * (with some arcane rule of equivalence of whitespace); otherwise,
	 * redefining the macro is an error. Most preprocessors would
	 * only emit a warning (or nothing at all) on an unidentical
	 * redefinition.
	 *
	 * Since it is easy to avoid this error (with a #undef directive),
	 * we choose to enforce the rule and emit an error.
	 */
	if ((n = HTT_get(&macros, mname)) != 0) {
		/* redefinition of a macro: we must check that we define
		   it identical */
		redef = 1;
		n->cval.rp = 0;
		freemem(mname);
		mname = 0;
	}
	if (!redef) {
		m = new_macro();
		m->narg = -1;
#define mval	mv
	}
	if (next_token(ls)) goto define_end;
	/*
	 * Check if the token immediately following the macro name is
	 * a left parenthesis; if so, then this is a macro with arguments.
	 * Collect their names and try to match the next parenthesis.
	 */
	if (ls->ctok->type == LPAR) {
		int i, j;
		int need_comma = 0, saw_mdots = 0;

		narg = 0;
		while (!next_token(ls)) {
			if (ls->ctok->type == NEWLINE) {
				error(l, "truncated macro definition");
				goto define_error;
			}
			if (ls->ctok->type == COMMA) {
				if (saw_mdots) {
					error(l, "'...' must end the macro "
						"argument list");
					goto warp_error;
				}
				if (!need_comma) {
					error(l, "void macro argument");
					goto warp_error;
				}
				need_comma = 0;
				continue;
			} else if (ls->ctok->type == NAME) {
				if (saw_mdots) {
					error(l, "'...' must end the macro "
						"argument list");
					goto warp_error;
				}
				if (need_comma) {
					error(l, "missing comma in "
						"macro argument list");
					goto warp_error;
				}
				if (!redef) {
					aol(m->arg, narg,
						sdup(ls->ctok->name), 8);
					/* we must keep track of m->narg
					   so that cleanup in case of
					   error works. */
					m->narg = narg;
					if (narg == 128
						&& (ls->flags & WARN_STANDARD))
						warning(l, "more arguments to "
							"macro than the ISO "
							"limit (127)");
					if (narg == 32767) {
						error(l, "too many arguments "
							"in macro definition "
							"(max 32766)");
						goto warp_error;
					}
				} else {
					/* this is a redefinition of the
					   macro; check equality between
					   old and new definitions */
					if (narg >= n->narg) goto redef_error;
					if (strcmp(ls->ctok->name,
						n->arg[narg ++]))
						goto redef_error;
				}
				need_comma = 1;
				continue;
			} else if ((ls->flags & MACRO_VAARG)
				&& ls->ctok->type == MDOTS) {
				if (need_comma) {
					error(l, "missing comma before '...'");
					goto warp_error;
				}
				if (redef && !n->vaarg) goto redef_error;
				if (!redef) m->vaarg = 1;
				saw_mdots = 1;
				need_comma = 1;
				continue;
			} else if (ls->ctok->type == RPAR) {
				if (narg > 0 && !need_comma) {
					error(l, "void macro argument");
					goto warp_error;
				}
				if (redef && n->vaarg && !saw_mdots)
					goto redef_error;
				break;
			} else if (ttMWS(ls->ctok->type)) {
				continue;
			}
			error(l, "invalid macro argument");
			goto warp_error;
		}
		if (!redef) {
			for (i = 1; i < narg; i ++) for (j = 0; j < i; j ++)
				if (!strcmp(m->arg[i], m->arg[j])) {
					error(l, "duplicate macro "
						"argument");
					goto warp_error;
				}
		}
		if (!redef) m->narg = narg;
	} else {
		if (!ttWHI(ls->ctok->type) && (ls->flags & WARN_STANDARD))
			warning(ls->line, "identifier not followed by "
				"whitespace in #define");
		ls->flags |= READ_AGAIN;
		narg = 0;
	}
	if (redef) nt = 0;

	/* now, we have the arguments. Let's get the macro contents. */
	while (!next_token(ls) && ls->ctok->type != NEWLINE) {
		struct token t;

		t.type = ls->ctok->type;
		if (ltwws && ttMWS(t.type)) continue;
		t.line = 0;
		if (t.type == NAME) {
			int i;

			if ((ls->flags & MACRO_VAARG)
				&& !strcmp(ls->ctok->name, "__VA_ARGS__")) {
				if (redef) {
					if (!n->vaarg) goto redef_error;
				} else if (!m->vaarg) {
					error(l, "'__VA_ARGS__' is forbidden "
						"in macros with a fixed "
						"number of arguments");
					goto warp_error;
				}
				t.type = MACROARG;
				t.line = redef ? n->narg : m->narg;
			}
			for (i = 0; i < narg; i ++)
				if (!strcmp(redef ? n->arg[i] : m->arg[i],
					ls->ctok->name)) {
					t.type = MACROARG;
					/* this is a hack: we store the
					   argument number in the line field */
					t.line = i;
					break;
				}
		}
		if (!redef && S_TOKEN(t.type)) t.name = sdup(ls->ctok->name);
		if (ttMWS(t.type)) {
			if (ltwws) continue;
#ifdef SEMPER_FIDELIS
			t.type = OPT_NONE;
#else
			t.type = NONE;
#endif
			ltwws = 1;
		} else ltwws = 0;
		if (!redef) {
			/* we ensure that each macro token has a correct
			   line number */
			if (t.type != MACROARG) t.line = 1;
			aol(mval.t, mval.nt, t, TOKEN_LIST_MEMG);
		} else {
			int tt;

			if (n->cval.rp >= n->cval.length) {
#ifdef SEMPER_FIDELIS
				if (t.type != OPT_NONE) goto redef_error;
#else
				if (t.type != NONE) goto redef_error;
#endif
			} else if (t.type != n->cval.t[n->cval.rp]) {
				goto redef_error;
			} else if (t.type == MACROARG) {
				unsigned anum = n->cval.t[n->cval.rp + 1];

				if (anum >= 128U) anum = ((anum & 127U) << 8)
					| m->cval.t[n->cval.rp + 2];
				if (anum != (unsigned)t.line) goto redef_error;
			} else if (S_TOKEN(t.type) && strcmp(ls->ctok->name,
				   (char *)(n->cval.t + n->cval.rp + 1))) {
				goto redef_error;
			}
			tt = n->cval.t[n->cval.rp ++];
			if (S_TOKEN(tt)) n->cval.rp += 1
				+ strlen((char *)(n->cval.t + n->cval.rp));
			else if (tt == MACROARG) {
				if (n->cval.t[++ n->cval.rp] >= 128)
					n->cval.rp ++;
			}
			nt ++;
		}
	}

	if (redef) {
		if (n->cval.rp < n->cval.length) goto redef_error_2;
		return 0;
	}

	/* now we have the complete macro; perform some checks about
	   the operators # and ##, and, if everything is ok,
	   store the macro into the hash table */
define_end:
#ifdef SEMPER_FIDELIS
	if (mval.nt && mval.t[mval.nt - 1].type == OPT_NONE) {
#else
	if (mval.nt && mval.t[mval.nt - 1].type == NONE) {
#endif
		mval.nt --;
		if (mval.nt == 0) freemem(mval.t);
	}
	if (mval.nt != 0) {
		/* some checks about the macro */
		if (mval.t[0].type == DSHARP
			|| mval.t[0].type == DIG_DSHARP
			|| mval.t[mval.nt - 1].type == DSHARP
			|| mval.t[mval.nt - 1].type == DIG_DSHARP) {
			error(l, "operator '##' may neither begin "
				"nor end a macro");
			goto define_error;
		}
		if (m->narg >= 0) {
			size_t i;
			for (i = 0; i < mval.nt; i ++)
				if ((mval.t[i].type == SHARP
					|| mval.t[i].type == DIG_SHARP) &&
					(i == (mval.nt - 1)
					|| (ttMWS(mval.t[i + 1].type) &&
					    (i == mval.nt - 2
					     || mval.t[i + 2].type != MACROARG))
					|| (!ttMWS(mval.t[i + 1].type)
					     && mval.t[i + 1].type != MACROARG))) {
					error(l, "operator '#' not followed "
						"by a macro argument");
					goto define_error;
				}
		}
	}
	{
		size_t i, l;

		for (i = 0, l = 0; i < mval.nt; i ++) {
			l ++;
			if (S_TOKEN(mval.t[i].type))
				l += 1 + strlen(mval.t[i].name);
			else if (mval.t[i].type == MACROARG) {
				l ++;
				if (mval.t[i].line >= 128) l ++;
			}
		}
		m->cval.length = l;
		if (l) m->cval.t = getmem(l);
		for (i = 0, l = 0; i < mval.nt; i ++) {
			m->cval.t[l ++] = mval.t[i].type;
			if (S_TOKEN(mval.t[i].type)) {
				size_t x = 1 + strlen(mval.t[i].name);

				mmv(m->cval.t + l, mval.t[i].name, x);
				l += x;
				freemem(mval.t[i].name);
			}
			else if (mval.t[i].type == MACROARG) {
				unsigned anum = mval.t[i].line;

				if (anum >= 128) {
					m->cval.t[l ++] = 128 | (anum >> 8);
					m->cval.t[l ++] = anum & 0xFF;
				} else {
					m->cval.t[l ++] = anum;
				}
			}
		}
コード例 #25
0
ファイル: assert.c プロジェクト: certik/nwcc
/*
 * for #unassert
 */
int handle_unassert(struct lexer_state *ls)
{
	int ltww;
	struct ucpp_token t;
	struct token_fifo atl;
	struct assert *a;
	int ret = -1;
	long l = ls->line;
	int nnp;
	size_t i;

	atl.art = atl.nt = 0;
	while (!next_token(ls)) {
		if (ls->ctok->type == NEWLINE) break;
		if (ttMWS(ls->ctok->type)) continue;
		if (ls->ctok->type == NAME) {
			if (!(a = HTT_get(&assertions, ls->ctok->name))) {
				ret = 0;
				goto handle_unassert_warp;
			}
			goto handle_unassert_next;
		}
		error(l, "illegal assertion name for #unassert");
		goto handle_unassert_warp;
	}
	goto handle_unassert_trunc;

handle_unassert_next:
	while (!next_token(ls)) {
		if (ls->ctok->type == NEWLINE) break;
		if (ttMWS(ls->ctok->type)) continue;
		if (ls->ctok->type != LPAR) {
			error(l, "syntax error in #unassert");
			goto handle_unassert_warp;
		}
		goto handle_unassert_next2;
	}
	if (emit_assertions)
		fprintf(emit_output, "#unassert %s\n", HASH_ITEM_NAME(a));
	HTT_del(&assertions, HASH_ITEM_NAME(a));
	return 0;

handle_unassert_next2:
	for (nnp = 1, ltww = 1; nnp && !next_token(ls);) {
		if (ls->ctok->type == NEWLINE) break;
		if (ltww && ttMWS(ls->ctok->type)) continue;
		ltww = ttMWS(ls->ctok->type);
		if (ls->ctok->type == LPAR) nnp ++;
		else if (ls->ctok->type == RPAR) {
			if (!(-- nnp)) goto handle_unassert_next3;
		}
		t.type = ls->ctok->type;
		if (S_TOKEN(t.type)) t.name = sdup(ls->ctok->name);
		aol(atl.t, atl.nt, t, TOKEN_LIST_MEMG);
	}
	goto handle_unassert_trunc;

handle_unassert_next3:
	while (!next_token(ls) && ls->ctok->type != NEWLINE) {
		if (!ttWHI(ls->ctok->type) && (ls->flags & WARN_STANDARD)) {
			warning(l, "trailing garbage in #unassert");
		}
	}
	if (atl.nt && ttMWS(atl.t[atl.nt - 1].type) && (-- atl.nt) == 0)
		freemem(atl.t);
	if (atl.nt == 0) {
		error(l, "void assertion in #unassert");
		return ret;
	}
	for (i = 0; i < a->nbval && cmp_token_list(&atl, a->val + i); i ++);
	if (i != a->nbval) {
		/* we have it, undefine it */
		del_token_fifo(a->val + i);
		if (i < (a->nbval - 1))
			mmvwo(a->val + i, a->val + i + 1, (a->nbval - i - 1)
				* sizeof(struct token_fifo));
		if ((-- a->nbval) == 0) freemem(a->val);
		if (emit_assertions) {
			fprintf(emit_output, "#unassert %s(",
				HASH_ITEM_NAME(a));
			print_token_fifo(&atl);
			fputs(")\n", emit_output);
		}
	}
	ret = 0;
	goto handle_unassert_finish;

handle_unassert_trunc:
	error(l, "unfinished #unassert");
handle_unassert_finish:
	if (atl.nt) del_token_fifo(&atl);
	return ret;
handle_unassert_warp:
	while (!next_token(ls) && ls->ctok->type != NEWLINE);
	return ret;
}
コード例 #26
0
ファイル: assert.c プロジェクト: certik/nwcc
/*
 * for #assert
 * Assertions are not part of the ISO-C89 standard, but they are sometimes
 * encountered, for instance in Solaris standard include files.
 */
int handle_assert(struct lexer_state *ls)
{
	int ina = 0, ltww;
	struct ucpp_token t;
	struct token_fifo *atl = 0;
	struct assert *a;
	char *aname;
	int ret = -1;
	long l = ls->line;
	int nnp;
	size_t i;

	while (!next_token(ls)) {
		if (ls->ctok->type == NEWLINE) break;
		if (ttMWS(ls->ctok->type)) continue;
		if (ls->ctok->type == NAME) {
			if (!(a = HTT_get(&assertions, ls->ctok->name))) {
				a = new_assertion();
				aname = sdup(ls->ctok->name);
				ina = 1;
			}
			goto handle_assert_next;
		}
		error(l, "illegal assertion name for #assert");
		goto handle_assert_warp_ign;
	}
	goto handle_assert_trunc;

handle_assert_next:
	while (!next_token(ls)) {
		if (ls->ctok->type == NEWLINE) break;
		if (ttMWS(ls->ctok->type)) continue;
		if (ls->ctok->type != LPAR) {
			error(l, "syntax error in #assert");
			goto handle_assert_warp_ign;
		}
		goto handle_assert_next2;
	}
	goto handle_assert_trunc;

handle_assert_next2:
	atl = getmem(sizeof(struct token_fifo));
	atl->art = atl->nt = 0;
	for (nnp = 1, ltww = 1; nnp && !next_token(ls);) {
		if (ls->ctok->type == NEWLINE) break;
		if (ltww && ttMWS(ls->ctok->type)) continue;
		ltww = ttMWS(ls->ctok->type);
		if (ls->ctok->type == LPAR) nnp ++;
		else if (ls->ctok->type == RPAR) {
			if (!(-- nnp)) goto handle_assert_next3;
		}
		t.type = ls->ctok->type;
		if (S_TOKEN(t.type)) t.name = sdup(ls->ctok->name);
		aol(atl->t, atl->nt, t, TOKEN_LIST_MEMG);
	}
	goto handle_assert_trunc;

handle_assert_next3:
	while (!next_token(ls) && ls->ctok->type != NEWLINE) {
		if (!ttWHI(ls->ctok->type) && (ls->flags & WARN_STANDARD)) {
			warning(l, "trailing garbage in #assert");
		}
	}
	if (atl->nt && ttMWS(atl->t[atl->nt - 1].type) && (-- atl->nt) == 0)
		freemem(atl->t);
	if (atl->nt == 0) {
		error(l, "void assertion in #assert");
		goto handle_assert_error;
	}
	for (i = 0; i < a->nbval && cmp_token_list(atl, a->val + i); i ++);
	if (i != a->nbval) {
		/* we already have it */
		ret = 0;
		goto handle_assert_error;
	}

	/* This is a new assertion. Let's keep it. */
	aol(a->val, a->nbval, *atl, TOKEN_LIST_MEMG);
	if (ina) {
		HTT_put(&assertions, a, aname);
		freemem(aname);
	}
	if (emit_assertions) {
		fprintf(emit_output, "#assert %s(", HASH_ITEM_NAME(a));
		print_token_fifo(atl);
		fputs(")\n", emit_output);
	}
	freemem(atl);
	return 0;

handle_assert_trunc:
	error(l, "unfinished #assert");
handle_assert_error:
	if (atl) {
		del_token_fifo(atl);
		freemem(atl);
	}
	if (ina) {
		freemem(aname);
		freemem(a);
	}
	return ret;
handle_assert_warp_ign:
	while (!next_token(ls) && ls->ctok->type != NEWLINE);
	if (ina) {
		freemem(aname);
		freemem(a);
	}
	return ret;
}
コード例 #27
0
ファイル: mem.c プロジェクト: scarabeusiv/ucpp
char *(sdup)(const char *s)
{
	return sdup(s);
}
コード例 #28
0
ファイル: pragmatics.c プロジェクト: linwukang/pcp
/* initialize Metric */
int      /* 1: ok, 0: try again later, -1: fail */
initMetric(Metric *m)
{
    char	*hname = symName(m->hname);
    char	*mname = symName(m->mname);
    char	**inames;
    int		*iids;
    int		handle;
    int		ret = 1;
    int		sts;
    int		i, j;

    /* set up temporary context */
    if ((handle = newContext(hname)) < 0)
	return 0;

    host_state_changed(hname, STATE_RECONN);

    if ((sts = pmLookupName(1, &mname, &m->desc.pmid)) < 0) {
	fprintf(stderr, "%s: metric %s not in namespace for %s\n"
		"pmLookupName failed: %s\n",
		pmProgname, mname, findsource(hname), pmErrStr(sts));
	ret = 0;
	goto end;
    }

    /* fill in performance metric descriptor */
    if ((sts = pmLookupDesc(m->desc.pmid, &m->desc)) < 0) {
	fprintf(stderr, "%s: metric %s not currently available from %s\n"
		"pmLookupDesc failed: %s\n",
		pmProgname, mname, findsource(hname), pmErrStr(sts));
	ret = 0;
	goto end;
    }

    if (m->desc.type == PM_TYPE_STRING ||
	m->desc.type == PM_TYPE_AGGREGATE ||
	m->desc.type == PM_TYPE_AGGREGATE_STATIC ||
	m->desc.type == PM_TYPE_EVENT ||
	m->desc.type == PM_TYPE_HIGHRES_EVENT ||
	m->desc.type == PM_TYPE_UNKNOWN) {
	fprintf(stderr, "%s: metric %s has non-numeric type\n", pmProgname, mname);
	ret = -1;
    }
    else if (m->desc.indom == PM_INDOM_NULL) {
	if (m->specinst != 0) {
	    fprintf(stderr, "%s: metric %s has no instances\n", pmProgname, mname);
	    ret = -1;
	}
	else
	    m->m_idom = 1;
    }
    else {
	/* metric has instances, get full instance profile */
	if (archives) {
	    if ((sts = pmGetInDomArchive(m->desc.indom, &iids, &inames)) < 0) {
		fprintf(stderr, "Metric %s from %s - instance domain not "
			"available in archive\npmGetInDomArchive failed: %s\n",
			mname, findsource(hname), pmErrStr(sts));
		ret = -1;
	    }
	}
	else if ((sts = pmGetInDom(m->desc.indom, &iids, &inames)) < 0) {
	    fprintf(stderr, "Instance domain for metric %s from %s not (currently) available\n"
		    "pmGetIndom failed: %s\n", mname, findsource(hname), pmErrStr(sts));
	    ret = 0;
	}

	if (ret == 1) {	/* got instance profile */
	    if (m->specinst == 0) {
		/* all instances */
		m->iids = iids;
		m->m_idom = sts;
		m->inames = alloc(m->m_idom*sizeof(char *));
		for (i = 0; i < m->m_idom; i++) {
		    m->inames[i] = sdup(inames[i]);
		}
	    }
	    else {
		/* selected instances only */
		m->m_idom = 0;
		for (i = 0; i < m->specinst; i++) {
		    /* look for first matching instance name */
		    for (j = 0; j < sts; j++) {
			if (eqinst(m->inames[i], inames[j])) {
			    m->iids[i] = iids[j];
			    m->m_idom++;
			    break;
			}
		    }
		    if (j == sts) {
			__pmNotifyErr(LOG_ERR, "metric %s from %s does not "
				"(currently) have instance \"%s\"\n",
				mname, findsource(hname), m->inames[i]);
			m->iids[i] = PM_IN_NULL;
			ret = 0;
		    }
		}
		if (sts > 0) {
		    /*
		     * pmGetInDom or pmGetInDomArchive returned some
		     * instances above
		     */
		    free(iids);
		}

		/* 
		 * if specinst != m_idom, then some not found ... move these
		 * to the end of the list
		 */
		for (j = m->specinst-1; j >= 0; j--) {
		    if (m->iids[j] != PM_IN_NULL)
			break;
		}
		for (i = 0; i < j; i++) {
		    if (m->iids[i] == PM_IN_NULL) {
			/* need to swap */
			char	*tp;
			tp = m->inames[i];
			m->inames[i] = m->inames[j];
			m->iids[i] = m->iids[j];
			m->inames[j] = tp;
			m->iids[j] = PM_IN_NULL;
			j--;
		    }
		}
	    }

#if PCP_DEBUG
	    if (pmDebug & DBG_TRACE_APPL1) {
		int	numinst;
		fprintf(stderr, "initMetric: %s from %s: instance domain specinst=%d\n",
			mname, hname, m->specinst);
		if (m->m_idom < 1) fprintf(stderr, "  %d instances!\n", m->m_idom);
		numinst =  m->specinst == 0 ? m->m_idom : m->specinst;
		for (i = 0; i < numinst; i++) {
		    fprintf(stderr, "  indom[%d]", i);
		    if (m->iids[i] == PM_IN_NULL) 
			fprintf(stderr, " ?missing");
		    else
			fprintf(stderr, " %d", m->iids[i]);
		    fprintf(stderr, " \"%s\"\n", m->inames[i]);
		}
	    }
#endif
	    if (sts > 0) {
		/*
		 * pmGetInDom or pmGetInDomArchive returned some instances
		 * above
		 */
		free(inames);
	    }
	}
    }

    if (ret == 1) {
	/* compute conversion factor into canonical units
	   - non-zero conversion factor flags initialized metric */
	m->conv = scale(m->desc.units);

	/* automatic rate computation */
	if (m->desc.sem == PM_SEM_COUNTER) {
	    m->vals = (double *) ralloc(m->vals, m->m_idom * sizeof(double));
	    for (j = 0; j < m->m_idom; j++)
		m->vals[j] = 0;
	}
    }

end:
    /* destroy temporary context */
    pmDestroyContext(handle);

    /* retry not meaningful for archives */
    if (archives && (ret == 0))
	ret = -1;

    return ret;
}