~ubuntu-branches/debian/wheezy/cuneiform/wheezy

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/ctb/src/ctb_oper.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-07-10 17:58:10 UTC
  • Revision ID: james.westby@ubuntu.com-20090710175810-rqc89d2i3tki9m89
Tags: upstream-0.7.0+dfsg
Import upstream version 0.7.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 1993-2008, Cognitive Technologies
 
3
All rights reserved.
 
4
 
 
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
 
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
 
7
 
 
8
      * ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
 
9
        ���� ����������� �� ��������� �����, ���� ������ ������� � �����������
 
10
        ����� �� ��������.
 
11
      * ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
 
12
        ������ ����������, ������������ ��� ���������������, ������ �����������
 
13
        ��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
 
14
        ����������� ����� �� ��������.
 
15
      * �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
 
16
        ���� ������������ � �������� �������� ��������� �/��� �����������
 
17
        ���������, ���������� �� ���� ��, ��� ���������������� �����������
 
18
        ����������.
 
19
 
 
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
 
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
 
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
 
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
 
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
 
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
 
26
������������� ������, ��������� � �������������� ��� ���������� ����������
 
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
 
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
 
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
 
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
 
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
 
32
 
 
33
Redistribution and use in source and binary forms, with or without modification,
 
34
are permitted provided that the following conditions are met:
 
35
 
 
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.
 
44
 
 
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.
 
55
*/
 
56
 
 
57
//************************************************************************//
 
58
//* CTB_oper.c : set of commands uses closed CTB-files********************//
 
59
//************************************************************************//
 
60
 
 
61
#define MAXPATH 256
 
62
#include<string.h>
 
63
#include<sys/stat.h>
 
64
#include "ctb.h"
 
65
 
 
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                   //
 
71
 
 
72
CTB_FUNC(Int32)  CTB_compress(char *filename)
 
73
{
 
74
char *p,tmp_file[MAXPATH],file_name[MAXPATH];
 
75
CTB_handle hi,ho;
 
76
Int32 i,n,compress;
 
77
Word8 dst[CTB_DATA_SIZE],buffer[256*128+2+CTB_DATA_SIZE];
 
78
 
 
79
p=ctb_last_punct(file_name);
 
80
strcpy(file_name,filename);
 
81
 
 
82
ctb_err_code = CTB_ERR_NONE;
 
83
if( p ) *p='\0';
 
84
STRCPY(tmp_file, file_name);
 
85
p = STRRCHR(tmp_file,'\\');
 
86
if( p )
 
87
        {
 
88
        *(p+1)='\0';
 
89
        STRCAT(tmp_file,"$$$$$$$$");
 
90
        }
 
91
else
 
92
        STRCPY(tmp_file, "$$$$$$$$");
 
93
 
 
94
if( !CTB_open(file_name, &hi,"w") )
 
95
        return FALSE;
 
96
 
 
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);
 
99
 
 
100
n = CTB_volume(&hi);
 
101
compress = hi.need_compress;
 
102
 
 
103
if( compress )
 
104
        {
 
105
  if( !CTB_open(tmp_file,&ho,"w") )
 
106
                return 0;
 
107
        for(i=0;i<n;i++)
 
108
        {
 
109
        switch( CTB_read(&hi,i,buffer,dst) )
 
110
            {
 
111
            case    1 :
 
112
                CTB_write_mark(&ho,-1,buffer,dst,FALSE);
 
113
                break;
 
114
            case    2:
 
115
                CTB_write_mark(&ho,-1,buffer,dst,TRUE);
 
116
                break;
 
117
            default:
 
118
                break;
 
119
            }
 
120
        }
 
121
        ho.need_compress=0;
 
122
    CTB_close(&ho);
 
123
        }
 
124
 
 
125
hi.need_compress=0;
 
126
CTB_close(&hi);
 
127
if( !compress )
 
128
    {   // delete tmp file //
 
129
    STRCAT(tmp_file,".CTB");
 
130
        UNLINK(tmp_file);
 
131
        *ctb_last_punct(tmp_file)=0;
 
132
    STRCAT(tmp_file,".IND");
 
133
        UNLINK(tmp_file);
 
134
        return 0;
 
135
        }
 
136
 
 
137
STRCAT(file_name,".CTB");
 
138
STRCAT(tmp_file,".CTB");
 
139
UNLINK(file_name);
 
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");
 
145
UNLINK(file_name);
 
146
RENAME(tmp_file,file_name);
 
147
 
 
148
return n;
 
149
}
 
150
 
 
151
CTB_FUNC(Int32)  CTB_rename(char *new_name, char *old_name)
 
152
{
 
153
char newname[MAXPATH], oldname[MAXPATH];
 
154
 
 
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           //
 
158
        {
 
159
        char *p = ctb_last_punct(old_name);
 
160
        if (p)
 
161
         *p = 0;
 
162
        p = ctb_last_punct(new_name);
 
163
        if (p)
 
164
         *p = 0;
 
165
 
 
166
  SPRINTF(newname,"%s.CTB",new_name);
 
167
  SPRINTF(oldname,"%s.CTB",old_name);
 
168
  if (!access(newname,0))
 
169
         unlink(newname);
 
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))
 
174
         unlink(newname);
 
175
  RENAME( oldname, newname);       // two files in one disk  //
 
176
    return 1;
 
177
  }
 
178
 
 
179
CTB_move(new_name, old_name); // move from disk to disk //
 
180
return 2;
 
181
}
 
182
 
 
183
 
 
184
CTB_FUNC(Int32)  CTB_move(char *new_name, char *old_name)
 
185
{
 
186
Int16 n;
 
187
 
 
188
n = (Int16)CTB_copy(new_name, old_name);
 
189
CTB_unlink(old_name);
 
190
return n;
 
191
}
 
192
 
 
193
CTB_FUNC(void) CTB_unlink(char *name)
 
194
{
 
195
char str[MAXPATH],*p=ctb_last_punct(name);
 
196
 
 
197
if( p ) *p='\0';
 
198
STRCPY(str,name);
 
199
STRCAT(str,".CTB");
 
200
UNLINK(str);
 
201
 
 
202
STRCPY(str,name);
 
203
STRCAT(str,".IND");
 
204
UNLINK(str);
 
205
return ;
 
206
}
 
207
 
 
208
CTB_FUNC(Int32)  CTB_copy(char *new_name, char *old_name)
 
209
{
 
210
char *p;
 
211
CTB_handle hi,ho;
 
212
Int16 i,n;
 
213
Word8 dst[CTB_DATA_SIZE], buffer[256*128+2+CTB_DATA_SIZE];
 
214
//size_t size;
 
215
 
 
216
ctb_err_code = CTB_ERR_NONE;
 
217
p=ctb_last_punct(old_name);
 
218
if( p ) *p='\0';
 
219
p=ctb_last_punct(new_name);
 
220
if( p ) *p='\0';
 
221
 
 
222
if( !CTB_open(old_name, &hi,"w") )
 
223
        return 0;
 
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);
 
227
 
 
228
n = (Int16)CTB_volume(&hi);
 
229
 
 
230
if( !CTB_open(new_name,&ho,"w") )
 
231
        return 0;
 
232
 
 
233
for(i=0;i<n;i++)
 
234
    {
 
235
    switch( CTB_read(&hi,i,buffer,dst) )
 
236
        {
 
237
        case    1 :
 
238
            CTB_write_mark(&ho,-1,buffer,dst,FALSE);
 
239
            break;
 
240
        case    2:
 
241
            CTB_write_mark(&ho,-1,buffer,dst,TRUE);
 
242
            break;
 
243
        default:
 
244
            break;
 
245
        }
 
246
    }
 
247
CTB_close(&ho);
 
248
CTB_close(&hi);
 
249
 
 
250
return n;
 
251
}
 
252
 
 
253
 
 
254