OpenCBM
raw.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2001 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
8 */
9 
10 #include <stdlib.h>
11 #include <string.h>
12 
13 #include "opencbm.h"
14 
15 #include "inputfiles.h"
16 
17 static int probe(FILE *file, const char *fname, cbmcopy_message_cb msg_cb)
18 {
19  return 1;
20 }
21 
22 
23 static int read(FILE *file, const char *fname, int entry,
24  char *cbmname, char *type,
25  unsigned char **data, size_t *size,
26  cbmcopy_message_cb msg_cb)
27 {
28  char *tail;
29  char *tail2;
30 
31  tail = strrchr(fname, '/');
32  tail2 = strrchr(fname, '\\');
33 
34  if (tail2)
35  {
36  if (tail2 > tail)
37  {
38  tail = tail2;
39  }
40  }
41 
42  strncpy(cbmname, tail ? tail+1 : fname, 16);
43  for(tail = cbmname; *tail; tail++)
44  {
45  switch(*tail)
46  {
47  case '_':
48  *tail = ' ';
49  break;
50  default:
51  *tail = cbm_ascii2petscii_c(*tail);
52  break;
53  }
54  }
55  *type = 'P';
56  *data = NULL;
57 
58  if(entry == 0 && fseek( file, 0L, SEEK_END ) == 0 )
59  {
60  *size = ftell(file);
61  if(*size)
62  {
63  *data = malloc(*size);
64  if(*data)
65  {
66  rewind(file);
67  if(fread(*data, *size, 1, file) == 1)
68  {
69  return 0;
70  }
71  free(*data);
72  }
73  }
74  else
75  {
76  return 0;
77  }
78  }
79  return 1;
80 }
81 
82 DECLARE_INPUT_READER(raw);
DLL interface for accessing the driver.
char CBMAPIDECL cbm_ascii2petscii_c(char Character)
Convert an ASCII character to PETSCII.
Definition: petscii.c:105