Example #1
0
File: mysql3.c Project: llxp/llxp
/* Daten mit mysql_real_query() in die Datenbank schreiben */
void filmdaten_anfuegen(void) {
   char titel[255], hauptrolle[255], temp[6];
   unsigned int fsk, gedreht;
   int i,  size=0;
   char *str[9], *query;
   char *ptr;

   printf("\n\nFilmtitel  : ");
   fgets(titel, 254, stdin);
   if( (ptr = strchr(titel, '\n')) != NULL)
      *ptr = '\0';  /* newline durch \0 ersetzen */

   printf("Hauptrolle : ");
   fgets(hauptrolle, 254, stdin);
   if( (ptr = strchr(hauptrolle, '\n')) != NULL)
      *ptr = '\0';  /* newline durch \0 ersetzen */

   printf("FSK        : ");
   fgets(temp, 4, stdin);
   if( (ptr = strchr(temp, '\n')) != NULL)
      *ptr = '\0';  /* newline durch \0 ersetzen */
   sscanf(temp, "%u", &fsk);

   printf("Gedreht    : ");
   fgets(temp, 5, stdin);
   if( (ptr = strchr(temp, '\n')) != NULL)
      *ptr = '\0';  /* newline durch \0 ersetzen */
   sscanf(temp, "%u", &gedreht);

   /* jetzt wird der Anfragestring erstellt */
   str[0]= "INSERT INTO filmdaten (titel, hauptrolle, fsk, "
            "gedreht) VALUES ('";
   str[1] = malloc(strlen(titel)+1);
   strcpy(str[1], titel);
   str[2] = "','";
   str[3] = malloc(strlen(hauptrolle)+1);
   strcpy(str[3], hauptrolle);
   str[4] = "',";
   str[5] = malloc(3);
   sprintf(str[5], "%2u", fsk);
   str[6] = ",";
   str[7] = malloc(5);
   sprintf(str[7], "%4u", gedreht);
   str[8] = ")";

   for (i=0; i < 9; i++)
      size+=strlen(str[i]);
   /* Speicherplatz für den Anfragestring reservieren */
   query = malloc(size + 1);
   strcpy(query, str[0]);
   for(i = 1; i < 9; i++)
      strcat(query, str[i]);
   /* zum Testen für die Konsole  */
   /* printf("%s",query);         */

   /* jetzt die Anfrage an den Datenbankserver */
   mysql_real_query(mysql, query, strlen(query));
   check_error();
   free(query);
}
Example #2
0
Object
range(DCEparsestate* state, Object sfirst, Object sstride, Object slast)
{
    DCEslice* slice = (DCEslice*)dcecreate(CES_SLICE);
    unsigned long first=0,stride=0,last=0;

    /* Note: that incoming arguments are strings; we must convert to size_t;
       but we do know they are legal integers or NULL */
    sscanf((char*)sfirst,"%lu",&first); /* always defined */
    if(slast != NULL)
        sscanf((char*)slast,"%lu",&last);
    else
	last = first;
    if(sstride != NULL)
        sscanf((char*)sstride,"%lu",&stride);
    else
	stride = 1; /* default */

    if(stride == 0)
    	dceerror(state,"Illegal index for range stride");
    if(last < first)
	dceerror(state,"Illegal index for range last index");
    slice->first  = first;
    slice->stride = (stride == 0 ? 1 : stride);
    slice->last   = last;
    slice->length  = (slice->last - slice->first) + 1;
    slice->count  = slice->length / slice->stride;
#ifdef DEBUG
fprintf(stderr,"	ce.slice: %s\n",
	dumpslice(slice));
#endif
    return slice;
}
Example #3
0
void getNextPlay(int stream, play_t *play, deck_t *deck) {
  static char buffer[MAXLINE];
  static char cmd[MAXLINE];
  static char from[MAXLINE];
  static char onto[MAXLINE];
  read(stream,buffer,MAXLINE);
  sscanf(buffer,"%s",cmd);
  if (cmd[0] == 'm') {
    // it's a move onto a lain stack
    sscanf(buffer,"%s %s",cmd,from);
    play->from = cardOf(from,deck);
    if (isKing(play->from)) {
      play->type = KING_PLAY;
      play->onto = NULL;
    } else {
      play->type = MOVE_PLAY;
      sscanf(buffer,"%s %s %s",cmd,from,onto);
      play->onto = cardOf(onto,deck);
    }
  } else if (cmd[0] == 'p') {
    // it's a play onto the arena
    play->type = ARENA_PLAY;
    sscanf(buffer,"%s %s",cmd,from);
    play->from = cardOf(from,deck);
    play->onto = NULL;
  } else if (cmd[0] == 'd') {
    // it's a draw
    play->type = DRAW_PLAY;
    play->from = NULL;
    play->onto = NULL;
  }
}
Example #4
0
void UT_FAP_Embmod::test_Embmod_vect()
{
    printf("\n === Test of module [Vector]\n");

    iEnv = CAE_Env::NewL(NULL, NULL, KSpecFileName_vect, 1, NULL, KLogFileName_vect);
    CPPUNIT_ASSERT_MESSAGE("Fail to create CAE_Env", iEnv != 0);
    iEnv->ConstructSystem();

    for (TInt i=0; i<18; i++)
    {
        iEnv->Step();
    }


    CAE_ConnPointBase* c_rock = iEnv->Root()->GetOutpN("rock");
    CPPUNIT_ASSERT_MESSAGE("Fail to get [rock] output", c_rock != 0);
    CAE_StateBase* sb_rock_coord = c_rock->GetSrcPin("coord")->GetFbObj(sb_rock_coord);
    CPPUNIT_ASSERT_MESSAGE("Fail to get [rock.coord] src pin state", sb_rock_coord != NULL);
    CAE_StateEx* s_rock_coord = sb_rock_coord->GetFbObj(s_rock_coord);
    CPPUNIT_ASSERT_MESSAGE("Incorrect [rock.coord] ext state", s_rock_coord != NULL);
    CSL_ExprBase& e_rock_coord = s_rock_coord->Value();
    string coord_xs = e_rock_coord.Args()[0]->Data();
    string coord_ys = e_rock_coord.Args()[1]->Data();
    float coord_x, coord_y;
    sscanf(coord_xs.c_str(), "%f", &coord_x);
    sscanf(coord_ys.c_str(), "%f", &coord_y);
    CPPUNIT_ASSERT_MESSAGE("Incorrect [rock.coord] value", coord_x == 1440.0 && coord_y > 79.2999191 && coord_y < 79.2999192);

    delete iEnv;
}
Example #5
0
/**
 * Write an amended monster.txt file
 */
void write_monster_entries(ang_file *fff)
{
	ang_file *old;
	char buf[1024];

	path_build(buf, sizeof(buf), ANGBAND_DIR_GAMEDATA, "monster.txt");
	old = file_open(buf, MODE_READ, FTYPE_TEXT);

	while (file_getl(old, buf, sizeof(buf))) {
		static struct monster_race *race;
		int i, n;

		/* Change monster record */
		if (1 == sscanf(buf, "name:%d", &n)) {
			race = &r_info[n];
			file_putf(fff, "%s\n", buf);
		}

		/* Rewrite 'power' line */
		else if (1 == sscanf(buf, "power:%d", &i))
			file_putf(fff,"power:%d:%d:%d:%d:%d\n", race->level, race->rarity,
					  power[n], scaled_power[n], race->mexp);

		/* Just copy */
		else
			file_putf(fff, "%s\n", buf);
	}

	file_close(old);
}
Example #6
0
static int opts_Parse(Options *opts, int argc, char *argv[])
{
    int ch = -1;

    while (1) {
        ch = getopt(argc, argv, "d:g:n:R:S:v:h?");
        if (ch == -1) {
            break;
        }

        switch (ch) {
          case 'd':
            opts->distance = atof(optarg);
            break;
          case 'n':
            opts->frames = atoi(optarg);
            break;
          case 'v':
            opts->verbose = atoi(optarg);
            break;
          case 'g':
            if (sscanf(optarg, "%i,%i",
                       &opts->width, &opts->height) != 2
             || (opts->width  < 320 || opts->width > 1920)
             || (opts->height < 200 || opts->height > 1080)) { // XXX
                opts->width = 800;
                opts->height = 600;
            }
            break;
          case 'R':
            if (sscanf(optarg, "%lf,%lf,%lf",
                       &opts->rx, &opts->ry, &opts->rz) != 3) { // XXX
                opts->rx = 1.0;
                opts->ry = 1.0;
                opts->rz = 1.0;
            }
            break;
          case 'S':
            opts->shade = shade_StrToMode(optarg);
            break;
          case '?': /* fallthrough */
          case 'h': /* fallthrough */
          default:
            usage();
            return 1;
        }
    }

    /* XXX: watch out here */
    argc -= optind;
    argv += optind;

    if (argc != 1) {
        usage();
        return -1;
    }
    opts->filename = argv[0];

    return 0;
}
Example #7
0
static int
gs232a_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
{
    char posbuf[32];
    int retval, angle;

    rig_debug(RIG_DEBUG_TRACE, "%s called\n", __FUNCTION__);

    retval = gs232a_transaction(rot, "C2" EOM, posbuf, sizeof(posbuf));
    if (retval != RIG_OK || strlen(posbuf) < 10) {
        return retval < 0 ? retval : -RIG_EPROTO;
    }

    /* parse "+0aaa+0eee" */
    if (sscanf(posbuf+2, "%d", &angle) != 1) {
        rig_debug(RIG_DEBUG_ERR, "%s: wrong reply '%s'\n", __FUNCTION__, posbuf);
        return -RIG_EPROTO;
    }
    *az = (azimuth_t)angle;

    if (sscanf(posbuf+7, "%d", &angle) != 1) {
        rig_debug(RIG_DEBUG_ERR, "%s: wrong reply '%s'\n", __FUNCTION__, posbuf);
        return -RIG_EPROTO;
    }
    *el = (elevation_t)angle;

    rig_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.1f, %.1f)\n",
              __FUNCTION__, *az, *el);

    return RIG_OK;
}
Example #8
0
/**
 * Retrieves the current Git revision.
 *
 * @param out[out] a string pointer to return the value (to be aFree()'d.)
 * @retval true  if a revision was correctly detected.
 * @retval false if no revision was detected. out is set to NULL in this case.
 */
bool sysinfo_git_get_revision(char **out) {
	// Only include Git support if we detected it, or we're on MSVC
#if !defined(SYSINFO_VCSTYPE) || SYSINFO_VCSTYPE == VCSTYPE_GIT || SYSINFO_VCSTYPE == VCSTYPE_UNKNOWN
	FILE *fp;
	char ref[128], filepath[128], line[128];

	strcpy(ref, "HEAD");

	while (*ref) {
		snprintf(filepath, sizeof(filepath), ".git/%s", ref);
		if ((fp = fopen(filepath, "r")) != NULL) {
			if (fgets(line, sizeof(line)-1, fp) == NULL) {
				fclose(fp);
				break;
			}
			fclose(fp);
			if (sscanf(line, "ref: %127[^\n]", ref) == 1) {
				continue;
			} else if (sscanf(line, "%127[a-f0-9]", ref) == 1 && strlen(ref) == 40) {
				if (*out != NULL)
					aFree(*out);
				*out = aStrdup(ref);
			}
		}
		break;
	}
	if (*out != NULL)
		return true;
#else
	if (*out != NULL)
		aFree(*out);
	*out = NULL;
#endif
	return false;
}
Example #9
0
/*!
   \fn 
   \brief 
   \return 
   \param 
 */
int
db_convert_Cstring_to_value(const char *Cstring, int sqltype, dbValue * value)
{
    int i;
    double d;

    switch (db_sqltype_to_Ctype(sqltype)) {
    case DB_C_TYPE_STRING:
	return db_set_value_string(value, Cstring);
    case DB_C_TYPE_INT:
	i = 0;
	sscanf(Cstring, "%d", &i);
	db_set_value_int(value, i);
	break;
    case DB_C_TYPE_DOUBLE:
	d = 0.0;
	sscanf(Cstring, "%lf", &d);
	db_set_value_double(value, d);
	break;
    case DB_C_TYPE_DATETIME:
	return db_convert_Cstring_to_value_datetime(Cstring, sqltype, value);
    default:
	db_error("db_convert_Cstring_to_value(): unrecognized sqltype");
	return DB_FAILED;
    }
    return DB_OK;
}
Example #10
0
void F77_NAME(c_line_parse, C_LINE_PARSE) 
(char *line, char *token, f_int *flag, f_int *f_ival, double *rval, char *cval)
{
    int i;
    int ival;

    /* Scan for the token.  If not found, return. */
 
    for (i = 0; i < strlen(line); i++)
       if (line[i] == *token) 
       {
          i++; 
          while (i < strlen(line))
          {
             if (!isspace(line[i])) break; 
             i++;
          }
          
          switch (*flag)
          {
             case 1:   sscanf(&line[i], "%d", &ival);  *f_ival = ival; /* integer */
             case 2:   sscanf(&line[i], "%lf", rval);  /* double */
             case 3:   strcpy(cval, &line[i]); /* character */
          } 
       } 
}
Example #11
0
//! Ugly shotgun parser for one record of the file.
int parseline(char *line,
	      char *retname, int *retadr){
  //Assumes a form like this:
  //md380_spiflash_read                    = 0x802fd83;
  
  
  char *start=line;
  char *eq=strstr(line,"=");
  char *semicolon=strstr(line,";");
  char *name=start;
  char *adr=strstr(line,"0x");
  char *plus=strstr(line,"+");
  
  //We can't handle arithmetic
  if(plus){
    return 0;
  }
  
  //We need all these fields.
  if(name && semicolon && eq && adr){
    sscanf(name,"%s ",retname);
    sscanf(adr, "0x%08x",retadr);
    return 1;
  }
  
  return 0;
}
/**
 * xmlInitMemory:
 *
 * Initialize the memory layer.
 *
 * Returns 0 on success
 */
int
xmlInitMemory(void)
{
#ifdef HAVE_STDLIB_H
     char *breakpoint;
#endif     

     if (xmlInitMemoryDone) return(-1);

#ifdef HAVE_STDLIB_H
     breakpoint = getenv("XML_MEM_BREAKPOINT");
     if (breakpoint != NULL) {
         sscanf(breakpoint, "%d", &xmlMemStopAtBlock);
     }
#endif     
#ifdef HAVE_STDLIB_H
     breakpoint = getenv("XML_MEM_TRACE");
     if (breakpoint != NULL) {
         sscanf(breakpoint, "%p", &xmlMemTraceBlockAt);
     }
#endif     
    
#ifdef DEBUG_MEMORY
     xmlGenericError(xmlGenericErrorContext,
	     "xmlInitMemory() Ok\n");
#endif     
     xmlMemInitialized = 1;
     xmlInitMemoryDone = 1;

     return(0);
}
Example #13
0
int beam_ht_cb(int argc, char *argv[])
{
    char *dist_s, *tilt_s, *a0_s;
    double d, tilt, a0;

    if (argc != 5) {
	fprintf(stderr, "Usage: %s %s distance tilt earth_radius\n",
		argv0, argv1);
	return 0;
    }
    dist_s = argv[2];
    tilt_s = argv[3];
    a0_s = argv[4];
    if (sscanf(dist_s, "%lf", &d) != 1) {
	fprintf(stderr, "Expected float value for distance, got %s\n", dist_s);
	return 0;
    }
    if (sscanf(tilt_s, "%lf", &tilt) != 1) {
	fprintf(stderr, "Expected float value for tilt, got %s\n", tilt_s);
	return 0;
    }
    if (sscanf(a0_s, "%lf", &a0) != 1) {
	fprintf(stderr, "Expected float value for Earth radius, got %s\n",
		a0_s);
	return 0;
    }
    printf("%lf\n", GeogBeamHt(d, tilt * RAD_DEG, a0));
    return 1;
}
Example #14
0
int az_cb(int argc, char *argv[])
{
    char *lon1_s, *lat1_s, *lon2_s, *lat2_s;
    double lon1, lat1, lon2, lat2;

    if (argc != 6) {
	fprintf(stderr, "Usage: %s %s lon1 lat1 lon2 lat2\n", argv0, argv1);
	return 0;
    }
    lon1_s = argv[2];
    lat1_s = argv[3];
    lon2_s = argv[4];
    lat2_s = argv[5];

    /* Get coordinates from command line arguments */
    if (sscanf(lon1_s, "%lf", &lon1) != 1) {
	fprintf(stderr, "Expected float value for lon1, got %s\n", lon1_s);
	return 0;
    }
    if (sscanf(lat1_s, "%lf", &lat1) != 1) {
	fprintf(stderr, "Expected float value for lat1, got %s\n", lat1_s);
	return 0;
    }
    if (sscanf(lon2_s, "%lf", &lon2) != 1) {
	fprintf(stderr, "Expected float value for lon2, got %s\n", lon2_s);
	return 0;
    }
    if (sscanf(lat2_s, "%lf", &lat2) != 1) {
	fprintf(stderr, "Expected float value for lat2, got %s\n", lat2_s);
	return 0;
    }
    printf("%f\n", GeogAz(lon1 * RAD_DEG, lat1 * RAD_DEG,
		lon2 * RAD_DEG,  lat2 * RAD_DEG) * DEG_RAD);
    return 1;
}
Example #15
0
int get_mem_usage(double *_pss, double *_rss) {
    char data[PATH_MAX];
    FILE *smaps;
    double pss = 0.0, rss = 0.0;
    char *line = NULL;
    size_t size = 0;
    pid_t pid = getpid();

    *_pss = 0.0;
    *_rss = 0.0;

    memset(data, 0, sizeof(data));
    snprintf(data, sizeof(data), "/proc/%d/smaps", pid);

    if (NULL == (smaps = fopen(data, "r"))) {
        return -1;
    }

    while ((size = getline(&line, &size, smaps)) != -1) {
        if (0 == strncmp(line, "Pss", strlen("Pss"))) {
            sscanf(line, "Pss: %lf", &pss);
            *_pss += pss;
        }
        if (0 == strncmp(line, "Rss", strlen("Pss"))) {
            sscanf(line, "Rss: %lf", &rss);
            *_rss += pss;
        }
    }
    free(line);
    fclose(smaps);

    return 0;
}
ssize_t amutt_param_write(struct file *filp, const char __user *buf, size_t len, loff_t *data)
{
	char desc[MAX_LEN] = {0};

	unsigned int tmp_up_dur = 10;
	unsigned int tmp_up_step = 1;

	unsigned int tmp_low_dur = 10;
	unsigned int tmp_low_step = 1;

	unsigned int tmp_low_rst_max = 6;

	int tmp_polling_interval = 1;

	unsigned int tmp_deepest_step = COOLER_STEPS-1;

	unsigned int tmp_log = 0;

	len = (len < (sizeof(desc) - 1)) ? len : (sizeof(desc) - 1);

	/* write data to the buffer */
	if (copy_from_user(desc, buf, len)) {
		return -EFAULT;
	}

	if (sscanf(desc, "%d %d %d %d %d %d %d", &tmp_up_dur, &tmp_up_step, &tmp_low_dur, \
								&tmp_low_step, &tmp_low_rst_max, &tmp_polling_interval, &tmp_deepest_step) >= 6) {

		up_duration = tmp_up_dur;
		up_step = tmp_up_step;

		low_duration = tmp_low_dur;
		low_step = tmp_low_step;

		low_rst_max = tmp_low_rst_max;
		polling_interval = tmp_polling_interval;

		if (tmp_deepest_step > 0 && tmp_deepest_step < COOLER_STEPS)
		    amutt.max_level = tmp_deepest_step;

		over_up_time = 0;
		below_low_time = 0;
		low_rst_time = 0;

		mtk_cooler_amutt_dprintk_always("[%s] %s [up]%d %d, [low]%d %d, rst=%d, interval=%d, max_step=%d\n", __func__, desc, up_duration, \
			up_step, low_duration, low_step, low_rst_max, polling_interval, amutt.max_level);

		return len;
	} else if (sscanf(desc, "log=%d", &tmp_log) == 1) {
		if (tmp_log == 1)
			cl_amutt_klog_on = 1;
		else
			cl_amutt_klog_on = 0;

		return len;
	} else {
		mtk_cooler_amutt_dprintk_always("[%s] bad argument = %s\n", __func__, desc);
	}
    return -EINVAL;
}
Example #17
0
unsigned meshObjProcessFace(char *line, int *face)
{
	if (sscanf(line, "%*s%i/%i/%i %i/%i/%i %i/%i/%i", &face[0], &face[1], &face[2], &face[3], &face[4], &face[5], &face[6], &face[7], &face[8]) == 9) {
		return 0;
	} else if (sscanf(line, "%*s%i//%i %i//%i %i//%i", &face[0], &face[2], &face[3], &face[5], &face[6], &face[8]) == 6) {
		face[1] = 0;
		face[4] = 0;
		face[7] = 0;

		return 0;
	} else if (sscanf(line, "%*s%i/%i %i/%i %i/%i", &face[0], &face[1], &face[3], &face[4], &face[6], &face[7]) == 6) {
		face[2] = 0;
		face[5] = 0;
		face[8] = 0;

		return 0;
	} else if (sscanf(line, "%*s%i %i %i", &face[0], &face[3], &face[6]) == 3) {
		face[1] = 0;
		face[4] = 0;
		face[7] = 0;

		face[2] = 0;
		face[5] = 0;
		face[8] = 0;

		return 0;
	}
	return -1;
}
Example #18
0
faidx_t *fai_read(FILE *fp)
{
	faidx_t *fai;
	char *buf, *p;
	int len, line_len, line_blen;
#ifdef _WIN32
	long offset;
#else
	long long offset;
#endif
	fai = (faidx_t*)calloc(1, sizeof(faidx_t));
	fai->hash = kh_init(s);
	buf = (char*)calloc(0x10000, 1);
	while (!feof(fp) && fgets(buf, 0x10000, fp)) {
		for (p = buf; *p && isgraph(*p); ++p);
		*p = 0; ++p;
#ifdef _WIN32
		sscanf(p, "%d%ld%d%d", &len, &offset, &line_blen, &line_len);
#else
		sscanf(p, "%d%lld%d%d", &len, &offset, &line_blen, &line_len);
#endif
		fai_insert_index(fai, buf, len, line_len, line_blen, offset);
	}
	free(buf);
	return fai;
}
Example #19
0
/* Gets parameters from single line of file input */
struct parameters getParametersFromFile(char * filename) {

  struct parameters p;

  char buf[BUF_LENGTH];

  FILE * inputFile;
  inputFile = fopen(filename, "r");

  while( fgets(buf, BUF_LENGTH, inputFile) != NULL ) {
    /* If scanning Time Parameters */
    if (buf[0] == 'T'){
      sscanf(buf, "%c %lf %lf %d", &buf[0], &p.time, &p.dt, &p.interval);
    }
    /* If scanning Particle Parameters */
    else if (buf[0] == 'P'){
      sscanf(buf, "%c %d %d", &buf[0], &p.nIons, &p.nElectrons);
    }
    /* If scanning Space Parameters */
    else if (buf[0] == 'S'){
      sscanf(buf, "%c %d %lf %lf", &buf[0], &p.nGridPoints, &p.gridStart, &p.gridEnd);
    }
    /* If scanning Other Parameters */
    else if (buf[0] == 'O'){
      sscanf(buf, "%c %lf %lf %lf", &buf[0], &p.T_i, &p.T_e, &p.k);
    }
  }
  
  fclose(inputFile);

  return p;
}
Example #20
0
int
main (int argc, char **argv)
{
  void *start, *end;

  printf ("NovaSTOR NovaNET remote DoS + arbitrary memory read\n"
          "by: <mu-b@digit-labs.org>\n"
          "http://www.digit-labs.org/ -- Digit-Labs 2007!@$!\n\n");

  if ((argc % 2) == 1 ||
      (argc > 3 && (sscanf (argv[2], "0x%p", &start) != 1 ||
                    sscanf (argv[3], "0x%p", &end) != 1)))
    {
      fprintf (stderr, "Usage: %s <host> [[start] [end]]\n"
                       "Note: not specifying [[start] [end]] results in DoS!\n\n", argv[0]);
      exit (EXIT_SUCCESS);
    }

  if (argc > 3)
    printf ("dumping from: %p -> %p (%d-bytes) to stderr\n", start, end, (int) (end - start));

  novanet_read (argv[1], start, end, !(argc > 3));

  return (EXIT_SUCCESS);
}
Example #21
0
static void load_obpix_settings (void)
{
	char *user_config_file;
	char linbuf[256], colstr[16];
	FILE *fp;

	// open the file
	user_config_file = g_build_filename (g_get_home_dir (), ".themes/PiX/openbox-3/themerc", NULL);
	fp = g_fopen (user_config_file, "rb");
	g_free (user_config_file);
	if (!fp) return;

	// set defaults in case read fails
	gdk_color_parse ("#4D98F5", &theme_colour);
	gdk_color_parse ("#FFFFFF", &themetext_colour);

	// read data from the file
	while (1)
	{
		if (!fgets (linbuf, 256, fp)) break;
		if (sscanf (linbuf, "window.active.title.bg.color: %s", colstr) == 1)
		{
			if (!gdk_color_parse (colstr, &theme_colour))
				gdk_color_parse ("#4D98F5", &theme_colour);
		}
		if (sscanf (linbuf, "window.active.label.text.color: %s", colstr) == 1)
		{
			if (!gdk_color_parse (colstr, &themetext_colour))
				gdk_color_parse ("#FFFFFF", &themetext_colour);
		}
	}
	fclose (fp);
}
Example #22
0
/* other lines packets/sec perline */ 
int read_network(int *hostrate) {
    FILE *fp;
    int i,numhost=0;
    char line[100];

     i=0; 
    printf(" network file \n");
     /* while(feof(fp) == 0) {*/
    fp=fopen("network.ntw","r");
     while( fgets(line,10,fp) != NULL) { 
            /* printf(" \n *** hell line is =%s \n",line); */
        if(i == 0) {
           /* realloc(hostrate,2*sizeof(int));  */
           /* printf(" network hostrate realloc\n"); */
           sscanf(line,"%3d",&numhost); 
           /* printf("numhost=%d \n",numhost);  */
          } else {
           /* printf("other then that =%s \n",line); */
           /*realloc(hostrate,2*sizeof(int)+(i+1)*sizeof(int));  */
           sscanf(line,"%3d",&hostrate[i]);
           /* printf("hostrate i=%d rate=%d\n",i,hostrate[i]);  */
        }
           i++;
            /* printf("line increment i=%d numhost=%d \n",i,numhost);   */
      }
            /* printf("line out\n");  */
       if(numhost != (i-2)) {
          printf("missing host in network.ntw ; numhost=%d total lines=%d   \n",numhost,i); 
          exit(0);
        }
   fclose(fp);
        printf(" network file read completed \n");
  return numhost;
}
Example #23
0
/********************************************************************************************
 * Channel_ConnectOutgoing
 * purpose : Connect a new outgoing channel
 *           This function is called from the TCL when the "Ok" button is pressed in the
 *           "New Channel" window.
 * input   : clientData - used for creating new command in tcl
 *           interp - interpreter for tcl commands
 *           argc - number of parameters entered to the new command
 *           argv - the parameters entered to the tcl command
 * output  : none
 * return  : TCL_OK - the command was invoked successfully.
 ********************************************************************************************/
int Channel_ConnectOutgoing(ClientData clientData, Tcl_Interp *interp,int argc, char *argv[])
{
    char *     dataType;
    int        status;
    CallInfo * CurrentCall;
    ChannelInfo * MimicChan = NULL;
    ChannelInfo * ReplaceChan = NULL;

    /* Make sure we've got a call related to the channel */
    if ((argv[1] == NULL) || (strlen(argv[1]) == 0)) return TCL_OK;
    if (sscanf(argv[1], "%*d 0x%p:", &CurrentCall) != 1) return TCL_OK;

   /* set the dataType */
    dataType = TclGetVariable("tmp(newchan,dataType)");

    /* see if replace or mimic operation is called for */
    if(argv[2][0])
    {/* argv[2] is not "" */
        if(argv[2][0] == 'S') /* "SameAs" -> mimic chan */
            sscanf(argv[3], "%*d 0x%p", &MimicChan);
        else if(argv[2][0] == 'R') /* "Replace" -> replace chan */
            sscanf(argv[3], "%*d 0x%p", &ReplaceChan);
        else return TCL_ERROR; /* something not right with the command */
    }
    status = OpenChannel(CurrentCall, dataType, MimicChan, ReplaceChan);
    if((argv[2][0] == 'R') && (status >= 0))
    /* The app is reponsible for opening the channle, so here it is: */
        TclExecute("after 3000 {Channel.Drop \"\" {%s} 3}", argv[3]);
    return status;
}
Example #24
0
// static
BOOL LLColor4U::parseColor4U(const std::string& buf, LLColor4U* value)
{
	if( buf.empty() || value == NULL)
	{
		return FALSE;
	}

	U32 v[4];
	S32 count = sscanf( buf.c_str(), "%u, %u, %u, %u", v + 0, v + 1, v + 2, v + 3 );
	if (1 == count )
	{
		// try this format
		count = sscanf( buf.c_str(), "%u %u %u %u", v + 0, v + 1, v + 2, v + 3 );
	}
	if( 4 != count )
	{
		return FALSE;
	}

	for( S32 i = 0; i < 4; i++ )
	{
		if( v[i] > U8_MAX )
		{
			return FALSE;
		}
	}

	value->set( U8(v[0]), U8(v[1]), U8(v[2]), U8(v[3]) );
	return TRUE;
}
static inline int get_wol_pw(const char *ethoptarg, unsigned char *wol_passwd)
{
	int passwd[6];
	int byte_cnt, i;

	/* handle MAC format */
	byte_cnt = sscanf(ethoptarg, "%2x:%2x:%2x:%2x:%2x:%2x",
	                  &passwd[0], &passwd[1], &passwd[2],
	                  &passwd[3], &passwd[4], &passwd[5]);
	/* handle IP format */
	if (byte_cnt < 4)
		byte_cnt = sscanf(ethoptarg, "%d.%d.%d.%d",
		                  &passwd[0], &passwd[1], &passwd[2], &passwd[3]);
	if (byte_cnt < 4) {
		bb_error_msg("cannot read Wake-On-LAN pass");
		return 0;
	}

	for (i = 0; i < byte_cnt; ++i)
		wol_passwd[i] = passwd[i];

	bb_debug_msg("password: %2.2x %2.2x %2.2x %2.2x (%d)\n\n",
	             wol_passwd[0], wol_passwd[1], wol_passwd[2], wol_passwd[3],
	             byte_cnt);

	return byte_cnt;
}
Example #26
0
gboolean
release_is_new(char *found_version)
{
    int curr_maj, curr_min, curr_patch, found_maj, found_min, found_patch;

    int parse_curr = sscanf(PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min,
        &curr_patch);
    int parse_found = sscanf(found_version, "%d.%d.%d", &found_maj, &found_min,
        &found_patch);

    if (parse_found == 3 && parse_curr == 3) {
        if (found_maj > curr_maj) {
            return TRUE;
        } else if (found_maj == curr_maj && found_min > curr_min) {
            return TRUE;
        } else if (found_maj == curr_maj && found_min == curr_min
                                        && found_patch > curr_patch) {
            return TRUE;
        } else {
            return FALSE;
        }
    } else {
        return FALSE;
    }
}
Example #27
0
void parse_option_file(char *prog, FILE *option_file)
{
  int j;
  float f;
  char name[50], val[50];
  while (fscanf(option_file, "%s %s", name, val) == 2) {
    if (name[0] != '-') {
      fprintf(stderr, "Need '-' before option '%s'\n", name);
      usage(prog);
    }
    j = find_option(prog, name+1);
    switch(options[j].type) {
    case INT_OPTION:
      if (sscanf(val, "%d", options[j].valp.i) != 1) {
	fprintf(stderr, "Can't parse argument '%s' as integer\n", val);
	usage(prog);
      }
      break;
    case DOUBLE_OPTION:
      if (sscanf(val, "%f", &f) != 1) {
	fprintf(stderr, "Can't parse argument '%s' as double\n", val);
	usage(prog);
      }
      *options[j].valp.d = f;
      break;
    case STRING_OPTION:
      *(options[j].valp.s) = strsave(val);
      break;
    default:
      fprintf(stderr,
	      "Internal error.  Don't know option type %d\n", options[j].type);
      exit(1);
    }
  }
}
Example #28
0
void TxCom(char *com, char *a1, char *a2, char *a3, 
	              char *a4, char *a5, char *a6)
{
  int i;
  ubyte txBuf[MAXMSGSIZE];
  int header = 0x82; /* Long message by default */
  int data1  = 0x01;
  int data2  = 0x02;
  int data3  = 0x03;
  int data4  = 0x04;
  word res;

  if (a1[0]) sscanf(a1, "%x", &header);
  if (a2[0]) sscanf(a2, "%x", &data1);
  if (a3[0]) sscanf(a3, "%x", &data2);
  if (a4[0]) sscanf(a4, "%x", &data3);
  if (a5[0]) sscanf(a5, "%x", &data4);

  txBuf[0] = header & 0xFF;
  txBuf[1] = data1 & 0xFF;
  txBuf[2] = data2 & 0xFF;
  txBuf[3] = data3 & 0xFF;
  txBuf[4] = data4 & 0xFF;

  for (i = 5; i < MAXMSGSIZE; ++i) txBuf[i] = i; /* put known values in buf */

  PrintMessage(txBuf);
  res = ML_Transmit(txBuf);
  if (res < 0) PrintFault("ML_Transmit", res);
}
Example #29
0
int
main (int argc, char *argv[])
{
  unsigned note_type;
  unsigned long hwcap_mask = 0;
  struct elfbuf elf;

  if (argc < 4)
    {
      abort ();
    }

  if (sscanf (argv[3], "%u", &note_type) != 1)
    exit_with_msg ("%s: bad command line arguments\n", argv[0]);

  if (argc >= 5)
    {
      if (sscanf (argv[4], "%lu", &hwcap_mask) != 1)
	exit_with_msg ("%s: bad command line arguments\n", argv[0]);
    }

  elfbuf_init_from_file (&elf, argv[1]);
  elfbuf_handle_core_notes (&elf, note_type, hwcap_mask);
  elfbuf_write_to_file (&elf, argv[2]);

  return 0;
}
PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream)
		: Control(engine, key) {
	// Loop until we find the closing brace
	Common::String line = stream.readLine();
	trimCommentsAndWhiteSpace(&line);

	while (!stream.eos() && !line.contains('}')) {
		if (line.matchString("*_hotspot*", true)) {
			uint x;
			uint y;
			uint width;
			uint height;

			sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height);

			_hotspot = Common::Rect(x, y, x + width, y + height);
		} else if (line.matchString("cursor*", true)) {
			char nameBuffer[25];

			sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer);

			_hoverCursor = Common::String(nameBuffer);
		}

		line = stream.readLine();
		trimCommentsAndWhiteSpace(&line);
	}

	if (_hotspot.isEmpty() || _hoverCursor.empty()) {
		warning("Push_toggle cursor %u was parsed incorrectly", key);
	}
}