SCM Repository
View of /branches/pure-cfg/src/lib/common/input.c
Parent Directory
|
Revision Log
Revision 1231 -
(download)
(as text)
(annotate)
Mon May 16 13:49:17 2011 UTC (11 years, 1 month ago) by jhr
File size: 2498 byte(s)
Mon May 16 13:49:17 2011 UTC (11 years, 1 month ago) by jhr
File size: 2498 byte(s)
Split input functions into their own file and added Diderot_InputVec2
/*! \file input.c * * \author John Reppy */ /* * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. */ #include "Diderot/diderot.h" #include <teem/hest.h> /* FIXME: eventally we should change the naming conventions in the header files to be generic */ #if defined(DIDEROT_SINGLE_PRECISION) #define vec2(a,b) vec2f(a,b) #define vec3(a,b,c) vec3f(a,b,c) #else #define vec2(a,b) vec2d(a,b) #define vec3(a,b,c) vec3d(a,b,c) #endif Status_t Diderot_InputString (const char *name, const char **v, bool hasDflt) { return DIDEROT_FAIL; } Status_t Diderot_InputReal (const char *name, Diderot_real_t *v, bool hasDflt) { char buf[256]; double f; while (true) { if (hasDflt) printf("Enter value for %s (default %lf): ", name, (double)*v); else printf("Enter value for %s: ", name); fflush (stdout); char *p = fgets(buf, sizeof(buf), stdin); if (p == NULL) return DIDEROT_FAIL; // EOF int n = sscanf(buf, "%lf\n", &f); if (n == 1) { *v = (Diderot_real_t)f; return DIDEROT_OK;; } else if (hasDflt) return DIDEROT_OK;; } } Status_t Diderot_InputVec2 (const char *name, Diderot_vec2_t *v, bool hasDflt) { char buf[256]; double f1, f2; while (true) { if (hasDflt) { Diderot_union2_t u; u.v = *v; printf("Enter value for %s (default %f %f): ", name, (double)(u.r[0]), (double)(u.r[1])); } else printf("Enter value for %s: ", name); fflush (stdout); char *p = fgets(buf, sizeof(buf), stdin); if (p == NULL) return DIDEROT_FAIL; // EOF int n = sscanf(buf, "%lf %lf\n", &f1, &f2); if (n == 2) { *v = vec2((Diderot_real_t)f1, (Diderot_real_t)f2); return DIDEROT_OK;; } else if (hasDflt) return DIDEROT_OK;; } } Status_t Diderot_InputVec3 (const char *name, Diderot_vec3_t *v, bool hasDflt) { char buf[256]; double f1, f2, f3; while (true) { if (hasDflt) { Diderot_union3_t u; u.v = *v; printf("Enter value for %s (default %f %f %f): ", name, (double)(u.r[0]), (double)(u.r[1]), (double)(u.r[2])); } else printf("Enter value for %s: ", name); fflush (stdout); char *p = fgets(buf, sizeof(buf), stdin); if (p == NULL) return DIDEROT_FAIL; // EOF int n = sscanf(buf, "%lf %lf %lf\n", &f1, &f2, &f3); if (n == 3) { *v = vec3((Diderot_real_t)f1, (Diderot_real_t)f2, (Diderot_real_t)f3); return DIDEROT_OK;; } else if (hasDflt) return DIDEROT_OK;; } }
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |