home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pascal / tpc14.arc / TPCMAC.H < prev   
C/C++ Source or Header  |  1987-05-20  |  3KB  |  125 lines

  1.  
  2. /*
  3.  * TPCMAC.H - Macro Header for use with Turbo Pascal --> C Translator
  4.  *
  5.  * S.H.Smith, 22-Dec-86 (rev. 18-Apr-87 shs)
  6.  *
  7.  */
  8.  
  9. #include <stdio.h>
  10.  
  11.  
  12. /* define some simple keyword replacements */
  13.  
  14. #define keypressed     kbhit()
  15. #define upcase(c)      toupper(c)
  16. #define length(s)      strlen(s)
  17. #define dispose(v)     free(v)
  18. #define pred(v)        ((v)-1)
  19. #define succ(v)        ((v)+1)
  20. #define sqr(v)         ((v)*(v))
  21. #define chr(n)         (n)
  22. #define ord(c)         (c)
  23. #define false          0
  24. #define true           1
  25. #define NIL            NULL
  26.  
  27. #define delete(dstr,pos,num) strcpy(dstr+pos-1,dstr+pos+num)
  28. #define val(dstr,res,code)   code=0, res=atof(dstr)
  29. #define pos(ch,dstr)         index(ch,dstr)
  30.  
  31. #define THRU           -2
  32. #define ENDSET         -1
  33.  
  34.  
  35. /*
  36.  * support library functions:  (these need to be written)
  37.  *
  38.  *   setof(a,b,...,-1)
  39.  *      construct and return a set of the specified character values
  40.  *
  41.  *   inset(ex,set)
  42.  *      predicate returns true if expression ex is a member of
  43.  *      the set parameter
  44.  *
  45.  */
  46.  
  47. typedef char *string;
  48. #define STRSIZ 255      /* default string length */
  49.  
  50.  
  51. /*
  52.  * copy len bytes from the dynamic string dstr starting at position from
  53.  *
  54.  */
  55. string copy(dstr,from,len)
  56. string dstr;
  57. int  from,len;
  58. {
  59.    static char buf[STRSIZ];
  60.  
  61.    buf[0]=0;
  62.    if (from>strlen(buf))     /* copy past end gives null string */
  63.       return buf;
  64.  
  65.    strcpy(buf,dstr+from-1);  /* skip over first part of string */
  66.    buf[len] = 0;             /* truncate after len characters */
  67.    return buf;
  68. }
  69.  
  70.  
  71. /*
  72.  *  concatenate str1 and str2 and return a pointer to the
  73.  *  static result.   note that str1 or str2 may point to the
  74.  *  concat static buffer.
  75.  */
  76. string concat(s1,s2)
  77. string s1;
  78. string s2;
  79. {
  80.    static char buf[STRSIZ];
  81.    char ts2[STRSIZ];
  82.  
  83.    strcpy(ts2,s2);    /* this is needed because either s1 or s2 could
  84.                          already point to buf! */
  85.    strcpy(buf,s1);
  86.    strcat(buf,ts2);
  87.  
  88.    return buf;
  89. }
  90.  
  91.  
  92. /* macros to process turbo pascal pragmas */
  93.  
  94. #define standard_io(p)        /* ignore */
  95. #define control_c_check(p)    /* ignore */
  96. #define device_check(p)       /* ignore */
  97. #define max_files(p)          /* ignore */
  98. #define input_file_buffer(p)  /* ignore */
  99. #define io_error_check(p)     /* ignore */
  100. #define stack_check(p)        /* ignore */
  101. #define output_file_buffer(p) /* ignore */
  102. #define range_check(p)        /* ignore */
  103. #define user_interrupt(p)     /* ignore */
  104. #define param_type_check(p)   /* ignore */
  105. #define E(p)                  /* ignore */
  106.  
  107.  
  108. /* file access support */
  109.  
  110. char _CURNAME[64];
  111. int  ioresult = 0;
  112.  
  113. typedef FILE *text;
  114.  
  115. #define eof(fd)         feof(fd)
  116. #define EOF(fd)         feof(fd)
  117.  
  118. #define assign(fd,name) strcpy(_CURNAME,name)
  119. #define reset(fd)       ioresult = (( (fd = fopen(_CURNAME,"r")) == 0))
  120. #define rewrite(fd)     ioresult = (( (fd = fopen(_CURNAME,"w")) == 0))
  121.  
  122. #define close(fd)       ioresult = fclose(fd)
  123.  
  124.  
  125.