示例#1
0
文件: main.c 项目: carriercomm/jump
int main(int argc, char *argv[]) {
	char *filename;
	char **map;
	player p;
	setlocale(LC_ALL,"");
	bindtextdomain("jump","/usr/share/locale");
	textdomain("jump");		

	p = malloc(sizeof (struct player_str));
	/* FIXME: */
	p->symbol = '*';
	p->x = 4;
	p->y = 4;


	if(argc > 1) {
		filename = malloc(255*sizeof(char));
		strcpy(filename, argv[1]);
	} else {
		printf(_("you have to choose a map file in the argument\n"));
		exit(-1);
	}

	map = readmap (filename);

	if (!map) {
		printf(_("cannot read map file!\n"));
		exit (-1);
	}

	free(filename);

	keyboard_interact(map, p);
	exit(0);
}
示例#2
0
void sendmap(char *mapname)
{
    if(*mapname) save_world(mapname);
    changemap(mapname);
    mapname = getclientmap();
    int mapsize;
    uchar *mapdata = readmap(mapname, &mapsize); 
    if(!mapdata) return;
    ENetPacket *packet = enet_packet_create(NULL, MAXTRANS + mapsize, ENET_PACKET_FLAG_RELIABLE);
    uchar *start = packet->data;
    uchar *p = start+2;
    putint(p, SV_SENDMAP);
    sendstring(mapname, p);
    putint(p, mapsize);
    if(65535 - (p - start) < mapsize)
    {
        conoutf("map %s is too large to send", mapname);
        free(mapdata);
        enet_packet_destroy(packet);
        return;
    };
    memcpy(p, mapdata, mapsize);
    p += mapsize;
    free(mapdata); 
    *(ushort *)start = ENET_HOST_TO_NET_16(p-start);
    enet_packet_resize(packet, p-start);
    sendpackettoserv(packet);
    conoutf("sending map %s to server...", mapname);
    sprintf_sd(msg)("[map %s uploaded to server, \"getmap\" to receive it]", mapname);
    toserver(msg);
}
// Load assets
bool ModuleSceneSpace::Start()
{
	LOG("Loading space scene");
	
	background = App->textures->Load("Gauntlet/g.png");

	addcolider = true;
	App->scene_intro->Disable();
	App->scene_lvl1->Disable();
	App->collision->Enable(); // enable before player
	App->player->Enable();
	App->scene_menu->Enable();
	App->scene_ghost_generator->Enable();
	App->scene_ghost->Enable();
	App->scene_items->Enable();

	
	App->audio->PlayMusic("stage1.ogg", 1.0f);
	SDL_Texture* particles = App->textures->Load("Gauntlet/g.png");
	explosion.graphics = particles;

	//App->renderer->camera.x = App->renderer->camera.y = 0;

	//App->collision->AddCollider({0, 224, 3000, 16}, COLLIDER_WALL);

	//App->collision->AddCollider({1376, 0, 112, 95}, COLLIDER_WALL);
	//App->collision->AddCollider({1376, 144, 112, 95}, COLLIDER_WALL);

	map.clear();
	readmap();

	return true;
}
示例#4
0
int
dockspace(char *spacefile)
{
	struct fstable *fs_tab;
	int	i, error;

	error = 0;

	/*
	 * Also, vanilla SVr4 code used the output from popen()
	 * on the "/etc/mount" command.  However, we need to get more
	 * information about mounted filesystems, so we use the C
	 * interfaces to the mount table, which also happens to be
	 * much faster than running another process.  Since several
	 * of the pkg commands need access to the mount table, this
	 * code is now in libinst.  However, mount table info is needed
	 * at the time the base directory is determined, so the call
	 * to get the mount table information is in main.c
	 */

	if (readmap(&error) || readspace(spacefile, &error))
		return (-1);

	for (i = 0; fs_tab = get_fs_entry(i); ++i) {
		if ((!fs_tab->fused) && (!fs_tab->bused))
			continue; /* not used by us */

		if (fs_tab->bfree < (LIM_BFREE + fs_tab->bused)) {
			warn(TYPE_BLCK, fs_tab->name, fs_tab->bused,
				fs_tab->bfree, LIM_BFREE);
			error++;
		}

		/* bug id 1091292 */
		if ((long)fs_tab->ffree == -1L)
			continue;
		if (fs_tab->ffree < (LIM_FFREE + fs_tab->fused)) {
			warn(TYPE_NODE, fs_tab->name, fs_tab->fused,
				fs_tab->ffree, LIM_FFREE);
			error++;
		}
	}
	return (error);
}
示例#5
0
int main(int argc, char* argv[])
{
	initscr();
	scrollok(stdscr, TRUE);
	stufffilename();
	wprintw(stdscr, "\n");
	if(middleman() != 0)
	{
		wprintw(stdscr, "Failed to open input or temp file!\n");
		refresh();
		hang(2);
		endwin();
		return 1;
	}
	if(readmap() != 0)
	{
		wprintw(stdscr, "Failed to open temporary map file!\n");
		refresh();
		hang(2);
		endwin();
		return 1;
	}
	stufffilename();
	wprintw(stdscr, "\n");
	if(writemap() != 0)
	{
		wprintw(stdscr, "Failed to write map file!\n");
		refresh();
		hang(2);
		endwin();
		return 1;
	}
	wprintw(stdscr, "Happily finished!\n");
	refresh();
	hang(2);
	endwin();
	return 0;
}
int main(int argc, char **argv) {
    struct stat     statinfo1;
    int             fd1, fd2, fd3;
    int             num_blocks;
    int             block_size;
    unsigned int             i;
    int             sparse_blocks;
    int             copied_blocks;
    int             percent = -1;
    unsigned char   *buffer1;

    if (argc != 4) {
        fprintf(stderr, "%s merge a sparsemap and a data file to a sparse file.\n", argv[0]);
        fprintf(stderr, "Usage: %s MAPFILE DATA SPARSEFILE\n", argv[0]);
        exit(EXIT_FAILURE);
    }


    if ((fd1 = open(argv[1], O_RDONLY)) < 0) {
        fprintf(stderr, "Cannot open %s\n", argv[1]);
        exit(EXIT_FAILURE);
    }


    if ((fd2 = open(argv[2], O_RDONLY)) < 0) {
        fprintf(stderr, "Cannot open %s\n", argv[2]);
        close(fd1);
        exit(EXIT_FAILURE);
    }

    if (ioctl(fd2, FIGETBSZ, &block_size) < 0) {
        fprintf(stderr, "Cannot get block size\n");
        close(fd1);
        close(fd2);
        exit(EXIT_FAILURE);
    }

    if (fstat(fd2, &statinfo1) < 0) {
        fprintf(stderr, "Cannot stat %s\n", argv[1]);
        close(fd1);
        close(fd2);
        exit(EXIT_FAILURE);
    }

    num_blocks = (statinfo1.st_size + block_size - 1) / block_size;

    if ((fd3 = open(argv[3], O_WRONLY|O_CREAT|O_TRUNC, 0777)) < 0) {
        fprintf(stderr, "Cannot open %s\n", argv[3]);
        close(fd1);
        close(fd2);
        exit(EXIT_FAILURE);
    }

    buffer1=malloc(block_size);
    if (!buffer1) {
        fprintf(stderr, "Cannot allocate buffer\n");
        close(fd1);
        close(fd2);
        close(fd3);
        exit(EXIT_FAILURE);
    }

    sparse_blocks = 0;
    copied_blocks = 0;

    for (i=0; i<num_blocks;) {
        int nread = 0;

        if (percent != ((i+1)*100 / num_blocks)){
            percent = (i+1)*100 / num_blocks;

            printf("%08d/%08d (%d%%), S:%08d, C:%08d  \r",
                    i+1, num_blocks, percent, sparse_blocks, copied_blocks);
            fflush(0);
        }

        /* No source block: skip*/
        if (!readmap(fd1)) {
            if (lseek(fd3, block_size, SEEK_CUR) < 0 ){
                fprintf(stderr, "Seek failed.\n");
                close(fd1);
                close(fd2);
                close(fd3);
                exit(EXIT_FAILURE);
            }
            sparse_blocks++;
            continue;
        }

        /* Check for zero blocks: skip if empty*/
        nread = read(fd2, buffer1, block_size);

        if (nread < block_size) {
            if (i != (num_blocks -1)){
                fprintf(stderr, "Unexpected short read.\n");
                close(fd1);
                close(fd2);
                close(fd3);
                exit(EXIT_FAILURE);
            }
        }

        if (nread == -1) {
            fprintf(stderr, "Cannot read block %d on %s\n", i, argv[2]);
        }
        else {
            if (write(fd3, buffer1, nread) != nread) {
                fprintf(stderr, "Cannot write block %d on %s\n", i, argv[3]);
                close(fd1);
                close(fd2);
                close(fd3);
                exit(EXIT_FAILURE);
            }
            else {
                copied_blocks++;
                i++;
            }
        }
    }

    close(fd1);
    free(buffer1);

    close(fd2);
    close(fd3);

    printf("\n");

    printf("Report:\n");
    printf("%d byte block size\n", block_size);
    printf("   total %08d blocks\n",num_blocks);
    printf("Inserted %08d sparse blocks\n",sparse_blocks);
    printf("  copied %08d data blocks\n",copied_blocks);
    printf("  ------------------------------------\n");
    printf("   Sum:  %08d blocks accounted for.\n",(sparse_blocks+copied_blocks));

    exit(EXIT_SUCCESS);
}
示例#7
0
文件: shiftcod.c 项目: yfyang86/yytex
int main (int argc, char *argv[]) {
	FILE *input, *output;
	char infilename[MAXFILENAME], outfilename[MAXFILENAME];
	char bakfilename[MAXFILENAME];
	int c, k, firstarg=1;
/*	int outfile=0, afmfile=0, hntfile=0; */
	char *s;

	for (k = 0; k < 256; k++) map[k] = k;				/* idendity mapping */

/*	for (k = low; k <= high; k++) map[k] = k + shift; */	/* shift a range */

	if (firstarg + 1 > argc) {
		fprintf(stderr, "Too few arguments\n");
		exit(1);
	}

/*	while ((c = argv[firstarg][0]) == '-') { */
	while (firstarg < argc && argv[firstarg][0]) == '-') {
		if (argv[firstarg][1] == 'w') writeback = ~writeback;
		else if (argv[firstarg][1] == 'r') {
			if (!readmap(&argv[firstarg][3])) exit(2);
		}
		else fprintf(stderr, "What is: %s\n", argv[firstarg]);
		firstarg++;
	}

	if (firstarg + 1 > argc) {
		fprintf(stderr, "Too few arguments\n");
		exit(1);
	}

	for (k = firstarg; k < argc; k++) {

		strcpy(infilename, argv[k]);
		lowercase(infilename);
	 
		if ((s = strchr(infilename, '.')) == NULL) {
			if (traceflag != 0) printf("Ignoring   %s\n", infilename);
			continue;
		}
		if (strcmp (s+1, "out") != 0 &&
				strcmp (s+1, "afm") != 0 &&
					strcmp (s+1, "hnt") != 0) {
			if (traceflag != 0) printf("Ignoring   %s\n", infilename);
			continue;
		}

		if (verboseflag != 0) printf("Processing %s --- ", infilename);

		if (writeback != 0) {
			strcpy(outfilename, infilename);
			strcpy(bakfilename, infilename);
			forceexten(bakfilename, "bak");
			(void) remove (bakfilename);
			(void) rename (infilename, bakfilename);
			if ((input = fopen(bakfilename, "r")) == NULL) { 
				perror(infilename);
				exit(1);
			}
		}
		else {
			strcpy(outfilename, filename(infilename)); 
			if ((input = fopen(infilename, "r")) == NULL) { 
				perror(infilename);
				exit(1);
			}
		}

/*		strcpy(outfilename, filename(infilename)); */
		if (strcmp(outfilename, infilename) == 0) {
			fprintf(stderr, "%s == %s\n", outfilename, infilename);
			exit(1);
		}
	
		if ((output = fopen(outfilename, "w")) == NULL) {
			perror(outfilename);
			exit(1);
		}

		if ((s = strchr(infilename, '.')) != NULL) {
			if (strcmp (s+1, "out") == 0) processout(output, input);
			else if (strcmp (s+1, "afm") == 0) processafm(output, input);
			else if (strcmp (s+1, "hnt") == 0) processhnt(output, input);
		}
	
		fclose(input);
		fclose(output);	
	}
	return 0;
}
示例#8
0
/*
 * Write an ELF coredump for the given pid to the given fd.
 */
void
elf_coredump(int fd, pid_t pid)
{
	vm_map_entry_t map;
	struct sseg_closure seginfo;
	void *hdr;
	size_t hdrsize;
	char memname[64];
	int memfd;
	Elf_Phdr *php;
	int i;

	/* Get the program's memory map. */
	map = readmap(pid);

	/* Size the program segments. */
	seginfo.count = 0;
	seginfo.size = 0;
	each_writable_segment(map, cb_size_segment, &seginfo);

	/*
	 * Calculate the size of the core file header area by making
	 * a dry run of generating it.  Nothing is written, but the
	 * size is calculated.
	 */
	hdrsize = 0;
	elf_puthdr(map, NULL, &hdrsize, NULL, NULL, NULL, seginfo.count);

	/*
	 * Allocate memory for building the header, fill it up,
	 * and write it out.
	 */
	hdr = malloc(hdrsize);
	if ((hdr = malloc(hdrsize)) == NULL)
		errx(1, "out of memory");
	elf_corehdr(fd, pid, map, seginfo.count, hdr, hdrsize);

	/* Write the contents of all of the writable segments. */
	snprintf(memname, sizeof memname, "/proc/%d/mem", pid);
	if ((memfd = open(memname, O_RDONLY)) == -1)
		err(1, "cannot open %s", memname);

	php = (Elf_Phdr *)((char *)hdr + sizeof(Elf_Ehdr)) + 1;
	for (i = 0;  i < seginfo.count;  i++) {
		int nleft = php->p_filesz;

		lseek(memfd, (off_t)php->p_vaddr, SEEK_SET);
		while (nleft > 0) {
			char buf[8*1024];
			int nwant;
			int ngot;

			nwant = nleft;
			if (nwant > sizeof buf)
				nwant = sizeof buf;
			ngot = read(memfd, buf, nwant);
			if (ngot == -1)
				err(1, "read from %s", memname);
			if (ngot < nwant)
				errx(1, "short read from %s:"
				    " wanted %d, got %d\n", memname,
				    nwant, ngot);
			ngot = write(fd, buf, nwant);
			if (ngot == -1)
				err(1, "write of segment %d failed", i);
			if (ngot != nwant)
				errx(1, "short write");
			nleft -= nwant;
		}
		php++;
	}
	close(memfd);
	free(hdr);
	freemap(map);
}
示例#9
0
int main(int argc, char **argv)
{
   ushort fromtable[256],desttable[256];
   int c,d,firstdiff;
   bool createutf;
   ushort uc;
       
   if(argc != 4 && argc!=5)
   {
      fprintf(stderr,"Usage: makechs <fromchrs> <destchrs> <frommap> [<destmap>]\n");
      exit(0);
   }
   
   if(argc == 4) createutf=TRUE;
   else          createutf=FALSE;
   
   if(!(readmap(fromtable,argv[3])))
      exit(0);

   if(!createutf)
   {      
      if(!(readmap(desttable,argv[4])))
         exit(0);
   }

   if(createutf)
   {
      firstdiff=0;
   }
   else
   {
      for(c=0;c<256;c++)
      {
         if(fromtable[c] != desttable[c])
         {
            firstdiff=c;
            break;
         }
       }
   }   
      
   printf(";\n");
   printf("; Generated by makechs 1.0 by Johan Billing. Some tweaking may be required.\n");
   printf(";\n");
      
   if(createutf || firstdiff < 128)
      printf("100000          ; ID number (when >65535, all 255 chars will be translated)\n");
      
   else
      printf("0               ; ID number (when >65535, all 255 chars will be translated)\n");
      
   printf("0               ; version number\n");
   printf(";\n");
   printf("2               ; level number\n");
   printf(";\n");
   printf("%s\n",argv[1]);
   printf("%s\n",argv[2]);
   printf(";\n");
   
   for(c=0;c<256;c++)
   {
      if(createutf)
      {
         uc=fromtable[c];
         
         if(uc < 0x80)
         {
            printbyte(0);
            printf("\t");
            printbyte(uc);
            printf("\n");
         }
         else if(uc < 0x800)
         {
            printbyte(0xC0 | (uc >> 6));
            printf("\t");
            printbyte(0x80 | (uc & 0x3F));
            printf("\n");
         }
         else
         {
            printbyte(0xE0 | (uc >> 12));
            printf("\t");
            printbyte(0x80 | ((uc >> 6) & 0x3F));
            printf("\t");
            printbyte(0x80 | (uc        & 0x3F));
            printf("\n");
         }     
      }