int
save_game()
{
    register FILE *savef;
    register int c;
    char buf[LINELEN];

    /*
     * get file name
     */
    mpos = 0;
    if (file_name[0] != '\0')
    {
	msg("Save file (%s)? ", file_name);
	do
	{
	    c = readchar();
		if (c == ESCAPE) { msg(""); return(0); }
	} while (c != 'n' && c != 'N' && c != 'y' && c != 'Y');
	mpos = 0;
	if (c == 'y' || c == 'Y')
	{
	    msg("File name: %s", file_name);
	    goto gotfile;
	}
    }

    do
    {
	msg("File name: ");
	mpos = 0;
	buf[0] = '\0';
	if (get_str(buf, msgw) == QUIT)
	{
	    msg("");
	    return FALSE;
	}
	strcpy(file_name, buf);
gotfile:
	if ((savef = fopen(file_name, "w")) == NULL)
	    msg(strerror(errno));	/* fake perror() */
    } while (savef == NULL);

    /*
     * write out encrpyted file (after a stat)
     * The fwrite is to force allocation of the buffer before the write
     */
    if (save_file(savef) == FALSE) {
	msg("Cannot create save file.");
	md_unlink(file_name);
	return(FALSE);
    }
    else return(TRUE);
}
Beispiel #2
0
static void
ar_check_ttl_expired(pmda md)
{
  p_md_obj ptr = md_first(md);

  while (ptr)
    {
      __ar_vrp arp = (__ar_vrp) ptr->ptr;
      if ( arp->ttl == 0 )
        {
          p_md_obj s_ptr = ptr->next;
          md_unlink(md, ptr);
          ptr = s_ptr;
          continue;
        }
      ptr = ptr->next;
    }
}
Beispiel #3
0
int
ar_remove(pmda md, uint32_t opt)
{
  p_md_obj ptr = md_first(md);

  while (ptr)
    {
      __ar_vrp arp = (__ar_vrp) ptr->ptr;
      if ( arp->opt == opt )
        {
          p_md_obj s_ptr = ptr->next;
          md_unlink(md, ptr);
          ptr = s_ptr;
          continue;

        }
      ptr = ptr->next;
    }

  return 1;
}
Beispiel #4
0
/**
 * The dispatch method tokenizes the input and passes it
 * on to the correct method which was invoked.
 */
int dispatch(char* str, int client) {
    FILE* stream = fdopen(client, "w");
    char* cmd;
    cmd = strtok(str, "|");

    // There was no command...
    if(cmd == NULL)
        return 0;

    if(strcmp(cmd, "readdir") == 0) {
        printf("'readdir' received\n");
        md_readdir(stream, "/");
    } else if(strcmp(cmd, "mknod") == 0) {
        printf("'mknod' received\n");
        char* name = strtok(NULL, "|");
        int mode = atoi(strtok(NULL, "|"));
        md_mknod(name, mode);
    } else if(strcmp(cmd, "unlink") == 0) {
        printf("'unlink' received\n");
        char* name = strtok(NULL, "|");
        md_unlink(name);
    } else if(strcmp(cmd, "truncate") == 0) {
        char* name = strtok(NULL, "|");
	char* end;
        unsigned long long size = strtoull(strtok(NULL, "|"), &end, 10);
        printf("'truncate' '%s' '%llu' received\n", name, size);
        md_truncate(name, size);
    } else if(strcmp(cmd, "getattr") == 0) {
        char* name = strtok(NULL, "|");
        printf("'getattr' '%s' received\n", name);
        md_getattr(stream, name);
    } else if(strcmp(cmd, "getobjects") == 0) {
        printf("'getobjects' received\n");
        md_getobjects(stream);
    } else if(strcmp(cmd, "getfile") == 0) {
        printf("'getfile' received\n");
        char* name = strtok(NULL, "|");
        md_getfile(stream, name);
    } else if(strcmp(cmd, "chown") == 0) {
        printf("'chown' received\n");
        char* name = strtok(NULL, "|");
        uid_t uid = atoi(strtok(NULL, "|"));
        gid_t gid = atoi(strtok(NULL, "|"));
        md_chown(name, uid, gid);
    } else if(strcmp(cmd, "invalidate") == 0) {
        printf("'invalidate' received\n");
        int file = atoi(strtok(NULL, "|"));
        int store = atoi(strtok(NULL, "|"));
        md_invalidate(file, store);
    } else if(strcmp(cmd, "getinvalid") == 0) {
        printf("'getinvalid' received\n");
        char* hostname = strtok(NULL, "|");
        int port = atoi(strtok(NULL, "|"));
        md_getinvalid(stream, hostname, port);
    } else if(strcmp(cmd, "setvalid") == 0) {
        printf("'setvalid' received\n");
        int file = atoi(strtok(NULL, "|"));
        char* hostname = strtok(NULL, "|");
        int port = atoi(strtok(NULL, "|"));
        md_setvalid(file, hostname, port);
    }
    return 0;
}
Beispiel #5
0
int
g_build_math_packet(__g_handle hdl, char *field, char oper, pmda mdm,
    __g_math *ret, uint32_t flags)
{
  g_setjmp(0, "g_build_math_packet", NULL, NULL);
  int rt = 0;
  md_init(mdm, 16);

  __g_math p_math = (__g_math ) mdm->pos->ptr;
  __g_math math = (__g_math ) md_alloc(mdm, sizeof(_g_math));

  if (!math)
    {
      rt = 1;
      goto end;
    }

  math->flags |= flags;

  if ((rt = g_get_math_g_t_ptr(hdl, field, math, 0, p_math)))
    {
      goto end;
    }

  if (!(math->flags & F_MATH_TYPES))
    {
      rt = 6;
      goto end;
    }

  if (math->_m_p)
    {
      math->op_t = m_get_op_proc(oper, math);

      if ( NULL == math->op_t)
        {
          rt = 7;
          goto end;
        }

      /*if (oper == 0x7E)
       {
       math->flags |= F_MATH_IS_SQRT;

       }*/
    }

  if (ret)
    {
      *ret = math;
    }

  end:

  if (rt)
    {
      md_unlink(mdm, mdm->pos);
    }

  return rt;
}
int
restore(char *file, char **envp)
{
    FILE *inf;
    extern char **environ;
    char buf[LINELEN];
    STAT sbuf2;
    int oldcol, oldline;	/* Old number of columns and lines */

    if (strcmp(file, "-r") == 0)
	file = file_name;
    if ((inf = fopen(file, "r")) == NULL)
    {
	perror(file);
	return FALSE;
    }

    fflush(stdout);
    ENCREAD(buf, strlen(version) + 1, inf);
    if (strcmp(buf, version) != 0)
    {
	printf("Sorry, saved game is out of date.\n");
	return FALSE;
    }

    /*
     * Get the lines and columns from the previous game
     */

    ENCREAD(buf, 80, inf);
    sscanf(buf, "%d x %d\n", &oldline, &oldcol);
    stat(file, &sbuf2);
    fflush(stdout);

    /*
     * Set the new terminal and make sure we aren't going to a smaller screen.
     */

    initscr();

    if (MY_COLS < oldcol || MY_LINES < oldline) {
	printf("Cannot restart the game on a smaller screen.\n");
	return FALSE;
    }

    cw = newwin(MY_LINES, MY_COLS, 0, 0);
    mw = newwin(MY_LINES, MY_COLS, 0, 0);
    hw = newwin(MY_LINES, MY_COLS, 0, 0);
    msgw = newwin(4, MY_COLS, 0, 0);
    keypad(cw,1);
    keypad(msgw,1);

    mpos = 0;
    mvwprintw(cw, 0, 0, "%s: %s", file, ctime(&sbuf2.st_mtime));

    /*
     * defeat multiple restarting from the same place
     */
    if (!wizard) {
	if (sbuf2.st_nlink != 1) {
	    printf("Cannot restore from a linked file\n");
	    return FALSE;
	}
    }

    if (rs_restore_file(inf) != 0)
    {
        endwin();
        printf("\nCannot restore file\n");
        return(FALSE);
    }

    if (!wizard)
    {
        if (md_unlink(file) < 0) {
            fclose(inf); /* only close if system insists */
            if (md_unlink(file) < 0) {
                endwin();
                printf("\nCannot unlink file\n");
                return FALSE;
            }
        }
    }

    environ = envp;
    strcpy(file_name, file);
    setup();
    clearok(curscr, TRUE);
    touchwin(cw);
    srand(md_getpid());
    playit();
    return(FALSE);
    /*NOTREACHED*/
}