summary refs log blame commit diff stats
path: root/main.c
blob: fb39b914d6defb8fa919375a6286a4b336251796 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                           

                                                                                        






                                  

                    
                    
                    

               

                     
                     
                     
 
                                                             

                             
                                       

                              
                                       
                              


                                       


                                       
                        
                                                                                                             



                                 
                             
                                                                                                     






                                           
                                                 

                                   



                                                        



                                                        



                                                         



                                                              



                                    
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <err.h>

#include <gemtext.h>

#include "gemlog.h"

static void
_print_gemlog(struct gemlog_entry **list)
{
	int i;
	char timestamp[50];

	for (i = 0; list[i] != NULL; i++) {
		strftime(timestamp, sizeof(timestamp), "%F", &(list[i]->date));
		printf("%s %d: %s\n", timestamp, list[i]->date.tm_hour, list[i]->title);
	}
}

int
main(int argc, char *argv[])
{
	struct gemlog_entry **log;
	char *aflag;
	char *hflag;
	char *iflag;
	char *lflag;
	int ch;

	aflag = NULL;
	hflag = NULL;
	iflag = NULL;
	lflag = NULL;

	while ((ch = getopt(argc, argv, "a:h:i:l:")) != -1) {
		switch (ch) {
		case 'a':
			aflag = optarg;
			break;
		case 'h':
			hflag = optarg;
			break;
		case 'i':
			iflag = optarg;
			break;
		case 'l':
			lflag = optarg;
			break;
		default:
			fprintf(stderr, "Usage: %s [-a file] [-h path] [-i file] [-l file] path\n", argv[0]);
			return 1;
		}
	}

	if (optind >= argc) {
		fprintf(stderr, "Usage: %s [-a file] [-h path] [-i file] [-l file] path\n", argv[0]);
		return 1;
	}

	log = gemlog_readdir(argv[optind]);
	if (log == NULL)
		err(1, "gemlog_readdir");

	if (!aflag && !hflag && !iflag && !lflag)
		_print_gemlog(log);

	if (aflag) {
		if (gemlog_write_atom(log, aflag) == -1)
			err(1, "gemlog_write_atom");
	}
	if (hflag) {
		if (gemlog_write_html(log, hflag) == -1)
			err(1, "gemlog_write_html");
	}
	if (iflag) {
		if (gemlog_write_index(log, iflag) == -1)
			err(1, "gemlog_write_index");
	}
	if (lflag) {
		if (gemlog_write_html_index(log, lflag) == -1)
			err(1, "gemlog_write_html_index");
	}

	gemlog_entry_list_free(log);
	return 0;
}