Example #1
0
void project(struct dbSysHead *head, relation *temp_datadic, relation *result){
	int original_rec_length = temp_datadic->getRecordLength(); //record_length in original table
	int new_rec_length = result->getRecordLength();   //each record length in new temp table, in case SPJ use
	//look up which buffer is empty
	int buffer_id_;
	int i;
	for (i = 0; i < 3; i++) {
		if (head->buff[i].emptyOrnot == true) {
			buffer_id_ = i;
			head->buff[i].emptyOrnot = false;   // ready for writein
			std::cout << "bufferID: " << i << std::endl;
			break;
		}
	}
	if (i == 3) {
		cout << "No Buffer Can be Used!" << endl;
	}
	else{
		//RecordCursor scanTable(head, temp_datadic->fileID, original_rec_length, -temp_datadic->fileID);
		RecordCursorTmp scanTable(head, temp_datadic->fileID, original_rec_length, -temp_datadic->fileID, temp_datadic->getRecordNum());
		cout << 1 << endl;
		char * one_Row_ = (char *)malloc(sizeof(char) * original_rec_length);
		char * new_Row_ = (char *)malloc(sizeof(char) * new_rec_length);
		Buffer t(head, -2); //to avoid positive number, no meaning
		int k = 0;
		while (true == scanTable.getNextRecord(one_Row_)) { //only scan
			k++;
			for (int ptr1 = 0, ptr2 = 0; ptr1 < temp_datadic->getAttributeNum() && ptr2 < result->getAttributeNum();){
				int offset1 = temp_datadic->getAttributeByNo(ptr1).getRecordDeviation();
				int offset2 = result->getAttributeByNo(ptr2).getRecordDeviation();
				if (strcmp(temp_datadic->getAttributeByNo(ptr1).getName(), result->getAttributeByNo(ptr2).getName()) == 0)
				{
					strncpy(new_Row_ + offset2, one_Row_ + offset1, result->getAttributeByNo(ptr2).getLength());
					if (result->getAttributeByNo(ptr2).getType() == 1){
						int value = *((int *)(new_Row_ + offset2));
						cout << ptr2 << ":" << value << endl;
					}
					if (result->getAttributeByNo(ptr2).getType() == 2){
						char * valuechar = (char *)malloc(sizeof(char)*result->getAttributeByNo(ptr2).getLength());
						memcpy(valuechar, new_Row_ + offset2, result->getAttributeByNo(ptr2).getLength());
						cout << ptr2 << ":" << valuechar << endl;
						free(valuechar);
					}
					ptr1++;
					ptr2++;
				}
				else
				{
					ptr1++;
				}
			}
			//if more than one page, write to file and reset Buffer t
			if (false == t.AppendBuffer(new_Row_, new_rec_length))
			{
				t.writeBufferPage(t.filehead, buffer_id_, t.data_, t.current_size_);
				t.pageID++;
				if (t.pageID == SIZE_BUFF) {
					std::cout << "this buffer full" << std::endl;
					break;
				}
				memset(t.data_, 0, SIZE_PER_PAGE);
				memcpy(t.data_, new_Row_, new_rec_length);
				t.pointer_ = t.data_ + new_rec_length;
				t.current_size_ = new_rec_length;
			}

		}
		//write remainder
		t.writeBufferPage(t.filehead, buffer_id_, t.data_, t.current_size_);
		result->fileID = -buffer_id_;
		head->buff[-temp_datadic->fileID].emptyOrnot = true;
		free(one_Row_);
		free(new_Row_);
		//        temp_datadic[dictID].recordLength = size_per_record;
		//        strcpy(temp_datadic[dictID].relationName ,"temp datadict 1");
	}
}
QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes()
{
    switch (currentNode->id) {
        case Html_body:
            if (currentNode->charFormat.background().style() != Qt::NoBrush) {
                QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
                fmt.setBackground(currentNode->charFormat.background());
                doc->rootFrame()->setFrameFormat(fmt);
                const_cast<QTextHtmlParserNode *>(currentNode)->charFormat.clearProperty(QTextFormat::BackgroundBrush);
            }
            break;

        case Html_ol:
        case Html_ul: {
            QTextListFormat::Style style = currentNode->listStyle;

            if (currentNode->id == Html_ul && !currentNode->hasOwnListStyle && currentNode->parent) {
                const QTextHtmlParserNode *n = &at(currentNode->parent);
                while (n) {
                    if (n->id == Html_ul) {
                        style = nextListStyle(currentNode->listStyle);
                    }
                    if (n->parent)
                        n = &at(n->parent);
                    else
                        n = 0;
                }
            }

            QTextListFormat listFmt;
            listFmt.setStyle(style);

            ++indent;
            if (currentNode->hasCssListIndent)
                listFmt.setIndent(currentNode->cssListIndent);
            else
                listFmt.setIndent(indent);

            List l;
            l.format = listFmt;
            l.listNode = currentNodeIdx;
            lists.append(l);
            compressNextWhitespace = true;

            // broken html: <ul>Text here<li>Foo
            const QString simpl = currentNode->text.simplified();
            if (simpl.isEmpty() || simpl.at(0).isSpace())
                return ContinueWithNextNode;
            break;
        }

        case Html_table: {
            Table t = scanTable(currentNodeIdx);
            tables.append(t);
            hasBlock = false;
            return ContinueWithNextNode;
        }

        case Html_tr:
            return ContinueWithNextNode;

        case Html_img: {
            QTextImageFormat fmt;
            fmt.setName(currentNode->imageName);

            fmt.merge(currentNode->charFormat);

            if (currentNode->imageWidth >= 0)
                fmt.setWidth(currentNode->imageWidth);
            if (currentNode->imageHeight >= 0)
                fmt.setHeight(currentNode->imageHeight);

            cursor.insertImage(fmt, QTextFrameFormat::Position(currentNode->cssFloat));

            cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
            cursor.mergeCharFormat(currentNode->charFormat);
            cursor.movePosition(QTextCursor::Right);

            hasBlock = false;
            return ContinueWithNextNode;
        }

        case Html_hr: {
            QTextBlockFormat blockFormat = currentNode->blockFormat;
            blockFormat.setTopMargin(topMargin(currentNodeIdx));
            blockFormat.setBottomMargin(bottomMargin(currentNodeIdx));
            blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, currentNode->width);
            if (hasBlock && importMode == ImportToDocument)
                cursor.mergeBlockFormat(blockFormat);
            else
                appendBlock(blockFormat);
            hasBlock = false;
            return ContinueWithNextNode;
        }

        default: break;
    }
    return ContinueWithCurrentNode;
}
Example #3
0
main(int argc, char** argv) {
    int excludes = 0;

    program = argv[0];

    while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
        switch ((*argv)[1]) {
        case 'd':
        {
            --argc,++argv;
            if (argc == 0) {
                usage();
                exit(-1);
            }
            File f(*argv);
            if (!f.exists()) {
                fprintf(stderr, "Directory %s doesn\'t exist", *argv);
                fprintf(stderr, " (or needs to be file-name-expanded).\n");
                usage();
                exit(-1);
            }
            dirs.working = *argv;
        }
        break;
        case 'n':
            do_echo  = 1;
            break;
        case 's':
            save     = 0;
            break;
        case 'v':
            verbose  = 1;
            break;
        case 'e':
            excludes = 1;
            break;
        case 'r':
        {
            --argc,++argv;
            if (argc == 0) {
                usage();
                exit(-1);
            }
            forced_revision_number = *argv;
        }
        break;
        case 't':
        {
            --argc,++argv;
            if (argc == 0) {
                usage();
                exit(-1);
            }
            forced_revision_date = *argv;
        }
        break;
        case 'h':
            usage();
            exit(0);
        case '\0':
            goto done;
        default:
            fprintf(stderr, "Option %s unknown.\n", *argv);
            usage();
            exit(-1);
        }
    }
done:
    ;

    dirs.initialize();

    File statusfile(dirs.baseline, dirs.subdir->path, ".file_status");
    readBaseFileStatus(statusfile.path);

    if (excludes) {
        // process all files, excluding listed files
        stringNode* node;
        for(; argc>=1; --argc,++argv) {
            if (node = table.lookup(*argv)) {
                node->mark();
            }
        }
        processAllFilesInDir();
        scanTable();
    } else if (argc > 0) {
        // process only listed files
        for (; argc>=1; --argc,++argv) {
            processFileArgument(*argv);
        }
    } else {
        // normal case; process all files
        processAllFilesInDir();
        scanTable();
    }

    exit(0);
}