summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-10-02 12:59:32 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-10-02 12:59:32 +0900
commita765645b458735ad77fe606f42e9d49c33055b97 (patch)
tree69068727a1eb813fa4b60378becd7a74c922ab26
parentae0277944bdd33ddd492b1c47f65bd77c89e585e (diff)
add a real primitive new handler for mrk
-rw-r--r--mrk.c168
1 files changed, 163 insertions, 5 deletions
diff --git a/mrk.c b/mrk.c
index b6fbc59..23b4595 100644
--- a/mrk.c
+++ b/mrk.c
@@ -1420,6 +1420,163 @@ package_qry(int op, const char *opdat)
1420 return 1; 1420 return 1;
1421} 1421}
1422 1422
1423static int
1424package_file_isbin(const char *file)
1425{
1426 const char *p;
1427
1428 p = strchr(file, '.');
1429 if (p)
1430 {
1431 if (!strcasecmp(p, ".png")) return 1;
1432 if (!strcasecmp(p, ".jpg")) return 1;
1433 if (!strcasecmp(p, ".edj")) return 1;
1434 if (!strcasecmp(p, ".gif")) return 1;
1435 if (!strcasecmp(p, ".bmp")) return 1;
1436 }
1437 return 0;
1438}
1439
1440static Eina_Bool
1441string_rep(const Eina_Hash *hash, const void *key, void *data, void *fdata)
1442{
1443 eina_strbuf_replace_all(fdata, key, data);
1444 return EINA_TRUE;
1445}
1446
1447static int
1448package_dir_dup(const char *src, const char *dst, Eina_Hash *vars)
1449{
1450 char tmp[4096];
1451 char tmp2[4096];
1452 Eina_Strbuf *dstsbuf;
1453
1454 dstsbuf = eina_strbuf_new();
1455 if (!dstsbuf) return 0;
1456 eina_strbuf_append(dstsbuf, dst);
1457 eina_hash_foreach(vars, string_rep, dstsbuf);
1458 if (ecore_file_is_dir(src))
1459 {
1460 Eina_List *files;
1461 char *s;
1462
1463 ecore_file_mkdir(eina_strbuf_string_get(dstsbuf));
1464 files = ecore_file_ls(src);
1465 EINA_LIST_FREE(files, s)
1466 {
1467 if (s[0] != '.')
1468 {
1469 snprintf(tmp, sizeof(tmp), "%s/%s", src, s);
1470 snprintf(tmp2, sizeof(tmp2), "%s/%s", eina_strbuf_string_get(dstsbuf), s);
1471 package_dir_dup(tmp, tmp2, vars);
1472 }
1473 free(s);
1474 }
1475 }
1476 else
1477 {
1478 if (package_file_isbin(src))
1479 ecore_file_cp(src, eina_strbuf_string_get(dstsbuf));
1480 else
1481 {
1482 FILE *fsrc, *fdst;
1483
1484 fsrc = fopen(src, "rb");
1485 fdst = fopen(eina_strbuf_string_get(dstsbuf), "wb");
1486 if ((fsrc) && (fdst))
1487 {
1488 long size;
1489
1490 fseek(fsrc, 0, SEEK_END);
1491 size = ftell(fsrc);
1492 fseek(fsrc, 0, SEEK_SET);
1493 if (size > 0)
1494 {
1495 char *buf = malloc(size + 1);
1496
1497 if (buf)
1498 {
1499 Eina_Strbuf *tmpsbuf;
1500
1501 tmpsbuf = eina_strbuf_new();
1502 if (tmpsbuf)
1503 {
1504 fread(buf, size, 1, fsrc);
1505 buf[size] = 0;
1506 eina_strbuf_append(tmpsbuf, buf);
1507 eina_hash_foreach(vars, string_rep, tmpsbuf);
1508 fwrite(eina_strbuf_string_get(tmpsbuf),
1509 eina_strbuf_length_get(tmpsbuf),
1510 1, fdst);
1511 eina_strbuf_free(tmpsbuf);
1512 }
1513 free(buf);
1514 }
1515 }
1516 }
1517 if (fsrc) fclose(fsrc);
1518 if (fdst) fclose(fdst);
1519 }
1520 }
1521 eina_strbuf_free(dstsbuf);
1522 return 1;
1523}
1524
1525static int
1526package_gen(const char *tmpldir, const char *tmpl, Eina_Hash *vars)
1527{
1528 char tmp[4096];
1529 char tmp2[4096];
1530 const char *domain;
1531
1532 domain = eina_hash_find(vars, "@APPDOM@");
1533 ecore_file_mkdir(domain);
1534 snprintf(tmp, sizeof(tmp), "%s/apps/%s", tmpldir, tmpl);
1535 package_dir_dup(tmp, domain, vars);
1536 snprintf(tmp, sizeof(tmp), "%s/licenses/%s",
1537 tmpldir, eina_hash_find(vars, "@APPCOPY@"));
1538 snprintf(tmp2, sizeof(tmp2), "%s/COPYING", domain);
1539 ecore_file_cp(tmp, tmp2);
1540}
1541
1542static int
1543package_new(void)
1544{
1545 Eina_Hash *vars = eina_hash_string_superfast_new(NULL);
1546 char tmp[4096];
1547
1548 if (!vars) return 0;
1549 printf("App Name: (e.g. Hello)\n");
1550 if (scanf("%500s", tmp) <= 0) return 0;
1551 eina_hash_add(vars, "@APPNAME@", eina_stringshare_add(tmp));
1552 printf("App Domain: (e.g. hello)\n");
1553 if (scanf("%500s", tmp) <= 0) return 0;
1554 eina_hash_add(vars, "@APPDOM@", eina_stringshare_add(tmp));
1555 printf("App Version: (e.g. 1.0.0)\n");
1556 if (scanf("%150s", tmp) <= 0) return 0;
1557 eina_hash_add(vars, "@APPVER@", eina_stringshare_add(tmp));
1558 printf("App License: (e.g. BSD-2 | GPL2 | APACHE | GPL3)\n");
1559 if (scanf("%20s", tmp) <= 0) return 0;
1560 eina_hash_add(vars, "@APPCOPY@", eina_stringshare_add(tmp));
1561 printf("App Brief Description: (1 line)\n");
1562 if (scanf("%400s", tmp) <= 0) return 0;
1563 eina_hash_add(vars, "@APPDESC@", eina_stringshare_add(tmp));
1564 printf("App Categories: (e.g. media)\n");
1565 if (scanf("%1000s", tmp) <= 0) return 0;
1566 eina_hash_add(vars, "@APPCATEGORIES@", eina_stringshare_add(tmp));
1567 printf("App Tags: (e.g. video audio media film movies music player)\n");
1568 if (scanf("%4000s", tmp) <= 0) return 0;
1569 eina_hash_add(vars, "@APPTAGS@", eina_stringshare_add(tmp));
1570 printf("Developer Name + E-Mail: Bob Jones <bob@bob.com>\n");
1571 if (scanf("%1000s", tmp) <= 0) return 0;
1572 eina_hash_add(vars, "@DEVMAIL@", eina_stringshare_add(tmp));
1573 printf("App EFL Minimum Version: (e.g. 1.11)\n");
1574 if (scanf("%50s", tmp) <= 0) return 0;
1575 eina_hash_add(vars, "@EFLVER@", eina_stringshare_add(tmp));
1576 package_gen("/home/raster/C/marrakesh/tmpl", "default", vars);
1577 return 1;
1578}
1579
1423int 1580int
1424main(int argc, char **argv) 1581main(int argc, char **argv)
1425{ 1582{
@@ -1432,21 +1589,21 @@ main(int argc, char **argv)
1432 if (argc < 2) 1589 if (argc < 2)
1433 { 1590 {
1434 printf("sub commands:\n" 1591 printf("sub commands:\n"
1592 " new\n"
1435 " build\n" 1593 " build\n"
1436 " src\n"
1437 " bin\n" 1594 " bin\n"
1595 " check\n"
1596 " src\n"
1438 " extract FILE\n" 1597 " extract FILE\n"
1439 " inst FILE\n" 1598 " inst FILE\n"
1440 " clean\n"
1441 " rm PKGNAME\n" 1599 " rm PKGNAME\n"
1442 " rel [FILE]\n" 1600 " rel [FILE]\n"
1443 " down PKGNAME\n" 1601 " down PKGNAME\n"
1444 " get PKGNAME\n" 1602 " get PKGNAME\n"
1603 " getsrc PKGNAME\n"
1604 " clean\n"
1445 " list [CATEGORY]\n" 1605 " list [CATEGORY]\n"
1446 " search KEY1 [KEY2] [KEY3] [...]\n" 1606 " search KEY1 [KEY2] [KEY3] [...]\n"
1447// " new\n"
1448// " getsrc\n"
1449 " check\n"
1450 "\n"); 1607 "\n");
1451 return -1; 1608 return -1;
1452 } 1609 }
@@ -1562,6 +1719,7 @@ main(int argc, char **argv)
1562 } 1719 }
1563 else if (!strcmp(argv[1], "new")) 1720 else if (!strcmp(argv[1], "new"))
1564 { 1721 {
1722 package_new();
1565 } 1723 }
1566 else if (!strcmp(argv[1], "getsrc")) 1724 else if (!strcmp(argv[1], "getsrc"))
1567 { 1725 {