Exemplo n.º 1
0
void slib_import_routines(slib_t *lib) {
#if defined(LNX_EXTLIB) || defined(WIN_EXTLIB)
  int i, count;
  char buf[SB_KEYWORD_SIZE];
  int (*fgetname) (int, char *);
  int (*fcount) (void);

  lib->first_proc = extproccount;
  lib->first_func = extfunccount;

  fcount = slib_getoptptr(lib, "sblib_proc_count");
  fgetname = slib_getoptptr(lib, "sblib_proc_getname");
  if (fcount) {
    count = fcount();
    for (i = 0; i < count; i++) {
      if (fgetname(i, buf)) {
        slib_add_external_proc(buf, lib->id);
      }
    }
  }
  fcount = slib_getoptptr(lib, "sblib_func_count");
  fgetname = slib_getoptptr(lib, "sblib_func_getname");
  if (fcount) {
    count = fcount();
    for (i = 0; i < count; i++) {
      if (fgetname(i, buf)) {
        slib_add_external_func(buf, lib->id);
      }
    }
  }
#endif
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
	namelist nl=make_namelist();
	int i;
	char c='f';
	if(strcmp(argv[1],"-p")==0){
		i=3;
		c='t';
	}
	else i=1;
	while(i<argc){
		FILE *file=fopen(argv[i],"r");
		char name[64];
		while(!feof(file)){
			if (fgetname(name,64,file)!= NULL && res_name(name)!=1){
				if(c=='f'||(c=='t'&& (name[0])!=*argv[2]))
				      add_name(nl,name);
				
			}
			
		}
		fclose(file);
		i++;
	}
	qsort(nl->names,nl->size,sizeof(struct namestat),cmpfunc);
	print_list(nl);
	return 0;
} 
Exemplo n.º 3
0
      int main (int argc, char **argv){
      //varibales
      namelist nl = make_namelist();  
      FILE *stream; 
      char *fileName;
      char name[64];
      int FLAG = 0;
      int i = 1;
      int j = 0;     
      
      //upload files in a loop and gets the name to an array
    for (i=1;i!=argc;i++){//each file
     fileName = argv[i];//get the file
     stream = fopen(fileName, "r");//read the file
     
     while(fgetname(name, sizeof(name), stream)) {
       if(legalName(name)){
       printf("%s ", name);
	add_name(nl, name);
	//printf("\n");
	}
     }
     fclose(stream);
      }
      qsort(nl->names,nl->size,sizeof(struct namestat),compare);
  
  for(i=0;i<nl->size;i++){
    printf("%s %d\n",nl->names[i].name,nl->names[i].count);
  }
  
   
      return 0;
      }
Exemplo n.º 4
0
char *
PerlIO_getname(PerlIO *f, char *buf)
{
#ifdef VMS
 return fgetname(f,buf);
#else
 dTHX;
 Perl_croak(aTHX_ "Don't know how to get file name");
 return NULL;
#endif
}
Exemplo n.º 5
0
static pwr_tStatus	logg_open_file( logg_t_loggconf_list	*conflist_ptr,
					int			first_time)
{
	int			csts;
	char			filename[80];
	pwr_tTime		time;
	char			timestr[80];

	if ( !first_time)
	{
	  /* Check if it's time for a new try to open the file */
	  conflist_ptr->wait_count++;
	  if (conflist_ptr->wait_count < 10)
	    return REM__SUCCESS;
	  conflist_ptr->wait_count = 0;
	}

	/* Open file */
	logg_get_filename( conflist_ptr->loggconf->LoggFile,
			filename, LOGG_FILE_EXT);

#if defined OS_LYNX || defined OS_LINUX
	conflist_ptr->outfile = fopen( filename, "a+");
#else
	conflist_ptr->outfile = fopen( filename, "w+", "shr=get");
#endif
	if (conflist_ptr->outfile != NULL)
	{
	  /* Write a file header */
          time_GetTime( &time);
	  time_AtoAscii( &time, time_eFormat_DateAndTime, timestr, 
		sizeof(timestr));
	  csts = fprintf( conflist_ptr->outfile,
			"RemLogg file opened at %s\n\n", timestr);
	  if (csts >= 0)
	  {
	    conflist_ptr->loggconf->FileOpenCount++;
#if defined OS_ELN || defined OS_VMS
	    fgetname( conflist_ptr->outfile, filename);
#endif
	    errh_CErrLog( REM__LOGGFILEOPEN, errh_ErrArgAF(filename), NULL);
	    conflist_ptr->file_open = 1;
	    return REM__SUCCESS;
	  }
	  else
	  {
	    fclose( conflist_ptr->outfile);
	  }
	}
	errh_CErrLog( REM__LOGGFILE, errh_ErrArgAF(filename), NULL);
	return REM__LOGGFILE;
}
Exemplo n.º 6
0
int main(int argc, char **argv) {
    FILE *ret;
    int j, i, isEqual=0;
    namelist ourList = make_namelist();


    char tempWord[64];
    char *saveWords[] = {"auto", "double", "int", "long", "break", "else", "long", "switch", "case", "enum", "register", 		"typedef" ,"char", "extern",
                         "return", "union", "const", "float", "short", "unsigned", "continue",
                         "for","signed", "void", "default", "goto", "sizeof" ,"volatile",
                         "do", "if" ,"static" ,"while"
                        };

    for (j=1; j < argc; ++j)
    {
        ret = fopen( argv[j], "r"); /*ret is a pointer to the file*/

        while( fgetname(tempWord, 64, ret)) {
            isEqual = 0;
            for(i=0; i<32; ++i) {


                if(strcmp(tempWord, saveWords[i])!=0) {
                    isEqual = isEqual+1;
                }
                if(isEqual==32) { /*tempWord not equal to any of the key words*/
                    add_name(ourList, tempWord);

                }
            }

        }

        fclose (ret);
    }

    qsort (ourList->names, ourList->size, sizeof(struct namestat), compare);

    for(i=0; i<ourList->size; ++i) {
        printf("%s ", ourList->names[i].name);
        printf("%d\n", ourList->names[i].count);
    }








    return 0;
}
Exemplo n.º 7
0
Arquivo: testfgn.c Projeto: Hagai/espl
int main(int argc, char **argv) {
	FILE *stream = fopen("fgetname.c", "r");
	char name[64];
	if(!stream) {
		fprintf(stderr, "run the test in the source directory\n");
		return 1;
	}

	while(fgetname(name, sizeof(name), stream))
		printf("%s\n", name);

	fclose(stream);

	return 0;
}
Exemplo n.º 8
0
static pwr_tStatus	tlog_insert_file( 	char 		*filename,
					tlog_t_linelist **list,
					int		*list_count,
					char		*full_filename)
{
	int		sts;
	int		alloc = 0;
	FILE		*infile;
	pwr_tString132	line;
	int		line_nr;

	/* Open the infile */
	infile = fopen( filename, "r");
	if ( !infile )
	  return TLOG__FILEOPEN;

	line_nr = 0;
	while( 1)
	{
	  /* Read next line */
	  sts = tlog_read_line( line, sizeof(line), infile);
	  if ( EVEN(sts))
	     break;
	  line_nr++;

	  /* The two first line are comments 	*/
	  if ( line_nr > 2)
	  {
	    sts = tlog_line_add( (pwr_tString132 *) line, list, list_count, 
			&alloc, line_nr);
	    if ( EVEN(sts)) return sts;
	  }
	}
	fgetname( infile, full_filename);
	fclose( infile);
	return TLOG__SUCCESS;
}
Exemplo n.º 9
0
void ls() {
  char path[512];
  char name[9];
  file dir;
  file f;
  int i;
  int type;
  filecache c;

  finitcache(&c);

  fgetwd(path);
  iwrites("\n-- Directory ");
  iwrites(path);
  iwrites(" --\n\n");
  dir = fget(path);

  for (i = 0; 1; i++) {
    f = fdirget(dir, i, &c);
    if (!f)
      break;
    fgetname(name, f);
    type = fgettype(f);
    if (type == 1)
      isetcolor(14);
    else if (type == 2)
      isetcolor(9);
    else if (type == 3)
      isetcolor(12);
    iwrites(name);
    iwrites("\n");
    isetcolor(7);
  }

  iwrites("\n");
}
Exemplo n.º 10
0
int MAIN(int argc, char** argv)
{
    int    i;
    char** useargv;
    char** pfargv;

    if( nRunde == 0 )
    {
        pCppIn = stdin;
        pCppOut = stdout;
    }

    nRunde++;
    InitCpp1();
    InitCpp2();
    InitCpp3();
    InitCpp4();
    InitCpp5();
    InitCpp6();

#if HOST == SYS_VMS
    argc = getredirection(argc, argv);      /* vms >file and <file  */
#endif
    initdefines();                          /* O.S. specific def's  */
    if ( argv[argc-1][0] == '@' )
    {
        i = readoptions( argv[1], &pfargv );    /* Command file */
        useargv=pfargv;
    }
    else
    {
        i = dooptions(argc, argv);              /* Command line -flags  */
        useargv=argv;
    }
    switch (i)
    {
#if OSL_DEBUG_LEVEL > 1
    case 4:
        if ( bDumpDefs )
        {
            /*
             * Get defBase file, "-" means use stdout.
             */
            if (!streq(useargv[3], "-"))
            {
#if HOST == SYS_VMS
                /*
                 * On vms, reopen stdout with "vanilla rms" attributes.
                 */
                if ((i = creat(useargv[3], 0, "rat=cr", "rfm=var")) == -1
                    || dup2(i, fileno(stdout)) == -1)
#else
                pDefOut = fopen( useargv[3], "w" );
                if( pDefOut == NULL )
#endif
                {
                    perror(useargv[3]);
                    cerror("Can't open output file \"%s\"", useargv[3]);
                    exit(IO_ERROR);
                }
            }                           /* Continue by opening output    */
        }
#endif
    case 3:
        /*
         * Get output file, "-" means use stdout.
         */
        if (!streq(useargv[2], "-"))
        {
#if HOST == SYS_VMS
            /*
             * On vms, reopen stdout with "vanilla rms" attributes.
             */
            if ((i = creat(useargv[2], 0, "rat=cr", "rfm=var")) == -1
                || dup2(i, fileno(stdout)) == -1)
#else
            pCppOut = fopen( useargv[2], "w" );
            if( pCppOut == NULL )
#endif
            {
                perror(useargv[2]);
                cerror("Can't open output file \"%s\"", useargv[2]);
                exit(IO_ERROR);
            }
        }                           /* Continue by opening input    */
    case 2:                         /* One file -> stdin            */
        /*
         * Open input file, "-" means use stdin.
         */
        if (!streq(useargv[1], "-"))
        {
            pCppIn = fopen( useargv[1], "r" );
            if( pCppIn == NULL)
            {
                perror(useargv[1]);
                cerror("Can't open input file \"%s\"", useargv[1]);
                exit(IO_ERROR);
            }
            strncpy(work, useargv[1], NWORK);  /* Remember input filename      */
            break;
        }                           /* Else, just get stdin         */
    case 0:                         /* No args?                     */
    case 1:                         /* No files, stdin -> stdout    */
#if (HOST == SYS_UNIX) || (HOST == SYS_UNKNOWN)
        work[0] = EOS;              /* Unix can't find stdin name   */
#else
        fgetname(stdin, work);      /* Vax-11C, Decus C know name   */
#endif
        break;

    default:
        exit(IO_ERROR);             /* Can't happen                 */
    }

    setincdirs();                   /* Setup -I include directories */
    addfile( pCppIn, work);           /* "open" main input file       */
#if OSL_DEBUG_LEVEL > 1
    if (debug > 0 || bDumpDefs)
        dumpdef("preset #define symbols");
#endif
    if( pCppIn != stdin )
        rewind( pCppIn );

    cppmain();                      /* Process main file            */

    if ((i = (ifptr - &ifstack[0])) != 0)
    {
#if OLD_PREPROCESSOR
        ciwarn("Inside #ifdef block at end of input, depth = %d", i);
#else
        cierror("Inside #ifdef block at end of input, depth = %d", i);
#endif
    }
#if OSL_DEBUG_LEVEL > 1
    if( pDefOut != stdout && pDefOut != stderr )
        fclose( pDefOut );
#endif
    if( pCppOut != stdout && pCppOut != stderr )
        fclose( pCppOut );

    if (errors > 0)
    {
        fprintf(stderr, (errors == 1)
                ? "%d error in preprocessor\n"
                : "%d errors in preprocessor\n", errors);
        if (!eflag)
            exit(IO_ERROR);
    }
#ifdef NOMAIN                  /* BP */ /* kein exit im der LIB-Version */
    return( IO_NORMAL );
#else
    exit(IO_NORMAL);                /* No errors or -E option set   */
#endif

}
Exemplo n.º 11
0
main(int argc, char *argv[])
{
	int	sts;
	char	*ssts;
	int	size;
	char	object_var[] = "Z800022";
	char	newstr[1000000];
	char	str[1000000];
	FILE 	*infile;
	FILE 	*outfile;
	char	error_line[80];
	int	error_num;
	char	filename[80];
	int	pos;
	char	line[400];
	int	arg_classdef_idx;
	int	outsize;
	FILE	*idxfile;
	
	if ( argc >= 2 )
	  strcpy( filename, argv[1]);
	else
	{
	  printf("\n");
	  printf("Usage:\n");
	  printf("	Argument 1: filename of wb_load-file.\n");
	  printf("	Argument 2: Start index for $ClassDef objekts or\n");
	  printf("	            if \"storedidx\" fetch from classdef_idx.dat\n");
	  printf("	Argument 3: if \"replace\" old index will be replaced\n");
	  printf("\n");
	  exit(0);
	}

	if ( argc >= 3 )
	{
	  if ( !strcmp( argv[2], "storedidx"))
	  {
	    idxfile = fopen( "classdef_idx.dat", "r");
	    if ( idxfile == 0)
	    {
	      printf( "-- Index file not found\n");
	      arg_classdef_idx = 1;
	    }
	    fscanf( idxfile, "%d", &arg_classdef_idx);
	    fclose( idxfile);
	  }
	  else if ( sscanf( argv[2], "%d", &arg_classdef_idx) != 1)
	  {
	    printf("** WbloadConvert Error, Syntax error in argument 2\n"); 
	    exit(0);
	  }
	}
	else
	  arg_classdef_idx = 1;
	classdef_idx = arg_classdef_idx;

	noclassdef = 0;
	replace_idx = 1;
	if ( argc >= 4 )
	{
	  if ( !strcmp( argv[3], "noreplace"))
	    replace_idx = 0;
	  else if ( !strcmp( argv[3], "NOREPLACE"))
	    replace_idx = 0;
	  else if ( !strcmp( argv[3], "noclassdef"))
	    noclassdef = 1;
	  else if ( !strcmp( argv[3], "NOCLASSDEF"))
	    noclassdef = 1;
	  else
	  {
	    printf("** WbloadConvert Error, Syntax error in argument 3\n"); 
	    exit(0);
	  }
	}

	printf("-- Processing %s	 Startindex $ClassDef: %d\n", 
		filename, arg_classdef_idx);

	str[0] = 0;
	pos = 0;
	infile = fopen( filename, "r");
	ssts = fgets( line,  sizeof(line), infile);
	while ( ssts != NULL)
	{
	  strcpy( str + pos, line);
	  pos += strlen(line);
	  ssts = fgets( line, sizeof(line), infile);
	}
	fclose( infile);

	size = sizeof(error_line);
	sts = convwbl_convert( str, newstr, object_var, sizeof(newstr),
		error_line, &size, &error_num, &outsize);
	if (EVEN(sts))
	{
	  printf( "Error in line %d,\n  %s\n", error_num, error_line);
	  printf( "sts : %d\n", sts);
	  exit( 0);
	}
	if ( idx_count)
	{
	  outfile = fopen( filename, "w");
	  fwrite( newstr, outsize, 1, outfile);
	  fgetname( outfile, filename);
	  fclose( outfile);
	  printf( "-- File %s created\n	Endindex $ClassDef %d, %d changes\n", 
		filename, classdef_idx, idx_count);
	}
	else
	  printf( "-- No changes in file\n", filename);

	idxfile = fopen( "classdef_idx.dat", "r+");
	if ( !idxfile)
	{
	  idxfile = fopen( "classdef_idx.dat", "w");
	  if ( !idxfile ) 
	  {
	    printf( "** Unable to store index i indexfile\n");
	    exit(0);
	  }
	}
	fprintf( idxfile, "%d", classdef_idx+1);
	fclose( idxfile);
	exit( sts);
}
Exemplo n.º 12
0
char *
readpassphrase(const char *prompt, char *pbuf, size_t buflen, int flags)
{

	static unsigned long keyboard_id, keytable_id = 0;
	unsigned long ctrl_mask, saved_ctrl_mask = 0;
	int timeout_secs = 0;
	int *timeout_ptr = NULL;
	unsigned long status = 0;
	unsigned short iosb[4];
	unsigned short ttchan, result_len = 0, stdin_is_tty;

	$DESCRIPTOR(ttdsc, "");
	$DESCRIPTOR(pbuf_dsc, "");
	$DESCRIPTOR(prompt_dsc, "");
	char *retval = NULL;
	char *myprompt = NULL;
	char input_fspec[MY_PASSWORD_LEN + 1];

	if (pbuf == NULL || buflen == 0) {
		errno = EINVAL;
		return NULL;
	}
	bzero(pbuf, buflen);
	pbuf_dsc.dsc$a_pointer = pbuf;
	pbuf_dsc.dsc$w_length = buflen - 1;


	/*
	 * If stdin is not a terminal and only reading from a terminal is allowed, we
	 * stop here.  
	 */
	stdin_is_tty = isatty(fileno(stdin));
	if (stdin_is_tty != 1 && (flags & RPP_REQUIRE_TTY)) {
		errno = ENOTTY;
		return NULL;
	}

	/*
	 * We need the file or device associated with stdin in VMS format.
	 */
	if (fgetname(stdin, input_fspec, 1)) {
		ttdsc.dsc$a_pointer = (char *)&input_fspec;
		ttdsc.dsc$w_length = strlen(input_fspec);
	} else {
		errno = EMFILE;
		return NULL;
	}

	/* 
	 * The prompt is expected to provide its own leading newline.
	 */
	myprompt = malloc(strlen(prompt) + 1);
	if (myprompt == NULL) {
		errno = ENOMEM;
		return NULL;
	}
	sprintf(myprompt, "\n%s", prompt);
	prompt_dsc.dsc$a_pointer = myprompt;
	prompt_dsc.dsc$w_length = strlen(myprompt);

	if (!(flags & RPP_ECHO_ON) && (stdin_is_tty)) {
		/* Disable Ctrl-T and Ctrl-Y */
		ctrl_mask = LIB$M_CLI_CTRLT | LIB$M_CLI_CTRLY;
		status = LIB$DISABLE_CTRL(&ctrl_mask, &saved_ctrl_mask);
		if (!$VMS_STATUS_SUCCESS(status)) {
			errno = EVMSERR;
			vaxc$errno = status;
			free(myprompt);
			return NULL;
		}
	}

	/* 
	 * Unless timeouts are disabled, find out how long should we wait for input
	 * before giving up.
	 */
	if (!(flags & RPP_TIMEOUT_OFF)) {
		unsigned long tmo_item = SYI$_LGI_PWD_TMO;

		status = LIB$GETSYI(&tmo_item, &timeout_secs);
		if (!$VMS_STATUS_SUCCESS(status))
			timeout_secs = DEFAULT_TIMEOUT;
		timeout_ptr = &timeout_secs;
	}

	if (!(flags & RPP_ECHO_ON) && (stdin_is_tty)) {
		/* 
		 * If we are suppressing echoing, get a line of input with $QIOW.  
		 * Non-echoed lines are not stored for recall.  (The same thing
		 * could be done with SMG but would require maintenance of a virtual 
		 * display and pasteboard.)
		 */
		status = SYS$ASSIGN(&ttdsc, &ttchan, 0, 0, 0);
		if ($VMS_STATUS_SUCCESS(status)) {

			unsigned long qio_func = IO$_READPROMPT | IO$M_NOECHO | IO$M_PURGE;

			if (!(flags & RPP_TIMEOUT_OFF))
				qio_func |= IO$M_TIMED;
			bzero(iosb, sizeof(iosb));

			status = SYS$QIOW(0,
					  (unsigned long) ttchan,
					  qio_func, &iosb, 0, 0, pbuf, buflen - 1, timeout_secs, 0, myprompt, strlen(myprompt));

			if ($VMS_STATUS_SUCCESS(status)) {
				status = iosb[0];
				result_len = iosb[1];	/* bytes actually read */
			}
			(void) SYS$DASSGN(ttchan);
		}
	} else {
		/* 
		 * We are not suppressing echoing because echoing has been explicitly 
		 * enabled and/or we are not reading from a terminal.  In this case we 
		 * use SMG, which will store commands for recall.  The virtual keyboard 
		 * and key table are static and will only be created if we haven't been 
		 * here before.
		 */
		status = SS$_NORMAL;
		if (keyboard_id == 0) {
			unsigned char recall_size = RECALL_SIZE;

			status = SMG$CREATE_VIRTUAL_KEYBOARD(&keyboard_id, &ttdsc, 0, 0, &recall_size);
		}
		if ($VMS_STATUS_SUCCESS(status) && keytable_id == 0) {
			status = SMG$CREATE_KEY_TABLE(&keytable_id);
		}

		if ($VMS_STATUS_SUCCESS(status)) {
			status = SMG$READ_COMPOSED_LINE(&keyboard_id,
							&keytable_id, &pbuf_dsc, &prompt_dsc, &result_len, 0, 0, 0, timeout_ptr);
		}
	}

	/* 
	 * Process return value from SYS$QIOW or SMG$READ_COMPOSED_LINE.
	 */
	switch (status) {
	case SS$_TIMEOUT:
		errno = ETIMEDOUT;
		break;
	case SMG$_EOF:
		if (result_len != 0) {
			status = SS$_NORMAL;
		}
		/* fall through */
	default:
		if ($VMS_STATUS_SUCCESS(status)) {
			int i;

			if (flags & RPP_FORCELOWER) {
				for (i = 0; i < result_len; i++)
					pbuf[i] = tolower(pbuf[i]);
			}
			if (flags & RPP_FORCEUPPER) {
				for (i = 0; i < result_len; i++)
					pbuf[i] = toupper(pbuf[i]);
			}
			if (flags & RPP_SEVENBIT) {
				for (i = 0; i < result_len; i++)
					pbuf[i] &= 0x7f;
			}
			pbuf[result_len] = '\0';
			retval = pbuf;
		} else {
			errno = EVMSERR;
			vaxc$errno = status;
		}
	}			/* end switch */

	free(myprompt);

	if (!(flags & RPP_ECHO_ON) && (stdin_is_tty)) {
		/*
		 * Reenable previous control processing.
		 */
		status = LIB$ENABLE_CTRL(&saved_ctrl_mask);

		if (!$VMS_STATUS_SUCCESS(status)) {
			errno = EVMSERR;
			vaxc$errno = status;
			return NULL;
		}
	}

	return retval;

}				/* getpassphrase */