]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/banners.c
2 * "$Id: banners.c,v 1.5.2.4 2003/01/07 18:27:15 mike Exp $"
4 * Banner routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2003 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * AddBanner() - Add a banner to the array.
27 * FindBanner() - Find a named banner.
28 * LoadBanners() - Load all available banner files...
29 * compare() - Compare two banners.
33 * Include necessary headers...
43 static int compare(const banner_t
*b0
, const banner_t
*b1
);
47 * 'AddBanner()' - Add a banner to the array.
51 AddBanner(const char *name
, /* I - Name of banner */
52 const char *filename
) /* I - Filename for banner */
54 mime_type_t
*filetype
; /* Filetype */
55 banner_t
*temp
; /* New banner data */
59 * See what the filetype is...
62 if ((filetype
= mimeFileType(MimeDatabase
, filename
)) == NULL
)
64 LogMessage(L_WARN
, "AddBanner: Banner \"%s\" is of an unknown file type - skipping!",
74 temp
= malloc(sizeof(banner_t
));
76 temp
= realloc(Banners
, sizeof(banner_t
) * (NumBanners
+ 1));
80 LogMessage(L_ERROR
, "AddBanner: Ran out of memory adding a banner!");
85 * Copy the new banner data over...
92 memset(temp
, 0, sizeof(banner_t
));
93 strlcpy(temp
->name
, name
, sizeof(temp
->name
));
94 temp
->filetype
= filetype
;
99 * 'FindBanner()' - Find a named banner.
102 banner_t
* /* O - Pointer to banner or NULL */
103 FindBanner(const char *name
) /* I - Name of banner */
105 banner_t key
; /* Search key */
108 strlcpy(key
.name
, name
, sizeof(key
.name
));
110 return ((banner_t
*)bsearch(&key
, Banners
, NumBanners
, sizeof(banner_t
),
111 (int (*)(const void *, const void *))compare
));
116 * 'LoadBanners()' - Load all available banner files...
120 LoadBanners(const char *d
) /* I - Directory to search */
122 DIR *dir
; /* Directory pointer */
123 DIRENT
*dent
; /* Directory entry */
124 char filename
[1024], /* Name of banner */
125 *ext
; /* Pointer to extension */
126 struct stat fileinfo
; /* File information */
130 * Free old banner info...
140 * Try opening the banner directory...
143 if ((dir
= opendir(d
)) == NULL
)
145 LogMessage(L_ERROR
, "LoadBanners: Unable to open banner directory \"%s\": %s",
151 * Read entries, skipping directories and backup files.
154 while ((dent
= readdir(dir
)) != NULL
)
157 * Check the file to make sure it isn't a directory or a backup
158 * file of some sort...
161 snprintf(filename
, sizeof(filename
), "%s/%s", d
, dent
->d_name
);
163 if (stat(filename
, &fileinfo
))
165 LogMessage(L_WARN
, "LoadBanners: Unable to state \"%s\" banner: %s",
166 dent
->d_name
, strerror(errno
));
170 if (S_ISDIR(fileinfo
.st_mode
))
173 if (dent
->d_name
[0] == '~')
176 if ((ext
= strrchr(dent
->d_name
, '.')) != NULL
)
177 if (strcmp(ext
, ".bck") == 0 ||
178 strcmp(ext
, ".bak") == 0 ||
179 strcmp(ext
, ".sav") == 0)
183 * Must be a valid file; add it!
186 AddBanner(dent
->d_name
, filename
);
190 * Close the directory and sort as needed...
196 qsort(Banners
, NumBanners
, sizeof(banner_t
),
197 (int (*)(const void *, const void *))compare
);
202 * 'compare()' - Compare two banners.
205 static int /* O - -1 if name0 < name1, etc. */
206 compare(const banner_t
*b0
, /* I - First banner */
207 const banner_t
*b1
) /* I - Second banner */
209 return (strcasecmp(b0
->name
, b1
->name
));
214 * End of "$Id: banners.c,v 1.5.2.4 2003/01/07 18:27:15 mike Exp $".