/******************************************************************************* DESCRIPTION: Skip rest of the line not including the newline token. *******************************************************************************/ void lx_skipline() { while (lx_next(),lx_token.type != NEWLINE_T); lx_unread(); if (debug > 1) { /******* debugging message *******************/ printf("*******line skept****\n"); printf("----------------------------------------------\n"); } }
static void match_any( pr_state_t* parser ) { switch ( lx_next( &parser->lexer ) ) { case LX_UNTERMINATED_STRING: longjmp( parser->env, PR_UNTERMINATED_STRING ); case LX_INVALID_CHARACTER: longjmp( parser->env, PR_INVALID_CHARACTER ); } }
/*********************************************************************** DESCRIPTION: Read a floating point value from a text widget with syntax error cheking. The value is read only if it have been changed since the last reading as indicated by status. If a syntax error have been found, the text field is visually marked and a warning message is popped up. An empty field is not considered an error by this function, and 0.0 is returned as the value. If the value has been succesfully read, it is checked by a user-supplied function valueok, and if rejected, the error is signaled as before with a user-supplied message given in the argument msg. ARGUMENTS: text - text widget *status - current status of the field on input, new status on output (enum textstatus) *dval - the read value is returned if there was no syntax error and the field is not empty valueok - a function which given a pointer to the value read, returns 1 if the application accepts it and 0 if not; if the field is empty, the pointer to the value is NULL EXTERNALS: None ***********************************************************************/ void textReadFloat(Widget text, TextStatusInfo *status, double *dp, int (*valueok)(double dval)) { String textstr; int sign = 1; double dval; if (status->change != TEXTSTAT_CHANGED) { currErrorCode = TEXT_NOCHANGE; return; } currErrorCode = TEXT_OK; XtVaGetValues(text,XmNvalue, &textstr,NULL); /****** read and analyze the field *****/ lx_load(textstr); lx_next(); if (lx_token.type == NEWLINE_T) { /* empty field */ dval = 0.0; currErrorCode = TEXT_EMPTY; goto ok_proc; } if (lx_token.type == OPER_T+'+') lx_next(); else if (lx_token.type == OPER_T+'-') {sign = -1; lx_next();} if (lx_token.type == DOUBLE_T) { dval = sign*lx_token.val.d; currErrorCode = TEXT_OK; } else if (lx_token.type == INT_T) { dval = sign*(double)lx_token.val.i; currErrorCode = TEXT_OK; } else { currErrorCode = TEXT_INVALID; goto endproc; } lx_next(); if (lx_token.type != NEWLINE_T) { currErrorCode = TEXT_INVDAFTER; goto endproc; } /***** perform user check *****/ ok_proc: valueok(dval); /* changes error code according to user preference */ /***** return the number or signal the error *****/ endproc: status->change = TEXTSTAT_NOCHANGE; switch (currErrorCode) { case TEXT_OK: if (status->stat==TEXTSTAT_SYNTERROR) utl_markTextValid(text); *dp = dval; status->stat = (status->stat&TEXTSTAT_SEMANTERROR)|TEXTSTAT_READOK; break; case TEXT_EMPTY: if (status->stat==TEXTSTAT_SYNTERROR) utl_markTextValid(text); *dp = dval; status->stat = (status->stat&TEXTSTAT_SEMANTERROR)|TEXTSTAT_EMPTY; break; case TEXT_INVALID: case TEXT_INVDAFTER: case TEXT_INVDEMPTY: case TEXT_INVDNONPOS: if (!(status->stat&TEXTSTAT_ANYERROR)) utl_markTextInvalid(text); status->stat = (status->stat&TEXTSTAT_SEMANTERROR)|TEXTSTAT_SYNTERROR; break; case TEXT_NOCHANGE: default: internalError(); } }
/*********************************************************************** DESCRIPTION: Read a name from a text widget with syntax error cheking. The value is read only if it have been changed since the last reading as indicated by status. If a syntax error have been found, the text field is visually marked and a warning message is popped up. An empty field is not considered an error by this function. ARGUMENTS: text - text widget *status - current status of the field on input, new status on output (enum textstatus) name - the read value is copied if there was no syntax error and the field is not empty valueok - a function which given a pointer to the value read, returns 1 if the application accepts it and 0 if not; if the field is empty, the pointer to the value is NULL EXTERNALS: None ***********************************************************************/ void textReadName(Widget text, TextStatusInfo *status, char *name, int (*valueok)(char *name,int n)) { String textstr; TOKLOC nameloc; if (status->change != TEXTSTAT_CHANGED) { currErrorCode = TEXT_NOCHANGE; return; } currErrorCode = TEXT_OK; XtVaGetValues(text,XmNvalue, &textstr,NULL); /****** read and analyze the field *****/ lx_load(textstr); lx_next(); nameloc = lx_loc; if (lx_token.type == NEWLINE_T) { /* empty field */ currErrorCode = TEXT_EMPTY; goto ok_proc; } if (lx_token.type == IDENT_T) { currErrorCode = TEXT_OK; } else { currErrorCode = TEXT_INVALID; goto endproc; } lx_next(); if (lx_token.type != NEWLINE_T) { currErrorCode = TEXT_INVDAFTER; } /***** perform user check *****/ ok_proc: /* changes error code according to user preference */ valueok(textstr+nameloc.pos,nameloc.inputlen); /***** return the name or signal the error *****/ endproc: status->change = TEXTSTAT_NOCHANGE; switch (currErrorCode) { case TEXT_OK: case TEXT_EMPTY: if (status->stat==TEXTSTAT_SYNTERROR) utl_markTextValid(text); status->stat = (status->stat&TEXTSTAT_SEMANTERROR)|TEXTSTAT_READOK; strncpy(name,textstr+nameloc.pos,nameloc.inputlen); name[nameloc.inputlen] = '\0'; break; case TEXT_INVALID: case TEXT_INVDEMPTY: case TEXT_INVDAFTER: if (!(status->stat&TEXTSTAT_ANYERROR)) utl_markTextInvalid(text); status->stat = (status->stat&TEXTSTAT_SEMANTERROR)|TEXTSTAT_SYNTERROR; break; case TEXT_NOCHANGE: default: internalError(); } }