1077
/* static CS_NOINLINE int csoundLoadOpcodeDB_AddFile(CSOUND *csound, */
1078
/* CsoundOpcodePluginFile_t *fp) */
1080
/* CsoundOpcodePluginFile_t **pp, *p; */
1081
/* unsigned char h; */
1083
/* pp = (CsoundOpcodePluginFile_t**) csound->pluginOpcodeFiles; */
1084
/* h = name_hash_2(csound, fp->fname); */
1087
/* /\* check for a name conflict *\/ */
1088
/* if (!sCmp(p->fname, fp->fname)) */
1092
/* fp->nxt = pp[h]; */
1093
/* fp->isLoaded = -1; */
1098
/* static CS_NOINLINE int csoundLoadOpcodeDB_AddOpcode(CSOUND *csound, */
1099
/* CsoundPluginOpcode_t *op) */
1101
/* CsoundPluginOpcode_t **pp, *p; */
1102
/* unsigned char h; */
1104
/* pp = (CsoundPluginOpcode_t**) csound->pluginOpcodeDB; */
1105
/* h = name_hash_2(csound, op->opname); */
1108
/* /\* check for a name conflict *\/ */
1109
/* if (!sCmp(p->opname, op->opname)) */
1113
/* op->nxt = pp[h]; */
1118
/* void csoundDestroyOpcodeDB(CSOUND *csound) */
1122
/* p = csound->pluginOpcodeFiles; */
1123
/* csound->pluginOpcodeFiles = NULL; */
1124
/* csound->pluginOpcodeDB = NULL; */
1125
/* csound->Free(csound, p); */
1128
/* load opcodes.dir from the specified directory, and set up database */
1130
/* int csoundLoadOpcodeDB(CSOUND *csound, const char *dname) */
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; */
1140
/* /\* check file name *\/ */
1141
/* if (dname == NULL || dname[0] == (char) 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) */
1150
/* if (fseek(fp, 0L, SEEK_END) != 0) { */
1151
/* sprintf(&(err_msg[0]), "seek error"); */
1152
/* goto err_return; */
1154
/* fileLen = (size_t) ftell(fp); */
1155
/* fseek(fp, 0L, SEEK_SET); */
1156
/* if (fileLen == (size_t) 0) { */
1157
/* csound->FileClose(csound, fd); */
1160
/* fileData = (char*) csound->Malloc(csound, fileLen + (size_t) 1); */
1161
/* n = fread(fileData, (size_t) 1, fileLen, fp); */
1162
/* csound->FileClose(csound, fd); */
1164
/* if (n != fileLen) { */
1165
/* sprintf(&(err_msg[0]), "read error"); */
1166
/* goto err_return; */
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; */
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) */
1179
/* fileData[i] = (char) 0; */
1180
/* if (fileData[i - 1] != ':') { */
1181
/* if (!fileCnt) { */
1182
/* sprintf(&(err_msg[0]), "syntax error"); */
1183
/* goto err_return; */
1187
/* #if !(defined(LINUX) || defined(__unix__) || defined(__MACH__)) */
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]); */
1200
/* if (n >= fileLen) */
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')) */
1209
/* sprintf(&(err_msg[0]), "syntax error"); */
1210
/* goto err_return; */
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" *\/ */
1228
/* + (size_t) 8 /\* "/libNAME.so\0" *\/ */
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') { */
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; */
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) */
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); */
1286
/* sprintf(sp, "%clib%s.so", DIRSEP, s); */
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; */
1294
/* currentFile = fp_; */
1296
/* if ((size_t) ((char*) sp - (char*) p) > byteCnt) */
1297
/* csound->Die(csound, Str(" *** internal error while " */
1298
/* "loading opcode database file")); */
1300
/* /\* clean up *\/ */
1301
/* csound->Free(csound, fileData); */
1302
/* /\* plugin opcode database has been successfully loaded *\/ */
1307
/* csound->Free(csound, fileData); */
1309
/* csound->FileClose(csound, fd); */
1310
/* csoundDestroyOpcodeDB(csound); */
1311
/* csound->ErrorMsg(csound, Str(" *** error loading opcode database file: "), */
1312
/* Str(&(err_msg[0]))); */
1316
/* load all pending opcode plugin libraries */
1317
/* called when listing opcodes (-z) */
1319
1089
int csoundLoadAllPluginOpcodes(CSOUND *csound)
1321
1091
CsoundOpcodePluginFile_t *p;