Example #1
0
static unsigned long depackedlen(const unsigned char *p, unsigned long plen) {
/*	DSA1/ROA1 doesn't use the first bytes as a signature "PP20".
 *	It's used instead for the lenght of the packed data. */

	if (p[0] == 'P' && p[1] == 'P' && p[2] == '2' && p[3] == '0')
		return val(p+plen-4);

	if (readd((Bit8u*)p) == plen)
		return val(p+plen-4);

	if (readd((Bit8u*)p) + 8 == plen)
		return val(p+plen-4);

	return 0; /* not a powerpacker file */
}
Example #2
0
/* \fcnfh
   ask for a positive double value from stdin with the question 'fmt';
   to stderr
*/
double
askforposd(char *fmt,		/* Question asked */
	   ...)			/* parameters for the question if any */
{
  va_list ap;
  va_start(ap,fmt);
  double val;
  char rc;

  while(1){
    vfprintf(stderr,fmt,ap);
    val=readd(stdin,&rc);
    if(rc=='q'){
      fprintf(stderr,"User interrupt!\n");
      exit(EXIT_SUCCESS);
    }
    if(val<=0)
      fprintf(stderr," Invalid value %g, it has to be positive\n",val);
    else if(!rc)
      break;
    fprintf(stderr,"Try again!\n");
  }
  va_end(ap);

  return val;
}
Example #3
0
int do_list(u8 * dir){
	s8 fd,ret;
	struct fnode fn;
	int i;
	u8 size;
	struct dir_str dira[256];
    u8 full_name[132];// fullpath name  of child
	if (!check_for_args(LIST,1)) return 1;
	fd = opend(dir);
	if (fd == -1){
		vd_puts("CANNOT OPEN DIRECTORY:: ");vd_puts(dir);vd_puts("\n");
				errormessage(geterror());
				fl_clean();
		return 1;
	}
	ret = finfo(fd,&fn);
	if (ret == -1){
		vd_puts(" CANNOT OPEN DIRECTORY::");vd_puts(dir);vd_puts("\n");
		errormessage(geterror());
		fl_clean();
		return 1;
	}
	size = fn.ct_links;
	ret=readd(fd,size+2,dira);
	if (! ret){
		vd_puts(" CANNOT READ THE DIRECTORY\n");
				errormessage(geterror());
				fl_clean();
		return 2;
	}
	for(i=0; i < size+2 ; i++){
#ifdef COLOR_LIST 
        strcpy(full_name,dir);
        strcat(full_name,"|");
        strcat(full_name,dira[i].name);
        if ( !strcmp(dira[i].name,".") || ! strcmp(dira[i].name,"..") ){
            textcolor(YELLOW);
            cprintf("%s\n\r",dira[i].name);
            textcolor(WHITE);
            continue;
        }
        if ( is_dir(full_name) ){
            textcolor(YELLOW);
            cprintf("%s\n\r",dira[i].name);
            continue;
        }
        textcolor(BLUE);
        cprintf("%s\n\r",dira[i].name);
#else
        printf("%s\n",dira[i].name);
#endif
    }
    textcolor(WHITE);
    fl_clean();
	return 0;
}
Example #4
0
	int veryLong::rd(char *inputFile)
	{
		lenght=readd(&number,inputFile,&znak);
		return 0;
	}
Example #5
0
int main(int argc, char *argv[])
{
    char *inputFirst,*inputSecond,*inputThird;
    FILE *output;
    int lenghtFirst,lenghtSecond,i,binary,module,lenghtModule;
    unsigned char *numberOne,*numberTwo,*ostatok,*numModule;
	unsigned char znak1,znak2,znak3;
	char znak;
	if (argc < 5 )
	{
		printf("\nEnter correct parameters\n");
		return 0;
	}
	if (argc == 7)
	{
		binary=1;
		module=1;
		inputThird=argv[6];
		lenghtModule = readb(&numModule,inputThird);
	}
	if (argc == 6)
	{
		if (strcmp(argv[5],"-b") == 0)
		{
			binary=1;
			module=0;
		}
		else
		{
			binary=0;
			module=1;
			inputThird=argv[5];
			lenghtModule = readd(&numModule,inputThird,&znak3);
		}
	}
	if (argc < 6)
	{
		binary=0;
		module=0;
	}
    
    
	inputFirst =argv[1];
    inputSecond=argv[3];
    
    if(!binary)
    {
        
        output = fopen(argv[4],"w");
    }
    else
    {
        output = fopen(argv[4],"wb");
    }
    
	znak=argv[2][0];
	switch(znak)
	{
		case '+' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((znak1=='+')&&(znak2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((znak1=='-')&&(znak2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
				if ((znak1=='+')&&(znak2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((znak1=='-')&&(znak2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=summb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '-' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((znak1=='+')&&(znak2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((znak1=='-')&&(znak2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
				if ((znak1=='+')&&(znak2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((znak1=='-')&&(znak2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=subb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '*' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				if (((znak1=='+')&&(znak2=='+'))||((znak1=='-')&&(znak2=='-')))
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
				}
				else
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=mulb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '/' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				if (((znak1=='+')&&(znak2=='+'))||((znak1=='-')&&(znak2=='-')))
				{
					fprintf(output,"%s",divv(&numberOne,&numberTwo,&ostatok));
				}
				else
				{
					fprintf(output,"-%s",divv(&numberOne,&numberTwo,&ostatok));
				}
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lenghtFirst);
				turnb(&numberTwo,lenghtSecond);
				numberOne=divvb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst,&ostatok,&lenghtSecond);
				turnb(&numberOne,lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
            
		case '%' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				divv(&numberOne,&numberTwo,&ostatok);
				fprintf(output,"%s",ostatok);
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lenghtFirst);
				turnb(&numberTwo,lenghtSecond);
				divvb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst,&ostatok,&lenghtSecond);
				turnb(&ostatok,lenghtSecond);
				fwrite(ostatok,lenghtSecond,1,output);
				free(ostatok);
			}
			break;
            
		case '^' :
			if (!binary)
			{
				lenghtFirst = readd(&numberOne,inputFirst,&znak1);
				lenghtSecond = readd(&numberTwo,inputSecond,&znak2);
				turn(&numberOne);
				turn(&numberTwo);
				numberOne=stepen(&numberOne,&numberTwo,&znak1);
				turn(&numberOne);
				if (znak1=='+')
					fprintf(output,"%s",numberOne);
				else
					fprintf(output,"-%s",numberOne);
			}
			else
			{
				lenghtFirst = readb(&numberOne,inputFirst);
				lenghtSecond = readb(&numberTwo,inputSecond);
				numberOne=stepenb(&numberOne,&numberTwo,lenghtFirst,lenghtSecond,&lenghtFirst);
				fwrite(numberOne,lenghtFirst,1,output);
			}
			break;
		default:
			break;
	}
    
    fclose(output);
    
	if (module)
	{
		if(!binary)
		{
			output = fopen(argv[4],"w");
			divv(&numberOne,&numModule,&ostatok);
			fprintf(output,"%s",ostatok);
		}
		else
		{
			output = fopen(argv[4],"wb");
			turnb(&numberOne,lenghtFirst);
			turnb(&numModule,lenghtModule);
			divvb(&numberOne,&numModule,lenghtFirst,lenghtModule,&lenghtFirst,&ostatok,&lenghtModule);
			turnb(&ostatok,lenghtModule);
			fwrite(ostatok,lenghtModule,1,output);
		}
		fclose(output);
	    
	}
    return 0;
}
Example #6
0
/**
 *	load_ani() -	loads an animation
 *	@nr:	number of the animation
 */
void Cseg027::load_ani(const signed short nr)
{
	struct sm_file smf;
	unsigned short bytes;
	Bit32u off_imdata, off_palette;
	Bit16u width, height;

	Bit8u compression_type;
	Bit8u palette_size;
	Bit8u num_elements;
	int off_elements;
	Bit8u* ptr_elements;
	
	//signed int area_size;
	int len;
	signed int len_3, len_4;
	unsigned int offset, offset_2;
	Bit8u *dst, *p6;
	int ani_off, ani_len;/*
	Bit8u *p5;
	signed int p4;
	signed int p3;*/
	Bit8u *p2;
	Bit8u *p1;
	Bit32u ani_buffer;
	Bit8u *ani_main_ptr;
	Bit8u *palette_ptr;
	/*
	unsigned short ems_handle;
	Bit8u *p_area;
	unsigned short i;
	unsigned short fd;
	signed short area_changes;
	signed short area_pics;
	unsigned short i_area;
	signed short di;


	/* sanity check */
	if (nr == -1)
		return;
	if (nr > 36)
		return;

	/* no need to reload  the same ani*/
	//if (nr == globvars->current_ani)
	//	return;

	//ds_writew(0x29ae, 0);
	/* set the new ani nr*/
	globvars->current_ani=nr;
	/* clear the old ani */
	//clear_ani();    seg004

	if (!anis_loaded[nr-1]){
		/* load ANIS.TAB */
		load_archive_file(0x17,&smf);
		bytes = read_archive_file(&smf, buffer, 148);
		fclose(smf.fd);

		ani_off = readd(buffer - 4 + nr * 4);
		ani_len = readd(buffer + nr * 4) - ani_off;

		/* load ANIS */
		load_archive_file(0x16,&smf);//fd = load_archive_file(0x16);
		/* seek to ordered ani */
		fseek(smf.fd, smf.off + ani_off, SEEK_SET);//seg002_0c72(fd, ani_off);
	
		bytes = read_archive_file(&smf, buffer,	(unsigned short)ani_len);//fd, Real2Host(ds_readd(0xc3db)),
		fclose(smf.fd);

		off_imdata = readd(buffer);//ds_readd(0xc3db);
		off_palette = readd(buffer+4);
		width = readw(buffer+8);
		height = readb(buffer+10);
		num_elements = readb(buffer+11);

		//für jedes Element:
		off_elements = readd(buffer+12);
	
		ptr_elements = buffer + off_elements;
		//posx = readw(ptr_elements+4);
		//posy = readb(ptr_elements+6);
		//width = readb(ptr_elements+7);
		//height = readb(ptr_elements+8);
		//anz = readb(ptr_elements+11);
		//for i<anz
		//posx = readb(ptr_elements+12+i*4);
		//posy = readb(ptr_elements+12+i*4+1);
		
		//anzanim = readw(ptr_elements+12+anz*4);
		//for i<anzanim
		//index = readw(ptr_elements+12+anz*4 + 4*i);
		//delay = readw(ptr_elements+12+anz*4 + 4*i+2);

		
		
		
		
		
		

		/* set start of picture data */
		ani_main_ptr = buffer + off_imdata;
		//ds_writed(ANI_MAIN_PTR,
			//host_readd(Real2Host(ds_readd(0xc3db))) + ani_buffer);
		/* set start of palette */
		
		palette_ptr = buffer + off_palette + 6;//palette ist hier  //??? src_rle = ani_main_ptr + readd(buffer+4) + 6;
		//ds_writed(0xce3b,
			//host_readd(Real2Host(ds_readd(0xc3db)) + 4) + ani_buffer + 6);
		/* read some bytes between data and palette */
		//word_313A9 = readw(src_rle-6);
		//ds_writew(0xc3e9,
			//host_readw(Real2Host(ds_readd(0xce3b)) - 6));
		//word_313AB = readw(src_rle-4);
		//ds_writew(0xc3eb,
			//host_readw(Real2Host(ds_readd(0xce3b)) - 4));
		/* compression type */
		compression_type = readw(palette_ptr-1);
		//ds_writeb(0xce39,
			//host_readb(Real2Host(ds_readd(0xce3b)) - 1));
		/* palette size*/
		palette_size = readw(palette_ptr-2);
		sm_set_palette(palette_ptr,0,palette_size);
		//ds_writeb(0xce3a,
			//host_readb(Real2Host(ds_readd(0xce3b)) - 2));

		//p6 = src_rle + palette_size * 3; //pointer auf end
		/* set picture size /
00 0d
	ds_writew(0xc3e7, host_readw(Real2Host(ds_readd(0xc3db) + 8)));
87
	ds_writeb(0xc3ed, host_readb(Real2Host(ds_readd(0xc3db) + 10)));
	/* set number of areas /
01
	ds_writeb(0xc3ee, host_readb(Real2Host(ds_readd(0xc3db) + 11)));

		/* Process Main Picture */
		if (compression_type != 0) {
			len_4 = readd(ani_main_ptr);//host_readd(Real2Host(ds_readd(ANI_MAIN_PTR)));
			//p1 = ani_main_ptr;

			//p1 += (len_4 - 4);

			//len_3 = readd(p1);
			//len_3 = swap_u32(len_3) >> 8;
		
			decomp_pp20(ani_main_ptr,gataosao,ani_main_ptr+4,len_4);

			//decomp_pp20(Real2Host(ds_readd(ANI_MAIN_PTR)),
			//	Real2Host(ds_readd(0xd303)),
			//	Real2Host(ds_readd(ANI_MAIN_PTR)) + 4,
			//	len_4);

			//offset = len_3 - len_4;
			//dst = ani_main_ptr;
			//dst += len_4;
			//len = p6 - dst;
//memcpy(p6 + offset, dst, len);

			//memcpy(Real2Host(ds_readd(ANI_MAIN_PTR)),
				//Real2Host(ds_readd(0xd303)), len_3);
//memcpy(ani_main_ptr, gataosao, len_3);
			//dst += offset;
//memcpy(dst, p6 + offset, len);
			//src_rle = src_rle + offset;
			//ds_writed(0xce3b, ds_readd(0xce3b) + offset);
			//p6 += offset;
printf("anis decompressed: %d\n",nr);
		}
		sm_images_init_anis(nr-1,gataosao);
		anis_loaded[nr-1]=true;
printf("anis loaded: %d\n",nr);
	}
	
		
		
	/* Process the Areas */
	//for (i_area = 0; (signed char)ds_readb(0xc3ee) > i_area; i_area++) {
	//for (i_area = 0; i_area < num_elements; i_area++) {
		//p5 = Real2Host(RealMake(datseg, 0xc3ef + i_area * 0x107));
		//p3 = host_readd(Real2Host(ds_readd(0xc3db) + i_area * 4 + 0xc));
		//p_area = Real2Host(ds_readd(0xc3db) + p3);
		//p_area = buffer + off_elements + i_area * 4;
		//strncpy((char*)p5, (char*)p_area, 4);

		//host_writew(p5 + 5, host_readw(p_area + 4));
		//host_writeb(p5 + 7, host_readb(p_area + 6));
		//host_writeb(p5 + 8, host_readb(p_area + 7));
		//host_writew(p5 + 9, host_readw(p_area + 8));
		//host_writeb(p5 + 0x0b, host_readb(p_area + 0x0a));
/*
		area_pics = (signed char)host_readb(p_area + 0x0b);
		host_writeb(p5 + 0x0c, (unsigned char)area_pics);
		if (ds_readb(0xce39) != 0) {

			p4 = host_readd(p_area + 0xc);
			p4 += offset;
			p1 = Real2Host(ds_readd(0xc3db) + p4);

			len_4 = host_readd(p1);
			p1 += (len_4 - 4);
			area_size = host_readd(p1);
			area_size = swap_u32(area_size) >> 8;

			decomp_pp20(Real2Host(ds_readd(0xc3db)) + p4,
				Real2Host(ds_readd(0xd303)),
				Real2Host(ds_readd(0xc3db)) + p4 + 4,
				len_4);

			offset_2 = area_size - len_4;
			offset += offset_2;

			dst = Real2Host(ds_readd(0xc3db));
			dst += p4;
			dst += len_4;
			len = p6 - dst;
			memcpy(p6 + offset_2, dst, (unsigned short)len);

			memcpy(Real2Host(ds_readd(0xc3db)) + p4,
				Real2Host(ds_readd(0xd303)), (unsigned short)area_size);
			dst += offset_2;
			memcpy(dst, p6 + offset_2, (unsigned short)len);
			ds_writed(0xce3b, ds_readd(0xce3b) + offset_2);
			p6 += offset_2;
			area_size = (unsigned char)host_readb(p5 + 8)
				* (signed short)host_readw(p5 + 9);

			for (di = 0; di < area_pics; di++) {
				host_writed(p5 + di * 4 + 0xd,
					ds_readd(0xc3db) + p4 + di * area_size);
			}
		} else {
			for (di = 0; di < area_pics; di++) {
				p4 = host_readd(p_area + di * 4 + 0xc);
				host_writed(p5 + di * 4 + 0x0d,
					ds_readd(0xc3db) + p4);
			}
		}
/*
		area_changes = host_readw(p_area + area_pics * 4 + 0x0c);
		host_writew(p5 + 0x5d, area_changes);

		p2 = p_area + area_pics * 4 + 0x0e;
		for (di = 0; di < area_changes; di++) {
			host_writew(p5 + 0x5f + di * 4,
				host_readw(p2 + di * 4));
			host_writew(p5 + 0x61 + di * 4,
				host_readw(p2 + di * 4 + 2));
		}
	}

	ani_len = p6 - Real2Host(ds_readd(0xc3db));
	/* this is always true /
	if (ani_len > (signed int)ds_readd(0xce43)) {
		ds_writew(0x2ccb, 0xffff);
	}*/
}
Example #7
0
/* ===========================================================================
 * Process a name or wildcard expression to operate on (or exclude).
 * We will only arrive here if we do a Freshen or Delete.
 * Return an error code in the ZEN_ class.
 * ZEN_OK, ZEN_ABORT, ZEN_MISS03, ZEN_MISS04, ZEN_MISS05, ZEN_MEM22, ZEN_MEM23
	*ArgName :: Name to process.
 */
int procname( char *ArgName, bool RecurseDir, struct Globals *pG ) {
	char         *a;       /* path and name for recursion     */
	zDIR         *d;       /* directory stream from opendir() */
	char         *e;       /* pointer to name from readd()    */
	int           m;       /* matched flag                    */
	char         *p;       /* path for recursion              */
	int           pnError; /* ProcName error                  */
	struct stat   StatRes; /* result of stat()                */
	struct zlist *z;       /* steps through zfiles list       */

	// sprintf( ewemsg, "in procname  name=>%s<=  recurse=%d", ArgName, RecurseDir );
	// diag( ewemsg );

	m = 1;  /* set dflt for success indicator (0=success) */

	if ( pG->global_abort_sw )  return ZEN_ABORT;		/* RCV changed was ZEN_MISS? */
	if ( *ArgName == '\0' ) return ZEN_MISS03;

	/* LSSTAT returns 0 if it's arg is any kind of file (even a dir). */
	/* IsShExp returns true if a wildcard symbol is found, or
	 * NULL if none were found -- IsShExp is in util.c
	 */

	if ( LSSTAT( GetFullPath( pG, ArgName ), &StatRes ) || (IsShExp( ArgName ) != NULL) ) {
		// diag( "not a file or dir - 'ArgName' must be a wildcard fspec" );

		// Upon finding a wildcard fspec, we need to mark entries in
		// the "zfiles" list that are included by the wildcard.

		/* convert the "external" (native) filename to an internal
		 * ZIP-archive-compatible filename.
		 */
		p = ex2in( ArgName, (int *)NULL, pG );   /* shouldn't affect matching chars */

		/* does any file already in the archive match this spec? */
		/* Note that we need the pathname and filename together for this */
		for ( z = pG->zfiles; z; z = z->nxt ) {
			if ( dosmatch( p, z->zname, pG ) ) {
				/* name is in archive - mark it for updating */
				z->mark = pG->pcount ? filter( z->zname, pG ) : 1;
				FREE( z->name );	// RCV added + next 8 lines needed for FRESHEN mode.
				if ( (z->name = MALLOC( lstrlen( z->zname ) + 4 )) == NULL ) return ZEN_MEM34;
				z->name[0] = '\0';	//v1.55
				if ( isalpha( ArgName[0] ) && ArgName[1] == ':' && ArgName[2] == '\\') {
					z->name[0] = ArgName[0];
					z->name[1] = ArgName[1];
					z->name[2] = ArgName[2];
					z->name[3] = '\0';
				}
				lstrcat( z->name, z->zname );
				if ( pG->verbose ) printf( "%scluding %s\n", z->mark ? "in" : "ex", z->name );
				m = 0; /* we had at least one file in the archive that we marked */
			}
		}
		FREE( p );

		/* returns 1 if no "zfiles" entries were marked,
		 * 0 if at least one entry was marked
		 */
		if ( m ) {
			// diag( "returning ZEN_MISS04 from procname" );
			return ZEN_MISS04;
		}
		// diag( "returning ZEN_OK from procname" );
		return ZEN_OK;
	} /* end of "if (LSSTAT..." */

	/* Existing and good filename or directory-- add the name if it's a file, recurse if directory */
	// diag( "good entry to add, or a dir to go into" );

	/* check the status returned by LSSTAT earlier to see if 'ArgName' is a dir */
	pnError = ZEN_OK;
	if ( !(StatRes.st_mode & S_IFDIR) ) {
		/* it's not a directory - add file to found list */
		sprintf( pG->ewemsg, "spot 1: Add file %s to found list", ArgName );
		diag( pG->ewemsg, pG );
		/* newname (fileio.c) adds to found list. If error m!=0 on return */
		if ( (m = newname( ArgName, StatRes.st_size, pG )) != ZEN_OK ) {
			sprintf( pG->ewemsg, "returning %d from procname after newname call", m );
			diag( pG->ewemsg, pG );
			return m;
		}
	} else {
		/* It is a directory - Add trailing / to the directory name */
		// diag( "Spot 2, directory found" );
		if ( (p = MALLOC( lstrlen( ArgName )+ 2) ) == NULL ) return ZEN_MEM22;
		if ( !strcmp( ArgName, "." ) || !strcmp( ArgName, "\\." ) ) {		// SLASH
			*p = '\0';  /* avoid "./" prefix and do not create zip entry */
		} else {
			// diag( "spot 3" );
			lstrcpy( p, ArgName );
			a = p + lstrlen( p );
			if ( a[-1] != '\\' ) lstrcpy( a, "\\" );		// SLASH
			/* newname (fileio.c) adds to found list. If error m != 0 on return */
			if ( pG->dirnames && (m = newname( p, 0, pG )) != ZEN_OK ) {
				FREE( p );
				sprintf( pG->ewemsg, "returning %d from procname after 2nd newname call", m );
				diag( pG->ewemsg, pG );
				return m;
			}
		}

		/* recurse into directory */
		// diag( "spot 4: optional recurse into dir" );
		if ( RecurseDir && ((d = Opendir( ArgName, pG )) != NULL) ) {     /* Open new dir (like chdir) */
			// diag( "good open of dir" );
			while ( (e = readd( d, pG )) != NULL ) {
				if ( pG->global_abort_sw ) {	// RCV changed error handling
					pnError = ZEN_ABORT;
					break;
				}
				/* e is pointing to the new filename we just read from dir */
				/* ignore dir entries of . and .. */
				if ( strcmp( e, "." ) && strcmp( e, ".." ) ) {
					/* get a new tmp buffer for the path and fname */
					if ( (a = MALLOC( lstrlen( p ) + lstrlen( e ) + 1 )) == NULL ) {
						pnError = ZEN_MEM23;		/* RCV error handling changed */
						break;
					}
					/* form the new dir's pathname followed by the fname just read */
					/* (we need to send in the dir and fname, or it won't be
					 * detected as a valid file by LSSTAT)
					 */
					lstrcat( lstrcpy( a, p ), e );

					// diag( "DOING RECURSIVE CALL TO PROCNAME FROM PROCNAME" );
					if ( (m = procname( a, RecurseDir, pG )) != ZEN_OK ) {
						/* recursive call failed; return code not ZEN_OK */
						if ( m != ZEN_OK && m != ZEN_MISS05 ) {	/* unknown error; RCV error handling changed */
							pnError = m;
							FREE( a );
							break;
						} else if ( (int)(char)(m & 0xFF) == ZEN_MISS ) zipwarn( "name not matched: ", a );
					}
					FREE( a );
				}
			} /* end while */
			Closedir( d );
		} /* end if (spot 4) */
		FREE( p );
	} /* (StatRes.st_mode & S_IFDIR) == 0) */
	// diag( "returning ZEN_ class from procname" );
	return pnError;
}
Example #8
0
/* ===========================================================================
 * If not in exclude mode, expand the pattern based on the contents
 * of the file system.
 * This function is used while gathering filenames to be added or updated
	*w :: Path/pattern to match.
   Possible return values: ZEN_MISS, ZEN_OK, ZEN_ABORT, ZEN_MEM or ZEN_PARMS.
 */
int Wild( char *w, struct Globals *pG ) {
	zDIR *d;                   /* Stream for reading directory       */
	char *e;                   /* File or directory name found.      */
	char *n;                   /* Constructed name from directory    */
	int   WError;              /* Result of Wild()                   */
	char *p, *a;               /* path originale and fixed.          */
	char *q;                   /* Filename / pattern.                */
	int   r;                   /* Result / temp var.                 */
	char  v[5];                /* space for device current directory.*/
	bool  StopRecurs = false;  /* No recursion if filespec is file.  */

	//	sprintf( pG->ewemsg, "in Wild of win32zip.c, pattern=%s recurse=%d", w, pG->recurse );
	//	diag( pG->ewemsg, pG );

	// "zip -$ foo a:" can be used to force a drive name once. 	// v1.6017
	if ( pG->volume_label == 1 ) {
		pG->volume_label = 2;
		pG->label = getVolumeLabel( pG, (w != NULL && w[ 1 ] == ':') ? to_up( w[ 0 ] ) : '\0', &pG->label_time, &pG->label_mode, &pG->label_utim );
		if ( pG->label != NULL )
			(void)newname( pG->label, 0, pG );
		if ( w == NULL || (w[1] == ':' && w[2] == '\0') ) return ZEN_OK;
	}

	/* Allocate and copy pattern */
	if ( (p = a = MALLOC( lstrlen( w ) + 1) ) == NULL ) return ZEN_MEM19;
	lstrcpy( p, w );

	/* Separate path and name into p and q */
   // We have '\' or '\name' or 'path1\path2\name2' or 'C:\path\name' but NOT 'C:\name'
	if ( (q = strrchr( p, '\\' )) != NULL && (q == p || q[-1] != ':') ) {		// SLASH
		*q++ = '\0';
		if ( *p == '\0' ) p = lstrcpy( v, "\\." );	   /* if path is just '\' SLASH               */
	} else if ( (q = strrchr( p, ':' )) != NULL ) {	/* We have 'C:' or 'C:\' or 'C:\name' */
		*q++ = '\0';
		p = lstrcat( lstrcpy( v, p ), ":" );          /* copy device as path eg. 'C:'       */
		if ( *q == '\\' ) {                          /* -> device:/., name  eg. 'C:\.' SLASH     */
			lstrcat( p, "\\" );		// SLASH
			q++;										         /* name or nothing.                   */
		}
		lstrcat( p, "." );   						         /* eg. 'C:.' or 'C:\.'                */
	} else if ( pG->recurse && (!strcmp( p, "." ) || !strcmp( p, ".." )) ) {
		/* current or parent directory */
		/* Get "zip -r foo ." to work. Allow the dubious "zip -r foo .." but
		 * reject "zip -r -m foo ..".  "dispose" means wipe out source path.
		 */
		if ( pG->dispose && !strcmp( p, ".." ) ) ziperr( ZEN_PARMS15, pG );
		q = (char *)pG->wild_match_all;
	}
	else {  /* no path or device */
		q = p;
		p = lstrcpy( v, "." );
	}
	if ( pG->recurse && *q == '\0' ) q = (char *)pG->wild_match_all;
	/* take out a possibly redundant dir name of "." */
	if ( (r = lstrlen( p )) > 1 && (strcmp( p + r - 2, ":." ) == 0 || strcmp( p + r - 2, "\\." ) == 0) )	// SLASH
		*(p + r - 1) = '\0';

	/* Only filename (not the path) can have special matching characters */
	if ( IsShExp( p ) ) {
		diag( "path has illegal chars", pG );
		FREE( a );
		return ZEN_PARMS16;
	}
	// sprintf( ewemsg, "at break up place in Wild: path=%s  name=%s", p, q );
	// diag( ewemsg );

	if ( !IsShExp( q ) ) {	// Speed up checking if file exits in case there are no wildcards
		struct stat s;       // and no recursion and no archiving v1.6016

		if ( !pG->recurse && !pG->ArchiveFiles ) {
			if ( !LSSTAT( GetFullPath( pG, w ), &s ) )                 /* file exists ? */
				return procname( w, false, pG );
			return ZEN_MISS02;                      /* woops, no wildcards where is the file! */
		}
		if ( pG->norecursefiles ) StopRecurs = true;
	}

	/* Now that we have a dir spec, along with an fspec, we'll step
	 * in the dir specified to see if there's any matches against the fspec.
	 */
	WError = ZEN_MISS02;
	if ( (d = Opendir( p, pG )) != NULL ) {
		while ( (e = readd( d, pG )) != NULL ) {
			if ( pG->global_abort_sw ) {
				WError = ZEN_ABORT;
				break;
			}
			// sprintf( ewemsg, "Found %s: %s", d->d_attr & FILE_ATTRIBUTE_DIRECTORY ? "directory" : "file", e );
			// diag( ewemsg );
			/* if e is NOT '.' or '..', and is a dir or match fspec. */
			if ( strcmp( e, "." ) && strcmp( e, ".." ) && (d->d_attr & FILE_ATTRIBUTE_DIRECTORY || dosmatch( q, e, pG )) ) {
				// diag( "Matched" );
				/* we matched fspec or it's a dir and entry is not '.' or '..' */
				if ( d->d_attr & FILE_ATTRIBUTE_DIRECTORY ) {
					// We do not save dirs or go into dirs if norecursefiles==1 and we a file without * or ? specs.
					if ( !StopRecurs && (pG->dirnames || pG->recurse) ) {
						if ( (n = MALLOC( lstrlen( p ) + lstrlen( e ) + lstrlen( q ) + 3 )) == NULL ) {
							WError = ZEN_MEM20;
							break;
						}
						*n = '\0';
						if ( *p != '.' ) AddSlash( lstrcpy( n, p ) );	// No ./ as first dir.
						lstrcat( n, e );
						if ( pG->dirnames ) {		// Save directory names also.
							r = procname( n, false, pG );
							if ( (int)(char)(r & 0xFF) > ZEN_OK || !pG->recurse ) FREE( n );
							if ( (int)(char)(r & 0xFF) > (int)(char)(WError & 0xFF) ) WError = r;
							if ( (int)(char)(r & 0xFF) > ZEN_OK ) break;
						}
						if ( pG->recurse ) {	// Recursively go into dir and check for other pattern matches.
							r = Wild( lstrcat( AddSlash( n ), q ), pG );	// Add the original pattern.
							FREE( n );
							// We keep a ZEN_OK even when ZEN_MISS occurs.
							if ( (int)(char)(r & 0xFF) > (int)(char)(WError & 0xFF) ) WError = r;
							if ( (int)(char)(r & 0xFF) > ZEN_OK ) break;						// An error, stop processing.
						}
   		      }
				} else {
					if ( (n = MALLOC( lstrlen( p ) + lstrlen( e ) + 2 )) == NULL ) {
						WError = ZEN_MEM21;
						break;
					}
					if ( !strcmp( p, "." ) ) r = procname( e, false, pG );
					else r = procname( lstrcat( AddSlash( lstrcpy( n, p ) ), e ), false, pG );
					FREE( n );
					if ( (int)(char)(r & 0xFF) > (int)(char)(WError & 0xFF) ) WError = r;
					if ( (int)(char)(r & 0xFF) > ZEN_OK ) break;
				}
			} /* end "if (strcmp..." */
		} /* end while */
		Closedir( d );
	} else diag( "can't open dir", pG );
	FREE( a );
	// sprintf( ewemsg, "Wild returned: %d", WError );
	// diag( ewemsg );
	return WError;
}
Example #9
0
int main(int argc, char *argv[])
{
    FILE *output;
    char *inputFirst,*inputSecond,*inputThird;
    int lengthFirst,lengthSecond,i,binary,module,lengthModule;
    unsigned char *numberOne,*numberTwo,*remainder,*numModule;
	unsigned char sign1,sign2,sign3;
	char sign;
	if (argc < 5 )
	{
		printf("\nEnter correct parameters\n");
		return 0;
	}
    if (argc < 6)
	{
		binary=0;
		module=0;
	}
    if (argc == 6)
	{
		if (strcmp(argv[5],"-b") == 0)
		{
			binary=1;
			module=0;
		}
		else
		{
			binary=0;
			module=1;
			inputThird=argv[5];
			lengthModule = readd(&numModule,inputThird,&sign3);
		}
	}
	if (argc == 7)
	{
		binary=1;
		module=1;
		inputThird=argv[6];
		lengthModule = readb(&numModule,inputThird);
	}
	
	inputFirst =argv[1];
    inputSecond=argv[3];

    if(!binary)
    {

        output = fopen(argv[4],"w");
    }
    else
    {
        output = fopen(argv[4],"wb");
    }

	sign=argv[2][0];
	switch(sign)
	{
		case '+' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((sign1=='+')&&(sign2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((sign1=='-')&&(sign2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
				if ((sign1=='+')&&(sign2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((sign1=='-')&&(sign2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=summb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '-' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				if ((sign1=='+')&&(sign2=='+'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					break;
				}
				if ((sign1=='-')&&(sign2=='-'))
				{
					if (cmp(&numberOne,&numberTwo) == 1)
					{
						numberOne = sub(&numberOne,&numberTwo);
						turn(&numberOne);
						fprintf(output,"-%s",numberOne);
					}
					else
					{
						numberOne = sub(&numberTwo,&numberOne);
						turn(&numberOne);
						fprintf(output,"%s",numberOne);
					}
					break;
				}
				if ((sign1=='+')&&(sign2=='-'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
					break;
				}
				if ((sign1=='-')&&(sign2=='+'))
				{
					numberOne = summ(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
					break;
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=subb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '*' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				if (((sign1=='+')&&(sign2=='+'))||((sign1=='-')&&(sign2=='-')))
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"%s",numberOne);
				}
				else
				{
					numberOne=mul(&numberOne,&numberTwo);
					turn(&numberOne);
					fprintf(output,"-%s",numberOne);
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=mulb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '/' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				if (((sign1=='+')&&(sign2=='+'))||((sign1=='-')&&(sign2=='-')))
				{
					fprintf(output,"%s",divv(&numberOne,&numberTwo,&remainder));
				}
				else
				{
					fprintf(output,"-%s",divv(&numberOne,&numberTwo,&remainder));
				}
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lengthFirst);
				turnb(&numberTwo,lengthSecond);
				numberOne=divvb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst,&remainder,&lengthSecond);
				turnb(&numberOne,lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;

		case '%' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				divv(&numberOne,&numberTwo,&remainder);
				fprintf(output,"%s",remainder);
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				turnb(&numberOne,lengthFirst);
				turnb(&numberTwo,lengthSecond);
				divvb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst,&remainder,&lengthSecond);
				turnb(&remainder,lengthSecond);
				fwrite(remainder,lengthSecond,1,output);
				free(remainder);
			}
			break;

		case '^' :
			if (!binary)
			{
				lengthFirst = readd(&numberOne,inputFirst,&sign1);
				lengthSecond = readd(&numberTwo,inputSecond,&sign2);
				turn(&numberOne);
				turn(&numberTwo);
				numberOne=degree(&numberOne,&numberTwo,&sign1);
				turn(&numberOne);
				if (sign1=='+')
					fprintf(output,"%s",numberOne);
				else
					fprintf(output,"-%s",numberOne);
			}
			else
			{
				lengthFirst = readb(&numberOne,inputFirst);
				lengthSecond = readb(&numberTwo,inputSecond);
				numberOne=degreeb(&numberOne,&numberTwo,lengthFirst,lengthSecond,&lengthFirst);
				fwrite(numberOne,lengthFirst,1,output);
			}
			break;
		default:
			break;
	}

    fclose(output);

	if (module)
	{
		if(!binary)
		{
			output = fopen(argv[4],"w");
			divv(&numberOne,&numModule,&remainder);
			fprintf(output,"%s",remainder);
		}
		else
		{
			output = fopen(argv[4],"wb");
			turnb(&numberOne,lengthFirst);
			turnb(&numModule,lengthModule);
			divvb(&numberOne,&numModule,lengthFirst,lengthModule,&lengthFirst,&remainder,&lengthModule);
			turnb(&remainder,lengthModule);
			fwrite(remainder,lengthModule,1,output);
		}
		fclose(output);
	    
	}
    return 0;
}