Esempio n. 1
6
int					main(int argc, char **argv)
{
	char		*line;
	int			fd;
	int			i;
	t_param		*event;

	event = NULL;
	i = 0;
	if (argc == 2)
	{
		event = event_initializer(event, argv);
		fd = clean_open(argv[1], O_RDONLY);
		while (get_next_line(fd, &line))
		{
			ischar(line);
			event->map[i] = ft_strsplit(line, ' ');
			i++;
		}
		if (line)
		{
			ft_strdel(&line);
			event_maker(event);
		}
	}
	return (0);
}
Esempio n. 2
0
int same (char regex[], char string[], int i) {

    if (!ischar(string[i]))
	return FALSE;

    if (!ischar(regex[i]))
	return FALSE;

    if (regex[i] == string[i] ||
	regex[i] == '?')
	return TRUE;
    return FALSE;
}
Esempio n. 3
0
To lexical_cast(const From& val){
    To output;
    bool except=false;
    std::stringstream ss,ss_c;
    std::stringstream checker_before, checker_after;
    ss<<val;
    ss>>output;
    checker_before<<val;
    checker_after<<output;
    if(checker_before.str().empty()) except=true;
    if(checker_after.str().empty()) except=true;
    if(checker_before.str().size()>1){
        if(ischar(checker_before.str().back()))
            except=true;
        if(checker_before.str().back()==' ')
            except=true;
    }
    if(checker_before.str().size()>0){
        if(checker_before.str()[0]==' ')
            except=true;
    }
    if(ss.bad()) except=true;
    {
        long long int a,b;
        checker_after>>a;
        checker_before>>b;
        if(a!=b) except=true;
    }

    if(except) throw bad_lexical_cast();
    return output;
}
Esempio n. 4
0
int				ft_neighbor(char **piece)
{
	int			i;
	int			j;
	int			l;
	int			k;

	i = 0;
	j = 0;
	k = 0;
	l = 0;
	while (i < 4)
	{
		while (j < 4)
		{
			if (ischar(piece[i][j]) == 0)
				return (0);
			if (piece[i][j] == '#')
				l += ft_neighbor_utils(piece, i, j, &k);
			j++;
		}
		i++;
		j = 0;
	}
	return (((l == 6 || l == 8) && k == 4) ? 1 : 0);
}
Esempio n. 5
0
static int
command_read(int argc, char *argv[])
{
    char	*prompt;
    int		timeout;
    time_t	when;
    char	*cp;
    char	*name;
    char	buf[256];		/* XXX size? */
    int		c;
    
    timeout = -1;
    prompt = NULL;
    optind = 1;
    optreset = 1;
    while ((c = getopt(argc, argv, "p:t:")) != -1) {
	switch(c) {
	    
	case 'p':
	    prompt = optarg;
	    break;
	case 't':
	    timeout = strtol(optarg, &cp, 0);
	    if (cp == optarg) {
		snprintf(command_errbuf, sizeof(command_errbuf),
		    "bad timeout '%s'", optarg);
		return(CMD_ERROR);
	    }
	    break;
	default:
	    return(CMD_OK);
	}
    }

    argv += (optind);
    argc -= (optind);
    if (argc > 1) {
	command_errmsg = "wrong number of arguments";
	return(CMD_ERROR);
    }
    name = (argc > 0) ? argv[0]: NULL;
	
    if (prompt != NULL)
	printf("%s", prompt);
    if (timeout >= 0) {
	when = time(NULL) + timeout;
	while (!ischar())
	    if (time(NULL) >= when)
		return(CMD_OK);		/* is timeout an error? */
    }

    ngets(buf, sizeof(buf));

    if (name != NULL)
	setenv(name, buf, 1);
    return(CMD_OK);
}
Esempio n. 6
0
int32_t compiler::to_literal(const std::string& s)
{
  if ( isnumber(s.c_str()) )
    return atoi(s.c_str());

  if ( ischar(s) )
    return to_ord(s);

  return -1;
}
Esempio n. 7
0
/*           key? - check for a character from stdin (FACILITY)
 *
 * key? ( -- flag )
 */
static void keyQuestion(FICL_VM *pVM)
{
#if FICL_ROBUST > 1
    vmCheckStack(pVM, 0, 1);
#endif
#ifdef TESTMAIN
    /* XXX Since we don't fiddle with termios, let it always succeed... */
    stackPushINT(pVM->pStack, FICL_TRUE);
#else
    /* But here do the right thing. */
    stackPushINT(pVM->pStack, ischar()? FICL_TRUE : FICL_FALSE);
#endif
    return;
}
Esempio n. 8
0
File: error.c Progetto: pipul/lab
/* printtoken - print current token preceeded by a space */
static void printtoken(void)
{
    switch (t) {
    case ID:
        fprint(stderr, " `%s'", token);
        break;
    case ICON:
        fprint(stderr, " `%s'", vtoa(tsym->type, tsym->u.c.v));
        break;
    case SCON: {
        int i, n;
        if (ischar(tsym->type->type)) {
            char *s = tsym->u.c.v.p;
            n = tsym->type->size;
            fprint(stderr, " \"");
            for (i = 0; i < 20 && i < n && *s; s++, i++)
                if (*s < ' ' || *s >= 0177)
                    fprint(stderr, "\\%o", *s);
                else
                    fprint(stderr, "%c", *s);
        } else {	/* wchar_t string */
            unsigned int *s = tsym->u.c.v.p;
            assert(tsym->type->type->size == widechar->size);
            n = tsym->type->size/widechar->size;
            fprint(stderr, " L\"");
            for (i = 0; i < 20 && i < n && *s; s++, i++)
                if (*s < ' ' || *s >= 0177)
                    fprint(stderr, "\\x%x", *s);
                else
                    fprint(stderr, "%c", *s);
        }
        if (i < n)
            fprint(stderr, " ...");
        else
            fprint(stderr, "\"");
        break;
    }
    case FCON:
        fprint(stderr, " `%S'", token, (char*)cp - token);
        break;
    case '`':
    case '\'':
        fprint(stderr, " \"%k\"", t);
        break;
    default:
        fprint(stderr, " `%k'", t);
    }
}
Esempio n. 9
0
Datum
ctos(Datum d)
{				/* convert char to string */
    if (ischar(d)) {		/* only if Datum is char */
	char       *s;

	s = (char *) getheap(2);/* put the string on heap */
	*s = d.u.i;
	s[1] = '\0';
	d.u.s = s;
	d.type = STRING;
    }
    if (!isstr(d))
	error("string needed");
    return d;
}
Esempio n. 10
0
int main()
{
	
	while(1)
	{
		k=M=0;
		while(1)
		{
			scanf("%s", mat[k]);
			if(mat[k][0]=='_') break;
			if(strlen(mat[k])>M)
				M = strlen(mat[k]);
			mat[k][M]=' ';
		}
		
		for(int i=0; i<k; i++)
			for(int j=0; j<M; j++)
				if(mat[i][j]!=' ' && ischar(mat[i][j]) )
		
	}
	
	return 0;
}
Esempio n. 11
0
int
autoboot(int timeout, char *prompt)
{
    time_t	when, otime, ntime;
    int		c, yes;
    char	*argv[2], *cp, *ep;
    char	*kernelname;

    autoboot_tried = 1;

    if (timeout == -1) {
	/* try to get a delay from the environment */
	if ((cp = getenv("autoboot_delay"))) {
	    timeout = strtol(cp, &ep, 0);
	    if (cp == ep)
		timeout = -1;
	}
    }
    if (timeout == -1)		/* all else fails */
	timeout = 10;

    kernelname = getenv("kernelname");
    if (kernelname == NULL) {
	argv[0] = NULL;
	loadakernel(0, 0, argv);
	kernelname = getenv("kernelname");
	if (kernelname == NULL) {
	    command_seterr("no valid kernel found");
	    return(CMD_ERROR);
	}
    }

    otime = time(NULL);
    when = otime + timeout;	/* when to boot */
    yes = 0;

    printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or any other key for command prompt." : prompt);

    for (;;) {
	if (ischar()) {
	    c = getchar();
	    if ((c == '\r') || (c == '\n'))
		yes = 1;
	    break;
	}
	ntime = time(NULL);
	if (ntime >= when) {
	    yes = 1;
	    break;
	}
	
	if (ntime != otime) {
	    printf("\rBooting [%s] in %d second%s... ",
	    		kernelname, (int)(when - ntime),
			(when-ntime)==1?"":"s");
	    otime = ntime;
	}
    }
    if (yes)
	printf("\rBooting [%s]...               ", kernelname);
    putchar('\n');
    if (yes) {
	argv[0] = "boot";
	argv[1] = NULL;
	return(command_boot(1, argv));
    }
    return(CMD_OK);
}
Esempio n. 12
0
//funzione che ritorna il puntatore al primo carattere della stringa s
char * findchar( char *s){
   while( !ischar(*s) && *s!='\0')
      s++;
   return s;
}
Esempio n. 13
0
//funzione che ritorna il puntatore al primo spazio
char * findspace(char *s){
   while(ischar(*s))
      s++;
   return s;
}
Esempio n. 14
0
//ritrona 1 se c è consonante
int iscons(char c){
   return ischar(c)&&!isvocale(c);
}
Esempio n. 15
0
//ritorna 1 se c è una vocale
int isvocale(char c){
   return ischar(c)&&cins(c,"aeiouAEIOU");
}
Esempio n. 16
0
int			ft_isvalid(const char *tab, int len)
{
	if (!issquare(tab, len) || !hasfour(tab) || !ischar(tab) || !doestouch(tab))
		return (0);
	return (1);
}
Esempio n. 17
0
File: type.c Progetto: l0stman/loot
/* Test if the expression is self-evaluating */
int
isself(exp_t *ep)
{
        return ep == NULL || isnum(ep) || isstr(ep) || isbool(ep) || ischar(ep);
}
Esempio n. 18
0
int main()
{
        int fd=open("x.c",O_RDONLY);
        char c;int i=0;
        char buffer[100];
        bzero(buffer,100);
        while( read(fd,&c,1)!=0)
        {
 
                if(c=='#')
                {
                	   if(i!=0)
                        printf(buffer,i);
                         bzero(buffer,100);

                        char c2;char subbuf[100];
                        bzero(subbuf,100);
                        int j=0;
                        subbuf[j++]=c;
                        read(fd,&c2,1);
                      	subbuf[j++]=c2;
                      	
                        while(c2!='\n')
                        {
		                    read(fd,&c2,1);
		                    subbuf[j++]=c2;
                        }
                        subbuf[j-1]='\0';
                        printf("%s Macro\n",subbuf);
                        i=0;
                        continue;

                        
				}
                if(c==',')
                {
                         if(i!=0)
                        print(buffer,i);
                        printf(",       COMMA\n");
                        char c2;
                        read(fd,&c2,1);
                        while(c2=='\t'||c2==' ')
                         {read(fd,&c2,1);}
                        i=0;
                        buffer[i++]=c2;
                        continue;

                }
                if(c==';')
                {
                        if(i!=0)
                        print(buffer,i);
                        printf(";       SEMICOL\n");
                        char c2;
                        read(fd,&c2,1);
                        while(c2=='\t'||c2==' '||c2=='\n')
                         {read(fd,&c2,1);}
                        i=0;
                        buffer[i++]=c2;
                        continue;


                }
                  if(c=='/')
                {
                         if(i!=0)
                        printf(buffer,i);
                         bzero(buffer,100);
						//printf("...........");
                         char c2;char subbuf[100];
                        int j=0;
                        bzero(subbuf,100);
                        subbuf[j++]=c;
                        read(fd,&c2,1);
                        if(c2=='/')
                        {
                                 subbuf[j]=c2;j++;
                         read(fd,&c2,1);subbuf[j]=c2;j++;
                        while(c2!='\n')
                        {

                         read(fd,&c2,1);
                        subbuf[j++]=c2;
                        }
                        printf("%s COMMENT\n",subbuf);
                        i=0;
                        continue;

                        }
                        else if(c2=='*')
                        {
                        	
                        subbuf[j++]=c2;
                        while(!(c2=='/' && subbuf[j-2]=='*'))
                        {

                         read(fd,&c2,1);
                        subbuf[j++]=c2;
                        }
                        printf("%s COMMENT\n",subbuf);
                        i=0;
                        continue;
                        }
                      }
                 if(c=='\"')
                {
                         if(i!=0)
                        printf(buffer,i);
                         bzero(buffer,100);


                         char c2;char subbuf[100];
                         bzero(subbuf,100);
                        int j=0;
                        subbuf[0]=c;
                        j++;
                        read(fd,&c2,1);
                        subbuf[j]=c2;j++;
                        while(c2!='\"')
                        {

                         read(fd,&c2,1);
                        subbuf[j++]=c2;
                        }
                        printf("%s STRING\n",subbuf);
                        i=0;
                        continue;

                }
				 if(c=='['||c==']'||c=='('||c==')'|c=='{'||c=='}')
                {
                        if(i!=0)
                        print(buffer,i);
                        bzero(buffer,100);
                        printf("%c \t special sym\n",c);
                        i=0;
                        continue;
                }
                if(c=='\t'||c==' '||c=='\n')
                {
                     // printf("flushing\n");
                        if(i!=0)
                        print(buffer,i);
                        else
                        continue;
                        bzero(buffer,100);
        //              printf("%s this is buf\n",buffer);
                        char c2;
                        read(fd,&c2,1);
                        while(c2=='\t'||c2==' ')
                  {read(fd,&c2,1);}
                        i=0;
                        c=c2;
        //                printf("%s this is buf\n",buffer);

                        //continue;

                }
               
                if(c=='+'||c=='/'||c=='*'||c=='%'||c=='-')
                {
                        if(i!=0)
                        print(buffer,i);

                          bzero(buffer,100);
                        char lo[2];
                        lo[0]=c;read(fd,&lo[1],1);
                        if(lo[1]=='='||lo[1]==' '||(lo[0]=='+' && lo[1]=='+')||(lo[0]=='+' && lo[1]=='+'))
                        {
                                printf("%s \t Arithmatic OP\n",lo);
                                i=0;
                                continue;
                        }
                        if(isdigit(lo[1])||ischar(lo[1]))
                        {

                                buffer[0]=lo[1];
                                i=1;
                                lo[1]='\0';
                                printf("%s \t Arithmatic OP\n",lo);
                                continue;

                        }


                }
                if(c=='>'||c=='<'||c=='='||c=='!')
                {
                        if(i!=0)
                        print(buffer,i);
                         bzero(buffer,100);

                        char lo[2];
                        lo[0]=c;read(fd,&lo[1],1);
                        if(c=='=' && lo[1]!='=')
                        {
                                 buffer[0]=lo[1];
                                i=1;
                                lo[1]='\0';

                                 printf("%s \t Assignment OP\n",lo);
                                continue;

                        }
                        if(lo[1]=='='||lo[1]==' ')
                        {
                                printf("%s \t Relational OP\n",lo);
                                i=0;
                                continue;
                        }
                        if(isdigit(lo[1])||ischar(lo[1]))
                  {

                                buffer[0]=lo[1];
                                i=1;
                                lo[1]='\0';
                                printf("%s \t Relational OP\n",lo);
                                continue;

                        }

                }

               

                


                buffer[i]=c;
                i++;

        }
}
Esempio n. 19
0
int
autoboot(int timeout, char *prompt)
{
    time_t	when, otime, ntime;
    int		c, yes;
    char	*argv[2], *cp, *ep;
    char	*kernelname;
#ifdef BOOT_PROMPT_123
    const char	*seq = "123", *p = seq;
#endif

    autoboot_tried = 1;

    if (timeout == -1) {
        timeout = 10;
	/* try to get a delay from the environment */
	if ((cp = getenv("autoboot_delay"))) {
	    timeout = strtol(cp, &ep, 0);
	    if (cp == ep)
		timeout = 10;		/* Unparseable? Set default! */
	}
    }

    kernelname = getenv("kernelname");
    if (kernelname == NULL) {
	argv[0] = NULL;
	loadakernel(0, 0, argv);
	kernelname = getenv("kernelname");
	if (kernelname == NULL) {
	    command_errmsg = "no valid kernel found";
	    return(CMD_ERROR);
	}
    }

    if (timeout >= 0) {
        otime = time(NULL);
        when = otime + timeout;	/* when to boot */

        yes = 0;

#ifdef BOOT_PROMPT_123
        printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or "
	    "1 2 3 sequence for command prompt." : prompt);
#else
        printf("%s\n", (prompt == NULL) ? "Hit [Enter] to boot immediately, or any other key for command prompt." : prompt);
#endif

        for (;;) {
	    if (ischar()) {
	        c = getchar();
#ifdef BOOT_PROMPT_123
		if ((c == '\r') || (c == '\n')) {
			yes = 1;
			break;
		} else if (c != *p++)
			p = seq;
		if (*p == 0)
			break;
#else
	        if ((c == '\r') || (c == '\n'))
		    yes = 1;
	        break;
#endif
	    }
	    ntime = time(NULL);
	    if (ntime >= when) {
	        yes = 1;
	        break;
	    }

	    if (ntime != otime) {
	        printf("\rBooting [%s] in %d second%s... ",
	    		    kernelname, (int)(when - ntime),
			    (when-ntime)==1?"":"s");
	        otime = ntime;
	    }
        }
    } else {
        yes = 1;
    }

    if (yes)
	printf("\rBooting [%s]...               ", kernelname);
    putchar('\n');
    if (yes) {
	argv[0] = "boot";
	argv[1] = NULL;
	return(command_boot(1, argv));
    }
    return(CMD_OK);
}
Esempio n. 20
0
File: clamb.c Progetto: irori/clamb
void eval(Cell root)
{
    Cell *bottom = rd_stack.sp;
    PUSH(root);

    for (;;) {
	while (ispair(TOP))
	    PUSH(car(TOP));

	if (TOP == COMB_I && APPLICABLE(1))
	{ /* I x -> x */
	    POP;
	    TOP = cdr(TOP);
	}
	else if (TOP == COMB_S && APPLICABLE(3))
	{ /* S f g x -> f x (g x) */
	    Cell a = alloc(2);
	    SET(a+0, ARG(1), ARG(3));	/* f x */
	    SET(a+1, ARG(2), ARG(3));	/* g x */
	    DROP(3);
	    SET(TOP, a+0, a+1);	/* f x (g x) */
	}
	else if (TOP == COMB_K && APPLICABLE(2))
	{ /* K x y -> I x */
	    Cell x = ARG(1);
	    DROP(2);
	    SET(TOP, COMB_I, x);
	    TOP = cdr(TOP);	/* shortcut reduction of I */
	}
	else if (TOP == COMB_B && APPLICABLE(3))
	{ /* B f g x -> f (g x) */
	    Cell f, gx;
	    gx = pair(ARG(2), ARG(3));
	    f = ARG(1);
	    DROP(3);
	    SET(TOP, f, gx);
	}
	else if (TOP == COMB_C && APPLICABLE(3))
	{ /* C f g x -> f x g */
	    Cell fx, g;
	    fx = pair(ARG(1), ARG(3));
	    g = ARG(2);
	    DROP(3);
	    SET(TOP, fx, g);
	}
	else if (TOP == COMB_SP && APPLICABLE(4))
	{ /* SP c f g x -> c (f x) (g x) */
	    Cell a = alloc(3);
	    SET(a+0, ARG(2), ARG(4));	/* f x */
	    SET(a+1, ARG(3), ARG(4));	/* g x */
	    SET(a+2, ARG(1), a+0);	/* c (f x) */
	    DROP(4);
	    SET(TOP, a+2, a+1);		/* c (f x) (g x) */
	}
	else if (TOP == COMB_BS && APPLICABLE(4))
	{ /* BS c f g x -> c (f (g x)) */
	    Cell a, c;
	    a = alloc(2);
	    SET(a+0, ARG(3), ARG(4));	/* g x */
	    SET(a+1, ARG(2), a+0);	/* f (g x) */
	    c = ARG(1);
	    DROP(4);
	    SET(TOP, c, a+1);		/* c (f (g x)) */
	}
	else if (TOP == COMB_CP && APPLICABLE(4))
	{ /* BS c f g x -> c (f x) g */
	    Cell a, g;
	    a = alloc(2);
	    SET(a+0, ARG(2), ARG(4));	/* f x */
	    SET(a+1, ARG(1), a+0);	/* c (f x) */
	    g = ARG(3);
	    DROP(4);
	    SET(TOP, a+1, g);		/* c (f x) g */
	}
	else if (TOP == COMB_IOTA && APPLICABLE(1))
	{ /* IOTA x -> x S K */
	    Cell xs = pair(ARG(1), COMB_S);
	    POP;
	    SET(TOP, xs, COMB_K);
	}
	else if (TOP == COMB_KI && APPLICABLE(2))
	{ /* KI x y -> I y */
	    DROP(2);
	    car(TOP) = COMB_I;
	}
	else if (TOP == COMB_CONS && APPLICABLE(3))
	{ /* CONS x y f -> f x y */
	    Cell fx, y;
	    fx = pair(ARG(3), ARG(1));
	    y = ARG(2);
	    DROP(3);
	    SET(TOP, fx, y);
	}
	else if (TOP == COMB_READ && APPLICABLE(2))
	{ /* READ NIL f -> CONS CHAR(c) (READ NIL) f
	                -> I KI f */
	    int c = read_char();
	    if (c == EOF) {
		POP;
		SET(TOP, COMB_I, COMB_KI);
	    }
	    else {
		Cell a = alloc(2);
		SET(a+0, COMB_CONS, mkchar(c == EOF ? 256 : c));
		SET(a+1, COMB_READ, NIL);
		POP;
		SET(TOP, a+0, a+1);
	    }
	}
	else if (TOP == COMB_WRITE && APPLICABLE(1))
	{ /* WRITE x -> x PUTC RETURN */
	    POP;
	    Cell a = pair(cdr(TOP), COMB_PUTC);	/* x PUTC */
	    SET(TOP, a, COMB_RETURN);		/* x PUTC RETURN */
	}
	else if (TOP == COMB_PUTC && APPLICABLE(3))
	{ /* PUTC x y i -> putc(eval(x INC NUM(0))); WRITE y */
	    Cell a = alloc(2);
	    SET(a+0, ARG(1), COMB_INC);	/* x INC */
	    SET(a+1, a+0, mkint(0));	/* x INC NUM(0) */
	    DROP(2);
	    eval(a+1);

	    if (!isint(TOP))
		errexit("invalid output format (result was not a number)\n");
	    if (intof(TOP) >= 256)
		errexit("invalid character %d\n", intof(TOP));

	    putchar(intof(TOP));
	    POP;

	    ARG(1) = cdr(TOP);	/* y */
	    POP;
	    car(TOP) = COMB_WRITE;	/* WRITE y */
	}
	else if (TOP == COMB_RETURN)
	    return;
	else if (TOP == COMB_INC && APPLICABLE(1))
	{ /* INC x -> eval(x)+1 */
	    Cell c = ARG(1);
	    POP;
	    eval(c);

	    c = POP;
	    if (!isint(c))
		errexit("invalid output format (attempted to apply inc to a non-number)\n");
	    SET(TOP, COMB_I, mkint(intof(c) + 1));
	}
	else if (ischar(TOP) && APPLICABLE(2)) {
	    int c = charof(TOP);
	    if (c <= 0) {  /* CHAR(0) f z -> z */
		Cell z = ARG(2);
		DROP(2);
		SET(TOP, COMB_I, z);
	    }
	    else {       /* CHAR(n+1) f z -> f (CHAR(n) f z) */
		Cell a = alloc(2);
		Cell f = ARG(1);
		SET(a+0, mkchar(c-1), f);	/* CHAR(n) f */
		SET(a+1, a+0, ARG(2));		/* CHAR(n) f z */
		DROP(2);
		SET(TOP, f, a+1);		/* f (CHAR(n) f z) */
	    }
	}
	else if (isint(TOP) && APPLICABLE(1))
	    errexit("invalid output format (attempted to apply a number)\n");
	else
	    return;
	reductions++;
    }
}
Esempio n. 21
0
 bool isInt(const char *s, int l){
     if (l <= 0) return false;
     for (int i = 0; i<l; i++) if (!ischar(s[i])) return false;
     return true;
 }
Esempio n. 22
0
File: prim.c Progetto: l0stman/loot
/* Test if the argument is a character. */
static exp_t *
prim_ischar(exp_t *args)
{
        chkargs("char?", args, 1);
        return ischar(car(args)) ? true: false;
}