Пример #1
0
void delete_directories(struct node *root){
  unsigned int i;
  if (get_cache(root)->directory){
    delete_directory(get_cache(root)->dir);
  }
  for (i=0; i<root->nb_children; i++){
    delete_directories(get_child(root, i));
  }
}
Пример #2
0
// An interesting thing with the CleanUp functions of each interpreter
// (i.e. interpreter1, 2, 3), is that each of them gets called by
// the destructor of that class. I don't understand why that happens.
// I would expect that, since the CleanUp functions are all virtual,
// only the CleanUp function of the lowest subclass (interpreter3
// currently) should be called. I don't know if the way things work 
// now is according to the C++ standard or if it is a Virtual Studio bug.
vint8 class_interpreter::clean_up()
{
  vEraseCharpVector(&module_names);
  vDeletePrecomputedValues();

  if (input_file_pointer != 0)
  {
    fclose(input_file_pointer);
  }

  delete_directories();  
  return 1;
}
Пример #3
0
/**
 * Main entry for program.
 *
 * @param argc Number of command line arguments
 * @param argv Command line arguments
 * @return 0 on success
 */
int
main (int argc, char* argv[])
{
  char *option;
  int result;
  char *sparam1=NULL, *sparam2, *sparam3, *sparam4;
  char *sparam5, *sparam6, *sparam7, *sparam8, *sparam9;
#ifdef _WIN32
  char path[MAX_PATH];
#endif
  int iparam1, iparam2;
  long lparam1;

  /****************************************************************************
   * Show program help
  ****************************************************************************/
  if (get_option (argv, argc, "--help", NULL) == 0)
    {
      usage (stdout);
      exit (0);
    }
  /****************************************************************************
   * Read command line options from file
  ****************************************************************************/
  if (get_option (argv, argc, "-file", &option) == 0)
    {
      result = read_file_options (option);
      free (option);
      if (result == -1)
        fail ("Failed to read options file: %s.", option);
    }
  /****************************************************************************
   * Enable logging
  ****************************************************************************/
  if (get_option (argv, argc, "-log", &option) == 0)
    {
      logFile = fopen (option, "a");
      if (logFile == NULL)
        fail ("Failed to write log file: %s", option);
      free (option);
    }
  /****************************************************************************
   * Wait for process to terminate
  ****************************************************************************/
  if (get_option (argv, argc, "-pid", &option) == 0)
    {
      iparam1 = -1;
      lparam1 = atoi (option);
      free (option);
      if (get_option (argv, argc, "-wait", &option) == 0)
        {
          iparam1 = atoi (option);
        }
      if (wait_for_pid (lparam1, iparam1) != 0)
        fail ("Timed out waiting for process to terminate.");
      free (option);
    }
  /****************************************************************************
   * Remove directories
  ****************************************************************************/
  if (get_option (argv, argc, "-removeDir", &option) == 0)
    {
      result = delete_directories (option, 0);
      if (result != 0)
        fail ("Failed to delete directories: %s", option);
      else
        log_message ("-removeDir %s", option);
      free (option);
    }
  /****************************************************************************
   * Remove directories if they are empty
  ****************************************************************************/
  if (get_option (argv, argc, "-removeEmptyDir", &option) == 0)
    {
      result = delete_directories (option, 1);
      if (result != 0)
        fail ("Failed to delete empty directories: %s", option);
      else
        log_message ("-removeEmptyDir %s", option);
      free (option);
    }
  /****************************************************************************
   * Set registry value
  ****************************************************************************/
  if (get_option (argv, argc, "-regSetValue", &option) == 0)
    {
#ifdef _WIN32
      sparam1 = get_argument (option);
      sparam2 = get_argument (NULL);
      sparam3 = get_argument (NULL);
      sparam4 = get_argument (NULL);
      result = set_registry_value (sparam1, sparam2, sparam3, sparam4);
      if (result != 0)
        fail ("Failed to set registry value.");
      else
        log_message ("-regSetValue %s, %s, %s, %s", sparam1, sparam2,
          sparam3, sparam4);
      free (option);
#else
      fail ("-regSetValue is only supported on Windows.");
#endif
    }
  /****************************************************************************
   * Get registry value
  ****************************************************************************/
  if (get_option (argv, argc, "-regGetValue", &option) == 0)
    {
#ifdef _WIN32
      sparam1 = get_argument (option);
      sparam2 = get_argument (NULL);
      sparam3 = get_registry_value (sparam1, sparam2);
      if (sparam3)
        puts (sparam3);
      else
        fail ("Failed to get registry value %s, %s.", sparam1, sparam2);
      free (option);
#else
      fail ("-regSetValue is only supported on Windows.");
#endif
    }
  /****************************************************************************
   * Delete registry value
  ****************************************************************************/
  if (get_option (argv, argc, "-regDeleteValue", &option) == 0)
    {
#ifdef _WIN32
      sparam1 = get_argument (option);
      sparam2 = get_argument (NULL);
      result = delete_registry_value (sparam1, sparam2);
      if (result != 0)
        fail ("Failed to delete registry value.");
      else
        log_message ("-regDeleteValue %s, %s", sparam1, sparam2);
      free (option);
#else
      fail ("-regDeleteValue is only supported on Windows.");
#endif
    }
  /****************************************************************************
   * Delete registry key
  ****************************************************************************/
  if (get_option (argv, argc, "-regDeleteKey", &option) == 0)
    {
#ifdef _WIN32
      result = delete_registry_key (option);
      if (result != 0)
        fail ("Failed to delete registry key.");
      else
        log_message ("-regDeleteKey %s", option);
      free (option);
#else
      fail ("-regDeleteKey is only supported on Windows.");
#endif
    }
  /****************************************************************************
   * Run as administrator
  ****************************************************************************/
  if (get_option (argv, argc, "-runAdmin", &option) == 0)
    {
#ifdef _WIN32
      sparam1 = get_argument (option);
      sparam2 = get_argument (NULL);

      result = -1;
      if ((sparam1 != NULL) && (sparam2 != NULL))
      {
        replace_chars (sparam2, '\'', '"');
        result = run_admin (sparam1, sparam2);
      }
      if (result != 0)
        fail ("Failed to run program.");
      else
        log_message ("-runAdmin %s,%s", sparam1, sparam2);
      free (option);
#else
      fail ("-runAdmin is currently only supported on Windows.");
#endif
    }
  /****************************************************************************
   * Create short-cut
  ****************************************************************************/
  if (get_option (argv, argc, "-createShortcut", &option) == 0)
    {
      sparam1 = get_argument (option);
      sparam2 = get_argument (NULL);
      sparam3 = get_argument (NULL);
      sparam4 = get_argument (NULL);
      sparam5 = get_argument (NULL);
      sparam6 = get_argument (NULL);
      sparam7 = get_argument (NULL);
      sparam8 = get_argument (NULL);
      sparam9 = get_argument (NULL);
      if (strlen (sparam6) != 0)
        iparam1 = atoi (sparam6);
      else
        iparam1 = 0;
      if (strlen (sparam9) != 0)
        iparam2 = atoi (sparam9);
      else
        iparam2 = 0;
      result = create_shortcut (sparam1, sparam2, sparam3, sparam4, sparam5,
        iparam1, sparam7, sparam8, iparam2);
      if (result != 0)
        fail ("Failed to create shortcut.");
      else
        log_message ("-createShortcut %s, %s, %s, %s, %s, %s, %s, %s %s",
          sparam1, sparam2, sparam3, sparam4, sparam5, sparam6, sparam7,
          sparam8, sparam9);
      free (option);
    }
  /****************************************************************************
   * Get special folder
  ****************************************************************************/
  if (get_option (argv, argc, "-getSpecialFolder", &option) == 0)
    {
#ifdef _WIN32
      sparam1 = get_argument (option);
      iparam1 = get_clsid (sparam1);
      result = get_special_folder (iparam1, path);
      free (option);
      if (result != 0)
        fail ("Failed to get special folder: %s", sparam1);
      else
        puts(path);
#else
      fail ("-getSpecialFolder is only supported on Windows.");
#endif
    }
  /****************************************************************************
   * Get property
  ****************************************************************************/
  if (get_option (argv, argc, "-getOsProperty", &option) == 0)
    {
      sparam1 = get_argument (option);
      print_os_property (sparam1);
      free (option);
    }

  if (logFile != NULL)
    fclose (logFile);
  if (fargv != NULL)
    free (fargv);

  return EXIT_SUCCESS;
}