From 7b98e444161e3f72f80967ccd319cc568aef9e2f Mon Sep 17 00:00:00 2001 From: Andrew Jenner Date: Mon, 20 Feb 2012 20:39:40 -0800 Subject: [PATCH] Fix Handle --- 4to8/4to8.cpp | 18 +- 8088/8088.cpp | 10 +- 8088/arduino_keyboard/keyboard/keyboard.cpp | 8 +- 8088/arduino_keyboard/run/run.cpp | 14 +- 8088/arduino_keyboard/send/send.cpp | 17 +- .../cga/attribute_clash/attribute_clash.cpp | 23 +- .../rose_hres_composite_50.config | 2 +- .../rose_lres_composite.config | 2 +- .../attribute_clash/rose_lres_digital.config | 2 +- 8088/demo/cga/raster/raster.cpp | 3 +- 8088/dos/bin_to_hex/bin_to_hex.cpp | 12 +- 8088/hd/decode/decode.cpp | 11 +- 8088/rip_rom/unescape/unescape.cpp | 6 +- 8088/serial/run/run.cpp | 22 +- alfe/Run.cpp | 4 +- alfe/alfe.cpp | 10 +- codec/codec.cpp | 18 +- crc32/crc32.cpp | 15 +- crc32/crc32.vcxproj | 13 +- crc32/crc32.vcxproj.filters | 66 +++ fractals/bif/bif.cpp | 4 +- include/alfe/any.h | 4 +- include/alfe/array.h | 5 +- include/alfe/assert.h | 3 +- include/alfe/audio.h | 5 +- include/alfe/bitmap.h | 183 ++----- include/alfe/bitmap_png.h | 162 ++++++ include/alfe/character_source.h | 38 +- include/alfe/colour_space.h | 2 + include/alfe/com.h | 3 +- include/alfe/complex.h | 2 + include/alfe/config_file.h | 25 +- include/alfe/convolution_pipe.h | 3 +- include/alfe/exception.h | 35 +- include/alfe/file.h | 494 +++++------------ include/alfe/file_handle.h | 63 +++ include/alfe/find_handle.h | 182 +++++++ include/alfe/fix.h | 4 +- include/alfe/fractal.h | 2 + include/alfe/gcd.h | 2 + include/alfe/handle.h | 95 ++-- include/alfe/hash_table.h | 5 +- include/alfe/integer_types.h | 2 + include/alfe/linked_list.h | 4 +- include/alfe/main.h | 99 ++-- include/alfe/minimum_maximum.h | 2 + include/alfe/owning_array.h | 2 + include/alfe/pipes.h | 32 +- include/alfe/random.h | 4 +- include/alfe/rational.h | 4 +- include/alfe/reference_counted.h | 4 +- include/alfe/reference_counted_array.h | 11 +- include/alfe/rotors.h | 2 + include/alfe/scratch.txt | 8 +- include/alfe/set.h | 7 +- include/alfe/space.h | 6 +- include/alfe/stack.h | 4 +- include/alfe/string.h | 47 +- include/alfe/swap.h | 2 + include/alfe/symbol.h | 2 + include/alfe/terminal6.h | 508 +++++++++--------- include/alfe/thread.h | 18 +- include/alfe/type.h | 3 +- include/alfe/uncopyable.h | 2 + include/alfe/user.h | 27 +- include/alfe/value.h | 4 +- include/alfe/vectors.h | 2 + intervals/simulator/simulator2.cpp | 1 - multifunction/multifunction.cpp | 2 +- perceptual/perceptual.cpp | 4 +- run_random/run_random.cpp | 2 +- scratch.txt | 5 - test/test.cpp | 4 +- tone_matrix/debugger/debugger.cpp | 2 +- 74 files changed, 1305 insertions(+), 1118 deletions(-) create mode 100644 crc32/crc32.vcxproj.filters create mode 100644 include/alfe/bitmap_png.h create mode 100644 include/alfe/file_handle.h create mode 100644 include/alfe/find_handle.h diff --git a/4to8/4to8.cpp b/4to8/4to8.cpp index 7c1aef71..2acafa06 100644 --- a/4to8/4to8.cpp +++ b/4to8/4to8.cpp @@ -2,18 +2,16 @@ int main() { - File inFile("/t/projects/emulation/pc/ibm5150.net/f/fire/fire.ech"); - FileHandle in(inFile); - in.openRead(); - File outFile("fire.raw"); - FileHandle out(outFile); - out.openWrite(); - Array four; + FileHandle in = + File("/t/projects/emulation/pc/ibm5150.net/f/fire/fire.ech"). + openRead(); + FileHandle out = File("fire.raw").openWrite(); + int s = in.size(); - four.allocate(s); + Array four(s); in.read(&four[0], s); - Array eight; - eight.allocate(s*2); + + Array eight(s*2); for (int i = 0; i < s; ++i) { eight[i*2] = (four[i]>>4) * 0x11; eight[i*2+1] = (four[i] & 0xf) * 0x11; diff --git a/8088/8088.cpp b/8088/8088.cpp index fb9106ee..48bf4be9 100644 --- a/8088/8088.cpp +++ b/8088/8088.cpp @@ -769,7 +769,7 @@ typedef DisassemblerTemplate Disassembler; template class Intel8088Template : public Component { public: - Intel8088Template(Simulator* simulator, Handle* console, int stopAtCycle) + Intel8088Template(Simulator* simulator, int stopAtCycle) : _flagsData(0x0002), // ? _state(stateFetch), _ip(0), @@ -785,7 +785,6 @@ template class Intel8088Template : public Component _abandonFetch(false), _useIO(false), _halted(false), - _console(console), _wait(0), _newInstruction(true), _newIP(0), @@ -904,7 +903,7 @@ template class Intel8088Template : public Component } line += _flags.text(); _newInstruction = false; - _console->write(line + "\n"); + console.write(line + "\n"); ++_cycle; if (_halted || _cycle == _stopAtCycle) _simulator->halt(); @@ -2992,7 +2991,6 @@ stateLoadD, stateLoadD, stateMisc, stateMisc}; int _rep; bool _useIO; bool _halted; - Handle* _console; bool _newInstruction; UInt16 _newIP; ISA8BitBus* _bus; @@ -3038,7 +3036,7 @@ class Program : public ProgramBase void run() { if (_arguments.count() < 2) { - _console.write("Syntax: " + _arguments[0] + + console.write("Syntax: " + _arguments[0] + " \n"); return; } @@ -3101,7 +3099,7 @@ class Program : public ProgramBase String stopSaveState = config.get("stopSaveState"); Simulator simulator; - Intel8088 cpu(&simulator, &_console, stopAtCycle); + Intel8088 cpu(&simulator, stopAtCycle); cpu.setBus(&bus); simulator.addComponent(&bus); simulator.addComponent(&cpu); diff --git a/8088/arduino_keyboard/keyboard/keyboard.cpp b/8088/arduino_keyboard/keyboard/keyboard.cpp index 48712b83..d000a407 100644 --- a/8088/arduino_keyboard/keyboard/keyboard.cpp +++ b/8088/arduino_keyboard/keyboard/keyboard.cpp @@ -4,9 +4,9 @@ class Program : public ProgramBase { public: - int run() + void run() { - _com.set(CreateFile( + _com = Handle::Auto(CreateFile( L"COM3", GENERIC_READ | GENERIC_WRITE, 0, // must be opened with exclusive-access @@ -56,7 +56,7 @@ class Program : public ProgramBase KeyboardWindow window(kwp); window.show(_nCmdShow); - return pumpMessages(); + pumpMessages(); } private: template class KeyboardWindow : public Base @@ -219,5 +219,5 @@ class Program : public ProgramBase _com.write(value); } - AutoHandle _com; + Handle _com; }; diff --git a/8088/arduino_keyboard/run/run.cpp b/8088/arduino_keyboard/run/run.cpp index 855d9602..b99298c7 100644 --- a/8088/arduino_keyboard/run/run.cpp +++ b/8088/arduino_keyboard/run/run.cpp @@ -8,7 +8,7 @@ class Program : public ProgramBase void run() { if (_arguments.count() == 1) { - _console.write("Usage: run [-c] \n"); + console.write("Usage: run [-c] \n"); return; } int fileNameArgument = 1; @@ -21,7 +21,7 @@ class Program : public ProgramBase String data = File(fileName).contents(); int l = data.length(); - _com.set(CreateFile( + _com = Handle::Auto(CreateFile( L"COM3", GENERIC_READ | GENERIC_WRITE, 0, // must be opened with exclusive-access @@ -95,7 +95,7 @@ class Program : public ProgramBase // When running a .com file, we need the instruction pointer to start // at 0x100. We do this by prepending 0x100 NOP bytes at the beginning. // In DOS this area would contain the Program Segment Prefix structure. - _console.write(hex(l) + "\n"); + console.write(hex(l) + "\n"); Byte checkSum = 0; if (comFile) { addLength(l + 0x100); @@ -110,13 +110,13 @@ class Program : public ProgramBase addByte(data[i]); // Send data byte checkSum += data[i]; if ((i & 0xff) == 0) - _console.write("."); + console.write("."); } addByte(checkSum); flush(); IF_ZERO_THROW(FlushFileBuffers(_com)); - _console.write("Upload complete.\n"); + console.write("Upload complete.\n"); // Dump bytes from COM port to stdout until we receive ^Z //thread.join(); } @@ -136,7 +136,7 @@ class Program : public ProgramBase c = _program->_com.tryReadByte(); if (c == 26 || c == -1) break; - _program->_console.write(c); + console.write(c); } while (true); } while (c != 26); } @@ -180,7 +180,7 @@ class Program : public ProgramBase _com.write(value); } - AutoHandle _com; + Handle _com; Byte _buffer[0xff]; int _bufferCount; diff --git a/8088/arduino_keyboard/send/send.cpp b/8088/arduino_keyboard/send/send.cpp index b3336abb..6d76cb46 100644 --- a/8088/arduino_keyboard/send/send.cpp +++ b/8088/arduino_keyboard/send/send.cpp @@ -8,19 +8,19 @@ class Program : public ProgramBase void run() { if (_arguments.count() == 1) { - _console.write("Usage: send \n"); - return; + console.write("Usage: send \n"); + return 0; } String fileName = _arguments[1]; String data = File(fileName).contents(); int l = data.length(); if (l > 0x400) { - _console.write("Error: " + fileName + " is " + l + + console.write("Error: " + fileName + " is " + l + " bytes (must be less than 1024).\n"); - return; + return 0; } - _com.set(CreateFile( + _com = Handle::Auto(CreateFile( L"COM3", GENERIC_READ | GENERIC_WRITE, 0, // must be opened with exclusive-access @@ -72,8 +72,9 @@ class Program : public ProgramBase sendByte(l >> 8); // Send high byte of length for (int i = 0; i < l; ++i) sendByte(data[i]); // Send program byte - _console.write("Send complete.\n"); + console.write("Send complete.\n"); thread.join(); + return 0; } private: class ReaderThread : public Thread @@ -90,7 +91,7 @@ class Program : public ProgramBase int c = _program->_com.read(); if (c == 26) break; - _program->_console.write(c); + console.write(c); } } while (true); } @@ -106,5 +107,5 @@ class Program : public ProgramBase _com.write(value); } - AutoHandle _com; + Handle _com; }; diff --git a/8088/demo/cga/attribute_clash/attribute_clash.cpp b/8088/demo/cga/attribute_clash/attribute_clash.cpp index c6fb35f8..8476d753 100644 --- a/8088/demo/cga/attribute_clash/attribute_clash.cpp +++ b/8088/demo/cga/attribute_clash/attribute_clash.cpp @@ -6,6 +6,7 @@ #include "alfe/thread.h" #include "alfe/bitmap.h" #include "alfe/config_file.h" +#include "alfe/bitmap_png.h" typedef Vector3 YIQ; @@ -124,8 +125,8 @@ class AttributeClashImage : public Image private: ColourSpace _c; }; - Bitmap srgbInputOriginal; - srgbInputOriginal.load(File(inputPictureFileName)); + Bitmap srgbInputOriginal = + PNGFileFormat().load(inputPictureFileName); Bitmap > linearInput(srgbInputOriginal.size()); srgbInputOriginal.convert(linearInput, ConvertSRGBToLinear()); Bitmap > linearScaled(_inputSize); @@ -225,7 +226,7 @@ class AttributeClashImage : public Image // _srgbOutput[p] = _srgbOutput[6]; // _perceptualOutput[p] = _colourSpace.fromSrgb(_srgbOutput[p]); // Colour c; -// if ((Vector(x, y) - _compositeOffset).inside(_pictureSize)) { +// if ((Vector(x, y) - _compositeOffset).inside(_outputSize)) { // c = _colourSpace.fromSrgb(SRGB( // srgbRow[ip], srgbRow[ip + 1], srgbRow[ip + 2])); // ip += 3; @@ -238,8 +239,8 @@ class AttributeClashImage : public Image // } // } // -// for (int y = 0; y < _pictureSize.y; ++y) -// for (int x = 0; x < _pictureSize.x; ++x) { +// for (int y = 0; y < _outputSize.y; ++y) +// for (int x = 0; x < _outputSize.x; ++x) { // int col = (y/8)*40 + (x/16); // int ch; // int at; @@ -259,7 +260,7 @@ class AttributeClashImage : public Image // ++fg; // at = fg + (bg << 4); // } -// int o = (y*_pictureSize.x + x)/8; +// int o = (y*_outputSize.x + x)/8; // _dataOutput[o*2] = ch; // _dataOutput[o*2 + 1] = at; // _position = Vector((x/8)*8, y); @@ -579,7 +580,7 @@ class AttributeClashImage : public Image // } // } // int character = _characters[bestPattern]; -// int p = (_position.y*_pictureSize.x + _position.x)/(_hres ? 4 : 8); +// int p = (_position.y*_outputSize.x + _position.x)/(_hres ? 4 : 8); // if (character != _dataOutput[p] || bestAt != _dataOutput[p + 1]) { // _changed = true; // _dataOutput[p] = character; @@ -700,13 +701,13 @@ class AttributeClashImage : public Image class Program : public ProgramBase { public: - int run() + void run() { if (_arguments.count() == 1) { NullTerminatedWideString s ("Usage: attribute_clash \n"); MessageBox(NULL, s, L"Error", MB_OK | MB_ICONERROR); - return 0; + return; } ConfigFile config; @@ -735,7 +736,7 @@ class Program : public ProgramBase config.addOption("inputPicture", Type::string); config.addOption("outputNTSC", Type::string); config.addOption("outputComposite", Type::string); - config.addOption("outputRGB", Type::string); + config.addOption("outputDigital", Type::string); config.addOption("outputData", Type::string); config.addOption("compositeTarget", Type::boolean); config.addOption("hres", Type::boolean); @@ -759,6 +760,6 @@ class Program : public ProgramBase AnimatedWindow window(awp); window.show(_nCmdShow); - return pumpMessages(); + pumpMessages(); } }; diff --git a/8088/demo/cga/attribute_clash/rose_hres_composite_50.config b/8088/demo/cga/attribute_clash/rose_hres_composite_50.config index df3a3fe2..622d0cc6 100644 --- a/8088/demo/cga/attribute_clash/rose_hres_composite_50.config +++ b/8088/demo/cga/attribute_clash/rose_hres_composite_50.config @@ -1,4 +1,4 @@ -cgaRomFile = "/t/projects/emulation/pc/5788005.u33"; +cgaRomFile = "/t/projects/emulation/pc/roms/5788005.u33"; inputPicture = "/t/colorful_rose_cropped.png"; outputNTSC = "/t/rose_hres_composite_50.ntsc"; outputComposite = "/t/rose_hres_composite_50.png"; diff --git a/8088/demo/cga/attribute_clash/rose_lres_composite.config b/8088/demo/cga/attribute_clash/rose_lres_composite.config index 12054ae5..b23d1c93 100644 --- a/8088/demo/cga/attribute_clash/rose_lres_composite.config +++ b/8088/demo/cga/attribute_clash/rose_lres_composite.config @@ -1,4 +1,4 @@ -cgaRomFile = "/t/projects/emulation/pc/5788005.u33"; +cgaRomFile = "/t/projects/emulation/pc/roms/5788005.u33"; inputPicture = "/t/pictures/reenigne/colorful_rose_cropped.png"; outputNTSC = "/t/rose_lres_composite.ntsc"; outputComposite = "/t/rose_lres_composite.png"; diff --git a/8088/demo/cga/attribute_clash/rose_lres_digital.config b/8088/demo/cga/attribute_clash/rose_lres_digital.config index 8068d28f..92dd2ec1 100644 --- a/8088/demo/cga/attribute_clash/rose_lres_digital.config +++ b/8088/demo/cga/attribute_clash/rose_lres_digital.config @@ -1,4 +1,4 @@ -cgaRomFile = "/t/projects/emulation/pc/5788005.u33"; +cgaRomFile = "/t/projects/emulation/pc/roms/5788005.u33"; inputPicture = "/t/pictures/reenigne/colorful_rose_cropped.png"; outputNTSC = "/t/rose_lres_composite.ntsc"; outputComposite = "/t/rose_lres_composite.png"; diff --git a/8088/demo/cga/raster/raster.cpp b/8088/demo/cga/raster/raster.cpp index 800eeff9..b97f92a6 100644 --- a/8088/demo/cga/raster/raster.cpp +++ b/8088/demo/cga/raster/raster.cpp @@ -7,7 +7,7 @@ int barColours[barWidth] = {4, 6, 14, 15, 11, 9, 1}; class Program : public ProgramBase { public: - int run() + void run() { int barY[nBars]; FILE* out = fopen("raster.raw", "wb"); @@ -20,6 +20,5 @@ class Program : public ProgramBase } } fclose(out); - return 0; } }; diff --git a/8088/dos/bin_to_hex/bin_to_hex.cpp b/8088/dos/bin_to_hex/bin_to_hex.cpp index d7a82c41..862913a9 100644 --- a/8088/dos/bin_to_hex/bin_to_hex.cpp +++ b/8088/dos/bin_to_hex/bin_to_hex.cpp @@ -7,7 +7,7 @@ class Program : public ProgramBase void run() { if (_arguments.count() == 1) { - _console.write("Usage: bin_to_hex \n"); + console.write("Usage: bin_to_hex \n"); return; } String fileName = _arguments[1]; @@ -15,18 +15,18 @@ class Program : public ProgramBase int l = data.length(); // Write length bytes - _console.write(" .byte " + hex(l & 0xff, 2) + ", " + hex(l >> 8, 2) + + console.write(" .byte " + hex(l & 0xff, 2) + ", " + hex(l >> 8, 2) + "\n"); for (int i = 0; i < l; ++i) { int c = i & 7; if (c == 0) - _console.write(" .byte "); - _console.write(hex(data[i], 2)); + console.write(" .byte "); + console.write(hex(data[i], 2)); if (c < 7 && i < l - 1) - _console.write(", "); + console.write(", "); else - _console.write("\n"); + console.write("\n"); } } }; diff --git a/8088/hd/decode/decode.cpp b/8088/hd/decode/decode.cpp index bcb6446f..e7dee083 100644 --- a/8088/hd/decode/decode.cpp +++ b/8088/hd/decode/decode.cpp @@ -4,14 +4,11 @@ class Program : public ProgramBase { public: - void run() + int run() { - File input("capture.txt"); - String inputData = input.contents(); - FileHandle outputStatus(File("status.txt")); - outputStatus.openWrite(); - FileHandle outputData(File("hd.dat")); - outputData.openWrite(); + String inputData = File("capture.txt").contents(); + FileHandle outputStatus = File("status.txt").openWrite(); + FileHandle outputData = File("hd.dat").openWrite(); int i = 7*64 + 24; int fails = 0; do { diff --git a/8088/rip_rom/unescape/unescape.cpp b/8088/rip_rom/unescape/unescape.cpp index 16595bd5..fb6fffa0 100644 --- a/8088/rip_rom/unescape/unescape.cpp +++ b/8088/rip_rom/unescape/unescape.cpp @@ -6,10 +6,8 @@ class Program : public ProgramBase protected: void run() { - File input("f000.dat"); - String inputData = input.contents(); - FileHandle outputData(File("1501512.u18")); - outputData.openWrite(); + String inputData = File("f000.dat").contents(); + FileHandle outputData = File("1501512.u18").openWrite(); int j = 0; for (int i = 0; i < 0x10000; ++i) { if (inputData[j] == 0) { diff --git a/8088/serial/run/run.cpp b/8088/serial/run/run.cpp index 6fa9bc36..d42f358e 100644 --- a/8088/serial/run/run.cpp +++ b/8088/serial/run/run.cpp @@ -8,23 +8,21 @@ class Program : public ProgramBase void run() { if (_arguments.count() == 1) { - _console.write("Usage: run [-c] \n"); + console.write("Usage: run [-c] \n"); return; } int fileNameArgument = 1; bool comFile = false; - if (_arguments[1] == String("-c")) { + if (_arguments[1] == "-c") { comFile = true; fileNameArgument = 2; } - String fileName = _arguments[fileNameArgument]; - String data = File(fileName).contents(); + String data = File(_arguments[fileNameArgument]).contents(); int l = data.length(); //// Reset the machine //{ - // AutoHandle arduinoCom; - // arduinoCom.set(CreateFile( + // Handle arduinoCom = Handle::Auto(CreateFile( // L"COM3", // GENERIC_READ | GENERIC_WRITE, // 0, // must be opened with exclusive-access @@ -72,7 +70,7 @@ class Program : public ProgramBase //Sleep(3000); - _com.set(CreateFile( + _com = Handle::Auto(CreateFile( L"COM1", GENERIC_READ | GENERIC_WRITE, 0, // must be opened with exclusive-access @@ -131,7 +129,7 @@ class Program : public ProgramBase // When running a .com file, we need the instruction pointer to start // at 0x100. We do this by prepending 0x100 NOP bytes at the beginning. // In DOS this area would contain the Program Segment Prefix structure. - //_console.write(hex(l, 8) + "\n"); + //console.write(hex(l, 8) + "\n"); Byte checkSum = 0; if (comFile) { sendLength(l + 0x100); @@ -146,18 +144,18 @@ class Program : public ProgramBase sendByte(data[i]); // Send data byte checkSum += data[i]; if ((i & 0xff) == 0) - _console.write("."); + console.write("."); } sendByte(checkSum); //IF_ZERO_THROW(FlushFileBuffers(_com)); - //_console.write("Upload complete.\n"); + //console.write("Upload complete.\n"); // Dump bytes from COM port to stdout until we receive ^Z do { int c = _com.read(); if (c == 26) break; - _console.write(c); + console.write(c); } while (true); } private: @@ -172,7 +170,7 @@ class Program : public ProgramBase _com.write(value); } - AutoHandle _com; + Handle _com; friend class ReaderThread; }; diff --git a/alfe/Run.cpp b/alfe/Run.cpp index fbd2f650..b50e9773 100644 --- a/alfe/Run.cpp +++ b/alfe/Run.cpp @@ -95,7 +95,7 @@ void run(SymbolArray program) case atomExit: return; case atomPrintFunction: - stack.pop().write(Handle::consoleOutput()); + console.write(stack.pop()); break; case atomIntegerConstant: stack.push(instruction[1].integer()); @@ -256,7 +256,7 @@ void run(SymbolArray program) stack.setPointer(stack.pop()); break; case atomDereference: - stack.push(*stack.pop()); + stack.push(*stack.pop()); break; case atomDuplicate: { diff --git a/alfe/alfe.cpp b/alfe/alfe.cpp index 063ddcd7..ce954e39 100644 --- a/alfe/alfe.cpp +++ b/alfe/alfe.cpp @@ -291,8 +291,7 @@ class Program : public ProgramBase void run() { if (_arguments.count() < 2) { - _console.write("Syntax: " + _arguments[0] + - " \n"); + console.write("Syntax: " + _arguments[0] + " \n"); return; } File file(_arguments[1]); @@ -302,7 +301,8 @@ class Program : public ProgramBase int printLabel = Symbol::newLabel(); Symbol voidType(atomVoid); IdentifierCache* printCache = new IdentifierCache(Span(), printLabel); - Symbol print(atomPrintFunction, voidType, String("print"), SymbolArray(Symbol(atomString)), printCache); + Symbol print(atomPrintFunction, voidType, String("print"), + SymbolArray(Symbol(atomString)), printCache); print.setLabel(printLabel); scope->addFunction(String("print"), printLabel, Span()); @@ -312,7 +312,9 @@ class Program : public ProgramBase CharacterSource s = source; if (s.get() != -1) source.location().throwError("Expected end of file"); - Symbol main(atomFunctionDefinitionStatement, voidType, String(), SymbolArray(), Symbol(atomCompoundStatement, mainCode), new FunctionDefinitionCache(Span())); + Symbol main(atomFunctionDefinitionStatement, voidType, String(), + SymbolArray(), Symbol(atomCompoundStatement, mainCode), + new FunctionDefinitionCache(Span())); int mainLabel = labelOf(main); setScopes(main, scope); resolveIdentifiersAndTypes(main); diff --git a/codec/codec.cpp b/codec/codec.cpp index c4174821..cbb8d00a 100644 --- a/codec/codec.cpp +++ b/codec/codec.cpp @@ -77,9 +77,7 @@ class Chromosome } } if (total == 0) { - File file(String("hbfs.dat")); - FileHandle handle(file); - handle.openWrite(); + FileHandle handle = File("hbfs.dat").openWrite(); handle.write(_data, sizeof(_data)); printf("Lossless solution found!\n"); exit(0); @@ -162,16 +160,12 @@ class Program : public ProgramBase void run() { { - Array waves; - Array wave; - wave.allocate(samplesPerWaveform); - waves.allocate(samplesPerWaveform * totalWaveforms); + Array waves(samplesPerWaveform * totalWaveforms); + Array wave(samplesPerWaveform); for (int sample = 0; sample < samplesPerWaveform; ++sample) waves[sample] = clamp(-32768.0, 0x8000*sin(sample*2*M_PI/samplesPerWaveform), 32767.0); - File file(String("waves.raw")); - FileHandle handle(file); - handle.openWrite(); + FileHandle handle = File("waves.raw").openWrite(); for (int i = 0; i < 50; ++i) handle.write(&waves[0], samplesPerWaveform * sizeof(Sample)); for (int waveform = 1; waveform < totalWaveforms; ++waveform) { @@ -201,9 +195,7 @@ class Program : public ProgramBase Array hbfs; { - File file(String("hbfs.wav")); - FileHandle handle(file); - handle.openRead(); + FileHandle handle = File("hbfs.wav").openRead(); handle.seek(44); hbfs.allocate(totalSamples); original = &hbfs[0]; diff --git a/crc32/crc32.cpp b/crc32/crc32.cpp index b4e21292..21287462 100644 --- a/crc32/crc32.cpp +++ b/crc32/crc32.cpp @@ -1,8 +1,6 @@ #include #include #include "alfe/main.h" -#include "alfe/file.h" -#include "alfe/minimum_maximum.h" static UInt32 crc_32_tab[]={ /* CRC polynomial 0xedb88320 */ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, @@ -55,19 +53,18 @@ class Crc32 public: void operator()(const File& file) { - NullTerminatedString path(file.messagePath()); + NullTerminatedString path(file.path()); - FileHandle handle(file); - if (!handle.tryOpenRead()) { - printf(" %s\n", path); + FileHandle handle = file.tryOpenRead(); + if (!handle.valid()) { + printf(" %s\n", (const char*)path); return; } UInt64 size = handle.size(); DWORD crc = 0xffffffff; - Array buffer; static const int bufferSize = 0x10000; - buffer.allocate(bufferSize); + Array buffer(bufferSize); while (size > 0) { int s = static_cast(min(static_cast(bufferSize), size)); @@ -90,7 +87,7 @@ class Program : public ProgramBase { Crc32 crc32; if (_arguments.count() == 1) { - printf("Usage: crc32 \n"); + console.write("Usage: crc32 \n"); return; } for (int i = 1; i < _arguments.count(); ++i) diff --git a/crc32/crc32.vcxproj b/crc32/crc32.vcxproj index e6e44706..f6e470b5 100644 --- a/crc32/crc32.vcxproj +++ b/crc32/crc32.vcxproj @@ -50,7 +50,6 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - ../include Console @@ -66,8 +65,6 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - ../include - MultiThreaded Console @@ -80,10 +77,20 @@ + + + + + + + + + + diff --git a/crc32/crc32.vcxproj.filters b/crc32/crc32.vcxproj.filters new file mode 100644 index 00000000..3071a3f3 --- /dev/null +++ b/crc32/crc32.vcxproj.filters @@ -0,0 +1,66 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/fractals/bif/bif.cpp b/fractals/bif/bif.cpp index b63f6910..6d45ba51 100644 --- a/fractals/bif/bif.cpp +++ b/fractals/bif/bif.cpp @@ -95,7 +95,7 @@ class BifCalcThread : public CalcThread class Program : public ProgramBase { protected: - int run() + void run() { Region region(Vector2(3.5f, 0.0f), Vector2(4.0f, 1.0f), Vector2(2, 2)); @@ -114,7 +114,7 @@ class Program : public ProgramBase ZoomableWindow window(zwp); window.show(_nCmdShow); - return pumpMessages(); + pumpMessages(); } }; diff --git a/include/alfe/any.h b/include/alfe/any.h index b1f29308..88b53677 100644 --- a/include/alfe/any.h +++ b/include/alfe/any.h @@ -1,8 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_ANY_H #define INCLUDED_ANY_H -#include "alfe/reference_counted.h" - class Any { public: diff --git a/include/alfe/array.h b/include/alfe/array.h index 83ee4c50..f22863c9 100644 --- a/include/alfe/array.h +++ b/include/alfe/array.h @@ -1,9 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_ARRAY_H #define INCLUDED_ARRAY_H -#include -#include "alfe/swap.h" - template class List { public: diff --git a/include/alfe/assert.h b/include/alfe/assert.h index 878d11e2..52827c51 100644 --- a/include/alfe/assert.h +++ b/include/alfe/assert.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_ASSERT_H #define INCLUDED_ASSERT_H @@ -5,7 +7,6 @@ // TODO: _CrtDbgBreak() is a VC-ism: port to other Windows compilers // TODO: Use console instead of MessageBox() for console applications? -#include "alfe/string.h" #include void alert(String message, HWND hWnd = NULL) diff --git a/include/alfe/audio.h b/include/alfe/audio.h index 6023ecb8..55277474 100644 --- a/include/alfe/audio.h +++ b/include/alfe/audio.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_AUDIO_H #define INCLUDED_AUDIO_H @@ -424,11 +426,10 @@ template class WaveFileSink : public AudioSink int samplesPerBufferChannel = 1024) : AudioSink(samplesPerSecond, channels), _samplesPerBuffer(samplesPerBufferChannel * channels), - _handle(file), _bytes(0) { // TODO: make endian-neutral. Posix port. - _handle.openWrite(); + _handle = file.openWrite(); _handle.write("RIFF", 4); DWORD t = 36; _handle.write(&t, 4); diff --git a/include/alfe/bitmap.h b/include/alfe/bitmap.h index 544b7948..1708357b 100644 --- a/include/alfe/bitmap.h +++ b/include/alfe/bitmap.h @@ -1,10 +1,34 @@ +#include "alfe/main.h" + #ifndef INCLUDED_BITMAP_H #define INCLUDED_BITMAP_H #include "alfe/vectors.h" #include "alfe/reference_counted_array.h" -#include "alfe/file.h" -#include + +template class Bitmap; + +template class BitmapFileFormat +{ +public: + Bitmap load(const File& file) + { + return _implementation->load(file); + } +protected: + class Implementation : public ReferenceCounted + { + public: + virtual void save(Bitmap& bitmap, const File& file) = 0; + virtual Bitmap load(const File& file) = 0; + }; + BitmapFileFormat(Implementation* implementation) + : _implementation(implementation) { } +private: + Reference _implementation; + + friend class Bitmap; +}; // A Bitmap is a value class encapsulating a 2D image. Its width, height, // stride and pixel format are immutable but the pixels themselves are not. @@ -26,7 +50,14 @@ template class Bitmap }; public: Bitmap() : _size(0, 0) { } - Bitmap(Vector size) { create(size, size.x*sizeof(Pixel)); } + Bitmap(Vector size) + { + int stride = size.x*sizeof(Pixel); + _size = size; + _data = ReferenceCountedArray::create(stride * size.y); + _data->_stride = stride; + _topLeft = &(*_data)[0]; + } bool valid() const { return _data.valid(); } @@ -171,26 +202,14 @@ template class Bitmap } } - // This will put 8-bit sRGB data in the bitmap. - void load(const File& file) + void load(const BitmapFileFormat& format, const File& file) { - FileHandle handle(file); - handle.openRead(); - Array header(8); - handle.read(&header[0], 8); - if (png_sig_cmp(&header[0], 0, 8)) - throw Exception(file.messagePath() + " is not a .png file"); - PNGRead read(&handle); - read.read(this); + *this = format._implementation->load(file); } - // The bitmap needs to be 8-bit sRGB data for this to work. - void save(const File& file) + void save(const BitmapFileFormat& format, const File& file) { - FileHandle handle(file); - handle.openWrite(); - PNGWrite write(&handle); - write.write(this); + format._implementation->save(*this, file); } Byte* data() { return _topLeft; } const Byte* data() const { return _topLeft; } @@ -263,132 +282,6 @@ template class Bitmap Bitmap(const Reference& data, Byte* topLeft, Vector size) : _data(data), _topLeft(topLeft), _size(size) { } - void create(Vector size, int stride) - { - _data = ReferenceCountedArray::create(stride * size.y); - _data->_stride = stride; - _topLeft = &(*_data)[0]; - } - - static void userReadData(png_structp png_ptr, png_bytep data, - png_size_t length) - { - FileHandle* handle = static_cast(png_get_io_ptr(png_ptr)); - handle->read(static_cast(data), length); - } - static void userWriteData(png_structp png_ptr, png_bytep data, - png_size_t length) - { - FileHandle* handle = static_cast(png_get_io_ptr(png_ptr)); - handle->write(static_cast(data), length); - } - static void userFlushData(png_structp png_ptr) { } - static void userErrorFunction(png_structp png_ptr, - png_const_charp error_msg) - { - FileHandle* handle = - static_cast(png_get_error_ptr(png_ptr)); - throw Exception("Error reading: " + handle->name() + ": " + error_msg); - } - static void userWarningFunction(png_structp png_ptr, - png_const_charp error_msg) - { - FileHandle* handle = - static_cast(png_get_error_ptr(png_ptr)); - throw Exception("Error reading: " + handle->name() + ": " + error_msg); - } - - class PNGRead - { - public: - PNGRead(FileHandle* handle) : _handle(handle) - { - _png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, - static_cast(handle), userErrorFunction, - userWarningFunction); - if (_png_ptr == 0) - throw Exception("Error creating PNG read structure"); - } - void read(Bitmap* bitmap) - { - _info_ptr = png_create_info_struct(_png_ptr); - if (_info_ptr == 0) - throw Exception("Error creating PNG info structure"); - png_set_read_fn(_png_ptr, static_cast(_handle), - userReadData); - png_set_sig_bytes(_png_ptr, 8); - png_read_png(_png_ptr, _info_ptr, PNG_TRANSFORM_IDENTITY, 0); - _row_pointers = png_get_rows(_png_ptr, _info_ptr); - Vector size(png_get_image_width(_png_ptr, _info_ptr), - png_get_image_height(_png_ptr, _info_ptr)); - *bitmap = Bitmap(size); - Byte* data = bitmap->data(); - int stride = bitmap->stride(); - for (int y = 0; y < size.y; ++y) { - Pixel* line = reinterpret_cast(data); - png_bytep row = _row_pointers[y]; - for (int x = 0; x < size.x; ++x) { - png_bytep p = &row[x*3]; - *line = Pixel(p[0], p[1], p[2]); - ++line; - } - data += stride; - } - } - ~PNGRead() - { - png_destroy_read_struct(&_png_ptr, &_info_ptr, 0); - } - private: - png_structp _png_ptr; - png_infop _info_ptr; - png_bytep* _row_pointers; - FileHandle* _handle; - }; - - class PNGWrite - { - public: - PNGWrite(FileHandle* handle) : _handle(handle) - { - _png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, - static_cast(handle), userErrorFunction, - userWarningFunction); - if (_png_ptr == 0) - throw Exception(String("Error creating PNG write structure")); - } - void write(Bitmap* bitmap) - { - _info_ptr = png_create_info_struct(_png_ptr); - if (_info_ptr == 0) - throw Exception(String("Error creating PNG info structure")); - png_set_write_fn(_png_ptr, static_cast(_handle), - userWriteData, userFlushData); - Vector size = bitmap->size(); - png_set_IHDR(_png_ptr, _info_ptr, size.x, size.y, 8, - PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - Array rows(size.y); - Byte* data = bitmap->data(); - for (int y = 0; y < size.y; ++y) { - rows[y] = data; - data += bitmap->stride(); - } - png_set_rows(_png_ptr, _info_ptr, - static_cast(&rows[0])); - png_write_png(_png_ptr, _info_ptr, PNG_TRANSFORM_IDENTITY, NULL); - } - ~PNGWrite() - { - png_destroy_write_struct(&_png_ptr, &_info_ptr); - } - private: - png_structp _png_ptr; - png_infop _info_ptr; - png_bytep* _row_pointers; - FileHandle* _handle; - }; - template void resampleVertically(Byte* intermediate, Bitmap& target) const { diff --git a/include/alfe/bitmap_png.h b/include/alfe/bitmap_png.h new file mode 100644 index 00000000..dc8c8b18 --- /dev/null +++ b/include/alfe/bitmap_png.h @@ -0,0 +1,162 @@ +#include "alfe/main.h" + +#ifndef INCLUDED_BITMAP_PNG_H +#define INCLUDED_BITMAP_PNG_H + +#include + +class PNGFileFormat : public BitmapFileFormat +{ +public: + PNGFileFormat() : BitmapFileFormat(new Implementation) { } +private: + class Implementation : public BitmapFileFormat::Implementation + { + public: + // The bitmap needs to be 8-bit sRGB data for this to work. + virtual void save(Bitmap& bitmap, const File& file) + { + FileHandle handle = file.openWrite(); + PNGWrite write(&handle); + write.write(bitmap); + } + // This will put 8-bit sRGB data in the bitmap. + virtual Bitmap load(const File& file) + { + FileHandle handle = file.openRead(); + Array header(8); + handle.read(&header[0], 8); + if (png_sig_cmp(&header[0], 0, 8)) + throw Exception(file.path() + " is not a .png file"); + return PNGRead(&handle).read(); + } + private: + static void userReadData(png_structp png_ptr, png_bytep data, + png_size_t length) + { + FileHandle* handle = + static_cast(png_get_io_ptr(png_ptr)); + handle->read(static_cast(data), length); + } + static void userWriteData(png_structp png_ptr, png_bytep data, + png_size_t length) + { + FileHandle* handle = + static_cast(png_get_io_ptr(png_ptr)); + handle->write(static_cast(data), length); + } + static void userFlushData(png_structp png_ptr) { } + static void userErrorFunction(png_structp png_ptr, + png_const_charp error_msg) + { + FileHandle* handle = + static_cast(png_get_error_ptr(png_ptr)); + throw Exception("Error reading: " + handle->file().path() + ": " + + error_msg); + } + static void userWarningFunction(png_structp png_ptr, + png_const_charp error_msg) + { + FileHandle* handle = + static_cast(png_get_error_ptr(png_ptr)); + throw Exception("Error reading: " + handle->file().path() + ": " + + error_msg); + } + + class PNGRead + { + public: + PNGRead(FileHandle* handle) : _handle(handle) + { + _png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, + static_cast(handle), userErrorFunction, + userWarningFunction); + if (_png_ptr == 0) + throw Exception("Error creating PNG read structure"); + } + Bitmap read() + { + _info_ptr = png_create_info_struct(_png_ptr); + if (_info_ptr == 0) + throw Exception("Error creating PNG info structure"); + png_set_read_fn(_png_ptr, static_cast(_handle), + userReadData); + png_set_sig_bytes(_png_ptr, 8); + png_read_png(_png_ptr, _info_ptr, PNG_TRANSFORM_IDENTITY, 0); + _row_pointers = png_get_rows(_png_ptr, _info_ptr); + Vector size(png_get_image_width(_png_ptr, _info_ptr), + png_get_image_height(_png_ptr, _info_ptr)); + Bitmap bitmap(size); + Byte* data = bitmap.data(); + int stride = bitmap.stride(); + for (int y = 0; y < size.y; ++y) { + SRGB* line = reinterpret_cast(data); + png_bytep row = _row_pointers[y]; + for (int x = 0; x < size.x; ++x) { + png_bytep p = &row[x*3]; + *line = SRGB(p[0], p[1], p[2]); + ++line; + } + data += stride; + } + return bitmap; + } + ~PNGRead() + { + png_destroy_read_struct(&_png_ptr, &_info_ptr, 0); + } + private: + png_structp _png_ptr; + png_infop _info_ptr; + png_bytep* _row_pointers; + FileHandle* _handle; + }; + + class PNGWrite + { + public: + PNGWrite(FileHandle* handle) : _handle(handle) + { + _png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + static_cast(handle), userErrorFunction, + userWarningFunction); + if (_png_ptr == 0) + throw Exception("Error creating PNG write structure"); + } + void write(Bitmap& bitmap) + { + _info_ptr = png_create_info_struct(_png_ptr); + if (_info_ptr == 0) + throw Exception("Error creating PNG info structure"); + png_set_write_fn(_png_ptr, static_cast(_handle), + userWriteData, userFlushData); + Vector size = bitmap.size(); + png_set_IHDR(_png_ptr, _info_ptr, size.x, size.y, 8, + PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + Array rows(size.y); + Byte* data = bitmap.data(); + int stride = bitmap.stride(); + for (int y = 0; y < size.y; ++y) { + rows[y] = data; + data += stride; + } + png_set_rows(_png_ptr, _info_ptr, + static_cast(&rows[0])); + png_write_png(_png_ptr, _info_ptr, PNG_TRANSFORM_IDENTITY, + NULL); + } + ~PNGWrite() + { + png_destroy_write_struct(&_png_ptr, &_info_ptr); + } + private: + png_structp _png_ptr; + png_infop _info_ptr; + png_bytep* _row_pointers; + FileHandle* _handle; + }; + }; +}; + +#endif // INCLUDED_BITMAP_PNG_H diff --git a/include/alfe/character_source.h b/include/alfe/character_source.h index 65c3daba..73e91807 100644 --- a/include/alfe/character_source.h +++ b/include/alfe/character_source.h @@ -1,4 +1,4 @@ -#include "alfe/string.h" +#include "alfe/main.h" #ifndef INCLUDED_CHARACTER_SOURCE_H #define INCLUDED_CHARACTER_SOURCE_H @@ -7,17 +7,16 @@ class Location { public: Location() : _line(0), _column(0), _offset(0) { } - Location(String fileName) - : _fileName(fileName), _line(1), _column(1), _offset(0) + Location(const File& file) : _file(file), _line(1), _column(1), _offset(0) { } - Location(String fileName, int line, int column) - : _fileName(fileName), _line(line), _column(column), _offset(0) + Location(const File& file, int line, int column) + : _file(file), _line(line), _column(column), _offset(0) { } String toString() const { - return _fileName + "(" + _line + "," + _column + ")"; + return _file.path() + "(" + _line + "," + _column + ")"; } - String fileName() const { return _fileName; } + File file() const { return _file; } void operator++() { ++_offset; } void advanceColumn() { ++_column; } void advanceLine() { _column = 1; ++_line; } @@ -34,7 +33,7 @@ class Location int line() const { return _line; } int column() const { return _column; } private: - String _fileName; + File _file; int _line; int _column; int _offset; @@ -45,28 +44,28 @@ class Span public: Span() : _startLine(-1) { } Span(Location start, Location end) - : _fileName(start.fileName()), + : _file(start.file()), _startLine(start.line()), _startColumn(start.column()), _endLine(end.line()), _endColumn(end.column()) { } - Span(String fileName, int startLine, int startColumn, int endLine, + Span(const File& file, int startLine, int startColumn, int endLine, int endColumn) - : _fileName(fileName), + : _file(file), _startLine(startLine), _startColumn(startColumn), _endLine(endLine), _endColumn(endColumn) { } - String fileName() const { return _fileName; } + File file() const { return _file; } int startLine() const { return _startLine; } int startColumn() const { return _startColumn; } int endLine() const { return _endLine; } int endColumn() const { return _endColumn; } String toString() const { - return _fileName + "(" + _startLine + "," + _startColumn + ")-(" + + return _file.path() + "(" + _startLine + "," + _startColumn + ")-(" + _endLine + "," + _endColumn + ")"; } void throwError(const String& message) const @@ -75,12 +74,9 @@ class Span } Location start() const { - return Location(_fileName, _startLine, _startColumn); - } - Location end() const - { - return Location(_fileName, _endLine, _endColumn); + return Location(_file, _startLine, _startColumn); } + Location end() const { return Location(_file, _endLine, _endColumn); } Span operator+(const Span& other) const { if (_startLine == -1) @@ -93,7 +89,7 @@ class Span return *this; } private: - String _fileName; + File _file; int _startLine; int _startColumn; int _endLine; @@ -105,8 +101,8 @@ class CharacterSource public: CharacterSource() { } CharacterSource(const String& string) : _string(string) { } - CharacterSource(const String& string, const String& fileName) - : _string(string), _location(fileName) { } + CharacterSource(const String& string, const File& file) + : _string(string), _location(file) { } int get(Span* span = 0) { Location start = _location; diff --git a/include/alfe/colour_space.h b/include/alfe/colour_space.h index f1094eb4..092d121c 100644 --- a/include/alfe/colour_space.h +++ b/include/alfe/colour_space.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_COLOUR_SPACE_H #define INCLUDED_COLOUR_SPACE_H diff --git a/include/alfe/com.h b/include/alfe/com.h index fe323d14..41a288fa 100644 --- a/include/alfe/com.h +++ b/include/alfe/com.h @@ -1,7 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_COM_H #define INCLUDED_COM_H -#include "alfe/string.h" #include #include #include "alfe/assert.h" diff --git a/include/alfe/complex.h b/include/alfe/complex.h index 4d4ac76d..6c44cd56 100644 --- a/include/alfe/complex.h +++ b/include/alfe/complex.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_COMPLEX_H #define INCLUDED_COMPLEX_H diff --git a/include/alfe/config_file.h b/include/alfe/config_file.h index 0660d4c5..95d5bef7 100644 --- a/include/alfe/config_file.h +++ b/include/alfe/config_file.h @@ -1,7 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_CONFIG_FILE_H #define INCLUDED_CONFIG_FILE_H -#include "alfe/string.h" #include "alfe/hash_table.h" #include "alfe/space.h" #include "alfe/any.h" @@ -107,7 +108,7 @@ class ConfigFile for (HashTable::Iterator i = _options.begin(); i != _options.end(); ++i) { if (!i.value().valid()) - throw Exception(file.messagePath() + ": " + i.key() + + throw Exception(file.path() + ": " + i.key() + " not defined and no default is available."); } } @@ -285,8 +286,7 @@ class ConfigFile if (part.type() != Type::string) source->location().throwError( "Don't know how to convert type " + - part.type().toString() + - " to a string"); + part.type().toString() + " to a string"); string += s.subString(startOffset, endOffset); startOffset = source->offset(); expression = combine(expression, TypedValue(Type::string, @@ -324,7 +324,7 @@ class ConfigFile int endOffset = source->offset(); String terminator = source->subString(startOffset, endOffset); startOffset = s.offset(); - CharacterSource terminatorSource(terminator, ""); + CharacterSource terminatorSource(terminator); int cc = terminatorSource.get(); String string; do { @@ -442,7 +442,7 @@ class ConfigFile return TypedValue(value.type(), value.value(), i.span()); } if (!_options.hasKey(s)) - i.span().throwError(String("Unknown identifier ") + s); + i.span().throwError("Unknown identifier " + s); TypedValue option = _options[s]; return TypedValue(option.type(), option.value(), i.span()); } @@ -505,11 +505,10 @@ class ConfigFile } // i is a type identifier if (!_types.hasKey(name)) - i.span().throwError(String("Unknown type ") + name); + i.span().throwError("Unknown type " + name); StructuredType type = _types[name]; if (!type.valid()) - i.span().throwError( - String("Only structure types can be constructed")); + i.span().throwError("Only structure types can be constructed"); const Array* members = type.members(); List values; Span span; @@ -599,7 +598,7 @@ class ConfigFile if (!okay) span.throwError("Don't know how to multiply type " + e.type().toString() + " and type " + - e2.type().toString() + codePoint('.')); + e2.type().toString() + "."); continue; } if (Space::parseCharacter(source, '/', &span)) { @@ -613,7 +612,7 @@ class ConfigFile else span.throwError("Don't know how to divide type " + e.type().toString() + " by type " + - e2.type().toString() + codePoint('.')); + e2.type().toString() + "."); continue; } return e; @@ -643,7 +642,7 @@ class ConfigFile else span.throwError("Don't know how to add type " + e2.type().toString() + " to type " + - e.type().toString() + codePoint('.')); + e.type().toString() + "."); continue; } if (Space::parseCharacter(source, '-', &span)) { @@ -657,7 +656,7 @@ class ConfigFile else span.throwError("Don't know how to subtract type " + e2.type().toString() + " from type " + - e.type().toString() + codePoint('.')); + e.type().toString() + "."); continue; } return e; diff --git a/include/alfe/convolution_pipe.h b/include/alfe/convolution_pipe.h index d207507d..1b37ec17 100644 --- a/include/alfe/convolution_pipe.h +++ b/include/alfe/convolution_pipe.h @@ -1,12 +1,13 @@ // Pipes that convolve with a kernel function to act as a finite impulse // response filter, and classes to define such kernel functions. +#include "alfe/main.h" + #ifndef INCLUDED_CONVOLUTION_PIPE_H #define INCLUDED_CONVOLUTION_PIPE_H #include "alfe/pipes.h" #include "alfe/gcd.h" -#include "alfe/reference_counted.h" #include "float.h" class ProductKernel; diff --git a/include/alfe/exception.h b/include/alfe/exception.h index 7de986ae..0dcca564 100644 --- a/include/alfe/exception.h +++ b/include/alfe/exception.h @@ -1,4 +1,4 @@ -#include "alfe/string.h" +#include "alfe/main.h" #ifndef INCLUDED_EXCEPTION_H #define INCLUDED_EXCEPTION_H @@ -147,6 +147,9 @@ template class ExceptionTemplate error = E_FAIL; } LocalString strMessage; + // The reinterpret_cast<> here is necessary because of the + // FORMAT_MESSAGE_ALLOCATE_BUFFER flag, which causes Windows to put a + // LPWSTR value in a *LPWSTR variable. DWORD formatted = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, @@ -157,8 +160,7 @@ template class ExceptionTemplate 0, NULL); if (formatted == 0) - return String("FormatMessage failed: 0x") + - hex(GetLastError(), 8); + return String("FormatMessage failed: ") + hex(GetLastError(), 8); return strMessage.string(); } #endif @@ -166,4 +168,31 @@ template class ExceptionTemplate Reference _implementation; }; +class PreserveSystemError +{ +public: + PreserveSystemError() + { +#ifdef _WIN32 + _lastError = GetLastError(); +#else + _errno = errno; +#endif + } + ~PreserveSystemError() + { +#ifdef _WIN32 + SetLastError(_lastError); +#else + errno = _errno; +#endif + } +private: +#ifdef _WIN32 + DWORD _lastError; +#else + int _errno; +#endif +}; + #endif // INCLUDED_EXCEPTION_H diff --git a/include/alfe/file.h b/include/alfe/file.h index 4491b50e..b6df9586 100644 --- a/include/alfe/file.h +++ b/include/alfe/file.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_FILE_H #define INCLUDED_FILE_H @@ -37,16 +39,7 @@ template class DriveCurrentDirectoryTemplate; typedef DriveCurrentDirectoryTemplate DriveCurrentDirectory; #endif -#include "alfe/string.h" - -#ifdef _WIN32 -#define NOMINMAX -#define WIN32_LEAN_AND_MEAN -#include -#else -#include -#include -#endif +class CharacterSource; template class FileSystemObjectTemplate { @@ -72,33 +65,23 @@ template class FileSystemObjectTemplate { return !operator==(other); } - int hash() const { return _implementation->hash(0); } -#ifdef _WIN32 - String windowsPath() const { return _implementation->windowsPath(); } - String messagePath() const { return windowsPath(); } -#else - String messagePath() const { return path(); } -#endif + int hash() const { return _implementation->hash(); } class Implementation : public ReferenceCounted { public: virtual Directory parent() const = 0; virtual String name() const = 0; - #ifdef _WIN32 - virtual String windowsPath() const = 0; - #endif virtual String path() const = 0; virtual bool isRoot() const = 0; - virtual int hash(int h) const = 0; + virtual int hash() const = 0; virtual int compare(const Implementation* other) const = 0; }; protected: - FileSystemObjectTemplate(Reference implementation) - : _implementation(implementation) { } - Reference _implementation; private: + FileSystemObjectTemplate(Reference implementation) + : _implementation(implementation) { } static FileSystemObject parse(const String& path, const Directory& relativeTo, bool windowsParsing) @@ -310,187 +293,13 @@ template class FileSystemObjectTemplate template friend class NamedFileSystemObjectImplementationTemplate; template friend class CurrentDirectoryTemplate; template friend class DirectoryTemplate; + friend class Console; template friend void applyToWildcard(T functor, const String& wildcard, int recurseIntoDirectories, const Directory& relativeTo); }; -#ifdef _WIN32 -template class FindHandleTemplate -{ -public: - FindHandleTemplate(const Directory& directory, const String& wildcard) - : _directory(directory), _wildcard(wildcard), _complete(false), - _handle(INVALID_HANDLE_VALUE) - { - _path = directory.child(wildcard).windowsPath(); - NullTerminatedWideString data(_path); - _handle = FindFirstFile(data, &_data); - if (_handle == INVALID_HANDLE_VALUE) { - if (GetLastError() == ERROR_FILE_NOT_FOUND) - _complete = true; - else - throwError(); - } - String n = name(); - if (n == "." || n == "..") - next(); - } - void next() - { - do { - if (FindNextFile(_handle, &_data) == 0) - if (GetLastError() == ERROR_NO_MORE_FILES) { - _complete = true; - return; - } - else - throwError(); - String n = name(); - if (n == "." || n == "..") - continue; - break; - } while (true); - } - ~FindHandleTemplate() - { - if (_handle != INVALID_HANDLE_VALUE) - FindClose(_handle); - } - bool isDirectory() const - { - return (_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - } - String name() const - { - return _data.cFileName; - } - FileSystemObject object() const - { - return _directory.child(name()); - } - DirectoryTemplate directory() const - { - return _directory.subDirectory(name()); - } - FileTemplate file() const - { - return _directory.file(name()); - } - bool complete() { return _complete; } -private: - void throwError() - { - throw Exception::systemError("Finding files " + _path); - } - - HANDLE _handle; - WIN32_FIND_DATA _data; - Directory _directory; - String _wildcard; - String _path; - bool _complete; -}; -#else -template class FindHandleTemplate -{ -public: - FindHandleTemplate(const Directory& directory, const String& wildcard) - : _directory(directory), _wildcard(wildcard), _complete(false), - _dir(NULL) - { - NullTerminatedString data(directory.path()); - _dir = opendir(data); - if (_dir == NULL) - throw Exception::systemError("Opening directory " + _path); - next(); - } - void next() - { - do { - errno = 0; - _data = readdir(_dir); - if (_data == NULL) - if (errno == 0) - _complete = true; - else - throw Exception::systemError("Reading directory " + _path); - String n = name(); - if (n == "." || n == "..") - continue; - if (!matches(n, wildcard)) - continue; - break; - } while (true); - } - ~FindHandle() - { - if (_handle != NULL) - closedir(_dir); - } - bool isDirectory() const - { - return _dirent->d_type == DT_DIR; - } - String name() const - { - return _data.d_name; - } - FileSystemObject object() const - { - return _directory.child(name()); - } - Directory directory() const - { - return _directory.subDirectory(name()); - } - File file() const - { - return _directory.file(name()); - } - bool complete() { return _complete; } -private: - static bool matches(String name, String wildcard) - { - CharacterSource sw(wildcard); - CharacterSource sn(name); - do { - int cs = sw.get(); - int cn = sn.get(); - switch (cs) { - case '?': - if (cn == -1) - return false; - continue; - case '*': - // TODO: this code is O(n^p) where p is number of stars, we - // can do better using dynamic programming. - if (cn == -1) - continue; - do { - if (matches(name.subString(sn.offset(), - name.length() - sn.offset()), sw.offset(), - wildcard.length() - sw.offset())) - return true; - cn = sn.get(); - } while (cn != -1); - return false; - case -1: - return (cn == -1); - default: - return (cn == cs); - } - } while (true); - } - - struct dirent* _data; - DIR* _dir; - String _path; - bool _complete; -}; -#endif - template class DirectoryTemplate : public FileSystemObject { public: @@ -554,8 +363,7 @@ template class CurrentDirectoryTemplate : public Directory int n = GetCurrentDirectory(0, NULL); if (n == 0) throw Exception::systemError("Obtaining current directory"); - Array buf; - buf.allocate(n); + Array buf(n); if (GetCurrentDirectory(n, &buf[0]) == 0) throw Exception::systemError("Obtaining current directory"); String path(&buf[0]); @@ -632,19 +440,18 @@ template class RootDirectoryTemplate : public Directory Directory parent() const { return RootDirectory(); } String name() const { return String(); } -#ifdef _WIN32 - String windowsPath() const + String path() const { +#ifdef _WIN32 // TODO: Use \\?\ to avoid MAX_PATH limit? - // If we do this we need to know the current drive - this is the - // first character of CurrentDirectory().windowsPath() . + // If we do this we need to know the current drive, which can be + // found from CurrentDirectory(). +#endif return String(); } -#endif - String path() const { return String(); } bool isRoot() const { return true; } - int hash(int h) const { return 0; } + int hash() const { return 0; } int compare(const FileSystemObject::Implementation* other) const { @@ -690,14 +497,13 @@ template class DriveRootDirectoryTemplate : public Directory Implementation(int drive) : _drive(drive) { } Directory parent() const { return DriveRootDirectory(_drive); } - String windowsPath() const + String path() const { // TODO: Use \\?\ to avoid MAX_PATH limit? - return path(); + return codePoint('A' + _drive) + ":"; } - String path() const { return codePoint('A' + _drive) + ":"; } - int hash(int h) const { return _drive; } + int hash() const { return _drive + 1; } int compare(const FileSystemObject::Implementation* other) const { @@ -730,15 +536,9 @@ template class UNCRootDirectoryTemplate : public Directory : _server(server), _share(share) { } Directory parent() const { return UNCRootDirectory(_server, _share); } - String windowsPath() const - { - return "\\\\" + _server + "\\" + _share; - } + String path() const { return "\\\\" + _server + "\\" + _share; } - int hash(int h) const - { - return (h*67 + _server.hash())*67 + _share.hash(); - } + int hash() const { return _server.hash()*67 + _share.hash(); } int compare(const FileSystemObject::Implementation* other) const { @@ -759,7 +559,8 @@ template class UNCRootDirectoryTemplate : public Directory }; #endif -class FileHandle; +template class FileHandleTemplate; +typedef FileHandleTemplate FileHandle; template class FileTemplate : public FileSystemObject { @@ -772,226 +573,164 @@ template class FileTemplate : public FileSystemObject String contents() const { - FileHandle handle(*this); - handle.openRead(); - UInt64 size = handle.size(); + FileHandle f = openRead(); + UInt64 size = f.size(); if (size >= 0x80000000) - throw Exception("2Gb or more in file " + messagePath()); + throw Exception("2Gb or more in file " + path()); int intSize = static_cast(size); String buffer(intSize); - handle.read(static_cast(buffer.data()), intSize); + f.read(static_cast(buffer.data()), intSize); + buffer._length = intSize; return buffer; } - void save(const Array& contents) + template void save(const U& contents) const { - FileHandle handle(*this); - handle.openWrite(); - handle.write(contents); + openWrite().write(contents); } - void save(const String& contents) - { - FileHandle handle(*this); - handle.openWrite(); - handle.write(contents); - } - void secureSave(const String& contents) + template void secureSave(const U& contents) const { // TODO: Backup file? - String tempPath; + File temp; { - FileHandle handle(*this); - tempPath = handle.openWriteTemporary(); - contents.write(handle); + f = openWriteTemporary(); + f.write(contents); #ifndef _WIN32 - handle.sync(); + f.sync(); #endif + temp = f.file(); } #ifdef _WIN32 - NullTerminatedWideString data(messagePath()); - NullTerminatedWideString tempData(tempPath); + NullTerminatedWideString data(path()); + NullTerminatedWideString tempData(temp.path()); if (ReplaceFile(data, tempData, NULL, REPLACEFILE_WRITE_THROUGH | REPLACEFILE_IGNORE_MERGE_ERRORS) == 0) { - // TODO: Delete temporary file? - throw Exception::systemError("Replacing file " + messagePath()); + { + PreserveSystemError p; + DeleteFile(tempData); // Ignore any errors + } + throw Exception::systemError("Replacing file " + path()); } #else - NullTerminatedString data(messagePath()); - NullTerminatedString tempData(tempPath); + NullTerminatedString data(path()); + NullTerminatedString tempData(temp.path()); if (rename(tempData, data) != 0) { - // TODO: Delete temporary file? - throw Exception::systemError("Replacing file " + messagePath()); + { + PreserveSystemError p; + unlink(tempData); // Ignore any errors + } + throw Exception::systemError("Replacing file " + path()); } #endif } - void append(const String& contents) + template void append(const U& contents) const { - FileHandle handle(*this); - handle.openAppend(); - contents.write(handle); + openAppend().write(contents); } -private: - FileTemplate(FileSystemObject object) : FileSystemObject(object) { } - - friend class DirectoryTemplate; -}; - -class FileHandle : public AutoHandle -{ -public: - FileHandle(const File& file) : _file(file) { } - void openRead() + FileHandleTemplate openRead() const { #ifdef _WIN32 - open(path(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, + return open(GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN); #else - open(path(), O_RDONLY); + return open(O_RDONLY); #endif } - void openWrite() + FileHandleTemplate openWrite() const { #ifdef _WIN32 - open(path(), GENERIC_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); + return open(GENERIC_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); #else - open(path(), O_WRONLY | O_CREAT | O_TRUNC); + return open(O_WRONLY | O_CREAT | O_TRUNC); #endif } - bool tryOpenRead() + FileHandleTemplate tryOpenRead() const { #ifdef _WIN32 - return tryOpen(path(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, + return tryOpen(GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN); #else - return tryOpen(path(), O_RDONLY); + return tryOpen(O_RDONLY); #endif } - bool tryOpenWrite() + FileHandleTemplate tryOpenWrite() const { #ifdef _WIN32 - return tryOpen(path(), GENERIC_WRITE, 0, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL); + return tryOpen(GENERIC_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL); #else - return tryOpen(path(), O_WRONLY | O_CREAT | O_TRUNC); + return tryOpen(O_WRONLY | O_CREAT | O_TRUNC); #endif } - String openWriteTemporary() + FileHandleTemplate openWriteTemporary() const { int i = 0; do { - String tempPath = path() + hex(i, 8, false); - bool success; + File temp = parent().file(name() + hex(i, 8, false)); #ifdef _WIN32 - success = open(tempPath, GENERIC_WRITE, 0, CREATE_NEW, + FileHandle f = open(tempPath, GENERIC_WRITE, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, false); #else - success = open(tempPath, O_WRONLY | O_CREAT | O_EXCL, false); + FileHandle f = open(tempPath, O_WRONLY | O_CREAT | O_EXCL, false); #endif - if (success) - return tempPath; + if (f.valid()) + return f; ++i; } while (true); } -#ifndef _WIN32 - void sync() - { - if (fsync(operator int()) != 0) - throw Exception::systemError("Synchronizing file " + path()); - } -#endif - UInt64 size() - { -#ifdef _WIN32 - LARGE_INTEGER size; - if (GetFileSizeEx(operator HANDLE(), &size) == 0) - throw Exception::systemError("Obtaining length of file " + - name()); - return size.QuadPart; -#else - off_t o = seek(0, SEEK_CUR); - off_t n = seek(0, SEEK_END); - seek(o, SEEK_SET); - return n; -#endif - } - void openAppend() + FileHandleTemplate openAppend() const { #ifdef _WIN32 - open(path(), GENERIC_WRITE, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL); -#else - open(path(), O_WRONLY | O_APPEND); -#endif - } - void seek(UInt64 position) - { -#ifdef _WIN32 - LARGE_INTEGER p; - p.QuadPart = position; - if (SetFilePointerEx(operator HANDLE(), p, NULL, FILE_BEGIN) == 0) - throw Exception::systemError("Seeking file " + name()); + return open(name(), GENERIC_WRITE, 0, OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL); #else - seek(position, SEEK_SET); + return open(name(), O_WRONLY | O_APPEND); #endif } private: #ifdef _WIN32 - bool open(String path, DWORD dwDesiredAccess, DWORD dwShareMode, + FileHandleTemplate open(DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, - bool throwIfExists = true) + bool throwIfExists = true) const { - if (!tryOpen(path, dwDesiredAccess, dwShareMode, dwCreationDisposition, - dwFlagsAndAttributes)) { - if (!throwIfExists && GetLastError() == ERROR_FILE_EXISTS) - return false; - throw Exception::systemError("Opening file " + path); - } - return true; + FileHandle f = tryOpen(dwDesiredAccess, dwShareMode, + dwCreationDisposition, dwFlagsAndAttributes); + if (!f.valid() && + (throwIfExists || GetLastError() == ERROR_FILE_EXISTS)) + throw Exception::systemError("Opening file " + path()); + return f; } - bool tryOpen(String path, DWORD dwDesiredAccess, DWORD dwShareMode, - DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes) + FileHandleTemplate tryOpen(DWORD dwDesiredAccess, DWORD dwShareMode, + DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes) const { - NullTerminatedWideString data(path); - HANDLE handle = CreateFile( + NullTerminatedWideString data(path()); + return FileHandle(CreateFile( data, // lpFileName dwDesiredAccess, dwShareMode, NULL, // lpSecurityAttributes dwCreationDisposition, dwFlagsAndAttributes, - NULL); // hTemplateFile - if (handle == INVALID_HANDLE_VALUE) - return false; - set(handle, path); - return true; + NULL), // hTemplateFile + *this); } #else - bool open(String path, int flags, bool throwIfExists = true) + FileHandle open(int flags, bool throwIfExists = true) const { - if (!tryOpen(path, flags)) { - if (!throwIfExists && errno == EEXIST) - return false; - throw Exception::systemError("Opening file " + path); - } - return true; + FileHandle f = tryOpen(flags); + if (!f.valid() && (throwIfExists || errno != EEXIST)) + throw Exception::systemError("Opening file " + path()); + return f; } - bool tryOpen(String path, int flags) + FileHandle tryOpen(int flags) const { - NullTerminatedString data(path); - int fileDescriptor = open(data, flags); - if (fileDescriptor == -1) - return false; - set(fileDescriptor, path); - return true; - } - off_t seek(off_t offset, int whence) - { - off_t n = lseek(operator int(), offset, whence); - if (n == (off_t)(-1)) - throw Exception::systemError("Seeking file " + name()); - return n; + NullTerminatedString data(path()); + return FileHandle(open(data, flags), *this); } #endif - String path() { return _file.messagePath(); } - File _file; + + FileTemplate(FileSystemObject object) : FileSystemObject(object) { } + + friend class DirectoryTemplate; + friend class Console; }; template class NamedFileSystemObjectImplementationTemplate @@ -1001,15 +740,16 @@ template class NamedFileSystemObjectImplementationTemplate NamedFileSystemObjectImplementationTemplate(const Directory& parent, const String& name) : _parent(parent), _name(name) { } #ifdef _WIN32 - String windowsPath() const + String path() const { - return _parent.windowsPath() + "\\" + _name; + return _parent.path() + "\\" + _name; } -#endif +#else String path() const { return _parent.path() + "/" + _name; } +#endif Directory parent() const { return _parent; } @@ -1017,7 +757,7 @@ template class NamedFileSystemObjectImplementationTemplate bool isRoot() const { return false; } - int hash(int h) const { return (h*67 + _parent.hash())*67 + _name.hash(); } + int hash() const { return _parent.hash()*67 + _name.hash(); } int compare(const FileSystemObject::Implementation* other) const { @@ -1146,4 +886,28 @@ template void applyToWildcard(T functor, const String& wildcard, applyToWildcard(functor, s, recurseIntoDirectories, dir); } +class Console : public File +{ +public: + Console() : File(FileSystemObject(new Implementation)) { } +private: + class Implementation : public FileSystemObject::Implementation + { + public: + String path() const { return "(console)"; } + Directory parent() const { return RootDirectory(); } + String name() const { return path(); } + bool isRoot() const { return false; } + int hash() const { return 27; } + int compare(const FileSystemObject::Implementation* other) const + { + const Implementation* c = + dynamic_cast(other); + if (c == 0) + return 1; + return 0; + } + }; +}; + #endif // INCLUDED_FILE_H diff --git a/include/alfe/file_handle.h b/include/alfe/file_handle.h new file mode 100644 index 00000000..fe3763d2 --- /dev/null +++ b/include/alfe/file_handle.h @@ -0,0 +1,63 @@ +#include "alfe/main.h" + +#ifndef INCLUDED_FILE_HANDLE_H +#define INCLUDED_FILE_HANDLE_H + +template class FileHandleTemplate : public AutoHandle +{ +public: +#ifdef _WIN32 + FileHandleTemplate(HANDLE handle, const File& file) + : AutoHandle(handle, file) + { } +#else + FileHandleTemplate(int fileDescriptor, const File& file) + : AutoHandle(fileDescriptor, file) { } +#endif +#ifndef _WIN32 + void sync() + { + if (fsync(operator int()) != 0) + throw Exception::systemError( + "Synchronizing file " + file().path()); + } +#endif + UInt64 size() + { +#ifdef _WIN32 + LARGE_INTEGER size; + if (GetFileSizeEx(operator HANDLE(), &size) == 0) + throw Exception::systemError( + "Obtaining length of file " + file().path()); + return size.QuadPart; +#else + off_t o = seek(0, SEEK_CUR); + off_t n = seek(0, SEEK_END); + seek(o, SEEK_SET); + return n; +#endif + } + void seek(UInt64 position) + { +#ifdef _WIN32 + LARGE_INTEGER p; + p.QuadPart = position; + if (SetFilePointerEx(operator HANDLE(), p, NULL, FILE_BEGIN) == 0) + throw Exception::systemError("Seeking file " + file().path()); +#else + seek(position, SEEK_SET); +#endif + } +private: +#ifndef _WIN32 + off_t seek(off_t offset, int whence) + { + off_t n = lseek(operator int(), offset, whence); + if (n == (off_t)(-1)) + throw Exception::systemError("Seeking file " + file().path()); + return n; + } +#endif +}; + +#endif // INCLUDED_FILE_HANDLE_H diff --git a/include/alfe/find_handle.h b/include/alfe/find_handle.h new file mode 100644 index 00000000..ca314e48 --- /dev/null +++ b/include/alfe/find_handle.h @@ -0,0 +1,182 @@ +#include "alfe/main.h" + +#ifndef INCLUDED_FIND_HANDLE_H +#define INCLUDED_FIND_HANDLE_H + +#ifdef _WIN32 +template class FindHandleTemplate +{ +public: + FindHandleTemplate(const Directory& directory, const String& wildcard) + : _directory(directory), _wildcard(wildcard), _complete(false), + _handle(INVALID_HANDLE_VALUE) + { + _path = directory.child(wildcard).path(); + NullTerminatedWideString data(_path); + _handle = FindFirstFile(data, &_data); + if (_handle == INVALID_HANDLE_VALUE) { + if (GetLastError() == ERROR_FILE_NOT_FOUND) + _complete = true; + else + throwError(); + } + String n = name(); + if (n == "." || n == "..") + next(); + } + void next() + { + do { + if (FindNextFile(_handle, &_data) == 0) + if (GetLastError() == ERROR_NO_MORE_FILES) { + _complete = true; + return; + } + else + throwError(); + String n = name(); + if (n == "." || n == "..") + continue; + break; + } while (true); + } + ~FindHandleTemplate() + { + if (_handle != INVALID_HANDLE_VALUE) + FindClose(_handle); + } + bool isDirectory() const + { + return (_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + } + String name() const + { + return _data.cFileName; + } + FileSystemObject object() const + { + return _directory.child(name()); + } + DirectoryTemplate directory() const + { + return _directory.subDirectory(name()); + } + FileTemplate file() const + { + return _directory.file(name()); + } + bool complete() { return _complete; } +private: + void throwError() + { + throw Exception::systemError("Finding files " + _path); + } + + HANDLE _handle; + WIN32_FIND_DATA _data; + Directory _directory; + String _wildcard; + String _path; + bool _complete; +}; +#else +template class FindHandleTemplate +{ +public: + FindHandleTemplate(const Directory& directory, const String& wildcard) + : _directory(directory), _wildcard(wildcard), _complete(false), + _dir(NULL) + { + _path = directory.child(wildcard).path(); + NullTerminatedString data(_path); + _dir = opendir(data); + if (_dir == NULL) + throw Exception::systemError("Opening directory " + _path); + next(); + } + void next() + { + do { + errno = 0; + _data = readdir(_dir); + if (_data == NULL) + if (errno == 0) + _complete = true; + else + throw Exception::systemError("Reading directory " + _path); + String n = name(); + if (n == "." || n == "..") + continue; + if (!matches(n, wildcard)) + continue; + break; + } while (true); + } + ~FindHandle() + { + if (_handle != NULL) + closedir(_dir); + } + bool isDirectory() const + { + return _dirent->d_type == DT_DIR; + } + String name() const + { + return _data.d_name; + } + FileSystemObject object() const + { + return _directory.child(name()); + } + Directory directory() const + { + return _directory.subDirectory(name()); + } + File file() const + { + return _directory.file(name()); + } + bool complete() { return _complete; } +private: + static bool matches(String name, String wildcard) + { + CharacterSource sw(wildcard); + CharacterSource sn(name); + do { + int cs = sw.get(); + int cn = sn.get(); + switch (cs) { + case '?': + if (cn == -1) + return false; + continue; + case '*': + // TODO: this code is O(n^p) where p is number of stars, we + // can do better using dynamic programming. + if (cn == -1) + continue; + do { + if (matches(name.subString(sn.offset(), + name.length() - sn.offset()), sw.offset(), + wildcard.length() - sw.offset())) + return true; + cn = sn.get(); + } while (cn != -1); + return false; + case -1: + return (cn == -1); + default: + return (cn == cs); + } + } while (true); + } + + struct dirent* _data; + DIR* _dir; + String _path; + bool _complete; +}; +#endif + +#endif // INCLUDED_FIND_HANDLE_H diff --git a/include/alfe/fix.h b/include/alfe/fix.h index 3a13d0c2..71c84a93 100644 --- a/include/alfe/fix.h +++ b/include/alfe/fix.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_FIX_H #define INCLUDED_FIX_H @@ -6,8 +8,6 @@ #pragma intrinsic(__emulu) #pragma intrinsic(__ll_lshift) -#include "alfe/integer_types.h" - template class Fixed; template class DoublePrecisionArithmeticHelper diff --git a/include/alfe/fractal.h b/include/alfe/fractal.h index b1f5c29c..410cead9 100644 --- a/include/alfe/fractal.h +++ b/include/alfe/fractal.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_FRACTAL_H #define INCLUDED_FRACTAL_H diff --git a/include/alfe/gcd.h b/include/alfe/gcd.h index 859c9a96..35072686 100644 --- a/include/alfe/gcd.h +++ b/include/alfe/gcd.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_GCD_H #define INCLUDED_GCD_H diff --git a/include/alfe/handle.h b/include/alfe/handle.h index 9b2c502c..842c9b8e 100644 --- a/include/alfe/handle.h +++ b/include/alfe/handle.h @@ -1,37 +1,30 @@ -#include "alfe/string.h" +#include "alfe/main.h" #ifndef INCLUDED_HANDLE_H #define INCLUDED_HANDLE_H -class Handle : Uncopyable +class Handle { public: #ifdef _WIN32 - Handle() : _handle(INVALID_HANDLE_VALUE), _name("") { } - Handle(HANDLE handle, const String& name = "") - : _handle(handle), _name(name) + Handle() : _handle(INVALID_HANDLE_VALUE) { } + Handle(HANDLE handle, const File& file = File()) + : _handle(handle), _file(file) { } operator HANDLE() const { return _handle; } - bool valid() const { return _handle != INVALID_HANDLE_VALUE; } - void set(HANDLE handle, const String& name = "") + bool valid() const { - _handle = handle; - _name = name; + return _handle != INVALID_HANDLE_VALUE && _handle != NULL; } #else Handle() : _fileDescriptor(-1) { } - Handle(int fileDescriptor, const String& name = "") - : _fileDescriptor(fileDescriptor), _name(name) + Handle(int fileDescriptor, const File& file = File()) + : _fileDescriptor(fileDescriptor), _file(file) { } operator int() const { return _fileDescriptor; } bool valid() const { return _fileDescriptor != -1; } - void set(int fileDescriptor, const String& name = "") - { - _fileDescriptor = fileDescriptor; - _name = name; - } #endif - String name() const { return _name; } + File file() const { return _file; } // Be careful using the template read() and write() functions with types // other than single bytes and arrays thereof - they are not endian-safe. void write(const char* string) const @@ -56,11 +49,11 @@ class Handle : Uncopyable DWORD bytesWritten; if (WriteFile(_handle, buffer, bytes, &bytesWritten, NULL) == 0 || bytesWritten != bytes) - throw Exception::systemError(String("Writing file ") + _name); + throw Exception::systemError("Writing file " + _file.path()); #else ssize_t writeResult = write(_fileDescriptor, buffer, bytes); if (writeResult < length()) - throw Exception::systemError(String("Writing file ") + _name); + throw Exception::systemError("Writing file " + _file.path()); #endif } template U read() @@ -78,7 +71,7 @@ class Handle : Uncopyable == 0) { if (GetLastError() == ERROR_HANDLE_EOF) return -1; - throw Exception::systemError(String("Reading file ") + _name); + throw Exception::systemError("Reading file " + _file.path()); } if (bytesRead != 1) return -1; @@ -87,7 +80,7 @@ class Handle : Uncopyable if (readResult < 1) { if (_eof(_fileDescriptor)) return -1; - throw Exception::systemError(String("Reading file ") + _name); + throw Exception::systemError("Reading file " + _file.path()); } #endif return b; @@ -99,39 +92,73 @@ class Handle : Uncopyable #ifdef _WIN32 DWORD bytesRead; if (ReadFile(_handle, buffer, bytes, &bytesRead, NULL) == 0) - throw Exception::systemError(String("Reading file ") + _name); + throw Exception::systemError("Reading file " + _file.path()); if (bytesRead != bytes) - throw Exception(String("End of file reading file ") + _name); + throw Exception("End of file reading file " + _file.path()); #else ssize_t readResult = read(_fileDescriptor, buffer, bytes); if (readResult < bytes) - throw Exception::systemError(String("Reading file ") + _name); + throw Exception::systemError("Reading file " + _file.path()); #endif } private: + class Implementation : public ReferenceCounted + { + public: +#ifdef _WIN32 + Implementation(HANDLE handle) : _handle(handle) { } + ~Implementation() + { + if (_handle != INVALID_HANDLE_VALUE) + CloseHandle(_handle); + } + HANDLE _handle; +#else + Implementation(int fileDescriptor) + : _fileDescriptor(fileDescriptor) { } + ~Implementation() + { + if (_fileDescriptor != -1) + close(_fileDescriptor); + } + int _fileDescriptor; +#endif + }; + +#ifdef _WIN32 + Handle(HANDLE handle, const File& file, Implementation* implementation) + : _handle(handle), _file(file), _implementation(implementation) { } +#else + Handle(int fileDescriptor, const File& file, + Implementation* implementation) + : _fileDescriptor(fileDescriptor), _file(file), + _implementation(implementation) + { } +#endif + #ifdef _WIN32 HANDLE _handle; #else int _fileDescriptor; #endif - String _name; + File _file; + Reference _implementation; + + friend class Implementation; + friend class AutoHandle; }; class AutoHandle : public Handle { public: - AutoHandle() { } #ifdef _WIN32 - AutoHandle(HANDLE handle, const String& name = "") - : Handle(handle, name) - { } - ~AutoHandle() { if (valid()) CloseHandle(operator HANDLE()); } + AutoHandle(HANDLE handle, const File& file = File()) + : Handle(handle, file, new Implementation(handle)) { } #else - AutoHandle(int fileDescriptor, const String& name = "") - : Handle(fileDescriptor, name) - { } - ~AutoHandle() { if (valid()) close(operator int()); } + AutoHandle(int fileDescriptor, const File& file = File()) + : Handle(handle, file, new Implementation(fileDescriptor)) { } #endif }; + #endif // INCLUDED_HANDLE_H diff --git a/include/alfe/hash_table.h b/include/alfe/hash_table.h index 1d873fa0..2eb5cbd2 100644 --- a/include/alfe/hash_table.h +++ b/include/alfe/hash_table.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_HASH_TABLE_H #define INCLUDED_HASH_TABLE_H @@ -132,8 +134,7 @@ template class HashTableBase : public Base void add(const Key& key, const Value& value) { if (_n == _table.count()) { - Array table; - table.allocate(_table.count() * 2); + Array table(_table.count() * 2); table.swap(_table); _n = 0; for (int i = 0; i < table.count(); ++i) diff --git a/include/alfe/integer_types.h b/include/alfe/integer_types.h index 119b24e3..e9f35893 100644 --- a/include/alfe/integer_types.h +++ b/include/alfe/integer_types.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_INTEGER_TYPES_H #define INCLUDED_INTEGER_TYPES_H diff --git a/include/alfe/linked_list.h b/include/alfe/linked_list.h index 2988afdd..4c155429 100644 --- a/include/alfe/linked_list.h +++ b/include/alfe/linked_list.h @@ -1,8 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_LINKED_LIST_H #define INCLUDED_LINKED_LIST_H -#include "alfe/uncopyable.h" - template class LinkedListMember; template class LinkedList : LinkedListMember diff --git a/include/alfe/main.h b/include/alfe/main.h index 6e624c22..36503500 100644 --- a/include/alfe/main.h +++ b/include/alfe/main.h @@ -1,20 +1,51 @@ #ifndef INCLUDED_MAIN_H #define INCLUDED_MAIN_H -#include "alfe/string.h" -#include "alfe/array.h" -#include "alfe/user.h" +#include +#include +#include +#include #ifdef _WIN32 +#define NOMINMAX +#define WIN32_LEAN_AND_MEAN #include +#ifdef _WINDOWS +#define UTF16_MESSAGES +#endif #include "shellapi.h" +#else +#include +#include +#include +#include #endif -Handle* debug; +#include "alfe/integer_types.h" +#include "alfe/uncopyable.h" +#include "alfe/reference_counted.h" +#include "alfe/swap.h" +#include "alfe/array.h" +#include "alfe/minimum_maximum.h" +#include "alfe/string.h" +#include "alfe/exception.h" +#include "alfe/file.h" +#include "alfe/find_handle.h" +#include "alfe/handle.h" +#include "alfe/file_handle.h" +#include "alfe/character_source.h" +#if defined(_WIN32) && defined(_WINDOWS) +#include "alfe/vectors.h" +#include "alfe/bitmap.h" +#include "alfe/user.h" +#endif + +Handle console; class ProgramBase : public Uncopyable { public: + ProgramBase() : _returnValue(0) { } #ifdef _WIN32 #ifdef _WINDOWS int initialize(HINSTANCE hInst, INT nCmdShow) @@ -23,7 +54,7 @@ class ProgramBase : public Uncopyable BEGIN_CHECKED { _windows.initialize(hInst); _nCmdShow = nCmdShow; - return initializeWindowsCommandLine(); + initializeWindowsCommandLine(); } END_CHECKED(Exception& e) { NullTerminatedWideString s(e.message()); @@ -33,35 +64,33 @@ class ProgramBase : public Uncopyable END_CHECKED(Exception&) { // Can't even display an error } - return 0; + return _returnValue; } #else - void initialize() + int initialize() { BEGIN_CHECKED { - HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); - if (h == INVALID_HANDLE_VALUE || h == NULL) + console = Handle(GetStdHandle(STD_OUTPUT_HANDLE), Console()); + if (!console.valid()) throw Exception::systemError("Getting console handle"); - _console.set(h, "console"); - debug = &_console; BEGIN_CHECKED { initializeWindowsCommandLine(); } END_CHECKED(Exception& e) { - _console.write(e); + console.write(e); } } END_CHECKED(Exception&) { // Can't even display an error } + return _returnValue; } #endif #else - void initialize(int argc, char* argv[]) + int initialize(int argc, char* argv[]) { BEGIN_CHECKED { - _console.set(STDOUT_FILENO, "console"); - debug = &_console; + console = Handle(STDOUT_FILENO, Console()); BEGIN_CHECKED { _arguments.allocate(argc); for (int i = 0; i < argc; ++i) { @@ -69,31 +98,42 @@ class ProgramBase : public Uncopyable run(); } END_CHECKED(Exception& e) { - _console.write(e); + console.write(e); } } END_CHECKED(Exception&) { // Can't even display an error } + return _returnValue; } #endif protected: #if defined(_WIN32) && defined(_WINDOWS) Windows _windows; INT _nCmdShow; - virtual int run() = 0; -#else - virtual void run() = 0; - Handle _console; + + void pumpMessages() + { + BOOL bRet; + do { + MSG msg; + bRet = GetMessage(&msg, NULL, 0, 0); + IF_MINUS_ONE_THROW(bRet); + if (bRet != 0) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + else + _returnValue = static_cast(msg.wParam); + } while (bRet != 0); + } #endif + virtual void run() = 0; Array _arguments; + int _returnValue; private: #ifdef _WIN32 -#ifdef _WINDOWS - int initializeWindowsCommandLine() -#else void initializeWindowsCommandLine() -#endif { class WindowsCommandLine { @@ -129,15 +169,12 @@ class ProgramBase : public Uncopyable _arguments[i] = buffer.subString(s, n); s += n; } -#ifdef _WINDOWS - return run(); -#else run(); -#endif } #endif }; +// Put Program in a template because it's not declared yet. #ifdef _WIN32 #ifdef _WINDOWS template INT APIENTRY WinMainTemplate(HINSTANCE hInst, INT nCmdShow) @@ -153,12 +190,10 @@ template int mainTemplate(int argc, char* argv[]) #ifdef _WINDOWS return program.initialize(hInst, nCmdShow); #else - program.initialize(); - return 0; + return program.initialize(); #endif #else - program.initialize(argc, argv); - return 0; + return program.initialize(argc, argv); #endif } diff --git a/include/alfe/minimum_maximum.h b/include/alfe/minimum_maximum.h index 3322fee3..9a9234ca 100644 --- a/include/alfe/minimum_maximum.h +++ b/include/alfe/minimum_maximum.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_MININUM_MAXIMUM_H #define INCLUDED_MININUM_MAXIMUM_H diff --git a/include/alfe/owning_array.h b/include/alfe/owning_array.h index 99661dc3..d83c9ab5 100644 --- a/include/alfe/owning_array.h +++ b/include/alfe/owning_array.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_OWNING_ARRAY_H #define INCLUDED_OWNING_ARRAY_H diff --git a/include/alfe/pipes.h b/include/alfe/pipes.h index 7fcb951a..7fc10a67 100644 --- a/include/alfe/pipes.h +++ b/include/alfe/pipes.h @@ -67,13 +67,12 @@ // // See also: http://dancinghacker.com/code/dataflow/ which is similar. +#include "alfe/main.h" + #ifndef INCLUDED_PIPES_H #define INCLUDED_PIPES_H -#include "alfe/minimum_maximum.h" -#include "alfe/uncopyable.h" #include "alfe/thread.h" -#include "alfe/file.h" #include #include @@ -198,28 +197,28 @@ template class Zero }; -// Functor to read samples from a FileHandle. +// Functor to read samples from a Handle. template class ReadFrom { public: - ReadFrom(FileHandle* handle) : _handle(handle) { } + ReadFrom(Handle handle) : _handle(handle) { } void operator()(T* destination, int n) { - _handle->read(destination, n*sizeof(T)); + _handle.read(destination, n*sizeof(T)); } private: - FileHandle* _handle; + Handle _handle; }; -// Functor to write samples to a FileHandle. +// Functor to write samples to a Handle. template class WriteTo { public: - WriteTo(FileHandle* handle) : _handle(handle) { } - void operator()(T* source, int n) { _handle->write(source, n*sizeof(T)); } + WriteTo(Handle handle) : _handle(handle) { } + void operator()(T* source, int n) { _handle.write(source, n*sizeof(T)); } private: - FileHandle* _handle; + Handle _handle; }; @@ -446,11 +445,10 @@ template class PeriodicSourceData PeriodicSourceData(int size) : _buffer(size) { } PeriodicSourceData(File file) { - FileHandle handle(file); - handle.openRead(); + FileHandle handle = file.openRead(); UInt64 size = handle.size(); if (size >= 0x80000000) - throw Exception("2Gb or more in file " + file.messagePath()); + throw Exception("2Gb or more in file " + file.path()); _buffer.resize(size / sizeof(T)); handle.read(&_buffer[0], size); } @@ -500,9 +498,9 @@ template class PeriodicSource : public Source template class FileSource : public Source { public: - FileSource(File file) : _handle(file) + FileSource(File file) { - _handle.openRead(); + _handle = file.openRead(); _size = _handle.size() / sizeof(T); } void produce(int n) @@ -513,7 +511,7 @@ template class FileSource : public Source nRead = static_cast(_size); Accessor w = writer(n); if (nRead > 0) { - w.items(ReadFrom(&_handle), nRead); + w.items(ReadFrom(_handle), nRead); nRemaining -= nRead; } if (nRemaining > 0) diff --git a/include/alfe/random.h b/include/alfe/random.h index bcf8edf1..2c856c49 100644 --- a/include/alfe/random.h +++ b/include/alfe/random.h @@ -1,8 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_RANDOM_H #define INCLUDED_RANDOM_H -#include "alfe/integer_types.h" - UInt32 random32() { static UInt32 r = 0; diff --git a/include/alfe/rational.h b/include/alfe/rational.h index 93d5317c..c1a99707 100644 --- a/include/alfe/rational.h +++ b/include/alfe/rational.h @@ -1,8 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_RATIONAL_H #define INCLUDED_RATIONAL_H -#include "alfe/string.h" - class ZeroDivideException : public Exception { ZeroDivideException : Exception(String("Division by zero")) { } diff --git a/include/alfe/reference_counted.h b/include/alfe/reference_counted.h index 9318e4b0..0672c3ef 100644 --- a/include/alfe/reference_counted.h +++ b/include/alfe/reference_counted.h @@ -1,8 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_REFERENCE_COUNTED_H #define INCLUDED_REFERENCE_COUNTED_H -#include "alfe/uncopyable.h" - class ReferenceCounted : Uncopyable { public: diff --git a/include/alfe/reference_counted_array.h b/include/alfe/reference_counted_array.h index 7a94d720..e7d7417c 100644 --- a/include/alfe/reference_counted_array.h +++ b/include/alfe/reference_counted_array.h @@ -1,9 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_REFERENCE_COUNTED_ARRAY_H #define INCLUDED_REFERENCE_COUNTED_ARRAY_H -#include "alfe/reference_counted.h" -#include "alfe/integer_types.h" - // This class combines an H and an array of Ts in a single memory block. H // must inherit from ReferenceCountedArray (curiously recurring template // pattern). H must have alignment equal to or greater than T. This can be @@ -12,12 +11,13 @@ template class ReferenceCountedArray { public: - static ReferenceCountedArray* create(int size) + static H* create(int size) { void* buffer = static_cast(operator new(sizeof(H) + size*sizeof(T))); + H* h; try { - H* h = new(buffer) H(); + h = new(buffer) H(); h->_size = size; int i = 0; try { @@ -37,6 +37,7 @@ template class ReferenceCountedArray operator delete(buffer); throw; } + return h; } void addReference() const { ++_count; } diff --git a/include/alfe/rotors.h b/include/alfe/rotors.h index b6dd088b..a9bd28c0 100644 --- a/include/alfe/rotors.h +++ b/include/alfe/rotors.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_ROTORS_H #define INCLUDED_ROTORS_H diff --git a/include/alfe/scratch.txt b/include/alfe/scratch.txt index d4e5fd0e..992a393d 100644 --- a/include/alfe/scratch.txt +++ b/include/alfe/scratch.txt @@ -4,13 +4,7 @@ See http://docs.racket-lang.org/reference/windowspaths.html for details on paths If use \\?\ to avoid MAX_PATH limit, we need to know the current drive - this is the first character of CurrentDirectory().windowsPath() . -When parsing paths, should we use: - getCodePoint() so that Unix paths can contain 0x0a and 0x0d bytes? or - get() so that error messages contain the correct line and column number? - Or make getCodePoint() increase _line/_column appropriately? - -CharacterSource currently only returns sensible _line/_column if it is started at the start of file contents - Really want to get good locations even for substrings - should SimpleString have a _line/_column? +When parsing paths, use getCodePoint() instead of get() so that Unix paths can contain 0x0a and 0x0d bytes. We should be using substitution into templates instead of concatenation for globalization purposes. diff --git a/include/alfe/set.h b/include/alfe/set.h index 584b43e4..1159f3fb 100644 --- a/include/alfe/set.h +++ b/include/alfe/set.h @@ -1,8 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_SET_H #define INCLUDED_SET_H -#include "alfe/array.h" - template class SetBase : public Base { public: @@ -17,8 +17,7 @@ template class SetBase : public Base void add(const Key& key) { if (_n == _table.count()) { - Array table; - table.allocate(_table.count() * 2); + Array table(_table.count() * 2); table.swap(_table); _n = 0; for (int i = 0; i < table.count(); ++i) diff --git a/include/alfe/space.h b/include/alfe/space.h index 1a0e411e..41e33075 100644 --- a/include/alfe/space.h +++ b/include/alfe/space.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_SPACE_H #define INCLUDED_SPACE_H @@ -35,7 +37,7 @@ class Space static bool parseOperator(CharacterSource* source, String op, Span* span) { CharacterSource s = *source; - CharacterSource o(op, ""); + CharacterSource o(op); Span sp; do { Span sp2; @@ -56,7 +58,7 @@ class Space Span* span) { CharacterSource s = *source; - CharacterSource o(keyword, ""); + CharacterSource o(keyword); Span sp; Span sp2; do { diff --git a/include/alfe/stack.h b/include/alfe/stack.h index 88048193..498efcd9 100644 --- a/include/alfe/stack.h +++ b/include/alfe/stack.h @@ -1,8 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_STACK_H #define INCLUDED_STACK_H -#include "alfe/array.h" - template class Stack { public: diff --git a/include/alfe/string.h b/include/alfe/string.h index bfcdb6fa..8fbb5d6e 100644 --- a/include/alfe/string.h +++ b/include/alfe/string.h @@ -1,26 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_STRING_H #define INCLUDED_STRING_H -#ifdef _WIN32 -#define NOMINMAX -#include -#ifdef _WINDOWS -#define UTF16_MESSAGES -#endif -#else -#include -#include -#include -#endif - -#include -#include -#include -#include "alfe/integer_types.h" -#include "alfe/reference_counted.h" -#include "alfe/array.h" -#include "alfe/minimum_maximum.h" - template class ExceptionTemplate; typedef ExceptionTemplate Exception; @@ -402,8 +384,18 @@ template class StringTemplate _implementation->expand(data, length); } void expand(int length) { _implementation->expand(length); } - const Byte* data() const { return _implementation->constData(); } - Byte* data() { return _implementation->data(); } + const Byte* data() const + { + if (!_implementation.valid()) + return 0; + return _implementation->constData(); + } + Byte* data() + { + if (!_implementation.valid()) + return 0; + return _implementation->data(); + } private: class Implementation : public ReferenceCounted { @@ -486,7 +478,7 @@ template class StringTemplate if (c == 0) break; if (c >= 0xdc00 && c < 0xe000) - throw Exception(String("String offset ") + hex(offset) + + throw Exception("String offset " + hex(offset) + ": expected 0x0000..0xD800 or 0xE000..0xFFFF, found " + hex(c, 4)); ++offset; @@ -494,7 +486,7 @@ template class StringTemplate int c2 = *utf16; ++utf16; if (c2 < 0xdc00 || c2 >= 0xe000) - throw Exception(String("String offset ") + hex(offset) + + throw Exception("String offset " + hex(offset) + ": expected 0xDC00..0xDFFF, found " + hex(c2, 4)); ++offset; c = (((c & 0x3ff) << 10) | (c2 & 0x3ff)) + 0x10000; @@ -561,7 +553,7 @@ template class NullTerminatedWideStringTemplate public: NullTerminatedWideStringTemplate(String s) { - CharacterSource start(s, ""); + CharacterSource start(s); CharacterSource cs = start; int l = 1; do { @@ -604,8 +596,6 @@ template class NullTerminatedWideStringTemplate typedef NullTerminatedWideStringTemplate NullTerminatedWideString; #endif -#include "alfe/exception.h" - class NullTerminatedString { public: @@ -632,7 +622,4 @@ class LocalString : Uncopyable }; #endif -#include "alfe/handle.h" -#include "alfe/character_source.h" - #endif // INCLUDED_STRING_H diff --git a/include/alfe/swap.h b/include/alfe/swap.h index 3c61cbc5..0013f2cf 100644 --- a/include/alfe/swap.h +++ b/include/alfe/swap.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_SWAP_H #define INCLUDED_SWAP_H diff --git a/include/alfe/symbol.h b/include/alfe/symbol.h index c3b9abb5..996a039a 100644 --- a/include/alfe/symbol.h +++ b/include/alfe/symbol.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_SYMBOL_H #define INCLUDED_SYMBOL_H diff --git a/include/alfe/terminal6.h b/include/alfe/terminal6.h index 57d44dfc..eaebe04e 100644 --- a/include/alfe/terminal6.h +++ b/include/alfe/terminal6.h @@ -1,262 +1,264 @@ +#include "alfe/main.h" + #ifndef INCLUDED_TERMINAL6_H #define INCLUDED_TERMINAL6_H int glyphs[0x100*8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x38, 0x44, 0x6C, 0x44, 0x54, 0x44, 0x38, 0x00, - 0x38, 0x7C, 0x54, 0x7C, 0x44, 0x7C, 0x38, 0x00, - 0x00, 0x28, 0x7C, 0x7C, 0x7C, 0x38, 0x10, 0x00, - 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x38, 0x10, 0x00, - 0x10, 0x38, 0x38, 0x10, 0x7C, 0x7C, 0x10, 0x00, - 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x10, 0x38, 0x00, - 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, - 0xFC, 0xFC, 0xFC, 0xCC, 0xCC, 0xFC, 0xFC, 0xFC, - 0x00, 0x00, 0x78, 0x48, 0x48, 0x78, 0x00, 0x00, - 0xFC, 0xFC, 0x84, 0xB4, 0xB4, 0x84, 0xFC, 0xFC, - 0x00, 0x1C, 0x0C, 0x34, 0x48, 0x48, 0x30, 0x00, - 0x38, 0x44, 0x44, 0x38, 0x10, 0x38, 0x10, 0x00, - 0x10, 0x18, 0x14, 0x10, 0x30, 0x70, 0x60, 0x00, - 0x0C, 0x34, 0x2C, 0x34, 0x2C, 0x6C, 0x60, 0x00, - 0x00, 0x54, 0x38, 0x6C, 0x38, 0x54, 0x00, 0x00, - 0x20, 0x30, 0x38, 0x3C, 0x38, 0x30, 0x20, 0x00, - 0x08, 0x18, 0x38, 0x78, 0x38, 0x18, 0x08, 0x00, - 0x10, 0x38, 0x7C, 0x10, 0x7C, 0x38, 0x10, 0x00, - 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x28, 0x00, - 0x3C, 0x54, 0x54, 0x34, 0x14, 0x14, 0x14, 0x00, - 0x38, 0x44, 0x30, 0x28, 0x18, 0x44, 0x38, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x78, 0x00, - 0x10, 0x38, 0x7C, 0x10, 0x7C, 0x38, 0x10, 0x38, - 0x10, 0x38, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x00, - 0x10, 0x10, 0x10, 0x10, 0x7C, 0x38, 0x10, 0x00, - 0x00, 0x10, 0x18, 0x7C, 0x18, 0x10, 0x00, 0x00, - 0x00, 0x10, 0x30, 0x7C, 0x30, 0x10, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7C, 0x00, - 0x00, 0x28, 0x28, 0x7C, 0x28, 0x28, 0x00, 0x00, - 0x10, 0x10, 0x38, 0x38, 0x7C, 0x7C, 0x00, 0x00, - 0x7C, 0x7C, 0x38, 0x38, 0x10, 0x10, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x38, 0x38, 0x10, 0x10, 0x00, 0x10, 0x00, - 0x6C, 0x6C, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x28, 0x7C, 0x28, 0x28, 0x7C, 0x28, 0x00, - 0x20, 0x38, 0x40, 0x30, 0x08, 0x70, 0x10, 0x00, - 0x64, 0x64, 0x08, 0x10, 0x20, 0x4C, 0x4C, 0x00, - 0x20, 0x50, 0x50, 0x20, 0x54, 0x48, 0x34, 0x00, - 0x30, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x00, - 0x20, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x00, - 0x00, 0x28, 0x38, 0x7C, 0x38, 0x28, 0x00, 0x00, - 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x20, - 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, - 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00, - 0x38, 0x44, 0x4C, 0x54, 0x64, 0x44, 0x38, 0x00, - 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, - 0x38, 0x44, 0x04, 0x18, 0x20, 0x40, 0x7C, 0x00, - 0x38, 0x44, 0x04, 0x38, 0x04, 0x44, 0x38, 0x00, - 0x08, 0x18, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00, - 0x7C, 0x40, 0x40, 0x78, 0x04, 0x44, 0x38, 0x00, - 0x18, 0x20, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00, - 0x7C, 0x04, 0x08, 0x10, 0x20, 0x20, 0x20, 0x00, - 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00, - 0x38, 0x44, 0x44, 0x3C, 0x04, 0x08, 0x30, 0x00, - 0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x00, - 0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x20, - 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00, - 0x00, 0x00, 0x7C, 0x00, 0x00, 0x7C, 0x00, 0x00, - 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00, - 0x38, 0x44, 0x04, 0x18, 0x10, 0x00, 0x10, 0x00, - 0x38, 0x44, 0x5C, 0x54, 0x5C, 0x40, 0x38, 0x00, - 0x38, 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x00, - 0x78, 0x44, 0x44, 0x78, 0x44, 0x44, 0x78, 0x00, - 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00, - 0x78, 0x44, 0x44, 0x44, 0x44, 0x44, 0x78, 0x00, - 0x7C, 0x40, 0x40, 0x78, 0x40, 0x40, 0x7C, 0x00, - 0x7C, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x00, - 0x38, 0x44, 0x40, 0x5C, 0x44, 0x44, 0x3C, 0x00, - 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x00, - 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, - 0x04, 0x04, 0x04, 0x04, 0x44, 0x44, 0x38, 0x00, - 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00, - 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7C, 0x00, - 0x44, 0x6C, 0x54, 0x44, 0x44, 0x44, 0x44, 0x00, - 0x44, 0x64, 0x54, 0x4C, 0x44, 0x44, 0x44, 0x00, - 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, - 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00, - 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00, - 0x78, 0x44, 0x44, 0x78, 0x48, 0x44, 0x44, 0x00, - 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00, - 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, - 0x44, 0x44, 0x54, 0x54, 0x54, 0x54, 0x28, 0x00, - 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00, - 0x44, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x00, - 0x78, 0x08, 0x10, 0x20, 0x40, 0x40, 0x78, 0x00, - 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, - 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00, - 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, - 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, + 0x38, 0x44, 0x6C, 0x44, 0x54, 0x44, 0x38, 0x00, + 0x38, 0x7C, 0x54, 0x7C, 0x44, 0x7C, 0x38, 0x00, + 0x00, 0x28, 0x7C, 0x7C, 0x7C, 0x38, 0x10, 0x00, + 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x38, 0x10, 0x00, + 0x10, 0x38, 0x38, 0x10, 0x7C, 0x7C, 0x10, 0x00, + 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x10, 0x38, 0x00, + 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, + 0xFC, 0xFC, 0xFC, 0xCC, 0xCC, 0xFC, 0xFC, 0xFC, + 0x00, 0x00, 0x78, 0x48, 0x48, 0x78, 0x00, 0x00, + 0xFC, 0xFC, 0x84, 0xB4, 0xB4, 0x84, 0xFC, 0xFC, + 0x00, 0x1C, 0x0C, 0x34, 0x48, 0x48, 0x30, 0x00, + 0x38, 0x44, 0x44, 0x38, 0x10, 0x38, 0x10, 0x00, + 0x10, 0x18, 0x14, 0x10, 0x30, 0x70, 0x60, 0x00, + 0x0C, 0x34, 0x2C, 0x34, 0x2C, 0x6C, 0x60, 0x00, + 0x00, 0x54, 0x38, 0x6C, 0x38, 0x54, 0x00, 0x00, + 0x20, 0x30, 0x38, 0x3C, 0x38, 0x30, 0x20, 0x00, + 0x08, 0x18, 0x38, 0x78, 0x38, 0x18, 0x08, 0x00, + 0x10, 0x38, 0x7C, 0x10, 0x7C, 0x38, 0x10, 0x00, + 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x28, 0x00, + 0x3C, 0x54, 0x54, 0x34, 0x14, 0x14, 0x14, 0x00, + 0x38, 0x44, 0x30, 0x28, 0x18, 0x44, 0x38, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x78, 0x00, + 0x10, 0x38, 0x7C, 0x10, 0x7C, 0x38, 0x10, 0x38, + 0x10, 0x38, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x00, + 0x10, 0x10, 0x10, 0x10, 0x7C, 0x38, 0x10, 0x00, + 0x00, 0x10, 0x18, 0x7C, 0x18, 0x10, 0x00, 0x00, + 0x00, 0x10, 0x30, 0x7C, 0x30, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7C, 0x00, + 0x00, 0x28, 0x28, 0x7C, 0x28, 0x28, 0x00, 0x00, + 0x10, 0x10, 0x38, 0x38, 0x7C, 0x7C, 0x00, 0x00, + 0x7C, 0x7C, 0x38, 0x38, 0x10, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x38, 0x38, 0x10, 0x10, 0x00, 0x10, 0x00, + 0x6C, 0x6C, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x28, 0x7C, 0x28, 0x28, 0x7C, 0x28, 0x00, + 0x20, 0x38, 0x40, 0x30, 0x08, 0x70, 0x10, 0x00, + 0x64, 0x64, 0x08, 0x10, 0x20, 0x4C, 0x4C, 0x00, + 0x20, 0x50, 0x50, 0x20, 0x54, 0x48, 0x34, 0x00, + 0x30, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x00, + 0x20, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x00, + 0x00, 0x28, 0x38, 0x7C, 0x38, 0x28, 0x00, 0x00, + 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x20, + 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, + 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00, + 0x38, 0x44, 0x4C, 0x54, 0x64, 0x44, 0x38, 0x00, + 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, + 0x38, 0x44, 0x04, 0x18, 0x20, 0x40, 0x7C, 0x00, + 0x38, 0x44, 0x04, 0x38, 0x04, 0x44, 0x38, 0x00, + 0x08, 0x18, 0x28, 0x48, 0x7C, 0x08, 0x08, 0x00, + 0x7C, 0x40, 0x40, 0x78, 0x04, 0x44, 0x38, 0x00, + 0x18, 0x20, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00, + 0x7C, 0x04, 0x08, 0x10, 0x20, 0x20, 0x20, 0x00, + 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00, + 0x38, 0x44, 0x44, 0x3C, 0x04, 0x08, 0x30, 0x00, + 0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x00, + 0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x20, + 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00, + 0x00, 0x00, 0x7C, 0x00, 0x00, 0x7C, 0x00, 0x00, + 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00, + 0x38, 0x44, 0x04, 0x18, 0x10, 0x00, 0x10, 0x00, + 0x38, 0x44, 0x5C, 0x54, 0x5C, 0x40, 0x38, 0x00, + 0x38, 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x00, + 0x78, 0x44, 0x44, 0x78, 0x44, 0x44, 0x78, 0x00, + 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00, + 0x78, 0x44, 0x44, 0x44, 0x44, 0x44, 0x78, 0x00, + 0x7C, 0x40, 0x40, 0x78, 0x40, 0x40, 0x7C, 0x00, + 0x7C, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x00, + 0x38, 0x44, 0x40, 0x5C, 0x44, 0x44, 0x3C, 0x00, + 0x44, 0x44, 0x44, 0x7C, 0x44, 0x44, 0x44, 0x00, + 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, + 0x04, 0x04, 0x04, 0x04, 0x44, 0x44, 0x38, 0x00, + 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7C, 0x00, + 0x44, 0x6C, 0x54, 0x44, 0x44, 0x44, 0x44, 0x00, + 0x44, 0x64, 0x54, 0x4C, 0x44, 0x44, 0x44, 0x00, + 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, + 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00, + 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00, + 0x78, 0x44, 0x44, 0x78, 0x48, 0x44, 0x44, 0x00, + 0x38, 0x44, 0x40, 0x38, 0x04, 0x44, 0x38, 0x00, + 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, + 0x44, 0x44, 0x54, 0x54, 0x54, 0x54, 0x28, 0x00, + 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00, + 0x44, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x00, + 0x78, 0x08, 0x10, 0x20, 0x40, 0x40, 0x78, 0x00, + 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x00, + 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00, + 0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, + 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x30, 0x30, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, - 0x40, 0x40, 0x78, 0x44, 0x44, 0x44, 0x78, 0x00, - 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x00, - 0x04, 0x04, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x00, - 0x00, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, - 0x18, 0x20, 0x20, 0x78, 0x20, 0x20, 0x20, 0x00, - 0x00, 0x00, 0x3C, 0x44, 0x44, 0x3C, 0x04, 0x38, - 0x40, 0x40, 0x70, 0x48, 0x48, 0x48, 0x48, 0x00, - 0x10, 0x00, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, - 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x48, 0x30, - 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, - 0x00, 0x00, 0x68, 0x54, 0x54, 0x44, 0x44, 0x00, - 0x00, 0x00, 0x70, 0x48, 0x48, 0x48, 0x48, 0x00, - 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, - 0x00, 0x00, 0x78, 0x44, 0x44, 0x44, 0x78, 0x40, - 0x00, 0x00, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x04, - 0x00, 0x00, 0x58, 0x24, 0x20, 0x20, 0x70, 0x00, - 0x00, 0x00, 0x38, 0x40, 0x38, 0x04, 0x38, 0x00, - 0x00, 0x20, 0x78, 0x20, 0x20, 0x28, 0x10, 0x00, - 0x00, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, - 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, - 0x00, 0x00, 0x44, 0x44, 0x54, 0x7C, 0x28, 0x00, - 0x00, 0x00, 0x48, 0x48, 0x30, 0x48, 0x48, 0x00, - 0x00, 0x00, 0x48, 0x48, 0x48, 0x38, 0x10, 0x60, - 0x00, 0x00, 0x78, 0x08, 0x30, 0x40, 0x78, 0x00, - 0x18, 0x20, 0x20, 0x60, 0x20, 0x20, 0x18, 0x00, - 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x00, - 0x30, 0x08, 0x08, 0x0C, 0x08, 0x08, 0x30, 0x00, - 0x28, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x38, 0x6C, 0x44, 0x44, 0x7C, 0x00, 0x00, - 0x38, 0x44, 0x40, 0x40, 0x44, 0x38, 0x10, 0x30, - 0x48, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, - 0x0C, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, - 0x38, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, - 0x28, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, - 0x30, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, - 0x38, 0x28, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, - 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x10, 0x30, - 0x38, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, - 0x28, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, - 0x30, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, - 0x28, 0x00, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, - 0x10, 0x28, 0x00, 0x10, 0x10, 0x10, 0x18, 0x00, - 0x20, 0x00, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, - 0x28, 0x00, 0x10, 0x28, 0x44, 0x7C, 0x44, 0x00, - 0x38, 0x28, 0x38, 0x6C, 0x44, 0x7C, 0x44, 0x00, - 0x0C, 0x00, 0x7C, 0x40, 0x78, 0x40, 0x7C, 0x00, - 0x00, 0x00, 0x78, 0x14, 0x7C, 0x50, 0x3C, 0x00, - 0x3C, 0x50, 0x50, 0x7C, 0x50, 0x50, 0x5C, 0x00, - 0x38, 0x00, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, - 0x28, 0x00, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, - 0x60, 0x00, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, - 0x38, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, - 0x60, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, - 0x28, 0x00, 0x48, 0x48, 0x48, 0x38, 0x10, 0x60, - 0x48, 0x30, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, - 0x28, 0x00, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, - 0x00, 0x10, 0x38, 0x40, 0x40, 0x38, 0x10, 0x00, - 0x18, 0x24, 0x20, 0x78, 0x20, 0x24, 0x5C, 0x00, - 0x44, 0x28, 0x10, 0x7C, 0x10, 0x7C, 0x10, 0x00, - 0x60, 0x50, 0x50, 0x68, 0x5C, 0x48, 0x48, 0x00, - 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x50, 0x20, - 0x18, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, - 0x18, 0x00, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, - 0x18, 0x00, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, - 0x18, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, - 0x28, 0x50, 0x00, 0x70, 0x48, 0x48, 0x48, 0x00, - 0x28, 0x50, 0x00, 0x48, 0x68, 0x58, 0x48, 0x00, - 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, 0x3C, 0x00, - 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, 0x78, 0x00, - 0x10, 0x00, 0x10, 0x30, 0x40, 0x44, 0x38, 0x00, - 0x00, 0x00, 0x7C, 0x40, 0x40, 0x40, 0x00, 0x00, - 0x00, 0x00, 0xFC, 0x04, 0x04, 0x00, 0x00, 0x00, - 0x40, 0x48, 0x50, 0x38, 0x44, 0x08, 0x1C, 0x00, - 0x40, 0x48, 0x50, 0x2C, 0x54, 0x1C, 0x04, 0x00, - 0x10, 0x00, 0x10, 0x10, 0x38, 0x38, 0x10, 0x00, - 0x00, 0x00, 0x24, 0x48, 0x24, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x48, 0x24, 0x48, 0x00, 0x00, 0x00, - 0x54, 0x00, 0xA8, 0x00, 0x54, 0x00, 0xA8, 0x00, - 0x54, 0xA8, 0x54, 0xA8, 0x54, 0xA8, 0x54, 0xA8, - 0xA8, 0xFC, 0x54, 0xFC, 0xA8, 0xFC, 0x54, 0xFC, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0xF0, 0x10, 0x10, 0x10, 0x10, - 0x10, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0x10, 0x10, - 0x50, 0x50, 0x50, 0xD0, 0x50, 0x50, 0x50, 0x50, - 0x00, 0x00, 0x00, 0xF0, 0x50, 0x50, 0x50, 0x50, - 0x00, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0x10, 0x10, - 0x50, 0xD0, 0x10, 0xD0, 0x50, 0x50, 0x50, 0x50, - 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, - 0x00, 0xF0, 0x10, 0xD0, 0x50, 0x50, 0x50, 0x50, - 0x50, 0xD0, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, - 0x50, 0x50, 0x50, 0xF0, 0x00, 0x00, 0x00, 0x00, - 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xF0, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x1C, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x10, 0x10, 0xFC, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xFC, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x1C, 0x10, 0x10, 0x10, 0x10, - 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x10, 0x10, 0xFC, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x1C, 0x10, 0x1C, 0x10, 0x10, 0x10, 0x10, - 0x50, 0x50, 0x50, 0x5C, 0x50, 0x50, 0x50, 0x50, - 0x50, 0x5C, 0x40, 0x7C, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x7C, 0x40, 0x5C, 0x50, 0x50, 0x50, 0x50, - 0x50, 0xDC, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xFC, 0x00, 0xDC, 0x50, 0x50, 0x50, 0x50, - 0x50, 0x5C, 0x40, 0x5C, 0x50, 0x50, 0x50, 0x50, - 0x00, 0xFC, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, - 0x50, 0xDC, 0x00, 0xDC, 0x50, 0x50, 0x50, 0x50, - 0x10, 0xFC, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, - 0x50, 0x50, 0x50, 0xFC, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xFC, 0x00, 0xFC, 0x10, 0x10, 0x10, 0x10, - 0x00, 0x00, 0x00, 0xFC, 0x50, 0x50, 0x50, 0x50, - 0x50, 0x50, 0x50, 0x7C, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x1C, 0x10, 0x1C, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1C, 0x10, 0x1C, 0x10, 0x10, 0x10, 0x10, - 0x00, 0x00, 0x00, 0x7C, 0x50, 0x50, 0x50, 0x50, - 0x50, 0x50, 0x50, 0xDC, 0x50, 0x50, 0x50, 0x50, - 0x10, 0xFC, 0x00, 0xFC, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x1C, 0x10, 0x10, 0x10, 0x10, - 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, - 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0xFC, 0xFC, - 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, - 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, - 0xFC, 0xFC, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x34, 0x48, 0x48, 0x34, 0x00, 0x00, - 0x00, 0x70, 0x48, 0x70, 0x48, 0x48, 0x70, 0x40, - 0x78, 0x48, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, - 0x00, 0x7C, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, - 0x78, 0x48, 0x20, 0x10, 0x20, 0x48, 0x78, 0x00, - 0x00, 0x00, 0x3C, 0x48, 0x48, 0x30, 0x00, 0x00, - 0x00, 0x00, 0x48, 0x48, 0x48, 0x70, 0x40, 0x40, - 0x00, 0x00, 0x28, 0x50, 0x10, 0x10, 0x10, 0x00, - 0x38, 0x10, 0x38, 0x44, 0x38, 0x10, 0x38, 0x00, - 0x30, 0x48, 0x48, 0x78, 0x48, 0x48, 0x30, 0x00, - 0x00, 0x38, 0x44, 0x44, 0x28, 0x28, 0x6C, 0x00, - 0x30, 0x40, 0x20, 0x10, 0x38, 0x48, 0x30, 0x00, - 0x00, 0x00, 0x28, 0x54, 0x54, 0x28, 0x00, 0x00, - 0x00, 0x10, 0x38, 0x54, 0x54, 0x38, 0x10, 0x00, - 0x00, 0x38, 0x40, 0x78, 0x40, 0x38, 0x00, 0x00, - 0x00, 0x30, 0x48, 0x48, 0x48, 0x48, 0x00, 0x00, - 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0x00, - 0x00, 0x10, 0x38, 0x10, 0x00, 0x38, 0x00, 0x00, - 0x40, 0x30, 0x08, 0x30, 0x40, 0x00, 0x78, 0x00, - 0x08, 0x30, 0x40, 0x30, 0x08, 0x00, 0x78, 0x00, - 0x00, 0x08, 0x14, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x50, 0x20, 0x00, - 0x00, 0x10, 0x00, 0x7C, 0x00, 0x10, 0x00, 0x00, - 0x00, 0x28, 0x50, 0x00, 0x28, 0x50, 0x00, 0x00, - 0x30, 0x48, 0x48, 0x30, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1C, 0x10, 0x10, 0x50, 0x50, 0x20, 0x00, - 0x50, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, - 0x60, 0x10, 0x20, 0x70, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00, + 0x00, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, + 0x40, 0x40, 0x78, 0x44, 0x44, 0x44, 0x78, 0x00, + 0x00, 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x00, + 0x04, 0x04, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x00, + 0x00, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, + 0x18, 0x20, 0x20, 0x78, 0x20, 0x20, 0x20, 0x00, + 0x00, 0x00, 0x3C, 0x44, 0x44, 0x3C, 0x04, 0x38, + 0x40, 0x40, 0x70, 0x48, 0x48, 0x48, 0x48, 0x00, + 0x10, 0x00, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, + 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x48, 0x30, + 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, + 0x00, 0x00, 0x68, 0x54, 0x54, 0x44, 0x44, 0x00, + 0x00, 0x00, 0x70, 0x48, 0x48, 0x48, 0x48, 0x00, + 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, + 0x00, 0x00, 0x78, 0x44, 0x44, 0x44, 0x78, 0x40, + 0x00, 0x00, 0x3C, 0x44, 0x44, 0x44, 0x3C, 0x04, + 0x00, 0x00, 0x58, 0x24, 0x20, 0x20, 0x70, 0x00, + 0x00, 0x00, 0x38, 0x40, 0x38, 0x04, 0x38, 0x00, + 0x00, 0x20, 0x78, 0x20, 0x20, 0x28, 0x10, 0x00, + 0x00, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, + 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00, + 0x00, 0x00, 0x44, 0x44, 0x54, 0x7C, 0x28, 0x00, + 0x00, 0x00, 0x48, 0x48, 0x30, 0x48, 0x48, 0x00, + 0x00, 0x00, 0x48, 0x48, 0x48, 0x38, 0x10, 0x60, + 0x00, 0x00, 0x78, 0x08, 0x30, 0x40, 0x78, 0x00, + 0x18, 0x20, 0x20, 0x60, 0x20, 0x20, 0x18, 0x00, + 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x10, 0x00, + 0x30, 0x08, 0x08, 0x0C, 0x08, 0x08, 0x30, 0x00, + 0x28, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x38, 0x6C, 0x44, 0x44, 0x7C, 0x00, 0x00, + 0x38, 0x44, 0x40, 0x40, 0x44, 0x38, 0x10, 0x30, + 0x48, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, + 0x0C, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, + 0x38, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, + 0x28, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, + 0x30, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, + 0x38, 0x28, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, + 0x00, 0x38, 0x44, 0x40, 0x44, 0x38, 0x10, 0x30, + 0x38, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, + 0x28, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, + 0x30, 0x00, 0x38, 0x44, 0x78, 0x40, 0x38, 0x00, + 0x28, 0x00, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, + 0x10, 0x28, 0x00, 0x10, 0x10, 0x10, 0x18, 0x00, + 0x20, 0x00, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, + 0x28, 0x00, 0x10, 0x28, 0x44, 0x7C, 0x44, 0x00, + 0x38, 0x28, 0x38, 0x6C, 0x44, 0x7C, 0x44, 0x00, + 0x0C, 0x00, 0x7C, 0x40, 0x78, 0x40, 0x7C, 0x00, + 0x00, 0x00, 0x78, 0x14, 0x7C, 0x50, 0x3C, 0x00, + 0x3C, 0x50, 0x50, 0x7C, 0x50, 0x50, 0x5C, 0x00, + 0x38, 0x00, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, + 0x28, 0x00, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, + 0x60, 0x00, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, + 0x38, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, + 0x60, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, + 0x28, 0x00, 0x48, 0x48, 0x48, 0x38, 0x10, 0x60, + 0x48, 0x30, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, + 0x28, 0x00, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, + 0x00, 0x10, 0x38, 0x40, 0x40, 0x38, 0x10, 0x00, + 0x18, 0x24, 0x20, 0x78, 0x20, 0x24, 0x5C, 0x00, + 0x44, 0x28, 0x10, 0x7C, 0x10, 0x7C, 0x10, 0x00, + 0x60, 0x50, 0x50, 0x68, 0x5C, 0x48, 0x48, 0x00, + 0x08, 0x14, 0x10, 0x38, 0x10, 0x10, 0x50, 0x20, + 0x18, 0x00, 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, + 0x18, 0x00, 0x10, 0x10, 0x10, 0x10, 0x18, 0x00, + 0x18, 0x00, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, + 0x18, 0x00, 0x48, 0x48, 0x48, 0x58, 0x28, 0x00, + 0x28, 0x50, 0x00, 0x70, 0x48, 0x48, 0x48, 0x00, + 0x28, 0x50, 0x00, 0x48, 0x68, 0x58, 0x48, 0x00, + 0x38, 0x04, 0x3C, 0x44, 0x3C, 0x00, 0x3C, 0x00, + 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, 0x78, 0x00, + 0x10, 0x00, 0x10, 0x30, 0x40, 0x44, 0x38, 0x00, + 0x00, 0x00, 0x7C, 0x40, 0x40, 0x40, 0x00, 0x00, + 0x00, 0x00, 0xFC, 0x04, 0x04, 0x00, 0x00, 0x00, + 0x40, 0x48, 0x50, 0x38, 0x44, 0x08, 0x1C, 0x00, + 0x40, 0x48, 0x50, 0x2C, 0x54, 0x1C, 0x04, 0x00, + 0x10, 0x00, 0x10, 0x10, 0x38, 0x38, 0x10, 0x00, + 0x00, 0x00, 0x24, 0x48, 0x24, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x48, 0x24, 0x48, 0x00, 0x00, 0x00, + 0x54, 0x00, 0xA8, 0x00, 0x54, 0x00, 0xA8, 0x00, + 0x54, 0xA8, 0x54, 0xA8, 0x54, 0xA8, 0x54, 0xA8, + 0xA8, 0xFC, 0x54, 0xFC, 0xA8, 0xFC, 0x54, 0xFC, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0xF0, 0x10, 0x10, 0x10, 0x10, + 0x10, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0x10, 0x10, + 0x50, 0x50, 0x50, 0xD0, 0x50, 0x50, 0x50, 0x50, + 0x00, 0x00, 0x00, 0xF0, 0x50, 0x50, 0x50, 0x50, + 0x00, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0x10, 0x10, + 0x50, 0xD0, 0x10, 0xD0, 0x50, 0x50, 0x50, 0x50, + 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, + 0x00, 0xF0, 0x10, 0xD0, 0x50, 0x50, 0x50, 0x50, + 0x50, 0xD0, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, + 0x50, 0x50, 0x50, 0xF0, 0x00, 0x00, 0x00, 0x00, + 0x10, 0xF0, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xF0, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x1C, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x10, 0x10, 0xFC, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFC, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x1C, 0x10, 0x10, 0x10, 0x10, + 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x10, 0x10, 0xFC, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x1C, 0x10, 0x1C, 0x10, 0x10, 0x10, 0x10, + 0x50, 0x50, 0x50, 0x5C, 0x50, 0x50, 0x50, 0x50, + 0x50, 0x5C, 0x40, 0x7C, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x7C, 0x40, 0x5C, 0x50, 0x50, 0x50, 0x50, + 0x50, 0xDC, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFC, 0x00, 0xDC, 0x50, 0x50, 0x50, 0x50, + 0x50, 0x5C, 0x40, 0x5C, 0x50, 0x50, 0x50, 0x50, + 0x00, 0xFC, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, + 0x50, 0xDC, 0x00, 0xDC, 0x50, 0x50, 0x50, 0x50, + 0x10, 0xFC, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, + 0x50, 0x50, 0x50, 0xFC, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFC, 0x00, 0xFC, 0x10, 0x10, 0x10, 0x10, + 0x00, 0x00, 0x00, 0xFC, 0x50, 0x50, 0x50, 0x50, + 0x50, 0x50, 0x50, 0x7C, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x1C, 0x10, 0x1C, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1C, 0x10, 0x1C, 0x10, 0x10, 0x10, 0x10, + 0x00, 0x00, 0x00, 0x7C, 0x50, 0x50, 0x50, 0x50, + 0x50, 0x50, 0x50, 0xDC, 0x50, 0x50, 0x50, 0x50, + 0x10, 0xFC, 0x00, 0xFC, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x1C, 0x10, 0x10, 0x10, 0x10, + 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, + 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0xFC, 0xFC, + 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, + 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, + 0xFC, 0xFC, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x34, 0x48, 0x48, 0x34, 0x00, 0x00, + 0x00, 0x70, 0x48, 0x70, 0x48, 0x48, 0x70, 0x40, + 0x78, 0x48, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, + 0x00, 0x7C, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, + 0x78, 0x48, 0x20, 0x10, 0x20, 0x48, 0x78, 0x00, + 0x00, 0x00, 0x3C, 0x48, 0x48, 0x30, 0x00, 0x00, + 0x00, 0x00, 0x48, 0x48, 0x48, 0x70, 0x40, 0x40, + 0x00, 0x00, 0x28, 0x50, 0x10, 0x10, 0x10, 0x00, + 0x38, 0x10, 0x38, 0x44, 0x38, 0x10, 0x38, 0x00, + 0x30, 0x48, 0x48, 0x78, 0x48, 0x48, 0x30, 0x00, + 0x00, 0x38, 0x44, 0x44, 0x28, 0x28, 0x6C, 0x00, + 0x30, 0x40, 0x20, 0x10, 0x38, 0x48, 0x30, 0x00, + 0x00, 0x00, 0x28, 0x54, 0x54, 0x28, 0x00, 0x00, + 0x00, 0x10, 0x38, 0x54, 0x54, 0x38, 0x10, 0x00, + 0x00, 0x38, 0x40, 0x78, 0x40, 0x38, 0x00, 0x00, + 0x00, 0x30, 0x48, 0x48, 0x48, 0x48, 0x00, 0x00, + 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00, 0x00, + 0x00, 0x10, 0x38, 0x10, 0x00, 0x38, 0x00, 0x00, + 0x40, 0x30, 0x08, 0x30, 0x40, 0x00, 0x78, 0x00, + 0x08, 0x30, 0x40, 0x30, 0x08, 0x00, 0x78, 0x00, + 0x00, 0x08, 0x14, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x50, 0x20, 0x00, + 0x00, 0x10, 0x00, 0x7C, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x28, 0x50, 0x00, 0x28, 0x50, 0x00, 0x00, + 0x30, 0x48, 0x48, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1C, 0x10, 0x10, 0x50, 0x50, 0x20, 0x00, + 0x50, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, + 0x60, 0x10, 0x20, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; #endif // INCLUDED_TERMINAL6_H diff --git a/include/alfe/thread.h b/include/alfe/thread.h index 1d0ef190..57f5699d 100644 --- a/include/alfe/thread.h +++ b/include/alfe/thread.h @@ -1,18 +1,18 @@ +#include "alfe/main.h" + #ifndef INCLUDED_LOCK_H #define INCLUDED_LOCK_H -#include "alfe/string.h" - // TODO: Posix version -class Event : public AutoHandle +class Event : public Handle { public: - Event() : AutoHandle() + Event() { HANDLE handle = CreateEvent(NULL, FALSE, FALSE, NULL); IF_NULL_THROW(handle); - set(handle); + Handle::operator=(AutoHandle(handle)); } void signal() { IF_ZERO_THROW(SetEvent(operator HANDLE())); } void wait() @@ -21,17 +21,15 @@ class Event : public AutoHandle } }; -class Thread : public AutoHandle +class Thread : public Handle { public: - Thread() - : _started(false), - _error(false) + Thread() : _started(false), _error(false) { HANDLE handle = CreateThread( NULL, 0, threadStaticProc, this, CREATE_SUSPENDED, NULL); IF_NULL_THROW(handle); - set(handle); + Handle::operator=(AutoHandle(handle)); } void setPriority(int nPriority) { diff --git a/include/alfe/type.h b/include/alfe/type.h index 6f7cc166..e2569996 100644 --- a/include/alfe/type.h +++ b/include/alfe/type.h @@ -1,7 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_TYPE_H #define INCLUDED_TYPE_H -#include "alfe/string.h" #include "alfe/any.h" #include "alfe/hash_table.h" #include "alfe/value.h" diff --git a/include/alfe/uncopyable.h b/include/alfe/uncopyable.h index c5386d99..3740a4f8 100644 --- a/include/alfe/uncopyable.h +++ b/include/alfe/uncopyable.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_UNCOPYABLE_H #define INCLUDED_UNCOPYABLE_H diff --git a/include/alfe/user.h b/include/alfe/user.h index 060ff86e..84ca0e12 100644 --- a/include/alfe/user.h +++ b/include/alfe/user.h @@ -1,12 +1,10 @@ +#include "alfe/main.h" + #ifndef INCLUDED_USER_H #define INCLUDED_USER_H // TODO: Xlib port -#include "alfe/swap.h" -#include "alfe/string.h" -#include "alfe/vectors.h" -#include "alfe/bitmap.h" #include #include #include @@ -116,7 +114,6 @@ template class WindowsTemplate : Uncopyable bool Windows::_failed = false; Exception Windows::_exception; - template class WindowTemplate { friend class WindowsTemplate; @@ -268,7 +265,7 @@ template class RootWindow : public Base }; -class DeviceContext +class DeviceContext : Uncopyable { public: void NoFailSelectObject(HGDIOBJ hObject) { ::SelectObject(_hdc, hObject); } @@ -550,24 +547,6 @@ template class AnimatedWindow : public Base }; -int pumpMessages() -{ - BOOL bRet; - do { - MSG msg; - bRet = GetMessage(&msg, NULL, 0, 0); - IF_MINUS_ONE_THROW(bRet); - if (bRet != 0) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - else - return static_cast(msg.wParam); - } while (bRet != 0); - return 0; -} - - class Pen { public: diff --git a/include/alfe/value.h b/include/alfe/value.h index 4e500b95..4d85a316 100644 --- a/include/alfe/value.h +++ b/include/alfe/value.h @@ -1,8 +1,8 @@ +#include "alfe/main.h" + #ifndef INCLUDED_VALUE_H #define INCLUDED_VALUE_H -#include "alfe/reference_counted.h" - template class Value { public: diff --git a/include/alfe/vectors.h b/include/alfe/vectors.h index 34104c4a..2b14c54f 100644 --- a/include/alfe/vectors.h +++ b/include/alfe/vectors.h @@ -1,3 +1,5 @@ +#include "alfe/main.h" + #ifndef INCLUDED_VECTORS_H #define INCLUDED_VECTORS_H diff --git a/intervals/simulator/simulator2.cpp b/intervals/simulator/simulator2.cpp index 5eed8b72..acf6ff3b 100644 --- a/intervals/simulator/simulator2.cpp +++ b/intervals/simulator/simulator2.cpp @@ -529,7 +529,6 @@ template class BarTemplate : public ReferenceCounted UInt8 _io; int _f; UInt8 _data; - Handle _console; int _state; int _cyclesSinceLastSync; }; diff --git a/multifunction/multifunction.cpp b/multifunction/multifunction.cpp index 1173ce11..434795dd 100644 --- a/multifunction/multifunction.cpp +++ b/multifunction/multifunction.cpp @@ -79,7 +79,7 @@ class Program : public ProgramBase s += "---"; s += " "; } - _console.write(s + "\n"); + console.write(s + "\n"); } } }; diff --git a/perceptual/perceptual.cpp b/perceptual/perceptual.cpp index 47985dfd..4c440300 100644 --- a/perceptual/perceptual.cpp +++ b/perceptual/perceptual.cpp @@ -419,7 +419,7 @@ class PerceptualImage : public Image class Program : public ProgramBase { public: - int run() + void run() { srand(time(0)); PerceptualImage image; @@ -437,6 +437,6 @@ class Program : public ProgramBase ThreeDWindow window(awp); window.show(_nCmdShow); - return pumpMessages(); + pumpMessages(); } }; diff --git a/run_random/run_random.cpp b/run_random/run_random.cpp index 31594575..4fa6d8ac 100644 --- a/run_random/run_random.cpp +++ b/run_random/run_random.cpp @@ -54,7 +54,7 @@ class Program : public ProgramBase COMInitializer com(COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); Collection collection; if (_arguments.count() == 1) { - _console.write("Usage: run_random \n"); + console.write("Usage: run_random \n"); return; } for (int i = 1; i < _arguments.count(); ++i) diff --git a/scratch.txt b/scratch.txt index f97733d2..3055f939 100644 --- a/scratch.txt +++ b/scratch.txt @@ -5,11 +5,6 @@ How do we deal with the problem that {} can delimit either a compound statement CompoundStatement or CompoundExpression depending on how it turns out, so its contents don't need to be re-parsed when it is converted. -Bitmap: - A Bitmap may own its own bits or just be a pointer into some other Bitmap's - bits. - Preserve that information with a flag or with - Want to be able to write "offset = (outputSize - inputSize)/2;" in config files We want the TypeConverter to be able to create its own Conversions by diff --git a/test/test.cpp b/test/test.cpp index c047c9a2..8eeefc8a 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -11,7 +11,7 @@ class Program : public ProgramBase String b("b"); String c = a+b; String d = c + "\n"; - _console.write(d); // Should print "ab" + console.write(d); // Should print "ab" } { @@ -23,7 +23,7 @@ class Program : public ProgramBase s.get(); s.get(); int b = s.offset(); - _console.write(s.subString(a, b)); // Should print "oob" + console.write(s.subString(a, b)); // Should print "oob" } } }; diff --git a/tone_matrix/debugger/debugger.cpp b/tone_matrix/debugger/debugger.cpp index 8cd25c63..2d30280a 100644 --- a/tone_matrix/debugger/debugger.cpp +++ b/tone_matrix/debugger/debugger.cpp @@ -5,7 +5,7 @@ class Program : public ProgramBase public: void run() { - AutoHandle com(CreateFile( + Handle com = Handle::Auto(CreateFile( L"COM3", GENERIC_READ | GENERIC_WRITE, 0, // must be opened with exclusive-access