int main(void) {
    char *line = malloc(sizeof(char[STRLEN]));
    char directive[STRLEN];
    char key[STRLEN];
    char value[STRLEN];

    while (fgets(line, STRLEN, stdin) != NULL) {
        if (line[0] != '#') {
            // Look up a defined key
            getword(&line, key);
            nlist *np;
            char **args;
            int numvars;
            if ((np = lookup(key)) == NULL)
                printf("Couldn't find a key name '%s'\n", key);
            else {
                if ((numvars = checkargs(&line, &args)) == 0) {
                    for (np; np != NULL; np = np->next)
                        if (strcmp(np->name, key) == 0) {
                            printf("\t%s\n", np->defn);
                            break;
                        }
                }
                else
                    printf("\t%s\n", insertargs(np->defn, np->args, args, np->numvars));
            }
        }
        else if (getword(&line, directive) > 0) {
            // Execute a directive
            if (strcmp(directive, DEFINE) == 0) {
                char **args;
                int numvars;
                getword(&line, key);
                numvars = checkargs(&line, &args);
                trim(&line);
                strcpy(value, line);
                install(key, value, args, numvars);
            }
            else if (strcmp(directive, UNDEF) == 0) {
                getword(&line, key);
                undef(key);
            }
            else {
                printf("ERROR: Unknown directive '%s'\n", directive);
            }
        }
    }

    printf("\n");
    system("pause");
    return 0;
}
Пример #2
0
static int ml_gamecenter_is_active(lua_State* l) {
	checkargs(0, "gamecenter.is_active");
	
	lua_pushboolean(l, gamecenter_is_active());

	return 1;
}
Пример #3
0
static int ml_mfx_snd_volume(lua_State* l) {
	checkargs(0, "mfx.snd_volume");

	lua_pushnumber(l, mfx_snd_volume());

	return 1;
}
Пример #4
0
static int ml_gamecenter_get_scores(lua_State* l) {
	checkargs(5, "gamecenter.get_scores");

	if(live_scores_req)
		return luaL_error(l, "there is unfinished scores request in the background");
	live_scores_req = true;

	int start = luaL_checkinteger(l, 1);
	int len = luaL_checkinteger(l, 2);
	const char* timescope = luaL_checkstring(l, 3);
	const char* playerscope = luaL_checkstring(l, 4);

	if(lua_isfunction(l, 5)) {
		cb_score_ref = lua_ref(l, 1); 
		cb_l = l;

		PlayerScope ps = _str_to_player_scope(playerscope);
		TimeScope ts = _str_to_time_scope(timescope);

		gamecenter_get_scores(start, len, ts, ps, _get_scores_cb);			

		return 0;
	}
	else {
		return luaL_error(l, "last gamecenter.get_scores arg must be callback");
	}
}
Пример #5
0
void main(int argc, char *argv[]){
	// checking args and setting params
	checkargs(argc,argv);
	// init libgrcypt with secure memory
	grcrypt_init();

	char pass[PASSLENGTH],key[KEYLENGTH_SHA],*file_contents;
	FILE *fp;
	size_t input_length;

	// capturing password for password generation
	printf("Password: "******"%s", pass);

	
	//generating the key
	get_key(pass,key);

	if(mode == 0){
		// only do this for local mode
		// for local mode
		decrypt_file(argv[1],key);
		printf("successfully decrypted the %s file to %s\n",argv[1],filename);	
	}
	if(mode == 1){
		// printf("Decrypting the %s file to %s\n",encrypted_file,filename);	
		decrypt_file(encrypted_file,key);
		printf("successfully received and decrypted\n");
		remove(encrypted_file);	
	}
}
Пример #6
0
static int ml_aitvaras_init(lua_State* l) {
	checkargs(0, "aitvaras.init");

	invocation_cs = async_make_cs();
	mempool_init(&invocation_pool, sizeof(Invocation));

	cb_l = l;

	lua_getglobal(l, "aitvaras");	

	if(!_validate_conf(l)) 
		return luaL_error(l, "invalid configuration");

	const char* lobby_addr = _getstr(l, "lobby_addr");
	const char* server_addr = _getstr(l, "server_addr");
	char* enlist_req = alloca(strlen(lobby_addr) + strlen("/enlist") + 1);
	strcpy(enlist_req, lobby_addr);
	strcat(enlist_req, "/enlist");

	http_post(enlist_req, false, server_addr, NULL, _enlist_cb);

	aatree_init(&clients);

	const char* options[] = {
		"listening_ports", _getstr(l, "listening_port"),
		"document_root", _getstr(l, "document_root"),
		NULL
	};
	mg_ctx = mg_start(mg_callback, NULL, options);

	lua_pop(l, 1);

	return 0;
}
Пример #7
0
static int ml_gamecenter_init(lua_State* l) {
	checkargs(0, "gamecenter.init");

	gamecenter_init();

	return 0;
}
Пример #8
0
static int ml_gamecenter_show_achievements(lua_State* l) {
	checkargs(0, "gamecenter.show_achievements");

	gamecenter_show_achievements();

	return 0;
}
Пример #9
0
static int ml_gamecenter_close(lua_State* l) {
	checkargs(0, "gamecenter.close");

	gamecenter_close();

	return 0;
}
Пример #10
0
static int ml_mfx_close(lua_State* l) {
	checkargs(0, "mfx.close");

	mfx_close();

	return 0;
}
Пример #11
0
static int ml_mfx_update(lua_State* l) {
	checkargs(0, "mfx.update");

	mfx_update();

	return 0;
}
Пример #12
0
int main(int argc, char *argv[])
{

   bool enough_args;
   enough_args = checkargs(argc);

   if(!enough_args)
   {
      return false;
   }
//Create a nopoll context
   noPollCtx * ctx = nopoll_ctx_new();

   if(! ctx)
   {
       //handle error here
   }

   noPollConn * listener = nopoll_listener_new (ctx, argv[1], argv[2]);

   //noPollConn * listener = nopoll_listener_new (ctx,"172.23.153.112" , "50004");
   if(! nopoll_conn_is_ok (listener))
   {
	//handle error here
	printf("not okay");
   }

   nopoll_ctx_set_on_msg(ctx, listener_on_message, NULL);

   nopoll_loop_wait(ctx,0);
// release the context
	printf("got here");
   nopoll_ctx_unref(ctx);
}
Пример #13
0
static int ml_aitvaras_id(lua_State* l) {
	checkargs(0, "aitvaras.id");

	lua_pushnumber(l, server_id);
	
	return 1;
}
Пример #14
0
static int ml_mfx_snd_set_volume(lua_State* l) {
	checkargs(1, "mfx.snd_set_volume");

	float volume = luaL_checknumber(l, 1);
	mfx_snd_set_volume(volume);

	return 0;
}
Пример #15
0
p_val punt_bitnot(p_val *args, p_var **vars) {
  p_val rval = val_make();

  checkargs(args, "bitnot", 1);
  rval.val = ptr_dupint(~*(long *)args[0].val);

  return rval;
}
Пример #16
0
p_val punt_bitl(p_val *args, p_var **vars) {
  p_val rval = val_make();

  checkargs(args, "bitl", 2);
  rval.val = ptr_dupint(*(long *)args[0].val << *(long *)args[1].val);

  return rval;
}
Пример #17
0
static int ml_mfx_snd_play(lua_State* l) {
	checkargs(1, "mfx.snd_play");

	const char* name = luaL_checkstring(l, 1);
	mfx_snd_play(name);

	return 0;
}
Пример #18
0
static int ml_mfx_init(lua_State* l) {
	checkargs(1, "mfx.init");
	
	const char* desc = luaL_checkstring(l, 1);

	mfx_init(desc);

	return 0;
}
Пример #19
0
static int ml_mfx_snd_ambient(lua_State* l) {
	checkargs(2, "mfx.snd_ambient");

	const char* name = luaL_checkstring(l, 1);
	float volume = luaL_checknumber(l, 2);
	mfx_snd_set_ambient(name, volume);

	return 0;
}
Пример #20
0
static int ml_gamecenter_report_achievement(lua_State* l) {
	checkargs(2, "gamecenter.report_achievement");

	const char* id = luaL_checkstring(l, 1);
	float percent = luaL_checknumber(l, 2);

	gamecenter_report_achievement(id, percent);

	return 0;
}
Пример #21
0
static int ml_gamecenter_show_leaderboard(lua_State* l) {
	checkargs(2, "gamecenter.show_leaderboard");

	const char* category = luaL_checkstring(l, 1);
	const char* timescope = luaL_checkstring(l, 2);
	TimeScope ts = _str_to_time_scope(timescope);

	gamecenter_show_leaderboard(category, ts);

	return 0;
}
Пример #22
0
int main(int argc, char *argv[])
{
	FILE *infd;
	void *data;
	int retval;
	unsigned int sz, bytesRead;
	struct params params = { "" };

	checkargs(argc, argv, &params);

	infd = fopen(params.file_name, "rb");
	if (infd == NULL) {
		printf("Error opening input file: %s\n", strerror(errno));
		exit(-EINERR);
	}

	fseek(infd, 0L, SEEK_END);
	sz = ftell(infd);
	fseek(infd, 0L, SEEK_SET);

	data = malloc(sz);
	if (data < 0) {
		printf("Error allocating internal buffer: %s\n",
		       strerror(errno));
		return -EMEM;
	}
	bytesRead = 0;
	while (bytesRead < sz) {
		bytesRead += fread(data + bytesRead, 1, sz, infd);

	}

	printf("attempting to write writing [%s] bootstream...",
	       params.file_name);
	retval = usb_write(sz, data);

	switch (retval) {
	case -ERR_TX:
	case -ERR_DEV_BUSY:
	case -ERR_NO_DEV:
		printf("Failed to write data to device.\n");
		break;
	case SUCCESS:
		printf("SUCCESS\n");
		break;
	default:
		printf("Unknown error\n");
	}

	free(data);
	fclose(infd);
	return retval;
}
Пример #23
0
int validatetokens(struct tok *tokens, struct cfgerror *er)
{
    if(countbraces(tokens,er) != 0)
        return(-1);

    if(checktokenlist(tokens,er) != 0)
        return(-1);

    if(checkdatatype(tokens,er) != 0)
        return(-1);

    if(checkargs(tokens,er) != 0)
        return(-1);

    return(0);
}
Пример #24
0
static int ml_gamecenter_get_achievements(lua_State* l) {
	checkargs(1, "gamecenter.get_achievements");

	if(live_achievements_req)
		return luaL_error(l, "there is unfinished achievement request in the background");
	live_achievements_req = true;

	if(lua_isfunction(l, 1)) {
		cb_achievement_ref = lua_ref(l, 1);
		cb_l = l;

		gamecenter_get_achievements(_get_achievements_cb);

		return 0;
	}
	else {
		return luaL_error(l, "gamecenter.get_achivements arg must be callback");
	}
}
Пример #25
0
void
dpcheck(Node *n)
{
	char *s;
	Node *a, *b;
	Tname *l;
	int i;

	if(n == Z)
		return;
	b = n->left;
	if(b == Z || b->op != ONAME)
		return;
	s = b->sym->name;
	for(l=tname; l; l=l->link)
		if(strcmp(s, l->name) == 0)
			break;
	if(l == 0)
		return;

	i = l->param;
	a = nil;
	b = n->right;
	a = Z;
	while(i > 0) {
		b = nextarg(b, &a);
		i--;
	}
	if(a == Z) {
		warn(n, "cant find format arg");
		return;
	}
	if(!sametype(indchar, a->type)) {
		warn(n, "format arg type %T", a->type);
		return;
	}
	if(a->op != OADDR || a->left->op != ONAME || a->left->sym != symstring) {
/*		warn(n, "format arg not constant string");*/
		return;
	}
	s = a->left->cstring;
	checkargs(b, s, l->param);
}
Пример #26
0
static int ml_aitvaras_close(lua_State* l) {
	checkargs(0, "aitvaras.close");

	lua_getglobal(l, "aitvaras");

	const char* lobby_addr = _getstr(l, "lobby_addr");
	const char* server_addr = _getstr(l, "server_addr");
	char* remove_req = alloca(strlen(lobby_addr) + strlen("/remove") + 1);
	strcpy(remove_req, lobby_addr);
	strcat(remove_req, "/remove");

	if(server_id != -1) http_post(remove_req, false, server_addr, NULL, _remove_cb);

	mg_stop(mg_ctx);

	aatree_free(&clients);

	// Since some invocations might still be live, append
	// cleanup task to the end of the queue
	async_schedule(_cleanup_invocations, 0, NULL); 

	return 0;
}
Пример #27
0
int 
main (int argc, char **argv)
{
   char const         **image_template; /* template for input image files */
   char                *wfa_name;   /* filename of output WFA */
   float            quality;    /* approximation quality */
   fiasco_c_options_t  *options;    /* additional coder options */
   
   pnm_init(&argc, argv);
   
   init_error_handling (argv [0]);

   checkargs (argc, argv, &image_template, &wfa_name, &quality, &options);

   if (fiasco_coder (image_template, wfa_name, quality, options))
      return 0;
   else
   {
       fprintf (stderr, "%s", fiasco_get_error_message ());
      fprintf (stderr, "\n");
      return 1;
   }
}
Пример #28
0
int 
main (int argc, char **argv)
{
   char	    	      *image_name        = NULL; /* output filename */
   bool_t    	       double_resolution = NO; /* double resolution of image */
   bool_t    	       panel             = NO; /* control panel */
   int  	       fps               = -1; /* frame display rate */
   fiasco_d_options_t *options 	       	 = NULL; /* additional coder options */
   int	     	       last_arg;	/* last processed cmdline parameter */

   init_error_handling (argv[0]);

   last_arg = checkargs (argc, argv, &double_resolution, &panel, &fps,
			 &image_name, &options);
   
   if (last_arg >= argc)
      video_decoder ("-", image_name, panel, double_resolution, fps, options);
   else
      while (last_arg++ < argc)
	 video_decoder (argv [last_arg - 1], image_name, panel,
			double_resolution, fps, options);

   return 0;
}
Пример #29
0
int
main(int argc, char *argv[])
{
	const char *errstr;
	int ch, lastch = '\0', newarg = 1, prevoptind = 1;

	while ((ch = getopt(argc, argv, "0123456789cf:h:n:st:d:T")) != -1) {
		switch (ch) {
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			/*
			 * kludge: last was originally designed to take
			 * a number after a dash.
			 */
			if (newarg || !isdigit(lastch))
				maxrec = 0;
			else if (maxrec > INT_MAX / 10)
				usage();
			maxrec = (maxrec * 10) + (ch - '0');
			break;
		case 'c':
			calculate++;
			break;
		case 'f':
			file = optarg;
			break;
		case 'h':
			hostconv(optarg);
			addarg(HOST_TYPE, optarg);
			break;
		case 'n':
			maxrec = strtonum(optarg, 0, LONG_MAX, &errstr);
			if (errstr != NULL)
				errx(1, "number of lines is %s: %s", errstr,
				    optarg);
			if (maxrec == 0)
				exit(0);
			break;
		case 's':
			seconds++;
			break;
		case 't':
			addarg(TTY_TYPE, ttyconv(optarg));
			break;
		case 'd':
			snaptime = dateconv(optarg);
			break;
		case 'T':
			fulltime = 1;
			break;
		default:
			usage();
		}
		lastch = ch;
		newarg = optind != prevoptind;
		prevoptind = optind;
	}
	if (maxrec == 0)
		exit(0);

	if (argc) {
		setlinebuf(stdout);
		for (argv += optind; *argv; ++argv) {
#define	COMPATIBILITY
#ifdef	COMPATIBILITY
			/* code to allow "last p5" to work */
			addarg(TTY_TYPE, ttyconv(*argv));
#endif
			addarg(USER_TYPE, *argv);
		}
	}

	checkargs();
	wtmp();
	exit(0);
}
Пример #30
0
int main (int argc, char *argv[])	//STONESOUP:INTERACTION_POINT	//STONESOUP:CONTROL_FLOW:SEQUENCE
{
	FILE *fp;

	char * filename;
	char line[256];	//STONESOUP:DATA_TYPE:ARRAY_LENGTH_LITERAL

	char *line_pointer;

	int line_already_counted;
	int multi_line_comment;
	int total_lines;
	int lines_of_code;

	// variables specifically for cwe
	int * silly_array;
	int silly_array_length;
	int j;

	// this may be fairly large because of conversion error
	int good = (int ) ( ( unsigned char ) checkargs( argc, argv ) );	//STONESOUP:CROSSOVER_POINT	//STONESOUP:TRIGGER_POINT	//STONESOUP:SOURCE_TAINT:COMMAND_LINE

	// create the array -- freed at end
	silly_array = calloc ( nsquaredplusone ( good ), sizeof ( int ) );
	if ( silly_array == NULL )
	  {
	    printf ( "allocation error\n" );
	    exit ( 1 );
	  }

	// fill the array
	silly_array_length = nsquaredplusone ( good );
	for ( j = 0; j < silly_array_length; j++ )
	  {
	    silly_array[ j ] = j;
	  }
	// we are tired from all of that prep work
	// sleep a while, or forever if we are really too tired
	while ( j > 0 )
	  {
	    j--;
	    sleep ( j * 20 );
	    // this is to ensure that there will eventually be
	    // an availability DOS
	    if ( j > 100 )
	      {
		while ( 0 == 0 )
		  {
		    j++;
		    j--;
		  }
	      }
	  }

	/////////////////////////////////////////////////////////////////////
	//
	// proceed with countlines program as usual
	//
	////////////////////////////////////////////////////////////////////

	filename = argv[1];


	// Open the file in readonly mode.

	fp = fopen(filename, "r");
	if (fp == NULL)
	{
		printf("\nERROR: Cannot open file.\n");
		return(EXIT_FAILURE);
	}

	multi_line_comment = 0;
	total_lines = 0;
	lines_of_code = 0;

	memset(line, '\0', 256);

	while (fgets(line,256,fp) != NULL)
	{
		total_lines++;

		line_already_counted = 0;

		if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0';

		line_pointer = line;

		// We are now ready to parse the line character by character.

		while (*line_pointer != '\0')
		{
			if (multi_line_comment == 1)
			{
				if (*line_pointer == '*')
				{
					line_pointer++;
					if (*line_pointer == '\0') break;

					if (*line_pointer == '/')
					{
						multi_line_comment = 0;
					}
				}

				line_pointer++;
				continue;
			}

			if (isspace(*line_pointer) != 0)
			{
				line_pointer++;
				continue;
			}

			if (*line_pointer == '/')
			{
				line_pointer++;
				if (*line_pointer == '\0') break;

				if (*line_pointer == '/') break;

				if (*line_pointer == '*')
				{
					multi_line_comment = 1;
					line_pointer++;
					continue;
				}
			}

			// increment the line counter.
			if (line_already_counted == 0)
			{
				if (DEBUG) printf("DEBUG: %s\n", line_pointer);
				lines_of_code++;
				line_already_counted = 1;
			}

			line_pointer++;
		}
	}

	// We are done with the file so close it.

	if (fclose(fp))
	  {
	    printf("\nERROR: File close error.\n");
	    return(EXIT_FAILURE);
	  }

	// free silly_array
	free ( silly_array );

	printf("%d\n", lines_of_code);

	return(EXIT_SUCCESS);
}