home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 379b.lha / p2c_v1.13a / examples / c / self.c < prev   
Encoding:
C/C++ Source or Header  |  1990-06-03  |  1.5 KB  |  73 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. Static Char a[100][256];
  9. Static long i, j;
  10.  
  11.  
  12. Static long t(a)
  13. long a;
  14. {
  15.   if (a < 7)
  16.     return a;
  17.   else
  18.     return (a + 11);
  19. }
  20.  
  21.  
  22. Static Char *q(Result, a_)
  23. Char *Result, *a_;
  24. {
  25.   Char a[256];
  26.   long j;
  27.   Char STR1[256];
  28.  
  29.   strcpy(a, a_);
  30.   for (j = strlen(a) - 1; j >= 0; j--) {
  31.     if (a[j] == '\'') {
  32.       sprintf(STR1, "'%s", a + j);
  33.       strcpy(a + j, STR1);
  34.     }
  35.   }
  36.   return strcpy(Result, a);
  37. }
  38.  
  39.  
  40. main(argc, argv)
  41. int argc;
  42. Char *argv[];
  43. {
  44.   Char STR2[256];
  45.  
  46.   PASCAL_MAIN(argc, argv);
  47.   strcpy(a[0], "program self(input, output);");
  48.   strcpy(a[1], "type s = string[255]; n=integer;");
  49.   strcpy(a[2], "var a : array [1..100] of s; i,j : integer;");
  50.   strcpy(a[3],
  51.     "function t(a:integer):integer; begin if a<7 then t:=a else t:=a+11 end; function q(a:s):s;");
  52.   strcpy(a[4],
  53.     " var j:n;begin for j:=strlen(a)downto 1 do if a[j]=#39 then strinsert(#39,a,j);q:=a;end;");
  54.   strcpy(a[5], "begin");
  55.   strcpy(a[17], "   for i := 1 to 11 do begin setstrlen(a[i+6], 0);");
  56.   strcpy(a[18],
  57.     "      strwrite(a[i+6],1,j,'   a[',t(i):1,'] := ''', q(a[t(i)]), ''';');");
  58.   strcpy(a[19], "   end;");
  59.   strcpy(a[20], "   for i := 1 to 22 do writeln(a[i]);");
  60.   strcpy(a[21], "end.");
  61.   for (i = 1; i <= 11; i++) {
  62.     sprintf(a[i + 5], "   a[%ld] := '%s';", t(i), q(STR2, a[t(i) - 1]));
  63.     j = strlen(a[i + 5]) + 1;
  64.   }
  65.   for (i = 1; i <= 22; i++)
  66.     puts(a[i - 1]);
  67.   exit(0);
  68. }
  69.  
  70.  
  71.  
  72. /* End. */
  73.