Logo Search packages:      
Sourcecode: csound version File versions  Download package

PUBLIC int csoundRunUtility ( CSOUND *  ,
const char *  name,
int  argc,
char **  argv 
)

Run utility with the specified name and command line arguments. Should be called after loading utility plugins with csoundPreCompile(); use csoundReset() to clean up after calling this function. Returns zero if the utility was run successfully.

Definition at line 65 of file utility.c.

References csoundRunUtility().

Referenced by csoundRunUtility().

{
    csUtility_t   *p;
    char          **lst;
    volatile void *saved_exitjmp;
    volatile int  n;

    if (csound == NULL)
      return -1;

    saved_exitjmp = (void*) malloc(sizeof(jmp_buf));
    if (saved_exitjmp == NULL)
      return -1;
    memcpy((void*) saved_exitjmp, (void*) &(csound->exitjmp), sizeof(jmp_buf));

    if ((n = setjmp(csound->exitjmp)) != 0) {
      n = (n - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS;
      goto err_return;
    }

    if (name == NULL || name[0] == '\0')
      goto notFound;
    p = (csUtility_t*) csound->utility_db;
    while (1) {
      if (p == NULL)
        goto notFound;
      if (strcmp(p->name, name) == 0)
        break;
      p = p->nxt;
    }
    csound->engineState |= CS_STATE_UTIL;
    csound->scorename = csound->orchname = (char*) name;    /* needed ? */
    csound->Message(csound, Str("util %s:\n"), name);
    n = p->UtilFunc(csound, argc, argv);
    goto err_return;

 notFound:
    if (name != NULL && name[0] != '\0') {
      print_opcodedir_warning(csound);
      csound->ErrorMsg(csound, Str("Error: utility '%s' not found"), name);
    }
    else
      csound->ErrorMsg(csound, Str("Error: utility not found"));
    lst = csound->ListUtilities(csound);
    if (lst != NULL && lst[0] != NULL) {
      int i;
      csound->Message(csound, Str("The available utilities are:\n"));
      for (i = 0; lst[i] != NULL; i++) {
        const char *desc = csound->GetUtilityDescription(csound, lst[i]);
        if (desc != NULL)
          csound->Message(csound, "    %s\t%s\n", lst[i], Str(desc));
        else
          csound->Message(csound, "    %s\n", lst[i]);
      }
    }
    csound->DeleteUtilityList(csound, lst);
    n = -1;
 err_return:
    memcpy((void*) &(csound->exitjmp), (void*) saved_exitjmp, sizeof(jmp_buf));
    free((void*) saved_exitjmp);
    return n;
}


Generated by  Doxygen 1.6.0   Back to index