~ubuntu-branches/ubuntu/saucy/fuse-emulator-utils/saucy-proposed

« back to all changes in this revision

Viewing changes to scl2trd.c

  • Committer: Package Import Robot
  • Author(s): Alberto Garcia
  • Date: 2013-06-03 01:42:44 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130603014244-7iyxwnnyzybfwpr6
Tags: 1.1.1-1
* New upstream release.
* Drop all patches, they are already included in this release.
* Update my e-mail address in debian/control and debian/copyright.
* Build with hardening options.
  - debian/compat: bump debhelper compatibility level to 9.
  - debian/control: update build dependency on debhelper as well.
* debian/control:
  - Add build dependencies on libswscale-dev and libavformat-dev.
  - Update build dependency on libspectrum to >= 1.1.0.
  - Remove obsolete DM-Upload-Allowed flag.
  - Update Standards-Version to 3.9.4 (no changes).
  - Mention the new fmfconv tool in the package description.
* debian/copyright: update copyright years.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* scl2trd.c: Convert .SCL disk images to .TRD disk images
2
2
   Copyright (c) 2002-2007 Dmitry Sanarin, Philip Kendall and Fredrick Meunier
3
3
 
4
 
   $Id: scl2trd.c 2891 2007-05-26 19:42:40Z zubzero $
 
4
   $Id: scl2trd.c 4889 2013-02-18 23:15:03Z sbaldovi $
5
5
 
6
6
   This program is free software; you can redistribute it and/or modify
7
7
   it under the terms of the GNU General Public License as published by
87
87
{
88
88
  int TRD, SCL, i;
89
89
 
90
 
  void *TRDh;
 
90
  void *TRDh = NULL;
91
91
  void *tmp;
92
92
 
93
 
  unsigned int *trd_free;
94
93
  unsigned char *trd_fsec;
95
94
  unsigned char *trd_ftrk;
96
95
  unsigned char *trd_files;
99
98
  char signature[8];
100
99
  unsigned char blocks;
101
100
  char headers[256][14];
102
 
  void *tmpscl;
 
101
  void *tmpscl = NULL;
103
102
  unsigned long left;
104
103
  unsigned long fptr;
105
104
  int x;
 
105
  ssize_t bytes_read;
 
106
  ssize_t bytes_written;
106
107
 
107
108
  unsigned char template[34] =
108
109
  {0x01, 0x16, 0x00, 0xF0,
145
146
  }
146
147
 
147
148
  TRDh = malloc(4096);
148
 
  read(TRD, TRDh, 4096);
 
149
  bytes_read = read(TRD, TRDh, 4096);
 
150
  if (bytes_read < 4096) {
 
151
    printf("Error - cannot read TRD header from %s\n", newname);
 
152
    close(TRD);
 
153
    free(TRDh);
 
154
    return;
 
155
  }
149
156
 
150
157
  tmp = (char *) TRDh + 0x8E5;
151
 
  trd_free = (unsigned int *) tmp;
152
158
  trd_files = (unsigned char *) TRDh + 0x8E4;
153
159
  trd_fsec = (unsigned char *) TRDh + 0x8E1;
154
160
  trd_ftrk = (unsigned char *) TRDh + 0x8E2;
155
161
 
156
162
  if ((SCL = open(oldname, O_RDONLY | O_BINARY)) == -1) {
157
163
    printf("Can't open SCL file %s.\n", oldname);
158
 
    close(TRD);
159
 
    close(SCL);
160
 
    return;
 
164
    goto Abort;
161
165
  }
162
166
 
163
 
  read(SCL, &signature, 8);
 
167
  bytes_read = read(SCL, &signature, 8);
 
168
  if (bytes_read < 8) {
 
169
    printf("Error - cannot read signature from SCL file %s\n", oldname);
 
170
    goto Abort;
 
171
  }
164
172
 
165
173
  if (strncasecmp(signature, "SINCLAIR", 8)) {
166
174
    printf("Wrong signature=%s. \n", signature);
167
 
    close(TRD);
168
 
    close(SCL);
169
 
    return;
170
 
  }
171
 
 
172
 
  read(SCL, &blocks, 1);
173
 
 
174
 
  for (x = 0; x < blocks; x++)
175
 
    read(SCL, &(headers[x][0]), 14);
 
175
    goto Abort;
 
176
  }
 
177
 
 
178
  bytes_read = read(SCL, &blocks, 1);
 
179
  if (bytes_read < 1) {
 
180
    printf("Error - cannot read number of files in SCL file %s\n", oldname);
 
181
    goto Abort;
 
182
  }
 
183
 
 
184
  for (x = 0; x < blocks; x++) {
 
185
    bytes_read = read(SCL, &(headers[x][0]), 14);
 
186
    if (bytes_read < 14) {
 
187
      printf("Error - cannot read header %d from SCL file %s\n", x, oldname);
 
188
      goto Abort;
 
189
    }
 
190
  }
176
191
 
177
192
  for (x = 0; x < blocks; x++) {
178
193
    size = headers[x][13];
202
217
    lseek(TRD, fptr, SEEK_SET);
203
218
 
204
219
    while (left > 32000) {
205
 
      read(SCL, tmpscl, 32000);
206
 
      write(TRD, tmpscl, 32000);
207
 
      left -= 32000;
208
 
    }
209
 
 
210
 
    read(SCL, tmpscl, left);
211
 
    write(TRD, tmpscl, left);
 
220
      bytes_read = read(SCL, tmpscl, 32000);
 
221
      if (bytes_read <= 0) {
 
222
        printf("Error - reading file %d from SCL %s\n", x, oldname);
 
223
        goto Abort;
 
224
      }
 
225
 
 
226
      bytes_written = write(TRD, tmpscl, bytes_read);
 
227
      if (bytes_written < bytes_read) {
 
228
        printf("Error - writing to TRD file %s\n", newname);
 
229
        goto Abort;
 
230
      }
 
231
 
 
232
      left -= bytes_read;
 
233
    }
 
234
 
 
235
    if (left > 0) {
 
236
      bytes_read = read(SCL, tmpscl, left);
 
237
      if (bytes_read < (ssize_t)left) {
 
238
        printf("Error - reading file %d from SCL %s\n", x, oldname);
 
239
        goto Abort;
 
240
      }
 
241
 
 
242
      bytes_written = write(TRD, tmpscl, bytes_read);
 
243
      if (bytes_written < bytes_read) {
 
244
        printf("Error - writing to TRD file %s\n", newname);
 
245
        goto Abort;
 
246
      }
 
247
    }
212
248
 
213
249
    free(tmpscl);
214
250
 
232
268
 
233
269
Finish:
234
270
  lseek(TRD, 0L, SEEK_SET);
235
 
  write(TRD, TRDh, 4096);
236
 
  close(TRD);
237
 
  free(TRDh);
 
271
  bytes_written = write(TRD, TRDh, 4096);
 
272
  if (bytes_written < 4096) {
 
273
    printf("Error - writing header to TRD file %s\n", newname);
 
274
  }
 
275
  close(TRD);
 
276
  free(TRDh);
 
277
  return;
 
278
 
 
279
Abort:
 
280
  close(SCL);
 
281
  close(TRD);
 
282
  free(TRDh);
 
283
  free(tmpscl);
238
284
}
239
285
 
240
286
static int
241
287
parse_options(int argc, char **argv, struct options * options)
242
288
{
243
289
  /* Defined by getopt */
244
 
  extern char *optarg;
245
290
  extern int optind;
246
291
 
247
292
  int c;