%{ #define YY_INPUT(buf,result,max_size) \ { int digit ; \ int c = getc( yyin ) ; \ result = c == EOF ? 0 : 1 ; \ if( c == '%' ) { \ c = getc( yyin ) ; \ digit = c >= 'A' ? (( c & 0xdf ) - 'A' ) + 10 : c - '0' ; \ digit *= 16 ; \ c = getc( yyin ) ; \ digit += c >= 'A' ? (( c & 0xdf ) - 'A' ) + 10 : c - '0' ; \ buf[0] = (char) digit ; \ } \ else if( c == '+' ) \ buf[0] = ' ' ; \ else \ buf[0] = (char) c ; \ } int ans9a = 0, ans9b = 0, ans9c = 0, ans9d = 0 ; int correct = 1 ; %} WS [ \t] %% "answer9-1a=T"\&? { ans9a = 1 ; } "answer9-1b=T"\&? { ans9b = 1 ; } "answer9-1c=T"\&? { ans9c = 1 ; } "answer9-1d=T"\&? { ans9d = 1 ; } \n {} %% #include main() { yylex() ; } yywrap() { if( !ans9a && ans9b && ans9c && !ans9d ) send_file( "ans9-1.right" ) ; else { printf( "Content-type: text/html\n\n" ) ; printf( "\n\n" ) ; printf( "Experimental C Tutorial - Part 9-1\n" ) ; printf( "\n\n" ) ; printf( "

Sorry, you answered one or more incorrectly

\n" ) ; if( ans9a ) { printf( "Since both the name and phone number are stored\n" ) ; printf( "they can be stored as text each on a line\n" ) ; } if( !ans9b || !ans9c ) { printf( "

If we want to maintain the structure with\n" ) ; printf( "with numbers in it, we need to store them as\n" ) ; printf( "binary data in the file.\n" ) ; } if( ans9d ) { printf( "

Each of the names could be easily stored as\n" ) ; printf( "text.\n" ) ; } printf( "

Return and try again\n" ) ; printf( "\n" ) ; } return( 1 ) ; } send_file( s ) char *s ; { FILE *fp ; char buf[81] ; printf( "Content-type: text/html\n\n" ) ; fp = fopen( s, "r" ) ; if( fp ) { while( fgets( buf, 80, fp )) { printf( "%s", buf ) ; } fclose( fp ) ; } }