Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

raw.c

00001 /*
00002  *      This program is free software; you can redistribute it and/or
00003  *      modify it under the terms of the GNU General Public License
00004  *      as published by the Free Software Foundation; either version
00005  *      2 of the License, or (at your option) any later version.
00006  *
00007  *  Copyright 2001 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
00008 */
00009 
00010 #ifdef SAVE_RCSID
00011 static char *rcsid =
00012     "@(#) $Id: raw.c,v 1.4 2006/02/24 12:01:01 trikalio Exp $";
00013 #endif
00014 
00015 #include <stdlib.h>
00016 #include <string.h>
00017 
00018 #include "opencbm.h"
00019 
00020 #include "inputfiles.h"
00021 
00022 static int probe(FILE *file, const char *fname, cbmcopy_message_cb msg_cb)
00023 {
00024     return 1;
00025 }
00026 
00027 
00028 static int read(FILE *file, const char *fname, int entry,
00029                 char *cbmname, char *type,
00030                 unsigned char **data, size_t *size,
00031                 cbmcopy_message_cb msg_cb)
00032 {
00033     char *tail;
00034     char *tail2;
00035 
00036     tail = strrchr(fname, '/');
00037     tail2 = strrchr(fname, '\\');
00038 
00039     if (tail2)
00040     {
00041         if (tail2 > tail)
00042         {
00043             tail = tail2;
00044         }
00045     }
00046 
00047     strncpy(cbmname, tail ? tail+1 : fname, 16);
00048     for(tail = cbmname; *tail; tail++)
00049     {
00050         switch(*tail)
00051         {
00052             case '_':
00053                 *tail = ' ';
00054                 break;
00055             default:
00056                 *tail = cbm_ascii2petscii_c(*tail);
00057                 break;
00058         }
00059     }
00060     *type = 'P';
00061     *data = NULL;
00062 
00063     if(entry == 0 && fseek( file, 0L, SEEK_END ) == 0 )
00064     {
00065         *size = ftell(file);
00066         if(*size)
00067         {
00068             *data = malloc(*size);
00069             if(*data)
00070             {
00071                 rewind(file);
00072                 if(fread(*data, *size, 1, file) == 1)
00073                 {
00074                     return 0;
00075                 }
00076                 free(*data);
00077             }
00078         }
00079         else
00080         {
00081             return 0;
00082         }
00083     }
00084     return 1;
00085 }
00086 
00087 DECLARE_INPUT_READER(raw);

Generated on Sun Apr 30 18:45:58 2006 for opencbm by  doxygen 1.4.2