/*
- Unix SMB/Netbios implementation.
- Version 1.9.
+ Unix SMB/CIFS implementation.
printcap parsing
Copyright (C) Karl Auer 1993-1998
#include "includes.h"
-#include "smb.h"
-
-extern int DEBUGLEVEL;
-
#ifdef AIX
/* ******************************************
Extend for AIX system and qconfig file
static void ScanQconfig_fn(char *psz,void (*fn)(char *, char *))
{
int iEtat;
- FILE *pfile;
+ XFILE *pfile;
char *line,*p;
pstring name,comment;
line = NULL;
*name = 0;
*comment = 0;
- if ((pfile = sys_fopen(psz, "r")) == NULL)
+ if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
{
DEBUG(0,( "Unable to open qconfig file %s for read!\n", psz));
return;
iEtat = 0;
/* scan qconfig file for searching <printername>: */
- for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); free(line))
+ for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); safe_free(line))
{
if (*line == '*' || *line == 0)
continue;
{
case 0: /* locate an entry */
if (*line == '\t' || *line == ' ') continue;
- if ((p=strchr(line,':')))
+ if ((p=strchr_m(line,':')))
{
*p = '\0';
p = strtok(line,":");
break;
}
}
- fclose(pfile);
+ x_fclose(pfile);
}
/* Scan qconfig file and locate de printername */
static BOOL ScanQconfig(char *psz,char *pszPrintername)
{
int iLg,iEtat;
- FILE *pfile;
+ XFILE *pfile;
char *pName;
char *line;
DEBUG(0,(" Unable to allocate memory for printer %s\n",pszPrintername));
return(False);
}
- if ((pfile = sys_fopen(psz, "r")) == NULL)
+ if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
{
DEBUG(0,( "Unable to open qconfig file %s for read!\n", psz));
- free(pName);
+ SAFE_FREE(pName);
return(False);
}
slprintf(pName, iLg + 9, "%s:",pszPrintername);
/*DEBUG(3,( " Looking for entry %s\n",pName));*/
iEtat = 0;
/* scan qconfig file for searching <printername>: */
- for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); free(line))
+ for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); safe_free(line))
{
if (*line == '*' || *line == 0)
continue;
/* name is found without stanza device */
/* probably a good printer ??? */
free (line);
- free(pName);
- fclose(pfile);
+ SAFE_FREE(pName);
+ x_fclose(pfile);
return(True);
}
{
/* it's a good virtual printer */
free (line);
- free(pName);
- fclose(pfile);
+ SAFE_FREE(pName);
+ x_fclose(pfile);
return(True);
}
break;
}
}
free (pName);
- fclose(pfile);
+ x_fclose(pfile);
return(False);
}
#endif /* AIX */
Scan printcap file pszPrintcapname for a printer called pszPrintername.
Return True if found, else False. Returns False on error, too, after logging
the error at level 0. For generality, the printcap name may be passed - if
-passed as NULL, the configuration will be queried for the name.
+passed as NULL, the configuration will be queried for the name.
***************************************************************************/
-BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname)
+BOOL pcap_printername_ok(const char *pszPrintername, const char *pszPrintcapname)
{
char *line=NULL;
- char *psz;
+ const char *psz;
char *p,*q;
- FILE *pfile;
+ XFILE *pfile;
if (pszPrintername == NULL || pszPrintername[0] == '\0')
{
return(False);
}
-#ifdef HAVE_LIBCUPS
+#ifdef HAVE_CUPS
if (strequal(psz, "cups"))
return (cups_printername_ok(pszPrintername));
-#endif /* HAVE_LIBCUPS */
+#endif /* HAVE_CUPS */
#ifdef SYSV
if (strequal(psz, "lpstat"))
return(ScanQconfig(psz,pszPrintername));
#endif
- if ((pfile = sys_fopen(psz, "r")) == NULL)
+ if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
{
DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
return(False);
}
- for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); free(line))
+ for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); safe_free(line))
{
if (*line == '#' || *line == 0)
continue;
/* now we have a real printer line - cut it off at the first : */
- p = strchr(line,':');
+ p = strchr_m(line,':');
if (p) *p = 0;
/* now just check if the name is in the list */
/* NOTE: I avoid strtok as the fn calling this one may be using it */
for (p=line; p; p=q)
{
- if ((q = strchr(p,'|'))) *q++ = 0;
+ if ((q = strchr_m(p,'|'))) *q++ = 0;
if (strequal(p,pszPrintername))
{
- /* normalise the case */
- pstrcpy(pszPrintername,p);
- free(line);
- fclose(pfile);
+ SAFE_FREE(line);
+ x_fclose(pfile);
return(True);
}
p = q;
}
}
- fclose(pfile);
+ x_fclose(pfile);
return(False);
}
/***************************************************************************
run a function on each printer name in the printcap file. The function is
-passed the primary name and the comment (if possible)
+passed the primary name and the comment (if possible). Note the fn() takes
+strings in DOS codepage. This means the xxx_printer_fn() calls must be fixed
+to return DOS codepage. FIXME !! JRA.
***************************************************************************/
void pcap_printer_fn(void (*fn)(char *, char *))
{
char *line;
char *psz;
char *p,*q;
- FILE *pfile;
+ XFILE *pfile;
/* only go looking if no printcap name supplied */
if (((psz = lp_printcapname()) == NULL) || (psz[0] == '\0'))
return;
}
-#ifdef HAVE_LIBCUPS
+#ifdef HAVE_CUPS
if (strequal(psz, "cups")) {
cups_printer_fn(fn);
return;
}
-#endif /* HAVE_LIBCUPS */
+#endif /* HAVE_CUPS */
#ifdef SYSV
if (strequal(psz, "lpstat")) {
}
#endif
- if ((pfile = sys_fopen(psz, "r")) == NULL)
+ if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
{
DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
return;
}
- for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); free(line))
+ for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); safe_free(line))
{
if (*line == '#' || *line == 0)
continue;
/* now we have a real printer line - cut it off at the first : */
- p = strchr(line,':');
+ p = strchr_m(line,':');
if (p) *p = 0;
/* now find the most likely printer name and comment
for (p=line; p; p=q)
{
BOOL has_punctuation;
- if ((q = strchr(p,'|'))) *q++ = 0;
+ if ((q = strchr_m(p,'|'))) *q++ = 0;
- has_punctuation = (strchr(p,' ') || strchr(p,'(') || strchr(p,')'));
+ has_punctuation = (strchr_m(p,' ') || strchr_m(p,'\t') || strchr_m(p,'(') || strchr_m(p,')'));
if (strlen(p)>strlen(comment) && has_punctuation)
{
- StrnCpy(comment,p,sizeof(comment)-1);
+ pstrcpy(comment,p);
continue;
}
continue;
}
- if (!strchr(comment,' ') &&
+ if (!strchr_m(comment,' ') &&
strlen(p) > strlen(comment))
{
- StrnCpy(comment,p,sizeof(comment)-1);
- continue;
+ pstrcpy(comment,p);
+ continue;
}
}
comment[60] = 0;
name[MAXPRINTERLEN] = 0;
- if (*name)
+ if (*name)
fn(name,comment);
}
- fclose(pfile);
+ x_fclose(pfile);
}