Changeset ac9b4f2 in mainline
- Timestamp:
- 2024-08-20T23:43:53Z (5 months ago)
- Branches:
- master
- Children:
- f8cb1bc5
- Parents:
- bff8619
- Location:
- uspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/taskbar.sif
rbff8619 rac9b4f2 1 [sif](){[entries](){[entry]([caption]=[~N~avigator][cmd]=[/app/nav][terminal]=[y]){}[entry]([caption]=[Text ~E~ditor][cmd]=[/app/edit][terminal]=[y]){}[entry]([caption]=[Co~m~mand Line][cmd]=[/app/bdsh][terminal]=[y]){}[entry]([caption]=[~C~alculator][cmd]=[/app/calculator -d %d][terminal]=[n]){}[entry]([caption]=[~I~mage Viewer][cmd]=[/app/viewer -d %d][terminal]=[n]){}[entry]([separator]=[y]){}[entry]([caption]=[~U~I Demo][cmd]=[/app/uidemo -d %d][terminal]=[n]){}[entry]([caption]=[~G~FX Demo][cmd]=[/app/gfxdemo -d %d ui][terminal]=[n]){}[entry]([caption]=[~B~arber Pole][cmd]=[/app/barber -d %d][terminal]=[n]){}[entry]([caption]=[~T~etris][cmd]=[/app/tetris][terminal]=[y]){}[entry]([separator]=[y]){}[entry]([caption]=[~D~isplay Configuration][cmd]=[/app/display-cfg -d %d][terminal]=[n]){}[entry]([caption]=[Ta~s~kbar Configuration][cmd]=[/app/taskbar-cfg -d %d][terminal]=[n]){}[entry]([separator]=[y]){}[entry]([caption]=[Tas~k~ Monitor (top)][cmd]=[/app/top][terminal]=[y]){}[entry]([caption]=[~F~disk Disk Editor][cmd]=[/app/fdisk][terminal]=[y]){}[entry]([separator]=[y]){}[entry]([caption]=[~A~bout HelenOS][cmd]=[/app/aboutos -d %d][terminal]=[n]){}}} 1 <sif> 2 <entries> 3 <entry caption="~N~avigator" cmd="/app/nav" terminal="y"> 4 </entry> 5 <entry caption="Text ~E~ditor" cmd="/app/edit" terminal="y"> 6 </entry> 7 <entry caption="Co~m~mand Line" cmd="/app/bdsh" terminal="y"> 8 </entry> 9 <entry caption="~C~alculator" cmd="/app/calculator -d %d" terminal="n"> 10 </entry> 11 <entry caption="~I~mage Viewer" cmd="/app/viewer -d %d" terminal="n"> 12 </entry> 13 <entry separator="y"> 14 </entry> 15 <entry caption="~U~I Demo" cmd="/app/uidemo -d %d" terminal="n"> 16 </entry> 17 <entry caption="~G~FX Demo" cmd="/app/gfxdemo -d %d ui" terminal="n"> 18 </entry> 19 <entry caption="~B~arber Pole" cmd="/app/barber -d %d" terminal="n"> 20 </entry> 21 <entry caption="~T~etris" cmd="/app/tetris" terminal="y"> 22 </entry> 23 <entry separator="y"> 24 </entry> 25 <entry caption="~D~isplay Configuration" cmd="/app/display-cfg -d %d" terminal="n"> 26 </entry> 27 <entry caption="Ta~s~kbar Configuration" cmd="/app/taskbar-cfg -d %d" terminal="n"> 28 </entry> 29 <entry separator="y"> 30 </entry> 31 <entry caption="Tas~k~ Monitor (top)" cmd="/app/top" terminal="y"> 32 </entry> 33 <entry caption="~F~disk Disk Editor" cmd="/app/fdisk" terminal="y"> 34 </entry> 35 <entry separator="y"> 36 </entry> 37 <entry caption="~A~bout HelenOS" cmd="/app/aboutos -d %d" terminal="n"> 38 </entry> 39 </entries> 40 </sif> -
uspace/lib/sif/src/sif.c
rbff8619 rac9b4f2 45 45 #include <adt/list.h> 46 46 #include <adt/odict.h> 47 #include <ctype.h> 47 48 #include <errno.h> 49 #include <stdbool.h> 48 50 #include <stdio.h> 49 51 #include <stdlib.h> … … 53 55 54 56 static errno_t sif_export_node(sif_node_t *, FILE *); 55 static errno_t sif_import_node(sif_node_t *, FILE *, sif_node_t ** );57 static errno_t sif_import_node(sif_node_t *, FILE *, sif_node_t **, bool *); 56 58 static sif_attr_t *sif_node_first_attr(sif_node_t *); 57 59 static sif_attr_t *sif_node_next_attr(sif_attr_t *); … … 60 62 static int sif_attr_cmp(void *, void *); 61 63 64 /** Determine if character can start a name. 65 * 66 * @param c Character 67 * @return @c true iff the character can start a name 68 */ 69 static bool sif_is_name_start_char(char c) 70 { 71 return isalpha(c) || c == '_'; 72 } 73 74 /** Determine if character can continue a name. 75 * 76 * @param c Character 77 * @return @c true iff the character can continue a name 78 */ 79 static bool sif_is_name_char(char c) 80 { 81 return isalnum(c) || c == '-' || c == '.'; 82 } 83 62 84 /** Create new SIF node. 63 85 * … … 205 227 sif_node_t *root = NULL; 206 228 errno_t rc; 229 bool endtag; 207 230 FILE *f; 208 231 … … 223 246 } 224 247 225 rc = sif_import_node(NULL, f, &root );226 if (rc != EOK )248 rc = sif_import_node(NULL, f, &root, &endtag); 249 if (rc != EOK || endtag == true) 227 250 goto error; 228 251 … … 343 366 if (rc != EOK) 344 367 goto error; 345 346 if (fputc('\n', f) == EOF) {347 rc = EIO;348 goto error;349 }350 368 351 369 if (fflush(f) == EOF) { … … 563 581 } 564 582 565 /** Export stringto file.566 * 567 * Export string to file (the string is bracketed and escaped).583 /** Export node name to file. 584 * 585 * Export node name to file. 568 586 * 569 587 * @param str String … … 571 589 * @return EOK on success, EIO on I/O error 572 590 */ 591 static errno_t sif_export_name(const char *str, FILE *f) 592 { 593 if (fputs(str, f) == EOF) 594 return EIO; 595 596 return EOK; 597 } 598 599 /** Export string to file. 600 * 601 * Export string to file (the string is double-quoted and escaped). 602 * 603 * @param str String 604 * @param f File 605 * @return EOK on success, EIO on I/O error 606 */ 573 607 static errno_t sif_export_string(const char *str, FILE *f) 574 608 { 575 609 const char *cp; 576 610 577 if (fputc(' [', f) == EOF)611 if (fputc('"', f) == EOF) 578 612 return EIO; 579 613 580 614 cp = str; 581 615 while (*cp != '\0') { 582 if (*cp == ']' || *cp == '\\') { 583 if (fputc('\\', f) == EOF) 616 if (*cp == '<') { 617 if (fputs("<", f) == EOF) 618 return EIO; 619 } else if (*cp == '"') { 620 if (fputs(""", f) == EOF) 621 return EIO; 622 } else { 623 if (fputc(*cp, f) == EOF) 584 624 return EIO; 585 625 } 586 if (fputc(*cp, f) == EOF) 626 627 ++cp; 628 } 629 630 if (fputc('"', f) == EOF) 631 return EIO; 632 633 return EOK; 634 } 635 636 /** Read characters from file, make sure they match the specified sequence. 637 * 638 * @param f File 639 * @param chars Expected sequence of characters to be read 640 * 641 * @return EOK on success, EIO on I/O error or mismatch 642 */ 643 static errno_t sif_get_verify_chars(FILE *f, const char *chars) 644 { 645 const char *cp; 646 char c; 647 648 cp = chars; 649 while (*cp != '\0') { 650 c = fgetc(f); 651 if (c != *cp) 587 652 return EIO; 588 653 ++cp; 589 654 } 590 655 591 if (fputc(']', f) == EOF) 592 return EIO; 593 594 return EOK; 595 } 596 597 /** Import string from file. 598 * 599 * Import string from file (the string in the file must be 600 * properly bracketed and escaped). 601 * 656 return EOK; 657 } 658 659 /** Import name from file. 660 * * 602 661 * @param f File 603 662 * @param rstr Place to store pointer to newly allocated string 604 663 * @return EOK on success, EIO on I/O error 605 664 */ 606 static errno_t sif_import_ string(FILE *f, char **rstr)665 static errno_t sif_import_name(FILE *f, char **rstr) 607 666 { 608 667 char *str; … … 620 679 621 680 c = fgetc(f); 622 if ( c != '[') {681 if (!sif_is_name_start_char(c)) { 623 682 rc = EIO; 624 683 goto error; … … 626 685 627 686 while (true) { 628 c = fgetc(f);629 if (c == EOF) {630 rc = EIO;631 goto error;632 }633 634 if (c == ']')635 break;636 637 if (c == '\\') {638 c = fgetc(f);639 if (c == EOF) {640 rc = EIO;641 goto error;642 }643 }644 645 687 if (sidx >= str_size) { 646 688 str_size *= 2; … … 655 697 656 698 str[sidx++] = c; 699 700 c = fgetc(f); 701 if (!sif_is_name_char(c)) 702 break; 703 } 704 705 ungetc(c, f); 706 707 str[sidx] = '\0'; 708 *rstr = str; 709 return EOK; 710 error: 711 free(str); 712 return rc; 713 } 714 715 /** Import string from file. 716 * 717 * Import string from file (the string in the file must be 718 * properly quoted and escaped). 719 * 720 * @param f File 721 * @param rstr Place to store pointer to newly allocated string 722 * @return EOK on success, EIO on I/O error 723 */ 724 static errno_t sif_import_string(FILE *f, char **rstr) 725 { 726 char *str; 727 char *nstr; 728 size_t str_size; 729 size_t sidx; 730 int c; 731 errno_t rc; 732 733 str_size = 1; 734 sidx = 0; 735 str = malloc(str_size + 1); 736 if (str == NULL) 737 return ENOMEM; 738 739 c = fgetc(f); 740 if (c != '"') { 741 rc = EIO; 742 goto error; 743 } 744 745 while (true) { 746 c = fgetc(f); 747 if (c == EOF) { 748 rc = EIO; 749 goto error; 750 } 751 752 if (c == '"') 753 break; 754 755 if (c == '&') { 756 c = fgetc(f); 757 if (c == EOF) { 758 rc = EIO; 759 goto error; 760 } 761 762 if (c == 'q') { 763 rc = sif_get_verify_chars(f, "uot;"); 764 if (rc != EOK) 765 goto error; 766 } else if (c == 'l') { 767 rc = sif_get_verify_chars(f, "t;"); 768 if (rc != EOK) 769 goto error; 770 } else { 771 rc = EIO; 772 goto error; 773 } 774 } 775 776 if (sidx >= str_size) { 777 str_size *= 2; 778 nstr = realloc(str, str_size + 1); 779 if (nstr == NULL) { 780 rc = ENOMEM; 781 goto error; 782 } 783 784 str = nstr; 785 } 786 787 str[sidx++] = c; 657 788 } 658 789 … … 680 811 int c; 681 812 682 rc = sif_import_ string(f, &aname);813 rc = sif_import_name(f, &aname); 683 814 if (rc != EOK) 684 815 goto error; … … 723 854 errno_t rc; 724 855 725 rc = sif_export_ string(attr->aname, f);856 rc = sif_export_name(attr->aname, f); 726 857 if (rc != EOK) 727 858 return rc; … … 749 880 sif_node_t *child; 750 881 751 rc = sif_export_string(node->ntype, f); 882 if (fputc('<', f) == EOF) 883 return EIO; 884 885 rc = sif_export_name(node->ntype, f); 752 886 if (rc != EOK) 753 887 return rc; … … 755 889 /* Attributes */ 756 890 757 if (fputc('(', f) == EOF)758 return EIO;759 760 891 attr = sif_node_first_attr(node); 761 892 while (attr != NULL) { 893 if (fputc(' ', f) == EOF) 894 return EIO; 895 762 896 rc = sif_export_attr(attr, f); 763 897 if (rc != EOK) … … 767 901 } 768 902 769 if (fput c(')', f) == EOF)903 if (fputs(">\n", f) == EOF) 770 904 return EIO; 771 905 772 906 /* Child nodes */ 773 774 if (fputc('{', f) == EOF)775 return EIO;776 907 777 908 child = sif_node_first_child(node); … … 784 915 } 785 916 786 if (fputc('}', f) == EOF) 917 if (fputs("</", f) == EOF) 918 return EIO; 919 920 rc = sif_export_name(node->ntype, f); 921 if (rc != EOK) 922 return rc; 923 924 if (fputs(">\n", f) == EOF) 787 925 return EIO; 788 926 … … 795 933 * @param f File 796 934 * @param rnode Place to store pointer to imported node 935 * @param rendtag Place to store @c true iff end tag is encountered 797 936 * @return EOK on success, EIO on I/O error 798 937 */ 799 static errno_t sif_import_node(sif_node_t *parent, FILE *f, sif_node_t **rnode) 938 static errno_t sif_import_node(sif_node_t *parent, FILE *f, sif_node_t **rnode, 939 bool *rendtag) 800 940 { 801 941 errno_t rc; … … 803 943 sif_node_t *child; 804 944 sif_attr_t *attr = NULL; 945 bool endtag; 946 bool cendtag; 805 947 char *ntype; 806 948 int c; … … 810 952 return ENOMEM; 811 953 812 rc = sif_import_string(f, &ntype); 954 c = fgetc(f); 955 while (isspace(c)) 956 c = fgetc(f); 957 958 if (c != '<') { 959 rc = EIO; 960 goto error; 961 } 962 963 c = fgetc(f); 964 if (c == '/') { 965 endtag = true; 966 } else { 967 endtag = false; 968 ungetc(c, f); 969 } 970 971 rc = sif_import_name(f, &ntype); 813 972 if (rc != EOK) 814 973 goto error; … … 817 976 818 977 /* Attributes */ 819 820 c = fgetc(f);821 if (c != '(') {822 rc = EIO;823 goto error;824 }825 978 826 979 c = fgetc(f); … … 830 983 } 831 984 832 while (c != ')') { 985 while (c != '>') { 986 /* End tags cannot have attributes */ 987 if (endtag) { 988 rc = EIO; 989 goto error; 990 } 991 992 while (isspace(c)) 993 c = fgetc(f); 833 994 ungetc(c, f); 834 995 … … 848 1009 /* Child nodes */ 849 1010 850 c = fgetc(f); 851 if (c != '{') { 852 rc = EIO; 853 goto error; 854 } 855 856 c = fgetc(f); 857 if (c == EOF) { 858 rc = EIO; 859 goto error; 860 } 861 862 while (c != '}') { 863 ungetc(c, f); 864 865 rc = sif_import_node(node, f, &child); 866 if (rc != EOK) 867 goto error; 868 869 list_append(&child->lparent, &node->children); 870 871 c = fgetc(f); 872 if (c == EOF) { 873 rc = EIO; 874 goto error; 1011 if (!endtag) { 1012 while (true) { 1013 rc = sif_import_node(node, f, &child, &cendtag); 1014 if (rc != EOK) 1015 goto error; 1016 1017 if (cendtag) { 1018 sif_node_delete(child); 1019 break; 1020 } 1021 1022 list_append(&child->lparent, &node->children); 875 1023 } 876 1024 } 877 1025 878 1026 *rnode = node; 1027 *rendtag = endtag; 879 1028 return EOK; 880 1029 error:
Note:
See TracChangeset
for help on using the changeset viewer.