1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/*Copyright (c) 1993-1998 Xerox Corporation. All Rights Reserved.
Permission to use, copy, modify and distribute without charge
this software, documentation, images, etc. is granted, provided
that this copyright and the author's name is retained.
A fee may be charged for this program ONLY to recover costs for
distribution (i.e. media costs). No profit can be made on this
program.
The author assumes no responsibility for disasters (natural or
otherwise) as a consequence of use of this software.
Adam Stein (adam@iset.scan.mc.xerox.com)
*/
#include <stdio.h>
#include <ctype.h>
#include "xtoolplaces.h"
#include "addon.h"
ADDON *head = NULL;
extern char *program,*addon;
extern FILE *fp;
/*This function will read in a file containing strings to put onto the
command line. This is used when WM_COMMAND isn't complete. In the case
of xrolo, the data file is never listed in WM_COMMAND and must be put
added. I don't know if this is an XVIEW bug or not. I haven't seen it
with any other program (yet).
Inputs: none
Outputs: none
Locals: fp - file pointer to read from
line - line of text read in
Globals: addon - name of file containing commands to add on
program - name of currently executing program
stderr - standard error
NULL - 0
*/
read_addon()
{
char line[200];
FILE *fp;
/*Open the file for reading*/
if((fp = fopen(addon,"r")) == NULL) {
fprintf(stderr,"%s: can't open {%s}\n",program,addon);
exit(1);
}
/*Read lines from file until there is no more*/
while(fgets(line,200,fp) != NULL)
switch(line[0]) {
case '#': /*Comment character - ignore line*/
case '\n': /*Blank line - ignore line*/
break;
default:
line[strlen(line)-1] = '\0'; /*Take out NL char*/
insert(line);
break;
}
}
/*This function will insert commands to be added into a linked list.
Inputs: line - line containing program name and commands to be added
Outputs: none
Locals: next - next available structure entry to fill in
pointer - point to : to separater program from commands and to
skip over white space to point to commands
Globals: addon - name of file containing commands to add on
head - pointer to head of linked list
program - name of currently executing program
stderr - standard error
ADDON - structure holding program and command line info
NULL - 0
*/
insert(line)
char *line;
{
char *pointer;
ADDON *next;
/*Find colon to make it a NULL thereby making line equal to just
the program name. Syntax error if the colon isn't found*/
if((pointer = index(line,':')) == NULL) {
fprintf(stderr,"%s: syntax error in {%s}\n",program,addon);
exit(1);
}
/*Insert new entry*/
if(!head) {
if((head = (ADDON *) calloc(1,sizeof(ADDON))) == NULL) {
perror(program);
exit(1);
}
next = head;
} else {
for(next = head;next->next;next = next->next)
;
if((next->next = (ADDON *) calloc(1,sizeof(ADDON))) == NULL) {
perror(program);
exit(1);
}
next = next->next;
}
/*Make colon NULL so that line equals just the program name*/
*pointer = '\0';
if((next->program = strdup(line)) == NULL) {
perror(program);
exit(1);
}
/*Put colon back and skip past whitespace to get to first character
in command line*/
*(pointer) = ':';
while(isspace(*(++pointer))) ;
if((next->cmmd_line = strdup(pointer)) == NULL) {
perror(program);
exit(1);
}
next->next = (ADDON *) NULL;
}
/*This function will find the corresponding addon commands to the program
being written out and at the commands to the command line being written
out.
Inputs: name - name of program being written out
Outputs: none
Locals: list - pointer to go through linked list
pointer - pointer to make name equal to just the first word in string
Globals: fp - file pointer to write window information to
head - pointer to head of linked list
NULL - 0
*/
addto(name)
char *name;
{
char *pointer;
ADDON *list;
/*If there is whitespace in the name string then put in a NULL to
make name equal to just the first word in the string, otherwise
assume the string is only made up of one word*/
if((pointer = index(name,' ')) != NULL)
*pointer = '\0';
/*Loop through linked list to match the program information saved with
the name of the program being written out. Write out saved addon
command line when we find a match*/
for(list = head;list;list = list->next)
if(!strcmp(name,list->program)) {
fprintf(fp,"%s ",list->cmmd_line);
break;
}
/*Put whitespace back to put the string back to normal*/
if(pointer) *pointer = ' ';
}
|