/*
* Open a TIFF file for read/writing.
*/
TIFF*
TIFFOpen(const char* name, const char* mode)
{
	static const char module[] = "TIFFOpen";
	int m;
	long fd;

	m = _TIFFgetMode(mode, module);
	if (m == -1)
		return ((TIFF*)0);
	if (m & O_TRUNC) {
		fd = Fcreate(name, 0);
	} else {
		fd = Fopen(name, m & O_ACCMODE);
		if (fd == AEFILNF && m & O_CREAT)
			fd = Fcreate(name, 0);
	}
	if (fd < 0)
		errno = (int)fd;
	if (fd < 0) {
		TIFFError(module, "%s: Cannot open", name);
		return ((TIFF*)0);
	}
	return (TIFFFdOpen(fd, name, mode));
}
Esempio n. 2
0
void createTestFiles(void)
{
    Dsetdrv(drive);             // switch to selected drive
    Dsetpath("\\");
    (void) Dcreate("TESTDIR");
    Dsetpath("\\TESTDIR");

    int i, f;
    char numString[8];
    char fileName[16];
    for(i=0; i<25; i++) {
        byteToHex(i + 1, numString);
        
        strcpy(fileName, "FILE_");
        strcat(fileName, numString);
        f = Fcreate(fileName, 0);
        Fwrite(f, 7, fileName);
        Fclose(f);
        
        strcpy(fileName, "FILENAME.X");
        strcat(fileName, numString);
        f = Fcreate(fileName, 0);
        Fwrite(f, 12, fileName);
        Fclose(f);
        
        strcpy(fileName, "DIR_");
        strcat(fileName, numString);
        (void) Dcreate(fileName);
    }
}
Esempio n. 3
0
void save_app_icon(void)
	{
	int i, fh;
	unsigned long len=0;
	char inf[256]={0};

	strcpy(inf,home);
	strcat(inf,"defaults\\MyTask.ico");
	fh=(int)Fcreate(inf,0);

	if (fh<0L)
		{
		strcpy(inf,home);
		strcat(inf,"MyTask.ico");
		fh=(int)Fcreate(inf,0);
		}

	if (fh>=0L)
		{
		len = icons_spec_app->no;
		write(fh, &len, 4);
		for(i=0; i<icons_spec_app->no; i++)
			{
			write(fh, &icons_spec_app[i].obj_no, 4);
			len = strlen(icons_spec_app[i].name);
			write(fh, &len, 4);
			write(fh, icons_spec_app[i].name, len);
			}
		close(fh);
		}
	}
void SwipeRecognizer::onTouchEnded(Touch *touch, Event *pEvent)
{
#if VERBOSE_TOUCH_RECOGNIZERS
    CCLOG("linked ? %s", mainLinker->linkedObjectOf(touch) == NULL ? "yes" : "no");
    CCLOG("is in start ? %s", touchStart.find(touch->getID()) != touchStart.end() ? "yes" : "no");
    CCLOG("time ? %s", (TIME - touchStart.at(touch->getID())) < 2.0 ? "yes" : "no");
    CCLOG("initial position : %f, %f, current : %f, %f", touchInitialPosition.at(touch->getID()).x, touchInitialPosition.at(touch->getID()).y, Scene::touchPosition(touch).x, Scene::touchPosition(touch).y);
#endif
    if(mainLinker != NULL
       && mainLinker->linkedObjectOf(touch) == NULL
       && touchStart.find(touch->getID()) != touchStart.end())
    {
        Vec2 initialPosition = touchInitialPosition.at(touch->getID());
        Vec2 currentPosition = Scene::touchPosition(touch);
        if(fabsf(initialPosition.x - currentPosition.x) >= minMovement * RESOLUTION_MULTIPLIER &&
           fabsf(initialPosition.y - currentPosition.y) <= fabsf(initialPosition.x - currentPosition.x) &&
           fabsf(initialPosition.x - currentPosition.x) > fabsf(initialPosition.y - currentPosition.y) &&
           fabsf(initialPosition.x - currentPosition.x) / (TIME - touchStart.at(touch->getID())) > minSpeed * RESOLUTION_MULTIPLIER)
        {
            CCDictionary* infos = CCDictionary::create();
            infos->setObject(touch, "Touch");
            infos->setObject(initialPosition.x > currentPosition.x ? Screate("Left") : Screate("Right"), "Direction");
            infos->setObject(Fcreate(initialPosition.x), "InitialPositionX");
            infos->setObject(Fcreate(initialPosition.y), "InitialPositionY");
            Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("SwipeRecognized", infos);
        }
        
    }
    touchStart.erase(touch->getID());
    touchInitialPosition.erase(touch->getID());
}
Esempio n. 5
0
static void printFile(char *fileNam)
{
	int fi, fo;
#define NBUFF 256
	char buff[NBUFF];
	long len;
	
	fileNam[0] = 'd';			/* force data file */

	if ( (fi=Fopen(fileNam, FO_READ)) >= 0 ) {
		if ( (fo=Fcreate(prDevice, 0)) < 0)
			fo=Fopen(prDevice, FO_WRITE);
		/* Fopen may return < 0 for devices like PRN: ! */
		if ( fo > -31) {
	
			while ( (len=Fread(fi, NBUFF, buff)) > 0)
				Fwrite(fo, len, buff);
	
			Fclose(fo);
		} else {
	        uiPrintf(uiH, uiPrERR, "cannot open device|>%s<", prDevice);
		}
		Fclose(fi);
	} else {
        uiPrintf(uiH, uiPrERR, "cannot open dFile");
	}

	Fdelete(fileNam);
	fileNam[0] = 'c';			/* force control file */
	Fdelete(fileNam);
}	
Esempio n. 6
0
int Copy_file(char *tos_name,char *long_name,int attributes)
{
 short in_file,out_file;
 long size;
 int error;

 if ((in_file=Fopen(tos_name,0))<0)
  return(FALSE);

 if ((out_file=Fcreate(long_name,attributes))<0)
 {
  Fclose(in_file);
  return(FALSE);
 }

 do
 {
  size=Fread(in_file,FILE_BUFF_SIZE,file_buff);
  error=(size!=Fwrite(out_file,size,file_buff));
 } while((size==FILE_BUFF_SIZE)&&(!error));

 Fclose(out_file);
 Fclose(in_file);
 return(!error);
}
Esempio n. 7
0
/****************************************************************
*																*
*				sauve le tampon dans un fichier					*
*																*
****************************************************************/
void sauver_tampon(void)
{
	int handle;
	char nom[FILENAME_MAX] = "", text[FILENAME_MAX];

	if(!selecteur(nom, "*.BUF", Messages(TAMPON_6)))
		return;

	sprintf(text, Messages(TAMPON_7), nom);
	ajoute(Firstwindow, text);

	if ((handle = (int)Fcreate(nom, 0)) >= 0)
	{
		int err;

		if ((err = (int)Fwrite(handle, 512L, Tampon -> fonction.tampon.secteurBin)) < 0)
			error_msg(err);
		else
			ajoute(Firstwindow, Messages(TAMPON_8));

		Fclose(handle);
	}
	else
		ajoute(Firstwindow, Messages(TAMPON_9));
} /* sauver_tampon */
Esempio n. 8
0
/* ------------------------
   | Save option settings |
   ------------------------ */
void save_options(void)
{
long f_handle;

f_handle = Fcreate(option_file, 0);
if (f_handle > 0)
	{
	Fwrite((int)f_handle, 2L, &flt_ovsm);
	Fwrite((int)f_handle, 2L, &flt_bad);
	Fwrite((int)f_handle, 2L, &flt_pitch);
	Fwrite((int)f_handle, 2L, &flt_slice);

	Fwrite((int)f_handle, 2L, &pck_filt);
	Fwrite((int)f_handle, 2L, &pck_4plus);
	Fwrite((int)f_handle, 2L, &pck_4bit);
	Fwrite((int)f_handle, 2L, &pck_alter);

	Fwrite((int)f_handle, 2L, &ovsm_typ);

	Fwrite((int)f_handle, 2L, &ply_speed);
	Fwrite((int)f_handle, 2L, &play_ovsm);
	Fwrite((int)f_handle, 2L, &play_dev);

	Fwrite((int)f_handle, 4L, &spd_table[4]);
	Fwrite((int)f_handle, sizeof(mw_data), mw_data);
	
	Fwrite((int)f_handle, 4L, smp_extension);
	Fwrite((int)f_handle, 4L, pck_extension);
	Fwrite((int)f_handle, 4L, avr_extension);
	
	Fclose((int)f_handle);
	}
}
Esempio n. 9
0
short makenewscore() {

   short ret = 0;

   scoreentries = 0;
#if ATARIST
	if ((sfdbn = Fcreate(SCOREFILE, 0)) < 0) ret = E_FOPENSCORE;
	else {
		Fwrite(sfdbn, 2L, &scoreentries);
		Fclose(sfdbn);
	}
#else
   while( creat( LOCKFILE) < 0);
   if( (scorefile = fopen( SCOREFILE, "w")) == NULL)
      ret = E_FOPENSCORE;
   else {
      sfdbn = fileno( scorefile);
      write( sfdbn, &scoreentries, 2);
      fclose( scorefile);
   }
   unlink( LOCKFILE);
#endif

   return( (ret == 0) ? E_ENDGAME : ret);
}
Esempio n. 10
0
int save_Room(Room *r) {
char filename[MAX_PATHLEN];
File *f;

	if (r == NULL)
		return -1;

	if (!(r->flags & ROOM_DIRTY)) {
/*
	if the room is not dirty, don't save it
	this is a performance improvement for demand loaded rooms; Home> and Mail>
*/
		if (!PARAM_HAVE_RESIDENT_INFO) {
			destroy_StringIO(r->info);
			r->info = NULL;
		}
		return 0;
	}
	r->flags &= ROOM_ALL;			/* this automatically clears ROOM_DIRTY */

	if (r->number == MAIL_ROOM || r->number == HOME_ROOM) {
		char name[MAX_LINE], *p;

		cstrcpy(name, r->name, MAX_LINE);
		if ((p = cstrchr(name, '\'')) == NULL)
			return -1;

		*p = 0;

		if (r->number == MAIL_ROOM)
			bufprintf(filename, sizeof(filename), "%s/%c/%s/MailData", PARAM_USERDIR, *name, name);
		else
			if (r->number == HOME_ROOM)
				bufprintf(filename, sizeof(filename), "%s/%c/%s/HomeData", PARAM_USERDIR, *name, name);

		load_roominfo(r, name);
	} else {
		bufprintf(filename, sizeof(filename), "%s/%u/RoomData", PARAM_ROOMDIR, r->number);
		load_roominfo(r, NULL);
	}
	path_strip(filename);

	if ((f = Fcreate(filename)) == NULL)
		return -1;

	if (save_Room_version1(f, r)) {
		Fcancel(f);
		return -1;
	}
	if (Fclose(f))
		return -1;

	if (!PARAM_HAVE_RESIDENT_INFO) {
		destroy_StringIO(r->info);
		r->info = NULL;
	}
	return 0;
}
Esempio n. 11
0
/****************************************************************
*																*
*			cr‚e un fichier vide d'une taille donn‚e			*
*																*
****************************************************************/
void creer_fichier(void)
{
	OBJECT *file_size;
	char nom[FILENAME_MAX] = "EMPTY.NEW", text[FILENAME_MAX];
	int ex, size, handle;

	if(!selecteur(nom, NULL, Messages(TAMPON_1)))
		return;

	sprintf(text, Messages(TAMPON_2), nom);
	ajoute(Firstwindow, text);

	rsrc_gaddr(R_TREE, TAILLE_FICHIER, &file_size);
	strcpy(file_size[CREATE_FILE_SIZE].ob_spec.tedinfo -> te_ptext, "1");

	ex = xdialog(Dialog[TAILLE_FICHIER].tree, NULL, NULL, NULL, TRUE, TRUE, DialogInWindow ? AUTO_DIAL|MODAL|NO_ICONIFY : FLY_DIAL|MODAL|NO_ICONIFY|SMART_FRAME);

	if (ex == CREATE_FILE_ANNU)
	{
		ajoute(Firstwindow, Messages(TAMPON_3));
		return;
	}

	size = atoi(file_size[CREATE_FILE_SIZE].ob_spec.tedinfo -> te_ptext);

	if ((handle = (int)Fcreate(nom, 0)) >! 0)
	{
		int i, err;
		char buffer[512];

		for (i=0; i<512; i++)	/* efface le buffer */
			buffer[i] = '\0';

		for (i=0; i<size; i++)	/* copie 'size' fois le buffer */
			if ((err = (int)Fwrite(handle, 512L, buffer)) < 0)
			{
				error_msg(err);
				break;
			}

		Fclose(handle);

		sprintf(text, Messages(TAMPON_4), nom, size*512L);
		ajoute(Firstwindow, text);

		if (nom[1] == ':')
			change_disque(toupper(nom[0]) -'A', TRUE);
	}
	else
	{
		error_msg(handle);
		sprintf(text, Messages(TAMPON_5), nom);
		ajoute(Firstwindow, text);
	}
} /* creer_fichier */
Esempio n. 12
0
F_open()
    {
    register char wRetStat;
    int cch, iocb, iocb16;
    int hand;
    char ch, aux1, aux2;
    register unsigned int vector;
    char rgch[80];
    register char *pch = rgch, *pchName;

    iocb16 = reg_X;
    iocb = iocb16 >> 4;
    vector = Dpeek(0x344+iocb16);
    pchName = (char *)lMemory + vector;

    aux1 = Peek(0x34A+iocb16);

    wRetStat=146;
    cch=0;

    parse_fn(pchName, rgch);

 /* Now check for the special case where the use wants a disk directory. */
 /* Open a file _.DIR and stuff a DOS 2.0 type directory listing into it. */

    if (aux1 == 4)
        hand = Fopen(rgch,0);
    else if (aux1 == 8)
        hand = Fcreate(rgch,0);
    else
        goto exit;

    if (hand < 0)
        {
        if (hand == -33)
            wRetStat = 170;
        else
            wRetStat = 165;
        }
    else
        {
        wRetStat = 1;
        rgwDOShand[iocb] = hand;
        rgwDOSmode[iocb] = aux1;
        }

exit:      
    reg_Y = wRetStat;

    reg_Z = wRetStat;
    reg_N = (wRetStat & 0x80) ? TRUE : FALSE;
    reg_PC = 0xE45B;
    }
Esempio n. 13
0
main()
{
  handle = Fcreate ("READ.ME", LECT_SEUL);
  
  if (handle < 0)
    printf ("Erreur … l'ouverture du fichier!\n");
  else
  {
    Fwrite (handle, (long) strlen (ligne), ligne);
    Fclose (handle);
  }
}
Esempio n. 14
0
int x_create(const char *file, int attr)
{
	long result;				/* HR 101202 long */

#if USE_gemdos
	result = (int) gemdos(60, file, attr);
#else
	result = Fcreate(file, attr);
#endif

	return (result < 0) ? xerror(result) : result;
}
Esempio n. 15
0
/***********************************************************
* init_dfht(): Initialisierung durchfuehren
***********************************************************/
void main(void)
{
int i;
int *sip;	
long file;

																			/* Sinustabelle initial. */
for(i = 0, sip = sin_d4; i < 2048; i++) 
	*(sip++) = (int)(sin((i * PI2) / (double)8192.0) * 32768.0);
*(sip++) = 32767;

file = Fcreate("DSPROG.TAB", 0);
Fwrite((int)file, 4098L, sin_d4);
Fclose((int)file);
}
Esempio n. 16
0
void done( void )
{
	v_show_c( handle, 0 );
	v_clsvwk( handle );
	if (score>hiscore)
	{
		puts("\033HSie haben einen neuen Highscore erreicht!");
		printf("Geben Sie Ihren Namen ein: ");
		scanf("%126s",hiname);
		highfile=(int)Fcreate("HISCORE.DAT",0);
		Fwrite(highfile, 4, &score );
		Fwrite(highfile, 128, hiname );
		Fclose(highfile);
	}
}
Esempio n. 17
0
datei_empfangen(void)
{
int hd;

    if (fsel("*.*",tbuf,"Datei empfangen") == 1) {
        strcpy((char *)transfer[UEBERSCH].ob_spec,"Datei empfangen");
/*        v_gtext(handle,640-13*8,13,"E");*/
        open_dial(1);
		if ((hd=Fcreate(tbuf,0)) > 0) {
            show_msg(receive_xmodem(hd));
            Fclose(hd);
        }
        open_dial(0);
    }
}
Esempio n. 18
0
bool wp_open(char *name)
{
	long	err;

	if (strcmp(name, "PRN:") == 0)
		prn_hdl = -3;
	else if (strcmp(name, "AUX:") == 0)
		prn_hdl = -2;
	else
	{
		err = Fopen(name, 1);
		if (err == -33)
			err = Fcreate(name, 0);
		else if (err > 0)
		{
			prn_hdl = (int) err;
			Fseek(0, prn_hdl, 2);
		}
	}
	return (prn_hdl > -31);
}
Esempio n. 19
0
int main (int argc, char **argv) {
	long fh;
	long i;
	struct objhead_struct *dst_adr=(struct objhead_struct *)&dst_buffer;
	
	if (argc<3) {
		printf("Usage: bdyconv.ttp <source.bdy> <dest.e3d>\n");
		Cconin();
		return 0;
	}
	printf("loading %s...\n",*(argv+1));
	
	fh=Fopen(*(argv+1),FO_READ);
	if (fh<0) return 0;
	
	Fread(fh,153600,&bdy_buffer);
	Fclose(fh);

	print_header_info((struct bdy_header *)&bdy_buffer);
	parse_bdy_data(&bdy_buffer,dst_adr);

	printf("saving %s...",*(argv+2));
	
	fh=Fcreate(*(argv+2),0);
	if (fh<0) return 0;
	Fwrite(fh,4,&dst_adr->num_of_points);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->x_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->y_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->z_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->nx_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->ny_buf);
	Fwrite(fh,dst_adr->num_of_points*4,dst_adr->nz_buf);
	Fwrite(fh,4,&dst_adr->num_of_polys);
	Fwrite(fh,sizeof(struct bdy_poly)*dst_adr->num_of_polys,dst_adr->polygons);
	Fclose(fh);
	printf("done.\n");

	return 0;
}
Esempio n. 20
0
short ddcreate(short *pipe)
{
	long fd = -1;

	pipename[17] = 'A';
	pipename[18] = 'A' - 1;

	do	/* ouvre un pipe inoccup� */
	{
		pipename[18]++;
		if (pipename[18] > 'Z')
		{
			pipename[17]++;
			if (pipename[17] > 'Z')
				break;
			else
				pipename[18] = 'A';
		}

		/* FA_HIDDEN f�r Pipe notwendig! */

		fd = Fcreate(pipename, FA_HIDDEN);

	} while (fd == (long) EACCDN);

	if (fd < 0L)
		return(-1);

	*pipe = (pipename[17] << 8) | pipename[18];


	/* Signalhandler konfigurieren */

	ddgetsig(&pipesig);


	return((short) fd);
}
Esempio n. 21
0
/* wait for the response from the newsserver */
int news_receive(int cn, char *file, int file_reqd)
{
	/* copied from http_get in CABCOVL.C  */
	int16 x, bytes_available, eof=0;
	long bytes_read=0,rc;
	int return_code=0;
	int file_handle, status=0, header_pos=0;
	time_t timeout,kicker,total;
	int bug=0;
	int sbuf=sizeof(buffer);

	if (file_reqd) {
		file_handle=(int) Fcreate(file, 0);
		if (bug) {
			fprintf( log, "news_receive - opening file = %d\n", file_handle );
			fflush( log );
		}
		if (file_handle<0) {
			#ifdef ERR_MSGS
				printf("Couldn't create %s!\n", file);
			#endif
			return(1);
		}
	}
	total=clock();					/* total time in routine */
	timeout=clock()+max_to*CLK_TCK;	/* timeout */
	kicker=clock()+kick*CLK_TCK;		/* conversation kicker */
	if (file_reqd) {
		browser->msg_status(2,0); /* Getting data... */
	}
	if (file_reqd==2) { status=2; }

	while (eof==0) {
		bytes_available=CNbyte_count(cn);
		/* printf("received %d bytes \n", (long)bytes_available ); */

		if (handle_escape_events()==27) { eof=4; }
		/*
		if (Bconstat(2)==-1 && (Bconin(2) & 0xFF)==27) { eof=4;	}
		*/
		if (clock()>timeout) {
			#ifdef MDEBUG
				printf("Timeout!\n");
			#endif
			eof=2;
		} else if (clock()>kicker) {
			#ifdef MDEBUG
				printf("Kick Connection!\n");
			#endif
			CNkick(cn);
			kicker=clock()+kick*CLK_TCK;	/* conversation kicker */
		} else if (bytes_available==E_EOF) {
			#ifdef MDEBUG
				printf("EOF!\n");
			#endif
			eof=1;
		} else if (bytes_available<E_NODATA) {
			#ifdef ERR_MSGS
				printf("CNbyte_count() returns: %s\n", get_err_text(bytes_available));
			#endif
			eof=3;
		} else if (bytes_available>0) {
			timeout=clock()+char_to*CLK_TCK;	/* timeout after last char */
			kicker=clock()+kick*CLK_TCK;		/* conversation kicker */
			if (status==2) {
				if (bytes_available>sbuf) { bytes_available=sbuf; }
				if (CNget_block(cn, buffer, bytes_available)>=E_NODATA) {
					rc = Fwrite(file_handle, bytes_available, &buffer);
					if (rc!=bytes_available) { 	/* didn't write everything */
						file_write_error(rc);
						Fclose(file_handle);
						return(1);
					}
					bytes_read+=bytes_available;
					if (bug) {
						fprintf( log, "received %d bytes, total %ld\n",
							bytes_available , bytes_read);
						fflush( log );
					} else { browser->msg_status(2, bytes_read); }

				/* look for period (.) on a line by itself */
					if (strncmp(&buffer[bytes_available-5], "\r\n.\r\n", 5)==0 ||
					    strncmp(&buffer[bytes_available-5], "\n\r.\n\r", 5)==0 ||
					    strncmp(&buffer[bytes_available-3], "\r.\r", 3)==0 ||
					    strncmp(&buffer[bytes_available-3], "\n.\n", 3)==0)
					eof=1;
					if (bytes_read==3 &&
					    strncmp(&buffer[bytes_available-3], ".\r\n", 3)==0)
					eof=1;
				} else {
					#ifdef ERR_MSGS
						printf("Error in CNget_block()!\n");
					#endif
					eof=3;
				}
			} else {
				x = CNget_char(cn);
				if (x<E_NODATA) {
					#ifdef ERR_MSGS
						printf("CNget_char() returns: %s\n", get_err_text(x));
					#endif
					eof=3;
				} else
					header[header_pos++]=(char) x;
			}
			/* only an empty line and response line in NNTP responses */
			/* when status = 0, drop until valid non-control, when = 1, store in header */
			if (status==0) {
				if (strncmp(&header[header_pos-1], " ", 1)<0) {
					header_pos = 0;
				} else { status++;}
			}
			if (status==1) {
				if (strncmp(&header[header_pos-2], "\r\n", 2)==0 ||
				    strncmp(&header[header_pos-2], "\n\r", 2)==0) {
				/*	strncmp(&header[header_pos-1], "\r", 1)==0 ||
				    strncmp(&header[header_pos-1], "\n", 1)==0) { */
					header[header_pos-2]=0;
					if (log_resp=='Y') { fprintf( log, "%s\n", header ); fflush(log); }
					#ifdef MDEBUG
						printf("Header: %s\n", header );
						printf("End of header.\n");
					#endif
					if (!file_reqd) { eof=1; } else { status++; }
					if (memcmp(header,"423",3)==0) { eof=1; }
				} else if (header_pos>2000) {
					rc = Fwrite(file_handle, header_pos, header);
					if (rc!=header_pos) { 	/* didn't write everything */
						file_write_error(rc);
						Fclose(file_handle);
						return(1);
					}
					status++;
				}
			}
		}
	}
	#ifdef MDEBUG
	printf("EOF= %d \n", (long)eof );
	#endif

	if (eof>1) {	/* timeout or worse*/
	/*	x = (int16)TCP_close(cn, 2);
		if (x < 0) {
			#ifdef MDEBUG
				printf("TCP_close() returns: %s\n", get_err_text(x));
			#endif
		} 
	*/
		if (bug) {
			fprintf( log, "news_receive - error - eof = %d\n", eof );
			fflush( log );
		}	
		if (file_reqd) {
		#ifdef MDEBUG
			printf("Fclose returns %i\n", Fclose(file_handle));
		#else
			/**** I might get a bug here! ****/
			if((x=(int16)Fclose(file_handle))<0) {
				#ifdef ERR_MSGS
					printf("Error with Fclose! (%i)\n", x);
				#endif
			}
		#endif
			if (bug) {
				fprintf( log, "news_receive - error - closing file = %d\n", x );
				fflush( log );
			}
		}
		if (eof==3) { eof=bytes_available; }  /* return negative value */
		return(eof);
	}	

	if (file_reqd) {
		if (log_data=='Y') {
			total=clock()-total;	/* total time in clock ticks */
			if (total) {
				fprintf( log, "Transfer Rate = %ld cps\n", (bytes_read*CLK_TCK)/total ); fflush(log);
			}
		}
		#ifdef MDEBUG
			printf("Fclose returns %d\n", Fclose(file_handle));
		#else
			if((x=(int16)Fclose(file_handle))<0)	browser->msg_error(x);
		#endif
		if (bug) {
			fprintf( log, "news_receive - good - closing file = %d\n", x );
			fflush( log );
		}
	}
	#ifdef MDEBUG
		printf("Hit a key.\n");
		Bconin(2);
	#endif
	return(return_code);	/* return(0)     if getting data was successful,	 */
        					/* return(errno) if it fails, return an error number */
}
Esempio n. 22
0
bool TapRecognizer::onTouchBegan(CCTouch *touch, CCEvent *pEvent)
{
    touchStart->setObject(Fcreate(TIME), touch->getID());
    touchInitialPosition.insert(std::make_pair(touch->getID(), Scene::touchPosition(touch)));
    return true;
}
Esempio n. 23
0
int
main(int argc, char **argv)
{
    long size[NUMFILES];
    long totsize;
    char buf[20], name[40];
    byte *inbuf, *ptr;
    byte *outbuf;
    long outsize;
    int i, fd;
    DTA *dt;
    int compress, noheader;
    int interactive = 1;

    dt = (DTA *)Fgetdta();

    compress = 0;
    noheader = 0;

    printf("\nSuperglue v1.0\n");
    while (argc > 1) {
        ptr = (byte *)argv[1];
        argv++;
        --argc;
        if (*ptr == '-') {
            ptr++;
            switch (*ptr) {
            case 'c':
                compress = 1;
                i = atoi(ptr+1);
                if (i) gl_matchsize = i;
                break;
            case 'n':
                noheader = 1;
                break;
            default:
                printf("usage: superglu [-n][-c#] [extension]\n");
                break;
            }
        } else {
            interactive = 0;
            break;
        }
    }

    puts(compress ? "COMPRESSING resources" : "storing resources" );
    if (interactive) {
        printf("\nPlease enter the 3 letter country abbreviation, or\n");
        printf("type 'exit' to quit\n");
    }

    do {
        totsize = HEADERSIZE;
        if (interactive) {
            printf("> ");
            fflush(stdout);
            gets(buf);
            if (strlen(buf) > 3) break;
        } else {
            strcpy(buf, *argv);
        }

        /* first, find the sizes of the pieces */
        for (i = 0; i < NUMFILES; i++) {
            sprintf(name, fname[i], buf);
            if (Fsfirst(name, 0) != 0) {
                printf("%s: not found\n", name);
                goto top;
            }
            size[i] = dt->dta_size;
            /* we round all file sizes up to the next even number when we
             * read them into memory, so everything will be on a word boundary
             */
            totsize += ROUND(size[i]);
        }


        ptr = inbuf = (byte *)Malloc( totsize );
        if (!inbuf) {
            printf("not enough memory: couldn't allocate %ld bytes\n",
                   totsize);
            goto top;
        }

        ptr += HEADERSIZE;

        /* now, go read the files */
        for (i = 0; i < NUMFILES; i++) {
            sprintf(name, fname[i], buf);
            fd = Fopen(name, 0);
            if (fd < 0) {
                printf("couldn't open %s\n", name);
                Mfree(inbuf);
                goto top;
            }
            puts(name);
            if (Fread(fd, size[i], ptr) != size[i]) {
                printf("Error during read\n");
                Mfree(inbuf);
                Fclose(fd);
                goto top;
            }
            Fclose(fd);
            ptr += ROUND(size[i]);
            /* fill in the size in the header */
            ((long *)inbuf)[i] = ROUND(size[i]);
        }

        /* OK, now write the result */
        sprintf(name, "glue.%s", buf);
        fd = Fcreate(name, 0);
        if (fd < 0) {
            printf("couldn't create %s\n", name);
            Mfree(inbuf);
            goto top;
        }

        if (compress) {
            outbuf = (byte *)Malloc( totsize * 2 );
            if (!outbuf) {
                printf("NO MEMORY FOR COMPRESSION!!\n");
                printf("storing resource instead\n");
                compress = 0;
            }
        }
        if (compress) {
            magic[0] = 0xab;
            magic[1] = 0x08;
            outsize = crunch(inbuf, totsize, outbuf);
        } else {
            outbuf = inbuf;
            outsize = totsize;
            magic[0] = magic[1] = 0;
        }
        printf("Writing %s...\n", name);

        /* first, the file header */
        if (!noheader) {
            Fwrite(fd, 2L, magic);
            Fwrite(fd, 4L, &totsize);
            Fwrite(fd, 4L, &outsize);
        }

        /* now write the data */
        if (Fwrite(fd, outsize, outbuf) != outsize) {
            printf("write error!\n");
        }

        Fclose(fd);
        Mfree(inbuf);
        if (compress) Mfree(outbuf);
top:
        ;
    } while (interactive);

    return 0;
}
Esempio n. 24
0
/*---------------------------------------------------*/
void save()
{
long file1;
int file;
int n,ba,colm,bank;
char *bootprg;
long bootlen;

if (!(bootprg=(char*)malloc(16384)))
	{
	alert(ERROR1);return;
	}
file1=Fopen(boot_prg_name,0);
if (file1<0)
{
	alert(ERROR1);free(bootprg);return;
}
file=(int)file1;
bootlen=Fread(file,16384,bootprg);
Fclose(file);

for (n=0;n<5;n++)
{
ba=(rs_object[COL2R1+5*n].ob_state==SELECTED)+
	2*(rs_object[COL2R2+5*n].ob_state==SELECTED);
	
if (ba==0)
		{ if (*(int*)(bootprg+0x20+n*2*128)!=2)
			*(int*)(bootprg+0x20+n*2*128)=1;
			if (*(int*)(bootprg+0x20+(n+5)*2*128)!=2)
			*(int*)(bootprg+0x20+(n+5)*2*128)=1;
		}
else
	if (ba==1)
		{
		*(int*)(bootprg+0x20+n*2*128)=0;
		*(char*)(bootprg+0x20+10*2*128+n)=0;
		if (*(int*)(bootprg+0x20+(n+5)*2*128)!=2)
			*(int*)(bootprg+0x20+(n+5)*2*128)=1;
		}
	else
		{
		*(int*)(bootprg+0x20+(n+5)*2*128)=0;
		*(char*)(bootprg+0x20+10*2*128+n)=1;
		if (*(int*)(bootprg+0x20+(n)*2*128)!=2)
			*(int*)(bootprg+0x20+(n)*2*128)=1;
		}
}
	for(n=0;(n<5)&&(_GemParBlk.global[10]!=planetab[n]);n++); /*nplanes */

	colm=n;
	bank=(rs_object[COL2R1+5*colm].ob_state==SELECTED?
		0:(rs_object[COL2R2+5*colm].ob_state==SELECTED?1:-1));
		
	if (bank!=-1)
	{
		*(int*)(bootprg+0x20+64+256*colm+bank*5*256+0x2a)=(rs_object[SAVER].ob_state&SELECTED?0x100:0);
		/*if (*(long*)(bootprg+0x20+64+256*colm+bank*5*256+0x26)<=(10L*200L))
			*(long*)(bootprg+0x20+64+256*colm+bank*5*256+0x26)=300L*200L;*/
	}
file1=Fcreate(boot_prg_name,0);
if (file1<0)
	{
	alert(ERROR1);free(bootprg);return;
	}
	file=(int)file1;
if (Fwrite(file,bootlen,bootprg)!=bootlen)
	{
	alert(ERROR1);
	}
	
Fclose(file);
free(bootprg);
 }
Esempio n. 25
0
copy_dir ()       /* source und dest sind global; bei Fehler: return (1) */
{
int source_len, dest_len, fd_source, fd_dest, error;
char dta[44];
long old_dta, fail, size, count;
   error=0;
   source_len=strlen(source);
   dest_len=strlen(dest);
   old_dta=Fgetdta();
   Fsetdta(dta);
   strcat(source,"\\*.*");
   fail=Fsfirst(source,16);
   source[source_len]=0;
   while (!fail)
   {  strcat(source,"\\");
      strcat(source,dta+30);
      strcat(dest,"\\");
      strcat(dest,dta+30);
      if (dta[21]==16)         /* Directory */
      {  if (strcmp(dta+30,".")&&strcmp(dta+30,".."))
            if (Dcreate(dest))
            {  printf("Ordner %s l„žt sich nicht anlegen.\n",dest);
               error=1;
            }
            else
               error|=copy_dir(source,dest);
      }
      else                     /* File */
      {  printf("%s  nach  %s\n",source,dest);
         if ((fd_source=Fopen(source,0))<0)
         {  printf("Datei %s l„žt sich nicht ”ffnen.\n",source);
            error=1;
         }
         else
            if ((fd_dest=Fcreate(dest,dta[21]&~1))<0)
            {  printf("Datei %s l„žt sich nicht einrichten.\n",dest);
               error=1;
            }
            else
            {  size=*(long*)(dta+26);
               while (size)
               {  count=(size<buf_size)?size:buf_size;
                  size-=count;
                  if (Fread(fd_source,count,buffer)!=count)
                  {  printf("Fehler beim Lesen von %s .\n",source);
                     error=1;
                     break;
                  }
                  if (Fwrite(fd_dest,count,buffer)!=count)
                  {  printf("Fehler beim Schreiben von %s .\n",dest);
                     error=1;
                     break;
                  }
               }
               Fclose(fd_source);
               Fclose(fd_dest);
               fd_dest=Fopen(dest,1);
               Fdatime(fd_dest,dta+22,1);
               Fclose(fd_dest);
            }
      }
      source[source_len]=0;
      dest[dest_len]=0;
      fail=Fsnext();
   }
   if (fail!=-49l)
   {  printf("Ordner %s nicht gefunden.\n",source);
      error=1;
   }
   Fsetdta(old_dta);
   return (error);
}
Esempio n. 26
0
/* Save_Data()
 * ======================================================================
 */
BOOLEAN
Save_Data( void )
{
    DTA  thedta, *saved;
    int  fd;
    int  *DataPtr;
    long EndIndex;
    BOOLEAN flag;

    flag = FALSE;
    saved = Fgetdta();
    Fsetdta( &thedta );
    if( Fsfirst( FPath, 0 ) <= -1 ) /* Can't find the file... */
    {
        Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
        form_alert( 1, alert2 );
    }
    else
    {
        DataBuf = calloc( 1, thedta.d_length * 2L );

        if( DataBuf )
        {
            fd = Fopen( FPath, 0 );
            if( fd <= 0 )
            {
                form_alert( 1, alert1 );
            }
            else
            {
                Buffer = ( long )DataBuf;
                Buffer = ( Buffer + 15L ) & 0xFFFFFFF0L;
                DataHdr = ( int *)Buffer;

                Fread( fd, thedta.d_length, DataHdr );
                Fclose( fd );

                EndIndex = thedta.d_length;
                DataPtr  = FindString( DataHdr, DataHdr + EndIndex - 8 );
                if( DataPtr )
                {
                    hdr = ( HEADER *)DataPtr;

                    hdr_buffer.quality    = Menu[ MQUALITY ].curvalue;
                    hdr_buffer.nplanes    = Menu[ MCOLOR ].curvalue + 1;
                    hdr_buffer.PageSize   = Menu[ MPAGESIZE ].curvalue;
                    hdr_buffer.xres       = xres_value;
                    hdr_buffer.yres       = yres_value;
                    hdr_buffer.port       = Menu[ MPORT ].curvalue;
                    hdr_buffer.paper_feed = Menu[ MTRAY ].curvalue;

                    *hdr = hdr_buffer;

                    flag = TRUE;
                    fd = Fcreate( FPath, 0 );
                    Fwrite( fd, thedta.d_length, DataHdr );
                    Fclose( fd );
                }
                else
                {
                    Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
                    form_alert( 1, alert3 );
                }
                free( DataBuf );
            }
        }
        else
            form_alert( 1, alert4 );
    }
    Fsetdta( saved );
    return( flag );
}
Esempio n. 27
0
do_batch(void)
{
int hd,sec,hd2;
char line[80],*l;
long timer;

    if (fsel("*.TTB",tbuf,"Batch starten") == 1){
        if ((hd=Fopen(tbuf,0)) > 0) {
            while (readline(hd,line)){
                l=line;
                while (*l++ > 32);
                *(l-1)=0;
                strupr(line);
                if (!strcmp(line,"DIAL")) {
                    if (call_modem(-1,l)) break;
                    else continue;
                }
                if (!strcmp(line,"WAIT")) {
                    sec=atoi(l);
                    timer=get_timer();
                    while ((get_timer()-timer) < (sec*200))
                        evnt_timer(0,0);
                    continue;
                }
                if (!strcmp(line,"RWAIT")) {
                    if (rwait(l) == 0) continue;
                    else break;
                }
                if (!strcmp(line,"SEND")) {
                    while(*l) send(*l++);
                    send(13);
                    continue;
                }
                if (!strcmp(line,"END")) {
                    break;
                }
                if (!strcmp(line,"BAUDRATE")) {
                    continue;
                }
                if (!strcmp(line,"UPLOAD")) {
                    if (*l == 'X') {
                        para.blklen=128;
                        para.chk=CHKSUM;
                    }
                    if (*l == 'Y') {
                        para.blklen=1024;
                        para.chk=CRC;
                    }
                    while (*l++ > 32);
                    *(l-1)=0;
                    open_dial(1);
                    if ((hd2=Fopen(l,0)) > 0) {
                        send_xmodem(hd2);
                        Fclose(hd2);
                    }
                    open_dial(0);
                }   
                if (!strcmp(line,"DOWNLOAD")) {
                    if (*l == 'X') {
                        para.blklen=128;
                        para.chk=CHKSUM;
                    }
                    if (*l == 'Y') {
                        para.blklen=1024;
                        para.chk=CRC;
                    }
                    while (*l++ > 32);
                    *(l-1)=0;
                    open_dial(1);
                    if ((hd2=Fcreate(l,0)) > 0) {
                        receive_xmodem(hd2);
                        Fclose(hd2);
                    }
                    open_dial(0);
                }   
            }
            Fclose(hd);
        }
    }
}
Esempio n. 28
0
static void dumpFile(int16 cnId, char fileNam[], long fileLen)
{
	int eFlag;
	char *eM;
	long accuLen;
	int fh;
	int16 nInQueue;
	clock_t tQuit;

#if 0
uiPrintf(uiH, "   %s|L: %ld|N: %s", pCnt, fileLen, fileNam);
#endif
	if ( (fh=Fcreate(fileNam, 0)) < 0 ) {
		uiPrintf(uiH, uiPrERR, "dumpFile|cannot create file");
		return;
	}


	for (eFlag=1,accuLen=0; eFlag; ) {
		tQuit = clock() + LTIMEOUT * CLK_TCK;	/* time to quit at */

		while ( (nInQueue = CNbyte_count(cnId)) == 0 || nInQueue == E_NODATA) {
			if (clock() > tQuit) {
		        eM="timed out"; goto errExit;
			}
			uiYield(uiH, YIELDMS);		/* wait till something arrives */
		} 
	
	
		if (nInQueue > 0) {
			NDB* ndb;
	
			if ( (ndb = CNget_NDB(cnId)) != NULL ) {
				accuLen += ndb->len;
#if 0
uiPrintf(uiH, "al: %ld", accuLen);
#endif
				if (accuLen == fileLen+1) {		/* this happens at the end */
					if (Fwrite(fh, ndb->len-1, ndb->ndata) <0) {
						eM="cannot write 1"; goto errExit;
					}
					if (ndb->ndata[ndb->len-1] != '\0') {
						eM="trailing 0 ?"; goto errExit;
					}
					eFlag=0;						/* normal end */
				} else {
					if (accuLen > fileLen+1) {	/* this should never happen */
						eM="prot.mismatch"; goto errExit;
					} else {
						if (Fwrite(fh, ndb->len, ndb->ndata) <0) {
							eM="cannot write 2"; goto errExit;
						}
					}
				}
				KRfree(ndb->ptr); KRfree(ndb);	/* throw ndb away */

			} else {
		        eM="get_NDB"; goto errExit;
			}	/* if..get_NDB successful */

		} else {
			eM=get_err_text(nInQueue); goto errExit;
		}	/* if..something in Queue */

	}	/* while..more blocks to read */


	Fclose(fh);
	return;

errExit:
	uiPrintf(uiH, uiPrERR, "dumpFile|%s", eM);
	Fclose(fh);
}	/* dumpFile */
Esempio n. 29
0
WORD
wrfile( char *fstr )
{
	REG int 	ret, retmsg;
	int 		inhand,outhand;
	int		time[2];
	DMABUFFER 	*mydta, *saved;
	char 		*buffer;
	long 		copysiz, bufsiz, wrsiz, tmpsiz; 
	int 		crted,sttime;
	char		buf[2];

	crted = 0;
	sttime = 1;
	retmsg = TRUE;
	rename = 0;
open:					/* open the source file	*/
	if ( ( inhand = (WORD)Fopen(fixsrc, 0) ) < 0 )		
	{				/* seek error or drive not ready */	
/*	  if ( (inhand == E_SEEK) || (inhand == EDRVNR) )
	    return( FALSE );
*/					/* skip	*/
	  if ( ( ret = fill_string( fixsrc, CNTOPEN ) ) == 1 )
	  {
	    updatnum(NUMFILE, --numfiles);
	    return SKIP;
	  }
	  else if (ret == 2)			/* retry */
		  goto open;
		else 				/* abort */
		  goto ww_3;
	}

	if ( !ch_undo() || f_cancel )		/* user want to stop */
	{
	  Fclose( inhand );
ww_3:	  f_abort = 1;
	  return( FALSE );
	}		  

	saved = (DMABUFFER *)Fgetdta();
	Fsetdta(mydta=(DMABUFFER *)malloc( (long)sizeof(DMABUFFER)));

	if ( Fsfirst( fixsrc, 0x37 ) )	
	{
	   retmsg = SKIP;
	   if ( do1_alert( RDERROR ) == 2 )	/* abort */
	   {
	     f_abort = 1;
	     retmsg = FALSE;
	   }
	   goto y2;
	}

	copysiz = mydta->d_fsize;
	buffer = (char *)malloc( copysiz );
	if ( buffer )
	{
	  bufsiz = copysiz;
	}
	else
	{
	  for (bufsiz = 128*1024L; bufsiz >= 1024L; bufsiz /= 2)
	  {
	    if ((buffer = (char *)malloc( bufsiz )) != 0)
	      break;
	  }
	  if (!buffer)
	    goto y2;
	}
  
	Fdatime( &time, inhand, 0 );	/* read the time and date */

rechkd:
	switch(chkdf(fstr, CPFILE))
	{
	    case CHECK:	
	      goto rechkd;

	    case SKIP:	
	      retmsg = SKIP;	
	      goto y1;

	    case QUIT:	
	      f_abort = 1;
	      retmsg = FALSE;
	      goto y1;

	    case FALSE:	
              retmsg = FALSE;
	      goto y1;
	}


	/* if it is move operation, then try rename first	*/

	if ( opcode == OP_MOVE )
	{			/* if same name and path, don't do it */
	  if ( strcmp( fixsrc, fixdst ) )
	    goto y22;
	
	  Fclose( inhand );

	  if ( Frename(0, fixsrc, fixdst) >= 0 )
   	  {	
	    inhand = (WORD)Fopen( fixdst, 0 );
	    if ( !p_timedate )		/* get the new time and date */
	    {
	      time[0] = Tgettime();
	      time[1] = Tgetdate();
	      Fdatime( &time, inhand, 1 ); 	
	    }
y22:	    
	    rename = 1;
	    goto y1;
	  }
	  else
	    inhand = (WORD)Fopen( fixsrc, 0 );		
	}


	while ( copysiz >= 0 ) 	/* let it passes through for zero file */
	{
	  tmpsiz = (copysiz > bufsiz) ? bufsiz : copysiz;
	  if (Fread(inhand, tmpsiz, buffer) < 0)	
	  {
	    retmsg = SKIP;
	    if ( crted )	
	      Fdelete( fixdst );

	    if (do1_alert( RDERROR ) == 2)	
	    {					/* abort */
	      f_abort = 1;
	      retmsg = FALSE;
	    }
	    goto y1;			/* skip */
	  }




create:
	  if ( sttime )
	  {
	    sttime = 0;

	    if ((outhand = (WORD)Fcreate(fixdst, mydta->d_fattr&7)) < 0)	
	    {
	      if ( ( ret = fill_string( fixdst, CNTCRTFL ) ) == 2 )
		goto create;

	      else if (ret == 3)				/* abort */
	      {
		 f_abort = 1;
		 retmsg = FALSE;
	      }
	      else	
		retmsg = SKIP;

	      goto y1;
	    }

	    crted = 1;
	  }

	  if ((wrsiz = Fwrite(outhand, tmpsiz, buffer)) < 0)	
	  {
	     retmsg = SKIP;
	     Fclose(outhand);
	     Fdelete(fixdst);

	    if (do1_alert( WRERROR ) == 2)	
	    {					/* abort */
	      f_abort = 1;
	      retmsg = FALSE;
	    }

	    goto y1;
	   }
				/* check if there are sufficent memory */
	   if (wrsiz != tmpsiz)		
	   { 			/* not sufficent memory ??*/
	      f_abort = 1;
	      retmsg = FALSE;
	      Fclose(outhand);	
	      Fdelete(fixdst);
	      buf[0] = *fixdst;
	      buf[1] = 0;
	      fill_string( buf, STDISKFU );
	      goto y1;
	   }

	   copysiz -= tmpsiz;
	   if ( !copysiz )
	     break;
	}

	if ( p_timedate )
	  Fdatime( &time, outhand, 1 );	

y0:
	Fclose(outhand);
y1:
	free(buffer);
y2:
	updatnum(NUMFILE, --numfiles);
	Fsetdta(saved);
y3:
	Fclose(inhand);
	free(mydta);

	if ( ( opcode == OP_MOVE ) && ( retmsg == TRUE ) )
	  upfdesk( fixsrc, fixdst );
	
	return(retmsg);
}