< {GT:}    ! Let 'indent' take care of this ...
<          !outsym(' ') %while opline_length-opline_lastnl <78
---
>          outsym(' ') %while opline_length-opline_lastnl <78
946d897
< {GT:} ! Should also check for std library names???
948c899
< %constinteger nr=34+1
---
> %constinteger nr=34
955,956c906
<                                     "fabs","volatile","asm","const","signed",
<                     { AND NOW LIBS }"exit"
---
>                                     "fabs","volatile","asm","const","signed";
1086,1099d1035
< %routine outhex(%integer value)
< %CONSTSTRING(1)%ARRAY HEX(0:15)="0","1","2","3","4",
<                "5","6","7","8","9","A","B","C","D","E","F"
< %INTEGER I,digit
< %STRING(8)RES
<       RES=""
<       %FOR I=8<<2-4,-4,0 %CYCLE
<          digit=VALUE>>I&15
<           %if res#"" %or digit#0 %then RES=RES.HEX(digit)
<       %REPEAT
<       %if res="" %then res="0"
<       outstring("0x".res)
< %end
< 
1122d1057
< {GT:DEBUG} outstring("/*");outhex(type);outstring("*/")
1153c1088,1100
< {GT: outhex moved higher up}
---
> %routine outhex(%integer value)
> %CONSTSTRING(1)%ARRAY HEX(0:15)="0","1","2","3","4",
>                "5","6","7","8","9","A","B","C","D","E","F"
> %INTEGER I,digit
> %STRING(8)RES
>       RES=""
>       %FOR I=8<<2-4,-4,0 %CYCLE
>          digit=VALUE>>I&15
>           %if res#"" %or digit#0 %then RES=RES.HEX(digit)
>       %REPEAT
>       %if res="" %then res="0"
>       outstring("0x".res)
> %end
1562c1509
< {GT:}       outstring("exit(0);"{"imp_stop();"}); outsym(NL)
---
>          outstring("imp_stop();"); outsym(NL)
1630,1632d1576
< {GT:} ! BUG !!!  %externalroutinespec fred(%int i)
< !       translates to void fred(void)
< 
1785,1790c1729,1730
<                                ! '%ON'(EVENT')(N)(NLIST)'%start'
< {GT:}    outstring("/* ***untranslateable IMP construct*** */"); outsym(NL)
< ! Shouldn't we compile a CSTART(..., 3) here?
< ! and in cstart, do...  %if code=3 %then outstring("#endif /* On event */") %and outsym(NL)
< ! so ... where is the %FINISH handled if not there???
< 
---
>                                          ! '%ON'(EVENT')(N)(NLIST)'%start'
>          outstring("***untranslateable IMP construct***")
1792,1804d1731
< ! Compare ...
< 
< !SW(3):                         ! (%iu)(COND)%then(UI)(ELSE')
< !         MARKIU = P+1; MARKC = MARKIU+3
< !         MARKR = P+2+A(P+2)<<8+A(P+3);   ! ! FROMAR2(P+2)
< !         MARKE = 0
< !         %if A(MARKR)=3 %then %start
< !            MARKE = MARKR+1+FROMAR2(MARKR+1)
< !            MARKUI = MARKR+3
< !         %finish
< !         CIFTHEN(MARKIU,MARKC,MARKUI,MARKE,MARKR,NO)
< !         ->CSSEXIT
< 
1845,1847c1772,1773
< {GT:}             outstring("int "); outswadname(k); outstring("_value;")
< {GT:}             outstring("int "); outswadname(k); outstring("_line;")
< {GT:}             outstring("char *"); outswadname(k); outstring("_file;")
---
>                   outstring("int "); outswadname(k)
>                   outstring("_value;")
3346,3348d3271
< {GT:}  ! NOTE goto t_despatch ... should pass in __LINE__ and __FILE__
<        ! rather than allow them to be picked up at point of dispatch
<        ! by which time they are meaningless
3365,3383c3288
< {GT:}   ! NOTE: using __LINE__ and __FILE__ from the dispatch table
<         ! is not very helpful.  We really want to know where the switch
<         ! was jumped to from, at the source of the original ->sw(i)
<         ! so I now note the originals into name_file and name_line
<         ! at the point of the jump.  I think it's worth the overhead
<         ! of the two extra assignments.
< 
<         ! NOTE ALSO: I assume the body of BADSWITCH is 
<         ! dumped at a %endofprogram - would be better not to,
<         ! and to supply it in "imptoc.h" instead
<         ! because of problems described elsewhere to
<         ! do with limitations of this traslator
<         ! (though I haven't yet found where it's dumped so I may be wrong)
< 
<                 outstring("BADSWITCH("); outswadname(jj);
< {GT:}!          outstring("_value,__LINE__,__FILE__);")
<                 outstring("_value,")
<                 outswadname(jj); outstring("_line,")
<                 outswadname(jj);outstring("_file);")
---
>                 outstring("BADSWITCH("); outswadname(jj); outstring("_value,__LINE__,__FILE__);")
3718,3720d3622
< {GT: Unfixed bug.  Type parameter i 0 in an externalspec }
< {    and shows up as  extern void itos(void, void)       }
< {    instead of       extern void itos(int, int)         } 
4024c3926
< {GT:}    %if opline_l(opline_length-1) # '{' %then outstring("; ")
---
>          outstring("; ")
4047,4051d3948
< {GT:}  ! NOTE goto t_despatch ... should pass in __LINE__ and __FILE__
<        ! rather than allow them to be picked up at point of dispatch
<        ! by which time they are meaningless
< {GT:}    outstring("; "); outswadname(lname); outstring("_line = __LINE__")
< {GT:}    outstring("; "); outswadname(lname); outstring("_file = __FILE__")
4114,4118d4010
< ! Woud be nice to intercept this at the level above and translate
< ! %if <cond> %then %monitor
< ! to
< ! assert(!(cond))
< {GT:} outstring("assert(_IMP_MONITOR_)")
4121c4013
< {GT:} outstring("exit(0)"{"imp_stop()"})
---
>       outstring("imp_stop()")
4304d4195
< {GT:}%if CODE=3 %then outstring("/* beginning of onevent block */") %and outsym(NL)
4314d4204
< {GT:}%if CODE=3 %then outstring("/* end of onevent block */") %and outsym(NL)
4319d4208
< 
4388a4278
>       outstring("do ")
4390d4279
<          outstring("do ")
4397d4285
<          outstring("for (;;) ")
4399c4287
<          !outstring(" while (1) /* FOR EVER */")
---
>          outstring(" while (1) /* FOR EVER */")
4705,4709c4593
< {GT:}             outsym('''');
<                   %if opnd_d = '\' %or opnd_d = '''' %c
<                    %then outsym('\');
<                   outsym(opnd_d);
<                   outsym('''')
---
>                   outsym(''''); outsym(opnd_d); outsym('''')
5409,5430c5293
< 
< {GT:} ! Would be nice to apply de-morgan's law below and invert the actual
<       ! conditional tests, eg
<       !        a=1 %and b>fred
<       ! ->     a#1 %or b<=fred
<       ! 
<       ! Since Imp80 has no %predicates, we don't need to re-insert any "!"s
<       ! at a lower level, except for conditional string resolution, i.e.
<       !       a->a.("->").b
<       ! ->    (%not a->a.("->").b)
<       ! 
<       ! If we add this as a general mechanism, then when translating to
<       ! C we can clean up 'unless' and 'repeat until' statements, which map
<       ! to C's if and while statements.
<       !
<       ! Also it would be useful in my %if <cond> %then %monitor
<       ! extension, which maps to assert(!(<cond>))
<       !
<       ! NOTE: ** it would appear SKIP SC(1) and SKIP COND()
<       ! do exactly what I want here!
<       !
< !           %if iu=2 %then outstring("(!")
---
>             %if iu=2 %then outstring("(!")
5432,5438c5295,5297
<             %if iu=2 %then %start
<               SKIP SC(1);                  ! SKIP THE 1ST CMPARSN
<               SKIP COND(1);                ! AND ANY %and/%or CLAUSES
<             %else
<               SKIP SC(0);                  ! SKIP THE 1ST CMPARSN
<               SKIP COND(0);                ! AND ANY %and/%or CLAUSES
<             %finish
---
>             SKIP SC(0);                  ! SKIP THE 1ST CMPARSN
>             SKIP COND(0);                ! AND ANY %and/%or CLAUSES
>            %if iu=2 %then outsym(')')
5440d5298
< !           %if iu=2 %then outsym(')')
5447,5454d5304
< 
< !
< ! In Imp to C translator we do NOT generate jumps so the logic
< ! for REVERSED which changes the jump destinations does not
< ! do anything.  Instead we must explicity apply de-morgan's
< ! law to the operands and operators.  I am in the process
< ! of adding that code now.  SKIP COND is done already
< 
5458,5462d5307
< 
< %conststring(6) %array REVCMP(0:10)=" ??? ","!=","<","<=",
<                        "==",">",">=","==","!?->??",
<                        "!=","=="
< 
5490,5495c5335,5336
<            %if REVERSED=1 %then %start
<              outstring(")!=0"); ! De-Morgan's law
<            %else
<              outstring(")==0")
<            %finish
<            %if c1_cmp2#0 %then outstring("untranslateable cond")
---
>            outstring(")==0")
>             %if c1_cmp2#0 %then outstring("untranslateable cond")
5503,5507c5344
<             %if REVERSED=1 %then %start
<               outstring(REVcmp(c1_cmp1)); ! de-morgan's law
<             %else
<               outstring(cmp(c1_cmp1))
<             %finish
---
>             outstring(cmp(c1_cmp1))
5510,5514c5347
<                %if REVERSED=1 %then %start
<                   outstring(") || ("); ! De-Morgan's Law
<                %else
<                   outstring(") && (")
<                %finish
---
>                outstring(") && (")
5529,5533c5362
<          %if REVERSED=1 %then %start
<             outstring(REVcmp(c1_cmp1)); ! DeMorgan's law
<          %else
<             outstring(cmp(c1_cmp1))
<          %finish
---
>          outstring(cmp(c1_cmp1))
5540,5544c5369
<             %if REVERSED=1 %then %start
<                outstring(") || (")
<             %else
<                outstring(") && (")
<             %finish
---
>             outstring(") && (")
5548,5552c5373
<             %if REVERSED=1 %then %start
<                outstring(REVcmp(c1_cmp1)); ! DeMorgan's law
<             %else
<                outstring(cmp(c1_cmp2))
<             %finish
---
>             outstring(cmp(c1_cmp2))
5573,5575c5394
< {GT:}!outstring("!(")
<      ! now that SKIP SC and SKIP COND reverse properly,
<      ! we do not need to negate here as well...
---
>       outstring("!(")
5577c5396
<      !outsym(')')
---
>       outsym(')')
5580d5398
<       %if REVERSED=1 %then outstring("/* what is a pseudo-boolean? - is the conditio accidentally inverted? */");
5594,5603c5412
< {GT: experimenting with reversing}
< 
<                      %if REVERSED=1 %then %start
<                        ! Apply de-morgan to operators
<                        %if alt=1 %then outstring(" || ") %else outstring(" && ")
<                      %else
<                        %if alt=1 %then outstring(" && ") %else outstring(" || ")
<                      %finish
< 
< 
---
>                      %if alt=1 %then outstring(" && ") %else outstring(" || ")
5746,5817d5554
< 
< %const %string(80) %array SMDETAILS(0:NO OF SNS) = %c
<   /* 0 */ "%routine SELECT INPUT(%integer STREAM)",
<   /* 1 */ "%routine SELECT OUTPUT(%integer STREAM)",
<   /* 2 */ "%routine NEWLINE",
<   /* 3= */ "%routine SPACE",
<   /* 4= */ "%routine SKIP SYMBOL",
<   /* 5= */ "%routine READ STRING(%stringname S)",
<   /* 6 */ "%routine NEWLINES(%integer N)",
<   /* 7 */ "%routine SPACES(%integer N)",
<   /* 8 */ "%integerfn NEXT SYMBOL",
<   /* 9= */ "%routine PRINT SYMBOL(%integer SYMBOL)",
<   /* 10 */ "%routine READ SYMBOL(%name SYMBOL)",
<   /* 11 */ "%routine READ(%name NUMBER)",
<   /* 12 */ "%routine WRITE(%integer VALUE,PLACES)",
<   /* 13 */ "%routine NEWPAGE",
<   /* 14= */ "%integerfn ADDR(%name VARIABLE)",
<   /* 15 */ "%longrealfn ARCSIN(%longreal X)",
<   /* 16 */ "%integerfn INT(%longreal X)",
<   /* 17 */ "%integerfn INTPT(%lonrgreal X)",
<   /* 18 */ "%longrealfn FRACPT(%longreal X)",
<   /* 19 */ "%routine PRINT(%longreal NUMBER,%integer BEFORE,AFTER)",
<   /* 20 */ "%routine PRINTFL(%longreal NUMBER,%integer PLACES)",
<   /* 21 */ "%realmap REAL(%integer VAR ADDR)",
<   /* 22 */ "%integermap INTEGER(%integer VAR ADDR)",
<   /* 23 */ "%longrealfn MOD(%longreal X)",
<   /* 24 */ "%longrealfn ARCCOS(%longreal X)",
<   /* 25 */ "%longrealfn SQRT(%longreal X)",
<   /* 26 */ "%longrealfn LOG(%longreal X)",
<   /* 27 */ "%longrealfn SIN(%longreal X)",
<   /* 28 */ "%longrealfn COS(%longreal X)",
<   /* 29 */ "%longrealfn TAN(%longreal X)",
<   /* 30 */ "%longrealfn EXP(%longreal X)",
<   /* 31 */ "%routine CLOSE STREAM(%integer STREAM)",
<   /* 32 */ "%byteintegermap BYTE INTEGER(%integer VAR ADDR)",
<   /* 33 */ "%integerfn EVENTINF",
<   /* 34= */ "%longrealfn RADIUS(%longreal X,Y)",
<   /* 35 */ "%longrealfn ARCTAN(%longreal X,Y)",
<   /* 36 */ "%byteintegermap LENGTH(%stringname  S)",
<   /* 37 */ "%routine PRINT STRING(%string(255)",
<   /* 38 */ "%integerfn NL",
<   /* 39= */ "%longrealmap LONG REAL(%integer VAR ADDR)",
<   /* 40 */ "%routine PRINT CH(%integer CHARACTER)",
<   /* 41 */ "%routine READ CH(%name CHARACTER)",
<   /* 42 */ "%stringmap STRING(%integer VAR ADDR)",
<   /* 43 */ "%routine READ ITEM(%stringname ITEM)",
<   /* 44 */ "%string(1)",
<   /* 45 */ "%byteintegermap CHARNO(%stringname STR,%integer CHARREQD)",
<   /* 46 */ "%string(1)",
<   /* 47 */ "%string(255)",
<   /* 48 */ "%recordmap RECORD(%integer REC ADDR)",
<   /* 49 */ "%arraymap ARRAY(%integer A1ADDR,%arrayname FORMAT)",
<   /* 50 */ "%integerfn SIZEOF(%name X)",
<   /* 51 */ "%integerfn IMOD(%integer VALUE)",
<   /* 52 */ "%longrealfn PI",
<   /* 53= */ "%integerfn EVENTLINE",
<   /* 54= */ "%longintegermap LONGINTEGER(%integer ADR)",
<   /* 55 */ "%longlongrealmap LONGLONGREAL(%integer ADR)",
<   /* 56 */ "%longintgerefn LENGTHENI(%integer VAL)",
<   /* 57 */ "%longlongrealfn LENGTHENR(%longreal VAL)",
<   /* 58 */ "%integerfn SHORTENI(%longinteger VAL)",
<   /* 59 */ "%longrealfn SHORTENR(%longlongreal VAL)",
<   /* 60 */ "%integerfn NEXTCH",
<   /* 61= */ "%halfintegermap HALFINTEGER(%integer ADDR)",
<   /* 62 */ "%routine PPROFILE",
<   /* 63= */ "%longrealfn FLOAT(%integer VALUE)",
<   /* 64 */ "%longintegerfn LINT(%longlongreal X)",
<   /* 65 */ "%longintegerfn LINTPT(%longlongreal X)",
<   /* 66 */ "%shortintegermap SHORTINTEGER(%integer N)",
<   /* 67 */ "%integerfn TRUNC(%longreal X)"
< 
< 
5972c5709
< {GT:}    outstring("fprintf(out_file, "); outsym('"')
---
>          outstring("printf("); outsym('"')
5981c5718
<          outstring("; _imptempint++) fprintf(out_file, "); outsym('"')
---
>          outstring("; _imptempint++) printf("); outsym('"')
5989,5994c5726
<       %if parm_arr=0 %then %start
<         outstring("_imp_printstring(")
<       %finishelsestart
< {GT:}   outstring("fprintf(out_file, "); outsym('"'); outstring("%s")
<         outsym('"'); outstring(", ")
<       %finish
---
>       %if parm_arr=0 %then outstring("_imp_printstring(") %else outstring("printf(")
6003,6005c5735
< {GT:}    outstring("fprintf(out_file, "); outsym('"'); outstring("%s")
<          outsym('"'); outstring(", "); outsym('"'); outsym('\')
<          outsym('n'); outsym('"');outsym(')')
---
>          outstring("printf(");outsym('"'); outstring("\n"); outsym('"'); outsym(')')
6012,6014c5742
< {GT:}    outstring("fprintf(out_file, "); outsym('"'); outstring("%s")
<          outsym('"'); outstring(", "); outsym('"'); outsym(' ')
<          outsym('"'); outsym(')')
---
>          outstring("printf("); outsym('"'); outsym(' '); outsym('"'); outsym(')')
6036d5763
< {GT: Needs special handling for charno(s,0); also for LHS = ..}
6045d5771
< {GT: Also needs special treatment on LHS }
6060,6064c5786
< {GT:}    outstring("fprintf(out_file, ");
<          outsym('"')
<          outstring("%c")
<          outsym('"');
<          outstring(", ");
---
>          outstring("printf("); outsym('"'); outstring("%c"); outsym('"'); outsym(',')
6080c5802
<          outstring("fprintf(out_file, "); outsym('"'); outstring("%")
---
>          outstring("printf("); outsym('"'); outstring("%")
6083c5805
<          outstring("fprintf(out_file, "); outsym('"'); outstring(" %d"); outsym('"'); outstring(",")
---
>          outstring("printf("); outsym('"'); outstring(" %d"); outsym('"'); outstring(",")
6096c5818
<          outstring("fprintf(out_file, "); outsym('"'); outstring(" %f"); outsym('"'); outstring(",")
---
>          outstring("printf("); outsym('"'); outstring(" %f"); outsym('"'); outstring(",")
6108c5830
<          outstring("fprintf(out_file, "); outsym('"'); outstring(" %e"); outsym('"'); outstring(",")
---
>          outstring("printf("); outsym('"'); outstring(" %e"); outsym('"'); outstring(",")
6114,6127d5835
< 
< ADHOC(0):                               ! SELECT INPUT
<       %if parm_arr=0 %start
<          outstring("_imp_selectinput(")
<          p=p+1; csexp(x'51'); outsym(')')
<          p=p+1; ->OKEXIT
<       %finish
<       ! if C i-o we can not handle this so fall thru
< {GT:} 
<       outstring("selectinput(")
<       p=p+1; csexp(x'51'); outstring(")")
<       p=p+1;
<       ->OKEXIT
< 
6135,6140d5842
< {GT:} 
<       outstring("selectoutput(")
<       p=p+1; csexp(x'51'); outstring(")")
<       p=p+1;
<       ->OKEXIT
< 
6143,6146c5845,5846
< {GT:} outstring("/* Call to ");
<       outstring(SMDETAILS(snno));
<       outstring (" - please modify pass2.i to handle it */")
<       skip app; p=p-1; -> OKEXIT
---
>       outstring("/* ****call on untranslateable imp support routine**** */")
>      skip app; p=p-1; -> OKEXIT
6173,6181d5872
< 
< {GT:}
< ADHOC(10):                                ! READ SYMBOL
< ADHOC(41):                                ! READ CH
<       P = P+6;
<       CNAME(1);
<       outstring(" = fgetc(in_file)")
<       P = P+2; ->OKEXIT
< 
