/*
   This program may be freely
  distributed , copied,and modified so long
as a fee is not charged. However,
I reserve all rights available to
me under The Copyright Act.
If you find any bugs please feel free to contact me.
  David DeGeorge
  Princeton,New Jersey
  March 1987

USENET:  ....princeton!idacrd!dld
COMPUSERVE: 74176,3210
GENIE: DEGEORGE
*/

/*
  This file contains most of
  the text output routines 
  for makersh
*/  

#include  "makersh.h"

printobj(p)
OBJECT *p;
 
{       union ptr { BITBLK *qb;
		    ICONBLK *qi;
		} q;
	int j;
	switch( p->ob_type & 0xFF){  /* mask off the low order byte
					so we are not misled by
					the extended types feature
				      */
	case G_STRING:
        case G_BUTTON:
        case G_TITLE:
	             p->ob_spec = findstr(p ->ob_spec);
	             break;
	case G_BOXTEXT:
	case G_FTEXT:
	case G_FBOXTEXT:
	case G_TEXT:
	     p->ob_spec=(p->ob_spec-(long)rheader.rsh_tedinfo)/sizeof(TEDINFO);
	           break;
	case G_IMAGE:
	    	q.qb = (BITBLK *)( head +(int)(p->ob_spec));
	     p->ob_width = q.qb->bi_wb;
	     p->ob_height = (q.qb -> bi_hl )/8 ;
	     p->ob_spec=(p->ob_spec-(long)rheader.rsh_bitblk)/sizeof(BITBLK);
	          break;
	case G_ICON:
	       q.qi = (ICONBLK *)(head + (int)( p->ob_spec));
	       p->ob_width = q.qi ->ib_wicon/8 ;
	       p -> ob_height = q.qi -> ib_hicon/8 ;
	  p->ob_spec=(p->ob_spec-(long)rheader.rsh_iconblk)/sizeof(ICONBLK);
	         break; 	
	 default:
	         break;
	        } 
	              	
	fprintf(out,"%d,",p->ob_next);
	fprintf(out,"%d,",p->ob_head);
	fprintf(out,"%d,",p->ob_tail);
	if ( p -> ob_type <= 32 )
	       fprintf(out,"%s,",types[ p->ob_type -20]);
	 else
        	fprintf(out,"0x%x,",p -> ob_type);
	fprintf(out,"0x%x,",p->ob_flags);
	fprintf(out,"0x%x,",p->ob_state);
	fprintf(out,"%DL,",p->ob_spec);
	fprintf(out,"0x%x,",p->ob_x);
	fprintf(out,"0x%x,",p->ob_y);	
	fprintf(out,"0x%x,",p->ob_width);
	fprintf(out,"0x%x",p->ob_height);
}

printbit(p)
BITBLK *p;
{
	fprintf(out,"%DL,",p->bi_pdata);
	fprintf(out,"%d,",p->bi_wb);
	fprintf(out,"%d,",p->bi_hl);
	fprintf(out,"0x%x,",p->bi_x);
        fprintf(out,"0x%x,",p->bi_y);
        fprintf(out,"0x%x",p->bi_color);
}


printicon(p)
ICONBLK *p;
{
	fprintf(out,"%DL,",p->ib_pmask);
	fprintf(out,"%DL,",p->ib_pdata);
	fprintf(out,"%DL,",p->ib_ptext);	
	fprintf(out,"%d,",p->ib_char);
	fprintf(out,"%d,",p->ib_xchar);
	fprintf(out,"%d,",p->ib_ychar);
        fprintf(out,"%d,",p->ib_xicon);
        fprintf(out,"%d,",p-> ib_yicon);
	fprintf(out,"%d,",p->ib_wicon);
	fprintf(out,"%d,",p->ib_hicon);
	fprintf(out,"%d,",p->ib_xtext);
        fprintf(out,"%d,",p->ib_ytext);
        fprintf(out,"%d,",p->ib_wtext);        
        fprintf(out,"%d,",p->ib_htext);                
        fprintf(out,"%d",0);
        
}
 
  

printted(p)
TEDINFO *p;
{
	p->te_ptext = findstr(p->te_ptext);
	p->te_ptmplt = findstr(p->te_ptmplt);
	p->te_pvalid = findstr(p->te_pvalid);		
	fprintf(out,"%DL,",p->te_ptext);
	fprintf(out,"%DL,",p->te_ptmplt);
	fprintf(out,"%DL,",p->te_pvalid);
	fprintf(out,"%d,",p->te_font);
	fprintf(out,"%d,",p->te_junk1);
	fprintf(out,"%d,",p->te_just);
	fprintf(out,"%d,",p->te_color);
	fprintf(out,"%d,",p->te_junk2);
	fprintf(out,"%d,",p->te_thickness);
	fprintf(out,"%d,",p->te_txtlen);
	fprintf(out,"%d",p->te_tmplen);
}

error(s,type)
char *s;
ERROR type;
{
	char mesag[80];
	int but;
	  switch(type){
	  	
	          case WARN:
#ifdef GEM	          
	                    sprintf(mesag,"[2][%s][continue|abort]",s);
	                    but=form_alert(1,mesag);
	                    if (but == 2 )leave();
#else
	        fprintf(stderr,"%s\nPress return to continue q to exit ",s);
	        	 if ( getchar() == 'q') exit(1);
#endif	        	 
      	  	          return;
	          case NOMEM:
#ifdef GEM	          
	          	   sprintf(mesag,"[3][Can't allocate mem|for %s][abort]",s);
			   form_alert(1,mesag);
			   leave();
#else
			   fprintf(stderr,"Can't allocate memory for %s\n",s);
			   exit(1);
#endif			   
	          case FATAL:
#ifdef GEM	          
	          	  sprintf(mesag,"[3][%s][abort]",s);
	          	  form_alert(1,mesag);
			  leave();
#else
		    fprintf(stderr,"%s.Aborting....\n",s);
		    exit(1);
#endif
#ifndef GEM
		  case USAGE:
		      fprintf(stderr,"Usage: RSC-file RSH-file\n");
                     exit(1);		      		    
#endif	           
	           default:
#ifdef GEM	           
			 sprintf(mesag,"[2][Unknown error][continue|abort]",s);
			 if(but == 2)leave();
			 return;
#else
                  fprintf(stderr,"Unknown error.Aborting...\n");
		        exit(1);
#endif		        
			}	
}

long
makeimage(p,size)
long p ;
int size;       /* size is in words */
									
{       int new ;
        int temp;
        int *mymy;
        int i,j;
        if ( size == 0 )return;
#ifdef GEM        
        imgprog(nimages + 1);
#endif        
	curimage += 1;
	nimages++;
	mymy = ( int *)( head + (int) p);
	fprintf(out,"\nint IMAG%d[]={\n",curimage);
          for(i=0; i < size-1 ; i++){
          fprintf(out,"0x%x,",mymy[i]);
          if( i % 4 == 0)fprintf(out,"\n");
        }
        fprintf(out,"0x%x",mymy[size-1]);
        fprintf(out,"\n};");
        return((long)curimage);
}

