Mercurial > pidgin
comparison src/util.c @ 2382:569ae9f2bb89
[gaim-migrate @ 2395]
big reorg of code. list.c contains 0 gtk.
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Fri, 28 Sep 2001 07:46:36 +0000 |
| parents | cacaf7ace3a5 |
| children | 520257562955 |
comparison
equal
deleted
inserted
replaced
| 2381:427ccd7dfdd2 | 2382:569ae9f2bb89 |
|---|---|
| 714 } | 714 } |
| 715 cpy[cnt] = '\0'; | 715 cpy[cnt] = '\0'; |
| 716 return (cpy); | 716 return (cpy); |
| 717 } | 717 } |
| 718 | 718 |
| 719 | |
| 720 | |
| 721 /* remove leading whitespace from a string */ | |
| 722 char *remove_spaces(char *str) | |
| 723 { | |
| 724 int i; | |
| 725 char *new; | |
| 726 | |
| 727 if (str == NULL) | |
| 728 return NULL; | |
| 729 | |
| 730 i = strspn(str, " \t\n\r\f"); | |
| 731 new = &str[i]; | |
| 732 | |
| 733 return new; | |
| 734 } | |
| 735 | |
| 736 | |
| 737 /* translate an AIM 3 buddylist (*.lst) to a GAIM buddylist */ | |
| 738 void translate_lst(FILE *src_fp, char *dest) | |
| 739 { | |
| 740 char line[BUF_LEN], *line2; | |
| 741 char *name; | |
| 742 int i; | |
| 743 | |
| 744 sprintf(dest, "m 1\n"); | |
| 745 | |
| 746 while (fgets(line, BUF_LEN, src_fp)) { | |
| 747 line2 = remove_spaces(line); | |
| 748 if (strstr(line2, "group") == line2) { | |
| 749 name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 750 strcat(dest, "g "); | |
| 751 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 752 if (name[i] != '\"') | |
| 753 strncat(dest, &name[i], 1); | |
| 754 strcat(dest, "\n"); | |
| 755 } | |
| 756 if (strstr(line2, "buddy") == line2) { | |
| 757 name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 758 strcat(dest, "b "); | |
| 759 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 760 if (name[i] != '\"') | |
| 761 strncat(dest, &name[i], 1); | |
| 762 strcat(dest, "\n"); | |
| 763 } | |
| 764 } | |
| 765 | |
| 766 return; | |
| 767 } | |
| 768 | |
| 769 | |
| 770 /* translate an AIM 4 buddylist (*.blt) to GAIM format */ | |
| 771 void translate_blt(FILE *src_fp, char *dest) | |
| 772 { | |
| 773 int i; | |
| 774 char line[BUF_LEN]; | |
| 775 char *buddy; | |
| 776 | |
| 777 sprintf(dest, "m 1\n"); | |
| 778 | |
| 779 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
| 780 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
| 781 | |
| 782 while (1) { | |
| 783 fgets(line, BUF_LEN, src_fp); | |
| 784 if (strchr(line, '}') != NULL) | |
| 785 break; | |
| 786 | |
| 787 /* Syntax starting with "<group> {" */ | |
| 788 if (strchr(line, '{') != NULL) { | |
| 789 strcat(dest, "g "); | |
| 790 buddy = remove_spaces(strtok(line, "{")); | |
| 791 for (i = 0; i < strlen(buddy); i++) { | |
| 792 if (buddy[i] != '\"') | |
| 793 strncat(dest, &buddy[i], 1); | |
| 794 } | |
| 795 strcat(dest, "\n"); | |
| 796 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | |
| 797 buddy = remove_spaces(line); | |
| 798 strcat(dest, "b "); | |
| 799 if (strchr(buddy, '\"') != NULL) { | |
| 800 buddy++; | |
| 801 strncat(dest, buddy, strchr(buddy, '\"') - buddy); | |
| 802 strcat(dest, "\n"); | |
| 803 } else | |
| 804 strcat(dest, buddy); | |
| 805 } | |
| 806 } | |
| 807 /* Syntax "group buddy buddy ..." */ | |
| 808 else { | |
| 809 buddy = remove_spaces(strtok(line, " \n")); | |
| 810 strcat(dest, "g "); | |
| 811 if (strchr(buddy, '\"') != NULL) { | |
| 812 strcat(dest, &buddy[1]); | |
| 813 strcat(dest, " "); | |
| 814 buddy = remove_spaces(strtok(NULL, " \n")); | |
| 815 while (strchr(buddy, '\"') == NULL) { | |
| 816 strcat(dest, buddy); | |
| 817 strcat(dest, " "); | |
| 818 buddy = remove_spaces(strtok(NULL, " \n")); | |
| 819 } | |
| 820 strncat(dest, buddy, strlen(buddy) - 1); | |
| 821 } else { | |
| 822 strcat(dest, buddy); | |
| 823 } | |
| 824 strcat(dest, "\n"); | |
| 825 while ((buddy = remove_spaces(strtok(NULL, " \n"))) != NULL) { | |
| 826 strcat(dest, "b "); | |
| 827 if (strchr(buddy, '\"') != NULL) { | |
| 828 strcat(dest, &buddy[1]); | |
| 829 strcat(dest, " "); | |
| 830 buddy = remove_spaces(strtok(NULL, " \n")); | |
| 831 while (strchr(buddy, '\"') == NULL) { | |
| 832 strcat(dest, buddy); | |
| 833 strcat(dest, " "); | |
| 834 buddy = remove_spaces(strtok(NULL, " \n")); | |
| 835 } | |
| 836 strncat(dest, buddy, strlen(buddy) - 1); | |
| 837 } else { | |
| 838 strcat(dest, buddy); | |
| 839 } | |
| 840 strcat(dest, "\n"); | |
| 841 } | |
| 842 } | |
| 843 } | |
| 844 | |
| 845 return; | |
| 846 } | |
| 847 | |
| 848 char *stylize(gchar *text, int length) | 719 char *stylize(gchar *text, int length) |
| 849 { | 720 { |
| 850 gchar *buf; | 721 gchar *buf; |
| 851 char *tmp = g_malloc(length); | 722 char *tmp = g_malloc(length); |
| 852 | 723 |
