source: neercs/trunk/src/actions.c @ 4640

Last change on this file since 4640 was 4640, checked in by pterjan, 4 years ago
  • Fix build in debug mode /o\
  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1/*
2 *  neercs        console-based window manager
3 *  Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
4 *                2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org>
5 *                2008-2010 Pascal Terjan <pterjan@linuxfr.org>
6 *                All Rights Reserved
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16#include <caca.h>
17#include <errno.h>
18#include <string.h>
19#include <sys/stat.h>
20#include "neercs.h"
21
22void dump_to_file(struct screen_list *screen_list)
23{
24    char filename[14] = "hardcopy.0";
25    int n = 0;
26    struct stat bufstat;
27    void * export;
28    size_t len, wrote;
29    FILE * out;
30
31    /* FIXME maybe use glob and get next one directly */
32    while (n<9999 && !stat(filename, &bufstat))
33    {
34        n++;
35        sprintf(&filename[9], "%d", n);
36    }
37    if (n>=9999)
38    {
39        debug("Too many hardcopy files in current directory\n");
40        return;
41    }
42
43    export = caca_export_canvas_to_memory(screen_list->cv, "ansi", &len);
44    if (!export)
45    {
46        debug("Failed to export to ansi\n");
47        return;
48    }
49
50    out = fopen(filename, "w");
51    if (!out)
52    {
53        debug("Failed to open output file %s: %s\n", filename, strerror(errno));
54        return;
55    }
56    wrote = fwrite(export, len, 1, out);
57    if (!wrote)
58    {
59        debug("Failed to write to output file: %s\n", strerror(errno));
60        return;
61    }
62    free(export);
63}
Note: See TracBrowser for help on using the repository browser.