home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / tex / texsrc2 / Src / web2c / c / regfix < prev    next >
Text File  |  1992-04-08  |  2KB  |  121 lines

  1. /* regfix -- change locals to be register declarations.  This
  2.   produces code which runs 10% faster on some systems (e.g., Vax-11/750,
  3.   Sequent Balance).  Don't try to use this program with other than TeX
  4.   and Metafont in C.
  5.  
  6.   Tim Morgan   February 25, 1988.  */
  7.  
  8. #include "config.h"
  9.  
  10. #define BUFFER_SIZE 10240
  11. char line[BUFFER_SIZE];
  12.  
  13.  
  14.  
  15. /* Replace the last (should be only) newline in S with a null.  */
  16.  
  17. void
  18. remove_newline (s)
  19.   char *s;
  20. {
  21.   char *temp = strrchr (s, '\n');
  22.   if (temp == NULL)
  23.     {
  24.       fprintf (stderr, "Lost newline somehow.\n");
  25.       uexit (1);
  26.     }
  27.  
  28.   *temp = 0;
  29. }
  30.  
  31.  
  32. #ifdef    REGFIX        /* REST OF FILE (almost) */
  33.  
  34. #define    Puts(s)    fputs(s, stdout)
  35.  
  36. char *types[] = {"ASCIIcode ", "schar ", "eightbits ", "scaled ",
  37.     "glueord ", "halfword ", "hyphpointer ", "internalfontnumber ",
  38.     "nonnegativeinteger ", "poolpointer ", "quarterword ", "smallnumber ",
  39.     "strnumber ", "triepointer ", "integer ", "short "};
  40. #define NUMTYPES (sizeof(types)/sizeof(types[0]))
  41. int lens[NUMTYPES];
  42.  
  43.  
  44. char *
  45. matchestype ()
  46. {
  47.   register int i;
  48.  
  49.   if (line[0] != ' ' || line[1] != ' ')
  50.       return 0;
  51.  
  52.   for (i = 0; i < NUMTYPES; i++)
  53.     {
  54.       if (strncmp (&line[2], types[i], lens[i]) == 0
  55.           && strchr (line, '[') == 0)
  56.         return line + 2 + lens[i];
  57.   }
  58.  
  59.   return 0;
  60. }
  61.  
  62.  
  63. int
  64. main ()
  65. {
  66.     register int i;
  67. #ifdef    vax
  68.     register char *cp;
  69. #endif
  70.  
  71.     for (i=0; i<NUMTYPES; i++)
  72.     lens[i] = strlen(types[i]);
  73.  
  74.     /* Copy the declarations.  */
  75.     while (fgets (line, BUFFER_SIZE, stdin)
  76.            && strncmp (&line[10], "coerce", 6) != 0)
  77.       {
  78.         remove_newline (line);
  79.     puts (line);
  80.       }
  81.  
  82.     puts (line);
  83.  
  84.     while (fgets (line, BUFFER_SIZE, stdin))
  85.       {
  86.         remove_newline (line);
  87.  
  88. #ifdef    vax
  89.     if (cp = matchestype() ) {
  90.         Puts("  register long ");
  91.         puts(cp);
  92. #else
  93.     if ( matchestype() ) {
  94.         Puts("  register");
  95.         puts(line+1);
  96. #endif
  97.     } else
  98.         puts(line);
  99.     }
  100.  
  101.     fclose (stdout);
  102.     uexit (0);
  103. }
  104.  
  105. #else    /* not REGFIX */
  106.  
  107. /* If we don't want to use register variables, we just copy stdin to
  108.    stdout.  */
  109.  
  110. int
  111. main ()
  112. {
  113.     while (fgets (line, BUFFER_SIZE, stdin))
  114.       {
  115.         remove_newline (line);
  116.     puts (line);
  117.       }
  118.     uexit (0);
  119. }
  120. #endif    /* not REGFIX */
  121.