home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / hackers / 2007 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  3.1 KB

  1. Path: sparky!uunet!UB.com!pacbell.com!sgiblab!spool.mu.edu!agate!doc.ic.ac.uk!warwick!uknet!comlab.ox.ac.uk!imc
  2. From: imc@comlab.ox.ac.uk (Ian Collier)
  3. Newsgroups: alt.hackers
  4. Subject: Re: obHack [polyglots]
  5. Message-ID: <2990.imc@uk.ac.ox.prg>
  6. Date: 28 Jan 93 15:58:21 GMT
  7. References: <1jks8bINNsj4@matt.ksu.ksu.edu> <C182ow.BAv@deshaw.com> <1js1teINNhq4@matt.ksu.ksu.edu>
  8. Organization: Oxford University Computing Laboratory
  9. Lines: 67
  10. Approved: or else it wouldn't get posted.
  11. X-Local-Date: Thursday, 28th January 1993 at 3:58pm GMT
  12. Originator: imc@msc7.comlab
  13.  
  14. In article <1js1teINNhq4@matt.ksu.ksu.edu>, holland@matt.ksu.ksu.edu (Rich Holland) wrote:
  15. >I hacked together a quick fortran/c example to demonstrate it, but POLYGLOT
  16. >*really* does a good job of confusing people.  :-)
  17.  
  18. >char a; /*
  19. >C$NOEXT
  20. >       PROGRAM hello
  21. >       WRITE (*,*) 'This is a fortran/c program!'
  22. >       END
  23. >C*/  main ()   /*
  24. >C*/  {        /*
  25. >C*/    printf("This is a fortran/c program!\n");  /*
  26. >C*/  }
  27.  
  28. At least it's possible with this program to understand exactly how it
  29. works... :-)   One problem with POLYGLOT is that I don't know by heart the
  30. commenting conventions of *all* the languages mentioned (perhaps I'm not a
  31. real programmer then, even if I can program a Z80 in hex. But I digress...)
  32. Another is that there is so much junk at the start of each line that it's
  33. hard to keep track of everything.
  34.  
  35. ObHack: Someone asked for macros? :-)
  36.  
  37. Pretty standard, but written in a terse manner...
  38.  
  39. #define set(x,b) (x[(b)/8]|=1<<(7-(b)%8))
  40. #define clr(x,b) (x[(b)/8]&=~(1<<(7-(b)%8)))
  41. #define let(x,b,v) (v?set(x,(b)):clr(x,(b)))
  42. #define tst(x,b) ((x[(b)/8]&(1<<(7-(b)%8)))!=0)
  43.  
  44. From an earlier (and easier to understand :-) ) version of my 1992 IOCCC
  45. entry:
  46.  
  47. #define q sscanf
  48. #define rf exit(1)
  49. #define sx(xs,f) q(++s,xs,&f)!=1&&c>++l&&q(v[l],xs,&f)!=1&&--l
  50. #define qh(j,i,f,g) t=0,*++s&&(t=q(s,j,&f,&g)),(!t&&c>++l&&\
  51.         !(t=q(v[l],j,&f,&g)))?--l:(t<2&&c>++l&&!(t=q(v[l],i,&g))&&--l
  52. #define i2 (qh("%d,%d","%d",xs,ys),(xs&&ys)||(fputs(m2,stderr),rf)))
  53. #define d1 (sx("%lg",f))
  54. #define i1(f) (sx("%d",f),f||(fputs(m2,stderr),rf))
  55. #define d2(f,g) (qh("%lg,%lg","%lg",f,g)))
  56.  
  57. result: if v is the argument array (i.e. argv), c is the argument count
  58. (i.e. argc), l is the current argument number, and s points to the character
  59. after an argument flag in v[l] (e.g. 4 in -m4,5); and t is a spare int
  60. variable, then
  61.  
  62. i2      gets two integers into xs and ys respectively, printing error message
  63.         m2 if either is zero
  64. i1(x)   gets an integer into x, printing error message m2 if it is zero
  65. d1      gets a double into f
  66. d2(f,g) gets two doubles into f and g respectively.
  67.  
  68. Afterwards, l is the number of the last used argument string.
  69.  
  70. The complexity of the macros makes sure that the arguments get picked up if
  71. they are written in any of the following forms:
  72.  
  73. -x1,2   -x1 2   -x 1 2    -x 1,2    -xylophone 1,2     -xylophone 1 2
  74. -y1             -y 1                -yes 1
  75.  
  76. It is OK to omit any of the numeric arguments; they just get left at their
  77. default (i.e. original) values.
  78.  
  79. Ian Collier
  80. Ian.Collier@prg.ox.ac.uk | imc@ecs.ox.ac.uk
  81.