File: sidcon.cpp

package info (click to toggle)
sidplay 1.36.28-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,192 kB
  • ctags: 1,674
  • sloc: cpp: 12,514; sh: 1,716; makefile: 223
file content (134 lines) | stat: -rw-r--r-- 3,419 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// A dirty sidtune format converter hack with almost no security code.
// TMP should be used.
 
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream.h>
#include <iomanip.h>
#include "sidtune.h"
#include "fformat.h"

static void printUsage()
{
    cerr << "Usage: sidcon [--psid|--sidplay] <files>" << endl;
}

int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        printUsage();
        exit(-1);
    }
    
    int a = 0;
    bool toPSID = true,
        toSIDPLAY = false;
    
    while (a++ < argc-1)
    {
        if (strnicmp(argv[a],"--psid",6) == 0)
        {
            toPSID = true;
            toSIDPLAY = false;
        }
        else if (strnicmp(argv[a],"--sidplay",9) == 0)
        {
            toPSID = false;
            toSIDPLAY = true;
        }
        else if (strnicmp(argv[a],"--",2) == 0)
        {
            printUsage();
            exit(-1);
        }
    }

    bool success = true;
    
    a = 0;
    while (a++ < argc-1)
    {
        success = true;  // reset flag for each new file
        
        if (strnicmp(argv[a],"--",2) != 0)
        {
            cout << argv[a] << ' ';
            
            char* outFileName = 0;
            sidTune mySidTune(argv[a]);
            sidTuneInfo mySTI;
            
            success &= mySidTune.getStatus();

            if (success)
            {
                cout << '.';
                success &= mySidTune.getInfo(mySTI);
				if (mySTI.fixLoad)
				{
					cout << endl << "Duplicate C64 load address detected. Fix it? (y/n) " << flush;
					char c;
					cin >> c;
					if (tolower(c)=='y')
					{
						mySidTune.fixLoadAddress();
					}
				}
                success &= (mySTI.dataFileName!=0);
                if (success)
                {
                    success &= (0!=(outFileName = new char[strlen(mySTI.path)+strlen(mySTI.dataFileName)+4+1]));
                    if (success)
                    {
						strcpy(outFileName,mySTI.path);
                        strcat(outFileName,mySTI.dataFileName);
                    }
                }
            }
            
            if (success)
            {
                cout << '.';
                success &= (remove(outFileName)==0);  // here = path+dataFileName
                if (mySTI.infoFileName != 0)
                {
					strcpy(outFileName,mySTI.path);
					strcat(outFileName,mySTI.infoFileName);
                    success &= (remove(outFileName)==0);
                }
            }
            
            if (success)
            {
                cout << '.';
                if (toPSID)
                {
                    strcpy(fileExtOfPath(outFileName),".sid");
                    success &= (mySidTune.savePSIDfile(outFileName));
                }
                else if (toSIDPLAY)
                {
                    strcpy(fileExtOfPath(outFileName),".c64");
                    success &= (mySidTune.saveC64dataFile(outFileName));
                    strcpy(fileExtOfPath(outFileName),".sid");
                    success &= (mySidTune.saveSIDfile(outFileName));
                }
            }

            if (success)
            {
                cout << " OK" << endl;
            }
            else
            {
                cout << " ERROR" << endl;
            }

            if (outFileName != 0)
                delete[] outFileName;
        }
    }
}