Changeset 1246 for cacamoo


Ignore:
Timestamp:
Oct 27, 2006, 9:30:36 PM (13 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Added --list-files option, unicode option (not working yet)
Location:
cacamoo/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cacamoo/trunk/src/cacamoo.h

    r1244 r1246  
    1818#include <string.h>
    1919#include <stdlib.h>
     20/* Portability ? */
     21#include <sys/types.h>
     22#include <dirent.h>
     23
     24
    2025#include <cucul.h>
    21 
    2226
    2327static void version(void);
     
    2832char *remove_slashes(char *str);
    2933char *remove_comments(char *str);
     34void list_files(const char *directory);
    3035
    3136#if defined(HAVE_GETOPT_H)
  • cacamoo/trunk/src/main.c

    r1244 r1246  
    5959/* Think ? */
    6060unsigned char think = 0;
     61
     62/* Unicode */
     63unsigned char unicode = 0;
    6164
    6265
     
    103106                { "wired", 1, NULL, 'w' },
    104107                { "think", 1, NULL, 'O' },
     108                { "unicode", 1, NULL, 'u' },
    105109                { "version", 0, NULL, 'v' },
     110                { "list-files", 0, NULL, 'l' },
    106111                { "help", 0, NULL, 'h' },
    107112                { NULL, 0, NULL, 0 }
     
    110115
    111116
    112         int c = getopt_long(argc, argv, "D:f:W:e:T:hvObtdgpsywn",
     117        int c = getopt_long(argc, argv, "D:f:W:e:T:hvObtdgpsylwnu",
    113118                            long_options, &option_index);
    114119#   else
    115120#       define MOREINFO "Try `%s -h' for more information.\n"
    116         int c = getopt(argc, argv, "D:f:W:hvObtdgpsywn");
     121        int c = getopt(argc, argv, "D:f:W:hvObtdgpsylwnu");
    117122#   endif
    118123        if(c == -1)
     
    170175            if(term_width && (term_width != 1)) term_width--;
    171176            break;
    172         case 'n': /* --width */
     177        case 'l': /* --list-files */
     178            list_files(".");
     179            list_files(cacamoo_dir);
     180            return 0;
     181            break;
     182        case 'u': /* --unicode */
     183            unicode = 1;
     184            break;
     185        case 'n': /* --no-wrap */
    173186            no_wrap = 1;
    174187            break;
     
    240253    /* Import our buffer as an ansi (color) one */
    241254    input_buffer = cucul_load_memory(buffer, buffer_size);
    242     canvas = cucul_import_canvas (input_buffer, "ansi");
     255    if(input_buffer == NULL)
     256    {
     257        printf("Can't load file in libcucul !\n");
     258        return -1;
     259    }
     260    canvas = cucul_import_canvas (input_buffer, unicode?"utf8":"ansi");
     261    if(canvas == NULL)
     262    {
     263        printf("Can't load file in libcucul !\n");
     264        return -1;
     265    }
    243266    /* Export given canvas to format we want */
    244267    output_buffer = cucul_export_canvas(canvas, "irc");
     268    if(output_buffer == NULL)
     269    {
     270        printf("Can't export file to text !\n");
     271        return -1;
     272    }
    245273
    246274    buf_size = cucul_get_buffer_size(output_buffer);
     
    258286}
    259287
     288
     289void list_files(const char *directory)
     290{
     291    struct dirent * dp;
     292    int count = 0;
     293    DIR *dir = opendir(directory);
     294
     295
     296    for (dp = readdir(dir); dp != NULL; dp = readdir(dir))
     297    {
     298        if(!strncmp(&dp->d_name[strlen(dp->d_name)-4], ".cow", 4))
     299        {
     300            char name[256];
     301            memcpy(name, dp->d_name, strlen(dp->d_name)-4);
     302            name[strlen(dp->d_name)-4] = 0;
     303            printf("%s ", name);
     304            count++;
     305            if(!(count%6))
     306                printf("\n");
     307        }
     308    }
     309    closedir(dir);
     310    if(count)
     311        printf("\n");
     312    return;
     313}
    260314
    261315char * make_caca_from_file(unsigned int *size)
Note: See TracChangeset for help on using the changeset viewer.