This file is indexed.

/usr/share/gcal/ct2gcal.awk is in gcal-common 3.6.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#  $Id: ct2gcal.awk 0.20 2000/06/14 00:02:00 tom Exp $
#
#  ct2gcal.awk:  Very simple, slow and silly AWK script for converting
#                  "[X]Calentool-2.3" appointments into the `gcal' format.
#
#
#  Copyright (c) 1994, 95, 1996, 2000  Thomas Esken      <esken@gmx.net>
#                                      Im Hagenfeld 84
#                                      D-48147 M"unster
#                                      GERMANY
#
#  This software doesn't claim completeness, correctness or usability.
#  On principle I will not be liable for ANY damages or losses (implicit
#  or explicit), which result from using or handling my software.
#  If you use this software, you agree without any exception to this
#  agreement, which binds you LEGALLY !!
#
#  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, or (at your option)
#  any later version.
#
#  You should have received a copy of the `GNU General Public License'
#  along with this program; if not, write to the:
#
#
#
BEGIN {
  #
  # Define the field separator used (blank actually).
  #
  FS = " "
  #
  # Define the length of the text displayed on a line.
  #   This is a minimum value suggesting where the first position of a
  #   break can take place.  If this happens within a word, the break
  #   is done at its end.
  #   Set `linebreak' to 0 if you don't want to break the text explicitly
  #   (this is the same mode which was done by former versions of this script).
  #
  linebreak = 0
  #
  # Print some leading comment text
  #
  print "; ct2gcal.awk output for Gcal-2.20 or newer"
  print ";"
  print "; Absolutely NO warrenty!"
  print ";"
  print ";"
  #
  # Maximum length of a gcal year yyyy (actually 4 places), month `mm',
  #   day `dd' and `n' field.
  #
  ylen = 4
  mlen = 2
  dlen = 2
  nlen = 1
  #
  # Maximum lenght of a repeated text
  #   means a maximum number of repetitions of 999.
  #
  rlen = 3
  #
  # The newline character of a text part of a gcal resource file line.
  #
  gcalnl = "~"
  #
  # The quote character of a text part of a gcal resource file line.
  #
  gcalqt = "\\"
  #
  # The remark character of a text part of a gcal resource file line.
  #
  gcalremark = ";"
  #
  # The `text' of a typical calentool appointment starts in column 19.
  #
  ctcolumn = 19
  #
  # The remark character sequence of a calentool appointment line.
  #
  ctremark = "# "
  #
  # The character sequence which indicates an eternal date field
  #   of a calentool appointment line
  #
  cteternal = "**"
}
#
# Main block.
#
{
  #
  # Test if line is a comment.
  #
  if (substr($0, 1, 1) == substr(ctremark, 1, 1))
   {
     #
     # First comment char found, check whether line contains a "#include" statement.
     #
     len = length($0)
     if (len > 1)
       ch = substr($0, 2, 1)
     else
       ch = ""
     if (ch == substr(ctremark, 2, 1) || ch == "")
       print gcalremark $0
     else
       print $0
   }
  else
   {
     #
     # We better work with buffer of first three fields of the line
     #   (gawk-2.15.6 fails if we don't work in such way).
     #
     f1 = $1
     f2 = $2
     f3 = $3
     #
     # On conversion we must calculate with some displacement.
     #
     displ = 0
     #
     # No comment, so try to convert...
     #
     if ($0 != "")
      {
        #
        # Test whether line contains an explictit gcal newline character ~
        #   if it is found, quote it by the gcal quote character \
        #   i.e. generate character sequence \~ .
        #
        tmpstr = ""
        len = length($0)
        for (i=1; i <= len; i++)
         {
           ch = substr($0, i, 1)
           if (ch == gcalnl)
             tmpstr = tmpstr gcalqt
           tmpstr = tmpstr ch
         }
        $0 = tmpstr
        #
        # Add "inclusive_date" special text %iyyyy[mm[dd[n]]] (variable "idatetxt")
        #   in case a "... yyyy)" text fragment is found in line.
        #
        idatetxt = ""
        #
        if ($0 ~ /[0-9]+\)/)
         {
           #
           # Pattern found, so search all fields for information.
           #
           for (i=1; i <= NF; i++)
            {
              #
              # Extract the year number.
              #
              if ($i ~ /[0-9]+\)/)
               {
                 #
                 # "tmpstr = substr($i, /[0-9]+\)/)" fails on some AWK implementations,
                 #   so we must emulate that function by a loop  ;((
                 #
                 len = length($i)
                 for (j=1; j <= len; j++)
                  {
                    if (substr($i, j, 1) ~ /[0-9]/)
                      len = j
                  }
                 tmpstr = substr($i, len, length($i))
                 #
                 # Ok, lets go on...
                 #
                 len = length(tmpstr)
                 for (j=1; j <= len; j++)
                  {
                    ch = substr(tmpstr, j, 1)
                    if (ch ~ /[0-9]/)
                      idatetxt = idatetxt ch
                  }
                 #
                 # Add leading zeroes to the year until length(year)==ylen.
                 #
                 len = length(idatetxt)
                 if (len < ylen)
                  {
                    tmpstr = ""
                    len = ylen - len
                    for (j=1; j <= len; j++)
                      tmpstr = "0" tmpstr
                    idatetxt = tmpstr idatetxt
                  }
                 #
                 # Add month and day to "idatetxt".
                 #
                 if (f2 != cteternal)
                  {
                    idatetxt = idatetxt f2
                    if (f3 != cteternal)
                      idatetxt = idatetxt f3
                  }
                 #
                 # Cut "idatetxt" so it contains ylen+mlen+dlen characters maximum.
                 #
                 len = length(idatetxt)
                 if (len > ylen+mlen+dlen)
                   idatetxt = substr(idatetxt, len-(ylen+mlen+dlen-1), ylen+mlen+dlen)
               }
            }
         }
        #
        # Test if line contains a textual "[number]" field which
        #   indicates a date, that occurs at [number]'th weekday of month.
        #
        ntxt = ""
        loopto = NF
        #
        if (f3 !~ /[0-9]/)
         {
           if ($0 ~ /\[+[012345lL]+\]/)
            {
              for (i=1; i <= loopto; i++)
               {
                 if ($i ~ /\[+[012345lL]+\]/)
                  {
                    #
                    # Pattern found, so terminate loop.
                    #
                    loopto = i
                    #
                    # Extract the information.
                    #
                    # "tmpstr = substr($i, /\[+[012345lL]+\]/)" fails on some AWK implementations,
                    #   so we must emulate that function by a loop  ;((
                    #
                    len = length($i)
                    for (j=1; j <= len; j++)
                     {
                       if (substr($i, j, 1) ~ /[012345lL]/)
                         len = j
                     }
                    tmpstr = substr($i, len, length($i))
                    #
                    # Ok, lets go on...
                    #
                    len = length(tmpstr)
                    for (j=1; j <= len; j++)
                     {
                       ch = substr(tmpstr, j, 1)
                       if (ch ~ /[012345lL]/)
                         ntxt = ntxt ch
                     }
                    #
                    # Cut "ntxt" so it contains "nlen" characters maximum.
                    #
                    if (length(ntxt) > nlen)
                      ntxt = substr(ntxt, 1, nlen)
                    #
                    # Replace l|L(==last weekday in month) entry by a `9'.
                    #
                    if (ntxt ~ /[lL]/)
                      ntxt = "9"
                    #
                    # Append found number text to starting date special text.
                    #
                    if (idatetxt != "")
                      idatetxt = idatetxt ntxt
                    #
                    # Eliminate the found "[number]" field.
                    #
                    displ += (length($i) + 1)
                  }
               }
            }
         }
        #
        # Test if line contains a textual "<number>" field and eliminate it.
        #
        rtxt = ""
        loopto = NF
        #
        if ($0 ~ /<+[0-9]+>/)
         {
           for (i=1; i <= loopto; i++)
            {
              if ($i ~ /<+[0-9]+>/)
               {
                 #
                 # Pattern found, so terminate loop.
                 #
                 loopto = i
                 #
                 # Extract the information.
                 #
                 # "tmpstr = substr($i, /<+[0-9]+>/)" fails on some AWK implementations,
                 #   so we must emulate that function by a loop  ;((
                 #
                 len = length($i)
                 for (j=1; j <= len; j++)
                  {
                    if (substr($i, j, 1) ~ /[0-9]/)
                      len = j
                  }
                 tmpstr = substr($i, len, length($i))
                 #
                 # Ok, lets go on...
                 #
                 len = length(tmpstr)
                 for (j=1; j <= len; j++)
                  {
                    ch = substr(tmpstr, j, 1)
                    if (ch ~ /[0-9]/)
                      rtxt = rtxt ch
                  }
                 #
                 # Cut "rtxt" so it contains "rlen" characters maximum.
                 #
                 if (length(rtxt) > rlen)
                   rtxt = substr(rtxt, 1, rlen)
                 #
                 # Eliminate the information.
                 #
                 displ += (length($i) + 1)
               }
            }
         }
        #
        # Append "idatetxt" to line.
        #
        if (idatetxt == "")
          line = $0
        else
          line = $0 "%i" idatetxt
        if (f2 == cteternal)
          f2 = "00"
        if (f3 == cteternal)
          f3 = "00"
        #
        #  Manage possible breaks in the text part of appointment.
        #
        if (linebreak < 1)
          textpart = substr(line, ctcolumn+displ)
        else
         {
           tpart = substr(line, ctcolumn+displ)
           len_tpart = length(tpart)
           if (len_tpart > linebreak)
            {
              k = 0
              textpart = ""
              for (i=1 ; i <= len_tpart ; i += (linebreak+k))
               {
                 textpart = textpart substr(tpart, i, linebreak-1)
                 j = 0
                 k = 0
                 while (substr(tpart, linebreak+i+j-1, 1) !~ /[ \t]/)
                  {
                    textpart = textpart substr(tpart, linebreak+i+j-1, 1)
                    j++
                    if (linebreak + i + j - 1 > len_tpart)
                      break
                  }
                 k += j
                 textpart = textpart gcalnl
               }
            }
           else
             textpart = tpart
           i = length(textpart)
           if (substr(textpart, i, 1) == gcalnl)
             textpart = substr(textpart, 1, i-1)
         }
        if (rtxt != "")
         {
           #
           # If "rtxt" is given, produce the line "rtxt" times using a date variable.
           #
           print "a=" f2 f3 ntxt
           j = int(rtxt)
           #
           # Print line(s) only if repetition factor is 1 or more.
           #
           if (j > 0)
            {
              for (i=1; i <= j; i++)
               {
                 if (f1 != cteternal)
                   print "19" f1 "@a" i-1 " " textpart
                 else
                   print "0@a" i-1 " " textpart
               }
            }
         }
        else
         {
           #
           # Print the constructed line.
           #
           if (f1 != cteternal)
             print "19" f1 f2 f3 ntxt " " textpart
           else
             print "0000" f2 f3 ntxt " " textpart
         }
      }
   }
}