| 660 | } |
| 661 | |
| 662 | int msWriteTree(treeObj *tree, char *filename, int B_order) |
| 663 | { |
| 664 | char signature[3] = "SQT"; |
| 665 | char version = 1; |
| 666 | char reserved[3] = {0,0,0}; |
| 667 | SHPTreeHandle disktree; |
| 668 | int i; |
| 669 | char mtBigEndian; |
| 670 | char pabyBuf[32]; |
| 671 | char *pszBasename, *pszFullname; |
| 672 | |
| 673 | |
| 674 | disktree = (SHPTreeHandle) malloc(sizeof(SHPTreeInfo)); |
| 675 | MS_CHECK_ALLOC(disktree, sizeof(SHPTreeInfo), MS_FALSE); |
| 676 | |
| 677 | /* -------------------------------------------------------------------- */ |
| 678 | /* Compute the base (layer) name. If there is any extension */ |
| 679 | /* on the passed in filename we will strip it off. */ |
| 680 | /* -------------------------------------------------------------------- */ |
| 681 | pszBasename = (char *) msSmallMalloc(strlen(filename)+5); |
| 682 | strcpy( pszBasename, filename ); |
| 683 | for( i = strlen(pszBasename)-1; |
| 684 | i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' |
| 685 | && pszBasename[i] != '\\'; |
| 686 | i-- ) {} |
| 687 | |
| 688 | if( pszBasename[i] == '.' ) |
| 689 | pszBasename[i] = '\0'; |
| 690 | |
| 691 | /* -------------------------------------------------------------------- */ |
| 692 | /* Open the .shp and .shx files. Note that files pulled from */ |
| 693 | /* a PC to Unix with upper case filenames won't work! */ |
| 694 | /* -------------------------------------------------------------------- */ |
| 695 | pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5); |
| 696 | sprintf( pszFullname, "%s%s", pszBasename, MS_INDEX_EXTENSION); |
| 697 | disktree->fp = fopen(pszFullname, "wb"); |
| 698 | |
| 699 | msFree(pszBasename); /* not needed */ |
| 700 | msFree(pszFullname); |
| 701 | |
| 702 | if(!disktree->fp) { |
| 703 | msFree(disktree); |
| 704 | msSetError(MS_IOERR, NULL, "msWriteTree()"); |
| 705 | return(MS_FALSE); |
| 706 | } |
| 707 | |
| 708 | |
| 709 | /* for efficiency, trim the tree */ |
| 710 | msTreeTrim(tree); |
| 711 | |
| 712 | /* -------------------------------------------------------------------- */ |
| 713 | /* Establish the byte order on this machine. */ |
| 714 | /* -------------------------------------------------------------------- */ |
| 715 | i = 1; |
| 716 | if( *((uchar *) &i) == 1 ) |
| 717 | mtBigEndian = MS_FALSE; |
| 718 | else |
| 719 | mtBigEndian = MS_TRUE; |
no test coverage detected