230{
231
232#ifdef PEBL_EMSCRIPTEN
233 EM_ASM(console.log("=== PEBLInterpret() called ==="));
234#endif
235
236 std::cerr << "**************Starting PEBLInterpret\n";
237 std::cerr << "**************argc:" << argc << endl;
238
239#if defined(PEBL_UNIX) and not defined(PEBL_OSX)
240 if(argc==2 && strcmp(argv[1].c_str(), "--install")==0)
241 {
242 string basedir;
245 {
246 PError::SignalWarning(
"Warning: BinReloc failed to initialize.\n Will fallback to hardcoded default path.\n");
247
248 basedir = "/usr/local/share/pebl2";
249 }
250
252 basedir = prefix + string("/share/pebl2/battery/");
253 string destdir = string(
"~/Documents/pebl-exp.") +
PEBL_VERSION;
254
255
256
259 std::cerr << "Copying files to ["+destdir+ "]\n";
261 exit(0);
262 }
263#endif
264
266
267
268
269
270
271
272#if 1
273
274 cerr << "************Arguments: "<< argv.size()<<"\n";
275 std::vector<std::string>::iterator ii = argv.begin();
276 while(ii != argv.end())
277 {
278 cerr << *ii << endl;
279 ii++;
280 cerr << "********\n";
281 }
282#endif
283
284
285
286 std::list<std::string> files =
GetFiles(argc, argv);
287
288
290
292
293
294 files.push_back("Design.pbl");
295 files.push_back("Utility.pbl");
296 files.push_back("Math.pbl");
297 files.push_back("Graphics.pbl");
298 files.push_back("UI.pbl");
299 files.push_back("HTML.pbl");
300 files.push_back("Transfer.pbl");
301 files.push_back("Layout.pbl");
302
303#ifdef PEBL_EMSCRIPTEN
304 files.push_back("EM.pbl");
305
306#endif
307
308
309
310
311#ifdef PEBL_EMSCRIPTEN
312
313
314#endif
315
316
317
318 std::list<std::string>::iterator i = files.begin();
319 i++;
320
321
322
323
324
325 std::cerr << "Loading filename:[" << *i << "]\n";
327 string otherfilename;
328
330 if(inputfilename != "")
331 {
332 cerr << "Processing PEBL Source File1: " << inputfilename << endl;
334 }
335 else
336 {
338 }
339 i++;
340
341
342
343
344
345 while(i != files.end())
346 {
347 std::cerr << "********************\n";
348 std::cerr << "Loading file name: [" << *i <<"]"<< endl;
350 std::cerr << "Resolved as: [" <<otherfilename <<"]"<< endl;
351 if(inputfilename != "")
352 {
353 cerr << "Processing PEBL Source File2: " << otherfilename << endl;
354
355
356
358 {
359
360 tmp =
parse(otherfilename.c_str());
361
362
363 head =
new OpNode(PEBL_FUNCTIONS,
head, tmp,
"INTERNAL PEBL STRUCTURE", -1);
364 }
365 }
366 else
367 {
369
370
371 }
372 i++;
373 }
374
375
376
377
378 cerr << "---------Loading Program---------" << endl;
379
380
381
384
385
386 cerr <<"Analyzing code for functions." << endl;
388
389
390 cerr << "Loading Library functions." << endl;
392
393
394
395
396
400
401#if 0
402 cerr << "\n\n--------------------------------\n";
403 cerr << "Functions used in program: " << endl;
404 cerr << "--------------------------------\n";
406 cerr << "--------------------------------\n\n";
407#endif
408
409
410
413
414
415
416
417
418
419
420 std::string displaySize="0x0";
421
422
423 std::string depth = "32";
426 bool windowed = true;
427 bool vsync = false;
428 bool softrender = false;
429 bool resizeable = false;
430 bool unicode = true;
431 bool upload = false;
432 bool showHelp = false;
433 bool showTestResults = false;
434 bool lslEnabled = false;
435
438
441
442
445
446
448
449
450 for(int j = 1; j < argc; j++)
451 {
452
453 if(strcmp(argv[j].c_str(), "-v")==0 ||
454 strcmp(argv[j].c_str(), "-V")==0)
455 {
457
459 }
460
461 else if(strcmp(argv[j].c_str(), "-s")==0 ||
462 strcmp(argv[j].c_str(), "-S")==0)
463 {
464 subnum = argv[++j];
465
466 }
467
468 else if(strcmp(argv[j].c_str(),"--driver")==0)
469 {
470 if(j+1 < argc)
471 {
472 j++;
474 }
475 }
476 else if(strcmp(argv[j].c_str(),"--display")==0)
477 {
478 displaySize = argv[++j];
479 }
480
481 else if(strcmp(argv[j].c_str(),"--depth")==0)
482 {
483 depth = argv[++j];
484
485 }
486
487 else if (strcmp(argv[j].c_str(),"--fullscreen")==0)
488 {
489 windowed = false;
490 }
491 else if(strcmp(argv[j].c_str(),"--windowed")==0)
492 {
493 windowed = true;
494 }
495 else if(strcmp(argv[j].c_str(),"--unicode")==0)
496 {
497 unicode = true;
498 }
499 else if(strcmp(argv[j].c_str(),"--language")==0)
500 {
501 lang = argv[++j];
502 }
503
504 else if(strcmp(argv[j].c_str(),"--pfile")==0)
505 {
506 std::string pfileArg = argv[++j];
507
508 if(pfileArg.compare(0, 7, "http://") == 0 || pfileArg.compare(0, 8, "https://") == 0)
509 {
511 }
512 else
513 {
515 }
516 }
517
518 else if(strcmp(argv[j].c_str(),"--upload")==0)
519 {
520
521 upload = true;
522 uploadConfigFile =
Variant(argv[++j]);
523 cerr << "setting upload file: [" << uploadConfigFile << "]\n";
524 }
525
526 else if(strcmp(argv[j].c_str(),"--lsl")==0)
527 {
528 lslEnabled = true;
529
530 if(j+1 < argc && argv[j+1].c_str()[0] != '-')
531 {
532 lslStreamName =
Variant(argv[++j]);
533 cerr << "LSL enabled with stream name: [" << lslStreamName << "]\n";
534 }
535 else
536 {
537 cerr << "LSL enabled (auto-generate stream name)\n";
538 }
539 }
540
541 else if(strcmp(argv[j].c_str(),"--resizeable")==0 ||
542 strcmp(argv[j].c_str(),"--resizable")==0 )
543 {
544 if(windowed)
545 resizeable = true;
546 }
547 else if(strcmp(argv[j].c_str(),"--vsyncon")==0)
548 {
549 vsync = true;
550 }
551
552 else if(strcmp(argv[j].c_str(),"--vsyncoff")==0)
553 {
554 vsync = false;
555 }
556 else if(strcmp(argv[j].c_str(),"--softrender")==0)
557 {
558 softrender = true;
559 }
560 else if(strcmp(argv[j].c_str(),"--help")==0)
561 {
562 showHelp = true;
563 }
564 else if(strcmp(argv[j].c_str(),"--showtestresults")==0)
565 {
566 showTestResults = true;
567 }
568
569
570
571 }
572
573
574
577
578
579
580
581#if defined(PEBL_UNIX)
582
583
584
585
586
587 cerr << "Priority set here**************************\n";
588 int priority = getpriority(PRIO_PROCESS,0);
589 cerr << "Process running at a nice value of " << priority << endl;
590 cerr << "attempting to set priority to: " << PRIO_MIN << endl;
591
592 setpriority(PRIO_PROCESS,0,PRIO_MIN);
593 priority = getpriority(PRIO_PROCESS,0);
594
595 cerr << "Process running at a nice value of " << priority << endl;
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622#elif defined(PEBL_WIN32)
623
624
625
626
627 SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS);
628
629
630#endif
631
632
633
634
635
636
638
639 cerr << "Environment created\n";
640
641
642
643 srand((unsigned int)time(0));
644
645 cerr << "---------Creating Evaluator-----" << endl;
646
647
648
649#if defined(PEBL_EMSCRIPTEN)
650 std::cerr <<"--------o-o-o-o-o-o--\n";
654#else
655
656
657
659 {
660 cerr <<"No command line arguments given\n";
664 }
665 else
666 {
669 }
670#endif
671
674
675 if(showHelp)
676 {
678 }
679
680
681
682 std::list<PNode> tmpcallstack;
683
684
686
687
688#if defined(PEBL_LINUX) || defined(PEBL_UNIX)
689
690 const char* appimage_path = getenv("APPIMAGE");
691 if (appimage_path !=
NULL) {
692
694 cerr << "Running from AppImage: " << appimage_path << endl;
695 } else {
696
698 if (exe_path !=
NULL) {
699
701 cerr << "Executable path: " << exe_path << endl;
702 free(exe_path);
703 } else {
704
707 }
708 }
709#else
710
712#endif
714
716
717
721
722 delete plist;
723 cursize = 0;
724
727
728
730
731
732
733
734 size_t found = displaySize.find("x");
735 if(found == string::npos)
736 {
737
738 width = 0;
739 height = 0;
740 } else
741 {
742 cerr <<"Size from command line argument: " << displaySize.substr(0,found)<< "|"<< displaySize.substr(found+1) <<endl;
743
744 width = atoi(displaySize.substr(0,found).c_str());
745 height = atoi(displaySize.substr(found+1).c_str());
746 }
747
748
750 {
753 }
754
755
756
758
759
761
762
764
765
767
768
769
770
773
774
775
776
779
780
781 std::string tmps =lang;
782 transform(tmps.begin(),tmps.end(),tmps.begin(),toupper);
784
785
786
788
789
791
792
793
794
798
802
803
804
805
806
810
811
813
814
815
817
819
821 {
822 cerr << "---------Evaluating Program-----" << endl;
823
824
825
826#ifdef PEBL_ITERATIVE_EVAL
827
828 cerr << "Starting evaluation with iterative evaluator\n";
829
830
831
832
833
834
835
836
840
842 OpNode* startCall =
new OpNode(PEBL_FUNCTION, funcNameNode, args,
"", 0);
843
845
846 cerr << "Running evaluator loop\n";
848 {
850 }
851#else
852
853 cerr << "Starting evaluation with recursive evaluator\n";
855#endif
856
857
858
859 int scriptReturnCode = 0;
862
864 scriptReturnCode = (int)returnVal;
865 cerr << "Script returned: " << scriptReturnCode << endl;
866 }
867 }
868
869#ifdef PEBL_EMSCRIPTEN
870
871 cerr << "========================================" << endl;
872 cerr << "PEBL program completed successfully." << endl;
873 cerr << "========================================" << endl;
874
875
877
878 return 0;
879#else
880
881
882
883
884 delete ::myEval;
886
888
892
893
894#ifdef PEBL_MOVIES
895
896 WV_waaveClose();
897#endif
898
899
900
901
902 SDL_Quit();
903
904
905
906 cerr << "Exiting with code: " << scriptReturnCode << endl;
907 _exit(scriptReturnCode);
908#endif
909
910
911
912
913 v = 0;
914
915 return scriptReturnCode;
916 }
917 else
918 {
919 cerr << "Error: Can't evaluate program" << endl;
920
922 return 1;
923
924 }
925
926 return 0;
927
928}
char * br_find_prefix(const char *default_prefix)
char * br_find_exe(const char *default_exe)
std::list< string > GetFiles(int argc, std::vector< std::string > argv)
This class has got everything you need to evaluate stuff.
bool Evaluate(const PNode *node)
void LoadUserFunctions(OpNode *node)
void LoadLibraryFunctions()
void FindFunctions(const PNode *Node)
PNode * GetMainPEBLFunction()
std::string FindFile(const string &filename)
void Initialize(std::list< std::string >)
Variant Nth(unsigned int n)
unsigned long Length() const
void PushBack(const Variant &v)
PComplexData * GetComplexData() const
bool IsNumber() const
This tests whether the Variant is a number (i.e., a float or an integer.)
Variant IsDirectory(Variant v)
void MakeEnvironment(PEBLVideoMode mode, PEBLVideoDepth depth, bool windowed, bool resizeable, bool unicode)
This function instantiates the namespace-viewable.
Variant SystemCall(std::string path, std::string args)
PEBLVideoDepth GetVideoDepth(std::string depthline)
const std::string GetBaseFileName(const std::string &file)
std::string GetFontForLanguageOrScript(const std::string &code, int fontType)
PEBLVideoMode GetVideoMode(std::string modeline)
Variant GetCurrentScreenResolution()