____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "stratagus.h"
#include "util.h"
Go to the source code of this file.
Functions | |
| void | InitSyncRand (void) |
| Initialize the syncron rand. | |
| int | SyncRand (void) |
| Syncron rand. | |
| int | SyncRand (int max) |
| Syncron rand. | |
| long | isqrt (long num) |
| unsigned int | strcpy_s (char *dst, size_t dstsize, const char *src) |
| size_t | strnlen (const char *str, size_t strsize) |
| < determine length of a fixed-length string | |
| unsigned int | strncpy_s (char *dst, size_t dstsize, const char *src, size_t count) |
| unsigned int | strcat_s (char *dst, size_t dstsize, const char *src) |
| int | sprintf_s (char *dest, size_t destSize, const char *format,...) |
| char * | strdcat (const char *l, const char *r) |
| strdup + strcat + strcat | |
| char * | strdcat3 (const char *l, const char *m, const char *r) |
| case insensitive strstr | |
| char * | strcasestr (const char *a, const char *b) |
| int | GetClipboard (std::string &str) |
| int | UTF8GetPrev (const std::string &text, int curpos) |
| int | UTF8GetNext (const std::string &text, int curpos) |
Variables | |
| unsigned | SyncRandSeed |
| sync random seed value. | |
Definition in file util.cpp.
| int GetClipboard | ( | std::string & | str | ) |
Standard implementation of getopt(3).
One extension: If the first character of the optionsstring is a ':' the error return for 'argument required' is a ':' not a '?'. This makes it easier to differentiate between an 'illegal option' and an 'argument required' error.
Paste text from the clipboard
Definition at line 414 of file util.cpp.
Referenced by gcn::TextField::keyPress(), gcn::TextBox::keyPress(), gcn::TextField::mousePress(), and gcn::TextBox::mousePress().
| void InitSyncRand | ( | void | ) |
Initialize the syncron rand.
Inititalize sync rand seed.
Definition at line 57 of file util.cpp.
References SyncRandSeed.
Referenced by CreateGame(), InitModules(), and main().
| long isqrt | ( | long | num | ) |
Compute a square root using ints
Uses John Halleck's method, see http://www.cc.utah.edu/~nahaj/factoring/isqrt.legalize.c.html
| num | Calculate the square root of this number |
Definition at line 104 of file util.cpp.
Referenced by AStarFindSimplePath(), HitUnit(), InitVisionTable(), MapDistance(), MapDistanceBetweenTypes(), and MapDistanceToType().
| int sprintf_s | ( | char * | dest, | |
| size_t | destSize, | |||
| const char * | format, | |||
| ... | ||||
| ) |
Definition at line 223 of file util.cpp.
Referenced by CclDefineButton(), CclFilteredListDirectory(), CclStratagusMap(), MessagesDisplay::CheckRepeatMessage(), CommandLog(), DrawInformations(), DrawResources(), DrawTimer(), FindFileWithExtension(), CPlayerColorGraphic::ForceNew(), CGraphic::ForceNew(), FormatNumber(), InitKey2Str(), InputKey(), LibraryFileName(), LuaEscape(), Screenshot(), ShowInput(), UIHandleButtonUp(), and UnitActions().
| char* strcasestr | ( | const char * | a, | |
| const char * | b | |||
| ) |
Case insensitive version of strstr
| a | String to search in | |
| b | Substring to search for |
Definition at line 298 of file util.cpp.
Referenced by CreateFileWriter(), and CreateGame().
| unsigned int strcat_s | ( | char * | dst, | |
| size_t | dstsize, | |||
| const char * | src | |||
| ) |
Definition at line 202 of file util.cpp.
Referenced by InputKey(), LoadStratagusMap(), ReadDataDirectory(), strdcat(), and strdcat3().
| unsigned int strcpy_s | ( | char * | dst, | |
| size_t | dstsize, | |||
| const char * | src | |||
| ) |
Definition at line 148 of file util.cpp.
Referenced by MessagesDisplay::AddMessage(), ApplyReplaySettings(), CclSavedGameInfo(), CreateGame(), CButtonPanel::Draw(), FindFileWithExtension(), InputKey(), LibraryFileName(), LoadStratagusMap(), ReadDataDirectory(), SetMessageEvent(), MessagesDisplay::ShiftMessages(), ShiftMessagesEvent(), StartEditor(), strdcat(), and strdcat3().
| char* strdcat | ( | const char * | l, | |
| const char * | r | |||
| ) |
strdup + strcat + strcat
String duplicate/concatenate (two arguments)
| l | Left string | |
| r | Right string |
Definition at line 255 of file util.cpp.
References strcat_s(), and strcpy_s().
| char* strdcat3 | ( | const char * | l, | |
| const char * | m, | |||
| const char * | r | |||
| ) |
case insensitive strstr
String duplicate/concatenate (three arguments)
| l | Left string | |
| m | Middle string | |
| r | Right string |
Definition at line 276 of file util.cpp.
References strcat_s(), and strcpy_s().
Referenced by SaveGlobal().
| unsigned int strncpy_s | ( | char * | dst, | |
| size_t | dstsize, | |||
| const char * | src, | |||
| size_t | count | |||
| ) |
Definition at line 175 of file util.cpp.
References _TRUNCATE, and strnlen().
Referenced by IsSafeMapName(), and ServerParseWaiting().
| size_t strnlen | ( | const char * | str, | |
| size_t | strsize | |||
| ) |
< determine length of a fixed-length string
Definition at line 161 of file util.cpp.
Referenced by strncpy_s().
| int SyncRand | ( | int | max | ) |
Syncron rand.
Synchronized random number.
| max | Max value of random number to return |
Definition at line 84 of file util.cpp.
References SyncRand().
| int SyncRand | ( | void | ) |
Syncron rand.
Synchronized random number.
Definition at line 68 of file util.cpp.
References SyncRandSeed.
Referenced by AiBuildBuilding(), AiCollectResources(), AiMoveUnitInTheWay(), AiSendExplorers(), CalculateDamage(), AreaBombardment::Cast(), CclCreateUnit(), CclMoveUnit(), EvaluateMissileLocation(), HitUnit(), SelectTargetUnitsOfAutoCast(), SyncRand(), tolua_stratagus_SyncRand00(), tolua_stratagus_SyncRand01(), and UnitShowAnimationScaled().
| int UTF8GetNext | ( | const std::string & | text, | |
| int | curpos | |||
| ) |
Definition at line 528 of file util.cpp.
Referenced by gcn::TextField::keyPress(), and gcn::TextBox::keyPress().
| int UTF8GetPrev | ( | const std::string & | text, | |
| int | curpos | |||
| ) |
Definition at line 510 of file util.cpp.
Referenced by InputKey(), gcn::TextField::keyPress(), and gcn::TextBox::keyPress().
| unsigned SyncRandSeed |
sync random seed value.
Sync random seed value.
Definition at line 52 of file util.cpp.
Referenced by CclSavedGameInfo(), CommandLog(), DoNextReplay(), InitSyncRand(), LoadGame(), NetworkSendCommands(), SaveGame(), SyncRand(), and UnitActions().
1.5.6