File indexing completed on 2024-05-12 04:34:00
0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*- 0002 /* 0003 * SPDX-FileCopyrightText: 1994 Paul Vojta. All rights reserved. 0004 * 0005 * SPDX-License-Identifier: BSD-2-Clause 0006 * 0007 * NOTE: 0008 * xdvi is based on prior work as noted in the modification history, below. 0009 */ 0010 0011 /* 0012 * DVI previewer for X. 0013 * 0014 * Eric Cooper, CMU, September 1985. 0015 * 0016 * Code derived from dvi-imagen.c. 0017 * 0018 * Modification history: 0019 * 1/1986 Modified for X.10 --Bob Scheifler, MIT LCS. 0020 * 7/1988 Modified for X.11 --Mark Eichin, MIT 0021 * 12/1988 Added 'R' option, toolkit, magnifying glass 0022 * --Paul Vojta, UC Berkeley. 0023 * 2/1989 Added tpic support --Jeffrey Lee, U of Toronto 0024 * 4/1989 Modified for System V --Donald Richardson, Clarkson Univ. 0025 * 3/1990 Added VMS support --Scott Allendorf, U of Iowa 0026 * 7/1990 Added reflection mode --Michael Pak, Hebrew U of Jerusalem 0027 * 1/1992 Added greyscale code --Till Brychcy, Techn. Univ. Muenchen 0028 * and Lee Hetherington, MIT 0029 * 4/1994 Added DPS support, bounding box 0030 * --Ricardo Telichevesky 0031 * and Luis Miguel Silveira, MIT RLE. 0032 */ 0033 0034 #include <config.h> 0035 0036 #include "debug_dvi.h" 0037 #include "xdvi.h" 0038 0039 #include <KLocalizedString> 0040 #include <KMessageBox> 0041 0042 #include <cstdlib> 0043 0044 #include <QLoggingCategory> 0045 0046 /* 0047 * General utility routines. 0048 */ 0049 0050 /* 0051 * Print error message and quit. 0052 */ 0053 0054 void oops(const QString &message) 0055 { 0056 qCCritical(OkularDviDebug) << "Fatal Error:" << message; 0057 0058 KMessageBox::error(nullptr, i18n("Fatal error.\n\n") + message + i18n("\n\n\ 0059 This probably means that either you found a bug in Okular,\n\ 0060 or that the DVI file, or auxiliary files (such as font files, \n\ 0061 or virtual font files) were really badly broken.\n\ 0062 Okular will abort after this message. If you believe that you \n\ 0063 found a bug, or that Okular should behave better in this situation\n\ 0064 please report the problem.")); 0065 exit(1); 0066 } 0067 0068 /* 0069 * Read size bytes from the FILE fp, constructing them into a 0070 * signed/unsigned integer. 0071 */ 0072 unsigned long num(FILE *fp, int size) 0073 { 0074 long x = 0; 0075 0076 while (size--) { 0077 x = (x << 8) | one(fp); 0078 } 0079 return x; 0080 } 0081 0082 long snum(FILE *fp, int size) 0083 { 0084 long x; 0085 0086 #ifdef __STDC__ 0087 x = (signed char)getc(fp); // NOLINT(bugprone-signed-char-misuse) This code is decades old, so prefer not to touch it 0088 #else 0089 x = (unsigned char)getc(fp); 0090 if (x & 0x80) 0091 x -= 0x100; 0092 #endif 0093 while (--size) { 0094 x = (x << 8) | one(fp); 0095 } 0096 return x; 0097 }