int parse_config_file(void) { int max_hosts; if (access(command_line_option.config_file, R_OK) != 0) { fprintf(stderr, _("Configuration file `%s' is not found.\n"), command_line_option.config_file); fprintf(stderr, _("Running weex setup wizard...\n\n")); setup_wizard(); exit(0); } max_hosts = cfgParse(command_line_option.config_file, config_table, CFG_INI); if (max_hosts == 0) { fprintf(stderr, _("There is no section in configuration file `%s'.\n"), command_line_option.config_file); exit(1); } if (max_hosts == -1) { fprintf(stderr, _("\nAn error has occured while parsing configuration file `%s'.\n"), command_line_option.config_file); exit(1); } set_default(max_hosts); check_and_convert_string_value(max_hosts); check_permission(command_line_option.config_file); return (max_hosts); }
int main (int argc, char *argv[]) { FILE *tmp, *db_file; char info[256]; char *command = NULL; int i, cmd_len = 0, cfg_trash_int; char *temp2, *temp, *sidplay, *sidplay_args, *cfg_trash; char *cfg_file; cfgStruct cfg[] = { { "SIDDB", CFG_STRING, &cfg_trash }, { "HVSC_BASE", CFG_STRING, &cfg_trash }, { "SIDPLAY", CFG_STRING, &sidplay }, { "SIDPLAY_ARGS", CFG_STRING, &sidplay_args }, { "PORT", CFG_INT, &cfg_trash_int }, { NULL, CFG_END, NULL } }; if (!(cfg_file = malloc (sizeof (char) * (strlen (getenv ("HOME")) + strlen (RC_FILE) + 2)))) { fprintf (stderr, "ERROR: Can't allocate memory!\n"); exit (1); } strcpy (cfg_file, getenv ("HOME")); strncat (cfg_file, RC_FILE, 255 - strlen (cfg_file)); if (db_file = fopen (cfg_file, "r")) { cfgParse (cfg_file, cfg, CFG_SIMPLE); fclose (db_file); } else { free (cfg_file); cfg_file = strdup (CONFIGDIR); if (db_file = fopen (cfg_file, "r")) { cfgParse (cfg_file, cfg, CFG_SIMPLE); fclose (db_file); } else { fprintf (stderr, "ERROR: No conf file in $HOME%s or %s!\n", RC_FILE, CONFIGDIR); exit (1); } } if (!sidplay) { fprintf (stderr, "ERROR: SIDPLAY not set in rc file!\n"); exit (1); } kill_sidplayo (sidplay); if (argc < 2) return 0; if (!strcmp (argv[1], "-h") || !strncmp (argv[1], "--help", strlen (argv[1]))) { usage (argv[0]); return 0; } else if (strcmp (argv[argc - 1] + strlen (argv[argc - 1]) - 4, SID_SUFFIX) == 0) { cmd_len = strlen (sidplay); cmd_len += strlen (sidplay_args); for (i = 0; i < argc; i++) cmd_len += strlen (argv[i]) + 4; if (!(command = (char *)malloc (sizeof (char) * cmd_len))) { fprintf (stderr, "ERROR: Out of memory!\n"); exit (1); } strcpy (command, sidplay); strcat (command, " "); strcat (command, sidplay_args); for (i = 1; i < (argc - 1); i++) { strcat (command, " "); strcat (command, argv[i]); } strcat (command, " "); strcat (command, " \""); temp = argv[argc - 1]; while (temp2 = strchr (temp, '\"')) { if ((strlen (command) + (temp2 - temp)) > 511) { fprintf (stderr, "ERROR: Too long input, exiting.\n"); exit (1); } strcat (command, temp); strcat (command, "\\\""); temp = temp2 + 1; } strcat (command, temp); strcat (command, "\" &"); } else { cmd_len = strlen (sidplay); cmd_len += strlen (sidplay_args); cmd_len += 8; for (i = 0; i < argc; i++) cmd_len += strlen (argv[i]) + 4; if (!(command = (char *)malloc (sizeof (char) * cmd_len))) { fprintf (stderr, "ERROR: Out of memory!\n"); exit (1); } strcpy (command, "zcat \""); temp = argv[argc - 1]; while (temp2 = strchr (temp, '\"')) { if ((strlen (command) + (temp2 - temp)) > 511) { fprintf (stderr, "ERROR: Too long input, exiting.\n"); exit (1); } strcat (command, temp); strcat (command, "\\\""); temp = temp2 + 1; } strcat (command, temp); strcat (command, "\" | "); strcat (command, sidplay); strcat (command, " "); strcat (command, sidplay_args); strcat (command, " -"); for (i = 1; i < (argc - 1); i++) { strcat (command, argv[i]); strcat (command, " "); } strcat (command, " &"); } if (!strstr (command, SID_SUFFIX)) { usage (argv[0]); return 1; } assert (cmd_len > strlen (command)); tmp = popen (command, "r"); if (!tmp) { fprintf(stderr, "Couldn't run sidplay!\n"); exit(1); } while (!feof (tmp)) { fgets (info, 255, tmp); if (!info) break; if (strstr (info, "^C") != 0) break; else if ((strstr (info, "-------") == 0) && (strcmp (info, "\n"))) printf ("%s", info); else continue; } pclose (tmp); printf ("\n"); return 0; }