Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
00bea56b
Commit
00bea56b
authored
17 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Be more sane about read() and write()
parent
b66fb231
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
xtrn/tbd/objects.mk
+1
-0
1 addition, 0 deletions
xtrn/tbd/objects.mk
xtrn/tbd/tbd2.c
+10
-124
10 additions, 124 deletions
xtrn/tbd/tbd2.c
xtrn/tbd/tbd_pack.c
+113
-0
113 additions, 0 deletions
xtrn/tbd/tbd_pack.c
xtrn/tbd/tbd_pack.h
+19
-0
19 additions, 0 deletions
xtrn/tbd/tbd_pack.h
with
143 additions
and
124 deletions
xtrn/tbd/objects.mk
+
1
−
0
View file @
00bea56b
OBJS
=
$(
MTOBJODIR
)$(
DIRSEP
)
tbd
$(
OFILE
)
\
$(
MTOBJODIR
)$(
DIRSEP
)
tbd2
$(
OFILE
)
\
$(
MTOBJODIR
)$(
DIRSEP
)
tbd_pack
$(
OFILE
)
\
$(
MTOBJODIR
)$(
DIRSEP
)
xsdk
$(
OFILE
)
\
$(
MTOBJODIR
)$(
DIRSEP
)
xsdkvars
$(
OFILE
)
...
...
This diff is collapsed.
Click to expand it.
xtrn/tbd/tbd2.c
+
10
−
124
View file @
00bea56b
...
...
@@ -2,7 +2,7 @@
Functions for The Beast's Domain
******************************************************************************/
#include
"tbd.h"
#include
"tbd
_pack
.h"
int
in_shop
=
0
;
long
cost_per_min
=
0L
,
total_cost
=
0L
,
times_per_day
=
0L
;
...
...
@@ -490,6 +490,7 @@ void game_commands(int menu,int line)
long
read_user
(
int
get_empty
)
{
int
file
,
x
,
count
;
char
buf
[
USER_T_SIZE
];
record_number
=
0L
;
if
(
!
fexist
(
"tbd.usr"
))
return
0L
;
/* User file doesn't exist */
...
...
@@ -502,56 +503,9 @@ long read_user(int get_empty)
count
=
0
;
while
(
lock
(
file
,
record_number
*
(
long
)(
USER_T_SIZE
),
(
long
)(
USER_T_SIZE
))
&&
count
++<
500
);
if
(
!
read
(
file
,
&
user
.
status
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
handle
,
26
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
mapx
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
mapy
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
mapz
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
roomx
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
roomy
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
health
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
max_health
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
exp
,
4
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
level
,
1
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
weapon
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
armor
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
gold
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
0
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
1
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
2
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
3
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
4
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
5
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
left_game
,
4
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
ring
,
1
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
key
,
1
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
compass
,
1
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
space
,
28
))
if
(
!
read
(
file
,
buf
,
USER_T_SIZE
))
ateof
=
1
;
unpack_user_t_struct
(
&
user
,
buf
);
truncsp
(
user
.
handle
);
if
(
!
user
.
status
)
{
if
(
get_empty
)
{
...
...
@@ -578,36 +532,14 @@ long read_user(int get_empty)
void
write_user
()
{
int
file
;
char
buf
[
USER_T_SIZE
];
strcpy
(
user
.
handle
,
user_name
);
if
((
file
=
nopen
(
"tbd.usr"
,
O_WRONLY
|
O_CREAT
))
==-
1
)
{
printf
(
"Error opening user data file
\r\n
"
);
}
lseek
(
file
,
record_number
*
(
long
)
USER_T_SIZE
,
SEEK_SET
);
write
(
file
,
&
user
.
status
,
2
);
write
(
file
,
&
user
.
handle
,
26
);
write
(
file
,
&
user
.
mapx
,
2
);
write
(
file
,
&
user
.
mapy
,
2
);
write
(
file
,
&
user
.
mapz
,
2
);
write
(
file
,
&
user
.
roomx
,
2
);
write
(
file
,
&
user
.
roomy
,
2
);
write
(
file
,
&
user
.
health
,
2
);
write
(
file
,
&
user
.
max_health
,
2
);
write
(
file
,
&
user
.
exp
,
4
);
write
(
file
,
&
user
.
level
,
1
);
write
(
file
,
&
user
.
weapon
,
2
);
write
(
file
,
&
user
.
armor
,
2
);
write
(
file
,
&
user
.
gold
,
2
);
write
(
file
,
&
(
user
.
item
[
0
]),
2
);
write
(
file
,
&
(
user
.
item
[
1
]),
2
);
write
(
file
,
&
(
user
.
item
[
2
]),
2
);
write
(
file
,
&
(
user
.
item
[
3
]),
2
);
write
(
file
,
&
(
user
.
item
[
4
]),
2
);
write
(
file
,
&
(
user
.
item
[
5
]),
2
);
write
(
file
,
&
user
.
left_game
,
4
);
write
(
file
,
&
user
.
ring
,
1
);
write
(
file
,
&
user
.
key
,
1
);
write
(
file
,
&
user
.
compass
,
1
);
write
(
file
,
&
user
.
space
,
28
);
pack_user_t_struct
(
buf
,
&
user
);
write
(
file
,
buf
,
USER_T_SIZE
);
close
(
file
);
}
/******************************************************************************
...
...
@@ -619,6 +551,7 @@ void list_users()
uchar
statlev
[
11
];
long
statexp
[
11
];
int
file
,
num
,
x
;
char
buf
[
USER_T_SIZE
];
for
(
x
=
0
;
x
<
11
;
x
++
)
{
statlev
[
x
]
=
0
;
statexp
[
x
]
=
0L
;
strcpy
(
statname
[
x
],
"Nobody"
);
}
...
...
@@ -633,56 +566,9 @@ void list_users()
bprintf
(
"
\r\n\1
n
\1
hReading user database..."
);
ateof
=
0
;
while
(
!
ateof
)
{
if
(
!
read
(
file
,
&
user
.
status
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
handle
,
26
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
mapx
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
mapy
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
mapz
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
roomx
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
roomy
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
health
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
max_health
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
exp
,
4
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
level
,
1
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
weapon
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
armor
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
gold
,
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
0
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
1
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
2
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
3
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
4
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
(
user
.
item
[
5
]),
2
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
left_game
,
4
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
ring
,
1
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
key
,
1
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
compass
,
1
))
ateof
=
1
;
if
(
!
read
(
file
,
&
user
.
space
,
28
))
if
(
!
read
(
file
,
buf
,
USER_T_SIZE
))
ateof
=
1
;
unpack_user_t_struct
(
&
user
,
buf
);
truncsp
(
user
.
handle
);
statlev
[
10
]
=
user
.
level
;
strcpy
(
statname
[
10
],
user
.
handle
);
statexp
[
10
]
=
user
.
exp
;
...
...
This diff is collapsed.
Click to expand it.
xtrn/tbd/tbd_pack.c
0 → 100644
+
113
−
0
View file @
00bea56b
#include
"tbd_pack.h"
int
pack_user_t_struct
(
char
*
buf
,
user_t
*
data
)
{
char
*
p
;
int
i
;
p
=
buf
;
*
(
short
*
)
p
=
LE_SHORT
(
data
->
status
);
p
+=
sizeof
(
short
);
for
(
i
=
0
;
i
<
26
;
i
++
)
{
*
p
=
data
->
handle
[
i
];
p
++
;
}
*
(
short
*
)
p
=
LE_SHORT
(
data
->
mapx
);
p
+=
sizeof
(
short
);
*
(
short
*
)
p
=
LE_SHORT
(
data
->
mapy
);
p
+=
sizeof
(
short
);
*
(
short
*
)
p
=
LE_SHORT
(
data
->
mapz
);
p
+=
sizeof
(
short
);
*
(
short
*
)
p
=
LE_SHORT
(
data
->
roomx
);
p
+=
sizeof
(
short
);
*
(
short
*
)
p
=
LE_SHORT
(
data
->
roomy
);
p
+=
sizeof
(
short
);
*
(
short
*
)
p
=
LE_SHORT
(
data
->
health
);
p
+=
sizeof
(
short
);
*
(
short
*
)
p
=
LE_SHORT
(
data
->
max_health
);
p
+=
sizeof
(
short
);
*
(
int
*
)
p
=
LE_LONG
(
data
->
exp
);
p
+=
sizeof
(
int
);
*
(
uchar
*
)
p
=
data
->
level
;
p
++
;
*
(
unsigned
short
*
)
p
=
LE_SHORT
(
data
->
weapon
);
p
+=
sizeof
(
unsigned
short
);
*
(
unsigned
short
*
)
p
=
LE_SHORT
(
data
->
armor
);
p
+=
sizeof
(
unsigned
short
);
*
(
unsigned
short
*
)
p
=
LE_SHORT
(
data
->
gold
);
p
+=
sizeof
(
unsigned
short
);
for
(
i
=
0
;
i
<
6
;
i
++
)
{
*
(
unsigned
short
*
)
p
=
LE_SHORT
(
data
->
item
[
i
]);
p
+=
sizeof
(
unsigned
short
);
}
*
(
int
*
)
p
=
LE_LONG
(
data
->
left_game
);
p
+=
sizeof
(
int
);
*
(
uchar
*
)
p
=
data
->
ring
;
p
++
;
*
(
uchar
*
)
p
=
data
->
key
;
p
++
;
*
(
uchar
*
)
p
=
data
->
compass
;
p
++
;
for
(
i
=
0
;
i
<
28
;
i
++
)
{
*
p
=
data
->
space
[
i
];
p
++
;
}
return
((
int
)(
p
-
buf
));
}
int
unpack_user_t_struct
(
user_t
*
data
,
char
*
buf
)
{
char
*
p
;
int
i
;
p
=
buf
;
data
->
status
=
LE_SHORT
(
*
(
short
*
)
p
);
p
+=
sizeof
(
short
);
for
(
i
=
0
;
i
<
26
;
i
++
)
{
data
->
handle
[
i
]
=
*
p
;
p
++
;
}
data
->
mapx
=
LE_SHORT
(
*
(
short
*
)
p
);
p
+=
sizeof
(
short
);
data
->
mapy
=
LE_SHORT
(
*
(
short
*
)
p
);
p
+=
sizeof
(
short
);
data
->
mapz
=
LE_SHORT
(
*
(
short
*
)
p
);
p
+=
sizeof
(
short
);
data
->
roomx
=
LE_SHORT
(
*
(
short
*
)
p
);
p
+=
sizeof
(
short
);
data
->
roomy
=
LE_SHORT
(
*
(
short
*
)
p
);
p
+=
sizeof
(
short
);
data
->
health
=
LE_SHORT
(
*
(
short
*
)
p
);
p
+=
sizeof
(
short
);
data
->
max_health
=
LE_SHORT
(
*
(
short
*
)
p
);
p
+=
sizeof
(
short
);
data
->
exp
=
LE_LONG
(
*
(
int
*
)
p
);
p
+=
sizeof
(
int
);
data
->
level
=
*
(
uchar
*
)
p
;
p
++
;
data
->
weapon
=
LE_SHORT
(
*
(
unsigned
short
*
)
p
);
p
+=
sizeof
(
unsigned
short
);
data
->
armor
=
LE_SHORT
(
*
(
unsigned
short
*
)
p
);
p
+=
sizeof
(
unsigned
short
);
data
->
gold
=
LE_SHORT
(
*
(
unsigned
short
*
)
p
);
p
+=
sizeof
(
unsigned
short
);
for
(
i
=
0
;
i
<
6
;
i
++
)
{
data
->
item
[
i
]
=
LE_SHORT
(
*
(
unsigned
short
*
)
p
);
p
+=
sizeof
(
unsigned
short
);
}
data
->
left_game
=
LE_LONG
(
*
(
int
*
)
p
);
p
+=
sizeof
(
int
);
data
->
ring
=
*
(
uchar
*
)
p
;
p
++
;
data
->
key
=
*
(
uchar
*
)
p
;
p
++
;
data
->
compass
=
*
(
uchar
*
)
p
;
p
++
;
for
(
i
=
0
;
i
<
28
;
i
++
)
{
data
->
space
[
i
]
=
*
p
;
p
++
;
}
return
((
int
)(
p
-
buf
));
}
This diff is collapsed.
Click to expand it.
xtrn/tbd/tbd_pack.h
0 → 100644
+
19
−
0
View file @
00bea56b
/* Generated by genpack.pl from tbd.h on Tue Jun 12 23:22:14 2007 */
#ifndef _INCLUDED_TBD_PACK_H
#define _INCLUDED_TBD_PACK_H
#include
"tbd.h"
#include
"xpendian.h"
/* Function prototypes */
#if defined(__cplusplus)
extern
"C"
{
#endif
int
pack_user_t_struct
(
char
*
buf
,
user_t
*
data
);
int
unpack_user_t_struct
(
user_t
*
data
,
char
*
buf
);
#if defined(__cplusplus)
}
#endif
#endif
/* Do not add anything after this line! */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment