[AStyle] : on most cpp files.

This commit is contained in:
Joris 2012-04-18 16:09:57 +02:00
parent 4ec2ba35af
commit 720bc8c831
24 changed files with 156 additions and 133 deletions

View file

@ -390,8 +390,8 @@ void COrder_Attack::MoveToTarget(CUnit &unit)
return;
}
// Attacking wall or ground.
if (((goal && goal->Type && goal->Type->Wall) || ((!goal)
&& (Map.WallOnMap(this->goalPos) || this->Action == UnitActionAttackGround)))
if (((goal && goal->Type && goal->Type->Wall)
|| (!goal && (Map.WallOnMap(this->goalPos) || this->Action == UnitActionAttackGround)))
&& unit.MapDistanceTo(this->goalPos) <= unit.Stats->Variables[ATTACKRANGE_INDEX].Max) {
// Reached wall or ground, now attacking it
unit.State = 0;

View file

@ -876,9 +876,9 @@ static void AiMoveUnitInTheWay(CUnit &unit)
// Check for collision
if (!((u0.x == b1.x + 1 || u1.x == b0.x - 1)
&& (std::max<int>(b0.y, u0.y) <= std::min<int>(b1.y, u1.y)))
&& (std::max<int>(b0.y, u0.y) <= std::min<int>(b1.y, u1.y)))
&& !((u0.y == b1.y + 1 || u1.y == b0.y - 1)
&& (std::max<int>(b0.x, u0.x) <= std::min<int>(b1.x, u1.x)))) {
&& (std::max<int>(b0.x, u0.x) <= std::min<int>(b1.x, u1.x)))) {
continue;
}

View file

@ -95,8 +95,8 @@ static int AiCheckSurrounding(const CUnit &worker,
if (x == worker.tilePos.x && y == worker.tilePos.y) {
surrounding[surroundingnb++] = 1;
} else if (Map.CheckMask(x + y_offset,
(MapFieldUnpassable | MapFieldWall | MapFieldRocks
| MapFieldForest | MapFieldBuilding))) {
(MapFieldUnpassable | MapFieldWall | MapFieldRocks
| MapFieldForest | MapFieldBuilding))) {
surrounding[surroundingnb++] = 0;
} else {
// Can pass there

View file

@ -397,7 +397,7 @@ static int CclDefineAiHelper(lua_State *l)
return 0;
}
static CAiType *GetAiTypesByName(const char* name)
static CAiType *GetAiTypesByName(const char *name)
{
for (size_t i = 0; i < AiTypes.size(); ++i) {
CAiType *ait = AiTypes[i];
@ -425,7 +425,7 @@ static int CclDefineAi(lua_State *l)
CAiType *aitype = new CAiType;
// AI Name
const char* aiName = LuaToString(l, 1);
const char *aiName = LuaToString(l, 1);
aitype->Name = aiName;
#ifdef DEBUG
@ -1273,7 +1273,7 @@ static int CclDefineAiPlayer(lua_State *l)
++j;
if (!strcmp(value, "ai-type")) {
const char* aiName = LuaToString(l, j + 1);
const char *aiName = LuaToString(l, j + 1);
CAiType *ait = GetAiTypesByName(aiName);
if (ait == NULL) {
lua_pushfstring(l, "ai-type not found: %s", aiName);
@ -1299,7 +1299,7 @@ static int CclDefineAiPlayer(lua_State *l)
for (int k = 1; k < subargs; ++k) {
lua_rawgeti(l, j + 1, k + 1);
const char* value = LuaToString(l, -1);
const char *value = LuaToString(l, -1);
lua_pop(l, 1);
++k;
if (!strcmp(value, "complete")) {

View file

@ -99,7 +99,7 @@ static int ParseAnimFlags(CUnit &unit, const char *parseflag)
const int destx = ParseAnimInt(&unit, this->destXStr.c_str());
const int desty = ParseAnimInt(&unit, this->destYStr.c_str());
const int flags = ParseAnimFlags(unit, this->flagsStr.c_str());
const CUnit *goal = flags & ANIM_SM_RELTARGET ? unit.CurrentOrder()->GetGoal(): &unit;
const CUnit *goal = flags & ANIM_SM_RELTARGET ? unit.CurrentOrder()->GetGoal() : &unit;
PixelPos start;
PixelPos dest;

View file

@ -30,17 +30,17 @@
extern "C" {
/**
** Need init function for beos.
**
** @param argc Number of command line argurments
*/
void beos_init(int argc, char** argv)
{
BPath path( argv[0] );
path.GetParent( &path );
chdir( path.Path() );
}
/**
** Need init function for beos.
**
** @param argc Number of command line argurments
*/
void beos_init(int argc, char **argv)
{
BPath path(argv[0]);
path.GetParent(&path);
chdir(path.Path());
}
}

View file

@ -44,7 +44,7 @@
-- Variables
----------------------------------------------------------------------------*/
static osso_context_t * osso = NULL;
static osso_context_t *osso = NULL;
static SDL_TimerID timer = NULL;
/*----------------------------------------------------------------------------
@ -57,8 +57,9 @@ static SDL_TimerID timer = NULL;
**/
static Uint32 OssoKeepBacklightAlive(Uint32 interval, void *)
{
if (!osso)
if (!osso) {
return 0;
}
osso_display_state_on(osso);
osso_display_blanking_pause(osso);
@ -72,15 +73,16 @@ static Uint32 OssoKeepBacklightAlive(Uint32 interval, void *)
**/
static void OssoInitialize(void)
{
char * application;
char *application;
if (FullGameName.empty()) {
application = strdup("org.stratagus");
} else {
application = (char *)calloc(FullGameName.size() + 15, 1);
strcpy(application, "org.stratagus.");
for (int i = 0; i < FullGameName.size(); i++)
application[i+14] = tolower(FullGameName[i]);
for (int i = 0; i < FullGameName.size(); i++) {
application[i + 14] = tolower(FullGameName[i]);
}
}
osso = osso_initialize(application, VERSION, TRUE, NULL);

View file

@ -114,9 +114,9 @@ void CMap::MarkSeenTile(const unsigned int index)
// Handle Walls changes.
} else if (this->Tileset.TileTypeTable[tile] == TileTypeHumanWall
|| this->Tileset.TileTypeTable[tile] == TileTypeOrcWall
|| this->Tileset.TileTypeTable[seentile] == TileTypeHumanWall
|| this->Tileset.TileTypeTable[seentile] == TileTypeOrcWall) {
|| this->Tileset.TileTypeTable[tile] == TileTypeOrcWall
|| this->Tileset.TileTypeTable[seentile] == TileTypeHumanWall
|| this->Tileset.TileTypeTable[seentile] == TileTypeOrcWall) {
MapFixSeenWallTile(pos);
MapFixSeenWallNeighbors(pos);
}
@ -231,8 +231,8 @@ bool UnitTypeCanBeAt(const CUnitType &type, const Vec2i &pos)
for (int addy = 0; addy < type.TileHeight; ++addy) {
for (int addx = 0; addx < type.TileWidth; ++addx) {
if (!(Map.Info.IsPointOnMap(pos.x + addx, pos.y + addy)
&& !Map.CheckMask(pos.x + addx + index, mask))) {
if (Map.Info.IsPointOnMap(pos.x + addx, pos.y + addy) == false
|| Map.CheckMask(pos.x + addx + index, mask) == true) {
return false;
}
}

View file

@ -352,7 +352,7 @@ void CViewport::Draw() const
//FIXME: This is still unsecure during parallel
if (!Preference.ShowOrders) {
} else if (Preference.ShowOrders < 0
|| (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) {
|| (ShowOrdersCount >= GameCycle) || (KeyModifiers & ModifierShift)) {
for (int i = 0; i < NumSelected; ++i) {
ShowOrder(*Selected[i]);
}

View file

@ -781,7 +781,7 @@ void Missile::MissileHit()
//
if (!mtype.Range) {
if (this->TargetUnit && (mtype.FriendlyFire == false
|| this->TargetUnit->Player->Index != this->SourceUnit->Player->Index)) {
|| this->TargetUnit->Player->Index != this->SourceUnit->Player->Index)) {
//
// Missiles without range only hits the goal always.
//
@ -934,7 +934,7 @@ void Missile::NextMissileFrameCycle()
j = f - i;
}
this->SpriteFrame = this->SpriteFrame % (this->Type->NumDirections / 2 + 1) +
j * (this->Type->NumDirections / 2 + 1);
j * (this->Type->NumDirections / 2 + 1);
break;
}
}
@ -1048,7 +1048,7 @@ void Missile::SaveMissile(CFile &file) const
file.printf(", \"goal\", ");
SavePixelPos(file, this->destination);
file.printf(",\n \"frame\", %d, \"state\", %d, \"anim-wait\", %d, \"wait\", %d, \"delay\", %d,\n ",
this->SpriteFrame, this->State, this->AnimWait, this->Wait, this->Delay);
this->SpriteFrame, this->State, this->AnimWait, this->Wait, this->Delay);
if (this->SourceUnit != NULL) {
file.printf(" \"source\", \"%s\",", UnitReference(this->SourceUnit).c_str());
}

View file

@ -1038,7 +1038,7 @@ void NetworkEvent()
if (slot < UnitSlotFree
&& (UnitSlots[slot]->Player->Index == player
|| Players[player].IsTeamed(*UnitSlots[slot]))) {
|| Players[player].IsTeamed(*UnitSlots[slot]))) {
validCommand = true;
} else {
validCommand = false;
@ -1054,7 +1054,7 @@ void NetworkEvent()
} else {
SetMessage(_("%s sent bad command"), Players[player].Name.c_str());
DebugPrint("%s sent bad command: 0x%x\n" _C_ Players[player].Name.c_str()
_C_ packet.Header.Type[i] & 0x7F);
_C_ packet.Header.Type[i] & 0x7F);
}
}

View file

@ -201,7 +201,7 @@ inline void ProfilePrint()
}
std::vector<ProfileData *> prof;
for (std::map<const char *const, ProfileData>::iterator i = functionProfiles.begin();
i != functionProfiles.end(); ++i) {
i != functionProfiles.end(); ++i) {
ProfileData *data = &i->second;
prof.insert(std::upper_bound(prof.begin(), prof.end(), data, compProfileData), data);
}
@ -415,7 +415,7 @@ static inline int AStarAddNode(const Vec2i &pos, int o, int costs)
smalli = midi;
} else if (costs < midcost || (costs == midcost
&& (costToGoal < midCostToGoal || (costToGoal == midCostToGoal
&& dist < midDist)))) {
&& dist < midDist)))) {
if (bigi == midi) {
bigi++;
} else {

View file

@ -839,12 +839,12 @@ static int CclSetPlayerData(lua_State *l)
const std::string res = LuaToString(l, 3);
const int resId = GetResourceIdByName(l, res.c_str());
p->SetResource(resId, LuaToNumber(l, 4), true);
// } else if (!strcmp(data, "UnitTypesCount")) {
// } else if (!strcmp(data, "AiEnabled")) {
// } else if (!strcmp(data, "TotalNumUnits")) {
// } else if (!strcmp(data, "NumBuildings")) {
// } else if (!strcmp(data, "Supply")) {
// } else if (!strcmp(data, "Demand")) {
// } else if (!strcmp(data, "UnitTypesCount")) {
// } else if (!strcmp(data, "AiEnabled")) {
// } else if (!strcmp(data, "TotalNumUnits")) {
// } else if (!strcmp(data, "NumBuildings")) {
// } else if (!strcmp(data, "Supply")) {
// } else if (!strcmp(data, "Demand")) {
} else if (!strcmp(data, "UnitLimit")) {
p->UnitLimit = LuaToNumber(l, 3);
} else if (!strcmp(data, "BuildingLimit")) {

View file

@ -779,7 +779,7 @@ int AddSelectedUnitsInRectangle(int x0, int y0, int x1, int y1)
// In this case, do nothing.
if (NumSelected == 1
&& (!CanSelectMultipleUnits(*Selected[0]->Player)
|| !Selected[0]->Type->SelectableByRectangle)) {
|| !Selected[0]->Type->SelectableByRectangle)) {
return NumSelected;
}
// If there is no selected unit yet, do a simple selection.
@ -929,7 +929,7 @@ int AddSelectedGroundUnitsInRectangle(int sx0, int sy0, int sx1, int sy1)
// In this case, do nothing.
if (NumSelected == 1
&& (!CanSelectMultipleUnits(*Selected[0]->Player)
|| !Selected[0]->Type->SelectableByRectangle)) {
|| !Selected[0]->Type->SelectableByRectangle)) {
return NumSelected;
}
@ -993,7 +993,7 @@ int AddSelectedAirUnitsInRectangle(int sx0, int sy0, int sx1, int sy1)
// In this case, do nothing.
if (NumSelected == 1
&& (!CanSelectMultipleUnits(*Selected[0]->Player)
|| !Selected[0]->Type->SelectableByRectangle)) {
|| !Selected[0]->Type->SelectableByRectangle)) {
return NumSelected;
}

View file

@ -324,7 +324,6 @@ int SpawnMissile::Cast(CUnit &caster, const SpellType *, CUnit *target, const Ve
missile->SourceUnit = &caster;
}
missile->TargetUnit = target;
return 1;
}
@ -423,11 +422,11 @@ int AdjustVitals::Cast(CUnit &caster, const SpellType *spell, CUnit *target, con
int castcount = 1;
if (hp) {
castcount = std::max<int>(castcount,
diffHP / abs(hp) + (((hp < 0) && (diffHP % (-hp) > 0)) ? 1 : 0));
diffHP / abs(hp) + (((hp < 0) && (diffHP % (-hp) > 0)) ? 1 : 0));
}
if (mana) {
castcount = std::max<int>(castcount,
diffMana / abs(mana) + (((mana < 0) && (diffMana % (-mana) > 0)) ? 1 : 0));
diffMana / abs(mana) + (((mana < 0) && (diffMana % (-mana) > 0)) ? 1 : 0));
}
if (manacost) {
castcount = std::min<int>(castcount, caster.Variable[MANA_INDEX].Value / manacost);
@ -689,7 +688,7 @@ static Target *NewTargetUnit(CUnit &unit)
** @return true if passed, false otherwise.
*/
static bool PassCondition(const CUnit &caster, const SpellType *spell, const CUnit *target,
const Vec2i &/*goalPos*/, const ConditionInfo *condition)
const Vec2i &/*goalPos*/, const ConditionInfo *condition)
{
if (caster.Variable[MANA_INDEX].Value < spell->ManaCost) { // Check caster mana.
return false;

View file

@ -352,7 +352,7 @@ int CPopupContentTypeCosts::GetWidth(const ButtonAction *button, int *Costs) con
for (unsigned int i = 1; i < MaxCosts; ++i) {
if (Costs[i]) {
if(UI.Resources[i].IconWidth != -1) {
if (UI.Resources[i].IconWidth != -1) {
popupWidth += (UI.Resources[i].IconWidth + 5);
} else {
const CGraphic *G = UI.Resources[i].G;
@ -551,8 +551,8 @@ static void GetPopupSize(const ButtonAction *button, const CUIButton *uibutton,
CPopup &popup = *PopupByIdent(button->Popup);
for (std::vector<CPopupContentType *>::const_iterator it = popup.Contents.begin();
it != popup.Contents.end();
++it) {
it != popup.Contents.end();
++it) {
const CPopupContentType &content = **it;
if (CanShowPopupContent(content.Condition, button, UnitTypes[button->Value])) {
@ -724,10 +724,10 @@ void DrawPopup(const ButtonAction *button, const CUIButton *uibutton)
// Contents
for (std::vector<CPopupContentType *>::const_iterator content = popup->Contents.begin();
content != popup->Contents.end(); ++content) {
if (CanShowPopupContent((*content)->Condition, button, UnitTypes[button->Value])) {
(*content)->Draw(x + (*content)->PosX, y + (*content)->PosY, button, Costs);
}
content != popup->Contents.end(); ++content) {
if (CanShowPopupContent((*content)->Condition, button, UnitTypes[button->Value])) {
(*content)->Draw(x + (*content)->PosX, y + (*content)->PosY, button, Costs);
}
}
#if 0 // Fixme: need to remove soon
@ -994,9 +994,9 @@ static bool IsButtonAllowed(const CUnit &unit, const ButtonAction *buttonaction)
break;
case ButtonReturn:
if (!(!unit.CurrentResource
|| !(unit.ResourcesHeld > 0 && !unit.Type->ResInfo[unit.CurrentResource]->LoseResources)
|| (unit.ResourcesHeld != unit.Type->ResInfo[unit.CurrentResource]->ResourceCapacity
&& unit.Type->ResInfo[unit.CurrentResource]->LoseResources))) {
|| !(unit.ResourcesHeld > 0 && !unit.Type->ResInfo[unit.CurrentResource]->LoseResources)
|| (unit.ResourcesHeld != unit.Type->ResInfo[unit.CurrentResource]->ResourceCapacity
&& unit.Type->ResInfo[unit.CurrentResource]->LoseResources))) {
res = true;
}
break;
@ -1234,7 +1234,7 @@ void CButtonPanel::DoClicked(int button)
// That or a bunker.
//
if ((NumSelected == 1 && Selected[0]->CurrentAction() == UnitActionStill
&& Map.CoastOnMap(Selected[0]->tilePos))
&& Map.CoastOnMap(Selected[0]->tilePos))
|| !Selected[0]->CanMove()) {
SendCommandUnload(*Selected[0], Selected[0]->tilePos, NoUnitP, flush);
break;
@ -1420,8 +1420,9 @@ void CButtonPanel::DoClicked(int button)
UI.StatusLine.Clear();
ClearCosts();
} else if (Selected[0]->Player->CheckLimits(type) == -3)
if (GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound)
if (GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound) {
PlayGameSound(GameSounds.NotEnoughFood[Selected[0]->Player->Race].Sound, MaxSampleVolume);
}
break;
}
case ButtonUpgradeTo: {

View file

@ -703,7 +703,7 @@ static void DrawUnitInfo(CUnit &unit)
order.GetUnitType().Icon.Icon->DrawUnitIcon(
UI.UpgradingButton->Style,
(ButtonAreaUnderCursor == ButtonAreaUpgrading
&& ButtonUnderCursor == 0) ?
&& ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0,
UI.UpgradingButton->X, UI.UpgradingButton->Y, "");
}
@ -716,7 +716,7 @@ static void DrawUnitInfo(CUnit &unit)
order.GetUpgrade().Icon->DrawUnitIcon(
UI.ResearchingButton->Style,
(ButtonAreaUnderCursor == ButtonAreaResearching
&& ButtonUnderCursor == 0) ?
&& ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0,
UI.ResearchingButton->X, UI.ResearchingButton->Y, "");
}

View file

@ -890,7 +890,7 @@ static PopupConditionPanel *ParsePopupConditions(lua_State *l)
for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) {
key = LuaToString(l, -2);
if (!strcmp(key, "ButtonType")) {
} else {
int index = UnitTypeVar.BoolFlagNameLookup[key];
if (index != -1) {
@ -959,20 +959,20 @@ static CPopupContentType *CclParsePopupContent(lua_State *l)
}
content = contentname;
} else if (!strcmp(key, "Costs")) {
CPopupContentTypeCosts *contentcosts = new CPopupContentTypeCosts;
CPopupContentTypeCosts *contentcosts = new CPopupContentTypeCosts;
Assert(lua_istable(l, -1));
for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) {
key = LuaToString(l, -2);
if (!strcmp(key, "Font")) {
contentcosts->Font = CFont::Get(LuaToString(l, -1));
} else if (!strcmp(key, "Centered")) {
contentcosts->Centered = LuaToBoolean(l, -1);
} else {
LuaError(l, "'%s' invalid for method 'Costs' in DefinePopups" _C_ key);
}
Assert(lua_istable(l, -1));
for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) {
key = LuaToString(l, -2);
if (!strcmp(key, "Font")) {
contentcosts->Font = CFont::Get(LuaToString(l, -1));
} else if (!strcmp(key, "Centered")) {
contentcosts->Centered = LuaToBoolean(l, -1);
} else {
LuaError(l, "'%s' invalid for method 'Costs' in DefinePopups" _C_ key);
}
content = contentcosts;
}
content = contentcosts;
} else if (!strcmp(key, "Variable")) {
CPopupContentTypeVariable *contenttext = new CPopupContentTypeVariable;

View file

@ -276,8 +276,8 @@ void CleanUserInterface()
// Button Popups
for (std::vector<CPopup *>::iterator popup = UI.ButtonPopups.begin();
popup != UI.ButtonPopups.end(); ++popup) {
delete *popup;
popup != UI.ButtonPopups.end(); ++popup) {
delete *popup;
}
UI.ButtonPopups.clear();

View file

@ -1591,10 +1591,10 @@ void CUnit::AssignWorkerToMine(CUnit &mine)
CUnit *head = mine.Resource.Workers;
#if 0
DebugPrint("%d: Worker [%d] is adding into %s [%d] on %d pos\n"
_C_ this->Player->Index _C_ this->Slot
_C_ mine.Type->Name.c_str()
_C_ mine.Slot
_C_ mine.Data.Resource.Assigned);
_C_ this->Player->Index _C_ this->Slot
_C_ mine.Type->Name.c_str()
_C_ mine.Slot
_C_ mine.Data.Resource.Assigned);
#endif
this->RefsIncrease();
this->NextWorker = head;
@ -1610,10 +1610,10 @@ void CUnit::DeAssignWorkerFromMine(CUnit &mine)
CUnit *prev = NULL, *worker = mine.Resource.Workers;
#if 0
DebugPrint("%d: Worker [%d] is removing from %s [%d] left %d units assigned\n"
_C_ this->Player->Index _C_ this->Slot
_C_ mine.Type->Name.c_str()
_C_ mine.Slot
_C_ mine.CurrentOrder()->Data.Resource.Assigned);
_C_ this->Player->Index _C_ this->Slot
_C_ mine.Type->Name.c_str()
_C_ mine.Slot
_C_ mine.CurrentOrder()->Data.Resource.Assigned);
#endif
for (int i = 0; NULL != worker; worker = worker->NextWorker, ++i) {
if (worker == this) {

View file

@ -578,13 +578,13 @@ static void DrawDecoration(const CUnit &unit, const CUnitType *type, int x, int
Assert(value <= max);
if (!((value == 0 && !var->ShowWhenNull) || (value == max && !var->ShowWhenMax)
|| (var->HideHalf && value != 0 && value != max)
|| (!var->ShowIfNotEnable && !unit.Variable[var->Index].Enable)
|| (var->ShowOnlySelected && !unit.Selected)
|| (unit.Player->Type == PlayerNeutral && var->HideNeutral)
|| (ThisPlayer->IsEnemy(unit) && !var->ShowOpponent)
|| (ThisPlayer->IsAllied(unit) && (unit.Player != ThisPlayer) && var->HideAllied)
|| max == 0)) {
|| (var->HideHalf && value != 0 && value != max)
|| (!var->ShowIfNotEnable && !unit.Variable[var->Index].Enable)
|| (var->ShowOnlySelected && !unit.Selected)
|| (unit.Player->Type == PlayerNeutral && var->HideNeutral)
|| (ThisPlayer->IsEnemy(unit) && !var->ShowOpponent)
|| (ThisPlayer->IsAllied(unit) && (unit.Player != ThisPlayer) && var->HideAllied)
|| max == 0)) {
var->Draw(
x + var->OffsetX + var->OffsetXPercent * unit.Type->TileWidth * PixelTileSize.x / 100,
y + var->OffsetY + var->OffsetYPercent * unit.Type->TileHeight * PixelTileSize.y / 100,
@ -719,8 +719,9 @@ static void DrawInformations(const CUnit &unit, const CUnitType &type, int x, in
// For debug draw sight, react and attack range!
//
if (NumSelected == 1 && unit.Selected) {
const PixelPos center = {x + type.TileWidth * PixelTileSize.x / 2,
y + type.TileHeight * PixelTileSize.y / 2};
const PixelPos center = {x + type.TileWidth *PixelTileSize.x / 2,
y + type.TileHeight *PixelTileSize.y / 2
};
if (Preference.ShowSightRange) {
const int value = stats.Variables[SIGHTRANGE_INDEX].Max;

View file

@ -61,7 +61,7 @@ std::string UnitReference(const CUnit &unit)
{
std::ostringstream ss;
ss << "U" << std::setfill('0') << std::setw(4) << std::uppercase
<< std::hex << UnitNumber(unit);
<< std::hex << UnitNumber(unit);
return ss.str();
}
@ -74,7 +74,7 @@ std::string UnitReference(const CUnitPtr &unit)
std::ostringstream ss;
ss << "U" << std::setfill('0') << std::setw(4) << std::uppercase
<< std::hex << unit->Slot;
<< std::hex << unit->Slot;
return ss.str();
}

View file

@ -56,7 +56,7 @@ void CUnitPtr::Reset()
unit = NULL;
}
CUnitPtr& CUnitPtr::operator= (CUnit *u)
CUnitPtr &CUnitPtr::operator= (CUnit *u)
{
if (this->unit != u) {
if (u) {

View file

@ -36,47 +36,54 @@ static HINSTANCE lib_ntdll = NULL;
typedef int FAR WINAPI proto_AttachConsole(int);
typedef int FAR WINAPI proto_NtQueryObject(HANDLE, int, void *, unsigned long int, unsigned long int *);
static proto_AttachConsole * func_AttachConsole = NULL;
static proto_NtQueryObject * func_NtQueryObject = NULL;
static proto_AttachConsole *func_AttachConsole = NULL;
static proto_NtQueryObject *func_NtQueryObject = NULL;
/// Check if HANDLE is attached to console
static int WINAPI_CheckIfConsoleHandle(HANDLE handle) {
static int WINAPI_CheckIfConsoleHandle(HANDLE handle)
{
wchar_t filename[MAX_PATH];
unsigned long int length = 0;
// Try to get filename of HANDLE
if ( func_NtQueryObject )
if (func_NtQueryObject) {
func_NtQueryObject(handle, 1, filename, MAX_PATH, &length);
}
// Filename start at position 8
if ( length > 8 )
if (length > 8) {
return 0;
else
} else {
return 1;
}
}
/// Try to reopen FILE* from WINAPI HANDLE
static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE * file, const char * mode) {
static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE *file, const char *mode)
{
int fd;
FILE * newfile;
FILE *newfile;
if ( ! handle || handle == INVALID_HANDLE_VALUE )
if (! handle || handle == INVALID_HANDLE_VALUE) {
return;
}
// Get file descriptor from HANDLE
fd = _open_osfhandle((intptr_t)handle, O_TEXT);
if ( fd < 0 )
if (fd < 0) {
return;
}
// Get C structure FILE* from file descriptior
newfile = _fdopen(fd, mode);
if ( ! newfile )
if (! newfile) {
return;
}
// Close current file
fclose(file);
@ -87,7 +94,7 @@ static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE * file, const char *
setvbuf(file, NULL, _IONBF, 0);
// If stdout/stderr write 2 empty lines to cmd console
if ( ! fixmode && strcmp(mode, "w") == 0 ) {
if (! fixmode && strcmp(mode, "w") == 0) {
fprintf(file, "\n\n");
fixmode = 1;
@ -97,27 +104,31 @@ static void WINAPI_ReopenFileFromHandle(HANDLE handle, FILE * file, const char *
}
/// Try to set std HANDLE from FILE*
static void WINAPI_SetStdHandleFromFile(int type, FILE * file) {
static void WINAPI_SetStdHandleFromFile(int type, FILE *file)
{
int fd;
HANDLE handle;
fd = _fileno(file);
if ( fd < 0 )
if (fd < 0) {
return;
}
handle = (HANDLE)_get_osfhandle(fd);
if ( ! handle || handle == INVALID_HANDLE_VALUE )
if (! handle || handle == INVALID_HANDLE_VALUE) {
return;
}
SetStdHandle(type, handle);
}
/// Try attach console of parent process for std input/output in Windows NT, 2000, XP or new
static void WINAPI_AttachConsole(void) {
static void WINAPI_AttachConsole(void)
{
OSVERSIONINFO osvi;
int hasVersion;
@ -132,29 +143,34 @@ static void WINAPI_AttachConsole(void) {
hasVersion = GetVersionEx(&osvi);
if ( ! hasVersion )
if (! hasVersion) {
return;
}
version = ( osvi.dwMajorVersion << 8 ) | osvi.dwMinorVersion;
version = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
// We need Windows 2000 or new
if ( version < 0x0500 )
if (version < 0x0500) {
return;
}
lib_kernel32 = LoadLibrary("kernel32.dll");
if ( ! lib_kernel32 )
if (! lib_kernel32) {
return;
}
func_AttachConsole = (proto_AttachConsole*)GetProcAddress(lib_kernel32, "AttachConsole");
func_AttachConsole = (proto_AttachConsole *)GetProcAddress(lib_kernel32, "AttachConsole");
if ( ! func_AttachConsole )
if (! func_AttachConsole) {
return;
}
lib_ntdll = LoadLibrary("ntdll.dll");
if ( lib_ntdll )
func_NtQueryObject = (proto_NtQueryObject*)GetProcAddress(lib_ntdll, "NtQueryObject");
if (lib_ntdll) {
func_NtQueryObject = (proto_NtQueryObject *)GetProcAddress(lib_ntdll, "NtQueryObject");
}
// Ignore if HANDLE is not attached console
reopen_stdin = WINAPI_CheckIfConsoleHandle(GetStdHandle(STD_INPUT_HANDLE));
@ -163,23 +179,27 @@ static void WINAPI_AttachConsole(void) {
attached = func_AttachConsole(-1);
if ( ! attached )
if (! attached) {
return;
}
if ( reopen_stdin )
if (reopen_stdin) {
WINAPI_ReopenFileFromHandle(GetStdHandle(STD_INPUT_HANDLE), stdin, "r");
else
} else {
WINAPI_SetStdHandleFromFile(STD_INPUT_HANDLE, stdin);
}
if ( reopen_stdout )
if (reopen_stdout) {
WINAPI_ReopenFileFromHandle(GetStdHandle(STD_OUTPUT_HANDLE), stdout, "w");
else
} else {
WINAPI_SetStdHandleFromFile(STD_OUTPUT_HANDLE, stdout);
}
if ( reopen_stderr )
if (reopen_stderr) {
WINAPI_ReopenFileFromHandle(GetStdHandle(STD_ERROR_HANDLE), stderr, "w");
else
} else {
WINAPI_SetStdHandleFromFile(STD_ERROR_HANDLE, stderr);
}
#ifdef __cplusplus
std::cin.clear();