|
|
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");
1.1.1.4 ! root 94: free(targetFileName);
1.1 root 95: return -1;
96: }
97:
98: strcpy(targetFileName, sourceFileName);
99: if (targetFileName[strlen(targetFileName)-4] == '.')
100: targetFileName[strlen(targetFileName)-4] = 0; /* Strip MSA extension */
101: strcat(targetFileName, ".st");
102:
103: printf("Converting %s to %s (%li Bytes)\n", sourceFileName, targetFileName, nImageBytes);
104:
105: retval = File_Save(targetFileName, diskBuffer, nImageBytes, FALSE);
106: }
107: else
108: {
109: /* Convert ST to MSA disk image */
110: nImageBytes = 0;
111:
112: /* Read the source disk image: Just load directly into buffer */
113: diskBuffer = File_Read(sourceFileName, &nImageBytes, NULL);
114: if (!diskBuffer || nImageBytes < 512*8)
115: {
116: fprintf(stderr,"Could not read ST disk!\n");
1.1.1.4 ! root 117: free(targetFileName);
1.1 root 118: return -1;
119: }
120:
121: strcpy(targetFileName, sourceFileName);
122: if (targetFileName[strlen(targetFileName)-3] == '.')
123: targetFileName[strlen(targetFileName)-3] = 0; /* Strip ST extension */
124: strcat(targetFileName, ".msa");
125:
126: printf("Converting %s to %s (%li Bytes)\n", sourceFileName, targetFileName, nImageBytes);
127:
128: retval = MSA_WriteDisk(targetFileName, diskBuffer, nImageBytes);
129: }
130:
131: free(targetFileName);
132: free(diskBuffer);
133:
134: return retval;
135: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.