CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
gen_conf_lua.c-Dateireferenz
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <stdarg.h>
+ Include-Abhängigkeitsdiagramm für gen_conf_lua.c:

gehe zum Quellcode dieser Datei

Funktionen

static int read_line (FILE *f, char *buf)
 
static char * get_str (char *s, char *d)
 
void usage (char *err)
 
int main (int argc, char **argv)
 

Dokumentation der Funktionen

static char* get_str ( char *  s,
char *  d 
)
static

Definiert in Zeile 28 der Datei gen_conf_lua.c.

29 {
30  while ((*s == ' ') || (*s == '\t') || (*s == ',')) s++;
31  while (*s && (*s != ' ') && (*s != '\t') && (*s != ',') && (*s != '=') && (*s != ')'))
32  {
33  *d++ = *s++;
34  }
35  while (*s && (*s != ',') && (*s != '=') && (*s != ')'))
36  {
37  if (*s == '+')
38  {
39  *d++ = *s++;
40  while ((*s == ' ') || (*s == '\t') || (*s == ',')) s++;
41  while (*s && (*s != ' ') && (*s != '\t') && (*s != ',') && (*s != '=') && (*s != ')'))
42  {
43  *d++ = *s++;
44  }
45  }
46  else s++;
47  }
48  *d = 0;
49  return s;
50 }
int main ( int  argc,
char **  argv 
)

Definiert in Zeile 60 der Datei gen_conf_lua.c.

61 {
62  if (argc != 4)
63  usage("args");
64 
65  int start = strtoul(argv[3], NULL, 0);
66 
67  FILE *f = fopen(argv[1], "rb");
68 
69  if (f == NULL) usage("failed to open conf.c file");
70 
71  char conf_name[200];
72  sprintf(conf_name, " %s[]", argv[2]);
73 
74  char line[1000];
75  char nm[200];
76  char val[200];
77  int lastid = 0;
78  int firstid = 0;
79  char *s;
80  int found = 0;
81 
82  printf("--[[\nGENERATED %s TABLE\n--]]\nreturn {\n _config_id=%d,\n", argv[2], start);
83 
84  while (read_line(f,line))
85  {
86  if (found)
87  {
88  s = strstr(line, "};");
89  if (s != 0) break;
90 
91  int off = 10;
92  s = strstr(line, "CONF_INFO(");
93  if (s == 0) { off = 11; s = strstr(line, "CONF_INFO2("); }
94  if (s == 0) { off = 11; s = strstr(line, "CONF_INFOP("); }
95  if (s != 0)
96  {
97  char *c = strstr(line, "//");
98  if ((c == 0) || (c > s))
99  {
100  s = get_str(s+off,val);
101  get_str(s,nm);
102  if (strcmp(nm+5,"script_allow_lua_native_calls") != 0) // Exclude enabling native calls
103  {
104  lastid = atoi(val) + start;
105  if (firstid == 0)
106  {
107  firstid = lastid;
108  printf(" _first_entry=%d,\n", firstid);
109  }
110  printf(" %s=%d,\n", nm+5, lastid);
111  }
112  }
113  }
114  }
115  else
116  {
117  s = strstr(line, conf_name);
118  if (s != 0) found = 1;
119  }
120  }
121  fclose(f);
122  printf(" _last_entry=%d\n}\n", lastid);
123 
124  return 0;
125 }
static int read_line ( FILE f,
char *  buf 
)
static

Definiert in Zeile 13 der Datei gen_conf_lua.c.

14 {
15  int eof = 0;
16  int len = 0;
17  while (1)
18  {
19  if (fread(buf,1,1,f) != 1) { eof = 1; break; }
20  if ((*buf == 0x0A) || (*buf == 0x0D)) break;
21  len++;
22  buf++;
23  }
24  *buf = 0;
25  return (eof == 0) || (len > 0);
26 }
void usage ( char *  err)

Definiert in Zeile 54 der Datei gen_conf_lua.c.

55 {
56  fprintf(stderr,"gen_conf_lua conf.c conf_name start_value - Error = %s\n",err);
57  exit(1);
58 }