view buddytrans.c @ 1106:5bc8fdacd2cb

[gaim-migrate @ 1116] lots of changes. buddy.c: just in general tried to get things to work better. moving things in the edit list window and signing off should be handled better in the main buddy list window (watch out for flashes). gaim.h: removed toc-specific things and moved them to toc.c and rvous.c as needed. gtkhtml.c: possible fix for AOL 6.0 problems (I wasn't able to reproduce the problem before or after the fix, but i fixed what i think might have been causing the problem). multi.c: moved LOGIN_STEPS from gaim.h here and actually use it now oscar.c: moved an oscar-specific struct definition from gaim.h here and also handle problems better perl.c: fix for stupid problem rvous.c: first pass at attempt to be able to remove toc.c and rvous.c (though this will never happen; gaim will support toc as long as aol does) without cruft. gaim is now only dependent on toc.c and rvous.c for toc_build_config and parse_toc_buddy_list, which gaim needs to save and read its buddy list. toc.c: rewrote the signin process so that the read()'s won't block. it's not actually a non-blocking read; it's just that it won't ever get to the read until there's data to be read (thanks to the gdk_input watcher). this means the cancel button should work after it's connected, but it's still not a non-blocking connect. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 20 Nov 2000 07:24:18 +0000
parents 05077cb276d4
children
line wrap: on
line source

#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void do_trans(int, int);

int main(int argc, char **argv) {
	char *srcn;
	char *destn;
	int   src;
	int   dest;
	char *resp;


	printf("Gaim - Buddy List Translator\n");
	printf("----------------------------\n");

	if (argc != 3) {
		printf("Syntax: %s buddy.lst gaimlist\n", argv[0]);
		exit(0);
	}

	srcn  = argv[1];
	destn = argv[2];

	if ((src = open(srcn, O_RDONLY)) != -1) {
		printf("Source=%s, Dest=%s\n", srcn, destn);

		if ((dest = open(destn, O_WRONLY | O_CREAT | O_EXCL)) == -1) {
			printf("%s exists! Should I continue? ", destn);
			scanf("%s", resp);
			if (strchr(resp, 'y') || strchr(resp, 'Y')) {
				dest = open(destn, O_WRONLY | O_CREAT |
							O_TRUNC);
				do_trans(src, dest);
			} else
				exit(0);
		} else
			do_trans(src, dest);
		printf("Conversion Complete.\n");
	} else {
		printf("Source file must exist!\n\nSyntax: %s buddy.lst gaimlist\n", argv[0]);
		exit(0);
	}
	return 0;
}

void do_trans(int source, int destin) {
	FILE *src;
	FILE *dest;
	char  line[1024];

	umask(644);
	src  = fdopen(source, "r");
	dest = fdopen(destin, "w");

	fprintf(dest, "toc_set_config {m 1\n");
	while (fgets(line, sizeof line, src)) {
		line[strlen(line) - 1] = 0;
		if (strpbrk(line, "abcdefghijklmnopqrstuvwxyz"
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
			char *field, *name;
			if (line[0] == ' ' || line[0] == '\t' ||
				line[0] == '\n' || line[0] == '\r' ||
				line[0] == '\f')
				field = strdup(line + 1);
			else
				field = strdup(line);
			name = strpbrk(field, " \t\n\r\f");
			name[0] = 0;
			name += 2;
			name[strlen(name) - 1] = 0;
			printf("%s, %s\n", field, name);
			if (!strcmp("group", field)) {
				fprintf(dest, "g %s\n", name);
			} else if (!strcmp("buddy", field)) {
				fprintf(dest, "b %s\n", name);
			}
			free(field);
		}
	}
	fprintf(dest, "}");
	fclose(src);
	fclose(dest);
}