Esempio n. 1
0
int main(int argc, char **argv) {
    char *arg;

    char *address = NULL;
    char *language = NULL;

    bool use_json = false;

    string_array *languages = NULL;

    for (int i = 1; i < argc; i++) {
        arg = argv[i];
        if (string_equals(arg, "-h") || string_equals(arg, "--help")) {
            printf(LIBPOSTAL_USAGE);
            exit(EXIT_SUCCESS);
        } else if (string_equals(arg, "--json")) {
            use_json = true;
        } else if (address == NULL) {
            address = arg;
        } else if (!string_starts_with(arg, "-")) {
            if (languages == NULL) {
                languages = string_array_new();
            }
            string_array_push(languages, arg);
        }
    }

    if (address == NULL && (!use_json || isatty(fileno(stdin)))) {
        log_error(LIBPOSTAL_USAGE);
        exit(EXIT_FAILURE);
    }

    if (!libpostal_setup() || (languages == NULL && !libpostal_setup_language_classifier())) {
        exit(EXIT_FAILURE);
    }

    normalize_options_t options = get_libpostal_default_options();

    if (languages != NULL) {
        options.languages = languages->a;
        options.num_languages = languages->n;
    }

    if (address == NULL) {
        char *line;
        while ((line = file_getline(stdin)) != NULL) {
            print_output(line, options, use_json);
            free(line);
        }
    } else {
        print_output(address, options, use_json);
    }

    if (languages != NULL) {
        string_array_destroy(languages);
    }

    libpostal_teardown();
    libpostal_teardown_language_classifier();
}
Esempio n. 2
0
int main(int argc, char *argv[], char *envp[]) {
  int option;
  int i;
  bool newline;
  char **ep;
  char *temp;

  newline = true;

  while((option = getopt(argc, argv, "0h")) != -1) {
    switch(option) {
      case '0': newline = false;
                break;
      case 'h': print_usage();
      default: err_exit("Try 'printenv -h' for more information.\n");
    }
  }

  if(optind == argc) {
    for(ep = envp; *ep != NULL; ep++) {
      print_output(newline, *ep);
    }
  } else {
    for(i = optind; i < argc; i++) {
      temp = getenv(argv[i]);
      if(temp != NULL) {
        print_output(newline, temp);
      }
    }
  }

  exit(EXIT_SUCCESS);
}
Esempio n. 3
0
void open_output(ofstream& outputfile, ofstream& errorfile,
                 string outputfilename) {
    
    outputfile.open(outputfilename.c_str());
    if (!outputfile.is_open()) {
        
        print_output(errorfile, cout, "Cannot open input file: ");
        print_output(errorfile, cout, outputfilename);
        print_output(errorfile, cout, "\n");
        
        exit(1);
    }
}
Esempio n. 4
0
int main(void){
	int x = get_input();
	int y = compute(x);
	print_output(y);

	return 0;
}
Esempio n. 5
0
int main(int argc,char *argv[])
{
	srand(time(NULL));
	int gen_no,tra_no;
	vote_t *votes=parse_input(&gen_no,&tra_no);
	int loy_no=gen_no-tra_no;
	print_input(gen_no,loy_no,tra_no,votes);
	mb_t *mbs=create_mailboxes(gen_no+1);
	mbi_t *mbis=mailbox_addresses(mbs,gen_no+1);
	mbo_t mbo=mbs[0].mbo;
	role_t *roles=init_roles(gen_no,tra_no);
	gen_t *gens=create_generals(roles,mbs,mbis,gen_no,tra_no,votes);
	sig_t sig=getpid();
	int rounds=max_traitors(gen_no)+1;
	for(int round=1;round<=rounds;round++)
	{
		sync_phase_wait(mbo,gen_no);
		print_round(round,rounds);
		print_phase(1,3);
		sync_phase_signal(mbis,sig,gen_no);
		sync_phase_wait(mbo,gen_no);
		print_phase(2,3);
		sync_phase_signal(mbis,sig,gen_no);
		sync_phase_wait(mbo,gen_no);
		print_phase(3,3);
		sync_phase_signal(mbis,sig,gen_no);
	}
	votes=get_final_votes(mbo,loy_no);
	print_output(loy_no,votes);
	free(votes);
	destroy_mailboxes(mbs,gen_no+1);
	free(mbs); free(mbis);
	free(gens); free(roles);
	return 0;
}
Esempio n. 6
0
/*** main
*
***/
int main(int argc, char **argv)
{
	FILE *input;
	FILE *output;
	struct instruction *inst = NULL; //initializing the instruction list
	if(argc == 1) //if argc is 1, that means that only the executable name is specified and there's no input or output files 
	{
		printf("Error: No file specified\n");
	}
	else if(argc == 2) //if argc is 2, that means that only the executable name and input file are specified 
	{
		printf("Error: no output file specified\n");
	}
	else if (argc == 3) //if argc is 3, we're good to go
	{
		input = fopen(argv[1], "r"); //open the input file for reading
		output = fopen(argv[2], "w"); //open the output file for writing 
		inst = set_label_addresses(inst, input); //cycle through the input file and look for labels and note their memory addresses. 
		fclose(input); //close the input file and re-open it to go through the main processing loop
		input = fopen(argv[1], "r");
		inst = process_file(inst, input); 
		print_output(inst, output); //write to the ouput file
		fclose(input);
		fclose(output);
	}
	else //if argc is over 3, then there are too many arguments
	{
		printf("Error: Too many arguments passed to assembler\n");
	}
	return 0;
}
Esempio n. 7
0
//********************************************************************
// Main Functions
//********************************************************************
void main(void) { //Main function
    Sys_Init(); // initialize board
    putchar(' '); //the quotes in this line may not format correctly
    Port_Init();//Init ports
    XBR0_Init();//init xbro
    PCA_Init();//init pca
    SMB_Init();//init smb
    printf("\r\n\n\n\nEmbedded Control Electric Compass and Ranger\n"); //print beginning message

    Calibration();//Run calibration
	comp_cal();	//Compass calibration
    Choose_heading();	//Heading choice 
	printf("\r\nheading error");
	while(1) {	//inf loop, 40 ms it returns the heading	

		if (new_heading){	//enough overflows for a new heading COMPASS STUFF
			new_heading = 0;//Clear new_heading
			heading = ReadCompass();	//get compass heading	
			Steering_Servo();	//run steer func
		}//end if new heading
		
		if (new_range) { //if 80 ms has passed
			new_range=0;//Clear new_range
			range=ReadRanger();//read ranger
			start_ping();//start ping
			counts++;//set up text function
			Drive_Motor();	//run drive func
		}//end if new_range

		if (counts == 3){	//prevoudly output prined every 200 ms, now every 180 ms
			print_output();//Print data function. Delete this if faster output is desired
		}//end if counts
	}//end inf while
}//end main
Esempio n. 8
0
int
matchfun(unsigned char *buf,
	 size_t len,
	 size_t pos,
	 void *misc)
{
    char *pathname = (char *) misc;
    
    pthread_mutex_lock(&matches_lock);
    ++n_matches;
    pthread_mutex_unlock(&matches_lock);

    if (line_f)
	while (pos > 0 &&
	       !(buf[pos-1] == '\n' || buf[pos-1] == '\r'))
	    --pos;
    
    pthread_mutex_lock(&print_lock);
    
    printf("%s : %lu : ", pathname, (unsigned long) pos);
    print_output(buf+pos, len-pos);
    putchar('\n');
    
    pthread_mutex_unlock(&print_lock);
    return 0;
}
Esempio n. 9
0
/* -------------------------------------------------------------
// ------   MAIN - replace this by your own aplication! 
// ------------------------------------------------------------- */
int main(int argn, char *argv[]) {
  int multipnm=1;
  job_t job;

  JOB = &job;
  setvbuf(stdout, (char *) NULL, _IONBF, 0);	/* not buffered */
  
  while (multipnm==1) {

    job_init(&job);
  
    process_arguments(&job, argn, argv);

    mark_start(&job);

    multipnm = read_picture(&job);
    /* separation of main and rest for using as lib
       this will be changed later => introduction of set_option()
       for better communication to the engine  */
    if (multipnm<0) break; /* read error */
  
    /* call main loop */
    pgm2asc(&job);

    mark_end(&job);
  
    print_output(&job);

    job_free(&job);
  
  }
  
  return 0;
}
Esempio n. 10
0
File: node.cpp Progetto: sawrubh/ghs
void Node::reportMessage(int weight, int j) {
  if(j != this->parent){
    if(weight < this->bestWeight){
      this->bestEdge = j;
      this->bestWeight = weight;
    }
    this->findCount += 1;
    report();
  }
  else{ 
    if(this->state == 1){
      message msg;
      msg.id = 5;
      msg.args[0]=weight;
      msg.weight = this->edges[j].weight;
      //place recieved message at queue end
      this->addMessage(msg);
    }
    else if(weight > this->bestWeight){
      changeRoot();
    }
    else if (weight == INF && this->bestWeight == INF){
      print_output();
      run = 0;
      //pthread_exit(NULL);
    }
  }
}	
Esempio n. 11
0
int main(void){
  int time, hour, minute, second;
  
  input(&time);
  distribution(time, &hour, &minute, &second);
  print_output(time, hour, minute, second); 
}
Esempio n. 12
0
/**
 * Print a bit more verbose information about outgoing data to stdout.
 * @param to Pointer to the address of the peer.
 * @param len Number of bytes sent.
 * @param ppid PPID set for the outgoing packet
 * @param streamno Number for the stream where the output was sent.
 */
void print_output_verbose( struct sockaddr_storage *to, int len,
                uint32_t ppid, uint16_t streamno)
{
        print_output(to,len);
        printf("\t stream: %d ppid: %d\n",
                        streamno, ppid);
}
Esempio n. 13
0
static void wrong_tag_error(const std::string & file, int line,
							const std::string & name,const std::string & parent,
							bool flag_exception){
	std::ostringstream ss;
	ss 	 <<at(file,line) << ": tag [" << name << "] may not be used in [" <<
			parent <<"]\n";
	print_output (ss.str (),flag_exception);
}
Esempio n. 14
0
static void missing_tag_error(const std::string & file, int line,
							  const std::string & name,int n,
							  const std::string & parent, bool flag_exception){
	std::ostringstream ss;
	ss 	 <<at(file,line) << ": missing tag [" << name << "]; there must be "
			<< n << " ["<<  name  <<"]s in [" << parent <<"]\n";
	print_output (ss.str (),flag_exception);
}
Esempio n. 15
0
static void wrong_value_error(const std::string & file, int line,
					 const std::string & tag,const std::string & key,
					 const std::string & value,bool flag_exception){
	std::ostringstream ss;
	ss << at(file,line) << ": Invalid value '"<< value << "' in key '" << key <<
			"=' in tag ["<< tag <<"] on line " << line << "'\n";
	print_output (ss.str (),flag_exception);
}
Esempio n. 16
0
static void extra_key_error(const std::string & file, int line,
					 const std::string & tag,const std::string & key,
					 bool flag_exception){
	std::ostringstream ss;
	ss << at(file,line) << ": Invalid key '"<< key <<"=' in tag ["<< tag
			<< "] on line " << line  << "\n";
	print_output (ss.str (),flag_exception);
}
Esempio n. 17
0
static void missing_key_error(const std::string & file, int line,
					 const std::string & tag,const std::string & key,
					 bool flag_exception){
	std::ostringstream ss;
	ss << at(file,line) << ": In tag "<< tag
			<< " which begins here, " << " missing key "<< key << "\n";
	print_output (ss.str (),flag_exception);
}
Esempio n. 18
0
static void missing_key_error(const std::string & file, int line,
					 const std::string & tag,const std::string & key,
					 bool flag_exception){
	std::ostringstream ss;
	ss << "Missing key '" << key << "=' in tag [" << tag
	   << "]\n"
	   << at(file, line) << "\n";
	print_output (ss.str (),flag_exception);
}
Esempio n. 19
0
static void extra_tag_error(const std::string & file, int line,
							const std::string & name,int n,
							const std::string & parent, bool flag_exception){
	std::ostringstream ss;
	ss << "Extra tag [" << name << "]; there may only be "
	   << n << " [" << name << "] in [" << parent << "]\n"
	   << at(file, line) << "\n";
	print_output (ss.str (),flag_exception);
}
Esempio n. 20
0
bool CScriptStorage::do_file	(LPCSTR caScriptName, LPCSTR caNameSpaceName)
{
	int				start = lua_gettop(lua());
	string_path		l_caLuaFileName;
	IReader			*l_tpFileReader = FS.r_open(caScriptName);
	if (!l_tpFileReader) {
		script_log	(eLuaMessageTypeError,"Cannot open file \"%s\"",caScriptName);
		return		(false);
	}
	strconcat		(sizeof(l_caLuaFileName),l_caLuaFileName,"@",caScriptName);
	
	if (!load_buffer(lua(),static_cast<LPCSTR>(l_tpFileReader->pointer()),(size_t)l_tpFileReader->length(),l_caLuaFileName,caNameSpaceName)) {
//		VERIFY		(lua_gettop(lua()) >= 4);
//		lua_pop		(lua(),4);
//		VERIFY		(lua_gettop(lua()) == start - 3);
		lua_settop	(lua(),start);
		FS.r_close	(l_tpFileReader);
		return		(false);
	}
	FS.r_close		(l_tpFileReader);

	int errFuncId = -1;
#ifdef USE_DEBUGGER
#	ifndef USE_LUA_STUDIO
		if( ai().script_engine().debugger() )
			errFuncId = ai().script_engine().debugger()->PrepareLua(lua());
#	endif // #ifndef USE_LUA_STUDIO
#endif // #ifdef USE_DEBUGGER
	if (0)	//.
	{
	    for (int i=0; lua_type(lua(), -i-1); i++)
            Msg	("%2d : %s",-i-1,lua_typename(lua(), lua_type(lua(), -i-1)));
	}

	// because that's the first and the only call of the main chunk - there is no point to compile it
//	luaJIT_setmode	(lua(),0,LUAJIT_MODE_ENGINE|LUAJIT_MODE_OFF);						// Oles
	int	l_iErrorCode = lua_pcall(lua(),0,0,(-1==errFuncId)?0:errFuncId);				// new_Andy
//	luaJIT_setmode	(lua(),0,LUAJIT_MODE_ENGINE|LUAJIT_MODE_ON);						// Oles

#ifdef USE_DEBUGGER
#	ifndef USE_LUA_STUDIO
		if( ai().script_engine().debugger() )
			ai().script_engine().debugger()->UnPrepareLua(lua(),errFuncId);
#	endif // #ifndef USE_LUA_STUDIO
#endif // #ifdef USE_DEBUGGER
	if (l_iErrorCode) {
#ifdef DEBUG
		print_output(lua(),caScriptName,l_iErrorCode);
#endif
		on_error	(lua());
		lua_settop	(lua(),start);
		return		(false);
	}

	return			(true);
}
Esempio n. 21
0
void CScriptEngine::lua_error			(CLuaVirtualMachine *L)
{
	print_output			(L,"",LUA_ERRRUN);

#if !XRAY_EXCEPTIONS
	Debug.fatal				(DEBUG_INFO,"LUA error: %s",lua_tostring(L,-1));
#else
	throw					lua_tostring(L,-1);
#endif
}
Esempio n. 22
0
int  CScriptEngine::lua_pcall_failed	(CLuaVirtualMachine *L)
{
	print_output			(L,"",LUA_ERRRUN);
#if !XRAY_EXCEPTIONS
	Debug.fatal				(DEBUG_INFO,"LUA error: %s",lua_isstring(L,-1) ? lua_tostring(L,-1) : "");
#endif
	if (lua_isstring(L,-1))
		lua_pop				(L,1);
	return					(LUA_ERRRUN);
}
Esempio n. 23
0
void CScriptEngine::lua_error(lua_State *L)
{
    print_output(L, "", LUA_ERRRUN);
    ai().script_engine().on_error(L);

#if !XRAY_EXCEPTIONS
    Debug.fatal(DEBUG_INFO, "LUA error: %s", lua_tostring(L, -1));
#else
    throw					lua_tostring(L,-1);
#endif
}
Esempio n. 24
0
END_TEST

START_TEST (test_print_output)
{
    int command_id = 1;

    print_output(-1);

    add_output("Hello, world!");
    print_output(command_id);

    mark_point();

    set_output_error();
    command_id = -1;
    add_output("Hello, world!");
    print_output(command_id);

    // Only exit value 0 can be tested here ...
}
Esempio n. 25
0
static void license(void)
{
	print_output("lrz version %s\n", PACKAGE_VERSION);
	print_output("Copyright (C) Con Kolivas 2006-2016\n");
	print_output("Based on rzip ");
	print_output("Copyright (C) Andrew Tridgell 1998-2003\n\n");
	print_output("This is free software.  You may redistribute copies of it under the terms of\n");
	print_output("the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n");
	print_output("There is NO WARRANTY, to the extent permitted by law.\n");
}
Esempio n. 26
0
int  CScriptEngine::lua_pcall_failed(lua_State *L)
{
    print_output(L, "", LUA_ERRRUN);
    ai().script_engine().on_error(L);

#if !XRAY_EXCEPTIONS
    Debug.fatal(DEBUG_INFO, "LUA error: %s", lua_isstring(L, -1) ? lua_tostring(L, -1) : "");
#endif
    if (lua_isstring(L, -1))
        lua_pop(L, 1);
    return					(LUA_ERRRUN);
}
Esempio n. 27
0
File: cw.c Progetto: tom-wr/FMP
int main(int argc, char *argv[])
{
	int i;
	printf("\n");

	for(i=1; i < argc; i++)
	{
		if(!read(argv[i])) // if file is not valid print error
			fprintf(stderr, "!!!\tSkipping file '%s' and continuing\n!!!\n", argv[i]);
	}
	print_output(root);
	free_tree(root);
	return (0);
}
Esempio n. 28
0
int main(int argc, char *argv[])
{
  DIR *dip;
  struct dirent *dit;
  
  int i = 0;

  if (argc < 2)
    {
      //prevents argv seg faults
      argv[1] = (char*)malloc(sizeof(char*));
      argv[1] = "";
    }

  char *dirname;
  dirname = get_dir_name(argv, argc);

  //open dir
  if ((dip = opendir(dirname)) == NULL)
    {
      perror("opendir");
      return 0;
    }
 
  char **output;
  output = (char**)malloc(sizeof(char**));

  //read dir
  while ((dit = readdir(dip)) != NULL)
    {
      output[i] = (char*)malloc(sizeof(dit->d_name));
      output[i] = strdup(dit->d_name);
      i++;
    }
 
  print_output(output, i, argv, argc);
 
  //close dirpwd
  //produces seg faults!!!!
  /*
    if (closedir(dip) == -1)
    {
      perror("closedir");
      return 0;
    }
  */
 
  return 1;
}
Esempio n. 29
0
int modes() {
    int status = EXIT_FAILURE;
    do_modes();
#if PRINT_OUTPUT
    printf("== modes ==\n");
    print_output();
#endif
    status = check();
    if (status == EXIT_SUCCESS) {
        printf("== modes: pass\n");
    } else {
        printf("== modes: FAIL!!!\n");
    }
    return status;
}
Esempio n. 30
0
int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int N, size;
    int* arr;
    int* output;
    scanf("%d",&N);
    arr = (int *) malloc(N * sizeof(int));
    output = (int *) malloc(N * sizeof(int));
    for(int arr_i = 0; arr_i < N; arr_i++) {
        scanf("%d", &arr[arr_i]);
    }
    qsort(arr, N, sizeof(int), compare);
    size = get_minimum(arr, output, N);
    print_output(output, size);
    return 0;
}