struct bwb_line * bwb_FIELD(struct bwb_line * l) { int dev_number; struct exp_ese *e; int current_pos; char atbuf[BasicStringLengthMax + 1]; int pos; bwx_DEBUG(__FUNCTION__); current_pos = 0; /* first read device number */ adv_ws(l->buffer, &(l->position)); if (l->buffer[l->position] == BasicFileNumberPrefix) { ++(l->position); adv_ws(l->buffer, &(l->position)); } adv_element(l->buffer, &(l->position), atbuf); pos = 0; e = bwb_exp(atbuf, FALSE, &pos); if (ERROR_PENDING) { return bwb_zline(l); } if (e->type != NUMBER) { bwb_error("in bwb_field(): Number was expected for device number"); return bwb_zline(l); } dev_number = exp_getival(e); if (dev_number < 1 || dev_number > BasicFileNumberMax) { bwb_error("in bwb_field(): Requested device number is not VALID."); return bwb_zline(l); } /* be sure that the requested device is open */ if (dev_table[dev_number].mode != DEVMODE_RANDOM) { bwb_error("in bwb_field(): Requested device number is not RANDOM."); return bwb_zline(l); } /* loop to read variables */ do { int length; struct bwb_variable *v; bstring *b; /* read the comma and advance beyond it */ adv_ws(l->buffer, &(l->position)); if (l->buffer[l->position] == ',') { ++(l->position); } /* first find the size of the field */ adv_element(l->buffer, &(l->position), atbuf); /* get element */ pos = 0; e = bwb_exp(atbuf, FALSE, &pos); if (ERROR_PENDING) { return bwb_zline(l); } if (e->type != NUMBER) { bwb_error("in bwb_field(): number value for field size not found"); return bwb_zline(l); } length = exp_getival(e); /* read the AS */ adv_element(l->buffer, &(l->position), atbuf); /* get element */ if (strcasecmp(atbuf, "AS") != 0) { bwb_error("in bwb_field(): AS statement not found"); return bwb_zline(l); } /* read the string variable name */ #if 0 adv_element(l->buffer, &(l->position), atbuf); /* get element */ #endif bwb_getvarname(l->buffer, atbuf, &(l->position)); v = var_find(atbuf); if (v->type != STRING) { bwb_error("in bwb_field(): string variable name not found"); return bwb_zline(l); } /* check for overflow of record length */ if ((current_pos + length) > dev_table[dev_number].width) { bwb_error("in bwb_field(): record length exceeded"); return bwb_zline(l); } /* set buffer */ b = var_findsval(v, v->array_pos); b->sbuffer = dev_table[dev_number].buffer + current_pos; b->length = (unsigned int) length; /* Was unsigned char * (JBV 9/4/97) */ b->rab = TRUE; current_pos += length; /* eat up any remaining whitespace */ adv_ws(l->buffer, &(l->position)); } while (l->buffer[l->position] == ','); /* return */ return bwb_zline(l); }
static struct bwb_line * dio_lrset(struct bwb_line * l, int rset) { char varname[BasicNameLengthMax + 1]; bstring *d, *s; int *pp; int n_params; int p; register int n, i; int startpos; struct exp_ese *e; struct bwb_variable *v; int pos; bwx_DEBUG(__FUNCTION__); /* find the variable name */ bwb_getvarname(l->buffer, varname, &(l->position)); v = var_find(varname); if (v == NULL) { sprintf(bwb_ebuf, "in dio_lrset(): failed to find variable"); bwb_error(bwb_ebuf); } if (v->type != STRING) { sprintf(bwb_ebuf, "in dio_lrset(): assignment must be to string variable"); bwb_error(bwb_ebuf); } /* read subscripts */ pos = 0; if ((v->dimensions == 1) && (v->array_sizes[0] == 1)) { n_params = 1; pp = &p; pp[0] = dim_base; } else { dim_getparams(l->buffer, &(l->position), &n_params, &pp); } CURTASK exps[CURTASK expsc].pos_adv = pos; for (n = 0; n < v->dimensions; ++n) { v->array_pos[n] = pp[n]; } /* get bstring pointer */ d = var_findsval(v, pp); /* find equals sign */ adv_ws(l->buffer, &(l->position)); if (l->buffer[l->position] != '=') { sprintf(bwb_ebuf, "in dio_lrset(): failed to find equal sign"); bwb_error(bwb_ebuf); } ++(l->position); adv_ws(l->buffer, &(l->position)); /* read remainder of line to get value */ e = bwb_exp(l->buffer, FALSE, &(l->position)); if (ERROR_PENDING) { return bwb_zline(l); } s = exp_getsval(e); /* set starting position */ startpos = 0; if (rset == TRUE) { if (s->length < d->length) { startpos = d->length - s->length; } } /* write characters to new position */ i = 0; for (n = startpos; (i < (int) s->length) && (n < (int) d->length); ++n) { d->sbuffer[n] = s->sbuffer[i]; ++i; } /* return */ return bwb_zline(l); }
extern int bwx_shell( struct bwb_line *l ) { static char *s_buffer; static int init = FALSE; static int position; /* get memory for temporary buffer if necessary */ if ( init == FALSE ) { init = TRUE; /* Revised to CALLOC pass-thru call by JBV */ if ( ( s_buffer = CALLOC( MAXSTRINGSIZE + 1, sizeof( char ),"bwx_shell" )) == NULL ) { bwb_error( err_getmem ); return FALSE; } } /* get the first element and check for a line number */ #if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwx_shell(): line buffer is <%s>.", l->buffer ); bwb_debug( bwb_ebuf ); #endif position = 0; adv_element( l->buffer, &position, s_buffer ); if ( is_numconst( s_buffer ) != TRUE ) /* not a line number */ { #if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwx_shell(): no line number, command <%s>.", l->buffer ); bwb_debug( bwb_ebuf ); #endif nl(); endwin(); /* Added by JBV 10/11/97 */ if ( system( l->buffer ) == 0 ) { refresh(); /* Added by JBV 10/11/97 */ nonl(); ncu_setpos(); return TRUE; } else { refresh(); /* Added by JBV 10/11/97 */ nonl(); ncu_setpos(); return FALSE; } } else /* advance past line number */ { adv_ws( l->buffer, &position ); /* advance past whitespace */ #if INTENSIVE_DEBUG sprintf( bwb_ebuf, "in bwx_shell(): line number, command <%s>.", l->buffer ); bwb_debug( bwb_ebuf ); #endif nl(); endwin(); /* Added by JBV 10/11/97 */ if ( system( &( l->buffer[ position ] ) ) == 0 ) { refresh(); /* Added by JBV 10/11/97 */ nonl(); ncu_setpos(); return TRUE; } else { refresh(); /* Added by JBV 10/11/97 */ nonl(); ncu_setpos(); return FALSE; } } }