Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/lib/diderot.c
ViewVC logotype

Diff of /branches/pure-cfg/src/lib/diderot.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 571, Mon Feb 28 21:36:12 2011 UTC revision 572, Tue Mar 1 15:34:03 2011 UTC
# Line 272  Line 272 
272    
273  Status_t Diderot_Inputf (const char *name, float *v, bool hasDflt)  Status_t Diderot_Inputf (const char *name, float *v, bool hasDflt)
274  {  {
275        char        buf[256];
276      float       f;      float       f;
277    
278      while (true) {      while (true) {
# Line 281  Line 282 
282              printf("Enter value for %s: ", name);              printf("Enter value for %s: ", name);
283          fflush (stdout);          fflush (stdout);
284    
285          int n = scanf("%f\n", &f);          char *p = fgets(buf, sizeof(buf), stdin);
286  printf("n = %d\n", n);          if (p == NULL)
287          if (n == EOF)              return DIDEROT_FAIL;        // EOF
288              return DIDEROT_FAIL;          int n = sscanf(buf, "%f\n", &f);
289          else if (n == 1) {          if (n == 1) {
290              *v = f;              *v = f;
291              return DIDEROT_OK;;              return DIDEROT_OK;;
292          }          }
# Line 297  Line 298 
298    
299  Status_t Diderot_InputVec3f (const char *name, vec3f_t *v, bool hasDflt)  Status_t Diderot_InputVec3f (const char *name, vec3f_t *v, bool hasDflt)
300  {  {
301      return DIDEROT_FAIL;      char        buf[256];
302        float       f1, f2, f3;
303    
304        while (true) {
305            if (hasDflt)
306                printf("Enter value for %s (default %f %f %f): ",
307                    name, ((union3f_t)*v).r[0], ((union3f_t)*v).r[1], ((union3f_t)*v).r[2]);
308            else
309                printf("Enter value for %s: ", name);
310            fflush (stdout);
311    
312            char *p = fgets(buf, sizeof(buf), stdin);
313            if (p == NULL)
314                return DIDEROT_FAIL;        // EOF
315            int n = sscanf(buf, "%f %f %f\n", &f1, &f2, &f3);
316            if (n == 3) {
317                *v = vec3f(f1, f2, f3);
318                return DIDEROT_OK;;
319            }
320            else if (hasDflt)
321                return DIDEROT_OK;;
322        }
323    
324  }  }

Legend:
Removed from v.571  
changed lines
  Added in v.572

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0