示例#1
0
int main(int argc, char* argv[])
{
	if(argc != 3) {
		return error("Usage: program_name text_file_name vocabulary_file_name");
	}

	text_file_name = argv[1];
	vocab_file_name = argv[2];

	 /* open streams for all of the files */
	text_file = fopen(text_file_name, "r");
	vocab_file = fopen(vocab_file_name, "r");
	temp_file = fopen(temp_file_name, "w");
	if(text_file == NULL || vocab_file == NULL || temp_file == NULL) {
		return error("text file, vocab file or temp file open error.");
	}

	if(scan_file(text_file) != 0) { /* documentation next to the function */
		return ERROR;
	}

	if(rewrite_file() != 0) { /* documentation next to the function */
		return ERROR;
	}

	if(remove(temp_file_name) != 0) { /* removes the temp file */
		return error("couldn't delete tempfile");
	}

	return 0;
}
示例#2
0
/* we scan only plain files, but also signal errors */
static int scan_entry(const char *full_path, enum os_file_flag flags, int entry_errno, void *data)
{
	struct a6o_on_demand *on_demand = (struct a6o_on_demand *)data;
	int canceled = a6o_on_demand_is_canceled(on_demand);

	if (canceled){
		//a6o_log(ARMADITO_LOG_LIB, ARMADITO_LOG_LEVEL_WARNING, "scan canceled on path %s", full_path);
		return 2;
	}

	if (flags & FILE_FLAG_IS_ERROR) {
		process_error(on_demand->scan, full_path, entry_errno);
		return 1;
	}

	if (!(flags & FILE_FLAG_IS_PLAIN_FILE))
		return 1;

	/* if scan is multi thread, just queue the scan to the thread pool, otherwise do it here */
	if (on_demand->flags & ARMADITO_SCAN_THREADED){
		
		if(full_path != NULL)
		   g_thread_pool_push(on_demand->thread_pool, (gpointer)os_strdup(full_path), NULL);
		/* 
		   full_path can be NULL if AV is launched as normal user and file rights are 700 for example.
		   In this case, we just skip these files to avoid segfault. To be improved.
		*/
	}
	else
		scan_file(on_demand, full_path);

        return 0;
}
示例#3
0
bool dsme_omap_get_temperature(int* temperature)
{
  return scan_file("/sys/class/hwmon/hwmon0/device/temp1_input",
                   "%d",
                   1,
                   temperature);
}
示例#4
0
文件: qrtest.c 项目: culina/quirc
static int test_scan(const char *path, struct result_info *info)
{
	int len = strlen(path);
	struct stat st;
	const char *filename;

	memset(info, 0, sizeof(*info));

	while (len >= 0 && path[len] != '/')
		len--;
	filename = path + len + 1;

	if (lstat(path, &st) < 0) {
		fprintf(stderr, "%s: lstat: %s\n", path, strerror(errno));
		return -1;
	}

	if (S_ISREG(st.st_mode))
		return scan_file(path, filename, info);

	if (S_ISDIR(st.st_mode))
		return scan_dir(path, filename, info);

	return 0;
}
示例#5
0
main(int argc, char *argv[])
{
	register int i;

	outfile = stdout;

	/* If first two args are -o FILE, output to FILE. */
	i = 1;
	if (argc > i + 1 && strcmp(argv[i], "-o") == 0) {
		outfile = fopen(argv[++i], "w");
		++i;
	}
	/* ...Or if args are -a FILE, append to FILE. */
	if (argc > i + 1 && strcmp(argv[i], "-a") == 0) {
		outfile = fopen(argv[++i], "a");
		++i;
	}
	if (!outfile) {
		fprintf(stderr, "Unable to open output file %s\n", argv[--i]);
		return;
	}

	for (; i < argc; i++)
		scan_file(argv[i]);

	return 0;
}
示例#6
0
文件: main.c 项目: james1345-1/Dawn
int main(int argc, char** argv) {

    gint returnCode;
    gchar *zErrMsg;
    gchar sql[512]; /* create oversized buffer */

    /* initialize gstreamer*/
    gst_init(&argc, &argv);
    
    /* Setup sqlite*/
    returnCode = sqlite3_open(DB, &database);
    if( returnCode){
        fprintf( stderr, "Cannot open database: %s:\n", sqlite3_errmsg(database));
        sqlite3_close(database);
        return(EXIT_FAILURE);
    }
    
    memset(sql, '\0', sizeof(sql));
    sprintf(sql, "CREATE TABLE IF NOT EXISTS %s(title text, album text, artist test)", TABLE);
    if( sqlite3_exec(database, sql, NULL, NULL, &zErrMsg) != SQLITE_OK ){
            fprintf(stderr, "SQL error: %s\n", zErrMsg);
            sqlite3_free(zErrMsg);
    }
    
    /* Do things. */
    scan_file(argv[1]);
    
    sqlite3_close(database);
    return (EXIT_SUCCESS);
}
示例#7
0
int
main(int argc, char **argv)
{ int i;
  const char *program = argv[0];
  FILE *ic, *ih;

  argc--;				/* skip program */
  argv++;
  if ( argc < 3 || strcmp(argv[2], "--") )
  { fprintf(stderr, "Usage: %s ic-file ih-file -- file ...\n", program);
    exit(1);
  }

  if ( !(ic = fopen(argv[0], "w")) ||
       !(ih = fopen(argv[1], "w")) )
  { fprintf(stderr, "%s: Could not open output\n", program);
    exit(1);
  }

  argc -= 3;
  argv += 3;

  for(i=1; i<argc; i++)
    scan_file(argv[i]);

  sort_names();
  emit_names(ic, ih);

  fclose(ic);
  fclose(ih);

  return 0;
}
示例#8
0
文件: word-finder.c 项目: bdw/lab
int main(int argc, char *argv[]) {
	int tokens[26];
	if(argc < 2) return usage(argv[0]);
	build_tokens(tokens, argv[1]);
	scan_file("/usr/share/dict/words", tokens);
	return 0;
}
示例#9
0
int
version_detect_from_executable(sci_version_t *result)
{
	sci_dir_t dir;
	char *filename;
	int mac = 0;

	/* For Mac versions we need to search the resource fork */
	mac = !chdir(".rsrc");

	sci_init_dir(&dir);

	filename = sci_find_first(&dir, "*");

	while (filename) {
		if (mac ? is_mac_exe(filename) : is_exe(filename))
			if (!scan_file(filename, result)) {
				sci_finish_find(&dir);

				if (mac)
					chdir("..");

				return 0;
			}

		filename = sci_find_next(&dir);
	}

	if (mac)
		chdir("..");

	return 1;
}
示例#10
0
int main(int argc, char *argv[])
{
    char *n;
    argv++;
    if (*argv == NULL)
        scan_file(stdin, "<stdin>");
    else while((n = *argv++) != NULL) {
        FILE *fp = fopen(n, "r");
        if (fp == NULL) {
            perror(n);
            exit(1);
        }
        scan_file(fp, n);
        fclose(fp);
    }
    exit(0);
}
int main(int argc, char *argv[])
{
    check(argc > 1, "USAGE: logfind word word word");

    scan_file("logfind.c", argc, argv);

    return 0;

error:
    return 1;
}
JNIEXPORT void JNICALL
Java_VirusScanner_scanFile
  (JNIEnv *env, jobject jo, jstring filePath)
{
  const char *filePathNativeStr = (*env)->GetStringUTFChars(env, filePath, 0);
  printf("Hello world from C!\n");
  printf("%s\n", filePathNativeStr);

  scan_file(filePathNativeStr);
  return;
 }
示例#13
0
void scanner::run()
{
    switch(_is_file)
    {
    case true:
        scan_file();
        break;
    case false:
        scan_data();
        break;
    }
}
示例#14
0
vcf_file::vcf_file(const string &filename, bool compressed, const string &chr, const string &exclude_chr, bool force_write_index) :
	filename(filename),
	compressed(compressed),
	has_body(false),
	has_file_format(false),
	has_genotypes(false),
	has_header(false),
	has_meta(false)
{
	open();
	scan_file(chr, exclude_chr, force_write_index);
}
示例#15
0
static void
scan_list(const char *file, GPtrArray *protos, GPtrArray *handoffs)
{
    char *contents, *arg;
    GError *err = NULL;

    if (!g_file_get_contents(file, &contents, NULL, &err)) {
        fprintf(stderr, "%s: %s\n", file, err->message);
        exit(1);
    }
    for (arg = strtok(contents, SEP); arg != NULL; arg = strtok(NULL, SEP)) {
        scan_file(arg, protos, handoffs);
    }
    g_free(contents);
}
示例#16
0
//------------------------------------------------------------------------------
DWORD  WINAPI AutoSearchFiles(LPVOID lParam)
{
  if (lParam == NULL)
  {
    //list all
    char tmp[MAX_PATH];
    int i,nblecteurs = GetLogicalDriveStrings(MAX_PATH,tmp);

    //search
    for (i=0;i<nblecteurs;i+=4)
    {
      switch(GetDriveType(&tmp[i]))
      {
        case DRIVE_FIXED:
        case DRIVE_REMOTE:
        case DRIVE_RAMDISK:
        case DRIVE_REMOVABLE:
          AddItemTreeView(htrv_files,&tmp[i], TRV_HTREEITEM_CONF[FILES_TITLE_FILES]);
          scan_file(&tmp[i], htrv_files);
        break;
      }
    }
  }else
  {
    char tmp_path[MAX_PATH];
    strncpy(tmp_path,(char*)lParam,MAX_PATH);

    AddItemTreeView(htrv_files,tmp_path, TRV_HTREEITEM_CONF[FILES_TITLE_FILES]);
    scan_file(tmp_path, htrv_files);
  }

  //tri and clean
  CleanTreeViewFiles(htrv_files);
  B_AUTOSEARCH = FALSE;
  return 0;
}
示例#17
0
int
jp2_get_bbox (FILE *fp, long *width, long *height,
         double *xdensity, double *ydensity)
{
  int r;
  ximage_info info;

  pdf_ximage_init_image_info(&info);

  rewind(fp);
  r = scan_file(&info, fp);

  *width  = info.width;
  *height = info.height;
  *xdensity = info.xdensity;
  *ydensity = info.ydensity;

  return r;
}
示例#18
0
/**
 *  tests scan_file()
 */
static char * test_scan_file() {
    Logo input;
    FILE *file;
    int i, count;
    char line[LINE_LENGTH];
    printf("Testing %s\n", __FUNCTION__);
    
    file = fopen(TEST_FILE1, "r");
    mu_assert("error, cannot open test file", file != NULL);
    /* scan the file */
    input = scan_file(file);
    /* calculate the number of lines */
    rewind(file);
    count = 0;
    while (fgets(line, sizeof(line), file) != NULL) {
        count = count + 1;
    }
    fclose(file);
    
    /* num_lines member should be same as count + 1 since count starts at 0 */
    mu_assert("error, input->num_lines != count + 1", input->num_lines == count + 1);
    /* counter should be 0 */
    mu_assert("error, input->counter != 0", input->counter == 0);
    /* there should be no newlines */
    for (i=0; i<input->num_lines; i++) {
        mu_assert("error, '\n' found in line",
                  strcspn(input->lines[i], "\n") == strlen(input->lines[i]));
    }
    /* there should be no leading whitespace */
    for (i=0; i<input->num_lines; i++) {
        mu_assert("error, leading whitespace found in line", 
                  isspace(input->lines[i][0]) == 0);
    }
    /* if strlen of line is 0, make sure it's a null char */
    for (i=0; i<input->num_lines; i++) {
        if (strlen(input->lines[i]) == 0) {
            mu_assert("error: empty line not null char", strcmp(input->lines[i], "\0") == 0);
        }
    }
    input->vars = NULL;
    free_logo(input);
    return 0;
}
示例#19
0
/* blocks until scan is finished, even if scan is multi-threaded */
void a6o_on_demand_run(struct a6o_on_demand *on_demand)
{
	struct os_file_stat stat_buf;
	int stat_errno;

	a6o_log(ARMADITO_LOG_LIB, ARMADITO_LOG_LEVEL_INFO, "starting %sthreaded scan of %s",
		on_demand->flags & ARMADITO_SCAN_THREADED ? "" : "non-",
		on_demand->root_path);

	/* create the thread pool now */
	if (on_demand->flags & ARMADITO_SCAN_THREADED)
		on_demand->thread_pool = g_thread_pool_new(scan_entry_thread_fun, on_demand, get_max_threads(), FALSE, NULL);

	/* what is scan root_path? a file or a directory? */
	os_file_stat(on_demand->root_path, &stat_buf, &stat_errno);

	/* it is a file, scan it, in a thread if scan is threaded */
	/* otherwise, walk through the directory and apply 'scan_entry' function to each entry (either file or directory) */
	if (stat_buf.flags & FILE_FLAG_IS_PLAIN_FILE) {
		on_demand->scan->to_scan_count = 1;
		if (on_demand->flags & ARMADITO_SCAN_THREADED)
			g_thread_pool_push(on_demand->thread_pool, (gpointer)os_strdup(on_demand->root_path), NULL);
		else
			scan_file(on_demand, on_demand->root_path);
	} else if (stat_buf.flags & FILE_FLAG_IS_DIRECTORY) {
		int recurse = on_demand->flags & ARMADITO_SCAN_RECURSE;

		count_to_scan(on_demand);
		os_dir_map(on_demand->root_path, recurse, scan_entry, on_demand);
	}

	/* if threaded, free the thread_pool */
	/* this has a side effect to wait for completion of *all* the scans queue'd in the thread pool */
	if (on_demand->flags & ARMADITO_SCAN_THREADED)
		g_thread_pool_free(on_demand->thread_pool, FALSE, TRUE);

	/* send the final progress (100%) */
	final_progress(on_demand->scan);

	if (on_demand->count_thread != NULL)
		g_thread_join(on_demand->count_thread);
}
示例#20
0
int
jp2_include_image (pdf_ximage *ximage, FILE *fp)
{
  int      smask = 0;
  pdf_obj *stream, *stream_dict;
  ximage_info info;

  if (pdf_check_version(1, 5) < 0) {
    WARN("JPEG 2000 support requires PDF version >= 1.5.\n");
    return -1;
  }

  pdf_ximage_init_image_info(&info);
  stream = stream_dict = NULL;

  rewind(fp);
  if (scan_file(&info, &smask, fp) < 0) {
    WARN("JPEG2000: Reading JPEG 2000 file failed.");
    return -1;
  }

  stream      = pdf_new_stream(0);
  stream_dict = pdf_stream_dict(stream);
  pdf_add_dict(stream_dict,
               pdf_new_name("Filter"), pdf_new_name("JPXDecode"));
  if (smask)
    pdf_add_dict(stream_dict,
                 pdf_new_name("SMaskInData"), pdf_new_number(1));
  /* Read whole file */
  {
    int nb_read;
    rewind(fp);
    while ((nb_read =
        fread(work_buffer, sizeof(char), WORK_BUFFER_SIZE, fp)) > 0)
      pdf_add_stream(stream, work_buffer, nb_read);
  }

  pdf_ximage_set_image(ximage, &info, stream);

  return 0;
}
示例#21
0
void run_scan( int argc, char *argv[] )
{
    /* Martin A. Hansen, September 2008 */

    /* For each file in argv scan the file for */
    /* bipartite motifs and output the motifs */
    /* and their count. */

    char      *file        = NULL;
    int        i           = 0;
    seq_entry *entry       = NULL;
    uint      *count_array = NULL;
//    size_t    new_nmemb    = 0;

    count_array = count_array_new( COUNT_ARRAY_NMEMB );

    entry = seq_new( MAX_SEQ_NAME, MAX_SEQ );

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

        fprintf( stderr, "Scanning file: %s\n", file );
        scan_file( file, entry, count_array );
        fprintf( stderr, "done.\n" );
    }

//    fprintf( stderr, "Printing motifs: ... " );
//    count_array_print( count_array, COUNT_ARRAY_NMEMB, CUTOFF );
//    fprintf( stderr, "done.\n" );

    file = argv[ 1 ];

    fprintf( stderr, "Rescanning file: %s\n", file );
    rescan_file( file, entry, count_array, CUTOFF );
    fprintf( stderr, "done.\n" );

    seq_destroy( entry );

    mem_free( &count_array );
}
示例#22
0
int main (int argc, char **argv) {
  if (argc == 1) {
    // Use current directory
  }else {
    for (int argi = 1; argi < argc; ++argi) {
      char *filename = argv[argi];
      FILE *input = fopen (filename, "r");
      if (input != NULL) {
        scan_file (filename);
        fclose (input);
      }else {
        exit_status = EXIT_FAILURE;
        fflush (NULL);
        fprintf (stderr, "%s FILE DOES NOT EXIT\n", filename);
        fflush (NULL);
      }
    }
  }

  return exit_status;
}
示例#23
0
文件: xmpdump.c 项目: Minoos/gimp
int
main (int   argc,
      char *argv[])
{
  g_set_prgname ("xmpdump");
  if (argc > 1)
    {
      for (argv++, argc--; argc; argv++, argc--)
        if (scan_file (*argv) != 0)
          return 1;
      return 0;
    }
  else
    {
      g_print ("Usage:\n"
               "\txmpdump file [file [...]]\n\n"
               "The file(s) given on the command line will be scanned "
               "for XMP metadata\n");
      return 1;
    }
}
示例#24
0
void *
worker(void *arg)
{
    char *path;
    
    
    while (pqueue_get(&pqb, (void **) &path) == 1)
    {
	scan_file(path);
	free(path);
    }

    fflush(stdout);

    pthread_mutex_lock(&aworker_lock);
    --aworkers;
    pthread_mutex_unlock(&aworker_lock);
    pthread_cond_signal(&aworker_cv);

    return NULL;
}
int main(int argc, char *argv[])
{
    int i = 0;
    int use_or = 0;
    glob_t files_found;

    check(argc > 1, "USAGE: logfind [-o] words");

    check(parse_args(&use_or, &argc, &argv) == 0, "USAGE: logfind [-o] words");

    check(list_files(&files_found) == 0, "Failed to list files.");

    for(i = 0; i < files_found.gl_pathc; i++) {
        scan_file(files_found.gl_pathv[i], use_or, argc, argv);
    }

    globfree(&files_found);
    return 0;

error:
    return 1;
}
示例#26
0
int
jp2_include_image (pdf_ximage *ximage, FILE *fp)
{
  unsigned pdf_version;
  pdf_obj *stream, *stream_dict;
  ximage_info info;

  pdf_version = pdf_get_version();
  if (pdf_version < 5) {
    WARN("JPEG 2000 support requires PDF version >= 1.5 (Current setting 1.%d)\n", pdf_version);
    return -1;
  }

  pdf_ximage_init_image_info(&info);
  stream = stream_dict = NULL;

  rewind(fp);
  if (scan_file(&info, fp) < 0) {
    WARN("Reading JPEG 2000 file failed.");
    return -1;
  }

  stream      = pdf_new_stream(0);
  stream_dict = pdf_stream_dict(stream);
  pdf_add_dict(stream_dict,
        pdf_new_name("Filter"), pdf_new_name("JPXDecode"));
  /* Read whole file */
  {
    long nb_read;
    rewind(fp);
    while ((nb_read =
        fread(work_buffer, sizeof(char), WORK_BUFFER_SIZE, fp)) > 0)
      pdf_add_stream(stream, work_buffer, nb_read);
  }

  pdf_ximage_set_image(ximage, &info, stream);

  return 0;
}
示例#27
0
//------------------------------------------------------------------------------
void scan_file(char *path, HANDLE htv)
{
  WIN32_FIND_DATA data;
  char tmp_path[MAX_PATH], file[MAX_PATH];

  snprintf(tmp_path,MAX_PATH,"%s*.*",path);
  HANDLE hfic = FindFirstFile(tmp_path, &data);
  if (hfic == INVALID_HANDLE_VALUE)return;
  do
  {
    // return
    if(data.cFileName[0] == '.' && (data.cFileName[1] == 0 || data.cFileName[1] == '.')){}
    else if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
      snprintf(tmp_path,MAX_PATH,"%s%s\\",path,data.cFileName);
      scan_file(tmp_path, htv);
    }else //file
    {
      strncpy(file,data.cFileName,MAX_PATH);
      AddItemFiletoTreeView(htv, charToLowChar(file), path, NULL);
    }
  }while(FindNextFile (hfic,&data));
}
示例#28
0
文件: scan.c 项目: EQ4/musicd
static bool scan_files_cb(library_file_t *file)
{
  struct stat status;
  
  if (stat(file->path, &status)) {
    musicd_perror(LOG_DEBUG, "scan", "removing file %s", file->path);
    library_file_delete(file->id);
    return true;
  }
  
  if (file->mtime == status.st_mtime) {
    return true;
  }
  
  library_file_clear(file->id);
  if (scan_file(file->path, file->directory)) {
    library_file_mtime_set(file->id, status.st_mtime);
  } else {
    library_file_delete(file->id);
  }
  
  return true;
}
示例#29
0
/* the thread function called by the thread pool, in case of threaded scan */
static void scan_entry_thread_fun(gpointer data, gpointer user_data)
{
	struct a6o_on_demand *on_demand = (struct a6o_on_demand *)user_data;
	char *path = (char *)data;

#ifdef _WIN32
	void * OldValue = NULL;
	if (Wow64DisableWow64FsRedirection(&OldValue) == FALSE) {
		return;
	}
#endif
	if(!cancel)
	   scan_file(on_demand, path);

	/* path was strdup'ed, so free it */
	free(path);

#ifdef _WIN32
	if (Wow64RevertWow64FsRedirection(OldValue) == FALSE ){
		return;
	}
#endif
}
示例#30
0
int
td_scan_includes(td_engine *engine, td_node *node, td_scanner *state)
{
	td_alloc scratch;
	int i, count;
	td_scanner *config = (td_scanner *) state;
	unsigned int salt = relation_salt_cpp(config);
	int set_cursor;
	include_set *set;

	td_alloc_init(&scratch, 10, 1024 * 1024);

	set = (include_set *) td_page_alloc(&scratch, sizeof(include_set));
	set->count = 0;

	for (i = 0, count = node->input_count; i < count; ++i)
		push_include(set, node->inputs[i]);

	set_cursor = 0;
	while (set_cursor < set->count)
	{
		td_file *input = set->files[set_cursor++];
		scan_file(engine, &scratch, input, config, salt, set);
	}

	node->job.idep_count = set->count - node->input_count;

	td_mutex_lock_or_die(engine->lock);
	node->job.ideps = (td_file **) td_page_alloc(&engine->alloc, sizeof(td_file*) * node->job.idep_count);
	td_mutex_unlock_or_die(engine->lock);

	memcpy(&node->job.ideps[0], &set->files[node->input_count], sizeof(td_file*) * node->job.idep_count);

	td_alloc_cleanup(&scratch);

	return 0;
}