Exemplo n.º 1
0
int HumdrumFileBasic::predictNewSpineCount(HumdrumRecord& aRecord) {
   int output = 0;
   int spinecount = aRecord.getFieldCount();
   int subcount;
   int i;
   int j;
   for (i=0; i<spinecount; i++) {
      if (strcmp("*^", aRecord[i]) == 0) {
         output += 2;
      } else if (strcmp("*-", aRecord[i]) == 0) {
         output = output;
      } else if (strcmp("*+", aRecord[i]) == 0) {
         output += 2;
      } else if (strcmp("*x", aRecord[i]) == 0) {
         output++;
      } else if (strcmp("*v", aRecord[i]) == 0) {
         subcount = 1;
         for (j=i+1; j<spinecount; j++) {
            if (strcmp("*v", aRecord[j]) == 0) {
               subcount++;
            } else {
               break;
            }
         }
         if (subcount == 1) {
            cout << "Error: single *v pathindicator on line: " 
                 << aRecord.getLineNum() << "\n"
                 << aRecord.getLine()
                 << endl;
            exit(1);
         }
         output++;
         i = j-1;
      } else {
         output++;
      }
   }

   return output;
}
Exemplo n.º 2
0
void HumdrumFileBasic::makeNewSpineInfo(SigCollection<char*>&spineinfo, 
   HumdrumRecord& aRecord, int newsize, int& spineid,
   SigCollection<int>& ex) {

   SigCollection<char*> newinfo;
   newinfo.setSize(newsize);
   int i, j;
   for (i=0; i<newsize; i++) {
      newinfo[i] = new char[1024];
      newinfo[i][0] = '\0';
   }

   int spinecount = aRecord.getFieldCount();
   int subcount;
   int inindex = 0;
   int outindex = 0;

   for (inindex=0; inindex<spinecount; inindex++) {
      if (strcmp("*^", aRecord[inindex]) == 0) {
         strcpy(newinfo[outindex], "(");
         strcat(newinfo[outindex], spineinfo[inindex]);
         strcat(newinfo[outindex], ")a");
         outindex++;
         strcpy(newinfo[outindex], "(");
         strcat(newinfo[outindex], spineinfo[inindex]);
         strcat(newinfo[outindex], ")b");
         outindex++;
      } else if (strcmp("*-", aRecord[inindex]) == 0) {
         // don't increment outindex
      } else if (strcmp("*+", aRecord[inindex]) == 0) {
         strcpy(newinfo[outindex], spineinfo[inindex]);
         outindex++;
         spineid++;
         sprintf(newinfo[outindex], "%d", spineid);
         outindex++;
      } else if (strcmp("*x", aRecord[inindex]) == 0) {
         strcpy(newinfo[outindex], spineinfo[inindex+1]);
         outindex++;
         strcpy(newinfo[outindex], spineinfo[inindex]);
         outindex++;
         inindex++;
      } else if (strcmp("*v", aRecord[inindex]) == 0) {
         subcount = 1;
         strcpy(newinfo[outindex], spineinfo[inindex]);
         for (j=inindex+1; j<spinecount; j++) {
            if (strcmp("*v", aRecord[j]) == 0) {
               subcount++;
               if (subcount > 1) {
                  strcat(newinfo[outindex], " ");
                  strcat(newinfo[outindex], spineinfo[inindex+subcount-1]);
                  simplifySpineString(newinfo[outindex]);
               } 
            } else {
               break;
            }
         }
         if (subcount == 1) {
            cout << "Error: single *v path indicator on line: " 
                 << aRecord.getLineNum() << "\n"
                 << aRecord.getLine()
                 << endl;
            exit(1);
         } else {
            inindex += subcount-1;   
         }
         // check to see if the spine info can be simplified:
         simplifySpineInfo(newinfo, outindex);    

         outindex++;
      } else if (strncmp("**", aRecord[inindex], 2) == 0) {
         int value;
         value = Convert::exint.getValue(aRecord[inindex]);
         if (spineid != ex.getSize()) {
            cout << "Error in exclusive interpretation allocation" 
                 << endl;
            exit(1);
         }
         if (value == E_unknown) {
            value = Convert::exint.add(aRecord[inindex]);
            ex.append(value);
         } else {
            ex.append(value);
         }
         strcpy(newinfo[outindex], spineinfo[inindex]);
         outindex++;
      } else {
         strcpy(newinfo[outindex], spineinfo[inindex]);
         outindex++;
      }
   }

   if (outindex != newinfo.getSize()) {
      cout << "Error in HumdrumFileBasic path parsing" << endl;
      exit(1);
   }

   if (inindex != spineinfo.getSize()) {
      cout << "Error in HumdrumFileBasic path parsing" << endl;
      exit(1);
   }

   // delete the old information:
   for (i=0; i<spineinfo.getSize(); i++) {
      if (spineinfo[i] != NULL) {
         delete [] spineinfo[i];
         spineinfo[i] = NULL;
      }
   }
   spineinfo.setSize(newinfo.getSize());

   // copy the new spine path indicators
   int length;
   for (i=0; i<spineinfo.getSize(); i++) {
      length = strlen(newinfo[i]);
      spineinfo[i] = new char[length + 1];
      strcpy(spineinfo[i], newinfo[i]);
      delete [] newinfo[i];
      newinfo[i] = NULL;
   }

   newinfo.setSize(0);
}
Exemplo n.º 3
0
void HumdrumFileBasic::readjustDotArrays(Array<int>& lastline, 
      Array<int>& lastspine, HumdrumRecord& record, int newsize) {

   Array<int> newline;
   Array<int> newspine;
   newline.setSize(newsize);
   newspine.setSize(newsize);
   newline.allowGrowth(0);
   newspine.allowGrowth(0);

   int i, j;
   for (i=0; i<newsize; i++) {
      newline[i] = -1;
      newspine[i] = -1;
   }

   int spinecount = record.getFieldCount();
   int subcount;
   int inindex = 0;
   int outindex = 0;

   for (inindex=0; inindex<spinecount; inindex++) {
      if (strcmp("*^", record[inindex]) == 0) {
         newline[outindex] = lastline[inindex];
         newspine[outindex] = lastspine[inindex];
         outindex++;
         newline[outindex] = lastline[inindex];
         newspine[outindex] = lastspine[inindex];
         outindex++;
      } else if (strcmp("*-", record[inindex]) == 0) {
         // don't increment outindex
      } else if (strcmp("*+", record[inindex]) == 0) {
         newline[outindex] = lastline[inindex];
         newspine[outindex] = lastline[inindex];
         outindex++;
         newline[outindex] = -1;
         newspine[outindex] = -1;
         outindex++;
      } else if (strcmp("*x", record[inindex]) == 0) {
         newline[outindex] = lastline[inindex+1];
         newspine[outindex] = lastspine[inindex+1];
         newline[outindex+1] = lastline[inindex];
         newspine[outindex+1] = lastspine[inindex];
         outindex+=2;
         inindex++;
      } else if (strcmp("*v", record[inindex]) == 0) {
         subcount = 1;
         newline[outindex] = lastline[outindex];
         newspine[outindex] = lastspine[outindex];
         for (j=inindex+1; j<spinecount; j++) {
            if (strcmp("*v", record[j]) == 0) {
               subcount++;
               if (subcount > 1) {
                  newline[outindex] = lastline[inindex+subcount-1];
                  newspine[outindex] = lastspine[inindex+subcount-1];
               } 
            } else {
               break;
            }
         }
         if (subcount == 1) {
            cout << "Error: single *v path indicator on line: " 
                 << record.getLineNum() << "\n"
                 << record.getLine()
                 << endl;
            exit(1);
         } else {
            inindex += subcount-1;   
         }
         outindex++;
      } else if (strncmp("**", record[inindex], 2) == 0) {
         newline[outindex] = -1;
         newspine[outindex] = -1;
         outindex++;
      } else {
         newline[outindex] = lastline[inindex];
         newspine[outindex] = lastspine[inindex];
         outindex++;
      }
   }

   if (outindex != newline.getSize()) {
      cout << "Error in HumdrumFileBasic path parsing" << endl;
      exit(1);
   }

   if (inindex != lastline.getSize()) {
      cout << "Error in HumdrumFileBasic path parsing" << endl;
      exit(1);
   }

   // copy the new information
   lastline.setSize(newline.getSize());
   lastspine.setSize(newspine.getSize());
   for (i=0; i<newline.getSize(); i++) {
      lastline[i] = newline[i];
      lastspine[i] = newspine[i];
   }

}