⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mkrom.c

📁 ertfs文件系统里面既有完整ucos程序
💻 C
📖 第 1 页 / 共 2 页
字号:
            }
            else
            {
                n_files += 1;
                n_file_clusters += (long) bytes_to_clusters(statobj.size);
                pkind = "-";
            }
            // matches unix output.
            for (i = 0; i < level; i++)
                printf(" ");
            printf("%s  %8ld  %-12s\r", pkind, statobj.size,statobj.name);
#if (SUPPORT_WIN95)
        } while (_findnext(dd, &statobj) == 0);
        
        _findclose(dd);
#else
        } while (_dos_findnext(&statobj) == 0);
#endif
    }
    /* Track root entries and blocks used by dir ents */
    n_dir_clusters += dirents_to_clusters(entries);

    /* Now traverse */
#if (SUPPORT_WIN95)
    if ((dd=_findfirst(path, &statobj))<0)
#else
    if (_dos_findfirst(path, _A_SUBDIR, &statobj)!=0)
#endif
    {
        return(0);
    }
    else
    {
        do 
        {
            if( statobj.attrib & _A_SUBDIR )
            {
                if ( (strcmp(".", statobj.name)!=0) &&
                     (strcmp("..", statobj.name)!=0)  )
                {
                    strcpy(path, name);
                    strcat(path, "\\");
                    strcat(path, statobj.name);
                    traverse(path, level+1);
                    strcpy(path, name);
                    strcat(path, "\\*.*");
                }
            }
#if (SUPPORT_WIN95)
        } while (_findnext(dd, &statobj) == 0);
        
        _findclose(dd);
#else
        } while (_dos_findnext(&statobj) == 0);
#endif
    }
    return(1);
}


int make_directories(char *name, int level)
{
statobj_t statobj;
char path[MAX_PATH_LEN];
char *p;
#if (SUPPORT_WIN95)
long dd;
#endif
#if (!VFAT)
char newpath[MAX_PATH_LEN];
#endif

    if (level)
    {
        p = name + root_path_len;

#if (!VFAT)
        // USE upper case for 8.3
        pc_str2upper(newpath, p);
        p = newpath;
#endif
        printf("Creating directory %s\n", p);
        if (!pc_mkdir(p) )
        {
            printf("Failed creating directory %s\n", p);
            return(-1);
        }
    }

    strcpy(path, name);
    strcat(path, "\\*.*");

#if (SUPPORT_WIN95)
    if ((dd = _findfirst(path, &statobj))<0)
#else
    if (_dos_findfirst(path, _A_SUBDIR, &statobj)!=0)
#endif
    {
        return(0);
    }
    else
    {
        do 
        {
            if( statobj.attrib & _A_SUBDIR )
            {
                if ( (strcmp(".", statobj.name)!=0) &&
                     (strcmp("..", statobj.name)!=0)  )
                {
                    strcpy(path, name);
                    strcat(path, "\\");
                    strcat(path, statobj.name);
                    if (make_directories(path, level+1) != 0)
                        return(-1);
                    strcpy(path, name);
                    strcat(path, "\\*.*");
                }
            }
#if (SUPPORT_WIN95)
        } while (_findnext(dd, &statobj) == 0);

        _findclose(dd);
#else
        } while (_dos_findnext(&statobj) == 0);
#endif
    }
    return(0);
}

/* Copy Native file *from to dos path *to */
BOOLEAN copy_one_file(char *path, char *filename)            /* __fn__ */
{
static char dos_path[MAX_PATH_LEN];
static char buf[1024];
PCFD  fd;
short res,res2;
int fi;
BOOLEAN retval = TRUE;
char *to;
#if (!VFAT)
char newpath[MAX_PATH_LEN];
#endif

    strcpy(dos_path, path);
    strcat(dos_path, "\\");
    strcat(dos_path, filename);

    /* Strip the leading path when we go to rtfs */
    to = &dos_path[root_path_len];
#if (!VFAT)
// USE upper case for 8.3
        pc_str2upper(newpath, to);
        to = newpath;
#endif
    printf("Copying %s to %s\n", dos_path, to);

    if ( (fi = open(dos_path,O_RDONLY|O_BINARY)) < 0)    /* Open binary read */ 
    {
        printf("Cant open %s\n",dos_path);
        return (FALSE);
    }
    else
    {
        /* Open the PC disk file for write */
        if ((fd = po_open(to,(PO_BINARY|PO_RDWR|PO_CREAT|PO_TRUNC),
                             (PS_IWRITE | PS_IREAD) ) ) < 0)
        {
            printf("Cant open %s error = %i\n",to, -1);
             return (FALSE);
        }
        else
        {
            /* Read from host until EOF */
            while ( (res =(short) read(fi,&buf[0],1024)) > 0)
            {
                /* Put to the drive */
                if ( (res2 = po_write(fd,buf,res)) != res)
                {
                    printf("Cant write %x %x \n",res,res2);
                    retval = FALSE;
                    break;
                }
            }
            /* Close the pc file flush buffers &  and de-allocate structure */
            po_close(fd);

            /* close the native file */
            /* PORT-ME */
            close(fi);

            return (retval);
        }
    }
}    
 

int copy_files(char *name, int level)
{
statobj_t statobj;
char path[MAX_PATH_LEN];
#if (SUPPORT_WIN95)
long dd;
#endif

    printf("Processing directory %s\n", name);
    strcpy(path, name);
    strcat(path, "\\*.*");

#if (SUPPORT_WIN95)
    if ((dd = _findfirst(path, &statobj))>=0)
#else
    if (_dos_findfirst(path, _A_NORMAL, &statobj)==0)
#endif
    {
        do 
        {
            if(!(statobj.attrib & (_A_SUBDIR) ))
            {
                if (!copy_one_file(name, statobj.name))
                    return(-1);
            }
#if (SUPPORT_WIN95)
        } while (_findnext(dd, &statobj) == 0);

        _findclose(dd);
#else
        } while (_dos_findnext(&statobj) == 0);
#endif
    }

    /* Now traverse */
#if (SUPPORT_WIN95)
    if ((dd = _findfirst(path, &statobj)) < 0)
#else
    if (_dos_findfirst(path, _A_SUBDIR, &statobj) != 0)
#endif
    {
        return(0);
    }
    else
    {
        do 
        {
            if( statobj.attrib & _A_SUBDIR )
            {
                if ( (strcmp(".", statobj.name)!=0) &&
                     (strcmp("..", statobj.name)!=0)  )
                {
                    strcpy(path, name);
                    strcat(path, "\\");
                    strcat(path, statobj.name);
                    if (copy_files(path, level+1) < 0)
                        return(-1);
                    strcpy(path, name);
                    strcat(path, "\\*.*");
                }
            }
#if (SUPPORT_WIN95)
        } while (_findnext(dd, &statobj) == 0);
        
        _findclose(dd);
#else
        } while (_dos_findnext(&statobj) == 0);
#endif
    }
    return(0);
}

void bintoc(void)
{
FILE *infile, *outc;
int c, linecount=0;
long count=0;

    infile = fopen("filedisk.dat", "rb");
    if (infile == NULL)
    {
        perror("filedisk.dat");
        exit(-1);
    }

    outc = fopen("romdisk.h", "wt");
    if (outc == NULL)
    {
        perror("romdisk.h");
        fclose(infile);
        exit(-1);
    }

    fprintf(outc, "/* %s */\n", "romdisk.h");
    fprintf(outc, "/* Automatically Created from %s using BINTOC.EXE */\n", "filedisk.dat");
    fprintf(outc, "\nunsigned char KS_FAR %s[]=\n{\n", "romdisk_data");

    // write the C file
    while ((c=fgetc(infile)) != EOF) 
    {
        if (linecount < 16) 
        {
            fprintf(outc, " 0x%02x, ",c);
            linecount++;
        }
        else 
        {
            fprintf(outc, " 0x%02x,\n", c);
            linecount=0;
        }

        count++;
    }

    fprintf(outc, "};\n");

    fclose(infile);
    fclose(outc);
}


// So we can compile 


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -