home *** CD-ROM | disk | FTP | other *** search
- /* SOURCE FILE *****************************************************
- * WTCLTOOL.C - WTAPI Sample Client Application Tools Menu Handler
- *******************************************************************
- *Copyright (C) 1993 WordPerfect Corp., All Rights Reserved
- *******************************************************************/
- #include "wtclient.h"
-
- #include <stdio.h>
- #include <string.h>
-
- #define WRITING "Writing"
- #define TOOLS "Tools"
- #define PATHEXE "PathExe"
- #define MENUNAME "MenuName"
- #define DESCNAME "DescriptiveName"
- #define PARAMETERS "Parameters"
- #define LONGPROMPT "LongPrompt"
- #define BTNBARTEXT "ButtonBarText"
- #define BITMAPPATH "BitmapPath"
- #define HELPFILE "HelpFilePath"
- #define HELPKEY "HelpFileKey"
-
- static BOOL GetToolInfo(FILE *, TOOLRECORD *);
-
- /*COMMENT***************************************************
- ;GetToolsInfo
- Title: Get information for all tools in the wtapi.rc file
- In: none
- Out: tools - list of tool information from file
- count - number of tools in list
- Xin: none
- Xout: none
- Return: TRUE - okay, FALSE - failed to read tool information from file
- Notes:
- ***********************************************************/
- BOOL GetToolsInfo(TOOLRECORD *tools, int *count)
- {
- FILE *fp; /* pointer to wtapi.rc file */
- unsigned char text[256]; /* last string read from file */
- int toolcnt = 0; /* number of tools found in the file */
- unsigned char found = 0; /* 1 = found WRITING, 2 = found TOOLS also */
- unsigned char *p;
- int len;
- long filepos;
-
- *count = 0; /* initialize count */
- fp = fopen("wtapi.rc", "r");
- if (!fp) {
- return FALSE;
- }
- /*
- * Search for [WRITING TOOLS] header.
- */
- text[0] = NULL;
- while (fscanf(fp, " %s ", text) != EOF) {
- len = strlen(text);
- if (text[len-1] == ']') {
- text[len-1] = 0;
- }
- if ((found == 0) && (text[0] != '[')) {
- continue;
- } else if (strcmp(text+1, WRITING) == 0) {
- found = 1;
- } else if ((found == 1) && (strcmp(text, TOOLS) == 0)) {
- found = 2;
- break;
- } else {
- found = 0; /* TOOLS must be next text after WRITING */
- }
- }
- if (found != 2) {
- return FALSE; /* no tools found */
- }
- /*
- * Build list of tools from file (convert "tool1=<optional text>" to
- * "tool1"). Search for the information for each tool and retrieve it
- * if found. If not found, do not include that tool.
- */
- while ((fscanf(fp, " %s ", text) != EOF) && (text[0] != '[') &&
- (toolcnt < MAXTOOLS))
- {
- /* find the next tool in the list */
- if (p = strchr(text, '=')) { /* should contain a '=' */
- *p = NULL; /* truncate at '=' */
- len = strlen(text);
- strcpy(tools[toolcnt].tool, text);
- /*
- * Search for tool info in file.
- */
- filepos = ftell(fp); /* remember where we are */
- if (GetToolInfo(fp, &tools[toolcnt])) {
- toolcnt++;
- }
- fseek(fp, filepos, 0); /* return to previous position */
- }
- }
- *count = toolcnt;
- fclose(fp);
- return TRUE;
- } /* GetToolsInfo */
-
- /*COMMENT***************************************************
- ;GetToolInfo
- Title: Fill in tool record info for a single tool from the file.
- In: fp - pointer to wtapi.rc file
- Out: tool - pointer to tool record where tool info is to be put
- Xin: none
- Xout: none
- Return: TRUE - okay, FALSE - failed to read tool information from file
- Notes: The tool member of the TOOLRECORD structure should already contain
- the name of the tool to search for.
- ***********************************************************/
- static BOOL GetToolInfo(FILE *fp, TOOLRECORD *tool)
- {
- unsigned char *target = tool->tool;
- unsigned char text[256]; /* last string read from file */
- unsigned char *product = 0; /* last product (tool) header read from file */
- unsigned char found = 0; /* 0 = not found, 1 = found product */
- unsigned char *left = 0; /* left side of left=right pair */
- unsigned char *right = 0; /* right side of left=right pair */
- unsigned char *curr = 0; /* pointer to parameter currently being set */
- unsigned char *p = 0;
- int len;
-
- if (!*target) {
- return FALSE; /* no target tool specified */
- }
- /*
- * Search to the beginning of the entries for the specified product.
- * e.g. [WPSpeller]
- */
- text[0] = NULL;
- while (fscanf(fp, " %s ", text) != EOF) {
- len = strlen(text);
- if ((text[0] != '[') || (text[len-1] != ']')) {
- continue;
- }
- product = text + 1; /* skip '[' */
- text[len-1] = 0; /* delete final ']' */
- if (strcmp(product, target) == 0) {
- found = 1;
- break;
- }
- }
- if (found != 1) {
- return FALSE; /* failed to find target product */
- }
- /*
- * We are positioned at the info for the specified target product.
- * Read in the information and store it in the tool record.
- * Null out any missing parameters.
- */
- while ((fscanf(fp, " %s ", text) != EOF) && (text[0] != '[')) {
- if ((p = strchr(text, '=')) != 0) {
- left = text;
- *p = NULL;
- right = p + 1;
- if (strcmp(left, PATHEXE) == 0) {
- strcpy(tool->exe, right);
- curr = tool->exe;
- } else if (strcmp(left, MENUNAME) == 0) {
- /* Use '&' to locate mnemonic then delete '&' */
- if ((p = strchr(right, '&')) != 0) {
- tool->mne = *(p+1); /* next char is mnemonic */
- strcpy(p, p+1); /* shift later chars left */
- } else {
- tool->mne = 0;
- }
- strcpy(tool->menu, right);
- curr = tool->menu;
- } else if (strcmp(left, DESCNAME) == 0) {
- strcpy(tool->desc, right);
- curr = tool->desc;
- } else if (strcmp(left, PARAMETERS) == 0) {
- strcpy(tool->params, right);
- curr = tool->params;
- } else if (strcmp(left, LONGPROMPT) == 0) {
- strcpy(tool->prompt, right);
- curr = tool->prompt;
- } else if (strcmp(left, BTNBARTEXT) == 0) {
- /* ignore */
- curr = 0;
- } else if (strcmp(left, BITMAPPATH) == 0) {
- /* ignore */
- curr = 0;
- } else if (strcmp(left, HELPFILE) == 0) {
- /* ignore */
- curr = 0;
- } else if (strcmp(left, HELPKEY) == 0) {
- /* ignore */
- curr = 0;
- } else {
- /* ignore */
- curr = 0;
- }
- }
- /*
- * Assume any text not containing '=' belongs to the preceding
- * parameter.
- */
- else {
- if (curr) {
- strcat(curr, " "); /* use space in place of newline */
- strcat(curr, text);
- }
- }
- }
- return TRUE;
- } /* GetToolInfo */
-