Ejemplo n.º 1
0
static void unexp(ApexParser *parser, size_t nExp, ...) {
    char buf[APEX_ERROR_MAX];
    va_list vl;
    size_t i;
    int lineno = apex_lexer_get_lineno(parser->lexer);
    ApexToken tk = GET_TOKEN(parser);
    const char *tkstr = apex_lexer_get_token_str(tk);
    
    if (nExp == 0) {
        sprintf(buf, "unexpected '%s'", tkstr);
    } else {
        sprintf(buf, "unexpected '%s', expecting '", tkstr);
    }

    va_start(vl, nExp);
    for (i = 0; i < nExp; i++) {
        ApexToken exp = va_arg(vl, ApexToken);
        const char *exp_str = apex_lexer_get_token_str(exp);

        if (i > 0) {
            sprintf(buf, "%s, '%s'", buf, exp_str);
        } else {
            sprintf(buf, "%s %s'", buf, exp_str);
        }
    }
    va_end(vl);
    apex_error_syntax("%s on line %d", buf, lineno);
}
Ejemplo n.º 2
0
/*
 * Load in all the class files.
 */ 
void load_classes( void )
{
    FILE       *fpList;
    const char *filename;
    char        fname     [ MAX_STRING_LENGTH ];
    char        classlist [ MAX_STRING_LENGTH ];
    int         stat;

    log_string( "Loading classes" );

    sprintf( classlist, "%s%s", CLASS_DIR, CLASS_LIST );
    if ( !( fpList = fopen( classlist, "r" ) ) )
    {
        perror( classlist );
        exit( 1 );
    }

    for ( ; ; )
    {
    	GET_TOKEN( fpList, filename, "$" );
	strcpy( fname, filename );
        if ( fname[0] == '$' )
          break;

        if ( fread_class( fname ) )
	    fputc( '.', stderr );
	else
	    bugf( "Cannot load class file: %s", fname );
    }
    fclose( fpList );

    fputc( '\n', stderr );
    return;
}
Ejemplo n.º 3
0
/* program
 * : module_spec
 * | program func_decl
 * | program import
 * | block
 */
static void program(ApexParser *parser) {
    ApexToken tk = NEXT_TOKEN(parser);
/*    module_spec(parser); */
     do {
        tk = GET_TOKEN(parser);
        switch (tk) {
        case APEX_TOKEN_IMPORT:
            import(parser);
            break;
        default:        
            block(parser);            
            break;
        }
        tk = GET_TOKEN(parser);
    } while (tk != APEX_TOKEN_EOS);
}
Ejemplo n.º 4
0
static int accept(ApexParser *parser, ApexToken tk) {
    if (GET_TOKEN(parser) != tk) {
        return 0;
    }
    parser->value = apex_lexer_get_value(parser->lexer);
    NEXT_TOKEN(parser);
    return 1;
}
Ejemplo n.º 5
0
static int expect(ApexParser *parser, ApexToken exp) {
    ApexToken tk = GET_TOKEN(parser);

    if (tk == exp) {
        parser->value = apex_lexer_get_value(parser->lexer);
        NEXT_TOKEN(parser);
        return 1;
    }
    unexp(parser, 1, exp);
    return 0;
}
Ejemplo n.º 6
0
/* This routine returns true if all the mandatory capabilities in
 * us appear in them.
 */
bool has_capabilities(const char *us, const char *them)
{
  const char *next;

  for (;;) {
    GET_TOKEN(us, next);

    if (*us == '+' && !my_has_capability(us+1, them, next-(us+1))) {
      return FALSE;
    }
    if (*next == '\0') {
      return TRUE;
    }

    us = next+1;
  }
}
Ejemplo n.º 7
0
/* This routine returns true if the capability in cap appears
 * in the capability list in capstr.  The capabilities in capstr
 * are allowed to start with a "+", but the capability in cap must not.
 */
static bool my_has_capability(const char *cap, const char *capstr,
			     const size_t cap_len)
{
  const char *next;

  fc_assert_ret_val(capstr != NULL, FALSE);

  for (;;) {
    GET_TOKEN(capstr, next);

    if (*capstr == '+') {
      capstr++;
    }
    if ((next-capstr == cap_len) && strncmp(cap, capstr, cap_len)==0) {
      return TRUE;
    }
    if (*next == '\0') {
      return FALSE;
    }

    capstr = next+1;
  }
}
Ejemplo n.º 8
0
nsresult
nsNNTPNewsgroupList::ParseLine(char *line, uint32_t * message_number)
{
  nsresult rv = NS_OK;
  nsCOMPtr <nsIMsgDBHdr> newMsgHdr;
  char *dateStr = nullptr;  // keep track of date str, for filters
  char *authorStr = nullptr; // keep track of author str, for filters

  if (!line || !message_number) {
    return NS_ERROR_NULL_POINTER;
  }

  char *next = line;

#define GET_TOKEN()                           \
  line = next;                                \
  next = (line ? PL_strchr (line, '\t') : 0); \
  if (next) *next++ = 0

  GET_TOKEN (); /* message number */
  *message_number = atol(line);

  if (atol(line) == 0) /* bogus xover data */
    return NS_ERROR_UNEXPECTED;

  m_newsDB->CreateNewHdr(*message_number, getter_AddRefs(newMsgHdr));

  NS_ASSERTION(newMsgHdr, "CreateNewHdr didn't fail, but it returned a null newMsgHdr");
  if (!newMsgHdr)
    return NS_ERROR_NULL_POINTER;

  GET_TOKEN (); /* subject */
  if (line) {
    const char *subject = line;  /* #### const evilness */
    uint32_t subjectLen = strlen(line);

    uint32_t flags = 0;
    // ### should call IsHeaderRead here...
    /* strip "Re: " */
    nsCString modifiedSubject;
    if (NS_MsgStripRE(&subject, &subjectLen, getter_Copies(modifiedSubject)))
      (void) newMsgHdr->OrFlags(nsMsgMessageFlags::HasRe, &flags);
    
    // this will make sure read flags agree with newsrc
    if (! (flags & nsMsgMessageFlags::Read))
      rv = newMsgHdr->OrFlags(nsMsgMessageFlags::New, &flags);

    rv = newMsgHdr->SetSubject(modifiedSubject.IsEmpty() ? subject : modifiedSubject.get());

    if (NS_FAILED(rv))
      return rv;
  }

  GET_TOKEN (); /* author */
  if (line) {
    authorStr = line;
    rv = newMsgHdr->SetAuthor(line);
    if (NS_FAILED(rv))
      return rv;
  }

  GET_TOKEN ();
  if (line) {
    dateStr = line;
    PRTime date;
    PRStatus status = PR_ParseTimeString (line, false, &date);
    if (PR_SUCCESS == status) {
      rv = newMsgHdr->SetDate(date); /* date */
      if (NS_FAILED(rv))
        return rv;
    }
  }

  GET_TOKEN (); /* message id */
  if (line) {
    char *strippedId = line;
    if (strippedId[0] == '<')
      strippedId++;
    char * lastChar = strippedId + PL_strlen(strippedId) -1;

    if (*lastChar == '>')
      *lastChar = '\0';

    rv = newMsgHdr->SetMessageId(strippedId);
    if (NS_FAILED(rv))
      return rv;
  }

  GET_TOKEN (); /* references */
  if (line) {
    rv = newMsgHdr->SetReferences(line);
    if (NS_FAILED(rv))
      return rv;
  }

  GET_TOKEN (); /* bytes */
  if (line) {
    uint32_t msgSize = 0;
    msgSize = (line) ? atol (line) : 0;

    rv = newMsgHdr->SetMessageSize(msgSize);
    if (NS_FAILED(rv)) return rv;
  }

  GET_TOKEN (); /* lines */
  if (line) {
    uint32_t numLines = 0;
    numLines = line ? atol (line) : 0;
    rv = newMsgHdr->SetLineCount(numLines);
    if (NS_FAILED(rv)) return rv;
  }

  GET_TOKEN (); /* xref */

  m_newHeaders.AppendObject(newMsgHdr);
  return NS_OK;
}
Ejemplo n.º 9
0
/*
 * Main function for doing the copying of bits
 */
int
TM_perform_transfer(nvlist_t *targs, void(*prog)(int))
{
	char *logfile = NULL, *buf = NULL, *cprefix;
	char *buf1 = NULL, *layout = NULL, *dbg;
	FILE *cpipe = NULL, *kbd_file;
	float ipercent, rem_percent, cpfiles;
	float calc_factor;
	int kbd = -1, kbd_layout;
	int rv = 0, i;
	struct file_list flist, *cflist;
	clock_t tm;
	struct stat st;
	char zerolist[PATH_MAX];

	if (pthread_mutex_lock(&tran_mutex) != 0) {
		Perror("Unable to acquire Transfer lock ");
		return (1);
	}

	if (nvlist_lookup_string(targs, "mountpoint", &mntpt) != 0) {
		Perror("Alternate root mountpoint not provided. Bailing. ");
		return (1);
	}

	if (prog == NULL) {
		progress = log_progress;
	} else {
		progress = prog;
	}

	logfile = malloc(PATH_MAX);
	if (logfile == NULL) {
		Perror("Malloc failed ");
		return (1);
	}

	(void) snprintf(logfile, PATH_MAX, "%s/%s", mntpt,
	    TM_LOGFILE_NAME);

	lof = fopen(logfile, "w+");
	if (lof == NULL) {
		Perror("Unable to open logfile ");
		goto error_done;
	}

	buf = malloc(BUF_SIZE);
	if (buf == NULL) {
		Perror("Malloc failed ");
		goto error_done;
	}

	buf1 = malloc(BUF_SIZE);
	if (buf1 == NULL) {
		Perror("Malloc failed ");
		goto error_done;
	}

	dbg = getenv("TM_DEBUG");
	if (dbg != NULL && strcmp(dbg, "1") == 0) {
		TM_enable_debug();
	}

	/*
	 * Set TMPDIR to avoid cpio depleting ramdisk space
	 */
	if (putenv(tmpenv) != 0) {
		Perror(tmpenv);
		goto error_done;
	}

	/*
	 * Zero length file list.
	 */
	(void) strlcpy(zerolist, mntpt, PATH_MAX);
	(void) strlcat(zerolist, "/flist.0length", PATH_MAX);
	if ((zerolength = fopen(zerolist, "w+")) == NULL) {
		Perror(zerolist);
		goto error_done;
	}

	tm = time(NULL);
	(void) strftime(buf, PATH_MAX, (char *)0, localtime(&tm));
	INFO_MSG2("-- Starting transfer process, %s --", buf);
	(void) chdir("/");
	CHECK_ABORT;

	(*progress)(0);
	percent = 0;
	opercent = 0;
	total_find_percent = (NUM_PREFIXES - 1) * FIND_PERCENT;

	/*
	 * Get the optimized libc overlay out of the way.
	 */
	if (umount("/lib/libc.so.1") != 0) {
		if (errno != EINVAL) {
			Perror("Can't unmount /lib/libc.so.1 ");
			goto error_done;
		}
	}
	CHECK_ABORT;
	INFO_MSG1("Building file lists for cpio");

	/*
	 * Do a file tree walk of all the mountpoints provided and
	 * build up pathname lists. Pathname lists of all mountpoints
	 * under the same prefix are aggregated in the same file to
	 * reduce the number of cpio invocations.
	 *
	 * This loop builds a linked list where each entry points to
	 * a file containing a pathname list and mentions other info
	 * like the mountpoint from which to copy etc.
	 */
	cprefix = "";
	flist.next = NULL;
	cflist = &flist;
	for (i = 0; cpio_prefixes[i].chdir_prefix != NULL; i++) {
		char *patt;
		regex_t re;

		CHECK_ABORT;
		DBG_MSG3("Cpio dir: %s, Chdir to: %s",
		    cpio_prefixes[i].cpio_dir,
		    cpio_prefixes[i].chdir_prefix);
		patt = cpio_prefixes[i].match_pattern;
		if (strcmp(cprefix,
		    cpio_prefixes[i].chdir_prefix) != 0 ||
		    patt != NULL ||
		    cpio_prefixes[i].clobber_files == 1 ||
		    cpio_prefixes[i].cpio_args != NULL) {

			cprefix = cpio_prefixes[i].chdir_prefix;
			cflist->next = (struct file_list *)
			    malloc(sizeof (struct file_list));
			cflist = cflist->next;
			cflist->next = NULL;
			(void) snprintf(cflist->name, PATH_MAX, "%s/flist%d",
			    mntpt, i);
			DBG_MSG2(" File list tempfile: %s", cflist->name);

			cflist->handle = fopen(cflist->name, "w+");
			if (cflist->handle == NULL) {
				Perror("Unable to open file list ");
				goto error_done;
			}

			cflist->chdir_prefix =
			    cpio_prefixes[i].chdir_prefix;
			if (patt != NULL) {
				DBG_MSG2(" Compiling regexp: %s", patt);
				if (patt[0] == '!') {
					negate = 1;
					patt++;
				} else {
					negate = 0;
				}
				if (regcomp(&re, patt,
				    REG_EXTENDED|REG_NOSUB) != 0) {
					Perror("Regexp error ");
					goto error_done;
				}
				mre = &re;
			} else {
				mre = NULL;
			}

			listfile = cflist->handle;
			cflist->clobber_files =
			    cpio_prefixes[i].clobber_files;
			if (cpio_prefixes[i].cpio_args != NULL) {
				cflist->cpio_args =
				    cpio_prefixes[i].cpio_args;
			} else {
				cflist->cpio_args = DEFAULT_CPIO_ARGS;
			}
		}

		INFO_MSG3("Scanning %s/%s", cflist->chdir_prefix,
		    cpio_prefixes[i].cpio_dir);
		(void) chdir(cflist->chdir_prefix);
		if (nftw(cpio_prefixes[i].cpio_dir, add_files, 10,
		    FTW_MOUNT|FTW_PHYS) < 0) {
			Perror("Nftw failed ");
			goto error_done;
		}
		(void) fflush(cflist->handle);
	}
	(void) fflush(zerolength);

	/*
	 * Now process each entry in the list. cpio is executed with the
	 * -V option where it prints a dot for each pathname processed.
	 * Since we already know the number of files we can show accurate
	 * percentage completion.
	 */
	INFO_MSG1("Beginning cpio actions ...");

	rem_percent = 95 - percent;
	ipercent = percent;
	cflist = flist.next;
	cpfiles = 0;
	opercent = 0;
	percent = 0;
	calc_factor = rem_percent / nfiles;
	while (cflist != NULL) {
		(void) fclose(cflist->handle);
		cflist->handle = NULL;
		CHECK_ABORT;
		if (cflist->clobber_files) {
			if (do_clobber_files(cflist->name) != 0) {
				goto error_done;
			}
		}

		(void) chdir(cflist->chdir_prefix);
		(void) snprintf(buf, PATH_MAX, "%s -%sV %s < %s",
		    CPIO, cflist->cpio_args, mntpt, cflist->name);
		DBG_MSG3("Executing: %s, CWD: %s", buf,
		    cflist->chdir_prefix);

		cpipe = popen(buf, "r");
		if (cpipe == NULL) {
			Perror("Unable to cpio files ");
			goto error_done;
		}

		while (!feof(cpipe)) {
			int ch = fgetc(cpipe);
			if (ch == '.') {
				cpfiles++;
				percent = (int)(cpfiles * calc_factor +
				    ipercent);
				if (percent - opercent >= 1) {
					if (progress != NULL) {
						(*progress)(percent);
					}
					opercent = percent;
				}
			}
			CHECK_ABORT;
		}
		if (ferror(cpipe)) {
			Perror(CPIO);
			goto error_done;
		}

		(void) fclose(cpipe);
		cpipe = NULL;

		(void) unlink(cflist->name);
		cflist->name[0] = '\0';
		cflist = cflist->next;
	}
	(*progress)(percent);
	cpipe = NULL;

	/*
	 * Process zero-length files if any.
	 */
	INFO_MSG1("Creating zero-length files");
	rewind(zerolength);
	while (fgets(buf, BUF_SIZE, zerolength) != NULL) {
		int fd;
		mode_t mod;
		uid_t st_uid, st_gid;
		char *token, *lasts;

		/* Get the newline out of the way */
		buf[strlen(buf) - 1] = '\0';

		/* Parse out ownership and perms */
		GET_TOKEN(token, lasts, buf, ",");
		mod = atoi(token);
		GET_TOKEN(token, lasts, NULL, ",");
		st_uid = atoi(token);
		GET_TOKEN(token, lasts, NULL, ",");
		st_gid = atoi(token);

		GET_TOKEN(token, lasts, NULL, ",");
		(void) snprintf(buf1, PATH_MAX, "%s/%s", mntpt, token);

		fd = open(buf1, O_WRONLY | O_CREAT | O_TRUNC, mod);
		if (fd != -1) {
			(void) fchown(fd, st_uid, st_gid);
			(void) close(fd);
			DBG_MSG2("Created file %s", buf1);
		} else {
			INFO_MSG1("Unable to create file:");
			Perror(buf1);
		}
	}
	(*progress)(97);

	CHECK_ABORT;
	INFO_MSG1("Extracting archive");
	(void) chdir(mntpt);
	(void) snprintf(buf, PATH_MAX, "%s e -so %s | %s -idum",
	    SZIP, ARCHIVE, CPIO);
	DBG_MSG3("Executing: %s, CWD: %s", buf, mntpt);
	if (system(buf) != 0) {
		Perror("Extracting archive failed ");
		goto error_done;
	}
	(*progress)(98);
	CHECK_ABORT;

	/*
	 * Check for the presence of skeleton.cpio before extracting it.
	 * This file may not be present in a Distro Constructor image.
	 */
	if (lstat(SKELETON, &st) == 0 && (S_ISREG(st.st_mode) ||
	    S_ISLNK(st.st_mode))) {
		INFO_MSG1("Extracting skeleton archive");
		(void) snprintf(buf, PATH_MAX, "%s -imu < %s", CPIO,
		    SKELETON, mntpt);
		DBG_MSG3("Executing: %s, CWD: %s", buf, mntpt);
		if (system(buf) != 0) {
			Perror("Skeleton cpio failed ");
			goto error_done;
		}
	}
	(*progress)(99);

	CHECK_ABORT;
	INFO_MSG1("Performing file operations");
	for (i = 0; i < NUM_FILEOPS_LIST; i++) {
		int rv;

		CHECK_ABORT;
		expand_symbols(fileops_list[i].src, buf, PATH_MAX);

		switch (fileops_list[i].op) {
			int op;

		case FILE_OP_UNLINK:
			DBG_MSG2("Unlink: %s", buf);
			(void) unlink(buf);
			rv = 0; /* unlink errors are non-fatal */
			break;

		case FILE_OP_RMDIR:
			DBG_MSG2("Rmdir: %s", buf);
			(void) rmdir(buf);
			rv = 0; /* Ignore rmdir errors for now */
			break;

		case FILE_OP_MKDIR:

			DBG_MSG2("Mkdir: %s", buf);
			rv = 0;
			if (lstat(buf, &st) == 0) {
				op = 0;
				if ((st.st_mode & S_IFMT)
				    != S_IFDIR) {
					rv = unlink(buf);
					op = 1;
				}
				if (rv == 0 && op) {
					rv = mkdir(buf,
					    fileops_list[i].perms);
				}
			} else {
				rv = mkdir(buf,
				    fileops_list[i].perms);
			}
			break;

		case FILE_OP_COPY:
			expand_symbols(fileops_list[i].dst, buf1,
			    PATH_MAX);
			rv = copyfile(buf, buf1);
			break;
		case FILE_OP_CHMOD:
			expand_symbols(fileops_list[i].dst, buf1,
			    PATH_MAX);
			rv = chmod(buf, fileops_list[i].perms);
			break;
		default:
			Perror("Unsupported file operation ");
			rv = 1;
			break;
		}
		if (rv != 0) {
			Perror("File ops error ");
			Perror(buf);
			goto error_done;
		}
	}

	CHECK_ABORT;
	INFO_MSG1("Fetching and updating keyboard layout");
	(void) chdir(mntpt);

	DBG_MSG2("Opening keyboard device: %s", KBD_DEVICE);
	kbd = open(KBD_DEVICE, O_RDWR);
	if (kbd < 0) {
		Perror("Error opening keyboard");
		goto error_done;
	}

	if (ioctl(kbd, KIOCLAYOUT, &kbd_layout)) {
		Perror("ioctl keyboard layout");
		goto error_done;
	}

	CHECK_ABORT;
	if ((layout = get_layout_name(kbd_layout)) == NULL) {
		goto error_done;
	}

	kbd_file = fopen(KBD_DEFAULTS_FILE, "a+");
	if (kbd_file == NULL) {
		Perror("Unable to open kbd defaults file ");
		goto error_done;
	}

	(void) fprintf(kbd_file, "LAYOUT=%s\n", layout);
	(void) fclose(kbd_file);
	DBG_MSG3("Updated keyboard defaults file: %s/%s", mntpt,
	    KBD_DEFAULTS_FILE);

	INFO_MSG2("Detected %s keyboard layout", layout);
	tm = time(NULL);
	(void) strftime(buf, PATH_MAX, (char *)0, localtime(&tm));
	INFO_MSG2("-- Completed transfer process, %s --", buf);

	(*progress)(100);

	goto done;
error_done:
	rv = 1;

done:
	if (lof != NULL)
		(void) fclose(lof);

	if (cpipe != NULL)
		(void) fclose(cpipe);

	free_flist(flist.next);

	if (logfile != NULL)
		free(logfile);

	if (kbd > 0)
		(void) close(kbd);

	if (buf != NULL)
		free(buf);

	if (buf1 != NULL)
		free(buf1);

	if (layout != NULL)
		free(layout);

	if (zerolength != NULL) {
		(void) fclose(zerolength);
		(void) unlink(zerolist);
	}

	do_abort = 0;
	(void) pthread_mutex_unlock(&tran_mutex);

	return (rv);
}
Ejemplo n.º 10
0
/*
 * New code for loading classes from file.
 */
bool fread_class( char *filename )
{
           FILE        *fp;
    static CLASS_TYPE   class_zero;
           CLASS_TYPE  *cclass;
     const char        *word;
           char         buf [ MAX_STRING_LENGTH ];
           bool         fMatch;
           int          stat;
           int          level;
           int          i;

    sprintf( buf, "%s%s", CLASS_DIR, filename );
    if ( !( fp = fopen( buf, "r" ) ) )
    {
        perror( buf );
        return FALSE;
    }

    strcpy( strArea, filename );
    fpArea = fp;

    cclass = (CLASS_TYPE *) alloc_mem ( sizeof( CLASS_TYPE ) );

    *cclass = class_zero;

    cclass->skill_level	 = (int *) alloc_mem( sizeof( int ) * MAX_SKILL );
    cclass->skill_adept	 = (int *) alloc_mem( sizeof( int ) * MAX_SKILL );
    cclass->skill_rating = (int *) alloc_mem( sizeof( int ) * MAX_SKILL );

    /* Initialize MAX_SPELL marker so noone can use it. */
    cclass->skill_level[MAX_SPELL] = MAX_LEVEL+1;

    for ( i = 0; i < MAX_SKILL; i++ )
    {
	cclass->skill_level[i] = L_APP;
	cclass->skill_adept[i] = 0;
    }

    for ( i = 0; i <= MAX_LEVEL; i++ )
    {
	cclass->title[i][0] = str_dup( "" );
	cclass->title[i][1] = str_dup( "" );
    }
	
    for ( i = 0; i < MAX_POSE; i++ )
    {
	cclass->pose[i][0] = str_dup( "" );
	cclass->pose[i][1] = str_dup( "" );
    }

    for ( ; ; )
    {
    	GET_TOKEN( fp, word, "End" );
	fMatch = FALSE;

	switch ( UPPER( word[0] ) )
	{
	case '*':
	    fMatch = TRUE;
	    fread_to_eol( fp );
	    break;

	case 'A':
            KEY( "AtrPrm", cclass->attr_prime, fread_number( fp, &stat ) );
	    break;

	case 'C':
	    break;

	case 'E':
	    if ( !str_cmp( word, "End" ) )
	    {
		fclose( fp );

		if ( !class_first )
		    class_first      = cclass;

		if ( class_last )
		    class_last->next = cclass;

		class_last           = cclass;

		fpArea = NULL;
		return TRUE;
	    }
	    break;

	case 'G':
            KEY( "Guild", cclass->guild, fread_number( fp, &stat ) );
	    break;

	case 'H':
            KEY( "Hpmin", cclass->hp_min, fread_number( fp, &stat ) );
            KEY( "Hpmax", cclass->hp_max, fread_number( fp, &stat ) );
	    break;

	case 'M':
            KEY( "Mana", cclass->fMana, fread_number( fp, &stat ) );
	    break;

	case 'N':
            SKEY( "Nm", cclass->name );
	    break;

	case 'P':
	    if ( !str_cmp( word, "Pose" ) )
	    {
		level = fread_number( fp, &stat );
		i     = fread_number( fp, &stat );

		if ( level < MAX_POSE )
		{
                    free_string( cclass->pose[level][i] );
                    cclass->pose[level][i] = fread_string( fp, &stat );
		}
		else
		    bugf( "Fread_class: invalid pose." );
		fMatch = TRUE;
	    }

	    break;

	case 'S':
            KEY( "SkllAdpt", cclass->max_adept, fread_number( fp, &stat ) );

	    if ( !str_cmp( word, "Skll" ) )
	    {
		int   sn;
		int   value1;
		int   value2;
		int   value3;

		value1 = fread_number( fp, &stat );
		value2 = fread_number( fp, &stat );
		value3 = fread_number( fp, &stat );
		word   = fread_word( fp, &stat );
		sn     = skill_lookup( word );
		if ( sn == -1 )
		{
		    bugf( "Fread_class: unknown skill: %s.", word );
		}
		else
		{
		    cclass->skill_level [sn] = value1;
		    cclass->skill_rating[sn] = value2;
		    cclass->skill_adept [sn] = value3;
		}
		fMatch = TRUE;
	    }

	    break;

	case 'T':
	    KEY( "Thac0", cclass->thac0_00, fread_number( fp, &stat ) );
	    KEY( "Thac47", cclass->thac0_47, fread_number( fp, &stat ) );

	    if ( !str_cmp( word, "Ttle" ) )
	    {
		i  = fread_number( fp, &stat );

		if ( i <= MAX_LEVEL )
		{
                    free_string( cclass->title[i][0] );
                    free_string( cclass->title[i][1] );
                    cclass->title[i][0] = fread_string( fp, &stat );
                    cclass->title[i][1] = fread_string( fp, &stat );
		}
		else
		    bugf( "Fread_class: too many titles." );
		fMatch = TRUE;
	    }

	    break;

	case 'W':
	    SKEY( "WhoNm", cclass->who_name );
	    KEY( "Wpn", cclass->weapon, fread_number( fp, &stat ) );
	    break;
	}

	if ( !fMatch )
	{
            bugf( "load_class_file: no match: %s", word );
	}
    }

    return FALSE;
}
Ejemplo n.º 11
0
/*
 * New code for loading clans from file.
 */
bool fread_clan( CLAN_DATA *clan, FILE *fp )
{
    const char *word;
    bool        fMatch;
    int         stat;

    for ( ; ; )
    {
    	GET_TOKEN( fp, word, "End" );
	fMatch = FALSE;

	switch ( UPPER( word[0] ) )
	{
	case '*':
	    fMatch = TRUE;
	    fread_to_eol( fp );
	    break;

	case 'C':
            SKEY( "Chieftain",   clan->chieftain );
             if ( !str_cmp( word, "Class" ) )
             {
		clan->cclass = class_lookup( temp_fread_string( fp, &stat ) );
             	fMatch = TRUE;
             	break;
             }
            KEY( "ClanHeros",    clan->clanheros, fread_number( fp, &stat ) );
            KEY( "ClanType",     clan->clan_type, fread_number( fp, &stat ) );
            KEY( "ClanObjOne",   clan->clanobj1,  fread_number( fp, &stat ) );
            KEY( "ClanObjTwo",   clan->clanobj2,  fread_number( fp, &stat ) );
            KEY( "ClanObjThree", clan->clanobj3,  fread_number( fp, &stat ) );
	    break;

	case 'D':
            SKEY( "Desc",    clan->description );
            KEY( "Donation", clan->donation,  fread_number( fp, &stat ) );
	    break;

	case 'E':
	    if ( !str_cmp( word, "End" ) )
		return TRUE;
	    break;

	case 'I':
            KEY( "IllegalPK",   clan->illegal_pk,  fread_number( fp, &stat ) );
	    break;

	case 'M':
            KEY( "Members",     clan->members, fread_number( fp, &stat ) );
            KEY( "MKills",      clan->mkills,  fread_number( fp, &stat ) );
            KEY( "MDeaths",     clan->mdeaths, fread_number( fp, &stat ) );
            SKEY( "Motto",      clan->motto );
	    break;

	case 'N':
            SKEY( "Name",      clan->name    );
	    break;

	case 'O':
            SKEY( "Overlord", clan->overlord );
	    break;

	case 'P':
            KEY( "PKills",  clan->pkills,  fread_number( fp, &stat ) );
            KEY( "PDeaths", clan->pdeaths, fread_number( fp, &stat ) );
	    break;

	case 'R':
            KEY( "Recall",  clan->recall,  fread_number( fp, &stat ) );
	    break;

	case 'S':
            KEY( "Score",     clan->score,     fread_number( fp, &stat ) );
            KEY( "Subchiefs", clan->subchiefs, fread_number( fp, &stat ) );
	    break;

	case 'W':
            SKEY( "WhoName",   clan->who_name    );
	    break;

	}

	if ( !fMatch )
	{
            bugf( "Load_clan_file: no match: %s", word );
	}
    }

    return FALSE;
}
Ejemplo n.º 12
0
void fread_social( FILE *fp )
{
    const char     *word;
    SOC_INDEX_DATA *social;
    bool            fMatch;
    int             stat;

    social = new_social( );

    for ( ; ; )
    {
    	GET_TOKEN( fp, word, "End" );
	fMatch = FALSE;

	switch ( UPPER( word[0] ) )
	{
	case '*':
	    fMatch = TRUE;
	    fread_to_eol( fp );
	    break;

	case 'C':
	    SKEY( "CharNoArg", social->char_no_arg );
	    SKEY( "CharFound", social->char_found  );
	    SKEY( "CharAuto",  social->char_auto   );
	    break;

	case 'E':
	    if ( !str_cmp( word, "End" ) )
	    {
		if ( !social->name )
		{
		    bugf( "Fread_social: Name not found" );
		    free_social( social );
		    return;
		}
		if ( !social->char_no_arg )
		{
		    bugf( "Fread_social: CharNoArg not found" );
		    free_social( social );
		    return;
		}
		add_social( social );
		return;
	    }
	    break;

	case 'N':
	    SKEY( "Name", social->name );
	    break;

	case 'O':
	    SKEY( "OthersNoArg", social->others_no_arg );
	    SKEY( "OthersFound", social->others_found  );
	    SKEY( "OthersAuto",	 social->others_auto   );
	    break;

	case 'V':
	    SKEY( "VictFound", social->vict_found );
	    break;
	}
	
	if ( !fMatch )
	{
            bugf( "Fread_social: no match: %s. Skipping to next line.", word );
	    fread_to_eol( fp );
	}
    }

    return;
}