home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / applications / xlispstat / src / src1.lzh / Amiga / init.c < prev    next >
C/C++ Source or Header  |  1990-10-11  |  4KB  |  128 lines

  1. /* Init.c - Amiga specific initialization routines                     */
  2. /* Copyright (c) 1990 by J.K. Lindsey                                  */
  3. /* Additions to XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney     */
  4. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  5. /* You may give out copies of this software; for conditions see the    */
  6. /* file COPYING included with this distribution.                       */
  7.  
  8. #include <proto/intuition.h>
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <workbench/startup.h>
  12. #include <exec/memory.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "autil2.h"
  16.  
  17. #define V 33
  18. extern struct IntuitionBase *IntuitionBase;
  19. extern struct MathBase *MathBase;
  20. extern struct MathTransBase *MathTransBase;
  21. extern struct GfxBase *GfxBase;
  22. struct DosBase *DosBase;
  23. struct IconBase *IconBase;
  24.  
  25. openlibs(){
  26.    IntuitionBase=0; MathBase=0; MathTransBase=0; GfxBase=0;
  27.    IconBase=0; DosBase=0;
  28.    if(!(DosBase=(struct DosBase *)OpenLibrary("dos.library",V)))return(1);
  29.    if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary(
  30.    "intuition.library",V)))return(1);
  31.    if(!(IconBase=(struct IconBase *)OpenLibrary("icon.library",V)))return(1);
  32.    if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",V)))return(1);
  33.    if(!(MathBase=(struct MathBase *)OpenLibrary("mathffp.library",V)))return(1);
  34.    if(!(MathTransBase=(struct MathTransBase *)OpenLibrary(
  35.    "mathtrans.library",V)))return(1);
  36.    return(0);}
  37. void closelibs(){
  38.    if(MathTransBase)CloseLibrary((struct Library *)MathTransBase);
  39.    if(MathBase)CloseLibrary((struct Library *)MathBase); 
  40.    if(GfxBase)CloseLibrary((struct Library *)GfxBase);
  41.    if(IconBase)CloseLibrary((struct Library *)IconBase);
  42.    if(IntuitionBase)CloseLibrary((struct Library *)IntuitionBase);
  43.    if(DosBase)CloseLibrary((struct Library *)DosBase);}
  44.  
  45. extern struct WBStartup *WBenchMsg;
  46. int FindRoot(BPTR,char []);
  47. void SplitName(char []); 
  48.  
  49. FindStart(argc,argv,start,project,defdir)
  50. int *argc;
  51. unsigned char *argv[];
  52. char start[],project[],defdir[];{
  53.    BPTR lock,plock;
  54.    short Cli;
  55.    int i;
  56.    struct WBArg *arg;
  57.    char buffer[80];
  58.    if(*argc){
  59.       Cli=1;
  60.       plock=Lock(argv[0],ACCESS_READ);
  61.       lock=ParentDir(plock);
  62.       UnLock(plock);
  63.       SplitName(argv[0]);}
  64.    else {
  65.       Cli=0;
  66.       *argc=WBenchMsg->sm_NumArgs;
  67.       arg=WBenchMsg->sm_ArgList;
  68.       lock=arg->wa_Lock;
  69.       for(i=0;i<*argc;i++,arg++){
  70.          if(!(argv[i]=malloc(strlen(arg->wa_Name)+1)))return(1);
  71.          strcpy(argv[i],arg->wa_Name);
  72.          if(i==1)CurrentDir(arg->wa_Lock);}}
  73.    if(!Cli&&(*argc>1))start[0]=0;
  74.    else if(FindRoot(lock,start))return(0);
  75.    if(Cli)UnLock(lock);
  76.    strcat(start,argv[0]);
  77.    if((*argc)>1){
  78.       if(Cli){
  79.          for(i=1;i<*argc;i++)if(argv[i][0]!='-'){
  80.             if(lock=Lock(argv[i],ACCESS_READ)){
  81.                plock=ParentDir(lock);
  82.                UnLock(lock);
  83.                strcpy(buffer,argv[i]);
  84.                SplitName(buffer);
  85.                if(FindRoot(plock,defdir))return(1);
  86.                UnLock(plock);
  87.                strcpy(project,defdir);
  88.                strcat(project,buffer);}
  89.             break;}}
  90.       else {
  91.          strcpy(project,argv[1]);
  92.          defdir[0]=0;}}
  93.    if(*argc==1)defdir[0]=project[0]=0;
  94.    return(0);}
  95.  
  96. static FindRoot(lock,dir)
  97. BPTR lock;
  98. char dir[];{
  99.    struct FileInfoBlock *FInfo;
  100.    BPTR plock;
  101.    short i;
  102.    char temp[50];
  103.    temp[0]=0;
  104.    if(!(FInfo=(struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),
  105.    MEMF_PUBLIC)))return(1);
  106.    i=0;
  107.    while(plock=ParentDir(lock)){
  108.       Examine(lock,FInfo);
  109.       if(i)UnLock(lock);
  110.       else i=1;
  111.       lock=plock;
  112.       strcpy(dir,FInfo->fib_FileName);
  113.       strcat(dir,"/");
  114.       strcat(dir,temp);
  115.       strcpy(temp,dir);}
  116.    Examine(lock,FInfo);
  117.    if(i)UnLock(lock);
  118.    strcpy(dir,FInfo->fib_FileName);
  119.    strcat(dir,":");
  120.    strcat(dir,temp);
  121.    FreeMem((char *)FInfo,sizeof(struct FileInfoBlock));
  122.    return(0);}
  123.  
  124. static void SplitName(fn)
  125. char fn[];{
  126.    int i,j,k;
  127.    for(i=(k=strlen(fn))-1;i>=0;i--)if(fn[i]=='/'||fn[i]==':')break;
  128.    for(j=i+1;j<=k;j++)fn[j-i-1]=fn[j];}