| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | #!/bin/perl | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Extract supported divecomputers from libdivecomputer source | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Usage: | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2019-07-15 11:22:10 -07:00
										 |  |  | # parse-descriptor.pl <outfile> | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | # | 
					
						
							|  |  |  | # depending on suffix of the outfile it creates the right content for | 
					
						
							|  |  |  | # either a text file or and html file | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | use Carp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #set command line arguments | 
					
						
							| 
									
										
										
										
											2019-07-15 11:22:10 -07:00
										 |  |  | my $outfi = $ARGV[0]; | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | my ($type) = $outfi =~ /\.([^.]+)$/; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-15 11:22:10 -07:00
										 |  |  | my $infi = "libdivecomputer/src/descriptor.c"; | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | open(my $fh, "<", $infi) || croak "can't open $infi: $!"; | 
					
						
							|  |  |  | open(STDOUT, ">", $outfi) || croak "can't open $outfi: $!"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-03 07:02:44 -07:00
										 |  |  | my $commentStart = "# "; | 
					
						
							|  |  |  | my $commentEnd = ""; | 
					
						
							|  |  |  | if ($type eq "html") { | 
					
						
							|  |  |  | 	$commentStart = "<!-- "; | 
					
						
							|  |  |  | 	$commentEnd = " -->"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | printf("%s This file is automatically generated, please edit scripts/parse-descriptor.pl%s\n", $commentStart, $commentEnd); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | my $lastVend = ""; | 
					
						
							| 
									
										
										
										
											2017-01-14 19:22:21 -08:00
										 |  |  | my $lastMod = ""; | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | my @descriptors = (); | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | while (<$fh>) { | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 	if (/^\s*{\s*"([^\,]*)"\s*,\s*"([^\,]*)"\s*,\s*([^\,]*).*}/) { | 
					
						
							|  |  |  | 		push(@descriptors, "$1,$2"); | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | } | 
					
						
							|  |  |  | my @sortedDescriptors = sort @descriptors; | 
					
						
							|  |  |  | foreach (@sortedDescriptors) { | 
					
						
							|  |  |  | 	($vend, $mod) = split(',', $_); | 
					
						
							| 
									
										
										
										
											2017-01-14 19:22:21 -08:00
										 |  |  | 	next if ($vend eq $lastVend && $mod eq $lastMod); | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 	if ($type eq "html") { | 
					
						
							|  |  |  | 		if ($vend eq $lastVend) { | 
					
						
							|  |  |  | 			printf(", %s", $mod); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-05-03 07:02:44 -07:00
										 |  |  | 			if ($lastVend lt "Seabaer" && $vend gt "Seabaer") { | 
					
						
							|  |  |  | 				printf("</li></ul>\n    </dd>\n    <dt>Seabaer</dt><dd><ul>\n\t    <li>T1, H3, HUDC"); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 			if ($lastVend lt "Uemis" && $vend gt "Uemis") { | 
					
						
							| 
									
										
										
										
											2014-08-09 12:04:48 -07:00
										 |  |  | 				printf("</li></ul>\n    </dd>\n    <dt>Uemis</dt><dd><ul>\n\t    <li>Zürich SDA"); | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if ($lastVend eq "") { | 
					
						
							| 
									
										
										
										
											2014-08-09 12:04:48 -07:00
										 |  |  | 				printf("<dl><dt>%s</dt><dd><ul>\n\t    <li>%s", $vend, $mod); | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2014-08-09 12:04:48 -07:00
										 |  |  | 				printf("</li></ul>\n    </dd>\n    <dt>%s</dt><dd><ul>\n\t    <li>%s", $vend, $mod); | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 		if ($vend eq $lastVend) { | 
					
						
							|  |  |  | 			printf(", %s", $mod); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-05-03 07:02:44 -07:00
										 |  |  | 			if ($lastVend lt "Seabaer" && $vend gt "Seabaer") { | 
					
						
							|  |  |  | 				printf("\nSeabaer: T1, H3, HUDC"); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 			if ($lastVend lt "Uemis" && $vend gt "Uemis") { | 
					
						
							|  |  |  | 				printf("\nUemis: Zürich SDA"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if ($lastVend eq "") { | 
					
						
							|  |  |  | 				printf("%s: %s", $vend, $mod); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				printf("\n%s: %s", $vend, $mod); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-07 13:51:02 -07:00
										 |  |  | 	$lastVend = $vend; | 
					
						
							| 
									
										
										
										
											2017-01-14 19:22:21 -08:00
										 |  |  | 	$lastMod = $mod; | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | } | 
					
						
							|  |  |  | if ($type eq "html") { | 
					
						
							| 
									
										
										
										
											2013-12-15 08:16:06 -08:00
										 |  |  |     print("</li>\n\t</ul>\n    </dd>\n</dl>"); | 
					
						
							| 
									
										
										
										
											2013-12-13 16:28:54 -08:00
										 |  |  | } | 
					
						
							|  |  |  | close $fh; |