comparison src/util.c @ 684:b29c92be568b

[gaim-migrate @ 694] bmiller translated perl to C so now gaim can import winaim lists. oh yeah, the permit/deny stuff isn't quite working right. argh. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 15 Aug 2000 17:02:00 +0000
parents 650687b7ca0e
children 012bf218a655
comparison
equal deleted inserted replaced
683:2186b43872b7 684:b29c92be568b
969 969
970 gtk_tooltips_set_tip(tips, button, text, "Gaim"); 970 gtk_tooltips_set_tip(tips, button, text, "Gaim");
971 return button; 971 return button;
972 } 972 }
973 973
974
975 /* remove leading whitespace from a string */
976 char *remove_spaces (char *str)
977 {
978 int i;
979 char *new;
980
981 if (str == NULL)
982 return NULL;
983
984 i = strspn (str, " \t\n\r\f");
985 new = &str[i];
986
987 return new;
988 }
989
990
991 /* translate an AIM 3 buddylist (*.lst) to a GAIM buddylist */
992 void translate_lst (FILE *src_fp, char *dest)
993 {
994 char line[BUF_LEN], *line2;
995 char *name;
996 int i;
997
998 sprintf (dest, "m 1\n");
999
1000 while (fgets (line, BUF_LEN, src_fp)) {
1001 line2 = remove_spaces (line);
1002 if (strstr (line2, "group") == line2) {
1003 name = strpbrk (line2, " \t\n\r\f") + 1;
1004 strcat (dest, "g ");
1005 for (i = 0; i < strcspn (name, "\n\r"); i++)
1006 if (name[i] != '\"')
1007 strncat (dest, &name[i], 1);
1008 strcat (dest, "\n");
1009 }
1010 if (strstr (line2, "buddy") == line2) {
1011 name = strpbrk (line2, " \t\n\r\f") + 1;
1012 strcat (dest, "b ");
1013 for (i = 0; i < strcspn (name, "\n\r"); i++)
1014 if (name[i] != '\"')
1015 strncat (dest, &name[i], 1);
1016 strcat (dest, "\n");
1017 }
1018 }
1019
1020 return;
1021 }
1022
1023
1024 /* translate an AIM 4 buddylist (*.blt) to GAIM format */
1025 void translate_blt (FILE *src_fp, char *dest)
1026 {
1027 int i;
1028 char line[BUF_LEN];
1029 char *buddy;
1030
1031 sprintf (dest, "m 1\n");
1032
1033 while (strstr (fgets (line, BUF_LEN, src_fp), "Buddy") == NULL) ;
1034 while (strstr (fgets (line, BUF_LEN, src_fp), "list") == NULL) ;
1035
1036 while (1) {
1037 fgets (line, BUF_LEN, src_fp);
1038 if (strchr (line, '}') != NULL)
1039 break;
1040
1041 /* Syntax starting with "<group> {" */
1042 if (strchr (line, '{') != NULL) {
1043 strcat (dest, "g ");
1044 buddy = remove_spaces (strtok (line, "{"));
1045 for (i = 0; i < strlen(buddy); i++) {
1046 if (buddy[i] != '\"')
1047 strncat (dest, &buddy[i], 1);
1048 }
1049 strcat (dest, "\n");
1050 while (strchr (fgets (line, BUF_LEN, src_fp), '}') == NULL) {
1051 buddy = remove_spaces (line);
1052 strcat (dest, "b ");
1053 if (strchr (buddy, '\"') != NULL) {
1054 strncat (dest, &buddy[1], strlen(buddy)-3);
1055 strcat (dest, "\n");
1056 } else
1057 strcat (dest, buddy);
1058 }
1059 }
1060 /* Syntax "group buddy buddy ..." */
1061 else {
1062 buddy = remove_spaces (strtok (line, " \n"));
1063 strcat (dest, "g ");
1064 if (strchr (buddy, '\"') != NULL) {
1065 strcat (dest, &buddy[1]);
1066 strcat (dest, " ");
1067 buddy = remove_spaces (strtok (NULL, " \n"));
1068 while (strchr (buddy, '\"') == NULL) {
1069 strcat (dest, buddy);
1070 strcat (dest, " ");
1071 buddy = remove_spaces (strtok (NULL, " \n"));
1072 }
1073 strncat (dest, buddy, strlen(buddy)-1);
1074 } else {
1075 strcat (dest, buddy);
1076 }
1077 strcat (dest, "\n");
1078 while ((buddy = remove_spaces (strtok (NULL, " \n"))) != NULL) {
1079 strcat (dest, "b ");
1080 if (strchr (buddy, '\"') != NULL) {
1081 strcat (dest, &buddy[1]);
1082 strcat (dest, " ");
1083 buddy = remove_spaces (strtok (NULL, " \n"));
1084 while (strchr (buddy, '\"') == NULL) {
1085 strcat (dest, buddy);
1086 strcat (dest, " ");
1087 buddy = remove_spaces (strtok (NULL, " \n"));
1088 }
1089 strncat (dest, buddy, strlen(buddy)-1);
1090 } else {
1091 strcat (dest, buddy);
1092 }
1093 strcat (dest, "\n");
1094 }
1095 }
1096 }
1097
1098 return;
1099 }