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

📄 mklist.c

📁 mips架构的bootloader,99左右的版本 但源代码现在没人更新了
💻 C
字号:
/************************************************************* * File: tools/mklist.c * Purpose: Create rules for makefile * Author: Phil Bunce (pjb@carmel.com) * Revision History: *	970918	Start of revision history *	970918	Changed name in help msg to mklist *	981121	Added code to niceExit to remove ofile on error. */#include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#define strequ(x,y)	((strcmp((x),(y))==0)?1:0)#define strNcpy(x,y,z)  (strncpy(x,y,z),(x)[z]=0)#define BUFSIZE 200char *av[500];int ac;char lnbuf[BUFSIZE];char tmp[BUFSIZE];char *nmlst[40];int nmcnt;char *sdlst[20];char *srcprefix;int sdcnt;int sflag;int rflag; /* generate rules */int Oflag; /* generate .o file names */char *usage[] = {	"usage: mklist [-o ofile][-Or] ifile src name... [-s name..]",	"	src	  specify the source prefix",	"       -o ofile  direct the output to ofile",	"       -r        generate rules",	"       -O        generate a list of .o filenames",	"       -s        safe files, make the .o file non writeable",	"       -d sdir   add a source directory",	0};FILE *ofp,*ifp;char *ofile;/**************************************************************  main(argc,argv)*/main(argc,argv)int argc;char *argv[];{char *ifile;int i,j,cflag;ofp = stdout;ifile = ofile = 0;sdlst[sdcnt++] = ".";for (i=1;i<argc;i++) {	if (argv[i][0] == '-') {		if (argv[i][1] == 'o') ofile = argv[++i];		else if (argv[i][1] == 's') nmlst[nmcnt++] = "-s";		else if (argv[i][1] == 'd') sdlst[sdcnt++] = argv[++i];		else if (argv[i][1] == 'r') rflag = 1;		else if (argv[i][1] == 'O') Oflag = 1;		else {			fprintf(stderr,"%c: bad option\n",argv[i][1]);			niceExit(1);			}		}	else {		if (!ifile) ifile = argv[i];		else if (!srcprefix) srcprefix = argv[i];		else nmlst[nmcnt++] = argv[i];		}	}if (!srcprefix || !ifile || nmcnt == 0) niceExit(1);ifp = fopen(ifile,"r");if (ifp == 0) {	fprintf(stderr,"Can't open %s\n",ifile);	niceExit(1);	}if (ofile) {	ofp = fopen(ofile,"w");	if (ofp == 0) {		fprintf(stderr,"can't open %s\n",ofile);		niceExit(1);		}	}if (rflag) {	fprintf(ofp,"##################################################\n");	fprintf(ofp,"#          Do Not Edit This File                 #\n");	fprintf(ofp,"#     Add any new modules to files.mk            #\n");	fprintf(ofp,"##################################################\n");	}cflag = 0;sflag = 0;for (i=0;i<nmcnt;i++) {	if (strchr(nmlst[i],'.')) mkrule(nmlst[i]);	else if (strequ(nmlst[i],"-s")) sflag = 1;	else {		rewind(ifp);		while (fgets(lnbuf,BUFSIZE,ifp)) {			ac = argvize(av,lnbuf);			j = 0;			if (!cflag) {				if (ac < 3) continue;				if (!strequ(nmlst[i],av[0])) continue;				j = 2;				}			for (;j<(ac-1);j++) mkrule(av[j]);			if (strequ(av[j],"\\")) cflag = 1;			else {				mkrule(av[j]);				cflag = 0;				}			}		}	}exit(0);}/**************************************************************  mkrule(name)*/mkrule(name)char *name;{char *b,*e,h[256],*flags,src[256];struct stat st;int i;e = strrchr(name,'.');if (!e) { /* filename must have an extent part */	fprintf(stderr,"%s: bad filename\n",name);	niceExit(1);	}b = strrchr(name,'/');if (b) b++;else b = name;strNcpy(h,b,e-b);/* h now contains the last part of the filename a-la csh :r */if (!rflag) {	if (Oflag) fprintf(ofp,"%s.o\n",h);	else fprintf(ofp,"%s\n",name);	return;	}if (strequ(e,".c")) flags = "$(CFLAGS)";else if (strequ(e,".s")) flags = "$(ASFLAGS)";else {	fprintf(stderr,"%s: bad extent\n",e);	niceExit(1);	}/* find the file */for (i=0;i<sdcnt;i++) {	sprintf(tmp,"%s/%s",sdlst[i],name);	if (stat(tmp,&st) == 0) break; /* file exists */	}if (i == sdcnt) {	fprintf(stderr,"%s: source not found\n",name);	niceExit(1);	}if (!strcmp(sdlst[i],".")) strcpy(src,srcprefix);else sprintf(src,"%s/%s",srcprefix,sdlst[i]);if (sflag) {	if (stat(name,&st) == 0) { /* file exists */		fprintf(ofp,"%s.o : %s/%s\n",h,src,name);		fprintf(ofp,"\t$(RMF) %s.o\n",h);		fprintf(ofp,"\t$(CC) -c %s -o %s.o %s/%s\n",flags, h,							src,name);		fprintf(ofp,"\tchmod -w %s.o\n",h);		}	}else {	fprintf(ofp,"%s.o : %s/%s\n",h,src,name);	fprintf(ofp,"\t$(CC) -c %s %s/%s\n",flags,src,name);	}}/**************************************************************  int argvize(av,s) *	place address of each word in s into the array av*/int argvize(av,s)char *av[];char *s;{char **pav = av, c;int ac;for (ac=0;;ac++) {	/* step over cntrls and spaces */	while(*s && *s <= ' ') ++s;	/* if eos quit */	if(!*s) break;	c = *s;	/* find end of word */	if (pav) *pav++ = s;	while(' ' < *s) ++s;	/* not eos inc ptr */	if(*s) *s++ = 0;	}return(ac);}/**************************************************************/niceExit(n)int n;{int i;if (ofp && ofp != stdout) {	fclose(ofp); 	if (ofile) unlink(ofile);	}for (i=0;usage[i];i++) fprintf(stderr,"%s\n",usage[i]);exit(n);}

⌨️ 快捷键说明

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