int	main(int ac, char **av)
{
  if (ac > 1)
    dos2unix(av + 1);
  else
    printf("%s : usage : %s file1 file2 ...\n", av[0], av[0]);
  return (0);
}
示例#2
0
文件: dos2unix.c 项目: qyh/studio
int main(int argc, char ** argv) {
    if (argc == 2) {
        printf("Converting file %s ...", argv[1]);
        if (dos2unix(argv[1], argv[1]) == -1) {
            exit(EXIT_FAILURE);
        }
        printf("Done\n");
    } else if (argc == 3) {
        printf("Converting file %s to %s ...", argv[1], argv[2]); 
        if (dos2unix(argv[1], argv[2]) == -1) {
            exit(EXIT_FAILURE);
        }
        printf("Done\n");
    } else {
        fprintf(stderr, "Usage: %s inputfile outputfile\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    
    exit(EXIT_SUCCESS);
}
/* example ssh.run["ls /"] */
static int	ssh_run(DC_ITEM *item, AGENT_RESULT *result, const char *encoding)
{
	const char	*__function_name = "ssh_run";
	zbx_sock_t	s;
	LIBSSH2_SESSION	*session;
	LIBSSH2_CHANNEL	*channel;
	int		auth_pw = 0, rc, ret = NOTSUPPORTED,
			exitcode, bytecount = 0;
	char		buffer[MAX_BUFFER_LEN], buf[16], *userauthlist,
			*publickey = NULL, *privatekey = NULL, *ssherr;
	size_t		sz;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	if (FAIL == zbx_tcp_connect(&s, CONFIG_SOURCE_IP, item->interface.addr, item->interface.port, 0))
	{
		SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot connect to SSH server: %s",
				zbx_tcp_strerror()));
		goto close;
	}

	/* initializes an SSH session object */
	if (NULL == (session = libssh2_session_init()))
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot initialize SSH session"));
		goto tcp_close;
	}

	/* set blocking mode on session */
	libssh2_session_set_blocking(session, 1);

	/* Create a session instance and start it up. This will trade welcome */
	/* banners, exchange keys, and setup crypto, compression, and MAC layers */
	if (0 != libssh2_session_startup(session, s.socket))
	{
		libssh2_session_last_error(session, &ssherr, NULL, 0);
		SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot establish SSH session: %s", ssherr));
		goto session_free;
	}

	/* check what authentication methods are available */
	if (NULL != (userauthlist = libssh2_userauth_list(session, item->username, strlen(item->username))))
	{
		if (NULL != strstr(userauthlist, "password"))
			auth_pw |= 1;
		if (NULL != strstr(userauthlist, "keyboard-interactive"))
			auth_pw |= 2;
		if (NULL != strstr(userauthlist, "publickey"))
			auth_pw |= 4;
	}
	else
	{
		libssh2_session_last_error(session, &ssherr, NULL, 0);
		SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain authentication methods: %s", ssherr));
		goto session_close;
	}

	zabbix_log(LOG_LEVEL_DEBUG, "%s() supported authentication methods:'%s'", __function_name, userauthlist);

	switch (item->authtype)
	{
		case ITEM_AUTHTYPE_PASSWORD:
			if (auth_pw & 1)
			{
				/* we could authenticate via password */
				if (0 != libssh2_userauth_password(session, item->username, item->password))
				{
					libssh2_session_last_error(session, &ssherr, NULL, 0);
					SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Password authentication failed: %s",
							ssherr));
					goto session_close;
				}
				else
					zabbix_log(LOG_LEVEL_DEBUG, "%s() password authentication succeeded",
							__function_name);
			}
			else if (auth_pw & 2)
			{
				/* or via keyboard-interactive */
				password = item->password;
				if (0 != libssh2_userauth_keyboard_interactive(session, item->username, &kbd_callback))
				{
					libssh2_session_last_error(session, &ssherr, NULL, 0);
					SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Keyboard-interactive authentication"
							" failed: %s", ssherr));
					goto session_close;
				}
				else
					zabbix_log(LOG_LEVEL_DEBUG, "%s() keyboard-interactive authentication succeeded",
							__function_name);
			}
			else
			{
				SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Unsupported authentication method."
						" Supported methods: %s", userauthlist));
				goto session_close;
			}
			break;
		case ITEM_AUTHTYPE_PUBLICKEY:
			if (auth_pw & 4)
			{
				if (NULL == CONFIG_SSH_KEY_LOCATION)
				{
					SET_MSG_RESULT(result, zbx_strdup(NULL, "Authentication by public key failed."
							" SSHKeyLocation option is not set"));
					goto session_close;
				}

				/* or by public key */
				publickey = zbx_dsprintf(publickey, "%s/%s", CONFIG_SSH_KEY_LOCATION, item->publickey);
				privatekey = zbx_dsprintf(privatekey, "%s/%s", CONFIG_SSH_KEY_LOCATION,
						item->privatekey);

				if (SUCCEED != zbx_is_regular_file(publickey))
				{
					SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot access public key file %s",
							publickey));
					goto session_close;
				}

				if (SUCCEED != zbx_is_regular_file(privatekey))
				{
					SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot access private key file %s",
							privatekey));
					goto session_close;
				}

				rc = libssh2_userauth_publickey_fromfile(session, item->username, publickey,
						privatekey, item->password);
				zbx_free(publickey);
				zbx_free(privatekey);

				if (0 != rc)
				{
					libssh2_session_last_error(session, &ssherr, NULL, 0);
					SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Public key authentication failed:"
							" %s", ssherr));
					goto session_close;
				}
				else
					zabbix_log(LOG_LEVEL_DEBUG, "%s() authentication by public key succeeded",
							__function_name);
			}
			else
			{
				SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Unsupported authentication method."
						" Supported methods: %s", userauthlist));
				goto session_close;
			}
			break;
	}

	/* exec non-blocking on the remove host */
	while (NULL == (channel = libssh2_channel_open_session(session)))
	{
		switch (libssh2_session_last_error(session, NULL, NULL, 0))
		{
			/* marked for non-blocking I/O but the call would block. */
			case LIBSSH2_ERROR_EAGAIN:
				waitsocket(s.socket, session);
				continue;
			default:
				SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot establish generic session channel"));
				goto session_close;
		}
	}

	dos2unix(item->params);	/* CR+LF (Windows) => LF (Unix) */
	/* request a shell on a channel and execute command */
	while (0 != (rc = libssh2_channel_exec(channel, item->params)))
	{
		switch (rc)
		{
			case LIBSSH2_ERROR_EAGAIN:
				waitsocket(s.socket, session);
				continue;
			default:
				SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot request a shell"));
				goto channel_close;
		}
	}

	for (;;)
	{
		/* loop until we block */
		do
		{
			if (0 < (rc = libssh2_channel_read(channel, buf, sizeof(buf))))
			{
				sz = (size_t)rc;
				if (sz > MAX_BUFFER_LEN - (bytecount + 1))
					sz = MAX_BUFFER_LEN - (bytecount + 1);
				if (0 == sz)
					continue;

				memcpy(buffer + bytecount, buf, sz);
				bytecount += sz;
			}
		}
		while (rc > 0);

		/* this is due to blocking that would occur otherwise so we loop on
		 * this condition
		 */
		if (LIBSSH2_ERROR_EAGAIN == rc)
			waitsocket(s.socket, session);
		else if (rc < 0)
		{
			SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot read data from SSH server"));
			goto channel_close;
		}
		else
			break;
	}

	buffer[bytecount] = '\0';
	SET_STR_RESULT(result, convert_to_utf8(buffer, bytecount, encoding));

	ret = SYSINFO_RET_OK;

channel_close:
	/* close an active data channel */
	exitcode = 127;
	while (0 != (rc = libssh2_channel_close(channel)))
	{
		switch (rc)
		{
			case LIBSSH2_ERROR_EAGAIN:
				waitsocket(s.socket, session);
				continue;
			default:
				libssh2_session_last_error(session, &ssherr, NULL, 0);
				zabbix_log(LOG_LEVEL_WARNING, "%s() cannot close generic session channel: %s",
						__function_name, ssherr);
				break;
		}
	}

	if (0 == rc)
		exitcode = libssh2_channel_get_exit_status(channel);
	zabbix_log(LOG_LEVEL_DEBUG, "%s() exitcode: %d bytecount: %d",
			__function_name, exitcode, bytecount);

	libssh2_channel_free(channel);
	channel = NULL;

session_close:
	libssh2_session_disconnect(session, "Normal Shutdown");

session_free:
	libssh2_session_free(session);

tcp_close:
	zbx_tcp_close(&s);

close:
	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;
}
示例#4
0
int main(int argc, char **argv)
{
    int mainfd = 0;
    int opt;
    char *filename;
    char *devname;
    
    if(argc < 3)
    {
    	printf("Usage: %s -f <file.dat> -d <tty device>\n", argv[0]);
	return 1;
    }

    while(1)
    {        
        opt = getopt(argc, argv, "d:f:");

	if(opt == -1)
	    break;
	
        switch(opt)
	{
	    case 'd':
	    	devname = optarg;
	    break;  	  

	    case 'f':
	    	filename = optarg;
	    break;    

	    default:
		printf("Usage: %s -f <file.dat> -d <tty device>\n", argv[0]);
	        exit(1);
	    break;
        }
    }
    
    if(strlen(filename) < 1 || strlen(devname) < 1)
    {
        printf("Usage: %s -f <file.dat> -d <tty device>\n", argv[0]);
        exit(1);
    }
    
    if(dos2unix(filename, "123123123temp.dat") < 0)
    {
	printf("dos2unix conversion failed, probably failed opening %s or creating 123123123temp.dat\n", filename);
	return 1;
    }
    
    mainfd = open_port(devname);
    
    if(mainfd < 0)
    {
    	printf("failed opening %s\n", devname);
	return 1;
    }
    else
        printf("opened device successfully\n");
    
    if(initmc(mainfd) < 0)
    {
	printf("failed mc init\n");
	return 1;
    }
    else
        printf("intialzied micro controller successfully\n");
    
    if(sendprog("123123123temp.dat", mainfd) < 0)
    {
	printf("failed programming\n");
	return 1;
    }     
    else
        printf("programmed eeprom successfully\n");

    unlink("123123123temp.dat");
    close(mainfd);
    return 0;
}
示例#5
0
/******************************************************************************
 *                                                                            *
 * Function: zbx_execute_script                                               *
 *                                                                            *
 * Purpose: executing user scripts or remote commands                         *
 *                                                                            *
 * Return value:  SUCCEED - processed successfully                            *
 *                FAIL - an error occurred                                    *
 *                TIMEOUT_ERROR - a timeout occurred                          *
 *                                                                            *
 * Comments: !!! always call 'zbx_script_clean' function after                *
 *           'zbx_execute_script' to clear allocated memory                   *
 *                                                                            *
 ******************************************************************************/
int	zbx_execute_script(DC_HOST *host, zbx_script_t *script, char **result, char *error, size_t max_error_len)
{
	const char	*__function_name = "zbx_execute_script";
	int		ret = FAIL;
	zbx_uint64_t	groupid;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	*error = '\0';

	switch (script->type)
	{
		case ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT:
			dos2unix(script->command);	/* CR+LF (Windows) => LF (Unix) */

			switch (script->execute_on)
			{
				case ZBX_SCRIPT_EXECUTE_ON_AGENT:
					ret = zbx_execute_script_on_agent(host, script->command, result,
							error, max_error_len);
					break;
				case ZBX_SCRIPT_EXECUTE_ON_SERVER:
					ret = zbx_execute(script->command, result, error, max_error_len,
							CONFIG_TRAPPER_TIMEOUT);
					break;
				default:
					zbx_snprintf(error, max_error_len, "Invalid 'Execute on' option [%d]",
							(int)script->execute_on);
			}
			break;
		case ZBX_SCRIPT_TYPE_IPMI:
#ifdef HAVE_OPENIPMI
			if (SUCCEED == (ret = zbx_execute_ipmi_command(host, script->command, error, max_error_len)))
			{
				if (NULL != result)
					*result = zbx_strdup(*result, "IPMI command successfully executed");
			}
#else
			zbx_strlcpy(error, "Support for IPMI commands was not compiled in", max_error_len);
#endif
			break;
		case ZBX_SCRIPT_TYPE_SSH:
#ifdef HAVE_SSH2
			substitute_simple_macros(NULL, NULL, NULL, NULL, &host->hostid, NULL, NULL,
					&script->publickey, MACRO_TYPE_COMMON, NULL, 0);
			substitute_simple_macros(NULL, NULL, NULL, NULL, &host->hostid, NULL, NULL,
					&script->privatekey, MACRO_TYPE_COMMON, NULL, 0);
			/* break; is not missing here */
#else
			zbx_strlcpy(error, "Support for SSH script was not compiled in", max_error_len);
			break;
#endif
		case ZBX_SCRIPT_TYPE_TELNET:
			substitute_simple_macros(NULL, NULL, NULL, NULL, &host->hostid, NULL, NULL,
					&script->username, MACRO_TYPE_COMMON, NULL, 0);
			substitute_simple_macros(NULL, NULL, NULL, NULL, &host->hostid, NULL, NULL,
					&script->password, MACRO_TYPE_COMMON, NULL, 0);

			ret = zbx_execute_script_on_terminal(host, script, result, error, max_error_len);
			break;
		case ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT:
			if (SUCCEED != DBget_script_by_scriptid(script->scriptid, script, &groupid))
			{
				zbx_snprintf(error, max_error_len,
						"Unknown Script ID [" ZBX_FS_UI64 "]", script->scriptid);
				break;
			}

			if (SUCCEED == check_script_permissions(groupid, host->hostid, error, max_error_len))
			{
				substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, host, NULL,
						&script->command, MACRO_TYPE_SCRIPT, NULL, 0);

				ret = zbx_execute_script(host, script, result, error, max_error_len);	/* recursion */
			}
			break;
		default:
			zbx_snprintf(error, max_error_len, "Invalid command type [%d]", (int)script->type);
	}

	if (SUCCEED != ret && NULL != result)
		*result = zbx_strdup(*result, "");

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;
}
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;         
}
示例#7
0
DIR *opendir(char *fname)
{
      int i;
      unsigned n = 0;
      char *p;
      DOSFileData dstruct;

      for (i = 0; i < _NDIRS; ++i)
      {
            if (!_DIRS[i].dd_fd)
                  break;
      }
      if (_NDIRS <= i)
      {
            DFerr = ENOMEM;
            return NULL;
      }

      dos2unix(fname);
      if (':' == fname[1] && 1 < strlen(fname))
            p = &fname[2];
      else  p = fname;
      while ('/' == LAST_CHAR(p) && 1 < strlen(p))
            LAST_CHAR(p) = '\0';
        
      if (strcmp(p, "/") && strlen(p))
      {
            if (Success_ != (FIND_FIRST(fname, _A_ANY, &_DIRS[i].dd_buf)))
            {
                  DFerr = ENOENT;
                  return NULL;
            }
            if (!(_A_SUBDIR & _DIRS[i].dd_buf.attrib))
            {
                  DFerr = ENOTDIR;
                  return NULL;
            }
      }
      strcpy(_DIRS[i].dd_dirname, fname);
      if (!strlen(p))
            strcat(_DIRS[i].dd_dirname, ".");
      if ('/' != LAST_CHAR(_DIRS[i].dd_dirname))
            strcat(_DIRS[i].dd_dirname, "/");
      strcat(strupr(_DIRS[i].dd_dirname), "*.*");
      if (Success_ != FIND_FIRST(_DIRS[i].dd_dirname,
            _A_ANY, &_DIRS[i].dd_buf))
      {
            DFerr = ENOENT;
            return NULL;
      }
      memcpy(&dstruct, &_DIRS[i].dd_buf, sizeof(DOSFileData));
      do
      {
            ++n;
      } while (Success_ == FIND_NEXT(&_DIRS[i].dd_buf));
      memcpy(&_DIRS[i].dd_buf, &dstruct, sizeof(DOSFileData));
      _DIRS[i].dd_size = n;
      _DIRS[i].dd_loc  = 0;
      _DIRS[i].dd_fd   = i + 1;
      DFerr = Success_;
      return &_DIRS[i];
}
示例#8
0
文件: ndir.c 项目: swhobbit/UUPC
struct direct *readdir(DIR *dirp)
{
   int errcode;

/*--------------------------------------------------------------------*/
/*    Debugging code for failures when running on Novell networks     */
/*--------------------------------------------------------------------*/

   if ( dirp == NULL )
   {
      flushall();
      printmsg(0,"readdir: INTERNAL ERROR: dirp pointer is NULL");
      printmsg(0,"readdir: Snuffles debug code: %s %p %p",
                  openForBusiness ? "Open" : "Closed",
                  lastDirP,
                  thisDirP );
      flushall();
      panic();
   }

   if (!equal(dirp->dirid, "DIR"))
   {
      flushall();
      printmsg(0,"readdir: INTERNAL ERROR: No search in progress");
      printmsg(0,"readdir: Snuffles debug code: %s %p %p %p %s",
                  openForBusiness ? "Open" : "Closed",
                  lastDirP,
                  thisDirP,
                  dirp,
                  dirp->dirid );
      flushall();
      panic();
   }

   if (dirp->dirfirst == -1) {
      union REGS inregs, outregs;
      struct SREGS segregs;
      DTA far *dtaptr;
      DTA far *dtasave;

     /* set DTA address to our buffer each time we're called */
      dtasave = (DTA far *)getdta();
      dtaptr = (DTA far *)&(dirp->dirdta);
      setdta((char far *)dtaptr);

      inregs.h.ah = 0x4f;
      segregs.ds = FP_SEG(dtaptr);
      inregs.x.dx = FP_OFF(dtaptr);
      intdosx(&inregs, &outregs, &segregs);
      errcode = outregs.x.cflag ? outregs.x.ax : 0;

      setdta((char far *)dtasave);  /* Restore DTA address     */

   } else {

      errcode = dirp->dirfirst;
      dirp->dirfirst = -1;

   };

   /* no more files in directory? */
   if (errcode == 18)
      return NULL;

   if ( errcode != 0)
   {
      errno = errcode;
      printerr( "readdir" );
      panic();
   }

   dirp->dirent.d_ino = -1;   /* no inode information */
   strcpy(dirp->dirent.d_name, dirp->dirdta.filename);
   strlwr(dirp->dirent.d_name );
   dirp->dirent.d_namlen = (short) strlen(dirp->dirent.d_name);
   dirp->dirent.d_reclen = (short) (sizeof(struct direct) - (MAXNAMLEN + 1) +
      ((((dirp->dirent.d_namlen + 1) + 3) / 4) * 4));

   dirp->dirent.d_modified = dos2unix( dirp->dirdta.filedate,
                                        dirp->dirdta.filetime );
   dirp->dirent.d_size     = dirp->dirdta.filesize;

   return &(dirp->dirent);

} /*readdir*/
示例#9
0
int main( int argc, char *argv[] ){

	int loop, opt, occurrence;
	char fname[FNAME_LEN];
	FILE *src, *dst;
	
	/* check the input parameters */
	if( argc < 2 ){

		usage();
		exit( 0 );
	}

	/* get only the first option required */
	opt = getopt( argc, argv, options );

	/* for each file in input */
	for( loop = 2; loop < argc; loop++ ){

		/* create backup file */
		strncpy( fname, argv[loop], FNAME_LEN - 4 );
		strcat( fname, ".bak" );
		printf( "creating backup file (%s)\n", fname );
		rename( argv[loop], fname );

		/* open the src and dst files */
		printf( "opening source and destination files\n" );
		src = fopen( fname, "r" );
		dst = fopen( argv[loop], "w" );

		/* check the fopen results */
		if( src != NULL && dst != NULL ){

			/* execute the requested operation */
			switch( opt ){

			/* remove \r\n with \n */
			case 'r':
				occurrence = remove_crnl( src, dst );
				break;

			/* replace \r\n with \n */
			case 'u':
				occurrence = dos2unix( src, dst );
				break;

			/* replace \n with \r\n */
			case 'd':
				occurrence = unix2dos( src, dst );
				break;

			/* replace \n with \r */
			case 'm':
				occurrence = unix2mac( src, dst );
				break;

			/* replace \r with \n */
			case 'n':
				occurrence = mac2unix( src, dst );
				break;

			default:
				printf( "ERROR in options\n" );
				occurrence = 0;
				break;
			}

			printf( "found %d occurrence\n", occurrence );

			/* close src and dst files */
			printf( "closing source and destination files\n" );
			fclose( src );
			fclose( dst );
		}
	}

	printf( "end of all operations\n" );

	return 0;
}