Exemple #1
0
/// isParam
int isParam(char *input_string)
{
  if(Stricmp(input_string, "catalog") == 0)
    return TRUE;
  if(Strnicmp(input_string, "catalog=", 8) == 0)
    return TRUE;
  if(Stricmp(input_string, "pofile") == 0)
    return TRUE;
  if(Strnicmp(input_string, "pofile=", 7) == 0)
    return TRUE;
  if(Stricmp(input_string, "codeset") == 0)
    return TRUE;
  if(Strnicmp(input_string, "codeset=", 8) == 0)
    return TRUE;
  if(Stricmp(input_string, "version") == 0)
    return TRUE;
  if(Strnicmp(input_string, "version=", 8) == 0)
    return TRUE;
  if(Stricmp(input_string, "revision") == 0)
    return TRUE;
  if(Strnicmp(input_string, "revision=", 8) == 0)
    return TRUE;
  if(Stricmp(input_string, "nooptim") == 0)
    return TRUE;
  if(Stricmp(input_string, "fill") == 0)
    return TRUE;
  if(Stricmp(input_string, "quiet") == 0)
    return TRUE;
  if(Stricmp(input_string, "flush") == 0)
    return TRUE;
  if(Stricmp(input_string, "nobeep") == 0)
    return TRUE;
  if(Stricmp(input_string, "nobufferedio") == 0)
    return TRUE;
  if(Strnicmp(input_string, "newctfile=", 10) == 0)
    return TRUE;
  if(Stricmp(input_string, "newctfile") == 0)
    return TRUE;
  if(Stricmp(input_string, "nolangtolower") == 0)
    return TRUE;
  if(Stricmp(input_string, "modified") == 0)
    return TRUE;
  if(Stricmp(input_string, "warnctgaps") == 0)
    return TRUE;
  if(Stricmp(input_string, "copymsgnew") == 0)
    return TRUE;
  if(Stricmp(input_string, "oldmsgnew") == 0)
    return TRUE;
  if(Stricmp(input_string, "?") == 0)
    return TRUE;
  if(Stricmp(input_string, "-h") == 0)
    return TRUE;
  if(Stricmp(input_string, "help") == 0)
    return TRUE;
  if(Stricmp(input_string, "--help") == 0)
    return TRUE;

  return FALSE;
}
Exemple #2
0
int SaveMessage( struct ClassData * data, STRPTR Message, ULONG msgnum )
{
	struct YGRDBIndex * idx;
	int rc = ERR_NOMEM, x=0;
	UBYTE *msg=Message, file[1024];
	BPTR fd;
	
	DBG("Saving message...\n");
	DBG_ASSERT(Message && *Message);
	if(!(Message && *Message))
		return ERR_INTERNAL;
	
	ObtainSemaphore(data->sem);
	
	if(!(idx = malloc(sizeof(struct YGRDBIndex))))
		goto done;
	
//	bzero( idx, sizeof(struct YGRDBIndex));
	DBG_ASSERT((strlen(Message) > 5) && !strncmp( Message, "From ", 5 ));
	
	#define cpln( src, dst )	\
		memcpy(dst,src, MIN(FindPos(src,"\n"),(int)sizeof(dst)-1))
	
	while(*msg && (x < 3))
	{
		if(!Strnicmp( msg, "From:", 5))
		{x++;	cpln(&msg[6], idx->from);}
		else if(!Strnicmp( msg, "Subject:", 8))
		{x++;	cpln(&msg[9], idx->subj);}
		else if(!Strnicmp( msg, "Date:", 5))
		{x++;	cpln(&msg[6], idx->date);}
		msg++;
	}
	idx->msgnum = msgnum;
	idx->udata = data->subtask.folder;
	
	DBG_VALUE(msgnum);
	DBG_STRING(idx->from);
	DBG_STRING(idx->subj);
	DBG_STRING(idx->date);
	
	idx->next = data->subtask.folder->idx;
	data->subtask.folder->idx = idx;
	
	data->subtask.folder->Total++;
	data->subtask.folder->New++;
	
	if(SameGroupFolder( data, FALSE ))
	{
		PushMethod( data->appobj, data->rightlist, 3, 
			MUIM_NList_InsertSingle, idx, MUIV_NList_Insert_Sorted);
	}
	
	rc = MakeMailFile( data->subtask.folder, file, sizeof(file)-1, 
		msgnum, (data->subtask.folder->New == 1));
	
	if(rc != ERR_NOERROR)
		goto done;
	
	if((fd = Open( file, MODE_NEWFILE)))
	{
		Write( fd, Message, strlen(Message));
		#ifdef DEBUG
		Flush( fd );
		#endif
		Close( fd );
	}
	
	DBG_STRING(file);
	
	if((rc = IoErr()) == 0)
		rc = ERR_NOERROR;
done:
	ReleaseSemaphore(data->sem);
	
	return(rc);
}
Exemple #3
0
int main(int argc, char *argv[])
{
  char *cdfile = NULL;
  char *ctfile = NULL;
  char *pofile = NULL;
  char *newctfile = NULL;
  char *catalog = NULL;
  char *source;
  char *template;
  int makenewct = FALSE;
  int makecatalog = FALSE;
  int i;

  if(argc == 0)      /* Aztec's entry point for workbench programs */
  {
    fprintf(stderr, "FlexCat can't be run from Workbench!\n" \
            "\n"
            "Open a Shell session and type FlexCat ?\n" \
            "for more information\n");
    exit(5);
  }

  if(OpenLibs() == FALSE)
    exit(20);

  OpenFlexCatCatalog();

  /* Big Endian vs. Little Endian (both supported ;-) */

  if(!SwapChoose())
  {
    fprintf(stderr, "FlexCat is unable to determine\n" \
            "the byte order used by your system.\n" \
            "It's neither Little nor Big Endian?!.\n");
    exit(5);
  }
#ifdef AMIGA
  ReadPrefs();
#endif
  if(argc == 1)
  {
    Usage();
  }

  for(i = 1; i < argc; i++)
  {
    if(Strnicmp(argv[i], "catalog=", 8) == 0)
    {
      catalog = argv[i] + 8;
      makecatalog = TRUE;
    }
    else if(Stricmp(argv[i], "catalog") == 0)
    {
      if(i == argc - 1)
      {
        catalog = NULL;
        makecatalog = TRUE;
      }
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          catalog = argv[i + 1];
          i++;
          makecatalog = TRUE;
        }
        else
        {
          catalog = NULL;
          makecatalog = TRUE;
        }
      }
    }
    else if(Strnicmp(argv[i], "pofile=", 7) == 0)
    {
      pofile = argv[i] + 7;
    }
    else if(Stricmp(argv[i], "pofile") == 0)
    {
      if(i == argc - 1)
        pofile = NULL;
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          pofile = argv[i + 1];
          i++;
        }
        else
          pofile = NULL;
      }
    }
    else if(Strnicmp(argv[i], "codeset=", 8) == 0)
    {
      strcpy(DestCodeset, argv[i] + 8);
    }
    else if(Stricmp(argv[i], "codeset") == 0)
    {
      if(i == argc - 1)
        DestCodeset[0] = '\0';
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          strcpy(DestCodeset, argv[i + 1]);
          i++;
        }
        else
          DestCodeset[0] = '\0';
      }
    }
    else if(Strnicmp(argv[i], "version=", 8) == 0)
    {
      CatVersion = strtol(argv[i]+8, NULL, 10);
    }
    else if(Stricmp(argv[i], "version") == 0)
    {
      if(i == argc - 1)
        CatVersion = -1;
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          CatVersion = strtol(argv[i + 1], NULL, 10);
          i++;
        }
        else
          CatVersion = -1;
      }
    }
    else if(Strnicmp(argv[i], "revision=", 9) == 0)
    {
      CatRevision = strtol(argv[i]+9, NULL, 10);
    }
    else if(Stricmp(argv[i], "revision") == 0)
    {
      if(i == argc - 1)
        CatRevision = -1;
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          CatRevision = strtol(argv[i + 1], NULL, 10);
          i++;
        }
        else
          CatRevision = -1;
      }
    }
    else if(Stricmp(argv[i], "nooptim") == 0)
    {
      NoOptim = TRUE;
    }
    else if(Stricmp(argv[i], "fill") == 0)
    {
      Fill = TRUE;
    }
    else if(Stricmp(argv[i], "quiet") == 0)
    {
      Quiet = TRUE;
    }
    else if(Stricmp(argv[i], "flush") == 0)
    {
      DoExpunge = TRUE;
    }
    else if(Stricmp(argv[i], "nobeep") == 0)
    {
      NoBeep = TRUE;
    }
    else if(Stricmp(argv[i], "nobufferedio") == 0)
    {
      NoBufferedIO = TRUE;
    }
    else if(Strnicmp(argv[i], "newctfile=", 10) == 0)
    {
      newctfile = argv[i] + 10;
      makenewct = TRUE;
    }
    else if(Stricmp(argv[i], "newctfile") == 0)
    {
      if(i == argc - 1)
      {
        newctfile = NULL;
        makenewct = TRUE;
      }
      else if(i < argc - 1)
      {
        if(isParam(argv[i + 1]) != TRUE)
        {
          newctfile = argv[i + 1];
          i++;
          makenewct = TRUE;
        }
        else
        {
          newctfile = NULL;
          makenewct = TRUE;
        }
      }
    }
    else if(Stricmp(argv[i], "nolangtolower") == 0)
    {
      LANGToLower = FALSE;
    }
    else if(Stricmp(argv[i], "modified") == 0)
    {
      Modified = TRUE;
    }
    else if(Stricmp(argv[i], "warnctgaps") == 0)
    {
      WarnCTGaps = TRUE;
    }
    else if(Stricmp(argv[i], "copymsgnew") == 0)
    {
      CopyNEWs = TRUE;
    }
    else if(Stricmp(argv[i], "oldmsgnew") == 0)
    {
      snprintf(Old_Msg_New, sizeof(Old_Msg_New), "; %s", argv[++i]);
    }
    else if(Stricmp(argv[i], "noautodate") == 0 || Stricmp(argv[i], "nospaces") == 0)
    {
      // just swallow some no longer supported options to
      // keep old scripts alive and happy
    }
    else if(cdfile == NULL)
    {
      if(Stricmp(argv[i], "?") == 0 ||
         Stricmp(argv[i], "-h") == 0 ||
         Stricmp(argv[i], "help") == 0 ||
         Stricmp(argv[i], "--help") == 0)
      {
        Usage();
      }

      cdfile = argv[i];

      // find out file extension and depending on it
      // we eiterh scan a CD file or the supplied pot file
      if(strstr(cdfile, ".pot") != NULL)
      {
        if(!ScanPOFile(cdfile, FALSE))
          MyExit(10);
      }
      else
      {
        if(!ScanCDFile(cdfile))
          MyExit(10);
      }
    }
    else if(strchr(argv[i], '=') != NULL)
    {
      /* Determine basename. */
      if(BaseName == NULL && cdfile != NULL)
      {
        char *lslash = strrchr(cdfile, '/');
        char  *ldot = strrchr(cdfile, '.');

        if(lslash == NULL)
          lslash = cdfile;
        else
          lslash++;

        if(ldot == NULL)
          ldot = cdfile + strlen(cdfile);

        if(ldot - lslash > 0)
        {
          BaseName = calloc(ldot - lslash + 3, 1);
          strncpy(BaseName, lslash, ldot - lslash);
        }
      }

      source =AllocString(argv[i]);
      template = strchr(source, '=');
      *template++ = '\0';
Exemple #4
0
static LONG Utility_strnicmp (STRPTR str1, STRPTR str2, LONG len) { return Strnicmp(str1, str2, len); }
Exemple #5
0
//
// thread which handles a single http request
//
static int proxy_handlereq(SOCKET sock_client)
{
	SOCKET sock_server;

	char buf[65536];
	char header_line[1024];
	char host[256];
	int		serverPort = 80;
    struct sockaddr     serverSockAddr;

	int gotHeader = 0;
	int count;
	int Status;
	unsigned long nbParm = 0L;
	char newline = '\n';
	fd_set rfds;
	int n, maxfd;

	int one = 1;

	buf[0] = '\0';
	host[0] = '\0';

	// set client socket non-blocking
	if ((Status = SockBlock(sock_client, 0)) < 0)
	{
		SockError("proxy_handlereq(): Failed to clear non-block mode on socket");
		return 1;
	}

	// now get headers from client
	while ((count = proxy_sockgets(sock_client, header_line, 1024)) > 0)
	{
		gotHeader = 1;

		// look for 'Host:' header
		if (!Strnicmp(header_line, "host: ", 6))
		{
			char *pPort;

			strcpy(host, header_line + 6);
			if ((pPort = strchr(host, ':')) != NULL)
			{
				*pPort++ = '\0';
				serverPort = atoi(pPort);
			}
		}

		//MessageBox(0, header_line, "Req header", MB_SYSTEMMODAL);
		strcat(buf, header_line);
		strcat(buf, "\n");
	}

	// add second line terminator to mark end of header
	strcat(buf, "\n");

	// bail if nothing came through
	if (!gotHeader)
	{
		SockClose(sock_client);
		return 1;
	}

	// did we get a host address?
	if (host[0] == '\0')
	{
		char err400[] = "HTTP/1.0 400 Invalid header received from browser\n\n";
		SockSend(sock_client, err400, strlen(err400));
		SockClose(sock_client);
		SockError("proxy_handlereq(): host missing from http header");
		return 1;
	}

	// allow callback function to intercept
	if (proxy_callback_fn != NULL)
		if ((*proxy_callback_fn)(host, buf, sock_client) != 0)
		{
			// callback took over
			SockClose(sock_client);
			return 0;
		}

	//MessageBox(0, buf, "Header", MB_SYSTEMMODAL);

	// change host and portnum if using downstream proxy
	if (proxy_extproxyaddr != NULL)
	{
		strcpy(host, proxy_extproxyaddr);
		serverPort = proxy_extproxyport;
	}

	// try to find server
    if (proxy_getaddr(host, serverPort, &serverSockAddr) == 0)
	{
		SockSend(sock_client, "404 Host Not Found\n\n", 20);
		SockClose(sock_client);
		return 1;
	}

    sock_server = socket(AF_INET, SOCK_STREAM, 0);
#ifdef WINDOWS
	setsockopt(sock_server, IPPROTO_TCP, TCP_NODELAY, (char * ) &one, sizeof (int));
#endif

	// try to connect to server
    if ((Status = connect(sock_server, &serverSockAddr, sizeof(serverSockAddr))) < 0)
	{
		SockSend(sock_client, "404 Host Not Found\n\n", 20);
		SockClose(sock_client);
		return 1;
	}

	// send client's req to server
	SockSend(sock_server, buf, strlen(buf));

	//
	// now loop around relaying stuff between server and client
	//

	maxfd = (sock_client > sock_server ) ? sock_client : sock_server;
	for(;;)
	{
		FD_ZERO(&rfds);
		FD_SET(sock_client, &rfds);
		FD_SET(sock_server, &rfds);

		if ((n = select(maxfd+1, &rfds, NULL, NULL, NULL)) < 0)
		{
			SockError("proxy_handlereq(): select() failed while handling http req");
			//fprintf(logfp, "%s: select() failed!: ", prog);
			//fperror(logfp, "");
			return 1;
		}

		// got data from client - relay to server
		if(FD_ISSET(sock_client, &rfds))
		{
			if ((n = SockReceive(sock_client, buf, sizeof(buf))) <= 0)
				break;  // end of request

			if (SockSend(sock_server, buf, n) != n)
			{
				//fprintf(logfp, "%s: write to: %s failed: ",	prog, http->host);
				//fperror(logfp, "");
				return 1;
			}
			continue;
		}

		// got data from server - relay to client
		if (FD_ISSET(sock_server, &rfds))
		{
			if ((n = SockReceive(sock_server, buf, sizeof(buf))) < 0)
			{
				//fprintf(logfp, "%s: read from: %s failed: ", prog, http->host);
				//fperror(logfp, "");

//				eno = safe_strerror(errno);
//				sprintf(buf, CFAIL, http->hostport, eno);
//				freez(eno);
				//write_socket(m_SockClient, buf, strlen(buf), 0);
				return 1;
			}

			if (n == 0)
				break;		// got all from server

			/* just write */
			if (SockSend(sock_client, buf, n) != n)
			{
				//fprintf(logfp, "%s: write to client failed: ",	prog);
				//fperror(logfp, "");
				return 1;
			}
			continue;

		}	// 'if (got something from server)'
	}		// 'for (;;)' - relaying data between client and server

	// all done - close sockets and terminate this thread
	SockClose(sock_client);
	SockClose(sock_server);

	// see you later
	return 0;

}		// 'proxy_handlereq()'
Exemple #6
0
int ScanCTFile(char *ctfile)
{
    FILE           *fp;
    char           *newline, *line, *idstr, *newidstr, *newstr;
    struct CatString *cs = NULL;
    int             Result = TRUE;
    int             CodeSet_checked = 0;

    ScanFile = ctfile;
    ScanLine = 0;

    if((fp = fopen(ctfile, "r")) == NULL)
    {
        ShowErrorQuick(MSG_ERR_NOCATALOGTRANSLATION, ctfile);
    }

    if(!NoBufferedIO)
        setvbuf(fp, NULL, _IOFBF, buffer_size);


    while(!feof(fp) && (line = newline = ReadLine(fp, TRUE)) != NULL)
    {
        switch(*line)
        {
            case ';':
                if(CopyNEWs == TRUE)
                {
                    if(cs && Strnicmp(line, Old_Msg_New, (int)strlen(Old_Msg_New)) == 0)
                    {
                        cs->NotInCT = TRUE;
                    }
                }
                break;

            case '#':

                /* '#' in the first  column of a line is the command introducer --
                any number of # symbols, blank spaces and tabs afterwards are
                skipped for compatibility with CatComp */

                while(*line == '#' || *line == ' ' || *line == '\t')
                {
                    ++line;
                }

                if(Strnicmp(line, "version", 7) == 0)
                {
                    if(CatVersionString || CatRcsId || CatName)
                    {
                        ShowError(MSG_ERR_DOUBLECTVERSION);
                    }
                    line += 7;
                    OverSpace(&line);
                    // perform a slightly obfuscated check for the version cookie to
                    // avoid having multiple cookies in the final binary
                    if(line[0] == '$' && Strnicmp(&line[1], "VER:", 4) == 0)
                    {
                        CatVersionString = AllocString(line);
                    }
                    else
                    {
                        ShowError(MSG_ERR_BADCTVERSION);
                    }
                }
                else if(Strnicmp(line, "codeset", 7) == 0)
                {
                    char *ptr;

                    if(CodeSet_checked)
                    {
                        ShowError(MSG_ERR_DOUBLECTCODESET);
                    }
                    line += 7;
                    OverSpace(&line);

                    if(!*line)
                    /* Missing argument for "## codeset" */
                    {
                        ShowError(MSG_ERR_BADCTCODESET);
                    }

                    for(ptr = line; *ptr; ptr++)
                        if(!isdigit((int)*ptr))
                        /* Non-digit char detected */
                        {
                            ShowError(MSG_ERR_BADCTCODESET);
                        }

                    errno = 0;

                    CodeSet = strtoul(line, &line, 0);

/*                  printf("ulong_max es %lu\n",ULONG_MAX);
                    printf("CodeSet obtenido de strtoul es %lu\n",CodeSet);*/

                    if(errno == ERANGE && CodeSet == ULONG_MAX)
                    {
                        ShowError(MSG_ERR_BADCTCODESET);
                    }

                    CodeSet_checked = 1;
                    // errno = 0;
                }
                else if(Strnicmp(line, "language", 8) == 0)
                {
                    char *ptr;

                    if(CatLanguage)
                    {
                        ShowError(MSG_ERR_DOUBLECTLANGUAGE);
                    }
                    line += 8;
                    OverSpace(&line);
                    CatLanguage = AddCatalogChunk(strdup("LANG"), line);

                    if(LANGToLower)
                        for(ptr = CatLanguage; *ptr; ptr++)
                            *ptr = tolower((int)*ptr);
                }
                else if(Strnicmp(line, "chunk", 5) == 0)
                {
                    char           *ID;

                    line += 5;
                    OverSpace(&line);
                    ID = line;
                    line += sizeof(ULONG);
                    OverSpace(&line);

                    AddCatalogChunk(ID, AllocString(line));
                }
                else if(Strnicmp(line, "rcsid", 5) == 0)
                {
                    if(CatVersionString || CatRcsId)
                    {
                        ShowError(MSG_ERR_DOUBLECTVERSION);
                    }
                    line += 5;
                    OverSpace(&line);
                    CatRcsId = AllocString(line);
                }
                else if(Strnicmp(line, "name", 5) == 0)
                {
                    if(CatVersionString || CatName)
                    {
                        ShowError(MSG_ERR_DOUBLECTVERSION);
                    }
                    line += 4;
                    OverSpace(&line);
                    CatName = AllocString(line);
                }
                else
                {
                    ShowWarn(MSG_ERR_UNKNOWNCTCOMMAND);
                }

                /* Stop looking for commands */

                break;

            default:
                if(*line == ' ' || *line == '\t')
                {
                    ShowError(MSG_ERR_UNEXPECTEDBLANKS);
                    OverSpace(&line);
                }
                idstr = line;

                while(IS_NUMBER_OR_LETTER(*line) || *line == '_')
                {
                    ++line;
                }
                if(idstr == line)
                {
                    ShowError(MSG_ERR_NOIDENTIFIER);
                    break;
                }

                if((newidstr = malloc(line - idstr + 1)) == NULL)
                {
                    MemError();
                }

                strncpy(newidstr, idstr, line - idstr);
                newidstr[line - idstr] = '\0';
                OverSpace(&line);

                if(*line)
                {
                    ShowError(MSG_ERR_EXTRA_CHARACTERS_ID, newidstr);
                }

                if((newstr = ReadLine(fp, FALSE)) != NULL)
                {
                    for(cs = FirstCatString; cs != NULL; cs = cs->Next)
                    {
                        if(strcmp(cs->ID_Str, newidstr) == 0)
                        {
                            break;
                        }
                    }
                    if(cs == NULL)
                    {
                        ShowWarn(MSG_ERR_UNKNOWNIDENTIFIER, newidstr);
                    }
                    else
                    {
                        size_t reallen;
                        size_t cd_len;

                        if(cs->CT_Str)
                        {
                            ShowError(MSG_ERR_DOUBLE_IDENTIFIER, cs->ID_Str);
                            Result = FALSE;
                            free(cs->CT_Str);
                        }
                        cs->CT_Str = AllocString(newstr);
                        cs->NotInCT = FALSE;

                        /* Get string length */

                        reallen = strlen(cs->CT_Str);
                        cd_len = strlen(cs->CD_Str);

                        if(cs->MinLen > 0 && reallen < (size_t)cs->MinLen)
                        {
                            ShowWarn(MSG_ERR_STRING_TOO_SHORT, cs->ID_Str);
                        }
                        if(cs->MaxLen > 0 && reallen > (size_t)cs->MaxLen)
                        {
                            ShowWarn(MSG_ERR_STRING_TOO_LONG, cs->ID_Str);
                        }

                        // check for empty translations
                        if(cd_len > 0 && reallen == 0)
                        {
                            ShowWarn(MSG_ERR_EMPTYTRANSLATION, cs->ID_Str);
                        }

                        /* Check for trailing ellipsis. */
                        if(reallen >= 3 && cd_len >= 3)
                        {
                            if(strcmp(&cs->CD_Str[cd_len - 3], "...") == 0 &&
                               strcmp(&cs->CT_Str[reallen - 3], "...") != 0)
                            {
                                ShowWarn(MSG_ERR_TRAILING_ELLIPSIS, cs->ID_Str);
                            }
                            if(strcmp(&cs->CD_Str[cd_len - 3], "...") != 0 &&
                               strcmp(&cs->CT_Str[reallen - 3], "...") == 0)
                            {
                                ShowWarn(MSG_ERR_NO_TRAILING_ELLIPSIS, cs->ID_Str);
                            }
                        }


                        /* Check for trailing spaces. */
                        if(reallen >= 1 && cd_len >= 1)
                        {
                            if(strcmp(&cs->CD_Str[cd_len - 1], " ") == 0 &&
                               strcmp(&cs->CT_Str[reallen - 1], " ") != 0)

                            {
                                ShowWarn(MSG_ERR_TRAILING_BLANKS, cs->ID_Str);
                            }
                            if(strcmp(&cs->CD_Str[cd_len - 1], " ") != 0 &&
                               strcmp(&cs->CT_Str[reallen - 1], " ") == 0)

                            {
                                ShowWarn(MSG_ERR_NO_TRAILING_BLANKS, cs->ID_Str);
                            }
                        }

                        /* Check for matching placeholders */
                        if(reallen >= 1 && cd_len >= 1)
                        {
                            char *cdP = cs->CD_Str;
                            char *ctP = cs->CT_Str;

                            do
                            {
                                cdP = strchr(cdP, '%');
                                ctP = strchr(ctP, '%');

                                if(cdP == NULL && ctP == NULL)
                                {
                                    // no more placeholders, bail out
                                    break;
                                }
                                else if(cdP != NULL && ctP != NULL)
                                {
                                    // skip the '%' sign
                                    cdP++;
                                    ctP++;

                                    // check the placeholder only if the '%' is followed by an
                                    // alpha-numerical character or another percent sign
                                    if(IS_NUMBER_OR_LETTER(*cdP) || *cdP == '%')
                                    {
                                        if(*cdP != *ctP)
                                        {
                                            ShowWarn(MSG_ERR_MISMATCHING_PLACEHOLDERS, cs->ID_Str);
                                            break;
                                        }
                                        // skip the second '%' sign
                                        if(*cdP == '%')
                                            cdP++;
                                        if(*ctP == '%')
                                            ctP++;
                                    }
                                    else if(IS_NUMBER_OR_LETTER(*ctP) || *ctP == '%')
                                    {
                                        // the translation uses a placeholder while the description
                                        // uses none.
                                        ShowWarn(MSG_ERR_EXCESSIVE_PLACEHOLDERS, cs->ID_Str);
                                        break;
                                    }
                                }
                                else if(cdP != NULL && ctP == NULL)
                                {
                                    // skip the '%' sign
                                    cdP++;

                                    // check if really a placeholder follows or just another percent sign
                                    // the original string is allowed to contain more single percent signs than the translated string
                                    if(IS_NUMBER_OR_LETTER(*cdP) || *cdP == '%')
                                    {
                                        // the description uses at least one more placeholder than the translation
                                        ShowWarn(MSG_ERR_MISSING_PLACEHOLDERS, cs->ID_Str);
                                    }
                                    break;
                                }
                                else if(cdP == NULL && ctP != NULL)
                                {
                                    // skip the '%' sign
                                    ctP++;

                                    // check if really a placeholder follows or just another percent sign
                                    // the translated string is allowed to contain more single percent signs than the original string
                                    if(IS_NUMBER_OR_LETTER(*ctP) || *ctP == '%')
                                    {
                                        // the translation uses at least one more placeholder than the description
                                        ShowWarn(MSG_ERR_EXCESSIVE_PLACEHOLDERS, cs->ID_Str);
                                    }
                                    break;
                                }
                            }
                            while(TRUE);
                        }
                    }

                    free(newstr);
                }
                else
                {
                    ShowWarn(MSG_ERR_MISSINGSTRING);
                    if(cs)
                        cs->CT_Str = (char *)"";
                }
                free(newidstr);
        }
        free(newline);
        // forget the pointers as we just freed them and 'line' must not be freed again after the loop
        newline = NULL;
        line = NULL;
    }

    if(!CodeSet_checked)
    {
        ShowErrorQuick(MSG_ERR_NOCTCODESET);
    }

    if(!(CatVersionString || (CatRcsId && CatName)))
    {
        ShowErrorQuick(MSG_ERR_NOCTVERSION);
    }

    // check if a translation exists for all identifiers
    for(cs = FirstCatString; cs != NULL; cs = cs->Next)
    {
        if(cs->CT_Str == NULL)
        {
            ShowWarnQuick(MSG_ERR_MISSINGTRANSLATION, cs->ID_Str);
        }
    }

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

    fclose(fp);

    if(WarnCTGaps)
    {
        for(cs = FirstCatString; cs != NULL; cs = cs->Next)
        {
            if(cs->CT_Str == NULL)
            {
                ShowWarn(MSG_ERR_CTGAP, cs->ID_Str);
            }
        }
    }

    if(Result)
        CT_Scanned = TRUE;

    return(Result);
}
BOOL FileNameComplete(Object *obj, BOOL backwards, struct InstData *data)
{
  BOOL edited = FALSE;

  ENTER();

  if(data->FNCBuffer != NULL)
  {
    if(data->FileEntries == 1)
    {
      DisplayBeep(NULL);
    }
    else
    {
      if(backwards)
      {
        if(--data->FileNumber < 0)
          data->FileNumber = data->FileEntries-1;
      }
      else
      {
        if(++data->FileNumber >= data->FileEntries)
          data->FileNumber = 0;
      }
    }
    InsertFileName(data->FileNameStart, data);
    edited = TRUE;
  }
  else
  {
    LONG pos = DoMethod(obj, MUIM_BetterString_FileNameStart, data->Contents, data->BufferPos);

    switch(pos)
    {
      case MUIR_BetterString_FileNameStart_Volume:
      {
        struct DosList *dl;
        STRPTR volumeName = NULL;
        char tmpBuffer[256];
        UWORD cut;

        pos = VolumeStart(data->Contents, data->BufferPos);
        if((cut = data->BufferPos-pos) != 0)
        {
          dl = LockDosList(LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS);
          while((dl = NextDosEntry(dl, LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS)) != NULL)
          {
            #ifdef __AROS__
            strlcpy(tmpBuffer, dl->dol_Ext.dol_AROS.dol_DevName, sizeof tmpBuffer);
            #else
            // dol_Name is a BSTR, we have to convert it to a regular C string
            char *bstr = BADDR(dl->dol_Name);

            // a BSTR cannot exceed 255 characters, hence the buffer size of 256 is enough in any case
            strlcpy(tmpBuffer, &bstr[1], (unsigned char)bstr[0]);
            #endif

            if(Strnicmp(tmpBuffer, data->Contents+pos, cut) == 0)
            {
              volumeName = tmpBuffer;
              break;
            }
          }

          if(volumeName != NULL)
          {
            if(OverwriteA(volumeName, pos, cut, strlen(volumeName)+1, data))
              data->Contents[data->BufferPos-1] = ':';
            edited = TRUE;
          }
          UnLockDosList(LDF_READ|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS);
        }
      }
      break;

      default:
      {
        struct FNCData *fncbuffer;
        struct FNCData *fncframe;
        struct ExAllControl *control;
        BPTR dirlock;
        char pattern[42];
        UWORD namestart = data->BufferPos;
        char oldletter = '\0';
        BOOL filename = TRUE;

        while(filename)
        {
          switch(*(data->Contents+namestart-1))
          {
            case '/':
            case ':':
              filename = FALSE;
              break;

            default:
              namestart--;
              break;
          }
        }

        if((data->BufferPos-namestart) < 32)
        {
          strlcpy(pattern, data->Contents+namestart, sizeof(pattern));
          strlcat(pattern, "~(#?.info)", sizeof(pattern));

          oldletter = data->Contents[namestart];
          data->Contents[namestart] = '\0';

          if((fncbuffer = (struct FNCData *)SharedPoolAlloc(4100)) != NULL)
          {
            fncbuffer->next = NULL;

            if((control = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL)))
            {
              char tokenized[sizeof(pattern) * 2 + 2];

              if(ParsePatternNoCase(pattern, tokenized, sizeof(tokenized)) != -1)
                control->eac_MatchString = tokenized;

              if((dirlock = Lock(data->Contents+pos, ACCESS_READ)))
              {
                UWORD entries = 0;

                fncframe = fncbuffer;
                while(fncframe && ExAll(dirlock, &fncframe->buffer, 4096, ED_TYPE, control))
                {
                  entries += control->eac_Entries;

                  if((fncframe->next = (struct FNCData *)SharedPoolAlloc(4100)))
                    fncframe->next->next = NULL;

                  fncframe = fncframe->next;
                }
                control->eac_Entries += entries;

                data->FileNumber = backwards ? control->eac_Entries-1 : 0;
                data->FileEntries = control->eac_Entries;
                data->FileNameStart = namestart;
                data->FNCBuffer = fncbuffer;

                if(control->eac_Entries)
                {
                  data->Contents[namestart] = oldletter;
                  InsertFileName(namestart, data);
                  edited = TRUE;
                }
                UnLock(dirlock);
              }
              else
              {
                SharedPoolFree(fncbuffer);
              }

              FreeDosObject(DOS_EXALLCONTROL, (APTR)control);
            }
          }
        }

        if(edited == FALSE)
          data->Contents[namestart] = oldletter;
      }
      break;
    }
  }

  RETURN(edited);
  return edited;
}
Exemple #8
0
LONG DoNameAsynch(struct IOFileSys *iofs, STRPTR name, 
		  struct DosLibrary *DOSBase)
{
    STRPTR volname, pathname, s1 = NULL;
    BPTR cur, lock = (BPTR)NULL;
    struct DosList    *dl;
    struct Device     *device;
    struct Unit       *unit;
    struct FileHandle *fh;
    struct Process    *me = (struct Process *)FindTask(NULL);

    if (!Strnicmp(name, "PROGDIR:", 8) && me->pr_HomeDir)
    {
	cur = me->pr_HomeDir;
	volname = NULL;
	pathname = name + 8;
    }
    else if (*name == ':')
    {
	cur = me->pr_CurrentDir;
	volname = NULL;
	pathname = name + 1;
    }
    else
    {
	/* Copy volume name */
	cur = me->pr_CurrentDir;
	s1 = name;
	pathname = name;
	volname = NULL;

	while (*s1)
	{
	    if (*s1++ == ':')
	    {
		volname = (STRPTR)AllocMem(s1-name, MEMF_ANY);

		if (volname == NULL)
		{
		    return ERROR_NO_FREE_STORE;
		}

		CopyMem(name, volname, s1 - name - 1);

		volname[s1 - name - 1] = '\0';
		pathname = s1;
		break;
	    }
	}
    }

    if (!volname && !cur && !DOSBase->dl_SYSLock)
    {
    	return ERROR_OBJECT_NOT_FOUND;
    }
    
    dl = LockDosList(LDF_ALL | LDF_READ);

    if (volname != NULL)
    {
	/* Find logical device */
	dl = FindDosEntry(dl, volname, LDF_ALL);

	if (dl == NULL)
	{
	    UnLockDosList(LDF_ALL | LDF_READ);
	    FreeMem(volname, s1 - name);

	    return ERROR_DEVICE_NOT_MOUNTED;
	}
	else if (dl->dol_Type == DLT_LATE)
	{
	    lock = Lock(dl->dol_misc.dol_assign.dol_AssignName, SHARED_LOCK);
	    UnLockDosList(LDF_ALL | LDF_READ);

	    if (lock != NULL)
	    {
		AssignLock(volname, lock);
		dl = LockDosList(LDF_ALL | LDF_READ);
		dl = FindDosEntry(dl, volname, LDF_ALL);

		if (dl == NULL)
		{
		    UnLockDosList(LDF_ALL | LDF_READ);
		    FreeMem(volname, s1 - name);

		    return ERROR_DEVICE_NOT_MOUNTED;
	        }
		
		device = dl->dol_Ext.dol_AROS.dol_Device;
		unit = dl->dol_Ext.dol_AROS.dol_Unit;
	    } 
	    else
	    {
		FreeMem(volname, s1 - name);

		return IoErr();
	    }
	} 
	else if (dl->dol_Type == DLT_NONBINDING)
	{
	    lock = Lock(dl->dol_misc.dol_assign.dol_AssignName, SHARED_LOCK);
	    fh = (struct FileHandle *)BADDR(lock);

	    if (fh != NULL)
	    {
		device = fh->fh_Device;
		unit = fh->fh_Unit;
	    } 
	    else
	    {
		UnLockDosList(LDF_ALL | LDF_READ);
		FreeMem(volname, s1 - name);

		return IoErr();
	    }
	}
	else
	{
	    device = dl->dol_Ext.dol_AROS.dol_Device;
	    unit   = dl->dol_Ext.dol_AROS.dol_Unit;
	}
    }
    else if (cur)
    {
	fh = (struct FileHandle *)BADDR(cur);
	device = fh->fh_Device;
	unit = fh->fh_Unit;
    }
    else
    {
    #if 0
    	/* stegerg: ?? */
	device = DOSBase->dl_NulHandler;
	unit = DOSBase->dl_NulLock;
    #else
    	fh = (struct FileHandle *)BADDR(DOSBase->dl_SYSLock);
	device = fh->fh_Device;
	unit = fh->fh_Unit;
    #endif
    }
    
    iofs->IOFS.io_Device = device;
    iofs->IOFS.io_Unit = unit;
    iofs->io_Union.io_NamedFile.io_Filename = pathname;

    if (volname != NULL)
    {
	FreeMem(volname, s1 - name);
    }

    return 0;
}
Exemple #9
0
static void getSystemCodeset(struct LibraryHeader *lib)
{
  struct codeset *foundCodeset = NULL;

  ENTER();

  // before we go any query the system via locale.library (which
  // might not be so accurate) we try different other means of
  // finding the codeset/charset of the system
  #if defined(__amigaos4__)
  if(foundCodeset == NULL)
  {
    LONG default_charset = GetDiskFontCtrl(DFCTRL_CHARSET);
    char *charset = (char *)ObtainCharsetInfo(DFCS_NUMBER, default_charset, DFCS_MIMENAME);

    foundCodeset = codesetsFind(&lib->codesets, charset);

    D(DBF_STARTUP, "%s system default codeset: '%s' (diskfont)", foundCodeset ? "found" : "not found", charset);
  }
  #endif

  if(foundCodeset == NULL)
  {
    char codepage[40];

    codepage[0] = '\0';
    if(GetVar("CODEPAGE", codepage, sizeof(codepage), 0) > 0)
    {
      D(DBF_STARTUP, "trying ENV:CODEPAGE '%s'", codepage);
      foundCodeset = codesetsFind(&lib->codesets, codepage);
    }

    D(DBF_STARTUP, "%s system default codeset: '%s' (ENV:CODEPAGE)", foundCodeset ? "found" : "did not find",
                                                                     foundCodeset ? foundCodeset->name : "?");
  }

  #if defined(__MORPHOS__)
  if(foundCodeset == NULL)
  {
    /* If CODEPAGE did not work (maybe user deleted it or something) we try a keymap instead. This only works
     * in MorphOS 2 and only if an old Amiga keymap is not used.
     */
    if(foundCodeset == NULL)
    {
      struct Library *KeymapBase;

      if((KeymapBase = OpenLibrary("keymap.library", 51)) != NULL)
      {
        /* Since we requested V51 it is either V51 or newer */
        if(KeymapBase->lib_Version > 51 || KeymapBase->lib_Revision >= 4)
        {
          CONST_STRPTR codepage;

          #ifndef GetKeyMapCodepage
          #define GetKeyMapCodepage(__p0) LP1(78, CONST_STRPTR , GetKeyMapCodepage, CONST struct KeyMap *, __p0, a0, , KEYMAP_BASE_NAME, 0, 0, 0, 0, 0, 0)
          #endif

          if((codepage = GetKeyMapCodepage(NULL)) != NULL)
          {
            foundCodeset = codesetsFind(&lib->codesets, codepage);

            D(DBF_STARTUP, "%s system default codeset: '%s' (keymap)", foundCodeset ? "found" : "did not find",
                                                                       foundCodeset ? foundCodeset->name : "?");
          }
        }

        CloseLibrary(KeymapBase);
      }
    }
  }
  #endif

  // if we still do not have our default charset we try to load
  // it from and environment variable ENVARC:CHARSET
  if(foundCodeset == NULL)
  {
    char charset[80];

    charset[0] = '\0';
    if(GetVar("CHARSET", charset, sizeof(charset), 0) > 0)
    {
      D(DBF_STARTUP, "trying ENV:CHARSET '%s'", charset);
      foundCodeset = codesetsFind(&lib->codesets, charset);
    }

    D(DBF_STARTUP, "%s system default codeset: '%s' (ENV:CHARSET)", foundCodeset ? "found" : "did not find",
                                                                    foundCodeset ? foundCodeset->name : "?");
  }

  // try the country code next
  if(foundCodeset == NULL)
  {
    struct Locale *defaultLocale;

    if((defaultLocale = OpenLocale(NULL)) != NULL)
    {
      int i;
      const struct loc *curLoc = NULL;
      BOOL found = FALSE;

      for(i=0;;i++)
      {
        curLoc = &locs[i];
        if(curLoc == NULL || curLoc->name == NULL)
          break;

        if(defaultLocale->loc_CountryCode == curLoc->carPlateCode || defaultLocale->loc_CountryCode == curLoc->iso3166Code)
        {
          D(DBF_STARTUP, "found country code for '%s'", curLoc->name);
          found = TRUE;
          break;
        }
      }

      if(found == TRUE)
        foundCodeset = codesetsFind(&lib->codesets, curLoc->codesetName);

      CloseLocale(defaultLocale);
    }

    D(DBF_STARTUP, "%s system default codeset: '%s' (locale/country)", foundCodeset ? "found" : "did not find",
                                                                       foundCodeset ? foundCodeset->name : "?");
  }

  // and if even the CHARSET environment variable didn't work
  // out we check the LANGUAGE env variable against our own
  // internal fallback list
  if(foundCodeset == NULL)
  {
    char language[80];

    language[0] = '\0';
    if(GetVar("LANGUAGE", language, sizeof(language), 0) > 0)
    {
      int i;
      const struct loc *curLoc = NULL;
      BOOL found = FALSE;

      for(i=0;;i++)
      {
        curLoc = &locs[i];
        if(curLoc == NULL || curLoc->name == NULL)
          break;

        if(Strnicmp(language, curLoc->name, curLoc->len) == 0)
        {
          D(DBF_STARTUP, "found language name for '%s'", curLoc->name);
          found = TRUE;
          break;
        }
      }

      if(found == TRUE)
        foundCodeset = codesetsFind(&lib->codesets, curLoc->codesetName);
    }

    D(DBF_STARTUP, "%s system default codeset: '%s' (ENV:LANGUAGE)", foundCodeset ? "found" : "did not find",
                                                                     foundCodeset ? foundCodeset->name : "?");
  }

  // and the very last check we do to find out the system's charset is
  // to use locale.library.
  if(foundCodeset == NULL)
  {
    struct Locale *locale;

    if((locale = OpenLocale(NULL)) != NULL)
    {
      int i;
      char *language = locale->loc_LanguageName;
      const struct loc *curLoc = NULL;
      BOOL found = FALSE;

      for(i=0;;i++)
      {
        curLoc = &locs[i];
        if(curLoc == NULL || curLoc->name == NULL)
          break;

        if(Strnicmp(language, curLoc->name, curLoc->len) == 0)
        {
          found = TRUE;
          break;
        }
      }

      CloseLocale(locale);

      if(found == TRUE)
        foundCodeset = codesetsFind(&lib->codesets, curLoc->codesetName);
    }

    D(DBF_STARTUP, "%s system default codeset: '%s' (locale/language)", foundCodeset ? "found" : "did not find",
                                                                        foundCodeset ? foundCodeset->name : "?");
  }

  // and if even that very last test didn't work out we
  // can just take the ISO-8859-1 charset as the fallback default
  if(foundCodeset == NULL)
    lib->systemCodeset = codesetsFind(&lib->codesets, "ISO-8859-1");
  else
    lib->systemCodeset = foundCodeset;

  D(DBF_STARTUP, "final system default codeset: '%s'", lib->systemCodeset ? lib->systemCodeset->name : "?");

  LEAVE();
}
Exemple #10
0
static BOOL
HandleToolTypes( UBYTE**             tool_types, 
                 struct ISAPNP_Card* card,
                 struct ISAPNPBase*  res )
{
  while( *tool_types )
  {
    if( Strnicmp( *tool_types, "DISABLE_CARD=", 13 ) == 0 )
    {
      LONG manufacturer;
      WORD product;
      BYTE revision;
      LONG serial;

      if( ParseID( *tool_types + 13, 
                   &manufacturer, &product, &revision, &serial ) )
      {
        struct ISAPNP_Card* card = NULL;

        while( ( card = ISAPNP_FindCard( card,
                                         manufacturer,
                                         product,
                                         revision,
                                         serial,
                                         res ) ) != NULL )
        {
          card->isapnpc_Disabled = TRUE;
        }
      }
      else
      {
        Req( "Illegal tool type: %s\n", (ULONG) *tool_types );
        return FALSE;
      }
    }
    else if( Strnicmp( *tool_types, "DISABLE_DEVICE=", 15 ) == 0 )
    {
      LONG manufacturer;
      WORD product;
      BYTE revision;

      if( ParseID( *tool_types + 15, 
                   &manufacturer, &product, &revision, NULL ) )
      {
        struct ISAPNP_Device* dev = NULL;

        while( ( dev = ISAPNP_FindDevice( dev,
                                          manufacturer,
                                          product,
                                          revision,
                                          res ) ) != NULL )
        {
          dev->isapnpd_Disabled = TRUE;
        }
      }
      else
      {
        Req( "Illegal tool type value: %s\n", (ULONG) *tool_types );
        return FALSE;
      }
    }
    else if( Strnicmp( *tool_types, "LEGACY_DEVICE=", 14 ) == 0 )
    {
      UBYTE* str;
      int    conv;
      LONG   manufacturer;
      WORD   product;
      BYTE   revision;
      UWORD  dev_num = 0;

      str  = *tool_types + 14;
      conv = ParseID( str,  &manufacturer, &product, &revision, NULL );

      str += conv;

      if( conv != 0 )
      {
        struct ISAPNP_Device*     dev;
        struct ISAPNP_Identifier* id;

        dev = ISAPNP_AllocDevice( res );

        if( dev == NULL )
        {
          Req( "Out of memory!" );
          return FALSE;
        }

        dev->isapnpd_Card = card;
        
        id  = AllocVec( sizeof( *id ), MEMF_PUBLIC | MEMF_CLEAR );
        
        if( id == NULL )
        {
          Req( "Out of memory!" );
          ISAPNP_FreeDevice( dev, res );
          return FALSE;
        }

        id->isapnpid_Vendor[ 0 ]  = ( manufacturer >> 24 ) & 0xff;
        id->isapnpid_Vendor[ 1 ]  = ( manufacturer >> 16 ) & 0xff;
        id->isapnpid_Vendor[ 2 ]  = ( manufacturer >>  8 ) & 0xff;
        id->isapnpid_Vendor[ 3 ]  = 0;

        id->isapnpid_ProductID    = product;
        id->isapnpid_Revision     = revision;
        
        AddTail( (struct List*) &dev->isapnpd_IDs, (struct Node*) id );
        
        if( card->isapnpc_Devices.lh_Head->ln_Succ != NULL )
        {
          dev_num = ( (struct ISAPNP_Device*) 
                      card->isapnpc_Devices.lh_TailPred )->isapnpd_DeviceNumber;
          ++dev_num;
        }
        
        dev->isapnpd_DeviceNumber = dev_num;

        AddTail( &card->isapnpc_Devices, (struct Node*) dev );
        
        while( *str != 0 )
        {
          if( *str != ' ' )
          {
            if( Strnicmp( str, "IRQ=", 4 ) == 0 )
            {
              int irq;
            
              irq = strtol( str + 4, (char**) &str, 0 );
            
              if( irq <= 0 || irq >= 16 )
              {
                Req( "Invalid IRQ value '%ld' in tooltype line\n"
                     "'%s'",
                     irq,
                     (ULONG) *tool_types );
                return FALSE;
              }
              else
              {
                struct ISAPNP_IRQResource* r;
        
                r = (struct ISAPNP_IRQResource*) 
                    ISAPNP_AllocResource( ISAPNP_NT_IRQ_RESOURCE, res );
            
                if( r == NULL )
                {
                  Req( "Out of memory!" );
                  return FALSE;
                }

                r->isapnpirqr_IRQMask = 1 << irq;
                r->isapnpirqr_IRQType = ISAPNP_IRQRESOURCE_ITF_HIGH_EDGE;
          
                AddTail( (struct List*) &dev->isapnpd_Options->isapnprg_Resources,
                         (struct Node*) r );
              }
            }
            else if( Strnicmp( str, "DMA=", 4 ) == 0 )
            {
              int dma;
            
              dma = strtol( str + 4, (char**) &str, 0 );
            
              if( dma <= 0 || dma >= 8 )
              {
                Req( "Invalid DMA value '%ld' in tooltype line\n"
                     "'%s'",
                     dma,
                     (ULONG) *tool_types );
                return FALSE;
              }
              else
              {
                struct ISAPNP_DMAResource* r;
        
                r = (struct ISAPNP_DMAResource*) 
                    ISAPNP_AllocResource( ISAPNP_NT_DMA_RESOURCE, res );
            
                if( r == NULL )
                {
                  Req( "Out of memory!" );
                  return FALSE;
                }

                r->isapnpdmar_ChannelMask = 1 << dma;
                r->isapnpdmar_Flags       = 0;
          
                AddTail( (struct List*) &dev->isapnpd_Options->isapnprg_Resources,
                         (struct Node*) r );
              }
            }
            else if( Strnicmp( str, "IO=", 3 ) == 0 )
            {
              int base;
              int length;

              struct ISAPNP_IOResource* r;
            
              base = strtol( str + 3, (char**) &str, 0 );

              if( *str != '/' )
              {
                Req( "Length missing from IO value in tooltype line\n"
                     "'%s'",
                     (ULONG) *tool_types );
                return FALSE;
              }

              ++str;

              length = strtol( str, (char**) &str, 0 );

              if( base <= 0 || base >= 0xffff )
              {
                Req( "Invalid IO base value '%ld' in tooltype line\n"
                     "'%s'",
                     base,
                     (ULONG) *tool_types );
                return FALSE;
              }

              if( length <= 0 || length >= 0xffff )
              {
                Req( "Invalid IO length value '%ld' in tooltype line\n"
                     "'%s'",
                     length,
                     (ULONG) *tool_types );
                return FALSE;
              }

              r = (struct ISAPNP_IOResource*) 
                  ISAPNP_AllocResource( ISAPNP_NT_IO_RESOURCE, res );
            
              if( r == NULL )
              {
                Req( "Out of memory!" );
                return FALSE;
              }

              r->isapnpior_MinBase   = base;
              r->isapnpior_MaxBase   = base;
              r->isapnpior_Length    = length;
              r->isapnpior_Alignment = 1;
          
              AddTail( (struct List*) &dev->isapnpd_Options->isapnprg_Resources,
                       (struct Node*) r );
            }
            else
            {
              Req( "Parse error near '%s'\n"
                   "in tooltype line\n"
                   "'%s'",
                   (ULONG) str,
                   (ULONG) *tool_types );
              return FALSE;
            }
          }
          
          if( *str )
          {
            ++str;
          }
        }
      }
      else
      {
        Req( "Illegal tool type: '%s'\n", (ULONG) *tool_types );
        return FALSE;
      }
    }