| 77 | } |
| 78 | |
| 79 | int main(int argc, char *argv[]) |
| 80 | { |
| 81 | SHPHandle inSHP,outSHP; /* ---- Shapefile file pointers ---- */ |
| 82 | DBFHandle inDBF,outDBF; /* ---- DBF file pointers ---- */ |
| 83 | sortStruct *array; |
| 84 | shapeObj shape; |
| 85 | int shpType, nShapes; |
| 86 | int fieldNumber=-1; /* ---- Field number of item to be sorted on ---- */ |
| 87 | DBFFieldType dbfField; |
| 88 | char fName[20]; |
| 89 | int fWidth,fnDecimals; |
| 90 | char buffer[1024]; |
| 91 | int i,j; |
| 92 | int num_fields, num_records; |
| 93 | |
| 94 | if(argc > 1 && strcmp(argv[1], "-v") == 0) { |
| 95 | printf("%s\n", msGetVersion()); |
| 96 | exit(0); |
| 97 | } |
| 98 | |
| 99 | /* ------------------------------------------------------------------------------- */ |
| 100 | /* Check the number of arguments, return syntax if not correct */ |
| 101 | /* ------------------------------------------------------------------------------- */ |
| 102 | if( argc != 5 ) { |
| 103 | fprintf(stderr,"Syntax: sortshp [infile] [outfile] [item] [ascending|descending]\n" ); |
| 104 | exit(1); |
| 105 | } |
| 106 | |
| 107 | msSetErrorFile("stderr", NULL); |
| 108 | |
| 109 | /* ------------------------------------------------------------------------------- */ |
| 110 | /* Open the shapefile */ |
| 111 | /* ------------------------------------------------------------------------------- */ |
| 112 | inSHP = msSHPOpen(argv[1], "rb" ); |
| 113 | if( !inSHP ) { |
| 114 | fprintf(stderr,"Unable to open %s shapefile.\n",argv[1]); |
| 115 | exit(1); |
| 116 | } |
| 117 | msSHPGetInfo(inSHP, &nShapes, &shpType); |
| 118 | |
| 119 | /* ------------------------------------------------------------------------------- */ |
| 120 | /* Open the dbf file */ |
| 121 | /* ------------------------------------------------------------------------------- */ |
| 122 | snprintf(buffer, sizeof(buffer), "%s.dbf",argv[1]); |
| 123 | inDBF = msDBFOpen(buffer,"rb"); |
| 124 | if( inDBF == NULL ) { |
| 125 | fprintf(stderr,"Unable to open %s XBASE file.\n",buffer); |
| 126 | exit(1); |
| 127 | } |
| 128 | |
| 129 | num_fields = msDBFGetFieldCount(inDBF); |
| 130 | num_records = msDBFGetRecordCount(inDBF); |
| 131 | |
| 132 | for(i=0;i<num_fields;i++) { |
| 133 | msDBFGetFieldInfo(inDBF,i,fName,NULL,NULL); |
| 134 | if(strncasecmp(argv[3],fName,strlen(argv[3])) == 0) { /* ---- Found it ---- */ |
| 135 | fieldNumber = i; |
| 136 | break; |
nothing calls this directly
no test coverage detected