File: ccc.cc

package info (click to toggle)
cdcover 0.9.1-12
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 400 kB
  • sloc: cpp: 3,257; makefile: 91
file content (165 lines) | stat: -rw-r--r-- 3,443 bytes parent folder | download | duplicates (9)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
    CCC - CD COVER CREATOR
    Copyright (C) 2000	Ulli Meybohm, www.meybohm.de (ulli@meybohm.de)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "bytevector.h"
#include "stringlist.h"
#include "ccchelp.h"
#include "texmaker.h"


/*String Ressources:*/

#include "cccpara.h"
Stringlist parameter(cccparaC,cccparaV);

#include "cccpara2.h"
Stringlist standalone_parameter(cccpara2C,cccpara2V);



/* Global Variables */
Stringlist arg;
Bytevector temp;
Cover cover; //Cover is defined in texmaker.h
Bytevector outputfile;
Bytevector errormsg("cdcover: ");



/* Error Messages */

void error_exit(){
	errormsg.fwriteln(fileno(stderr));
	exit(1);
}

void print_help() {
	errormsg=Stringlist(ccchelpC,ccchelpV).toBytevector();
	error_exit();
}

void missing_value_error(Bytevector para){
	errormsg+=
		Bytevector("No value for last parameter ")+
		para;
	error_exit();
}

void unknown_parameter_error(Bytevector para){
	errormsg+=
		Bytevector("Unknown parameter: ")+
		para;
	error_exit();
}

void count_error(Bytevector cnt){
	errormsg+=
		Bytevector("wrong value for-c or --count: ")+
		cnt;		
	error_exit();
}

void fopen_error(){
	errormsg+=
		Bytevector("can't open outputfile ")+
		outputfile;		
	error_exit();
}



/* Parsing the program arguments */

void parse_arguments(){
	int pnr;
	int i=1;
	while ((unsigned int)i<arg.size()){
		pnr=parameter.find(arg[i],0);
		if ( ((unsigned int)i==(arg.size()-1)) && 
			(pnr!=-1) && 
			(!standalone_parameter.includes(arg[i]))
		   ) missing_value_error(arg[i]);	
		switch (pnr) {
			/*-h, --help*/
			case 0: 
			case 1:
				print_help();
				break;
			/*-t, --title*/
			case 2: 
			case 3:
				cover.title=arg[++i];
				break;
			/*-s, --subtitle*/
			case 4: 
			case 5:
				cover.subtitle=arg[++i];
				break;
			/*-b, --backcover*/
			case 6: 
			case 7:
				cover.backcover=arg[++i];
				break;
			/*-c, --count*/
			case 8:
			case 9:
				cover.count=arg[++i].toInt();
				if (cover.count<1) count_error(arg[i]);
				break;
			/*-o, --outputfile*/
			case 10:
			case 11:
				outputfile=arg[++i];
				break;			
			/*-l, --sidebartext-left*/
			case 12:
			case 13:
				cover.sidetext_left=arg[++i];
				break;
			/*-r, --sidebartext-right*/
			case 14:
			case 15:
				cover.sidetext_right=arg[++i];
				break;
			default:
				unknown_parameter_error(arg[i]);
				break;		
		}
		i++;
	}
}


int main(int argc, char * argv[]){
  	Stringlist temp(argc,argv);
	arg=temp; // arg=Stringlist(argc,argv) didn't work under solaris
	if (arg.size()==1) print_help();
	parse_arguments();
	if (outputfile.size!=0) {
		FILE* f=fopen(outputfile.data, "w+b");
		if (!f){
			fopen_error();
		}
		cover.texcover().fwrite(fileno(f));
		fclose(f);
	} else {
		cover.texcover().fwrite(fileno(stdout));
	}
	return 0;
}