static void cb(void *a, int count) { u8 *buf; buf = a; fprintf(stderr, "cb %d\n", count); if (count < 0) { fprintf(stderr, "error\n"); done++; } else if (count > 0) { write(1, buf, count); cnt += count; fprintf(stderr, "%d\n", cnt); readnb(buf); } else done++; }
int main(int argc, char **argv) { int ecode; int c; char *addr; char *ename, *path; Spuser *user; Spcfsys *fs; user = sp_unix_users->uid2user(sp_unix_users, geteuid()); while ((c = getopt(argc, argv, "dp:")) != -1) { switch (c) { case 'd': spc_chatty = 1; break; case 'u': user = sp_unix_users->uname2user(sp_unix_users, optarg); break; default: usage(); } } if (!user) { fprintf(stderr, "cannot retrieve user %d\n", geteuid()); exit(1); } if (argc - optind < 2) usage(); addr = argv[optind]; path = argv[optind+1]; fs = spc_netmount(addr, user, 564, NULL, NULL); fid = spc_open(fs, path, Oread); if (!fid) { fprintf(stderr, "cannot open\n"); exit(1); } if (readnb(buf1) < 0) goto error; if (readnb(buf2) < 0) goto error; if (readnb(buf3) < 0) goto error; if (readnb(buf4) < 0) goto error; while (done < 4) sp_poll_once(); spc_close(fid); spc_umount(fs); return 0; error: sp_rerror(&ename, &ecode); fprintf(stderr, "Error: %s\n", ename); return -1; }
int main(int argc, char *argv[]) { int i, j, x, z; char fnwoe[384], *e, *minimap, *hmap, **tname; int *tid; if(argc < 2) {printf("Usage: bcm2snr \"input.bcm\"\n"); return 0;} assert(file = fopen(argv[1], "rb")); fseek(file, 12, SEEK_CUR); mapw = read32(); maph = read32(); strcpy(fnwoe, argv[1]); e = strrchr(fnwoe, '.'); if(!e) {e = fnwoe + strlen(fnwoe); *e = '.';} strcpy(e, ".snr"); assert(fsnr = fopen(fnwoe, "w")); fprintf(fsnr, "SCENARIO_VERSION 4.00\n"); fprintf(fsnr, "SCENARIO_DIMENSIONS %u %u\n", mapw, maph); fprintf(fsnr, "SCENARIO_EDGE_WIDTH %u\n", read32()); fprintf(fsnr, "SCENARIO_TEXTURE_DATABASE \""); ReadPrintWString(fsnr); fprintf(fsnr, "\"\n"); strcpy(e, ""); fprintf(fsnr, "SCENARIO_TERRAIN \"%s.trn\"\n", fnwoe); fprintf(fsnr, "SCENARIO_HEIGHTMAP \"%s_heightmap.pcx\"\n", fnwoe); fprintf(fsnr, "SCENARIO_HEIGHT_SCALE_FACTOR %f\n", readfloat()); fprintf(fsnr, "SCENARIO_SUN_COLOUR"); for(i = 0; i < 3; i++) fprintf(fsnr, " %u", read32()); fprintf(fsnr, "\n"); fprintf(fsnr, "SCENARIO_SUN_VECTOR"); for(i = 0; i < 3; i++) fprintf(fsnr, " %f", readfloat()); fprintf(fsnr, "\n"); fprintf(fsnr, "SCENARIO_FOG_COLOUR"); for(i = 0; i < 3; i++) fprintf(fsnr, " %u", read32()); fprintf(fsnr, "\n"); fprintf(fsnr, "SCENARIO_SKY_TEXTURES_DIRECTORY \""); ReadPrintWString(fsnr); fprintf(fsnr, "\"\n"); fprintf(fsnr, "SCENARIO_MINIMAP \"%s_minimap.pcx\"\n", fnwoe); strcpy(e, "_minimap.pcx"); assert(fpcx = fopen(fnwoe, "wb")); assert(minimap = (char*)malloc(0xC000)); fread(minimap, 0xC000, 1, file); WritePCXHeader(fpcx, 128, 128, 3); WritePCXData(fpcx, minimap, 128, 128, 3); fclose(fpcx); free(minimap); nlakes = readnb(6); for(i = 0; i < nlakes; i++) { fprintf(fsnr, "SCENARIO_LAKE"); for(j = 0; j < 3; j++) fprintf(fsnr, " %f", readfloat()); fprintf(fsnr, " 0.0\n"); readnb(2); } printf("Number of names: %u\n", nnames = read16()); assert(tname = (char**)malloc(nnames * sizeof(char*))); for(i = 0; i < nnames; i++) {tname[i] = (char*)malloc(128); ReadName(tname[i]);} printf("Number of IDs: %u\n", nids = read16()); assert(tid = (int*)malloc(nids * sizeof(int))); for(i = 0; i < nids; i++) tid[i] = read32(); printf("\n------------\n\n"); ngrpbits = GetMaxBits(nnames); //2; nidbits = GetMaxBits(nids); //3; strcpy(e, ".trn"); assert(ftrn = fopen(fnwoe, "w")); for(z = maph-1; z >= 0; z--) for(x = 0; x < mapw; x++) { fprintf(ftrn, "X %u Z %u ", x+1, z+1); fprintf(ftrn, "GROUP \"%s\" ", tname[readnb(ngrpbits)]); fprintf(ftrn, "ID %u ", tid[readnb(nidbits)]); fprintf(ftrn, "ROTATION %u ", readnb(2)); fprintf(ftrn, "XFLIP %u ", readbit()); fprintf(ftrn, "ZFLIP %u\n", readbit()); } fclose(ftrn); printf("End offset: 0x%08X\n", ftell(file)); printf("\n------------\n\n"); printf("Num of ?: %u\n", nunk = read32()); printf("0x62: 0x%X\n", read32()); for(i = 0; i < nunk; i++) {readnb(ngrpbits); readnb(nidbits);} assert(hmap = (char*)malloc((mapw+1)*(maph+1))); fread(hmap, (mapw+1)*(maph+1), 1, file); strcpy(e, "_heightmap.pcx"); assert(fpcx = fopen(fnwoe, "wb")); WritePCXHeader(fpcx, mapw+1, maph+1, 1); WritePCXData(fpcx, hmap, mapw+1, maph+1, 1); write8(fpcx, 12); for(i = 0; i < 256; i++) for(j = 0; j < 3; j++) write8(fpcx, i); fclose(fpcx); free(hmap); printf("End offset: 0x%08X\n", ftell(file)); fclose(file); fclose(fsnr); free(tid); for(i = 0; i < nnames; i++) free(tname[i]); free(tname); }