📄 bwb_cmd.c
字号:
#endif bwx_terminate(); return &CURTASK bwb_end; /* to make LINT happy */ }/*************************************************************** FUNCTION: bwb_load() DESCRIPTION: This C function implements the BASIC LOAD command. SYNTAX: LOAD file-name***************************************************************/#if ANSI_Cstruct bwb_line *bwb_load( struct bwb_line *l )#elsestruct bwb_line *bwb_load( l ) struct bwb_line *l;#endif { /* clear current contents */ bwb_new( l ); /* call xload function to load program in memory */ bwb_xload( l ); return bwb_zline( l ); }/*************************************************************** FUNCTION: bwb_xload() DESCRIPTION: This C function loads a BASIC program into memory.***************************************************************/#if ANSI_Cstruct bwb_line *bwb_xload( struct bwb_line *l )#elsestruct bwb_line *bwb_xload( l ) struct bwb_line *l;#endif { FILE *loadfile; struct exp_ese *e; /* JBV */ /* Get an argument for filename */ adv_ws( l->buffer, &( l->position ) ); switch( l->buffer[ l->position ] ) { case '\0': case '\n': case '\r': case ':': bwb_error( err_nofn ); /* Added by JBV (bug found by DD) */ return bwb_zline( l ); default: break; } /* Section added by JBV (bug found by DD) */ e = bwb_exp( l->buffer, FALSE, &( l->position ) ); if ( e->type != STRING ) {#if PROG_ERRORS sprintf( bwb_ebuf, "in bwb_xload(): Missing filespec" ); bwb_error( bwb_ebuf );#else bwb_error( err_syntax );#endif return bwb_zline( l ); } /* This line removed by JBV (no longer required) */ /* bwb_const( l->buffer, CURTASK progfile, &( l->position ) ); */ str_btoc( CURTASK progfile, exp_getsval( e ) ); /* JBV */ if ( ( loadfile = fopen( CURTASK progfile, "r" )) == NULL ) { sprintf( bwb_ebuf, err_openfile, CURTASK progfile ); bwb_error( bwb_ebuf ); return bwb_zline( l ); } bwb_fload( loadfile ); return bwb_zline( l ); }/*************************************************************** FUNCTION: bwb_save() DESCRIPTION: This C function implements the BASIC SAVE command. SYNTAX: SAVE file-name***************************************************************/#if ANSI_Cstruct bwb_line *bwb_save( struct bwb_line *l )#elsestruct bwb_line *bwb_save( l ) struct bwb_line *l;#endif { FILE *outfile; static char filename[ MAXARGSIZE ]; struct exp_ese *e; /* JBV */#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_save(): entered function." ); bwb_debug( bwb_ebuf );#endif /* Get an argument for filename */ adv_ws( l->buffer, &( l->position ) ); switch( l->buffer[ l->position ] ) { case '\0': case '\n': case '\r': case ':': bwb_error( err_nofn ); return bwb_zline( l ); default: break; } /* Section added by JBV (bug found by DD) */ e = bwb_exp( l->buffer, FALSE, &( l->position ) ); if ( e->type != STRING ) {#if PROG_ERRORS sprintf( bwb_ebuf, "in bwb_save(): Missing filespec" ); bwb_error( bwb_ebuf );#else bwb_error( err_syntax );#endif return bwb_zline( l ); } /* This line removed by JBV (no longer required) */ /* bwb_const( l->buffer, filename, &( l->position ) ); */ str_btoc( filename, exp_getsval( e ) ); /* JBV */ if ( ( outfile = fopen( filename, "w" )) == NULL ) { sprintf( bwb_ebuf, err_openfile, filename ); bwb_error( bwb_ebuf ); return bwb_zline( l ); } bwb_xlist( l, outfile ); fclose( outfile ); return bwb_zline( l ); }/*************************************************************** FUNCTION: bwb_list() DESCRIPTION: This C function implements the BASIC LIST command. SYNTAX: LIST line[-line]***************************************************************/#if ANSI_Cstruct bwb_line *bwb_list( struct bwb_line *l )#elsestruct bwb_line *bwb_list( l ) struct bwb_line *l;#endif { bwb_xlist( l, stdout ); return bwb_zline( l ); }/*************************************************************** FUNCTION: bwb_xlist() DESCRIPTION: This C function lists the program in memory to a specified output device.***************************************************************/#if ANSI_Cstruct bwb_line *bwb_xlist( struct bwb_line *l, FILE *file )#elsestruct bwb_line *bwb_xlist( l, file ) struct bwb_line *l; FILE *file;#endif { struct bwb_line *start, *end, *current; int s, e; int f, r; start = CURTASK bwb_start.next; end = &CURTASK bwb_end; r = bwb_numseq( &( l->buffer[ l->position ] ), &s, &e ); /* advance to the end of the segment */#if MULTISEG_LINES adv_eos( l->buffer, &( l->position ));#endif if (( r == FALSE ) || ( s == 0 )) { s = CURTASK bwb_start.next->number; } if ( e == 0 ) { e = s; } if ( r == FALSE ) { for ( current = CURTASK bwb_start.next; current != &CURTASK bwb_end; current = current->next ) { if ( current->next == &CURTASK bwb_end ) { e = current->number; } } }#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_xlist(): LBUFFER sequence is %d-%d", s, e ); bwb_debug( bwb_ebuf );#endif /* abort if either number == (MAXLINENO + 1) which denotes CURTASK bwb_end */ if ( ( s == (MAXLINENO + 1)) || ( e == (MAXLINENO + 1 ) ) ) { return bwb_zline( l ); } /* Now try to find the actual lines in memory */ f = FALSE; for ( current = CURTASK bwb_start.next; current != &CURTASK bwb_end; current = current->next ) { if ( current != l ) { if (( current->number == s ) && ( f == FALSE )) { f = TRUE; start = current;#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_xlist(): start line number is <%d>", s ); bwb_debug( bwb_ebuf );#endif } } } /* check and see if a line number was found */ if ( f == FALSE ) { sprintf( bwb_ebuf, err_lnnotfound, s ); bwb_error( bwb_ebuf ); return bwb_zline( l ); } if ( e >= s ) { for ( current = CURTASK bwb_start.next; current != &CURTASK bwb_end; current = current->next ) { if ( current != l ) { if ( current->number == e ) {#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_xlist(): end line number is <%d>", current->next->number ); bwb_debug( bwb_ebuf );#endif end = current->next; } } } } else { end = start; }#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_xlist(): line sequence is <%d-%d>", start->number, end->number ); bwb_debug( bwb_ebuf );#endif /* previous should now be set to the line previous to the first in the omission list */ /* now go through and list appropriate lines */ if ( start == end ) {#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_xlist(): start == end" ); bwb_debug( bwb_ebuf );#endif xl_line( file, start ); } else { for ( current = start; current != end; current = current->next ) { xl_line( file, current ); } } return bwb_zline( l ); }/*************************************************************** FUNCTION: xl_line() DESCRIPTION: This function lists a single program line to a specified device of file. It is called by bwb_xlist();***************************************************************/#if ANSI_Cstatic intxl_line( FILE *file, struct bwb_line *l )#elsestatic intxl_line( file, l ) FILE *file; struct bwb_line *l;#endif { char tbuf[ MAXSTRINGSIZE + 1 ]; if (( file == stdout ) || ( file == stderr )) { if ( l->xnum == (char) TRUE ) /* Better recast this one (JBV) */ { sprintf( tbuf, "%7d: %s\n", l->number, l->buffer ); } else { sprintf( tbuf, " : %s\n", l->buffer ); } prn_xprintf( file, tbuf ); } else { if ( l->xnum == (char) TRUE ) /* Better recast this one (JBV) */ { fprintf( file, "%d %s\n", l->number, l->buffer ); } else { fprintf( file, "%s\n", l->buffer ); } } return TRUE; }/*************************************************************** FUNCTION: bwb_delete() DESCRIPTION: This C function implements the BASIC DELETE command for interactive programming, deleting a specified program line (or lines) from memory. SYNTAX: DELETE line[-line]***************************************************************/#if ANSI_Cstruct bwb_line *bwb_delete( struct bwb_line *l )#elsestruct bwb_line *bwb_delete( l ) struct bwb_line *l;#endif { struct bwb_line *start, *end, *current, *previous, *p, *next; static int s, e; int f; previous = &CURTASK bwb_start; start = CURTASK bwb_start.next; end = &CURTASK bwb_end; bwb_numseq( &( l->buffer[ l->position ] ), &s, &e );#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_delete(): LBUFFER sequence is %d-%d", s, e ); bwb_debug( bwb_ebuf );#endif /* advance to the end of the segment */#if MULTISEG_LINES adv_eos( l->buffer, &( l->position ));#endif /* Now try to find the actual lines in memory */ previous = p = &CURTASK bwb_start; f = FALSE; for ( current = CURTASK bwb_start.next; current != &CURTASK bwb_end; current = current->next ) { if ( current != l ) { /* Following line revised by JBV */ if (( current->xnum == (char) TRUE ) && ( current->number == s )) { f = TRUE; previous = p; start = current;#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_delete(): start line number is <%d>", s ); bwb_debug( bwb_ebuf );#endif } } p = current; } /* check and see if a line number was found */ if ( f == FALSE ) { sprintf( bwb_ebuf, err_lnnotfound, s ); bwb_error( bwb_ebuf ); return bwb_zline( l ); } if ( e > s ) { for ( current = CURTASK bwb_start.next; current != &CURTASK bwb_end; current = current->next ) { if ( current != l ) { /* Following line revised by JBV */ if (( current->xnum == (char) TRUE) && ( current->number == e )) {#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_delete(): end line number is <%d>", e ); bwb_debug( bwb_ebuf );#endif end = current->next; } } } } else { end = start->next; } /* previous should now be set to the line previous to the first in the omission list */ /* now go through and delete appropriate lines */ current = start; while (( current != end ) && ( current != &CURTASK bwb_end )) { next = current->next;#if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwb_delete(): deleting line %d", current->number ); bwb_debug( bwb_ebuf );#endif /* free line memory */ bwb_freeline( current ); /* recycle */ current = next; } /* reset link */ previous->next = current; return bwb_zline( l ); }/*************************************************************** FUNCTION: bwb_donum() DESCRIPTION: This function implements the BASIC DO NUM command, numbering all program lines in memory in increments of 10 beginning at 10.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -