⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bwb_cmd.c

📁 这是一个简易的basic语言解释器, 可供我们学习和改进.
💻 C
📖 第 1 页 / 共 4 页
字号:
	SYNTAX:		DO NUM***************************************************************/#if ANSI_Cstruct bwb_line *bwb_donum( struct bwb_line *l )#elsestruct bwb_line *bwb_donum( l )   struct bwb_line *l;#endif   {   struct bwb_line *current;   register int lnumber;   lnumber = 10;   for ( current = bwb_start.next; current != &bwb_end; current = current->next )      {      current->number = lnumber;      current->xnum = TRUE;      lnumber += 10;      if ( lnumber >= MAXLINENO )         {         return bwb_zline( l );         }      }   return bwb_zline( l );   }/***************************************************************        FUNCTION:       bwb_dounnum()	DESCRIPTION:    This function implements the BASIC DO			UNNUM command, removing all line numbers			from the program in memory.	SYNTAX:		DO UNNUM***************************************************************/#if ANSI_Cstruct bwb_line *bwb_dounnum( struct bwb_line *l )#elsestruct bwb_line *bwb_dounnum( l )   struct bwb_line *l;#endif   {   struct bwb_line *current;   for ( current = bwb_start.next; current != &bwb_end; current = current->next )      {      current->number = 0;      current->xnum = FALSE;      }   return bwb_zline( l );   }#endif				/* INTERACTIVE */#if COMMON_CMDS/***************************************************************        FUNCTION:       bwb_chain()        DESCRIPTION:	This C function implements the BASIC			CHAIN command.   	SYNTAX:		CHAIN file-name***************************************************************/#if ANSI_Cstruct bwb_line *bwb_chain( struct bwb_line *l )#elsestruct bwb_line *bwb_chain( l )   struct bwb_line *l;#endif   {   /* deallocate all variables except common ones */   var_delcvars();   /* remove old program from memory */   bwb_xnew( l );   /* call xload function to load new program in memory */   bwb_xload( l );   /* reset all stack counters */   CURTASK exsc = -1;   CURTASK expsc = 0;   CURTASK xtxtsc = 0;   /* run the program */   return bwb_run( &CURTASK bwb_start  );   }/***************************************************************        FUNCTION:       bwb_merge()        DESCRIPTION:	This C function implements the BASIC			MERGE command, merging command lines from			a specified file into the program in memory			without deleting the lines already in memory.   	SYNTAX:		MERGE file-name***************************************************************/#if ANSI_Cstruct bwb_line *bwb_merge( struct bwb_line *l )#elsestruct bwb_line *bwb_merge( l )   struct bwb_line *l;#endif   {   /* call xload function to merge program in memory */   bwb_xload( l );   return bwb_zline( l );   }/***************************************************************        FUNCTION:       bwb_onerror()        DESCRIPTION:	This C function implements the BASIC        		ON ERROR GOSUB command.   	SYNTAX:		ON ERROR GOSUB line | label***************************************************************/#if ANSI_Cstruct bwb_line *bwb_onerror( struct bwb_line *l )#elsestruct bwb_line *bwb_onerror( l )   struct bwb_line *l;#endif   {   char tbuf[ MAXSTRINGSIZE + 1 ];#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in bwb_onerror(): entered function" );   bwb_debug( bwb_ebuf );#endif   /* get the GOSUB STATEMENT */   adv_element( l->buffer, &( l->position ), tbuf );   /* check for GOSUB statement */   bwb_strtoupper( tbuf );   if ( strcmp( tbuf, CMD_GOSUB ) != 0 )      {#if PROG_ERRORS      sprintf( bwb_ebuf, "in bwb_onerror(): GOSUB statement missing" );      bwb_error( bwb_ebuf );#else      bwb_error( err_syntax );#endif      return bwb_zline( l );      }   /* get the GOSUB line */   adv_element( l->buffer, &( l->position ), err_gosubl );   return bwb_zline( l );   }/***************************************************************        FUNCTION:       bwb_tron()	DESCRIPTION:    This function implements the BASIC TRON			command, turning the trace mechanism on.	SYNTAX:		TRON***************************************************************/#if ANSI_Cstruct bwb_line *bwb_tron( struct bwb_line *l )#elsestruct bwb_line *bwb_tron( l )   struct bwb_line *l;#endif   {   bwb_trace = TRUE;   prn_xprintf( stdout, "Trace is ON\n" );   return bwb_zline( l );   }/***************************************************************        FUNCTION:       bwb_troff()	DESCRIPTION:    This function implements the BASIC TROFF			command, turning the trace mechanism off.	SYNTAX:		TROFF***************************************************************/#if ANSI_Cstruct bwb_line *bwb_troff( struct bwb_line *l )#elsestruct bwb_line *bwb_troff( l )   struct bwb_line *l;#endif   {   bwb_trace = FALSE;   prn_xprintf( stdout, "Trace is OFF\n" );   return bwb_zline( l );   }#endif				/* COMMON_CMDS *//***************************************************************        FUNCTION:       bwb_randomize()	DESCRIPTION:    This function implements the BASIC			RANDOMIZE command, seeding the pseudo-			random number generator.	SYNTAX:		RANDOMIZE number***************************************************************/#if ANSI_Cstruct bwb_line *bwb_randomize( struct bwb_line *l )#elsestruct bwb_line *bwb_randomize( l )   struct bwb_line *l;#endif   {   register unsigned n;   struct exp_ese *e;   /* Check for argument */   adv_ws( l->buffer, &( l->position ) );   switch( l->buffer[ l->position ] )      {      case '\0':      case '\n':      case '\r':#if MULTISEG_LINES      case ':':#endif         n = (unsigned) 1;         break;      default:         n = (unsigned) 0;         break;      }   /* get the argument in tbuf */   if ( n == (unsigned) 0 )      {      e = bwb_exp( l->buffer, FALSE, &( l->position ) );      n = (unsigned) exp_getnval( e );      }#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in bwb_randomize(): argument is <%d>", n );   bwb_debug( bwb_ebuf );#endif   srand( n );   return bwb_zline( l );   }/***************************************************************        FUNCTION:       bwb_xnew()        DESCRIPTION:	Clears the program in memory, but does not			deallocate all variables.***************************************************************/#if ANSI_Cstruct bwb_line *bwb_xnew( struct bwb_line *l )#elsestruct bwb_line *bwb_xnew( l )   struct bwb_line *l;#endif   {   struct bwb_line *current, *previous;   int wait;   wait = TRUE;   for ( current = CURTASK bwb_start.next; current != &CURTASK bwb_end; current = current->next )      {      if ( wait != TRUE )         {         /* Revised to FREE pass-thru call by JBV */         FREE( previous, "bwb_xnew" );         previous = NULL; /* JBV */         }      wait = FALSE;      previous = current;      }   CURTASK bwb_start.next = &CURTASK bwb_end;   return bwb_zline( l );   }#if UNIX_CMDS/***************************************************************        FUNCTION:       bwb_environ()        DESCRIPTION:	This C function implements the BASIC			ENVIRON command, assigning a string			value to an environment variable.	SYNTAX:		ENVIRON variable-string$ = string$***************************************************************/#if ANSI_Cstruct bwb_line *bwb_environ( struct bwb_line *l )#elsestruct bwb_line *bwb_environ( l )   struct bwb_line *l;#endif   {   static char tbuf[ MAXSTRINGSIZE + 1 ];   char tmp[ MAXSTRINGSIZE + 1 ];   register int i;   int pos;   struct exp_ese *e;   /* find the equals sign */   for ( i = 0; ( l->buffer[ l->position ] != '=' ) && ( l->buffer[ l->position ] != '\0' ); ++i )      {      tbuf[ i ] = l->buffer[ l->position ];      tbuf[ i + 1 ] = '\0';      ++( l->position );      }#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in bwb_environ(): variable string is <%s>", tbuf );   bwb_debug( bwb_ebuf );#endif   /* get the value string to be assigned */   pos = 0;   e = bwb_exp( tbuf, FALSE, &pos );   str_btoc( tbuf, exp_getsval( e ) );#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in bwb_environ(): variable string resolves to <%s>", tbuf );   bwb_debug( bwb_ebuf );#endif   /* find the equals sign */   adv_ws( l->buffer, &( l->position ) );   if ( l->buffer[ l->position ] != '=' )      {#if PROG_ERRORS      sprintf( bwb_ebuf, "in bwb_environ(): failed to find equal sign" );      bwb_error( bwb_ebuf );#else      bwb_error( err_syntax );#endif      return bwb_zline( l );      }   ++( l->position );   /* get the value string to be assigned */   e = bwb_exp( l->buffer, FALSE, &( l->position ));   str_btoc( tmp, exp_getsval( e ) );#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in bwb_environ(): value string resolves to <%s>", tmp );   bwb_debug( bwb_ebuf );#endif   /* construct string */   strcat( tbuf, "=" );   strcat( tbuf, tmp );#if INTENSIVE_DEBUG   sprintf( bwb_ebuf, "in bwb_environ(): assignment string is <%s>", tbuf );   bwb_debug( bwb_ebuf );#endif   /* now assign value to variable */   if ( putenv( tbuf ) == -1 )      {      bwb_error( err_opsys );      return bwb_zline( l );      }   /* return */   return bwb_zline( l );   }#endif					/* UNIX_CMDS *//***************************************************************        FUNCTION:       bwb_cmds()	DESCRIPTION:    This function implements a CMD command,			which lists all commands implemented.			It is not part of a BASIC specification,			but is used for debugging bwBASIC.	SYNTAX:		CMDS***************************************************************/#if PERMANENT_DEBUG#if ANSI_Cstruct bwb_line *bwb_cmds( struct bwb_line *l )#elsestruct bwb_line *bwb_cmds( l )   struct bwb_line *l;#endif   {   register int n;   char tbuf[ MAXSTRINGSIZE + 1 ];   prn_xprintf( stdout, "BWBASIC COMMANDS AVAILABLE: \n" );   /* run through the command table and print comand names */   for ( n = 0; n < COMMANDS; ++n )      {      sprintf( tbuf, "%s \n", bwb_cmdtable[ n ].name );      prn_xprintf( stdout, tbuf );      }   return bwb_zline( l );   }#endif/***************************************************************	FUNCTION:       getcmdnum()	DESCRIPTION:    This function returns the number associated			with a specified command (cmdstr) in the			command table.***************************************************************/#if ANSI_Cintgetcmdnum( char *cmdstr )#elseintgetcmdnum( cmdstr )   char *cmdstr;#endif   {   register int c;   for ( c = 0; c < COMMANDS; ++c )      {      if ( strcmp( bwb_cmdtable[ c ].name, cmdstr ) == 0 )         {         return c;         }      }   return -1;   }/***************************************************************        FUNCTION:       bwb_zline()        DESCRIPTION:	This function is called at the exit from        		Bywater BASIC command functions.  If        		MULTISEG_LINES is TRUE, then it returns        		a pointer to the current line; otherwise it        		sets the position in the next line to zero        		and returns a pointer to the next line.***************************************************************/#if ANSI_Cextern struct bwb_line *bwb_zline( struct bwb_line *l )#elsestruct bwb_line *bwb_zline( l )   struct bwb_line *l;#endif   {#if MULTISEG_LINES   /* l->marked = FALSE; */   return l;#else   l->next->position = 0;   return l->next;#endif   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -