| 1 |
/******************************************************************** |
| 2 |
This file is part of Ironseed. |
| 3 |
|
| 4 |
Ironseed is free software: you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation, either version 3 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
Ironseed is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with Ironseed. If not, see <https://www.gnu.org/licenses/>. |
| 16 |
********************************************************************/ |
| 17 |
|
| 18 |
/********************************************* |
| 19 |
Data Generator: shared structs for *.d |
| 20 |
|
| 21 |
Copyright: |
| 22 |
1994 Channel 7, Destiny: Virtual |
| 23 |
2020 Matija Nalis <[email protected]> |
| 24 |
**********************************************/ |
| 25 |
|
| 26 |
import std.conv; |
| 27 |
|
| 28 |
template PString(int L){ |
| 29 |
align(1) struct ps { |
| 30 |
ubyte length; |
| 31 |
char[L] data; |
| 32 |
void opCall(char []s) { |
| 33 |
const int maxlength = L; |
| 34 |
assert (maxlength < 255); |
| 35 |
if(s.length > maxlength) { |
| 36 |
this.length = to!ubyte(maxlength); |
| 37 |
data[0..this.length] = s[0..this.length]; |
| 38 |
} else { |
| 39 |
this.length = to!ubyte(s.length); |
| 40 |
data[0..s.length] = s[0..s.length]; |
| 41 |
} |
| 42 |
} |
| 43 |
char []opCast() { |
| 44 |
return data[0..this.length]; |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
struct ConverseRecord { |
| 50 |
short event; |
| 51 |
short runevent; |
| 52 |
short rcode; |
| 53 |
short index; |
| 54 |
ubyte keywordlength; |
| 55 |
char[75] keyword; |
| 56 |
}; |
| 57 |
struct ResponseRecord { |
| 58 |
short index; |
| 59 |
ubyte responselength; |
| 60 |
char[255] response; |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
struct TitleRecord { |
| 65 |
short id; |
| 66 |
PString!(49).ps text; |
| 67 |
}; |
| 68 |
|
| 69 |
struct LogRecord { |
| 70 |
PString!(49).ps[25] text; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
int encodechar(char c) { |
| 75 |
if(c >= ' ' && c <= '"') {return c - 31;} |
| 76 |
if(c >= 'A' && c <= 'Z') {return c - 36;} |
| 77 |
if(c >= 'a' && c <= 'z') {return c - 40;} |
| 78 |
if(c >= '\'' && c <= '?') {return c - 35;} |
| 79 |
switch(c) { |
| 80 |
case '%': return 55; |
| 81 |
case '^': return 200; |
| 82 |
case 200: return 200; |
| 83 |
case '@': return 201; |
| 84 |
default: return -1; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
char []encodestring(char []instr) { |
| 89 |
char[] s; |
| 90 |
int ec; |
| 91 |
foreach(char c; instr) { |
| 92 |
ec = encodechar(c); |
| 93 |
if(ec >= 0) { |
| 94 |
s ~= cast(char)ec; |
| 95 |
} |
| 96 |
} |
| 97 |
return s; |
| 98 |
} |