File: arjdata.c

package info (click to toggle)
arj 3.10.22-13
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,352 kB
  • ctags: 4,701
  • sloc: ansic: 32,990; makefile: 2,034; sh: 1,547; asm: 436
file content (318 lines) | stat: -rw-r--r-- 6,871 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
 * $Id: arjdata.c,v 1.6 2004/04/17 11:44:46 andrew_belov Exp $
 * ---------------------------------------------------------------------------
 * User-modifyable resource information. It must be kept binding-independent.
 *
 */

#include <time.h>

#include "arj.h"

/* Tags */

#define TAG_CHAR                 '@'
#define TAG_SPECIAL_BEGIN        '{'
#define TAG_SPECIAL_END          '}'

/* Alignments */

#define ALIGN_NONE                 0
#define ALIGN_RIGHT                1
#define ALIGN_CENTER               2

/* Resource list hash array. The syntax is: <tag> <substitution> */

static char *resources[][2]=
{
 /* Version */
 {
  "VERSION",
  #ifdef TILED
   "2.78"
  #else
   "3.10"
  #endif
 },
 /* ARJ Software, Inc. counterparts (note: always 4 chars, spaces allowed!) */
 {
  "COUNTERPARTS", "2.7x"                /* The docs mention DOS */
 },
 /* Short product description */
 {
  "PRODUCT",
  "ARJ"
  #if TARGET==OS2
   "/2"
  #endif
  #ifndef TILED
   #if TARGET==OS2
    "-"
   #endif
   "32"
  #endif
 },
 /* Platform */
 {
  "PLATFORM",
  #if TARGET==DOS
   "DOS"
  #elif TARGET==OS2
   "OS/2"
  #elif TARGET==WIN32
   "Win32"
  #elif TARGET==UNIX
   #if defined(linux)
    "Linux"
   #elif defined(__FreeBSD__)
    "FreeBSD"
   #elif defined(SUNOS)
    "SunOS"
   #elif defined(__QNXNTO__)
    "QNX"
   #else
    "UNIX"
   #endif
  #endif
 },
 /* Platform -- legal filename format */
 {
  "PLATFORM_FN",
  #if TARGET==OS2
   "OS2",
  #elif TARGET==UNIX
   "UNIX",
  #else
   "@PLATFORM",
  #endif
 },
 /* Platform specification for FILE_ID.DIZ (appended to description) */
 {
  "PLATFORM_APPENDIX",
  #if defined(linux)
   "/Linux",
  #elif defined(__FreeBSD__)
   "/FreeBSD",
  #elif defined(SUNOS)
   "/SunOS",
  #elif defined(__QNXNTO__)
   "/QNX",
  #elif TARGET==WIN32
   "/Win32",
  #else
   "",
  #endif
 },
 /* Long product description */
 {
  "PRODUCT_LONG",
  #if TARGET==DOS
   #if LOCALE==LANG_en
    "ARJ version @VERSION Open-Source"
   #elif LOCALE==LANG_ru
    "ARJ,  @VERSION"
   #endif
  #else
   #if LOCALE==LANG_en
    "ARJ for @PLATFORM, version @VERSION"
   #elif LOCALE==LANG_ru
    "ARJ  @PLATFORM,  @VERSION"
   #endif
  #endif
 },
 /* Registration token */
 {
  "REGTYPE",
  #ifdef TILED
   "A2"
  #else
   "A3"
  #endif
 },
 /* Extension of executables (for resources) */
 {"EXE_EXT", EXE_EXTENSION},
 /* Archive extension */
 {"ARJ_EXT",
  #if TARGET==DOS
   ".ARJ"                               /* ASR 27/10/2000 -- for packaging
                                           under OS/2 MDOS */
  #else
   ".arj"
  #endif
 },
 /* Ending marker */
 {NULL, NULL}
};

/* Returns year (for Q&D copyright formatting) */

static int cur_year()
{
 struct tm *stm;
 time_t cur_unixtime;

 cur_unixtime=time(NULL);
 stm=localtime(&cur_unixtime);
 return(stm->tm_year+1900); 
}

/* Date formatter */

void date_fmt(char *dest)
{
 #if LOCALE==LANG_en
  static char *mon[]={"January", "February", "March", "April", "May", "June",
                     "July", "August", "September", "October", "November",
                     "December"};
 #elif LOCALE==LANG_fr
  static char *mon[]={"janvier", "fevrier", "mars", "avril", "mai", "juin",
                     "juillet", "aout", "septembre", "octobre", "novembre",
                     "decembre"};
 #elif LOCALE==LANG_de
  static char *mon[]={"Januar", "Februar", "Maerz", "April", "Mai", "Juni",
                     "Juli", "August", "September", "Oktober", "November",
                     "Dezember"};
 #elif LOCALE==LANG_ru
  static char *mon[]={"ﭢ", "䥢ࠫ", "", "५", "", "",
                     "", "", "ᥭ", "", "",
                     ""};
 #endif
 time_t cur_unixtime;
 struct tm *stm;
 #if LOCALE==LANG_en
  char *enstr;                          /* -rd, -th, ... */
 #endif

 cur_unixtime=time(NULL);
 stm=localtime(&cur_unixtime);
 #if LOCALE==LANG_en
  if(stm->tm_mday==1||stm->tm_mday==21||stm->tm_mday==31)
   enstr="st";
  else if(stm->tm_mday==2||stm->tm_mday==22)
   enstr="nd";
  else if(stm->tm_mday==3||stm->tm_mday==23)
   enstr="rd";
  else
   enstr="th";
  sprintf(dest, "%s %d%s, %d", mon[stm->tm_mon], stm->tm_mday, enstr, cur_year());
 #elif LOCALE==LANG_fr
  sprintf(dest, "%d %s %d", stm->tm_mday, mon[stm->tm_mon], cur_year());
 #elif LOCALE==LANG_de
  sprintf(dest, "%d %s %d", stm->tm_mday, mon[stm->tm_mon], cur_year());
 #elif LOCALE==LANG_ru
  sprintf(dest, "%d %s %d .", stm->tm_mday, mon[stm->tm_mon], cur_year());
 #endif
}

/* Context substitution routine */

char *expand_tags(char *str, int limit)
{
 int i, j, sl;
 int l, rl;                             /* Tag/substitution length */
 int align_lmargin=0, align_rmargin=0;
 int align_type=ALIGN_NONE;
 char *p, *et;
 int shift;
 char date_stg[128];
 int repl_len, repl_j;

 sl=strlen(str);
 p=str;
 while(*p!='\0')
 {
  if(*p==TAG_CHAR)
  {
   if(*(p+1)==TAG_CHAR)
   {
    safe_strcpy(p, p+1);
    p++;
   }
   else if(*(p+1)==TAG_SPECIAL_BEGIN&&(et=strchr(p+3, TAG_SPECIAL_END))!=NULL)
   {
    switch(*(p+2))
    {
     case 'd':
     case 'y':
      if(*(p+2)=='y')
       sprintf(date_stg, "%u", cur_year());
      else
       date_fmt(date_stg);
      rl=strlen(date_stg);
      if(sl+rl<limit)
      {
       safe_strcpy(p+rl, p);
       memcpy(p, date_stg, rl);
       limit+=rl;
       p+=rl;
       et+=rl;
      }
      break;
     case 'r':
      align_type=ALIGN_RIGHT;
      align_lmargin=p-str;
      align_rmargin=atoi(p+3);
      break;
     case 'c':
      align_type=ALIGN_CENTER;
      align_lmargin=p-str;
      align_rmargin=atoi(p+3);
      break;
     case '_':
      i=p-str;
      if(align_type==ALIGN_RIGHT)
       shift=align_rmargin-i;           /* The margin is 1-relative! */
      else if(align_type==ALIGN_CENTER)
       shift=align_rmargin-(i+align_lmargin)/2-1;
      if(align_type!=ALIGN_NONE&&shift>0&&sl+shift<limit)
      {
       sl+=shift;
       safe_strcpy(str+align_lmargin+shift, str+align_lmargin);
       memset(str+align_lmargin, 32, shift);
       p+=shift;
       et+=shift;
      }
      align_type=ALIGN_NONE;
      align_rmargin=0;
      break;
    }
    sl-=(et-p);
    safe_strcpy(p, et+1);
   }
   else
   {
    repl_len=0;
    for(j=0; resources[j][0]!=NULL; j++)
    {
     l=strlen(resources[j][0]);
     if(!memcmp(p+1, resources[j][0], l))
     {
      /* Try to find the longest possible match */
      if(l>repl_len)
      {
       repl_j=j;
       repl_len=l;
      }
     }
    }
    if(repl_len==0)
    {
     printf("ARJDATA: unknown tag <%s>\n", p);
     p++;
    }
    else
    {
     rl=strlen(resources[repl_j][1]);
     /* Is it OK to stick the substitution in? */
     if((sl+=rl)>=limit)
      return(NULL);
     safe_strcpy(p+rl, p+repl_len+1);
     memcpy(p, resources[repl_j][1], rl);
    }
   }
  }
  else
   p++;
 }
 return(str);
}