aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: 486df78651a8542de69741c2c0800e5521356e5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <readline/readline.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>

#include "login.h"
#include "util.h"
#include "post.h"
#include "upload_file.h"

/* prints usage */

void
usage(const char *progname)
{
	printf("Usage: %s -s=status [-v=visibility] [-F=filename]\n",progname);
	return;
}

/* prints a string to stderr */


int
main(int argc, char **argv)
{
	if(access(".demiurgerc", F_OK ))
		setup();
	int c;
	char *status = NULL;
	char *visibility = NULL;
	char *id_ptr = NULL;
	if(argc == 1) {
		usage(argv[0]);
		return -1;
	}
	
	while((c = getopt(argc,argv,"s:v:F:")) != -1) {
		switch(c) {
		case 's':
			status = optarg;
			break;
		case 'v':
			visibility = optarg;
			break;
		case 'F':
			upload_file(optarg,optarg,&id_ptr);
			break;
		}
	
	}
	
	if(status == NULL) {
		eputs("Enter a status (-s)");
		return -1;
	}
	
	if(visibility == NULL) {
		visibility = "public";
	}
	
	post_status(status,visibility,id_ptr);
}