Back to index

tetex-bin  3.0
regfix.c
Go to the documentation of this file.
00001 /* regfix -- change locals to be register declarations.  This
00002    produces code which runs 10% faster on some systems (e.g., Vax-11/750,
00003    Sequent Balance).  Don't try to use this program with other than TeX
00004    and Metafont in C.
00005 
00006    Tim Morgan   February 25, 1988.  */
00007 
00008 #include "config.h"
00009 
00010 #ifdef REGFIX        /* REST OF FILE (almost) */
00011 
00012 #define BUFFER_SIZE 10240
00013 char line[BUFFER_SIZE];
00014 
00015 
00016 
00017 /* Replace the last (should be only) newline in S with a null.  */
00018 
00019 void
00020 remove_newline P1C(string, s)
00021 {
00022   char *temp = strrchr (s, '\n');
00023   if (temp == NULL)
00024     {
00025       fprintf (stderr, "regfix: Lost newline somehow.\n");
00026       exit (EXIT_FAILURE);
00027     }
00028 
00029   *temp = 0;
00030 }
00031 
00032 
00033 
00034 #define       Puts(s)       fputs(s, stdout)
00035 
00036 char *types[] = {"ASCIIcode ", "schar ", "eightbits ", "scaled ",
00037        "glueord ", "halfword ", "hyphpointer ", "internalfontnumber ",
00038        "nonnegativeinteger ", "poolpointer ", "quarterword ", "smallnumber ",
00039        "strnumber ", "triepointer ", "integer ", "short "};
00040 #define NUMTYPES (sizeof(types)/sizeof(types[0]))
00041 int lens[NUMTYPES];
00042 
00043 
00044 char *
00045 matchestype P1H(void)
00046 {
00047   register int i;
00048 
00049   if (line[0] != ' ' || line[1] != ' ')
00050       return 0;
00051 
00052   for (i = 0; i < NUMTYPES; i++)
00053     {
00054       if (strncmp (&line[2], types[i], lens[i]) == 0
00055           && strchr (line, '[') == 0)
00056         return line + 2 + lens[i];
00057   }
00058 
00059   return 0;
00060 }
00061 
00062 
00063 int
00064 main P1H(void)
00065 {
00066     register int i;
00067 #ifdef vax
00068     register char *cp;
00069 #endif
00070 
00071     for (i=0; i<NUMTYPES; i++)
00072        lens[i] = strlen(types[i]);
00073 
00074     /* Copy the declarations.  */
00075     while (fgets (line, BUFFER_SIZE, stdin)
00076            && strncmp (&line[10], "coerce", 6) != 0)
00077       {
00078         remove_newline (line);
00079        puts (line);
00080       }
00081 
00082     puts (line);
00083 
00084     while (fgets (line, BUFFER_SIZE, stdin))
00085       {
00086         remove_newline (line);
00087 
00088 #ifdef vax
00089        if (cp = matchestype() ) {
00090            Puts("  register long ");
00091            puts(cp);
00092 #else
00093        if ( matchestype() ) {
00094            Puts("  register");
00095            puts(line+1);
00096 #endif
00097        } else
00098            puts(line);
00099     }
00100 
00101     fclose (stdout);
00102     uexit (0);
00103 }
00104 
00105 #else /* not REGFIX */
00106 
00107 /* If we don't want to use register variables, we just copy stdin to
00108    stdout.  If writing or reading fail, exit with bad status.  */
00109 
00110 int
00111 main ()
00112 {
00113   int c;
00114 
00115   while ((c = getchar ()) != EOF)
00116     {
00117       if (putchar (c) == EOF)
00118         {
00119           perror ("regfix");
00120           exit (EXIT_FAILURE);
00121         }
00122     }
00123 
00124   if (!feof (stdin))
00125     {
00126       perror ("regfix");
00127       exit (EXIT_FAILURE);
00128     }
00129 
00130   return EXIT_SUCCESS;
00131 }
00132 
00133 #endif /* not REGFIX */