home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Internet / Strony_WWW / Opus4.x / DOpus414JRsrc.lha / DirectoryOpus4 / Program / main10.c < prev    next >
C/C++ Source or Header  |  2000-03-08  |  12KB  |  461 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. void initdatetime(datetime,datebuf,timebuf,foo)
  34. struct DOpusDateTime *datetime;
  35. char *datebuf,*timebuf;
  36. int foo;
  37. {
  38.     datetime->dat_Format=dateformat(config->dateformat);
  39.     datetime->dat_StrDay=(UBYTE *)NULL;
  40.     datetime->dat_StrDate=(BYTE *)datebuf;
  41.     datetime->dat_StrTime=(BYTE *)timebuf;
  42.     if (foo==-1 || (foo && config->dateformat&DATE_SUBST))
  43.         datetime->dat_Flags=DDTF_SUBST;
  44.     else datetime->dat_Flags=0;
  45.     if (foo>0 && config->dateformat&DATE_12HOUR)
  46.         datetime->dat_Flags|=DDTF_12HOUR;
  47.     datetime->dat_Flags|=DDTF_CUSTOM;
  48.     datetime->custom_months=date_months;
  49.     datetime->custom_shortmonths=date_shortmonths;
  50.     datetime->custom_weekdays=date_weekdays;
  51.     datetime->custom_shortweekdays=date_shortweekdays;
  52.     datetime->custom_special_days=date_special;
  53.     StampToStr(datetime);
  54. }
  55.  
  56. void doarexx(rexx)
  57. int rexx;
  58. {
  59.     char buf[256];
  60.  
  61.     buf[0]=0;
  62.     if (rexx) strcpy(buf,rexx_args[0]);
  63.     else {
  64.         strcpy(buf,str_arexx_command);
  65.         if (!(whatsit(globstring[STR_ENTER_AREXX_COMMAND],256,buf,(char *)-2))) return;
  66.     }
  67.     if (!buf[0]) return;
  68.     if (!(strstri(buf,"address")) && buf[0]!='\"') {
  69.         strcpy(str_arexx_command,buf);
  70.         strcpy(&buf[1],str_arexx_command);
  71.         buf[0]='*';
  72.         if (getfunction(buf,NULL)!=-1) {
  73.             dofunctionstring(buf,NULL,NULL,NULL);
  74.             return;
  75.         }
  76.         strcpy(buf,str_arexx_command);
  77.     }
  78.     if (!(FindPort("REXX"))) {
  79.         simplerequest(globstring[STR_AREXX_NOT_RUNNING],str_okaystring,NULL);
  80.         return;
  81.     }
  82.     strcpy(str_arexx_command,buf);
  83.     status_flags|=STATUS_DONEREXX;
  84.     rexx_command(buf,NULL);
  85. }
  86.  
  87. void setcurdir(rexx)
  88. int rexx;
  89. {
  90.     static int time_through=0;
  91.     char dir[256];
  92.     BPTR lock;
  93.  
  94.     if (!rexx) {
  95.         expand_path("",dir);
  96.         if (!(whatsit(globstring[STR_ENTER_NEW_CD],256,dir,(char *)-1))) {
  97.             myabort();
  98.             return;
  99.         }
  100.     }
  101.     else strcpy(dir,rexx_args[0]);
  102.     if (!(lock=Lock(dir,ACCESS_READ))) {
  103.         doerror(IoErr());
  104.         return;
  105.     }
  106.     if (lock=CurrentDir(lock)) {
  107.         if (time_through) UnLock(lock);
  108.         ++time_through;
  109.     }
  110.     okay();
  111. }
  112.  
  113. void dodevicelist(win)
  114. int win;
  115. {
  116.     struct DeviceList *devlist;
  117.     struct RootNode *rootnode;
  118.     struct DosInfo *dosinfo;
  119.     char devname[32];
  120.     int type;
  121.     static char type_order[4]={DLT_DEVICE,DLT_VOLUME,DLT_DIRECTORY,-1};
  122.     struct Directory *addafter=NULL;
  123.  
  124.     if (status_iconified) return;
  125.     makespecialdir(win,globstring[STR_DEVICE_LIST_TITLE]);
  126.  
  127.     dostatustext(globstring[STR_SCANNING_DEVICE_LIST]);
  128.     busy();
  129.     rootnode=(struct RootNode *) DOSBase->dl_Root;
  130.     dosinfo=(struct DosInfo *) BADDR(rootnode->rn_Info);
  131.     for (type=0;type<4;type++) {
  132.         devlist=(struct DeviceList *) BADDR(dosinfo->di_DevInfo);
  133.         while (devlist) {
  134.             if (status_haveaborted) {
  135.                 myabort();
  136.                 break;
  137.             }
  138.             if (devlist->dl_Type==type_order[type] ||
  139.                 (devlist->dl_Type>DLT_VOLUME && type_order[type]==-1)) {
  140.                 if (devlist->dl_Type!=DLT_DEVICE || devlist->dl_Task) {
  141.                     BtoCStr((BPTR)devlist->dl_Name,devname,32);
  142.                     strcat(devname,":");
  143.                     if (!(addfile(dopus_curwin[win],
  144.                         win,devname,devlist->dl_Type,0,
  145.                         NULL,NULL,0,0,FALSE,NULL,addafter,0,0))) break;
  146.                 }
  147.             }
  148.             devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
  149.         }
  150.         if ((addafter=dopus_curwin[win]->firstentry))
  151.             while (addafter->next) addafter=addafter->next;
  152.     }
  153.     refreshwindow(win,3);
  154.     unbusy();
  155.     okay();
  156. }
  157.  
  158. huntfile(name,completename,aa)
  159. char *name,*completename;
  160. int *aa;
  161. {
  162.     char buf[FILEBUF_SIZE];
  163.     int rec;
  164.  
  165.     StrToUpper(name,buf);
  166.     if (LMatchPatternI(str_hunt_name_parsed,buf)) {
  167.         char mesbuf[300],*ptr;
  168.  
  169.         if (ptr=BaseName(completename)) {
  170.             strcpy(buf,BaseName(completename));
  171.             *ptr=0;
  172.         }
  173.         else buf[0]=0;
  174.  
  175.         lsprintf(mesbuf,globstring[STR_FOUND_A_MATCH],buf,completename);
  176.         if ((rec=simplerequest(mesbuf,
  177.             str_okaystring,globstring[STR_ABORT],globstring[STR_SKIP],NULL))==1) {
  178.             if (!status_iconified) {
  179.                 unbusy();
  180.                 advancebuf(data_active_window,1);
  181.                 strcpy(str_pathbuffer[data_active_window],completename);
  182.                 startgetdir(data_active_window,3);
  183.                 busy();
  184.             }
  185.             return(-3);
  186.         }
  187.         else if (rec==2) return(0);
  188.         else if (rec==0) return(-1);
  189.     }
  190.     else *aa=0;
  191.     return(0);
  192. }
  193.  
  194. void checksize(win)
  195. int win;
  196. {
  197.     BPTR mylock;
  198.  
  199.     main_proc->pr_WindowPtr=(APTR)-1;
  200.     if (mylock=Lock(str_pathbuffer[win],ACCESS_READ)) {
  201.         UnLock(mylock);
  202.         seename(win);
  203.     }
  204.     else displayname(win,1);
  205.     if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
  206. }
  207.  
  208. void centerwindow(wind)
  209. struct NewWindow *wind;
  210. {
  211.     int h,w,pw,ph;
  212.     struct Screen scrbuf;
  213.  
  214.     if (!status_iconified && Window) {
  215.         w=Window->WScreen->Width;
  216.         h=Window->WScreen->Height;
  217.         pw=Window->Width;
  218.         ph=Window->Height;
  219.     }
  220.     else {
  221.         GetWBScreen(&scrbuf);
  222.         pw=w=scrbuf.Width;
  223.         ph=h=scrbuf.Height;
  224.     }
  225.  
  226.     if (wind->Width>w) wind->Width=w;
  227.     if (wind->Height>h) wind->Height=h;
  228.     wind->LeftEdge=(pw-wind->Width)/2;
  229.     wind->TopEdge=(ph-wind->Height)/2;
  230.     wind->Type=CUSTOMSCREEN;
  231.  
  232.     if (!status_publicscreen) wind->Screen=MainScreen;
  233.     else {
  234.         if (Window) wind->Screen=Window->WScreen;
  235.         else wind->Type=WBENCHSCREEN;
  236.         if (!status_iconified && Window) {
  237.             wind->LeftEdge+=Window->LeftEdge;
  238.             wind->TopEdge+=Window->TopEdge;
  239.         }
  240.     }
  241. }
  242.  
  243. char *parsedatetime(buf,dbuf,tbuf,dis)
  244. char *buf,*dbuf,*tbuf;
  245. int *dis;
  246. {
  247.     char *datebuf,*timebuf,*ptr,*temp,dbuffer[80],mydtbuf[20],mytmbuf[20];
  248.     struct DOpusDateTime datetime;
  249.     int a,b,c,swap=0;
  250.  
  251.     timebuf=datebuf=NULL; *dis=0;
  252.     strcpy(dbuffer,buf); b=strlen(dbuffer);
  253.     for (a=0;a<b;a++) if (!(isspace(dbuffer[a]))) break;
  254.     if (a==b) goto getout;
  255.     if (dbuffer[a]=='>') {
  256.         ++a; *dis=2;
  257.         goto getout;
  258.     }
  259.     datebuf=&dbuffer[a];
  260.  
  261.     for (++a;a<b;a++) {
  262.         if (isspace(dbuffer[a])) {
  263.             dbuffer[a]=0;
  264.             break;
  265.         }
  266.         if (dbuffer[a]==':') swap=1;
  267.     }
  268.     if (a>=b) goto getout;
  269.     for (++a;a<b;a++) if (!(isspace(dbuffer[a]))) break;
  270.     if (a>=b) goto getout;
  271.  
  272.     if (dbuffer[a]=='>') {
  273.         ++a; *dis=1;
  274.         goto getout;
  275.     }
  276.  
  277.     timebuf=&dbuffer[a];
  278.     for (++a;a<b;a++) {
  279.         if (isspace(dbuffer[a])) {
  280.             dbuffer[a]=0;
  281.             break;
  282.         }
  283.     }
  284.     if (a==b) goto getout;
  285.     c=a;
  286.     for (++a;a<b;a++) {
  287.         if (dbuffer[a]=='>') {
  288.             c=a+1; *dis=1;
  289.             break;
  290.         }
  291.     }
  292.     a=c;
  293. getout:
  294.     ptr=&buf[a];
  295.     if (swap) {
  296.         temp=datebuf; datebuf=timebuf; timebuf=temp;
  297.     }
  298.  
  299.     DateStamp(&(datetime.dat_Stamp));
  300.     initdatetime(&datetime,mydtbuf,mytmbuf,-1);
  301.  
  302.     c=0;
  303.     if (datebuf && (a=strlen(datebuf))<12 && a>4) strcpy(dbuf,datebuf);
  304.     else {
  305.         if ((*dis)!=2) {
  306.             c=1;
  307.             strcpy(dbuf,mydtbuf);
  308.         }
  309.         else {
  310.             char *fptr;
  311.  
  312.             switch (dateformat(config->dateformat)) {
  313.                 case FORMAT_INT: fptr="78-01-01"; break;
  314.                 case FORMAT_USA:
  315.                 case FORMAT_AUS:
  316.                     fptr="01-01-78"; 
  317.                     break;
  318.                 default:
  319.                     fptr="1-Jan-78";
  320.                     break;
  321.             }
  322.             strcpy(dbuf,fptr);
  323.         }
  324.     }
  325.     if (timebuf && (a=strlen(timebuf))<9 && a>2) {
  326.         strcpy(tbuf,timebuf);
  327.         if (!(*dis)) *dis=-1;
  328.     }
  329.     else {
  330.         if (c) strcpy(tbuf,mytmbuf);
  331.         else strcpy(tbuf,"00:00:00");
  332.     }
  333.     return(ptr);
  334. }
  335.  
  336. void copy_datestamp(source,dest)
  337. struct DateStamp *source,*dest;
  338. {
  339.     dest->ds_Days=source->ds_Days;
  340.     dest->ds_Minute=source->ds_Minute;
  341.     dest->ds_Tick=source->ds_Tick;
  342. }
  343.  
  344. void readkeys(keys)
  345. APTR keys;
  346. {
  347.     keyboard_req->io_Length=13;
  348.     keyboard_req->io_Data=(APTR)keys;
  349.     keyboard_req->io_Command=KBD_READMATRIX;
  350.     DoIO((struct IORequest *)keyboard_req);
  351. }
  352.  
  353. ULONG clone_screen(original,clone)
  354. struct Screen *original;
  355. struct ExtNewScreen *clone;
  356. {
  357.     struct Screen scrbuf;
  358.  
  359.     if (system_version2) {
  360.         struct Screen *screen=NULL;
  361.         ULONG modes;
  362.  
  363.         if (original ||
  364.             (original=screen=LockPubScreen("Workbench"))) {
  365.             clone->Width=original->Width;
  366.             clone->Height=original->Height;
  367.             if ((clone->Depth=original->RastPort.BitMap->Depth)>config->scrdepth)
  368.                 clone->Depth=config->scrdepth;
  369.             clone->ViewModes=original->ViewPort.Modes;
  370.             modes=GetVPModeID(&original->ViewPort);
  371.             if (screen) UnlockPubScreen(NULL,screen);
  372.             return(modes);
  373.         }
  374.     }
  375.  
  376.     GetScreenData((char *)&scrbuf,
  377.         sizeof(struct Screen),
  378.         (original)?CUSTOMSCREEN:WBENCHSCREEN,
  379.         original);
  380.  
  381.     clone->Width=scrbuf.Width;
  382.     clone->Height=scrbuf.Height;
  383.     if ((clone->Depth=scrbuf.RastPort.BitMap->Depth)>4) clone->Depth=4;
  384.     clone->ViewModes=scrbuf.ViewPort.Modes;
  385.     return((ULONG)clone->ViewModes);
  386. }
  387.  
  388. copy_string(string,copy,memkey)
  389. char *string,**copy;
  390. struct DOpusRemember **memkey;
  391. {
  392.     if (!string) {
  393.         *copy=NULL;
  394.         return(1);
  395.     }
  396.     if (!(*copy=LAllocRemember(memkey,strlen(string)+1,0))) return(0);
  397.     strcpy(*copy,string);
  398.     return(1);
  399. }
  400.  
  401. char *strstri(string,substring)
  402. char *string,*substring;
  403. {
  404.     int a,len,sublen;
  405.  
  406.     len=(strlen(string)-(sublen=strlen(substring)))+1;
  407.     if (len<1) return(NULL);
  408.  
  409.     for (a=0;a<len;a++) {
  410.         if (LStrnCmpI(&string[a],substring,sublen)==0)
  411.             return(string+a);
  412.     }
  413.     return(NULL);
  414. }
  415.  
  416. struct MsgPort *CreateUniquePort(base,buffer,count)
  417. char *base,*buffer;
  418. int *count;
  419. {
  420.     int a;
  421.     struct MsgPort *port;
  422.  
  423.     Forbid();
  424.     for (a=0;;a++) {
  425.         lsprintf(buffer,"%s.%ld",base,a+1);
  426.         if (!(FindPort(buffer))) {
  427.             port=LCreatePort(buffer,0);
  428.             if (count) *count=a;
  429.             break;
  430.         }
  431.     }
  432.     Permit();
  433.     return(port);
  434. }
  435.  
  436. identify_and_load(win,unit)
  437. int win,unit;
  438. {
  439.     char buf[20];
  440.     BPTR lock;
  441.     APTR wsave;
  442.  
  443.     wsave=main_proc->pr_WindowPtr;
  444.     main_proc->pr_WindowPtr=(APTR)-1;
  445.  
  446.     lsprintf(buf,"DF%ld:",unit);
  447.     if (!(lock=Lock(buf,ACCESS_READ))) {
  448.         lsprintf(buf,"PC%ld:",unit);
  449.         if (!(lock=Lock(buf,ACCESS_READ))) return(0);
  450.     }
  451.     UnLock(lock);
  452.  
  453.     main_proc->pr_WindowPtr=wsave;
  454.  
  455.     if (win>-1) {
  456.         strcpy(str_pathbuffer[win],buf);
  457.         startgetdir(win,SGDFLAGS_CANMOVEEMPTY);
  458.     }
  459.     return(1);
  460. }
  461.