void rm (char *name ) { int no_entries; word dirsize; Stream *s; int isdir; Object *o = Locate(CurrentDir,name); if( o == Null(Object) ) { fprintf(stderr,"Cannot find %s : %lx\n",name, Result2(CurrentDir)); errors++; return; } isdir = (int)(o->Type & Type_Directory); if (!isdir) { fprintf(stderr,"%s: %s is not a directory\n", progname, name); errors++; return; } Close (o); del(name); while ( pflag && ( strcmp ( ( name = dirname (name) ) , "." ) != 0 ) ) { o = Locate(CurrentDir,name); if( o == Null(Object) ) { fprintf(stderr,"Cannot find %s : %lx\n",name, Result2(CurrentDir)); errors++; return; } s = Open(o,NULL,O_ReadOnly); if( s == Null(Stream) ) { fprintf(stderr,"Cannot open %s : %lx\n",name,Result2(o)); errors++; return; } dirsize = GetFileSize(s); Close(s); Close(o); no_entries = (int)dirsize/sizeof(DirEntry); if (no_entries == 2) del (name); /* Having only two entries namely . and .. the directory 'name' will be deleted */ /* without complaint from 'delete'. */ } return; }
/* * The Reader process simply waits for a request to arrive and then * reads a message from the /ether server. * It calls the Action routine, so the stack size here must be adequate * for the tcpip server to do its packet arrival processing. */ static void Reader( NetDCB * dcb ) { word got; NetDevReq * req; for (;;) { /* wait for a request from server */ Wait( &dcb->nreq ); /* remove it from list. Note that we must lock the DCB */ /* before doing this. */ Wait( &dcb->lock ); req = (NetDevReq *)RemHead( &dcb->readq ); Signal( &dcb->lock ); if (req == NULL) continue; /* Read until we get some data, we hope that it will */ /* be a complete ether packet. */ again: got = Read( dcb->read, (char *) req->Buf, req->Size, -1 ); if (got <= 0) { #ifdef DEBUG IOdebug( "Reader: Read failed, return code = %d, Result2 = %x", got, Result2( dcb->read ) ); #endif goto again; } #ifdef DEBUG { int i; char * buf = (char *)req->Buf; IOdebug( "RX %d [%", got ); for (i = 0;i < 24; i++) IOdebug( "%x %", buf[ i ] ); IOdebug( "]" ); } #endif req->Actual = got; req->DevReq.Result = 0; /* Return request to server. */ (*req->DevReq.Action)( dcb, req ); } return; } /* Reader */
/** *** This routine would be called, typically, when walking down the directory *** of current sessions. Every entry is Locate()'ed and this routine is *** used on the resulting object. It gives a Stream for the login window. *** Programs like write and wall are implemented using this. **/ Stream *RmGetWindow(Object *Session, WORD *error) { Stream *SessionStream = Null(Stream); int size; BYTE *buffer = Null(BYTE); Stream *result = Null(Stream); Object *TargetWindow = Null(Object); WORD junk; if (error eq Null(WORD)) error = &junk; if (Session eq Null(Object)) { *error = EC_Error + EG_Invalid + EO_Session; return(Null(Stream)); } if (Session->Type ne Type_Session) { *error = EC_Error + EG_Invalid + EO_Session; return(Null(Stream)); } SessionStream = Open(Session, Null(char), O_ReadOnly); if (SessionStream eq Null(Stream)) { *error = Result2(Session); return(Null(Stream)); } size = (int) GetFileSize(SessionStream); if ( (size <= 0) || (size > IOCDataMax + sizeof(Capability))) { *error = EC_Error + EG_WrongSize + EO_Stream; goto done; } buffer = (BYTE *) Malloc(size); if (buffer eq Null(BYTE)) { *error = EC_Error + EG_NoMemory + EO_Message; goto done; } if (Read(SessionStream, buffer, size, -1) ne size) { *error = EC_Error + EG_Broken + EO_Stream; goto done; } TargetWindow = NewObject(&(buffer[sizeof(Capability)]), (Capability *) buffer); if (TargetWindow eq Null(Object)) { *error = EC_Error + EG_Unknown + EO_Window; goto done; } result = Open(TargetWindow, Null(char), O_ReadOnly); if (result eq Null(Stream)) *error = Result2(TargetWindow); done: if (buffer ne Null(BYTE)) Free(buffer); if (TargetWindow ne Null(Object)) Close(TargetWindow); if (SessionStream ne Null(Stream)) Close(SessionStream); return(result); }
void SMatrix::addNode(int count){ std::complex<double> Result1((2.0-(double)count)/(double)count,0.0); std::complex<double> Result2(2.0/(double)count,0.0); std::complex<double> *Destination; for (int i=0; i<count; i++) { for (int j=0; j<count; j++) { Destination=SMatrix_+MatrixDimension_*Pos_+Pos_+MatrixDimension_*i+j; if (i==j) { *Destination=Result1; } else { *Destination=Result2; } } } Pos_ += count; }
int main(int argc, char **argv) { char dcname[40]; if( argc < 2 ) { printf("usage: %s objects...\n",argv[0]); exit(1); } argv++; for( ; *argv != NULL; argv++ ) { char *name = *argv; char *s; ObjInfo info; char *type; char tt[20]; if( ObjectInfo(CurrentDir,name,(byte *)&info) != 0 ) { fprintf(stderr,"could not locate %s : %x\n",name,Result2(CurrentDir)); continue; } switch( info.DirEntry.Type ) { case Type_Directory: type = "d"; break; case Type_File: type = "f"; break; case Type_Link: type = "l"; break; default: type = tt; sprintf(tt,"%x",info.DirEntry.Type); break; } DecodeMatrix(dcname,info.DirEntry.Matrix,info.DirEntry.Type); printf("%s %s %s\n",type,dcname,info.DirEntry.Name); } return 0; }
void GetEngGrpMonUni(bool fDouble) { if ((bInBuff6 != 0) || (bInBuff8 != 0) || (bInBuffA != 0)) Result2(bUNI_BADDATA); else if (bInBuff7 > bGROUPS) Result2(bUNI_BADDATA); else if (bInBuff7+bInBuff9-1 > bGROUPS) Result2(bUNI_BADDATA); else if (bInBuffB >= bMONTHS) Result2(bUNI_BADDATA); else if (bInBuffC > bTARIFFS) Result2(bUNI_BADDATA); else if (bInBuffC+bInBuffD-1 > bTARIFFS) Result2(bUNI_BADDATA); else { InitPushUni(); LoadImpMon((bMONTHS+ibHardMon-bInBuffB) % bMONTHS); uint wSize = 0; uchar g; for (g=bInBuff7; g<bInBuff7+bInBuff9; g++) { uchar i; for (i=bInBuffC; i<bInBuffC+bInBuffD; i++) { if (fDouble) { PushDouble(GetGrpImp2DoubleEng(mpimMonCan[ PrevSoftMon() ], g-1, 0x01 << (i-1))); wSize += sizeof(double); } else { PushFloat(GetGrpImp2FloatEng(mpimMonCan[ PrevSoftMon() ], g-1, 0x01 << (i-1))); wSize += sizeof(float); } } } ulong dw = DateToMonIndex(*GetCurrTimeDate()); dw -= bInBuffB; time ti = MonIndexToDate(dw); Output2_Code(wSize, ((CheckDefGrpMonUni(ti.bMonth) == 0) ? bUNI_OK : bUNI_DEFECT), ti); } }
void GetEngCanDayUni(bool fDouble) { if ((bInBuff6 != 0) || (bInBuff8 != 0) || (bInBuffA != 0)) Result2(bUNI_BADDATA); else if (bInBuff7 > bCANALS) Result2(bUNI_BADDATA); else if (bInBuff7+bInBuff9-1 > bCANALS) Result2(bUNI_BADDATA); else if (bInBuffB >= bDAYS) Result2(bUNI_BADDATA); else if (bInBuffC > bTARIFFS) Result2(bUNI_BADDATA); else if (bInBuffC+bInBuffD-1 > bTARIFFS) Result2(bUNI_BADDATA); else { InitPushUni(); LoadImpDay((bDAYS+ibHardDay-bInBuffB) % bDAYS); uint wSize = 0; uchar c; for (c=bInBuff7; c<bInBuff7+bInBuff9; c++) { uchar i; for (i=bInBuffC; i<bInBuffC+bInBuffD; i++) { if (fDouble) { PushDouble(GetCanImp2DoubleEng(mpimDayCan[ PrevSoftDay() ], c-1, 0x01 << (i-1))); wSize += sizeof(double); } else { PushFloat(GetCanImp2FloatEng(mpimDayCan[ PrevSoftDay() ], c-1, 0x01 << (i-1))); wSize += sizeof(float); } } } ulong dw = DateToDayIndex(*GetCurrTimeDate()); dw -= bInBuffB; time ti = DayIndexToDate(dw); Output2_Code(wSize, ((CheckDefCanDayUni() == 0) ? bUNI_OK : bUNI_DEFECT), ti); } }
void GetMaxGrpMonUni(void) { if ((bInBuff6 != 0) || (bInBuff8 != 0) || (bInBuffA != 0)) Result2(bUNI_BADDATA); else if (bInBuff7 > bGROUPS) Result2(bUNI_BADDATA); else if (bInBuff7+bInBuff9-1 > bGROUPS) Result2(bUNI_BADDATA); else if (bInBuffB >= bMONTHS) Result2(bUNI_BADDATA); else if (bInBuffC > bTARIFFS) Result2(bUNI_BADDATA); else if (bInBuffC+bInBuffD-1 > bTARIFFS) Result2(bUNI_BADDATA); else { InitPushUni(); LoadPowMon((bMONTHS+ibHardMon-bInBuffB) % bMONTHS); uchar ibGrp; for (ibGrp=bInBuff7; ibGrp<bInBuff7+bInBuff9; ibGrp++) { uchar i; for (i=bInBuffC; i<bInBuffC+bInBuffD; i++) { PushFloat(GetGrpMaxPowReal(mppoMonGrp[ PrevSoftMon() ], ibGrp-1, i-1)); time ti1 = GetGrpMaxPowTime(mppoMonGrp[ PrevSoftMon() ], ibGrp-1, i-1); PushChar(ti1.bDay); PushChar(ti1.bHour*2 + ti1.bMinute/30); } } ulong dw = DateToMonIndex(*GetCurrTimeDate()); dw -= bInBuffB; time ti2 = MonIndexToDate(dw); Output2_Code((uint)6*bInBuff9*bInBuffD, ((CheckDefGrpMonUni(ti2.bMonth) == 0) ? bUNI_OK : bUNI_DEFECT), ti2); } }
int main(int argc, char **argv) { char dcname[40]; AccMask setmask = 0; AccMask clearmask = 0; char *s; PrgName = argv [0]; if( argc < (1 + 1)) { printf("Usage: %s [[-+=][rwefghvxyzda]] <Objects>\n", PrgName); exit(1); } argv++; s = *argv; if( *s == '+' || *s == '-' || *s == '=' ) { AccMask *mask = &setmask; if( *s == '-' ) mask = &clearmask; elif( *s == '=' ) clearmask = 0xff; s++; while( *s != '\0' ) { int bit = getbit(*s,FileChars); if( bit == 0 ) bit = getbit(*s,DirChars); if( bit == 0 ) printf("invalid bit character %c\n",*s); *mask |= bit; s++; } argv++; } for( ; *argv != NULL; argv++ ) { char *name = *argv; Object *o; word e; o = Locate(CurrentDir,name); if( o == NULL ) { fprintf(stderr,"could not locate %s : %x\n",name,Result2(CurrentDir)); continue; } if( clearmask || setmask ) { AccMask mask = o->Access.Access; mask &= ~clearmask; mask |= setmask; e = Refine(o,mask); if( e < 0 ) fprintf(stderr,"refine of %s failed: %x\n",name,e); } DecodeCapability(dcname,&o->Access); printf("%s%s\n",dcname,o->Name); } return 0; }
void rm( char * name ) { DirEntry * b; DirEntry * m; word no_entries; word i; word size; word dirsize; Stream * s; char rname[ 128 ]; word isdir; word islink; Dinfo obinfo; Object * o = Locate( CurrentDir, name ); if ( ObjectInfo(CurrentDir,name,obinfo.buff) != 0) { if (!fflag) fprintf(stderr,"Cannot find %s : %lx\n",name, Result2(CurrentDir)); errors++; return; } islink = obinfo.DirEntry.Type & Type_Link; isdir = o->Type & Type_Directory; if (iflag) { fprintf(stderr,"rm: delete %s %s? ", (isdir ? "directory" : "file"), name); fflush(stderr); if (!confirm ()) return; } /* If a simple file or directory, delete it */ if ( islink || !(isdir && rflag)) { del(name); return; } /* More complicated case - scan a directory */ s = Open(o,NULL,O_ReadOnly); if ( s == Null(Stream) ) { fprintf(stderr,"Cannot open %s : %lx\n",name,Result2(o)); errors++; return; } dirsize = GetFileSize(s); no_entries = dirsize/sizeof(DirEntry); if (no_entries > 0) { m = b = (DirEntry *) Malloc(dirsize); if (b == Null(DirEntry)) { fprintf(stderr,"rm: Out of memory\n"); exit(1); } size = Read(s,(char *)b,dirsize,-1); if ( size != dirsize) { fprintf(stderr,"Read failure %lx\n",Result2(s)); errors++; return; } for ( i = 0 ; i < no_entries; i++ ) { if (strcmp ("..", m->Name) && strcmp (".", m->Name)) { strcpy (rname, name); strcat (rname, "/"); strcat (rname, m->Name); rm (rname); } m++; } Free(b); } Close(s); Close(o); del (name); return; } /* rm */
int main(void) { Object *root_obj = Locate(NULL, "/"); Object *mouse_obj; Object *keyboard_obj; Attributes attr; WORD result; setvbuf(stdin, NULL, _IONBF, 0); if ((result = GetAttributes(Heliosno(stdin), &attr)) < 0) { printf("Failed to get stdin attributes : %x. Exiting.\n", result); exit(result); } AddAttribute(&attr, ConsoleRawOutput); AddAttribute(&attr, ConsoleRawInput); RemoveAttribute(&attr, ConsolePause); RemoveAttribute(&attr, ConsoleEcho); if ((result = SetAttributes(Heliosno(stdin), &attr)) < 0) { printf("Failed to set stdin attributes : %x. Exiting.\n", result); exit(result); } printf("\f\t\tX Support Test\r\n"); printf( "\t\t==============\r\n\n\n"); mouse_obj = Locate(root_obj, "/mouse"); if (mouse_obj eq Null(Object)) { printf("Failed to find a mouse device : %x.\r\n", Result2(root_obj)); exit(Result2(root_obj)); } printf("Found a mouse server : %s.\r\n", mouse_obj->Name); mouse_stream = Open(mouse_obj, NULL, O_ReadOnly); if (mouse_stream eq Null(Stream)) { printf("Failed to open stream : %x.\n", Result2(mouse_obj)); exit(Result2(mouse_obj)); } Close(mouse_obj); keyboard_obj = Locate(root_obj, "/keyboard"); if (keyboard_obj eq Null(Object)) { printf("Failed to find a keyboard device : %x.\r\n", Result2(root_obj)); exit(Result2(root_obj)); } printf("Found a keyboard server : %s.\r\n", keyboard_obj->Name); keyboard_stream = Open(keyboard_obj, NULL, O_ReadOnly); if (keyboard_stream eq Null(Stream)) { printf("Failed to open stream : %x.\n", Result2(keyboard_obj)); exit(Result2(keyboard_obj)); } Close(keyboard_obj); Close(root_obj); wait_for_user(); main_menu(); Close(mouse_stream); Close(keyboard_stream); printf("\r\n\n\n"); return(0); }
static void DevOperate( NetDCB * dcb, NetDevReq * req ) { NetInfoReq * ireq = (NetInfoReq *)req; NetInfo * info = &ireq->NetInfo; switch (req->DevReq.Request) { case FG_Read: /* Queue read requests for Reader process. The server */ /* currently sends us several of these when it starts. */ /* Note that we must lock the DCB against concurrent */ /* access. */ Wait( &dcb->lock ); AddTail( &dcb->readq, &req->DevReq.Node ); Signal( &dcb->nreq ); Signal( &dcb->lock ); return; case FG_Write: #ifdef DEBUG { int i; char * buf = (char *)req->Buf; IOdebug( "TX %d buf = %x [%", req->Size, buf ); for (i = 0;i < 24; i++) IOdebug( "%x %", buf[ i ] ); IOdebug( "]" ); } #endif /* Write data to /ether server inline */ req->Actual = Write( dcb->write, (char *) req->Buf, req->Size, -1 ); req->DevReq.Result = Result2( dcb->write ); break; case FG_SetInfo: #ifdef DEBUG IOdebug( "Net SetInfo %x %x %x [%", info->Mask, info->Mode, info->State ); { int i; for (i = 0; i < 5; i++ ) IOdebug( "%d.%", info->Addr[ i ] ); IOdebug( "%d]", info->Addr[ 5 ] ); } #endif /* Set options/address in ethernet device */ /* The tcpip server will attempt to set the ethernet */ /* address on startup. */ /* SetInfo does nothing in this driver. */ /* req->DevReq.Result = SetInfo(dcb->write,info,sizeof(NetInfo)); */ req->DevReq.Result = 0; break; case FG_GetInfo: /* Get options/address from /ether device. Only the */ /* ethernet address is used by tcpip server. */ info->Mask = 7; req->DevReq.Result = GetInfo( dcb->read, (byte *)info ); #ifdef DEBUG { int i; IOdebug( "Addr [%" ); for (i = 0; i < 6; i++ ) IOdebug( "%d %", info->Addr[ i ] ); IOdebug( "]" ); } #endif break; } #if 0 /* Unlock the DCB before returning request to server */ Signal( &dcb->lock ); #endif /* return request to server by calling the Action routine in */ /* the request. Note that the tcpip server will re-call */ /* DevOperate before returning from this routine when the */ /* request was a Read. */ (*req->DevReq.Action)( dcb, req ); return; } /* DevOperate */