Ejemplo n.º 1
0
// NOTE: arg_i is used here to avoid ugly *i so many times in this function
void ParseArgs(const int argc, char** argv,
                  const char** lang,
                  const char** image,
                  const char** outputbase,
                  const char** datapath,
                  bool* list_langs,
                  bool* print_parameters,
                  GenericVector<STRING>* vars_vec,
                  GenericVector<STRING>* vars_values,
                  int* arg_i,
                  tesseract::PageSegMode* pagesegmode) {
  if (argc == 1) {
    PrintHelpMessage(argv[0]);
    exit(0);
  }

  if (argc == 2) {
    if ((strcmp(argv[1], "-h") == 0) ||
         (strcmp(argv[1], "--help") == 0)) {
      PrintHelpMessage(argv[0]);
      exit(0);
    }
    if ((strcmp(argv[1], "--help-psm") == 0)) {
      PrintHelpForPSM();
      exit(0);
    }
    if ((strcmp(argv[1], "-v") == 0) ||
         (strcmp(argv[1], "--version") == 0)) {
      PrintVersionInfo();
      exit(0);
    }
  }

  bool noocr = false;
  int i = 1;
  while (i < argc && (*outputbase == NULL || argv[i][0] == '-')) {
    if (strcmp(argv[i], "-l") == 0 && i + 1 < argc) {
      *lang = argv[i + 1];
      ++i;
    } else if (strcmp(argv[i], "--tessdata-dir") == 0 && i + 1 < argc) {
      *datapath = argv[i + 1];
      ++i;
    } else if (strcmp(argv[i], "--user-words") == 0 && i + 1 < argc) {
      vars_vec->push_back("user_words_file");
      vars_values->push_back(argv[i + 1]);
      ++i;
    } else if (strcmp(argv[i], "--user-patterns") == 0 && i + 1 < argc) {
      vars_vec->push_back("user_patterns_file");
      vars_values->push_back(argv[i + 1]);
      ++i;
    } else if (strcmp(argv[i], "--list-langs") == 0) {
      noocr = true;
      *list_langs = true;
    } else if (strcmp(argv[i], "-psm") == 0 && i + 1 < argc) {
      *pagesegmode = static_cast<tesseract::PageSegMode>(atoi(argv[i + 1]));
      ++i;
    } else if (strcmp(argv[i], "--print-parameters") == 0) {
      noocr = true;
      *print_parameters = true;
    } else if (strcmp(argv[i], "-c") == 0 && i + 1 < argc) {
      // handled properly after api init
      ++i;
    } else if (*image == NULL) {
      *image = argv[i];
    } else if (*outputbase == NULL) {
      *outputbase = argv[i];
    }
    ++i;
  }

  *arg_i = i;

  if (argc == 2 && strcmp(argv[1], "--list-langs") == 0) {
    *list_langs = true;
    noocr = true;
  }

  if (*outputbase == NULL && noocr == false) {
    PrintHelpMessage(argv[0]);
    exit(1);
  }
}
Ejemplo n.º 2
0
/***********************************************************************
 *                             HandleCmdLineArgs
 *  This function handles the command line arguments.
 *  output: stack size
 ***********************************************************************/
void HandleCmdLineArgs(
    int argc,                       /* number of command-line arguments */
    char *argv[])                   /* ptrs to command-line arguments   */
{
    int argNum;                     /* argument number                  */

    if (argc > (int) 1) {

        for (argNum = (int) 1; argNum < argc; argNum++) {

            /* The command line contains an argument. */

            if ((strcmp(argv[argNum],"--version") == STRINGS_EQUAL) ||
                (strcmp(argv[argNum],"-v")        == STRINGS_EQUAL)) {
                /* Print version information and exit. */
                PrintVersionInfo();
                exit(0);
            }

            else if ((strcmp(argv[argNum],"--help") == STRINGS_EQUAL) ||
                     (strcmp(argv[argNum],"-h")     == STRINGS_EQUAL) ||
                     (strcmp(argv[argNum],"-?")     == STRINGS_EQUAL)) {
                /* Print help information and exit. */
                PrintHelpInfo();
                exit(0);
            }

            else if ((strcmp(argv[argNum],"--file") == STRINGS_EQUAL) ||
                     (strcmp(argv[argNum],"-f")     == STRINGS_EQUAL)) {
                /* Set the name of the output file. */
                ++argNum;
                if (argNum < argc) {
                    SetFileName(argv[argNum]);
                }
                else {
                    printf("*** Output file name not specified. ***\n");
                    printf("Default output file name will be used.\n");
                }
            }

            else if ((strcmp(argv[argNum],"--time") == STRINGS_EQUAL) ||
                     (strcmp(argv[argNum],"-t")     == STRINGS_EQUAL)) {
                /* Set the interrupt period. */
                ++argNum;
                if (argNum < argc) {
                    SetInterruptPeriod(argv[argNum]);
                }
                else {
                    printf("*** Interrupt period not specified. ***\n");
                    printf("Default interrupt period will be used.\n");
                }

            }

            else if ((strcmp(argv[argNum],"--priority") ==
                      STRINGS_EQUAL) ||
                     (strcmp(argv[argNum],"-p")       == STRINGS_EQUAL)) {
                /* Set the scheduler priority. */
                ++argNum;
                if (argNum < argc) {
                    SetSchedulerPriority(argv[argNum]);
                }
                else {
                    printf("*** Scheduler priority not specified. ***\n");
                    printf("Default scheduler priority will be used.\n");
                }

            }

            else if ((strcmp(argv[argNum],"--readfile") ==
                      STRINGS_EQUAL) ||
                     (strcmp(argv[argNum],"-r")       == STRINGS_EQUAL)) {
                /* Set the file to read*/
                ++argNum;

                strncpy(ReadFile, argv[argNum], sizeof(ReadFile));
                DoRead = TRUE;
            }

            else if ((strcmp(argv[argNum],"--write_bytes") ==
                      STRINGS_EQUAL) ||
                     (strcmp(argv[argNum],"-w")       == STRINGS_EQUAL)) {
                /* Set the file to read*/
                ++argNum;

                WriteBytes = atoi(argv[argNum]);

                if(WriteBytes < MIN_WRITE_BYTES)
                {
                    printf("Writing less than %i bytes is not allowed. Bye.\n",
                           MIN_WRITE_BYTES);
                    exit(0);
                }


            }

            else if ((strcmp(argv[argNum],"--consolefile") ==
                      STRINGS_EQUAL) ||
                     (strcmp(argv[argNum],"-c")       == STRINGS_EQUAL)) {
	      /* Set the file to log console log on. */
	      ++argNum;

	      strncpy(LogFile, argv[argNum], sizeof(LogFile));
            }

            else if ((strcmp(argv[argNum],"--grab_kprofile") ==
                      STRINGS_EQUAL))
	      {
                /* We will read the /proc/profile file on configurable timeout */
                GrabKProfile = TRUE;

                ++argNum;

                /* If the jittter is > this #, then the profile is grabbed. */
                ProfileTriggerMSecs = (long) atoi(argv[argNum]);

		if(ProfileTriggerMSecs <= 0){

		  printf("Illegal value for profile trigger threshold.\n");
		  exit(0);
		}
	      }

            else if ((strcmp(argv[argNum],"--siggc") ==
                      STRINGS_EQUAL))
	      {
                /* We will SIGSTOP/SIGCONT the specified pid */
                SignalGCTask = TRUE;

                ++argNum;

                GCTaskPID = atoi(argv[argNum]);

		if(ProfileTriggerMSecs <= 0){

		  printf("Illegal value for JFFS(2) GC task pid.\n");
		  exit(0);
		}
	      }


            else {
	      /* Unknown argument. Print help information and exit. */
	      printf("Invalid option %s\n", argv[argNum]);
	      printf("Try 'JitterTest --help' for more information.\n");
	      exit(0);
            }
        }
    }

    return;
}
Ejemplo n.º 3
0
INT_PTR CALLBACK DlgProcView(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	RECT rc;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(IDI_VI, true));
			SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconEx(IDI_VI));

			CHARFORMAT2 chf;
			chf.cbSize = sizeof(chf);
			SendDlgItemMessage(hwndDlg, IDC_VIEWVERSIONINFO, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&chf);
			mir_tstrcpy(chf.szFaceName, TEXT("Courier New"));
			SendDlgItemMessage(hwndDlg, IDC_VIEWVERSIONINFO, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&chf);

			CMString buffer;
			PrintVersionInfo(buffer, (unsigned int)lParam);
			SetDlgItemText(hwndDlg, IDC_VIEWVERSIONINFO, buffer.c_str());
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
		}

		if (lParam & VI_FLAG_PRNDLL)
			SetWindowText(hwndDlg, TranslateT("View Version Information (with DLLs)"));

		Utils_RestoreWindowPositionNoMove(hwndDlg, NULL, PluginName, "ViewInfo_");
		ShowWindow(hwndDlg, SW_SHOW);
		break;

	case WM_SIZE:
		GetWindowRect(GetDlgItem(hwndDlg, IDC_FILEVER), &rc);

		int dx, dy;
		if (MyResizeGetOffset(GetDlgItem(hwndDlg, IDC_VIEWVERSIONINFO), LOWORD(lParam) - 20, HIWORD(lParam) - 30 - (rc.bottom - rc.top), &dx, &dy)) {
			HDWP hDwp = BeginDeferWindowPos(4);
			hDwp = MyResizeWindow(hDwp, hwndDlg, GetDlgItem(hwndDlg, IDC_FILEVER), 0, dy, 0, 0);
			hDwp = MyResizeWindow(hDwp, hwndDlg, GetDlgItem(hwndDlg, IDC_CLIPVER), dx / 2, dy, 0, 0);
			hDwp = MyResizeWindow(hDwp, hwndDlg, GetDlgItem(hwndDlg, IDCANCEL), dx, dy, 0, 0);
			hDwp = MyResizeWindow(hDwp, hwndDlg, GetDlgItem(hwndDlg, IDC_VIEWVERSIONINFO), 0, 0, dx, dy);
			EndDeferWindowPos(hDwp);
		}
		break;

	case WM_GETMINMAXINFO:
		{
			LPMINMAXINFO mmi = (LPMINMAXINFO)lParam;
			mmi->ptMinTrackSize.x = 400; // The minimum width in points
			mmi->ptMinTrackSize.y = 300; // The minimum height in points
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_CLIPVER:
			CallService(MS_CRASHDUMPER_STORETOCLIP, 0, GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
			break;

		case IDC_FILEVER:
			CallService(MS_CRASHDUMPER_STORETOFILE, 0, GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
			break;

		case IDCANCEL:
			DestroyWindow(hwndDlg);
			break;
		}
		break;

	case WM_CONTEXTMENU:
		{
			HWND hView = GetDlgItem(hwndDlg, IDC_VIEWVERSIONINFO);
			GetWindowRect(hView, &rc);

			POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
			if (PtInRect(&rc, pt)) {
				static const CHARRANGE all = { 0, -1 };

				HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXT));
				HMENU hSubMenu = GetSubMenu(hMenu, 0);
				TranslateMenu(hSubMenu);

				CHARRANGE sel;
				SendMessage(hView, EM_EXGETSEL, 0, (LPARAM)&sel);
				if (sel.cpMin == sel.cpMax)
					EnableMenuItem(hSubMenu, IDM_COPY, MF_BYCOMMAND | MF_GRAYED);

				switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, NULL)) {
				case IDM_COPY:
					SendMessage(hView, WM_COPY, 0, 0);
					break;

				case IDM_COPYALL:
					SendMessage(hView, EM_EXSETSEL, 0, (LPARAM)&all);
					SendMessage(hView, WM_COPY, 0, 0);
					SendMessage(hView, EM_EXSETSEL, 0, (LPARAM)&sel);
					break;

				case IDM_SELECTALL:
					SendMessage(hView, EM_EXSETSEL, 0, (LPARAM)&all);
					break;
				}
				DestroyMenu(hMenu);
			}
		}
		break;

	case WM_DESTROY:
		hViewWnd = NULL;
		IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
		IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
		Utils_SaveWindowPosition(hwndDlg, NULL, PluginName, "ViewInfo_");
		if (servicemode)
			PostQuitMessage(0);
		break;
	}
	return FALSE;
}