예제 #1
0
파일: menu.cpp 프로젝트: mariuz/haiku
static bool
debug_menu_display_syslog(Menu* menu, MenuItem* item)
{
	ring_buffer* buffer = (ring_buffer*)gKernelArgs.debug_output;
	if (buffer == NULL)
		return true;

	struct TextSource : PagerTextSource {
		TextSource(ring_buffer* buffer)
			:
			fBuffer(buffer)
		{
		}

		virtual size_t BytesAvailable() const
		{
			return ring_buffer_readable(fBuffer);
		}

		virtual size_t Read(size_t offset, void* buffer, size_t size) const
		{
			return ring_buffer_peek(fBuffer, offset, buffer, size);
		}

	private:
		ring_buffer*	fBuffer;
	};

	pager(TextSource(buffer));

	return true;
}
예제 #2
0
KWin::WindowInfo *Desktop::windowAtPosition(const QPoint &p, QPoint *internalpos)
{
	QRect r;
	const QValueList<WId> &list(pager()->kwin()->stackingOrder());
	if (list.count() <= 0)
		return 0L;

	for (QValueList<WId>::ConstIterator it = list.fromLast(); ; --it)
	{
		KWin::WindowInfo* info = pager()->info( *it );
		if (shouldPaintWindow(info))
		{
			r=info->geometry();
			convertRectS2P(r);
			if (r.contains(p))
			{
				if (internalpos)
				{
					internalpos->setX(p.x()-r.x());
					internalpos->setY(p.y()-r.y());
				}
				return info;
			}
		}

		if (it == list.begin())
			break;
	}
	return 0L;
}
예제 #3
0
// start background thread
void datacloud::startthread()
   {
   int i;

   // check pending tile count
   if (PENDINGTILES==0) return;

   // non-threaded paging
   if (START_CALLBACK==NULL) pager();
   // threaded paging
   else
      for (i=1; i<=MAXTHREADS; i++)
         if (!ISRUNNING[i])
            {
            // wait for background thread to finish
            stopthread(i);

            // start new background thread
            ISRUNNING[i]=TRUE;
            ISREADY[i]=FALSE;
            ISNOTREADY=TRUE;
            START_CALLBACK(triggerpager,&BACKARRAY[i],START_DATA);
            NUMTHREADS++;
            }
   }
예제 #4
0
파일: mail.c 프로젝트: talkers/ew-too
 void read_letter(player *p,char *str)
 {
   char *oldstack,*which;
   saved_player *sp;
   note *mail;
   oldstack=stack;

   which=str;
   sp=p->saved;
   if (!sp) {
     tell_player(p,"You have no save info.\n");
     return;
   }

   mail=find_received(sp,atoi(which));
   if (!mail) {
     sprintf(stack,"No such letter '%s'\n",which);
     stack=end_string(stack);
     tell_player(p,oldstack);
     stack=oldstack;
     return;
   }
   get_string(stack,mail->text.where);
   stack=end_string(stack);
   pager(p,oldstack,0);
   p->saved_flags &= ~NEW_MAIL;
   stack=oldstack;	
 }
예제 #5
0
void Desktop::mousePressEvent( QMouseEvent * ev)
{
    bool showWindows= KPagerConfigDialog::m_showWindows;
    if (ev->button()==LeftButton){
	pressPos = ev->pos();
    }
    else if ((ev->button()==MidButton)&&(showWindows))
	startDrag(ev->pos());
    else if (ev->button()==RightButton) {
	QPoint pos;
	KWin::WindowInfo *info = windowAtPosition(ev->pos(), &pos);
	if ( info && showWindows )
	    pager()->showPopupMenu(info->win(), mapToGlobal(ev->pos()));
	else
	    pager()->showPopupMenu(0, mapToGlobal(ev->pos()));
    }
}
void TestPaginator::itemsCountChangesMakeCurrentPageInvalid_data()
{
    QTest::addColumn<TPaginator>("pager");
    QTest::addColumn<int>("itemsCount");
    QTest::addColumn<int>("expectedCurrentPage");

    TPaginator pager(158, 4, 5);
    pager.setCurrentPage(21);
    QTest::newRow("ItemsCount = Limit + 1") << pager << 5 << 1;
}
void TestPaginator::limitChangesMakeCurrentPageInvalid_data()
{
    QTest::addColumn<TPaginator>("pager");
    QTest::addColumn<int>("limit");
    QTest::addColumn<int>("expectedCurrentPage");

    TPaginator pager(158, 4, 5);
    pager.setCurrentPage(21);
    QTest::newRow("Limit = ItemsCount - 1") << pager << 157 << 1;
    QTest::newRow("Limit > ItemsCount") << pager << 200 << 1;
}
예제 #8
0
static void intercom_tell_player(char *str, int format)
{
  char *name, *msg;
  player *p;
  char *oldstack = stack, *stack_ptr, *end_ptr;

  name = str;

  if (!str || !*str)
  {
    log("error", "Empty message in intercom_tell_player");
    return;
  }
  msg = strchr(str, ':');
  if (msg)
    *msg++ = '\0';

  if (!msg || !*msg)
    return;

  p = find_player_global_quiet(name);

  if (!p)
    return;

  /*We have a player, p, so if we need to, format the output */
  if (format)
    msg = format_output(p, msg);

  /*Put the whole thing on the stack, so we can add a \n on it. This is thanks
     to Nevyn at Crazylands, cos he threw away process output and now Crazylands
     cant handle the \n at the end cos of colour code methods. */

  stack_ptr = stack;
  strcpy(stack_ptr, msg);
  stack = end_string(stack_ptr);
  end_ptr = stack - 1;

  if (end_ptr >= stack_ptr && *end_ptr != '\n')
  {
    sprintf(end_ptr, "%s\n", COLOUR_TERMINATOR);
    stack = end_string(end_ptr);
  }
  if (p->flags & PROMPT)
    pager(p, stack_ptr);
  else
    tell_player(p, stack_ptr);

  stack = oldstack;

  command_type = 0;

  return;
}
void TestPaginator::isValidPage_data()
{
    QTest::addColumn<TPaginator>("pager");
    QTest::addColumn<int>("page");
    QTest::addColumn<bool>("expectedIsValidPage");

    TPaginator pager(158, 4, 5);
    QTest::newRow("Page < 1") << pager << -2 << false;
    QTest::newRow("Page = 1") << pager << 1 << true;
    QTest::newRow("Page = Valid page") << pager << 36 << true;
    QTest::newRow("Page = Last page") << pager << 40 << true;
    QTest::newRow("Page > Last page") << pager << 68 << false;
}
void TestPaginator::setCurrentPage_data()
{
    QTest::addColumn<TPaginator>("pager");
    QTest::addColumn<int>("currentPage");
    QTest::addColumn<int>("expectedCurrentPage");
    QTest::addColumn<int>("expectedFirstPage");
    QTest::addColumn<int>("expectedPreviousPage");
    QTest::addColumn<int>("expectedNextPage");
    QTest::addColumn<int>("expectedLastPage");
    QTest::addColumn<bool>("expectedHasPreviousPage");
    QTest::addColumn<bool>("expectedHasNextPage");
    QTest::addColumn<QList<int> >("expectedRange");

    TPaginator pager(158, 4, 5);
    QList<int> range;
    range << 1 << 2 << 3 << 4 << 5;
    QTest::newRow("Page < 1") << pager << -53 << 1 << 1 << 1 << 2 << 40 << false << true << range;

    pager = TPaginator(158, 4, 5);
    range = QList<int>();
    range << 1 << 2 << 3 << 4 << 5;
    QTest::newRow("Page = 1") << pager << 1 << 1 << 1 << 1 << 2 << 40 << false << true << range;

    pager = TPaginator(158, 4, 5);
    range = QList<int>();
    range << 1 << 2 << 3 << 4 << 5;
    QTest::newRow("Page <= floor(MidRange / 2)") << pager << 2 << 2 << 1 << 1 << 3 << 40 << true << true << range;

    pager = TPaginator(158, 4, 5);
    range = QList<int>();
    range << 23 << 24 << 25 << 26 << 27;
    QTest::newRow("Page > floor(MidRange / 2) && Page <= Nb.Pages - floor(MidRange / 2)") << pager << 25 << 25 << 1 << 24 << 26 << 40 << true << true << range;

    pager = TPaginator(158, 4, 5);
    range = QList<int>();
    range << 36 << 37 << 38 << 39 << 40;
    QTest::newRow("Page > Nb.Pages - floor(MidRange / 2)") << pager << 39 << 39 << 1 << 38 << 40 << 40 << true << true << range;

    pager = TPaginator(158, 4, 5);
    range = QList<int>();
    range << 36 << 37 << 38 << 39 << 40;
    QTest::newRow("Page = Nb.Pages") << pager << 40 << 40 << 1 << 39 << 40 << 40 << true << false << range;

    pager = TPaginator(158, 4, 5);
    range = QList<int>();
    range << 1 << 2 << 3 << 4 << 5;
    QTest::newRow("Page > Nb.Pages") << pager << 59 << 1 << 1 << 1 << 2 << 40 << false << true << range;
}
예제 #11
0
static bool
debug_menu_display_current_log(Menu* menu, MenuItem* item)
{
	// get the buffer
	size_t bufferSize;
	const char* buffer = platform_debug_get_log_buffer(&bufferSize);
	if (buffer == NULL || bufferSize == 0)
		return true;

	struct TextSource : PagerTextSource {
		TextSource(const char* buffer, size_t size)
			:
			fBuffer(buffer),
			fSize(strnlen(buffer, size))
		{
		}

		virtual size_t BytesAvailable() const
		{
			return fSize;
		}

		virtual size_t Read(size_t offset, void* buffer, size_t size) const
		{
			if (offset >= fSize)
				return 0;

			if (size > fSize - offset)
				size = fSize - offset;

			memcpy(buffer, fBuffer + offset, size);
			return size;
		}

	private:
		const char*	fBuffer;
		size_t		fSize;
	};

	pager(TextSource(buffer, bufferSize));

	return true;
}
예제 #12
0
void dynamic_test_func_blocks(player *p,char *str)
{
  dfile *df;
  char *oldstack;
  int block,total,next_block,length;
  
  oldstack=stack;
  df=room_df;
  length=lseek(df->data_fd,0,SEEK_END);
  total=length/df->granularity;
  vtell_player(p, "Length = %d ( %d blocks )\n",length,total);
  for(block=0;total;total--,block++) {
    next_block=dynamic_get_next_block(df,block);
    sprintf(stack,"Block %d\tNext block %d\n",block,next_block);
    while(*stack) stack++;
  }
  *stack++=0;
  pager(p,oldstack,0);
  stack=oldstack;
}
void TestPaginator::setItemCountPerPage_data()
{
    QTest::addColumn<TPaginator>("pager");
    QTest::addColumn<int>("limit");
    QTest::addColumn<int>("expectedItemsCount");
    QTest::addColumn<int>("expectedNumPages");
    QTest::addColumn<int>("expectedLimit");
    QTest::addColumn<int>("expectedOffset");
    QTest::addColumn<int>("expectedMidRange");
    QTest::addColumn<QList<int> >("expectedRange");

    TPaginator pager(158, 4, 5);
    QList<int> range;
    range << 1 << 2 << 3 << 4 << 5;
    QTest::newRow("Limit < 1") << pager << 0 << 158 << 158 << 1 << 0 << 5 << range;

    pager = TPaginator(158, 4, 5);
    range = QList<int>();
    range << 1 << 2 << 3 << 4 << 5;
    QTest::newRow("Limit = 1") << pager << 1 << 158 << 158 << 1 << 0 << 5 << range;
}
void TestPaginator::setItemTotalCount_data()
{
    QTest::addColumn<TPaginator>("pager");
    QTest::addColumn<int>("itemsCount");
    QTest::addColumn<int>("expectedItemsCount");
    QTest::addColumn<int>("expectedNumPages");
    QTest::addColumn<int>("expectedLimit");
    QTest::addColumn<int>("expectedOffset");
    QTest::addColumn<int>("expectedMidRange");
    QTest::addColumn<QList<int> >("expectedRange");

    TPaginator pager(158, 4, 5);
    QList<int> range;
    range << 1;
    QTest::newRow("ItemsCount < 0") << pager << -4 << 0 << 1 << 4 << 0 << 5 << range;

    pager = TPaginator(158, 4, 5);
    range = QList<int>();
    range << 1;
    QTest::newRow("ItemsCount = 0") << pager << 0 << 0 << 1 << 4 << 0 << 5 << range;
}
예제 #15
0
/* thing to see the cache contents */
void	view_dynamic_cache(player *p, char *str)
{
  int count;
  char *oldstack;
  
  oldstack = stack;
  
  sprintf(stack, " Current dynamic_cache contents (size %d):\n", MAX_DYNAMIC_CACHE);
  stack = strchr(stack, 0);
  /* scan through the cache */
  for(count=0; count<MAX_DYNAMIC_CACHE; count++) {
    if(dynamic_cache[count].sp) {
      sprintf(stack, "  Pos %-3d: %-20s (%d bytes)\n", count, 
      	dynamic_cache[count].sp->lower_name, dynamic_cache[count].data.length);
      stack = strchr(stack, 0);
    }
  }
  *stack++=0;
  pager(p, oldstack, 0);
  stack = oldstack;
}
예제 #16
0
파일: mail.c 프로젝트: talkers/ew-too
void read_article(player *p,char *str)
{
    char *oldstack;
    note *article;
    oldstack=stack;

    if (!*str) {
	tell_player(p,"Format: read <article-number>\n");
	return;
    }

    article=find_news_article(atoi(str));
    if (!article) {
	sprintf(stack,"No such news article '%s'\n",str);
	stack=end_string(stack);
	tell_player(p,oldstack);
	stack=oldstack;
	return;
    }
    article->read_count++;
    if (article->flags&ANONYMOUS) {
	if (p->residency&(LOWER_ADMIN|ADMIN))
	    sprintf(stack,"Subject: %s\nPosted annonymously on %s by %s.\n",
		    article->header,convert_time(article->date),article->name);
	else sprintf(stack,"Subject: %s\nPosted annonymously on %s.\n",
		     article->header,convert_time(article->date));
    }
    else sprintf(stack,"Subject: %s\nPosted by %s on %s.\n",article->header,
		 article->name,convert_time(article->date));
    stack=strchr(stack,0);
    if (article->read_count==1) strcpy(stack,"Article read once only.\n\n");
    else sprintf(stack,"Article has been read %s times.\n\n",
		 number2string(article->read_count));
    stack=strchr(stack,0);
    get_string(stack,article->text.where);
    stack=end_string(stack);
    pager(p,oldstack,0);
    stack=oldstack;
}
예제 #17
0
파일: mail.c 프로젝트: talkers/ew-too
 void view_note(player *p,char *str)
 {
   note *n;
   char *oldstack;
   oldstack=stack;
   if (!*str) {
     tell_player(p,"Format: view_note <number>\n");
     return;
   }
   n=find_note(atoi(str));
   if (!n) {
     tell_player(p,"Can't find note with that number.\n");
     return;
   }
   if (n->flags&NEWS_ARTICLE) 
       strcpy(stack,"News Article.\n");
   else
       strcpy(stack,"Mail (?).\n");
   stack=strchr(stack,0);
   sprintf(stack,"Posted on %s, by %s.\nRead count: %d\n",
	   convert_time(n->date),n->name,n->read_count);
   stack=strchr(stack,0);
   if (n->flags&ANONYMOUS) {
     strcpy(stack,"Posted anonymously.\n");
     stack=strchr(stack,0);
   }
   if (n->flags&NOT_READY) {
     strcpy(stack,"Not ready flag set.\n");
     stack=strchr(stack,0);
   }
   if (n->flags&SUPRESS_NAME) {
     strcpy(stack,"Name suppressed.\n");
     stack=strchr(stack,0);
  }
  sprintf(stack,"Next link -> %d\n",n->next_sent);
  stack=end_string(stack);
  pager(p,oldstack,0);
  stack=oldstack;
}
예제 #18
0
void dynamic_test_func_keys(player *p,char *str)
{
  dfile *df;
  char *oldstack;
  int key,*scan;

  oldstack=stack;
  df=room_df;
  
  vtell_player(p,"nkeys = %d\n",df->nkeys);
  
  scan=df->keylist;
  for(key=0;key<=df->nkeys;key++) {
    sprintf(stack,"Key %d\tBlock pointer %d\tlength %d\n",
      key,*scan,*(scan+1));
    scan+=2;
    while(*stack) stack++;
  }
  *stack++=0;
  pager(p,oldstack,0);  
  stack=oldstack;
}
예제 #19
0
/* debugging function - scan who is logged in, and output who is in the cache
   (alledgedly) and where */
void	scan_players_for_caching(player *p, char *str)
{
  char *oldstack, let;
  int i;
  saved_player *scan, **hash;
  
  oldstack = stack;
  strcpy(stack, " Scanning for people in the cache from players:\n");
  stack = strchr(stack, 0);
  for(let='a'; let<='z'; let++) {
    hash = saved_hash[((int) (tolower(let)) - (int) 'a')];
    for(i=0; i<HASH_SIZE; i++, hash++) {
      for(scan=*hash; scan; scan=scan->next)
        if(scan->cache>=0) {
          sprintf(stack, " %-20s: %-3d\n", scan->lower_name, scan->cache);
          stack = strchr(stack, 0);
        }
    }
  }
  stack = end_string(stack);
  pager(p, oldstack, 0);
  stack = oldstack;
}
예제 #20
0
파일: slots.c 프로젝트: talkers/pgplus
void view_slots_panels(player * p)
{
  char *oldstack = stack;
  int i, j;

  for (i = 0; i < 4; i++)
  {

    stack += sprintf(stack,
		     "            %-9s           %-9s            %-9s\n"
    "    -==================-  -=================-  -==================-\n",
		     SlotsPics[(i * 3)][0], SlotsPics[(i * 3) + 1][0], SlotsPics[(i * 3) + 2][0]);
    for (j = 1; j < 8; j++)
    {
      stack += sprintf(stack, "   ||%s||%s||%s||\n",
		       SlotsPics[(i * 3)][j], SlotsPics[(i * 3) + 1][j], SlotsPics[(i * 3) + 2][j]);
    }
    stack += sprintf(stack,
		     "    -==================-  -=================-  -==================-\n\n");
  }
  stack = end_string(stack);
  pager(p, oldstack);
  stack = oldstack;
}
예제 #21
0
파일: libwrapper.cpp 프로젝트: chrox/sdcv
bool Library::process_phrase(const char *loc_str, read_line &io, bool force, bool json)
{
	if (NULL==loc_str)
		return true;

	std::string query;

	
	analyze_query(loc_str, query);
	if (!query.empty())
		io.add_to_history(query.c_str());
	


	gsize bytes_read;
	gsize bytes_written;
	GError *err=NULL;
	char *str=NULL;
	if (!utf8_input)
		str=g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, &err);
	else
		str=g_strdup(loc_str);

	if (NULL==str) {
		fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str);
		fprintf(stderr, "%s\n", err->message);
		g_error_free(err);
		return false;
	}

	if (str[0]=='\0')
		return true;

  
	TSearchResultList res_list;


	switch (analyze_query(str, query)) {
	case qtFUZZY:
		LookupWithFuzzy(query, res_list);
		break;
	case qtREGEXP:
		LookupWithRule(query, res_list);
		break;
	case qtSIMPLE:
		SimpleLookup(str, res_list);
		if (res_list.empty())
			LookupWithFuzzy(str, res_list);
		break;
	case qtDATA:
		LookupData(query, res_list);
		break;
	default:
		/*nothing*/;
	}

	if (!res_list.empty()) {    
		/* try to be more clever, if there are
		   one or zero results per dictionary show all
		*/
		bool show_all_results=true;
		typedef std::map< string, int, std::less<string> > DictResMap;
		if (!force) {
			DictResMap res_per_dict;
			for(TSearchResultList::iterator ptr=res_list.begin(); ptr!=res_list.end(); ++ptr){
				std::pair<DictResMap::iterator, DictResMap::iterator> r = 
					res_per_dict.equal_range(ptr->bookname);
				DictResMap tmp(r.first, r.second);
				if (tmp.empty()) //there are no yet such bookname in map
					res_per_dict.insert(DictResMap::value_type(ptr->bookname, 1));
				else {
					++((tmp.begin())->second);
					if (tmp.begin()->second>1) {
						show_all_results=false;
						break;
					}
				}
			}
		}//if (!force)

		if (!show_all_results && !force) {
			printf(_("Found %d items, similar to %s.\n"), res_list.size(), 
			       utf8_output ? str : utf8_to_locale_ign_err(str).c_str());
			for (size_t i=0; i<res_list.size(); ++i) {
				string loc_bookname, loc_def;
				loc_bookname=utf8_to_locale_ign_err(res_list[i].bookname);
				loc_def=utf8_to_locale_ign_err(res_list[i].def);
				printf("%d)%s-->%s\n", i,
				       utf8_output ?  res_list[i].bookname.c_str() : loc_bookname.c_str(),
				       utf8_output ? res_list[i].def.c_str() : loc_def.c_str());
			}
			int choise;
			for (;;) {
				string str_choise;
				printf(_("Your choice[-1 to abort]: "));
				
				if(!stdio_getline(stdin, str_choise)){
					putchar('\n');
					exit(EXIT_SUCCESS);
				}
				sscanf(str_choise.c_str(), "%d", &choise);
				if (choise>=0 && choise<int(res_list.size())) { 
					sdcv_pager pager;
					print_search_result(pager.get_stream(), res_list[choise]);
					break;
				} else if (choise==-1)
					break;
				else
					printf(_("Invalid choise.\nIt must be from 0 to %d or -1.\n"), 
					       res_list.size()-1);	  
			}		
		} else {
			sdcv_pager pager(force);
			if (!json) {
				fprintf(pager.get_stream(), _("Found %d items, similar to %s.\n"),
					res_list.size(), utf8_output ? str : utf8_to_locale_ign_err(str).c_str());
				for (PSearchResult ptr=res_list.begin(); ptr!=res_list.end(); ++ptr)
					print_search_result(pager.get_stream(), *ptr);
			} else {
				char *out;
				cJSON *root,*fld;
				root=cJSON_CreateArray();
				for (PSearchResult ptr=res_list.begin(); ptr!=res_list.end(); ++ptr) {
					const TSearchResult & res = *ptr;
					string loc_bookname, loc_def, loc_exp;
					if(!utf8_output){
						loc_bookname=utf8_to_locale_ign_err(res.bookname);
						loc_def=utf8_to_locale_ign_err(res.def);
						loc_exp=utf8_to_locale_ign_err(res.exp);
					}
					cJSON_AddItemToArray(root,fld=cJSON_CreateObject());
					cJSON_AddStringToObject(fld, "dict", utf8_output ? res.bookname.c_str() : loc_bookname.c_str());
					cJSON_AddStringToObject(fld, "word", utf8_output ? res.def.c_str() : loc_def.c_str());
					cJSON_AddStringToObject(fld, "definition", utf8_output ? res.exp.c_str() : loc_exp.c_str());
				}
				out=cJSON_Print(root);
				cJSON_Delete(root);
				fprintf(pager.get_stream(), "%s", out);
				free(out);
			}
		}
    
	} else {
		string loc_str;
		if (!utf8_output)
			loc_str=utf8_to_locale_ign_err(str);
    
		printf(_("Nothing similar to %s, sorry :(\n"), utf8_output ? str : loc_str.c_str());
	}
	g_free(str);

	return true;
}
예제 #22
0
파일: article.c 프로젝트: flashjay/c-blog
void panel_article_list(struct env_t *_SERVER)
{
	tpl_t  *tpl;
	char   url[128];
	char   *html, *sql;
	int    rc, i, type, total;
	

	uint limit[2], cur;
	sqlite3_stmt   *stmt;
	const char     *sortlevel, *page;
	
	
	tpl = tpl_alloc();
	if (tpl_load(tpl, "./templets/panel/article_list.html") != TPL_OK)
    {
		printf("Content-type: text/html\r\n\r\n./templets/panel/article_list.html Error loading template file!");
		tpl_free(tpl);
		return ;
    }

	total     = 0;
	sortlevel = tclistval2(_SERVER->_GET, 3);
	page      = tclistval2(_SERVER->_GET, 4);

	memset(&url, 0, sizeof(url));
	if((sortlevel) && (strcmp(sortlevel, "all") == 0))
	{
		strcpy(url, "/panel-article-list-all");
		rc   = sqlite3_prepare(db, "SELECT COUNT(*) AS c FROM article;", -1, &stmt, NULL);
	}
	else if((sortlevel) && (is_alpha(sortlevel)) && (strcmp(sortlevel, "html") != 0))
	{
		rc   = sqlite3_prepare(db, "SELECT COUNT(*) AS c FROM article WHERE catid = ?;", -1, &stmt, NULL);
		sqlite3_bind_text(stmt, 1, sortlevel, -1, SQLITE_STATIC);
		
		snprintf(url, sizeof(url), "/panel-article-list-%s", sortlevel);
	}
	else
	{
		strcpy(url, "/panel-article-list-all");
		rc   = sqlite3_prepare(db, "SELECT COUNT(*) AS c FROM article;", -1, &stmt, NULL);
	}

	rc = sqlite3_step(stmt);
	if(rc == SQLITE_ROW)
	{
		total = sqlite3_column_int(stmt, 0);
	}
	sqlite3_finalize(stmt);
	
	
	cur = (page) ? atoi(page) : 1;

	//分页
	pager(tpl, total, conf.page.admin, cur, url, limit);

	tpl_set_field_int_global(tpl, "total", total);

	if((sortlevel) && (strcmp(sortlevel, "all") == 0))
	{
		rc = sqlite3_prepare(db, "SELECT art.comment_num, art.hit, art.art_id, art.title, art.content, datetime(art.post_time, 'unixepoch') AS dt, cat.sortname, cat.sortdir FROM article AS art LEFT JOIN category AS cat ON cat.sortdir = art.catid ORDER BY art.art_id DESC LIMIT ?, ?;", -1, &stmt, NULL);
		
		sqlite3_bind_int(stmt, 1, limit[0]);
		sqlite3_bind_int(stmt, 2, limit[1]);
	}
	else if((sortlevel) && (is_alpha(sortlevel)) && (strcmp(sortlevel, "html") != 0))
	{
		rc = sqlite3_prepare(db, "SELECT art.comment_num, art.hit, art.art_id, art.title, art.content, datetime(art.post_time, 'unixepoch') AS dt, cat.sortname, cat.sortdir FROM article AS art LEFT JOIN category AS cat ON cat.sortdir = art.catid WHERE art.catid = ? ORDER BY art.art_id DESC LIMIT ?, ?;", -1, &stmt, NULL);
		
		sqlite3_bind_text(stmt, 1, sortlevel, -1, SQLITE_STATIC);
		sqlite3_bind_int(stmt,  2, limit[0]);
		sqlite3_bind_int(stmt,  3, limit[1]);
	}
	else
	{
		rc = sqlite3_prepare(db, "SELECT art.comment_num, art.hit, art.art_id, art.title, art.content, datetime(art.post_time, 'unixepoch') AS dt, cat.sortname, cat.sortdir FROM article AS art LEFT JOIN category AS cat ON cat.sortdir = art.catid ORDER BY art.art_id DESC LIMIT ?, ?;", -1, &stmt, NULL);
		
		sqlite3_bind_int(stmt, 1, limit[0]);
		sqlite3_bind_int(stmt, 2, limit[1]);
	}
	
	
	
	tpl_select_section(tpl, "data");
	while((rc = sqlite3_step(stmt)) == SQLITE_ROW)
	{
		for(i=0; i<sqlite3_column_count(stmt); i++)
		{
			type = sqlite3_column_type(stmt, i);
			switch(type)
			{
				case SQLITE_INTEGER:
					tpl_set_field_uint(tpl, sqlite3_column_name(stmt,i), sqlite3_column_int(stmt, i));
					break;
				case SQLITE_TEXT:
					tpl_set_field(tpl, sqlite3_column_name(stmt,i) ,sqlite3_column_text(stmt,i), strlen(sqlite3_column_text(stmt,i)));
					break;
			}
		}
		tpl_append_section(tpl);
	}

	tpl_deselect_section(tpl);
	sqlite3_finalize(stmt);
	

	html = mspace_malloc(_SERVER->mp, tpl_length(tpl) + 1);
    tpl_get_content(tpl, html);
	
	printf("Content-type: text/html\r\n\r\n%s", html);

	tpl_free(tpl);
	mspace_free(_SERVER->mp, html);
	
	tpl  = NULL;
	
}
예제 #23
0
파일: main.c 프로젝트: pbleser/mdp
int
main(int ac, char **av)
{
	char *t;
	int opt, mode = MODE_PAGER;
	extern int optind;
	extern char *optarg;

	if (ac < 2)
		usage();

	setlocale(LC_ALL, "");

	/* Populate $HOME */
	t = getenv("HOME");
	if (t == NULL || *t == '\0')
		errx(0, "Unknown variable '$HOME'.");
	mbstowcs(home, t, MAXPATHLEN);

	/* Populate $EDITOR */
	t = getenv("EDITOR");
	if (t != NULL)
		mbstowcs(editor, t, MAXPATHLEN);

	while ((opt = getopt(ac, av, "hVdeg:qrc:")) != -1) {
		switch (opt) {
		case 'd':
			cfg_debug = 1;
			break;
		case 'V':
			mode = MODE_VERSION;
			break;
		case 'q':
			mode = MODE_QUERY;
			break;
		case 'e':
			mode = MODE_EDIT;
			break;
		case 'g':
			mode = MODE_GENERATE;
			password_length = strtoumax(optarg, NULL, 10);
			break;
		case 'r':
			mode = MODE_RAW;
			break;
		case 'c':
			swprintf(cfg_config_path, MAXPATHLEN, L"%s", optarg);
			break;
		default:
			usage();
		}
	}

	debug("read config");

	config_set_defaults();
	config_check_paths();
	config_read();

	ac -= optind;
	av += optind;

	keywords_load_from_argv(av);

	/* Decide if we use the internal pager or just dump to screen. */
	switch (mode) {
		case MODE_VERSION:
			printf("mdp-%s\n", MDP_VERSION);
			break;

		case MODE_RAW:
			debug("mode: MODE_RAW");
			if (ac == 0)
				usage();

			gpg_check();
			load_results();
			filter_results();
			print_results();
			break;

		case MODE_PAGER:
			debug("mode: MODE_PAGER");
			if (ac == 0)
				usage();

			gpg_check();
			load_results();
			filter_results();
			pager(START_WITHOUT_PROMPT);
			break;

		case MODE_QUERY:
			debug("mode: MODE_QUERY");
			gpg_check();
			load_results();
			pager(START_WITH_PROMPT);
			break;

		case MODE_EDIT:
			debug("mode: MODE_EDIT");
			if (ac != 0)
				usage();

			gpg_check();
			lock_set();
			load_results();
			edit_results();
			break;

		case MODE_GENERATE:
			debug("mode: MODE_GENERATE");
			if (ac != 0)
				usage();

			print_passwords(password_length, cfg_password_count);
			break;

		default:
			errx(1, "unknown mode");
			break;
	}

	debug("normal shutdown");

	return 0;
}
void pageit(Pentry q[MAXPROCESSES]) { 

    /* This file contains the stub for an LRU pager */
    /* You may need to add/remove/modify any part of this file */
	//printf("%ld",processes[0]->pid);
    /* Static vars */
    static int initialized = 0;
    //static int tick = 1; // artificial time
    
	//printf("here\n");
    /* Local vars */
    int proctmp;
int minPageTwo;
	int secondMinPageOne;
	int secondMinPageTwo;
    int pagetmp;
	int secondMaxPage;
	int secondsecondMaxPage;
	int pc;
	int page;
	static int procount=0;
	int min;
	int pageOne;
	int predOne;
	int predTwo;
	int predThree;

		int swapRow=0;
		int swapCol=0;
		int tmppage;
		int proc;
	int pageTwo;
	int minPage;
	int i;
	int minPageOne;
    /* initialize static vars on first run */
    if(!initialized){
	for(proctmp=0; proctmp < MAXPROCESSES; proctmp++){
	    for(pagetmp=0; pagetmp < MAXPROCPAGES; pagetmp++){
				timestamps[proctmp][pagetmp] = 0;
				pageLastRemovedAt[proctmp][pagetmp]=0; 
				numberofpagesout=0;
		for(i=0; i<2;i++){
			betRevlentPage[proctmp][pagetmp][i]=0;

		}
		for(i=0;i<MAXPROCPAGES;i++){
			revelentPageFreq[proctmp][pagetmp][i]=0;
		}
	    }
		lastPageCalled[proctmp]=0;
	}
	tick=1;
	prevtick=0;
	initialized = 1;
    }
    
	
	//pager();
	for(proc=0; proc <MAXPROCESSES; proc++){
		//printf("1\n");	
		if(q[proc].active){
			
			//printf("2\n");
			pc = q[proc].pc;
			page=pc/PAGESIZE;
			/*if(procount>=4){

				pager(q);
			}*/

			timestamps[proc][page] = tick;
			
			


			tmppage=lastPageCalled[page];
			betRevlentPage[proc][tmppage][1]=betRevlentPage[proc][tmppage][0];
			betRevlentPage[proc][tmppage][0]=page;


			predOne=betRevlentPage[proc][page][0];
			predTwo=betRevlentPage[proc][predOne][0];
			predThree=betRevlentPage[proc][predTwo][0];


			revelentPageFreq[proc][tmppage][page]++;
			lastPageCalled[proc]=page;

			pageOne=arrayMax(proc,page,&secondMaxPage);
			pageTwo=arrayMax(proc,pageOne,&secondsecondMaxPage);

			minPageOne=arrayMin(q,proc,page,&secondMinPageOne);
			minPageTwo=arrayMin(q,proc,pageOne,&secondMinPageTwo);


			minPage=lru(q,proc,page);
			pagein(proc,page);
			pagein(proc,pageTwo);
			pagein(proc,pageOne);
			/*if(secondMaxPage!=-100 && secondMaxPage!=secondMinPageOne){
				pagein(proc,secondMaxPage);
				if(secondMinPageOne!=-100){
					pageout(proc, secondMinPageOne);
				}
			}
			if(secondMaxPage!=-100 && secondMaxPage!=secondMinPageTwo){
				pagein(proc,secondsecondMaxPage);*
				if(secondMinPageTwo!=-100){
					pageout(proc,secondMinPageTwo);
				}
			}*/
			//pagein(proc,predThree);
			//pagein(proc,predTwo);
			//pagein(proc,predOne);


			if(!q[proc].pages[page]){
				effChecker(proc,page);
				if(!pagein(proc,page)){
					pageout(proc,minPage);
					pageout(proc,minPageOne);
					pageout(proc,minPageTwo);
					if(secondMinPageTwo!=-100){
						pageout(proc,secondMinPageTwo);
					}
					if(secondMinPageOne!=-100){
						pageout(proc, secondMinPageOne);
					}
					

				}else if(!pagein(proc,pageTwo)){
					pageout(proc,minPage);
					pageout(proc,minPageOne);
					if(secondMinPageTwo!=-100){
						pageout(proc,secondMinPageTwo);
					}
					if(secondMinPageOne!=-100){
						pageout(proc, secondMinPageOne);
					}
					

				}else if(!pagein(proc,pageOne)){
					//pageout(proc,minPage);
					pageout(proc,minPage);
					pageout(proc,minPageOne);
					pageout(proc,minPageTwo);
					//pageout(proc,minPageOne);
					if(secondMinPageTwo!=-100){
						pageout(proc,secondMinPageTwo);
					}
					if(secondMinPageOne!=-100){
						pageout(proc, secondMinPageOne);
					}
					
				}

			}

			
				


		}else{//remove all things related to the process if not active
			for(i=0;i<MAXPROCPAGES;i++){
				pageout(proc,i);
				procount++;
			}

		}
 		
	}



    /* TODO: Implement LRU Paging */
	//pager(q);

    /* advance time for next pageit iteration */
	pager(q);
    tick++;
} 
예제 #25
0
파일: article.c 프로젝트: flashjay/c-blog
void make_article_index(struct env_t *_SERVER)
{
	uint  total;
	tpl_t *tpl;
	char  *html;
	FILE   *fp;

	int  rc, i, type;
	uint limit[2];
	sqlite3_stmt *stmt;

	tpl = tpl_alloc();
	if (tpl_load(tpl, "./templets/blog/article_list.html") != TPL_OK)
    {
		puts("Content-type: text/html\r\n\r\n./templets/blog/article_list.html Error loading template file!");
		tpl_free(tpl);
		return ;
    }
	
	//获取总数据集大小
	total = dataset_count("SELECT COUNT(*) AS c FROM article");
	
	tpl_set_field_int_global(tpl, "total", total);
	//分页
	pager(tpl, total, conf.page.blog, 1, "/article-list-all", limit);

	//获取分类数据
	assign_tpl_category(tpl);
	//加载推荐数据
	assign_tpl_recommend(tpl);

	//加载友情链接
	assign_tpl_friendlink(tpl);
	rc = sqlite3_prepare(db, "SELECT art.filename, art.comment_num, art.hit, art.art_id, art.title,  substring(art.content, art.position) AS c, datetime(art.post_time, 'unixepoch') AS dt, cat.sortname, cat.sortdir FROM article AS art LEFT JOIN category AS cat ON cat.sortdir = art.catid ORDER BY art.art_id DESC LIMIT ?;", -1, &stmt, NULL);
		
	sqlite3_bind_int(stmt, 1, conf.page.blog);


	tpl_select_section(tpl, "data");
	while((rc = sqlite3_step(stmt)) == SQLITE_ROW)
	{
		for(i=0; i<sqlite3_column_count(stmt); i++)
		{
			type = sqlite3_column_type(stmt, i);
			switch(type)
			{
				case SQLITE_INTEGER:
					tpl_set_field_uint(tpl, sqlite3_column_name(stmt,i), sqlite3_column_int(stmt, i));
					break;
				case SQLITE_TEXT:
					tpl_set_field(tpl, sqlite3_column_name(stmt,i) ,sqlite3_column_text(stmt,i), strlen(sqlite3_column_text(stmt,i)));
					break;
			}
		}

		tpl_append_section(tpl);
	}

	tpl_deselect_section(tpl);
	sqlite3_finalize(stmt);

	html = mspace_malloc(_SERVER->mp, tpl_length(tpl) + 1);
    tpl_get_content(tpl, html);
	
	//printf("Content-type: text/html\r\n\r\n%s", html);
	
	fp = fopen("./index.htm", "wb");
	if(fp)
	{
		fwrite(html, sizeof(char), tpl_length(tpl), fp);
		fclose(fp);
	}
	
	chmod("./index.htm", S_IRWXU | S_IRWXG | S_IRWXO);
	
	tpl_free(tpl);
	mspace_free(_SERVER->mp, html);
	
	tpl  = NULL;
}
예제 #26
0
static void intercom_tell_player_and_return(char *str)
{
  char *job_id, *name, *msg = 0, *ptr, *oldstack;
  player *p = 0;
  char end_was;
  char *end_pos;
  list_ent *l;
  saved_player *sp;
  char *end_ptr;

  if (!str || !*str)
  {
    log("error", "Empty message in intercom_tell_player");
    return;
  }
  job_id = str;

  name = strchr(job_id, ':');
  if (name)
  {
    *name++ = '\0';
    msg = strchr(name, ':');
    if (msg)
      *msg++ = '\0';
  }
  if (!msg || !*msg || !*name || !*job_id)
    return;

  if (strcasecmp(name, "me"))
    p = find_player_global_quiet(name);

  if (!p)
  {
    send_to_intercom(NULL, "%c%c%s:%s", REPLY_IS, NO_SUCH_PLAYER, job_id, name);
    command_type = 0;
    return;
  }
  if (p->tag_flags & BLOCK_TELLS)
  {
    send_to_intercom(NULL, "%c%c%s:%s", REPLY_IS, TALKER_BLOCKED, job_id,
		     p->name);
    return;
  }
  /*Check the list entry isnt an ignore */
  ptr = strchr(msg, '@');
  if (!ptr)
  {
    log("error", "intercom tried to send to player without a valid name.");
    return;
  }
  end_pos = ptr + 1;
  while (*end_pos && *end_pos != ',' && *end_pos != '\'' && *end_pos != ' ')
    end_pos++;

  end_was = *end_pos;
  *end_pos = '\0';

  /*Now at the start of the message we have the name and address and thats it */
  l = find_list_entry(p, msg);
  if (!l)
    l = find_list_entry(p, ptr);
  if (!l)
    l = find_list_entry(p, "@");
  if (!l)
  {
    *ptr = '\0';
    l = find_list_entry(p, msg);
    *ptr = '@';
  }
  /*One quick check, is the sender a banished name here */
  oldstack = stack;
  *ptr = '\0';
  strcpy(oldstack, msg);
  *ptr = '@';
  stack = end_string(oldstack);
  lower_case(oldstack);
  sp = find_saved_player(oldstack);
  if (sp)
    if (sp->residency == BANISHED || sp->residency & BANISHD)
    {
      send_to_intercom(NULL, "%c%c%s:%s", REPLY_IS, NAME_BANISHED,
		       job_id, p->name);
      stack = oldstack;
      return;
    }
  if (check_intercom_banished_name(oldstack))
  {
    send_to_intercom(NULL, "%c%c%s:%s", REPLY_IS, NAME_BANISHED,
		     job_id, p->name);
    stack = oldstack;
    return;
  }
  stack = oldstack;

  *end_pos = end_was;

  if (l)
  {
    if (l->flags & IGNORE)
    {
      if (*(l->name) == '@')
	send_to_intercom(NULL, "%c%c%s:%s", REPLY_IS, TALKER_IGNORED, job_id,
			 p->name);
      else
	send_to_intercom(NULL, "%c%c%s:%s", REPLY_IS, NAME_IGNORED, job_id,
			 p->name);
      return;
    }
    if (l->flags & BLOCK)
    {
      if (*(l->name) == '@')
	send_to_intercom(NULL, "%c%c%s:%s", REPLY_IS, TALKER_BLOCKED, job_id,
			 p->name);
      else
	send_to_intercom(NULL, "%c%c%s:%s", REPLY_IS, NAME_BLOCKED,
			 job_id, p->name);
      return;
    }
  }
  /*Put the whole thing on the stack, so we can add a \n on it. This is thanks
     to Nevyn at Crazylands, cos he threw away process output and now Crazylands
     cant handle the \n at the end cos of colour code methods. */
  strcpy(oldstack, msg);
  stack = end_string(oldstack);
  end_ptr = stack - 1;

  if (end_ptr >= oldstack && *end_ptr != '\n')
  {
    sprintf(end_ptr, "%s\n", COLOUR_TERMINATOR);
    stack = end_string(end_ptr);
  }
  if (p->flags & PROMPT)
    pager(p, oldstack);
  else
    tell_player(p, oldstack);

  send_to_intercom(NULL, "%c%c%s:%s", REPLY_IS, COMMAND_SUCCESSFUL,
		   job_id, p->name);

  return;
}
예제 #27
0
파일: sys_main.c 프로젝트: vonwenm/FreeVMS
void
freevms_main(void)
{
    char                        *command_line;

#   define                      ROOT_DEVICE_LENGTH 80
    char                        root_device[ROOT_DEVICE_LENGTH];
#   define                      CONSOLE_DEVICE_LENGTH 80
    char                        console_device[CONSOLE_DEVICE_LENGTH];

    L4_BootRec_t                *boot_record;

    L4_KernelInterfacePage_t    *kip;

    L4_ProcDesc_t               *main_proc_desc;

    L4_ThreadId_t               root_tid;
    L4_ThreadId_t               s0_tid;

    L4_Word_t                   api_flags;
    L4_Word_t                   boot_info;
    L4_Word_t                   i;
    L4_Word_t                   kernel_id;
    L4_Word_t                   kernel_interface;
    L4_Word_t                   num_boot_info_entries;
    L4_Word_t                   num_processors;
    L4_Word_t                   page_bits;
    L4_Word_t                   pagesize;

    struct vms$meminfo          mem_info;

    vms$pd_initialized = 0;

    notice("\n");
    notice(">>> FreeVMS %s (R)\n", FREEVMS_VERSION);
    notice("\n");

    kip = (L4_KernelInterfacePage_t *) L4_KernelInterface(&kernel_interface,
            &api_flags, &kernel_id);

    notice(SYSBOOT_I_SYSBOOT "leaving kernel privileges\n");
    notice(SYSBOOT_I_SYSBOOT "launching FreeVMS kernel with executive "
            "privileges\n");
    root_tid = L4_Myself();
    s0_tid = L4_GlobalId(kip->ThreadInfo.X.UserBase, 1);

    notice(SYSBOOT_I_SYSBOOT "booting main processor\n");

    for(page_bits = 0; !((1 << page_bits) & L4_PageSizeMask(kip)); page_bits++);
    pagesize = (((vms$pointer) 1) << page_bits);
    notice(SYSBOOT_I_SYSBOOT "computing page size: %d bytes\n",
            (int) pagesize);

    num_processors = L4_NumProcessors((void *) kip);

    switch(num_processors - 1)
    {
        case 0:
            break;

        case 1:
            notice(SYSBOOT_I_SYSBOOT "booting %d secondary processor\n",
                    (int) (num_processors - 1));
            break;

        default:
            notice(SYSBOOT_I_SYSBOOT "booting %d secondary processors\n",
                    (int) (num_processors - 1));
            break;
    }

    for(i = 0; i < num_processors; i++)
    {
        main_proc_desc = L4_ProcDesc((void *) kip, i);
        notice(SYSBOOT_I_SYSBOOT "CPU%d EXTFREQ=%d MHz, INTFREQ=%d MHz\n",
                (int) i, (int) (main_proc_desc->X.ExternalFreq / 1000),
                (int) (main_proc_desc->X.InternalFreq / 1000));
    }

    L4_Sigma0_GetPage(L4_nilthread, L4_Fpage(L4_BootInfo(kip), pagesize));

    boot_info = L4_BootInfo((void *) kip);
    num_boot_info_entries = L4_BootInfo_Entries((void *) boot_info);
    boot_record = L4_BootInfo_FirstEntry((void *) boot_info);

    for(i = 2; i < num_boot_info_entries; i++)
    {
        PANIC(L4_BootRec_Type(boot_record) != L4_BootInfo_SimpleExec);
        command_line = L4_SimpleExec_Cmdline(boot_record);

        if ((strstr(command_line, "vmskernel.sys") != NULL) && (i == 3))
        {
            break;
        }

        boot_record = L4_BootRec_Next(boot_record);
    }

    PANIC(L4_BootRec_Type(boot_record) != L4_BootInfo_SimpleExec);
    command_line = L4_SimpleExec_Cmdline(boot_record);
    notice(SYSBOOT_I_SYSBOOT "parsing command line: %s\n", command_line);
    sys$parsing(command_line, (char *) "root", root_device,
            ROOT_DEVICE_LENGTH);
    notice(SYSBOOT_I_SYSBOOT "selecting root device: %s\n", root_device);
    sys$parsing(command_line, (char *) "console", console_device,
            CONSOLE_DEVICE_LENGTH);
    notice(SYSBOOT_I_SYSBOOT "selecting console device: %s\n", console_device);

    dbg$virtual_memory = (strstr(command_line, " dbg$virtual_memory") != NULL)
            ? 1 : 0;
    dbg$sys_pagefault = (strstr(command_line, " dbg$sys_pagefault") != NULL)
            ? 1 : 0;
    dbg$vms_pagefault = (strstr(command_line, " dbg$vms_pagefault") != NULL)
            ? 1 : 0;

    // Starting virtual memory subsystem
    sys$mem_init(kip, &mem_info, pagesize);
    sys$bootstrap(&mem_info, pagesize);
    sys$objtable_init();
    sys$utcb_init(kip);
    sys$pd_init(&mem_info);
    sys$thread_init(kip);
    sys$populate_init_objects(&mem_info, pagesize);

    dev$init();
    names$init();

    sys$pager(kip, &mem_info, pagesize, root_device);
    sys$init(kip, &mem_info, pagesize, root_device);
    sys$loop();

    notice(">>> System halted\n");
    return;
}
예제 #28
0
/* list all the robot sections */
void list_robots(player * p, char *str)
{
  char *oldstack;
  robot *scan;
  move *movescan;
  int count = 0;

  oldstack = stack;
  if (robot_start == NULL)
  {
    tell_player(p, " There are no robots.\n");
    return;
  }
  pstack_mid("Robot Information");
  for (scan = robot_start; scan; scan = scan->next)
  {
    count++;

    if (count > 1)
    {
      sprintf(stack, LINE "\n\n");
      stack = strchr(stack, 0);
    }
    if (scan->flags & STORED)
      sprintf(stack, "Name: %s (STORED)\n", scan->lower_name);
    else
      sprintf(stack, "Name: %s\n", scan->lower_name);
    stack = strchr(stack, 0);
    /* action times */
    sprintf(stack, "Action every %d seconds, counter at %d\n", scan->speed, scan->counter);
    stack = strchr(stack, 0);
    /* flags */
    if (scan->flags)
    {
      strcpy(stack, "Robot is ");
      stack = strchr(stack, 0);
      if (scan->flags & WANDER)
      {
	strcpy(stack, "fully wandering, ");
	stack = strchr(stack, 0);
      }
      else if (scan->flags & LOCAL_WANDER)
      {
	strcpy(stack, "restricted to local rooms, ");
	stack = strchr(stack, 0);
      }
      if (scan->flags & INTELLIGENT)
      {
	strcpy(stack, "artificially intelligent, ");
	stack = strchr(stack, 0);
      }
      if (scan->flags & STORED)
      {
	strcpy(stack, "in storage, ");
	stack = strchr(stack, 0);
      }
      if (scan->flags & FIXED)
      {
	strcpy(stack, "fixed in location, ");
	stack = strchr(stack, 0);
      }
      /* fix trailing ,'s */
      stack -= 2;
      *stack++ = '.';
      *stack++ = '\n';
      *stack = 0;
    }
    else
    {
      strcpy(stack, "Robot has no flag settings.\n");
      stack = strchr(stack, 0);
    }

    /* actions */
    if (scan->max_moves)
    {
      sprintf(stack, "Robot has %d defined moves, which are:\n", scan->max_moves);
      stack = strchr(stack, 0);
      for (movescan = scan->moves_top; movescan; movescan = movescan->next)
      {
	sprintf(stack, "  %s\n", movescan->move_string);
	stack = strchr(stack, 0);
      }
    }
    else
    {
      strcpy(stack, "Robot has no defined moves.\n");
      stack = strchr(stack, 0);
    }
    *stack++ = '\n';
  }
  sprintf(stack, LINE "\n");
  stack = end_string(stack);
  if (count == 0)
  {
    tell_player(p, " Sorry - No robots found!\n");
    stack = oldstack;
    return;
  }
  pager(p, oldstack);
  stack = oldstack;
}
void TestPaginator::setMidRange_data()
{
    QTest::addColumn<TPaginator>("pager");
    QTest::addColumn<int>("midRange");
    QTest::addColumn<int>("expectedItemsCount");
    QTest::addColumn<int>("expectedNumPages");
    QTest::addColumn<int>("expectedLimit");
    QTest::addColumn<int>("expectedOffset");
    QTest::addColumn<int>("expectedMidRange");
    QTest::addColumn<QList<int> >("expectedRange");
    QTest::addColumn<int>("expectedCurrentPage");

    TPaginator pager(158, 4, 5);
    pager.setCurrentPage(20);
    QList<int> range;
    range << 20;
    QTest::newRow("MidRange < 1") << pager << -16 << 158 << 40 << 4 << 76 << 1 << range << 20;

    pager = TPaginator(158, 4, 5);
    pager.setCurrentPage(20);
    range = QList<int>();
    range << 20;
    QTest::newRow("MidRange = 1") << pager << 1 << 158 << 40 << 4 << 76 << 1 << range << 20;

    pager = TPaginator(158, 4, 5);
    pager.setCurrentPage(20);
    range = QList<int>();
    range << 16 << 17 << 18 << 19;
    range << 20;
    range << 21 << 22 << 23 << 24;
    QTest::newRow("MidRange = even number") << pager << 8 << 158 << 40 << 4 << 76 << 9 << range << 20;

    pager = TPaginator(158, 4, 5);
    pager.setCurrentPage(20);
    range = QList<int>();
    range << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 << 19;
    range << 20;
    range << 21 << 22 << 23 << 24 << 25 << 26 << 27 << 28 << 29 << 30 << 31 << 32 << 33 << 34 << 35 << 36 << 37 << 38 << 39;
    QTest::newRow("MidRange = Nb.Pages - 1") << pager << 39 << 158 << 40 << 4 << 76 << 39 << range << 20;

    pager = TPaginator(158, 4, 5);
    pager.setCurrentPage(20);
    range = QList<int>();
    range << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 << 19;
    range << 20;
    range << 21 << 22 << 23 << 24 << 25 << 26 << 27 << 28 << 29 << 30 << 31 << 32 << 33 << 34 << 35 << 36 << 37 << 38 << 39 << 40;
    QTest::newRow("MidRange = Nb.Pages && Nb.Pages = even number") << pager << 40 << 158 << 40 << 4 << 76 << 41 << range << 20;

    pager = TPaginator(158, 4, 5);
    pager.setCurrentPage(20);
    range = QList<int>();
    range << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 << 19;
    range << 20;
    range << 21 << 22 << 23 << 24 << 25 << 26 << 27 << 28 << 29 << 30 << 31 << 32 << 33 << 34 << 35 << 36 << 37 << 38 << 39 << 40;
    QTest::newRow("MidRange > Nb.Pages") << pager << 53 << 158 << 40 << 4 << 76 << 53 << range << 20;

    pager = TPaginator(161, 4, 5);
    pager.setCurrentPage(21);
    range = QList<int>();
    range << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17 << 18 << 19 << 20;
    range << 21;
    range << 22 << 23 << 24 << 25 << 26 << 27 << 28 << 29 << 30 << 31 << 32 << 33 << 34 << 35 << 36 << 37 << 38 << 39 << 40 << 41;
    QTest::newRow("MidRange = Nb.Pages && Nb.Pages = odd number") << pager << 41 << 161 << 41 << 4 << 80 << 41 << range << 21;
}