home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / pascal2c / self.c < prev    next >
C/C++ Source or Header  |  1992-08-03  |  2KB  |  78 lines

  1. /* Output from p2c, the Pascal-to-C translator */
  2. /* From input file "dist/examples/self.p" */
  3.  
  4.  
  5. #include <p2c/p2c.h>
  6.  
  7.  
  8. typedef Char s[256];
  9.  
  10. typedef long n;
  11.  
  12.  
  13. Static s a[100];
  14. Static long i, j;
  15.  
  16.  
  17. Static long t(a)
  18. long a;
  19. {
  20.   if (a < 7)
  21.     return a;
  22.   else
  23.     return (a + 11);
  24. }
  25.  
  26.  
  27. Static Char *q(Result, a_)
  28. Char *Result, *a_;
  29. {
  30.   s a;
  31.   n j;
  32.   Char STR1[256];
  33.  
  34.   strcpy(a, a_);
  35.   for (j = strlen(a) - 1; j >= 0; j--) {
  36.     if (a[j] == '\'') {
  37.       sprintf(STR1, "'%s", a + j);
  38.       strcpy(a + j, STR1);
  39.     }
  40.   }
  41.   return strcpy(Result, a);
  42. }
  43.  
  44.  
  45. main(argc, argv)
  46. int argc;
  47. Char *argv[];
  48. {
  49.   Char STR2[256];
  50.  
  51.   PASCAL_MAIN(argc, argv);
  52.   strcpy(a[0], "program self(input, output);");
  53.   strcpy(a[1], "type s = string[255]; n=integer;");
  54.   strcpy(a[2], "var a : array [1..100] of s; i,j : integer;");
  55.   strcpy(a[3],
  56.     "function t(a:integer):integer; begin if a<7 then t:=a else t:=a+11 end; function q(a:s):s;");
  57.   strcpy(a[4],
  58.     " var j:n;begin for j:=strlen(a)downto 1 do if a[j]=#39 then strinsert(#39,a,j);q:=a;end;");
  59.   strcpy(a[5], "begin");
  60.   strcpy(a[17], "   for i := 1 to 11 do begin setstrlen(a[i+6], 0);");
  61.   strcpy(a[18],
  62.     "      strwrite(a[i+6],1,j,'   a[',t(i):1,'] := ''', q(a[t(i)]), ''';');");
  63.   strcpy(a[19], "   end;");
  64.   strcpy(a[20], "   for i := 1 to 22 do writeln(a[i]);");
  65.   strcpy(a[21], "end.");
  66.   for (i = 1; i <= 11; i++) {
  67.     sprintf(a[i + 5], "   a[%ld] := '%s';", t(i), q(STR2, a[t(i) - 1]));
  68.     j = strlen(a[i + 5]) + 1;
  69.   }
  70.   for (i = 1; i <= 22; i++)
  71.     puts(a[i - 1]);
  72.   exit(EXIT_SUCCESS);
  73. }
  74.  
  75.  
  76.  
  77. /* End. */
  78.