int main( int argc, char *argv[] ) { char *getenv(); int i, file0; progname = argv[0]; libpath[0] = "./"; if ((libpath[i=1] = getenv("MDIR")) != NULL) i++; libpath[i++] = "/usr/local/lib/meta/"; libpath[i] = NULL; for (file0 = 1; file0 < argc-1; file0 += 2) if (!isopt(argv[file0])) break; if (file0 >= argc) dofile(argc-1, argv+1, NULL); else for (i = file0; i < argc; i++) dofile(file0-1, argv+1, argv[i]); quit(0); return 0; /* pro forma return */ }
// Create DSP Factory llvm_dsp_factory* dsp_server_connection_info::createFactory(DSPServer* server, string& error) { // Sort out compilation options int argc = fCompilationOptions.size(); const char* argv[argc]; for (int i = 0; i < argc; i++) { argv[i] = fCompilationOptions[i].c_str(); } llvm_dsp_factory* factory = NULL; if (isopt(argc, argv, "-lm")) { // Machine code factory = readDSPFactoryFromMachine(fFaustCode, loptions(argv, "-lm", "")); //factory = readCDSPFactoryFromMachine(fFaustCode.c_str(), loptions(argv, "-lm", "")); } else { // DSP code string error1; factory = createDSPFactoryFromString(fNameApp, fFaustCode, argc, argv, "", error, atoi(fOptLevel.c_str())); /* char error1[256]; factory = createCDSPFactoryFromString(fNameApp.c_str(), fFaustCode.c_str(), argc, argv, "", error1, atoi(fOptLevel.c_str())); */ error = error1; } if (factory && server->fCreateDSPFactoryCb) { // Possibly call callback server->fCreateDSPFactoryCb(factory, server->fCreateDSPFactoryCb_arg); } return factory; }
int dirseek ( char *cmd_, DCLARG *d_, int mfld, int need) { static char sFMT1[] = "File(s) not found: %%.%ds"; static char format [sizeof(sFMT1)+6]; for (; d_; d_ = d_->dcl_next) { if (isopt (d_->dcl_text[0])) continue; else if (d_->dcl_mfld != mfld) continue; if (! dirseek_spec (d_, FALSE, 0)) { if (need) { sprintf (format, sFMT1, d_->dcl_size); warn (format, &cmd_[d_->dcl_from]); } return (FALSE); } } return (TRUE); }
char opttok(const char** out_value, int argc, const char* argv[], const option* options, size_t num_options) { thread_local static const char**s_local_argv = 0; thread_local static int s_local_argc = 0; thread_local static const option* s_local_options = 0; thread_local static size_t s_num_options = 0; thread_local static int i = 0; *out_value = ""; if (argv) { s_local_argv = argv; s_local_argc = argc; s_local_options = options; s_num_options = num_options; i = 1; // skip exe name } else if (i >= s_local_argc) return 0; const char* currarg = s_local_argv[i]; const char* nextarg = s_local_argv[i+1]; if (!currarg) return 0; const option* oend = s_local_options + s_num_options; if (islongopt(currarg)) { currarg += 2; for (const option* o = s_local_options; o < oend; o++) { if (!strcmp(o->fullname, currarg)) { if (o->argname) { if (i == argc-1 || isopt(nextarg)) { i++; *out_value = (const char*)(uintptr_t)i; return ':'; } *out_value = nextarg; } else *out_value = currarg; i++; if (o->argname) i++; return o->abbrev; } o++; } i++; // skip unrecognized opt *out_value = currarg; return '?'; } else if (isopt(s_local_argv[i])) { currarg++; for (const option* o = s_local_options; o < oend; o++) { if (*currarg == o->abbrev) { if (o->argname) { if (*(currarg+1) == ' ' || *(currarg+1) == 0) { if (i == argc-1 || isopt(nextarg)) { i++; return ':'; } *out_value = nextarg; i += 2; } else { *out_value = currarg + 1; i++; } } else { *out_value = currarg; i++; } return o->abbrev; } } i++; // skip unrecognized opt *out_value = currarg; return '?'; } *out_value = s_local_argv[i++]; // skip to next arg return ' '; }
int main (int argc, char **argv) { char *buf = NULL; char *key = NULL; char *seed = NULL; uint32_t h = 0; // parse opts { char *opt = NULL; char tmp = 0; opt = *argv++; // unused while ((opt = *argv++)) { // flags if ('-' == *opt++) { switch (*opt++) { case 'h': return usage(), help(), 0; case 'V': fprintf(stderr, "%s\n", MURMURHASH_VERSION); return 0; case '-': if (isopt(opt, "seed")) { setopt(opt, "seed", seed); } break; default: tmp = *opt--; // error fprintf(stderr, "unknown option: `%s'\n", opt); usage(); return 1; } } } } if (NULL == seed) { seed = "0"; } #define hash(key) murmurhash(key, (uint32_t) strlen(key), (uint32_t) atoi(seed)); if (1 == isatty(0)) { return 1; } else if (ferror(stdin)) { return 1; } else { buf = read_stdin(); if (NULL == buf) { return 1; } else if (0 == strlen(buf)) { buf = ""; } h = hash(buf); printf("%" PRIu32 "\n", h); do { key = read_stdin(); if (NULL == key) { break; } else if (0 == strlen(buf)) { buf = ""; } h = hash(buf); printf("%d" PRIu32 "\n", h); } while (NULL != key); } #undef hash return 0; }
DCLARG *dclarg(char *inp_, char *dft_, int cmd_arg, int cpy_dft) { DCLARG *arg_ = 0; struct FAB fab; struct NAM nam, nam2; int len, /* (misc) string length */ use_dna2 = FALSE; /* TRUE if 'dna2[]' is default */ char rsa [NAM$C_MAXRSS], /* resultant string (SYS$SEARCH)*/ esa [NAM$C_MAXRSS], /* expanded string (SYS$PARSE) */ dna [NAM$C_MAXRSS], /* next 'sfld' default string */ dna2 [NAM$C_MAXRSS], /* next 'mfld' default if list */ dna3 [NAM$C_MAXRSS], /* next 'mfld' default if single*/ cmdtok [NAM$C_MAXRSS], *i_ = inp_, /* beginning of item to parse */ *j_, /* end+1 of item to parse */ *k_; /* miscellaneous pointer */ if (!dft_) dft_ = ""; strcpy (dna, dft_); strcpy (dna2,dft_); strcpy (dna3,dft_); dclarg_init (); for (;;) { SPC(i_); /* Ignore blanks between tokens */ j_ = i_; if (*i_ == EOS) return (first_); /* * Options begin with "/", and are followed by: * (a) an optional alphanumeric+'_' name, then * (b) an optional (if name given) "=" * (c) an option-value if "=", perhaps enclosed in * "(" and ")". * * SET-commands may use an "=" without a preceding "/" * (e.g., "SET PROTECTION=(OWN:RE)"). */ else if (isopt(*i_)) { if (*i_ == '/') { i_++; SPC(i_); i_ = dclarg_keyw (i_); k_ = i_; SPC(k_); if (isopt2(*k_)) i_ = k_; } if (isopt2(*i_)) { i_++; SPC(i_); if (*i_ == '(') { while (*i_ && (*i_ != ')')) i_++; if (*i_ == ')') i_++; } else i_ = dclarg_spec (i_, "-"); } status = 0; STRNCPY(esa, j_, i_ - j_); arg_ = dclarg_make (arg_, esa, FROM, (struct NAM *)0); } /* * File names contain a mixture of ".", ":", ";", alphanumeric * characters, and "[", "]" to delimit directories. Many * DCL-oriented programs permit a list of filenames separated * by comma to indicate that the directory defaults. Finally, * wildcard characters "*" and "%" are used. * * Perform enough parsing here to pass along the defaults to * the calling program. */ else if (dclarg_name(*i_)) { i_ = dclarg_spec (i_, 0); if (cmd_arg > 0) { STRNCPY(cmdtok, j_, i_ - j_); arg_ = dclarg_make (arg_, cmdtok, FROM, (struct NAM *)0); } else { if (mfld <= 0) mfld = 1, sfld = 0; rmsinit_fab (&fab, &nam, (sfld ? dna : (use_dna2 ? dna2 : dna3)), 0); fab.fab$l_fna = j_; fab.fab$b_fns = i_-j_; rmsinit_nam (&nam, rsa, esa); status = sys$parse(&fab); /* * If we're referring to a directory that doesn't exist, * the parse will return a directory-not-found (something * that we'd normally expect from sys$search). That * breaks the "create" command. */ if (status == RMS$_DNF) status = 0; /* * Use the most recent name as a default name for the next * parse: */ STRNCPY(dna, esa, nam.nam$b_esl); nam2 = nam; /* Save to use in 'dclarg_make' */ /* * If this was the first item in any list, (sfld==0), * obtain the parsed string, and the first-found from a * search for the defaults 'dna3' and 'dna2', respectively. */ if (sfld == 0) { dclarg__copy (dna3, &nam, cpy_dft); if (cpy_dft) { sys$search (&fab); dclarg__copy (dna2, &nam, cpy_dft); } use_dna2 = FALSE; } /* * Make a new DCLARG-entry: */ arg_ = dclarg_make (arg_, (nam.nam$b_esl ? dna : j_), FROM, &nam2); } } else { while (!dclarg_name(*i_) && !isopt(*i_)) i_++; status = -1; arg_ = dclarg_make (arg_, err_parm, FROM, (struct NAM *)0); } SPC(i_); if (*i_ == ',') { use_dna2 = cpy_dft; /* COPY-output inherits 1st input */ i_++; sfld++; SPC(i_); j_ = i_; while (isspace(*i_) || *i_ == ',') i_++; if (j_ != i_ || isopt(*i_)) { status = -1; arg_ = dclarg_make (arg_, err_null, FROM, (struct NAM *)0); } } else if (!isopt(*i_)) { strcpy (dna, dft_); if (cmd_arg <= 0) { mfld++; sfld = 0; } } if (cmd_arg > 0) cmd_arg--; /* (On zero, look for filenames) */ } }
// Create DSP Factory dsp_factory* dsp_server_connection_info::crossCompileFactory(DSPServer* server, string& error) { dsp_factory* factory; // Already in the cache... #ifdef LLVM_DSP_FACTORY if ((factory = getDSPFactoryFromSHAKey(fSHAKey))) { #else if ((factory = getInterpreterDSPFactoryFromSHAKey(fSHAKey))) { #endif return factory; } else { // Sort out compilation options int argc = int(fCompilationOptions.size()); const char* argv[argc]; for (int i = 0; i < argc; i++) { argv[i] = fCompilationOptions[i].c_str(); } string error1; #ifdef LLVM_DSP_FACTORY factory = createDSPFactoryFromString(fNameApp, fFaustCode, argc, argv, fTarget, error1, atoi(fOptLevel.c_str())); #else factory = createInterpreterDSPFactoryFromString(fNameApp, fFaustCode, argc, argv, error1); #endif error = error1; if (factory && server->fCreateDSPFactoryCb) { // Possibly call callback server->fCreateDSPFactoryCb(factory, server->fCreateDSPFactoryCb_arg); } return factory; } } // Create DSP Factory dsp_factory* dsp_server_connection_info::createFactory(DSPServer* server, string& error) { // Sort out compilation options int argc = fCompilationOptions.size(); const char* argv[argc]; for (int i = 0; i < argc; i++) { argv[i] = fCompilationOptions[i].c_str(); } dsp_factory* factory = NULL; if (isopt(argc, argv, "-lm")) { // Machine code #ifdef LLVM_DSP_FACTORY factory = readDSPFactoryFromMachine(fFaustCode, loptions(argv, "-lm", "")); #else factory = readInterpreterDSPFactoryFromMachine(fFaustCode); #endif } else { // DSP code string error1; #ifdef LLVM_DSP_FACTORY factory = createDSPFactoryFromString(fNameApp,fFaustCode, argc, argv, "", error, atoi(fOptLevel.c_str())); #else factory = createInterpreterDSPFactoryFromString(fNameApp, fFaustCode, argc, argv, error); #endif error = error1; } if (factory && server->fCreateDSPFactoryCb) { // Possibly call callback server->fCreateDSPFactoryCb(factory, server->fCreateDSPFactoryCb_arg); } return factory; }
int main(int argc, char *argv[]) { char appname[256]; char filename[256]; char rcfilename[256]; std::string error_msg; char* home = getenv("HOME"); llvm_dsp* DSP = NULL; llvm_dsp_factory* factory; int inc_arg = 0; int celt = lopt(argv, "--celt", -1); const char* master_ip = lopts(argv, "--a", DEFAULT_MULTICAST_IP); int master_port = lopt(argv, "--p", DEFAULT_PORT); if (isopt(argv, "--celt")) inc_arg += 2; if (isopt(argv, "--a")) inc_arg += 2; if (isopt(argv, "--p")) inc_arg += 2; if (argc < 2) { printf("Usage: faust-netjack-gtk args [file.dsp | file.bc]\n"); exit(1); } else { factory = createDSPFactoryFromFile(argv[1], argc-2-inc_arg, (const char**)&argv[inc_arg+2], "", error_msg); DSP = factory->createDSPInstance(); if (!DSP) { std::cerr << error_msg; std::cerr << "Cannot load .dsp or .bc file" << std::endl; exit(1); } } snprintf(appname, 256, "%s", basename(argv[0])); snprintf(filename, 256, "%s", basename(argv[argc-1])); snprintf(rcfilename, 256, "%s/.%s-%src", home, appname, argv[1]); GUI* interface = new GTKUI(filename, &argc, &argv); FUI* finterface = new FUI(); DSP->buildUserInterface(interface); DSP->buildUserInterface(finterface); #ifdef HTTPCTRL httpdUI* httpdinterface = new httpdUI(appname, argc, argv); DSP->buildUserInterface(httpdinterface); #endif #ifdef OSCCTRL GUI* oscinterface = new OSCUI(filename, argc, argv); DSP->buildUserInterface(oscinterface); #endif netjackaudio audio(celt, master_ip, master_port, DEFAULT_MTU); if (!audio.init(filename, DSP)) { return 0; } finterface->recallState(rcfilename); audio.start(); #ifdef HTTPCTRL httpdinterface->run(); #endif #ifdef OSCCTRL oscinterface->run(); #endif interface->run(); audio.stop(); finterface->saveState(rcfilename); return 0; }
int getopt(int argc, char * const argv[], const char *optstring) { int has_arg, is_optional; const char *match; /* Check for a reset. */ if (optind == 0) { optind = 1; nextchar = 0; } for (;;) { if (!argv[optind] || !isopt(argv[optind])) return DONE; if (argv[optind][nextchar] != '\0') break; optind++; nextchar = 0; } if (nextchar == 0) nextchar = 1; optopt = argv[optind][nextchar]; match = strchr(optstring, optopt); /* Advance to the next character or argument. */ nextchar++; if (argv[optind][nextchar] == '\0') { optind++; nextchar = 0; } if (!match) { if (opterr) fprintf(stderr, "Option '%c' is not recognized.", optopt); return UNRECOGNIZED_OPTION; } /* Should the option have an argument? */ has_arg = match[1] == ':'; if (has_arg) { /* Options in optstring followed by two colons (::) are optional. */ is_optional = has_arg && match[2] == ':'; /* If we've depleted this argument, optind has already been advanced, * and nextarg is zero, so this is safe even at the end of all * arguments where argv[optind] is NULL. */ optarg = argv[optind] + nextchar; /* Advance the pointers in preparation for the next option. */ optind++; nextchar = 0; /* I'm interpreting the man page as only returning ':' if optstring * begins with ':' and the argument is optional. Otherwise, there is no * reason for using "::" in optstring to indicate optionality. */ if (optarg == NULL) return (optstring[0] == ':' && is_optional) ? MISSING_ARGUMENT : UNRECOGNIZED_OPTION; } return optopt; }