File: wmf.c

package info (click to toggle)
wmf 1.0.5-7
  • links: PTS
  • area: main
  • in suites: buster, sid, stretch
  • size: 412 kB
  • ctags: 337
  • sloc: ansic: 5,405; makefile: 53; sh: 19
file content (163 lines) | stat: -rw-r--r-- 5,208 bytes parent folder | download | duplicates (4)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*************************************************************
 * WebMailFolder                                             *
 * COPYRIGHT 1998 by Norbert Kuemin <norbert.kuemin@gmx.net> *
 *************************************************************/
   
#define MAIN_FILE
#include "wmf.h"

void ShowUsage(int level) {
    printf("  usage: %s [option]\n\n",config.ProgramName);
    if (level>0) {
	printf("    -?        show this help text\n");
	printf("    -a url    about hyperlink\n");
	printf("    -c file   specify configuration file\n");
	printf("    -d dir    directory\n");
	printf("    -e cmd    mail command\n");
	printf("    -f mode   same as umask for creating new files\n");
	printf("    -h        show this help text\n");
	printf("    -l days   day limit\n");
	printf("    -m mbox   mbox file (- for stdin)\n");
	printf("    -n name   name of the mailinglist\n");
	printf("    -p x      lines / page index\n");
	printf("    -r        reverse sorting (Newest first)\n");
	printf("    -t level  threading level limitation\n");
	printf("    -v        print the programname and the version\n");
	printf("    -w x      write-mode (0=index 1=overwrite 2=append 3=append+noindex)\n");
	printf("    -x x      debug level\n");
    }
}

void Cleanup() {

    /* Deallocate memory */
    if (config.DebugLevel & 1)
        printf(".cleanup\n");

    /* Free LastFileName and close open files */ 
    AppendFile("","");

    /* Throw Html commands away */
    EndHtmlCmd();

    /* Destroy configuration */
    DestroyConfig();
}


int main (int argc, char **argv) {

    extern char *optarg;
    char opt;
    int i;
            
    /* Initial */
    config.ProgramName = argv[0];
    InitConfig();
#ifdef DEBUG
    Debug.StrAlloc = 0;
    Debug.StrDeAlloc = 0;
#endif

    while ((opt = getopt(argc, argv, "?hvra:c:d:e:f:l:m:n:p:t:w:x:")) != '\xFF') {
        switch (opt) {
	    case '?': /* help information */
	    case 'h':
	        ShowUsage(1);
	        exit(0);
	        break;
	    case 'v': /* show current version */
	        printf("%s version %s\n",NAME,VERSION);
	        exit(0);
	        break;
	    case 'w': /* write-mode */
		config.WriteMode = atoi(optarg);
	        break;
	    case 't': /* thread level limit */
		config.ThreadLevelLimit = atoi(optarg);
	        break;
	    case 'l': /* list limit */
		config.ListLimit = time(NULL) - atoi(optarg) * 24 * 60 * 60;
	        break;
	    case 'p': /* page size */
		config.PageSize = atoi(optarg);
	        break;
	    case 'f': /* permissions for new files */
		for(i=0;i<(strlen(optarg));i++) {
		    config.NewFilePerm = config.NewFilePerm*8+optarg[i]-48;
		}
	        break;
	    case 'x': /* debug level */
		config.DebugLevel = atoi(optarg);
	        break;
	    case 'r': /* sort reverse */
		config.SortOrder = SORT_REVERSE;
	        break;
	    case 'c': /* another config-file */
                if (config.ConfigFile != NULL) {
                    freechar(config.ConfigFile);
                }
                config.ConfigFile = newchar(strlen(optarg)+1);
                strncpy(config.ConfigFile,optarg,strlen(optarg)+1);
	        break;
	    case 'd': /* directory */
                if (config.Directory != NULL) {
                    freechar(config.Directory);
                }
                config.Directory = newchar(strlen(optarg)+1);
                strncpy(config.Directory,optarg,strlen(optarg)+1);
	        break;
	    case 'n': /* name */
                if (config.Name != NULL) {
                    freechar(config.Name);
                }
                config.Name = newchar(strlen(optarg)+1);
                strncpy(config.Name,optarg,strlen(optarg)+1);
	        break;
	    case 'm': /* mailbox file */
                if (config.MailBoxFile != NULL) {
                    freechar(config.MailBoxFile);
                }
                config.MailBoxFile = newchar(strlen(optarg)+1);
                strncpy(config.MailBoxFile,optarg,strlen(optarg)+1);
	        break;
	    case 'e': /* mail command */
                if (config.MailCommand != NULL) {
                    freechar(config.MailCommand);
                }
                config.MailCommand = newchar(strlen(optarg)+1);
                strncpy(config.MailCommand,optarg,strlen(optarg)+1);
	        break;
	    case 'a': /* about link url */
                if (config.AboutLink != NULL) {
                    freechar(config.AboutLink);
                }
                config.AboutLink = dupchar(optarg);
	        break;
	    default:
		ShowUsage(0);
	        exit(1);
	        break;
        }
    }
    
    ReadConfig();
    if (config.Directory != NULL) {
	if (config.Directory[strlen(config.Directory)-1] == '/')
	    config.Directory[strlen(config.Directory)-1] = '\0';
	if (!FileExist(config.Directory)) {
	    fprintf(stderr,"Error: directory %s doesn't exist or isn't readable.\n",config.Directory);
	    exit(1);
	}
    }
    if (config.MailBoxFile != NULL) Mail2Html(config.MailBoxFile);
    if (config.WriteMode != HTML_APPENDNOINDEX) CreateIndex();

    Cleanup();

#ifdef DEBUG
    printf("Allocated strings:%d\n",Debug.StrAlloc);
    printf("Deallocated strings:%d\n",Debug.StrDeAlloc);
#endif
    return 0;
}