Esempio n. 1
0
FILE *os2_fopen (const char *fname, const char *mode)
{
  char *new_fname = convert_filename (fname, alloca (MAXPATHLEN + 1), MAXPATHLEN + 1);

  if (!new_fname)
    return (NULL);

#undef fopen
  return fopen (new_fname, mode);
}
Esempio n. 2
0
uint8 FSDrive::open_file(int channel, char *filename)
{
	char plainname[NAMEBUF_LENGTH];
	int filemode = FMODE_READ;
	int filetype = FTYPE_PRG;
	bool wildflag = false;
	char *mode = "rb";
	
	convert_filename(filename, plainname, &filemode, &filetype, &wildflag);

	// Channel 0 is READ PRG, channel 1 is WRITE PRG
	if (!channel) {
		filemode = FMODE_READ;
		filetype = FTYPE_PRG;
	}
	if (channel == 1) {
		filemode = FMODE_WRITE;
		filetype = FTYPE_PRG;
	}

	// Wildcards are only allowed on reading
	if (wildflag) {
		if (filemode != FMODE_READ) {
			set_error(ERR_SYNTAX33);
			return ST_OK;
		}
		find_first_file(plainname);
	}

	// Select fopen() mode according to file mode
	switch (filemode) {
		case FMODE_READ:
			mode = "rb";
			break;
		case FMODE_WRITE:
			mode = "wb";
			break;
		case FMODE_APPEND:
			mode = "ab";
			break;
	}

	// Open file
	if (chdir(dir_path))
		set_error(ERR_NOTREADY);
	else if ((file[channel] = fopen(plainname, mode)) != NULL) {
		if (filemode == FMODE_READ)	// Read and buffer first byte
			read_char[channel] = fgetc(file[channel]);
	} else
		set_error(ERR_FILENOTFOUND);
	chdir(AppDirPath);

	return ST_OK;
}
Esempio n. 3
0
uint8 T64Drive::open_file(int channel, char *filename)
{
    char plainname[NAMEBUF_LENGTH];
    int filemode = FMODE_READ;
    int filetype = FTYPE_PRG;
    int num;

    convert_filename(filename, plainname, &filemode, &filetype);

    // Channel 0 is READ PRG, channel 1 is WRITE PRG
    if (!channel) {
        filemode = FMODE_READ;
        filetype = FTYPE_PRG;
    }
    if (channel == 1) {
        filemode = FMODE_WRITE;
        filetype = FTYPE_PRG;
    }

    // Allow only read accesses
    if (filemode != FMODE_READ) {
        set_error(ERR_WRITEPROTECT);
        return ST_OK;
    }

    // Find file
    if (find_first_file(plainname, filetype, &num)) {

        // Open temporary file
        if ((file[channel] = tmpfile()) != NULL) {

            // Write load address (.t64 only)
            if (!is_lynx) {
                fwrite(&file_info[num].sa_lo, 1, 1, file[channel]);
                fwrite(&file_info[num].sa_hi, 1, 1, file[channel]);
            }

            // Copy file contents from .t64 file to temp file
            uint8 *buf = new uint8[file_info[num].length];
            fseek(the_file, file_info[num].offset, SEEK_SET);
            fread(buf, file_info[num].length, 1, the_file);
            fwrite(buf, file_info[num].length, 1, file[channel]);
            rewind(file[channel]);
            delete[] buf;

            if (filemode == FMODE_READ)	// Read and buffer first byte
                read_char[channel] = fgetc(file[channel]);
        }
    } else
        set_error(ERR_FILENOTFOUND);

    return ST_OK;
}
Esempio n. 4
0
int os2_open (const char *name, int oflag,...)
{
  va_list va;
  int h;
  char *new_name = convert_filename (name, alloca (MAXPATHLEN + 1), MAXPATHLEN + 1);

  if (!new_name)
    return (-1);

  va_start (va, oflag);
  h = _vsopen (new_name, oflag, SH_DENYNO, va);
  va_end (va);
  return h;
}
Esempio n. 5
0
int convert_intl(char *in_filename, char *out_filename, char *src, char *dst)
{
    struct stat statbuf;
    FILE *infile, *outfile;
    char *real_out_filename;

    if (stat(in_filename, &statbuf) < 0) {
        printf("cannot stat %s\n", in_filename);
        return 0;
    }

    if (statbuf.st_size == 0) {
        printf("file %s is 0 bytes\n", in_filename);
        return 0;
    }

    infile = fopen(in_filename, "rb");
    if (infile == NULL) {
        printf("cannot open %s for reading\n", in_filename);
        return 0;
    }

    real_out_filename = convert_filename(out_filename, src, dst);

    outfile = fopen(real_out_filename, "wb");
    if (outfile == NULL) {
        printf("cannot open %s for writing\n", real_out_filename);
        free(real_out_filename);
        fclose(infile);
        return 0;
    }

    while (!feof(infile)) {
        getline_simple(infile);
        if (!feof(infile)) {
            if (!strncmp(line_buffer, "/* en */" ,8)) {
                strip_comments(line_buffer);
                replace_string(line_buffer,outfile);
            } else {
                strip_comments(line_buffer);
                fprintf(outfile,"%s",line_buffer);
            }
        }
    }
    fclose(infile);
    fclose(outfile);
    free(real_out_filename);
    return 1;
}
Esempio n. 6
0
uint8 FSDrive::open_directory(int channel, char *filename)
{
	char buf[] = "\001\004\001\001\0\0\022\042                \042 00 2A";
	char str[NAMEBUF_LENGTH];
	char pattern[NAMEBUF_LENGTH];
	char *p, *q;
	int i;
	int filemode;
	int filetype;
	bool wildflag;

	DIR *dir;
	struct dirent *de;
	struct stat statbuf;

	// Special treatment for "$0"
	if (filename[0] == '0' && filename[1] == 0)
		filename += 1;

	// Convert filename ('$' already stripped), filemode/type are ignored
	convert_filename(filename, pattern, &filemode, &filetype, &wildflag);

	// Open directory for reading and skip '.' and '..'
	if ((dir = opendir(dir_path)) == NULL) {
		set_error(ERR_NOTREADY);
		return ST_OK;
	}
	de = readdir(dir);
	while (de && (0 == strcmp(".", de->d_name) || 0 == strcmp("..", de->d_name))) 
		de = readdir(dir);

	// Create temporary file
	if ((file[channel] = tmpfile()) == NULL) {
		closedir(dir);
		return ST_OK;
	}

	// Create directory title
	p = &buf[8];
	for (i=0; i<16 && dir_title[i]; i++)
		*p++ = conv_to_64(dir_title[i], false);
	fwrite(buf, 1, 32, file[channel]);

	// Create and write one line for every directory entry
	while (de) {

		// Include only files matching the pattern
		if (match(pattern, de->d_name)) {

			// Get file statistics
			chdir(dir_path);
			stat(de->d_name, &statbuf);
			chdir(AppDirPath);

			// Clear line with spaces and terminate with null byte
			memset(buf, ' ', 31);
			buf[31] = 0;

			p = buf;
			*p++ = 0x01;	// Dummy line link
			*p++ = 0x01;

			// Calculate size in blocks (254 bytes each)
			i = (statbuf.st_size + 254) / 254;
			*p++ = i & 0xff;
			*p++ = (i >> 8) & 0xff;

			p++;
			if (i < 10) p++;	// Less than 10: add one space
			if (i < 100) p++;	// Less than 100: add another space

			// Convert and insert file name
			strcpy(str, de->d_name);
			*p++ = '\"';
			q = p;
			for (i=0; i<16 && str[i]; i++)
				*q++ = conv_to_64(str[i], true);
			*q++ = '\"';
			p += 18;

			// File type
			if (S_ISDIR(statbuf.st_mode)) {
				*p++ = 'D';
				*p++ = 'I';
				*p++ = 'R';
			} else {
				*p++ = 'P';
				*p++ = 'R';
				*p++ = 'G';
			}

			// Write line
			fwrite(buf, 1, 32, file[channel]);
		}

		// Get next directory entry
		de = readdir(dir);
	}
Esempio n. 7
0
int convert_rc(char *in_filename, char *out_filename, char *src, char *dst)
{
    struct stat statbuf;
    FILE *infile, *outfile;
    int status = SCANNING;
    int found = UNKNOWN;
    int stringtable_found = 0;
    char *real_out_filename;

    if (stat(in_filename, &statbuf) < 0) {
        printf("cannot stat %s\n", in_filename);
        return 0;
    }

    if (statbuf.st_size == 0) {
        printf("file %s is 0 bytes\n", in_filename);
        return 0;
    }

    infile = fopen(in_filename, "rb");
    if (infile == NULL) {
        printf("cannot open %s for reading\n", in_filename);
        return 0;
    }

    real_out_filename = convert_filename(out_filename, src, dst);

    outfile = fopen(real_out_filename, "wb");
    if (outfile == NULL) {
        printf("cannot open %s for writing\n", real_out_filename);
        fclose(infile);
        free(real_out_filename);
        return 0;
    }

    while (!feof(infile)) {
        found = intl2po_getline(infile);
        switch(found) {
            case FOUND_STRINGTABLE:
                if (stringtable_found == 0) {
                    if (status != SCANNING) {
                        wrong_location("STRINGTABLE", infile, outfile, in_filename);
                        return 0;
                    }
                    status = STRINGTABLE_BEGIN_SCAN;
                    fprintf(outfile, "%s", line_buffer);
                } else {
                    fprintf(outfile, "%s", line_buffer);
                    intl2po_getline(infile);
                    if (!strncmp(line_buffer, "LANGUAGE LANG_ENGLISH", 21)) {
                        status = STRINGTABLE_BEGIN_SCAN;
                    }
                    fprintf(outfile, "%s", line_buffer);
                }
                break;
            case FOUND_MENU:
                if (status != SCANNING) {
                    wrong_location("MENU", infile, outfile, in_filename);
                    return 0;
                } else {
                    if (language_id(line_buffer) == 0) {
                        status = MENU_BEGIN_SCAN;
                    }
                    fprintf(outfile, "%s", line_buffer);
                }
                break;
            case FOUND_DIALOG:
                if (status != SCANNING) {
                    printf("%s", line_buffer);
                    wrong_location("DIALOG", infile, outfile, in_filename);
                    return 0;
                } else {
                    if (language_id(line_buffer) == 0) {
                        status = DIALOG_BEGIN_SCAN;
                    }
                    fprintf(outfile, "%s", line_buffer);
                }
                break;
            case FOUND_CAPTION:
                if (status == DIALOG_BEGIN_SCAN) {
                    replace_string(line_buffer, outfile);
                } else {
                    fprintf(outfile, "%s", line_buffer);
                }
                break;
            case FOUND_BEGIN:
                switch (status) {
                    case STRINGTABLE_BEGIN_SCAN:
                        stringtable_found = 1;
                        status = TEXT_CONVERSION;
                        break;
                    case MENU_BEGIN_SCAN:
                    case DIALOG_BEGIN_SCAN:
                        status = TEXT_CONVERSION;
                        break;
                }
                fprintf(outfile, "%s", line_buffer);
                break;
            case FOUND_END:
                status = SCANNING;
                fprintf(outfile, "%s", line_buffer);
                break;
            default:
                switch (status) {
                    case TEXT_CONVERSION:
                        replace_string(line_buffer, outfile);
                        break;
                    case SCANNING:
                        if (!feof(infile)) {
                            fprintf(outfile,"%s",line_buffer);
                        }
                        break;
                }
        }
    }
    fclose(infile);
    fclose(outfile);
    free(real_out_filename);
    return 1;
}
Esempio n. 8
0
uint8 T64Drive::open_directory(int channel, char *filename)
{
    char buf[] = "\001\004\001\001\0\0\022\042                \042 00 2A";
    char str[NAMEBUF_LENGTH];
    char pattern[NAMEBUF_LENGTH];
    char *p, *q;
    int i, num;
    int filemode;
    int filetype;

    // Special treatment for "$0"
    if (strlen(filename) == 1 && filename[0] == '0')
        filename += 1;

    // Convert filename ('$' already stripped), filemode/type are ignored
    convert_filename(filename, pattern, &filemode, &filetype);

    // Create temporary file
    if ((file[channel] = tmpfile()) == NULL)
        return ST_OK;

    // Create directory title
    p = &buf[8];
    for (i=0; i<16 && dir_title[i]; i++)
        *p++ = dir_title[i];
    fwrite(buf, 1, 32, file[channel]);

    // Create and write one line for every directory entry
    for (num=0; num<num_files; num++) {

        // Include only files matching the pattern
        if (match(pattern, file_info[num].name)) {

            // Clear line with spaces and terminate with null byte
            memset(buf, ' ', 31);
            buf[31] = 0;

            p = buf;
            *p++ = 0x01;	// Dummy line link
            *p++ = 0x01;

            // Calculate size in blocks (254 bytes each)
            i = (file_info[num].length + 254) / 254;
            *p++ = i & 0xff;
            *p++ = (i >> 8) & 0xff;

            p++;
            if (i < 10) p++;	// Less than 10: add one space
            if (i < 100) p++;	// Less than 100: add another space

            // Convert and insert file name
            strcpy(str, file_info[num].name);
            *p++ = '\"';
            q = p;
            for (i=0; i<16 && str[i]; i++)
                *q++ = str[i];
            *q++ = '\"';
            p += 18;

            // File type
            switch (file_info[num].type) {
            case FTYPE_PRG:
                *p++ = 'P';
                *p++ = 'R';
                *p++ = 'G';
                break;
            case FTYPE_SEQ:
                *p++ = 'S';
                *p++ = 'E';
                *p++ = 'Q';
                break;
            case FTYPE_USR:
                *p++ = 'U';
                *p++ = 'S';
                *p++ = 'R';
                break;
            case FTYPE_REL:
                *p++ = 'R';
                *p++ = 'E';
                *p++ = 'L';
                break;
            default:
                *p++ = '?';
                *p++ = '?';
                *p++ = '?';
                break;
            }

            // Write line
            fwrite(buf, 1, 32, file[channel]);
        }
    }