efl

Форк
0
/
edje_cc_sources.c 
235 строк · 6.9 Кб
1
#ifdef HAVE_CONFIG_H
2
# include "config.h"
3
#endif
4

5
#include <string.h>
6
#include <ctype.h>
7
#include <limits.h>
8

9
#include "edje_cc.h"
10

11
static Eet_Data_Descriptor *_srcfile_edd = NULL;
12
static Eet_Data_Descriptor *_srcfile_list_edd = NULL;
13

14
static Eet_Data_Descriptor *_external_edd = NULL;
15
static Eet_Data_Descriptor *_external_list_edd = NULL;
16

17
static Eet_Data_Descriptor *_font_edd = NULL;
18
static Eet_Data_Descriptor *_font_list_edd = NULL;
19

20
static SrcFile_List srcfiles = {NULL};
21

22
void
23
source_edd(void)
24
{
25
   Eet_Data_Descriptor_Class eddc;
26

27
   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "srcfile", sizeof (SrcFile));
28
   _srcfile_edd = eet_data_descriptor_stream_new(&eddc);
29
   EET_DATA_DESCRIPTOR_ADD_BASIC(_srcfile_edd, SrcFile, "name", name, EET_T_INLINED_STRING);
30
   EET_DATA_DESCRIPTOR_ADD_BASIC(_srcfile_edd, SrcFile, "file", file, EET_T_INLINED_STRING);
31

32
   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "srcfile_list", sizeof (SrcFile_List));
33
   _srcfile_list_edd = eet_data_descriptor_stream_new(&eddc);
34
   EET_DATA_DESCRIPTOR_ADD_LIST(_srcfile_list_edd, SrcFile_List, "list", list, _srcfile_edd);
35

36
   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "external", sizeof (External));
37
   _external_edd = eet_data_descriptor_stream_new(&eddc);
38
   EET_DATA_DESCRIPTOR_ADD_BASIC(_external_edd, External, "name", name, EET_T_INLINED_STRING);
39

40
   eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "external_list", sizeof (External_List));
41
   _external_list_edd = eet_data_descriptor_stream_new(&eddc);
42
   EET_DATA_DESCRIPTOR_ADD_LIST(_external_list_edd, External_List, "list", list, _external_edd);
43

44
   _edje_data_font_list_desc_make(&_font_list_edd, &_font_edd);
45
}
46

47
static void source_fetch_file(const char *fil, const char *filname);
48

49
static void
50
source_fetch_file(const char *fil, const char *filname)
51
{
52
   FILE *f;
53
   char buf[16 * 1024], *dir = NULL;
54
   long sz;
55
   size_t tmp;
56
   ssize_t dir_len = 0;
57
   SrcFile *sf;
58

59
   f = fopen(fil, "rb");
60
   if (!f)
61
     {
62
        ERR("Cannot open file '%s'", fil);
63
        exit(-1);
64
     }
65

66
   if (fseek(f, 0, SEEK_END) < 0)
67
     ERR("Error seeking");
68
   sz = ftell(f);
69
   if (fseek(f, 0, SEEK_SET) < 0)
70
     ERR("Error seeking");
71
   sf = mem_alloc(SZ(SrcFile));
72
   sf->name = mem_strdup(filname);
73
   sf->file = mem_alloc(sz + 1);
74
   if (sz > 0)
75
     {
76
        tmp = fread(sf->file, sz, 1, f);
77
        if (tmp != 1)
78
          {
79
             ERR("file length for (%s) doesn't match!", filname);
80
             exit(-1);
81
          }
82
     }
83

84
   sf->file[sz] = '\0';
85
   if (fseek(f, 0, SEEK_SET) < 0)
86
     ERR("Error seeking");
87
   srcfiles.list = eina_list_append(srcfiles.list, sf);
88

89
   while (fgets(buf, sizeof(buf), f))
90
     {
91
        char *p, *pp;
92
        int forgetit = 0;
93
        int haveinclude = 0;
94
        char *file = NULL, *fname = NULL;
95

96
        p = buf;
97
        while ((!forgetit) && (*p))
98
          {
99
             if (!isspace(*p))
100
               {
101
                  if (*p != '#')
102
                    forgetit = 1;
103
               }
104
             p++;
105

106
             if (!haveinclude)
107
               {
108
                  if (!isspace(*p))
109
                    {
110
                       if (!strncmp(p, "include", 7))
111
                         {
112
                            haveinclude = 1;
113
                            p += 7;
114
                         }
115
                       /* HACK! the logic above should be fixed so
116
                        * preprocessor statements don't have to begin
117
                        * in column 0.
118
                        * otoh, edje_cc should print a warning in that case,
119
                        * since according to the standard, preprocessor
120
                        * statements need to be put in column 0.
121
                        */
122
                       else if (!strncmp(p, "#include", 8))
123
                         {
124
                            haveinclude = 1;
125
                            p += 8;
126
                         }
127
                       else
128
                         forgetit = 1;
129
                    }
130
               }
131
             else
132
               {
133
                  if (!isspace(*p))
134
                    {
135
                       char end = '\0';
136

137
                       if (*p == '"') end = '"';
138
                       else if (*p == '<')
139
                         end = '>';
140

141
                       if (end)
142
                         {
143
                            pp = strchr(p + 1, end);
144
                            if (!pp)
145
                              forgetit = 1;
146
                            else
147
                              {
148
                                 ssize_t l = 0;
149

150
                                 /* get the directory of the current file
151
                                  * if we haven't already done so
152
                                  */
153
                                 if (!dir)
154
                                   {
155
                                      dir = ecore_file_dir_get(fil);
156
                                      if (dir) dir_len = strlen(dir);
157
                                   }
158

159
                                 l = pp - p + dir_len + 1;
160
                                 file = mem_alloc(l);
161

162
                                 if (!dir_len)
163
                                   {
164
                                      snprintf(file, l - 1, "%s", p + 1);
165
                                      file[l - 2] = 0;
166
                                   }
167
                                 else
168
                                   {
169
                                      snprintf(file, l, "%s/%s", dir, p + 1);
170
                                      file[l - 1] = 0;
171
                                   }
172

173
                                 fname = strdup(p + 1);
174
                                 pp = strrchr(fname, end);
175
                                 if (pp) *pp = 0;
176
                                 forgetit = 1;
177
                              }
178
                         }
179
                       else
180
                         forgetit = 1;
181
                    }
182
                  else
183
                    p++;
184
               }
185
          }
186
        if ((file) && (fname))
187
          source_fetch_file(file, fname);
188

189
        if (file) free(file);
190
        if (fname) free(fname);
191
     }
192
   free(dir);
193
   fclose(f);
194
}
195

196
void
197
source_fetch(void)
198
{
199
   source_fetch_file(file_in, ecore_file_file_get(file_in));
200
}
201

202
int
203
source_append(Eet_File *ef)
204
{
205
   return eet_data_write(ef, _srcfile_list_edd, "edje_sources", &srcfiles,
206
                         compress_mode);
207
}
208

209
SrcFile_List *
210
source_load(Eet_File *ef)
211
{
212
   SrcFile_List *s;
213

214
   s = eet_data_read(ef, _srcfile_list_edd, "edje_sources");
215
   return s;
216
}
217

218
int
219
source_fontmap_save(Eet_File *ef, Eina_List *font_list)
220
{
221
   Edje_Font_List fl;
222

223
   fl.list = font_list;
224
   return eet_data_write(ef, _font_list_edd, "edje_source_fontmap", &fl,
225
                         compress_mode);
226
}
227

228
Edje_Font_List *
229
source_fontmap_load(Eet_File *ef)
230
{
231
   Edje_Font_List *fl;
232

233
   fl = eet_data_read(ef, _font_list_edd, "edje_source_fontmap");
234
   return fl;
235
}
236

237

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.