diff 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
line wrap: on
line diff
--- a/src/util.c	Tue Aug 15 16:20:27 2000 +0000
+++ b/src/util.c	Tue Aug 15 17:02:00 2000 +0000
@@ -971,3 +971,129 @@
 	return button;
 }
 
+
+/* remove leading whitespace from a string */
+char *remove_spaces (char *str)
+{
+	int i;
+	char *new;
+
+	if (str == NULL)
+		return NULL;
+
+	i = strspn (str, " \t\n\r\f");
+	new = &str[i];
+
+	return new;
+}
+
+
+/* translate an AIM 3 buddylist (*.lst) to a GAIM buddylist */
+void translate_lst (FILE *src_fp, char *dest) 
+{
+	char line[BUF_LEN], *line2;
+	char *name;
+	int i;
+
+	sprintf (dest, "m 1\n");
+  
+	while (fgets (line, BUF_LEN, src_fp)) {
+		line2 = remove_spaces (line);
+		if (strstr (line2, "group") == line2) {
+			name = strpbrk (line2, " \t\n\r\f") + 1;
+			strcat (dest, "g ");
+			for (i = 0; i < strcspn (name, "\n\r"); i++)
+				if (name[i] != '\"')
+					strncat (dest, &name[i], 1);
+			strcat (dest, "\n");
+		}
+		if (strstr (line2, "buddy") == line2) {
+			name = strpbrk (line2, " \t\n\r\f") + 1;
+			strcat (dest, "b ");
+			for (i = 0; i < strcspn (name, "\n\r"); i++)
+				if (name[i] != '\"')
+					strncat (dest, &name[i], 1);
+			strcat (dest, "\n");
+		}
+	}
+
+	return;
+}
+
+
+/* translate an AIM 4 buddylist (*.blt) to GAIM format */
+void translate_blt (FILE *src_fp, char *dest)
+{
+	int i;
+	char line[BUF_LEN];
+	char *buddy;
+
+	sprintf (dest, "m 1\n");
+  
+	while (strstr (fgets (line, BUF_LEN, src_fp), "Buddy") == NULL)	;
+	while (strstr (fgets (line, BUF_LEN, src_fp), "list") == NULL)	;
+
+	while (1) {
+		fgets (line, BUF_LEN, src_fp);
+		if (strchr (line, '}') != NULL)
+			break;
+    
+		/* Syntax starting with "<group> {" */
+		if (strchr (line, '{') != NULL) {
+			strcat (dest, "g ");
+			buddy = remove_spaces (strtok (line, "{"));
+			for (i = 0; i < strlen(buddy); i++) {
+				if (buddy[i] != '\"')
+					strncat (dest, &buddy[i], 1);
+			}
+			strcat (dest, "\n");
+			while (strchr (fgets (line, BUF_LEN, src_fp), '}') == NULL) {
+				buddy = remove_spaces (line);
+				strcat (dest, "b ");
+				if (strchr (buddy, '\"') != NULL) {
+					strncat (dest, &buddy[1], strlen(buddy)-3);
+					strcat (dest, "\n");
+				} else
+					strcat (dest, buddy);
+			}
+		}
+		/* Syntax "group buddy buddy ..." */
+		else {
+			buddy = remove_spaces (strtok (line, " \n"));
+			strcat (dest, "g ");
+			if (strchr (buddy, '\"') != NULL) {
+				strcat (dest, &buddy[1]);
+				strcat (dest, " ");
+				buddy = remove_spaces (strtok (NULL, " \n"));
+				while (strchr (buddy, '\"') == NULL) {
+					strcat (dest, buddy);
+					strcat (dest, " ");
+					buddy = remove_spaces (strtok (NULL, " \n"));
+				}
+				strncat (dest, buddy, strlen(buddy)-1);
+			} else {
+				strcat (dest, buddy);
+			}
+			strcat (dest, "\n");
+			while ((buddy = remove_spaces (strtok (NULL, " \n"))) != NULL) {
+				strcat (dest, "b ");
+				if (strchr (buddy, '\"') != NULL) {
+					strcat (dest, &buddy[1]);
+					strcat (dest, " ");
+					buddy = remove_spaces (strtok (NULL, " \n"));
+					while (strchr (buddy, '\"') == NULL) {
+						strcat (dest, buddy);
+						strcat (dest, " ");
+						buddy = remove_spaces (strtok (NULL, " \n"));
+					}
+					strncat (dest, buddy, strlen(buddy)-1);
+				} else {
+					strcat (dest, buddy);
+				}
+				strcat (dest, "\n");
+			}
+		}
+	}
+
+	return;
+}