<commit_before>/** 
 * \file delfile.c
 * Example program to delete a file off the device.
 *
 * Copyright (C) 2005-2008 <NAME> <<EMAIL>>
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include <stdlib.h>
#include <limits.h>

#include "common.h"
#include "string.h"
#include "pathutils.h"
#include "connect.h"

extern LIBMTP_mtpdevice_t *device;
extern LIBMTP_folder_t *folders;
extern LIBMTP_file_t *files;

void delfile_usage(void)
{
  printf("Usage: delfile [-n] <fileid/trackid> | -f <filename>\n");
}

int
delfile_function(char * path)
{
  uint32_t id = parse_path (path,files,folders);

  if (id > 0) {
    printf("Deleting %s which has item_id:%d\n",path,id);
    int ret = 1;
    ret = LIBMTP_Delete_Object(device, id);
    if (ret != 0) {
      LIBMTP_Dump_Errorstack(device);
      LIBMTP_Clear_Errorstack(device);
      printf("Failed to remove file\n");
      return 1;
    }
  }
  return 0;
}

int delfile_command(int argc, char **argv)
{
  int FILENAME = 1;
  int ITEMID = 2;
  int field_type = 0;
  int i;
  int ret = 0;

  if ( argc > 2 ) {
    if (strncmp(argv[1],"-f",2) == 0) {
      field_type = FILENAME;
      strcpy(argv[1],"");
    } else if (strncmp(argv[1],"-n",2) == 0) {
      field_type = ITEMID;
      strcpy(argv[1],"0");
    } else {
      delfile_usage();
      return 0;
    }
  } else {
    delfile_usage();
    return 0;
  }

  for (i=1;i<argc;i++) {
    uint32_t id;
    char *endptr;

    if (field_type == ITEMID) {
      // Sanity check song ID
      id = strtoul(argv[i], &endptr, 10);
      if ( *endptr != 0 ) {
        fprintf(stderr, "illegal value %s .. skipping\n", argv[i]);
        id = 0;
      }
    } else {
      if (strlen(argv[i]) > 0) {
        id = parse_path (argv[i],files,folders);
      } else {
        id = 0;
      }
    }
    if (id > 0 ) {
      printf("Deleting %s\n",argv[i]);
      ret = LIBMTP_Delete_Object(device, id);
    }
    if ( ret != 0 ) {
      printf("Failed to delete file:%s\n",argv[i]);
      LIBMTP_Dump_Errorstack(device);
      LIBMTP_Clear_Errorstack(device);
      ret = 1;
    }
  }
  return ret;
}

<commit_msg>fixed usage text for 'mtp-delfile' according to implementation<commit_after>/** 
 * \file delfile.c
 * Example program to delete a file off the device.
 *
 * Copyright (C) 2005-2008 <NAME>ij <<EMAIL>>
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include <stdlib.h>
#include <limits.h>

#include "common.h"
#include "string.h"
#include "pathutils.h"
#include "connect.h"

extern LIBMTP_mtpdevice_t *device;
extern LIBMTP_folder_t *folders;
extern LIBMTP_file_t *files;

void delfile_usage(void)
{
  printf("Usage: delfile -n <fileid/trackid> | -f <filename> ...\n");
}

int
delfile_function(char * path)
{
  uint32_t id = parse_path (path,files,folders);

  if (id > 0) {
    printf("Deleting %s which has item_id:%d\n",path,id);
    int ret = 1;
    ret = LIBMTP_Delete_Object(device, id);
    if (ret != 0) {
      LIBMTP_Dump_Errorstack(device);
      LIBMTP_Clear_Errorstack(device);
      printf("Failed to remove file\n");
      return 1;
    }
  }
  return 0;
}

int delfile_command(int argc, char **argv)
{
  int FILENAME = 1;
  int ITEMID = 2;
  int field_type = 0;
  int i;
  int ret = 0;

  if ( argc > 2 ) {
    if (strncmp(argv[1],"-f",2) == 0) {
      field_type = FILENAME;
      strcpy(argv[1],"");
    } else if (strncmp(argv[1],"-n",2) == 0) {
      field_type = ITEMID;
      strcpy(argv[1],"0");
    } else {
      delfile_usage();
      return 0;
    }
  } else {
    delfile_usage();
    return 0;
  }

  for (i=1;i<argc;i++) {
    uint32_t id;
    char *endptr;

    if (field_type == ITEMID) {
      // Sanity check song ID
      id = strtoul(argv[i], &endptr, 10);
      if ( *endptr != 0 ) {
        fprintf(stderr, "illegal value %s .. skipping\n", argv[i]);
        id = 0;
      }
    } else {
      if (strlen(argv[i]) > 0) {
        id = parse_path (argv[i],files,folders);
      } else {
        id = 0;
      }
    }
    if (id > 0 ) {
      printf("Deleting %s\n",argv[i]);
      ret = LIBMTP_Delete_Object(device, id);
    }
    if ( ret != 0 ) {
      printf("Failed to delete file:%s\n",argv[i]);
      LIBMTP_Dump_Errorstack(device);
      LIBMTP_Clear_Errorstack(device);
      ret = 1;
    }
  }
  return ret;
}


{'fraction_non_alphanumeric': 0.13296108881521548, 'fraction_numerical': 0.021636712615599372, 'mean_word_length': 2.8035832780358327, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6466769', 'n_tokens_mistral': 2163, 'n_tokens_neox': 2001, 'n_words': 614}