main.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. * Author: Hans van Staveren
  6. */
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include "param.h"
  10. #include "types.h"
  11. #include "tes.h"
  12. #include "alloc.h"
  13. #include "util.h"
  14. #include "getline.h"
  15. #include "cleanup.h"
  16. #include "util.h"
  17. #include "putline.h"
  18. #include <em_spec.h>
  19. #include "ext.h"
  20. #include <missing_proto.h>
  21. /*
  22. * Main program for EM optimizer
  23. */
  24. void fileinit();
  25. void flags(char *s);
  26. int main(int argc, char *argv[])
  27. {
  28. int somespace[STACKROOM];
  29. progname = argv[0];
  30. while (argc-->1 && **++argv == '-')
  31. flags(*argv);
  32. if (argc>1) {
  33. fprintf(stderr,"Usage: %s [-Ln] [-m<num>] [name]\n",progname);
  34. exit(-1);
  35. }
  36. if (argc)
  37. if (freopen(*argv,"r",stdin) == NULL)
  38. error("Cannot open %s",*argv);
  39. fileinit();
  40. coreinit((short *)somespace,(short *)(somespace+STACKROOM));
  41. getlines();
  42. cleanup();
  43. return(0);
  44. }
  45. void flags(char *s)
  46. {
  47. for (s++;*s;s++)
  48. switch(*s) {
  49. case 'L': Lflag = TRUE; break;
  50. case 'n': nflag = TRUE; break;
  51. case 'm': if (*(s+1) == 'l') {
  52. s++;
  53. repl_longmuls = TRUE;
  54. }
  55. repl_muls = atoi(s+1); break;
  56. }
  57. }
  58. void fileinit()
  59. {
  60. if (readshort() != (short) sp_magic)
  61. error("wrong input file");
  62. if (Lflag) {
  63. mktemp(template);
  64. outfile = fopen(template, "w");
  65. if (outfile == NULL)
  66. error("can't create %s",template);
  67. } else {
  68. outfile = stdout;
  69. outshort(sp_magic);
  70. }
  71. }