Skip to content

Commit

Permalink
rename CrashIf() => ReportIf
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 28, 2024
1 parent 3781ebf commit be452dd
Show file tree
Hide file tree
Showing 123 changed files with 874 additions and 871 deletions.
10 changes: 5 additions & 5 deletions src/Accelerators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static WORD ParseVirtKey(const char* s) {
if (idx < 0) {
return 0;
}
CrashIf(idx >= dimof(gVirtKeysIds));
ReportIf(idx >= dimof(gVirtKeysIds));
WORD keyId = gVirtKeysIds[idx];
return keyId;
}
Expand Down Expand Up @@ -600,7 +600,7 @@ static HACCEL gAccelTables[3] = {
/* returns a pointer to HACCEL so that we can update it and message loop will use
the latest version */
static void CreateSumatraAcceleratorTable() {
CrashIf(gAccelTables[0] || gAccelTables[1] || gAccelTables[2]);
ReportIf(gAccelTables[0] || gAccelTables[1] || gAccelTables[2]);

int nBuiltIn = (int)dimof(gBuiltInAccelerators);

Expand Down Expand Up @@ -671,11 +671,11 @@ static void CreateSumatraAcceleratorTable() {
gAccelsCount = nAccels;

gAccelTables[0] = CreateAcceleratorTableW(gAccels, gAccelsCount);
CrashIf(gAccelTables[0] == nullptr);
ReportIf(gAccelTables[0] == nullptr);
gAccelTables[1] = CreateAcceleratorTableW(editAccels, nEditAccels);
CrashIf(gAccelTables[1] == nullptr);
ReportIf(gAccelTables[1] == nullptr);
gAccelTables[2] = CreateAcceleratorTableW(treeViewAccels, nTreeViewAccels);
CrashIf(gAccelTables[2] == nullptr);
ReportIf(gAccelTables[2] == nullptr);

free(toFreeAccels);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ static const char* gAnnotReadableNames =
/*
const char* AnnotationName(AnnotationType tp) {
int n = (int)tp;
CrashIf(n < -1 || n > (int)AnnotationType::ThreeD);
ReportIf(n < -1 || n > (int)AnnotationType::ThreeD);
if (n < 0) {
return "Unknown";
}
const char* s = seqstrings::IdxToStr(gAnnotNames, n);
CrashIf(!s);
ReportIf(!s);
return s;
}
*/
Expand All @@ -132,7 +132,7 @@ TempStr AnnotationReadableNameTemp(AnnotationType tp) {
return (char*)"Unknown";
}
char* s = (char*)seqstrings::IdxToStr(gAnnotReadableNames, n);
CrashIf(!s);
ReportIf(!s);
return s;
}

Expand All @@ -144,12 +144,12 @@ bool IsAnnotationEq(Annotation* a1, Annotation* a2) {
}

AnnotationType Type(Annotation* annot) {
CrashIf((int)annot->type < 0);
ReportIf((int)annot->type < 0);
return annot->type;
}

int PageNo(Annotation* annot) {
CrashIf(annot->pageNo < 1);
ReportIf(annot->pageNo < 1);
return annot->pageNo;
}

Expand Down Expand Up @@ -246,7 +246,7 @@ bool SetQuadding(Annotation* annot, int newQuadding) {
{
auto ctx = e->Ctx();
ScopedCritSec cs(e->ctxAccess);
CrashIf(!IsValidQuadding(newQuadding));
ReportIf(!IsValidQuadding(newQuadding));
bool didChange = Quadding(annot) != newQuadding;
if (!didChange) {
return false;
Expand Down Expand Up @@ -513,7 +513,7 @@ static PdfColor PdfColorFromFloat(fz_context* ctx, int n, float color[4]) {
}
return MkPdfColorFromFloat(rgb[0], rgb[1], rgb[2]);
}
CrashIf(true);
ReportIf(true);
return 0;
}

Expand Down Expand Up @@ -872,7 +872,7 @@ void SetOpacity(Annotation* annot, int newOpacity) {
{
auto ctx = e->Ctx();
ScopedCritSec cs(e->ctxAccess);
CrashIf(newOpacity < 0 || newOpacity > 255);
ReportIf(newOpacity < 0 || newOpacity > 255);
newOpacity = std::clamp(newOpacity, 0, 255);
float fopacity = (float)newOpacity / 255.f;

Expand Down
2 changes: 1 addition & 1 deletion src/AppColors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
#define ABOUT_BG_GRAY_COLOR RGB(0xF2, 0xF2, 0xF2)

COLORREF GetAppColor(AppColor col) {
CrashIf(true);
ReportIf(true);
return 0;
}
10 changes: 5 additions & 5 deletions src/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static int GetWeekCount() {
date20110101.wDay = 1;
FILETIME origTime, currTime;
BOOL ok = SystemTimeToFileTime(&date20110101, &origTime);
CrashIf(!ok);
ReportIf(!ok);
GetSystemTimeAsFileTime(&currTime);
return (currTime.dwHighDateTime - origTime.dwHighDateTime) / 1408;
// 1408 == (10 * 1000 * 1000 * 60 * 60 * 24 * 7) / (1 << 32)
Expand Down Expand Up @@ -96,7 +96,7 @@ static void setMinMax(int& i, int minVal, int maxVal) {

/* Caller needs to CleanUpSettings() */
bool LoadSettings() {
CrashIf(gGlobalPrefs);
ReportIf(gGlobalPrefs);

auto timeStart = TimeGet();

Expand All @@ -118,7 +118,7 @@ bool LoadSettings() {
gprefs->lastPrefUpdate = file::GetModificationTime(settingsPath);
gprefs->defaultDisplayModeEnum = DisplayModeFromString(gprefs->defaultDisplayMode, DisplayMode::Automatic);
gprefs->defaultZoomFloat = ZoomFromString(gprefs->defaultZoom, kZoomActualSize);
CrashIf(!IsValidZoom(gprefs->defaultZoomFloat));
ReportIf(!IsValidZoom(gprefs->defaultZoomFloat));

int weekDiff = GetWeekCount() - gprefs->openCountWeek;
gprefs->openCountWeek = GetWeekCount();
Expand Down Expand Up @@ -272,7 +272,7 @@ bool SaveSettings() {
str::Free(prevPrefs.data());
str::Free(prefs.data());
};
CrashIf(prefs.empty());
ReportIf(prefs.empty());
if (prefs.empty()) {
return false;
}
Expand Down Expand Up @@ -371,7 +371,7 @@ void RegisterSettingsForFileChanges() {
return;
}

CrashIf(gWatchedSettingsFile); // only call me once
ReportIf(gWatchedSettingsFile); // only call me once
TempStr path = GetSettingsPathTemp();
gWatchedSettingsFile = FileWatcherSubscribe(path, schedulePrefsReload);
}
Expand Down
22 changes: 11 additions & 11 deletions src/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void UpdateDeltaPerLine() {
///// methods needed for FixedPageUI canvases with document loaded /////

static void OnVScroll(MainWindow* win, WPARAM wp) {
CrashIf(!win->AsFixed());
ReportIf(!win->AsFixed());

SCROLLINFO si{};
si.cbSize = sizeof(si);
Expand Down Expand Up @@ -154,7 +154,7 @@ static void OnVScroll(MainWindow* win, WPARAM wp) {
}

static void OnHScroll(MainWindow* win, WPARAM wp) {
CrashIf(!win->AsFixed());
ReportIf(!win->AsFixed());

SCROLLINFO si{};
si.cbSize = sizeof(si);
Expand Down Expand Up @@ -307,7 +307,7 @@ static bool gShowAnnotationNotification = true;

static void OnMouseMove(MainWindow* win, int x, int y, WPARAM) {
DisplayModel* dm = win->AsFixed();
CrashIf(!dm);
ReportIf(!dm);

if (win->InPresentation()) {
if (PM_BLACK_SCREEN == win->presentation || PM_WHITE_SCREEN == win->presentation) {
Expand Down Expand Up @@ -471,7 +471,7 @@ static void OnMouseLeftButtonDown(MainWindow* win, int x, int y, WPARAM key) {
if (isMoveableAnnot) {
StartAnnotationDrag(win, annot, pt);
} else {
CrashIf(win->linkOnLastButtonDown);
ReportIf(win->linkOnLastButtonDown);
IPageElement* pageEl = dm->GetElementAtPos(pt, nullptr);
if (pageEl) {
if (pageEl->Is(kindPageElementDest)) {
Expand Down Expand Up @@ -502,7 +502,7 @@ static void OnMouseLeftButtonDown(MainWindow* win, int x, int y, WPARAM key) {

static void OnMouseLeftButtonUp(MainWindow* win, int x, int y, WPARAM key) {
DisplayModel* dm = win->AsFixed();
CrashIf(!dm);
ReportIf(!dm);
auto ma = win->mouseAction;
if (MouseAction::None == ma || IsRightDragging(win)) {
return;
Expand Down Expand Up @@ -691,7 +691,7 @@ static void OnMouseRightButtonDown(MainWindow* win, int x, int y) {
} else if (win->mouseAction != MouseAction::None) {
return;
}
CrashIf(!win->AsFixed());
ReportIf(!win->AsFixed());

SetFocus(win->hwndFrame);

Expand All @@ -702,7 +702,7 @@ static void OnMouseRightButtonDown(MainWindow* win, int x, int y) {
}

static void OnMouseRightButtonUp(MainWindow* win, int x, int y, WPARAM key) {
CrashIf(!win->AsFixed());
ReportIf(!win->AsFixed());
if (!IsRightDragging(win)) {
return;
}
Expand Down Expand Up @@ -883,7 +883,7 @@ NO_INLINE static void PaintCurrentEditAnnotationMark(WindowTab* tab, HDC hdc, Di
}

static void DrawDocument(MainWindow* win, HDC hdc, RECT* rcArea) {
CrashIf(!win->AsFixed());
ReportIf(!win->AsFixed());
if (!win->AsFixed()) {
return;
}
Expand Down Expand Up @@ -970,7 +970,7 @@ static void DrawDocument(MainWindow* win, HDC hdc, RECT* rcArea) {
if (!pageInfo || 0.0f == pageInfo->visibleRatio) {
continue;
}
CrashIf(!pageInfo->shown);
ReportIf(!pageInfo->shown);
if (!pageInfo->shown) {
continue;
}
Expand Down Expand Up @@ -1121,7 +1121,7 @@ static LRESULT OnSetCursorMouseNone(MainWindow* win, HWND hwnd) {
}

static LRESULT OnSetCursor(MainWindow* win, HWND hwnd) {
CrashIf(win->hwndCanvas != hwnd);
ReportIf(win->hwndCanvas != hwnd);
if (win->mouseAction != MouseAction::None) {
win->DeleteToolTip();
}
Expand Down Expand Up @@ -1851,7 +1851,7 @@ LRESULT CALLBACK WndProcCanvas(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
MainWindow* win = FindMainWindowByHwnd(hwnd);
switch (msg) {
case WM_DROPFILES:
CrashIf(lp != 0 && lp != 1);
ReportIf(lp != 0 && lp != 1);
OnDropFiles(win, (HDROP)wp, !lp);
return 0;

Expand Down
2 changes: 1 addition & 1 deletion src/CanvasAboutUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void OnMouseLeftButtonUpAbout(MainWindow* win, int x, int y, WPARAM) {
} else {
// assume it's a thumbnail of a document
auto path = url;
CrashIf(!path);
ReportIf(!path);
LoadArgs args(path, win);
// ctrl forces always opening
args.activateExisting = !IsCtrlPressed();
Expand Down
8 changes: 4 additions & 4 deletions src/ChmFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static char* GetCharZ(const ByteSlice& d, size_t off) {
if (off >= len) {
return nullptr;
}
CrashIf(!memchr(data + off, '\0', len - off + 1)); // data is zero-terminated
ReportIf(!memchr(data + off, '\0', len - off + 1)); // data is zero-terminated
u8* str = data + off;
if (str::IsEmpty((const char*)str)) {
return nullptr;
Expand Down Expand Up @@ -367,7 +367,7 @@ void ChmFile::GetAllPaths(StrVec* v) const {
... siblings ...
*/
static bool VisitChmTocItem(EbookTocVisitor* visitor, HtmlElement* el, uint cp, int level) {
CrashIf(el->tag != Tag_Object || level > 1 && (!el->up || el->up->tag != Tag_Li));
ReportIf(el->tag != Tag_Object || level > 1 && (!el->up || el->up->tag != Tag_Li));

AutoFreeWStr name, local;
for (el = el->GetChildByTag(Tag_Param); el; el = el->next) {
Expand Down Expand Up @@ -416,7 +416,7 @@ static bool VisitChmTocItem(EbookTocVisitor* visitor, HtmlElement* el, uint cp,
... siblings ...
*/
static bool VisitChmIndexItem(EbookTocVisitor* visitor, HtmlElement* el, uint cp, int level) {
CrashIf(el->tag != Tag_Object || level > 1 && (!el->up || el->up->tag != Tag_Li));
ReportIf(el->tag != Tag_Object || level > 1 && (!el->up || el->up->tag != Tag_Li));

StrVec references;
AutoFreeWStr keyword, name;
Expand Down Expand Up @@ -471,7 +471,7 @@ static bool VisitChmIndexItem(EbookTocVisitor* visitor, HtmlElement* el, uint cp
}

static void WalkChmTocOrIndex(EbookTocVisitor* visitor, HtmlElement* list, uint cp, bool isIndex, int level = 1) {
CrashIf(Tag_Ul != list->tag);
ReportIf(Tag_Ul != list->tag);

// some broken ToCs wrap every <li> into its own <ul>
for (; list && Tag_Ul == list->tag; list = list->next) {
Expand Down
20 changes: 10 additions & 10 deletions src/ChmModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static IPageDestination* NewChmNamedDest(const char* url, int pageNo) {
dest = pdest;
}
dest->pageNo = pageNo;
CrashIf(!dest->kind);
ReportIf(!dest->kind);
dest->rect = RectF(DEST_USE_DEFAULT, DEST_USE_DEFAULT, DEST_USE_DEFAULT, DEST_USE_DEFAULT);
return dest;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ void ChmModel::GoToPage(int pageNo, bool) {
}

bool ChmModel::SetParentHwnd(HWND hwnd) {
CrashIf(htmlWindow || htmlWindowCb);
ReportIf(htmlWindow || htmlWindowCb);
htmlWindowCb = new HtmlWindowHandler(this);
htmlWindow = HtmlWindow::Create(hwnd, htmlWindowCb);
if (!htmlWindow) {
Expand Down Expand Up @@ -221,7 +221,7 @@ bool ChmModel::DisplayPage(const char* pageUrl) {
}

void ChmModel::ScrollTo(int, RectF, float) {
CrashIf(true);
ReportIf(true);
}

bool ChmModel::HandleLink(IPageDestination* link, ILinkHandler*) {
Expand Down Expand Up @@ -331,9 +331,9 @@ class ChmTocBuilder : public EbookTocVisitor {
bool inserted = urlsSet.Insert(plainUrl, pageNo, &pageNo);
if (inserted) {
pages->Append(plainUrl);
CrashIf(pageNo != pages->Size());
ReportIf(pageNo != pages->Size());
} else {
CrashIf(pageNo == pages->Size() + 1);
ReportIf(pageNo == pages->Size() + 1);
}
return pageNo;
}
Expand All @@ -348,7 +348,7 @@ class ChmTocBuilder : public EbookTocVisitor {
for (int i = 0; i < n; i++) {
const char* url = pages->At(i);
bool inserted = urlsSet.Insert(url, i + 1, nullptr);
CrashIf(!inserted);
ReportIf(!inserted);
}
}

Expand Down Expand Up @@ -377,7 +377,7 @@ bool ChmModel::Load(const char* fileName) {
tocTrace = new Vec<ChmTocTraceItem>();
ChmTocBuilder tmpTocBuilder(doc, &pages, tocTrace, &poolAlloc);
doc->ParseToc(&tmpTocBuilder);
CrashIf(pages.Size() == 0);
ReportIf(pages.Size() == 0);
return pages.Size() > 0;
}

Expand Down Expand Up @@ -541,7 +541,7 @@ TocTree* ChmModel::GetToc() {
TocItem* item = NewChmTocItem(nullptr, ti.title, ti.pageNo, ti.url);
item->id = ++idCounter;
// append the item at the correct level
CrashIf(ti.level < 1);
ReportIf(ti.level < 1);
if ((size_t)ti.level <= levels.size()) {
levels.RemoveAt(ti.level, levels.size() - ti.level);
levels.Last()->AddSiblingAtEnd(item);
Expand Down Expand Up @@ -577,8 +577,8 @@ float ChmModel::GetNextZoomStep(float towardsLevel) const {
}

Vec<float>* zoomLevels = gGlobalPrefs->zoomLevels;
CrashIf(zoomLevels->size() != 0 && (zoomLevels->at(0) < kZoomMin || zoomLevels->Last() > kZoomMax));
CrashIf(zoomLevels->size() != 0 && zoomLevels->at(0) > zoomLevels->Last());
ReportIf(zoomLevels->size() != 0 && (zoomLevels->at(0) < kZoomMin || zoomLevels->Last() > kZoomMax));
ReportIf(zoomLevels->size() != 0 && zoomLevels->at(0) > zoomLevels->Last());

const float FUZZ = 0.01f;
float newZoom = towardsLevel;
Expand Down
Loading

0 comments on commit be452dd

Please sign in to comment.