示例#1
0
int parse_actor_body_part (body_part *part, xmlNode *cfg, const char *part_name) {
	xmlNode *item;
	char errmsg[120];
	int ok = 1;

	if (cfg == NULL) return 0;
	
	for (item = cfg; item; item = item->next) {
		if (item->type == XML_ELEMENT_NODE) {
			if (xmlStrcasecmp (item->name, "model") == 0) {
				get_string_value (part->model_name, sizeof (part->model_name), item);
			} else if (xmlStrcasecmp (item->name, "skin") == 0) {
				get_string_value (part->skin_name, sizeof (part->skin_name), item);
			} else if (xmlStrcasecmp (item->name, "glow") == 0) {
				int mode = find_description_index (glow_mode_dict, item->children->content, "glow mode");
				if (mode < 0) mode = GLOW_NONE;
				part->glow = mode;
			} else {
				snprintf (errmsg, sizeof (errmsg), "unknown %s property \"%s\"", part_name, item->name);
				LogError (errmsg);
				ok = 0;
			}
		}
	}
	
	return ok;
}
示例#2
0
int parse_actor_legs (actor_types *act, xmlNode *cfg) {
	xmlNode *item;
	char errmsg[120];
	int ok, col_idx;
	legs_part *legs;

	if (cfg == NULL || cfg->children == NULL) return 0;
	
	col_idx = get_property (cfg, "color", "legs color", legs_color_dict);
	if (col_idx < 0) return 0;
	
	legs = &(act->legs[col_idx]);
	ok = 1;
	for (item = cfg->children; item; item = item->next) {
		if (item->type == XML_ELEMENT_NODE) {
			if (xmlStrcasecmp (item->name, "skin") == 0) {
				get_string_value (legs->legs_name, sizeof (legs->legs_name), item);
			} else if (xmlStrcasecmp (item->name, "model") == 0) {
				get_string_value (legs->model_name, sizeof (legs->model_name), item);
			} else if (xmlStrcasecmp (item->name, "glow") == 0) {
				int mode = find_description_index (glow_mode_dict, item->children->content, "glow mode");
				if (mode < 0) mode = GLOW_NONE;
				legs->glow = mode;
			} else {
				snprintf (errmsg, sizeof (errmsg), "unknown legs property \"%s\"", item->name);
				LogError (errmsg);
				ok = 0;
			}
		}
	}
	
	return ok;
}
示例#3
0
/* Load the history list from the history file. */
void
load_history ()
{
  char *hf;

  /* Truncate history file for interactive shells which desire it.
     Note that the history file is automatically truncated to the
     size of HISTSIZE if the user does not explicitly set the size
     differently. */
  set_if_not ("HISTFILESIZE", get_string_value ("HISTSIZE"));
  stupidly_hack_special_variables ("HISTFILESIZE");

  /* Read the history in HISTFILE into the history list. */
  hf = get_string_value ("HISTFILE");

  if (hf && *hf)
    {
      struct stat buf;

      if (stat (hf, &buf) == 0)
	{
	  read_history (hf);
	  using_history ();
	  history_lines_in_file = where_history ();
	}
    }
}
示例#4
0
int parse_actor_skin (actor_types *act, xmlNode *cfg) {
	xmlNode *item;
	char errmsg[120];
	int ok, col_idx;
	skin_part *skin;

	if (cfg == NULL || cfg->children == NULL) return 0;
	
	col_idx = get_property (cfg, "color", "skin color", skin_color_dict);
	if (col_idx < 0) return 0;
	
	skin = &(act->skin[col_idx]);
	ok = 1;
	for (item = cfg->children; item; item = item->next) {
		if (item->type == XML_ELEMENT_NODE) {
			if (xmlStrcasecmp (item->name, "hands") == 0) {
				get_string_value (skin->hands_name, sizeof (skin->hands_name), item);
			} else if (xmlStrcasecmp (item->name, "head") == 0) {
				get_string_value (skin->head_name, sizeof (skin->head_name), item);
			} else {
				snprintf (errmsg, sizeof (errmsg), "unknown skin property \"%s\"", item->name);
				LogError (errmsg);
				ok = 0;
			}
		}
	}
	
	return ok;
}
示例#5
0
int parse_actor_shirt (actor_types *act, xmlNode *cfg) {
	xmlNode *item;
	char errmsg[120];
	int ok, col_idx;
	shirt_part *shirt;

	if (cfg == NULL || cfg->children == NULL) return 0;
	
	col_idx = get_property (cfg, "color", "shirt color", shirt_color_dict);
	if (col_idx < 0) return 0;
	
	shirt = &(act->shirt[col_idx]);
	ok = 1;
	for (item = cfg->children; item; item = item->next) {
		if (item->type == XML_ELEMENT_NODE) {
			if (xmlStrcasecmp (item->name, "arms") == 0) {
				get_string_value (shirt->arms_name, sizeof (shirt->arms_name), item);
			} else if (xmlStrcasecmp (item->name, "model") == 0) {
				get_string_value (shirt->model_name, sizeof (shirt->model_name), item);
			} else if (xmlStrcasecmp (item->name, "torso") == 0) {
				get_string_value (shirt->torso_name, sizeof (shirt->torso_name), item);
			} else {
				snprintf (errmsg, sizeof (errmsg), "unknown shirt property \"%s\"", item->name);
				LogError (errmsg);
				ok = 0;
			}
		}
	}
	
	return ok;
}
示例#6
0
文件: protocol.c 项目: starius/ravi
static int vscode_parse_initialize_request(json_value *js, ProtocolMessage *msg,
                                           FILE *log) {
  // {"type":"request","seq":1,"command":"initialize","arguments":{"adapterID":"lua","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true}}
  json_value *args = get_object_value(js, "arguments", log);
  if (args == NULL) return VSCODE_UNKNOWN_REQUEST;
  const char *adapterID = get_string_value(args, "adapterID", log);
  if (adapterID == NULL || strcmp(adapterID, "lua") != 0) {
    fprintf(log, "Unknown adapterID '%s' in initialize command\n",
            adapterID != NULL ? adapterID : "null");
    return VSCODE_UNKNOWN_REQUEST;
  }
  strncpy(msg->u.Request.u.InitializeRequest.adapterID, adapterID,
          sizeof msg->u.Request.u.InitializeRequest.adapterID);
  const char *pathFormat = get_string_value(args, "pathFormat", log);
  if (pathFormat != NULL && strcmp(pathFormat, "path") != 0) {
    fprintf(log, "Unsupported pathFormat '%s' in initialize command\n",
            pathFormat != NULL ? pathFormat : "null");
    return VSCODE_UNKNOWN_REQUEST;
  }
  if (pathFormat)
    strncpy(msg->u.Request.u.InitializeRequest.pathFormat, pathFormat,
            sizeof msg->u.Request.u.InitializeRequest.pathFormat);
  int found = 0;
  msg->u.Request.u.InitializeRequest.columnsStartAt1 =
      get_boolean_value(args, "columnsStartAt1", log, &found);
  msg->u.Request.u.InitializeRequest.linesStartAt1 =
      get_boolean_value(args, "linesStartAt1", log, &found);
  msg->u.Request.request_type = VSCODE_INITIALIZE_REQUEST;
  return VSCODE_INITIALIZE_REQUEST;
}
示例#7
0
int parse_actor_script (xmlNode *cfg) {
	xmlNode *item;
	char errmsg[120];
	int ok, act_idx;
	actor_types *act;

	if (cfg == NULL || cfg->children == NULL) return 0;
	
	act_idx = get_property (cfg, "type", "actor type", actor_type_dict);
	if (act_idx < 0) return 0;
	
	act = &(actors_defs[act_idx]);
	ok = 1;
	for (item = cfg->children; item; item = item->next) {
		if (item->type == XML_ELEMENT_NODE) {
			if (xmlStrcasecmp (item->name, "ghost") == 0) {
				act->ghost = get_bool_value (item);
			} else if (xmlStrcasecmp (item->name, "skin") == 0) {
				get_string_value (act->skin_name, sizeof (act->skin_name), item);
			} else if (xmlStrcasecmp (item->name, "model") == 0) {
				get_string_value (act->file_name, sizeof (act->file_name), item);
			} else if (xmlStrcasecmp (item->name, "frames") == 0) {
				ok &= parse_actor_frames (act, item->children);
			} else if (xmlStrcasecmp (item->name, "shirt") == 0) {
				ok &= parse_actor_shirt (act, item);
			} else if (xmlStrcasecmp (item->name, "hskin") == 0) {
				ok &= parse_actor_skin (act, item);
			} else if (xmlStrcasecmp (item->name, "hair") == 0) {
				ok &= parse_actor_hair (act, item);
			} else if (xmlStrcasecmp (item->name, "boots") == 0) {
				ok &= parse_actor_boots (act, item);
			} else if (xmlStrcasecmp (item->name, "legs") == 0) {
				ok &= parse_actor_legs (act, item);
			} else if (xmlStrcasecmp (item->name, "cape") == 0) {
				ok &= parse_actor_cape (act, item);
			} else if (xmlStrcasecmp (item->name, "head") == 0) {
				ok &= parse_actor_head (act, item);
			} else if (xmlStrcasecmp (item->name, "shield") == 0) {
				ok &= parse_actor_shield (act, item);
			} else if (xmlStrcasecmp (item->name, "weapon") == 0) {
				ok &= parse_actor_weapon (act, item);
			} else if (xmlStrcasecmp (item->name, "helmet") == 0) {
				ok &= parse_actor_helmet (act, item);
			} else if (xmlStrcasecmp (item->name, "walk_speed") == 0) {
				act->walk_speed = get_float_value (item);
			} else if (xmlStrcasecmp (item->name, "run_speed") == 0) {
				act->run_speed = get_float_value (item);
			} else {
				snprintf (errmsg, sizeof (errmsg), "Unknown actor attribute \"%s\"", item->name);
				LogError (errmsg);
				ok = 0;
			}
		}
	}
	
	return ok;
}
示例#8
0
文件: file.c 项目: DongXiao1983/uva
extern char* file_read_line(xString *const line , FILE* fp)
{
   char *result = NULL;
   
   string_clear(line);

   if ( NULL == fp )
         error(FATAL, "NULL file pointer");
   else{
      boolean re_readline;

      do {
         char *const pLastChar = get_string_value(line) + get_string_size (line) -2;
			fpos_t startOfLine;

			fgetpos (fp, &startOfLine);
			re_readline = FALSE;
			*pLastChar = '\0';
			result = fgets (get_string_value(line), (int) get_string_size(line), fp);
			if (result == NULL)
			{
				if (! feof(fp))
					error (FATAL | ERROR, "Failure on attempt to read file");
			}
			else if (*pLastChar != '\0'  &&
					 *pLastChar != '\n'  &&  *pLastChar != '\r')
			{
				/*  buffer overflow */
				re_readline = string_auto_resize(line);
				if (re_readline)
					fsetpos (fp, &startOfLine);
				else
					error (FATAL | ERROR, "input line too big; out of memory");
			}
			else
			{
				char* eol;
            line->length = strlen (line->buffer);

				/* canonicalize new line */
				eol = get_string_value(line) + get_string_length(line) - 1;
				if (*eol == '\r')
					*eol = '\n';
				else if (*(eol - 1) == '\r'  &&  *eol == '\n')
				{
					*(eol - 1) = '\n';
					*eol = '\0';
					--line->length;
				}
			}
      }while(re_readline);
   }
   return result;
}
示例#9
0
int _get_string_node_string(QSP_ARG_DECL  char *buf, size_t *buflen_p, spinNodeHandle hNode )
{
	size_t n_need;

	// Ensure allocated buffer is large enough for storing the string
	if( get_string_value(hNode, NULL, &n_need) < 0 ) return -1;
	if(n_need <= *buflen_p) {
		if( get_string_value(hNode, buf, buflen_p) < 0 ) return -1;
	} else {
		strcpy(buf,"(...)");
	}
	return 0;
}
示例#10
0
文件: file.c 项目: DongXiao1983/uva
extern int file_get_char()
{
   int c;
   
   if ( g_file.ungetch != '\0' ){
      c = g_file.ungetch ;
      g_file.ungetch = '\0';
      return c;
   }

   do {
      if ( g_file.current_line != NULL ){
         c = *g_file.current_line++;
         if ( '\0' == c )
              g_file.current_line = NULL ;
      }
      else {
         xString *line = __file_get_line();
         if ( NULL != line )
            g_file.current_line = (unsigned char*) get_string_value (line);
         if ( g_file.current_line == NULL )
            c = EOF;
         else
            c = '\0';
      }
   }while( c == '\0');
   return c;
}
示例#11
0
int main(int argc, char **argv)
{
	const char *parname;
	enum lc15bts_par par;
	int rc, val;

	rc = parse_options(argc, argv);
	if (rc < 0)
		exit(2);

	if (optind >= argc) {
		fprintf(stderr, "You must specify the parameter name\n");
		exit(2);
	}
	parname = argv[optind];

	rc = get_string_value(lc15bts_par_names, parname);
	if (rc < 0) {
		fprintf(stderr, "`%s' is not a valid parameter\n", parname);
		exit(2);
	} else
		par = rc;

	switch (action) {
	case ACT_GET:
		rc = lc15bts_par_get_int(par, &val);
		if (rc < 0) {
			fprintf(stderr, "Error %d\n", rc);
			goto err;
		}
		printf("%d\n", val);
		break;
	case ACT_SET:
		rc = lc15bts_par_get_int(par, &val);
		if (rc < 0) {
			fprintf(stderr, "Error %d\n", rc);
			goto err;
		}
		if (val != 0xFFFF && val != 0xFF && val != 0xFFFFFFFF && !void_warranty) {
			fprintf(stderr, "Parameter is already set!\r\n");
			goto err;
		}
		rc = lc15bts_par_set_int(par, atoi(write_arg));
		if (rc < 0) {
			fprintf(stderr, "Error %d\n", rc);
			goto err;
		}
		printf("Success setting %s=%d\n", parname,
			atoi(write_arg));
		break;
	default:
		fprintf(stderr, "Unsupported action\n");
		goto err;
	}

	exit(0);

err:
	exit(1);
}
示例#12
0
文件: protocol.c 项目: starius/ravi
static int vscode_parse_request(json_value *js, ProtocolMessage *msg,
                                FILE *log) {
  const char *cmd = get_string_value(js, "command", log);
  int found = 0;
  if (cmd == NULL) return VSCODE_UNKNOWN_REQUEST;
  msg->type = VSCODE_REQUEST;
  msg->seq = get_int_value(js, "seq", log, &found);
  strncpy(msg->u.Request.command, cmd, sizeof msg->u.Request.command);
  fprintf(log, "Request --> '%s'", cmd);
  int cmdtype = get_cmdtype(msg->u.Request.command);
  switch (cmdtype) {
    case VSCODE_INITIALIZE_REQUEST:
      return vscode_parse_initialize_request(js, msg, log);
    case VSCODE_DISCONNECT_REQUEST:
    case VSCODE_ATTACH_REQUEST:
    case VSCODE_CONFIGURATION_DONE_REQUEST:
    case VSCODE_THREAD_REQUEST:
      msg->u.Request.request_type = cmdtype;
      break;
    case VSCODE_CONTINUE_REQUEST:
    case VSCODE_NEXT_REQUEST:
    case VSCODE_STEPIN_REQUEST:
    case VSCODE_STEPOUT_REQUEST:
    case VSCODE_PAUSE_REQUEST:
      return vscode_parse_intarg_request(js, msg, cmdtype, "threadId", log);
    case VSCODE_SCOPES_REQUEST:
      return vscode_parse_intarg_request(js, msg, cmdtype, "frameId", log);
    case VSCODE_LAUNCH_REQUEST:
      return vscode_parse_launch_request(js, msg, cmdtype, log);
    case VSCODE_UNKNOWN_REQUEST: break;
    default: msg->u.Request.request_type = cmdtype;
  }
  return cmdtype;
}
示例#13
0
// Returns a more readable representation of the card values
const char* get_string_for_print_value(card_value_t value) {
  if (value == ten) {
    return "10";
  }
  else {
    return get_string_value(value);
  }
}
示例#14
0
rw_status_t get_string_value (const RwTLVAIterator *iter,
                              std::string& str)
{
  rw_ylib_data_t val;
  
  rw_status_t rs = iter->get_value(&val);
  RW_ASSERT(RW_STATUS_SUCCESS == rs);

  return get_string_value(&val.rw_confd, str);
}
示例#15
0
文件: file.c 项目: DongXiao1983/uva
extern const unsigned char *file_get_line(void)
{
   xString* const line = __file_get_line();
   const unsigned char* result = NULL;
   if (line != NULL)
   {
      result = (const unsigned char*) get_string_value(line);
      string_strip_newline(line);
   }
   return result;
}
示例#16
0
/* Returns non-zero if it is time to check mail. */
time_to_check_mail ()
{
  char *temp = get_string_value ("MAILCHECK");
  time_t now = NOW;
  unsigned seconds = 0;

  if ((!temp || sscanf (temp, "%u", &seconds) == 0) ||
      ((now - last_time_mail_checked < seconds)))
    return (0);

  return (1);
}
示例#17
0
    bool SaveOP::init(const map<string, string>& config) {
        string db_url = map_get(config, "db");
        if (!db_url.empty()) {
            db_ = db::open_db(db_url, db::WRITE);
            if (db_) {
                writer_ = db_->new_writer();
            }
        }

        get_string_value(config, "key", key_fno_, key_);

        return is_init();
    }
示例#18
0
文件: protocol.c 项目: starius/ravi
static int vscode_parse_launch_request(json_value *js, ProtocolMessage *msg,
                                       int msgtype, FILE *log) {
  json_value *args = get_object_value(js, "arguments", log);
  if (args == NULL) return VSCODE_UNKNOWN_REQUEST;
  int found = 0;
  msg->u.Request.u.LaunchRequest.noDebug =
      get_boolean_value(args, "noDebug", log, &found);
  msg->u.Request.u.LaunchRequest.stopOnEntry = get_boolean_value(args, "stopOnEntry", log, &found);
  const char *prog = get_string_value(args, "program", log);
  if (prog == NULL) return VSCODE_UNKNOWN_REQUEST;
  strncpy(msg->u.Request.u.LaunchRequest.program, prog, sizeof msg->u.Request.u.LaunchRequest.program);
  msg->u.Request.request_type = msgtype;
  return msgtype;
}
示例#19
0
int parse_actor_hair (actor_types *act, xmlNode *cfg) {
	int col_idx;
	size_t len;
	char *buf;
	
	if (cfg == NULL || cfg->children == NULL) return 0;
	
	col_idx = get_property (cfg, "color", "hair color", hair_color_dict);
	if (col_idx < 0) return 0;
	
	buf = act->hair[col_idx].hair_name;
	len = sizeof (act->hair[col_idx].hair_name);
	get_string_value (buf, len, cfg);
	return 1;
}
示例#20
0
文件: test.c 项目: Hi-Spy/loho
int main(int argc, char *argv[])
{	
	int value = 0;

	int bit = 2;
	char *string = "123ABFabf";
	int i = 0;

	for(i = 1; i <= strlen(string); i++)
	{
		value = get_string_value(string, i);
		printf("string(%s) bit(%d)value(%d)\n", string, i,value);
	}

	return 0;
}
示例#21
0
文件: np.c 项目: adityadx/frash
static struct NPFuckedUpVariant variant_for_object_name(int name) {
    bool valid;
    void *value; size_t value_len;
    _assertZero(get_string_value(food, name, &valid, &value, &value_len));
    struct NPFuckedUpVariant ret;
    log("variant_for_object_name(%d): valid = %d", name, (int) valid);
    if(valid) {
        ret.type = NPVariantType_String;
        ret.string.value = (NPString) {value, value_len};
    } else {
        ret.type = NPVariantType_Object;
        ret.object.whoknows1 = \
        ret.object.whoknows2 = \
        ret.object.whoknows3 = new_idproxy_object(name);
    }
    return ret;
}
示例#22
0
/* If this is an interactive shell, then append the lines executed
   this session to the history file. */
int
maybe_save_shell_history ()
{
  int result = 0;

  if (history_lines_this_session)
    {
      char *hf = get_string_value ("HISTFILE");

      if (hf && *hf)
	{
	  struct stat buf;

	  /* If the file doesn't exist, then create it. */
	  if (stat (hf, &buf) == -1)
	    {
	      int file = open (hf, O_CREAT | O_TRUNC | O_WRONLY, 0666);
	      if (file != -1)
		close (file);
	    }

	  /* Now actually append the lines if the history hasn't been
	     stifled.  If the history has been stifled, rewrite the
	     history file. */
	  using_history ();
	  if (history_lines_this_session <= where_history ())
	    {
	      result = append_history (history_lines_this_session, hf);
	      history_lines_in_file += history_lines_this_session;
	    }
	  else
	    {
	      result = write_history (hf);
	      history_lines_in_file = history_lines_this_session;
	    }
	  history_lines_this_session = 0;
	}
    }
  return (result);
}
示例#23
0
/* Write the existing history out to the history file. */
void
save_history ()
{
  char *hf = get_string_value ("HISTFILE");

  if (hf && *hf)
    {
      struct stat buf;

      if (stat (hf, &buf) == 0)
	{
	  /* Append only the lines that occurred this session to
	     the history file. */
	  using_history ();

	  if (history_lines_this_session < where_history ())
	    append_history (history_lines_this_session, hf);
	  else
	    write_history (hf);
	}
    }
}
示例#24
0
/* Set default values for LC_CTYPE, LC_COLLATE, and LC_MESSAGES if they
   are not specified in the environment, but LANG or LC_ALL is.  This
   should be called from main() after parsing the environment. */
void
set_default_locale_vars ()
{
  char *val;

#if defined (HAVE_SETLOCALE)
  val = get_string_value ("LC_CTYPE");
  if (val == 0 && lc_all && *lc_all)
    setlocale (LC_CTYPE, lc_all);

#  if defined (LC_COLLATE)
  val = get_string_value ("LC_COLLATE");
  if (val == 0 && lc_all && *lc_all)
    setlocale (LC_COLLATE, lc_all);
#  endif /* LC_COLLATE */

#  if defined (LC_MESSAGES)
  val = get_string_value ("LC_MESSAGES");
  if (val == 0 && lc_all && *lc_all)
    setlocale (LC_MESSAGES, lc_all);
#  endif /* LC_MESSAGES */

#  if defined (LC_NUMERIC)
  val = get_string_value ("LC_NUMERIC");
  if (val == 0 && lc_all && *lc_all)
    setlocale (LC_NUMERIC, lc_all);
#  endif /* LC_NUMERIC */

#endif /* HAVE_SETLOCALE */

  val = get_string_value ("TEXTDOMAIN");
  if (val && *val)
    {
      FREE (default_domain);
      default_domain = savestring (val);
      textdomain (default_domain);
    }

  val = get_string_value ("TEXTDOMAINDIR");
  if (val && *val)
    {
      FREE (default_dir);
      default_dir = savestring (val);
      bindtextdomain (default_domain, default_dir);
    }
}
示例#25
0
void get_item_string_value(char *buf, size_t maxlen, const xmlNode *item,
	const unsigned char *name)
{
	const xmlNode *node;

	if (!item)
	{
		LOG_ERROR("Item is null!");
		buf[0] = '\0';
		return;
	}

	// look for this entry in the children
	for (node = item->children; node; node = node->next)
	{
		if (node->type == XML_ELEMENT_NODE
			&& xmlStrcasecmp(node->name, name) == 0)
		{
			get_string_value(buf, maxlen, node);
			return;
		}
	}
}
示例#26
0
int parse_mine_defs(xmlNode *node)
{
	xmlNode *def;
	mine_types * mine_def = NULL;
	char content[100] = "";
	int ok = 1;

	for (def = node->children; def; def = def->next)
	{
		if (def->type == XML_ELEMENT_NODE)
		{
			if (xmlStrcasecmp (def->name, (xmlChar*)"mine") == 0)
			{
				if (num_mine_defs >= MAX_MINE_DEFS)
				{
					LOG_ERROR("%s: Maximum mine types reached: %d", mines_config_error, MAX_MINE_DEFS);
					ok = 0;
				}
				mine_def = &mine_defs[num_mine_defs++];
				mine_def->id = get_int_property(def, "id");
				get_string_value(content, sizeof(content), def);				
				safe_strncpy(mine_def->file, content, sizeof(mine_def->file));
			}
			else
			{
				LOG_ERROR("%s: Unknown element found: %s", mines_config_error, def->name);
				ok = 0;
			}
		}
		else if (def->type == XML_ENTITY_REF_NODE)
		{
			ok &= parse_mine_defs (def->children);
		}
	}

	return ok;
}
示例#27
0
// Run function of whole program
static void run(const char *config_filename) {
	double max_z, min_z;
	source_object *object;
	double complex *optical_field;

	// Initialize FFTW threads
	fftw_init_threads();

	// Load config to memory
	load_config(config_filename);

	// Initialize logger
	initialize_logger(get_integer_value(CONF_LOGGER_DEBUG_MODE));

	// Load source object
	load_source_object(&object, get_string_value(CONF_OBJECT_POINTS_FILE));

	// Initialize final optical field
	initialize_optical_field(&optical_field);

	// Extract z position extremes of source object
	extract_object_proportions(object, &min_z, &max_z, OBJECT_DEPTH);

	// Modified WRP method itself
	perform_wrp_method(object, optical_field, min_z, max_z);

	// Numerical reconstruction on hologram
	perform_numerical_reconstruction(optical_field, min_z);

	// Memory clear
	log_info("Deleting all structures from memory\n");
	free(optical_field);
	delete_source_object(object);
	delete_lookup_table();
	delete_config();
}
int
parse_command ()
{
  int r;
  char *command_to_execute;
  need_here_doc = 0;
  run_pending_traps ();
  if (interactive && bash_input.type != st_string){
    command_to_execute = get_string_value ("PROMPT_COMMAND");
    if (command_to_execute)
      execute_variable_command (command_to_execute, "PROMPT_COMMAND");
    
    if (running_under_emacs == 2)
      send_pwd_to_eterm ();
  }
  
  current_command_line_count = 0;
  r = yyparse ();
  
  if (need_here_doc)
    gather_here_documents ();
  
  return (r);
}
示例#29
0
int parse_actor_weapon (actor_types *act, xmlNode *cfg) {
	xmlNode *item;
	char errmsg[120];
	int ok, type_idx;
	weapon_part *weapon;

	if (cfg == NULL || cfg->children == NULL) return 0;
	
	type_idx = get_property (cfg, "type", "weapon type", weapon_type_dict);
	if (type_idx < 0) return 0;
	
	weapon = &(act->weapon[type_idx]);
	ok = 1;
	for (item = cfg->children; item; item = item->next) {
		if (item->type == XML_ELEMENT_NODE) {
			if (xmlStrcasecmp (item->name, "model") == 0) {
				get_string_value (weapon->model_name, sizeof (weapon->model_name), item);
			} else if (xmlStrcasecmp (item->name, "skin") == 0) {
				get_string_value (weapon->skin_name, sizeof (weapon->skin_name), item);
			} else if (xmlStrcasecmp (item->name, "attack_up1") == 0) {
				get_string_value (weapon->attack_up1, sizeof (weapon->attack_up1), item);
			} else if (xmlStrcasecmp (item->name, "attack_up2") == 0) {
				get_string_value (weapon->attack_up2, sizeof (weapon->attack_up2), item);
			} else if (xmlStrcasecmp (item->name, "attack_down1") == 0) {
				get_string_value (weapon->attack_down1, sizeof (weapon->attack_down1), item);
			} else if (xmlStrcasecmp (item->name, "attack_down2") == 0) {
				get_string_value (weapon->attack_down2, sizeof (weapon->attack_down2), item);
			} else if (xmlStrcasecmp (item->name, "glow") == 0) {
				int mode = find_description_index (glow_mode_dict, item->children->content, "glow mode");
				if (mode < 0) mode = GLOW_NONE;
				weapon->glow = mode;
			} else {
				snprintf (errmsg, sizeof (errmsg), "unknown weapon property \"%s\"", item->name);
				LogError (errmsg);
				ok = 0;
			}
		}
	}
	
	return ok;
}
size_t
strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
{
	char *endp = s + maxsize;
	char *start = s;
	auto char tbuf[100];
	long off;
	int i, w, y;
	static short first = 1;
#ifdef POSIX_SEMANTICS
	static char *savetz = NULL;
	static int savetzlen = 0;
	char *tz;
#endif /* POSIX_SEMANTICS */
#ifndef HAVE_TM_ZONE
#ifndef HAVE_TM_NAME
#ifndef HAVE_TZNAME
	extern char *timezone();
	struct timeval tv;
	struct timezone zone;
#endif /* HAVE_TZNAME */
#endif /* HAVE_TM_NAME */
#endif /* HAVE_TM_ZONE */

	/* various tables, useful in North America */
	static const char *days_a[] = {
		"Sun", "Mon", "Tue", "Wed",
		"Thu", "Fri", "Sat",
	};
	static const char *days_l[] = {
		"Sunday", "Monday", "Tuesday", "Wednesday",
		"Thursday", "Friday", "Saturday",
	};
	static const char *months_a[] = {
		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
	};
	static const char *months_l[] = {
		"January", "February", "March", "April",
		"May", "June", "July", "August", "September",
		"October", "November", "December",
	};
	static const char *ampm[] = { "AM", "PM", };

	if (s == NULL || format == NULL || timeptr == NULL || maxsize == 0)
		return 0;

	/* quick check if we even need to bother */
	if (strchr(format, '%') == NULL && strlen(format) + 1 >= maxsize)
		return 0;

#ifndef POSIX_SEMANTICS
	if (first) {
		tzset();
		first = 0;
	}
#else	/* POSIX_SEMANTICS */
#if defined (SHELL)
	tz = get_string_value ("TZ");
#else
	tz = getenv("TZ");
#endif
	if (first) {
		if (tz != NULL) {
			int tzlen = strlen(tz);

			savetz = (char *) malloc(tzlen + 1);
			if (savetz != NULL) {
				savetzlen = tzlen + 1;
				strcpy(savetz, tz);
			}
		}
		tzset();
		first = 0;
	}
	/* if we have a saved TZ, and it is different, recapture and reset */
	if (tz && savetz && (tz[0] != savetz[0] || strcmp(tz, savetz) != 0)) {
		i = strlen(tz) + 1;
		if (i > savetzlen) {
			savetz = (char *) realloc(savetz, i);
			if (savetz) {
				savetzlen = i;
				strcpy(savetz, tz);
			}
		} else
			strcpy(savetz, tz);
		tzset();
	}
#endif	/* POSIX_SEMANTICS */

	for (; *format && s < endp - 1; format++) {
		tbuf[0] = '\0';
		if (*format != '%') {
			*s++ = *format;
			continue;
		}
	again:
		switch (*++format) {
		case '\0':
			*s++ = '%';
			goto out;

		case '%':
			*s++ = '%';
			continue;

		case 'a':	/* abbreviated weekday name */
			if (timeptr->tm_wday < 0 || timeptr->tm_wday > 6)
				strcpy(tbuf, "?");
			else
				strcpy(tbuf, days_a[timeptr->tm_wday]);
			break;

		case 'A':	/* full weekday name */
			if (timeptr->tm_wday < 0 || timeptr->tm_wday > 6)
				strcpy(tbuf, "?");
			else
				strcpy(tbuf, days_l[timeptr->tm_wday]);
			break;

		case 'b':	/* abbreviated month name */
		short_month:
			if (timeptr->tm_mon < 0 || timeptr->tm_mon > 11)
				strcpy(tbuf, "?");
			else
				strcpy(tbuf, months_a[timeptr->tm_mon]);
			break;

		case 'B':	/* full month name */
			if (timeptr->tm_mon < 0 || timeptr->tm_mon > 11)
				strcpy(tbuf, "?");
			else
				strcpy(tbuf, months_l[timeptr->tm_mon]);
			break;

		case 'c':	/* appropriate date and time representation */
			/*
			 * This used to be:
			 *
			 * strftime(tbuf, sizeof tbuf, "%a %b %e %H:%M:%S %Y", timeptr);
			 *
			 * Now, per the ISO 1999 C standard, it this:
			 */
			strftime(tbuf, sizeof tbuf, "%A %B %d %T %Y", timeptr);
			break;

		case 'C':
		century:
			sprintf(tbuf, "%02d", (timeptr->tm_year + 1900) / 100);
			break;

		case 'd':	/* day of the month, 01 - 31 */
			i = range(1, timeptr->tm_mday, 31);
			sprintf(tbuf, "%02d", i);
			break;

		case 'D':	/* date as %m/%d/%y */
			strftime(tbuf, sizeof tbuf, "%m/%d/%y", timeptr);
			break;

		case 'e':	/* day of month, blank padded */
			sprintf(tbuf, "%2d", range(1, timeptr->tm_mday, 31));
			break;

		case 'E':
			/* POSIX (now C99) locale extensions, ignored for now */
			goto again;

		case 'F':	/* ISO 8601 date representation */
			strftime(tbuf, sizeof tbuf, "%Y-%m-%d", timeptr);
			break;

		case 'g':
		case 'G':
			/*
			 * Year of ISO week.
			 *
			 * If it's December but the ISO week number is one,
			 * that week is in next year.
			 * If it's January but the ISO week number is 52 or
			 * 53, that week is in last year.
			 * Otherwise, it's this year.
			 */
			w = iso8601wknum(timeptr);
			if (timeptr->tm_mon == 11 && w == 1)
				y = 1900 + timeptr->tm_year + 1;
			else if (timeptr->tm_mon == 0 && w >= 52)
				y = 1900 + timeptr->tm_year - 1;
			else
				y = 1900 + timeptr->tm_year;

			if (*format == 'G')
				sprintf(tbuf, "%d", y);
			else
				sprintf(tbuf, "%02d", y % 100);
			break;

		case 'h':	/* abbreviated month name */
			goto short_month;

		case 'H':	/* hour, 24-hour clock, 00 - 23 */
			i = range(0, timeptr->tm_hour, 23);
			sprintf(tbuf, "%02d", i);
			break;

		case 'I':	/* hour, 12-hour clock, 01 - 12 */
			i = range(0, timeptr->tm_hour, 23);
			if (i == 0)
				i = 12;
			else if (i > 12)
				i -= 12;
			sprintf(tbuf, "%02d", i);
			break;

		case 'j':	/* day of the year, 001 - 366 */
			sprintf(tbuf, "%03d", timeptr->tm_yday + 1);
			break;

		case 'm':	/* month, 01 - 12 */
			i = range(0, timeptr->tm_mon, 11);
			sprintf(tbuf, "%02d", i + 1);
			break;

		case 'M':	/* minute, 00 - 59 */
			i = range(0, timeptr->tm_min, 59);
			sprintf(tbuf, "%02d", i);
			break;

		case 'n':	/* same as \n */
			tbuf[0] = '\n';
			tbuf[1] = '\0';
			break;

		case 'O':
			/* POSIX (now C99) locale extensions, ignored for now */
			goto again;

		case 'p':	/* am or pm based on 12-hour clock */
			i = range(0, timeptr->tm_hour, 23);
			if (i < 12)
				strcpy(tbuf, ampm[0]);
			else
				strcpy(tbuf, ampm[1]);
			break;

		case 'r':	/* time as %I:%M:%S %p */
			strftime(tbuf, sizeof tbuf, "%I:%M:%S %p", timeptr);
			break;

		case 'R':	/* time as %H:%M */
			strftime(tbuf, sizeof tbuf, "%H:%M", timeptr);
			break;

#if defined(HAVE_MKTIME) || defined(GAWK)
		case 's':	/* time as seconds since the Epoch */
		{
			struct tm non_const_timeptr;

			non_const_timeptr = *timeptr;
			sprintf(tbuf, "%ld", mktime(& non_const_timeptr));
			break;
		}
#endif /* defined(HAVE_MKTIME) || defined(GAWK) */

		case 'S':	/* second, 00 - 60 */
			i = range(0, timeptr->tm_sec, 60);
			sprintf(tbuf, "%02d", i);
			break;

		case 't':	/* same as \t */
			tbuf[0] = '\t';
			tbuf[1] = '\0';
			break;

		case 'T':	/* time as %H:%M:%S */
		the_time:
			strftime(tbuf, sizeof tbuf, "%H:%M:%S", timeptr);
			break;

		case 'u':
		/* ISO 8601: Weekday as a decimal number [1 (Monday) - 7] */
			sprintf(tbuf, "%d", timeptr->tm_wday == 0 ? 7 :
					timeptr->tm_wday);
			break;

		case 'U':	/* week of year, Sunday is first day of week */
			sprintf(tbuf, "%02d", weeknumber(timeptr, 0));
			break;

		case 'V':	/* week of year according ISO 8601 */
			sprintf(tbuf, "%02d", iso8601wknum(timeptr));
			break;

		case 'w':	/* weekday, Sunday == 0, 0 - 6 */
			i = range(0, timeptr->tm_wday, 6);
			sprintf(tbuf, "%d", i);
			break;

		case 'W':	/* week of year, Monday is first day of week */
			sprintf(tbuf, "%02d", weeknumber(timeptr, 1));
			break;

		case 'x':	/* appropriate date representation */
			strftime(tbuf, sizeof tbuf, "%A %B %d %Y", timeptr);
			break;

		case 'X':	/* appropriate time representation */
			goto the_time;
			break;

		case 'y':	/* year without a century, 00 - 99 */
		year:
			i = timeptr->tm_year % 100;
			sprintf(tbuf, "%02d", i);
			break;

		case 'Y':	/* year with century */
		fullyear:
			sprintf(tbuf, "%d", 1900 + timeptr->tm_year);
			break;

		/*
		 * From: Chip Rosenthal <*****@*****.**>
		 * Date: Sun, 19 Mar 1995 00:33:29 -0600 (CST)
		 * 
		 * Warning: the %z [code] is implemented by inspecting the
		 * timezone name conditional compile settings, and
		 * inferring a method to get timezone offsets. I've tried
		 * this code on a couple of machines, but I don't doubt
		 * there is some system out there that won't like it.
		 * Maybe the easiest thing to do would be to bracket this
		 * with an #ifdef that can turn it off. The %z feature
		 * would be an admittedly obscure one that most folks can
		 * live without, but it would be a great help to those of
		 * us that muck around with various message processors.
		 */
 		case 'z':	/* time zone offset east of GMT e.g. -0600 */
#ifdef HAVE_TM_NAME
			/*
			 * Systems with tm_name probably have tm_tzadj as
			 * secs west of GMT.  Convert to mins east of GMT.
			 */
			off = -timeptr->tm_tzadj / 60;
#else /* !HAVE_TM_NAME */
#ifdef HAVE_TM_ZONE
			/*
			 * Systems with tm_zone probably have tm_gmtoff as
			 * secs east of GMT.  Convert to mins east of GMT.
			 */
			off = timeptr->tm_gmtoff / 60;
#else /* !HAVE_TM_ZONE */
#if HAVE_TZNAME
			/*
			 * Systems with tzname[] probably have timezone as
			 * secs west of GMT.  Convert to mins east of GMT.
			 */
#  ifdef HPUX
			off = -timezone / 60;
#  else
			off = -(daylight ? timezone : altzone) / 60;
#  endif /* !HPUX */
#else /* !HAVE_TZNAME */
			gettimeofday(& tv, & zone);
			off = -zone.tz_minuteswest;
#endif /* !HAVE_TZNAME */
#endif /* !HAVE_TM_ZONE */
#endif /* !HAVE_TM_NAME */
			if (off < 0) {
				tbuf[0] = '-';
				off = -off;
			} else {
				tbuf[0] = '+';
			}
			sprintf(tbuf+1, "%02d%02d", off/60, off%60);
			break;

		case 'Z':	/* time zone name or abbrevation */
#ifdef HAVE_TZNAME
			i = (daylight && timeptr->tm_isdst > 0); /* 0 or 1 */
			strcpy(tbuf, tzname[i]);
#else
#ifdef HAVE_TM_ZONE
			strcpy(tbuf, timeptr->tm_zone);
#else
#ifdef HAVE_TM_NAME
			strcpy(tbuf, timeptr->tm_name);
#else
			gettimeofday(& tv, & zone);
			strcpy(tbuf, timezone(zone.tz_minuteswest,
						timeptr->tm_isdst > 0));
#endif /* HAVE_TM_NAME */
#endif /* HAVE_TM_ZONE */
#endif /* HAVE_TZNAME */
			break;

#ifdef SUNOS_EXT
		case 'k':	/* hour, 24-hour clock, blank pad */
			sprintf(tbuf, "%2d", range(0, timeptr->tm_hour, 23));
			break;

		case 'l':	/* hour, 12-hour clock, 1 - 12, blank pad */
			i = range(0, timeptr->tm_hour, 23);
			if (i == 0)
				i = 12;
			else if (i > 12)
				i -= 12;
			sprintf(tbuf, "%2d", i);
			break;
#endif

#ifdef HPUX_EXT
		case 'N':	/* Emperor/Era name */
			/* this is essentially the same as the century */
			goto century;	/* %C */

		case 'o':	/* Emperor/Era year */
			goto year;	/* %y */
#endif /* HPUX_EXT */


#ifdef VMS_EXT
		case 'v':	/* date as dd-bbb-YYYY */
			sprintf(tbuf, "%2d-%3.3s-%4d",
				range(1, timeptr->tm_mday, 31),
				months_a[range(0, timeptr->tm_mon, 11)],
				timeptr->tm_year + 1900);
			for (i = 3; i < 6; i++)
				if (islower(tbuf[i]))
					tbuf[i] = toupper(tbuf[i]);
			break;
#endif

		default:
			tbuf[0] = '%';
			tbuf[1] = *format;
			tbuf[2] = '\0';
			break;
		}
		i = strlen(tbuf);
		if (i) {
			if (s + i < endp - 1) {
				strcpy(s, tbuf);
				s += i;
			} else
				return 0;
		}
	}
out:
	if (s < endp && *format == '\0') {
		*s = '\0';
		return (s - start);
	} else
		return 0;
}