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

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

unix.superglobalmegacorp.com

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