Exemplo n.º 1
0
int try_main(int argc, char* argv[])
{
    bool error_flag = false;
    statistics z;
    for(int j = 1; j < argc; ++j)
        {
        try
            {
            z += process_file(argv[j]);
            }
        catch(...)
            {
            error_flag = true;
            std::cerr << "Exception--file '" << argv[j] << "': " << std::flush;
            report_exception();
            }
        }
    z.print_summary();
    return error_flag ? EXIT_FAILURE : EXIT_SUCCESS;
}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{
  int i = 1;
  int retval = 0;

  program_name = argv[0];

  parse_int_env("EJ_MAX_LINE_LENGTH", &max_line_length);
  parse_int_env("EJ_DISABLE_TABS", &disable_tabs);
  parse_int_env("EJ_BASE_INDENT", &base_indent);

  if (i >= argc) die("no files to check");

  for (; i < argc; ++i) {
    if (process_file(argv[i]) < 0) retval = 1;
  }

  return retval;
}
Exemplo n.º 3
0
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
void check_for_file(TString &prev_line, TString txt = "../../data/daqcapture.dq0")
{
	char txtline[256];

	ifstream captured_file(txt);
	captured_file.getline(txtline,sizeof(txtline));
	if(strlen(txtline)==0)
	{	
		cout<<"Error reading "<<txt<<endl;
		return;
	}
	//cout<<txtline<<"\n";
	if( !prev_line.CompareTo(txtline) ) return;
	cout<<"File changed from "<<prev_line<<" to "<<txtline<<endl;
	prev_line = txtline;
	txt = "../../data/";
	txt += txtline;
	cout<<"File to process: "<<txt<<endl;
	process_file(txt,-1);
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
	int i;
	int result = 1;

	if(argc == 1) {
		version_info();
		usage_info();
		return EXIT_SUCCESS;
	}

	for(i=1; i<argc; i++)
		if(result)
			result = process_file(argv[i]);

	if(result)
		return EXIT_SUCCESS;
	else
		return EXIT_FAILURE;
}
Exemplo n.º 5
0
static void
process_path(const char *path)
{
	struct	stat st;
	int	walkflags = FTW_CHDIR;
	char	*buf = NULL;

	if (rflag) {
		if (stat(path, &st) != -1 &&
		    (st.st_mode & S_IFMT) == S_IFDIR) {
			outfn = 1; /* Print filename */

			/*
			 * Add trailing slash if arg
			 * is directory, to resolve symlinks.
			 */
			if (path[strlen(path) - 1] != '/') {
				(void) asprintf(&buf, "%s/", path);
				if (buf != NULL)
					path = buf;
			}

			/*
			 * Search through subdirs if path is directory.
			 * Don't follow symlinks if Rflag is not set.
			 */
			if (!Rflag)
				walkflags |= FTW_PHYS;

			if (nftw(path, recursive, MAX_DEPTH, walkflags) != 0) {
				if (!sflag)
					(void) fprintf(stderr,
					    gettext("%s: can't open \"%s\"\n"),
					    cmdname, path);
				errors = 1;
			}
			return;
		}
	}
	process_file(path, 0);
}
Exemplo n.º 6
0
int main(int argc, char **argv)
{
	char  *in_filename;
	char  *out_filename;

	int  ch;
	while ((ch = getopt_long(argc, argv, "b:c:", longopts, NULL)) != -1) {
		switch (ch) {
			case 'b':
				parse_block_size(optarg);
				break;

			case 'c':
				codec = optarg;
				break;

			default:
				usage();
				exit(1);
		}
	}

	argc -= optind;
	argv += optind;

	if (argc == 2) {
		in_filename = argv[0];
		out_filename = argv[1];
	} else if (argc == 1) {
		in_filename = NULL;
		out_filename = argv[0];
	} else {
		fprintf(stderr, "Can't read from multiple input files.\n");
		usage();
		exit(1);
	}

	/* Process the data file */
	process_file(in_filename, out_filename);
	return 0;
}
Exemplo n.º 7
0
static int
translate_file(const char *cpath, size_t offset, char *toString)
{
    size_t base = 0;
    LIST_MEMBER *pentry = NULL;
    int res = 0;
    char *path, *dpath;

    dpath = path = convert_path(cpath);
    if (!path)
        return 1;

    // The path could be absolute:
    if (get_ImageBase(path, &base))
    {
        pentry = entry_lookup(&cache, path);
        if (pentry)
        {
            path = pentry->path;
            base = pentry->ImageBase;
            if (base == INVALID_BASE)
            {
                l2l_dbg(1, "No, or invalid base address: %s\n", path);
                res = 2;
            }
        }
        else
        {
            l2l_dbg(1, "Not found in cache: %s\n", path);
            res = 3;
        }
    }

    if (!res)
    {
        res = process_file(path, offset, toString);
    }

    free(dpath);
    return res;
}
Exemplo n.º 8
0
static int process_path(const char *path)
{
	int len;
	struct stat st;

	len = strlen(path);
	if (has_symlink_leading_path(len, path))
		return error("'%s' is beyond a symbolic link", path);

	/*
	 * First things first: get the stat information, to decide
	 * what to do about the pathname!
	 */
	if (lstat(path, &st) < 0)
		return process_lstat_error(path, errno);

	if (S_ISDIR(st.st_mode))
		return process_directory(path, len, &st);

	return process_file(path, len, &st);
}
Exemplo n.º 9
0
void process_file_list(
    const char *const *file_name_index,
    jmp_buf *jmp_if_error)
{
    while(*file_name_index)
    {
        /* Check if the current file name is "-" */
        if(strcmp(*file_name_index, STDIN_FILE_NAME) == 0)
        {
            /* The user specified standard input as a file to replace.
               Filter standard input to standard output. */
            process_file(STDIN_FILE_NAME, STDOUT_FILE_NAME, jmp_if_error);
        }
        else
        {
            /* Process current file in-place */
            process_file_in_place(*file_name_index, jmp_if_error);
        }
        file_name_index++;
    }
}
Exemplo n.º 10
0
static char *process_token(char *p, object list) 
{ 
	char word[128], *w; 
	int inquote, noexpand; 

	while (*p && space(*p)) 
		p++; 
	if (noexpand = inquote = *p == '"') 
		p++; 
	for (w=word ; *p && (!space(*p) || inquote) ; p++) 
		if (inquote && *p == '"') 
		inquote = 0; 
	else 
		*w++ = *p; 
	*w = '\0'; 
	if (*word == '@') 
		process_file(list, word+1); 
	else if (*word) 
		process_word(word, list, noexpand); 
	return p; 
} 
Exemplo n.º 11
0
int main(int argc, char **argv)
{
	int i;

	/* Process command line arguments and open input/output files. */
	if (argc < 2) {
#ifdef VMS
		printf("Usage: uaf_to_passwd [sysuaf-brief-list|$|~user]\n");
		printf("($ spawns authorize to make SYSUAF.LIS file)\n");
#else
		printf("Usage: uaf_to_passwd uaf_file\n");
#endif
		return 0;
	}

	for (i = 1; i < argc; i++) {
		process_file(argv[i]);
	}

	return 0;
}
Exemplo n.º 12
0
static void process_rc_file(const char *config)
{
	char text[256];

	if (!config) {
		if (!access(".mspdebug", F_OK)) {
			config = ".mspdebug";
		} else {
			const char *home = getenv("HOME");

			if (home) {
				snprintf(text, sizeof(text), "%s/.mspdebug",
					 home);
				if (!access(text, F_OK))
					config = text;
			}
		}
	}

	if (config)
		process_file(config, 0);
}
//Given files just for this thread and global num found
void process_files(queue_t * loc_file_queue, unsigned int * num_found, char * to_find)
{
	unsigned int local_num_found = 0;
	
	//We have a list of files
	//Loop through each of them
	while(1)
	{
		queue_element_t * item = remove_from_queue(loc_file_queue);
		if(item == NULL)
		{
			//Done increment global with local
			(*num_found) +=local_num_found;
			return;
		}
		
		//Get the str from this item
		char * str = item->path_name;
		//Process this dir
		process_file(str, to_find, &local_num_found);
	}	
}
Exemplo n.º 14
0
void ReadFiles(POETCode* _files, LexState _lexStateStart, std::list<POETProgram*>& resultFiles)
{
   POETCode* files = eval_AST(_files);
   POETCode* p_files=files;
   while (p_files != 0) {
       POETList* fileList = dynamic_cast<POETList*>(p_files);
       POETCode* fileCur = p_files;
       if (fileList != 0) {
              fileCur = fileList->get_first();
              p_files=fileList->get_rest();
        }
       else  p_files = 0;
       
       std::string fname= fileCur->toString(OUTPUT_NO_DEBUG); 
       if (fname == "") {
          std::cerr << "Empty file name: " << fileCur->toString() << " from list " << files->toString() << "\n";
       } 
       lexState = _lexStateStart;
       POETProgram* programFile =  process_file(fname.c_str());
       resultFiles.push_back(programFile);
       lexState=LEX_DEFAULT;
    }
}
Exemplo n.º 15
0
void			process_fat(t_file_info *file_info)
{
	struct fat_header	*fat;
	struct fat_arch		*arch;
	uint32_t			n;
	uint32_t			offset;
	t_file_info			sub_file_info;

	fat = file_info->data;
	n = fat->nfat_arch;
	n = swapuint32_t(n);
	arch = file_info->data + sizeof(fat);
	while (n)
	{
		if (swapuint32_t(arch->cputype) == CPU_TYPE_X86_64)
			offset = arch->offset;
		arch += sizeof(arch) / sizeof(void*);
		n--;
	}
	ft_memcpy(&sub_file_info, file_info, sizeof(t_file_info));
	sub_file_info.data = file_info->data + swapuint32_t(offset);
	process_file(&sub_file_info, FALSE);
}
Exemplo n.º 16
0
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
int main(int argc, char **argv)                                     /* @7c */
{
   int i;
   int rc;                                                          /* @7a */

   rc = parse_cmd_line(argc, argv, cmds, &num_subcmds);             /* @7a */
   if (rc != BAIL_OUT)                                              /* @7c */
     if (open_files(cmds, argc, argv) != BAIL_OUT)
       if (num_files)
         {
           for (i = firstfile; i < argc; i++)
             if (process_file_spec(argv[i], cmds) == BAIL_OUT)
               {                                                    /* @7a */
                 rc = BAIL_OUT;                                     /* @7a */
                 break;
               }                                                    /* @7a */
         }
       else
         rc = process_file(NULL, cmds);                             /* @7c */
     else                                                           /* @7a */
       rc = BAIL_OUT;                                               /* @7a */
   return(rc);                                                      /* @7a */
}
Exemplo n.º 17
0
int main(int argc, char *argv[])
{
	struct saved_data data;
	const char *path;
	char stack_path[PATH_MAX + 1];
	int rc;

	if (argc != 2) {
		fprintf(stderr, "usage: %s input_file\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	memset(&data, 0, sizeof(data));

	path = argv[1];

	rc = process_file(&data, path);
	if (rc < 0)
		return rc;

	rc = sort_specs(&data);
	if (rc)
		return rc;

	rc = snprintf(stack_path, sizeof(stack_path), "%s.bin", path);
	if (rc < 0 || rc >= sizeof(stack_path))
		return rc;
	rc = write_binary_file(&data, stack_path);
	if (rc < 0)
		return rc;

	rc = free_specs(&data);
	if (rc < 0)
		return rc;

	return 0;
}
Exemplo n.º 18
0
int process_directory( t_string8 x_sIn, t_string8 x_sOut, t_string8 x_sRel, t_cmdline8 &cl, t_strlist8 &lstCmp, t_string8 &sRoot, long &lI )
{
	if ( !x_sIn.length() || !x_sOut.length() )
		return 0;

	// Process directory contents
	disk::SFindData fd;
	disk::HFIND hFind = disk::FindFirst( x_sIn.c_str(), "*", &fd );
	if ( disk::c_invalid_hfind == hFind )
		return 0;

	do 
	{ 
		// Ignore relative
		if ( '.' != *fd.szName )
		{
			// Recurse if directory
			if ( disk::eFileAttribDirectory & fd.uFileAttributes )
				process_directory( disk::FilePath< char, t_string8 >( x_sIn, fd.szName ), 
								   disk::FilePath< char, t_string8 >( x_sOut, fd.szName ),
								   disk::FilePath< char, t_string8 >( x_sRel, fd.szName ), 
								   cl, lstCmp, sRoot, lI );

			// Go process the file
			else
				process_file( x_sIn, x_sOut, x_sRel, fd.szName, cl, lstCmp, sRoot, lI );

		} // end if

	// While we can find more files
	} while ( disk::FindNext( hFind, &fd ) );

	// Close the find handle
	disk::FindClose( hFind );

	return 1;
}
Exemplo n.º 19
0
int main(int ac,char *av[]){
  FILE *input_file = stdin;
  FILE *output_file = stdout;
  mode_of_operation = MODE_INTERACTIVE;
  if (ac > 1) {
    input_file = fopen(av[1], "r");
    if (input_file == NULL)
      input_file = stdin;
    else
      mode_of_operation = MODE_FILE;
  }
  initialize(input_file, output_file);

  while(!quit && !feof(input_file)) {
    if (mode_of_operation == MODE_INTERACTIVE) {
      fprintf(output_file, "\n> ");
      fflush(output_file);
    }

    // Parse expression
    yyparse(yyscanner);
    if (use == 1) {
      use = 0;
      process_file(input_file, filename);
    }
    if (help == 1) {
      help = 0;
      if (mode_of_operation == MODE_INTERACTIVE)
        printHelp(output_file);
    } else {
      printResult(output_file, result);
    }
  }
  yylex_destroy(yyscanner);

  return(0);
}
Exemplo n.º 20
0
int main(int argc, char **argv)
{
    if (argc < 2) {
        usage();
    }

    int ii = 1;
    while (strncmp(argv[ii], "-", 1) == 0) {
        if (strcmp(argv[ii], "--byid") == 0) {
            mode = DumpByID;
        } else if (strcmp(argv[ii], "--byseq") == 0) {
            mode = DumpBySequence;
        } else if (strcmp(argv[ii], "--tree") == 0) {
            dumpTree = true;
        } else {
            usage();
        }
        ++ii;
    }

    if (ii >= argc) {
        usage();
    }

    int error = 0;
    int count = 0;
    for (; ii < argc; ++ii) {
        error += process_file(argv[ii], &count);
    }

    printf("\nTotal docs: %d\n", count);
    if (error) {
        exit(EXIT_FAILURE);
    } else {
        exit(EXIT_SUCCESS);
    }
}
Exemplo n.º 21
0
// 递归遍历一个目录
void find_directory(char *dir_name, void (*process_file)(char *, char *), char *type)
{
	DIR *dir;
	struct dirent *entry;
	struct stat statbuf;

	if ((dir = opendir(dir_name)) == NULL) {
		perror("Open Directory Error");
		return;
	}

	// 改变当前工作目录
	chdir(dir_name);
	while ((entry = readdir(dir)) != NULL) {
		if (lstat(entry->d_name, &statbuf) == -1) {
			perror(entry->d_name);
			return;
		}
		// 如果目标是一个目录
		if (S_ISDIR(statbuf.st_mode)) {
			// 注意忽略掉特殊目录 . 和 ..
			if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0) {
				continue;
			}
			// 对子目录递归查找
			find_directory(entry->d_name, process_file, type);
		} else { // 如果是文件
			process_file(entry->d_name, type);
		}
	}

	// 返回上一层目录
	chdir("..");

	// 释放资源
	closedir(dir);
}
Exemplo n.º 22
0
Arquivo: tags.c Projeto: dacap/htmlex
/* executes an extern command, redirects the stdout and process it */
static char *tag_exec_proc (int argc, char *argv[])
{
  if (argc >= 1) {
    char *s, *filename = temp_filename ();
    int outbak = dup (1);
    int outdsc =
	open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
    char buf[4096] = "";
    STREAM *in;
    int c;
    /* make the command to run */
    for (c = 0; c < argc; c++) {
      s = process_text (argv[c]);
      sprintf (buf + strlen (buf), "%s ", s);
      free (s);
    }
    /* redirect the stdout */
    fflush (stdout);
    dup2 (outdsc, 1);
    /* run the command */
    system (buf);
    /* restore the stdout */
    dup2 (outbak, 1);
    close (outdsc);
    close (outbak);
    /* process the redirected output from the file and put it
       to the active output stream */
    in = stopen (filename, "r");
    process_file (in, _o_stream);
    stclose (in);
    /* close */
    remove (filename);
    free (filename);
  }
  /* nothing to add */
  return NULL;
}
Exemplo n.º 23
0
int
main(int argc, char *argv[])
{
    int i;
    int res = 0;
    struct ndn_charbuf *c = ndn_charbuf_create();
    int opt;
    
    while ((opt = getopt(argc, argv, "h")) != -1) {
        switch (opt) {
            case 'h':
            default:
                usage(argv[0]);
        }
    }
    
    if (argv[optind] == NULL)
        return (process_fd(STDIN_FILENO, c));
    
    for (i = optind; argv[i] != 0; i++) {
        res |= process_file(argv[i], c);
    }
    return(res);
}
Exemplo n.º 24
0
/**
 * input_file
 *
 * Función principal para operar sobre el fichero de texto
 *
 * Primero intentamos leer el fichero, a continuación
 * lo procesamos y pedimos las opciones correspondientes
 * al usuario
 */
int input_file(char* filename)
{
	FILE *ifile;
	ifile = fopen(filename, "r");

	PLANNER_INPUT data_input;

	// fichero inaccesible
	if(ifile == NULL)
	{
		printf(ERROR_FILEOPEN, filename);
		return -1;
	}

	// fichero abierto, podemos proseguir
	data_input = process_file(ifile);

	printf(INFO_OPTIONFILE);

	char* opt = read_from_input(stdin);

	// tanto si es 'v' como 'c', imprimimos la información
	if(strcmp(opt, "v") == 0 || strcmp(opt, "c") == 0)
	{
		// imprimir en 'stdout'
		output_algorithm_result(&data_input, stdout);
	}

	// si es 'w' o 'c', escribimos la información en un fichero
	if(strcmp(opt, "w") == 0 || strcmp(opt, "c") == 0)
	{
		save_to_file(&data_input);
	}

	return 0;
}
Exemplo n.º 25
0
int
main (int argc, const char ** argv)
{
  const char ** scan = (argv + 1);
  const char ** end = (argv + argc);

  n_prefix_rules = 0;
  prefix_rules_size = 16;
  prefix_rules = (xmalloc (prefix_rules_size * (sizeof (prefix_rule_t))));

  while ((scan < end) && ((strcmp ((*scan), "--rewrite")) == 0))
    {
      if ((scan + 3) > end)
	abort ();
      if (n_prefix_rules == prefix_rules_size)
	{
	  prefix_rules_size *= 2;
	  prefix_rules
	    = (xrealloc (prefix_rules,
			 (prefix_rules_size * (sizeof (prefix_rule_t)))));
	}
      ((prefix_rules[n_prefix_rules]) . pattern) = (scan[1]);
      ((prefix_rules[n_prefix_rules]) . replacement) = (scan[2]);
      n_prefix_rules += 1;
      scan += 3;
    }

  while (scan < end)
    {
      if ((strcmp ((*scan), "--rewrite")) == 0)
	abort ();
      process_file (*scan++);
    }

  return (0);
}
Exemplo n.º 26
0
/*
 * Read and process all files in directory recursively.
 */
static int
recursive(const char *name, const struct stat *statp, int info, struct FTW *ftw)
{
	/*
	 * Process files and follow symlinks if Rflag set.
	 */
	if (info != FTW_F) {
		/* Report broken symlinks and unreadable files */
		if (!sflag &&
		    (info == FTW_SLN || info == FTW_DNR || info == FTW_NS)) {
			(void) fprintf(stderr,
			    gettext("%s: can't open \"%s\"\n"), cmdname, name);
		}
		return (0);
	}


	/* Skip devices and pipes if Rflag is not set */
	if (!Rflag && !S_ISREG(statp->st_mode))
		return (0);
	/* Pass offset to relative name from FTW_CHDIR */
	process_file(name, ftw->base);
	return (0);
}
Exemplo n.º 27
0
void CScriptEngine::load_common_scripts()
{
#ifdef DBG_DISABLE_SCRIPTS
    return;
#endif
    string_path		S;
    FS.update_path(S, "$game_config$", "script.ltx");
    CInifile		*l_tpIniFile = xr_new<CInifile>(S);
    R_ASSERT(l_tpIniFile);
    if (!l_tpIniFile->section_exist("common"))
    {
        xr_delete(l_tpIniFile);
        return;
    }

    if (l_tpIniFile->line_exist("common", "script"))
    {
        LPCSTR			caScriptString = l_tpIniFile->r_string("common", "script");
        u32				n = _GetItemCount(caScriptString);
        string256		I;
        for (u32 i = 0; i < n; ++i)
        {
            process_file(_GetItem(caScriptString, i, I));
            xr_strcat(I, "_initialize");
            if (object("_G", I, LUA_TFUNCTION))
            {
                //				lua_dostring			(lua(),xr_strcat(I,"()"));
                luabind::functor<void>	f;
                R_ASSERT(functor(I, f));
                f();
            }
        }
    }

    xr_delete(l_tpIniFile);
}
Exemplo n.º 28
0
Arquivo: dump.cpp Projeto: ownyang/cdp
int main(int argc, char **argv)
{
	if(argc < 2)
	{
		printf("Usage: %s fileName\n", argv[0]);
		return -1;
	}

	CAccessConfig* config = CAccessConfig::getInstance();
	config->start();

	std::cout<<"-----------------------------------------------------"<<std::endl;

	//////////////
	process_file(argv[1]);

	std::cout<<"-----------------------------------------------------"<<std::endl;

	config->stop();
	
	delete config;
	
	return 0;
}
Exemplo n.º 29
0
int main(int argc, char **argv)
{
	struct stat rcstat;

	parse_command_line(argc, argv);

	terminal_setup();

	if (!no_init)
		init();

	history_restore(".haltest_history");

	fd_stack[fd_stack_pointer++] = 0;
	/* Register command line handler */
	poll_register_fd(0, POLLIN, stdin_handler);

	if (stat(".haltestrc", &rcstat) == 0 && (rcstat.st_mode & S_IFREG) != 0)
		process_file(".haltestrc");

	poll_dispatch_loop();

	return 0;
}
Exemplo n.º 30
0
int process_directory(const char * path)
{
    printf("Processing %s\n", path);

    //try to open directory
    DIR * directory = opendir(path);
    if(!directory)
        return 0;

    dirent * entry;
    while((entry = readdir(directory)) > 0)
    {
        //skip current, parent, this file and parts
        if(!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..") || strstr(entry->d_name, ".part"))
            continue;

        //create full path for the entry
        char * fullpath = new char[strlen(path) + entry->d_namlen + 2];
        strcpy(fullpath, path);
        strcat(fullpath, entry->d_name);

        //process files
        if(!process_file(fullpath))
        {
            //process subdirs
            strcat(fullpath, "/");
            process_directory(fullpath);
        };

        delete [] fullpath;
    };

    //close directory
    closedir(directory);
    return 1;
};