Esempio n. 1
0
int main(int argc, const char * argv[])
{
    
    //
    //  Set up the file and a line buffer
    //

    ifstream records;
    std::string fileName = "Input.txt";
    
    if(!openInputStream(records, fileName)){
        std::cout << "Couldn't open " << fileName << std::endl;
        throw runtime_error("Couldn't open " + fileName);
    }
    
    std::string line;
    
    //
    //  Skip the first two lines, they're whitespace
    //
    
    getline(records, line);
    getline(records, line);

    //
    //  Create a storekeeper instance to process sales.
    //
    
    Storekeeper *shop = new Storekeeper();
    
    //
    //  Process the input files.
    //
    
    while (getline(records, line)) {
        
        Record r = Record(line);
        
        if (r.getRecordType() == kRecordTypePromotion) {
            shop->setPromotionRate(r.getSaleAmount());
            shop->beginPromotion();
        }
        else if(r.getRecordType() == kRecordTypeSale){
            shop->sellWidgets(r.getQuantity());
        }
        else if(r.getRecordType() == kRecordTypeReciept){
            shop->receiveNumWidgetsAtPrice(r.getQuantity(), r.getPricePerWidget());
        }
    }
    
    shop->printOverstock();
    
    return 0;
}
Esempio n. 2
0
int compile(char *fileName) {
  if (openInputStream(fileName) == IO_ERROR)
    return IO_ERROR;

  currentToken = NULL;
  lookAhead = getValidToken();

  compileProgram();

  free(currentToken);
  free(lookAhead);
  closeInputStream();
  return IO_SUCCESS;
}
Esempio n. 3
0
int scan(char *fileName) {
  Token *token;

  if (openInputStream(fileName) == IO_ERROR)
    return IO_ERROR;

  token = getToken();
  while (token->tokenType != TK_EOF) {
    printToken(token);
    free(token);
    token = getToken();
  }

  free(token);
  closeInputStream();
  return IO_SUCCESS;
}
Esempio n. 4
0
int compile(char *fileName) {
  if (openInputStream(fileName) == IO_ERROR)
    return IO_ERROR;

  currentToken = NULL;
  lookAhead = getValidToken();

  initSymTab();

  compileProgram();

  printObject(symtab->program,0);

  cleanSymTab();
  free(currentToken);
  free(lookAhead);
  closeInputStream();
  return IO_SUCCESS;

}
Esempio n. 5
0
void decodeStart(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) {
        int ret;
        InputStream inStream;
        InputPlugin * plugin = NULL;
        char * path;

        if(isRemoteUrl(pc->utf8url)) {
                path = utf8StrToLatin1Dup(pc->utf8url);
        }
	else path = strdup(rmp2amp(utf8ToFsCharset(pc->utf8url)));

	if(!path) {
		dc->error = DECODE_ERROR_FILE;
		dc->state = DECODE_STATE_STOP;
		dc->start = 0;
                return;
	}

	copyMpdTagToOutputBuffer(cb, NULL);

        strncpy(dc->utf8url, pc->utf8url, MAXPATHLEN);
	dc->utf8url[MAXPATHLEN] = '\0';

        if(openInputStream(&inStream, path) < 0) {
		dc->error = DECODE_ERROR_FILE;
		dc->state = DECODE_STATE_STOP;
		dc->start = 0;
		free(path);
                return;
        }

        dc->seekable = inStream.seekable;
        dc->state = DECODE_STATE_START;
	dc->start = 0;

        while(!inputStreamAtEOF(&inStream) && bufferInputStream(&inStream) < 0
                        && !dc->stop)
	{
		/* sleep so we don't consume 100% of the cpu */
//		fprintf(stderr,"In decode.c decodeParent decode start func\r\n");
	//	my_usleep(1000);
	}

        if(dc->stop) {
                dc->state = DECODE_STATE_STOP;
                dc->stop = 0;
		free(path);
                return;
        }

        /*if(inStream.metaName) {
		MpdTag * tag = newMpdTag();
		tag->name = strdup(inStream.metaName);
		copyMpdTagToOutputBuffer(cb, tag);
		freeMpdTag(tag);
        }*/

	/* reset Metadata in OutputBuffer */

        ret = DECODE_ERROR_UNKTYPE;
	if(isRemoteUrl(dc->utf8url)) {
		cb->acceptMetadata = 1;
		plugin = getInputPluginFromMimeType(inStream.mime);
                if(plugin == NULL) {
                        plugin = getInputPluginFromSuffix(
                                        getSuffix(dc->utf8url));
                }
                /* this is needed for bastard streams that don't have a suffix
                                or set the mimeType */
                if(plugin == NULL) {
                        plugin = getInputPluginFromName("mp3");
                }
                if(plugin && (plugin->streamTypes & INPUT_PLUGIN_STREAM_URL) &&
                                plugin->streamDecodeFunc) 
                {
                        ret = plugin->streamDecodeFunc(cb, dc, &inStream);
                }
	}
        else {
		cb->acceptMetadata = 0;
                plugin = getInputPluginFromSuffix(getSuffix(dc->utf8url));
                if(plugin && (plugin->streamTypes && INPUT_PLUGIN_STREAM_FILE))
                {
                        if(plugin->streamDecodeFunc) {
                                ret = plugin->streamDecodeFunc(cb, dc, 
                                                &inStream);
                        }
                        else if(plugin->fileDecodeFunc) {
                                closeInputStream(&inStream);
                                ret = plugin->fileDecodeFunc(cb, dc, path);
                        }
                }
        }

	if(ret<0 || ret == DECODE_ERROR_UNKTYPE) {
		strncpy(pc->erroredUrl, dc->utf8url, MAXPATHLEN);
		pc->erroredUrl[MAXPATHLEN] = '\0';
		if(ret != DECODE_ERROR_UNKTYPE) dc->error = DECODE_ERROR_FILE;
                else {
                        dc->error = DECODE_ERROR_UNKTYPE;
                        closeInputStream(&inStream);
                }
		dc->stop = 0;
		dc->state = DECODE_STATE_STOP;
	}

	free(path);
}