+ // This routine is shared by LoadInclude after it builds the image
+ return AddToProcessingList(ptr, fname, nullStr, 0);
+}
+
+
+//
+// What it says on the tin: check for a .o suffix on the passed in string
+//
+uint8_t HasDotOSuffix(char * s)
+{
+ char * temp = strrchr(s, '.');
+
+ if ((temp == NULL) || (strncmp(temp, ".o", 2) != 0))
+ return 0;
+
+ return 1;
+}
+
+
+//
+// Process an ar archive file (*.a)
+//
+int LoadArchive(char * fname, int fd)
+{
+ // Read in the archive file to memory and process
+ long size = FileSize(fd);
+ char * ptr = malloc(size);
+ char * endPtr = ptr + size;
+ char * longFilenames = NULL;
+
+ if (ptr == NULL)
+ {
+ printf("Out of memory while processing %s\n", fname);
+ close(fd);
+ return 1;
+ }
+
+ if (read(fd, ptr, size) != size)
+ {
+ printf("File read error on %s\n", fname);
+ close(fd);
+ free(ptr);
+ return 1;
+ }
+
+ close(fd);
+
+ // Save the pointer for later...
+ arPtr[arIndex++] = ptr;
+ char objName[FNLEN];
+ char objSize[11];
+ int i;
+//printf("\nProcessing AR file \"%s\"...\n", fname);
+ ptr += 8;
+
+ // Loop through all objects in the archive and process them
+ do
+ {
+ memset(objName, 0, 17);
+ objSize[10] = 0;
+
+ for(i=0; i<16; i++)
+ {
+// if ((ptr[i] == '/') || (ptr[i] == ' '))
+ if ((ptr[i] == ' ') && (i != 0))
+ {
+ objName[i] = 0;
+ break;
+ }
+
+ objName[i] = ptr[i];
+ }
+
+ for(i=0; i<10; i++)
+ {
+ if (ptr[48 + i] == ' ')
+ {
+ objSize[i] = 0;
+ break;
+ }
+
+ objSize[i] = ptr[48 + i];
+ }
+
+ // Check to see if a long filename was requested
+ if (objName[0] == 0x20)
+ {
+ uint32_t fnSize = atoi(objName + 1);
+
+ if (longFilenames != NULL)
+ {
+ i = 0;
+ char * currentFilename = longFilenames + fnSize;
+
+ while (*currentFilename != 0x0A)
+ objName[i++] = *currentFilename++;
+
+ objName[i] = 0;
+ }
+ }
+
+ if ((strncmp(objName, "ARFILENAMES/", 12) == 0) || (strncmp(objName, "//", 2) == 0))
+ {
+ longFilenames = ptr + 60;
+ }
+ else if (HasDotOSuffix(objName))
+ {
+
+ // Strip off any trailing forward slash at end of object name
+ int lastChar = strlen(objName) - 1;
+
+ if (objName[lastChar] == '/')
+ objName[lastChar] = 0;
+
+//printf("Processing object \"%s\" (size == %i, obj_index == %i)...\n", objName, atoi(objSize), obj_index);
+ strcpy(obj_fname[obj_index], objName);
+ obj_segsize[obj_index][0] = (GetLong(ptr + 60 + 4) + secalign) & ~secalign;
+ obj_segsize[obj_index][1] = (GetLong(ptr + 60 + 8) + secalign) & ~secalign;
+ obj_segsize[obj_index][2] = (GetLong(ptr + 60 + 12) + secalign) & ~secalign;
+ obj_index++;
+
+ if (AddToProcessingList(ptr + 60, objName, fname, 1))
+ return 1;
+ }
+
+ uint32_t size = atoi(objSize);
+ size += (size & 0x01 ? 1 : 0);
+ ptr += 60 + size;
+ }
+ while (ptr < endPtr);
+
+ return 0;