Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,532 @@
/* $TOG: BaseObj.C /main/4 1998/08/03 16:30:23 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "BaseObj.h"
#include <string.h>
#include <stdlib.h>
const char *ACTION_NOT_FOUND = "ActionNotFound";
BaseObj::BaseObj(BaseObj *parent,
const char *name)
{
_name = STRDUP(name);
_displayName = NULL;
_details = NULL;
_parent = parent;
_init_children = false;
_init_attributes = false;
_children = NULL;
_numChildren = 0;
_numActions = 0;
_numAttributes = 0;
_actions = NULL;
_attributes = NULL;
_lastActionName = NULL;
_lastActionOutput = NULL;
_lastActionStatus = 0;
AddToParent();
BaseObj *p = _parent;
while (p)
{
p->NotifyCreate(this);
p = p->_parent;
}
}
BaseObj::~BaseObj()
{
int i;
DeleteChildren();
DeleteFromParent();
BaseObj *parent = _parent;
while (parent)
{
parent->NotifyDelete(this);
parent = parent->_parent;
}
for (i = 0; i < _numAttributes; i++)
{
delete _attributes[i]->ReferenceName;
delete _attributes[i]->Value;
delete _attributes[i]->DisplayName;
delete _attributes[i]->DisplayValue;
delete _attributes[i]->DefaultValue;
delete _attributes[i]->DisplayDefaultValue;
delete _attributes[i]->Help;
delete _attributes[i]->ContextualHelp;
delete _attributes[i]->Listing;
delete _attributes[i]->Dependancies;
delete _attributes[i];
}
delete []_attributes;
for (i = 0; i < _numActions; i++)
{
delete _actions[i]->ReferenceName;
delete _actions[i]->DisplayName;
delete _actions[i]->Nmemonic;
delete _actions[i]->AcceleratorText;
delete _actions[i]->Accelerator;
delete _actions[i]->Help;
delete _actions[i]->ContextualHelp;
delete _actions[i]->Dependancies;
delete _actions[i];
}
delete []_actions;
delete []_children;
free(_lastActionName);
delete [] _lastActionOutput;
free(_details);
free(_displayName);
free(_name);
}
char *BaseObj::DisplayName()
{
if (!_displayName)
{
InitDisplayName();
if (!_displayName)
_displayName = STRDUP(_name);
}
return _displayName;
}
void BaseObj::ReadAttributes()
{
if (_init_attributes == false)
{
LoadAttributes(_numAttributes, _attributes);
_init_attributes = true;
}
}
char *BaseObj::Details()
{
if (!_details)
{
InitDetails();
if (!_details)
_details = STRDUP("");
}
return _details;
}
void BaseObj::UpdateDetails()
{
free(_details);
_details = NULL;
(void) Details();
}
void BaseObj::UpdateChildren()
{
DeleteChildren();
InitChildren();
_init_children = true;
}
BaseObj **BaseObj::Children()
{
if (_init_children == false)
{
InitChildren();
_init_children = true;
}
return _children;
}
int BaseObj::NumChildren()
{
if (_init_children == false)
{
InitChildren();
_init_children = true;
}
return _numChildren;
}
void BaseObj::DeleteAction(const char *name)
{
Action *action;
if (!HasAction(name, &action))
return;
Action **new_actions;
int i, index;
index = 0;
new_actions = new Action*[_numActions - 1];
for (i = 0; i < _numActions; i++)
if (_actions[i] != action)
new_actions[index++] = _actions[i];
delete action->ReferenceName;
delete action->DisplayName;
delete action->Nmemonic;
delete action->AcceleratorText;
delete action->Accelerator;
delete action->Help;
delete action->ContextualHelp;
delete action->Dependancies;
delete action;
delete []_actions;
_actions = new_actions;
_numActions--;
}
void BaseObj::DeleteAttribute(const char *name)
{
Attribute *attribute;
if (!HasAttribute(name, &attribute))
return;
Attribute **new_attributes;
int i, index;
index = 0;
new_attributes = new Attribute*[_numAttributes - 1];
for (i = 0; i < _numAttributes; i++)
if (_attributes[i] != attribute)
new_attributes[index++] = _attributes[i];
delete attribute->ReferenceName;
delete attribute->Value;
delete attribute->DisplayName;
delete attribute->DisplayValue;
delete attribute->DefaultValue;
delete attribute->DisplayDefaultValue;
delete attribute->Help;
delete attribute->ContextualHelp;
delete attribute->Listing;
delete attribute->Dependancies;
delete attribute;
delete []_attributes;
_attributes = new_attributes;
_numAttributes--;
}
void BaseObj::AddAttribute(const char *ReferenceName,
const char *DisplayName,
const char *Help,
const char *ContextualHelp,
Characteristics Mask,
ValueList ValueListType,
const char *Listing,
const char *Dependancies,
const char *DefaultValue,
const char *DisplayDefaultValue)
{
Attribute **new_attributes;
int i;
new_attributes = new Attribute*[_numAttributes + 1];
for (i = 0; i < _numAttributes; i++)
new_attributes[i] = _attributes[i];
delete []_attributes;
_attributes = new_attributes;
Attribute *attribute = new Attribute;
attribute->ReferenceName = STRDUP(ReferenceName);
attribute->Value = NULL;
attribute->DisplayName = STRDUP(DisplayName);
attribute->DisplayValue = NULL;
attribute->DefaultValue = STRDUP(DefaultValue);
attribute->DisplayDefaultValue = STRDUP(DisplayDefaultValue);
attribute->Mask = Mask;
attribute->Help = STRDUP(Help);
attribute->ContextualHelp = STRDUP(ContextualHelp);
attribute->Listing = STRDUP(Listing);
attribute->ValueListType = ValueListType;
attribute->Dependancies = STRDUP(Dependancies);
_attributes[_numAttributes] = attribute;
_numAttributes++;
}
void BaseObj::AddAction(ActionHandler Handler,
const char *ReferenceName,
const char *DisplayName,
const char *Nmemonic,
const char *Help,
const char *ContextualHelp,
boolean InputRequired,
const char *AcceleratorText,
const char *Accelerator,
const char *Dependancies)
{
Action **new_actions;
int i;
new_actions = new Action*[_numActions + 1];
for (i = 0; i < _numActions; i++)
new_actions[i] = _actions[i];
delete []_actions;
_actions = new_actions;
Action *action = new Action;
action->Handler = Handler;
action->ReferenceName = STRDUP(ReferenceName);
action->DisplayName = STRDUP(DisplayName);
action->Nmemonic = STRDUP(Nmemonic);
action->AcceleratorText = STRDUP(AcceleratorText);
action->Accelerator = STRDUP(Accelerator);
action->InputRequired = InputRequired;
action->Help = STRDUP(Help);
action->ContextualHelp = STRDUP(ContextualHelp);
action->Dependancies = STRDUP(Dependancies);
_actions[_numActions] = action;
_numActions++;
}
void BaseObj::AddToParent()
{
if (!_parent)
return;
BaseObj **new_children;
int i;
new_children = new BaseObj*[_parent->_numChildren + 1];
for (i = 0; i < _parent->_numChildren; i++)
new_children[i] = _parent->_children[i];
delete []_parent->_children;
_parent->_children = new_children;
_parent->_children[_parent->_numChildren] = this;
_parent->_numChildren++;
}
void BaseObj::DeleteFromParent()
{
if (!_parent)
return;
BaseObj **new_children;
int i, index;
index = 0;
new_children = new BaseObj*[_parent->_numChildren - 1];
for (i = 0; i < _parent->_numChildren; i++)
if (_parent->_children[i] != this)
new_children[index++] = _parent->_children[i];
delete []_parent->_children;
_parent->_children = new_children;
_parent->_numChildren--;
}
int BaseObj::NumSiblings()
{
if (_parent)
return _parent->_numChildren;
else
return 0;
}
BaseObj ** BaseObj::Siblings()
{
if (_parent)
return _parent->_children;
else
return NULL;
}
boolean BaseObj::HasAction(const char *actionName,
Action **action)
{
int i;
for (i = 0; i < _numActions; i++)
if (!strcmp(_actions[i]->ReferenceName, actionName))
{
*action = _actions[i];
return true;
}
return false;
}
boolean BaseObj::HasAction(Action *action)
{
Action *dummy;
if (action)
return HasAction(action->ReferenceName, &dummy);
else
return false;
}
boolean BaseObj::HasAction(const char *actionName)
{
Action *dummy;
return HasAction(actionName, &dummy);
}
boolean BaseObj::SendAction(Action *action,
BaseObj *requestor)
{
boolean status;
delete [] _lastActionOutput;
free(_lastActionName);
_lastActionOutput = NULL;
_lastActionName = strdup(action->ReferenceName);
if ((status = HasAction(action)) == true)
_lastActionStatus = (*action->Handler)(this, &_lastActionOutput,
requestor);
else
{
_lastActionStatus = -1;
int len = strlen("'%s' is not an action of %s") +
strlen(ObjectClassName()) + strlen(action->ReferenceName);
_lastActionOutput = new char [len];
sprintf(_lastActionOutput, "'%s' is not an action of %s",
ObjectClassName(), action->ReferenceName);
}
return status;
}
boolean BaseObj::SendAction(const char *actionName,
BaseObj *requestor)
{
Action *action;
(void) HasAction(actionName, &action);
return SendAction(action, requestor);
}
char * BaseObj::AttributeValue(char *referenceName)
{
Attribute *dummy;
ReadAttributes();
if (HasAttribute(referenceName, &dummy))
return dummy->Value;
else
return NULL;
}
boolean BaseObj::HasAttribute(const char *attributeName,
Attribute **attribute)
{
int i;
for (i = 0; i < _numAttributes; i++)
if (!strcmp(_attributes[i]->ReferenceName, attributeName))
{
*attribute = _attributes[i];
return true;
}
return false;
}
boolean BaseObj::HasAttribute(Attribute *attribute)
{
Attribute *dummy;
return HasAttribute(attribute->ReferenceName, &dummy);
}
boolean BaseObj::HasAttribute(const char *attributeName)
{
Attribute *dummy;
return HasAttribute(attributeName, &dummy);
}
void BaseObj::DeleteChildren()
{
if (_numChildren)
{
BaseObj **kids = new BaseObj*[_numChildren];
int i, n = _numChildren;
// Save children first before deleting a child since the destructor
// updates the _children variable
for (i = 0; i < n; i++)
kids[i] = _children[i];
for (i = 0; i < n; i++)
delete kids[i];
delete []kids;
}
}
// Dump object
void BaseObj::Dump(boolean verbose, int level)
{
int i, j;
for (i = 0; i < level; i++) printf(" ");
printf("%s : %s\n", Name(), ObjectClassName());
if (verbose)
{
for (i = -1; i <= level; i++) printf(" ");
printf("Display Name = '%s'\n", _displayName);
for (i = -1; i <= level; i++) printf(" ");
printf("Details = '%s'\n", _details);
for (i = -1; i <= level; i++) printf(" ");
printf("Number Actions = %d\n", _numActions);
for (j = 0; j < _numActions; j++)
{
for (i = -2; i <= level; i++) printf(" ");
printf("Action.%s = '%s'\n", _actions[j]->ReferenceName,
_actions[j]->DisplayName);
}
for (i = -1; i <= level; i++) printf(" ");
printf("Number Attributes = %d\n", _numAttributes);
for (j = 0; j < _numAttributes; j++)
{
for (i = -2; i <= level; i++) printf(" ");
printf("Attribute.%s = '%s'\n", _attributes[j]->ReferenceName,
_attributes[j]->DisplayValue);
}
for (i = -1; i <= level; i++) printf(" ");
printf("Number Children = %d\n", _numChildren);
}
}
// Dump object hierarchy
void BaseObj::DumpHierarchy(boolean verbose, int level)
{
int i;
Dump(verbose, level);
for (i = 0; i < _numChildren; i++)
_children[i]->DumpHierarchy(verbose, level + 1);
}
void BaseObj::Error(const char *message)
{
// Log Error
printf("%s: (%s) %s\n", ObjectClassName(), Name(), message);
}
int BaseObj::RunCommand(const char *command,
char **std_out,
char **std_err)
{
int status;
Invoke *_thread = new Invoke(command, std_out, std_err);
status = _thread->status;
delete _thread;
return status;
}

View File

@@ -0,0 +1,249 @@
/* $TOG: BaseObj.h /main/5 1998/04/06 13:34:28 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef BASEOBJ_H
#define BASEOBJ_H
#include <stdio.h>
#include "Invoke.h"
#ifndef _BOOLEAN_
#define _BOOLEAN_
#if (defined(sun) && OSMAJORVERSION <= 5 && OSMINORVERSION <= 3)|| defined(USL) || defined(__uxp__)
#include <sys/types.h>
#define boolean boolean_t
#define true B_TRUE
#define false B_FALSE
#elif defined(linux)
#define false 0
#define true 0
#define boolean int
#else
typedef enum
{
false = 0,
true = 1
} boolean;
#endif
#endif
#ifndef STRDUP
#define STRDUP(string) (string ? strdup(string) : NULL)
#define STRCMP(s1, s2) (s1 && s2 ? strcmp(s1, s2) : (s1 ? 1 : -1))
#define STRLEN(string) (string ? strlen(string) : 0)
#endif
typedef enum
{
STRING,
MULT_LINE_STRING,
INTEGER,
REAL,
FILE_NAME,
DIRECTORY_NAME,
HOST_NAME,
USER_NAME,
GROUP_NAME,
DATE,
TIME,
MONEY,
HOUR,
MINUTE,
SECOND,
DAY,
MONTH,
YEAR
} AttributeType;
typedef enum
{
OPTIONAL = 0,
ALLOW_DIRECT_ENTRY = 1,
REQUIRED = 2,
EDITABLE_AFTER_CREATE = 4,
EDITABLE_DURING_CREATE = 8,
ECHO_INPUT = 16
} Characteristics;
typedef enum
{
INFORMATION_LINE,
NO_LIST,
SINGLE_SELECT_LIST,
MULTI_SELECT_LIST,
RANGE,
MULTI_SELECT_MIN_RANGE,
MULTI_SELECT_MAX_RANGE,
MULTI_SELECT_RANGE
} ValueList;
#define AllowDirectEntry(attr) (attr->Mask & ALLOW_DIRECT_ENTRY)
#define IsRequired(attr) (attr->Mask & REQUIRED)
#define EditableAfterCreate(attr) (attr->Mask & EDITABLE_AFTER_CREATE)
#define EditableDuringCreate(attr) (attr->Mask & EDITABLE_DURING_CREATE)
#define EchoInput(attr) (attr->Mask & ECHO_INPUT)
typedef struct
{
char *ReferenceName;
AttributeType Type;
Characteristics Mask;
char *DisplayName;
char *Value;
char *DisplayValue;
char *DefaultValue;
char *DisplayDefaultValue;
char *Help;
char *ContextualHelp;
ValueList ValueListType;
char *Listing;
char *Dependancies;
// The base class initializes the next 4 variables
int n_values;
char **CompiledValueList;
char **CompiledDisplayValueList;
char **CompiledHelpValueList;
} Attribute;
class BaseObj;
typedef int (*ActionHandler) (BaseObj *, char **output, BaseObj *requestor);
typedef struct
{
ActionHandler Handler;
char *ReferenceName;
char *DisplayName;
char *Nmemonic;
char *Help;
char *ContextualHelp;
char *AcceleratorText;
char *Accelerator;
boolean InputRequired;
char *Dependancies;
} Action;
extern const char *ACTION_NOT_FOUND;
class BaseObj {
protected:
char *_name;
char *_displayName;
char *_details;
BaseObj *_parent;
BaseObj **_children;
int _numChildren;
Attribute **_attributes;
int _numAttributes;
Action **_actions;
int _numActions;
boolean _init_children;
boolean _init_attributes;
char *_lastActionName;
char *_lastActionOutput;
int _lastActionStatus;
BaseObj(BaseObj *parent,
const char *name);
void AddToParent();
void DeleteFromParent();
void DeleteAttribute(const char *ReferenceName);
void AddAttribute(const char *ReferenceName,
const char *DisplayName = NULL,
const char *Help = NULL,
const char *ContextualHelp = NULL,
Characteristics Mask = OPTIONAL,
ValueList ValueListType = NO_LIST,
const char *Listing = NULL,
const char *Dependancies = NULL,
const char *DefaultValue = NULL,
const char *DisplayDefaultValue = NULL);
void DeleteAction(const char *ReferenceName);
void AddAction(ActionHandler Handler,
const char *ReferenceName,
const char *DisplayName = NULL,
const char *Nmemonic = NULL,
const char *Help = NULL,
const char *ContextualHelp = NULL,
boolean InputRequired = false,
const char *AcceleratorText = NULL,
const char *Accelerator = NULL,
const char *Dependancies = NULL);
// Derived classes should redefine these functions
virtual void InitChildren() { _children = NULL; _numChildren = 0; }
virtual void InitDetails() { }
virtual void LoadAttributes(int /*n_attrs*/, Attribute ** /*attrs*/) { }
virtual void InitDisplayName() { }
// These messages are sent to all parents
virtual void NotifyCreate(BaseObj *) { } ;
virtual void NotifyDelete(BaseObj *) { } ;
public:
virtual ~BaseObj(); // destructor
boolean HasAttribute(Attribute *action);
boolean HasAttribute(const char *ReferenceName);
boolean HasAttribute(const char *ReferenceName, Attribute **action);
boolean HasAction(Action *action);
boolean HasAction(const char *ReferenceName);
boolean HasAction(const char *ReferenceName, Action **action);
boolean SendAction(Action *action,
BaseObj *requestor = NULL);
boolean SendAction(const char *ReferenceName,
BaseObj *requestor = NULL);
char * LastActionName() { return _lastActionName; }
char * LastActionOutput() { return _lastActionOutput; }
int LastActionStatus() { return _lastActionStatus; }
const char * Name() { return _name; }
char * DisplayName();
char * Details();
char * AttributeValue(char *ReferenceName);
BaseObj * Parent() { return _parent; }
const int NumActions() { return _numActions; }
const int NumAttributes() { return _numAttributes; }
Action **Actions() { return _actions; }
Attribute **Attributes() { return _attributes; }
BaseObj ** Children();
int NumChildren();
void ReadAttributes();
void UpdateChildren();
void UpdateDetails();
void DeleteChildren();
void SetInitChildren() { _init_children = true; }
int RunCommand(const char *command,
char **std_out = NULL,
char **std_err = NULL);
// These are for children
BaseObj ** Siblings();
int NumSiblings();
// Log Error message
void Error(const char *message);
// Dumps object to stdout
void Dump(boolean verbose = false,
int level = 0);
// Dumps object heirarchy to stdout
void DumpHierarchy(boolean verbose = false,
int level = 0);
virtual const char *const ObjectClassName() { return "BaseObj"; }
};
#endif // BASEOBJ_H

View File

@@ -0,0 +1,31 @@
XCOMM $TOG: Imakefile /main/5 1998/08/25 12:59:24 mgreess $
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
#define IHaveSubdirs
#define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)' 'CXXDEBUGFLAGS=$(CXXDEBUGFLAGS)'
SUBDIRS = PrintObj
MakeSubdirs($(SUBDIRS))
DependSubdirs($(SUBDIRS))
INCLUDES = -I. -I.. -I./PrintObj -I../util
#ifdef SunArchitecture
.NO_PARALLEL:
#endif
#ifdef RsArchitecture
EXTRA_DEFINES = -DHAS_EXCEPTIONS
#endif
SRCS = BaseObj.C
OBJS = BaseObj.o
NormalCplusplusObjectRule()
all:: $(OBJS)
clean::
$(RM) *.map

View File

@@ -0,0 +1,28 @@
XCOMM $XConsortium: Imakefile /main/4 1996/04/21 19:52:17 drk $
#define DoNormalLib YES
#define DoSharedLib NO
#define DoDebugLib NO
#define DoProfileLib NO
#define LibName PrintObj
#define LibHeaders NO
#define LibInstall NO
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
INCLUDES = -I. -I.. -I../.. -I../../util
#ifdef RsArchitecture
DEFINES = -DHAS_EXCEPTIONS
#endif
#ifdef AlphaArchitecture
DEFINES = -UNO_REGCOMP
#endif
SRCS = ParseJobs.C PrintJob.C PrintSubSys.C Queue.C
OBJS = ParseJobs.o PrintJob.o PrintSubSys.o Queue.o
#include <Library.tmpl>
DependTarget()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,64 @@
/* $XConsortium: ParseJobs.h /main/3 1995/11/06 09:46:45 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef PARSEJOBS_H
#define PARSEJOBS_H
typedef enum
{
UNKNOWN_OUTPUT,
AIX_V2_OUTPUT,
AIX_V3_OUTPUT,
BSD_OUTPUT
} JobOutputType;
extern JobOutputType DetermineOutput(char *output);
// returns socket to print server, or -1 if error
// timeout is in seconds, a default of 5 is used if timeout <= 0.
extern int ConnectToPrintServer(const char *server, int timeout);
// return 0 if error, otherwise return 1 if successful
extern int SendPrintJobStatusReguest(int sockfd, const char *printer);
extern void LocalPrintJobs(
char *printer,
char **return_job_list,
int *return_n_jobs);
extern int RemotePrintJobs(
char *server,
char *printer,
char **return_job_list,
int *return_n_jobs);
extern int ParseRemotePrintJobs(
char *printer,
char *jobs,
char **return_job_list,
int *return_n_jobs);
extern int ParseBSDPrintJobs(
char *printer,
char *jobs,
char **return_job_list,
int *return_n_jobs);
extern int ParseAIXv3PrintJobs(
char *printer,
char *jobs,
char **return_job_list,
int *return_n_jobs);
extern int ParseAIXv2PrintJobs(
char *printer,
char *jobs,
char **return_job_list,
int *return_n_jobs);
#endif // PARSEJOBS_H

View File

@@ -0,0 +1,107 @@
/* $TOG: PrintJob.C /main/6 1998/07/24 16:17:39 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "PrintJob.h"
// Object Class Name
const char *PRINTJOB = "PrintJob";
// Actions
const char *CANCEL_PRINT_JOB = "CancelPrintJob";
// Attributes
const char *PRINTJOB_NAME = "PrintJobName";
const char *OWNER = "Owner";
const char *JOB_NUMBER = "JobNumber";
const char *JOB_SIZE = "JobSize";
const char *SUBMITTED = "Submitted";
const char *DATE_SUBMITTED = "DateSubmitted";
const char *TIME_SUBMITTED = "TimeSubmitted";
PrintJob::PrintJob(BaseObj *parent,
char *JobName,
char *JobNumber,
char *Owner,
char *Date,
char *Time,
char *Size)
: BaseObj(parent, JobName)
{
AddAction(&PrintJob::CancelJob, CANCEL_PRINT_JOB, MESSAGE(CancelChoiceL),
MESSAGE(CancelMnemonicL), NULL, NULL, true,
MESSAGE(CancelAcceleratorL), "<Key>osfDelete");
char *Help = NULL, *ContextualHelp = NULL, *Listing = NULL;
Characteristics Mask = OPTIONAL;
ValueList ValueListType = NO_LIST;
int n = 0;
AddAttribute(PRINTJOB_NAME, MESSAGE(JobNameL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(JobName);
_attributes[n]->DisplayValue = STRDUP(JobName);
n++;
AddAttribute(OWNER, MESSAGE(OwnerL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Owner);
_attributes[n]->DisplayValue = STRDUP(Owner);
n++;
AddAttribute(JOB_NUMBER, MESSAGE(JobNumberL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(JobNumber);
_attributes[n]->DisplayValue = STRDUP(JobNumber);
_jobNumber = _attributes[n]->DisplayValue;
n++;
AddAttribute(JOB_SIZE, MESSAGE(SizeL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Size);
_attributes[n]->DisplayValue = STRDUP(Size);
n++;
ValueListType = INFORMATION_LINE;
AddAttribute(SUBMITTED, MESSAGE(SubmittedL),
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Time);
_attributes[n]->DisplayValue = STRDUP(Time);
n++;
ValueListType = NO_LIST;
char *message = new char [strlen(MESSAGE(TimeL)) + 4];
sprintf(message, " %s", MESSAGE(TimeL));
AddAttribute(TIME_SUBMITTED, message,
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Time);
_attributes[n]->DisplayValue = STRDUP(Time);
delete [] message;
n++;
message = new char [strlen(MESSAGE(DateL)) + 4];
sprintf(message, " %s", MESSAGE(DateL));
AddAttribute(DATE_SUBMITTED, message,
Help, ContextualHelp, Mask, ValueListType, Listing);
_attributes[n]->Value = STRDUP(Date);
_attributes[n]->DisplayValue = STRDUP(Date);
delete [] message;
}
PrintJob::~PrintJob()
{
// Empty
}
int PrintJob::CancelJob(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
static char command[256];
PrintJob *me = (PrintJob *) obj;
#ifdef aix
sprintf(command, "enq -P%s -x%s", me->Parent()->Name(), me->_jobNumber);
#elif __osf__
sprintf(command, "lprm -P%s %s", me->Parent()->Name(), me->_jobNumber);
#else
sprintf(command, "cancel %s-%s", me->Parent()->Name(), me->_jobNumber);
#endif
return me->RunCommand(command, NULL, output);
}

View File

@@ -0,0 +1,54 @@
/* $XConsortium: PrintJob.h /main/3 1995/11/06 09:47:08 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef PRINTJOB_H
#define PRINTJOB_H
#include "BaseObj.h"
#include "dtprintinfomsg.h"
#include <string.h>
// Object Class Name
extern const char *PRINTJOB;
// Actions
extern const char *CANCEL_PRINT_JOB;
// Attributes
extern const char *PRINTJOB_NAME;
extern const char *OWNER;
extern const char *JOB_NUMBER;
extern const char *JOB_SIZE;
extern const char *SUBMITTED;
extern const char *DATE_SUBMITTED;
extern const char *TIME_SUBMITTED;
class PrintJob : public BaseObj {
friend int CancelJob(BaseObj *, char **output, BaseObj *requestor);
protected:
char *_jobNumber;
static int CancelJob(BaseObj *, char **output, BaseObj *requestor);
public:
PrintJob(BaseObj *parent, char *JobName, char *JobNumber, char *Owner,
char *Date, char *Time, char *Size);
virtual ~PrintJob();
const char *JobNumber() { return _jobNumber; }
virtual const char *const ObjectClassName() { return PRINTJOB; }
};
#endif // PRINTJOB_H

View File

@@ -0,0 +1,86 @@
/* $XConsortium: PrintSubSys.C /main/4 1996/01/17 18:02:47 lehors $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "PrintSubSys.h"
#include "Queue.h"
#include <string.h>
#ifdef aix
const char *LIST_QUEUES = "lsallq | grep -v '^bsh$' | sort";
#else
#ifdef hpux
const char *LIST_QUEUES = "LANG=C lpstat -v | "
"awk '"
" $2 == \"for\" "
" { "
" x = match($3, /:/); "
" print substr($3, 1, x-1)"
" }' | sort";
#else
#ifdef __osf__
const char *LIST_QUEUES = "LANG=C lpstat -v | "
"nawk '"
" $2 == \"for\" "
" { print $10 }' "
" | sort";
#else
#ifdef __uxp__
const char *LIST_QUEUES = "LANG=C lpstat -v | "
"nawk '"
" $4 == \"for\" "
" { "
" x = match($5, /:/); "
" print substr($5, 1, x-1)"
" }' | sort";
#else
const char *LIST_QUEUES = "LANG=C lpstat -v | "
"nawk '"
" $2 == \"for\" "
" { "
" x = match($3, /:/); "
" print substr($3, 1, x-1)"
" }' | sort";
#endif
#endif
#endif
#endif
// Object Class Name
const char *PRINTSUBSYSTEM = "PrintSubSystem";
PrintSubSystem::PrintSubSystem(BaseObj *parent)
: BaseObj(parent, "PrintSubSystem")
{
_displayName = strdup(MESSAGE(PrinterMenuL));
_details = strdup("Status Number Owner Date Time Size");
}
PrintSubSystem::~PrintSubSystem()
{
// Empty
}
void PrintSubSystem::InitChildren()
{
char *std_out;
if (RunCommand(LIST_QUEUES, &std_out))
{
Error("InitChildren method could not list queues.");
}
else
{
char *queue = strtok(std_out, " \n");
while (queue && *queue)
{
new Queue(this, queue);
queue = strtok(NULL, " \n");
}
}
delete std_out;
}

View File

@@ -0,0 +1,36 @@
/* $XConsortium: PrintSubSys.h /main/3 1995/11/06 09:47:33 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef PRINTSUBSYS_H
#define PRINTSUBSYS_H
#include "BaseObj.h"
#include "dtprintinfomsg.h"
// Object Class Name
extern const char *PRINTSUBSYSTEM;
// List Children command;
extern const char *LIST_QUEUES;
class PrintSubSystem : public BaseObj {
protected:
void InitChildren();
public:
PrintSubSystem(BaseObj *parent);
virtual ~PrintSubSystem();
virtual const char *const ObjectClassName() { return PRINTSUBSYSTEM; }
};
#endif // PRINTSUBSYS_H

View File

@@ -0,0 +1,440 @@
/* $TOG: Queue.C /main/4 1998/07/24 16:17:58 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#include "Queue.h"
#include "PrintJob.h"
#include "ParseJobs.h"
#include <stdlib.h>
extern "C" {
#include <Dt/DtNlUtils.h>
}
#ifdef aix
const char *GET_ATTRS = "lsque -cq%s |awk -F: 'NR == 2 {print $2,$6,$9}' OFS=:";
const char *GET_QUEUE_STATUS = "LANG=C enq -As -P%s | "
"egrep 'READY|RUNNING' > /dev/null";
const char *GET_DEVICE_STATUS = "LANG=C enq -As -P%s | "
"egrep 'READY|RUNNING' > /dev/null";
const char *START_QUEUE_CMD = "enq -U -P%s";
const char *STOP_QUEUE_CMD = "enq -D -P%s";
#else
#ifdef hpux
const char *GET_ATTRS = "LANG=C lpstat -v%s 2>&1 | awk '"
"BEGIN { device=\"\"; rhost=\"\"; rp=\"\" } "
"/device for/ { device = $4 } "
"/remote to/ { rhost = $5; rp = $3 } "
"END { print device,rhost,rp }' OFS=:";
const char *GET_QUEUE_STATUS = "LANG=C lpstat -i -a%s | awk '"
"{if ($2 == \"not\") {exit 1} else {exit 0}}'";
const char *GET_DEVICE_STATUS = "LANG=C lpstat -i -p%s | "
"awk '/disabled/ {exit 1}'";
const char *START_QUEUE_CMD = "/usr/lib/accept %s";
const char *STOP_QUEUE_CMD = "/usr/lib/reject %s";
const char *START_PRINTING_CMD = "enable %s";
const char *STOP_PRINTING_CMD = "disable %s";
#else
const char *GET_ATTRS = "LANG=C lpstat -v %s 2>&1 | nawk '"
"BEGIN { device=\"\"; rhost=\"\"; rp=\"\" } "
"/device for/ { device = $4 } "
"/system for/ { rhost = $4; x = match($7, /\\)/); "
" if (x == 0) "
" rp = substr($3, 1, match($3, /:/) - 1); "
" else "
" rp = substr($7, 1, x - 1) } "
"END { print device,rhost,rp }' OFS=:";
const char *GET_QUEUE_STATUS = "LANG=C lpstat -a%s | awk '"
"{if ($2 == \"not\") {exit 1} else {exit 0}}'";
const char *GET_DEVICE_STATUS = "LANG=C lpstat -p%s | "
"awk '/disabled/ {exit 1}'";
const char *START_QUEUE_CMD = "/usr/sbin/accept %s";
const char *STOP_QUEUE_CMD = "/usr/sbin/reject %s";
const char *START_PRINTING_CMD = "enable %s";
const char *STOP_PRINTING_CMD = "disable %s";
#endif
#endif
// Object Class Name
const char *QUEUE = "Queue";
// Actions
const char *START_QUEUE = "StartQueue";
const char *STOP_QUEUE = "StopQueue";
#ifndef aix
const char *START_PRINTING = "StartPrinting";
const char *STOP_PRINTING = "StopPrinting";
#endif
// Attributes
const char *ICON_NAME = "IconName";
const char *PRINTER_QUEUE = "PrinterQueue";
const char *QUEUE_DEVICE = "QueueDevice";
Queue::Queue(BaseObj *parent,
char *_name)
: BaseObj(parent, _name)
{
if (getenv("DO_ADMIN"))
{
AddAction(&Queue::Start, START_QUEUE, MESSAGE(StartChoiceL),
MESSAGE(StartMnemonicL));
AddAction(&Queue::Stop, STOP_QUEUE, MESSAGE(StopChoiceL),
MESSAGE(StopMnemonicL));
#ifndef aix
AddAction(&Queue::StartPrint, START_PRINTING, MESSAGE(EnableChoiceL),
MESSAGE(EnableMnemonicL));
AddAction(&Queue::StopPrint, STOP_PRINTING, MESSAGE(DisableChoiceL),
MESSAGE(DisableMnemonicL));
#endif
}
#ifdef aix
local_devices = NULL;
n_devices = 0;
#endif
remote_server = NULL;
remote_printer = NULL;
is_remote = false;
_loaded_attributes = false;
char *Help = NULL, *ContextualHelp = NULL, *Listing = NULL;
Characteristics Mask = EDITABLE_AFTER_CREATE;
ValueList ValueListType = NO_LIST;
// AddAttribute(ICON_NAME, MESSAGE(IconNameL),
// Help, ContextualHelp, Mask, ValueListType, Listing);
Mask = OPTIONAL;
AddAttribute(PRINTER_QUEUE, MESSAGE(PrintQueueL),
Help, ContextualHelp, Mask, ValueListType, Listing);
AddAttribute(QUEUE_DEVICE, MESSAGE(DeviceL),
Help, ContextualHelp, Mask, ValueListType, Listing);
}
Queue::~Queue()
{
#ifdef aix
int i;
for (i = 0; i < n_devices; i++)
delete local_devices[i];
delete local_devices;
#endif
delete remote_server;
delete remote_printer;
}
void Queue::LoadAttributes(int /*n_attrs*/, Attribute **attrs)
{
char *command = new char[500];
sprintf(command, GET_ATTRS, Name());
char *output;
RunCommand(command, &output);
delete [] command;
char *s = output, *s1;
char *dollar[3];
int i;
for (i = 0; i < 3; i++)
{
if (s1 = strchr(s, ':'))
*s1++ = '\0';
else if (s1 = strchr(s, '\n'))
*s1++ = '\0';
dollar[i] = s;
s = s1;
}
i = 0;
attrs[i]->Value = strdup(Name());
attrs[i]->DisplayValue = strdup(Name());
i++;
if (_loaded_attributes == false)
{
if (*dollar[2]) // It's a remote printer
{
#ifdef aix
n_devices = 1;
local_devices = new char *[1];
local_devices[0] = new char[strlen(Name()) + strlen(dollar[0]) + 2];
sprintf(local_devices[0], "%s:%s", Name(), dollar[0]);
#endif
is_remote = true;
char *new_value = new char [strlen(MESSAGE(PrinterOnServerL)) +
strlen(dollar[1]) + strlen(dollar[2])];
remote_server = strdup(dollar[1]);
remote_printer = strdup(dollar[2]);
sprintf(new_value, MESSAGE(PrinterOnServerL), remote_printer,
remote_server);
attrs[i]->Value = strdup(new_value);
attrs[i]->DisplayValue = strdup(new_value);
delete [] new_value;
}
else // It's a local printer
{
#ifdef aix
if (strchr(dollar[0], ',')) // AIX can have multiple devices per queue
{
DeleteAttribute(QUEUE_DEVICE);
char *device = new char [strlen(MESSAGE(DeviceNL)) + 4];
s = dollar[0];
while (s && *s)
{
if (s1 = strchr(s, ','))
s1++;
s = s1;
n_devices++;
}
local_devices = new char *[n_devices];
n_devices = 0;
s = dollar[0];
while (s && *s)
{
sprintf(device, MESSAGE(DeviceNL), n_devices + 1);
AddAttribute(QUEUE_DEVICE, device,
NULL, NULL, OPTIONAL, NO_LIST, NULL);
if (s1 = strchr(s, ','))
*s1++ = '\0';
_attributes[i]->Value = strdup(s);
_attributes[i]->DisplayValue = strdup(s);
local_devices[n_devices] = new char[strlen(Name()) + strlen(s)+2];
sprintf(local_devices[n_devices], "%s:%s", Name(), s);
i++;
s = s1;
n_devices++;
}
delete [] device;
}
else
#endif
{
#ifdef aix
n_devices = 1;
local_devices = new char *[1];
local_devices[0] = new char[strlen(Name()) + strlen(dollar[0]) + 2];
sprintf(local_devices[0], "%s:%s", Name(), dollar[0]);
#endif
attrs[i]->Value = strdup(dollar[0]);
attrs[i]->DisplayValue = strdup(dollar[0]);
}
}
_loaded_attributes = true;
}
delete output;
}
#ifdef aix
char *Queue::Device(int index)
{
if (_loaded_attributes == false)
ReadAttributes();
if (index >= 0 && index <= n_devices)
return local_devices[index];
else
return NULL;
}
int Queue::NumberDevices()
{
if (_loaded_attributes == false)
ReadAttributes();
return n_devices;
}
#endif
int Queue::Start(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
Queue *queue = (Queue *)obj;
int rc;
char *command = new char[100];
#ifdef aix
if (queue->n_devices > 1)
{
sprintf(command, START_QUEUE_CMD, "$d");
int i, len;
len = 30 + strlen(command) + queue->n_devices;
for (i = 0; i < queue->n_devices; i++)
len += strlen(queue->local_devices[i]);
char *cmd = new char[len];
strcpy(cmd, "for d in");
for (i = 0; i < queue->n_devices; i++)
{
strcat(cmd, " ");
strcat(cmd, queue->local_devices[i]);
}
strcat(cmd, " ; do ");
strcat(cmd, command);
strcat(cmd, "; done");
rc = queue->RunCommand(cmd, NULL, output);
delete [] cmd;
}
else
#endif
{
sprintf(command, START_QUEUE_CMD, queue->Name());
rc = queue->RunCommand(command, NULL, output);
}
delete [] command;
return rc;
}
int Queue::Stop(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
Queue *queue = (Queue *)obj;
char *command = new char[100];
int rc;
#ifdef aix
if (queue->n_devices > 1)
{
sprintf(command, STOP_QUEUE_CMD, "$d");
int i, len;
len = 30 + strlen(command) + queue->n_devices;
for (i = 0; i < queue->n_devices; i++)
len += strlen(queue->local_devices[i]);
char *cmd = new char[len];
strcpy(cmd, "for d in");
for (i = 0; i < queue->n_devices; i++)
{
strcat(cmd, " ");
strcat(cmd, queue->local_devices[i]);
}
strcat(cmd, " ; do ");
strcat(cmd, command);
strcat(cmd, "; done");
rc = queue->RunCommand(cmd, NULL, output);
delete [] cmd;
}
else
#endif
{
sprintf(command, STOP_QUEUE_CMD, queue->Name());
rc = queue->RunCommand(command, NULL, output);
}
delete [] command;
return rc;
}
#ifndef aix
int Queue::StartPrint(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
Queue *queue = (Queue *)obj;
char *command = new char[100];
int rc;
sprintf(command, STOP_PRINTING_CMD, queue->Name());
rc = queue->RunCommand(command, NULL, output);
delete [] command;
return rc;
}
int Queue::StopPrint(BaseObj *obj, char **output, BaseObj * /*requestor*/)
{
Queue *queue = (Queue *)obj;
char *command = new char[100];
int rc;
sprintf(command, STOP_PRINTING_CMD, queue->Name());
rc = queue->RunCommand(command, NULL, output);
delete [] command;
return rc;
}
#endif
void Queue::InitChildren()
{
if (_loaded_attributes == false)
ReadAttributes();
ProcessJobs();
}
void Queue::ProcessJobs(char *jobs)
{
char *job_list;
int n_jobs;
// Get remote jobs first
if (is_remote)
{
int rc;
if (jobs)
rc = ParseRemotePrintJobs(remote_printer, jobs, &job_list, &n_jobs);
else
rc = RemotePrintJobs(remote_server, remote_printer, &job_list,
&n_jobs);
remote_up = rc ? true : false;
ParseOutput(job_list, n_jobs);
#ifdef sun
return;
#endif
}
// Get local jobs next
#ifdef aix
if (is_remote)
LocalPrintJobs(local_devices[0], &job_list, &n_jobs);
else
LocalPrintJobs((char*)Name(), &job_list, &n_jobs);
#else
LocalPrintJobs((char*)Name(), &job_list, &n_jobs);
#endif
ParseOutput(job_list, n_jobs);
}
void Queue::ParseOutput(char *job_list, int n_jobs)
{
int i;
char *printer = DtStrtok(job_list, "|");
for (i = 0; i < n_jobs; i++)
{
char *JobName = DtStrtok(NULL, "|");
char *JobNumber = DtStrtok(NULL, "|");
char *Owner = DtStrtok(NULL, "|");
char *Date = DtStrtok(NULL, "|");
char *Time = DtStrtok(NULL, "|");
char *tmp = DtStrtok(NULL, "\n");
char *Size = new char [strlen(tmp) + strlen(MESSAGE(BytesL)) + 2];
sprintf(Size, "%s %s", tmp, MESSAGE(BytesL));
new PrintJob(this, JobName, JobNumber, Owner, Date, Time, Size);
delete [] Size;
printer = DtStrtok(NULL, "|");
}
}
void Queue::ParseRemoteStatus(char *output)
{
SetInitChildren();
DeleteChildren();
if (_loaded_attributes == false)
ReadAttributes();
ProcessJobs(output);
}
boolean Queue::IsRemote()
{
if (_loaded_attributes == false)
ReadAttributes();
return is_remote;
}
const char *Queue::RemotePrinter()
{
if (_loaded_attributes == false)
ReadAttributes();
return remote_printer;
}
const char *Queue::Server()
{
if (_loaded_attributes == false)
ReadAttributes();
return remote_server;
}

View File

@@ -0,0 +1,89 @@
/* $XConsortium: Queue.h /main/3 1995/11/06 09:47:44 rswiston $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef QUEUE_H
#define QUEUE_H
#include "BaseObj.h"
#include "dtprintinfomsg.h"
// Object Class Name
extern const char *QUEUE;
// Actions
extern const char *START_QUEUE;
extern const char *STOP_QUEUE;
#ifndef aix
extern const char *START_PRINTING;
extern const char *STOP_PRINTING;
#endif
// Attributes
extern const char *ICON_NAME;
extern const char *PRINTER_QUEUE;
extern const char *QUEUE_DEVICE;
// Status Commands
extern const char *GET_QUEUE_STATUS;
extern const char *GET_DEVICE_STATUS;
class Queue : public BaseObj {
friend int Start(BaseObj *, char **output, BaseObj *requestor);
friend int Stop(BaseObj *, char **output, BaseObj *requestor);
#ifndef aix
friend int StartPrint(BaseObj *, char **output, BaseObj *requestor);
friend int StopPrint(BaseObj *, char **output, BaseObj *requestor);
#endif
protected:
static int Start(BaseObj *, char **output, BaseObj *requestor);
static int Stop(BaseObj *, char **output, BaseObj *requestor);
#ifndef aix
static int StartPrint(BaseObj *, char **output, BaseObj *requestor);
static int StopPrint(BaseObj *, char **output, BaseObj *requestor);
#endif
boolean _loaded_attributes;
void InitChildren();
void LoadAttributes(int numAttributes, Attribute **attributes);
void ParseOutput(char *, int);
void ProcessJobs(char *jobs = NULL);
boolean is_remote;
boolean remote_up;
#ifdef aix
char **local_devices;
int n_devices;
#endif
char *remote_server;
char *remote_printer;
public:
Queue(BaseObj *parent, char *name);
virtual ~Queue();
const char *Server();
const char *RemotePrinter();
#ifdef aix
char *Device(int index = 0);
int NumberDevices();
#endif
boolean IsRemote();
boolean RemoteUp() { return remote_up; }
void ParseRemoteStatus(char *output);
virtual const char *const ObjectClassName() { return QUEUE; }
};
#endif // QUEUE_H