⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grphshm.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      *nameend = '\0';           /*chop display off */    nameend = strchr (name, '.');    if (nameend != NULL)      *nameend = '\0';           /*chop resolv off */    #ifdef __UNIX__    if (strcmp (name, LOCAL1) && strcmp (name, LOCAL2)    && gethostname (thishost, MAX_PATH) >= 0) {      nameend = strchr (thishost, '.');      if (nameend != NULL)        *nameend = '\0';         /*chop resolv off */      if (strcmp (name, thishost)) {        return TRUE;      }    }    #else    return TRUE;    #endif  }  #endif  return FALSE;}/********************************************************************** * getshm * * Get the next element of the shared memory.  If there is no more room * in the segment, kick the daemon to get it to empty it out and then * restart the buffer once it acknowledges the cleanout. **********************************************************************/DLLSYM void *getshm(            /*get memory */                    INT32 size  /*required size */                   ) {  void *segment;                 /*return segment */  if (shminfo.shmstart == NULL)    return NULL;                 //no daemon connection  size = (size + 3) & ~3;  if (size > shminfo.shmsize)    return NULL;                                 /*too full? */  if (shminfo.usedsize + size > shminfo.shmsize  || shminfo.usedsize < 0) {     /*or read pending */    kick_daemon(AWAIT_BUFFER);  /*get it to read */  }                                 /*address of segment */  segment = (char *) shminfo.shmstart + shminfo.usedsize;  shminfo.usedsize += size;      /*sum used sizes */  return segment;}/********************************************************************** * kick_daemon * * Tell the daemon to read the shared memory and perform all the * operations in it.  This function blocks until the daemon has * emptied the queue. **********************************************************************/void kick_daemon(           /*empty queue */                 INT8 mode  /*control mode */                ) {  #ifndef __MAC__  SBD_GRAPHICS_EVENT event;      /*event from daemon */  GRAPHICS_EVENT real_event;     //converted format  #ifdef __MSW32__  unsigned long nwrite;  unsigned long nread;           //bytes read  char pipe_char[2];             //char from pipe  INT32 pipe_index;              //index to event queue  #endif  static INT16 reads_pending = 0;/*acknowledges pending */  if (mode == COUNT_READS) {    lock_events();    reads_pending--;             /*got a read */    unlock_events();    return;  }  if (shminfo.shmstart == NULL)    return;                      //no connection  if (shminfo.usedsize > 0) {    #ifdef __UNIX__    if (write      (shminfo.fds[OUTFD], (const char *) &shminfo.usedsize,      sizeof (INT32)) != sizeof (INT32))      WRITEFAILED.error ("kick_daemon", EXIT, "sbdaemon pipe");    #else    PRIMITIVES = shminfo.usedsize;    if (WriteFile (shminfo.fds[OUTFD], "xx", 2, &nwrite, NULL) == 0    || nwrite != 2) {      cleanup_sbdaemon();      return;    }    #endif    #ifdef __UNIX__    if (shminfo.shmid < 0) {      if (write (shminfo.fds[OUTFD], (const char *) shminfo.shmstart,        shminfo.usedsize) != shminfo.usedsize)        WRITEFAILED.error ("kick_daemon", EXIT, "sbdaemon pipe");      #else      if (shminfo.shmid == NULL) {        if (WriteFile (shminfo.fds[OUTFD], (const char *) shminfo.shmstart,          shminfo.usedsize, &nwrite, NULL) == 0        || nwrite != (UINT32) shminfo.usedsize) {          cleanup_sbdaemon();          return;        }        #endif        shminfo.usedsize = 0;    /*can use it now */      }      else        shminfo.usedsize = -1;   /*need to wait */      lock_events();      reads_pending++;           /*acknowledges due */      unlock_events();    }    if (mode == FLUSH_IN || reads_pending > MAX_PENDING || mode == AWAIT_BUFFER      #ifdef __UNIX__      && shminfo.shmid < 0)    #else      && shminfo.shmid != NULL)        #endif    {      while (reads_pending > 0) {        #ifdef __MSW32__        if (event_id == GetCurrentThreadId ()) {          if (ReadFile (shminfo.fds[INFD], pipe_char, 2, &nread, NULL) != 0          && nread == 2) {            pipe_index = EVENT_HEAD;              event = EVENT_INDEX (pipe_index);              pipe_index++;              if (pipe_index >= EVENTSIZE)                pipe_index = 0;                EVENT_HEAD = pipe_index;                #endif                #ifdef __UNIX__                if (read                  (shminfo.fds[INFD], &event,                  sizeof (SBD_GRAPHICS_EVENT)) !=                  sizeof (SBD_GRAPHICS_EVENT))                  READFAILED.error ("kick_daemon", EXIT, "sbdaemon pipe");                  #endif            if (event.type != QUEUE_CLEAR) {              real_event.fildes = event.fd;                real_event.type = event.type;                real_event.key = event.key;                real_event.x = event.x;                real_event.y = event.y;                real_event.next = NULL;                                 /*add event to queue */                add_event(&real_event);            }            else              reads_pending--;   /*got acknowledge */              #ifdef __MSW32__          }        }        else          Sleep (50);            #endif      }      if (shminfo.usedsize < 0)  //must be reentrant          shminfo.usedsize = 0;  /*none used now */    }    #endif  }  #ifdef __MSW32__  /**********************************************************************   * two_way_pipe   *   * Open the process and connect a 2 way pipe to its stdin and stdout.   **********************************************************************/  int    two_way_pipe (               //do one file    const char *file,            //program to run    const char *argv[],          //args to execvp    HANDLE fds[]                 //output fds  ) {    int argind;                  //argument index      HANDLE infds[2];           //input fds      HANDLE outfds[2];          //output fds      HANDLE sends[2];           //fds for child      HANDLE process;            //current process      STARTUPINFO start_info;    //start information                                 //process info      PROCESS_INFORMATION proc_info;      char cmd[MAX_PATH * 2];    //final command line      if (CreatePipe (&infds[0], &infds[1], NULL, PIPESIZE) == 0        || CreatePipe (&outfds[0], &outfds[1], NULL, PIPESIZE) == 0)        return -1;    /*	if (_pipe(infds,PIPESIZE,_O_BINARY)<0      || _pipe(outfds,PIPESIZE,_O_BINARY)<0)        return -1;	*/        process = GetCurrentProcess ();        if (DuplicateHandle (process, outfds[0],          process, &sends[0], GENERIC_READ, TRUE,          DUPLICATE_CLOSE_SOURCE) == 0)          return -1;          if (DuplicateHandle (process, infds[1],            process, &sends[1], GENERIC_WRITE, TRUE,            DUPLICATE_CLOSE_SOURCE) == 0)            return -1;            cmd[0] = '\0';    for (argind = 0; argv[argind] != NULL; argind++) {      if (argind != 0)          strcat (cmd, " ");          strcat (cmd, argv[argind]);    }    GetStartupInfo(&start_info);      start_info.wShowWindow = FALSE;      start_info.hStdInput = sends[0];      start_info.hStdOutput = sends[1];      start_info.dwFlags = STARTF_USESTDHANDLES;      if (!CreateProcess (NULL, (char *) cmd, NULL, NULL, TRUE,        CREATE_NO_WINDOW | CREATE_SUSPENDED, NULL, NULL,        &start_info, &proc_info))        return -1;        CloseHandle (sends[0]);        CloseHandle (sends[1]);        CloseHandle (proc_info.hProcess);        ResumeThread (proc_info.hThread);        CloseHandle (proc_info.hThread);        fds[INFD] = infds[0];        fds[OUTFD] = outfds[1];        return 0;  }  #endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -