Esempio n. 1
0
static
void
esdip_crop (buffer *buf, const device *hw, unsigned int count,
            const Option_Value *val)
{
  ipc_dip_parms p;

  require (dip->plugin && hw && hw->fw_name && val);

  memset (&p, 0, sizeof (p));
  memcpy (&p.parms, &buf->ctx, sizeof (p.parms));
  p.res_x = val[OPT_X_RESOLUTION].w;
  p.res_y = val[OPT_Y_RESOLUTION].w;
  p.gamma = hw->gamma_type[ val[OPT_GAMMA_CORRECTION].w ];
  p.bside = SANE_FALSE;
  if (using (hw, adf) && val[OPT_ADF_MODE].w)
    {
      p.bside = (0 == count % 2);
    }
  strncpy (p.fw_name, hw->fw_name, num_of (p.fw_name));

  ipc_dip_proc (dip->plugin, TYPE_DIP_CROP_FLAG, &p,
                &buf->ctx, (void **) &buf->buf);

  buf->cap  = buf->ctx.bytes_per_line * buf->ctx.lines;
  buf->ptr  = buf->buf;
  buf->end  = buf->ptr;
  buf->end += buf->ctx.bytes_per_line * buf->ctx.lines;
}
Esempio n. 2
0
void generateNum(char *rightAns)
{
	int n=0;//generated number( 1~9 )
	int c=0;//count
	int table[10];//table[0] 은 dummy space. 
				  //테이블에 해당 번호가 이미 나왔는지 아닌지 플래그를 둔다.
				  //1~9 까지만 유효하다.
	long int r;//

	assert(rightAns!=NULL);

	srand(time(NULL));

	for( c=0; c < num_of(table); c++)
		table[c]=false;//initialize

	for( c=0; c < 3 ; c++ ){
		while( 1 ){
			r = rand();//generate random number
			n = r%10;//maybe n is 0~9

			if( n==0 || table[n]==true )//0 is not allowed, or duplicated number
				continue;//re-generate another number

			//now, n is must 1~9 with do duplication.
			rightAns[c]=n+'0';
			table[n]=true;//flag set.
			break;

		}//end of while

		n=0;//table[0] is always 0.

	}//end of for

	rightAns[c]='\0';//c is 3(the last index). mark '\0'. because it is string.

#ifdef DEBUG
	printf("Right Answer is %s\n", rightAns);
#endif
}
Esempio n. 3
0
static const char *get_first_input_addr(const tal_t *ctx,
					const char *buffer,
					const jsmntok_t *txid)
{
	const jsmntok_t *toks, *intxid, *onum, *type, *address;
	unsigned int outnum;
	const char *delve, *txstr;

	/* eg:
	getrawtransaction e84b0c87934a146d211fcaa6f1ec187da33e205fb250400cf66620a82a9111a0 1
	{
	    "hex" : "010000000193721eadf1bb2a40498b41ca6be2adaddf4c1780884637fedf05cf37015ac508000000006b4830450221008ce700a0c872af67612e5d5226f1e8bdcb2329549883b8fa02df002409f54c43022029b10a885ca3c5103574f06ab90e6f5a7c9c2cafe6e583f17316c967d678bab4012103c511c82cf0aae4541c026eee5d9f738dc1cb4a2114e20b3f5710a22dc94825ceffffffff02d0f88774030000001976a9144e81b0986efad3643012783f016ec10a9c3d35cd88ac005a6202000000001976a91434f89b68a07bd841bbca98f9b7b1521ce1a3d17688ac00000000",
	    "txid" : "e84b0c87934a146d211fcaa6f1ec187da33e205fb250400cf66620a82a9111a0",
	    "version" : 1,
	    "locktime" : 0,
	    "vin" : [
	        {
	            "txid" : "08c55a0137cf05dffe37468880174cdfadade26bca418b49402abbf1ad1e7293",
	            "vout" : 0,
	            "scriptSig" : {
	                "asm" : "30450221008ce700a0c872af67612e5d5226f1e8bdcb2329549883b8fa02df002409f54c43022029b10a885ca3c5103574f06ab90e6f5a7c9c2cafe6e583f17316c967d678bab401 03c511c82cf0aae4541c026eee5d9f738dc1cb4a2114e20b3f5710a22dc94825ce",
	                "hex" : "4830450221008ce700a0c872af67612e5d5226f1e8bdcb2329549883b8fa02df002409f54c43022029b10a885ca3c5103574f06ab90e6f5a7c9c2cafe6e583f17316c967d678bab4012103c511c82cf0aae4541c026eee5d9f738dc1cb4a2114e20b3f5710a22dc94825ce"
	            },
	            "sequence" : 4294967295
	        }
	    ],
	    "vout" : [
	        {
	            "value" : 148.39970000,
	            "n" : 0,
	            "scriptPubKey" : {
	                "asm" : "OP_DUP OP_HASH160 4e81b0986efad3643012783f016ec10a9c3d35cd OP_EQUALVERIFY OP_CHECKSIG",
	                "hex" : "76a9144e81b0986efad3643012783f016ec10a9c3d35cd88ac",
	                "reqSigs" : 1,
	                "type" : "pubkeyhash",
	                "addresses" : [
	                    "mng4N2LZqin7joL7GAjs4tp8WNNt8GjcYz"
	                ]
	            }
	        },
	        {
	            "value" : 0.40000000,
	            "n" : 1,
	            "scriptPubKey" : {
	                "asm" : "OP_DUP OP_HASH160 34f89b68a07bd841bbca98f9b7b1521ce1a3d176 OP_EQUALVERIFY OP_CHECKSIG",
	                "hex" : "76a91434f89b68a07bd841bbca98f9b7b1521ce1a3d17688ac",
	                "reqSigs" : 1,
	                "type" : "pubkeyhash",
	                "addresses" : [
	                    "mkM3FYuYoKFiXS3YL99JdJEdPM5HVGpZTj"
	                ]
	            }
	        }
	    ],
	    "blockhash" : "0000000022a3a02881f56c24bbe7556eef98b1e29267b4015a4fbfc83bab5735",
	    "confirmations" : 14,
	    "time" : 1406252550,
	    "blocktime" : 1406252550
	}
	*/
	txstr = tal_fmt(ctx, "%.*s", 
			(int)(txid->end - txid->start),
			buffer + txid->start);
	toks = json_bitcoind(ctx, &buffer,
			     "getrawtransaction", txstr, "1", NULL);
	if (!toks)
		err(1, "getrawtransaction of tx %s", txstr);

	/* This can happen in if someone aims their block reward at
	   the gateway. */
	intxid = json_delve(buffer, toks, ".vin[0].txid");
	onum = json_delve(buffer, toks, ".vin[0].vout");
	if (!intxid || !onum)
		errx(1, "Missing txid/vout in '%s'", buffer);

	/* Get this before we replace buffer. */
	outnum = num_of(buffer, onum);

	/* Get details of *that* tx. */
	txstr = tal_fmt(ctx, "%.*s", 
			(int)(intxid->end - intxid->start),
			buffer + intxid->start);

	toks = json_bitcoind(ctx, &buffer,
			     "getrawtransaction", txstr, "1", NULL);
	if (!toks)
		err(1, "getrawtransaction of input tx %s", txstr);

	/* make sure it's a pubkeyhash */
	delve = tal_fmt(ctx, ".vout[%u].scriptPubKey.type", outnum);
	type = json_delve(buffer, toks, delve);
	if (!type || !json_tok_streq(buffer, type, "pubkeyhash"))
		errx(1, "'%s' was not a pubkeyhash in '%s'", delve, buffer);

	delve = tal_fmt(ctx, ".vout[%u].scriptPubKey.addresses[0]", outnum);
	address = json_delve(buffer, toks, delve);
	if (!address)
		errx(1, "Can't find %s in '%s'", delve, buffer);

	return tal_strndup(ctx, buffer + address->start,
			   address->end - address->start);
}
Esempio n. 4
0
int main( int argc, char *argv[] )
{
    
    
    bool print_usage_and_exit = false;
    bool generate = false;
    long number_count = 100;
    bool has_number_count = false;
    int number_min = 1;
    bool has_number_min = false;
    int number_max = 255;
    bool has_number_max = false;
    int seed = 0;
    bool has_seed = false;
    
    const char* ifile_name = NULL;
    const char* ofile_name = NULL;
    const char* cfile_name = NULL;
    
    ///overallocate the numbers a bit, just in case
    int* number_array = malloc(sizeof(int)*argc);
    size_t number_array_size = 0;
    
    if (!number_array)
    {
      printf("error allocating, somethings wrong\n");
      exit(-1);
    }
    
    for (int i = 1; i < argc; ++i)
    {
        const char* argi = argv[i];
        
        
        //if (atoi(argi) != 0 || arg_is_zero(argi))

        if (atoi(argi) != 0 || arg_is_zero(argi))

        {
          ///this was a number input
          
          
          number_array[number_array_size] = atoi(argi);
          number_array_size++;
          
          continue;
        }
        
        char dash = argi[0];
        
        
        if (strlen(argi) != 2 || dash != '-')
        {
            print_usage();
            return -1;
        }
        
        
        char flag = argi[1];
        
        if (flag == 'u')
        {
            if (print_usage_and_exit) {
            
                ///Example: ./Lab1 -u -u
                print_usage();
                return -1;
            }
            print_usage_and_exit = true;
            continue;
        }
        
        
        if (flag == 'g')
        {
            if (generate || number_array_size > 0) {
            
                ///Example: ./Lab1 -g -g
                ///Example: ./Lab1 -g 5 5
                print_usage();
                return -1;
            }
            generate = true;
            continue;
        }
        
        if (!(i + 1 < argc))
        {
            ///Example: ./Lab1 -m
            print_usage();
            return -1;
        }
        
        
        if (flag == 'n')
        {
            if (has_number_count)
            {
                ///Example: ./Lab1 -n <number> -n <number>
                print_usage();
                return -1;
              //continue;
            }
            
            const char* next_arg_i = argv[i+1];
            char* next_arg_i_end = NULL;
            
            has_number_count = true;

            number_count = strtol( /*first character in string*/next_arg_i
                              , /*this will change the end pointer point to the last character strtol parses as a number*/
                                &next_arg_i_end
                              , /*base*/10);

            if (number_count == 0 && arg_is_not_zero(next_arg_i))
            {
                ///Example: ./Lab1 -n NOTANUMBER
                print_usage();
                return -1;
            }
            
            i++;
            continue;
        }
        
        
        if (flag == 'm')
        {
            if (has_number_min)
            {
                ///Example: ./Lab1 -m <min> -m <min>
                print_usage();
                return -1;
            }
            
            
            const char* next_arg_i = argv[i+1];
            char* next_arg_i_end = NULL;
            
            has_number_min = true;
            number_min = strtol( /*first character in string*/next_arg_i
                              , /*this will change the end pointer point to the last character strtol parses as a number*/
                                &next_arg_i_end
                              , /*base*/10);
            
            if (number_min == 0 && arg_is_not_zero(next_arg_i))
            {
                ///Example: ./Lab1 -m NOTANUMBER
                print_usage();
                return -1;
            }
            i++;
            continue;
        }
        
        
        if (flag == 'M')
        {
            if (has_number_max)
            {
                ///Example: ./Lab1 -M <max> -M <max>
                print_usage();
                return -1;
            }
            
            
            const char* next_arg_i = argv[i+1];
            char* next_arg_i_end = NULL;
            
            has_number_max = true;
            number_max = strtol( /*first character in string*/next_arg_i
                              , /*this will change the end pointer point to the last character strtol parses as a number*/
                                &next_arg_i_end
                              , /*base*/10);
            
            if (number_max == 0 && arg_is_not_zero(next_arg_i))
            {
                ///Example: ./Lab1 -M NOTANUMBER
                print_usage();
                return -1;
            }
            
            i++;
            continue;
        }
        
        if (flag == 's')
        {
            if (has_seed)
            {
                ///Example: ./Lab1 -s <seed> -s <seed>
                print_usage();
                return -1;
            }
            
            
            const char* next_arg_i = argv[i+1];
            char* next_arg_i_end = NULL;
            
            has_seed = true;
            
            
            seed = strtol( /*first character in string*/next_arg_i
                              , /*this will change the end pointer point to the last character strtol parses as a number*/
                                &next_arg_i_end
                              , /*base*/10);
            
            if (seed == 0 && arg_is_not_zero(next_arg_i))
            {
                ///Example: ./Lab1 -s NOTANUMBER
                print_usage();
                return -1;
            }
            
            
            i++;
            continue;
        }
        
        
        
        if (flag == 'i')
        {
            if (ifile_name != NULL)
            {
                ///Example: ./Lab1 -i INPUTFILE -i INPUTFILE
                print_usage();
                return -1;
            }
            
            
            ifile_name = argv[i+1];
            
            i++;
            continue;
        }
        
        if (flag == 'o')
        {
            if (ofile_name != NULL)
            {
                ///Example: ./Lab1 -o OUTPUTFILE -o OUTPUTFILE
                print_usage();
                return -1;
            }
            


            
            ofile_name = argv[i+1];
            
            i++;
            continue;
        }
        
        if (flag == 'c')
        {
            if (cfile_name != NULL)
            {
                ///Example: ./Lab1 -c OUTPUTFILE -c OUTPUTFILE
                print_usage();
                return -1;
            }
            
            
            cfile_name = argv[i+1];
            
            i++;
            continue;
        }
    }
    
    if (print_usage_and_exit)
    {
        print_usage();
        exit(0);
    }
    
    
    if (ifile_name)
    {
        free(number_array);
        
        number_array = get_input_from_file(ifile_name, &number_array_size);
      
    }
    
    
    FILE* ofile = NULL;
    if (ofile_name)
    {
        ofile = fopen(ofile_name, "w");
        if (!ofile)
        {
            printf("Cannot open %s for writing\n", ofile_name);
            exit(-1);
        }
        
    }
    
    FILE* cfile = NULL;
    if (cfile_name)
    {
        cfile = fopen(cfile_name, "w");
        if (!cfile)
        {
            printf("Cannot open %s for writing\n", cfile_name);
            exit(-1);
        }
        
    }
    
    
    if (!generate && number_array_size == 0)
    {
        fprintf(stdout, "Enter the number count\n");
        fflush(stdout);
        
        free(number_array);
        
        int ret = fscanf(stdin, "%zi", &number_array_size);
        fgetc(stdin);
            
        
        if (ret == EOF)
        {
            fprintf(stdout, "Error reading from command line\n");
            exit(-1);
        }
        
        number_array = (int*)malloc(sizeof(int)*number_array_size);
        
        for (int i = 0; i < number_array_size; ++i)
        {
            int value;
            int ret = fscanf(stdin, "%i", &value);
            
            if (ret == EOF)
            {
                fprintf(stdout, "Error reading from command line\n");
                exit(-1);
            }
            fgetc(stdin);
            
            number_array[i] = value;
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    sort_nums(number_array, number_array_size);

    
    
    
    
    
    
    
    
    
    
    
    
    if (generate) 
    {
        if(has_number_count)
        {   
            if(has_number_max && has_number_min && !(has_seed) && !(ofile)) //3
                min_num_Max(number_count, number_min, number_max);

            if(has_number_max && has_number_min && has_seed && ofile) // 1
                min_num_Max_seed(number_count, number_min, number_max, seed, ofile);

            if(has_number_max && has_number_min && has_seed && !(ofile)) // 2 //7
                min_num_Max_seed_Nf(number_count, number_min, number_max, seed);

            else if(has_number_max && !(has_number_min) && !(has_seed) && !(ofile)) // 15
                max_num(number_count,number_max);

            else if (has_number_min &&!(has_number_max) && !(has_seed) && !(ofile)) //4
                min_num(number_count,number_min);


            else if(has_number_max && !(has_number_min) && (has_seed)&& !(ofile)) //12
                max_num_seed(number_count,number_max,seed);

            else if (has_number_min &&!(has_number_max) && (has_seed) && !(ofile) ) //5
                min_num_seed(number_count,number_min,seed);

            else if (has_number_min &&!(has_number_max) && !(has_seed) && (ofile) ) //6
                min_num_of(number_count,number_min,ofile);


            else if (has_number_min && (has_number_max) && !(has_seed) && (ofile) ) //8         // I have problem here
                min_max_num_of(number_count,number_min,number_max,ofile);

            else if (!(has_number_min) && (has_number_max) && !(has_seed) && (ofile) ) //9   // I am heve problem 
                max_num_of(number_count,number_max,ofile);


            else if (!(has_number_min) && !(has_number_max) && (has_seed) && (ofile) ) //10    //  completed 
                num_seed_of(number_count,seed,ofile);

            else if (!(has_number_min) && !(has_number_max) && !(has_seed) && (ofile) ) //11  // result in negative 
                num_of(number_count,ofile);

            else if(has_seed && !(has_number_min) && !(has_number_max) && !(ofile)) //14  // good 
               random_case_generator_seed(number_count,seed);

            else if (!(has_number_min) && (has_number_max) && (has_seed) && (ofile) ) //13  // good 
                max_num_of_seed(number_count,number_max,seed,ofile);
            

            if(has_number_count && !(has_seed) && !(has_number_max) && !(has_number_min) && !(ofile)) //16
                random_num_generator(number_count);
            
            if (has_number_count)
            {
                goto here;
            }
        }

        if(!(has_number_count))
        {   
            if(has_number_max && has_number_min && !(has_seed) && !(ofile)) //3         /////////////// Done
                min_num_Max_nd(number_min, number_max);

            if(has_number_max && has_number_min && has_seed && ofile) // 1             /////////////////Done
                min_num_Max_seed_nd( number_min, number_max, seed, ofile);  //done 

            if(has_number_max && has_number_min && has_seed && !(ofile)) // 2 //7      ////////////// Done 
                min_num_Max_seed_Nf_nd( number_min, number_max, seed);

            else if(has_number_max && !(has_number_min) && !(has_seed) && !(ofile)) // 15  /////////// Done 
                max_num_nd(number_max);

            else if (has_number_min &&!(has_number_max) && !(has_seed) && !(ofile)) //4   //////////// Done 
                min_num_nd(number_min);


            else if(has_number_max && !(has_number_min) && (has_seed)&& !(ofile)) //12    /////////// Done 
                max_num_seed_nd(number_max,seed);

            else if (has_number_min &&!(has_number_max) && (has_seed) && !(ofile) ) //5   /////////// Done 
                min_num_seed_nd(number_min,seed);

            else if (has_number_min &&!(has_number_max) && !(has_seed) && (ofile) ) //6  //////////// Done 
                min_num_of_nd(number_min,ofile);


            else if (has_number_min && (has_number_max) && !(has_seed) && (ofile) ) //8  //////////// Done 
                min_max_num_of_nd(number_min,number_max,ofile);

            else if (!(has_number_min) && (has_number_max) && !(has_seed) && (ofile) ) //9   //////////// Done  
                max_num_of_nd(number_max,ofile);


            else if (!(has_number_min) && !(has_number_max) && (has_seed) && (ofile) ) //10    //////////// Done
                num_seed_of_nd(seed,ofile);

            else if (!(has_number_min) && !(has_number_max) && !(has_seed) && (ofile) ) //11  //////////// Problem 
                num_of_nd(ofile);

            else if(has_seed && !(has_number_min) && !(has_number_max) && !(ofile)) //14  // good //////// Done 
               random_case_generator_seed_nd(seed);

            else if (!(has_number_min) && (has_number_max) && (has_seed) && (ofile) ) //13  // good /////// Done 
                max_num_of_seed_nd(number_max,seed,ofile);
            
            if (!(has_number_count) && !(has_seed) && !(has_number_max) && !(has_number_min) && !(ofile)) //// Done
            {
                random_case_generator();
            }
        }



        here:
            printf("");

    }
    else {
        ///get input from user
        
        
        
        
        
        
        
        
        
        const char* userid = getenv("USER");
        size_t useridlen = strlen(userid);
        
        Begin_clock();

        for (int i = 0; i < useridlen; ++i)
        {
          char c = userid[i];
          
          int freq = calculate_frequency(c, number_array, number_array_size);
          
          if (cfile) fprintf(cfile, "%c  %d\t%d\n", c, (int)c, freq);
          if (!cfile) fprintf(stdout, "%c  %d\t%d\n", c, (int)c, freq);  
        }
        
        if (ofile) {
            for (int i = 0; i < number_array_size; ++i)
            {
                fprintf(ofile, "%d\n", number_array[i]);

            }

            fprintf(ofile, "\n");
        }

        if (!ofile) {
            for (int i = 0; i < number_array_size; ++i)
            {
              printf("\n");
              fprintf(stdout, "%d\t", number_array[i]);

            }

            printf("\n");

        }

            
        Eng_clock();

        Calculate_Time();
    }
    
        
    
    return 0;
}