Esempio n. 1
0
/****** context_init *********************************************************
PROTO   contextstruct *context_init(char **names, int *group, int ndim,
			int *degree, int ngroup, int pcexflag)
PURPOSE Allocate and initialize a context structure.
INPUT   Pointer to an array of context names,
	Pointer to an array of group indices,
	Number of dependency parameters,
	Pointer to an array of group degrees,
	Number of groups,
	Principal Component exclusion flag.
OUTPUT  Pointer to an allocated context structure.
NOTES   See prefs.h.
AUTHOR  E. Bertin (IAP)
VERSION 13/02/2009
*/
contextstruct	*context_init(char **names, int *group, int ndim, int *degree,
	 int ngroup, int pcexflag)
  {
   contextstruct	*context;
   int			*groupflag,
			d,d2,g,g2, pcflag;

  QCALLOC(context, contextstruct, 1);
  QCALLOC(context->name, char *, ndim);
  QCALLOC(context->group, int, ndim);
  QCALLOC(context->degree, int, ndim);
  QCALLOC(context->pcflag, int, ndim);
  QCALLOC(groupflag, int, ndim);
/* Copy context names and group indices ...*/
/* ... and remove Principal Components if asked to */
  d2=0;
  for (d=0; d<ndim; d++)
    {
    if ((pcflag = !wstrncmp(names[d], "HIDDEN?", 80)))
      {
      context->npc++;
      if (!pcexflag)
        context->pcflag[d] = 1;
      }
    if (!pcexflag || !pcflag)
      {
      QMALLOC(context->name[d2], char, 80);
      strncpy(context->name[d2], names[d], 80);
      context->group[d2] = group[d];
      groupflag[group[d]-1]++;
      d2++;
      } 
    }
Esempio n. 2
0
/****** fitsfind **************************************************************
PROTO	int fitsfind(char *fitsbuf, char *keyword)
PURPOSE	Search for a FITS keyword in a FITS header.
INPUT	pointer to the FITS buffer,
	name of the keyword to search for.
OUTPUT	position in lines  of 80 char (0=first) of the keyword if it was
	found, RETURN_ERROR otherwise.
NOTES	The buffer MUST contain the ``END     '' keyword.
AUTHOR	E. Bertin (IAP & Leiden observatory)
VERSION	15/02/96
 ***/
int	fitsfind(char *fitsbuf, char *keyword)

  {
   char	*ptr;
   int	i, len;

  len = strlen(keyword);
  for (i=0; strncmp(ptr=&fitsbuf[80*i], "END     ", 8); i++)
    if (!wstrncmp(ptr, keyword, len))
      return i;
  if (strncmp(keyword, "END     ", 8))
    return RETURN_ERROR;
  else
    return i;
  }
Esempio n. 3
0
int main(int argc, char *argv[])
{
	WCHAR *wpath = TEXT("c:\\Program Files (x86)\\Pacifica\\Auth");
	int wpath_size = strlen("c:\\Program Files (x86)\\Pacifica\\Auth");
	LONG res;
	DWORD size = BUFFSIZE * sizeof(WCHAR);
	DWORD type = REG_EXPAND_SZ;
	HKEY key;
	WCHAR data[BUFFSIZE];
	WCHAR *final_path;
	WCHAR *start;
	WCHAR *end;
	int offset = 0;
	int i;
	int remove = 0;
	int args_start = 1;
//	FILE *file;
	if(argc < 2)
	{
		return -1;
	}
	if(argv[1][0] == '/' && argv[1][1] == 'r' && argv[1][2] == '\0')
	{
		remove = 1;
		args_start = 2;
		if(argc < 3)
		{
			return -1;
		}
	}
	wpath_size = strlen(argv[args_start]);
	wpath = (WCHAR*)LocalAlloc(LPTR, sizeof(WCHAR) * (wpath_size + 1));
	if(!wpath)
	{
		return -1;
	}
	for(i = 0; i < wpath_size + 1; i++)
	{
		wpath[i] = argv[args_start][i];
	}
	for(i = wpath_size - 1; i >= 0; i--)
	{
		if(wpath[i] == ' ' || wpath[i] == '\\')
		{
			wpath[i] = '\0';
			wpath_size--;
		}
		else
		{
			break;
		}
	}
//	file = fopen("c:\\pacificaauth\\foo.txt", "w");
//		fprintf(file, "type %d\n", remove);
//	for(i = args_start; i < argc; i++)
//	{
//		fprintf(file, "%s\n", argv[i]);
//	}
//	fclose(file);
	res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"), NULL, KEY_ALL_ACCESS, &key);
	if(res != ERROR_SUCCESS)
	{
		printf("%ld\n", res);
		return -1;
	}
	res = RegQueryValueEx(key, TEXT("Path"), NULL, &type, (LPBYTE) data, &size);
	if(res != ERROR_SUCCESS)
	{
		printf("%ld\n", res);
		return -1;
	}
	if(((WCHAR*)data)[(size - 1)/2] == (WCHAR)'\0')
	{
		size -= 2;
	}
	final_path = (WCHAR*)LocalAlloc(LPTR, sizeof(WCHAR) * (size + 4 + wpath_size));
	if(!final_path)
	{
		return -1;
	}
	for(start = data; start < data + (size/2);)
	{
		for(end = start + 1; *end != (WCHAR)'\0' && *end != (WCHAR)';'; end++);
		if(wstrncmp(start, wpath, end-start) && *start != '\0')
		{
			if(start != data)
			{
				final_path[offset] = ';';
				offset++;
			}
			my_wstrcpy(final_path + offset, start, end-start);
			offset += end-start;
		}
		start = end + 1;
	}
	if(!remove)
	{
		if(start != data)
		{
			final_path[offset] = ';';
			offset++;
		}
		my_wstrcpy(final_path + offset, wpath, wpath_size);
		offset += wpath_size;
	}
	final_path[offset] = '\0';
	wprintf(TEXT("%s\n"), final_path);
	res = RegSetValueEx(key, TEXT("Path"), NULL, type, (LPBYTE) final_path, offset * sizeof(WCHAR));
	if(res != ERROR_SUCCESS)
	{
		printf("%ld\n", res);
		return -1;
	}
	RegCloseKey(key);
	return 0;
}