Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
config.c File Reference
#include "ac_cfg.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "avrdude.h"
#include "libavrdude.h"
#include "config.h"
#include "config_gram.h"
#include "avrdude-slic3r.conf.h"
+ Include dependency graph for config.c:

Go to the source code of this file.

Macros

#define DEBUG   0
 

Typedefs

typedef struct yy_buffer_stateYY_BUFFER_STATE
 

Functions

void cleanup_config (void)
 
int init_config (void)
 
int yywrap ()
 
int yyerror (char *errmsg,...)
 
int yywarning (char *errmsg,...)
 
TOKENnew_token (int primary)
 
void free_token (TOKEN *tkn)
 
void free_tokens (int n,...)
 
TOKENnumber (char *text)
 
TOKENnumber_real (char *text)
 
TOKENhexnumber (char *text)
 
TOKENstring (char *text)
 
TOKENkeyword (int primary)
 
void print_token (TOKEN *tkn)
 
void pyytext (void) { yylval = NULL
 
char * dup_string (const char *str)
 
int yylex_destroy (void)
 
int read_config (const char *file)
 
YY_BUFFER_STATE yy_scan_bytes (const char *base, size_t size)
 
void yy_delete_buffer (YY_BUFFER_STATE b)
 
int read_config_builtin ()
 

Variables

char default_programmer [MAX_STR_CONST]
 
char default_parallel [PATH_MAX]
 
char default_serial [PATH_MAX]
 
double default_bitclock
 
int default_safemode
 
char string_buf [MAX_STR_CONST]
 
char * string_buf_ptr = '\r'
 
LISTID string_list
 
LISTID number_list
 
PROGRAMMERcurrent_prog
 
AVRPARTcurrent_part
 
AVRMEMcurrent_mem
 
LISTID part_list
 
LISTID programmers
 
int lineno
 
const char * infile
 
char * yytext
 

Macro Definition Documentation

◆ DEBUG

#define DEBUG   0

Typedef Documentation

◆ YY_BUFFER_STATE

Function Documentation

◆ cleanup_config()

void cleanup_config ( void  )
62{
63 ldestroy_cb(part_list, (void(*)(void*))avr_free_part);
64 ldestroy_cb(programmers, (void(*)(void*))pgm_free);
65 ldestroy_cb(string_list, (void(*)(void*))free_token);
66 ldestroy_cb(number_list, (void(*)(void*))free_token);
67}
void avr_free_part(AVRPART *d)
Definition avrpart.c:498
LISTID number_list
Definition config.c:47
LISTID part_list
Definition config.c:51
LISTID string_list
Definition config.c:46
LISTID programmers
Definition config.c:52
void free_token(TOKEN *tkn)
Definition config.c:145
void ldestroy_cb(LISTID lid, void(*ucleanup)(void *data_ptr))
Definition lists.c:480
void pgm_free(PROGRAMMER *const p)
Definition pgm.c:141

References avr_free_part(), free_token(), ldestroy_cb(), number_list, part_list, pgm_free(), programmers, and string_list.

Referenced by cleanup_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dup_string()

char * dup_string ( const char *  str)
308{
309 char * s;
310
311 s = strdup(str);
312 if (s == NULL) {
313 yyerror("dup_string(): out of memory");
314 return NULL;
315 }
316
317 return s;
318}
int yyerror(char *errmsg,...)
Definition config.c:93

References yyerror().

Referenced by yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free_token()

void free_token ( TOKEN tkn)
146{
147 if (tkn) {
148 switch (tkn->value.type) {
149 case V_STR:
150 if (tkn->value.string)
151 free(tkn->value.string);
152 tkn->value.string = NULL;
153 break;
154 }
155
156 free(tkn);
157 }
158}
int type
Definition config.h:33
VALUE value
Definition config.h:44
@ V_STR
Definition config.h:31
char * string
Definition config.h:37
void free(void *)

References free(), value_t::string, value_t::type, V_STR, and token_t::value.

Referenced by assign_pin(), assign_pin_list(), cleanup_config(), free_tokens(), parse_cmdbits(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free_tokens()

void free_tokens ( int  n,
  ... 
)
162{
163 TOKEN * t;
164 va_list ap;
165
166 va_start(ap, n);
167 while (n--) {
168 t = va_arg(ap, TOKEN *);
169 free_token(t);
170 }
171 va_end(ap);
172}
Definition config.h:42

References free_token().

Referenced by yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hexnumber()

TOKEN * hexnumber ( char *  text)
210{
211 struct token_t * tkn;
212 char * e;
213
214 tkn = new_token(TKN_NUMBER);
215 if (tkn == NULL) {
216 return NULL; /* yyerror already called */
217 }
218 tkn->value.type = V_NUM;
219 tkn->value.number = strtoul(text, &e, 16);
220 if ((e == text) || (*e != 0)) {
221 yyerror("can't scan hex number \"%s\"", text);
222 return NULL;
223 }
224
225#if DEBUG
226 avrdude_message(MSG_INFO, "HEXNUMBER(%g)\n", tkn->value.number);
227#endif
228
229 return tkn;
230}
#define MSG_INFO
Definition avrdude.h:51
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93
TOKEN * new_token(int primary)
Definition config.c:127
int number
Definition config.h:35
@ V_NUM
Definition config.h:31
#define TKN_NUMBER
Definition config_gram.c:398

References avrdude_message(), MSG_INFO, new_token(), value_t::number, TKN_NUMBER, value_t::type, V_NUM, token_t::value, and yyerror().

+ Here is the call graph for this function:

◆ init_config()

int init_config ( void  )
70{
71 string_list = lcreat(NULL, 0);
72 number_list = lcreat(NULL, 0);
73 current_prog = NULL;
74 current_part = NULL;
75 current_mem = NULL;
76 part_list = lcreat(NULL, 0);
77 programmers = lcreat(NULL, 0);
78
79 lineno = 1;
80 infile = NULL;
81
82 return 0;
83}
AVRPART * current_part
Definition config.c:49
const char * infile
Definition config.c:55
int lineno
Definition config.c:54
AVRMEM * current_mem
Definition config.c:50
PROGRAMMER * current_prog
Definition config.c:48
LISTID lcreat(void *liststruct, int poolsize)
Definition lists.c:410

References current_mem, current_part, current_prog, infile, lcreat(), lineno, number_list, part_list, programmers, and string_list.

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ keyword()

TOKEN * keyword ( int  primary)
262{
263 struct token_t * tkn;
264
265 tkn = new_token(primary);
266
267 return tkn;
268}
int primary
Definition config.h:43

References new_token(), and token_t::primary.

Referenced by Slic3r::GCode::do_export(), and Slic3r::GUI::Tab::validate_custom_gcode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ new_token()

TOKEN * new_token ( int  primary)
128{
129 TOKEN * tkn;
130
131 tkn = (TOKEN *)malloc(sizeof(TOKEN));
132 if (tkn == NULL) {
133 yyerror("new_token(): out of memory");
134 return NULL;
135 }
136
137 memset(tkn, 0, sizeof(TOKEN));
138
139 tkn->primary = primary;
140
141 return tkn;
142}
void * malloc(YYSIZE_T)

References malloc(), token_t::primary, and yyerror().

Referenced by hexnumber(), keyword(), number(), number_real(), and string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ number()

TOKEN * number ( char *  text)
177{
178 struct token_t * tkn;
179
180 tkn = new_token(TKN_NUMBER);
181 if (tkn == NULL) {
182 return NULL; /* yyerror already called */
183 }
184 tkn->value.type = V_NUM;
185 tkn->value.number = atoi(text);
186
187#if DEBUG
188 avrdude_message(MSG_INFO, "NUMBER(%d)\n", tkn->value.number);
189#endif
190
191 return tkn;
192}

References avrdude_message(), MSG_INFO, new_token(), value_t::number, TKN_NUMBER, value_t::type, V_NUM, and token_t::value.

Referenced by Slic3r::anonymous_namespace{SL1_SVG.cpp}::decimal_from().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ number_real()

TOKEN * number_real ( char *  text)
195{
196 struct token_t * tkn;
197
198 tkn = new_token(TKN_NUMBER);
199 tkn->value.type = V_NUM_REAL;
200 tkn->value.number_real = atof(text);
201
202#if DEBUG
203 avrdude_message(MSG_INFO, "NUMBER(%g)\n", tkn->value.number_real);
204#endif
205
206 return tkn;
207}
double number_real
Definition config.h:36
@ V_NUM_REAL
Definition config.h:31

References avrdude_message(), MSG_INFO, new_token(), value_t::number_real, TKN_NUMBER, value_t::type, V_NUM_REAL, and token_t::value.

+ Here is the call graph for this function:

◆ print_token()

void print_token ( TOKEN tkn)
272{
273 if (!tkn)
274 return;
275
276 avrdude_message(MSG_INFO, "token = %d = ", tkn->primary);
277 switch (tkn->value.type) {
278 case V_NUM:
279 avrdude_message(MSG_INFO, "NUMBER, value=%d", tkn->value.number);
280 break;
281
282 case V_NUM_REAL:
283 avrdude_message(MSG_INFO, "NUMBER, value=%g", tkn->value.number_real);
284 break;
285
286 case V_STR:
287 avrdude_message(MSG_INFO, "STRING, value=%s", tkn->value.string);
288 break;
289
290 default:
291 avrdude_message(MSG_INFO, "<other>");
292 break;
293 }
294
296}

References avrdude_message(), MSG_INFO, value_t::number, value_t::number_real, token_t::primary, value_t::string, value_t::type, V_NUM, V_NUM_REAL, V_STR, and token_t::value.

+ Here is the call graph for this function:

◆ pyytext()

pyytext ( void  ) { yylval = NULL
300{
301#if DEBUG
302 avrdude_message(MSG_INFO, "TOKEN: \"%s\"\n", yytext);
303#endif
304}
char * yytext
Definition lexer.c:956

References avrdude_message(), MSG_INFO, and yytext.

+ Here is the call graph for this function:

◆ read_config()

int read_config ( const char *  file)
326{
327 FILE * f;
328 int r;
329
330 f = fopen_utf8(file, "r");
331 if (f == NULL) {
332 avrdude_message(MSG_INFO, "%s: can't open config file \"%s\": %s\n",
333 progname, file, strerror(errno));
334 return -1;
335 }
336
337 lineno = 1;
338 infile = file;
339 yyin = f;
340
341 r = yyparse();
342
343#ifdef HAVE_YYLEX_DESTROY
344 /* reset lexer and free any allocated memory */
346#endif
347
348 fclose(f);
349
350 return r;
351}
char * progname
Definition main.c:61
int yylex_destroy(void)
int yyparse(void)
Definition config_gram.c:1576
FILE * yyin
Definition lexer.c:327
FILE * fopen_utf8(const char *filename, const char *mode)
Definition fileio.c:108

References avrdude_message(), fopen_utf8(), infile, lineno, MSG_INFO, progname, yyin, yylex_destroy(), and yyparse().

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_config_builtin()

int read_config_builtin ( )
358{
359 int r;
360
361 lineno = 1;
362 infile = "(builtin)";
363
364 // Note: Can't use yy_scan_buffer, it's buggy (?), leads to fread from a null FILE*
365 // and so unfortunatelly we have to use the copying variant here
366 YY_BUFFER_STATE buffer = yy_scan_bytes((const char *)avrdude_slic3r_conf, avrdude_slic3r_conf_SIZE);
367 if (buffer == NULL) {
368 avrdude_message(MSG_INFO, "%s: read_config_builtin: Failed to initialize parsing buffer\n", progname);
369 return -1;
370 }
371
372 r = yyparse();
373 yy_delete_buffer(buffer);
374
375#ifdef HAVE_YYLEX_DESTROY
376 /* reset lexer and free any allocated memory */
378#endif
379
380 return r;
381}
YY_BUFFER_STATE yy_scan_bytes(const char *base, size_t size)
void yy_delete_buffer(YY_BUFFER_STATE b)
Definition lexer.c:186

References avrdude_message(), infile, lineno, MSG_INFO, progname, yy_delete_buffer(), yy_scan_bytes(), yylex_destroy(), and yyparse().

Referenced by avrdude_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string()

TOKEN * string ( char *  text)
234{
235 struct token_t * tkn;
236 int len;
237
238 tkn = new_token(TKN_STRING);
239 if (tkn == NULL) {
240 return NULL; /* yyerror already called */
241 }
242
243 len = (int)strlen(text);
244
245 tkn->value.type = V_STR;
246 tkn->value.string = (char *) malloc(len+1);
247 if (tkn->value.string == NULL) {
248 yyerror("string(): out of memory");
249 return NULL;
250 }
251 strcpy(tkn->value.string, text);
252
253#if DEBUG
254 avrdude_message(MSG_INFO, "STRING(%s)\n", tkn->value.string);
255#endif
256
257 return tkn;
258}
#define TKN_STRING
Definition config_gram.c:400

References avrdude_message(), malloc(), MSG_INFO, new_token(), value_t::string, TKN_STRING, value_t::type, V_STR, token_t::value, and yyerror().

Referenced by Slic3r::client::macro_processor::macro_processor(), igl::readOFF(), and igl::readWRL().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ yy_delete_buffer()

void yy_delete_buffer ( YY_BUFFER_STATE  b)

Referenced by read_config_builtin().

+ Here is the caller graph for this function:

◆ yy_scan_bytes()

YY_BUFFER_STATE yy_scan_bytes ( const char *  base,
size_t  size 
)

Referenced by read_config_builtin().

+ Here is the caller graph for this function:

◆ yyerror()

int yyerror ( char *  errmsg,
  ... 
)
94{
95 va_list args;
96
97 char message[512];
98
99 va_start(args, errmsg);
100
101 vsnprintf(message, sizeof(message), errmsg, args);
102 avrdude_message(MSG_INFO, "%s: error at %s:%d: %s\n", progname, infile, lineno, message);
103
104 va_end(args);
105
106 return 0;
107}

References avrdude_message(), infile, lineno, MSG_INFO, and progname.

Referenced by assign_pin(), assign_pin_list(), dup_string(), hexnumber(), new_token(), parse_cmdbits(), string(), which_opcode(), and yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ yylex_destroy()

int yylex_destroy ( void  )

Referenced by read_config(), and read_config_builtin().

+ Here is the caller graph for this function:

◆ yywarning()

int yywarning ( char *  errmsg,
  ... 
)
111{
112 va_list args;
113
114 char message[512];
115
116 va_start(args, errmsg);
117
118 vsnprintf(message, sizeof(message), errmsg, args);
119 avrdude_message(MSG_INFO, "%s: warning at %s:%d: %s\n", progname, infile, lineno, message);
120
121 va_end(args);
122
123 return 0;
124}

References avrdude_message(), infile, lineno, MSG_INFO, and progname.

Referenced by yyparse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ yywrap()

int yywrap ( void  )
88{
89 return 1;
90}

Variable Documentation

◆ current_mem

AVRMEM* current_mem

Referenced by init_config(), and yyparse().

◆ current_part

AVRPART* current_part

Referenced by init_config(), and yyparse().

◆ current_prog

PROGRAMMER* current_prog

◆ default_bitclock

double default_bitclock

Referenced by avrdude_main(), and yyparse().

◆ default_parallel

char default_parallel[PATH_MAX]

Referenced by avrdude_main(), and yyparse().

◆ default_programmer

char default_programmer[MAX_STR_CONST]

Referenced by avrdude_main(), and yyparse().

◆ default_safemode

int default_safemode

Referenced by avrdude_main(), and yyparse().

◆ default_serial

char default_serial[PATH_MAX]

Referenced by avrdude_main(), and yyparse().

◆ infile

◆ lineno

◆ number_list

◆ part_list

◆ programmers

◆ string_buf

char string_buf[MAX_STR_CONST]

◆ string_buf_ptr

while yptr * string_buf_ptr = '\r'

◆ string_list

LISTID string_list

◆ yytext

char * yytext
extern

Referenced by pyytext().