~ubuntu-branches/ubuntu/precise/vice/precise

« back to all changes in this revision

Viewing changes to src/arch/riscos/archdep.c

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2010-02-11 18:30:16 UTC
  • mfrom: (1.1.8 upstream) (9.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100211183016-f6n8usn3tzp0u6dp
Tags: 2.2.dfsg-1
* New upstream release, C64 DTV is included so update package description
  and add it to the menu.
* Drop patch fixing build failure with gcc-4.4 , applied upstream.
* Fix some lintian problems and clean up debian/rules .

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include "machine.h"
39
39
#include "util.h"
40
40
 
41
 
 
42
 
 
43
41
/* File types */
44
42
static const int FileType_GZIP = 0xf89;
45
43
 
48
46
const char *archdep_rsrc_machine_name = "DRIVES";
49
47
void (*archdep_set_leds_callback)(unsigned int, int) = NULL;
50
48
 
51
 
 
52
49
int archdep_init(int *argc, char **argv)
53
50
{
54
 
  return 0;
 
51
    return 0;
55
52
}
56
53
 
57
 
 
58
54
void archdep_closedown(void)
59
55
{
60
 
  if (defaultLogFile != NULL)
61
 
  {
62
 
    fclose(defaultLogFile);
63
 
    defaultLogFile = NULL;
64
 
    remove(defaultLogName);
65
 
    lib_free(defaultLogName);
66
 
    defaultLogName = NULL;
67
 
  }
 
56
    if (defaultLogFile != NULL) {
 
57
        fclose(defaultLogFile);
 
58
        defaultLogFile = NULL;
 
59
        remove(defaultLogName);
 
60
        lib_free(defaultLogName);
 
61
        defaultLogName = NULL;
 
62
    }
68
63
}
69
64
 
70
 
 
71
65
char *archdep_program_name(void)
72
66
{
73
 
  char *name=NULL;
74
 
 
75
 
  if (machine_name != NULL)
76
 
  {
77
 
    if ((name = (char*)lib_malloc(strlen("Vice") + strlen(machine_name) + 1)) != NULL)
78
 
      sprintf(name, "Vice%s", machine_name);
79
 
  }
80
 
 
81
 
  return name;
 
67
    char *name = NULL;
 
68
 
 
69
    if (machine_name != NULL) {
 
70
        if ((name = lib_malloc(strlen("Vice") + strlen(machine_name) + 1)) != NULL) {
 
71
            sprintf(name, "Vice%s", machine_name);
 
72
        }
 
73
    }
 
74
 
 
75
    return name;
82
76
}
83
77
 
84
 
 
85
78
FILE *archdep_open_default_log_file(void)
86
79
{
87
 
  const char *name = tmpnam(NULL);
88
 
 
89
 
  if ((defaultLogName = (char*)lib_malloc(strlen(name)+1)) != NULL)
90
 
  {
91
 
    strcpy(defaultLogName, name);
92
 
    if ((defaultLogFile = fopen(defaultLogName, "w+")) != NULL)
93
 
    {
94
 
      return defaultLogFile;
95
 
    }
96
 
    else
97
 
    {
98
 
      lib_free(defaultLogName);
99
 
      defaultLogName = NULL;
100
 
    }
101
 
  }
102
 
 
103
 
  return fopen("null:", "w");
 
80
    const char *name = tmpnam(NULL);
 
81
 
 
82
    if ((defaultLogName = lib_malloc(strlen(name) + 1)) != NULL) {
 
83
        strcpy(defaultLogName, name);
 
84
        if ((defaultLogFile = fopen(defaultLogName, "w+")) != NULL) {
 
85
            return defaultLogFile;
 
86
        } else {
 
87
            lib_free(defaultLogName);
 
88
            defaultLogName = NULL;
 
89
        }
 
90
    }
 
91
 
 
92
    return fopen("null:", "w");
104
93
}
105
94
 
106
 
 
107
95
FILE *archdep_get_default_log_file(void)
108
96
{
109
 
  return defaultLogFile;
 
97
    return defaultLogFile;
110
98
}
111
99
 
112
 
 
113
100
/* Return a malloc'ed backup file name for file `fname'.  */
114
101
char *archdep_make_backup_filename(const char *fname)
115
102
{
118
105
 
119
106
char *archdep_default_resource_file_name(void)
120
107
{
121
 
  char *name;
122
 
  const char *basename = archdep_rsrc_machine_name;
123
 
 
124
 
  if ((name = (char*)lib_malloc(strlen("Vice:.vicerc") + strlen(basename) + 1)) != NULL)
125
 
     sprintf(name, "Vice:%s.vicerc", basename);
126
 
 
127
 
  return name;
 
108
    char *name;
 
109
    const char *basename = archdep_rsrc_machine_name;
 
110
 
 
111
    if ((name = lib_malloc(strlen("Vice:.vicerc") + strlen(basename) + 1)) != NULL) {
 
112
       sprintf(name, "Vice:%s.vicerc", basename);
 
113
    }
 
114
    return name;
128
115
}
129
116
 
130
 
 
131
117
char *archdep_default_fliplist_file_name(void)
132
118
{
133
119
    return lib_msprintf("Vice:%s.fliplist", machine_name);
134
120
}
135
121
 
 
122
char *archdep_default_autostart_disk_image_file_name(void)
 
123
{
 
124
    return lib_msprintf("Vice:autostart-%s.d64", machine_name);
 
125
}
136
126
 
137
127
char *archdep_default_save_resource_file_name(void)
138
128
{
139
129
  return archdep_default_resource_file_name();
140
130
}
141
131
 
142
 
 
143
132
char *archdep_default_sysfile_pathlist(const char *emu_id)
144
133
{
145
 
  return lib_msprintf("Vice:%s.", emu_id);
 
134
    return lib_msprintf("Vice:%s.", emu_id);
146
135
}
147
136
 
148
 
 
149
137
int archdep_num_text_lines(void)
150
138
{
151
 
  return 0;
 
139
    return 0;
152
140
}
153
141
 
154
142
int archdep_num_text_columns(void)
155
143
{
156
 
  return 0;
 
144
    return 0;
157
145
}
158
146
 
159
 
 
160
147
int archdep_path_is_relative(const char *directory)
161
148
{
162
 
  const char *b;
 
149
    const char *b;
163
150
 
164
 
  b = directory;
165
 
  while (*b != 0)
166
 
  {
167
 
    if ((*b == '$') || (*b == ':')) return 1;
168
 
    b++;
169
 
  }
170
 
  return 0;
 
151
    b = directory;
 
152
    while (*b != 0) {
 
153
        if ((*b == '$') || (*b == ':')) {
 
154
            return 1;
 
155
        }
 
156
        b++;
 
157
    }
 
158
    return 0;
171
159
}
172
160
 
173
 
 
174
 
 
175
 
 
176
 
#define READLINE_BUFFER         512
 
161
#define READLINE_BUFFER 512
177
162
 
178
163
static char readbuffer[READLINE_BUFFER];
179
164
 
180
165
/* Readline emulation */
181
166
char *readline(const char *prompt)
182
167
{
183
 
  char *retbuf;
184
 
  int len;
185
 
 
186
 
  if (prompt != NULL) printf("%s", prompt);
187
 
 
188
 
  readbuffer[0] = '\0';
189
 
  len = OS_ReadLine(readbuffer, READLINE_BUFFER, 0, 255, 0);
190
 
 
191
 
  if ((len <= 0) || (readbuffer[0] < 32)) return NULL;
192
 
  readbuffer[len] = '\0';
193
 
 
194
 
  retbuf = (char*)lib_malloc(strlen(readbuffer) + 1);
195
 
  strcpy(retbuf, readbuffer);
196
 
 
197
 
  return retbuf;
 
168
    char *retbuf;
 
169
    int len;
 
170
 
 
171
    if (prompt != NULL) {
 
172
        printf("%s", prompt);
 
173
    }
 
174
 
 
175
    readbuffer[0] = '\0';
 
176
    len = OS_ReadLine(readbuffer, READLINE_BUFFER, 0, 255, 0);
 
177
 
 
178
    if ((len <= 0) || (readbuffer[0] < 32)) {
 
179
        return NULL;
 
180
    }
 
181
    readbuffer[len] = '\0';
 
182
 
 
183
    retbuf = lib_malloc(strlen(readbuffer) + 1);
 
184
    strcpy(retbuf, readbuffer);
 
185
 
 
186
    return retbuf;
198
187
}
199
188
 
200
 
 
201
189
void add_history(const char *p)
202
190
{
203
191
}
204
192
 
205
 
 
206
193
/* Logfile handling */
207
194
FILE *open_logfile(const char *basename)
208
195
{
209
 
  FILE *fp;
210
 
  char buffer[256];
211
 
  int number;
 
196
    FILE *fp;
 
197
    char buffer[256];
 
198
    int number;
212
199
 
213
 
  for (number=0; number<16; number++)
214
 
  {
215
 
    sprintf(buffer, "%s%d", basename, number);
216
 
    if ((fp = fopen(buffer, "w")) != NULL) return fp;
217
 
  }
218
 
  return NULL;
 
200
    for (number = 0; number < 16; number++) {
 
201
        sprintf(buffer, "%s%d", basename, number);
 
202
        if ((fp = fopen(buffer, "w")) != NULL) {
 
203
            return fp;
 
204
        }
 
205
    }
 
206
    return NULL;
219
207
}
220
208
 
221
209
int archdep_default_logger(const char *level_string, const char *txt)
223
211
    return 0;
224
212
}
225
213
 
226
 
int archdep_spawn(const char *name, char **argv,
227
 
                  char **pstdout_redir, const char *stderr_redir)
 
214
int archdep_spawn(const char *name, char **argv, char **pstdout_redir, const char *stderr_redir)
228
215
{
229
216
    return 0;
230
217
}
233
220
int archdep_expand_path(char **return_path, const char *orig_name)
234
221
{
235
222
    /* Always treat it as the full pathname... */
236
 
    *return_path = (char*)lib_malloc(strlen(orig_name) + 1);
 
223
    *return_path = lib_malloc(strlen(orig_name) + 1);
237
224
    strcpy(*return_path, orig_name);
238
225
    return 0;
239
226
}
272
259
 
273
260
    fd = fopen(tmp, mode);
274
261
 
275
 
    if (fd == NULL)
 
262
    if (fd == NULL) {
276
263
        return NULL;
 
264
    }
277
265
 
278
266
    *filename = tmp;
279
267
 
282
270
 
283
271
const char *archdep_extract_dir_and_leaf(const char *path)
284
272
{
285
 
  const char *dir, *leaf, *b;
 
273
    const char *dir, *leaf, *b;
286
274
 
287
 
  b = path; leaf = b; dir = b;
288
 
  while (*b != '\0')
289
 
  {
290
 
    if ((*b == FSDEV_DIR_SEP_CHR) || (*b == ':'))
291
 
    {
292
 
      dir = leaf; leaf = b + 1;
 
275
    b = path;
 
276
    leaf = b;
 
277
    dir = b;
 
278
    while (*b != '\0') {
 
279
        if ((*b == FSDEV_DIR_SEP_CHR) || (*b == ':')) {
 
280
            dir = leaf;
 
281
            leaf = b + 1;
 
282
        }
 
283
        b++;
293
284
    }
294
 
    b++;
295
 
  }
296
 
  return dir;
 
285
    return dir;
297
286
}
298
287
 
299
288
int archdep_file_is_gzip(const char *name)
302
291
 
303
292
    type = GetFileType(name);
304
293
    /* only look at filename if the filetype differs from 0xF89 */
305
 
    if (type != FileType_GZIP)
306
 
    {
 
294
    if (type != FileType_GZIP) {
307
295
        size_t l = strlen(name);
308
296
 
309
 
        if ((l < 4 || strcasecmp(name + l - 3, FSDEV_EXT_SEP_STR "gz"))
 
297
        if ((l < 4 || strcasecmp(name + l - 3, FSDEV_EXT_SEP_STR "gz")) 
310
298
            && (l < 3 || strcasecmp(name + l - 2, FSDEV_EXT_SEP_STR "z"))
311
 
            && (l < 4 || toupper(name[l - 1]) != 'Z' || name[l - 4] != FSDEV_EXT_SEP_CHR))
 
299
            && (l < 4 || toupper(name[l - 1]) != 'Z' || name[l - 4] != FSDEV_EXT_SEP_CHR)) {
312
300
            return 0;
 
301
        }
313
302
    }
314
303
    return 1;
315
304
}
316
305
 
317
306
int archdep_file_set_gzip(const char *name)
318
307
{
319
 
  if (SetFileType(name, FileType_GZIP) != NULL)
320
 
    return -1;
 
308
    if (SetFileType(name, FileType_GZIP) != NULL) {
 
309
        return -1;
 
310
    }
321
311
 
322
 
  return 0;
 
312
    return 0;
323
313
}
324
314
 
325
315
int archdep_mkdir(const char *pathname, int mode)
332
322
    int objType;
333
323
    int catInfo[4];
334
324
 
335
 
    if ((objType = ReadCatalogueInfo(file_name, catInfo)) == 0)
 
325
    if ((objType = ReadCatalogueInfo(file_name, catInfo)) == 0) {
336
326
        return -1;
 
327
    }
337
328
 
338
329
    *len = catInfo[2];
339
330
    *isdir = objType & 2;
353
344
 
354
345
void archdep_shutdown(void)
355
346
{
356
 
 
357
347
}
358
348
 
359
349
void archdep_set_drive_leds(unsigned int led, int status)
360
350
{
361
 
  if (archdep_set_leds_callback != NULL)
362
 
    archdep_set_leds_callback(led, status);
 
351
    if (archdep_set_leds_callback != NULL) {
 
352
        archdep_set_leds_callback(led, status);
 
353
    }
363
354
}