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

PUBLIC int csoundNewOpcodeList ( CSOUND *  csound,
opcodeListEntry **  lstp 
)

Gets an alphabetically sorted list of all opcodes. Should be called after externals are loaded by csoundCompile(). Returns the number of opcodes, or a negative error code on failure. Make sure to call csoundDisposeOpcodeList() when done with the list.

Definition at line 61 of file opcode.c.

References csoundNewOpcodeList().

Referenced by csoundNewOpcodeList().

{
    void    *lst;
    OENTRY  *ep;
    char    *s;
    size_t  nBytes = (size_t) 0;
    int     i, cnt = 0;

    (*lstp) = NULL;
    i = csoundLoadAllPluginOpcodes(csound);
    if (i != 0)
      return i;
    ep = (OENTRY*) csound->opcodlst;
    if (ep == NULL)
      return -1;
    /* count the number of opcodes, and bytes to allocate */
    for ( ; ep < (OENTRY*) csound->oplstend; ep++) {
      if (ep->opname != NULL &&
          ep->opname[0] != '\0' && isalpha(ep->opname[0]) &&
          ep->outypes != NULL && ep->intypes != NULL) {
        cnt++;
        nBytes += sizeof(opcodeListEntry);
        for (i = 0; ep->opname[i] != '\0' && ep->opname[i] != '.'; i++)
          ;
        nBytes += (size_t) i;
        nBytes += strlen(ep->outypes);
        nBytes += strlen(ep->intypes);
        nBytes += 3;    /* for null characters */
      }
    }
    nBytes += sizeof(opcodeListEntry);
    /* allocate memory for opcode list */
    lst = malloc(nBytes);
    if (lst == NULL)
      return CSOUND_MEMORY;
    (*lstp) = (opcodeListEntry*) lst;
    /* store opcodes in list */
    ep = (OENTRY*) csound->opcodlst;
    s = (char*) lst + ((int) sizeof(opcodeListEntry) * (cnt + 1));
    for (cnt = 0; ep < (OENTRY*) csound->oplstend; ep++) {
      if (ep->opname != NULL &&
          ep->opname[0] != '\0' && isalpha(ep->opname[0]) &&
          ep->outypes != NULL && ep->intypes != NULL) {
        for (i = 0; ep->opname[i] != '\0' && ep->opname[i] != '.'; i++)
          s[i] = ep->opname[i];
        s[i++] = '\0';
        ((opcodeListEntry*) lst)[cnt].opname = s;
        s += i;
        strcpy(s, ep->outypes);
        ((opcodeListEntry*) lst)[cnt].outypes = s;
        s += ((int) strlen(ep->outypes) + 1);
        strcpy(s, ep->intypes);
        ((opcodeListEntry*) lst)[cnt].intypes = s;
        s += ((int) strlen(ep->intypes) + 1);
        cnt++;
      }
    }
    ((opcodeListEntry*) lst)[cnt].opname = NULL;
    ((opcodeListEntry*) lst)[cnt].outypes = NULL;
    ((opcodeListEntry*) lst)[cnt].intypes = NULL;
    /* sort list */
    qsort(lst, (size_t) cnt, sizeof(opcodeListEntry), opcode_cmp_func);
    /* return the number of opcodes */
    return cnt;
}


Generated by  Doxygen 1.6.0   Back to index