Exemple #1
0
int load_file(Computer* comp, const char* name, int id, int drv) {
	QString path = QDialog::trUtf8(name);
	QString flt;
	QString ext;
	xFileTypeInfo* inf;
	xFileGroupInfo* grp = &fg_dum;
	if (id == FG_DISK)
		id = disk_id[drv & 3];
	if (id == FG_ALL)
		id = detect_hw_id(comp->hw->id);
	int err = ERR_OK;
	if (path.isEmpty()) {
		flt = file_get_hw_filter(comp, id, 0);
		if (flt.isEmpty()) {
			flt = file_get_group_filter(comp, id, 0);
			if (flt.isEmpty())
				flt = file_get_type_filter(id, 0);
		}
		if (!flt.isEmpty()) {
			filer->setWindowTitle("Open file");
			filer->setNameFilter(flt);
			filer->setDirectory(conf.path.lastDir);
			filer->setAcceptMode(QFileDialog::AcceptOpen);
			filer->setHistory(QStringList());
			if (filer->exec()) {
				path = filer->selectedFiles().first();
				flt = filer->selectedNameFilter();
				grp = file_detect_grp(flt);
				drv = grp->drv;
			}
			strcpy(conf.path.lastDir, filer->directory().absolutePath().toLocal8Bit().data());
		}
	}
	if (path.isEmpty()) return err;
	inf = file_ext_type(path);
	if (grp->id == FG_RAW)
		inf = &ft_raw;
	if (drv < 0) drv = 0;
	if (inf) {
		if (inf->load) {
			if (inf->ch) {
				if (saveChangedDisk(comp, drv)) {
					err = inf->load(comp, path.toLocal8Bit().data(), drv);
					disk_boot(comp, drv, inf->id);
				} else {
					err = ERR_OK;
				}
			} else {
				err = inf->load(comp, path.toLocal8Bit().data(), drv);
				disk_boot(comp, drv, inf->id);
			}
		}
	}
	file_errors(err);
	return err;
}
Exemple #2
0
int main() {
    /* Implementation defined. Set this to your initial id. */
    if (sos_my_id() != 0) {
        printf("I am a child with pid: %d.\n", sos_my_id());
        /* Try to delete our parent. Once again this is implementation defined.*/
        assert(sos_process_delete(sos_my_id() - 1) == -1);
        assert(sos_process_wait(sos_my_id() - 1) == -1);
        printf("Child test exited successfully.\n");
        return 0;
    }

    printf("Running timer error tests.\n");
    timer_errors();
    printf("Timer error tests passed.\n");

    printf("Running file error tests.\n");
    file_errors();
    printf("File error tests passed.\n");

    printf("Running memory error tests.\n");
    printf("Warning: Here be implementation specific dragons.\n");
    memory_errors();
    printf("Memory error tests passed.\n");

    printf("Running process error tests.\n");
    process_errors();
    printf("Process error tests passed.\n");

    // TODO(karl): Write share vm tests.

    printf("Running crash tests. You need to manually comment out individual lines.\n");
    crash_errors();
    assert(!"Crash tests failed you should never get here!\n");

    return 0;
}
Exemple #3
0
int save_file(Computer* comp, const char* name, int id, int drv) {
	QString path = QDialog::trUtf8(name);
	QString flt;
	QString ext;
	xFileTypeInfo* inf = NULL;
	xFileTypeInfo* tin;
	xFileGroupInfo* grp;
	int i;
	int flg;
	if (id == FG_DISK)
		id = disk_id[drv & 3];
	if (id == FG_ALL)
		id = detect_hw_id(comp->hw->id);
	int err = ERR_OK;
	if (path.isEmpty()) {
		flt = file_get_hw_filter(comp, id, 1);
		if (flt.isEmpty()) {
			flt = file_get_group_filter(comp, id, 1);
			if (flt.isEmpty())
				flt = file_get_type_filter(id, 1);
		}
		if (!flt.isEmpty()) {
			filer->setWindowTitle("Save file");
			filer->setNameFilter(flt);
			filer->setAcceptMode(QFileDialog::AcceptSave);
			filer->setDirectory(conf.path.lastDir);
			filer->setHistory(QStringList());
			if (filer->exec()) {
				path = filer->selectedFiles().first();
				flt = filer->selectedNameFilter();
				grp = file_detect_grp(flt);
				if (grp->id != FL_NONE) {
					drv = grp->drv;
					i = 0;
					flg = 1;
					// scan group file types and check if path extension is the same
					while ((grp->child[i] != FL_NONE) && flg) {
						tin = file_find_type(grp->child[i]);
						if (tin) {
							if (path.endsWith(tin->ext, Qt::CaseInsensitive)) {
								flg = 0;
								inf = tin;
							}
						}
						i++;
					}
					// if no filetypes found, add default extension
					if (flg) {
						path.append(grp->defext);
					}
				} else {
					tin = file_detect_type(flt);
					if (tin->id != FL_NONE) {
						path.append(tin->ext);
					}
				}
			}
			strcpy(conf.path.lastDir, filer->directory().absolutePath().toLocal8Bit().data());
		}
	}
	if (path.isEmpty()) return err;
	if (drv < 0)
		drv = 0;
	if (!inf)
		inf = file_ext_type(path);
	if (inf) {
		if (inf->save) {
			err = inf->save(comp, path.toLocal8Bit().data(), drv);
		} else {
			shitHappens("Can't save that");
		}
	} else {
		shitHappens("Don't know such extension");
	}
	file_errors(err);
	return err;
}