~ubuntu-branches/ubuntu/precise/csound/precise

« back to all changes in this revision

Viewing changes to Engine/namedins.c

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2012-04-19 09:26:46 UTC
  • mfrom: (3.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20120419092646-96xbj1n6atuqosk2
Tags: 1:5.17.6~dfsg-1
* New upstream release
 - Do not build the wiimote opcodes (we need wiiuse).
* Add new API function to symbols file
* Disable lua opcodes, they were broken. Requires OpenMP to be enabled.
* Backport fixes from upstream:
  - Link dssi4cs with dl. Backport
  - Fix building of CsoundAC

Show diffs side-by-side

added added

removed removed

Lines of Context:
469
469
/* -------------------------------------------------------------------- */
470
470
/* These functions replace the functionality of strsav() in rdorch.c.   */
471
471
 
472
 
#define STRSPACE    (8000)              /* number of bytes in a buffer  */
 
472
#define STRSPACE    (1000)               /* number of bytes in a buffer  */
473
473
 
474
474
typedef struct strsav_t {
475
475
        struct strsav_t *nxt;           /* pointer to next structure    */
477
477
} STRSAV;
478
478
 
479
479
typedef struct strsav_space_t {
480
 
        char    sp[STRSPACE];           /* string space                */
 
480
        char    *sp;                    /* string space                */
 
481
        int     size;                   /* Size of buffer              */
481
482
        int     splim;                  /* number of bytes allocated   */
482
483
        struct strsav_space_t   *prv;   /* ptr to previous buffer      */
483
484
} STRSAV_SPACE;
490
491
void strsav_create(CSOUND *csound)
491
492
{
492
493
    if (csound->strsav_space != NULL) return;   /* already allocated */
 
494
    csound->strsav_str = mcalloc(csound, sizeof(STRSAV*) * 256);
493
495
    csound->strsav_space = mcalloc(csound, sizeof(STRSAV_SPACE));
494
 
    csound->strsav_str = mcalloc(csound, sizeof(STRSAV*) * 256);
 
496
    STRSAV_SPACE_->sp = (char*)mcalloc(csound, STRSPACE);
 
497
    STRSAV_SPACE_->size = STRSPACE;
495
498
}
496
499
 
497
500
/* Locate string s in database, and return address of stored string (not */
526
529
    n = (int) sizeof(struct strsav_t *) + (int) strlen(s) + 1;  /* n bytes */
527
530
    n = ((n + (int) sizeof(struct strsav_t *) - 1)  /* round up for alignment */
528
531
         / (int) sizeof(struct strsav_t *)) * (int) sizeof(struct strsav_t *);
529
 
    if ((STRSAV_SPACE_->splim + n) > STRSPACE) {
 
532
    if ((STRSAV_SPACE_->splim + n) > STRSAV_SPACE_->size) {
530
533
      STRSAV_SPACE  *sp;
531
534
      /* not enough space, allocate new buffer */
532
 
      if (UNLIKELY(n > STRSPACE)) {
 
535
       if (UNLIKELY(n > STRSAV_SPACE_->size)) {
533
536
        /* this should not happen */
534
 
        csound->ErrorMsg(csound,
535
 
                         "internal error: strsav: string length > STRSPACE");
536
 
        return NULL;
537
 
      }
538
 
      sp = (STRSAV_SPACE*) mcalloc(csound, sizeof(STRSAV_SPACE));
539
 
      sp->prv = STRSAV_SPACE_;
540
 
      csound->strsav_space = sp;
 
537
         sp = (STRSAV_SPACE*)mcalloc(csound, sizeof(STRSAV_SPACE));
 
538
         sp->sp =
 
539
          (char*)mcalloc(csound, sp->size = n+STRSPACE);
 
540
         csound->DebugMsg(csound,
 
541
                        "internal message: strsav: buffer length now %d\n",
 
542
                        sp->size);
 
543
 
 
544
       }
 
545
       else {
 
546
         sp = (STRSAV_SPACE*) mcalloc(csound, sizeof(STRSAV_SPACE));
 
547
         sp->sp =
 
548
           (char*)mcalloc(csound, STRSAV_SPACE_->size = STRSPACE);
 
549
       }
 
550
       sp->prv = STRSAV_SPACE_;
 
551
       csound->strsav_space = sp;
541
552
    }
542
553
    /* use space from buffer */
543
 
    ssp = (STRSAV*) ((char*) STRSAV_SPACE_->sp + STRSAV_SPACE_->splim);
 
554
    //    ssp = (STRSAV*) ((char*) STRSAV_SPACE_->sp + STRSAV_SPACE_->splim);
 
555
    ssp = (STRSAV*)(&(STRSAV_SPACE_->sp)[STRSAV_SPACE_->splim]);
544
556
    STRSAV_SPACE_->splim += n;
545
557
    strcpy(ssp->s, s);          /* save string */
546
558
    /* link into chain */
1074
1086
    return 1;
1075
1087
}
1076
1088
 
1077
 
/* static CS_NOINLINE int csoundLoadOpcodeDB_AddFile(CSOUND *csound, */
1078
 
/*                                     CsoundOpcodePluginFile_t *fp) */
1079
 
/* { */
1080
 
/*     CsoundOpcodePluginFile_t    **pp, *p; */
1081
 
/*     unsigned char               h; */
1082
 
 
1083
 
/*     pp = (CsoundOpcodePluginFile_t**) csound->pluginOpcodeFiles; */
1084
 
/*     h = name_hash_2(csound, fp->fname); */
1085
 
/*     p = pp[h]; */
1086
 
/*     while (p) { */
1087
 
/*       /\* check for a name conflict *\/ */
1088
 
/*       if (!sCmp(p->fname, fp->fname)) */
1089
 
/*         return -1; */
1090
 
/*       p = p->nxt; */
1091
 
/*     } */
1092
 
/*     fp->nxt = pp[h]; */
1093
 
/*     fp->isLoaded = -1; */
1094
 
/*     pp[h] = fp; */
1095
 
/*     return 0; */
1096
 
/* } */
1097
 
 
1098
 
/* static CS_NOINLINE int csoundLoadOpcodeDB_AddOpcode(CSOUND *csound, */
1099
 
/*                                           CsoundPluginOpcode_t *op) */
1100
 
/* { */
1101
 
/*     CsoundPluginOpcode_t    **pp, *p; */
1102
 
/*     unsigned char           h; */
1103
 
 
1104
 
/*     pp = (CsoundPluginOpcode_t**) csound->pluginOpcodeDB; */
1105
 
/*     h = name_hash_2(csound, op->opname); */
1106
 
/*     p = pp[h]; */
1107
 
/*     while (p) { */
1108
 
/*       /\* check for a name conflict *\/ */
1109
 
/*       if (!sCmp(p->opname, op->opname)) */
1110
 
/*         return -1; */
1111
 
/*       p = p->nxt; */
1112
 
/*     } */
1113
 
/*     op->nxt = pp[h]; */
1114
 
/*     pp[h] = op; */
1115
 
/*     return 0; */
1116
 
/* } */
1117
 
 
1118
 
/* void csoundDestroyOpcodeDB(CSOUND *csound) */
1119
 
/* { */
1120
 
/*     void    *p; */
1121
 
 
1122
 
/*     p = csound->pluginOpcodeFiles; */
1123
 
/*     csound->pluginOpcodeFiles = NULL; */
1124
 
/*     csound->pluginOpcodeDB = NULL; */
1125
 
/*     csound->Free(csound, p); */
1126
 
/* } */
1127
 
 
1128
 
/* load opcodes.dir from the specified directory, and set up database */
1129
 
 
1130
 
/* int csoundLoadOpcodeDB(CSOUND *csound, const char *dname) */
1131
 
/* { */
1132
 
/*     char    err_msg[256]; */
1133
 
/*     char    *s, *sp, *fileData = (char*) NULL; */
1134
 
/*     void    *fd = (void*) NULL; */
1135
 
/*     FILE    *fp = (FILE*) NULL; */
1136
 
/*     size_t  i, n, fileLen, fileCnt, opcodeCnt, byteCnt; */
1137
 
/*     void    *p, *p1, *p2; */
1138
 
/*     CsoundOpcodePluginFile_t  *currentFile; */
1139
 
 
1140
 
/*     /\* check file name *\/ */
1141
 
/*     if (dname == NULL || dname[0] == (char) 0) */
1142
 
/*       return 0; */
1143
 
/*     n = strlen(dname); */
1144
 
/*     s = csoundConcatenatePaths(csound, dname, "opcodes.dir"); */
1145
 
/*     /\* open and load file *\/ */
1146
 
/*     fd = csound->FileOpen(csound, &fp, CSFILE_STD, s, "rb", NULL); */
1147
 
/*     csound->Free(csound, s); */
1148
 
/*     if (fd == NULL) */
1149
 
/*       return 0; */
1150
 
/*     if (fseek(fp, 0L, SEEK_END) != 0) { */
1151
 
/*       sprintf(&(err_msg[0]), "seek error"); */
1152
 
/*       goto err_return; */
1153
 
/*     } */
1154
 
/*     fileLen = (size_t) ftell(fp); */
1155
 
/*     fseek(fp, 0L, SEEK_SET); */
1156
 
/*     if (fileLen == (size_t) 0) { */
1157
 
/*       csound->FileClose(csound, fd); */
1158
 
/*       return 0; */
1159
 
/*     } */
1160
 
/*     fileData = (char*) csound->Malloc(csound, fileLen + (size_t) 1); */
1161
 
/*     n = fread(fileData, (size_t) 1, fileLen, fp); */
1162
 
/*     csound->FileClose(csound, fd); */
1163
 
/*     fd = NULL; */
1164
 
/*     if (n != fileLen) { */
1165
 
/*       sprintf(&(err_msg[0]), "read error"); */
1166
 
/*       goto err_return; */
1167
 
/*     } */
1168
 
/*     fileData[fileLen] = (char) '\n'; */
1169
 
/*     /\* check syntax, and count the number of files and opcodes *\/ */
1170
 
/*     fileCnt = (size_t) 0; */
1171
 
/*     opcodeCnt = (size_t) 0; */
1172
 
/*     byteCnt = (size_t) 0; */
1173
 
/*     n = fileLen; */
1174
 
/*     for (i = (size_t) 0; i <= fileLen; i++) { */
1175
 
/*       if (fileData[i] == (char) ' ' || fileData[i] == (char) '\t' || */
1176
 
/*           fileData[i] == (char) '\r' || fileData[i] == (char) '\n') { */
1177
 
/*         if (n >= fileLen) */
1178
 
/*           continue; */
1179
 
/*         fileData[i] = (char) 0; */
1180
 
/*         if (fileData[i - 1] != ':') { */
1181
 
/*           if (!fileCnt) { */
1182
 
/*             sprintf(&(err_msg[0]), "syntax error"); */
1183
 
/*             goto err_return; */
1184
 
/*           } */
1185
 
/*           opcodeCnt++; */
1186
 
/*         } */
1187
 
/* #if !(defined(LINUX) || defined(__unix__) || defined(__MACH__)) */
1188
 
/*         else { */
1189
 
/*           size_t  j; */
1190
 
/*           /\* on some platforms, file names are case insensitive *\/ */
1191
 
/*           for (j = n; j < (i - 1); j++) { */
1192
 
/*             if (isupper(fileData[j])) */
1193
 
/*               fileData[j] = (char) tolower(fileData[j]); */
1194
 
/*           } */
1195
 
/*         } */
1196
 
/* #endif */
1197
 
/*         n = fileLen; */
1198
 
/*         continue; */
1199
 
/*       } */
1200
 
/*       if (n >= fileLen) */
1201
 
/*         n = i; */
1202
 
/*       if (!(isalnum(fileData[i]) || fileData[i] == (char) '.' || */
1203
 
/*             fileData[i] == (char) '-' || fileData[i] == (char) '_')) { */
1204
 
/*         if (fileData[i] == (char) ':' && i != n && i < fileLen && */
1205
 
/*             (fileData[i + 1] == (char) ' ' || fileData[i + 1] == (char) '\t' || */
1206
 
/*              fileData[i + 1] == (char) '\r' || fileData[i + 1] == (char) '\n')) */
1207
 
/*           fileCnt++; */
1208
 
/*         else { */
1209
 
/*           sprintf(&(err_msg[0]), "syntax error"); */
1210
 
/*           goto err_return; */
1211
 
/*         } */
1212
 
/*       } */
1213
 
/*       else */
1214
 
/*         byteCnt++; */
1215
 
/*     } */
1216
 
/*     /\* calculate the number of bytes to allocate *\/ */
1217
 
/*     byteCnt += ((size_t) 256 * sizeof(CsoundOpcodePluginFile_t*)); */
1218
 
/*     byteCnt += ((size_t) 256 * sizeof(CsoundPluginOpcode_t*)); */
1219
 
/*     byteCnt += (fileCnt * sizeof(CsoundOpcodePluginFile_t)); */
1220
 
/*     byteCnt = (byteCnt + (size_t) 15) & (~((size_t) 15)); */
1221
 
/*     byteCnt += (opcodeCnt * sizeof(CsoundPluginOpcode_t)); */
1222
 
/*     byteCnt += (fileCnt * (strlen(dname) */
1223
 
/* #if defined(WIN32) */
1224
 
/*                 + (size_t) 6        /\* "\\NAME.dll\0" *\/ */
1225
 
/* #elif defined(__MACH__) */
1226
 
/*                 + (size_t) 11       /\* "/libNAME.dylib\0" *\/ */
1227
 
/* #else */
1228
 
/*                 + (size_t) 8        /\* "/libNAME.so\0" *\/ */
1229
 
/* #endif */
1230
 
/*                 )); */
1231
 
/*     byteCnt += opcodeCnt; */
1232
 
/*     /\* allocate and set up database *\/ */
1233
 
/*     p = csound->Calloc(csound, byteCnt); */
1234
 
/*     csound->pluginOpcodeFiles = p; */
1235
 
/*     n = (size_t) 256 * sizeof(CsoundOpcodePluginFile_t*); */
1236
 
/*     csound->pluginOpcodeDB = (void*) &(((char*) p)[n]); */
1237
 
/*     n += ((size_t) 256 * sizeof(CsoundPluginOpcode_t*)); */
1238
 
/*     p1 = (void*) &(((char*) p)[n]); */
1239
 
/*     n += (fileCnt * sizeof(CsoundOpcodePluginFile_t)); */
1240
 
/*     n = (n + (size_t) 15) & (~((size_t) 15)); */
1241
 
/*     p2 = (void*) &(((char*) p)[n]); */
1242
 
/*     n += (opcodeCnt * sizeof(CsoundPluginOpcode_t)); */
1243
 
/*     sp = &(((char*) p)[n]); */
1244
 
/*     currentFile = (CsoundOpcodePluginFile_t*) NULL; */
1245
 
/*     i = (size_t) 0; */
1246
 
/*     while (i < fileLen) { */
1247
 
/*       if (fileData[i] == (char) ' ' || fileData[i] == (char) '\t' || */
1248
 
/*           fileData[i] == (char) '\r' || fileData[i] == (char) '\n') { */
1249
 
/*         i++; */
1250
 
/*         continue; */
1251
 
/*       } */
1252
 
/*       s = &(fileData[i]); */
1253
 
/*       n = strlen(s); */
1254
 
/*       i += (n + (size_t) 1); */
1255
 
/*       if (s[n - 1] != (char) ':') { */
1256
 
/*         /\* add opcode entry *\/ */
1257
 
/*         CsoundPluginOpcode_t  *op_; */
1258
 
/*         op_ = (CsoundPluginOpcode_t*) p2; */
1259
 
/*         p2 = (void*) ((char*) p2 + (long) sizeof(CsoundPluginOpcode_t)); */
1260
 
/*         strcpy(sp, s); */
1261
 
/*         op_->opname = sp; */
1262
 
/*         sp += ((long) strlen(s) + 1L); */
1263
 
/*         op_->fp = currentFile; */
1264
 
/*         if (csoundLoadOpcodeDB_AddOpcode(csound, op_) != 0) { */
1265
 
/*           sprintf(&(err_msg[0]), "duplicate opcode name"); */
1266
 
/*           goto err_return; */
1267
 
/*         } */
1268
 
/*       } */
1269
 
/*       else { */
1270
 
/*         /\* add file entry *\/ */
1271
 
/*         CsoundOpcodePluginFile_t  *fp_; */
1272
 
/*         fp_ = (CsoundOpcodePluginFile_t*) p1; */
1273
 
/*         p1 = (void*) ((char*) p1 + (long) sizeof(CsoundOpcodePluginFile_t)); */
1274
 
/*         s[n - 1] = (char) 0; */
1275
 
/*         strcpy(sp, dname); */
1276
 
/*         n = strlen(dname); */
1277
 
/*         if (sp[n - 1] == (char) DIRSEP) */
1278
 
/*           n--; */
1279
 
/*         fp_->fullName = sp; */
1280
 
/*         sp = (char*) fp_->fullName + (long) n; */
1281
 
/* #if defined(WIN32) */
1282
 
/*         sprintf(sp, "\\%s.dll", s); */
1283
 
/* #elif defined(__MACH__) */
1284
 
/*         sprintf(sp, "/lib%s.dylib", s); */
1285
 
/* #else */
1286
 
/*         sprintf(sp, "%clib%s.so", DIRSEP, s); */
1287
 
/* #endif */
1288
 
/*         fp_->fname = &(sp[1]); */
1289
 
/*         sp = (char*) strchr(fp_->fname, '\0') + 1L; */
1290
 
/*         if (csoundLoadOpcodeDB_AddFile(csound, fp_) != 0) { */
1291
 
/*           sprintf(&(err_msg[0]), "duplicate file name"); */
1292
 
/*           goto err_return; */
1293
 
/*         } */
1294
 
/*         currentFile = fp_; */
1295
 
/*       } */
1296
 
/*       if ((size_t) ((char*) sp - (char*) p) > byteCnt) */
1297
 
/*         csound->Die(csound, Str(" *** internal error while " */
1298
 
/*                                 "loading opcode database file")); */
1299
 
/*     } */
1300
 
/*     /\* clean up *\/ */
1301
 
/*     csound->Free(csound, fileData); */
1302
 
/*     /\* plugin opcode database has been successfully loaded *\/ */
1303
 
/*     return 0; */
1304
 
 
1305
 
/*  err_return: */
1306
 
/*     if (fileData) */
1307
 
/*       csound->Free(csound, fileData); */
1308
 
/*     if (fd) */
1309
 
/*       csound->FileClose(csound, fd); */
1310
 
/*     csoundDestroyOpcodeDB(csound); */
1311
 
/*     csound->ErrorMsg(csound, Str(" *** error loading opcode database file: "), */
1312
 
/*                              Str(&(err_msg[0]))); */
1313
 
/*     return -1; */
1314
 
/* } */
1315
 
 
1316
 
/* load all pending opcode plugin libraries */
1317
 
/* called when listing opcodes (-z) */
1318
 
 
1319
1089
int csoundLoadAllPluginOpcodes(CSOUND *csound)
1320
1090
{
1321
1091
    CsoundOpcodePluginFile_t    *p;
1349
1119
#ifdef __cplusplus
1350
1120
}
1351
1121
#endif
1352