Example #1
0
static char *
format_type_internal(Oid type_oid, int32 typemod,
					 bool typemod_given, bool allow_invalid)
{
	bool		with_typemod = typemod_given && (typemod >= 0);
	HeapTuple	tuple;
	Form_pg_type typeform;
	Oid			array_base_type;
	bool		is_array;
	char	   *buf;

	if (type_oid == InvalidOid && allow_invalid)
		return pstrdup("-");

	tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_oid));
	if (!HeapTupleIsValid(tuple))
	{
		if (allow_invalid)
			return pstrdup("???");
		else
			elog(ERROR, "cache lookup failed for type %u", type_oid);
	}
	typeform = (Form_pg_type) GETSTRUCT(tuple);

	/*
	 * Check if it's an array (and not a domain --- we don't want to show the
	 * substructure of a domain type).	Fixed-length array types such as
	 * "name" shouldn't get deconstructed either.  As of Postgres 8.1, rather
	 * than checking typlen we check the toast property, and don't deconstruct
	 * "plain storage" array types --- this is because we don't want to show
	 * oidvector as oid[].
	 */
	array_base_type = typeform->typelem;

	if (array_base_type != InvalidOid &&
		typeform->typstorage != 'p' &&
		typeform->typtype != TYPTYPE_DOMAIN)
	{
		/* Switch our attention to the array element type */
		ReleaseSysCache(tuple);
		tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(array_base_type));
		if (!HeapTupleIsValid(tuple))
		{
			if (allow_invalid)
				return pstrdup("???[]");
			else
				elog(ERROR, "cache lookup failed for type %u", type_oid);
		}
		typeform = (Form_pg_type) GETSTRUCT(tuple);
		type_oid = array_base_type;
		is_array = true;
	}
	else
		is_array = false;

	/*
	 * See if we want to special-case the output for certain built-in types.
	 * Note that these special cases should all correspond to special
	 * productions in gram.y, to ensure that the type name will be taken as a
	 * system type, not a user type of the same name.
	 *
	 * If we do not provide a special-case output here, the type name will be
	 * handled the same way as a user type name --- in particular, it will be
	 * double-quoted if it matches any lexer keyword.  This behavior is
	 * essential for some cases, such as types "bit" and "char".
	 */
	buf = NULL;					/* flag for no special case */

	switch (type_oid)
	{
		case BITOID:
			if (with_typemod)
				buf = printTypmod("bit", typemod, typeform->typmodout);
			else if (typemod_given)
			{
				/*
				 * bit with typmod -1 is not the same as BIT, which means
				 * BIT(1) per SQL spec.  Report it as the quoted typename so
				 * that parser will not assign a bogus typmod.
				 */
			}
			else
				buf = pstrdup("bit");
			break;

		case BOOLOID:
			buf = pstrdup("boolean");
			break;

		case BPCHAROID:
			if (with_typemod)
				buf = printTypmod("character", typemod, typeform->typmodout);
			else if (typemod_given)
			{
				/*
				 * bpchar with typmod -1 is not the same as CHARACTER, which
				 * means CHARACTER(1) per SQL spec.  Report it as bpchar so
				 * that parser will not assign a bogus typmod.
				 */
			}
			else
				buf = pstrdup("character");
			break;

		case FLOAT4OID:
			buf = pstrdup("real");
			break;

		case FLOAT8OID:
			buf = pstrdup("double precision");
			break;

		case INT2OID:
			buf = pstrdup("smallint");
			break;

		case INT4OID:
			buf = pstrdup("integer");
			break;

		case INT8OID:
			buf = pstrdup("bigint");
			break;

		case NUMERICOID:
			if (with_typemod)
				buf = printTypmod("numeric", typemod, typeform->typmodout);
			else
				buf = pstrdup("numeric");
			break;

		case INTERVALOID:
			if (with_typemod)
				buf = printTypmod("interval", typemod, typeform->typmodout);
			else
				buf = pstrdup("interval");
			break;

		case TIMEOID:
			if (with_typemod)
				buf = printTypmod("time", typemod, typeform->typmodout);
			else
				buf = pstrdup("time without time zone");
			break;

		case TIMETZOID:
			if (with_typemod)
				buf = printTypmod("time", typemod, typeform->typmodout);
			else
				buf = pstrdup("time with time zone");
			break;

		case TIMESTAMPOID:
			if (with_typemod)
				buf = printTypmod("timestamp", typemod, typeform->typmodout);
			else
				buf = pstrdup("timestamp without time zone");
			break;

		case TIMESTAMPTZOID:
			if (with_typemod)
				buf = printTypmod("timestamp", typemod, typeform->typmodout);
			else
				buf = pstrdup("timestamp with time zone");
			break;

		case VARBITOID:
			if (with_typemod)
				buf = printTypmod("bit varying", typemod, typeform->typmodout);
			else
				buf = pstrdup("bit varying");
			break;

		case VARCHAROID:
			if (with_typemod)
				buf = printTypmod("character varying", typemod, typeform->typmodout);
			else
				buf = pstrdup("character varying");
			break;
	}

	if (buf == NULL)
	{
		/*
		 * Default handling: report the name as it appears in the catalog.
		 * Here, we must qualify the name if it is not visible in the search
		 * path, and we must double-quote it if it's not a standard identifier
		 * or if it matches any keyword.
		 */
		char	   *nspname;
		char	   *typname;

		if (TypeIsVisible(type_oid))
			nspname = NULL;
		else
			nspname = get_namespace_name(typeform->typnamespace);

		typname = NameStr(typeform->typname);

		buf = quote_qualified_identifier(nspname, typname);

		if (with_typemod)
			buf = printTypmod(buf, typemod, typeform->typmodout);
	}

	if (is_array)
		buf = psnprintf(strlen(buf) + 3, "%s[]", buf);

	ReleaseSysCache(tuple);

	return buf;
}
Example #2
0
//
// HU_ChatRespond
//
// Responds to chat-related events.
//
static bool HU_ChatRespond(event_t *ev)
{
   char ch = 0;
   static bool shiftdown;

   // haleyjd 06/11/08: get HUD actions
   int action = G_KeyResponder(ev, kac_hud);
   
   if(ev->data1 == KEYD_RSHIFT) 
      shiftdown = (ev->type == ev_keydown);

   if(action == ka_frags)
      hu_showfrags = (ev->type == ev_keydown);

   if(ev->type != ev_keydown)
      return false;

   if(!chat_active)
   {
      if(ev->data1 == key_chat && netgame) 
      {       
         chat_active = true; // activate chat
         chatinput[0] = 0;   // empty input string
         return true;
      }
      return false;
   }
  
   if(altdown && ev->type == ev_keydown &&
      ev->data1 >= '0' && ev->data1 <= '9')
   {
      // chat macro
      char tempstr[100];
      psnprintf(tempstr, sizeof(tempstr),
                "say \"%s\"", chat_macros[ev->data1-'0']);
      C_RunTextCmd(tempstr);
      chat_active = false;
      return true;
   }
  
   if(ev->data1 == KEYD_ESCAPE)    // kill chat
   {
      chat_active = false;
      return true;
   }
  
   if(ev->data1 == KEYD_BACKSPACE && chatinput[0])
   {
      chatinput[strlen(chatinput)-1] = 0;      // remove last char
      return true;
   }
  
   if(ev->data1 == KEYD_ENTER)
   {
      char tempstr[100];
      psnprintf(tempstr, sizeof(tempstr), "say \"%s\"", chatinput);
      C_RunTextCmd(tempstr);
      chat_active = false;
      return true;
   }

   if(ev->character)
      ch = ev->character;
   else if(ev->data1 > 31 && ev->data1 < 127)
      ch = shiftdown ? shiftxform[ev->data1] : ev->data1; // shifted?
   
   if(ch > 31 && ch < 127)
   {
      psnprintf(chatinput, sizeof(chatinput), "%s%c", chatinput, ch);
      return true;
   }
   return false;
}
Example #3
0
static char *format_type_internal(oid_t type_oid, int32 typemod, bool typemod_given, bool allow_invalid)
{
    bool with_typemod = typemod_given && (typemod >= 0);
    struct heap_tuple * tuple;
    Form_pg_type typeform;
    oid_t array_base_type;
    bool is_array;
    char *buf;

    if (type_oid == INVALID_OID && allow_invalid)
        return pstrdup("-");

    tuple = search_syscache1(TYPEOID, OID_TO_D(type_oid));
    if (!HT_VALID(tuple)) {
        if (allow_invalid)
            return pstrdup("???");
        else
            elog(ERROR, "cache lookup failed for type %u", type_oid);
    }

    typeform = (Form_pg_type) GET_STRUCT(tuple);

    /*
     * Check if it's a regular (variable length) array type.  Fixed-length
     * array types such as "name" shouldn't get deconstructed.  As of
     * Postgres 8.1, rather than checking typlen we check the toast
     * property, and don't deconstruct "plain storage" array types --- this
     * is because we don't want to show oid_vector_s as oid[].
     */
    array_base_type = typeform->typelem;

    if (array_base_type != INVALID_OID && typeform->typstorage != 'p') {
        /* Switch our attention to the array element type */
        release_syscache(tuple);
        tuple = search_syscache1(TYPEOID, OID_TO_D(array_base_type));
        if (!HT_VALID(tuple)) {
            if (allow_invalid)
                return pstrdup("???[]");
            else
                elog(ERROR, "cache lookup failed for type %u", type_oid);
        }

        typeform = (Form_pg_type) GET_STRUCT(tuple);
        type_oid = array_base_type;
        is_array = true;
    } else {
        is_array = false;
    }

    /*
     * See if we want to special-case the output for certain built-in types.
     * Note that these special cases should all correspond to special
     * productions in gram.y, to ensure that the type name will be taken as
     * a system type, not a user type of the same name.
     *
     * If we do not provide a special-case output here, the type name will
     * be handled the same way as a user type name --- in particular, it
     * will be double-quoted if it matches any lexer keyword.
     *
     * This behavior is essential for some cases, such as types "bit" and
     * "char".
     */
    buf = NULL;		/* flag for no special case */

    switch (type_oid) {
    case BITOID:
        if (with_typemod) {
            buf = printTypmod("bit", typemod, typeform->typmodout);
        } else if (typemod_given) {
            /*
             * bit with typmod -1 is not the same as BIT, which
             * means BIT(1) per SQL spec. Report it as the quoted
             * typename so that parser will not assign a bogus
             * typmod.
             */
        } else {
            buf = pstrdup("bit");
        }
        break;

    case BOOLOID:
        buf = pstrdup("boolean");
        break;

    case BPCHAROID:
        if (with_typemod) {
            buf = printTypmod("character", typemod, typeform->typmodout);
        } else if (typemod_given) {
            /*
             * bpchar with typmod -1 is not the same as CHARACTER,
             * which means CHARACTER(1) per SQL spec. Report it as
             * bpchar so that parser will not assign a bogus typmod.
             */
        } else {
            buf = pstrdup("character");
        }
        break;

    case FLOAT4OID:
        buf = pstrdup("real");
        break;

    case FLOAT8OID:
        buf = pstrdup("double precision");
        break;

    case INT2OID:
        buf = pstrdup("smallint");
        break;

    case INT4OID:
        buf = pstrdup("integer");
        break;

    case INT8OID:
        buf = pstrdup("bigint");
        break;

    case NUMERICOID:
        if (with_typemod)
            buf = printTypmod("numeric", typemod, typeform->typmodout);
        else
            buf = pstrdup("numeric");

        break;

    case INTERVALOID:
        if (with_typemod)
            buf = printTypmod("interval", typemod, typeform->typmodout);
        else
            buf = pstrdup("interval");
        break;

    case TIMEOID:
        if (with_typemod)
            buf = printTypmod("time", typemod, typeform->typmodout);
        else
            buf = pstrdup("time without time zone");
        break;

    case TIMETZOID:
        if (with_typemod)
            buf = printTypmod("time", typemod, typeform->typmodout);
        else
            buf = pstrdup("time with time zone");
        break;

    case TIMESTAMPOID:
        if (with_typemod)
            buf = printTypmod("timestamp", typemod, typeform->typmodout);
        else
            buf = pstrdup("timestamp without time zone");
        break;

    case TIMESTAMPTZOID:
        if (with_typemod)
            buf = printTypmod("timestamp", typemod, typeform->typmodout);
        else
            buf = pstrdup("timestamp with time zone");
        break;

    case VARBITOID:
        if (with_typemod)
            buf = printTypmod("bit varying", typemod, typeform->typmodout);
        else
            buf = pstrdup("bit varying");
        break;

    case VARCHAROID:
        if (with_typemod)
            buf = printTypmod("character varying", typemod, typeform->typmodout);
        else
            buf = pstrdup("character varying");
        break;
    }

    if (buf == NULL) {
        /*
         * Default handling: report the name as it appears in the
         * catalog. Here, we must qualify the name if it is not visible
         * in the search path, and we must double-quote it if it's not
         * a standard identifier or if it matches any keyword.
         */
        char *nspname;
        char *typname;

        if (type_is_visible(type_oid))
            nspname = NULL;
        else
            nspname = get_ns_name(typeform->typnamespace);

        typname = NAME_TO_STR(typeform->typname);
        buf = quote_qualified_identifier(nspname, typname);
        if (with_typemod)
            buf = printTypmod(buf, typemod, typeform->typmodout);
    }

    if (is_array)
        buf = psnprintf(strlen(buf) + 3, "%s[]", buf);

    release_syscache(tuple);

    return buf;
}
Example #4
0
SANE_Status soapht_control_option(SANE_Handle handle, SANE_Int option, SANE_Action action, void *value, SANE_Int *set_result)
{
   struct soap_session *ps = (struct soap_session *)handle;
   SANE_Int *int_value = value, mset_result=0;
   int i, stat=SANE_STATUS_INVAL;
   char sz[64];

   switch(option)
   {
      case SOAP_OPTION_COUNT:
         if (action == SANE_ACTION_GET_VALUE)
         {
            *int_value = SOAP_OPTION_MAX;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_SCAN_MODE:
         if (action == SANE_ACTION_GET_VALUE)
         {
            for (i=0; ps->scanModeList[i]; i++)
            {
               if (ps->currentScanMode == ps->scanModeMap[i])
               {
                  strcpy(value, ps->scanModeList[i]);
                  stat = SANE_STATUS_GOOD;
                  break;
               }
            }
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            for (i=0; ps->scanModeList[i]; i++)
            {
               if (strcasecmp(ps->scanModeList[i], value) == 0)
               {
                  ps->currentScanMode = ps->scanModeMap[i];
                  set_scan_mode_side_effects(ps, ps->currentScanMode);
                  mset_result |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
                  stat = SANE_STATUS_GOOD;
                  break;
               }
            }
         }
         else
         {  /* Set default. */
            ps->currentScanMode = ps->scanModeMap[0];
            set_scan_mode_side_effects(ps, ps->currentScanMode);
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_INPUT_SOURCE:
         if (action == SANE_ACTION_GET_VALUE)
         {
            for (i=0; ps->inputSourceList[i]; i++)
            {
               if (ps->currentInputSource == ps->inputSourceMap[i])
               {
                  strcpy(value, ps->inputSourceList[i]);
                  stat = SANE_STATUS_GOOD;
                  break;
               }
            }
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
          for (i=0; ps->inputSourceList[i]; i++)
           {
             if (strcasecmp(ps->inputSourceList[i], value) == 0)
             {
               ps->currentInputSource = ps->inputSourceMap[i];
               set_input_source_side_effects(ps, ps->currentInputSource);
               if(ps->currentInputSource == IS_ADF || ps->currentInputSource == IS_ADF_DUPLEX)
               {
                 i = ps->adf_resolutionList[0] + 1;
                 while(i--) ps->resolutionList[i] = ps->adf_resolutionList[i];
               }
               else //if(ps->currentInputSource == IS_PLATEN) 
               {
                 i = ps->platen_resolutionList[0] + 1;
                 while(i--) ps->resolutionList[i] = ps->platen_resolutionList[i];
               }
               mset_result |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
               stat = SANE_STATUS_GOOD;
               break;
             }
           }
         }
         else
         {  /* Set default. */
            ps->currentInputSource = ps->inputSourceMap[0];
            set_input_source_side_effects(ps, ps->currentInputSource);
            mset_result |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_SCAN_RESOLUTION:
         if (action == SANE_ACTION_GET_VALUE)
         {
            *int_value = ps->currentResolution;
            stat = SANE_STATUS_GOOD;
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            for (i=1; i <= ps->resolutionList[0]; i++)
            {
               if (ps->resolutionList[i] == *int_value)
               {
                  ps->currentResolution = *int_value;
                  mset_result |= SANE_INFO_RELOAD_PARAMS;
                  stat = SANE_STATUS_GOOD;
                  break;
               }
            }
            if (stat != SANE_STATUS_GOOD)
            {
                ps->currentResolution = ps->resolutionList[1];
                stat = SANE_STATUS_GOOD;
            }
         }
         else
         {  /* Set default. */
            ps->currentResolution = 75;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_CONTRAST:
         if (action == SANE_ACTION_GET_VALUE)
         {
            *int_value = ps->currentContrast;
            stat = SANE_STATUS_GOOD;
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            if (*int_value >= SOAP_CONTRAST_MIN && *int_value <= SOAP_CONTRAST_MAX)
            {
               ps->currentContrast = *int_value;
            }
            else
            {
               ps->currentContrast = SOAP_CONTRAST_DEFAULT;
            }
            mset_result |= SANE_INFO_RELOAD_PARAMS;
            stat = SANE_STATUS_GOOD;
         }
         else
         {  /* Set default. */
            ps->currentContrast = SOAP_CONTRAST_DEFAULT;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_BRIGHTNESS:
         if (action == SANE_ACTION_GET_VALUE)
         {
            *int_value = ps->currentBrightness;
            stat = SANE_STATUS_GOOD;
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            if (*int_value >= SOAP_BRIGHTNESS_MIN && *int_value <= SOAP_BRIGHTNESS_MAX)
            {
               ps->currentBrightness = *int_value;
            }
            else
            {
              ps->currentBrightness = SOAP_BRIGHTNESS_DEFAULT;
            }
            stat = SANE_STATUS_GOOD;
         }
         else
         {  /* Set default. */
            ps->currentBrightness = SOAP_BRIGHTNESS_DEFAULT;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_COMPRESSION:
         if (action == SANE_ACTION_GET_VALUE)
         {
            for (i=0; ps->compressionList[i]; i++)
            {
               if (ps->currentCompression == ps->compressionMap[i])
               {
                  strcpy(value, ps->compressionList[i]);
                  stat = SANE_STATUS_GOOD;
                  break;
               }
            }
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            for (i=0; ps->compressionList[i]; i++)
            {
               if (strcasecmp(ps->compressionList[i], value) == 0)
               {
                  ps->currentCompression = ps->compressionMap[i];
                  stat = SANE_STATUS_GOOD;
                  break;
               }
            }
         }
         else
         {  /* Set default. */
            ps->currentCompression = SF_JFIF;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_JPEG_QUALITY:
         if (action == SANE_ACTION_GET_VALUE)
         {
            *int_value = ps->currentJpegQuality;
            stat = SANE_STATUS_GOOD;
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            if (*int_value >= MIN_JPEG_COMPRESSION_FACTOR && *int_value <= MAX_JPEG_COMPRESSION_FACTOR)
            {
               ps->currentJpegQuality = *int_value;
               stat = SANE_STATUS_GOOD;
               break;
            }
         }
         else
         {  /* Set default. */
            ps->currentJpegQuality = SAFER_JPEG_COMPRESSION_FACTOR;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_TL_X:
         if (action == SANE_ACTION_GET_VALUE)
         {
            *int_value = ps->currentTlx;
            stat = SANE_STATUS_GOOD;
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            if (*int_value >= ps->tlxRange.min && *int_value <= ps->tlxRange.max)
            {
               ps->currentTlx = *int_value;
               mset_result |= SANE_INFO_RELOAD_PARAMS;
               stat = SANE_STATUS_GOOD;
               break;
            }
         }
         else
         {  /* Set default. */
            ps->currentTlx = ps->tlxRange.min;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_TL_Y:
         if (action == SANE_ACTION_GET_VALUE)
         {
            *int_value = ps->currentTly;
            stat = SANE_STATUS_GOOD;
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            if (*int_value >= ps->tlyRange.min && *int_value <= ps->tlyRange.max)
            {
               
               ps->currentTly = *int_value;
               mset_result |= SANE_INFO_RELOAD_PARAMS;
               stat = SANE_STATUS_GOOD;
               break;
            }
         }
         else
         {  /* Set default. */
            ps->currentTly = ps->tlyRange.min;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_BR_X:
         if (action == SANE_ACTION_GET_VALUE)
         {
            *int_value = ps->currentBrx;
            stat = SANE_STATUS_GOOD;
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            if (*int_value >= ps->brxRange.min && *int_value <= ps->brxRange.max)
            {
               ps->currentBrx = *int_value;
               mset_result |= SANE_INFO_RELOAD_PARAMS;
               stat = SANE_STATUS_GOOD;
               break;
            }
         }
         else
         {  /* Set default. */
            ps->currentBrx = ps->brxRange.max;
            stat = SANE_STATUS_GOOD;
         }
         break;
      case SOAP_OPTION_BR_Y:
         if (action == SANE_ACTION_GET_VALUE)
         {
            *int_value = ps->currentBry;
            stat = SANE_STATUS_GOOD;
         }
         else if (action == SANE_ACTION_SET_VALUE)
         {
            if (*int_value >= ps->bryRange.min && *int_value <= ps->bryRange.max)
            {
               ps->currentBry = *int_value;
               mset_result |= SANE_INFO_RELOAD_PARAMS;
               stat = SANE_STATUS_GOOD;
               break;
            }
         }
         else
         {  /* Set default. */
            ps->currentBry = ps->bryRange.max;
            stat = SANE_STATUS_GOOD;
         }
         break;
      default:
         break;
   }

   if (set_result)
      *set_result = mset_result;

   if (stat != SANE_STATUS_GOOD)
   {
      BUG("control_option failed: option=%s action=%s\n", ps->option[option].name, 
                  action==SANE_ACTION_GET_VALUE ? "get" : action==SANE_ACTION_SET_VALUE ? "set" : "auto");
   }

   DBG8("sane_hpaio_control_option (option=%s action=%s value=%s)\n", ps->option[option].name, 
                        action==SANE_ACTION_GET_VALUE ? "get" : action==SANE_ACTION_SET_VALUE ? "set" : "auto",
     value ? ps->option[option].type == SANE_TYPE_STRING ? (char *)value : psnprintf(sz, sizeof(sz), "%d", *(int *)value) : "na");

   return stat;
} /* soapht_control_option */
Example #5
0
//
// cht_levelWarp
//
// haleyjd 08/23/13: Shared logic for warp cheats
//
static bool cht_levelWarp(const char *buf)
{
   char mapname[9];
   int epsd, map, lumpnum;
   bool foundit = false;
   WadDirectory *levelDir = g_dir; // 11/06/12: look in g_dir first
   int mission = inmanageddir;     // save current value of managed mission

   // return silently on nonsense input
   if(buf[0] < '0' || buf[0] > '9' ||
      buf[1] < '0' || buf[1] > '9')
      return false;

   // haleyjd: build mapname
   memset(mapname, 0, sizeof(mapname));

   if(GameModeInfo->flags & GIF_MAPXY)
   {
      epsd = 1; //jff was 0, but espd is 1-based 
      map  = (buf[0] - '0')*10 + buf[1] - '0';

      psnprintf(mapname, sizeof(mapname), "MAP%02d", map);
   }
   else
   {
      epsd = buf[0] - '0';
      map  = buf[1] - '0';

      psnprintf(mapname, sizeof(mapname), "E%dM%d", epsd, map);
   }

   // haleyjd: check mapname for existence and validity as a map
   do
   {
      lumpnum = levelDir->checkNumForName(mapname);

      if(lumpnum != -1 && P_CheckLevel(levelDir, lumpnum) != LEVEL_FORMAT_INVALID)
      {
         foundit = true;
         break; // got one!
      }
   }
   while(levelDir != &wGlobalDir && (levelDir = &wGlobalDir));

   if(!foundit)
   {
      player_printf(plyr, "%s not found or is not a valid map", mapname);
      return false;
   }

   // So be it.

   idmusnum = -1; //jff 3/17/98 revert to normal level music on IDCLEV

   G_DeferedInitNewFromDir(gameskill, mapname, levelDir);
   
   // restore mission if appropriate
   if(levelDir != &wGlobalDir)
      inmanageddir = mission;

   return true;
}
Example #6
0
static void HI_loadData(void)
{
   int i;
   char mapname[9];

   memset(mapname, 0, 9);

   // load interpic
   hi_interpic = NULL;
   hi_exitpic = nullptr;

   if(estrnonempty(hi_wbs.li_lastexitpic))
   {
      hi_exitpic = PatchLoader::CacheName(wGlobalDir, hi_wbs.li_lastexitpic,
                                          PU_STATIC);
   }

   if(estrnonempty(hi_wbs.li_nextenterpic))
   {
      hi_interpic = PatchLoader::CacheName(wGlobalDir, hi_wbs.li_nextenterpic,
                                           PU_STATIC);
   }
   else if(gameepisode <= 3)
   {
      sprintf(mapname, "MAPE%d", gameepisode);
      hi_interpic = PatchLoader::CacheName(wGlobalDir, mapname, PU_STATIC);
   }

   // load positional indicators
   hi_in_x   = PatchLoader::CacheName(wGlobalDir, "IN_X",   PU_STATIC);
   hi_in_yah = PatchLoader::CacheName(wGlobalDir, "IN_YAH", PU_STATIC);

   // get lump numbers for faces
   for(i = 0; i < 4; i++)
   {
      char tempstr[9];

      memset(tempstr, 0, 9);

      sprintf(tempstr, "FACEA%.1d", i);
      hi_faces[i] = W_GetNumForName(tempstr);

      sprintf(tempstr, "FACEB%.1d", i);
      hi_dead_faces[i] = W_GetNumForName(tempstr);
   }

   // haleyjd 03/27/05: EDF-defined intermission map names
   mapName     = NULL;
   nextMapName = NULL;

   {
      char nameBuffer[24];
      const char *basename;
      edf_string_t *str;

      // set current map
      if(hi_wbs.li_lastlevelname && *hi_wbs.li_lastlevelname)
         mapName = hi_wbs.li_lastlevelname;
      else
      {
         psnprintf(nameBuffer, 24, "_IN_NAME_%s", gamemapname);
         if((str = E_StringForName(nameBuffer)))
            mapName = str->string;
      }

      if(hi_wbs.li_nextlevelname && *hi_wbs.li_nextlevelname)
      {
         nextMapName = hi_wbs.li_nextlevelname;
         return;
      }

      // are we going to a secret level?
      basename = hi_wbs.gotosecret ? LevelInfo.nextSecret : LevelInfo.nextLevel;

      // set next map
      if(*basename)
      {
         psnprintf(nameBuffer, 24, "_IN_NAME_%s", basename);

         if((str = E_StringForName(nameBuffer)))
            nextMapName = str->string;
      }
      else
      {
         // try ExMy and MAPxy defaults for normally-named maps
         if(isExMy(gamemapname))
         {
            psnprintf(nameBuffer, 24, "_IN_NAME_E%01dM%01d", 
                      hi_wbs.epsd + 1, hi_wbs.next + 1);
            if((str = E_StringForName(nameBuffer)))
               nextMapName = str->string;
         }
         else if(isMAPxy(gamemapname))
         {
            psnprintf(nameBuffer, 24, "_IN_NAME_MAP%02d", hi_wbs.next + 1);
            if((str = E_StringForName(nameBuffer)))
               nextMapName = str->string;
         }
      }
   }
}