Exemple #1
0
static BOOLEAN
LoadSisState (SIS_STATE *SSPtr, void *fp)
{
	if (
			read_32s (fp, &SSPtr->log_x) != 1 ||
			read_32s (fp, &SSPtr->log_y) != 1 ||
			read_32  (fp, &SSPtr->ResUnits) != 1 ||
			read_32  (fp, &SSPtr->FuelOnBoard) != 1 ||
			read_16  (fp, &SSPtr->CrewEnlisted) != 1 ||
			read_16  (fp, &SSPtr->TotalElementMass) != 1 ||
			read_16  (fp, &SSPtr->TotalBioMass) != 1 ||
			read_a8  (fp, SSPtr->ModuleSlots, NUM_MODULE_SLOTS) != 1 ||
			read_a8  (fp, SSPtr->DriveSlots, NUM_DRIVE_SLOTS) != 1 ||
			read_a8  (fp, SSPtr->JetSlots, NUM_JET_SLOTS) != 1 ||
			read_8   (fp, &SSPtr->NumLanders) != 1 ||
			read_a16 (fp, SSPtr->ElementAmounts, NUM_ELEMENT_CATEGORIES) != 1 ||

			read_str (fp, SSPtr->ShipName, SIS_NAME_SIZE) != 1 ||
			read_str (fp, SSPtr->CommanderName, SIS_NAME_SIZE) != 1 ||
			read_str (fp, SSPtr->PlanetName, SIS_NAME_SIZE) != 1 ||

			read_16  (fp, NULL) != 1 /* padding */
		)
		return FALSE;
	else
	{
		// JMS: Let's make savegames work even between different resolution modes.
		SSPtr->log_x <<= RESOLUTION_FACTOR;
		SSPtr->log_y <<= RESOLUTION_FACTOR;
		return TRUE;
	}
}
int main(void)
{
    char usr_str[MAX_LEN], max_word[MAX_LEN], min_word[MAX_LEN];
    int i;

    /* we must take the user's first word and arbitrarily appoint it both the 
     * largest and smallest word - since we aren't making comparisons as with 
     * folowing words, this portion must be outside the for loop */
    printf("\nEnter word: ");

    /* read_str() returns -1 if the user's word was too long - since the while
     * loop calls read_str every time it evaluates its condition, and since
     * read_str() takes care of reading characters into usr_str, this loop 
     * constitutes a complete error check for strings longer than 20 
     * characters */
    while (read_str(usr_str, MAX_LEN) == -1) {
        printf("\nPlease try again: \n");
    }

    /* arbitrarily put the user's first word into both max_word and min_word -
     * should this first word be four characters long, this will be both the 
     * largest and the smallest string, and the program will print output and
     * terminate */
    strcpy(max_word, usr_str);
    strcpy(min_word, usr_str);

    if (strlen(usr_str) == TERMINATE_LEN) {
        printf("\nSmallest word: %s\n", min_word);
        printf("\nLargest word: %s\n", max_word);
        return 0;
    }

    /* infinite for loop - breaks when the user enters a word of four characters,
     * but only after the word is compared to the current largest and smallest 
     * words */
    for (;;) {
        printf("Enter word: ");

        while (read_str(usr_str, MAX_LEN) == -1) {
            printf("\nPlease try again: ");
        }

        if (strcmp(usr_str, max_word) > 0) {
            strcpy(max_word, usr_str);
        } else if (strcmp(usr_str, min_word) < 0) {
            strcpy(min_word, usr_str);
        }
        
        if (strlen(usr_str) == TERMINATE_LEN) {
            break;
        }
    }

    /* output is printed here if the user's first word was not four characters 
     * in length */
    printf("\nSmallest word: %s\n", min_word);
    printf("\nLargest word: %s\n", max_word);

    return 0;
}
Exemple #3
0
	button pcb_button(const JSON::node& root, const JSON::pointer& ptr)
	{
		auto pshadow = ptr.field("shadow");
		auto pname = ptr.field("name");
		auto psymbol = ptr.field("symbol");
		auto pmacro = ptr.field("macro");
		auto pmovie = ptr.field("movie");
		struct button ret;
		ret.type = button::TYPE_BUTTON;
		ret.name = read_str(root, pname);
		std::u32string symbol = (root.type_of(psymbol) != JSON::none) ? read_str32(root, psymbol) :
			utf8::to32(ret.name);
		if(symbol.length() != 1)
			(stringfmt() << "Symbol at '" << ptr << "' must be 1 codepoint").throwex();
		ret.symbol = symbol[0];
		ret.rmin = 0;
		ret.rmax = 0;
		ret.centers = false;
		ret.macro = (root.type_of(pmacro) != JSON::none) ? read_str(root, pmacro) : utf8::to8(symbol);
		std::string movie = (root.type_of(pmovie) != JSON::none) ? read_str(root, pmovie) :
			utf8::to8(symbol);
		if(movie.length() != 1)
			(stringfmt() << "Movie at '" << ptr << "' must be 1 character").throwex();
		ret.msymbol = movie[0];
		ret.shadow = (root.type_of(pshadow) != JSON::none) ? read_bool(root, pshadow) : false;
		return ret;
	}
Exemple #4
0
sys_shlfunc()
#define sys_shl sys_shlfunc()
{register int st,i,v ;
  st=cre(1);
  fprintf ( bstdout, "Shell (0 to quit): ");
  read_str(st);
  while( len_str(st)==0 ){
    fprintf ( bstdout, "\n");
    fprintf ( bstdout, "Shell (0 to quit): ");
    read_str(st);
  }
  while( fst_str(st)!=ord('0') ){
    itr_str(st,i,v,cstr_shl[i-1]=chr(v));
    cstr_shl[len_str(st)]='\0';
    fprintf ( bstdout, "\n");
    system(cstr_shl);
    fprintf ( bstdout, "\n");
    fprintf ( bstdout, "Shell (0 to quit): ");
    read_str(st);
    while( len_str(st)==0 ){
      fprintf ( bstdout, "\n");
      fprintf ( bstdout, "Shell (0 to quit): ");
      read_str(st);
    }
  }
}
Exemple #5
0
	struct controller_set* pcs_parse_set(const JSON::node& root, JSON::pointer ptr)
	{
		if(root.type_of_indirect(ptr) != JSON::object)
			(stringfmt() << "Expected (indirect) object for '" << ptr << "'").throwex();
		ptr = root.resolve_indirect(ptr);
		controller_set* ret = NULL;
		auto pcontrollers = ptr.field("controllers");
		auto plegal = ptr.field("legal");
		auto phname = ptr.field("hname");
		auto psymbol = ptr.field("symbol");
		if(root.type_of_indirect(pcontrollers) != JSON::array)
			(stringfmt() << "Expected (indirect) array for '" << pcontrollers << "'").throwex();
		JSON::pointer _controllers = root.resolve_indirect(pcontrollers);
		const JSON::node& n_controllers = root.follow(_controllers);
		std::vector<controller> controllers;
		for(auto i = n_controllers.begin(); i != n_controllers.end(); i++)
			controllers.push_back(pcs_parse_controller(root, _controllers.index(i.index())));
		if(root.type_of_indirect(plegal) != JSON::array)
			(stringfmt() << "Expected (indirect) array for '" << plegal << "'").throwex();
		JSON::pointer _legal = root.resolve_indirect(plegal);
		const JSON::node& n_legal = root.follow_indirect(_legal);
		std::set<unsigned> legal;
		for(auto i = n_legal.begin(); i != n_legal.end(); i++)
			legal.insert(read_int(root, _legal.index(i.index())));
		std::string iname = read_str(root, ptr.field("name"));
		std::string hname = (root.type_of(phname) != JSON::none) ? read_str(root, phname) : iname;
		std::string symbol = (root.type_of(psymbol) != JSON::none) ? read_str(root, psymbol) : iname;
		ret = new controller_set;
		ret->iname = iname;
		ret->hname = hname;
		ret->symbol = symbol;
		ret->controllers = controllers;
		ret->legal_for = legal;
		return ret;
	}
Exemple #6
0
void Server(semaphore sem,int fifo)
{
	num_mem member;
	bool flag = true;
	lth = false;
	std::vector<pthread_t> threads;
	while (flag)
	{
		pthread_t temp;
		if(!lth && !isStr)
		{
			lth = true;
			std::string* ptr = &sent;
			pthread_create(&temp,NULL,getStr,NULL);
			threads.push_back(temp);
		}
		int val;
		if(!isStr)
		{
			sem_getvalue(sem.ws,&val);
			if(val == 0)
			{
				read_str(sem,fifo,&member);
			}
		}
		if(isStr)
		{
			sem_getvalue(sem.ws,&val);
			if(val == 0)
			{
				read_str(sem,fifo,&member);
			} else
			{
				if( sem_trywait(sem.ib) == 0)
				{
					sem_wait(sem.ws);
					int status = write_str(sem,fifo,sent,&member);
					isStr = false;
				}
			}
		}
		if(EF)
		{
			flag = false;
			end_seq(threads);
			return;
		}
		if(threads.size() > 100)
		{
			clear(threads);
		}
	}
}
int init_settings_from_env()
{
    if (read_str("TMC_SPYWARE_DATA_DIR", &settings.data_dir) <= 0) {
        return 0;
    }

    if (read_str("TMC_SPYWARE_AUTH_URL", &settings.auth_url) <= 0) {
        return 0;
    }

    return 1;
}
static bool load_cached_font_list(struct serializer *s)
{
	bool success = true;
	int count;

	success = read_var(s, count);
	if (!success) return false;

	da_init(font_list);
	da_resize(font_list, count);

#define do_read(var) \
	success = read_var(s, var); \
	if (!success) break

	for (int i = 0; i < count; i++) {
		struct font_path_info *info = &font_list.array[i];

		success = read_str(s, &info->face_and_style);
		if (!success) break;

		do_read(info->full_len);
		do_read(info->face_len);
		do_read(info->is_bitmap);
		do_read(info->num_sizes);

		info->sizes = bmalloc(sizeof(int) * info->num_sizes);
		success = read_data(s, info->sizes,
				sizeof(int) * info->num_sizes);
		if (!success) break;

		do_read(info->bold);

		success = read_str(s, &info->path);
		if (!success) break;

		do_read(info->italic);
		do_read(info->index);
	}

#undef do_read

	if (!success) {
		free_os_font_list();
		return false;
	}

	return true;
}
Exemple #9
0
int main (int argc, char * argv[]) {
  trv_struc base;
  char * fname1, *fname2;
  int lado;
  mat_str   str, str_rot;
  win_struc win_ero;
  trv_struc_list * lower, * apt_list;

  fname1 = argv[1];
  fname2 = argv[2];

  zera_basis_by_ron (&base);
  read_itrv (fname1, &base);
  read_str (fname2, &str);

  beatriz = 1;
  gera_lower_bounds_crescente (&lower, &base, &str);

  lado = 0;
  while (lower) { 
    apt_list = lower;
    lower = lower->prox;
    printf ("Lower Basis %03d:\n", ++lado);
    disp_basis_by_ron (&apt_list->base);
    free_basis_by_ron (&apt_list->base);
    free (apt_list);
  }


  free_basis_by_ron (&base);
  if (str.tag == MM_IMG && str.dat) free (str.dat);
}
Exemple #10
0
int Scanner::GetToken(int *sub) {
  *sub = 0;
  skip_non_token();
  //
  char c = cur_char();
  if (is_dec(c)) {
    return read_num();
  }
  //
  struct OperatorTableEntry *op = lookup_op();
  if (op) {
    int r;
    r = read_op(op);
    *sub = op->sub_op;
    return r;
  }
  //
  if (c == '\"') {
    return read_str();
  }
  if (is_symhead(c)) {
    return read_sym();
  }
  return -1;
}
Exemple #11
0
/*
 * Read some house info
 */
static void rd_house(int n)
{
	house_type *house_ptr = &houses[n];

	start_section_read("house");

	/* coordinates of corners of house */
	house_ptr->x_1 = read_int("x1");
	house_ptr->y_1 = read_int("y1");
	house_ptr->x_2 = read_int("x2");
	house_ptr->y_2 = read_int("y2");
	
	/* coordinates of the house door */
	house_ptr->door_y = read_int("door_y");
	house_ptr->door_x = read_int("door_x");

	/* Door Strength */
	house_ptr->strength = read_int("strength");

	/* Owned or not */
	read_str("owned",house_ptr->owned); 

	house_ptr->depth = read_int("depth");
	house_ptr->price = read_int("price");

	end_section_read("house");

}
Exemple #12
0
std::unique_ptr<tag> io::read(std::istream& is, std::string& key)
{
    tag::tag_type tt = read_type(is);
    key = read_str(is);
    if(!is)
        throw tag::input_error((boost::format("Error reading name of tag_%1%") % tt).str());
    return read_payload(tt, is);
}
Exemple #13
0
/*
 * Read some party info
 
 FOUND THE BUIG!!!!!! the disapearing party bug. no more.
 I hope......
-APD-
 */
static void rd_party(int n)
{
	party_type *party_ptr = &parties[n];

	start_section_read("party");

	/* Party name */
	read_str("name",party_ptr->name);

	/* Party owner's name */
	read_str("owner",party_ptr->owner);

	/* Number of people and creation time */
	party_ptr->num = read_int("num");
	read_hturn("created", &party_ptr->created);

	end_section_read("party");
}
Exemple #14
0
/* Parse the string in *src as JSON, and write the result into *dst.
 * max_depth limits the recursion and JSON tree depth.
 * Warning: this overwrites the input string (what *src points to)!
 * Returns:
 *   0: success, *dst is valid, *src points to the end (the caller must check
 *      whether *src really terminates)
 *  -1: failure, *dst is invalid, there may be dead allocs under ta_parent
 *      (ta_free_children(ta_parent) is the only way to free them)
 * The input string can be mutated in both cases. *dst might contain string
 * elements, which point into the (mutated) input string.
 */
int json_parse(void *ta_parent, struct mpv_node *dst, char **src, int max_depth)
{
    max_depth -= 1;
    if (max_depth < 0)
        return -1;

    eat_ws(src);

    char c = **src;
    if (!c)
        return -1; // early EOF
    if (c == 'n' && strncmp(*src, "null", 4) == 0) {
        *src += 4;
        dst->format = MPV_FORMAT_NONE;
        return 0;
    } else if (c == 't' && strncmp(*src, "true", 4) == 0) {
        *src += 4;
        dst->format = MPV_FORMAT_FLAG;
        dst->u.flag = 1;
        return 0;
    } else if (c == 'f' && strncmp(*src, "false", 5) == 0) {
        *src += 5;
        dst->format = MPV_FORMAT_FLAG;
        dst->u.flag = 0;
        return 0;
    } else if (c == '"') {
        return read_str(ta_parent, dst, src);
    } else if (c == '[' || c == '{') {
        return read_sub(ta_parent, dst, src, max_depth);
    } else if (c == '-' || (c >= '0' && c <= '9')) {
        // The number could be either a float or an int. JSON doesn't make a
        // difference, but the client API does.
        char *nsrci = *src, *nsrcf = *src;
        errno = 0;
        long long int numi = strtoll(*src, &nsrci, 0);
        if (errno)
            nsrci = *src;
        errno = 0;
        double numf = strtod(*src, &nsrcf);
        if (errno)
            nsrcf = *src;
        if (nsrci >= nsrcf) {
            *src = nsrci;
            dst->format = MPV_FORMAT_INT64; // long long is usually 64 bits
            dst->u.int64 = numi;
            return 0;
        }
        if (nsrcf > *src && isfinite(numf)) {
            *src = nsrcf;
            dst->format = MPV_FORMAT_DOUBLE;
            dst->u.double_ = numf;
            return 0;
        }
        return -1;
    }
    return -1; // character doesn't start a valid token
}
Exemple #15
0
AST_expr* readASTExpr(BufferedReader* reader) {
    uint8_t type = reader->readByte();
    if (VERBOSITY("parsing") >= 2)
        printf("type = %d\n", type);
    if (type == 0)
        return NULL;

    uint8_t checkbyte = reader->readByte();
    assert(checkbyte == 0xae);

    switch (type) {
        case AST_TYPE::Attribute:
            return read_attribute(reader);
        case AST_TYPE::BinOp:
            return read_binop(reader);
        case AST_TYPE::BoolOp:
            return read_boolop(reader);
        case AST_TYPE::Call:
            return read_call(reader);
        case AST_TYPE::Compare:
            return read_compare(reader);
        case AST_TYPE::Dict:
            return read_dict(reader);
        case AST_TYPE::DictComp:
            return read_dictcomp(reader);
        case AST_TYPE::IfExp:
            return read_ifexp(reader);
        case AST_TYPE::Index:
            return read_index(reader);
        case AST_TYPE::Lambda:
            return read_lambda(reader);
        case AST_TYPE::List:
            return read_list(reader);
        case AST_TYPE::ListComp:
            return read_listcomp(reader);
        case AST_TYPE::Name:
            return read_name(reader);
        case AST_TYPE::Num:
            return read_num(reader);
        case AST_TYPE::Repr:
            return read_repr(reader);
        case AST_TYPE::Slice:
            return read_slice(reader);
        case AST_TYPE::Str:
            return read_str(reader);
        case AST_TYPE::Subscript:
            return read_subscript(reader);
        case AST_TYPE::Tuple:
            return read_tuple(reader);
        case AST_TYPE::UnaryOp:
            return read_unaryop(reader);
        default:
            fprintf(stderr, "Unknown expr node type (parser.cpp:" STRINGIFY(__LINE__) "): %d\n", type);
            abort();
            break;
    }
}
Exemple #16
0
void
pkcs11_generate(FILE * outfile, const char *url, gnutls_pk_algorithm_t pk,
		unsigned int bits,
		const char *label, const char *id, int detailed,
		unsigned int flags, common_info_st * info)
{
	int ret;
	gnutls_datum_t pubkey;
	gnutls_datum_t cid = {NULL, 0};
	unsigned char raw_id[128];
	size_t raw_id_size;

	pkcs11_common(info);

	FIX(url, outfile, detailed, info);
	CHECK_LOGIN_FLAG(flags);

	if (id != NULL) {
		raw_id_size = sizeof(raw_id);
		ret = gnutls_hex2bin(id, strlen(id), raw_id, &raw_id_size);
		if (ret < 0) {
			fprintf(stderr, "Error converting hex: %s\n", gnutls_strerror(ret));
			exit(1);
		}
		cid.data = raw_id;
		cid.size = raw_id_size;
	}

	if (outfile == stderr || outfile == stdout) {
		fprintf(stderr, "warning: no --outfile was specified and the generated public key will be printed on screen.\n");
	}

	if (label == NULL && info->batch == 0) {
		label = read_str("warning: Label was not specified.\nLabel: ");
	}

	ret =
	    gnutls_pkcs11_privkey_generate3(url, pk, bits, label, &cid,
					    GNUTLS_X509_FMT_PEM, &pubkey,
					    info->key_usage,
					    flags);
	if (ret < 0) {
		fprintf(stderr, "Error in %s:%d: %s\n", __func__, __LINE__,
			gnutls_strerror(ret));
		if (bits != 1024 && pk == GNUTLS_PK_RSA)
			fprintf(stderr,
				"note: several smart cards do not support arbitrary size keys; try --bits 1024 or 2048.\n");
		exit(1);
	}

	fwrite(pubkey.data, 1, pubkey.size, outfile);
	gnutls_free(pubkey.data);

	UNFIX;
	return;
}
Exemple #17
0
static int read_int(char *line, char *param)
{
  char *tmp;
  int value;

  tmp = read_str(line, param);
  sscanf(tmp, "%i", &value);

  return value;
}
Exemple #18
0
static float read_float(char *line, char *param)
{
  char *tmp;
  float value;

  tmp = read_str(line, param);
  sscanf(tmp, "%f", &value);

  return value;
}
Exemple #19
0
static double read_double(char *line, char *param)
{
  char *tmp;
  double value;

  tmp = read_str(line, param);
  sscanf(tmp, "%lf", &value);

  return value;
}
Exemple #20
0
int read_data(const char *file)
{
	size_t i;
	FILE *fin = fopen(file, "r");
	if (fin == NULL)
		goto exit_no_file;

	fscanf(fin, "%zu", &idata_count);
	if (feof(fin) || ferror(fin))
		goto exit_bad_file;

	idata = malloc(idata_count * sizeof *idata);
	if (idata == NULL)
		goto exit_no_mem;

	for (i = 0; i < idata_count; ++i)
		fscanf(fin, "%d", &idata[i]);
	if (feof(fin) || ferror(fin))
		goto exit_bad_file;

	fscanf(fin, "%zu", &sdata_count);
	if (feof(fin) || ferror(fin))
		goto exit_bad_file;

	sdata = malloc(sdata_count * sizeof *sdata);
	if (sdata == NULL)
		goto exit_no_mem;

	for (i = 0; i < sdata_count; ++i)
	{
		sdata[i] = read_str(fin);

		/* could also be no memory, but chances of this is higher */
		if (sdata[i] == NULL)
			goto exit_bad_file;
	}

	fclose(fin);

	return 0;
exit_no_file:
	printf("no such file: \"%s\"\n", file);
	goto exit_fail;
exit_bad_file:
	printf("bad file format\n");
	goto exit_yes_file;
exit_no_mem:
	printf("out of memory\n");
exit_yes_file:
	fclose(fin);
exit_fail:
	cleanup_data();
	return -1;
}
Exemple #21
0
void	command_pwd(t_env *env, char **splitted)
{
	char	*path;

	write_long(env, COMMAND_PWD);
	path = read_str(env);
	ft_putendl(path);
	ft_putendl("SUCCESS");
	free(path);
	(void)splitted;
}
Exemple #22
0
static void print_kdump(void)
{
	struct stat sb;
	char tmp[1024];

	if (stat("/sys/kernel/kexec_crash_loaded", &sb) != 0)
		return;
	read_str(tmp, "/sys/kernel/kexec_crash_loaded", sizeof(tmp));
	if (strncmp(tmp, "1", 1) == 0)
		printf("kdump,");
}
int read_int(char *b, char *f, int *n)
{
  char buff[256];

  if(read_str(b, f, buff, sizeof(buff)) < 0)
    return -1;

  /* read value */
  sscanf(buff, "%d", n);

  return 0;
}
Exemple #24
0
/* This is wrapper around read_str() (which see for details); it
   simply asks svn_path_is_canonical() of the string it reads,
   returning an error if the test fails.
   ### It seems this is only called for entrynames now
   */
static svn_error_t *
read_path(const char **result,
          char **buf, const char *end,
          apr_pool_t *pool)
{
    SVN_ERR(read_str(result, buf, end, pool));
    if (*result && **result && !svn_relpath_is_canonical(*result))
        return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
                                 _("Entry contains non-canonical path '%s'"),
                                 *result);
    return SVN_NO_ERROR;
}
Exemple #25
0
	struct controller pcs_parse_controller(const JSON::node& root, JSON::pointer ptr)
	{
		if(root.type_of_indirect(ptr) != JSON::object)
			(stringfmt() << "Expected (indirect) object for '" << ptr << "'").throwex();
		ptr = root.resolve_indirect(ptr);
		controller ret;
		auto pbuttons = ptr.field("buttons");
		std::string cclass = read_str(root, ptr.field("class"));
		std::string type = read_str(root, ptr.field("type"));
		if(root.type_of_indirect(pbuttons) != JSON::array)
			(stringfmt() << "Expected (indirect) array for '" << pbuttons << "'").throwex();
		JSON::pointer _buttons = root.resolve_indirect(pbuttons);
		const JSON::node& n_buttons = root.follow(_buttons);
		std::vector<button> buttons;
		for(auto i = n_buttons.begin(); i != n_buttons.end(); i++)
			buttons.push_back(pcs_parse_button(root, _buttons.index(i.index())));
		ret.cclass = cclass;
		ret.type = type;
		ret.buttons = buttons;
		return ret;
	}
Exemple #26
0
int RDFParser::read_main(stringstream & stream) {
	int ret;
	ret=read_str(stream, "main");
       	if (ret < 0)
		return ret;

	ret=read_conditions(stream);
	if (ret < 0)
		return ret;

	return 0;
}
Exemple #27
0
static int
recv_bsd_auth (int s, u_char *buf,
	       struct sockaddr_in *thisaddr,
	       struct sockaddr_in *thataddr,
	       char **client_username,
	       char **server_username,
	       char **cmd)
{
    struct passwd *pwd;

    *client_username = read_str (s, USERNAME_SZ, "local username");
    *server_username = read_str (s, USERNAME_SZ, "remote username");
    *cmd = read_str (s, ARG_MAX + 1, "command");
    pwd = getpwnam(*server_username);
    if (pwd == NULL)
	fatal(s, NULL, "Login incorrect.");
    if (iruserok(thataddr->sin_addr.s_addr, pwd->pw_uid == 0,
		 *client_username, *server_username))
	fatal(s, NULL, "Login incorrect.");
    return 0;
}
Exemple #28
0
static void
read_next(ParseInfo pi, const char *key) {
    VALUE	obj;

    if ((void*)&obj < pi->stack_min) {
	rb_raise(rb_eSysStackError, "JSON is too deeply nested");
    }
    next_non_white(pi);	/* skip white space */
    switch (*pi->s) {
    case '{':
	read_hash(pi, key);
	break;
    case '[':
	read_array(pi, key);
	break;
    case '"':
	read_str(pi, key);
	break;
    case '+':
    case '-':
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
	read_num(pi, key);
	break;
    case 'I':
	read_num(pi, key);
	break;
    case 't':
	read_true(pi, key);
	break;
    case 'f':
	read_false(pi, key);
	break;
    case 'n':
	read_nil(pi, key);
	break;
    case '\0':
	return;
    default:
	return;
    }
}
Exemple #29
0
/* returns false if a option was missing */
bool Profile::load_profile(const char *section) {
  int ires, *tvar;
  float fres, *fvar;
  bool tres, res = true;
  struct stat st;
  
  if(!cfg) return(false); /* no setup() called */
  if(stat(profile_path, &st) == -1) return(false); /* file not there */

  for(int i=0;cfg[i].name;i++) {
    
    switch(cfg[i].type) {

    case cfgINT:
      tvar = (int*)cfg[i].var;
      ires = read_int(section,cfg[i].name);
      *tvar = (ires<0) ? atoi(cfg[i].defval) : ires;
      func("load_profile(%s) parsed %s value %i",
	   section, cfg[i].name, *(int*)cfg[i].var);
      res &= (ires>=0);
      break;

    case cfgSTR:
      tres = read_str(section,cfg[i].name,(char*)cfg[i].var);
      if(!tres) {
	snprintf((char*)cfg[i].var,MAX_VALUE_SIZE,"%s",cfg[i].defval);
	res = false;
      }
      func("load_profile(%s) parsed %s value %s",
	   section, cfg[i].name,(char*)cfg[i].var);
      break;

    case cfgFLOAT:
      fvar = (float*)cfg[i].var;
      fres = read_float(section,cfg[i].name);
      if(fres==-1.0f) {
	sscanf(cfg[i].defval,"%f",fvar);
	res = false; }
      else *fvar = fres;
      func("load_profile(%s) parsed %s value %.4f",
	   section, cfg[i].name, *(float*)cfg[i].var);
      break;

    case cfgNULL: break;

    }
  }
  return(res);
}
Exemple #30
0
int RDFParser::read_rules(stringstream & stream) {
	int ret=0;
	string rulename;
	string rulestr;
	Rule * rule;
	rdfg->graph->resolve();
	while (ret >= 0) {
		ret = check_str(stream, "rule");
		if (ret<0)
			break;
		stream >> rulename;
		rule = new Rule(rulename);
		ret = read_str(stream, "{");
		if (ret < 0)
			return ret;
		ret = read_str(stream, "left");
		if (ret < 0)
			return ret;
		ret = read_graph(stream, rule->left());
		if (ret < 0)
			return ret;
		ret = read_str(stream, "right");
		if (ret < 0)
			return ret;
		ret = read_graph(stream, rule->right());
		if (ret < 0)
			return ret;
		ret = read_str(stream, "}");
		if (ret < 0)
			return ret;

		rule->preprocess();
		rdfg->add_rule(rule);		
	}
	return 0;
}