source: trunk/tools/neercs/old/actions.c @ 2183

Last change on this file since 2183 was 2183, checked in by sam, 7 years ago

build: fix the WTFPL site URL in all code comments.

  • Property svn:keywords set to Id
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://www.wtfpl.net/ for more details.
13 */
14
15#if defined HAVE_CONFIG_H
16#   include "config.h"
17#endif
18
19#include <caca.h>
20#include <errno.h>
21#include <string.h>
22#include <sys/stat.h>
23#include "neercs.h"
24
25void dump_to_file(struct screen_list *screen_list)
26{
27    char filename[14] = "hardcopy.0";
28    int n = 0;
29    struct stat bufstat;
30    void * export;
31    size_t len, wrote;
32    FILE * out;
33
34    /* FIXME maybe use glob and get next one directly */
35    while (n<9999 && !stat(filename, &bufstat))
36    {
37        n++;
38        sprintf(&filename[9], "%d", n);
39    }
40    if (n>=9999)
41    {
42        debug("Too many hardcopy files in current directory\n");
43        return;
44    }
45
46    export = caca_export_canvas_to_memory(screen_list->cv, "ansi", &len);
47    if (!export)
48    {
49        debug("Failed to export to ansi\n");
50        return;
51    }
52
53    out = fopen(filename, "w");
54    if (!out)
55    {
56        debug("Failed to open output file %s: %s\n", filename, strerror(errno));
57        return;
58    }
59    wrote = fwrite(export, len, 1, out);
60    if (!wrote)
61    {
62        debug("Failed to write to output file: %s\n", strerror(errno));
63        return;
64    }
65    free(export);
66}
Note: See TracBrowser for help on using the repository browser.