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