Exemple #1
0
static gint
git_show(gchar ** std_out, gchar ** std_err, const gchar * filename,
	 GSList * list, const gchar * message)
{
	gchar *base_dir = get_base_dir(filename);
	gint len = strlen(base_dir);
	const gchar *argv[] = { "git", "show", NULL, NULL };
	gint ret;

	g_return_val_if_fail(base_dir, -1);

	argv[2] = g_strdup_printf("HEAD:%s", filename + len + 1);

	ret = execute_custom_command(base_dir, argv, GIT_ENV_SHOW, std_out, std_err, base_dir, list,
				     message);
	g_free(base_dir);
	g_free((gchar *) argv[2]);
	return ret;
}
Exemple #2
0
void cmd_myqr(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
    char id_string[TOX_ADDRESS_SIZE * 2 + 1];
    char bin_id[TOX_ADDRESS_SIZE];
    tox_self_get_address(m, (uint8_t *) bin_id);

    if (bin_id_to_string(bin_id, sizeof(bin_id), id_string, sizeof(id_string)) == -1) {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code.");
        return;
    }

    char nick[TOX_MAX_NAME_LENGTH];
    tox_self_get_name(m, (uint8_t *) nick);
    size_t nick_len = tox_self_get_name_size(m);
    nick[nick_len] = '\0';

    size_t data_file_len = strlen(DATA_FILE);
    char dir[data_file_len];
    size_t dir_len = get_base_dir(DATA_FILE, data_file_len, dir);

    char qr_path[dir_len + nick_len + strlen(QRCODE_FILENAME_EXT) + 1];
    snprintf(qr_path, sizeof(qr_path), "%s%s%s", dir, nick, QRCODE_FILENAME_EXT);

    FILE *output = fopen(qr_path, "wb");

    if (output == NULL) {
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code.");
        return;
    }

    if (ID_to_QRcode_string(id_string, output) == -1) {
        fclose(output);
        line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create QR code.");
        return;
    }

    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "QR code has been printed to the file '%s'", qr_path);

    fclose(output);
}
Exemple #3
0
static gint
git_commit(G_GNUC_UNUSED gchar ** std_out, G_GNUC_UNUSED gchar ** std_err, const gchar * filename,
	   GSList * list, const gchar * message)
{
	gchar *base_dir = get_base_dir(filename);
	gint len = strlen(base_dir);
	GSList *commit = NULL;
	GSList *tmp = NULL;
	const gchar *argv[] = { "git", "commit", "-m", MESSAGE, "--", FILE_LIST, NULL };
	gint ret;

	g_return_val_if_fail(base_dir, -1);

	for (tmp = list; tmp != NULL; tmp = g_slist_next(tmp))
	{
		commit = g_slist_prepend(commit, (gchar *) tmp->data + len + 1);
	}

	ret = execute_custom_command(base_dir, argv, NULL, NULL, NULL, base_dir, commit, message);
	g_slist_free(commit);
	g_free(base_dir);
	return ret;
}
Exemple #4
0
int
main (int argc, char *argv[])
{
  /* These have been moved from global to local variables */
  /* this reduces binary size and improves code structure. RP */
  /* Also size of home_page and help_page reduced from 257. RP 11-mar-04 */
  char home_page[20] = "index.htm";
  char help_page[20] = "help.htm";
  char base_dir[257];

  char *showcommand = 0;
  char *oldscreen;
  int oldcursorx = wherex (), oldcursory = wherey ();
  int i;			/* counter for loop */
  int forcemono = 0, fancyscheme = 0;
  int AsciiExtendedChars = 1;
  int codepage = 0;

  cat = catopen("htmlhelp", 0);

  if (getenv ("HELPPATH") == NULL)
    {
      get_base_dir (base_dir, argv[0]);
      strcat (base_dir, "..\\help\\"); /* default location */

      if (lang_add(base_dir, home_page) != 0)
      {
         char testpath[257];
         get_base_dir (base_dir, argv[0]);
         strcat (base_dir, "..\\help\\"); /* bookshelf location */

         strcpy(testpath, base_dir);
         strcat(testpath, home_page);
         if (checkForFile(testpath) != 0)
         {
            get_base_dir (base_dir, argv[0]); /* try same dir as exe */
            strcpy(testpath, base_dir);
            strcat(testpath, home_page);
            if (checkForFile(testpath) != 0)
            {
               *base_dir = '\0'; /* try current dir */
               strcpy(testpath, home_page);
               if (checkForFile(testpath) != 0)
               {
                  get_base_dir (base_dir, argv[0]);
                  strcat (base_dir, "..\\help\\");
               }
            }
         }
      }
    }
  else
    {
      strcpy (base_dir, getenv ("HELPPATH"));
      if (lang_add(base_dir, home_page) != 0)
      {
         strcpy (base_dir, getenv ("HELPPATH"));
         if (base_dir[0] != '\0')
         {
            if (base_dir[strlen(base_dir)-1] != '\\' &&
                base_dir[strlen(base_dir)-1] != '/');
	            strcat (base_dir, "\\");
         }
      }

    }

  if (getenv ("HELPCMD"))
    {
      if (strstr (getenv ("HELPCMD"), "/A"))
	AsciiExtendedChars = 0;
      if (strstr (getenv ("HELPCMD"), "/M"))
	forcemono = 1;
      if (strstr (getenv ("HELPCMD"), "/F1"))
         fancyscheme = 1;
      if (strstr (getenv ("HELPCMD"), "/F2"))
         fancyscheme = 2;
    }

  for (i = 1; i < argc; i++)
    {
      if (argv[i][0] == '/')
	{
	  switch (argv[i][1])
	    {

	    default:
	      printf ("%s -- %s\n", hcatInvArg, argv[i] + 1);
		   printf ("%s\n", hcatHowGetUsage);
         break;

	    case '?':
	      show_usage ();
	      return 0;

	    case 'a':
	    case 'A':
	      if (argv[i][2] == 0)
		AsciiExtendedChars = 0;
	      break;

       case 'c':
       case 'C':
       codepage = atoi(argv[i]+2);
       if (codepage == 0)
       {
          printf("%s (/Cnnn)\n", hcatCodepagePlease);
          printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages);
          return 0;
       }
       break;

	    case 'f':
	    case 'F':
	      fancyscheme = atoi(argv[i] + 2);
         if (fancyscheme < 1 || fancyscheme > 2)
            fancyscheme = 1;
         break;

	    case 'h':
	    case 'H':
	      if (argv[i][2] == 0)	/* Only put /h or /H */
		{
        printf ("%s\n", hcatInvArg);
		  printf ("%s\n", hcatHowGetUsage);
		  return 0;
		}
	      else
		{
           strncpy(help_page, argv[i] + 2, 14);
		}
	      break;

	    case 'l':
	    case 'L':
	      strcat (base_dir, argv[i] + 2);
	      checkForFile (base_dir);
	      get_home_page (home_page, base_dir);
	      get_base_dir (base_dir, base_dir);
	      break;

	    case 'm':
	    case 'M':
	      if (argv[i][2] == '\0')
		forcemono = 1;
	      else
		{
		  printf ("%s -- %s\n", hcatInvArg, argv[i] + 1);
		  printf ("%s\n", hcatHowGetUsage);
		  return 0;
		}
	      break;

	    case 'o':		/* Override index file path/name */
	    case 'O':
	      strcpy (base_dir, argv[i] + 2);
         if (lang_add(base_dir, home_page) != 0)
         {
	         strcpy (base_dir, argv[i] + 2);
	         checkForFile (base_dir);
	         get_home_page (home_page, base_dir);
	         get_base_dir (base_dir, base_dir);
         }
	    }
	}
      else if (showcommand == 0)
	{
	  showcommand = malloc (strlen (argv[i]) + 11);
	  if (!showcommand)
	    {
	      printf ("%s\n", hcatMemErr);
	      return 0;
	    }
	  sprintf (showcommand, "#%s", argv[i]);
	}
      else
	{
	  printf ("%s\n", hcat2ManyTopics);
	  printf ("%s\n", hcatHowGetUsage);
	  return 0;
	}
    }

  if (fancyscheme && forcemono)
  {
     printf ("%s\n", hcatFwithN);
	  printf ("%s\n", hcatHowGetUsage);
     return 0;
  }

  /* detect (or force) the codepage to select UTF-8 and entity
     substition support */
  if (selectCodepage(codepage) != codepage && codepage > 0)
  {
     printf("%s\n", hcatCodepageNotSupported);
     printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages);
     return 0;
  }

  /* initialise user interface */
  conio_init (forcemono);

  if (forcemono == 0)
    {
      oldscreen = malloc (W * H * 2);
      if (oldscreen)
	save_window (X, Y, W, H, oldscreen);
    }

  if (MonoOrColor == COLOR_MODE && fancyscheme == 0)
    {
      TEXT_COLOR = C_TEXT_COLOR;
      BOLD_COLOR = C_BOLD_COLOR;
      ITALIC_COLOR = C_ITALIC_COLOR;
      BORDER_BOX_COLOR = C_BORDER_COLOR;
      BORDER_TEXT_COLOR = C_BORDER_TEXT_COLOR;
      LINK_COLOR = C_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = C_LINK_HIGHLIGHTED_COLOR;
    }
  else if (MonoOrColor == COLOR_MODE && fancyscheme == 1)
    {
      TEXT_COLOR = F1_TEXT_COLOR;
      BOLD_COLOR = F1_BOLD_COLOR;
      ITALIC_COLOR = F1_ITALIC_COLOR;
      BORDER_BOX_COLOR = F1_BORDER_COLOR;
      BORDER_TEXT_COLOR = F1_BORDER_TEXT_COLOR;
      LINK_COLOR = F1_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = F1_LINK_HIGHLIGHTED_COLOR;
    }
  else if (MonoOrColor == COLOR_MODE && fancyscheme == 2)
    {
      TEXT_COLOR = F2_TEXT_COLOR;
      BOLD_COLOR = F2_BOLD_COLOR;
      ITALIC_COLOR = F2_ITALIC_COLOR;
      BORDER_BOX_COLOR = F2_BORDER_COLOR;
      BORDER_TEXT_COLOR = F2_BORDER_TEXT_COLOR;
      LINK_COLOR = F2_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = F2_LINK_HIGHLIGHTED_COLOR;
    }
  else
    {
      TEXT_COLOR = M_TEXT_COLOR;
      BOLD_COLOR = M_BOLD_COLOR;
      ITALIC_COLOR = M_ITALIC_COLOR;
      BORDER_BOX_COLOR = M_BORDER_COLOR;
      BORDER_TEXT_COLOR = M_BORDER_TEXT_COLOR;
      LINK_COLOR = M_LINK_COLOR;
      LINK_HIGHLIGHTED_COLOR = M_LINK_HIGHLIGHTED_COLOR;
    }
  if (AsciiExtendedChars == 0)
    {
      strcpy (Border22f, "+-+( )+-+");
      strcpy (Border22if, "+-+( )+-+");
      BarBlock1 = '.';
      BarBlock2 = '#';
    }
  show_mouse ();
  move_mouse (80, 25);
  drawmenu ();
  html_view (showcommand, base_dir, home_page, help_page);
  free (showcommand);
  hide_mouse ();
  if ((oldscreen != 0) && (forcemono == 0))
    {
      load_window (X, Y, W, H, oldscreen);
      free (oldscreen);
    }
  conio_exit ();
  gotoxy (oldcursorx, oldcursory);

  return 0;
}
Exemple #5
0
static void test_symboliclink(void)
{
    NTSTATUS status;
    UNICODE_STRING str, target;
    OBJECT_ATTRIBUTES attr;
    HANDLE dir, link, h;
    IO_STATUS_BLOCK iosb;

    /* No name and/or no attributes */
    InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
    SYMLNK_TEST_CREATE_OPEN_FAILURE2(NULL, "", "", STATUS_ACCESS_VIOLATION, STATUS_INVALID_PARAMETER)

    status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, NULL);
    ok(status == STATUS_ACCESS_VIOLATION,
       "NtCreateSymbolicLinkObject should have failed with STATUS_ACCESS_VIOLATION got(%08x)\n", status);
    status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL);
    ok(status == STATUS_INVALID_PARAMETER,
       "NtOpenSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);

    /* No attributes */
    pRtlCreateUnicodeStringFromAsciiz(&target, "\\DosDevices");
    status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, NULL, &target);
    ok(status == STATUS_SUCCESS || status == STATUS_ACCESS_VIOLATION, /* nt4 */
       "NtCreateSymbolicLinkObject failed(%08x)\n", status);
    pRtlFreeUnicodeString(&target);
    if (!status) pNtClose(h);

    InitializeObjectAttributes(&attr, NULL, 0, 0, NULL);
    status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
    ok(status == STATUS_INVALID_PARAMETER ||
       broken(status == STATUS_SUCCESS),  /* nt4 */
       "NtCreateSymbolicLinkObject should have failed with STATUS_INVALID_PARAMETER got(%08x)\n", status);
    if (!status) pNtClose(h);
    status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr);
    ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
       "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);

    /* Bad name */
    pRtlCreateUnicodeStringFromAsciiz(&target, "anywhere");
    InitializeObjectAttributes(&attr, &str, 0, 0, NULL);

    pRtlCreateUnicodeStringFromAsciiz(&str, "");
    status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
    ok(status == STATUS_SUCCESS, "Failed to create SymbolicLink(%08x)\n", status);
    status = pNtOpenSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr);
    ok(status == STATUS_OBJECT_PATH_SYNTAX_BAD,
       "NtOpenSymbolicLinkObject should have failed with STATUS_OBJECT_PATH_SYNTAX_BAD got(%08x)\n", status);
    pNtClose(link);
    pRtlFreeUnicodeString(&str);

    pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
    status = pNtCreateSymbolicLinkObject(&h, SYMBOLIC_LINK_QUERY, &attr, &target);
    todo_wine ok(status == STATUS_OBJECT_TYPE_MISMATCH,
                 "NtCreateSymbolicLinkObject should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
    pRtlFreeUnicodeString(&str);
    pRtlFreeUnicodeString(&target);

    SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "BaseNamedObjects", "->Somewhere", STATUS_OBJECT_PATH_SYNTAX_BAD)
    SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
    SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\\\BaseNamedObjects", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
    SYMLNK_TEST_CREATE_OPEN_FAILURE(&h, "\\BaseNamedObjects\\\\om.c-test", "->Somewhere", STATUS_OBJECT_NAME_INVALID)
    SYMLNK_TEST_CREATE_OPEN_FAILURE2(&h, "\\BaseNamedObjects\\om.c-test\\", "->Somewhere",
                                     STATUS_OBJECT_NAME_INVALID, STATUS_OBJECT_PATH_NOT_FOUND)


    /* Compound test */
    if (!(dir = get_base_dir()))
    {
        win_skip( "couldn't find the BaseNamedObjects dir\n" );
        return;
    }

    InitializeObjectAttributes(&attr, &str, 0, dir, NULL);
    pRtlCreateUnicodeStringFromAsciiz(&str, "test-link");
    pRtlCreateUnicodeStringFromAsciiz(&target, "\\DosDevices");
    status = pNtCreateSymbolicLinkObject(&link, SYMBOLIC_LINK_QUERY, &attr, &target);
    ok(status == STATUS_SUCCESS, "Failed to create SymbolicLink(%08x)\n", status);
    pRtlFreeUnicodeString(&str);
    pRtlFreeUnicodeString(&target);

    pRtlCreateUnicodeStringFromAsciiz(&str, "test-link\\NUL");
    status = pNtOpenFile(&h, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN);
    todo_wine ok(status == STATUS_SUCCESS, "Failed to open NUL device(%08x)\n", status);
    pRtlFreeUnicodeString(&str);

    pNtClose(h);
    pNtClose(link);
    pNtClose(dir);
}
Exemple #6
0
static void test_name_collisions(void)
{
    NTSTATUS status;
    UNICODE_STRING str;
    OBJECT_ATTRIBUTES attr;
    HANDLE dir, h, h1, h2;
    DWORD winerr;
    LARGE_INTEGER size;

    InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
    pRtlCreateUnicodeStringFromAsciiz(&str, "\\");
    DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_COLLISION)
    InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, 0, NULL);

    DIR_TEST_CREATE_FAILURE(&h, STATUS_OBJECT_NAME_EXISTS)
    pNtClose(h);
    status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
    ok(status == STATUS_OBJECT_TYPE_MISMATCH,
       "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
    pRtlFreeUnicodeString(&str);

    pRtlCreateUnicodeStringFromAsciiz(&str, "\\??\\PIPE\\om.c-mutant");
    status = pNtCreateMutant(&h, GENERIC_ALL, &attr, FALSE);
    ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_OBJECT_PATH_NOT_FOUND,
       "NtCreateMutant should have failed with STATUS_OBJECT_TYPE_MISMATCH got(%08x)\n", status);
    pRtlFreeUnicodeString(&str);

    if (!(dir = get_base_dir()))
    {
        win_skip( "couldn't find the BaseNamedObjects dir\n" );
        return;
    }
    pRtlCreateUnicodeStringFromAsciiz(&str, "om.c-test");
    InitializeObjectAttributes(&attr, &str, OBJ_OPENIF, dir, NULL);
    h = CreateMutexA(NULL, FALSE, "om.c-test");
    ok(h != 0, "CreateMutexA failed got ret=%p (%d)\n", h, GetLastError());
    status = pNtCreateMutant(&h1, GENERIC_ALL, &attr, FALSE);
    ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
       "NtCreateMutant should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
    h2 = CreateMutexA(NULL, FALSE, "om.c-test");
    winerr = GetLastError();
    ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
       "CreateMutexA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
    pNtClose(h);
    pNtClose(h1);
    pNtClose(h2);

    h = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
    ok(h != 0, "CreateEventA failed got ret=%p (%d)\n", h, GetLastError());
    status = pNtCreateEvent(&h1, GENERIC_ALL, &attr, FALSE, FALSE);
    ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
       "NtCreateEvent should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
    h2 = CreateEventA(NULL, FALSE, FALSE, "om.c-test");
    winerr = GetLastError();
    ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
       "CreateEventA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
    pNtClose(h);
    pNtClose(h1);
    pNtClose(h2);

    h = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
    ok(h != 0, "CreateSemaphoreA failed got ret=%p (%d)\n", h, GetLastError());
    status = pNtCreateSemaphore(&h1, GENERIC_ALL, &attr, 1, 2);
    ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
       "NtCreateSemaphore should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
    h2 = CreateSemaphoreA(NULL, 1, 2, "om.c-test");
    winerr = GetLastError();
    ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
       "CreateSemaphoreA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
    pNtClose(h);
    pNtClose(h1);
    pNtClose(h2);

    h = pCreateWaitableTimerA(NULL, TRUE, "om.c-test");
    ok(h != 0, "CreateWaitableTimerA failed got ret=%p (%d)\n", h, GetLastError());
    status = pNtCreateTimer(&h1, GENERIC_ALL, &attr, NotificationTimer);
    ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
       "NtCreateTimer should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
    h2 = pCreateWaitableTimerA(NULL, TRUE, "om.c-test");
    winerr = GetLastError();
    ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
       "CreateWaitableTimerA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
    pNtClose(h);
    pNtClose(h1);
    pNtClose(h2);

    h = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
    ok(h != 0, "CreateFileMappingA failed got ret=%p (%d)\n", h, GetLastError());
    size.u.LowPart = 256;
    size.u.HighPart = 0;
    status = pNtCreateSection(&h1, SECTION_MAP_WRITE, &attr, &size, PAGE_READWRITE, SEC_COMMIT, 0);
    ok(status == STATUS_OBJECT_NAME_EXISTS && h1 != NULL,
       "NtCreateSection should have succeeded with STATUS_OBJECT_NAME_EXISTS got(%08x)\n", status);
    h2 = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, "om.c-test");
    winerr = GetLastError();
    ok(h2 != 0 && winerr == ERROR_ALREADY_EXISTS,
       "CreateFileMappingA should have succeeded with ERROR_ALREADY_EXISTS got ret=%p (%d)\n", h2, winerr);
    pNtClose(h);
    pNtClose(h1);
    pNtClose(h2);

    pRtlFreeUnicodeString(&str);
    pNtClose(dir);
}
Exemple #7
0
int main(int argc, char* argv[]) {
    init_random_gen();
    //SDL init;
    std::cout<<"init sdl"<<std::endl;
    if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_OPENGL|SDL_INIT_TIMER)==-1) {
        std::cerr<<"sdl init failed..."<<SDL_GetError()<<std::endl;
        return 1;
    }

    IMG_Init(IMG_INIT_PNG);

    std::cout<<"init video"<<std::endl;
    screen=SDL_SetVideoMode(SCREEN_W,SCREEN_H,SCREEN_DEPTH,SDL_OPENGL|SDL_DOUBLEBUF);
    if (!screen) {
        std::cerr<<"video init failed..."<<std::endl;
        return 1;
    }
    SDL_WM_SetCaption("FrEEsIegE FiGHt",NULL);
    TextureIds texture_ids=init_opengl(screen->w,screen->h,N_TEXTURE);

    //object init
    std::string base_dir=get_base_dir();
    SpriteCollection spr_coll(base_dir+"sprites.cfg",base_dir+"anims.cfg",base_dir,texture_ids);
    std::cout<<spr_coll<<std::endl;

    Background background(&spr_coll);
    Foreground foreground(&spr_coll);
    LifeBar life_bar1(&spr_coll,PLAYER_1);
    LifeBar life_bar2(&spr_coll,PLAYER_2);
    BattleField battlefield(&spr_coll,&life_bar1,&life_bar2,&foreground);

    //mutex timer init
    counter_reset_mutex=SDL_CreateMutex();
    SDL_TimerID counter_reset_id=SDL_AddTimer(1000,counter_reset_callback,NULL);

    bool quit=false;
    SDL_Event event;
    Uint32 ticks=SDL_GetTicks();
    while (!quit) {
        //draw
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        background.draw();
        life_bar1.draw();
        life_bar2.draw();
        battlefield.refresh();
        battlefield.draw();
        foreground.draw();
        SDL_GL_SwapBuffers();
        SDL_Flip(screen);
        //logic

        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_KEYDOWN:
                if (event.key.keysym.sym!=SDLK_ESCAPE) {
                    switch (event.key.keysym.sym) {
                    //unit spawn keys
                    case SDLK_a:
                        battlefield.spawn(SOLDIER,PLAYER_1);
                        break;
                    case SDLK_q:
                        battlefield.spawn(SOLDIER,PLAYER_2);
                        break;
                    case SDLK_z:
                        battlefield.spawn(DRUID,PLAYER_1);
                        break;
                    case SDLK_s:
                        battlefield.spawn(DRUID,PLAYER_2);
                        break;
                    case SDLK_e:
                        battlefield.spawn(KNIGHT,PLAYER_1);
                        break;
                    case SDLK_d:
                        battlefield.spawn(KNIGHT,PLAYER_2);
                        break;
                    case SDLK_r:
                        battlefield.spawn(GOLEM,PLAYER_1);
                        break;
                    case SDLK_f:
                        battlefield.spawn(GOLEM,PLAYER_2);
                        break;
                    case SDLK_t:
                        battlefield.spawn(PLANT,PLAYER_1);
                        break;
                    case SDLK_g:
                        battlefield.spawn(PLANT,PLAYER_2);
                        break;
                    case SDLK_y:
                        battlefield.spawn(DRAGON,PLAYER_1);
                        break;
                    case SDLK_h:
                        battlefield.spawn(DRAGON,PLAYER_2);
                        break;
                    case SDLK_u:
                        battlefield.spawn(FLOWER,PLAYER_2);
                        break;
                    case SDLK_j:
                        battlefield.spawn(FLOWER,PLAYER_1);
                        break;
                    case SDLK_o:
                        battlefield.spawn(VETERAN,PLAYER_2);
                        break;
                    case SDLK_l:
                        battlefield.spawn(VETERAN,PLAYER_1);
                        break;
                    default:
                        break;
                    }
                    break;
                }
            case SDL_QUIT:
                quit=true;
                break;
            default:
                break;
            }
        }

        while (ticks>(SDL_GetTicks()-1000/FPS)) SDL_Delay(3);
        ticks=SDL_GetTicks();

        current_fps++;
    }

    SDL_RemoveTimer(counter_reset_id);
    SDL_DestroyMutex(counter_reset_mutex);

    IMG_Quit();

    SDL_Quit();
    return 0;
}
Exemple #8
0
int
html_view_internal (struct eventState *pes, char *base_dir, char *home_page)
{
  int i;

  if (pes->link_text != 0)
    {
      statusbar (hcatStatusLooking);
      if (*pes->link_text == '#')
	{
	  char *anchor;

	  if (strnicmp (pes->link_text + 1, HTMLHELP_INTERNAL_SEARCHLINK,
			strlen (HTMLHELP_INTERNAL_SEARCHLINK)) == 0)
	    {
	      /* Internal search engine link */
	      anchor = pes->body_start + atoi (pes->link_text +
					       strlen
					       (HTMLHELP_INTERNAL_SEARCHLINK)
					       + 1);
	    }
	  else
	    {
	      sprintf (pes->text_holder, "<a name=\"%.*s\"",
		       link_length (pes->link_text + 1), pes->link_text + 1);
	      anchor = strstr (pes->body_start, pes->text_holder);
	    }

	  if (anchor)
	    {
	      /* Locate start of line. */
	      while (anchor != pes->body_start && *anchor != '\n')
		anchor--;

	      if (*anchor == '\n')
		anchor++;

	      /* Move to this line, just near top of screen */
         if (!pes->first_time)
            addBookmark(pes);
	      pes->seek_base = anchor;
	      pes->seek_cnt = -1;
         pes->clink = 0; /* RP - Added 5.3.2 */
	      pes->link_text = 0;
	      *pes->text_holder = 0;
	      statusbar (NULL);
	      return NAVIGATE_DONT;
	    }
	  else
	    {
	      int triedasfile = 0;
         int tryexact = 1;
	      sprintf (pes->text_holder, "%.*s",
		       link_length (pes->link_text + 1), pes->link_text + 1);
	      strlwr (pes->text_holder);
		   write_string (TEXT_COLOR, X + strlen(hcatStatusLooking) + 3, TY,
				                       hcatStatusEscape);
	      do
		{

		  pes->p = pes->body_start;
		  while ((pes->p = strstr (pes->p, "<a")) != 0)
		    {
		      static struct event ev;
		      get_event (&ev, EV_KEY | EV_NONBLOCK);
		      if (ev.ev_type == EV_KEY && ev.key == 27)
			{
			  pes->link_text = 0;
           show_error(hcatUserAborted);
			  return NAVIGATE_DONT;
			}

		      pes->p = strchr (pes->p, '>');
		      if (pes->p)
			{
			  ++(pes->p);
			  if ((strnicmp(pes->p, pes->text_holder,
			                        strlen (pes->text_holder)) == 0) &&
                (pes->p[strlen(pes->text_holder)] == '<' || !tryexact))
			    {
			      while (pes->p != pes->body_start &&
				     strncmp (pes->p, "<a", 2))
				pes->p--;

			      pes->p = strstr (pes->p, "href=");
			      if (pes->p != 0)
				{
				  pes->p += 6;
				  if (*pes->p == '\"')
				    pes->p++;

				  if (*pes->p == '#')
				    break;

				  if (prepare_link (pes))
				    {
                  if (tryexact == 0)
                     show_error(hcatNoExactFound);
				      return NAVIGATE_LINK;
				    }
				}
			    }
			}
		    }
		  if (triedasfile == 0)
		    {
		      int undostrcat = strlen (base_dir);
		      if (base_dir[strlen (base_dir) - 1] != '\\'
			  && base_dir[0] != 0)
			strcat (base_dir, "\\");
		      strcat (base_dir, pes->text_holder);
		      if (checkForFile (base_dir))
			{
			  /* Didn't work */
			  base_dir[undostrcat] = '\0';
			}
		      else
			{
			  if (pes->first_time)
			    pes->hidden = 1;
			  get_home_page (home_page, base_dir);
			  get_base_dir (base_dir, base_dir);
			  return NAVIGATE_HOME;
			}
		      triedasfile = 1;
		    }
		  else
		    {
            /* don't try to match end with the < */
            if (tryexact)
            {
               tryexact = 0;
            }
            else
            {
		         pes->p = pes->text_holder + strlen (pes->text_holder) - 1;
		         if (*pes->p > 'a')
			         --(*pes->p);
		         else
			         *pes->p = 0;
            }
		    }
		}
	      while (*(pes->text_holder) != 0);
	    }
     statusbar (NULL);

	  sprintf (pes->text_holder, "%s '%.*s'", hcatCouldntFind,
		   link_length (pes->link_text + 1), pes->link_text + 1);
	  show_error (pes->text_holder);
	  pes->link_text = 0;
	  *(pes->text_holder) = 0;
	  return NAVIGATE_DONT;
	}
      else if (prepare_link (pes))
	return NAVIGATE_LINK;

      pes->link_text = 0;
    }

  if (pes->first_time)
  {
     drawmenu();
     save_window (X, Y, W, H, pes->screen_buf);
     pes->first_time = 0;
  }

  if (pes->seek_cnt != 0)
    {
      if (pes->seek_cnt <= 0)
	{
	  i = -pes->seek_cnt;
	  pes->p = pes->seek_base - 1;
	  if (*pes->p == '\n')
	    pes->p--;

	  for (; (pes->p != pes->body_start); pes->p--)
	    if (*pes->p == '\n')
	      {
		i--;
		if (i == 0)
		  {
		    pes->p++;
		    break;
		  }
	      }
	  pes->top = pes->p;
	}
      else if (pes->seek_cnt > 0)
	{
	  i = pes->seek_cnt;
	  pes->p = pes->seek_base;
	  for (; pes->p != pes->body_end; pes->p++)
	    if (*pes->p == '\n')
	      {
		i--;
		if (i == 0)
		  {
		    pes->p++;
		    break;
		  }
	      }

	  if (pes->p == pes->body_end)
	    {
	      pes->seek_base = pes->body_end - 1;
	      pes->seek_cnt = -1;
	      return NAVIGATE_DONT;
	    }

	  pes->top = pes->p;
	}
      pes->seek_cnt = 0;
    }

  if (pes->maxtop != 0)
    pes->barpos = ((pes->top - pes->body_start) * BARLEN) / pes->maxtop;
  else
    pes->barpos = BARLEN - 1;

  if (pes->barpos >= BARLEN || pes->barpos < 0)	/* <0 fix - RP */
    pes->barpos = BARLEN - 1;

  if (pes->bar_hooked)
    {
      pes->seek_base = pes->top;
      if (pes->forced_barpos == 0)
	{
	  pes->top = pes->body_start;
	  pes->barpos = 0;
	}
      else if (pes->forced_barpos == BARLEN - 1
	       && pes->barpos != pes->forced_barpos)
	{
	  pes->old_barpos = pes->barpos;
	  pes->seek_base = pes->body_end;
	  pes->seek_cnt = -N;
	  return NAVIGATE_DONT;
	}
      else if (pes->forced_barpos < pes->barpos
	       && pes->forced_barpos < pes->old_barpos)
	{
	  pes->old_barpos = pes->barpos;
	  pes->seek_cnt = -1;
	  return NAVIGATE_DONT;
	}
      else if (pes->forced_barpos > pes->barpos
	       && pes->forced_barpos > pes->old_barpos)
	{
	  pes->old_barpos = pes->barpos;
	  pes->seek_cnt = +1;
	  return NAVIGATE_DONT;
	}
    }

  pes->old_barpos = pes->barpos;
  if (pes->top != pes->old_top)
    pes->force_redraw = 1;

  /* ------ Display processing ------------------------------------ */
  displayProcess (pes);

  /* ------ Event processing -------------------------------------- */
  return processEvents (pes);
}