comparison interps/cfunge/cfunge-src/src/funge-space/funge-space.h @ 996:859f9b4339e6

<Gregor> tar xf egobot.tar.xz
author HackBot
date Sun, 09 Dec 2012 19:30:08 +0000
parents
children
comparison
equal deleted inserted replaced
995:6883f5911eb7 996:859f9b4339e6
1 /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
2 *
3 * cfunge - A standard-conforming Befunge93/98/109 interpreter in C.
4 * Copyright (C) 2008-2009 Arvid Norlander <anmaster AT tele2 DOT se>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at the proxy's option) any later version. Arvid Norlander is a
10 * proxy who can decide which future versions of the GNU General Public
11 * License can be used.
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, see <http://www.gnu.org/licenses/>.
20 */
21
22 /**
23 * @file
24 * Contains functions to access Funge-Space.
25 */
26
27 #ifndef FUNGE_HAD_SRC_FUNGE_SPACE_H
28 #define FUNGE_HAD_SRC_FUNGE_SPACE_H
29
30 #include "../global.h"
31 #include "../vector.h"
32 #include "../rect.h"
33 #include <stdint.h>
34 #include <stdbool.h>
35
36 /// DO NOT CHANGE unless you are 100 sure of what you are doing!
37 /// Yes I mean you!
38 typedef funge_vector fungeSpaceHashKey;
39
40 /**
41 * Create a Funge-space.
42 * @warning Should only be called from internal setup code.
43 * @return True if successful, otherwise false.
44 */
45 FUNGE_ATTR_FAST FUNGE_ATTR_WARN_UNUSED
46 bool fungespace_create(void);
47 /**
48 * Destroy a Funge-space.
49 * @warning Should only be called from internal tear-down code.
50 */
51 FUNGE_ATTR_FAST
52 void fungespace_free(void);
53 /**
54 * Get a cell.
55 * @param position The place in Funge-Space to get the value for.
56 * @return The value for that position.
57 */
58 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED
59 funge_cell fungespace_get(const funge_vector * restrict position);
60 /**
61 * Get a cell, with an offset. Mostly used to handle storage offset.
62 * @param position The place in Funge-Space to get the value for.
63 * @param offset An additional offset to add to the position.
64 * @return The value for that position after adding offset.
65 */
66 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED
67 funge_cell fungespace_get_offset(const funge_vector * restrict position,
68 const funge_vector * restrict offset);
69 /**
70 * Set a cell.
71 * @param value The value to set.
72 * @param position The place in Funge-Space to set the value for.
73 */
74 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL
75 void fungespace_set(funge_cell value,
76 const funge_vector * restrict position);
77 /**
78 * Set a cell, with an offset. Mostly used to handle storage offset.
79 * @param value The value to set.
80 * @param position The place in Funge-Space to set the value for.
81 * @param offset An additional offset to add to the position.
82 */
83 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL
84 void fungespace_set_offset(funge_cell value,
85 const funge_vector * restrict position,
86 const funge_vector * restrict offset);
87 /**
88 * Calculate the new position after adding a delta to a position, considering
89 * any needed wrapping. Used for IP wrapping.
90 * @param position Position before change, will be modified in place.
91 * @param delta The delta to add to this position.
92 * @note
93 * This code modifies the position vector in place!
94 */
95 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL
96 void fungespace_wrap(funge_vector * restrict position,
97 const funge_vector * restrict delta);
98 /**
99 * Load a file into Funge-Space at 0,0. Optimised compared to
100 * fungespace_load_at_offset(). Only used for loading initial file.
101 * @param filename Filename to load.
102 * @return True if successful, otherwise false.
103 */
104 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED
105 bool fungespace_load(const char * restrict filename);
106
107 #ifdef FUNGE_EXTERNAL_LIBRARY
108 /**
109 * Load a string into Funge-Space at 0,0. Optimised. This code is used
110 * internally by cfunge itself but is not usually exposed. It is however needed
111 * for IFFI (using cfunge as a library in C-INTERCAL).
112 * @param program Program to load.
113 * @param length Length of string, needed since code need to be embedded
114 * null bytes, thus strlen() won't work.
115 */
116 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL
117 void fungespace_load_string(const unsigned char * restrict program,
118 size_t length);
119 #endif
120
121 /**
122 * Load a file into Funge-Space at an offset. Used for the i instruction.
123 * @param filename Filename to load.
124 * @param offset The offset to load the file at.
125 * @param size This variable will be filled in by the function with the width
126 * and height of the "bounding rectangle" that the file was loaded in.
127 * @param binary If true newlines will be put into Funge-Space and won't
128 * increment the y "counter".
129 * @return True if successful, otherwise false.
130 */
131 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED
132 bool fungespace_load_at_offset(const char * restrict filename,
133 const funge_vector * restrict offset,
134 funge_vector * restrict size,
135 bool binary);
136 /**
137 * Write out a file from an area of Funge-Space at an offset. Used for the o
138 * instruction.
139 * @param filename Filename to write to.
140 * @param offset The offset to write the file from.
141 * @param size The width and height of the area to write out.
142 * @param textfile If true will strip any spaces from end of lines and also
143 * strip trailing newlines.
144 * @return True if successful, otherwise false.
145 */
146 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL FUNGE_ATTR_WARN_UNUSED
147 bool fungespace_save_to_file(const char * restrict filename,
148 const funge_vector * restrict offset,
149 const funge_vector * restrict size,
150 bool textfile);
151
152 /**
153 * Get the bounding rectangle for the part of Funge-Space that isn't empty.
154 * @note It won't be too small, but it may be too big.
155 * @param rect Out parameter for the bounding rectangle.
156 */
157 FUNGE_ATTR_FAST FUNGE_ATTR_NONNULL
158 void fungespace_get_bounds_rect(fungeRect * restrict rect);
159
160 #endif