|
|
1.1 ! root 1: /* Main entry point to REGISTER. This routine does initial setup, */ ! 2: /* such as opening the files, allocating the shared memory, */ ! 3: /* registering the replacement routine, calling the original routine */ ! 4: /* and starting the ACCESS routine in a different screen group. */ ! 5: /* */ ! 6: /* Created by Microsoft Corp. 1988 */ ! 7: ! 8: ! 9: #define INCL_DOSSESMGR ! 10: #define INCL_DOSFILEMGR ! 11: #define INCL_DOSMEMMGR ! 12: #define INCL_DOSSEMAPHORES ! 13: #define INCL_SUB ! 14: ! 15: #include <os2def.h> ! 16: #include <bse.h> ! 17: #include <stdio.h> ! 18: #include <fcntl.h> ! 19: #include "share.h" /* Common declarations between processes */ ! 20: ! 21: extern unsigned _aenvseg; /* Used by GetPath in getting the full path */ ! 22: extern unsigned _acmdln; /* name of this program (the one used by */ ! 23: /* EXECPGM()) */ ! 24: ! 25: int fileopen(); ! 26: void GetPath(); ! 27: ! 28: ! 29: main(argc, argv) ! 30: int argc; ! 31: NPCH argv[]; ! 32: ! 33: { STARTDATA SDbuf; /* Stores process data for ! 34: DosStartSession */ ! 35: struct ShareRec far *SmemPtr; /* Shared memory layout defined in ! 36: Share.h */ ! 37: HFILE fpoint; /* file pointer */ ! 38: USHORT byread; /* Number of bytes read by DosRead */ ! 39: unsigned rc; /* return code */ ! 40: SEL Selector; /* Shared memory selector */ ! 41: USHORT SessionID, ProcessID; /* Values returned by DosStartSession ! 42: when child process is started. ! 43: ACCESS.EXE isn't a child process. */ ! 44: char string[10]; /* Read by DosRead, written by ! 45: VioWrtTTy */ ! 46: char *spbuf, pathbuf[128], Inputs[10]; ! 47: char pathname[128], modname[128]; ! 48: ! 49: /* If no file is specified, exit the program to start again */ ! 50: if (argc == 1) { ! 51: printf("Usage: Register n\n"); ! 52: printf(" Must specify n as 1,2, or 3\n"); ! 53: DosExit(EXIT_PROCESS,0); ! 54: } ! 55: ! 56: /* Allocate shared memory for counter in ACCESS.EXE */ ! 57: if (rc = DosAllocShrSeg( SHRSEGSIZE, SHRSEGNAME, &Selector)) { ! 58: printf("Alloc of shared memory failed, error: %d\n", rc); ! 59: DosExit(EXIT_PROCESS,0); ! 60: } ! 61: ! 62: /* Get a far pointer from a 16-bit selector */ ! 63: SmemPtr = (struct ShareRec far *) MAKEP(Selector,0); ! 64: ! 65: /* Initialize shared memory semaphores */ ! 66: DosSemSet((HSEM)&(SmemPtr->updated)); ! 67: DosSemClear((HSEM)&(SmemPtr->mutexsem)); ! 68: SmemPtr->count = 0; ! 69: SmemPtr->mutexsem = 0; ! 70: SmemPtr->totalength = 0; ! 71: ! 72: /* Data that describes ACCESS.EXE for DosStartSession */ ! 73: spbuf = "SHARED MEMORY ACCESS"; ! 74: SDbuf.cb = sizeof(SDbuf); ! 75: SDbuf.Related = 0; /* Unrelated process */ ! 76: SDbuf.FgBg = 0; /* Start ACCESS.EXE in foreground */ ! 77: SDbuf.TraceOpt = 0; /* Run synchronously */ ! 78: SDbuf.PgmTitle = spbuf; /* Title in session manager box */ ! 79: GetPath(pathbuf); ! 80: sprintf(pathname, "%s%s", pathbuf,"ACCESS.EXE"); ! 81: SDbuf.PgmName= pathname; /* Exec path - see GetPath */ ! 82: SDbuf.PgmInputs= 0L; /* No command line arguments */ ! 83: SDbuf.TermQ = 0L; /* No notification queue */ ! 84: ! 85: /* Start ACCESS.EXE using above data */ ! 86: /* SessionID and ProcessID are not returned - unrelated process */ ! 87: DosStartSession(&SDbuf, &SessionID, &ProcessID); ! 88: ! 89: /* Register the replacement routine in the dynamic link module, within ! 90: this screen group. VIOROUT is the name of the dll, and VIOROUT is the ! 91: name of the replacement routine in the dll. */ ! 92: rc = VioRegister("VIOROUT", "VIOROUT", 0x4000L, 0L); ! 93: if (rc >= 1) ! 94: printf(" VioRegister error: %d\n", rc); ! 95: ! 96: /* Open file for VioWrtTTy to read */ ! 97: fpoint = fileopen(pathbuf,*argv[1]); ! 98: ! 99: DosRead(fpoint, string, 10, &byread); ! 100: while (byread != 0) { ! 101: /* Calling VioWrtTTy sends control to the VIO router, which invokes ! 102: the replacement routine registered in VioRegister */ ! 103: VioWrtTTy(string,10,0); ! 104: DosRead(fpoint, string, 10, &byread); ! 105: } ! 106: ! 107: VioDeRegister(); ! 108: ! 109: } ! 110: ! 111: int fileopen(pathvar,av) ! 112: NPCH pathvar; ! 113: int av; ! 114: { int fp; ! 115: char filename[128]; ! 116: ! 117: switch (av) { ! 118: case '1': ! 119: sprintf(filename, "%s%s", pathvar, "TEST1.DAT"); ! 120: fp = open(filename, O_RDONLY); ! 121: if (fp == -1) { ! 122: printf(" Cannot open file 1.\n"); ! 123: DosExit(EXIT_PROCESS,0); } ! 124: break; ! 125: case '2': ! 126: sprintf(filename, "%s%s", pathvar, "TEST2.DAT"); ! 127: fp = open(filename, O_RDONLY); ! 128: if (fp == -1) { ! 129: printf(" Cannot open file 2.\n"); ! 130: DosExit(EXIT_PROCESS,0); } ! 131: break; ! 132: case '3': ! 133: sprintf(filename, "%s%s", pathvar, "TEST3.DAT"); ! 134: fp = open(filename, O_RDONLY); ! 135: if (fp == -1) { ! 136: printf(" Cannot open file 3.\n"); ! 137: DosExit(EXIT_PROCESS,0); } ! 138: break; ! 139: default: ! 140: sprintf(filename, "%s%s", pathvar, "TEST1.DAT"); ! 141: fp = open(filename, O_RDONLY); ! 142: if (fp == -1) { ! 143: printf(" Cannot open file.\n"); ! 144: DosExit(EXIT_PROCESS,0); } ! 145: break; ! 146: } ! 147: return(fp); ! 148: } ! 149: ! 150: void GetPath(pbuf) ! 151: NPCH pbuf; ! 152: ! 153: { int i,c; ! 154: PCH progname; ! 155: ! 156: ! 157: SELECTOROF(progname) = _aenvseg; /* Standard C runtime routines */ ! 158: OFFSETOF(progname) = _acmdln-1; /* The pathname comes just prior */ ! 159: c = 0; /* to argv[0]-but is in a different */ ! 160: while(*--progname != '\\') /* segment, thus the copy to pbuf */ ! 161: ; ! 162: ! 163: /* Cut the program name off the path */ ! 164: while (*--progname) ! 165: c++; ! 166: ! 167: for (i=0; i<=c; i++) ! 168: pbuf[i]= *++progname; ! 169: ! 170: pbuf[++c] = '\0'; ! 171: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.