コード例 #1
0
	void printResults(VECTOR_ELEMENT_TYPE *pResult, int lambda, int idx, int varIdx)
	{
		FILE *file = openOutFile();
		if (!file)
			return;

		const char *pTag = idx >= 0 ? "+++++++++++++++++++" : (pResult ? "-------------------" : "===================");
		fprintf(file, "Total: %2d: %s %s = %d  ppp = %2d\n", nSolutions, pTag, pResult ? "lambdaToSplit" : "lambdaMin", lambda, ppp);
		for (int i = 0; i < PRINT_RES_EQU_NUMB; i++) {
			CEquation *pMyEqu = pMyEquA[i];
			if (!pMyEqu)
				continue;

			fprintf(file, "%d:  m_nVar = %d  right part = %d  solved = %3s\n", i, pMyEqu->numbVar(),
				pMyEqu->rightPart(), pMyEqu->solved() ? "Yes" : "No");
		}

		if (idx >= 0)
			nSolutions++;

		if (pResult)
			printResults(file, pResult, printResNumVar, varIdx);

		fclose(file);
	}
コード例 #2
0
	void printDefinedVariable(VECTOR_ELEMENT_TYPE varID, VECTOR_ELEMENT_TYPE varValue)
	{
		FILE *file = openOutFile();
		if (!file)
			return;

		fprintf(file, "varID = %2d = %d  (%3d)\n", varID, varValue , ppp);
		fclose(file);
	}
コード例 #3
0
	void printFinalResultForRightPart(CVariableMapping *pVarValue)
	{
		FILE *file = openOutFile();
		if (!file)
			return;

		fprintf(file, "===>>> Constructed %d solutions for current right part, Map Pos: %s \n", nSolutions - nSolutionsPrev, pVarValue->nElement() == 0 ? "OK" : "WRONG");
		nSolutionsPrev = nSolutions;
		fclose(file);
	}
コード例 #4
0
	void printAddEquationVariable(const CEquation *pEqu, VECTOR_ELEMENT_TYPE varIdx, VECTOR_ELEMENT_TYPE varVal, bool addFlg)
	{
		if (pEqu->myID < 0 || EQUATION_ID_TO_PRINT >= 0 && pEqu->myID != EQUATION_ID_TO_PRINT)
			return;

		FILE *file = openOutFile();
		if (!file)
			return;

		fprintf(file, "ppp = %2d:  [%d] %s  m_nVar = %d  right part = %d  solved = %3s  varIdx = %2d  valVar = %d\n", ppp, pEqu->myID, addFlg ? "+++" : "---", pEqu->numbVar(), pEqu->rightPart(), pEqu->solved() ? "Yes" : "No", varIdx, varVal);
		fclose(file);
	}
コード例 #5
0
ファイル: Process.cpp プロジェクト: Bobain/pyb
  void Process::create()
  {
    SECURITY_ATTRIBUTES sa; 
    sa.nLength = sizeof(SECURITY_ATTRIBUTES); 
    sa.bInheritHandle = TRUE; 
    sa.lpSecurityDescriptor = NULL; 


    STARTUPINFO info;
    GetStartupInfo(&info);

    char curdir[100];
    GetCurrentDirectory(sizeof(curdir), curdir);

    SetCurrentDirectory( const_cast<char*>(m_workingDir.c_str()) );

    HANDLE hReadPipe, hWritePipe;
    if(m_sendToFile)
    {
      openOutFile();
      info.dwFlags = STARTF_USESTDHANDLES;
      CreatePipe(&hReadPipe, &hWritePipe, &sa, 0);
      info.hStdOutput = m_outFileHandle;
      info.hStdError = m_outFileHandle;
    }

    else if(m_sendToStd)
    {
      info.dwFlags = STARTF_USESTDHANDLES;
      CreatePipe(&hReadPipe, &hWritePipe, &sa, 0);
      info.hStdOutput = hWritePipe;
      info.hStdError = hWritePipe;
    }

    m_created = CreateProcess(
      NULL,
      const_cast<char*>(m_commandLine.c_str()),
      NULL,
      NULL,
      TRUE,
      getFlags(),
      NULL,
      NULL,
      &info,
      &m_procinfo ) != 0;

    if(m_created && (m_sendToFile || m_sendToStd))
      _beginthread((void(__cdecl*)(void*))readOutput, 0, hReadPipe);

    SetCurrentDirectory( curdir );
  }
コード例 #6
0
	void printMapInfo(CVariableMapping *pVarValue, VECTOR_ELEMENT_TYPE *pResult)
	{
		if (!ppp)
			return;

		FILE *file = openOutFile();
		if (!file)
			return;

		const auto pMapping = pVarValue->getMappingPntr();
		size_t nElem = pVarValue->nElement();
		int varIdx = *(pMapping + (nElem << 1) - 2);
		fprintf(file, "nElem = %2d  varIdx = %2d  varVal = %2d\n", nElem, varIdx, pResult[varIdx]);
		fclose(file);
	}
コード例 #7
0
ファイル: read_tape.c プロジェクト: SimonWilkinson/openafs
static int
WorkerBee(struct cmd_syndesc *as, void *arock)
{
    char *tapedev;
    struct tapeLabel *label;
    struct fileMark *fmark;
    afs_int32 fmtype;
    struct blockMark *bmark;
    afs_int32 isheader, isdatablock;
    char *data;
    char *tblock;
    afs_int32 code;
    struct volumeHeader *volheaderPtr = NULL;
    int eod = 1;
    int rc;
    char *nextblock;		/* We cycle through three tape blocks so we  */
    char *lastblock;		/* can trim off the volume trailer from the  */
    char *lastblock2;		/* end of each volume without having to back */
    char *tapeblock1;		/* up the output stream.                     */
    char *tapeblock2;
    char *tapeblock3;

    tapedev = as->parms[0].items->data;	/* -tape     */
    nrestore =
	(as->parms[1].items ? atol(as->parms[1].items->data) : 0x7fffffff);
    nskip = (as->parms[2].items ? atol(as->parms[2].items->data) : 0);
    if (as->parms[4].items)
	nskip = 0x7fffffff;	/* -scan     */
    outfile = (as->parms[3].items ? as->parms[3].items->data : 0);
    ask = (as->parms[5].items ? 0 : 1);	/* -noask    */
    printlabels = (as->parms[6].items ? 1 : 0);	/* -label    */
    printheaders = (as->parms[7].items ? 1 : 0);	/* -vheaders */
    verbose = (as->parms[8].items ? 1 : 0);	/* -verbose  */

    /* Open the tape device */
    rc = usd_Open(tapedev, USD_OPEN_RDONLY, 0, &fd);
    if (rc != 0) {
	printf("Failed to open tape device %s. Code = %d\n", tapedev, rc);
	exit(1);
    }

    /*
     * Initialize the tape block buffers
     */
    tapeblock1 = (char *)malloc(3 * 16384);
    if (tapeblock1 == NULL) {
	printf("Failed to allocate I/O buffers.\n");
	exit(1);
    }
    tapeblock2 = tapeblock1 + 16384;
    tapeblock3 = tapeblock2 + 16384;

    nextblock = tapeblock1;
    lastblock = NULL;
    lastblock2 = NULL;

    /* Read each tape block deciding what to do with it */
    do {			/* while ((nskip!=0) && (nrestore!=0)) */
	code = readblock(nextblock);
	if (code) {
	    if (!eod)
		fprintf(stderr, "Tape device read error: %d\n", code);
	    break;
	}
	isdatablock = 0;

	/* A data block can be either a volume header, volume trailer,
	 * or actual data from a dump.
	 */
	bmark = (struct blockMark *)nextblock;
	label = (struct tapeLabel *)nextblock;
	fmark = (struct fileMark *)nextblock;
	if (ntohl(bmark->magic) == BLOCK_MAGIC) {
	    if (verbose)
		printf("Data block\n");
	    isdatablock = 1;
	    isheader = 0;
	    data = &nextblock[sizeof(struct blockMark)];
	    if (strncmp(data, "H++NAME#", 8) == 0) {
		volheaderPtr = (struct volumeHeader *)data;
		printHeader(volheaderPtr, &isheader);
	    }
	    if (isheader) {
		code = openOutFile(volheaderPtr);
		nextblock = tapeblock1;
		lastblock = NULL;
		lastblock2 = NULL;
	    } else {
		if (lastblock2 != NULL) {
		    data = &lastblock2[sizeof(struct blockMark)];
		    bmark = (struct blockMark *)lastblock2;
		    writeData(data, ntohl(bmark->count));
		    tblock = lastblock2;
		} else if (lastblock != NULL) {
		    tblock = tapeblock2;
		} else {
		    tblock = tapeblock3;
		}
		lastblock2 = lastblock;
		lastblock = nextblock;
		nextblock = tblock;
	    }
	}

	/* Filemarks come in 3 forms: BEGIN, END, and EOD.
	 * There is no information stored in filemarks.
	 */
	else if (ntohl(fmark->magic) == FILE_MAGIC) {
	    fmtype = ntohl(fmark->nBytes);
	    if (fmtype == FILE_BEGIN) {
		if (verbose)
		    fprintf(stderr, "File mark volume begin\n");
	    } else if (fmtype == FILE_END) {
		if (verbose)
		    fprintf(stderr, "File mark volume end\n");
	    } else if (fmtype == FILE_EOD) {
		if (verbose)
		    fprintf(stderr, "File mark end-of-dump\n");
		eod = 1;
	    }
	}

	/* A dump label */
	else if (ntohl(label->magic) == TAPE_MAGIC) {
	    if (verbose)
		fprintf(stderr, "Dump label\n");
	    printLabel(label);
	    eod = 0;
	}

	else {
	    if (verbose) {
		fprintf(stderr, "Unrecognized tape block - end\n");
	    }
	}

	/* Anything other than a data block closes the out file.
	 * At this point nextblock contains the end of tape file mark,
	 * lastblock contains the last data block for the current volume,
	 * and lastblock2 contains the second to last block for the current
	 * volume. If the volume fits in a single block, lastblock2 will
	 * be NULL. Call writeLastBlocks to strip off the dump trailer before
	 * writing the last of the volume data to the dump file. The dump
	 * trailer may span block boundaries.
	 */
	if (!isdatablock && lastblock) {
	    writeLastBlocks(lastblock, lastblock2);
	    closeOutFile();
	    nextblock = tapeblock1;
	    lastblock = NULL;
	    lastblock2 = NULL;
	}
    } while ((nskip != 0) || (nrestore != 0));

    free(tapeblock1);

    return 0;
}
コード例 #8
0
int startReceiver(int doWarn,
		  struct disk_config *disk_config,
		  struct net_config *net_config,
		  struct stat_config *stat_config,
		  const char *ifName)
{
    char ipBuffer[16];
    union serverControlMsg Msg;
    int connectReqSent=0;
    struct client_config client_config;
    int outFile=1;
    int pipedOutFile;
    struct sockaddr_in myIp;
    int pipePid = 0;
    int origOutFile;
    int haveServerAddress;

    client_config.sender_is_newgen = 0;

    net_config->net_if = getNetIf(ifName);
    zeroSockArray(client_config.socks, NR_CLIENT_SOCKS);

    client_config.S_UCAST = makeSocket(ADDR_TYPE_UCAST,
				       net_config->net_if,
				       0, RECEIVER_PORT(net_config->portBase));
    client_config.S_BCAST = makeSocket(ADDR_TYPE_BCAST,
				       net_config->net_if,
				       0, RECEIVER_PORT(net_config->portBase));

    if(net_config->ttl == 1 && net_config->mcastRdv == NULL) {
	getBroadCastAddress(net_config->net_if,
			    &net_config->controlMcastAddr,
			    SENDER_PORT(net_config->portBase));
	setSocketToBroadcast(client_config.S_UCAST);
    } else {
	getMcastAllAddress(&net_config->controlMcastAddr,
			   net_config->mcastRdv,
			   SENDER_PORT(net_config->portBase));
	if(isMcastAddress(&net_config->controlMcastAddr)) {
	    setMcastDestination(client_config.S_UCAST, net_config->net_if,
				&net_config->controlMcastAddr);
	    setTtl(client_config.S_UCAST, net_config->ttl);
	    
	    client_config.S_MCAST_CTRL =
		makeSocket(ADDR_TYPE_MCAST,
			   net_config->net_if,
			   &net_config->controlMcastAddr,
			   RECEIVER_PORT(net_config->portBase));
	    // TODO: subscribe address as receiver to!
	}
    }
    clearIp(&net_config->dataMcastAddr);
    udpc_flprintf("%sUDP receiver for %s at ", 
		  disk_config->pipeName == NULL ? "" :  "Compressed ",
		  disk_config->fileName == NULL ? "(stdout)":disk_config->fileName);
    printMyIp(net_config->net_if);
    udpc_flprintf(" on %s\n", net_config->net_if->name);

    connectReqSent = 0;
    haveServerAddress = 0;

    client_config.clientNumber= 0; /*default number for asynchronous transfer*/
    while(1) {
	// int len;
	int msglen;
	int sock;

	if (!connectReqSent) {
	    if (sendConnectReq(&client_config, net_config,
			       haveServerAddress) < 0) {
		perror("sendto to locate server");
	    }
	    connectReqSent = 1;
	}

	haveServerAddress=0;

	sock = udpc_selectSock(client_config.socks, NR_CLIENT_SOCKS,
			       net_config->startTimeout);
	if(sock < 0) {
		return -1;
	}

	// len = sizeof(server);
	msglen=RECV(sock, 
		    Msg, client_config.serverAddr, net_config->portBase);
	if (msglen < 0) {
	    perror("recvfrom to locate server");
	    exit(1);
	}
	
	if(getPort(&client_config.serverAddr) != 
	   SENDER_PORT(net_config->portBase))
	    /* not from the right port */
	    continue;

	switch(ntohs(Msg.opCode)) {
	    case CMD_CONNECT_REPLY:
		client_config.clientNumber = ntohl(Msg.connectReply.clNr);
		net_config->blockSize = ntohl(Msg.connectReply.blockSize);

		udpc_flprintf("received message, cap=%08lx\n",
			      (long) ntohl(Msg.connectReply.capabilities));
		if(ntohl(Msg.connectReply.capabilities) & CAP_NEW_GEN) {
		    client_config.sender_is_newgen = 1;
		    copyFromMessage(&net_config->dataMcastAddr,
				    Msg.connectReply.mcastAddr);
		}
		if (client_config.clientNumber == -1) {
		    udpc_fatal(1, "Too many clients already connected\n");
		}
		goto break_loop;

	    case CMD_HELLO_STREAMING:
	    case CMD_HELLO_NEW:
	    case CMD_HELLO:
		connectReqSent = 0;
		if(ntohs(Msg.opCode) == CMD_HELLO_STREAMING)
			net_config->flags |= FLAG_STREAMING;
		if(ntohl(Msg.hello.capabilities) & CAP_NEW_GEN) {
		    client_config.sender_is_newgen = 1;
		    copyFromMessage(&net_config->dataMcastAddr,
				    Msg.hello.mcastAddr);
		    net_config->blockSize = ntohs(Msg.hello.blockSize);
		    if(ntohl(Msg.hello.capabilities) & CAP_ASYNC)
			net_config->flags |= FLAG_PASSIVE;
		    if(net_config->flags & FLAG_PASSIVE)
			goto break_loop;
		}
		haveServerAddress=1;
		continue;
	    case CMD_CONNECT_REQ:
	    case CMD_DATA:
	    case CMD_FEC:
		continue;
	    default:
		break;
	}


	udpc_fatal(1, 
		   "Bad server reply %04x. Other transfer in progress?\n",
		   (unsigned short) ntohs(Msg.opCode));
    }

 break_loop:
    udpc_flprintf("Connected as #%d to %s\n", 
		  client_config.clientNumber, 
		  getIpString(&client_config.serverAddr, ipBuffer));

    getMyAddress(net_config->net_if, &myIp);

    if(!ipIsZero(&net_config->dataMcastAddr)  &&
       !ipIsEqual(&net_config->dataMcastAddr, &myIp) &&
       (ipIsZero(&net_config->controlMcastAddr) ||
       !ipIsEqual(&net_config->dataMcastAddr, &net_config->controlMcastAddr)
	)) {
	udpc_flprintf("Listening to multicast on %s\n",
		      getIpString(&net_config->dataMcastAddr, ipBuffer));
	client_config.S_MCAST_DATA = 
	  makeSocket(ADDR_TYPE_MCAST, net_config->net_if, 
		     &net_config->dataMcastAddr, 
		     RECEIVER_PORT(net_config->portBase));
    }


    if(net_config->requestedBufSize) {
      int i;
      for(i=0; i<NR_CLIENT_SOCKS; i++)
	if(client_config.socks[i] != -1)
	  setRcvBuf(client_config.socks[i],net_config->requestedBufSize);
    }

    outFile=openOutFile(disk_config);
    origOutFile = outFile;
    pipedOutFile = openPipe(outFile, disk_config, &pipePid);

    global_client_config= &client_config;
    atexit(sendDisconnectWrapper);
    {
	struct fifo fifo;
	int printUncompressedPos =
	    udpc_shouldPrintUncompressedPos(stat_config->printUncompressedPos,
					    origOutFile, pipedOutFile);

	receiver_stats_t stats = allocReadStats(origOutFile,
						stat_config->statPeriod,
						printUncompressedPos);
	
	udpc_initFifo(&fifo, net_config->blockSize);

	fifo.data = pc_makeProduconsum(fifo.dataBufSize, "receive");

	client_config.isStarted = 0;

	if((net_config->flags & (FLAG_PASSIVE|FLAG_NOKBD))) {
	  /* No console used */
	  client_config.console = NULL;
	} else {
	  if(doWarn)
	    udpc_flprintf("WARNING: This will overwrite the hard disk of this machine\n");
	  client_config.console = prepareConsole(0);
	  atexit(fixConsole);
	}

	spawnNetReceiver(&fifo,&client_config, net_config, stats);
	writer(&fifo, pipedOutFile);
	if(pipePid) {
	    close(pipedOutFile);
	}
	pthread_join(client_config.thread, NULL);

	/* if we have a pipe, now wait for that too */
	if(pipePid) {
	    udpc_waitForProcess(pipePid, "Pipe");
	}
#ifndef __MINGW32__
	fsync(origOutFile);
#endif /* __MINGW32__ */
	displayReceiverStats(stats, 1);

    }
    fixConsole();
    sendDisconnectWrapper();
    global_client_config= NULL;
    return 0;
}
コード例 #9
0
void AnalysisManager::startSequence(void)
{
    if(inFilesList_.size()==0 || (theXmlParser_->getDocument())==0)
        return;

    currentOperation_ = "Running analyses";
    STDLINE(currentOperation_,ACRed);
    abort_            = false;
    isFinished_       = false;
    currentEntry_     = 0;
    completionStatus_ = 0;
    currentEntry_     = 0;

    resetAnalyses();
    openOutFile();

    setMaxNumberOfThreads(atoi(theXmlParser_->getGeneral()->getNumberOfThreads().c_str()));
    setThreadEvents();

    if(abort_) return;

    if((theXmlParser_->getPlanes())["Dut0"]->useCalibrations())
    {
        STDLINE("Setting calibrations for Dut0...",ACRed);
        setupCalibrations(0);
        STDLINE("Done!",ACGreen);
    }
    else if((theXmlParser_->getPlanes())["Dut1"]->useCalibrations())
    {
        STDLINE("Setting calibrations for Dut1...",ACRed);
        setupCalibrations(1);
        STDLINE("Done!",ACGreen);
    }
    else
        STDLINE("Not using calibrations!",ACRed);

    std::map<int, std::pair<std::string,XmlAnalysis*> > analyses = theXmlParser_->getAnalyses();
    int totAnalysesToRun = 0;
    for(std::map<int, std::pair<std::string, XmlAnalysis*> >::iterator iy = analyses.begin(); iy != analyses.end(); ++iy)
    {
        if(iy->second.second->isToRun())
        {
            std::string analName = iy->second.first;
            int it = iy->second.second->getPriority();
            addAnalysis(it, analName);
            analyses[it].second->setCutsList();
            ++totAnalysesToRun;

            std::stringstream ss;
            ss << it;
            STDLINE("Adding " + analName + " analysis with priority " + ss.str(), ACWhite);
        }
    }

    std::sort(analysesOrder_.begin(), analysesOrder_.end(), sorter_);

    completionStatus_ = 1;
    if(abort_) return;

    //initializeTrees();//Done already in setThreadEvents()

    completionStatus_ = 2;
    if(abort_) return;

    currentOperation_ = "Begin jobs";
    STDLINE(currentOperation_, ACRed);

    for (int it = 0; it < totAnalysesToRun; ++it)
    {
        setCutsFormula(analyses[it].first,analyses[it].second->getCutsList());
    }
    completionStatus_ = 3;
    float completionRunning = 95/analysesOrder_.size();
    float n = 0;

    for (int it = 0; it < totAnalysesToRun; ++it)
    {
        analyses_[it].second->setDoNotDelete(true);//Because the out file is open and it will delete the objects when closed

        setListOfRun(analyses_[it].second);

        if (analyses[it].first.find("After") != std::string::npos)
        {
            writeOutFile();
            analyses_[it].second->getInFile(outFile_);
        }

        currentOperation_ = "Begin " + analyses_[it].first + "jobs";
        STDLINE(currentOperation_, ACRed);

        if (!outFile_) STDLINE("Where the hell is the output file??", ACRed);
        outFile_->cd();
        analyses_[it].second->beginJob();

        currentOperation_ += " done!";
        STDLINE(currentOperation_, ACGreen);

        if(abort_) return;
        currentOperation_ += " done!";
        STDLINE(currentOperation_, ACGreen);

        completionStatus_      = 3 + completionRunning*n + 1;
        if(abort_) return;
        completionStatusBegin_ = completionStatusEnd_ = completionStatus_;

        if(abort_) return;
        currentOperation_ = "Running " + analyses_[it].first + " analysis";
        STDLINE(currentOperation_, ACRed);

        currentEntry_ = 0;
        completionStatusBegin_ = completionStatusEnd_;
        completionStatusEnd_ += completionRunning -1;
        resetThreadedEntries();
        outFile_->cd();
        analyses_[it].second->runAnalysis();
        if(abort_) return;
        currentOperation_ = analyses_[it].first + " analysis done!";
        STDLINE(currentOperation_, ACGreen);

        if(abort_) return;
        currentOperation_ = "End " + analyses_[it].first + " jobs";
        STDLINE(currentOperation_, ACRed);

        outFile_->cd();
        analyses_[it].second->endJob();

        currentOperation_ += " done!";
        STDLINE(currentOperation_, ACGreen);

        n += 1;
        if(abort_) return;
    }
    closeInFiles();

    completionStatus_ = completionStatusEnd_;
    if(abort_) return;
    currentOperation_ += " done!";
    STDLINE(currentOperation_, ACGreen);

    if(abort_) return;
    currentOperation_ = "Writing file " + outFileName_;
    STDLINE(currentOperation_, ACRed);
    writeOutFile();
    //closeOutFile();
    resetAnalyses();
    completionStatus_ = 99;
    if(abort_) return;
    currentOperation_ += " done!";
    STDLINE(currentOperation_,ACGreen);

    isFinished_ = true;
    currentOperation_ = "Analyses completed!";
    STDLINE(currentOperation_,ACGreen);
}
コード例 #10
0
ファイル: pos.cpp プロジェクト: wk1984/gimli
void saveRVector3(const std::vector < RVector3 > l, const std::string & fileName){
    std::fstream file; openOutFile(fileName, & file);
    for (uint i = 0; i < l.size(); i ++) file << l[i] << std::endl;
    file.close();
}
コード例 #11
0
ファイル: whdread.c プロジェクト: hcs64/vgm_ripping
int main(int argc, char * argv[]) {
    FILE * inwhd, * inwav = NULL, * instream, * outfile;
    int offset,type,fileoffset,filesize;
    unsigned char buf[16],namebuf[256];
    int i;

    printf("whdread 0.2\n\n");

    if (argc != 3 && argc != 4) {
	fprintf(stderr,"Usage: whdread foo.WHD streams.wav [foo.WAV]\n");
	return 1;
    }
    inwhd = fopen(argv[1],"rb");
    if (!inwhd) {
	fprintf(stderr,"Error opening %s for reading\n",argv[1]);
	return 1;
    }
    instream = fopen(argv[2],"rb");
    if (!instream) {
	fprintf(stderr,"Error opening %s for reading\n",argv[2]);
	return 1;
    }
    if (argc == 4) {
	inwav = fopen(argv[3],"rb");
	if (!inwav) {
	    fprintf(stderr,"Error opening %s for reading\n",argv[3]);
	    return 1;
	}
    } else {
	char * t;
	t=strrchr(argv[1],'.');
	if (!t) {fprintf(stderr,"couldn't guess a corresponding WAV for %s\n",argv[1]); return 1;}
	t[1]='W';
	t[2]='A';
	t[3]='V';
	printf("Guessing %s as wav\n",argv[1]);
	inwav = fopen(argv[1],"rb");
	if (!inwav) {
	    fprintf(stderr,"Error opening %s for reading\n",argv[1]);
	    /*return 1;*/
	}
    }

    fseek(inwhd,0,SEEK_SET);
    fread(buf,1,8,inwhd);

    printf("WHD Size: %d\nLast offset: 0x%x\n\n",get32bit(buf+4),get32bit(buf));

    offset=get32bit(buf);
    fseek(inwhd,offset-4,SEEK_SET); /* seek to last offset */

    while (fread(buf,1,4,inwhd)==4) {
	type=get32bit(buf);
	if (type==0) { /* DSP */
	    int i;
	    int coef;
	    char headbuf[0x60];
	    fseek(inwhd,offset-8,SEEK_SET);
	    fread(buf,1,4,inwhd);
	    coef=get32bit(buf); /* offset of DSP coefficients */
	    offset=coef-1;
	    fseek(inwhd,coef+0x50,SEEK_SET);
	    fread(buf,1,8,inwhd);
	    fileoffset=get32bit(buf);
	    filesize=(get32bit(buf+4)/14+1)*8;
	    fseek(inwhd,offset,SEEK_SET);
	    offset=getNameBackwards(inwhd,namebuf,sizeof(namebuf));

	    fseek(inwhd,coef,SEEK_SET);

	    /* do nothing if file already exists */
	    if (inwav && !openOutFile((char*)namebuf,&outfile)) {
		if (!outfile) {
		    fprintf(stderr,"Error opening %s for output\n",namebuf);
		    return 1;
		}

		fread(headbuf,1,0x60,inwhd);
		fwrite(headbuf,1,0x60,outfile);

		fseek(inwav,fileoffset,SEEK_SET);

		for (i=filesize;i>=16;i-=16) {
		    fread(buf,1,16,inwav);
		    fwrite(buf,1,16,outfile);
		}
		if (i) {
		    fread(buf,1,i,inwav);
		    fwrite(buf,1,i,outfile);
		}

		fclose(outfile);
	    }
	} else if (type==1) { /* 16-bit big endian PCM */
	    int oldoffset,i;
	    char headbuf[0x30];
	    offset-=0x32;
	    fseek(inwhd,offset+0x22,SEEK_SET);
	    fread(buf,1,8,inwhd);
	    fileoffset=get32bit(buf);
	    filesize=get32bit(buf+4)*2; /* counted in samples */
	    fseek(inwhd,offset,SEEK_SET);
	    oldoffset=offset;
	    offset=getNameBackwards(inwhd,namebuf,sizeof(namebuf));

	    fseek(inwhd,oldoffset+2,SEEK_SET);

	    /* do nothing if file already exists */
	    if (!openOutFile((char*)namebuf,&outfile)) {
		if (!outfile) {
		    fprintf(stderr,"Error opening %s for output\n",namebuf);
		    return 1;
		}

		fread(headbuf,1,0x30,inwhd);
		fwrite(headbuf,1,0x30,outfile);

		fseek(instream,fileoffset,SEEK_SET);

		for (i=filesize;i>=16;i-=16) {
		    fread(buf,1,16,instream);
		    fwrite(buf,1,16,outfile);
		}
		if (i) {
		    fread(buf,1,i,instream);
		    fwrite(buf,1,i,outfile);
		}

		fclose(outfile);
	    }
	    
	} else break;

	if (type==0) {
	    printf("****\ntype=DSP\nname=%s\n",namebuf);
	    printf("offset=0x%x\nsize=0x%x\n",fileoffset,filesize);
	}
	if (type==1) {
	    printf("****\ntype=PCM\nname=%s\n",namebuf);
	    printf("offset=0x%x\nsize=0x%x\n",fileoffset,filesize);
	}
	printf("\n");

	fseek(inwhd,offset-4,SEEK_SET);
    }

    return 0;
}