Пример #1
0
/**
 * ModuleUsage will take an argument for the specified 
 * module and print out help information on the topic.  
 * information is stored in a written file in the location 
 * in Macro EMAIL_DIR. and also specified with EMAIL_HELP_FILE
 */
static void
moduleUsage(const char *module)
{
	FILE *help=NULL;
	short found=0;
	char *moduleptr=NULL;
	dstrbuf *buf = DSB_NEW;
	dstrbuf *help_file = expandPath(EMAIL_HELP_FILE);

	if (!(help = fopen(help_file->str, "r"))) {
		fatal("Could not open help file: %s", help_file->str);
		dsbDestroy(help_file);
		properExit(ERROR);
	}
	dsbDestroy(help_file);

	while (!feof(help)) {
		dsbReadline(buf, help);
		if ((buf->str[0] == '#') || (buf->str[0] == '\n')) {
			continue;
		}

		chomp(buf->str);
		moduleptr = strtok(buf->str, "|");
		if (strcasecmp(moduleptr, module) != 0) {
			while ((moduleptr = strtok(NULL, "|")) != NULL) {
				if (strcasecmp(moduleptr, module) == 0) {
					found = 1;
					break;
				}
			}
		} else {
			found = 1;
		}

		if (!found) {
			continue;
		}
		while (!feof(help)) {
			dsbReadline(buf, help);
			if (!strcmp(buf->str, "EOH\n")) {
				break;
			}
			printf("%s", buf->str);
		}
		break;
	}

	if (feof(help)) {
		printf("There is no help in the module: %s\n", module);
		usage();
	}

	dsbDestroy(buf);
	fclose(help);
	exit(0);
}
Пример #2
0
dstrbuf *
mimeFiletype(const char *filename)
{
	bool found=false;
	int i=0, veclen=0;
	dstrbuf *type=NULL;
	dstrbuf *buf=DSB_NEW;
	dvector vec=NULL;
	const char *ext=NULL;
	dstrbuf *filen=NULL;
	FILE *file = fopen(MAGIC_FILE, "r");

	if (!file) {
		goto exit;
	}
	filen = mimeFilename(filename);
	ext = strrchr(filen->str, '.');

	/* If we don't know  the extension, we don't know what type
	 * of file it's going to be. Therefore, skip all of this.  */
	if (!ext) {
		goto exit;
	}
	/* Get past . in extension name. */
	ext++;

	while (!feof(file)) {
		dsbReadline(buf, file);
		if (buf->str[0] == '#' || buf->str[0] == '\n') {
			continue;
		}
		chomp(buf->str);

		/* If we still have an allocated type, free it */
		if (type) {
			dsbDestroy(type);
		}
		type = getMimeType(buf->str);
		if (type->len == 0) {
			continue;
		}
		vec = explode(buf->str, " \t");
		veclen = dvLength(vec);
		/* Start i at 1 since the first element in the
		 * vector is the mime type. The exts are after that. */
		for (i=1; i < veclen; i++) {
			if (strcmp((char *)vec[i], ext) == 0) {
				found = true;
				break;
			}
		}
		dvDestroy(vec);
		if (found) {
			/* Found it! */
			break;
		}
	}

exit:
	dsbDestroy(filen);
	dsbDestroy(buf);
	if (file) {
		fclose(file);
	}
	if (!type || type->len == 0) {
		type = DSB_NEW;
		dsbCopy(type, "application/unknown");
	}
	return type;
}