gsch2pcb: Make --m4-file and -m4-pcbdir arguments work again.
[geda-gaf/peter-b.git] / utils / scripts / mk_char_tab.pl
blob275b4d9eff6a9fa67c0423c02342bffec855c7fa
1 #!/usr/bin/perl
3 # This is a perl script to create a character width table from gEDA's
4 # font .sym files.
6 # MK_CHAR_TAB typical use:
7 # ./mk_char_tab.pl
8 # will produce the char width table file: char_width.c
10 for ($i = 0; $i <= 256; $i++) # clear the width table
12 @width_table[$i] = 0;
14 while (defined($file = <../lib/sym/font/*.sym>)) # search the directory for *.sym files
16 open(INFO,"<$file");
17 @lines = <INFO>;
18 close(INFO);
20 foreach $line (@lines) # search for the F type line
22 @tokens = split (/\s+/,$line); # parse the line
23 $type = @tokens[0];
24 if ($type eq "F")
26 $char_value = ord(@tokens[1]);
27 $char_width = @tokens[2];
28 $is_space = @tokens[3]; # is this the space char?
29 if ($is_space eq "1")
31 $char_value = 32; # if so do fix-up
33 @width_table[$char_value] = $char_width;
34 # print "$file: @tokens, $type $char_value $char_width $is_space\n";
39 # Now we'll build the C file from the width table
41 $FileToWrite = './char_width.c';
42 open(C_file, ">$FileToWrite");
44 print C_file "\n#define CHAR_POINTS 2\n\n";
45 print C_file "const int char_width[]={\n ";
47 for ($i = 0; $i < 256; $i++)
49 print C_file "@width_table[$i]"; # add the char width to the table
50 if ($i == 255) # end of table?
52 print C_file "\n};\n" ;
54 elsif (( $i % 16) == 15 ) # end of line?
56 print C_file ",\n ";
58 else
60 print C_file ",";
64 # Add in the basic string to pixs function
66 print C_file "\n";
67 print C_file "/***************************************************************/\n";
68 print C_file "/* GetStringDisplayLength: */\n";
69 print C_file "/* inputs: string to be sized */\n";
70 print C_file "/* string\'s font size to use */\n";
71 print C_file "/* returns: length of string in gEDA points */\n";
72 print C_file "/***************************************************************/\n";
73 print C_file "int GetStringDisplayLength(char *str,int font_size)\n";
74 print C_file "{ int width=0;\n";
75 print C_file " int i, len;\n";
76 print C_file " len = strlen(str);\n";
77 print C_file " for (i=0;i<len;i++)\n";
78 print C_file " width += char_width[(int)str[i]];\n";
79 print C_file " width = (font_size*width)/CHAR_POINTS;\n";
80 print C_file " return width;\n";
81 print C_file "}\n";
82 print C_file "\n";
84 close(C_file);
87 # we're done