示例#1
0
文件: yeti_math.c 项目: emmt/Yeti
void Y_arc(int nArgs)
{
  Operand op;
  int promoteID;
  long number, i;
  if (nArgs != 1) YError("arc takes exactly one argument");
  if (! sp->ops) YError("unexpected keyword");
  sp->ops->FormOperand(sp, &op);
  promoteID = op.ops->promoteID;
  if (promoteID == T_DOUBLE) {
    const double rad = TWO_PI;
    const double scl = ONE_OVER_TWO_PI;
    double *x, *y;
    x = op.value;
    y = build_result(&op, &doubleStruct);
    number = op.type.number;
    for (i=0 ; i<number ; ++i) y[i] = x[i] - rad*round(scl*x[i]);
    pop_to_d(sp - 2);
  } else if (promoteID <= T_FLOAT) {
    const float rad = JOIN(TWO_PI,F);
    const float scl = JOIN(ONE_OVER_TWO_PI,F);
    float *x, *y;
    if (promoteID != T_FLOAT) op.ops->ToFloat(&op);
    x = op.value;
    y = build_result(&op, &floatStruct);
    number = op.type.number;
    for (i=0 ; i<number ; ++i) y[i] = x[i] - rad*roundf(scl*x[i]);
    PopTo(sp - 2);
  } else {
    YError("expecting non-complex numeric argument");
  }
  Drop(1);
}
示例#2
0
int		check_rest(t_get *get, char **rest, char **line)
{
	size_t	i;
	char	*tmp;

	i = -1;
	get->ret = 1;
	while (*rest && ++i < LEN(*rest))
	{
		if ((*rest)[i] == '\n')
		{
			if (i == 0 && *line && LEN(*line) == 0)
				manage_line(0, line, rest, i);
			else
				manage_line(1, line, rest, i);
			return (1);
		}
	}
	tmp = *line;
	*line = JOIN(*line, *rest);
	if (*line == NULL)
		*line = SDUP(*rest);
	REMOVE(&tmp);
	REMOVE(rest);
	return (0);
}
示例#3
0
void f()
{
  int i=0;
  JOIN(tid);
  while(1){
    printf("tid :%d in f: %d\n",getID(),i++);
    usleep(90000);
  }
}
示例#4
0
文件: ren2.c 项目: YoshinoAkira/prog
int main(void){
	int one = 1;
	int two = 2;
	int onetwo = 3;

	printf("%d\n",JOIN(one,two));

	return 0;
}
示例#5
0
文件: main.c 项目: jmontija/minishell
int		stock_env(t_group *grp, char **env)
{
	int		i;
	char	*pwd;
	char	*old_pwd;
	char	buf[512];

	pwd = JOIN("PWD=", getcwd(buf, 512));
	insert_env(grp, pwd);
	old_pwd = JOIN("OLDPWD=", ft_getenv(grp, "PWD"));
	insert_env(grp, old_pwd);
	insert_env(grp, "SHLVL=1");
	i = -1;
	while (env[++i] != NULL)
		insert_env(grp, env[i]);
	insert_env(grp, "_=/usr/bin/env");
	return (1);
}
示例#6
0
文件: main.c 项目: jmontija/minishell
void	shlvl(t_group *grp)
{
	char	*shlvl;
	int		lvl;

	lvl = ft_atoi(ft_getenv(grp, "SHLVL"));
	lvl++;
	shlvl = ft_itoa(lvl);
	shlvl = JOIN("SHLVL=", shlvl);
	insert_env(grp, shlvl);
}
示例#7
0
void f()
{
  int i=0;
	int flag = 0;
  JOIN(tid);
	int result; 
  while(1){
    
	if(!flag)
	{
	result = *( int * ) GetThreadResult(tid);
	flag =1;
	}
	printf("tid :%d in f: %d and result is %d\n",getID(),i++,result);
    usleep(90000);
  }
}
示例#8
0
void	manage_line(int is_join, char **line, char **rest, size_t i)
{
	char *old_line;
	char *eol;

	if (is_join)
	{
		old_line = *line;
		eol = SUB(*rest, 0, i);
		*line = JOIN(*line, eol);
		REMOVE(&old_line);
		REMOVE(&eol);
	}
	else
		*line = SDUP("");
	manage_rest(rest, i);
}
示例#9
0
void	ft_read(t_get *get, char **rest, char **line)
{
	char *buf;

	buf = NEW(BUFF_SIZE);
	if (buf == NULL)
	{
		get->ret = -1;
		return ;
	}
	while ((get->ret = read(get->fd, buf, BUFF_SIZE)))
	{
		buf[get->ret] = '\0';
		*rest = JOIN(*rest, buf);
		if (*rest == NULL)
			*rest = SDUP(buf);
		if ((get->ret < 0) || check_rest(get, rest, line))
			break ;
	}
	REMOVE(&buf);
}
示例#10
0
  /* Skip header. */
  getline(&line_buf, &line_buf_size, file);

  unsigned long long mem_used = 0, segs_used = 0;

  while (getline(&line_buf, &line_buf_size, file) >= 0) {
    unsigned long long seg_size = 0;
    if (sscanf(line_buf, "%*d %*d %*o %llu", &seg_size) < 1)
      continue;

    mem_used += seg_size;
    segs_used++;
  }

  stats_set(stats, "mem_used", mem_used);
  stats_set(stats, "segs_used", segs_used);

 out:
  free(line_buf);
  if (file != NULL)
    fclose(file);
}

struct stats_type sysv_shm_stats_type = {
  .st_name = "sysv_shm",
  .st_collect = &collect_sysv_shm,
#define X SCHEMA_DEF
  .st_schema_def = JOIN(KEYS),
#undef X
};
示例#11
0
Elem & Machine::execute(std::ostream &out)
{
    Instruction *command;
    std::shared_ptr<Elem> command_ptr;

    Elem *ADD(new Instruction("ADD"));
    Elem *MUL(new Instruction("MUL"));
    Elem *SUB(new Instruction("SUB"));
    Elem *DIV(new Instruction("DIV"));
    Elem *REM(new Instruction("REM"));
    Elem *EQ(new Instruction("EQ"));
    Elem *LEQ(new Instruction("LEQ"));
    Elem *SEL(new Instruction("SEL"));
    Elem *LD(new Instruction("LD"));
    Elem *LDC(new Instruction("LDC"));
    Elem *LDF(new Instruction("LDF"));
    Elem *CAR(new Instruction("CAR"));
    Elem *CDR(new Instruction("CDR"));
    Elem *CONS(new Instruction("CONS"));
    Elem *NIL(new Instruction("NIL"));
    Elem *DUM(new Instruction("DUM"));
    Elem *AP(new Instruction("AP"));
    Elem *RAP(new Instruction("RAP"));
    Elem *RTN(new Instruction("RTN"));
    Elem *JOIN(new Instruction("JOIN"));
    Elem *STOP(new Instruction("STOP"));

    while (!C->empty())
    {
        if (out != 0x0)
        {
            print_S(out);
            print_E(out);
            print_C(out);
            out << std::endl;
        }

        command_ptr = C->pop_ret();
        command = dynamic_cast<Instruction*>(&*command_ptr);
        if (command == nullptr) throw Exception("Execute", "FatalError");

        if (*command == *ADD)       this->ADD();
        else if (*command == *MUL)  this->MUL();
        else if (*command == *SUB)  this->SUB();
        else if (*command == *DIV)  this->DIV();
        else if (*command == *REM)  this->REM();
        else if (*command == *EQ)   this->EQ();
        else if (*command == *LEQ)  this->LEQ();
        else if (*command == *SEL)  this->SEL();
        else if (*command == *LD)   this->LD();
        else if (*command == *LDC)  this->LDC();
        else if (*command == *LDF)  this->LDF();
        else if (*command == *CAR)  this->CAR();
        else if (*command == *CDR)  this->CDR();
        else if (*command == *CONS) this->CONS();
        else if (*command == *NIL)  this->NIL();
        else if (*command == *DUM)  this->DUM();
        else if (*command == *AP)   this->AP();
        else if (*command == *RAP)  this->RAP();
        else if (*command == *RTN)  this->RTN();
        else if (*command == *JOIN)  this->JOIN();
        else if (*command == *STOP) { return (*(this->STOP()));}
        else throw Exception("Execute", "Expected 'instruction' but greeted constant.");
    }

    throw Exception("Execute", "FatalError");
}
示例#12
0
文件: irq.c 项目: charngda/tacc_stats
static void collect_irq_stats( struct stats_type *type, const char *path ) {
    FILE *file = NULL;
    char *line = NULL;
    size_t line_size = 0;

    file = fopen( path, "r" );
    if ( file == NULL ) {
        //ERROR( "cannot open `%s': %m\n", path );
        goto out;
    }

    while ( 0 <= getline( &line, &line_size, file ) ) {
        char *rest = line;
        char *key = wsep( &rest );
        if ( key == NULL || rest == NULL )
            continue;

        if ( ! strncasecmp( key, "cpu0", 4 ) )
            continue;
#define X(k,r...) k = 0
        unsigned long long KEYS;
#undef X
        if ( 0 <    sscanf( rest,
#define X(k,r...) " %llu"
                            JOIN( KEYS )
#undef X
#define X(k,r...) &k
                            , KEYS ) ) {
#undef X
            /* remove the colon */
            char *t = key;
            do {
                if ( ':' == *t )
                    *t = '\0';
            }
            while ( *t++ );

            /* check if the key is a number of not */
            strtoul( key, &t, 10 );
            if ( '\0' == *t ) {
                /* so the key is a number, e.g. like the following
                             CPU0       CPU1       CPU2       CPU3
                	0:        198          1          0          0   IO-APIC-edge      timer
                	1:          0          2          2          3   IO-APIC-edge      i8042
                	4:          0          0          4          0   IO-APIC-edge      serial
                	6:          0          0          1          1   IO-APIC-edge      floppy
                	8:          0          0          1          0   IO-APIC-edge      rtc0
                	...
                */
                /* get the real device name from the last column(s) */
                /* An x86 IRQ description is of form "%s-%s %s" where the first
                   %s is from the "name" field, e.g. in arch/x86/kernel/apic/io_apic.c :

                   static struct irq_chip ioapic_chip __read_mostly = {
                           .name                   = "IO-APIC",
                           .irq_startup            = startup_ioapic_irq,
                           .irq_mask               = mask_ioapic_irq,
                           .irq_unmask             = unmask_ioapic_irq,
                           .irq_ack                = ack_apic_edge,
                           .irq_eoi                = ack_apic_level,
                   #ifdef CONFIG_SMP
                           .irq_set_affinity       = ioapic_set_affinity,
                   #endif
                           .irq_retrigger          = ioapic_retrigger_irq,
                   };
                */
                /* ignore interrupts from certain devices, e.g. keyboard, floppy, USB, etc */
                if ( strstr( rest, " i8042" ) || strstr( rest, " floppy" ) || strstr( rest, ":usb" ) || strstr( rest, " serial" ) ) continue;
                size_t s = strspn( rest, "0123456789: \t\n\r" );
                if ( '\0' == rest[s] ) continue; /* there is no last column; move on */
                rest += s;
                wsep( &rest );
                if ( NULL == rest ) continue;
                s = strspn( rest, " \t\n\r" );
                if ( '\0' == rest[s] ) continue;
                /* replace every space with underscore */
                t = key = rest + s;
                do {
                    if ( '\r' == *t || '\n' == *t ) *t = '\0';
                    if ( isspace( *t ) ) *t = '_';
                }
                while ( *t++ );
            }

            struct stats *stats = get_current_stats( type, key );
            if ( NULL ==  stats ) break;
#define X(k,r...) stats_set(stats, #k, k)
            KEYS;
#undef X
        }
    }

out:
    if ( NULL != line )
        free( line );
    if ( NULL != file )
        fclose( file );

}