├── .editorconfig
├── .github
└── workflows
│ └── msbuild.yml
├── .gitignore
├── Changelog.txt
├── LICENSE.md
├── README.md
├── build
├── Incursion.props
├── Incursion.sln
├── Incursion.vcxproj
├── Incursion.vcxproj.filters
├── IncursionDebug.props
├── IncursionRelease.props
├── exe_curses.vcxproj
├── exe_curses.vcxproj.filters
├── exe_libtcod.vcxproj
├── exe_libtcod.vcxproj.filters
├── modaccent.vcxproj
├── modaccent.vcxproj.filters
└── x64.props
├── dependencies
└── flex.exe
├── docs
├── Notes.txt
├── incursionscript.md
├── modules.md
└── reference.md
├── fonts
├── 12x16.png
├── 16x12.png
├── 16x16.png
└── 8x8.png
├── inc
├── Api.h
├── ArmourTab.h
├── Base.h
├── ConstNam.h
├── Creature.h
├── Defines.h
├── Events.h
├── Feature.h
├── Globals.h
├── Incursion.h
├── Inline.h
├── Item.h
├── Magic.h
├── Map.h
├── RComp.h
├── Res.h
├── Target.h
├── Term.h
├── cpp.h
├── cppdef.h
├── dispatch.h
├── lz.h
├── rle.h
└── yygram.h
├── lang
├── Grammar.acc
└── Tokens.lex
├── lib
├── abilities.irh
├── alchemy.irh
├── classes.irh
├── defines.irh
├── domains.irh
├── dungeon.irh
├── enclist.irh
├── flavors.irh
├── help.irh
├── m_items.irh
├── main.irc
├── module-example.irc
├── mon1.irh
├── mon2.irh
├── mon3.irh
├── mon4.irh
├── mundane.irh
├── new.irh
├── prestige.irh
├── pspells.irh
├── races.irh
├── religion.irh
├── sk_descs.irh
├── sp_books.irh
├── subraces.irh
├── threats.irh
├── weapons.irh
└── wspells.irh
├── modaccent
├── README
├── include
│ ├── gen.h
│ └── sets.h
└── src
│ ├── actions.c
│ ├── ana.c
│ ├── auxil.c
│ ├── bnf.c
│ ├── code.c
│ ├── encode.c
│ ├── errmsg.c
│ ├── flatten.c
│ ├── grts.c
│ ├── idents.c
│ ├── lexinfo.c
│ ├── main.c
│ ├── output.c
│ ├── sets.c
│ ├── strings.c
│ ├── verbose.c
│ ├── yylex.c
│ └── yytab.c
└── src
├── Annot.cpp
├── Art.cpp
├── Base.cpp
├── CalcVal.cpp
├── Create.cpp
├── Creature.cpp
├── Debug.cpp
├── Display.cpp
├── Djikstra.cpp
├── Effects.cpp
├── Encounter.cpp
├── Event.cpp
├── FeatTab.cpp
├── Feature.cpp
├── Fight.cpp
├── Help.cpp
├── Inv.cpp
├── Item.cpp
├── Magic.cpp
├── Main.cpp
├── MakeLev.cpp
├── Managers.cpp
├── Message.cpp
├── Monster.cpp
├── Move.cpp
├── OverGen.cpp
├── Overland.cpp
├── Player.cpp
├── Prayer.cpp
├── Quest.cpp
├── RComp.cpp
├── Registry.cpp
├── Res.cpp
├── Sheet.cpp
├── Skills.cpp
├── Social.cpp
├── Status.cpp
├── Tables.cpp
├── Target.cpp
├── Term.cpp
├── TextTerm.cpp
├── Tokens.cpp
├── VMachine.cpp
├── Values.cpp
├── Vision.cpp
├── Wcurses.cpp
├── Wlibtcod.cpp
├── cpp1.c
├── cpp2.c
├── cpp3.c
├── cpp4.c
├── cpp5.c
├── cpp6.c
├── lz.c
├── rle.c
└── yygram.cpp
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # 4 space indentation
7 | [*.{c,h,cpp,irh,irc}]
8 | indent_style = space
9 | indent_size = 4
10 |
--------------------------------------------------------------------------------
/.github/workflows/msbuild.yml:
--------------------------------------------------------------------------------
1 | # This workflow uses actions that are not certified by GitHub.
2 | # They are provided by a third-party and are governed by
3 | # separate terms of service, privacy policy, and support
4 | # documentation.
5 |
6 | name: MSBuild
7 |
8 | on:
9 | push:
10 | pull_request:
11 |
12 | env:
13 | # Path to the solution file relative to the root of the project.
14 | SOLUTION_FILE_PATH: build\Incursion.sln
15 | # Generated files to clean and check
16 | GENERATED_FILES: src/tokens.cpp src/yygram.cpp inc/yygram.h
17 |
18 | permissions:
19 | contents: read
20 |
21 | jobs:
22 | build:
23 | strategy:
24 | matrix:
25 | configuration: ["Release", "Debug"]
26 | platform: ["Win32", "x64"]
27 | runs-on: windows-2022
28 |
29 | steps:
30 | - uses: actions/checkout@v4
31 |
32 | - name: Add MSBuild to PATH
33 | uses: microsoft/setup-msbuild@v2
34 |
35 | - name: Obtain external dependencies
36 | run: |
37 | pushd dependencies
38 | curl -L -O https://github.com/libtcod/libtcod/releases/download/1.7.0/libtcod-1.7.0-${{ matrix.platform == 'Win32' && 'x86' || 'x86_64' }}-msvc.zip
39 | 7z x libtcod-*.zip
40 | popd
41 |
42 | - name: Clean generated files
43 | if: matrix.platform == 'Win32' && matrix.configuration == 'Debug'
44 | shell: bash
45 | run: rm -v ${{env.GENERATED_FILES}}
46 |
47 | - name: Build
48 | # Add additional options to the MSBuild command line here (like platform or verbosity level).
49 | # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
50 | run: msbuild /m /p:Configuration=${{matrix.configuration}} /p:Platform=${{matrix.platform}} ${{env.SOLUTION_FILE_PATH}}
51 |
52 | - name: Verify generated files
53 | run: git diff --exit-code ${{env.GENERATED_FILES}}
54 |
55 | - name: Copy binaries to project root
56 | shell: bash
57 | run: cp -v build/*/*/exe_libtcod/Incursion.exe dependencies/libtcod-*/libtcod.dll dependencies/libtcod-*/SDL2.dll .
58 |
59 | - name: Compile mod
60 | if: matrix.configuration == 'Debug'
61 | shell: bash
62 | run: ./Incursion.exe -compile
63 |
64 | - name: Upload mod
65 | if: matrix.configuration == 'Debug'
66 | uses: actions/upload-artifact@v4
67 | with:
68 | name: mod-${{ matrix.platform }}
69 | path: mod
70 | retention-days: 1
71 |
72 | - name: Upload binaries
73 | uses: actions/upload-artifact@v4
74 | with:
75 | name: direct-binaries-${{matrix.configuration}}-${{matrix.platform}}
76 | path: |
77 | *.exe
78 | *.dll
79 | retention-days: 1
80 |
81 | package:
82 | needs: [build]
83 | runs-on: ubuntu-latest
84 | strategy:
85 | matrix:
86 | platform: ["Win32", "x64"]
87 |
88 | steps:
89 | - uses: actions/checkout@v4
90 | - name: Fetch mod
91 | uses: actions/download-artifact@v4
92 | with:
93 | name: mod-${{ matrix.platform }}
94 | path: mod
95 | - name: Fetch binaries
96 | uses: actions/download-artifact@v4
97 | with:
98 | name: direct-binaries-Release-${{matrix.platform}}
99 | path: .
100 | - name: Package Incursion
101 | uses: actions/upload-artifact@v4
102 | with:
103 | name: Incursion-${{matrix.platform}}
104 | path: |
105 | *.exe
106 | *.dll
107 | *.md
108 | *.txt
109 | fonts
110 | docs
111 | mod
112 | retention-days: 30
113 | compression-level: 9
114 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.slo
3 | *.lo
4 | *.o
5 | *.obj
6 |
7 | # Windows build & dependencies
8 | .vs
9 | build/dependencies
10 | build/packages
11 | build/run
12 | build/Win32
13 | build/x64
14 | *.vcxproj.user
15 | *.suo
16 | *.sdf
17 | Incursion.opensdf
18 |
19 | # Incursion specific temporary files.
20 | lib/dispatch.h
21 | lib/program.i
22 | Options.dat
23 | save
24 |
25 | # Local nonsense.
26 | _external
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Incursion
2 | =========
3 |
4 | Incursion is a roguelike developed by Julian Mensch. He has kindly released the source he has for some of the later versions.
5 |
6 | At this time building is only supported on Windows, using Visual Studio 2022. You should be able to substitute other versions of Visual Studio, or write a makefile if you plan to compile on another platform.
7 |
8 | The Incursion website is [found here](http://incursion-roguelike.net).
9 |
10 | Frequently asked questions
11 | ==========================
12 |
13 | Q. When I press a movement key, it sends two keypresses?
14 | A. Turn off numlock. You are using a keypad on a full keyboard. SDL2 does not support differentiating between number keypad presses, and number key presses. This means we cannot either.
15 |
16 | Recent Changes
17 | --------------
18 |
19 | Read 'Changelog.txt'. The version accompanying any source code should reflect the changes relating to that source code. The version on Github will reflect the latest changes.
20 |
21 | Support the development
22 | -----------------------
23 |
24 | Want to support development? Want to encourage work on certain aspects? Offer me money if you really want, this is not a project I work on these days. Or chip in and help out with pull requests! Or fork it and release something it with a name that does not confuse your builds with this project.
25 |
26 | Links
27 | -----
28 |
29 | * Page on [Rogue Basin](https://www.roguebasin.com/index.php?title=Incursion).
30 | * Discuss things with us in [our discussion area](https://github.com/rmtew/incursion-roguelike/discussions).
31 | * Report a bug on [our issues tracker](https://github.com/rmtew/incursion-roguelike/issues).
32 | * Find the source code in the [Incursion repository](https://github.com/rmtew/incursion-roguelike).
33 |
34 | Windows build instructions
35 | --------------------------
36 |
37 | **Recommended compiler:**
38 |
39 | * Visual Studio Community 2022: [web-based installer](https://visualstudio.microsoft.com/downloads/#d-community).
40 |
41 | **Dependencies:**
42 |
43 | * libtcod 1.7.0 binaries: [Github release page](https://github.com/libtcod/libtcod/releases/tag/1.7.0).
44 |
45 | These are optional extras, for the unsupported pdcurses-based console version or making changes to the module language. The links may be stale.
46 |
47 | * `flex.exe`: [winflexbison@sourceforge](http://sourceforge.net/projects/winflexbison/) 660 KB (extract and rename `win_flex.exe` to `flex.exe`).
48 | * `pdcurses`: [pdcurses@sourceforge](http://pdcurses.sourceforge.net) 384 KB
49 |
50 | **Compilation instructions:**
51 |
52 | These instructions are intended to allow you to get Incursion to the point where you can debug it within Visual Studio.
53 |
54 | 1. Download the following two binary releases for [libtcod 1.7.0](https://github.com/libtcod/libtcod/releases/tag/1.7.0):
55 | * `libtcod-1.7.0-x86-msvc.zip`.
56 | * `libtcod-1.7.0-x86_64-msvc.zip`.
57 | 2. Extract each to the top-level `dependencies` directory.
58 | * `dependencies\libtcod-1.7.0-x86-msvc`.
59 | * `dependencies\libtcod-1.7.0-x86_64-msvc`.
60 | 3. Open `build\Incursion.sln` in Visual Studio 2022.
61 | 4. Ensure `exe_libtcod` is the default project. If it is not, right click on it and select "Set as Startup Project".
62 | 5. Build a Debug solution.
63 | 6. Run the built `Incursion.exe` with the command-line `build/Win32/Debug/exe_libtcod/Incursion.exe -compile` with a current directory of the top-level source directory. The module compilation code is not built into Release builds. It should generate a `mod\Incursion.mod` file which provides the game rules, setting and other things.
64 |
65 | Note that there are custom build steps in Debug configurations that update this resource compiler, under the "Language Files" folder within Visual Studio. `tokens.lex` is parsed by `flex.exe`. `grammar.acc` is parsed by `modaccent.exe`. These steps may need to be disabled to compile the x64 Debug build as `modaccent.exe` is based on old external code that is not 64-bit compatible at this time. The output files of both steps are checked in and only deleted by rerunning these steps, so running them is not necessary and if it is, it can be done in Win32 Debug configuration.
66 |
67 | At this point, you are ready to do some development, or just play the latest version of the source code by debugging it within Visual Studio. Congratulations!
68 |
69 | **Running the game:**
70 |
71 | The following directory structure is required to have a running game installation:
72 |
73 | ```
74 | Incursion.exe
75 | libtcod.dll
76 | SDL2.dll
77 | fonts\12x16.png
78 | fonts\16x12.png
79 | fonts\16x16.png
80 | fonts\8x8.png
81 | mod\Incursion.Mod
82 | ```
83 |
84 |
85 | **x64 support:**
86 |
87 | Yes, you can compile an x64 build of Incursion. It will runs and enters a new game without crashing. Will it allow someone to play without crashing any more than the Win32 version does? No idea!
88 |
89 | Note that the build will fail unless you can work out a way to get it to use the Win32 build of modaccent, which crashes when run as an x64 binary. Incursion gives a lot of compilation warnings when compiled for the x64 platform, as it is an older project. But `modaccent` is even older source code which uses some arcane parts of the original C programming standard! Anyone wanting to use x64 builds should not expect any bugs filed about it to be resolved.
90 |
91 | Also, the unsupported `exe_curses` prototype has been disabled for x64. `pdcurses` only provides a makefile for the Win32 platfom.
--------------------------------------------------------------------------------
/build/Incursion.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | false
7 |
8 |
9 |
10 | true
11 | Console
12 | false
13 |
14 |
15 | 5.01
16 | dependencies\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)
17 |
18 |
19 |
20 |
21 | ..\inc;dependencies\include;%(AdditionalIncludeDirectories)
22 | _MBCS;WIN32;_CONSOLE;%(PreprocessorDefinitions)
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/build/Incursion.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio 14
3 | VisualStudioVersion = 14.0.25420.1
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_incursion", "Incursion.vcxproj", "{9040FAAA-3DBF-41E9-BF70-4FACC525DC84}"
6 | EndProject
7 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "modaccent", "modaccent.vcxproj", "{8CBF1412-2722-4FC4-9801-44943CC0BCB2}"
8 | EndProject
9 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exe_curses", "exe_curses.vcxproj", "{E227072C-E53A-4616-B6D4-46BA536509BE}"
10 | EndProject
11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exe_libtcod", "exe_libtcod.vcxproj", "{74143DA4-9FB7-49A5-A2E1-9D98E7A52742}"
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Win32 = Debug|Win32
16 | Debug|x64 = Debug|x64
17 | Release|Win32 = Release|Win32
18 | Release|x64 = Release|x64
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {9040FAAA-3DBF-41E9-BF70-4FACC525DC84}.Debug|Win32.ActiveCfg = Debug|Win32
22 | {9040FAAA-3DBF-41E9-BF70-4FACC525DC84}.Debug|Win32.Build.0 = Debug|Win32
23 | {9040FAAA-3DBF-41E9-BF70-4FACC525DC84}.Debug|x64.ActiveCfg = Debug|x64
24 | {9040FAAA-3DBF-41E9-BF70-4FACC525DC84}.Debug|x64.Build.0 = Debug|x64
25 | {9040FAAA-3DBF-41E9-BF70-4FACC525DC84}.Release|Win32.ActiveCfg = Release|Win32
26 | {9040FAAA-3DBF-41E9-BF70-4FACC525DC84}.Release|Win32.Build.0 = Release|Win32
27 | {9040FAAA-3DBF-41E9-BF70-4FACC525DC84}.Release|x64.ActiveCfg = Release|x64
28 | {9040FAAA-3DBF-41E9-BF70-4FACC525DC84}.Release|x64.Build.0 = Release|x64
29 | {8CBF1412-2722-4FC4-9801-44943CC0BCB2}.Debug|Win32.ActiveCfg = Debug|Win32
30 | {8CBF1412-2722-4FC4-9801-44943CC0BCB2}.Debug|Win32.Build.0 = Debug|Win32
31 | {8CBF1412-2722-4FC4-9801-44943CC0BCB2}.Debug|x64.ActiveCfg = Debug|x64
32 | {8CBF1412-2722-4FC4-9801-44943CC0BCB2}.Debug|x64.Build.0 = Debug|x64
33 | {8CBF1412-2722-4FC4-9801-44943CC0BCB2}.Release|Win32.ActiveCfg = Release|Win32
34 | {8CBF1412-2722-4FC4-9801-44943CC0BCB2}.Release|Win32.Build.0 = Release|Win32
35 | {8CBF1412-2722-4FC4-9801-44943CC0BCB2}.Release|x64.ActiveCfg = Release|x64
36 | {8CBF1412-2722-4FC4-9801-44943CC0BCB2}.Release|x64.Build.0 = Release|x64
37 | {E227072C-E53A-4616-B6D4-46BA536509BE}.Debug|Win32.ActiveCfg = Debug|Win32
38 | {E227072C-E53A-4616-B6D4-46BA536509BE}.Debug|x64.ActiveCfg = Release|x64
39 | {E227072C-E53A-4616-B6D4-46BA536509BE}.Release|Win32.ActiveCfg = Release|Win32
40 | {E227072C-E53A-4616-B6D4-46BA536509BE}.Release|x64.ActiveCfg = Release|x64
41 | {74143DA4-9FB7-49A5-A2E1-9D98E7A52742}.Debug|Win32.ActiveCfg = Debug|Win32
42 | {74143DA4-9FB7-49A5-A2E1-9D98E7A52742}.Debug|Win32.Build.0 = Debug|Win32
43 | {74143DA4-9FB7-49A5-A2E1-9D98E7A52742}.Debug|x64.ActiveCfg = Debug|x64
44 | {74143DA4-9FB7-49A5-A2E1-9D98E7A52742}.Debug|x64.Build.0 = Debug|x64
45 | {74143DA4-9FB7-49A5-A2E1-9D98E7A52742}.Release|Win32.ActiveCfg = Release|Win32
46 | {74143DA4-9FB7-49A5-A2E1-9D98E7A52742}.Release|Win32.Build.0 = Release|Win32
47 | {74143DA4-9FB7-49A5-A2E1-9D98E7A52742}.Release|x64.ActiveCfg = Release|x64
48 | {74143DA4-9FB7-49A5-A2E1-9D98E7A52742}.Release|x64.Build.0 = Release|x64
49 | EndGlobalSection
50 | GlobalSection(SolutionProperties) = preSolution
51 | HideSolutionNode = FALSE
52 | EndGlobalSection
53 | EndGlobal
54 |
--------------------------------------------------------------------------------
/build/IncursionDebug.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | MultiThreadedDebug
10 | DEBUG;_DEBUG;%(PreprocessorDefinitions)
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/build/IncursionRelease.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | MultiThreaded
10 | NDEBUG;%(PreprocessorDefinitions)
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/build/exe_curses.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Debug
10 | x64
11 |
12 |
13 | Release
14 | Win32
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {E227072C-E53A-4616-B6D4-46BA536509BE}
23 | Win32Proj
24 | 10.0
25 |
26 |
27 |
28 | Application
29 | true
30 | v143
31 | MultiByte
32 |
33 |
34 | Application
35 | true
36 | v143
37 | MultiByte
38 |
39 |
40 | Application
41 | false
42 | v143
43 | Unicode
44 |
45 |
46 | Application
47 | false
48 | v143
49 | Unicode
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | true
77 | $(SolutionName)
78 | $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
79 | $(OutDir)
80 | PATH=%PATH%;$(SolutionDir)dependencies\$(Platform)\$(Configuration)
81 | INCURSIONFONTPATH=$(SolutionDir)..\fonts
82 | INCURSIONLIBPATH=$(SolutionDir)..\lib
83 | $(LocalDebuggerEnvironment)
84 | WindowsLocalDebugger
85 | $(SolutionDir)\..
86 |
87 |
88 |
89 |
90 | true
91 | $(SolutionName)
92 | $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
93 | PATH=%PATH%;$(SolutionDir)dependencies\$(Platform)\$(Configuration)
94 | INCURSIONFONTPATH=$(SolutionDir)..\fonts
95 | INCURSIONLIBPATH=$(SolutionDir)..\lib
96 | $(LocalDebuggerEnvironment)
97 | WindowsLocalDebugger
98 | $(SolutionDir)\..
99 |
100 |
101 |
102 | true
103 | $(SolutionName)
104 | $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
105 | $(OutDir)
106 | WindowsLocalDebugger
107 | PATH=%PATH%;$(SolutionDir)dependencies
108 | INCURSIONFONTPATH=$(SolutionDir)..\fonts
109 | INCURSIONLIBPATH=$(SolutionDir)..\lib
110 | $(LocalDebuggerEnvironment)
111 | $(SolutionDir)\..
112 |
113 |
114 |
115 |
116 | true
117 | $(SolutionName)
118 | $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
119 | WindowsLocalDebugger
120 | PATH=%PATH%;$(SolutionDir)dependencies\$(Platform)\$(Configuration)
121 | INCURSIONFONTPATH=$(SolutionDir)..\fonts
122 | INCURSIONLIBPATH=$(SolutionDir)..\lib
123 | $(LocalDebuggerEnvironment)
124 | $(SolutionDir)\..
125 |
126 |
127 |
128 |
129 | _UNICODE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
130 | MultiThreadedDebug
131 | Level3
132 | ProgramDatabase
133 | Disabled
134 | $(IntDir)$(SolutionName)C.pch
135 | $(IntDir)$(TargetName)C.pdb
136 |
137 |
138 | MachineX86
139 | true
140 | Console
141 | $(OutDir)$(TargetName)$(TargetExt)
142 | pdcurses.lib;%(AdditionalDependencies)
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 | _UNICODE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
152 | MultiThreadedDebug
153 | Level3
154 | ProgramDatabase
155 | Disabled
156 | $(IntDir)$(SolutionName)C.pch
157 | $(IntDir)$(TargetName)C.pdb
158 |
159 |
160 | true
161 | Console
162 | $(OutDir)$(TargetName)$(TargetExt)
163 | pdcurses.lib;%(AdditionalDependencies)
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 | _UNICODE;WIN32;NDEBUG;_CONSOLE;USE_BREAKPAD;%(PreprocessorDefinitions)
173 | MultiThreaded
174 | Level3
175 | ProgramDatabase
176 | $(IntDir)$(SolutionName)C.pch
177 | $(IntDir)$(TargetName)C.pdb
178 |
179 |
180 | MachineX86
181 | true
182 | Console
183 | true
184 | true
185 | $(OutDir)$(TargetName)$(TargetExt)
186 | pdcurses.lib;%(AdditionalDependencies)
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 | _UNICODE;WIN32;NDEBUG;_CONSOLE;USE_BREAKPAD;%(PreprocessorDefinitions)
196 | MultiThreaded
197 | Level3
198 | ProgramDatabase
199 | $(IntDir)$(SolutionName)C.pch
200 | $(IntDir)$(TargetName)C.pdb
201 |
202 |
203 | true
204 | Console
205 | true
206 | true
207 | $(OutDir)$(TargetName)$(TargetExt)
208 | pdcurses.lib;%(AdditionalDependencies)
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 | {9040faaa-3dbf-41e9-bf70-4facc525dc84}
218 | false
219 | true
220 | false
221 | true
222 | true
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
--------------------------------------------------------------------------------
/build/exe_curses.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/build/exe_libtcod.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/build/modaccent.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Debug
10 | x64
11 |
12 |
13 | Release
14 | Win32
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | {8CBF1412-2722-4FC4-9801-44943CC0BCB2}
47 | Win32Proj
48 | modaccent
49 | 10.0
50 |
51 |
52 |
53 | Application
54 | true
55 | Unicode
56 | v143
57 |
58 |
59 | Application
60 | true
61 | Unicode
62 | v143
63 |
64 |
65 | Application
66 | false
67 | true
68 | Unicode
69 | v143
70 |
71 |
72 | Application
73 | false
74 | true
75 | Unicode
76 | v143
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | true
96 | $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
97 | $(OutDir)
98 |
99 |
100 | true
101 | $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
102 | $(OutDir)
103 |
104 |
105 | false
106 | $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
107 | $(OutDir)
108 |
109 |
110 | false
111 | $(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\
112 | $(OutDir)
113 |
114 |
115 |
116 |
117 |
118 | Level3
119 | Disabled
120 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
121 | $(ProjectDir)..\modaccent\include;%(AdditionalIncludeDirectories)
122 |
123 |
124 | Console
125 | true
126 | legacy_stdio_definitions.lib;%(AdditionalDependencies)
127 |
128 |
129 |
130 |
131 |
132 |
133 | Level3
134 | Disabled
135 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
136 | $(ProjectDir)..\modaccent\include;%(AdditionalIncludeDirectories)
137 |
138 |
139 | Console
140 | true
141 |
142 |
143 |
144 |
145 | Level3
146 |
147 |
148 | MaxSpeed
149 | true
150 | true
151 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
152 | $(ProjectDir)..\modaccent\include;%(AdditionalIncludeDirectories)
153 |
154 |
155 | Console
156 | true
157 | true
158 | true
159 | legacy_stdio_definitions.lib;%(AdditionalDependencies)
160 |
161 |
162 |
163 |
164 | Level3
165 |
166 |
167 | MaxSpeed
168 | true
169 | true
170 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
171 | $(ProjectDir)..\modaccent\include;%(AdditionalIncludeDirectories)
172 |
173 |
174 | Console
175 | true
176 | true
177 | true
178 |
179 |
180 |
181 |
182 |
183 |
--------------------------------------------------------------------------------
/build/modaccent.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 |
26 |
27 | Source Files
28 |
29 |
30 | Source Files
31 |
32 |
33 | Source Files
34 |
35 |
36 | Source Files
37 |
38 |
39 | Source Files
40 |
41 |
42 | Source Files
43 |
44 |
45 | Source Files
46 |
47 |
48 | Source Files
49 |
50 |
51 | Source Files
52 |
53 |
54 | Source Files
55 |
56 |
57 | Source Files
58 |
59 |
60 | Source Files
61 |
62 |
63 | Source Files
64 |
65 |
66 | Source Files
67 |
68 |
69 | Source Files
70 |
71 |
72 | Source Files
73 |
74 |
75 | Source Files
76 |
77 |
78 | Source Files
79 |
80 |
81 |
--------------------------------------------------------------------------------
/build/x64.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | 5.02
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/dependencies/flex.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/dependencies/flex.exe
--------------------------------------------------------------------------------
/docs/Notes.txt:
--------------------------------------------------------------------------------
1 | 2014-11-09:
2 | https://bitbucket.org/rmtew/incursion-roguelike/issue/144/
3 | The 'x' cancel menu cannot find the springblade bracers to deactivate them, after they have been activated.
4 | Stati are put in place by the EV_BIRTH event in the script.
5 | EActor->GainPermStati(EFF_FLAG1,nhBlade1,SS_MISC, type, 0, $"Springblade Bracers");
6 | EActor->GainPermStati(EFF_FLAG2,nhBlade2,SS_MISC, type, 0, $"Springblade Bracers");
7 | However, they are not found when cancel looks for stati.
--------------------------------------------------------------------------------
/docs/incursionscript.md:
--------------------------------------------------------------------------------
1 | # IncursionScript
2 |
3 | ## Events
4 |
5 | ### Event Modifiers
6 |
7 | #### PRE
8 |
9 | Before an specified event 'broadcast-event' is processed, 'PRE(broadcast-event)' is first processed.
10 |
11 | Return values:
12 |
13 | * ABORT: Do not process 'broadcast-event'.
14 | * DONE: Do not process 'broadcast-event'.
15 | * Otherwise: Proceed to process 'broadcast-event'.
16 |
17 | #### POST
18 |
19 | If when 'broadcast-event' is processed ABORT is not the return value, 'POST(broadcast-event)' is next processed.
20 |
21 | No return values required from post-events.
22 |
23 | #### EVICTIM / ETARGET
24 |
25 | When a creature receives an event:
26 |
27 | * If the creature is the victim the event will be propagated to the monster handling as 'EVICTIM(event)'.
28 | * If the creature is the actor the event will be propagated to the monster handling as 'event'.
29 |
30 | If the return value is not DONE, ERROR or ABORT, then what was propagated will be further propagated to all template statis.
31 |
32 | #### EITEM
33 |
34 | When an item receives an event:
35 |
36 | # The script class for the item gets the event propagated as 'EITEM(event)'. But only if the script class for the event is not that of the item receiving the event. If DONE or ERROR are returned, the item is done handling the event.
37 | # The script class for the item gets the event propagated as is. If any result other than NOTHING is returned, the item is done handling the event.
38 | # Otherwise, the item falls back on standard hard-coded event handling.
39 |
40 | #### META
41 |
42 | For every event processed, a targeted further modified event 'META(event)' is sent to all involved objects. Except for the victim/target which is sent 'META(EVICTIM(event))'.
43 |
44 | #### GODWATCH
45 |
46 | For every event processed, a targeted further modified event 'GODWATCH(event)' is sent to each god. Next the process is repeated with 'GODWATCH(EVICTIM(event))' sent to each god.
47 |
48 | ### Event Types
49 |
50 | All event types can be hooked into in a variety of ways, by most scripts. However, some events are limited to certain script types.
51 |
52 | #### EV_ACTIVATE
53 | #### EV_ADAMAGE
54 | #### EV_ADVANCE
55 |
56 | Invoked in: Player.
57 | Handled in: Various script classes.
58 |
59 | Invoked when the player advances a level.
60 |
61 | #### EV_ALIGNED
62 |
63 | Invoked in: Character.
64 | Handled in: Various script classes.
65 |
66 | Invoked when a character peforms an action representative of a given alignment.
67 |
68 | #### EV_ANGER_PULSE
69 |
70 | Invoked in: Creature.
71 | Handled in: Various god script classes.
72 |
73 | Invoked during a creature's turn, as an indication of an angry god.
74 |
75 | #### EV_APPLY
76 | #### EV_ASCEND
77 |
78 | Handled in: Creature.
79 |
80 | Called to go up a level, climb onto the ceiling or climb a tree.
81 |
82 | * DONE: Success.
83 | * ABORT: Failure.
84 |
85 | #### EV_ATTACKMSG
86 | #### EV_ATTK
87 | #### EV_BARTER
88 | #### EV_BIRTH
89 | #### EV_BLESSING
90 | #### EV_BLOCK
91 |
92 | Not implemented.
93 |
94 | #### EV_BREAK
95 | #### EV_BRIDGE
96 | #### EV_BURN
97 | #### EV_CALC_EFFECT
98 | #### EV_CALC_FAVOUR
99 | #### EV_CALC_VALUES
100 | #### EV_CAST
101 | #### EV_CHANGE_ALIGN
102 | #### EV_CLEAN
103 | #### EV_CLOSE
104 |
105 | Handled in: Door.
106 |
107 | At this time, it is only called to attempt to close a door.
108 |
109 | * DONE: Success.
110 | * ABORT: Failure.
111 |
112 | #### EV_COMPULSION
113 |
114 | Handled in: Script hook possibility.
115 |
116 | Invoked prioritised forced action for a charmed and compelled player or monster, currently does nothing.
117 |
118 | #### EV_CONDITION
119 |
120 | Not implemented.
121 |
122 | #### EV_CONVERT
123 |
124 | Handled in: Creature.
125 |
126 | Invoked when a praying user chooses to convert to follow whomever the given altar represents.
127 |
128 | * DONE: Success.
129 | * ABORT: Failure.
130 |
131 | #### EV_CONVERT_ALTAR
132 |
133 | Handled in: Creature.
134 |
135 | Invoked when a praying user chooses to consecrate the given altar to whomever they follow.
136 |
137 | * DONE: Success.
138 | * ABORT: Failure.
139 |
140 | #### EV_COW
141 |
142 | Handled in: Creature.
143 |
144 | Invoked when the user chooses to attempt to cow a creature, or a group of creatures.
145 |
146 | * DONE: Success.
147 | * ABORT: Failure.
148 |
149 | #### EV_CRIT
150 | #### EV_CRITERIA
151 |
152 | Handled in: Script hook possibility.
153 |
154 | If game logic wishes to determine if a script class is suitable for a given use, it invokes this event against that class. There are three possible return values:
155 |
156 | * SHOULD_CAST_IT: valid.
157 | * CAN_CAST_IT: valid.
158 | * CANNOT_CAST_IT: invalid.
159 |
160 | This event is used in the game engine for the selection of templates to apply to monsters, encounters to spawn, and also in user dialogs to narrow down a selection of script classes to choose from (e.g. when using the Oil of Transformation).
161 |
162 | #### EV_CUT
163 | #### EV_DAMAGE
164 | #### EV_DEATH
165 | #### EV_DESCEND
166 |
167 | Handled in: Creature.
168 |
169 | Called to go down a level, climb down from a tree, descend from levitation or climb down a chasm.
170 |
171 | * DONE: Success.
172 | * ABORT: Failure.
173 |
174 | #### EV_DIG
175 | #### EV_DIP
176 | #### EV_DISARM
177 | #### EV_DISGUISE
178 | #### EV_DISMISS
179 | #### EV_DISMOUNT
180 | #### EV_DISPELLED
181 | #### EV_DISSECT
182 | #### EV_DISTRACT
183 | #### EV_DIVIDE
184 | #### EV_DODGE
185 | #### EV_DRINK
186 | #### EV_DROP
187 | #### EV_EAT
188 | #### EV_EFFECT
189 | #### EV_ELAPSED
190 | #### EV_ENBUILD_MON
191 | #### EV_ENCHOOSE_MID
192 | #### EV_ENCHOOSE_TEMP
193 | #### EV_ENGEN
194 | #### EV_ENGEN_ALIGN
195 | #### EV_ENGEN_MOUNT
196 | #### EV_ENGEN_PART
197 | #### EV_ENLIST
198 | #### EV_ENSELECT_TEMPS
199 | #### EV_ENTER
200 | #### EV_ENTERSTORE
201 | #### EV_EXAMINE
202 | #### EV_FAST_TALK
203 | #### EV_FIELDOFF
204 | #### EV_FIELDON
205 | #### EV_FORCE
206 | #### EV_FUMBLE
207 | #### EV_GAIN_STATI
208 | #### EV_GENITEM
209 | #### EV_GEN_DUNGEON
210 | #### EV_GEN_LEVEL
211 | #### EV_GEN_PANEL
212 | #### EV_GEN_ROOM
213 | #### EV_GETNAME
214 | #### EV_GIVE
215 | #### EV_GIVE_AID
216 | #### EV_GODPULSE
217 |
218 | Invoked in: Creature.
219 | Handled in: Various god script classes.
220 |
221 | Invoked during a creature's turn, as an indication of an angry god.
222 |
223 | #### EV_GOD_RAISE
224 |
225 | Invoked in: Player.
226 | Handled in: Various god script classes.
227 |
228 | Invoked when a player dies, first against their god if they have one. Otherwise if the result is NOTHING, then against all remaining gods while the result continues to be NOTHING.
229 |
230 | #### EV_GREET
231 | #### EV_HIDE
232 | #### EV_HIT
233 | #### EV_IBLESSING
234 | #### EV_IMBUE
235 | #### EV_INFECT
236 | #### EV_INITIALIZE
237 | #### EV_INIT_COMP
238 | #### EV_INIT_FIELDS
239 | #### EV_INIT_STATI
240 | #### EV_INSCRIBE
241 | #### EV_INSERT
242 | #### EV_INSIGHT
243 | #### EV_INVOKE
244 | #### EV_ISDETECT
245 | #### EV_ISTARGET
246 |
247 | Handled in: Script hook possibility.
248 |
249 | If game logic wishes to determine if a script class can be applied to a given object, it invokes this event against that class. There are three possible return values:
250 |
251 | * SHOULD_CAST_IT: Autobuff and monster AI will do so.
252 | * CAN_CAST_IT: Player can, monsters won't.
253 | * CANNOT_CAST_IT: Invalid target.
254 |
255 | It isn't just used for spell classes, but also encounter generation and validating character creation choices.
256 |
257 | #### EV_ITERRAIN
258 | #### EV_JAM
259 | #### EV_JEALOUSY
260 | #### EV_JUMP
261 | #### EV_JUMP_OFF
262 | #### EV_LAND
263 | #### EV_LEAVE
264 | #### EV_LOADXBOW
265 | #### EV_LOSEITEM
266 | #### EV_MACRO
267 | #### EV_MAGIC_HIT
268 |
269 | Handled in: Creature, Item.
270 |
271 | Called by EV_MAGIC_STRIKE if the target is not immune to the strike, and fails to resist it. Or if the thing is EF_PARTIAL, provided by non-magic or a magic blast (?).
272 |
273 | * ABORT: Stop the hit from being applied.
274 | * NOTHING / DONE: Allow the hit to proceed.
275 |
276 | #### EV_MAGIC_STRIKE
277 | #### EV_MAGIC_XY
278 | #### EV_MINE
279 | #### EV_MISS
280 | #### EV_MISSILE
281 | #### EV_MIX
282 | #### EV_MON_CONSIDER
283 | #### EV_MOUNT
284 | #### EV_MOVE
285 | #### EV_NATTACK
286 | #### EV_OATTACK
287 | #### EV_OPEN
288 |
289 | Handled in: Door.
290 |
291 | At this time, it is only called to attempt to open a door.
292 |
293 | * DONE: Success.
294 | * ABORT: Failure.
295 |
296 | #### EV_ORDER
297 | #### EV_PARRY
298 | #### EV_PDAMAGE
299 | #### EV_PHASE
300 | #### EV_PICKLOCK
301 | #### EV_PICKUP
302 | #### EV_PICK_POCKET
303 | #### EV_PLACE
304 | #### EV_PLAY
305 | #### EV_POISON
306 | #### EV_POUR
307 | #### EV_PRAY
308 | #### EV_PREREQ
309 | #### EV_PRESS
310 | #### EV_PRINT_NAME
311 | #### EV_PULL
312 | #### EV_PUSH
313 | #### EV_PUTON
314 | #### EV_QUELL
315 | #### EV_RATETARG
316 |
317 | Handled in: Script hook possibility.
318 |
319 | Applies to: Q_INV
320 |
321 | Used to filter which inventory items are shown in a menu for the user to select from.
322 |
323 | * SHOULD_CAST_IT: Autobuff and monster AI will do so.
324 | * CAN_CAST_IT: Player can, monsters won't.
325 | * CANNOT_CAST_IT: Invalid target.
326 |
327 | #### EV_RATE_SAC
328 | #### EV_RATTACK
329 | #### EV_READ
330 | #### EV_REMOVE
331 | #### EV_REMOVED
332 | #### EV_REQUEST
333 | #### EV_RESEARCH
334 | #### EV_REST
335 | #### EV_RESTING
336 | #### EV_RETRIBUTION
337 | #### EV_RUB
338 | #### EV_SACRIFICE
339 | #### EV_SATTACK
340 | #### EV_SEARCH
341 | #### EV_SHIFT
342 | #### EV_SHOW
343 | #### EV_SIT
344 | #### EV_SMELL
345 |
346 | Invoked in: Y use menu.
347 | Handled in: Script hook possibility.
348 |
349 | #### EV_SPECIAL
350 |
351 | Invoked in: Creature.
352 | Handled in: Terrain Script.
353 |
354 | Invoked as terrain effect for a given creature, if the relevant terrain at the creature's location handles this event.
355 |
356 | * Each turn.
357 | * When the creature moves, or is moved, to that location.
358 | * Terrain type for the given location changes to a new type.
359 |
360 | #### EV_STARTING_ITEM
361 |
362 | Invoked in: Player.
363 | Handled in: God, Race, and Class Scripts.
364 |
365 | Notify various scripts about each starting item the player has.
366 |
367 | #### EV_STRIKE
368 |
369 | Invoked in: Various.
370 | Handled in: Creature, Feature, Item.
371 |
372 | Invoked to strike an object.
373 |
374 | * ABORT: ...
375 | * Otherwise: ...
376 |
377 | #### EV_SUNRISE
378 |
379 | Not implemented.
380 |
381 | #### EV_SUNSET
382 |
383 | Not implemented.
384 |
385 | #### EV_SURRENDER
386 |
387 | Invoked in: Player talk 'surrender' option.
388 | Handled in: Creature.
389 |
390 | Invoked when a player wishes to surrender to another creature.
391 |
392 | #### EV_TAKEOFF
393 |
394 | Invoked in: Monster
395 | Handled in: Script hook possibility.
396 |
397 | Invoked to give the chance that a worn object can be removed.
398 |
399 | #### EV_TAKEOUT
400 | #### EV_TALK
401 | #### EV_TASTE
402 | #### EV_TAUNT
403 | #### EV_TDAMAGE
404 | #### EV_TERMS
405 |
406 | Invoked in: Player talk 'offer terms' option.
407 | Handled in: Creature.
408 |
409 | Invoked when a player is offering terms to another creature.
410 |
411 | #### EV_TIE_TO
412 |
413 | Invoked in: Y use menu.
414 | Handled in: Script hook possiblity.
415 |
416 | #### EV_TIE_UP
417 |
418 | Invoked in: Y use menu.
419 | Handled in: Script hook possiblity.
420 |
421 | #### EV_TOUCH
422 |
423 | Invoked in: Y use menu.
424 | Handled in: Script hook possiblity.
425 |
426 | #### EV_TURN
427 |
428 | Invoked in: Creature.
429 | Handled in: Creature, Various scripts.
430 |
431 | Allow an object to play out a game turn.
432 |
433 | #### EV_TURNING
434 |
435 | Handled in: Creature.
436 |
437 | Used to attempt to turn another creature (e.g. undead).
438 |
439 | #### EV_TWIST
440 |
441 | Invoked in: Y use menu.
442 | Handled in: Script hook possiblity.
443 |
444 | #### EV_UNLOCK
445 |
446 | Not implemented.
447 |
448 | #### EV_VICTORY
449 |
450 | Invoked in: Feature script.
451 | Handled in: Player.
452 |
453 | Invoked to declare the player has won the game.
454 |
455 | #### EV_WALKON
456 |
457 | Handled in: Feature Script.
458 |
459 | Invoked to verify whether a creature can walk on a map tile which holds a given feature. For instance, a closed door cannot be walked on and will fail. An open door however, can successfully be walked on.
460 |
461 | * ABORT: Disallow.
462 | * Otherwise: Allow.
463 |
464 | #### EV_WATTACK
465 |
466 | Handled in: Creature.
467 | Invoked in: Various places.
468 |
469 | Invoke character attack sequence.
470 |
471 | #### EV_WAVE
472 |
473 | Invoked in: Y use menu.
474 | Handled in: Script hook possiblity.
475 |
476 | #### EV_WEAR
477 |
478 | Not implemented.
479 |
480 | #### EV_WIELD
481 |
482 | Handled in: Creature.
483 | Invoked in: Various places.
484 |
485 | Invoked to make the creature wield an item in a given slot.
486 |
487 | #### EV_WILLBUY
488 |
489 | Handled in: NPC Script.
490 |
491 | Invoked on a barter attempt from the player.
492 |
493 | * DONE: Success. Object is sold.
494 | * NOMSG: Abort but do not show a message.
495 | * Otherwise: Abort but show a default message.
496 |
497 | #### EV_ZAP
498 |
499 | Handled in: Item.
500 |
501 | Invoked for use of wands and staffs.
502 |
--------------------------------------------------------------------------------
/docs/modules.md:
--------------------------------------------------------------------------------
1 | # User defined modules
2 |
3 | TODO: RComp.cpp: Game::ResourceCompiler()
4 | if (FIND("mage") && FIND("shocker lizard") && !Errors) {
5 |
6 | ## Which modules are loaded
7 |
8 | There are a number of ways to start playing from the main menu, and they
9 | depend on modules in different ways.
10 |
11 | If the player chooses to create a new character or to reincarnate an existing
12 | character, any modules located on disk are loaded.
13 |
14 | If the player chooses to load a saved game, the set of modules which were on
15 | disk at the time the game's character was created, or reincarnated, are
16 | expected to be present and will be the ones loaded. If any are not present
17 | the user will be shown an error dialog.
18 |
19 | ## Creating a Module
20 |
21 | A module is defined using a file with the suffix `.irc`. At this time only
22 | the top level of the `mod` subdirectory is searched for these files.
23 |
24 | ### Keyword: Module
25 |
26 | Required: If not provided, compilation of the given module will fail.
27 |
28 | This is a required definition. It specifies the module name, as presented to
29 | the player.
30 |
31 | Module "";
32 | e.g. Module "Bong Bong's Magical Tower"
33 |
34 | ### Keyword: File
35 |
36 | Required: If not provided, compilation of the given module will fail.
37 |
38 | This is a required definition. It specifies the module file name, and it
39 | specifies the file name which the compiled module will be written out as.
40 |
41 | File "";
42 | e.g. File "BongBongsMagicalTower.Mod";
43 |
44 | ### Keyword: Slot
45 |
46 | Optional: If not provided, the module will automatically be placed in the
47 | first unoccupied slot.
48 |
49 | Slot ;
50 | e.g. Slot 4;
51 |
52 | The slot a given module appears in depends mainly on module loading
53 | order. It is possible for a module to explicitly specify a slot number
54 | by defining a `Slot` entry, but module loading will error if this causes
55 | a conflict, discarding the second of the two to be encountered.
56 |
--------------------------------------------------------------------------------
/docs/reference.md:
--------------------------------------------------------------------------------
1 | Julian's Licensing Announcement
2 | -------------------------------
3 |
4 | Hi, folks, this is Julian Mensch writing though the website is now being maintained by Richard Tew. I wanted to make one final official statement about Incursion. It's been brought to my attention that the Creative Commons licenses are not very suitable for software, so I'm offering all the code that I originally offered under other licenses as well.
5 |
6 | * All of the Incursion source released by Julian Mensch to date is hereby dual-licensed under the BSD 3-Clause License, and the Apache 2.0 License and the Expat License.
7 | The code also remains licensed under the CC license, as it has been released as such and thus is impossible to revoke. However, future developers are warned that this license may be legally ambiguous for software.
8 | * I disavow all legal rights associated with the small supply of customized ASCII characters used by the game (the elf, dwarf, halfling, etc.) icons and release them under the same licenses as above to whatever extent I'm legally able to do so. The original glyphs are a screencap of a Microsoft font, however, so my ability to license them is dubious. I would recommend that developers that want to cross legal T's and dot legal I's make new, similar glyphs from an open-license console font.
9 | * Permission is granted to any developers to consolidate the copyright notices at the start of each file to include documentation of their own development work. I can be credited as "Copyright (c) 1999-2008 Julian Mensch".
10 | * Anyone that wants to verify that this relicensing is legitimate is welcome to e-mail me (jmensch@shaw.ca). I no longer use Google services under my real name due to privacy concerns and have deleted my old accounts, hence why there is no post on the discussion group (by me directly, at least) about this relicensing.
11 |
--------------------------------------------------------------------------------
/fonts/12x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/fonts/12x16.png
--------------------------------------------------------------------------------
/fonts/16x12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/fonts/16x12.png
--------------------------------------------------------------------------------
/fonts/16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/fonts/16x16.png
--------------------------------------------------------------------------------
/fonts/8x8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/fonts/8x8.png
--------------------------------------------------------------------------------
/inc/ArmourTab.h:
--------------------------------------------------------------------------------
1 | int8 ArmourTable[33][16] = {
2 | /* AR 0 */ { 0, 0, 0, 0, 0, 0, 0, 0,
3 | 0, 0, 0, 0, 0, 0, 0, 0 },
4 |
5 | /* AR 1 */ { 4, 3, 3, 3, 3, 3, 3, 3,
6 | 3, 3, 3, 3, 3, 3, 3, 3 },
7 |
8 | /* AR 2 */ { 9, 8, 6, 6, 6, 6, 6, 6,
9 | 6, 6, 6, 6, 6, 6, 6, 6 },
10 |
11 | /* AR 3 */ { 14, 13, 12, 9, 9, 9, 9, 9,
12 | 9, 9, 9, 9, 9, 9, 9, 9 },
13 |
14 | /* AR 4 */ { 20, 18, 17, 16, 12, 12, 12, 12,
15 | 12, 12, 12, 12, 12, 12, 12, 12 },
16 |
17 | /* AR 5 */ { 26, 23, 22, 21, 20, 15, 15, 15,
18 | 15, 15, 15, 15, 15, 15, 15, 15 },
19 |
20 | /* AR 6 */ { 32, 29, 27, 26, 25, 24, 18, 18,
21 | 18, 18, 18, 18, 18, 18, 18, 18 },
22 |
23 | /* AR 7 */ { 37, 34, 32, 31, 30, 29, 28, 21,
24 | 21, 21, 21, 21, 21, 21, 21, 21 },
25 |
26 | /* AR 8 */ { 43, 40, 38, 36, 35, 34, 33, 32,
27 | 24, 24, 24, 24, 24, 24, 24, 24 },
28 |
29 | /* AR 9 */ { 49, 46, 43, 41, 40, 39, 38, 37,
30 | 36, 27, 27, 27, 27, 27, 27, 27 },
31 |
32 | /* AR 10 */ { 55, 51, 49, 47, 45, 44, 43, 42,
33 | 41, 40, 30, 30, 30, 30, 30, 30 },
34 |
35 | /* AR 11 */ { 65, 61, 57, 54, 52, 50, 49, 48,
36 | 46, 45, 45, 31, 31, 31, 31, 31 },
37 |
38 | /* AR 12 */ { 67, 63, 59, 57, 54, 53, 51, 50,
39 | 48, 47, 46, 46, 32, 32, 32, 32 },
40 |
41 | /* AR 13 */ { 69, 65, 61, 59, 56, 55, 53, 52,
42 | 50, 49, 48, 48, 47, 33, 33, 33 },
43 |
44 | /* AR 14 */ { 71, 67, 63, 61, 59, 57, 55, 54,
45 | 52, 51, 50, 49, 49, 48, 34, 34 },
46 |
47 | /* AR 15 */ { 73, 69, 65, 63, 61, 59, 57, 56,
48 | 54, 53, 52, 51, 51, 50, 49, 35 },
49 |
50 | /* AR 16 */ { 74, 70, 67, 65, 62, 61, 59, 58,
51 | 56, 55, 54, 53, 52, 52, 51, 50 },
52 |
53 | /* AR 17 */ { 76, 72, 69, 67, 64, 63, 61, 59,
54 | 58, 57, 56, 55, 54, 53, 53, 52 },
55 |
56 | /* AR 18 */ { 78, 74, 71, 68, 66, 64, 63, 61,
57 | 60, 59, 58, 57, 56, 55, 55, 54 },
58 |
59 | /* AR 19 */ { 79, 76, 73, 70, 68, 66, 65, 63,
60 | 62, 61, 60, 59, 58, 57, 56, 56 },
61 |
62 | /* AR 20 */ { 81, 78, 75, 72, 70, 68, 66, 65,
63 | 64, 63, 61, 60, 60, 59, 58, 57 },
64 |
65 | /* AR 21 */ { 83, 79, 76, 74, 72, 70, 68, 67,
66 | 66, 64, 63, 62, 61, 61, 60, 59 },
67 |
68 | /* AR 22 */ { 84, 81, 78, 76, 74, 72, 70, 69,
69 | 67, 66, 65, 64, 63, 62, 61, 61 },
70 |
71 | /* AR 23 */ { 86, 83, 80, 78, 75, 74, 72, 70,
72 | 69, 68, 67, 66, 65, 64, 63, 62 },
73 |
74 | /* AR 24 */ { 87, 84, 82, 79, 77, 75, 74, 72,
75 | 71, 70, 69, 68, 67, 66, 65, 64 },
76 |
77 | /* AR 25 */ { 89, 86, 83, 81, 79, 77, 75, 74,
78 | 73, 71, 70, 69, 68, 67, 67, 66 },
79 |
80 | /* AR 26 */ { 91, 88, 85, 83, 81, 79, 77, 76,
81 | 74, 73, 72, 71, 70, 69, 68, 68 },
82 |
83 | /* AR 27 */ { 92, 89, 87, 84, 82, 81, 79, 77,
84 | 76, 75, 74, 73, 72, 71, 70, 69 },
85 |
86 | /* AR 28 */ { 94, 91, 88, 86, 84, 82, 81, 79,
87 | 78, 77, 75, 74, 73, 73, 72, 71 },
88 |
89 | /* AR 29 */ { 95, 93, 90, 88, 86, 84, 82, 81,
90 | 80, 78, 77, 76, 75, 74, 73, 73 },
91 |
92 | /* AR 30 */ { 97, 94, 92, 89, 88, 86, 84, 83,
93 | 81, 80, 79, 78, 77, 76, 75, 74 },
94 |
95 | /* AR 31 */ { 98, 96, 93, 91, 89, 87, 86, 84,
96 | 83, 82, 81, 79, 78, 78, 77, 76 },
97 |
98 | /* AR 32 */ { 100, 97, 95, 93, 91, 89, 87, 86,
99 | 85, 83, 82, 81, 80, 79, 78, 78 },
100 |
101 | };
102 |
103 |
104 | int8 AbsorbTable[17][16] = {
105 | /* AR 0 */ { 0, 0, 0, 0, 0, 0, 0, 0,
106 | 0, 0, 0, 0, 0, 0, 0, 0 },
107 |
108 | /* AR 1 */ { 2, 0, 0, 0, 0, 0, 0, 0,
109 | 0, 0, 0, 0, 0, 0, 0, 0 },
110 |
111 | /* AR 2 */ { 7, 3, 0, 0, 0, 0, 0, 0,
112 | 0, 0, 0, 0, 0, 0, 0, 0 },
113 |
114 | /* AR 3 */ { 12, 8, 5, 2, 0, 0, 0, 0,
115 | 0, 0, 0, 0, 0, 0, 0, 0 },
116 |
117 | /* AR 4 */ { 17, 13, 10, 7, 3, 0, 0, 0,
118 | 0, 0, 0, 0, 0, 0, 0, 0 },
119 |
120 | /* AR 5 */ { 22, 18, 15, 12, 8, 5, 2, 0,
121 | 0, 0, 0, 0, 0, 0, 0, 0 },
122 |
123 | /* AR 6 */ { 27, 23, 20, 17, 13, 10, 7, 3,
124 | 0, 0, 0, 0, 0, 0, 0, 0 },
125 |
126 | /* AR 7 */ { 32, 28, 25, 22, 18, 15, 12, 8,
127 | 5, 2, 0, 0, 0, 0, 0, 0 },
128 |
129 | /* AR 8 */ { 37, 33, 30, 27, 23, 20, 17, 13,
130 | 10, 7, 3, 0, 0, 0, 0, 0 },
131 |
132 | /* AR 9 */ { 42, 38, 35, 32, 28, 25, 22, 18,
133 | 15, 12, 8, 5, 2, 0, 0, 0 },
134 |
135 | /* AR 10 */ { 47, 43, 40, 37, 33, 30, 27, 23,
136 | 20, 17, 13, 10, 7, 3, 0, 0 },
137 |
138 | /* AR 11 */ { 52, 48, 45, 42, 38, 35, 32, 28,
139 | 25, 22, 18, 15, 12, 8, 5, 2 },
140 |
141 | /* AR 12 */ { 57, 53, 50, 47, 43, 40, 37, 33,
142 | 30, 27, 23, 20, 17, 13, 10, 7 },
143 |
144 | /* AR 13 */ { 62, 58, 55, 52, 48, 45, 42, 38,
145 | 35, 32, 28, 25, 22, 18, 15, 12 },
146 |
147 | /* AR 14 */ { 67, 63, 60, 57, 53, 50, 47, 43,
148 | 40, 37, 33, 30, 27, 23, 20, 17 },
149 |
150 | /* AR 15 */ { 72, 68, 65, 62, 58, 55, 52, 48,
151 | 45, 42, 38, 35, 32, 28, 25, 22 },
152 |
153 | /* AR 16 */ { 77, 73, 70, 67, 63, 60, 57, 53,
154 | 50, 47, 43, 40, 37, 33, 30, 27 },
155 |
156 | };
157 |
--------------------------------------------------------------------------------
/inc/Feature.h:
--------------------------------------------------------------------------------
1 | /* See the Incursion LICENSE file for copyright information.
2 |
3 | This file contains class definitions for Feature,
4 | Door, Portal and Trap.
5 | */
6 |
7 |
8 | /* Features are dungeon features too large for the player
9 | to pick up. They include Door, Trap, Trigger, Stair,
10 | Throne, Mirror, Sink, Fountain, Pit, Rubble and so on. */
11 | class Feature: public Thing
12 | {
13 | ARCHIVE_CLASS(Feature,Thing,r)
14 | END_ARCHIVE
15 | public:
16 | int16 cHP, mHP;
17 | rID fID;
18 | int8 MoveMod;
19 | Feature(int16 Image,rID _fID, int16 _Type) : Thing(Image, _Type)
20 | {
21 | fID = _fID;
22 | Timeout = -1;
23 | Flags = TFEAT(_fID)->Flags;
24 | MoveMod = TFEAT(_fID)->MoveMod;
25 | cHP = mHP = TFEAT(_fID)->hp;
26 | }
27 | Feature(rID _fID) : Thing( TFEAT(_fID)->Image, T_FEATURE)
28 | {
29 | fID = _fID;
30 | Timeout = -1;
31 | Flags = TFEAT(_fID)->Flags;
32 | MoveMod = TFEAT(_fID)->MoveMod;
33 | cHP = mHP = TFEAT(_fID)->hp;
34 | }
35 | virtual String & Name(int16 Flags=0);
36 | virtual String & Describe(Player *p);
37 | virtual void StatiOn(Status s);
38 | virtual void StatiOff(Status s);
39 | EvReturn Event(EventInfo &e);
40 | virtual int8 Material() {
41 | return TFEAT(fID)->Material;
42 | }
43 | };
44 |
45 | class Door: public Feature
46 | {
47 | ARCHIVE_CLASS(Door,Feature,r)
48 | END_ARCHIVE
49 |
50 | public:
51 | Door(rID fID);
52 | ~Door();
53 | EvReturn Event(EventInfo &e);
54 | void SetImage();
55 | int8 DoorFlags;
56 | virtual bool isDead() {
57 | return (Flags & F_DELETE) || (DoorFlags & DF_BROKEN);
58 | }
59 | Glyph SecretSavedGlyph;
60 | virtual String & Describe(Player *p);
61 | EvReturn Zapped(EventInfo &e);
62 | };
63 |
64 | class Trap: public Feature
65 | {
66 | ARCHIVE_CLASS(Trap,Feature,r)
67 | END_ARCHIVE
68 | public:
69 | uint8 TrapFlags; rID tID;
70 | Trap(rID _fID,rID _tID) :
71 | Feature(TFEAT(_fID)->Image,_fID,T_TRAP)
72 | { TrapFlags = 0;
73 | tID = _tID; SetImage(); }
74 | EvReturn Event(EventInfo &e);
75 | virtual String & Name(int16 Flags=0);
76 | ~Trap();
77 | void SetImage();
78 | int16 TrapLevel()
79 | { return TEFF(tID)->Level; }
80 | EvReturn TriggerTrap(EventInfo &e, bool foundBefore);
81 | };
82 |
83 |
84 | /* A Portal is anything that can transport the player to a different
85 | map;, other then scrolls of level teleport, teletraps, pits, etc.
86 | They can also be special-function map spots that can be entered,
87 | like stores or guilds. Portals include:
88 | * literal magic portals
89 | * stairs
90 | * dungeon entrances
91 | * sub-dungeon entrances
92 | * stores
93 | * guilds
94 | * entrance to a building (i.e., the tavern)
95 | * the 'Rope Trick' rope
96 | * the 'Mordenkainen's Mansion' door
97 | */
98 | class Portal: public Feature
99 | {
100 | ARCHIVE_CLASS(Portal,Feature,r)
101 | END_ARCHIVE
102 | public:
103 | Portal(rID pID);
104 | bool isDownStairs()
105 | { return TFEAT(fID)->xval == POR_DOWN_STAIR; }
106 | EvReturn Event(EventInfo &e);
107 | EvReturn Enter(EventInfo &e);
108 | bool EnterDir(Dir d);
109 | };
110 |
111 |
--------------------------------------------------------------------------------
/inc/Globals.h:
--------------------------------------------------------------------------------
1 | /* See the Incursion LICENSE file for copyright information.
2 |
3 | This file contains declarations for all of the global
4 | variables and functions used in Incursion.
5 | */
6 |
7 | class String;
8 |
9 | void Fatal(const char*,...);
10 | void Error(const char*,...);
11 |
12 | void init_genrand(uint32_t s);
13 | uint32_t genrand_int32(void);
14 |
15 | int16 strcatf(char*,const char*,...);
16 | inline int16 random(int16 mx);
17 | inline const int16 dist(uint16 x1, uint16 y1, uint16 x2, uint16 y2);
18 | inline Dir DirTo(int16 sx, int16 sy, int16 tx, int16 ty);
19 | uint16 ResAlign(rID xID);
20 | bool AlignConflict(uint16 al1, uint16 al2, bool strict=false);
21 | bool godAllowsAlign(rID gID, uint16 align);
22 | bool isLegalPersonTo(Creature *Actor, Creature *Victim);
23 | int16 getChivalryBreach(EventInfo &e);
24 | rID getAnimalName();
25 | const char* GodPronoun(rID gID, bool poss);
26 | bool effectGivesStati(rID eID);
27 | Item* OneSomeAll(Item *it, Creature *cr, bool assume_some=false);
28 | int16 getGodRelation(rID fromID, rID toID, bool * doWrath);
29 | bool isExploreMode(Player *p);
30 | extern const char* OptChoice(const char *text, int16 num);
31 | void PurgeStrings();
32 |
33 | void EncAddMon(rID mID, rID tID=0, rID tID2=0, rID tID3=0);
34 |
35 | EvReturn Throw(int16 Ev, Object *p1=NULL, Object *p2=NULL,
36 | Object*p3=NULL, Object *p4=NULL);
37 | EvReturn ThrowVal(int16 Ev,int16 n, Object *p1=NULL, Object *p2
38 | =NULL, Object*p3=NULL, Object *p4=NULL);
39 | EvReturn ThrowXY(int16 Ev,int16 x,int16 y, Object *p1=NULL,
40 | Object *p2=NULL, Object*p3=NULL, Object *p4=NULL);
41 |
42 | EvReturn ThrowDir(int16 Ev,Dir d,Object *p1=NULL,
43 | Object *p2=NULL, Object*p3=NULL, Object *p4=NULL);
44 | EvReturn ThrowField(int16 Ev,Field *f,Object *p1=NULL,
45 | Object *p2=NULL, Object*p3=NULL, Object *p4=NULL);
46 | EvReturn ThrowEff(int16 Ev,rID eID,Object *p1=NULL, Object *p2
47 | =NULL, Object*p3=NULL, Object *p4=NULL);
48 | EvReturn ThrowEffDir(int16 Ev,rID eID,Dir d, Object *p1=NULL, Object *p2
49 | =NULL, Object*p3=NULL, Object *p4=NULL);
50 | EvReturn ThrowEffXY(int16 Ev,rID eID,int16 x,int16 y, Object *p1=NULL,
51 | Object *p2=NULL, Object*p3=NULL, Object *p4=NULL);
52 | EvReturn ThrowLoc(int16 Ev,int16 x,int16 y,Object *p1=NULL, Object *p2
53 | =NULL, Object*p3=NULL, Object *p4=NULL);
54 | EvReturn ThrowDmg(int16 Ev,int16 DType,int16 DmgVal, const char*s,
55 | Object *p1=NULL, Object *p2=NULL,Object*p3=NULL,
56 | Object *p4=NULL);
57 | EvReturn ThrowTerraDmg(int16 Ev,int16 DType,int16 DmgVal, const char*s,
58 | Object *victim, rID terID);
59 | EvReturn ThrowDmgEff(int16 Ev,int16 DType,int16 DmgVal, const char*s,
60 | rID eID, Object *p1=NULL, Object *p2=NULL,Object*p3=NULL,
61 | Object *p4=NULL);
62 | EvReturn RedirectEff(EventInfo &e, rID eID, int16 Ev=EV_EFFECT);
63 |
64 | EvReturn ReThrow(int16 ev, EventInfo &e);
65 | void SetEvent(EventInfo &e, int16 Ev, Object *p1, Object *p2=NULL,
66 | Object*p3=NULL,Object *p4=NULL);
67 | extern EventInfo EventStack[EVENT_STACK_SIZE];
68 | extern int16 EventSP;
69 |
70 | int StringCompare(const void *a, const void *b);
71 | String & DescribeSkill(int16 sk);
72 |
73 | const char* __XPrint(Player *POV, const char *msg,va_list args);
74 | const char* XPrint(const char*msg,...);
75 | const char* PPrint(Player *POV, const char*msg, ...);
76 | /* Display a message to all players who xperceive the event. */
77 | void APrint(EventInfo &e, const char *msg1, ...);
78 | /* Display one message to the acting player, and another to any players who xperceive the actor. */
79 | void DPrint(EventInfo &e, const char *msg1,const char *msg2,...);
80 | /* Display one message to the victim player, and another to any players who xperceive the victim. */
81 | void VPrint(EventInfo &e, const char *msg1, const char *msg2, ...);
82 | /* Display one message to the acting player, another to the victim, and yet another to any players who xperceive the actor/victim. */
83 | void TPrint(EventInfo &e, const char *msg1, const char *msg2, const char *msg3,...);
84 | void BDPrint(EventInfo &e, const char *msg1,...);
85 | void BTPrint(EventInfo &e,const char *msg1,const char *msg2,...);
86 | /* Display a message to all players (other than the actor) within the given range, who are able to hear. */
87 | void Hear(EventInfo &e, int16 range, const char *msg1,...);
88 | /* Display a message to all players for whom the source location or actor is visible or perceived respectively. */
89 | void SinglePrintXY(EventInfo &e, const char*msg,...);
90 |
91 | int8 MonHDType(int8 MType);
92 | int8 MonGoodSaves(int8 MType);
93 | int16 ResourceLevel(rID xID);
94 | bool ResourceHasFlag(rID xID, int16 fl);
95 | int16 MaxItemPlus(int16 MaxLev,rID eID);
96 | Creature * InitShopkeeper(rID mID, int32 gold);
97 | bool PossiblyPause(Term *T1, int x, int y, int timeout);
98 | extern String & ItemNameFromEffect(rID eID);
99 | extern String & DescribeSkill(int16 sk);
100 | extern String & DescribeFeat(int16 ft);
101 |
102 | bool isSimilarDir(Dir d, Dir d2);
103 |
104 | extern int16 Silence;
105 | extern int16 __spentHours;
106 |
107 | extern int16 LastSkillCheckResult;
108 |
109 | extern Game* theGame;
110 | extern Registry* theRegistry;
111 | extern Registry MainRegistry, ResourceRegistry;
112 |
113 | extern rID Candidates[2048];
114 | extern int16 nCandidates;
115 |
116 | extern int16 FavEnemies[], MonGroupRarities[];
117 | extern uint8 BlastColourSets[];
118 |
119 |
120 | extern int16 s_racial, s_enhance, s_feat, s_domain, s_item, s_train, s_syn,
121 | s_armour, s_comp, s_circ, s_inh, s_size, s_kit, s_focus, s_ins;
122 | extern int16 Studies[9][4];
123 | extern int32 EncumValues[4];
124 |
125 | extern "C" int Preprocess(const char*,const char*);
126 | extern int8 DirX[],DirY[];
127 | extern int8 ManaMultiplier[],
128 | GoodSave[],
129 | PoorSave[],
130 | ChargeBonusTable[10][30],
131 | ArmourTable[33][16],
132 | AbsorbTable[17][16];
133 |
134 | extern const char *KeyBindings,
135 | *GlyphLegend1,
136 | *GlyphLegend2,
137 | *AttrTitle[],
138 | *RatingWord[],
139 | *SlotNames[],
140 | *NumberNames[],
141 | *RomanNumerals[],
142 | // *TileNames[],
143 | *EncumbranceNames[];
144 |
145 | extern TextVal DTypeNames[],
146 | ATypeNames[],
147 | AbilityNames[],
148 | ClassAbilities[],
149 | RarityNames[],
150 | //FeatNames[],
151 | WeaponGroupNames[],
152 | MTypeNames[],
153 | ITypeNames[],
154 | SourceNames[],
155 | AnnotationNames[],
156 | AttkVerbs1[],
157 | AttkVerbs2[],
158 | BreathTypes[],
159 | StatiLineStats[],
160 | StatiLineShorts[],
161 | BoltNames[],
162 | BeamNames[],
163 | CloudNames[],
164 | BallNames[],
165 | BreathNames[],
166 | SchoolNames[],
167 | StudyNames[],
168 | SizeNames[],
169 | ActionVerbs[],
170 | DataTypeNames[],
171 | BonusNames[],
172 | BonusNicks[],
173 | // FeatNames[],
174 | // FeatDescs[],
175 | SaveBonusNames[],
176 | PreQualNames[],
177 | PostQualNames[],
178 | QualityDescs[],
179 | MaterialDescs[],
180 | GenericPreQualNames[],
181 | APreQualNames[],
182 | APostQualNames[],
183 | GenericQualityDescs[],
184 | AQualityDescs[],
185 | MMDTypeNames[],
186 | MMAttkVerbs[],
187 | MMAttkVerbs2[],
188 | SpellPurposeNames[],
189 | PerDescs[],
190 | FileErrors[];
191 |
192 | extern TextVal MA_CONSTNAMES[],
193 | M_CONSTNAMES[],
194 | AD_CONSTNAMES[],
195 | A_CONSTNAMES[],
196 | T_CONSTNAMES[],
197 | SS_CONSTNAMES[],
198 | ATTR_CONSTNAMES[],
199 | STATI_CONSTNAMES[],
200 | EV_CONSTNAMES[],
201 | OPCODE_CONSTNAMES[],
202 | TA_CONSTNAMES[],
203 | DT_CONSTNAMES[],
204 | WQ_CONSTNAMES[],
205 | AQ_CONSTNAMES[],
206 | IQ_CONSTNAMES[],
207 | WS_CONSTNAMES[],
208 | SK_CONSTNAMES[],
209 | SN_CONSTNAMES[],
210 | HI_CONSTNAMES[],
211 | IL_CONSTNAMES[],
212 | PHASE_CONSTNAMES[],
213 | BARD_CONSTNAMES[],
214 | INV_CONSTNAMES[],
215 | CH_CONSTNAMES[],
216 | CA_CONSTNAMES[],
217 | SP_CONSTNAMES[],
218 | AI_CONSTNAMES[],
219 | MS_CONSTNAMES[],
220 | IF_CONSTNAMES[],
221 | GLYPH_CONSTNAMES[];
222 |
223 | extern Dice MonkDamage[];
224 |
225 | extern struct PerkAbil okStartingAbils[];
226 | extern int16 badStartingFeats[];
227 |
228 |
229 | extern struct SkillInfoStruct SkillInfo[];
230 | extern int8 Synergies[][3];
231 | extern struct AlignmentInfoStruct AlignmentInfo[];
232 | extern struct AbilityInfoStruct AbilInfo[];
233 | extern struct FeatInfoStruct FeatInfo[];
234 | extern const char * FeatName(int16 ft);
235 | extern bool FeatUnimplemented(int16 ft);
236 |
237 | extern const char *Arrows;
238 | extern const char *MenuLetters;
239 | extern const int16 MonsterGlyphs[],
240 | ItemGlyphs[],
241 | CreationGlyphs[],
242 | WildShapeGlyphs[];
243 | extern const char *PersonalityNames[],
244 | *PersonalityDescs[];
245 | extern int32 ExperienceChart[];
246 | extern int8 SpellTable[27][9],
247 | BonusSpells[22][9];
248 | extern int16 EncumbranceTable[];
249 | extern int16 RogueFeats[],
250 | MonkFeats[],
251 | RangerEnemies[];
252 | extern int16 QualityMods[][2],
253 | AQualityMods[][2];
254 |
255 | extern int8 FaceRadius[];
256 | extern int8 NeededSwings[];
257 |
258 | extern int8 SpecialistTable[9][9];
259 | extern int16 __SAL[];
260 | extern int32 WealthByLevel[];
261 |
262 | extern uint16 ActiveTraits[];
263 | extern struct Option OptionList[];
264 | extern struct YuseCommand YuseCommands[];
265 |
266 | extern struct ReincarnationInfo RInf;
267 |
268 | extern int16 p_base, p_int, p_spec, p_lev, p_conc,
269 | p_meta, p_spec, p_calc, p_circ;
270 | extern const char* ps_perfect, *ps_calc;
271 |
272 | extern int16 dc_base, dc_hard, dc_focus, dc_trick, dc_will,
273 | dc_beguile, dc_lev, dc_attr, dc_height, dc_affinity;
274 | extern const char* dcs_attr;
275 |
276 | extern rID GodIDList[];
277 | extern int16 nGods;
278 |
279 | extern Term *T1;
280 |
281 | extern "C" int yyerror(const char*);
282 |
--------------------------------------------------------------------------------
/inc/Incursion.h:
--------------------------------------------------------------------------------
1 | /* See the Incursion LICENSE file for copyright information.
2 |
3 | This is the central C++ header file for Incursion, which
4 | includes in itself all the other second-tier header files.
5 | */
6 |
7 | #define SYSTEMNAME "Win32"
8 | #define VISION
9 | #define BYTECODE_TRACER
10 |
11 | /* A member of the template class is not defined.
12 | http://msdn.microsoft.com/en-us/library/1k7k17za.aspx
13 | */
14 | #pragma warning (disable : 4661)
15 | /* posix names differ for c++ iso */
16 | #pragma warning (disable : 4996)
17 |
18 | //#define DEBUG_MEMORY_CORRUPTION
19 | //#ifdef DEBUG_MEMORY_CORRUPTION
20 | //#define INTENSIVE_MEMORY_DEBUG
21 | //#endif
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | #ifdef DEBUG_MEMORY_CORRUPTION
35 |
36 | void * _malloc(size_t sz);
37 | void * _realloc(void *vp, size_t sz);
38 | void _free(void *vp);
39 | char* _incursion_strdup(const char *str);
40 | long array_index(long x,long y);
41 |
42 |
43 | #define malloc _malloc
44 | #define free _free
45 | #define strdup _incursion_strdup
46 | #define realloc _realloc
47 | #define calloc(a,b) _malloc((a)*(b))
48 | #define I(x,y) array_index(x,y)
49 |
50 | #else
51 |
52 | #define I(x,y) x
53 |
54 | #endif
55 |
56 | #ifndef WIN32
57 | #undef stricmp
58 | #define stricmp strcasecmp
59 | #endif
60 |
61 |
62 | #include "Defines.h"
63 | #include "Globals.h"
64 | #include "Base.h"
65 | #include "Target.h"
66 | #include "RComp.h"
67 | #include "Events.h"
68 | #include "Magic.h"
69 | #include "Res.h"
70 | #include "Map.h"
71 | #include "Creature.h"
72 | #include "Item.h"
73 | #include "Feature.h"
74 | #include "Term.h"
75 | #include "Inline.h"
76 |
77 |
--------------------------------------------------------------------------------
/inc/Magic.h:
--------------------------------------------------------------------------------
1 | /* See the Incursion LICENSE file for copyright information.
2 |
3 | This file contains the class definition for Magic.
4 | */
5 |
6 |
7 | class Magic
8 | {
9 | public:
10 | // The Area-Effect Functions
11 | // ww: folded into one, now ...
12 | /*
13 | EvReturn ABolt(EventInfo &e);
14 | EvReturn ABall(EventInfo &e);
15 | EvReturn ABeam(EventInfo &e);
16 | */
17 | EvReturn ABallBeamBolt(EventInfo &e);
18 |
19 | // used by the monster AI ...
20 | void PredictVictimsOfBallBeamBolt(EventInfo &e,
21 | bool isBeam, bool isBall, bool isChain, Creature * victim[], int16 & numVic);
22 |
23 |
24 | EvReturn ATouch(EventInfo &e);
25 | EvReturn AGlobe(EventInfo &e);
26 | EvReturn AField(EventInfo &e);
27 | EvReturn ABarrier(EventInfo &e);
28 |
29 | bool isTarget(EventInfo &e, Thing *t);
30 | void CalcEffect(EventInfo &e);
31 | EvReturn MagicEvent(EventInfo &e);
32 | EvReturn MagicStrike(EventInfo &e);
33 | EvReturn MagicHit(EventInfo &e);
34 | EvReturn MagicXY(EventInfo &e,int16 x,int16 y);
35 |
36 | // The Effect Archetypes
37 | EvReturn Blast(EventInfo &e);
38 | EvReturn Inflict(EventInfo &e);
39 | EvReturn Grant(EventInfo &e);
40 | EvReturn Drain(EventInfo &e);
41 | EvReturn Terraform(EventInfo &e);
42 | EvReturn Travel(EventInfo &e);
43 | EvReturn Identify(EventInfo &e);
44 | EvReturn Illusion(EventInfo &e);
45 | EvReturn Summon(EventInfo &e);
46 | EvReturn Animate(EventInfo &e);
47 | EvReturn Creation(EventInfo &e);
48 | EvReturn Bless(EventInfo &e);
49 | EvReturn Charm(EventInfo &e);
50 | EvReturn Poison(EventInfo &e);
51 | EvReturn TimeStop(EventInfo &e);
52 | EvReturn Slaying(EventInfo &e);
53 | EvReturn Telepathy(EventInfo &e);
54 | EvReturn Detect(EventInfo &e);
55 | EvReturn Reveal(EventInfo &e);
56 | EvReturn Override(EventInfo &e);
57 |
58 | EvReturn Vision(EventInfo &e);
59 | EvReturn Dispel(EventInfo &e);
60 | EvReturn EConstruct(EventInfo &e);
61 | EvReturn Banish(EventInfo &e);
62 | EvReturn Castigate(EventInfo &e);
63 | EvReturn Healing(EventInfo &e);
64 | EvReturn Raise(EventInfo &e);
65 | EvReturn Menu(EventInfo &e);
66 | EvReturn Cancel(EventInfo &e);
67 | EvReturn Wonder(EventInfo &e);
68 | EvReturn ManyThings(EventInfo &e);
69 | EvReturn Polymorph(EventInfo &e);
70 | EvReturn Genocide(EventInfo &e);
71 | EvReturn LevGain(EventInfo &e);
72 | EvReturn Holding(EventInfo &e);
73 | EvReturn Warning(EventInfo &e);
74 | EvReturn Digging(EventInfo &e);
75 | EvReturn Earthquake(EventInfo &e);
76 | EvReturn Cure(EventInfo &e);
77 | EvReturn Restore(EventInfo &e);
78 | EvReturn Shield(EventInfo &e);
79 |
80 | //General Effects
81 | };
82 | extern int16 ZapX[];
83 | extern int16 ZapY[];
84 | extern Map* ZapMap;
85 | extern uint16 ZapImage[];
86 |
87 |
--------------------------------------------------------------------------------
/inc/RComp.h:
--------------------------------------------------------------------------------
1 | /* See the Incursion LICENSE file for copyright information.
2 |
3 | This file contains class definitions and constants
4 | related solely to the IncursionScript compiler.
5 | */
6 |
7 |
8 | #define HASH_SIZE 4096
9 | #define SYMBOL_SEG 120000
10 |
11 | enum btype { SYS_OBJ, LOC_VAR, MOD_FUNC, GLOB_VAR, MEM_VAR, MEM_FUNC,
12 | RES_VAR, SYS_FUNC, RES_MEM, RES_FUNC, ANY };
13 |
14 | #define DT_VOID 1
15 | #define DT_INT32 2
16 | #define DT_HOBJ 3
17 | #define DT_HTEXT 4
18 | #define DT_RID 5
19 | #define DT_STRING 6
20 | #define DT_BOOL 7
21 | #define DT_RECT 8
22 | #define DT_INT16 9
23 | #define DT_INT8 10
24 | #define DT_UINT8 11
25 | #define DT_UINT16 12
26 | #define DT_UNKNOWN 12
27 |
28 |
29 | #define RT_CONSTANT 0
30 | #define RT_REGISTER 1
31 | #define RT_MEMORY 2
32 | #define RT_REGMEM 3
33 | #define RT_EXTENDED 4
34 | #define RT_STACK 8
35 | #define RT_MEMBER 16
36 |
37 | #define sys_error 1
38 | #define sys_fatal 2
39 | #define sys_addstring 3
40 | #define sys_str_left 4
41 | #define sys_str_right 5
42 | #define sys_copy_str 6
43 | #define sys_set_str 7
44 | #define sys_fmt_str 8
45 | #define sys_alloc_str 9
46 | #define sys_free_str 10
47 | #define sys_empty_str 11
48 | #define sys_first_thing 12
49 | #define sys_next_thing 13
50 | #define sys_first_creat 14
51 | #define sys_next_creat 15
52 | #define sys_first_item 16
53 | #define sys_next_item 17
54 | #define sys_thing_n 18
55 |
56 | extern uint32 CompilerFlags,
57 | MemFuncID,
58 | MemVarID,
59 | HeapHead,
60 | StackHead;
61 |
62 |
63 | struct VCode
64 | {
65 | unsigned int Opcode:6;
66 | signed int Param1:10;
67 | unsigned int P1Type:3;
68 | signed int Param2:10;
69 | unsigned int P2Type:3;
70 | };
71 |
72 |
73 | struct Binding
74 | {
75 | Binding() { next = NULL; xID = 0; Event = 0; }
76 | btype type;
77 | rID xID;
78 | int16 Event;
79 | Binding *next;
80 | ~Binding()
81 | { if (next) delete next; }
82 | };
83 |
84 | class SymbolTable
85 | {
86 | private:
87 | inline int32 hashval(const char*text);
88 | struct SymbolNode
89 | {
90 | const char*text;
91 | int32 id;
92 | Binding *b;
93 | SymbolNode *left, *right, *next;
94 | ~SymbolNode()
95 | { if (next) delete next;
96 | if (b) delete b;
97 | if (text) free((void*)text); }
98 | };
99 | SymbolNode *HashTable[HASH_SIZE];
100 | SymbolNode * RefTable[HASH_SIZE];
101 | int32 LastID;
102 | public:
103 | SymbolTable();
104 | int32 GetLastID() { return LastID; }
105 | int32 operator[](const char*text);
106 | const char* operator[](int32 id);
107 | int32 Add(const char *text);
108 | void Bind(int32 id, Binding *b);
109 | void Empty();
110 | Binding *GetBinding(const char *text, rID xID=0, int16 Ev=0, btype type = ANY);
111 | Binding *GetBinding(int32 id, rID xID=0, int16 Ev=0, btype type = ANY);
112 | };
113 |
114 | struct BSysFunc : public Binding
115 | {
116 | BSysFunc(int16 _funcid, int8 _ret)
117 | { funcid = _funcid;
118 | ReturnType = _ret;
119 | ParamCount = 0;
120 | type = SYS_FUNC;
121 | isVarParam = 0;
122 | HasDefault = 0;
123 | xID = 0;
124 | Event = 0; }
125 | int16 funcid, ParamCount;
126 | int8 ReturnType;
127 | int8 ParamType[10];
128 | int8 ParamOType[10];
129 | int8 Default[10];
130 | int16 HasDefault;
131 | bool isVarParam;
132 | };
133 |
134 | struct BMemFunc : public BSysFunc
135 | {
136 | BMemFunc(int16 _funcid, int8 _ret, int8 _OType)
137 | : BSysFunc(_funcid, _ret)
138 | { OType = _OType;
139 | type = MEM_FUNC; }
140 | int8 OType;
141 | };
142 |
143 | struct BResFunc : public BSysFunc
144 | {
145 | BResFunc(int16 _funcid, int8 _ret, int8 _RType)
146 | : BSysFunc(_funcid, _ret)
147 | { RType = _RType;
148 | type = RES_FUNC; }
149 | int8 RType;
150 | };
151 |
152 |
153 | struct BMemVar : public Binding
154 | {
155 | int16 varid;
156 | int8 VarType;
157 | int8 OType;
158 | };
159 |
160 | struct BResMem : public Binding
161 | {
162 | int16 varid;
163 | int8 VarType;
164 | int8 RType;
165 | };
166 |
167 | struct BLocalVar : public Binding
168 | {
169 | int16 StackOffset;
170 | int8 VarType;
171 | };
172 |
173 | struct BResVar : public Binding
174 | {
175 | int32 Address;
176 | int8 VarType;
177 | };
178 |
179 | struct BGlobalVar : public Binding
180 | {
181 | int32 Address;
182 | int8 VarType;
183 | };
184 |
185 | struct BSysObj : public Binding
186 | {
187 | int16 ObjNum;
188 | int8 OType;
189 | };
190 |
191 | class VBlock
192 | {
193 | private:
194 | int32 size, space;
195 | VCode *vc;
196 | public:
197 | VBlock()
198 | {
199 | size = 0; space = 5;
200 | vc = (VCode*)malloc(sizeof(VCode)*space);
201 | ASSERT(vc);
202 | }
203 | ~VBlock()
204 | {
205 | //free(vc);
206 | }
207 | void Clear()
208 | {
209 | free(vc);
210 | size = 0; space = 5;
211 | vc = (VCode*)malloc(sizeof(VCode)*space);
212 | ASSERT(vc);
213 | }
214 |
215 | VCode *GetCode() { return vc; }
216 | int32 GetSize() { return size; }
217 | int16 LastOpcode() { if (!size) return 0;
218 | return vc[size-1].Opcode; }
219 | void Generate(int8 opcode, int8 typ1=0, int32 param1=0, int8 typ2=0,int32 param2=0);
220 | void GenDWord(int32 dw)
221 | { ASSERT(sizeof(int32) <= sizeof(VCode));
222 | Generate(0);
223 | size--;
224 | *((int32*)(&(vc[size++]))) = dw; }
225 | hCode Add(VBlock *b)
226 | {
227 | if (!b)
228 | return size;
229 | ASSERT(vc);
230 | if (size + b->size >= space)
231 | {
232 | space += b->size;
233 | /* This is causing crashes, and I have no idea why!
234 | vc = (VCode*)realloc(vc,sizeof(VCode)*space); */
235 | VCode * temp_vc;
236 | temp_vc = (VCode*)malloc(sizeof(VCode)*space);
237 | memcpy(temp_vc,vc,size * sizeof(VCode));
238 | free(vc);
239 | vc = temp_vc;
240 | }
241 | memcpy(&(vc[size]),b->vc,b->size * sizeof(VCode));
242 | size += b->size;
243 | return (size - b->size);
244 | }
245 | void TrimGratuitousMOV() {
246 | if (!size)
247 | return;
248 | if (vc[size-1].Opcode == MOV)
249 | if (vc[size-1].P1Type == RT_REGISTER)
250 | size--;
251 | return;
252 | }
253 | void ProcessContinues();
254 |
255 | };
256 |
257 | struct PExp
258 | {
259 | PExp() { Type = Storage = 0; Value = 0; Code = NULL; }
260 | VBlock* Code;
261 | int8 Type, Storage;
262 | int32 Value;
263 | };
264 |
265 | struct LExp
266 | {
267 | void PExp() {
268 | Type = Storage = 0;
269 | Value = 0;
270 | RCode = WCode = NULL;
271 | }
272 | VBlock *RCode, *WCode;
273 | int8 Type, Storage;
274 | int32 Value;
275 | };
276 |
277 | extern VBlock theCodeSeg;
278 |
279 | PExp& CodeOperator(int16 op, PExp &ex1,PExp &ex2);
280 | PExp& CodeAssignment(int16 op, LExp &lv,PExp *val);
281 | PExp& CodeRectMember(PExp *rect, int16 id);
282 | LExp& CodeRectLVal(LExp *rect,int16 id);
283 |
284 | void FreeRegister(int16 reg);
285 | int16 AllocRegister();
286 | void FreeString(int16 s);
287 | void LockString(int16 s);
288 | void ClearStrings();
289 | bool isStringLocked(int16 s);
290 | int16 AllocString();
291 | bool AllowedCast(int16 from, int16 to);
292 |
293 |
294 |
295 |
--------------------------------------------------------------------------------
/inc/Target.h:
--------------------------------------------------------------------------------
1 | /*
2 | * See the Incursion LICENSE file for copyright information.
3 | *
4 | * ww: Revised Incursion Targeting System ...
5 | * Since Targeting is so important (e.g., we might want to attach special
6 | * debug information to targeting information) and since we scan though all
7 | * of our targets commonly, we have pulled Targets out of the Stati array.
8 | */
9 |
10 | /* ww: Key Concept: "certifying"
11 | * We should always know why A thinks B is a target. In essence, we should
12 | * carry around a "proof".
13 | *
14 | * Eventually, this "proof" can be used to give information to players when
15 | * they use SK_SENSE_MOTIVE (or somesuch).
16 | */
17 |
18 | /* ww: this would be a class, but disjoint unions are too annoying to do
19 | * correctly in C++, and it would be a pain to unserialize later ...
20 | * actually, everything here used to be a class, but I gave up ... */
21 | typedef enum {
22 | HostilityDefault,
23 | HostilityFeud, // MA_ELF, MA_DROW
24 | HostilityMindless, // M_MINDLESS
25 | HostilityPeaceful, // MS_PEACEFUL
26 | HostilityGood, // MA_GOOD on MA_GOOD
27 | HostilityOutsider, // LE outsider on CG outsider, etc.
28 | HostilityDragon, // chromatic vs. metallic dragons
29 | HostilitySmite, // Good Smites Evil!
30 | HostilityLeader,
31 | HostilityMount,
32 | HostilityDefendLeader,
33 | HostilityYourLeaderHatesMe,
34 | HostilityYourLeaderIsOK,
35 | HostilityParty,
36 | HostilityFlag, // M_HOSTILE
37 | HostilitySolidarity, // elves get along with elves, undead with undead
38 | HostilityEID, // cloak of vermin friendship, aggravate monsters
39 | HostilityTarget, // specific feelings about this one thing
40 | HostilityFood, // carnivores eat adventurers ...
41 | HostilityEvil, // evil creatures attack weaker things
42 | HostilityAlienation, // animals in a dungeon, elementals on the prime
43 | HostilityCharmed,
44 | HostilityCommanded,
45 | } HostilityWhyType;
46 |
47 | typedef struct HostilityWhy {
48 | HostilityWhyType type;
49 | union {
50 | struct {
51 | uint8 ma;
52 | } solidarity;
53 | struct {
54 | uint8 m1, m2;
55 | } feud;
56 | struct {
57 | rID eid;
58 | } eid;
59 | } data;
60 | String & Dump();
61 | } HostilityWhy;
62 |
63 | typedef enum {
64 | Neutral, // I will ignore you unless you hurt me
65 | Enemy, // I will attack you now
66 | Ally // I will cast healing spells on you, etc.
67 | } HostilityQual;
68 |
69 | typedef enum {
70 | Apathy = 0, // "I don't care": only for Neutral above
71 | Minimal = 1,
72 | Tiny = 2, // evil things go after weaker things
73 | Weak = 10, // "feud" elves and dwarves
74 | Medium = 20, // "hatred" elves and drow, undead and living
75 | Strong = 30, // "loathing" aligned dragons, aligned outsiders
76 | } HostilityQuant;
77 |
78 | typedef struct Hostility {
79 | // ww: Hostility should only be between creatures.
80 | HostilityQual quality;
81 | HostilityQuant quantity;
82 | HostilityWhy why;
83 | String & Dump(const char * toWhat);
84 | } Hostility;
85 |
86 | typedef enum {
87 | TargetDefault,
88 | TargetGreedy,
89 | TargetHitMe,
90 | TargetSpelledMe,
91 | TargetWasSeenAndHostile,
92 | TargetIsAllyOfEnemy,
93 | TargetHeardNoise,
94 | TargetWanderlust,
95 | TargetLiberated,
96 | TargetOrderedTo,
97 | TargetResents
98 | } TargetWhyType;
99 |
100 | typedef struct TargetWhy {
101 | TargetWhyType type;
102 | uint32 turnOfBirth;
103 | union {
104 | struct {
105 | rID spellID;
106 | } SpelledMe;
107 | struct {
108 | Hostility h;
109 | uint16 per;
110 | } WasSeenAndHostile;
111 | struct {
112 | Hostility hAlly;
113 | hObj ally;
114 | } IsAllyOfEnemy;
115 | } data;
116 | String & Dump(const char *toWhat);
117 | void Set(TargetWhyType _type);
118 | } TargetWhy;
119 |
120 | typedef enum {
121 | TargetInvalid, // should never been seen!
122 |
123 | TargetEnemy,
124 | TargetAlly,
125 |
126 | TargetLeader, // Normal leader: this troll leads these goblins
127 | TargetSummoner, // You cast Summon Monster II. Less likely to turn.
128 | TargetMaster, // Druid Animal (or somesuch) -- will never attack leader.
129 | TargetMount, // Mount Obeys its rider
130 |
131 | TargetArea,
132 | TargetWander,
133 |
134 | TargetItem,
135 |
136 | OrderStandStill,
137 | OrderDoNotAttack,
138 | OrderAttackNeutrals,
139 | OrderHide,
140 | OrderDoNotHide,
141 | OrderWalkInFront,
142 | OrderWalkInBack,
143 | OrderWalkNearMe,
144 | OrderWalkToPoint,
145 | OrderBeFriendly,
146 | OrderAttackTarget,
147 | OrderTakeWatches,
148 | OrderGiveMeItem,
149 | OrderReturnHome,
150 | OrderNoPickup,
151 |
152 | MemoryCantHitPhased,
153 | MemoryCantHitWImmune,
154 | MemoryElemResistKnown,
155 | MemoryMeleeDCKnown,
156 | MemoryRangedDCKnown,
157 |
158 | TargetAny = -1
159 | } TargetType;
160 |
161 | typedef struct Target {
162 | TargetType type;
163 | uint16 priority;
164 | uint16 vis; // visible now? (as of last ChooseAction)
165 | TargetWhy why;
166 | union {
167 | struct {
168 | hObj c;
169 | uint32 damageDoneToMe;
170 | } Creature;
171 | struct {
172 | uint8 x,y;
173 | } Area;
174 | struct {
175 | hObj i;
176 | } Item;
177 | } data;
178 | String & Dump();
179 | int16 DistanceFrom(const Thing *me);
180 | uint8 X();
181 | uint8 Y();
182 | Thing * GetThing();
183 | Thing * GetThingOrNULL();
184 | bool isValid();
185 | } Target;
186 |
187 | typedef struct TargetSystem {
188 | public:
189 |
190 | #define NUM_TARGETS 32
191 | Target t[NUM_TARGETS];
192 | uint8 tCount;
193 |
194 | // I would love to use your OArray, but I get a C++ link error I don't
195 | // understand:
196 | // OArray t;
197 |
198 | /* shouldRecalc is true if we should recalculate possible targets before
199 | * choosing our next action ... */
200 | bool shouldRetarget;
201 |
202 | /* RacialHostilty uses only MA_* things from the monster and the template
203 | * (and possibly also flags like M_EARTH) */
204 | Hostility RacialHostility(Creature *me, Creature *t);
205 |
206 | /* Specific Hostility also takes into account Stati and abilities and
207 | * other personal feelings (e.g., CHARMED, FRIEND, you hit me, partyID) */
208 | Hostility SpecificHostility(Creature *me, Creature *t);
209 |
210 | /* LowPriorityStatiHostility contains stati-related hostility checks that
211 | * come after SpecificHostility, but before RacialHostility in the standard
212 | * evaluation order. */
213 | Hostility LowPriorityStatiHostility(Creature * me, Creature * t);
214 |
215 | /* RateAsTarget is used when you are seeing something for the first
216 | * time and you're not sure if you like it or not. */
217 | void RateAsTarget(Creature *me, Thing *t, Target &newT);
218 |
219 | /* GetTarget is used to see if you have a specific memory about this
220 | * thing: maybe you would normally be peaceful to it, but you remember
221 | * that it hit you! */
222 | Target * GetTarget(Thing *thing);
223 |
224 | /* Mark the ith target as invalid. */
225 | void RemoveTargetNumber(uint16 i);
226 |
227 | bool isLeader(Creature *t);
228 | Creature * getLeader();
229 |
230 | bool hasTargetOfType(TargetType type);
231 | Target * getTargetOfType(TargetType type);
232 | bool hasTargetThing(Thing *t);
233 |
234 | /* gain a new target explicitly ... do not use these if you
235 | * can possibly help it! */
236 | bool addCreatureTarget(Creature *targ, TargetType type);
237 | bool giveOrder(Creature *me, Creature *master, TargetType order, Thing * victim=NULL, int x = -1, int y = -1);
238 | void removeCreatureTarget(Creature *targ, TargetType type);
239 | bool addTarget(Target &newT);
240 |
241 | /* 't' turned into something else out of sight, so we should forget
242 | * negative feelings we have for it */
243 | void MissedShapechange(Creature *me, Creature *t);
244 |
245 | /* drop all current TargetWanders, add a TargetWander to some random
246 | * location ... */
247 | void Wanderlust(Creature *me, Thing *t=NULL);
248 |
249 | /* something just made a big noise and we heard it ... note that we may
250 | * not be able to see the noise-maker, and there might not even be one
251 | * (ventriloquism) */
252 | void HearNoise(Creature *me, uint8 x, uint8 y);
253 |
254 | /* 't' just struck us! 't' may be an ally, at which point we should
255 | * shrug it off ...*/
256 | void ItHitMe(Creature *me, Creature *t, int16 damage);
257 |
258 | /* We're a summoned creature and have just been liberated from our
259 | * summoner's control via the Liberation domain granted power. */
260 | void Liberate(Creature *me, Creature *lib);
261 |
262 | /* I needed to make this for Lesser Planar Binding... friendly creature
263 | * turns hostile for reasons other than ItHitMe. */
264 | void TurnHostileTo(Creature *me, Creature *hostile_to);
265 | void TurnNeutralTo(Creature *me, Creature *neutral_to);
266 |
267 |
268 | /* should not normally be called -- debugging only, etc. */
269 | void Clear();
270 |
271 | /* (Animal Empathy) 't' Pacified us! */
272 | void Pacify(Creature *me, Creature *t);
273 |
274 | /* 't' has just appeared on the map (AlertNew) or for some reason we want
275 | * to think about it again ... we might not be able to see it, and it
276 | * might be an item, creature, etc. */
277 | void Consider(Creature *me, Thing *t);
278 |
279 | /* Look at all of the things nearby and rebuild our target array. */
280 | void Retarget(Creature *me, bool force = false);
281 |
282 | void ForgetOrders(Creature *me, int ofType = -1);
283 |
284 | String & Dump();
285 | void Serialize(Registry &r);
286 | } TargetSystem;
287 |
288 |
--------------------------------------------------------------------------------
/inc/cpp.h:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * I n t e r n a l D e f i n i t i o n s f o r C P P
4 | *
5 | * In general, definitions in this file should not be changed.
6 | */
7 |
8 | #ifndef TRUE
9 | #define TRUE 1
10 | #define FALSE 0
11 | #endif
12 | #ifndef EOS
13 | /*
14 | * This is predefined in Decus C
15 | */
16 | #define EOS '\0' /* End of string */
17 | #endif
18 | #define EOF_CHAR 0 /* Returned by get() on eof */
19 | #define NULLST ((char *) NULL) /* Pointer to nowhere (linted) */
20 | #define DEF_NOARGS (-1) /* #define foo vs #define foo() */
21 |
22 | /*
23 | * The following may need to change if the host system doesn't use ASCII.
24 | */
25 | #define DEF_MAGIC 0x1D /* Magic for #defines */
26 | #define TOK_SEP 0x1E /* Token concatenation delim. */
27 | #define COM_SEP 0x1F /* Magic comment separator */
28 |
29 | /*
30 | * Note -- in Ascii, the following will map macro formals onto DEL + the
31 | * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
32 | * be ok as long as PAR_MAC is less than 33). Note that the last PAR_MAC
33 | * value is reserved for string substitution.
34 | */
35 |
36 | #define MAC_PARM 0x7F /* Macro formals start here */
37 | #if PAR_MAC >= 33
38 | assertion fails -- PAR_MAC isn't less than 33
39 | #endif
40 | #define LASTPARM (PAR_MAC - 1)
41 |
42 | /*
43 | * Character type codes.
44 | */
45 |
46 | #define INV 0 /* Invalid, must be zero */
47 | #define OP_EOE INV /* End of expression */
48 | #define DIG 1 /* Digit */
49 | #define LET 2 /* Identifier start */
50 | #define FIRST_BINOP OP_ADD
51 | #define OP_ADD 3
52 | #define OP_SUB 4
53 | #define OP_MUL 5
54 | #define OP_DIV 6
55 | #define OP_MOD 7
56 | #define OP_ASL 8
57 | #define OP_ASR 9
58 | #define OP_AND 10 /* &, not && */
59 | #define OP_OR 11 /* |, not || */
60 | #define OP_XOR 12
61 | #define OP_EQ 13
62 | #define OP_NE 14
63 | #define OP_LT 15
64 | #define OP_LE 16
65 | #define OP_GE 17
66 | #define OP_GT 18
67 | #define OP_ANA 19 /* && */
68 | #define OP_ORO 20 /* || */
69 | #define OP_QUE 21 /* ? */
70 | #define OP_COL 22 /* : */
71 | #define OP_CMA 23 /* , (relevant?) */
72 | #define LAST_BINOP OP_CMA /* Last binary operand */
73 | /*
74 | * The following are unary.
75 | */
76 | #define FIRST_UNOP OP_PLU /* First Unary operand */
77 | #define OP_PLU 24 /* + (draft ANSI standard) */
78 | #define OP_NEG 25 /* - */
79 | #define OP_COM 26 /* ~ */
80 | #define OP_NOT 27 /* ! */
81 | #define LAST_UNOP OP_NOT
82 | #define OP_LPA 28 /* ( */
83 | #define OP_RPA 29 /* ) */
84 | #define OP_END 30 /* End of expression marker */
85 | #define OP_MAX (OP_END + 1) /* Number of operators */
86 | #define OP_FAIL (OP_END + 1) /* For error returns */
87 |
88 | /*
89 | * The following are for lexical scanning only.
90 | */
91 |
92 | #define QUO 65 /* Both flavors of quotation */
93 | #define DOT 66 /* . might start a number */
94 | #define SPA 67 /* Space and tab */
95 | #define BSH 68 /* Just a backslash */
96 | #define END 69 /* EOF */
97 |
98 | /*
99 | * These bits are set in ifstack[]
100 | */
101 | #define WAS_COMPILING 1 /* TRUE if compile set at entry */
102 | #define ELSE_SEEN 2 /* TRUE when #else processed */
103 | #define TRUE_SEEN 4 /* TRUE when #if TRUE processed */
104 |
105 | /*
106 | * Define bits for the basic types and their adjectives
107 | */
108 |
109 | #define T_CHAR 1
110 | #define T_INT 2
111 | #define T_FLOAT 4
112 | #define T_DOUBLE 8
113 | #define T_SHORT 16
114 | #define T_LONG 32
115 | #define T_SIGNED 64
116 | #define T_UNSIGNED 128
117 | #define T_PTR 256 /* Pointer */
118 | #define T_FPTR 512 /* Pointer to functions */
119 |
120 | /*
121 | * The DEFBUF structure stores information about #defined
122 | * macros. Note that the defbuf->repl information is always
123 | * in malloc storage.
124 | */
125 |
126 | typedef struct defbuf {
127 | struct defbuf *link; /* Next define in chain */
128 | char *repl; /* -> replacement */
129 | int hash; /* Symbol table hash */
130 | int nargs; /* For define(args) */
131 | char name[1]; /* #define name */
132 | } DEFBUF;
133 |
134 | /*
135 | * The FILEINFO structure stores information about open files
136 | * and macros being expanded.
137 | */
138 |
139 | typedef struct fileinfo {
140 | char *bptr; /* Buffer pointer */
141 | int line; /* for include or macro */
142 | FILE *fp; /* File if non-null */
143 | struct fileinfo *parent; /* Link to includer */
144 | char *filename; /* File/macro name */
145 | char *progname; /* From #line statement */
146 | unsigned int unrecur; /* For macro recursion */
147 | char buffer[1]; /* current input line */
148 | } FILEINFO;
149 |
150 | /*
151 | * The SIZES structure is used to store the values for #if sizeof
152 | */
153 |
154 | typedef struct sizes {
155 | short bits; /* If this bit is set, */
156 | short size; /* this is the datum size value */
157 | short psize; /* this is the pointer size */
158 | } SIZES;
159 | /*
160 | * nomacarg is a built-in #define on Decus C.
161 | */
162 |
163 | #ifdef nomacarg
164 | #define cput output /* cput concatenates tokens */
165 | #else
166 | #if COMMENT_INVISIBLE
167 | #define cput(c) { if (c != TOK_SEP && c != COM_SEP) fputc(c,fout); }
168 | #else
169 | #define cput(c) { if (c != TOK_SEP) fputc(c,fout); }
170 | #endif
171 | #endif
172 |
173 | #ifndef nomacarg
174 | #define streq(s1, s2) (strcmp(s1, s2) == 0)
175 | #endif
176 |
177 | /*
178 | * Error codes. VMS uses system definitions.
179 | * Decus C codes are defined in stdio.h.
180 | * Others are cooked to order.
181 | */
182 |
183 | #if HOST == SYS_VMS
184 | #include
185 | #include
186 | #define IO_NORMAL (SS$_NORMAL | STS$M_INHIB_MSG)
187 | #define IO_ERROR SS$_ABORT
188 | #endif
189 | /*
190 | * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
191 | */
192 | #ifndef IO_NORMAL
193 | #define IO_NORMAL 0
194 | #endif
195 | #ifndef IO_ERROR
196 | #define IO_ERROR 1
197 | #endif
198 |
199 | /*
200 | * Externs
201 | */
202 |
203 | extern int c_line; /* Current line number */
204 | extern int wrongline; /* Force #line to cc pass 1 */
205 | extern char type[]; /* Character classifier */
206 | extern char token[IDMAX + 1]; /* Current input token */
207 | extern int instring; /* TRUE if scanning string */
208 | extern int inmacro; /* TRUE if scanning #define */
209 | extern int errors; /* Error counter */
210 | extern int recursion; /* Macro depth counter */
211 | extern char ifstack[BLK_NEST]; /* #if information */
212 | #define compiling ifstack[0]
213 | extern char *ifptr; /* -> current ifstack item */
214 | extern char *incdir[NINCLUDE]; /* -i directories */
215 | extern char **incend; /* -> active end of incdir */
216 | extern int cflag; /* -C option (keep comments) */
217 | extern int eflag; /* -E option (ignore errors) */
218 | extern int nflag; /* -N option (no pre-defines) */
219 | extern int rec_recover; /* unwind recursive macros */
220 | extern char *preset[]; /* Standard predefined symbols */
221 | extern char *magic[]; /* Magic predefined symbols */
222 | extern FILEINFO *infile; /* Current input file */
223 | extern char work[NWORK + 1]; /* #define scratch */
224 | extern char *workp; /* Free space in work */
225 | #if DEBUG
226 | extern int debug; /* Debug level */
227 | #endif
228 | extern int keepcomments; /* Don't remove comments if set */
229 | extern SIZES size_table[]; /* For #if sizeof sizes */
230 | extern char *getmem(); /* Get memory or die. */
231 | extern DEFBUF *lookid(); /* Look for a #define'd thing */
232 | extern DEFBUF *defendel(); /* Symbol table enter/delete */
233 | extern char *savestring(); /* Stuff string in malloc mem. */
234 | extern char *strcpy();
235 | extern char *strcat();
236 | extern char *strrchr();
237 | extern char *strchr();
238 | extern long time();
239 | extern FILE* fout;
240 | //extern char *sprintf(); /* Lint needs this */
241 |
--------------------------------------------------------------------------------
/inc/cppdef.h:
--------------------------------------------------------------------------------
1 | /*
2 | * S y s t e m D e p e n d e n t
3 | * D e f i n i t i o n s f o r C P P
4 | *
5 | * Definitions in this file may be edited to configure CPP for particular
6 | * host operating systems and target configurations.
7 | *
8 | * NOTE: cpp assumes it is compiled by a compiler that supports macros
9 | * with arguments. If this is not the case (as for Decus C), #define
10 | * nomacarg -- and provide function equivalents for all macros.
11 | *
12 | * cpp also assumes the host and target implement the Ascii character set.
13 | * If this is not the case, you will have to do some editing here and there.
14 | */
15 |
16 | /*
17 | * This redundant definition of TRUE and FALSE works around
18 | * a limitation of Decus C.
19 | */
20 | #ifndef TRUE
21 | #define TRUE 1
22 | #define FALSE 0
23 | #endif
24 |
25 | /*
26 | * Define the HOST operating system. This is needed so that
27 | * cpp can use appropriate filename conventions.
28 | */
29 | #define SYS_UNKNOWN 0
30 | #define SYS_UNIX 1
31 | #define SYS_VMS 2
32 | #define SYS_RSX 3
33 | #define SYS_RT11 4
34 | #define SYS_LATTICE 5
35 | #define SYS_ONYX 6
36 | #define SYS_68000 7
37 |
38 | #define HOST SYS_UNIX
39 |
40 | #ifndef HOST
41 | #ifdef unix
42 | #define HOST SYS_UNIX
43 | #else
44 | #ifdef vms
45 | #define HOST SYS_VMS
46 | #else
47 | #ifdef rsx
48 | #define HOST SYS_RSX
49 | #else
50 | #ifdef rt11
51 | #define HOST SYS_RT11
52 | #endif
53 | #endif
54 | #endif
55 | #endif
56 | #endif
57 |
58 | #ifndef HOST
59 | #define HOST SYS_UNKNOWN
60 | #endif
61 |
62 | /*
63 | * We assume that the target is the same as the host system
64 | */
65 | #ifndef TARGET
66 | #define TARGET HOST
67 | #endif
68 |
69 | /*
70 | * In order to predefine machine-dependent constants,
71 | * several strings are defined here:
72 | *
73 | * MACHINE defines the target cpu (by name)
74 | * SYSTEM defines the target operating system
75 | * COMPILER defines the target compiler
76 | *
77 | * The above may be #defined as "" if they are not wanted.
78 | * They should not be #defined as NULL.
79 | *
80 | * LINE_PREFIX defines the # output line prefix, if not "line"
81 | * This should be defined as "" if cpp is to replace
82 | * the "standard" C pre-processor.
83 | *
84 | * FILE_LOCAL marks functions which are referenced only in the
85 | * file they reside. Some C compilers allow these
86 | * to be marked "static" even though they are referenced
87 | * by "extern" statements elsewhere.
88 | *
89 | * OK_DOLLAR Should be set TRUE if $ is a valid alphabetic character
90 | * in identifiers (default), or zero if $ is invalid.
91 | * Default is TRUE.
92 | *
93 | * OK_CONCAT Should be set TRUE if # may be used to concatenate
94 | * tokens in macros (per the Ansi Draft Standard) or
95 | * FALSE for old-style # processing (needed if cpp is
96 | * to process assembler source code).
97 | *
98 | * OK_DATE Predefines the compilation date if set TRUE.
99 | * Not permitted by the Nov. 12, 1984 Draft Standard.
100 | *
101 | * S_CHAR etc. Define the sizeof the basic TARGET machine word types.
102 | * By default, sizes are set to the values for the HOST
103 | * computer. If this is inappropriate, see the code in
104 | * cpp3.c for details on what to change. Also, if you
105 | * have a machine where sizeof (signed int) differs from
106 | * sizeof (unsigned int), you will have to edit code and
107 | * tables in cpp3.c (and extend the -S option definition.)
108 | *
109 | * CPP_LIBRARY May be defined if you have a site-specific include directory
110 | * which is to be searched *before* the operating-system
111 | * specific directories.
112 | */
113 |
114 | #if TARGET == SYS_LATTICE
115 | /*
116 | * We assume the operating system is pcdos for the IBM-PC.
117 | * We also assume the small model (just like the PDP-11)
118 | */
119 | #define MACHINE "i8086"
120 | #define SYSTEM "pcdos"
121 | #endif
122 |
123 | #if TARGET == SYS_ONYX
124 | #define MACHINE "z8000"
125 | #define SYSTEM "unix"
126 | #endif
127 |
128 | #if TARGET == SYS_VMS
129 | #define MACHINE "vax"
130 | #define SYSTEM "vms"
131 | #define COMPILER "vax11c"
132 | #endif
133 |
134 | #if TARGET == SYS_RSX
135 | #define MACHINE "pdp11"
136 | #define SYSTEM "rsx"
137 | #define COMPILER "decus"
138 | #endif
139 |
140 | #if TARGET == SYS_RT11
141 | #define MACHINE "pdp11"
142 | #define SYSTEM "rt11"
143 | #define COMPILER "decus"
144 | #endif
145 |
146 | #if TARGET == SYS_68000 || defined(M68000) || defined(m68000) || defined(m68k)
147 | /*
148 | * All three machine designators have been seen in various systems.
149 | * Warning -- compilers differ as to sizeof (int). cpp3 assumes that
150 | * sizeof (int) == 2
151 | */
152 | #define MACHINE "M68000", "m68000", "m68k"
153 | #define SYSTEM "unix"
154 | #endif
155 |
156 | #if TARGET == SYS_UNIX
157 | #define SYSTEM "unix"
158 | #ifdef pdp11
159 | #define MACHINE "pdp11"
160 | #endif
161 | #ifdef vax
162 | #define MACHINE "vax"
163 | #endif
164 | #endif
165 |
166 | /*
167 | * defaults
168 | */
169 |
170 | #ifndef MSG_PREFIX
171 | #define MSG_PREFIX "cpp: "
172 | #endif
173 |
174 | #ifndef LINE_PREFIX
175 | #define LINE_PREFIX "line"
176 | #endif
177 |
178 | /*
179 | * OLD_PREPROCESSOR forces the definition of OK_DOLLAR, OK_CONCAT,
180 | * COMMENT_INVISIBLE, and STRING_FORMAL to values appropriate for
181 | * an old-style preprocessor.
182 | */
183 |
184 | #ifndef OLD_PREPROCESSOR
185 | #define OLD_PREPROCESSOR FALSE
186 | #endif
187 |
188 | #if OLD_PREPROCESSOR
189 | #define OK_DOLLAR FALSE
190 | #define OK_CONCAT TRUE
191 | #define COMMENT_INVISIBLE TRUE
192 | #define STRING_FORMAL TRUE
193 | #define IDMAX 63 /* actually, seems to be unlimited */
194 | #endif
195 |
196 | /*
197 | * RECURSION_LIMIT may be set to -1 to disable the macro recursion test.
198 | */
199 | #ifndef RECURSION_LIMIT
200 | #define RECURSION_LIMIT 1000
201 | #endif
202 |
203 | /*
204 | * BITS_CHAR may be defined to set the number of bits per character.
205 | * it is needed only for multi-byte character constants.
206 | */
207 | #ifndef BITS_CHAR
208 | #define BITS_CHAR 8
209 | #endif
210 |
211 | /*
212 | * BIG_ENDIAN is set TRUE on machines (such as the IBM 360 series)
213 | * where 'ab' stores 'a' in the high-bits and 'b' in the low-bits.
214 | * It is set FALSE on machines (such as the PDP-11 and Vax-11)
215 | * where 'ab' stores 'a' in the low-bits and 'b' in the high-bits.
216 | * (Or is it the other way around?) -- Warning: BIG_ENDIAN code is untested.
217 | */
218 | #ifndef BIG_ENDIAN
219 | #define BIG_ENDIAN FALSE
220 | #endif
221 |
222 | /*
223 | * COMMENT_INVISIBLE may be defined to allow "old-style" comment
224 | * processing, whereby the comment becomes a zero-length token
225 | * delimiter. This permitted tokens to be concatenated in macro
226 | * expansions. This was removed from the Draft Ansi Standard.
227 | */
228 | #ifndef COMMENT_INVISIBLE
229 | #define COMMENT_INVISIBLE FALSE
230 | #endif
231 |
232 | /*
233 | * STRING_FORMAL may be defined to allow recognition of macro parameters
234 | * anywhere in replacement strings. This was removed from the Draft Ansi
235 | * Standard and a limited recognition capability added.
236 | */
237 | #ifndef STRING_FORMAL
238 | #define STRING_FORMAL FALSE
239 | #endif
240 |
241 | /*
242 | * OK_DOLLAR enables use of $ as a valid "letter" in identifiers.
243 | * This is a permitted extension to the Ansi Standard and is required
244 | * for e.g., VMS, RSX-11M, etc. It should be set FALSE if cpp is
245 | * used to preprocess assembler source on Unix systems. OLD_PREPROCESSOR
246 | * sets OK_DOLLAR FALSE for that reason.
247 | */
248 | #ifndef OK_DOLLAR
249 | #define OK_DOLLAR TRUE
250 | #endif
251 |
252 | /*
253 | * OK_CONCAT enables (one possible implementation of) token concatenation.
254 | * If cpp is used to preprocess Unix assembler source, this should be
255 | * set FALSE as the concatenation character, #, is used by the assembler.
256 | */
257 | #ifndef OK_CONCAT
258 | #define OK_CONCAT TRUE
259 | #endif
260 |
261 | /*
262 | * OK_DATE may be enabled to predefine today's date as a string
263 | * at the start of each compilation. This is apparently not permitted
264 | * by the Draft Ansi Standard.
265 | */
266 | #ifndef OK_DATE
267 | #define OK_DATE TRUE
268 | #endif
269 |
270 | /*
271 | * Some common definitions.
272 | */
273 |
274 | #ifndef DEBUG
275 | #define DEBUG FALSE
276 | #endif
277 |
278 | /*
279 | * The following definitions are used to allocate memory for
280 | * work buffers. In general, they should not be modified
281 | * by implementors.
282 | *
283 | * PAR_MAC The maximum number of #define parameters (31 per Standard)
284 | * Note: we need another one for strings.
285 | * IDMAX The longest identifier, 31 per Ansi Standard
286 | * NBUFF Input buffer size
287 | * NWORK Work buffer size -- the longest macro
288 | * must fit here after expansion.
289 | * NEXP The nesting depth of #if expressions
290 | * NINCLUDE The number of directories that may be specified
291 | * on a per-system basis, or by the -I option.
292 | * BLK_NEST The number of nested #if's permitted.
293 | */
294 |
295 | #ifndef IDMAX
296 | #define IDMAX 31
297 | #endif
298 | #define PAR_MAC (31 + 1)
299 | #define NBUFF 4096
300 | #define NWORK 4096
301 | #define NEXP 128
302 | #define NINCLUDE 7
303 | #define MAXINCLUDE 5
304 | #define NPARMWORK (NWORK * 2)
305 | #define BLK_NEST 32
306 |
307 | /*
308 | * Some special constants. These may need to be changed if cpp
309 | * is ported to a wierd machine.
310 | *
311 | * NOTE: if cpp is run on a non-ascii machine, ALERT and VT may
312 | * need to be changed. They are used to implement the proposed
313 | * ANSI standard C control characters '\a' and '\v' only.
314 | * DEL is used to tag macro tokens to prevent #define foo foo
315 | * from looping. Note that we don't try to prevent more elaborate
316 | * #define loops from occurring.
317 | */
318 |
319 | #ifndef ALERT
320 | #define ALERT '\007' /* '\a' is "Bell" */
321 | #endif
322 |
323 | #ifndef VT
324 | #define VT '\013' /* Vertical Tab CTRL/K */
325 | #endif
326 |
327 |
328 | #ifndef FILE_LOCAL
329 | #ifdef decus
330 | #define FILE_LOCAL static
331 | #else
332 | #ifdef vax11c
333 | #define FILE_LOCAL static
334 | #else
335 | #define FILE_LOCAL /* Others are global */
336 | #endif
337 | #endif
338 | #endif
339 |
340 |
--------------------------------------------------------------------------------
/inc/lz.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * Name: lz.h
3 | * Author: Marcus Geelnard
4 | * Description: LZ77 coder/decoder interface.
5 | * Reentrant: Yes
6 | *-------------------------------------------------------------------------
7 | * Copyright (c) 2003-2006 Marcus Geelnard
8 | *
9 | * This software is provided 'as-is', without any express or implied
10 | * warranty. In no event will the authors be held liable for any damages
11 | * arising from the use of this software.
12 | *
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | *
17 | * 1. The origin of this software must not be misrepresented; you must not
18 | * claim that you wrote the original software. If you use this software
19 | * in a product, an acknowledgment in the product documentation would
20 | * be appreciated but is not required.
21 | *
22 | * 2. Altered source versions must be plainly marked as such, and must not
23 | * be misrepresented as being the original software.
24 | *
25 | * 3. This notice may not be removed or altered from any source
26 | * distribution.
27 | *
28 | * Marcus Geelnard
29 | * marcus.geelnard at home.se
30 | *************************************************************************/
31 |
32 | #ifndef _lz_h_
33 | #define _lz_h_
34 |
35 | #ifdef __cplusplus
36 | extern "C" {
37 | #endif
38 |
39 |
40 | /*************************************************************************
41 | * Function prototypes
42 | *************************************************************************/
43 |
44 | int LZ_Compress( unsigned char *in, unsigned char *out,
45 | unsigned int insize );
46 | int LZ_CompressFast( unsigned char *in, unsigned char *out,
47 | unsigned int insize, unsigned int *work );
48 | void LZ_Uncompress( unsigned char *in, unsigned char *out,
49 | unsigned int insize );
50 |
51 |
52 | #ifdef __cplusplus
53 | }
54 | #endif
55 |
56 | #endif /* _lz_h_ */
57 |
--------------------------------------------------------------------------------
/inc/rle.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * Name: rle.h
3 | * Author: Marcus Geelnard
4 | * Description: RLE coder/decoder interface.
5 | * Reentrant: Yes
6 | *-------------------------------------------------------------------------
7 | * Copyright (c) 2003-2006 Marcus Geelnard
8 | *
9 | * This software is provided 'as-is', without any express or implied
10 | * warranty. In no event will the authors be held liable for any damages
11 | * arising from the use of this software.
12 | *
13 | * Permission is granted to anyone to use this software for any purpose,
14 | * including commercial applications, and to alter it and redistribute it
15 | * freely, subject to the following restrictions:
16 | *
17 | * 1. The origin of this software must not be misrepresented; you must not
18 | * claim that you wrote the original software. If you use this software
19 | * in a product, an acknowledgment in the product documentation would
20 | * be appreciated but is not required.
21 | *
22 | * 2. Altered source versions must be plainly marked as such, and must not
23 | * be misrepresented as being the original software.
24 | *
25 | * 3. This notice may not be removed or altered from any source
26 | * distribution.
27 | *
28 | * Marcus Geelnard
29 | * marcus.geelnard at home.se
30 | *************************************************************************/
31 |
32 | #ifndef _rle_h_
33 | #define _rle_h_
34 |
35 | #ifdef __cplusplus
36 | extern "C" {
37 | #endif
38 |
39 |
40 | /*************************************************************************
41 | * Function prototypes
42 | *************************************************************************/
43 |
44 | int RLE_Compress( unsigned char *in, unsigned char *out,
45 | unsigned int insize );
46 | void RLE_Uncompress( unsigned char *in, unsigned char *out,
47 | unsigned int insize );
48 |
49 |
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 |
54 | #endif /* _rle_h_ */
55 |
--------------------------------------------------------------------------------
/inc/yygram.h:
--------------------------------------------------------------------------------
1 | #ifndef YYSTYPE
2 | #define YYSTYPE long
3 | #endif
4 | extern YYSTYPE yylval;
5 | extern long yypos;
6 |
7 | #define MEMBER_OP 496
8 | #define ELLIPSIS 495
9 | #define ASSIGN_SUB 494
10 | #define ASSIGN_RSHIFT 493
11 | #define ASSIGN_LSHIFT 492
12 | #define ASSIGN_NEG 491
13 | #define ASSIGN_OR 490
14 | #define ASSIGN_AND 489
15 | #define ASSIGN_MOD 488
16 | #define ASSIGN_DIV 487
17 | #define ASSIGN_ADD 486
18 | #define ASSIGN_MULT 485
19 | #define OR_OP 484
20 | #define AND_OP 483
21 | #define NE_OP 482
22 | #define EQ_OP 481
23 | #define LE_OP 480
24 | #define GE_OP 479
25 | #define RSHIFT_OP 478
26 | #define LSHIFT_OP 477
27 | #define DECREMENT_OP 476
28 | #define INCREMENT_OP 475
29 | #define WORD_RECT 474
30 | #define YVAL 473
31 | #define XVAL 472
32 | #define WITH 471
33 | #define WIELD 470
34 | #define WHILE 469
35 | #define WEIGHT_LIM 468
36 | #define WEIGHT_MOD 467
37 | #define WEIGHT 466
38 | #define WEEK 465
39 | #define WALLS 464
40 | #define VAR 463
41 | #define VALUE 462
42 | #define TVAL 461
43 | #define TYPE 460
44 | #define TURNS 459
45 | #define WORD_TRUE 458
46 | #define TO 457
47 | #define TIMEOUT 456
48 | #define TILES 455
49 | #define TILE 454
50 | #define THROWING 453
51 | #define THREAT 452
52 | #define TEXT 451
53 | #define TERRAIN 450
54 | #define WORD_TEMPLATE 449
55 | #define WORD_TARGET 448
56 | #define SYSTEM 447
57 | #define SWITCH 446
58 | #define SVAL 445
59 | #define SUSTAINS 444
60 | #define STORE 443
61 | #define STOCK 442
62 | #define STATIC 441
63 | #define STATI 440
64 | #define STARTING 439
65 | #define START 438
66 | #define SPELLS 437
67 | #define SPELL 436
68 | #define SPEED 435
69 | #define SPECIALS 434
70 | #define SLOT 433
71 | #define SKILLS 432
72 | #define SIZE 431
73 | #define SDMG 430
74 | #define SAVES 429
75 | #define RVAL 428
76 | #define ROUTINE 427
77 | #define ROOMTYPES 426
78 | #define RETURN 425
79 | #define RESISTS 424
80 | #define REGIONS 423
81 | #define REGION 422
82 | #define RATING 421
83 | #define RANGE 420
84 | #define RANDOM 419
85 | #define RACE 418
86 | #define QVAL 417
87 | #define QUEST 416
88 | #define QUALITIES 415
89 | #define PVAL 414
90 | #define PURPOSE 413
91 | #define PROP 412
92 | #define PROFICIENCIES 411
93 | #define POWER 410
94 | #define POISON 409
95 | #define PER 408
96 | #define PENALTY 407
97 | #define PARTS 406
98 | #define PARTIAL 405
99 | #define PARRY 404
100 | #define PARAMS 403
101 | #define OPTION 402
102 | #define OR 401
103 | #define ON 400
104 | #define OF 399
105 | #define OBJECTS 398
106 | #define OBJECT 397
107 | #define NUTRITION 396
108 | #define WORD_NULL 395
109 | #define NPC 394
110 | #define NORMAL 393
111 | #define NONE 392
112 | #define NEAR 391
113 | #define MTYPE 390
114 | #define MOVE 389
115 | #define MONSTER 388
116 | #define WORD_MIN 387
117 | #define MEMBER 386
118 | #define MELEE 385
119 | #define WORD_MAX 384
120 | #define MATERIAL 383
121 | #define MAP 382
122 | #define MANA 381
123 | #define MODULE 380
124 | #define MAX_SIZE 379
125 | #define LVAL 378
126 | #define LISTS 377
127 | #define LIGHT 376
128 | #define LIFESPAN 375
129 | #define WORD_LEVEL 374
130 | #define LDMG 373
131 | #define ITEM 372
132 | #define INVOKE 371
133 | #define INNATE 370
134 | #define IMMUNE 369
135 | #define IMAGE 368
136 | #define IF 367
137 | #define HIT 366
138 | #define HITPOINTS 365
139 | #define HITDICE 364
140 | #define HEAVY 363
141 | #define GUILD 362
142 | #define GROUP 361
143 | #define GRID 360
144 | #define GRANTS 359
145 | #define GOD 358
146 | #define GLYPH 357
147 | #define GEAR 356
148 | #define FUEL 355
149 | #define FROM 354
150 | #define FOR 353
151 | #define WORD_FILE 352
152 | #define FLOOR 351
153 | #define FLAGS 350
154 | #define FIRES 349
155 | #define FEATURE 348
156 | #define FEAT 347
157 | #define FEATS 346
158 | #define WORD_FALSE 345
159 | #define FACTOR 344
160 | #define EVERY 343
161 | #define EVENT 342
162 | #define FLAVOR 341
163 | #define FAVORED 340
164 | #define EVAL 339
165 | #define EQUIP 338
166 | #define EXPORT 337
167 | #define WORD_ENCOUNTER 336
168 | #define ELSE 335
169 | #define EFFECT 334
170 | #define DVAL 333
171 | #define DUNGEON 332
172 | #define DO 331
173 | #define DISEASE 330
174 | #define DOMAINS 329
175 | #define DOMAIN 328
176 | #define DOOR 327
177 | #define WORD_DESC 326
178 | #define DEPTH 325
179 | #define DEFAULT 324
180 | #define DEF 323
181 | #define WORD_DC 322
182 | #define DAY 321
183 | #define DARK 320
184 | #define DMG 319
185 | #define CVAL 318
186 | #define CURSED 317
187 | #define CRIT 316
188 | #define COST 315
189 | #define CONTINUE 314
190 | #define CTYPE 313
191 | #define COVERAGE 312
192 | #define CONSTANTS 311
193 | #define WORD_COLOR 310
194 | #define CLASS 309
195 | #define CHANCE 308
196 | #define WORD_CR 307
197 | #define CASTER 306
198 | #define CASE 305
199 | #define CAPACITY 304
200 | #define BRIGHT 303
201 | #define BREAK 302
202 | #define BRAWL 301
203 | #define BLESSED 300
204 | #define BEHAVIOUR 299
205 | #define BASE 298
206 | #define AVAL 297
207 | #define ATTACK 296
208 | #define AT 295
209 | #define AS 294
210 | #define ARTIFACT 293
211 | #define ARM 292
212 | #define ARCHERY 291
213 | #define APTITUDES 290
214 | #define WORD_ANY 289
215 | #define AND 288
216 | #define ALSO 287
217 | #define ALL 286
218 | #define ALIGN 285
219 | #define ACC 284
220 | #define ABS 283
221 | #define ABILITY 282
222 | #define REGNAME 281
223 | #define OPCODE 280
224 | #define STYPE 279
225 | #define DIRECTION 278
226 | #define ATTRIBUTE 277
227 | #define WEP_TYPE 276
228 | #define COLOR 275
229 | #define BOOL 274
230 | #define STRING 273
231 | #define RID 272
232 | #define HTEXT 271
233 | #define UINT32 270
234 | #define UINT16 269
235 | #define UINT8 268
236 | #define INT32 267
237 | #define INT16 266
238 | #define INT8 265
239 | #define VOID 264
240 | #define HOBJ 263
241 | #define SCOPE_OPER 262
242 | #define NOTDONE 261
243 | #define MAPAREA 260
244 | #define CHAR_CONST 259
245 | #define IDENT 258
246 | #define LITERAL 257
247 | #define NUMBER 256
248 |
--------------------------------------------------------------------------------
/lib/defines.irh:
--------------------------------------------------------------------------------
1 | /* ww: let's prevent copy-past errors! */
2 |
3 | #define PLANT_IMMUNITIES \
4 | DF_MIND, DF_POIS, DF_SLEE, DF_PLYS, DF_POLY, \
5 | DF_STUN, DF_CRIT, DF_CONF, DF_FEAR
6 |
7 | #define UNDEAD_IMMUNITIES \
8 | DF_MIND, DF_POIS, DF_SLEE, DF_PLYS, DF_STUN, \
9 | DF_DISE, DF_NECR, DF_CRIT, DF_SUBD
10 |
11 | #define SKELETON_IMMUNITIES \
12 | DF_COLD
13 |
14 | #define OOZE_IMMUNITIES \
15 | DF_CRIT, DF_FEAR, DF_MIND, DF_PLYS, DF_POIS, DF_POLY, DF_PSYC \
16 | DF_SLEE, DF_STUK, DF_STUN, DF_SONI
17 |
18 | #define ELEMENTAL_IMMUNITIES \
19 | DF_DISE, DF_POIS, DF_SLEE, DF_PLYS, DF_STUN, DF_STUK, DF_CRIT
20 |
21 | #define WEAPON_FOCUS_NATURAL_ATTACK \
22 | Stati[ADJUST_NAT,A_HIT_BRAWL,+1]
23 |
24 | #define RACIAL_SKILL(sk,lv) \
25 | Stati[SKILL_BONUS,sk,lv]
26 | #define ABILITY(ab,lv) \
27 | Stati[EXTRA_ABILITY,ab,lv]
28 | #undef MAGIC_RES
29 | #define MAGIC_RES(lv) \
30 | Stati[ADJUST_NAT,A_MR,lv]
31 | #define SPELL_RES(lv) \
32 | Stati[ADJUST_NAT,A_MR,((lv*5)-50)]
33 |
34 | /* Spell Difficulties */
35 | #define SP_BUFF 100
36 | #define SP_TRIVIAL 95
37 | #define SP_EASY 90
38 | #define SP_MEDIUM 75
39 | #define SP_HARD 60
40 | #define SP_VERY_HARD 30
41 |
42 | #define IS_A_BUFF(the_cost) \
43 | Flags: EF_NOTBAD, EF_PERSISTANT, EF_LOSEMANA, EF_SHOWNAME, EF_CANCEL; \
44 | Base: SP_BUFF; Purpose: EP_BUFF; Cost: the_cost
45 |
46 | #define COST_1 5
47 | #define COST_1X 10
48 | #define COST_2 15
49 | #define COST_2X 20
50 | #define COST_3 25
51 | #define COST_3X 30
52 | #define COST_4 35
53 | #define COST_4X 40
54 | #define COST_5 45
55 | #define COST_5X 50
56 | #define COST_6 55
57 | #define COST_6X 60
58 |
59 | #define ABIL_BOOST_COST(percent) \
60 | ( (1000 * percent) / 200 ) \
61 | ( (4000 * percent) / 200 ) \
62 | ( (8000 * percent) / 200 ) \
63 | ( (16000 * percent) / 200 ) \
64 | ( (32000 * percent) / 200 ) \
65 | ( (64000 * percent) / 200 )
66 |
67 | #define ALIENIST_CLAUSE(n) \
68 | On Event POST(EV_MAGIC_HIT) { \
69 | hObj cr; \
70 | if (EActor->isCharacter()) \
71 | if (EActor->LevelAs($"alienist") >= n+1) \
72 | { \
73 | cr = EMap->GetEncounterCreature(0); \
74 | if (cr != NULL_OBJ) \
75 | if (cr->CanAddTemplate($"pseudonatural")) \
76 | cr->AddTemplate($"pseudonatural");\
77 | } \
78 | return NOTHING; \
79 | };
80 |
81 | #define ANIMATION_MORALITY(corpse, undead) \
82 | if (undead->isMType(MA_EVIL) && undead->HasMFlag(M_IALIGN)) \
83 | { EActor->Transgress($"mara",5,false,"creating inherently evil undead"); \
84 | EActor->AlignedAct(AL_NONGOOD|AL_EVIL,3,"creating inherently evil undead"); } \
85 | else if (undead->isMType(MA_EVIL) && !EActor->isMType(MA_EVIL) && \
86 | EActor->isCharacter() && isMarist) \
87 | undead->GainPermStati(ALIGNMENT,NULL,SS_MISC,AL_GOOD|AL_LAWFUL); \
88 | if (corpse->HasStati(WAS_FRIENDLY,-1,EActor)) \
89 | EActor->Transgress($"Mara",5,false,"desecrating foes' bodies"); \
90 | if (!corpse->HasEffStati(CORPSE_FLAG,$"Mara"))\
91 | if (undead->isMType(MA_SAPIENT)) \
92 | EActor->gainFavour($"Mara",50); \
93 | if (!isMarist) \
94 | EActor->AlignedAct(AL_NONGOOD|AL_EVIL,1,"creating undead with infernal power"); \
95 | EActor->Transgress($"Immotian",7,false,"creating undead"); \
96 | EActor->Transgress($"Hesani",7,false,"creating undead"); \
97 | EActor->Transgress($"Xavias",4,false,"creating undead"); \
98 | EActor->Transgress($"Erich",4,false,"creating undead"); \
99 | EActor->Transgress($"Ekliazeh",6,false,"creating undead"); \
100 |
101 | #define ANIMATION_HEADER \
102 | bool isMarist; \
103 | isMarist = (EActor->getGod() == $"Mara" || \
104 | (EActor->isCharacter() && EActor->getGodLevel($"Mara") >= 2)); \
105 |
106 |
107 | /* Imagine that for every pair of weapons we hold a best-out-of-21 pitfight
108 | * with equal fighters. The percentage of such matches won by a weapon is
109 | * its weimer-cost. This gives a feel for the relative powers of weapons.
110 | * Note that currently (Fri Dec 19 09:26:30 PST 2003) the enemy AI is
111 | * really abysmal with reach weapons like the longspear. */
112 | #define OPT_COST(wes,orig) orig
113 |
--------------------------------------------------------------------------------
/lib/module-example.irc:
--------------------------------------------------------------------------------
1 | Module "Incursion Example Module";
2 | File "Example.Mod";
3 |
4 |
--------------------------------------------------------------------------------
/lib/new.irh:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/lib/new.irh
--------------------------------------------------------------------------------
/modaccent/README:
--------------------------------------------------------------------------------
1 | This directory, `$DISTRIBUTION/accent',
2 | contains the C code of the ACCENT Compiler Compiler.
3 |
4 | Run the script `build' to compile this code.
5 |
6 | The C code has been generated from the Gentle sources
7 | in directory `$DISTRIBUTION/generate'.
8 | It is not neccessary that you touch that directory.
9 |
10 |
11 | -----------------------------------------------------------------------
12 |
13 | Copyright (C) 1999, 2006 Friedrich Wilhelm Schroeer
14 | This program is free software; you can redistribute it and/or modify
15 | it under the terms of the GNU General Public License as published by
16 | the Free Software Foundation; either version 2 of the License, or
17 | (at your option) any later version.
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | GNU General Public License for more details.
22 | You should have received a copy of the GNU General Public License
23 | along with this program; if not, write to the Free Software
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 |
--------------------------------------------------------------------------------
/modaccent/include/gen.h:
--------------------------------------------------------------------------------
1 | typedef struct {long attr[2];} yyATTRIBUTES;
2 | #define YYSTYPE yyATTRIBUTES
3 | extern YYSTYPE yylval;
4 |
5 | #define Ident 257
6 | #define Char 258
7 | #define Number 259
8 | #define CodeBlock 260
9 | #define yytk_PERCENT_g_BLANK_e_BLANK_n_BLANK_t_BLANK_l_BLANK_e_BLANK 261
10 | #define yytk_PERCENT_z_BLANK_e_BLANK_r_BLANK_o_BLANK 262
11 | #define yytk_PERCENT_o_BLANK_u_BLANK_t_BLANK 263
12 | #define yytk_PERCENT_i_BLANK_n_BLANK 264
13 | #define yytk_GREATER 265
14 | #define yytk_LESS 266
15 | #define yytk_PERCENT_c_BLANK_o_BLANK_n_BLANK_f_BLANK_i_BLANK_l_BLANK_t_BLANK_e_BLANK_r_BLANK 267
16 | #define yytk_PERCENT_l_BLANK_o_BLANK_n_BLANK_g_BLANK 268
17 | #define yytk_PERCENT_s_BLANK_h_BLANK_o_BLANK_r_BLANK_t_BLANK 269
18 | #define yytk_PERCENT_t_BLANK_a_BLANK_i_BLANK_l_BLANK 270
19 | #define yytk_RPAREN 271
20 | #define yytk_RPAREN_ASTERISK 272
21 | #define yytk_RPAREN_QUESTIONM 273
22 | #define yytk_LPAREN 274
23 | #define yytk_PERCENT_d_BLANK_i_BLANK_s_BLANK_f_BLANK_i_BLANK_l_BLANK_t_BLANK_e_BLANK_r_BLANK 275
24 | #define yytk_PERCENT_p_BLANK_r_BLANK_i_BLANK_o_BLANK 276
25 | #define yytk_BAR 277
26 | #define yytk_COLON 278
27 | #define yytk_PERCENT_n_BLANK_o_BLANK_d_BLANK_e_BLANK_f_BLANK_a_BLANK_u_BLANK_l_BLANK_t_BLANK 279
28 | #define yytk_PERCENT_d_BLANK_e_BLANK_f_BLANK_a_BLANK_u_BLANK_l_BLANK_t_BLANK 280
29 | #define yytk_COMMA 281
30 | #define yytk_SEMICOLON 282
31 | #define yytk_PERCENT_t_BLANK_o_BLANK_k_BLANK_e_BLANK_n_BLANK 283
32 | #define yytk_PERCENT_p_BLANK_r_BLANK_e_BLANK_l_BLANK_u_BLANK_d_BLANK_e_BLANK 284
33 |
--------------------------------------------------------------------------------
/modaccent/include/sets.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ACCENT
3 | *
4 | * A Compiler Compiler for the Entire Class of Context-Free Languages
5 | *
6 | * Copyright (C) 1999 Friedrich Wilhelm Schroeer
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 | */
22 |
23 |
24 | /*
25 | * sets.h
26 | */
27 |
28 |
29 | typedef struct SET *set;
30 |
31 | void print_set(set s);
32 |
33 | set empty_set ();
34 |
35 | void into_set_include_elem ();
36 |
37 | void into_set_include_set ();
38 |
39 | extern int changed;
40 |
--------------------------------------------------------------------------------
/modaccent/src/ana.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ACCENT
3 | *
4 | * A Compiler Compiler for the Entire Class of Context-Free Languages
5 | *
6 | * Copyright (C) 1999 Friedrich Wilhelm Schroeer
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 | */
22 |
23 |
24 | /*
25 | * ana.c
26 | */
27 |
28 | /*----------------------------------------------------------------------------*/
29 |
30 | #include "sets.h"
31 |
32 | #define PUBLIC
33 | #define PRIVATE static
34 |
35 | /*----------------------------------------------------------------------------*/
36 |
37 | PRIVATE void compute_transparent();
38 | PRIVATE void compute_first ();
39 | PRIVATE void compute_follow ();
40 | PRIVATE void compute_dir ();
41 | PRIVATE void process_rhs();
42 |
43 | /*----------------------------------------------------------------------------*/
44 | /* Grammar Definition */
45 | /*----------------------------------------------------------------------------*/
46 |
47 | #define max_char 255
48 |
49 | typedef struct MEMBERLIST *memberlist;
50 | typedef struct RULELIST *rulelist;
51 |
52 | typedef int member;
53 |
54 | struct MEMBERLIST {
55 | member head;
56 | memberlist tail;
57 | };
58 |
59 | struct RULELIST {
60 | memberlist head;
61 | rulelist tail;
62 | };
63 |
64 | PRIVATE int n_of_nonterms = 0;
65 | PRIVATE rulelist cur_rule_list = 0;
66 | PRIVATE rulelist last_rule_list_ptr;
67 | PRIVATE memberlist last_member_ptr;
68 | PRIVATE int rulecount = 0;
69 |
70 | /*----------------------------------------------------------------------------*/
71 |
72 | PRIVATE mallocerror()
73 | {
74 | printf("running out of memory\n");
75 | exit(1);
76 | }
77 |
78 | /*----------------------------------------------------------------------------*/
79 |
80 | PUBLIC get_rulecount(ref_n)
81 | int *ref_n;
82 | {
83 | *ref_n = rulecount;
84 | }
85 |
86 | /*----------------------------------------------------------------------------*/
87 |
88 | PUBLIC start_rule(n, ref_r)
89 | int n;
90 | int *ref_r;
91 |
92 | {
93 | rulelist lst;
94 | memberlist r;
95 |
96 | if (n > n_of_nonterms) n_of_nonterms = n;
97 |
98 | r = (memberlist) malloc (sizeof(struct MEMBERLIST));
99 | if (! r) mallocerror();
100 | last_member_ptr = r;
101 |
102 | r->head = n;
103 | r->tail = 0;
104 |
105 | lst = (rulelist) malloc (sizeof (struct RULELIST));
106 | if (! lst) mallocerror();
107 | lst->head = r;
108 | lst->tail = 0;
109 |
110 | if (cur_rule_list == 0) {
111 | cur_rule_list = lst;
112 | last_rule_list_ptr = lst;
113 | }
114 | else {
115 | last_rule_list_ptr->tail = lst;
116 | last_rule_list_ptr = lst;
117 | }
118 |
119 | rulecount++;
120 |
121 | *ref_r = rulecount;
122 | }
123 |
124 | /*----------------------------------------------------------------------------*/
125 |
126 | PRIVATE append_member(n)
127 | {
128 | memberlist lst;
129 |
130 | lst = (memberlist) malloc (sizeof (struct MEMBERLIST));
131 | if (! lst) mallocerror();
132 | lst->tail = 0;
133 | lst->head = n;
134 |
135 | last_member_ptr->tail = lst;
136 | last_member_ptr = lst;
137 | }
138 |
139 | PUBLIC append_nonterm_member(n)
140 | {
141 | append_member(n);
142 | }
143 |
144 | PUBLIC append_token_member(n)
145 | {
146 | append_member(- n);
147 | }
148 |
149 | /*----------------------------------------------------------------------------*/
150 |
151 | PRIVATE print_grammar()
152 | {
153 | rulelist r;
154 | memberlist m;
155 |
156 | r = cur_rule_list;
157 | while (r) {
158 | m = r->head;
159 | r = r-> tail;
160 |
161 | printf("rule\n");
162 | printf("lhs = %d\n", m->head);
163 | m = m->tail;
164 |
165 | while(m) {
166 | printf("member = %d\n", m->head);
167 | m = m->tail;
168 | }
169 | }
170 | }
171 |
172 | /*----------------------------------------------------------------------------*/
173 | /* LL Analysis */
174 | /*----------------------------------------------------------------------------*/
175 |
176 |
177 | PRIVATE int *TRANSPARENT;
178 | PRIVATE set *FIRST;
179 | PRIVATE set *FOLLOW;
180 | PRIVATE set *DIRSET;
181 |
182 | PRIVATE allocate_arrays()
183 | {
184 | TRANSPARENT = (int *) malloc (sizeof(int)*n_of_nonterms+1);
185 | if (! TRANSPARENT) mallocerror();
186 | FIRST = (set *) malloc (sizeof(set)*n_of_nonterms+1);
187 | if (! FIRST) mallocerror();
188 | FOLLOW = (set *) malloc (sizeof(set)*n_of_nonterms+1);
189 | if (! FOLLOW) mallocerror();
190 | DIRSET = (set *) malloc (sizeof(set)*rulecount+1);
191 | if (! DIRSET) mallocerror();
192 | }
193 |
194 | PRIVATE set right_context;
195 | PRIVATE int true_change;
196 |
197 | /*----------------------------------------------------------------------------*/
198 |
199 | PUBLIC init_ana()
200 | {
201 | ;
202 | }
203 |
204 | /*----------------------------------------------------------------------------*/
205 |
206 | PUBLIC run_ana()
207 | {
208 | allocate_arrays();
209 |
210 | compute_transparent();
211 | compute_first();
212 | compute_follow();
213 | compute_dir();
214 | }
215 |
216 |
217 | /*----------------------------------------------------------------------------*/
218 |
219 | PRIVATE void compute_transparent()
220 | {
221 | int i;
222 |
223 | for (i = 1; i <= n_of_nonterms; i++) {
224 | TRANSPARENT[i] = 0;
225 | }
226 |
227 | do {
228 | rulelist rl;
229 | memberlist ml;
230 | member lhs;
231 |
232 | changed = 0;
233 |
234 | /* for all rules */
235 | rl = cur_rule_list;
236 | while (rl) {
237 | ml = rl->head;
238 | rl = rl->tail;
239 | lhs = ml->head;
240 |
241 | if (! TRANSPARENT[lhs]) {
242 | if (ml-> tail == 0) { /* empty rhs */
243 | TRANSPARENT[lhs] = 1;
244 | changed = 1;
245 | }
246 | else {
247 | /* for all members of rhs */
248 | ml = ml->tail;
249 | while (ml) {
250 | member m;
251 | int is_still_trans = 1;
252 |
253 | m = ml->head;
254 | if (m <= 0) { /* m is token */
255 | is_still_trans = 0;
256 | break;
257 | }
258 | if (TRANSPARENT[m]) {
259 | ; /* continue with rhs */
260 | }
261 | else {
262 | is_still_trans = 0;
263 | break;
264 | }
265 |
266 | if (is_still_trans) {
267 | TRANSPARENT[lhs] = 1;
268 | changed = 1;
269 | }
270 |
271 | ml = ml->tail;
272 | }
273 | }
274 | }
275 | }
276 |
277 | } while(changed);
278 |
279 | }
280 |
281 | /*----------------------------------------------------------------------------*/
282 |
283 | PRIVATE void compute_first ()
284 | {
285 | int i;
286 |
287 | /* for all nonterms FIRST = empty_set */
288 |
289 | for (i = 1; i <= n_of_nonterms; i++) {
290 | FIRST[i] = empty_set();
291 | }
292 |
293 | do {
294 | rulelist rl;
295 | memberlist ml;
296 | member lhs, m;
297 |
298 | changed = 0;
299 |
300 | /* for all rules */
301 | rl = cur_rule_list;
302 | while (rl) {
303 | ml = rl->head;
304 | rl = rl->tail;
305 |
306 | lhs = ml->head;
307 | ml = ml->tail;
308 | while(ml) {
309 | m = ml->head;
310 | if (m <= 0) { /* m is a token */
311 | into_set_include_elem(&FIRST[lhs], - m);
312 | break;
313 | }
314 | into_set_include_set(&FIRST[lhs], FIRST[m]);
315 | if (TRANSPARENT[m]) {
316 | ; /* continue */
317 | }
318 | else {
319 | break;
320 | }
321 |
322 | ml = ml->tail;
323 | }
324 | }
325 | } while (changed);
326 |
327 | }
328 |
329 | /*----------------------------------------------------------------------------*/
330 |
331 | PRIVATE void compute_follow ()
332 | {
333 | int i;
334 |
335 | /* for all nonterms FOLLOW = empty_set */
336 |
337 | for (i = 1; i <= n_of_nonterms; i++) {
338 | FOLLOW[i] = empty_set();
339 | }
340 |
341 | do {
342 | rulelist rl;
343 | memberlist ml;
344 | member lhs;
345 | memberlist rhs;
346 |
347 | true_change = 0;
348 |
349 | /* for all rules */
350 | rl = cur_rule_list;
351 | while (rl) {
352 | ml = rl->head;
353 | rl = rl->tail;
354 |
355 | lhs = ml->head;
356 | rhs = ml->tail;
357 | right_context = empty_set();
358 | into_set_include_set(&right_context, FOLLOW[lhs]);
359 | process_rhs(rhs);
360 |
361 | }
362 | } while (true_change);
363 |
364 | }
365 |
366 | /*----------------------------------------------------------------------------*/
367 |
368 | /* called by compute_follow */
369 |
370 | PRIVATE void process_rhs(ml)
371 | memberlist ml;
372 | {
373 | member m;
374 |
375 | if (ml == 0) return;
376 |
377 | process_rhs(ml->tail);
378 | m = ml->head;
379 |
380 | if (m <= 0) { /* m is a token */
381 | right_context = empty_set();
382 | into_set_include_elem(&right_context, - m);
383 | }
384 | else { /* m is a nonterm */
385 | changed = 0;
386 | into_set_include_set(&FOLLOW[m], right_context);
387 | if (changed) true_change = 1;
388 |
389 | if (TRANSPARENT[m]) {
390 | into_set_include_set(&right_context, FIRST[m]);
391 | }
392 | else {
393 | right_context = empty_set();
394 | into_set_include_set(&right_context, FIRST[m]);
395 | }
396 | }
397 | }
398 |
399 | /*----------------------------------------------------------------------------*/
400 |
401 | PRIVATE void compute_dir ()
402 | {
403 | rulelist rl;
404 | memberlist ml;
405 | member lhs;
406 | member m;
407 |
408 | set cur;
409 | int still_transparent;
410 | int ruleindex;
411 |
412 | rl = cur_rule_list;
413 | ruleindex = 0;
414 | while (rl) {
415 | ml = rl->head;
416 | rl = rl->tail;
417 |
418 | cur = empty_set();
419 |
420 | still_transparent = 1;
421 |
422 | lhs = ml->head;
423 | ml = ml->tail;
424 | while (ml) {
425 | m = ml->head;
426 | ml = ml->tail;
427 |
428 | if (m <= 0) { /* m is a token */
429 | into_set_include_elem(&cur, - m);
430 | ruleindex++;
431 | DIRSET[ruleindex] = cur;
432 | still_transparent = 0;
433 | break;
434 | }
435 |
436 | into_set_include_set(&cur, FIRST[m]);
437 | if (TRANSPARENT[m]) {
438 | ; /* continue */
439 | }
440 | else {
441 | ruleindex++;
442 | DIRSET[ruleindex] = cur;
443 | still_transparent = 0;
444 | break;
445 | }
446 | }
447 | if (still_transparent) {
448 | into_set_include_set(&cur, FOLLOW[lhs]);
449 | ruleindex++;
450 | DIRSET[ruleindex] = cur;
451 | }
452 |
453 | }
454 | }
455 |
456 | /*----------------------------------------------------------------------------*/
457 |
458 | PUBLIC get_dirset(n, ref_s)
459 | int n;
460 | set *ref_s;
461 | {
462 | *ref_s = DIRSET[n];
463 | }
464 |
465 | /*----------------------------------------------------------------------------*/
466 |
467 | PUBLIC get_transparent(n, ref_val)
468 | int n;
469 | int *ref_val;
470 | {
471 | *ref_val = TRANSPARENT[n];
472 | }
473 | /*----------------------------------------------------------------------------*/
474 |
475 | PUBLIC get_max_char(ref_n)
476 | int *ref_n;
477 | {
478 | *ref_n = max_char;
479 | }
480 |
481 | /*----------------------------------------------------------------------------*/
482 |
--------------------------------------------------------------------------------
/modaccent/src/auxil.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ACCENT
3 | *
4 | * A Compiler Compiler for the Entire Class of Context-Free Languages
5 | *
6 | * Copyright (C) 1999 Friedrich Wilhelm Schroeer
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 | */
22 |
23 |
24 | POS_to_INT(pos, ref_number)
25 | long pos;
26 | long *ref_number;
27 | {
28 | *ref_number = pos;
29 | }
30 |
31 | #define yyLCODE 1000L
32 | #define yyFCODE 1000000000L
33 |
34 | POS_to_LineNumber(pos, ref_number)
35 | long pos;
36 | long *ref_number;
37 | {
38 | *ref_number = (pos % yyFCODE) / yyLCODE;
39 | }
40 |
--------------------------------------------------------------------------------
/modaccent/src/code.c:
--------------------------------------------------------------------------------
1 | #define NULL 0
2 | typedef long * yy;
3 | #define yyu (-2147483647L)
4 | static yy yynull;
5 | extern yy yyh;
6 | extern yy yyhx;
7 | static yyErr(n,l)
8 | {
9 | yyAbort(n,"code", l);
10 | }
11 | extern yy yyglov_GentleFlag;
12 | extern yy yyglov_NontermList;
13 | extern yy yyglov_PreludeBlock;
14 | fix_code()
15 | {
16 | {
17 | yy yyb = NULL;
18 | yy yy_2_1;
19 | yy yy_4_1;
20 | yy yy_6_1;
21 | yy yy_8_1_1;
22 | yy yy_8_1_2_1;
23 | yy yy_8_2_1_1;
24 | yy yy_8_2_3_1;
25 | yy yy_9_1;
26 | yy yy_11_1;
27 | yy yy_13_1;
28 | yy yy_15_1;
29 | yy yy_17_1;
30 | yy yy_19_1;
31 | yy yy_21_1;
32 | yy yy_23_1;
33 | yy yy_25_1;
34 | yy yy_27_1;
35 | yy yy_29_1;
36 | yy yy_31_1;
37 | yy yy_33_1;
38 | yy yy_35_1;
39 | yy yy_37_1;
40 | yy yy_39_1;
41 | yy yy_41_1;
42 | yy yy_43_1;
43 | yy yy_45_1;
44 | yy yy_47_1;
45 | yy yy_49_1;
46 | yy yy_51_1;
47 | yy yy_53_1;
48 | yy yy_55_1;
49 | yy yy_57_1;
50 | yy yy_59_1;
51 | yy yy_61_1;
52 | yy yy_63_1;
53 | yy yy_65_1;
54 | yy yy_67_1;
55 | yy yy_69_1;
56 | yy yy_71_1;
57 | yy yy_73_1;
58 | yy yy_75_1;
59 | yy yy_77_1;
60 | yy yy_79_1;
61 | yy yy_81_1;
62 | yy yy_83_1;
63 | yy yy_85_1;
64 | yy yy_87_1;
65 | yy yy_89_1;
66 | yy yy_91_1;
67 | yy yy_93_1;
68 | yy yy_95_1;
69 | yy yy_97_1;
70 | yy yy_99_1;
71 | yy yy_101_1;
72 | Nl();
73 | yy_2_1 = ((yy)"extern YYSTYPE yylval;");
74 | Put(yy_2_1);
75 | Nl();
76 | yy_4_1 = ((yy)"YYSTYPE yylval;");
77 | Put(yy_4_1);
78 | Nl();
79 | #ifdef INCURSION_YYPOS
80 | yy_6_1 = ((yy)"extern long yypos;");
81 | Put(yy_6_1);
82 | Nl();
83 | #endif
84 | {
85 | yy yysb = yyb;
86 | yy_8_1_1 = yyglov_GentleFlag;
87 | if (yy_8_1_1 == (yy) yyu) yyErr(1,41);
88 | if (yy_8_1_1[0] != 1) goto yyfl_3_1_8_1;
89 | yy_8_1_2_1 = ((yy)"/* GentleFlag = yes */");
90 | Put(yy_8_1_2_1);
91 | Nl();
92 | goto yysl_3_1_8;
93 | yyfl_3_1_8_1 : ;
94 | #ifdef INCURSION_YYPOS
95 | yy_8_2_1_1 = ((yy)"long yypos = 1;");
96 | Put(yy_8_2_1_1);
97 | Nl();
98 | #endif
99 | yy_8_2_3_1 = ((yy)"/* GentleFlag = no */");
100 | Put(yy_8_2_3_1);
101 | Nl();
102 | goto yysl_3_1_8;
103 | yysl_3_1_8 : ;
104 | yyb = yysb;
105 | }
106 | yy_9_1 = ((yy)"");
107 | Put(yy_9_1);
108 | Nl();
109 | yy_11_1 = ((yy)"typedef struct LEXELEMSTRUCT {");
110 | Put(yy_11_1);
111 | Nl();
112 | yy_13_1 = ((yy)" YYSTYPE val;");
113 | Put(yy_13_1);
114 | Nl();
115 | yy_15_1 = ((yy)" long pos;");
116 | Put(yy_15_1);
117 | Nl();
118 | yy_17_1 = ((yy)" long sym;");
119 | Put(yy_17_1);
120 | Nl();
121 | yy_19_1 = ((yy)" char * text;");
122 | Put(yy_19_1);
123 | Nl();
124 | yy_21_1 = ((yy)" struct LEXELEMSTRUCT *next;");
125 | Put(yy_21_1);
126 | Nl();
127 | yy_23_1 = ((yy)"} LEXELEM;");
128 | Put(yy_23_1);
129 | Nl();
130 | yy_25_1 = ((yy)" ");
131 | Put(yy_25_1);
132 | Nl();
133 | yy_27_1 = ((yy)"LEXELEM *first_lexelem, *cur_lexelem;");
134 | Put(yy_27_1);
135 | Nl();
136 | yy_29_1 = ((yy)"");
137 | Put(yy_29_1);
138 | Nl();
139 | yy_31_1 = ((yy)"void init_lexelem()");
140 | Put(yy_31_1);
141 | Nl();
142 | yy_33_1 = ((yy)"{");
143 | Put(yy_33_1);
144 | Nl();
145 | yy_35_1 = ((yy)" cur_lexelem = first_lexelem;");
146 | Put(yy_35_1);
147 | Nl();
148 | yy_37_1 = ((yy)"}");
149 | Put(yy_37_1);
150 | Nl();
151 | yy_39_1 = ((yy)"");
152 | Put(yy_39_1);
153 | Nl();
154 | yy_41_1 = ((yy)"void first_lexval () {");
155 | Put(yy_41_1);
156 | Nl();
157 | yy_43_1 = ((yy)" LEXELEM *p;");
158 | Put(yy_43_1);
159 | Nl();
160 | yy_45_1 = ((yy)" p = (LEXELEM *)malloc(sizeof(LEXELEM));");
161 | Put(yy_45_1);
162 | Nl();
163 | yy_47_1 = ((yy)" if (! p) yymallocerror();");
164 | Put(yy_47_1);
165 | Nl();
166 | yy_49_1 = ((yy)" p->val = yylval;");
167 | Put(yy_49_1);
168 | Nl();
169 | yy_51_1 = ((yy)" p->pos = yypos;");
170 | Put(yy_51_1);
171 | Nl();
172 | yy_53_1 = ((yy)" p->next = 0;");
173 | Put(yy_53_1);
174 | Nl();
175 | yy_55_1 = ((yy)" cur_lexelem = p;");
176 | Put(yy_55_1);
177 | Nl();
178 | yy_57_1 = ((yy)" first_lexelem = p;");
179 | Put(yy_57_1);
180 | Nl();
181 | yy_59_1 = ((yy)"}");
182 | Put(yy_59_1);
183 | Nl();
184 | yy_61_1 = ((yy)"");
185 | Put(yy_61_1);
186 | Nl();
187 | yy_63_1 = ((yy)"void next_lexval() {");
188 | Put(yy_63_1);
189 | Nl();
190 | yy_65_1 = ((yy)" LEXELEM *p;");
191 | Put(yy_65_1);
192 | Nl();
193 | yy_67_1 = ((yy)" p = (LEXELEM *)malloc(sizeof(LEXELEM));");
194 | Put(yy_67_1);
195 | Nl();
196 | yy_69_1 = ((yy)" if (! p) yymallocerror();");
197 | Put(yy_69_1);
198 | Nl();
199 | yy_71_1 = ((yy)" cur_lexelem-> next = p;");
200 | Put(yy_71_1);
201 | Nl();
202 | yy_73_1 = ((yy)" p->val = yylval;");
203 | Put(yy_73_1);
204 | Nl();
205 | yy_75_1 = ((yy)" p->pos = yypos;");
206 | Put(yy_75_1);
207 | Nl();
208 | yy_77_1 = ((yy)" p->next = 0;");
209 | Put(yy_77_1);
210 | Nl();
211 | yy_79_1 = ((yy)" cur_lexelem = p;");
212 | Put(yy_79_1);
213 | Nl();
214 | yy_81_1 = ((yy)"}");
215 | Put(yy_81_1);
216 | Nl();
217 | yy_83_1 = ((yy)"");
218 | Put(yy_83_1);
219 | Nl();
220 | yy_85_1 = ((yy)"void get_lexval() {");
221 | Put(yy_85_1);
222 | Nl();
223 | yy_87_1 = ((yy)" extern int FREE_LEXELEMS;");
224 | Put(yy_87_1);
225 | Nl();
226 | yy_89_1 = ((yy)" LEXELEM *p;");
227 | Put(yy_89_1);
228 | Nl();
229 | yy_91_1 = ((yy)" yylval = cur_lexelem->val;");
230 | Put(yy_91_1);
231 | Nl();
232 | yy_93_1 = ((yy)" yypos = cur_lexelem->pos;");
233 | Put(yy_93_1);
234 | Nl();
235 | yy_95_1 = ((yy)" p = cur_lexelem;");
236 | Put(yy_95_1);
237 | Nl();
238 | yy_97_1 = ((yy)" cur_lexelem = cur_lexelem->next;");
239 | Put(yy_97_1);
240 | Nl();
241 | yy_99_1 = ((yy)" free(p);");
242 | Put(yy_99_1);
243 | Nl();
244 | yy_101_1 = ((yy)"}");
245 | Put(yy_101_1);
246 | Nl();
247 | Nl();
248 | return;
249 | }
250 | }
251 |
--------------------------------------------------------------------------------
/modaccent/src/errmsg.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ACCENT
3 | *
4 | * A Compiler Compiler for the Entire Class of Context-Free Languages
5 | *
6 | * Copyright (C) 1999 Friedrich Wilhelm Schroeer
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 | */
22 |
23 |
24 | /*
25 | * errmsg.c
26 | */
27 |
28 |
29 | #define PRIVATE static
30 |
31 | /*--------------------------------------------------------------------*/
32 | /* Source Positions */
33 | /*--------------------------------------------------------------------*/
34 |
35 | #define yyLCODE 1000L
36 |
37 | long yypos = (yyLCODE+1);
38 |
39 | PRIVATE long yyLineCount = 1;
40 |
41 | /*--------------------------------------------------------------------*/
42 | void yyGetPos(ref_pos)
43 | long *ref_pos;
44 | {
45 | *ref_pos = yypos-1;
46 | }
47 |
48 | /*--------------------------------------------------------------------*/
49 |
50 | void yyPosToNextLine()
51 | {
52 | yyLineCount++;
53 | yypos = yyLineCount*yyLCODE+1;
54 | }
55 |
56 | /*--------------------------------------------------------------------*/
57 |
58 | PRIVATE yyLineAtPos(pos)
59 | long pos;
60 | {
61 | long l;
62 | l = pos / yyLCODE;
63 | return l;
64 | }
65 |
66 | /*--------------------------------------------------------------------*/
67 |
68 | PRIVATE yyColAtPos(pos)
69 | long pos;
70 | {
71 | long c;
72 | c = pos % yyLCODE;
73 | return c;
74 | }
75 |
76 | /*--------------------------------------------------------------------*/
77 | /* Error Messages */
78 | /*--------------------------------------------------------------------*/
79 |
80 | void Error(msg, pos)
81 | char *msg;
82 | long pos;
83 | {
84 | printf("line %d, col %d: %s\n",
85 | yyLineAtPos(pos), yyColAtPos(pos), msg);
86 | exit(1);
87 | }
88 |
89 | /*--------------------------------------------------------------------*/
90 |
91 | yyerror(msg)
92 | char *msg;
93 | {
94 | long pos;
95 |
96 | yyGetPos(& pos);
97 | Error(msg, pos);
98 | }
99 |
100 | /*--------------------------------------------------------------------*/
101 |
--------------------------------------------------------------------------------
/modaccent/src/grts.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | GENTLE 97
4 |
5 | Gentle Compiler Construction System 3.0
6 | Copyright (C) 1992, 1997 F.W. Schroeer
7 |
8 | 01100401
9 |
10 | */
11 |
12 |
13 | /* Gentle Runtime System */
14 |
15 | char *THIS_RUNTIME_SYSTEM =
16 | "Gentle 3.0 01100401 (C) 1992, 1997";
17 |
18 | typedef long * yyt;
19 |
20 | yyt yyh;
21 | yyt yyhx;
22 |
23 | #define HEAPPIECE 20000
24 |
25 | yyExtend()
26 | {
27 | yyh = (yyt) malloc(HEAPPIECE * sizeof(long));
28 | yyhx = yyh + HEAPPIECE - 100;
29 | if (yyh == 0) {
30 | printf ("HEAP STORAGE FULL\n");
31 | exit(1);
32 | }
33 | }
34 |
35 | #define yyCntlMax 500
36 |
37 | static yyt CURBLOCK;
38 | static yyt CURPOS;
39 | static yyt FIRSTBLOCK;
40 |
41 | static yyt FREELIST = 0;
42 |
43 | static yyt NEWBLOCK()
44 | {
45 | yyt p;
46 |
47 | if (FREELIST == 0) {
48 | p = (yyt) malloc (sizeof (yyt) * (yyCntlMax + 200));
49 | if (p == 0) {
50 | printf("NEWBLOCK: running out of memory\n");
51 | exit(1);
52 | }
53 | }
54 | else {
55 | p = FREELIST;
56 | FREELIST = (yyt) *p;
57 | }
58 |
59 | return p;
60 | }
61 |
62 | static FREEBLOCK (p)
63 | yyt p;
64 | {
65 | *p = (long) FREELIST;
66 | FREELIST = p;
67 | }
68 |
69 | yyt yyAllocCntl(n)
70 | {
71 | yyt p;
72 | p = CURPOS;
73 | CURPOS += n;
74 | if (CURPOS >= CURBLOCK+yyCntlMax) {
75 | yyt b;
76 | b = NEWBLOCK();
77 | *b = 0;
78 | *CURBLOCK = (long) b;
79 | CURBLOCK = b;
80 | CURPOS = CURBLOCK + 1;
81 | p = CURPOS;
82 | CURPOS += n;
83 | }
84 | return p;
85 | }
86 |
87 | typedef struct {
88 | yyt firstblock;
89 | yyt curblock;
90 | yyt curpos;
91 | } yysave;
92 |
93 | yyBeginChoice(ref_saved)
94 | yysave *ref_saved;
95 | {
96 | ref_saved->curblock = CURBLOCK;
97 | ref_saved->curpos = CURPOS;
98 | ref_saved->firstblock = FIRSTBLOCK;
99 |
100 | FIRSTBLOCK = NEWBLOCK();
101 | *FIRSTBLOCK = 0;
102 | CURBLOCK = FIRSTBLOCK;
103 | CURPOS = CURBLOCK + 1;
104 | }
105 |
106 | yyEndChoice(saved)
107 | yysave saved;
108 | {
109 | yyt p;
110 |
111 | p = FIRSTBLOCK;
112 | while (p != (yyt) 0) {
113 | yyt next;
114 | next = (yyt) *p;
115 | FREEBLOCK(p);
116 | p = next;
117 | }
118 |
119 | CURBLOCK = saved.curblock;
120 | CURPOS = saved.curpos;
121 | FIRSTBLOCK = saved.firstblock;
122 | }
123 |
124 | yyAbort (Code, FileName, Line)
125 | int Code;
126 | char * FileName;
127 | int Line;
128 | {
129 | switch(Code) {
130 | case 1:
131 | printf ("Undefined value in \"%s.g\", line %d\n", FileName, Line);
132 | exit(1);
133 | case 2:
134 | printf ("No rule applicable in \"%s.g\", line %d\n", FileName, Line);
135 | exit(1);
136 | case 3:
137 | printf ("Selected grammar rule failed in \"%s.g\", line %d\n",
138 | FileName, Line);
139 | exit(1);
140 | case 4:
141 | printf ("Selected CHOICE rule failed in \"%s.g\", line %d\n",
142 | FileName, Line);
143 | exit(1);
144 | default:
145 | printf ("Error %d (?) in \"%s.g\", line %d\n", Code, FileName, Line);
146 | exit(1);
147 | }
148 | }
149 |
150 | yyPrintOpaque (i)
151 | long i;
152 | {
153 | printf("<<%d>>", i);
154 | }
155 |
156 | yyPrintIndex (i)
157 | long i;
158 | {
159 | printf("#%d", i);
160 | }
161 |
162 | yyPrint_INT (i)
163 | long i;
164 | {
165 | printf("%d", i);
166 | }
167 |
168 | yyPrint_POS (i)
169 | long i;
170 | {
171 | printf("%d", i);
172 | }
173 |
174 | #define STRINGLENGTH 40
175 |
176 | yyPrint_STRING (Str)
177 | char *Str;
178 | {
179 | char OutBuf[STRINGLENGTH];
180 | char * OutBufPtr;
181 | OutBufPtr = &OutBuf[0];
182 |
183 | while(*Str) {
184 | if (OutBufPtr > &OutBuf[STRINGLENGTH-4]) {
185 | *OutBufPtr++ = '.';
186 | *OutBufPtr++ = '.';
187 | *OutBufPtr++ = '.';
188 | break;
189 | }
190 |
191 | switch (*Str) {
192 |
193 | case '\\':
194 | *OutBufPtr++ = '\\';
195 | *OutBufPtr++ = '\\';
196 | Str++;
197 | break;
198 | case '\n':
199 | *OutBufPtr++ = '\\';
200 | *OutBufPtr++ = 'n';
201 | Str++;
202 | break;
203 | case '\"':
204 | *OutBufPtr++ = '\\';
205 | *OutBufPtr++ = '"';
206 | Str++;
207 | break;
208 |
209 | default:
210 | *OutBufPtr++ = *Str++;
211 | }
212 | }
213 | *OutBufPtr = '\0';
214 |
215 | printf("\"%s\"", OutBuf);
216 | }
217 |
218 | static long yyIndentation = 0;
219 |
220 | static yyIndent()
221 | {
222 | int i;
223 |
224 | for (i = 1; i <= yyIndentation; i++) {
225 | printf(" ");
226 | }
227 | }
228 |
229 | yyTerm(f)
230 | {
231 | printf("%s", f);
232 | }
233 |
234 | yyFirstArg()
235 | {
236 | printf("(\n");
237 | yyIndentation++;
238 | yyIndent();
239 | }
240 |
241 | yyNextArg()
242 | {
243 | printf(",\n");
244 | yyIndent();
245 | }
246 |
247 | yyEndArgs()
248 | {
249 | yyIndentation--;
250 | printf("\n");
251 | yyIndent();
252 | printf(")");
253 | }
254 |
255 | yyNoArgs()
256 | {
257 | ;
258 | }
259 |
260 | yyEndPrint()
261 | {
262 | printf("\n");
263 | }
264 |
--------------------------------------------------------------------------------
/modaccent/src/idents.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ACCENT
3 | *
4 | * A Compiler Compiler for the Entire Class of Context-Free Languages
5 | *
6 | * Copyright (C) 1999 Friedrich Wilhelm Schroeer
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 | */
22 |
23 |
24 | #include
25 |
26 | #define PRIVATE static
27 |
28 | /*--------------------------------------------------------------------*/
29 |
30 | #define HashTabSize 2048
31 | #define STRINGTAB_PIECE 10000
32 | #define STRINGTAB_EXTRA 500
33 |
34 | typedef struct IDENTSTRUCT *IDENT;
35 |
36 | struct IDENTSTRUCT
37 | {
38 | char *firstposptr;
39 | long length;
40 | IDENT next;
41 | long meaning;
42 | };
43 |
44 | PRIVATE char *idstringtab_ptr;
45 | PRIVATE char *idstringtab_endptr;
46 |
47 | struct IDENTSTRUCT *idtab_ptr;
48 | struct IDENTSTRUCT *idtab_endptr;
49 |
50 | PRIVATE IDENT HashTab [HashTabSize];
51 |
52 | PRIVATE int initialized = 0;
53 |
54 | /*--------------------------------------------------------------------*/
55 |
56 | PRIVATE allocate_idstringtab ()
57 | {
58 | idstringtab_ptr =
59 | (char *) malloc (STRINGTAB_PIECE + STRINGTAB_EXTRA);
60 | if (idstringtab_ptr == 0) {
61 | printf("memory allocation failed\n");
62 | exit(1);
63 | }
64 | idstringtab_endptr = idstringtab_ptr + STRINGTAB_PIECE - 1;
65 | }
66 |
67 | /*--------------------------------------------------------------------*/
68 |
69 | #define IDTABPIECESIZE 500
70 | typedef struct IDENTSTRUCT IDTAB [IDTABPIECESIZE];
71 |
72 | PRIVATE allocate_idtab ()
73 | {
74 | idtab_ptr =
75 | (struct IDENTSTRUCT *)
76 | malloc (sizeof (IDTAB /*struct IDENTSTRUCT [IDTABPIECESIZE]*/ ) );
77 | if (idtab_ptr == 0) {
78 | printf("memory allocation failed\n");
79 | exit(1);
80 | }
81 | idtab_endptr = & idtab_ptr[IDTABPIECESIZE - 1];
82 | }
83 |
84 | /*--------------------------------------------------------------------*/
85 |
86 | PRIVATE InitIdents ()
87 | {
88 | long i;
89 |
90 | for (i = 0; i<=HashTabSize-1; i++) HashTab[i] = 0;
91 |
92 | allocate_idtab ();
93 | allocate_idstringtab ();
94 |
95 | initialized = 1;
96 | }
97 |
98 | /*--------------------------------------------------------------------*/
99 |
100 | slice_to_id (idstart, idstop, ref_id)
101 | char *idstart; /* position of first character */
102 | char *idstop; /* position a f t e r last character */
103 | IDENT *ref_id;
104 |
105 | {
106 | long hash, length;
107 | IDENT chain;
108 | IDENT NewId;
109 |
110 | if (! initialized) InitIdents();
111 |
112 | length = idstop-idstart;
113 | hash = ( length*256 + ((*idstart)&0xf)*16 + (*(idstop-1)&0xf) )
114 | & (HashTabSize-1);
115 | chain = HashTab[hash];
116 |
117 | for(;;) {
118 | if (chain == 0) {
119 |
120 | /* not in table */
121 |
122 | register char *i, *freeptr, *stop;
123 |
124 | NewId = idtab_ptr;
125 |
126 | if (idtab_ptr == idtab_endptr)
127 | allocate_idtab();
128 | else
129 | idtab_ptr++;
130 |
131 | /* copy id into string table */
132 | i = idstart;
133 | if (idstringtab_ptr > idstringtab_endptr)
134 | allocate_idstringtab();
135 | freeptr = idstringtab_ptr;
136 | stop = idstop;
137 | while (i < stop) {
138 | *freeptr++ = *i++;
139 | }
140 | *freeptr = '\0';
141 | freeptr++;
142 |
143 | NewId->firstposptr = idstringtab_ptr;
144 | NewId->length = length;
145 | NewId->next = HashTab[hash];
146 | NewId->meaning = 0;
147 |
148 | HashTab[hash] = NewId;
149 |
150 | idstringtab_ptr= freeptr;
151 |
152 |
153 | break;
154 | }
155 |
156 | /* current token == ident at chain ? */
157 |
158 | if (chain->length == length) {
159 | register char *i, *j;
160 | i = idstart; j = chain->firstposptr;
161 | while (i != idstop && *i == *j) {
162 | i++; j++;
163 | }
164 |
165 | if (i == idstop && *j == '\0') {
166 |
167 | /* found */
168 |
169 | NewId = chain;
170 | break;
171 | }
172 | }
173 |
174 | chain = chain->next;
175 | }
176 |
177 | *ref_id = NewId;
178 | }
179 |
180 | /*--------------------------------------------------------------------*/
181 | void string_to_id (string, ref_id)
182 | char *string;
183 | IDENT *ref_id;
184 | {
185 | char *idstop;
186 |
187 | idstop = string;
188 | while (*idstop != '\0') idstop++;
189 | slice_to_id (string, idstop, ref_id);
190 | }
191 |
192 | /*--------------------------------------------------------------------*/
193 | void id_to_string (id, ref_string)
194 | IDENT id;
195 | char **ref_string;
196 | {
197 | *ref_string = id->firstposptr;
198 | }
199 |
200 | /*--------------------------------------------------------------------*/
201 | void DefMeaning (id, m)
202 | IDENT id;
203 | long m;
204 | {
205 | id->meaning = m;
206 | }
207 |
208 | /*--------------------------------------------------------------------*/
209 | void UndefMeaning (id)
210 | IDENT id;
211 | {
212 | id->meaning = 0;
213 | }
214 |
215 | /*--------------------------------------------------------------------*/
216 | int HasMeaning (id, ref_meaning)
217 | IDENT id;
218 | long *ref_meaning;
219 | {
220 | if (id->meaning == 0)
221 | return 0;
222 | *ref_meaning = id->meaning;
223 | return 1;
224 | }
225 |
226 | /*--------------------------------------------------------------------*/
227 | ErrorI (str1, id, str2, pos)
228 | char *str1;
229 | IDENT id;
230 | char *str2;
231 | long pos;
232 | {
233 | char *idrepr;
234 | char buf[300];
235 |
236 | id_to_string (id, &idrepr);
237 | sprintf(buf, "%s%s%s", str1, idrepr, str2);
238 | Error(buf, pos);
239 | }
240 |
241 | /*--------------------------------------------------------------------*/
242 |
--------------------------------------------------------------------------------
/modaccent/src/lexinfo.c:
--------------------------------------------------------------------------------
1 | typedef long * yy;
2 | #define yyu (-2147483647L)
3 | static yy yynull;
4 | extern yy yyh;
5 | extern yy yyhx;
6 | static yyErr(n,l)
7 | {
8 | yyAbort(n,"lexinfo", l);
9 | }
10 | extern yy yyglov_LHS_List;
11 | extern yy yyglov_GentleFlag;
12 | extern yy yyglov_NontermList;
13 | extern yy yyglov_PreludeBlock;
14 | yy yyglov_Tokens = (yy) yyu;
15 | yy yyglov_Literals = (yy) yyu;
16 | yyeq_TKNLIST(t1, t2) yy t1, t2;
17 | {
18 | switch(t1[0]) {
19 | case 1: return (t2[0] == 1)
20 | && yyeq_TKN((yy)t1[1], (yy)t2[1])
21 | && yyeq_TKNLIST((yy)t1[2], (yy)t2[2])
22 | ;
23 | case 2: return (t2[0] == 2)
24 | ;
25 | }
26 | }
27 | yyPrint_TKNLIST(t) yy t;
28 | {
29 | switch(t[0]) {
30 | case 1:
31 | yyTerm("list");
32 | yyFirstArg();
33 | yyPrint_TKN((yy)t[1]);
34 | yyNextArg();
35 | yyPrint_TKNLIST((yy)t[2]);
36 | yyEndArgs();
37 | break;
38 | case 2:
39 | yyTerm("nil");
40 | yyNoArgs();
41 | break;
42 | }
43 | }
44 | yybroadcast_TKNLIST(t,In,Out,Handler)
45 | yy t, In, *Out; int (*Handler) ();
46 | {
47 | yy A, B;
48 | A = In;
49 | if (! Handler(yybroadcast_TKNLIST, t, In, Out)) {
50 | switch(t[0]) {
51 | case 1:
52 | yybroadcast_TKN((yy)t[1], A, &B, Handler);
53 | yybroadcast_TKNLIST((yy)t[2], B, &A, Handler);
54 | *Out = A;
55 | break;
56 | case 2:
57 | *Out = A;
58 | break;
59 | }
60 | }
61 | }
62 | yyeq_TKN(t1, t2) yy t1, t2;
63 | {
64 | switch(t1[0]) {
65 | case 1: return (t2[0] == 1)
66 | && yyeq_IDENT((yy)t1[1], (yy)t2[1])
67 | && (t1[2] == t2[2])
68 | ;
69 | }
70 | }
71 | yyPrint_TKN(t) yy t;
72 | {
73 | switch(t[0]) {
74 | case 1:
75 | yyTerm("token");
76 | yyFirstArg();
77 | yyPrint_IDENT((yy)t[1]);
78 | yyNextArg();
79 | yyPrint_INT((yy)t[2]);
80 | yyEndArgs();
81 | break;
82 | }
83 | }
84 | yybroadcast_TKN(t,In,Out,Handler)
85 | yy t, In, *Out; int (*Handler) ();
86 | {
87 | yy A, B;
88 | A = In;
89 | if (! Handler(yybroadcast_TKN, t, In, Out)) {
90 | switch(t[0]) {
91 | case 1:
92 | yybroadcast_IDENT((yy)t[1], A, &B, Handler);
93 | *Out = B;
94 | break;
95 | }
96 | }
97 | }
98 | yyeq_LITLIST(t1, t2) yy t1, t2;
99 | {
100 | switch(t1[0]) {
101 | case 1: return (t2[0] == 1)
102 | && yyeq_LIT((yy)t1[1], (yy)t2[1])
103 | && yyeq_LITLIST((yy)t1[2], (yy)t2[2])
104 | ;
105 | case 2: return (t2[0] == 2)
106 | ;
107 | }
108 | }
109 | yyPrint_LITLIST(t) yy t;
110 | {
111 | switch(t[0]) {
112 | case 1:
113 | yyTerm("list");
114 | yyFirstArg();
115 | yyPrint_LIT((yy)t[1]);
116 | yyNextArg();
117 | yyPrint_LITLIST((yy)t[2]);
118 | yyEndArgs();
119 | break;
120 | case 2:
121 | yyTerm("nil");
122 | yyNoArgs();
123 | break;
124 | }
125 | }
126 | yybroadcast_LITLIST(t,In,Out,Handler)
127 | yy t, In, *Out; int (*Handler) ();
128 | {
129 | yy A, B;
130 | A = In;
131 | if (! Handler(yybroadcast_LITLIST, t, In, Out)) {
132 | switch(t[0]) {
133 | case 1:
134 | yybroadcast_LIT((yy)t[1], A, &B, Handler);
135 | yybroadcast_LITLIST((yy)t[2], B, &A, Handler);
136 | *Out = A;
137 | break;
138 | case 2:
139 | *Out = A;
140 | break;
141 | }
142 | }
143 | }
144 | yyeq_LIT(t1, t2) yy t1, t2;
145 | {
146 | switch(t1[0]) {
147 | case 1: return (t2[0] == 1)
148 | &&(strcmp((char *) t1[1], (char *) t2[1]) == 0)
149 | && (t1[2] == t2[2])
150 | ;
151 | }
152 | }
153 | yyPrint_LIT(t) yy t;
154 | {
155 | switch(t[0]) {
156 | case 1:
157 | yyTerm("literal");
158 | yyFirstArg();
159 | yyPrint_STRING((yy)t[1]);
160 | yyNextArg();
161 | yyPrint_INT((yy)t[2]);
162 | yyEndArgs();
163 | break;
164 | }
165 | }
166 | yybroadcast_LIT(t,In,Out,Handler)
167 | yy t, In, *Out; int (*Handler) ();
168 | {
169 | yy A, B;
170 | A = In;
171 | if (! Handler(yybroadcast_LIT, t, In, Out)) {
172 | switch(t[0]) {
173 | case 1:
174 | *Out = A;
175 | break;
176 | }
177 | }
178 | }
179 | init_lexinfo()
180 | {
181 | {
182 | yy yyb;
183 | yy yy_1;
184 | yy yy_2;
185 | yyb = yyh;
186 | yyh += 2; if (yyh > yyhx) yyExtend();
187 | yy_1 = yyb + 0;
188 | yy_1[0] = 2;
189 | yyglov_Tokens = yy_1;
190 | yy_2 = yyb + 1;
191 | yy_2[0] = 2;
192 | yyglov_Literals = yy_2;
193 | return;
194 | }
195 | }
196 | enter_token(yyin_1, yyin_2)
197 | yy yyin_1;
198 | yy yyin_2;
199 | {
200 | {
201 | yy yyb;
202 | yy yyv_Id;
203 | yy yy_0_1;
204 | yy yyv_N;
205 | yy yy_0_2;
206 | yy yyv_L;
207 | yy yy_1;
208 | yy yy_2;
209 | yy yy_2_1;
210 | yy yy_2_1_1;
211 | yy yy_2_1_2;
212 | yy yy_2_2;
213 | yy_0_1 = yyin_1;
214 | yy_0_2 = yyin_2;
215 | yyv_Id = yy_0_1;
216 | yyv_N = yy_0_2;
217 | yyb = yyh;
218 | yyh += 6; if (yyh > yyhx) yyExtend();
219 | yy_1 = yyglov_Tokens;
220 | if (yy_1 == (yy) yyu) yyErr(1,59);
221 | yyv_L = yy_1;
222 | yy_2_1_1 = yyv_Id;
223 | yy_2_1_2 = yyv_N;
224 | yy_2_1 = yyb + 3;
225 | yy_2_1[0] = 1;
226 | yy_2_1[1] = ((long)yy_2_1_1);
227 | yy_2_1[2] = ((long)yy_2_1_2);
228 | yy_2_2 = yyv_L;
229 | yy_2 = yyb + 0;
230 | yy_2[0] = 1;
231 | yy_2[1] = ((long)yy_2_1);
232 | yy_2[2] = ((long)yy_2_2);
233 | yyglov_Tokens = yy_2;
234 | return;
235 | }
236 | }
237 | enter_literal(yyin_1, yyin_2)
238 | yy yyin_1;
239 | yy yyin_2;
240 | {
241 | {
242 | yy yyb;
243 | yy yyv_Str;
244 | yy yy_0_1;
245 | yy yyv_N;
246 | yy yy_0_2;
247 | yy yyv_L;
248 | yy yy_1;
249 | yy yy_2;
250 | yy yy_2_1;
251 | yy yy_2_1_1;
252 | yy yy_2_1_2;
253 | yy yy_2_2;
254 | yy_0_1 = yyin_1;
255 | yy_0_2 = yyin_2;
256 | yyv_Str = yy_0_1;
257 | yyv_N = yy_0_2;
258 | yyb = yyh;
259 | yyh += 6; if (yyh > yyhx) yyExtend();
260 | yy_1 = yyglov_Literals;
261 | if (yy_1 == (yy) yyu) yyErr(1,64);
262 | yyv_L = yy_1;
263 | yy_2_1_1 = yyv_Str;
264 | yy_2_1_2 = yyv_N;
265 | yy_2_1 = yyb + 3;
266 | yy_2_1[0] = 1;
267 | yy_2_1[1] = ((long)yy_2_1_1);
268 | yy_2_1[2] = ((long)yy_2_1_2);
269 | yy_2_2 = yyv_L;
270 | yy_2 = yyb + 0;
271 | yy_2[0] = 1;
272 | yy_2[1] = ((long)yy_2_1);
273 | yy_2[2] = ((long)yy_2_2);
274 | yyglov_Literals = yy_2;
275 | return;
276 | }
277 | }
278 | lexinfo()
279 | {
280 | {
281 | yy yyb;
282 | yy yy_1_1;
283 | yy yy_2_1;
284 | yy yy_4_1;
285 | yy yy_6_1;
286 | yy yy_8_1;
287 | yy yy_10_1;
288 | yy yyv_TL;
289 | yy yy_13;
290 | yy yy_14_1_1;
291 | yy yy_14_1_2;
292 | yy yyv_Head;
293 | yy yy_14_1_2_1;
294 | yy yyv_Tail;
295 | yy yy_14_1_2_2;
296 | yy yy_14_2_1;
297 | yy yy_14_2_2;
298 | yy yyv_Id;
299 | yy yy_14_2_2_1;
300 | yy yyv_N;
301 | yy yy_14_2_2_2;
302 | yy yy_14_3_1;
303 | yy yyv_Str;
304 | yy yy_14_3_2;
305 | yy yy_14_4_1;
306 | yy yy_14_5_1;
307 | yy yy_14_6_1;
308 | yy yy_14_7_1;
309 | yy yy_14_9_1;
310 | yy yy_14_9_2;
311 | yy yyv_LL;
312 | yy yy_15;
313 | yy yy_16_1_1;
314 | yy yy_16_1_2;
315 | yy yy_16_1_2_1;
316 | yy yy_16_1_2_2;
317 | yy yy_16_2_1;
318 | yy yy_16_2_2;
319 | yy yy_16_2_2_1;
320 | yy yy_16_2_2_2;
321 | yy yy_16_3_1;
322 | yy yy_16_4_1;
323 | yy yy_16_5_1;
324 | yy yy_16_6_1;
325 | yy yy_16_8_1;
326 | yy yy_16_8_2;
327 | GetDestHeaderFileName(&yy_1_1);
328 | OpenOutput(yy_1_1);
329 | yy_2_1 = ((yy)"#ifndef YYSTYPE");
330 | Put(yy_2_1);
331 | Nl();
332 | yy_4_1 = ((yy)"#define YYSTYPE long");
333 | Put(yy_4_1);
334 | Nl();
335 | yy_6_1 = ((yy)"#endif");
336 | Put(yy_6_1);
337 | Nl();
338 | yy_8_1 = ((yy)"extern YYSTYPE yylval;");
339 | Put(yy_8_1);
340 | Nl();
341 | yy_10_1 = ((yy)"extern long yypos;");
342 | Put(yy_10_1);
343 | Nl();
344 | Nl();
345 | yy_13 = yyglov_Tokens;
346 | if (yy_13 == (yy) yyu) yyErr(1,78);
347 | yyv_TL = yy_13;
348 | yysl_10_1_14 : ;
349 | yy_14_1_1 = yyv_TL;
350 | yy_14_1_2 = yy_14_1_1;
351 | if (yy_14_1_2[0] != 1) goto yyfl_10_1_14;
352 | yy_14_1_2_1 = ((yy)yy_14_1_2[1]);
353 | yy_14_1_2_2 = ((yy)yy_14_1_2[2]);
354 | yyv_Head = yy_14_1_2_1;
355 | yyv_Tail = yy_14_1_2_2;
356 | yy_14_2_1 = yyv_Head;
357 | yy_14_2_2 = yy_14_2_1;
358 | if (yy_14_2_2[0] != 1) goto yyfl_10_1_14;
359 | yy_14_2_2_1 = ((yy)yy_14_2_2[1]);
360 | yy_14_2_2_2 = ((yy)yy_14_2_2[2]);
361 | yyv_Id = yy_14_2_2_1;
362 | yyv_N = yy_14_2_2_2;
363 | yy_14_3_1 = yyv_Id;
364 | id_to_string(yy_14_3_1, &yy_14_3_2);
365 | yyv_Str = yy_14_3_2;
366 | yy_14_4_1 = ((yy)"#define ");
367 | Put(yy_14_4_1);
368 | yy_14_5_1 = yyv_Str;
369 | Put(yy_14_5_1);
370 | yy_14_6_1 = ((yy)" ");
371 | Put(yy_14_6_1);
372 | yy_14_7_1 = yyv_N;
373 | PutI(yy_14_7_1);
374 | Nl();
375 | yy_14_9_1 = yyv_Tail;
376 | yyv_TL = yy_14_9_1;
377 | goto yysl_10_1_14;
378 | yyfl_10_1_14 : ;
379 | yy_15 = yyglov_Literals;
380 | if (yy_15 == (yy) yyu) yyErr(1,91);
381 | yyv_LL = yy_15;
382 | yysl_10_1_16 : ;
383 | yy_16_1_1 = yyv_LL;
384 | yy_16_1_2 = yy_16_1_1;
385 | if (yy_16_1_2[0] != 1) goto yyfl_10_1_16;
386 | yy_16_1_2_1 = ((yy)yy_16_1_2[1]);
387 | yy_16_1_2_2 = ((yy)yy_16_1_2[2]);
388 | yyv_Head = yy_16_1_2_1;
389 | yyv_Tail = yy_16_1_2_2;
390 | yy_16_2_1 = yyv_Head;
391 | yy_16_2_2 = yy_16_2_1;
392 | if (yy_16_2_2[0] != 1) goto yyfl_10_1_16;
393 | yy_16_2_2_1 = ((yy)yy_16_2_2[1]);
394 | yy_16_2_2_2 = ((yy)yy_16_2_2[2]);
395 | yyv_Str = yy_16_2_2_1;
396 | yyv_N = yy_16_2_2_2;
397 | yy_16_3_1 = ((yy)"#define yytoken_");
398 | Put(yy_16_3_1);
399 | yy_16_4_1 = yyv_N;
400 | PutI(yy_16_4_1);
401 | yy_16_5_1 = ((yy)" ");
402 | Put(yy_16_5_1);
403 | yy_16_6_1 = yyv_N;
404 | PutI(yy_16_6_1);
405 | Nl();
406 | yy_16_8_1 = yyv_Tail;
407 | yyv_LL = yy_16_8_1;
408 | goto yysl_10_1_16;
409 | yyfl_10_1_16 : ;
410 | CloseOutput();
411 | return;
412 | }
413 | }
414 | lex_printnames()
415 | {
416 | {
417 | yy yyb;
418 | yy yyv_TL;
419 | yy yy_1;
420 | yy yy_2_1_1;
421 | yy yy_2_1_2;
422 | yy yyv_Head;
423 | yy yy_2_1_2_1;
424 | yy yyv_Tail;
425 | yy yy_2_1_2_2;
426 | yy yy_2_2_1;
427 | yy yy_2_2_2;
428 | yy yyv_Id;
429 | yy yy_2_2_2_1;
430 | yy yyv_N;
431 | yy yy_2_2_2_2;
432 | yy yy_2_3_1;
433 | yy yy_2_4_1;
434 | yy yy_2_5_1;
435 | yy yy_2_6_1;
436 | yy yyv_Str;
437 | yy yy_2_6_2;
438 | yy yy_2_7_1;
439 | yy yy_2_8_1;
440 | yy yy_2_10_1;
441 | yy yy_2_10_2;
442 | yy yyv_LL;
443 | yy yy_3;
444 | yy yy_4_1_1;
445 | yy yy_4_1_2;
446 | yy yy_4_1_2_1;
447 | yy yy_4_1_2_2;
448 | yy yy_4_2_1;
449 | yy yy_4_2_2;
450 | yy yy_4_2_2_1;
451 | yy yy_4_2_2_2;
452 | yy yy_4_3_1;
453 | yy yy_4_4_1;
454 | yy yy_4_5_1;
455 | yy yy_4_6_1;
456 | yy yy_4_7_1;
457 | yy yy_4_9_1;
458 | yy yy_4_9_2;
459 | yy_1 = yyglov_Tokens;
460 | if (yy_1 == (yy) yyu) yyErr(1,110);
461 | yyv_TL = yy_1;
462 | yysl_11_1_2 : ;
463 | yy_2_1_1 = yyv_TL;
464 | yy_2_1_2 = yy_2_1_1;
465 | if (yy_2_1_2[0] != 1) goto yyfl_11_1_2;
466 | yy_2_1_2_1 = ((yy)yy_2_1_2[1]);
467 | yy_2_1_2_2 = ((yy)yy_2_1_2[2]);
468 | yyv_Head = yy_2_1_2_1;
469 | yyv_Tail = yy_2_1_2_2;
470 | yy_2_2_1 = yyv_Head;
471 | yy_2_2_2 = yy_2_2_1;
472 | if (yy_2_2_2[0] != 1) goto yyfl_11_1_2;
473 | yy_2_2_2_1 = ((yy)yy_2_2_2[1]);
474 | yy_2_2_2_2 = ((yy)yy_2_2_2[2]);
475 | yyv_Id = yy_2_2_2_1;
476 | yyv_N = yy_2_2_2_2;
477 | yy_2_3_1 = ((yy)" case ");
478 | Put(yy_2_3_1);
479 | yy_2_4_1 = yyv_N;
480 | PutI(yy_2_4_1);
481 | yy_2_5_1 = ((yy)": return \"");
482 | Put(yy_2_5_1);
483 | yy_2_6_1 = yyv_Id;
484 | id_to_string(yy_2_6_1, &yy_2_6_2);
485 | yyv_Str = yy_2_6_2;
486 | yy_2_7_1 = yyv_Str;
487 | Put(yy_2_7_1);
488 | yy_2_8_1 = ((yy)"\"; break;");
489 | Put(yy_2_8_1);
490 | Nl();
491 | yy_2_10_1 = yyv_Tail;
492 | yyv_TL = yy_2_10_1;
493 | goto yysl_11_1_2;
494 | yyfl_11_1_2 : ;
495 | yy_3 = yyglov_Literals;
496 | if (yy_3 == (yy) yyu) yyErr(1,124);
497 | yyv_LL = yy_3;
498 | yysl_11_1_4 : ;
499 | yy_4_1_1 = yyv_LL;
500 | yy_4_1_2 = yy_4_1_1;
501 | if (yy_4_1_2[0] != 1) goto yyfl_11_1_4;
502 | yy_4_1_2_1 = ((yy)yy_4_1_2[1]);
503 | yy_4_1_2_2 = ((yy)yy_4_1_2[2]);
504 | yyv_Head = yy_4_1_2_1;
505 | yyv_Tail = yy_4_1_2_2;
506 | yy_4_2_1 = yyv_Head;
507 | yy_4_2_2 = yy_4_2_1;
508 | if (yy_4_2_2[0] != 1) goto yyfl_11_1_4;
509 | yy_4_2_2_1 = ((yy)yy_4_2_2[1]);
510 | yy_4_2_2_2 = ((yy)yy_4_2_2[2]);
511 | yyv_Str = yy_4_2_2_1;
512 | yyv_N = yy_4_2_2_2;
513 | yy_4_3_1 = ((yy)" case ");
514 | Put(yy_4_3_1);
515 | yy_4_4_1 = yyv_N;
516 | PutI(yy_4_4_1);
517 | yy_4_5_1 = ((yy)": return \"");
518 | Put(yy_4_5_1);
519 | yy_4_6_1 = yyv_Str;
520 | Put(yy_4_6_1);
521 | yy_4_7_1 = ((yy)"\"; break;");
522 | Put(yy_4_7_1);
523 | Nl();
524 | yy_4_9_1 = yyv_Tail;
525 | yyv_LL = yy_4_9_1;
526 | goto yysl_11_1_4;
527 | yyfl_11_1_4 : ;
528 | return;
529 | }
530 | }
531 |
--------------------------------------------------------------------------------
/modaccent/src/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ACCENT
3 | *
4 | * A Compiler Compiler for the Entire Class of Context-Free Languages
5 | *
6 | * Copyright (C) 1999 Friedrich Wilhelm Schroeer
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 | */
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | extern FILE *yyin;
29 |
30 | char *SourceFileName = NULL;
31 | char *cOutFileName = NULL;
32 | char *hOutFileName = NULL;
33 |
34 | void main (int argc, char **argv) {
35 | size_t outSize = 0;
36 | char cOutName[] = "yygram.cpp";
37 | char hOutName[] = "yygram.h";
38 |
39 | if (argc > 4) {
40 | printf("too many arguments\n");
41 | exit(1);
42 | }
43 |
44 | SourceFileName = NULL;
45 |
46 | if (argc >= 2) {
47 | size_t i;
48 | SourceFileName = argv[1];
49 | yyin = fopen (SourceFileName, "r");
50 | if (yyin == NULL) {
51 | printf("cannot open '%s'\n", SourceFileName);
52 | exit(1);
53 | }
54 | for (i = 0; i < strlen(SourceFileName); i++) {
55 | if (SourceFileName[i] == '\\')
56 | SourceFileName[i] = '/';
57 | }
58 | }
59 |
60 | if (argc >= 3) {
61 | size_t i, n = strlen(argv[2]) + strlen(cOutName) + 10;
62 | cOutFileName = (char *)alloca(n);
63 | strncpy(cOutFileName, argv[2], n);
64 | for (i = 0; i < n; i++) {
65 | if (cOutFileName [i] == '\\') /* Switch chars. */
66 | cOutFileName [i] = '/';
67 | }
68 | if (cOutFileName[strlen(argv[2])-1] != '/')
69 | strncat(cOutFileName, "/",1);
70 | strncat(cOutFileName, cOutName, strlen(cOutName));
71 | }
72 |
73 | if (argc >= 4) {
74 | size_t i, n = strlen(argv[3]) + strlen(hOutName) + 10;
75 | hOutFileName = (char *)alloca(n);
76 | strncpy(hOutFileName, argv[3], n);
77 | for (i = 0; i < n; i++) {
78 | if (hOutFileName [i] == '\\') /* Switch chars. */
79 | hOutFileName [i] = '/';
80 | }
81 | if (hOutFileName[strlen(argv[3])-1] != '/')
82 | strncat(hOutFileName, "/",1);
83 | strncat(hOutFileName, hOutName, strlen(hOutName));
84 | }
85 |
86 | ROOT();
87 |
88 | exit(0);
89 | }
90 |
91 | GetSourceFileName(ref_string)
92 | char **ref_string;
93 | {
94 | *ref_string = SourceFileName;
95 | }
96 |
97 | GetDestCodeFileName(char **ref_string) {
98 | *ref_string = cOutFileName;
99 | }
100 |
101 | GetDestHeaderFileName(char **ref_string) {
102 | *ref_string = hOutFileName;
103 | }
104 |
--------------------------------------------------------------------------------
/modaccent/src/output.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ACCENT
3 | *
4 | * A Compiler Compiler for the Entire Class of Context-Free Languages
5 | *
6 | * Copyright (C) 1999 Friedrich Wilhelm Schroeer
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 | */
22 |
23 |
24 | #define PRIVATE static
25 |
26 | #include
27 |
28 | /*--------------------------------------------------------------------*/
29 |
30 | #define OutBufSize 6000
31 | #define FlushPos 5000
32 |
33 | /*--------------------------------------------------------------------*/
34 |
35 | PRIVATE long OutputLineCount = 0;
36 |
37 | PRIVATE char OutBuf[OutBufSize];
38 | PRIVATE char *OutBufPtr;
39 | PRIVATE FILE *OutFile;
40 |
41 | /*--------------------------------------------------------------------*/
42 |
43 | OpenOutput (Name)
44 | char *Name;
45 | {
46 | OutFile = fopen(Name, "w");
47 |
48 | if (OutFile == NULL) {
49 | printf("cannot open %s\n", Name); exit(1);
50 | }
51 | OutBufPtr = &OutBuf[0];
52 | OutputLineCount = 0;
53 | return 1;
54 | }
55 |
56 | /*--------------------------------------------------------------------*/
57 | CloseOutput ()
58 | {
59 | fwrite(OutBuf, 1, OutBufPtr - &OutBuf[0], OutFile);
60 | fclose(OutFile);
61 | }
62 |
63 | /*--------------------------------------------------------------------*/
64 | Put(Str)
65 | char *Str;
66 | {
67 | while(*Str) *OutBufPtr++ = *Str++;
68 | }
69 |
70 | /*--------------------------------------------------------------------*/
71 | PutBlockText(Str)
72 | char *Str;
73 | {
74 | while(*Str) {
75 | if (*Str == '\n') {
76 | Nl();
77 | Str++;
78 | }
79 | else
80 | *OutBufPtr++ = *Str++;
81 | }
82 | }
83 |
84 | /*--------------------------------------------------------------------*/
85 | PutI (N)
86 | long N;
87 | {
88 | if (N < 0) {
89 | *OutBufPtr++ = '-';
90 | N = -N;
91 | }
92 | if (N < 10) {
93 | *OutBufPtr++ = N + '0';
94 | }
95 | else if (N < 100) {
96 | *OutBufPtr++ = N/10 + '0';
97 | *OutBufPtr++ = N%10 + '0';
98 | }
99 | else {
100 | char buf[50];
101 | register i;
102 | register n = N;
103 |
104 | i = 0;
105 |
106 | do {
107 | buf[++i] = (n % 10) + '0';
108 | n = n / 10;
109 | } while (n);
110 |
111 | while (i)
112 | *OutBufPtr++ = buf[i--];
113 | }
114 | }
115 |
116 | /*--------------------------------------------------------------------*/
117 | Nl ()
118 | {
119 | if (OutBufPtr > &OutBuf[FlushPos]) {
120 | fwrite(OutBuf, 1, OutBufPtr - &OutBuf[0], OutFile);
121 | OutBufPtr = &OutBuf[0];
122 | }
123 |
124 | #ifdef EMIT_CR
125 | *OutBufPtr++ = '\r';
126 | #endif
127 | *OutBufPtr++ = '\n';
128 | OutputLineCount++;
129 | }
130 |
131 | /*--------------------------------------------------------------------*/
132 |
133 | GetOutputLineCount(ref_n)
134 | int * ref_n;
135 | {
136 | *ref_n = OutputLineCount;
137 | }
138 |
139 | /*--------------------------------------------------------------------*/
140 |
--------------------------------------------------------------------------------
/modaccent/src/sets.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ACCENT
3 | *
4 | * A Compiler Compiler for the Entire Class of Context-Free Languages
5 | *
6 | * Copyright (C) 1999 Friedrich Wilhelm Schroeer
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 | */
22 |
23 |
24 | /*
25 | * sets.c
26 | */
27 |
28 | #include
29 | #include
30 | #include
31 |
32 | #include "sets.h"
33 |
34 | #define PUBLIC
35 | #define PRIVATE static
36 |
37 | struct SET {
38 | int head;
39 | set tail;
40 | };
41 |
42 | PUBLIC int changed;
43 |
44 | PUBLIC void print_set(s)
45 | set s;
46 | {
47 | set p;
48 |
49 | p = s;
50 | printf("{");
51 | while (p) {
52 | printf(" %d", p->head);
53 | p = p->tail;
54 | }
55 | printf(" }");
56 | }
57 |
58 | PUBLIC void emit_set(s)
59 | set s;
60 | {
61 | set p;
62 |
63 | p = s;
64 | Put("{");
65 | while (p) {
66 | extern TokenNumberToString();
67 | char *str;
68 | Put(" ");
69 | TokenNumberToString(p->head, &str);
70 | Put("'");
71 | Put(str);
72 | Put("'");
73 | p = p->tail;
74 | }
75 | Put(" }");
76 | }
77 |
78 | PUBLIC void write_set(n, s)
79 | int n;
80 | set s;
81 | {
82 | set p;
83 |
84 | p = s;
85 | while (p) {
86 | Put("TABLE[");
87 | PutI(n);
88 | Put("][");
89 | PutI(p->head);
90 | Put("] = 1;");
91 | Nl();
92 | p = p->tail;
93 | }
94 | }
95 |
96 | PUBLIC set empty_set ()
97 | {
98 | return 0;
99 | }
100 |
101 | PUBLIC void into_set_include_elem (ref_s, e)
102 | set *ref_s;
103 | int e;
104 | {
105 | set p;
106 |
107 | /*
108 | print_set(*ref_s);
109 | printf(" + %d\n", e);
110 | */
111 |
112 | p = *ref_s;
113 | while(p) {
114 | if (p->head == e) return;
115 | p = p->tail;
116 | }
117 |
118 | p = (set) malloc (sizeof (struct SET));
119 | if (! p) {
120 | printf("running out of memory\n");
121 | exit(1);
122 | }
123 | p->head = e;
124 | p->tail = *ref_s;
125 | *ref_s = p;
126 |
127 | changed = 1;
128 | }
129 |
130 | PUBLIC void into_set_include_set (ref_s, x)
131 | set *ref_s, x;
132 | {
133 | set p;
134 | p = x;
135 | while(p) {
136 | into_set_include_elem(ref_s, p->head);
137 | p = p->tail;
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/modaccent/src/strings.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ACCENT
3 | *
4 | * A Compiler Compiler for the Entire Class of Context-Free Languages
5 | *
6 | * Copyright (C) 1999 Friedrich Wilhelm Schroeer
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 | */
22 |
23 |
24 | #define PRIVATE static
25 |
26 | /*--------------------------------------------------------------------*/
27 |
28 | PRIVATE int initialized = 0;
29 |
30 | PRIVATE char *p; /* points to first free position of current buffer */
31 | PRIVATE char *first; /* points to first char of current string */
32 | PRIVATE char *start; /* points to first position of current buffer */
33 | PRIVATE char *stop; /* points to position after last char of current buffer */
34 |
35 | PRIVATE long SIZE = 500;
36 |
37 | #define INCR 500
38 |
39 | /*--------------------------------------------------------------------*/
40 |
41 | PRIVATE Allocate ()
42 | {
43 | p = (char *) malloc (SIZE);
44 | if (p == 0) {
45 | printf("memory allocation failed\n");
46 | exit(1);
47 | }
48 | first = p;
49 | start = p;
50 | stop = p+SIZE;
51 | }
52 |
53 | /*--------------------------------------------------------------------*/
54 |
55 | PRIVATE Initialize()
56 | {
57 | Allocate();
58 | initialized = 1;
59 | }
60 |
61 | /*--------------------------------------------------------------------*/
62 | AppendToString (ch)
63 | char ch;
64 | {
65 | if ( ! initialized) Initialize();
66 |
67 | if (p == stop) { /* buffer full */
68 | char *q;
69 | char *qfirst = first;
70 | char *qstop = stop;
71 |
72 | if (first == start) SIZE += INCR;
73 |
74 | Allocate();
75 | for (q = qfirst; q != qstop; q++) {
76 | *p++ = *q;
77 | }
78 | }
79 | *p++ = ch;
80 | }
81 |
82 | /*--------------------------------------------------------------------*/
83 | GetStringRef(ref_string)
84 | char **ref_string;
85 | {
86 | if ( ! initialized) Initialize();
87 | AppendToString(0);
88 | *ref_string = first;
89 | first = p;
90 | }
91 |
92 | /*--------------------------------------------------------------------*/
93 |
94 |
--------------------------------------------------------------------------------
/src/CalcVal.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/src/CalcVal.cpp
--------------------------------------------------------------------------------
/src/Djikstra.cpp:
--------------------------------------------------------------------------------
1 | /* DJIKSTRA.CPP -- See the Incursion LICENSE file for copyright information.
2 |
3 | An implementation of Djikstra's algorithm used for the
4 | running code, but available for any other (AI?) purposes
5 | that it might be needed as well.
6 |
7 | void Map::PQInsert(uint16 Node, int16 Weight)
8 | int32 Map::PQPeekMin()
9 | bool Map::PQPopMin()
10 | bool Map::ShortestPath(uint8 sx, uint8 sy, uint8 tx, uint8 ty)
11 | uint16 Map::PathPoint(int16 n)
12 | bool Map::RunOver(uint8 x, uint8 y)
13 |
14 | */
15 |
16 | #include "Incursion.h"
17 |
18 |
19 | struct PQueue
20 | {
21 | int16 Weight;
22 | NArray Elements;
23 | PQueue *Next;
24 | PQueue(uint16 FirstNode, int16 _Weight)
25 | { Next = NULL;
26 | Weight = Weight;
27 | Elements.Set(FirstNode,0); }
28 | };
29 |
30 | PQueue *PHead;
31 |
32 | uint16 ThePath[MAX_PATH_LENGTH];
33 |
34 | void Map::PQInsert(uint16 Node, int16 Weight)
35 | {
36 | PQueue *pq, *pq2;
37 | if (PHead == NULL || PHead->Weight > Weight)
38 | {
39 | PHead = new PQueue(Node, Weight);
40 | return;
41 | }
42 |
43 | for(pq = PHead; pq->Next && pq->Next->Weight < Weight; pq = pq->Next)
44 | ;
45 |
46 | if (pq->Weight == Weight)
47 | {
48 | pq->Elements.Add(Node);
49 | return;
50 | }
51 | pq2 = new PQueue(Node, Weight);
52 | pq2->Next = pq->Next;
53 | pq->Next = pq2;
54 |
55 | return;
56 | }
57 |
58 | int32 Map::PQPeekMin()
59 | {
60 | if (!PHead)
61 | return -1;
62 | if (PHead->Elements.Total() == 0)
63 | return -1;
64 | return PHead->Elements[0];
65 | }
66 |
67 | bool Map::PQPopMin()
68 | {
69 | PQueue *pq;
70 | if (PQPeekMin() == -1)
71 | return false;
72 |
73 | /* Remove the node from the first stack */
74 | PHead->Elements.Remove(0);
75 |
76 | /* Remove the stack if it's empty */
77 | if (PHead->Elements.Total() == 0)
78 | {
79 | pq = PHead;
80 | PHead = PHead->Next;
81 | delete pq;
82 | }
83 | return true;
84 | }
85 |
86 |
87 | bool Map::ShortestPath(uint8 sx, uint8 sy, uint8 tx, uint8 ty,
88 | Creature *runner, int32 dangerFactor,
89 | uint16 *ThePath)
90 | {
91 | int32 xy, i, c; int16 x, y, nx, ny;
92 | static int16 Dist[256][256];
93 | static uint16 Parent[256][256];
94 |
95 | if (!ThePath)
96 | ThePath = ::ThePath;
97 |
98 | ASSERT(InBounds(sx,sy))
99 | ASSERT(InBounds(tx,ty))
100 | PHead = NULL;
101 |
102 | bool Incor =
103 | runner->HasMFlag(M_INCOR) ||
104 | runner->HasStati(PHASED);
105 | bool Meld =
106 | runner->HasAbility(CA_EARTHMELD);
107 |
108 | for (x=0;x!=256;x++)
109 | for(y=0;y!=256;y++)
110 | {
111 | Dist[x][y] = 30000;
112 | Parent[x][y] = 0;
113 | }
114 |
115 | Dist[sx][sy] = 0;
116 |
117 | PQInsert(sx+sy*256,0);
118 |
119 | while ((xy = PQPeekMin()) != -1)
120 | {
121 | PQPopMin();
122 | x = (int16)(xy % 256);
123 | y = (int16)(xy / 256);
124 |
125 | for (i=0;i!=8;i++) {
126 | nx = x + DirX[i];
127 | ny = y + DirY[i];
128 | /* KLUDGE: We consider (0,0) to be offmap so that we can use
129 | node 0 as a special empty/unmarked value. */
130 | if (nx == 0 && ny == 0)
131 | continue;
132 | if (!InBounds(nx,ny))
133 | continue;
134 | int baseCost = RunOver(nx&0xFF,ny&0xFF,true,runner,dangerFactor,Incor,Meld);
135 | if (!baseCost)
136 | continue;
137 | if (DirX[i] && DirY[i])
138 | baseCost = (baseCost * 3) / 2;
139 |
140 | if (Dist[x][y] + baseCost < Dist[nx][ny])
141 | {
142 | Dist[nx][ny] = std::min(30000,Dist[x][y] + baseCost);
143 | Parent[nx][ny] = x+y*256;
144 | PQInsert(nx+ny*256,Dist[nx][ny]);
145 | }
146 | }
147 | }
148 |
149 | x = tx;
150 | y = ty;
151 | c = 0;
152 |
153 | if (Dist[tx][ty] == 30000) {
154 | #ifdef DEBUG_DJIKSTRA
155 | for (x = std::min(0,sx-30);x!=std::max(127,sx+30);x++)
156 | for (y = std::min(0,sx-30);y!=std::max(127,sy+30);y++)
157 | if (Dist[x][y] != 30000)
158 | {
159 | At(x,y).Glyph =
160 | GLYPH_VALUE(GLYPH_FLOOR2, EMERALD);
161 | At(x,y).Memory =
162 | GLYPH_VALUE(GLYPH_FLOOR2, EMERALD);
163 | At(x,y).Shade = false;
164 | }
165 | #endif
166 | return false;
167 | }
168 |
169 | do {
170 | c++;
171 | xy = Parent[x][y];
172 | x = (int16)(xy % 256);
173 | y = (int16)(xy / 256);
174 | }
175 | while (xy);
176 |
177 | x = tx;
178 | y = ty;
179 | i = 0; c--;
180 | do {
181 | ThePath[c - i] = x + y*256;
182 | xy = Parent[x][y];
183 | x = (int16)(xy % 256);
184 | y = (int16)(xy / 256);
185 | i++;
186 | }
187 | while (xy);
188 |
189 | ThePath[c+1] = 0;
190 |
191 | #ifdef DEBUG_DJIKSTRA
192 | for (i=0;i==0 || ThePath[i];i++) {
193 | At(ThePath[i]%256,ThePath[i]/256).Glyph =
194 | GLYPH_VALUE(GLYPH_FLOOR2, MAGENTA);
195 | At(ThePath[i]%256,ThePath[i]/256).Memory =
196 | GLYPH_VALUE(GLYPH_FLOOR2, MAGENTA);
197 | At(ThePath[i]%256,ThePath[i]/256).Shade = false;
198 | }
199 | #endif
200 |
201 | return true;
202 |
203 |
204 |
205 | }
206 |
207 | uint16 Map::PathPoint(int16 n)
208 | { return ThePath[n]; }
209 |
210 | uint16 Map::RunOver(uint8 x, uint8 y, bool memonly, Creature *c,
211 | int32 dangerFactor, bool Incor, bool Meld)
212 | {
213 | if (!Incor && SolidAt(x,y)) {
214 | if (Meld) {
215 | int i = TTER(PTerrainAt(x,y,c))->Material;
216 | if (i == MAT_GRANITE || i == MAT_MAGMA || i == MAT_QUARTZ ||
217 | i == MAT_GEMSTONE || i == MAT_MINERAL)
218 | ; // we can walk here
219 | else
220 | return 0;
221 | } else return 0;
222 | }
223 | if (memonly && !At(x,y).Memory)
224 | return 0;
225 | if (At(x,y).Contents) {
226 | Creature *ca; Trap *tr; Door *dr;
227 | for (ca=FCreatureAt(x,y);ca;ca=NCreatureAt(x,y))
228 | if (ca && c->Perceives(ca) && ca->isHostileTo(c))
229 | return 0;
230 | for (tr=FTrapAt(x,y);tr;tr=NTrapAt(x,y)) {
231 | if (tr->TrapFlags & TS_FOUND)
232 | if (!(tr->TrapFlags & TS_DISARMED)) {
233 | if (dangerFactor & DF_IGNORE_TRAPS)
234 | return (sizeX * 3) + (tr->TrapLevel() * 10);
235 | else
236 | return 0;
237 | }
238 | }
239 | for (dr=FDoorAt(x,y);dr;dr=NDoorAt(x,y))
240 | if (!(dr->DoorFlags & DF_OPEN))
241 | return 0;
242 | }
243 | rID stickyID = StickyAt(x,y);
244 | if (stickyID &&
245 | !c->HasStati(STUCK) &&
246 | !c->HasMFlag(M_AMORPH) &&
247 | !c->isAerial() &&
248 | c->onPlane() == PHASE_MATERIAL &&
249 | c->ResistLevel(AD_STUK) != -1 &&
250 | !c->HasAbility(CA_WOODLAND_STRIDE)) {
251 | if (dangerFactor & DF_IGNORE_TERRAIN)
252 | return (sizeX * 3);
253 | else
254 | return 0;
255 | }
256 |
257 | Feature * f;
258 | for (f=FFeatureAt(x,y);f;f=NFeatureAt(x,y))
259 | if (TFEAT(f->fID)->PEvent(EV_MON_CONSIDER,c,f,f->fID) == ABORT) {
260 | if (dangerFactor & DF_IGNORE_TERRAIN)
261 | return (sizeX * 3);
262 | else
263 | return 0;
264 | }
265 | if (At(x,y).Terrain) {
266 | rID t = PTerrainAt(x,y,c);
267 | if (TTER(t)->HasFlag(TF_WARN)) {
268 | if (TTER(t)->PEvent(EV_MON_CONSIDER,c,t) == ABORT) {
269 | if (dangerFactor & DF_IGNORE_TERRAIN)
270 | return (sizeX * 3);
271 | else
272 | return 0;
273 | }
274 | }
275 | if (TTER(t)->MoveMod)
276 | return 4;
277 | else
278 | return 2;
279 | }
280 | return 2;
281 | }
282 |
--------------------------------------------------------------------------------
/src/OverGen.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/src/OverGen.cpp
--------------------------------------------------------------------------------
/src/Overland.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/src/Overland.cpp
--------------------------------------------------------------------------------
/src/Quest.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rmtew/incursion-roguelike/2fe9808de59e9bfd6d81c256589541463fc61007/src/Quest.cpp
--------------------------------------------------------------------------------
/src/cpp3.c:
--------------------------------------------------------------------------------
1 | /*
2 | * C P P 3 . C
3 | *
4 | * File open and command line options
5 | *
6 | * Edit history
7 | * 13-Nov-84 MM Split from cpp1.c
8 | */
9 | #undef DEBUG
10 | #include
11 | #include
12 | #include "cppdef.h"
13 | #include "cpp.h"
14 | #if DEBUG && (HOST == SYS_VMS || HOST == SYS_UNIX)
15 | #include
16 | extern int abort(); /* For debugging */
17 | #endif
18 |
19 | int
20 | openfile(filename)
21 | char *filename;
22 | /*
23 | * Open a file, add it to the linked list of open files.
24 | * This is called only from openfile() above.
25 | */
26 | {
27 | register FILE *fp;
28 |
29 | if ((fp = fopen(filename, "r")) == NULL) {
30 | #if DEBUG
31 | perror(filename);
32 | #endif
33 | return (FALSE);
34 | }
35 | addfile(fp, filename);
36 | return (TRUE);
37 | }
38 |
39 | addfile(fp, filename)
40 | FILE *fp; /* Open file pointer */
41 | char *filename; /* Name of the file */
42 | /*
43 | * Initialize tables for this open file. This is called from openfile()
44 | * above (for #include files), and from the entry to cpp to open the main
45 | * input file. It calls a common routine, getfile() to build the FILEINFO
46 | * structure which is used to read characters. (getfile() is also called
47 | * to setup a macro replacement.)
48 | */
49 | {
50 | register FILEINFO *file;
51 | extern FILEINFO *getfile();
52 |
53 | file = getfile(NBUFF, filename);
54 | file->fp = fp; /* Better remember FILE * */
55 | file->buffer[0] = EOS; /* Initialize for first read */
56 | c_line = 1; /* Working on line 1 now */
57 | wrongline = TRUE; /* Force out initial #line */
58 | }
59 |
60 | setincdirs()
61 | /*
62 | * Append system-specific directories to the include directory list.
63 | * Called only when cpp is started.
64 | */
65 | {
66 | *incend++ = "../inc";
67 | *incend++ = "../lib";
68 | *incend++ = "./inc";
69 | *incend++ = "./lib";
70 | }
71 |
72 |
73 | initdefines()
74 | /*
75 | * Initialize the built-in #define's. There are two flavors:
76 | * #define decus 1 (static definitions)
77 | * #define __FILE__ ?? (dynamic, evaluated by magic)
78 | * Called only on cpp startup.
79 | *
80 | * Note: the built-in static definitions are supressed by the -N option.
81 | * __LINE__, __FILE__, and __DATE__ are always present.
82 | */
83 | {
84 | register char **pp;
85 | register char *tp;
86 | register DEFBUF *dp;
87 | int i;
88 | long tvec;
89 | extern char *ctime();
90 |
91 | /*
92 | * Predefine the built-in symbols. Allow the
93 | * implementor to pre-define a symbol as "" to
94 | * eliminate it.
95 | */
96 | if (nflag == 0) {
97 | for (pp = preset; *pp != NULL; pp++) {
98 | if (*pp[0] != EOS) {
99 | dp = defendel(*pp, FALSE);
100 | dp->repl = savestring("1");
101 | dp->nargs = DEF_NOARGS;
102 | }
103 | }
104 | }
105 | /*
106 | * The magic pre-defines (__FILE__ and __LINE__ are
107 | * initialized with negative argument counts. expand()
108 | * notices this and calls the appropriate routine.
109 | * DEF_NOARGS is one greater than the first "magic" definition.
110 | */
111 | if (nflag < 2) {
112 | for (pp = magic, i = DEF_NOARGS; *pp != NULL; pp++) {
113 | dp = defendel(*pp, FALSE);
114 | dp->nargs = --i;
115 | }
116 | #if OK_DATE
117 | /*
118 | * Define __DATE__ as today's date.
119 | */
120 | dp = defendel("__DATE__", FALSE);
121 | dp->repl = tp = getmem(27);
122 | dp->nargs = DEF_NOARGS;
123 | time(&tvec);
124 | *tp++ = '"';
125 | strcpy(tp, ctime(&tvec));
126 | tp[24] = '"'; /* Overwrite newline */
127 | #endif
128 | }
129 | }
130 |
131 |
132 |
--------------------------------------------------------------------------------
/src/rle.c:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * Name: rle.c
3 | * Author: Marcus Geelnard
4 | * Description: RLE coder/decoder implementation.
5 | * Reentrant: Yes
6 | *
7 | * RLE (Run Length Encoding) is the simplest possible lossless compression
8 | * method. Nevertheless it serves a purpose, even in state of the art
9 | * compression (it is used in JPEG compression, for instance). The basic
10 | * principle is to identify sequences of equal bytes, and replace them with
11 | * the byte in question and a repetition count (coded in some clever
12 | * fashion).
13 | *
14 | * There are several different ways to do RLE. The particular method
15 | * implemented here is a very efficient one. Instead of coding runs for
16 | * both repeating and non-repeating sections, a special marker byte is
17 | * used to indicate the start of a repeating section. Non-repeating
18 | * sections can thus have any length without being interrupted by control
19 | * bytes, except for the rare case when the special marker byte appears in
20 | * the non-repeating section (which is coded with at most two bytes). For
21 | * optimal efficiency, the marker byte is chosen as the least frequent
22 | * (perhaps even non-existent) symbol in the input stream.
23 | *
24 | * Repeating runs can be as long as 32768 bytes. Runs shorter than 129
25 | * bytes require three bytes for coding (marker + count + symbol), whereas
26 | * runs longer than 128 bytes require four bytes for coding (marker +
27 | * counthi|0x80 + countlo + symbol). This is normally a win in compression,
28 | * and it's very seldom a loss of compression ratio compared to using a
29 | * fixed coding of three bytes (which allows coding a run of 256 bytes in
30 | * just three bytes).
31 | *
32 | * With this scheme, the worst case compression result is
33 | * (257/256)*insize + 1.
34 | *
35 | *-------------------------------------------------------------------------
36 | * Note: This code is based on the code found in "codrle2.c" and
37 | * "dcodrle2.c" by David Bourgin, as described in "Introduction to the
38 | * losslessy compression schemes", 1994. The main differences from Davids
39 | * implementation are the addition of long (15-bit) run counts, the removal
40 | * of file I/O (this implementation works solely with preallocated memory
41 | * buffers), and that the code is now 100% reentrant.
42 | *-------------------------------------------------------------------------
43 | * Copyright (c) 2003-2006 Marcus Geelnard
44 | *
45 | * This software is provided 'as-is', without any express or implied
46 | * warranty. In no event will the authors be held liable for any damages
47 | * arising from the use of this software.
48 | *
49 | * Permission is granted to anyone to use this software for any purpose,
50 | * including commercial applications, and to alter it and redistribute it
51 | * freely, subject to the following restrictions:
52 | *
53 | * 1. The origin of this software must not be misrepresented; you must not
54 | * claim that you wrote the original software. If you use this software
55 | * in a product, an acknowledgment in the product documentation would
56 | * be appreciated but is not required.
57 | *
58 | * 2. Altered source versions must be plainly marked as such, and must not
59 | * be misrepresented as being the original software.
60 | *
61 | * 3. This notice may not be removed or altered from any source
62 | * distribution.
63 | *
64 | * Marcus Geelnard
65 | * marcus.geelnard at home.se
66 | *************************************************************************/
67 |
68 |
69 |
70 | /*************************************************************************
71 | * INTERNAL FUNCTIONS *
72 | *************************************************************************/
73 |
74 |
75 | /*************************************************************************
76 | * _RLE_WriteRep() - Encode a repetition of 'symbol' repeated 'count'
77 | * times.
78 | *************************************************************************/
79 |
80 | static void _RLE_WriteRep( unsigned char *out, unsigned int *outpos,
81 | unsigned char marker, unsigned char symbol, unsigned int count )
82 | {
83 | unsigned int i, idx;
84 |
85 | idx = *outpos;
86 | if( count <= 3 )
87 | {
88 | if( symbol == marker )
89 | {
90 | out[ idx ++ ] = marker;
91 | out[ idx ++ ] = count-1;
92 | }
93 | else
94 | {
95 | for( i = 0; i < count; ++ i )
96 | {
97 | out[ idx ++ ] = symbol;
98 | }
99 | }
100 | }
101 | else
102 | {
103 | out[ idx ++ ] = marker;
104 | -- count;
105 | if( count >= 128 )
106 | {
107 | out[ idx ++ ] = (count >> 8) | 0x80;
108 | }
109 | out[ idx ++ ] = count & 0xff;
110 | out[ idx ++ ] = symbol;
111 | }
112 | *outpos = idx;
113 | }
114 |
115 |
116 | /*************************************************************************
117 | * _RLE_WriteNonRep() - Encode a non-repeating symbol, 'symbol'. 'marker'
118 | * is the marker symbol, and special care has to be taken for the case
119 | * when 'symbol' == 'marker'.
120 | *************************************************************************/
121 |
122 | static void _RLE_WriteNonRep( unsigned char *out, unsigned int *outpos,
123 | unsigned char marker, unsigned char symbol )
124 | {
125 | unsigned int idx;
126 |
127 | idx = *outpos;
128 | if( symbol == marker )
129 | {
130 | out[ idx ++ ] = marker;
131 | out[ idx ++ ] = 0;
132 | }
133 | else
134 | {
135 | out[ idx ++ ] = symbol;
136 | }
137 | *outpos = idx;
138 | }
139 |
140 |
141 |
142 | /*************************************************************************
143 | * PUBLIC FUNCTIONS *
144 | *************************************************************************/
145 |
146 |
147 | /*************************************************************************
148 | * RLE_Compress() - Compress a block of data using an RLE coder.
149 | * in - Input (uncompressed) buffer.
150 | * out - Output (compressed) buffer. This buffer must be 0.4% larger
151 | * than the input buffer, plus one byte.
152 | * insize - Number of input bytes.
153 | * The function returns the size of the compressed data.
154 | *************************************************************************/
155 |
156 | int RLE_Compress( unsigned char *in, unsigned char *out,
157 | unsigned int insize )
158 | {
159 | unsigned char byte1, byte2, marker;
160 | unsigned int inpos, outpos, count, i, histogram[ 256 ];
161 |
162 | /* Do we have anything to compress? */
163 | if( insize < 1 )
164 | {
165 | return 0;
166 | }
167 |
168 | /* Create histogram */
169 | for( i = 0; i < 256; ++ i )
170 | {
171 | histogram[ i ] = 0;
172 | }
173 | for( i = 0; i < insize; ++ i )
174 | {
175 | ++ histogram[ in[ i ] ];
176 | }
177 |
178 | /* Find the least common byte, and use it as the repetition marker */
179 | marker = 0;
180 | for( i = 1; i < 256; ++ i )
181 | {
182 | if( histogram[ i ] < histogram[ marker ] )
183 | {
184 | marker = i;
185 | }
186 | }
187 |
188 | /* Remember the repetition marker for the decoder */
189 | out[ 0 ] = marker;
190 | outpos = 1;
191 |
192 | /* Start of compression */
193 | byte1 = in[ 0 ];
194 | inpos = 1;
195 | count = 1;
196 |
197 | /* Are there at least two bytes? */
198 | if( insize >= 2 )
199 | {
200 | byte2 = in[ inpos ++ ];
201 | count = 2;
202 |
203 | /* Main compression loop */
204 | do
205 | {
206 | if( byte1 == byte2 )
207 | {
208 | /* Do we meet only a sequence of identical bytes? */
209 | while( (inpos < insize) && (byte1 == byte2) &&
210 | (count < 32768) )
211 | {
212 | byte2 = in[ inpos ++ ];
213 | ++ count;
214 | }
215 | if( byte1 == byte2 )
216 | {
217 | _RLE_WriteRep( out, &outpos, marker, byte1, count );
218 | if( inpos < insize )
219 | {
220 | byte1 = in[ inpos ++ ];
221 | count = 1;
222 | }
223 | else
224 | {
225 | count = 0;
226 | }
227 | }
228 | else
229 | {
230 | _RLE_WriteRep( out, &outpos, marker, byte1, count-1 );
231 | byte1 = byte2;
232 | count = 1;
233 | }
234 | }
235 | else
236 | {
237 | /* No, then don't handle the last byte */
238 | _RLE_WriteNonRep( out, &outpos, marker, byte1 );
239 | byte1 = byte2;
240 | count = 1;
241 | }
242 | if( inpos < insize )
243 | {
244 | byte2 = in[ inpos ++ ];
245 | count = 2;
246 | }
247 | }
248 | while( (inpos < insize) || (count >= 2) );
249 | }
250 |
251 | /* One byte left? */
252 | if( count == 1 )
253 | {
254 | _RLE_WriteNonRep( out, &outpos, marker, byte1 );
255 | }
256 |
257 | return outpos;
258 | }
259 |
260 |
261 | /*************************************************************************
262 | * RLE_Uncompress() - Uncompress a block of data using an RLE decoder.
263 | * in - Input (compressed) buffer.
264 | * out - Output (uncompressed) buffer. This buffer must be large
265 | * enough to hold the uncompressed data.
266 | * insize - Number of input bytes.
267 | *************************************************************************/
268 |
269 | void RLE_Uncompress( unsigned char *in, unsigned char *out,
270 | unsigned int insize )
271 | {
272 | unsigned char marker, symbol;
273 | unsigned int i, inpos, outpos, count;
274 |
275 | /* Do we have anything to uncompress? */
276 | if( insize < 1 )
277 | {
278 | return;
279 | }
280 |
281 | /* Get marker symbol from input stream */
282 | inpos = 0;
283 | marker = in[ inpos ++ ];
284 |
285 | /* Main decompression loop */
286 | outpos = 0;
287 | do
288 | {
289 | symbol = in[ inpos ++ ];
290 | if( symbol == marker )
291 | {
292 | /* We had a marker byte */
293 | count = in[ inpos ++ ];
294 | if( count <= 2 )
295 | {
296 | /* Counts 0, 1 and 2 are used for marker byte repetition
297 | only */
298 | for( i = 0; i <= count; ++ i )
299 | {
300 | out[ outpos ++ ] = marker;
301 | }
302 | }
303 | else
304 | {
305 | if( count & 0x80 )
306 | {
307 | count = ((count & 0x7f) << 8) + in[ inpos ++ ];
308 | }
309 | symbol = in[ inpos ++ ];
310 | for( i = 0; i <= count; ++ i )
311 | {
312 | out[ outpos ++ ] = symbol;
313 | }
314 | }
315 | }
316 | else
317 | {
318 | /* No marker, plain copy */
319 | out[ outpos ++ ] = symbol;
320 | }
321 | }
322 | while( inpos < insize );
323 | }
324 |
--------------------------------------------------------------------------------