summaryrefslogtreecommitdiff
path: root/recordmydesktop/src/parseargs.c
blob: 12fb52e3e7b2dbe65f9d0ee127b07181eb76b463 (plain)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
/******************************************************************************
*                            recordMyDesktop                                  *
*******************************************************************************
*                                                                             *
*            Copyright (C) 2006,2007,2008 John Varouhakis                     *
*                                                                             *
*                                                                             *
*   This program is free software; you can redistribute it and/or modify      *
*   it under the terms of the GNU General Public License as published by      *
*   the Free Software Foundation; either version 2 of the License, or         *
*   (at your option) any later version.                                       *
*                                                                             *
*   This program is distributed in the hope that it will be useful,           *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*   GNU General Public License for more details.                              *
*                                                                             *
*   You should have received a copy of the GNU General Public License         *
*   along with this program; if not, write to the Free Software               *
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
*                                                                             *
*                                                                             *
*                                                                             *
*   For further information contact me at johnvarouhakis@gmail.com            *
******************************************************************************/


#include "recordmydesktop.h"
#include "rmd_rescue.h"


static void PrintConfig(void) {
    fprintf(stderr,"\nrecordMyDesktop was compiled with"
                   " the following options:\n\n");
#ifdef HAVE_JACK_H
    fprintf(stdout,"Jack\t\t\t:Enabled\n");
#else
    fprintf(stdout,"Jack\t\t\t:Disabled\n");
#endif
#ifdef HAVE_LIBASOUND
    fprintf(stdout,"Default Audio Backend\t:ALSA\n");
#else
    fprintf(stdout,"Default Audio Backend\t:OSS\n");
#endif
    fprintf(stderr,"\n\n");
}

boolean ParseArgs(int argc, char **argv, ProgArgs *arg_return) {
    int i;
    char *usage="\nUsage:\n"
    "\trecordmydesktop [OPTIONS]^filename\n\n\n"

    "General Options:\n"
    "\t-h or --help\t\tPrint this help and exit.\n"
    "\t--version\t\tPrint program version and exit.\n"
    "\t--print-config\t\tPrint info about options "
    "selected during compilation and exit.\n\n"

    "Image Options:\n"
    "\t-windowid id_of_window\tid of window to be recorded.\n"
    "\t-display DISPLAY\tDisplay to connect to.\n"
    "\t-x X\t\t\tOffset in x direction.\n"
    "\t-y Y\t\t\tOffset in y direction.\n"
    "\t-width N\t\tWidth of recorded window.\n"
    "\t-height N\t\tHeight of recorded window.\n\n"

    "\t-dummy-cursor color\tColor of the dummy cursor [black|white]\n"
    "\t--no-cursor\t\tDisable drawing of the cursor.\n"
    "\t--no-shared\t\tDisable usage of"
    " MIT-shared memory extension(Not Recommended!).\n"

    "\t--full-shots\t\tTake full screenshot at every frame(Not recomended!).\n"
    "\t--quick-subsampling\tDo subsampling"
    " of the chroma planes by discarding,not averaging.\n"

    "\t-fps N(number>0.0)\tA positive number denoting desired framerate.\n\n"

    "Sound Options:\n"
    "\t-channels N\t\t\tA positive number denoting"
    " desired sound channels in recording.\n"

    "\t-freq N\t\t\t\tA positive number denoting desired sound frequency.\n"
    "\t-buffer-size N\t\t\tA positive number denoting the desired"
    " sound buffer size (in frames,when using ALSA or OSS)\n"
    "\t-ring-buffer-size N\t\tA float number denoting the desired"
    " ring buffer size (in seconds,when using JACK only).\n"

    "\t-device SOUND_DEVICE\t\tSound device(default "
    DEFAULT_AUDIO_DEVICE
    ").\n"
    "\t-use-jack port1 port2... portn\tRecord audio from the specified\n"
    "\t\t\t\t\tlist of space-separated jack ports.\n"
    "\t--no-sound\t\t\tDo not record sound.\n\n"

    "Encoding Options\n"
    "\t--on-the-fly-encoding\tEncode the audio-video data, while recording.\n"
    "\t-v_quality n\t\tA number from 0 to 63 for"
    " desired encoded video quality(default 63).\n"

    "\t-v_bitrate n\t\tA number from 45000 to 2000000"
    " for desired encoded video bitrate(default 45000).\n"

    "\t-s_quality n\t\tDesired audio quality(-1 to 10).\n\n"

    "Misc Options:\n"
    "\t-rescue path_to_data\tEncode data from a previous, crashed, session.\n"
    "\t--no-wm-check\t\tDo not try to detect"
    " the window manager(and set options according to it)\n"

    "\t-pause-shortcut MOD+KEY\tShortcut that will be used for (un)pausing" 
    "(default Control+Mod1+p).\n"
    "\t-stop-shortcut MOD+KEY\tShortcut that will be used to stop the "
    "recording (default Control+Mod1+s).\n" 

    "\t--compress-cache\tImage data are cached with light compression.\n"
    "\t-workdir DIR\t\tLocation where a temporary directory"
    " will be created to hold project files(default $HOME).\n"

    "\t-delay n[H|h|M|m]\tNumber of secs(default),minutes or hours"
    " before capture starts(number can be float)\n"

    "\t--overwrite\t\tIf there is already a file with the same name,"
    " delete it\n"

    "\t\t\t\t(default is to add a number postfix to the new one).\n"
    "\t-o filename\t\tName of recorded video(default out.ogv).\n"
    "\n\tIf no other options are specified, filename can be given "
    "without the -o switch.\n\n\n";

    if(argc==2){
        if(argv[1][0]!='-'){
            free(arg_return->filename);
            arg_return->filename=malloc(strlen(argv[1])+1);
            strcpy(arg_return->filename,argv[1]);
            return TRUE;
        }
    }
    for(i=1;i<argc;i++){
        if(!strcmp(argv[i],"-delay")){
            if(i+1<argc){
                float num=atof(argv[i+1]);
                if(num>0.0){
                    int k;
                    for(k=0;k<strlen(argv[i+1]);k++){
                        if((argv[i+1][k]=='M')||(argv[i+1][k]=='m')){
                            num*=60.0;
                            break;
                        }
                        else if((argv[i+1][k]=='H')||(argv[i+1][k]=='h')){
                            num*=3600.0;
                            break;
                        }
                    }
                    arg_return->delay=(int)num;
                }
                else{
                    fprintf(stderr,"Argument Usage: -delay n[H|h|M|m]\n"
                                   "where n is a float number\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: -delay n[H|h|M|m]\n"
                               "where n is a float number\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-windowid")){
            if(i+1<argc){
                Window num=strtod(argv[i+1],NULL);
                if(num>0)
                    arg_return->windowid=num;
                else{
                    fprintf(stderr,"Argument Usage:"
                                   " -windowid id_of_window(number)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage:"
                               " -windowid id_of_window(number)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-display")){
            if(i+1<argc){
                if(arg_return->display!=NULL)
                    free(arg_return->display);
                arg_return->display=malloc(strlen(argv[i+1])+1);
                strcpy(arg_return->display,argv[i+1]);
            }
            else{
                fprintf(stderr,"Argument Usage: -display DISPLAY\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-x")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if(num>0)
                    arg_return->x=num;
                else{
                    fprintf(stderr,"Argument Usage: -x X(number>0)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: -x X(number>0)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-y")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if(num>0)
                    arg_return->y=num;
                else{
                    fprintf(stderr,"Argument Usage: -y Y(number>0)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: -y Y(number>0)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-width")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if(num>0)
                    arg_return->width=num;
                else{
                    fprintf(stderr,"Argument Usage: -width N(number>0)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: -width N(number>0)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-height")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if(num>0)
                    arg_return->height=num;
                else{
                    fprintf(stderr,"Argument Usage: -height N(number>0)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: -height N(number>0)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-o")){
            if(i+1<argc){
                free(arg_return->filename);
                arg_return->filename=malloc(strlen(argv[i+1])+1);
                strcpy(arg_return->filename,argv[i+1]);
            }
            else{
                fprintf(stderr,"Argument Usage: -o filename\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-fps")){
            if(i+1<argc){
                float num=atof(argv[i+1]);
                if(num>0.0)
                    arg_return->fps=num;
                else{
                    fprintf(stderr,"Argument Usage: -fps N(number>0)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: -fps N(number>0)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-v_quality")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if((num>=0)&&(num<64))
                    arg_return->v_quality=num;
                else{
                    fprintf(stderr,"Argument Usage:"
                                   " -v_quality n(number 0-63)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage:"
                               " -v_quality n(number 0-63)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-v_bitrate")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if((num>=45000)&&(num<=2000000))
                    arg_return->v_bitrate=num;
                else{
                    fprintf(stderr,"Argument Usage:"
                                   " -v_bitrate n(number 45000-2000000)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage:"
                               " -v_bitrate n(number 45000-2000000)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-dummy-cursor")){
            if(i+1<argc){
                if(!strcmp(argv[i+1],"white"))
                    arg_return->cursor_color=0;
                else if(!strcmp(argv[i+1],"black"))
                    arg_return->cursor_color=1;
                else{
                    fprintf(stderr,"Argument Usage:"
                                   " -dummy-cursor [black|white]\n");
                    return FALSE;
                }
                arg_return->have_dummy_cursor=1;
                arg_return->xfixes_cursor=0;
            }
            else{
                fprintf(stderr,"Argument Usage:"
                               " -dummy-cursor [black|white]\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"--no-cursor"))
            arg_return->xfixes_cursor=0;
        else if(!strcmp(argv[i],"-freq")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if(num>0)
                    arg_return->frequency=num;
                else{
                    fprintf(stderr,"Argument Usage: -freq N(number>0)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: -freq N(number>0)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-channels")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if(num>0)
                    arg_return->channels=num;
                else{
                    fprintf(stderr,"Argument Usage: -channels N(number>0)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: -channels N(number>0)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-s_quality")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if((num>=-1)&&(num<=10))
                    arg_return->s_quality=num;
                else{
                    fprintf(stderr,"Argument Usage:"
                                   " -s_quality n(number -1 to 10)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage:"
                               " -s_quality n(number -1 to 10)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-device")){
            if(i+1<argc){
                free(arg_return->device);
                arg_return->device=malloc(strlen(argv[i+1])+1);
                strcpy(arg_return->device,argv[i+1]);
            }
            else{
                fprintf(stderr,"Argument Usage: -device SOUND_DEVICE\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-workdir")){
            if(i+1<argc){
                free(arg_return->workdir);
                arg_return->workdir=malloc(strlen(argv[i+1])+1);
                strcpy(arg_return->workdir,argv[i+1]);
            }
            else{
                fprintf(stderr,"Argument Usage: -workdir DIR\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-pause-shortcut")){
            if(i+1<argc){
                free(arg_return->pause_shortcut);
                arg_return->pause_shortcut=malloc(strlen(argv[i+1])+1);
                strcpy(arg_return->pause_shortcut,argv[i+1]);
            }
            else{
                fprintf(stderr,"Argument Usage: -pause-shortcut MOD+KEY\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-stop-shortcut")){
            if(i+1<argc){
                free(arg_return->stop_shortcut);
                arg_return->stop_shortcut=malloc(strlen(argv[i+1])+1);
                strcpy(arg_return->stop_shortcut,argv[i+1]);
            }
            else{
                fprintf(stderr,"Argument Usage: -stop-shortcut MOD+KEY\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-buffer-size")){
            if(i+1<argc){
                int num=atoi(argv[i+1]);
                if(num>0)
                    arg_return->buffsize=num;
                else{
                    fprintf(stderr,"Argument Usage:"
                                   " -buffer-size N(number>0)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: -buffer-size N(number>0)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-use-jack")){
            if(i+1<argc){
#ifdef HAVE_JACK_H
                int k=i+1;
                arg_return->jack_nports=0;
                while((k<argc)&&(argv[k][0]!='-')){
                    arg_return->jack_nports++;
                    k++;
                }
                if(arg_return->jack_nports>0){
                    arg_return->jack_port_names=malloc(sizeof(char*)*
                                                       arg_return->jack_nports);
                    for(k=i+1;k<i+1+arg_return->jack_nports;k++){
                        arg_return->jack_port_names[k-i-1]=
                            malloc(strlen(argv[k])+1);
                        strcpy(arg_return->jack_port_names[k-i-1],
                               argv[k]);
                    }
                    i+=arg_return->jack_nports;
                    arg_return->use_jack=1;
                }
                else{
                    fprintf(stderr,"Argument Usage: -use-jack port1"
                                   " port2... portn\n");
                    return FALSE;
                }
#else
                fprintf(stderr,"recordMyDesktop is not compiled"
                               " with Jack support!\n");
                return FALSE;
#endif
            }
            else{
                fprintf(stderr,"Argument Usage: -use-jack port1"
                               " port2... portn\n");
                return FALSE;
            }
        }
        else if(!strcmp(argv[i],"-ring-buffer-size")){
            if(i+1<argc){
                float num=atof(argv[i+1]);
                if(num>0.0)
                    arg_return->jack_ringbuffer_secs=num;
                else{
                    fprintf(stderr,"Argument Usage: --ring-buffer-size"
                                   " N(floating point number>0.0)\n");
                    return FALSE;
                }
            }
            else{
                fprintf(stderr,"Argument Usage: --ring-buffer-size"
                                " N(floating point number>0.0)\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"-rescue")){
            if(i+1<argc){
                int ex_st=rmdRescue(argv[i+1]);
                exit(ex_st);
            }
            else{
                fprintf(stderr,"Argument Usage: -rescue path_to_data\n");
                return FALSE;
            }
            i++;
        }
        else if(!strcmp(argv[i],"--no-sound"))
            arg_return->nosound=1;
        else if(!strcmp(argv[i],"--no-shared")){
            arg_return->noshared=1;
        }
        else if(!strcmp(argv[i],"--full-shots")){
            arg_return->full_shots=1;
        }
        else if(!strcmp(argv[i],"--no-frame")){
            arg_return->noframe=1;
        }
        else if(!strcmp(argv[i],"--follow-mouse")){
            arg_return->full_shots=1;
            arg_return->follow_mouse=1;
        }
        else if(!strcmp(argv[i],"--no-encode"))
            arg_return->no_encode=1;
        else if(!strcmp(argv[i],"--quick-subsampling")){
            arg_return->no_quick_subsample=0;
        }
        else if(!strcmp(argv[i],"--on-the-fly-encoding")){
            arg_return->encOnTheFly=1;
        }
        else if(!strcmp(argv[i],"--overwrite"))
            arg_return->overwrite=1;
        else if(!strcmp(argv[i],"--no-wm-check"))
            arg_return->nowmcheck=1;
        else if(!strcmp(argv[i],"--compress-cache")){
            arg_return->zerocompression=0;
        }
        else if(!strcmp(argv[i],"--help")||!strcmp(argv[i],"-h")){
            fprintf(stderr,"%s",usage);
            exit(0);
        }
        else if(!strcmp(argv[i],"--version")){
            fprintf(stderr,"recordMyDesktop v%s\n\n",VERSION);
            exit(0);
        }
        else if(!strcmp(argv[i],"--print-config")){
            PrintConfig();
            exit(0);
        }
        else{
            fprintf(stderr,"\n\tError parsing arguments.\n\t"
                           "Type --help or -h for usage.\n\n");
            return FALSE;
        }
    }
    
    return TRUE;
}
© All Rights Reserved