示例#1
0
文件: gui_script.c 项目: c10ud/CHDK
//-------------------------------------------------------------------
// Process one entry "@default VAR VALUE"
//-------------------------------------------------------------------
static const char* get_default(sc_param *p, const char *ptr, int isScript)
{
    ptr = skip_to_token(ptr);
    if (p)
    {
        int type = MENUITEM_INT|MENUITEM_SCRIPT_PARAM;
        int range = 0;
        if (strncmp(ptr, "true", 4) == 0)
        {
            p->val = 1;
            type = MENUITEM_BOOL|MENUITEM_SCRIPT_PARAM;
            range = MENU_MINMAX(1,0);   // Force boolean data type in Lua (ToDo: this is clunky, needs fixing)

        }
        else if (strncmp(ptr, "false", 5) == 0)
        {
            p->val = 0;
            type = MENUITEM_BOOL|MENUITEM_SCRIPT_PARAM;
            range = MENU_MINMAX(1,0);   // Force boolean data type in Lua (ToDo: this is clunky, needs fixing)
        }
        else
        {
            p->val = strtol(ptr, NULL, 0);
        }
        p->old_val = p->val;
        if (isScript)   // Loading from script file (rather than saved param set file)
        {
            p->def_val = p->val;
            p->range = range;
            p->range_type = type;
        }
    }
    return skip_token(ptr);
}
示例#2
0
文件: metrics.cpp 项目: imaxxs/cyton
int *cpu_available_freq_func( void ) {
	char *p;
	static int val[3];

	if ( stat(CPU_FREQ_SCALING_AVAILABLE_FREQ, &struct_stat) == 0 ) {
		if(slurpfile(CPU_FREQ_SCALING_AVAILABLE_FREQ, sys_devices_system_cpu_available, 128)) {
			p = sys_devices_system_cpu_available;
			val[0] = (strtol( p, (char **)NULL , 10 ) / 1000 );
			p = skip_token(p);
			val[1] = (strtol( p, (char **)NULL , 10 ) / 1000 );
			p = skip_token(p);
			val[2] = (strtol( p, (char **)NULL , 10 ) / 1000 );
		}
	}
	return val;
}
示例#3
0
/* same as in ACK */
static int zap_unknown(asm86_t *a)
/* An error, zap the rest of the line. */
{
	token_t *t;
#define MAX_ASTR	4096
	char astr[MAX_ASTR];
	unsigned astr_len = 0;

	astr[astr_len++] = '\t';
	while ((t= get_token(0))->type != T_EOF && t->symbol != ';' 
			&& t->type != T_COMMENT) {
		switch(t->type) {
			case T_CHAR: 
				astr[astr_len++] = t->symbol;
				break;
			case T_WORD:
			case T_STRING:
				strncpy(astr + astr_len, t->name, t->len);
				astr_len += t->len;
				break;

		}
		skip_token(1);
	}
	astr[astr_len++] = '\0';
	
	a->raw_string = malloc(astr_len);
	if (!a->raw_string)
		return -1;

	strcpy(a->raw_string, astr);

	return 0;
}
示例#4
0
文件: scas.c 项目: thentenaar/sctools
static int parse_meta_handed(const char *p)
{
	char *t;
	int meta;
	int ret = 0;
	if (!p) goto ret;

	while (*p) {
		t = get_token(p);
		if (t) {
			meta = lookup_meta_token(t);
			free(t);
		} else meta = INVALID_NUMBER;

		if (meta == INVALID_NUMBER /*|| !is_meta_handed(meta)*/) {
			ret = INVALID_NUMBER;
			break;
		}

		ret |= meta;
		p = skip_token(p);
	}

ret:
	return ret;
}
示例#5
0
static unsigned long
read_boot_time(glibtop *server)
{
	char* line = NULL;
	size_t size = 0;
	FILE* stat;
	unsigned long btime = 0;

	if (!(stat = fopen("/proc/stat", "r"))) {
		glibtop_error_io_r(server, "fopen(\"/proc/stat\")");
		goto out;
	}

	while (getline(&line, &size, stat) != -1) {
		if (!strncmp(line, "btime", 5)) {
			btime = strtoul(skip_token(line), NULL, 10);
			break;
		}
	}

	free(line);
	fclose(stat);
out:
	return btime;
}
示例#6
0
/*
 * A helper function to return the total number of cpu jiffies
 */
JT
total_jiffies_func ( void )
{
   char *p;
   JT user_jiffies, nice_jiffies, system_jiffies, idle_jiffies,
                 wio_jiffies, irq_jiffies, sirq_jiffies;

   p = update_file(&proc_stat);
   p = skip_token(p);
   p = skip_whitespace(p);
   user_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   nice_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   system_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   idle_jiffies = strtod( p, &p );

   if(num_cpustates == NUM_CPUSTATES_24X)
     return user_jiffies + nice_jiffies + system_jiffies + idle_jiffies;

   p = skip_whitespace(p);
   wio_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   irq_jiffies = strtod( p, &p );
   p = skip_whitespace(p);
   sirq_jiffies = strtod( p, &p );

   return user_jiffies + nice_jiffies + system_jiffies + idle_jiffies +
          wio_jiffies + irq_jiffies + sirq_jiffies;
}
示例#7
0
parse_size(device *current,
	   device *bus,
	   const char *chp,
	   device_unit *size)
{
  int i;
  int nr;
  const char *curr = chp;
  memset(size, 0, sizeof(*size));
  /* parse the numeric list */
  size->nr_cells = device_nr_size_cells(bus);
  nr = 0;
  ASSERT(size->nr_cells > 0);
  while (1) {
    char *next;
    size->cells[nr] = strtoul(curr, &next, 0);
    if (curr == next)
      device_error(current, "Problem parsing <size> %s", chp);
    nr += 1;
    if (next[0] != ',')
      break;
    if (nr == size->nr_cells)
      device_error(current, "Too many values in <size> %s", chp);
    curr = next + 1;
  }
  ASSERT(nr > 0 && nr <= size->nr_cells);
  /* right align the numbers */
  for (i = 1; i <= size->nr_cells; i++) {
    if (i <= nr)
      size->cells[size->nr_cells - i] = size->cells[nr - i];
    else
      size->cells[size->nr_cells - i] = 0;
  }
  return skip_token(chp);
}
示例#8
0
void get_cpu (dbgov_cpu * buf)
{
  char buffer[BUFSIZ], *p;

  memset (buf, 0, sizeof (dbgov_cpu));

  int res = try_file_to_buffer (buffer, FILENAME);
  if (res == TRY_FILE_TO_BUFFER_OK_IOSTAT)
    {
      p = skip_token (buffer);
      buf->user = strtoull (p, &p, 0);
      buf->nice = strtoull (p, &p, 0);
      buf->sys = strtoull (p, &p, 0);
      buf->idle = strtoull (p, &p, 0);
      buf->total = buf->user + buf->nice + buf->sys + buf->idle;

      /* 2.6 kernel */
      if (os_version_code >= LINUX_VERSION_CODE (2, 6, 0))
	{
	  buf->iowait = strtoull (p, &p, 0);
	  buf->irq = strtoull (p, &p, 0);
	  buf->softirq = strtoull (p, &p, 0);

	  buf->total += buf->iowait + buf->irq + buf->softirq;
	}

      buf->frequency = 100;
    }
}
示例#9
0
文件: scas.c 项目: thentenaar/sctools
static int parse_multi_set(const char *p)
{
	char *t;
	int s, val = 0;

	while (p && *p) {
		t = get_token(p);
		if (t) {
			s = lookup_set_token(t);
			free(t);

			if (s == INVALID_NUMBER) {
				val = s;
				break;
			}

			if (s) val |= 1 << (s - 1);
			else   val = 0;
		}

		p = skip_token(p);
	}

	return val;
}
示例#10
0
g_val_t
cpu_user_func ( void )
{
   char *p;
   static g_val_t val;
   static struct timeval stamp={0, 0};
   static JT last_user_jiffies,  user_jiffies, 
             last_total_jiffies, total_jiffies, diff;

   p = update_file(&proc_stat);
   if((proc_stat.last_read.tv_sec != stamp.tv_sec) &&
      (proc_stat.last_read.tv_usec != stamp.tv_usec)) {
     stamp = proc_stat.last_read;

     p = skip_token(p);
     user_jiffies  = strtod( p , (char **)NULL );
     total_jiffies = total_jiffies_func();

     diff = user_jiffies - last_user_jiffies;

     if ( diff )
       val.f = ((double)diff/(double)(total_jiffies - last_total_jiffies)) * 100.0;
     else
       val.f = 0.0;

     last_user_jiffies  = user_jiffies;
     last_total_jiffies = total_jiffies;

   }
   return val;
}
示例#11
0
g_val_t
cpu_user_func ( void )
{
   char *p;
   static g_val_t val;
   static int stamp;
   static double last_user_jiffies,  user_jiffies, 
                 last_total_jiffies, total_jiffies, diff;
   
   p = update_file(&proc_stat);
   if(proc_stat.last_read != stamp) {
     stamp = proc_stat.last_read;
     
     p = skip_token(p);
     user_jiffies  = strtod( p , (char **)NULL );
     total_jiffies = total_jiffies_func();
     
     diff = user_jiffies - last_user_jiffies; 
     
     if ( diff )
       val.f = (diff/(total_jiffies - last_total_jiffies))*100;
     else
       val.f = 0.0;
     
     last_user_jiffies  = user_jiffies;
     last_total_jiffies = total_jiffies;
     
   }
   return val;
}
示例#12
0
/* read_config_read_data():
   reads data of a given type from a token(s) on a configuration line.

   Returns: character pointer to the next token in the configuration line.
            NULL if none left.
            NULL if an unknown type.
*/
char *read_config_read_data(int type, char *readfrom, void *dataptr, size_t *len) {

  int *intp;
  char **charpp;
  oid  **oidpp;

  if (dataptr == NULL || readfrom == NULL)
    return NULL;
  
  switch(type) {
    case ASN_INTEGER:
      intp = (int *) dataptr;
      *intp = atoi(readfrom);
      readfrom = skip_token(readfrom);
      return readfrom;
      
    case ASN_OCTET_STR:
      charpp = (char **) dataptr;
      return read_config_read_octet_string(readfrom, (u_char **) charpp, len);

    case ASN_OBJECT_ID:
      oidpp = (oid **) dataptr;
      return read_config_read_objid(readfrom, oidpp, len);

    default:
      DEBUGMSGTL(("read_config_read_data","Fail: Unknown type: %d", type));
      return NULL;
  }
  return NULL;
}
示例#13
0
文件: start.c 项目: rosedu/anjuta
static void
attach_process_add_line (AttachProcess *ap, GtkTreeStore *store, gchar *line)
{
	gchar *pid, *user, *start, *command, *tmp;
	// guint i, level;
	GtkTreeIter *iter;

	pid = skip_spaces (line); // skip leading spaces
	user = skip_token_and_spaces (pid); // skip PID
	start = skip_token_and_spaces (user); // skip USER
	tmp = skip_token (start); // skip START (do not skip spaces)

	command = calc_depth_and_get_iter (ap, store, &iter, tmp);

	if (ap->hide_paths)
	{
		command = skip_path (command);
	}

	if (ap->hide_params)
	{
		remove_params(command);
	}

	gtk_tree_store_set (store, iter,
						PID_COLUMN, pid,
						USER_COLUMN, user,
						START_COLUMN, start,
						COMMAND_COLUMN, command,
						-1);
}
示例#14
0
static inline char *
skip_multiple_token (const char *p, size_t count)
{
	while(count--)
		p = skip_token (p);

	return (char *)p;
}
示例#15
0
static void zap(void)
/* An error, zap the rest of the line. */
{
	token_t *t;

	while ((t= get_token(0))->type != T_EOF && t->symbol != ';')
		skip_token(1);
}
示例#16
0
static inline size_t get_token_len( char* tok )
{
    char* start = tok;

    skip_token( tok );

    return size_t( tok - start );
}
示例#17
0
文件: bookmark.c 项目: richq/rockbox
/* ----------------------------------------------------------------------- */
static bool parse_bookmark(const char *bookmark, const bool parse_filenames)
{
    const char* s = bookmark;
    const char* end;
    
#define GET_INT_TOKEN(var)  s = int_token(s, &var)
#define GET_LONG_TOKEN(var)  s = long_token(s, &var)
#define GET_BOOL_TOKEN(var) var = (atoi(s)!=0); s = skip_token(s)
    
    /* if new format bookmark, extract the optional content flags,
       otherwise treat as an original format bookmark */
    int opt_flags = 0;
    bool new_format = (strchr(s, '>') == s);
    if (new_format)
    {
        s++;
        GET_INT_TOKEN(opt_flags);
    }
    
    /* extract all original bookmark tokens */
    GET_INT_TOKEN(bm.resume_index);
    GET_LONG_TOKEN(bm.resume_offset);
    GET_INT_TOKEN(bm.resume_seed);
    if (!new_format)    /* skip deprecated token */
        s = skip_token(s);
    GET_LONG_TOKEN(bm.resume_time);
    GET_INT_TOKEN(bm.repeat_mode);
    GET_BOOL_TOKEN(bm.shuffle);
    
    /* extract all optional bookmark tokens */
    if (opt_flags & BM_PITCH)
        GET_INT_TOKEN(bm.pitch);
    if (opt_flags & BM_SPEED)
        GET_INT_TOKEN(bm.speed);
    
    if (*s == 0)
    {
        return false;
    }
    
    end = strchr(s, ';');

    /* extract file names */
    if (parse_filenames)
    {
        size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s);
        len = MIN(TEMP_BUF_SIZE - 1, len);
        strlcpy(global_temp_buffer, s, len + 1);
        
        if (end != NULL)
        {
            end++;
            strlcpy(global_filename, end, MAX_PATH);
        }
     }
    
    return true;
}
示例#18
0
文件: metrics.cpp 项目: imaxxs/cyton
double cpu_system_func ( void ) {
	char *p;
	double val;
	double last_system_jiffies,  system_jiffies,
                 last_total_jiffies, total_jiffies, diff;
 
	p = update_file(&proc_stat);
	p = skip_token(p);
	p = skip_token(p);
	p = skip_token(p);
	system_jiffies = strtod( p , (char **)NULL );
	if (num_cpustates > NUM_CPUSTATES_24X) {
		p = skip_token(p);
		p = skip_token(p);
		p = skip_token(p);
		system_jiffies += strtod( p , (char **)NULL ); /* "intr" counted in system */
		p = skip_token(p);
		system_jiffies += strtod( p , (char **)NULL ); /* "sintr" counted in system */
	}
	total_jiffies  = total_jiffies_func();

	diff = system_jiffies  - last_system_jiffies;

	if ( diff )
	val = (diff/(total_jiffies - last_total_jiffies))*100;
	else
	val = 0.0;

	last_system_jiffies  = system_jiffies;
	last_total_jiffies = total_jiffies;   

	return val;
}
示例#19
0
inline static bool is_function( char* cur, bool& isAMacro )
{
    isAMacro = false;

    int tmpLnNo;
    store_line_no( tmpLnNo );

    // NOTE:: comments and quoted strings are not checked here

    // first,check for "single-line hanginging macros" like:
    // ___UNICODE
    //

    char* eol = cur;
    skip_to_eol( eol );

    skip_token( cur );
    get_next_token( cur );

    if ( cur > eol )
    {
        isAMacro = true;
        restore_line_no( tmpLnNo );

        return true;
    }

    // it's not a macro, go to the begining of arg. list

    do
    {
        // if bracket found, it's a function or a begining
        // of some macro
        if ( *cur == '(' )
        {
            restore_line_no( tmpLnNo );
            return true;
        }

        // end of statement found without any brackets in it
        // - it cannot be a function

        if ( *cur == ';' )
        {
            restore_line_no( tmpLnNo );
            return false;
        }

        ++cur;

    } while( cur < _gSrcEnd);

    isAMacro = 1;
    restore_line_no( tmpLnNo );

    return false;
}
示例#20
0
g_val_t
proc_total_func ( void )
{
   char *p;
   g_val_t val;

   p = update_file(&proc_loadavg);
   p = skip_token(p);
   p = skip_token(p);
   p = skip_token(p);
   p = skip_whitespace(p);
   while ( isdigit(*p) )
      p++;
   p++;  /* skip the slash-/ */
   val.uint32 = strtol( p, (char **)NULL, 10 );

   return val;
}
示例#21
0
文件: gui_script.c 项目: c10ud/CHDK
// Extract next token into buffer supplied (up to maxlen)
const char* get_token(const char *p, char *buf, int maxlen)
{
    p = skip_whitespace(p);
    int l = skip_token(p) - p;
    int n = (l <= maxlen) ? l : maxlen;
    strncpy(buf, p, n);
    buf[n] = 0;
    return p + l;
}
示例#22
0
// returns 0, if end of source reached
static inline bool skip_imp_block( char*& cur )
{
    while( *cur != '{' && cur < _gSrcEnd )
    {
        skip_token( cur );
        if ( !get_next_token( cur ) ) return false;
    }

    while( *cur != '}' && cur < _gSrcEnd )
    {
        skip_token( cur );
        if ( !get_next_token( cur ) ) return false;
    }

    ++cur;

    return true;
}
示例#23
0
文件: expr.c 项目: thewhoo/ifj15
void generate_internal_function(TVariable *ret_var, Tins_list *act_ins_list)
{
	TList_item *actual_ins;
	int ins_type;
	TVariable *var_1;
	TVariable *var_2;
	TVariable *var_3;

	token = get_token();
	ins_type = operator_2_ins_type(token);
	skip_token(TOKEN_LROUND_BRACKET);
	switch (ins_type) {
		case INS_LENGTH:
		case INS_SORT:
			var_1 = get_next_para(TYPE_STRING);
			actual_ins = create_ins(ins_type, ret_var, var_1, NULL);
			list_insert(act_ins_list, actual_ins);
			break;
		case INS_CONCAT:
		case INS_FIND:
			var_1 = get_next_para(TYPE_STRING);
			skip_token(TOKEN_COMMA);
			var_2 = get_next_para(TYPE_STRING);
			actual_ins = create_ins(ins_type, ret_var, var_1, var_2);
			list_insert(act_ins_list, actual_ins);
			break;
		case INS_SUBSTR:
			var_1 = get_next_para(TYPE_STRING);
			skip_token(TOKEN_COMMA);
			var_2 = get_next_para(TYPE_INT);
			skip_token(TOKEN_COMMA);
			var_3 = get_next_para(TYPE_INT);
			actual_ins = create_ins(INS_PUSH_PARAM, var_1, NULL, NULL);
			list_insert(act_ins_list, actual_ins);
			actual_ins = create_ins(INS_PUSH_PARAM, var_2, NULL, NULL);
			list_insert(act_ins_list, actual_ins);
			actual_ins = create_ins(INS_PUSH_PARAM, var_3, NULL, NULL);
			list_insert(act_ins_list, actual_ins);
			actual_ins = create_ins(ins_type, ret_var, NULL, NULL); /* SUBSTR with ASSIGN params */
			list_insert(act_ins_list, actual_ins);
	}
	skip_token(TOKEN_RROUND_BRACKET);
}
示例#24
0
g_val_t
proc_run_func( void )
{
   char *p;
   g_val_t val;

   p = update_file(&proc_loadavg);
   p = skip_token(p);
   p = skip_token(p);
   p = skip_token(p);
   val.uint32 = strtol( p, (char **)NULL, 10 );

   val.uint32--;
   /* This shouldn't happen.. but it might */
   if (val.uint32 <0)
      val.uint32 = 0;

   return val;
}
示例#25
0
g_val_t
cpu_aidle_func ( void )
{
   char *p;
   g_val_t val;
   JT idle_jiffies, total_jiffies;

   p = update_file(&proc_stat);

   p = skip_token(p);
   p = skip_token(p);
   p = skip_token(p);
   p = skip_token(p);
   idle_jiffies  = (JT) strtod( p , (char **)NULL );
   total_jiffies = total_jiffies_func();

   val.f = ((double)(idle_jiffies/total_jiffies)) * 100.0;
   return val;
}
示例#26
0
文件: gui_script.c 项目: c10ud/CHDK
//-------------------------------------------------------------------
// Process one entry "@values VAR A B C D ..."
//-------------------------------------------------------------------
static const char* get_values(sc_param *p, const char *ptr, char end)
{
    ptr = skip_whitespace(ptr);
    int len = skip_tochar(ptr, end) - ptr;

    if (p)
    {
        p->range = 0;
        p->range_type = MENUITEM_ENUM2|MENUITEM_SCRIPT_PARAM;

        p->option_buf = malloc(len+1);
        strncpy(p->option_buf, ptr, len);
        p->option_buf[len] = 0;

        const char *s = p->option_buf;
        int cnt = 0;
        while (*s)
        {
            s = skip_whitespace(skip_token(s));
            cnt++;
        }
        p->option_count = cnt;
        p->options = malloc(cnt * sizeof(char*));

        s = p->option_buf;
        cnt = 0;
        while (*s)
        {
            p->options[cnt] = s;
            s = skip_token(s);
            if (*s)
            {
                *((char*)s) = 0;
                s = skip_whitespace(s+1);
            }
            cnt++;
        }
    }

    ptr += len;
    if (end && (*ptr == end)) ptr++;
    return ptr;
}
示例#27
0
parse_address(device *current,
	      device *bus,
	      const char *chp,
	      device_unit *address)
{
  ASSERT(device_nr_address_cells(bus) > 0);
  if (device_decode_unit(bus, chp, address) < 0)
    device_error(current, "invalid unit address in %s", chp);
  return skip_token(chp);
}
示例#28
0
static const char *
parse_address (struct hw *current,
	       struct hw *bus,
	       const char *chp,
	       hw_unit *address)
{
  if (hw_unit_decode (bus, chp, address) < 0)
    hw_abort (current, "invalid unit address in %s", chp);
  return skip_token (chp);
}
示例#29
0
g_val_t
cpu_wio_func ( void )
{
   char *p;
   static g_val_t val;
   static struct timeval stamp={0, 0};
   static JT last_wio_jiffies,  wio_jiffies,
             last_total_jiffies, total_jiffies, diff;

   if (num_cpustates == NUM_CPUSTATES_24X) {
     val.f = 0.0;
     return val;
     }

   p = update_file(&proc_stat);
   if((proc_stat.last_read.tv_sec != stamp.tv_sec) &&
      (proc_stat.last_read.tv_usec != stamp.tv_usec)) {
     stamp = proc_stat.last_read;

     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     p = skip_token(p);
     wio_jiffies  = strtod( p , (char **)NULL );
     total_jiffies = total_jiffies_func();

     diff = wio_jiffies - last_wio_jiffies;

     if ( diff )
       val.f = ((double)diff/(double)(total_jiffies - last_total_jiffies)) * 100.0;
     else
       val.f = 0.0;

     val.f = sanityCheck( __LINE__, __FILE__, __FUNCTION__, val.f, (double)diff, (double)(total_jiffies - last_total_jiffies), wio_jiffies, last_wio_jiffies, total_jiffies, last_total_jiffies );

     last_wio_jiffies  = wio_jiffies;
     last_total_jiffies = total_jiffies;

   }

   return val;
}
示例#30
0
文件: metrics.cpp 项目: imaxxs/cyton
double load_five_func ( void ) {
	char *p;
	double val;

	p = update_file(&proc_loadavg);
	p = skip_token(p);
	val = strtod( p, (char **)NULL);

	return val;
}