1#!/usr/bin/awk -f 2 3BEGIN { 4 first = 1; 5 col = 1; 6} 7 8/^[ \t]*#/ { 9 # skip comment lines 10 next; 11} 12 13/^[ \t]*$/ { 14 # skip blank 15 next; 16} 17 18# we do this 'first' song and dance because variables set 19# on the command line are not available in the BEGIN section 20first == 1 { 21 first = 0; 22 printf("@c Generated file. Do not edit directly\n"); 23 printf("@multitable @columnfractions "); 24 for(i = 1 ; i <= 2*ncol ; i = i + 1) { 25 printf("%.3g ", 0.5 / ncol); 26 } 27 printf("\n"); 28 29 printf("@item "); 30 for(i = 1 ; i <= ncol ; i = i + 1) { 31 if( i > 1 ) { printf("@tab "); } 32 printf("Drill @tab Diameter "); 33 } 34 printf("\n"); 35 36 printf("@item "); 37 for(i = 1 ; i <= ncol ; i = i + 1) { 38 if( i > 1 ) { printf("@tab "); } 39 printf("Size @tab (inches) "); 40 } 41 printf("\n"); 42 43 printf("\n"); 44} 45 46{ 47 if( col == 1 ) { 48 printf("@item "); 49 } else { 50 printf("@tab "); 51 } 52 drl = $1; 53 dia = $2; 54 gsub(/_/, " ", drl); 55 printf("%s @tab %s ", drl, dia); 56 col = col + 1; 57 if( col > ncol ) { 58 col = 1; 59 printf("\n"); 60 } 61} 62 63END { 64 while( (col > 1) && (col <= ncol ) ) { 65 printf("@tab @tab "); 66 col = col + 1; 67 } 68 69 printf("@end multitable\n\n"); 70} 71 72 73 74