Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtprintinfo / objects / PrintObj / PrintSubSys.C
1 /* $XConsortium: PrintSubSys.C /main/4 1996/01/17 18:02:47 lehors $ */
2 /*                                                                      *
3  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
4  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
5  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
6  * (c) Copyright 1993, 1994 Novell, Inc.                                *
7  */
8
9 #include "PrintSubSys.h"
10 #include "Queue.h"
11
12 #include <string.h>
13
14 #ifdef aix
15 const char *LIST_QUEUES = "lsallq | grep -v '^bsh$' | sort";
16 #else
17 #ifdef hpux
18 const char *LIST_QUEUES = "LANG=C lpstat -v | "
19                             "awk '"
20                             " $2 == \"for\" "
21                             "   { "
22                             "      x = match($3, /:/); "
23                             "      print substr($3, 1, x-1)"
24                             "   }' | sort";
25 #else
26 #ifdef __osf__
27   const char *LIST_QUEUES = "LANG=C lpstat -v | "
28                             "nawk '"
29                             " $2 == \"for\"    "
30                             "   { print $10 }' "
31                             "   | sort";
32 #else
33 #ifdef __uxp__
34 const char *LIST_QUEUES = "LANG=C lpstat -v | "
35                             "nawk '"
36                             " $4 == \"for\" "
37                             "   { "
38                             "      x = match($5, /:/); "
39                             "      print substr($5, 1, x-1)"
40                             "   }' | sort";
41 #else
42 const char *LIST_QUEUES = "LANG=C lpstat -v | "
43                             "nawk '"
44                             " $2 == \"for\" "
45                             "   { "
46                             "      x = match($3, /:/); "
47                             "      print substr($3, 1, x-1)"
48                             "   }' | sort";
49 #endif
50 #endif
51 #endif
52 #endif
53
54 // Object Class Name
55 const char *PRINTSUBSYSTEM = "PrintSubSystem";
56
57 PrintSubSystem::PrintSubSystem(BaseObj *parent)
58         : BaseObj(parent, "PrintSubSystem")
59 {
60    _displayName = strdup(MESSAGE(PrinterMenuL));
61    _details = strdup("Status   Number   Owner      Date       Time       Size");
62 }
63
64 PrintSubSystem::~PrintSubSystem()
65 {
66    // Empty
67 }
68
69 void PrintSubSystem::InitChildren()
70 {
71    char *std_out;
72    if (RunCommand(LIST_QUEUES, &std_out))
73     {
74       Error("InitChildren method could not list queues.");
75     }
76    else
77     {
78       char *queue = strtok(std_out, " \n");
79       while (queue && *queue)
80        {
81          new Queue(this, queue);
82          queue = strtok(NULL, " \n");
83        }
84     }
85    delete std_out;
86 }