Пример #1
0
// ---------------------------------------------------------------------------
int main(int argc, char* argv[]) {
  // load settings
  Settings_Load("play.conf");

  // initialize signal handlers
  signal(SIGINT, (sig_t)cleanup);
  signal(SIGPIPE, (sig_t)broken_pipe);
  atexit(exit_func);
  
  player = Settings_Get("program", "player");
  strcpy(current_song, Settings_Get("path", "current_song"));
  buffer_size = atol(Settings_Get("program", "buffer"));
  
  // reset current song
  FILE* song_file = fopen(current_song, "w");
  fprintf(song_file, "%s\n", " - ");
  fclose(song_file);
    
  // save program name and url to play
  url = argv[1];
  path = argv[0];
  
  // start the stream
  start_stream();
  
  // if done, cleanup
  Settings_Unload();
  return 0;
}
Пример #2
0
// ---------------------------------------------------------------------------
int main(int argc, char* argv[]) {
	// initialize signal handlers
	signal(SIGINT, (sig_t)cleanup);
	signal(SIGHUP, (sig_t)next_song);

	// load settings
	Settings_Load("play.conf");
	
	// start playing
	if(is_mp3(argv[1])) {
		start_player(Settings_Get("program", "player"), argv[1]);
	} else if(is_playlist(argv[1])) {
		// get path
		int i;
		for(i = strlen(argv[1]) - 1; i >= 0; i--) {
		  if(argv[1][i] == '/') {
		    strcpy(root_path, argv[1]);
		    root_path[i] = '\0';
		    break;
		  }
		}
		//printf("playlist\r\n");
		play_playlist(Settings_Get("program", "player"), argv[1]);
	}
	
	// done playing, reset id3 info
	FILE* f = fopen(Settings_Get("path", "current_song"), "w");
	fprintf(f, "(no artist) - (no title)\r\n");
	fclose(f);
	
	Settings_Unload();
	
	return 0;
}
Пример #3
0
// ---------------------------------------------------------------------------
int Settings_Load(char* file) {
	if(settings != NULL) Settings_Unload();
	settings = (SettingsFile*)malloc(sizeof(SettingsFile));
	settings->category = NULL;
	settings->cats = 0;
	FILE* f = fopen(file, "r");
	if(f == NULL) return 0;
	char buffer[256];
	char* line;
	int current_cat = -1;
	while(fgets(buffer, 256, f) != NULL) {
		line = trim(&buffer[0]);
		if(strlen(line) == 0) continue; // blank line
		if(line[0] == '#') continue; // just a comment
		// new category
		if(line[0] == '[') {
			line++;
			line[strlen(line) - 1] = 0;
			char* cat_name = (char*)malloc(sizeof(char) * (1 + strlen(line)));
            strcpy(cat_name, line);
			addCategory(cat_name);
            current_cat = settings->cats - 1;
            //printf("Cat: %s\r\n", line);
		}
		// new value
		else {
			// value without category -> error
			if(current_cat == -1) {
				fclose(f);
				return 0;
			}
			// get key and value
			char* ptr = strtok(line, "=");
			if(ptr == NULL) {
				fclose(f);
				return 0;
			}
			ptr = skipWhitespace(ptr);
			char* key = (char*)malloc(sizeof(char) * (1 + strlen(ptr)));
			strcpy(key, ptr);
			key = trim(key);
			ptr = strtok(NULL, "\1");
			//ptr += strlen(ptr) + 1;
			if(ptr == NULL) {
				fclose(f);
				return 0;
			}
			ptr = skipWhitespace(ptr);
			char* value = (char*)malloc(sizeof(char) * (1 + strlen(ptr)));
			strcpy(value, ptr);
			value = trim(value);
            addValue(current_cat, key, value);
            printf(" -> %s: %s\r\n", key, value);
		}
	}
	fclose(f);
	return 1;
}