home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Program / main2.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  22KB  |  817 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "DOpus.h"
  32.  
  33. #define EXALL_NUM 2
  34.  
  35. void freedir(dir,win)
  36. struct DirectoryWindow *dir;
  37. int win;
  38. {
  39.     struct Directory *free,*work;
  40.  
  41.     if (dir) {
  42.         if (dir->firstentry && dir->total>0) {
  43.             if (dir->firstentry) {
  44.                 free=dir->firstentry;
  45.                 while (free) {
  46.                     if (free->next) work=free->next;
  47.                     else work=NULL;
  48.                     free->next=NULL;
  49.                     free->last=NULL;
  50.  
  51.                     free_file_memory(free);
  52.                     free=work;
  53.                 }
  54.             }
  55.         }
  56.         dir->firstentry=dir->firstfile=dir->firstdir=NULL;
  57.         dir->oldoff=dir->oldhoff=-1;
  58.         dir->offset=dir->total=dir->filesel=
  59.             dir->dirsel=dir->bytessel=dir->bytestot=
  60.             dir->dirtot=dir->filetot=dir->hoffset=0;
  61.         dir->custhandler[0]=0;
  62.         dir->realdevice[0]=0;
  63.         dir->volumename[0]=0;
  64.         dir->flags=0;
  65.         if (Window && win>-1) {
  66.             fixhorizprop(win);
  67.             last_selected_entry=NULL;
  68.         }
  69.     }
  70. }
  71.  
  72. getdir(dir,win,incmess)
  73. struct DirectoryWindow *dir;
  74. int win,incmess;
  75. {
  76.     int tot=1,a,use_exall=0,exall_entry,exall_continue,exall_bufsize;
  77.     BPTR mylock;
  78.     char buf[256];
  79.     struct FileInfoBlock __aligned fileinfo;
  80.     struct ExAllControl *exall_control;
  81.     struct ExAllData *exall_buffer,*exall_current;
  82.     struct MsgPort *deviceport;
  83.  
  84.     endnotify(win);
  85.     freedir(dir,win);
  86.  
  87.     vert_propinfo[win].VertPot=0;
  88.     if (Window && !status_iconified) {
  89.         refreshwindow(win,1);
  90.         if (win==data_active_window)
  91.             SetAPen(main_rp,screen_pens[config->disknameselbg].pen);
  92.         else SetAPen(main_rp,screen_pens[config->disknamebg].pen);
  93.         rectfill(main_rp,
  94.             scrdata_diskname_xpos[win]+2,
  95.             scrdata_diskname_ypos,
  96.             scrdata_diskname_width[win],
  97.             scrdata_diskname_height-2);
  98.         SetAPen(main_rp,screen_pens[1].pen);
  99.     }
  100.  
  101.     if (!(mylock=Lock(dir->directory,ACCESS_READ))) {
  102.         if (Window) doerror(IoErr());
  103.         for (a=0;a<30;a++) {
  104.             if (str_pathbuffer[win][a]==':' || str_pathbuffer[win][a]==0) break;
  105.         }
  106.         if (str_pathbuffer[win][a]==':') LStrnCpy(dir->realdevice,str_pathbuffer[win],a+1);
  107.         return(0);
  108.     }
  109.  
  110.     strcpy(buf,str_pathbuffer[win]);
  111.     if (getroot(buf,NULL)) {
  112.         strcpy(dir->volumename,buf);
  113.         strcat(buf,":");
  114.         if (deviceport=(struct MsgPort *)DeviceProc(buf))
  115.             get_device_task(mylock,dir->realdevice,deviceport);
  116.     }
  117.  
  118.     if (config->dirflags&DIRFLAGS_EXPANDPATHS) {
  119.         PathName(mylock,buf,256);
  120.         strcpy(str_pathbuffer[win],buf);
  121.         if (Window) checkdir(str_pathbuffer[win],&path_strgadget[win]);
  122.         else checkdir(str_pathbuffer[win],NULL);
  123.         strcpy(dir->directory,str_pathbuffer[win]);
  124.     }
  125.  
  126.     Examine(mylock,&fileinfo);
  127.     if (fileinfo.fib_DirEntryType<0) {
  128.         if (Window) doerror(ERROR_OBJECT_WRONG_TYPE);
  129.         UnLock(mylock);
  130.         return(0);
  131.     }
  132.     dir->firstentry=NULL;
  133.     if (Window) {
  134.         if (incmess) dostatustext(globstring[STR_READING_CHANGED_DIRECTORY]);
  135.         else dostatustext(globstring[STR_READING_DIRECTORY]);
  136.         busy();
  137.     }
  138.     copy_datestamp(&fileinfo.fib_Date,&dir->dirstamp);
  139.  
  140.     if (config->dirflags&DIRFLAGS_EXALL && system_version2>=OSVER_40) {
  141.         if (exall_control=AllocDosObject(DOS_EXALLCONTROL,NULL)) {
  142.             if (exall_buffer=(struct ExAllData *)
  143.                 AllocMem((exall_bufsize=((sizeof(struct ExAllData)+160)*EXALL_NUM)),MEMF_CLEAR)) {
  144.                 use_exall=1;
  145.                 exall_entry=0;
  146.                 exall_continue=1;
  147.                 exall_control->eac_Entries=0;
  148.                 exall_control->eac_LastKey=0;
  149.                 exall_control->eac_MatchString=NULL;
  150.                 exall_control->eac_MatchFunc=NULL;
  151.                 exall_current=NULL;
  152.             }
  153.             else {
  154.                 FreeDosObject(DOS_EXALLCONTROL,exall_control);
  155.                 exall_control=NULL;
  156.             }
  157.         }
  158.     }
  159.  
  160.     FOREVER {
  161.         fileinfo.fib_OwnerUID=fileinfo.fib_OwnerGID=0;
  162.         if (use_exall) {
  163.             if (exall_entry>=exall_control->eac_Entries || !exall_current) {
  164.                 if (!exall_continue) break;
  165.                 exall_continue=ExAll(mylock,exall_buffer,exall_bufsize,ED_COMMENT,exall_control);
  166.                 exall_entry=0;
  167.                 exall_current=exall_buffer;
  168.                 continue;
  169.             }
  170.             if (exall_current->ed_Name)
  171.                 strcpy(fileinfo.fib_FileName,exall_current->ed_Name);
  172.             else fileinfo.fib_FileName[0]=0;
  173.             fileinfo.fib_DirEntryType=exall_current->ed_Type;
  174.             fileinfo.fib_Size=exall_current->ed_Size;
  175.             fileinfo.fib_Protection=exall_current->ed_Prot;
  176.             fileinfo.fib_Date.ds_Days=exall_current->ed_Days;
  177.             fileinfo.fib_Date.ds_Minute=exall_current->ed_Mins;
  178.             fileinfo.fib_Date.ds_Tick=exall_current->ed_Ticks;
  179.             if (exall_current->ed_Comment)
  180. /*
  181.                 BtoCStr((BSTR)exall_current->ed_Comment,fileinfo.fib_Comment,79);
  182. */
  183.                 strcpy(fileinfo.fib_Comment,exall_current->ed_Comment);
  184.             else fileinfo.fib_Comment[0]=0;
  185.             ++exall_entry;
  186.             exall_current=exall_current->ed_Next;
  187.         }
  188.         else {
  189.             if (!(ExNext(mylock,&fileinfo))) break;
  190.         }
  191.  
  192.         if (status_haveaborted && Window) {
  193.             myabort();
  194.             dir->flags|=DWF_ABORTED;
  195.             tot=-1;
  196.             break;
  197.         }
  198.         if (!(addfile(dir,win,fileinfo.fib_FileName,
  199.             (fileinfo.fib_DirEntryType>0)?-1:fileinfo.fib_Size,
  200.             fileinfo.fib_DirEntryType,
  201.             &fileinfo.fib_Date,fileinfo.fib_Comment,fileinfo.fib_Protection,0,
  202.             FALSE,NULL,NULL,fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID))) {
  203.             if (Window) doerror(IoErr());
  204.             tot=0;
  205.             break;
  206.         }
  207.         else if (Window) fixprop(win);
  208.     }
  209.     UnLock(mylock);
  210.  
  211.     if (Window) {
  212.         unbusy();
  213.         if (tot) {
  214.             seename(win);
  215.             if (tot==1) okay();
  216.         }
  217.         refreshwindow(win,1);
  218.     }
  219.     if (use_exall) {
  220.         if (exall_control) FreeDosObject(DOS_EXALLCONTROL,exall_control);
  221.         if (exall_buffer) FreeMem(exall_buffer,exall_bufsize);
  222.     }
  223.     startnotify(win);
  224.     return(1);
  225. }
  226.  
  227. void fixprop(win)
  228. int win;
  229. {
  230.     if (win>-1 && !status_iconified) {
  231.         FixSliderBody(Window,&vert_propgad[win],dopus_curwin[win]->total,scrdata_dispwin_lines,0);
  232.         fixvertprop(win);
  233.     }
  234. }
  235.  
  236. void fixvertprop(win)
  237. int win;
  238. {
  239.     if (win>-1 && !status_iconified) {
  240.         FixSliderPot(Window,&vert_propgad[win],dopus_curwin[win]->offset,
  241.             dopus_curwin[win]->total,scrdata_dispwin_lines,2);
  242.     }
  243. }
  244.  
  245. void fixhorizprop(win)
  246. int win;
  247. {
  248.     if (win>-1 && !status_iconified) {
  249.         fixhlen(win);
  250.         if (Window) {
  251.             FixSliderBody(NULL,&horiz_propgad[win],dopus_curwin[win]->hlen,scrdata_dispwin_nchars[win],0);
  252.             FixSliderPot(Window,&horiz_propgad[win],dopus_curwin[win]->hoffset,dopus_curwin[win]->hlen,scrdata_dispwin_nchars[win],2);
  253.         }
  254.     }
  255. }
  256.  
  257. doposprop(win)
  258. int win;
  259. {
  260.     int i;
  261.  
  262.     if (win<0 || status_iconified) return(0);
  263.     if (!(status_flags&STATUS_NEWLOOK) &&
  264.         vert_propgad[win].MutualExclude) ShowSlider(Window,&vert_propgad[win]);
  265.     i=GetSliderPos(&vert_propgad[win],dopus_curwin[win]->total,scrdata_dispwin_lines);
  266.     if (dopus_curwin[win]->offset==i) return(0);
  267.     dopus_curwin[win]->offset=i;
  268.     displaydir(win);
  269.     return(1);
  270. }
  271.  
  272. void doposhprop(win)
  273. int win;
  274. {
  275.     int i;
  276.  
  277.     if (!status_iconified && win>-1) {
  278.         if (!(status_flags&STATUS_NEWLOOK) &&
  279.             horiz_propgad[win].MutualExclude) ShowSlider(Window,&horiz_propgad[win]);
  280.         i=GetSliderPos(&horiz_propgad[win],dopus_curwin[win]->hlen,scrdata_dispwin_nchars[win]);
  281.         if (dopus_curwin[win]->hoffset==i) return;
  282.         dopus_curwin[win]->hoffset=i; dopus_curwin[win]->oldoff=-1;
  283.         displaydir(win);
  284.     }
  285. }
  286.  
  287. void checkdir(str,gad)
  288. char *str;
  289. struct Gadget *gad;
  290. {
  291.     struct StringInfo *sinfo;
  292.  
  293.     TackOn(str,NULL,256);
  294.     if (gad) {
  295.         sinfo=(struct StringInfo *)gad->SpecialInfo;
  296.         gad->Flags|=GADGHNONE;
  297.         if (!system_version2) {
  298.             sinfo->BufferPos=0; RefreshGList(gad,Window,NULL,1);
  299.         }
  300.         sinfo->BufferPos=strlen(str); RefreshGList(gad,Window,NULL,1);
  301.         gad->Flags&=~GADGHNONE;
  302.     }
  303. }
  304.  
  305. void verticalscroll(win,dir)
  306. int win,dir;
  307. {
  308.     if (win<0 || dopus_curwin[win]->total<=scrdata_dispwin_lines) return;
  309.  
  310.     if (dir<0) {
  311.         --dopus_curwin[win]->offset;
  312.         if (dopus_curwin[win]->offset<0) {
  313.             dopus_curwin[win]->offset=0;
  314.             return;
  315.         }
  316.     }
  317.     else {
  318.         ++dopus_curwin[win]->offset;
  319.         if (dopus_curwin[win]->offset>dopus_curwin[win]->total-scrdata_dispwin_lines) {
  320.             dopus_curwin[win]->offset=dopus_curwin[win]->total-scrdata_dispwin_lines;
  321.             return;
  322.         }
  323.     }
  324.     fixvertprop(win);
  325.     displaydir(win);
  326. }
  327.  
  328. void horizontalscroll(win,dir)
  329. int win,dir;
  330. {
  331.     if (win<0 || dopus_curwin[win]->total==0 || dopus_curwin[win]->firstentry->type==ENTRY_DEVICE)
  332.         return;
  333.     if (dir<0) {
  334.          if (dopus_curwin[win]->hoffset==0) return;
  335.         --dopus_curwin[win]->hoffset;
  336.     }
  337.     else {
  338.         if (dopus_curwin[win]->hoffset==dopus_curwin[win]->hlen-scrdata_dispwin_nchars[win]) return;
  339.         ++dopus_curwin[win]->hoffset;
  340.     }
  341.     refreshwindow(win,1);
  342. }
  343.  
  344. void findfirstsel(win,type)
  345. int win,type;
  346. {
  347.     struct Directory *sel;
  348.     int a;
  349.  
  350.     if (win<0 || dopus_curwin[win]->total<=scrdata_dispwin_lines) return;
  351.     sel=dopus_curwin[win]->firstentry; a=0;
  352.     while (sel) {
  353.         if (sel->selected) {
  354.             if (type==-2 || ENTRYTYPE(sel->type)==type) break;
  355.         }
  356.         sel=sel->next;
  357.         ++a;
  358.     }
  359.     if (sel) {
  360.         dopus_curwin[win]->offset=a;
  361.         if (dopus_curwin[win]->offset>dopus_curwin[win]->total-scrdata_dispwin_lines)
  362.             dopus_curwin[win]->offset=dopus_curwin[win]->total-scrdata_dispwin_lines;
  363.         fixvertprop(win);
  364.         displaydir(win);
  365.     }
  366.     return;
  367. }
  368.  
  369. void findfirstchar(win,c)
  370. int win;
  371. char c;
  372. {
  373.     struct Directory *sel;
  374.     int a=0,b=0,file=0;
  375.  
  376.     if (isupper(c)) { file=1; c=LToLower(c); }
  377.     if (dopus_curwin[win]->total<=scrdata_dispwin_lines) return;
  378.     sel=dopus_curwin[win]->firstentry;
  379.     while (sel) {
  380.         if (LToLower(sel->name[0])>=c) {
  381.             if (!file || ENTRYTYPE(sel->type)==ENTRY_FILE) {
  382.                 b=1;
  383.                 break;
  384.             }
  385.         }
  386.         if (sel->next) sel=sel->next;
  387.         else sel=NULL;
  388.         ++a;
  389.     }
  390.     if (!b) dopus_curwin[win]->offset=dopus_curwin[win]->total-scrdata_dispwin_lines;
  391.     else {
  392.         dopus_curwin[win]->offset=a;
  393.         if (dopus_curwin[win]->offset>dopus_curwin[win]->total-scrdata_dispwin_lines)
  394.             dopus_curwin[win]->offset=dopus_curwin[win]->total-scrdata_dispwin_lines;
  395.     }
  396.     if (dopus_curwin[win]->offset<0) dopus_curwin[win]->offset=0;
  397.     fixvertprop(win);
  398.     displaydir(win);
  399. }
  400.  
  401. void doinfodisplay(entry,state)
  402. struct Directory *entry;
  403. int state;
  404. {
  405.     char buf[MAXDISPLAYLENGTH],pbuf[10],dbuf[30];
  406.  
  407.     buf[0]=0;
  408.     if (entry->selected==state) {
  409.         getprot(entry->protection,pbuf);
  410.         nodayseedate(&(entry->date),dbuf);
  411.         lsprintf(buf,"%8s %18s ",pbuf,dbuf);
  412.         if (entry->type!=ENTRY_CUSTOM && entry->comment)
  413.             strcat(buf,entry->comment);
  414.     }
  415.     dostatustext(buf);
  416. }
  417.  
  418. void nodayseedate(ds,date)
  419. struct DateStamp *ds;
  420. char *date;
  421. {
  422.     char datebuf[16],timebuf[16];
  423.     struct DOpusDateTime dt;
  424.  
  425.     copy_datestamp(ds,&dt.dat_Stamp);
  426.     initdatetime(&dt,datebuf,timebuf,0);
  427.     strcpy(date,datebuf); strcat(date," "); strcat(date,timebuf);
  428. }
  429.  
  430. void displaydirgiven(win,dir,bypass)
  431. int win;
  432. struct Directory *dir;
  433. char bypass;
  434. {
  435.     struct Directory *display;
  436.     int off;
  437.  
  438.     if (win<0 ||
  439.         (!bypass && !(config->dynamicflags&UPDATE_SCROLL))) return;
  440.  
  441.     display=dopus_curwin[win]->firstentry;
  442.     off=0;
  443.     while (display) {
  444.         if (display==dir) break;
  445.         display=display->next;
  446.         ++off;
  447.     }
  448.     if (!display) return;
  449.     dopus_curwin[win]->offset=off;
  450.     if (dopus_curwin[win]->oldoff>-1) {
  451.         if (dopus_curwin[win]->offset>=dopus_curwin[win]->oldoff &&
  452.             dopus_curwin[win]->offset<dopus_curwin[win]->oldoff+scrdata_dispwin_lines)
  453.             dopus_curwin[win]->offset=dopus_curwin[win]->oldoff;
  454.     }
  455.     if (dopus_curwin[win]->offset>dopus_curwin[win]->total-scrdata_dispwin_lines)
  456.         dopus_curwin[win]->offset=dopus_curwin[win]->total-scrdata_dispwin_lines;
  457.     if (dopus_curwin[win]->offset<0) dopus_curwin[win]->offset=0;
  458.     if (dopus_curwin[win]->offset!=dopus_curwin[win]->oldoff) {
  459.         displaydir(win);
  460.         fixvertprop(win);
  461.     }
  462. }
  463.  
  464. void endfollow(win)
  465. int win;
  466. {
  467.     if (win>-1 && scrdata_old_offset_store>-1) {
  468.         dopus_curwin[win]->offset=scrdata_old_offset_store;
  469.         if (dopus_curwin[win]->offset>(dopus_curwin[win]->total-scrdata_dispwin_lines))
  470.             dopus_curwin[win]->offset=dopus_curwin[win]->total-scrdata_dispwin_lines;
  471.         if (dopus_curwin[win]->offset<0) dopus_curwin[win]->offset=0;
  472.         fixvertprop(win);
  473.         displaydir(win);
  474.         scrdata_old_offset_store=-1;
  475.     }
  476. }
  477.  
  478. void displaydir(win)
  479. int win;
  480. {
  481.     int d,a,l,tl,bl,b,ds,my,c,f,pw,px,lpst8,sc,to,y;
  482.     char sbuf[MAXDISPLAYLENGTH];
  483.     struct Directory *display;
  484.  
  485.     if (win<0 || status_iconified) return;
  486.     l=dopus_curwin[win]->oldoff-dopus_curwin[win]->offset;
  487.     display=dopus_curwin[win]->firstentry;
  488.     if (l<0) {
  489.         tl=scrdata_dispwin_lines-1+l; bl=scrdata_dispwin_lines; a=-l;
  490.     }
  491.     else {
  492.         tl=-1; bl=l; a=l;
  493.     }
  494.     b=scrdata_dispwin_lines-1;
  495.     if (dopus_curwin[win]->oldoff==-1 || a>b) {
  496.         tl=-1; bl=scrdata_dispwin_lines; ds=0; sc=0;
  497.     }
  498.     else {
  499.         b=ABSI(l);
  500.         if (config->dynamicflags&4 && b>(scrdata_dispwin_lines/4)) {
  501.             tl=-1; bl=scrdata_dispwin_lines; ds=0; sc=0;
  502.         }
  503.         else {
  504.             if (b==0) d=0;
  505.             else d=-(dopus_curwin[win]->oldoff-dopus_curwin[win]->offset)/b;
  506.             ds=1; sc=d;
  507.         }
  508.     }
  509.     for (a=0;a<dopus_curwin[win]->offset;a++) {
  510.         if (!display) break;
  511.         display=display->next;
  512.     }
  513.     if (sc<0 && ds) {
  514.         c=b-1;
  515.         for (a=0;a<c;a++) {
  516.             if (!display) break;
  517.             display=display->next;
  518.         }
  519.     }
  520.     if (ds) {
  521.         if (sc<0) my=scrdata_font_baseline;
  522.         else my=(scrdata_font_baseline+scrdata_dirwin_height)-scrdata_font_ysize;
  523.     }
  524.     else my=scrdata_font_ysize+scrdata_font_baseline+(tl*scrdata_font_ysize);
  525.     my+=scrdata_dirwin_ypos[win];
  526.     lpst8=scrdata_dirwin_height-scrdata_font_ysize;
  527.  
  528.     ++tl;
  529.     for (a=0;a<tl;a++) {
  530.         if (!display) break;
  531.         if (sc<0) display=display->last;
  532.         else display=display->next;
  533.     }
  534.     pw=scrdata_dispwin_nchars[win]; px=scrdata_dirwin_xpos[win]; to=0;
  535.     if (dopus_curwin[win]->oldhoff!=-1) {
  536.         f=dopus_curwin[win]->oldhoff-dopus_curwin[win]->hoffset;
  537.         if (f && f>-scrdata_dispwin_nchars[win] && f<scrdata_dispwin_nchars[win]) {
  538.             if (f>0) ClipBlit(&dir_rp[win],scrdata_dirwin_xpos[win],scrdata_dirwin_ypos[win],&dir_rp[win],
  539.                 (f*scrdata_font_xsize)+scrdata_dirwin_xpos[win],scrdata_dirwin_ypos[win],scrdata_dirwin_width[win]-(f*scrdata_font_xsize),scrdata_dirwin_height,0xc0);
  540.             else {
  541.                 f=-f;
  542.                 ClipBlit(&dir_rp[win],(f*scrdata_font_xsize)+scrdata_dirwin_xpos[win],scrdata_dirwin_ypos[win],&dir_rp[win],
  543.                     scrdata_dirwin_xpos[win],scrdata_dirwin_ypos[win],scrdata_dirwin_width[win]-(f*scrdata_font_xsize),scrdata_dirwin_height,0xc0);
  544.                 px=(scrdata_dirwin_width[win]-(f*scrdata_font_xsize))+scrdata_dirwin_xpos[win]; to=scrdata_dispwin_nchars[win]-f;
  545.             }
  546.             pw=f;
  547.         }
  548.     }
  549.     for (a=tl;a<bl;a++) {
  550.         setdispcol(display,win);
  551.         builddisplaystring(display,sbuf,win);
  552.         y=my;
  553.         if (ds) {
  554.             if (sc>0) ClipBlit(&dir_rp[win],scrdata_dirwin_xpos[win],scrdata_font_ysize+scrdata_dirwin_ypos[win],&dir_rp[win],
  555.                 scrdata_dirwin_xpos[win],scrdata_dirwin_ypos[win],scrdata_dirwin_width[win],lpst8,0xc0);
  556.             else ClipBlit(&dir_rp[win],scrdata_dirwin_xpos[win],scrdata_dirwin_ypos[win],&dir_rp[win],
  557.                 scrdata_dirwin_xpos[win],scrdata_font_ysize+scrdata_dirwin_ypos[win],scrdata_dirwin_width[win],lpst8,0xc0);
  558.         }
  559.         else my+=scrdata_font_ysize;
  560.         entry_text(&dir_rp[win],display,&sbuf[to],pw,px,y);
  561.         if (display) {
  562.             if (sc<0) display=display->last;
  563.             else display=display->next;
  564.         }
  565.     }
  566.     dopus_curwin[win]->oldoff=dopus_curwin[win]->offset;
  567.     dopus_curwin[win]->oldhoff=dopus_curwin[win]->hoffset;
  568. }
  569.  
  570. void display_entry(entry,win,x,y)
  571. struct Directory *entry;
  572. int win,x,y;
  573. {
  574.     char dispbuf[MAXDISPLAYLENGTH];
  575.  
  576.     setdispcol(entry,win);
  577.     builddisplaystring(entry,dispbuf,win);
  578.     entry_text(&dir_rp[win],entry,dispbuf,scrdata_dispwin_nchars[win],x,y);
  579. }
  580.  
  581. void entry_text(rp,entry,buf,len,x,y)
  582. struct RastPort *rp;
  583. struct Directory *entry;
  584. char *buf;
  585. int len,x,y;
  586. {
  587.     int a,final=0;
  588.  
  589.     Move(rp,x,y);
  590.     if (entry && entry->type==ENTRY_CUSTOM && entry->subtype==CUSTOMENTRY_DIRTREE) {
  591.         char pbuf[MAXDISPLAYLENGTH];
  592.  
  593.         strcpy(pbuf,buf);
  594.         for (a=0;a<len;a++) {
  595.             if (buf[a]=='|' || buf[a]=='+' || buf[a]=='-')
  596.                 buf[a]=' ';
  597.             else if (buf[a]!=' ') break;
  598.         }
  599.         Text(rp,buf,len);
  600.         if (entry->selected) SetAPen(rp,screen_pens[config->dirsselfg].pen);
  601.         else SetAPen(rp,screen_pens[config->dirsfg].pen);
  602.         y-=scrdata_font_baseline;
  603.  
  604.         for (a=0;a<len;a++) {
  605.             if (pbuf[a]=='|') {
  606.                 if (pbuf[a+1]=='-') draw_dirtree_gfx(rp,x,y,DIRTREEGFX_VERTCROSS);
  607.                 else draw_dirtree_gfx(rp,x,y,DIRTREEGFX_VERT);
  608.             }
  609.             else if (pbuf[a]=='-') {
  610.                 draw_dirtree_gfx(rp,x,y,(final)?DIRTREEGFX_FINALCROSS:DIRTREEGFX_CROSS);
  611.                 final=1-final;
  612.             }
  613.             else if (pbuf[a]=='+') draw_dirtree_gfx(rp,x,y,DIRTREEGFX_BRANCH);
  614.             else if (pbuf[a]!=' ') break;
  615.             x+=scrdata_font_xsize;
  616.         }
  617.     }
  618.     else Text(rp,buf,len);
  619. }
  620.  
  621. void builddisplaystring(display,sbuf,win)
  622. struct Directory *display;
  623. char *sbuf;
  624. int win;
  625. {
  626.     char buf[MAXDISPLAYLENGTH],sizebuf[20];
  627.     char *sptr,*dptr,*eptr;
  628.     int a,b,namelen;
  629.  
  630.     if (!display) CopyMem(str_space_string,sbuf,scrdata_dispwin_nchars[win]);
  631.     else switch (ENTRYTYPE(display->type)) {
  632.         case ENTRY_CUSTOM:
  633.             CopyMem(str_space_string,sbuf,scrdata_dispwin_nchars[win]);
  634.             if (display->comment) {
  635.                 a=strlen(display->comment)-dopus_curwin[win]->hoffset;
  636.                 if (a>scrdata_dispwin_nchars[win]) a=scrdata_dispwin_nchars[win];
  637.                 if (a>0) CopyMem(&display->comment[dopus_curwin[win]->hoffset],sbuf,a);
  638.             }
  639.             break;
  640.         case ENTRY_DEVICE:
  641.             CopyMem(str_space_string,sbuf,scrdata_dispwin_nchars[win]);
  642.             CopyMem(display->name,sbuf,strlen(display->name));
  643.             CopyMem(display->comment,&sbuf[scrdata_dispwin_nchars[win]-5],5);
  644.             break;
  645.         default:
  646.             namelen=config->displaylength[win][0];
  647.             if (display->type<0 || (display->type>0 && display->size>0)) {
  648.                 lsprintf(sizebuf,"%7ld ",display->size);
  649.                 if ((a=strlen(sizebuf))>8) {
  650.                     a-=8;
  651.                     if (namelen>(30-a)) namelen=30-a;
  652.                 }
  653.             }
  654.             else LStrnCpy(sizebuf,str_space_string,8);
  655.             dptr=buf; eptr=buf+dopus_curwin[win]->hlen+1;
  656.  
  657.             for (a=0;a<DISPLAY_LAST+1;a++) {
  658.                 switch (config->displaypos[win][a]) {
  659.                     case DISPLAY_NAME:
  660.                         b=namelen;
  661.                         sptr=display->name;
  662.                         while (*sptr && b) {
  663.                             *dptr++=*sptr++;
  664.                             --b;
  665.                         }
  666.                         while (b--) *dptr++=' ';
  667.                         break;
  668.                     case DISPLAY_SIZE:
  669.                         sptr=sizebuf;
  670.                         while (*sptr) *dptr++=*sptr++;
  671.                         break;
  672.                     case DISPLAY_PROTECT:
  673.                         sptr=display->protbuf;
  674.                         while (*sptr) *dptr++=*sptr++; *dptr++=' ';
  675.                         break;
  676.                     case DISPLAY_DATE:
  677.                         sptr=display->datebuf;
  678.                         while (*sptr) *dptr++=*sptr++; *dptr++=' ';
  679.                         break;
  680.                     case DISPLAY_COMMENT:
  681.                         b=config->displaylength[win][1];
  682.                         if ((sptr=display->comment)) {
  683.                             while (*sptr && b) {
  684.                                 *dptr++=*sptr++;
  685.                                 --b;
  686.                             }
  687.                         }
  688.                         while (b--) *dptr++=' ';
  689.                         break;
  690.                     case DISPLAY_FILETYPE:
  691.                         b=config->displaylength[win][2];
  692.                         if ((sptr=display->description)) {
  693.                             while (*sptr && b) {
  694.                                 *dptr++=*sptr++;
  695.                                 --b;
  696.                             }
  697.                         }
  698.                         while (b--) *dptr++=' ';
  699.                         break;
  700.                     case DISPLAY_OWNER:
  701.                         if (AccountsBase) {
  702.                             b=config->displaylength[win][3];
  703.                             if (!display->network || !(sptr=display->network->owner))
  704.                                 sptr=globstring[STR_NETWORK_NO_OWNER];
  705.                             while (*sptr && b) {
  706.                                 *dptr++=*sptr++;
  707.                                 --b;
  708.                             }
  709.                             while (b--) *dptr++=' ';
  710.                         }
  711.                         break;
  712.                     case DISPLAY_GROUP:
  713.                         if (AccountsBase) {
  714.                             b=config->displaylength[win][4];
  715.                             if (!display->network || !(sptr=display->network->group))
  716.                                 sptr=globstring[STR_NETWORK_NO_GROUP];
  717.                             while (*sptr && b) {
  718.                                 *dptr++=*sptr++;
  719.                                 --b;
  720.                             }
  721.                             while (b--) *dptr++=' ';
  722.                         }
  723.                         break;
  724.                     case DISPLAY_NETPROT:
  725.                         if (AccountsBase) {
  726.                             b=10;
  727.                             if (display->network) {
  728.                                 sptr=display->network->net_protbuf;
  729.                                 while (*sptr && b) {
  730.                                     *dptr++=*sptr++;
  731.                                     --b;
  732.                                 }
  733.                             }
  734.                             while (b--) *dptr++=' ';
  735.                         }
  736.                         break;
  737.                 }
  738.             }
  739.             while (dptr<eptr) *dptr++=' ';
  740.             CopyMem(&buf[dopus_curwin[win]->hoffset],sbuf,scrdata_dispwin_nchars[win]);
  741.             break;
  742.     }
  743. }
  744.  
  745. void setdispcol(display,win)
  746. struct Directory *display;
  747. int win;
  748. {
  749.     int fg,bg;
  750.  
  751.     if (display && !status_iconified) {
  752.         switch (ENTRYTYPE(display->type)) {
  753.             case ENTRY_FILE:
  754.                 if (display->selected) {
  755.                     fg=config->filesselfg;
  756.                     bg=config->filesselbg;
  757.                 }
  758.                 else {
  759.                     fg=config->filesfg;
  760.                     bg=config->filesbg;
  761.                 }
  762.                 break;
  763.             case ENTRY_DEVICE:
  764.                 if (display->size==DLT_DEVICE || display->size==DLT_VOLUME) {
  765.                     if (display->selected) {
  766.                         fg=config->filesselfg;
  767.                         bg=config->filesselbg;
  768.                     }
  769.                     else {
  770.                         fg=config->filesfg;
  771.                         bg=config->filesbg;
  772.                     }
  773.                     break;
  774.                 }
  775.             case ENTRY_DIRECTORY:
  776.                 if (display->selected) {
  777.                     fg=config->dirsselfg;
  778.                     bg=config->dirsselbg;
  779.                 }
  780.                 else {
  781.                     fg=config->dirsfg;
  782.                     bg=config->dirsbg;
  783.                 }
  784.                 break;
  785.             case ENTRY_CUSTOM:
  786.                 if (display->subtype==CUSTOMENTRY_USER) {
  787.                     if (display->selected) {
  788.                         fg=config->filesselfg;
  789.                         bg=config->filesselbg;
  790.                     }
  791.                     else {
  792.                         if ((display->size&0xff)==0xff) fg=config->filesfg;
  793.                         else fg=display->size&0xff;
  794.                         if ((display->size&0xff00)==0xff00) bg=config->filesbg;
  795.                         else bg=(display->size&0xff00)>>8;
  796.                     }
  797.                 }
  798.                 else {
  799.                     if (display->selected) {
  800.                         fg=config->dirsselfg;
  801.                         bg=config->dirsselbg;
  802.                     }
  803.                     else {
  804.                         fg=config->dirsfg;
  805.                         bg=config->dirsbg;
  806.                     }
  807.                 }
  808.                 break;
  809.         }
  810.     }
  811.     else {
  812.         fg=bg=config->filesbg;
  813.     }
  814.     SetAPen(&dir_rp[win],screen_pens[fg].pen);
  815.     SetBPen(&dir_rp[win],screen_pens[bg].pen);
  816. }
  817.