45 /* the length of the incoming line buffer */ |
45 /* the length of the incoming line buffer */ |
46 unsigned short int bufsize; |
46 unsigned short int bufsize; |
47 |
47 |
48 debug( 1, LOC, "Waiting for input...\n" ); |
48 debug( 1, LOC, "Waiting for input...\n" ); |
49 while ( fgets( buf, LINE_BUFSIZE, stdin ) != NULL ) { |
49 while ( fgets( buf, LINE_BUFSIZE, stdin ) != NULL ) { |
50 |
|
51 bufsize = strlen( buf ); |
50 bufsize = strlen( buf ); |
52 |
51 |
53 /* Common case, or last iteration of loop: |
52 /* Common case, or last iteration of loop: |
54 End of line was found without filling LINE_BUFSIZE |
53 End of line was found without filling LINE_BUFSIZE |
55 */ |
54 */ |
56 if ( bufsize + 1 < LINE_BUFSIZE ) { |
55 if ( bufsize + 1 < LINE_BUFSIZE ) { |
57 /* line wasn't concatenated onto in previous loops, |
56 /* line wasn't concatenated onto in previous loops, |
58 * just pass it directly to parse() */ |
57 * just pass it directly to process() */ |
59 if ( line == NULL ) { |
58 if ( line == NULL ) { |
60 parse( buf ); |
59 process( buf ); |
61 } |
60 } |
62 |
61 |
63 /* memory was previously allocated to contain the line, |
62 /* memory was previously allocated to contain the line, |
64 * append the final chunk, pass to parse(), and cleanup. */ |
63 * append the final chunk, pass to process(), and cleanup. */ |
65 else { |
64 else { |
66 if ( (line = extend_line( line, buf )) == NULL ) continue; |
65 if ( (line = extend_line( line, buf )) == NULL ) continue; |
67 parse( line ); |
66 process( line ); |
68 free( line ); |
67 free( line ), line = NULL; |
69 line = NULL; |
|
70 } |
68 } |
71 } |
69 } |
72 |
70 |
73 /* If we've filled LINE_BUFSIZE on this iteration, we were likely |
71 /* If we've filled LINE_BUFSIZE on this iteration, we were likely |
74 * passed a very long URL that we'll need to allocate more memory |
72 * passed a very long URL that we'll need to allocate more memory |
85 * LINE_BUFSIZE, but we can't simply check for that, since |
83 * LINE_BUFSIZE, but we can't simply check for that, since |
86 * we don't know if there are more iterations pending |
84 * we don't know if there are more iterations pending |
87 * (within the current line) that still need to be appended. |
85 * (within the current line) that still need to be appended. |
88 */ |
86 */ |
89 if ( buf[ bufsize - 1 ] == '\n' ) { |
87 if ( buf[ bufsize - 1 ] == '\n' ) { |
90 parse( line ); |
88 process( line ); |
91 free( line ); |
89 free( line ), line = NULL; |
92 line = NULL; |
|
93 } |
90 } |
94 } |
91 } |
95 } |
92 } |
96 |
93 |
97 /* stdin closed */ |
94 /* stdin closed */ |
98 debug( 1, LOC, "End of stream\n" ); |
95 debug( 1, LOC, "End of stream\n" ); |
|
96 report_speed(); |
99 return( 0 ); |
97 return( 0 ); |
100 } |
98 } |
101 |
99 |