author | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
commit | 155d68c1e7d7dc0fed2534ac43d6d77ce2781f55 (patch) (unidiff) | |
tree | e6edaa5a7040fe6c224c3943d1094dcf02e4f74c /qmake/project.cpp | |
parent | 86703e8a5527ef114facd02c005b6b3a7e62e263 (diff) | |
download | opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.zip opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.gz opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.bz2 |
update qmake to 1.05a
-rw-r--r-- | qmake/project.cpp | 407 |
1 files changed, 245 insertions, 162 deletions
diff --git a/qmake/project.cpp b/qmake/project.cpp index 44eb503..834823d 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp | |||
@@ -68,5 +68,10 @@ static QString varMap(const QString &x) | |||
68 | QString ret(x); | 68 | QString ret(x); |
69 | ret.replace(QRegExp("^TMAKE"), "QMAKE"); | 69 | if(ret.startsWith("TMAKE")) //tmake no more! |
70 | ret = "QMAKE" + ret.mid(5); | ||
70 | if(ret == "INTERFACES") | 71 | if(ret == "INTERFACES") |
71 | ret = "FORMS"; | 72 | ret = "FORMS"; |
73 | if(ret == "QMAKE_POST_BUILD") | ||
74 | ret = "QMAKE_POST_LINK"; | ||
75 | if(ret == "TARGETDEPS") | ||
76 | ret = "POST_TARGETDEPS"; | ||
72 | return ret; | 77 | return ret; |
@@ -108,3 +113,3 @@ static QStringList split_value_list(const QString &vals, bool do_semicolon=FALSE | |||
108 | quote.push(vals[x]); | 113 | quote.push(vals[x]); |
109 | } else if(quote.isEmpty() && | 114 | } else if(quote.isEmpty() && |
110 | ((do_semicolon && vals[x] == ';') || vals[x] == ' ')) { | 115 | ((do_semicolon && vals[x] == ';') || vals[x] == ' ')) { |
@@ -124,6 +129,8 @@ QMakeProject::QMakeProject() | |||
124 | bool | 129 | bool |
125 | QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | 130 | QMakeProject::parse(const QString &t, QMap<QString, QStringList> &place) |
126 | { | 131 | { |
127 | QString s = t.simplifyWhiteSpace(); | 132 | QString s = t.simplifyWhiteSpace(); |
128 | s.replace(QRegExp("#.*$"), ""); /* bye comments */ | 133 | int hash_mark = s.find('#'); |
134 | if(hash_mark != -1) //good bye comments | ||
135 | s = s.left(hash_mark); | ||
129 | if(s.isEmpty()) /* blank_line */ | 136 | if(s.isEmpty()) /* blank_line */ |
@@ -156,13 +163,17 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | |||
156 | int parens = 0, scope_count=0; | 163 | int parens = 0, scope_count=0; |
157 | while(*d && *d != '=') { | 164 | while(*d) { |
158 | if((*d == '+' || *d == '-' || *d == '*' || *d == '~')) { | 165 | if(!parens) { |
159 | if(*(d+1) == '=') { | 166 | if(*d == '=') |
160 | break; | 167 | break; |
161 | } else if(*(d+1) == ' ') { | 168 | if(*d == '+' || *d == '-' || *d == '*' || *d == '~') { |
162 | const char *k = d + 1; | 169 | if(*(d+1) == '=') { |
163 | SKIP_WS(k); | 170 | break; |
164 | if(*k == '=') { | 171 | } else if(*(d+1) == ' ') { |
165 | QString msg; | 172 | const char *k = d + 1; |
166 | qmake_error_msg(*d + "must be followed immediatly by ="); | 173 | SKIP_WS(k); |
167 | return FALSE; | 174 | if(*k == '=') { |
175 | QString msg; | ||
176 | qmake_error_msg(*d + "must be followed immediately by ="); | ||
177 | return FALSE; | ||
178 | } | ||
168 | } | 179 | } |
@@ -219,3 +230,3 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | |||
219 | } else { | 230 | } else { |
220 | test = isActiveConfig(comp_scope.stripWhiteSpace()); | 231 | test = isActiveConfig(comp_scope.stripWhiteSpace(), TRUE); |
221 | } | 232 | } |
@@ -289,3 +300,3 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | |||
289 | /* vallist is the broken up list of values */ | 300 | /* vallist is the broken up list of values */ |
290 | QStringList vallist = split_value_list(vals, (var == "DEPENDPATH" || var == "INCLUDEPATH")); | 301 | QStringList vallist = split_value_list(vals, (var == "DEPENDPATH" || var == "INCLUDEPATH")); |
291 | if(!vallist.grep("=").isEmpty()) | 302 | if(!vallist.grep("=").isEmpty()) |
@@ -357,3 +368,3 @@ QMakeProject::parse(QString t, QMap<QString, QStringList> &place) | |||
357 | bool | 368 | bool |
358 | QMakeProject::read(QString file, QMap<QString, QStringList> &place) | 369 | QMakeProject::read(const QString &file, QMap<QString, QStringList> &place) |
359 | { | 370 | { |
@@ -365,7 +376,7 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place) | |||
365 | 376 | ||
366 | file = Option::fixPathToLocalOS(file); | 377 | QString filename = Option::fixPathToLocalOS(file); |
367 | doVariableReplace(file, place); | 378 | doVariableReplace(filename, place); |
368 | bool ret = FALSE, using_stdin = FALSE; | 379 | bool ret = FALSE, using_stdin = FALSE; |
369 | QFile qfile; | 380 | QFile qfile; |
370 | if(!strcmp(file, "-")) { | 381 | if(!strcmp(filename, "-")) { |
371 | qfile.setName(""); | 382 | qfile.setName(""); |
@@ -374,3 +385,3 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place) | |||
374 | } else { | 385 | } else { |
375 | qfile.setName(file); | 386 | qfile.setName(filename); |
376 | ret = qfile.open(IO_ReadOnly); | 387 | ret = qfile.open(IO_ReadOnly); |
@@ -380,3 +391,3 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place) | |||
380 | QString s, line; | 391 | QString s, line; |
381 | parser.file = file; | 392 | parser.file = filename; |
382 | parser.line_no = 0; | 393 | parser.line_no = 0; |
@@ -386,3 +397,7 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place) | |||
386 | int prelen = line.length(); | 397 | int prelen = line.length(); |
387 | line.replace(QRegExp("#.*$"), ""); // bye comments | 398 | { |
399 | int hash_mark = line.find('#'); | ||
400 | if(hash_mark != -1) //bye comments | ||
401 | line = line.left(hash_mark); | ||
402 | } | ||
388 | if(!line.isEmpty() && line.right(1) == "\\") { | 403 | if(!line.isEmpty() && line.right(1) == "\\") { |
@@ -410,4 +425,11 @@ QMakeProject::read(QString file, QMap<QString, QStringList> &place) | |||
410 | bool | 425 | bool |
411 | QMakeProject::read(QString project, QString) | 426 | QMakeProject::read(const QString &project, const QString &, bool just_project) |
412 | { | 427 | { |
428 | if(just_project) { //nothing more, nothing less | ||
429 | pfile = project; | ||
430 | if(pfile != "-" && !QFile::exists(pfile) && pfile.right(4) != ".pro") | ||
431 | pfile += ".pro"; | ||
432 | return read(pfile, vars); | ||
433 | } | ||
434 | |||
413 | if(cfile.isEmpty()) { | 435 | if(cfile.isEmpty()) { |
@@ -416,2 +438,4 @@ QMakeProject::read(QString project, QString) | |||
416 | base_vars["QMAKE_EXT_H"] = Option::h_ext; | 438 | base_vars["QMAKE_EXT_H"] = Option::h_ext; |
439 | if(!Option::user_template_prefix.isEmpty()) | ||
440 | base_vars["TEMPLATE_PREFIX"] = Option::user_template_prefix; | ||
417 | 441 | ||
@@ -443,16 +467,5 @@ QMakeProject::read(QString project, QString) | |||
443 | /* prefer $QTDIR if it is set */ | 467 | /* prefer $QTDIR if it is set */ |
444 | /* prefer QMAKESPECSDIR -cl */ | 468 | if (getenv("QTDIR")) |
445 | |||
446 | if (getenv("QTDIR")) { | ||
447 | mkspec_roots << getenv("QTDIR"); | 469 | mkspec_roots << getenv("QTDIR"); |
448 | } | ||
449 | mkspec_roots << qInstallPathData(); | 470 | mkspec_roots << qInstallPathData(); |
450 | |||
451 | if (Option::mkfile::qmakespec.isEmpty() && getenv("QMAKESPECSDIR")){ | ||
452 | QString mkspec = QString(getenv("QMAKESPECSDIR")) + QDir::separator() + | ||
453 | QDir::separator() + "default"; | ||
454 | if(QFile::exists(mkspec)) | ||
455 | Option::mkfile::qmakespec = mkspec; | ||
456 | } | ||
457 | |||
458 | if(Option::mkfile::qmakespec.isEmpty()) { | 471 | if(Option::mkfile::qmakespec.isEmpty()) { |
@@ -466,7 +479,6 @@ QMakeProject::read(QString project, QString) | |||
466 | } | 479 | } |
467 | } | 480 | if(Option::mkfile::qmakespec.isEmpty()) { |
468 | 481 | fprintf(stderr, "QMAKESPEC has not been set, so configuration cannot be deduced.\n"); | |
469 | if(Option::mkfile::qmakespec.isEmpty()) { | 482 | return FALSE; |
470 | fprintf(stderr, "QMAKESPEC has not been set, so configuration cannot be deduced.\n"); | 483 | } |
471 | return FALSE; | ||
472 | } | 484 | } |
@@ -546,8 +558,10 @@ QMakeProject::read(QString project, QString) | |||
546 | 558 | ||
547 | if(vars["TEMPLATE"].isEmpty()) | 559 | QStringList &templ = vars["TEMPLATE"]; |
548 | vars["TEMPLATE"].append(QString("app")); | 560 | if(templ.isEmpty()) |
549 | else | 561 | templ.append(QString("app")); |
550 | vars["TEMPLATE"].first().replace(QRegExp("\\.t$"), ""); | 562 | else if(vars["TEMPLATE"].first().endsWith(".t")) |
551 | if(!Option::user_template_prefix.isEmpty()) | 563 | templ = QStringList(templ.first().left(templ.first().length() - 2)); |
552 | vars["TEMPLATE"].first().prepend(Option::user_template_prefix); | 564 | if ( !Option::user_template_prefix.isEmpty() ) { |
565 | templ.first().prepend(Option::user_template_prefix); | ||
566 | } | ||
553 | 567 | ||
@@ -581,3 +595,3 @@ QMakeProject::read(QString project, QString) | |||
581 | bool | 595 | bool |
582 | QMakeProject::isActiveConfig(const QString &x) | 596 | QMakeProject::isActiveConfig(const QString &x, bool regex) |
583 | { | 597 | { |
@@ -586,5 +600,4 @@ QMakeProject::isActiveConfig(const QString &x) | |||
586 | 600 | ||
587 | QRegExp re(x, FALSE, TRUE); | 601 | if((Option::target_mode == Option::TARG_MACX_MODE || Option::target_mode == Option::TARG_QNX6_MODE || |
588 | if((Option::target_mode == Option::TARG_MACX_MODE || Option::target_mode == Option::TARG_QNX6_MODE || Option::target_mode == Option::TARG_UNIX_MODE) && | 602 | Option::target_mode == Option::TARG_UNIX_MODE) && x == "unix") |
589 | x == "unix") | ||
590 | return TRUE; | 603 | return TRUE; |
@@ -603,5 +616,6 @@ QMakeProject::isActiveConfig(const QString &x) | |||
603 | 616 | ||
617 | QRegExp re(x, FALSE, TRUE); | ||
604 | QString spec = Option::mkfile::qmakespec.right(Option::mkfile::qmakespec.length() - | 618 | QString spec = Option::mkfile::qmakespec.right(Option::mkfile::qmakespec.length() - |
605 | (Option::mkfile::qmakespec.findRev(QDir::separator())+1)); | 619 | (Option::mkfile::qmakespec.findRev(QDir::separator())+1)); |
606 | if(re.exactMatch(spec)) | 620 | if((regex && re.exactMatch(spec)) || (!regex && spec == x)) |
607 | return TRUE; | 621 | return TRUE; |
@@ -618,3 +632,3 @@ QMakeProject::isActiveConfig(const QString &x) | |||
618 | r = r.mid(r.findRev('/') + 1); | 632 | r = r.mid(r.findRev('/') + 1); |
619 | if(re.exactMatch(r)) | 633 | if((regex && re.exactMatch(r)) || (!regex && r == x)) |
620 | return TRUE; | 634 | return TRUE; |
@@ -627,2 +641,3 @@ QMakeProject::isActiveConfig(const QString &x) | |||
627 | for(QStringList::Iterator it = configs.begin(); it != configs.end(); ++it) { | 641 | for(QStringList::Iterator it = configs.begin(); it != configs.end(); ++it) { |
642 | if((regex && re.exactMatch((*it))) || (!regex && (*it) == x)) | ||
628 | if(re.exactMatch((*it))) | 643 | if(re.exactMatch((*it))) |
@@ -634,3 +649,3 @@ QMakeProject::isActiveConfig(const QString &x) | |||
634 | bool | 649 | bool |
635 | QMakeProject::doProjectTest(QString func, const QString ¶ms, QMap<QString, QStringList> &place) | 650 | QMakeProject::doProjectTest(const QString& func, const QString ¶ms, QMap<QString, QStringList> &place) |
636 | { | 651 | { |
@@ -646,3 +661,3 @@ QMakeProject::doProjectTest(QString func, const QString ¶ms, QMap<QString, Q | |||
646 | bool | 661 | bool |
647 | QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStringList> &place) | 662 | QMakeProject::doProjectTest(const QString& func, QStringList args, QMap<QString, QStringList> &place) |
648 | { | 663 | { |
@@ -656,2 +671,12 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin | |||
656 | return doProjectCheckReqs(args, place); | 671 | return doProjectCheckReqs(args, place); |
672 | } else if(func == "equals") { | ||
673 | if(args.count() != 2) { | ||
674 | fprintf(stderr, "%s:%d: equals(variable, value) requires two arguments.\n", parser.file.latin1(), | ||
675 | parser.line_no); | ||
676 | return FALSE; | ||
677 | } | ||
678 | QString value = args[1]; | ||
679 | if((value.left(1) == "\"" || value.left(1) == "'") && value.right(1) == value.left(1)) | ||
680 | value = value.mid(1, value.length()-2); | ||
681 | return vars[args[0]].join(" ") == value; | ||
657 | } else if(func == "exists") { | 682 | } else if(func == "exists") { |
@@ -693,3 +718,3 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin | |||
693 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { | 718 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { |
694 | if(regx.exactMatch((*it))) | 719 | if(regx.exactMatch((*it))) |
695 | return TRUE; | 720 | return TRUE; |
@@ -807,4 +832,7 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin | |||
807 | bool r = read(file.latin1(), place); | 832 | bool r = read(file.latin1(), place); |
808 | if(r) | 833 | if(r) |
809 | vars["QMAKE_INTERNAL_INCLUDED_FILES"].append(file); | 834 | vars["QMAKE_INTERNAL_INCLUDED_FILES"].append(file); |
835 | else | ||
836 | warn_msg(WarnParser, "%s:%d: Failure to include file %s.", | ||
837 | pi.file.latin1(), pi.line_no, file.latin1()); | ||
810 | parser = pi; | 838 | parser = pi; |
@@ -821,2 +849,7 @@ QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStrin | |||
821 | QString msg = args.first(); | 849 | QString msg = args.first(); |
850 | if((msg.startsWith("\"") || msg.startsWith("'")) && msg.endsWith(msg.left(1))) | ||
851 | msg = msg.mid(1, msg.length()-2); | ||
852 | msg.replace(QString("${QMAKE_FILE}"), parser.file.latin1()); | ||
853 | msg.replace(QString("${QMAKE_LINE_NUMBER}"), QString::number(parser.line_no)); | ||
854 | msg.replace(QString("${QMAKE_DATE}"), QDateTime::currentDateTime().toString()); | ||
822 | doVariableReplace(msg, place); | 855 | doVariableReplace(msg, place); |
@@ -859,3 +892,3 @@ QMakeProject::doProjectCheckReqs(const QStringList &deps, QMap<QString, QStringL | |||
859 | } else { | 892 | } else { |
860 | test = isActiveConfig(chk); | 893 | test = isActiveConfig(chk, TRUE); |
861 | } | 894 | } |
@@ -879,114 +912,164 @@ QMakeProject::doVariableReplace(QString &str, const QMap<QString, QStringList> & | |||
879 | { | 912 | { |
880 | for(int x = 0, rep; x < 5; x++) { | 913 | for(int var_begin, var_last=0; (var_begin = str.find("$$", var_last)) != -1; var_last = var_begin) { |
881 | QRegExp reg_var; | 914 | if(var_begin >= int( str.length() + 2 ) ) { |
882 | reg_var.setMinimal(TRUE); | 915 | break; |
883 | if( x == 0 ) //function blocked out by {}'s | 916 | } else if(var_begin != 0 && str[var_begin-1] == '\\') { |
884 | reg_var = QRegExp("\\$\\$\\{([a-zA-Z0-9_]*)\\((\\(.|(.*)\\)*)\\)\\}"); | 917 | str.replace(var_begin-1, 1, ""); |
885 | else if( x == 1 ) //variables blocked out by {}'s | 918 | var_begin += 1; |
886 | reg_var = QRegExp("\\$\\$\\{([a-zA-Z0-9_\\.-]*)\\}"); | 919 | continue; |
887 | else if(x == 2) //environment | 920 | } |
888 | reg_var = QRegExp("\\$\\$\\(([a-zA-Z0-9_\\.-]*)\\)"); | 921 | |
889 | else if(x == 3) //function | 922 | int var_incr = var_begin + 2; |
890 | reg_var = QRegExp("\\$\\$([a-zA-Z0-9_]*)\\((\\(.|(.*)\\)*)\\)"); | 923 | bool in_braces = FALSE, as_env = FALSE; |
891 | else if(x == 4) //normal variable | 924 | if(str[var_incr] == '{') { |
892 | reg_var = QRegExp("\\$\\$([a-zA-Z0-9_\\.-]*)"); | 925 | in_braces = TRUE; |
893 | while((rep = reg_var.search(str)) != -1) { | 926 | var_incr++; |
894 | QString replacement; | 927 | while(var_incr < int( str.length() ) && |
895 | if(x == 2) {//environment | 928 | (str[var_incr] == ' ' || str[var_incr] == '\t' || str[var_incr] == '\n')) |
896 | replacement = getenv(reg_var.cap(1)); | 929 | var_incr++; |
897 | } else if(x == 0 || x == 3) { //function | 930 | } |
898 | QStringList args = split_arg_list(reg_var.cap(2)); | 931 | if(str[var_incr] == '(') { |
899 | for(QStringList::Iterator arit = args.begin(); arit != args.end(); ++arit) { | 932 | as_env = TRUE; |
900 | (*arit) = (*arit).stripWhiteSpace(); // blah, get rid of space | 933 | var_incr++; |
901 | doVariableReplace((*arit), place); | 934 | } |
902 | } | 935 | QString val, args; |
903 | debug_msg(1, "Running function: %s( %s )", reg_var.cap(1).latin1(), args.join("::").latin1()); | 936 | while(var_incr < int( str.length() ) && |
904 | if(reg_var.cap(1).lower() == "member") { | 937 | (str[var_incr].isLetter() || str[var_incr].isNumber() || str[var_incr] == '.' || str[var_incr] == '_')) |
905 | if(args.count() < 1 || args.count() > 2) { | 938 | val += str[var_incr++]; |
906 | fprintf(stderr, "%s:%d: member(var, place) requires two arguments.\n", | 939 | if(as_env) { |
907 | parser.file.latin1(), parser.line_no); | 940 | if(str[var_incr] != ')') { |
908 | } else { | 941 | var_incr++; |
909 | uint pos = 0; | 942 | warn_msg(WarnParser, "%s:%d: Unterminated env-variable replacement '%s' (%s)", |
910 | if(args.count() == 2) | 943 | parser.file.latin1(), parser.line_no, |
911 | pos = args[1].toInt(); | 944 | str.mid(var_begin, QMAX(var_incr - var_begin, int(str.length()))).latin1(), str.latin1()); |
912 | const QStringList &var = place[varMap(args.first())]; | 945 | var_begin += var_incr; |
913 | if(var.count() >= pos) | 946 | continue; |
914 | replacement = var[pos]; | 947 | } |
915 | } | 948 | var_incr++; |
916 | } else if(reg_var.cap(1).lower() == "list") { | 949 | } else if(str[var_incr] == '(') { //args |
917 | if(args.count() != 1) { | 950 | for(int parens = 0; var_incr < int( str.length() ); var_incr++) { |
918 | fprintf(stderr, "%s:%d: list(vals) requires one" | 951 | if(str[var_incr] == '(') { |
919 | "argument.\n", parser.file.latin1(), parser.line_no); | 952 | parens++; |
920 | } else { | 953 | if(parens == 1) |
921 | static int x = 0; | 954 | continue; |
922 | replacement.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++); | 955 | } else if(str[var_incr] == ')') { |
923 | (*((QMap<QString, QStringList>*)&place))[replacement] = split_value_list(args.first()); | 956 | parens--; |
924 | } | 957 | if(!parens) { |
925 | } else if(reg_var.cap(1).lower() == "join") { | 958 | var_incr++; |
926 | if(args.count() < 1 || args.count() > 4) { | 959 | break; |
927 | fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four" | ||
928 | "arguments.\n", parser.file.latin1(), parser.line_no); | ||
929 | } else { | ||
930 | QString glue, before, after; | ||
931 | if(args.count() >= 2) | ||
932 | glue = args[1].replace("\"", "" ); | ||
933 | if(args.count() >= 3) | ||
934 | before = args[2].replace("\"", "" ); | ||
935 | if(args.count() == 4) | ||
936 | after = args[3].replace("\"", "" ); | ||
937 | const QStringList &var = place[varMap(args.first())]; | ||
938 | if(!var.isEmpty()) | ||
939 | replacement = before + var.join(glue) + after; | ||
940 | } | 960 | } |
941 | } else if(reg_var.cap(1).lower() == "find") { | 961 | } |
942 | if(args.count() != 2) { | 962 | args += str[var_incr]; |
943 | fprintf(stderr, "%s:%d find(var, str) requires two arguments\n", | 963 | } |
944 | parser.file.latin1(), parser.line_no); | 964 | } |
945 | } else { | 965 | if(var_incr > int( str.length() ) || (in_braces && str[var_incr] != '}')) { |
946 | QRegExp regx(args[1]); | 966 | var_incr++; |
947 | const QStringList &var = place[varMap(args.first())]; | 967 | warn_msg(WarnParser, "%s:%d: Unterminated variable replacement '%s' (%s)", |
948 | for(QStringList::ConstIterator vit = var.begin(); | 968 | parser.file.latin1(), parser.line_no, |
949 | vit != var.end(); ++vit) { | 969 | str.mid(var_begin, QMAX(var_incr - var_begin, int( str.length() ))).latin1(), str.latin1()); |
950 | if(regx.search(*vit) != -1) { | 970 | var_begin += var_incr; |
951 | if(!replacement.isEmpty()) | 971 | continue; |
952 | replacement += " "; | 972 | } else if(in_braces) { |
953 | replacement += (*vit); | 973 | var_incr++; |
954 | } | 974 | } |
975 | |||
976 | QString replacement; | ||
977 | if(as_env) { | ||
978 | replacement = getenv(val); | ||
979 | } else if(args.isEmpty()) { | ||
980 | if(val.left(1) == ".") | ||
981 | replacement = ""; | ||
982 | else if(val == "LITERAL_WHITESPACE") | ||
983 | replacement = "\t"; | ||
984 | else | ||
985 | replacement = place[varMap(val)].join(" "); | ||
986 | } else { | ||
987 | QStringList arg_list = split_arg_list(args); | ||
988 | for(QStringList::Iterator arit = arg_list.begin(); arit != arg_list.end(); ++arit) { | ||
989 | (*arit) = (*arit).stripWhiteSpace(); // blah, get rid of space | ||
990 | doVariableReplace((*arit), place); | ||
991 | } | ||
992 | debug_msg(1, "Running function: %s( %s )", val.latin1(), arg_list.join("::").latin1()); | ||
993 | if(val.lower() == "member") { | ||
994 | if(arg_list.count() < 1 || arg_list.count() > 2) { | ||
995 | fprintf(stderr, "%s:%d: member(var, place) requires two arguments.\n", | ||
996 | parser.file.latin1(), parser.line_no); | ||
997 | } else { | ||
998 | uint pos = 0; | ||
999 | if(arg_list.count() == 2) | ||
1000 | pos = arg_list[1].toInt(); | ||
1001 | const QStringList &var = place[varMap(arg_list.first())]; | ||
1002 | if(var.count() >= pos) | ||
1003 | replacement = var[pos]; | ||
1004 | } | ||
1005 | } else if(val.lower() == "list") { | ||
1006 | static int x = 0; | ||
1007 | replacement.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++); | ||
1008 | QStringList &lst = (*((QMap<QString, QStringList>*)&place))[replacement]; | ||
1009 | lst.clear(); | ||
1010 | for(QStringList::ConstIterator arg_it = arg_list.begin(); | ||
1011 | arg_it != arg_list.end(); ++arg_it) | ||
1012 | lst += split_value_list((*arg_it)); | ||
1013 | } else if(val.lower() == "join") { | ||
1014 | if(arg_list.count() < 1 || arg_list.count() > 4) { | ||
1015 | fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four" | ||
1016 | "arguments.\n", parser.file.latin1(), parser.line_no); | ||
1017 | } else { | ||
1018 | QString glue, before, after; | ||
1019 | if(arg_list.count() >= 2) | ||
1020 | glue = arg_list[1].replace("\"", "" ); | ||
1021 | if(arg_list.count() >= 3) | ||
1022 | before = arg_list[2].replace("\"", "" ); | ||
1023 | if(arg_list.count() == 4) | ||
1024 | after = arg_list[3].replace("\"", "" ); | ||
1025 | const QStringList &var = place[varMap(arg_list.first())]; | ||
1026 | if(!var.isEmpty()) | ||
1027 | replacement = before + var.join(glue) + after; | ||
1028 | } | ||
1029 | } else if(val.lower() == "find") { | ||
1030 | if(arg_list.count() != 2) { | ||
1031 | fprintf(stderr, "%s:%d find(var, str) requires two arguments\n", | ||
1032 | parser.file.latin1(), parser.line_no); | ||
1033 | } else { | ||
1034 | QRegExp regx(arg_list[1]); | ||
1035 | const QStringList &var = place[varMap(arg_list.first())]; | ||
1036 | for(QStringList::ConstIterator vit = var.begin(); | ||
1037 | vit != var.end(); ++vit) { | ||
1038 | if(regx.search(*vit) != -1) { | ||
1039 | if(!replacement.isEmpty()) | ||
1040 | replacement += " "; | ||
1041 | replacement += (*vit); | ||
955 | } | 1042 | } |
956 | } | 1043 | } |
957 | } else if(reg_var.cap(1).lower() == "system") { | 1044 | } |
958 | if(args.count() != 1) { | 1045 | } else if(val.lower() == "system") { |
959 | fprintf(stderr, "%s:%d system(execut) requires one argument\n", | 1046 | if(arg_list.count() != 1) { |
960 | parser.file.latin1(), parser.line_no); | 1047 | fprintf(stderr, "%s:%d system(execut) requires one argument\n", |
961 | } else { | 1048 | parser.file.latin1(), parser.line_no); |
962 | char buff[256]; | 1049 | } else { |
963 | FILE *proc = QT_POPEN(args.join(" ").latin1(), "r"); | 1050 | char buff[256]; |
964 | while(proc && !feof(proc)) { | 1051 | FILE *proc = QT_POPEN(arg_list.join(" ").latin1(), "r"); |
965 | int read_in = fread(buff, 1, 255, proc); | 1052 | while(proc && !feof(proc)) { |
966 | if(!read_in) | 1053 | int read_in = fread(buff, 1, 255, proc); |
967 | break; | 1054 | if(!read_in) |
968 | for(int i = 0; i < read_in; i++) { | 1055 | break; |
969 | if(buff[i] == '\n' || buff[i] == '\t') | 1056 | for(int i = 0; i < read_in; i++) { |
970 | buff[i] = ' '; | 1057 | if(buff[i] == '\n' || buff[i] == '\t') |
971 | } | 1058 | buff[i] = ' '; |
972 | buff[read_in] = '\0'; | ||
973 | replacement += buff; | ||
974 | } | 1059 | } |
1060 | buff[read_in] = '\0'; | ||
1061 | replacement += buff; | ||
975 | } | 1062 | } |
976 | } else { | ||
977 | fprintf(stderr, "%s:%d: Unknown replace function: %s\n", | ||
978 | parser.file.latin1(), parser.line_no, reg_var.cap(1).latin1()); | ||
979 | } | 1063 | } |
980 | } else { //variable | 1064 | } else { |
981 | if(reg_var.cap(1).left(1) == ".") | 1065 | fprintf(stderr, "%s:%d: Unknown replace function: %s\n", |
982 | replacement = ""; | 1066 | parser.file.latin1(), parser.line_no, val.latin1()); |
983 | else if(reg_var.cap(1) == "LITERAL_WHITESPACE") | ||
984 | replacement = "\t"; | ||
985 | else | ||
986 | replacement = place[varMap(reg_var.cap(1))].join(" "); | ||
987 | } | 1067 | } |
988 | debug_msg(2, "Project parser: %d (%s) :: %s -> %s", x, str.latin1(), | ||
989 | reg_var.capturedTexts().join("::").latin1(), replacement.latin1()); | ||
990 | str.replace(rep, reg_var.matchedLength(), replacement); | ||
991 | } | 1068 | } |
1069 | //actually do replacement now.. | ||
1070 | int mlen = var_incr - var_begin; | ||
1071 | debug_msg(2, "Project Parser [var replace]: '%s' :: %s -> %s", str.latin1(), | ||
1072 | str.mid(var_begin, mlen).latin1(), replacement.latin1()); | ||
1073 | str.replace(var_begin, mlen, replacement); | ||
1074 | var_begin += replacement.length(); | ||
992 | } | 1075 | } |