예제 #1
0
void main (int argc, char **argv)
{
   int cFilesRequested = 0;

   g::CodePage = CP_ACP;

   for (--argc,++argv; argc; --argc,++argv)
      {
      if ((argv[0][0] == '-') || (argv[0][0] == '/'))
         {
         g::CodePage = atol(&argv[0][1]);
         }
      else // ((argv[0][0] != '-') && (argv[0][0] != '/'))
         {
         WIN32_FIND_DATA Data;

         HANDLE hFind;
         if ((hFind = FindFirstFile (argv[0], &Data)) == INVALID_HANDLE_VALUE)
            {
            printf ("file %s not found\n", argv[0]);
            }
         else
            {
            LPTSTR pszNames = NULL;

            do {
               if (!(Data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
                  mstrcat (&pszNames, TEXT('\0'), FindFullPath (argv[0], Data.cFileName));
               } while (FindNextFile (hFind, &Data));

            FindClose (hFind);

            if (pszNames)
               {
               for (LPTSTR psz = pszNames; psz && *psz; psz += 1+lstrlen(psz))
                  {
                  printf ("translating %s into rtf...\n", psz);
                  TranslateFile (psz);
                  }
               mstrfree (pszNames);
               }
            }

         cFilesRequested++;
         }
      }

   if (!cFilesRequested)
      {
      printf ("format : sgml2rtf filename {...}\r\n\r\n");
      }

   exit(0);
}
예제 #2
0
파일: kvect.c 프로젝트: apc-llc/cernlib
/*
 * action routine for /VECTOR/INPUT
 */
int kxvinput()
{
  char *vspec = ku_getc();
  int  lvspec = strlen( vspec );
  char *vname;
  char *p;
  INTEGER LLOW;
  INTEGER LHIGH;
  int nval;
  int vtype;
  int ilo[3];
  int ihi[3];
  int idx[3];
  int ndim = 1;
  int status = 0;
  int i;

  Kcvect.TVECFL = ku_true( 0 ); /* don't make a temporary copy */
  F77_CALL_Cxx(Kuvect,vspec,lvspec,&LLOW,&LHIGH);
  Kcvect.TVECFL = ku_true( 1 );

  if( LLOW == 0 ) {
    ku_alfa();
    printf( " *** VECTOR/INPUT: unknown vector %s\n", vspec );
    return -1;
  }

  if( IQUEST(20) != 0 ) {
    ku_alfa();
    printf( " *** VECTOR/INPUT: sub-vector %s not implemented\n",
           vspec );
    return -1;
  }

  vtype = IQUEST(14);
  for( i = 0; i < 3; i++ ) {
    idx[i] = ilo[i] = IQUEST(21+i);
    if( (ihi[i] = IQUEST(31+i)) > 1 )
      ndim = i + 1;
  }

  nval = LHIGH - LLOW + 1;

  vname = strdup( vspec );
  if( (p = strchr( vname, '(' )) != NULL )
    *p = '\0';

  ku_getc();
  while( nval > 0 ) {
    const char *value;
    INTEGER ival;
    REAL rval;
    int repeat;
    char *prompt = str2dup( vname, "(" );
    prompt = mstricat( prompt, idx[0] );
    for( i = 1; i < ndim; i++ ) {
      prompt = mstrcat( prompt, "," );
      prompt = mstricat( prompt, idx[i] );
    }
    prompt = mstrcat( prompt, ") " );

    if( (value = ku_getl()) == NULL ) {
      /* prompt for values */
      value = ku_proc( prompt, NULL );
      if( value == NULL ) {
        free( prompt );
        status = -1;
        break;
      }
    }

    if( *value == '\0' ) {
      /* leave value unchanged */
      free( prompt );
      repeat = 1;
    }
    else {
      if( vtype != 1 )
        repeat = repeat_value( "VECTOR/INPUT", prompt, value, &ival, NULL );
      else
        repeat = repeat_value( "VECTOR/INPUT", prompt, value, NULL, &rval );

      free( prompt );
      if( repeat < 1 ) {
        status = -1;
        break;
      }

      if( repeat > nval ) {
        repeat = nval;
        ku_alfa();
        printf( " *** VECTOR/INPUT: too many initializers for %s\n", vspec );
      }

      for( i = 0; i < repeat; i++ ) {
        if( vtype != 1 )
          IQ(LLOW) = ival;
        else
          Q(LLOW) = rval;
        LLOW++;
      }
    }

    nval -= repeat;
    for( i = 0; i < repeat; i++ ) {
      int k;
      for( k = 0; k < ndim; k++ ) {
        if( ++idx[k] > ihi[k] )
          idx[k] = ilo[k];
        else
          break;
      }
    }
  }

  free( vname );
  return status;
}
예제 #3
0
void p_f_iles(void)
	{
	print_at(2,2);
	printf("3. DEMO: Filehandling\n");
	print_at(2,4);
	printf("   Fileselectorbox, Alertbox, Auslesen eines Files, RELSEEK, SEEK, LOF, LOC ..\n");
	bild_char = sget(bild_char);
	chdrive(1);
	msprintf(a_char,"*.LST");
	msprintf(b_char,"A:\\GFA_TEST\\");
	chdir( b_char);
	fileselect(mstrcat( b_char,a_char),a_char,c_char);
	sput( bild_char);
	if(strcmp(c_char,""))
		{
		if((FP[1] = fopen(c_char,"r")) == NULL)
			{
			printf("\nFehler beim �ffnen der Datei !");
			getchar();
			r_aus(-1);
			}
		c_long=lof(FP[1]);
		msprintf(c_char,"%s",mid(c_char,rinstr(c_char,"\\")+1,-1));
		print_at(5,6);
		printf("L�nge der Datei %c%s%c%s: %ld\n",*chr(34),c_char,*chr(34),space(15-strlen(c_char)),c_long);
		relseek(FP[1],10);
		print_at(5,7);
		printf("Suche Position                   : %ld\n",loc(FP[1]));
		relseek(FP[1],10);
		print_at(5,8);
		printf("Erh�he den Filepointer um 10 Byte: %ld\n",loc(FP[1]));
		seek(FP[1],10);
		print_at(5,9);
		printf("Stelle den Pointer auf Position  : %ld\n",loc(FP[1]));
		print_at(5,11);
		printf("Auslesen und Anzeigen der Datei >>%s<< (Stop/Abbruch: Taste)\n",c_char);
		p_s_top();
		printf("\33E");
		do
			{
			printf("%c", *chr(fgetc(FP[1])));
			if(strcmp(inkey(),""))
				{
				a_lert( 2,"Abbruch",2,"JA|NEIN",back_long);
				if(back_long==1)
					{
					goto raus;
					}
				}
			if(feof(FP[1]))
				goto M2;
			}
		while(1);
		M2:
		raus:

		print_at(5,25);
		printf("Ausgelesen bis Position: %ld%s\n",loc(FP[1]),space(54-strlen(ltoab(loc(FP[1]),-1,-1))));
		fclose(FP[1]);
		}
	else
		{
		print_at(5,6);
		printf("Sie haben keine Datei ausgew�hlt!\n");
		}
	p_s_top();
	printf("\33E");
	}
예제 #4
0
char *PathResolver::normalizeFilename( const char *path )
{
	switch (path[0])
	{
	case '<': // Input
			return prettyPath(mstrcat(project_root, path+1));
	case '>': // Output
			return prettyPath(mstrcat(out_root, path+1));
	case '~': // Output
		return prettyPath(mstrcat(getenv("HOME"), path+1));
	case '@': // Auto path
		{
			/***** Expand the path *****/
			char *p = mstrdup(path);
			char *pf = p;
			if ( p[1] != '/' ) p[0] = '!';
			else               p++;
			char *b = normalizeFilename(p);
			free(pf);

			char *n = NULL;

			size_t olen = strlen(out_root);
			size_t plen = strlen(project_root);
			size_t blen = strlen(b);

			if (!strncmp(b, out_root, olen))
			{
				n = b; // Already in the out directory.
			}
			else if (!strncmp(b, project_root, plen))
			{
				n = myalloc(blen - plen + olen + 1);

				strcpy(n,      out_root);
				strcpy(n+olen, b+plen);

				free(b);
			}
			else // Outside of our directories
			{
				n = myalloc(olen + blen + 1);

				strcpy(n,      out_root);
				strcpy(n+olen, b);

				free(b);
			}

			return prettyPath(n);
		}
	case '*': // System path
		{
			path = mstrdup(path);

			DIR *cwd  = opendir(".");

			char *pathdir = mstrdup(getenv("PATH"));
			char *nt = pathdir; // NULL-terminator
			bool moredirs = true;

			const char *exename = path + 1;
			while ( moredirs )
			{
				/*** NULL-terminate the end of the next dir ***/
				pathdir = nt;
				while ( *nt != '\0' && *nt != ':' )
					nt++;
				if (!*nt)
					moredirs = false;
				*(nt++) = '\0';

				/*** Check for executable ***/
				chdir(pathdir);
				FILE *e = fopen(exename, "r");
				if (e) // Found it.
				{
					char *n = mstrcat(pathdir, '/', exename);

					fchdir(dirfd(cwd));
					closedir(cwd);

					return prettyPath(n);
				}
			}

			fchdir(dirfd(cwd));
			closedir(cwd);
		}

		msg::error("System path \"%s\" not found.", path);
		exit(EX_DATAERR);
	case '/': // Already absolute
		return prettyPath(mstrdup(path));
	}

	// Regular relative path

	if ( *path == '!' ) path++; // We didn't want the first character
	                            // to be looked at.

	char *n = getcwd(NULL, 0);
	int cwdlen = strlen(n);

	n = (char*)realloc(n, (cwdlen+2+strlen(path))*sizeof(char));
	if ( cwdlen > 1 )
	{
		n[cwdlen]   = '/' ;
		n[cwdlen+1] = '\0';
	}
	strcat(n, path);

	return prettyPath(n);
}