Quantcast
Channel: Icepack-linux and Neck Pads » linux scripts code
Viewing all articles
Browse latest Browse all 8

linux kernel code scripts unifdef.c 2

$
0
0

/*
* The main program.
*/
int
main(int argc, char *argv[])
{
int opt;

while ((opt = getopt(argc, argv, “i:D:U:I:o:bBcdeKklnsStV”)) != -1)
switch (opt) {
case ‘i’: /* treat stuff controlled by these symbols as text */
/*
* For strict backwards-compatibility the U or D
* should be immediately after the -i but it doesn’t
* matter much if we relax that requirement.
*/
opt = *optarg++;
if (opt == ‘D’)
addsym(true, true, optarg);
else if (opt == ‘U’)
addsym(true, false, optarg);
else
usage();
break;
case ‘D’: /* define a symbol */
addsym(false, true, optarg);
break;
case ‘U’: /* undef a symbol */
addsym(false, false, optarg);
break;
case ‘I’: /* no-op for compatibility with cpp */
break;
case ‘b’: /* blank deleted lines instead of omitting them */
case ‘l’: /* backwards compatibility */
lnblank = true;
break;
case ‘B’: /* compress blank lines around removed section */
compblank = true;
break;
case ‘c’: /* treat -D as -U and vice versa */
complement = true;
break;
case ‘d’:
debugging = true;
break;
case ‘e’: /* fewer errors from dodgy lines */
iocccok = true;
break;
case ‘K’: /* keep ambiguous #ifs */
strictlogic = true;
break;
case ‘k’: /* process constant #ifs */
killconsts = true;
break;
case ‘n’: /* add #line directive after deleted lines */
lnnum = true;
break;
case ‘o’: /* output to a file */
ofilename = optarg;
break;
case ‘s’: /* only output list of symbols that control #ifs */
symlist = true;
break;
case ‘S’: /* list symbols with their nesting depth */
symlist = symdepth = true;
break;
case ‘t’: /* don’t parse C comments */
text = true;
break;
case ‘V’: /* print version */
version();
default:
usage();
}
argc -= optind;
argv += optind;
if (compblank && lnblank)
errx(2, “-B and -b are mutually exclusive”);
if (argc > 1) {
errx(2, “can only do one file”);
} else if (argc == 1 && strcmp(*argv, “-”) != 0) {
filename = *argv;
input = fopen(filename, “rb”);
if (input == NULL)
err(2, “can’t open %s”, filename);
} else {
filename = “[stdin]“;
input = stdin;
}
if (ofilename == NULL) {
ofilename = “[stdout]“;
output = stdout;
} else {
struct stat ist, ost;
if (stat(ofilename, &ost) == 0 &&
fstat(fileno(input), &ist) == 0)
overwriting = (ist.st_dev == ost.st_dev
&& ist.st_ino == ost.st_ino);
if (overwriting) {
const char *dirsep;
int ofd;

dirsep = strrchr(ofilename, ‘/’);
if (dirsep != NULL)
snprintf(tempname, sizeof(tempname),
“%.*s/” TEMPLATE,
(int)(dirsep – ofilename), ofilename);
else
snprintf(tempname, sizeof(tempname),
TEMPLATE);
ofd = mkstemp(tempname);
if (ofd != -1)
output = fdopen(ofd, “wb+”);
if (output == NULL)
err(2, “can’t create temporary file”);
fchmod(ofd, ist.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO));
} else {
output = fopen(ofilename, “wb”);
if (output == NULL)
err(2, “can’t open %s”, ofilename);
}
}
process();
abort(); /* bug */
}


Viewing all articles
Browse latest Browse all 8

Trending Articles