aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.indent.pro1
-rw-r--r--ast.c157
-rw-r--r--ast.h193
-rw-r--r--client_bsd.c20
-rw-r--r--client_sysv.c50
-rw-r--r--code_gen.c531
-rw-r--r--code_gen.h11
-rw-r--r--db.h257
-rw-r--r--db_file.c237
-rw-r--r--db_io.c154
-rw-r--r--db_io.h45
-rw-r--r--db_objects.c114
-rw-r--r--db_private.h87
-rw-r--r--db_properties.c301
-rw-r--r--db_verbs.c178
-rw-r--r--decompile.c409
-rw-r--r--decompile.h11
-rw-r--r--disassemble.c289
-rw-r--r--disassemble.h11
-rw-r--r--eval_env.c48
-rw-r--r--eval_env.h21
-rw-r--r--eval_vm.c31
-rw-r--r--eval_vm.h21
-rw-r--r--exceptions.c38
-rw-r--r--exceptions.h95
-rw-r--r--execute.c2661
-rw-r--r--execute.h157
-rw-r--r--extensions.c41
-rw-r--r--functions.c127
-rw-r--r--functions.h71
-rw-r--r--getpagesize.h17
-rw-r--r--gnu-malloc.c1076
-rw-r--r--keywords.c257
-rw-r--r--keywords.h15
-rw-r--r--list.c329
-rw-r--r--list.h35
-rw-r--r--log.c41
-rw-r--r--log.h11
-rw-r--r--malloc.c17
-rw-r--r--match.c47
-rw-r--r--match.h9
-rw-r--r--md5.c220
-rw-r--r--md5.h27
-rw-r--r--my-ctype.h13
-rw-r--r--my-fcntl.h11
-rw-r--r--my-in.h15
-rw-r--r--my-ioctl.h9
-rw-r--r--my-signal.h17
-rw-r--r--my-socket.h23
-rw-r--r--my-stat.h13
-rw-r--r--my-stdarg.h13
-rw-r--r--my-stdio.h37
-rw-r--r--my-stdlib.h37
-rw-r--r--my-string.h45
-rw-r--r--my-sys-time.h13
-rw-r--r--my-time.h17
-rw-r--r--my-tiuser.h25
-rw-r--r--my-types.h11
-rw-r--r--my-unistd.h31
-rw-r--r--my-wait.h9
-rw-r--r--name_lookup.c99
-rw-r--r--name_lookup.h19
-rw-r--r--net_bsd_lcl.c46
-rw-r--r--net_bsd_tcp.c90
-rw-r--r--net_mp_fake.c56
-rw-r--r--net_mp_poll.c30
-rw-r--r--net_mp_selct.c15
-rw-r--r--net_mplex.h29
-rw-r--r--net_multi.c234
-rw-r--r--net_multi.h21
-rw-r--r--net_proto.h51
-rw-r--r--net_single.c61
-rw-r--r--net_sysv_lcl.c134
-rw-r--r--net_sysv_tcp.c97
-rw-r--r--network.h79
-rw-r--r--numbers.c298
-rw-r--r--numbers.h29
-rw-r--r--objects.c278
-rw-r--r--opcode.h29
-rw-r--r--options.h9
-rw-r--r--parse_cmd.c78
-rw-r--r--parse_cmd.h35
-rw-r--r--parser.h15
-rw-r--r--pattern.c55
-rw-r--r--pattern.h19
-rw-r--r--program.c32
-rw-r--r--program.h49
-rw-r--r--property.c146
-rw-r--r--quota.c23
-rw-r--r--quota.h11
-rw-r--r--random.h11
-rw-r--r--ref_count.c59
-rw-r--r--ref_count.h11
-rw-r--r--regexpr.c2495
-rw-r--r--regexpr.h81
-rw-r--r--server.c634
-rw-r--r--server.h61
-rw-r--r--storage.c63
-rw-r--r--storage.h21
-rw-r--r--streams.c102
-rw-r--r--streams.h31
-rw-r--r--structures.h35
-rw-r--r--sym_table.c72
-rw-r--r--sym_table.h23
-rw-r--r--tasks.c816
-rw-r--r--tasks.h111
-rw-r--r--timers.c98
-rw-r--r--timers.h29
-rw-r--r--unparse.c377
-rw-r--r--unparse.h29
-rw-r--r--utils.c231
-rw-r--r--utils.h41
-rw-r--r--verbs.c283
-rw-r--r--verbs.h11
-rw-r--r--version.c4
-rw-r--r--version.h13
116 files changed, 8515 insertions, 8201 deletions
diff --git a/.indent.pro b/.indent.pro
new file mode 100644
index 0000000..053b4f0
--- /dev/null
+++ b/.indent.pro
@@ -0,0 +1 @@
+-kr -ip4 -psl -nfca -lps
diff --git a/ast.c b/ast.c
index fa26496..dcdbebd 100644
--- a/ast.c
+++ b/ast.c
@@ -28,12 +28,12 @@
#include "utils.h"
struct entry {
- void *ptr;
- Memory_Type type;
+ void *ptr;
+ Memory_Type type;
};
-static int pool_size, next_pool_slot;
-static struct entry *pool;
+static int pool_size, next_pool_slot;
+static struct entry *pool;
void
begin_code_allocation()
@@ -47,23 +47,22 @@ void
end_code_allocation(int aborted)
{
if (aborted) {
- int i;
+ int i;
for (i = 0; i < next_pool_slot; i++) {
if (pool[i].ptr != 0)
myfree(pool[i].ptr, pool[i].type);
}
}
-
myfree(pool, M_AST_POOL);
}
static void *
allocate(int size, Memory_Type type)
{
- if (next_pool_slot >= pool_size) { /* enlarge the pool */
- struct entry *new_pool;
- int i;
+ if (next_pool_slot >= pool_size) { /* enlarge the pool */
+ struct entry *new_pool;
+ int i;
pool_size *= 2;
new_pool = mymalloc(pool_size * sizeof(struct entry), M_AST_POOL);
@@ -73,7 +72,6 @@ allocate(int size, Memory_Type type)
myfree(pool, M_AST_POOL);
pool = new_pool;
}
-
pool[next_pool_slot].type = type;
return pool[next_pool_slot++].ptr = mymalloc(size, type);
}
@@ -81,7 +79,7 @@ allocate(int size, Memory_Type type)
static void
deallocate(void *ptr)
{
- int i;
+ int i;
for (i = 0; i < next_pool_slot; i++) {
if (ptr == pool[i].ptr) {
@@ -97,8 +95,8 @@ deallocate(void *ptr)
char *
alloc_string(const char *buffer)
{
- char *string = allocate(strlen(buffer) + 1, M_STRING);
-
+ char *string = allocate(strlen(buffer) + 1, M_STRING);
+
strcpy(string, buffer);
return string;
}
@@ -112,7 +110,7 @@ dealloc_string(char *str)
double *
alloc_float(double value)
{
- double *d = allocate(sizeof(double), M_FLOAT);
+ double *d = allocate(sizeof(double), M_FLOAT);
*d = value;
return d;
@@ -127,7 +125,7 @@ dealloc_node(void *node)
Stmt *
alloc_stmt(enum Stmt_Kind kind)
{
- Stmt *result = allocate(sizeof(Stmt), M_AST);
+ Stmt *result = allocate(sizeof(Stmt), M_AST);
result->kind = kind;
result->next = 0;
@@ -135,9 +133,9 @@ alloc_stmt(enum Stmt_Kind kind)
}
Cond_Arm *
-alloc_cond_arm(Expr *condition, Stmt *stmt)
+alloc_cond_arm(Expr * condition, Stmt * stmt)
{
- Cond_Arm *result = allocate(sizeof(Cond_Arm), M_AST);
+ Cond_Arm *result = allocate(sizeof(Cond_Arm), M_AST);
result->condition = condition;
result->stmt = stmt;
@@ -146,9 +144,9 @@ alloc_cond_arm(Expr *condition, Stmt *stmt)
}
Except_Arm *
-alloc_except(int id, Arg_List *codes, Stmt *stmt)
+alloc_except(int id, Arg_List * codes, Stmt * stmt)
{
- Except_Arm *result = allocate(sizeof(Except_Arm), M_AST);
+ Except_Arm *result = allocate(sizeof(Except_Arm), M_AST);
result->id = id;
result->codes = codes;
@@ -161,8 +159,8 @@ alloc_except(int id, Arg_List *codes, Stmt *stmt)
Expr *
alloc_expr(enum Expr_Kind kind)
{
- Expr *result = allocate(sizeof(Expr), M_AST);
-
+ Expr *result = allocate(sizeof(Expr), M_AST);
+
result->kind = kind;
return result;
}
@@ -170,26 +168,26 @@ alloc_expr(enum Expr_Kind kind)
Expr *
alloc_var(var_type type)
{
- Expr *result = alloc_expr(EXPR_VAR);
+ Expr *result = alloc_expr(EXPR_VAR);
result->e.var.type = type;
return result;
}
Expr *
-alloc_binary(enum Expr_Kind kind, Expr *lhs, Expr *rhs)
+alloc_binary(enum Expr_Kind kind, Expr * lhs, Expr * rhs)
{
- Expr *result = alloc_expr(kind);
-
+ Expr *result = alloc_expr(kind);
+
result->e.bin.lhs = lhs;
result->e.bin.rhs = rhs;
return result;
}
Expr *
-alloc_verb(Expr *obj, Expr *verb, Arg_List *args)
+alloc_verb(Expr * obj, Expr * verb, Arg_List * args)
{
- Expr *result = alloc_expr(EXPR_VERB);
+ Expr *result = alloc_expr(EXPR_VERB);
result->e.verb.obj = obj;
result->e.verb.verb = verb;
@@ -198,9 +196,9 @@ alloc_verb(Expr *obj, Expr *verb, Arg_List *args)
}
Arg_List *
-alloc_arg_list(enum Arg_Kind kind, Expr *expr)
+alloc_arg_list(enum Arg_Kind kind, Expr * expr)
{
- Arg_List *result = allocate(sizeof(Arg_List), M_AST);
+ Arg_List *result = allocate(sizeof(Arg_List), M_AST);
result->kind = kind;
result->expr = expr;
@@ -209,9 +207,9 @@ alloc_arg_list(enum Arg_Kind kind, Expr *expr)
}
Scatter *
-alloc_scatter(enum Scatter_Kind kind, int id, Expr *expr)
+alloc_scatter(enum Scatter_Kind kind, int id, Expr * expr)
{
- Scatter *sc = allocate(sizeof(Scatter), M_AST);
+ Scatter *sc = allocate(sizeof(Scatter), M_AST);
sc->kind = kind;
sc->id = id;
@@ -225,9 +223,9 @@ alloc_scatter(enum Scatter_Kind kind, int id, Expr *expr)
static void free_expr(Expr *);
static void
-free_arg_list(Arg_List *args)
+free_arg_list(Arg_List * args)
{
- Arg_List *arg, *next_arg;
+ Arg_List *arg, *next_arg;
for (arg = args; arg; arg = next_arg) {
next_arg = arg->next;
@@ -237,9 +235,9 @@ free_arg_list(Arg_List *args)
}
static void
-free_scatter(Scatter *sc)
+free_scatter(Scatter * sc)
{
- Scatter *next_sc;
+ Scatter *next_sc;
for (; sc; sc = next_sc) {
next_sc = sc->next;
@@ -250,72 +248,84 @@ free_scatter(Scatter *sc)
}
static void
-free_expr(Expr *expr)
+free_expr(Expr * expr)
{
switch (expr->kind) {
- case EXPR_VAR:
+ case EXPR_VAR:
free_var(expr->e.var);
break;
- case EXPR_ID:
- case EXPR_LENGTH:
+ case EXPR_ID:
+ case EXPR_LENGTH:
/* Do nothing. */
break;
- case EXPR_PROP: case EXPR_INDEX: case EXPR_PLUS:
- case EXPR_MINUS: case EXPR_TIMES: case EXPR_DIVIDE:
- case EXPR_MOD: case EXPR_AND: case EXPR_OR:
- case EXPR_EQ: case EXPR_NE: case EXPR_LT:
- case EXPR_LE: case EXPR_GT: case EXPR_GE:
- case EXPR_IN: case EXPR_ASGN: case EXPR_EXP:
+ case EXPR_PROP:
+ case EXPR_INDEX:
+ case EXPR_PLUS:
+ case EXPR_MINUS:
+ case EXPR_TIMES:
+ case EXPR_DIVIDE:
+ case EXPR_MOD:
+ case EXPR_AND:
+ case EXPR_OR:
+ case EXPR_EQ:
+ case EXPR_NE:
+ case EXPR_LT:
+ case EXPR_LE:
+ case EXPR_GT:
+ case EXPR_GE:
+ case EXPR_IN:
+ case EXPR_ASGN:
+ case EXPR_EXP:
free_expr(expr->e.bin.lhs);
free_expr(expr->e.bin.rhs);
break;
- case EXPR_COND:
+ case EXPR_COND:
free_expr(expr->e.cond.condition);
free_expr(expr->e.cond.consequent);
free_expr(expr->e.cond.alternate);
break;
- case EXPR_VERB:
+ case EXPR_VERB:
free_expr(expr->e.verb.obj);
free_expr(expr->e.verb.verb);
free_arg_list(expr->e.verb.args);
break;
- case EXPR_RANGE:
+ case EXPR_RANGE:
free_expr(expr->e.range.base);
free_expr(expr->e.range.from);
free_expr(expr->e.range.to);
break;
- case EXPR_CALL:
+ case EXPR_CALL:
free_arg_list(expr->e.call.args);
break;
- case EXPR_NEGATE:
- case EXPR_NOT:
+ case EXPR_NEGATE:
+ case EXPR_NOT:
free_expr(expr->e.expr);
break;
- case EXPR_LIST:
+ case EXPR_LIST:
free_arg_list(expr->e.list);
break;
- case EXPR_CATCH:
+ case EXPR_CATCH:
free_expr(expr->e.catch.try);
free_arg_list(expr->e.catch.codes);
if (expr->e.catch.except)
free_expr(expr->e.catch.except);
break;
- case EXPR_SCATTER:
+ case EXPR_SCATTER:
free_scatter(expr->e.scatter);
break;
- default:
+ default:
errlog("FREE_EXPR: Unknown Expr_Kind: %d\n", expr->kind);
break;
}
@@ -324,10 +334,10 @@ free_expr(Expr *expr)
}
void
-free_stmt(Stmt *stmt)
+free_stmt(Stmt * stmt)
{
- Stmt *next_stmt;
- Cond_Arm *arm, *next_arm;
+ Stmt *next_stmt;
+ Cond_Arm *arm, *next_arm;
Except_Arm *except, *next_e;
for (; stmt; stmt = next_stmt) {
@@ -335,7 +345,7 @@ free_stmt(Stmt *stmt)
switch (stmt->kind) {
- case STMT_COND:
+ case STMT_COND:
for (arm = stmt->s.cond.arms; arm; arm = next_arm) {
next_arm = arm->next;
free_expr(arm->condition);
@@ -346,34 +356,34 @@ free_stmt(Stmt *stmt)
free_stmt(stmt->s.cond.otherwise);
break;
- case STMT_LIST:
+ case STMT_LIST:
free_expr(stmt->s.list.expr);
free_stmt(stmt->s.list.body);
break;
- case STMT_RANGE:
+ case STMT_RANGE:
free_expr(stmt->s.range.from);
free_expr(stmt->s.range.to);
free_stmt(stmt->s.range.body);
break;
- case STMT_WHILE:
+ case STMT_WHILE:
free_expr(stmt->s.loop.condition);
free_stmt(stmt->s.loop.body);
break;
- case STMT_FORK:
+ case STMT_FORK:
free_expr(stmt->s.fork.time);
free_stmt(stmt->s.fork.body);
break;
- case STMT_EXPR:
- case STMT_RETURN:
+ case STMT_EXPR:
+ case STMT_RETURN:
if (stmt->s.expr)
free_expr(stmt->s.expr);
break;
- case STMT_TRY_EXCEPT:
+ case STMT_TRY_EXCEPT:
free_stmt(stmt->s.catch.body);
for (except = stmt->s.catch.excepts; except; except = next_e) {
next_e = except->next;
@@ -383,16 +393,16 @@ free_stmt(Stmt *stmt)
}
break;
- case STMT_TRY_FINALLY:
+ case STMT_TRY_FINALLY:
free_stmt(stmt->s.finally.body);
free_stmt(stmt->s.finally.handler);
break;
- case STMT_BREAK:
- case STMT_CONTINUE:
+ case STMT_BREAK:
+ case STMT_CONTINUE:
break; /* Nothing extra to free */
- default:
+ default:
errlog("FREE_STMT: unknown Stmt_Kind: %d\n", stmt->kind);
break;
}
@@ -404,9 +414,12 @@ free_stmt(Stmt *stmt)
char rcsid_ast[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:21 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.4 1996/02/08 07:11:54 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1 (again).
*
diff --git a/ast.h b/ast.h
index cc6e5f4..e5f949e 100644
--- a/ast.h
+++ b/ast.h
@@ -23,15 +23,15 @@
#include "structures.h"
#include "sym_table.h"
-typedef struct Expr Expr;
-typedef struct Arg_List Arg_List;
-typedef struct Stmt Stmt;
-typedef struct Cond_Arm Cond_Arm;
+typedef struct Expr Expr;
+typedef struct Arg_List Arg_List;
+typedef struct Stmt Stmt;
+typedef struct Cond_Arm Cond_Arm;
typedef struct Except_Arm Except_Arm;
-typedef struct Scatter Scatter;
+typedef struct Scatter Scatter;
struct Expr_Binary {
- Expr *lhs, *rhs;
+ Expr *lhs, *rhs;
};
enum Arg_Kind {
@@ -39,9 +39,9 @@ enum Arg_Kind {
};
struct Arg_List {
- Arg_List *next;
- enum Arg_Kind kind;
- Expr *expr;
+ Arg_List *next;
+ enum Arg_Kind kind;
+ Expr *expr;
};
enum Scatter_Kind {
@@ -49,36 +49,36 @@ enum Scatter_Kind {
};
struct Scatter {
- Scatter *next;
- enum Scatter_Kind kind;
- int id;
- Expr *expr;
+ Scatter *next;
+ enum Scatter_Kind kind;
+ int id;
+ Expr *expr;
/* These fields for convenience during code generation and decompiling */
- int label, next_label;
+ int label, next_label;
};
struct Expr_Call {
- unsigned func;
- Arg_List *args;
+ unsigned func;
+ Arg_List *args;
};
struct Expr_Verb {
- Expr *obj, *verb;
- Arg_List *args;
+ Expr *obj, *verb;
+ Arg_List *args;
};
struct Expr_Range {
- Expr *base, *from, *to;
+ Expr *base, *from, *to;
};
struct Expr_Cond {
- Expr *condition, *consequent, *alternate;
+ Expr *condition, *consequent, *alternate;
};
struct Expr_Catch {
- Expr *try;
- Arg_List *codes;
- Expr *except;
+ Expr *try;
+ Arg_List *codes;
+ Expr *except;
};
enum Expr_Kind {
@@ -92,80 +92,80 @@ enum Expr_Kind {
EXPR_EQ, EXPR_NE, EXPR_LT, EXPR_LE, EXPR_GT, EXPR_GE,
EXPR_IN, EXPR_LIST, EXPR_COND,
EXPR_CATCH, EXPR_LENGTH, EXPR_SCATTER,
- SizeOf_Expr_Kind /* The last element is also the number of elements... */
+ SizeOf_Expr_Kind /* The last element is also the number of elements... */
};
union Expr_Data {
- Var var;
- int id;
- struct Expr_Binary bin;
- struct Expr_Call call;
- struct Expr_Verb verb;
- struct Expr_Range range;
- struct Expr_Cond cond;
- struct Expr_Catch catch;
- Expr *expr;
- Arg_List *list;
- Scatter *scatter;
+ Var var;
+ int id;
+ struct Expr_Binary bin;
+ struct Expr_Call call;
+ struct Expr_Verb verb;
+ struct Expr_Range range;
+ struct Expr_Cond cond;
+ struct Expr_Catch catch;
+ Expr *expr;
+ Arg_List *list;
+ Scatter *scatter;
};
struct Expr {
- enum Expr_Kind kind;
- union Expr_Data e;
+ enum Expr_Kind kind;
+ union Expr_Data e;
};
struct Cond_Arm {
- Cond_Arm *next;
- Expr *condition;
- Stmt *stmt;
+ Cond_Arm *next;
+ Expr *condition;
+ Stmt *stmt;
};
struct Except_Arm {
- Except_Arm *next;
- int id;
- Arg_List *codes;
- Stmt *stmt;
+ Except_Arm *next;
+ int id;
+ Arg_List *codes;
+ Stmt *stmt;
/* This field is for convenience during code generation and decompiling */
- int label;
+ int label;
};
struct Stmt_Cond {
- Cond_Arm *arms;
- Stmt *otherwise;
+ Cond_Arm *arms;
+ Stmt *otherwise;
};
struct Stmt_List {
- int id;
- Expr *expr;
- Stmt *body;
+ int id;
+ Expr *expr;
+ Stmt *body;
};
struct Stmt_Range {
- int id;
- Expr *from, *to;
- Stmt *body;
+ int id;
+ Expr *from, *to;
+ Stmt *body;
};
struct Stmt_Loop {
- int id;
- Expr *condition;
- Stmt *body;
+ int id;
+ Expr *condition;
+ Stmt *body;
};
struct Stmt_Fork {
- int id;
- Expr *time;
- Stmt *body;
+ int id;
+ Expr *time;
+ Stmt *body;
};
struct Stmt_Catch {
- Stmt *body;
- Except_Arm *excepts;
+ Stmt *body;
+ Except_Arm *excepts;
};
struct Stmt_Finally {
- Stmt *body;
- Stmt *handler;
+ Stmt *body;
+ Stmt *handler;
};
enum Stmt_Kind {
@@ -174,49 +174,52 @@ enum Stmt_Kind {
};
union Stmt_Data {
- struct Stmt_Cond cond;
- struct Stmt_List list;
- struct Stmt_Range range;
- struct Stmt_Loop loop;
- struct Stmt_Fork fork;
- struct Stmt_Catch catch;
- struct Stmt_Finally finally;
- Expr *expr;
- int exit;
+ struct Stmt_Cond cond;
+ struct Stmt_List list;
+ struct Stmt_Range range;
+ struct Stmt_Loop loop;
+ struct Stmt_Fork fork;
+ struct Stmt_Catch catch;
+ struct Stmt_Finally finally;
+ Expr *expr;
+ int exit;
};
struct Stmt {
- Stmt *next;
- enum Stmt_Kind kind;
- union Stmt_Data s;
+ Stmt *next;
+ enum Stmt_Kind kind;
+ union Stmt_Data s;
};
-
-extern void begin_code_allocation(void);
-extern void end_code_allocation(int);
-extern Stmt *alloc_stmt(enum Stmt_Kind);
-extern Cond_Arm *alloc_cond_arm(Expr *, Stmt *);
-extern Expr *alloc_expr(enum Expr_Kind);
-extern Expr *alloc_var(var_type);
-extern Expr *alloc_binary(enum Expr_Kind, Expr *, Expr *);
-extern Expr *alloc_verb(Expr *, Expr *, Arg_List *);
-extern Arg_List *alloc_arg_list(enum Arg_Kind, Expr *);
-extern Except_Arm *alloc_except(int, Arg_List *, Stmt *);
-extern Scatter *alloc_scatter(enum Scatter_Kind, int, Expr *);
-extern char *alloc_string(const char *);
-extern double *alloc_float(double);
+extern void begin_code_allocation(void);
+extern void end_code_allocation(int);
-extern void dealloc_node(void *);
-extern void dealloc_string(char *);
-extern void free_stmt(Stmt *);
+extern Stmt *alloc_stmt(enum Stmt_Kind);
+extern Cond_Arm *alloc_cond_arm(Expr *, Stmt *);
+extern Expr *alloc_expr(enum Expr_Kind);
+extern Expr *alloc_var(var_type);
+extern Expr *alloc_binary(enum Expr_Kind, Expr *, Expr *);
+extern Expr *alloc_verb(Expr *, Expr *, Arg_List *);
+extern Arg_List *alloc_arg_list(enum Arg_Kind, Expr *);
+extern Except_Arm *alloc_except(int, Arg_List *, Stmt *);
+extern Scatter *alloc_scatter(enum Scatter_Kind, int, Expr *);
+extern char *alloc_string(const char *);
+extern double *alloc_float(double);
-#endif /* !AST_h */
+extern void dealloc_node(void *);
+extern void dealloc_string(char *);
+extern void free_stmt(Stmt *);
+
+#endif /* !AST_h */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:22 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.3 1996/02/08 05:59:43 pavel
* Updated copyright notice for 1996. Added exponentiation expression, named
* WHILE loops, BREAK and CONTINUE statements, support for floating-point.
diff --git a/client_bsd.c b/client_bsd.c
index 649a11e..04827a6 100644
--- a/client_bsd.c
+++ b/client_bsd.c
@@ -33,9 +33,9 @@
void
main(int argc, char **argv)
{
- const char *connect_file = DEFAULT_CONNECT_FILE;
- int s;
- struct sockaddr_un address;
+ const char *connect_file = DEFAULT_CONNECT_FILE;
+ int s;
+ struct sockaddr_un address;
if (argc == 2)
connect_file = argv[1];
@@ -43,12 +43,10 @@ main(int argc, char **argv)
fprintf(stderr, "Usage: %s [server-connect-file]\n", argv[0]);
exit(1);
}
-
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
perror("socket");
exit(1);
}
-
address.sun_family = AF_UNIX;
strcpy(address.sun_path, connect_file);
@@ -57,10 +55,9 @@ main(int argc, char **argv)
perror("connect");
exit(1);
}
-
while (1) {
- fd_set input;
- char buffer[1024];
+ fd_set input;
+ char buffer[1024];
FD_ZERO(&input);
FD_SET(0, &input);
@@ -90,9 +87,12 @@ main(int argc, char **argv)
char rcsid_client_bsd[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:23 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/03/10 01:11:49 pavel
* Moved definition of DEFAULT_CONNECT_FILE to options.h. Release 1.8.0.
*
diff --git a/client_sysv.c b/client_sysv.c
index 79b97f0..b2868e8 100644
--- a/client_sysv.c
+++ b/client_sysv.c
@@ -75,22 +75,22 @@ write_all(int fd, const char *buffer, int length)
void
main(int argc, char **argv)
{
- const char *connect_file = DEFAULT_CONNECT_FILE;
- int server_fifo;
- const char *dir;
- char c2s[1000], s2c[1000], connect[2010];
- int pid = getpid();
- int rfd, wfd;
- int use_home_dir = 0;
- char *prog_name = argv[0];
-
- while (--argc && **(++argv) == '-') {
+ const char *connect_file = DEFAULT_CONNECT_FILE;
+ int server_fifo;
+ const char *dir;
+ char c2s[1000], s2c[1000], connect[2010];
+ int pid = getpid();
+ int rfd, wfd;
+ int use_home_dir = 0;
+ char *prog_name = argv[0];
+
+ while (--argc && **(++argv) == '-') {
switch ((*argv)[1]) {
- case 'h':
+ case 'h':
use_home_dir = 1;
break;
- default:
+ default:
goto usage;
}
}
@@ -104,28 +104,25 @@ main(int argc, char **argv)
signal(SIGINT, kill_signal);
signal(SIGQUIT, kill_signal);
- if (!use_home_dir || !(dir = getenv("HOME")))
+ if (!use_home_dir || !(dir = getenv("HOME")))
dir = "/usr/tmp";
sprintf(c2s, "%s/.c2s-%05d", dir, (int) pid);
sprintf(s2c, "%s/.s2c-%05d", dir, (int) pid);
- if (mkfifo(c2s, 0000) < 0 || chmod(c2s, 0644) < 0
- || mkfifo(s2c, 0000) < 0 || chmod(s2c, 0622) < 0) {
+ if (mkfifo(c2s, 0000) < 0 || chmod(c2s, 0644) < 0
+ || mkfifo(s2c, 0000) < 0 || chmod(s2c, 0622) < 0) {
perror("Creating personal FIFOs");
goto die;
}
-
if ((rfd = open(s2c, O_RDONLY | NONBLOCK_FLAG)) < 0) {
perror("Opening server-to-client FIFO");
goto die;
}
-
if ((server_fifo = open(connect_file, O_WRONLY | NONBLOCK_FLAG)) < 0) {
perror("Opening server FIFO");
goto die;
}
-
sprintf(connect, "\n%s %s\n", c2s, s2c);
write(server_fifo, connect, strlen(connect));
close(server_fifo);
@@ -134,27 +131,24 @@ main(int argc, char **argv)
perror("Opening client-to-server FIFO");
goto die;
}
-
remove(c2s);
remove(s2c);
fprintf(stderr, "[Connected to server]\n");
- if (!set_non_blocking(0) || !set_non_blocking(rfd)) {
+ if (!set_non_blocking(0) || !set_non_blocking(rfd)) {
perror("Setting connection non-blocking");
exit(1);
}
-
while (1) {
- char buffer[1024];
- int count, did_some = 0;
+ char buffer[1024];
+ int count, did_some = 0;
count = read(0, buffer, sizeof(buffer));
if (count > 0) {
did_some = 1;
write_all(wfd, buffer, count);
}
-
count = read(rfd, buffer, sizeof(buffer));
if (count > 0) {
did_some = 1;
@@ -164,7 +158,6 @@ main(int argc, char **argv)
} else
write_all(1, buffer, count);
}
-
if (!did_some)
sleep(1);
}
@@ -185,9 +178,12 @@ main(int argc, char **argv)
char rcsid_client_sysv[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:23 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.3 1996/03/10 01:11:56 pavel
* Moved definition of DEFAULT_CONNECT_FILE to options.h. Release 1.8.0.
*
diff --git a/code_gen.c b/code_gen.c
index 84ef9f8..1501db0 100644
--- a/code_gen.c
+++ b/code_gen.c
@@ -17,7 +17,7 @@
#include <limits.h>
-#include "ast.h"
+#include "ast.h"
#include "exceptions.h"
#include "opcode.h"
#include "program.h"
@@ -36,53 +36,52 @@ enum fixup_kind {
};
struct fixup {
- enum fixup_kind kind;
- unsigned pc;
- unsigned value;
- unsigned prev_literals, prev_forks, prev_var_refs, prev_labels,
- prev_stacks;
- int next; /* chain for compiling IF/ELSEIF arms */
+ enum fixup_kind kind;
+ unsigned pc;
+ unsigned value;
+ unsigned prev_literals, prev_forks, prev_var_refs, prev_labels,
+ prev_stacks;
+ int next; /* chain for compiling IF/ELSEIF arms */
};
-typedef struct fixup Fixup;
+typedef struct fixup Fixup;
struct gstate {
- unsigned total_var_refs; /* For duplicating an old bug... */
- unsigned num_literals, max_literals;
- Var *literals;
- unsigned num_fork_vectors, max_fork_vectors;
- Bytecodes *fork_vectors;
+ unsigned total_var_refs; /* For duplicating an old bug... */
+ unsigned num_literals, max_literals;
+ Var *literals;
+ unsigned num_fork_vectors, max_fork_vectors;
+ Bytecodes *fork_vectors;
};
-typedef struct gstate GState;
+typedef struct gstate GState;
struct loop {
- int id;
- Fixup top_label;
- unsigned top_stack;
- int bottom_label;
- unsigned bottom_stack;
+ int id;
+ Fixup top_label;
+ unsigned top_stack;
+ int bottom_label;
+ unsigned bottom_stack;
};
-typedef struct loop Loop;
+typedef struct loop Loop;
struct state {
- unsigned max_literal, max_fork, max_var_ref;
- /* For telling how big the refs must be */
- unsigned num_literals, num_forks, num_var_refs, num_labels,
- num_stacks;
- /* For computing the final vector length */
- unsigned num_fixups, max_fixups;
- Fixup *fixups;
- unsigned num_bytes, max_bytes;
- Byte *bytes;
- unsigned cur_stack, max_stack;
- unsigned saved_stack;
- unsigned num_loops, max_loops;
- Loop *loops;
- GState *gstate;
+ unsigned max_literal, max_fork, max_var_ref;
+ /* For telling how big the refs must be */
+ unsigned num_literals, num_forks, num_var_refs, num_labels, num_stacks;
+ /* For computing the final vector length */
+ unsigned num_fixups, max_fixups;
+ Fixup *fixups;
+ unsigned num_bytes, max_bytes;
+ Byte *bytes;
+ unsigned cur_stack, max_stack;
+ unsigned saved_stack;
+ unsigned num_loops, max_loops;
+ Loop *loops;
+ GState *gstate;
};
-typedef struct state State;
+typedef struct state State;
static void
-init_gstate(GState *gstate)
+init_gstate(GState * gstate)
{
gstate->total_var_refs = 0;
gstate->num_literals = gstate->num_fork_vectors = 0;
@@ -101,7 +100,7 @@ free_gstate(GState gstate)
}
static void
-init_state(State *state, GState *gstate)
+init_state(State * state, GState * gstate)
{
state->num_literals = state->num_forks = state->num_labels = 0;
state->num_var_refs = state->num_stacks = 0;
@@ -135,13 +134,13 @@ free_state(State state)
}
static void
-emit_byte(Byte b, State *state)
+emit_byte(Byte b, State * state)
{
if (state->num_bytes == state->max_bytes) {
- unsigned new_max = 2 * state->max_bytes;
- Byte *new_bytes = mymalloc(sizeof(Byte) * new_max,
- M_BYTECODES);
- unsigned i;
+ unsigned new_max = 2 * state->max_bytes;
+ Byte *new_bytes = mymalloc(sizeof(Byte) * new_max,
+ M_BYTECODES);
+ unsigned i;
for (i = 0; i < state->num_bytes; i++)
new_bytes[i] = state->bytes[i];
@@ -150,26 +149,25 @@ emit_byte(Byte b, State *state)
state->bytes = new_bytes;
state->max_bytes = new_max;
}
-
state->bytes[state->num_bytes++] = b;
}
static void
-emit_extended_byte(Byte b, State *state)
+emit_extended_byte(Byte b, State * state)
{
emit_byte(OP_EXTENDED, state);
emit_byte(b, state);
}
static int
-add_known_fixup(Fixup f, State *state)
+add_known_fixup(Fixup f, State * state)
{
- int i;
+ int i;
if (state->num_fixups == state->max_fixups) {
- unsigned new_max = 2 * state->max_fixups;
- Fixup *new_fixups = mymalloc(sizeof(Fixup) * new_max,
- M_CODE_GEN);
+ unsigned new_max = 2 * state->max_fixups;
+ Fixup *new_fixups = mymalloc(sizeof(Fixup) * new_max,
+ M_CODE_GEN);
for (i = 0; i < state->num_fixups; i++)
new_fixups[i] = state->fixups[i];
@@ -178,7 +176,6 @@ add_known_fixup(Fixup f, State *state)
state->fixups = new_fixups;
state->max_fixups = new_max;
}
-
f.pc = state->num_bytes;
state->fixups[i = state->num_fixups++] = f;
@@ -188,9 +185,9 @@ add_known_fixup(Fixup f, State *state)
}
static int
-add_linked_fixup(enum fixup_kind kind, unsigned value, int next, State *state)
+add_linked_fixup(enum fixup_kind kind, unsigned value, int next, State * state)
{
- Fixup f;
+ Fixup f;
f.kind = kind;
f.value = value;
@@ -204,30 +201,30 @@ add_linked_fixup(enum fixup_kind kind, unsigned value, int next, State *state)
}
static int
-add_fixup(enum fixup_kind kind, unsigned value, State *state)
+add_fixup(enum fixup_kind kind, unsigned value, State * state)
{
return add_linked_fixup(kind, value, -1, state);
}
static void
-add_literal(Var v, State *state)
+add_literal(Var v, State * state)
{
- GState *gstate = state->gstate;
- Var *literals = gstate->literals;
- unsigned i;
+ GState *gstate = state->gstate;
+ Var *literals = gstate->literals;
+ unsigned i;
for (i = 0; i < gstate->num_literals; i++)
- if (v.type == literals[i].type /* no int/float coercion here */
+ if (v.type == literals[i].type /* no int/float coercion here */
&& equality(v, literals[i], 1))
break;
if (i == gstate->num_literals) {
/* New literal to intern */
if (gstate->num_literals == gstate->max_literals) {
- unsigned new_max = gstate->max_literals == 0
- ? 5 : 2 * gstate->max_literals;
- Var *new_literals = mymalloc(sizeof(Var) * new_max,
- M_CODE_GEN);
+ unsigned new_max = gstate->max_literals == 0
+ ? 5 : 2 * gstate->max_literals;
+ Var *new_literals = mymalloc(sizeof(Var) * new_max,
+ M_CODE_GEN);
if (gstate->literals) {
for (i = 0; i < gstate->num_literals; i++)
@@ -235,14 +232,11 @@ add_literal(Var v, State *state)
myfree(literals, M_CODE_GEN);
}
-
gstate->literals = new_literals;
gstate->max_literals = new_max;
}
-
gstate->literals[i = gstate->num_literals++] = var_ref(v);
}
-
add_fixup(FIXUP_LITERAL, i, state);
state->num_literals++;
if (i > state->max_literal)
@@ -250,16 +244,16 @@ add_literal(Var v, State *state)
}
static void
-add_fork(Bytecodes b, State *state)
+add_fork(Bytecodes b, State * state)
{
- unsigned i;
- GState *gstate = state->gstate;
+ unsigned i;
+ GState *gstate = state->gstate;
if (gstate->num_fork_vectors == gstate->max_fork_vectors) {
- unsigned new_max = gstate->max_fork_vectors == 0
- ? 1 : 2 * gstate->max_fork_vectors;
- Bytecodes *new_fv = mymalloc(sizeof(Bytecodes) * new_max,
- M_CODE_GEN);
+ unsigned new_max = gstate->max_fork_vectors == 0
+ ? 1 : 2 * gstate->max_fork_vectors;
+ Bytecodes *new_fv = mymalloc(sizeof(Bytecodes) * new_max,
+ M_CODE_GEN);
if (gstate->fork_vectors) {
for (i = 0; i < gstate->num_fork_vectors; i++)
@@ -267,11 +261,9 @@ add_fork(Bytecodes b, State *state)
myfree(gstate->fork_vectors, M_CODE_GEN);
}
-
gstate->fork_vectors = new_fv;
gstate->max_fork_vectors = new_max;
}
-
gstate->fork_vectors[i = gstate->num_fork_vectors++] = b;
add_fixup(FIXUP_FORK, i, state);
@@ -281,7 +273,7 @@ add_fork(Bytecodes b, State *state)
}
static void
-add_var_ref(unsigned slot, State *state)
+add_var_ref(unsigned slot, State * state)
{
add_fixup(FIXUP_VAR_REF, slot, state);
state->num_var_refs++;
@@ -291,24 +283,24 @@ add_var_ref(unsigned slot, State *state)
}
static int
-add_linked_label(int next, State *state)
+add_linked_label(int next, State * state)
{
- int label = add_linked_fixup(FIXUP_LABEL, 0, next, state);
+ int label = add_linked_fixup(FIXUP_LABEL, 0, next, state);
state->num_labels++;
return label;
}
static int
-add_label(State *state)
+add_label(State * state)
{
return add_linked_label(-1, state);
}
static void
-add_pseudo_label(unsigned value, State *state)
+add_pseudo_label(unsigned value, State * state)
{
- Fixup f;
+ Fixup f;
f.kind = FIXUP_LABEL;
f.value = value;
@@ -321,18 +313,18 @@ add_pseudo_label(unsigned value, State *state)
}
static int
-add_known_label(Fixup f, State *state)
+add_known_label(Fixup f, State * state)
{
- int label = add_known_fixup(f, state);
+ int label = add_known_fixup(f, state);
state->num_labels++;
return label;
}
static Fixup
-capture_label(State *state)
+capture_label(State * state)
{
- Fixup f;
+ Fixup f;
f.kind = FIXUP_LABEL;
f.value = state->num_bytes;
@@ -346,12 +338,12 @@ capture_label(State *state)
}
static void
-define_label(int label, State *state)
+define_label(int label, State * state)
{
- unsigned value = state->num_bytes;
+ unsigned value = state->num_bytes;
while (label != -1) {
- Fixup *fixup = &(state->fixups[label]);
+ Fixup *fixup = &(state->fixups[label]);
fixup->value = value;
fixup->prev_literals = state->num_literals;
@@ -363,13 +355,13 @@ define_label(int label, State *state)
}
static void
-add_stack_ref(unsigned index, State *state)
+add_stack_ref(unsigned index, State * state)
{
add_fixup(FIXUP_STACK, index, state);
}
static void
-push_stack(unsigned n, State *state)
+push_stack(unsigned n, State * state)
{
state->cur_stack += n;
if (state->cur_stack > state->max_stack)
@@ -377,15 +369,15 @@ push_stack(unsigned n, State *state)
}
static void
-pop_stack(unsigned n, State *state)
+pop_stack(unsigned n, State * state)
{
state->cur_stack -= n;
}
static unsigned
-save_stack_top(State *state)
+save_stack_top(State * state)
{
- unsigned old = state->saved_stack;
+ unsigned old = state->saved_stack;
state->saved_stack = state->cur_stack - 1;
@@ -393,28 +385,28 @@ save_stack_top(State *state)
}
static unsigned
-saved_stack_top(State *state)
+saved_stack_top(State * state)
{
return state->saved_stack;
}
static void
-restore_stack_top(unsigned old, State *state)
+restore_stack_top(unsigned old, State * state)
{
state->saved_stack = old;
}
static void
enter_loop(int id, Fixup top_label, unsigned top_stack,
- int bottom_label, unsigned bottom_stack, State *state)
+ int bottom_label, unsigned bottom_stack, State * state)
{
- int i;
- Loop *loop;
+ int i;
+ Loop *loop;
if (state->num_loops == state->max_loops) {
- unsigned new_max = 2 * state->max_loops;
- Loop *new_loops = mymalloc(sizeof(Loop) * new_max,
- M_CODE_GEN);
+ unsigned new_max = 2 * state->max_loops;
+ Loop *new_loops = mymalloc(sizeof(Loop) * new_max,
+ M_CODE_GEN);
for (i = 0; i < state->num_loops; i++)
new_loops[i] = state->loops[i];
@@ -423,7 +415,6 @@ enter_loop(int id, Fixup top_label, unsigned top_stack,
state->loops = new_loops;
state->max_loops = new_max;
}
-
loop = &(state->loops[state->num_loops++]);
loop->id = id;
loop->top_label = top_label;
@@ -433,34 +424,33 @@ enter_loop(int id, Fixup top_label, unsigned top_stack,
}
static int
-exit_loop(State *state)
+exit_loop(State * state)
{
return state->loops[--state->num_loops].bottom_label;
}
-
+
static void
-emit_var_op(Opcode op, unsigned slot, State *state)
+emit_var_op(Opcode op, unsigned slot, State * state)
{
if (slot >= NUM_READY_VARS) {
emit_byte(op + NUM_READY_VARS, state);
add_var_ref(slot, state);
- } else
+ } else
emit_byte(op + slot, state);
}
static void generate_expr(Expr *, State *);
static void
-generate_arg_list(Arg_List *args, State *state)
+generate_arg_list(Arg_List * args, State * state)
{
if (!args) {
emit_byte(OP_MAKE_EMPTY_LIST, state);
push_stack(1, state);
} else {
- Opcode normal_op = OP_MAKE_SINGLETON_LIST,
- splice_op = OP_CHECK_LIST_FOR_SPLICE;
- unsigned pop = 0;
+ Opcode normal_op = OP_MAKE_SINGLETON_LIST, splice_op = OP_CHECK_LIST_FOR_SPLICE;
+ unsigned pop = 0;
for (; args; args = args->next) {
generate_expr(args->expr, state);
@@ -474,19 +464,19 @@ generate_arg_list(Arg_List *args, State *state)
}
static void
-push_lvalue(Expr *expr, int indexed_above, State *state)
+push_lvalue(Expr * expr, int indexed_above, State * state)
{
- unsigned old;
+ unsigned old;
switch (expr->kind) {
- case EXPR_RANGE:
+ case EXPR_RANGE:
push_lvalue(expr->e.range.base, 1, state);
old = save_stack_top(state);
generate_expr(expr->e.range.from, state);
generate_expr(expr->e.range.to, state);
restore_stack_top(old, state);
break;
- case EXPR_INDEX:
+ case EXPR_INDEX:
push_lvalue(expr->e.bin.lhs, 1, state);
old = save_stack_top(state);
generate_expr(expr->e.bin.rhs, state);
@@ -496,13 +486,13 @@ push_lvalue(Expr *expr, int indexed_above, State *state)
push_stack(1, state);
}
break;
- case EXPR_ID:
+ case EXPR_ID:
if (indexed_above) {
emit_var_op(OP_PUSH, expr->e.id, state);
push_stack(1, state);
}
break;
- case EXPR_PROP:
+ case EXPR_PROP:
generate_expr(expr->e.bin.lhs, state);
generate_expr(expr->e.bin.rhs, state);
if (indexed_above) {
@@ -510,13 +500,13 @@ push_lvalue(Expr *expr, int indexed_above, State *state)
push_stack(1, state);
}
break;
- default:
+ default:
panic("Bad lvalue in PUSH_LVALUE()");
}
}
static void
-generate_codes(Arg_List *codes, State *state)
+generate_codes(Arg_List * codes, State * state)
{
if (codes)
generate_arg_list(codes, state);
@@ -527,12 +517,12 @@ generate_codes(Arg_List *codes, State *state)
}
static void
-generate_expr(Expr *expr, State *state)
+generate_expr(Expr * expr, State * state)
{
switch (expr->kind) {
- case EXPR_VAR:
+ case EXPR_VAR:
{
- Var v;
+ Var v;
v = expr->e.var;
if (v.type == TYPE_INT && IN_OPTIM_NUM_RANGE(v.v.num))
@@ -544,14 +534,14 @@ generate_expr(Expr *expr, State *state)
push_stack(1, state);
}
break;
- case EXPR_ID:
+ case EXPR_ID:
emit_var_op(OP_PUSH, expr->e.id, state);
push_stack(1, state);
break;
- case EXPR_AND:
- case EXPR_OR:
+ case EXPR_AND:
+ case EXPR_OR:
{
- int end_label;
+ int end_label;
generate_expr(expr->e.bin.lhs, state);
emit_byte(expr->kind == EXPR_AND ? OP_AND : OP_OR, state);
@@ -561,60 +551,88 @@ generate_expr(Expr *expr, State *state)
define_label(end_label, state);
}
break;
- case EXPR_NEGATE:
- case EXPR_NOT:
+ case EXPR_NEGATE:
+ case EXPR_NOT:
generate_expr(expr->e.expr, state);
emit_byte(expr->kind == EXPR_NOT ? OP_NOT : OP_UNARY_MINUS, state);
break;
- case EXPR_EQ:
- case EXPR_NE:
- case EXPR_GE:
- case EXPR_GT:
- case EXPR_LE:
- case EXPR_LT:
- case EXPR_IN:
- case EXPR_PLUS:
- case EXPR_MINUS:
- case EXPR_TIMES:
- case EXPR_DIVIDE:
- case EXPR_MOD:
- case EXPR_PROP:
+ case EXPR_EQ:
+ case EXPR_NE:
+ case EXPR_GE:
+ case EXPR_GT:
+ case EXPR_LE:
+ case EXPR_LT:
+ case EXPR_IN:
+ case EXPR_PLUS:
+ case EXPR_MINUS:
+ case EXPR_TIMES:
+ case EXPR_DIVIDE:
+ case EXPR_MOD:
+ case EXPR_PROP:
{
- Opcode op = OP_ADD; /* initialize to silence warning */
+ Opcode op = OP_ADD; /* initialize to silence warning */
generate_expr(expr->e.bin.lhs, state);
generate_expr(expr->e.bin.rhs, state);
switch (expr->kind) {
- case EXPR_EQ: op = OP_EQ; break;
- case EXPR_NE: op = OP_NE; break;
- case EXPR_GE: op = OP_GE; break;
- case EXPR_GT: op = OP_GT; break;
- case EXPR_LE: op = OP_LE; break;
- case EXPR_LT: op = OP_LT; break;
- case EXPR_IN: op = OP_IN; break;
- case EXPR_PLUS: op = OP_ADD; break;
- case EXPR_MINUS: op = OP_MINUS; break;
- case EXPR_TIMES: op = OP_MULT; break;
- case EXPR_DIVIDE: op = OP_DIV; break;
- case EXPR_MOD: op = OP_MOD; break;
- case EXPR_PROP: op = OP_GET_PROP; break;
- case EXPR_INDEX: op = OP_REF; break;
- default:
+ case EXPR_EQ:
+ op = OP_EQ;
+ break;
+ case EXPR_NE:
+ op = OP_NE;
+ break;
+ case EXPR_GE:
+ op = OP_GE;
+ break;
+ case EXPR_GT:
+ op = OP_GT;
+ break;
+ case EXPR_LE:
+ op = OP_LE;
+ break;
+ case EXPR_LT:
+ op = OP_LT;
+ break;
+ case EXPR_IN:
+ op = OP_IN;
+ break;
+ case EXPR_PLUS:
+ op = OP_ADD;
+ break;
+ case EXPR_MINUS:
+ op = OP_MINUS;
+ break;
+ case EXPR_TIMES:
+ op = OP_MULT;
+ break;
+ case EXPR_DIVIDE:
+ op = OP_DIV;
+ break;
+ case EXPR_MOD:
+ op = OP_MOD;
+ break;
+ case EXPR_PROP:
+ op = OP_GET_PROP;
+ break;
+ case EXPR_INDEX:
+ op = OP_REF;
+ break;
+ default:
panic("Not a binary operator in GENERATE_EXPR()");
}
emit_byte(op, state);
pop_stack(1, state);
}
break;
- case EXPR_EXP:
+ case EXPR_EXP:
generate_expr(expr->e.bin.lhs, state);
generate_expr(expr->e.bin.rhs, state);
emit_extended_byte(EOP_EXP, state);
pop_stack(1, state);
break;
- case EXPR_INDEX:
+ case EXPR_INDEX:
{
- unsigned old;
+ unsigned old;
generate_expr(expr->e.bin.lhs, state);
old = save_stack_top(state);
@@ -624,9 +642,9 @@ generate_expr(Expr *expr, State *state)
pop_stack(1, state);
}
break;
- case EXPR_RANGE:
+ case EXPR_RANGE:
{
- unsigned old;
+ unsigned old;
generate_expr(expr->e.range.base, state);
old = save_stack_top(state);
@@ -637,9 +655,9 @@ generate_expr(Expr *expr, State *state)
pop_stack(2, state);
}
break;
- case EXPR_LENGTH:
+ case EXPR_LENGTH:
{
- unsigned saved = saved_stack_top(state);
+ unsigned saved = saved_stack_top(state);
if (saved != UINT_MAX) {
emit_extended_byte(EOP_LENGTH, state);
@@ -649,25 +667,25 @@ generate_expr(Expr *expr, State *state)
panic("Missing saved stack for `$' in GENERATE_EXPR()");
}
break;
- case EXPR_LIST:
+ case EXPR_LIST:
generate_arg_list(expr->e.list, state);
break;
- case EXPR_CALL:
+ case EXPR_CALL:
generate_arg_list(expr->e.call.args, state);
emit_byte(OP_BI_FUNC_CALL, state);
emit_byte(expr->e.call.func, state);
break;
- case EXPR_VERB:
+ case EXPR_VERB:
generate_expr(expr->e.verb.obj, state);
generate_expr(expr->e.verb.verb, state);
generate_arg_list(expr->e.verb.args, state);
emit_byte(OP_CALL_VERB, state);
pop_stack(2, state);
break;
- case EXPR_COND:
+ case EXPR_COND:
{
- int else_label, end_label;
-
+ int else_label, end_label;
+
generate_expr(expr->e.cond.condition, state);
emit_byte(OP_IF_QUES, state);
else_label = add_label(state);
@@ -681,15 +699,15 @@ generate_expr(Expr *expr, State *state)
define_label(end_label, state);
}
break;
- case EXPR_ASGN:
+ case EXPR_ASGN:
{
- Expr *e = expr->e.bin.lhs;
+ Expr *e = expr->e.bin.lhs;
if (e->kind == EXPR_SCATTER) {
- int nargs = 0, nreq = 0, rest = -1;
- unsigned done;
- Scatter *sc;
-
+ int nargs = 0, nreq = 0, rest = -1;
+ unsigned done;
+ Scatter *sc;
+
generate_expr(expr->e.bin.rhs, state);
for (sc = e->e.scatter; sc; sc = sc->next) {
nargs++;
@@ -715,7 +733,7 @@ generate_expr(Expr *expr, State *state)
}
done = add_label(state);
for (sc = e->e.scatter; sc; sc = sc->next)
- if (sc->kind == SCAT_OPTIONAL && sc->expr) {
+ if (sc->kind == SCAT_OPTIONAL && sc->expr) {
define_label(sc->label, state);
generate_expr(sc->expr, state);
emit_var_op(OP_PUT, sc->id, state);
@@ -724,7 +742,7 @@ generate_expr(Expr *expr, State *state)
}
define_label(done, state);
} else {
- int is_indexed = 0;
+ int is_indexed = 0;
push_lvalue(e, 0, state);
generate_expr(expr->e.bin.rhs, state);
@@ -732,26 +750,26 @@ generate_expr(Expr *expr, State *state)
emit_byte(OP_PUT_TEMP, state);
while (1) {
switch (e->kind) {
- case EXPR_RANGE:
+ case EXPR_RANGE:
emit_extended_byte(EOP_RANGESET, state);
pop_stack(3, state);
e = e->e.range.base;
is_indexed = 1;
continue;
- case EXPR_INDEX:
+ case EXPR_INDEX:
emit_byte(OP_INDEXSET, state);
pop_stack(2, state);
e = e->e.bin.lhs;
is_indexed = 1;
continue;
- case EXPR_ID:
+ case EXPR_ID:
emit_var_op(OP_PUT, e->e.id, state);
break;
- case EXPR_PROP:
+ case EXPR_PROP:
emit_byte(OP_PUT_PROP, state);
pop_stack(2, state);
break;
- default:
+ default:
panic("Bad lvalue in GENERATE_EXPR()");
}
break;
@@ -763,9 +781,9 @@ generate_expr(Expr *expr, State *state)
}
}
break;
- case EXPR_CATCH:
+ case EXPR_CATCH:
{
- int handler_label, end_label;
+ int handler_label, end_label;
generate_codes(expr->e.catch.codes, state);
emit_extended_byte(EOP_PUSH_LABEL, state);
@@ -776,7 +794,7 @@ generate_expr(Expr *expr, State *state)
generate_expr(expr->e.expr, state);
emit_extended_byte(EOP_END_CATCH, state);
end_label = add_label(state);
- pop_stack(3, state); /* codes, label, catch */
+ pop_stack(3, state); /* codes, label, catch */
define_label(handler_label, state);
/* After this label, we still have a value on the stack, but now,
* instead of it being the value of the main expression, we have
@@ -794,7 +812,7 @@ generate_expr(Expr *expr, State *state)
define_label(end_label, state);
}
break;
- default:
+ default:
panic("Can't happen in GENERATE_EXPR()");
}
}
@@ -802,19 +820,19 @@ generate_expr(Expr *expr, State *state)
static Bytecodes stmt_to_code(Stmt *, GState *);
static void
-generate_stmt(Stmt *stmt, State *state)
+generate_stmt(Stmt * stmt, State * state)
{
for (; stmt; stmt = stmt->next) {
switch (stmt->kind) {
- case STMT_COND:
+ case STMT_COND:
{
- Opcode if_op = OP_IF;
- int end_label = -1;
- Cond_Arm *arms;
+ Opcode if_op = OP_IF;
+ int end_label = -1;
+ Cond_Arm *arms;
for (arms = stmt->s.cond.arms; arms; arms = arms->next) {
- int else_label;
-
+ int else_label;
+
generate_expr(arms->condition, state);
emit_byte(if_op, state);
else_label = add_label(state);
@@ -831,13 +849,13 @@ generate_stmt(Stmt *stmt, State *state)
define_label(end_label, state);
}
break;
- case STMT_LIST:
+ case STMT_LIST:
{
- Fixup loop_top;
- int end_label;
-
+ Fixup loop_top;
+ int end_label;
+
generate_expr(stmt->s.list.expr, state);
- emit_byte(OPTIM_NUM_TO_OPCODE(1), state); /* loop list index */
+ emit_byte(OPTIM_NUM_TO_OPCODE(1), state); /* loop list index */
push_stack(1, state);
loop_top = capture_label(state);
emit_byte(OP_FOR_LIST, state);
@@ -853,11 +871,11 @@ generate_stmt(Stmt *stmt, State *state)
pop_stack(2, state);
}
break;
- case STMT_RANGE:
+ case STMT_RANGE:
{
- Fixup loop_top;
- int end_label;
-
+ Fixup loop_top;
+ int end_label;
+
generate_expr(stmt->s.range.from, state);
generate_expr(stmt->s.range.to, state);
loop_top = capture_label(state);
@@ -874,11 +892,11 @@ generate_stmt(Stmt *stmt, State *state)
pop_stack(2, state);
}
break;
- case STMT_WHILE:
+ case STMT_WHILE:
{
- Fixup loop_top;
- int end_label;
-
+ Fixup loop_top;
+ int end_label;
+
loop_top = capture_label(state);
generate_expr(stmt->s.loop.condition, state);
if (stmt->s.loop.id == -1)
@@ -898,7 +916,7 @@ generate_stmt(Stmt *stmt, State *state)
define_label(end_label, state);
}
break;
- case STMT_FORK:
+ case STMT_FORK:
generate_expr(stmt->s.fork.time, state);
if (stmt->s.fork.id >= 0)
emit_byte(OP_FORK_WITH_ID, state);
@@ -909,12 +927,12 @@ generate_stmt(Stmt *stmt, State *state)
add_var_ref(stmt->s.fork.id, state);
pop_stack(1, state);
break;
- case STMT_EXPR:
+ case STMT_EXPR:
generate_expr(stmt->s.expr, state);
emit_byte(OP_POP, state);
pop_stack(1, state);
break;
- case STMT_RETURN:
+ case STMT_RETURN:
if (stmt->s.expr) {
generate_expr(stmt->s.expr, state);
emit_byte(OP_RETURN, state);
@@ -922,10 +940,10 @@ generate_stmt(Stmt *stmt, State *state)
} else
emit_byte(OP_RETURN0, state);
break;
- case STMT_TRY_EXCEPT:
+ case STMT_TRY_EXCEPT:
{
- int end_label, arm_count = 0;
- Except_Arm *ex;
+ int end_label, arm_count = 0;
+ Except_Arm *ex;
for (ex = stmt->s.catch.excepts; ex; ex = ex->next) {
generate_codes(ex->codes, state);
@@ -940,10 +958,10 @@ generate_stmt(Stmt *stmt, State *state)
generate_stmt(stmt->s.catch.body, state);
emit_extended_byte(EOP_END_EXCEPT, state);
end_label = add_label(state);
- pop_stack(2 * arm_count + 1, state); /* 2(codes,pc) + catch */
+ pop_stack(2 * arm_count + 1, state); /* 2(codes,pc) + catch */
for (ex = stmt->s.catch.excepts; ex; ex = ex->next) {
define_label(ex->label, state);
- push_stack(1, state); /* exception tuple */
+ push_stack(1, state); /* exception tuple */
if (ex->id >= 0)
emit_var_op(OP_PUT, ex->id, state);
emit_byte(OP_POP, state);
@@ -957,29 +975,29 @@ generate_stmt(Stmt *stmt, State *state)
define_label(end_label, state);
}
break;
- case STMT_TRY_FINALLY:
+ case STMT_TRY_FINALLY:
{
- int handler_label;
+ int handler_label;
emit_extended_byte(EOP_TRY_FINALLY, state);
handler_label = add_label(state);
push_stack(1, state);
generate_stmt(stmt->s.finally.body, state);
emit_extended_byte(EOP_END_FINALLY, state);
- pop_stack(1, state); /* FINALLY marker */
+ pop_stack(1, state); /* FINALLY marker */
define_label(handler_label, state);
- push_stack(2, state); /* continuation value, reason */
+ push_stack(2, state); /* continuation value, reason */
generate_stmt(stmt->s.finally.handler, state);
emit_extended_byte(EOP_CONTINUE, state);
pop_stack(2, state);
}
break;
- case STMT_BREAK:
- case STMT_CONTINUE:
+ case STMT_BREAK:
+ case STMT_CONTINUE:
{
- int i;
- Loop *loop = 0; /* silence warnings */
-
+ int i;
+ Loop *loop = 0; /* silence warnings */
+
if (stmt->s.exit == -1) {
emit_extended_byte(EOP_EXIT, state);
if (state->num_loops == 0)
@@ -1007,7 +1025,7 @@ generate_stmt(Stmt *stmt, State *state)
}
}
break;
- default:
+ default:
panic("Can't happen in GENERATE_STMT()");
}
}
@@ -1031,13 +1049,13 @@ ref_size(unsigned max)
}
static Bytecodes
-stmt_to_code(Stmt *stmt, GState *gstate)
+stmt_to_code(Stmt * stmt, GState * gstate)
{
- State state;
- Bytecodes bc;
- unsigned old_i, new_i, fix_i;
- Fixup *fixup;
-
+ State state;
+ Bytecodes bc;
+ unsigned old_i, new_i, fix_i;
+ Fixup *fixup;
+
init_state(&state, gstate);
generate_stmt(stmt, &state);
@@ -1060,9 +1078,9 @@ stmt_to_code(Stmt *stmt, GState *gstate)
gstate->total_var_refs));
bc.size = state.num_bytes
- + (bc.numbytes_literal - 1) * state.num_literals
- + (bc.numbytes_fork - 1) * state.num_forks
- + (bc.numbytes_var_name - 1) * state.num_var_refs;
+ + (bc.numbytes_literal - 1) * state.num_literals
+ + (bc.numbytes_fork - 1) * state.num_forks
+ + (bc.numbytes_var_name - 1) * state.num_var_refs;
if (bc.size <= 256)
bc.numbytes_label = 1;
@@ -1082,44 +1100,44 @@ stmt_to_code(Stmt *stmt, GState *gstate)
for (old_i = new_i = 0; old_i < state.num_bytes; old_i++) {
if (fix_i < state.num_fixups && fixup->pc == old_i) {
- unsigned value, size = 0; /* initialized to silence warning */
+ unsigned value, size = 0; /* initialized to silence warning */
value = fixup->value;
switch (fixup->kind) {
- case FIXUP_LITERAL:
+ case FIXUP_LITERAL:
size = bc.numbytes_literal;
break;
- case FIXUP_FORK:
+ case FIXUP_FORK:
size = bc.numbytes_fork;
break;
- case FIXUP_VAR_REF:
+ case FIXUP_VAR_REF:
size = bc.numbytes_var_name;
break;
- case FIXUP_STACK:
+ case FIXUP_STACK:
size = bc.numbytes_stack;
break;
- case FIXUP_LABEL:
+ case FIXUP_LABEL:
value += fixup->prev_literals * (bc.numbytes_literal - 1)
- + fixup->prev_forks * (bc.numbytes_fork - 1)
- + fixup->prev_var_refs * (bc.numbytes_var_name - 1)
- + fixup->prev_labels * (bc.numbytes_label - 1)
- + fixup->prev_stacks * (bc.numbytes_stack - 1);
+ + fixup->prev_forks * (bc.numbytes_fork - 1)
+ + fixup->prev_var_refs * (bc.numbytes_var_name - 1)
+ + fixup->prev_labels * (bc.numbytes_label - 1)
+ + fixup->prev_stacks * (bc.numbytes_stack - 1);
size = bc.numbytes_label;
break;
- default:
+ default:
panic("Can't happen #1 in STMT_TO_CODE()");
}
switch (size) {
- case 4:
+ case 4:
bc.vector[new_i++] = value >> 24;
bc.vector[new_i++] = value >> 16;
- case 2:
+ case 2:
bc.vector[new_i++] = value >> 8;
- case 1:
+ case 1:
bc.vector[new_i++] = value;
break;
- default:
+ default:
panic("Can't happen #2 in STMT_TO_CODE()");
}
@@ -1134,11 +1152,11 @@ stmt_to_code(Stmt *stmt, GState *gstate)
return bc;
}
-Program *
-generate_code(Stmt *stmt, DB_Version version)
+Program *
+generate_code(Stmt * stmt, DB_Version version)
{
- Program *prog = new_program();
- GState gstate;
+ Program *prog = new_program();
+ GState gstate;
init_gstate(&gstate);
@@ -1146,7 +1164,7 @@ generate_code(Stmt *stmt, DB_Version version)
prog->version = version;
if (gstate.literals) {
- unsigned i;
+ unsigned i;
prog->literals = mymalloc(sizeof(Var) * gstate.num_literals,
M_LIT_LIST);
@@ -1159,7 +1177,7 @@ generate_code(Stmt *stmt, DB_Version version)
}
if (gstate.fork_vectors) {
- unsigned i;
+ unsigned i;
prog->fork_vectors =
mymalloc(sizeof(Bytecodes) * gstate.num_fork_vectors,
@@ -1180,9 +1198,12 @@ generate_code(Stmt *stmt, DB_Version version)
char rcsid_code_gen[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:24 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.4 1996/02/08 07:21:08 pavel
* Renamed TYPE_NUM to TYPE_INT. Added support for exponentiation expression,
* named WHILE loop and BREAK and CONTINUE statement. Updated copyright
diff --git a/code_gen.h b/code_gen.h
index f465682..58e5ac6 100644
--- a/code_gen.h
+++ b/code_gen.h
@@ -15,16 +15,19 @@
Pavel@Xerox.Com
*****************************************************************************/
-#include "ast.h"
+#include "ast.h"
#include "program.h"
#include "version.h"
-extern Program *generate_code(Stmt *, DB_Version);
+extern Program *generate_code(Stmt *, DB_Version);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:25 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/02/08 06:28:58 pavel
* Made generate_code() version-dependent. Updated copyright notice for 1996.
* Release 1.8.0beta1.
diff --git a/db.h b/db.h
index a11fbae..41c43e1 100644
--- a/db.h
+++ b/db.h
@@ -25,12 +25,12 @@
/**** file system ****/
-extern const char *db_usage_string(void);
+extern const char *db_usage_string(void);
/* Returns a string describing the database
* command-line arguments.
*/
-extern int db_initialize(int *pargc, char ***pargv);
+extern int db_initialize(int *pargc, char ***pargv);
/* (*pargc) and (*pargv) refer to the database
* command-line arguments and perhaps others.
* Returns true (and sets (*pargc) and (*pargv)
@@ -38,7 +38,7 @@ extern int db_initialize(int *pargc, char ***pargv);
* database args were valid.
*/
-extern int db_load(void);
+extern int db_load(void);
/* Does any necessary long-running preparations
* of the database, such as loading significant
* amounts of data into memory, returning true
@@ -53,15 +53,15 @@ enum db_flush_type {
* if necessary. */
FLUSH_PANIC /* Do all pending output; the server is going
* down in emergency mode. */
- };
+};
-extern int db_flush(enum db_flush_type);
+extern int db_flush(enum db_flush_type);
/* Flush some amount of the changed portion of
* the database to disk, as indicated by the
* argument. Returns true on success.
*/
-extern int32 db_disk_size(void);
+extern int32 db_disk_size(void);
/* Return the total size, in bytes, of the most
* recent full representation of the database
* as one or more disk files. Returns -1 if,
@@ -69,7 +69,7 @@ extern int32 db_disk_size(void);
* representation is currently available.
*/
-extern void db_shutdown(void);
+extern void db_shutdown(void);
/* Shut down the database module, flushing all
* pending database changes to disk and only
* returning after this is done.
@@ -77,13 +77,13 @@ extern void db_shutdown(void);
/**** objects ****/
-extern Objid db_create_object(void);
+extern Objid db_create_object(void);
/* Creates a new object with parent & location
* == #-1. Returns new object's id number.
*/
-extern Objid db_last_used_objid(void);
-extern void db_reset_last_used_objid(void);
+extern Objid db_last_used_objid(void);
+extern void db_reset_last_used_objid(void);
/* The former returns the highest object number
* ever returned by db_create_object(). The
* latter resets that high-water mark to the
@@ -91,21 +91,21 @@ extern void db_reset_last_used_objid(void);
* currently-valid object.
*/
-extern void db_destroy_object(Objid);
+extern void db_destroy_object(Objid);
/* Destroys object, freeing all associated
* storage. The object's parent and location
* must == #-1 and it must not have any
* children or contents.
*/
-extern Objid db_renumber_object(Objid);
+extern Objid db_renumber_object(Objid);
/* Renumbers object to have the lowest free
* object number. Returns its new number.
*/
-extern int valid(Objid);
+extern int valid(Objid);
-extern int db_object_bytes(Objid);
+extern int db_object_bytes(Objid);
/* Returns the number of bytes of memory
* currently required in order to represent the
* given object and all of its verbs and
@@ -114,31 +114,31 @@ extern int db_object_bytes(Objid);
/**** object attributes ****/
-extern Objid db_object_owner(Objid);
-extern void db_set_object_owner(Objid oid, Objid owner);
+extern Objid db_object_owner(Objid);
+extern void db_set_object_owner(Objid oid, Objid owner);
-extern const char *db_object_name(Objid);
-extern void db_set_object_name(Objid oid, const char *name);
+extern const char *db_object_name(Objid);
+extern void db_set_object_name(Objid oid, const char *name);
/* These functions do not change the reference
* count of the name they accept/return. Thus,
* the caller should str_ref() the name if the
* reference is to be persistent.
*/
-extern Objid db_object_parent(Objid);
-extern int db_count_children(Objid);
-extern int db_for_all_children(Objid,
- int (*)(void *, Objid),
- void *);
+extern Objid db_object_parent(Objid);
+extern int db_count_children(Objid);
+extern int db_for_all_children(Objid,
+ int (*)(void *, Objid),
+ void *);
/* The outcome is unspecified if any of the
* following functions are called during a call
* to db_for_all_children():
- * db_create_object()
- * db_destroy_object()
- * db_renumber_object()
- * db_change_parent()
+ * db_create_object()
+ * db_destroy_object()
+ * db_renumber_object()
+ * db_change_parent()
*/
-extern int db_change_parent(Objid oid, Objid parent);
+extern int db_change_parent(Objid oid, Objid parent);
/* db_change_parent() returns true (and
* actually changes the parent of OID) iff
* neither OID nor any of its descendents
@@ -147,35 +147,35 @@ extern int db_change_parent(Objid oid, Objid parent);
* its ancestors.
*/
-extern Objid db_object_location(Objid);
-extern int db_count_contents(Objid);
-extern int db_for_all_contents(Objid,
- int (*)(void *, Objid),
- void *);
+extern Objid db_object_location(Objid);
+extern int db_count_contents(Objid);
+extern int db_for_all_contents(Objid,
+ int (*)(void *, Objid),
+ void *);
/* The outcome is unspecified if any of the
* following functions are called during a call
* to db_for_all_contects():
- * db_destroy_object()
- * db_renumber_object()
- * db_change_location()
+ * db_destroy_object()
+ * db_renumber_object()
+ * db_change_location()
*/
-extern void db_change_location(Objid oid, Objid location);
+extern void db_change_location(Objid oid, Objid location);
/* NOTE: New flags must always be added to the end of this list, rather than
- * replacing one of the obsolete ones, since old databases might have
- * old objects around that still have that flag set.
+ * replacing one of the obsolete ones, since old databases might have
+ * old objects around that still have that flag set.
*/
typedef enum {
FLAG_USER, FLAG_PROGRAMMER, FLAG_WIZARD, FLAG_OBSOLETE_1,
FLAG_READ, FLAG_WRITE, FLAG_OBSOLETE_2, FLAG_FERTILE
} db_object_flag;
-extern int db_object_has_flag(Objid, db_object_flag);
-extern void db_set_object_flag(Objid, db_object_flag);
-extern void db_clear_object_flag(Objid, db_object_flag);
+extern int db_object_has_flag(Objid, db_object_flag);
+extern void db_set_object_flag(Objid, db_object_flag);
+extern void db_clear_object_flag(Objid, db_object_flag);
-extern int db_object_allows(Objid oid, Objid progr,
- db_object_flag flag);
+extern int db_object_allows(Objid oid, Objid progr,
+ db_object_flag flag);
/* Returns true iff either OID has FLAG or
* PROGR either is a wizard or owns OID; that
* is, iff PROGR's authority is sufficient to
@@ -183,29 +183,29 @@ extern int db_object_allows(Objid oid, Objid progr,
* OID.
*/
-extern int is_wizard(Objid oid);
-extern int is_programmer(Objid oid);
-extern int is_user(Objid oid);
+extern int is_wizard(Objid oid);
+extern int is_programmer(Objid oid);
+extern int is_user(Objid oid);
-extern Var db_all_users(void);
+extern Var db_all_users(void);
/* db_all_users() does not change the reference
* count of the `users' list maintained by this
* module. The caller should thus var_ref() it
* to make it persistent.
*/
-
+
/**** properties *****/
typedef enum {
- PF_READ = 01,
+ PF_READ = 01,
PF_WRITE = 02,
PF_CHOWN = 04
} db_prop_flag;
-extern int db_add_propdef(Objid oid, const char *pname,
- Var value, Objid owner,
- unsigned flags);
+extern int db_add_propdef(Objid oid, const char *pname,
+ Var value, Objid owner,
+ unsigned flags);
/* Returns true (and actually adds the property
* to OID) iff (1) no property named PNAME
* already exists on OID or one of its
@@ -218,8 +218,8 @@ extern int db_add_propdef(Objid oid, const char *pname,
* zero or more elements of `db_prop_flag'.
*/
-extern int db_rename_propdef(Objid oid, const char *old,
- const char *new);
+extern int db_rename_propdef(Objid oid, const char *old,
+ const char *new);
/* Returns true (and actually renames the
* propdef on OID) iff (1) a propdef with the
* name OLD existed on OID, (2) no property
@@ -230,16 +230,16 @@ extern int db_rename_propdef(Objid oid, const char *old,
* this is a no-op that returns true.
*/
-extern int db_delete_propdef(Objid, const char *);
+extern int db_delete_propdef(Objid, const char *);
/* Returns true iff a propdef with the given
- * name existed on the object (i.e., was there
+ * name existed on the object (i.e., was there
* to be deleted).
*/
-extern int db_count_propdefs(Objid);
-extern int db_for_all_propdefs(Objid,
- int (*)(void *, const char *),
- void *);
+extern int db_count_propdefs(Objid);
+extern int db_for_all_propdefs(Objid,
+ int (*)(void *, const char *),
+ void *);
/* db_for_all_propdefs() does not change the
* reference counts of the property names
* passed to the given callback function.
@@ -256,13 +256,13 @@ enum bi_prop {
};
typedef struct {
- enum bi_prop built_in; /* true iff property is a built-in one */
- Objid definer; /* if !built_in, the object defining prop */
- void *ptr; /* null iff property not found */
+ enum bi_prop built_in; /* true iff property is a built-in one */
+ Objid definer; /* if !built_in, the object defining prop */
+ void *ptr; /* null iff property not found */
} db_prop_handle;
-extern db_prop_handle db_find_property(Objid oid, const char *name,
- Var *value);
+extern db_prop_handle db_find_property(Objid oid, const char *name,
+ Var * value);
/* Returns a handle on the named property of
* the given object. If `value' is non-null,
* then the value of the named property (after
@@ -288,8 +288,8 @@ extern db_prop_handle db_find_property(Objid oid, const char *name,
* leave the handle intact.
*/
-extern Var db_property_value(db_prop_handle);
-extern void db_set_property_value(db_prop_handle, Var);
+extern Var db_property_value(db_prop_handle);
+extern void db_set_property_value(db_prop_handle, Var);
/* For non-built-in properties, these functions
* do not change the reference count of the
* value they accept/return, so the caller
@@ -303,23 +303,23 @@ extern void db_set_property_value(db_prop_handle, Var);
* illegal value for a built-in property.
*/
-extern Objid db_property_owner(db_prop_handle);
-extern void db_set_property_owner(db_prop_handle, Objid);
+extern Objid db_property_owner(db_prop_handle);
+extern void db_set_property_owner(db_prop_handle, Objid);
/* These functions may not be called for
- * built-in properties.
+ * built-in properties.
*/
-extern unsigned db_property_flags(db_prop_handle);
-extern void db_set_property_flags(db_prop_handle, unsigned);
+extern unsigned db_property_flags(db_prop_handle);
+extern void db_set_property_flags(db_prop_handle, unsigned);
/* The property flags are the result of ORing
- * together zero or more elements of
- * `db_prop_flag', defined above. These
- * functions may not be called for built-in
- * properties.
+ * together zero or more elements of
+ * `db_prop_flag', defined above. These
+ * functions may not be called for built-in
+ * properties.
*/
-extern int db_property_allows(db_prop_handle, Objid,
- db_prop_flag);
+extern int db_property_allows(db_prop_handle, Objid,
+ db_prop_flag);
/* Returns true iff either the property has the
* flag or the object either is a wizard or
* owns the property; that is, iff the object's
@@ -328,14 +328,14 @@ extern int db_property_allows(db_prop_handle, Objid,
* This function may not be called for built-in
* properties.
*/
-
+
/**** verbs ****/
typedef enum {
- VF_READ = 01,
- VF_WRITE = 02,
- VF_EXEC = 04,
+ VF_READ = 01,
+ VF_WRITE = 02,
+ VF_EXEC = 04,
VF_DEBUG = 010
} db_verb_flag;
@@ -344,13 +344,13 @@ typedef enum {
} db_arg_spec;
typedef enum {
- PREP_ANY = -2,
+ PREP_ANY = -2,
PREP_NONE = -1,
Other_Preps = 0 /* Others are indices into DB-internal table */
} db_prep_spec;
-extern db_prep_spec db_find_prep(int argc, char *argv[],
- int *first, int *last);
+extern db_prep_spec db_find_prep(int argc, char *argv[],
+ int *first, int *last);
/* Look for a prepositional phrase in the
* ARGC-element sequence ARGV, returning
* PREP_NONE if none was found. If FIRST and
@@ -361,13 +361,13 @@ extern db_prep_spec db_find_prep(int argc, char *argv[],
* unless the entire sequence is a phrase.
*/
-extern db_prep_spec db_match_prep(const char *);
+extern db_prep_spec db_match_prep(const char *);
/* Try to recognize the given string as a
* prepositional phrase, returning the
* appropriate db_prep_spec on success and
* PREP_NONE on failure. The string may be of
* the form
- * [#]<digit>+
+ * [#]<digit>+
* (an optional hash mark followed by one or
* more decimal digits). If the number so
* represented is a legitimate index for a
@@ -376,7 +376,7 @@ extern db_prep_spec db_match_prep(const char *);
* returned, or PREP_NONE otherwise.
*/
-extern const char *db_unparse_prep(db_prep_spec);
+extern const char *db_unparse_prep(db_prep_spec);
/* Returns a string giving the human-readable
* name(s) for the given preposition
* specification. The returned string may not
@@ -385,20 +385,20 @@ extern const char *db_unparse_prep(db_prep_spec);
* persistent.
*/
-extern void db_add_verb(Objid oid, const char *vnames,
- Objid owner, unsigned flags,
- db_arg_spec dobj, db_prep_spec prep,
- db_arg_spec iobj);
+extern void db_add_verb(Objid oid, const char *vnames,
+ Objid owner, unsigned flags,
+ db_arg_spec dobj, db_prep_spec prep,
+ db_arg_spec iobj);
/* This function does not change the reference
* count of the NAMES string it accepts. Thus,
* the caller should str_ref() it if it is to
* be persistent.
*/
-extern int db_count_verbs(Objid);
-extern int db_for_all_verbs(Objid,
- int (*)(void *, const char *),
- void *);
+extern int db_count_verbs(Objid);
+extern int db_for_all_verbs(Objid,
+ int (*)(void *, const char *),
+ void *);
/* db_for_all_verbs() does not change the
* reference counts of the verb names
* passed to the given callback function.
@@ -407,12 +407,12 @@ extern int db_for_all_verbs(Objid,
*/
typedef struct {
- void *ptr;
+ void *ptr;
} db_verb_handle;
-extern db_verb_handle db_find_command_verb(Objid oid, const char *verb,
- db_arg_spec dobj, unsigned prep,
- db_arg_spec iobj);
+extern db_verb_handle db_find_command_verb(Objid oid, const char *verb,
+ db_arg_spec dobj, unsigned prep,
+ db_arg_spec iobj);
/* Returns a handle on the first matching
* verb found defined on OID or one of its
* ancestors. A matching verb has a name
@@ -427,7 +427,7 @@ extern db_verb_handle db_find_command_verb(Objid oid, const char *verb,
* leave the handle intact.
*/
-extern db_verb_handle db_find_callable_verb(Objid oid, const char *verb);
+extern db_verb_handle db_find_callable_verb(Objid oid, const char *verb);
/* Returns a handle on the first verb found
* defined on OID or one of its ancestors with
* a name matching VERB (and, for now, the
@@ -439,8 +439,8 @@ extern db_verb_handle db_find_callable_verb(Objid oid, const char *verb);
* leave the handle intact.
*/
-extern db_verb_handle db_find_defined_verb(Objid oid, const char *verb,
- int allow_numbers);
+extern db_verb_handle db_find_defined_verb(Objid oid, const char *verb,
+ int allow_numbers);
/* Returns a handle on the first verb found
* defined on OID with a name matching VERB
* (or, if ALLOW_NUMBERS is true and VERB has
@@ -454,7 +454,7 @@ extern db_verb_handle db_find_defined_verb(Objid oid, const char *verb,
* leave the handle intact.
*/
-extern db_verb_handle db_find_indexed_verb(Objid oid, unsigned index);
+extern db_verb_handle db_find_indexed_verb(Objid oid, unsigned index);
/* Returns a handle on the 1-based INDEX'th
* verb defined on OID. The `ptr' in the
* result is null iff there is no such verb.
@@ -464,43 +464,43 @@ extern db_verb_handle db_find_indexed_verb(Objid oid, unsigned index);
* leave the handle intact.
*/
-extern Objid db_verb_definer(db_verb_handle);
+extern Objid db_verb_definer(db_verb_handle);
/* Returns the object on which the given verb
* is defined.
*/
-extern const char *db_verb_names(db_verb_handle);
-extern void db_set_verb_names(db_verb_handle, const char *);
+extern const char *db_verb_names(db_verb_handle);
+extern void db_set_verb_names(db_verb_handle, const char *);
/* These functions do not change the reference
* count of the string they accept/return.
* Thus, the caller should str_ref() it if it
* is to be persistent.
*/
-extern Objid db_verb_owner(db_verb_handle);
-extern void db_set_verb_owner(db_verb_handle, Objid);
+extern Objid db_verb_owner(db_verb_handle);
+extern void db_set_verb_owner(db_verb_handle, Objid);
-extern unsigned db_verb_flags(db_verb_handle);
-extern void db_set_verb_flags(db_verb_handle, unsigned);
+extern unsigned db_verb_flags(db_verb_handle);
+extern void db_set_verb_flags(db_verb_handle, unsigned);
-extern Program *db_verb_program(db_verb_handle);
-extern void db_set_verb_program(db_verb_handle, Program *);
+extern Program *db_verb_program(db_verb_handle);
+extern void db_set_verb_program(db_verb_handle, Program *);
/* These functions do not change the reference
* count of the program they accept/return.
* Thus, the caller should program_ref() it if
* it is to be persistent.
*/
-extern void db_verb_arg_specs(db_verb_handle h,
- db_arg_spec *dobj,
- db_prep_spec *prep,
- db_arg_spec *iobj);
-extern void db_set_verb_arg_specs(db_verb_handle h,
- db_arg_spec dobj,
- db_prep_spec prep,
- db_arg_spec iobj);
+extern void db_verb_arg_specs(db_verb_handle h,
+ db_arg_spec * dobj,
+ db_prep_spec * prep,
+ db_arg_spec * iobj);
+extern void db_set_verb_arg_specs(db_verb_handle h,
+ db_arg_spec dobj,
+ db_prep_spec prep,
+ db_arg_spec iobj);
-extern int db_verb_allows(db_verb_handle, Objid, db_verb_flag);
+extern int db_verb_allows(db_verb_handle, Objid, db_verb_flag);
/* Returns true iff either the verb has the
* flag or the object either is a wizard or
* owns the verb; that is, iff the object's
@@ -508,18 +508,21 @@ extern int db_verb_allows(db_verb_handle, Objid, db_verb_flag);
* the indicated operation on the verb.
*/
-extern void db_delete_verb(db_verb_handle);
+extern void db_delete_verb(db_verb_handle);
/* Deletes the given verb entirely. This
* db_verb_handle may not be used again after
* this call returns.
*/
-#endif /* !DB_h */
+#endif /* !DB_h */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:26 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.5 1996/05/12 21:31:37 pavel
* Added documentation of the memory-management policy for db_add_verb().
* Release 1.8.0p5.
diff --git a/db_file.c b/db_file.c
index 2b179b9..55ebe54 100644
--- a/db_file.c
+++ b/db_file.c
@@ -38,18 +38,18 @@
#include "timers.h"
#include "version.h"
-static char *input_db_name, *dump_db_name;
-static int dump_generation = 0;
-static const char *header_format_string
- = "** LambdaMOO Database, Format Version %u **\n";
-
-DB_Version dbio_input_version;
+static char *input_db_name, *dump_db_name;
+static int dump_generation = 0;
+static const char *header_format_string
+= "** LambdaMOO Database, Format Version %u **\n";
+DB_Version dbio_input_version;
+
/*********** Verb and property I/O ***********/
static void
-read_verbdef(Verbdef *v)
+read_verbdef(Verbdef * v)
{
v->name = str_dup(dbio_read_string());
v->owner = dbio_read_objid();
@@ -60,7 +60,7 @@ read_verbdef(Verbdef *v)
}
static void
-write_verbdef(Verbdef *v)
+write_verbdef(Verbdef * v)
{
dbio_write_string(v->name);
dbio_write_objid(v->owner);
@@ -76,13 +76,13 @@ read_propdef()
}
static void
-write_propdef(Propdef *p)
+write_propdef(Propdef * p)
{
dbio_write_string(p->name);
}
static void
-read_propval(Pval *p)
+read_propval(Pval * p)
{
p->var = dbio_read_var();
p->owner = dbio_read_objid();
@@ -90,27 +90,27 @@ read_propval(Pval *p)
}
static void
-write_propval(Pval *p)
+write_propval(Pval * p)
{
dbio_write_var(p->var);
dbio_write_objid(p->owner);
dbio_write_num(p->perms);
}
-
+
/*********** Object I/O ***********/
static int
read_object(void)
{
- Objid oid;
- Object *o;
- char s[20];
- int i;
- Verbdef *v, **prevv;
- int nprops;
-
- if (dbio_scanf("#%d", &oid) != 1 || oid != db_last_used_objid() + 1)
+ Objid oid;
+ Object *o;
+ char s[20];
+ int i;
+ Verbdef *v, **prevv;
+ int nprops;
+
+ if (dbio_scanf("#%d", &oid) != 1 || oid != db_last_used_objid() + 1)
return 0;
dbio_read_line(s, sizeof(s));
@@ -154,7 +154,6 @@ read_object(void)
for (i = 0; i < o->propdefs.cur_length; i++)
o->propdefs.l[i] = read_propdef();
}
-
nprops = dbio_read_num();
if (nprops)
o->propval = mymalloc(nprops * sizeof(Pval), M_PVAL);
@@ -171,10 +170,10 @@ read_object(void)
static void
write_object(Objid oid)
{
- Object *o;
- Verbdef *v;
- int i;
- int nverbdefs, nprops;
+ Object *o;
+ Verbdef *v;
+ int i;
+ int nverbdefs, nprops;
if (!valid(oid)) {
dbio_printf("#%d recycled\n", oid);
@@ -207,24 +206,24 @@ write_object(Objid oid)
dbio_write_num(o->propdefs.cur_length);
for (i = 0; i < o->propdefs.cur_length; i++)
write_propdef(&o->propdefs.l[i]);
-
+
nprops = dbpriv_count_properties(oid);
dbio_write_num(nprops);
for (i = 0; i < nprops; i++)
write_propval(o->propval + i);
}
-
+
/*********** File-level Input ***********/
static int
validate_hierarchies()
{
- Objid oid, log_oid;
- Objid size = db_last_used_objid() + 1;
- int broken = 0;
- int fixed_nexts = 0;
+ Objid oid, log_oid;
+ Objid size = db_last_used_objid() + 1;
+ int broken = 0;
+ int fixed_nexts = 0;
oklog("VALIDATING the object hierarchies ...\n");
@@ -243,11 +242,10 @@ validate_hierarchies()
MAYBE_LOG_PROGRESS;
if (o) {
- if (o->location == NOTHING && o->next != NOTHING) {
+ if (o->location == NOTHING && o->next != NOTHING) {
o->next = NOTHING;
fixed_nexts++;
}
-
# define CHECK(field, name) \
{ \
if (o->field != NOTHING \
@@ -275,7 +273,7 @@ validate_hierarchies()
oklog("VALIDATE: Phase 2: Check for cycles ...\n");
for (oid = 0, log_oid = PROGRESS_INTERVAL; oid < size; oid++) {
- Object *o = dbpriv_find_object(oid);
+ Object *o = dbpriv_find_object(oid);
MAYBE_LOG_PROGRESS;
if (o) {
@@ -308,7 +306,7 @@ validate_hierarchies()
oklog("VALIDATE: Phase 3: Check for inconsistencies ...\n");
for (oid = 0, log_oid = PROGRESS_INTERVAL; oid < size; oid++) {
- Object *o = dbpriv_find_object(oid);
+ Object *o = dbpriv_find_object(oid);
MAYBE_LOG_PROGRESS;
if (o) {
@@ -356,11 +354,11 @@ validate_hierarchies()
CHECK(parent, child, "child", sibling);
CHECK(location, contents, "contents", next);
-
+
# undef CHECK
}
}
-
+
oklog("VALIDATING the object hierarchies ... finished.\n");
return !broken;
}
@@ -368,8 +366,8 @@ validate_hierarchies()
static const char *
fmt_verb_name(void *data)
{
- db_verb_handle *h = data;
- static Stream *s = 0;
+ db_verb_handle *h = data;
+ static Stream *s = 0;
if (!s)
s = new_stream(40);
@@ -381,22 +379,21 @@ fmt_verb_name(void *data)
static int
read_db_file(void)
{
- Objid oid;
- int nobjs, nprogs, nusers;
- Var user_list;
- int i, vnum, dummy;
- db_verb_handle h;
- Program *program;
+ Objid oid;
+ int nobjs, nprogs, nusers;
+ Var user_list;
+ int i, vnum, dummy;
+ db_verb_handle h;
+ Program *program;
if (dbio_scanf(header_format_string, &dbio_input_version) != 1)
dbio_input_version = DBV_Prehistory;
if (!check_version(dbio_input_version)) {
errlog("READ_DB_FILE: Unknown DB version number: %d\n",
- dbio_input_version);
+ dbio_input_version);
return 0;
}
-
/* I use a `dummy' variable here and elsewhere instead of the `*'
* assignment-suppression syntax of `scanf' because it allows more
* straightforward error checking; unfortunately, the standard says that
@@ -408,7 +405,6 @@ read_db_file(void)
errlog("READ_DB_FILE: Bad header\n");
return 0;
}
-
user_list = new_list(nusers);
for (i = 1; i <= nusers; i++) {
user_list.v.list[i].type = TYPE_OBJ;
@@ -422,7 +418,7 @@ read_db_file(void)
errlog("READ_DB_FILE: Bad object #%d.\n", i - 1);
return 0;
}
- if (i % 10000 == 0 || i == nobjs)
+ if (i % 10000 == 0 || i == nobjs)
oklog("LOADING: Done reading %d objects ...\n", i);
}
@@ -430,7 +426,6 @@ read_db_file(void)
errlog("READ_DB_FILE: Errors in object hierarchies.\n");
return 0;
}
-
oklog("LOADING: Reading %d MOO verb programs...\n", nprogs);
for (i = 1; i <= nprogs; i++) {
if (dbio_scanf("#%d:%d\n", &oid, &vnum) != 2) {
@@ -439,10 +434,10 @@ read_db_file(void)
}
if (!valid(oid)) {
errlog("READ_DB_FILE: Verb for non-existant object: #%d:%d.\n",
- oid, vnum);
+ oid, vnum);
return 0;
}
- h = db_find_indexed_verb(oid, vnum + 1); /* DB file is 0-based. */
+ h = db_find_indexed_verb(oid, vnum + 1); /* DB file is 0-based. */
if (!h.ptr) {
errlog("READ_DB_FILE: Unknown verb index: #%d:%d.\n", oid, vnum);
return 0;
@@ -453,7 +448,7 @@ read_db_file(void)
return 0;
}
db_set_verb_program(h, program);
- if (i % 5000 == 0 || i == nprogs)
+ if (i % 5000 == 0 || i == nprogs)
oklog("LOADING: Done reading %d verb programs...\n", i);
}
@@ -462,29 +457,27 @@ read_db_file(void)
errlog("READ_DB_FILE: Can't read task queue.\n");
return 0;
}
-
oklog("LOADING: Reading list of formerly active connections...\n");
if (!read_active_connections()) {
errlog("DB_READ: Can't read active connections.\n");
return 0;
}
-
return 1;
}
-
+
/*********** File-level Output ***********/
static int
write_db_file(const char *reason)
{
- Objid oid;
- Objid max_oid = db_last_used_objid();
- Verbdef *v;
- Var user_list;
- int i;
- volatile int nprogs = 0;
- volatile int success = 1;
+ Objid oid;
+ Objid max_oid = db_last_used_objid();
+ Verbdef *v;
+ Var user_list;
+ int i;
+ volatile int nprogs = 0;
+ volatile int success = 1;
for (oid = 0; oid <= max_oid; oid++) {
if (valid(oid))
@@ -492,59 +485,61 @@ write_db_file(const char *reason)
if (v->program)
nprogs++;
}
-
+
user_list = db_all_users();
-
- TRY
+
+ TRY
dbio_printf(header_format_string, current_version);
- dbio_printf("%d\n%d\n%d\n%d\n",
- max_oid + 1, nprogs, 0, user_list.v.list[0].v.num);
- for (i = 1; i <= user_list.v.list[0].v.num; i++)
- dbio_write_objid(user_list.v.list[i].v.obj);
- oklog("%s: Writing %d objects...\n", reason, max_oid + 1);
- for (oid = 0; oid <= max_oid; oid++) {
- write_object(oid);
- if ((oid + 1) % 10000 == 0 || oid == max_oid)
- oklog("%s: Done writing %d objects...\n", reason, oid + 1);
- }
- oklog("%s: Writing %d MOO verb programs...\n", reason, nprogs);
- for (i = 0, oid = 0; oid <= max_oid; oid++)
- if (valid(oid)) {
- int vcount = 0;
-
- for (v = dbpriv_find_object(oid)->verbdefs; v; v = v->next) {
- if (v->program) {
- dbio_printf("#%d:%d\n", oid, vcount);
- dbio_write_program(v->program);
- if (++i % 5000 == 0 || i == nprogs)
- oklog("%s: Done writing %d verb programs...\n",
- reason, i);
- }
- vcount++;
+ dbio_printf("%d\n%d\n%d\n%d\n",
+ max_oid + 1, nprogs, 0, user_list.v.list[0].v.num);
+ for (i = 1; i <= user_list.v.list[0].v.num; i++)
+ dbio_write_objid(user_list.v.list[i].v.obj);
+ oklog("%s: Writing %d objects...\n", reason, max_oid + 1);
+ for (oid = 0; oid <= max_oid; oid++) {
+ write_object(oid);
+ if ((oid + 1) % 10000 == 0 || oid == max_oid)
+ oklog("%s: Done writing %d objects...\n", reason, oid + 1);
+ }
+ oklog("%s: Writing %d MOO verb programs...\n", reason, nprogs);
+ for (i = 0, oid = 0; oid <= max_oid; oid++)
+ if (valid(oid)) {
+ int vcount = 0;
+
+ for (v = dbpriv_find_object(oid)->verbdefs; v; v = v->next) {
+ if (v->program) {
+ dbio_printf("#%d:%d\n", oid, vcount);
+ dbio_write_program(v->program);
+ if (++i % 5000 == 0 || i == nprogs)
+ oklog("%s: Done writing %d verb programs...\n",
+ reason, i);
}
+ vcount++;
}
-
- oklog("%s: Writing forked and suspended tasks...\n", reason);
- write_task_queue();
- oklog("%s: Writing list of formerly active connections...\n", reason);
- write_active_connections();
- EXCEPT (dbpriv_dbio_failed)
+ }
+ oklog("%s: Writing forked and suspended tasks...\n", reason);
+ write_task_queue();
+ oklog("%s: Writing list of formerly active connections...\n", reason);
+ write_active_connections();
+ EXCEPT(dbpriv_dbio_failed)
success = 0;
ENDTRY;
return success;
}
-typedef enum { DUMP_SHUTDOWN, DUMP_CHECKPOINT, DUMP_PANIC } Dump_Reason;
-const char *reason_names[] = { "DUMPING", "CHECKPOINTING", "PANIC-DUMPING" };
+typedef enum {
+ DUMP_SHUTDOWN, DUMP_CHECKPOINT, DUMP_PANIC
+} Dump_Reason;
+const char *reason_names[] =
+{"DUMPING", "CHECKPOINTING", "PANIC-DUMPING"};
static int
dump_database(Dump_Reason reason)
{
- Stream *s = new_stream(100);
- char *temp_name;
- FILE *f;
- int success;
+ Stream *s = new_stream(100);
+ char *temp_name;
+ FILE *f;
+ int success;
retryDumping:
@@ -566,14 +561,14 @@ dump_database(Dump_Reason reason)
#else
if (reason == DUMP_CHECKPOINT) {
switch (fork_server("checkpointer")) {
- case FORK_PARENT:
+ case FORK_PARENT:
reset_command_history();
free_stream(s);
return 1;
- case FORK_ERROR:
+ case FORK_ERROR:
free_stream(s);
return 0;
- case FORK_CHILD:
+ case FORK_CHILD:
set_server_cmdline("(MOO checkpointer)");
break;
}
@@ -591,7 +586,7 @@ dump_database(Dump_Reason reason)
errlog("Abandoning checkpoint attempt...\n");
success = 0;
} else {
- int retry_interval = 60;
+ int retry_interval = 60;
errlog("Waiting %d seconds and retrying dump...\n",
retry_interval);
@@ -624,8 +619,8 @@ dump_database(Dump_Reason reason)
return success;
}
-
+
/*********** External interface ***********/
const char *
@@ -634,12 +629,12 @@ db_usage_string(void)
return "input-db-file output-db-file";
}
-static FILE *input_db;
+static FILE *input_db;
int
db_initialize(int *pargc, char ***pargv)
{
- FILE *f;
+ FILE *f;
if (*pargc < 2)
return 0;
@@ -654,7 +649,6 @@ db_initialize(int *pargc, char ***pargv)
input_db_name);
return 0;
}
-
input_db = f;
dbpriv_build_prep_table();
@@ -672,7 +666,7 @@ db_load(void)
return 0;
}
oklog("LOADING: %s done, will dump new database on %s\n",
- input_db_name, dump_db_name);
+ input_db_name, dump_db_name);
fclose(input_db);
return 1;
@@ -683,17 +677,17 @@ db_flush(enum db_flush_type type)
{
int success = 0;
- switch(type) {
- case FLUSH_IF_FULL:
- case FLUSH_ONE_SECOND:
+ switch (type) {
+ case FLUSH_IF_FULL:
+ case FLUSH_ONE_SECOND:
success = 1;
break;
- case FLUSH_ALL_NOW:
+ case FLUSH_ALL_NOW:
success = dump_database(DUMP_CHECKPOINT);
break;
- case FLUSH_PANIC:
+ case FLUSH_PANIC:
success = dump_database(DUMP_PANIC);
break;
}
@@ -704,9 +698,9 @@ db_flush(enum db_flush_type type)
int32
db_disk_size(void)
{
- struct stat st;
+ struct stat st;
- if ((dump_generation == 0 || stat(dump_db_name, &st) < 0)
+ if ((dump_generation == 0 || stat(dump_db_name, &st) < 0)
&& stat(input_db_name, &st) < 0)
return -1;
else
@@ -722,9 +716,12 @@ db_shutdown()
char rcsid_db_file[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:27 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.5 1996/04/08 01:07:21 pavel
* Changed a boot-time error message to go directly to stderr, instead of
* through the logging package. Release 1.8.0p3.
diff --git a/db_io.c b/db_io.c
index e53a13f..2083493 100644
--- a/db_io.c
+++ b/db_io.c
@@ -37,14 +37,14 @@
#include "structures.h"
#include "unparse.h"
#include "version.h"
-
+
/*********** Input ***********/
-static FILE *input;
+static FILE *input;
void
-dbpriv_set_dbio_input(FILE *f)
+dbpriv_set_dbio_input(FILE * f)
{
input = f;
}
@@ -56,10 +56,10 @@ dbio_read_line(char *s, int n)
}
int
-dbio_scanf(const char *format, ...)
+dbio_scanf(const char *format,...)
{
- va_list args;
- int count;
+ va_list args;
+ int count;
const char *ptr;
va_start(args, format);
@@ -75,9 +75,9 @@ dbio_scanf(const char *format, ...)
count = 0;
for (ptr = format; *ptr; ptr++) {
- int c, n, *ip;
- unsigned *up;
- char *cp;
+ int c, n, *ip;
+ unsigned *up;
+ char *cp;
if (isspace(*ptr)) {
do
@@ -88,7 +88,7 @@ dbio_scanf(const char *format, ...)
do
c = fgetc(input);
while (isspace(c));
-
+
if (c == EOF)
return count ? count : EOF;
else if (c != *ptr) {
@@ -97,15 +97,15 @@ dbio_scanf(const char *format, ...)
}
} else
switch (*++ptr) {
- case 'd':
+ case 'd':
ip = va_arg(args, int *);
n = fscanf(input, "%d", ip);
goto finish;
- case 'u':
+ case 'u':
up = va_arg(args, unsigned *);
n = fscanf(input, "%u", up);
goto finish;
- case 'c':
+ case 'c':
cp = va_arg(args, char *);
n = fscanf(input, "%c", cp);
finish:
@@ -113,10 +113,10 @@ dbio_scanf(const char *format, ...)
count++;
else if (n == 0)
return count;
- else /* n == EOF */
+ else /* n == EOF */
return count ? count : EOF;
break;
- default:
+ default:
panic("DBIO_SCANF: Unsupported directive!");
}
}
@@ -129,30 +129,30 @@ dbio_scanf(const char *format, ...)
int
dbio_read_num(void)
{
- char s[20];
- char *p;
- int i;
+ char s[20];
+ char *p;
+ int i;
fgets(s, 20, input);
i = strtol(s, &p, 10);
if (isspace(*s) || *p != '\n')
errlog("DBIO_READ_NUM: Bad number: \"%s\" at file pos. %ld\n",
- s, ftell(input));
+ s, ftell(input));
return i;
}
double
dbio_read_float(void)
{
- char s[40];
- char *p;
- double d;
+ char s[40];
+ char *p;
+ double d;
fgets(s, 40, input);
d = strtod(s, &p);
if (isspace(*s) || *p != '\n')
errlog("DBIO_READ_FLOAT: Bad number: \"%s\" at file pos. %ld\n",
- s, ftell(input));
+ s, ftell(input));
return d;
}
@@ -165,9 +165,9 @@ dbio_read_objid(void)
const char *
dbio_read_string(void)
{
- static Stream *str = 0;
- static char buffer[1024];
- int len, used_stream = 0;
+ static Stream *str = 0;
+ static char buffer[1024];
+ int len, used_stream = 0;
if (str == 0)
str = new_stream(1024);
@@ -175,12 +175,11 @@ dbio_read_string(void)
try_again:
fgets(buffer, sizeof(buffer), input);
len = strlen(buffer);
- if (len == sizeof(buffer) - 1 && buffer[len - 1] != '\n') {
+ if (len == sizeof(buffer) - 1 && buffer[len - 1] != '\n') {
stream_add_string(str, buffer);
used_stream = 1;
goto try_again;
}
-
if (buffer[len - 1] == '\n')
buffer[len - 1] = '\0';
@@ -194,38 +193,38 @@ dbio_read_string(void)
Var
dbio_read_var(void)
{
- Var r;
- int i, l = dbio_read_num();
+ Var r;
+ int i, l = dbio_read_num();
- if (l == (int) TYPE_ANY && dbio_input_version == DBV_Prehistory)
+ if (l == (int) TYPE_ANY && dbio_input_version == DBV_Prehistory)
l = TYPE_NONE; /* Old encoding for VM's empty temp register
* and any as-yet unassigned variables.
*/
r.type = (var_type) l;
switch (l) {
- case TYPE_CLEAR:
- case TYPE_NONE:
+ case TYPE_CLEAR:
+ case TYPE_NONE:
break;
- case TYPE_STR:
+ case TYPE_STR:
r.v.str = str_dup(dbio_read_string());
break;
- case TYPE_OBJ:
- case TYPE_ERR:
- case TYPE_INT:
- case TYPE_CATCH:
- case TYPE_FINALLY:
+ case TYPE_OBJ:
+ case TYPE_ERR:
+ case TYPE_INT:
+ case TYPE_CATCH:
+ case TYPE_FINALLY:
r.v.num = dbio_read_num();
break;
- case TYPE_FLOAT:
+ case TYPE_FLOAT:
r = new_float(dbio_read_float());
break;
- case TYPE_LIST:
+ case TYPE_LIST:
l = dbio_read_num();
r = new_list(l);
for (i = 0; i < l; i++)
r.v.list[i + 1] = dbio_read_var();
break;
- default:
+ default:
errlog("DBIO_READ_VAR: Unknown type (%d) at DB file pos. %ld\n",
l, ftell(input));
r = zero;
@@ -235,9 +234,9 @@ dbio_read_var(void)
}
struct state {
- char prev_char;
- const char *(*fmtr)(void *);
- void *data;
+ char prev_char;
+ const char *(*fmtr) (void *);
+ void *data;
};
static const char *
@@ -246,7 +245,7 @@ program_name(struct state *s)
if (!s->fmtr)
return s->data;
else
- return (*s->fmtr)(s->data);
+ return (*s->fmtr) (s->data);
}
static void
@@ -266,13 +265,13 @@ my_warning(void *data, const char *msg)
static int
my_getc(void *data)
{
- struct state *s = data;
- int c;
+ struct state *s = data;
+ int c;
c = fgetc(input);
- if (c == '.' && s->prev_char == '\n') {
+ if (c == '.' && s->prev_char == '\n') {
/* end-of-verb marker in DB */
- c = fgetc(input); /* skip next newline */
+ c = fgetc(input); /* skip next newline */
return EOF;
}
if (c == EOF)
@@ -281,36 +280,37 @@ my_getc(void *data)
return c;
}
-static Parser_Client parser_client = { my_error, my_warning, my_getc };
+static Parser_Client parser_client =
+{my_error, my_warning, my_getc};
Program *
-dbio_read_program(DB_Version version, const char *(*fmtr)(void *), void *data)
+dbio_read_program(DB_Version version, const char *(*fmtr) (void *), void *data)
{
- struct state s;
+ struct state s;
s.prev_char = '\n';
s.fmtr = fmtr;
s.data = data;
return parse_program(version, parser_client, &s);
}
-
+
/*********** Output ***********/
Exception dbpriv_dbio_failed;
-static FILE *output;
+static FILE *output;
void
-dbpriv_set_dbio_output(FILE *f)
+dbpriv_set_dbio_output(FILE * f)
{
output = f;
}
void
-dbio_printf(const char *format, ...)
+dbio_printf(const char *format,...)
{
- va_list args;
+ va_list args;
va_start(args, format);
if (vfprintf(output, format, args) < 0)
@@ -327,14 +327,13 @@ dbio_write_num(int n)
void
dbio_write_float(double d)
{
- static const char *fmt = 0;
- static char buffer[10];
+ static const char *fmt = 0;
+ static char buffer[10];
if (!fmt) {
sprintf(buffer, "%%.%dg\n", DBL_DIG + 4);
fmt = buffer;
}
-
dbio_printf(fmt, d);
}
@@ -353,27 +352,27 @@ dbio_write_string(const char *s)
void
dbio_write_var(Var v)
{
- int i;
+ int i;
dbio_write_num((int) v.type);
switch (v.type) {
- case TYPE_CLEAR:
- case TYPE_NONE:
+ case TYPE_CLEAR:
+ case TYPE_NONE:
break;
- case TYPE_STR:
+ case TYPE_STR:
dbio_write_string(v.v.str);
break;
- case TYPE_OBJ:
- case TYPE_ERR:
- case TYPE_INT:
- case TYPE_CATCH:
- case TYPE_FINALLY:
+ case TYPE_OBJ:
+ case TYPE_ERR:
+ case TYPE_INT:
+ case TYPE_CATCH:
+ case TYPE_FINALLY:
dbio_write_num(v.v.num);
break;
- case TYPE_FLOAT:
+ case TYPE_FLOAT:
dbio_write_float(*v.v.fnum);
break;
- case TYPE_LIST:
+ case TYPE_LIST:
dbio_write_num(v.v.list[0].v.num);
for (i = 0; i < v.v.list[0].v.num; i++)
dbio_write_var(v.v.list[i + 1]);
@@ -388,14 +387,14 @@ receiver(void *data, const char *line)
}
void
-dbio_write_program(Program *program)
+dbio_write_program(Program * program)
{
unparse_program(program, receiver, 0, 1, 0, MAIN_VECTOR);
dbio_printf(".\n");
}
void
-dbio_write_forked_program(Program *program, int f_index)
+dbio_write_forked_program(Program * program, int f_index)
{
unparse_program(program, receiver, 0, 1, 0, f_index);
dbio_printf(".\n");
@@ -404,9 +403,12 @@ dbio_write_forked_program(Program *program, int f_index)
char rcsid_db_io[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:27 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.5 1996/03/19 07:16:12 pavel
* Increased precision of floating-point numbers printed in the DB file.
* Release 1.8.0p2.
diff --git a/db_io.h b/db_io.h
index 17fa579..ead973a 100644
--- a/db_io.h
+++ b/db_io.h
@@ -25,36 +25,36 @@
/*********** Input ***********/
-extern DB_Version dbio_input_version;
+extern DB_Version dbio_input_version;
/* What DB-format version are we reading? */
-extern void dbio_read_line(char *s, int n);
+extern void dbio_read_line(char *s, int n);
/* Reads at most N-1 characters through the
* next newline into S, terminating S with a
* null. (Like the `fgets()' function.)
*/
-extern int dbio_scanf(const char *format, ...);
+extern int dbio_scanf(const char *format,...);
-extern int dbio_read_num(void);
-extern Objid dbio_read_objid(void);
-extern double dbio_read_float(void);
+extern int dbio_read_num(void);
+extern Objid dbio_read_objid(void);
+extern double dbio_read_float(void);
-extern const char *dbio_read_string(void);
+extern const char *dbio_read_string(void);
/* The returned string is in private storage of
* the DBIO module, so the caller should
* str_dup() it if it is to persist.
*/
-extern Var dbio_read_var(void);
+extern Var dbio_read_var(void);
/* The DBIO module retains no references to
* the returned value, so freeing it is
* entirely the responsibility of the caller.
*/
-extern Program *dbio_read_program(DB_Version version,
- const char *(*fmtr)(void *),
- void *data);
+extern Program *dbio_read_program(DB_Version version,
+ const char *(*fmtr) (void *),
+ void *data);
/* FMTR is called with DATA to produce a human-
* understandable identifier for the program
* being read, for use in any error/warning
@@ -74,26 +74,29 @@ extern Program *dbio_read_program(DB_Version version,
* event.
*/
-extern void dbio_printf(const char *format, ...);
+extern void dbio_printf(const char *format,...);
-extern void dbio_write_num(int);
-extern void dbio_write_objid(Objid);
-extern void dbio_write_float(double);
+extern void dbio_write_num(int);
+extern void dbio_write_objid(Objid);
+extern void dbio_write_float(double);
-extern void dbio_write_string(const char *);
+extern void dbio_write_string(const char *);
/* The given string should not contain any
* newline characters.
*/
-extern void dbio_write_var(Var);
+extern void dbio_write_var(Var);
-extern void dbio_write_program(Program *);
-extern void dbio_write_forked_program(Program *prog, int f_index);
+extern void dbio_write_program(Program *);
+extern void dbio_write_forked_program(Program * prog, int f_index);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:28 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.3 1996/02/08 06:28:21 pavel
* Added dbio_input_version, dbio_read/write_float(). Made dbio_read_program
* version-dependent. Updated copyright notice for 1996. Release 1.8.0beta1.
diff --git a/db_objects.c b/db_objects.c
index e34a65b..8ff1fae 100644
--- a/db_objects.c
+++ b/db_objects.c
@@ -28,18 +28,18 @@
#include "utils.h"
static Object **objects;
-static int num_objects = 0;
-static int max_objects = 0;
-
-static Var all_users;
+static int num_objects = 0;
+static int max_objects = 0;
+static Var all_users;
+
/*********** Objects qua objects ***********/
Object *
dbpriv_find_object(Objid oid)
{
- if (oid < 0 || oid >= num_objects)
+ if (oid < 0 || oid >= num_objects)
return 0;
else
return objects[oid];
@@ -71,10 +71,9 @@ ensure_new_object(void)
max_objects = 100;
objects = mymalloc(max_objects * sizeof(Object *), M_OBJECT_TABLE);
}
-
if (num_objects >= max_objects) {
- int i;
- Object **new;
+ int i;
+ Object **new;
new = mymalloc(max_objects * 2 * sizeof(Object *), M_OBJECT_TABLE);
for (i = 0; i < max_objects; i++)
@@ -88,7 +87,7 @@ ensure_new_object(void)
Object *
dbpriv_new_object(void)
{
- Object *o;
+ Object *o;
ensure_new_object();
o = objects[num_objects] = mymalloc(sizeof(Object), M_OBJECT);
@@ -108,8 +107,8 @@ dbpriv_new_recycled_object(void)
Objid
db_create_object(void)
{
- Object *o;
- Objid oid;
+ Object *o;
+ Objid oid;
o = dbpriv_new_object();
oid = o->id;
@@ -133,9 +132,9 @@ db_create_object(void)
void
db_destroy_object(Objid oid)
{
- Object *o = dbpriv_find_object(oid);
- Verbdef *v, *w;
- int i;
+ Object *o = dbpriv_find_object(oid);
+ Verbdef *v, *w;
+ int i;
if (!o)
panic("DB_DESTROY_OBJECT: Invalid object!");
@@ -145,13 +144,12 @@ db_destroy_object(Objid oid)
panic("DB_DESTROY_OBJECT: Not a barren orphan!");
if (is_user(oid)) {
- Var t;
+ Var t;
t.type = TYPE_OBJ;
t.v.obj = oid;
all_users = setremove(all_users, t);
}
-
free_str(o->name);
for (i = 0; i < o->propdefs.cur_length; i++) {
@@ -181,8 +179,8 @@ db_destroy_object(Objid oid)
Objid
db_renumber_object(Objid old)
{
- Objid new;
- Object *o;
+ Objid new;
+ Object *o;
for (new = 0; new < old; new++) {
if (objects[new] == 0) {
@@ -193,17 +191,16 @@ db_renumber_object(Objid old)
/* Fix up the parent/children hierarchy */
{
- Objid oid, *oidp;
+ Objid oid, *oidp;
if (o->parent != NOTHING) {
oidp = &objects[o->parent]->child;
- while (*oidp != old && *oidp != NOTHING)
+ while (*oidp != old && *oidp != NOTHING)
oidp = &objects[*oidp]->sibling;
if (*oidp == NOTHING)
panic("Object not in parent's children list");
*oidp = new;
}
-
for (oid = o->child;
oid != NOTHING;
oid = objects[oid]->sibling)
@@ -212,17 +209,16 @@ db_renumber_object(Objid old)
/* Fix up the location/contents hierarchy */
{
- Objid oid, *oidp;
+ Objid oid, *oidp;
if (o->location != NOTHING) {
oidp = &objects[o->location]->contents;
- while (*oidp != old && *oidp != NOTHING)
+ while (*oidp != old && *oidp != NOTHING)
oidp = &objects[*oidp]->next;
if (*oidp == NOTHING)
panic("Object not in location's contents list");
*oidp = new;
}
-
for (oid = o->contents;
oid != NOTHING;
oid = objects[oid]->next)
@@ -231,7 +227,7 @@ db_renumber_object(Objid old)
/* Fix up the list of users, if necessary */
if (is_user(new)) {
- int i;
+ int i;
for (i = 1; i <= all_users.v.list[0].v.num; i++)
if (all_users.v.list[i].v.obj == old) {
@@ -239,16 +235,15 @@ db_renumber_object(Objid old)
break;
}
}
-
/* Fix the owners of verbs, properties and objects */
{
- Objid oid;
+ Objid oid;
for (oid = 0; oid < num_objects; oid++) {
- Object *o = objects[oid];
- Verbdef *v;
- Pval *p;
- int i, count;
+ Object *o = objects[oid];
+ Verbdef *v;
+ Pval *p;
+ int i, count;
if (!o)
continue;
@@ -285,9 +280,9 @@ db_renumber_object(Objid old)
int
db_object_bytes(Objid oid)
{
- Object *o = objects[oid];
- int i, len, count;
- Verbdef *v;
+ Object *o = objects[oid];
+ int i, len, count;
+ Verbdef *v;
count = sizeof(Object) + sizeof(Object *);
count += strlen(o->name) + 1;
@@ -310,8 +305,8 @@ db_object_bytes(Objid oid)
return count;
}
-
+
/*********** Object attributes ***********/
Objid
@@ -335,7 +330,7 @@ db_object_name(Objid oid)
void
db_set_object_name(Objid oid, const char *name)
{
- Object *o = objects[oid];
+ Object *o = objects[oid];
if (o->name)
free_str(o->name);
@@ -351,8 +346,8 @@ db_object_parent(Objid oid)
int
db_count_children(Objid oid)
{
- Objid c;
- int i = 0;
+ Objid c;
+ int i = 0;
for (c = objects[oid]->child; c != NOTHING; c = objects[c]->sibling)
i++;
@@ -361,9 +356,9 @@ db_count_children(Objid oid)
}
int
-db_for_all_children(Objid oid, int (*func)(void *, Objid), void *data)
+db_for_all_children(Objid oid, int (*func) (void *, Objid), void *data)
{
- Objid c;
+ Objid c;
for (c = objects[oid]->child; c != NOTHING; c = objects[c]->sibling)
if (func(data, c))
@@ -405,17 +400,17 @@ db_for_all_children(Objid oid, int (*func)(void *, Objid), void *data)
int
db_change_parent(Objid oid, Objid parent)
{
- Objid old_parent;
+ Objid old_parent;
if (!dbpriv_check_properties_for_chparent(oid, parent))
return 0;
old_parent = objects[oid]->parent;
- if (old_parent != NOTHING)
+ if (old_parent != NOTHING)
LL_REMOVE(old_parent, child, oid, sibling);
- if (parent != NOTHING)
+ if (parent != NOTHING)
LL_APPEND(parent, child, oid, sibling);
objects[oid]->parent = parent;
@@ -433,8 +428,8 @@ db_object_location(Objid oid)
int
db_count_contents(Objid oid)
{
- Objid c;
- int i = 0;
+ Objid c;
+ int i = 0;
for (c = objects[oid]->contents; c != NOTHING; c = objects[c]->next)
i++;
@@ -443,9 +438,9 @@ db_count_contents(Objid oid)
}
int
-db_for_all_contents(Objid oid, int (*func)(void *, Objid), void *data)
+db_for_all_contents(Objid oid, int (*func) (void *, Objid), void *data)
{
- Objid c;
+ Objid c;
for (c = objects[oid]->contents; c != NOTHING; c = objects[c]->next)
if (func(data, c))
@@ -458,17 +453,17 @@ void
db_change_location(Objid oid, Objid location)
{
Objid old_location = objects[oid]->location;
-
- if (valid(old_location))
+
+ if (valid(old_location))
LL_REMOVE(old_location, contents, oid, next);
-
+
if (valid(location))
LL_APPEND(location, contents, oid, next);
objects[oid]->location = location;
}
-int
+int
db_object_has_flag(Objid oid, db_object_flag f)
{
return (objects[oid]->flags & (1 << f)) != 0;
@@ -479,7 +474,7 @@ db_set_object_flag(Objid oid, db_object_flag f)
{
objects[oid]->flags |= (1 << f);
if (f == FLAG_USER) {
- Var v;
+ Var v;
v.type = TYPE_OBJ;
v.v.obj = oid;
@@ -492,7 +487,7 @@ db_clear_object_flag(Objid oid, db_object_flag f)
{
objects[oid]->flags &= ~(1 << f);
if (f == FLAG_USER) {
- Var v;
+ Var v;
v.type = TYPE_OBJ;
v.v.obj = oid;
@@ -511,19 +506,19 @@ db_object_allows(Objid oid, Objid progr, db_object_flag f)
int
is_wizard(Objid oid)
{
- return valid(oid) && db_object_has_flag(oid, FLAG_WIZARD);
+ return valid(oid) && db_object_has_flag(oid, FLAG_WIZARD);
}
int
is_programmer(Objid oid)
{
- return valid(oid) && db_object_has_flag(oid, FLAG_PROGRAMMER);
+ return valid(oid) && db_object_has_flag(oid, FLAG_PROGRAMMER);
}
int
is_user(Objid oid)
{
- return valid(oid) && db_object_has_flag(oid, FLAG_USER);
+ return valid(oid) && db_object_has_flag(oid, FLAG_USER);
}
Var
@@ -541,9 +536,12 @@ dbpriv_set_all_users(Var v)
char rcsid_db_objects[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:29 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.5 1996/04/08 00:42:11 pavel
* Adjusted computation in `db_object_bytes()' to account for change in the
* definition of `value_bytes()'. Release 1.8.0p3.
diff --git a/db_private.h b/db_private.h
index 0e10d6d..e04b3f8 100644
--- a/db_private.h
+++ b/db_private.h
@@ -24,95 +24,95 @@
#include "program.h"
#include "structures.h"
-typedef struct Verbdef Verbdef;
+typedef struct Verbdef Verbdef;
struct Verbdef {
const char *name;
- Program *program;
- Objid owner;
- short perms;
- short prep;
- Verbdef *next;
+ Program *program;
+ Objid owner;
+ short perms;
+ short prep;
+ Verbdef *next;
};
typedef struct Proplist Proplist;
-typedef struct Propdef Propdef;
+typedef struct Propdef Propdef;
struct Propdef {
const char *name;
- int hash;
+ int hash;
};
struct Proplist {
- int max_length;
- int cur_length;
- Propdef *l;
+ int max_length;
+ int cur_length;
+ Propdef *l;
};
typedef struct Pval {
- Var var;
- Objid owner;
- short perms;
+ Var var;
+ Objid owner;
+ short perms;
} Pval;
typedef struct Object {
- Objid id;
- Objid owner;
- Objid location;
- Objid contents;
- Objid next;
+ Objid id;
+ Objid owner;
+ Objid location;
+ Objid contents;
+ Objid next;
- Objid parent;
- Objid child;
- Objid sibling;
+ Objid parent;
+ Objid child;
+ Objid sibling;
const char *name;
- int flags;
+ int flags;
- Verbdef *verbdefs;
- Proplist propdefs;
- Pval *propval;
+ Verbdef *verbdefs;
+ Proplist propdefs;
+ Pval *propval;
} Object;
/*********** Objects ***********/
-extern void dbpriv_set_all_users(Var);
+extern void dbpriv_set_all_users(Var);
/* Initialize the list returned by
* db_all_users().
*/
-extern Object *dbpriv_new_object(void);
+extern Object *dbpriv_new_object(void);
/* Creates a new object, assigning it a number,
* but doesn't fill in any of the fields other
* than `id'.
*/
-extern void dbpriv_new_recycled_object(void);
+extern void dbpriv_new_recycled_object(void);
/* Does the equivalent of creating and
* destroying an object, with the net effect of
* using up the next available object number.
*/
-extern Object *dbpriv_find_object(Objid);
+extern Object *dbpriv_find_object(Objid);
/* Returns 0 if given object is not valid.
*/
/*********** Properties ***********/
-extern Propdef dbpriv_new_propdef(const char *name);
+extern Propdef dbpriv_new_propdef(const char *name);
-extern int dbpriv_count_properties(Objid);
+extern int dbpriv_count_properties(Objid);
-extern int dbpriv_check_properties_for_chparent(Objid oid,
- Objid new_parent);
+extern int dbpriv_check_properties_for_chparent(Objid oid,
+ Objid new_parent);
/* Return true iff NEW_PARENT defines no
* properties that are also defined by either
* OID or any of OID's descendants.
*/
-extern void dbpriv_fix_properties_after_chparent(Objid oid,
- Objid old_parent);
+extern void dbpriv_fix_properties_after_chparent(Objid oid,
+ Objid old_parent);
/* OID has just had its parent changed away
* from OLD_PARENT. Fix up the properties of
* OID and its descendants, removing obsolete
@@ -122,7 +122,7 @@ extern void dbpriv_fix_properties_after_chparent(Objid oid,
/*********** Verbs ***********/
-extern void dbpriv_build_prep_table(void);
+extern void dbpriv_build_prep_table(void);
/* Should be called once near the beginning of
* the world, to initialize the
* prepositional-phrase matching table.
@@ -130,18 +130,21 @@ extern void dbpriv_build_prep_table(void);
/*********** DBIO ***********/
-extern Exception dbpriv_dbio_failed;
+extern Exception dbpriv_dbio_failed;
/* Raised by DBIO in case of failure (e.g.,
* running out of disk space for the dump).
*/
-extern void dbpriv_set_dbio_input(FILE *);
-extern void dbpriv_set_dbio_output(FILE *);
+extern void dbpriv_set_dbio_input(FILE *);
+extern void dbpriv_set_dbio_output(FILE *);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:30 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.3 1996/02/08 06:27:28 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/db_properties.c b/db_properties.c
index 69116f4..eb8fabc 100644
--- a/db_properties.c
+++ b/db_properties.c
@@ -29,7 +29,7 @@
Propdef
dbpriv_new_propdef(const char *name)
{
- Propdef newprop;
+ Propdef newprop;
newprop.name = str_ref(name);
newprop.hash = str_hash(name);
@@ -39,12 +39,12 @@ dbpriv_new_propdef(const char *name)
int
dbpriv_count_properties(Objid oid)
{
- Object *o;
- int nprops = 0;
+ Object *o;
+ int nprops = 0;
for (o = dbpriv_find_object(oid); o; o = dbpriv_find_object(o->parent))
nprops += o->propdefs.cur_length;
-
+
return nprops;
}
@@ -53,31 +53,31 @@ property_defined_at_or_below(const char *pname, int phash, Objid oid)
{
/* Return true iff some descendant of OID defines a property named PNAME.
*/
- Objid c;
- Proplist *props = &dbpriv_find_object(oid)->propdefs;
- int length = props->cur_length;
- int i;
-
+ Objid c;
+ Proplist *props = &dbpriv_find_object(oid)->propdefs;
+ int length = props->cur_length;
+ int i;
+
for (i = 0; i < length; i++)
if (props->l[i].hash == phash
&& !mystrcasecmp(props->l[i].name, pname))
return 1;
-
+
for (c = dbpriv_find_object(oid)->child;
c != NOTHING;
c = dbpriv_find_object(c)->sibling)
if (property_defined_at_or_below(pname, phash, c))
return 1;
-
+
return 0;
}
static void
insert_prop(Objid oid, int pos, Pval pval)
{
- Pval *new_propval;
- Object *o;
- int i, nprops;
+ Pval *new_propval;
+ Object *o;
+ int i, nprops;
nprops = dbpriv_count_properties(oid);
new_propval = mymalloc(nprops * sizeof(Pval), M_PVAL);
@@ -103,16 +103,16 @@ insert_prop(Objid oid, int pos, Pval pval)
static void
insert_prop_recursively(Objid root, int root_pos, Pval pv)
{
- Objid c;
+ Objid c;
insert_prop(root, root_pos, pv);
- pv.var.type = TYPE_CLEAR; /* do after initial insert_prop so only
+ pv.var.type = TYPE_CLEAR; /* do after initial insert_prop so only
children will be TYPE_CLEAR */
for (c = dbpriv_find_object(root)->child;
c != NOTHING;
c = dbpriv_find_object(c)->sibling) {
- int new_prop_count = dbpriv_find_object(c)->propdefs.cur_length;
-
+ int new_prop_count = dbpriv_find_object(c)->propdefs.cur_length;
+
insert_prop_recursively(c, new_prop_count + root_pos, pv);
}
}
@@ -121,10 +121,10 @@ int
db_add_propdef(Objid oid, const char *pname, Var value, Objid owner,
unsigned flags)
{
- Object *o;
- Pval pval;
- int i;
- db_prop_handle h;
+ Object *o;
+ Pval pval;
+ int i;
+ db_prop_handle h;
h = db_find_property(oid, pname, 0);
@@ -133,10 +133,10 @@ db_add_propdef(Objid oid, const char *pname, Var value, Objid owner,
o = dbpriv_find_object(oid);
if (o->propdefs.cur_length == o->propdefs.max_length) {
- Propdef *old_props = o->propdefs.l;
- int new_size = (o->propdefs.max_length == 0
- ? 8 : 2 * o->propdefs.max_length);
-
+ Propdef *old_props = o->propdefs.l;
+ int new_size = (o->propdefs.max_length == 0
+ ? 8 : 2 * o->propdefs.max_length);
+
o->propdefs.l = mymalloc(new_size * sizeof(Propdef), M_PROPDEF);
for (i = 0; i < o->propdefs.max_length; i++)
o->propdefs.l[i] = old_props[i];
@@ -144,14 +144,13 @@ db_add_propdef(Objid oid, const char *pname, Var value, Objid owner,
if (old_props)
myfree(old_props, M_PROPDEF);
- }
-
+ }
o->propdefs.l[o->propdefs.cur_length++] = dbpriv_new_propdef(pname);
-
+
pval.var = value;
pval.owner = owner;
pval.perms = flags;
-
+
insert_prop_recursively(oid, o->propdefs.cur_length - 1, pval);
return 1;
@@ -160,21 +159,21 @@ db_add_propdef(Objid oid, const char *pname, Var value, Objid owner,
int
db_rename_propdef(Objid oid, const char *old, const char *new)
{
- Proplist *props = &dbpriv_find_object(oid)->propdefs;
- int hash = str_hash(old);
- int count = props->cur_length;
- int i;
- db_prop_handle h;
+ Proplist *props = &dbpriv_find_object(oid)->propdefs;
+ int hash = str_hash(old);
+ int count = props->cur_length;
+ int i;
+ db_prop_handle h;
for (i = 0; i < count; i++) {
- Propdef p;
+ Propdef p;
p = props->l[i];
- if (p.hash == hash && !mystrcasecmp(p.name, old)) {
- if (mystrcasecmp(old, new) != 0) { /* Not changing just the case */
+ if (p.hash == hash && !mystrcasecmp(p.name, old)) {
+ if (mystrcasecmp(old, new) != 0) { /* Not changing just the case */
h = db_find_property(oid, new, 0);
if (h.ptr
- || property_defined_at_or_below(new, str_hash(new), oid))
+ || property_defined_at_or_below(new, str_hash(new), oid))
return 0;
}
free_str(props->l[i].name);
@@ -191,15 +190,15 @@ db_rename_propdef(Objid oid, const char *old, const char *new)
static void
remove_prop(Objid oid, int pos)
{
- Pval *new_propval;
- Object *o;
- int i, nprops;
+ Pval *new_propval;
+ Object *o;
+ int i, nprops;
o = dbpriv_find_object(oid);
nprops = dbpriv_count_properties(oid);
free_var(o->propval[pos].var); /* free deleted property */
-
+
if (nprops) {
new_propval = mymalloc(nprops * sizeof(Pval), M_PVAL);
for (i = 0; i < pos; i++)
@@ -217,14 +216,14 @@ remove_prop(Objid oid, int pos)
static void
remove_prop_recursively(Objid root, int root_pos)
{
- Objid c;
+ Objid c;
remove_prop(root, root_pos);
for (c = dbpriv_find_object(root)->child;
c != NOTHING;
c = dbpriv_find_object(c)->sibling) {
- int new_prop_count = dbpriv_find_object(c)->propdefs.cur_length;
-
+ int new_prop_count = dbpriv_find_object(c)->propdefs.cur_length;
+
remove_prop_recursively(c, new_prop_count + root_pos);
}
}
@@ -232,26 +231,26 @@ remove_prop_recursively(Objid root, int root_pos)
int
db_delete_propdef(Objid oid, const char *pname)
{
- Proplist *props = &dbpriv_find_object(oid)->propdefs;
- int hash = str_hash(pname);
- int count = props->cur_length;
- int max = props->max_length;
- int i, j;
-
+ Proplist *props = &dbpriv_find_object(oid)->propdefs;
+ int hash = str_hash(pname);
+ int count = props->cur_length;
+ int max = props->max_length;
+ int i, j;
+
for (i = 0; i < count; i++) {
Propdef p;
-
+
p = props->l[i];
- if (p.hash == hash && !mystrcasecmp(p.name, pname)) {
+ if (p.hash == hash && !mystrcasecmp(p.name, pname)) {
if (p.name)
free_str(p.name);
- if (max > 8 && props->cur_length <= ((max * 3) / 8)) {
- int new_size = max / 2;
- Propdef *new_props;
+ if (max > 8 && props->cur_length <= ((max * 3) / 8)) {
+ int new_size = max / 2;
+ Propdef *new_props;
new_props = mymalloc(new_size * sizeof(Propdef), M_PROPDEF);
-
+
for (j = 0; j < i; j++)
new_props[j] = props->l[j];
for (j = i + 1; j < count; j++)
@@ -270,7 +269,7 @@ db_delete_propdef(Objid oid, const char *pname)
return 1;
}
}
-
+
return 0;
}
@@ -281,11 +280,11 @@ db_count_propdefs(Objid oid)
}
int
-db_for_all_propdefs(Objid oid, int (*func)(void *, const char *), void *data)
+db_for_all_propdefs(Objid oid, int (*func) (void *, const char *), void *data)
{
- int i;
- Object *o = dbpriv_find_object(oid);
- int len = o->propdefs.cur_length;
+ int i;
+ Object *o = dbpriv_find_object(oid);
+ int len = o->propdefs.cur_length;
for (i = 0; i < len; i++)
if (func(data, o->propdefs.l[i].name))
@@ -295,14 +294,14 @@ db_for_all_propdefs(Objid oid, int (*func)(void *, const char *), void *data)
}
struct contents_data {
- Var r;
- int i;
+ Var r;
+ int i;
};
static int
add_to_list(void *data, Objid c)
{
- struct contents_data *d = data;
+ struct contents_data *d = data;
d->i++;
d->r.v.list[d->i].type = TYPE_OBJ;
@@ -312,47 +311,47 @@ add_to_list(void *data, Objid c)
}
static void
-get_bi_value(db_prop_handle h, Var *value)
+get_bi_value(db_prop_handle h, Var * value)
{
- Objid oid = *((Objid *) h.ptr);
+ Objid oid = *((Objid *) h.ptr);
switch (h.built_in) {
- case BP_NAME:
+ case BP_NAME:
value->type = TYPE_STR;
value->v.str = str_ref(db_object_name(oid));
break;
- case BP_OWNER:
+ case BP_OWNER:
value->type = TYPE_OBJ;
value->v.obj = db_object_owner(oid);
break;
- case BP_PROGRAMMER:
+ case BP_PROGRAMMER:
value->type = TYPE_INT;
value->v.num = db_object_has_flag(oid, FLAG_PROGRAMMER);
break;
- case BP_WIZARD:
+ case BP_WIZARD:
value->type = TYPE_INT;
value->v.num = db_object_has_flag(oid, FLAG_WIZARD);
break;
- case BP_R:
+ case BP_R:
value->type = TYPE_INT;
value->v.num = db_object_has_flag(oid, FLAG_READ);
break;
- case BP_W:
+ case BP_W:
value->type = TYPE_INT;
value->v.num = db_object_has_flag(oid, FLAG_WRITE);
break;
- case BP_F:
+ case BP_F:
value->type = TYPE_INT;
value->v.num = db_object_has_flag(oid, FLAG_FERTILE);
break;
- case BP_LOCATION:
+ case BP_LOCATION:
value->type = TYPE_OBJ;
value->v.obj = db_object_location(oid);
break;
- case BP_CONTENTS:
+ case BP_CONTENTS:
{
- struct contents_data d;
-
+ struct contents_data d;
+
d.r = new_list(db_count_contents(oid));
d.i = 0;
db_for_all_contents(oid, add_to_list, &d);
@@ -360,44 +359,61 @@ get_bi_value(db_prop_handle h, Var *value)
*value = d.r;
}
break;
- default:
+ default:
panic("Unknown built-in property in GET_BI_VALUE!");
}
}
db_prop_handle
-db_find_property(Objid oid, const char *name, Var *value)
+db_find_property(Objid oid, const char *name, Var * value)
{
static struct {
- const char *name;
- enum bi_prop prop;
- int hash;
+ const char *name;
+ enum bi_prop prop;
+ int hash;
} ptable[] = {
- {"name", BP_NAME, 0},
- {"owner", BP_OWNER, 0},
- {"programmer", BP_PROGRAMMER, 0},
- {"wizard", BP_WIZARD, 0},
- {"r", BP_R, 0},
- {"w", BP_W, 0},
- {"f", BP_F, 0},
- {"location", BP_LOCATION, 0},
- {"contents", BP_CONTENTS, 0}
+ {
+ "name", BP_NAME, 0
+ },
+ {
+ "owner", BP_OWNER, 0
+ },
+ {
+ "programmer", BP_PROGRAMMER, 0
+ },
+ {
+ "wizard", BP_WIZARD, 0
+ },
+ {
+ "r", BP_R, 0
+ },
+ {
+ "w", BP_W, 0
+ },
+ {
+ "f", BP_F, 0
+ },
+ {
+ "location", BP_LOCATION, 0
+ },
+ {
+ "contents", BP_CONTENTS, 0
+ }
};
- static int ptable_init = 0;
- int i, n;
- db_prop_handle h;
- int hash = str_hash(name);
- Object *o;
+ static int ptable_init = 0;
+ int i, n;
+ db_prop_handle h;
+ int hash = str_hash(name);
+ Object *o;
if (!ptable_init) {
for (i = 0; i < Arraysize(ptable); i++)
ptable[i].hash = str_hash(ptable[i].name);
ptable_init = 1;
}
-
for (i = 0; i < Arraysize(ptable); i++) {
if (ptable[i].hash == hash && !mystrcasecmp(name, ptable[i].name)) {
- static Objid ret;
+ static Objid ret;
ret = oid;
h.built_in = ptable[i].prop;
@@ -412,19 +428,19 @@ db_find_property(Objid oid, const char *name, Var *value)
h.built_in = BP_NONE;
n = 0;
for (o = dbpriv_find_object(oid); o; o = dbpriv_find_object(o->parent)) {
- Proplist *props = &(o->propdefs);
- Propdef *defs = props->l;
- int length = props->cur_length;
+ Proplist *props = &(o->propdefs);
+ Propdef *defs = props->l;
+ int length = props->cur_length;
for (i = 0; i < length; i++, n++) {
if (defs[i].hash == hash
&& !mystrcasecmp(defs[i].name, name)) {
- Pval *prop;
+ Pval *prop;
h.definer = o->id;
o = dbpriv_find_object(oid);
prop = h.ptr = o->propval + n;
-
+
if (value) {
while (prop->var.type == TYPE_CLEAR) {
n -= o->propdefs.cur_length;
@@ -445,12 +461,12 @@ db_find_property(Objid oid, const char *name, Var *value)
Var
db_property_value(db_prop_handle h)
{
- Var value;
-
+ Var value;
+
if (h.built_in)
get_bi_value(h, &value);
else {
- Pval *prop = h.ptr;
+ Pval *prop = h.ptr;
value = prop->var;
}
@@ -462,38 +478,38 @@ void
db_set_property_value(db_prop_handle h, Var value)
{
if (!h.built_in) {
- Pval *prop = h.ptr;
+ Pval *prop = h.ptr;
free_var(prop->var);
prop->var = value;
} else {
- Objid oid = *((Objid *) h.ptr);
- db_object_flag flag;
-
+ Objid oid = *((Objid *) h.ptr);
+ db_object_flag flag;
+
switch (h.built_in) {
- case BP_NAME:
+ case BP_NAME:
if (value.type != TYPE_STR)
goto complain;
db_set_object_name(oid, value.v.str);
break;
- case BP_OWNER:
+ case BP_OWNER:
if (value.type != TYPE_OBJ)
goto complain;
db_set_object_owner(oid, value.v.obj);
break;
- case BP_PROGRAMMER:
+ case BP_PROGRAMMER:
flag = FLAG_PROGRAMMER;
goto finish_flag;
- case BP_WIZARD:
+ case BP_WIZARD:
flag = FLAG_WIZARD;
goto finish_flag;
- case BP_R:
+ case BP_R:
flag = FLAG_READ;
goto finish_flag;
- case BP_W:
+ case BP_W:
flag = FLAG_WRITE;
goto finish_flag;
- case BP_F:
+ case BP_F:
flag = FLAG_FERTILE;
finish_flag:
if (is_true(value))
@@ -502,12 +518,12 @@ db_set_property_value(db_prop_handle h, Var value)
db_clear_object_flag(oid, flag);
free_var(value);
break;
- case BP_LOCATION:
- case BP_CONTENTS:
+ case BP_LOCATION:
+ case BP_CONTENTS:
complain:
panic("Inappropriate value in DB_SET_PROPERTY_VALUE!");
break;
- default:
+ default:
panic("Unknown built-in property in DB_SET_PROPERTY_VALUE!");
}
}
@@ -520,7 +536,7 @@ db_property_owner(db_prop_handle h)
panic("Built-in property in DB_PROPERTY_OWNER!");
return NOTHING;
} else {
- Pval *prop = h.ptr;
+ Pval *prop = h.ptr;
return prop->owner;
}
@@ -532,7 +548,7 @@ db_set_property_owner(db_prop_handle h, Objid oid)
if (h.built_in)
panic("Built-in property in DB_SET_PROPERTY_OWNER!");
else {
- Pval *prop = h.ptr;
+ Pval *prop = h.ptr;
prop->owner = oid;
}
@@ -545,7 +561,7 @@ db_property_flags(db_prop_handle h)
panic("Built-in property in DB_PROPERTY_FLAGS!");
return 0;
} else {
- Pval *prop = h.ptr;
+ Pval *prop = h.ptr;
return prop->perms;
}
@@ -557,7 +573,7 @@ db_set_property_flags(db_prop_handle h, unsigned flags)
if (h.built_in)
panic("Built-in property in DB_SET_PROPERTY_FLAGS!");
else {
- Pval *prop = h.ptr;
+ Pval *prop = h.ptr;
prop->perms = flags;
}
@@ -574,12 +590,12 @@ db_property_allows(db_prop_handle h, Objid progr, db_prop_flag flag)
static void
fix_props(Objid oid, int parent_local, int old, int new, int common)
{
- Object *me = dbpriv_find_object(oid);
- Object *parent = dbpriv_find_object(me->parent);
- Pval *new_propval;
- int local = parent_local;
- int i;
- Objid c;
+ Object *me = dbpriv_find_object(oid);
+ Object *parent = dbpriv_find_object(me->parent);
+ Pval *new_propval;
+ int local = parent_local;
+ int i;
+ Objid c;
local += me->propdefs.cur_length;
@@ -591,7 +607,7 @@ fix_props(Objid oid, int parent_local, int old, int new, int common)
for (i = 0; i < local; i++)
new_propval[i] = me->propval[i];
for (i = 0; i < new; i++) {
- Pval pv;
+ Pval pv;
pv = parent->propval[parent_local + i];
new_propval[local + i] = pv;
@@ -615,14 +631,14 @@ fix_props(Objid oid, int parent_local, int old, int new, int common)
int
dbpriv_check_properties_for_chparent(Objid oid, Objid new_parent)
{
- Object *o;
- int i;
+ Object *o;
+ int i;
for (o = dbpriv_find_object(new_parent);
o;
o = dbpriv_find_object(o->parent)) {
- Proplist *props = &o->propdefs;
-
+ Proplist *props = &o->propdefs;
+
for (i = 0; i < props->cur_length; i++)
if (property_defined_at_or_below(props->l[i].name,
props->l[i].hash,
@@ -636,8 +652,8 @@ dbpriv_check_properties_for_chparent(Objid oid, Objid new_parent)
void
dbpriv_fix_properties_after_chparent(Objid oid, Objid old_parent)
{
- Objid o1, o2, common, new_parent;
- int common_props, old_props, new_props;
+ Objid o1, o2, common, new_parent;
+ int common_props, old_props, new_props;
/* Find the nearest common ancestor between old & new parent */
new_parent = db_object_parent(oid);
@@ -664,9 +680,12 @@ dbpriv_fix_properties_after_chparent(Objid oid, Objid old_parent)
char rcsid_db_properties[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:31 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.6 1996/04/08 01:08:32 pavel
* Fixed `db_rename_propdef()' to allow case-only changes. Release 1.8.0p3.
*
diff --git a/db_verbs.c b/db_verbs.c
index 578026d..5090c46 100644
--- a/db_verbs.c
+++ b/db_verbs.c
@@ -30,17 +30,18 @@
#include "program.h"
#include "storage.h"
#include "utils.h"
-
+
/*********** Prepositions ***********/
-#define MAXPPHRASE 3 /* max. number of words in a prepositional phrase */
+#define MAXPPHRASE 3 /* max. number of words in a prepositional phrase */
/* NOTE: New prepositional phrases should only be added to this list at the
* end, never in the middle, and no entries should every be removed from this
* list; the list indices are stored raw in the DB file.
*/
-static const char *prep_list[] = {
+static const char *prep_list[] =
+{
"with/using",
"at/to",
"in front of",
@@ -61,23 +62,23 @@ static const char *prep_list[] = {
#define NPREPS Arraysize(prep_list)
typedef struct pt_entry {
- int nwords;
- char *words[MAXPPHRASE];
+ int nwords;
+ char *words[MAXPPHRASE];
struct pt_entry *next;
} pt_entry;
-struct pt_entry *prep_table[NPREPS];
+struct pt_entry *prep_table[NPREPS];
void
dbpriv_build_prep_table(void)
{
- int i, j;
- int nwords;
- char **words;
- char cprep[100];
+ int i, j;
+ int nwords;
+ char **words;
+ char cprep[100];
const char *p;
- char *t;
- pt_entry *current_alias, **prev;
+ char *t;
+ pt_entry *current_alias, **prev;
for (i = 0; i < NPREPS; i++) {
p = prep_list[i];
@@ -112,9 +113,9 @@ dbpriv_build_prep_table(void)
db_prep_spec
db_find_prep(int argc, char *argv[], int *first, int *last)
{
- pt_entry *alias;
- int i, j, k;
- int exact_match = (first == 0 || last == 0);
+ pt_entry *alias;
+ int i, j, k;
+ int exact_match = (first == 0 || last == 0);
for (i = 0; i < argc; i++) {
for (j = 0; j < NPREPS; j++) {
@@ -125,8 +126,8 @@ db_find_prep(int argc, char *argv[], int *first, int *last)
break;
}
if (k == alias->nwords
- && (! exact_match || i + k == argc)) {
- if (! exact_match) {
+ && (!exact_match || i + k == argc)) {
+ if (!exact_match) {
*first = i;
*last = i + alias->nwords - 1;
}
@@ -144,11 +145,11 @@ db_find_prep(int argc, char *argv[], int *first, int *last)
db_prep_spec
db_match_prep(const char *prepname)
{
- db_prep_spec prep;
- int argc;
- char *ptr;
- char **argv;
- char *s, first;
+ db_prep_spec prep;
+ int argc;
+ char *ptr;
+ char **argv;
+ char *s, first;
s = str_dup(prepname);
first = s[0];
@@ -162,7 +163,6 @@ db_match_prep(const char *prepname)
else
return prep;
}
-
if ((ptr = strchr(s, '/')) != '\0')
*ptr = '\0';
@@ -182,8 +182,8 @@ db_unparse_prep(db_prep_spec prep)
else
return prep_list[prep];
}
-
+
/*********** Verbs ***********/
#define DOBJSHIFT 4
@@ -195,8 +195,8 @@ void
db_add_verb(Objid oid, const char *vnames, Objid owner, unsigned flags,
db_arg_spec dobj, db_prep_spec prep, db_arg_spec iobj)
{
- Object *o = dbpriv_find_object(oid);
- Verbdef *v, *newv;
+ Object *o = dbpriv_find_object(oid);
+ Verbdef *v, *newv;
newv = mymalloc(sizeof(Verbdef), M_VERBDEF);
newv->name = vnames;
@@ -206,21 +206,20 @@ db_add_verb(Objid oid, const char *vnames, Objid owner, unsigned flags,
newv->next = 0;
newv->program = 0;
if (o->verbdefs) {
- for (v = o->verbdefs; v->next; v = v->next)
- ;
+ for (v = o->verbdefs; v->next; v = v->next);
v->next = newv;
} else
o->verbdefs = newv;
}
static Verbdef *
-find_verbdef_by_name(Object *o, const char *vname, int check_x_bit)
+find_verbdef_by_name(Object * o, const char *vname, int check_x_bit)
{
- Verbdef *v;
+ Verbdef *v;
for (v = o->verbdefs; v; v = v->next)
if (verbcasecmp(v->name, vname)
- && (!check_x_bit || (v->perms & VF_EXEC)))
+ && (!check_x_bit || (v->perms & VF_EXEC)))
break;
return v;
@@ -229,9 +228,9 @@ find_verbdef_by_name(Object *o, const char *vname, int check_x_bit)
int
db_count_verbs(Objid oid)
{
- int count = 0;
- Object *o = dbpriv_find_object(oid);
- Verbdef *v;
+ int count = 0;
+ Object *o = dbpriv_find_object(oid);
+ Verbdef *v;
for (v = o->verbdefs; v; v = v->next)
count++;
@@ -241,32 +240,32 @@ db_count_verbs(Objid oid)
int
db_for_all_verbs(Objid oid,
- int (*func)(void *data, const char *vname),
+ int (*func) (void *data, const char *vname),
void *data)
{
- Object *o = dbpriv_find_object(oid);
- Verbdef *v;
+ Object *o = dbpriv_find_object(oid);
+ Verbdef *v;
for (v = o->verbdefs; v; v = v->next)
- if ((*func)(data, v->name))
+ if ((*func) (data, v->name))
return 1;
return 0;
}
typedef struct { /* Non-null db_verb_handles point to these */
- Objid definer;
- Verbdef *verbdef;
+ Objid definer;
+ Verbdef *verbdef;
} handle;
void
db_delete_verb(db_verb_handle vh)
{
- handle *h = (handle *) vh.ptr;
- Objid oid = h->definer;
- Verbdef *v = h->verbdef;
- Object *o = dbpriv_find_object(oid);
- Verbdef *vv;
+ handle *h = (handle *) vh.ptr;
+ Objid oid = h->definer;
+ Verbdef *v = h->verbdef;
+ Object *o = dbpriv_find_object(oid);
+ Verbdef *vv;
vv = o->verbdefs;
if (vv == v)
@@ -288,20 +287,20 @@ db_verb_handle
db_find_command_verb(Objid oid, const char *verb,
db_arg_spec dobj, unsigned prep, db_arg_spec iobj)
{
- Object *o;
- Verbdef *v;
- static handle h;
- db_verb_handle vh;
+ Object *o;
+ Verbdef *v;
+ static handle h;
+ db_verb_handle vh;
for (o = dbpriv_find_object(oid); o; o = dbpriv_find_object(o->parent))
for (v = o->verbdefs; v; v = v->next) {
- db_arg_spec vdobj = (v->perms >> DOBJSHIFT) & OBJMASK;
- db_arg_spec viobj = (v->perms >> IOBJSHIFT) & OBJMASK;
+ db_arg_spec vdobj = (v->perms >> DOBJSHIFT) & OBJMASK;
+ db_arg_spec viobj = (v->perms >> IOBJSHIFT) & OBJMASK;
if (verbcasecmp(v->name, verb)
- && (vdobj == ASPEC_ANY || vdobj == dobj)
- && (v->prep == PREP_ANY || v->prep == prep)
- && (viobj == ASPEC_ANY || viobj == iobj)) {
+ && (vdobj == ASPEC_ANY || vdobj == dobj)
+ && (v->prep == PREP_ANY || v->prep == prep)
+ && (viobj == ASPEC_ANY || viobj == iobj)) {
h.definer = o->id;
h.verbdef = v;
vh.ptr = &h;
@@ -318,10 +317,10 @@ db_find_command_verb(Objid oid, const char *verb,
db_verb_handle
db_find_callable_verb(Objid oid, const char *verb)
{
- Object *o;
- Verbdef *v;
- static handle h;
- db_verb_handle vh;
+ Object *o;
+ Verbdef *v;
+ static handle h;
+ db_verb_handle vh;
for (o = dbpriv_find_object(oid); o; o = dbpriv_find_object(o->parent))
if ((v = find_verbdef_by_name(o, verb, 1)) != 0) {
@@ -331,7 +330,6 @@ db_find_callable_verb(Objid oid, const char *verb)
return vh;
}
-
vh.ptr = 0;
return vh;
@@ -340,12 +338,12 @@ db_find_callable_verb(Objid oid, const char *verb)
db_verb_handle
db_find_defined_verb(Objid oid, const char *vname, int allow_numbers)
{
- Object *o = dbpriv_find_object(oid);
- Verbdef *v;
- char *p;
- int num, i;
- static handle h;
- db_verb_handle vh;
+ Object *o = dbpriv_find_object(oid);
+ Verbdef *v;
+ char *p;
+ int num, i;
+ static handle h;
+ db_verb_handle vh;
if (!allow_numbers ||
(num = strtol(vname, &p, 10),
@@ -363,7 +361,6 @@ db_find_defined_verb(Objid oid, const char *vname, int allow_numbers)
return vh;
}
-
vh.ptr = 0;
return vh;
@@ -372,11 +369,11 @@ db_find_defined_verb(Objid oid, const char *vname, int allow_numbers)
db_verb_handle
db_find_indexed_verb(Objid oid, unsigned index)
{
- Object *o = dbpriv_find_object(oid);
- Verbdef *v;
- unsigned i;
- static handle h;
- db_verb_handle vh;
+ Object *o = dbpriv_find_object(oid);
+ Verbdef *v;
+ unsigned i;
+ static handle h;
+ db_verb_handle vh;
for (v = o->verbdefs, i = 0; v; v = v->next)
if (++i == index) {
@@ -386,7 +383,6 @@ db_find_indexed_verb(Objid oid, unsigned index)
return vh;
}
-
vh.ptr = 0;
return vh;
@@ -395,7 +391,7 @@ db_find_indexed_verb(Objid oid, unsigned index)
Objid
db_verb_definer(db_verb_handle vh)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h)
return h->definer;
@@ -407,7 +403,7 @@ db_verb_definer(db_verb_handle vh)
const char *
db_verb_names(db_verb_handle vh)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h)
return h->verbdef->name;
@@ -419,7 +415,7 @@ db_verb_names(db_verb_handle vh)
void
db_set_verb_names(db_verb_handle vh, const char *names)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h) {
if (h->verbdef->name)
@@ -432,7 +428,7 @@ db_set_verb_names(db_verb_handle vh, const char *names)
Objid
db_verb_owner(db_verb_handle vh)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h)
return h->verbdef->owner;
@@ -444,7 +440,7 @@ db_verb_owner(db_verb_handle vh)
void
db_set_verb_owner(db_verb_handle vh, Objid owner)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h)
h->verbdef->owner = owner;
@@ -455,7 +451,7 @@ db_set_verb_owner(db_verb_handle vh, Objid owner)
unsigned
db_verb_flags(db_verb_handle vh)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h)
return h->verbdef->perms & PERMMASK;
@@ -467,7 +463,7 @@ db_verb_flags(db_verb_handle vh)
void
db_set_verb_flags(db_verb_handle vh, unsigned flags)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h) {
h->verbdef->perms &= ~PERMMASK;
@@ -479,22 +475,21 @@ db_set_verb_flags(db_verb_handle vh, unsigned flags)
Program *
db_verb_program(db_verb_handle vh)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h) {
- Program *p = h->verbdef->program;
+ Program *p = h->verbdef->program;
return p ? p : null_program();
}
-
panic("DB_VERB_PROGRAM: Null handle!");
return 0;
}
void
-db_set_verb_program(db_verb_handle vh, Program *program)
+db_set_verb_program(db_verb_handle vh, Program * program)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h) {
if (h->verbdef->program)
@@ -506,9 +501,9 @@ db_set_verb_program(db_verb_handle vh, Program *program)
void
db_verb_arg_specs(db_verb_handle vh,
- db_arg_spec *dobj, db_prep_spec *prep, db_arg_spec *iobj)
+ db_arg_spec * dobj, db_prep_spec * prep, db_arg_spec * iobj)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h) {
*dobj = (h->verbdef->perms >> DOBJSHIFT) & OBJMASK;
@@ -520,9 +515,9 @@ db_verb_arg_specs(db_verb_handle vh,
void
db_set_verb_arg_specs(db_verb_handle vh,
- db_arg_spec dobj, db_prep_spec prep, db_arg_spec iobj)
+ db_arg_spec dobj, db_prep_spec prep, db_arg_spec iobj)
{
- handle *h = (handle *) vh.ptr;
+ handle *h = (handle *) vh.ptr;
if (h) {
h->verbdef->perms = ((h->verbdef->perms & PERMMASK)
@@ -545,9 +540,12 @@ db_verb_allows(db_verb_handle h, Objid progr, db_verb_flag flag)
char rcsid_db_verbs[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:31 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.4 1996/05/12 21:32:23 pavel
* Changed db_add_verb() not to bump the reference count of the given
* verb-names string. Release 1.8.0p5.
diff --git a/decompile.c b/decompile.c
index bb94116..c9e0265 100644
--- a/decompile.c
+++ b/decompile.c
@@ -15,7 +15,7 @@
Pavel@Xerox.Com
*****************************************************************************/
-#include "ast.h"
+#include "ast.h"
#include "decompile.h"
#include "exceptions.h"
#include "opcode.h"
@@ -24,17 +24,19 @@
#include "utils.h"
static Program *program;
-static Expr **expr_stack;
-static int top_expr_stack;
+static Expr **expr_stack;
+static int top_expr_stack;
-static Byte *hot_byte;
-static void *hot_node;
-static enum { TOP, ENDBODY, BOTTOM, DONE } hot_position;
+static Byte *hot_byte;
+static void *hot_node;
+static enum {
+ TOP, ENDBODY, BOTTOM, DONE
+} hot_position;
-static int lineno;
+static int lineno;
static void
-push_expr(Expr *expr)
+push_expr(Expr * expr)
{
expr_stack[top_expr_stack++] = expr;
}
@@ -85,16 +87,16 @@ do { \
#define READ_JUMP(is_hot) read_jump(bc.numbytes_label, &ptr, &is_hot)
static unsigned
-read_jump(unsigned numbytes_label, Byte **p, int *is_hot)
+read_jump(unsigned numbytes_label, Byte ** p, int *is_hot)
{
- Byte *ptr = *p;
- unsigned label;
+ Byte *ptr = *p;
+ unsigned label;
*is_hot = (ptr == hot_byte);
if (*ptr++ != OP_JUMP)
panic("Missing JUMP in DECOMPILE!");
-
- label = READ_BYTES(numbytes_label);
+
+ label = READ_BYTES(numbytes_label);
*p = ptr;
return label;
@@ -123,21 +125,21 @@ read_jump(unsigned numbytes_label, Byte **p, int *is_hot)
(ptr = decompile(bc, start, end, stmt_sink, arm_sink))
static Byte *
-decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
- Cond_Arm **arm_sink)
+decompile(Bytecodes bc, Byte * start, Byte * end, Stmt ** stmt_sink,
+ Cond_Arm ** arm_sink)
{
/*** The reader will likely find it useful to consult the file
*** `MOOCodeSequences.txt' in this directory while reading this function.
***/
- Byte *ptr = start;
- unsigned stmt_start = start - bc.vector;
- unsigned jump_len = bc.numbytes_label + 1;
- Stmt *s;
- Expr *e;
- enum Expr_Kind kind;
- void *node;
- int asgn_hot = 0;
+ Byte *ptr = start;
+ unsigned stmt_start = start - bc.vector;
+ unsigned jump_len = bc.numbytes_label + 1;
+ Stmt *s;
+ Expr *e;
+ enum Expr_Kind kind;
+ void *node;
+ int asgn_hot = 0;
if (stmt_sink)
*stmt_sink = 0;
@@ -145,9 +147,9 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
*arm_sink = 0;
while (ptr < end) {
- int op_hot = (ptr == hot_byte);
- Opcode op = *ptr++;
-
+ int op_hot = (ptr == hot_byte);
+ Opcode op = *ptr++;
+
if (IS_PUSH_n(op)) {
e = alloc_expr(EXPR_ID);
e->e.id = PUSH_n_INDEX(op);
@@ -165,16 +167,15 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
push_expr(HOT_OP(e));
continue;
}
-
switch (op) {
- case OP_IF:
+ case OP_IF:
{
- unsigned next = READ_LABEL();
- Expr *condition = pop_expr();
- Stmt *arm_stmts;
- Cond_Arm *arm;
- unsigned done;
- int jump_hot;
+ unsigned next = READ_LABEL();
+ Expr *condition = pop_expr();
+ Stmt *arm_stmts;
+ Cond_Arm *arm;
+ unsigned done;
+ int jump_hot;
s = alloc_stmt(STMT_COND);
DECOMPILE(bc, ptr, bc.vector + next - jump_len, &arm_stmts, 0);
@@ -184,18 +185,18 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
HOT_BOTTOM(jump_hot, arm);
DECOMPILE(bc, ptr, bc.vector + done, &(s->s.cond.otherwise),
&(arm->next));
-
+
ADD_STMT(s);
}
break;
- case OP_EIF:
+ case OP_EIF:
{
- unsigned next = READ_LABEL();
- Expr *condition = pop_expr();
- Stmt *arm_stmts;
- Cond_Arm *arm;
- unsigned done;
- int jump_hot;
+ unsigned next = READ_LABEL();
+ Expr *condition = pop_expr();
+ Stmt *arm_stmts;
+ Cond_Arm *arm;
+ unsigned done;
+ int jump_hot;
DECOMPILE(bc, ptr, bc.vector + next - jump_len, &arm_stmts, 0);
ADD_ARM(arm = alloc_cond_arm(condition, arm_stmts));
@@ -207,14 +208,14 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
stmt_start = ptr - bc.vector;
}
break;
- case OP_FOR_LIST:
+ case OP_FOR_LIST:
{
- unsigned top = (ptr - 1) - bc.vector;
- int id = READ_ID();
- unsigned done = READ_LABEL();
- Expr *one = pop_expr();
- Expr *list = pop_expr();
- int jump_hot;
+ unsigned top = (ptr - 1) - bc.vector;
+ int id = READ_ID();
+ unsigned done = READ_LABEL();
+ Expr *one = pop_expr();
+ Expr *list = pop_expr();
+ int jump_hot;
if (one->kind != EXPR_VAR
|| one->e.var.type != TYPE_INT
@@ -233,14 +234,14 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
ADD_STMT(HOT_OP2(one, list, s));
}
break;
- case OP_FOR_RANGE:
+ case OP_FOR_RANGE:
{
- unsigned top = (ptr - 1) - bc.vector;
- int id = READ_ID();
- unsigned done = READ_LABEL();
- Expr *to = pop_expr();
- Expr *from = pop_expr();
- int jump_hot;
+ unsigned top = (ptr - 1) - bc.vector;
+ int id = READ_ID();
+ unsigned done = READ_LABEL();
+ Expr *to = pop_expr();
+ Expr *from = pop_expr();
+ int jump_hot;
s = alloc_stmt(STMT_RANGE);
s->s.range.id = id;
@@ -254,15 +255,15 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
ADD_STMT(HOT_OP2(from, to, s));
}
break;
- case OP_WHILE:
+ case OP_WHILE:
s = alloc_stmt(STMT_WHILE);
s->s.loop.id = -1;
finish_while:
{
- unsigned top = stmt_start;
- unsigned done = READ_LABEL();
- Expr *condition = pop_expr();
- int jump_hot;
+ unsigned top = stmt_start;
+ unsigned done = READ_LABEL();
+ Expr *condition = pop_expr();
+ int jump_hot;
s->s.loop.condition = condition;
DECOMPILE(bc, ptr, bc.vector + done - jump_len,
@@ -273,12 +274,12 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
ADD_STMT(HOT_OP1(condition, s));
}
break;
- case OP_FORK:
- case OP_FORK_WITH_ID:
+ case OP_FORK:
+ case OP_FORK_WITH_ID:
{
- Bytecodes fbc;
- int id;
- Expr *time = pop_expr();
+ Bytecodes fbc;
+ int id;
+ Expr *time = pop_expr();
fbc = READ_FORK();
id = (op == OP_FORK ? -1 : READ_ID());
@@ -291,35 +292,35 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
ADD_STMT(HOT_OP1(time, s));
}
break;
- case OP_POP:
+ case OP_POP:
s = alloc_stmt(STMT_EXPR);
e = s->s.expr = pop_expr();
ADD_STMT(HOT_OP1(e, s));
break;
- case OP_RETURN:
- case OP_RETURN0:
+ case OP_RETURN:
+ case OP_RETURN0:
s = alloc_stmt(STMT_RETURN);
e = s->s.expr = (op == OP_RETURN ? pop_expr() : 0);
ADD_STMT(HOT(op_hot || (e && e == hot_node), s));
break;
- case OP_DONE:
+ case OP_DONE:
if (ptr != end)
panic("DONE not at end in DECOMPILE!");
break;
- case OP_IMM:
+ case OP_IMM:
e = alloc_expr(EXPR_VAR);
e->e.var = var_ref(READ_LITERAL());
push_expr(HOT_OP(e));
break;
- case OP_G_PUSH:
+ case OP_G_PUSH:
e = alloc_expr(EXPR_ID);
e->e.id = READ_ID();
push_expr(HOT_OP(e));
break;
- case OP_AND:
- case OP_OR:
+ case OP_AND:
+ case OP_OR:
{
- unsigned done = READ_LABEL();
+ unsigned done = READ_LABEL();
e = pop_expr();
DECOMPILE(bc, ptr, bc.vector + done, 0, 0);
@@ -330,64 +331,64 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
push_expr(HOT_OP2(e->e.bin.lhs, e->e.bin.rhs, e));
}
break;
- case OP_UNARY_MINUS:
- case OP_NOT:
+ case OP_UNARY_MINUS:
+ case OP_NOT:
e = alloc_expr(op == OP_NOT ? EXPR_NOT : EXPR_NEGATE);
e->e.expr = pop_expr();
push_expr(HOT_OP1(e->e.expr, e));
break;
- case OP_GET_PROP:
- case OP_PUSH_GET_PROP:
+ case OP_GET_PROP:
+ case OP_PUSH_GET_PROP:
kind = EXPR_PROP;
goto finish_binary;
- case OP_EQ:
+ case OP_EQ:
kind = EXPR_EQ;
goto finish_binary;
- case OP_NE:
+ case OP_NE:
kind = EXPR_NE;
goto finish_binary;
- case OP_LT:
+ case OP_LT:
kind = EXPR_LT;
goto finish_binary;
- case OP_LE:
+ case OP_LE:
kind = EXPR_LE;
goto finish_binary;
- case OP_GT:
+ case OP_GT:
kind = EXPR_GT;
goto finish_binary;
- case OP_GE:
+ case OP_GE:
kind = EXPR_GE;
goto finish_binary;
- case OP_IN:
+ case OP_IN:
kind = EXPR_IN;
goto finish_binary;
- case OP_ADD:
+ case OP_ADD:
kind = EXPR_PLUS;
goto finish_binary;
- case OP_MINUS:
+ case OP_MINUS:
kind = EXPR_MINUS;
goto finish_binary;
- case OP_MULT:
+ case OP_MULT:
kind = EXPR_TIMES;
goto finish_binary;
- case OP_DIV:
+ case OP_DIV:
kind = EXPR_DIVIDE;
goto finish_binary;
- case OP_MOD:
+ case OP_MOD:
kind = EXPR_MOD;
goto finish_binary;
- case OP_REF:
- case OP_PUSH_REF:
+ case OP_REF:
+ case OP_PUSH_REF:
kind = EXPR_INDEX;
finish_binary:
e = pop_expr();
e = alloc_binary(kind, pop_expr(), e);
push_expr(HOT_OP2(e->e.bin.lhs, e->e.bin.rhs, e));
break;
- case OP_RANGE_REF:
+ case OP_RANGE_REF:
{
- Expr *e1 = pop_expr();
- Expr *e2 = pop_expr();
+ Expr *e1 = pop_expr();
+ Expr *e2 = pop_expr();
e = alloc_expr(EXPR_RANGE);
e->e.range.base = pop_expr();
@@ -396,9 +397,9 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
push_expr(HOT_OP3(e1, e2, e->e.range.base, e));
}
break;
- case OP_BI_FUNC_CALL:
+ case OP_BI_FUNC_CALL:
{
- Expr *a = pop_expr();
+ Expr *a = pop_expr();
if (a->kind != EXPR_LIST)
panic("Missing arglist for BI_FUNC_CALL in DECOMPILE!");
@@ -409,10 +410,10 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
push_expr(HOT_OP1(a, e));
}
break;
- case OP_CALL_VERB:
+ case OP_CALL_VERB:
{
- Expr *a = pop_expr();
- Expr *e2 = pop_expr();
+ Expr *a = pop_expr();
+ Expr *e2 = pop_expr();
if (a->kind != EXPR_LIST)
panic("Missing arglist for CALL_VERB in DECOMPILE!");
@@ -421,10 +422,10 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
push_expr(HOT_OP3(e->e.verb.obj, a, e2, e));
}
break;
- case OP_IF_QUES:
+ case OP_IF_QUES:
{
- unsigned label = READ_LABEL();
- int jump_hot;
+ unsigned label = READ_LABEL();
+ int jump_hot;
e = alloc_expr(EXPR_COND);
e->e.cond.condition = pop_expr();
@@ -440,18 +441,18 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
e));
}
break;
- case OP_PUT_TEMP:
+ case OP_PUT_TEMP:
/* Ignore; following RANGESET or INDEXSET does the work */
if (op_hot)
asgn_hot = 1;
break;
- case OP_INDEXSET:
+ case OP_INDEXSET:
/* Most of the lvalue has already been constructed on the stack.
* Add the final indexing.
*/
{
- Expr *rvalue = pop_expr();
- Expr *index = pop_expr();
+ Expr *rvalue = pop_expr();
+ Expr *index = pop_expr();
e = alloc_binary(EXPR_INDEX, pop_expr(), index);
push_expr(HOT3(op_hot || asgn_hot,
@@ -464,21 +465,21 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
*/
asgn_hot = 0;
while (*ptr != OP_PUSH_TEMP) {
- if (ptr == hot_byte) /* it's our assignment expression */
+ if (ptr == hot_byte) /* it's our assignment expression */
hot_node = expr_stack[top_expr_stack];
ptr++;
}
ptr++;
break;
- case OP_G_PUT:
+ case OP_G_PUT:
e = alloc_expr(EXPR_ID);
e->e.id = READ_ID();
e = alloc_binary(EXPR_ASGN, e, pop_expr());
push_expr(HOT_OP1(e->e.bin.rhs, e));
break;
- case OP_PUT_PROP:
+ case OP_PUT_PROP:
{
- Expr *rvalue = pop_expr();
+ Expr *rvalue = pop_expr();
e = pop_expr();
e = alloc_binary(EXPR_PROP, pop_expr(), e);
@@ -486,53 +487,52 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
alloc_binary(EXPR_ASGN, e, rvalue)));
}
break;
- case OP_MAKE_EMPTY_LIST:
+ case OP_MAKE_EMPTY_LIST:
e = alloc_expr(EXPR_LIST);
e->e.list = 0;
push_expr(HOT_OP(e));
break;
- case OP_MAKE_SINGLETON_LIST:
+ case OP_MAKE_SINGLETON_LIST:
e = alloc_expr(EXPR_LIST);
e->e.list = alloc_arg_list(ARG_NORMAL, pop_expr());
push_expr(HOT_OP1(e->e.list->expr, e));
break;
- case OP_CHECK_LIST_FOR_SPLICE:
+ case OP_CHECK_LIST_FOR_SPLICE:
e = alloc_expr(EXPR_LIST);
e->e.list = alloc_arg_list(ARG_SPLICE, pop_expr());
push_expr(HOT_OP1(e->e.list->expr, e));
break;
- case OP_LIST_ADD_TAIL:
- case OP_LIST_APPEND:
+ case OP_LIST_ADD_TAIL:
+ case OP_LIST_APPEND:
{
- Expr *list;
- Arg_List *a;
+ Expr *list;
+ Arg_List *a;
e = pop_expr();
list = pop_expr();
if (list->kind != EXPR_LIST)
panic("Missing list expression in DECOMPILE!");
- for (a = list->e.list; a->next; a = a->next)
- ;
+ for (a = list->e.list; a->next; a = a->next);
a->next = alloc_arg_list(op == OP_LIST_APPEND ? ARG_SPLICE
- : ARG_NORMAL, e);
+ : ARG_NORMAL, e);
push_expr(HOT_OP1(e, list));
}
break;
- case OP_PUSH_TEMP:
- case OP_JUMP:
+ case OP_PUSH_TEMP:
+ case OP_JUMP:
panic("Unexpected opcode in DECOMPILE!");
break;
- case OP_EXTENDED:
+ case OP_EXTENDED:
{
- Extended_Opcode eop = *ptr++;
+ Extended_Opcode eop = *ptr++;
switch (eop) {
- case EOP_RANGESET:
+ case EOP_RANGESET:
/* Most of the lvalue has already been constructed on the
* stack. Add the final subranging.
*/
{
- Expr *rvalue = pop_expr();
+ Expr *rvalue = pop_expr();
e = alloc_expr(EXPR_RANGE);
e->e.range.to = pop_expr();
@@ -541,34 +541,34 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
push_expr(HOT4(op_hot || asgn_hot,
e->e.range.base, e->e.range.from,
e->e.range.to, rvalue,
- alloc_binary(EXPR_ASGN, e, rvalue)));
+ alloc_binary(EXPR_ASGN, e, rvalue)));
}
goto finish_indexed_assignment;
- case EOP_LENGTH:
+ case EOP_LENGTH:
READ_STACK();
e = alloc_expr(EXPR_LENGTH);
push_expr(HOT_OP(e));
break;
- case EOP_EXP:
+ case EOP_EXP:
kind = EXPR_EXP;
goto finish_binary;
- case EOP_SCATTER:
+ case EOP_SCATTER:
{
- Scatter *sc, **scp;
- int nargs = *ptr++;
- int rest = (ptr++, *ptr++); /* skip nreq */
- int *next_label = 0;
- int i, done, is_hot = op_hot;
+ Scatter *sc, **scp;
+ int nargs = *ptr++;
+ int rest = (ptr++, *ptr++); /* skip nreq */
+ int *next_label = 0;
+ int i, done, is_hot = op_hot;
for (i = 1, scp = &sc;
i <= nargs;
i++, scp = &((*scp)->next)) {
- int id = READ_ID();
- int label = READ_LABEL();
+ int id = READ_ID();
+ int label = READ_LABEL();
*scp = alloc_scatter(i == rest ? SCAT_REST :
- label == 0 ? SCAT_REQUIRED
- : SCAT_OPTIONAL,
+ label == 0 ? SCAT_REQUIRED
+ : SCAT_OPTIONAL,
id, 0);
if (label > 1) {
(*scp)->label = label;
@@ -585,8 +585,8 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
e->e.scatter = sc;
for (sc = e->e.scatter; sc; sc = sc->next)
if (sc->label) {
- Expr *defallt;
-
+ Expr *defallt;
+
if (ptr != bc.vector + sc->label)
panic("Misplaced default in DECOMPILE!");
DECOMPILE(bc, ptr,
@@ -611,19 +611,19 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
panic("Not at end of scatter in DECOMPILE!");
}
break;
- case EOP_PUSH_LABEL:
+ case EOP_PUSH_LABEL:
e = alloc_var(TYPE_INT);
e->e.var.v.num = READ_LABEL();
push_expr(HOT_OP(e));
break;
- case EOP_CATCH:
+ case EOP_CATCH:
{
- Expr *label_expr = pop_expr();
- Expr *codes = pop_expr();
- Expr *try_expr, *default_expr = 0;
- Arg_List *a = 0; /* silence warning */
- int label, done;
- int is_hot = op_hot;
+ Expr *label_expr = pop_expr();
+ Expr *codes = pop_expr();
+ Expr *try_expr, *default_expr = 0;
+ Arg_List *a = 0; /* silence warning */
+ int label, done;
+ int is_hot = op_hot;
if (label_expr->kind != EXPR_VAR
|| label_expr->e.var.type != TYPE_INT)
@@ -668,21 +668,21 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
e->e.catch.codes = a;
e->e.catch.except = default_expr;
push_expr(HOT3(is_hot || (default_expr
- && default_expr == hot_node),
+ && default_expr == hot_node),
label_expr, codes, try_expr,
e));
}
break;
- case EOP_END_CATCH:
+ case EOP_END_CATCH:
/* Early exit; main logic is in CATCH case, above. */
return ptr - 2;
- case EOP_TRY_EXCEPT:
+ case EOP_TRY_EXCEPT:
{
- Expr *label_expr;
- Except_Arm *ex;
- Arg_List *a = 0; /* silence warning */
- int count = *ptr++, label;
- unsigned done;
+ Expr *label_expr;
+ Except_Arm *ex;
+ Arg_List *a = 0; /* silence warning */
+ int count = *ptr++, label;
+ unsigned done;
s = HOT_OP(alloc_stmt(STMT_TRY_EXCEPT));
s->s.catch.excepts = 0;
@@ -715,8 +715,8 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
panic("Missing END_EXCEPT in DECOMPILE!");
done = READ_LABEL();
for (ex = s->s.catch.excepts; ex; ex = ex->next) {
- Byte *stop;
- int jump_hot = 0;
+ Byte *stop;
+ int jump_hot = 0;
if (ex->label != ptr - bc.vector)
panic("Not at start of handler in DECOMPILE!");
@@ -747,12 +747,12 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
ADD_STMT(s);
}
break;
- case EOP_END_EXCEPT:
+ case EOP_END_EXCEPT:
/* Early exit; main logic is in TRY_EXCEPT case, above. */
return ptr - 2;
- case EOP_TRY_FINALLY:
+ case EOP_TRY_FINALLY:
{
- int label = READ_LABEL();
+ int label = READ_LABEL();
s = HOT_OP(alloc_stmt(STMT_TRY_FINALLY));
DECOMPILE(bc, ptr, end, &(s->s.finally.body), 0);
@@ -769,16 +769,16 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
ADD_STMT(s);
}
break;
- case EOP_END_FINALLY:
- case EOP_CONTINUE:
+ case EOP_END_FINALLY:
+ case EOP_CONTINUE:
/* Early exit; main logic is in TRY_FINALLY case, above. */
return ptr - 2;
- case EOP_WHILE_ID:
+ case EOP_WHILE_ID:
s = alloc_stmt(STMT_WHILE);
s->s.loop.id = READ_ID();
goto finish_while;
- case EOP_EXIT:
- case EOP_EXIT_ID:
+ case EOP_EXIT:
+ case EOP_EXIT_ID:
s = alloc_stmt(STMT_BREAK);
if (eop == EOP_EXIT_ID)
s->s.exit = READ_ID();
@@ -789,12 +789,12 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
s->kind = STMT_CONTINUE;
ADD_STMT(HOT_OP(s));
break;
- default:
+ default:
panic("Unknown extended opcode in DECOMPILE!");
}
}
break;
- default:
+ default:
panic("Unknown opcode in DECOMPILE!");
}
}
@@ -806,11 +806,11 @@ decompile(Bytecodes bc, Byte *start, Byte *end, Stmt **stmt_sink,
}
static Stmt *
-program_to_tree(Program *prog, int vector, int pc_vector, int pc)
+program_to_tree(Program * prog, int vector, int pc_vector, int pc)
{
- Stmt *result;
- Bytecodes bc;
- int i, sum;
+ Stmt *result;
+ Bytecodes bc;
+ int i, sum;
program = prog;
bc = (pc_vector == MAIN_VECTOR
@@ -847,18 +847,18 @@ program_to_tree(Program *prog, int vector, int pc_vector, int pc)
}
Stmt *
-decompile_program(Program *prog, int vector)
+decompile_program(Program * prog, int vector)
{
return program_to_tree(prog, vector, MAIN_VECTOR, -1);
}
static int
-find_hot_node(Stmt *stmt)
+find_hot_node(Stmt * stmt)
{
/* Invariants: on entry, lineno is number of first line of STMT
- * on exit, if result is true,
- * lineno is line number of hot_node/position
- * else, lineno is number of first line after STMT
+ * on exit, if result is true,
+ * lineno is line number of hot_node/position
+ * else, lineno is number of first line after STMT
*/
for (; stmt; stmt = stmt->next) {
@@ -866,9 +866,9 @@ find_hot_node(Stmt *stmt)
return 1;
switch (stmt->kind) {
- case STMT_COND:
+ case STMT_COND:
{
- Cond_Arm *arm;
+ Cond_Arm *arm;
for (arm = stmt->s.cond.arms; arm; arm = arm->next) {
if (arm == hot_node && hot_position == TOP)
@@ -877,7 +877,7 @@ find_hot_node(Stmt *stmt)
if (find_hot_node(arm->stmt))
return 1;
else if (arm == hot_node && hot_position == BOTTOM) {
- lineno--; /* Blame last line of arm */
+ lineno--; /* Blame last line of arm */
return 1;
}
}
@@ -888,37 +888,37 @@ find_hot_node(Stmt *stmt)
}
}
break;
- case STMT_LIST:
+ case STMT_LIST:
lineno++; /* Skip `for' line */
if (find_hot_node(stmt->s.list.body))
return 1;
break;
- case STMT_RANGE:
+ case STMT_RANGE:
lineno++; /* Skip `for' line */
if (find_hot_node(stmt->s.range.body))
return 1;
break;
- case STMT_WHILE:
+ case STMT_WHILE:
lineno++; /* Skip `while' line */
if (find_hot_node(stmt->s.loop.body))
return 1;
break;
- case STMT_FORK:
+ case STMT_FORK:
lineno++; /* Skip `fork' line */
if (find_hot_node(stmt->s.fork.body))
return 1;
break;
- case STMT_EXPR:
- case STMT_RETURN:
- case STMT_BREAK:
- case STMT_CONTINUE:
+ case STMT_EXPR:
+ case STMT_RETURN:
+ case STMT_BREAK:
+ case STMT_CONTINUE:
/* Nothing more to do */
break;
- case STMT_TRY_EXCEPT:
+ case STMT_TRY_EXCEPT:
{
- Except_Arm *ex;
-
- lineno++; /* Skip `try' line */
+ Except_Arm *ex;
+
+ lineno++; /* Skip `try' line */
if (find_hot_node(stmt->s.catch.body))
return 1;
if (stmt == hot_node && hot_position == ENDBODY) {
@@ -932,13 +932,13 @@ find_hot_node(Stmt *stmt)
if (find_hot_node(ex->stmt))
return 1;
if (ex == hot_node && hot_position == BOTTOM) {
- lineno--; /* blame last line of handler */
+ lineno--; /* blame last line of handler */
return 1;
}
}
}
break;
- case STMT_TRY_FINALLY:
+ case STMT_TRY_FINALLY:
lineno++; /* Skip `try' line */
if (find_hot_node(stmt->s.finally.body)
|| (stmt == hot_node && hot_position == ENDBODY))
@@ -947,7 +947,7 @@ find_hot_node(Stmt *stmt)
if (find_hot_node(stmt->s.finally.handler))
return 1;
break;
- default:
+ default:
panic("Unknown statement kind in FIND_HOT_NODE!");
}
@@ -961,9 +961,9 @@ find_hot_node(Stmt *stmt)
}
int
-find_line_number(Program *prog, int vector, int pc)
+find_line_number(Program * prog, int vector, int pc)
{
- Stmt *tree = program_to_tree(prog, MAIN_VECTOR, vector, pc);
+ Stmt *tree = program_to_tree(prog, MAIN_VECTOR, vector, pc);
lineno = prog->first_lineno;
find_hot_node(tree);
@@ -971,16 +971,19 @@ find_line_number(Program *prog, int vector, int pc)
if (!hot_node && hot_position != DONE)
panic("Can't do job in FIND_LINE_NUMBER!");
-
+
return lineno;
}
char rcsid_decompile[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:32 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.6 1996/03/10 01:17:48 pavel
* Removed a automatic structure initialization. Release 1.8.0.
*
diff --git a/decompile.h b/decompile.h
index 8760802..5278917 100644
--- a/decompile.h
+++ b/decompile.h
@@ -18,13 +18,16 @@
#include "ast.h"
#include "program.h"
-extern Stmt *decompile_program(Program *program, int vector);
-extern int find_line_number(Program *program, int vector, int pc);
+extern Stmt *decompile_program(Program * program, int vector);
+extern int find_line_number(Program * program, int vector, int pc);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:33 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:27:19 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/disassemble.c b/disassemble.c
index d67e9ef..13aefb7 100644
--- a/disassemble.c
+++ b/disassemble.c
@@ -30,85 +30,87 @@
#include "utils.h"
#include "verbs.h"
-const char *mnemonics[256], *ext_mnemonics[256];
+const char *mnemonics[256], *ext_mnemonics[256];
struct mapping {
- unsigned value;
+ unsigned value;
const char *name;
};
-struct mapping mappings[] = {
- {OP_IF, "IF"},
- {OP_WHILE, "WHILE"},
- {OP_EIF, "ELSEIF"},
- {OP_FORK, "FORK"},
- {OP_FORK_WITH_ID, "FORK_NAMED"},
- {OP_FOR_LIST, "FOR_LIST"},
- {OP_FOR_RANGE, "FOR_RANGE"},
- {OP_INDEXSET, "INDEXSET"},
- {OP_PUSH_GET_PROP, "PUSH_GET_PROP"},
- {OP_GET_PROP, "GET_PROP"},
- {OP_CALL_VERB, "CALL_VERB"},
- {OP_PUT_PROP, "PUT_PROP"},
- {OP_BI_FUNC_CALL, "CALL_FUNC"},
- {OP_IF_QUES, "IF_EXPR"},
- {OP_REF, "INDEX"},
- {OP_RANGE_REF, "RANGE"},
- {OP_MAKE_SINGLETON_LIST, "MAKE_SINGLETON_LIST"},
- {OP_CHECK_LIST_FOR_SPLICE, "CHECK_LIST_FOR_SPLICE"},
- {OP_MULT, "MULTIPLY"},
- {OP_DIV, "DIVIDE"},
- {OP_MOD, "MOD"},
- {OP_ADD, "ADD"},
- {OP_MINUS, "SUBTRACT"},
- {OP_EQ, "EQ"},
- {OP_NE, "NE"},
- {OP_LT, "LT"},
- {OP_LE, "LE"},
- {OP_GT, "GT"},
- {OP_GE, "GE"},
- {OP_IN, "IN"},
- {OP_AND, "AND"},
- {OP_OR, "OR"},
- {OP_UNARY_MINUS, "NEGATE"},
- {OP_NOT, "NOT"},
- {OP_G_PUT, "PUT"},
- {OP_G_PUSH, "PUSH"},
- {OP_IMM, "PUSH_LITERAL"},
- {OP_MAKE_EMPTY_LIST, "MAKE_EMPTY_LIST"},
- {OP_LIST_ADD_TAIL, "LIST_ADD_TAIL"},
- {OP_LIST_APPEND, "LIST_APPEND"},
- {OP_PUSH_REF, "PUSH_INDEX"},
- {OP_PUT_TEMP, "PUT_TEMP"},
- {OP_PUSH_TEMP, "PUSH_TEMP"},
- {OP_JUMP, "JUMP"},
- {OP_RETURN, "RETURN"},
- {OP_RETURN0, "RETURN 0"},
- {OP_DONE, "DONE"},
- {OP_POP, "POP"}};
-
-struct mapping ext_mappings[] = {
- {EOP_RANGESET, "RANGESET"},
- {EOP_LENGTH, "LENGTH"},
- {EOP_PUSH_LABEL, "PUSH_LABEL"},
- {EOP_SCATTER, "SCATTER"},
- {EOP_EXP, "EXPONENT"},
- {EOP_CATCH, "CATCH"},
- {EOP_END_CATCH, "END_CATCH"},
- {EOP_TRY_EXCEPT, "TRY_EXCEPT"},
- {EOP_END_EXCEPT, "END_EXCEPT"},
- {EOP_TRY_FINALLY, "TRY_FINALLY"},
- {EOP_END_FINALLY, "END_FINALLY"},
- {EOP_CONTINUE, "CONTINUE"},
- {EOP_WHILE_ID, "WHILE_ID"},
- {EOP_EXIT, "EXIT"},
- {EOP_EXIT_ID, "EXIT_ID"}};
+struct mapping mappings[] =
+{
+ {OP_IF, "IF"},
+ {OP_WHILE, "WHILE"},
+ {OP_EIF, "ELSEIF"},
+ {OP_FORK, "FORK"},
+ {OP_FORK_WITH_ID, "FORK_NAMED"},
+ {OP_FOR_LIST, "FOR_LIST"},
+ {OP_FOR_RANGE, "FOR_RANGE"},
+ {OP_INDEXSET, "INDEXSET"},
+ {OP_PUSH_GET_PROP, "PUSH_GET_PROP"},
+ {OP_GET_PROP, "GET_PROP"},
+ {OP_CALL_VERB, "CALL_VERB"},
+ {OP_PUT_PROP, "PUT_PROP"},
+ {OP_BI_FUNC_CALL, "CALL_FUNC"},
+ {OP_IF_QUES, "IF_EXPR"},
+ {OP_REF, "INDEX"},
+ {OP_RANGE_REF, "RANGE"},
+ {OP_MAKE_SINGLETON_LIST, "MAKE_SINGLETON_LIST"},
+ {OP_CHECK_LIST_FOR_SPLICE, "CHECK_LIST_FOR_SPLICE"},
+ {OP_MULT, "MULTIPLY"},
+ {OP_DIV, "DIVIDE"},
+ {OP_MOD, "MOD"},
+ {OP_ADD, "ADD"},
+ {OP_MINUS, "SUBTRACT"},
+ {OP_EQ, "EQ"},
+ {OP_NE, "NE"},
+ {OP_LT, "LT"},
+ {OP_LE, "LE"},
+ {OP_GT, "GT"},
+ {OP_GE, "GE"},
+ {OP_IN, "IN"},
+ {OP_AND, "AND"},
+ {OP_OR, "OR"},
+ {OP_UNARY_MINUS, "NEGATE"},
+ {OP_NOT, "NOT"},
+ {OP_G_PUT, "PUT"},
+ {OP_G_PUSH, "PUSH"},
+ {OP_IMM, "PUSH_LITERAL"},
+ {OP_MAKE_EMPTY_LIST, "MAKE_EMPTY_LIST"},
+ {OP_LIST_ADD_TAIL, "LIST_ADD_TAIL"},
+ {OP_LIST_APPEND, "LIST_APPEND"},
+ {OP_PUSH_REF, "PUSH_INDEX"},
+ {OP_PUT_TEMP, "PUT_TEMP"},
+ {OP_PUSH_TEMP, "PUSH_TEMP"},
+ {OP_JUMP, "JUMP"},
+ {OP_RETURN, "RETURN"},
+ {OP_RETURN0, "RETURN 0"},
+ {OP_DONE, "DONE"},
+ {OP_POP, "POP"}};
+
+struct mapping ext_mappings[] =
+{
+ {EOP_RANGESET, "RANGESET"},
+ {EOP_LENGTH, "LENGTH"},
+ {EOP_PUSH_LABEL, "PUSH_LABEL"},
+ {EOP_SCATTER, "SCATTER"},
+ {EOP_EXP, "EXPONENT"},
+ {EOP_CATCH, "CATCH"},
+ {EOP_END_CATCH, "END_CATCH"},
+ {EOP_TRY_EXCEPT, "TRY_EXCEPT"},
+ {EOP_END_EXCEPT, "END_EXCEPT"},
+ {EOP_TRY_FINALLY, "TRY_FINALLY"},
+ {EOP_END_FINALLY, "END_FINALLY"},
+ {EOP_CONTINUE, "CONTINUE"},
+ {EOP_WHILE_ID, "WHILE_ID"},
+ {EOP_EXIT, "EXIT"},
+ {EOP_EXIT_ID, "EXIT_ID"}};
static void
initialize_tables(void)
{
- static int tables_initialized = 0;
- unsigned i;
+ static int tables_initialized = 0;
+ unsigned i;
if (tables_initialized)
return;
@@ -127,28 +129,28 @@ initialize_tables(void)
tables_initialized = 1;
}
-typedef void (*Printer)(const char *, void *);
-static Printer print;
-static void *print_data;
-static int bytes_width, max_bytes_width;
+typedef void (*Printer) (const char *, void *);
+static Printer print;
+static void *print_data;
+static int bytes_width, max_bytes_width;
static void
-output(Stream *s)
+output(Stream * s)
{
- (*print)(reset_stream(s), print_data);
+ (*print) (reset_stream(s), print_data);
}
static void
-new_insn(Stream *s, unsigned pc)
+new_insn(Stream * s, unsigned pc)
{
stream_printf(s, "%3d:", pc);
bytes_width = max_bytes_width;
}
static unsigned
-add_bytes(Stream *s, Byte *vector, unsigned pc, unsigned length)
+add_bytes(Stream * s, Byte * vector, unsigned pc, unsigned length)
{
- unsigned arg = 0, b;
+ unsigned arg = 0, b;
while (length--) {
if (bytes_width == 0) {
@@ -166,7 +168,7 @@ add_bytes(Stream *s, Byte *vector, unsigned pc, unsigned length)
}
static void
-finish_insn(Stream *s, Stream *insn)
+finish_insn(Stream * s, Stream * insn)
{
while (bytes_width--)
stream_add_string(s, " ");
@@ -175,20 +177,20 @@ finish_insn(Stream *s, Stream *insn)
}
static void
-disassemble(Program *prog, Printer p, void *data)
+disassemble(Program * prog, Printer p, void *data)
{
- Stream *s = new_stream(100);
- Stream *insn = new_stream(50);
- int i, l;
- unsigned pc;
- Bytecodes bc;
- const char *ptr;
- const char **names = prog->var_names;
- unsigned tmp, num_names = prog->num_var_names;
+ Stream *s = new_stream(100);
+ Stream *insn = new_stream(50);
+ int i, l;
+ unsigned pc;
+ Bytecodes bc;
+ const char *ptr;
+ const char **names = prog->var_names;
+ unsigned tmp, num_names = prog->num_var_names;
# define NAMES(i) (tmp = i, \
tmp < num_names ? names[tmp] \
: "*** Unknown variable ***")
- Var *literals = prog->literals;
+ Var *literals = prog->literals;
initialize_tables();
print = p;
@@ -228,12 +230,12 @@ disassemble(Program *prog, Printer p, void *data)
max_bytes_width = 5;
for (pc = 0; pc < bc.size;) {
- Byte b;
- unsigned arg;
+ Byte b;
+ unsigned arg;
# define ADD_BYTES(n) (arg = add_bytes(s, bc.vector, pc, n), \
pc += n, \
arg)
- unsigned a1, a2;
+ unsigned a1, a2;
new_insn(s, pc);
b = add_bytes(s, bc.vector, pc++, 1);
@@ -250,33 +252,35 @@ disassemble(Program *prog, Printer p, void *data)
stream_add_string(insn, COUNT_EOP_TICK(b) ? " * " : " ");
stream_add_string(insn, ext_mnemonics[b]);
switch ((Extended_Opcode) b) {
- case EOP_WHILE_ID:
+ case EOP_WHILE_ID:
a1 = ADD_BYTES(bc.numbytes_var_name);
a2 = ADD_BYTES(bc.numbytes_label);
stream_printf(insn, " %s %d", NAMES(a1), a2);
break;
- case EOP_EXIT_ID:
+ case EOP_EXIT_ID:
stream_printf(insn, " %s",
NAMES(ADD_BYTES(bc.numbytes_var_name)));
/* fall thru */
- case EOP_EXIT:
+ case EOP_EXIT:
a1 = ADD_BYTES(bc.numbytes_stack);
a2 = ADD_BYTES(bc.numbytes_label);
stream_printf(insn, " %d %d", a1, a2);
break;
- case EOP_PUSH_LABEL: case EOP_END_CATCH:
- case EOP_END_EXCEPT: case EOP_TRY_FINALLY:
+ case EOP_PUSH_LABEL:
+ case EOP_END_CATCH:
+ case EOP_END_EXCEPT:
+ case EOP_TRY_FINALLY:
stream_printf(insn, " %d", ADD_BYTES(bc.numbytes_label));
break;
- case EOP_TRY_EXCEPT:
+ case EOP_TRY_EXCEPT:
stream_printf(insn, " %d", ADD_BYTES(1));
break;
- case EOP_LENGTH:
+ case EOP_LENGTH:
stream_printf(insn, " %d", ADD_BYTES(bc.numbytes_stack));
break;
- case EOP_SCATTER:
+ case EOP_SCATTER:
{
- int i, nargs = ADD_BYTES(1);
+ int i, nargs = ADD_BYTES(1);
a1 = ADD_BYTES(1);
a2 = ADD_BYTES(1);
@@ -290,49 +294,53 @@ disassemble(Program *prog, Printer p, void *data)
ADD_BYTES(bc.numbytes_label));
}
break;
- default:
+ default:
break;
}
} else {
stream_add_string(insn, mnemonics[b]);
switch ((Opcode) b) {
- case OP_IF: case OP_IF_QUES: case OP_EIF:
- case OP_AND: case OP_OR: case OP_JUMP:
- case OP_WHILE:
+ case OP_IF:
+ case OP_IF_QUES:
+ case OP_EIF:
+ case OP_AND:
+ case OP_OR:
+ case OP_JUMP:
+ case OP_WHILE:
stream_printf(insn, " %d", ADD_BYTES(bc.numbytes_label));
break;
- case OP_FORK:
+ case OP_FORK:
stream_printf(insn, " %d", ADD_BYTES(bc.numbytes_fork));
break;
- case OP_FORK_WITH_ID:
+ case OP_FORK_WITH_ID:
a1 = ADD_BYTES(bc.numbytes_fork);
a2 = ADD_BYTES(bc.numbytes_var_name);
stream_printf(insn, " %d %s", a1, NAMES(a2));
break;
- case OP_FOR_LIST:
- case OP_FOR_RANGE:
+ case OP_FOR_LIST:
+ case OP_FOR_RANGE:
a1 = ADD_BYTES(bc.numbytes_var_name);
a2 = ADD_BYTES(bc.numbytes_label);
stream_printf(insn, " %s %d", NAMES(a1), a2);
break;
- case OP_G_PUSH:
- case OP_G_PUT:
+ case OP_G_PUSH:
+ case OP_G_PUT:
stream_printf(insn, " %s",
NAMES(ADD_BYTES(bc.numbytes_var_name)));
break;
- case OP_IMM:
+ case OP_IMM:
{
Var v;
v = literals[ADD_BYTES(bc.numbytes_literal)];
switch (v.type) {
- case TYPE_OBJ:
+ case TYPE_OBJ:
stream_printf(insn, " #%d", v.v.obj);
break;
- case TYPE_INT:
+ case TYPE_INT:
stream_printf(insn, " %d", v.v.num);
break;
- case TYPE_STR:
+ case TYPE_STR:
stream_add_string(insn, " \"");
for (ptr = v.v.str; *ptr; ptr++) {
if (*ptr == '"' || *ptr == '\\')
@@ -341,19 +349,19 @@ disassemble(Program *prog, Printer p, void *data)
}
stream_add_char(insn, '"');
break;
- case TYPE_ERR:
+ case TYPE_ERR:
stream_printf(insn, " %s", error_name(v.v.err));
break;
- default:
+ default:
stream_printf(insn, " <literal type = %d>",
v.type);
break;
}
}
break;
- case OP_BI_FUNC_CALL:
+ case OP_BI_FUNC_CALL:
stream_printf(insn, " %s", name_func_by_num(ADD_BYTES(1)));
- default:
+ default:
break;
}
}
@@ -369,37 +377,37 @@ disassemble(Program *prog, Printer p, void *data)
static void
print_line(const char *line, void *data)
{
- FILE *f = data;
+ FILE *f = data;
fprintf(f, "%s\n", line);
}
void
-disassemble_to_file(FILE *fp, Program *prog)
+disassemble_to_file(FILE * fp, Program * prog)
{
disassemble(prog, print_line, fp);
}
void
-disassemble_to_stderr(Program *prog)
+disassemble_to_stderr(Program * prog)
{
disassemble_to_file(stderr, prog);
}
struct data {
- char **lines;
- int used, max;
+ char **lines;
+ int used, max;
};
static void
add_line(const char *line, void *data)
{
- struct data *d = data;
+ struct data *d = data;
if (d->used >= d->max) {
- int new_max = (d->max == 0 ? 20 : d->max * 2);
- char **new = mymalloc(sizeof(char **) * new_max, M_DISASSEMBLE);
- int i;
+ int new_max = (d->max == 0 ? 20 : d->max * 2);
+ char **new = mymalloc(sizeof(char **) * new_max, M_DISASSEMBLE);
+ int i;
for (i = 0; i < d->used; i++)
new[i] = d->lines[i];
@@ -408,27 +416,25 @@ add_line(const char *line, void *data)
d->lines = new;
d->max = new_max;
}
-
d->lines[d->used++] = str_dup(line);
}
static package
bf_disassemble(Var arglist, Byte next, void *vdata, Objid progr)
{
- Objid oid = arglist.v.list[1].v.obj;
- Var desc = arglist.v.list[2];
- db_verb_handle h;
- struct data data;
- Var r;
- int i;
- enum error e;
+ Objid oid = arglist.v.list[1].v.obj;
+ Var desc = arglist.v.list[2];
+ db_verb_handle h;
+ struct data data;
+ Var r;
+ int i;
+ enum error e;
if ((e = validate_verb_descriptor(desc)) != E_NONE
|| (e = E_INVARG, !valid(oid))) {
free_var(arglist);
return make_error_pack(e);
}
-
h = find_described_verb(oid, desc);
free_var(arglist);
@@ -459,9 +465,12 @@ register_disassemble(void)
char rcsid_disassemble[] = "$Id";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:34 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.6 1996/04/08 01:09:40 pavel
* Added missing mnemonic-table entry for EOP_PUSH_LABEL. Release 1.8.0p3.
*
diff --git a/disassemble.h b/disassemble.h
index add3e0b..bbb2adc 100644
--- a/disassemble.h
+++ b/disassemble.h
@@ -19,13 +19,16 @@
#include "program.h"
-extern void disassemble_to_file(FILE *fp, Program *program);
-extern void disassemble_to_stderr(Program *program);
+extern void disassemble_to_file(FILE * fp, Program * program);
+extern void disassemble_to_stderr(Program * program);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:35 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:27:06 pavel
* Added disassemble_to_file(). Updated copyright notice for 1996.
* Release 1.8.0beta1.
diff --git a/eval_env.c b/eval_env.c
index 582fd7b..a74e688 100644
--- a/eval_env.c
+++ b/eval_env.c
@@ -27,15 +27,15 @@ new_rt_env(unsigned size)
{
Var *ret = mymalloc(size * sizeof(Var), M_RT_ENV);
unsigned i;
-
+
for (i = 0; i < size; i++)
ret[i].type = TYPE_NONE;
return ret;
-}
+}
-void
-free_rt_env(Var *rt_env, unsigned size)
+void
+free_rt_env(Var * rt_env, unsigned size)
{
register unsigned i;
@@ -45,36 +45,43 @@ free_rt_env(Var *rt_env, unsigned size)
}
Var *
-copy_rt_env(Var *from, unsigned size)
+copy_rt_env(Var * from, unsigned size)
{
unsigned i;
Var *ret = new_rt_env(size);
- for (i = 0; i < size; i++)
+ for (i = 0; i < size; i++)
ret[i] = var_ref(from[i]);
return ret;
}
void
-fill_in_rt_consts(Var *env, DB_Version version)
+fill_in_rt_consts(Var * env, DB_Version version)
{
Var v;
v.type = TYPE_INT;
- v.v.num = (int) TYPE_ERR; env[SLOT_ERR] = var_ref(v);
- v.v.num = (int) TYPE_INT; env[SLOT_NUM] = var_ref(v);
- v.v.num = (int) TYPE_STR; env[SLOT_STR] = var_ref(v);
- v.v.num = (int) TYPE_OBJ; env[SLOT_OBJ] = var_ref(v);
- v.v.num = (int) TYPE_LIST; env[SLOT_LIST] = var_ref(v);
+ v.v.num = (int) TYPE_ERR;
+ env[SLOT_ERR] = var_ref(v);
+ v.v.num = (int) TYPE_INT;
+ env[SLOT_NUM] = var_ref(v);
+ v.v.num = (int) TYPE_STR;
+ env[SLOT_STR] = var_ref(v);
+ v.v.num = (int) TYPE_OBJ;
+ env[SLOT_OBJ] = var_ref(v);
+ v.v.num = (int) TYPE_LIST;
+ env[SLOT_LIST] = var_ref(v);
if (version >= DBV_Float) {
- v.v.num = (int) TYPE_INT; env[SLOT_INT] = var_ref(v);
- v.v.num = (int) TYPE_FLOAT; env[SLOT_FLOAT] = var_ref(v);
+ v.v.num = (int) TYPE_INT;
+ env[SLOT_INT] = var_ref(v);
+ v.v.num = (int) TYPE_FLOAT;
+ env[SLOT_FLOAT] = var_ref(v);
}
}
void
-set_rt_env_obj(Var *env, int slot, Objid o)
+set_rt_env_obj(Var * env, int slot, Objid o)
{
Var v;
v.type = TYPE_OBJ;
@@ -83,7 +90,7 @@ set_rt_env_obj(Var *env, int slot, Objid o)
}
void
-set_rt_env_str(Var *env, int slot, const char *s)
+set_rt_env_str(Var * env, int slot, const char *s)
{
Var v;
v.type = TYPE_STR;
@@ -92,7 +99,7 @@ set_rt_env_str(Var *env, int slot, const char *s)
}
void
-set_rt_env_var(Var *env, int slot, Var v)
+set_rt_env_var(Var * env, int slot, Var v)
{
env[slot] = v;
}
@@ -100,9 +107,12 @@ set_rt_env_var(Var *env, int slot, Var v)
char rcsid_rt_env[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:35 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 07:13:03 pavel
* Renamed TYPE_NUM to TYPE_INT. Made fill_in_rt_consts() version-dependent.
* Updated copyright notice for 1996. Release 1.8.0beta1.
diff --git a/eval_env.h b/eval_env.h
index 25b2a26..a0d95e2 100644
--- a/eval_env.h
+++ b/eval_env.h
@@ -22,22 +22,25 @@
#include "structures.h"
#include "version.h"
-extern Var *new_rt_env(unsigned size);
-extern void free_rt_env(Var *rt_env, unsigned size);
-extern Var *copy_rt_env(Var *from, unsigned size);
+extern Var *new_rt_env(unsigned size);
+extern void free_rt_env(Var * rt_env, unsigned size);
+extern Var *copy_rt_env(Var * from, unsigned size);
-void set_rt_env_obj(Var *env, int slot, Objid o);
-void set_rt_env_str(Var *env, int slot, const char *s);
-void set_rt_env_var(Var *env, int slot, Var v);
+void set_rt_env_obj(Var * env, int slot, Objid o);
+void set_rt_env_str(Var * env, int slot, const char *s);
+void set_rt_env_var(Var * env, int slot, Var v);
-void fill_in_rt_consts(Var *env, DB_Version);
+void fill_in_rt_consts(Var * env, DB_Version);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:36 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:26:34 pavel
* Made fill_in_rt_consts() version-dependent. Updated copyright notice for
* 1996. Release 1.8.0beta1.
diff --git a/eval_vm.c b/eval_vm.c
index 8b7f26f..5e49658 100644
--- a/eval_vm.c
+++ b/eval_vm.c
@@ -31,7 +31,7 @@
vm
new_vm(int task_id, int stack_size)
{
- vm the_vm = mymalloc(sizeof(vmstruct), M_VM);
+ vm the_vm = mymalloc(sizeof(vmstruct), M_VM);
the_vm->task_id = task_id;
the_vm->activ_stack = mymalloc(sizeof(activation) * stack_size, M_VM);
@@ -44,7 +44,7 @@ free_vm(vm the_vm, int stack_too)
{
int i;
- if (stack_too)
+ if (stack_too)
for (i = the_vm->top_activ_stack; i >= 0; i--)
free_activation(the_vm->activ_stack[i], 1);
myfree(the_vm->activ_stack, M_VM);
@@ -58,7 +58,7 @@ top_activ(vm the_vm)
}
Objid
-progr_of_cur_verb(vm the_vm)
+progr_of_cur_verb(vm the_vm)
{
return top_activ(the_vm).progr;
}
@@ -69,15 +69,15 @@ suspended_lineno_of_vm(vm the_vm)
activation top;
top = top_activ(the_vm);
- return find_line_number(top.prog, (the_vm->top_activ_stack == 0
- ? the_vm->root_activ_vector
+ return find_line_number(top.prog, (the_vm->top_activ_stack == 0
+ ? the_vm->root_activ_vector
: MAIN_VECTOR),
top.error_pc);
}
/**** read/write data base ****/
-void
+void
write_vm(vm the_vm)
{
unsigned i;
@@ -85,7 +85,7 @@ write_vm(vm the_vm)
dbio_printf("%u %d %u %u\n",
the_vm->top_activ_stack, the_vm->root_activ_vector,
the_vm->func_id, the_vm->max_stack_size);
-
+
for (i = 0; i <= the_vm->top_activ_stack; i++)
write_activ(the_vm->activ_stack[i]);
}
@@ -93,10 +93,10 @@ write_vm(vm the_vm)
vm
read_vm(int task_id)
{
- unsigned i, top, func_id, max;
- int vector;
- char c;
- vm the_vm;
+ unsigned i, top, func_id, max;
+ int vector;
+ char c;
+ vm the_vm;
if (dbio_scanf("%u %d %u%c", &top, &vector, &func_id, &c) != 4
|| (c == ' '
@@ -105,7 +105,6 @@ read_vm(int task_id)
errlog("READ_VM: Bad vm header\n");
return 0;
}
-
the_vm = new_vm(task_id, top + 1);
the_vm->max_stack_size = max;
the_vm->top_activ_stack = top;
@@ -118,16 +117,18 @@ read_vm(int task_id)
errlog("READ_VM: Bad activ number %d\n", i);
return 0;
}
-
return the_vm;
}
char rcsid_eval_vm[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:36 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/02/08 07:12:16 pavel
* Renamed err/logf() to errlog/oklog(). Updated copyright notice for 1996.
* Release 1.8.0beta1.
diff --git a/eval_vm.h b/eval_vm.h
index 910360c..215aed3 100644
--- a/eval_vm.h
+++ b/eval_vm.h
@@ -19,20 +19,23 @@
#include "execute.h"
#include "structures.h"
-extern vm read_vm(int task_id);
-extern void write_vm(vm);
+extern vm read_vm(int task_id);
+extern void write_vm(vm);
-extern vm new_vm(int task_id, int stack_size);
-extern void free_vm(vm the_vm, int stack_too);
+extern vm new_vm(int task_id, int stack_size);
+extern void free_vm(vm the_vm, int stack_too);
-extern activation top_activ(vm);
-extern Objid progr_of_cur_verb(vm);
-extern unsigned suspended_lineno_of_vm(vm);
+extern activation top_activ(vm);
+extern Objid progr_of_cur_verb(vm);
+extern unsigned suspended_lineno_of_vm(vm);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:36 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:26:06 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/exceptions.c b/exceptions.c
index c799609..1f4ad38 100644
--- a/exceptions.c
+++ b/exceptions.c
@@ -19,35 +19,35 @@
/* Distributed only by permission. */
/*****************************************************************************/
/* File: exceptions.c */
-/* Taken originally from: */
-/* Implementing Exceptions in C */
-/* Eric S. Roberts */
-/* Research Report #40 */
-/* DEC Systems Research Center */
-/* March 21, 1989 */
+/* Taken originally from: */
+/* Implementing Exceptions in C */
+/* Eric S. Roberts */
+/* Research Report #40 */
+/* DEC Systems Research Center */
+/* March 21, 1989 */
/* Modified slightly by Pavel Curtis for use in the LambdaMOO server code. */
/* ------------------------------------------------------------------------- */
-/* Implementation of the C exception handler. Most of the real work is */
-/* done in the macros defined in the exceptions.h header file. */
+/* Implementation of the C exception handler. Most of the real work is */
+/* done in the macros defined in the exceptions.h header file. */
/*****************************************************************************/
#include <setjmp.h>
#include "exceptions.h"
-ES_CtxBlock *ES_exceptionStack = 0;
+ES_CtxBlock *ES_exceptionStack = 0;
-Exception ANY;
+Exception ANY;
void
-ES_RaiseException(Exception *exception, int value)
+ES_RaiseException(Exception * exception, int value)
{
- ES_CtxBlock *cb, *xb;
- int i;
+ ES_CtxBlock *cb, *xb;
+ int i;
for (xb = ES_exceptionStack; xb; xb = xb->link) {
for (i = 0; i < xb->nx; i++) {
- if (xb->array[i] == exception || xb->array[i] == &ANY)
+ if (xb->array[i] == exception || xb->array[i] == &ANY)
goto doneSearching;
}
}
@@ -56,8 +56,7 @@ ES_RaiseException(Exception *exception, int value)
if (!xb)
panic("Unhandled exception!");
- for (cb = ES_exceptionStack; cb != xb && !cb->finally; cb = cb->link)
- ;
+ for (cb = ES_exceptionStack; cb != xb && !cb->finally; cb = cb->link);
ES_exceptionStack = cb;
cb->id = exception;
cb->value = value;
@@ -67,9 +66,12 @@ ES_RaiseException(Exception *exception, int value)
char rcsid_exceptions[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:37 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 07:11:32 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/exceptions.h b/exceptions.h
index 81d238a..21a7076 100644
--- a/exceptions.h
+++ b/exceptions.h
@@ -19,40 +19,40 @@
/* Distributed only by permission. */
/*****************************************************************************/
/* File: exceptions.h */
-/* Taken originally from: */
-/* Implementing Exceptions in C */
-/* Eric S. Roberts */
-/* Research Report #40 */
-/* DEC Systems Research Center */
-/* March 21, 1989 */
+/* Taken originally from: */
+/* Implementing Exceptions in C */
+/* Eric S. Roberts */
+/* Research Report #40 */
+/* DEC Systems Research Center */
+/* March 21, 1989 */
/* Modified slightly by Pavel Curtis for use in the LambdaMOO server code. */
/* ------------------------------------------------------------------------- */
/* The exceptions package provides a general exception handling mechanism */
-/* for use with C that is portable across a variety of compilers and */
-/* operating systems. The design of this facility is based on the */
+/* for use with C that is portable across a variety of compilers and */
+/* operating systems. The design of this facility is based on the */
/* exception handling mechanism used in the Modula-2+ language at DEC/SRC */
-/* and is described in detail in the paper cited above. */
+/* and is described in detail in the paper cited above. */
/* For more background on the underlying motivation for this design, see */
-/* SRC Research Report #3. */
+/* SRC Research Report #3. */
/*****************************************************************************/
/*
- * Syntax: Exception my_exception;
+ * Syntax: Exception my_exception;
*
- * TRY
- * stmts;
- * EXCEPT (my_exception) [ANY matches all exceptions]
- * stmts; [int exception_value available here]
- * ...
- * ENDTRY
+ * TRY
+ * stmts;
+ * EXCEPT (my_exception) [ANY matches all exceptions]
+ * stmts; [int exception_value available here]
+ * ...
+ * ENDTRY
*
- * RAISE(my_exception, value);
+ * RAISE(my_exception, value);
*
- * TRY
- * stmts;
- * FINALLY
- * stmts;
- * ENDTRY
+ * TRY
+ * stmts;
+ * FINALLY
+ * stmts;
+ * ENDTRY
*/
#ifndef Exceptions_H
@@ -64,24 +64,28 @@
#define ES_MaxExceptionsPerScope 10
-typedef enum ES_Value { ES_Initialize, ES_EvalBody, ES_Exception } ES_Value;
+typedef enum ES_Value {
+ ES_Initialize, ES_EvalBody, ES_Exception
+} ES_Value;
-typedef struct { int junk; } Exception; /* Only addr. of exception is used. */
+typedef struct {
+ int junk;
+} Exception; /* Only addr. of exception is used. */
typedef volatile struct ES_CtxBlock ES_CtxBlock;
struct ES_CtxBlock {
- jmp_buf jmp;
- int nx;
- Exception *array[ES_MaxExceptionsPerScope];
- Exception *id;
- int value;
- int finally;
- ES_CtxBlock *link;
+ jmp_buf jmp;
+ int nx;
+ Exception *array[ES_MaxExceptionsPerScope];
+ Exception *id;
+ int value;
+ int finally;
+ ES_CtxBlock *link;
};
-extern Exception ANY;
-extern ES_CtxBlock *ES_exceptionStack;
-extern void ES_RaiseException(Exception *exception, int value);
+extern Exception ANY;
+extern ES_CtxBlock *ES_exceptionStack;
+extern void ES_RaiseException(Exception * exception, int value);
#define RAISE(e, v) ES_RaiseException(&e, v)
@@ -101,7 +105,7 @@ extern void ES_RaiseException(Exception *exception, int value);
\
while (1) { \
if (ES_es == ES_EvalBody) { \
- /* TRY body goes here */
+ /* TRY body goes here */
#define EXCEPT(e) \
@@ -120,7 +124,7 @@ extern void ES_RaiseException(Exception *exception, int value);
ES_exceptionStack = ES_ctx.link; \
exception_value = exception_value; \
/* avoid warnings */ \
- /* handler goes here */
+ /* handler goes here */
#define FINALLY \
@@ -146,18 +150,21 @@ extern void ES_RaiseException(Exception *exception, int value);
/* The exceptions package doesn't provide this function, but it calls it */
-/* whenever a fatal error occurs: */
-/* 1) Too many EXCEPT clauses in a single TRY construct. */
-/* 2) An unhandled exception is RAISEd. */
+/* whenever a fatal error occurs: */
+/* 1) Too many EXCEPT clauses in a single TRY construct. */
+/* 2) An unhandled exception is RAISEd. */
-extern void panic(const char *message);
+extern void panic(const char *message);
-#endif /* !Exceptions_H */
+#endif /* !Exceptions_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:37 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:25:56 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/execute.c b/execute.c
index 7abbae5..cee32b8 100644
--- a/execute.c
+++ b/execute.c
@@ -43,26 +43,26 @@
#include "version.h"
/* the following globals are the guts of the virtual machine: */
-static activation *activ_stack = 0;
-static int max_stack_size = 0;
-static unsigned top_activ_stack; /* points to top-of-stack
- (last-occupied-slot),
- not next-empty-slot */
-static int root_activ_vector; /* root_activ_vector == MAIN_VECTOR
- iff root activation is main
- vector */
+static activation *activ_stack = 0;
+static int max_stack_size = 0;
+static unsigned top_activ_stack; /* points to top-of-stack
+ (last-occupied-slot),
+ not next-empty-slot */
+static int root_activ_vector; /* root_activ_vector == MAIN_VECTOR
+ iff root activation is main
+ vector */
/* these globals are not part of the vm because they get re-initialized
after a suspend */
-static int ticks_remaining;
-int task_timed_out;
-static int interpreter_is_running = 0;
-static int task_killed;
-static Timer_ID task_alarm_id;
-static task_kind current_task_kind;
+static int ticks_remaining;
+int task_timed_out;
+static int interpreter_is_running = 0;
+static int task_killed;
+static Timer_ID task_alarm_id;
+static task_kind current_task_kind;
-static const char *handler_verb_name; /* For in-DB traceback handling */
-static Var handler_verb_args;
+static const char *handler_verb_name; /* For in-DB traceback handling */
+static Var handler_verb_args;
/* macros to ease indexing into activation stack */
#define RUN_ACTIV activ_stack[top_activ_stack]
@@ -73,15 +73,15 @@ static Var handler_verb_args;
typedef enum { /* Reasons for executing a FINALLY handler */
/* These constants are stored in the DB, so don't change the order... */
FIN_FALL_THRU, FIN_RAISE, FIN_UNCAUGHT, FIN_RETURN,
- FIN_ABORT, /* This doesn't actually get you into a FINALLY... */
+ FIN_ABORT, /* This doesn't actually get you into a FINALLY... */
FIN_EXIT
} Finally_Reason;
void
-print_error_backtrace(const char *msg, void (*output)(const char *))
+print_error_backtrace(const char *msg, void (*output) (const char *))
{
- int t;
- Stream *str;
+ int t;
+ Stream *str;
if (!interpreter_is_running)
return;
@@ -90,14 +90,14 @@ print_error_backtrace(const char *msg, void (*output)(const char *))
if (t != top_activ_stack)
stream_printf(str, "... called from ");
stream_printf(str, "#%d:%s", activ_stack[t].vloc,
- activ_stack[t].verbname);
+ activ_stack[t].verbname);
if (activ_stack[t].vloc != activ_stack[t].this)
stream_printf(str, " (this == #%d)", activ_stack[t].this);
stream_printf(str, ", line %d",
find_line_number(activ_stack[t].prog,
(t == 0 ? root_activ_vector
- : MAIN_VECTOR),
+ : MAIN_VECTOR),
activ_stack[t].error_pc));
if (t == top_activ_stack)
stream_printf(str, ": %s", msg);
@@ -118,12 +118,12 @@ output_to_log(const char *line)
oklog("%s\n", line);
}
-static Var backtrace_list;
+static Var backtrace_list;
static void
output_to_list(const char *line)
{
- Var str;
+ Var str;
str.type = TYPE_STR;
str.v.str = str_dup(line);
@@ -141,18 +141,18 @@ error_backtrace_list(const char *msg)
static enum error
suspend_task(package p)
{
- vm the_vm = new_vm(current_task_id, top_activ_stack + 1);
- int i;
- enum error e;
-
+ vm the_vm = new_vm(current_task_id, top_activ_stack + 1);
+ int i;
+ enum error e;
+
the_vm->max_stack_size = max_stack_size;
the_vm->top_activ_stack = top_activ_stack;
the_vm->root_activ_vector = root_activ_vector;
- the_vm->func_id = 0; /* shouldn't need func_id; */
+ the_vm->func_id = 0; /* shouldn't need func_id; */
for (i = 0; i <= top_activ_stack; i++)
the_vm->activ_stack[i] = activ_stack[i];
-
- e = (*p.u.susp.proc)(the_vm, p.u.susp.data);
+
+ e = (*p.u.susp.proc) (the_vm, p.u.susp.data);
if (e != E_NONE)
free_vm(the_vm, 0);
return e;
@@ -165,22 +165,22 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome)
{
/* Returns true iff the entire stack was unwound and the interpreter
* should stop, in which case *outcome is the correct outcome to return. */
- Var code = (why == FIN_RAISE ? value.v.list[1] : zero);
+ Var code = (why == FIN_RAISE ? value.v.list[1] : zero);
for (;;) { /* loop over activations */
- activation *a = &(activ_stack[top_activ_stack]);
- void *bi_func_data = 0;
- int bi_func_pc;
- unsigned bi_func_id = 0;
- Objid player;
- Var v, *goal = a->base_rt_stack;
+ activation *a = &(activ_stack[top_activ_stack]);
+ void *bi_func_data = 0;
+ int bi_func_pc;
+ unsigned bi_func_id = 0;
+ Objid player;
+ Var v, *goal = a->base_rt_stack;
if (why == FIN_EXIT)
goal += value.v.list[1].v.num;
- while (a->top_rt_stack > goal) { /* loop over rt stack */
+ while (a->top_rt_stack > goal) { /* loop over rt stack */
a->top_rt_stack--;
v = *(a->top_rt_stack);
- if (why != FIN_ABORT && v.type == TYPE_FINALLY) {
+ if (why != FIN_ABORT && v.type == TYPE_FINALLY) {
/* FINALLY handler */
a->pc = v.v.num;
v.type = TYPE_INT;
@@ -188,11 +188,11 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome)
*(a->top_rt_stack++) = v;
*(a->top_rt_stack++) = value;
return 0;
- } else if (why == FIN_RAISE && v.type == TYPE_CATCH) {
+ } else if (why == FIN_RAISE && v.type == TYPE_CATCH) {
/* TRY-EXCEPT or `expr ! ...' handler */
- Var *new_top = a->top_rt_stack - 2 * v.v.num;
- Var *vv;
- int found = 0;
+ Var *new_top = a->top_rt_stack - 2 * v.v.num;
+ Var *vv;
+ int found = 0;
for (vv = new_top; vv < a->top_rt_stack; vv += 2) {
if (!found && (vv->type != TYPE_LIST
@@ -219,7 +219,6 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome)
free_var(value);
return 0;
}
-
bi_func_pc = a->bi_func_pc;
if (bi_func_pc) {
bi_func_id = a->bi_func_id;
@@ -228,7 +227,7 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome)
player = a->player;
free_activation(*a, 0); /* 0 == don't free bi_func_data */
- if (top_activ_stack == 0) { /* done */
+ if (top_activ_stack == 0) { /* done */
if (outcome)
*outcome = (why == FIN_RETURN
? OUTCOME_DONE
@@ -238,17 +237,17 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome)
top_activ_stack--;
if (bi_func_pc != 0) { /* Must unwind through a built-in function */
- package p;
+ package p;
if (why == FIN_RETURN) {
a = &(activ_stack[top_activ_stack]);
p = call_bi_func(bi_func_id, value, bi_func_pc, a->progr,
bi_func_data);
switch (p.kind) {
- case BI_RETURN:
+ case BI_RETURN:
*(a->top_rt_stack++) = p.u.ret;
return 0;
- case BI_RAISE:
+ case BI_RAISE:
if (a->debug)
return raise_error(p, outcome);
else {
@@ -257,10 +256,10 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome)
free_var(p.u.raise.value);
return 0;
}
- case BI_SUSPEND:
+ case BI_SUSPEND:
{
- enum error e = suspend_task(p);
-
+ enum error e = suspend_task(p);
+
if (e == E_NONE) {
if (outcome)
*outcome = OUTCOME_BLOCKED;
@@ -271,8 +270,8 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome)
return unwind_stack(FIN_RAISE, value, outcome);
}
}
- case BI_CALL:
- a = &(activ_stack[top_activ_stack]); /* TOS has changed */
+ case BI_CALL:
+ a = &(activ_stack[top_activ_stack]); /* TOS has changed */
a->bi_func_id = bi_func_id;
a->bi_func_pc = p.u.call.pc;
a->bi_func_data = p.u.call.data;
@@ -292,25 +291,25 @@ unwind_stack(Finally_Reason why, Var value, enum outcome *outcome)
p = call_bi_func(bi_func_id, zero, bi_func_pc, a->progr,
bi_func_data);
switch (p.kind) {
- case BI_RETURN:
+ case BI_RETURN:
free_var(p.u.ret);
break;
- case BI_RAISE:
+ case BI_RAISE:
free_var(p.u.raise.code);
free_str(p.u.raise.msg);
free_var(p.u.raise.value);
break;
- case BI_SUSPEND:
+ case BI_SUSPEND:
break;
- case BI_CALL:
+ case BI_CALL:
free_activation(activ_stack[top_activ_stack--], 0);
bi_func_pc = p.u.call.pc;
bi_func_data = p.u.call.data;
break;
}
- } while (p.kind == BI_CALL && bi_func_pc != 0); /* !tailcall */
+ } while (p.kind == BI_CALL && bi_func_pc != 0); /* !tailcall */
}
- } else if (why == FIN_RETURN) { /* Push the value on the stack & go */
+ } else if (why == FIN_RETURN) { /* Push the value on the stack & go */
a = &(activ_stack[top_activ_stack]);
*(a->top_rt_stack++) = value;
return 0;
@@ -324,12 +323,12 @@ find_handler_activ(Var code)
/* Returns the index of the hottest activation with an active exception
* handler for the given code.
*/
- int frame;
+ int frame;
for (frame = top_activ_stack; frame >= 0; frame--) {
- activation *a = &(activ_stack[frame]);
- Var *v, *vv;
-
+ activation *a = &(activ_stack[frame]);
+ Var *v, *vv;
+
for (v = a->top_rt_stack - 1; v >= a->base_rt_stack; v--)
if (v->type == TYPE_CATCH) {
for (vv = v - 2 * v->v.num; vv < v; vv += 2)
@@ -343,11 +342,11 @@ find_handler_activ(Var code)
}
static Var
-make_stack_list(activation *stack, int start, int end, int include_end,
+make_stack_list(activation * stack, int start, int end, int include_end,
int root_vector, int line_numbers_too)
{
- Var r;
- int count = 0, i, j;
+ Var r;
+ int count = 0, i, j;
for (i = end; i >= start; i--) {
if (include_end || i != end)
@@ -359,8 +358,8 @@ make_stack_list(activation *stack, int start, int end, int include_end,
r = new_list(count);
j = 1;
for (i = end; i >= start; i--) {
- Var v;
-
+ Var v;
+
if (include_end || i != end) {
v = r.v.list[j++] = new_list(line_numbers_too ? 6 : 5);
v.v.list[1].type = TYPE_OBJ;
@@ -381,7 +380,6 @@ make_stack_list(activation *stack, int start, int end, int include_end,
stack[i].error_pc);
}
}
-
if (i != start && stack[i].bi_func_pc) {
v = r.v.list[j++] = new_list(line_numbers_too ? 6 : 5);
v.v.list[1].type = TYPE_OBJ;
@@ -416,9 +414,9 @@ static int
raise_error(package p, enum outcome *outcome)
{
/* ASSERT: p.kind == BI_RAISE */
- int handler_activ = find_handler_activ(p.u.raise.code);
- Finally_Reason why;
- Var value;
+ int handler_activ = find_handler_activ(p.u.raise.code);
+ Finally_Reason why;
+ Var value;
if (handler_activ >= 0) { /* handler found */
why = FIN_RAISE;
@@ -441,16 +439,15 @@ raise_error(package p, enum outcome *outcome)
save_handler_info("handle_uncaught_error", value);
value = zero;
}
-
return unwind_stack(why, value, outcome);
}
static void
abort_task(int is_ticks)
{
- Var value;
+ Var value;
const char *msg = (is_ticks ? "Task ran out of ticks"
- : "Task ran out of seconds");
+ : "Task ran out of seconds");
value = new_list(3);
value.v.list[1].type = TYPE_STR;
@@ -472,34 +469,34 @@ push_activation(void)
return 1;
} else
return 0;
-}
+}
-void
+void
free_activation(activation a, char data_too)
{
Var *i;
-
+
free_rt_env(a.rt_env, a.prog->num_var_names);
-
+
for (i = a.base_rt_stack; i < a.top_rt_stack; i++)
free_var(*i);
myfree((void *) a.base_rt_stack, M_RT_STACK);
free_var(a.temp);
free_str(a.verb);
free_str(a.verbname);
-
+
free_program(a.prog);
-
+
if (data_too && a.bi_func_pc && a.bi_func_data)
free_data(a.bi_func_data);
/* else bi_func_state will be later freed by bi_function */
}
-
+
/** Set up another activation for calling a verb
does not change the vm in case of any error **/
-enum error
+enum error
call_verb(Objid this, const char *vname, Var args, int do_pass)
{
/* if call succeeds, args will be consumed. If call fails, args
@@ -511,13 +508,13 @@ call_verb(Objid this, const char *vname, Var args, int do_pass)
case, else sets up the activ_stack for the verb call and then returns
E_NONE */
- Objid where;
- db_verb_handle h;
- Program *program;
- Var *env;
+ Objid where;
+ db_verb_handle h;
+ Program *program;
+ Var *env;
Var v;
- if (do_pass)
+ if (do_pass)
if (!valid(RUN_ACTIV.vloc))
return E_INVIND;
else
@@ -544,29 +541,29 @@ call_verb(Objid this, const char *vname, Var args, int do_pass)
RUN_ACTIV.debug = (db_verb_flags(h) & VF_DEBUG);
RUN_ACTIV.top_rt_stack = RUN_ACTIV.base_rt_stack
- = mymalloc (program->main_vector.max_stack * sizeof(Var), M_RT_STACK);
+ = mymalloc(program->main_vector.max_stack * sizeof(Var), M_RT_STACK);
RUN_ACTIV.pc = 0;
RUN_ACTIV.error_pc = 0;
RUN_ACTIV.bi_func_pc = 0;
RUN_ACTIV.temp.type = TYPE_NONE;
RUN_ACTIV.rt_env = env = new_rt_env(RUN_ACTIV.prog->num_var_names);
-
+
fill_in_rt_consts(env, program->version);
set_rt_env_obj(env, SLOT_THIS, this);
set_rt_env_obj(env, SLOT_CALLER, CALLER_ACTIV.this);
-
+
#define ENV_COPY(slot) \
set_rt_env_var(env, slot, var_ref(CALLER_ACTIV.rt_env[slot]))
-
+
ENV_COPY(SLOT_ARGSTR);
ENV_COPY(SLOT_DOBJ);
- ENV_COPY(SLOT_DOBJSTR);
- ENV_COPY(SLOT_PREPSTR);
+ ENV_COPY(SLOT_DOBJSTR);
+ ENV_COPY(SLOT_PREPSTR);
ENV_COPY(SLOT_IOBJ);
ENV_COPY(SLOT_IOBJSTR);
-
+
if (is_wizard(CALLER_ACTIV.progr) &&
(CALLER_ACTIV.rt_env[SLOT_PLAYER].type == TYPE_OBJ))
ENV_COPY(SLOT_PLAYER);
@@ -575,11 +572,11 @@ call_verb(Objid this, const char *vname, Var args, int do_pass)
RUN_ACTIV.player = env[SLOT_PLAYER].v.obj;
#undef ENV_COPY
-
+
v.type = TYPE_STR;
v.v.str = vname;
- set_rt_env_var(env, SLOT_VERB, v); /* no var_dup */
- set_rt_env_var(env, SLOT_ARGS, args); /* no var_dup */
+ set_rt_env_var(env, SLOT_VERB, v); /* no var_dup */
+ set_rt_env_var(env, SLOT_ARGS, args); /* no var_dup */
return E_NONE;
}
@@ -587,7 +584,7 @@ call_verb(Objid this, const char *vname, Var args, int do_pass)
static int
rangeset_check(int end, int from, int to)
{
- if (from > end+1 || to < 0)
+ if (from > end + 1 || to < 0)
return 1;
return 0;
}
@@ -601,16 +598,34 @@ bi_prop_protected(enum bi_prop prop, Objid progr)
return 0;
switch (prop) {
- case BP_NAME: pname = "protect_name"; break;
- case BP_OWNER: pname = "protect_owner"; break;
- case BP_PROGRAMMER: pname = "protect_programmer"; break;
- case BP_WIZARD: pname = "protect_wizard"; break;
- case BP_R: pname = "protect_r"; break;
- case BP_W: pname = "protect_w"; break;
- case BP_F: pname = "protect_f"; break;
- case BP_LOCATION: pname = "protect_location"; break;
- case BP_CONTENTS: pname = "protect_contents"; break;
- default:
+ case BP_NAME:
+ pname = "protect_name";
+ break;
+ case BP_OWNER:
+ pname = "protect_owner";
+ break;
+ case BP_PROGRAMMER:
+ pname = "protect_programmer";
+ break;
+ case BP_WIZARD:
+ pname = "protect_wizard";
+ break;
+ case BP_R:
+ pname = "protect_r";
+ break;
+ case BP_W:
+ pname = "protect_w";
+ break;
+ case BP_F:
+ pname = "protect_f";
+ break;
+ case BP_LOCATION:
+ pname = "protect_location";
+ break;
+ case BP_CONTENTS:
+ pname = "protect_contents";
+ break;
+ default:
panic("Can't happen in BI_PROP_PROTECTED!");
}
@@ -620,25 +635,25 @@ bi_prop_protected(enum bi_prop prop, Objid progr)
/**
the main interpreter -- run()
everything is just an entry point to it
-**/
-
+**/
+
static enum outcome
-run(enum error resumption_error, Var *result) /* runs the_vm */
-{
+run(enum error resumption_error, Var * result)
+{ /* runs the_vm */
/* If the returned value is OUTCOME_DONE and RESULT is non-NULL, then
* *RESULT is the value returned by the top frame.
*/
/* bc, bv, rts are distinguished as the state variables of run()
their value capture the state of the running between OP_ cases */
- Bytecodes bc;
- Byte *bv, *error_bv;
- Var *rts; /* next empty slot */
- enum Opcode op;
- Var error_var;
- enum outcome outcome;
-
- /** a bunch of macros that work *ONLY* inside run() **/
+ Bytecodes bc;
+ Byte *bv, *error_bv;
+ Var *rts; /* next empty slot */
+ enum Opcode op;
+ Var error_var;
+ enum outcome outcome;
+
+/** a bunch of macros that work *ONLY* inside run() **/
/* helping macros about the runtime_stack. */
#define POP() (*(--rts))
@@ -674,7 +689,7 @@ do { \
RUN_ACTIV.error_pc = error_bv - bc.vector; \
RUN_ACTIV.top_rt_stack = rts; \
} while (0)
-
+
#define RAISE_ERROR(the_err) \
do { \
if (RUN_ACTIV.debug) { \
@@ -700,1164 +715,1167 @@ do { \
/* end of major run() macros */
- LOAD_STATE_VARIABLES();
-
- if (resumption_error != E_NONE) {
- error_bv = bv;
- PUSH_ERROR(resumption_error);
- }
-
- for (;;) {
- next_opcode:
- op = *bv;
- error_bv = bv;
- bv++;
-
- if (COUNT_TICK(op))
- ticks_remaining--;
-
- if (task_killed) {
- STORE_STATE_VARIABLES();
- unwind_stack(FIN_ABORT, zero, 0);
- return OUTCOME_ABORTED;
- }
+ LOAD_STATE_VARIABLES();
- if (ticks_remaining <= 0) {
- STORE_STATE_VARIABLES();
- abort_task(1);
- return OUTCOME_ABORTED;
- }
-
- if (task_timed_out) {
- STORE_STATE_VARIABLES();
- abort_task(0);
- return OUTCOME_ABORTED;
+ if (resumption_error != E_NONE) {
+ error_bv = bv;
+ PUSH_ERROR(resumption_error);
}
+ for (;;) {
+ next_opcode:
+ op = *bv;
+ error_bv = bv;
+ bv++;
- switch (op) {
-
- case OP_IF_QUES:
- case OP_IF:
- case OP_WHILE:
- case OP_EIF:
- do_test:
- {
- Var cond;
-
- cond = POP();
- if (!is_true(cond)) /* jump if false */
- JUMP(READ_BYTES(bv, bc.numbytes_label));
- else {
- bv += bc.numbytes_label;
- }
- free_var(cond);
- }
- break;
-
- case OP_JUMP:
- JUMP(READ_BYTES(bv, bc.numbytes_label));
- break;
-
- case OP_FOR_LIST:
- {
- unsigned id = READ_BYTES(bv, bc.numbytes_var_name);
- unsigned lab = READ_BYTES(bv, bc.numbytes_label);
- Var count, list;
-
- count = TOP_RT_VALUE; /* will be a integer */
- list = NEXT_TOP_RT_VALUE; /* should be a list */
- if (list.type != TYPE_LIST) {
- RAISE_ERROR(E_TYPE);
- free_var(POP());
- free_var(POP());
- JUMP(lab);
- } else if (count.v.num > list.v.list[0].v.num /* size */) {
- free_var(POP());
- free_var(POP());
- JUMP(lab);
- } else {
- free_var(RUN_ACTIV.rt_env[id]);
- RUN_ACTIV.rt_env[id] = var_ref(list.v.list[count.v.num]);
- count.v.num++; /* increment count */
- TOP_RT_VALUE = count;
- }
- }
- break;
-
- case OP_FOR_RANGE:
- {
- unsigned id = READ_BYTES(bv, bc.numbytes_var_name);
- unsigned lab = READ_BYTES(bv, bc.numbytes_label);
- Var from, to;
-
- to = TOP_RT_VALUE;
- from = NEXT_TOP_RT_VALUE;
- if ((to.type != TYPE_INT && to.type != TYPE_OBJ)
- || to.type != from.type) {
- RAISE_ERROR(E_TYPE);
- free_var(POP());
- free_var(POP());
- JUMP(lab);
- } else if (to.type == TYPE_INT
- ? from.v.num > to.v.num
- : from.v.obj > to.v.obj) {
- free_var(POP());
- free_var(POP());
- JUMP(lab);
- } else {
- free_var(RUN_ACTIV.rt_env[id]);
- RUN_ACTIV.rt_env[id] = var_ref(from);
- if (to.type == TYPE_INT)
- from.v.num++;
- else
- from.v.obj++;
- NEXT_TOP_RT_VALUE = from;
- }
- }
- break;
-
- case OP_POP:
- free_var(POP());
- break;
-
- case OP_IMM:
- {
- int slot = READ_BYTES(bv, bc.numbytes_literal);
- PUSH_REF(RUN_ACTIV.prog->literals[slot]);
- }
- break;
-
- case OP_MAKE_EMPTY_LIST:
- {
- Var list;
+ if (COUNT_TICK(op))
+ ticks_remaining--;
- list = new_list(0);
- PUSH(list);
+ if (task_killed) {
+ STORE_STATE_VARIABLES();
+ unwind_stack(FIN_ABORT, zero, 0);
+ return OUTCOME_ABORTED;
}
- break;
-
- case OP_LIST_ADD_TAIL:
- {
- Var tail, list;
-
- tail = POP(); /* whatever */
- list = POP(); /* should be list */
- if (list.type != TYPE_LIST) {
- free_var(list);
- free_var(tail);
- PUSH_ERROR(E_TYPE);
- } else
- PUSH(listappend(list, tail));
+ if (ticks_remaining <= 0) {
+ STORE_STATE_VARIABLES();
+ abort_task(1);
+ return OUTCOME_ABORTED;
}
- break;
-
- case OP_LIST_APPEND:
- {
- Var tail, list;
-
- tail = POP(); /* second, should be list */
- list = POP(); /* first, should be list */
- if (tail.type != TYPE_LIST || list.type != TYPE_LIST) {
- free_var(tail);
- free_var(list);
- PUSH_ERROR(E_TYPE);
- } else
- PUSH(listconcat(list, tail));
+ if (task_timed_out) {
+ STORE_STATE_VARIABLES();
+ abort_task(0);
+ return OUTCOME_ABORTED;
}
- break;
-
- case OP_INDEXSET:
- {
- Var value, index, list;
-
- value = POP(); /* rhs value */
- index = POP(); /* index, should be integer */
- list = POP(); /* lhs except last index, should be list or str */
- /* whole thing should mean list[index] = value */
- if ((list.type != TYPE_LIST && list.type != TYPE_STR)
- || index.type != TYPE_INT
- || (list.type == TYPE_STR && value.type != TYPE_STR)) {
- free_var(value);
- free_var(index);
- free_var(list);
- PUSH_ERROR(E_TYPE);
- } else if (index.v.num < 1
- || (list.type == TYPE_LIST
- && index.v.num > list.v.list[0].v.num /* size */)
- || (list.type == TYPE_STR
- && index.v.num > (int) strlen(list.v.str))) {
- free_var(value);
- free_var(index);
- free_var(list);
- PUSH_ERROR(E_RANGE);
- } else if (list.type == TYPE_STR && strlen(value.v.str) != 1) {
- free_var(value);
- free_var(index);
- free_var(list);
- PUSH_ERROR(E_INVARG);
- } else if (list.type == TYPE_LIST) {
- PUSH(listset(var_dup(list), value, index.v.num));
- free_var(list);
- } else { /* TYPE_STR */
- char *tmp_str = str_dup(list.v.str);
- free_str(list.v.str);
- tmp_str[index.v.num - 1] = value.v.str[0];
- list.v.str = tmp_str;
- free_var(value);
- PUSH(list);
+ switch (op) {
+
+ case OP_IF_QUES:
+ case OP_IF:
+ case OP_WHILE:
+ case OP_EIF:
+ do_test:
+ {
+ Var cond;
+
+ cond = POP();
+ if (!is_true(cond)) /* jump if false */
+ JUMP(READ_BYTES(bv, bc.numbytes_label));
+ else {
+ bv += bc.numbytes_label;
+ }
+ free_var(cond);
}
- }
- break;
-
- case OP_MAKE_SINGLETON_LIST:
- {
- Var list;
-
- list = new_list(1);
- list.v.list[1] = POP();
- PUSH(list);
- }
- break;
-
- case OP_CHECK_LIST_FOR_SPLICE:
- if (TOP_RT_VALUE.type != TYPE_LIST) {
- free_var(POP());
- PUSH_ERROR(E_TYPE);
- }
- /* no op if top-rt-stack is a list */
- break;
-
- case OP_PUT_TEMP:
- RUN_ACTIV.temp = var_ref(TOP_RT_VALUE);
- break;
-
- case OP_PUSH_TEMP:
- PUSH(RUN_ACTIV.temp);
- RUN_ACTIV.temp.type = TYPE_NONE;
- break;
-
- case OP_EQ:
- case OP_NE:
- {
- Var rhs, lhs, ans;
-
- rhs = POP();
- lhs = POP();
- ans.type = TYPE_INT;
- ans.v.num = (op == OP_EQ
- ? equality(rhs, lhs, 0)
- : !equality(rhs, lhs, 0));
- PUSH(ans);
- free_var(rhs);
- free_var(lhs);
- }
- break;
-
- case OP_GT:
- case OP_LT:
- case OP_GE:
- case OP_LE:
- {
- Var rhs, lhs, ans;
- int comparison;
-
- rhs = POP();
- lhs = POP();
- if ((lhs.type == TYPE_INT || lhs.type == TYPE_FLOAT)
- && (rhs.type == TYPE_INT || rhs.type == TYPE_FLOAT)) {
- ans = compare_numbers(lhs, rhs);
- if (ans.type == TYPE_ERR) {
- free_var(rhs);
- free_var(lhs);
- PUSH_ERROR(ans.v.err);
+ break;
+
+ case OP_JUMP:
+ JUMP(READ_BYTES(bv, bc.numbytes_label));
+ break;
+
+ case OP_FOR_LIST:
+ {
+ unsigned id = READ_BYTES(bv, bc.numbytes_var_name);
+ unsigned lab = READ_BYTES(bv, bc.numbytes_label);
+ Var count, list;
+
+ count = TOP_RT_VALUE; /* will be a integer */
+ list = NEXT_TOP_RT_VALUE; /* should be a list */
+ if (list.type != TYPE_LIST) {
+ RAISE_ERROR(E_TYPE);
+ free_var(POP());
+ free_var(POP());
+ JUMP(lab);
+ } else if (count.v.num > list.v.list[0].v.num /* size */ ) {
+ free_var(POP());
+ free_var(POP());
+ JUMP(lab);
} else {
- comparison = ans.v.num;
- goto finish_comparison;
- }
- } else if (rhs.type != lhs.type || rhs.type == TYPE_LIST) {
- free_var(rhs);
- free_var(lhs);
- PUSH_ERROR(E_TYPE);
- } else {
- switch(rhs.type) {
- case TYPE_INT:
- comparison = compare_integers(lhs.v.num, rhs.v.num);
- break;
- case TYPE_OBJ:
- comparison = compare_integers(lhs.v.obj, rhs.v.obj);
- break;
- case TYPE_ERR:
- comparison = ((int) lhs.v.err) - ((int) rhs.v.err);
- break;
- case TYPE_STR:
- comparison = mystrcasecmp(lhs.v.str, rhs.v.str);
- break;
- default:
- errlog("RUN: Impossible type in comparison: %d\n",
- rhs.type);
- comparison = 0;
- }
-
- finish_comparison:
- ans.type = TYPE_INT;
- switch (op) {
- case OP_LT:
- ans.v.num = (comparison < 0);
- break;
- case OP_LE:
- ans.v.num = (comparison <= 0);
- break;
- case OP_GT:
- ans.v.num = (comparison > 0);
- break;
- case OP_GE:
- ans.v.num = (comparison >= 0);
- break;
- default:
- errlog("RUN: Imposible opcode in comparison: %d\n", op);
- break;
+ free_var(RUN_ACTIV.rt_env[id]);
+ RUN_ACTIV.rt_env[id] = var_ref(list.v.list[count.v.num]);
+ count.v.num++; /* increment count */
+ TOP_RT_VALUE = count;
}
- PUSH(ans);
- free_var(rhs);
- free_var(lhs);
}
- }
- break;
-
- case OP_IN:
- {
- Var lhs, rhs, ans;
-
- rhs = POP(); /* should be list */
- lhs = POP(); /* lhs, any type */
- if (rhs.type != TYPE_LIST) {
- free_var(rhs);
- free_var(lhs);
- PUSH_ERROR(E_TYPE);
- } else {
- ans.type = TYPE_INT;
- ans.v.num = ismember(lhs, rhs, 0);
- PUSH(ans);
- free_var(rhs);
- free_var(lhs);
- }
- }
- break;
-
- case OP_MULT:
- case OP_MINUS:
- case OP_DIV:
- case OP_MOD:
- {
- Var lhs, rhs, ans;
-
- rhs = POP(); /* should be number */
- lhs = POP(); /* should be number */
- if ((lhs.type == TYPE_INT || lhs.type == TYPE_FLOAT)
- && (rhs.type == TYPE_INT || rhs.type == TYPE_FLOAT)) {
- switch (op) {
- case OP_MULT: ans = do_multiply(lhs, rhs); break;
- case OP_MINUS: ans = do_subtract(lhs, rhs); break;
- case OP_DIV: ans = do_divide(lhs, rhs); break;
- case OP_MOD: ans = do_modulus(lhs, rhs); break;
- default:
- errlog("RUN: Impossible opcode in arith ops: %d\n", op);
- break;
+ break;
+
+ case OP_FOR_RANGE:
+ {
+ unsigned id = READ_BYTES(bv, bc.numbytes_var_name);
+ unsigned lab = READ_BYTES(bv, bc.numbytes_label);
+ Var from, to;
+
+ to = TOP_RT_VALUE;
+ from = NEXT_TOP_RT_VALUE;
+ if ((to.type != TYPE_INT && to.type != TYPE_OBJ)
+ || to.type != from.type) {
+ RAISE_ERROR(E_TYPE);
+ free_var(POP());
+ free_var(POP());
+ JUMP(lab);
+ } else if (to.type == TYPE_INT
+ ? from.v.num > to.v.num
+ : from.v.obj > to.v.obj) {
+ free_var(POP());
+ free_var(POP());
+ JUMP(lab);
+ } else {
+ free_var(RUN_ACTIV.rt_env[id]);
+ RUN_ACTIV.rt_env[id] = var_ref(from);
+ if (to.type == TYPE_INT)
+ from.v.num++;
+ else
+ from.v.obj++;
+ NEXT_TOP_RT_VALUE = from;
}
- } else {
- ans.type = TYPE_ERR;
- ans.v.err = E_TYPE;
}
- free_var(rhs);
- free_var(lhs);
- if (ans.type == TYPE_ERR)
- PUSH_ERROR(ans.v.err);
- else
- PUSH(ans);
- }
- break;
-
- case OP_ADD:
- {
- Var rhs, lhs, ans;
-
- rhs = POP();
- lhs = POP();
- if ((lhs.type == TYPE_INT || lhs.type == TYPE_FLOAT)
- && (rhs.type == TYPE_INT || rhs.type == TYPE_FLOAT))
- ans = do_add(lhs, rhs);
- else if (lhs.type == TYPE_STR && rhs.type == TYPE_STR) {
- char *str;
-
- str = mymalloc((strlen(rhs.v.str) + strlen(lhs.v.str) + 1)
- * sizeof(char), M_STRING);
- sprintf(str, "%s%s", lhs.v.str, rhs.v.str);
- ans.type = TYPE_STR;
- ans.v.str = str;
- } else {
- ans.type = TYPE_ERR;
- ans.v.err = E_TYPE;
- }
- free_var(rhs);
- free_var(lhs);
+ break;
- if (ans.type == TYPE_ERR)
- PUSH_ERROR(ans.v.err);
- else
- PUSH(ans);
- }
- break;
-
- case OP_AND:
- case OP_OR:
- {
- Var lhs;
- unsigned lab = READ_BYTES(bv, bc.numbytes_label);
-
- lhs = TOP_RT_VALUE;
- if ( (op == OP_AND && !is_true(lhs))
- || (op == OP_OR && is_true(lhs))) /* short-circuit */
- JUMP(lab);
- else {
- free_var(POP());
+ case OP_POP:
+ free_var(POP());
+ break;
+
+ case OP_IMM:
+ {
+ int slot = READ_BYTES(bv, bc.numbytes_literal);
+ PUSH_REF(RUN_ACTIV.prog->literals[slot]);
}
- }
- break;
-
- case OP_NOT:
- {
- Var arg, ans;
-
- arg = POP();
- ans.type = TYPE_INT;
- ans.v.num = !is_true(arg);
- PUSH(ans);
- free_var(arg);
- }
- break;
+ break;
- case OP_UNARY_MINUS:
- {
- Var arg, ans;
-
- arg = POP();
- if (arg.type == TYPE_INT) {
- ans.type = TYPE_INT;
- ans.v.num = -arg.v.num;
- } else if (arg.type == TYPE_FLOAT)
- ans = new_float(-*arg.v.fnum);
- else {
- free_var(arg);
- PUSH_ERROR(E_TYPE);
- break;
+ case OP_MAKE_EMPTY_LIST:
+ {
+ Var list;
+
+ list = new_list(0);
+ PUSH(list);
}
+ break;
- PUSH(ans);
- free_var(arg);
- }
- break;
+ case OP_LIST_ADD_TAIL:
+ {
+ Var tail, list;
- case OP_REF:
- {
- Var index, list;
-
- index = POP(); /* should be integer */
- list = POP(); /* should be list or string */
-
- if (index.type != TYPE_INT ||
- (list.type != TYPE_LIST && list.type != TYPE_STR)) {
- free_var(index);
- free_var(list);
- PUSH_ERROR(E_TYPE);
+ tail = POP(); /* whatever */
+ list = POP(); /* should be list */
+ if (list.type != TYPE_LIST) {
+ free_var(list);
+ free_var(tail);
+ PUSH_ERROR(E_TYPE);
+ } else
+ PUSH(listappend(list, tail));
}
- else if (list.type == TYPE_LIST) {
- if (index.v.num <= 0 || index.v.num > list.v.list[0].v.num) {
- free_var(index);
+ break;
+
+ case OP_LIST_APPEND:
+ {
+ Var tail, list;
+
+ tail = POP(); /* second, should be list */
+ list = POP(); /* first, should be list */
+ if (tail.type != TYPE_LIST || list.type != TYPE_LIST) {
+ free_var(tail);
free_var(list);
- PUSH_ERROR(E_RANGE);
- } else {
- PUSH(var_ref(list.v.list[index.v.num]));
+ PUSH_ERROR(E_TYPE);
+ } else
+ PUSH(listconcat(list, tail));
+ }
+ break;
+
+ case OP_INDEXSET:
+ {
+ Var value, index, list;
+
+ value = POP(); /* rhs value */
+ index = POP(); /* index, should be integer */
+ list = POP(); /* lhs except last index, should be list or str */
+ /* whole thing should mean list[index] = value */
+ if ((list.type != TYPE_LIST && list.type != TYPE_STR)
+ || index.type != TYPE_INT
+ || (list.type == TYPE_STR && value.type != TYPE_STR)) {
+ free_var(value);
free_var(index);
free_var(list);
- }
- } else { /* list.type == TYPE_STR */
- if (index.v.num <= 0
- || index.v.num > (int) strlen(list.v.str)) {
+ PUSH_ERROR(E_TYPE);
+ } else if (index.v.num < 1
+ || (list.type == TYPE_LIST
+ && index.v.num > list.v.list[0].v.num /* size */ )
+ || (list.type == TYPE_STR
+ && index.v.num > (int) strlen(list.v.str))) {
+ free_var(value);
free_var(index);
free_var(list);
PUSH_ERROR(E_RANGE);
- } else {
- PUSH(strget(list, index));
+ } else if (list.type == TYPE_STR && strlen(value.v.str) != 1) {
+ free_var(value);
free_var(index);
free_var(list);
+ PUSH_ERROR(E_INVARG);
+ } else if (list.type == TYPE_LIST) {
+ PUSH(listset(var_dup(list), value, index.v.num));
+ free_var(list);
+ } else { /* TYPE_STR */
+ char *tmp_str = str_dup(list.v.str);
+ free_str(list.v.str);
+ tmp_str[index.v.num - 1] = value.v.str[0];
+ list.v.str = tmp_str;
+ free_var(value);
+ PUSH(list);
}
}
- }
- break;
+ break;
- case OP_PUSH_REF:
- {
- Var index, list;
-
- index = TOP_RT_VALUE;
- list = NEXT_TOP_RT_VALUE;
+ case OP_MAKE_SINGLETON_LIST:
+ {
+ Var list;
- if (index.type != TYPE_INT || list.type != TYPE_LIST) {
- PUSH_ERROR(E_TYPE);
- } else if (index.v.num <= 0 ||
- index.v.num > list.v.list[0].v.num) {
- PUSH_ERROR(E_RANGE);
- } else
- PUSH(var_ref(list.v.list[index.v.num]));
- }
- break;
-
- case OP_RANGE_REF:
- {
- Var base, from, to;
-
- to = POP(); /* should be integer */
- from = POP(); /* should be integer */
- base = POP(); /* should be list or string */
-
- if ((base.type != TYPE_LIST && base.type != TYPE_STR)
- || to.type != TYPE_INT || from.type != TYPE_INT) {
- free_var(to);
- free_var(from);
- PUSH_ERROR(E_TYPE);
- } else {
- int len = (base.type == TYPE_STR ? strlen(base.v.str)
- : base.v.list[0].v.num);
- if (from.v.num <= to.v.num
- && (from.v.num <= 0 || from.v.num > len
- || to.v.num <= 0 || to.v.num > len)) {
- free_var(to);
- free_var(from);
- free_var(base);
- PUSH_ERROR(E_RANGE);
- } else {
- PUSH((base.type == TYPE_STR
- ? substr(base, from.v.num, to.v.num)
- : sublist(base, from.v.num, to.v.num)));
- /* base freed by substr/sublist */
- free_var(from);
- free_var(to);
- }
+ list = new_list(1);
+ list.v.list[1] = POP();
+ PUSH(list);
}
- }
- break;
-
- case OP_G_PUT:
- {
- unsigned id = READ_BYTES(bv, bc.numbytes_var_name);
- free_var(RUN_ACTIV.rt_env[id]);
- RUN_ACTIV.rt_env[id] = var_ref(TOP_RT_VALUE);
- }
- break;
-
- case OP_G_PUSH:
- {
- Var value;
-
- value = RUN_ACTIV.rt_env[READ_BYTES(bv, bc.numbytes_var_name)];
- if (value.type == TYPE_NONE)
- PUSH_ERROR(E_VARNF);
- else
- PUSH_REF(value);
- }
- break;
-
- case OP_GET_PROP:
- {
- Var propname, obj, prop;
-
- propname = POP(); /* should be string */
- obj = POP(); /* should be objid */
- if (propname.type != TYPE_STR || obj.type != TYPE_OBJ) {
- free_var(propname);
- free_var(obj);
- PUSH_ERROR(E_TYPE);
- } else if (!valid(obj.v.obj)) {
- free_var(propname);
- free_var(obj);
- PUSH_ERROR(E_INVIND);
- } else {
- db_prop_handle h;
+ break;
- h = db_find_property(obj.v.obj, propname.v.str, &prop);
- if (!h.ptr)
- PUSH_ERROR(E_PROPNF);
- else if (h.built_in
- ? bi_prop_protected(h.built_in, RUN_ACTIV.progr)
- : !db_property_allows(h, RUN_ACTIV.progr, PF_READ))
- PUSH_ERROR(E_PERM);
- else if (h.built_in)
- PUSH(prop); /* it's already freshly allocated */
- else
- PUSH_REF(prop);
- free_var(propname);
- free_var(obj);
- }
- }
- break;
-
- case OP_PUSH_GET_PROP:
- {
- Var propname, obj, prop;
-
- propname = TOP_RT_VALUE;
- obj = NEXT_TOP_RT_VALUE;
- if (propname.type != TYPE_STR || obj.type != TYPE_OBJ)
+ case OP_CHECK_LIST_FOR_SPLICE:
+ if (TOP_RT_VALUE.type != TYPE_LIST) {
+ free_var(POP());
PUSH_ERROR(E_TYPE);
- else if (!valid(obj.v.obj))
- PUSH_ERROR(E_INVIND);
- else {
- db_prop_handle h;
-
- h = db_find_property(obj.v.obj, propname.v.str, &prop);
- if (!h.ptr)
- PUSH_ERROR(E_PROPNF);
- else if (h.built_in
- ? bi_prop_protected(h.built_in, RUN_ACTIV.progr)
- : !db_property_allows(h, RUN_ACTIV.progr, PF_READ))
- PUSH_ERROR(E_PERM);
- else if (h.built_in)
- PUSH(prop);
- else
- PUSH_REF(prop);
}
- }
- break;
-
- case OP_PUT_PROP:
- {
- Var obj, propname, rhs;
-
- rhs = POP(); /* any type */
- propname = POP(); /* should be string */
- obj = POP(); /* should be objid */
- if (obj.type != TYPE_OBJ || propname.type != TYPE_STR) {
- free_var(rhs);
- free_var(propname);
- free_var(obj);
- PUSH_ERROR(E_TYPE);
- } else if (!valid(obj.v.obj)) {
- free_var(rhs);
- free_var(propname);
- free_var(obj);
- PUSH_ERROR(E_INVIND);
- } else {
- db_prop_handle h;
- enum error err = E_NONE;
- Objid progr = RUN_ACTIV.progr;
+ /* no op if top-rt-stack is a list */
+ break;
- h = db_find_property(obj.v.obj, propname.v.str, 0);
- if (!h.ptr)
- err = E_PROPNF;
- else {
- switch (h.built_in) {
- case BP_NONE: /* Not a built-in property */
- if (!db_property_allows(h, progr, PF_WRITE))
- err = E_PERM;
+ case OP_PUT_TEMP:
+ RUN_ACTIV.temp = var_ref(TOP_RT_VALUE);
+ break;
+
+ case OP_PUSH_TEMP:
+ PUSH(RUN_ACTIV.temp);
+ RUN_ACTIV.temp.type = TYPE_NONE;
+ break;
+
+ case OP_EQ:
+ case OP_NE:
+ {
+ Var rhs, lhs, ans;
+
+ rhs = POP();
+ lhs = POP();
+ ans.type = TYPE_INT;
+ ans.v.num = (op == OP_EQ
+ ? equality(rhs, lhs, 0)
+ : !equality(rhs, lhs, 0));
+ PUSH(ans);
+ free_var(rhs);
+ free_var(lhs);
+ }
+ break;
+
+ case OP_GT:
+ case OP_LT:
+ case OP_GE:
+ case OP_LE:
+ {
+ Var rhs, lhs, ans;
+ int comparison;
+
+ rhs = POP();
+ lhs = POP();
+ if ((lhs.type == TYPE_INT || lhs.type == TYPE_FLOAT)
+ && (rhs.type == TYPE_INT || rhs.type == TYPE_FLOAT)) {
+ ans = compare_numbers(lhs, rhs);
+ if (ans.type == TYPE_ERR) {
+ free_var(rhs);
+ free_var(lhs);
+ PUSH_ERROR(ans.v.err);
+ } else {
+ comparison = ans.v.num;
+ goto finish_comparison;
+ }
+ } else if (rhs.type != lhs.type || rhs.type == TYPE_LIST) {
+ free_var(rhs);
+ free_var(lhs);
+ PUSH_ERROR(E_TYPE);
+ } else {
+ switch (rhs.type) {
+ case TYPE_INT:
+ comparison = compare_integers(lhs.v.num, rhs.v.num);
break;
- case BP_NAME:
- if (rhs.type != TYPE_STR)
- err = E_TYPE;
- else if (!is_wizard(progr)
- && (is_user(obj.v.obj)
- || progr != db_object_owner(obj.v.obj)))
- err = E_PERM;
+ case TYPE_OBJ:
+ comparison = compare_integers(lhs.v.obj, rhs.v.obj);
break;
- case BP_OWNER:
- if (rhs.type != TYPE_OBJ)
- err = E_TYPE;
- else if (!is_wizard(progr))
- err = E_PERM;
+ case TYPE_ERR:
+ comparison = ((int) lhs.v.err) - ((int) rhs.v.err);
break;
- case BP_PROGRAMMER:
- case BP_WIZARD:
- if (!is_wizard(progr))
- err = E_PERM;
- else if (h.built_in == BP_WIZARD
- && !is_true(rhs) != !is_wizard(obj.v.obj)) {
- /* Notify only on changes in state; the !'s above
- * serve to canonicalize the truth values.
- */
- /* First make sure traceback will be accurate. */
- STORE_STATE_VARIABLES();
- oklog("%sWIZARDED: #%d by programmer #%d\n",
- is_wizard(obj.v.obj) ? "DE" : "",
- obj.v.obj, progr);
- print_error_backtrace(is_wizard(obj.v.obj)
- ? "Wizard bit unset."
- : "Wizard bit set.",
- output_to_log);
- }
+ case TYPE_STR:
+ comparison = mystrcasecmp(lhs.v.str, rhs.v.str);
break;
- case BP_R:
- case BP_W:
- case BP_F:
- if (progr != db_object_owner(obj.v.obj)
- && !is_wizard(progr))
- err = E_PERM;
+ default:
+ errlog("RUN: Impossible type in comparison: %d\n",
+ rhs.type);
+ comparison = 0;
+ }
+
+ finish_comparison:
+ ans.type = TYPE_INT;
+ switch (op) {
+ case OP_LT:
+ ans.v.num = (comparison < 0);
+ break;
+ case OP_LE:
+ ans.v.num = (comparison <= 0);
+ break;
+ case OP_GT:
+ ans.v.num = (comparison > 0);
break;
- case BP_LOCATION:
- case BP_CONTENTS:
- err = E_PERM;
+ case OP_GE:
+ ans.v.num = (comparison >= 0);
+ break;
+ default:
+ errlog("RUN: Imposible opcode in comparison: %d\n", op);
break;
- default:
- panic("Unknown built-in property in OP_PUT_PROP!");
}
+ PUSH(ans);
+ free_var(rhs);
+ free_var(lhs);
}
+ }
+ break;
- if (err == E_NONE) {
- db_set_property_value(h, var_ref(rhs));
- PUSH(rhs);
+ case OP_IN:
+ {
+ Var lhs, rhs, ans;
+
+ rhs = POP(); /* should be list */
+ lhs = POP(); /* lhs, any type */
+ if (rhs.type != TYPE_LIST) {
+ free_var(rhs);
+ free_var(lhs);
+ PUSH_ERROR(E_TYPE);
} else {
+ ans.type = TYPE_INT;
+ ans.v.num = ismember(lhs, rhs, 0);
+ PUSH(ans);
free_var(rhs);
- PUSH_ERROR(err);
+ free_var(lhs);
}
- free_var(propname);
- free_var(obj);
}
- }
- break;
-
- case OP_FORK:
- case OP_FORK_WITH_ID:
- {
- Var time;
- unsigned id = 0, f_index;
-
- time = POP();
- f_index = READ_BYTES(bv, bc.numbytes_fork);
- if (op == OP_FORK_WITH_ID)
- id = READ_BYTES(bv, bc.numbytes_var_name);
- if (time.type != TYPE_INT) {
- free_var(time);
- RAISE_ERROR(E_TYPE);
- } else if (time.v.num < 0) {
- free_var(time);
- RAISE_ERROR(E_INVARG);
- } else {
- Var *copied_rt_env;
- Var task_id;
-
- copied_rt_env = copy_rt_env(RUN_ACTIV.rt_env,
- RUN_ACTIV.prog->num_var_names);
- task_id = enqueue_forked_task(program_ref(RUN_ACTIV.prog),
- RUN_ACTIV, copied_rt_env,
- f_index, time.v.num);
- if (task_id.type == TYPE_ERR) {
- free_rt_env(copied_rt_env, RUN_ACTIV.prog->num_var_names);
- RAISE_ERROR(task_id.v.err);
- } else if (op == OP_FORK_WITH_ID) {
- free_var(RUN_ACTIV.rt_env[id]);
- RUN_ACTIV.rt_env[id] = task_id;
- free_var(copied_rt_env[id]);
- copied_rt_env[id] = task_id;
+ break;
+
+ case OP_MULT:
+ case OP_MINUS:
+ case OP_DIV:
+ case OP_MOD:
+ {
+ Var lhs, rhs, ans;
+
+ rhs = POP(); /* should be number */
+ lhs = POP(); /* should be number */
+ if ((lhs.type == TYPE_INT || lhs.type == TYPE_FLOAT)
+ && (rhs.type == TYPE_INT || rhs.type == TYPE_FLOAT)) {
+ switch (op) {
+ case OP_MULT:
+ ans = do_multiply(lhs, rhs);
+ break;
+ case OP_MINUS:
+ ans = do_subtract(lhs, rhs);
+ break;
+ case OP_DIV:
+ ans = do_divide(lhs, rhs);
+ break;
+ case OP_MOD:
+ ans = do_modulus(lhs, rhs);
+ break;
+ default:
+ errlog("RUN: Impossible opcode in arith ops: %d\n", op);
+ break;
+ }
+ } else {
+ ans.type = TYPE_ERR;
+ ans.v.err = E_TYPE;
}
+ free_var(rhs);
+ free_var(lhs);
+ if (ans.type == TYPE_ERR)
+ PUSH_ERROR(ans.v.err);
+ else
+ PUSH(ans);
}
- }
- break;
-
- case OP_CALL_VERB:
- {
- enum error err;
- Var args, verb, obj;
-
- args = POP(); /* args, should be list */
- verb = POP(); /* verbname, should be string */
- obj = POP(); /* objid, should be obj */
-
- if (args.type != TYPE_LIST || verb.type != TYPE_STR
- || obj.type != TYPE_OBJ)
- err = E_TYPE;
- else if (!valid(obj.v.obj))
- err = E_INVIND;
- else {
- STORE_STATE_VARIABLES();
- err = call_verb(obj.v.obj, verb.v.str, args, 0);
- /* if there is no error, RUN_ACTIV is now the CALLEE's.
- args will be consumed in the new rt_env */
- /* if there is an error, then RUN_ACTIV is unchanged, and
- args is not consumed in this case */
- LOAD_STATE_VARIABLES();
- }
- free_var(obj);
- free_var(verb);
+ break;
+
+ case OP_ADD:
+ {
+ Var rhs, lhs, ans;
+
+ rhs = POP();
+ lhs = POP();
+ if ((lhs.type == TYPE_INT || lhs.type == TYPE_FLOAT)
+ && (rhs.type == TYPE_INT || rhs.type == TYPE_FLOAT))
+ ans = do_add(lhs, rhs);
+ else if (lhs.type == TYPE_STR && rhs.type == TYPE_STR) {
+ char *str;
+
+ str = mymalloc((strlen(rhs.v.str) + strlen(lhs.v.str) + 1)
+ * sizeof(char), M_STRING);
+ sprintf(str, "%s%s", lhs.v.str, rhs.v.str);
+ ans.type = TYPE_STR;
+ ans.v.str = str;
+ } else {
+ ans.type = TYPE_ERR;
+ ans.v.err = E_TYPE;
+ }
+ free_var(rhs);
+ free_var(lhs);
- if (err != E_NONE) { /* there is an error, RUN_ACTIV unchanged,
- args must be freed */
- free_var(args);
- PUSH_ERROR(err);
- }
- }
- break;
-
- case OP_RETURN:
- case OP_RETURN0:
- case OP_DONE:
- {
- Var ret_val;
-
- if (op == OP_RETURN)
- ret_val = POP();
- else
- ret_val = zero;
-
- STORE_STATE_VARIABLES();
- if (unwind_stack(FIN_RETURN, ret_val, &outcome)) {
- if (result && outcome == OUTCOME_DONE)
- *result = ret_val;
+ if (ans.type == TYPE_ERR)
+ PUSH_ERROR(ans.v.err);
else
- free_var(ret_val);
- return outcome;
+ PUSH(ans);
}
- LOAD_STATE_VARIABLES();
- }
- break;
-
- case OP_BI_FUNC_CALL:
- {
- unsigned func_id;
- Var args;
-
- func_id = READ_BYTES(bv, 1); /* 1 == numbytes of func_id */
- args = POP(); /* should be list */
- if (args.type != TYPE_LIST) {
- free_var(args);
- PUSH_ERROR(E_TYPE);
- } else {
- package p;
-
- STORE_STATE_VARIABLES();
- p = call_bi_func(func_id, args, 1, RUN_ACTIV.progr, 0);
- LOAD_STATE_VARIABLES();
+ break;
+
+ case OP_AND:
+ case OP_OR:
+ {
+ Var lhs;
+ unsigned lab = READ_BYTES(bv, bc.numbytes_label);
+
+ lhs = TOP_RT_VALUE;
+ if ((op == OP_AND && !is_true(lhs))
+ || (op == OP_OR && is_true(lhs))) /* short-circuit */
+ JUMP(lab);
+ else {
+ free_var(POP());
+ }
+ }
+ break;
- switch (p.kind) {
- case BI_RETURN:
- PUSH(p.u.ret);
+ case OP_NOT:
+ {
+ Var arg, ans;
+
+ arg = POP();
+ ans.type = TYPE_INT;
+ ans.v.num = !is_true(arg);
+ PUSH(ans);
+ free_var(arg);
+ }
+ break;
+
+ case OP_UNARY_MINUS:
+ {
+ Var arg, ans;
+
+ arg = POP();
+ if (arg.type == TYPE_INT) {
+ ans.type = TYPE_INT;
+ ans.v.num = -arg.v.num;
+ } else if (arg.type == TYPE_FLOAT)
+ ans = new_float(-*arg.v.fnum);
+ else {
+ free_var(arg);
+ PUSH_ERROR(E_TYPE);
break;
- case BI_RAISE:
- if (RUN_ACTIV.debug) {
- if (raise_error(p, 0))
- return OUTCOME_ABORTED;
- else
- LOAD_STATE_VARIABLES();
+ }
+
+ PUSH(ans);
+ free_var(arg);
+ }
+ break;
+
+ case OP_REF:
+ {
+ Var index, list;
+
+ index = POP(); /* should be integer */
+ list = POP(); /* should be list or string */
+
+ if (index.type != TYPE_INT ||
+ (list.type != TYPE_LIST && list.type != TYPE_STR)) {
+ free_var(index);
+ free_var(list);
+ PUSH_ERROR(E_TYPE);
+ } else if (list.type == TYPE_LIST) {
+ if (index.v.num <= 0 || index.v.num > list.v.list[0].v.num) {
+ free_var(index);
+ free_var(list);
+ PUSH_ERROR(E_RANGE);
} else {
- PUSH(p.u.raise.code);
- free_str(p.u.raise.msg);
- free_var(p.u.raise.value);
+ PUSH(var_ref(list.v.list[index.v.num]));
+ free_var(index);
+ free_var(list);
}
- break;
- case BI_CALL:
- /* another activ has been pushed onto activ_stack */
- RUN_ACTIV.bi_func_id = func_id;
- RUN_ACTIV.bi_func_data = p.u.call.data;
- RUN_ACTIV.bi_func_pc = p.u.call.pc;
- break;
- case BI_SUSPEND:
- {
- enum error e = suspend_task(p);
-
- if (e == E_NONE)
- return OUTCOME_BLOCKED;
- else
- PUSH_ERROR(e);
+ } else { /* list.type == TYPE_STR */
+ if (index.v.num <= 0
+ || index.v.num > (int) strlen(list.v.str)) {
+ free_var(index);
+ free_var(list);
+ PUSH_ERROR(E_RANGE);
+ } else {
+ PUSH(strget(list, index));
+ free_var(index);
+ free_var(list);
}
- break;
}
}
- }
- break;
+ break;
- case OP_EXTENDED:
- {
- register enum Extended_Opcode eop = *bv;
- bv++;
- if (COUNT_EOP_TICK(eop))
- ticks_remaining--;
- switch (eop) {
- case EOP_RANGESET:
- {
- Var base, from, to, value;
-
- value = POP(); /* rhs value (list or string) */
- to = POP(); /* end of range (integer) */
- from = POP(); /* start of range (integer) */
- base = POP(); /* lhs (list or string) */
- /* base[from..to] = value */
- if (to.type != TYPE_INT || from.type != TYPE_INT
- || (base.type != TYPE_LIST && base.type != TYPE_STR)
- || (value.type != TYPE_LIST && value.type != TYPE_STR)
- || (base.type != value.type)) {
- free_var(base);
+ case OP_PUSH_REF:
+ {
+ Var index, list;
+
+ index = TOP_RT_VALUE;
+ list = NEXT_TOP_RT_VALUE;
+
+ if (index.type != TYPE_INT || list.type != TYPE_LIST) {
+ PUSH_ERROR(E_TYPE);
+ } else if (index.v.num <= 0 ||
+ index.v.num > list.v.list[0].v.num) {
+ PUSH_ERROR(E_RANGE);
+ } else
+ PUSH(var_ref(list.v.list[index.v.num]));
+ }
+ break;
+
+ case OP_RANGE_REF:
+ {
+ Var base, from, to;
+
+ to = POP(); /* should be integer */
+ from = POP(); /* should be integer */
+ base = POP(); /* should be list or string */
+
+ if ((base.type != TYPE_LIST && base.type != TYPE_STR)
+ || to.type != TYPE_INT || from.type != TYPE_INT) {
+ free_var(to);
+ free_var(from);
+ PUSH_ERROR(E_TYPE);
+ } else {
+ int len = (base.type == TYPE_STR ? strlen(base.v.str)
+ : base.v.list[0].v.num);
+ if (from.v.num <= to.v.num
+ && (from.v.num <= 0 || from.v.num > len
+ || to.v.num <= 0 || to.v.num > len)) {
free_var(to);
free_var(from);
- free_var(value);
- PUSH_ERROR(E_TYPE);
- } else if (rangeset_check(base.type == TYPE_STR
- ? strlen(base.v.str)
- : base.v.list[0].v.num,
- from.v.num, to.v.num)) {
free_var(base);
- free_var(to);
- free_var(from);
- free_var(value);
PUSH_ERROR(E_RANGE);
- } else if (base.type == TYPE_LIST)
- PUSH(listrangeset(base, from.v.num, to.v.num, value));
- else /* TYPE_STR */
- PUSH(strrangeset(base, from.v.num, to.v.num, value));
+ } else {
+ PUSH((base.type == TYPE_STR
+ ? substr(base, from.v.num, to.v.num)
+ : sublist(base, from.v.num, to.v.num)));
+ /* base freed by substr/sublist */
+ free_var(from);
+ free_var(to);
+ }
}
- break;
+ }
+ break;
- case EOP_LENGTH:
- {
- unsigned i = READ_BYTES(bv, bc.numbytes_stack);
- Var item, v;
+ case OP_G_PUT:
+ {
+ unsigned id = READ_BYTES(bv, bc.numbytes_var_name);
+ free_var(RUN_ACTIV.rt_env[id]);
+ RUN_ACTIV.rt_env[id] = var_ref(TOP_RT_VALUE);
+ }
+ break;
- v.type = TYPE_INT;
- item = RUN_ACTIV.base_rt_stack[i];
- if (item.type == TYPE_STR) {
- v.v.num = strlen(item.v.str);
- PUSH(v);
- } else if (item.type == TYPE_LIST) {
- v.v.num = item.v.list[0].v.num;
- PUSH(v);
- } else
- PUSH_ERROR(E_TYPE);
+ case OP_G_PUSH:
+ {
+ Var value;
+
+ value = RUN_ACTIV.rt_env[READ_BYTES(bv, bc.numbytes_var_name)];
+ if (value.type == TYPE_NONE)
+ PUSH_ERROR(E_VARNF);
+ else
+ PUSH_REF(value);
+ }
+ break;
+
+ case OP_GET_PROP:
+ {
+ Var propname, obj, prop;
+
+ propname = POP(); /* should be string */
+ obj = POP(); /* should be objid */
+ if (propname.type != TYPE_STR || obj.type != TYPE_OBJ) {
+ free_var(propname);
+ free_var(obj);
+ PUSH_ERROR(E_TYPE);
+ } else if (!valid(obj.v.obj)) {
+ free_var(propname);
+ free_var(obj);
+ PUSH_ERROR(E_INVIND);
+ } else {
+ db_prop_handle h;
+
+ h = db_find_property(obj.v.obj, propname.v.str, &prop);
+ if (!h.ptr)
+ PUSH_ERROR(E_PROPNF);
+ else if (h.built_in
+ ? bi_prop_protected(h.built_in, RUN_ACTIV.progr)
+ : !db_property_allows(h, RUN_ACTIV.progr, PF_READ))
+ PUSH_ERROR(E_PERM);
+ else if (h.built_in)
+ PUSH(prop); /* it's already freshly allocated */
+ else
+ PUSH_REF(prop);
+ free_var(propname);
+ free_var(obj);
}
- break;
+ }
+ break;
+
+ case OP_PUSH_GET_PROP:
+ {
+ Var propname, obj, prop;
+
+ propname = TOP_RT_VALUE;
+ obj = NEXT_TOP_RT_VALUE;
+ if (propname.type != TYPE_STR || obj.type != TYPE_OBJ)
+ PUSH_ERROR(E_TYPE);
+ else if (!valid(obj.v.obj))
+ PUSH_ERROR(E_INVIND);
+ else {
+ db_prop_handle h;
+
+ h = db_find_property(obj.v.obj, propname.v.str, &prop);
+ if (!h.ptr)
+ PUSH_ERROR(E_PROPNF);
+ else if (h.built_in
+ ? bi_prop_protected(h.built_in, RUN_ACTIV.progr)
+ : !db_property_allows(h, RUN_ACTIV.progr, PF_READ))
+ PUSH_ERROR(E_PERM);
+ else if (h.built_in)
+ PUSH(prop);
+ else
+ PUSH_REF(prop);
+ }
+ }
+ break;
- case EOP_EXP:
- {
- Var lhs, rhs, ans;
+ case OP_PUT_PROP:
+ {
+ Var obj, propname, rhs;
- rhs = POP();
- lhs = POP();
- ans = do_power(lhs, rhs);
- free_var(lhs);
+ rhs = POP(); /* any type */
+ propname = POP(); /* should be string */
+ obj = POP(); /* should be objid */
+ if (obj.type != TYPE_OBJ || propname.type != TYPE_STR) {
free_var(rhs);
- if (ans.type == TYPE_ERR)
- PUSH_ERROR(ans.v.err);
+ free_var(propname);
+ free_var(obj);
+ PUSH_ERROR(E_TYPE);
+ } else if (!valid(obj.v.obj)) {
+ free_var(rhs);
+ free_var(propname);
+ free_var(obj);
+ PUSH_ERROR(E_INVIND);
+ } else {
+ db_prop_handle h;
+ enum error err = E_NONE;
+ Objid progr = RUN_ACTIV.progr;
+
+ h = db_find_property(obj.v.obj, propname.v.str, 0);
+ if (!h.ptr)
+ err = E_PROPNF;
+ else {
+ switch (h.built_in) {
+ case BP_NONE: /* Not a built-in property */
+ if (!db_property_allows(h, progr, PF_WRITE))
+ err = E_PERM;
+ break;
+ case BP_NAME:
+ if (rhs.type != TYPE_STR)
+ err = E_TYPE;
+ else if (!is_wizard(progr)
+ && (is_user(obj.v.obj)
+ || progr != db_object_owner(obj.v.obj)))
+ err = E_PERM;
+ break;
+ case BP_OWNER:
+ if (rhs.type != TYPE_OBJ)
+ err = E_TYPE;
+ else if (!is_wizard(progr))
+ err = E_PERM;
+ break;
+ case BP_PROGRAMMER:
+ case BP_WIZARD:
+ if (!is_wizard(progr))
+ err = E_PERM;
+ else if (h.built_in == BP_WIZARD
+ && !is_true(rhs) != !is_wizard(obj.v.obj)) {
+ /* Notify only on changes in state; the !'s above
+ * serve to canonicalize the truth values.
+ */
+ /* First make sure traceback will be accurate. */
+ STORE_STATE_VARIABLES();
+ oklog("%sWIZARDED: #%d by programmer #%d\n",
+ is_wizard(obj.v.obj) ? "DE" : "",
+ obj.v.obj, progr);
+ print_error_backtrace(is_wizard(obj.v.obj)
+ ? "Wizard bit unset."
+ : "Wizard bit set.",
+ output_to_log);
+ }
+ break;
+ case BP_R:
+ case BP_W:
+ case BP_F:
+ if (progr != db_object_owner(obj.v.obj)
+ && !is_wizard(progr))
+ err = E_PERM;
+ break;
+ case BP_LOCATION:
+ case BP_CONTENTS:
+ err = E_PERM;
+ break;
+ default:
+ panic("Unknown built-in property in OP_PUT_PROP!");
+ }
+ }
+
+ if (err == E_NONE) {
+ db_set_property_value(h, var_ref(rhs));
+ PUSH(rhs);
+ } else {
+ free_var(rhs);
+ PUSH_ERROR(err);
+ }
+ free_var(propname);
+ free_var(obj);
+ }
+ }
+ break;
+
+ case OP_FORK:
+ case OP_FORK_WITH_ID:
+ {
+ Var time;
+ unsigned id = 0, f_index;
+
+ time = POP();
+ f_index = READ_BYTES(bv, bc.numbytes_fork);
+ if (op == OP_FORK_WITH_ID)
+ id = READ_BYTES(bv, bc.numbytes_var_name);
+ if (time.type != TYPE_INT) {
+ free_var(time);
+ RAISE_ERROR(E_TYPE);
+ } else if (time.v.num < 0) {
+ free_var(time);
+ RAISE_ERROR(E_INVARG);
+ } else {
+ Var *copied_rt_env;
+ Var task_id;
+
+ copied_rt_env = copy_rt_env(RUN_ACTIV.rt_env,
+ RUN_ACTIV.prog->num_var_names);
+ task_id = enqueue_forked_task(program_ref(RUN_ACTIV.prog),
+ RUN_ACTIV, copied_rt_env,
+ f_index, time.v.num);
+ if (task_id.type == TYPE_ERR) {
+ free_rt_env(copied_rt_env, RUN_ACTIV.prog->num_var_names);
+ RAISE_ERROR(task_id.v.err);
+ } else if (op == OP_FORK_WITH_ID) {
+ free_var(RUN_ACTIV.rt_env[id]);
+ RUN_ACTIV.rt_env[id] = task_id;
+ free_var(copied_rt_env[id]);
+ copied_rt_env[id] = task_id;
+ }
+ }
+ }
+ break;
+
+ case OP_CALL_VERB:
+ {
+ enum error err;
+ Var args, verb, obj;
+
+ args = POP(); /* args, should be list */
+ verb = POP(); /* verbname, should be string */
+ obj = POP(); /* objid, should be obj */
+
+ if (args.type != TYPE_LIST || verb.type != TYPE_STR
+ || obj.type != TYPE_OBJ)
+ err = E_TYPE;
+ else if (!valid(obj.v.obj))
+ err = E_INVIND;
+ else {
+ STORE_STATE_VARIABLES();
+ err = call_verb(obj.v.obj, verb.v.str, args, 0);
+ /* if there is no error, RUN_ACTIV is now the CALLEE's.
+ args will be consumed in the new rt_env */
+ /* if there is an error, then RUN_ACTIV is unchanged, and
+ args is not consumed in this case */
+ LOAD_STATE_VARIABLES();
+ }
+ free_var(obj);
+ free_var(verb);
+
+ if (err != E_NONE) { /* there is an error, RUN_ACTIV unchanged,
+ args must be freed */
+ free_var(args);
+ PUSH_ERROR(err);
+ }
+ }
+ break;
+
+ case OP_RETURN:
+ case OP_RETURN0:
+ case OP_DONE:
+ {
+ Var ret_val;
+
+ if (op == OP_RETURN)
+ ret_val = POP();
+ else
+ ret_val = zero;
+
+ STORE_STATE_VARIABLES();
+ if (unwind_stack(FIN_RETURN, ret_val, &outcome)) {
+ if (result && outcome == OUTCOME_DONE)
+ *result = ret_val;
else
- PUSH(ans);
+ free_var(ret_val);
+ return outcome;
}
- break;
+ LOAD_STATE_VARIABLES();
+ }
+ break;
+
+ case OP_BI_FUNC_CALL:
+ {
+ unsigned func_id;
+ Var args;
+
+ func_id = READ_BYTES(bv, 1); /* 1 == numbytes of func_id */
+ args = POP(); /* should be list */
+ if (args.type != TYPE_LIST) {
+ free_var(args);
+ PUSH_ERROR(E_TYPE);
+ } else {
+ package p;
+
+ STORE_STATE_VARIABLES();
+ p = call_bi_func(func_id, args, 1, RUN_ACTIV.progr, 0);
+ LOAD_STATE_VARIABLES();
- case EOP_SCATTER:
- {
- int nargs = READ_BYTES(bv, 1);
- int nreq = READ_BYTES(bv, 1);
- int rest = READ_BYTES(bv, 1);
- int have_rest = (rest > nargs ? 0 : 1);
- Var list;
- int len = 0, nopt_avail, nrest, i, offset;
- int done, where = 0;
- enum error e = E_NONE;
-
- list = TOP_RT_VALUE;
- if (list.type != TYPE_LIST)
- e = E_TYPE;
- else if ((len = list.v.list[0].v.num) < nreq
- || (!have_rest && len > nargs))
- e = E_ARGS;
-
- if (e != E_NONE) { /* skip rest of operands */
- free_var(POP()); /* replace list with error code */
- PUSH_ERROR(e);
- for (i = 1; i <= nargs; i++) {
- READ_BYTES(bv, bc.numbytes_var_name);
- READ_BYTES(bv, bc.numbytes_label);
+ switch (p.kind) {
+ case BI_RETURN:
+ PUSH(p.u.ret);
+ break;
+ case BI_RAISE:
+ if (RUN_ACTIV.debug) {
+ if (raise_error(p, 0))
+ return OUTCOME_ABORTED;
+ else
+ LOAD_STATE_VARIABLES();
+ } else {
+ PUSH(p.u.raise.code);
+ free_str(p.u.raise.msg);
+ free_var(p.u.raise.value);
}
- } else {
- nopt_avail = len - nreq;
- nrest = (have_rest && len >= nargs ? len - nargs + 1
- : 0);
- for (offset = 0, i = 1; i <= nargs; i++) {
- int id = READ_BYTES(bv, bc.numbytes_var_name);
- int label = READ_BYTES(bv, bc.numbytes_label);
-
- if (i == rest) { /* rest */
- free_var(RUN_ACTIV.rt_env[id]);
- RUN_ACTIV.rt_env[id] = sublist(var_ref(list),
- i,
- i + nrest - 1);
- offset += nrest - 1;
- } else if (label == 0) { /* required */
- free_var(RUN_ACTIV.rt_env[id]);
- RUN_ACTIV.rt_env[id] =
- var_ref(list.v.list[i + offset]);
- } else { /* optional */
- if (nopt_avail > 0) {
- nopt_avail--;
+ break;
+ case BI_CALL:
+ /* another activ has been pushed onto activ_stack */
+ RUN_ACTIV.bi_func_id = func_id;
+ RUN_ACTIV.bi_func_data = p.u.call.data;
+ RUN_ACTIV.bi_func_pc = p.u.call.pc;
+ break;
+ case BI_SUSPEND:
+ {
+ enum error e = suspend_task(p);
+
+ if (e == E_NONE)
+ return OUTCOME_BLOCKED;
+ else
+ PUSH_ERROR(e);
+ }
+ break;
+ }
+ }
+ }
+ break;
+
+ case OP_EXTENDED:
+ {
+ register enum Extended_Opcode eop = *bv;
+ bv++;
+ if (COUNT_EOP_TICK(eop))
+ ticks_remaining--;
+ switch (eop) {
+ case EOP_RANGESET:
+ {
+ Var base, from, to, value;
+
+ value = POP(); /* rhs value (list or string) */
+ to = POP(); /* end of range (integer) */
+ from = POP(); /* start of range (integer) */
+ base = POP(); /* lhs (list or string) */
+ /* base[from..to] = value */
+ if (to.type != TYPE_INT || from.type != TYPE_INT
+ || (base.type != TYPE_LIST && base.type != TYPE_STR)
+ || (value.type != TYPE_LIST && value.type != TYPE_STR)
+ || (base.type != value.type)) {
+ free_var(base);
+ free_var(to);
+ free_var(from);
+ free_var(value);
+ PUSH_ERROR(E_TYPE);
+ } else if (rangeset_check(base.type == TYPE_STR
+ ? strlen(base.v.str)
+ : base.v.list[0].v.num,
+ from.v.num, to.v.num)) {
+ free_var(base);
+ free_var(to);
+ free_var(from);
+ free_var(value);
+ PUSH_ERROR(E_RANGE);
+ } else if (base.type == TYPE_LIST)
+ PUSH(listrangeset(base, from.v.num, to.v.num, value));
+ else /* TYPE_STR */
+ PUSH(strrangeset(base, from.v.num, to.v.num, value));
+ }
+ break;
+
+ case EOP_LENGTH:
+ {
+ unsigned i = READ_BYTES(bv, bc.numbytes_stack);
+ Var item, v;
+
+ v.type = TYPE_INT;
+ item = RUN_ACTIV.base_rt_stack[i];
+ if (item.type == TYPE_STR) {
+ v.v.num = strlen(item.v.str);
+ PUSH(v);
+ } else if (item.type == TYPE_LIST) {
+ v.v.num = item.v.list[0].v.num;
+ PUSH(v);
+ } else
+ PUSH_ERROR(E_TYPE);
+ }
+ break;
+
+ case EOP_EXP:
+ {
+ Var lhs, rhs, ans;
+
+ rhs = POP();
+ lhs = POP();
+ ans = do_power(lhs, rhs);
+ free_var(lhs);
+ free_var(rhs);
+ if (ans.type == TYPE_ERR)
+ PUSH_ERROR(ans.v.err);
+ else
+ PUSH(ans);
+ }
+ break;
+
+ case EOP_SCATTER:
+ {
+ int nargs = READ_BYTES(bv, 1);
+ int nreq = READ_BYTES(bv, 1);
+ int rest = READ_BYTES(bv, 1);
+ int have_rest = (rest > nargs ? 0 : 1);
+ Var list;
+ int len = 0, nopt_avail, nrest, i, offset;
+ int done, where = 0;
+ enum error e = E_NONE;
+
+ list = TOP_RT_VALUE;
+ if (list.type != TYPE_LIST)
+ e = E_TYPE;
+ else if ((len = list.v.list[0].v.num) < nreq
+ || (!have_rest && len > nargs))
+ e = E_ARGS;
+
+ if (e != E_NONE) { /* skip rest of operands */
+ free_var(POP()); /* replace list with error code */
+ PUSH_ERROR(e);
+ for (i = 1; i <= nargs; i++) {
+ READ_BYTES(bv, bc.numbytes_var_name);
+ READ_BYTES(bv, bc.numbytes_label);
+ }
+ } else {
+ nopt_avail = len - nreq;
+ nrest = (have_rest && len >= nargs ? len - nargs + 1
+ : 0);
+ for (offset = 0, i = 1; i <= nargs; i++) {
+ int id = READ_BYTES(bv, bc.numbytes_var_name);
+ int label = READ_BYTES(bv, bc.numbytes_label);
+
+ if (i == rest) { /* rest */
+ free_var(RUN_ACTIV.rt_env[id]);
+ RUN_ACTIV.rt_env[id] = sublist(var_ref(list),
+ i,
+ i + nrest - 1);
+ offset += nrest - 1;
+ } else if (label == 0) { /* required */
free_var(RUN_ACTIV.rt_env[id]);
RUN_ACTIV.rt_env[id] =
var_ref(list.v.list[i + offset]);
- } else {
- offset--;
- if (where == 0 && label != 1)
- where = label;
+ } else { /* optional */
+ if (nopt_avail > 0) {
+ nopt_avail--;
+ free_var(RUN_ACTIV.rt_env[id]);
+ RUN_ACTIV.rt_env[id] =
+ var_ref(list.v.list[i + offset]);
+ } else {
+ offset--;
+ if (where == 0 && label != 1)
+ where = label;
+ }
}
}
}
+
+ done = READ_BYTES(bv, bc.numbytes_label);
+ if (where == 0)
+ JUMP(done);
+ else
+ JUMP(where);
}
+ break;
- done = READ_BYTES(bv, bc.numbytes_label);
- if (where == 0)
- JUMP(done);
- else
- JUMP(where);
- }
- break;
+ case EOP_PUSH_LABEL:
+ case EOP_TRY_FINALLY:
+ {
+ Var v;
- case EOP_PUSH_LABEL:
- case EOP_TRY_FINALLY:
- {
- Var v;
+ v.type = (eop == EOP_PUSH_LABEL ? TYPE_INT : TYPE_FINALLY);
+ v.v.num = READ_BYTES(bv, bc.numbytes_label);
+ PUSH(v);
+ }
+ break;
- v.type = (eop == EOP_PUSH_LABEL ? TYPE_INT : TYPE_FINALLY);
- v.v.num = READ_BYTES(bv, bc.numbytes_label);
- PUSH(v);
- }
- break;
+ case EOP_CATCH:
+ case EOP_TRY_EXCEPT:
+ {
+ Var v;
- case EOP_CATCH:
- case EOP_TRY_EXCEPT:
- {
- Var v;
+ v.type = TYPE_CATCH;
+ v.v.num = (eop == EOP_CATCH ? 1 : READ_BYTES(bv, 1));
+ PUSH(v);
+ }
+ break;
- v.type = TYPE_CATCH;
- v.v.num = (eop == EOP_CATCH ? 1 : READ_BYTES(bv, 1));
- PUSH(v);
- }
- break;
+ case EOP_END_CATCH:
+ case EOP_END_EXCEPT:
+ {
+ Var v, marker;
+ int i;
+
+ if (eop == EOP_END_CATCH)
+ v = POP();
+
+ marker = POP();
+ if (marker.type != TYPE_CATCH)
+ panic("Stack marker is not TYPE_CATCH!");
+ for (i = 0; i < marker.v.num; i++) {
+ (void) POP(); /* handler PC */
+ free_var(POP()); /* code list */
+ }
- case EOP_END_CATCH:
- case EOP_END_EXCEPT:
- {
- Var v, marker;
- int i;
+ if (eop == EOP_END_CATCH)
+ PUSH(v);
- if (eop == EOP_END_CATCH)
- v = POP();
+ JUMP(READ_BYTES(bv, bc.numbytes_label));
+ }
+ break;
- marker = POP();
- if (marker.type != TYPE_CATCH)
- panic("Stack marker is not TYPE_CATCH!");
- for (i = 0; i < marker.v.num; i++) {
- (void) POP(); /* handler PC */
- free_var(POP()); /* code list */
+ case EOP_END_FINALLY:
+ {
+ Var v, why;
+
+ v = POP();
+ if (v.type != TYPE_FINALLY)
+ panic("Stack marker is not TYPE_FINALLY!");
+ why.type = TYPE_INT;
+ why.v.num = FIN_FALL_THRU;
+ PUSH(why);
+ PUSH(zero);
}
+ break;
- if (eop == EOP_END_CATCH)
- PUSH(v);
+ case EOP_CONTINUE:
+ {
+ Var v, why;
- JUMP(READ_BYTES(bv, bc.numbytes_label));
- }
- break;
+ v = POP();
+ why = POP();
+ switch (why.type == TYPE_INT ? why.v.num : -1) {
+ case FIN_FALL_THRU:
+ /* Do nothing; normal case. */
+ break;
+ case FIN_EXIT:
+ case FIN_RAISE:
+ case FIN_RETURN:
+ case FIN_UNCAUGHT:
+ STORE_STATE_VARIABLES();
+ if (unwind_stack(why.v.num, v, &outcome))
+ return outcome;
+ LOAD_STATE_VARIABLES();
+ break;
+ default:
+ panic("Unknown FINALLY reason!");
+ }
+ }
+ break;
- case EOP_END_FINALLY:
- {
- Var v, why;
-
- v = POP();
- if (v.type != TYPE_FINALLY)
- panic("Stack marker is not TYPE_FINALLY!");
- why.type = TYPE_INT;
- why.v.num = FIN_FALL_THRU;
- PUSH(why);
- PUSH(zero);
- }
- break;
+ case EOP_WHILE_ID:
+ {
+ unsigned id = READ_BYTES(bv, bc.numbytes_var_name);
+ free_var(RUN_ACTIV.rt_env[id]);
+ RUN_ACTIV.rt_env[id] = var_ref(TOP_RT_VALUE);
+ }
+ goto do_test;
- case EOP_CONTINUE:
- {
- Var v, why;
+ case EOP_EXIT_ID:
+ READ_BYTES(bv, bc.numbytes_var_name); /* ignore id */
+ /* fall thru */
+ case EOP_EXIT:
+ {
+ Var v;
- v = POP();
- why = POP();
- switch (why.type == TYPE_INT ? why.v.num : -1) {
- case FIN_FALL_THRU:
- /* Do nothing; normal case. */
- break;
- case FIN_EXIT:
- case FIN_RAISE:
- case FIN_RETURN:
- case FIN_UNCAUGHT:
+ v = new_list(2);
+ v.v.list[1].type = TYPE_INT;
+ v.v.list[1].v.num = READ_BYTES(bv, bc.numbytes_stack);
+ v.v.list[2].type = TYPE_INT;
+ v.v.list[2].v.num = READ_BYTES(bv, bc.numbytes_label);
STORE_STATE_VARIABLES();
- if (unwind_stack(why.v.num, v, &outcome))
- return outcome;
+ unwind_stack(FIN_EXIT, v, 0);
LOAD_STATE_VARIABLES();
- break;
- default:
- panic("Unknown FINALLY reason!");
}
- }
- break;
+ break;
- case EOP_WHILE_ID:
- {
- unsigned id = READ_BYTES(bv, bc.numbytes_var_name);
- free_var(RUN_ACTIV.rt_env[id]);
- RUN_ACTIV.rt_env[id] = var_ref(TOP_RT_VALUE);
+ default:
+ panic("Unknown extended opcode!");
}
- goto do_test;
-
- case EOP_EXIT_ID:
- READ_BYTES(bv, bc.numbytes_var_name); /* ignore id */
- /* fall thru */
- case EOP_EXIT:
- {
- Var v;
-
- v = new_list(2);
- v.v.list[1].type = TYPE_INT;
- v.v.list[1].v.num = READ_BYTES(bv, bc.numbytes_stack);
- v.v.list[2].type = TYPE_INT;
- v.v.list[2].v.num = READ_BYTES(bv, bc.numbytes_label);
- STORE_STATE_VARIABLES();
- unwind_stack(FIN_EXIT, v, 0);
- LOAD_STATE_VARIABLES();
- }
- break;
-
- default:
- panic("Unknown extended opcode!");
}
- }
- break;
-
- default:
- if (IS_PUSH_n(op)) {
- Var value;
- value = RUN_ACTIV.rt_env[PUSH_n_INDEX(op)];
- if (value.type == TYPE_NONE) {
- free_var(value);
- PUSH_ERROR(E_VARNF);
+ break;
+
+ default:
+ if (IS_PUSH_n(op)) {
+ Var value;
+ value = RUN_ACTIV.rt_env[PUSH_n_INDEX(op)];
+ if (value.type == TYPE_NONE) {
+ free_var(value);
+ PUSH_ERROR(E_VARNF);
+ } else
+ PUSH_REF(value);
+ } else if (IS_PUT_n(op)) {
+ free_var(RUN_ACTIV.rt_env[PUT_n_INDEX(op)]);
+ RUN_ACTIV.rt_env[PUT_n_INDEX(op)] = var_ref(TOP_RT_VALUE);
+ } else if (IS_OPTIM_NUM_OPCODE(op)) {
+ Var value;
+ value.type = TYPE_INT;
+ value.v.num = OPCODE_TO_OPTIM_NUM(op);
+ PUSH(value);
} else
- PUSH_REF(value);
- } else if (IS_PUT_n(op)) {
- free_var(RUN_ACTIV.rt_env[PUT_n_INDEX(op)]);
- RUN_ACTIV.rt_env[PUT_n_INDEX(op)] = var_ref(TOP_RT_VALUE);
- } else if (IS_OPTIM_NUM_OPCODE(op)) {
- Var value;
- value.type = TYPE_INT;
- value.v.num = OPCODE_TO_OPTIM_NUM(op);
- PUSH(value);
- } else
- panic("Unknown opcode!");
- break;
+ panic("Unknown opcode!");
+ break;
+ }
}
- }
}
-
+
/**** manipulating data of task ****/
-static int timeouts_enabled = 1; /* set to 0 in debugger to disable
+static int timeouts_enabled = 1; /* set to 0 in debugger to disable
timeouts */
static void
@@ -1875,20 +1893,20 @@ setup_task_execution_limits(int seconds, int ticks)
ticks_remaining = (ticks < 100 ? 100 : ticks);
return task_alarm_id;
}
-
+
enum outcome
-run_interpreter(enum error e, Var *result, int is_fg, int do_db_tracebacks)
+run_interpreter(enum error e, Var * result, int is_fg, int do_db_tracebacks)
{
- enum outcome ret;
-
+ enum outcome ret;
+
setup_task_execution_limits(is_fg ? server_int_option("fg_seconds",
- DEFAULT_FG_SECONDS)
- : server_int_option("bg_seconds",
- DEFAULT_BG_SECONDS),
+ DEFAULT_FG_SECONDS)
+ : server_int_option("bg_seconds",
+ DEFAULT_BG_SECONDS),
is_fg ? server_int_option("fg_ticks",
- DEFAULT_FG_TICKS)
- : server_int_option("bg_ticks",
- DEFAULT_BG_TICKS));
+ DEFAULT_FG_TICKS)
+ : server_int_option("bg_ticks",
+ DEFAULT_BG_TICKS));
handler_verb_args = zero;
handler_verb_name = 0;
@@ -1898,35 +1916,34 @@ run_interpreter(enum error e, Var *result, int is_fg, int do_db_tracebacks)
task_timed_out = 0;
cancel_timer(task_alarm_id);
- if (ret == OUTCOME_ABORTED && handler_verb_name) {
- db_verb_handle h;
- Var args, handled, traceback;
- int i;
+ if (ret == OUTCOME_ABORTED && handler_verb_name) {
+ db_verb_handle h;
+ Var args, handled, traceback;
+ int i;
args = handler_verb_args;
h = db_find_callable_verb(SYSTEM_OBJECT, handler_verb_name);
- if (do_db_tracebacks && h.ptr) {
+ if (do_db_tracebacks && h.ptr) {
ret = do_server_verb_task(SYSTEM_OBJECT, handler_verb_name,
var_ref(handler_verb_args), h,
- activ_stack[0].player, "", &handled, 0);
+ activ_stack[0].player, "", &handled, 0);
if ((ret == OUTCOME_DONE && is_true(handled))
|| ret == OUTCOME_BLOCKED) {
/* Assume the in-DB code handled it */
free_var(args);
- return OUTCOME_ABORTED; /* original ret value */
+ return OUTCOME_ABORTED; /* original ret value */
}
}
i = args.v.list[0].v.num;
- traceback = args.v.list[i]; /* traceback is always the last argument */
+ traceback = args.v.list[i]; /* traceback is always the last argument */
for (i = 1; i <= traceback.v.list[0].v.num; i++)
notify(activ_stack[0].player, traceback.v.list[i].v.str);
free_var(args);
}
-
return ret;
}
-
+
Objid
caller()
{
@@ -1948,7 +1965,7 @@ check_activ_stack_size(int max)
static int
current_max_stack_size(void)
{
- int max = server_int_option("max_stack_depth", DEFAULT_MAX_STACK_DEPTH);
+ int max = server_int_option("max_stack_depth", DEFAULT_MAX_STACK_DEPTH);
if (max < DEFAULT_MAX_STACK_DEPTH)
max = DEFAULT_MAX_STACK_DEPTH;
@@ -1963,22 +1980,22 @@ current_max_stack_size(void)
/* procedure to create a new task */
static enum outcome
-do_task(Program *prog, int which_vector, Var *result, int do_db_tracebacks)
-{ /* which vector determines the vector for the root_activ.
- a forked task can also have which_vector == MAIN_VECTOR.
- this happens iff it is recovered from a read from disk,
- because in that case the forked statement is parsed as
- the main vector */
- int forked = (current_task_kind == TASK_FORKED);
+do_task(Program * prog, int which_vector, Var * result, int do_db_tracebacks)
+{ /* which vector determines the vector for the root_activ.
+ a forked task can also have which_vector == MAIN_VECTOR.
+ this happens iff it is recovered from a read from disk,
+ because in that case the forked statement is parsed as
+ the main vector */
+ int forked = (current_task_kind == TASK_FORKED);
RUN_ACTIV.prog = program_ref(prog);
- root_activ_vector = which_vector; /* main or which of the forked */
+ root_activ_vector = which_vector; /* main or which of the forked */
RUN_ACTIV.top_rt_stack = RUN_ACTIV.base_rt_stack
- = mymalloc ((which_vector == MAIN_VECTOR
- ? prog->main_vector.max_stack
- : prog->fork_vectors[which_vector].max_stack) *
- sizeof(Var), M_RT_STACK);
+ = mymalloc((which_vector == MAIN_VECTOR
+ ? prog->main_vector.max_stack
+ : prog->fork_vectors[which_vector].max_stack) *
+ sizeof(Var), M_RT_STACK);
RUN_ACTIV.pc = 0;
RUN_ACTIV.error_pc = 0;
@@ -1991,9 +2008,9 @@ do_task(Program *prog, int which_vector, Var *result, int do_db_tracebacks)
/* procedure to resume an old task */
enum outcome
-resume_from_previous_vm(vm the_vm, Var v, task_kind kind, Var *result)
+resume_from_previous_vm(vm the_vm, Var v, task_kind kind, Var * result)
{
- int i;
+ int i;
current_task_kind = kind;
check_activ_stack_size(the_vm->max_stack_size);
@@ -2013,30 +2030,30 @@ resume_from_previous_vm(vm the_vm, Var v, task_kind kind, Var *result)
return run_interpreter(E_NONE, result, 0, 1);
}
}
-
+
/*** external functions ***/
enum outcome
do_server_verb_task(Objid this, const char *verb, Var args, db_verb_handle h,
- Objid player, const char *argstr, Var *result,
+ Objid player, const char *argstr, Var * result,
int do_db_tracebacks)
{
return do_server_program_task(this, verb, args, db_verb_definer(h),
db_verb_names(h), db_verb_program(h),
db_verb_owner(h),
db_verb_flags(h) & VF_DEBUG,
- player, argstr, result, do_db_tracebacks);
+ player, argstr, result, do_db_tracebacks);
}
enum outcome
do_server_program_task(Objid this, const char *verb, Var args, Objid vloc,
- const char *verbname, Program *program, Objid progr,
+ const char *verbname, Program * program, Objid progr,
int debug, Objid player, const char *argstr,
- Var *result, int do_db_tracebacks)
+ Var * result, int do_db_tracebacks)
{
- Var *env;
-
+ Var *env;
+
current_task_kind = TASK_INPUT;
check_activ_stack_size(current_max_stack_size());
top_activ_stack = 0;
@@ -2066,10 +2083,10 @@ do_server_program_task(Objid this, const char *verb, Var args, Objid vloc,
}
enum outcome
-do_input_task(Objid user, Parsed_Command *pc, Objid this, db_verb_handle vh)
+do_input_task(Objid user, Parsed_Command * pc, Objid this, db_verb_handle vh)
{
- Program *prog = db_verb_program(vh);
- Var *env;
+ Program *prog = db_verb_program(vh);
+ Var *env;
current_task_kind = TASK_INPUT;
check_activ_stack_size(current_max_stack_size());
@@ -2100,30 +2117,30 @@ do_input_task(Objid user, Parsed_Command *pc, Objid this, db_verb_handle vh)
}
enum outcome
-do_forked_task(Program *prog, Var *rt_env, activation a, int f_id,
- Var *result)
-{
- current_task_kind = TASK_FORKED;
+do_forked_task(Program * prog, Var * rt_env, activation a, int f_id,
+ Var * result)
+{
+ current_task_kind = TASK_FORKED;
check_activ_stack_size(current_max_stack_size());
top_activ_stack = 0;
RUN_ACTIV = a;
RUN_ACTIV.rt_env = rt_env;
-
+
return do_task(prog, f_id, result, 1);
}
/* this is called from bf_eval to set up stack for an eval call */
int
-setup_activ_for_eval(Program *prog)
+setup_activ_for_eval(Program * prog)
{
Var *env;
if (!push_activation())
return 0;
-
+
RUN_ACTIV.prog = prog;
-
+
RUN_ACTIV.rt_env = env = new_rt_env(prog->num_var_names);
fill_in_rt_consts(env, prog->version);
set_rt_env_obj(env, SLOT_PLAYER, CALLER_ACTIV.player);
@@ -2137,7 +2154,7 @@ setup_activ_for_eval(Program *prog)
set_rt_env_str(env, SLOT_PREPSTR, str_dup(""));
set_rt_env_str(env, SLOT_VERB, str_dup(""));
set_rt_env_var(env, SLOT_ARGS, new_list(0));
-
+
RUN_ACTIV.this = NOTHING;
RUN_ACTIV.player = CALLER_ACTIV.player;
RUN_ACTIV.progr = CALLER_ACTIV.progr;
@@ -2145,13 +2162,13 @@ setup_activ_for_eval(Program *prog)
RUN_ACTIV.verb = str_dup("");
RUN_ACTIV.verbname = str_dup("Input to EVAL");
RUN_ACTIV.debug = 1;
- RUN_ACTIV.top_rt_stack = RUN_ACTIV.base_rt_stack
- = mymalloc (RUN_ACTIV.prog->main_vector.max_stack * sizeof(Var),
- M_RT_STACK);
+ RUN_ACTIV.top_rt_stack = RUN_ACTIV.base_rt_stack
+ = mymalloc(RUN_ACTIV.prog->main_vector.max_stack * sizeof(Var),
+ M_RT_STACK);
RUN_ACTIV.pc = 0;
RUN_ACTIV.error_pc = 0;
RUN_ACTIV.temp.type = TYPE_NONE;
-
+
return 1;
}
@@ -2164,20 +2181,20 @@ abort_running_task(void)
/**** built in functions ****/
struct cf_state {
- unsigned fnum;
- void *data;
+ unsigned fnum;
+ void *data;
};
static package
bf_call_function(Var arglist, Byte next, void *vdata, Objid progr)
{
- package p;
- unsigned fnum;
- struct cf_state *s;
+ package p;
+ unsigned fnum;
+ struct cf_state *s;
if (next == 1) { /* first call */
- const char *fname = arglist.v.list[1].v.str;
-
+ const char *fname = arglist.v.list[1].v.str;
+
fnum = number_func_by_name(fname);
if (fnum == FUNC_NOT_FOUND) {
p = make_raise_pack(E_INVARG, "Unknown built-in function",
@@ -2200,14 +2217,13 @@ bf_call_function(Var arglist, Byte next, void *vdata, Objid progr)
s->data = p.u.call.data;
p.u.call.data = s;
}
-
return p;
}
static void
bf_call_function_write(void *data)
{
- struct cf_state *s = data;
+ struct cf_state *s = data;
dbio_printf("bf_call_function data: fname = %s\n",
name_func_by_num(s->fnum));
@@ -2217,10 +2233,10 @@ bf_call_function_write(void *data)
static void *
bf_call_function_read(void)
{
- struct cf_state *s = alloc_data(sizeof(struct cf_state));
- const char *line = dbio_read_string();
- const char *hdr = "bf_call_function data: fname = ";
- int hlen = strlen(hdr);
+ struct cf_state *s = alloc_data(sizeof(struct cf_state));
+ const char *line = dbio_read_string();
+ const char *hdr = "bf_call_function data: fname = ";
+ int hlen = strlen(hdr);
if (!strncmp(line, hdr, hlen)) {
line += hlen;
@@ -2229,20 +2245,19 @@ bf_call_function_read(void)
else if (read_bi_func_data(s->fnum, &s->data, pc_for_bi_func_data()))
return s;
}
-
return 0;
}
static package
bf_raise(Var arglist, Byte next, void *vdata, Objid progr)
{
- package p;
- int nargs = arglist.v.list[0].v.num;
- Var code = var_ref(arglist.v.list[1]);
+ package p;
+ int nargs = arglist.v.list[0].v.num;
+ Var code = var_ref(arglist.v.list[1]);
const char *msg = (nargs >= 2
? str_ref(arglist.v.list[2].v.str)
: str_dup(value2str(code)));
- Var value;
+ Var value;
value = (nargs >= 3 ? var_ref(arglist.v.list[3]) : zero);
free_var(arglist);
@@ -2257,8 +2272,8 @@ bf_raise(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_suspend(Var arglist, Byte next, void *vdata, Objid progr)
{
- static int seconds;
- int nargs = arglist.v.list[0].v.num;
+ static int seconds;
+ int nargs = arglist.v.list[0].v.num;
if (nargs >= 1)
seconds = arglist.v.list[1].v.num;
@@ -2266,7 +2281,7 @@ bf_suspend(Var arglist, Byte next, void *vdata, Objid progr)
seconds = -1;
free_var(arglist);
- if (nargs >= 1 && seconds < 0)
+ if (nargs >= 1 && seconds < 0)
return make_error_pack(E_INVARG);
else
return make_suspend_pack(enqueue_suspended_task, &seconds);
@@ -2275,10 +2290,10 @@ bf_suspend(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_read(Var arglist, Byte next, void *vdata, Objid progr)
{
- int argc = arglist.v.list[0].v.num;
- static Objid connection;
- int non_blocking = (argc >= 2
- && is_true(arglist.v.list[2]));
+ int argc = arglist.v.list[0].v.num;
+ static Objid connection;
+ int non_blocking = (argc >= 2
+ && is_true(arglist.v.list[2]));
if (argc >= 1)
connection = arglist.v.list[1].v.obj;
@@ -2289,17 +2304,17 @@ bf_read(Var arglist, Byte next, void *vdata, Objid progr)
/* Permissions checking */
if (argc >= 1) {
if (!is_wizard(progr)
- && (!valid(connection)
- || progr != db_object_owner(connection)))
+ && (!valid(connection)
+ || progr != db_object_owner(connection)))
return make_error_pack(E_PERM);
} else {
if (!is_wizard(progr)
- || last_input_task_id(connection) != current_task_id)
+ || last_input_task_id(connection) != current_task_id)
return make_error_pack(E_PERM);
}
if (non_blocking) {
- Var r;
+ Var r;
r = read_input_now(connection);
if (r.type == TYPE_ERR)
@@ -2307,7 +2322,6 @@ bf_read(Var arglist, Byte next, void *vdata, Objid progr)
else
return make_var_pack(r);
}
-
return make_suspend_pack(make_reading_task, &connection);
}
@@ -2335,32 +2349,32 @@ static package
bf_pass(Var arglist, Byte next, void *vdata, Objid progr)
{
enum error e = call_verb(RUN_ACTIV.this, RUN_ACTIV.verb, arglist, 1);
-
- if (e == E_NONE)
+
+ if (e == E_NONE)
return tail_call_pack();
-
+
free_var(arglist);
return make_error_pack(e);
}
static package
-bf_set_task_perms(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (player) */
+bf_set_task_perms(Var arglist, Byte next, void *vdata, Objid progr)
+{ /* (player) */
/* warning!! modifies top activation */
Objid oid = arglist.v.list[1].v.obj;
-
+
free_var(arglist);
-
- if (progr != oid && !is_wizard(progr))
+
+ if (progr != oid && !is_wizard(progr))
return make_error_pack(E_PERM);
-
+
RUN_ACTIV.progr = oid;
return no_var_pack();
}
static package
-bf_caller_perms(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* () */
+bf_caller_perms(Var arglist, Byte next, void *vdata, Objid progr)
+{ /* () */
Var r;
r.type = TYPE_OBJ;
if (top_activ_stack == 0)
@@ -2374,24 +2388,24 @@ bf_caller_perms(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_callers(Var arglist, Byte next, void *vdata, Objid progr)
{
- int line_numbers_too = 0;
+ int line_numbers_too = 0;
if (arglist.v.list[0].v.num >= 1)
line_numbers_too = is_true(arglist.v.list[1]);
free_var(arglist);
return make_var_pack(make_stack_list(activ_stack, 0, top_activ_stack, 0,
- root_activ_vector, line_numbers_too));
+ root_activ_vector, line_numbers_too));
}
static package
bf_task_stack(Var arglist, Byte next, void *vdata, Objid progr)
{
- int nargs = arglist.v.list[0].v.num;
- int id = arglist.v.list[1].v.num;
- int line_numbers_too = (nargs >= 2 && is_true(arglist.v.list[2]));
- vm the_vm = find_suspended_task(id);
- Objid owner = (the_vm ? progr_of_cur_verb(the_vm) : NOTHING);
+ int nargs = arglist.v.list[0].v.num;
+ int id = arglist.v.list[1].v.num;
+ int line_numbers_too = (nargs >= 2 && is_true(arglist.v.list[2]));
+ vm the_vm = find_suspended_task(id);
+ Objid owner = (the_vm ? progr_of_cur_verb(the_vm) : NOTHING);
free_var(arglist);
if (!the_vm)
@@ -2405,7 +2419,7 @@ bf_task_stack(Var arglist, Byte next, void *vdata, Objid progr)
line_numbers_too));
}
-void
+void
register_execute(void)
{
register_function_with_read_write("call_function", 1, -1, bf_call_function,
@@ -2415,7 +2429,7 @@ register_execute(void)
register_function("raise", 1, 3, bf_raise, TYPE_ANY, TYPE_STR, TYPE_ANY);
register_function("suspend", 0, 1, bf_suspend, TYPE_INT);
register_function("read", 0, 2, bf_read, TYPE_OBJ, TYPE_ANY);
-
+
register_function("seconds_left", 0, 0, bf_seconds_left);
register_function("ticks_left", 0, 0, bf_ticks_left);
register_function("pass", 0, -1, bf_pass);
@@ -2424,8 +2438,8 @@ register_execute(void)
register_function("callers", 0, 1, bf_callers, TYPE_ANY);
register_function("task_stack", 1, 2, bf_task_stack, TYPE_INT, TYPE_ANY);
}
-
+
/**** storing to/loading from database ****/
void
@@ -2438,7 +2452,7 @@ write_activ_as_pi(activation a)
dbio_write_var(dummy);
dbio_printf("%d %d %d %d %d %d %d %d %d\n",
- a.this, -7, -8, a.player, -9, a.progr, a.vloc, -10, a.debug);
+ a.this, -7, -8, a.player, -9, a.progr, a.vloc, -10, a.debug);
dbio_write_string("No");
dbio_write_string("More");
dbio_write_string("Parse");
@@ -2448,11 +2462,11 @@ write_activ_as_pi(activation a)
}
int
-read_activ_as_pi(activation *a)
+read_activ_as_pi(activation * a)
{
- int dummy;
- char c;
-
+ int dummy;
+ char c;
+
free_var(dbio_read_var());
/* I use a `dummy' variable here and elsewhere instead of the `*'
@@ -2462,25 +2476,25 @@ read_activ_as_pi(activation *a)
* of `scanf'...
*/
if (dbio_scanf("%d %d %d %d %d %d %d %d %d%c",
- &a->this, &dummy, &dummy, &a->player, &dummy, &a->progr,
+ &a->this, &dummy, &dummy, &a->player, &dummy, &a->progr,
&a->vloc, &dummy, &a->debug, &c) != 10
|| c != '\n') {
errlog("READ_A: Bad numbers.\n");
return 0;
}
- dbio_read_string(); /* was argstr */
- dbio_read_string(); /* was dobjstr */
- dbio_read_string(); /* was iobjstr */
- dbio_read_string(); /* was prepstr */
+ dbio_read_string(); /* was argstr */
+ dbio_read_string(); /* was dobjstr */
+ dbio_read_string(); /* was iobjstr */
+ dbio_read_string(); /* was prepstr */
a->verb = str_dup(dbio_read_string());
a->verbname = str_dup(dbio_read_string());
return 1;
}
void
-write_rt_env(const char **var_names, Var *rt_env, unsigned size)
+write_rt_env(const char **var_names, Var * rt_env, unsigned size)
{
- unsigned i;
+ unsigned i;
dbio_printf("%d variables\n", size);
for (i = 0; i < size; i++) {
@@ -2490,15 +2504,14 @@ write_rt_env(const char **var_names, Var *rt_env, unsigned size)
}
int
-read_rt_env(const char ***old_names, Var **rt_env, int *old_size)
+read_rt_env(const char ***old_names, Var ** rt_env, int *old_size)
{
- unsigned i;
+ unsigned i;
if (dbio_scanf("%d variables\n", old_size) != 1) {
errlog("READ_RT_ENV: Bad count.\n");
return 0;
}
-
*old_names = (const char **) mymalloc((*old_size) * sizeof(char *),
M_NAMES);
*rt_env = new_rt_env(*old_size);
@@ -2511,8 +2524,8 @@ read_rt_env(const char ***old_names, Var **rt_env, int *old_size)
}
Var *
-reorder_rt_env(Var *old_rt_env, const char **old_names,
- int old_size, Program *prog)
+reorder_rt_env(Var * old_rt_env, const char **old_names,
+ int old_size, Program * prog)
{
/* reorder old_rt_env, which is aligned according to old_names,
to align to prog->var_names -- return the new rt_env
@@ -2524,13 +2537,13 @@ reorder_rt_env(Var *old_rt_env, const char **old_names,
unsigned i;
for (i = 0; i < size; i++) {
- int slot;
+ int slot;
for (slot = 0; slot < old_size; slot++) {
if (mystrcasecmp(old_names[slot], prog->var_names[i]) == 0)
break;
}
-
+
if (slot < old_size)
rt_env[i] = var_ref(old_rt_env[slot]);
}
@@ -2551,16 +2564,16 @@ write_activ(activation a)
dbio_printf("language version %u\n", a.prog->version);
dbio_write_program(a.prog);
write_rt_env(a.prog->var_names, a.rt_env, a.prog->num_var_names);
-
+
dbio_printf("%d rt_stack slots in use\n",
a.top_rt_stack - a.base_rt_stack);
- for (v = a.base_rt_stack; v != a.top_rt_stack; v++)
+ for (v = a.base_rt_stack; v != a.top_rt_stack; v++)
dbio_write_var(*v);
write_activ_as_pi(a);
dbio_write_var(a.temp);
-
+
dbio_printf("%u %u %u\n", a.pc, a.bi_func_pc, a.error_pc);
if (a.bi_func_pc != 0) {
dbio_write_string(name_func_by_num(a.bi_func_id));
@@ -2569,11 +2582,11 @@ write_activ(activation a)
}
static int
-check_pc_validity(Program *prog, int which_vector, unsigned pc)
+check_pc_validity(Program * prog, int which_vector, unsigned pc)
{
- Bytecodes *bc = (which_vector == -1
- ? &prog->main_vector
- : &prog->fork_vectors[which_vector]);
+ Bytecodes *bc = (which_vector == -1
+ ? &prog->main_vector
+ : &prog->fork_vectors[which_vector]);
/* Current insn must be call to verb or built-in function like eval(),
* move(), pass(), or suspend().
@@ -2584,16 +2597,16 @@ check_pc_validity(Program *prog, int which_vector, unsigned pc)
}
int
-read_activ(activation *a, int which_vector)
+read_activ(activation * a, int which_vector)
{
- DB_Version version;
- Var *old_rt_env;
+ DB_Version version;
+ Var *old_rt_env;
const char **old_names;
- int old_size, stack_in_use;
- unsigned i;
+ int old_size, stack_in_use;
+ unsigned i;
const char *func_name;
- int max_stack;
- char c;
+ int max_stack;
+ char c;
if (dbio_input_version < DBV_Float)
version = dbio_input_version;
@@ -2602,21 +2615,18 @@ read_activ(activation *a, int which_vector)
return 0;
} else if (!check_version(version)) {
errlog("READ_ACTIV: Unrecognized language version: %d\n",
- version);
+ version);
return 0;
}
-
if (!(a->prog = dbio_read_program(version,
0, (void *) "suspended task"))) {
errlog("READ_ACTIV: Malformed program\n");
return 0;
}
-
if (!read_rt_env(&old_names, &old_rt_env, &old_size)) {
errlog("READ_ACTIV: Malformed runtime environment\n");
return 0;
}
-
a->rt_env = reorder_rt_env(old_rt_env, old_names, old_size, a->prog);
max_stack = (which_vector == MAIN_VECTOR
@@ -2628,16 +2638,14 @@ read_activ(activation *a, int which_vector)
errlog("READ_ACTIV: Bad stack_in_use number\n");
return 0;
}
-
a->top_rt_stack = a->base_rt_stack;
- for (i = 0; i < stack_in_use; i++)
+ for (i = 0; i < stack_in_use; i++)
*(a->top_rt_stack++) = dbio_read_var();
-
+
if (!read_activ_as_pi(a)) {
errlog("READ_ACTIV: Bad activ.\n", stack_in_use);
return 0;
}
-
a->temp = dbio_read_var();
if (dbio_scanf("%u %u%c", &a->pc, &i, &c) != 3) {
@@ -2645,19 +2653,17 @@ read_activ(activation *a, int which_vector)
return 0;
}
a->bi_func_pc = i;
-
+
if (c == '\n')
a->error_pc = a->pc;
else if (dbio_scanf("%u\n", &a->error_pc) != 1) {
errlog("READ_ACTIV: no error pc.\n");
return 0;
}
-
if (!check_pc_validity(a->prog, which_vector, a->pc)) {
errlog("READ_ACTIV: Bad PC for suspended task.\n");
return 0;
}
-
if (a->bi_func_pc != 0) {
func_name = dbio_read_string();
a->bi_func_id = number_func_by_name(func_name);
@@ -2668,7 +2674,7 @@ read_activ(activation *a, int which_vector)
if (!read_bi_func_data(a->bi_func_id, &a->bi_func_data,
&a->bi_func_pc)) {
errlog("READ_ACTIV: Bad saved state for built-in function `%s'\n",
- func_name);
+ func_name);
return 0;
}
}
@@ -2679,9 +2685,12 @@ read_activ(activation *a, int which_vector)
char rcsid_execute[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:44:59 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:38 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:44:59 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.10 1996/04/19 01:24:40 pavel
* Added support for built-in functions making tail calls to MOO verbs and
* changed pass() to use the new feature. Added patches to allow generation
diff --git a/execute.h b/execute.h
index eb721d0..c9f51a7 100644
--- a/execute.h
+++ b/execute.h
@@ -26,49 +26,51 @@
#include "structures.h"
typedef struct {
- Program *prog;
- Var *rt_env; /* same length as prog.var_names */
- Var *base_rt_stack;
- Var *top_rt_stack; /* the stack has a fixed size equal to prog.num_var_names;
- top_rt_stack always points to next empty slot;
- there is no need to check bounds! */
- unsigned pc;
- unsigned error_pc;
- Byte bi_func_pc; /* next == 0 means a normal activation, which just
- returns to the previous activation (caller verb).
- next == 1, 2, 3, ... means the returned value should be
- fed to the bi_func (as specified in bi_func_id)
- together with the next code. */
- Byte bi_func_id;
- void *bi_func_data;
- Var temp; /* VM's temp register */
-
- /* verb information */
- Objid this;
- Objid player;
- Objid progr;
- Objid vloc;
- const char *verb;
- const char *verbname;
- int debug;
+ Program *prog;
+ Var *rt_env; /* same length as prog.var_names */
+ Var *base_rt_stack;
+ Var *top_rt_stack; /* the stack has a fixed size equal to prog.num_var_names;
+ top_rt_stack always points to next empty slot;
+ there is no need to check bounds! */
+ unsigned pc;
+ unsigned error_pc;
+ Byte bi_func_pc; /* next == 0 means a normal activation, which just
+ returns to the previous activation (caller verb).
+ next == 1, 2, 3, ... means the returned value should be
+ fed to the bi_func (as specified in bi_func_id)
+ together with the next code. */
+ Byte bi_func_id;
+ void *bi_func_data;
+ Var temp; /* VM's temp register */
+
+ /* verb information */
+ Objid this;
+ Objid player;
+ Objid progr;
+ Objid vloc;
+ const char *verb;
+ const char *verbname;
+ int debug;
} activation;
-extern void free_activation(activation a, char data_too);
+extern void free_activation(activation a, char data_too);
typedef struct {
- int task_id;
- activation *activ_stack;
- unsigned max_stack_size;
- unsigned top_activ_stack;
- int root_activ_vector;
- /* root_activ_vector == MAIN_VECTOR
- means root activation is main_vector */
- unsigned func_id;
+ int task_id;
+ activation *activ_stack;
+ unsigned max_stack_size;
+ unsigned top_activ_stack;
+ int root_activ_vector;
+ /* root_activ_vector == MAIN_VECTOR
+ means root activation is main_vector */
+ unsigned func_id;
} vmstruct;
-typedef vmstruct *vm;
+typedef vmstruct *vm;
-typedef enum { TASK_INPUT, TASK_FORKED, TASK_SUSPENDED } task_kind;
+typedef enum {
+ TASK_INPUT, TASK_FORKED, TASK_SUSPENDED
+} task_kind;
#define alloc_data(size) mymalloc(size, M_BI_FUNC_DATA)
#define free_data(ptr) myfree((void *) ptr, M_BI_FUNC_DATA)
@@ -78,7 +80,7 @@ typedef enum { TASK_INPUT, TASK_FORKED, TASK_SUSPENDED } task_kind;
extern enum error call_verb(Objid obj, const char *vname, Var args,
int do_pass);
-extern int setup_activ_for_eval(Program *prog);
+extern int setup_activ_for_eval(Program * prog);
enum outcome {
OUTCOME_DONE, /* Task ran successfully to completion */
@@ -86,49 +88,52 @@ enum outcome {
* by an uncaught error. */
OUTCOME_BLOCKED /* Task called a blocking built-in function. */
};
-
-extern enum outcome do_forked_task(Program *prog, Var *rt_env,
- activation a, int f_id, Var *result);
-extern enum outcome do_input_task(Objid user, Parsed_Command *pc,
- Objid this, db_verb_handle vh);
-extern enum outcome do_server_verb_task(Objid this, const char *verb,
- Var args, db_verb_handle h,
- Objid player, const char *argstr,
- Var *result, int do_db_tracebacks);
-extern enum outcome do_server_program_task(Objid this, const char *verb,
- Var args, Objid vloc,
- const char *verbname,
- Program *program, Objid progr,
- int debug, Objid player,
- const char *argstr,
- Var *result,
- int do_db_tracebacks);
-extern enum outcome resume_from_previous_vm(vm the_vm, Var value,
- task_kind tk, Var *result);
-
-extern int task_timed_out;
-extern void abort_running_task(void);
-extern void print_error_backtrace(const char *, void (*)(const char *));
-extern void output_to_log(const char *);
-extern Objid caller();
-
-extern void write_activ_as_pi(activation);
-extern int read_activ_as_pi(activation *);
-void write_rt_env(const char **var_names, Var *rt_env,
- unsigned size);
-int read_rt_env(const char ***old_names, Var **rt_env,
- int *old_size);
-Var *reorder_rt_env(Var *old_rt_env, const char **old_names,
- int old_size, Program *prog);
-extern void write_activ(activation a);
-extern int read_activ(activation *a, int which_vector);
-
+
+extern enum outcome do_forked_task(Program * prog, Var * rt_env,
+ activation a, int f_id, Var * result);
+extern enum outcome do_input_task(Objid user, Parsed_Command * pc,
+ Objid this, db_verb_handle vh);
+extern enum outcome do_server_verb_task(Objid this, const char *verb,
+ Var args, db_verb_handle h,
+ Objid player, const char *argstr,
+ Var * result, int do_db_tracebacks);
+extern enum outcome do_server_program_task(Objid this, const char *verb,
+ Var args, Objid vloc,
+ const char *verbname,
+ Program * program, Objid progr,
+ int debug, Objid player,
+ const char *argstr,
+ Var * result,
+ int do_db_tracebacks);
+extern enum outcome resume_from_previous_vm(vm the_vm, Var value,
+ task_kind tk, Var * result);
+
+extern int task_timed_out;
+extern void abort_running_task(void);
+extern void print_error_backtrace(const char *, void (*)(const char *));
+extern void output_to_log(const char *);
+extern Objid caller();
+
+extern void write_activ_as_pi(activation);
+extern int read_activ_as_pi(activation *);
+void write_rt_env(const char **var_names, Var * rt_env,
+ unsigned size);
+int read_rt_env(const char ***old_names, Var ** rt_env,
+ int *old_size);
+Var *reorder_rt_env(Var * old_rt_env, const char **old_names,
+ int old_size, Program * prog);
+extern void write_activ(activation a);
+extern int read_activ(activation * a, int which_vector);
+
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:03 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:40 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:03 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.5 1996/03/10 01:20:08 pavel
* Added new `caller()' entry point, for use by built-in fns. Release 1.8.0.
*
diff --git a/extensions.c b/extensions.c
index f1cd8c3..1d118f2 100644
--- a/extensions.c
+++ b/extensions.c
@@ -16,7 +16,7 @@
*****************************************************************************/
/* Extensions to the MOO server
- *
+
* This module contains some examples of how to extend the MOO server using
* some of the interfaces exported by various other modules. The examples are
* all commented out, since they're really not all that useful in general; they
@@ -47,22 +47,22 @@
typedef struct stdin_waiter {
struct stdin_waiter *next;
- vm the_vm;
+ vm the_vm;
} stdin_waiter;
-static stdin_waiter *waiters = 0;
+static stdin_waiter *waiters = 0;
static task_enum_action
stdin_enumerator(task_closure closure, void *data)
{
- stdin_waiter **ww;
+ stdin_waiter **ww;
for (ww = &waiters; *ww; ww = &((*ww)->next)) {
- stdin_waiter *w = *ww;
- const char *status = (w->the_vm->task_id & 1
- ? "stdin-waiting"
- : "stdin-weighting");
- task_enum_action tea = (*closure)(w->the_vm, status, data);
+ stdin_waiter *w = *ww;
+ const char *status = (w->the_vm->task_id & 1
+ ? "stdin-waiting"
+ : "stdin-weighting");
+ task_enum_action tea = (*closure) (w->the_vm, status, data);
if (tea == TEA_KILL) {
*ww = w->next;
@@ -70,7 +70,6 @@ stdin_enumerator(task_closure closure, void *data)
if (!waiters)
network_unregister_fd(0);
}
-
if (tea != TEA_CONTINUE)
return tea;
}
@@ -81,10 +80,10 @@ stdin_enumerator(task_closure closure, void *data)
static void
stdin_readable(int fd, void *data)
{
- char buffer[1000];
- int n;
- Var v;
- stdin_waiter *w;
+ char buffer[1000];
+ int n;
+ Var v;
+ stdin_waiter *w;
if (data != &waiters)
panic("STDIN_READABLE: Bad data!");
@@ -93,7 +92,6 @@ stdin_readable(int fd, void *data)
errlog("STDIN_READABLE: Nobody cares!\n");
return;
}
-
n = read(0, buffer, sizeof(buffer));
buffer[n] = '\0';
while (n)
@@ -119,7 +117,7 @@ stdin_readable(int fd, void *data)
static enum error
stdin_suspender(vm the_vm, void *data)
{
- stdin_waiter *w = data;
+ stdin_waiter *w = data;
if (!waiters)
network_register_fd(0, stdin_readable, 0, &waiters);
@@ -134,11 +132,11 @@ stdin_suspender(vm the_vm, void *data)
static package
bf_read_stdin(Var arglist, Byte next, void *vdata, Objid progr)
{
- stdin_waiter *w = mymalloc(sizeof(stdin_waiter), M_TASK);
+ stdin_waiter *w = mymalloc(sizeof(stdin_waiter), M_TASK);
return make_suspend_pack(stdin_suspender, w);
}
-#endif /* EXAMPLE */
+#endif /* EXAMPLE */
void
register_extensions()
@@ -152,9 +150,12 @@ register_extensions()
char rcsid_extensions[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:41 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 07:03:47 pavel
* Renamed err/logf() to errlog/oklog(). Updated copyright notice for 1996.
* Release 1.8.0beta1.
diff --git a/functions.c b/functions.c
index a6ce186..e5d942b 100644
--- a/functions.c
+++ b/functions.c
@@ -28,7 +28,7 @@
#include "streams.h"
#include "structures.h"
#include "unparse.h"
-#include "utils.h"
+#include "utils.h"
/*****************************************************************************
* This is the table of procedures that register MOO built-in functions. To
@@ -39,9 +39,10 @@
* files to the `CSRCS' line in the Makefile.
****************************************************************************/
-typedef void (*registry)();
+typedef void (*registry) ();
-static registry bi_function_registries[] = {
+static registry bi_function_registries[] =
+{
register_disassemble,
register_extensions,
register_execute,
@@ -60,24 +61,24 @@ void
register_bi_functions()
{
int loop, num_registries =
- sizeof(bi_function_registries) / sizeof(bi_function_registries[0]);
+ sizeof(bi_function_registries) / sizeof(bi_function_registries[0]);
for (loop = 0; loop < num_registries; loop++)
- (void) (*(bi_function_registries[loop]))();
+ (void) (*(bi_function_registries[loop])) ();
}
/*** register ***/
struct bft_entry {
- const char *name;
- const char *protect_str;
- const char *verb_str;
- int minargs;
- int maxargs;
- var_type *prototype;
- bf_type func;
- bf_read_type read;
- bf_write_type write;
+ const char *name;
+ const char *protect_str;
+ const char *verb_str;
+ int minargs;
+ int maxargs;
+ var_type *prototype;
+ bf_type func;
+ bf_read_type read;
+ bf_write_type write;
};
static struct bft_entry bf_table[MAX_FUNC];
@@ -87,9 +88,9 @@ static unsigned
register_common(const char *name, int minargs, int maxargs, bf_type func,
bf_read_type read, bf_write_type write, va_list args)
{
- int va_index;
- int num_arg_types = maxargs == -1 ? minargs : maxargs;
- static Stream *s = 0;
+ int va_index;
+ int num_arg_types = maxargs == -1 ? minargs : maxargs;
+ static Stream *s = 0;
if (!s)
s = new_stream(30);
@@ -98,7 +99,6 @@ register_common(const char *name, int minargs, int maxargs, bf_type func,
errlog("too many functions. %s cannot be registered.\n", name);
return 0;
}
-
bf_table[top_bf_table].name = str_dup(name);
stream_printf(s, "protect_%s", name);
bf_table[top_bf_table].protect_str = str_dup(reset_stream(s));
@@ -116,14 +116,14 @@ register_common(const char *name, int minargs, int maxargs, bf_type func,
else
bf_table[top_bf_table].prototype = 0;
for (va_index = 0; va_index < num_arg_types; va_index++)
- bf_table[top_bf_table].prototype[va_index] = va_arg(args, var_type);
+ bf_table[top_bf_table].prototype[va_index] = va_arg(args, var_type);
return top_bf_table++;
}
-
+
unsigned
register_function(const char *name, int minargs, int maxargs,
- bf_type func, ...)
+ bf_type func,...)
{
va_list args;
unsigned ans;
@@ -133,11 +133,11 @@ register_function(const char *name, int minargs, int maxargs,
va_end(args);
return ans;
}
-
+
unsigned
register_function_with_read_write(const char *name, int minargs, int maxargs,
bf_type func, bf_read_type read,
- bf_write_type write, ...)
+ bf_write_type write,...)
{
va_list args;
unsigned ans;
@@ -153,8 +153,8 @@ register_function_with_read_write(const char *name, int minargs, int maxargs,
static const char *func_not_found_msg = "no such function";
const char *
-name_func_by_num(unsigned n) /* used by unparse only */
-{
+name_func_by_num(unsigned n)
+{ /* used by unparse only */
if (n >= top_bf_table)
return func_not_found_msg;
else
@@ -162,8 +162,8 @@ name_func_by_num(unsigned n) /* used by unparse only */
}
unsigned
-number_func_by_name(const char *name) /* used by parser only */
-{
+number_func_by_name(const char *name)
+{ /* used by parser only */
unsigned i;
for (i = 0; i < top_bf_table; i++)
@@ -175,23 +175,22 @@ number_func_by_name(const char *name) /* used by parser only */
/*** calling built-in functions ***/
-package
-call_bi_func(unsigned n, Var arglist, Byte func_pc,
+package
+call_bi_func(unsigned n, Var arglist, Byte func_pc,
Objid progr, void *vdata)
/* requires arglist.type == TYPE_LIST
- call_bi_func will free arglist */
+ call_bi_func will free arglist */
{
- struct bft_entry *f;
+ struct bft_entry *f;
if (n >= top_bf_table) {
errlog("CALL_BI_FUNC: Unknown function number: %d\n", n);
free_var(arglist);
return no_var_pack();
}
-
f = bf_table + n;
- if (func_pc == 1) { /* check arg types and count *ONLY* for first entry */
+ if (func_pc == 1) { /* check arg types and count *ONLY* for first entry */
int k, max;
Var *args = arglist.v.list;
@@ -210,7 +209,6 @@ call_bi_func(unsigned n, Var arglist, Byte func_pc,
return make_error_pack(e == E_MAXREC ? e : E_PERM);
}
}
-
/*
* Check argument count
* (Can't always check in the compiler, because of @)
@@ -220,20 +218,19 @@ call_bi_func(unsigned n, Var arglist, Byte func_pc,
free_var(arglist);
return make_error_pack(E_ARGS);
}
-
/*
* Check argument types
*/
max = (f->maxargs == -1) ? f->minargs : args[0].v.num;
for (k = 0; k < max; k++) {
- var_type proto = f->prototype[k];
- var_type arg = args[k+1].type;
-
- if (! (proto == TYPE_ANY
- || (proto == TYPE_NUMERIC && (arg == TYPE_INT
- || arg == TYPE_FLOAT))
- || proto == arg)) {
+ var_type proto = f->prototype[k];
+ var_type arg = args[k + 1].type;
+
+ if (!(proto == TYPE_ANY
+ || (proto == TYPE_NUMERIC && (arg == TYPE_INT
+ || arg == TYPE_FLOAT))
+ || proto == arg)) {
free_var(arglist);
return make_error_pack(E_TYPE);
}
@@ -244,21 +241,20 @@ call_bi_func(unsigned n, Var arglist, Byte func_pc,
*/
return make_var_pack(arglist);
}
-
/*
* do the function
*/
- return (*(f->func))(arglist, func_pc, vdata, progr);
+ return (*(f->func)) (arglist, func_pc, vdata, progr);
/* f->func is responsible for freeing/using up arglist. */
}
void
write_bi_func_data(void *vdata, Byte f_id)
{
- if (f_id >= top_bf_table)
+ if (f_id >= top_bf_table)
errlog("WRITE_BI_FUNC_DATA: Unknown function number: %d\n", f_id);
else if (bf_table[f_id].write)
- (*(bf_table[f_id].write))(vdata);
+ (*(bf_table[f_id].write)) (vdata);
}
static Byte *pc_for_bi_func_data_being_read;
@@ -270,16 +266,16 @@ pc_for_bi_func_data(void)
}
int
-read_bi_func_data(Byte f_id, void **bi_func_state, Byte *bi_func_pc)
+read_bi_func_data(Byte f_id, void **bi_func_state, Byte * bi_func_pc)
{
pc_for_bi_func_data_being_read = bi_func_pc;
-
+
if (f_id >= top_bf_table) {
errlog("READ_BI_FUNC_DATA: Unknown function number: %d\n", f_id);
*bi_func_state = 0;
return 0;
} else if (bf_table[f_id].read) {
- *bi_func_state = (*(bf_table[f_id].read))();
+ *bi_func_state = (*(bf_table[f_id].read)) ();
if (*bi_func_state == 0) {
errlog("READ_BI_FUNC_DATA: Can't read data for %s()\n",
bf_table[f_id].name);
@@ -304,7 +300,7 @@ read_bi_func_data(Byte f_id, void **bi_func_state, Byte *bi_func_pc)
package
make_error_pack(enum error err)
-{
+{
return make_raise_pack(err, unparse_error(err), zero);
}
@@ -312,13 +308,13 @@ package
make_raise_pack(enum error err, const char *msg, Var value)
{
package p;
-
+
p.kind = BI_RAISE;
p.u.raise.code.type = TYPE_ERR;
p.u.raise.code.v.err = err;
p.u.raise.msg = str_dup(msg);
p.u.raise.value = value;
-
+
return p;
}
@@ -326,10 +322,10 @@ package
make_var_pack(Var v)
{
package p;
-
+
p.kind = BI_RETURN;
p.u.ret = v;
-
+
return p;
}
@@ -358,9 +354,9 @@ tail_call_pack(void)
}
package
-make_suspend_pack(enum error (*proc)(vm, void *), void *data)
+make_suspend_pack(enum error(*proc) (vm, void *), void *data)
{
- package p;
+ package p;
p.kind = BI_SUSPEND;
p.u.susp.proc = proc;
@@ -372,9 +368,9 @@ make_suspend_pack(enum error (*proc)(vm, void *), void *data)
static Var
function_description(int i)
{
- struct bft_entry entry;
- Var v, vv;
- int j, nargs;
+ struct bft_entry entry;
+ Var v, vv;
+ int j, nargs;
entry = bf_table[i];
v = new_list(4);
@@ -397,9 +393,9 @@ function_description(int i)
static package
bf_function_info(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
- int i;
-
+ Var r;
+ int i;
+
if (arglist.v.list[0].v.num == 1) {
i = number_func_by_name(arglist.v.list[1].v.str);
if (i == FUNC_NOT_FOUND) {
@@ -426,9 +422,12 @@ register_functions(void)
char rcsid_functions[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:42 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.6 1996/04/19 01:20:49 pavel
* Fixed bug in how $bf_FOO() verbs are called to override built-in functions.
* Added code to screen out the worst of the problems this bug could
diff --git a/functions.h b/functions.h
index fdc1821..7001853 100644
--- a/functions.h
+++ b/functions.h
@@ -26,28 +26,28 @@
#include "structures.h"
typedef struct {
- enum {
- BI_RETURN, /* Normal function return */
- BI_RAISE, /* Raising an error */
- BI_CALL, /* Making a nested verb call */
- BI_SUSPEND /* Suspending the current task */
- } kind;
- union {
- Var ret;
- struct {
- Var code;
- const char *msg;
- Var value;
- } raise;
- struct {
- Byte pc;
- void *data;
- } call;
- struct {
- enum error (*proc)(vm, void *);
- void *data;
- } susp;
- } u;
+ enum {
+ BI_RETURN, /* Normal function return */
+ BI_RAISE, /* Raising an error */
+ BI_CALL, /* Making a nested verb call */
+ BI_SUSPEND /* Suspending the current task */
+ } kind;
+ union {
+ Var ret;
+ struct {
+ Var code;
+ const char *msg;
+ Var value;
+ } raise;
+ struct {
+ Byte pc;
+ void *data;
+ } call;
+ struct {
+ enum error (*proc) (vm, void *);
+ void *data;
+ } susp;
+ } u;
} package;
void register_bi_functions();
@@ -60,9 +60,9 @@ package make_call_pack(Byte pc, void *data);
package tail_call_pack(void);
package make_suspend_pack(enum error (*)(vm, void *), void *);
-typedef package (*bf_type)(Var, Byte, void *, Objid);
-typedef void (*bf_write_type)(void *vdata);
-typedef void *(*bf_read_type)(void);
+typedef package(*bf_type) (Var, Byte, void *, Objid);
+typedef void (*bf_write_type) (void *vdata);
+typedef void *(*bf_read_type) (void);
#define MAX_FUNC 256
#define FUNC_NOT_FOUND MAX_FUNC
@@ -74,25 +74,28 @@ typedef void *(*bf_read_type)(void);
extern const char *name_func_by_num(unsigned);
extern unsigned number_func_by_name(const char *);
-extern unsigned register_function(const char *, int, int, bf_type, ...);
+extern unsigned register_function(const char *, int, int, bf_type,...);
extern unsigned register_function_with_read_write(const char *, int, int,
bf_type, bf_read_type,
- bf_write_type, ...);
+ bf_write_type,...);
-extern package call_bi_func(unsigned, Var, Byte, Objid, void *);
+extern package call_bi_func(unsigned, Var, Byte, Objid, void *);
/* will free or use Var arglist */
-extern void write_bi_func_data(void *vdata, Byte f_id);
-extern int read_bi_func_data(Byte f_id, void **bi_func_state,
- Byte *bi_func_pc);
-extern Byte *pc_for_bi_func_data(void);
+extern void write_bi_func_data(void *vdata, Byte f_id);
+extern int read_bi_func_data(Byte f_id, void **bi_func_state,
+ Byte * bi_func_pc);
+extern Byte *pc_for_bi_func_data(void);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:03 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:42 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:03 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/04/19 01:22:04 pavel
* Added tail_call_pack() declaration and patches to allow generation of the
* new warning in read_bi_func_data(). Release 1.8.0p4.
diff --git a/getpagesize.h b/getpagesize.h
index 758f4e9..294e661 100644
--- a/getpagesize.h
+++ b/getpagesize.h
@@ -32,19 +32,22 @@
#define getpagesize() NBPG * CLSIZE
#ifndef CLSIZE
#define CLSIZE 1
-#endif /* no CLSIZE */
-#else /* no NBPG */
+#endif /* no CLSIZE */
+#else /* no NBPG */
#define getpagesize() NBPC
-#endif /* no NBPG */
-#endif /* no EXEC_PAGESIZE */
+#endif /* no NBPG */
+#endif /* no EXEC_PAGESIZE */
-#endif /* not HAVE_GETPAGESIZE */
+#endif /* not HAVE_GETPAGESIZE */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:03 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:43 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:03 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:24:58 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/gnu-malloc.c b/gnu-malloc.c
index 526fbc1..9bf249f 100644
--- a/gnu-malloc.c
+++ b/gnu-malloc.c
@@ -18,114 +18,114 @@
/* dynamic memory allocation for GNU.
Copyright (C) 1985, 1987 Free Software Foundation, Inc.
- NO WARRANTY
-
- BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
-NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
-WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
-RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
-WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
-BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
-AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
-DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
-CORRECTION.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
-STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
-WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
-LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
-OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
-DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
-A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
-PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
-
- GENERAL PUBLIC LICENSE TO COPY
-
- 1. You may copy and distribute verbatim copies of this source file
-as you receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy a valid copyright notice "Copyright
-(C) 1985 Free Software Foundation, Inc."; and include following the
-copyright notice a verbatim copy of the above disclaimer of warranty
-and of this License. You may charge a distribution fee for the
-physical act of transferring a copy.
-
- 2. You may modify your copy or copies of this source file or
-any portion of it, and copy and distribute such modifications under
-the terms of Paragraph 1 above, provided that you also do the following:
-
- a) cause the modified files to carry prominent notices stating
- that you changed the files and the date of any change; and
-
- b) cause the whole of any work that you distribute or publish,
- that in whole or in part contains or is a derivative of this
- program or any part thereof, to be licensed at no charge to all
- third parties on terms identical to those contained in this
- License Agreement (except that you may choose to grant more extensive
- warranty protection to some or all third parties, at your option).
-
- c) You may charge a distribution fee for the physical act of
- transferring a copy, and you may at your option offer warranty
- protection in exchange for a fee.
-
-Mere aggregation of another unrelated program with this program (or its
-derivative) on a volume of a storage or distribution medium does not bring
-the other program under the scope of these terms.
-
- 3. You may copy and distribute this program (or a portion or derivative
-of it, under Paragraph 2) in object code or executable form under the terms
-of Paragraphs 1 and 2 above provided that you also do one of the following:
-
- a) accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of
- Paragraphs 1 and 2 above; or,
-
- b) accompany it with a written offer, valid for at least three
- years, to give any third party free (except for a nominal
- shipping charge) a complete machine-readable copy of the
- corresponding source code, to be distributed under the terms of
- Paragraphs 1 and 2 above; or,
-
- c) accompany it with the information you received as to where the
- corresponding source code may be obtained. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form alone.)
-
-For an executable file, complete source code means all the source code for
-all modules it contains; but, as a special exception, it need not include
-source code for modules which are standard libraries that accompany the
-operating system on which the executable file runs.
-
- 4. You may not copy, sublicense, distribute or transfer this program
-except as expressly provided under this License Agreement. Any attempt
-otherwise to copy, sublicense, distribute or transfer this program is void and
-your rights to use the program under this License agreement shall be
-automatically terminated. However, parties who have received computer
-software programs from you with this License Agreement will not have
-their licenses terminated so long as such parties remain in full compliance.
-
- 5. If you wish to incorporate parts of this program into other free
-programs whose distribution conditions are different, write to the Free
-Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
-worked out a simple rule that can be stated here, but we will often permit
-this. We will be guided by the two goals of preserving the free status of
-all derivatives of our free software and of promoting the sharing and reuse of
-software.
-
-
-In other words, you are welcome to use, share and improve this program.
-You are forbidden to forbid anyone else to use, share and improve
-what you give them. Help stamp out software-hoarding! */
+ NO WARRANTY
+
+ BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
+ NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
+ WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
+ RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
+ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
+ AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
+ DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
+ CORRECTION.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
+ STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
+ WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
+ LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
+ OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+ USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
+ DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
+ A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
+ PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
+
+ GENERAL PUBLIC LICENSE TO COPY
+
+ 1. You may copy and distribute verbatim copies of this source file
+ as you receive it, in any medium, provided that you conspicuously and
+ appropriately publish on each copy a valid copyright notice "Copyright
+ (C) 1985 Free Software Foundation, Inc."; and include following the
+ copyright notice a verbatim copy of the above disclaimer of warranty
+ and of this License. You may charge a distribution fee for the
+ physical act of transferring a copy.
+
+ 2. You may modify your copy or copies of this source file or
+ any portion of it, and copy and distribute such modifications under
+ the terms of Paragraph 1 above, provided that you also do the following:
+
+ a) cause the modified files to carry prominent notices stating
+ that you changed the files and the date of any change; and
+
+ b) cause the whole of any work that you distribute or publish,
+ that in whole or in part contains or is a derivative of this
+ program or any part thereof, to be licensed at no charge to all
+ third parties on terms identical to those contained in this
+ License Agreement (except that you may choose to grant more extensive
+ warranty protection to some or all third parties, at your option).
+
+ c) You may charge a distribution fee for the physical act of
+ transferring a copy, and you may at your option offer warranty
+ protection in exchange for a fee.
+
+ Mere aggregation of another unrelated program with this program (or its
+ derivative) on a volume of a storage or distribution medium does not bring
+ the other program under the scope of these terms.
+
+ 3. You may copy and distribute this program (or a portion or derivative
+ of it, under Paragraph 2) in object code or executable form under the terms
+ of Paragraphs 1 and 2 above provided that you also do one of the following:
+
+ a) accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of
+ Paragraphs 1 and 2 above; or,
+
+ b) accompany it with a written offer, valid for at least three
+ years, to give any third party free (except for a nominal
+ shipping charge) a complete machine-readable copy of the
+ corresponding source code, to be distributed under the terms of
+ Paragraphs 1 and 2 above; or,
+
+ c) accompany it with the information you received as to where the
+ corresponding source code may be obtained. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form alone.)
+
+ For an executable file, complete source code means all the source code for
+ all modules it contains; but, as a special exception, it need not include
+ source code for modules which are standard libraries that accompany the
+ operating system on which the executable file runs.
+
+ 4. You may not copy, sublicense, distribute or transfer this program
+ except as expressly provided under this License Agreement. Any attempt
+ otherwise to copy, sublicense, distribute or transfer this program is void and
+ your rights to use the program under this License agreement shall be
+ automatically terminated. However, parties who have received computer
+ software programs from you with this License Agreement will not have
+ their licenses terminated so long as such parties remain in full compliance.
+
+ 5. If you wish to incorporate parts of this program into other free
+ programs whose distribution conditions are different, write to the Free
+ Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
+ worked out a simple rule that can be stated here, but we will often permit
+ this. We will be guided by the two goals of preserving the free status of
+ all derivatives of our free software and of promoting the sharing and reuse of
+ software.
+
+
+ In other words, you are welcome to use, share and improve this program.
+ You are forbidden to forbid anyone else to use, share and improve
+ what you give them. Help stamp out software-hoarding! */
/*
* @(#)nmalloc.c 1 (Caltech) 2/21/82
*
- * U of M Modified: 20 Jun 1983 ACT: strange hacks for Emacs
+ * U of M Modified: 20 Jun 1983 ACT: strange hacks for Emacs
*
- * Nov 1983, Mike@BRL, Added support for 4.1C/4.2 BSD.
+ * Nov 1983, Mike@BRL, Added support for 4.1C/4.2 BSD.
*
* This is a very fast storage allocator. It allocates blocks of a small
* number of different sizes, and keeps free lists of each size. Blocks
@@ -152,10 +152,10 @@ what you give them. Help stamp out software-hoarding! */
* go in the first int of the block, and the returned pointer will point
* to the second.
*
-#ifdef MSTATS
+ #ifdef MSTATS
* nmalloc[i] is the difference between the number of mallocs and frees
* for a given block size.
-#endif MSTATS
+ #endif MSTATS
*/
#ifdef emacs
@@ -170,14 +170,14 @@ what you give them. Help stamp out software-hoarding! */
#ifndef USG
#define USG
#endif
-#endif /* not VMS */
-#else /* SIGTSTP */
+#endif /* not VMS */
+#else /* SIGTSTP */
#ifdef SIGIO
#define BSD4_2
-#endif /* SIGIO */
-#endif /* SIGTSTP */
+#endif /* SIGIO */
+#endif /* SIGTSTP */
-#endif /* not emacs */
+#endif /* not emacs */
/* Define getpagesize () if the system does not. */
#include "getpagesize.h"
@@ -185,13 +185,13 @@ what you give them. Help stamp out software-hoarding! */
#ifndef BSD4_2
#ifndef USG
#include <sys/vlimit.h> /* warn the user when near the end */
-#endif /* not USG */
-#else /* if BSD4_2 */
+#endif /* not USG */
+#else /* if BSD4_2 */
#include <sys/time.h>
#include <sys/resource.h>
-#endif /* BSD4_2 */
+#endif /* BSD4_2 */
-extern char *start_of_data ();
+extern char *start_of_data();
#ifdef BSD
#ifndef DATA_SEG_BITS
@@ -206,17 +206,17 @@ extern char *start_of_data ();
#define ISALLOC ((char) 0xf7) /* magic byte that implies allocation */
#define ISFREE ((char) 0x54) /* magic byte that implies free block */
/* this is for error checking only */
-#define ISMEMALIGN ((char) 0xd6) /* Stored before the value returned by
- memalign, with the rest of the word
- being the distance to the true
- beginning of the block. */
+#define ISMEMALIGN ((char) 0xd6) /* Stored before the value returned by
+ memalign, with the rest of the word
+ being the distance to the true
+ beginning of the block. */
extern char etext;
/* These two are for user programs to look at, when they are interested. */
-unsigned int malloc_sbrk_used; /* amount of data space used now */
-unsigned int malloc_sbrk_unused; /* amount more we can have */
+unsigned int malloc_sbrk_used; /* amount of data space used now */
+unsigned int malloc_sbrk_unused; /* amount more we can have */
/* start of data space; can be changed by calling init_malloc */
static char *data_space_start;
@@ -224,7 +224,7 @@ static char *data_space_start;
#ifdef MSTATS
static int nmalloc[30];
static int nmal, nfre;
-#endif /* MSTATS */
+#endif /* MSTATS */
/* If range checking is not turned on, all we have is a flag indicating
whether memory is allocated, an index in nextf[], and a size field; to
@@ -234,22 +234,22 @@ static int nmal, nfre;
is allocated, so the 'size' field is never used. */
struct mhead {
- char mh_alloc; /* ISALLOC or ISFREE */
- char mh_index; /* index in nextf[] */
+ char mh_alloc; /* ISALLOC or ISFREE */
+ char mh_index; /* index in nextf[] */
/* Remainder are valid only when block is allocated */
- unsigned short mh_size; /* size, if < 0x10000 */
+ unsigned short mh_size; /* size, if < 0x10000 */
#ifdef rcheck
- unsigned mh_nbytes; /* number of bytes allocated */
- int mh_magic4; /* should be == MAGIC4 */
-#endif /* rcheck */
+ unsigned mh_nbytes; /* number of bytes allocated */
+ int mh_magic4; /* should be == MAGIC4 */
+#endif /* rcheck */
};
/* Access free-list pointer of a block.
- It is stored at block + 4.
- This is not a field in the mhead structure
- because we want sizeof (struct mhead)
- to describe the overhead for when the block is in use,
- and we do not want the free-list pointer to count in that. */
+ It is stored at block + 4.
+ This is not a field in the mhead structure
+ because we want sizeof (struct mhead)
+ to describe the overhead for when the block is in use,
+ and we do not want the free-list pointer to count in that. */
#define CHAIN(a) \
(*(struct mhead **) (sizeof (char *) + (char *) (a)))
@@ -268,7 +268,7 @@ struct mhead {
#else
#define ASSERT(p)
#define EXTRA 0
-#endif /* rcheck */
+#endif /* rcheck */
/* nextf[i] is free list of blocks of size 2**(i + 3) */
@@ -283,10 +283,10 @@ static char busy[30];
static unsigned int lim_data;
/* Level number of warnings already issued.
- 0 -- no warnings issued.
- 1 -- 75% warning already issued.
- 2 -- 85% warning already issued.
-*/
+ 0 -- no warnings issued.
+ 1 -- 75% warning already issued.
+ 2 -- 85% warning already issued.
+ */
static int warnlevel;
/* Function to call to issue a warning;
@@ -298,532 +298,523 @@ static int gotpool;
char *_malloc_base;
-static void getpool ();
+static void getpool();
/* Cause reinitialization based on job parameters;
- also declare where the end of pure storage is. */
+ also declare where the end of pure storage is. */
void
-malloc_init (start, warnfun)
- char *start;
- void (*warnfun) ();
+malloc_init(start, warnfun)
+ char *start;
+ void (*warnfun) ();
{
- if (start)
- data_space_start = start;
- lim_data = 0;
- warnlevel = 0;
- warnfunction = warnfun;
+ if (start)
+ data_space_start = start;
+ lim_data = 0;
+ warnlevel = 0;
+ warnfunction = warnfun;
}
/* Return the maximum size to which MEM can be realloc'd
without actually requiring copying. */
int
-malloc_usable_size (mem)
- char *mem;
+malloc_usable_size(mem)
+ char *mem;
{
- int blocksize = 8 << (((struct mhead *) mem) - 1) -> mh_index;
+ int blocksize = 8 << (((struct mhead *) mem) - 1)->mh_index;
- return blocksize - sizeof (struct mhead) - EXTRA;
+ return blocksize - sizeof(struct mhead) - EXTRA;
}
void get_lim_data();
static void
-morecore (nu) /* ask system for more memory */
- register int nu; /* size index to get more of */
+morecore(nu) /* ask system for more memory */
+ register int nu; /* size index to get more of */
{
- char *sbrk ();
- register char *cp;
- register int nblks;
- register unsigned int siz;
+ char *sbrk();
+ register char *cp;
+ register int nblks;
+ register unsigned int siz;
#ifdef BSD
#ifndef BSD4_1
- int oldmask;
+ int oldmask;
- /* ?? There was a suggestion not to block SIGILL, somehow for GDB's sake. */
- oldmask = sigsetmask (-1);
+ /* ?? There was a suggestion not to block SIGILL, somehow for GDB's sake. */
+ oldmask = sigsetmask(-1);
#endif
#endif
- if (!data_space_start)
- {
- data_space_start = start_of_data ();
+ if (!data_space_start) {
+ data_space_start = start_of_data();
}
+ if (lim_data == 0)
+ get_lim_data();
+
+ /* On initial startup, get two blocks of each size up to 1k bytes */
+ if (!gotpool) {
+ getpool();
+ getpool();
+ gotpool = 1;
+ }
+ /* Find current end of memory and issue warning if getting near max */
- if (lim_data == 0)
- get_lim_data ();
-
- /* On initial startup, get two blocks of each size up to 1k bytes */
- if (!gotpool)
- { getpool (); getpool (); gotpool = 1; }
+#ifndef VMS
+ /* Maximum virtual memory on VMS is difficult to calculate since it
+ * depends on several dynmacially changing things. Also, alignment
+ * isn't that important. That is why much of the code here is ifdef'ed
+ * out for VMS systems.
+ */
+ cp = sbrk(0);
+ siz = cp - data_space_start;
+
+ if (warnfunction)
+ switch (warnlevel) {
+ case 0:
+ if (siz > (lim_data / 4) * 3) {
+ warnlevel++;
+ (*warnfunction) ("Warning: past 75% of memory limit");
+ }
+ break;
+ case 1:
+ if (siz > (lim_data / 20) * 17) {
+ warnlevel++;
+ (*warnfunction) ("Warning: past 85% of memory limit");
+ }
+ break;
+ case 2:
+ if (siz > (lim_data / 20) * 19) {
+ warnlevel++;
+ (*warnfunction) ("Warning: past 95% of memory limit");
+ }
+ break;
+ }
+ if ((int) cp & 0x3ff) /* land on 1K boundaries */
+ sbrk(1024 - ((int) cp & 0x3ff));
+#endif /* not VMS */
- /* Find current end of memory and issue warning if getting near max */
+ /* Take at least 2k, and figure out how many blocks of the desired size
+ we're about to get */
+ nblks = 1;
+ if ((siz = nu) < 8)
+ nblks = 1 << ((siz = 8) - nu);
-#ifndef VMS
- /* Maximum virtual memory on VMS is difficult to calculate since it
- * depends on several dynmacially changing things. Also, alignment
- * isn't that important. That is why much of the code here is ifdef'ed
- * out for VMS systems.
- */
- cp = sbrk (0);
- siz = cp - data_space_start;
-
- if (warnfunction)
- switch (warnlevel)
- {
- case 0:
- if (siz > (lim_data / 4) * 3)
- {
- warnlevel++;
- (*warnfunction) ("Warning: past 75% of memory limit");
- }
- break;
- case 1:
- if (siz > (lim_data / 20) * 17)
- {
- warnlevel++;
- (*warnfunction) ("Warning: past 85% of memory limit");
- }
- break;
- case 2:
- if (siz > (lim_data / 20) * 19)
- {
- warnlevel++;
- (*warnfunction) ("Warning: past 95% of memory limit");
- }
- break;
- }
-
- if ((int) cp & 0x3ff) /* land on 1K boundaries */
- sbrk (1024 - ((int) cp & 0x3ff));
-#endif /* not VMS */
-
- /* Take at least 2k, and figure out how many blocks of the desired size
- we're about to get */
- nblks = 1;
- if ((siz = nu) < 8)
- nblks = 1 << ((siz = 8) - nu);
-
- if ((cp = sbrk (1 << (siz + 3))) == (char *) -1)
- {
+ if ((cp = sbrk(1 << (siz + 3))) == (char *) -1) {
#ifdef BSD
#ifndef BSD4_1
- sigsetmask (oldmask);
+ sigsetmask(oldmask);
#endif
#endif
- return; /* no more room! */
+ return; /* no more room! */
}
- malloc_sbrk_used = siz;
- malloc_sbrk_unused = lim_data - siz;
+ malloc_sbrk_used = siz;
+ malloc_sbrk_unused = lim_data - siz;
#ifndef VMS
- if ((int) cp & 7)
- { /* shouldn't happen, but just in case */
- cp = (char *) (((int) cp + 8) & ~7);
- nblks--;
+ if ((int) cp & 7) { /* shouldn't happen, but just in case */
+ cp = (char *) (((int) cp + 8) & ~7);
+ nblks--;
}
-#endif /* not VMS */
-
- /* save new header and link the nblks blocks together */
- nextf[nu] = (struct mhead *) cp;
- siz = 1 << (nu + 3);
- while (1)
- {
- ((struct mhead *) cp) -> mh_alloc = ISFREE;
- ((struct mhead *) cp) -> mh_index = nu;
- if (--nblks <= 0) break;
- CHAIN ((struct mhead *) cp) = (struct mhead *) (cp + siz);
- cp += siz;
+#endif /* not VMS */
+
+ /* save new header and link the nblks blocks together */
+ nextf[nu] = (struct mhead *) cp;
+ siz = 1 << (nu + 3);
+ while (1) {
+ ((struct mhead *) cp)->mh_alloc = ISFREE;
+ ((struct mhead *) cp)->mh_index = nu;
+ if (--nblks <= 0)
+ break;
+ CHAIN((struct mhead *) cp) = (struct mhead *) (cp + siz);
+ cp += siz;
}
- CHAIN ((struct mhead *) cp) = 0;
+ CHAIN((struct mhead *) cp) = 0;
#ifdef BSD
#ifndef BSD4_1
- sigsetmask (oldmask);
+ sigsetmask(oldmask);
#endif
#endif
}
static void
-getpool ()
+getpool()
{
- register int nu;
- char * sbrk ();
- register char *cp = sbrk (0);
-
- if ((int) cp & 0x3ff) /* land on 1K boundaries */
- sbrk (1024 - ((int) cp & 0x3ff));
-
- /* Record address of start of space allocated by malloc. */
- if (_malloc_base == 0)
- _malloc_base = cp;
-
- /* Get 2k of storage */
-
- cp = sbrk (04000);
- if (cp == (char *) -1)
- return;
-
- /* Divide it into an initial 8-word block
- plus one block of size 2**nu for nu = 3 ... 10. */
-
- CHAIN (cp) = nextf[0];
- nextf[0] = (struct mhead *) cp;
- ((struct mhead *) cp) -> mh_alloc = ISFREE;
- ((struct mhead *) cp) -> mh_index = 0;
- cp += 8;
-
- for (nu = 0; nu < 7; nu++)
- {
- CHAIN (cp) = nextf[nu];
- nextf[nu] = (struct mhead *) cp;
- ((struct mhead *) cp) -> mh_alloc = ISFREE;
- ((struct mhead *) cp) -> mh_index = nu;
- cp += 8 << nu;
+ register int nu;
+ char *sbrk();
+ register char *cp = sbrk(0);
+
+ if ((int) cp & 0x3ff) /* land on 1K boundaries */
+ sbrk(1024 - ((int) cp & 0x3ff));
+
+ /* Record address of start of space allocated by malloc. */
+ if (_malloc_base == 0)
+ _malloc_base = cp;
+
+ /* Get 2k of storage */
+
+ cp = sbrk(04000);
+ if (cp == (char *) -1)
+ return;
+
+ /* Divide it into an initial 8-word block
+ plus one block of size 2**nu for nu = 3 ... 10. */
+
+ CHAIN(cp) = nextf[0];
+ nextf[0] = (struct mhead *) cp;
+ ((struct mhead *) cp)->mh_alloc = ISFREE;
+ ((struct mhead *) cp)->mh_index = 0;
+ cp += 8;
+
+ for (nu = 0; nu < 7; nu++) {
+ CHAIN(cp) = nextf[nu];
+ nextf[nu] = (struct mhead *) cp;
+ ((struct mhead *) cp)->mh_alloc = ISFREE;
+ ((struct mhead *) cp)->mh_index = nu;
+ cp += 8 << nu;
}
}
char *
-malloc (n) /* get a block */
- unsigned n;
+malloc(n) /* get a block */
+ unsigned n;
{
- register struct mhead *p;
- register unsigned int nbytes;
- register int nunits = 0;
-
- /* Figure out how many bytes are required, rounding up to the nearest
- multiple of 8, then figure out which nestf[] area to use.
- Both the beginning of the header and the beginning of the
- block should be on an eight byte boundary. */
- nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
- {
- register unsigned int shiftr = (nbytes - 1) >> 2;
-
- while (shiftr >>= 1)
- nunits++;
- }
-
- /* In case this is reentrant use of malloc from signal handler,
- pick a block size that no other malloc level is currently
- trying to allocate. That's the easiest harmless way not to
- interfere with the other level of execution. */
- while (busy[nunits]) nunits++;
- busy[nunits] = 1;
-
- /* If there are no blocks of the appropriate size, go get some */
- /* COULD SPLIT UP A LARGER BLOCK HERE ... ACT */
- if (nextf[nunits] == 0)
- morecore (nunits);
-
- /* Get one block off the list, and set the new list head */
- if ((p = nextf[nunits]) == 0)
+ register struct mhead *p;
+ register unsigned int nbytes;
+ register int nunits = 0;
+
+ /* Figure out how many bytes are required, rounding up to the nearest
+ multiple of 8, then figure out which nestf[] area to use.
+ Both the beginning of the header and the beginning of the
+ block should be on an eight byte boundary. */
+ nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
{
- busy[nunits] = 0;
- return 0;
+ register unsigned int shiftr = (nbytes - 1) >> 2;
+
+ while (shiftr >>= 1)
+ nunits++;
}
- nextf[nunits] = CHAIN (p);
- busy[nunits] = 0;
- /* Check for free block clobbered */
- /* If not for this check, we would gobble a clobbered free chain ptr */
- /* and bomb out on the NEXT allocate of this size block */
- if (p -> mh_alloc != ISFREE || p -> mh_index != nunits)
- botch ("block on free list clobbered");
+ /* In case this is reentrant use of malloc from signal handler,
+ pick a block size that no other malloc level is currently
+ trying to allocate. That's the easiest harmless way not to
+ interfere with the other level of execution. */
+ while (busy[nunits])
+ nunits++;
+ busy[nunits] = 1;
+
+ /* If there are no blocks of the appropriate size, go get some */
+ /* COULD SPLIT UP A LARGER BLOCK HERE ... ACT */
+ if (nextf[nunits] == 0)
+ morecore(nunits);
- /* Fill in the info, and if range checking, set up the magic numbers */
- p -> mh_alloc = ISALLOC;
+ /* Get one block off the list, and set the new list head */
+ if ((p = nextf[nunits]) == 0) {
+ busy[nunits] = 0;
+ return 0;
+ }
+ nextf[nunits] = CHAIN(p);
+ busy[nunits] = 0;
+
+ /* Check for free block clobbered */
+ /* If not for this check, we would gobble a clobbered free chain ptr */
+ /* and bomb out on the NEXT allocate of this size block */
+ if (p->mh_alloc != ISFREE || p->mh_index != nunits)
+ botch("block on free list clobbered");
+
+ /* Fill in the info, and if range checking, set up the magic numbers */
+ p->mh_alloc = ISALLOC;
#ifdef rcheck
- p -> mh_nbytes = n;
- p -> mh_magic4 = MAGIC4;
- {
- /* Get the location n after the beginning of the user's space. */
- register char *m = (char *) p + ((sizeof *p + 7) & ~7) + n;
-
- *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1;
- }
-#else /* not rcheck */
- p -> mh_size = n;
-#endif /* not rcheck */
+ p->mh_nbytes = n;
+ p->mh_magic4 = MAGIC4;
+ {
+ /* Get the location n after the beginning of the user's space. */
+ register char *m = (char *) p + ((sizeof *p + 7) & ~7) + n;
+
+ *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1;
+ }
+#else /* not rcheck */
+ p->mh_size = n;
+#endif /* not rcheck */
#ifdef MSTATS
- nmalloc[nunits]++;
- nmal++;
-#endif /* MSTATS */
- return (char *) p + ((sizeof *p + 7) & ~7);
+ nmalloc[nunits]++;
+ nmal++;
+#endif /* MSTATS */
+ return (char *) p + ((sizeof *p + 7) & ~7);
}
void
-free (mem)
- char *mem;
+free(mem)
+ char *mem;
{
- register struct mhead *p;
- {
- register char *ap = mem;
+ register struct mhead *p;
+ {
+ register char *ap = mem;
- if (ap == 0)
- return;
+ if (ap == 0)
+ return;
- p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7));
- if (p -> mh_alloc == ISMEMALIGN)
- {
- ap -= p->mh_size;
p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7));
- }
+ if (p->mh_alloc == ISMEMALIGN) {
+ ap -= p->mh_size;
+ p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7));
+ }
+ if (p->mh_alloc != ISALLOC) {
+ if (p->mh_alloc == ISFREE)
+ botch("free: Called with already freed block argument\n");
+ else
+ botch("free: Called with bad argument\n");
+ }
+#ifdef rcheck
+ ASSERT(p->mh_magic4 == MAGIC4);
+ ap += p->mh_nbytes;
+ ASSERT(*ap++ == MAGIC1);
+ ASSERT(*ap++ == MAGIC1);
+ ASSERT(*ap++ == MAGIC1);
+ ASSERT(*ap == MAGIC1);
+#endif /* rcheck */
+ }
+ {
+ register int nunits = p->mh_index;
- if (p -> mh_alloc != ISALLOC)
- {
- if (p -> mh_alloc == ISFREE)
- botch ("free: Called with already freed block argument\n");
- else
- botch ("free: Called with bad argument\n");
- }
+ ASSERT(nunits <= 29);
+ p->mh_alloc = ISFREE;
-#ifdef rcheck
- ASSERT (p -> mh_magic4 == MAGIC4);
- ap += p -> mh_nbytes;
- ASSERT (*ap++ == MAGIC1); ASSERT (*ap++ == MAGIC1);
- ASSERT (*ap++ == MAGIC1); ASSERT (*ap == MAGIC1);
-#endif /* rcheck */
- }
- {
- register int nunits = p -> mh_index;
-
- ASSERT (nunits <= 29);
- p -> mh_alloc = ISFREE;
-
- /* Protect against signal handlers calling malloc. */
- busy[nunits] = 1;
- /* Put this block on the free list. */
- CHAIN (p) = nextf[nunits];
- nextf[nunits] = p;
- busy[nunits] = 0;
+ /* Protect against signal handlers calling malloc. */
+ busy[nunits] = 1;
+ /* Put this block on the free list. */
+ CHAIN(p) = nextf[nunits];
+ nextf[nunits] = p;
+ busy[nunits] = 0;
#ifdef MSTATS
- nmalloc[nunits]--;
- nfre++;
-#endif /* MSTATS */
- }
+ nmalloc[nunits]--;
+ nfre++;
+#endif /* MSTATS */
+ }
}
char *
-realloc (mem, n)
- char *mem;
- register unsigned n;
+realloc(mem, n)
+ char *mem;
+ register unsigned n;
{
- register struct mhead *p;
- register unsigned int tocopy;
- register unsigned int nbytes;
- register int nunits;
-
- if (mem == 0)
- return malloc (n);
- p = (struct mhead *) (mem - ((sizeof *p + 7) & ~7));
- nunits = p -> mh_index;
- ASSERT (p -> mh_alloc == ISALLOC);
+ register struct mhead *p;
+ register unsigned int tocopy;
+ register unsigned int nbytes;
+ register int nunits;
+
+ if (mem == 0)
+ return malloc(n);
+ p = (struct mhead *) (mem - ((sizeof *p + 7) & ~7));
+ nunits = p->mh_index;
+ ASSERT(p->mh_alloc == ISALLOC);
#ifdef rcheck
- ASSERT (p -> mh_magic4 == MAGIC4);
- {
- register char *m = mem + (tocopy = p -> mh_nbytes);
- ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1);
- ASSERT (*m++ == MAGIC1); ASSERT (*m == MAGIC1);
- }
-#else /* not rcheck */
- if (p -> mh_index >= 13)
- tocopy = (1 << (p -> mh_index + 3)) - ((sizeof *p + 7) & ~7);
- else
- tocopy = p -> mh_size;
-#endif /* not rcheck */
-
- /* See if desired size rounds to same power of 2 as actual size. */
- nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
-
- /* If ok, use the same block, just marking its size as changed. */
- if (nbytes > (4 << nunits) && nbytes <= (8 << nunits))
+ ASSERT(p->mh_magic4 == MAGIC4);
{
+ register char *m = mem + (tocopy = p->mh_nbytes);
+ ASSERT(*m++ == MAGIC1);
+ ASSERT(*m++ == MAGIC1);
+ ASSERT(*m++ == MAGIC1);
+ ASSERT(*m == MAGIC1);
+ }
+#else /* not rcheck */
+ if (p->mh_index >= 13)
+ tocopy = (1 << (p->mh_index + 3)) - ((sizeof *p + 7) & ~7);
+ else
+ tocopy = p->mh_size;
+#endif /* not rcheck */
+
+ /* See if desired size rounds to same power of 2 as actual size. */
+ nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
+
+ /* If ok, use the same block, just marking its size as changed. */
+ if (nbytes > (4 << nunits) && nbytes <= (8 << nunits)) {
#ifdef rcheck
- register char *m = mem + tocopy;
- *m++ = 0; *m++ = 0; *m++ = 0; *m++ = 0;
- p-> mh_nbytes = n;
- m = mem + n;
- *m++ = MAGIC1; *m++ = MAGIC1; *m++ = MAGIC1; *m++ = MAGIC1;
-#else /* not rcheck */
- p -> mh_size = n;
-#endif /* not rcheck */
- return mem;
+ register char *m = mem + tocopy;
+ *m++ = 0;
+ *m++ = 0;
+ *m++ = 0;
+ *m++ = 0;
+ p->mh_nbytes = n;
+ m = mem + n;
+ *m++ = MAGIC1;
+ *m++ = MAGIC1;
+ *m++ = MAGIC1;
+ *m++ = MAGIC1;
+#else /* not rcheck */
+ p->mh_size = n;
+#endif /* not rcheck */
+ return mem;
+ }
+ if (n < tocopy)
+ tocopy = n;
+ {
+ register char *new;
+ int bcopy();
+
+ if ((new = malloc(n)) == 0)
+ return 0;
+ bcopy(mem, new, tocopy);
+ free(mem);
+ return new;
}
-
- if (n < tocopy)
- tocopy = n;
- {
- register char *new;
- int bcopy();
-
- if ((new = malloc (n)) == 0)
- return 0;
- bcopy (mem, new, tocopy);
- free (mem);
- return new;
- }
}
#ifndef VMS
char *
-memalign (alignment, size)
- unsigned alignment, size;
+memalign(alignment, size)
+ unsigned alignment, size;
{
- register char *ptr = malloc (size + alignment);
- register char *aligned;
- register struct mhead *p;
-
- if (ptr == 0)
- return 0;
- /* If entire block has the desired alignment, just accept it. */
- if (((int) ptr & (alignment - 1)) == 0)
- return ptr;
- /* Otherwise, get address of byte in the block that has that alignment. */
- aligned = (char *) (((int) ptr + alignment - 1) & -alignment);
-
- /* Store a suitable indication of how to free the block,
- so that free can find the true beginning of it. */
- p = (struct mhead *) aligned - 1;
- p -> mh_size = aligned - ptr;
- p -> mh_alloc = ISMEMALIGN;
- return aligned;
+ register char *ptr = malloc(size + alignment);
+ register char *aligned;
+ register struct mhead *p;
+
+ if (ptr == 0)
+ return 0;
+ /* If entire block has the desired alignment, just accept it. */
+ if (((int) ptr & (alignment - 1)) == 0)
+ return ptr;
+ /* Otherwise, get address of byte in the block that has that alignment. */
+ aligned = (char *) (((int) ptr + alignment - 1) & -alignment);
+
+ /* Store a suitable indication of how to free the block,
+ so that free can find the true beginning of it. */
+ p = (struct mhead *) aligned - 1;
+ p->mh_size = aligned - ptr;
+ p->mh_alloc = ISMEMALIGN;
+ return aligned;
}
#ifndef HPUX
/* This runs into trouble with getpagesize on HPUX.
Patching out seems cleaner than the ugly fix needed. */
char *
-valloc (size)
-int size;
+valloc(size)
+ int size;
{
- return memalign (getpagesize (), size);
+ return memalign(getpagesize(), size);
}
-#endif /* not HPUX */
-#endif /* not VMS */
+#endif /* not HPUX */
+#endif /* not VMS */
#ifdef MSTATS
/* Return statistics describing allocation of blocks of size 2**n. */
-struct mstats_value
- {
+struct mstats_value {
int blocksize;
int nfree;
int nused;
- };
+};
struct mstats_value
-malloc_stats (size)
- int size;
+malloc_stats(size)
+ int size;
{
- struct mstats_value v;
- register struct mhead *p;
+ struct mstats_value v;
+ register struct mhead *p;
- v.nfree = 0;
+ v.nfree = 0;
- if (size < 0 || size >= 30)
- {
- v.blocksize = 0;
- v.nused = 0;
- return v;
+ if (size < 0 || size >= 30) {
+ v.blocksize = 0;
+ v.nused = 0;
+ return v;
}
+ v.blocksize = 1 << (size + 3);
+ v.nused = nmalloc[size];
- v.blocksize = 1 << (size + 3);
- v.nused = nmalloc[size];
-
- for (p = nextf[size]; p; p = CHAIN (p))
- v.nfree++;
+ for (p = nextf[size]; p; p = CHAIN(p))
+ v.nfree++;
- return v;
+ return v;
}
int
-malloc_mem_used ()
+malloc_mem_used()
{
- int i;
- int size_used;
+ int i;
+ int size_used;
- size_used = 0;
-
- for (i = 0; i < 30; i++)
- {
- int allocation_size = 1 << (i + 3);
-
- size_used += nmalloc[i] * allocation_size;
+ size_used = 0;
+
+ for (i = 0; i < 30; i++) {
+ int allocation_size = 1 << (i + 3);
+
+ size_used += nmalloc[i] * allocation_size;
}
- return size_used;
+ return size_used;
}
-int
-malloc_mem_free ()
+int
+malloc_mem_free()
{
- int i;
- int size_unused;
+ int i;
+ int size_unused;
- size_unused = 0;
-
- for (i = 0; i < 30; i++)
- {
- int allocation_size = 1 << (i + 3);
- struct mhead *p;
-
- for (p = nextf[i]; p ; p = CHAIN (p))
- size_unused += allocation_size;
+ size_unused = 0;
+
+ for (i = 0; i < 30; i++) {
+ int allocation_size = 1 << (i + 3);
+ struct mhead *p;
+
+ for (p = nextf[i]; p; p = CHAIN(p))
+ size_unused += allocation_size;
}
- return size_unused;
+ return size_unused;
}
-#endif /* MSTATS */
+#endif /* MSTATS */
/*
- * This function returns the total number of bytes that the process
- * will be allowed to allocate via the sbrk(2) system call. On
- * BSD systems this is the total space allocatable to stack and
- * data. On USG systems this is the data space only.
+ * This function returns the total number of bytes that the process
+ * will be allowed to allocate via the sbrk(2) system call. On
+ * BSD systems this is the total space allocatable to stack and
+ * data. On USG systems this is the data space only.
*/
#ifdef USG
void
-get_lim_data ()
+get_lim_data()
{
- extern long ulimit ();
-
+ extern long ulimit();
+
#ifdef ULIMIT_BREAK_VALUE
- lim_data = ULIMIT_BREAK_VALUE;
+ lim_data = ULIMIT_BREAK_VALUE;
#else
- lim_data = ulimit (3, 0);
+ lim_data = ulimit(3, 0);
#endif
- lim_data -= (long) data_space_start;
+ lim_data -= (long) data_space_start;
}
-#else /* not USG */
+#else /* not USG */
#ifndef BSD4_2
void
-get_lim_data ()
+get_lim_data()
{
- lim_data = vlimit (LIM_DATA, -1);
+ lim_data = vlimit(LIM_DATA, -1);
}
-#else /* BSD4_2 */
+#else /* BSD4_2 */
void
-get_lim_data ()
+get_lim_data()
{
- struct rlimit XXrlimit;
- void getrlimit();
+ struct rlimit XXrlimit;
+ void getrlimit();
- getrlimit (RLIMIT_DATA, &XXrlimit);
+ getrlimit(RLIMIT_DATA, &XXrlimit);
#ifdef RLIM_INFINITY
- lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
+ lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
#else
- lim_data = XXrlimit.rlim_cur; /* soft limit */
+ lim_data = XXrlimit.rlim_cur; /* soft limit */
#endif
}
-#endif /* BSD4_2 */
-#endif /* not USG */
+#endif /* BSD4_2 */
+#endif /* not USG */
#ifdef VMS
/* There is a problem when dumping and restoring things on VMS. Calls
@@ -861,48 +852,45 @@ get_lim_data ()
int vms_out_initial = 0;
char vms_initial_buffer[VMS_ALLOCATION_SIZE];
static char *vms_current_brk = &vms_initial_buffer;
-static char *vms_end_brk = &vms_initial_buffer[VMS_ALLOCATION_SIZE-1];
+static char *vms_end_brk = &vms_initial_buffer[VMS_ALLOCATION_SIZE - 1];
#include <stdio.h>
char *
-sys_sbrk (incr)
- int incr;
+sys_sbrk(incr)
+ int incr;
{
- char *sbrk(), *temp, *ptr;
+ char *sbrk(), *temp, *ptr;
- if (vms_out_initial)
- {
- /* out of initial allocation... */
- if (!(temp = malloc (incr)))
- temp = (char *) -1;
- }
- else
- {
- /* otherwise, go out of our area */
- ptr = vms_current_brk + incr; /* new current_brk */
- if (ptr <= vms_end_brk)
- {
- temp = vms_current_brk;
- vms_current_brk = ptr;
- }
- else
- {
- vms_out_initial = 1; /* mark as out of initial allocation */
- if (!(temp = malloc (incr)))
+ if (vms_out_initial) {
+ /* out of initial allocation... */
+ if (!(temp = malloc(incr)))
temp = (char *) -1;
+ } else {
+ /* otherwise, go out of our area */
+ ptr = vms_current_brk + incr; /* new current_brk */
+ if (ptr <= vms_end_brk) {
+ temp = vms_current_brk;
+ vms_current_brk = ptr;
+ } else {
+ vms_out_initial = 1; /* mark as out of initial allocation */
+ if (!(temp = malloc(incr)))
+ temp = (char *) -1;
}
}
- return temp;
+ return temp;
}
-#endif /* VMS */
+#endif /* VMS */
char rcsid_gnu_malloc[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:44 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:38:46 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/keywords.c b/keywords.c
index a8c6725..ed2f166 100644
--- a/keywords.c
+++ b/keywords.c
@@ -36,130 +36,178 @@
#define MAX_HASH_VALUE 106
/*
35 keywords
- 104 is the maximum key range
-*/
+ 104 is the maximum key range
+ */
static int
-hash (register const char *str, register int len)
+hash(register const char *str, register int len)
{
- static const unsigned char hash_table[] =
+ static const unsigned char hash_table[] =
{
- 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
- 106, 106, 106, 106, 106, 106, 106, 10, 0, 45,
- 0, 0, 0, 10, 106, 45, 106, 10, 106, 35,
- 5, 106, 5, 10, 0, 25, 55, 106, 35, 5,
- 106, 10, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106, 106, 10, 0, 45,
+ 0, 0, 0, 10, 106, 45, 106, 10, 106, 35,
+ 5, 106, 5, 10, 0, 25, 55, 106, 35, 5,
+ 106, 10, 106, 106, 106, 106, 106, 106,
};
- register int hval = len;
-
- switch (hval)
- {
- default:
- case 3:
- hval += hash_table[tolower((unsigned char) str[2])];
- case 2:
- case 1:
- hval += hash_table[tolower((unsigned char) str[0])];
+ register int hval = len;
+
+ switch (hval) {
+ default:
+ case 3:
+ hval += hash_table[tolower((unsigned char) str[2])];
+ case 2:
+ case 1:
+ hval += hash_table[tolower((unsigned char) str[0])];
}
- return hval + hash_table[tolower((unsigned char) str[len - 1])];
+ return hval + hash_table[tolower((unsigned char) str[len - 1])];
}
static int
-case_strcmp (register const char *str, register const char *key)
+case_strcmp(register const char *str, register const char *key)
{
- int ans = 0;
+ int ans = 0;
- while (!(ans = tolower(*str) - (int) *key) && *str)
- str++, key++;
+ while (!(ans = tolower(*str) - (int) *key) && *str)
+ str++, key++;
- return ans;
+ return ans;
}
const struct keyword *
-in_word_set (register const char *str, register int len)
+in_word_set(register const char *str, register int len)
{
- static const struct keyword wordlist[] =
+ static const struct keyword wordlist[] =
{
- {"",}, {"",}, {"",},
- {"for", DBV_Prehistory, tFOR},
- {"",},
- {"endif", DBV_Prehistory, tENDIF},
- {"endfor", DBV_Prehistory, tENDFOR},
- {"e_range", DBV_Prehistory, tERROR, E_RANGE},
- {"endwhile", DBV_Prehistory, tENDWHILE},
- {"e_recmove", DBV_Prehistory, tERROR, E_RECMOVE},
- {"",},
- {"e_none", DBV_Prehistory, tERROR, E_NONE},
- {"",},
- {"e_propnf", DBV_Prehistory, tERROR, E_PROPNF},
- {"fork", DBV_Prehistory, tFORK},
- {"break", DBV_BreakCont, tBREAK},
- {"endtry", DBV_Exceptions, tENDTRY},
- {"endfork", DBV_Prehistory, tENDFORK},
- {"",}, {"",}, {"",}, {"",},
- {"finally", DBV_Exceptions, tFINALLY},
- {"",}, {"",}, {"",}, {"",},
- {"e_quota", DBV_Prehistory, tERROR, E_QUOTA},
- {"",},
- {"else", DBV_Prehistory, tELSE},
- {"",},
- {"elseif", DBV_Prehistory, tELSEIF},
- {"",},
- {"any", DBV_Exceptions, tANY},
- {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
- {"e_div", DBV_Prehistory, tERROR, E_DIV},
- {"e_args", DBV_Prehistory, tERROR, E_ARGS},
- {"e_varnf", DBV_Prehistory, tERROR, E_VARNF},
- {"e_verbnf", DBV_Prehistory, tERROR, E_VERBNF},
- {"",}, {"",},
- {"e_perm", DBV_Prehistory, tERROR, E_PERM},
- {"if", DBV_Prehistory, tIF},
- {"",}, {"",}, {"",}, {"",},
- {"in", DBV_Prehistory, tIN},
- {"e_invind", DBV_Prehistory, tERROR, E_INVIND},
- {"",},
- {"while", DBV_Prehistory, tWHILE},
- {"e_nacc", DBV_Prehistory, tERROR, E_NACC},
- {"",},
- {"continue", DBV_BreakCont, tCONTINUE},
- {"",}, {"",},
- {"e_type", DBV_Prehistory, tERROR, E_TYPE},
- {"e_float", DBV_Float, tERROR, E_FLOAT},
- {"e_invarg", DBV_Prehistory, tERROR, E_INVARG},
- {"",}, {"",},
- {"return", DBV_Prehistory, tRETURN},
- {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
- {"",}, {"",},
- {"try", DBV_Exceptions, tTRY},
- {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
- {"e_maxrec", DBV_Prehistory, tERROR, E_MAXREC},
- {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
- {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
- {"except", DBV_Exceptions, tEXCEPT},
+ {"",},
+ {"",},
+ {"",},
+ {"for", DBV_Prehistory, tFOR},
+ {"",},
+ {"endif", DBV_Prehistory, tENDIF},
+ {"endfor", DBV_Prehistory, tENDFOR},
+ {"e_range", DBV_Prehistory, tERROR, E_RANGE},
+ {"endwhile", DBV_Prehistory, tENDWHILE},
+ {"e_recmove", DBV_Prehistory, tERROR, E_RECMOVE},
+ {"",},
+ {"e_none", DBV_Prehistory, tERROR, E_NONE},
+ {"",},
+ {"e_propnf", DBV_Prehistory, tERROR, E_PROPNF},
+ {"fork", DBV_Prehistory, tFORK},
+ {"break", DBV_BreakCont, tBREAK},
+ {"endtry", DBV_Exceptions, tENDTRY},
+ {"endfork", DBV_Prehistory, tENDFORK},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"finally", DBV_Exceptions, tFINALLY},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"e_quota", DBV_Prehistory, tERROR, E_QUOTA},
+ {"",},
+ {"else", DBV_Prehistory, tELSE},
+ {"",},
+ {"elseif", DBV_Prehistory, tELSEIF},
+ {"",},
+ {"any", DBV_Exceptions, tANY},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"e_div", DBV_Prehistory, tERROR, E_DIV},
+ {"e_args", DBV_Prehistory, tERROR, E_ARGS},
+ {"e_varnf", DBV_Prehistory, tERROR, E_VARNF},
+ {"e_verbnf", DBV_Prehistory, tERROR, E_VERBNF},
+ {"",},
+ {"",},
+ {"e_perm", DBV_Prehistory, tERROR, E_PERM},
+ {"if", DBV_Prehistory, tIF},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"in", DBV_Prehistory, tIN},
+ {"e_invind", DBV_Prehistory, tERROR, E_INVIND},
+ {"",},
+ {"while", DBV_Prehistory, tWHILE},
+ {"e_nacc", DBV_Prehistory, tERROR, E_NACC},
+ {"",},
+ {"continue", DBV_BreakCont, tCONTINUE},
+ {"",},
+ {"",},
+ {"e_type", DBV_Prehistory, tERROR, E_TYPE},
+ {"e_float", DBV_Float, tERROR, E_FLOAT},
+ {"e_invarg", DBV_Prehistory, tERROR, E_INVARG},
+ {"",},
+ {"",},
+ {"return", DBV_Prehistory, tRETURN},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"try", DBV_Exceptions, tTRY},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"e_maxrec", DBV_Prehistory, tERROR, E_MAXREC},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"",},
+ {"except", DBV_Exceptions, tEXCEPT},
};
- if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
- {
- register int key = hash (str, len);
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) {
+ register int key = hash(str, len);
- if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
- {
- register const char *s = wordlist[key].name;
+ if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE) {
+ register const char *s = wordlist[key].name;
- if (*s == tolower(*str) && !case_strcmp (str + 1, s + 1))
- return &wordlist[key];
- }
+ if (*s == tolower(*str) && !case_strcmp(str + 1, s + 1))
+ return &wordlist[key];
+ }
}
- return 0;
+ return 0;
}
const struct keyword *
@@ -171,9 +219,12 @@ find_keyword(const char *word)
char rcsid_keywords[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:45 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/02/08 06:33:21 pavel
* Added `break', `continue', and E_FLOAT. Updated copyright notice for 1996.
* Release 1.8.0beta1.
diff --git a/keywords.h b/keywords.h
index 024cc22..8d81907 100644
--- a/keywords.h
+++ b/keywords.h
@@ -20,10 +20,10 @@
#include "version.h"
struct keyword {
- const char *name; /* the canonical spelling of the keyword */
- DB_Version version; /* the DB version when it was introduced */
- int token; /* the type of token the scanner should use */
- enum error error; /* for token == ERROR, the value */
+ const char *name; /* the canonical spelling of the keyword */
+ DB_Version version; /* the DB version when it was introduced */
+ int token; /* the type of token the scanner should use */
+ enum error error; /* for token == ERROR, the value */
};
typedef const struct keyword Keyword;
@@ -31,9 +31,12 @@ typedef const struct keyword Keyword;
extern Keyword *find_keyword(const char *);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:03 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:46 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:03 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/02/08 06:24:47 pavel
* Fixed type of version number. Updated copyright notice for 1996.
* Release 1.8.0beta1.
diff --git a/list.c b/list.c
index 5e31f2b..7eae3f0 100644
--- a/list.c
+++ b/list.c
@@ -38,10 +38,10 @@
Var
new_list(int size)
{
- Var new;
+ Var new;
new.type = TYPE_LIST;
- new.v.list = (Var *) mymalloc((size + 1) * sizeof (Var), M_LIST);
+ new.v.list = (Var *) mymalloc((size + 1) * sizeof(Var), M_LIST);
new.v.list[0].type = TYPE_INT;
new.v.list[0].v.num = size;
return new;
@@ -60,7 +60,7 @@ setadd(Var list, Var value)
Var
setremove(Var list, Var value)
{
- int i;
+ int i;
if ((i = ismember(value, list, 0)) != 0) {
return listdelete(list, i);
@@ -72,7 +72,7 @@ setremove(Var list, Var value)
int
ismember(Var lhs, Var rhs, int case_matters)
{
- int i;
+ int i;
for (i = 1; i <= rhs.v.list[0].v.num; i++) {
if (equality(lhs, rhs.v.list[i], case_matters)) {
@@ -93,8 +93,8 @@ listset(Var list, Var value, int pos)
static Var
doinsert(Var list, Var value, int pos)
{
- Var new;
- int i;
+ Var new;
+ int i;
new = new_list(list.v.list[0].v.num + 1);
for (i = 1; i < pos; i++)
@@ -125,8 +125,8 @@ listappend(Var list, Var value)
Var
listdelete(Var list, int pos)
{
- Var new;
- int i;
+ Var new;
+ int i;
new = new_list(list.v.list[0].v.num - 1);
for (i = 1; i < pos; i++) {
@@ -141,11 +141,11 @@ listdelete(Var list, int pos)
Var
listconcat(Var first, Var second)
{
- int lsecond = second.v.list[0].v.num;
- int lfirst = first.v.list[0].v.num;
- Var new;
+ int lsecond = second.v.list[0].v.num;
+ int lfirst = first.v.list[0].v.num;
+ Var new;
int i;
-
+
new = new_list(lsecond + lfirst);
for (i = 1; i <= lfirst; i++)
new.v.list[i] = var_ref(first.v.list[i]);
@@ -171,7 +171,7 @@ listrangeset(Var base, int from, int to, Var value)
Var ans;
ans = new_list(newsize);
- for (index = 1; index <= lenleft; index++)
+ for (index = 1; index <= lenleft; index++)
ans.v.list[++offset] = var_ref(base.v.list[index]);
for (index = 1; index <= lenmiddle; index++)
ans.v.list[++offset] = var_ref(value.v.list[index]);
@@ -189,9 +189,9 @@ sublist(Var list, int lower, int upper)
free_var(list);
return new_list(0);
} else {
- Var r;
- int i;
-
+ Var r;
+ int i;
+
r = new_list(upper - lower + 1);
for (i = lower; i <= upper; i++)
r.v.list[i - lower + 1] = var_ref(list.v.list[i]);
@@ -201,46 +201,46 @@ sublist(Var list, int lower, int upper)
}
static const char *
-list2str(Var *args)
+list2str(Var * args)
{
- static Stream *str = 0;
- int i;
-
+ static Stream *str = 0;
+ int i;
+
if (!str)
str = new_stream(100);
-
+
for (i = 1; i <= args[0].v.num; i++) {
switch (args[i].type) {
- case TYPE_INT:
+ case TYPE_INT:
stream_printf(str, "%d", args[i].v.num);
break;
- case TYPE_OBJ:
+ case TYPE_OBJ:
stream_printf(str, "#%d", args[i].v.obj);
break;
- case TYPE_STR:
+ case TYPE_STR:
stream_add_string(str, args[i].v.str);
break;
- case TYPE_ERR:
+ case TYPE_ERR:
stream_add_string(str, unparse_error(args[i].v.err));
break;
- case TYPE_FLOAT:
+ case TYPE_FLOAT:
stream_printf(str, "%g", *args[i].v.fnum);
break;
- case TYPE_LIST:
+ case TYPE_LIST:
stream_add_string(str, "{list}");
break;
- default:
+ default:
panic("LIST2STR: Impossible var type.\n");
}
}
-
+
return reset_stream(str);
}
const char *
value2str(Var value)
{
- Var list;
+ Var list;
const char *str;
list = new_list(1);
@@ -251,43 +251,43 @@ value2str(Var value)
}
static void
-print_to_stream(Var v, Stream *s)
+print_to_stream(Var v, Stream * s)
{
switch (v.type) {
- case TYPE_INT:
+ case TYPE_INT:
stream_printf(s, "%d", v.v.num);
break;
- case TYPE_OBJ:
+ case TYPE_OBJ:
stream_printf(s, "#%d", v.v.obj);
break;
- case TYPE_ERR:
+ case TYPE_ERR:
stream_add_string(s, error_name(v.v.num));
break;
- case TYPE_FLOAT:
+ case TYPE_FLOAT:
stream_printf(s, "%g", *v.v.fnum);
break;
- case TYPE_STR:
+ case TYPE_STR:
{
const char *str = v.v.str;
-
+
stream_add_char(s, '"');
while (*str) {
switch (*str) {
- case '"':
- case '\\':
+ case '"':
+ case '\\':
stream_add_char(s, '\\');
/* fall thru */
- default:
+ default:
stream_add_char(s, *str++);
}
}
stream_add_char(s, '"');
}
break;
- case TYPE_LIST:
+ case TYPE_LIST:
{
const char *sep = "";
- int len, i;
+ int len, i;
stream_add_char(s, '{');
len = v.v.list[0].v.num;
@@ -299,7 +299,7 @@ print_to_stream(Var v, Stream *s)
stream_add_char(s, '}');
}
break;
- default:
+ default:
errlog("PRINT_TO_STREAM: Unknown Var type = %d\n", v.type);
stream_add_string(s, ">>Unknown value<<");
}
@@ -308,7 +308,7 @@ print_to_stream(Var v, Stream *s)
const char *
value_to_literal(Var v)
{
- static Stream *s = 0;
+ static Stream *s = 0;
if (!s)
s = new_stream(100);
@@ -329,7 +329,7 @@ strrangeset(Var base, int from, int to, Var value)
int lenmiddle = val_len;
int lenright = (base_len > to) ? base_len - to : 0;
int newsize = lenleft + lenmiddle + lenright;
-
+
Var ans;
char *s;
@@ -346,13 +346,13 @@ strrangeset(Var base, int from, int to, Var value)
ans.v.str = s;
free_var(base);
free_var(value);
- return ans;
+ return ans;
}
Var
substr(Var str, int lower, int upper)
{
- Var r;
+ Var r;
r.type = TYPE_STR;
if (lower > upper)
@@ -373,8 +373,8 @@ substr(Var str, int lower, int upper)
Var
strget(Var str, Var i)
{
- Var r;
- char *s;
+ Var r;
+ char *s;
r.type = TYPE_STR;
s = str_dup(" ");
@@ -389,30 +389,30 @@ static package
bf_length(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
- switch(arglist.v.list[1].type) {
- case TYPE_LIST:
+ switch (arglist.v.list[1].type) {
+ case TYPE_LIST:
r.type = TYPE_INT;
r.v.num = arglist.v.list[1].v.list[0].v.num;
break;
- case TYPE_STR:
+ case TYPE_STR:
r.type = TYPE_INT;
r.v.num = strlen(arglist.v.list[1].v.str);
break;
- default:
+ default:
free_var(arglist);
return make_error_pack(E_TYPE);
break;
}
-
+
free_var(arglist);
return make_var_pack(r);
}
-static package
+static package
bf_setadd(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
-
+
r = setadd(var_ref(arglist.v.list[1]), var_ref(arglist.v.list[2]));
free_var(arglist);
return make_var_pack(r);
@@ -423,7 +423,7 @@ static package
bf_setremove(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
-
+
r = setremove(var_ref(arglist.v.list[1]), arglist.v.list[2]);
free_var(arglist);
return make_var_pack(r);
@@ -451,8 +451,8 @@ bf_listinsert(Var arglist, Byte next, void *vdata, Objid progr)
if (arglist.v.list[0].v.num == 2)
r = listinsert(var_ref(arglist.v.list[1]), var_ref(arglist.v.list[2]), 1);
else
- r = listinsert(var_ref(arglist.v.list[1]),
- var_ref(arglist.v.list[2]), arglist.v.list[3].v.num);
+ r = listinsert(var_ref(arglist.v.list[1]),
+ var_ref(arglist.v.list[2]), arglist.v.list[3].v.num);
free_var(arglist);
return make_var_pack(r);
}
@@ -461,7 +461,7 @@ static package
bf_listdelete(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
- if (arglist.v.list[2].v.num <= 0
+ if (arglist.v.list[2].v.num <= 0
|| arglist.v.list[2].v.num > arglist.v.list[1].v.list[0].v.num) {
free_var(arglist);
return make_error_pack(E_RANGE);
@@ -477,12 +477,12 @@ static package
bf_listset(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
- if (arglist.v.list[3].v.num <= 0
+ if (arglist.v.list[3].v.num <= 0
|| arglist.v.list[3].v.num > arglist.v.list[1].v.list[0].v.num) {
free_var(arglist);
return make_error_pack(E_RANGE);
} else {
- r = listset(var_dup(arglist.v.list[1]),
+ r = listset(var_dup(arglist.v.list[1]),
var_ref(arglist.v.list[2]), arglist.v.list[3].v.num);
}
free_var(arglist);
@@ -492,7 +492,7 @@ bf_listset(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_equal(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
+ Var r;
r.type = TYPE_INT;
r.v.num = equality(arglist.v.list[1], arglist.v.list[2], 1);
@@ -503,7 +503,7 @@ bf_equal(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_is_member(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
+ Var r;
r.type = TYPE_INT;
r.v.num = ismember(arglist.v.list[1], arglist.v.list[2], 1);
@@ -513,10 +513,10 @@ bf_is_member(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_strsub(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (source, what, with [, case-matters]) */
+{ /* (source, what, with [, case-matters]) */
Var r;
- int case_matters = 0;
-
+ int case_matters = 0;
+
if (arglist.v.list[0].v.num == 4)
case_matters = is_true(arglist.v.list[4]);
if (arglist.v.list[2].v.str[0] == '\0') {
@@ -527,7 +527,7 @@ bf_strsub(Var arglist, Byte next, void *vdata, Objid progr)
r.v.str = str_dup(strsub(arglist.v.list[1].v.str,
arglist.v.list[2].v.str,
arglist.v.list[3].v.str, case_matters));
-
+
free_var(arglist);
return make_var_pack(r);
}
@@ -535,15 +535,15 @@ bf_strsub(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_crypt(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (string, [salt]) */
- Var r;
+{ /* (string, [salt]) */
+ Var r;
#if HAVE_CRYPT
- char salt[3];
+ char salt[3];
static char saltstuff[] =
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
extern const char *crypt(const char *, const char *);
-
+
if (arglist.v.list[0].v.num == 1 || strlen(arglist.v.list[2].v.str) < 2) {
salt[0] = saltstuff[RANDOM() % (int) strlen(saltstuff)];
salt[1] = saltstuff[RANDOM() % (int) strlen(saltstuff)];
@@ -554,7 +554,7 @@ bf_crypt(Var arglist, Byte next, void *vdata, Objid progr)
salt[2] = '\0';
r.type = TYPE_STR;
r.v.str = str_dup(crypt(arglist.v.list[1].v.str, salt));
-#else /* !HAVE_CRYPT */
+#else /* !HAVE_CRYPT */
r.type = TYPE_STR;
r.v.str = str_ref(arglist.v.list[1].v.str);
#endif
@@ -571,9 +571,9 @@ signum(int x)
static package
bf_strcmp(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (string1, string2) */
+{ /* (string1, string2) */
Var r;
-
+
r.type = TYPE_INT;
r.v.num = signum(strcmp(arglist.v.list[1].v.str, arglist.v.list[2].v.str));
free_var(arglist);
@@ -582,33 +582,33 @@ bf_strcmp(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_index(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (source, what [, case-matters]) */
+{ /* (source, what [, case-matters]) */
Var r;
int case_matters = 0;
-
+
if (arglist.v.list[0].v.num == 3)
case_matters = is_true(arglist.v.list[3]);
r.type = TYPE_INT;
- r.v.num = strindex(arglist.v.list[1].v.str, arglist.v.list[2].v.str,
+ r.v.num = strindex(arglist.v.list[1].v.str, arglist.v.list[2].v.str,
case_matters);
-
+
free_var(arglist);
return make_var_pack(r);
}
static package
bf_rindex(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (source, what [, case-matters]) */
+{ /* (source, what [, case-matters]) */
Var r;
-
+
int case_matters = 0;
-
+
if (arglist.v.list[0].v.num == 3)
case_matters = is_true(arglist.v.list[3]);
r.type = TYPE_INT;
- r.v.num = strrindex(arglist.v.list[1].v.str, arglist.v.list[2].v.str,
+ r.v.num = strrindex(arglist.v.list[1].v.str, arglist.v.list[2].v.str,
case_matters);
-
+
free_var(arglist);
return make_var_pack(r);
}
@@ -627,7 +627,7 @@ static package
bf_toliteral(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
-
+
r.type = TYPE_STR;
r.v.str = str_dup(value_to_literal(arglist.v.list[1]));
free_var(arglist);
@@ -635,19 +635,19 @@ bf_toliteral(Var arglist, Byte next, void *vdata, Objid progr)
}
struct pat_cache_entry {
- char *string;
- int case_matters;
- Pattern pattern;
- struct pat_cache_entry *next;
+ char *string;
+ int case_matters;
+ Pattern pattern;
+ struct pat_cache_entry *next;
};
-
-static struct pat_cache_entry *pat_cache;
-static struct pat_cache_entry pat_cache_entries[PATTERN_CACHE_SIZE];
+
+static struct pat_cache_entry *pat_cache;
+static struct pat_cache_entry pat_cache_entries[PATTERN_CACHE_SIZE];
static void
setup_pattern_cache()
{
- int i;
+ int i;
for (i = 0; i < PATTERN_CACHE_SIZE; i++) {
pat_cache_entries[i].string = 0;
@@ -657,21 +657,21 @@ setup_pattern_cache()
for (i = 0; i < PATTERN_CACHE_SIZE - 1; i++)
pat_cache_entries[i].next = &(pat_cache_entries[i + 1]);
pat_cache_entries[PATTERN_CACHE_SIZE - 1].next = 0;
-
+
pat_cache = &(pat_cache_entries[0]);
}
static Pattern
get_pattern(const char *string, int case_matters)
{
- struct pat_cache_entry *entry, **entry_ptr;
+ struct pat_cache_entry *entry, **entry_ptr;
entry = pat_cache;
entry_ptr = &pat_cache;
while (1) {
- if (entry->string && !strcmp(string, entry->string)
- && case_matters == entry->case_matters) {
+ if (entry->string && !strcmp(string, entry->string)
+ && case_matters == entry->case_matters) {
/* A cache hit; move this entry to the front of the cache. */
break;
} else if (!entry->next) {
@@ -705,23 +705,23 @@ get_pattern(const char *string, int case_matters)
Var
do_match(Var arglist, int reverse)
{
- const char *subject, *pattern;
- int i;
- Pattern pat;
- Var ans;
- Match_Indices regs[10];
+ const char *subject, *pattern;
+ int i;
+ Pattern pat;
+ Var ans;
+ Match_Indices regs[10];
subject = arglist.v.list[1].v.str;
pattern = arglist.v.list[2].v.str;
pat = get_pattern(pattern, (arglist.v.list[0].v.num == 3
- && is_true(arglist.v.list[3])));
+ && is_true(arglist.v.list[3])));
if (!pat.ptr) {
ans.type = TYPE_ERR;
ans.v.err = E_INVARG;
} else
switch (match_pattern(pat, subject, regs, reverse)) {
- case MATCH_SUCCEEDED:
+ case MATCH_SUCCEEDED:
ans = new_list(4);
ans.v.list[1].type = TYPE_INT;
ans.v.list[2].type = TYPE_INT;
@@ -738,10 +738,10 @@ do_match(Var arglist, int reverse)
ans.v.list[3].v.list[i].v.list[2].v.num = regs[i].end;
}
break;
- case MATCH_FAILED:
+ case MATCH_FAILED:
ans = new_list(0);
break;
- case MATCH_ABORTED:
+ case MATCH_ABORTED:
ans.type = TYPE_ERR;
ans.v.err = E_QUOTA;
break;
@@ -754,7 +754,7 @@ static package
bf_match(Var arglist, Byte next, void *vdata, Objid progr)
{
Var ans;
-
+
ans = do_match(arglist, 0);
free_var(arglist);
if (ans.type == TYPE_ERR)
@@ -780,7 +780,7 @@ int
invalid_pair(int num1, int num2, int max)
{
if ((num1 == 0 && num2 == -1)
- || (num1 > 0 && num2 >= num1 - 1 && num2 <= max))
+ || (num1 > 0 && num2 >= num1 - 1 && num2 <= max))
return 0;
else
return 1;
@@ -791,7 +791,7 @@ check_subs_list(Var subs)
{
const char *subj;
int subj_length, loop;
-
+
if (subs.type != TYPE_LIST || subs.v.list[0].v.num != 4
|| subs.v.list[1].type != TYPE_INT
|| subs.v.list[2].type != TYPE_INT
@@ -804,16 +804,16 @@ check_subs_list(Var subs)
if (invalid_pair(subs.v.list[1].v.num, subs.v.list[2].v.num,
subj_length))
return 1;
-
+
for (loop = 1; loop <= 9; loop++) {
Var pair;
pair = subs.v.list[3].v.list[loop];
- if (pair.type != TYPE_LIST
- || pair.v.list[0].v.num != 2
- || pair.v.list[1].type != TYPE_INT
- || pair.v.list[2].type != TYPE_INT
+ if (pair.type != TYPE_LIST
+ || pair.v.list[0].v.num != 2
+ || pair.v.list[1].type != TYPE_INT
+ || pair.v.list[2].type != TYPE_INT
|| invalid_pair(pair.v.list[1].v.num, pair.v.list[2].v.num,
- subj_length))
+ subj_length))
return 1;
}
return 0;
@@ -839,12 +839,12 @@ bf_substitute(Var arglist, Byte next, void *vdata, Objid progr)
}
subject = subs.v.list[4].v.str;
subject_length = strlen(subject);
-
+
s = new_stream(template_length);
ans.type = TYPE_STR;
while ((c = *(template++)) != '\0') {
- switch(c) {
- case '%':
+ switch (c) {
+ case '%':
{
Var pair;
int start = 0, end = 0;
@@ -853,13 +853,13 @@ bf_substitute(Var arglist, Byte next, void *vdata, Objid progr)
stream_add_char(s, '%');
else {
if (c >= '1' && c <= '9') {
- pair = subs.v.list[3].v.list[c-'0'];
- start = pair.v.list[1].v.num-1;
- end = pair.v.list[2].v.num-1;
+ pair = subs.v.list[3].v.list[c - '0'];
+ start = pair.v.list[1].v.num - 1;
+ end = pair.v.list[2].v.num - 1;
} else if (c == '0') {
- start = subs.v.list[1].v.num-1;
- end = subs.v.list[2].v.num-1;
- } else
+ start = subs.v.list[1].v.num - 1;
+ end = subs.v.list[2].v.num - 1;
+ } else
invarg = 1;
if (!invarg) {
int where;
@@ -869,27 +869,27 @@ bf_substitute(Var arglist, Byte next, void *vdata, Objid progr)
}
break;
}
- default:
+ default:
stream_add_char(s, c);
}
if (invarg)
break;
}
-
+
free_var(arglist);
if (!invarg)
ans.v.str = str_dup(reset_stream(s));
free_stream(s);
- if (invarg)
+ if (invarg)
return make_error_pack(E_INVARG);
- else
+ else
return make_var_pack(ans);
}
static package
bf_value_bytes(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
+ Var r;
r.type = TYPE_INT;
r.v.num = value_bytes(arglist.v.list[1]);
@@ -900,11 +900,11 @@ bf_value_bytes(Var arglist, Byte next, void *vdata, Objid progr)
static const char *
hash_bytes(const char *input, int length)
{
- md5ctx_t context;
- uint8 result[16];
- int i;
- const char digits[] = "0123456789ABCDEF";
- char *hex = str_dup("12345678901234567890123456789012");
+ md5ctx_t context;
+ uint8 result[16];
+ int i;
+ const char digits[] = "0123456789ABCDEF";
+ char *hex = str_dup("12345678901234567890123456789012");
const char *answer = hex;
md5_Init(&context);
@@ -920,8 +920,8 @@ hash_bytes(const char *input, int length)
static package
bf_binary_hash(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
- int length;
+ Var r;
+ int length;
const char *bytes = binary_to_raw_bytes(arglist.v.list[1].v.str, &length);
free_var(arglist);
@@ -935,7 +935,7 @@ bf_binary_hash(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_string_hash(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
+ Var r;
const char *str = arglist.v.list[1].v.str;
r.type = TYPE_STR;
@@ -947,7 +947,7 @@ bf_string_hash(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_value_hash(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
+ Var r;
const char *lit = value_to_literal(arglist.v.list[1]);
r.type = TYPE_STR;
@@ -959,12 +959,12 @@ bf_value_hash(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_decode_binary(Var arglist, Byte next, void *vdata, Objid progr)
{
- int length;
+ int length;
const char *bytes = binary_to_raw_bytes(arglist.v.list[1].v.str, &length);
- int nargs = arglist.v.list[0].v.num;
- int fully = (nargs >= 2 && is_true(arglist.v.list[2]));
- Var r;
- int i;
+ int nargs = arglist.v.list[0].v.num;
+ int fully = (nargs >= 2 && is_true(arglist.v.list[2]));
+ Var r;
+ int i;
free_var(arglist);
if (!bytes)
@@ -977,16 +977,16 @@ bf_decode_binary(Var arglist, Byte next, void *vdata, Objid progr)
r.v.list[i].v.num = bytes[i - 1];
}
} else {
- static Stream *s = 0;
- int count, in_string;
+ static Stream *s = 0;
+ int count, in_string;
if (!s)
s = new_stream(50);
for (count = in_string = 0, i = 0; i < length; i++) {
unsigned char c = bytes[i];
-
- if (isgraph(c) || c == ' ' || c == '\t') {
+
+ if (isgraph(c) || c == ' ' || c == '\t') {
if (!in_string)
count++;
in_string = 1;
@@ -999,8 +999,8 @@ bf_decode_binary(Var arglist, Byte next, void *vdata, Objid progr)
r = new_list(count);
for (count = 1, in_string = 0, i = 0; i < length; i++) {
unsigned char c = bytes[i];
-
- if (isgraph(c) || c == ' ' || c == '\t') {
+
+ if (isgraph(c) || c == ' ' || c == '\t') {
stream_add_char(s, c);
in_string = 1;
} else {
@@ -1026,25 +1026,25 @@ bf_decode_binary(Var arglist, Byte next, void *vdata, Objid progr)
}
static int
-encode_binary(Stream *s, Var v)
+encode_binary(Stream * s, Var v)
{
- int i;
+ int i;
switch (v.type) {
- case TYPE_INT:
- if (v.v.num < 0 || v.v.num >= 256)
+ case TYPE_INT:
+ if (v.v.num < 0 || v.v.num >= 256)
return 0;
stream_add_char(s, (char) v.v.num);
break;
- case TYPE_STR:
+ case TYPE_STR:
stream_add_string(s, v.v.str);
break;
- case TYPE_LIST:
+ case TYPE_LIST:
for (i = 1; i <= v.v.list[0].v.num; i++)
if (!encode_binary(s, v.v.list[i]))
return 0;
break;
- default:
+ default:
return 0;
}
@@ -1054,10 +1054,10 @@ encode_binary(Stream *s, Var v)
static package
bf_encode_binary(Var arglist, Byte next, void *vdata, Objid progr)
{
- static Stream *s = 0;
- int ok, length;
- Var r;
- const char *bytes;
+ static Stream *s = 0;
+ int ok, length;
+ Var r;
+ const char *bytes;
if (!s)
s = new_stream(100);
@@ -1117,9 +1117,12 @@ register_list(void)
char rcsid_list[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:46 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.7 1996/03/11 23:35:17 pavel
* Fixed bad use of possibly-signed characters in decode_binary().
* Release 1.8.0p1.
diff --git a/list.h b/list.h
index 06cd013..2529db5 100644
--- a/list.h
+++ b/list.h
@@ -17,27 +17,30 @@
#include "structures.h"
-extern Var listappend(Var list, Var value);
-extern Var listinsert(Var list, Var value, int pos);
-extern Var listdelete(Var list, int pos);
-extern Var listset(Var list, Var value, int pos);
-extern Var listrangeset(Var list, int from, int to, Var value);
-extern Var listconcat(Var first, Var second);
-extern int ismember(Var value, Var list, int case_matters);
-extern Var setadd(Var list, Var value);
-extern Var setremove(Var list, Var value);
-extern Var sublist(Var list, int lower, int upper);
-extern Var strrangeset(Var list, int from, int to, Var value);
-extern Var substr(Var str, int lower, int upper);
-extern Var strget(Var str, Var i);
-extern Var new_list(int size);
+extern Var listappend(Var list, Var value);
+extern Var listinsert(Var list, Var value, int pos);
+extern Var listdelete(Var list, int pos);
+extern Var listset(Var list, Var value, int pos);
+extern Var listrangeset(Var list, int from, int to, Var value);
+extern Var listconcat(Var first, Var second);
+extern int ismember(Var value, Var list, int case_matters);
+extern Var setadd(Var list, Var value);
+extern Var setremove(Var list, Var value);
+extern Var sublist(Var list, int lower, int upper);
+extern Var strrangeset(Var list, int from, int to, Var value);
+extern Var substr(Var str, int lower, int upper);
+extern Var strget(Var str, Var i);
+extern Var new_list(int size);
extern const char *value2str(Var);
extern const char *value_to_literal(Var);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:03 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:47 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:03 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:23:44 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/log.c b/log.c
index 4947cb6..0b0c258 100644
--- a/log.c
+++ b/log.c
@@ -30,10 +30,10 @@
#include "streams.h"
#include "utils.h"
-static FILE *log_file = 0;
+static FILE *log_file = 0;
void
-set_log_file(FILE *f)
+set_log_file(FILE * f)
{
log_file = f;
}
@@ -41,15 +41,15 @@ set_log_file(FILE *f)
static void
do_log(const char *fmt, va_list args, const char *prefix)
{
- FILE *f;
+ FILE *f;
if (log_file) {
- time_t now = time(0);
- char *nowstr = ctime(&now);
+ time_t now = time(0);
+ char *nowstr = ctime(&now);
nowstr[19] = '\0'; /* kill the year and newline at the end */
f = log_file;
- fprintf(f, "%s: %s", nowstr + 4, prefix); /* skip the day of week */
+ fprintf(f, "%s: %s", nowstr + 4, prefix); /* skip the day of week */
} else
f = stderr;
@@ -58,9 +58,9 @@ do_log(const char *fmt, va_list args, const char *prefix)
}
void
-oklog(const char *fmt, ...)
+oklog(const char *fmt,...)
{
- va_list args;
+ va_list args;
va_start(args, fmt);
do_log(fmt, args, "");
@@ -68,9 +68,9 @@ oklog(const char *fmt, ...)
}
void
-errlog(const char *fmt, ...)
+errlog(const char *fmt,...)
{
- va_list args;
+ va_list args;
va_start(args, fmt);
do_log(fmt, args, "*** ");
@@ -85,7 +85,7 @@ log_perror(const char *what)
#ifdef LOG_COMMANDS
-static Stream *command_history = 0;
+static Stream *command_history = 0;
#endif
void
@@ -111,14 +111,14 @@ void
add_command_to_history(Objid player, const char *command)
{
#ifdef LOG_COMMANDS
- time_t now = time(0);
- char *nowstr = ctime(&now);
+ time_t now = time(0);
+ char *nowstr = ctime(&now);
- nowstr[19] = '\0'; /* kill the year and newline at the end */
+ nowstr[19] = '\0'; /* kill the year and newline at the end */
stream_printf(command_history, "%s: #%d: %s\n",
nowstr + 4, /* skip day of week */
player, command);
-#endif /* LOG_COMMANDS */
+#endif /* LOG_COMMANDS */
}
/**** built in functions ****/
@@ -131,13 +131,13 @@ bf_server_log(Var arglist, Byte next, void *vdata, Objid progr)
return make_error_pack(E_PERM);
} else {
int is_error = (arglist.v.list[0].v.num == 2
- && is_true(arglist.v.list[2]));
+ && is_true(arglist.v.list[2]));
if (is_error)
errlog("> %s\n", arglist.v.list[1].v.str);
else
oklog("> %s\n", arglist.v.list[1].v.str);
-
+
free_var(arglist);
return no_var_pack();
}
@@ -152,9 +152,12 @@ register_log(void)
char rcsid_log[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:48 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/04/08 01:06:25 pavel
* Added `set_log_file()' entry point. Made logging print undated messages to
* stderr if they arrive before a log file has been set. Release 1.8.0p3.
diff --git a/log.h b/log.h
index c046ded..bf1ab26 100644
--- a/log.h
+++ b/log.h
@@ -22,8 +22,8 @@
extern void set_log_file(FILE *);
-extern void oklog(const char *, ...);
-extern void errlog(const char *, ...);
+extern void oklog(const char *,...);
+extern void errlog(const char *,...);
extern void log_perror(const char *);
extern void reset_command_history(void);
@@ -31,9 +31,12 @@ extern void log_command_history(void);
extern void add_command_to_history(Objid player, const char *command);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:03 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:48 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:03 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/04/08 01:05:28 pavel
* Added `set_log_file()' entry point. Release 1.8.0p3.
*
diff --git a/malloc.c b/malloc.c
index ed4e6bc..29f443b 100644
--- a/malloc.c
+++ b/malloc.c
@@ -30,8 +30,8 @@
unsigned
malloc_real_size(void *ptr)
{
- char *cp = (char *) ptr;
- struct mhead *p = (struct mhead *) (cp - ((sizeof *p + 7) & ~7));
+ char *cp = (char *) ptr;
+ struct mhead *p = (struct mhead *) (cp - ((sizeof *p + 7) & ~7));
return 1 << (p->mh_index + 3);
}
@@ -39,8 +39,8 @@ malloc_real_size(void *ptr)
unsigned
malloc_size(void *ptr)
{
- char *cp = (char *) ptr;
- struct mhead *p = (struct mhead *) (cp - ((sizeof *p + 7) & ~7));
+ char *cp = (char *) ptr;
+ struct mhead *p = (struct mhead *) (cp - ((sizeof *p + 7) & ~7));
#ifdef rcheck
return p->mh_nbytes;
@@ -49,7 +49,7 @@ malloc_size(void *ptr)
#endif
}
-#else /* !defined(USE_GNU_MALLOC) */
+#else /* !defined(USE_GNU_MALLOC) */
int malloc_dummy; /* Prevent `empty compilation unit' warning */
@@ -58,9 +58,12 @@ int malloc_dummy; /* Prevent `empty compilation unit' warning */
char rcsid_malloc[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:49 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:59:50 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/match.c b/match.c
index da837d8..bb054d6 100644
--- a/match.c
+++ b/match.c
@@ -31,8 +31,8 @@
static Var *
aliases(Objid oid)
{
- Var value;
- db_prop_handle h;
+ Var value;
+ db_prop_handle h;
h = db_find_property(oid, "aliases", &value);
if (!h.ptr || value.type != TYPE_LIST) {
@@ -41,21 +41,21 @@ aliases(Objid oid)
} else
return value.v.list;
}
-
+
struct match_data {
- int lname;
+ int lname;
const char *name;
- Objid exact, partial;
+ Objid exact, partial;
};
static int
match_proc(void *data, Objid oid)
{
- struct match_data *d = data;
- Var *names = aliases(oid);
- int i;
- const char *name;
-
+ struct match_data *d = data;
+ Var *names = aliases(oid);
+ int i;
+ const char *name;
+
for (i = 0; i <= names[0].v.num; i++) {
if (i == 0)
name = db_object_name(oid);
@@ -63,14 +63,14 @@ match_proc(void *data, Objid oid)
continue;
else
name = names[i].v.str;
-
+
if (!mystrncasecmp(name, d->name, d->lname)) {
- if (name[d->lname] == '\0') { /* exact match */
+ if (name[d->lname] == '\0') { /* exact match */
if (d->exact == NOTHING || d->exact == oid)
d->exact = oid;
else
return 1;
- } else { /* partial match */
+ } else { /* partial match */
if (d->partial == FAILED_MATCH || d->partial == oid)
d->partial = oid;
else
@@ -80,15 +80,15 @@ match_proc(void *data, Objid oid)
}
return 0;
-}
+}
static Objid
match_contents(Objid player, const char *name)
{
- Objid loc;
- int step;
- Objid oid;
- struct match_data d;
+ Objid loc;
+ int step;
+ Objid oid;
+ struct match_data d;
d.lname = strlen(name);
d.name = name;
@@ -119,8 +119,8 @@ match_object(Objid player, const char *name)
if (name[0] == '\0')
return NOTHING;
if (name[0] == '#') {
- char *p;
- Objid r = strtol(name + 1, &p, 10);
+ char *p;
+ Objid r = strtol(name + 1, &p, 10);
if (*p != '\0' || !valid(r))
return FAILED_MATCH;
@@ -138,9 +138,12 @@ match_object(Objid player, const char *name)
char rcsid_match[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:50 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:59:41 pavel
* Fixed minor portability problem. Updated copyright notice for 1996.
* Release 1.8.0beta1.
diff --git a/match.h b/match.h
index 3173903..c2a96ad 100644
--- a/match.h
+++ b/match.h
@@ -18,12 +18,15 @@
#include "config.h"
#include "structures.h"
-extern Objid match_object(Objid player, const char *name);
+extern Objid match_object(Objid player, const char *name);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:03 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:50 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:03 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:22:33 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/md5.c b/md5.c
index e42489e..f6de70b 100644
--- a/md5.c
+++ b/md5.c
@@ -17,7 +17,7 @@
/* md5.c
MD5 Message Digest Algorithm implementation.
Ron Frederick
-
+
Derived from RSA Data Security, Inc. MD5 Message-Digest Algorithm
See below for original license notice.
*/
@@ -34,12 +34,12 @@
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
-
+
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
-
+
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
@@ -68,7 +68,8 @@
#define S43 15
#define S44 21
-static uint8 PADDING[64] = {
+static uint8 PADDING[64] =
+{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@@ -122,119 +123,122 @@ static uint8 PADDING[64] = {
/*
* Encodes input (uint32) into output (uint8). Assumes len is a multiple of 4.
*/
-static void md5_Encode(uint8 *output, uint32 *input, int len)
+static void
+md5_Encode(uint8 * output, uint32 * input, int len)
{
unsigned int i, j;
- for (i=0, j=0; j < len; i++, j += 4) {
- output[j] = (uint8)(input[i] & 0xff);
- output[j+1] = (uint8)((input[i] >> 8) & 0xff);
- output[j+2] = (uint8)((input[i] >> 16) & 0xff);
- output[j+3] = (uint8)((input[i] >> 24) & 0xff);
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[j] = (uint8) (input[i] & 0xff);
+ output[j + 1] = (uint8) ((input[i] >> 8) & 0xff);
+ output[j + 2] = (uint8) ((input[i] >> 16) & 0xff);
+ output[j + 3] = (uint8) ((input[i] >> 24) & 0xff);
}
}
/*
* Decodes input (uint8) into output (uint32). Assumes len is a multiple of 4.
*/
-static void md5_Decode(uint32 *output, uint8 *input, int len)
+static void
+md5_Decode(uint32 * output, uint8 * input, int len)
{
unsigned int i, j;
- for (i=0, j=0; j < len; i++, j += 4) {
- output[i] = ((uint32)input[j]) |
- (((uint32)input[j+1]) << 8) |
- (((uint32)input[j+2]) << 16) |
- (((uint32)input[j+3]) << 24);
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[i] = ((uint32) input[j]) |
+ (((uint32) input[j + 1]) << 8) |
+ (((uint32) input[j + 2]) << 16) |
+ (((uint32) input[j + 3]) << 24);
}
}
/*
* MD5 basic transformation. Transforms state based on block.
*/
-static void md5_Transform(uint32 state[4], uint8 block[64])
+static void
+md5_Transform(uint32 state[4], uint8 block[64])
{
uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
-
+
md5_Decode(x, block, 64);
/* Round 1 */
- FF(a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
- FF(d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
- FF(c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
- FF(b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
- FF(a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
- FF(d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
- FF(c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
- FF(b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
- FF(a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
- FF(d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
- FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
- FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
- FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
- FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
- FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
- FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+ FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */
+ FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */
+ FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */
+ FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */
+ FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */
+ FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */
+ FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */
+ FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */
+ FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */
+ FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */
+ FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
- GG(a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
- GG(d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
- GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
- GG(b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
- GG(a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
- GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
- GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
- GG(b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
- GG(a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
- GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
- GG(c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
- GG(b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
- GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
- GG(d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
- GG(c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
- GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+ GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */
+ GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */
+ GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */
+ GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */
+ GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */
+ GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */
+ GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */
+ GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */
+ GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */
+ GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */
+ GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
- HH(a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
- HH(d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
- HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
- HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
- HH(a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
- HH(d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
- HH(c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
- HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
- HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
- HH(d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
- HH(c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
- HH(b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
- HH(a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
- HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
- HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
- HH(b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+ HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */
+ HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */
+ HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */
+ HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */
+ HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */
+ HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */
+ HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */
+ HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */
+ HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */
+ HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
- II(a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
- II(d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
- II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
- II(b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
- II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
- II(d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
- II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
- II(b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
- II(a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
- II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
- II(c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
- II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
- II(a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
- II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
- II(c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
- II(b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+ II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */
+ II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */
+ II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */
+ II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */
+ II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */
+ II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */
+ II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */
+ II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */
+ II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */
+ II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
-
+
/* Zeroize sensitive information */
memset((char *) x, 0, sizeof(x));
}
@@ -242,7 +246,8 @@ static void md5_Transform(uint32 state[4], uint8 block[64])
/*
* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
-void md5_Init(md5ctx_t *context)
+void
+md5_Init(md5ctx_t * context)
{
context->count[0] = context->count[1] = 0;
@@ -257,42 +262,44 @@ void md5_Init(md5ctx_t *context)
* MD5 block update operation. Continues an MD5 message-digest operation,
* processing another message block, and updating the context.
*/
-void md5_Update(md5ctx_t *context, uint8 *buf, int len)
+void
+md5_Update(md5ctx_t * context, uint8 * buf, int len)
{
unsigned int i, index, partLen;
/* Compute number of bytes mod 64 */
- index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+ index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
- if ((context->count[0] += ((uint32)len << 3)) < ((uint32)len << 3))
- context->count[1]++;
- context->count[1] += ((uint32)len >> 29);
-
- partLen = 64-index;
-
+ if ((context->count[0] += ((uint32) len << 3)) < ((uint32) len << 3))
+ context->count[1]++;
+ context->count[1] += ((uint32) len >> 29);
+
+ partLen = 64 - index;
+
/* Transform as many times as possible */
if (len >= partLen) {
- memcpy((char *) &context->buffer[index], (char *)buf, partLen);
+ memcpy((char *) &context->buffer[index], (char *) buf, partLen);
md5_Transform(context->state, context->buffer);
-
- for (i=partLen; i+63 < len; i += 64)
+
+ for (i = partLen; i + 63 < len; i += 64)
md5_Transform(context->state, &buf[i]);
-
+
index = 0;
} else {
i = 0;
}
-
+
/* Buffer remaining input */
- memcpy((char *) &context->buffer[index], (char *)&buf[i], len-i);
+ memcpy((char *) &context->buffer[index], (char *) &buf[i], len - i);
}
/*
* MD5 finalization. Ends an MD5 message-digest operation, writing the
* the message digest and zeroizing the context.
*/
-void md5_Final(md5ctx_t *context, uint8 digest[16])
+void
+md5_Final(md5ctx_t * context, uint8 digest[16])
{
uint8 bits[8];
unsigned int index, padLen;
@@ -301,24 +308,27 @@ void md5_Final(md5ctx_t *context, uint8 digest[16])
md5_Encode(bits, context->count, 8);
/* Pad out to 56 mod 64 */
- index = (unsigned int)((context->count[0] >> 3) & 0x3f);
- padLen = (index < 56) ? (56-index) : (120-index);
+ index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
+ padLen = (index < 56) ? (56 - index) : (120 - index);
md5_Update(context, PADDING, padLen);
-
+
/* Append length (before padding) */
md5_Update(context, bits, 8);
/* Store state in digest */
md5_Encode(digest, context->state, 16);
-
+
/* Zeroize sensitive information */
memset((char *) context, 0, sizeof(*context));
}
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:51 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 1.1 1996/02/18 23:19:18 pavel
* Initial revision
*
diff --git a/md5.h b/md5.h
index 797e444..ae96acd 100644
--- a/md5.h
+++ b/md5.h
@@ -34,12 +34,12 @@
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
-
+
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
-
+
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
@@ -49,26 +49,29 @@
#include "config.h"
-typedef unsigned char uint8;
-typedef unsigned32 uint32;
+typedef unsigned char uint8;
+typedef unsigned32 uint32;
/* MD5 context. */
typedef struct {
- uint32 state[4]; /* state (ABCD) */
- uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
- uint8 buffer[64]; /* input buffer */
+ uint32 state[4]; /* state (ABCD) */
+ uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ uint8 buffer[64]; /* input buffer */
} md5ctx_t;
-void md5_Init(md5ctx_t *context);
-void md5_Update(md5ctx_t *context, uint8 *buf, int len);
-void md5_Final(md5ctx_t *context, uint8 digest[16]);
+void md5_Init(md5ctx_t * context);
+void md5_Update(md5ctx_t * context, uint8 * buf, int len);
+void md5_Final(md5ctx_t * context, uint8 digest[16]);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:52 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 1.1 1996/02/18 23:18:53 pavel
* Initial revision
*
diff --git a/my-ctype.h b/my-ctype.h
index bde266a..e86b3bb 100644
--- a/my-ctype.h
+++ b/my-ctype.h
@@ -22,16 +22,19 @@
#include <ctype.h>
#if NDECL_TOLOWER
-extern int tolower(int);
-extern int toupper(int);
+extern int tolower(int);
+extern int toupper(int);
#endif
-#endif /* !My_Ctype_H */
+#endif /* !My_Ctype_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:52 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:05:23 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-fcntl.h b/my-fcntl.h
index dd9407b..3ff6015 100644
--- a/my-fcntl.h
+++ b/my-fcntl.h
@@ -20,8 +20,8 @@
#include <fcntl.h>
#if NDECL_FCNTL
-extern int fcntl(int, int, ...);
-extern int open(const char *, int, ...);
+extern int fcntl(int, int,...);
+extern int open(const char *, int,...);
#endif
#if POSIX_NONBLOCKING_WORKS
@@ -32,9 +32,12 @@ extern int open(const char *, int, ...);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:52 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:05:07 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-in.h b/my-in.h
index 09e2c97..3472cfc 100644
--- a/my-in.h
+++ b/my-in.h
@@ -30,10 +30,10 @@
#else
# if !defined(htonl) && NDECL_HTONL
- extern unsigned short htons();
- extern unsigned32 htonl();
- extern unsigned short ntohs();
- extern unsigned32 ntohl();
+extern unsigned short htons();
+extern unsigned32 htonl();
+extern unsigned short ntohs();
+extern unsigned32 ntohl();
# endif
#endif
@@ -41,9 +41,12 @@
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:53 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:04:58 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-ioctl.h b/my-ioctl.h
index 3f1d60e..4e42118 100644
--- a/my-ioctl.h
+++ b/my-ioctl.h
@@ -20,13 +20,16 @@
#include <sys/ioctl.h>
#if NDECL_IOCTL
-extern int ioctl(int, int, ...);
+extern int ioctl(int, int,...);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:53 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:04:38 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-signal.h b/my-signal.h
index 9bf92c1..fdb0db1 100644
--- a/my-signal.h
+++ b/my-signal.h
@@ -27,20 +27,20 @@
#if NDECL_KILL
#include "my-types.h"
-extern int kill(pid_t, int);
+extern int kill(pid_t, int);
#endif
#if NDECL_SIGEMPTYSET && HAVE_SIGEMPTYSET
-extern int sigemptyset(sigset_t *);
-extern int sigaddset(sigset_t *, int);
+extern int sigemptyset(sigset_t *);
+extern int sigaddset(sigset_t *, int);
#endif
#if NDECL_SIGPROCMASK && HAVE_SIGPROCMASK
-extern int sigprocmask(int, sigset_t *, sigset_t *);
+extern int sigprocmask(int, sigset_t *, sigset_t *);
#endif
#if NDECL_SIGRELSE && HAVE_SIGRELSE
-extern int sigrelse(int);
+extern int sigrelse(int);
#endif
#ifndef SIGCHLD
@@ -48,9 +48,12 @@ extern int sigrelse(int);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:54 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:03:00 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-socket.h b/my-socket.h
index ae4c38f..3fa4062 100644
--- a/my-socket.h
+++ b/my-socket.h
@@ -27,26 +27,29 @@
#include <sys/socket.h>
#if NDECL_ACCEPT
-extern int accept(int, struct sockaddr *, int *);
-extern int listen(int, int);
-extern int setsockopt(int, int, int, const char *, int);
-extern int socket(int, int, int);
+extern int accept(int, struct sockaddr *, int *);
+extern int listen(int, int);
+extern int setsockopt(int, int, int, const char *, int);
+extern int socket(int, int, int);
#endif
#if NDECL_BIND
-extern int bind(int, struct sockaddr *, int);
-extern int getsockname(int, struct sockaddr *, int *);
-extern int connect(int, struct sockaddr *, int);
+extern int bind(int, struct sockaddr *, int);
+extern int getsockname(int, struct sockaddr *, int *);
+extern int connect(int, struct sockaddr *, int);
#endif
#if NDECL_SHUTDOWN
-extern int shutdown(int, int);
+extern int shutdown(int, int);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:54 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/02/08 06:02:39 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-stat.h b/my-stat.h
index 15ebf92..a5c4168 100644
--- a/my-stat.h
+++ b/my-stat.h
@@ -26,9 +26,9 @@
#if NDECL_FSTAT
#include "my-types.h"
-extern int stat(const char *, struct stat *);
-extern int fstat(int, struct stat *);
-extern int mkfifo(const char *, mode_t);
+extern int stat(const char *, struct stat *);
+extern int fstat(int, struct stat *);
+extern int mkfifo(const char *, mode_t);
#endif
#if !HAVE_MKFIFO
@@ -37,9 +37,12 @@ extern int mknod(const char *file, int mode, int dev);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:55 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.3 1996/02/08 06:02:22 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-stdarg.h b/my-stdarg.h
index b2996e4..aceb74c 100644
--- a/my-stdarg.h
+++ b/my-stdarg.h
@@ -36,7 +36,7 @@
#ifndef _VA_LIST_
#define _VA_LIST_ 1
-typedef void *va_list;
+typedef void *va_list;
#endif
#define va_start(ptr, arg) \
@@ -47,18 +47,21 @@ typedef void *va_list;
#define va_end(ptr)
-#endif /* STDARG_H */
+#endif /* STDARG_H */
#else
#include <stdarg.h>
-#endif /* BUGGY_STDARG */
+#endif /* BUGGY_STDARG */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:55 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:02:14 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-stdio.h b/my-stdio.h
index 9144b90..1211475 100644
--- a/my-stdio.h
+++ b/my-stdio.h
@@ -25,31 +25,31 @@
#if NDECL_FCLOSE
#include "my-types.h"
-extern int fclose(FILE *);
-extern int fflush(FILE *);
-extern size_t fwrite(const void *, size_t, size_t, FILE *);
-extern int fgetc(FILE *);
-extern int fprintf(FILE *, const char *, ...);
-extern int fscanf(FILE *, const char *, ...);
-extern int sscanf(const char *, const char *, ...);
-extern int printf(const char *, ...);
-extern int ungetc(int, FILE *);
+extern int fclose(FILE *);
+extern int fflush(FILE *);
+extern size_t fwrite(const void *, size_t, size_t, FILE *);
+extern int fgetc(FILE *);
+extern int fprintf(FILE *, const char *,...);
+extern int fscanf(FILE *, const char *,...);
+extern int sscanf(const char *, const char *,...);
+extern int printf(const char *,...);
+extern int ungetc(int, FILE *);
#endif
#if NDECL_PERROR
-extern void perror(const char *);
+extern void perror(const char *);
#endif
#if NDECL_REMOVE
-extern int remove(const char *);
-extern int rename(const char *, const char *);
+extern int remove(const char *);
+extern int rename(const char *, const char *);
#endif
#if NDECL_VFPRINTF
#include "my-stdarg.h"
-extern int vfprintf(FILE *, const char *, va_list);
-extern int vfscanf(FILE *, const char *, va_list);
+extern int vfprintf(FILE *, const char *, va_list);
+extern int vfscanf(FILE *, const char *, va_list);
#endif
#if !HAVE_REMOVE
@@ -62,12 +62,15 @@ extern int vfscanf(FILE *, const char *, va_list);
# define rename(old, new) (link(old, new) && unlink(old))
#endif
-#endif /* !My_Stdio_H */
+#endif /* !My_Stdio_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:56 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/02/08 06:02:04 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-stdlib.h b/my-stdlib.h
index a939a6b..564b079 100644
--- a/my-stdlib.h
+++ b/my-stdlib.h
@@ -28,51 +28,54 @@
#include <malloc.h>
#endif
-#else /* !HAVE_STDLIB_H */
+#else /* !HAVE_STDLIB_H */
#include "my-types.h"
-extern void abort(void);
-extern int abs(int);
-extern void exit(int);
-extern void free(void *);
-extern void *malloc(size_t);
-extern int rand(void);
-extern void *realloc(void *, size_t);
-extern void srand(unsigned);
+extern void abort(void);
+extern int abs(int);
+extern void exit(int);
+extern void free(void *);
+extern void *malloc(size_t);
+extern int rand(void);
+extern void *realloc(void *, size_t);
+extern void srand(unsigned);
-#endif /* !HAVE_STDLIB_H */
+#endif /* !HAVE_STDLIB_H */
#if NDECL_STRTOD
- extern double strtod(const char *, char **);
+extern double strtod(const char *, char **);
#endif
#if NDECL_STRTOL
- extern long strtol(const char *, char **, int);
+extern long strtol(const char *, char **, int);
#endif
#if HAVE_STRTOUL
# if NDECL_STRTOUL
- extern unsigned long strtoul(const char *, char **, int);
+extern unsigned long strtoul(const char *, char **, int);
# endif
#else
# define strtoul strtol
#endif
#if NDECL_RANDOM
-extern int random(void);
+extern int random(void);
#endif
#if NDECL_SRANDOM
-extern int srandom(unsigned);
+extern int srandom(unsigned);
#endif
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:56 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:01:42 pavel
* Updated copyright notice for 1996. Added strtod(). Release 1.8.0beta1.
*
diff --git a/my-string.h b/my-string.h
index b5a7d07..2beb032 100644
--- a/my-string.h
+++ b/my-string.h
@@ -24,24 +24,24 @@
#include "my-types.h"
-extern void bzero(char *, int);
-extern void *memset(void *, int, size_t);
-extern char *strcpy(char *, const char *);
-extern char *strncpy(char *, const char *, size_t);
-extern char *strcat(char *, const char *);
-extern int strcmp(const char *, const char *);
-extern int strncmp(const char *, const char *, size_t);
-extern char *strchr(const char *, int);
-extern char *strerror(int);
+extern void bzero(char *, int);
+extern void *memset(void *, int, size_t);
+extern char *strcpy(char *, const char *);
+extern char *strncpy(char *, const char *, size_t);
+extern char *strcat(char *, const char *);
+extern int strcmp(const char *, const char *);
+extern int strncmp(const char *, const char *, size_t);
+extern char *strchr(const char *, int);
+extern char *strerror(int);
/* We don't need to declare these because we're only using our own string.h
* due to GCC complaining about conflicting built-in declarations for them.
*/
#if 0
-extern void *memcpy(void *, const void *, size_t);
-extern int memcmp(const void *, const void *, size_t);
-extern size_t strlen(const char *);
+extern void *memcpy(void *, const void *, size_t);
+extern int memcmp(const void *, const void *, size_t);
+extern size_t strlen(const char *);
#endif
#else
@@ -53,8 +53,8 @@ extern size_t strlen(const char *);
# else
# if NDECL_MEMCPY
# include "my-types.h"
- extern void *memcpy(void *, const void *, size_t);
- extern int memcmp(const void *, const void *, size_t);
+extern void *memcpy(void *, const void *, size_t);
+extern int memcmp(const void *, const void *, size_t);
# endif
# endif
@@ -62,10 +62,10 @@ extern size_t strlen(const char *);
#if HAVE_STRERROR
# if NDECL_STRERROR
- extern char *strerror(int);
+extern char *strerror(int);
# endif
#else
- extern const char *sys_errlist[];
+extern const char *sys_errlist[];
# define strerror(error_code) sys_errlist[error_code]
#endif
@@ -73,22 +73,25 @@ extern size_t strlen(const char *);
# if BZERO_IN_STDLIB_H
# include "my-stdlib.h"
# else
- extern void bzero(char *, int);
+extern void bzero(char *, int);
# endif
#endif
#if NDECL_MEMSET
#include "my-types.h"
-extern void *memset(void *, int, size_t);
+extern void *memset(void *, int, size_t);
#endif
-#endif /* !My_String_H */
+#endif /* !My_String_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:57 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:01:23 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-sys-time.h b/my-sys-time.h
index 82f21a0..5a5bab7 100644
--- a/my-sys-time.h
+++ b/my-sys-time.h
@@ -26,23 +26,26 @@
#endif
#if NDECL_GETITIMER
-extern int getitimer(int, struct itimerval *);
+extern int getitimer(int, struct itimerval *);
#endif
#if NDECL_SETITIMER
-extern int setitimer(int, struct itimerval *, struct itimerval *);
+extern int setitimer(int, struct itimerval *, struct itimerval *);
#endif
#if NDECL_SELECT && MPLEX_STYLE == MP_SELECT
#include "my-types.h"
-extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
+extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:57 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:01:00 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-time.h b/my-time.h
index 783a728..b160151 100644
--- a/my-time.h
+++ b/my-time.h
@@ -30,7 +30,7 @@
#if NDECL_TIME
#include "my-types.h"
-extern time_t time(time_t *);
+extern time_t time(time_t *);
#endif
#if defined(MACH) && defined(CMU)
@@ -41,20 +41,23 @@ extern time_t time(time_t *);
#if HAVE_STRFTIME && NDECL_STRFTIME
#include "my-types.h"
-extern size_t strftime(char *s, size_t smax, const char *fmt,
- const struct tm *tp);
+extern size_t strftime(char *s, size_t smax, const char *fmt,
+ const struct tm *tp);
#endif
#if HAVE_TZNAME && NDECL_TZNAME
-extern char *tzname;
+extern char *tzname;
#endif
-#endif /* !My_Time_H */
+#endif /* !My_Time_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:58 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:00:41 pavel
* *** empty log message ***
*
diff --git a/my-tiuser.h b/my-tiuser.h
index b278cbf..9af2db3 100644
--- a/my-tiuser.h
+++ b/my-tiuser.h
@@ -20,25 +20,28 @@
#include <tiuser.h>
#if NDECL_T_OPEN
-extern int t_accept(int, int, struct t_call *);
-extern void *t_alloc(int, int, int);
-extern int t_bind(int, struct t_bind *, struct t_bind *);
-extern int t_close(int);
-extern int t_connect(int, struct t_call *, struct t_call *);
-extern int t_listen(int, struct t_call *);
-extern int t_open(const char *, int, struct t_info *);
+extern int t_accept(int, int, struct t_call *);
+extern void *t_alloc(int, int, int);
+extern int t_bind(int, struct t_bind *, struct t_bind *);
+extern int t_close(int);
+extern int t_connect(int, struct t_call *, struct t_call *);
+extern int t_listen(int, struct t_call *);
+extern int t_open(const char *, int, struct t_info *);
-extern int t_errno;
+extern int t_errno;
#endif
#if NDECL_T_ERRLIST
-extern char *t_errlist[];
+extern char *t_errlist[];
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:58 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:00:32 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-types.h b/my-types.h
index 8edbbb9..f2a81fa 100644
--- a/my-types.h
+++ b/my-types.h
@@ -31,14 +31,17 @@
#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
#define FD_SET(n, p) ((p)->fds_bits[0] |= (1L<<((n)%NFDBITS)))
#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1L<<((n)%NFDBITS)))
-#endif /* FD_ZERO */
+#endif /* FD_ZERO */
-#endif /* !My_Types_h */
+#endif /* !My_Types_h */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:58 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:00:13 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-unistd.h b/my-unistd.h
index acfe357..291e57b 100644
--- a/my-unistd.h
+++ b/my-unistd.h
@@ -26,26 +26,29 @@
#include "my-types.h"
extern unsigned alarm(unsigned);
-extern int chmod(const char *, mode_t);
-extern int close(int);
-extern int dup(int);
-extern void _exit(int);
-extern pid_t fork(void);
-extern pid_t getpid(void);
-extern int link(const char *, const char *);
-extern int pause(void);
-extern int pipe(int *fds);
-extern int read(int, void *, unsigned);
+extern int chmod(const char *, mode_t);
+extern int close(int);
+extern int dup(int);
+extern void _exit(int);
+extern pid_t fork(void);
+extern pid_t getpid(void);
+extern int link(const char *, const char *);
+extern int pause(void);
+extern int pipe(int *fds);
+extern int read(int, void *, unsigned);
extern unsigned sleep(unsigned);
-extern int unlink(const char *);
-extern int write(int, const void *, unsigned);
+extern int unlink(const char *);
+extern int write(int, const void *, unsigned);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:18:59 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:00:01 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/my-wait.h b/my-wait.h
index 1af8d5b..3a775d3 100644
--- a/my-wait.h
+++ b/my-wait.h
@@ -21,13 +21,16 @@
#if NDECL_WAITPID
#include "my-types.h"
-extern pid_t waitpid(pid_t, int *, int);
+extern pid_t waitpid(pid_t, int *, int);
#endif
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:05 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:00 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:05 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 05:58:27 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/name_lookup.c b/name_lookup.c
index daec035..3a6b4e4 100644
--- a/name_lookup.c
+++ b/name_lookup.c
@@ -30,7 +30,7 @@
#include "my-unistd.h"
#include "my-inet.h" /* inet_addr() */
#include "my-in.h" /* struct sockaddr_in, INADDR_ANY, htons(),
- * htonl(), ntohl(), struct in_addr */
+ * htonl(), ntohl(), struct in_addr */
#include <netdb.h> /* struct hostent, gethostbyaddr() */
#include "my-socket.h" /* AF_INET */
#include "my-wait.h"
@@ -48,11 +48,11 @@
*****************************************************************************/
static pid_t
-spawn_pipe(void (*child_proc)(int to_parent, int from_parent),
+spawn_pipe(void (*child_proc) (int to_parent, int from_parent),
int *to_child, int *from_child)
{
- int pipe_to_child[2], pipe_from_child[2];
- pid_t pid;
+ int pipe_to_child[2], pipe_from_child[2];
+ pid_t pid;
if (pipe(pipe_to_child) < 0) {
log_perror("SPAWNING: Couldn't create first pipe");
@@ -67,8 +67,8 @@ spawn_pipe(void (*child_proc)(int to_parent, int from_parent),
close(pipe_from_child[0]);
close(pipe_from_child[1]);
} else if (pid != 0) { /* parent */
- int status;
-
+ int status;
+
close(pipe_to_child[0]);
close(pipe_from_child[1]);
*to_child = pipe_to_child[1];
@@ -99,7 +99,7 @@ spawn_pipe(void (*child_proc)(int to_parent, int from_parent),
write(pipe_from_child[1], &pid, sizeof(pid));
exit(0);
} else { /* finally, the child */
- (*child_proc)(pipe_from_child[1], pipe_to_child[0]);
+ (*child_proc) (pipe_from_child[1], pipe_to_child[0]);
exit(0);
}
}
@@ -124,7 +124,7 @@ robust_read(int fd, void *buffer, int len)
int count;
do {
- count = read(fd, buffer, len);
+ count = read(fd, buffer, len);
} while (count == -1 && errno == EINTR);
return count;
@@ -135,11 +135,13 @@ robust_read(int fd, void *buffer, int len)
*****************************************************************************/
struct request {
- enum { REQ_NAME_FROM_ADDR, REQ_ADDR_FROM_NAME } kind;
- unsigned timeout;
+ enum {
+ REQ_NAME_FROM_ADDR, REQ_ADDR_FROM_NAME
+ } kind;
+ unsigned timeout;
union {
- unsigned length;
- struct sockaddr_in address;
+ unsigned length;
+ struct sockaddr_in address;
} u;
};
@@ -156,11 +158,11 @@ timeout_proc(Timer_ID id, Timer_Data data)
static void
lookup(int to_intermediary, int from_intermediary)
{
- struct request req;
- static char *buffer = 0;
- static int buflen = 0;
- Timer_ID id;
- struct hostent *e;
+ struct request req;
+ static char *buffer = 0;
+ static int buflen = 0;
+ Timer_ID id;
+ struct hostent *e;
set_server_cmdline("(MOO name-lookup slave)");
/* Read requests and do them. Before each, we set a timer. If it
@@ -184,15 +186,15 @@ lookup(int to_intermediary, int from_intermediary)
if (e && e->h_length == sizeof(unsigned32))
write(to_intermediary, e->h_addr_list[0], e->h_length);
else {
- unsigned32 addr;
+ unsigned32 addr;
/* This cast is for the same reason as the one above... */
addr = inet_addr((void *) buffer);
write(to_intermediary, &addr, sizeof(addr));
- }
+ }
} else {
const char *host_name;
- int length;
+ int length;
id = set_timer(req.timeout, timeout_proc, 0);
e = gethostbyaddr((void *) &req.u.address.sin_addr,
sizeof(req.u.address.sin_addr),
@@ -210,8 +212,8 @@ lookup(int to_intermediary, int from_intermediary)
* Code that runs in the intermediary process.
*****************************************************************************/
-static int to_lookup, from_lookup;
-static pid_t lookup_pid;
+static int to_lookup, from_lookup;
+static pid_t lookup_pid;
static void
restart_lookup(void)
@@ -227,17 +229,17 @@ restart_lookup(void)
oklog("NAME_LOOKUP: Started new lookup process\n");
else
errlog("NAME_LOOKUP: Can't spawn lookup process; "
- "will try again later...\n");
+ "will try again later...\n");
}
static void
intermediary(int to_server, int from_server)
{
- struct request req;
- static char *buffer = 0;
- static int buflen = 0;
- int len;
- unsigned32 addr;
+ struct request req;
+ static char *buffer = 0;
+ static int buflen = 0;
+ int len;
+ unsigned32 addr;
set_server_cmdline("(MOO name-lookup master)");
signal(SIGPIPE, SIG_IGN);
@@ -262,8 +264,7 @@ intermediary(int to_server, int from_server)
addr = 0;
}
write(to_server, &addr, sizeof(addr));
- }
- else {
+ } else {
if (robust_read(from_lookup, &len, sizeof(len))
!= sizeof(len)) {
restart_lookup();
@@ -281,7 +282,7 @@ intermediary(int to_server, int from_server)
write(to_server, buffer, len);
}
} else { /* Lookup dead and wouldn't restart ... */
- int failure = 0;
+ int failure = 0;
write(to_server, &failure, sizeof(failure));
}
@@ -293,8 +294,8 @@ intermediary(int to_server, int from_server)
* Code that runs in the server process.
*****************************************************************************/
-static int to_intermediary, from_intermediary;
-static int dead_intermediary = 0;
+static int to_intermediary, from_intermediary;
+static int dead_intermediary = 0;
int
@@ -315,10 +316,10 @@ abandon_intermediary(const char *prefix)
const char *
lookup_name_from_addr(struct sockaddr_in *addr, unsigned timeout)
{
- struct request req;
- static char *buffer = 0;
- static int buflen = 0;
- int len;
+ struct request req;
+ static char *buffer = 0;
+ static int buflen = 0;
+ int len;
if (!dead_intermediary) {
req.kind = REQ_NAME_FROM_ADDR;
@@ -333,22 +334,21 @@ lookup_name_from_addr(struct sockaddr_in *addr, unsigned timeout)
ensure_buffer(&buffer, &buflen, len + 1);
if (robust_read(from_intermediary, buffer, len) != len)
abandon_intermediary("LOOKUP_NAME: "
- "Data-read from intermediary failed");
+ "Data-read from intermediary failed");
else {
buffer[len] = '\0';
return buffer;
}
}
}
-
/* Either the intermediary is presumed dead, or else it failed to produce
* a name; in either case, we must fall back on a the default, dotted-
* decimal notation.
*/
{
- static char decimal[20];
- unsigned32 a = ntohl(addr->sin_addr.s_addr);
+ static char decimal[20];
+ unsigned32 a = ntohl(addr->sin_addr.s_addr);
sprintf(decimal, "%u.%u.%u.%u",
(unsigned) (a >> 24) & 0xff, (unsigned) (a >> 16) & 0xff,
@@ -356,12 +356,12 @@ lookup_name_from_addr(struct sockaddr_in *addr, unsigned timeout)
return decimal;
}
}
-
+
unsigned32
lookup_addr_from_name(const char *name, unsigned timeout)
{
- struct request req;
- unsigned32 addr = 0;
+ struct request req;
+ unsigned32 addr = 0;
if (dead_intermediary) {
/* Numeric addresses should always work... */
@@ -380,15 +380,18 @@ lookup_addr_from_name(const char *name, unsigned timeout)
return addr == 0xffffffff ? 0 : addr;
}
-
-#endif /* NETWORK_PROTOCOL == NP_TCP */
+
+#endif /* NETWORK_PROTOCOL == NP_TCP */
char rcsid_name_lookup[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:00 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.2 1996/02/08 06:59:04 pavel
* Renamed err/logf() to errlog/oklog(). Updated copyright notice for 1996.
* Release 1.8.0beta1.
diff --git a/name_lookup.h b/name_lookup.h
index bceb745..a10930f 100644
--- a/name_lookup.h
+++ b/name_lookup.h
@@ -26,21 +26,21 @@
#include "config.h"
-extern int initialize_name_lookup(void);
+extern int initialize_name_lookup(void);
/* Initialize the module, returning true iff
* this succeeds.
*/
-extern unsigned32 lookup_addr_from_name(const char *name,
- unsigned timeout);
+extern unsigned32 lookup_addr_from_name(const char *name,
+ unsigned timeout);
/* Translate a host name to a 32-bit
* internet address in host byte order. If
* anything goes wrong, return 0. Dotted
* decimal address are translated properly.
*/
-extern const char *lookup_name_from_addr(struct sockaddr_in *addr,
- unsigned timeout);
+extern const char *lookup_name_from_addr(struct sockaddr_in *addr,
+ unsigned timeout);
/* Translate an internet address, contained
* in the sockaddr_in, to a host name. If
* the translation cannot be done, the
@@ -48,12 +48,15 @@ extern const char *lookup_name_from_addr(struct sockaddr_in *addr,
* form.
*/
-#endif /* Name_Lookup_H */
+#endif /* Name_Lookup_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:01 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.0 1995/11/30 05:07:03 pavel
* New baseline version, corresponding to release 1.8.0alpha1.
*
diff --git a/net_bsd_lcl.c b/net_bsd_lcl.c
index 9f38993..f61b431 100644
--- a/net_bsd_lcl.c
+++ b/net_bsd_lcl.c
@@ -20,8 +20,8 @@
#include <errno.h> /* EMFILE */
#include "my-socket.h" /* socket(), AF_UNIX, SOCK_STREAM,
- * bind(), struct sockaddr, accept(),
- * shutdown(), connect() */
+ * bind(), struct sockaddr, accept(),
+ * shutdown(), connect() */
#include "my-stdio.h" /* remove() */
#include "my-string.h" /* strcpy() */
#include <sys/un.h> /* struct sockaddr_un */
@@ -35,9 +35,9 @@
#include "utils.h"
typedef struct listener {
- struct listener *next;
- int fd;
- const char *filename;
+ struct listener *next;
+ int fd;
+ const char *filename;
} listener;
static listener *all_listeners = 0;
@@ -55,7 +55,7 @@ proto_usage_string(void)
}
int
-proto_initialize(struct proto *proto, Var *desc, int argc, char **argv)
+proto_initialize(struct proto *proto, Var * desc, int argc, char **argv)
{
const char *connect_file = DEFAULT_CONNECT_FILE;
@@ -68,19 +68,18 @@ proto_initialize(struct proto *proto, Var *desc, int argc, char **argv)
else if (argc == 1) {
connect_file = argv[0];
}
-
desc->type = TYPE_STR;
desc->v.str = str_dup(connect_file);
return 1;
}
enum error
-proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
+proto_make_listener(Var desc, int *fd, Var * canon, const char **name)
{
- struct sockaddr_un address;
- int s;
- const char *connect_file;
- listener *l;
+ struct sockaddr_un address;
+ int s;
+ const char *connect_file;
+ listener *l;
if (desc.type != TYPE_STR)
return E_TYPE;
@@ -91,12 +90,11 @@ proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
log_perror("Creating listening socket");
return E_QUOTA;
}
-
address.sun_family = AF_UNIX;
strcpy(address.sun_path, connect_file);
if (bind(s, (struct sockaddr *) &address,
sizeof(address.sun_family) + strlen(connect_file))) {
- enum error e = E_QUOTA;
+ enum error e = E_QUOTA;
log_perror("Binding listening socket");
if (errno == EACCES)
@@ -104,7 +102,6 @@ proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
close(s);
return e;
}
-
l = mymalloc(sizeof(listener), M_NETWORK);
l->next = all_listeners;
all_listeners = l;
@@ -128,9 +125,9 @@ enum proto_accept_error
proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
const char **name)
{
- int fd;
- static struct sockaddr_un address;
- int addr_length = sizeof(address);
+ int fd;
+ static struct sockaddr_un address;
+ int addr_length = sizeof(address);
fd = accept(listener_fd, (struct sockaddr *) &address, &addr_length);
if (fd < 0) {
@@ -141,7 +138,6 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
return PA_OTHER;
}
}
-
*read_fd = *write_fd = fd;
*name = "??";
return PA_OKAY;
@@ -157,10 +153,10 @@ proto_close_connection(int read_fd, int write_fd)
void
proto_close_listener(int fd)
{
- listener *l, **ll;
+ listener *l, **ll;
for (l = all_listeners, ll = &all_listeners; l; ll = &(l->next),
- l = l->next)
+ l = l->next)
if (l->fd == fd) {
close(l->fd);
remove(l->filename);
@@ -170,16 +166,18 @@ proto_close_listener(int fd)
myfree(l, M_NETWORK);
return;
}
-
errlog("Can't find fd in PROTO_CLOSE_LISTENER!\n");
}
char rcsid_net_bsd_lcl[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:02 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.4 1996/03/10 01:13:22 pavel
* Moved definition of DEFAULT_CONNECT_FILE to options.h. Release 1.8.0.
*
diff --git a/net_bsd_tcp.c b/net_bsd_tcp.c
index 3291c5a..03d5c63 100644
--- a/net_bsd_tcp.c
+++ b/net_bsd_tcp.c
@@ -19,13 +19,13 @@
#include "my-inet.h" /* inet_addr() */
#include <errno.h> /* EMFILE, EADDRNOTAVAIL, ECONNREFUSED,
- * ENETUNREACH, ETIMEOUT */
+ * ENETUNREACH, ETIMEOUT */
#include "my-in.h" /* struct sockaddr_in, INADDR_ANY, htons(),
- * htonl(), ntohl(), struct in_addr */
+ * htonl(), ntohl(), struct in_addr */
#include "my-socket.h" /* socket(), AF_INET, SOCK_STREAM,
- * setsockopt(), SOL_SOCKET, SO_REUSEADDR,
- * bind(), struct sockaddr, accept(),
- * connect() */
+ * setsockopt(), SOL_SOCKET, SO_REUSEADDR,
+ * bind(), struct sockaddr, accept(),
+ * connect() */
#include "my-stdlib.h" /* strtoul() */
#include "my-string.h" /* memcpy() */
#include "my-unistd.h" /* close() */
@@ -54,11 +54,11 @@ proto_usage_string(void)
}
int
-proto_initialize(struct proto *proto, Var *desc, int argc, char **argv)
+proto_initialize(struct proto *proto, Var * desc, int argc, char **argv)
{
- int port = DEFAULT_PORT;
- char *p;
-
+ int port = DEFAULT_PORT;
+ char *p;
+
initialize_name_lookup();
proto->pocket_size = 1;
@@ -72,18 +72,17 @@ proto_initialize(struct proto *proto, Var *desc, int argc, char **argv)
if (*p != '\0')
return 0;
}
-
desc->type = TYPE_INT;
desc->v.num = port;
return 1;
}
enum error
-proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
+proto_make_listener(Var desc, int *fd, Var * canon, const char **name)
{
- struct sockaddr_in address;
- int s, port, option = 1;
- static Stream *st = 0;
+ struct sockaddr_in address;
+ int s, port, option = 1;
+ static Stream *st = 0;
if (!st)
st = new_stream(20);
@@ -107,7 +106,7 @@ proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
address.sin_addr.s_addr = htonl(INADDR_ANY);
address.sin_port = htons(port);
if (bind(s, (struct sockaddr *) &address, sizeof(address)) < 0) {
- enum error e = E_QUOTA;
+ enum error e = E_QUOTA;
log_perror("Binding listening socket");
if (errno == EACCES)
@@ -115,10 +114,9 @@ proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
close(s);
return e;
}
-
if (port == 0) {
- int length = sizeof(address);
-
+ int length = sizeof(address);
+
if (getsockname(s, (struct sockaddr *) &address, &length) < 0) {
log_perror("Discovering local port number");
close(s);
@@ -147,11 +145,11 @@ enum proto_accept_error
proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
const char **name)
{
- int timeout = server_int_option("name_lookup_timeout", 5);
- int fd;
- struct sockaddr_in address;
- int addr_length = sizeof(address);
- static Stream *s = 0;
+ int timeout = server_int_option("name_lookup_timeout", 5);
+ int fd;
+ struct sockaddr_in address;
+ int addr_length = sizeof(address);
+ static Stream *s = 0;
if (!s)
s = new_stream(100);
@@ -165,7 +163,6 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
return PA_OTHER;
}
}
-
*read_fd = *write_fd = fd;
stream_printf(s, "%s, port %d",
lookup_name_from_addr(&address, timeout),
@@ -192,7 +189,7 @@ proto_close_listener(int fd)
#include "exceptions.h"
#include "structures.h"
-static Exception timeout_exception;
+static Exception timeout_exception;
static void
timeout_proc(Timer_ID id, Timer_Data data)
@@ -208,19 +205,18 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
* getting all those nasty little parameter-passing rules right. This
* function isn't recursive anyway, so it doesn't matter.
*/
- static const char *host_name;
- static int port;
- static Timer_ID id;
- int s, result, length;
- int timeout = server_int_option("name_lookup_timeout", 5);
- static struct sockaddr_in addr;
- static Stream *st1 = 0, *st2 = 0;
+ static const char *host_name;
+ static int port;
+ static Timer_ID id;
+ int s, result, length;
+ int timeout = server_int_option("name_lookup_timeout", 5);
+ static struct sockaddr_in addr;
+ static Stream *st1 = 0, *st2 = 0;
if (!st1) {
st1 = new_stream(20);
st2 = new_stream(50);
}
-
if (arglist.v.list[0].v.num != 2)
return E_ARGS;
else if (arglist.v.list[1].type != TYPE_STR ||
@@ -242,36 +238,33 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
log_perror("Making socket in proto_open_connection");
return E_QUOTA;
}
-
TRY
id = set_timer(server_int_option("outbound_connect_timeout", 5),
timeout_proc, 0);
- result = connect(s, (struct sockaddr *) &addr, sizeof(addr));
- cancel_timer(id);
- EXCEPT (timeout_exception)
+ result = connect(s, (struct sockaddr *) &addr, sizeof(addr));
+ cancel_timer(id);
+ EXCEPT(timeout_exception)
result = -1;
- errno = ETIMEDOUT;
- reenable_timers();
+ errno = ETIMEDOUT;
+ reenable_timers();
ENDTRY
- if (result < 0) {
+ if (result < 0) {
close(s);
if (errno == EADDRNOTAVAIL ||
- errno == ECONNREFUSED ||
- errno == ENETUNREACH ||
+ errno == ECONNREFUSED ||
+ errno == ENETUNREACH ||
errno == ETIMEDOUT)
return E_INVARG;
log_perror("Connecting in proto_open_connection");
return E_QUOTA;
}
-
length = sizeof(addr);
if (getsockname(s, (struct sockaddr *) &addr, &length) < 0) {
close(s);
log_perror("Getting local name in proto_open_connection");
return E_QUOTA;
}
-
*read_fd = *write_fd = s;
stream_printf(st1, "port %d", (int) ntohs(addr.sin_port));
@@ -282,14 +275,17 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
return E_NONE;
}
-#endif /* OUTBOUND_NETWORK */
+#endif /* OUTBOUND_NETWORK */
char rcsid_net_bsd_tcp[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:02 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.5 1996/03/10 01:13:48 pavel
* Moved definition of DEFAULT_PORT to options.h. Release 1.8.0.
*
diff --git a/net_mp_fake.c b/net_mp_fake.c
index 09c9097..45487ce 100644
--- a/net_mp_fake.c
+++ b/net_mp_fake.c
@@ -29,25 +29,27 @@
#error Configuration Error: this code can only be used with the FIFO protocol
#endif
-typedef enum {Read, Write} Direction;
+typedef enum {
+ Read, Write
+} Direction;
typedef struct {
- int fd;
- Direction dir;
+ int fd;
+ Direction dir;
} Port;
-static Port *ports = 0;
-static int num_ports = 0;
-static int max_ports = 0;
+static Port *ports = 0;
+static int num_ports = 0;
+static int max_ports = 0;
-static char *readable = 0;
-static char *writable = 0;
-static int rw_size = 0;
+static char *readable = 0;
+static char *writable = 0;
+static int rw_size = 0;
void
mplex_clear(void)
{
- int i;
+ int i;
num_ports = 0;
for (i = 0; i < rw_size; i++)
@@ -58,12 +60,12 @@ static void
add_common(int fd, Direction dir)
{
if (fd >= rw_size) { /* Grow readable/writable arrays */
- int new_size = (fd + 9) / 10 * 10 + 1;
- char *new_readable = (char *) mymalloc(new_size * sizeof(char),
- M_NETWORK);
- char *new_writable = (char *) mymalloc(new_size * sizeof(char),
- M_NETWORK);
- int i;
+ int new_size = (fd + 9) / 10 * 10 + 1;
+ char *new_readable = (char *) mymalloc(new_size * sizeof(char),
+ M_NETWORK);
+ char *new_writable = (char *) mymalloc(new_size * sizeof(char),
+ M_NETWORK);
+ int i;
for (i = 0; i < new_size; i++)
new_readable[i] = new_writable[i] = 0;
@@ -72,16 +74,14 @@ add_common(int fd, Direction dir)
myfree(readable, M_NETWORK);
myfree(writable, M_NETWORK);
}
-
readable = new_readable;
writable = new_writable;
rw_size = new_size;
}
-
- if (num_ports == max_ports) { /* Grow ports array */
- int new_max = max_ports + 10;
- Port *new_ports = mymalloc(new_max * sizeof(Port), M_NETWORK);
- int i;
+ if (num_ports == max_ports) { /* Grow ports array */
+ int new_max = max_ports + 10;
+ Port *new_ports = mymalloc(new_max * sizeof(Port), M_NETWORK);
+ int i;
for (i = 0; i < max_ports; i++)
new_ports[i] = ports[i];
@@ -92,7 +92,6 @@ add_common(int fd, Direction dir)
ports = new_ports;
max_ports = new_max;
}
-
ports[num_ports].fd = fd;
ports[num_ports++].dir = dir;
}
@@ -112,8 +111,8 @@ mplex_add_writer(int fd)
int
mplex_wait(unsigned timeout)
{
- struct stat st;
- int i, got_one = 0;
+ struct stat st;
+ int i, got_one = 0;
while (1) {
for (i = 0; i < num_ports; i++) {
@@ -162,9 +161,12 @@ mplex_is_writable(int fd)
char rcsid_net_mp_fake[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:03 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:36:06 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/net_mp_poll.c b/net_mp_poll.c
index 78d9d4c..f9b395a 100644
--- a/net_mp_poll.c
+++ b/net_mp_poll.c
@@ -24,16 +24,16 @@
#include "net_mplex.h"
#include "storage.h"
-typedef struct pollfd Port;
+typedef struct pollfd Port;
-static Port *ports = 0;
-static unsigned num_ports = 0;
-static unsigned max_fd;
+static Port *ports = 0;
+static unsigned num_ports = 0;
+static unsigned max_fd;
void
mplex_clear(void)
{
- int i;
+ int i;
max_fd = 0;
for (i = 0; i < num_ports; i++) {
@@ -46,9 +46,9 @@ static void
add_common(int fd, unsigned dir)
{
if (fd >= num_ports) { /* Grow ports array */
- int new_num = (fd + 9) / 10 * 10 + 1;
- Port *new_ports = mymalloc(new_num * sizeof(Port), M_NETWORK);
- int i;
+ int new_num = (fd + 9) / 10 * 10 + 1;
+ Port *new_ports = mymalloc(new_num * sizeof(Port), M_NETWORK);
+ int i;
for (i = 0; i < num_ports; i++)
new_ports[i] = ports[i];
@@ -59,7 +59,6 @@ add_common(int fd, unsigned dir)
ports = new_ports;
num_ports = new_num;
}
-
ports[fd].fd = fd;
ports[fd].events |= dir;
if (fd > max_fd)
@@ -81,7 +80,7 @@ mplex_add_writer(int fd)
int
mplex_wait(unsigned timeout)
{
- int result = poll(ports, max_fd + 1, timeout * 1000);
+ int result = poll(ports, max_fd + 1, timeout * 1000);
if (result < 0) {
if (errno != EINTR)
@@ -94,21 +93,24 @@ mplex_wait(unsigned timeout)
int
mplex_is_readable(int fd)
{
- return fd <= max_fd && (ports[fd].revents & (POLLIN | POLLHUP)) != 0;
+ return fd <= max_fd && (ports[fd].revents & (POLLIN | POLLHUP)) != 0;
}
int
mplex_is_writable(int fd)
{
- return fd <= max_fd && (ports[fd].revents & POLLOUT) != 0;
+ return fd <= max_fd && (ports[fd].revents & POLLOUT) != 0;
}
char rcsid_net_mp_poll[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:04 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:36:15 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/net_mp_selct.c b/net_mp_selct.c
index 88eecf4..8ec786a 100644
--- a/net_mp_selct.c
+++ b/net_mp_selct.c
@@ -25,8 +25,8 @@
#include "log.h"
#include "net_mplex.h"
-static fd_set input, output;
-static int max_descriptor;
+static fd_set input, output;
+static int max_descriptor;
void
mplex_clear(void)
@@ -55,8 +55,8 @@ mplex_add_writer(int fd)
int
mplex_wait(unsigned timeout)
{
- struct timeval tv;
- int n;
+ struct timeval tv;
+ int n;
tv.tv_sec = timeout;
tv.tv_usec = 0;
@@ -86,9 +86,12 @@ mplex_is_writable(int fd)
char rcsid_net_mp_selct[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:04 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:36:22 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/net_mplex.h b/net_mplex.h
index f0867ba..d1a316b 100644
--- a/net_mplex.h
+++ b/net_mplex.h
@@ -22,10 +22,10 @@
* perform an I/O operation on any of a set of file descriptors without
* blocking. Uses of the abstraction always have the following form:
*
- * mplex_clear();
- * { mplex_add_reader(fd) or mplex_add_writer(fd) }*
- * timed_out = mplex_wait(timeout);
- * { mplex_is_readable(fd) or mplex_is_writable(fd) }*
+ * mplex_clear();
+ * { mplex_add_reader(fd) or mplex_add_writer(fd) }*
+ * timed_out = mplex_wait(timeout);
+ * { mplex_is_readable(fd) or mplex_is_writable(fd) }*
*
* The set of file descriptors maintained by the abstraction is referred to
* below as the `wait set'. Each file descriptor in the wait set is marked
@@ -35,20 +35,20 @@
#ifndef Net_MPlex_H
#define Net_MPlex_H 1
-extern void mplex_clear(void);
+extern void mplex_clear(void);
/* Reset the wait set to be empty. */
-extern void mplex_add_reader(int fd);
+extern void mplex_add_reader(int fd);
/* Add the given file descriptor to the wait
* set, marked for reading.
*/
-extern void mplex_add_writer(int fd);
+extern void mplex_add_writer(int fd);
/* Add the given file descriptor to the wait
* set, marked for writing.
*/
-extern int mplex_wait(unsigned timeout);
+extern int mplex_wait(unsigned timeout);
/* Wait until it is possible either to do the
* appropriate kind of I/O on some descriptor
* in the wait set or until `timeout' seconds
@@ -56,24 +56,27 @@ extern int mplex_wait(unsigned timeout);
* expired without any I/O becoming possible.
*/
-extern int mplex_is_readable(int fd);
+extern int mplex_is_readable(int fd);
/* Return true iff the most recent mplex_wait()
* call terminated (in part) because reading
* had become possible on the given descriptor.
*/
-extern int mplex_is_writable(int fd);
+extern int mplex_is_writable(int fd);
/* Return true iff the most recent mplex_wait()
* call terminated (in part) because reading
* had become possible on the given descriptor.
*/
-#endif /* !Net_MPlex_H */
+#endif /* !Net_MPlex_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:05 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:18:23 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/net_multi.c b/net_multi.c
index 42a5a25..d4ffa5e 100644
--- a/net_multi.c
+++ b/net_multi.c
@@ -41,76 +41,76 @@
#include "timers.h"
#include "utils.h"
-static struct proto proto;
-static int eol_length; /* == strlen(proto.eol_out_string) */
+static struct proto proto;
+static int eol_length; /* == strlen(proto.eol_out_string) */
#ifdef EAGAIN
-static int eagain = EAGAIN;
+static int eagain = EAGAIN;
#else
-static int eagain = -1;
+static int eagain = -1;
#endif
#ifdef EWOULDBLOCK
-static int ewouldblock = EWOULDBLOCK;
+static int ewouldblock = EWOULDBLOCK;
#else
-static int ewouldblock = -1;
+static int ewouldblock = -1;
#endif
-static int *pocket_descriptors = 0; /* fds we keep around in case we need
+static int *pocket_descriptors = 0; /* fds we keep around in case we need
* one and no others are left... */
typedef struct text_block {
- struct text_block *next;
- int length;
- char *buffer;
- char *start;
+ struct text_block *next;
+ int length;
+ char *buffer;
+ char *start;
} text_block;
typedef struct nhandle {
- struct nhandle *next, **prev;
- server_handle shandle;
- int rfd, wfd;
- char *name;
- Stream *input;
- int last_input_was_CR;
- int input_suspended;
- text_block *output_head;
- text_block **output_tail;
- int output_length;
- int output_lines_flushed;
- int outbound, binary;
+ struct nhandle *next, **prev;
+ server_handle shandle;
+ int rfd, wfd;
+ char *name;
+ Stream *input;
+ int last_input_was_CR;
+ int input_suspended;
+ text_block *output_head;
+ text_block **output_tail;
+ int output_length;
+ int output_lines_flushed;
+ int outbound, binary;
#if NETWORK_PROTOCOL == NP_TCP
- int client_echo;
+ int client_echo;
#endif
} nhandle;
-static nhandle *all_nhandles = 0;
+static nhandle *all_nhandles = 0;
typedef struct nlistener {
- struct nlistener *next, **prev;
- server_listener slistener;
- int fd;
- const char *name;
+ struct nlistener *next, **prev;
+ server_listener slistener;
+ int fd;
+ const char *name;
} nlistener;
-static nlistener *all_nlisteners = 0;
+static nlistener *all_nlisteners = 0;
typedef struct {
- int fd;
+ int fd;
network_fd_callback readable;
network_fd_callback writable;
- void *data;
+ void *data;
} fd_reg;
-static fd_reg *reg_fds = 0;
-static int max_reg_fds = 0;
+static fd_reg *reg_fds = 0;
+static int max_reg_fds = 0;
void
network_register_fd(int fd, network_fd_callback readable,
network_fd_callback writable, void *data)
{
- int i;
+ int i;
if (!reg_fds) {
max_reg_fds = 5;
@@ -118,13 +118,12 @@ network_register_fd(int fd, network_fd_callback readable,
for (i = 0; i < max_reg_fds; i++)
reg_fds[i].fd = -1;
}
-
/* Find an empty slot */
for (i = 0; i < max_reg_fds; i++)
if (reg_fds[i].fd == -1)
break;
- if (i >= max_reg_fds) { /* No free slots */
- int new_max = 2 * max_reg_fds;
+ if (i >= max_reg_fds) { /* No free slots */
+ int new_max = 2 * max_reg_fds;
fd_reg *new = mymalloc(new_max * sizeof(fd_reg), M_NETWORK);
for (i = 0; i < new_max; i++)
@@ -138,7 +137,6 @@ network_register_fd(int fd, network_fd_callback readable,
max_reg_fds = new_max;
reg_fds = new;
}
-
reg_fds[i].fd = fd;
reg_fds[i].readable = readable;
reg_fds[i].writable = writable;
@@ -148,7 +146,7 @@ network_register_fd(int fd, network_fd_callback readable,
void
network_unregister_fd(int fd)
{
- int i;
+ int i;
for (i = 0; i < max_reg_fds; i++)
if (reg_fds[i].fd == fd)
@@ -158,7 +156,7 @@ network_unregister_fd(int fd)
static void
add_registered_fds(void)
{
- fd_reg *reg;
+ fd_reg *reg;
for (reg = reg_fds; reg < reg_fds + max_reg_fds; reg++)
if (reg->fd != -1) {
@@ -172,20 +170,20 @@ add_registered_fds(void)
static void
check_registered_fds(void)
{
- fd_reg *reg;
+ fd_reg *reg;
for (reg = reg_fds; reg < reg_fds + max_reg_fds; reg++)
if (reg->fd != -1) {
- if (reg->readable && mplex_is_readable(reg->fd))
- (*reg->readable)(reg->fd, reg->data);
- if (reg->writable && mplex_is_writable(reg->fd))
- (*reg->writable)(reg->fd, reg->data);
+ if (reg->readable && mplex_is_readable(reg->fd))
+ (*reg->readable) (reg->fd, reg->data);
+ if (reg->writable && mplex_is_writable(reg->fd))
+ (*reg->writable) (reg->fd, reg->data);
}
}
static void
-free_text_block(text_block *b)
+free_text_block(text_block * b)
{
myfree(b->buffer, M_NETWORK);
myfree(b, M_NETWORK);
@@ -198,7 +196,7 @@ network_set_nonblocking(int fd)
/* Prefer this implementation, since the second one fails on some SysV
* platforms, including HP/UX.
*/
- int yes = 1;
+ int yes = 1;
if (ioctl(fd, FIONBIO, &yes) < 0)
return 0;
@@ -216,14 +214,14 @@ network_set_nonblocking(int fd)
}
static int
-push_output(nhandle *h)
+push_output(nhandle * h)
{
text_block *b;
- int count;
+ int count;
if (h->output_lines_flushed > 0) {
- char buf[100];
- int length;
+ char buf[100];
+ int length;
sprintf(buf,
"%s>> Network buffer overflow: %u line%s of output to you %s been lost <<%s",
@@ -237,12 +235,12 @@ push_output(nhandle *h)
if (count == length)
h->output_lines_flushed = 0;
else
- return count >= 0 || errno == eagain || errno == ewouldblock;
+ return count >= 0 || errno == eagain || errno == ewouldblock;
}
while ((b = h->output_head) != 0) {
count = write(h->wfd, b->start, b->length);
if (count < 0)
- return (errno == eagain || errno == ewouldblock);
+ return (errno == eagain || errno == ewouldblock);
h->output_length -= count;
if (count == b->length) {
h->output_head = b->next;
@@ -258,12 +256,12 @@ push_output(nhandle *h)
}
static int
-pull_input(nhandle *h)
+pull_input(nhandle * h)
{
- Stream *s = h->input;
- int count;
- char buffer[1024];
- char *ptr, *end;
+ Stream *s = h->input;
+ int count;
+ char buffer[1024];
+ char *ptr, *end;
if ((count = read(h->rfd, buffer, sizeof(buffer))) > 0) {
if (h->binary) {
@@ -272,11 +270,11 @@ pull_input(nhandle *h)
h->last_input_was_CR = 0;
} else {
for (ptr = buffer, end = buffer + count; ptr < end; ptr++) {
- unsigned char c = *ptr;
+ unsigned char c = *ptr;
- if (isgraph(c) || c == ' ' || c == '\t')
+ if (isgraph(c) || c == ' ' || c == '\t')
stream_add_char(s, c);
- else if (c == '\r' || (c == '\n' && !h->last_input_was_CR))
+ else if (c == '\r' || (c == '\n' && !h->last_input_was_CR))
server_receive_line(h->shandle, reset_stream(s));
h->last_input_was_CR = (c == '\r');
@@ -284,22 +282,22 @@ pull_input(nhandle *h)
}
return 1;
} else
- return (count == 0 && !proto.believe_eof)
- || (count < 0 && (errno == eagain || errno == ewouldblock));
+ return (count == 0 && !proto.believe_eof)
+ || (count < 0 && (errno == eagain || errno == ewouldblock));
}
static nhandle *
new_nhandle(int rfd, int wfd, const char *local_name, const char *remote_name,
int outbound)
{
- nhandle *h;
- static Stream *s = 0;
+ nhandle *h;
+ static Stream *s = 0;
if (s == 0)
s = new_stream(100);
if (!network_set_nonblocking(rfd)
- || (rfd != wfd && !network_set_nonblocking(wfd)))
+ || (rfd != wfd && !network_set_nonblocking(wfd)))
log_perror("Setting connection non-blocking");
h = mymalloc(sizeof(nhandle), M_NETWORK);
@@ -333,7 +331,7 @@ new_nhandle(int rfd, int wfd, const char *local_name, const char *remote_name,
}
static void
-close_nhandle(nhandle *h)
+close_nhandle(nhandle * h)
{
text_block *b, *bb;
@@ -354,7 +352,7 @@ close_nhandle(nhandle *h)
}
static void
-close_nlistener(nlistener *l)
+close_nlistener(nlistener * l)
{
*(l->prev) = l->next;
if (l->next)
@@ -369,8 +367,8 @@ make_new_connection(server_listener sl, int rfd, int wfd,
const char *local_name, const char *remote_name,
int outbound)
{
- nhandle *h;
- network_handle nh;
+ nhandle *h;
+ network_handle nh;
nh.ptr = h = new_nhandle(rfd, wfd, local_name, remote_name, outbound);
h->shandle = server_new_connection(sl, nh, outbound);
@@ -379,7 +377,7 @@ make_new_connection(server_listener sl, int rfd, int wfd,
static void
get_pocket_descriptors()
{
- int i;
+ int i;
if (!pocket_descriptors)
pocket_descriptors =
@@ -395,19 +393,19 @@ get_pocket_descriptors()
}
static void
-accept_new_connection(nlistener *l)
+accept_new_connection(nlistener * l)
{
- network_handle nh;
- nhandle *h;
- int rfd, wfd, i;
- const char *host_name;
+ network_handle nh;
+ nhandle *h;
+ int rfd, wfd, i;
+ const char *host_name;
switch (proto_accept_connection(l->fd, &rfd, &wfd, &host_name)) {
- case PA_OKAY:
+ case PA_OKAY:
make_new_connection(l->slistener, rfd, wfd, l->name, host_name, 0);
break;
- case PA_FULL:
+ case PA_FULL:
for (i = 0; i < proto.pocket_size; i++)
close(pocket_descriptors[i]);
if (proto_accept_connection(l->fd, &rfd, &wfd, &host_name) != PA_OKAY)
@@ -420,7 +418,7 @@ accept_new_connection(nlistener *l)
get_pocket_descriptors();
break;
- case PA_OTHER:
+ case PA_OTHER:
/* Do nothing. The protocol implementation has already logged it. */
break;
}
@@ -430,21 +428,21 @@ static int
enqueue_output(network_handle nh, const char *line, int line_length,
int add_eol, int flush_ok)
{
- nhandle *h = nh.ptr;
- int length = line_length + (add_eol ? eol_length : 0);
- char *buffer;
+ nhandle *h = nh.ptr;
+ int length = line_length + (add_eol ? eol_length : 0);
+ char *buffer;
text_block *block;
if (h->output_length != 0
- && h->output_length + length > MAX_QUEUED_OUTPUT) { /* must flush... */
- int to_flush;
- text_block *b;
-
+ && h->output_length + length > MAX_QUEUED_OUTPUT) { /* must flush... */
+ int to_flush;
+ text_block *b;
+
(void) push_output(h);
to_flush = h->output_length + length - MAX_QUEUED_OUTPUT;
if (to_flush > 0 && !flush_ok)
return 0;
- while (to_flush > 0 && (b = h->output_head)) {
+ while (to_flush > 0 && (b = h->output_head)) {
h->output_length -= b->length;
to_flush -= b->length;
h->output_lines_flushed++;
@@ -454,7 +452,6 @@ enqueue_output(network_handle nh, const char *line, int line_length,
if (h->output_head == 0)
h->output_tail = &(h->output_head);
}
-
buffer = (char *) mymalloc(length * sizeof(char), M_NETWORK);
block = (text_block *) mymalloc(sizeof(text_block), M_NETWORK);
memcpy(buffer, line, line_length);
@@ -488,7 +485,7 @@ network_usage_string(void)
}
int
-network_initialize(int argc, char **argv, Var *desc)
+network_initialize(int argc, char **argv, Var * desc)
{
if (!proto_initialize(&proto, desc, argc, argv))
return 0;
@@ -504,11 +501,11 @@ network_initialize(int argc, char **argv, Var *desc)
enum error
network_make_listener(server_listener sl, Var desc,
- network_listener *nl, Var *canon, const char **name)
+ network_listener * nl, Var * canon, const char **name)
{
- int fd;
- enum error e = proto_make_listener(desc, &fd, canon, name);
- nlistener *l;
+ int fd;
+ enum error e = proto_make_listener(desc, &fd, canon, name);
+ nlistener *l;
if (e == E_NONE) {
nl->ptr = l = mymalloc(sizeof(nlistener), M_NETWORK);
@@ -521,15 +518,14 @@ network_make_listener(server_listener sl, Var desc,
l->prev = &all_nlisteners;
all_nlisteners = l;
}
-
return e;
}
int
network_listen(network_listener nl)
{
- nlistener *l = nl.ptr;
-
+ nlistener *l = nl.ptr;
+
return proto_listen(l->fd);
}
@@ -549,7 +545,7 @@ network_send_bytes(network_handle nh, const char *buffer, int buflen,
int
network_buffered_output_length(network_handle nh)
{
- nhandle *h = nh.ptr;
+ nhandle *h = nh.ptr;
return h->output_length;
}
@@ -557,7 +553,7 @@ network_buffered_output_length(network_handle nh)
void
network_suspend_input(network_handle nh)
{
- nhandle *h = nh.ptr;
+ nhandle *h = nh.ptr;
h->input_suspended = 1;
}
@@ -565,7 +561,7 @@ network_suspend_input(network_handle nh)
void
network_resume_input(network_handle nh)
{
- nhandle *h = nh.ptr;
+ nhandle *h = nh.ptr;
h->input_suspended = 0;
}
@@ -573,8 +569,8 @@ network_resume_input(network_handle nh)
int
network_process_io(int timeout)
{
- nhandle *h, *hnext;
- nlistener *l;
+ nhandle *h, *hnext;
+ nlistener *l;
mplex_clear();
for (l = all_nlisteners; l; l = l->next)
@@ -595,8 +591,8 @@ network_process_io(int timeout)
accept_new_connection(l);
for (h = all_nhandles; h; h = hnext) {
hnext = h->next;
- if ((mplex_is_readable(h->rfd) && !pull_input(h))
- || (mplex_is_writable(h->wfd) && !push_output(h))) {
+ if ((mplex_is_readable(h->rfd) && !pull_input(h))
+ || (mplex_is_writable(h->wfd) && !push_output(h))) {
server_close(h->shandle);
close_nhandle(h);
}
@@ -609,7 +605,7 @@ network_process_io(int timeout)
const char *
network_connection_name(network_handle nh)
{
- nhandle *h = (nhandle *) nh.ptr;
+ nhandle *h = (nhandle *) nh.ptr;
return h->name;
}
@@ -617,7 +613,7 @@ network_connection_name(network_handle nh)
void
network_set_connection_binary(network_handle nh, int do_binary)
{
- nhandle *h = nh.ptr;
+ nhandle *h = nh.ptr;
h->binary = do_binary;
}
@@ -626,8 +622,8 @@ Var
network_connection_options(network_handle nh, Var list)
{
#if NETWORK_PROTOCOL == NP_TCP
- nhandle *h = nh.ptr;
- Var pair;
+ nhandle *h = nh.ptr;
+ Var pair;
pair = new_list(2);
pair.v.list[1].type = TYPE_STR;
@@ -641,10 +637,10 @@ network_connection_options(network_handle nh, Var list)
}
int
-network_connection_option(network_handle nh, const char *option, Var *value)
+network_connection_option(network_handle nh, const char *option, Var * value)
{
#if NETWORK_PROTOCOL == NP_TCP
- nhandle *h = nh.ptr;
+ nhandle *h = nh.ptr;
if (!mystrcasecmp(option, "client-echo")) {
value->type = TYPE_INT;
@@ -660,16 +656,17 @@ int
network_set_connection_option(network_handle nh, const char *option, Var value)
{
#if NETWORK_PROTOCOL == NP_TCP
- nhandle *h = nh.ptr;
+ nhandle *h = nh.ptr;
- /* These values taken from RFC 854 and RFC 857. */
+ /* These values taken from RFC 854 and RFC 857. */
#define TN_IAC 255 /* Interpret As Command */
#define TN_WILL 251
#define TN_WONT 252
#define TN_ECHO 1
{
- static char telnet_cmd[4] = {TN_IAC, 0, TN_ECHO, 0};
+ static char telnet_cmd[4] =
+ {TN_IAC, 0, TN_ECHO, 0};
if (!mystrcasecmp(option, "client-echo")) {
h->client_echo = is_true(value);
@@ -691,9 +688,9 @@ network_set_connection_option(network_handle nh, const char *option, Var value)
enum error
network_open_connection(Var arglist)
{
- int rfd, wfd;
+ int rfd, wfd;
const char *local_name, *remote_name;
- enum error e;
+ enum error e;
e = proto_open_connection(arglist, &rfd, &wfd, &local_name, &remote_name);
if (e == E_NONE)
@@ -728,9 +725,12 @@ network_shutdown(void)
char rcsid_net_multi[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:05 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.6 1996/05/12 21:29:09 pavel
* Fixed mis-initialization of "client-echo" option. Release 1.8.0p5.
*
diff --git a/net_multi.h b/net_multi.h
index 402391d..0a05eae 100644
--- a/net_multi.h
+++ b/net_multi.h
@@ -22,10 +22,10 @@
* configurations.
*/
-typedef void (*network_fd_callback)(int fd, void *data);
+typedef void (*network_fd_callback) (int fd, void *data);
-extern void network_register_fd(int fd, network_fd_callback readable,
- network_fd_callback writable, void *data);
+extern void network_register_fd(int fd, network_fd_callback readable,
+ network_fd_callback writable, void *data);
/* The file descriptor FD will be selected for
* at intervals (whenever the networking module
* is doing its own I/O processing). If FD
@@ -35,22 +35,25 @@ extern void network_register_fd(int fd, network_fd_callback readable,
* WRITABLE.
*/
-extern void network_unregister_fd(int fd);
+extern void network_unregister_fd(int fd);
/* Any existing registration for FD is
* forgotten.
*/
-extern int network_set_nonblocking(int fd);
+extern int network_set_nonblocking(int fd);
/* Enable nonblocking I/O on the file
- * descriptor FD. Return true iff successful.
+ * descriptor FD. Return true iff successful.
*/
-#endif /* !Net_Multi_H */
+#endif /* !Net_Multi_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:06 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.1 1996/02/08 06:18:14 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/net_proto.h b/net_proto.h
index c4e7512..6153747 100644
--- a/net_proto.h
+++ b/net_proto.h
@@ -27,14 +27,14 @@
#include "structures.h"
struct proto {
- unsigned pocket_size; /* Maximum number of file descriptors it might
+ unsigned pocket_size; /* Maximum number of file descriptors it might
* take to accept a new connection in this
* protocol. The generic multi-user network
* code will keep this many descriptors `in its
* pocket', ready to be freed up in order to
* tell potential users that there's no more
* room in the server. */
- int believe_eof; /* If true, then read() will return 0 on a
+ int believe_eof; /* If true, then read() will return 0 on a
* connection using this protocol iff the
* connection really is closed. If false, then
* read() -> 0 will be interpreted as the
@@ -44,17 +44,17 @@ struct proto {
* line of output on connections. */
};
-extern const char *proto_name(void);
+extern const char *proto_name(void);
/* Returns a string naming the protocol. */
-extern const char *proto_usage_string(void);
+extern const char *proto_usage_string(void);
/* Returns a string giving the syntax of any
* extra, protocol-specific command-line
* arguments, such as a port number.
*/
-extern int proto_initialize(struct proto *proto, Var *desc,
- int argc, char **argv);
+extern int proto_initialize(struct proto *proto, Var * desc,
+ int argc, char **argv);
/* ARGC and ARGV refer to just the protocol-
* specific command-line arguments, if any,
* which always come after any protocol-
@@ -67,8 +67,8 @@ extern int proto_initialize(struct proto *proto, Var *desc,
* server's initial listening point.
*/
-extern enum error proto_make_listener(Var desc, int *fd, Var *canon,
- const char **name);
+extern enum error proto_make_listener(Var desc, int *fd, Var * canon,
+ const char **name);
/* DESC is the second argument in a call to the
* built-in MOO function `listen()'; it should
* be used as a specification of a new local
@@ -90,7 +90,7 @@ extern enum error proto_make_listener(Var desc, int *fd, Var *canon,
* accepting connections.
*/
-extern int proto_listen(int fd);
+extern int proto_listen(int fd);
/* Prepare for accepting connections on the
* given file descriptor, returning true if
* successful. FD was returned by a call to
@@ -98,12 +98,14 @@ extern int proto_listen(int fd);
*/
-enum proto_accept_error { PA_OKAY, PA_FULL, PA_OTHER };
+enum proto_accept_error {
+ PA_OKAY, PA_FULL, PA_OTHER
+};
extern enum proto_accept_error
- proto_accept_connection(int listener_fd,
- int *read_fd, int *write_fd,
- const char **name);
+ proto_accept_connection(int listener_fd,
+ int *read_fd, int *write_fd,
+ const char **name);
/* Accept a new connection on LISTENER_FD,
* returning PA_OKAY if successful, PA_FULL if
* unsuccessful only because there aren't
@@ -121,10 +123,10 @@ extern enum proto_accept_error
#ifdef OUTBOUND_NETWORK
-extern enum error proto_open_connection(Var arglist,
- int *read_fd, int *write_fd,
- const char **local_name,
- const char **remote_name);
+extern enum error proto_open_connection(Var arglist,
+ int *read_fd, int *write_fd,
+ const char **local_name,
+ const char **remote_name);
/* The given MOO arguments should be used as a
* specification of a remote network connection
* to be opened. If the arguments are OK for
@@ -138,28 +140,31 @@ extern enum error proto_open_connection(Var arglist,
* an appropriate error should be returned.
*/
-#endif /* OUTBOUND_NETWORK */
+#endif /* OUTBOUND_NETWORK */
-extern void proto_close_connection(int read_fd, int write_fd);
+extern void proto_close_connection(int read_fd, int write_fd);
/* Close the given file descriptors, which were
* returned by proto_accept_connection(),
* performing whatever extra clean-ups are
* required by the protocol.
*/
-extern void proto_close_listener(int fd);
+extern void proto_close_listener(int fd);
/* Close FD, which was returned by a call to
* proto_make_listener(), performing whatever
* extra clean-ups are required by the
* protocol.
*/
-#endif /* !Net_Proto_H */
+#endif /* !Net_Proto_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:07 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.3 1996/02/08 06:16:01 pavel
* Updated copyright notice for 1996. Release 1.8.0beta1.
*
diff --git a/net_single.c b/net_single.c
index e2a39f3..9e20593 100644
--- a/net_single.c
+++ b/net_single.c
@@ -28,10 +28,12 @@
#include "structures.h"
#include "utils.h"
-static enum {STATE_OPEN, STATE_CLOSED} state = STATE_CLOSED;
-static int listening = 0;
-static server_listener slistener;
-static int binary = 0;
+static enum {
+ STATE_OPEN, STATE_CLOSED
+} state = STATE_CLOSED;
+static int listening = 0;
+static server_listener slistener;
+static int binary = 0;
const char *
network_protocol_name(void)
@@ -46,7 +48,7 @@ network_usage_string(void)
}
int
-network_initialize(int argc, char **argv, Var *desc)
+network_initialize(int argc, char **argv, Var * desc)
{
*desc = zero;
if (argc != 0)
@@ -56,8 +58,8 @@ network_initialize(int argc, char **argv, Var *desc)
}
enum error
-network_make_listener(server_listener sl, Var desc, network_listener *nl,
- Var *canon, const char **name)
+network_make_listener(server_listener sl, Var desc, network_listener * nl,
+ Var * canon, const char **name)
{
if (listening)
return E_PERM;
@@ -121,7 +123,7 @@ network_connection_options(network_handle nh, Var list)
}
int
-network_connection_option(network_handle nh, const char *option, Var *value)
+network_connection_option(network_handle nh, const char *option, Var * value)
{
return 0;
}
@@ -154,7 +156,7 @@ network_shutdown(void)
log_perror("Setting standard input blocking again");
}
-static int input_suspended = 0;
+static int input_suspended = 0;
void
network_suspend_input(network_handle nh)
@@ -171,17 +173,17 @@ network_resume_input(network_handle nh)
int
network_process_io(int timeout)
{
- network_handle nh;
+ network_handle nh;
static server_handle sh;
- static Stream *s = 0;
- char buffer[1024];
- int count;
- char *ptr, *end;
- int got_some = 0;
-
+ static Stream *s = 0;
+ char buffer[1024];
+ int count;
+ char *ptr, *end;
+ int got_some = 0;
+
if (s == 0) {
int flags;
-
+
s = new_stream(1000);
if ((flags = fcntl(0, F_GETFL)) < 0
@@ -190,19 +192,17 @@ network_process_io(int timeout)
return 0;
}
}
-
switch (state) {
- case STATE_CLOSED:
+ case STATE_CLOSED:
if (listening) {
sh = server_new_connection(slistener, nh, 0);
state = STATE_OPEN;
got_some = 1;
- } else
- if (timeout != 0)
- sleep(timeout);
- break;
+ } else if (timeout != 0)
+ sleep(timeout);
+ break;
- case STATE_OPEN:
+ case STATE_OPEN:
for (;;) {
while (!input_suspended
&& (count = read(0, buffer, sizeof(buffer))) > 0) {
@@ -214,16 +214,16 @@ network_process_io(int timeout)
for (ptr = buffer, end = buffer + count;
ptr < end;
ptr++) {
- unsigned char c = *ptr;
+ unsigned char c = *ptr;
- if (isgraph(c) || c == ' ' || c == '\t')
+ if (isgraph(c) || c == ' ' || c == '\t')
stream_add_char(s, c);
else if (c == '\n')
server_receive_line(sh, reset_stream(s));
}
}
- if (got_some || timeout == 0)
+ if (got_some || timeout == 0)
goto done;
sleep(1);
@@ -238,9 +238,12 @@ network_process_io(int timeout)
char rcsid_net_single[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:07 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.4 1996/03/10 01:23:12 pavel
* Added support for `connection_option()'. Added missing include of
* "utils.h". Release 1.8.0.
diff --git a/net_sysv_lcl.c b/net_sysv_lcl.c
index f4d6e55..211bdef 100644
--- a/net_sysv_lcl.c
+++ b/net_sysv_lcl.c
@@ -16,36 +16,36 @@
*****************************************************************************/
/* Multi-user networking protocol implementation for local clients on SysV UNIX
- *
+
* The protocol for connection establishment works like this:
*
- * CLIENT SERVER
- * Create SERVER_FIFO (mode 622).
- * Open SERVER_FIFO for reading (O_NDELAY)
- * Wait for input on SERVER_FIFO
- * ...
- * Create C2S_FIFO (mode 644)
- * and S2C_FIFO (mode 622) in
- * some personal directory
- * (like $HOME).
- * Open S2C_FIFO for reading
- * (O_NDELAY).
- * Open SERVER_FIFO for writing
- * (no O_NDELAY), write
- * '\n' C2S_FIFO ' ' S2C_FIFO '\n'
- * in a single write() call, and
- * then close SERVER_FIFO.
- * Open C2S_FIFO for writing Read C2S_FIFO and S2C_FIFO from
- * (*no* O_NDELAY). SERVER_FIFO.
- * Open S2C_FIFO for writing (O_NDELAY)
- * and abort connection on error.
- * Open C2S_FIFO for reading (O_NDELAY)
- * and abort connection on error.
- * Unlink C2S_FIFO and S2C_FIFO
- * for privacy; their names
- * are no longer needed.
- * ...
- * Close SERVER_FIFO and unlink it.
+ * CLIENT SERVER
+ * Create SERVER_FIFO (mode 622).
+ * Open SERVER_FIFO for reading (O_NDELAY)
+ * Wait for input on SERVER_FIFO
+ * ...
+ * Create C2S_FIFO (mode 644)
+ * and S2C_FIFO (mode 622) in
+ * some personal directory
+ * (like $HOME).
+ * Open S2C_FIFO for reading
+ * (O_NDELAY).
+ * Open SERVER_FIFO for writing
+ * (no O_NDELAY), write
+ * '\n' C2S_FIFO ' ' S2C_FIFO '\n'
+ * in a single write() call, and
+ * then close SERVER_FIFO.
+ * Open C2S_FIFO for writing Read C2S_FIFO and S2C_FIFO from
+ * (*no* O_NDELAY). SERVER_FIFO.
+ * Open S2C_FIFO for writing (O_NDELAY)
+ * and abort connection on error.
+ * Open C2S_FIFO for reading (O_NDELAY)
+ * and abort connection on error.
+ * Unlink C2S_FIFO and S2C_FIFO
+ * for privacy; their names
+ * are no longer needed.
+ * ...
+ * Close SERVER_FIFO and unlink it.
*
* It is important that the client do the above actions in the given order;
* no other sequence (with the sole exception of the timing of the opening
@@ -85,15 +85,17 @@
#include "streams.h"
#include "utils.h"
-enum state { RejectLine, GetC2S, GetS2C, Accepting };
+enum state {
+ RejectLine, GetC2S, GetS2C, Accepting
+};
typedef struct listener {
- struct listener *next;
- int fifo, pseudo_client;
- const char *filename;
- enum state state;
- char c2s[1001], s2c[1001];
- int ptr; /* current index in c2s or s2c */
+ struct listener *next;
+ int fifo, pseudo_client;
+ const char *filename;
+ enum state state;
+ char c2s[1001], s2c[1001];
+ int ptr; /* current index in c2s or s2c */
} listener;
static listener *all_listeners = 0;
@@ -111,7 +113,7 @@ proto_usage_string(void)
}
int
-proto_initialize(struct proto *proto, Var *desc, int argc, char **argv)
+proto_initialize(struct proto *proto, Var * desc, int argc, char **argv)
{
const char *connect_file = DEFAULT_CONNECT_FILE;
@@ -129,20 +131,19 @@ proto_initialize(struct proto *proto, Var *desc, int argc, char **argv)
else if (argc == 1) {
connect_file = argv[0];
}
-
desc->type = TYPE_STR;
desc->v.str = str_dup(connect_file);
return 1;
}
enum error
-proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
+proto_make_listener(Var desc, int *fd, Var * canon, const char **name)
{
- char buffer[1024];
+ char buffer[1024];
const char *connect_file;
- int fifo, pseudo_client;
- listener *l;
-
+ int fifo, pseudo_client;
+ listener *l;
+
if (desc.type != TYPE_STR)
return E_TYPE;
@@ -161,7 +162,6 @@ proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
log_perror("Setting listening FIFO non-blocking");
return E_QUOTA;
}
-
l = mymalloc(sizeof(listener), M_NETWORK);
l->next = all_listeners;
all_listeners = l;
@@ -180,7 +180,7 @@ proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
static listener *
find_listener(int fd)
{
- listener *l;
+ listener *l;
for (l = all_listeners; l; l = l->next)
if (l->fifo == fd)
@@ -192,17 +192,15 @@ find_listener(int fd)
int
proto_listen(int fd)
{
- listener *l = find_listener(fd);
+ listener *l = find_listener(fd);
if (l) {
if (chmod(l->filename, 0622) < 0) {
log_perror("Making listening FIFO writable");
return 0;
}
-
return 1;
}
-
errlog("Can't find FIFO in PROTO_LISTEN!");
return 0;
}
@@ -213,7 +211,7 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
{
/* There is input available on listener_fd; read up to 1K of it and try
* to parse a line like this from it:
- * <c2s-path-name> <space> <s2c-path-name> <newline>
+ * <c2s-path-name> <space> <s2c-path-name> <newline>
* Because it's impossible in System V and can be difficult in POSIX to do
* otherwise, we assume that the maximum length of a path-name is 1000
* bytes. In fact, because System V and POSIX only guarantee that 512
@@ -222,12 +220,12 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
* FIFO, it really ought not use names longer than about 250 bytes each.
* Of course, in practice, the names will likely never exceed 100 bytes...
*/
- listener *l = find_listener(listener_fd);
- struct stat st1, st2;
- struct passwd *pw;
+ listener *l = find_listener(listener_fd);
+ struct stat st1, st2;
+ struct passwd *pw;
if (l->state != Accepting) {
- int got_one = 0;
+ int got_one = 0;
while (!got_one) {
char c;
@@ -236,14 +234,14 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
break;
switch (l->state) {
- case RejectLine:
+ case RejectLine:
if (c == '\n') {
l->state = GetC2S;
l->ptr = 0;
}
break;
- case GetC2S:
+ case GetC2S:
if (c == ' ') {
l->c2s[l->ptr] = '\0';
l->state = GetS2C;
@@ -259,7 +257,7 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
l->c2s[l->ptr++] = c;
break;
- case GetS2C:
+ case GetS2C:
if (c == '\n') {
l->s2c[l->ptr] = '\0';
l->state = Accepting;
@@ -272,7 +270,7 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
l->s2c[l->ptr++] = c;
break;
- default:
+ default:
panic("Can't happen in proto_accept_connection()");
}
}
@@ -282,7 +280,6 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
return PA_OTHER;
}
}
-
if ((*write_fd = open(l->s2c, O_WRONLY | NONBLOCK_FLAG)) < 0) {
log_perror("Failed to open server->client FIFO");
if (errno == EMFILE)
@@ -302,14 +299,12 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
return PA_OTHER;
}
}
-
l->state = GetC2S;
-
- if (fstat(*read_fd, &st1) < 0 || fstat(*write_fd, &st2) < 0) {
+
+ if (fstat(*read_fd, &st1) < 0 || fstat(*write_fd, &st2) < 0) {
log_perror("Statting client FIFOs");
return PA_OTHER;
}
-
if (st1.st_mode & S_IFMT != S_IFIFO
|| st2.st_mode & S_IFMT != S_IFIFO
|| st1.st_uid != st2.st_uid) {
@@ -318,17 +313,16 @@ proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
errlog("Bogus FIFO names: \"%s\" and \"%s\"\n", l->c2s, l->s2c);
return PA_OTHER;
}
-
pw = getpwuid(st1.st_uid);
if (pw)
*name = pw->pw_name;
else {
- static char buffer[20];
+ static char buffer[20];
sprintf(buffer, "User #%d", (int) st1.st_uid);
*name = buffer;
}
-
+
return PA_OKAY;
}
@@ -343,10 +337,10 @@ proto_close_connection(int read_fd, int write_fd)
void
proto_close_listener(int fd)
{
- listener *l, **ll;
+ listener *l, **ll;
for (l = all_listeners, ll = &all_listeners; l; ll = &(l->next),
- l = l->next)
+ l = l->next)
if (l->fifo == fd) {
remove(l->filename);
close(l->fifo);
@@ -357,16 +351,18 @@ proto_close_listener(int fd)
myfree(l, M_NETWORK);
return;
}
-
errlog("Can't find fd in PROTO_CLOSE_LISTENER!\n");
}
char rcsid_net_sysv_lcl[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:08 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.4 1996/03/10 01:13:11 pavel
* Moved definition of DEFAULT_CONNECT_FILE to options.h. Release 1.8.0.
*
diff --git a/net_sysv_tcp.c b/net_sysv_tcp.c
index 1d3c716..d6375d2 100644
--- a/net_sysv_tcp.c
+++ b/net_sysv_tcp.c
@@ -35,7 +35,7 @@
#include <errno.h> /* EMFILE */
#include "my-fcntl.h" /* O_RDWR */
#include "my-in.h" /* struct sockaddr_in, INADDR_ANY, htonl(),
- * htons(), ntohl(), struct in_addr */
+ * htons(), ntohl(), struct in_addr */
#include "my-ioctl.h" /* ioctl() */
#include "my-socket.h" /* AF_INET */
#include "my-stdlib.h" /* strtoul() */
@@ -55,7 +55,7 @@
#include "structures.h"
#include "timers.h"
-static struct t_call *call = 0;
+static struct t_call *call = 0;
static void
log_ti_error(const char *msg)
@@ -79,13 +79,13 @@ proto_usage_string(void)
}
int
-proto_initialize(struct proto *proto, Var *desc, int argc, char **argv)
+proto_initialize(struct proto *proto, Var * desc, int argc, char **argv)
{
- int port = DEFAULT_PORT;
- char *p;
+ int port = DEFAULT_PORT;
+ char *p;
initialize_name_lookup();
-
+
proto->pocket_size = 1;
proto->believe_eof = 1;
proto->eol_out_string = "\r\n";
@@ -97,19 +97,18 @@ proto_initialize(struct proto *proto, Var *desc, int argc, char **argv)
if (*p != '\0')
return 0;
}
-
desc->type = TYPE_INT;
desc->v.num = port;
return 1;
}
enum error
-proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
+proto_make_listener(Var desc, int *fd, Var * canon, const char **name)
{
- struct sockaddr_in req_addr, rec_addr;
- struct t_bind requested, received;
- int s, port;
- static Stream *st = 0;
+ struct sockaddr_in req_addr, rec_addr;
+ struct t_bind requested, received;
+ int s, port;
+ static Stream *st = 0;
if (!st)
st = new_stream(20);
@@ -123,7 +122,6 @@ proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
log_ti_error("Creating listening endpoint");
return E_QUOTA;
}
-
req_addr.sin_family = AF_INET;
req_addr.sin_addr.s_addr = htonl(INADDR_ANY);
req_addr.sin_port = htons(port);
@@ -138,19 +136,18 @@ proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
received.addr.buf = (void *) &rec_addr;
if (t_bind(s, &requested, &received) < 0) {
- enum error e = E_QUOTA;
+ enum error e = E_QUOTA;
log_ti_error("Binding to listening address");
t_close(s);
- if (t_errno == TACCES || (t_errno == TSYSERR && errno == EACCES))
+ if (t_errno == TACCES || (t_errno == TSYSERR && errno == EACCES))
e = E_PERM;
return e;
- } else if (port != 0 && rec_addr.sin_port != port) {
+ } else if (port != 0 && rec_addr.sin_port != port) {
errlog("Can't bind to requested port!\n");
t_close(s);
return E_QUOTA;
}
-
if (!call)
call = (struct t_call *) t_alloc(s, T_CALL, T_ADDR);
if (!call) {
@@ -158,7 +155,6 @@ proto_make_listener(Var desc, int *fd, Var *canon, const char **name)
t_close(s);
return E_QUOTA;
}
-
canon->type = TYPE_INT;
canon->v.num = ntohs(rec_addr.sin_port);
@@ -179,7 +175,7 @@ proto_listen(int fd)
static int
set_rw_able(int fd)
{
- char buffer[FMNAMESZ + 1];
+ char buffer[FMNAMESZ + 1];
if (ioctl(fd, I_LOOK, buffer) < 0
|| strcmp(buffer, "timod") != 0
@@ -195,47 +191,42 @@ enum proto_accept_error
proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
const char **name)
{
- int timeout = server_int_option("name_lookup_timeout", 5);
- int fd;
+ int timeout = server_int_option("name_lookup_timeout", 5);
+ int fd;
struct sockaddr_in *addr = (struct sockaddr_in *) call->addr.buf;
- static Stream *s = 0;
+ static Stream *s = 0;
if (!s)
s = new_stream(100);
fd = t_open((void *) "/dev/tcp", O_RDWR, 0);
if (fd < 0) {
- if (t_errno == TSYSERR && errno == EMFILE)
+ if (t_errno == TSYSERR && errno == EMFILE)
return PA_FULL;
else {
log_ti_error("Opening endpoint for new connection");
return PA_OTHER;
}
}
-
if (t_bind(fd, 0, 0) < 0) {
log_ti_error("Binding endpoint for new connection");
t_close(fd);
return PA_OTHER;
}
-
if (t_listen(listener_fd, call) < 0) {
log_ti_error("Accepting new network connection");
t_close(fd);
return PA_OTHER;
}
-
if (t_accept(listener_fd, fd, call) < 0) {
log_ti_error("Accepting new network connection");
t_close(fd);
return PA_OTHER;
}
-
if (!set_rw_able(fd)) {
t_close(fd);
return PA_OTHER;
}
-
*read_fd = *write_fd = fd;
stream_printf(s, "%s, port %d",
lookup_name_from_addr(addr, timeout),
@@ -261,7 +252,7 @@ proto_close_listener(int fd)
#include "exceptions.h"
-static Exception timeout_exception;
+static Exception timeout_exception;
static void
timeout_proc(Timer_ID id, Timer_Data data)
@@ -277,21 +268,20 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
* getting all those nasty little parameter-passing rules right. This
* function isn't recursive anyway, so it doesn't matter.
*/
- struct sockaddr_in rec_addr;
- struct t_bind received;
- static const char *host_name;
- static int port;
- static Timer_ID id;
- int fd, result;
- int timeout = server_int_option("name_lookup_timeout", 5);
- static struct sockaddr_in addr;
- static Stream *st1 = 0, *st2 = 0;
+ struct sockaddr_in rec_addr;
+ struct t_bind received;
+ static const char *host_name;
+ static int port;
+ static Timer_ID id;
+ int fd, result;
+ int timeout = server_int_option("name_lookup_timeout", 5);
+ static struct sockaddr_in addr;
+ static Stream *st1 = 0, *st2 = 0;
if (!st1) {
st1 = new_stream(20);
st2 = new_stream(50);
}
-
if (arglist.v.list[0].v.num != 2)
return E_ARGS;
else if (arglist.v.list[1].type != TYPE_STR ||
@@ -310,11 +300,10 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
/* Cast to (void *) here to workaround const-less decls on some systems. */
fd = t_open((void *) "/dev/tcp", O_RDWR, 0);
if (fd < 0) {
- if (t_errno != TSYSERR || errno != EMFILE)
+ if (t_errno != TSYSERR || errno != EMFILE)
log_ti_error("Making endpoint in proto_open_connection");
return E_QUOTA;
}
-
received.addr.maxlen = sizeof(rec_addr);
received.addr.len = sizeof(rec_addr);
received.addr.buf = (void *) &rec_addr;
@@ -324,7 +313,6 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
t_close(fd);
return E_QUOTA;
}
-
call->addr.maxlen = sizeof(addr);
call->addr.len = sizeof(addr);
call->addr.buf = (void *) &addr;
@@ -332,26 +320,24 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
TRY
id = set_timer(server_int_option("outbound_connect_timeout", 5),
timeout_proc, 0);
- result = t_connect(fd, call, 0);
- cancel_timer(id);
- EXCEPT (timeout_exception)
+ result = t_connect(fd, call, 0);
+ cancel_timer(id);
+ EXCEPT(timeout_exception)
result = -1;
- errno = ETIMEDOUT;
- t_errno = TSYSERR;
- reenable_timers();
+ errno = ETIMEDOUT;
+ t_errno = TSYSERR;
+ reenable_timers();
ENDTRY
- if (result < 0) {
+ if (result < 0) {
t_close(fd);
log_ti_error("Connecting in proto_open_connection");
return E_QUOTA;
}
-
if (!set_rw_able(fd)) {
t_close(fd);
return E_QUOTA;
}
-
*read_fd = *write_fd = fd;
stream_printf(st1, "port %d", (int) ntohs(rec_addr.sin_port));
@@ -362,14 +348,17 @@ proto_open_connection(Var arglist, int *read_fd, int *write_fd,
return E_NONE;
}
-#endif /* OUTBOUND_NETWORK */
+#endif /* OUTBOUND_NETWORK */
char rcsid_net_sysv_tcp[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:02 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:09 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:02 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.5 1996/03/10 01:13:36 pavel
* Moved definition of DEFAULT_PORT to options.h. Release 1.8.0.
*
diff --git a/network.h b/network.h
index c09e4ab..7f140c2 100644
--- a/network.h
+++ b/network.h
@@ -29,28 +29,28 @@
#include "structures.h"
typedef struct { /* Network's handle on a connection */
- void *ptr;
+ void *ptr;
} network_handle;
typedef struct { /* Network's handle on a listening point */
- void *ptr;
+ void *ptr;
} network_listener;
#include "server.h" /* Include this *after* defining the types */
-extern const char *network_protocol_name(void);
+extern const char *network_protocol_name(void);
/* Returns a string naming the networking
* protocol in use.
*/
-extern const char *network_usage_string(void);
+extern const char *network_usage_string(void);
/* Returns a string describing any extra
* network-specific command-line arguments,
* such as a port number, etc.
*/
-extern int network_initialize(int argc, char **argv,
- Var *desc);
+extern int network_initialize(int argc, char **argv,
+ Var * desc);
/* ARGC and ARGV refer to just the network-
* specific arguments, if any, which always
* come after any network-independent args.
@@ -60,9 +60,9 @@ extern int network_initialize(int argc, char **argv,
* create the server's initial listening point.
*/
-extern enum error network_make_listener(server_listener sl, Var desc,
- network_listener *nl,
- Var *canon, const char **name);
+extern enum error network_make_listener(server_listener sl, Var desc,
+ network_listener * nl,
+ Var * canon, const char **name);
/* DESC is the second argument in a call to the
* built-in MOO function `listen()'; it should
* be used as a specification of a new local
@@ -87,14 +87,14 @@ extern enum error network_make_listener(server_listener sl, Var desc,
* accepting connections.
*/
-extern int network_listen(network_listener nl);
+extern int network_listen(network_listener nl);
/* The network should begin accepting
- * connections on the given listening point,
- * returning true iff this is now possible.
+ * connections on the given listening point,
+ * returning true iff this is now possible.
*/
-extern int network_send_line(network_handle nh, const char *line,
- int flush_ok);
+extern int network_send_line(network_handle nh, const char *line,
+ int flush_ok);
/* The given line should be queued for output
* on the specified connection. 'line' does
* NOT end in a newline; it is up to the
@@ -109,9 +109,9 @@ extern int network_send_line(network_handle nh, const char *line,
* fail if FLUSH_OK is false.
*/
-extern int network_send_bytes(network_handle nh,
- const char *buffer, int buflen,
- int flush_ok);
+extern int network_send_bytes(network_handle nh,
+ const char *buffer, int buflen,
+ int flush_ok);
/* The first BUFLEN bytes in the given BUFFER
* should be queued for output on the specified
* connection. If FLUSH_OK is true, then the
@@ -124,30 +124,30 @@ extern int network_send_bytes(network_handle nh,
* fail if FLUSH_OK is false.
*/
-extern int network_buffered_output_length(network_handle nh);
+extern int network_buffered_output_length(network_handle nh);
/* Returns the number of bytes of output
* currently queued up on the given connection.
*/
-extern void network_suspend_input(network_handle nh);
+extern void network_suspend_input(network_handle nh);
/* The network module is strongly encouraged,
* though not strictly required, to temporarily
* stop calling `server_receive_line()' for
* the given connection.
*/
-extern void network_resume_input(network_handle nh);
+extern void network_resume_input(network_handle nh);
/* The network module may once again feel free
* to call `server_receive_line()' for the
* given connection.
*/
-extern void network_set_connection_binary(network_handle, int);
+extern void network_set_connection_binary(network_handle, int);
/* Set the given connection into or out of
* `binary input mode'.
*/
-extern int network_process_io(int timeout);
+extern int network_process_io(int timeout);
/* This is called at intervals to allow the
* network to flush pending output, receive
* pending input, and handle requests for new
@@ -158,31 +158,31 @@ extern int network_process_io(int timeout);
* timeout).
*/
-extern const char *network_connection_name(network_handle nh);
+extern const char *network_connection_name(network_handle nh);
/* Return some human-readable identification
* for the specified connection. It should fit
* into the phrase 'Connection accepted: %s'.
*/
-extern Var network_connection_options(network_handle nh,
- Var list);
+extern Var network_connection_options(network_handle nh,
+ Var list);
/* Add the current option settings for the
* given connection onto the end of LIST and
* return the new list. Each entry on LIST
* should be a {NAME, VALUE} pair.
*/
-extern int network_connection_option(network_handle nh,
- const char *option,
- Var *value);
+extern int network_connection_option(network_handle nh,
+ const char *option,
+ Var * value);
/* Return true iff the given option name
* is valid for the given connection, storing
* the current setting into *VALUE if valid.
*/
-extern int network_set_connection_option(network_handle nh,
- const char *option,
- Var value);
+extern int network_set_connection_option(network_handle nh,
+ const char *option,
+ Var value);
/* Return true iff the given option/value pair
* is valid for the given connection, applying
* the given setting if valid.
@@ -191,7 +191,7 @@ extern int network_set_connection_option(network_handle nh,
#ifdef OUTBOUND_NETWORK
#include "structures.h"
-extern enum error network_open_connection(Var arglist);
+extern enum error network_open_connection(Var arglist);
/* The given MOO arguments should be used as a
* specification of a remote network connection
* to be made. If the arguments are OK and the
@@ -211,7 +211,7 @@ extern enum error network_open_connection(Var arglist);
#endif
-extern void network_close(network_handle nh);
+extern void network_close(network_handle nh);
/* The specified connection should be closed
* immediately, after flushing as much pending
* output as possible. Effective immediately,
@@ -221,7 +221,7 @@ extern void network_close(network_handle nh);
* network.
*/
-extern void network_close_listener(network_listener nl);
+extern void network_close_listener(network_listener nl);
/* The specified listening point should be
* closed immediately. Effective immediately,
* the given network_listener will not be used
@@ -230,7 +230,7 @@ extern void network_close_listener(network_listener nl);
* network.
*/
-extern void network_shutdown(void);
+extern void network_shutdown(void);
/* All network connections should be closed
* after flushing as much pending output as
* possible, and all listening points should be
@@ -242,12 +242,15 @@ extern void network_shutdown(void);
* never make another call on the network.
*/
-#endif /* Network_H */
+#endif /* Network_H */
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:10 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.4 1996/03/10 01:15:13 pavel
* Added support for `connection_option()'. Release 1.8.0.
*
diff --git a/numbers.c b/numbers.c
index 9eb8317..a3b3edf 100644
--- a/numbers.c
+++ b/numbers.c
@@ -34,10 +34,10 @@
static int
parse_number(const char *str, int *result, int try_floating_point)
{
- char *p;
- int negative = 0;
-
- while (*str && *str == ' ')
+ char *p;
+ int negative = 0;
+
+ while (*str && *str == ' ')
str++;
if (*str == '-') {
str++;
@@ -59,11 +59,11 @@ parse_number(const char *str, int *result, int try_floating_point)
}
static int
-parse_object(const char *str, Objid *result)
+parse_object(const char *str, Objid * result)
{
- int number;
-
- while (*str && *str == ' ')
+ int number;
+
+ while (*str && *str == ' ')
str++;
if (*str == '#')
str++;
@@ -77,10 +77,10 @@ parse_object(const char *str, Objid *result)
static int
parse_float(const char *str, double *result)
{
- char *p;
- int negative = 0;
-
- while (*str && *str == ' ')
+ char *p;
+ int negative = 0;
+
+ while (*str && *str == ' ')
str++;
if (*str == '-') {
str++;
@@ -101,60 +101,60 @@ parse_float(const char *str, double *result)
enum error
become_integer(Var in, int *ret, int called_from_tonum)
-{
+{
switch (in.type) {
- case TYPE_INT:
+ case TYPE_INT:
*ret = in.v.num;
break;
- case TYPE_STR:
+ case TYPE_STR:
if (!(called_from_tonum
? parse_number(in.v.str, ret, 1)
: parse_object(in.v.str, ret)))
*ret = 0;
break;
- case TYPE_OBJ:
+ case TYPE_OBJ:
*ret = in.v.obj;
break;
- case TYPE_ERR:
+ case TYPE_ERR:
*ret = in.v.err;
break;
- case TYPE_FLOAT:
+ case TYPE_FLOAT:
if (*in.v.fnum < (double) INT_MIN || *in.v.fnum > (double) INT_MAX)
return E_FLOAT;
*ret = (int) *in.v.fnum;
break;
- case TYPE_LIST:
+ case TYPE_LIST:
return E_TYPE;
- default:
- errlog("BECOME_INTEGER: Impossible var type: %d\n", (int)in.type);
+ default:
+ errlog("BECOME_INTEGER: Impossible var type: %d\n", (int) in.type);
}
return E_NONE;
}
static enum error
become_float(Var in, double *ret)
-{
+{
switch (in.type) {
- case TYPE_INT:
- *ret = (double) in.v.num;
- break;
- case TYPE_STR:
- if (!parse_float(in.v.str, ret) || !IS_REAL(*ret))
- return E_INVARG;
- break;
- case TYPE_OBJ:
- *ret = (double) in.v.obj;
- break;
- case TYPE_ERR:
- *ret = (double) in.v.err;
- break;
- case TYPE_FLOAT:
- *ret = *in.v.fnum;
- break;
- case TYPE_LIST:
- return E_TYPE;
- default:
- errlog("BECOME_FLOAT: Impossible var type: %d\n", (int)in.type);
+ case TYPE_INT:
+ *ret = (double) in.v.num;
+ break;
+ case TYPE_STR:
+ if (!parse_float(in.v.str, ret) || !IS_REAL(*ret))
+ return E_INVARG;
+ break;
+ case TYPE_OBJ:
+ *ret = (double) in.v.obj;
+ break;
+ case TYPE_ERR:
+ *ret = (double) in.v.err;
+ break;
+ case TYPE_FLOAT:
+ *ret = *in.v.fnum;
+ break;
+ case TYPE_LIST:
+ return E_TYPE;
+ default:
+ errlog("BECOME_FLOAT: Impossible var type: %d\n", (int) in.type);
}
return E_NONE;
}
@@ -162,7 +162,7 @@ become_float(Var in, double *ret)
Var
new_float(double d)
{
- Var v;
+ Var v;
v.type = TYPE_FLOAT;
v.v.fnum = mymalloc(sizeof(double), M_FLOAT);
@@ -176,13 +176,13 @@ static int
to_float(Var v, double *dp)
{
switch (v.type) {
- case TYPE_INT:
+ case TYPE_INT:
*dp = (double) v.v.num;
break;
- case TYPE_FLOAT:
+ case TYPE_FLOAT:
*dp = *v.v.fnum;
break;
- default:
+ default:
return 0;
}
@@ -195,26 +195,25 @@ to_float(Var v, double *dp)
int
matherr(struct exception *x)
{
- switch (x->type)
- {
- case DOMAIN:
- case SING:
- errno = EDOM;
- /* fall thru to... */
- case OVERFLOW:
- x->retval = HUGE_VAL;
- return 1;
- case UNDERFLOW:
- x->retval = 0.0;
- return 1;
- default:
- return 0; /* Take default action */
- }
+ switch (x->type) {
+ case DOMAIN:
+ case SING:
+ errno = EDOM;
+ /* fall thru to... */
+ case OVERFLOW:
+ x->retval = HUGE_VAL;
+ return 1;
+ case UNDERFLOW:
+ x->retval = 0.0;
+ return 1;
+ default:
+ return 0; /* Take default action */
+ }
}
#endif
+
-
- /**** opcode implementations ****/
+/**** opcode implementations ****/
/*
* All of the following implementations are strict, not performing any
@@ -223,7 +222,7 @@ matherr(struct exception *x)
int
do_equals(Var lhs, Var rhs)
-{ /* LHS == RHS */
+{ /* LHS == RHS */
/* At least one of LHS and RHS is TYPE_FLOAT */
if (lhs.type != rhs.type)
@@ -246,7 +245,7 @@ compare_integers(int a, int b)
Var
compare_numbers(Var a, Var b)
{
- Var ans;
+ Var ans;
if (a.type != b.type) {
ans.type = TYPE_ERR;
@@ -255,8 +254,8 @@ compare_numbers(Var a, Var b)
ans.type = TYPE_INT;
ans.v.num = compare_integers(a.v.num, b.v.num);
} else {
- double aa = *a.v.fnum, bb = *b.v.fnum;
-
+ double aa = *a.v.fnum, bb = *b.v.fnum;
+
ans.type = TYPE_INT;
if (aa < bb)
ans.v.num = -1;
@@ -297,7 +296,6 @@ compare_numbers(Var a, Var b)
SIMPLE_BINARY(add, +)
SIMPLE_BINARY(subtract, -)
SIMPLE_BINARY(multiply, *)
-
#define DIVISION_OP(name, iop, fexpr) \
Var \
do_ ## name(Var a, Var b) \
@@ -330,14 +328,13 @@ SIMPLE_BINARY(multiply, *)
DIVISION_OP(divide, /, *a.v.fnum / *b.v.fnum)
DIVISION_OP(modulus, %, fmod(*a.v.fnum, *b.v.fnum))
-
Var
do_power(Var lhs, Var rhs)
-{ /* LHS ^ RHS */
- Var ans;
+{ /* LHS ^ RHS */
+ Var ans;
- if (lhs.type == TYPE_INT) { /* integer exponentiation */
- int a = lhs.v.num, b, r;
+ if (lhs.type == TYPE_INT) { /* integer exponentiation */
+ int a = lhs.v.num, b, r;
if (rhs.type != TYPE_INT)
goto type_error;
@@ -346,40 +343,44 @@ do_power(Var lhs, Var rhs)
ans.type = TYPE_INT;
if (b < 0)
switch (a) {
- case -1:
+ case -1:
ans.v.num = (b % 2 == 0 ? 1 : -1);
break;
- case 0:
+ case 0:
ans.type = TYPE_ERR;
ans.v.err = E_DIV;
break;
- case 1:
+ case 1:
ans.v.num = 1;
break;
- default:
+ default:
ans.v.num = 0;
+ } else {
+ r = 1;
+ while (b != 0) {
+ if (b % 2 != 0)
+ r *= a;
+ a *= a;
+ b >>= 1;
}
- else {
- r = 1;
- while (b != 0) {
- if (b % 2 != 0)
- r *= a;
- a *= a;
- b >>= 1;
- }
- ans.v.num = r;
+ ans.v.num = r;
}
- } else if (lhs.type == TYPE_FLOAT) { /* floating-point exponentiation */
+ } else if (lhs.type == TYPE_FLOAT) { /* floating-point exponentiation */
double d;
switch (rhs.type) {
- case TYPE_INT: d = (double) rhs.v.num; break;
- case TYPE_FLOAT: d = *rhs.v.fnum; break;
- default: goto type_error;
+ case TYPE_INT:
+ d = (double) rhs.v.num;
+ break;
+ case TYPE_FLOAT:
+ d = *rhs.v.fnum;
+ break;
+ default:
+ goto type_error;
}
errno = 0;
d = pow(*lhs.v.fnum, d);
- if (errno != 0 || !IS_REAL(d)) {
+ if (errno != 0 || !IS_REAL(d)) {
ans.type = TYPE_ERR;
ans.v.err = E_FLOAT;
} else
@@ -394,34 +395,34 @@ do_power(Var lhs, Var rhs)
ans.v.err = E_TYPE;
return ans;
}
-
- /**** built in functions ****/
+
+/**** built in functions ****/
static package
bf_toint(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
+ Var r;
enum error e;
-
+
r.type = TYPE_INT;
e = become_integer(arglist.v.list[1], &(r.v.num), 1);
-
+
free_var(arglist);
if (e != E_NONE)
return make_error_pack(e);
-
+
return make_var_pack(r);
}
static package
bf_tofloat(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
+ Var r;
enum error e;
-
+
r = new_float(0.0);
e = become_float(arglist.v.list[1], r.v.fnum);
-
+
free_var(arglist);
if (e == E_NONE)
return make_var_pack(r);
@@ -433,12 +434,12 @@ bf_tofloat(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_min(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
- int i, nargs = arglist.v.list[0].v.num;
- int bad_types = 0;
-
+ Var r;
+ int i, nargs = arglist.v.list[0].v.num;
+ int bad_types = 0;
+
r = arglist.v.list[1];
- if (r.type == TYPE_INT) { /* integers */
+ if (r.type == TYPE_INT) { /* integers */
for (i = 2; i <= nargs; i++)
if (arglist.v.list[i].type != TYPE_INT)
bad_types = 1;
@@ -463,12 +464,12 @@ bf_min(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_max(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
- int i, nargs = arglist.v.list[0].v.num;
- int bad_types = 0;
-
+ Var r;
+ int i, nargs = arglist.v.list[0].v.num;
+ int bad_types = 0;
+
r = arglist.v.list[1];
- if (r.type == TYPE_INT) { /* integers */
+ if (r.type == TYPE_INT) { /* integers */
for (i = 2; i <= nargs; i++)
if (arglist.v.list[i].type != TYPE_INT)
bad_types = 1;
@@ -481,7 +482,7 @@ bf_max(Var arglist, Byte next, void *vdata, Objid progr)
else if (*arglist.v.list[i].v.fnum > *r.v.fnum)
r = arglist.v.list[i];
}
-
+
r = var_ref(r);
free_var(arglist);
if (bad_types)
@@ -494,7 +495,7 @@ static package
bf_abs(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
-
+
r = var_dup(arglist.v.list[1]);
if (r.type == TYPE_INT) {
if (r.v.num < 0)
@@ -504,7 +505,7 @@ bf_abs(Var arglist, Byte next, void *vdata, Objid progr)
free_var(arglist);
return make_var_pack(r);
-}
+}
#define MATH_FUNC(name) \
static package \
@@ -525,29 +526,23 @@ bf_abs(Var arglist, Byte next, void *vdata, Objid progr)
}
MATH_FUNC(sqrt)
-
MATH_FUNC(sin)
MATH_FUNC(cos)
MATH_FUNC(tan)
-
MATH_FUNC(asin)
MATH_FUNC(acos)
-
MATH_FUNC(sinh)
MATH_FUNC(cosh)
MATH_FUNC(tanh)
-
MATH_FUNC(exp)
MATH_FUNC(log)
MATH_FUNC(log10)
-
MATH_FUNC(ceil)
MATH_FUNC(floor)
-
-static package
-bf_trunc(Var arglist, Byte next, void *vdata, Objid progr)
+ static package
+ bf_trunc(Var arglist, Byte next, void *vdata, Objid progr)
{
- double d;
+ double d;
d = *arglist.v.list[1].v.fnum;
errno = 0;
@@ -558,7 +553,7 @@ bf_trunc(Var arglist, Byte next, void *vdata, Objid progr)
free_var(arglist);
if (errno == EDOM)
return make_error_pack(E_INVARG);
- else if (errno != 0 || !IS_REAL(d))
+ else if (errno != 0 || !IS_REAL(d))
return make_error_pack(E_FLOAT);
else
return make_var_pack(new_float(d));
@@ -567,7 +562,7 @@ bf_trunc(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_atan(Var arglist, Byte next, void *vdata, Objid progr)
{
- double d, dd;
+ double d, dd;
d = *arglist.v.list[1].v.fnum;
errno = 0;
@@ -579,7 +574,7 @@ bf_atan(Var arglist, Byte next, void *vdata, Objid progr)
free_var(arglist);
if (errno == EDOM)
return make_error_pack(E_INVARG);
- else if (errno != 0 || !IS_REAL(d))
+ else if (errno != 0 || !IS_REAL(d))
return make_error_pack(E_FLOAT);
else
return make_var_pack(new_float(d));
@@ -599,40 +594,40 @@ static package
bf_ctime(Var arglist, Byte next, void *vdata, Objid progr)
{
Var r;
- time_t c;
- char buffer[50];
-
+ time_t c;
+ char buffer[50];
+
if (arglist.v.list[0].v.num == 1) {
c = arglist.v.list[1].v.num;
} else {
c = time(0);
}
- { /* Format the time, including a timezone name */
+ { /* Format the time, including a timezone name */
#if HAVE_STRFTIME
strftime(buffer, 50, "%a %b %d %H:%M:%S %Y %Z", localtime(&c));
#else
# if HAVE_TM_ZONE
- struct tm *t = localtime(&c);
- char *tzname = t->tm_zone;
+ struct tm *t = localtime(&c);
+ char *tzname = t->tm_zone;
# else
# if !HAVE_TZNAME
- const char *tzname = "XXX";
+ const char *tzname = "XXX";
# endif
-# endif
-
+# endif
+
strcpy(buffer, ctime(&c));
buffer[24] = ' ';
strncpy(buffer + 25, tzname, 3);
buffer[28] = '\0';
#endif
}
-
+
if (buffer[8] == '0')
buffer[8] = ' ';
r.type = TYPE_STR;
r.v.str = str_dup(buffer);
-
+
free_var(arglist);
return make_var_pack(r);
}
@@ -642,13 +637,13 @@ bf_random(Var arglist, Byte next, void *vdata, Objid progr)
{
int nargs = arglist.v.list[0].v.num;
int num = (nargs >= 1 ? arglist.v.list[1].v.num : 1);
-
+
free_var(arglist);
-
- if (num <= 0)
+
+ if (num <= 0)
return make_error_pack(E_INVARG);
else {
- Var r;
+ Var r;
r.type = TYPE_INT;
if (nargs == 0)
@@ -661,13 +656,13 @@ bf_random(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_floatstr(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (float, precision [, sci-notation]) */
- double d = *arglist.v.list[1].v.fnum;
- int prec = arglist.v.list[2].v.num;
- int use_sci = (arglist.v.list[0].v.num >= 3
- && is_true(arglist.v.list[3]));
- char fmt[10], output[500]; /* enough for IEEE double */
- Var r;
+{ /* (float, precision [, sci-notation]) */
+ double d = *arglist.v.list[1].v.fnum;
+ int prec = arglist.v.list[2].v.num;
+ int use_sci = (arglist.v.list[0].v.num >= 3
+ && is_true(arglist.v.list[3]));
+ char fmt[10], output[500]; /* enough for IEEE double */
+ Var r;
free_var(arglist);
if (prec > DBL_DIG + 4)
@@ -687,7 +682,7 @@ Var zero; /* useful constant */
void
register_numbers(void)
-{
+{
zero.type = TYPE_INT;
zero.v.num = 0;
register_function("toint", 1, 1, bf_toint, TYPE_ANY);
@@ -723,9 +718,12 @@ register_numbers(void)
char rcsid_numbers[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:00 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:11 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:00 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.5 1996/03/19 07:15:27 pavel
* Fixed floatstr() to allow DBL_DIG + 4 digits. Release 1.8.0p2.
*
diff --git a/numbers.h b/numbers.h
index 463ef3a..a1004a3 100644
--- a/numbers.h
+++ b/numbers.h
@@ -17,24 +17,27 @@
#include "structures.h"
-extern Var new_float(double);
-extern enum error become_integer(Var, int *, int);
+extern Var new_float(double);
+extern enum error become_integer(Var, int *, int);
-extern int do_equals(Var, Var);
-extern int compare_integers(int, int);
-extern Var compare_numbers(Var, Var);
+extern int do_equals(Var, Var);
+extern int compare_integers(int, int);
+extern Var compare_numbers(Var, Var);
-extern Var do_add(Var, Var);
-extern Var do_subtract(Var, Var);
-extern Var do_multiply(Var, Var);
-extern Var do_divide(Var, Var);
-extern Var do_modulus(Var, Var);
-extern Var do_power(Var, Var);
+extern Var do_add(Var, Var);
+extern Var do_subtract(Var, Var);
+extern Var do_multiply(Var, Var);
+extern Var do_divide(Var, Var);
+extern Var do_modulus(Var, Var);
+extern Var do_power(Var, Var);
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:04 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:11 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:04 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 1.1 1996/02/08 07:28:25 pavel
* Initial revision
*
diff --git a/objects.c b/objects.c
index 2d590e1..76c3ac5 100644
--- a/objects.c
+++ b/objects.c
@@ -37,7 +37,7 @@ controls(Objid who, Objid what)
static Var
make_arglist(Objid what)
{
- Var r;
+ Var r;
r = new_list(1);
r.v.list[1].type = TYPE_OBJ;
@@ -45,24 +45,24 @@ make_arglist(Objid what)
return r;
}
-
+
struct bf_move_data {
- Objid what, where;
+ Objid what, where;
};
static package
do_move(Var arglist, Byte next, struct bf_move_data *data, Objid progr)
{
- Objid what = data->what, where = data->where;
- Objid oid, oldloc;
- int accepts;
- Var args;
- enum error e;
-
+ Objid what = data->what, where = data->where;
+ Objid oid, oldloc;
+ int accepts;
+ Var args;
+ enum error e;
+
switch (next) {
- case 1: /* Check validity and decide `accepts' */
- if (!valid(what) || (!valid(where) && where != NOTHING))
+ case 1: /* Check validity and decide `accepts' */
+ if (!valid(what) || (!valid(where) && where != NOTHING))
return make_error_pack(E_INVARG);
else if (!controls(progr, what))
return make_error_pack(E_PERM);
@@ -72,72 +72,71 @@ do_move(Var arglist, Byte next, struct bf_move_data *data, Objid progr)
args = make_arglist(what);
e = call_verb(where, "accept", args, 0);
/* e will not be E_INVIND */
-
- if (e == E_NONE)
+
+ if (e == E_NONE)
return make_call_pack(2, data);
else {
free_var(args);
if (e == E_VERBNF)
accepts = 0;
- else /* (e == E_MAXREC) */
+ else /* (e == E_MAXREC) */
return make_error_pack(e);
}
}
goto accepts_decided;
- case 2: /* Returned from `accepts' call */
+ case 2: /* Returned from `accepts' call */
accepts = is_true(arglist);
accepts_decided:
- if (!is_wizard(progr) && accepts == 0)
+ if (!is_wizard(progr) && accepts == 0)
return make_error_pack(E_NACC);
-
+
if (!valid(what)
- || (where != NOTHING && !valid(where))
- || db_object_location(what) == where)
+ || (where != NOTHING && !valid(where))
+ || db_object_location(what) == where)
return no_var_pack();
-
+
/* Check to see that we're not trying to violate the hierarchy */
for (oid = where; oid != NOTHING; oid = db_object_location(oid))
if (oid == what)
return make_error_pack(E_RECMOVE);
-
+
oldloc = db_object_location(what);
db_change_location(what, where);
-
+
args = make_arglist(what);
e = call_verb(oldloc, "exitfunc", args, 0);
-
- if (e == E_NONE)
+
+ if (e == E_NONE)
return make_call_pack(3, data);
else {
free_var(args);
- if (e == E_MAXREC)
+ if (e == E_MAXREC)
return make_error_pack(e);
}
/* e == E_INVIND or E_VERBNF, in both cases fall through */
- case 3: /* Returned from exitfunc call */
+ case 3: /* Returned from exitfunc call */
if (valid(where) && valid(what)
&& db_object_location(what) == where) {
args = make_arglist(what);
e = call_verb(where, "enterfunc", args, 0);
/* e != E_INVIND */
-
- if (e == E_NONE)
+
+ if (e == E_NONE)
return make_call_pack(4, data);
else {
free_var(args);
- if (e == E_MAXREC)
+ if (e == E_MAXREC)
return make_error_pack(e);
/* else e == E_VERBNF, fall through */
}
}
-
- case 4: /* Returned from enterfunc call */
+ case 4: /* Returned from enterfunc call */
return no_var_pack();
- default:
+ default:
panic("Unknown PC in DO_MOVE");
return no_var_pack(); /* Dead code to eliminate compiler warning */
}
@@ -147,20 +146,19 @@ static package
bf_move(Var arglist, Byte next, void *vdata, Objid progr)
{
struct bf_move_data *data = vdata;
- package p;
-
+ package p;
+
if (next == 1) {
data = alloc_data(sizeof(*data));
data->what = arglist.v.list[1].v.obj;
data->where = arglist.v.list[2].v.obj;
}
-
p = do_move(arglist, next, data, progr);
free_var(arglist);
-
+
if (p.kind != BI_CALL)
free_data(data);
-
+
return p;
}
@@ -178,28 +176,28 @@ bf_move_read()
{
struct bf_move_data *data = alloc_data(sizeof(*data));
- if (dbio_scanf("bf_move data: what = %d, where = %d\n",
- &data->what, &data->where) == 2)
+ if (dbio_scanf("bf_move data: what = %d, where = %d\n",
+ &data->what, &data->where) == 2)
return data;
else
return 0;
-}
+}
static package
bf_toobj(Var arglist, Byte next, void *vdata, Objid progr)
{
- Var r;
- int i;
- enum error e;
-
+ Var r;
+ int i;
+ enum error e;
+
r.type = TYPE_OBJ;
e = become_integer(arglist.v.list[1], &i, 0);
r.v.obj = i;
-
+
free_var(arglist);
if (e != E_NONE)
return make_error_pack(e);
-
+
return make_var_pack(r);
}
@@ -215,9 +213,9 @@ bf_typeof(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_valid(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (object) */
+{ /* (object) */
Var r;
-
+
r.type = TYPE_INT;
r.v.num = valid(arglist.v.list[1].v.obj);
free_var(arglist);
@@ -225,8 +223,8 @@ bf_valid(Var arglist, Byte next, void *vdata, Objid progr)
}
static package
-bf_max_object(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* () */
+bf_max_object(Var arglist, Byte next, void *vdata, Objid progr)
+{ /* () */
Var r;
free_var(arglist);
@@ -237,61 +235,61 @@ bf_max_object(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_create(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (parent [, owner]) */
+{ /* (parent [, owner]) */
Objid *data = vdata;
- Var r;
-
- if (next == 1) {
+ Var r;
+
+ if (next == 1) {
Objid parent, owner;
-
+
parent = arglist.v.list[1].v.obj;
owner = (arglist.v.list[0].v.num == 2
? arglist.v.list[2].v.obj
: progr);
free_var(arglist);
-
+
if ((valid(parent) ? !db_object_allows(parent, progr, FLAG_FERTILE)
- : (parent != NOTHING))
- || (owner != progr && !is_wizard(progr)))
+ : (parent != NOTHING))
+ || (owner != progr && !is_wizard(progr)))
return make_error_pack(E_PERM);
- if (valid(owner) && !decr_quota(owner))
+ if (valid(owner) && !decr_quota(owner))
return make_error_pack(E_QUOTA);
else {
- enum error e;
- Objid oid = db_create_object();
- Var args;
-
+ enum error e;
+ Objid oid = db_create_object();
+ Var args;
+
db_set_object_name(oid, str_dup(""));
db_set_object_owner(oid, owner == NOTHING ? oid : owner);
db_change_parent(oid, parent);
-
+
data = alloc_data(sizeof(*data));
*data = oid;
args = new_list(0);
e = call_verb(oid, "initialize", args, 0);
/* e will not be E_INVIND */
-
+
if (e == E_NONE)
return make_call_pack(2, data);
-
+
free_data(data);
free_var(args);
-
- if (e == E_MAXREC)
+
+ if (e == E_MAXREC)
return make_error_pack(e);
- else { /* (e == E_VERBNF) do nothing */
+ else { /* (e == E_VERBNF) do nothing */
r.type = TYPE_OBJ;
r.v.obj = oid;
return make_var_pack(r);
}
}
- } else { /* next == 2, returns from initialize verb_call */
+ } else { /* next == 2, returns from initialize verb_call */
r.type = TYPE_OBJ;
r.v.obj = *data;
free_data(data);
return make_var_pack(r);
- }
+ }
}
static void
@@ -304,7 +302,7 @@ static void *
bf_create_read(void)
{
Objid *data = alloc_data(sizeof(Objid));
-
+
if (dbio_scanf("bf_create data: oid = %d\n", data) == 1)
return data;
else
@@ -313,10 +311,10 @@ bf_create_read(void)
static package
bf_chparent(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (object, new_parent) */
- Objid what = arglist.v.list[1].v.obj;
- Objid parent = arglist.v.list[2].v.obj;
- Objid oid;
+{ /* (object, new_parent) */
+ Objid what = arglist.v.list[1].v.obj;
+ Objid parent = arglist.v.list[2].v.obj;
+ Objid oid;
free_var(arglist);
if (!valid(what)
@@ -330,7 +328,7 @@ bf_chparent(Var arglist, Byte next, void *vdata, Objid progr)
for (oid = parent; oid != NOTHING; oid = db_object_parent(oid))
if (oid == what)
return make_error_pack(E_RECMOVE);
-
+
if (!db_change_parent(what, parent))
return make_error_pack(E_INVARG);
else
@@ -340,13 +338,13 @@ bf_chparent(Var arglist, Byte next, void *vdata, Objid progr)
static package
bf_parent(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (object) */
+{ /* (object) */
Var r;
Objid obj = arglist.v.list[1].v.obj;
-
+
free_var(arglist);
-
- if (!valid(obj))
+
+ if (!valid(obj))
return make_error_pack(E_INVARG);
else {
r.type = TYPE_OBJ;
@@ -356,14 +354,14 @@ bf_parent(Var arglist, Byte next, void *vdata, Objid progr)
}
struct children_data {
- Var r;
- int i;
+ Var r;
+ int i;
};
static int
add_to_list(void *data, Objid child)
{
- struct children_data *d = data;
+ struct children_data *d = data;
d->i++;
d->r.v.list[d->i].type = TYPE_OBJ;
@@ -374,15 +372,15 @@ add_to_list(void *data, Objid child)
static package
bf_children(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (object) */
+{ /* (object) */
Objid oid = arglist.v.list[1].v.obj;
-
+
free_var(arglist);
-
- if (!valid(oid))
+
+ if (!valid(oid))
return make_error_pack(E_INVARG);
else {
- struct children_data d;
+ struct children_data d;
d.r = new_list(db_count_children(oid));
d.i = 0;
@@ -396,15 +394,15 @@ static int
move_to_nothing(Objid oid)
{
/* All we need to do is change the location and run the exitfunc. */
- Objid oldloc = db_object_location(oid);
- Var args;
- enum error e;
-
+ Objid oldloc = db_object_location(oid);
+ Var args;
+ enum error e;
+
db_change_location(oid, NOTHING);
-
+
args = make_arglist(oid);
e = call_verb(oldloc, "exitfunc", args, 0);
-
+
if (e == E_NONE)
return 1;
@@ -415,14 +413,14 @@ move_to_nothing(Objid oid)
static int
first_proc(void *data, Objid oid)
{
- Objid *oidp = data;
+ Objid *oidp = data;
*oidp = oid;
return 1;
}
static Objid
-get_first(Objid oid, int (*for_all)(Objid, int (*)(void *, Objid), void *))
+get_first(Objid oid, int (*for_all) (Objid, int (*)(void *, Objid), void *))
{
Objid result = NOTHING;
@@ -433,35 +431,35 @@ get_first(Objid oid, int (*for_all)(Objid, int (*)(void *, Objid), void *))
static package
bf_recycle(Var arglist, Byte func_pc, void *vdata, Objid progr)
-{ /* (object) */
- Objid oid, c;
- Var args;
- enum error e;
- Objid *data = vdata;
-
+{ /* (object) */
+ Objid oid, c;
+ Var args;
+ enum error e;
+ Objid *data = vdata;
+
switch (func_pc) {
- case 1:
+ case 1:
oid = arglist.v.list[1].v.obj;
free_var(arglist);
- if (!valid(oid))
+ if (!valid(oid))
return make_error_pack(E_INVARG);
else if (!controls(progr, oid))
return make_error_pack(E_PERM);
-
+
data = alloc_data(sizeof(*data));
*data = oid;
args = new_list(0);
e = call_verb(oid, "recycle", args, 0);
/* e != E_INVIND */
-
- if (e == E_NONE)
+
+ if (e == E_NONE)
return make_call_pack(2, data);
/* else e == E_VERBNF or E_MAXREC; fall through */
free_var(args);
goto moving_contents;
- case 2: /* moving all contents to #-1 */
+ case 2: /* moving all contents to #-1 */
free_var(arglist);
oid = *data;
@@ -470,13 +468,12 @@ bf_recycle(Var arglist, Byte func_pc, void *vdata, Objid progr)
free_data(data);
return no_var_pack();
}
-
while ((c = get_first(oid, db_for_all_contents)) != NOTHING)
if (move_to_nothing(c))
return make_call_pack(2, data);
if (db_object_location(oid) != NOTHING
- && move_to_nothing(oid))
+ && move_to_nothing(oid))
/* Return to same case because this :exitfunc might add new */
/* contents to OID or even move OID right back in. */
return make_call_pack(2, data);
@@ -491,11 +488,11 @@ bf_recycle(Var arglist, Byte func_pc, void *vdata, Objid progr)
/* Finish the demolition. */
incr_quota(db_object_owner(oid));
db_destroy_object(oid);
-
+
free_data(data);
return no_var_pack();
}
-
+
panic("Can't happen in BF_RECYCLE");
return no_var_pack();
}
@@ -503,17 +500,17 @@ bf_recycle(Var arglist, Byte func_pc, void *vdata, Objid progr)
static void
bf_recycle_write(void *vdata)
{
- Objid *data = vdata;
-
+ Objid *data = vdata;
+
dbio_printf("bf_recycle data: oid = %d, cont = 0\n", *data);
}
static void *
bf_recycle_read(void)
{
- Objid *data = alloc_data(sizeof(*data));
- int dummy;
-
+ Objid *data = alloc_data(sizeof(*data));
+ int dummy;
+
/* I use a `dummy' variable here and elsewhere instead of the `*'
* assignment-suppression syntax of `scanf' because it allows more
* straightforward error checking; unfortunately, the standard says that
@@ -525,48 +522,48 @@ bf_recycle_read(void)
return data;
else
return 0;
-}
-
+}
+
static package
bf_players(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* () */
+{ /* () */
free_var(arglist);
return make_var_pack(var_ref(db_all_users()));
}
static package
bf_is_player(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (object) */
+{ /* (object) */
Var r;
Objid oid = arglist.v.list[1].v.obj;
-
+
free_var(arglist);
-
+
if (!valid(oid))
return make_error_pack(E_INVARG);
-
+
r.type = TYPE_INT;
r.v.num = is_user(oid);
return make_var_pack(r);
}
static package
-bf_set_player_flag(Var arglist, Byte next, void *vdata, Objid progr)
-{ /* (object, yes/no) */
+bf_set_player_flag(Var arglist, Byte next, void *vdata, Objid progr)
+{ /* (object, yes/no) */
Var obj;
char bool;
-
+
obj = arglist.v.list[1];
bool = is_true(arglist.v.list[2]);
-
+
free_var(arglist);
-
+
if (!valid(obj.v.obj))
return make_error_pack(E_INVARG);
- else if (!is_wizard(progr))
+ else if (!is_wizard(progr))
return make_error_pack(E_PERM);
-
+
if (bool) {
db_set_object_flag(obj.v.obj, FLAG_USER);
} else {
@@ -577,14 +574,14 @@ bf_set_player_flag(Var arglist, Byte next, void *vdata, Objid progr)
}
static package
-bf_object_bytes(Var arglist, Byte next, void *vdata, Objid progr)
+bf_object_bytes(Var arglist, Byte next, void *vdata, Objid progr)
{
- Objid oid = arglist.v.list[1].v.obj;
- Var v;
+ Objid oid = arglist.v.list[1].v.obj;
+ Var v;
free_var(arglist);
- if (!is_wizard(progr))
+ if (!is_wizard(progr))
return make_error_pack(E_PERM);
else if (!valid(oid))
return make_error_pack(E_INVIND);
@@ -597,7 +594,7 @@ bf_object_bytes(Var arglist, Byte next, void *vdata, Objid progr)
void
register_objects(void)
-{
+{
register_function("toobj", 1, 1, bf_toobj, TYPE_ANY);
register_function("typeof", 1, 1, bf_typeof, TYPE_ANY);
register_function_with_read_write("create", 1, 2, bf_create,
@@ -624,9 +621,12 @@ register_objects(void)
char rcsid_objects[] = "$Id$";
/* $Log$
-/* Revision 1.1 1997/03/03 03:45:01 nop
-/* Initial revision
+/* Revision 1.2 1997/03/03 04:19:12 nop
+/* GNU Indent normalization
/*
+ * Revision 1.1.1.1 1997/03/03 03:45:01 nop
+ * LambdaMOO 1.8.0p5
+ *
* Revision 2.3 1996/04/19 01:17:48 pavel
* Rationalized the errors that can be raised from chparent().
* Release 1.8.0p4.
diff --git a/opcode.h b/opcode.h
index 808522f..df0a460 100644
--- a/opcode.h
+++ b/opcode.h
@@ -29,9 +29,9 @@ enum Extended_Opcode {
EOP_CATCH, EOP_TRY_EXCEPT, EOP_TRY_FINALLY,
EOP_WHILE_ID, EOP_EXIT, EOP_EXIT_ID,
EOP_SCATTER, EOP_EXP,
-