//N address of the TRUE root struct TREE_NODE* SEARCH(struct TREE_NODE *N, int K) { if(N->K == K) return N; if(N == NULL) return NULL; struct TREE_NODE *X = SEARCH(N->L,K); struct TREE_NODE *Y = SEARCH(N->R,K); if(X != NULL) return X; if(Y != NULL) return Y; }
int main() { int *a; int i; a = (int *) malloc(sizeof(int) * N_ELEMENTS); a[0] = 0; for (i = 1; i < N_ELEMENTS; i++) { if (rand() % 2) a[i] = a[i - 1]; else a[i] = a[i - 1] + 3; } #if 0 for (i = 0; i < 10000; i++) { int r1, r2, r3; printf("s%d\n", i); r1 = sequential_search(i, a, N_ELEMENTS); printf("b%d\n", i); r2 = binary_search(i, a, N_ELEMENTS); printf("t%d\n", i); r3 = ternary_search(i, a, N_ELEMENTS); if (r1 != -1 && a[r1] != i) { printf("error!"); exit(0); } if (r2 != -1 && a[r2] != i) { printf("error!"); exit(0); } if (r3 != -1 && a[r3] != i) { printf("error!"); exit(0); } } #endif START_TIME; printf("%d\n", SEARCH(120000000, a, N_ELEMENTS)); printf("%d\n", SEARCH(1000, a, N_ELEMENTS)); printf("%d\n", SEARCH(0, a, N_ELEMENTS)); printf("%d\n", SEARCH(3, a, 1)); printf("%d\n", SEARCH(6, a, 2)); printf("%d\n", SEARCH(9, a, 4)); printf("%d\n", SEARCH(9, a, 20)); END_TIME; return 0; }
main() { LIST L, p, p2; char ans, element; MAKENULL(&L); do { clrscr(); printf("\n MENU\n"); printf("[1] Insert\n"); printf("[2] Delete\n"); printf("[3] Display\n"); printf("[4] Search\n"); printf("[5] Quit\n\n"); printf("Enter chosen number: "); ans = toupper(getche()); switch (ans) { case '1': /* case 1 has an approximated running time of 3n + 12 */ printf("\n\nEnter an element to insert: "); element = getche(); p = INS_POS(element, L); INSERT(element, p); break; case '2' : /* case 2 has an approximated running time of 8n + 10 */ printf("\n\nEnter element to delete: "); element = getche(); p = LOCATE(element,L); DELETE(element, p); break; case '3' : /* case 3 has an approximated running time of 3n + 4 */ printf("\n\n"); PRINTLIST(L); break; case '4' : /* case 4 has an approximated running time of 4n + 14 */ printf("\n\nEnter element to search: "); element = getch(); p = LOCATE(element,L); SEARCH(element, p); break; case '5' : break; } } while (ans != '5'); DELETEALL(p); /* DELETEALL has an approximated runnning time of 4n + 1 */ }
void TREE_ARAMA_KERNEL::SLOT_SEARCH_BUTTON() { run_search_button->setDisabled(true); if ( CHECK_VAR_CONTROL() EQ false ) { run_search_button->setDisabled(false); return; } if ( CHECK_EMPTY() EQ ADAK_FAIL ) { run_search_button->setDisabled ( false ); return; } SEARCH(); run_search_button->setDisabled ( false ); }
static int vms_file_stats_name (const char *dirname, const char *filename, long long *cdt, long *siz, char *rfo, int *ver) { char fullname[strlen (dirname) + strlen (filename) + 1]; #ifdef VMS struct FAB fab; struct NAM nam; unsigned long long create; FAT recattr; char ascnamebuff [256]; ATRDEF atrlst[] = { { ATR$S_CREDATE, ATR$C_CREDATE, &create }, { ATR$S_RECATTR, ATR$C_RECATTR, &recattr }, { ATR$S_ASCNAME, ATR$C_ASCNAME, &ascnamebuff }, { 0, 0, 0} }; FIBDEF fib; struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib}; struct IOSB iosb; long status; unsigned short chan; struct vstring file; struct dsc$descriptor_s filedsc = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string}; struct vstring device; struct dsc$descriptor_s devicedsc = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string}; struct vstring result; struct dsc$descriptor_s resultdsc = {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string}; if (strcmp (filename, "<internal>") == 0 || strcmp (filename, "<built-in>") == 0) { if (cdt) *cdt = 0; if (siz) *siz = 0; if (rfo) *rfo = 0; if (ver) *ver = 0; return 0; } strcpy (fullname, dirname); strcat (fullname, filename); tryfile = to_vms_file_spec (fullname); /* Allocate and initialize a FAB and NAM structures. */ fab = cc$rms_fab; nam = cc$rms_nam; nam.nam$l_esa = file.string; nam.nam$b_ess = NAM$C_MAXRSS; nam.nam$l_rsa = result.string; nam.nam$b_rss = NAM$C_MAXRSS; fab.fab$l_fna = tryfile; fab.fab$b_fns = strlen (tryfile); fab.fab$l_nam = &nam; /* Validate filespec syntax and device existence. */ status = SYS$PARSE (&fab, 0, 0); if ((status & 1) != 1) return 1; file.string[nam.nam$b_esl] = 0; /* Find matching filespec. */ status = SYS$SEARCH (&fab, 0, 0); if ((status & 1) != 1) return 1; file.string[nam.nam$b_esl] = 0; result.string[result.length=nam.nam$b_rsl] = 0; /* Get the device name and assign an IO channel. */ strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev); devicedsc.dsc$w_length = nam.nam$b_dev; chan = 0; status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0); if ((status & 1) != 1) return 1; /* Initialize the FIB and fill in the directory id field. */ memset (&fib, 0, sizeof (fib)); fib.fib$w_did[0] = nam.nam$w_did[0]; fib.fib$w_did[1] = nam.nam$w_did[1]; fib.fib$w_did[2] = nam.nam$w_did[2]; fib.fib$l_acctl = 0; fib.fib$l_wcc = 0; strcpy (file.string, (strrchr (result.string, ']') + 1)); filedsc.dsc$w_length = strlen (file.string); result.string[result.length = 0] = 0; /* Open and close the file to fill in the attributes. */ status = SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0, &fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0); if ((status & 1) != 1) return 1; if ((iosb.status & 1) != 1) return 1; result.string[result.length] = 0; status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0, &atrlst, 0); if ((status & 1) != 1) return 1; if ((iosb.status & 1) != 1) return 1; /* Deassign the channel and exit. */ status = SYS$DASSGN (chan); if ((status & 1) != 1) return 1; if (cdt) *cdt = create; if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) + (512 * (recattr.fat$w_efblkl - 1)) + recattr.fat$w_ffbyte; if (rfo) *rfo = recattr.fat$v_rtype; if (ver) *ver = strtol (strrchr (ascnamebuff, ';') + 1, 0, 10); #else /* not VMS */ struct stat buff; struct tm *ts; long long gmtoff, secs, nsecs; strcpy (fullname, dirname); strcat (fullname, filename); if ((stat (fullname, &buff)) != 0) return 1; if (cdt) { ts = localtime (& buff.st_mtime); #ifdef HAVE_TM_GMTOFF gmtoff = ts->tm_gmtoff; #else { extern long timezone; if (ts->tm_isdst == 1) gmtoff = - (timezone - 3600); else gmtoff = - timezone; } #endif #ifdef HAVE_ST_MTIM_TV_SEC secs = buff.st_mtim.tv_sec; #else secs = buff.st_mtime; #endif #ifdef HAVE_ST_MTIM_TV_NSEC nsecs = buff.st_mtim.tv_nsec; #else nsecs = 0; #endif /* VMS timestamps are stored in local time to 100 nsec accuracy, but by experiment I found timestamps truncated to (at least) microseconds on an NFS mounted filesystem, hence the adjustment below. DBR. */ *cdt = ((secs + gmtoff) * VMS_GRANULARITY_FACTOR) + (nsecs / 1000 * 10) + VMS_EPOCH_OFFSET; } if (siz) *siz = buff.st_size; if (rfo) *rfo = 2; /* Stream LF format. */ /* Returning a file version of 0 is never correct for debug info, version 1 will be correct if file editing is done only on the Unix side. If editing is done on the VMS side, then its TBD. */ if (ver) *ver = 1; #endif /* VMS */ return 0; }
bool authcursor::find_cache_key (str key) { SEARCH (ae.type == SFSAUTH_CACHEENTRY && ae.cacheentry->key == key); }
bool authcursor::find_group_gid (u_int32_t id) { SEARCH (ae.type == SFSAUTH_GROUP && ae.groupinfo->id == id); }
bool authcursor::find_group_name (str name) { SEARCH (ae.type == SFSAUTH_GROUP && ae.groupinfo->name == name); }
bool authcursor::find_user_uid (u_int32_t id) { SEARCH (ae.type == SFSAUTH_USER && ae.userinfo->id == id); }
bool authcursor::find_user_pubkey (const sfspub &pk) { SEARCH (ae.type == SFSAUTH_USER && (pk == ae.userinfo->pubkey || pk == ae.userinfo->srvprivkey)); }
bool authcursor::find_user_name (str name) { SEARCH (ae.type == SFSAUTH_USER && ae.userinfo->name == name); }
void rec1_open_file( int expand, const char *file, INT file_len, char mode, INT *slot, int *newslot ) { /*+ */ /* Name: */ /* rec1_open_file */ /* Purpose: */ /* Open an existing file. */ /* Invocation: */ /* rec1_open_file( expand, file, file_len, mode, slot, newslot ) */ /* Description: */ /* This function opens an existing container file for reading or writing */ /* and allocates a new File Control Vector slot (if necessary) to refer */ /* to the file. Any new FCV slot is initialised and its number is */ /* returned. The file's reference count is left unchanged if it is */ /* already in use, or is set to zero if it is being opened for the first */ /* time. */ /* Parameters: */ /* int expand */ /* If expand is non-zero, then the file name supplied will be */ /* regarded as an abbreviated form of the full name of the file and */ /* will be expanded (according to the underlying operating system's */ /* rules) before use. Otherwise, the file name supplied is regarded */ /* as already fully expanded and will be used literally. This */ /* mechanism is provided to allow previously-expanded file names to */ /* be given, while allowing for the fact that expanding a file name */ /* twice may cause the wrong file to be identified (if the underlying */ /* file system has changed and/or the expanded file name contains */ /* special characters, for instance). */ /* const char *file */ /* Pointer to a char array containing the host file-system name of */ /* the container file to be opened. It should not be null terminated. */ /* If expand is non-zero, then leading and trailing white space will */ /* be ignored. If expand is zero, then the file name must be */ /* fully-expanded and white space may be significant. */ /* INT file_len */ /* Number of characters in the file name (excluding any terminating */ /* null, if present). */ /* char mode */ /* A character specifying the required file access mode: 'R' for */ /* read-only access or 'W' for write (or update) access. */ /* INT *slot */ /* Pointer to an integer in which the File Control Vector slot number */ /* allocated to the file will be returned. */ /* int *newslot */ /* Returns 1 if the FCV slot is a new one, otherwise 0 if the slot */ /* was already in use (i.e. the file was already open). */ /* Returned Value: */ /* void */ /* Copyright: */ /* Copyright (C) 1992 Science & Engineering Research Council */ /* Copyright (C) 2005 Particle Physics and Astronomy Research Council */ /* Licence: */ /* This program is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU General Public License as */ /* published by the Free Software Foundation; either version 2 of */ /* the License, or (at your option) any later version. */ /* This program is distributed in the hope that it will be */ /* useful, but WITHOUT ANY WARRANTY; without even the implied */ /* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */ /* PURPOSE. See the GNU General Public License for more details. */ /* You should have received a copy of the GNU General Public */ /* License along with this program; if not, write to the Free */ /* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, */ /* MA 02110-1301, USA */ /* Authors: */ /* RFWS: R.F. Warren-Smith (STARLINK) */ /* TIMJ: Tim Jenness (JAC, Hawaii) */ /* {@enter_new_authors_here@} */ /* History: */ /* 28-MAR-1991 (RFWS): */ /* Added prologue. */ /* 3-APR-1991 (RFWS): */ /* Fixed bug in passing of file name for error message. */ /* 3-MAY-1991 (RFWS): */ /* Re-structured to return an FCV slot number and to initialise the */ /* slot if necessary. */ /* 7-MAY-1991 (RFWS): */ /* Added a portable implementation. */ /* 21-MAY-1991 (RFWS): */ /* Remove trailing blanks from file names (portable version). */ /* 22-MAY-1991 (RFWS): */ /* Added defaulting of ".sdf" file extension in portable version. */ /* 12-JUN-1991 (RFWS): */ /* Fixed bug in testing of access mode. */ /* 28-JUN-1991 (RFWS): */ /* Removed initialisation of the VMS-specific FCV lid field (not */ /* necessary). Added function prototypes for VMS system calls. */ /* 11-SEP-1992 (RFWS): */ /* Do not increment the file reference count. This is now the */ /* caller's responsibility. */ /* 14-OCT-1992 (RFWS): */ /* Changed to a void function and to use separate string pointer and */ /* length arguments. */ /* 24-NOV-1992 (RFWS): */ /* Fixed error in assigning access mode for error message. */ /* 25-NOV-1992 (RFWS): */ /* Changed to extend the File Control Vector when necessary. */ /* 26-NOV-1992 (RFWS): */ /* Enhanced file name handling by using rec1_get_path. */ /* 1-DEC-1992 (RFWS): */ /* Added the expand parameter. */ /* 28-DEC-2005 (TIMJ): */ /* Use DAT__FLEXT rather than hard-coded ".SDF" */ /* 02-FEB-2006 (TIMJ): */ /* Free malloced memory if the slot is reused. */ /* {@enter_further_changes_here@} */ /* Bugs: */ /* {@note_any_bugs_here@} */ /*- */ /* Local Variables: */ #if defined (vms ) /* VMS version local variables: */ char esabuf[ NAM$C_MAXRSS ]; /* Expanded file name string buffer */ char rsabuf[ NAM$C_MAXRSS ]; /* Resultant file name string buffer */ struct FAB fab; /* RMS file access block */ struct NAM nam; /* RMS NAM block */ unsigned int systat; /* System status code */ unsigned short int iochan; /* File I/O channel */ #else /* Portable version local variables: */ FILE *iochan=NULL; /* File I/O stream */ #endif INT i; /* Loop counter for FCV slots */ INT lfns; /* Length of File Name String */ INT start; /* Array offset of first non-blank char */ char *fns; /* Pointer to file name string */ int mustopen=0; /* File must be opened? */ struct FCV *fcv; /* Pointer to File Control Vector element */ struct FID *fid; /* Pointer to File ID */ /* External References: */ #if defined( vms ) /* VMS version system calls: */ unsigned int SYS$OPEN( struct FAB *fab ); unsigned int SYS$PARSE( struct FAB *fab ); unsigned int SYS$SEARCH( struct FAB *fab ); #endif /*. */ /* Check the inherited global status. */ if ( !_ok( hds_gl_status ) ) return; /* Initialise. */ fns = NULL; fid = NULL; /* If necessary, modify the file name length to omit any trailing white */ /* space. */ start = 0; if ( expand ) { for ( ; file_len > 0; file_len-- ) { if ( !isspace( file[ file_len - 1 ] ) ) break; } /* Also strip white space from the start of the file name (but leave at */ /* least one character, even if the string is completely blank). */ for ( start = 0; start < ( file_len - 1 ); start++ ) { if ( !isspace( file[ start ] ) ) break; } } /* VMS version: */ /* =========== */ #if defined( vms ) /* Initialise the file FAB and NAM blocks. */ fab = cc$rms_fab; fab.fab$l_dna = DAT__FLEXT; fab.fab$b_dns = DAT__SZFLX; fab.fab$l_fna = file + start; fab.fab$b_fns = file_len - start; fab.fab$l_nam = &nam; nam = cc$rms_nam; nam.nam$l_esa = esabuf; nam.nam$b_ess = NAM$C_MAXRSS; nam.nam$l_rsa = rsabuf; nam.nam$b_rss = NAM$C_MAXRSS; /* Parse the file name, reporting any errors. */ systat = SYS$PARSE( &fab ); if ( !( systat & STS$M_SUCCESS ) ) { hds_gl_status = ( systat == RMS$_PRV ) ? DAT__FILPR : DAT__FILNF; emsSetnc( "FILE", file + start, file_len - start ); emsSyser( "MESSAGE", systat ); emsRep( "REC1_OPEN_FILE_1", "Error in file name \'^FILE\' - ^MESSAGE.", &hds_gl_status ); } /* Search for the file, again reporting errors. */ if ( _ok( hds_gl_status ) ) { systat = SYS$SEARCH( &fab ); if ( !( systat & STS$M_SUCCESS ) ) { hds_gl_status = ( systat == RMS$_PRV ) ? DAT__FILPR : DAT__FILNF; emsSetnc( "FILE", esabuf, nam.nam$b_esl ); emsSyser( "MESSAGE", systat ); emsRep( "REC1_OPEN_FILE_2", "Error searching for file ^FILE - ^MESSAGE.", &hds_gl_status ); } /* If the file was found successfully, then allocate memory to hold the */ /* File Name String and the File ID and copy the relevant information from */ /* the NAM block into this memory (adding a terminating null to the file */ /* name). */ else { lfns = nam.nam$b_rsl; rec_alloc_mem( lfns + 1, (void **) &fns ); rec_alloc_mem( sizeof( struct FID ), (void **) &fid ); if ( _ok( hds_gl_status ) ) { (void) memcpy( (void *) fns, (const void *) nam.nam$l_rsa, (size_t) lfns ); fns[ lfns ] = '\0'; (void) memcpy( (void *) fid, (const void *) nam.nam$t_dvi, sizeof( struct FID ) ); } } } /* Portable version: */ /* ================ */ #else /* If required, obtain the full path name of the file. */ if ( expand ) { rec1_get_path( file + start, file_len - start, &fns, &lfns ); } /* Otherwise, allocate space and copy the file name for use directly. */ else { lfns = file_len - start; rec_alloc_mem( lfns + 1, (void **) &fns ); if ( _ok( hds_gl_status ) ) { (void) memcpy( (void *) fns, (const void *) ( file + start ), (size_t) lfns ); fns[ lfns ] = '\0'; } } /* Allocate memory to hold the File ID and store file identification */ /* information in it. */ rec_alloc_mem( sizeof( struct FID ), (void **) &fid ); rec1_get_fid( fns, fid ); #endif /* Loop to search the File Control Vector for any slot which is currently */ /* open and associated with the same file. */ if ( _ok( hds_gl_status ) ) { *slot = rec_gl_endslot; *newslot = 1; for ( i = 0; i < rec_gl_endslot; i++ ) { /* Remember the number of the last slot which is not being used. */ if ( !rec_ga_fcv[ i ].open ) { *slot = i; } /* If a slot is open and the identification matches, then note that a new */ /* slot is not needed and quit searching */ else if ( !memcmp( (const void *) rec_ga_fcv[ i ].fid, (const void *) fid, sizeof( struct FID ) ) ) { *slot = i; *newslot = 0; break; } } /* If no File ID match or unused FCV slot was found, then a new slot must */ /* be used. */ if ( *slot == rec_gl_endslot ) { /* If there is insufficient space for another slot in the File Control */ /* Vector, then extend the FCV by doubling its size. If successful, */ /* initialise the new region to zero and record the new size. */ if ( *slot >= rec_gl_mxslot ) { rec_reall_mem( rec_gl_mxslot * 2 * sizeof( struct FCV ), (void **) &rec_ga_fcv ); if ( _ok( hds_gl_status ) ) { (void) memset( (void *) ( rec_ga_fcv + rec_gl_mxslot ), 0, sizeof( struct FCV ) * (size_t) rec_gl_mxslot ); rec_gl_mxslot *= 2; } } /* If OK, increment the count of FCV slots used. */ if ( _ok( hds_gl_status ) ) { rec_gl_endslot++; } } } /* See if the file needs opening. This will be necessary if a new FCV slot */ /* is being used or if the file is currently open for read-only access and */ /* write access is now required. */ if ( _ok( hds_gl_status ) ) { mustopen = *newslot || ( ( mode != 'R' ) && ( rec_ga_fcv[ *slot ].write == REC__NOIOCHAN ) ); /* If the file is to be opened... */ if ( mustopen ) { /* VMS version: */ /* =========== */ #if defined( vms ) /* Initialise the FAB block. */ fab.fab$l_fop = FAB$M_UFO | FAB$M_NAM; fab.fab$b_shr = FAB$M_SHRPUT | FAB$M_SHRGET | FAB$M_UPI; fab.fab$b_fac = ( mode == 'R' ) ? FAB$M_GET : ( FAB$M_GET | FAB$M_PUT ); /* Open the file, reporting any errors. */ systat = SYS$OPEN( &fab ); if ( !( systat & STS$M_SUCCESS ) ) { hds_gl_status = ( systat == RMS$_PRV ) ? DAT__FILPR : DAT__FILNF; emsSetnc( "FILE", rsabuf, nam.nam$b_rsl ); emsSetnc( "ACCESS", ( mode == 'R' ) ? "reading" : "writing", EMS__SZTOK ); emsSyser( "MESSAGE", systat ); emsRep( "REC1_OPEN_FILE_3", "Unable to open file ^FILE for ^ACCESS - ^MESSAGE.", &hds_gl_status ); } /* If the file was opened successfully, extract its I/O channel from the */ /* FAB block. */ else { iochan = (int) fab.fab$l_stv; } /* Portable version: */ /* ================ */ #else /* Open the file, checking for errors. */ iochan = fopen( (const char *) fns, ( mode == 'R' ) ? "rb" : "r+b"); if ( iochan == NULL ) { /* Categorise the possible error conditions, setting the appropriate status */ /* value. */ switch ( errno ) { case EACCES: hds_gl_status = DAT__FILPR; /* Access denied */ break; case EISDIR: hds_gl_status = DAT__FILIN; /* File is a directory */ break; case EROFS: hds_gl_status = DAT__FILPR; /* Read-only file system */ break; default: /* All other errors ==> */ hds_gl_status = DAT__FILNF; /* File not found */ break; } /* Report the error. */ emsSyser( "MESSAGE", errno ); emsSetnc( "FILE", fns, EMS__SZTOK ); emsSetnc( "ACCESS", ( mode == 'R' ) ? "read" : "read/write", EMS__SZTOK ); emsRep( "REC1_OPEN_FILE_4", "Error opening file ^FILE for ^ACCESS access - \ ^MESSAGE", &hds_gl_status ); } #endif } } /* If the file has been opened successfully but an old slot has been used, */ /* then simply store the new I/O channel in the slot. */ if ( _ok( hds_gl_status ) ) { if ( mustopen ) { if ( !*newslot ) { rec_ga_fcv[ *slot ].write = iochan; } /* If a new slot is being used, fill in the File Control Vector fields, */ /* marking the slot as open. */ else { fcv = &rec_ga_fcv[ *slot ]; fcv->name = fns; fcv->fid = fid; fcv->read = ( mode == 'R' ) ? iochan : REC__NOIOCHAN; fcv->write = ( mode == 'R' ) ? REC__NOIOCHAN : iochan; fcv->count = 0; fcv->dele = 0; fcv->open = 1; fcv->locked = 0; fcv->hcb = NULL; fcv->hcbmodify = 0; } } } /* If an error occurred, then deallocate any memory allocated for the File */ /* Name String and File ID. */ /* Also free the memory if we are reusing a slot (since the name is already */ /* stored and the copy is not used. */ if ( !_ok( hds_gl_status ) || !*newslot ) { rec_deall_mem( lfns + 1, (void **) &fns ); rec_deall_mem( sizeof( struct FID ), (void **) &fid ); } /* Exit the routine. */ return; }
void search( ushort used ) { int prev = 0; ME_PIPE mepI = {0}, mepO = {0}, mepP = {0}; DWORD isEof = 0; schar iSz[] = { sizeof( lint ), sizeof( long ), sizeof( int ), sizeof( short ), sizeof( char ) }, *uSz = iSz, fSz[] = { sizeof( lpn ), sizeof( dpn ), sizeof( fpn ) }; int i = 0,// c = 5, qNo = 0; char szDmp[4] = {0}, szPath[10] = {0}, szNow[10] = "q", szOld[10] = {0}; char const fEx[] = ".mef", iEx[] = ".mes", uEx[] = ".meu"; ipFdOpen( mepI.fd, "test.xps", IP_O_RW, IP_D_RW ); snprintf( szDmp, 4, "%i", qNo ); appendstr( szNow, DIR_SEP, 10 ); copystri( szOld, szNow, 10 ); appendstr( szNow, szDmp, 10 ); if ( qNo ) { snprintf( szDmp, 4, "%i", qNo - 1 ); } else { copystri( szDmp, "0", 4 ); } appendstr( szOld, szDmp, 10 ); copystri( szPath, szNow, 10 ); appendstr( szPath, ".dmp", 10 ); ipFdOpen( mepO.fd, szPath, IP_O_MKFILE | IP_O_RW, IP_D_RW ); isEof = ipFdRdBuff( mepI.fd, mepI.buff, BUFSIZ ); do { ipFdWrBuff( mepO.fd, mepO.buff, BUFSIZ ); isEof = ipFdRdBuff( mepI.fd, mepI.buff, BUFSIZ ); } while ( isEof ); ipFdShut( mepI.fd ); ipFdShut( mepO.fd ); ipFdOpen( mepI.fd, szPath, IP_O_RW, IP_D_RW ); SEARCH( f, 3 ); SEARCH( i, 5 ); SEARCH( u, 5 ); /* Close Down Pipes */ if ( prev ) { ipFdShut( prev ); ipFdShut( mepP.fd ); } ipFdShut( mepI.fd ); }
int vms_file_stats_name (const char *filename, long long *cdt, long *siz, char *rfo, int *ver) { #ifdef VMS struct FAB fab; struct NAM nam; unsigned long long create; FAT recattr; char ascnamebuff [256]; ATRDEF atrlst[] = { { ATR$S_CREDATE, ATR$C_CREDATE, &create }, { ATR$S_RECATTR, ATR$C_RECATTR, &recattr }, { ATR$S_ASCNAME, ATR$C_ASCNAME, &ascnamebuff }, { 0, 0, 0} }; FIBDEF fib; struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib}; struct IOSB iosb; long status; unsigned short chan; struct vstring file; struct dsc$descriptor_s filedsc = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string}; struct vstring device; struct dsc$descriptor_s devicedsc = {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string}; struct vstring result; struct dsc$descriptor_s resultdsc = {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string}; if (strcmp (filename, "<internal>") == 0 || strcmp (filename, "<built-in>") == 0) { if (cdt) *cdt = 0; if (siz) *siz = 0; if (rfo) *rfo = 0; if (ver) *ver = 0; return 0; } tryfile = to_vms_file_spec ((char *) filename); /* Allocate and initialize a FAB and NAM structures. */ fab = cc$rms_fab; nam = cc$rms_nam; nam.nam$l_esa = file.string; nam.nam$b_ess = NAM$C_MAXRSS; nam.nam$l_rsa = result.string; nam.nam$b_rss = NAM$C_MAXRSS; fab.fab$l_fna = tryfile; fab.fab$b_fns = strlen (tryfile); fab.fab$l_nam = &nam; /* Validate filespec syntax and device existence. */ status = SYS$PARSE (&fab, 0, 0); if ((status & 1) != 1) return 1; file.string[nam.nam$b_esl] = 0; /* Find matching filespec. */ status = SYS$SEARCH (&fab, 0, 0); if ((status & 1) != 1) return 1; file.string[nam.nam$b_esl] = 0; result.string[result.length=nam.nam$b_rsl] = 0; /* Get the device name and assign an IO channel. */ strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev); devicedsc.dsc$w_length = nam.nam$b_dev; chan = 0; status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0); if ((status & 1) != 1) return 1; /* Initialize the FIB and fill in the directory id field. */ memset (&fib, 0, sizeof (fib)); fib.fib$w_did[0] = nam.nam$w_did[0]; fib.fib$w_did[1] = nam.nam$w_did[1]; fib.fib$w_did[2] = nam.nam$w_did[2]; fib.fib$l_acctl = 0; fib.fib$l_wcc = 0; strcpy (file.string, (strrchr (result.string, ']') + 1)); filedsc.dsc$w_length = strlen (file.string); result.string[result.length = 0] = 0; /* Open and close the file to fill in the attributes. */ status = SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0, &fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0); if ((status & 1) != 1) return 1; if ((iosb.status & 1) != 1) return 1; result.string[result.length] = 0; status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0, &atrlst, 0); if ((status & 1) != 1) return 1; if ((iosb.status & 1) != 1) return 1; /* Deassign the channel and exit. */ status = SYS$DASSGN (chan); if ((status & 1) != 1) return 1; if (cdt) *cdt = create; if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) + (512 * (recattr.fat$w_efblkl - 1)) + recattr.fat$w_ffbyte; if (rfo) *rfo = recattr.fat$v_rtype; if (ver) *ver = strtol (strrchr (ascnamebuff, ';')+1, 0, 10); return 0; #else struct stat buff; struct tm *ts; if ((stat (filename, &buff)) != 0) return 1; if (cdt) { ts = localtime (&buff.st_mtime); *cdt = (long long) ((buff.st_mtim.tv_sec * VMS_GRANULARITY_FACTOR) + (buff.st_mtim.tv_nsec / 100)) + VMS_EPOCH_OFFSET; } if (siz) *siz = buff.st_size; if (rfo) *rfo = 2; /* Stream LF format. */ if (ver) *ver = 0; return 0; #endif }
Main_Window::Main_Window(std::string login_user, DStore dbase) { ds = dbase; currentuser = login_user; //Title setWindowTitle("Amazon Shop"); // Overall layout OverallLayout = new QHBoxLayout(); //this is smaller layout within overall layout SearchOptionLayout = new QVBoxLayout(); OverallLayout->addLayout(SearchOptionLayout); //Terms text SearchTermsLabel = new QLabel("Search Terms"); SearchOptionLayout->addWidget(SearchTermsLabel); //Creating line edit to enter terms to search SearchTermsInput = new QLineEdit(); SearchOptionLayout->addWidget(SearchTermsInput); //Creating exclusive group check-box CheckboxLayout = new QHBoxLayout(); SearchOptionLayout->addLayout(CheckboxLayout); AND = new QRadioButton(tr("AND")); CheckboxLayout->addWidget(AND); OR = new QRadioButton(tr("OR")); CheckboxLayout->addWidget(OR); AND->setAutoExclusive(true); AND->setChecked(true); //Add the search button SearchButton = new QPushButton("SEARCH"); connect(SearchButton, SIGNAL(clicked()), this, SLOT(SEARCH())); SearchOptionLayout->addWidget(SearchButton); //Add the alphabetical merge-sort button SortOptionLayout = new QHBoxLayout(); SearchOptionLayout->addLayout(SortOptionLayout); AlphaSortButton = new QPushButton("Sort Search Alphabetically"); connect(AlphaSortButton, SIGNAL(clicked()), this, SLOT(AlphaSort())); SortOptionLayout->addWidget(AlphaSortButton); //Add the review merge-sort button ReviewSortButton = new QPushButton("Sort Search by Average Rating"); connect(ReviewSortButton, SIGNAL(clicked()), this, SLOT(RSort())); SortOptionLayout->addWidget(ReviewSortButton); //Create dropdown menu to select user UserDropdown = new QComboBox(); //iterating through user vector to print into menu for(unsigned int i=0; i<ds.getUserVector().size(); i++) { std::vector<User*> myVector= ds.getUserVector(); User* user= myVector[i]; QString qstr= QString::fromStdString(user->getName()); UserDropdown->addItem(qstr); } SearchOptionLayout->addWidget(UserDropdown); connect(UserDropdown, SIGNAL(currentIndexChanged(int)), this, SLOT(filler(int))); //Horizontal layout for add and view cart buttons CartOptionLayout = new QHBoxLayout(); SearchOptionLayout->addLayout(CartOptionLayout); //Create add cart button AddCartButton = new QPushButton("Add-to-Cart"); connect(AddCartButton, SIGNAL(clicked()), this, SLOT(ADDCART())); CartOptionLayout->addWidget(AddCartButton); //Create view cart button ViewCartButton = new QPushButton("View-Cart"); connect(ViewCartButton, SIGNAL(clicked()), this, SLOT(VIEWCART())); CartOptionLayout->addWidget(ViewCartButton); //Enter valid file to save to text SaveLabel = new QLabel("Type valid file to save to"); SearchOptionLayout->addWidget(SaveLabel); //Creating line edit to enter terms to search SaveInput = new QLineEdit(); SearchOptionLayout->addWidget(SaveInput); //Save database to a file button SaveButton = new QPushButton("Save Text File"); connect(SaveButton, SIGNAL(clicked()), this, SLOT(SAVE())); SearchOptionLayout->addWidget(SaveButton); //Quit program button QuitButton = new QPushButton("QUIT"); connect(QuitButton, SIGNAL(clicked()), this, SLOT(QUIT())); SearchOptionLayout->addWidget(QuitButton); //Create product list and layout ProductLayout = new QVBoxLayout(); OverallLayout->addLayout(ProductLayout); //Create text for Products ProductsLabel = new QLabel("Products That Match Search"); ProductLayout->addWidget(ProductsLabel); //Create empty list that will have products from search ProductList = new QListWidget(); prodref = ProductList; connect(ProductList, SIGNAL(currentRowChanged(int)), this, SLOT(ProductChange(int))); ProductLayout->addWidget(ProductList); //Create review list and layout ReviewLayout = new QVBoxLayout(); OverallLayout->addLayout(ReviewLayout); //Create text for Reviews ReviewsLabel = new QLabel("Reviews of Product"); ReviewLayout->addWidget(ReviewsLabel); //Create empty list that will have reviews of products from search ReviewList = new QListWidget(); ReviewLayout->addWidget(ReviewList); //Create add reviews layout AddReviewLayout = new QVBoxLayout(); OverallLayout->addLayout(AddReviewLayout); //Create text for adding reviews AddReviewsLabel = new QLabel("Add a Review Section"); AddReviewLayout->addWidget(AddReviewsLabel); //Creating text for adding rating AddReviewsRating = new QLabel("Enter an integer between 1-5"); AddReviewLayout->addWidget(AddReviewsRating); //Creating line edit to enter rating of product RatingLine = new QLineEdit(); AddReviewLayout->addWidget(RatingLine); //Creating text for adding date AddReviewsDate = new QLabel("Enter a date: YYYY-MM-DD"); AddReviewLayout->addWidget(AddReviewsDate); //Creating line edit to enter date of product DateLine = new QLineEdit(); AddReviewLayout->addWidget(DateLine); //Creating text for string of text AddReviewsText = new QLabel("Type in review text"); AddReviewLayout->addWidget(AddReviewsText); //Creating line edit to enter string of text of product TextLine = new QLineEdit(); AddReviewLayout->addWidget(TextLine); AddReviewButton = new QPushButton("ADD REVIEW"); connect(AddReviewButton, SIGNAL(clicked()), this, SLOT(ADDREVIEW())); AddReviewLayout->addWidget(AddReviewButton); setLayout(OverallLayout); }