Example #1
0
static int * bgscan_learn_get_supp_freqs(struct wpa_supplicant *wpa_s)
{
	struct hostapd_hw_modes *modes;
	int i, j, *freqs = NULL, *n;
	size_t count = 0;

	modes = wpa_s->hw.modes;
	if (modes == NULL)
		return NULL;

	for (i = 0; i < wpa_s->hw.num_modes; i++) {
		for (j = 0; j < modes[i].num_channels; j++) {
			if (modes[i].channels[j].flag & HOSTAPD_CHAN_DISABLED)
				continue;
			/* some hw modes (e.g. 11b & 11g) contain same freqs */
			if (in_array(freqs, modes[i].channels[j].freq))
				continue;
			n = os_realloc_array(freqs, count + 2, sizeof(int));
			if (n == NULL)
				continue;

			freqs = n;
			freqs[count] = modes[i].channels[j].freq;
			count++;
			freqs[count] = 0;
		}
	}

	return freqs;
}
Example #2
0
extern "C" resposta getmatch(const string url) {
    resposta r;	
	
	vector<string> black_list; // tudo para não usar array? o que tem de mais em um array...
	black_list.push_back ("ave2.info.gz");
	black_list.push_back ("info-wks-classic-nt-en.info.gz");
	black_list.push_back ("specvir-nt.info.gz");
	black_list.push_back ("vdf.info.gz");
	black_list.push_back ("classic-nt-en.info.gz");
	
	if ( ( (url.find(".avgate.net/") != string::npos) or (url.find(".avgate.com/") != string::npos) or
		   (url.find(".freeav.net/") != string::npos) or (url.find(".freeav.com/") != string::npos) )  and
	     ( (url.find(".gz") != string::npos) or (url.find(".zip") != string::npos) or (url.find(".exe") != string::npos) ) and 
		 (in_array(url, black_list) == false)
	) {
		
	    r.file = get_filename(url);
		if (!r.file.empty()) {
			r.match = true;
			r.domain = "avgate";
		} else {
			r.match = false;
		}
	} else {
		r.match = false;
	}
	return r;
}
Example #3
0
static int * bgscan_learn_get_probe_freq(struct bgscan_learn_data *data,
					 int *freqs, size_t count)
{
	int idx, *n;

	if (data->supp_freqs == NULL)
		return freqs;

	idx = data->probe_idx;
	do {
		if (!in_array(freqs, data->supp_freqs[idx])) {
			wpa_printf(MSG_DEBUG, "bgscan learn: Probe new freq "
				   "%u", data->supp_freqs[idx]);
			data->probe_idx = idx + 1;
			if (data->supp_freqs[data->probe_idx] == 0)
				data->probe_idx = 0;
			n = os_realloc_array(freqs, count + 2, sizeof(int));
			if (n == NULL)
				return freqs;
			freqs = n;
			freqs[count] = data->supp_freqs[idx];
			count++;
			freqs[count] = 0;
			break;
		}

		idx++;
		if (data->supp_freqs[idx] == 0)
			idx = 0;
	} while (idx != data->probe_idx);

	return freqs;
}
Example #4
0
// Returns true if the given signature could possibly match an invocation where
// the given tag maps to the given value.
static bool can_match_eq(value_t signature, value_t tag, value_t value) {
  int64_t paramc = get_signature_parameter_count(signature);
  // First look for a matching parameter in the signature.
  value_t match = nothing();
  for (int64_t i = 0; i < paramc; i++) {
    value_t param = get_signature_parameter_at(signature, i);
    value_t tags = get_parameter_tags(param);
    if (in_array(tags, tag)) {
      match = param;
      break;
    }
  }
  if (is_nothing(match)) {
    // There was no matching parameter so this can only match if the signature
    // permits it as an extra argument.
    return get_signature_allow_extra(signature);
  } else {
    value_t guard = get_parameter_guard(match);
    if (get_guard_type(guard) == gtEq) {
      value_t eq_value = get_guard_value(guard);
      return value_identity_compare(value, eq_value);
    } else {
      return true;
    }
  }
}
Example #5
0
// Returns the verse text given a $verse_number and $usfm code.
// Handles combined verses.
string usfm_get_verse_text (string usfm, int verse_number)
{
  vector <string> result;
  bool hit = (verse_number == 0);

  vector <string> lines = filter_string_explode (usfm, '\n');
  for (string line : lines) {
    vector <int> verses = usfm_get_verse_numbers (line);
    if (verse_number == 0) {
      if (verses.size () != 1) hit = false;
      if (hit) result.push_back (line);
    } else {
      if (in_array (verse_number, verses)) {
        // Desired verse found.
        hit = true;
      } else if (verses.size () == 1) {
        // No verse found: No change in situation.
      } else {
        // Outside desired verse.
        hit = false;
      }
      if (hit) result.push_back (line);
    }
  }
  
  // Return the verse text.
  string verseText = filter_string_implode (result, "\n");
  return verseText;
}
Example #6
0
colog_matches_t match(const char *pattern, const char *source)
{
  colog_matches_t matches;
  int analyzed_length;
  char* extract = NULL;
  char* analyzed = xalloc((strlen(source) + 1) * sizeof(char));
  char* tmp;
  int cont = 1;

  matches.list = NULL;
  matches.length = 0;
  strcpy(analyzed, source);
  while (cont) {
    extract = execute_regex(pattern, analyzed);
    if (extract) {
      if (!in_array(extract, matches.list, matches.length)) {
        matches.list = xrealloc(matches.list, (matches.length + 1) * sizeof(char *));
        matches.list[matches.length] = xalloc((strlen(extract) + 1) * sizeof(char));
        strcpy(matches.list[matches.length], extract);
        matches.length++;
        tmp = str_replace(analyzed, extract, "");
        free(analyzed);
        analyzed = tmp;
      }
      free(extract);
    } else {
      cont = 0;
    }
  }
  free(analyzed);

  return matches;
}
Example #7
0
int draw_shape(shape s, int board_x, int board_y){

	int i, j;
	int * map;
	int * (*map_func)(int i, int j) = get_map_func(s, 0);

	int y_vals[4];
	int height = 0;

	attron(COLOR_PAIR(s.type+1));

	for(i = 0; i < 4; i++){
		for(j = 0; j < 4; j++){
			map = map_func(i , j);

			if(CHECK_BIT(shape_bytes[s.type][BYTE_MAP(map)], BIT_MAP(map))){

				mvaddch(s.y + Y_MAP(map) + board_y, ((s.x + X_MAP(map))*2)  + (board_x) + 1,  ' '|A_REVERSE);
				mvaddch(s.y + Y_MAP(map) + board_y, ((s.x + X_MAP(map))*2) + (board_x) + 2,  ' '|A_REVERSE);

				if(!in_array(s.y + Y_MAP(map), y_vals, 4)){
					y_vals[height] = s.y + Y_MAP(map);
					height++;
				}
			}/*else{
				mvaddch(s.y + Y_MAP(map) + board_y, ((s.x + X_MAP(map))*2)  + (board_x*2) + 1,  'x');
				mvaddch(s.y + Y_MAP(map) + board_y, ((s.x + X_MAP(map))*2) + (board_x*2) + 2,  'x');
			}*/
			
		}
	}
	attroff(COLOR_PAIR(s.type+1));

	return height;
}
void init( struct gameState *g, char **argv )
{
    int seed, k[ 10 ], num_players, val, i;

    seed = atoi( argv[ 1 ] );
    srand( seed );

    // min 2 players
    num_players = rand() % ( MAX_PLAYERS - 2 ) + 2;

    // select kingdom cards
    for ( i = 0; i < 10; i++ )
    {
        do
        {
            val = rand() % ( K_CARD_MAX - K_CARD_MIN ) + K_CARD_MIN;
        }
        while ( in_array( val, k, i + 1 ) );

        k[ i ] = val;
    }

    if ( initializeGame( num_players, k, seed, g ) == -1 )
    {
        printf( "Call to initializeGame failed\n" );
        exit( 1 );
    }
}
Example #9
0
void Checks_Verses::missingPunctuationAtEnd (string bible, int book, int chapter, map <int, string> verses,
                                             string center_marks, string end_marks)
{
  vector <string> centermarks = filter_string_explode (center_marks, ' ');
  vector <string> endmarks = filter_string_explode (end_marks, ' ');
  Database_Check database_check;
  for (auto element : verses) {
    int verse = element.first;
    string text = element.second;
    if (verse == 0) continue;
    if (text.empty ()) continue;
    size_t text_length = unicode_string_length (text);
    string lastCharacter = unicode_string_substr (text, text_length - 1, 1);
    if (in_array (lastCharacter, centermarks)) continue;
    if (in_array (lastCharacter, endmarks)) continue;
    database_check.recordOutput (bible, book, chapter, verse, "No punctuation at end of verse: " + lastCharacter);
  }
}
Example #10
0
string checks_suppress (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;
  Database_Check database_check;
  
  
  string page;
  page = Assets_Page::header (translate ("Suppressed check results"), webserver_request);
  Assets_View view;
  
  
  if (request->query.count ("release")) {
    int release = convert_to_int (request->query["release"]);
    database_check.release (release);
    view.set_variable ("success", translate("The check result is no longer suppressed."));
  }
  
                        
  // Get the Bibles the user has write-access to.
  vector <string> bibles;
  {
    vector <string> all_bibles = request->database_bibles()->getBibles ();
    for (auto bible : all_bibles) {
      if (access_bible_write (webserver_request, bible)) {
        bibles.push_back (bible);
      }
    }
  }
  
  
  string block;
  vector <Database_Check_Hit> suppressions = database_check.getSuppressions ();
  for (auto suppression : suppressions) {
    string bible = suppression.bible;
    // Only display entries for Bibles the user has write access to.
    if (in_array (bible, bibles)) {
      int id = suppression.rowid;
      bible = filter_string_sanitize_html (bible);
      string passage = filter_passage_display_inline ({Passage ("", suppression.book, suppression.chapter, convert_to_string (suppression.verse))});
      string result = filter_string_sanitize_html (suppression.data);
      result.insert (0, bible + " " + passage + " ");
      block.append ("<p style=\"color:grey;\">\n");
      block.append ("<a href=\"suppress?release=" + convert_to_string (id) + "\">\n");
      block.append (emoji_wastebasket () + "\n");
      block.append ("</a>\n");
      block.append (result + "\n");
      block.append ("</p>\n");
    }
  }
  view.set_variable ("block", block);
  
  
  page += view.render ("checks", "suppress");
  page += Assets_Page::footer ();
  return page;
}
Example #11
0
// This runs on the server.
// It gets the html or text contents for a $resource for serving it to a client.
string resource_logic_get_contents_for_client (string resource, int book, int chapter, int verse)
{
  // Lists of the various types of resources.
  Database_UsfmResources database_usfmresources;
  vector <string> externals = resource_external_names ();
  vector <string> usfms = database_usfmresources.getResources ();
  
  // Possible SWORD details in case the client requests a SWORD resource.
  string sword_module = sword_logic_get_remote_module (resource);
  string sword_source = sword_logic_get_source (resource);
  
  // Determine the type of the current resource.
  bool isExternal = in_array (resource, externals);
  bool isUsfm = in_array (resource, usfms);
  bool isSword = (!sword_source.empty () && !sword_module.empty ());
  
  if (isExternal) {
    // The server fetches it from the web.
    return resource_external_cloud_fetch_cache_extract (resource, book, chapter, verse);
  }
  
  if (isUsfm) {
    // Fetch from database and convert to html.
    string chapter_usfm = database_usfmresources.getUsfm (resource, book, chapter);
    string verse_usfm = usfm_get_verse_text (chapter_usfm, verse);
    string stylesheet = styles_logic_standard_sheet ();
    Filter_Text filter_text = Filter_Text (resource);
    filter_text.html_text_standard = new Html_Text ("");
    filter_text.addUsfmCode (verse_usfm);
    filter_text.run (stylesheet);
    return filter_text.html_text_standard->getInnerHtml ();
  }
  
  if (isSword) {
    // Fetch it from a SWORD module.
    return sword_logic_get_text (sword_source, sword_module, book, chapter, verse);
  }

  // Nothing found.
  return "Bibledit Cloud could not localize this resource";
}
Example #12
0
void	evolvi (short unsigned* shm, short unsigned* local,int* n_gen,
		short* s,short size_s,short* b,short size_b)
{

	int x, y;
	short vivi;
	
	P(sem_id_counter,0);
	inuso=P(sem_id,0);
	
	for( y=0; y < N_Y; ++y )
	{
		for( x=start_x; x < stop_x; ++x )
		{
			vivi=vicini_vivi(x,y,local);

			switch( get_stato(x,y,local)) 
			{
				case VIVO:	// S
					if( in_array(vivi,s,size_s) )
						fiat(x,y,shm);
					else
						uccidi(x,y,shm);
					break;
				case MORTO:	// B
					if( in_array(vivi,b,size_b) )
						fiat(x,y,shm);
					else
						uccidi(x,y,shm);
					break;
				default:	// ?
					printf("ERROR");
					break;
			}
		}
	}
	
	inuso=V(sem_id,0);
	//Z(sem_id_counter,0);
}
Example #13
0
void depth_first(ELE tos) {
	int i;
	if(in_array(finished, findex, tos->val)) {
		return;
	}
	printf("%d ", tos->val);
	stk=push_stack(stk, tos);
	push_array(finished, &findex, tos->val);
	for(i=0;i<=tos->n_child;i++) {
		depth_first(tos->child[i]);
	}
	stk=pop_stack(stk);
}
Example #14
0
int main()
{
    try {
        cl::Context context;
        std::vector<cl::Device> devices;
        std::tie(context, devices) = init_open_cl();
        cl::CommandQueue queue(context, devices[0]);
        cl::Program program = load_program("program.cl", context, devices);
        cl_fn reduce_fn(program, "do_reduce");
        cl_fn sweep_fn(program, "do_sweep");

        std::ifstream in(INPUT_FILE);
        size_t n, npow2;
        in >> n;
        npow2 = pow(2.0, ceil(log2(n)));
        std::vector<float> in_array(npow2);
        for (size_t i = 0; i < n; ++i)
            in >> in_array[i];

        cl::Buffer out_buf(context, std::begin(in_array), std::end(in_array), false);
        std::vector<cl::Event> events;

        for (size_t offset = 1; npow2 / (offset * 2) >= WORKGROUP_SIZE; offset *= 2)
            exec_fn(reduce_fn, out_buf, npow2, offset, npow2 / offset, events, queue);

        if (npow2 < 512)
            exec_fn(reduce_fn, out_buf, npow2, 1, WORKGROUP_SIZE, events, queue);

        exec_fn(sweep_fn, out_buf, npow2, npow2 / 2, WORKGROUP_SIZE, events, queue);

        for (size_t offset = npow2 / 1024; offset > 0; offset /= 2)
            exec_fn(sweep_fn, out_buf, npow2, offset, npow2 / offset, events, queue);

        std::vector<float> out_array(n);
        queue.enqueueReadBuffer(out_buf, CL_TRUE, 0, sizeof(float) * n, &out_array[0]);

        std::ofstream out(OUTPUT_FILE);
        out << std::fixed << std::setprecision(3);
        for (size_t i = 0; i < n; i++)
            out << out_array[i] << " ";
        out << std::endl;
    }
    catch (cl::Error &e) {
        std::cerr << "ERROR: " << e.what() << " (" << e.err() << ")" << std::endl;
    }
    catch (std::runtime_error &e) {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}
Example #15
0
int is_valid_expression(const char *str)
{
    int i, res, valid = 0;
    char operation;

    res = sscanf(str, "%f %c %f", &f1, &operation, &f2);
    
    if(!in_array(operation, valid_ops, ops_s)) {
        return 0;
    }

    op = operation;

    return res == 3;
}
Example #16
0
static void unset_environ_except(char **except) {
	char **tmp = environ;
	while (*tmp) {
		char* pos = strchr(*tmp, '=');
		if (pos != NULL) {
			char *key = strndup(*tmp, pos-*tmp);
			if (!in_array(except, key))
				unsetenv(key);
			free(key);
		} else {
			DEBUG_MSG("problem with %s\n",*tmp);
		}
		tmp++;
	}
}
Example #17
0
const int		p_operand(t_op *operation, int *i)
{
  int			j;

  j = 0;
  while ((in_array(operation->input[*i + j], operation->operands))
	 != RETURN_FAILURE)
    ++j;
  if ((push_back(operation->lexeme_list,
		 my_strndup(&(operation->input[*i]), j)))
      == RETURN_FAILURE)
    return (RETURN_FAILURE);
  if ((operation->lexeme_list->back->content =
       uniform_result(operation->lexeme_list->back->content, operation->operands,
		      operation->operators[3])) == NULL)
    return (RETURN_FAILURE);
  operation->lexeme_list->back->type = P_OPERAND;
  *i += j;
  return (RETURN_SUCCESS);
}
Example #18
0
int find_max_plus(int a[], int sz)
{
//	/*int*/ a = merge_sort(a,0,sz-1,1);
//	print_array(a2,sz);
//	print_array(a,sz);
	int** mat = (int**)malloc(sizeof(int*)*(sz-1));	
	int i,j,k = 0;
	for(i=0;i<(sz-1);i++)
	{
		mat[i] = (int*)malloc(sizeof(int)*(i+1));
	}
	for(i=0;i<=(sz-1-1);i++)	
	{
		for(j=0;j<(i+1);j++)
		{
			mat[i][j] = a[i+1] + a[j];
			printf("%d ",mat[i][j]);
		}
		printf("\n");
	}

	int* arr = (int*) malloc(sizeof(int)*(sz)*(sz-1)/2);

	for(i=0;i<=(sz-1-1);i++)	
		for(j=0;j<(i+1);j++)
			arr[k++] = mat[i][j];
	printf("\n");
	print_array(arr,sz*(sz-1)/2);
//	arr = merge_sort(arr,0,sizeof(arr)/sizeof(int)-1,1);
	k = -99999999;
	 
	for(i=0;i<sz*(sz-1)/2;i++)
	{
//		printf("arr[%d] = %d\n",i,arr[i]);
		if( (k < arr[i]) && (in_array(a,sz,arr[i])==1) )
			k = arr[i];
	}
	return k;
}
Example #19
0
static int * bgscan_learn_get_freqs(struct bgscan_learn_data *data,
				    size_t *count)
{
	struct bgscan_learn_bss *bss;
	int *freqs = NULL, *n;

	*count = 0;

	dl_list_for_each(bss, &data->bss, struct bgscan_learn_bss, list) {
		if (in_array(freqs, bss->freq))
			continue;
		n = os_realloc_array(freqs, *count + 2, sizeof(int));
		if (n == NULL)
			return freqs;
		freqs = n;
		freqs[*count] = bss->freq;
		(*count)++;
		freqs[*count] = 0;
	}

	return freqs;
}
Example #20
0
int is_multiple_of(long number, int base)
{

	int remainders[0];
	int size_rem = 0;

	//printf("Base is %d\n", base);
	if (base == 2)
	{
		size_rem = 30;
		int remainders[30] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58};
		//memcpy(remainders, remainders2, sizeof(remainders2));
	}
	if (base == 3)
	{
		size_rem = 10;
		int remainders[10] = {3, 9, 15, 21, 27, 33, 39, 45, 51, 57};
		//memcpy(remainders, remainders3, sizeof(remainders3));
	}
	if (base == 5)
	{
		size_rem = 4;
		int remainders[4] = {5, 25, 35, 55};
		//memcpy(remainders, remainders5, sizeof(remainders5));
	}

	//printf("Testing %ld as multiple of %d\n", number, base);
	number = number % 60;
	if (in_array(number, remainders, size_rem) != 0)
	{
		//printf("\n%ld is multiple of %d\n", number, base);
		return true;
	}

	return false;
}
Example #21
0
string resource_get (void * webserver_request)
{
    Webserver_Request * request = (Webserver_Request *) webserver_request;


    vector <string> bits;


    string s_resource = request->query["resource"];
    string s_book = request->query["book"];
    string s_chapter = request->query["chapter"];
    string s_verse = request->query["verse"];


    if (!s_resource.empty () && !s_book.empty () && !s_chapter.empty () && !s_verse.empty ()) {


        unsigned int resource = convert_to_int (s_resource);
        int book = convert_to_int (s_book);
        int chapter = convert_to_int (s_chapter);
        int verse = convert_to_int (s_verse);


        // In JavaScript the resource identifier starts at 1 instead of at 0.
        resource--;
        vector <string> resources = request->database_config_user()->getActiveResources ();
        if (resource <= resources.size ()) {
            s_resource = resources [resource];


            // Handle a divider.
            if (resource_logic_is_divider (s_resource)) return resource_logic_get_divider (s_resource);


            string bible = request->database_config_user ()->getBible ();
            string versification = Database_Config_Bible::getVersificationSystem (bible);
            Database_Versifications database_versifications;
            vector <int> chapters = database_versifications.getChapters (versification, book);


            // Whether to add extra verse numbers, for clarity in case of viewing more than one verse.
            bool add_verse_numbers = false;
            int context_before = request->database_config_user ()->getResourceVersesBefore ();
            if (context_before) add_verse_numbers = true;
            int context_after = request->database_config_user ()->getResourceVersesAfter ();
            if (context_after) add_verse_numbers = true;


            // Context before the focused verse.
            vector <int> chapters_before;
            vector <int> verses_before;
            if (context_before > 0) {
                for (int ch = chapter - 1; ch <= chapter; ch++) {
                    if (in_array (ch, chapters)) {
                        vector <int> verses = database_versifications.getVerses (versification, book, ch);
                        for (size_t vs = 0; vs < verses.size (); vs++) {
                            int vs2 = verses [vs];
                            if ((ch < chapter) || (vs2 < verse)) {
                                if (vs2 > 0) {
                                    chapters_before.push_back (ch);
                                    verses_before.push_back (verses[vs]);
                                }
                            }
                        }
                    }
                }
                while ((int)chapters_before.size () > context_before) {
                    chapters_before.erase (chapters_before.begin ());
                    verses_before.erase (verses_before.begin ());
                }
            }
            for (unsigned int i = 0; i < chapters_before.size (); i++) {
                bits.push_back (resource_logic_get_html (request, s_resource, book, chapters_before[i], verses_before[i], add_verse_numbers));
            }


            // Focused verse.
            bits.push_back (resource_logic_get_html (request, s_resource, book, chapter, verse, add_verse_numbers));


            // Context after the focused verse.
            vector <int> chapters_after;
            vector <int> verses_after;
            if (context_after > 0) {
                for (int ch = chapter; ch <= chapter + 1; ch++) {
                    if (in_array (ch, chapters)) {
                        vector <int> verses = database_versifications.getVerses (versification, book, ch);
                        for (size_t vs = 0; vs < verses.size (); vs++) {
                            int vs2 = verses [vs];
                            if ((ch > chapter) || (vs2 > verse)) {
                                if (vs2 > 0) {
                                    chapters_after.push_back (ch);
                                    verses_after.push_back (verses[vs]);
                                }
                            }
                        }
                    }
                }
                while ((int)chapters_after.size () > context_after) {
                    chapters_after.pop_back ();
                    verses_after.pop_back ();
                }
            }
            for (unsigned int i = 0; i < chapters_after.size (); i++) {
                bits.push_back (resource_logic_get_html (request, s_resource, book, chapters_after[i], verses_after[i], add_verse_numbers));
            }
        }
    }


    string page = filter_string_implode (bits, ""); // <br>
    return page;
}
Example #22
0
// Cleans and resets the data in the Bibledit installation.
void demo_clean_data ()
{
  Database_Logs::log ("Cleaning up the demo data");

  
  Webserver_Request request;
  
  
  // Set user to the demo credentials (admin) as this is the user who is always logged-in in a demo installation.
  request.session_logic ()->setUsername (session_admin_credentials ());
  
  
  // Delete empty stylesheet that may have been there.
  request.database_styles()->revokeWriteAccess ("", styles_logic_standard_sheet ());
  request.database_styles()->deleteSheet ("");
  styles_sheets_create_all ();
  
  
  // Set the export stylesheet to "Standard" for all Bibles and the admin.
  vector <string> bibles = request.database_bibles()->getBibles ();
  for (auto & bible : bibles) {
    Database_Config_Bible::setExportStylesheet (bible, styles_logic_standard_sheet ());
  }
  request.database_config_user()->setStylesheet (styles_logic_standard_sheet ());
  
  
  // Set the site language to "Default"
  Database_Config_General::setSiteLanguage ("");
  
  
  // Ensure the default users are there.
  map <string, int> users = {
    make_pair ("guest", Filter_Roles::guest ()),
    make_pair ("member", Filter_Roles::member ()),
    make_pair ("consultant", Filter_Roles::consultant ()),
    make_pair ("translator", Filter_Roles::translator ()),
    make_pair ("manager", Filter_Roles::manager ()),
    make_pair (session_admin_credentials (), Filter_Roles::admin ())
  };
  for (auto & element : users) {
    if (!request.database_users ()->usernameExists (element.first)) {
      request.database_users ()->addNewUser(element.first, element.first, element.second, "");
    }
    request.database_users ()->updateUserLevel (element.first, element.second);
  }

  
  // Create / update sample Bible.
  demo_create_sample_bible ();


  // Create sample notes.
  demo_create_sample_notes (&request);
  
  
  // Create samples for the workbenches.
  demo_create_sample_workbenches (&request);
  
  
  // Set navigator to John 3:16.
  Ipc_Focus::set (&request, 43, 3, 16);
  
  
  // Set and/or trim resources to display.
  // Too many resources crash the demo: Limit the amount.
  vector <string> resources = request.database_config_user()->getActiveResources ();
  bool reset_resources = false;
  if (resources.size () > 25) reset_resources = true;
  vector <string> defaults = demo_logic_default_resources ();
  for (auto & name : defaults) {
    if (!in_array (name, resources)) reset_resources = true;
  }
  if (reset_resources) {
    resources = demo_logic_default_resources ();
    request.database_config_user()->setActiveResources (resources);
  }
  
  
  // No flipped basic <> advanded mode.
  request.database_config_user ()->setFlipInterfaceMode (false);
}
Example #23
0
string resource_cache (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;

  
  string resource = request->query ["resource"];
  
  
  string page;
  Assets_Header header = Assets_Header (menu_logic_resources_text (), request);
  header.addBreadCrumb (menu_logic_settings_menu (), menu_logic_settings_text ());
  page = header.run ();
  Assets_View view;

  
  if (request->query.count ("clear")) {
    sendreceive_resources_clear_all ();
  }
  vector <string> resources = Database_Config_General::getResourcesToCache ();
  if (!resources.empty ()) {
    view.enable_zone ("scheduled");
    view.set_variable ("scheduled", filter_string_implode (resources, " | "));
  }
  
  
  vector <string> listed_resources;
  string block;
  
  // Display the available USFM resources.
  resources = client_logic_usfm_resources_get ();
  for (auto & resource : resources) {
    block.append ("<p>");
    block.append ("<a href=\"download?name=" + resource + "\">" + resource + "</a>");
    block.append ("</p>\n");
  }
  listed_resources.insert (listed_resources.end (), resources.begin (), resources.end ());
  // Display the available external resources.
  resources = resource_external_names ();
  for (auto & resource : resources) {
    block.append ("<p>");
    block.append ("<a href=\"download?name=" + resource + "\">" + resource + "</a>");
    block.append ("</p>\n");
  }
  listed_resources.insert (listed_resources.end (), resources.begin (), resources.end ());
  // Display the available SWORD resources.
  resources = sword_logic_get_available ();
  for (auto & resource : resources) {
    string source = sword_logic_get_source (resource);
    string module = sword_logic_get_remote_module (resource);
    string name = "[" + source + "][" + module + "]";
    block.append ("<p>");
    block.append ("<a href=\"download?name=" + name + "\">" + resource + "</a>");
    block.append ("</p>\n");
  }
  listed_resources.insert (listed_resources.end (), resources.begin (), resources.end ());
  // Display any old USFM resources still available on the client.
  Database_UsfmResources database_usfmresources;
  resources = database_usfmresources.getResources ();
  for (auto & resource : resources) {
    if (in_array (resource, listed_resources)) continue;
    block.append ("<p>");
    block.append ("<a href=\"download?name=" + resource + "&old=yes\">" + resource + "</a>");
    block.append ("</p>\n");
  }
  // Display any offline resources still available on the client.
  Database_OfflineResources database_offlineresources;
  resources = database_offlineresources.names ();
  for (auto & resource : resources) {
    if (in_array (resource, listed_resources)) continue;
    block.append ("<p>");
    block.append ("<a href=\"download?name=" + resource + "&old=yes\">" + resource + "</a>");
    block.append ("</p>\n");
  }
  // Display the list.
  view.set_variable ("block", block);

  
  page += view.render ("resource", "cache");
  page += Assets_Page::footer ();
  return page;
}
Example #24
0
string public_index (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;


  // If the person providing public feedback is not logged in, foward to the page for entering details.
  if (!request->session_logic ()->loggedIn ()) {
    redirect_browser (request, public_login_url ());
    return "";
  }

  
  // Take the Bible for this user, and ensure that it is one of the Bibles that have public feedback enabled.
  string bible = request->database_config_user()->getBible ();
  vector <string> public_bibles = public_logic_bibles (webserver_request);
  if (!in_array (bible, public_bibles)) {
    bible.clear ();
    if (!public_bibles.empty ()) {
      bible = public_bibles [0];
    }
    request->database_config_user()->setBible (bible);
  }
  
  
  // Switch Bible before displaying the passage navigator because the navigator contains the active Bible.
  if (request->query.count ("bible")) {
    bible = request->query ["bible"];
    if (bible == "") {
      Dialog_List dialog_list = Dialog_List ("index", translate("Select which Bible to display"), "", "");
      for (auto & bible : public_bibles) {
        dialog_list.add_row (bible, "bible", bible);
      }
      Assets_Header header = Assets_Header ("", request);
      string page = header.run ();
      page += dialog_list.run();
      return page;
    } else {
      request->database_config_user()->setBible (bible);
    }
  }
  
  
  string page;
  Assets_Header header = Assets_Header (translate ("Public feedback"), request);
  header.setNavigator ();
  header.setStylesheet ();
  page = header.run ();
  Assets_View view;
  

  string stylesheet = Database_Config_Bible::getExportStylesheet (bible);

  
  bible = request->database_config_user()->getBible ();
  view.set_variable ("bible", bible);
  
  
  // If there's more than one Bible with public feedback enabled, the public can select a Bible.
  if (public_bibles.size () > 1) {
    view.enable_zone ("bibles");
  }

  
  string clss = Filter_Css::getClass (bible);
  string font = Fonts_Logic::getTextFont (bible);
  int direction = Database_Config_Bible::getTextDirection (bible);
  int lineheight = Database_Config_Bible::getLineHeight (bible);
  int letterspacing = Database_Config_Bible::getLetterSpacing (bible);
  view.set_variable ("custom_class", clss);
  view.set_variable ("custom_css", Filter_Css::getCss (clss,
                                                       Fonts_Logic::getFontPath (font),
                                                       direction,
                                                       lineheight,
                                                       letterspacing));
  
  Styles_Css styles_css = Styles_Css (&request, stylesheet);
  styles_css.exports ();
  styles_css.generate ();
  string css = styles_css.css ();
  view.set_variable ("exports_css", css);
  
  page += view.render ("public", "index");
  page += Assets_Page::footer ();
  return page;
}
Example #25
0
string resource_logic_get_html (void * webserver_request,
                                string resource, int book, int chapter, int verse,
                                bool add_verse_numbers)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;

  string html;
  
  Database_UsfmResources database_usfmresources;
  Database_ImageResources database_imageresources;
  Database_Mappings database_mappings;
  
  // Lists of the various types of resources.
  vector <string> bibles = request->database_bibles()->getBibles ();
  vector <string> usfms;
  if (config_logic_client_prepared ()) {
    usfms = client_logic_usfm_resources_get ();
    // As from February 2016 a client no longer automatically downloads USFM resources off the server.
    // But a client takes in account existing USFM resources it has downloaded before.
    vector <string> old_usfms = database_usfmresources.getResources ();
    usfms.insert (usfms.end (), old_usfms.begin (), old_usfms.end ());
  } else {
    usfms = database_usfmresources.getResources ();
  }
  vector <string> externals = resource_external_names ();
  vector <string> images = database_imageresources.names ();
  vector <string> lexicons = lexicon_logic_resource_names ();

  // Possible SWORD details.
  string sword_module = sword_logic_get_remote_module (resource);
  string sword_source = sword_logic_get_source (resource);
  
  // Determine the type of the current resource.
  bool isBible = in_array (resource, bibles);
  bool isUsfm = in_array (resource, usfms);
  bool isExternal = in_array (resource, externals);
  bool isImage = in_array (resource, images);
  bool isLexicon = in_array (resource, lexicons);
  bool isSword = (!sword_source.empty () && !sword_module.empty ());

  // Retrieve versification system of the active Bible.
  string bible = request->database_config_user ()->getBible ();
  string bible_versification = Database_Config_Bible::getVersificationSystem (bible);

  // Determine the versification system of the current resource.
  string resource_versification;
  if (isBible || isUsfm) {
    resource_versification = Database_Config_Bible::getVersificationSystem (bible);
  } else if (isExternal) {
    resource_versification = resource_external_mapping (resource);
  } else if (isImage) {
  } else if (isLexicon) {
    resource_versification = database_mappings.original ();
    if (resource == KJV_LEXICON_NAME) resource_versification = "English";
  } else if (isSword) {
    resource_versification = "English";
  } else {
  }

  // If the resource versification system differs from the Bible's versification system,
  // map the focused verse of the Bible to a verse in the Resource.
  // There are resources without versification system: Do nothing about them.
  vector <Passage> passages;
  if ((bible_versification != resource_versification) && !resource_versification.empty ()) {
    passages = database_mappings.translate (bible_versification, resource_versification, book, chapter, verse);
  } else {
    passages.push_back (Passage ("", book, chapter, convert_to_string (verse)));
  }

  // If there's been a mapping, the resource should include the verse number for clarity.
  if (passages.size () != 1) add_verse_numbers = true;
  for (auto passage : passages) {
    if (verse != convert_to_int (passage.verse)) {
      add_verse_numbers = true;
    }
  }
  
  for (auto passage : passages) {
    
    int book = passage.book;
    int chapter = passage.chapter;
    int verse = convert_to_int (passage.verse);
    
    string possible_included_verse;
    if (add_verse_numbers) possible_included_verse = convert_to_string (verse) + " ";
    if (isImage) possible_included_verse.clear ();
    
    html.append (resource_logic_get_verse (webserver_request, resource, book, chapter, verse));
  }
  
  return html;
}
Example #26
0
string resource_organize (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;

  
  string checkbox = request->post ["checkbox"];
  bool checked = convert_to_bool (request->post ["checked"]);

  
  if (request->query.count ("add") || request->post.count ("add")) {
    string add = request->query["add"];
    if (add.empty ()) add = request->post ["add"];
    vector <string> resources = request->database_config_user()->getActiveResources ();
    resources.push_back (add);
    request->database_config_user()->setActiveResources (resources);
    request->database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization);
  }
  
  
  if (request->query.count ("remove")) {
    size_t remove = convert_to_int (request->query["remove"]);
    vector <string> resources = request->database_config_user()->getActiveResources ();
    if (remove < resources.size ()) {
      resources.erase (resources.begin () + remove);
    }
    request->database_config_user()->setActiveResources (resources);
    request->database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization);
  }

  
  if (request->query.count ("moveup")) {
    size_t moveup = convert_to_int (request->query["moveup"]);
    vector <string> resources = request->database_config_user()->getActiveResources ();
    array_move_up_down (resources, moveup, true);
    request->database_config_user()->setActiveResources (resources);
    request->database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization);
  }

  
  if (request->query.count ("movedown")) {
    size_t movedown = convert_to_int (request->query["movedown"]);
    vector <string> resources = request->database_config_user()->getActiveResources ();
    array_move_up_down (resources, movedown, false);
    request->database_config_user()->setActiveResources (resources);
    request->database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization);
  }
  
  
  string page;
  Assets_Header header = Assets_Header (translate("Resources"), request);
  page = header.run ();
  Assets_View view;

  
  // Active resources.
  vector <string> active_resources = request->database_config_user()->getActiveResources ();
  string activesblock;
  for (size_t i = 0; i < active_resources.size (); i++) {
    activesblock.append ("<p>");
    activesblock.append ("<a href=\"?remove=" + convert_to_string (i) + "\">");
    activesblock.append (emoji_wastebasket ());
    activesblock.append ("</a>");
    activesblock.append (" ");
    activesblock.append ("<a href=\"?moveup=" + convert_to_string (i) + "\">");
    activesblock.append (unicode_black_up_pointing_triangle ());
    activesblock.append ("</a>");
    activesblock.append ("<a href=\"?movedown=" + convert_to_string (i) + "\">");
    activesblock.append (unicode_black_down_pointing_triangle ());
    activesblock.append ("</a>");
    activesblock.append (" ");
    activesblock.append (active_resources [i]);
    activesblock.append ("</p>");
    activesblock.append ("\n");
  }
  view.set_variable ("activesblock", activesblock);
  
  
  // Context before.
  if (request->query.count ("before")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("organize", translate("Please enter the number of verses"), convert_to_string (request->database_config_user ()->getResourceVersesBefore ()), "before", translate ("How many verses of context to display before the focused verse."));
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count ("before")) {
    int value = convert_to_int (request->post["entry"]);
    if ((value >= 0) && (value <= 100)) {
      request->database_config_user ()->setResourceVersesBefore (value);
    }
  }
  view.set_variable ("before", convert_to_string (request->database_config_user ()->getResourceVersesBefore ()));

  
  // Context after.
  if (request->query.count ("after")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("organize", translate("Please enter the number of verses"), convert_to_string (request->database_config_user ()->getResourceVersesAfter ()), "after", translate ("How many verses of context to display after the focused verse."));
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count ("after")) {
    int value = convert_to_int (request->post["entry"]);
    if ((value >= 0) && (value <= 100)) {
      request->database_config_user ()->setResourceVersesAfter (value);
    }
  }
  view.set_variable ("after", convert_to_string (request->database_config_user ()->getResourceVersesAfter ()));

  
  if (checkbox == "related") {
    request->database_config_user ()->setIncludeRelatedPassages (checked);
    return "";
  }
  view.set_variable ("related", get_checkbox_status (request->database_config_user ()->getIncludeRelatedPassages ()));

  
  if (request->query.count ("install")) {
    vector <string> usfm_resources = client_logic_usfm_resources_get ();
    vector <string> original_language_resources = resource_external_get_original_language_resources ();
    vector <string> bible_resources = resource_external_get_bibles ();
    vector <string> commentary_resources = resource_external_get_commentaries ();
    vector <string> general_resources = resource_external_get_general_resources ();
    vector <string> sword_resources = sword_logic_get_available ();
    vector <string> installable_resources;
    installable_resources.insert (installable_resources.end (), usfm_resources.begin (), usfm_resources.end ());
    installable_resources.insert (installable_resources.end (), original_language_resources.begin (), original_language_resources.end ());
    installable_resources.insert (installable_resources.end (), bible_resources.begin (), bible_resources.end ());
    installable_resources.insert (installable_resources.end (), commentary_resources.begin (), commentary_resources.end ());
    installable_resources.insert (installable_resources.end (), general_resources.begin (), general_resources.end ());
    installable_resources.insert (installable_resources.end (), sword_resources.begin (), sword_resources.end ());
    vector <string> installing_resources = Database_Config_General::getResourcesToCache ();
    vector <string> active_resources = request->database_config_user()->getActiveResources ();
    for (auto & resource : active_resources) {
      if (in_array (resource, installable_resources)) {
        if (!in_array (resource, installing_resources)) {
          installing_resources.push_back (resource);
          Database_Config_General::setResourcesToCache (installing_resources);
        }
      }
    }
    tasks_logic_queue (SYNCRESOURCES);
    view.set_variable ("success", translate ("Will install the resources.") + " " + translate ("The journal displays the progress."));
  }

  
#ifdef HAVE_CLIENT
  view.enable_zone ("client");
#endif

  
  page += view.render ("resource", "organize");
  page += Assets_Page::footer ();
  return page;
}
Example #27
0
int DecodeMultiColorSpriteGraphics (GifFileType *SpriteGif)
{
    int wwidth = 12; // wanted width
    // make sure we have the correct number of pixels
    if ((SpriteGif->SWidth % wwidth != 0) && SpriteGif->SHeight != 21)
    {
        fprintf (stderr, "Error: Incorrect dimensions: %dx%d\n", SpriteGif->SWidth, SpriteGif->SHeight);
        return 1;
    }

    // iterate over the raster bits
    unsigned char *raster = SpriteGif->SavedImages->RasterBits;

    int wscale = SpriteGif->SWidth / wwidth;
    int i, j, m = 0, row = 0; // iterators
    int colors[4] = { -1, -1, -1, -1 }; // palette values to store
    int cur, k, l; // current color, array indices
    for (m = 0; m < wscale; m++)
    {
        if (wscale > 1)
        {
            printf ("\n; sprite %x\n", m % 21);
        }
        for (i = 0; i < 252; i += 12)
        {
            printf ("\n\n\t; row %x", row++);
            for (j = 0; j < 12; j++)
            {
                if (j % 4 == 0) fputs ("\n\t.byte %", stdout);
                int index = (i * wscale + m * 12) + j;
                // world_is_a_fuck(wscale,index,12,21);
                // fprintf(stderr,"index %d\n",index);
                cur = raster[index];
                k = in_array (colors, cur);
                if (k == -1)
                {
                    l = in_array (colors, -1);
                    if (l == -1)
                    {
                        fputs ("ERROR: more than 4 colors in the palette\n", stderr);
                        fputs ("Color cache: { ", stderr);
                        int z;
                        for (z = 0; z < 4; z++)
                        {
                            fprintf (stderr, "%d, ", colors[z]);
                        }
                        fputs ("}\n", stderr);
                        return 1;
                    }
                    colors[l] = cur;
                    printf (bin (l), stdout);
                }
                else
                {
                    printf (bin (k), stdout);
                }
            }
        }

        fputs ("\n\t; padding byte\n\t.byte $00\n", stdout);
    }
    fputs ("\n", stdout);

    return 0;
}
bool Database_NoteAssignment::exists (string user, string assignee)
{
  vector <string> users = assignees (user);
  return in_array (assignee, users);
}
Example #29
0
// This is the most basic version that fetches the text of a $resource.
// It works on server and on client.
// It uses the cache.
string resource_logic_get_verse (void * webserver_request, string resource, int book, int chapter, int verse)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;

  string data;

  Database_UsfmResources database_usfmresources;
  Database_ImageResources database_imageresources;
  
  // Lists of the various types of resources.
  // As from February 2016 a client no longer automatically downloads USFM resources from the Cloud.
  // But a client takes in account existing USFM resources it has downloaded before.
  vector <string> bibles = request->database_bibles()->getBibles ();
  vector <string> local_usfms = database_usfmresources.getResources ();
  vector <string> remote_usfms;
  if (config_logic_client_prepared ()) {
    remote_usfms = client_logic_usfm_resources_get ();
  }
  vector <string> externals = resource_external_names ();
  vector <string> images = database_imageresources.names ();
  vector <string> lexicons = lexicon_logic_resource_names ();
  
  // Possible SWORD details.
  string sword_module = sword_logic_get_remote_module (resource);
  string sword_source = sword_logic_get_source (resource);
  
  // Determine the type of the current resource.
  bool isBible = in_array (resource, bibles);
  bool isLocalUsfm = in_array (resource, local_usfms);
  bool isRemoteUsfm = in_array (resource, remote_usfms);
  bool isExternal = in_array (resource, externals);
  bool isImage = in_array (resource, images);
  bool isLexicon = in_array (resource, lexicons);
  bool isSword = (!sword_source.empty () && !sword_module.empty ());
  
  if (isBible || isLocalUsfm) {
    string chapter_usfm;
    if (isBible) chapter_usfm = request->database_bibles()->getChapter (resource, book, chapter);
    if (isLocalUsfm) chapter_usfm = database_usfmresources.getUsfm (resource, book, chapter);
    string verse_usfm = usfm_get_verse_text (chapter_usfm, verse);
    string stylesheet = styles_logic_standard_sheet ();
    Filter_Text filter_text = Filter_Text (resource);
    filter_text.html_text_standard = new Html_Text ("");
    filter_text.addUsfmCode (verse_usfm);
    filter_text.run (stylesheet);
    data = filter_text.html_text_standard->getInnerHtml ();
  } else if (isRemoteUsfm) {
    data = resource_logic_client_fetch_cache_from_cloud (resource, book, chapter, verse);
  } else if (isExternal) {
    if (config_logic_client_prepared ()) {
      // A client fetches it from the cache or from the Cloud,
      // or, for older versions, from the offline resources database.
      // As of 12 December 2015, the offline resources database is not needed anymore.
      // It can be removed after a year or so.
      Database_OfflineResources database_offlineresources;
      if (database_offlineresources.exists (resource, book, chapter, verse)) {
        data = database_offlineresources.get (resource, book, chapter, verse);
      } else {
        data = resource_logic_client_fetch_cache_from_cloud (resource, book, chapter, verse);
      }
    } else {
      // The server fetches it from the web, via the http cache.
      data.append (resource_external_cloud_fetch_cache_extract (resource, book, chapter, verse));
    }
    
  } else if (isImage) {
    vector <string> images = database_imageresources.get (resource, book, chapter, verse);
    for (auto & image : images) {
      data.append ("<div><img src=\"/resource/imagefetch?name=" + resource + "&image=" + image + "\" alt=\"Image resource\" style=\"width:100%\"></div>");
    }
  } else if (isLexicon) {
    data = lexicon_logic_get_html (request, resource, book, chapter, verse);
  } else if (isSword) {
    data = sword_logic_get_text (sword_source, sword_module, book, chapter, verse);
  } else {
    // Nothing found.
  }
  
  // Any font size given in a paragraph style may interfere with the font size setting for the resources
  // as given in Bibledit. For that reason remove the class name from a paragraph style.
  for (unsigned int i = 0; i < 5; i++) {
    string fragment = "p class=\"";
    size_t pos = data.find (fragment);
    if (pos != string::npos) {
      size_t pos2 = data.find ("\"", pos + fragment.length () + 1);
      if (pos2 != string::npos) {
        data.erase (pos + 1, pos2 - pos + 1);
      }
    }
  }
  
  // NET Bible updates.
  data = filter_string_str_replace ("<span class=\"s ", "<span class=\"", data);

  return data;
}
Example #30
0
string resource_download (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;
  Database_UsfmResources database_usfmresources;
  
  
  string page;
  Assets_Header header = Assets_Header (translate("Download resource"), request);
  header.addBreadCrumb (menu_logic_settings_menu (), menu_logic_settings_text ());
  header.addBreadCrumb (resource_cache_url (), menu_logic_resources_text ());
  page = header.run ();
  Assets_View view;

  
  string name = request->query["name"];
  view.set_variable ("name", name);
  
  
  
  bool old = request->query.count ("old");
  if (old) view.enable_zone ("old");
  else view.enable_zone ("current");
                        
                      
  if (request->query.count ("clear")) {
    // The client clears the two older storage locations just to be sure they are gone.
    database_usfmresources.deleteResource (name);
    // The client clears the installed resource.
    Database_Cache::remove (name);
  }
  if (request->query.count ("clearold")) {
    // The client clears the two older storage locations just to be sure they are gone.
    database_usfmresources.deleteResource (name);
    redirect_browser (request, resource_cache_url ());
    return "";
  }
  
  
  if (request->query.count ("download")) {
    // Trigger caching the resource.
    // Add the resource to the general configuration to be cached, if it is not already there.
    vector <string> resources = Database_Config_General::getResourcesToCache ();
    if (!in_array (name, resources)) {
      resources.push_back (name);
      Database_Config_General::setResourcesToCache (resources);
    }
    tasks_logic_queue (SYNCRESOURCES);
    redirect_browser (request, journal_index_url ());
    return "";
  }
  
  
  int count = 0;
  if (count == 0) {
    vector <int> books = database_usfmresources.getBooks (name);
    for (auto book : books) {
      vector <int> chapters = database_usfmresources.getChapters (name, book);
      // Rough average of 20 verses per chapter.
      count += (20 * chapters.size());
    }
  }
  if (count == 0) count = Database_Cache::count (name);
  view.set_variable ("count", convert_to_string (count));
                      
                      
  page += view.render ("resource", "download");
  page += Assets_Page::footer ();
  return page;
}