コード例 #1
0
ファイル: fc.c プロジェクト: sharpglasses/ServerSkeleton
static void _asn_fcdir(thash *hash, const char *path, mmatic *mm)
{
	struct dirent *dirp;
	DIR *subd;
	char *np, *v;
	uint32_t len;

	if (!(subd = opendir(path)))
		die("opendir(%s) failed: %m\n", path);

	while ((dirp = readdir(subd))) {
		if (dirp->d_name[0] == '.') continue;

		np = (streq(path, ".")) ? dirp->d_name : mmprintf("%s/%s", path, dirp->d_name);
		if (asn_isdir(np) == 1) {
			_asn_fcdir(hash, np, mm);
		}
		else {
			v = asn_readfile(np, mm);
			if (!v) die("%s: could not read config file (%m)\n", np); /* fopen() failed */

			/* trim endlines at the end */
			len = strlen(v);
			if (len && v[len-1] == '\n') v[len-1] = '\0';

			thash_set(hash, np, v);
		}
	}

	closedir(subd);
}
コード例 #2
0
ファイル: media_menu.c プロジェクト: Bilalh/Media
// prints each series in the hash, also stores a pointer 
// for each series indexed by the order printed in eps_ptr
static void print_menu(Eps** eps_ptr, Eps *hash ) {
	
	sqlite3 *db;
	int result;
	
	result = sqlite3_open(DATABASE, &db);
	if( result ) {
		efprintf("show_menu failed: %s\n", sqlite3_errmsg(db));
		sqlite3_close(db);
		exit(23);
	}
	
	sqlite3_stmt *statement_h;
	const char *query_h = "select current from SeriesData where Title = ?";
	sqlite3_prepare_v2(db, query_h, (int) strlen(query_h), &statement_h, NULL);
	
	int index =0;
	// Prints each series of a separate row
	for(Eps *e=hash; e != NULL; e=e->hh.next, ++index) {
		
		// uses a array indexing index to series then use that to select the right series
		eps_ptr[index] =  e;
		bool ordered = true;
		
		qsort_b(e->eps->arr, e->eps->index, sizeof(size_t),
				^(const void *a, const void *b){
					const Ep *ea = *((Ep**)a), *eb = *((Ep**)b);
					mmprintf("%ld %ld res: %d\n", ea->num, eb->num, longcmp( ea->num, eb->num ) );
					return longcmp( ea->num , eb->num );
				}
				);
		
		
		if (e->eps->index > 1){
			for(int i = 0; i<e->eps->index-1;i++){
				if (EPS_ARR(e,i+1)->num != 1 + EPS_ARR(e,i)->num){
					ordered = false;
					break;
				}
			}
			
		}
		
		sqlite3_bind_text(statement_h, 1, e->series, -1, SQLITE_TRANSIENT);
		result = sqlite3_step(statement_h);
		mmprintf("r:%i Row:%i Ok:%i done:%i \n", result, SQLITE_ROW, SQLITE_OK, SQLITE_DONE );
		
		int current =-1;
		if (result == SQLITE_ROW||  result == SQLITE_OK  || result == SQLITE_DONE){
			
			current = sqlite3_column_int(statement_h, 0);
			mmprintf("current:%d\n",current );			
			
		}else{
			efprintf(  "SQL error %s : %s\n", e->series, sqlite3_errmsg(db));
			exit(12);
		}
		
			
		// Printing
		
		printf( SSS("%-2d") " :", COLOUR(index,GREEN));
		printf(" P: " SSS("%-2d"), COLOUR(current,WHITE));
		printf(" N: ");
		
		if (ordered && e->eps->index > 1 ){ // Range of eps
			printf(SSS("%4ld") SSS("-%-4ld"), 
				   COLOUR(EPS_ARR(e,0)->num, BLUE), COLOUR(EPS_ARR(e,e->eps->index-1)->num,BLUE)
				   );
			
		}else if (e->eps->index == 1){ // single ep
			const int extra = (3-1)*3;
			printf(SSS("%2ld") " %*s", COLOUR(EPS_ARR(e,0)->num, YELLOW), extra,"" );
			
		}else{ // range with eps missing (only shows the fist three)	
			const int min =  e->eps->index < 3 ? e->eps->index :3;
			const int extra = (3-min)*3;
			for(int i = 0; i<min;i++){
				printf(SSS("%2ld") " %*s", COLOUR(EPS_ARR(e,i)->num, RED), extra,"" );
			}
		}
		
		printf(" %s\n", e->series);
		result = sqlite3_reset(statement_h);
    }