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

📄 mkfiles.c

📁 mips架构的bootloader,99左右的版本 但源代码现在没人更新了
💻 C
字号:
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <string.h>#ifdef MSDOS#include <process.h>#endif/* * This program is designed to permit read-only files to be downloaded * to a target system, and be opened by filename. It generates a file * that contains an array of structures, each structure contains, the * filename, start point, and size. It also generates a .cof file that * contains the actual file data. See the example examples/pmon/filetst.c * for description on how to use this feature. */char cmd[1000];char tempfile[] = "/tmp/mkXXXXXX";char *leflag = "";int vflag;/**************************************************************  main(argc,argv)*/main(argc,argv)int argc;char *argv[];{int i,c,ifiles;long offset;struct stat st;char *ofile;off_t size;FILE *ifp,*tfp;ofile = 0;ifiles = 0;for (i=1;i<argc;i++) {	if (argv[i][0] == '-') {		if (argv[i][1] == 'l') leflag = "-l";		else if (argv[i][1] == 'v') vflag = 1;		else {			fprintf(stderr,"%s: unknown switch\n",argv[i]);			exit(1);			}		}	else {		if (! ofile) ofile = argv[i];		else {			ifiles = i;			break;			}		}	}if (! ofile || ! ifiles )  {	fprintf(stderr,"usage: mkfiles [-lv] ofile ifiles..\n");	exit(1);	}mktemp(tempfile);if (! *tempfile) {	fprintf(stderr,"can't creat tempfile name\n");	exit(1);	}tfp = fopen(tempfile,"w");if (! tfp) {	fprintf(stderr,"can't open tempfile %s\n",tempfile);	exit(1);	}printf("#include <termio.h>\n");printf("Ramfile _mfile[] = {\n");offset = 0;for (i=ifiles;i<argc;i++) {	if (stat(argv[i],&st)) {		fprintf(stderr,"can't stat %s\n",argv[i]);		exit(1);		}	size = st.st_size;	printf("\t{\"%s\",0,%d,%d,0},\n",argv[i],offset,size);	offset += size;	ifp = fopen(argv[i],"r");	if (! ifp) {		fprintf(stderr,"can't open %s\n",argv[i]);		exit(1);		}	while ((c=getc(ifp)) != EOF) putc(c,tfp);	fclose(ifp);	}fclose(tfp);printf("\t{0}};\n");sprintf(cmd,"gencoff %s -T%lx -o %s.cof %s",leflag,offset,ofile,tempfile);if (vflag) fprintf(stderr,"%s\n",cmd);if (system(cmd)) exit(1);unlink(tempfile);exit(0);}#ifdef MSDOS/**************************************************************  system(cmd)*/system(cmd)char *cmd;{int i;char *p,*av[20];for (i=0,p=strtok(cmd," ");p;p=strtok(0," ")) {	if (i > 20) {		fprintf(stderr,"system: too many args\n");		exit(1);		}	av[i++] = p;	}av[i] = 0;return _spawnvp(_P_WAIT,av[0],av);}#endif

⌨️ 快捷键说明

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