예제 #1
0
bool ami_add_to_clipboard(const char *text, size_t length, bool space)
{
	char *buffer;

	if(option_utf8_clipboard || ami_utf8_clipboard)
	{
		WriteChunkBytes(iffh,text,length);
	}
	else
	{
		buffer = ami_utf8_easy(text);

		if(buffer)
		{
			char *p;

			p = buffer;

			while(*p != '\0')
			{
				if(*p == 0xa0) *p = 0x20;
				p++;
			}
			WriteChunkBytes(iffh, buffer, strlen(buffer));

			ami_utf8_free(buffer);
		}
	}

	if(space) WriteChunkBytes(iffh," ",1);

	return true;
}
예제 #2
0
파일: clipboard.c 프로젝트: ysei/NetSurf
static void gui_set_clipboard(const char *buffer, size_t length,
	nsclipboard_styles styles[], int n_styles)
{
	char *text;
	struct CSet cset = {0};

	if(buffer == NULL) return;

	if(!(OpenIFF(iffh, IFFF_WRITE)))
	{
		if(!(PushChunk(iffh, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN)))
		{
			if(nsoption_bool(clipboard_write_utf8))
			{
				if(!(PushChunk(iffh, 0, ID_CSET, 32)))
				{
					cset.CodeSet = 106; // UTF-8
					WriteChunkBytes(iffh, &cset, 32);
					PopChunk(iffh);
				}
			}
		}
		else
		{
			PopChunk(iffh);
		}

		if(!(PushChunk(iffh, 0, ID_CHRS, IFFSIZE_UNKNOWN))) {
			if(nsoption_bool(clipboard_write_utf8)) {
				WriteChunkBytes(iffh, buffer, length);
			} else {
				if(utf8_to_local_encoding(buffer, length, &text) == NSERROR_OK) {
					char *p;

					p = text;

					while(*p != '\0') {
						if(*p == 0xa0) *p = 0x20;
						p++;
					}
					WriteChunkBytes(iffh, text, strlen(text));
					ami_utf8_free(text);
				}
			}

			PopChunk(iffh);
		} else {
			PopChunk(iffh);
		}

		if(!(PushChunk(iffh, 0, ID_UTF8, IFFSIZE_UNKNOWN))) {
			WriteChunkBytes(iffh, buffer, length);
			PopChunk(iffh);
		} else {
			PopChunk(iffh);
		}
		CloseIFF(iffh);
	}
}
예제 #3
0
void ClipLine(struct line_node *line, struct InstData *data)
{
  UWORD *styles = line->line.Styles;
  UWORD *colors = line->line.Colors;
  LONG error;

  ENTER();

  D(DBF_CLIPBOARD, "ClipLine()");

  ClipInfo(line, data);

  if(colors)
  {
    D(DBF_CLIPBOARD, "writing COLS");
    error = PushChunk(data->iff, 0, ID_COLS, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);

    while(*colors != 0xffff)
    {
      colors += 2;
    }

    error = WriteChunkBytes(data->iff, line->line.Colors, colors - line->line.Colors);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  if(styles)
  {
    D(DBF_CLIPBOARD, "writing STYL");
    error = PushChunk(data->iff, 0, ID_STYL, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);

    while(*styles != EOS)
    {
      styles += 2;
    }

    error = WriteChunkBytes(data->iff, line->line.Styles, styles - line->line.Styles);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  D(DBF_CLIPBOARD, "writing CHRS");
  error = PushChunk(data->iff, 0, ID_CHRS, IFFSIZE_UNKNOWN);
  SHOWVALUE(DBF_CLIPBOARD, error);
  error = WriteChunkBytes(data->iff, line->line.Contents, line->line.Length);
  SHOWVALUE(DBF_CLIPBOARD, error);
  error = PopChunk(data->iff);
  SHOWVALUE(DBF_CLIPBOARD, error);

  LEAVE();
}
예제 #4
0
BOOL SaveSettings(char *name, struct List *list) {
  struct IFFHandle  *iff;
  struct PrefHeader  header = { 0, 0, 0 };
  struct Node       *n;
  BOOL               success = FALSE;

  if(name && (iff = AllocIFF())) {
    iff->iff_Stream = Open(name, MODE_NEWFILE);
    if(iff->iff_Stream) {
      InitIFFasDOS(iff);
      if(!OpenIFF(iff, IFFF_WRITE)) {
        if(! PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN)) {

          success = TRUE;

          // Prefs header
          if(! PushChunk(iff, ID_PREF, ID_PRHD, sizeof header)) {
            WriteChunkBytes(iff, &header, sizeof header);
            PopChunk(iff);
          }
          else success = FALSE;

          // Global prefs
          if(! PushChunk(iff, ID_PREF, ID_AHIG, sizeof globalprefs)) {
            WriteChunkBytes(iff, &globalprefs, sizeof globalprefs);
            PopChunk(iff);
          }
          else success = FALSE;

          // Units
          if(list != NULL) {    
            for(n = list->lh_Head; n->ln_Succ; n = n->ln_Succ) {
              if(! PushChunk(iff, ID_PREF, ID_AHIU, sizeof(struct AHIUnitPrefs))) {
                WriteChunkBytes(iff, &((struct UnitNode *) n)->prefs,
                    sizeof(struct AHIUnitPrefs));
                PopChunk(iff);
              }
              else success = FALSE;
            }
          }
        }
        CloseIFF(iff);
      }
      Close(iff->iff_Stream);
    }
    FreeIFF(iff);
  }
  return success;
}
예제 #5
0
bool gui_empty_clipboard(void)
{
	/* Put a half-completed FTXT on the clipboard and leave it open for more additions */

	struct CSet cset = {0};

	if(!(OpenIFF(iffh,IFFF_WRITE)))
	{
		if(!(PushChunk(iffh,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN)))
		{
			if(option_utf8_clipboard || ami_utf8_clipboard)
			{
				if(!(PushChunk(iffh,0,ID_CSET,32)))
				{
					cset.CodeSet = 106; // UTF-8
					WriteChunkBytes(iffh,&cset,32);
					PopChunk(iffh);
				}
			}
		}
		else
		{
			PopChunk(iffh);
			return false;
		}
		return true;
	}
	return false;
}
예제 #6
0
ULONG WRITE_Gadget(piClass *cl,piObject *o,struct piIO *msg)
{
	LONG error=0,a;
	struct Node_Gadget *ng;
	struct GadToolsData *gtd;

	piGetAttr(o,OBJ_Node,(ULONG *)&ng);
	piGetAttr(o,GAOBJ_NodeData,(ULONG *)&gtd);
	if(error=PushChunk(msg->IFFh,NULL,ng->ng_PlugInID,IFFSIZE_UNKNOWN)) return (ULONG)error;
	WriteChunkBytes(msg->IFFh,(APTR)&ng->ng_X,SIZE(Node_Gadget,ng_X));
	for(a=0;a<ng->ng_NumTags;a++) WriteTagItem(msg->IFFh,&ng->ng_Tags[a],ng->ng_TagTypes[a]);
	for(a=0;a<ng->ng_NumOwnTags;a++) WriteTagItem(msg->IFFh,&ng->ng_OwnTags[a],ng->ng_OwnTagTypes[a]);
	if(ng->ng_Type==GTYPE_GADTOOLS) WriteChunkBytes(msg->IFFh,(APTR)gtd,sizeof(struct GadToolsData));
	if(error=PopChunk(msg->IFFh)) return (ULONG)error;
	return (ULONG)error;
}
예제 #7
0
파일: frame.c 프로젝트: thom-ek/GadToolsBox
ULONG WRITE_Frame(piClass *cl,piObject *o,struct piIO *msg)
{
	LONG error=0;
	struct Node_Frame *nf;

	piGetAttr(o,OBJ_Node,(ULONG *)&nf);
	if(error=PushChunk(msg->IFFh,NULL,ID_FRME,IFFSIZE_UNKNOWN)) return (ULONG)error;
	WriteChunkBytes(msg->IFFh,(APTR)&nf->nf_X,SIZE(Node_Frame,nf_X));
	if(error=PopChunk(msg->IFFh)) return (ULONG)error;
	return (ULONG)error;
}
예제 #8
0
void ClipInfo(struct line_node *line, struct InstData *data)
{
  LONG error;

  ENTER();

  if(line->line.Flow != MUIV_TextEditor_Flow_Left)
  {
    D(DBF_CLIPBOARD, "writing FLOW");
    error = PushChunk(data->iff, 0, ID_FLOW, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = WriteChunkBytes(data->iff, &line->line.Flow, 2);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  if(line->line.Separator)
  {
    D(DBF_CLIPBOARD, "writing SBAR");
    error = PushChunk(data->iff, 0, ID_SBAR, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = WriteChunkBytes(data->iff, &line->line.Separator, 2);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  if(line->line.Color)
  {
    D(DBF_CLIPBOARD, "writing HIGH");
    error = PushChunk(data->iff, 0, ID_HIGH, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = WriteChunkBytes(data->iff, &line->line.Color, 2);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  LEAVE();
}
예제 #9
0
BOOL PushStringChunk( struct IFFHandle *iff, LONG id, STRPTR txt)
{
	if(txt)
	{
		if(!PushChunk(iff,0,id,IFFSIZE_UNKNOWN))
		{
			WriteChunkBytes(iff,txt,strlen(txt));
			PopChunk(iff);
		}
	}
	return TRUE;
}
예제 #10
0
/*** Save a file where we found it, otherwise in ENVARC: ***/
UBYTE save_prefs(PREFS *prefs)
{
	APTR  file;
	UBYTE num, size;
	UBYTE NumField[2];
	if( (file = open_prefs(Path, MODE_SAVE)) )
	{
		if( !PushChunk(file, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN) )
		{
			if( !PushChunk(file, ID_PREF, ID_JANO, IFFSIZE_UNKNOWN) )
			{	 
			    	if (Wnd)
				{
				    /* Save window dimension */
				    CopyMem(&Wnd->LeftEdge, &prefs->left, 4*sizeof(WORD));
				}
				else
				{
				    prefs->left = prefs->top = prefs->width = prefs->height = 0;
				}
				
				/* Write configuration file */
				for(num=0; num < MAX_NUMFIELD; num++) {
					register STRPTR src;
					size = sizefields[ num ];
					src  = (STRPTR)prefs + offsets[ num ];
					if(size == 0) src = *(STRPTR *)src, size = strlen(src)+1;

					NumField[0] = num; NumField[1] = size;
					if( WriteChunkBytes(file, NumField, 2) != 2   ||
					    WriteChunkBytes(file, src,   size) != size ) break;
				}
				PopChunk( file );
			}
			PopChunk( file );
		}
		close_prefs(file);
	}
	return 0;
}
예제 #11
0
/**************************************************************************
 SavePrefsHeader: Write a PRHD chunk
**************************************************************************/
static int SavePrefsHeader(struct IFFHandle *iff)
{
    if (!PushChunk( iff, 0, MAKE_ID('P','R','H','D'), IFFSIZE_UNKNOWN))
    {
        struct PrefHeader ph;
        ph.ph_Version = 0;
        ph.ph_Type = 0;
        ph.ph_Flags = 0;

        if (WriteChunkBytes(iff, &ph, sizeof(struct PrefHeader)))
            if (!PopChunk(iff)) return 1;
        PopChunk(iff);
    }
    return 0;
}
예제 #12
0
void PutScrap(uint32 type, void *scrap, int32 length)
{
	D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
	if (length <= 0 || !clipboard_open)
		return;

	switch (type) {
		case 'TEXT': {
			D(bug(" clipping TEXT\n"));

			// Open IFF stream
			if (OpenIFF(iffw, IFFF_WRITE))
				break;

			// Convert text from Mac charset to ISO-Latin1
			uint8 *buf = new uint8[length];
			uint8 *p = (uint8 *)scrap;
			uint8 *q = buf;
			for (int i=0; i<length; i++) {
				uint8 c = *p++;
				if (c < 0x80) {
					if (c == 13)	// CR -> LF
						c = 10;
				} else if (!no_clip_conversion)
					c = mac2iso[c & 0x7f];
				*q++ = c;
			}

			// Write text
			if (!PushChunk(iffw, 'FTXT', 'FORM', IFFSIZE_UNKNOWN)) {
				if (!PushChunk(iffw, 0, 'CHRS', IFFSIZE_UNKNOWN)) {
					WriteChunkBytes(iffw, scrap, length);
					PopChunk(iffw);
				}
				PopChunk(iffw);
			}

			// Close IFF stream
			CloseIFF(iffw);
			delete[] buf;
			break;
		}
	}
}
예제 #13
0
BOOL SavePrefsFH(BPTR fh)
{
    static struct SerialPrefs 	saveprefs;
    struct IFFHandle 	     	*iff;    
    BOOL    	    	    	retval = FALSE, delete_if_error = FALSE;
    
    saveprefs = serialprefs;
    
    
    D(bug("SavePrefsFH: fh: %lx\n", fh));
    //if ((iff->iff_Stream = (IPTR)Open(filename, MODE_NEWFILE)))
    
    if ((iff = AllocIFF()))
    {
	iff->iff_Stream = (IPTR) fh;
	D(bug("SavePrefsFH: stream opened.\n"));
	    
	    delete_if_error = TRUE;
	    
	    InitIFFasDOS(iff);
	    
	    if (!OpenIFF(iff, IFFF_WRITE))
	    {
    	    	D(bug("SavePrefsFH: OpenIFF okay.\n"));
		
		if (!PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN))
		{
    	    	    D(bug("SavePrefsFH: PushChunk(FORM) okay.\n"));
		    
		    if (!PushChunk(iff, ID_PREF, ID_PRHD, sizeof(struct FilePrefHeader)))
		    {
		    	struct FilePrefHeader head;

    	    	    	D(bug("SavePrefsFH: PushChunk(PRHD) okay.\n"));
			
			head.ph_Version  = PHV_CURRENT; 
			head.ph_Type     = 0;
			head.ph_Flags[0] =
			head.ph_Flags[1] =
			head.ph_Flags[2] =
			head.ph_Flags[3] = 0;
			
			if (WriteChunkBytes(iff, &head, sizeof(head)) == sizeof(head))
			{
    	    	    	    D(bug("SavePrefsFH: WriteChunkBytes(PRHD) okay.\n"));
			    
			    PopChunk(iff);
			    
			    if (!PushChunk(iff, ID_PREF, ID_SERL, sizeof(struct SerialPrefs)))
			    {
    	    	    	    	D(bug("SavePrefsFH: PushChunk(LCLE) okay.\n"));
				
			    	if (WriteChunkBytes(iff, &saveprefs, sizeof(saveprefs)) == sizeof(saveprefs))
				{
   	    	    	    	    D(bug("SavePrefsFH: WriteChunkBytes(SERL) okay.\n"));
  	    	    	    	    D(bug("SavePrefsFH: Everything okay :-)\n"));
				    
				    retval = TRUE;
				}
				
    			    	PopChunk(iff);

			    } /* if (!PushChunk(iff, ID_PREF, ID_SERL, sizeof(struct LocalePrefs))) */
			    			    
			} /* if (WriteChunkBytes(iff, &head, sizeof(head)) == sizeof(head)) */
			else
		    	{
			    PopChunk(iff);
			}
			
		    } /* if (!PushChunk(iff, ID_PREF, ID_PRHD, sizeof(struct PrefHeader))) */
		    
		    PopChunk(iff);
		    		    
		} /* if (!PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN)) */
		
	    	CloseIFF(iff);
				
	    } /* if (!OpenIFF(iff, IFFFWRITE)) */
	    
	
	FreeIFF(iff);
	
    } /* if ((iff = AllocIFF())) */
    
    #if 0
    if (!retval && delete_if_error)
    {
    	DeleteFile(filename);
    }
    #endif
	    
    
    return retval;    
}
예제 #14
0
파일: io.c 프로젝트: cbeust/banker-amiga
static void
writeDatabaseFile(Entries entries, struct IFFHandle *iff)
{
   Automatic nextFreeAuto = NULL;
   Entry nextFreeEntry = NULL;
   DataBase db;
   int j;

   PushChunk(iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN);

/* Write the automatic entries */
   PushChunk(iff, 0, ID_AUTO, IFFSIZE_UNKNOWN);
   j = 0;
   db = (DataBase) entries -> automatic;
   DB_Rewind(db);
   while ((nextFreeAuto = DB_NextEntry(db))) {
      struct DateStamp *ds;

   /* skip to the next free entry */
      ds = & nextFreeAuto -> first;
      WriteChunkBytes(iff, & ds -> ds_Days, sizeof(LONG));
      WriteChunkBytes(iff, & ds -> ds_Minute, sizeof(LONG));
      WriteChunkBytes(iff, & ds -> ds_Tick, sizeof(LONG));

      ds = & nextFreeAuto -> last;
      WriteChunkBytes(iff, & ds -> ds_Days, sizeof(LONG));
      WriteChunkBytes(iff, & ds -> ds_Minute, sizeof(LONG));
      WriteChunkBytes(iff, & ds -> ds_Tick, sizeof(LONG));

      WriteChunkBytes(iff, & nextFreeAuto -> repeatDays, sizeof(ULONG));
      WriteChunkBytes(iff, & nextFreeAuto -> repeatWeeks, sizeof(ULONG));
      WriteChunkBytes(iff, & nextFreeAuto -> repeatMonths, sizeof(ULONG));
      WriteChunkBytes(iff, & nextFreeAuto -> repeatYears, sizeof(ULONG));
      WriteChunkBytes(iff, nextFreeAuto -> amount, AMOUNTL);
      WriteChunkBytes(iff, nextFreeAuto -> transaction, TRANSACTIONL);
      WriteChunkBytes(iff, nextFreeAuto -> imputation, IMPUTATIONL);
   }
   PopChunk(iff);   /* AUTO */

/* Write the regular database */
   PushChunk(iff, 0, ID_CHRS, IFFSIZE_UNKNOWN);
   j = 0;
   db = (DataBase) entries -> list;
   DB_Rewind(db);
   while ((nextFreeEntry = DB_NextEntry(db))) {
      struct DateStamp *ds = & nextFreeEntry -> date;

      if (! nextFreeEntry -> fake) {  /* only save regular entries, not auto */
         WriteChunkBytes(iff, & ds -> ds_Days, sizeof(LONG));
         WriteChunkBytes(iff, & ds -> ds_Minute, sizeof(LONG));
         WriteChunkBytes(iff, & ds -> ds_Tick, sizeof(LONG));

         WriteChunkBytes(iff, nextFreeEntry -> transaction, TRANSACTIONL);
         WriteChunkBytes(iff, nextFreeEntry -> amount, AMOUNTL);
         WriteChunkBytes(iff, nextFreeEntry -> checkNumber, CHECKNUMBERL);
         WriteChunkBytes(iff, nextFreeEntry -> imputation, IMPUTATIONL);
         WriteChunkBytes(iff, nextFreeEntry -> reason, REASONL);
         WriteChunkBytes(iff, & nextFreeEntry -> validated, 4);
      }
   }
   PopChunk(iff);   /* CHRS */

   PopChunk(iff);   /* FTXT */
}
예제 #15
0
IPTR SMEditor__MUIM_PrefsEditor_ExportFH
(
    Class *CLASS, Object *self,
    struct MUIP_PrefsEditor_ExportFH *message
)
{
    SETUP_INST_DATA;
    
    struct PrefHeader header = { 0 }; 
    struct IFFHandle *handle;
    BOOL              success = TRUE;
    LONG              error   = 0;
        
    if ((handle = AllocIFF()))
    {
        handle->iff_Stream = (IPTR) message->fh;
        
        InitIFFasDOS(handle);
        
        if (!(error = OpenIFF(handle, IFFF_WRITE))) /* NULL = successful! */
        {
            struct ScreenModePrefs smp;
	    
	    memset(&smp, 0, sizeof(smp));
            
	    BYTE i;
            
            PushChunk(handle, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN); /* FIXME: IFFSIZE_UNKNOWN? */
            
            header.ph_Version = PHV_CURRENT;
            header.ph_Type    = 0;
            
            PushChunk(handle, ID_PREF, ID_PRHD, IFFSIZE_UNKNOWN); /* FIXME: IFFSIZE_UNKNOWN? */
            
            WriteChunkBytes(handle, &header, sizeof(struct PrefHeader));
            
            PopChunk(handle);
            
            for (i = 0; i < 1; i++)
            {
                error = PushChunk(handle, ID_PREF, ID_SCRM, sizeof(struct ScreenModePrefs));
                
                if (error != 0) // TODO: We need some error checking here!
                {
                    printf("error: PushChunk() = %ld ", error);
                }
                
	        smp.smp_DisplayID = XGET(data->properties, MUIA_ScreenModeProperties_DisplayID);
                smp.smp_Width     = XGET(data->properties, MUIA_ScreenModeProperties_Width);
                smp.smp_Height    = XGET(data->properties, MUIA_ScreenModeProperties_Height);
                smp.smp_Depth     = XGET(data->properties, MUIA_ScreenModeProperties_Depth);
                
		if (XGET(data->properties, MUIA_ScreenModeProperties_Autoscroll))
		    smp.smp_Control = AUTOSCROLL;
		else
		    smp.smp_Control = 0;
                
		SMPByteSwap(&smp);
			
                error = WriteChunkBytes(handle, &smp, sizeof(struct ScreenModePrefs));
                error = PopChunk(handle);
                                
                if (error != 0) // TODO: We need some error checking here!
                {
                    printf("error: PopChunk() = %ld ", error);
                }
            }

            // Terminate the FORM
            PopChunk(handle);
        }
        else
        {
            //ShowError(_(MSG_CANT_OPEN_STREAM));
            success = FALSE;
        }
        
        CloseIFF(handle);
	FreeIFF(handle);
    }
    else // AllocIFF()
    {
        // Do something more here - if IFF allocation has failed, something isn't right
        //ShowError(_(MSG_CANT_ALLOCATE_IFFPTR));
        success = FALSE;
    }

    return success;
}
예제 #16
0
void ClipChars(LONG x, struct line_node *line, LONG length, struct InstData *data)
{
  UWORD style[2] = {1, GetStyle(x-1, line)};
  UWORD color[2] = {1, 0};
  UWORD *colors = line->line.Colors;
  LONG error;

  ENTER();

  D(DBF_CLIPBOARD, "ClipChars()");

  ClipInfo(line, data);

  if(colors)
  {
    D(DBF_CLIPBOARD, "writing COLS");
    error = PushChunk(data->iff, 0, ID_COLS, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);

    while((*colors <= x) && (*colors != 0xffff))
    {
      color[1] = *(colors+1);
      colors += 2;
    }

    if(color[1] != 0 && *colors-x != 1)
    {
      error = WriteChunkBytes(data->iff, color, 4);
      SHOWVALUE(DBF_CLIPBOARD, error);
    }

    if(*colors != 0xffff)
    {
      while(*colors <= x+length)
      {
        color[0] = *colors++ - x;
        color[1] = *colors++;

        error = WriteChunkBytes(data->iff, color, 4);
        SHOWVALUE(DBF_CLIPBOARD, error);
      }
    }

    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  D(DBF_CLIPBOARD, "writing STYL");
  error = PushChunk(data->iff, 0, ID_STYL, IFFSIZE_UNKNOWN);
  SHOWVALUE(DBF_CLIPBOARD, error);

  if(style[1] != 0)
  {
    unsigned short t_style = style[1];

    if(t_style & BOLD)
    {
      style[1] = BOLD;
      error = WriteChunkBytes(data->iff, style, 4);
      SHOWVALUE(DBF_CLIPBOARD, error);
    }
    if(t_style & ITALIC)
    {
      style[1] = ITALIC;
      error = WriteChunkBytes(data->iff, style, 4);
      SHOWVALUE(DBF_CLIPBOARD, error);
    }
    if(t_style & UNDERLINE)
    {
      style[1] = UNDERLINE;
      error = WriteChunkBytes(data->iff, style, 4);
      SHOWVALUE(DBF_CLIPBOARD, error);
    }
  }

  if(line->line.Styles)
  {
    unsigned short *styles = line->line.Styles;

    while((*styles <= x) && (*styles != EOS))
      styles += 2;

    if(*styles != EOS)
    {
      while(*styles <= x+length)
      {
        style[0] = *styles++ - x;
        style[1] = *styles++;
        error = WriteChunkBytes(data->iff, style, 4);
        SHOWVALUE(DBF_CLIPBOARD, error);
      }

      style[0] = length+1;
      style[1] = GetStyle(x+length-1, line);
      if(style[1] != 0)
      {
        unsigned short t_style = style[1];

        if(t_style & BOLD)
        {
          style[1] = ~BOLD;
          error = WriteChunkBytes(data->iff, style, 4);
          SHOWVALUE(DBF_CLIPBOARD, error);
        }
        if(t_style & ITALIC)
        {
          style[1] = ~ITALIC;
          error = WriteChunkBytes(data->iff, style, 4);
          SHOWVALUE(DBF_CLIPBOARD, error);
        }
        if(t_style & UNDERLINE)
        {
          style[1] = ~UNDERLINE;
          error = WriteChunkBytes(data->iff, style, 4);
          SHOWVALUE(DBF_CLIPBOARD, error);
        }
      }
    }
  }

  error = PopChunk(data->iff);
  SHOWVALUE(DBF_CLIPBOARD, error);

  D(DBF_CLIPBOARD, "writing CHRS");
  error = PushChunk(data->iff, 0, ID_CHRS, IFFSIZE_UNKNOWN);
  SHOWVALUE(DBF_CLIPBOARD, error);
  error = WriteChunkBytes(data->iff, line->line.Contents + x, length);
  SHOWVALUE(DBF_CLIPBOARD, error);
  error = PopChunk(data->iff);
  SHOWVALUE(DBF_CLIPBOARD, error);

  LEAVE();
}
예제 #17
0
main(int argc, char **argv)
{
    int colors;
    struct {
        long nplanes;
        long pbytes;
        long across;
        long down;
        long npics;
        long xsize;
        long ysize;
    } pdat;
    long pbytes; /* Bytes of data in a plane */
    int i, cnt;
    BitMapHeader bmhd;
    struct IFFHandle *iff;
    long camg = HIRES | LACE;
    int tiles = 0;
    char **planes;

    if (argc != 3) {
        fprintf(stderr, "Usage: %s source destination\n", argv[0]);
        exit(1);
    }

#if defined(_DCC) || defined(__GNUC__)
    IFFParseBase = OpenLibrary("iffparse.library", 0);
    if (!IFFParseBase) {
        error("unable to open iffparse.library");
        exit(1);
    }
#endif

    /* First, count the files in the file */
    if (fopen_text_file(argv[1], "r") != TRUE) {
        perror(argv[1]);
        return (1);
    }

    nplanes = 0;
    i = colorsinmap - 1; /*IFFScreen.Colors - 1; */
    while (i != 0) {
        nplanes++;
        i >>= 1;
    }

    planes = malloc(nplanes * sizeof(char *));
    if (planes == 0) {
        error("can not allocate planes pointer");
        exit(1);
    }

    while (read_text_tile(pixels) == TRUE)
        ++tiles;
    fclose_text_file();

    IFFScreen.Width = COLS * TILE_X;
    IFFScreen.Height = ROWS * TILE_Y;

    pbytes = (COLS * ROWS * TILE_X + 15) / 16 * 2 * TILE_Y;

    for (i = 0; i < nplanes; ++i) {
        planes[i] = calloc(1, pbytes);
        if (planes[i] == 0) {
            error("can not allocate planes pointer");
            exit(1);
        }
    }

    /* Now, process it */
    if (fopen_text_file(argv[1], "r") != TRUE) {
        perror(argv[1]);
        return (1);
    }

    iff = AllocIFF();
    if (!iff) {
        error("Can not allocate IFFHandle");
        return (1);
    }

    iff->iff_Stream = Open(argv[2], MODE_NEWFILE);
    if (!iff->iff_Stream) {
        error("Can not open output file");
        return (1);
    }

    InitIFFasDOS(iff);
    OpenIFF(iff, IFFF_WRITE);

    PushChunk(iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN);

    bmhd.w = IFFScreen.Width;
    bmhd.h = IFFScreen.Height;
    bmhd.x = 0;
    bmhd.y = 0;
    bmhd.nPlanes = nplanes;
    bmhd.masking = 0;
    bmhd.compression = 0;
    bmhd.reserved1 = 0;
    bmhd.transparentColor = 0;
    bmhd.xAspect = 100;
    bmhd.yAspect = 100;
    bmhd.pageWidth = TILE_X;
    bmhd.pageHeight = TILE_Y;

    PushChunk(iff, ID_BMAP, ID_BMHD, sizeof(bmhd));
    WriteChunkBytes(iff, &bmhd, sizeof(bmhd));
    PopChunk(iff);

    PushChunk(iff, ID_BMAP, ID_CAMG, sizeof(camg));
    WriteChunkBytes(iff, &camg, sizeof(camg));
    PopChunk(iff);

    /* We need to reorder the colors to get reasonable default pens but
     * we also need to know where some of the colors are - so go find out.
     */
    map_colors();

    cmap = malloc((colors = (1L << nplanes)) * sizeof(AmiColorMap));
    for (i = 0; i < colors; ++i) {
        cmap[colrmap[i]].r = ColorMap[CM_RED][i];
        cmap[colrmap[i]].g = ColorMap[CM_GREEN][i];
        cmap[colrmap[i]].b = ColorMap[CM_BLUE][i];
    }

    PushChunk(iff, ID_BMAP, ID_CMAP, IFFSIZE_UNKNOWN);
    for (i = 0; i < colors; ++i)
        WriteChunkBytes(iff, &cmap[i], 3);
    PopChunk(iff);

    cnt = 0;
    while (read_text_tile(pixels) == TRUE) {
        packwritebody(pixels, planes, cnt);
        if (cnt % 20 == 0)
            printf("%d..", cnt);
        ++cnt;
        fflush(stdout);
    }

    pdat.nplanes = nplanes;
    pdat.pbytes = pbytes;
    pdat.xsize = TILE_X;
    pdat.ysize = TILE_Y;
    pdat.across = COLS;
    pdat.down = ROWS;
    pdat.npics = cnt;

    PushChunk(iff, ID_BMAP, ID_PDAT, IFFSIZE_UNKNOWN);
    WriteChunkBytes(iff, &pdat, sizeof(pdat));
    PopChunk(iff);

    PushChunk(iff, ID_BMAP, ID_PLNE, IFFSIZE_UNKNOWN);
    for (i = 0; i < nplanes; ++i)
        WriteChunkBytes(iff, planes[i], pbytes);
    PopChunk(iff);

    CloseIFF(iff);
    Close(iff->iff_Stream);
    FreeIFF(iff);

    printf("\n%d tiles converted\n", cnt);

#if defined(_DCC) || defined(__GNUC__)
    CloseLibrary(IFFParseBase);
#endif
    exit(0);
}
예제 #18
0
/*** Write strings to the clipboard.device ***/
BOOL CBWriteFTXT( LINE *stsel, struct cutcopypast *ccp )
{
	LINE *ln;
	long  length;

	/* If clipboard not already allocated, makes it now */
	if( clip == NULL && !CBOpen(STD_CLIP_UNIT) ) return FALSE;

	/* Compute how many chars are selected */
	for(length=0, ln=stsel; ln && ln->flags; ln=ln->next)
	{
		length += ln->size;
		/* In block selection mode, always add a newline */
		if(ccp->select == COLUMN_TYPE) length++;
		if(ln->flags & FIRSTSEL) length -= find_nbc(ln, ccp->startsel);
		if(ln->flags & LASTSEL)  length += find_nbc(ln, ccp->endsel)-ln->size;
		else length++; /* New line */
	}
	if(length == 0) return FALSE;

	if( !OpenIFF(clip, IFFF_WRITE) )
	{
		/* Let iffparse manage main chunk size */
		if( !PushChunk(clip, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN) )
		{
			if( !PushChunk(clip, ID_FTXT, ID_CHRS, length) )
			{
				/* In columnar selection, use '\r' as eol */
				char eol = (ccp->select == COLUMN_TYPE ? '\r':'\n'), add_eol;

				/* Write the content of strings */
				for(ln = stsel; ln && ln->flags; ln = ln->next)
				{
					STRPTR stream;
					ULONG  length;
					stream = (STRPTR)ln->stream;
					length = ln->size;
					if(ln->flags & FIRSTSEL) {
						register long rc = find_nbc(ln, ccp->startsel);
						length -= rc; stream += rc;
					}
					if(ln->flags & LASTSEL) {
						length += find_nbc(ln, ccp->endsel) - ln->size;
						/* Add automatically a newline */
						add_eol = (ccp->select == COLUMN_TYPE);
					}
					else add_eol = 1;

					WriteChunkBytes(clip, stream, length);
					if(add_eol)
						WriteChunkBytes(clip, &eol, 1);
				}
				PopChunk(clip);
			}
			else ThrowError(Wnd, ErrMsg(ERR_NOMEM));
			PopChunk(clip);
		}
		else ThrowError(Wnd, ErrMsg(ERR_NOMEM));
		CloseIFF(clip);
	}
	return TRUE;
}
예제 #19
0
파일: xpm2iff.c 프로젝트: Agyar/NetHack
main( int argc, char **argv )
{
    int colors;
    struct {
	long nplanes;
	long pbytes;
	long across;
	long down;
	long npics;
	long xsize;
	long ysize;
    } pdat;
    long pbytes;	/* Bytes of data in a plane */
    int i, cnt;
    BitMapHeader bmhd;
    struct IFFHandle *iff;
    long camg = HIRES|LACE;
    int tiles=0;
    int index;

#if defined(_DCC) || defined (__GNUC__)
    IFFParseBase = OpenLibrary( "iffparse.library", 0 );
    if( !IFFParseBase ) {
	error( "unable to open iffparse.library" );
	exit( 1 );
    }
#endif

    if( fopen_xpm_file( argv[1], "r" ) != TRUE )
    {
	perror( argv[1] );
	return( 1 );
    }

    nplanes = 0;
    i = XpmScreen.Colors - 1;
    while( i != 0 )
    {
	nplanes++;
	i >>= 1;
    }

    planes = malloc( nplanes * sizeof( char * ) );
    if( planes == 0 )
    {
	error( "can not allocate planes pointer" );
	exit( 1 );
    }

    XpmScreen.BytesPerRow = ((XpmScreen.Width + 15)/16)*2;
    pbytes = XpmScreen.BytesPerRow * XpmScreen.Height;
    for( i = 0; i < nplanes; ++i )
    {
	planes[ i ] = malloc( pbytes );
	if( planes[ i ] == 0 )
	{
	    error( "can not allocate planes pointer" );
	    exit( 1 );
	}
	memset( planes[i], 0, pbytes );
    }

    iff = AllocIFF();
    if( !iff )
    {
	error( "Can not allocate IFFHandle" );
	return( 1 );
    }

    iff->iff_Stream = Open( argv[2], MODE_NEWFILE );
    if( !iff->iff_Stream )
    {
	error( "Can not open output file" );
	return( 1 );
    }

    InitIFFasDOS( iff );
    OpenIFF( iff, IFFF_WRITE );

    PushChunk( iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN );

    bmhd.w = XpmScreen.Width;
    bmhd.h = XpmScreen.Height;
    bmhd.x = 0;
    bmhd.y = 0;
    bmhd.nPlanes = nplanes;
    bmhd.masking = 0;
    bmhd.compression = 0;
    bmhd.reserved1 = 0;
    bmhd.transparentColor = 0;
    bmhd.xAspect = 100;
    bmhd.yAspect = 100;
    bmhd.pageWidth = 0;			/* not needed for this program */
    bmhd.pageHeight = 0;		/* not needed for this program */

    PushChunk( iff, ID_BMAP, ID_BMHD, sizeof( bmhd ) );
    WriteChunkBytes( iff, &bmhd, sizeof( bmhd ) );
    PopChunk( iff );

    PushChunk( iff, ID_BMAP, ID_CAMG, sizeof( camg ) );
    WriteChunkBytes( iff, &camg, sizeof( camg ) );
    PopChunk( iff );

#define SCALE(x) (x)
    cmap = malloc( (colors = (1L<<nplanes)) * sizeof(AmiColorMap) );
    if(cmap == 0){
	error("Can't allocate color map");
	exit(1);
    }
    for(index = 0; index<256; index++){
	if(ttable[index].flag){
	    cmap[ttable[index].slot].r = SCALE(ttable[index].r);
	    cmap[ttable[index].slot].g = SCALE(ttable[index].g);
	    cmap[ttable[index].slot].b = SCALE(ttable[index].b);
	}
    }
#undef SCALE

    PushChunk( iff, ID_BMAP, ID_CMAP, IFFSIZE_UNKNOWN );
    WriteChunkBytes( iff, cmap, colors*sizeof(*cmap) );
    PopChunk( iff );

    conv_image();

    pdat.nplanes = nplanes;
    pdat.pbytes = pbytes;
    pdat.xsize = XpmScreen.Width;
    pdat.ysize = XpmScreen.Height;
    pdat.across = 0;
    pdat.down = 0;
    pdat.npics = 1;

    PushChunk( iff, ID_BMAP, ID_PDAT, IFFSIZE_UNKNOWN );
    WriteChunkBytes( iff, &pdat, sizeof( pdat ) );
    PopChunk( iff );

    PushChunk( iff, ID_BMAP, ID_PLNE, IFFSIZE_UNKNOWN );
    for( i = 0; i < nplanes; ++i )
	WriteChunkBytes( iff, planes[i], pbytes );
    PopChunk( iff );

    CloseIFF( iff );
    Close( iff->iff_Stream );
    FreeIFF( iff );

#if defined(_DCC) || defined (__GNUC__)
    CloseLibrary( IFFParseBase );
#endif
    exit( 0 );
}