Пример #1
0
main()
{
   LongString str;
   LongString str2;
   int   cou,i;
   int   len;

   LongStringInit(&str,1);

   for (i = 0, cou = str.split(&str,"1 2",-1,0,' ',0); i < cou; i++)
   {
      printf("<%*.*s>\n",
         str.field_size[i],str.field_size[i],str.field_value[i]);
   };
   for (i = 0, cou = str.split(&str,"1 2 3def 4 5bcdef",-1,0,' ',0);
      i < cou; i++)
   {
      printf("<%*.*s>\n",
         str.field_size[i],str.field_size[i],str.field_value[i]);
   };
   for (i = 0, cou = str.split(&str,"AA\001BB",4,0,'\001',0); i < cou; i++)
   {
      printf("<%*.*s>\n",
         str.field_size[i],str.field_size[i],str.field_value[i]);
   };
   str.dup(&str2,&str);
   for (i = 0; i < cou; i++)
   {
      printf("<%*.*s>\n",
         str2.field_size[i],str2.field_size[i],str2.field_value[i]);
      printf("len: %d\n",str2.field_size[i]);
   };
#if 1
   str.appendstrings(&str,"1skfbjrhvbfr"," " "44442d,mn9"," " "3**",NULL);
   printf("<%s>\n",str.buf);
   str.copy(&str,"BAC",-1);
   str.append(&str,"Zsolt",-1);
   str.append(&str,"Hello",3);

   printf("<%s>\n",str.buf);

   str2.free(&str2);
   str.dup(&str2,&str);
   str2.min(&str2);
   printf("<%s>\n",str2.buf);

   str.copy(&str,"zk",-1);

   printf("<%s>\n",str.buf);
   str2.free(&str2);
   str.free(&str);
/*
   printf("%s",str.readfile(&str,"longstr.h"));
   printf("%s",str.readfile(&str,"longstr.c"));
*/
#endif
   str.free(&str);

   exit(0);
}
Пример #2
0
int
main(int argc, char **argv)
{
	char	*data;
	char	*key;
	char	*bufp;
	char	save_c;
	long	type;
	int	linenum;
	char	*cache = NULL;
	char	*cross_cache = NULL;
	FILE	*logfp = NULL;
	FILE	*infp = stdin;
	char	*file = NULL;
	int	first_xref = TRUE;
	char	*db_prefix = NULL;
	char	*sn_host = NULL;
	char	*sn_pid = NULL;
	char	*omode = NULL;
	char	lock_file[MAXPATHLEN];
	int	set_sgns = FALSE;
	LongString	buf;
	char *macro_file[MAX_MACRO_FILES];
	int macro_file_num = 0;

	LongStringInit(&buf,0);
	Tcl_FindExecutable(argv[0]);

#if !WIN32 && TTY_TRACE
	tty = fopen("/dev/tty","w");
#endif /* !WIN32 && TTY_TRACE */

	while((type = getopt(argc,argv,"c:C:lf:H:O:P:M:sFm:")) != EOF)
	{
		switch (type)
		{
		case 'c':
			cache = optarg;
			break;

		case 'C':
			cross_cache = optarg;
			break;

		case 'l':
			report_local_vars = TRUE;
			break;

		case 'f':
			file = optarg;
			break;

		case 'H':
			sn_host = optarg;
			break;

		case 'P':
			sn_pid = optarg;
			break;

		case 'M':
			omode = optarg;
			break;

		case 's':
			set_sgns = FALSE;
			break;

		case 'F':
			break;

		case 'm':
			if (macro_file_num < MAX_MACRO_FILES - 1)
			{
				macro_file[macro_file_num++] = optarg;
			}
			MacroReadFile(optarg);
			break;
		}
	}

	if (optind < argc)
	{
		db_prefix = argv[optind];
	}

	if (!db_prefix)
	{
		printf("Usage: %s ?-c cache_size? ?-C cross_cache_size? ?-l? ?-f file? ?-m macrofile? db_prefix\n",
			argv[0]);

		exit(2);
	}

	if (set_sgns)
		set_signals();

	killed = FALSE;

	if (sn_host && sn_pid)
	{
		sprintf(lock_file,"%s.lck",db_prefix);

		switch (create_lock_file(lock_file,sn_host,sn_pid))
		{
		case -1:
			fprintf(stderr,"Could not create lock,%s\n",strerror(errno));
			exit(2);
			break;

		case FALSE:
			fprintf(stderr,"The database is in an inconsistent state.\n");
			exit(2);
			break;
		}
	}
	else
		lock_file[0] = '\0';

	if (file)
	{
		FILE	*in;

		in = fopen(file,"r");
		if (in)
			infp = in;
	}

	/*SN_DBIMP is set interactive in the tcl init procedure!*/
	if (getenv("SN_DBIMP"))
	{
		char    tmp[MAXPATHLEN];
		char    *e;

		e = getenv("TMPDIR");

		sprintf(tmp,"%s/dbimp_%lu.tmp",
			e ? e : "/tmp",
			(unsigned long)getpid());

		logfp = fopen(tmp,"w+");
		if (logfp)
		{
			chmod(tmp,0666);
			fprintf(logfp,"#dbimp (pid: %lu) started database\n#prefix: <%s> cache: %s ",
				(unsigned long)getpid(),
				db_prefix,
				cache ? cache : "#");
			fprintf(logfp,"cross_cache: %s local_vars: %d file: <%s>\n",
				cross_cache ? cross_cache : "#",
				report_local_vars,
				file ? file : "stdin");
			if (macro_file_num)
			{
				int cou;

				for (cou = 0; cou < macro_file_num; cou++)
				{
					fprintf(logfp,"macro file %d: <%s>\n",
						cou + 1,
						macro_file[cou]);
				}
			}
			fflush(logfp);
		}
	}

	Paf_dbimp_running = TRUE;

	Paf_db_init_tables(db_prefix,cache,cross_cache);

	linenum = 0;
	type = -999;

	switch (setjmp(BAD_IMPL_jmp_buf))
	{
	case PAF_PANIC_SOFT:
		killed = TRUE;

		fprintf(stderr,"dbimp (soft) panic");

		if (filename_g)
		{
			fprintf(stderr,", in file: %s, at line: %d column: %d\n",
				filename_g,yylineno,yycharno);
		}
		fprintf(stderr,"\n");
		fflush(stderr);
		break;

	case PAF_PANIC_SIMPLE:
		killed = TRUE;
		break;

	case PAF_PANIC_EMERGENCY:
		killed = -1;

		fprintf(stderr,"Run time error: %s\n",strerror(errno));
		fflush(stderr);
		break;
	}

	while (!killed && (bufp = buf.fgets(&buf,infp)))
	{
		if (logfp)
		{
			fputs(bufp,logfp);
			fputs("\n",logfp);
			fflush(logfp);
		}

		if (bufp[0] == '#' || bufp[0] == '\0')
			continue;

		linenum++;

		key = strchr(bufp,';');
		if (key)
			data = strchr(key + 1,';');
		else
			data = NULL;

		if (!key || !data)
		{
			fprintf(stderr,"dbimp Error: %s\n",bufp);
			fflush(stderr);
			continue;
		}

		save_c = *key;
		*key = '\0';
		type = strtol(bufp,NULL,0);
		*key = save_c;

		if (type < -3)
		{
			fprintf(stderr,"dbimp invalid type: %ld, %s\n",type,bufp);
			fflush(stderr);
			continue;
		}
		else if (type == -1)
		{
			db_remove_file_def(0,data + 1);
		}
		else if (type == -3)
		{
			db_remove_file_xfer_using_keys(0,data + 1);
		}
		else if (type == PAF_CROSS_REF_CPP)
		{
			if (first_xref)
			{
				first_xref = FALSE;

				open_tables_for_cross_ref();
			}
			Paf_insert_cross_ref_qry(bufp);
		}
		else
		{
			*data = '\0';
			db_insert_entry(type,key + 1,data + 1);
		}
	}

#if TTY_TRACE
	if (tty)
	{
		fprintf(tty,"END (pid: %d) killed: %d eof: %d\n",
			(int)getpid(),killed,feof(infp));
	}
#endif /* TTY_TRACE */

	buf.free(&buf);

	if (!first_xref)
	{
		Paf_Cpp_Cross_Ref_Clean();
	}

	if (Paf_db_close_tables() == -1)
	{
		fprintf(stderr,"Database closing error: %s\n",strerror(errno));
		fflush(stderr);

		killed = -1;
	}

	if (logfp)
	{
		fprintf(logfp,"#dbimp (pid: %lu) exited\n",(unsigned long)getpid());
		fclose(logfp);
	}

	if (yyfd >= 0)
	{
		close(yyfd);
		yyfd = -1;
	}

	if (lock_file[0])
	{
		if (killed == -1)
		{
			/*
			 * Mark the project as unusable. We must not open the
			 * file with O_TRUNC, because if the disk is already full,
			 * we will get a zero size file that we cannot write.
			 */
			int	fd = open(lock_file,O_WRONLY,0666);
			if (fd != -1)
			{
				char	status_buf[500];

				/* Now, we just overwrite the file. The 0000000 pid indicates
				 * that the project is unusable.
				 */
				sprintf(status_buf,"%s %s %7d\n",
					sn_pid,
					sn_host,
					0);

				write(fd,status_buf,strlen(status_buf));

				close(fd);
			}
		}
		else
		{
			/* Delete the lock file to indicate, that we did not crash! */
			if (unlink(lock_file) == -1 && access(lock_file,F_OK) != -1)
			{
				/* Under Windows, somebody might have open the file. */
				sleep(1);

#if TTY_TRACE
				if (tty)
				{
					fprintf(tty,"Removing lock file %d\n",(int)getpid());
				}
#endif /* TTY_TRACE */
				unlink(lock_file);
			}
		}
	}

	fclose(infp);	/* It is important to synchronize. */

	exit(killed == -1 ? 2 : 0);

	return 0;
}
Пример #3
0
Файл: parser.c Проект: JD26/ICE
int
put_cross_ref(
int     type,
int     scope_type,
int     scope_lev,
char    *fnc_cls,              /* caller class */
char    *fnc,                   /* caller function/method */
char	*fnc_arg_types,         /* caller function/method argument types */
char    *scope,                 /* referenced class */
char	*what,                  /* referenced member */
char	*arg_types,		/* referenced function/method argument types */
char	*file,
int	lineno,
int	acc)
{
	LongString	key_value;
	LongString	data_value;
	char	lineno_buf[10];

	if (!cross_ref_fp || !fnc || *fnc == '\0' ||
		(scope_lev == PAF_REF_SCOPE_LOCAL && !report_local_vars))
	{
		return -1;
	}

	MY_DEBUG2 ((Output, "put_cross_ref (%i, %i, %i, %s, %s, %s, %s, %s, %s, %s, %i, %i)\n",
					type, scope_type, scope_lev,
					fnc_cls?fnc_cls:"?",
					fnc?fnc:"?",
					fnc_arg_types?fnc_arg_types:"?", scope?scope:"?", what?what:"?",
					arg_types?arg_types:"?",	file?file:"?", lineno, acc));

	if (scope && *scope == '\0')
		scope = NULL;
	else if (scope)
	{
		char *_p;
		for (; isspace(*scope); scope++);
		
		/*
		 * It can happen, that the scope contains "class fld ",
		 * so then terminate the rest after "class" */
		if ((_p=strchr (scope, DB_FLDSEP_CHR)))
		{
			*_p = 0;
		}
		/**/
		if (*scope == '\0')
			scope = NULL;
	}
	if (fnc_cls && *fnc_cls == '\0')
		fnc_cls = NULL;
	else if (fnc_cls)
	{
		for (; isspace(*fnc_cls); fnc_cls++);
	}

	if (!file)
	{
		fprintf(stderr,"Filename must not be NULL\n");
		return -1;
	}
	if (!what || !*what)
	{
		fprintf(stderr,"Input parameter (#8) must not be NULL file: %s line: %d\n",
				file,lineno);
		return -1;
	}

	for (; isspace(*what); what++);
	for (; isspace(*file); file++);

	if (type <= 0 || type > PAF_REF_UNDEFINED)
	{
		fprintf(stderr,"Input parameter (#1) %d is not allowed\n",
			type);
		return -1;
	}

	if (scope_type <= 0 || scope_type >= PAF_VAR_DCL)
	{
		fprintf(stderr,"Input parameter (#2) %d is not allowed\n",
			scope_type);
		return -1;
	}

	LongStringInit(&key_value,0);
	LongStringInit(&data_value,0);

	if (type == PAF_MBR_FUNC_DCL)
		type = PAF_MBR_FUNC_DEF;

	sprintf(lineno_buf,"%06d",lineno);
	key_value.copystrings(&key_value,
		fnc_cls ? fnc_cls : "#",            DB_FLDSEP_STR,
		fnc,                                DB_FLDSEP_STR,
		SN_GetSymbolType(scope_type),       DB_FLDSEP_STR,
		scope ? scope : "#",                DB_FLDSEP_STR,
		what,                               DB_FLDSEP_STR,
		SN_GetSymbolType(type),             DB_FLDSEP_STR,
		acc_strings[acc],                   DB_FLDSEP_STR,
		lineno_buf,                         DB_FLDSEP_STR,
		file,
		NULL);
	data_value.copystrings(&data_value,
		fnc_arg_types ? fnc_arg_types : "", DB_FLDSEP_STR,
		arg_types ? arg_types : "",
		NULL);

	if(!scope || *scope != '?')
	{
		fprintf(cross_ref_fp, "%d%c%s%c%s\n",
			PAF_CROSS_REF, KEY_DATA_SEP_CHR,
			key_value.buf, KEY_DATA_SEP_CHR,
			data_value.buf);
	}

	key_value.free(&key_value);
	data_value.free(&data_value);

	return 0;
}