void catDir(int dirCount, char *dirs[])
/* catDir - concatenate files in directory - for those times when too 
 * many files for cat to handle.. */
{
int i;
struct fileInfo *list, *el;

for (i=0; i<dirCount; ++i)
    {
    list = listDirX(dirs[i], NULL, TRUE);
    for (el = list; el != NULL; el = el->next)
        {
	char *name = el->name;
	if (el->isDir && recurse)
	    {
	    catDir(1, &name);
	    }
	else if (wildCard == NULL || wildMatch(wildCard, name))
	    {
	    if (suffix == NULL || endsWith(name, suffix))
		catFile(name);
	    }
	}
    slFreeList(&list);
    }
}
Пример #2
0
//Print Main Menu
char mainMenu()
{
    char selectmenu;
    printf("\n");
    printf("%60s","################## M E N U ####################\n");
    printf("%60s","# ########################################### #\n");
    printf("%60s","# #                                         # #\n");
    printf("%60s","# #  1 -> Capture to TXT                    # #\n");
    printf("%60s","# #  2 -> Capture to CSV - Excel            # #\n");
    printf("%60s","# #  3 -> Visualize TXT file                # #\n");
    printf("%60s","# #  4 -> Statistics (CSV files)            # #\n");
    printf("%60s","# #  5 -> Exit                              # #\n");
    printf("%60s","# #                                         # #\n");
    printf("%60s","# ########################################### #\n");
    printf("%60s","###############################################\n");
    printf("\nOption: ");

    if(optionSave=='m') {
        scanf("%c", &selectmenu);
    }

    switch (selectmenu)
    {
    case '1':
        optionSave = selectmenu;
        system("clear");
        startCapture(selectmenu);
        fclose(logfile);
        break;
    case '2':
        optionSave = selectmenu;
        system("clear");
        startCapture(selectmenu);
        fclose(logfilecsv);
        break;
    case '3':
        optionSave = selectmenu;
        system("clear");
        catFile();
        break;
    case '4':
        optionSave = selectmenu;
        system("clear");
        statsMenu();
        break;
    case '5':
        printf("Thanks for using this amazing sniffer, bye!!!!\n");
        optionSave = selectmenu;
        exit(0);
        break;
    default:
        system("clear");
        printf(" Invalid option - please select options 1-4!!! \n ");
        main();
        break;
    }

}
Пример #3
0
int main(int argc, char **argv)
{  
  int i;
  if (argc == 1) {
    catFile("-", stdout);
    return EXIT_SUCCESS;
  }

  for (i =1; i < argc; i++) {
    if (strcmp(argv[i], "--help") ==0) {
      printHelp();
      return EXIT_SUCCESS;
    }
  }

  for (i=1; i < argc; i++) {
    if (catFile(argv[i], stdout) == FALSE) {
      fprintf(stderr, "cat cannot open %s\n", argv[i]);
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}
Пример #4
0
int main(int argc, char *argv[])
{
	int inputYet = 0;
	int i;
	for (i=1; i<argc; i++)
	{
		inputYet = 1;
		int fd = open(argv[i], O_RDONLY);
		if (fd == -1)
		{
			perror(argv[i]);
			return 1;
		};
		catFile(fd);
		close(fd);
	};

	if (!inputYet)
	{
		catFile(0);
	};

	return 0;
};
Пример #5
0
static void sortTagFile (void)
{
	if (TagFile.numTags.added > 0L)
	{
		if (Option.sorted != SO_UNSORTED)
		{
			verbose ("sorting tag file\n");
#ifdef EXTERNAL_SORT
			externalSortTags (TagsToStdout);
#else
			internalSortTags (TagsToStdout);
#endif
		}
		else if (TagsToStdout)
			catFile (TagFile.fp);
	}
}
Пример #6
0
static void sortTagFile (void)
{
	if (TagFile.numTags.added > 0L)
	{
		if (Option.sorted != SO_UNSORTED)
		{
			verbose ("sorting tag file\n");
#ifdef EXTERNAL_SORT
			externalSortTags (TagsToStdout);
#else
			internalSortTags (TagsToStdout);
#endif
		}
		else if (TagsToStdout)
			catFile (tagFileName ());
	}
	if (TagsToStdout)
		remove (tagFileName ());  /* remove temporary file */
}
Пример #7
0
void USBDevice::parseSysDir(int bus, int parent, int level, QString dname)
{
  _level = level;
  _parent = parent;
  _manufacturer = catFile(dname + "/manufacturer");
  _product = catFile(dname + "/product");

  _bus = bus;
  _device = catFile(dname + "/devnum").toUInt();

  if (_device == 1)
    _product += QString(" (%1)").arg(_bus);

  _vendorID = catFile(dname + "/idVendor").toUInt(0, 16);
  _prodID = catFile(dname + "/idProduct").toUInt(0, 16);

  _class = catFile(dname + "/bDeviceClass").toUInt(0, 16);
  _sub = catFile(dname + "/bDeviceSubClass").toUInt(0, 16);
  _maxPacketSize = catFile(dname + "/bMaxPacketSize0").toUInt();

  _speed = catFile(dname + "/speed").toDouble();
  _serial = catFile(dname + "/serial");
  _channels = catFile(dname + "/maxchild").toUInt();

  double version = catFile(dname + "/version").toDouble();
  _verMajor = int(version);
  _verMinor = int(10*(version - floor(version)));

  QDir dir(dname);
  dir.setNameFilter(QString("%1-*").arg(bus));
  dir.setFilter(QDir::Dirs);
  QStringList list = dir.entryList();

  for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
    if ((*it).contains(':'))
      continue;

    USBDevice* dev = new USBDevice();
    dev->parseSysDir(bus, ++level, _device, dname + "/" + *it);
  }
}
Пример #8
0
void launchShell() {
    //allocate some memory for command string buffer. 1kB should be enough for now
    const int bufSize = 128;
    char bufStr[bufSize];

    

   
    while (true)
    {
        print("\nQ-Kernel>  ", 0x08);
        typingCmd = true;
        newCmd = true;
        readStr(bufStr, bufSize);
        typingCmd = false;

        if (strEql(strTrim(bufStr), ""))
        {
            print(COMMAND_HELP, 0x0F);
        }
        else if(strEql(bufStr, "help"))
        {
            kbHelp();
            println(PRO_TIP, 0x0F);
            print(COMMAND_HELP, 0x0F);
        }
        else if(strEql(bufStr, "reboot"))
        {
            //reboots the computer
            reboot();
        }
        else if(strEql(bufStr, "skip"))
        {
            // It literally does nothing... (Useful at callback) 
        }
        else if(strEql(bufStr, "hi"))
        {
            print("\nHello!", 0x3F);
        }
        else if(strEql(bufStr, "files"))
        {
            newline();
            listTree();
        }
        else if(strEql(bufStr, "cat"))
        {
            print("\nFile Name>  ", 0x0F);
            readStr(bufStr, bufSize);
            ASSERT(strlength(bufStr) < MAX_FNAME_LEN);
            catFile(finddir_fs(fs_root, bufStr));
        }
        else if(strEql(bufStr,"execute"))
        {
            execute();
        }
        else if(strEql(bufStr,"switch"))
        {
            	print("\nThe specified directory was not found ", 0x0F);
        }
	else if(strEql(bufStr,"writer")) { writer(); }
	else if(strEql(bufStr, "writer -h")) { writerHelp(); }
	
	else if(strEql(bufStr, "calc")){ calc(); }
        else if(strEql(bufStr, "calc -h")){ calcHelp(); }

        else if(strEql(bufStr, "clear"))
        {
           	 clearScreen();
           	 cursorX = 0;
           	 cursorY = 0;
           	 updateCursor();
        }
        else if(strEql(bufStr, "clear -i"))
        {
            	clearScreen();
            	printIntro();
        }
        else if(strEql(bufStr, "newdir"))
        {
            	print("\nReserved", 0x0F);
        }
        else if(strEql(bufStr, "erase"))
        {
            	print("\nReserved", 0x0F);
        }
        else
        {
            	print("\nCommand Not Found ", 0x0F);
        }
        newline();
    }
}
Пример #9
0
int main(int argc, char **argv)
{
  char inFormat[25], outFormat[25], configFile[255];
  int currArg = 1, NUM_ARGS = 1, configFlag = FALSE;
  c2v_config *cfg=NULL;

  if (argc < 3) {
    usage(argv[0]);
    exit(1);
  }
    
  // Check for configuration file option first
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key, "-help", "--help", NULL)) {
      usage(argv[0]);
      char format[25], data_dictionary[512];
      CHECK_ARG(1);
      strcpy(format, GET_ARG(1));
      sprintf(data_dictionary, "%s%c%s_data_dictionary.csv", 
        get_asf_share_dir(), DIR_SEPARATOR, format);
      if (fileExists(data_dictionary)) {
        asfPrintStatus("\nFormat defined in %s_data_dictionary.csv\n\n", 
        format);
        catFile(data_dictionary);
        asfPrintStatus("\n\n");
      }
      else
        asfPrintWarning("Could not find a data dictionary for format (%s)!\n\n", 
          format);
      exit(1);
    }
    else if (strmatches(key, "-config", "--config", "-c", NULL)) {
      CHECK_ARG(1);
      strcpy(configFile, GET_ARG(1));
      cfg = read_c2v_config(configFile);
      configFlag = TRUE;
    }
  }
  if (!configFlag) {
    sprintf(configFile, "%s%cconvert2vector.config", 
      get_asf_share_dir(), DIR_SEPARATOR);
    asfPrintStatus("\nReading parameters from default configuration file:\n"
		   "%s\n", configFile);
    cfg = read_c2v_config(configFile);
  }

  // Pick up the rest of the arguments
  currArg = 1;
  NUM_ARGS = 2;
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key, "-config", "--config", "-c", NULL)) { ; }
    else if (strmatches(key, "-log", "--log", NULL)) {
      CHECK_ARG(1);
      strcpy(logFile,GET_ARG(1));
      fLog = FOPEN(logFile, "a");
      logflag = TRUE;
    }
    else if (strmatches(key, "-quiet", "--quiet", "-q", NULL))
      quietflag = TRUE;
    else if (strmatches(key, "-list", "--list", NULL))
      cfg->list = TRUE;
    else if (strmatches(key, "-nosplit", "--nosplit", "-ns", NULL))
      cfg->nosplit = TRUE;
    else if (strmatches(key, "-input-format", "--input-format", "-i", NULL)) {
      CHECK_ARG(1);
      strcpy(cfg->input_format, GET_ARG(1));
    }
    else if (strmatches(key, "-output-format", "--output-format", "-o", NULL)) {
      CHECK_ARG(1);
      strcpy(cfg->output_format, GET_ARG(1));
    }
    else {
      --currArg;
      break;
    }
  }
  if ((argc-currArg) < NUM_ARGS) {
    printf("Insufficient arguments.\n");
    usage(argv[0]);
  }

  if (!configFlag) {
    sprintf(cfg->input_file, "%s", argv[currArg++]);
    sprintf(cfg->output_file, "%s", argv[currArg]);
  }

  asfSplashScreen (argc, argv);

  sprintf(inFormat, "%s", uc(cfg->input_format));
  sprintf(outFormat, "%s", uc(cfg->output_format));
  
  // Check whether you can find information about the format in the header
  // list file in the share directory
  dbf_header_t *dbf;
  int nCols;
  char shape_type[25];
  if (strcmp_case(inFormat, "CSV") == 0 ||
    read_header_config(inFormat, &dbf, &nCols, shape_type))
    asfPrintStatus("   Converting a %s format file to %s\n", 
      inFormat, outFormat);
  else
    asfPrintError("   Unsupported input format (%s)\n", inFormat);
  
  // Set output directory as the temporary directory -- where all temp files
  // created during import should be put
  char *tmpdir = get_dirname(cfg->output_file);
  if (tmpdir && strlen(tmpdir) > 0)
    set_asf_tmp_dir(tmpdir);

  convert2vector(cfg);

  asfPrintStatus("Done.\n\n");

  return(0);
}