Exemple #1
0
void CClctrl::exitError(const string error)
{
  cerr << error << endl << endl;
  waitForSpace();
  helpInfo();
  exit(1);
}
//check command before a user logged
int beforeLogged(const uchar *str)
{
	int cmdCode=CmdFormatCheck(str);
	if(cmdCode==-1)
	{
		printf("Too long command. Please re-input again:\n");
		return 0;
	}
    if(cmdCode!=1 && cmdCode!=2 )
    {
        if(cmdCode==8)
        {
            helpInfo();
            fputs("Now, input your command below:\n", stdout);
        }
        else
        {
            fputs("\nOnly Register, Login, Help commands work before you logged.\n", stdout);
            fputs("Please input your command again!\n", stdout);
        }
        return 0;
    }
    else
    {
        if(cmdCode==1)
        {
            Register();
        }
        return 1;
    }

}
Exemple #3
0
Fichier : app.c Projet : HsuJv/Note
int getOption(const char* options[], const char *op){
    unsigned int i;
    
    for (i = 0; options[i]; i++){
        if (!strcmp(options[i], op)) return i;
    }
    
    fprintf(stdout, "unknown option %s\n", op);
    helpInfo();
    exit(0);
}
Exemple #4
0
void printHelp()
{
	std::cout << "Usage: repobouncerclient <address> <port> <username> <password> <command> [<args>]" << std::endl;
	std::cout << std::endl;
	std::cout << "address\t\tAddress of database instance" << std::endl;
	std::cout << "port\t\tPort of database instance" << std::endl;
	std::cout << "username\tUsername to connect to database" << std::endl;
	std::cout << "password\tPassword of user" << std::endl;
	std::cout << std::endl;
	std::cout << "Supported Commands:" << std::endl;
	std::cout << helpInfo() << std::endl;
}
Exemple #5
0
int main(int argc, char** argv)
{
//-------------------------------Analyse params---------------------------
	int ch;

	if(argc <= 1)
	{
		retval = NO_PARAM;
		goto EXIT;
	}
	else if(argv[1][0] != '-' && isNum(argv[1]))
	{
		programNum = atoi(argv[1]);
	}
	else if(argv[1][0] != '-' && !isNum(argv[1]))
	{
		retval = NO_PARAM;
		goto EXIT;
	}

	while((ch = getopt(argc, argv, "s:a:h")) != -1)
	{
		switch(ch)
		{
			case 's':
				if(isNum(optarg))
					freq = atoi(optarg);
				else
				{
					retval = PARAM_ERR;
					goto EXIT;
				}

				break;
			case 'a':
				break;
			case 'h':
				helpInfo();
				break;
			default:
				helpInfo();
		}
	}	


//----------------------------Init memory----------------------------
    progInfoBuffer = (char *)malloc(PROG_INFO_BUFFER_SIZE);
	if(progInfoBuffer == NULL)
	{
		printf("Erro occurred! Maybe lack of memory.");
		return MALLOC_ERR;
	}

//---------------------------Get dat from profile file----------------

	int tmpDatLen = 0;

	sprintf(progInfoBuffer, "[freq] %d\n", freq);	
	tmpDatLen = strlen(progInfoBuffer);

	if(freq > 0)
	{
		if((datFp = fopen("tmp.dat", "w+")) == NULL)
		{
			retval = DAT_OPEN_ERR;
			goto EXIT;
		}

		fwrite(progInfoBuffer, tmpDatLen,1, datFp);
	}
	else
	{
		if((datFp = fopen("tmp.dat", "r")) == NULL)
		{
			retval = DAT_OPEN_ERR;
			goto EXIT;
		}

		char* freqFromFile;
		int tmpFreq = 0;
		freqFromFile = (char*)malloc(tmpDatLen + 1);
		fread(freqFromFile, tmpDatLen, 1, datFp);

		if(sscanf(freqFromFile, "[freq] %d\n", &tmpFreq) > 0)
			freq = tmpFreq;

		free(freqFromFile);
	}

	if(datFp != NULL)
		fclose(datFp);

	if(freq == -1)
	{
		retval = FREQ_ERR;
		goto EXIT;
	}

	if(programNum != -1)
	{
		programWantToPlay = programNum;
		printf("Program Num: %d\n", programWantToPlay);
	}

	printf("Freq is %d\n", freq);

//---------------------Start to parse ts---------------------
	if(!parseTS(freq))
	{
		retval = FREQ_ERR;
		goto EXIT;
	}

EXIT:

	if(progInfoBuffer != NULL)
		free(progInfoBuffer);

	if(retval != 0)
		errInfo(retval);

	return retval;	
}
Exemple #6
0
int main                        // MAIN-LINE
    ( int arg_count             // - # arg.s
    , char const * args[] )     // - arguments
{
    int retn = 0;
    if( arg_count != 4 ) {
        helpInfo();
        retn = 1;
    } else {
        in = fopen( args[1], "rt" );
        if( NULL == in ) {
            errmsg( "cannot open"
                  , args[1]
                  , NULL );
            retn = 2;
        } else {
            tgt = fopen( args[2], "rt" );
            if( 0 == tgt ) {
                notemsg( "creating"
                       , args[2]
                       , NULL );
                tgt_write = TRUE;
            } else {
                readTgt();
            }
            readSrc();
            for( ; ; ) {
                if( ! have_src ) break;
                if( ! tgt_write ) {
                    if( have_tgt ) {
                        if( src_size == strlen( target )
                         && 0 == memcmp( target, src_rec, src_size ) ) {
                            readTgt();
                        } else {
                            notemsg( "replacing"
                                   , args[2]
                                   , NULL );
                            tgt_write = TRUE;
                        }
                    } else {
                        tgt_write = TRUE;
                    }
                }
                if( ! storeSrc() ) {
                    errmsg( "ran out of memory", NULL );
                    retn = 2;
                    break;
                }
                readSrc();
            }
            if( have_tgt ) {
                tgt_write = TRUE;
            }
            fclose( in );
            if( NULL != tgt ) {
                fclose( tgt );
            }
            if( 0 == retn ) {
                struct stat src_stats;
                struct utimbuf mod_times;
                stat( args[1], &src_stats );
                mod_times.actime = src_stats.st_mtime;
                mod_times.modtime = src_stats.st_mtime;
                if( tgt_write && retn == 0 ) {
                    tgt = fopen( args[2], "wt" );
                    if( 0 == tgt ) {
                        errmsg( "cannot write file"
                              , args[2]
                              , NULL );
                        retn = 2;
                    } else {
                        record* rec = recordsList;
                        while( NULL != rec ) {
                            if( NULL == fputs( rec->_data, tgt ) ) {
                                errmsg( "i/o error writing file"
                                      , args[2]
                                      , NULL );
                                retn = 2;
                                break;
                            }
                            rec = rec->_next;
                        }
                        fclose( tgt );
                        if( 0 == retn ) {
                            utime( args[2], &mod_times );
                            retn = setTimeFile( args[3], &mod_times );
                        }
                    }
                } else {
                    retn = setTimeFile( args[3], &mod_times );
                }
            }
        }
        remove( args[1] );
    }
    return retn;
}
Exemple #7
0
Fichier : app.c Projet : HsuJv/Note
int main(int argc, char* argv[]){
    const char* options[] = {"-u", "upload", "-d", "download", \
        "-h", "help", "-l", "list", "-r", "remove", 0};
    int op;

    if (argc != 3 && argc != 2){
        helpInfo();
        return 0;
    }
    
    op = getOption(options, argv[1]);
    switch(op){
        case 0:
        case 1:
            if (argc == 2){
                fprintf(stdout, "Please input the filename!\n");
                exit(0);
            }
            if (access(argv[2], R_OK)){
                fprintf(stdout, "File '%s' not exists,\n", argv[2]);
                fprintf(stdout, "Or permession denied.\n");
                fprintf(stdout, "Please check the filename.\n");
                exit(0);
            }
            if(!uploadFile(argv[2]))
                fprintf(stdout, "Upload %s success\n", argv[2]);
            break;
        case 2:
        case 3:
            if (argc == 2){
                fprintf(stdout, "Please input the filename!\n");
                exit(0);
            }
            if(!downloadFile(argv[2]))
               fprintf(stdout, "Downloadload %s success\n", argv[2]);
            break;
        case 4:
        case 5:
            helpInfo();
            break;
        case 6:
        case 7:
            if (argc == 2){
                fprintf(stdout, "Please input the filename!\n");
                exit(0);
            }
            dfsList(argv[2]);
            break;
        case 8:
        case 9:
            if (argc == 2){
                fprintf(stdout, "Please input the filename!\n");
                exit(0);
            }
            if (!dfsRemove(argv[2]))
                fprintf(stdout, "Delete %s success\n", argv[2]);
            break;
        default:
            exit(-1);
    }
    exit(0);
}