2 Unix SMB/Netbios implementation.
4 Create printer definition files.
6 Copyright (C) Jean-Francois.Micouleau@utc.fr, 10/26/97 - 1998
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 char *driverfile, *datafile, *helpfile, *languagemonitor, *datatype;
31 char sub_dir[50][2][255];
33 void usage(char *name)
35 fprintf(stderr,"%s: printer.def \"Printer Name\"\n", name);
39 This function split a line in two parts
40 on both side of the equal sign
43 char *scan(char *chaine,char **entry)
49 *entry=(char *)malloc(255*sizeof(char));
50 value=(char *)malloc(255*sizeof(char));
51 strcpy(*entry,chaine);
53 while( temp[i]!='=' && temp[i]!='\0') {
57 strcpy(value,temp+i+1);
67 while (*buffer[i]!='\0') {
68 data=scan(buffer[i],&entry);
70 fprintf(stderr,"\tentry=data %s:%s\n",entry,data);
73 if (strcmp(data,"11")==0) {
74 strcpy(sub_dir[i][0],entry);
75 strcpy(sub_dir[i][1],"");
77 if (strcmp(data,"23")==0) {
78 strcpy(sub_dir[i][0],entry);
79 strcpy(sub_dir[i][1],"color\\");
82 fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]);
89 Lockup an entry in a file
90 Return all the lines between the entry and the next one or the end of file
91 An entry is something between braces.
93 void lookup_entry(FILE *fichier,char *chaine)
95 int found=0,pointeur=0,i=0;
98 temp=(char *)malloc(255*sizeof(char));
99 temp2=(char *)malloc(255*sizeof(char));
104 strcat(temp2,chaine);
109 fprintf(stderr,"\tLooking for %s\n",chaine);
112 while (!feof(fichier) && found==0) {
114 fgets(temp,255,fichier);
115 if (strncmp(temp,temp2,strlen(temp2))==0) found=1;
119 while (!feof(fichier) && found==1) {
121 fgets(temp,255,fichier);
124 *buffer[pointeur]='\0';
127 strcpy(buffer[pointeur],temp);
128 i=strlen(buffer[pointeur])-1;
129 while (buffer[pointeur][i]=='\r' || buffer[pointeur][i]=='\n')
130 buffer[pointeur][i--]='\0';
135 fprintf(stderr,"\t\tFound %d entries\n",pointeur-1);
141 char *find_desc(FILE *fichier,char *text)
151 chaine=(char *)malloc(255*sizeof(char));
152 long_desc=(char *)malloc(40*sizeof(char));
153 short_desc=(char *)malloc(40*sizeof(char));
155 while (!feof(fichier) && found==0)
157 fgets(chaine,255,fichier);
159 long_desc=strtok(chaine,"=");
160 crap=strtok(NULL,",\r");
163 while(*p!='"' && *p!='\0')
165 if (*p=='"' && *(p+1)!='\0') p++;
175 if (!strcmp(text,long_desc))
179 if (!found || !crap) return(NULL);
180 while(*crap==' ') crap++;
181 strcpy(short_desc,crap);
185 void scan_copyfiles(FILE *fichier, char *chaine)
191 fprintf(stderr,"In scan_copyfiles Lookup up of %s\n",chaine);
193 fprintf(stderr,"\nCopy the following files to your printer$ share location:\n");
194 part=strtok(chaine,",");
196 /* If the entry start with a @ then it's a file to copy
197 else it's an entry refering to files to copy
198 the main difference is when it's an entry
199 you can have a directory to append before the file name
202 if (strlen(files_to_copy) != 0)
203 strcat(files_to_copy,",");
204 strcat(files_to_copy,&part[1]);
205 fprintf(stderr,"%s\n",&part[1]);
207 lookup_entry(fichier,part);
210 while (*sub_dir[i][0]!='\0') {
212 fprintf(stderr,"\tsubdir %s:%s\n",sub_dir[i][0],sub_dir[i][1]);
214 if (strcmp(sub_dir[i][0],part)==0)
215 strcpy(direc,sub_dir[i][1]);
219 while (*buffer[i]!='\0') {
220 part = &buffer[i][strlen(buffer[i])-1];
223 if (strlen(files_to_copy) != 0)
224 strcat(files_to_copy,",");
225 strcat(files_to_copy,direc);
226 strcat(files_to_copy,buffer[i]);
227 fprintf(stderr,"%s%s\n",direc,buffer[i]);
231 part=strtok(NULL,",");
234 fprintf(stderr,"\n");
238 void scan_short_desc(FILE *fichier, char *short_desc)
243 char *copyfiles=0,*datasection=0;
248 chaine=(char *)malloc(255*sizeof(char));
249 temp=(char *)malloc(255*sizeof(char));
251 driverfile=short_desc;
254 lookup_entry(fichier,short_desc);
256 while(*buffer[i]!='\0') {
258 fprintf(stderr,"\tLookup up of %s\n",buffer[i]);
260 if (strncmp(buffer[i],"CopyFiles",9)==0)
261 copyfiles=scan(buffer[i],&temp);
262 else if (strncmp(buffer[i],"DataSection",11)==0)
263 datasection=scan(buffer[i],&temp);
264 else if (strncmp(buffer[i],"DataFile",8)==0)
265 datafile=scan(buffer[i],&temp);
266 else if (strncmp(buffer[i],"DriverFile",10)==0)
267 driverfile=scan(buffer[i],&temp);
268 else if (strncmp(buffer[i],"HelpFile",8)==0)
269 helpfile=scan(buffer[i],&temp);
270 else if (strncmp(buffer[i],"LanguageMonitor",15)==0)
271 languagemonitor=scan(buffer[i],&temp);
272 else if (strncmp(buffer[i],"DefaultDataType",15)==0)
273 datatype=scan(buffer[i],&temp);
278 lookup_entry(fichier,datasection);
281 while(*buffer[i]!='\0') {
283 fprintf(stderr,"\tLookup up of %s\n",buffer[i]);
285 if (strncmp(buffer[i],"CopyFiles",9)==0)
286 copyfiles=scan(buffer[i],&temp);
287 else if (strncmp(buffer[i],"DataSection",11)==0)
288 datasection=scan(buffer[i],&temp);
289 else if (strncmp(buffer[i],"DataFile",8)==0)
290 datafile=scan(buffer[i],&temp);
291 else if (strncmp(buffer[i],"DriverFile",10)==0)
292 driverfile=scan(buffer[i],&temp);
293 else if (strncmp(buffer[i],"HelpFile",8)==0)
294 helpfile=scan(buffer[i],&temp);
295 else if (strncmp(buffer[i],"LanguageMonitor",15)==0)
296 languagemonitor=scan(buffer[i],&temp);
297 else if (strncmp(buffer[i],"DefaultDataType",15)==0)
298 datatype=scan(buffer[i],&temp);
303 if (languagemonitor && (*languagemonitor == '%')) {
305 languagemonitor[strlen(languagemonitor)-1] = '\0';
306 lookup_entry(fichier,"Strings");
308 while(*buffer[i]!='\0') {
310 fprintf(stderr,"\tLookup up of %s\n",buffer[i]);
312 if (strncmp(buffer[i],languagemonitor,strlen(languagemonitor))==0)
314 temp = strtok(buffer[i],"=");
315 temp = strtok(NULL,",");
316 if (*temp == '"') ++temp;
317 strcpy(languagemonitor,temp);
324 if (i) fprintf(stderr,"End of section found\n");
326 fprintf(stderr,"CopyFiles: %s\n",copyfiles);
327 fprintf(stderr,"Datasection: %s\n",datasection);
328 fprintf(stderr,"Datafile: %s\n",datafile);
329 fprintf(stderr,"Driverfile: %s\n",driverfile);
330 fprintf(stderr,"Helpfile: %s\n",helpfile);
331 fprintf(stderr,"LanguageMonitor: %s\n",languagemonitor);
332 if (copyfiles) scan_copyfiles(fichier,copyfiles);
335 int main(int argc, char *argv[])
346 inf_file=fopen(argv[1],"r");
349 fprintf(stderr,"Description file not found, bye\n");
353 short_desc=find_desc(inf_file,argv[2]);
354 if (short_desc==NULL)
356 fprintf(stderr,"Printer not found\n");
359 else fprintf(stderr,"Found:%s\n",short_desc);
361 lookup_entry(inf_file,"DestinationDirs");
364 files_to_copy=(char *)malloc(2048*sizeof(char));
366 scan_short_desc(inf_file,short_desc);
367 fprintf(stdout,"%s:%s:%s:",
368 argv[2],driverfile,datafile);
369 fprintf(stdout,"%s:",
370 helpfile?helpfile:"");
371 fprintf(stdout,"%s:",
372 languagemonitor?languagemonitor:"");
373 fprintf(stdout,"%s:",datatype);
374 fprintf(stdout,"%s\n",files_to_copy);