Example #1
0
File: pragma.c Project: pmprog/cc65
static void FlagPragma (StrBuf* B, IntStack* Stack)
/* Handle a pragma that expects a boolean paramater */
{
    StrBuf Ident = AUTO_STRBUF_INITIALIZER;
    long   Val;
    int    Push;


    /* Try to read an identifier */
    int IsIdent = SB_GetSym (B, &Ident, 0);

    /* Check if we have a first argument named "pop" */
    if (IsIdent && SB_CompareStr (&Ident, "pop") == 0) {
        PopInt (Stack);
        /* No other arguments allowed */
        return;
    }

    /* Check if we have a first argument named "push" */
    if (IsIdent && SB_CompareStr (&Ident, "push") == 0) {
        Push = 1;
        if (!GetComma (B)) {
            goto ExitPoint;
        }
        IsIdent = SB_GetSym (B, &Ident, 0);
    } else {
        Push = 0;
    }

    /* Boolean argument follows */
    if (IsIdent) {
        Val = BoolKeyword (&Ident);
    } else if (!GetNumber (B, &Val)) {
        goto ExitPoint;
    }

    /* Set/push the new value */
    if (Push) {
        PushInt (Stack, Val);
    } else {
        IS_Set (Stack, Val);
    }

ExitPoint:
    /* Free the identifier */
    SB_Done (&Ident);
}
Example #2
0
void 
prim_condescr(PRIM_PROTOTYPE)
{
    /* int -- int */
    CHECKOP(1);
    oper1 = POP();
    if (mlev < LM3)
	abort_interp("M3 prim");
    if (oper1->type != PROG_INTEGER)
	abort_interp("Argument not an integer (1)");
    result = oper1->data.number;
    if ((result < 1) || (result > pcount()))
	abort_interp("Invalid connection number (1)");
    result = pdescr(result);
    CLEAR(oper1);
    PushInt(result);
}
Example #3
0
void prim_bwrite(PRIM_PROTOTYPE)
{
  FILE *fh;
  char *filename;
  int result, tempdat;
  double offset;
  CHECKOP(3);
  oper1 = POP();
  oper2 = POP();
  oper3 = POP();
  if (getuid() == 0 ) 
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if (oper1->type != PROG_INTEGER) abort_interp("Arguement 1 is not an integer.");
  if (oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number.");
  if (oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string.");
  if (!oper2->data.string) abort_interp("Arguement 2 is a null string.");
  if (oper3->type != PROG_INTEGER) abort_interp("Arguement 3 is not an integer.");
  if (oper3->data.number < 0 ) abort_interp("Arguement 3 is a negative number.");
  offset = oper1->data.number;
  filename = oper2->data.string->data;
  tempdat = (int) oper3->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif
  fh = fopen(filename, "w");
  if (fh == NULL) { result = 0; } else {
    fseek(fh, offset, SEEK_SET);
    fputc(tempdat - 8, fh); 
    fclose(fh);
    result = 1;
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s BWRITE : %s \n", program, unparse_object(player, player), oper2->data.string->data); 
  }
  CLEAR(oper1);
  CLEAR(oper2);
  CLEAR(oper3);
  PushInt(result);
}
Example #4
0
void
prim_ignoringp(PRIM_PROTOTYPE)
{
    CHECKOP(2);
    oper1 = POP();
    oper2 = POP();
    if (mlev < 3)
	abort_interp("Permission Denied.");
    if (!valid_object(oper1))
	abort_interp("Invalid object. (2)");
    if (!valid_object(oper2))
	abort_interp("Invalid object. (1)");
    result = ignore_is_ignoring(oper2->data.objref, oper1->data.objref);
    CLEAR(oper1);
    CLEAR(oper2);
    PushInt(result);
}
Example #5
0
void 
prim_ignoringp(PRIM_PROTOTYPE)
{
    CHECKOP(2);
    oper2 = POP();
    oper1 = POP();
    if (!valid_object(oper1))
	abort_interp("invalid argument (1)");
    if (!valid_object(oper2))
	abort_interp("invalid argument (2)");
    ref = oper1->data.objref;
    ref = OWNER(ref);
    if (Typeof(ref) != TYPE_PLAYER)
	abort_interp("invalid argument (1)");
    result = ignoring(ref, OWNER(oper2->data.objref));
    PushInt(result);
}
Example #6
0
void 
prim_contime(PRIM_PROTOTYPE)
{
    /* int -- int */
    CHECKOP(1);
    oper1 = POP();
    if (mlev < (tp_compatible_muf ? LM3 : LM2))
	abort_interp(tp_compatible_muf ? "M3 prim" : "M2 prim");
    if (oper1->type != PROG_INTEGER)
	abort_interp("Argument not an integer (1)");
    result = oper1->data.number;
    if ((result < 1) || (result > pcount()))
	abort_interp("Invalid connection number (1)");
    result = pontime(result);
    CHECKOFLOW(1);
    CLEAR(oper1);
    PushInt(result);
}
Example #7
0
void prim_bread(PRIM_PROTOTYPE)
{
  FILE *fh; /* Should return -1 for file open error. */ 
  char *filename; /* -2 for EOF. */ 
  double offset;
  int result;
  CHECKOP(2);
  oper1 = POP();
  oper2 = POP();
  if (getuid() == 0 ) 
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if(oper1->type != PROG_INTEGER)
    abort_interp("Arguement 1 is not an integer.");
  if(oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number.");
  if(oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string.");
  if(!oper2->data.string) abort_interp("Argueemnt 2 is a null string.");
  offset = oper1->data.number;
  filename = oper2->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif
  fh = fopen(filename, "r");
  if (fh == NULL) { result = -1; } else {
    fseek(fh, offset, SEEK_SET);
    result = fgetc(fh);
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s BREAD: %s \n", program, unparse_object(player, player), oper2->data.string->data); 
    if (result == EOF) { 
      result = -2; 
    } 
    fclose(fh);
  }
  CLEAR(oper1);
  CLEAR(oper2);
  PushInt(result);
} 
Example #8
0
void prim_fren(PRIM_PROTOTYPE)
{
  char *oldname, *newname;
  char tempB[BUFFER_LEN] = "";
  CHECKOP(2);
  oper1 = POP();
  oper2 = POP();
  if (getuid() == 0 )
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if(oper1->type != PROG_STRING) abort_interp("Argument 1 is not a string.");
  if(!oper1->data.string) abort_interp("Argument 1 is a null string.");
  if(oper2->type != PROG_STRING) abort_interp("Argument 2 is not a string.");
  if(!oper2->data.string) abort_interp("Argument 2 is a null string.");
  newname = oper1->data.string->data;
  oldname = oper2->data.string->data; /* ( s<old> s<new> -- i ) */
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name( newname )))
      abort_interp( "Invalid file name. (2)");
  if ( strchr( newname, '$' ) == NULL )
    newname = set_directory(newname);
  else
    newname = parse_token( newname );
  if ( newname == NULL )
    abort_interp( "Invalid shortcut used. (2)" );   
  strcpy( tempB, newname );
  if (!(valid_name(oldname)))
      abort_interp( "Invalid file name. (1)");
  if ( strchr( oldname, '$' ) == NULL )
    oldname = set_directory(oldname);
  else
    oldname = parse_token( oldname );
  if ( oldname == NULL )
    abort_interp( "Invalid shortcut used. (1)" );
  newname = tempB;
#endif
  result = rename(oldname, newname);
  if(tp_log_files)
    log2filetime("logs/files", "#%d by %s FREN: %s -> %s \n", program, unparse_object(player, player), oper2->data.string->data, oper1->data.string->data); 
  CLEAR(oper1);
  CLEAR(oper2);
  PushInt(result);
} 
Example #9
0
void prim_fsinfo(PRIM_PROTOTYPE) 
{ 
  struct statfs fs; 
  if (getuid() == 0 ) 
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  /* Returns: */ 
  /* Magic Number, Total Blocks, Free Blocks, Available Blocks, Total Files, */ 
  /* Free Files, Block Size (bytes), and Max Name Length. */ 
  statfs("/", &fs); 
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s FSINFO \n", program, unparse_object(player, player)); 
  PushInt(fs.f_type); 
  PushInt(fs.f_blocks); 
  PushInt(fs.f_bfree); 
  PushInt(fs.f_bavail); 
  PushInt(fs.f_files); 
  PushInt(fs.f_ffree); 
  PushInt(fs.f_bsize); 
  PushInt(fs.f_namelen); 
}
Example #10
0
void
prim_clear_error(PRIM_PROTOTYPE)
{
	int loop;

	CHECKOP(1);
	oper1 = POP();
	if (oper1->type != PROG_STRING && oper1->type != PROG_INTEGER)
		abort_interp("Invalid argument type. (1)");
	if (!err_init)
		init_err_val();
	if (oper1->type == PROG_INTEGER) {
		if ((oper1->data.number < 0) || (oper1->data.number >= ERROR_NUM)) {
			result = 0;
		} else {
			fr->error.is_flags = fr->error.is_flags & (~err_bits[oper1->data.number].is_flags);
			result = 1;
		}
	} else {
		if (!oper1->data.string) {
			result = 0;
		} else {
			loop = 0;
			result = strlen(oper1->data.string->data);
			for (loop = 0; loop < result; loop++)
				buf[loop] = toupper(oper1->data.string->data[loop]);
			result = 0;
			loop = 0;
			while (loop < ERROR_NUM) {
				if (!strcmp(buf, err_defs[loop].error_name)) {
					result = 1;
					fr->error.is_flags = fr->error.is_flags & (~err_bits[loop].is_flags);
					break;
				} else {
					loop++;
				}
			}
		}
	}
	CLEAR(oper1);
	PushInt(result);
}
Example #11
0
static ssl_value MechNum( unsigned select, ssl_value parm )
{
    switch( select ) {
    case 0:
        Num = SSL2INT( parm );
        break;
    case 1:
        Num += SSL2INT( parm );
        break;
    case 2:
        PushInt( Num );
        break;
    case 3:
        /* need to check that top stack entry is an integer value here? */
        Num = I32FetchTrunc( ExprSP->v.sint );
        PopEntry();
        break;
    }
    return( 0 );
}
Example #12
0
static unsigned MechNum( unsigned select, unsigned parm )
{
    switch( select ) {
    case 0:
        Num = parm;
        break;
    case 1:
        Num += parm;
        break;
    case 2:
        PushInt( Num );
        break;
    case 3:
        /* need to check that top stack entry is an integer value here? */
        Num = U32FetchTrunc( ExprSP->v.uint );
        PopEntry();
        break;
    }
    return( 0 );
}
Example #13
0
void
prim_descr_setuser(PRIM_PROTOTYPE)
{
    char *ptr;

    CHECKOP(3);
    oper3 = POP();
    oper2 = POP();
    oper1 = POP();

    if (mlev < (tp_compatible_muf ? LMAGE : LARCH))
	abort_interp(tp_compatible_muf ? "Mage prim" : "Arch prim");
    if (oper1->type != PROG_INTEGER)
	abort_interp("Integer descriptor number expected (1)");
    if (oper2->type != PROG_OBJECT)
	abort_interp("Player dbref expected (2)");
    ref = oper2->data.objref;
    if (ref != NOTHING && !valid_player(oper2))
	abort_interp("Player dbref expected (2)");
    if (oper3->type != PROG_STRING)
	abort_interp("Password string expected");
    ptr = oper3->data.string? oper3->data.string->data : "";
    if ((ref != NOTHING) && DBFETCH(ref)->sp.player.password &&
	(*DBFETCH(ref)->sp.player.password) &&
	strcmp(ptr, DBFETCH(ref)->sp.player.password)
    )	abort_interp("Incorrect password");

    if (ref != NOTHING) {
	log_status("SUID: %d %s to %s(%d)\n",
		oper1->data.number, unparse_object(MAN, player), NAME(ref), ref);
    }
    tmp = oper1->data.number;

    CLEAR(oper1);
    CLEAR(oper2);
    CLEAR(oper3);

    result = pset_user(tmp, ref);

    PushInt(result);
}
Example #14
0
void 
prim_kill(PRIM_PROTOTYPE)
{
    /* i -- i */
    CHECKOP(1);
    oper1 = POP();
    if (oper1->type != PROG_INTEGER)
	abort_interp("Non-integer argument (1)");
    if (oper1->data.number == fr->pid) {
	do_abort_silent();
    } else {
	if (mlev < LMAGE) {
	    if (!control_process(ProgUID, oper1->data.number)) {
		abort_interp(tp_noperm_mesg);
            }
        }
        result = dequeue_process(oper1->data.number);
    }
    CLEAR(oper1);
    PushInt(result);
}
Example #15
0
void
prim_lreverse(PRIM_PROTOTYPE)
{
    CHECKOP(1);
    oper1 = POP();
    if (oper1->type != PROG_INTEGER)
	abort_interp("Invalid argument type.");
    tmp = oper1->data.number;	/* Depth on stack */
    if (tmp < 0)
	abort_interp("Argument must be positive.");
    EXPECT_WRITE_STACK(tmp);
    if (tmp > 0) {
	for (int i = 0; i < (tmp / 2); i++) {
	    temp2 = arg[*top - (tmp - i)];
	    arg[*top - (tmp - i)] = arg[*top - (i + 1)];
	    arg[*top - (i + 1)] = temp2;
	}
    }
    CLEAR(oper1);
    PushInt(tmp);
}
Example #16
0
void prim_fappend(PRIM_PROTOTYPE)
{
  FILE *fh;
  char *filename;
  char *writestring;
  CHECKOP(2);
  oper1 = POP();
  oper2 = POP();
  if (getuid() == 0 ) 
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if(oper1->type != PROG_STRING) abort_interp("Argument 1 is not a string.");
  if(!oper1->data.string) abort_interp("Argument 1 is a null string.");
  if(oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string.");
  if(!oper2->data.string) abort_interp("Arguement 2 is a null string.");
  filename = oper1->data.string->data;
  writestring = oper2->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif
  fh = fopen(filename, "a");
  if (fh == NULL) { result = 0; } else {
    fputs(writestring, fh);
    fclose(fh);
    result = 1;
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s FAPPEND: %s \n", program, unparse_object(player, player), oper1->data.string->data); 
  }
  CLEAR(oper1);
  CLEAR(oper2);
  PushInt(result);
}
Example #17
0
void
prim_getpropval(PRIM_PROTOTYPE)
{
	CHECKOP(2);
	oper1 = POP();
	oper2 = POP();
	if (oper1->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper1->data.string)
		abort_interp("Empty string argument (2)");
	if (!valid_object(oper2))
		abort_interp("Non-object argument (1)");
	CHECKREMOTE(oper2->data.objref);

	if (!prop_read_perms(ProgUID, oper2->data.objref, oper1->data.string->data, mlev))
		abort_interp("Permission denied.");

	{
		char type[BUFFER_LEN];
		int len = oper1->data.string->length;

		strcpyn(type, sizeof(type), oper1->data.string->data);
		while (len-- > 0 && type[len] == PROPDIR_DELIMITER) {
			type[len] = '\0';
		}
		result = get_property_value(oper2->data.objref, type);

#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) GETPROPVAL: o=%d n=\"%s\" v=%d",
				 program, pc->line, oper2->data.objref, type, result);
#endif

		/* if (Typeof(oper2->data.objref) != TYPE_PLAYER)
		   ts_lastuseobject(oper2->data.objref); */
	}
	CLEAR(oper1);
	CLEAR(oper2);
	PushInt(result);
}
Example #18
0
void
prim_ldup(PRIM_PROTOTYPE)
{
    int i;

    CHECKOP(1);
    oper1 = POP();
    if (oper1->type != PROG_INTEGER)
        abort_interp("Operand is not an integer.");
    result = oper1->data.number;
    if (result < 0)
        abort_interp("Operand is negative.");
    CLEAR(oper1);
    PushInt(result);
    result++;
    CHECKOP(result);
    nargs = 0;
    CHECKOFLOW(result);
    for (i = result; i > 0; i--) {
        copyinst(&arg[*top - result], &arg[*top]);
        (*top)++;
    }
}
Example #19
0
void 
prim_queue(PRIM_PROTOTYPE)
{
    dbref temproom;

    /* int dbref string -- */
    CHECKOP(3);
    oper1 = POP();
    oper2 = POP();
    oper3 = POP();
    if (mlev < LM3)
	abort_interp("M3 prim");
    if (oper3->type != PROG_INTEGER)
	abort_interp("Non-integer argument (1)");
    if (oper2->type != PROG_OBJECT)
	abort_interp("Argument must be a dbref (2)");
    if (!valid_object(oper2))
	abort_interp("Invalid dbref (2)");
    if (Typeof(oper2->data.objref) != TYPE_PROGRAM)
	abort_interp("Object must be a program (2)");
    if (oper1->type != PROG_STRING)
	abort_interp("Non-string argument (3)");

    if ((oper4 = fr->variables + 1)->type != PROG_OBJECT)
	temproom = DBFETCH(player)->location;
    else
	temproom = oper4->data.objref;

    result = add_muf_delayq_event(oper3->data.number, fr->descr, player, temproom,
		    NOTHING, oper2->data.objref, DoNullInd(oper1->data.string),
		     "Queued Event.", 0);

    CLEAR(oper1);
    CLEAR(oper2);
    CLEAR(oper3);
    PushInt(result);
}
Example #20
0
void 
prim_testlock(PRIM_PROTOTYPE)
{
    /* d d - i */
    CHECKOP(2);
    oper1 = POP();		/* boolexp lock */
    oper2 = POP();		/* player dbref */
    if (fr->level > 8)
	abort_interp("Interp call loops not allowed");
    if (!valid_object(oper2))
	abort_interp("Invalid argument (1).");
    if (Typeof(oper2->data.objref) != TYPE_PLAYER &&
        Typeof(oper2->data.objref) != TYPE_THING )
    {
	abort_interp("Invalid object type (1).");
    }
    CHECKREMOTE(oper2->data.objref);
    if (oper1->type != PROG_LOCK)
	abort_interp("Invalid argument (2)");
    result = eval_boolexp(fr->descr, oper2->data.objref, oper1->data.lock, player);
    CLEAR(oper1);
    CLEAR(oper2);
    PushInt(result);
}
Example #21
0
static ssl_value MechPush_n_Pop( unsigned select, ssl_value parm )
{
    location_list           ll;
    dig_type_info           ti;
    ssl_value               result;
    static const unsigned   TypeTbl[] = {
        TI_CREATE( TK_VOID,     TM_NONE,         0 ),
        TI_CREATE( TK_INTEGER,  TM_UNSIGNED,     1 ),
        TI_CREATE( TK_INTEGER,  TM_SIGNED,       1 ),
        TI_CREATE( TK_INTEGER,  TM_UNSIGNED,     2 ),
        TI_CREATE( TK_INTEGER,  TM_SIGNED,       2 ),
        TI_CREATE( TK_INTEGER,  TM_UNSIGNED,     4 ),
        TI_CREATE( TK_INTEGER,  TM_SIGNED,       4 ),
        TI_CREATE( TK_REAL,     TM_NONE,         4 ),
        TI_CREATE( TK_REAL,     TM_NONE,         8 ),
        TI_CREATE( TK_COMPLEX,  TM_NONE,         8 ),
        TI_CREATE( TK_COMPLEX,  TM_NONE,        16 ),
    };

    result = 0;
    switch( select ) {
    case 0:
        PushInt( SSL2INT( parm ) );
        break;
    case 1:
        PushAddr( GetDotAddr() );
        break;
    case 2:
        ParseRegSet( true, &ll, &ti );
        if( ti.size != 0 ) {
            if( ti.kind == TK_NONE )
                Error( ERR_NONE, LIT_ENG( ERR_ILL_TYPE ) );
            PushLocation( &ll, &ti );
            result = true;
        }
        break;
    case 3:
        if( CurrToken == T_INT_NUM ) {
            PushNum64( IntNumVal() );
            Scan();
            result = true;
        } else if( CurrToken == T_REAL_NUM ) {
            PushRealNum( RealNumVal() );
            Scan();
            result = true;
        }
        break;
    case 4:
        BasicType( TypeTbl[parm] );
        break;
    case 5:
        DupStack();
        break;
    case 6:
        PopEntry();
        break;
    case 7:
        PushString();
        break;
    case 8:
        /* here because old debuggers will always return false */
        if( (parm & SSL_VERSION_MAJOR_MASK) != SSL_VERSION_MAJOR_CURR ) {
            break;
        }
#if SSL_VERSION_MINOR_CURR != 0
        if( (parm & SSL_VERSION_MINOR_MASK) > SS_MINOR_VERSION_CURR ) {
            break;
        }
#endif
        result = true;
        break;
    case 9:
        BasicType( parm );
        break;
    }
    return( result );
}
Example #22
0
static unsigned MechPush_n_Pop( unsigned select, unsigned parm )
{
    location_list       ll;
    dip_type_info       ti;
    unsigned            result;
    const static unsigned       TypeTbl[] = {
        TI_CREATE( TK_VOID,     TM_NONE,         0 ),
        TI_CREATE( TK_INTEGER,  TM_UNSIGNED,     1 ),
        TI_CREATE( TK_INTEGER,  TM_SIGNED,       1 ),
        TI_CREATE( TK_INTEGER,  TM_UNSIGNED,     2 ),
        TI_CREATE( TK_INTEGER,  TM_SIGNED,       2 ),
        TI_CREATE( TK_INTEGER,  TM_UNSIGNED,     4 ),
        TI_CREATE( TK_INTEGER,  TM_SIGNED,       4 ),
        TI_CREATE( TK_REAL,     TM_NONE,         4 ),
        TI_CREATE( TK_REAL,     TM_NONE,         8 ),
        TI_CREATE( TK_COMPLEX,  TM_NONE,         8 ),
        TI_CREATE( TK_COMPLEX,  TM_NONE,        16 ),
    };

    result = FALSE;
    switch( select ) {
    case 0:
        PushInt( parm );
        break;
    case 1:
        PushAddr( GetDotAddr() );
        break;
    case 2:
        ParseRegSet( TRUE, &ll, &ti );
        if( ti.size != 0 ) {
            if( ti.kind == TK_NONE ) Error( ERR_NONE, LIT( ERR_ILL_TYPE ) );
            PushLocation( &ll, &ti );
            result = TRUE;
        }
        break;
    case 3:
        if( CurrToken == T_INT_NUM ) {
            PushNum64( IntNumVal() );
            Scan();
            result = TRUE;
        } else if( CurrToken == T_REAL_NUM ) {
            PushRealNum( RealNumVal() );
            Scan();
            result = TRUE;
        } else {
            result = FALSE;
        }
        break;
    case 4:
        BasicType( TypeTbl[ parm ] );
        break;
    case 5:
        DupStack();
        break;
    case 6:
        PopEntry();
        break;
    case 7:
        PushString();
        break;
    case 8:
        /* here because old debuggers will always return FALSE */
        switch( parm & SSL_VERSION_MAJOR_MASK ) {
        case SSL_VERSION_MAJOR_CURR:
            break;
        default:
            return( FALSE );
        }
        #if SSL_VERSION_MINOR_CURR != 0
            if( (parm & SSL_VERSION_MINOR_MASK) > SS_MINOR_VERSION_CURR ) {
                return( FALSE );
            }
        #endif
        result = TRUE;
        break;
    case 9:
        BasicType( parm );
        break;
    }
    return( result );
}
void ParseScript()
{
	char str[512];
	
	while(!feof(infile))
	{	
		memset(str,'\0',512);
		fgets(str,512,infile);
		
		switch(GetType(str))
		{
			case 1:
			{
				int opcode = GetID(str);
				
				if(opcode!=-1)
				{
					Push(&bytestack,opcode,1);
					PushArgs(&bytestack,str,opcode,4);
				}
			}
			break;
			
			case 2:
			{
				char *name = GetFuncName(str);
				int opcode = GetOpcode(name);
				
				Push(&bytestack,opcode,1);
				PushArgs(&bytestack,str,opcode,strlen(name));
				
				free(name);
			}
			break;
			
			case 3:
			{
				int id = GetID(str);
				
				if(id!=-1)
				{
					PushInt(&labelstack,bytestack.size,id);
					scrhead.labels.size++;
				}
				else
				{
					printf("Problem parsing label: %s",str);
					exit(1);
				}
			}
			break;
				
			case 4:
			{
				int id = GetID(str);
				
				if(id!=-1)
				{
					//Push(&markerstack,id,4);
					markerstack[id] = bytestack.size;
					scrhead.markers.size = 100;
				}
				else
				{
					printf("Problem parsing marker: %s",str);
					exit(1);
				}
			}
			break;
				
			case 5:
			{
				FILE *textfile = NULL;
				
				while(str[strlen(str)-1]=='\r' || str[strlen(str)-1]=='\n')
					str[strlen(str)-1] = '\0';
					
				textfile = fopen(str+9,"rb");
				
				if(!textfile)
				{
					printf("Could not open %s\n",str+9);
					exit(1);
				}
				
				ParseText(textfile);
				fclose(textfile);
			}
			break;
			
			case 6:
			{
				int t = 0;
				sscanf(str+1,"%x",&t);
				
				if(scrhead.unk12.size==0)
					unk12stack = (int*)calloc(1,sizeof(int));
				else
					unk12stack = (int*)realloc(unk12stack,(scrhead.unk12.size+1)*sizeof(int));
				
				unk12stack[scrhead.unk12.size++] = t;
			}
			break;
			
			case 7:
			{
				int t = 0;
				sscanf(str+1,"%x",&t);
				
				if(scrhead.unk13.size==0)
					unk13stack = (int*)calloc(1,sizeof(int));
				else
					unk13stack = (int*)realloc(unk13stack,(scrhead.unk13.size+1)*sizeof(int));
					
				unk13stack[scrhead.unk13.size++] = t;
			}
			break;
		
			default:
				break;
		}
	}
}
Example #24
0
 int Push(const void* d, size_t length){
     PushHead<std::vector<byte> >(data);
     PushInt(data, length );
     PushMem(data, d, length);
 }
void SgIncrementalStack::PushPtrEvent(int type, void* ptr)
{
    PushPtr(ptr);
    PushInt(type);
}
Example #26
0
void 
prim_fork(PRIM_PROTOTYPE)
{
    int     i, j;
    struct frame *tmpfr;

    CHECKOP(0);
    CHECKOFLOW(1);

    if (mlev < LMAGE)
	abort_interp("Mage prim");

    fr->pc = pc;

    tmpfr = (struct frame *) calloc(1, sizeof(struct frame));

    tmpfr->system.top = fr->system.top;
    for (i = 0; i < fr->system.top; i++)
	tmpfr->system.st[i] = fr->system.st[i];

    tmpfr->argument.top = fr->argument.top;
    for (i = 0; i < fr->argument.top; i++)
	copyinst(&fr->argument.st[i], &tmpfr->argument.st[i]);

    tmpfr->caller.top = fr->caller.top;
    for (i = 0; i <= fr->caller.top; i++) {
	tmpfr->caller.st[i] = fr->caller.st[i];
	if (i > 0) DBFETCH(fr->caller.st[i])->sp.program.instances++;
    }

    for (i = 0; i < MAX_VAR; i++)
	copyinst(&fr->variables[i], &tmpfr->variables[i]);

    tmpfr->varset.top = fr->varset.top;
    for (i = fr->varset.top; i >= 0; i--) {
	tmpfr->varset.st[i] = (vars *) calloc(1, sizeof(vars));
	for (j = 0; j < MAX_VAR; j++)
	    copyinst(&((*fr->varset.st[i])[j]), &((*tmpfr->varset.st[i])[j]));
    }

    tmpfr->pc = pc;
    tmpfr->pc++;
    tmpfr->level = fr->level;
    tmpfr->already_created = fr->already_created;
    tmpfr->trig = fr->trig;

    tmpfr->brkpt.debugging = 0;
    tmpfr->brkpt.count = 0;
    tmpfr->brkpt.showstack = 0;
    tmpfr->brkpt.isread = 0;
    tmpfr->brkpt.bypass = 0;
    tmpfr->brkpt.lastcmd = NULL;

    tmpfr->pid = top_pid++;
    tmpfr->multitask = BACKGROUND;
    tmpfr->writeonly = 1;
    tmpfr->started = time(NULL);
    tmpfr->instcnt = 0;

    /* child process gets a 0 returned on the stack */
    result = 0;
    push(tmpfr->argument.st, &(tmpfr->argument.top),
	 PROG_INTEGER, MIPSCAST & result);

    result = add_muf_delay_event(0, fr->descr, player, NOTHING, NOTHING, program,
				tmpfr, "BACKGROUND");

    /* parent process gets the child's pid returned on the stack */
    if (!result)
	result = -1;
    PushInt(result);
}
Example #27
0
void
prim_fork(PRIM_PROTOTYPE)
{
    struct frame *tmpfr;

    CHECKOP(0);
    CHECKOFLOW(1);

    if (mlev < 3)
	abort_interp("Permission Denied.");

    fr->pc = pc;

    tmpfr = calloc(1, sizeof(struct frame));
    tmpfr->next = NULL;

    array_init_active_list(&tmpfr->array_active_list);
    stk_array_active_list = &tmpfr->array_active_list;

    tmpfr->system.top = fr->system.top;
    for (int i = 0; i < fr->system.top; i++)
	tmpfr->system.st[i] = fr->system.st[i];

    tmpfr->argument.top = fr->argument.top;
    for (int i = 0; i < fr->argument.top; i++)
	deep_copyinst(&fr->argument.st[i], &tmpfr->argument.st[i], -1);

    tmpfr->caller.top = fr->caller.top;
    for (int i = 0; i <= fr->caller.top; i++) {
	tmpfr->caller.st[i] = fr->caller.st[i];
	if (i > 0)
	    PROGRAM_INC_INSTANCES(fr->caller.st[i]);
    }

    tmpfr->trys.top = fr->trys.top;
    tmpfr->trys.st = copy_trys(fr->trys.st);

    tmpfr->fors.top = fr->fors.top;
    tmpfr->fors.st = copy_fors(fr->fors.st);

    for (int i = 0; i < MAX_VAR; i++)
	deep_copyinst(&fr->variables[i], &tmpfr->variables[i], -1);

    localvar_dupall(tmpfr, fr);
    scopedvar_dupall(tmpfr, fr);

    tmpfr->error.is_flags = fr->error.is_flags;
    if (fr->rndbuf) {
	tmpfr->rndbuf = malloc(sizeof(unsigned long) * 4);

	if (tmpfr->rndbuf) {
	    memcpy(tmpfr->rndbuf, fr->rndbuf, 16);
	}
    } else {
	tmpfr->rndbuf = NULL;
    }
    tmpfr->pc = pc;
    tmpfr->pc++;
    tmpfr->level = fr->level;
    tmpfr->already_created = fr->already_created;
    tmpfr->trig = fr->trig;

    tmpfr->brkpt.debugging = 0;
    tmpfr->brkpt.bypass = 0;
    tmpfr->brkpt.isread = 0;
    tmpfr->brkpt.showstack = 0;
    tmpfr->brkpt.lastline = 0;
    tmpfr->brkpt.lastpc = 0;
    tmpfr->brkpt.lastlisted = 0;
    tmpfr->brkpt.lastcmd = NULL;
    tmpfr->brkpt.breaknum = -1;

    tmpfr->brkpt.lastproglisted = NOTHING;
    tmpfr->brkpt.proglines = NULL;

    tmpfr->brkpt.count = 1;
    tmpfr->brkpt.temp[0] = 1;
    tmpfr->brkpt.level[0] = -1;
    tmpfr->brkpt.line[0] = -1;
    tmpfr->brkpt.linecount[0] = -2;
    tmpfr->brkpt.pc[0] = NULL;
    tmpfr->brkpt.pccount[0] = -2;
    tmpfr->brkpt.prog[0] = program;

    tmpfr->proftime.tv_sec = 0;
    tmpfr->proftime.tv_usec = 0;
    tmpfr->totaltime.tv_sec = 0;
    tmpfr->totaltime.tv_usec = 0;


    tmpfr->pid = top_pid++;
    tmpfr->multitask = BACKGROUND;
    tmpfr->been_background = 1;
    tmpfr->writeonly = 1;
    tmpfr->started = time(NULL);
    tmpfr->instcnt = 0;
    tmpfr->skip_declare = fr->skip_declare;
    tmpfr->wantsblanks = fr->wantsblanks;
    tmpfr->perms = fr->perms;
    tmpfr->descr = fr->descr;
    tmpfr->supplicant = fr->supplicant;
    tmpfr->events = NULL;
    tmpfr->waiters = NULL;
    tmpfr->waitees = NULL;
    tmpfr->dlogids = NULL;
    tmpfr->timercount = 0;

    /* child process gets a 0 returned on the stack */
    result = 0;
    push(tmpfr->argument.st, &(tmpfr->argument.top), PROG_INTEGER, MIPSCAST & result);

    result = add_muf_delay_event(0, fr->descr, player, NOTHING, NOTHING, program,
				 tmpfr, "BACKGROUND");

    stk_array_active_list = &fr->array_active_list;

    /* parent process gets the child's pid returned on the stack */
    if (!result)
	result = -1;
    PushInt(result);
}
void SgIncrementalStack::StartMoveInfo()
{
    PushInt(SG_NEXTMOVE);
}
Example #29
0
void
prim_force_level(PRIM_PROTOTYPE)
{
    CHECKOFLOW(1);
    PushInt(force_level);
}
Example #30
0
void
prim_ext_name_okp(PRIM_PROTOTYPE)
{
    /* These are function pointers */
    int (*ok1) (const char *) = NULL;
    int (*ok2) (const char *) = NULL;

    CHECKOP(2);
    oper2 = POP();
    oper1 = POP();

    if (oper1->type != PROG_STRING)
	abort_interp("Object name string expected (1).");
    if (!oper1->data.string)
	abort_interp("Cannot be an empty string (1).");

    if (oper2->type == PROG_STRING) {
	if (!oper2->data.string)
	    abort_interp("Cannot be an empty string (2).");
	strcpyn(buf, sizeof(buf), oper2->data.string->data);
	for (ref = 0; buf[ref]; ref++)
	    buf[ref] = tolower(buf[ref]);
	if (!strcmp(buf, "e") || !strcmp(buf, "exit")) {
	    ok1 = ok_ascii_other;
	    ok2 = ok_name;
	} else if (!strcmp(buf, "r") || !strcmp(buf, "room")) {
	    ok1 = ok_ascii_other;
	    ok2 = ok_name;
	} else if (!strcmp(buf, "t") || !strcmp(buf, "thing")) {
	    ok1 = ok_ascii_thing;
	    ok2 = ok_name;
	} else if (!strcmp(buf, "p") || !strcmp(buf, "player")) {
	    ok1 = ok_player_name;
	} else if (!strcmp(buf, "f") || !strcmp(buf, "muf")
		   || !strcmp(buf, "program")) {
	    ok1 = ok_ascii_other;
	    ok2 = ok_name;
	} else {
	    abort_interp("String must be a valid object type (2).");
	}
    } else if (oper2->type == PROG_OBJECT) {
	if (!valid_object(oper2))
	    abort_interp("Invalid argument (2).");
	switch (Typeof(oper2->data.objref)) {
	case TYPE_EXIT:
	case TYPE_ROOM:
	case TYPE_PROGRAM:
	    ok1 = ok_ascii_other;
	    ok2 = ok_name;
	    break;
	case TYPE_THING:
	    ok1 = ok_ascii_thing;
	    ok2 = ok_name;
	    break;
	case TYPE_PLAYER:
	    ok1 = ok_player_name;
	    break;
	}

    } else {
	abort_interp("Dbref or object type name expected (2).");
    }

    result = ok1 && ok1(oper1->data.string->data);
    if (ok2 && result)
	result = ok2(oper1->data.string->data);
    CLEAR(oper1);
    CLEAR(oper2);
    PushInt(result);
}