MCPcopy Index your code
hub / github.com/MapServer/MapServer / main

Function main

sortshp.c:79–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79int 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;

Callers

nothing calls this directly

Calls 15

msGetVersionFunction · 0.85
msSetErrorFileFunction · 0.85
msSHPOpenFunction · 0.85
msSHPGetInfoFunction · 0.85
msDBFOpenFunction · 0.85
msDBFGetFieldCountFunction · 0.85
msDBFGetRecordCountFunction · 0.85
msDBFGetFieldInfoFunction · 0.85
strncasecmpFunction · 0.85
strlcpyFunction · 0.85
msDBFReadStringAttributeFunction · 0.85
msDBFReadDoubleAttributeFunction · 0.85

Tested by

no test coverage detected