Fix some greedy sed changes in imported code. Also provide a sys/types.h for compatib...
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / s_main.c
blobb77f804e9f87519f2dff3de6cde902deca50fec7
1 /* Copyright (c) 1997-1999 Miller Puckette and others.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
5 /* IOhannes :
6 * hacked the code to add advanced multidevice-support
7 * 1311:forum::für::umläute:2001
8 */
10 char pd_version[] = "Pd version 0.37.4\n";
11 char pd_compiletime[] = __TIME__;
12 char pd_compiledate[] = __DATE__;
14 #include "m_pd.h"
15 #include "m_imp.h"
16 #include "s_stuff.h"
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <limits.h>
20 #include <string.h>
21 #include <stdio.h>
22 #include <fcntl.h>
23 #include <stdlib.h>
25 #ifdef UNIX
26 #include <unistd.h>
27 #endif
28 #ifdef MSW
29 #include <io.h>
30 #include <windows.h>
31 #include <winbase.h>
32 #endif
34 void pd_init(void);
35 int sys_argparse(int argc, char **argv);
36 void sys_findprogdir(char *progname);
37 int sys_startgui(const char *guipath);
38 int sys_rcfile(void);
39 int m_scheduler(void);
40 void sys_addhelppath(char *p);
41 void alsa_adddev(char *name);
43 int sys_debuglevel;
44 int sys_verbose;
45 int sys_noloadbang;
46 int sys_nogui;
47 int sys_stdin = 0;
48 char *sys_guicmd;
49 t_symbol *sys_libdir;
50 static t_symbol *sys_guidir;
51 static t_namelist *sys_externlist;
52 static t_namelist *sys_openlist;
53 static t_namelist *sys_messagelist;
54 static int sys_version;
55 int sys_oldtclversion; /* hack to warn g_rtext.c about old text sel */
57 int sys_nmidiout = 1;
58 #ifdef MSW
59 int sys_nmidiin = 0;
60 #else
61 int sys_nmidiin = 1;
62 #endif
63 int sys_midiindevlist[MAXMIDIINDEV] = {1};
64 int sys_midioutdevlist[MAXMIDIOUTDEV] = {1};
66 static int sys_main_srate = DEFAULTSRATE;
67 static int sys_main_advance = DEFAULTADVANCE;
69 /* IOhannes { */
71 /* here the "-1" counts signify that the corresponding vector hasn't been
72 specified in command line arguments; sys_open_audio will detect this
73 and fill things in. */
74 int sys_nsoundin = -1;
75 int sys_nsoundout = -1;
76 int sys_soundindevlist[MAXAUDIOINDEV];
77 int sys_soundoutdevlist[MAXAUDIOOUTDEV];
79 int sys_nchin = -1;
80 int sys_nchout = -1;
81 int sys_chinlist[MAXAUDIOINDEV];
82 int sys_choutlist[MAXAUDIOOUTDEV];
83 /* } IOhannes */
86 typedef struct _fontinfo
88 int fi_fontsize;
89 int fi_maxwidth;
90 int fi_maxheight;
91 int fi_hostfontsize;
92 int fi_width;
93 int fi_height;
94 } t_fontinfo;
96 /* these give the nominal point size and maximum height of the characters
97 in the six fonts. */
99 static t_fontinfo sys_fontlist[] = {
100 {8, 5, 9, 0, 0, 0}, {10, 7, 13, 0, 0, 0}, {12, 9, 16, 0, 0, 0},
101 {16, 10, 20, 0, 0, 0}, {24, 15, 25, 0, 0, 0}, {36, 25, 45, 0, 0, 0}};
102 #define NFONT (sizeof(sys_fontlist)/sizeof(*sys_fontlist))
104 /* here are the actual font size structs on msp's systems:
105 MSW:
106 font 8 5 9 8 5 11
107 font 10 7 13 10 6 13
108 font 12 9 16 14 8 16
109 font 16 10 20 16 10 18
110 font 24 15 25 16 10 18
111 font 36 25 42 36 22 41
113 linux:
114 font 8 5 9 8 5 9
115 font 10 7 13 12 7 13
116 font 12 9 16 14 9 15
117 font 16 10 20 16 10 19
118 font 24 15 25 24 15 24
119 font 36 25 42 36 22 41
122 static t_fontinfo *sys_findfont(int fontsize)
124 unsigned int i;
125 t_fontinfo *fi;
126 for (i = 0, fi = sys_fontlist; i < (NFONT-1); i++, fi++)
127 if (fontsize < fi[1].fi_fontsize) return (fi);
128 return (sys_fontlist + (NFONT-1));
131 int sys_nearestfontsize(int fontsize)
133 return (sys_findfont(fontsize)->fi_fontsize);
136 int sys_hostfontsize(int fontsize)
138 return (sys_findfont(fontsize)->fi_hostfontsize);
141 int sys_fontwidth(int fontsize)
143 return (sys_findfont(fontsize)->fi_width);
146 int sys_fontheight(int fontsize)
148 return (sys_findfont(fontsize)->fi_height);
151 int sys_defaultfont;
152 #ifdef MSW
153 #define DEFAULTFONT 12
154 #else
155 #define DEFAULTFONT 10
156 #endif
158 static void openit(const char *dirname, const char *filename)
160 char dirbuf[MAXPDSTRING], *nameptr;
161 int fd = open_via_path(dirname, filename, "", dirbuf, &nameptr,
162 MAXPDSTRING, 0);
163 if (fd)
165 close (fd);
166 glob_evalfile(0, gensym(nameptr), gensym(dirbuf));
168 else
169 error("%s: can't open", filename);
172 #define NHOSTFONT 7
174 /* this is called from the gui process. The first argument is the cwd, and
175 succeeding args give the widths and heights of known fonts. We wait until
176 these are known to open files and send messages specified on the command line.
177 We ask the GUI to specify the "cwd" in case we don't have a local OS to get it
178 from; for instance we could be some kind of RT embedded system. However, to
179 really make this make sense we would have to implement
180 open(), read(), etc, calls to be served somehow from the GUI too. */
182 void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv)
184 char *cwd = atom_getsymbolarg(0, argc, argv)->s_name;
185 t_namelist *nl;
186 unsigned int i, j;
187 if (argc != 2 + 3 * NHOSTFONT) bug("glob_initfromgui");
188 for (i = 0; i < NFONT; i++)
190 int wantheight = sys_fontlist[i].fi_maxheight;
191 for (j = 0; j < NHOSTFONT-1; j++)
193 if (atom_getintarg(3 * (j + 1) + 3, argc, argv) > wantheight)
194 break;
196 /* j is now the "real" font index for the desired font index i. */
197 sys_fontlist[i].fi_hostfontsize = atom_getintarg(3 * j + 1, argc, argv);
198 sys_fontlist[i].fi_width = atom_getintarg(3 * j + 2, argc, argv);
199 sys_fontlist[i].fi_height = atom_getintarg(3 * j + 3, argc, argv);
201 #if 0
202 for (i = 0; i < 6; i++)
203 fprintf(stderr, "font %d %d %d %d %d\n",
204 sys_fontlist[i].fi_fontsize,
205 sys_fontlist[i].fi_maxheight,
206 sys_fontlist[i].fi_hostfontsize,
207 sys_fontlist[i].fi_width,
208 sys_fontlist[i].fi_height);
209 #endif
210 /* load dynamic libraries specified with "-lib" args */
211 for (nl = sys_externlist; nl; nl = nl->nl_next)
212 if (!sys_load_lib(cwd, nl->nl_string))
213 post("%s: can't load library", nl->nl_string);
214 namelist_free(sys_externlist);
215 sys_externlist = 0;
216 /* open patches specifies with "-open" args */
217 for (nl = sys_openlist; nl; nl = nl->nl_next)
218 openit(cwd, nl->nl_string);
219 namelist_free(sys_openlist);
220 sys_openlist = 0;
221 /* send messages specified with "-send" args */
222 for (nl = sys_messagelist; nl; nl = nl->nl_next)
224 t_binbuf *b = binbuf_new();
225 binbuf_text(b, nl->nl_string, strlen(nl->nl_string));
226 binbuf_eval(b, 0, 0, 0);
227 binbuf_free(b);
229 namelist_free(sys_messagelist);
230 sys_messagelist = 0;
231 sys_oldtclversion = atom_getfloatarg(1 + 3 * NHOSTFONT, argc, argv);
234 static void sys_afterargparse(void);
236 /* this is called from main() in s_entry.c */
237 int sys_main(int argc, char **argv)
239 #ifdef PD_DEBUG
240 fprintf(stderr, "Pd: COMPILED FOR DEBUGGING\n");
241 #endif
242 pd_init();
243 sys_findprogdir(argv[0]); /* set sys_progname, guipath */
244 #ifdef UNIX
245 sys_rcfile(); /* parse the startup file */
246 #endif
247 if (sys_argparse(argc, argv)) /* parse cmd line */
248 return (1);
249 sys_afterargparse(); /* post-argparse settings */
250 if (sys_verbose || sys_version) fprintf(stderr, "%scompiled %s %s\n",
251 pd_version, pd_compiletime, pd_compiledate);
252 if (sys_version) /* if we were just asked our version, exit here. */
253 return (0);
254 if (sys_startgui(sys_guidir->s_name)) /* start the gui */
255 return(1);
256 /* open audio and MIDI */
257 sys_open_midi(sys_nmidiin, sys_midiindevlist,
258 sys_nmidiout, sys_midioutdevlist);
259 sys_open_audio(sys_nsoundin, sys_soundindevlist, sys_nchin, sys_chinlist,
260 sys_nsoundout, sys_soundoutdevlist, sys_nchout, sys_choutlist,
261 sys_main_srate, sys_main_advance, 1);
262 /* run scheduler until it quits */
264 return (m_scheduler_pda());
265 return (m_scheduler());
268 static char *(usagemessage[]) = {
269 "usage: pd [-flags] [file]...\n",
270 "\naudio configuration flags:\n",
271 "-r <n> -- specify sample rate\n",
272 "-audioindev ... -- audio in devices; e.g., \"1,3\" for first and third\n",
273 "-audiooutdev ... -- audio out devices (same)\n",
274 "-audiodev ... -- specify input and output together\n",
275 "-inchannels ... -- audio input channels (by device, like \"2\" or \"16,8\")\n",
276 "-outchannels ... -- number of audio out channels (same)\n",
277 "-channels ... -- specify both input and output channels\n",
278 "-audiobuf <n> -- specify size of audio buffer in msec\n",
279 "-blocksize <n> -- specify audio I/O block size in sample frames\n",
280 "-sleepgrain <n> -- specify number of milliseconds to sleep when idle\n",
281 "-nodac -- suppress audio output\n",
282 "-noadc -- suppress audio input\n",
283 "-noaudio -- suppress audio input and output (-nosound is synonym) \n",
284 "-listdev -- list audio and MIDI devices\n",
286 #ifdef USEAPI_OSS
287 "-oss -- use OSS audio API\n",
288 "-32bit ----- allow 32 bit OSS audio (for RME Hammerfall)\n",
289 #endif
291 #ifdef USEAPI_ALSA
292 "-alsa -- use ALSA audio API\n",
293 "-alsaadd <name> -- add an ALSA device name to list\n",
294 "-alsadev <n> ----- obsolete: use -audiodev\n",
295 #endif
297 #ifdef USEAPI_JACK
298 "-jack -- use JACK audio API\n",
299 #endif
301 #ifdef USEAPI_PORTAUDIO
302 #ifdef MSW
303 "-asio -- use ASIO audio driver (via Portaudio)\n",
304 "-pa -- synonym for -asio\n",
305 #else
306 "-pa -- use Portaudio API\n",
307 #endif
308 #endif
310 #ifdef USEAPI_MMIO
311 "-mmio -- use MMIO audio API (default for Windows)\n",
312 #endif
313 " (default audio API for this platform: ", API_DEFSTRING, ")\n\n",
315 "\nMIDI configuration flags:\n",
316 "-midiindev ... -- midi in device list; e.g., \"1,3\" for first and third\n",
317 "-midioutdev ... -- midi out device list, same format\n",
318 "-mididev ... -- specify -midioutdev and -midiindev together\n",
319 "-nomidiin -- suppress MIDI input\n",
320 "-nomidiout -- suppress MIDI output\n",
321 "-nomidi -- suppress MIDI input and output\n",
323 "\nother flags:\n",
324 "-path <path> -- add to file search path\n",
325 "-helppath <path> -- add to help file search path\n",
326 "-open <file> -- open file(s) on startup\n",
327 "-lib <file> -- load object library(s)\n",
328 "-font <n> -- specify default font size in points\n",
329 "-verbose -- extra printout on startup and when searching for files\n",
330 "-version -- don't run Pd; just print out which version it is \n",
331 "-d <n> -- specify debug level\n",
332 "-noloadbang -- suppress all loadbangs\n",
333 "-nogui -- suppress starting the GUI\n",
334 "-stdin -- scan stdin for keypresses\n",
335 "-guicmd \"cmd...\" -- substitute another GUI program (e.g., rsh)\n",
336 "-send \"msg...\" -- send a message at startup (after patches are loaded)\n",
337 #ifdef UNIX
338 "-rt or -realtime -- use real-time priority\n",
339 "-nrt -- don't use real-time priority\n",
340 #endif
343 static void sys_parsedevlist(int *np, int *vecp, int max, char *str)
345 int n = 0;
346 while (n < max)
348 if (!*str) break;
349 else
351 char *endp;
352 vecp[n] = strtol(str, &endp, 10);
353 if (endp == str)
354 break;
355 n++;
356 if (!endp)
357 break;
358 str = endp + 1;
361 *np = n;
364 static int sys_getmultidevchannels(int n, int *devlist)
366 int sum = 0;
367 if (n<0)return(-1);
368 if (n==0)return 0;
369 while(n--)sum+=*devlist++;
370 return sum;
374 /* this routine tries to figure out where to find the auxilliary files
375 Pd will need to run. This is either done by looking at the command line
376 invokation for Pd, or if that fails, by consulting the variable
377 INSTALL_PREFIX. In MSW, we don't try to use INSTALL_PREFIX. */
378 void sys_findprogdir(char *progname)
380 char sbuf[MAXPDSTRING], sbuf2[MAXPDSTRING], *sp;
381 char *lastslash;
382 #ifdef UNIX
383 struct stat statbuf;
384 #endif
386 /* find out by what string Pd was invoked; put answer in "sbuf". */
387 #ifdef MSW
388 GetModuleFileName(NULL, sbuf2, sizeof(sbuf2));
389 sbuf2[MAXPDSTRING-1] = 0;
390 sys_unbashfilename(sbuf2, sbuf);
391 #endif /* MSW */
392 #ifdef UNIX
393 strncpy(sbuf, progname, MAXPDSTRING);
394 sbuf[MAXPDSTRING-1] = 0;
395 #endif
396 lastslash = strrchr(sbuf, '/');
397 if (lastslash)
399 /* bash last slash to zero so that sbuf is directory pd was in,
400 e.g., ~/pd/bin */
401 *lastslash = 0;
402 /* go back to the parent from there, e.g., ~/pd */
403 lastslash = strrchr(sbuf, '/');
404 if (lastslash)
406 strncpy(sbuf2, sbuf, lastslash-sbuf);
407 sbuf2[lastslash-sbuf] = 0;
409 else strcpy(sbuf2, "..");
411 else
413 /* no slashes found. Try INSTALL_PREFIX. */
414 #ifdef INSTALL_PREFIX
415 strcpy(sbuf2, INSTALL_PREFIX);
416 #else
417 strcpy(sbuf2, ".");
418 #endif
420 /* now we believe sbuf2 holds the parent directory of the directory
421 pd was found in. We now want to infer the "lib" directory and the
422 "gui" directory. In "simple" UNIX installations, the layout is
423 .../bin/pd
424 .../bin/pd-gui
425 .../doc
426 and in "complicated" UNIX installations, it's:
427 .../bin/pd
428 .../lib/pd/bin/pd-gui
429 .../lib/pd/doc
430 To decide which, we stat .../lib/pd; if that exists, we assume it's
431 the complicated layout. In MSW, it's the "simple" layout, but
432 the gui program is straight wish80:
433 .../bin/pd
434 .../bin/wish80.exe
435 .../doc
437 #ifdef UNIX
438 strncpy(sbuf, sbuf2, MAXPDSTRING-30);
439 sbuf[MAXPDSTRING-30] = 0;
440 strcat(sbuf, "/lib/pd");
441 if (stat(sbuf, &statbuf) >= 0)
443 /* complicated layout: lib dir is the one we just stat-ed above */
444 sys_libdir = gensym(sbuf);
445 /* gui lives in .../lib/pd/bin */
446 strncpy(sbuf, sbuf2, MAXPDSTRING-30);
447 sbuf[MAXPDSTRING-30] = 0;
448 strcat(sbuf, "/lib/pd/bin");
449 sys_guidir = gensym(sbuf);
451 else
453 /* simple layout: lib dir is the parent */
454 sys_libdir = gensym(sbuf2);
455 /* gui lives in .../bin */
456 strncpy(sbuf, sbuf2, MAXPDSTRING-30);
457 sbuf[MAXPDSTRING-30] = 0;
458 strcat(sbuf, "/bin");
459 sys_guidir = gensym(sbuf);
461 #endif
462 #ifdef MSW
463 sys_libdir = gensym(sbuf2);
464 sys_guidir = &s_; /* in MSW the guipath just depends on the libdir */
465 #endif
468 #ifdef MSW
469 static int sys_mmio = 1;
470 #else
471 static int sys_mmio = 0;
472 #endif
474 int sys_argparse(int argc, char **argv)
476 char sbuf[MAXPDSTRING];
477 int i;
478 argc--; argv++;
479 while ((argc > 0) && **argv == '-')
481 if (!strcmp(*argv, "-r") && argc > 1 &&
482 sscanf(argv[1], "%d", &sys_main_srate) >= 1)
484 argc -= 2;
485 argv += 2;
487 else if (!strcmp(*argv, "-inchannels"))
488 { /* IOhannes */
489 sys_parsedevlist(&sys_nchin,
490 sys_chinlist, MAXAUDIOINDEV, argv[1]);
492 if (!sys_nchin)
493 goto usage;
495 argc -= 2; argv += 2;
497 else if (!strcmp(*argv, "-outchannels"))
498 { /* IOhannes */
499 sys_parsedevlist(&sys_nchout, sys_choutlist,
500 MAXAUDIOOUTDEV, argv[1]);
502 if (!sys_nchout)
503 goto usage;
505 argc -= 2; argv += 2;
507 else if (!strcmp(*argv, "-channels"))
509 sys_parsedevlist(&sys_nchin, sys_chinlist,MAXAUDIOINDEV,
510 argv[1]);
511 sys_parsedevlist(&sys_nchout, sys_choutlist,MAXAUDIOOUTDEV,
512 argv[1]);
514 if (!sys_nchout)
515 goto usage;
517 argc -= 2; argv += 2;
519 else if (!strcmp(*argv, "-soundbuf") || !strcmp(*argv, "-audiobuf"))
521 sys_main_advance = atoi(argv[1]);
522 argc -= 2; argv += 2;
524 else if (!strcmp(*argv, "-blocksize"))
526 sys_setblocksize(atoi(argv[1]));
527 argc -= 2; argv += 2;
529 else if (!strcmp(*argv, "-sleepgrain"))
531 sys_sleepgrain = 1000 * atoi(argv[1]);
532 argc -= 2; argv += 2;
534 else if (!strcmp(*argv, "-nodac"))
535 { /* IOhannes */
536 sys_nsoundout=0;
537 sys_nchout = 0;
538 argc--; argv++;
540 else if (!strcmp(*argv, "-noadc"))
541 { /* IOhannes */
542 sys_nsoundin=0;
543 sys_nchin = 0;
544 argc--; argv++;
546 else if (!strcmp(*argv, "-nosound") || !strcmp(*argv, "-noaudio"))
547 { /* IOhannes */
548 sys_nsoundin=sys_nsoundout = 0;
549 sys_nchin = sys_nchout = 0;
550 argc--; argv++;
552 #ifdef USEAPI_OSS
553 else if (!strcmp(*argv, "-oss"))
555 sys_set_audio_api(API_OSS);
556 argc--; argv++;
558 else if (!strcmp(*argv, "-32bit"))
560 sys_set_audio_api(API_OSS);
561 oss_set32bit();
562 argc--; argv++;
564 #endif
565 #ifdef USEAPI_ALSA
566 else if (!strcmp(*argv, "-alsa"))
568 sys_set_audio_api(API_ALSA);
569 argc--; argv++;
571 else if (!strcmp(*argv, "-alsaadd"))
573 if (argc > 1)
574 alsa_adddev(argv[1]);
575 else goto usage;
576 argc -= 2; argv +=2;
578 /* obsolete flag for setting ALSA device number or name */
579 else if (!strcmp(*argv, "-alsadev"))
581 int devno = 0;
582 if (argv[1][0] >= '1' && argv[1][0] <= '9')
583 devno = 1 + 2 * (atoi(argv[1]) - 1);
584 else if (!strncmp(argv[1], "hw:", 3))
585 devno = 1 + 2 * atoi(argv[1]+3);
586 else if (!strncmp(argv[1], "plughw:", 7))
587 devno = 2 + 2 * atoi(argv[1]+7);
588 else goto usage;
589 sys_nsoundin = sys_nsoundout = 1;
590 sys_soundindevlist[0] = sys_soundoutdevlist[0] = devno;
591 sys_set_audio_api(API_ALSA);
592 argc -= 2; argv +=2;
594 #endif
595 #ifdef USEAPI_JACK
596 else if (!strcmp(*argv, "-jack"))
598 sys_set_audio_api(API_JACK);
599 argc--; argv++;
601 #endif
602 #ifdef USEAPI_PORTAUDIO
603 else if (!strcmp(*argv, "-pa") || !strcmp(*argv, "-portaudio")
604 #ifdef MSW
605 || !strcmp(*argv, "-asio")
606 #endif
609 sys_set_audio_api(API_PORTAUDIO);
610 sys_mmio = 0;
611 argc--; argv++;
613 #endif
614 #ifdef USEAPI_MMIO
615 else if (!strcmp(*argv, "-mmio"))
617 sys_set_audio_api(API_MMIO);
618 sys_mmio = 1;
619 argc--; argv++;
621 #endif
622 else if (!strcmp(*argv, "-nomidiin"))
624 sys_nmidiin = 0;
625 argc--; argv++;
627 else if (!strcmp(*argv, "-nomidiout"))
629 sys_nmidiout = 0;
630 argc--; argv++;
632 else if (!strcmp(*argv, "-nomidi"))
634 sys_nmidiin = sys_nmidiout = 0;
635 argc--; argv++;
637 else if (!strcmp(*argv, "-midiindev"))
639 sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV,
640 argv[1]);
641 if (!sys_nmidiin)
642 goto usage;
643 argc -= 2; argv += 2;
645 else if (!strcmp(*argv, "-midioutdev"))
647 sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV,
648 argv[1]);
649 if (!sys_nmidiout)
650 goto usage;
651 argc -= 2; argv += 2;
653 else if (!strcmp(*argv, "-mididev"))
655 sys_parsedevlist(&sys_nmidiin, sys_midiindevlist, MAXMIDIINDEV,
656 argv[1]);
657 sys_parsedevlist(&sys_nmidiout, sys_midioutdevlist, MAXMIDIOUTDEV,
658 argv[1]);
659 if (!sys_nmidiout)
660 goto usage;
661 argc -= 2; argv += 2;
663 else if (!strcmp(*argv, "-path"))
665 sys_addpath(argv[1]);
666 argc -= 2; argv += 2;
668 else if (!strcmp(*argv, "-helppath"))
670 sys_addhelppath(argv[1]);
671 argc -= 2; argv += 2;
673 else if (!strcmp(*argv, "-open") && argc > 1)
675 sys_openlist = namelist_append(sys_openlist, argv[1]);
676 argc -= 2; argv += 2;
678 else if (!strcmp(*argv, "-lib") && argc > 1)
680 sys_externlist = namelist_append(sys_externlist, argv[1]);
681 argc -= 2; argv += 2;
683 else if (!strcmp(*argv, "-font") && argc > 1)
685 sys_defaultfont = sys_nearestfontsize(atoi(argv[1]));
686 argc -= 2;
687 argv += 2;
689 else if (!strcmp(*argv, "-verbose"))
691 sys_verbose = 1;
692 argc--; argv++;
694 else if (!strcmp(*argv, "-version"))
696 sys_version = 1;
697 argc--; argv++;
699 else if (!strcmp(*argv, "-d") && argc > 1 &&
700 sscanf(argv[1], "%d", &sys_debuglevel) >= 1)
702 argc -= 2;
703 argv += 2;
705 else if (!strcmp(*argv, "-noloadbang"))
707 sys_noloadbang = 1;
708 argc--; argv++;
710 else if (!strcmp(*argv, "-nogui"))
712 sys_nogui = 1;
713 argc--; argv++;
715 else if (!strcmp(*argv, "-stdin"))
717 sys_stdin = 1;
718 argc--; argv++;
720 else if (!strcmp(*argv, "-guicmd") && argc > 1)
722 sys_guicmd = argv[1];
723 argc -= 2; argv += 2;
725 else if (!strcmp(*argv, "-send") && argc > 1)
727 sys_messagelist = namelist_append(sys_messagelist, argv[1]);
728 argc -= 2; argv += 2;
730 else if (!strcmp(*argv, "-listdev"))
732 sys_listdevs();
733 argc--; argv++;
735 #ifdef UNIX
736 else if (!strcmp(*argv, "-rt") || !strcmp(*argv, "-realtime"))
738 sys_hipriority = 1;
739 argc--; argv++;
741 else if (!strcmp(*argv, "-nrt"))
743 sys_hipriority = 0;
744 argc--; argv++;
746 #endif
747 else if (!strcmp(*argv, "-soundindev") ||
748 !strcmp(*argv, "-audioindev"))
749 { /* IOhannes */
750 sys_parsedevlist(&sys_nsoundin, sys_soundindevlist,
751 MAXAUDIOINDEV, argv[1]);
752 if (!sys_nsoundin)
753 goto usage;
754 argc -= 2; argv += 2;
756 else if (!strcmp(*argv, "-soundoutdev") ||
757 !strcmp(*argv, "-audiooutdev"))
758 { /* IOhannes */
759 sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist,
760 MAXAUDIOOUTDEV, argv[1]);
761 if (!sys_nsoundout)
762 goto usage;
763 argc -= 2; argv += 2;
765 else if (!strcmp(*argv, "-sounddev") || !strcmp(*argv, "-audiodev"))
767 sys_parsedevlist(&sys_nsoundin, sys_soundindevlist,
768 MAXAUDIOINDEV, argv[1]);
769 sys_parsedevlist(&sys_nsoundout, sys_soundoutdevlist,
770 MAXAUDIOOUTDEV, argv[1]);
771 if (!sys_nsoundout)
772 goto usage;
773 argc -= 2; argv += 2;
775 else
777 unsigned int i;
778 usage:
779 for (i = 0; i < sizeof(usagemessage)/sizeof(*usagemessage); i++)
780 fprintf(stderr, "%s", usagemessage[i]);
781 return (1);
784 if (!sys_defaultfont)
785 sys_defaultfont = DEFAULTFONT;
786 for (; argc > 0; argc--, argv++)
787 sys_openlist = namelist_append(sys_openlist, *argv);
790 return (0);
793 int sys_getblksize(void)
795 return (DEFDACBLKSIZE);
798 /* stuff to do, once, after calling sys_argparse() -- which may itself
799 be called twice because of the .pdrc hack. */
800 static void sys_afterargparse(void)
802 char sbuf[MAXPDSTRING];
803 int i;
804 /* add "extra" library to path */
805 strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30);
806 sbuf[MAXPDSTRING-30] = 0;
807 strcat(sbuf, "/extra");
808 sys_addpath(sbuf);
809 strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30);
810 sbuf[MAXPDSTRING-30] = 0;
811 strcat(sbuf, "/intern");
812 sys_addpath(sbuf);
813 /* add "doc/5.reference" library to helppath */
814 strncpy(sbuf, sys_libdir->s_name, MAXPDSTRING-30);
815 sbuf[MAXPDSTRING-30] = 0;
816 strcat(sbuf, "/doc/5.reference");
817 sys_addhelppath(sbuf);
818 /* correct to make audio and MIDI device lists zero based. On
819 MMIO, however, "1" really means the second device (the first one
820 is "mapper" which is was not included when the command args were
821 set up, so we leave it that way for compatibility. */
822 if (!sys_mmio)
824 for (i = 0; i < sys_nsoundin; i++)
825 sys_soundindevlist[i]--;
826 for (i = 0; i < sys_nsoundout; i++)
827 sys_soundoutdevlist[i]--;
829 for (i = 0; i < sys_nmidiin; i++)
830 sys_midiindevlist[i]--;
831 for (i = 0; i < sys_nmidiout; i++)
832 sys_midioutdevlist[i]--;
835 static void sys_addreferencepath(void)
837 char sbuf[MAXPDSTRING];