+#define LP_JOBPENDING (1<<5)
+
+void lp_origin (int origin)
+{
+ lp.lp_origin = origin;
+}
+
+/* the converted string should always be shorter, but ... FIXME! */
+static void convert_octal (char *string, charset_t dest)
+{
+ unsigned char *p, *q;
+ char temp[4];
+ long int ch;
+
+ q=p=(unsigned char *)string;
+ while ( *p != '\0' ) {
+ ch = 0;
+ if ( *p == '\\' ) {
+ p++;
+ if (dest && isdigit(*p) && isdigit(*(p+1)) && isdigit(*(p+2)) ) {
+ temp[0] = *p;
+ temp[1] = *(p+1);
+ temp[2] = *(p+2);
+ temp[3] = 0;
+ ch = strtol( temp, NULL, 8);
+ if ( ch && ch < 0xff)
+ *q = ch;
+ else
+ *q = '.';
+ p += 2;
+ }
+ else
+ *q = '.';
+ }
+ else {
+ *q = *p;
+ }
+ p++;
+ q++;
+ }
+ *q = 0;
+}
+
+
+static void translate(charset_t from, charset_t dest, char **option)
+{
+ char *translated;
+
+ if (*option != NULL) {
+ convert_octal(*option, from);
+ if (from) {
+ if ((size_t) -1 != (convert_string_allocate(from, dest, *option, strlen(*option), &translated)) ) {
+ free (*option);
+ *option = translated;
+ }
+ }
+ }
+}
+
+
+static void lp_setup_comments (charset_t dest)
+{
+ charset_t from=0;
+
+ switch (lp.lp_origin) {
+ case 1:
+ from=CH_MAC;
+ break;
+ case 2:
+ from=CH_UTF8_MAC;
+ break;
+ }
+
+ if (lp.lp_job) {
+#ifdef DEBUG1
+ LOG(log_debug, logtype_papd, "job: %s", lp.lp_job );
+#endif
+ translate(from, dest, &lp.lp_job);
+ }
+ if (lp.lp_created_for) {
+#ifdef DEBUG1
+ LOG(log_debug, logtype_papd, "for: %s", lp.lp_created_for );
+#endif
+ translate(from, dest, &lp.lp_created_for);
+ }
+ if (lp.lp_person) {
+#ifdef DEBUG1
+ LOG(log_debug, logtype_papd, "person: %s", lp.lp_person );
+#endif
+ translate(from, dest, &lp.lp_person);
+ }
+}
+
+#define is_var(a, b) (strncmp((a), (b), 2) == 0)
+
+#if 0
+/* removed, it's not used and a pain to get it right from a security POV */
+static size_t quote(char *dest, char *src, const size_t bsize, size_t len)
+{
+size_t used = 0;
+
+ while (len && used < bsize ) {
+ switch (*src) {
+ case '$':
+ case '\\':
+ case '"':
+ case '`':
+ if (used + 2 > bsize )
+ return used;
+ *dest = '\\';
+ dest++;
+ used++;
+ break;
+ }
+ *dest = *src;
+ src++;
+ dest++;
+ len--;
+ used++;
+ }
+ return used;
+}