Пример #1
0
void fill_with_string(void)
{
  char *msg = hexOrAscii ? "Hexa string to fill with: " : "Ascii string to fill with: ";
  char **last = hexOrAscii ? &lastFillWithStringHexa : &lastFillWithStringAscii;
  char tmp2[BLOCK_SEARCH_SIZE];
  unsigned char *tmp1;
  size_t i, l1, l2;

  if (!mark_set) return;
  if (isReadOnly) { displayMessageAndWaitForKey("File is read-only!"); return; }
  if (sizeCopyBuffer > BIGGEST_COPYING) {
    displayTwoLineMessage("Hey, don't you think that's too big?!", "Really fill (Yes/No)");
    if (tolower(getch()) != 'y') return;
  }
  if (!displayMessageAndGetString(msg, last, tmp2, sizeof(tmp2))) return;
  l1 = mark_max - mark_min + 1;
  l2 = strlen(tmp2);
  if (hexOrAscii) {
    if (l2 == 1) {
      if (!isxdigit(*tmp2)) { displayMessageAndWaitForKey("Invalid hexa string"); return; }
      *tmp2 = hexCharToInt(*tmp2);
    } else if (!hexStringToBinString(tmp2, &l2)) return;
  }
  tmp1 = malloc(l1);
  if(!tmp1) return;
  for (i = 0; i < l1 - l2 + 1; i += l2) memcpy(tmp1 + i, tmp2, l2);
  memcpy(tmp1 + i, tmp2, l1 - i);
  addToEdited(mark_min, l1, tmp1);
  readFile();
  free(tmp1);
}
Пример #2
0
int findFile(void)
{
  char *p, tmp[BLOCK_SEARCH_SIZE];
  p = lastFindFile ? strdup(lastFindFile) : NULL;
  if (!displayMessageAndGetString("File name: ", &p, tmp, sizeof(tmp))) return FALSE;
  if (!is_file(tmp)) return FALSE;
  FREE(lastFindFile); lastFindFile = fileName;
  fileName = p;
  return TRUE;
}
Пример #3
0
static int searchA(char **string, int *sizea, char *tmp, int tmp_size)
{
  char *msg = hexOrAscii ? "Hexa string to search: " : "Ascii string to search: ";
  char **last = hexOrAscii ? &lastAskHexString : &lastAskAsciiString;

  if (!ask_about_save_and_redisplay()) return FALSE;
  if (!displayMessageAndGetString(msg, last, tmp, tmp_size)) return FALSE;

  *sizea = strlen(tmp);
  if (hexOrAscii) if (!hexStringToBinString(tmp, sizea)) return FALSE;

  *string = malloc(*sizea);
  memcpy(*string, tmp, *sizea);

  nodelay(stdscr, TRUE);
  displayTwoLineMessage("searching...", "(press any key to cancel)");
  return TRUE;
}
Пример #4
0
void yank_to_a_file(void)
{
  char tmp[BLOCK_SEARCH_SIZE];
  int f;

  if (copyBuffer == NULL) { displayMessageAndWaitForKey("Nothing to paste"); return; }

  if (!displayMessageAndGetString("File name: ", &lastYankToAFile, tmp, sizeof(tmp))) return;

  if ((f = open(tmp, O_RDONLY)) != -1) {
    close(f);
    displayTwoLineMessage("File exists", "Overwrite it (Yes/No)");
    if (tolower(getch()) != 'y') return;
  }
  if ((f = creat(tmp, 0666)) == -1 || write(f, copyBuffer, sizeCopyBuffer) == -1) {
    displayMessageAndWaitForKey(strerror(errno));
  }

  if (f != -1) close(f);
}