This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Bug report


Sorry I'm not sure to which address to send this

version:                                gcc version 2.7.2.3
compiler invocation:         g++ dirlist.cpp
machine type:                     iP133
operating system:              DEBIAN GNU Linux - Slink 2.1

operands to configure
when installed the
compiler:                              unknown, because installed from
deb packages in
                                                the  linux distribution

compiler modification:      none

attached files:                      to reproduce the bug

contact me if more information is required:
                                                 Attila Zimler
<hijaszu@mail.novo-iram.hu>
#ifndef __APP_H__
#define __APP_H__
/****************************************************************************
*
* TAPPLICATION HEADER FILE
*
****************************************************************************/
#include "comtypes.h"
#include "keyboard.h"
#include "viscom.h"
#include "list.h"

class TVisualComponent;

class TApplication
{
  private:
    TList *viscoms;
  public:
    TApplication(void);
    ~TApplication(void);

    virtual int mainEventLoop(void) = 0;
      //virtual abstract function for main event loop

    void addVisualComponent(TVisualComponent *viscom);
};

//__APP_H__
#endif
#ifndef __BORDERS_H__
#define __BORDERS_H__
/****************************************************************************
*                           ASCII BORDER CHARACTERS                         *
****************************************************************************/
#define S_TOP_LEFT	'Ú' /* 218 */
#define S_HORIZONTAL	'Ä' /* 196 */
#define S_H_TO_BOTTOM	'Â' /* 194 */
#define S_TOP_RIGHT	'¿' /* 191 */
#define S_VERTICAL	'³' /* 179 */
#define S_V_TO_RIGHT	'Ã' /* 195 */
#define S_CROSS		'Å' /* 197 */
#define S_V_TO_LEFT	'´' /* 180 */
#define S_BOTTOM_LEFT	'À' /* 192 */
#define S_H_TO_TOP	'Á' /* 193 */
#define S_BOTTOM_RIGHT	'Ù' /* 217 */

#define D_TOP_LEFT	'É' /* 201 */
#define D_HORIZONTAL	'Í' /* 205 */
#define D_H_TO_BOTTOM	'Ë' /* 203 */
#define D_TOP_RIGHT	'»' /* 187 */
#define D_VERTICAL	'º' /* 186 */
#define D_V_TO_RIGHT	'Ì' /* 204 */
#define D_CROSS		'Î' /* 206 */
#define D_V_TO_LEFT	'¹' /* 185 */
#define D_BOTTOM_LEFT	'È' /* 200 */
#define D_H_TO_TOP	'Ê' /* 202 */
#define D_BOTTOM_RIGHT	'¼' /* 188 */

typedef enum TLineWidth { LW_SINGLE, LW_DOUBLE } lineWidth;

//__BORDERS_H__
#endif
#ifndef __COLORS_H__
#define __COLORS_H__
/****************************************************************************
*
* COLOR MANIPULATING CONSTANTS & ROUTINES FOR CURSES
*
****************************************************************************/
#include <curses.h>
#define A_BOLD_CHAR		128
#define A_REVERSE_CHAR		64
#define A_BLINK_CHAR		32

#define COLOR_GREY		(COLOR_BLACK+A_BOLD_CHAR)
#define COLOR_LIGHT_BLUE	(COLOR_BLUE+A_BOLD_CHAR)
#define COLOR_LIGHT_GREEN	(COLOR_GREEN+A_BOLD_CHAR)
#define COLOR_LIGHT_CYAN	(COLOR_CYAN+A_BOLD_CHAR)
#define COLOR_ROSE		(COLOR_RED+A_BOLD_CHAR)
#define COLOR_LIGHT_PURPLE	(COLOR_PURPLE+A_BOLD_CHAR)
#define COLOR_NORMAL_YELLOW	(COLOR_YELLOW+A_BOLD_CHAR)
#define COLOR_HIGH_WHITE	(COLOR_WHITE+A_BOLD_CHAR)

//- color constants ---------------------------------------------------------
#define BLACK_ON_BLACK		7
#define BLUE_ON_BLACK		(COLOR_BLACK*8+COLOR_BLUE)
#define GREEN_ON_BLACK          (COLOR_BLACK*8+COLOR_GREEN)
#define CYAN_ON_BLACK		(COLOR_BLACK*8+COLOR_CYAN)
#define RED_ON_BLACK		(COLOR_BLACK*8+COLOR_RED)
#define PURPLE_ON_BLACK		(COLOR_BLACK*8+COLOR_PURPLE)
#define BROWN_ON_BLACK		(COLOR_BLACK*8+COLOR_YELLOW)
#define WHITE_ON_BLACK		0
#define GREY_ON_BLACK		(7+A_BOLD_CHAR)
#define LIGHT_BLUE_ON_BLACK	(COLOR_BLACK*8+COLOR_LIGHT_BLUE)
#define LIGHT_GREEN_ON_BLACK    (COLOR_BLACK*8+COLOR_LIGHT_GREEN)
#define LIGHT_CYAN_ON_BLACK	(COLOR_BLACK*8+COLOR_LIGHT_CYAN)
#define ROSE_ON_BLACK		(COLOR_BLACK*8+COLOR_ROSE)
#define LIGHT_PURPLE_ON_BLACK	(COLOR_BLACK*8+COLOR_LIGHT_PURPLE)
#define YELLOW_ON_BLACK		(COLOR_BLACK*8+COLOR_NORMAL_YELLOW)
#define HIGH_WHITE_ON_BLACK	(0+A_BOLD_CHAR)

#define BLACK_ON_BLUE		(COLOR_BLUE*8+COLOR_BLACK)
#define BLUE_ON_BLUE		(COLOR_BLUE*8+COLOR_BLUE)
#define GREEN_ON_BLUE	        (COLOR_BLUE*8+COLOR_GREEN)
#define CYAN_ON_BLUE		(COLOR_BLUE*8+COLOR_CYAN)
#define RED_ON_BLUE		(COLOR_BLUE*8+COLOR_RED)
#define PURPLE_ON_BLUE		(COLOR_BLUE*8+COLOR_PURPLE)
#define BROWN_ON_BLUE		(COLOR_BLUE*8+COLOR_YELLOW)
#define WHITE_ON_BLUE		(COLOR_BLUE*8+COLOR_WHITE)
#define GREY_ON_BLUE		(COLOR_BLUE*8+COLOR_GREY)
#define LIGHT_BLUE_ON_BLUE	(COLOR_BLUE*8+COLOR_LIGHT_BLUE)
#define LIGHT_GREEN_ON_BLUE	(COLOR_BLUE*8+COLOR_LIGHT_GREEN)
#define LIGHT_CYAN_ON_BLUE	(COLOR_BLUE*8+COLOR_LIGHT_CYAN)
#define ROSE_ON_BLUE		(COLOR_BLUE*8+COLOR_ROSE)
#define LIGHT_PURPLE_ON_BLUE	(COLOR_BLUE*8+COLOR_LIGHT_PURPLE)
#define YELLOW_ON_BLUE		(COLOR_BLUE*8+COLOR_NORMAL_YELLOW)
#define HIGH_WHITE_ON_BLUE	(COLOR_BLUE*8+COLOR_HIGH_WHITE)

#define BLACK_ON_GREEN		(COLOR_GREEN*8+COLOR_BLACK)
#define BLUE_ON_GREEN		(COLOR_GREEN*8+COLOR_BLUE)
#define GREEN_ON_GREEN	        (COLOR_GREEN*8+COLOR_GREEN)
#define CYAN_ON_GREEN		(COLOR_GREEN*8+COLOR_CYAN)
#define RED_ON_GREEN		(COLOR_GREEN*8+COLOR_RED)
#define PURPLE_ON_GREEN		(COLOR_GREEN*8+COLOR_PURPLE)
#define BROWN_ON_GREEN		(COLOR_GREEN*8+COLOR_YELLOW)
#define WHITE_ON_GREEN		(COLOR_GREEN*8+COLOR_WHITE)
#define GREY_ON_GREEN		(COLOR_GREEN*8+COLOR_GREY)
#define LIGHT_BLUE_ON_GREEN	(COLOR_GREEN*8+COLOR_LIGHT_BLUE)
#define LIGHT_GREEN_ON_GREEN	(COLOR_GREEN*8+COLOR_LIGHT_GREEN)
#define LIGHT_CYAN_ON_GREEN	(COLOR_GREEN*8+COLOR_LIGHT_CYAN)
#define ROSE_ON_GREEN		(COLOR_GREEN*8+COLOR_ROSE)
#define LIGHT_PURPLE_ON_GREEN	(COLOR_GREEN*8+COLOR_LIGHT_PURPLE)
#define YELLOW_ON_GREEN		(COLOR_GREEN*8+COLOR_NORMAL_YELLOW)
#define HIGH_WHITE_ON_GREEN	(COLOR_GREEN*8+COLOR_HIGH_WHITE)

#define BLACK_ON_CYAN		(COLOR_CYAN*8+COLOR_BLACK)
#define BLUE_ON_CYAN		(COLOR_CYAN*8+COLOR_BLUE)
#define GREEN_ON_CYAN	        (COLOR_CYAN*8+COLOR_GREEN)
#define CYAN_ON_CYAN		(COLOR_CYAN*8+COLOR_CYAN)
#define RED_ON_CYAN		(COLOR_CYAN*8+COLOR_RED)
#define PURPLE_ON_CYAN		(COLOR_CYAN*8+COLOR_PURPLE)
#define BROWN_ON_CYAN		(COLOR_CYAN*8+COLOR_YELLOW)
#define WHITE_ON_CYAN		(COLOR_CYAN*8+COLOR_WHITE)
#define GREY_ON_CYAN		(COLOR_CYAN*8+COLOR_GREY)
#define LIGHT_BLUE_ON_CYAN	(COLOR_CYAN*8+COLOR_LIGHT_BLUE)
#define LIGHT_GREEN_ON_CYAN	(COLOR_CYAN*8+COLOR_LIGHT_GREEN)
#define LIGHT_CYAN_ON_CYAN	(COLOR_CYAN*8+COLOR_LIGHT_CYAN)
#define ROSE_ON_CYAN		(COLOR_CYAN*8+COLOR_ROSE)
#define LIGHT_PURPLE_ON_CYAN	(COLOR_CYAN*8+COLOR_LIGHT_PURPLE)
#define YELLOW_ON_CYAN		(COLOR_CYAN*8+COLOR_NORMAL_YELLOW)
#define HIGH_WHITE_ON_CYAN	(COLOR_CYAN*8+COLOR_HIGH_WHITE)

#define BLACK_ON_RED		(COLOR_RED*8+COLOR_BLACK)
#define BLUE_ON_RED		(COLOR_RED*8+COLOR_BLUE)
#define GREEN_ON_RED	        (COLOR_RED*8+COLOR_GREEN)
#define CYAN_ON_RED		(COLOR_RED*8+COLOR_CYAN)
#define RED_ON_RED		(COLOR_RED*8+COLOR_RED)
#define PURPLE_ON_RED		(COLOR_RED*8+COLOR_PURPLE)
#define BROWN_ON_RED		(COLOR_RED*8+COLOR_YELLOW)
#define WHITE_ON_RED		(COLOR_RED*8+COLOR_WHITE)
#define GREY_ON_RED		(COLOR_RED*8+COLOR_GREY)
#define LIGHT_BLUE_ON_RED	(COLOR_RED*8+COLOR_LIGHT_BLUE)
#define LIGHT_GREEN_ON_RED	(COLOR_RED*8+COLOR_LIGHT_GREEN)
#define LIGHT_CYAN_ON_RED	(COLOR_RED*8+COLOR_LIGHT_CYAN)
#define ROSE_ON_RED		(COLOR_RED*8+COLOR_ROSE)
#define LIGHT_PURPLE_ON_RED	(COLOR_RED*8+COLOR_LIGHT_PURPLE)
#define YELLOW_ON_RED		(COLOR_RED*8+COLOR_NORMAL_YELLOW)
#define HIGH_WHITE_ON_RED	(COLOR_RED*8+COLOR_HIGH_WHITE)

#define BLACK_ON_PURPLE		(COLOR_PURPLE*8+COLOR_BLACK)
#define BLUE_ON_PURPLE		(COLOR_PURPLE*8+COLOR_BLUE)
#define GREEN_ON_PURPLE	        (COLOR_PURPLE*8+COLOR_GREEN)
#define CYAN_ON_PURPLE		(COLOR_PURPLE*8+COLOR_CYAN)
#define RED_ON_PURPLE		(COLOR_PURPLE*8+COLOR_RED)
#define PURPLE_ON_PURPLE	(COLOR_PURPLE*8+COLOR_PURPLE)
#define BROWN_ON_PURPLE		(COLOR_PURPLE*8+COLOR_YELLOW)
#define WHITE_ON_PURPLE		(COLOR_PURPLE*8+COLOR_WHITE)
#define GREY_ON_PURPLE		(COLOR_PURPLE*8+COLOR_GREY)
#define LIGHT_BLUE_ON_PURPLE	(COLOR_PURPLE*8+COLOR_LIGHT_BLUE)
#define LIGHT_GREEN_ON_PURPLE	(COLOR_PURPLE*8+COLOR_LIGHT_GREEN)
#define LIGHT_CYAN_ON_PURPLE	(COLOR_PURPLE*8+COLOR_LIGHT_CYAN)
#define ROSE_ON_PURPLE		(COLOR_PURPLE*8+COLOR_ROSE)
#define LIGHT_PURPLE_ON_PURPLE	(COLOR_PURPLE*8+COLOR_LIGHT_PURPLE)
#define YELLOW_ON_PURPLE	(COLOR_PURPLE*8+COLOR_NORMAL_YELLOW)
#define HIGH_WHITE_ON_PURPLE	(COLOR_PURPLE*8+COLOR_HIGH_WHITE)

#define BLACK_ON_BROWN		(COLOR_YELLOW*8+COLOR_BLACK)
#define BLUE_ON_BROWN		(COLOR_YELLOW*8+COLOR_BLUE)
#define GREEN_ON_BROWN	        (COLOR_YELLOW*8+COLOR_GREEN)
#define CYAN_ON_BROWN		(COLOR_YELLOW*8+COLOR_CYAN)
#define RED_ON_BROWN		(COLOR_YELLOW*8+COLOR_RED)
#define PURPLE_ON_BROWN		(COLOR_YELLOW*8+COLOR_PURPLE)
#define BROWN_ON_BROWN		(COLOR_YELLOW*8+COLOR_YELLOW)
#define WHITE_ON_BROWN		(COLOR_YELLOW*8+COLOR_WHITE)
#define GREY_ON_BROWN		(COLOR_YELLOW*8+COLOR_GREY)
#define LIGHT_BLUE_ON_BROWN	(COLOR_YELLOW*8+COLOR_LIGHT_BLUE)
#define LIGHT_GREEN_ON_BROWN	(COLOR_YELLOW*8+COLOR_LIGHT_GREEN)
#define LIGHT_CYAN_ON_BROWN	(COLOR_YELLOW*8+COLOR_LIGHT_CYAN)
#define ROSE_ON_BROWN		(COLOR_YELLOW*8+COLOR_ROSE)
#define LIGHT_PURPLE_ON_BROWN	(COLOR_YELLOW*8+COLOR_LIGHT_PURPLE)
#define YELLOW_ON_BROWN		(COLOR_YELLOW*8+COLOR_NORMAL_YELLOW)
#define HIGH_WHITE_ON_BROWN	(COLOR_YELLOW*8+COLOR_HIGH_WHITE)

#define BLACK_ON_WHITE		COLOR_WHITE*8+COLOR_BLACK
#define BLUE_ON_WHITE		(COLOR_WHITE*8+COLOR_BLUE)
#define GREEN_ON_WHITE	        (COLOR_WHITE*8+COLOR_GREEN)
#define CYAN_ON_WHITE		(COLOR_WHITE*8+COLOR_CYAN)
#define RED_ON_WHITE		(COLOR_WHITE*8+COLOR_RED)
#define PURPLE_ON_WHITE		(COLOR_WHITE*8+COLOR_PURPLE)
#define BROWN_ON_WHITE		(COLOR_WHITE*8+COLOR_YELLOW)
#define WHITE_ON_WHITE		(COLOR_WHITE*8+COLOR_WHITE)
#define GREY_ON_WHITE		(COLOR_WHITE*8+COLOR_GREY)
#define LIGHT_BLUE_ON_WHITE	(COLOR_WHITE*8+COLOR_LIGHT_BLUE)
#define LIGHT_GREEN_ON_WHITE	(COLOR_WHITE*8+COLOR_LIGHT_GREEN)
#define LIGHT_CYAN_ON_WHITE	(COLOR_WHITE*8+COLOR_LIGHT_CYAN)
#define ROSE_ON_WHITE		(COLOR_WHITE*8+COLOR_ROSE)
#define LIGHT_PURPLE_ON_WHITE	(COLOR_WHITE*8+COLOR_LIGHT_PURPLE)
#define YELLOW_ON_WHITE		(COLOR_WHITE*8+COLOR_NORMAL_YELLOW)
#define HIGH_WHITE_ON_WHITE	(COLOR_WHITE*8+COLOR_HIGH_WHITE)
void setColorPairs(void);

//__COLORS_H__
#endif
#ifndef __COMTYPES_H__
#define __COMTYPES_H__
/****************************************************************************
*
* COMMON TYPES NOT SUPPERTED BY TURBO C++
*
****************************************************************************/
#include <curses.h>
#define false	FALSE
#define true	TRUE

//typedef unsigned char bool; CPC
typedef unsigned char byte;
typedef unsigned short word;

typedef enum TOnOff { off=0, on=1 };

typedef enum TBackgroundColor { black=0, red, green, yellow, blue, purple,
				cyan, grey };

//__COMTYPES_H__
#endif
#include "dirlist.h"

TDirectoryList::TDirectoryList(TApplication *app)
  :TVisualComponent(app)
{
  normalAttr=selectedAttr=normalCursorAttr=selectedCursorAttr=0;
  items=new TNumberedList();
  drives=new TNumberedList();
  readDirectory();
#if defined (__MSDOS__)
  selectDriveKey=KCIgnored;
//#if defined (__MSDOS__)
#endif
}

#if defined (__MSDOS__)
  void TDirectoryList::readDrives(void)
  {
    int defaultdrv=getdisk();
    for (int drive=0; drive<27; drive++)
    {
      setdisk(drive);
      if (drive==getdisk())
      {
        char drvletter[2] = { drive+65, 0 };
        drives->add(strdup(drvletter));
      }
    }
    setdisk(defaultdrv);
  }
//#if defined (__MSDOS__)
#endif

#if defined (__MSDOS__)
  void TDirectoryList::selectDrive(void)
  {
    readDrives();
    if (!drives->first()) return;
    TMessageBox *sel=new TMessageBox(NULL);
    do {
      sel->add((char*)(drives->element()));
    } while (drives->next());
    sel->setTitle("Drive");
    sel->setGeometry();
    sel->moveTo(left+(width-sel->getWidth())/2,
  	        top+(height-sel->getHeight())/2);
    sel->normalAttr=diskNormalAttr;
    sel->cursorAttr=diskCursorAttr;
    sel->addAppList(KCEsc);
    sel->setFocus();
    if (sel->lastKey()==KCEnter)
    {
      char newdrive[3];
      drives->seek(sel->result);
      char *diskletter=(char*)(drives->element());
      int disknumber=diskletter[0]-65;
      setdisk(disknumber);
      readDirectory();
      listDirectory();
    }
    delete sel;
    do {
      char *str=(char*)(drives->element());
      free(str);
    } while(drives->next());
    delete drives;
    drives=new TNumberedList();
  }
//#if defined (__MSDOS__)
#endif

TDirectoryList::~TDirectoryList(void)
{
  if (items->first())
    do {
      TDirectoryItem *di=(TDirectoryItem*)(items->element());
      free(di);
    } while (items->next());
  delete items;
  if (drives->first())
    do {
      char *driveletter=(char*)(drives->element());
      free(driveletter);
    } while (drives->next());
  delete drives;
}


void TDirectoryList::setGeometry(byte l, byte t, byte r, byte b)
{
  left=l;
  top=t;
  right=r;
  bottom=b;
  height=bottom-top+1;
  width=right-left+1;
}

bool TDirectoryList::selected(unsigned int item)
{
  items->seek(item);
  TDirectoryItem *di=(TDirectoryItem*)(items->element());
  return (di->selected);
}

void TDirectoryList::readItems(int attrib)
{
#if defined (__MSDOS__)
  struct ffblk ffblk;
  int done=findfirst("*.*", &ffblk, attrib);
  while (!done)
  {
    if (ffblk.ff_attrib & attrib)
    {
      TDirectoryItem *di=(TDirectoryItem*)malloc(sizeof(TDirectoryItem));
      attrib==FA_DIREC? strcpy(di->name, ffblk.ff_name)
			:
			strcpy(di->name, strlwr(ffblk.ff_name));
      di->directory=(attrib==FA_DIREC);
      for (byte p=0; p<strlen(di->name); p++)
      {
	if (di->name[p]=='.' && di->name[p+1]!=0 && di->name[p+1]!='.'
	    && p<8)
	{
	  char *strbuf=strdup(di->name+p);
	  di->name[p]=' ';
	  di->name[p+1]=0;
	  strcat(di->name, strbuf);
	  free(strbuf);
	}
	if (di->name[p]=='.' && p>7) di->name[p]=' ';
      }
      di->selected=false;
      items->add(di);
    }
    done=findnext(&ffblk);
  }
#elif defined (linux)
  DIR *dirstream=opendir(".");
  if (dirstream==NULL)
    {
      printf("dirstream==NULL while reading directory entry");
      exit(EXIT_FAILURE);
    }
  struct dirent *dirent=readdir(dirstream);
  while (dirent!=NULL)
  {
    struct stat *buf;
    stat(dirent->d_name, buf);
    if ((S_ISDIR(buf->mode_t)>0)==attrib)
    {
      TDirectoryItem *di=(TDirectoryItem*)malloc(sizeof(TDirectoryItem));
      attrib==FA_DIREC? strcpy(di->name, ffblk.ff_name)
			:
			strcpy(di->name, strlwr(ffblk.ff_name));
      di->directory=(attrib==FA_DIREC);
      for (byte p=0; p<strlen(di->name); p++)
      {
	if (di->name[p]=='.' && di->name[p+1]!=0 && di->name[p+1]!='.'
	    && p<8)
	{
	  char *strbuf=strdup(di->name+p);
	  di->name[p]=' ';
	  di->name[p+1]=0;
	  strcat(di->name, strbuf);
	  free(strbuf);
	}
	if (di->name[p]=='.' && p>7) di->name[p]=' ';
      }
      di->selected=false;
      items->add(di);
    }
    dirent=readdir(dirstream);
  }
//#if defined (__MSDOS__)
#endif
}

void TDirectoryList::readDirectory()
{
  if (items->first())
    do {
      TDirectoryItem *di=(TDirectoryItem*)(items->element());
      free(di);
    } while (items->next());
  delete items;
  items=new TNumberedList();
  topItem=0;
  cursorItem=0;
#if defined (__MSDOS__)
  readItems(FA_DIREC);
  readItems(~FA_DIREC);
#elif defined (linux)
  readItems(FA_DIREC);
  readItems(!FA_DIREC);
//#if defined (__MSDOS__)
#endif
  sort();
}

void TDirectoryList::listDirectory(void)
{
  byte row=top+1;
  if (items->seek(topItem))
    do {
      cattrset(selected(topItem+row-top-1)? selectedAttr:normalAttr);
      move(row, left+1);
      TDirectoryItem *di=(TDirectoryItem*)(items->element());
      csetScreenAttr(row, left+1, 12,
		     selected(topItem+row-top-1)? selectedAttr:normalAttr);
      printw("%-12s", di->name);
      cattrset(normalAttr);
      csetScreenAttr(row, left+13, 1, normalAttr);
      printw("%c", S_VERTICAL);
      row++;
    } while (items->next() && row<bottom);
  cattrset(normalAttr);
  for (; row<bottom; row++) //don't touch '(;' it is good writed
    {
      move(row, left+1);
      csetScreenAttr(row, left+1, 13, normalAttr);
      printw("%-12s%c", "", S_VERTICAL);
    }
  refresh();
}

void TDirectoryList::cursorDown(void)
{
  if (cursorItem<items->count()-1)
  {
    if (cursorItem<height-3) cursorItem++;
    else if (cursorItem+topItem<items->count()-1)
    {
      topItem++;
      listDirectory();
    }
  }
}

void TDirectoryList::cursorUp(void)
{
  if (cursorItem>0) cursorItem--;
  else if (topItem>0)
  {
    topItem--;
    listDirectory();
  }
}

void TDirectoryList::execute(void)
{
  cattrset(normalAttr);
  draw_box(left, top, right, bottom, LW_DOUBLE);
  listDirectory();
  kc=KCEmpty;
  while (!toApplication(kc))
  {
    kc=KCEmpty;
    cursorRow(on);
    while (!toApplication(kc) && kc!=KCEnter &&
	   kc!=KCCursorUp && kc!=KCCursorDown && kc!=KCInsert &&
	   kc!=KCPageUp && kc!=KCPageDown
#if defined (__MSDOS__)
	   && kc!=selectDriveKey
//#if defined (__MSDOS__)
#endif
	  )
      kc=inkey();
    cursorRow(off);
    if (kc==KCInsert) /*insert*/
      {
	items->seek(cursorItem+topItem);
	TDirectoryItem *di=(TDirectoryItem*)(items->element());
	if (!di->directory) di->selected=!di->selected;
      }
    if (kc==KCCursorDown || kc==KCInsert) cursorDown();
    if (kc==KCCursorUp) cursorUp();
    if (kc==KCPageUp) for (byte num=0; num<height-2; num++) cursorUp();
    if (kc==KCPageDown) for (byte num=0; num<height-2; num++) cursorDown();
#if defined (__MSDOS__)
    if (kc==selectDriveKey) selectDrive();
//#if defined (__MSDOS__)
#endif
    if (kc==KCInsert) listDirectory();
    if (kc==KCEnter)
      {
	char *entry=getEntry();
	chdir(entry);
	free(entry);
	readDirectory();
	listDirectory();
      }
  }
}

void TDirectoryList::cursorRow(TOnOff state)
{
  bool select=selected(cursorItem+topItem) ;
  for (int col=left+1; col<right; col++)
  {
    bool selectcolor=select && col<left+12+1;
    int attr=selectcolor?
	       state? selectedCursorAttr : selectedAttr
	       :
	       state? normalCursorAttr : normalAttr;
    textattr(col, cursorItem+top+1, attr);
  }
  refresh();
}

void TDirectoryList::show(void)
{
  displayed=true;
  storedDisplay=(char*)malloc((right-left+1)*(bottom-top+1)*2);
  gettext(left, top, right, bottom, storedDisplay);
  cattrset(normalAttr);
  draw_box(left, top, right, bottom, LW_SINGLE);
  listDirectory();
  refresh();
}

void TDirectoryList::hide(void)
{
  displayed=false;
  puttext(left, top, right, bottom, storedDisplay);
  free(storedDisplay);
  refresh();
}

void TDirectoryList::lostFocus(void)
{
  draw_box(left, top, right, bottom, LW_SINGLE);
  listDirectory();
}

char *TDirectoryList::getEntry(void)
{
  TDirectoryItem *di=(TDirectoryItem*)(items->element());
  char *rvalue=strdup(di->name);
  signed char pos=12;
  while (rvalue[pos]!=' ' && pos>-1) pos--;
  if (pos>-1) rvalue[pos]='.';
  while (rvalue[pos]=='.' && rvalue[pos-1]==' ')
  {
    strcpy(rvalue+(pos-1), rvalue+(pos));
    pos--;
  }
  return rvalue;
}

char *TDirectoryList::getEntry(unsigned int item)
{
  items->seek(item);
  return getEntry();
}

void TDirectoryList::setSelected(unsigned int item, bool newstate)
{
  items->seek(item);
  TDirectoryItem *di=(TDirectoryItem*)(items->element());
  di->selected=newstate;
  listDirectory();
}

void TDirectoryList::sort(void)
{
  bool sorted;
  do {
    sorted=true;
    if (items->first())
    {
      bool notlast;
      do {
	TDirectoryItem *curdi=(TDirectoryItem*)(items->element());
	notlast=items->next();
	if (notlast)
	{
	  TDirectoryItem *nextdi=(TDirectoryItem*)(items->element());
	  if (strcmp(curdi->name, nextdi->name)>0)
	  {
	    items->swapWithPrev();
	    sorted=false;
	  }
	}
      } while (notlast);
    }
  } while (!sorted);
}
#ifndef __DIRLIST_H__
#define __DIRLIST_H__
/****************************************************************************
*
* DIRECTORY LISTING PANEL
*
****************************************************************************/
#if defined (__MSDOS__)
#  include <dir.h>
#  include <dos.h>
#elif defined (linux)
#  include <unistd.h>
#  include <dirent.h>
#  include <sys/stat.h>
//#if defined (__MSDOS__)
#endif

#include <string.h>

#include "viscom.h"
#include "app.h"
#include "screen.h"
#include "numlist.h"
#include "msgbox.h"

#if defined (linux)
#  define FA_DIREC	true
//#if defined (linux)
#endif

typedef struct TDirectoryItem
{
  char name[13];
  bool selected;
  bool directory;
} TDirectoryItem;

class TDirectoryList : public TVisualComponent
{
  protected:
    TNumberedList *items;
    TNumberedList *drives;
    byte cursorItem, topItem;
    char *storedDisplay;
    byte height, width;

    void execute(void);
    void lostFocus(void);

    void readItems(int attrib);
    void readDirectory();
    void listDirectory(void);
    void cursorRow(TOnOff state);
    void cursorUp(void);
    void cursorDown(void);
    void readDrives(void);
    char *getEntry(void);
    void sort(void);

  public:
    int normalAttr, selectedAttr, normalCursorAttr, selectedCursorAttr;
    int diskNormalAttr, diskCursorAttr;
    byte left, top, right, bottom;
#if defined (__MSDOS__)
    TKeyCode selectDriveKey;
//#if defined (__MSDOS__)
#endif

    TDirectoryList(TApplication *app);
    ~TDirectoryList(void);
    void show(void);
    void hide(void);

    void setGeometry(byte l, byte t, byte r, byte b);
    unsigned int entryCount(void) { return items->count(); }
    bool selected(unsigned int item);
    char *getEntry(unsigned int item);
    void setSelected(unsigned int item, bool newstate);
#if defined (__MSDOS__)
    void selectDrive(void);
//#if defined (__MSDOS__)
#endif
};

//__DIRLIST_H__
#endif
#ifndef __KEYBOARD_H__
#define __KEYBOARD_H__
/****************************************************************************
*
* Keyboard handling
*
****************************************************************************/
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>

#if defined (linux)
#  include <termios.h>
#  include <unistd.h>
//#if defined (linux)
#endif
#include "comtypes.h"

typedef enum TKeyCode
  {
    KCEmpty=0,
    KCAlt0, KCAlt1, KCAlt2, KCAlt3, KCAlt4,
      KCAlt5, KCAlt6, KCAlt7, KCAlt8, KCAlt9,
    KCAltA, KCAltB, KCAltC, KCAltD, KCAltE,
      KCAltF, KCAltG, KCAltH, KCAltJ, KCAltK,
      KCAltL, KCAltM, KCAltN, KCAltO, KCAltP,
      KCAltQ, KCAltR, KCAltS, KCAltT, KCAltU,
      KCAltV, KCAltW, KCAltX, KCAltY, KCAltZ,
    KCCtrlA, KCCtrlB, KCCtrlD, KCCtrlE, KCCtrlF,
      KCCtrlG, KCCtrlH, KCCtrlI, KCCtrlK, KCCtrlL,
      KCCtrlN, KCCtrlO, KCCtrlP, KCCtrlR, KCCtrlT,
      KCCtrlU, KCCtrlV, KCCtrlW, KCCtrlX, KCCtrlY,
    KCF1, KCF2, KCF3, KCF4, KCF5, KCF6, KCF7, KCF8, KCF9, KCF10,
    KCCursorUp, KCCursorDown, KCCursorLeft, KCCursorRight,
    KCTab, KCEnter, KCEsc,
    KCInsert, KCDelete, KCHome, KCEnd, KCPageUp, KCPageDown,
    KCInvalid, //this is not a recognised character code
    KCIgnored  //this is an ignored option at testing
      	       //(comparing to this will always fall)
  };

TKeyCode inkey(void);
void init_key(void);
//#ifndef __KEYBOARD_H__
#endif
#ifndef __LIST_H__
#define __LIST_H__
/****************************************************************************
*                               DYNAMIC LIST                                *
****************************************************************************/
#include <stdlib.h>

#include "comtypes.h"

typedef struct listElement {
  listElement *prev;
  void *element;
  listElement *next;
} listElement;

class TList
{
  private:
    void remove(listElement *le);

  protected:
    listElement *_head;
    listElement *_tail;
    listElement *_current;

  public:
    TList(void);
    ~TList(void);
    int first(void);
    int last(void);
    int prev(void);
    int next(void);
    virtual void add(void *i);
    void *element(void);
    unsigned int count(void);
    void remove(void) { if (_current!=NULL) remove(_current); }
    void swapWithPrev(void);
};

#endif
//__LIST_H__
#ifndef __MSGBOX_H__
#define __MSGBOX_H__
/****************************************************************************
*
* MESSAGEBOX VISUAL COMPONENT
*
****************************************************************************/
#include <string.h>

#include "viscom.h"
#include "app.h"
#include "numlist.h"
#include "screen.h"

typedef struct TMsgBtnList {
  unsigned char left;
  char *caption;
} TMsgBtnList;

class TMessageBox : public TVisualComponent
{
  protected:
    TNumberedList *nl;
    byte btnpos;
    char *title;
    byte left, right, top, width, height, titleleft;
    char *storedDisplay;

    void execute(void);
    void lostFocus(void);

  public:
    TMessageBox(TApplication *app);
    ~TMessageBox(void);
    signed char result; //-1 if not leaving because enter is pressed
    byte normalAttr, cursorAttr;

    void show(void);
    void hide(void);

    void setTitle(const char *t);
    void add(const char *item);
    void setGeometry(void);
    void moveTo(byte l, byte t);
    byte getWidth(void) { return width; }
    byte getHeight(void) { return height; }
};

//__MSGBOX_H__
#endif
#ifndef __NUMLIST_H__
#define __NUMLIST_H__
/****************************************************************************
*                        LIST WIDTH NUMBERED ENTRIES                        *
****************************************************************************/
#include "list.h"
#include "comtypes.h"

typedef struct numberedListElement : public listElement {
  unsigned int num;
} numberedListElement;

class TNumberedList : TList
{
  private:
    unsigned int _maxitem;

  public:
    TNumberedList(void);
    ~TNumberedList(void);
    int first(void) { return TList::first(); }
    int prev(void) { return TList::prev(); }
    int next(void) { return TList::next(); }
    int last(void) { return TList::last(); }
    bool seek(signed long item);
    virtual void add(void *e);
    void *element(void) { return TList::element(); }
    unsigned int pos(void);
    unsigned int maxitem(void) { return _maxitem; }
    unsigned int count(void) { return TList::count(); }
    void remove(unsigned int item);
    void remove(void) { remove(pos()); }
    void swapWithPrev(void);
};

//__NUMLIST_H__
#endif
#ifndef __SCREEN_H__
#define __SCREEN_H__
/****************************************************************************
*
* TEXT SCREEN HANDLING ROUTINES
*
****************************************************************************/
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#if defined (__MSDOS__)
#  include <dos.h>
#elif defined (__LINUX__)
#endif

#include "comtypes.h"
#include "borders.h"
#include "colors.h"

void textattr(int col, int row, int attr);
void cursor(TOnOff newstate);
void draw_box(int left, int top, int right, int bottom, TLineWidth w);
void setBlinking(TOnOff newstate);
TOnOff getBlinking(void);

void gettext(int left, int top, int right, int bottom, char *buffer);
void puttext(int left, int top, int right, int bottom, char *buffer);

//--- overdefined functions !!have to use this ones!! -----------------------
WINDOW* cinitscr(void);
int cendwin(void);
int cattrset(chtype attr);
void csetScreenAttr(int y, int x, int number, char attr);

//__SCREEN_H__
#endif
#ifndef __VISCOM_H__
#define __VISCOM_H__
/****************************************************************************
*
* ABSTRACT VISUAL COMPONENT CLASS
*
****************************************************************************/
#include <stdlib.h>

#include "comtypes.h"
#include "keyboard.h"
#include "app.h"

class TApplication;

class TVisualComponent
{
  protected:
    TKeyCode *toAppList;
    int maxToApp;
    bool displayed;
    TApplication *application;
    TKeyCode kc;

    virtual void show(void) = 0;
    virtual void hide(void) = 0;
    virtual void execute(void) = 0;
    virtual void lostFocus(void) = 0;

    bool toApplication(TKeyCode kc);

  public:
    TKeyCode lastKey(void);

    TVisualComponent(TApplication *app);
    ~TVisualComponent(void);
    void addAppList(TKeyCode kc);

    void setFocus(void);
};

//__VISCOM_H__
#endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]