Tizen 2.1 base
[apps/core/preloaded/print-service.git] / drvopt / getdrv.go
1 /*
2 *       Printservice
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://floralicense.org/license/
11
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 package main
21
22 import (
23         "./drv"
24         "flag"
25         "fmt"
26         "os"
27         "os/exec"
28         "runtime/pprof"
29 )
30
31 var (
32         infile    string
33         outfile   string
34         glob      string
35         show_help bool
36         cpuprofile string
37 )
38
39 func init() {
40         flag.StringVar(&infile, "i", "stripped.drv", "input drv file")
41         flag.StringVar(&glob, "r", "", "model search pattern")
42         flag.StringVar(&cpuprofile, "p", "", "write cpu profile to file")
43 }
44
45 func main() {
46         flag.Parse()
47
48         if cpuprofile != "" {
49         f, err := os.Create(cpuprofile)
50         if err != nil {
51             fmt.Print(err)
52         }
53         pprof.StartCPUProfile(f)
54         defer pprof.StopCPUProfile()
55     }
56         
57         if glob == "" {
58                 flag.Usage()
59                 return
60         }
61
62         buf, err := drv.Read(infile)
63         if err != nil {
64                 fmt.Println(err)
65                 return
66         }
67         
68         model, err := drv.Find_model(buf, glob)
69         if err != nil {
70                 fmt.Println(err)
71                 return
72         }
73         
74         if outfile == "" {
75                 outfile = glob + ".drv"
76         }
77         
78         fd, err := os.Create(outfile)
79         if err != nil {
80                 fmt.Println(err)
81                 return
82         }
83         defer os.Remove(outfile)
84         defer fd.Close()
85         
86         _, err = fd.Write([]byte(model))
87         if err != nil {
88                 fmt.Println(err)
89                 return
90         }
91         
92         cmd := exec.Command("ppdc", "-d", ".", outfile)
93         err = cmd.Run()
94         if err != nil {
95         fmt.Println("ppdc:", err)
96         }
97         
98         return
99 }