Пример #1
0
static void *centerMain(void *arg)
{
  int cnt;

  processlist = NULL; // processlist = empty
  cnt = 99999;        // cnt = expired
  do_reload(0);       // reload speadsheat
  while(1)
  {
    if(toCenter.poll() == rlFifo::DATA_AVAILABLE)
    {
      toCenter.read(interpreter.line,rl_PRINTF_LENGTH-1);
      if     (interpreter.isCommand("sigterm(")) do_sigterm();
      else if(interpreter.isCommand("sigkill(")) do_sigkill();
      else if(interpreter.isCommand("reload("))  do_reload(1);
      else if(interpreter.isCommand("remove("))  do_remove();
      else if(interpreter.isCommand("save("))    do_save();
      if(processes_have_been_modified)           do_save();
    }
    else if(cnt++ >= WATCHDOG_CYCLE_TIME)
    {
      cnt = 0;
      watchdog();
      if(processes_have_been_modified)           do_save();
    }
    else
    {
      rlsleep(1000); // 1 second
    }
    if(arg == NULL) return NULL; // just to fool the compiler
  }
}
Пример #2
0
int
param_main(int argc, char *argv[])
{
	if (argc >= 2) {
		if (!strcmp(argv[1], "save")) {
			if (argc >= 3) {
				do_save(argv[2]);
			} else {
				do_save(param_get_default_file());
			}
		}

		if (!strcmp(argv[1], "load")) {
			if (argc >= 3) {
				do_load(argv[2]);
			} else {
				do_load(param_get_default_file());
			}
		}

		if (!strcmp(argv[1], "import")) {
			if (argc >= 3) {
				do_import(argv[2]);
			} else {
				do_import(param_get_default_file());
			}
		}

		if (!strcmp(argv[1], "select")) {
			if (argc >= 3) {
				param_set_default_file(argv[2]);
			} else {
				param_set_default_file(NULL);
			}
			warnx("selected parameter default file %s", param_get_default_file());
			exit(0);
		}

		if (!strcmp(argv[1], "show"))
			if (argc >= 3) {
				do_show(argv[2]);
			} else {
				do_show(NULL);
			}
	}
	
	errx(1, "expected a command, try 'load', 'import', 'show', 'select' or 'save'");
}
Пример #3
0
void read_files(char *path)
{
	char buf[2048]={0};
	int count=0;
	long long all=0;
	int save=0;
	struct Files file;
	save=init_save("zhoustest.mpg");
	fd_open(&file,path);
	while(1)
    {
		count=fd_read(&file,buf,2048);
        all+=count;
        if(all>file.File_Size)
        {
            count-=4;
        }
        do_save(save,buf,count,all);
        if(count < 2048)
        {
            break;
        }
    }
    exit_save(save);
	fd_close(&file);
}
Пример #4
0
void DistributedObject::commit(const DistributedWriteLock& dist_lock, const ReadableLock& lock) const
{
	lock.check_read(get_local_mutex());

	if (!persistence_enabled_)
	{
		const_cast<DistributedObject*>(this)->timestamp_ = time(NULL);
		return;
	}

	if (&dist_lock.get_object() != this)
		throw std::runtime_error("Distributed lock has incorrect object");
	if (file_.string().empty())
		throw std::runtime_error("Distributed object has no associated file");

	try
	{
		std::ofstream file_stream(get_file().string().c_str());
		if (!file_stream)
			throw bfs::filesystem_error("open failed", get_file(), bs::error_code(errno, boost::system::posix_category));

		OutputArchive file_arch(file_stream);
		do_save(file_arch, lock);
		file_stream.flush();
		const_cast<DistributedObject*>(this)->timestamp_ = bfs::last_write_time(file_);
	}
	catch (bfs::filesystem_error& e)
	{
		throw distributed_object_error("file error: " + std::string(e.what()));
	}
	catch (boost::archive::archive_exception& e)
	{
		throw distributed_object_error("serialization error: " + std::string(e.what()));
	}
}
Пример #5
0
void Editor::load_layers() {
  layerselect.selected_tilemap = NULL;
  layerselect.layers.clear();
  bool tsel = false;
  for(auto& i : currentsector->gameobjects) {
    auto go = i.get();
    auto mo = dynamic_cast<MovingObject*>(go);
    if ( !mo && go->do_save() ) {
      layerselect.add_layer(go);

      auto tm = dynamic_cast<TileMap*>(go);
      if (tm) {
        if ( !tm->is_solid() || tsel ) {
          tm->editor_active = false;
        } else {
          layerselect.selected_tilemap = tm;
          tm->editor_active = true;
          tsel = true;
        }
      }

    }
  }

  layerselect.sort_layers();
  layerselect.refresh_sector_text();
}
Пример #6
0
Mark_mmdb::Mark_mmdb (MarkBase_mmdb &base, UAS_Pointer<UAS_Common> &doc_ptr,
		      const Anchor &anchor,
		      const char *name, const char *notes)
: f_doc_ptr (doc_ptr),
  f_anchor (anchor),
  f_mark_base (base),
  f_name (NULL),
  f_notes (NULL)
{
  // This creates a new user mark in the mmdb mark database. 

#ifdef FUJITSU_OLIAS
  // Id = bookcase id / section id
  UAS_String theId = doc_ptr->bid();
  theId = theId + "/" + doc_ptr->id();
#else
  UAS_String theId = doc_ptr->id();
#endif
  
  f_user_mark = new mark_smart_ptr (base, theId);
  set_name (name);
  set_notes (notes);

  // Flush the new mark to disk. 
  do_save();
}
Пример #7
0
/***********************************************************************
 *
 *  Procedure:
 *	Process message - examines packet types, and takes appropriate action
 *
 ***********************************************************************/
void process_message(unsigned long type,unsigned long *body)
{
  switch(type)
    {
    case M_CONFIGURE_WINDOW:
      if(!find_window(body[0]))
	add_window(body[0],body);
      break;
    case M_WINDOW_NAME:
      {
	struct list *l;
	if ((l = find_window(body[0])) != 0) {
	   l->name = (char *)safemalloc(strlen((char *)&body[3])+1);
	   strcpy(l->name,(char *)&body[3]);
	}
      }
      break;
    case M_NEW_PAGE:
      list_new_page(body);
      break;
    case M_NEW_DESK:
      CurDesk = (long)body[0];
      break;
    case M_END_WINDOWLIST:
      do_save();
      break;
    default:
      break;
    }
}
Пример #8
0
/**
 * @param [in,out] os Ссылка на поток вывода для сохранения документа
 * @param params Параметры сохранения документа
 */
inline
void
Document::save( OutStream_t & os
              , const SaveParams & params /*= default_save_params()*/
              ) const
{
    do_save( os , params );
}
Пример #9
0
/** no@@return true iff should exit */
static void do_exit(void) {
  if (dirty) {
    int i=MessageBox(hwnd_main, "Save changes before exit?", "Confirm exit",
      MB_YESNOCANCEL|MB_ICONEXCLAMATION|MB_DEFBUTTON1);
    if (i==IDCANCEL || (i==IDYES && !do_save(true))) return;
  }
  DestroyWindow(hwnd_main);
}
Пример #10
0
static void do_save_as(void) {
  char *old_filename2=filename2;
  filename2=NULL;
  do_ask_save_as();
  if (filename2!=NULL) {
    if (do_save(false)) { delete [] old_filename2; return; }
    delete [] filename2;
  }
  filename2=old_filename2;
}
Пример #11
0
/**
 * @param file_path Путь к файлу документа
 * @param params Параметры сохранения документа
 * @param loc Локализация документа
 */
inline
void
Document::save( const Path_t &      file_path
              , const SaveParams &  params /*= default_save_params()*/
              , const std::locale & loc /*= std::locale()*/
              ) const
{
    fs::ofstream ofs ( file_path );
    ofs.imbue( loc );
    do_save( ofs , params );
}
Пример #12
0
void MainWindow::on_buttonBox_clicked(QAbstractButton* button)
{
	QDialogButtonBox::StandardButton btype = ui->buttonBox->standardButton(button);

	switch(btype) {
	case QDialogButtonBox::Save:
		do_save();
		break;
	case QDialogButtonBox::Close:
		do_close();
		break;
	default:
		;
	}
}
Пример #13
0
int
param_main(int argc, char *argv[])
{
	if (argc >= 2) {
		if (!strcmp(argv[1], "save")) {
			if (argc >= 3) {
				do_save(argv[2]);
			} else {
				do_save(param_file_name_default);
			}
		}

		if (!strcmp(argv[1], "load")) {
			if (argc >= 3) {
				do_load(argv[2]);
			} else {
				do_load(param_file_name_default);
			}
		}

		if (!strcmp(argv[1], "import")) {
			if (argc >= 3) {
				do_import(argv[2]);
			} else {
				do_import(param_file_name_default);
			}
		}

		if (!strcmp(argv[1], "show")) {
			do_show();
		}
			
	}

	errx(1, "expected a command, try 'load', 'import', 'show' or 'save'\n");
}
Пример #14
0
int
param_main(int argc, char *argv[])
{
	if (argc >= 2) {
		if (!strcmp(argv[1], "save"))
			do_save();
		if (!strcmp(argv[1], "load"))
			do_load();
		if (!strcmp(argv[1], "import"))
			do_import();
		if (!strcmp(argv[1], "show"))
			do_show();
	}

	errx(1, "expected a command, try 'load', 'import', 'show' or 'save'\n");
}
Пример #15
0
/***********************************************************************
 *
 *  Procedure:
 *	Process message - examines packet types, and takes appropriate action
 *
 ***********************************************************************/
void process_message(unsigned long type,unsigned long *body)
{
  switch(type)
    {
    case M_CONFIGURE_WINDOW:
      if(!find_window(body[0]))
	add_window(body[0],body);
      break;
    case M_NEW_PAGE:
      list_new_page(body);
      break;
    case M_END_WINDOWLIST:
      do_save();
      break;
    default:
      break;
    }
}
Пример #16
0
        inline bool save(char const* buffer, std::size_t size)
        {
            if (!good()) return false;

            int deep = deep_++;
            if (!do_save(buffer, size))
            {
                state_ = archive_state::error;
                -- deep_;
                return false;
            }
            else
            {
                if (!deep)
                    acc_ = 0;
                -- deep_;
                return true;
            }
        }
Пример #17
0
        inline bool save(T const& t)
        {
            if (!good()) return false;

            int deep = deep_++;
            if (!do_save(const_cast<T&>(t)))
            {
                state_ = archive_state::error;
                -- deep_;
                return false;
            }
            else
            {
                if (!deep)
                    acc_ = 0;
                -- deep_;
                return true;
            }
        }
Пример #18
0
int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
		  struct sockaddr *from)
{

	if (!check_len(conn, a, data, len, from))
		return 0;


	mbag_t itemstore;
///	if (!a->target)
		itemstore = conn->incomming;
//	else
//		itemstore = a->target(conn, a);


	return do_save(itemstore, conn, a, data, len, from);



}
Пример #19
0
void do_email( CHAR_DATA * ch, char * argument )
{
    /* interface for setting up email addresses */
    char arg1[MSL];
    char arg2[MSL];
    char outbuf[MSL];
    char catbuf[MSL];
    bool valid_email = FALSE;

    if ( IS_NPC( ch ) )
        return;
    argument = one_argument( argument, arg1 );
    if ( arg1[0] == '\0' )
    {
        sprintf( outbuf, "%s", "Syntax for email:\n\r" );
        sprintf( catbuf, "%s",
            "set <email address>\n\r" );
        safe_strcat( MSL, outbuf, catbuf );
        if ( ch->pcdata->valid_email )
        {
            sprintf( catbuf, "Your email address is currently set to %s.\n\r",
                ch->pcdata->email_address );
            safe_strcat( MSL, outbuf, catbuf );
        }
        else
        {
            if ( !str_cmp( ch->pcdata->email_address, "not set" ) )
                safe_strcat(MSL, outbuf, "Your email address has not been set.\n\r" );
            else
            {
                sprintf( catbuf, "Your email address has been set to %s, but has not been authorized by an Implementor.\n\r",
                    ch->pcdata->email_address );
                safe_strcat( MSL, outbuf, catbuf );
            }
        }
        send_to_char( outbuf, ch );
        return;
    }

    argument = one_argument( argument, arg2 );
    if ( arg2[0] == '\0' )
    {
        do_email( ch, "" );
        return;
    }
    if ( !str_cmp( arg1, "set" ) )
    {
        valid_email = valid_email_addy( arg2 );
        if ( valid_email )
        {
            free_string( ch->pcdata->email_address );
            ch->pcdata->email_address = str_dup( arg2 );
            ch->pcdata->valid_email = TRUE;
            do_save( ch, "" );
            sprintf( outbuf,
                "Your email address has been set to %s.\n\r",
                ch->pcdata->email_address );
            send_to_char( outbuf, ch );
            return;
        }
        else
        {
            sprintf( outbuf, "%s is not an acceptable email address.\n\r",
                arg2 );
            send_to_char( outbuf, ch );
            return;
        }
    }
    /*  if ( !str_cmp( arg1, "validate" ) )
      {

        if ( get_trust( ch ) < MAX_LEVEL )
        {
          send_to_char( "Only Implementors may use this command.\n\r", ch );
          return;
        }
        else
        {
          CHAR_DATA *victim;
          DESCRIPTOR_DATA d;
          BRAND_DATA * brand;
          DL_LIST * brand_list;

          bool logged_in = FALSE;
          if ( arg2[0] == '\0' )
          {
            send_to_char( "Authorize email for whom?\n\r", ch );
            return;
          }

          if ( ( victim = get_char_world( ch, arg2 ) ) == NULL )
          {
            bool found = FALSE;
            found = load_char_obj( &d, arg2, TRUE );

            if (!found)
            {
              char    buf[MSL];
              sprintf( buf, "No pFile found for '%s'.\n\r", capitalize( arg2 ) );
              send_to_char( buf, ch );
              free_char( d.character );
              return;
            }

            victim = d.character;
            d.character = NULL;
            victim->desc = NULL;
            LINK( victim, first_char, last_char, next, prev );
          }
          else
          {
            logged_in = TRUE;
          }

          victim->pcdata->valid_email = TRUE;
          send_to_char( "OK.\n\r", ch );

          for ( brand_list = first_brand;
                brand_list;
                brand_list = brand_list->next )
          {
            brand = brand_list->this_one;
            if (  ( !str_cmp( brand->branded, victim->name ) )
               && ( !str_cmp( brand->priority, "Email Validation" ) )  )
              break;
          }
          if ( brand_list != NULL )
          {
            UNLINK( brand_list, first_brand, last_brand, next, prev );
            brand = brand_list->this_one;
            PUT_FREE(brand, brand_data_free);
            brand_list->this_one = NULL;
            PUT_FREE( brand_list, dl_list_free );
            save_brands( );
          }
          if ( !logged_in )
            do_quit( victim, "" );

          return;
        }
      } */
    do_email( ch, "" );
    return;
}
Пример #20
0
int
param_main(int argc, char *argv[])
{
	if (argc >= 2) {
		if (!strcmp(argv[1], "save")) {
			if (argc >= 3) {
				do_save(argv[2]);
			} else {
				if (param_save_default()) {
					warnx("Param export failed.");
					exit(1);
				} else {
					exit(0);
				}
			}
		}

		if (!strcmp(argv[1], "load")) {
			if (argc >= 3) {
				do_load(argv[2]);
			} else {
				do_load(param_get_default_file());
			}
		}

		if (!strcmp(argv[1], "import")) {
			if (argc >= 3) {
				do_import(argv[2]);
			} else {
				do_import(param_get_default_file());
			}
		}

		if (!strcmp(argv[1], "select")) {
			if (argc >= 3) {
				param_set_default_file(argv[2]);
			} else {
				param_set_default_file(NULL);
			}
			warnx("selected parameter default file %s", param_get_default_file());
			exit(0);
		}

		if (!strcmp(argv[1], "show")) {
			if (argc >= 3) {
				do_show(argv[2]);
			} else {
				do_show(NULL);
			}
		}

		if (!strcmp(argv[1], "set")) {
			if (argc >= 4) {
				do_set(argv[2], argv[3]);
			} else {
				errx(1, "not enough arguments.\nTry 'param set PARAM_NAME 3'");
			}
		}

		if (!strcmp(argv[1], "compare")) {
			if (argc >= 4) {
				do_compare(argv[2], &argv[3], argc - 3);
			} else {
				errx(1, "not enough arguments.\nTry 'param compare PARAM_NAME 3'");
			}
		}
	}
	
	errx(1, "expected a command, try 'load', 'import', 'show', 'set', 'compare', 'select' or 'save'");
}
Пример #21
0
void handle_menu_choice(eMenu item_hit) {
	std::string dialogToShow;
	sf::Event dummyEvent = {sf::Event::KeyPressed};
	short i, choice;
	
	switch(item_hit) {
		case eMenu::NONE: break;
		case eMenu::FILE_OPEN:
			do_load();
			break;
		case eMenu::FILE_SAVE:
			do_save(0);
			break;
		case eMenu::FILE_SAVE_AS:
			do_save(1);
			break;
		case eMenu::FILE_NEW:
			if(overall_mode != MODE_STARTUP) {
				std::string choice = cChoiceDlog("restart-game",{"okay","cancel"}).show();
				if(choice == "cancel")
					return;
				for(i = 0; i < 6; i++)
					univ.party[i].main_status = eMainStatus::ABSENT;
				party_in_memory = false;
				reload_startup();
				overall_mode = MODE_STARTUP;
				draw_startup(0);
			}
			start_new_game();
			draw_startup(0);
			menu_activate();
			break;
		case eMenu::FILE_ABORT:
			if(overall_mode != MODE_STARTUP) {
				std::string choice = cChoiceDlog("abort-game",{"okay","cancel"}).show();
				if (choice=="cancel") return;
				reload_startup();
				overall_mode = MODE_STARTUP;
			}
			party_in_memory = false;
			draw_startup(0);
			menu_activate();
			break;
		case eMenu::PREFS:
			pick_preferences();
			break;
		case eMenu::QUIT:
			if(overall_mode == MODE_STARTUP) {
				if(party_in_memory) {
					std::string choice = cChoiceDlog("quit-confirm-save", {"save","quit","cancel"}).show();
					if(choice == "cancel") break;
					if(choice == "save") {
						fs::path file = nav_put_party();
						if(!file.empty()) break;
						save_party(file, univ);
					}
				}
				All_Done = true;
				break;
			}
			if(overall_mode > MODE_TOWN) {
				std::string choice = cChoiceDlog("quit-confirm-nosave",{"quit","cancel"}).show();
				if(choice == "cancel")
					return;
			}
			else {
				std::string choice = cChoiceDlog("quit-confirm-save",{"quit","save","cancel"}).show();
				if(choice == "cancel")
					break;
				if(choice == "save") {
					if(univ.file.empty()) {
						univ.file = nav_put_party();
						if(univ.file.empty()) break;
					}
					save_party(univ.file, univ);
				}
			}
			All_Done = true;
			break;
		case eMenu::OPTIONS_PC_GRAPHIC:
			choice = char_select_pc(1,"New graphic for who?");
			if(choice < 6)
				pick_pc_graphic(choice,1,nullptr);
			draw_terrain();
			break;
			
		case eMenu::OPTIONS_DELETE_PC:
			if(!prime_time()) {
				ASB("Finish what you're doing first.");
				print_buf();
			}
			else {
				choice = char_select_pc(1,"Delete who?");
				if(choice < 6) {
					std::string confirm = cChoiceDlog("delete-pc-confirm",{"yes","no"}).show();
					if(confirm == "yes")
						kill_pc(univ.party[choice],eMainStatus::ABSENT);
				}
				draw_terrain();
			}
			break;
			
			
		case eMenu::OPTIONS_RENAME_PC:
			choice = char_select_pc(1,"Rename who?");
			if(choice < 6)
				pick_pc_name(choice,nullptr);
			put_pc_screen();
			put_item_screen(stat_window);
			break;
			
			
		case eMenu::OPTIONS_NEW_PC:
			if(!(is_town())) {
				add_string_to_buf("Add PC: Town mode only.");
				print_buf();
				break;
			}
			for(i = 0; i < 6; i++)
				if(univ.party[i].main_status == eMainStatus::ABSENT)
					i = 20;
			if(i == 6) {
				ASB("Add PC: You already have 6 PCs.");
				print_buf();
				break;
			}
			if(univ.town->has_tavern) {
				give_help(56,0);
				create_pc(6,nullptr);
			} else {
				add_string_to_buf("Add PC: You cannot add new characters in this town. Try in the town you started in.", 2);
			}
			print_buf();
			put_pc_screen();
			put_item_screen(stat_window);
			break;
			
		case eMenu::OPTIONS_JOURNAL:
			journal();
			break;
		case eMenu::OPTIONS_TALK_NOTES:
			if(overall_mode == MODE_TALKING) {
				ASB("Talking notes: Can't read while talking.");
				print_buf();
				return;
			}
			talk_notes();
			break;
		case eMenu::OPTIONS_ENCOUNTER_NOTES:
			adventure_notes();
			break;
		case eMenu::OPTIONS_STATS:
			if(overall_mode != MODE_STARTUP)
				print_party_stats();
			break;
		case eMenu::HELP_OUT:
			dialogToShow = "help-outdoor";
			break;
		case eMenu::HELP_TOWN:
			dialogToShow = "help-town";
			break;
		case eMenu::HELP_COMBAT:
			dialogToShow = "help-combat";
			break;
		case eMenu::HELP_BARRIER:
			dialogToShow = "help-fields";
			break;
		case eMenu::HELP_HINTS:
			dialogToShow = "help-hints";
			break;
		case eMenu::HELP_SPELLS:
			dialogToShow = "help-magic";
			break;
		case eMenu::ABOUT:
			dialogToShow = "about-boe";
			break;
		case eMenu::LIBRARY_MAGE:
			display_spells(eSkill::MAGE_SPELLS,100,0);
			break;
		case eMenu::LIBRARY_PRIEST:
			display_spells(eSkill::PRIEST_SPELLS,100,0);
			break;
		case eMenu::LIBRARY_SKILLS:
			display_skills(eSkill::INVALID,0);
			break;
		case eMenu::LIBRARY_ALCHEMY:
			// TODO: Create a dedicated dialog for alchemy info
			display_alchemy();
			break;
		case eMenu::LIBRARY_TIPS:
			tip_of_day();
			break;
		case eMenu::LIBRARY_INTRO:
			dialogToShow = "welcome";
			break;
		case eMenu::ACTIONS_ALCHEMY:
			dummyEvent.key.code = sf::Keyboard::A;
			dummyEvent.key.shift = true;
			handle_keystroke(dummyEvent);
			break;
		case eMenu::ACTIONS_WAIT:
			dummyEvent.key.code = sf::Keyboard::W;
			handle_keystroke(dummyEvent);
			break;
		case eMenu::ACTIONS_AUTOMAP:
			if(!prime_time()) {
				ASB("Finish what you're doing first.");
				print_buf();
			}
			else {
				give_help(62,0);
				display_map();
			}
			make_cursor_sword();
			break;
		case eMenu::HELP_TOC:
			if(fs::is_directory(progDir/"doc"))
				launchURL("file://" + (progDir/"doc/game/Contents.html").string());
			else launchURL("https://blades.calref.net/doc/game/Contents.html");
			break;
		case eMenu::ABOUT_MAGE:
		case eMenu::ABOUT_PRIEST:
			give_help(209,0);
			break;
		case eMenu::ABOUT_MONSTERS:
			give_help(212,0);
			break;
	}
	if(!dialogToShow.empty()) {
		cChoiceDlog dlog(dialogToShow);
		dlog.show();
	}
}
Пример #22
0
static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc,
			   char * const argv[])
{
	return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
}
Пример #23
0
Файл: chx.c Проект: mischasan/hx
//--------------|---------------------------------------------
int
main(int argc, char **argv)
{
    int     ret = 0;
    int     opt;
    int     timed = 0;
    char    cmd[10240];

    while (0 < (opt = getopt(argc, argv, "?c:dmp:s:tv-"))) {
        switch (opt) {

        case '?':
            help();
            break;
        case 'c':
            hxcrash = atoi(optarg);
            break;
        case 'd':
            ++hxdebug;
            break;
        case 'm':
            mmode |= HX_MMAP;
            break;
        case 's':
            mmode |= HX_FSYNC;
            break;
        case 't':
            timed++;
            break;
        case 'v':
            ++verbose;
            break;
        }
    }

    argc -= optind;
    argv += optind;

    setvbuf(stdout, NULL, _IOLBF, 0);
    setvbuf(stderr, NULL, _IOLBF, 0);
    errno = 0;                  //setvbuf sets errno !?

    int     size = 0;
    HXMODE  mode;
    HXFILE *hp = NULL;
    FILE   *fp = NULL;

    if (!*argv)
        die("See 'chx help' for usage");
    if (*argv[0] == '?' || !strcmp(argv[0], "help"))
        help();

    double  tstart = tick();

    if (hxdebug)
        hxtime = tstart;
    if (!strcmp(argv[0], "build")) {

        hp = do_hxopen("build", argv[1], HX_UPDATE);
        fp = do_fopen("build", argv[2], "r");
        int     memsize = argc > 3 ? atoi(argv[3]) : 1;
        int     inpsize = argc > 4 ? atoi(argv[4]) : 0;

        memsize <<= 20;
        is_hxret("build", hxbuild(hp, fp, memsize, inpsize));

    } else if (!strcmp(argv[0], "check")) {
        char   *udata = argc > 3 ? argv[3] : NULL;

        if (argc < 2)
            die("%s: requires filename [pgsize [udata]]", argv[0]);
        if (argc > 2 && !sscanf(argv[2], "%d", &size))
            die("%s: invalid pgsize", argv[2]);

        hp = do_hxopen("check", argv[1], HX_CHECK);
        mode = hxfix(hp, NULL, size, udata, udata ? strlen(udata) : 0);
        if (verbose || mode != HX_UPDATE)
            printf("%s %s\n", hxmode(mode), errno ? strerror(errno) : "");
        ret = mode != HX_UPDATE;

    } else if (!strcmp(argv[0], "create")) {

        if (argc < 3 || !sscanf(argv[2], "%d", &size))
            die("create: requires filename, pgsize, type");

        char const *type = argv[3] ? argv[3] : "";

        is_hxret("create", hxcreate(argv[1], 0644, size, type, strlen(type)));

        hp = do_hxopen("create", argv[1], HX_RECOVER);

    } else if (!strcmp(argv[0], "del")) {

        hp = do_hxopen("del", argv[1], HX_UPDATE);
        fp = do_fopen("del", argv[2], "r");
        del(hp, fp);

    } else if (!strcmp(argv[0], "dump")) {

        hp = do_hxopen("dump", argv[1], HX_READ);
        dump(hp, stdout);

    } else if (!strcmp(argv[0], "fix") || !strcmp(argv[0], "repair")) {
        char   *udata = argc > 3 ? argv[3] : NULL;

        if (argc < 2)
            die("%s: requires filename [pgsize [udata]]", argv[0]);

        if (argv[2] && !sscanf(argv[2], "%d", &size))
            die("%s: invalid pgsize", argv[2]);

        hp = do_hxopen("repair", argv[1], HX_UPDATE);
        fp = tmpfile();
        mode = hxfix(hp, fp, size, udata, udata ? strlen(udata) : 0);
        if (verbose || mode != HX_UPDATE)
            printf("%s %s\n", hxmode(mode), errno ? strerror(errno) : "");
        ret = mode != HX_UPDATE;

    } else if (!strcmp(argv[0], "hdrs")) {

        hp = do_hxopen("hdrs", argv[1], HX_READ);
        fp = do_fopen("hdrs", argv[2], "w");
        hdrs(hp);

    } else if (!strcmp(argv[0], "info")) {

        hp = do_hxopen("info", argv[1], HX_READ);
        info(hp);

    } else if (!strcmp(argv[0], "load")) {

        hp = do_hxopen("load", argv[1], HX_UPDATE);
        fp = do_fopen("hdrs", argv[2], "r");
        do_load(hp, fp);

    } else if (!strcmp(argv[0], "lock")) {

        hp = do_hxopen("lock", argv[1], HX_READ);
        do_lock(hp);

    } else if (!strcmp(argv[0], "maps")) {

        hp = do_hxopen("maps", argv[1], HX_READ);
        is_hxret("maps", maps(hp));

    } else if (!strcmp(argv[0], "pack")) {

        hp = do_hxopen("load", argv[1], HX_UPDATE);
        is_hxret("pack", hxpack(hp));

    } else if (!strcmp(argv[0], "save")) {

        hp = do_hxopen("save", argv[1], HX_READ);
        fp = do_fopen("save", argv[2], "w");
        do_save(hp, fp);

    } else if (!strcmp(argv[0], "shape")) {
        double  density;

        if (argc != 3 || !sscanf(argv[2], "%lf", &density))
            die("%s: requires density arg (0 to 1.0)", argv[2]);

        hp = do_hxopen("shape", argv[1], HX_UPDATE);
        is_hxret("shape", hxshape(hp, density));

    } else if (!strcmp(argv[0], "stat")) {

        hp = do_hxopen("stat", argv[1], HX_READ);
        stats(hp);

    } else if (!strcmp(argv[0], "types")) {
        // for each dir in LD_LIBRARY_PATH (and "" -> ".") then /lib then /usr/lib,
        //  find all files of the form "<dir>/hx_<rectype>.so"
        //      and build a file of unique rectypes.
        // Then call hxlib which returns an exact path and a bitmask of DIFF/LOAD/TEST
        //  "type diff-load-test path"
        // If the path matches, print the entry.

        types(getenv("LD_LIBRARY_PATH"));
        types("lib:/usr/lib");
    } else {

        die("%s: unknown command. See 'chx help'", cmd);
    }

    if (fp)
        fclose(fp);
    if (hp)
        hxclose(hp);
    if (timed)
        fprintf(stderr, "# chx %s: %.3f secs\n", *argv, tick() - tstart);

    return ret;
}
Пример #24
0
Sint32 vbutton::do_call(Sint32 whatfunc, Sint32 arg)
{
	switch (whatfunc)
	{
		case BEGINMENU:
			return beginmenu(arg);
		case CREATE_TEAM_MENU:
			return create_team_menu(arg);
		case SET_PLAYER_MODE:
			return set_player_mode(arg);
		case QUIT_MENU:
			quit(arg);
			return 1;
		case CREATE_VIEW_MENU:
			return create_view_menu(arg);
		case CREATE_EDIT_MENU:
			return create_edit_menu(arg);
		case CREATE_BUY_MENU:
			return create_buy_menu(arg);
		case CREATE_LOAD_MENU:
			return create_load_menu(arg);
		case CREATE_SAVE_MENU:
			return create_save_menu(arg);
		case GO_MENU:
			return go_menu(arg);
		case RETURN_MENU:
			return arg;
		case CYCLE_TEAM_GUY:
			return cycle_team_guy(arg);
		case DECREASE_STAT:
			return decrease_stat(arg);
		case INCREASE_STAT:
			return increase_stat(arg);
		case EDIT_GUY:
			return edit_guy(arg);
		case CYCLE_GUY:
			return cycle_guy(arg);
		case ADD_GUY:
			return add_guy(arg);
		case DO_SAVE:
			return do_save(arg);
		case DO_LOAD:
			return do_load(arg);
		case NAME_GUY: // name some guy
			return name_guy(arg);
		case CREATE_DETAIL_MENU:
			return create_detail_menu(NULL);
		case DO_SET_SCEN_LEVEL:
			return do_set_scen_level(arg);
		case SET_DIFFICULTY:
			return set_difficulty();
		case CHANGE_TEAM:
			return change_teamnum(arg);
		case CHANGE_HIRE_TEAM:
			return change_hire_teamnum(arg);
		case ALLIED_MODE:
			return change_allied();
		case YES_OR_NO:
			return yes_or_no(arg);
		default:
			return 4;
	}
}
Пример #25
0
turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg)
{
	// the simple wesnothserver implementation in wesnoth was removed years ago.
	assert(cfg.all_children_count() == 1);
	assert(cfg.attribute_range().first == cfg.attribute_range().second);
	if(!resources::recorder->at_end())
	{
		ERR_NW << "processing network data while still having data on the replay." << std::endl;
	}

	if (const config &msg = cfg.child("message"))
	{
		resources::screen->get_chat_manager().add_chat_message(time(nullptr), msg["sender"], msg["side"],
				msg["message"], events::chat_handler::MESSAGE_PUBLIC,
				preferences::message_bell());
	}
	else if (const config &msg = cfg.child("whisper") /*&& is_observer()*/)
	{
		resources::screen->get_chat_manager().add_chat_message(time(nullptr), "whisper: " + msg["sender"].str(), 0,
				msg["message"], events::chat_handler::MESSAGE_PRIVATE,
				preferences::message_bell());
	}
	else if (const config &ob = cfg.child("observer") )
	{
		resources::screen->get_chat_manager().add_observer(ob["name"]);
	}
	else if (const config &ob = cfg.child("observer_quit"))
	{
		resources::screen->get_chat_manager().remove_observer(ob["name"]);
	}
	else if (cfg.child("leave_game")) {
		throw ingame_wesnothd_error("");
	}
	else if (const config &turn = cfg.child("turn"))
	{
		return handle_turn(turn);
	}
	else if (cfg.has_child("whiteboard"))
	{
		resources::whiteboard->process_network_data(cfg);
	}
	else if (const config &change = cfg.child("change_controller"))
	{
		if(change.empty()) {
			ERR_NW << "Bad [change_controller] signal from server, [change_controller] tag was empty." << std::endl;
			return PROCESS_CONTINUE;
		}

		const int side = change["side"].to_int();
		const bool is_local = change["is_local"].to_bool();
		const std::string player = change["player"];
		const size_t index = side - 1;
		if(index >= resources::gameboard->teams().size()) {
			ERR_NW << "Bad [change_controller] signal from server, side out of bounds: " << change.debug() << std::endl;
			return PROCESS_CONTINUE;
		}

		const team & tm = resources::gameboard->teams().at(index);
		const bool was_local = tm.is_local();

		resources::gameboard->side_change_controller(side, is_local, player);

		if (!was_local && tm.is_local()) {
			resources::controller->on_not_observer();
		}

		if (resources::gameboard->is_observer() || (resources::gameboard->teams())[resources::screen->playing_team()].is_local_human()) {
			resources::screen->set_team(resources::screen->playing_team());
			resources::screen->redraw_everything();
			resources::screen->recalculate_minimap();
		} else if (tm.is_local_human()) {
			resources::screen->set_team(side - 1);
			resources::screen->redraw_everything();
			resources::screen->recalculate_minimap();
		}

		resources::whiteboard->on_change_controller(side,tm);

		resources::screen->labels().recalculate_labels();

		const bool restart = resources::screen->playing_side() == side && (was_local || tm.is_local());
		return restart ? PROCESS_RESTART_TURN : PROCESS_CONTINUE;
	}

	else if (const config &side_drop_c = cfg.child("side_drop"))
	{
		const int  side_drop = side_drop_c["side_num"].to_int(0);
		size_t index = side_drop -1;

		bool restart = side_drop == resources::screen->playing_side();

		if (index >= resources::teams->size()) {
			ERR_NW << "unknown side " << side_drop << " is dropping game" << std::endl;
			throw ingame_wesnothd_error("");
		}

		team::CONTROLLER ctrl;
		if(!ctrl.parse(side_drop_c["controller"])) {
			ERR_NW << "unknown controller type issued from server on side drop: " << side_drop_c["controller"] << std::endl;
			throw ingame_wesnothd_error("");
		}
		
		if (ctrl == team::CONTROLLER::AI) {
			resources::gameboard->side_drop_to(side_drop, ctrl);
			return restart ? PROCESS_RESTART_TURN:PROCESS_CONTINUE;
		}
		//null controlled side cannot be dropped becasue they aren't controlled by anyone.
		else if (ctrl != team::CONTROLLER::HUMAN) {
			ERR_NW << "unknown controller type issued from server on side drop: " << ctrl.to_cstring() << std::endl;
			throw ingame_wesnothd_error("");
		}

		int action = 0;
		int first_observer_option_idx = 0;
		int control_change_options = 0;
		bool has_next_scenario = !resources::gamedata->next_scenario().empty() && resources::gamedata->next_scenario() != "null";

		std::vector<std::string> observers;
		std::vector<const team *> allies;
		std::vector<std::string> options;

		const team &tm = resources::gameboard->teams()[index];

		for (const team &t : resources::gameboard->teams()) {
			if (!t.is_enemy(side_drop) && !t.is_local_human() && !t.is_local_ai() && !t.is_network_ai() && !t.is_empty()
				&& t.current_player() != tm.current_player()) {
				allies.push_back(&t);
			}
		}

		// We want to give host chance to decide what to do for side
		if (!resources::controller->is_linger_mode() || has_next_scenario) {
			utils::string_map t_vars;

			//get all allies in as options to transfer control
			for (const team *t : allies) {
				//if this is an ally of the dropping side and it is not us (choose local player
				//if you want that) and not ai or empty and if it is not the dropping side itself,
				//get this team in as well
				t_vars["player"] = t->current_player();
				options.push_back(vgettext("Give control to their ally $player", t_vars));
				control_change_options++;
			}

			first_observer_option_idx = options.size();

			//get all observers in as options to transfer control
			for (const std::string &ob : resources::screen->observers()) {
				t_vars["player"] = ob;
				options.push_back(vgettext("Give control to observer $player", t_vars));
				observers.push_back(ob);
				control_change_options++;
			}

			options.push_back(_("Replace with AI"));
			options.push_back(_("Replace with local player"));
			options.push_back(_("Set side to idle"));
			options.push_back(_("Save and abort game"));

			t_vars["player"] = tm.current_player();
			const std::string msg =  vgettext("$player has left the game. What do you want to do?", t_vars);
			gui2::tsimple_item_selector dlg("", msg, options);
			dlg.set_single_button(true);
			dlg.show(resources::screen->video());
			action = dlg.selected_index();

			// If esc was pressed, default to setting side to idle
			if (action == -1) {
				action = control_change_options + 2;
			}
		} else {
			// Always set leaving side to idle if in linger mode and there is no next scenario
			action = 2;
		}

		if (action < control_change_options) {
			// Grant control to selected ally
			
			{
				// Server thinks this side is ours now so in case of error transferring side we have to make local state to same as what server thinks it is.
				resources::gameboard->side_drop_to(side_drop, team::CONTROLLER::HUMAN, team::PROXY_CONTROLLER::PROXY_IDLE);
			}

			if (action < first_observer_option_idx) {
				change_side_controller(side_drop, allies[action]->current_player());
			} else {
				change_side_controller(side_drop, observers[action - first_observer_option_idx]);
			}

			return restart ? PROCESS_RESTART_TURN : PROCESS_CONTINUE;
		} else {
			action -= control_change_options;

			//make the player an AI, and redo this turn, in case
			//it was the current player's team who has just changed into
			//an AI.
			switch(action) {
				case 0:
					resources::controller->on_not_observer();
					resources::gameboard->side_drop_to(side_drop, team::CONTROLLER::HUMAN, team::PROXY_CONTROLLER::PROXY_AI);

					return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;

				case 1:
					resources::controller->on_not_observer();
					resources::gameboard->side_drop_to(side_drop, team::CONTROLLER::HUMAN, team::PROXY_CONTROLLER::PROXY_HUMAN);

					return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;
				case 2:
					resources::gameboard->side_drop_to(side_drop, team::CONTROLLER::HUMAN, team::PROXY_CONTROLLER::PROXY_IDLE);

					return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;

				case 3:
					//The user pressed "end game". Don't throw a network error here or he will get
					//thrown back to the title screen.
					do_save();
					throw_quit_game_exception();
				default:
					break;
			}
		}
	}

	// The host has ended linger mode in a campaign -> enable the "End scenario" button
	// and tell we did get the notification.
	else if (cfg.child("notify_next_scenario")) {
		gui::button* btn_end = resources::screen->find_action_button("button-endturn");
		if(btn_end) {
			btn_end->enable(true);
		}
		return PROCESS_END_LINGER;
	}

	//If this client becomes the new host, notify the play_controller object about it
	else if (cfg.child("host_transfer")){
		host_transfer_.notify_observers();
	}
	else
	{
		ERR_NW << "found unknown command:\n" << cfg.debug() << std::endl;
	}

	return PROCESS_CONTINUE;
}
Пример #26
0
Boolean handle_menu (short item, HMENU)
{
    short choice,i;
    POINT x = {1001,0},pass_point;
    Boolean to_return = false;

    switch (item) {
    case 1:  // File Menu
        if (in_startup_mode == true) startup_load();
        else do_load();
        break;
    case 2:
        do_save(0);
        break;
    case 3:
        if (in_startup_mode == true) save_file(1);
        else do_save(1);
        break;
    case 4:
        if (in_startup_mode == false)
        {
            choice = FCD(1091,0);
            if (choice == 1) return false;
            for (i = 0; i < 6; i++)
                adven[i].main_status = MAIN_STATUS_ABSENT;
            party_in_memory = false;
            reload_startup();
            in_startup_mode = true;
            draw_startup(0);
        }
        start_new_game();
        draw_startup(0);
        break;
    case 6:
        pick_preferences();
        break;
    case 7:
        pick_compatibility();
        break;
    case 8:  // Quit
        if (in_startup_mode == true) {
            to_return = All_Done = true;
            break;
        }
        if (overall_mode > MODE_TOWN) {
            choice = FCD(1067,0);
            if (choice == 1) return All_Done;
        }
        else {
            choice = FCD(1066,0);
            if (choice == 3)
                break;
            if (choice == 1)
                save_file(0);
        }
        to_return = All_Done = true;
        break;

    // Options menu
    case 21:
        choice = char_select_pc(0,0,"New graphic for who?");
        if (choice < 6)
            pick_pc_graphic(choice,1,0);
        initiate_redraw();
        break;

    case 22:
        choice = select_pc(0,0);
        if (choice < 6)
            pick_pc_name(choice,0);
        put_pc_screen();
        put_item_screen(stat_window,0);
        break;


    case 23:
        if (!(is_town())) {
            add_string_to_buf("Add PC: Town mode only.");
            print_buf();
            break;
        }
        for (i = 0; i < NUM_OF_PCS; i++)
            if (adven[i].main_status == MAIN_STATUS_ABSENT)
                i = 20;
        if (i == INVALID_PC) {
            ASB("Add PC: You already have 6 PCs.");
            print_buf();
        }
        if (c_town.town_num == scenario.which_town_start) {
            give_help(56,0,0);
            create_pc(6,0);
        }
        else {
            add_string_to_buf("Add PC: You can only make new");
            add_string_to_buf("  characters in the town you ");
            add_string_to_buf("  started in.");
        }
        print_buf();
        put_pc_screen();
        put_item_screen(stat_window,0);
        break;

    case 24:
        if (prime_time() == false) {
            ASB("Finish what you're doing first.");
            print_buf();
        }
        else {
            choice = char_select_pc(0,0,"Delete who?");
            if (choice < 6) {
                if ((i = FCD(1053,0)) == 2)
                    adven[choice].kill(0);
            }
            initiate_redraw();
        }
        break;

    case 27:
        if (overall_mode == MODE_TALKING) {
            ASB("Talking notes: Can't read while talking.");
            print_buf();
            return to_return;
        }
        talk_notes();
        break;
    case 28:
        adventure_notes();
        break;
    case 29:
        if (in_startup_mode == false) print_party_stats();
        break;

    // Help menu
    case 41:
        FCD(1079,0);
        break;
    case 42:
        FCD(1080,0);
        break;
    case 43:
        FCD(1081,0);
        break;
    case 44:
        FCD(1072,0);
        break; // magic barriers
    case 46:
        FCD(1084,0);
        break;
    case 47:
        FCD(1088,0);
        break;

    // Library
    case 61:
        display_spells(0,100,0);
        break;
    case 62:
        display_spells(1,100,0);
        break;
    case 63:
        display_skills(100,0);
        break;
    case 64:
        display_help(0,0);
        break;
    case 65:
        tip_of_day();
        break;
    case 67:
        FCD(986,0);
        break;

    // Actions
    case 81:
        if (overall_mode != MODE_TOWN) {
            ASB("Alchemy: In town mode only.");
            print_buf();
            break;
        }
        pass_point.x = 1000;
        pass_point.y = 405;
        to_return = handle_action(pass_point,(WPARAM) 0,(LPARAM)-1);
        break;
    case 82:
        to_return = handle_action(x,(WPARAM) 0,(LPARAM)-1);
        break;
    case 84:
        if (prime_time() == false) {
            ASB("Finish what you're doing first.");
            print_buf();
        }
        else {
            give_help(62,0,0);
            display_map();
        }
        SetCursor(sword_curs);
        break;

    // Mage is 399
    case 399:
        give_help(209,0,0);
        party.help_received[9] = false;
        break;

    // Priest is 499
    case 499:
        give_help(209,0,0);
        party.help_received[9] = false;
        break;

    // Monsters is 599
    case 599:
        give_help(212,0,0);
        break;

    case 100: // Index
        WinHelp(mainPtr,"Blades of Exile.hlp",HELP_CONTENTS,0L);
        break;

    case 200: // About
        FCD(1062,0);
        break;

    default:
        if ((item >= 400) && (item < 500))  { // mage spell
            if (prime_time() == false) {
                ASB("Finish what you're doing first.");
                print_buf();
            }
            else handle_menu_spell(item - 400,0);
            break;
        }
        if ((item >= 500) && (item < 600))  { // priest spell
            if (prime_time() == false) {
                ASB("Finish what you're doing first.");
                print_buf();
            }
            else handle_menu_spell(item - 500,1);
            break;
        }
        if ((item >= 600) && (item < 700))  { // monster spell
            display_monst(item - 600,(creature_data_type *) NULL,1);
            break;
        }
        break;
    }
    if (in_startup_mode == true)
        menu_activate(0);
    else menu_activate(1);
    return to_return;
}
Пример #27
0
int
param_main(int argc, char *argv[])
{
	if (argc >= 2) {
		if (!strcmp(argv[1], "save")) {
			if (argc >= 3) {
				return do_save(argv[2]);

			} else {
				int ret = do_save_default();

				if (ret) {
					PX4_ERR("Param save failed (%i)", ret);
					return 1;

				} else {
					return 0;
				}
			}
		}

		if (!strcmp(argv[1], "load")) {
			if (argc >= 3) {
				return do_load(argv[2]);

			} else {
				return do_load(param_get_default_file());
			}
		}

		if (!strcmp(argv[1], "import")) {
			if (argc >= 3) {
				return do_import(argv[2]);

			} else {
				return do_import(param_get_default_file());
			}
		}

		if (!strcmp(argv[1], "select")) {
			if (argc >= 3) {
				param_set_default_file(argv[2]);

			} else {
				param_set_default_file(NULL);
			}

			PX4_INFO("selected parameter default file %s", param_get_default_file());
			return 0;
		}

		if (!strcmp(argv[1], "show")) {
			if (argc >= 3) {
				// optional argument -c to show only non-default params
				if (!strcmp(argv[2], "-c")) {
					if (argc >= 4) {
						return do_show(argv[3], true);

					} else {
						return do_show(NULL, true);
					}

				} else {
					return do_show(argv[2], false);
				}

			} else {
				return do_show(NULL, false);
			}
		}

		if (!strcmp(argv[1], "set")) {
			if (argc >= 5) {

				/* if the fail switch is provided, fails the command if not found */
				bool fail = !strcmp(argv[4], "fail");

				return do_set(argv[2], argv[3], fail);

			} else if (argc >= 4) {
				return do_set(argv[2], argv[3], false);

			} else {
				PX4_ERR("not enough arguments.\nTry 'param set PARAM_NAME 3 [fail]'");
				return 1;
			}
		}

		if (!strcmp(argv[1], "compare")) {
			if (argc >= 4) {
				return do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR_EQUAL);

			} else {
				PX4_ERR("not enough arguments.\nTry 'param compare PARAM_NAME 3'");
				return 1;
			}
		}

		if (!strcmp(argv[1], "greater")) {
			if (argc >= 4) {
				return do_compare(argv[2], &argv[3], argc - 3, COMPARE_OPERATOR_GREATER);

			} else {
				PX4_ERR("not enough arguments.\nTry 'param greater PARAM_NAME 3'");
				return 1;
			}
		}

		if (!strcmp(argv[1], "reset")) {
			if (argc >= 3) {
				return do_reset((const char **) &argv[2], argc - 2);

			} else {
				return do_reset(NULL, 0);
			}
		}

		if (!strcmp(argv[1], "reset_nostart")) {
			if (argc >= 3) {
				return do_reset_nostart((const char **) &argv[2], argc - 2);

			} else {
				return do_reset_nostart(NULL, 0);
			}
		}

		if (!strcmp(argv[1], "index_used")) {
			if (argc >= 3) {
				return do_show_index(argv[2], true);

			} else {
				PX4_ERR("no index provided");
				return 1;
			}
		}

		if (!strcmp(argv[1], "index")) {
			if (argc >= 3) {
				return do_show_index(argv[2], false);

			} else {
				PX4_ERR("no index provided");
				return 1;
			}
		}

		if (!strcmp(argv[1], "find")) {
			if (argc >= 3) {
				return do_find(argv[2]);

			} else {
				PX4_ERR("not enough arguments.\nTry 'param find PARAM_NAME'");
				return 1;
			}
		}
	}

	PX4_INFO("expected a command, try 'load', 'import', 'show [-c] [<filter>]', 'set <param> <value>', 'compare',\n'index', 'index_used', 'find', 'greater', 'select', 'save', or 'reset' ");
	return 1;
}
Пример #28
0
 inline typename boost::enable_if<is_optimize<T, binary_oarchive>, bool>::type do_save(T const& t)
 {
     return do_save((char const*)boost::addressof(t), sizeof(T));
 }
Пример #29
0
int
param_main(int argc, char *argv[])
{
	if (argc >= 2) {
		if (!strcmp(argv[1], "save")) {
			if (argc >= 3) {
				return do_save(argv[2]);

			} else {
				if (param_save_default()) {
					warnx("Param export failed.");
					return 1;

				} else {
					return 0;
				}
			}
		}

		if (!strcmp(argv[1], "load")) {
			if (argc >= 3) {
				return do_load(argv[2]);

			} else {
				return do_load(param_get_default_file());
			}
		}

		if (!strcmp(argv[1], "import")) {
			if (argc >= 3) {
				return do_import(argv[2]);

			} else {
				return do_import(param_get_default_file());
			}
		}

		if (!strcmp(argv[1], "select")) {
			if (argc >= 3) {
				param_set_default_file(argv[2]);

			} else {
				param_set_default_file(NULL);
			}

			warnx("selected parameter default file %s", param_get_default_file());
			return 0;
		}

		if (!strcmp(argv[1], "show")) {
			if (argc >= 3) {
				do_show(argv[2]);
				return 0;

			} else {
				do_show(NULL);
				return 0;
			}
		}

		if (!strcmp(argv[1], "set")) {
			if (argc >= 5) {

				/* if the fail switch is provided, fails the command if not found */
				bool fail = !strcmp(argv[4], "fail");

				return do_set(argv[2], argv[3], fail);

			} else if (argc >= 4) {
				return do_set(argv[2], argv[3], false);

			} else {
				warnx("not enough arguments.\nTry 'param set PARAM_NAME 3 [fail]'");
				return 1;
			}
		}

		if (!strcmp(argv[1], "compare")) {
			if (argc >= 4) {
				return do_compare(argv[2], &argv[3], argc - 3);

			} else {
				warnx("not enough arguments.\nTry 'param compare PARAM_NAME 3'");
				return 1;
			}
		}

		if (!strcmp(argv[1], "reset")) {
			if (argc >= 3) {
				return do_reset((const char **) &argv[2], argc - 2);

			} else {
				return do_reset(NULL, 0);
			}
		}

		if (!strcmp(argv[1], "reset_nostart")) {
			if (argc >= 3) {
				return do_reset_nostart((const char **) &argv[2], argc - 2);

			} else {
				return do_reset_nostart(NULL, 0);
			}
		}

		if (!strcmp(argv[1], "index_used")) {
			if (argc >= 3) {
				do_show_index(argv[2], true);
			} else {
				warnx("no index provided");
				return 1;
			}
		}

		if (!strcmp(argv[1], "index")) {
			if (argc >= 3) {
				do_show_index(argv[2], false);
			} else {
				warnx("no index provided");
				return 1;
			}
		}
	}

	warnx("expected a command, try 'load', 'import', 'show', 'set', 'compare', 'select' or 'save'");
	return 1;
}
Пример #30
0
void equip_char(struct char_data *ch, struct obj_data *obj, int pos)
{
  int j;
  
  assert(pos>=0 && pos<MAX_WEAR);
  assert(!(ch->equipment[pos]));
  
  if (obj->carried_by) {
    logE("EQUIP: Obj is carried_by when equip.");
    assert(0);
  }
  
  if (obj->in_room!=NOWHERE) {
    logE("EQUIP: Obj is in_room when equip.");
    assert(0);
    return;
  }

  /*
    if the item is limited, check its ego.
    use some funky function to determine if pc's ego is higher than objs'
    ego.. if it is, proceed.. otherwise, deny.
    */
  j = ItemEgoClash(ch, obj, 0);
  if (j < -5) {
    act("$p almost seems to say 'You're much too puny to use me, twerp!'",0,
	ch, obj, 0, TO_CHAR); 
    act("$p falls to the floor",0,ch, obj, 0, TO_CHAR); 
    act("$p removes itself, and falls to the floor",0,ch, obj, 0, TO_ROOM); 
    obj_to_room(obj, ch->in_room);
    do_save(ch,"",0);
    return;
  } else if (j < 0) {
    act("$p almost seems to say 'You're pretty puny.  I don't want to be seen with you!\n", 0, ch, obj, 0, TO_CHAR);
    act("$p falls to the floor",0,ch, obj, 0, TO_CHAR); 
    act("$p removes itself, and falls to the floor",0,ch, obj, 0, TO_ROOM); 
    obj_to_room(obj, ch->in_room);
    do_save(ch,"",0);
    return;
  }

  if (ItemAlignClash(ch, obj)) {
    if (ch->in_room != NOWHERE) {
      
      act("You are zapped by $p and instantly drop it.", 
	  FALSE, ch, obj, 0, TO_CHAR);
      act("$n is zapped by $p and instantly drop it.", 
	  FALSE, ch, obj, 0, TO_ROOM);
      obj_to_room(obj, ch->in_room);
      do_save(ch,"",0);
      return;
    } else {
      logE("ch->in_room = NOWHERE when equipping char.");
      assert(0);
    }
  }
  
  if (IS_AFFECTED(ch, AFF_SNEAK) &&
      IsRestricted(GetItemClassRestrictions(obj), CLASS_THIEF))
    affect_from_char(ch, SKILL_SNEAK);
  
  ch->equipment[pos] = obj;
  obj->equipped_by = ch;
  obj->eq_pos = pos;
  
  if (GET_ITEM_TYPE(obj) == ITEM_ARMOR)
    GET_AC(ch) -= apply_ac(ch, pos);
  
  for(j=0; j<MAX_OBJ_AFFECT; j++)
    affect_modify(ch, obj->affected[j].location,
		  (int)obj->affected[j].modifier,
		  obj->obj_flags.bitvector, TRUE);

  if (GET_ITEM_TYPE(obj) == ITEM_WEAPON) {
    /* some nifty manuevering for strength */
    if (IS_NPC(ch) && !IS_SET(ch->specials.act, ACT_POLYSELF))
       GiveMinStrToWield(obj, ch);
  }
  
  affect_total(ch);
}