#!/bin/sh
# $Id: index-mon2num,v 1.1 1992/10/10 18:02:52 cross Exp cross $
# INDEX format converter: symbolic -> numerical month names

awk '
BEGIN {
    months["Jan"] =  1; months["Feb"] =  2; months["Mar"] =  3;
    months["Apr"] =  4; months["May"] =  5; months["Jun"] =  6;
    months["Jul"] =  7; months["Aug"] =  8; months["Sep"] =  9;
    months["Oct"] = 10; months["Nov"] = 11; months["Dec"] = 12;
    version=0;
}
/^#VERSION/ {
    if ($2 != "1.0") {
	print "wrong version header \"" $2 "\". cannot decode format.";
	exit;
    }
    off=3;
    while(substr($0,off,1) == " " || substr($0,off,1) == "	")
	off++;
    while(substr($0,off,1) != " " && substr($0,off,1) != "	")
	off++;

    printf("#VERSION (num-month)1.0%s\n", substr($0,off,2048));
    version=1;
    next;
}
/^F/ || /^D/ || /^L/ { 
    if (!version) {
	print "no version (#VERSION) header provided. cannot decode format.";
	exit;
    }
    if (NF < 5) {
	print "illegal format in line " NR;
	exit;
    }
    # must be seeked from left because of embedded spaces in filenames!
    off=0;
    for(i = 0; i < 2; i++) {
	while(substr($0,off,1) != " " && substr($0,off,1) != "	")
	    off++;
	while(substr($0,off,1) == " " || substr($0,off,1) == "	")
	    off++;
    }
    off += 3;
    month=months[substr($0,off,3)];
    if (month <= 0) {
	print "illegal month name " monthstr " in line " NR;
	exit;
    }
 
    printf("%s%02d%s\n", substr($0,1,off-1), month, substr($0,off+3,4096));
    next;
}
{
    # comment lines
    print $0;
}
'
