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

  1. /* "p2c", a Pascal to C translator.
  2.    Copyright (C) 1989, 1990, 1991 Free Software Foundation.
  3.    Author's address: daveg@csvax.caltech.edu; 256-80 Caltech/Pasadena CA 91125.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation (any version).
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; see the file COPYING.  If not, write to
  16. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  17.  
  18.  
  19.  
  20. #define PROTO_HPMODS_C
  21. #include "trans.h"
  22.  
  23.  
  24.  
  25.  
  26.  
  27. /* FS functions */
  28.  
  29.  
  30. Static Stmt *proc_freadbytes()
  31. {
  32.     Expr *ex, *ex2, *vex, *fex;
  33.     Type *type;
  34.  
  35.     if (!skipopenparen())
  36.     return NULL;
  37.     fex = p_expr(tp_text);
  38.     if (!skipcomma())
  39.     return NULL;
  40.     vex = p_expr(NULL);
  41.     if (!skipcomma())
  42.     return NULL;
  43.     ex2 = p_expr(tp_integer);
  44.     skipcloseparen();
  45.     type = vex->val.type;
  46.     ex = makeexpr_bicall_4("fread", tp_integer,
  47.                            makeexpr_addr(vex),
  48.                            convert_size(type, ex2, "FREADBYTES"),
  49.                            makeexpr_long(1),
  50.                            filebasename(copyexpr(fex)));
  51.     if (checkeof(fex)) {
  52.         ex = makeexpr_bicall_2(name_SETIO, tp_void,
  53.                                makeexpr_rel(EK_EQ, ex, makeexpr_long(1)),
  54.                                makeexpr_long(30));
  55.     }
  56.     return wrapopencheck(makestmt_call(ex), fex);
  57. }
  58.  
  59.  
  60.  
  61.  
  62. Static Stmt *proc_fwritebytes()
  63. {
  64.     Expr *ex, *ex2, *vex, *fex;
  65.     Type *type;
  66.  
  67.     if (!skipopenparen())
  68.     return NULL;
  69.     fex = p_expr(tp_text);
  70.     if (!skipcomma())
  71.     return NULL;
  72.     vex = p_expr(NULL);
  73.     if (!skipcomma())
  74.     return NULL;
  75.     ex2 = p_expr(tp_integer);
  76.     skipcloseparen();
  77.     type = vex->val.type;
  78.     ex = makeexpr_bicall_4("fwrite", tp_integer,
  79.                            makeexpr_addr(vex),
  80.                            convert_size(type, ex2, "FWRITEBYTES"),
  81.                            makeexpr_long(1),
  82.                            filebasename(copyexpr(fex)));
  83.     if (checkfilewrite) {
  84.         ex = makeexpr_bicall_2(name_SETIO, tp_void,
  85.                                makeexpr_rel(EK_EQ, ex, makeexpr_long(1)),
  86.                                makeexpr_long(3));
  87.     }
  88.     return wrapopencheck(makestmt_call(ex), fex);
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. /* SYSGLOBALS */
  101.  
  102.  
  103. Static void setup_sysglobals()
  104. {
  105.     Symbol *sym;
  106.  
  107.     sym = findsymbol("SYSESCAPECODE");
  108.     if (sym->mbase)
  109.         strchange(&sym->mbase->name, name_ESCAPECODE);
  110.     sym = findsymbol("SYSIORESULT");
  111.     if (sym->mbase)
  112.         strchange(&sym->mbase->name, name_IORESULT);
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. void hpmods(name, defn)
  123. char *name;
  124. int defn;
  125. {
  126.     if (!strcmp(name, "FS")) {
  127.         makespecialproc("freadbytes", proc_freadbytes);
  128.         makespecialproc("fwritebytes", proc_fwritebytes);
  129.     } else if (!strcmp(name, "SYSGLOBALS")) {
  130.         setup_sysglobals();
  131.     }
  132. }
  133.  
  134.  
  135.  
  136.  
  137. /* End. */
  138.  
  139.  
  140.  
  141.