file.cpp

changeset 117
7eb7a43a511b
parent 116
4fde8fdf258a
child 127
a6e2067bb2f1
equal deleted inserted replaced
116:4fde8fdf258a 117:7eb7a43a511b
57 57
58 if (~io_ldpath.value) { 58 if (~io_ldpath.value) {
59 // Try with just the LDraw path first 59 // Try with just the LDraw path first
60 zFilePath = format ("%s" DIRSLASH "%s", 60 zFilePath = format ("%s" DIRSLASH "%s",
61 io_ldpath.value.chars(), zTruePath.chars()); 61 io_ldpath.value.chars(), zTruePath.chars());
62 printf ("try %s\n", zFilePath.chars()); 62 logf ("Trying %s\n", zFilePath.chars());
63 63
64 fp = fopen (zFilePath, "r"); 64 fp = fopen (zFilePath, "r");
65 if (fp != null) 65 if (fp != null)
66 return fp; 66 return fp;
67 67
561 return; // was not found 561 return; // was not found
562 562
563 // Erase it from memory 563 // Erase it from memory
564 objects.erase (objects.begin() + ulIndex); 564 objects.erase (objects.begin() + ulIndex);
565 } 565 }
566
567 // =============================================================================
568 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
569 // =============================================================================
570 std::vector<partListEntry> g_PartList;
571
572 void initPartList () {
573 logf ("%s: initializing parts.lst\n", __func__);
574
575 FILE* fp = openLDrawFile ("parts.lst", false);
576
577 if (!fp)
578 return;
579
580 char sLine[1024];
581 while (fgets (sLine, sizeof sLine, fp)) {
582 // Locate the first whitespace
583 char* cpWhite = strstr (sLine, " ");
584
585 char sName[65];
586 size_t uLength = (cpWhite - sLine);
587
588 if (uLength >= 64)
589 continue; // too long
590
591 strncpy (sName, sLine, uLength);
592 sName[uLength] = '\0';
593
594 // Surf through the whitespace sea!
595 while (*cpWhite == ' ')
596 cpWhite++;
597
598 // Get the end point
599 char* cpEnd = strstr (sLine, "\r");
600
601 if (cpEnd == null) {
602 // must not be DOS-formatted
603 cpEnd = strstr (sLine, "\n");
604 }
605
606 assert (cpEnd != null);
607
608 // Make the file title now
609 char sTitle[81];
610 uLength = (cpEnd - cpWhite);
611 strncpy (sTitle, cpWhite, uLength);
612 sTitle[uLength] = '\0';
613
614 // Add it to the array.
615 partListEntry entry;
616 strcpy (entry.sName, sName);
617 strcpy (entry.sTitle, sTitle);
618 g_PartList.push_back (entry);
619 }
620 }

mercurial