]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/banners.c
2 * "$Id: banners.c,v 1.5.2.2 2002/01/02 18:04:58 mike Exp $"
4 * Banner routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2002 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 strncpy(temp
->name
, name
, sizeof(temp
->name
) - 1);
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 strncpy(key
.name
, name
, sizeof(key
.name
) - 1);
109 key
.name
[sizeof(key
.name
) - 1] = '\0';
111 return ((banner_t
*)bsearch(&key
, Banners
, NumBanners
, sizeof(banner_t
),
112 (int (*)(const void *, const void *))compare
));
117 * 'LoadBanners()' - Load all available banner files...
121 LoadBanners(const char *d
) /* I - Directory to search */
123 DIR *dir
; /* Directory pointer */
124 DIRENT
*dent
; /* Directory entry */
125 char filename
[1024], /* Name of banner */
126 *ext
; /* Pointer to extension */
127 struct stat fileinfo
; /* File information */
131 * Free old banner info...
141 * Try opening the banner directory...
144 if ((dir
= opendir(d
)) == NULL
)
146 LogMessage(L_ERROR
, "LoadBanners: Unable to open banner directory \"%s\": %s",
152 * Read entries, skipping directories and backup files.
155 while ((dent
= readdir(dir
)) != NULL
)
158 * Check the file to make sure it isn't a directory or a backup
159 * file of some sort...
162 snprintf(filename
, sizeof(filename
), "%s/%s", d
, dent
->d_name
);
164 if (stat(filename
, &fileinfo
))
166 LogMessage(L_WARN
, "LoadBanners: Unable to state \"%s\" banner: %s",
167 dent
->d_name
, strerror(errno
));
171 if (S_ISDIR(fileinfo
.st_mode
))
174 if (dent
->d_name
[0] == '~')
177 if ((ext
= strrchr(dent
->d_name
, '.')) != NULL
)
178 if (strcmp(ext
, ".bck") == 0 ||
179 strcmp(ext
, ".bak") == 0 ||
180 strcmp(ext
, ".sav") == 0)
184 * Must be a valid file; add it!
187 AddBanner(dent
->d_name
, filename
);
191 * Close the directory and sort as needed...
197 qsort(Banners
, NumBanners
, sizeof(banner_t
),
198 (int (*)(const void *, const void *))compare
);
203 * 'compare()' - Compare two banners.
206 static int /* O - -1 if name0 < name1, etc. */
207 compare(const banner_t
*b0
, /* I - First banner */
208 const banner_t
*b1
) /* I - Second banner */
210 return (strcasecmp(b0
->name
, b1
->name
));
215 * End of "$Id: banners.c,v 1.5.2.2 2002/01/02 18:04:58 mike Exp $".