From 84272a2b1223df6e244528f1eff7cec06a3b06eb Mon Sep 17 00:00:00 2001 From: William Ferrell Date: Sat, 11 Dec 1999 19:00:33 +0000 Subject: [PATCH] Removed old/ and tests/ from distribution -- these were barely useful for the original developers, and are *definitely* not useful anymore :) --- old/LCDproc_objectmethods.txt | 49 -- old/LCDproc_objects.txt | 92 --- old/cfg.c | 443 ------------- old/cfg.h | 70 --- old/cfg_test.c | 76 --- old/cfg_testfile.cfg | 15 - old/change.log | 73 --- old/llistd.c | 429 ------------- old/llistd.h | 63 -- old/main.c | 318 ---------- old/main.h | 16 - old/menu.c | 162 ----- old/menu.h | 58 -- old/mode.c | 1107 --------------------------------- old/mode.h | 30 - old/sockets.c | 273 -------- old/sockets.h | 99 --- old/stat.c | 644 ------------------- old/stat.h | 58 -- tests/LL_test.c | 156 ----- tests/Makefile | 128 ---- tests/bartest | 42 -- tests/ctest.c | 30 - tests/drv_test.c | 54 -- tests/lcd.c | 638 ------------------- tests/menutest.c | 88 --- tests/script | 20 - tests/script.1 | 23 - tests/script.2 | 11 - tests/script.3 | 21 - tests/socktest.c | 44 -- tests/srvtest.c | 144 ----- tests/test | 75 --- 33 files changed, 5549 deletions(-) delete mode 100644 old/LCDproc_objectmethods.txt delete mode 100644 old/LCDproc_objects.txt delete mode 100644 old/cfg.c delete mode 100644 old/cfg.h delete mode 100644 old/cfg_test.c delete mode 100644 old/cfg_testfile.cfg delete mode 100644 old/change.log delete mode 100644 old/llistd.c delete mode 100644 old/llistd.h delete mode 100644 old/main.c delete mode 100644 old/main.h delete mode 100644 old/menu.c delete mode 100644 old/menu.h delete mode 100644 old/mode.c delete mode 100644 old/mode.h delete mode 100644 old/sockets.c delete mode 100644 old/sockets.h delete mode 100644 old/stat.c delete mode 100644 old/stat.h delete mode 100644 tests/LL_test.c delete mode 100644 tests/Makefile delete mode 100644 tests/bartest delete mode 100644 tests/ctest.c delete mode 100644 tests/drv_test.c delete mode 100644 tests/lcd.c delete mode 100644 tests/menutest.c delete mode 100644 tests/script delete mode 100644 tests/script.1 delete mode 100644 tests/script.2 delete mode 100644 tests/script.3 delete mode 100644 tests/socktest.c delete mode 100644 tests/srvtest.c delete mode 100644 tests/test diff --git a/old/LCDproc_objectmethods.txt b/old/LCDproc_objectmethods.txt deleted file mode 100644 index 7dea5eb..0000000 --- a/old/LCDproc_objectmethods.txt +++ /dev/null @@ -1,49 +0,0 @@ -Object methods and properties and some vars - -Tcomms - Properties - int InboundFD (for select to watch if>0) - IMODE imode {none,polled,fd} (method for reading data) - Tconfig config - Methods - ParseConfig(TConfig config) - Init - poll - writechar - writestr - -Tserial - Private Vars - char port[] - int speed - Properties - - - -Tdriver - Properties - Tconfig config - int backlight_state - int disp_width - int disp_height - Methods - Init - ClearScr - NewCustomChar(struct CustChar defination) - PutCustChar(zoff,yoff,char) - PutChar(xoff,yoff,char) - PlaceString(xoff,yoff,string) - DrawHorizBar(xoff,yoff,chwidth,percentage) - DrawVertBar(xoff,yoff,chheight,percentage) - - - -Tdisplay - Properties - Tdriver driver - Tconfig config - int RefreshInterval (for clock would be 500 for every half second) - Methods - HardInit (called once on prog start) - Init (called on every new cycle) - diff --git a/old/LCDproc_objects.txt b/old/LCDproc_objects.txt deleted file mode 100644 index ba1ee9f..0000000 --- a/old/LCDproc_objects.txt +++ /dev/null @@ -1,92 +0,0 @@ -LCDproc suggestion object hierarchy - -Tdriver - TVirtualDriver - TMtxOrbDriver - TTextDriver - -Tcomms - TSerial - TParallel - TSCSI - -Tdisplay - Tclock_dsp - Tmail_dsp - Tcpustate_dsp - Tcpugraph_dsp - Tmeminf_dsp - Tuptime_dsp - Txload_dsp - Tcredits_dsp - Theartbeat_dsp - Tstub_dsp - Tusercfg_dsp - -Tremote - Ttcpsockd - TUNIXsockd - -Tchannel - Ttcpsocket - TUNIXsocket - -Tconfig - -Tfeedback - TMtxOrb_keypad - Tserial_buttons - -Tschedular - ---------------------------------------------------- - -Object brief descriptions - -Tdriver (and decendants) provide manipulation of the physical -LCD panel including backlight, typeface loading, etc. -Tdriver will provide default methods for tasks such as - text centering - scrolling - screen clearing - etc - TVirtualDriver could act as a frame buffer / virtual display. - This would allow several display objects to access the (virtual) - display in a single cycle and then the virtual driver can flush - the changes from the last display (delta display) in a single pass. - This provides a portable way to implement display objects - (like the heartbeat which only changes one character at a time) - but overlap a standard full screen display - - - Tcomms (and decendants) transmit and receive all data to and - from the communications interfaces. Tdriver and Tfeedback will - use these objects directly. - - Tdisplay (and decendants) generate the actual display information - by manipulating the Tdriver object which has been given to it. - The Tdriver object should usually be a TVirtualDriver descendant. - - Tremote (and decendants) create, keep track of and ultimately destroy - Tchannel objects. Each Tchannel can potentitally be an external - connection to a remote client. The remote client can generate - either complete screens in a similar style to a Tdisplay object with - Tchannel using a Tstub_dsp to generate the screen based on info - supplied to it or it can feed data into an existing Tdisplay object - (Tchannel will do this by setting Tdisplay properties). - - Tconfig is responsible for parsing the command line and reading/re-reading - the contents of a configuration file. - - Tfeedback (and its descendants) may communicate with a Tcomms object to - retrieve information from a keypad or other input device. - - Tschedular is responsible for the overall co-ordination of everything. - - -Other notes: - I can't decide things like "should scroll stuff be down to Tdriver - or Tdisplay?". - Some sort of Thash would be a useful way of passing data from - sockets to display objects as well - diff --git a/old/cfg.c b/old/cfg.c deleted file mode 100644 index 75866f9..0000000 --- a/old/cfg.c +++ /dev/null @@ -1,443 +0,0 @@ -/*********************************************** -** -** cfg.c v0.01 -** -** Generic config file handler -** (c) Gareth Watts 1998 -** gareth@omnipotent.net -** -** Alpha code as of 980601 -*/ - -#include -#include -#include -#include -#include - -#include "cfg.h" - - - -/************************** -* PUBLIC METHODS -*/ - -void cfg_free(cfg *self) { - struct cfg_node *ptr, *nextptr; - int i; - - for(i=0;icfg_hash[i]) { - for(ptr=self->cfg_hash[i];ptr;ptr=nextptr) { - nextptr=ptr->next; - free(ptr->optname); - free(ptr->optvalue); - free(ptr); - } - } - } - free(self->filename); - free(self->lasterror); - self->_queuefree(self); - free(self); -} - - -#define CFG_BUZSIZE 4096 -int cfg_openfile(cfg *self,char *fn,int mode) { - char buffer[CFG_BUZSIZE]; - char *keyname,*keyvalue; - int comment; - FILE *fh; - - self->filename=strdup(fn); - fh=fopen(fn,"r"); - if (!fh) { - if (mode==CFG_READONLY) { - self->lasterror=strdup(strerror(errno)); - return(1); - } - return(0); /* read/write but file not found */ - } - - // READ AND PARSE FILE HERE - while(feof(fh)==0) { - fgets(buffer,CFG_BUZSIZE-1,fh); - if (strlen(buffer)) { - if (buffer[strlen(buffer)-1]=='\n') { - buffer[strlen(buffer)-1]='\0'; - } - if (buffer[0]=='#') { - comment=1; - } else { - comment=0; - } - } else { comment=1;} - if (!comment&&self->_splitline(self,buffer,&keyname,&keyvalue)) { - return(1); /* memory error or somesuch */ - } - if (!comment&&keyname&&keyvalue) { - if (!self->_lookup(self,keyname)) { - self->_insert(self,keyname,keyvalue,0); - } - } - - } - return(0); -} - - -char *cfg_getstring(cfg *self,char *keyname) { - return(self->_lookup(self,keyname)); -} - - -int cfg_getint(cfg *self,char *keyname) { - int result=0; - char *keydata; - - keydata=self->_lookup(self,keyname); - if (keydata) - sscanf(keydata,"%d",&result); - return(result); -} - - -/* This is virtually useless due to rounding errors */ -float cfg_getfloat(cfg *self,char *keyname) { - float result=0.0; - char *keydata; - - keydata=self->_lookup(self,keyname); - if (keydata) - sscanf(keydata,"%f",&result); - return(result); -} - - -int cfg_setstring(cfg *self,char *keyname, char *keyvalue) { - return(self->_set(self,keyname,keyvalue)); -} - - -int cfg_setint(cfg *self,char *keyname, int keyvalue) { - char buffer[200]; - - sprintf(buffer,"%d",keyvalue); - return(self->_set(self,keyname,buffer)); -} - -int cfg_setfloat(cfg *self,char *keyname, float keyvalue) { - char buffer[200]; - - sprintf(buffer,"%f",keyvalue); - return(self->_set(self,keyname,buffer)); -} - -int cfg_flush(cfg *self) { - if (self->filemode==CFG_READONLY) { - return(0); - } else { - return(self->_flush(self)); - } -} - - -int cfg_autoflush(cfg *self,int aflush) { - self->aflush=(aflush>0); - return(0); -} - - - -/************************** -* PRIVATE/INTERNAL METHODS -*/ - -int _cfg_init(cfg *self) { - memset(self->cfg_hash,0,sizeof(self->cfg_hash)); - return(0); -} - - -int _cfg_queuepush(cfg *self, struct cfg_node *node) { - struct cfg_queuenode *ptr; - - ptr=(struct cfg_queuenode *)calloc(1,sizeof(struct cfg_queuenode)); - if (!ptr) return(1); - ptr->ref=node; - if (self->cfg_newsttail) { - self->cfg_newsttail->next=ptr; - self->cfg_newsttail=ptr; - } else { - self->cfg_newsthead=self->cfg_newsttail=ptr; - } - return(0); -} - - -struct cfg_queuenode *_cfg_queuenext(cfg *self, struct cfg_queuenode *last) { - if (last) { - return(last->next); - } else { - return(self->cfg_newsthead); - } -} - - -int _cfg_queuefree(cfg *self) { - struct cfg_queuenode *ptr,*next; - - for(ptr=self->cfg_newsthead;ptr;ptr=next) { - next=ptr->next; - free(ptr); - } - self->cfg_newsthead=self->cfg_newsttail=NULL; - return(0); -} - - -int _cfg_getkey(cfg *self,char *str) { - unsigned int total; - int i=1; - int j=0; - - total=(*str)-0x20; - str++; - while(*str) { - total+=i*((*str)-0x20); - str++; - i+=(33+j++)*j; - } - return(total % CFG_HASHSIZE); -} - - -int _cfg_insert(cfg *self,char *keyname, char *keyval,int dirty) { - int key,match=0; - struct cfg_node *ptr,*nextptr;; - - key=self->_getkey(self,keyname); - if (!self->cfg_hash[key]) { - self->cfg_hash[key]=(struct cfg_node *)calloc(1,sizeof(struct cfg_node)); - if (!(self->cfg_hash[key]->optname=strdup(keyname))) { - return(1); - } - if (!(self->cfg_hash[key]->optvalue=strdup(keyval))) { - return(1); - } - if (dirty) self->_queuepush(self,self->cfg_hash[key]); - } else { - for(nextptr=self->cfg_hash[key];(nextptr)&&(!match);nextptr=ptr->next) { - ptr=nextptr; - match=(strcasecmp(ptr->optname,keyname)==0); - } - - if (match) { /* node already exists / overwrite */ - free(ptr->optvalue); - ptr->dirty=dirty; - } else { /* new node */ - ptr->next=(struct cfg_node *)calloc(1,sizeof(struct cfg_node)); - ptr=ptr->next; - if (!(ptr->optname=strdup(keyname))) { - return(1); - } - if (dirty) self->_queuepush(self,ptr); - } - if (!(ptr->optvalue=strdup(keyval))) { - return(1); - } - } - return(0); -} - - -struct cfg_node *_cfg_getnode(cfg *self, char *keyname) { - int key; - struct cfg_node *ptr,*next; - int match=0; - - key=self->_getkey(self,keyname); - if (!self->cfg_hash[key]) - return(NULL); - for(next=self->cfg_hash[key];next&&!match;next=ptr->next) { - ptr=next; - match=(strcasecmp(ptr->optname,keyname)==0); - } - if (match) - return(ptr); - return(NULL); -} - - -char *_cfg_lookup(cfg *self,char *keyname) { - struct cfg_node *ptr; - - ptr=self->_getnode(self,keyname); - if (ptr) - return(ptr->optvalue); - else - return(NULL); -} - - -int _cfg_cleardirty(cfg *self,struct cfg_node *ptr) { - ptr->dirty=0; - return(0); -} - - -int _cfg_set(cfg *self,char *keyname,char *keyvalue) { - int key; - - key=self->_getkey(self,keyname); - if (self->_insert(self,keyname,keyvalue,1)!=0) { - return(1); /* error */ - } - if (self->aflush) { - return(self->flush(self)); - } - return(0); -} - -int _cfg_splitline(cfg *self,char *src, char **f, char **s) { - char *brkpoint; - int offset,slen,fpos; - static char first[4096],second[4096]; - - *f=*s=NULL; - if ((brkpoint=strchr(src,'='))==NULL) { - return(0); - } - offset=brkpoint-src; - slen=strlen(src); - if (offset==slen-1) { - return(0); - } - if (offset>4094) {offset=4094;} - - memset(first,0,4096); - memset(second,0,4096); - strncpy(first,src,offset); - strncpy(second,brkpoint+1,4095); - - fpos=strlen(first)-1; - while((first[fpos]==' ')&&fpos) { - first[fpos]='\0'; - fpos--; - } - *f=first; - for(*s=second;(**s)&&(**s==' ');(*s)++); - return(0); -} - - - -#define CFGF_MAXLINES 50000 -#define CFGF_LINELEN 4096 -int _cfg_realflush(cfg *self) { - char *outbuf[CFGF_MAXLINES]; - char buffer[CFGF_LINELEN]; - int linenum=0; - int comment,i; - char *keyname,*keyvalue; - struct cfg_queuenode *qptr; - struct cfg_node *ptr; - FILE *fh; - char *rd; - - fh=fopen(self->filename,"r"); - if (fh) { - while((feof(fh)==0)&&(linenum_splitline(self,buffer,&keyname,&keyvalue)) { - fclose(fh); - return(1); /* memory error or somesuch */ - } - if ((keyname)&&(ptr=self->_getnode(self,keyname))&&(ptr->dirty)) { - sprintf(buffer,"%s = %s",ptr->optname,ptr->optvalue); - outbuf[linenum]=strdup(buffer); - self->_cleardirty(self,ptr); - } else { - outbuf[linenum]=strdup(buffer); - } - } - linenum++; - } - } - fclose(fh); - } - for(qptr=self->_queuenext(self,NULL);qptr;qptr=self->_queuenext(self,qptr)) { - sprintf(buffer,"%s=%s",qptr->ref->optname,qptr->ref->optvalue); - outbuf[linenum]=strdup(buffer); - linenum++; - } - fh=fopen(self->filename,"w"); - if (!fh) { - self->lasterror=strdup(strerror(errno)); - return(1); - } - for(i=0;i_queuefree(self); - return(0); -} - - - - - - -/***************** -* THE CONSTRUCTOR -*/ - -cfg *cfg_new() { - cfg *ptr; - - ptr=(cfg *)calloc(1,sizeof(cfg)); - if (!ptr) return(NULL); - - ptr->getstring=cfg_getstring; - ptr->getint=cfg_getint; - ptr->getfloat=cfg_getfloat; - ptr->openfile=cfg_openfile; - ptr->setstring=cfg_setstring; - ptr->setint=cfg_setint; - ptr->setfloat=cfg_setfloat; - ptr->flush=cfg_flush; - ptr->autoflush=cfg_autoflush; - ptr->free=cfg_free; - - ptr->_getkey=_cfg_getkey; - ptr->_insert=_cfg_insert; - ptr->_lookup=_cfg_lookup; - ptr->_cleardirty=_cfg_cleardirty; - ptr->_set=_cfg_set; - ptr->_splitline=_cfg_splitline; - ptr->_queuepush=_cfg_queuepush; - ptr->_queuenext=_cfg_queuenext; - ptr->_queuefree=_cfg_queuefree; - ptr->_getnode=_cfg_getnode; - ptr->_flush=_cfg_realflush; - - if (_cfg_init(ptr)) return(NULL); - return(ptr); -} - diff --git a/old/cfg.h b/old/cfg.h deleted file mode 100644 index f166cb5..0000000 --- a/old/cfg.h +++ /dev/null @@ -1,70 +0,0 @@ -/*********************************************** -** -** cfg.h v0.01 -** -** Generic config file handler -** (c) Gareth Watts 1998 -*/ - - -#define CFG_READONLY 1 -#define CFG_READWRITE 2 - - -struct cfg_node { - char *optname; - char *optvalue; - int dirty; - struct cfg_node *next; -}; - - -struct cfg_queuenode { - struct cfg_node *ref; - struct cfg_queuenode *next; -}; - - -#define CFG_HASHSIZE 1297 -typedef struct cfg { - - // PUBLIC METHODS - void (*free)(struct cfg *self); - int (*openfile)(struct cfg *self,char *fn,int mode); - int (*autoflush)(struct cfg *self,int flushmode); - char *(*getstring)(struct cfg *self,char *key); - int (*getint)(struct cfg *self,char *key); - float (*getfloat)(struct cfg *self,char *key); - int (*setstring)(struct cfg *self,char *key, char *value); - int (*setint)(struct cfg *self,char *key, int value); - int (*setfloat)(struct cfg *self,char *key, float value); - int (*flush)(struct cfg *self); - - // PUBLIC DATA - char *lasterror; - - - // PRIVATE METHODS - int (*_init)(struct cfg *self); - int (*_getkey)(struct cfg *self,char *str); - int (*_insert)(struct cfg *self,char *keyname,char *keyval,int dirty); - struct cfg_node *(*_getnode)(struct cfg *self,char *keyname); - char *(*_lookup)(struct cfg *self,char *keyname); - int (*_cleardirty)(struct cfg *self,struct cfg_node *ptr); - int (*_splitline)(struct cfg *self,char *src, char **f, char **s); - int (*_set)(struct cfg *self, char *keyname, char *keyvalue); - int (*_queuepush)(struct cfg *self, struct cfg_node *node); - struct cfg_queuenode *(*_queuenext)(struct cfg *self, struct cfg_queuenode *last); - int (*_queuefree)(struct cfg *self); - int (*_flush)(struct cfg *self); - - // PRIVATE DATA - struct cfg_node *cfg_hash[CFG_HASHSIZE]; - struct cfg_queuenode *cfg_newsthead; - struct cfg_queuenode *cfg_newsttail; - char *filename; - int filemode; - int aflush; -} cfg; - -cfg *cfg_new(); diff --git a/old/cfg_test.c b/old/cfg_test.c deleted file mode 100644 index bc94fb0..0000000 --- a/old/cfg_test.c +++ /dev/null @@ -1,76 +0,0 @@ -/********************************************* -** cfg.c example -** gareth@omnipotent.net 1/June/1998 -** -** This code will create cfg_testfile.cfg if -** it doesn't already exist and set some -** values within it. Simple really. -*/ - -#include -#include -#include - -#include "cfg.h" - - -#define TESTFILE "cfg_testfile.cfg" - -int main() { - cfg *cfgfile; - - /* First create our object */ - if ((cfgfile=cfg_new())==NULL) { - printf("Error creating config object\n"); - exit(255); - } - - /* Then find a config file to open */ - if (cfgfile->openfile(cfgfile,TESTFILE,CFG_READWRITE)!=0) { - printf("Error reading file: %s\n",cfgfile->lasterror); - cfgfile->free(cfgfile); - } - - /* Save to disk on every update */ - cfgfile->autoflush(cfgfile,1); - - /* print out the current settings - Will return NULL if */ - /* they don't currently exist (eg. new file) */ - printf("'A test string' is set to '%s'\n", - cfgfile->getstring(cfgfile,"A test string")); - printf("'A test integer' is set to %d\n\n", - cfgfile->getint(cfgfile,"A test integer")); - - /* set to some new values */ - cfgfile->setstring(cfgfile,"A test string","Marvin the paranoid android"); - cfgfile->setint(cfgfile,"A test integer",42); - - /* print out the new settings */ - printf("'A test string' is now set to '%s'\n", - cfgfile->getstring(cfgfile,"A test string")); - printf("'A test integer' is now set to %d\n\n", - cfgfile->getint(cfgfile,"A test integer")); - - - /* set the values to something else with autoflush off */ - cfgfile->autoflush(cfgfile,0); - cfgfile->setstring(cfgfile,"A test string","Life, don't talk to me about life"); - cfgfile->setint(cfgfile,"A test integer",417362); - - /* print out the new settings */ - printf("'A test string' is finally set to '%s'\n", - cfgfile->getstring(cfgfile,"A test string")); - printf("'A test integer' is finally set to %d\n\n", - cfgfile->getint(cfgfile,"A test integer")); - - /* flush the last set of data to disk as autoflush is off */ - cfgfile->flush(cfgfile); - - - /* cleanup */ - - cfgfile->free(cfgfile); - - return(0); -} - diff --git a/old/cfg_testfile.cfg b/old/cfg_testfile.cfg deleted file mode 100644 index 5a54dc4..0000000 --- a/old/cfg_testfile.cfg +++ /dev/null @@ -1,15 +0,0 @@ -########################## -# Test file thingy! # -########################## - -# A string of some sort... -A test string = Life, don't talk to me about life -# An integer... -A test integer = 417362 - -My flag = yes -My other flag = true - -#################### Here's a big-ass comment! ############################################################################################ See, it goes on for a long time! #################################################### - -And stuff = Hell, yeah! diff --git a/old/change.log b/old/change.log deleted file mode 100644 index 07a044c..0000000 --- a/old/change.log +++ /dev/null @@ -1,73 +0,0 @@ -1998-04-26: Scott - all: Implemented logical/physical drivers.. Whew! - main.c, mode.c, lcd.* have changed, and I've added text.* and - MtxOrb.* driver files... - New commandline option "-l driver" selects a driver. - -1998-04-21: Scott - all: Lots of updates... (patches, etc) - Implemented a frame buffer, and custom characters... - Added lots of comments, and cleaned a few things... - Added a few function to lcd.c - -1998-03-22: Scott - main.c: Should exit cleanly now, always... It sometimes wouldn't, if killed - by init at shutdown... (it would get stuck in a usleep for too - long, and then get killed instead of shutting down) - main.c: Changed timing method... Sequences now specify their length in - TIME_UNITs. A time unit is 1/8th of a second. This should make - blinking and other such things easy... - main.c: Removed command line options to specify timings... Why would the - user really need to change that anyway? - main.c: A few mode-feedback things are implemented: blinking, and backlight - on/off stuff... - mode.c: Xload_screen now sends feedback to toggle blinking for a high load, - or turn the backlight off for no load... - -1998-03-13: Scott - Makefile: Installs man page in /usr/local/man/man1... - main.c: Now detects previously running lcdproc. - lock.?: New files for detecting another lcdproc... - Now detects an already-running process, and gets its pid. So far, - it just exits when this happens. - -1998-02-28: Scott - Makefile: Now handles installation with "make install". - main.c: New command line stuff... (in man page) Also, default contrast is - 140 now. Looks better from all angles, at least on my machine. :) - lcd.1: Man page. New.. :) - mode.c: Rearranged memory screen.. Shows Memory and Swap space separately, - with two graphs. - -1998-02-24: Scott - mode.c: Rearranged memory screen. Worked around hbar bios bug. Added swap - info to this screen also, so get_mem_info is back to its former - state. (call it on an array) - mode.c: Fixed xload screen. It was displaying things one space to the left. - main.c: Changed command line style from "mode num_times delay_time" to - "mode total_time delay_time". Is this better or worse? - -1998-02-22: Scott - main.c: Now handles SIGINT (Ctrl-C) and SIGTERM (kill) for a clean exit. - main.c: Default device now works. (device[] was getting overwritten by - argv[0], which would always be "lcd") - mode.c: Fixed CPU load meter. Decreased cpu buffer size back to 4. - mode.c: Made goodbye_screen() do something... - mode.c: Fixed am/pm on clock_screen(). Was previously displaying 12:xx:xxA - during the noon hour, instead of 12:xx:xxP. - -1998-02-18: Scott - mode.c: Fixed crash on memory screen; commented out last two lines of - get_mem_info, which accessed a non-existent variable. - mode.c: Added "rep" parameter to all screen functions. Specifies how many times - that screen has been run. Using 0 will force screen clear/redraw, and - the time-based ones also use this to determine if colons should be drawn. - main.c: Implemented simple command-line parameters. Example: - lcd m 4 .5 /dev/cua1 x 1 2 - uses /dev/cua1 for lcd, displaying memory info 4 times at .5 seconds each, - and the xload screen once for 2 seconds; then loops. - mode.c & lcd.c: created "NOLCD" preprocessor switch. When defined, lcd uses - text output (stdout) instead of the com port. - mode.c: Changed clock string generation to use "%02d" to achieve that - "02:37:06" look. (hint: printf can pad numbers with leading 0's) - main.c: Added minimal command-line help. diff --git a/old/llistd.c b/old/llistd.c deleted file mode 100644 index 4c4f2cb..0000000 --- a/old/llistd.c +++ /dev/null @@ -1,429 +0,0 @@ -#include // for NULL definition -#include "llistd.h" // function prototypes - -/***************************************************************************** -* AUTHOR: Scott Scriven, SSN: 523-21-9640, CLASS: CS151.003, DATE: 96-11-21 -****************************************************************************** -* Doubly Linked Lists! (some of my really old code, commented for this class) -* This code will handle "generic" Doubly-Linked Lists. These lists can be -* any type as long as they satisfy a few requirements: -* Your structure must start with two integer pointers: -* struct mystruct { -* int *next, *prev; -* ... -* }; -* That's all, pretty much. -* -* Most of the functions take integer pointers. This means you will have to -* call them in one of the following ways: -* function((int *)&mystruct); -* function((int *)mystruct); -* function(&mystruct.next); -* -****************************************************************************** -* If I'm not mistaken, this code should work regardless of your machine's -* integer size (16/32/64/etc... bit) -****************************************************************************** -* Note that we have to do NULL checking to make sure we don't try to write -* to protected areas of memory if we reach the beginning/end of a list. -* -* We also do some circular-link checking to avoid infinite loops. -* These loops will work fine: -* a <-> b <-> c <-> a <-> b... -* a <-> b <-> c -> c -> c... -* This loop might make this code puke: -* a <-> b <-> c <-> d -> c d <- e <-> f <-> g -*****************************************************************************/ - - -/***************************************************************************** -* Function: LLMakeFirstNode() -****************************************************************************** -* Description: -* Makes a node stand alone; creates the first node of a list. You must do -* the memory/node allocation manually. It returns the parameter you send it. -****************************************************************************** -* Function Calls: -* None. -*****************************************************************************/ -int * LLMakeFirstNode(int * first) // Make a standalone node... -{ - (int *)first[0] = NULL; - (int *)first[1] = NULL; - return first; -} - - -/***************************************************************************** -* Function: LLFindFirst() -****************************************************************************** -* Description: -* Given a node of a list, it returns the first node of the list (assuming -* that the first node either points to NULL or itself). If list is circular, -* it returns *next* node in the list. -****************************************************************************** -* Function Calls: -* LLFindPrev See below... -*****************************************************************************/ -int * LLFindFirst(int * current) // returns address of First node -{ - int *prev=current; - - // If prev[1] (pointer to previous node) is NULL, we hit the beginning. - // If prev[1] is the same as current, we've got a circular linked list... - while((int *)prev[1] != NULL && (int *)prev[1] != current) - { - prev = LLFindPrev(prev); - } - - return prev; -} - -/***************************************************************************** -* Function: LLFindNext() -****************************************************************************** -* Description: -* Returns the address of the next node in the list, or NULL if we're at the -* end of the list. -****************************************************************************** -* Function Calls: -* None. -*****************************************************************************/ -int * LLFindNext(int * current) // returns address of next node -{ - // Return the address of the next node - if((int *)current[0] != current) - return (int *)current[0]; - else - return NULL; -} - -/***************************************************************************** -* Function: LLFindPrev() -****************************************************************************** -* Description: -* Returns the address of the previous node in the list, or NULL if we're -* at the beginning of the list. -****************************************************************************** -* Function Calls: -* None. -*****************************************************************************/ -int * LLFindPrev(int * current) // returns address of prev node -{ - // Return the address of the previous node - if((int *)current[1] != current) - return (int *)current[1]; - else - return NULL; -} - -/***************************************************************************** -* Function: LLFindLast() -****************************************************************************** -* Description: -* Given any node, returns the address of the last node of that list. This -* works just like LLFindFirst(), but in reverse. -****************************************************************************** -* Function Calls: -* LLFindNext See above... -*****************************************************************************/ -int * LLFindLast(int * current) // returns address of last node -{ - int *next = current; - - // If next[0] (pointer to next node) is NULL, we hit the end. - // If next[0] is the same as current, we've got a circular linked list... - while((int *)next[0] != NULL && (int *)next[0] != current) - { - next = LLFindNext(next); - } - - return next; -} - - -/***************************************************************************** -* Function: LLAddNode() -****************************************************************************** -* Description: -* Inserts a node in the list *after* the "current" node. It updates the -* list neighbors accordingly. -****************************************************************************** -* Function Calls: -* LLFindNext See above... -*****************************************************************************/ -int * LLAddNode(int * current, int * add) // Adds node AFTER current one -{ - int *next; - - if(current == add) return current; // We can't add a node to itself... - - next = LLFindNext(current); // Get the next node address - - (int *)current[0] = add; // Point the current node to the new node - (int *)add[0] = next; // Point the new node to next node - (int *)add[1] = current; // Make new node point back to the current node - - if(next != NULL) - (int *)next[1] = add; // Point next node back to the new node - - return add; // Return the address of the new node -} - -/***************************************************************************** -* Function: LLInsertNode() -****************************************************************************** -* Description: -* Inserts a node in the list *before* the "current" node. It updates the -* list neighbors accordingly. -****************************************************************************** -* Function Calls: -* LLFindPrev See above... -*****************************************************************************/ -int * LLInsertNode(int * current, int * add) // Adds node BEFORE current one -{ - int *prev; - - if(current == add) return current; // We can't add a node to itself... - - prev = LLFindPrev(current); // Get the previous node's address - - if(prev != NULL) - (int *)prev[0] = add; // Previous node points to new node - (int *)add[0] = current; // New node points to current node - (int *)add[1] = prev; // New node points back to previous node - (int *)current[1] = add; // Current node points back to new node - - return add; // Return the address of the new node -} - -/***************************************************************************** -* Function: LLCutNode() -****************************************************************************** -* Description: -* Removes a node from the list, and joins its neighbors. Returns the -* address of the cut node. You must deallocate the node manually, if -* you want to free its memory. -****************************************************************************** -* Function Calls: -* LLFindPrev See Above... -* LLFindNext See Above... -*****************************************************************************/ -int * LLCutNode(int * cut) // Removes a node from the link -{ - int * prev, * next; - - prev = LLFindPrev(cut); // Find surrounding nodes... - next = LLFindNext(cut); - - (int *)cut[0] = NULL; // Make the removed node point nowhere - (int *)cut[1] = NULL; - - if(prev != NULL) // Join the surrounding nodes... - (int *)prev[0] = next; - if(next != NULL) - (int *)next[1] = prev; - - return cut; // Return the address of the node that has been cut... -} - - -/***************************************************************************** -* Function: LLPush() -****************************************************************************** -* Description: -* Inserts a node at the end of the whole list. "Current" can be any node -* in the list, and "add" is the node you want to add. -****************************************************************************** -* Function Calls: -* LLFindLast() See above... -* LLAddNode() See above... -*****************************************************************************/ -int * LLPush(int * current, int * add) // Add node to end of list -{ - int *last; - - last = LLFindLast(current); - - return LLAddNode(last, add); -} - -/***************************************************************************** -* Function: LLPop() -****************************************************************************** -* Description: -* Pops (removes) a node off the end of the list. Returns the address of -* the node we chopped off. "current" can be any node in the list. -****************************************************************************** -* Function Calls: -* LLFindLast See above... -* LLCutNode See above... -*****************************************************************************/ -int * LLPop(int * current) // Remove node from end of list -{ - int *last; - - last = LLFindLast(current); - - return LLCutNode(last); -} - -/***************************************************************************** -* Function: LLShift() -****************************************************************************** -* Description: -* Pops (removes) a node from the beginning of the list. Returns the address -* of the node we cut off. -****************************************************************************** -* Function Calls: -* LLFindFirst See above... -* LLCutNode See above... -*****************************************************************************/ -int * LLShift(int * current) // Remove node from start of list -{ - int *begin; - - begin = LLFindFirst(current); - - return LLCutNode(begin); -} - -/***************************************************************************** -* Function: LLUnshift() -****************************************************************************** -* Description: -* Inserts a node at the beginning of the list. -****************************************************************************** -* Function Calls: -* LLFindFirst See above... -* LLInsertNode See above... -*****************************************************************************/ -int * LLUnshift(int * current, int * add) // Add node to beginning of list -{ - int *begin; - - begin = LLFindFirst(current); - - return LLInsertNode(begin, add); -} - -/***************************************************************************** -* Function: LLSwapNodes() -****************************************************************************** -* Description: -* Switches two nodes' positions in the linked list. It can handle cases -* when the nodes are complete seperate, cases when the nodes are each -* other's neighbors, and cases when the two nodes are the same one. -* No return value. -****************************************************************************** -* Function Calls: -* LLFindNext See Above... -* LLFindPrev See above... -*****************************************************************************/ -void LLSwapNodes(int * one, int * two) // Switch two nodes' positions... -{ - int *firstprev, *firstnext; - int *secondprev, *secondnext; - - if(one == two) return; // if they're the same, do nothing - - firstprev = LLFindPrev(one); // Store the addresses of their neighbors... - firstnext = LLFindNext(one); - secondprev = LLFindPrev(two); - secondnext = LLFindNext(two); - - if(firstprev != NULL) (int *)firstprev[0] = two; // Swap their - if(firstnext != NULL) (int *)firstnext[1] = two; // Neighbors' pointers - if(secondprev != NULL) (int *)secondprev[0] = one; - if(secondnext != NULL) (int *)secondnext[1] = one; - - (int *)one[0] = secondnext; // Swap the two nodes' pointers - (int *)one[1] = secondprev; - (int *)two[0] = firstnext; - (int *)two[1] = firstprev; - - if(firstnext == two) (int *)one[1] = two; // Fix things if they were - if(firstprev == two) (int *)one[0] = two; // next to each other... - if(secondprev == one) (int *)two[0] = one; - if(secondnext == one) (int *)two[1] = one; -} - -/***************************************************************************** -* Function: LLCountNodes() -****************************************************************************** -* Description: -* Traverses the entire list and returns the number of nodes it finds. -****************************************************************************** -* Function Calls: -* LLFindFirst See above... -* LLFindNext See above... -*****************************************************************************/ -int LLCountNodes(int * current) // Returns # of nodes in entire list -{ - int numnodes=1; - int *first, *next; - - first = LLFindFirst(current); // Get the first node... - next = first; - - - // If next[0] (pointer to next node) is NULL, we hit the end. - // If next[0] is the same as current, we've got a circular linked list... - while((int *)next[0] != NULL && (int *)next[0] != first) - { - numnodes++; - next = LLFindNext(next); - } - - return numnodes; -} - - -/***************************************************************************** -* Function: LLSelectSort() -****************************************************************************** -* Description: -* Given any node in a list, sorts the whole list using a selection sort -* algorithm. You must supply a function to compare two nodes. The -* return value is the address of the new first node in the list. -****************************************************************************** -* Function Calls: -* LLCountNodes See above... -* LLFindLast See above... -* LLFindFirst See above... -* LLFindNext See above... -* LLFindPrev See above... -* LLSwapNodes See above... -* compare The user-defined function which compares two nodes. -* If you've ever used qsort, this should be familiar. -*****************************************************************************/ -// Sorts the list and returns a pointer to the first node -int * LLSelectSort(int * current, int compare(void *, void *)) -{ - int i,j; // Junk / loop variables - int numnodes; // number of nodes in list - int *best, *last; // best match and last node in the list - - numnodes = LLCountNodes(current); // get the number of nodes... - last = LLFindLast(current); // Find the last node. - - for(i=numnodes-1; i>1; i--) - { - current = LLFindFirst(current); // get the first node again - best = last; // reset our "best" node - - for(j=0; j 0) // If we found a better match... - { - best = current; // keep track of the "best" match - } - current = LLFindNext(current); // Go to the next node. - } - - LLSwapNodes(last, best); // Switch two nodes... - last = LLFindPrev(best); // And go backwards by one node. - } - - return LLFindFirst(current); // return pointer to the first node. -} diff --git a/old/llistd.h b/old/llistd.h deleted file mode 100644 index 6f0a22d..0000000 --- a/old/llistd.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef LLISTD_H -#define LLISTD_H -/***************************************************************************** -* AUTHOR: Scott Scriven, SSN: 523-21-9640, CLASS: CS151.003, DATE: 96-11-21 -****************************************************************************** -* Doubly Linked Lists! -* This code will handle "generic" Doubly-Linked Lists. These lists can be -* any type as long as they satisfy a few requirements: -* Your structure must start with two integer pointers: -* struct mystruct { -* int *next, *prev; -* ... -* }; -* That's all, pretty much. -* -* Most of the functions take integer pointers. This means you will have to -* call them in one of the following ways: -* function((int *)&mystruct); -* function((int *)mystruct); -* function(&mystruct.next); -* -****************************************************************************** -* If I'm not mistaken, this code should work regardless of your machine's -* integer size (16/32/64/etc... bit) -****************************************************************************** -* Note that we have to do NULL checking to make sure we don't try to write -* to protected areas of memory if we reach the beginning/end of a list. -* -* We also do some circular-link checking to avoid infinite loops. -* These loops will work fine: -* a <-> b <-> c <-> a <-> b... -* a <-> b <-> c -> c -> c... -* This loop might make this code puke: -* a <-> b <-> c <-> d -> c d <- e <-> f <-> g -*****************************************************************************/ - - -// See llistd.c for detailed descriptions of these functions. - -int * LLMakeFirstNode(int * first); // Make a standalone node... - -int * LLFindFirst(int * current); // returns address of First node -int * LLFindNext(int * current); // returns address of next node -int * LLFindPrev(int * current); // returns address of prev node -int * LLFindLast(int * current); // returns address of last node - -int * LLAddNode(int * current, int * add); // Adds node AFTER current one -int * LLInsertNode(int * current, int * add); // Adds node BEFORE current one -int * LLCutNode(int * cut); // Removes a node from the link - -int * LLPush(int * current, int * add); // Add node to end of list -int * LLPop(int * current); // Remove node from end of list -int * LLShift(int * current); // Remove node from start of list -int * LLUnshift(int * current, int * add); // Add node to beginning of list - -void LLSwapNodes(int * one, int * two); // Switch two nodes positions... - -int LLCountNodes(int * current); // Returns # of nodes in entire list - -// "Selection Sort"s the list and returns a pointer to the first node -int * LLSelectSort(int * current, int compare(void *, void *)); - -#endif diff --git a/old/main.c b/old/main.c deleted file mode 100644 index b17c1a9..0000000 --- a/old/main.c +++ /dev/null @@ -1,318 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "main.h" -#include "lcd.h" -#include "mode.h" -//#include "lock.h" -#include "sockets.h" - - -// TODO: Commenting... Everything! - - -char version[] = "v0.3.4"; -char build_date[] = "1998-06-20"; -int Quit = 0; - -/* - Mode List: - See below... (default_sequence[]) -*/ - -typedef struct mode { - char which; - int num_times; - int delay_time; -} mode; - -void HelpScreen(); -void exit_program(int val); -void main_loop(mode *sequence); - -#define MAX_SEQUENCE 256 -// 1/8th second is a single time unit... -#define TIME_UNIT 125000 - - -// Contains a list of modes to run -mode default_sequence[] = -{ - { 'C', 32, 1, },// [C]PU - { 'M', 8, 4, },// [M]emory - { 'X', 1, 32, },// [X]-load (load histogram) - { 'T', 8, 4, },// [T]ime/Date - { 'D', 32, 1, },// [D]isk stats - { 'A', 1, 16, },// [A]bout (credits) - - { 1 , 0, 0, },// Modes after this line will not be run by default... - // ... all non-default modes must be in here! - // ... they will not show up otherwise. - { 'O', 8, 4, },// [O]ld Timescreen - { 'U', 8, 4, },// Old [U]ptime Screen - { 'B', 32, 1, },// [B]attery Status - { 'G', 32, 1, },// Cpu histogram [G]raph - { 0, 0, 0, },// No more.. all done. -}; - -// TODO: Clean up main()... It is still way too big. - -// TODO: Socket language, client handling... -// TODO: Config file; not just command line - - -int main(int argc, char **argv) -{ - char device[256] = "/dev/lcd"; - char cfgfile[256] = "/etc/lcdproc.cf"; - mode sequence[MAX_SEQUENCE]; - char driver[256] = "MtxOrb"; - int i, j, k; - int already_running = 0; - int contrast = 140; - int tmp; - - memset(sequence, 0, sizeof(mode) * MAX_SEQUENCE); - - // Ctrl-C will cause a clean exit... - signal(SIGINT, exit_program); - // and "kill"... - signal(SIGTERM, exit_program); - // and "kill -HUP" (hangup)... - signal(SIGHUP, exit_program); - // and just in case, "kill -KILL" (which cannot be trapped; but oh well) - signal(SIGKILL, exit_program); - - // Check to see if we are already running... -// already_running = CheckForLock(); - already_running = PingLCDport(); - if(already_running < 0) - { - printf("Error checking for another LCDproc.\n"); - return -1; - } - - - // Communicate with the previously running LCDproc - if(already_running > 0) - { - // "already_running" holds the pid of the LCDproc we want to talk to... - - // Do the command line ("lcd pet status", or "lcd contrast 50") - // And stuff... - // ...Then exit - printf("Detected another LCDproc. (%i) Exiting...\n", already_running); - // Remove me ^^^^ - return 0; - } - - tmp = StartSocketServer(); - if (tmp <= 0) - { - printf("Error starting socket server.\n"); - return 0; - } - - - - // Command line - memcpy(sequence, default_sequence, sizeof(default_sequence)); - for(i=1, j=0; i= 0 - &&ThisMenu.menu[ThisMenu.sel].child) - { - i = do_menu(ThisMenu.menu[ThisMenu.sel].child, &ThisMenu); - if(i == GUI_OK) ret = GUI_OK; - } - - // Or call a function? - else if( // execute was pressed... - &&ThisMenu.sel >= 0 - &&ThisMenu.menu[ThisMenu.sel].func) - { - ret = ThisMenu.menu[ThisMenu.sel].func(); - //ret = GUI_OK; - } - - } while(! ret); - - return ret; -} - - - -////////////////////////////////////////////////////////////////////// -// Initializes a menu... -// -void FillMenuInfo(MenuInfo *m, MenuItem *menu, MenuInfo * parent) -{ - m->menu = menu; - m->parent = parent; - m->sel = 0; - -} - - -void DrawMenu(MenuInfo *m) -{ - int i; - - for(i=0; iitems; i++) - DrawMenuItem(m, i); -} - -void DrawMenuItem(MenuInfo *m, int item) -{ - // Figure out how much to scroll down... - // Write each menu item... - // Put arrows where needed (next to current item, and up/down arrow) - // m->menu[item].text holds the text string... -} - - - diff --git a/old/menu.h b/old/menu.h deleted file mode 100644 index 30baafa..0000000 --- a/old/menu.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef MENU_H -#define MENU_H - -////////////////////////////////////////////// -// THIS IS NOT READY YET! -////////////////////////////////////////////// - -/* - - Pull-down menus... - - To use a menu, first define it; then call menu(). - - To define a menu, just declare an array of MenuItems. The last element - must have all NULL fields. - - MenuItem FileMenu[] = - { - "Open", OpenFile_proc, NULL, - "Close", CloseFile_proc, NULL, - "Save", SaveFile_proc, NULL, - "Save As...", NULL, SaveAsMenu, - "Quit", Quit_proc, NULL, - NULL, NULL, NULL, - }; - - The first field is the text for the menu item. - The second field is a function to call when the item is picked. - The function should take no parameters, and return an int. - The return values are: - MENU_OK Normal return value. Menu will close. - MENU_CONT Menu will stay up after function returns. - The third field is the child menu to display when the item is picked. - - Note that either the second or third field must be NULL. If both are - NULL, the item is considered to be just a label. (for example, a title) - It will be non-pickable if both are NULL. - -*/ - - -#define MENU_OK 1 -#define MENU_CONT 2 - -typedef struct MenuItem -{ - char *text; - int (*func)(); - struct MenuItem *child; -} MenuItem; - - - -// This does a pull-down menu... -int menu(MenuItem *menu); - - -#endif diff --git a/old/mode.c b/old/mode.c deleted file mode 100644 index 6caa3d0..0000000 --- a/old/mode.c +++ /dev/null @@ -1,1107 +0,0 @@ -/* - * This file contains status-gathering code *and* modescreen functions. - * It's long, and messy; but that will change with V0.4. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef LINUX -#include -#else -#include -#endif - -#include "mode.h" -#include "lcd.h" -#include "main.h" - -#ifndef NETDEVICE -#define NETDEVICE "ppp0" -#endif - -#ifndef LOAD_MAX -#define LOAD_MAX 1.3 -#endif -#ifndef LOAD_MIN -#define LOAD_MIN 0.5 -#endif - - -int PAD=255; -int ELLIPSIS=7; -int TwentyFourHour=0; - -// TODO: Clean this up... Support multiple display sizes.. - -struct load { unsigned long total, user, system, nice, idle; }; -struct meminfo { int total, cache, buffers, free, shared; }; -static char buffer[1024]; - -// Nothing else can see these... -static int meminfo_fd, load_fd, loadavg_fd, uptime_fd, batt_fd=0; -static FILE *mtab_fd; - -static char kver[SYS_NMLN]; -static char sysname[SYS_NMLN]; - -static void reread(int f, char *errmsg); -static int getentry(const char *tag, const char *bufptr); -static void get_mem_info(struct meminfo *result); -static double get_loadavg(void); -static double get_uptime(double *up, double *idle); -static void get_load(struct load * result); -static int get_batt_stat(int *acstat, int *battstat, - int *battflag, int *percent); - - -typedef struct mounts -{ - char dev[256], type[64], mpoint[256]; - long bsize, blocks, bfree, files, ffree; -} mounts; - - -int mode_init() -{ - struct utsname *unamebuf = - (struct utsname *) malloc( sizeof(struct utsname) ); - - meminfo_fd = open("/proc/meminfo",O_RDONLY); - loadavg_fd = open("/proc/loadavg",O_RDONLY); - load_fd = open("/proc/stat",O_RDONLY); - uptime_fd = open("/proc/uptime",O_RDONLY); - -#if 0 - kversion_fd = open("/proc/sys/kernel/osrelease",O_RDONLY); - - reread(kversion_fd, "main:"); - sscanf(buffer, "%s", kver); - - close(kversion_fd); -# endif - - /* Get OS name and version from uname() */ - if( uname( unamebuf ) != 0 ) { - perror( "Error calling uname:" ); - } - strcpy( kver, unamebuf->release ); - strcpy( sysname, unamebuf->sysname ); - - return 0; -} - -void mode_close() -{ - close(meminfo_fd); - close(loadavg_fd); - close(load_fd); - close(uptime_fd); - if(batt_fd) close(batt_fd); - -} - - -static void reread(int f, char *errmsg) -{ - if (lseek(f, 0L, 0) == 0 && read(f, buffer, sizeof(buffer) - 1 ) > 0 ) - return; - perror(errmsg); - exit(1); -} - -static int getentry(const char *tag, const char *bufptr) -{ - char *tail; - int retval, len = strlen(tag); - - while (bufptr) - { - if (*bufptr == '\n') bufptr++; - if (!strncmp(tag, bufptr, len)) - { - retval = strtol(bufptr + len, &tail, 10); - if (tail == bufptr + len) return -1; - else return retval; - } - bufptr = strchr( bufptr, '\n'); - } - return -1; -} - -static void get_mem_info(struct meminfo *result) -{ -// int i, res; char *bufptr; - - reread(meminfo_fd, "get_meminfo:"); - result[0].total = getentry("MemTotal:", buffer); - result[0].free = getentry("MemFree:", buffer); - result[0].shared = getentry("MemShared:", buffer); - result[0].buffers = getentry("Buffers:", buffer); - result[0].cache = getentry("Cached:", buffer); - result[1].total = getentry("SwapTotal:", buffer); - result[1].free = getentry("SwapFree:", buffer); -} - -static double get_loadavg(void) -{ - double load; - - reread(loadavg_fd, "get_load:"); - sscanf(buffer, "%lf", &load); - return load; -} - -static double get_uptime(double *up, double *idle) -{ - double uptime; - - reread(uptime_fd, "get_uptime:"); - sscanf(buffer, "%lf %lf", &uptime, idle); - - *up = uptime; - - return uptime; -} - -static int get_fs(mounts fs[]) -{ - struct statfs fsinfo; - char line[256]; - int x = 0, y; - - mtab_fd = fopen("/etc/mtab", "r"); - - // Get rid of old, unmounted filesystems... - memset(fs, 0, sizeof(mounts)*256); - - while (x < 256) - { - if(fgets(line, 256, mtab_fd) == NULL) - { - fclose(mtab_fd); - return x; - } - - sscanf(line, "%s %s %s", fs[x].dev, fs[x].mpoint, fs[x].type); - - if( strcmp(fs[x].type, "proc") -#ifndef STAT_NFS - && strcmp(fs[x].type, "nfs") -#endif -#ifndef STAT_SMBFS - && strcmp(fs[x].type, "smbfs") -#endif - ) - { -#ifdef LINUX - y = statfs(fs[x].mpoint, &fsinfo); -#else - y = statfs(fs[x].mpoint, &fsinfo, sizeof(fsinfo), 0); -#endif - fs[x].bsize = fsinfo.f_bsize; - fs[x].blocks = fsinfo.f_blocks; - fs[x].bfree = fsinfo.f_bfree; - fs[x].files = fsinfo.f_files; - fs[x].ffree = fsinfo.f_ffree; - x++; - } - } - - fclose(mtab_fd); - return x; -} - -static void get_load(struct load * result) -{ - static struct load last_load = { 0, 0, 0, 0, 0 }; struct load curr_load; - - reread(load_fd, "get_load:"); - sscanf(buffer, "%*s %lu %lu %lu %lu\n", &curr_load.user, &curr_load.nice, &curr_load.system, &curr_load.idle); - curr_load.total = curr_load.user + curr_load.nice + curr_load.system + curr_load.idle; - result->total = curr_load.total - last_load.total; - result->user = curr_load.user - last_load.user; - result->nice = curr_load.nice - last_load.nice; - result->system = curr_load.system - last_load.system; - result->idle = curr_load.idle - last_load.idle; - last_load.total = curr_load.total; - last_load.user = curr_load.user; - last_load.nice = curr_load.nice; - last_load.system = curr_load.system; - last_load.idle = curr_load.idle; -} - - -static int get_batt_stat(int *acstat, int *battstat, - int *battflag, int *percent) -{ - char str[64]; - - if(!batt_fd) - batt_fd = open("/proc/apm", O_RDONLY); - if(batt_fd <= 0) return -1; - - if(lseek(batt_fd, 0, 0) != 0) return -1; - - if(read(batt_fd, str, sizeof(str)-1) < 0) return -1; - - if(3 > sscanf(str+13, "0x%x 0x%x 0x%x %d", - acstat, battstat, battflag, percent)) - return -1; - - return 0; - -} - - -/////////////////////////////////////////////////////////////////////////// -//////////////////////// Let the Modes Begin! ///////////////////////////// -/////////////////////////////////////////////////////////////////////////// - -// TODO: Implement more return values for behavior changing... -// TODO: more modes... - -static char tmp[256]; - -// A couple of tables for later use... -static char *days[] = { - "Sunday, ", - "Monday, ", - "Tuesday, ", - "Wednesday,", - "Thursday, ", - "Friday, ", - "Saturday, ", -}; -static char *shortdays[] = { - "Sun", - "Mon", - "Tue", - "Wed", - "Thu", - "Fri", - "Sat", -}; - -static char *months[] = { - " January", - " February", - " March", - " April", - " May", - " June", - " July", - " August", - "September", - " October", - " November", - " December", -}; -static char *shortmonths[] = { - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec", -}; - - -////////////////////////////////////////////////////////////////////////// -// CPU screen shows info about percentage of the CPU being used -// -int cpu_screen(int rep) -{ -#undef CPU_BUF_SIZE -#define CPU_BUF_SIZE 4 - int i, j, n; - float value; - static float cpu[CPU_BUF_SIZE + 1][5];// last buffer is scratch - struct load load; - - - - get_load(&load); - - // Shift values over by one - for(i=0; i<(CPU_BUF_SIZE-1); i++) - for(j=0; j<5; j++) - cpu[i][j] = cpu[i+1][j]; - - // Read new data - cpu[CPU_BUF_SIZE-1][0] = ((float)load.user / (float)load.total) * 100.0; - cpu[CPU_BUF_SIZE-1][1] = ((float)load.system / (float)load.total) * 100.0; - cpu[CPU_BUF_SIZE-1][2] = ((float)load.nice / (float)load.total) * 100.0; - cpu[CPU_BUF_SIZE-1][3] = ((float)load.idle / (float)load.total) * 100.0; - cpu[CPU_BUF_SIZE-1][4] = (((float)load.user + (float)load.system + - (float)load.nice) / (float)load.total) * 100.0; - - // Only clear on first display... - if(!rep) - { - lcd.clear(); - lcd.init_hbar(); - - sprintf(tmp, "%c%c CPU LOAD %c%c", PAD, PAD, PAD, PAD); - - lcd.string(1, 1, tmp); - lcd.string(1, 2, "Usr 0.0% Nice 0.0%"); - lcd.string(1, 3, "Sys 0.0% Idle 0.0%"); - lcd.string(1, 4, "0% 100%"); - - // Make all the same, if this is the first time... - for(i=0; i= 99.9) { lcd.string(13, 1, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(13, 1, tmp); } - - value = cpu[CPU_BUF_SIZE][0]; - if (value >= 99.9) { lcd.string(5, 2, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(5, 2, tmp); } - - value = cpu[CPU_BUF_SIZE][1]; - if (value >= 99.9) { lcd.string(5, 3, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(5, 3, tmp); } - - value = cpu[CPU_BUF_SIZE][2]; - if (value >= 99.9) { lcd.string(16, 2, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(16, 2, tmp); } - - value = cpu[CPU_BUF_SIZE][3]; - if (value >= 99.9) { lcd.string(16, 3, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(16, 3, tmp); } - - value = cpu[CPU_BUF_SIZE][4]; - n = (int)(value * 70.0 / 100.0); - lcd.string(1, 4, "0% 100%"); - lcd.hbar(3, 4, n); - - return 0; -} // End cpu_screen() - - - -////////////////////////////////////////////////////////////////////////// -// Cpu Graph Screen shows a quick-moving histogram of CPU use. -// -int cpu_graph_screen(int rep) -{ - int i, j, n; - float value, maxload; -#undef CPU_BUF_SIZE -#define CPU_BUF_SIZE 2 - static float cpu[CPU_BUF_SIZE + 1];// last buffer is scratch - static float cpu_past[LCD_MAX_WIDTH]; - struct load load; - int status=0; - char out[LCD_MAX_WIDTH]; - - - - get_load(&load); - - // Shift values over by one - for(i=0; i<(CPU_BUF_SIZE-1); i++) - cpu[i] = cpu[i+1]; - - // Read new data - cpu[CPU_BUF_SIZE-1] = ((float)load.user + (float)load.system - + (float)load.nice) / (float)load.total; - - - // Only clear on first display... - if(!rep) - { - lcd.init_vbar(); - - // Make all the same, if this is the first time... - for(i=0; i maxload) maxload = cpu_past[i]; - } - - value = cpu[CPU_BUF_SIZE]; - n = (int)(value * 8.0 * (float)(lcd.hgt-1)); - - cpu_past[lcd.wid-1] = n; - lcd.vbar(lcd.wid, cpu_past[lcd.wid-1]); - - sprintf(out, "%c%c CPU GRAPH %c%c%c%c%c%c", PAD,PAD, - PAD,PAD,PAD,PAD,PAD,PAD); - lcd.string(1,1,out); - - - - if(n > maxload) maxload = n; - - if(cpu_past[lcd.wid-1] > 0 ) status = BACKLIGHT_ON; - if(maxload < 1) status = BACKLIGHT_OFF; - -// return status; - return 0; -} // End cpu_graph_screen() - - - -////////////////////////////////////////////////////////////////////// -// Clock Screen displays current time and date... -// -// TODO: 24-hour time on old clock screen, if desired. -int clock_screen(int rep) -{ - char hr[8], min[8], sec[8], ampm[8]; - char day[16], month[16]; - time_t thetime; - struct tm *rtime; - int i; - - - if(!rep) - { - lcd.clear(); - sprintf(tmp, "%c%c DATE & TIME %c%c%c%c%c", PAD, PAD, PAD, PAD, PAD, PAD, PAD); - lcd.string(1, 1, tmp); - } - - time(&thetime); - rtime = localtime(&thetime); - - strcpy(day, days[rtime->tm_wday]); - - if (rtime->tm_hour > 12) { i = 1; sprintf(hr, "%02d", (rtime->tm_hour - 12)); } - else { i = 0; sprintf(hr, "%02d", rtime->tm_hour); } - if(rtime->tm_hour == 12) i=1; - sprintf(min, "%02d", rtime->tm_min); - sprintf(sec, "%02d", rtime->tm_sec); - if (i == 1) { sprintf(ampm, "%s", "P"); } - else { sprintf(ampm, "%s", "A"); } - if (rep & 1) { sprintf(tmp, "%s:%s:%s%s %s", hr, min, sec, ampm, day); } - else { sprintf(tmp, "%s %s %s%s %s", hr, min, sec, ampm, day); } - - strcpy(month, months[rtime->tm_mon]); - - lcd.string(1, 3, tmp); - - sprintf(tmp, "%s %d, %d", month, rtime->tm_mday, (rtime->tm_year + 1900)); - lcd.string(2, 4, tmp); - - return 0; -} // End clock_screen() - - - -////////////////////////////////////////////////////////////////////// -// Time Screen displays current time and date, uptime, OS ver... -// -//+--------------------+ -//|## Linux 2.0.33 ###@| -//|Up xxx days hh:mm:ss| -//| Wed May 17, 1998 | -//|11:32:57a 100% idle| -//+--------------------+ -// - -int time_screen(int rep) -{ - char hr[8], min[8], sec[8], ampm[8]; - char day[16], month[16]; - time_t thetime; - struct tm *rtime; - double uptime, idle; - int i; - - - - if(!rep) - { - lcd.clear(); - } - - - get_uptime(&uptime, &idle); - idle = (idle * 100) / uptime; - - - ///////////////////// Write the title bar (os name and version) - memset(tmp, 0, lcd.wid+1); - sprintf(tmp, "%c%c %s %s ", - PAD, PAD, sysname, kver); - for(i=1; i<(20-strlen(sysname)-strlen(kver)-4); i++) - tmp[lcd.wid-i]=PAD; - - lcd.string(1, 1, tmp); - - /////////////////////// Display the time... - time(&thetime); - rtime = localtime(&thetime); - - if(TwentyFourHour) - { - sprintf(hr, "%02d", rtime->tm_hour); - } - else - { - if (rtime->tm_hour > 12) - { i = 1; sprintf(hr, "%02d", (rtime->tm_hour - 12)); } - else { i = 0; sprintf(hr, "%02d", rtime->tm_hour); } - } - if(rtime->tm_hour == 12) i=1; - if (i == 1) { sprintf(ampm, "%s", "P"); } - else { sprintf(ampm, "%s", "A"); } - - sprintf(min, "%02d", rtime->tm_min); - sprintf(sec, "%02d", rtime->tm_sec); - if (rep & 1) - { - if(TwentyFourHour) - sprintf(tmp, "%s:%s:%s %2i%% idle", hr, min, sec, (int)idle); - else - sprintf(tmp, "%s:%s:%s%s %2i%% idle", hr, min, sec, ampm, (int)idle); - } - else - { - if(TwentyFourHour) - sprintf(tmp, "%s %s %s %2i%% idle", hr, min, sec, (int)idle); - else - sprintf(tmp, "%s %s %s%s %2i%% idle", hr, min, sec, ampm, (int)idle); - } - // Center the output line... - i = ((lcd.wid - strlen(tmp)) / 2) + 1; - lcd.string(i, 4, tmp); - - - - - /////////////////////// Display the uptime... - strcpy(day, shortdays[rtime->tm_wday]); - strcpy(month, shortmonths[rtime->tm_mon]); - - sprintf(tmp, "%s %s %d, %d", day, month, - rtime->tm_mday, (rtime->tm_year + 1900)); - lcd.string(3, 3, tmp); - - - i = (int)uptime / 86400; - sprintf(day, "%d day%s,", i, (i != 1 ? "s" : "")); - i = ((int)uptime % 86400) / 60 / 60; - sprintf(hr, "%02i",i); - i = (((int)uptime % 86400) % 3600) / 60; - sprintf(min, "%02i",i); - i = ((int)uptime % 60); - sprintf(sec, "%02i",i); - if (rep & 1) - sprintf(tmp, "%s %s:%s:%s", day, hr, min, sec); - else - sprintf(tmp, "%s %s %s %s", day, hr, min, sec); - // Center this line automatically... - i = ((lcd.wid - strlen(tmp)) / 2) + 1; - lcd.string(i, 2, tmp); - - return 0; -} // End time_screen() - - -///////////////////////////////////////////////////////////////////////// -// Mem Screen displays info about memory and swap usage... -// -int mem_screen(int rep) -{ - int n; - struct meminfo mem[2]; - - - if(!rep) - { - lcd.clear(); - lcd.init_hbar(); - sprintf(tmp, "%c%c%c MEM %c%c%c%c SWAP %c%c", - PAD,PAD,PAD,PAD,PAD,PAD,PAD,PAD,PAD); - lcd.string(1, 1, tmp); - lcd.string(9, 2, "Totl"); - lcd.string(9, 3, "Free"); - //lcd.string(1, 4, "E F E F"); - } - - - // Total memory - get_mem_info(mem); - sprintf(tmp, "%6dk", mem[0].total); - lcd.string(1, 2, tmp); - - // Free memory (plus buffers and cache) - sprintf(tmp, "%6dk", - mem[0].free + mem[0].buffers + mem[0].cache); - lcd.string(1, 3, tmp); - - // Total swap - sprintf(tmp, "%6dk", mem[1].total); - lcd.string(14, 2, tmp); - - // Free swap - sprintf(tmp, "%6dk", mem[1].free); - lcd.string(14, 3, tmp); - - - // Empty or full? - lcd.string(1, 4, "E F E F"); - - // Free memory graph - n = (int)(35.0 - - ((float)mem[0].free + (float)mem[0].buffers + (float)mem[0].cache) - / (float)mem[0].total - * 35.0); - lcd.hbar(2, 4, n); - - // Free swap graph - n = (int)(35.0 - - (float)mem[1].free / (float)mem[1].total - * 35.0); - lcd.hbar(13, 4, n); - - - return 0; -} // End mem_screen() - - -//////////////////////////////////////////////////////////////////// -// Uptime Screen shows info about system uptime and OS version -// -int uptime_screen(int rep) -{ - int i; - char date[16], hour[8], min[8], sec[8]; - double uptime, idle; - - - if(!rep) - { - lcd.clear(); - sprintf(tmp, "%c%c SYSTEM UPTIME %c%c%c", PAD, PAD, PAD, PAD, PAD); - lcd.string(1, 1, tmp); - - sprintf(tmp, "%s %s", sysname, kver); - lcd.string(5, 4, tmp); - } - - get_uptime(&uptime, &idle); - i = (int)uptime / 86400; - sprintf(date, "%d day%s,", i, (i != 1 ? "s" : "")); - i = ((int)uptime % 86400) / 60 / 60; - sprintf(hour, "%02i",i); - i = (((int)uptime % 86400) % 3600) / 60; - sprintf(min, "%02i",i); - i = ((int)uptime % 60); - sprintf(sec, "%02i",i); - if (rep & 1) - sprintf(tmp, "%s %s:%s:%s", date, hour, min, sec); - else - sprintf(tmp, "%s %s %s %s", date, hour, min, sec); - i = ((20 - strlen(tmp)) / 2) + 1; - lcd.string(i, 3, tmp); - - - return 0; -} // End uptime_screen() - - -/////////////////////////////////////////////////////////////////////////// -// Gives disk stats. -// -// Stays onscreen until it is done. -// -int disk_screen(int rep) -{ - static mounts mnt[256]; - static int count=0; - - struct disp // Holds info to display (avoid recalculating it) - { - char dev[8]; - char cap[8]; - int full; - } table[256]; - int i, y; - static int first=0; // First line to display, sort of. - - #define huge long long int - huge size; - - - // Grab disk stats on first display, and fill "table". - if(!rep) - { - lcd.clear(); - lcd.init_hbar(); - lcd.icon(2,7); - - // Get rid of old, unmounted filesystems... - memset(table, 0, sizeof(struct disp)*256); - - count = get_fs(mnt); - first = 0; - - sprintf(tmp, "%c%c FILESYSTEMS %c%c%c%c", - PAD, PAD, PAD, PAD, PAD, PAD); - lcd.string(1, 1, tmp); - - // Fill the display structure... - if(count) - { - for(i=0; i 6) - { - sprintf(table[i].dev, "%c%s", ELLIPSIS, - (mnt[i].mpoint)+(strlen(mnt[i].mpoint)-5)); - } - else - { - sprintf(table[i].dev, "%s", mnt[i].mpoint); - } - - table[i].full = (lcd.cellwid * 4) - * (huge)(mnt[i].blocks - mnt[i].bfree) - / (huge)mnt[i].blocks; - - size = (huge)mnt[i].bsize * (huge)mnt[i].blocks; - memset(table[i].cap, 0, 8); - - // Kilobytes - if(size > 0 && size < (huge)1000*(huge)1000) - sprintf(table[i].cap, "%3.1fk", - (double)(size)/1024.0); - // Megabytes - else if(size >= (huge)1000*(huge)1000 - && size < (huge)1000*(huge)1000*(huge)1000) - sprintf(table[i].cap, "%3.1fM", - (float)(size/(huge)1024)/1024.0); - // Gigabytes - else if(size >= (huge)1000*(huge)1000*(huge)1000 - && size < (huge)1000*(huge)1000*(huge)1000*(huge)1000) - sprintf(table[i].cap, "%3.1fG", - (float)(size/((huge)1024*(huge)1024))/1024.0); - // Terabytes - else if(size >= (huge)1000*(huge)1000*(huge)1000*(huge)1000 - && size < (huge)1000*(huge)1000*(huge)1000*(huge)1000*(huge)1000) - sprintf(table[i].cap, "%3.1fT", - (float)(size/((huge)1024*(huge)1024*(huge)1024))/1024.0); - - // PectaBytes -- Yeah! I want some! - else if(size >= (huge)1000*(huge)1000*(huge)1000*(huge)1000*(huge)1000 - && size < (huge)1000*(huge)1000*(huge)1000*(huge)1000*(huge)1000*(huge)1000) - sprintf(table[i].cap, "%3.1fP", - (float)(size/((huge)1024*(huge)1024*(huge)1024*(huge)1024))/1024.0); - - } - } - } // End if(!rep) - - - // Increment this once per second. - if((rep&7) == 0) first++; - - - if (!count) - { - lcd.string(1, 2, "Error Retrieving"); - lcd.string(5, 3, "Filesystem Stats"); - return 0; - } - - // If we are done, tell the system to keep going. - if (first >= count+1) - return CONTINUE; - - - // Display stuff... (show for two seconds, then scroll once per - // second, then hold at the end for two seconds) - for(y=0; y<3; y++) - { - i = first - 2; - if(i>count-3) i=count-3; - if(i<0) i=0; - i += y; - - if(table[i].dev[0] == 0) continue; - sprintf(tmp, "%-6s %6s E F", table[i].dev, table[i].cap); - - lcd.string(1, y+2, tmp); - lcd.hbar(16, y+2, table[i].full); - } - - - #undef huge - -/* -// ** FILESYSTEMS ***** -// / 543.2M E----F -// /dos/c 2.1G E----F -// /stuff 4.3G E----F -*/ - return HOLD_SCREEN; -} - - -/////////////////////////////////////////////////////////////////////////// -// Shows a display very similar to "xload"'s histogram. -// - -int xload_screen(int rep) -{ - static float loads[LCD_MAX_WIDTH]; - static int first_time=1; - int n; - float loadmax=0, factor, x; - int status = 0; - - - if(first_time) // Only the first time this is ever called... - { - memset(loads, 0, sizeof(float)*LCD_MAX_WIDTH); - first_time = 0; - } - - if(!rep) - { - lcd.clear(); - } - - - for(n=0; n<(lcd.wid-2); n++) loads[n] = loads[n+1]; - loads[lcd.wid-2] = get_loadavg(); - - for(n=0; n loadmax) loadmax = loads[n]; - - lcd.string(20, 4, "0"); - n = (int)loadmax; - if ((float)n < loadmax) { n++; } - sprintf(tmp, "%i", n); lcd.string(20, 2, tmp); - - if (loadmax < 1.0) factor = 24.0; - else factor = 24 / (float)n; - - for(n=0; n LOAD_MIN) status = BACKLIGHT_ON; - if(loads[lcd.wid-2] > LOAD_MAX) status = BLINK_ON; - - // This must be drawn *after* the vertical bars... (?) - sprintf(tmp, "%c%c LOAD AVG %2.2f %c%c", PAD, PAD, loads[lcd.wid-2], PAD, PAD); - lcd.string(1, 1, tmp); - - if(!rep) - lcd.init_vbar(); - - - return status; -} // End xload_screen() - - - - - -//////////////////////////////////////////////////////////////////////// -// Battery Screen shows apm battery status... -// - -//#################### -//## Battery: 100% ### -//AC: Unknown -//Batt: Low (Charging) -//E------------------F - -int battery_screen(int rep) -{ - int acstat=0, battstat=0, battflag=0, percent=0; - - - // Only run once every 16 frames... - if(rep&0x0f) return 0; - - get_batt_stat(&acstat, &battstat, &battflag, &percent); - - lcd.clear(); - - - sprintf(tmp, "%c%c Battery: ", PAD, PAD); - - if(percent >= 0) sprintf(tmp+strlen(tmp), "%i%% %c%c%c%c", - percent, PAD, PAD, PAD, PAD); - else sprintf(tmp+strlen(tmp), "??%% %c%c%c", PAD, PAD, PAD); - - lcd.string(1,1,tmp); - - - switch(acstat) - { - case 0: sprintf(tmp, "AC: Off"); - break; - case 1: sprintf(tmp, "AC: On"); - break; - case 2: sprintf(tmp, "AC: Backup"); - break; - default: sprintf(tmp, "AC: Unknown"); - break; - } - - lcd.string(1,2,tmp); - - - if(battflag == 0xff) - { - sprintf(tmp, "Battery Stat Unknown"); - } - else - { - sprintf(tmp, "Batt:"); - if(battflag & 1) sprintf(tmp+strlen(tmp), " High"); - if(battflag & 2) sprintf(tmp+strlen(tmp), " Low"); - if(battflag & 4) sprintf(tmp+strlen(tmp), " Critical"); - if(battflag & 8 - ||battstat == 3) sprintf(tmp+strlen(tmp), " Charging"); - if(battflag & 128) sprintf(tmp+strlen(tmp), " (NONE)"); - } - lcd.string(1,3,tmp); - - lcd.chr(1,4, 'E'); - lcd.chr(lcd.wid,4, 'F'); - - if(percent > 0) - { - lcd.hbar(2,4, (percent * ((lcd.wid-2)*lcd.cellwid)/100)); - } - - - return 0; -} - - - -//////////////////////////////////////////////////////////////////////// -// Credit Screen shows who wrote this... -// -int credit_screen(int rep) -{ - - if(!rep) - { - lcd.clear(); - sprintf(tmp, "%c%c LCDPROC %s %c%c%c%c", - PAD, PAD, version, PAD, PAD, PAD, PAD); - lcd.string(1, 1, tmp); - lcd.string(1, 2, " for Linux "); - lcd.string(1, 3, " by William Ferrell "); - lcd.string(1, 4, " and Scott Scriven "); - } - - return 0; -} // End credit_screen() - - -////////////////////////////////////////////////////////////////////// -// This is mostly for debugging. It should never show up. -// -int dumbass_screen(int rep) -{ - - lcd.string(1,1, "---=== Haha... ==---"); - lcd.string(1,2, " You specified an "); - lcd.string(1,3, " INVALID MODE!!! "); - lcd.string(1,4, "---== Ya LOSER! ==--"); -/* - lcd.string(1,1, "--===GO AWAY!!!===--"); - lcd.string(1,2, " You're a slimy, "); - lcd.string(1,3, " mold-ridden "); - lcd.string(1,4, " pop-tart! "); -*/ - - return BLINK_ON; -} - - -////////////////////////////////////////////////////////////////////////// -// This gets called upon program exit, to say "goodbye" -// -int goodbye_screen(int rep) -{ - - lcd.clear(); -/* - lcd.string(1,1, "---===SHUTDOWN===---"); - lcd.string(1,2, " DANGER, WILL "); - lcd.string(1,3, " ROBINSON! "); - lcd.string(1,4, "---===EJECT!!!===---"); - usleep(250000); -*/ - - lcd.string(1,1, " "); - lcd.string(1,2, " Thanks for using "); - lcd.string(1,3, " LCDproc and Linux! "); - lcd.string(1,4, " "); - - return 0; -} - - diff --git a/old/mode.h b/old/mode.h deleted file mode 100644 index 5278aaa..0000000 --- a/old/mode.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef MODE_H -#define MODE_H - - -//TODO: Net stats screen... -//TODO: "Who" -//TODO: biff / mail checking - -// Character to use for padding title bars, etc... -extern int PAD; -// Character for the "..." symbol. -extern int ELLIPSIS; - -int mode_init(); -void mode_close(); - -int cpu_screen(int rep); -int cpu_graph_screen(int rep); -int clock_screen(int rep); -int mem_screen(int rep); -int uptime_screen(int rep); -int time_screen(int rep); -int disk_screen(int rep); -int xload_screen(int rep); -int battery_screen(int rep); -int credit_screen(int rep); -int dumbass_screen(int rep); -int goodbye_screen(int rep); - -#endif diff --git a/old/sockets.c b/old/sockets.c deleted file mode 100644 index e4c5e22..0000000 --- a/old/sockets.c +++ /dev/null @@ -1,273 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sockets.h" - - -/************************************************** - LCDproc sockets code... - - This is messy, and needs to be finished. -**************************************************/ - -fd_set active_fd_set, read_fd_set; -int sock; - -// Length of longest transmission allowed at once... -#define MAXMSG 8192 - - - -int init_sockaddr (sockaddr_in *name, - const char *hostname, - unsigned short int port) -{ - struct hostent *hostinfo; - - name->sin_family = AF_INET; - name->sin_port = htons (port); - hostinfo = gethostbyname (hostname); - if (hostinfo == NULL) - { - fprintf (stderr,"Unknown host %s.\n", hostname); - return -1; - } - name->sin_addr = *(struct in_addr *) hostinfo->h_addr; - - return 0; - -} - - -#if 0 -// Creates a socket as a file... -int CreateNamedSocket(char *filename) -{ - struct sockaddr_un name; - size_t size; - - sock=socket(PF_FILE, SOCK_STREAM, 0); - if(sock < 0) return -1; - - - name.sun_family = AF_FILE; - strcpy (name.sun_path, filename); - - /* The size of the address is - the offset of the start of the filename, - plus its length, - plus one for the terminating null byte. */ - size = (offsetof (struct sockaddr_un, sun_path) - + strlen (name.sun_path) + 1); - - if (bind (sock, (struct sockaddr *) &name, size) < 0) - return -1; - - return sock; -} -#endif - -// Creates a socket in internet space -int CreateInetSocket(unsigned short int port) -{ - struct sockaddr_in name; - - /* Create the socket. */ - //fprintf(stderr,"Creating Inet Socket\n"); - sock = socket (PF_INET, SOCK_STREAM, 0); - if (sock < 0) - return -1; - - /* Give the socket a name. */ - //fprintf(stderr,"Binding Inet Socket\n"); - name.sin_family = AF_INET; - name.sin_port = htons (port); - name.sin_addr.s_addr = htonl (INADDR_ANY); - if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) - return -1; - - return sock; - -} - -// Checks the LCDproc port for a response... -int PingLCDport() -{ - struct sockaddr_in servername; - int err=0; - char ping[16] = {0xFE, 0x01, 0}; - - - //fprintf(stderr,"Creating socket (client)\n"); - sock = socket(PF_INET, SOCK_STREAM, 0); - if(sock < 0) - { - fprintf(stderr,"Error creating socket (client)\n"); - return sock; - } - //else fprintf(stderr,"Created socket (%i) (client)\n", sock); - - - init_sockaddr(&servername, "localhost", LCDPORT); - - err = connect (sock, - (struct sockaddr *) &servername, - sizeof (servername)); - if(err<0) - { - //fprintf (stderr,"connect failed (client)\n"); - shutdown(sock, 2); - return 0; // Normal exit if server doesn't exist... - } - - err = write (sock, ping, strlen(ping) + 1); - if (err < 0) - { - fprintf (stderr,"socket write error (client)"); - shutdown(sock, 2); - return err; - } - - shutdown(sock, 2); - - return 1; -} - -int ConnectAsClient() -{ - return 0; -} - -int StartSocketServer() -{ - - /* Create the socket and set it up to accept connections. */ - sock = CreateInetSocket (LCDPORT); - if(sock < 0) - { - fprintf(stderr,"Error creating socket (server)\n"); - return -1; - } - - - if (listen (sock, 1) < 0) - { - fprintf (stderr,"Listen error (server)\n"); - return -1; - } - - /* Initialize the set of active sockets. */ - FD_ZERO (&active_fd_set); - FD_SET (sock, &active_fd_set); - - return sock; -} - - -int PollSockets() -{ - int i; - struct sockaddr_in clientname; - size_t size; - struct timeval t; - - - t.tv_sec = 0; - t.tv_usec = 0; - - /* Block until input arrives on one or more active sockets. */ - read_fd_set = active_fd_set; - - if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, &t) < 0) - { - fprintf (stderr,"Select error (server)\n"); - return -1; - } - - /* Service all the sockets with input pending. */ - for (i = 0; i < FD_SETSIZE; ++i) - if (FD_ISSET (i, &read_fd_set)) - { - if (i == sock) - { - /* Connection request on original socket. */ - int new; - size = sizeof (clientname); - new = accept (sock, - (struct sockaddr *) &clientname, - &size); - if (new < 0) - { - fprintf (stderr,"Accept error (server)\n"); - return -1; - } - fprintf (stderr,"Server: connect from host %s, port %hd.\n", - inet_ntoa (clientname.sin_addr), - ntohs (clientname.sin_port)); - FD_SET (new, &active_fd_set); - } - else - { - /* Data arriving on an already-connected socket. */ - if (read_from_client (i) < 0) - { - close (i); - FD_CLR (i, &active_fd_set); - fprintf(stderr,"Closed connection %i\n", i); - } - } - } - return 0; -} - - -int read_from_client (int filedes) -{ - char buffer[MAXMSG]; - int nbytes; - - nbytes = read (filedes, buffer, MAXMSG); - buffer[nbytes] = 0; - buffer[nbytes+1] = 0; - - if (nbytes < 0) // Read error - { - fprintf (stderr,"Read error (server)\n"); - return -1; - } - else if (nbytes == 0) // EOF - return -1; - else // Data Read - { - fprintf (stderr,"Server: got message: `%s'\n", buffer); - return 0; - } -} - -int CloseAllConnections() -{ - int i; - - /* Service all the sockets with input pending. */ - for (i = 0; i < FD_SETSIZE; ++i) - if (FD_ISSET (i, &read_fd_set)) - { - /* Data arriving on an already-connected socket. */ - close (i); - FD_CLR (i, &active_fd_set); - fprintf(stderr,"Closed connection %i\n", i); - } - - return 0; - -} diff --git a/old/sockets.h b/old/sockets.h deleted file mode 100644 index 064a12f..0000000 --- a/old/sockets.h +++ /dev/null @@ -1,99 +0,0 @@ -#define LCDPORT 13666 - -/********************************************************************** - LCDproc socket interface grammar: - - RawText Print whatever you send, at whatever the current position is. - - or... - - 0xFE Command prefix, followed by... - - 0x00 EOT. End of transmission, where applicicable. - 0x01 Ping. Will respond with a "pong". - 'k',x Send "keypad" input, character x (A-Z) - - ?,x,...,EOT Send new mode sequence (x,...)... - ?,x Switch to new mode x immediately - ?,xxxx Pause in current mode for x frames/seconds (0=infinite) - ? Play -- continue mode cycle. - ?,x,y,...,EOT - Send raw text to be displayed. x is style (raw, wrapped), - and y is num frames between lines displayed. - - ?,... Send MtxOrb-like control commands (bargraphs, etc) - - ... more to come later ... -**********************************************************************/ - -/***************************************************************** - LCDproc command line interface: (while running) - - -command - Tells LCDproc to interpret stdin as raw commands to send through - the socket. Input must be formatted as above, in socket interface. - -function f - Runs LCDproc external function f, where f is one of the predefined - functions which can be assigned to keypad keys. (like NEXTMODE, etc) - -key x - Simulates keypad press of key 'x', where 'x' is (A-Z). - -print [time] - Prints stdin on LCD one line at a time, with no line-wrapping (raw), - with [time] frames between updates (lines). - -wrap [time] - Prints stdin as with "-print", but with line wrapping when possible. - -contrast xxx - Sets contrast to xxx (decimal) - -backlight [on/off] - Turns backlight [on/off/auto], or toggles it. - If [off], stays off. - If [on], stays on. - If [auto], LCDproc controls backlight based on load, etc... - -exit - -quit - Duh... :) - -******************************************************************/ - -/***************************************************************** - LCDproc stuff supported in config file (loose approximation): - - Grammar is tcl-style. I.e., "command arg1 arg2 ...". - Spaces are used as argument separators, *until* it thinks it has the final - argument. So, "function thing shell myprogram arg1 arg2 arg3" would be - split into "function", "thing", "shell", and "myprogram arg1 arg2 arg3". - - User-definable functions (use built-in's to create new ones?): - Function mp3NextSong Shell /usr/local/bin/mp3player -next - Function MySequence Sequence cpu mem xload - Function OtherSequence Sequence time cd xload - - Keypad keys can be bound to any _function_: - Key A mp3NextSong - Key B HaltSystem - Key C Menu - Key D Next/+ - Key E OtherSequence - - -******************************************************************/ - -typedef struct sockaddr_in sockaddr_in; - -int init_sockaddr (sockaddr_in *name, - const char *hostname, - unsigned short int port); - -// Creates a socket in internet space -int CreateInetSocket(unsigned short int port); - -// Checks the LCDproc port for a response... -int PingLCDport(); - -int StartSocketServer(); - -int PollSockets(); - -int read_from_client (int filedes); - -int CloseAllConnections(); diff --git a/old/stat.c b/old/stat.c deleted file mode 100644 index 45705ec..0000000 --- a/old/stat.c +++ /dev/null @@ -1,644 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "stat.h" -#include "lcd.h" - - -/* - Don't use this yet! It's barely even started... - */ - - - -struct load { unsigned long total, user, system, nice, idle; }; -struct meminfo { int total, cache, buffers, free, shared; }; -static char buffer[1024]; - -// Nothing else can see these... -static int meminfo_fd, load_fd, loadavg_fd, uptime_fd; - -static char kver[SYS_NMLN]; -static char sysname[SYS_NMLN]; - -static void reread(int f, char *errmsg); -static int getentry(const char *tag, const char *bufptr); -static void get_mem_info(struct meminfo *result); -static double get_loadavg(void); -static double get_uptime(void); -static void get_load(struct load * result); - - - -int stat_init() -{ - struct utsname *unamebuf = - (struct utsname *) malloc( sizeof(struct utsname) ); - - meminfo_fd = open("/proc/meminfo",O_RDONLY); - loadavg_fd = open("/proc/loadavg",O_RDONLY); - load_fd = open("/proc/stat",O_RDONLY); - uptime_fd = open("/proc/uptime",O_RDONLY); - -#if 0 - kversion_fd = open("/proc/sys/kernel/osrelease",O_RDONLY); - - reread(kversion_fd, "main:"); - sscanf(buffer, "%s", kver); - - close(kversion_fd); -# endif - - /* Get OS name and version from uname() */ - if( uname( unamebuf ) != 0 ) { - perror( "Error calling uname:" ); - } - strcpy( kver, unamebuf->release ); - strcpy( sysname, unamebuf->sysname ); - - return 0; -} - -void stat_close() -{ - close(meminfo_fd); - close(loadavg_fd); - close(load_fd); - close(uptime_fd); -} - - -static void reread(int f, char *errmsg) -{ - if (lseek(f, 0L, 0) == 0 && read(f, buffer, sizeof(buffer) - 1 ) > 0 ) - return; - perror(errmsg); - exit(1); -} - -static int getentry(const char *tag, const char *bufptr) -{ - char *tail; - int retval, len = strlen(tag); - - while (bufptr) - { - if (*bufptr == '\n') bufptr++; - if (!strncmp(tag, bufptr, len)) - { - retval = strtol(bufptr + len, &tail, 10); - if (tail == bufptr + len) return -1; - else return retval; - } - bufptr = strchr( bufptr, '\n'); - } - return -1; -} - -static void get_mem_info(struct meminfo *result) -{ -// int i, res; char *bufptr; - - reread(meminfo_fd, "get_meminfo:"); - result[0].total = getentry("MemTotal:", buffer); - result[0].free = getentry("MemFree:", buffer); - result[0].shared = getentry("MemShared:", buffer); - result[0].buffers = getentry("Buffers:", buffer); - result[0].cache = getentry("Cached:", buffer); - result[1].total = getentry("SwapTotal:", buffer); - result[1].free = getentry("SwapFree:", buffer); -} - -static double get_loadavg(void) -{ - double load; - - reread(loadavg_fd, "get_load:"); - sscanf(buffer, "%lf", &load); - return load; -} - -static double get_uptime(void) -{ - double uptime; - - reread(uptime_fd, "get_uptime:"); - sscanf(buffer, "%lf", &uptime); - return uptime; -} - -static void get_load(struct load * result) -{ - static struct load last_load = { 0, 0, 0, 0, 0 }; struct load curr_load; - - reread(load_fd, "get_load:"); - sscanf(buffer, "%*s %lu %lu %lu %lu\n", - &curr_load.user, &curr_load.nice, &curr_load.system, &curr_load.idle); - curr_load.total = curr_load.user + curr_load.nice - + curr_load.system + curr_load.idle; - result->total = curr_load.total - last_load.total; - result->user = curr_load.user - last_load.user; - result->nice = curr_load.nice - last_load.nice; - result->system = curr_load.system - last_load.system; - result->idle = curr_load.idle - last_load.idle; - last_load.total = curr_load.total; - last_load.user = curr_load.user; - last_load.nice = curr_load.nice; - last_load.system = curr_load.system; - last_load.idle = curr_load.idle; -} - - -static char tmp[256]; - -// A couple of tables for later use... -static char *days[] = { - "Sunday, ", - "Monday, ", - "Tuesday, ", - "Wednesday,", - "Thursday, ", - "Friday, ", - "Saturday, ", -}; - -static char *months[] = { - " January", - " February", - " March", - " April", - " May", - " June", - " July", - " August", - "September", - " October", - " November", - " December", -}; - - -////////////////////////////////////////////////////////////////////////// -// CPU screen shows info about percentage of the CPU being used -// -int cpu_screen(int rep) -{ -#undef CPU_BUF_SIZE -#define CPU_BUF_SIZE 4 - int i, j, n; - float value; - static float cpu[CPU_BUF_SIZE + 1][5];// last buffer is scratch - struct load load; - - - - get_load(&load); - - // Shift values over by one - for(i=0; i<(CPU_BUF_SIZE-1); i++) - for(j=0; j<5; j++) - cpu[i][j] = cpu[i+1][j]; - - // Read new data - cpu[CPU_BUF_SIZE-1][0] = ((float)load.user / (float)load.total) * 100.0; - cpu[CPU_BUF_SIZE-1][1] = ((float)load.system / (float)load.total) * 100.0; - cpu[CPU_BUF_SIZE-1][2] = ((float)load.nice / (float)load.total) * 100.0; - cpu[CPU_BUF_SIZE-1][3] = ((float)load.idle / (float)load.total) * 100.0; - cpu[CPU_BUF_SIZE-1][4] = (((float)load.user + (float)load.system + - (float)load.nice) / (float)load.total) * 100.0; - - // Only clear on first display... - if(!rep) - { - lcd.clear(); - lcd.init_hbar(); - - sprintf(tmp, "%c%c CPU LOAD %c%c", PAD, PAD, PAD, PAD); - - lcd.string(1, 1, tmp); - lcd.string(1, 2, "Usr 0.0% Nice 0.0%"); - lcd.string(1, 3, "Sys 0.0% Idle 0.0%"); - lcd.string(1, 4, "0% 100%"); - - // Make all the same, if this is the first time... - for(i=0; i= 99.9) { lcd.string(13, 1, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(13, 1, tmp); } - - value = cpu[CPU_BUF_SIZE][0]; - if (value >= 99.9) { lcd.string(5, 2, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(5, 2, tmp); } - - value = cpu[CPU_BUF_SIZE][1]; - if (value >= 99.9) { lcd.string(5, 3, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(5, 3, tmp); } - - value = cpu[CPU_BUF_SIZE][2]; - if (value >= 99.9) { lcd.string(16, 2, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(16, 2, tmp); } - - value = cpu[CPU_BUF_SIZE][3]; - if (value >= 99.9) { lcd.string(16, 3, " 100%"); } - else { sprintf(tmp, "%4.1f%%", value); lcd.string(16, 3, tmp); } - - value = cpu[CPU_BUF_SIZE][4]; - n = (int)(value * 70.0 / 100.0); - lcd.string(1, 4, "0% 100%"); - lcd.hbar(3, 4, n); - - return 0; -} // End cpu_screen() - - - -////////////////////////////////////////////////////////////////////////// -// Cpu Graph Screen shows a quick-moving histogram of CPU use. -// -int cpu_graph_screen(int rep) -{ - int i, j, n; - float value, maxload; -#undef CPU_BUF_SIZE -#define CPU_BUF_SIZE 2 - static float cpu[CPU_BUF_SIZE + 1];// last buffer is scratch - static float cpu_past[LCD_MAX_WIDTH]; - struct load load; - int status=0; - char out[LCD_MAX_WIDTH]; - - - - get_load(&load); - - // Shift values over by one - for(i=0; i<(CPU_BUF_SIZE-1); i++) - cpu[i] = cpu[i+1]; - - // Read new data - cpu[CPU_BUF_SIZE-1] = ((float)load.user + (float)load.system - + (float)load.nice) / (float)load.total; - - - // Only clear on first display... - if(!rep) - { - lcd.init_vbar(); - - // Make all the same, if this is the first time... - for(i=0; i maxload) maxload = cpu_past[i]; - } - - value = cpu[CPU_BUF_SIZE]; - n = (int)(value * 8.0 * (float)(lcd.hgt-1)); - - cpu_past[lcd.wid-1] = n; - lcd.vbar(lcd.wid, cpu_past[lcd.wid-1]); - - sprintf(out, "%c%c CPU GRAPH %c%c%c%c%c%c", PAD,PAD, - PAD,PAD,PAD,PAD,PAD,PAD); - lcd.string(1,1,out); - - - - if(n > maxload) maxload = n; - - if(cpu_past[lcd.wid-1] > 0 ) status = BACKLIGHT_ON; - if(maxload < 1) status = BACKLIGHT_OFF; - -// return status; - return 0; -} // End cpu_graph_screen() - - - -////////////////////////////////////////////////////////////////////// -// Clock Screen displays current time and date... -// -// TODO: 24-hour time, if desired. -int clock_screen(int rep) -{ - char hr[8], min[8], sec[8], ampm[8]; - char day[16], month[16]; - time_t thetime; - struct tm *rtime; - int i; - - - if(!rep) - { - lcd.clear(); - sprintf(tmp, "%c%c DATE & TIME %c%c%c%c%c", PAD, PAD, PAD, PAD, PAD, PAD, PAD); - lcd.string(1, 1, tmp); - } - - time(&thetime); - rtime = localtime(&thetime); - - strcpy(day, days[rtime->tm_wday]); - - if (rtime->tm_hour > 12) { i = 1; sprintf(hr, "%02d", (rtime->tm_hour - 12)); } - else { i = 0; sprintf(hr, "%02d", rtime->tm_hour); } - if(rtime->tm_hour == 12) i=1; - sprintf(min, "%02d", rtime->tm_min); - sprintf(sec, "%02d", rtime->tm_sec); - if (i == 1) { sprintf(ampm, "%s", "P"); } - else { sprintf(ampm, "%s", "A"); } - if (rep & 1) { sprintf(tmp, "%s:%s:%s%s %s", hr, min, sec, ampm, day); } - else { sprintf(tmp, "%s %s %s%s %s", hr, min, sec, ampm, day); } - - strcpy(month, months[rtime->tm_mon]); - - lcd.string(1, 3, tmp); - - sprintf(tmp, "%s %d, %d", month, rtime->tm_mday, (rtime->tm_year + 1900)); - lcd.string(2, 4, tmp); - - return 0; -} // End clock_screen() - - -///////////////////////////////////////////////////////////////////////// -// Mem Screen displays info about memory and swap usage... -// -int mem_screen(int rep) -{ - int n; - struct meminfo mem[2]; - - - if(!rep) - { - lcd.clear(); - lcd.init_hbar(); - sprintf(tmp, "%c%c%c MEM %c%c%c%c SWAP %c%c", - PAD,PAD,PAD,PAD,PAD,PAD,PAD,PAD,PAD); - lcd.string(1, 1, tmp); - lcd.string(9, 2, "Totl"); - lcd.string(9, 3, "Free"); - lcd.string(1, 4, "E F E F"); - } - - get_mem_info(mem); - sprintf(tmp, "%6dk", mem[0].total); - lcd.string(1, 2, tmp); - sprintf(tmp, "%6dk", mem[0].free); - lcd.string(1, 3, tmp); - sprintf(tmp, "%6dk", mem[1].total); - lcd.string(14, 2, tmp); - sprintf(tmp, "%6dk", mem[1].free); - lcd.string(14, 3, tmp); - -// This gives just main memory usage -// n = (int)(50.0 - (float)mem[0].free / (float)mem[0].total * 50.0); -// This uses main + swap usage... - - lcd.string(1, 4, "E F E F"); - - n = (int)(35.0 - - (float)mem[0].free / (float)mem[0].total - * 35.0); - lcd.hbar(2, 4, n); - - n = (int)(35.0 - - (float)mem[1].free / (float)mem[1].total - * 35.0); - lcd.hbar(13, 4, n); - - -/* - { - int i; - for(i=0; i<100; i++) - { - lcd.hbar(1,1,i); - lcd.hbar(1,2,i); - lcd.hbar(1,3,i); - lcd.hbar(1,4,i); - usleep(100000); - } - } -*/ - - return 0; -} // End mem_screen() - - -//////////////////////////////////////////////////////////////////// -// Uptime Screen shows info about system uptime and OS version -// -int uptime_screen(int rep) -{ - int i; - char date[16], hour[8], min[8], sec[8]; - double uptime; - - - if(!rep) - { - lcd.clear(); - sprintf(tmp, "%c%c SYSTEM UPTIME %c%c%c", PAD, PAD, PAD, PAD, PAD); - lcd.string(1, 1, tmp); - - sprintf(tmp, "%s %s", sysname, kver); - lcd.string(5, 4, tmp); - } - - uptime = get_uptime(); - i = (int)uptime / 86400; - sprintf(date, "%d day%s,", i, (i != 1 ? "s" : "")); - i = ((int)uptime % 86400) / 60 / 60; - sprintf(hour, "%02i",i); - i = (((int)uptime % 86400) % 3600) / 60; - sprintf(min, "%02i",i); - i = ((int)uptime % 60); - sprintf(sec, "%02i",i); - if (rep & 1) - sprintf(tmp, "%s %s:%s:%s", date, hour, min, sec); - else - sprintf(tmp, "%s %s %s %s", date, hour, min, sec); - i = ((20 - strlen(tmp)) / 2) + 1; - lcd.string(i, 3, tmp); - - - return 0; -} // End uptime_screen() - - -/////////////////////////////////////////////////////////////////////////// -// Shows a display very similar to "xload"'s histogram. -// - -int xload_screen(int rep) -{ - static float loads[LCD_MAX_WIDTH]; - static int first_time=1; - int n; - float loadmax=0, factor, x; - int status = 0; - - - if(first_time) // Only the first time this is ever called... - { - memset(loads, 0, sizeof(float)*LCD_MAX_WIDTH); - first_time = 0; - } - - if(!rep) - { - lcd.clear(); - } - - - for(n=0; n<(lcd.wid-2); n++) loads[n] = loads[n+1]; - loads[lcd.wid-2] = get_loadavg(); - - for(n=0; n loadmax) loadmax = loads[n]; - - lcd.string(20, 4, "0"); - n = (int)loadmax; - if ((float)n < loadmax) { n++; } - sprintf(tmp, "%i", n); lcd.string(20, 2, tmp); - - if (loadmax < 1.0) factor = 24.0; - else factor = 24 / (float)n; - - for(n=0; n 0.05) status = BACKLIGHT_ON; - if(loads[lcd.wid-2] > LOAD_THRESHOLD) status = BLINK_ON; - - // This must be drawn *after* the vertical bars... (?) - sprintf(tmp, "%c%c LOAD AVG %2.2f %c%c", PAD, PAD, loads[lcd.wid-2], PAD, PAD); - lcd.string(1, 1, tmp); - - if(!rep) - lcd.init_vbar(); - - - return status; -} // End xload_screen() - - - -//////////////////////////////////////////////////////////////////////// -// Credit Screen shows who wrote this... -// -int credit_screen(int rep) -{ - - if(!rep) - { - lcd.clear(); - sprintf(tmp, "%c%c LCDPROC %s %c%c%c%c", - PAD, PAD, version, PAD, PAD, PAD, PAD); - lcd.string(1, 1, tmp); - lcd.string(1, 2, " for Linux "); - lcd.string(1, 3, " by William Ferrell "); - lcd.string(1, 4, " and Scott Scriven "); - } - - return 0; -} // End credit_screen() - - -////////////////////////////////////////////////////////////////////// -// This is mostly for debugging. It should never show up. -// -int dumbass_screen(int rep) -{ - - lcd.string(1,1, "---=== Haha... ==---"); - lcd.string(1,2, " You specified an "); - lcd.string(1,3, " INVALID MODE!!! "); - lcd.string(1,4, "---== Ya LOSER! ==--"); -/* - lcd.string(1,1, "--===GO AWAY!!!===--"); - lcd.string(1,2, " You're a slimy, "); - lcd.string(1,3, " mold-ridden "); - lcd.string(1,4, " pop-tart! "); -*/ - - return BLINK_ON; -} - - -////////////////////////////////////////////////////////////////////////// -// This gets called upon program exit, to say "goodbye" -// -int goodbye_screen(int rep) -{ - - lcd.clear(); -/* - lcd.string(1,1, "---===SHUTDOWN===---"); - lcd.string(1,2, " DANGER, WILL "); - lcd.string(1,3, " ROBINSON! "); - lcd.string(1,4, "---===EJECT!!!===---"); - usleep(250000); -*/ - - lcd.string(1,1, " "); - lcd.string(1,2, " Thanks for using "); - lcd.string(1,3, " LCDproc and Linux! "); - lcd.string(1,4, " "); - - return 0; -} - - diff --git a/old/stat.h b/old/stat.h deleted file mode 100644 index 870e2b1..0000000 --- a/old/stat.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef MODE_H -#define MODE_H - -/* - Don't use this yet! It's barely even started! - */ - -int stat_init(); -void stat_close(); - -typedef struct status -{ - // should hold persistent data somehow... -// data_type data; - - // Takes position onscreen (x,y), and - // format (i=int, f=float, h=horz bar, v=vert bar, 2=24-hour, 1=12-hour, - // x=xload-style, etc...) - // Each stat will only draw valid formats... - // size is max size (graphs) or num digits, etc... (0 is "max" size) - // reread specifies to re-grab the value first. - void (*draw)(int x, int y, int size, char format, int reread); - void (*read)(int reread); - - // Should also maybe be able to return the data? -// return_type (*get)(); - -}; - - -extern status cpu; -extern status cpu_nice; -extern status cpu_idle; -extern status cpu_sys; -extern status cpu_usr; - -extern status mem_free; -extern status mem_total; -extern status swap_free; -extern status swap_total; - -extern status load; - -extern status date; -extern status uptime; - -extern status os_ver; - -extern status disk_activity; -extern status disk_free; -extern status disk_total; - -extern status net_sent; -extern status net_recv; -extern status net_rate; - - -#endif diff --git a/tests/LL_test.c b/tests/LL_test.c deleted file mode 100644 index 84985a5..0000000 --- a/tests/LL_test.c +++ /dev/null @@ -1,156 +0,0 @@ -#include -#include -#include "LL.h" - - - -/* Tested functions: - LL_New(); - LL_Rewind(); - LL_AddNode(); - LL_Next(); - LL_Get(); - LL_Push(); - LL_Unshift(); - LL_InsertNode(); - LL_Roll(); - LL_UnRoll(); - LL_SwapNodes(); - LL_Sort(); - LL_Find(); - */ - -typedef struct my_struct -{ - int num; - char str[16]; -} my_struct; - - -int list_list(LL *list) -{ - my_struct *foo; - - - if(!list) return -1; - - printf("Listing the list contents...\n"); - printf(" Items: %i\n", LL_Length(list)); - - - LL_Rewind(list); - - do{ - foo = (my_struct *)LL_Get(list); - if(!foo) - { - printf("Can't read list data\n"); - return -1; - } - printf("\tItem: %i\n", foo->num); - - } while(LL_Next(list) == 0); - - - return 0; -} - -int compare(void *one, void *two) -{ - my_struct *a, *b; - - if(!one || !two) return 0; - - - a = (my_struct *)one; - b = (my_struct *)two; - - return (a->num - b->num); - -} - - - -int main() -{ - LL *list = NULL; - my_struct *foo; - my_struct bar; - int i,j; - - - list = LL_new(); - if(!list) - { - printf("Cannot create list.\n"); - return -1; - } - - for(i=0; i<10; i++) - { - foo = malloc(sizeof(my_struct)); - if(!foo) - { - printf("Can't allocate new struct\n"); - return -1; - } - - foo->num = i; - - LL_InsertNode(list, (void *)foo); - printf("Added node: %i\n", foo->num); - - } - - if(list_list(list) != 0) return -1; - - printf("Sorting the list...\n"); - - if(LL_Sort(list, compare) < 0) - { - printf("Error sorting.\n"); - return -1; - } - - if(list_list(list) != 0) return -1; - - bar.num = 5; - - printf("Searching for item \"5\"\n"); - LL_Rewind(list); - - foo = LL_Find(list, compare, &bar); - if(foo) - { - printf(" Found... %i\n", foo->num); - } - - - printf("Deallocating list...\n"); - LL_Rewind(list); - do{ - foo = LL_Get(list); - free(foo); - - } while(LL_Next(list) == 0); - - if(LL_Destroy(list) == 0) return 0; - - - printf("Attempting to access list...\n"); - - printf("List = %x\n", list); - - LL_Rewind(list); - - do{ - foo = LL_Get(list); - if(foo) printf(" Item: %i\n", foo->num); - - } while(LL_Next(list) == 0); - - - - return 0; - -} diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 1956a52..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,128 +0,0 @@ -include ../Makefile.config - -######################################################################## -# Modify these variables to fit your system. -######################################################################## - -##################### Serial device -# This should be whatever your display is connected to. -# "make install" will create a link from /dev/lcd to DEVICE -DEVICE = /dev/ttyS0 - -##################### Operating System -# Uncomment the line for your OS. -OS=-DLINUX -#OS=-DIRIX - -##################### Modescreen Options - -##### Load Screen -# Max: Load Avg at which the backlight will start blinking -MISC += -DLOAD_MAX=1.3 -# Min: Load Avg at which the backlight will turn off (asleep) -MISC += -DLOAD_MIN=0.05 - -##### Filesystems to display stats for... (comment out ones you don't want) -# NFS (Network File System) -MISC += -DSTAT_NFS -# SMBFS (Samba filesystem -- Windows drives) -MISC += -DSTAT_SMBFS - - -##################### Drivers -# Comment out each section you don't want. - -# Matrix-Orbital displays -DRIVERS += -DMTXORB_DRV -OBJ += MtxOrb.o - -# Curses text-based output -DRIVERS += -DCURSES_DRV -OBJ += curses_drv.o -LIB += -lncurses - -# Regular text output (ugly) -DRIVERS += -DTEXT_DRV -OBJ += text.o - -# Debugging output (very ugly) -DRIVERS += -DDEBUG_DRV -OBJ += debug.o - -# HD44780 parallel port lcd displays -#DRIVERS += -DHD44780_DRV -#OBJ += hd44780.o -# Pick one of the following ports to use -#LPTPORT = 0x378 -#LPTPORT = 0x278 -#LPTPORT = 0x3bc - - - -######################################################################## -# You shouldn't need to touch anything below here. -######################################################################## - -#GCC = gcc -Wall -Wp,-lang-c-c++-comments -O6 -#OBJ += main.o mode.o lcd.o sockets.o config.o drv_base.o -#MISC += $(OS) $(DRIVERS) -#VERSION = 0.4 - - -################################################################### -# Compilation... -# -#MISC=-DCURSES_DRV -g -DDEBUG - -test: - $(GCC) -c $(MISC) menutest.c - $(GCC) -c $(MISC) lcd.c - $(GCC) -c $(MISC) menu.c - $(GCC) -c $(MISC) drivers/curses_drv.c - $(GCC) -c $(MISC) drivers/drv_base.c - $(GCC) -o menutest curses_drv.o menutest.o lcd.o drv_base.o menu.o -lncurses - -test2: - $(GCC) -c $(MISC) LL.c - $(GCC) -c $(MISC) LL_test.c - $(GCC) -o LL_test LL_test.o LL.o - -test3: - $(GCC) -c $(MISC) config.c - $(GCC) -c $(MISC) config_test.c - $(GCC) -o config_test config.o config_test.o - -driver_test: - $(GCC) -g -c $(MISC) drv_test.c - $(GCC) -g -o drv_test drv_test.o ../server/drivers/libLCDdrivers.a \ - ../shared/libLCDstuff.a -lncurses - -socktest: -# $(GCC) -g -c $(MISC) socktest.c -# $(GCC) -g -o st socktest.o ../server/drivers/libLCDdrivers.a \ -# ../shared/libLCDstuff.a -lncurses - $(GCC) -c $(MISC) srvtest.c - $(GCC) -c $(MISC) ../server/sock.c - $(GCC) $(MISC) -o srv srvtest.o ../server/*.o \ - ../server/drivers/libLCDdrivers.a \ - ../shared/libLCDstuff.a -lncurses - - - - - -################################################################## -# Installation -# -install: - @echo Nothing to install in tests... - -################################################################## -# Other stuff... -# -clean: - rm -f *.o core *~ - -edit: - emacs . & - diff --git a/tests/bartest b/tests/bartest deleted file mode 100644 index 1f9ecdf..0000000 --- a/tests/bartest +++ /dev/null @@ -1,42 +0,0 @@ -hello -screen_add one - -widget_add one v string -widget_set one v 1 1 "VBars" -widget_add one h string -widget_set one h 10 1 "HBars" - -widget_add one h1 hbar -widget_add one h2 hbar -widget_add one h3 hbar -widget_set one h1 10 2 28 -widget_set one h2 10 3 27 -widget_set one h3 10 4 26 - -widget_add one v1 vbar -widget_add one v2 vbar -widget_add one v3 vbar -widget_add one v4 vbar -widget_set one v1 1 4 15 -widget_set one v2 2 4 14 -widget_set one v3 3 4 13 -widget_set one v4 4 4 12 -widget_add one v5 vbar -widget_set one v5 5 4 11 -widget_set one v5 5 4 12 -widget_set one v5 5 4 10 -widget_set one v5 5 4 8 -widget_set one v5 5 4 18 -widget_set one v5 5 4 17 -widget_set one v5 5 4 16 -widget_set one v5 5 4 15 -widget_set one v5 5 4 14 -widget_set one v5 5 4 13 -widget_set one v5 5 4 12 -widget_set one v5 5 4 11 -widget_del one h3 -widget_add one h3 hbar -widget_set one h3 10 4 16 -widget_set one h3 10 4 26 -widget_set one h3 10 4 27 -widget_set one h3 10 4 25 diff --git a/tests/ctest.c b/tests/ctest.c deleted file mode 100644 index 30331e6..0000000 --- a/tests/ctest.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -void main() -{ - char string[64]; - - int done=0; - int key=0; - - - initscr(); - cbreak(); - noecho(); - nonl(); - intrflush(stdscr, FALSE); - keypad(stdscr, TRUE); - - - while(!done) - { - key=getch(); - if(key == KEY_BACKSPACE) done=1; - sprintf(string, "Key: %i", key); - - mvaddstr(0,0,string); - - - } - -} diff --git a/tests/drv_test.c b/tests/drv_test.c deleted file mode 100644 index 20598e8..0000000 --- a/tests/drv_test.c +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include "../server/drivers/lcd.h" - -int main() -{ - int err; - int len; - - srand(time(NULL)); - - err = lcd_init(""); - - err = lcd_add_driver("joy", ""); - err = lcd_add_driver("curses", "Booger"); -// err = lcd_add_driver("text", "Booger"); - err = lcd_add_driver("MtxOrb", ""); - - lcd.clear(); - - lcd.init_hbar(); - - lcd.string(1,1,"Booger!"); - len = rand()%100; - lcd.hbar(1,2,len ); - lcd.flush(); - - for(err=0; err!='Z'; err=lcd.getkey()) - { -// if(err) - { - if(err == 'B') len--; - if(err == 'C') len++; - if(err == 'D') len--; - if(err == 'E') len-=5; - if(err == 'F') len+=5; - - lcd.clear(); - lcd.string(1,1,"Booger!"); - lcd.hbar(1,2,len ); - lcd.chr(1,3,(char)err); - - lcd.flush(); - } - usleep(125000); - } - -// sleep(1); - - lcd_shutdown(); - - return 0; -} diff --git a/tests/lcd.c b/tests/lcd.c deleted file mode 100644 index efa279b..0000000 --- a/tests/lcd.c +++ /dev/null @@ -1,638 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "LL.h" - -#include "lcd.h" - -#include "drv_base.h" - -#ifdef MTXORB_DRV -#include "MtxOrb.h" -#endif - -#ifdef TEXT_DRV -#include "text.h" -#endif - -#ifdef DEBUG_DRV -#include "debug.h" -#endif - -#ifdef CURSES_DRV -#include "curses_drv.h" -#endif - -#ifdef HD44780_DRV -#include "hd44780.h" -#endif - -// TODO: Make a Windows server, and clients...? - - -lcd_logical_driver lcd; - -lcd_physical_driver drivers[] = -{ - { "base", drv_base_init, }, -#ifdef MTXORB_DRV - { "MtxOrb", MtxOrb_init, }, -#endif -#ifdef HD44780_DRV - { "HD44780", HD44780_init, }, -#endif -#ifdef TEXT_DRV - { "text", text_init, }, -#endif -#ifdef DEBUG_DRV - { "debug", debug_init, }, -#endif -#ifdef CURSES_DRV - { "curses", curses_drv_init, }, -#endif - { NULL, NULL, }, - -}; - -LL *list; - -//////////////////////////////////////////////////////////// -// This sets up which driver to use and initializes stuff. -// -int lcd_init(char *args) -{ -// int i; - - list = LL_new(); - if(!list) - { - printf("Error allocating driver list.\n"); - return -1; - } - - lcd_drv_init(NULL, NULL); - - return lcd_add_driver("base", args); - - /* - drv_base_init(args); - - for(i=0; drivers[i].name; i++) - { - if(!strcmp(driver, drivers[i].name)) - { - return drivers[i].init(args); - } - } - - printf("Invalid driver: %s\n", driver); - return -1; - */ - -} - - -// TODO: lcd_remove_driver() - -int lcd_add_driver(char *driver, char *args) -{ - int i; - - lcd_logical_driver *add; - - for(i=0; drivers[i].name; i++) - { - - //printf("Checking driver: %s\n", drivers[i].name); - - if(0 == strcmp(driver, drivers[i].name)) - { - - //printf("Found driver: %s (%s)\n", drivers[i].name, driver); - - add = malloc(sizeof(lcd_logical_driver)); - if(!add) - { - printf("Couldn't allocate driver \"%s\".\n", driver); - return -1; - } - //printf("Allocated driver\n"); - memset(add, 0, sizeof(lcd_logical_driver)); - - add->wid = lcd.wid; add->hgt = lcd.hgt; - add->cellwid = lcd.cellwid; add->cellhgt = lcd.cellhgt; - - //printf("LCD driver info:\n\twid: %i\thgt: %i\n", - // add->wid, add->hgt); - - add->framebuf = malloc(add->wid * add->hgt); - - if(!add->framebuf) - { - printf("Couldn't allocate framebuffer for driver \"%s\".\n", - driver); - free(add); - return -1; - } - //printf("Allocated frame buffer\n"); - - LL_Push(list, (void *)add); - - return drivers[i].init(add, args); - } - } - - return -1; -} - -// TODO: Put lcd_shutdown in the shutdown function... -int lcd_shutdown() -{ - lcd_logical_driver *del; - - LL_Rewind(list); - do { - del = (lcd_logical_driver *)LL_DeleteNode(list); - if(del->close) del->close(); - free(del); - } while(LL_Length(list) > 0); - - return 0; -} - - - -int lcd_drv_init(struct lcd_logical_driver *driver, char *args) -{ -// printf("lcd_drv_init()\n"); - - lcd.wid = 20; - lcd.hgt = 4; - - lcd.framebuf = NULL; -/* - if(!lcd.framebuf) - lcd.framebuf = malloc(lcd.wid * lcd.hgt); - - if(!lcd.framebuf) - { - lcd_drv_close(); - return -1; - } - memset(lcd.framebuf, ' ', lcd.wid*lcd.hgt); -*/ -// Debugging... -// if(lcd.framebuf) printf("Frame buffer: %i\n", (int)lcd.framebuf); - - lcd.cellwid = 5; - lcd.cellhgt = 8; - - // Set up these wrapper functions... - lcd.clear = lcd_drv_clear; - lcd.string = lcd_drv_string; - lcd.chr = lcd_drv_chr; - lcd.vbar = lcd_drv_vbar; - lcd.hbar = lcd_drv_hbar; - lcd.init_num = lcd_drv_init_num; - lcd.num = lcd_drv_num; - - lcd.init = lcd_drv_init; - lcd.close = lcd_drv_close; - lcd.flush = lcd_drv_flush; - lcd.flush_box = lcd_drv_flush_box; - lcd.contrast = lcd_drv_contrast; - lcd.backlight = lcd_drv_backlight; - lcd.set_char = lcd_drv_set_char; - lcd.icon = lcd_drv_icon; - lcd.init_vbar = lcd_drv_init_vbar; - lcd.init_hbar = lcd_drv_init_hbar; - lcd.draw_frame = lcd_drv_draw_frame; - - lcd.getkey = lcd_drv_getkey; - - - return 1; // 1 is arbitrary. (must be 1 or more) -} - - - -////////////////////////////////////////////////////////////////////// -// All functions below here call their respective driver functions... -// -// The way it works is this: -// It loops through the list of drivers, calling each one to keep -// them all synchronized. During this loop... -// - First, set the framebuffer to point to the drivers' framebuffer. -// (this ensures that whatever driver gets called will operate on -// the correct buffer) -// - Then, it checks to see what sort of call to make. -// driver->func() > 0 means it should call the driver function. -// driver->func() == NULL means it should not make a call. -// driver->func() == -1 means it should call the generic driver. -////////////////////////////////////////////////////////////////////// - - -void lcd_drv_close() -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->close > 0) - driver->close(); - else if((int)driver->close == -1) - { - drv_base->close(); - } - } - } while(LL_Next(list) == 0); - -} - -void lcd_drv_clear() -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->clear > 0) - driver->clear(); - else if((int)driver->clear == -1) - { - drv_base->clear(); - } - } - } while(LL_Next(list) == 0); - -} - - -void lcd_drv_flush() -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->flush > 0) - driver->flush(); - else if((int)driver->flush == -1) - { - drv_base->flush(); - } - } - } while(LL_Next(list) == 0); -} - - -void lcd_drv_string(int x, int y, char string[]) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->string > 0) - driver->string(x,y,string); - else if((int)driver->string == -1) - { - drv_base->string(x,y,string); - } - } - } while(LL_Next(list) == 0); -} - -void lcd_drv_chr(int x, int y, char c) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->chr > 0) - driver->chr(x,y,c); - else if((int)driver->chr == -1) - { - drv_base->chr(x,y,c); - } - } - } while(LL_Next(list) == 0); -} - - - -void lcd_drv_contrast(int contrast) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->contrast > 0) - driver->contrast(contrast); - else if((int)driver->contrast == -1) - { - drv_base->contrast(contrast); - } - } - } while(LL_Next(list) == 0); -} - -void lcd_drv_backlight(int on) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->backlight > 0) - driver->backlight(on); - else if((int)driver->backlight == -1) - { - drv_base->backlight(on); - } - } - } while(LL_Next(list) == 0); -} - -void lcd_drv_init_vbar() -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->init_vbar > 0) - driver->init_vbar(); - else if((int)driver->init_vbar == -1) - { - drv_base->init_vbar(); - } - } - } while(LL_Next(list) == 0); -} - -void lcd_drv_init_hbar() -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->init_hbar > 0) - driver->init_hbar(); - else if((int)driver->init_hbar == -1) - { - drv_base->init_hbar(); - } - } - } while(LL_Next(list) == 0); -} - -void lcd_drv_init_num() -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->init_num > 0) - driver->init_num(); - else if((int)driver->init_num == -1) - { - drv_base->init_num(); - } - } - } while(LL_Next(list) == 0); -} - -void lcd_drv_num(int x, int num) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->num > 0) - driver->num(x,num); - else if((int)driver->num == -1) - { - drv_base->num(x,num); - } - } - } while(LL_Next(list) == 0); -} - -void lcd_drv_set_char(int n, char *dat) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->set_char > 0) - driver->set_char(n,dat); - else if((int)driver->set_char == -1) - { - drv_base->set_char(n,dat); - } - } - } while(LL_Next(list) == 0); -} - -void lcd_drv_vbar(int x, int len) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->vbar > 0) - driver->vbar(x,len); - else if((int)driver->vbar == -1) - { - drv_base->vbar(x,len); - } - } - } while(LL_Next(list) == 0); -} - -void lcd_drv_hbar(int x, int y, int len) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->hbar > 0) - driver->hbar(x,y,len); - else if((int)driver->hbar == -1) - { - drv_base->hbar(x,y,len); - } - } - } while(LL_Next(list) == 0); -} - - -void lcd_drv_icon(int which, char dest) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->icon > 0) - driver->icon(which,dest); - else if((int)driver->icon == -1) - { - drv_base->icon(which,dest); - } - } - } while(LL_Next(list) == 0); -} - - -void lcd_drv_flush_box(int lft, int top, int rgt, int bot) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->flush_box > 0) - driver->flush_box(lft,top,rgt,bot); - else if((int)driver->flush_box == -1) - { - drv_base->flush_box(lft,top,rgt,bot); - } - } - } while(LL_Next(list) == 0); - -} - - -// TODO: Check whether lcd.draw_frame() should really take a framebuffer -// TODO: as an argument, or if it should always use lcd.framebuf -void lcd_drv_draw_frame(char *dat) -{ - lcd_logical_driver *driver; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->draw_frame > 0) - driver->draw_frame(dat); - else if((int)driver->draw_frame == -1) - { - drv_base->draw_frame(dat); - } - } - } while(LL_Next(list) == 0); - -} - - -char lcd_drv_getkey() -{ - lcd_logical_driver *driver; - - char key; - - LL_Rewind(list); - do { - driver = (lcd_logical_driver *)LL_Get(list); - if(driver) - { - lcd.framebuf = driver->framebuf; - - if(driver->getkey > 0) - { - key = driver->getkey(); - if(key) return key; - } - else if((int)driver->getkey == -1) - { - key = drv_base->getkey(); - if(key) return key; - } - } - } while(LL_Next(list) == 0); - - return 0; -} diff --git a/tests/menutest.c b/tests/menutest.c deleted file mode 100644 index eb5fd56..0000000 --- a/tests/menutest.c +++ /dev/null @@ -1,88 +0,0 @@ -#include "lcd.h" -#include "menu.h" - - - -extern menu_item MainMenu[]; -extern menu_item OptionsMenu[]; -extern int Shutdown_func(); -extern int Close_func(); -extern int OK_func(); -extern int Time24_func(); -extern int Contrast_func(); - - -menu_item MainMenu[] = { - "MAIN MENU", 0, 0, // Title - "Options", TYPE_MENU, (void *)OptionsMenu, - "Kill LCDproc", TYPE_FUNC, (void *)Shutdown_func, - "OK", TYPE_FUNC, (void *)OK_func, - 0, 0, 0, - -}; - -menu_item OptionsMenu[] = { - "OPTIONS MENU", TYPE_TITL, 0, // Title - "24-hour Time", TYPE_CHEK, (void *)Time24_func, - "Contrast...", TYPE_SLID, (void *)Contrast_func, - "OK", TYPE_FUNC, (void *)OK_func, - "Close Menu", TYPE_FUNC, (void *)Close_func, - "Exit Program", TYPE_FUNC, (void *)Shutdown_func, - "Another Title",TYPE_TITL, 0, - 0, 0, 0, -}; - - -///////////////// Elsewhere, we declare these... - -int Shutdown_func() -{ - // Do something here... - return MENU_KILL; -} - -int Close_func() -{ - return MENU_CLOSE; -} - -int OK_func() -{ - return MENU_OK; -} - - -int Time24_func(int input) -{ - static int status=0; - - if(input == MENU_READ) return status; - if(input == MENU_CHECK) status ^= 1; // does something. - return (status | MENU_OK); - // The status is "or"-ed with the MENU value to let do_menu() - // know what to do after selecting the item. (two return - // values in one. :) - - // Also, "MENU_OK" happens to be zero, so it does not matter - // unless you want something else (like MENU_CLOSE) -} - -int Contrast_func(int input) -{ - static int status=128; - - - if(input == MENU_READ) return status; - if(input == MENU_PLUS) status++; // does something. - if(input == MENU_MINUS) status--; // does something. - return (status | MENU_OK); -} - - -void main() -{ - lcd_init("", "curses"); - - do_menu(MainMenu); - -} diff --git a/tests/script b/tests/script deleted file mode 100644 index a5acd05..0000000 --- a/tests/script +++ /dev/null @@ -1,20 +0,0 @@ -hello -screen_add_widget one w1 string -screen_add one -screen_add two -screen_add_widget one w1 string -screen_add_widget one w2 vbar -screen_add_widget two w1 hbar -screen_add_widget two w2 scroller -screen_del two -screen_add two -screen_del_widget w1 -screen_del_widget two w1 -screen_del_widget one w2 -screen_add_widget two w1 icon -screen_add_widget two w2 title -screen_add three -screen_add_widget three w1 string -screen_add_widget three w2 hbar -screen_add_widget one w2 string -screen_add_widget one w2 hbar diff --git a/tests/script.1 b/tests/script.1 deleted file mode 100644 index 8f97131..0000000 --- a/tests/script.1 +++ /dev/null @@ -1,23 +0,0 @@ -hello - -screen_add one -screen_widget_add one w1 string -screen_widget_set one w1 1 2 "Hello?" -screen_widget_add one title title -screen_widget_set one title "TEST SCREEN ONE" - -screen_add two -screen_widget_add two title title -screen_widget_add two 0% string -screen_widget_add two 100% string -screen_widget_add two cpubar hbar -screen_widget_set two title "CPU: 57.6%" -screen_widget_set two 0% 1 4 0% -screen_widget_set two 100% 17 4 100% -screen_widget_set two cpubar 3 4 47 - -screen_add three -screen_widget_add three w1 string -screen_widget_set three w1 1 3 "Me too!" -screen_widget_add three title title -screen_widget_set three title "TEST THREE" diff --git a/tests/script.2 b/tests/script.2 deleted file mode 100644 index b516534..0000000 --- a/tests/script.2 +++ /dev/null @@ -1,11 +0,0 @@ -hello -screen_add one -screen_widget_add one w1 string -screen_widget_set one w1 7 2 CENTER -screen_widget_add one w2 string -screen_widget_set one w2 7 3 CENTER -screen_widget_add one title string -screen_widget_set one title 1 1 "## BOOGER! ##########" -screen_widget_set one title 1 1 "## BOOGER! #########" -screen_widget_set one w1 8 2 CENTER -screen_widget_set one w2 8 3 CENTER diff --git a/tests/script.3 b/tests/script.3 deleted file mode 100644 index f5a212a..0000000 --- a/tests/script.3 +++ /dev/null @@ -1,21 +0,0 @@ -hello -screen_add one -screen_add two -screen_add three -screen_add four -widget_add one title title -widget_add two title title -widget_add three title title -widget_add four title title -widget_set one title "One" -widget_set two title "Two" -widget_set three title "Three" -widget_set four title "Four" -widget_add one dot string -widget_add two dot string -widget_add three dot string -widget_add four dot string -widget_set one dot 1 2 . -widget_set two dot 2 2 . -widget_set three dot 3 2 . -widget_set four dot 4 2 . diff --git a/tests/socktest.c b/tests/socktest.c deleted file mode 100644 index d7176dd..0000000 --- a/tests/socktest.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include - -#define LCDPORT 13667 - -#include "../shared/sockets.h" - - -int main() -{ - char string[1024]; - char string2[1024]; - int sock; - int err; - - memset(string, 0, 1024); - - fcntl(stdin, F_SETFL, O_NONBLOCK); - - sock = sock_connect("localhost", LCDPORT); - - if(sock <= 0) - { - printf("Error opening socket.\n"); - return 1; - } - - - while(string[0] != 'q') - { - do { - err = sock_recv(sock, string2, 1024); - if (err > 0) printf("Received message: %s\n", string2); - } while(err > 0); - printf("Enter a string to send:\n\t"); - gets(string); - sock_send_string(sock, string); - } - sock_close(sock); - - return 0; -} diff --git a/tests/srvtest.c b/tests/srvtest.c deleted file mode 100644 index f0fd699..0000000 --- a/tests/srvtest.c +++ /dev/null @@ -1,144 +0,0 @@ -#include -#include -#include -#include -#include - -// For debugging purposes... -// ... should not be defined in a release. -// (defaults to 13666) -//#define LCDPORT 13667 - -#include "../server/drivers/lcd.h" -#include "../server/sock.h" -#include "../server/clients.h" -#include "../server/screenlist.h" -#include "../server/screen.h" -#include "../server/parse.h" -#include "../server/render.h" -#include "../server/serverscreens.h" - - -void exit_program(int val); - - -int main() -{ - char string[1024]; - int sock; - screen *s; - int timer=0; - - - - // Ctrl-C will cause a clean exit... - signal(SIGINT, exit_program); - // and "kill"... - signal(SIGTERM, exit_program); - // and "kill -HUP" (hangup)... - signal(SIGHUP, exit_program); - // and just in case, "kill -KILL" (which cannot be trapped; but oh well) - signal(SIGKILL, exit_program); - - - memset(string, 0, 1024); - - lcd_init(""); - - // Feel free to add as many drivers as you like... :) - //lcd_add_driver("joy", ""); - //lcd_add_driver("curses", "Booger"); - lcd_add_driver("MtxOrb", ""); - - - - sock = sock_create_server(); - - if(sock <= 0) - { - printf("Error opening socket.\n"); - return 1; - } - - if(client_init() < 0) - { - printf("Error initializing client list\n"); - return 1; - } - - if(screenlist_init() < 0) - { - printf("Error initializing screen list\n"); - return 1; - } - - // Make sure the server screen shows up every once in a while.. - server_screen_init(); - - // Main loop... - while(1) - { - sock_poll_clients(); - parse_all_client_messages(); - // TODO: Check for and handle keypresses here... - //handle_input(); - - timer++; - if(timer >= 32) - { - timer = 0; - // TODO: Notify clients of "listen" and "ignore" - s = screenlist_next(); - if(s) - { - printf("Screen: %s\n", s->id); - } - } - draw_server_screen(timer); - s = screenlist_current(); - if(s) - { - // render something here... - draw_screen(s, timer); - } - else - { - no_screen_screen(timer); - } - - usleep(125000); - } - - // Say goodbye! - goodbye_screen(); - - // Can go anywhere... - lcd_shutdown(); - // Must come before screenlist_shutdown - client_shutdown(); - // Must come after client_shutdown - screenlist_shutdown(); - // Should come after client_shutdown - sock_close_all(); - - return 0; -} - - -void exit_program(int val) -{ - // Say goodbye! - goodbye_screen(); - - // Can go anywhere... - lcd_shutdown(); - // Must come before screenlist_shutdown - client_shutdown(); - // Must come after client_shutdown - screenlist_shutdown(); - // Should come after client_shutdown - sock_close_all(); - - exit(0); - -} diff --git a/tests/test b/tests/test deleted file mode 100644 index 3b760a2..0000000 --- a/tests/test +++ /dev/null @@ -1,75 +0,0 @@ -hello - -screen_add one - -widget_add one f frame -widget_set one f 1 2 10 3 20 4 v 2 -widget_add one g frame -in f -widget_set one g 5 1 15 3 20 4 v 2 - -widget_add one s string -widget_add one s string -in f -widget_add one s string -in g -widget_set one s 1 1 "123456789012345678901234567890" -widget_set one s 1 2 "123456789012345678901234567890" -widget_set one s 1 3 "123456789012345678901234567890" -widget_set one s 1 4 "123456789012345678901234567890" -widget_del one s - -widget_add one h hbar -widget_add one h hbar -in f -widget_add one h hbar -in g -widget_set one h 1 2 13 -widget_set one h 1 2 43 -widget_set one h 1 2 83 -widget_del one h - -widget_add one t title -widget_add one t title -in f -widget_add one t title -in g -widget_set one t Hello -widget_set one t "Hello there" -widget_set one t "Hi, there. Watch me scroll!" -widget_del one t - - ------------------------- Disk Screen test... -hello -screen_add D -widget_add D t title -widget_set D t "Disk Use" -widget_add D f frame -widget_set D f 1 2 20 4 20 8 v 8 -widget_add D s1 string -in f -widget_add D s2 string -in f -widget_add D s3 string -in f -widget_add D s4 string -in f -widget_add D s5 string -in f -widget_add D s6 string -in f -widget_add D s7 string -in f -widget_add D s8 string -in f -widget_add D h1 hbar -in f -widget_add D h2 hbar -in f -widget_add D h3 hbar -in f -widget_add D h4 hbar -in f -widget_add D h5 hbar -in f -widget_add D h6 hbar -in f -widget_add D h7 hbar -in f -widget_add D h8 hbar -in f -widget_set D s1 1 1 /foo -widget_set D s2 1 2 /bar -widget_set D s3 1 3 /baz -widget_set D s4 1 4 /quux -widget_set D s5 1 5 /foobar -widget_set D s6 1 6 /tmp -widget_set D s7 1 7 /snot -widget_set D s8 1 8 /booger -widget_set D h1 10 1 3 -widget_set D h2 10 2 6 -widget_set D h3 10 3 9 -widget_set D h4 10 4 12 -widget_set D h5 10 5 15 -widget_set D h6 10 6 18 -widget_set D h7 10 7 21 -widget_set D h8 10 8 24 ----------------------------