OSDN Git Service

29121627cc55a87e6f2bcfbd074210c0e400d3ed
[bbk/bchan.git] / src / poptray.c
1 /*
2  * poptray.c
3  *
4  * Copyright (c) 2009 project bchan
5  *
6  * This software is provided 'as-is', without any express or implied
7  * warranty. In no event will the authors be held liable for any damages
8  * arising from the use of this software.
9  *
10  * Permission is granted to anyone to use this software for any purpose,
11  * including commercial applications, and to alter it and redistribute it
12  * freely, subject to the following restrictions:
13  *
14  * 1. The origin of this software must not be misrepresented; you must not
15  *    claim that you wrote the original software. If you use this software
16  *    in a product, an acknowledgment in the product documentation would be
17  *    appreciated but is not required.
18  *
19  * 2. Altered source versions must be plainly marked as such, and must not be
20  *    misrepresented as being the original software.
21  *
22  * 3. This notice may not be removed or altered from any source
23  *    distribution.
24  *
25  */
26
27 #include        <basic.h>
28 #include        <bstdlib.h>
29 #include        <bstdio.h>
30 #include        <errcode.h>
31 #include        <tstring.h>
32 #include        <tcode.h>
33 #include        <btron/btron.h>
34 #include        <btron/dp.h>
35 #include        <btron/hmi.h>
36
37 #include    "poptray.h"
38 #include    "postres.h"
39
40 #ifdef BCHAN_CONFIG_DEBUG
41 # define DP(arg) printf arg
42 # define DP_ER(msg, err) printf("%s (%d/%x)\n", msg, err>>16, err)
43 #else
44 # define DP(arg) /**/
45 # define DP_ER(msg, err) /**/
46 #endif
47
48 EXPORT W poptray_gettraydata(postresdata_t **post)
49 {
50         TRAYREC *data;
51         TR_VOBJREC *vobjrec = NULL;
52         postresdata_t *ret;
53         W i, size, recs, err;
54
55         err = tget_dat(NULL, 0, &size, -1);
56         if (err < 0) {
57                 DP_ER("tget_dat: get size error", err);
58                 return err;
59         }
60         if (err == 0) {
61                 /* tray is empty */
62                 return 0;
63         }
64         data = (TRAYREC*)malloc(size);
65         if (data == NULL) {
66                 return 0;
67         }
68         recs = tget_dat(data, size, NULL, -1);
69         if (recs < 0) {
70                 DP_ER("tget_dat: get data error", recs);
71                 return err;
72         }
73
74         for (i = 0; i < recs; i++) {
75                 if (data[i].id != TR_VOBJ) {
76                         continue;
77                 }
78                 vobjrec = (TR_VOBJREC*)data[i].dt;
79         }
80
81         if (vobjrec != NULL) {
82                 ret = postresdata_new();
83                 if (ret == NULL) {
84                         free(data);
85                         return 0;
86                 }
87                 postresdata_readfile(ret, &(vobjrec->vlnk));
88                 *post = ret;
89         }
90
91         tset_dat(NULL, 0);
92         free(data);
93
94         return 0;
95 }