static int load_frame_ascii(cst_track *t, int i, cst_tokenstream *ts) { int j; t->times[i] = cst_atof(ts_get(ts)); ts_get(ts); /* the can be only 1 */ for (j = 0; j < t->num_channels; j++) t->frames[i][j] = cst_atof(ts_get(ts)); if ((i + 1 < t->num_frames) && (ts_eof(ts))) { return -1; } return 0; }
int relation_load(cst_relation *r, const char *filename) { cst_tokenstream *fd; cst_item *item; const char *token=0; if ((fd = ts_open(filename,NULL,";","","")) == 0) { cst_errmsg("relation_load: can't open file \"%s\" for reading\n", filename); return CST_ERROR_FORMAT; } for ( ; !ts_eof(fd); ) { token = ts_get(fd); if (cst_streq("#",token)) break; } #import "OpenEarsStaticAnalysisToggle.h" #ifdef STATICANALYZEDEPENDENCIES #define __clang_analyzer__ 1 #endif #if !defined(__clang_analyzer__) || defined(STATICANALYZEDEPENDENCIES) #undef __clang_analyzer__ if (!cst_streq("#",token)) #endif { cst_errmsg("relation_load: no end of header marker in \"%s\"\n", filename); ts_close(fd); return CST_ERROR_FORMAT; } while (!ts_eof(fd)) { token = ts_get(fd); if (cst_streq(token,"")) continue; item = relation_append(r,NULL); item_set_float(item,"end",(float)cst_atof(token)); #import "OpenEarsStaticAnalysisToggle.h" #ifdef STATICANALYZEDEPENDENCIES #define __clang_analyzer__ 1 #endif #if !defined(__clang_analyzer__) || defined(STATICANALYZEDEPENDENCIES) #undef __clang_analyzer__ token = ts_get(fd); #endif token = ts_get(fd); item_set_string(item,"name",token); } ts_close(fd); return CST_OK_FORMAT; }
int relation_load(cst_relation *r, const char *filename) { cst_tokenstream *fd; cst_item *item; const char *token=0; if ((fd = ts_open(filename,NULL,";","","")) == 0) { cst_errmsg("relation_load: can't open file \"%s\" for reading\n", filename); return CST_ERROR_FORMAT; } for ( ; !ts_eof(fd); ) { token = ts_get(fd); if (cst_streq("#",token)) break; } if (!cst_streq("#",token)) { cst_errmsg("relation_load: no end of header marker in \"%s\"\n", filename); ts_close(fd); return CST_ERROR_FORMAT; } while (!ts_eof(fd)) { token = ts_get(fd); if (cst_streq(token,"")) continue; item = relation_append(r,NULL); item_set_float(item,"end",(float)cst_atof(token)); token = ts_get(fd); token = ts_get(fd); item_set_string(item,"name",token); } ts_close(fd); return CST_OK_FORMAT; }
float val_float(const cst_val *v) { if (v && (CST_VAL_TYPE(v) == CST_VAL_TYPE_INT)) return (float)CST_VAL_INT(v); else if (v && (CST_VAL_TYPE(v) == CST_VAL_TYPE_FLOAT)) return CST_VAL_FLOAT(v); else if (v && (CST_VAL_TYPE(v) == CST_VAL_TYPE_STRING)) return cst_atof(CST_VAL_STRING(v)); else { cst_errmsg("VAL: tried to access float in %d typed val\n", (v ? CST_VAL_TYPE(v) : -1)); cst_error(); } return 0; }
cst_file cst_url_open(const char *url) { /* Always opens it for reading */ cst_tokenstream *urlts; const cst_string *protocol; int port; cst_string *host; int fd; char *url_request; char *path; cst_file ofd; int state,n; char c; urlts = ts_open_string(url, "", ":/", "", ""); protocol = ts_get(urlts); if (cst_streq(protocol,"http")) { #ifdef CST_NO_SOCKETS ts_close(urlts); return NULL; #else if (!cst_streq(ts_get(urlts),":") || !cst_streq(ts_get(urlts),"/") || !cst_streq(ts_get(urlts),"/")) { ts_close(urlts); return NULL; } host = cst_strdup(ts_get(urlts)); if (cst_streq(ts_get(urlts),":")) port = (int)cst_atof(ts_get(urlts)); else port = 80; /* Open port to web server */ fd = cst_socket_open(host,port); if (fd < 0) { cst_free(host); ts_close(urlts); return NULL; } url_request = cst_alloc(char,cst_strlen(url)+17); cst_sprintf(url_request,"GET %s HTTP/1.2\n\n",url); n = write(fd,url_request,cst_strlen(url_request)); cst_free(url_request); /* Skip http header -- until \n\n */ state=0; while (state != 4) { n=read(fd,&c,1); if (n == 0) { /* eof or link gone down */ cst_free(host); ts_close(urlts); return NULL; } if ((state == 0) && (c == '\r')) state=1; else if ((state == 1) && (c == '\n')) state=2; else if ((state == 2) && (c == '\r')) state=3; else if ((state == 3) && (c == '\n')) state=4; /* Not sure you can get no CRs in the stream */ else if ((state == 0) && (c == '\n')) state=2; else if ((state == 2) && (c == '\n')) state=4; else state = 0; } ofd = fdopen(fd,"rb"); ts_close(urlts); cst_free(host); return ofd; #endif }