Annotation of hatari/tools/hmsa/hmsa.c, revision 1.1.1.1

1.1       root        1: /*
                      2:   Hatari tool: Magic Shadow Archiver - hmsa.c
                      3:  
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
                      6: */
                      7: 
                      8: #include <stdio.h>
                      9: #include <stdlib.h>
                     10: #include <stdarg.h>
                     11: #include <string.h>
                     12: 
                     13: #include "hmsa.h"
                     14: #include "file.h"
                     15: #include "msa.h"
                     16: 
                     17: 
                     18: /**
                     19:  * Output string to log file
                     20:  */
                     21: void Log_Printf(int nType, const char *psFormat, ...)
                     22: {
                     23:        va_list argptr;
                     24: 
                     25:        if (nType <= 4)
                     26:        {
                     27:                va_start(argptr, psFormat);
                     28:                vfprintf(stdout, psFormat, argptr);
                     29:                va_end(argptr);
                     30:        }
                     31: }
                     32: 
                     33: 
                     34: /**
                     35:  * Query user
                     36:  */
                     37: int DlgAlert_Query(const char *text)
                     38: {
                     39:        puts(text);
                     40:        return TRUE;
                     41: }
                     42: 
                     43: 
                     44: /**
                     45:  * Output string to log file
                     46:  */
                     47: int main(int argc, char *argv[])
                     48: {
                     49:        long nImageBytes;
                     50:        int retval;
                     51:        unsigned char *diskBuffer;
                     52:        char *sourceFileName;
                     53:        char *targetFileName;
                     54: 
                     55:        if(argc!=2 || argv[1][0]=='-')
                     56:        {
                     57:                printf("\rHatari Magic Shadow (Un-)Archiver version 0.2.1.\n\n"
                     58:                       "Usage:  %s FILENAME\n\n"
                     59:                       "This program converts a MSA disk image into a ST disk image and vice versa.\n\n"
                     60:                       "This software is distributed under the GNU Public License, version 2 or at your\n"
                     61:                       "option any later version. Please read the file gpl.txt for details.\n",
                     62:                       argv[0]);
                     63:                return 0;
                     64:        }
                     65: 
                     66:        if(strlen(argv[1]) < 4)
                     67:        {
                     68:                fprintf(stderr,"Invalid file name %s\n", argv[1]);
                     69:                return -1;
                     70:        }
                     71: 
                     72:        sourceFileName = argv[1];
                     73:        targetFileName = malloc(strlen(sourceFileName) + 6);
                     74: 
                     75:        if (targetFileName == NULL)
                     76:        {
                     77:                fprintf(stderr,"Not enough memory\n");
                     78:                return -1;
                     79:        }
                     80: 
                     81:        if (strcasecmp(&sourceFileName[strlen(sourceFileName)-3], "msa") == 0)
                     82:        {
                     83:                /* Convert MSA to ST disk image */
                     84: 
                     85:                /* Read the source disk image */
                     86:                diskBuffer = MSA_ReadDisk(sourceFileName, &nImageBytes);
                     87:                if (!diskBuffer || nImageBytes < 512*8)
                     88:                {
                     89:                        fprintf(stderr,"Could not read MSA disk!\n");
                     90:                        return -1;
                     91:                }
                     92: 
                     93:                strcpy(targetFileName, sourceFileName);
                     94:                if (targetFileName[strlen(targetFileName)-4] == '.')
                     95:                        targetFileName[strlen(targetFileName)-4] = 0;  /* Strip MSA extension */
                     96:                strcat(targetFileName, ".st");
                     97: 
                     98:                printf("Converting %s to %s (%li Bytes)\n", sourceFileName, targetFileName, nImageBytes);
                     99: 
                    100:                retval = File_Save(targetFileName, diskBuffer, nImageBytes, FALSE);
                    101:        }
                    102:        else
                    103:        {
                    104:                /* Convert ST to MSA disk image */
                    105:                nImageBytes = 0;
                    106: 
                    107:                /* Read the source disk image: Just load directly into buffer */
                    108:                diskBuffer = File_Read(sourceFileName, &nImageBytes, NULL);
                    109:                if (!diskBuffer || nImageBytes < 512*8)
                    110:                {
                    111:                        fprintf(stderr,"Could not read ST disk!\n");
                    112:                        return -1;
                    113:                }
                    114: 
                    115:                strcpy(targetFileName, sourceFileName);
                    116:                if (targetFileName[strlen(targetFileName)-3] == '.')
                    117:                        targetFileName[strlen(targetFileName)-3] = 0;  /* Strip ST extension */
                    118:                strcat(targetFileName, ".msa");
                    119: 
                    120:                printf("Converting %s to %s (%li Bytes)\n", sourceFileName, targetFileName, nImageBytes);
                    121: 
                    122:                retval = MSA_WriteDisk(targetFileName, diskBuffer, nImageBytes);
                    123:        }
                    124: 
                    125:        free(targetFileName);
                    126:        free(diskBuffer);
                    127: 
                    128:        return retval;
                    129: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.