summaryrefslogtreecommitdiff
path: root/setup/Linux/confgen.c
blob: 53662f2a802f5a4fe6fd75a135494c4e6d8f9615 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <libgen.h>
#include <sys/stat.h>

char *targetdir = "";
char *confpath = "";

static int
copy_parms (FILE * f, FILE * conf)
{
  char line[1024], *s;
  char var[256] = "", comment[64 * 1024] = "";
  int i;
  int ok = 0;

  while (fgets (line, sizeof (line), f) != NULL)
    {
      for (i = 0; i < strlen (line); i++)
	if (line[i] == '\n')
	  line[i] = 0;

      s = line;

      while (*s == ' ' || *s == '\t')
	s++;
      if (strncmp (s, "int ", 4) == 0)
	{
	  if (*var != 0)
	    {
	      fprintf (conf, "%s\n", comment);
	      if (*var != 0)
		fprintf (conf, "#%s\n#\n", var);
	      *var = 0;
	      *comment = 0;
	    }
	  s += 4;

	  for (i = 0; i < strlen (line); i++)
	    if (line[i] == ';')
	      line[i] = 0;
	  ok = 1;
	  strcpy (var, s);
	  continue;
	}


      s = line;

      while (*s == ' ' || *s == '\t' || *s == '/' || *s == '*')
	s++;

      if (*comment != 0)
	strcat (comment, "\n");
      strcat (comment, "# ");
      strcat (comment, s);
    }

  if (*var != 0)
    {
      fprintf (conf, "%s\n", comment);
      fprintf (conf, "#%s\n", var);
    }

  return ok;
}

static void
scan_dir (const char *srcdir, const char *modnam)
{
  char confname[256], tmp[256], line[1024];
  char module[256], *p;
  FILE *conf;
  FILE *f;
  int i;
  struct stat st;

  int check_platform = 0;
  int platform_ok = 0;
  int ok = 0;

  strcpy (module, modnam);
  p = module;
  while (*p)
    {
      if (*p == '.')
	*p = 0;
      else
	p++;
    }

  if (stat (srcdir, &st) == -1)
    return;

  if (!S_ISDIR (st.st_mode))	/* Not a directory? */
    return;

  sprintf (tmp, "%s/.nomake", srcdir);
  if (stat (tmp, &st) != -1)	/* File exists */
    return;			/* Skip this one */

  sprintf (tmp, "%s/.config", srcdir);
  if ((f = fopen (tmp, "r")) != NULL)
    {
      while (fgets (line, sizeof (line), f) != NULL)
	{
	  char *s;
	  for (i = 0; i < strlen (line); i++)
	    if (line[i] == '\n')
	      line[i] = 0;

	  s = line;
	  while (*s && *s != '=')
	    s++;
	  if (*s == '=')
	    *s++ = 0;

	  if (strcmp (line, "OS") == 0 || strcmp (line, "targetos") == 0)
	    {
	      check_platform = 1;
	      if (strcmp (s, "Linux") == 0)
		platform_ok = 1;
	      continue;
	    }
	}
      fclose (f);
    }

  if (check_platform && !platform_ok && strcmp (modnam, "osscore"))
    {
      return;
    }
#if 0
  /* copy the man pages */
  sprintf (syscmd, "sed 's:CONFIGFILEPATH:%s:g' < %s/%s.man > /tmp/ossman.man",
	   confpath, srcdir, module);
  printf ("%s\n", syscmd);
  unlink ("/tmp/ossman.man");
  system (syscmd);

  sprintf (syscmd,
	   "./origdir/setup/txt2man -t \"%s\" -v \"Devices\" -s 7  /tmp/ossman.man > prototype/usr/man/man7/%s.7",
	   module, module);
  printf ("%s\n", syscmd);
  system (syscmd);
#endif

  sprintf (confname, "%s/%s.conf", targetdir, module);
  sprintf (tmp, "%s/.params", srcdir);
  if ((f = fopen (tmp, "r")) != NULL)
    {
      if ((conf = fopen (confname, "w")) == NULL)
        {
          perror (confname);
          exit (-1);
        }
      fprintf (conf, "# Open Sound System configuration file\n");
      fprintf (conf,
	   "# Remove the '#' in front of the option(s) you like to set.\n#\n");
      ok = copy_parms (f, conf);
      fclose (f);
//      fprintf(conf, "#\n");
      fclose (conf);
      if (!ok)
        unlink (confname);
    }
}

int
main (int argc, char *argv[])
{
  int i;

  if (argc < 3)
    exit (-1);

  targetdir = argv[1];
  confpath = argv[2];

  for (i = 3; i < argc; i++)
    {
      scan_dir (argv[i], basename (argv[i]));
    }

  exit (0);
}