Subversion Repositories public

Rev

Rev 93 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 93 Rev 136
Line 1067... Line 1067...
1067
    GETU32(size);
1067
    GETU32(size);
1068
    if ( id == list->id ) {
1068
    if ( id == list->id ) {
1069
      garmin_list_append(list,garmin_unpack(pos,type));
1069
      garmin_list_append(list,garmin_unpack(pos,type));
1070
    } else {
1070
    } else {
1071
      /* list element has wrong list ID */
1071
      /* list element has wrong list ID */
-
 
1072
      char hv0[256];
1072
      printf("garmin_unpack_dlist: list element had ID %d, expected ID %d\n",
1073
      sprintf(hv0, "garmin_unpack_dlist: list element had ID %d, expected ID %d!",
1073
	     id,list->id);
1074
	     id,list->id);
-
 
1075
      garmin_queue_error(hv0, err_error);
1074
    }
1076
    }
1075
  }
1077
  }
1076
}
1078
}
1077
 
1079
 
1078
 
1080
 
Line 1086... Line 1088...
1086
  uint32        unpacked;
1088
  uint32        unpacked;
1087
  uint32        version;
1089
  uint32        version;
1088
  uint32        size;
1090
  uint32        size;
1089
  uint32        type;
1091
  uint32        type;
1090
  uint32        chunk;
1092
  uint32        chunk;
-
 
1093
  char          hv0[256];
1091
 
1094
 
1092
  /* First, read the header and check that it's satisfactory. */
1095
  /* First, read the header and check that it's satisfactory. */
1093
  
1096
  
1094
  if ( memcmp(*pos,GARMIN_MAGIC,strlen(GARMIN_MAGIC)) == 0 ) {
1097
  if ( memcmp(*pos,GARMIN_MAGIC,strlen(GARMIN_MAGIC)) == 0 ) {
1095
    SKIP(12);
1098
    SKIP(12);
1096
    GETU32(version);
1099
    GETU32(version);
1097
    
1100
    
1098
    if ( version > GARMIN_VERSION ) {
1101
    if ( version > GARMIN_VERSION ) {
1099
      /* warning: version is more recent than supported. */
1102
      /* warning: version is more recent than supported. */
1100
      printf("garmin_unpack_chunk: version %.2f supported, %.2f found\n",
1103
      sprintf(hv0, "garmin_unpack_chunk: version %.2f supported, %.2f found!",
1101
	     GARMIN_VERSION/100.0, version/100.0);
1104
	     GARMIN_VERSION/100.0, version/100.0);
-
 
1105
      garmin_queue_error(hv0, err_warning);
1102
    }
1106
    }
1103
    
1107
    
1104
    /* This is the size of the packed data (not including the header) */
1108
    /* This is the size of the packed data (not including the header) */
1105
    
1109
    
1106
    GETU32(size);
1110
    GETU32(size);
Line 1116... Line 1120...
1116
    data     = garmin_unpack(pos,type);
1120
    data     = garmin_unpack(pos,type);
1117
    unpacked = *pos - start;
1121
    unpacked = *pos - start;
1118
 
1122
 
1119
    /* Double check - did we unpack the number of bytes we were supposed to? */
1123
    /* Double check - did we unpack the number of bytes we were supposed to? */
1120
 
1124
 
1121
    if ( unpacked != chunk ) {      
1125
    if ( unpacked != chunk ) {
1122
      /* unpacked the wrong number of bytes! */
1126
      /* unpacked the wrong number of bytes! */
1123
      printf("garmin_unpack_chunk: unpacked %d bytes (expecting %d)\n",
1127
      sprintf(hv0, "garmin_unpack_chunk: unpacked %d bytes (expecting %d)!",
1124
	     unpacked,chunk);
1128
	     unpacked,chunk);
-
 
1129
      garmin_queue_error(hv0, err_error);
1125
    }
1130
    }
1126
    
-
 
1127
  } else {
1131
  } else {
1128
    /* unknown file format */
1132
    /* unknown file format */
1129
    printf("garmin_unpack_chunk: not a .gmn file\n");
1133
    sprintf(hv0, "garmin_unpack_chunk: not a .gmn file!");
-
 
1134
    garmin_queue_error(hv0, err_fatal);
1130
  }
1135
  }
1131
 
1136
 
1132
  return data;
1137
  return data;
1133
}
1138
}
1134
 
1139
 
Line 1147... Line 1152...
1147
  uint8 *       buf;
1152
  uint8 *       buf;
1148
  uint8 *       pos;
1153
  uint8 *       pos;
1149
  uint8 *       start;
1154
  uint8 *       start;
1150
  struct stat   sb;
1155
  struct stat   sb;
1151
  int           fd;
1156
  int           fd;
-
 
1157
  char          hv0[1024];
1152
 
1158
 
1153
  if ( (fd = open(filename,O_RDONLY)) != -1 ) {
1159
  if ( (fd = open(filename,O_RDONLY)) != -1 ) {
1154
    if ( fstat(fd,&sb) != -1 ) {
1160
    if ( fstat(fd,&sb) != -1 ) {
1155
      if ( (buf = malloc(sb.st_size)) != NULL ) {
1161
      if ( (buf = malloc(sb.st_size)) != NULL ) {
1156
	if ( (bytes = read(fd,buf,sb.st_size)) == sb.st_size ) {
1162
	if ( (bytes = read(fd,buf,sb.st_size)) == sb.st_size ) {
Line 1160... Line 1166...
1160
	  while ( pos - buf < bytes ) {
1166
	  while ( pos - buf < bytes ) {
1161
	    start = pos;
1167
	    start = pos;
1162
	    garmin_list_append(list,garmin_unpack_chunk(&pos));
1168
	    garmin_list_append(list,garmin_unpack_chunk(&pos));
1163
	    if ( pos == start ) {
1169
	    if ( pos == start ) {
1164
	      /* did not unpack anything! */
1170
	      /* did not unpack anything! */
1165
	      printf("garmin_load:  %s: nothing unpacked!\n",filename);
1171
	      sprintf(hv0, "garmin_load:  %s: nothing unpacked!",filename);
-
 
1172
	      garmin_queue_error(hv0, err_error);
1166
	      break;
1173
	      break;
1167
	    }
1174
	    }
1168
	  }
1175
	  }
1169
 
1176
 
1170
	  /* 
1177
	  /* 
Line 1176... Line 1183...
1176
	    data = list->head->data;
1183
	    data = list->head->data;
1177
	    list->head->data = NULL;
1184
	    list->head->data = NULL;
1178
	    garmin_free_data(data_l);
1185
	    garmin_free_data(data_l);
1179
	  } else {
1186
	  } else {
1180
	    data = data_l;
1187
	    data = data_l;
1181
	  }	     
1188
	  }
1182
 
1189
 
1183
	} else {
1190
	} else {
1184
	  /* read failed */
1191
	  /* read failed */
1185
	  printf("%s: read: %s\n",filename,strerror(errno));
1192
	  sprintf(hv0, "%s: read: %s!",filename,strerror(errno));
-
 
1193
	  garmin_queue_error(hv0, err_error);
1186
	}
1194
	}
1187
	free(buf);
1195
	free(buf);
1188
      } else {
1196
      } else {
1189
	/* malloc failed */
1197
	/* malloc failed */
1190
	printf("%s: malloc: %s\n",filename,strerror(errno));
1198
	sprintf(hv0, "%s: malloc: %s!",filename,strerror(errno));
-
 
1199
        garmin_queue_error(hv0, err_fatal);
1191
      }
1200
      }
1192
    } else {
1201
    } else {
1193
      /* fstat failed */
1202
      /* fstat failed */
1194
      printf("%s: fstat: %s\n",filename,strerror(errno));
1203
      sprintf(hv0, "%s: fstat: %s!",filename,strerror(errno));
-
 
1204
      garmin_queue_error(hv0, err_error);
1195
    }
1205
    }
1196
    close(fd);
1206
    close(fd);
1197
  } else {
1207
  } else {
1198
    /* open failed */
1208
    /* open failed */
1199
    printf("%s: open: %s\n",filename,strerror(errno));
1209
    sprintf(hv0, "%s: open: %s!",filename,strerror(errno));
-
 
1210
    garmin_queue_error(hv0, err_error);
1200
  }
1211
  }
1201
 
1212
 
1202
  return data;
1213
  return data;
1203
}
1214
}
1204
 
1215
 
Line 1223... Line 1234...
1223
garmin_data *
1234
garmin_data *
1224
garmin_unpack ( uint8 **         pos, 
1235
garmin_unpack ( uint8 **         pos, 
1225
		garmin_datatype  type )
1236
		garmin_datatype  type )
1226
{
1237
{
1227
  garmin_data * d = garmin_alloc_data(type);
1238
  garmin_data * d = garmin_alloc_data(type);
-
 
1239
  char hv0[256];
1228
 
1240
 
1229
  /* Early exit if we were asked to allocate an unknown data type. */
1241
  /* Early exit if we were asked to allocate an unknown data type. */
1230
 
1242
 
1231
  if ( d->data == NULL ) {
1243
  if ( d->data == NULL ) {
1232
    free(d);
1244
    free(d);
Line 1295... Line 1307...
1295
  CASE_DATA(1011);
1307
  CASE_DATA(1011);
1296
  CASE_DATA(1012);
1308
  CASE_DATA(1012);
1297
  CASE_DATA(1013);
1309
  CASE_DATA(1013);
1298
  CASE_DATA(1015);
1310
  CASE_DATA(1015);
1299
  default: 
1311
  default: 
1300
    printf("garmin_unpack: data type %d not supported\n",type);
1312
    sprintf(hv0, "garmin_unpack: data type %d not supported!",type);
-
 
1313
    garmin_queue_error(hv0, err_warning);
1301
    break;
1314
    break;
1302
  }
1315
  }
1303
 
1316
 
1304
  return d;
1317
  return d;
1305
 
1318