home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / telecomm / uemlsrc / cc.c < prev    next >
C/C++ Source or Header  |  1987-08-24  |  12KB  |  316 lines

  1. /* FILE:         cc.c
  2.  * DATE:         27-Jan-1987
  3.  *               Updated 07-01-1987 to allow wildcards and linking multiple
  4.  *               files.
  5.  *               Updated 27-01-1987 to allow assembling and/or compiling and
  6.  *               to allow linking without compiling.
  7.  * AUTHOR:       Robert Royar rdroya01@bitnet
  8.  * SYSTEM:       Atari ST
  9.  * COMPILER:     Alcyon v. 4.14
  10.  * PURPOSE:      A simple minded compiler driver, no frills. (well, almost)
  11.  * USAGE:        cc filename[s] (path must agree with cc.ini)
  12.  *               the command line may contain wildcards as long as all
  13.  *               source files are on the drive designated as the sdir in
  14.  *               this file.  Using the link option will cause the linker to
  15.  *               look for a command file on the source directory.  That link
  16.  *               file should be named `foo.lnk' where `foo' is the name in
  17.  *               the cc.ini file associated with the lnkfile value.  The
  18.  *               link file should tell the linker to place the output on the
  19.  *               source dir if the relocation program is to find the
  20.  *               `foo.68k' file and successfully create a `foo.prg' file.
  21.  *               Calling the program without a command line and with dolink=1
  22.  *               will force it to try to link the file `linkfile.68k' and
  23.  *               then call relmod.  Giving it a filename with an .s extent
  24.  *               will skip the compiling and assemble the file.  Files with
  25.  *               .s extents and .c extents may be mixed on a line.
  26.  * DISTRIBUTION: Public Domain.  Do with it what you will.  Just leave
  27.  *               the header intact.
  28.  */
  29. #include <stdio.h>
  30. #include <osbind.h>
  31. #include <ctype.h>
  32. #include <errno.h>
  33.  
  34. unsigned long _STKSIZ = 16284;  /* keep 16K */
  35.  
  36. /* These are the defaults.  All of them can be over-ridden by values
  37.  * in the cc.ini file if that file is on the default drive and directory.
  38.  */
  39. char sdir[81] = "e:\\"; /* where the source files are */
  40. char include[81] = "d:\\stdlib.h\\"; /* include files */
  41. char tdir[81] = "m:\\"; /* temporary files (all of them) */
  42. char bin[81] = "c:\\bin\\";     /* compiler directory */
  43. char symb[81] = "c:\\bin\\";    /* as68 symbols */
  44. char floflag[12] = " ";         /* float ?      */
  45. char delflag[12] = "1";         /* delete temporary files */
  46. char lnkflag[12] = "0";         /* link file[s] if == "1" */
  47. char warn[12] = " ";            /* make it -w to suppress warnings */
  48. char syslib[81] = "c:\\bin\\";  /* drive to log for linker */
  49. char lnk[81] = "out";           /* .68K and .lnk filename */
  50. char fprg[81] = "out";          /* final output name */
  51. char pname[81];
  52. char command[81];
  53. char source[81];
  54. int temdrv;
  55. char delfile[80];
  56. int delete = 1;
  57. int dolink = 0;
  58. int doasm  = FALSE;
  59. char path[128];
  60. int exec;
  61. int curdrv;
  62. char author[30] = "Robert Royar";
  63.  
  64. main(argc,argv)
  65. register int argc;
  66. char *argv[];
  67. {
  68.         register char c, *ptr;
  69.         register int argnum;
  70.         char *index();
  71.  
  72.         argnum = 1;
  73.         curdrv = (int)Dgetdrv(); /* 0 = A */
  74.         Dgetpath(path,(1+curdrv)); /* 1 = A */
  75.         if (access("cc.ini",4) != -1)
  76.                 if (!inivar())
  77.                         exit(-1);
  78.         if (argc == 1 && dolink == FALSE)
  79.                 {
  80.                 fprintf(stderr,"usage: %s filename[s]\n",argv[0]);
  81.                 exit(-1);
  82.                 }
  83.         if (argc == 1)
  84.                 {
  85.                 exec = linkfil();
  86.                 goto out;
  87.                 }
  88.         if (tdir[1] == ':')
  89.                 {
  90.                 c = (char)toupper(tdir[0]);
  91.                 temdrv = (int)(c - 'A');
  92.                 Dsetdrv(temdrv);        /* Log into temp drive */
  93.                 }
  94.         if((exec=(int)Dsetpath(tdir))!=0)
  95.                 goto out;
  96.         while(--argc)
  97.                 {
  98.                 strcpy(source,argv[argnum++]);
  99.                 if ((ptr=index(source,':'))!=NULL)
  100.                         strcpy(source,++ptr);
  101.                 /* If the file has an .s extent, then assemble it.
  102.                  * Check the source dir first.  If it's not there,
  103.                  * check the temp dir.  Set the doasm flag to fit
  104.                  * the outcome, or break if no file found.
  105.                  */
  106.                 if ((ptr=index(source,'.'))!=NULL)
  107.                         {
  108.                         *ptr = '\0';    /* don't let the extension through */
  109.                         /* delete any existing .o files */
  110.                         sprintf(delfile,"%s%s.o",tdir,source);
  111.                         if (access(delfile,4)==NULL)
  112.                                 unlink(delfile);
  113.                         ++ptr;
  114.                         if (*ptr != '\0')
  115.                                 {
  116.                                 *ptr = tolower(*ptr);
  117.                                 if (strcmp(ptr,"s")==NULL) /* assemb only */
  118.                                         {
  119.                                         sprintf(command,"%s%s.s",sdir,source);
  120.                                         if ((exec=access(command,4)) == -1)
  121.                                                 {
  122.                                                 sprintf(command,"%s%s.s",
  123.                                                        tdir,source);
  124.                                                 if ((exec=access(command,4))
  125.                                                      == -1)
  126.                                                         continue;
  127.                                                 else /* this is a tdir file */
  128.                                                         doasm = FALSE;
  129.                                                 }
  130.                                         else    /* this asm file is on sdir */
  131.                                                 doasm = TRUE;
  132.                                         if ((exec=as())!=NULL)
  133.                                                 goto out;
  134.                                         else
  135.                                                 continue;
  136.                                         }
  137.                                 }
  138.                         }
  139.                 /* delete any existing .o files */
  140.                 sprintf(delfile,"%s%s.o",tdir,source);
  141.                 if (access(delfile,4)==NULL)
  142.                         unlink(delfile);
  143.                 doasm = FALSE;
  144.                 sprintf(command,"%s%s.c",sdir,source);
  145.                 if ((exec=access(command,4)) == -1)
  146.                         break;
  147.                 if ((exec=cc())!=NULL)
  148.                         break;
  149.                 }
  150.         if (dolink && (exec == NULL))
  151.                 exec = linkfil();
  152. out:    Dsetdrv(curdrv);
  153.         Dsetpath(path);
  154.         exit(exec);
  155. }
  156.  
  157. cc()
  158. {
  159.         fprintf(stderr,"\nCompiling : %s%s.c\n",sdir,source);
  160.         sprintf(&command[1],"-i %s %s%s.c %s%s.i ",
  161.                 include,sdir,source,tdir,source);
  162.         command[0] = (char)strlen(&command[1]);
  163.         sprintf(pname,"%sCP68.PRG",bin);
  164.         if((exec=(int)Pexec(0,pname,command,0L))!=0)
  165.                 return(exec);
  166.         sprintf(&command[1],"%s%s.i %s%s.1 %s%s.2 %s%s.3 %s %s",
  167.                 tdir,source,tdir,source,tdir,source,tdir,source,floflag,warn);
  168.         command[0] = (char)strlen(&command[1]);
  169.         sprintf(pname,"%sC068.PRG",bin);
  170.         if((exec=(int)Pexec(0,pname,command,0L))!=0)
  171.                 return(exec);
  172.         if (delete)
  173.                 {
  174.                 sprintf(command,"%s%s.i",tdir,source);
  175.                 unlink(command);
  176.                 }
  177.         sprintf(&command[1],"%s%s.1 %s%s.2 %s%s.s",
  178.         tdir,source,tdir,source,tdir,source);
  179.         command[0] = (char)strlen(&command[1]);
  180.         sprintf(pname,"%sC168.PRG",bin);
  181.         if((exec=(int)Pexec(0,pname,command,0L))!=0)
  182.                 return(exec);
  183.         sprintf(command,"%s%s.1",tdir,source);
  184.         unlink(command);
  185.         sprintf(command,"%s%s.2",tdir,source);
  186.         unlink(command);
  187.         exec = as();
  188.         return(exec);
  189. }
  190.  
  191. as()
  192. {
  193.         if (!doasm)
  194.                 {
  195.                 fprintf(stderr,"\nAssembling : %s%s.s\n",tdir,source);
  196.                 sprintf(&command[1],"-l -u -s %s %s%s.s",bin,tdir,source);
  197.                 }
  198.         else
  199.                 {
  200.                 fprintf(stderr,"\nAssembling : %s%s.s\n",sdir,source);
  201.                 sprintf(&command[1],"-l -u -s %s %s%s.s",bin,sdir,source);
  202.                 }
  203.         command[0] = (char)strlen(&command[1]);
  204.         sprintf(pname,"%sAS68.PRG",bin);
  205.         if((exec=(int)Pexec(0,pname,command,0L))!=0)
  206.                 return(exec);
  207.         sprintf(command,"%s%s.o",tdir,source);
  208.         if ((exec=access(command,4))==NULL)
  209.                 if (delete)
  210.                         {
  211.                         sprintf(command,"%s%s.s",tdir,source);
  212.                         unlink(command);
  213.                         }
  214.         return(exec);
  215. }
  216.  
  217. linkfil()
  218. {
  219.         register char c;
  220.  
  221.         if (syslib[1] == ':')
  222.                 {
  223.                 c = (char)toupper(syslib[0]);
  224.                 temdrv = (int) (c - 'A');
  225.                 Dsetdrv(temdrv);
  226.                 }
  227.         else
  228.                 Dsetdrv(curdrv);
  229.         Dsetpath(syslib);
  230.         /* save disk write errors */
  231.         sprintf(delfile,"%s%s.68k",sdir,lnk);
  232.         if (access(delfile,4)==NULL)
  233.                 unlink(delfile);
  234.         sprintf(delfile,"%s%s.prg",tdir,lnk);
  235.         if (access(delfile,4)==NULL)
  236.                 unlink(delfile);
  237.         sprintf(source,"%s%s",sdir,lnk);
  238.         sprintf(pname,"%s%s",bin,"link68.ttp");
  239.         sprintf(&command[1],"[co[%s.lnk]]",source);
  240.         command[0] = (char)strlen(&command[1]);
  241.         if ((exec=Pexec(0,pname,command,0L))!=0)
  242.                 return(exec);
  243.         sprintf(source,"%s%s.68K",sdir,lnk);
  244.         if ((exec=access(source,4))!=NULL)
  245.                 return(exec);
  246.         sprintf(pname,"%s%s",tdir,lnk);
  247.         sprintf(&command[1],"%s %s",source,pname);
  248.         sprintf(pname,"%s%s",bin,"relmod.ttp");
  249.         command[0] = (char)strlen(&command[1]);
  250.         if ((exec=Pexec(0,pname,command,0L))!=0)
  251.                 return(exec);
  252.         if ((exec=access(delfile,4))==NULL)
  253.                 if (delete)
  254.                         unlink(source);
  255.         return(exec);
  256. }
  257.  
  258. inivar()
  259. {
  260.         FILE *freopen();
  261.         char *gets(), *index();
  262.         register char *ptr;
  263.         static char line[81];
  264.  
  265.         if (freopen("cc.ini","r",stdin) != stdin)
  266.                 {
  267.                 fprintf(stderr,"cc: cannot open %scc.ini\n",path);
  268.                 return(0);
  269.                 }
  270.         while (gets(line))
  271.                 {
  272.                 if ((ptr=index(line,' '))!=(char *)NULL)
  273.                         *ptr = '\0';
  274.                 if ((ptr=index(line,'\t'))!=(char *)NULL)
  275.                         *ptr = '\0';
  276.                 if ((ptr=index(line,'='))!=(char *)NULL)
  277.                         *ptr = '\0';
  278.                 else
  279.                         continue;
  280.                 ++ptr;
  281.                 if (strcmp(line,"source")==NULL)
  282.                         strncpy(sdir,ptr,80);
  283.                 else if (strcmp(line,"include")==NULL)
  284.                         strncpy(include,ptr,80);
  285.                 else if (strcmp(line,"temp")==NULL)
  286.                         strncpy(tdir,ptr,80);
  287.                 else if (strcmp(line,"bin")==NULL)
  288.                         strncpy(bin,ptr,80);
  289.                 else if (strcmp(line,"symb")==NULL)
  290.                         strncpy(symb,ptr,80);
  291.                 else if (strcmp(line,"syslib")==NULL)
  292.                         strncpy(syslib,ptr,80);
  293.                 else if (strcmp(line,"linkfile")==NULL)
  294.                         strncpy(lnk,ptr,80);
  295.                 else if (strcmp(line,"float")==NULL)
  296.                         strncpy(floflag,ptr,3);
  297.                 else if (strcmp(line,"warn")==NULL)
  298.                         strncpy(warn,ptr,3);
  299.                 else if (strcmp(line,"delete")==NULL)
  300.                         {
  301.                         strncpy(delflag,ptr,2);
  302.                         if (strncmp(delflag,"0",1)==NULL)
  303.                                 delete = FALSE;
  304.                         }
  305.                 else if (strcmp(line,"dolink")==NULL)
  306.                         {
  307.                         strncpy(lnkflag,ptr,2);
  308.                         if (strncmp(lnkflag,"1",1)==NULL)
  309.                                 dolink = TRUE;
  310.                         }
  311.                 else if (feof(stdin))
  312.                         break;
  313.                 }
  314.         return(1);
  315. }
  316.