Rev 281 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 280 | agaran | 1 | #!/usr/bin/perl -w |
| 2 | use strict; |
||
| 3 | # Thu, 13 Nov 2008 21:06:23 +0100 |
||
| 4 | # Maciej 'agaran' Pijanka <agaran@pld-linux.org> |
||
| 5 | # for OpenARM SBC Project |
||
| 6 | # license: gpl v3 |
||
| 7 | |||
| 8 | use Getopt::Long qw//; |
||
| 9 | |||
| 10 | # ITS UNFINISHED |
||
| 11 | |||
| 12 | # idea/todo |
||
| 13 | # -v for verbose (muiltiple for more) |
||
| 14 | # -q for quiet or -s for silent? |
||
| 15 | # |
||
| 16 | # some file with definitions of required fields |
||
| 17 | # if not present (default) then hardcoded data will |
||
| 18 | # be used |
||
| 19 | # |
||
| 20 | # split elements by types so defaults/required-fields |
||
| 21 | # different for different types could be applied |
||
| 22 | # |
||
| 23 | |||
| 24 | # first stage is build list of all data found (no caching concept yet) |
||
| 25 | # then find all sch and make bom? or find already done boms? |
||
| 26 | |||
| 27 | |||
| 28 | sub dbg_printf($$@) { |
||
| 29 | my ($lvl, $format, @args) = @_; |
||
| 30 | |||
| 31 | return if ($lvl >= 3) ; |
||
| 32 | |||
| 33 | printf STDERR $format, @args; |
||
| 34 | } |
||
| 35 | |||
| 36 | sub parse_ifile($) { |
||
| 37 | my ($filepath) = @_; |
||
| 38 | |||
| 39 | open(IN, $filepath) or return 1; |
||
| 40 | |||
| 41 | while (not eof IN) { |
||
| 42 | my $line = <IN>; |
||
| 43 | |||
| 44 | chomp $line; |
||
| 45 | |||
| 46 | if ($line =~ /^[A-Z][a-z]+[ ]*:[ ]+.*$/) { |
||
| 47 | my ($name,$value) = split (/[ ]*:[ ]+/, $line); |
||
| 48 | if ($name =~ /^price$/i) { |
||
| 49 | } elsif ($name =~ /^manufacturer$/i) { |
||
| 50 | } elsif ($name =~ /^description$/i) { |
||
| 51 | } elsif ($name =~ /^datasheet$/i) { |
||
| 52 | } elsif ($name =~ /^supplier$/i) { |
||
| 53 | } elsif ($name =~ /^$/i) { |
||
| 54 | } else { |
||
| 55 | dbg_printf(1, "UNHANDLED IDATA %s = %s\n", $name, $value); |
||
| 56 | } |
||
| 57 | } else { |
||
| 58 | dbg_printf(3, "REST %s\n", $line); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | close(IN); |
||
| 62 | |||
| 63 | } |
||
| 64 | |||
| 65 | sub build_ifile_list($); |
||
| 66 | sub build_ifile_list($) { |
||
| 67 | my ($dir) = @_; |
||
| 68 | |||
| 69 | |||
| 70 | if ( -d $dir) { |
||
| 71 | opendir(DIR, $dir) or return 1; |
||
| 72 | foreach my $e (readdir(DIR)) { |
||
| 73 | my $fe = $dir .'/'. $e; |
||
| 74 | if ( -f $fe) { |
||
| 75 | # Whoo file we have |
||
| 76 | if ($e =~ /\.[pP][dD][fF]$/) { |
||
| 77 | # its an pdf file if filename is correct |
||
| 78 | dbg_printf(3, "PDF %s\n", $fe); |
||
| 79 | } elsif ($e eq 'information.txt') { |
||
| 80 | # we found an information.txt file |
||
| 81 | dbg_printf(2, "IFILE %s\n", $fe); |
||
| 82 | parse_ifile($fe); |
||
| 83 | } else { |
||
| 84 | printf STDERR "FILE %s\n", $fe; |
||
| 85 | } |
||
| 86 | } elsif (-d $fe) { # now its dir... |
||
| 87 | if ($e eq '.svn') { # if entry name is equal to svn |
||
| 88 | next; # go to next entry in foreach loop |
||
| 89 | } |
||
| 90 | next if ($e eq '.' or $e eq '..'); # skip to next if dir entry is . or .. |
||
| 91 | |||
| 92 | dbg_printf(3, "DIR %s\n", $fe); |
||
| 93 | # so we are in dir and not unwanted one |
||
| 94 | build_ifile_list($fe); |
||
| 95 | # so scan deeper |
||
| 96 | } else { |
||
| 97 | # symlink or other myserius beast |
||
| 98 | } |
||
| 99 | } |
||
| 100 | closedir(DIR); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | build_ifile_list('.'); |
||
| 105 |