2
Copyright (c) 1993-2008, Cognitive Technologies
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
8
* ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
���� ����������� �� ��������� �����, ���� ������ ������� � �����������
11
* ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
������ ����������, ������������ ��� ���������������, ������ �����������
13
��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
����������� ����� �� ��������.
15
* �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
���� ������������ � �������� �������� ��������� �/��� �����������
17
���������, ���������� �� ���� ��, ��� ���������������� �����������
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
������������� ������, ��������� � �������������� ��� ���������� ����������
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
33
Redistribution and use in source and binary forms, with or without modification,
34
are permitted provided that the following conditions are met:
36
* Redistributions of source code must retain the above copyright notice,
37
this list of conditions and the following disclaimer.
38
* Redistributions in binary form must reproduce the above copyright notice,
39
this list of conditions and the following disclaimer in the documentation
40
and/or other materials provided with the distribution.
41
* Neither the name of the Cognitive Technologies nor the names of its
42
contributors may be used to endorse or promote products derived from this
43
software without specific prior written permission.
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57
//************************************************************************//
58
//* CTB_oper.c : set of commands uses closed CTB-files********************//
59
//************************************************************************//
66
/// extern fuxntions and data
67
extern char * ctb_last_punct(char *word);
68
extern Bool32 CTB_files_init(char *file_name,Word8 *data,Int16 maxX,Int16 maxY,
69
Int16 dpb,Word8 signums,Word8 attr_size);
70
extern Int32 ctb_err_code ; // error code //
72
CTB_FUNC(Int32) CTB_compress(char *filename)
74
char *p,tmp_file[MAXPATH],file_name[MAXPATH];
77
Word8 dst[CTB_DATA_SIZE],buffer[256*128+2+CTB_DATA_SIZE];
79
p=ctb_last_punct(file_name);
80
strcpy(file_name,filename);
82
ctb_err_code = CTB_ERR_NONE;
84
STRCPY(tmp_file, file_name);
85
p = STRRCHR(tmp_file,'\\');
89
STRCAT(tmp_file,"$$$$$$$$");
92
STRCPY(tmp_file, "$$$$$$$$");
94
if( !CTB_open(file_name, &hi,"w") )
97
CTB_read_global_data(&hi,dst);
98
CTB_files_init(tmp_file,dst,hi.width,hi.height, hi.dpb,hi.signums,hi.attr_size);
101
compress = hi.need_compress;
105
if( !CTB_open(tmp_file,&ho,"w") )
109
switch( CTB_read(&hi,i,buffer,dst) )
112
CTB_write_mark(&ho,-1,buffer,dst,FALSE);
115
CTB_write_mark(&ho,-1,buffer,dst,TRUE);
128
{ // delete tmp file //
129
STRCAT(tmp_file,".CTB");
131
*ctb_last_punct(tmp_file)=0;
132
STRCAT(tmp_file,".IND");
137
STRCAT(file_name,".CTB");
138
STRCAT(tmp_file,".CTB");
140
RENAME(tmp_file,file_name);
141
*ctb_last_punct(tmp_file)=0;
142
*ctb_last_punct(file_name)=0;
143
STRCAT(file_name,".IND");
144
STRCAT(tmp_file,".IND");
146
RENAME(tmp_file,file_name);
151
CTB_FUNC(Int32) CTB_rename(char *new_name, char *old_name)
153
char newname[MAXPATH], oldname[MAXPATH];
155
if( *(new_name+1)!=':' && *(old_name+1)!=':' || // without disk names //
156
toupper(*new_name)==toupper(*old_name) &&
157
*(new_name+1)==':' && *(old_name+1)==':') // one disk //
159
char *p = ctb_last_punct(old_name);
162
p = ctb_last_punct(new_name);
166
SPRINTF(newname,"%s.CTB",new_name);
167
SPRINTF(oldname,"%s.CTB",old_name);
168
if (!access(newname,0))
170
RENAME( oldname, newname); // two files in one disk //
171
SPRINTF(newname,"%s.IND",new_name);
172
SPRINTF(oldname,"%s.IND",old_name);
173
if (!access(newname,0))
175
RENAME( oldname, newname); // two files in one disk //
179
CTB_move(new_name, old_name); // move from disk to disk //
184
CTB_FUNC(Int32) CTB_move(char *new_name, char *old_name)
188
n = (Int16)CTB_copy(new_name, old_name);
189
CTB_unlink(old_name);
193
CTB_FUNC(void) CTB_unlink(char *name)
195
char str[MAXPATH],*p=ctb_last_punct(name);
208
CTB_FUNC(Int32) CTB_copy(char *new_name, char *old_name)
213
Word8 dst[CTB_DATA_SIZE], buffer[256*128+2+CTB_DATA_SIZE];
216
ctb_err_code = CTB_ERR_NONE;
217
p=ctb_last_punct(old_name);
219
p=ctb_last_punct(new_name);
222
if( !CTB_open(old_name, &hi,"w") )
224
CTB_read_global_data(&hi,dst);
225
CTB_files_init(new_name,dst,hi.width,hi.height,
226
hi.dpb,hi.signums,hi.attr_size);
228
n = (Int16)CTB_volume(&hi);
230
if( !CTB_open(new_name,&ho,"w") )
235
switch( CTB_read(&hi,i,buffer,dst) )
238
CTB_write_mark(&ho,-1,buffer,dst,FALSE);
241
CTB_write_mark(&ho,-1,buffer,dst,TRUE);