Beispiel #1
0
static void dissector_init_ether_types(void)
{
	FILE *fp;
	char buff[512], *ptr;
	struct ether_type *et;
	void **pos;

	fp = fopen("/etc/netsniff-ng/ether.conf", "r");
	if (!fp)
		panic("No /etc/netsniff-ng/ether.conf found!\n");
	memset(buff, 0, sizeof(buff));
	while (fgets(buff, sizeof(buff), fp) != NULL) {
		buff[sizeof(buff) - 1] = 0;
		et = xmalloc(sizeof(*et));
		ptr = buff;
		ptr = skips(ptr);
		ptr = getuint(ptr, &et->id);
		ptr = skips(ptr);
		ptr = skipchar(ptr, ',');
		ptr = skips(ptr);
		ptr = strtrim_right(ptr, '\n');
		ptr = strtrim_right(ptr, ' ');
		et->type = xstrdup(ptr);
		et->next = NULL;
		pos = insert_hash(et->id, et, &eth_ether_types);
		if (pos) {
			et->next = *pos;
			*pos = et;
		}
		memset(buff, 0, sizeof(buff));
	}

	fclose(fp);
}
Beispiel #2
0
static void dissector_init_ports_tcp(void)
{
	FILE *fp;
	char buff[512], *ptr;
	struct port_tcp *ptcp;
	void **pos;

	fp = fopen("/etc/netsniff-ng/tcp.conf", "r");
	if (!fp)
		panic("No /etc/netsniff-ng/tcp.conf found!\n");
	memset(buff, 0, sizeof(buff));
	while (fgets(buff, sizeof(buff), fp) != NULL) {
		buff[sizeof(buff) - 1] = 0;
		ptcp = xmalloc(sizeof(*ptcp));
		ptr = buff;
		ptr = skips(ptr);
		ptr = getuint(ptr, &ptcp->id);
		ptr = skips(ptr);
		ptr = skipchar(ptr, ',');
		ptr = skips(ptr);
		ptr = strtrim_right(ptr, '\n');
		ptr = strtrim_right(ptr, ' ');
		ptcp->port = xstrdup(ptr);
		ptcp->next = NULL;
		pos = insert_hash(ptcp->id, ptcp, &eth_ports_tcp);
		if (pos) {
			ptcp->next = *pos;
			*pos = ptcp;
		}
		memset(buff, 0, sizeof(buff));
	}

	fclose(fp);
}
Beispiel #3
0
static void dissector_init_oui(void)
{
	FILE *fp;
	char buff[512], *ptr;
	struct vendor_id *ven;
	void **pos;

	fp = fopen("/etc/netsniff-ng/oui.conf", "r");
	if (!fp)
		panic("No /etc/netsniff-ng/oui.conf found!\n");
	memset(buff, 0, sizeof(buff));
	while (fgets(buff, sizeof(buff), fp) != NULL) {
		buff[sizeof(buff) - 1] = 0;
		ven = xmalloc(sizeof(*ven));
		ptr = buff;
		ptr = skips(ptr);
		ptr = getuint(ptr, &ven->id);
		ptr = skips(ptr);
		ptr = skipchar(ptr, ',');
		ptr = skips(ptr);
		ptr = strtrim_right(ptr, '\n');
		ptr = strtrim_right(ptr, ' ');
		ven->vendor = xstrdup(ptr);
		ven->next = NULL;
		pos = insert_hash(ven->id, ven, &eth_oui);
		if (pos) {
			ven->next = *pos;
			*pos = ven;
		}
		memset(buff, 0, sizeof(buff));
	}

	fclose(fp);
}
Beispiel #4
0
/*
 *----------------------------------------------------------------------
 * findfile--
 * 	Finds a file in a : separated list of paths. ~ expansion is also
 * done.
 *
 * Returns:
 * 	The complete path for the file (in a newly allocated string) or
 * NULL if the file was not found.
 *
 * Side effects:
 * 	A new string is allocated. It must be freed later.
 *
 *----------------------------------------------------------------------
 */
char*
wfindfile(char *paths, char *file)
{
    char *path;
    char *tmp, *tmp2;
    int len, flen;
    char *fullpath;

    if (!file)
        return NULL;

    if (*file=='/' || *file=='~' || *file=='$' || !paths || *paths==0) {
        if (access(file, F_OK)<0) {
            fullpath = wexpandpath(file);
            if (!fullpath)
                return NULL;

            if (access(fullpath, F_OK)<0) {
                wfree(fullpath);
                return NULL;
            } else {
                return fullpath;
            }
        } else {
            return wstrdup(file);
        }
    }

    flen = strlen(file);
    tmp = paths;
    while (*tmp) {
        tmp = skipchar(tmp, ':');
        if (*tmp==0)
            break;
        tmp2 = nextchar(tmp, ':');
        len = tmp2 - tmp;
        path = wmalloc(len+flen+2);
        path = memcpy(path, tmp, len);
        path[len]=0;
        if (path[len-1] != '/')
            strcat(path, "/");
        strcat(path, file);
        fullpath = wexpandpath(path);
        wfree(path);
        if (fullpath) {
            if (access(fullpath, F_OK)==0) {
                return fullpath;
            }
            wfree(fullpath);
        }
        tmp = tmp2;
    }

    return NULL;
}
int main(int argc, char *argv[])
{
unsigned int repeat=0;
char **tags;
int i;
int a;
int b;
float gdivide_a;
float gdivide_b;


char are_you_sure[100];

#ifdef NAJI_DEBUG

 fprintf(stderr, "\n\n");
 fprintf(stderr, "NAJI_DEBUG - check if two commands are displayed as one joined string,\n");
 fprintf(stderr, "             you might have missed a , in najitool_valid_commands[]\n\n");

 for (i=0; i<NAJITOOL_MAX_COMMANDS; i++)               
 fprintf(stderr, "%s ", najitool_valid_commands[i]);
 fgetc(stdin);

#endif /* NAJI_DEBUG */



#ifdef NAJI_DEBUG
    fprintf(stderr, "\n\nNAJI_DEBUG - YOUR PARAMETERS/ARGUMENTS:\n\n");
    
    for (i=0; i<argc; i++)
    fprintf(stderr, "%s ", argv[i]);
    
    fprintf(stderr, "\n\n");

    fgetc(stdin);
#endif /* NAJI_DEBUG */



    if (argc >= 2)
    {
    tolowers(argv[1]);
    najitool_check_command(argv[1]);
    }


    if (argc == 1)
    {
    printf("\n\n");


/*
printf("           __    |         \n");
printf("          /  \\   |        \n");
printf("     /   _____|  | o \\    \n");
printf("    |    \\  o    |___|    \n");
printf("     \\____\\              \n");
printf("      o o    T O O L       \n");
*/


printf("           __    |          ********************************************\n");
printf("          /  \\   |               najitool 0.8.4 using libnaji 0.6.4     \n");
printf("     /   _____|  | o \\            both written by NECDET COKYAZICI      \n");
printf("    |    \\  o    |___|                   and contributors              \n");
printf("     \\____\\                 ********************************************\n");
printf("      o o    T O O L         No warranty, to view the license type:     \n");
printf("                                         najitool license               \n");
printf("  http://najitool.sf.net/   ********************************************\n");
printf("                             To view the credits type: najitool credits \n");
printf("  Public Domain, 2003-2011  ********************************************\n");
printf("\n");


forhelp();


    return 0;
    }



    if (argc >= 2)
    {


        if (!strcmp(argv[1], "mp3taged"))
        {

            if ((argc % 2 != 1) | (argc == 3))
            {
            printf("mp3taged: too few arguments '%s'\n", argv[1]);
            return 1;
            }

            /*
             * we save the tags' options:
             * tags[i] = <tag name>
             * tags[i+1] = <user content>
             * ..
             */

            tags = (char**) malloc (sizeof(char*)*(argc-3)*2);

            for (i=0; i<(argc-3)*2; i+=2)
            tags[i] = (char*) malloc(7*sizeof(char));

            for (i=1; i<(argc-3)*2; i+=2)
            tags[i] = argv[i+2];

            for (i=0; i<(argc-3)*2; i+=2)
            memcpy (tags[i], argv[i+2], 7);

            mp3editag (argv[argc-1], tags, argc-3);

            for (i=0; i<(argc-3)*2; i+=2)
            free(tags[i]);

            free(tags);

        return 0;
        }

        if (!strcmp(argv[1], "credits"))
        {

            if (argc > 2)
            tooparam("credits");

            naji_credits();

            return 0;
        }

        if (!strcmp(argv[1], "asctable"))
        {

            if (argc > 2)
            tooparam("asctable");

            asctable();
            return 0;
        }

        if (!strcmp(argv[1], "engnum"))
        {

            if (argc > 2)
            tooparam("engnum");

            engnum();
            return 0;
        }

        if (!strcmp(argv[1], "turnum"))
        {

            if (argc > 2)
            tooparam("turnum");
     
            turnum();
            return 0;
        }

        if (!strcmp(argv[1], "najcrypt"))
        {

            if (argc > 2)
            tooparam("najcrypt");

            najcrypt();
            return 0;
        }

        if (!strcmp(argv[1], "database"))
        {

            if (argc > 2)
            tooparam("database");
    
            naji_database();
            return 0;
        }

        if (!strcmp(argv[1], "html_db"))
        {

            if (argc > 2)
            tooparam("html_db");

            naji_html_database();
            return 0;
        }

        if (!strcmp(argv[1], "calc"))
        {

            if (argc > 2)
            tooparam("calc");

            naji_calc();
            return 0;
        }

        if (!strcmp(argv[1], "length"))
        {

            if (argc > 2)
            tooparam("length");

            length();
            return 0;
        }

        if (!strcmp(argv[1], "mathgame"))
        {

            if (argc > 2)
            tooparam("mathgame");

            mathgame();
            return 0;
        }

        if (!strcmp(argv[1], "license"))
        {

            if (argc > 2)
            tooparam("license");

            naji_license();
            return 0;
        }

        if (!strcmp(argv[1], "ttt"))
        {

            if (argc > 2)
            tooparam("ttt");

            ttt();
            return 0;
        }

        if (!strcmp(argv[1], "naji_bmp"))
        {
            if (argc > 2)
            tooparam("naji_bmp");

            naji_bmp();
            return 0;
        }

        if (!strcmp(argv[1], "unihtml"))
        {

            if (argc > 2)
            tooparam("unihtml");

            naji_gen_unicode_html_pages();
            return 0;
        }
    
        if (!strcmp(argv[1], "rmunihtm"))
        {

            if (argc > 2)
            tooparam("rmunihtm");
    
            naji_del_gen_unicode_html_pages();
            return 0;
        }
    
        if (!strcmp(argv[1], "cat_text"))
        {

            if (argc == 2)
            {
            naji_stdin_msg();
            cat_text_stdin();
            return 0;
            }

            if (argc == 3)
            {
            cat_text(argv[2]);
            return 0;
            }

            if (argc > 3)
            tooparam("cat_text");

            return 0;
        }

        if (!strcmp(argv[1], "kitten"))
        {

            if (argc == 2)
            {
            naji_stdin_msg();
            kitten_stdin();
            return 0;
            }

            if (argc == 3)
            {
            kitten(argv[2]);
            return 0;
            }

            if (argc > 3)
            tooparam("kitten");

        return 0;
        }

        if (!strcmp(argv[1], "genlic"))
        {

            if (argc > 2)
            tooparam("genlic");

            naji_genlic();
            return 0;
        }

        if (!strcmp(argv[1], "genhelp"))
        {

            if (argc > 2)
            tooparam("genhelp");

            najitool_generate_help();
            return 0;
        }

        if (!strcmp(argv[1], "htmlhelp"))
        {
            if (argc > 2)
            tooparam("htmlhelp");

            najitool_generate_help_html();
            return 0;
        }

        if (!strcmp(argv[1], "systemdt"))
        {
            if (argc > 2)
            tooparam("systemdt");
        
            systemdt();
            return 0;
        }


        if (!strcmp(argv[1], "datetime"))
        {

            if (argc > 2)
            tooparam("datetime");

            datetime();
            return 0;
        }

        if (!strcmp(argv[1], "telltime"))
        {

            if (argc > 2)
            tooparam("telltime");

            printf("\n\n");
            telltime();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "today"))
        {

            if (argc > 2)
            tooparam("today");

            printf("\n\n");
            today();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "dayofmon"))
        {

            if (argc > 2)
            tooparam("dayofmon");
    
            printf("\n\n");
            dayofmon();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "month"))
        {

            if (argc > 2)
            tooparam("month");

            printf("\n\n");
            month();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "year"))
        {

            if (argc > 2)
            tooparam("year");

            printf("\n\n");
            year();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "saatarih"))
        {

            if (argc > 2)
            tooparam("saatarih");

            saatarih();
            return 0;
        }

        if (!strcmp(argv[1], "saat"))
        {

            if (argc > 2)
            tooparam("saat");

            printf("\n\n");
            saat();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "bugun"))
        {
            if (argc > 2)
            tooparam("bugun");

            printf("\n\n");
            bugun();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "ayinkaci"))
        {

            if (argc > 2)
            tooparam("ayinkaci");

            printf("\n\n");
            ayinkaci();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "ay"))
        {

            if (argc > 2)
            tooparam("ay");

            printf("\n\n");
            ay();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "yil"))
        {
            if (argc > 2)
            tooparam("yil");

            printf("\n\n");
            yil();
            printf("\n\n");

            return 0;
        }


        if (!strcmp(argv[1], "allbmp16"))
        {
            if (argc > 2)
            tooparam("allbmp16");

            printf("\n\n");
            allbmp16();
            printf("\n\n");

            return 0;
        }


        if (!strcmp(argv[1], "help"))
        {

            if (argc == 2)
            {
            printf("\n\nAvailable help catagories:\n\n");
            printf("commands\n");
            printf("\n\n");
            forhelp();
            return 0;
            }


            if (argc == 3)
            {

                  if (!strcmp(argv[2], "commands"))
                  najitool_help_commands();

                  else najitool_command_help(argv[2]);

                  return 0;
            }


            if (argc > 3)
            tooparam("help");

            return 0;
        }



begin_cmd("mergline", 7)
mergline(argv[2], argv[3], argv[4], argv[5], argv[6]);
end_cmd()

begin_cmd("mp3split", 6)
mp3split(argv[4], argv[5], atoi(argv[2]), atoi(argv[3]));
end_cmd()

begin_cmd("rrrchars", 6)
rrrchars(argv[2], argv[3], atoi(argv[4]), atoi(argv[5]));
end_cmd()

begin_cmd("chstr", 6)
chstr(argv[2], argv[3], argv[4], argv[5]);
end_cmd()

begin_cmd("chchars", 6)
chchars(argv[2], argv[3], argv[4], argv[5]);
end_cmd()

begin_cmd("chchar", 6)
chchar(argv[2], argv[3], argv[4][0], argv[5][0]);
end_cmd()

begin_cmd("filechop", 6)
filechop( (strtol(argv[2], NULL, 0)), argv[3], argv[4], argv[5]);
end_cmd()
        
begin_cmd("putlines", 6)
putlines(argv[2], argv[3], argv[4], argv[5]);
end_cmd()

begin_cmd("copyoffs", 6)
copyoffs(argv[2], strtoul(argv[3], NULL, 0), strtoul(argv[4], NULL, 0), argv[5]);
end_cmd()

begin_cmd("istrael", 6)
istrael(argv[2], atoi(argv[3]), argv[4], argv[5]);
end_cmd()

begin_cmd("addline", 6)
addline(argv[2], argv[3], argv[4], strtoul(argv[5], NULL, 0));
end_cmd()

begin_cmd("replacel", 6)
replacel(argv[2], argv[3], argv[4], strtoul(argv[5], NULL, 0));
end_cmd()


begin_cmd("bremline", 5)
bremline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("eremline", 5)
eremline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("remline", 5)
remline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("skipstr", 5)
skipstr(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("makarray", 5)
makarray(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("streline", 5)
streline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("strbline", 5)
strbline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("swapfeb", 5)
swapfeb(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("filbreed", 5)
filbreed(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("skipchar", 5)
skipchar(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("onlychar", 5)
onlychar(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("repchar", 5)
repeat = (unsigned int) atoi(argv[4]);
repchar(argv[2], argv[3], repeat);
end_cmd()

begin_cmd("linesnip", 5)
repeat = (unsigned int) atoi(argv[2]);
linesnip(repeat, argv[3], argv[4]);
end_cmd()

begin_cmd("charwarp", 5)
repeat = (unsigned int) atoi(argv[4]);
charwrap(repeat, argv[2], argv[3]);
end_cmd()

begin_cmd("repcharp", 5)
repeat = (unsigned int) atoi(argv[4]);
repcharp(argv[2], argv[3], repeat);
end_cmd()

begin_cmd("coffset", 5)
coffset(argv[2], strtoul(argv[3], NULL, 0), strtoul(argv[4], NULL, 0));
end_cmd()

begin_cmd("dumpoffs", 5)
dumpoffs(argv[2], strtoul(argv[3], NULL, 0), strtoul(argv[4], NULL, 0));
end_cmd()

begin_cmd("bin2c", 5)
bin2c(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("filejoin", 5)
filejoin(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("mkpatch", 5)
mkpatch(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("charfile", 5)
repeat = (unsigned int) atoi(argv[3]);
charfile(argv[2], repeat, argv[4][0]);
end_cmd()

begin_cmd("strfile", 5)
repeat = (unsigned int) atoi(argv[3]);
strfile(argv[2], repeat, argv[4]);
end_cmd()

begin_cmd("tabspace", 5)
repeat = atoi(argv[2]);
tabspace(repeat, argv[3], argv[4]);
end_cmd()

begin_cmd("charaftr", 5)
charaftr(argv[2], argv[3], argv[4][0]);
end_cmd()

begin_cmd("charbefr", 5)
charbefr(argv[2], argv[3], argv[4][0]);
end_cmd()

begin_cmd("strachar", 5)
strachar(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("strbchar", 5)
strbchar(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("rstrach", 5)
rstrach(atoi(argv[2]), argv[3], argv[4]);
end_cmd()

begin_cmd("rstrbch", 5)
rstrbch(atoi(argv[2]), argv[3], argv[4]);
end_cmd()

begin_cmd("cpfroml", 5)
cpfroml(atoi(argv[2]), argv[3], argv[4]);
end_cmd()

begin_cmd("cptiline", 5)
cptiline(atoi(argv[2]), argv[3], argv[4]);
end_cmd()

begin_cmd("n2ch", 5)
n2ch(argv[2][0], argv[3], argv[4]);
end_cmd()

begin_cmd("n2str", 5)
n2str(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("weakrypt", 5)
weakrypt(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("sp2ce2sp", 5)
sp2ce2sp(argv[2][0], argv[3], argv[4]);
end_cmd()

begin_cmd("istreml", 5)
istreml(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("removel", 5)
removel(argv[2], argv[3], strtoul(argv[4], NULL, 0));
end_cmd()




begin_cmd("printftx", 4)
printftx(argv[2], argv[3]);
end_cmd()

begin_cmd("lensorts", 4)
lensorts(argv[2], argv[3]);
end_cmd()

begin_cmd("lensortl", 4)
lensortl(argv[2], argv[3]);
end_cmd()

begin_cmd("find", 4)
find(argv[2], argv[3]);
end_cmd()

begin_cmd("findi", 4)
findi(argv[2], argv[3]);
end_cmd()

begin_cmd("cfind", 4)
cfind(argv[2], argv[3]);
end_cmd()

begin_cmd("cfindi", 4)
cfindi(argv[2], argv[3]);
end_cmd()

begin_cmd("showline", 4)
showline(argv[2], atoi(argv[3]));
end_cmd()

begin_cmd("cat_tail", 4)
cat_tail(argv[2], atoi(argv[3]));
end_cmd()

begin_cmd("cat_head", 4)
cat_head(argv[2], atoi(argv[3]));
end_cmd()

begin_cmd("getlinks", 4)
getlinks(argv[2], argv[3]);
end_cmd()

begin_cmd("f2upper", 4)
f2upper(argv[2], argv[3]);
end_cmd()

begin_cmd("f2lower", 4)
f2lower(argv[2], argv[3]);
end_cmd()

begin_cmd("fswpcase", 4)
fswpcase(argv[2], argv[3]);
end_cmd()

begin_cmd("downlist", 4)
downlist(argv[2], argv[3]);
end_cmd()

begin_cmd("hilist", 4)
hilist(argv[2], argv[3]);
end_cmd()

begin_cmd("rtcafter", 4)
rtcafter(argv[2], argv[3]);
end_cmd()

begin_cmd("rtcbefor", 4)
rtcbefor(argv[2], argv[3]);
end_cmd()

begin_cmd("rbcafter", 4)
rbcafter(argv[2], argv[3]);
end_cmd()

begin_cmd("rbcbefor", 4)
rbcbefor(argv[2], argv[3]);
end_cmd()

begin_cmd("numlines", 4)
numlines(argv[2], argv[3]);
end_cmd()

begin_cmd("file2dec", 4)
file2dec(argv[2], argv[3]);
end_cmd()

begin_cmd("file2hex", 4)
file2hex(argv[2], argv[3]);
end_cmd()

begin_cmd("file2bin", 4)
file2bin(argv[2], argv[3]);
end_cmd()

begin_cmd("wordline", 4)
wordline(argv[2], argv[3]);
end_cmd()

begin_cmd("8bit256", 4)
repeat = (unsigned int) atoi(argv[3]);
_8bit256(argv[2], repeat);
end_cmd()

begin_cmd("eng2arab", 4)
eng2arab(argv[2], argv[3]);
end_cmd()

begin_cmd("arab2eng", 4)
arab2eng(argv[2], argv[3]);
end_cmd()

begin_cmd("e2ahtml", 4)
e2ahtml(argv[2], argv[3]);
end_cmd()

begin_cmd("freverse", 4)
freverse(argv[2], argv[3]);
end_cmd()

begin_cmd("repcat", 4)
repeat = (unsigned int) atoi(argv[3]);
repcat(argv[2], repeat);
end_cmd()

begin_cmd("repcatpp", 4)
repeat = (unsigned int) atoi(argv[3]);
repcatpp(argv[2], repeat);
end_cmd()

begin_cmd("copyfile", 4)
copyfile(argv[2], argv[3]);
end_cmd()

begin_cmd("qpatch", 4)
qpatch(argv[2], argv[3]);
end_cmd()

begin_cmd("flipcopy", 4)
flipcopy(argv[2], argv[3]);
end_cmd()

begin_cmd("fillfile", 4)
fillfile(argv[2], argv[3][0]);
end_cmd()

begin_cmd("bin2text", 4)
bin2text(argv[2], argv[3]);
end_cmd()

begin_cmd("bin2hexi", 4)
bin2hexi(argv[2], argv[3]);
end_cmd()

begin_cmd("rndbfile", 4)
rndbfile(argv[2], strtoul(argv[3], NULL, 0));
end_cmd()

begin_cmd("rndtfile", 4)
rndtfile(argv[2], strtoul(argv[3], NULL, 0));
end_cmd()

begin_cmd("skipcat", 4)
skipcat(argv[2], argv[3]);
end_cmd()

begin_cmd("onlycat", 4)
onlycat(argv[2], argv[3]);
end_cmd()

begin_cmd("bigascif", 4)
bigascif(argv[2], argv[3]);
end_cmd()

begin_cmd("leetfile", 4)
leetfile(argv[2], argv[3]);
end_cmd()

begin_cmd("asc2ebc", 4)
asc2ebc(argv[2], argv[3]);
end_cmd()

begin_cmd("ebc2asc", 4)
ebc2asc(argv[2], argv[3]);
end_cmd()

begin_cmd("unix2dos", 4)
unix2dos(argv[2], argv[3]);
end_cmd()

begin_cmd("dos2unix", 4)
dos2unix(argv[2], argv[3]);
end_cmd()

begin_cmd("uuencode", 4)
uuencode(argv[2], argv[3]);
end_cmd()

begin_cmd("uudecode", 4)
uudecode(argv[2], argv[3]);
end_cmd()

begin_cmd("wordwrap", 4)
wordwrap(argv[2], argv[3]);
end_cmd()

begin_cmd("compare", 4)
compare(argv[2], argv[3]);
end_cmd()

begin_cmd("ccompare", 4)
ccompare(argv[2], argv[3]);
end_cmd()

begin_cmd("hmakerf", 4)
hmakerf(argv[2], argv[3]);
end_cmd()

begin_cmd("qcrypt", 4)
qcrypt(argv[2], argv[3]);
end_cmd()

begin_cmd("revlines", 4)
revlines(argv[2], argv[3]);
end_cmd()

begin_cmd("html2txt", 4)
html2txt(argv[2], argv[3]);
end_cmd()

begin_cmd("txt2html", 4)
txt2html(argv[2], argv[3]);
end_cmd()

begin_cmd("htmlfast", 4)
htmlfast(argv[2], argv[3]);
end_cmd()

begin_cmd("onlalnum", 4)
onlalnum(argv[2], argv[3]);
end_cmd()

begin_cmd("onlalpha", 4)
onlalpha(argv[2], argv[3]);
end_cmd()

begin_cmd("onlcntrl", 4)
onlcntrl(argv[2], argv[3]);
end_cmd()

begin_cmd("onldigit", 4)
onldigit(argv[2], argv[3]);
end_cmd()

begin_cmd("onlgraph", 4)
onlgraph(argv[2], argv[3]);
end_cmd()

begin_cmd("onllower", 4)
onllower(argv[2], argv[3]);
end_cmd()

begin_cmd("onlprint", 4)
onlprint(argv[2], argv[3]);
end_cmd()

begin_cmd("onlpunct", 4)
onlpunct(argv[2], argv[3]);
end_cmd()

begin_cmd("onlspace", 4)
onlspace(argv[2], argv[3]);
end_cmd()

begin_cmd("onlupper", 4)
onlupper(argv[2], argv[3]);
end_cmd()

begin_cmd("onlxdigt", 4)
onlxdigt(argv[2], argv[3]);
end_cmd()

begin_cmd("skpalnum", 4)
skpalnum(argv[2], argv[3]);
end_cmd()

begin_cmd("skpalpha", 4)
skpalpha(argv[2], argv[3]);
end_cmd()

begin_cmd("skpcntrl", 4)
skpcntrl(argv[2], argv[3]);
end_cmd()

begin_cmd("skpdigit", 4)
skpdigit(argv[2], argv[3]);
end_cmd()

begin_cmd("skpgraph", 4)
skpgraph(argv[2], argv[3]);
end_cmd()

begin_cmd("skplower", 4)
skplower(argv[2], argv[3]);
end_cmd()

begin_cmd("skpprint", 4)
skpprint(argv[2], argv[3]);
end_cmd()

begin_cmd("skppunct", 4)
skppunct(argv[2], argv[3]);
end_cmd()

begin_cmd("skpspace", 4)
skpspace(argv[2], argv[3]);
end_cmd()

begin_cmd("skpupper", 4)
skpupper(argv[2], argv[3]);
end_cmd()

begin_cmd("skpxdigt", 4)
skpxdigt(argv[2], argv[3]);
end_cmd()

begin_cmd("ftothe", 4)
ftothe(argv[2], argv[3]);
end_cmd()

begin_cmd("blanka", 4)
blanka(argv[2], argv[3]);
end_cmd()

begin_cmd("unblanka", 4)
unblanka(argv[2], argv[3]);
end_cmd()

begin_cmd("najirle", 4)
najirle(argv[2], argv[3]);
end_cmd()

begin_cmd("unajirle", 4)
unajirle(argv[2], argv[3]);
end_cmd()


begin_cmd("gplus", 4)
a = atoi(argv[2]);
b = atoi(argv[3]);
gplus(a, b);
end_cmd()


begin_cmd("gminus", 4)
a = atoi(argv[2]);
b = atoi(argv[3]);
gminus(a, b);
end_cmd()


begin_cmd("gtimes", 4)
a = atoi(argv[2]);
b = atoi(argv[3]);
gtimes(a, b);
end_cmd()


begin_cmd("gdivide", 4)
gdivide_a = atof(argv[2]);
gdivide_b = atof(argv[3]);
gdivide(gdivide_a, gdivide_b);
end_cmd()


begin_cmd("bytsplit", 4)
bytsplit(argv[2], atol(argv[3]));
end_cmd()

begin_cmd("kbsplit", 4)
kbsplit(argv[2], atol(argv[3]));
end_cmd()

begin_cmd("mbsplit", 4)
mbsplit(argv[2], atol(argv[3]));
end_cmd()

begin_cmd("gbsplit", 4)
gbsplit(argv[2], atol(argv[3]));
end_cmd()

begin_cmd("mjoin", 4)
mjoin(argv[2], argv[3]);
end_cmd()


begin_cmd("listdigt", 4)
listdigt(atoi(argv[2]), argv[3]);
end_cmd()

begin_cmd("listlowr", 4)
listlowr(atoi(argv[2]), argv[3]);
end_cmd()

begin_cmd("listprnt", 4)
listprnt(atoi(argv[2]), argv[3]);
end_cmd()

begin_cmd("listuppr", 4)
listuppr(atoi(argv[2]), argv[3]);
end_cmd()

begin_cmd("charsort", 4)
charsort(argv[2], argv[3]);
end_cmd()

begin_cmd("sp2re2sp", 4)
sp2re2sp(argv[2], argv[3]);
end_cmd()









begin_cmd("lcvfiles", 3)
lcvfiles(argv[2]);
end_cmd()

begin_cmd("rcvfiles", 3)
rcvfiles(argv[2]);
end_cmd()


begin_cmd("mp3tagnf", 3)
mp3info(argv[2]);
end_cmd()

begin_cmd("catrandl", 3)
catrandl(argv[2]);
end_cmd()

begin_cmd("leetstr", 3)
printf("\n\n");
leetstr(argv[2]);
printf("\n\n");
end_cmd()

begin_cmd("lcharvar", 3)
lcharvar(argv[2]);
end_cmd()

begin_cmd("rcharvar", 3)
rcharvar(argv[2]);
end_cmd()

begin_cmd("hexicat", 3)
hexicat(argv[2]);
end_cmd()

begin_cmd("rndffill", 3)
rndffill(argv[2]);
end_cmd()

begin_cmd("zerokill", 3)
zerokill(argv[2]);
end_cmd()

begin_cmd("randkill", 3)
randkill(argv[2]);
end_cmd()

begin_cmd("najisum", 3)
najisum(argv[2]);
end_cmd()


begin_cmd("rndbsout", 3)
rndbsout(strtoul(argv[2], NULL, 0));
end_cmd()

begin_cmd("rndtsout", 3)
rndtsout(strtoul(argv[2], NULL, 0));
end_cmd()

begin_cmd("patch", 3)
patch(argv[2]);
end_cmd()

begin_cmd("revcat", 3)
revcat(argv[2]);
end_cmd()

begin_cmd("copyself", 3)
copyfile(argv[0], argv[2]);
end_cmd()

begin_cmd("bigascii", 3)
bigascii(argv[2]);
end_cmd()

begin_cmd("hmaker", 3)
hmaker(argv[2]);
end_cmd()

begin_cmd("wrdcount", 3)
printf("\n\n%i\n\n", wrdcount(argv[2]));
end_cmd()

begin_cmd("addim", 3)
addim(atoi(argv[2]));
end_cmd()

begin_cmd("allfiles", 3)

fprintf(stderr, 
"\n"
"NOTE: On most systems you can stop with Ctrl+C\n"
"WARNING: This will make a lot of files.\n"
"Are you sure? type YES to continue\n"
"or anything else to quit.\n"
);
safegets(are_you_sure, 80);
            
if (!strcmp(are_you_sure, "YES"))
allfiles(atol(argv[2]));
end_cmd();        

begin_cmd("tothe", 3)
tothe(argv[2]);
end_cmd()

begin_cmd("vowelwrd", 3)
vowelwrd(argv[2]);
end_cmd()

begin_cmd("gigabyte", 3)
gigabyte(strtoul(argv[2], NULL, 0));
end_cmd()

begin_cmd("sort", 3)
sort(argv[2]);
end_cmd()

begin_cmd("sortlast", 3)
sortlast(argv[2]);
end_cmd()

begin_cmd("lineback", 3)
lineback(argv[2]);
end_cmd()

begin_cmd("longline", 3)
longline(argv[2]);
end_cmd()

begin_cmd("howline", 3)
howline(argv[2]);
end_cmd()

begin_cmd("rndlines", 3)
rndlines(argv[2]);
end_cmd()

begin_cmd("spyramid", 3)
spyramid(argv[2]);
end_cmd()


    } /* if (argc >= 2) */

return 0;         
}
Beispiel #6
0
int
main (int ac, char **av)
{
  static char execfile[SBUF];
  char rbuff[LBUF];
  char buff[LBUF];
  char cmd[LBUF];
  char mfname[TBUF];
  char tfname[TBUF];
  char pkname[TBUF];

  char name[TBUF];
  char dpi[TBUF];
  char ydpi[TBUF];
  char bdpi[TBUF];
  char mag[TBUF];
  char mode[TBUF];
  char destdir[SBUF];
  char designsize[64];

  char *arg[4];

  char currdir[SBUF];
  char kpsedot[SBUF];
  char *tmp;
  int cdrive, tdrive;

  FILE *fr, *fw, *fnul, *tfmfileptr;

  int i, savo, savi, ret;
  int style;
  int issetdest;
  int app;
  int oldform;
  int ps2pkok;
  char *env;
  char *p, *fpp;

  double Xdpi, Ydpi;

  char texname[TBUF], pfbname[TBUF], slant[TBUF], extend[TBUF], encname[TBUF];

  char texbindir[256];
  char fullbin[512];

/*
 * style =  0 : MAKETEXPK_STYLE undefined or other than dosnames
 * style =  1 : MAKETEXPK_STYLE = dosnames
 */

/*
 * issetdest = 0 : no destdir
 * issetdest = 1 : destdir
 * issetdest = 2 : current working dir
 */

/*
 * app = 0 : mf
 * app = 1 : ps2pk
 * app = 2 : gsftopk
 * app = 3 : ttf2pk
 * app = 4 : hbf2gf
 */

/*
 * oldform = 0 : newform of the command line
 * oldform = 1 : oldform of the command line
 */

/*
 * TEMP | TMP | TMPDIR (necessary)
 *
 */

  tmp = getenv ("TEMP");
  if (!tmp)
    tmp = getenv ("TMP");
  if (!tmp)
    tmp = getenv ("TMPDIR");
  if (!tmp) {
    tpkerr ("Please define TEMP | TMP | TMPDIR.");
    return (100);
  }
  tmp = xstrdup(tmp);

/*
 * normalize directory separators
 */
  normalize (tmp);

  for (i = 0; i < 4; i++)
    arg[i] = (char *) malloc (SBUF);

  kpse_set_program_name (av[0], NULL);
  progname = kpse_program_name;

/*
 * get tex binary dir
 *
 */
  p = kpse_var_value("SELFAUTOLOC");
  if(p == 0) {
     fprintf(stderr, "I cannot get SELFAUTOLOC\n");
     exit(100);
  }
  strcpy(texbindir, p);
  free(p);
  for(p=texbindir; *p; p++) {
     if(*p == '/') *p = '\\';
  }
  *p = '\\';
  *(p+1) = '\0';

  if (ac < 2) {
    usage ();
    relmem (arg);
    free(tmp);
    return (100);
  }

  issetdest = 0;
  ps2pkok = 0;

/*
 * oldform or newform ?
 *
 */

  if (av[1][0] == '-')
    oldform = 0;
  else
    oldform = 1;


/*
 * Old form of the command line
 */

  if (oldform == 1) {
    if (ac < 5) {
      usage ();
      relmem (arg);
      free(tmp);
      return (100);
    }
    if((strlen(av[1]) > TBUF -1 ) ||
       (strlen(av[2]) > TBUF -1 ) ||
       (strlen(av[3]) > TBUF -1 ) ||
       (strlen(av[4]) > TBUF -1 )) {
      fprintf(stderr, "\nToo long a string.\n");
      free(tmp);
      return 100;
    }

    strcpy (name, av[1]);
    strcpy (dpi, av[2]);
    strcpy (bdpi, av[3]);
    strcpy (mag, av[4]);
    if (ac > 5) {
      if(strlen(av[5]) > TBUF -1) {
        fprintf(stderr, "\nToo long a string.\n");
        free(tmp);
        return 100;
      } 
      strcpy (mode, av[5]);
    }
    else
      mode[0] = '\0';
  } else {
/*
 * New form of the command line
 */
    name[0] = dpi[0] = bdpi[0] = mag[0] = mode[0] = destdir[0] = '\0';
    i = 1;
    while (i < ac) {
      if(strlen(av[i]) > TBUF - 1) {
        fprintf(stderr, "\nToo long a string.\n");
        free(tmp);
        return 100;
      }
      if (av[i][0] != '-') {
        strcpy (name, av[i]);
        break;
      }
      if (!strcmp (av[i], "--dpi") || !strcmp (av[i], "-dpi")) {
        i++;
        if (i >= ac) {
          tpkerr ("Invalid arguments.");
          relmem (arg);
          free(tmp);
          return (100);
        }
        strcpy (dpi, av[i]);
        i++;
      } else if (!strcmp (av[i], "--bdpi") || !strcmp (av[i], "-bdpi")) {
        i++;
        if (i >= ac) {
          tpkerr ("Invalid arguments.");
          relmem (arg);
          free(tmp);
          return (100);
        }
        strcpy (bdpi, av[i]);
        i++;
      } else if (!strcmp (av[i], "--mag") || !strcmp (av[i], "-mag")) {
        i++;
        if (i >= ac) {
          tpkerr ("Invalid arguments.");
          relmem (arg);
          free(tmp);
          return (100);
        }
        strcpy (mag, av[i]);
        i++;
      } else if (!strcmp (av[i], "--mfmode") || !strcmp (av[i], "-mfmode")) {
        i++;
        if (i >= ac) {
          tpkerr ("Invalid arguments.");
          relmem (arg);
          free(tmp);
          return (100);
        }
        strcpy (mode, av[i]);
        i++;
      } else if (!strcmp (av[i], "--destdir") || !strcmp (av[i], "-destdir")) {
        i++;
        if (i >= ac) {
          tpkerr ("Invalid arguments.");
          relmem (arg);
          free(tmp);
          return (100);
        }
        strcpy (destdir, av[i]);
        issetdest = 1;
        i++;
      } else if (!strcmp (av[i], "--version") || !strcmp (av[i], "-version")) {
        version ();
        relmem (arg);
        free(tmp);
        return (0);
      } else if (!strcmp (av[i], "--help") || !strcmp (av[i], "-help")) {
        help ();
        relmem (arg);
        free(tmp);
        return (0);
      } else {
        tpkerr ("Argument error.");
        relmem (arg);
        free(tmp);
        return (100);
      }
    }
  }                             /* End of command line analysis */

  env = kpse_var_value ("MAKETEXPK_STYLE");

  if ((env == NULL) || !(*env) || (env && strcmp (env, "dosnames"))) {
    style = 0;
  } else
    style = 1;

/*
 * Default program is mf
 */

  app = 0;

/*
 * check if mfmode and bdpi are consistent or not
 */

  if (bdpi[0] && mode[0] && mode[0] != '/') {
    FILE *frd;
    char buff[128];
    int len;

    strcpy (fullbin, texbindir);
    strcat (fullbin, "mf-nowin.exe \"\\mode:=");
    strcat (fullbin, mode);
    strcat (fullbin, ";mode_setup;message");
    strcat (fullbin, "(decimal round pixels_per_inch);");
    strcat (fullbin, "end. <nul\"");

    frd = popen (fullbin, "r");
    if (!frd) {
      tpkerr ("I cannot find METAFONT.\n");
      relmem (arg);
      free(tmp);
      return (100);
    }
    (void) fgets (buff, 126, frd);
    (void) fgets (buff, 126, frd);
    pclose (frd);
    system("del /Q mfput.*");

    len = (int)strlen (buff);
    if (buff[len - 1] == '\n') {
      buff[len - 1] = '\0';
      if (buff[len - 2] == '\r')
        buff[len - 2] = '\0';
    }
    if (strcmp (bdpi, buff)) {
      fprintf(stderr, "mode_dpi %s and bdpi %s are inconsistent.\n", buff, bdpi);
      fprintf(stderr, "therefore I reset mfmode.\n");
      mode[0] = '\0';
    }
  }

/*
 * determine mfmode if not given
 */

  if (mode[0] == 0 || mode[0] == '/') {
    if (bdpi[0] == 0) {
      tpkerr ("Cannot determine the mode.");
      tpkerr ("I will try other possibilities.");
      app = 1;
    } else {
      strcpy (rbuff, "MAKETEXPK_MODE_");
      strcat (rbuff, bdpi);
      if ((env = kpse_var_value ("MAKETEXPK_MODE")) && *env)
        strcpy (mode, env);
      else if ((env = kpse_var_value (rbuff)))
        strcpy (mode, env);
      else if (!strcmp (bdpi, "85"))
        strcpy (mode, "sun");
      else if (!strcmp (bdpi, "100"))
        strcpy (mode, "nextscrn");
      else if (!strcmp (bdpi, "118"))
        strcpy (mode, "pcprevw");
      else if (!strcmp (bdpi, "160"))
        strcpy (mode, "nectzo");
      else if (!strcmp (bdpi, "180"))
        strcpy (mode, "toshiba");
      else if (!strcmp (bdpi, "200"))
        strcpy (mode, "highfax");
      else if (!strcmp (bdpi, "240"))
        strcpy (mode, "canonlbp");
      else if (!strcmp (bdpi, "300"))
        strcpy (mode, "cx");
      else if (!strcmp (bdpi, "320"))
        strcpy (mode, "neclm");
      else if (!strcmp (bdpi, "360"))
        strcpy (mode, "epstylus");
      else if (!strcmp (bdpi, "400"))
        strcpy (mode, "nexthi");
      else if (!strcmp (bdpi, "600"))
        strcpy (mode, "ljfour");
      else if (!strcmp (bdpi, "720"))
        strcpy (mode, "epscszz");
      else if (!strcmp (bdpi, "800"))
        strcpy (mode, "lwpro");
      else if (!strcmp (bdpi, "1000"))
        strcpy (mode, "lmaster");
      else if (!strcmp (bdpi, "1200"))
        strcpy (mode, "ultre");
      else if (!strcmp (bdpi, "1270"))
        strcpy (mode, "linoone");
      else if (!strcmp (bdpi, "1800"))
        strcpy (mode, "vtftzz");
      else if (!strcmp (bdpi, "2400"))
        strcpy (mode, "supre");
      else if (!strcmp (bdpi, "2540"))
        strcpy (mode, "linotzzh");
      else if (!strcmp (bdpi, "3386"))
        strcpy (mode, "linolttz");
      else if (!strcmp (bdpi, "8000"))
        strcpy (mode, "dpdfezzz");
      else if (!strcmp (bdpi, "9600"))
        strcpy (mode, "ibx");
      else {
        tpkerr ("Cannot determine the mode.");
        tpkerr ("I will try other possibilities.");
        app = 1;
      }
    }
  }

  if (env) free (env);

  if (name[0] == 0) {
    tpkerr ("Font name is not given.");
    relmem (arg);
    free(tmp);
    return (100);
  }

  if ((p = strrchr (name, '.')))
    *p = '\0';

  strcpy (mfname, name);
  strcat (mfname, ".mf");

  if (app == 0) {
    if (!(p = kpse_var_value ("MFINPUTS"))) {
      tpkerr ("Cannot get value of MFINPUTS.");
      relmem (arg);
      free(tmp);
      return (100);
    }
    free (p);
    xputenv("MKTEXMF", "1");
    if (!(p = kpse_find_file (mfname, kpse_mf_format, 1))) {
      fprintf (stderr, "Cannot find %s .\n", mfname);
      tpkerr ("I try ps2pk --> gsftopk --> ttf2pk --> hbf2gf.");
      app = 1;
    }
  }

  if (app != 0) {
    strcpy (mode, "modeless");
    strcpy (tfname, name);
    strcat (tfname, ".tfm");
    if (!(p = kpse_var_value ("TFMFONTS"))) {
      tpkerr ("Cannot get value of TFMFONTS.");
      relmem (arg);
      free(tmp);
      return (100);
    }
    free (p);
/*
 I don't try to create nonexisting tfm here.
*/
    if (!(p = kpse_find_file (tfname, kpse_tfm_format, 0))) {
      fprintf (stderr, "Cannot find %s .\n", tfname);
      relmem (arg);
      free(tmp);
      return 100;
    }
    tfmfileptr = fopen (p, "rb");
    if (!tfmfileptr) {
      fprintf (stderr, "I cannot open %s.\n", p);
      relmem (arg);
      free(tmp);
      return 100;
    }
    i = 256 * getc (tfmfileptr);
    i += getc (tfmfileptr);
    fclose (tfmfileptr);
    if ((i == 9) || (i == 11)) {
      fprintf (stderr, "Current font seems to be a Japanese one.\n");
      fprintf (stderr, "I give up to create a PK font.\n");
      relmem (arg);
      free(tmp);
      return 100;
    }
  }

  if ((p[0] == '.') && (p[1] == '/') && (issetdest != 1))
    issetdest = 2;

  fpp = _getcwd (currdir, SBUF);
  if (!fpp) {
    fprintf (stderr, "Failed to get current working directory.\n");
    relmem (arg);
    free(tmp);
    return (100);
  }
  normalize (currdir);

  i = (int)strlen (currdir);
  if (currdir[i - 1] == '/')
    currdir[i - 1] = '\0';

  strcpy (kpsedot, "KPSE_DOT=.;");
  strcat (kpsedot, currdir);
  _putenv (kpsedot);

  if (issetdest == 2) {
    strcpy (destdir, currdir);
  }

  if (issetdest == 0) {
    strcpy (arg[0], "Dummy");
    strcpy (arg[1], "pk");
    strcpy (arg[2], p);
    strcpy (arg[3], mode);

    if (!(p = getdestdir (4, arg))) {
      tpkerr ("Cannot get destination directory name.");
      relmem (arg);
      free(tmp);
      return (100);
    }
    strcpy (rbuff, p);
  } else
    strcpy (rbuff, destdir);

/*
 * Change backslash into slash
 */
  normalize (rbuff);

  p = rbuff;
  i = (int)strlen (p);
  if (p[i - 1] == '/')
    p[i - 1] = '\0';

  if (issetdest) {
    if (!is_dir (p)) {
      fprintf (stderr, "Destination %s is not found.\n", p);
      relmem (arg);
      free(tmp);
      return (100);
    }
  } else if (!is_dir (p)) {
    if (make_dir (p)) {
      tpkerr ("Error in make_dir.");
      relmem (arg);
      free(tmp);
      return (100);
    }
  }

  strcpy (buff, p);
  p = buff;

  i = (int)strlen (p);

  if (p[i - 1] != '/')
    strcat (p, "/");

  if (dpi[0] == 0) {
    tpkerr ("Cannot determine DPI.");
    relmem (arg);
    free(tmp);
    return (100);
  }

  if (style == 1 && issetdest != 2) {   /* dosnames */
    strcat (p, "dpi");
    strcat (p, dpi);
    if (!is_dir (p)) {
      if (make_dir (p)) {
        tpkerr ("Error in make_dir.");
        relmem (arg);
        free(tmp);
        return (100);
      }
    }
    strcat (p, "/");
  }

  strcat (p, name);
  strcat (p, ".");

  if (style != 1 || issetdest == 2)
    strcat (p, dpi);            /* long suffix */
  strcat (p, "pk");

/* Now buff and p is the full path name of pk file */
/* check the existence of pk file */

  if (_access (p, 0) == 0) {
    fprintf (stderr, "%s exists.\n", p);
    relmem (arg);
    printf ("%s\n", p);
    free(tmp);
    return (0);
  }

/*
 * Go to the temporary directory
 */

  cdrive = _getdrive ();
  if (tmp[1] == ':') {
    tdrive = tolower (*tmp) - 'a' + 1;
    _chdrive (tdrive);
  }
  _chdir (tmp);

/*
 * save stdout and stdin
 */
  savo = _dup (fileno (stdout));
  savi = _dup (fileno (stdin));

/*
 * connect stdout to stderr
*/
  _dup2 (fileno (stderr), fileno (stdout));

/*
 * connect stdin to nul
 */
  if (!(fnul = fopen ("nul", "rb"))) {
    fprintf (stderr, "Cannot open nul device to read.\n");
    _chdrive (cdrive);
    _chdir (currdir);
    relmem (arg);
    free(tmp);
    return (100);
  }
  _dup2 (fileno (fnul), fileno (stdin));

/*
 * pkname is the filename of PK font
 */
  sprintf (pkname, "%s.%spk", name, dpi);

  if (app == 0) {
/*
 * METAFONT command line
 */
    if (mag[0] == 0) {
      tpkerr ("Cannot determine MAG.");
      _chdrive (cdrive);
      _chdir (currdir);
      relmem (arg);
      free(tmp);
      return (100);
    }
    sprintf (cmd,
       "--progname=mf --base=mf \\mode:=%s; \\mag:=%s; nonstopmode; input %s;",
        mode, mag, name);

    strcpy (execfile, "mf-nowin.exe");
    fprintf (stderr, "%s %s\n", execfile, cmd);
    strcpy(fullbin, texbindir);
    strcat(fullbin, execfile);
    (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL);

    sprintf (cmd, "%s.%sgf", name, dpi);

/*
 * check the consistency
 */
    if (_access (cmd, 0) != 0) {
      tpkerr ("Failed to make gf font by METAFONT.");
      _chdrive (cdrive);
      _chdir (currdir);
      relmem (arg);
      free(tmp);
      return (100);
    }

/*
 * Change gf into pk
 */
    strcpy (execfile, "gftopk.exe");
    fprintf (stderr, "%s %s %s\n", execfile, cmd, pkname);
    strcpy(fullbin, texbindir);
    strcat(fullbin, execfile);
    (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, pkname, NULL);

    if (_access (pkname, 0) != 0) {
      tpkerr ("Failed to make pk from gf.");
      _chdrive (cdrive);
      _chdir (currdir);
      relmem (arg);
      free(tmp);
      return (100);
    }

/*
 * erase gf file
 */
    remove (cmd);

/*
 * erase log file
 */
    sprintf (cmd, "%s.log", name);
    remove (cmd);
/*
 * erase tfm file
 */
    sprintf (cmd, "%s.tfm", name);
    remove (cmd);

    goto finale;
  }

/*
 * app = 1 : ps2pk --> gsftopk --> ttf2pk --> hbf2gf
 */

  p = kpse_find_file ("pspksupp.map", kpse_fontmap_format, 0);
  if(p) {
    fr = fopen (p, "r");        /* Read pspksupp.map */
    free (p);

    if (!fr) {
      tpkerr ("Cannot open pspksupp.map to read.");
      ps2pkok = 0;
      goto do_ps2pk;
    }

    while (fgets (rbuff, SBUF, fr)) {
      if (rbuff[0] == '%' || rbuff[0] == '#' || rbuff[0] == '\n')
        continue;
      texname[0] = pfbname[0] = slant[0] = extend[0] = encname[0] = '\0';
      i = sscanf (rbuff, "%s %s %s %s %s", texname, pfbname, slant, extend,
                  encname);
      if (i == 2 && !strncmp (texname, "AspectRatio", 11)) {
        if (!sscanf (pfbname, "%lf", &AspectRatio)) {
          tpkerr ("File format of pspksupp.map is wrong.");
          fclose (fr);
          ps2pkok = 0;
          goto do_ps2pk;
        }
        UseAspectRatio = 1;
        continue;
      } else if (i > 0 && !stricmp (texname, name)) {
        p = kpse_var_value ("T1FONTS");
        if (!p) {
          tpkerr ("T1FONTS is not defined.");
          ps2pkok = 0;
          break;
        }
        free (p);
        p = kpse_find_file (pfbname, kpse_type1_format, 0);
        if (!p) {
          fprintf (stderr, "%s is not found.\n", pfbname);
          ps2pkok = 0;
          break;
        }
        free (p);
        ps2pkok = 1;
        if(bdpi[0] == 0)
          i--;
        break;
      }
    }
    fclose (fr);
    goto do_ps2pk;
  } else {
    char *q;
    char a[SBUF];
    char b[SBUF];
    char psname[SBUF];
    char pscommand[SBUF];
    double slantval, extendval;

    texname[0] = pfbname[0] = encname[0] = '\0';
    a[0] = b[0] = psname[0] = pscommand[0] = '\0';
    FileName = 0;
    strcpy(slant, "0");
    strcpy(extend, "1");

    ps2pkok = 0;

    p = kpse_find_file ("ps2pk.map", kpse_fontmap_format, 0);
    if(!p) {
      tpkerr("Necessary map file for ps2pk is not found.");
      goto do_ps2pk;
    }
    fr = fopen(p,"rb");
    free(p);
    if (!fr) {
      tpkerr ("Cannot open ps2pk.map to read.");
      goto do_ps2pk;
    }
    while ((ret=ffgets (rbuff, LBUF, fr)) != FFILE_END) {
      if(ret == BBUFF_FUL) {
        fprintf(stderr, "A line in ps2pk.map seems to be too long.\n");
        fprintf(stderr, "I try to continue. But something may be wrong.\n");
      }
      p = rbuff;
      skipchar(&p);
      if((*p == '%') || (*p == '#') || (*p == '\n'))
        continue;
      q = texname;
      while(!isskip(*p) && (*p != '\n'))
        *q++ = *p++;
      *q = '\0';
      if(stricmp(texname, name))
        continue;
      skipchar(&p);
      if((*p == '%') || (*p == '#') || (*p == '\n')) {
        fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n");
        break;
      }
      if(FileName)
        q = a;
      else
        q = psname;
      while(!isskip(*p) && (*p != '\n'))
        *q++ = *p++;
      *q = '\0';
      skipchar(&p);
/*
skip flag
*/
      if(!FileName) {
        while(isdigit(*p))
          p++;
        skipchar(&p);
      }
      if((*p == '%') || (*p == '#') || (*p == '\n')) {
        tpkerr("I cannot use ps2pk due to lack of data.");
        break;
      }
      if(*p == '\"') {
        q = pscommand;
        *q++ = *p++;
        while(*p != '\"')
          *q++ = *p++;
        *q++ = *p++;
        *q = '\0';
        skipchar(&p);
        if((*p == '%') || (*p == '#') || (*p == '\n'))
          break;
      }
      if(FileName && a[0] == '\0')
        q = a;
      else if(FileName && b[0] == '\0')
        q = b;
      else {
        tpkerr("Incorrect line in ps2pk.map.");
        break;
      }
      while(!isskip(*p) && (*p != '\n'))
        *q++ = *p++;
      *q = '\0';
      skipchar(&p);
      if((*p == '%') || (*p == '#') || (*p == '\n'))
        break;
      if(*p == '\"') {
        q = pscommand;
        *q++ = *p++;
        while(*p != '\"')
          *q++ = *p++;
        *q++ = *p++;
        *q = '\0';
        skipchar(&p);
        if((*p == '%') || (*p == '#') || (*p == '\n'))
          break;
      }
      if (FileName && a[0] == '\0')
        q = a;
      else if (FileName && b[0] == '\0')
        q = b;
      else {
        fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n");
        break;
      }
      while(!isskip(*p) && (*p != '\n'))
        *q++ = *p++;
      *q = '\0';
      skipchar(&p);
      if((*p == '%') || (*p == '#') || (*p == '\n'))
        break;
      if(*p == '\"') {
        q = pscommand;
        *q++ = *p++;
        while(*p != '\"')
          *q++ = *p++;
        *q++ = *p++;
        *q = '\0';
        skipchar(&p);
        if((*p == '%') || (*p == '#') || (*p == '\n'))
          break;
      }
      skipchar(&p);
      if((*p == '%') || (*p == '#') || (*p == '\n'))
        break;
      else {
        fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n");
        break;
      }
    }
    fclose(fr);

    if(pscommand[0]) {
      p = strstr(pscommand, "SlantFont");
      if(p) {
        p--;
        while(*p == ' ' || *p == '\t') p--;
        while(*p != ' ' && *p != '\t' && *p != '\"') p--;
        p++;
        sscanf(p, "%lf SlantFont", &slantval);
        sprintf(slant, "%lf", slantval);
        p = slant + strlen(slant) - 1;
        while(*p == '0') {
          *p = '\0';
          p--;
        }
      }
      p = strstr(pscommand, "ExtendFont");
      if(p) {
        p--;
        while(*p == ' ' || *p == '\t') p--;
        while(*p != ' ' && *p != '\t' && *p != '\"') p--;
        p++;
        sscanf(p, "%lf ExtendFont", &extendval);
        sprintf(extend, "%lf", extendval);
        p = extend + strlen(extend) - 1;
        while(*p == '0') {
          *p = '\0';
          p--;
        }
      }
    }
    if(a[0]) {
      p = strrchr(a, '.');
      if(p && !stricmp(p, ".enc")) {
        *p = '\0';
        strcpy(encname, a);
      }
      else if(p && !stricmp(p, ".pfb")) {
        *p = '\0';
        strcpy(pfbname, a);
      }
    }
    if(b[0]) {
      p = strrchr(b, '.');
      if(p && !stricmp(p, ".enc")) {
        *p = '\0';
        strcpy(encname, b);
      }
      else if(p && !stricmp(p, ".pfb")) {
        *p = '\0';
        strcpy(pfbname, b);
      }
    }
    if(pfbname[0] == '\0')
      goto do_ps2pk;
    p = kpse_find_file (pfbname, kpse_type1_format, 0);
    if(!p)
      goto do_ps2pk;
    free(p);
    ps2pkok = 1;
    if(encname[0] && bdpi[0]) {
      i = 5;
    } else if(!encname[0] && !bdpi[0]) {
      i = 3;
    } else {
      i = 4;
    }
  }

 do_ps2pk:

  if (ps2pkok) {
    if (UseAspectRatio) {
      sscanf (dpi, "%lf", &Xdpi);
      Ydpi = Xdpi * AspectRatio;
      sprintf (ydpi, "%d", (int) Ydpi);
    } else
      strcpy (ydpi, dpi);

    strcpy(tfname, name);
    strcat(tfname, ".tfm");
    get_designsize(tfname, designsize);

    if (i == 3) {
      sprintf (cmd, "-X%s -Y%s -S%s -E%s -P%s %s %s",
               dpi, ydpi, slant, extend, designsize, pfbname, pkname);
    } else if (i == 4 && bdpi[0]) {
      sprintf (cmd, "-X%s -Y%s -R%s -S%s -E%s -P%s %s %s",
               dpi, ydpi, bdpi, slant, extend, designsize, pfbname, pkname);
    } else if (i == 4 && encname[0]) {
      sprintf (cmd, "-e%s -X%s -Y%s -S%s -E%s -P%s %s %s",
               encname, dpi, ydpi, slant, extend, designsize, pfbname, pkname);
    } else if (i == 5) {
      sprintf (cmd, "-e%s -X%s -Y%s -R%s -S%s -E%s -P%s %s %s",
               encname, dpi, ydpi, bdpi, slant, extend, designsize, pfbname, pkname);
    } else {
      tpkerr ("File format of pspksupp.map is wrong.");
      goto do_gsftopk;
    }

    strcpy (execfile, "ps2pk.exe");
    fprintf (stderr, "%s %s\n", execfile, cmd);
    strcpy(fullbin, texbindir);
    strcat(fullbin, execfile);
    (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL);

    if (_access (pkname, 0) != 0) {
      tpkerr ("ps2pk failed to make pk font.");
      goto do_gsftopk;
    }
    goto finale;
  }

/*
 * ps2pk is impossible to use
 */

 do_gsftopk:

  tpkerr ("ps2pk cannot be used.");
  tpkerr ("I try gsftopk.");
  app = 2;

  strcpy (execfile, "gsftopk.exe");
  fprintf (stderr, "%s %s %s\n", execfile, name, dpi);
  strcpy(fullbin, texbindir);
  strcat(fullbin, execfile);
  (void) _spawnlp (_P_WAIT, fullbin, execfile, name, dpi, NULL);

  if (_access (pkname, 0) != 0) {
    tpkerr ("gsftopk cannot be used.");
    tpkerr ("Next I try ttf2pk.");
    app = 3;
    strcpy (execfile, "ttf2pk.exe");
    fprintf (stderr, "%s -q %s %s\n", execfile, name, dpi);
    strcpy(fullbin, texbindir);
    strcat(fullbin, execfile);
    (void) _spawnlp (_P_WAIT, fullbin, execfile, "-q", name, dpi, NULL);

    if (_access (pkname, 0) != 0) {
      tpkerr ("ttf2pk failed.");
      tpkerr ("Finally I try hbf2gf.");
      app = 4;
      strcpy (execfile, "hbf2gf.exe");
      fprintf (stderr, "%s -q -p %s %s\n", execfile, name, dpi);
      strcpy(fullbin, texbindir);
      strcat(fullbin, execfile);
      (void) _spawnlp (_P_WAIT, fullbin, execfile, "-q -p", name, dpi, NULL);

      sprintf (cmd, "%s.%sgf", name, dpi);
      if (_access (cmd, 0) != 0) {
        tpkerr ("All trials failed.");
        _chdrive (cdrive);
        _chdir (currdir);
        relmem (arg);
        free(tmp);
        return (100);
      }
      strcpy (execfile, "gftopk.exe");
      fprintf (stderr, "%s %s %s\n", execfile, cmd, pkname);
      strcpy(fullbin, texbindir);
      strcat(fullbin, execfile);
      (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, pkname, NULL);

      if (_access (pkname, 0) != 0) {
        tpkerr ("All trials failed.");
        _chdrive (cdrive);
        _chdir (currdir);
        relmem (arg);
        free(tmp);
        return (100);
      }
      remove (cmd);
    }
  }

 finale:

/*
 * return to original stdout and stdin
 */
  _dup2 (savo, fileno (stdout));
  close (savo);
  _dup2 (savi, fileno (stdin));
  close (savi);

/*
 * close nul device
 */
  fclose (fnul);

/*
 * copy the pk file
 */
  if (!(fr = fopen (pkname, "rb"))) {
    fprintf (stderr, "Cannot open %s to read.\n", pkname);
    _chdrive (cdrive);
    _chdir (currdir);
    relmem (arg);
    free(tmp);
    return (100);
  }

  if (!(fw = fopen (buff, "wb"))) {
    fprintf (stderr, "Cannot open %s to write.\n", buff);
    _chdrive (cdrive);
    _chdir (currdir);
    relmem (arg);
    free(tmp);
    return (100);
  }

  while ((i = (int)fread (rbuff, 1, LBUF, fr)))
    fwrite (rbuff, 1, i, fw);

  fclose (fr);
  fclose (fw);
  remove (pkname);

  relmem (arg);

/*
 * update ls-R if it exists
 */
  mktexupd (buff);

/*
 * tell kpathsea
 */

  printf ("%s\n", buff);
  _chdrive (cdrive);
  _chdir (currdir);
  free(tmp);

  return (0);
}