Beispiel #1
0
static bool get_ea_dos_attribute(connection_struct *conn,
				 struct smb_filename *smb_fname,
				 uint32_t *pattr)
{
	struct xattr_DOSATTRIB dosattrib;
	enum ndr_err_code ndr_err;
	DATA_BLOB blob;
	ssize_t sizeret;
	fstring attrstr;
	uint32_t dosattr;

	if (!lp_store_dos_attributes(SNUM(conn))) {
		return False;
	}

	/* Don't reset pattr to zero as we may already have filename-based attributes we
	   need to preserve. */

	sizeret = SMB_VFS_GETXATTR(conn, smb_fname->base_name,
				   SAMBA_XATTR_DOS_ATTRIB, attrstr,
				   sizeof(attrstr));
	if (sizeret == -1) {
		if (errno == ENOSYS
#if defined(ENOTSUP)
			|| errno == ENOTSUP) {
#else
				) {
#endif
			DEBUG(1,("get_ea_dos_attribute: Cannot get attribute "
				 "from EA on file %s: Error = %s\n",
				 smb_fname_str_dbg(smb_fname),
				 strerror(errno)));
			set_store_dos_attributes(SNUM(conn), False);
		}
		return False;
	}

	blob.data = (uint8_t *)attrstr;
	blob.length = sizeret;

	ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
			(ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);

	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		DEBUG(1,("get_ea_dos_attribute: bad ndr decode "
			 "from EA on file %s: Error = %s\n",
			 smb_fname_str_dbg(smb_fname),
			 ndr_errstr(ndr_err)));
		return false;
	}

	DEBUG(10,("get_ea_dos_attribute: %s attr = %s\n",
		  smb_fname_str_dbg(smb_fname), dosattrib.attrib_hex));

	switch (dosattrib.version) {
		case 0xFFFF:
			dosattr = dosattrib.info.compatinfoFFFF.attrib;
			break;
		case 1:
			dosattr = dosattrib.info.info1.attrib;
			if (!null_nttime(dosattrib.info.info1.create_time)) {
				struct timespec create_time =
					nt_time_to_unix_timespec(
						dosattrib.info.info1.create_time);

				update_stat_ex_create_time(&smb_fname->st,
							create_time);

				DEBUG(10,("get_ea_dos_attribute: file %s case 1 "
					"set btime %s\n",
					smb_fname_str_dbg(smb_fname),
					time_to_asc(convert_timespec_to_time_t(
						create_time)) ));
			}
			break;
		case 2:
			dosattr = dosattrib.info.oldinfo2.attrib;
			/* Don't know what flags to check for this case. */
			break;
		case 3:
			dosattr = dosattrib.info.info3.attrib;
			if ((dosattrib.info.info3.valid_flags & XATTR_DOSINFO_CREATE_TIME) &&
					!null_nttime(dosattrib.info.info3.create_time)) {
				struct timespec create_time =
					nt_time_to_unix_timespec(
						dosattrib.info.info3.create_time);

				update_stat_ex_create_time(&smb_fname->st,
							create_time);

				DEBUG(10,("get_ea_dos_attribute: file %s case 3 "
					"set btime %s\n",
					smb_fname_str_dbg(smb_fname),
					time_to_asc(convert_timespec_to_time_t(
						create_time)) ));
			}
			break;
		default:
			DEBUG(1,("get_ea_dos_attribute: Badly formed DOSATTRIB on "
				 "file %s - %s\n", smb_fname_str_dbg(smb_fname),
				 attrstr));
	                return false;
	}

	if (S_ISDIR(smb_fname->st.st_ex_mode)) {
		dosattr |= FILE_ATTRIBUTE_DIRECTORY;
	}
	/* FILE_ATTRIBUTE_SPARSE is valid on get but not on set. */
	*pattr = (uint32_t)(dosattr & (SAMBA_ATTRIBUTES_MASK|FILE_ATTRIBUTE_SPARSE));

	dos_mode_debug_print(__func__, *pattr);

	return True;
}

/****************************************************************************
 Set DOS attributes in an EA.
 Also sets the create time.
****************************************************************************/

static bool set_ea_dos_attribute(connection_struct *conn,
				 struct smb_filename *smb_fname,
				 uint32_t dosmode)
{
	struct xattr_DOSATTRIB dosattrib;
	enum ndr_err_code ndr_err;
	DATA_BLOB blob;

	ZERO_STRUCT(dosattrib);
	ZERO_STRUCT(blob);

	dosattrib.version = 3;
	dosattrib.info.info3.valid_flags = XATTR_DOSINFO_ATTRIB|
					XATTR_DOSINFO_CREATE_TIME;
	dosattrib.info.info3.attrib = dosmode;
	dosattrib.info.info3.create_time = unix_timespec_to_nt_time(
				smb_fname->st.st_ex_btime);

	DEBUG(10,("set_ea_dos_attributes: set attribute 0x%x, btime = %s on file %s\n",
		(unsigned int)dosmode,
		time_to_asc(convert_timespec_to_time_t(smb_fname->st.st_ex_btime)),
		smb_fname_str_dbg(smb_fname) ));

	ndr_err = ndr_push_struct_blob(
			&blob, talloc_tos(), &dosattrib,
			(ndr_push_flags_fn_t)ndr_push_xattr_DOSATTRIB);

	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		DEBUG(5, ("create_acl_blob: ndr_push_xattr_DOSATTRIB failed: %s\n",
			ndr_errstr(ndr_err)));
		return false;
	}

	if (blob.data == NULL || blob.length == 0) {
		return false;
	}

	if (SMB_VFS_SETXATTR(conn, smb_fname->base_name,
			     SAMBA_XATTR_DOS_ATTRIB, blob.data, blob.length,
			     0) == -1) {
		bool ret = false;
		bool need_close = false;
		files_struct *fsp = NULL;

		if((errno != EPERM) && (errno != EACCES)) {
			if (errno == ENOSYS
#if defined(ENOTSUP)
				|| errno == ENOTSUP) {
#else
				) {
#endif
				DEBUG(1,("set_ea_dos_attributes: Cannot set "
					 "attribute EA on file %s: Error = %s\n",
					 smb_fname_str_dbg(smb_fname),
					 strerror(errno) ));
				set_store_dos_attributes(SNUM(conn), False);
			}
			return false;
		}

		/* We want DOS semantics, ie allow non owner with write permission to change the
			bits on a file. Just like file_ntimes below.
		*/

		/* Check if we have write access. */
		if(!CAN_WRITE(conn) || !lp_dos_filemode(SNUM(conn)))
			return false;

		if (!can_write_to_file(conn, smb_fname)) {
			return false;
		}

		/*
		 * We need to get an open file handle to do the
		 * metadata operation under root.
		 */

		if (!NT_STATUS_IS_OK(get_file_handle_for_metadata(conn,
						smb_fname,
						&fsp,
						&need_close))) {
			return false;
		}

		become_root();
		if (SMB_VFS_FSETXATTR(fsp,
				     SAMBA_XATTR_DOS_ATTRIB, blob.data,
				     blob.length, 0) == 0) {
			ret = true;
		}
		unbecome_root();
		if (need_close) {
			close_file(NULL, fsp, NORMAL_CLOSE);
		}
		return ret;
	}
	DEBUG(10,("set_ea_dos_attribute: set EA 0x%x on file %s\n",
		(unsigned int)dosmode,
		smb_fname_str_dbg(smb_fname)));
	return true;
}

/****************************************************************************
 Change a unix mode to a dos mode for an ms dfs link.
****************************************************************************/

uint32_t dos_mode_msdfs(connection_struct *conn,
		      const struct smb_filename *smb_fname)
{
	uint32_t result = 0;

	DEBUG(8,("dos_mode_msdfs: %s\n", smb_fname_str_dbg(smb_fname)));

	if (!VALID_STAT(smb_fname->st)) {
		return 0;
	}

	/* First do any modifications that depend on the path name. */
	/* hide files with a name starting with a . */
	if (lp_hide_dot_files(SNUM(conn))) {
		const char *p = strrchr_m(smb_fname->base_name, '/');
		if (p) {
			p++;
		} else {
			p = smb_fname->base_name;
		}

		/* Only . and .. are not hidden. */
		if (p[0] == '.' && !((p[1] == '\0') ||
				(p[1] == '.' && p[2] == '\0'))) {
			result |= FILE_ATTRIBUTE_HIDDEN;
		}
	}

	result |= dos_mode_from_sbuf(conn, smb_fname);

	/* Optimization : Only call is_hidden_path if it's not already
	   hidden. */
	if (!(result & FILE_ATTRIBUTE_HIDDEN) &&
	    IS_HIDDEN_PATH(conn, smb_fname->base_name)) {
		result |= FILE_ATTRIBUTE_HIDDEN;
	}

	if (result == 0) {
		result = FILE_ATTRIBUTE_NORMAL;
	}

	result = filter_mode_by_protocol(result);

	/*
	 * Add in that it is a reparse point
	 */
	result |= FILE_ATTRIBUTE_REPARSE_POINT;

	dos_mode_debug_print(__func__, result);

	return(result);
}
Beispiel #2
0
void X264_end()
{
	encoder_end(&g_X264Encoder);
	close_file();
	free(YUVframe);	
}
Beispiel #3
0
FileVorbis::~FileVorbis()
{
	close_file();
}
Beispiel #4
0
/*----------------------------------------------------------------------*/
void
makeincludeindex(void)
{
	FILE *PIPE;
	STRBUF *input = strbuf_open(0);
	char *ctags_x;
	struct data *inc;
	char *target = (Fflag) ? "mains" : "_top";
	char command[MAXFILLEN];

	/*
	 * Pick up include pattern.
	 *
	 * C: #include "xxx.h"
	 * PHP: include("xxx.inc.php");
	 */
	/*
	 * Unlike Perl regular expression, POSIX regular expression doesn't support C-style escape sequence.
	 * Therefore, we can not use "\\t" here.
	 */
	snprintf(command, sizeof(command), PQUOTE "%s -gnx --encode-path=\" \t\" \"^[ \t]*(#[ \t]*(import|include)|include[ \t]*\\()\"" PQUOTE, quote_shell(global_path));
	if ((PIPE = popen(command, "r")) == NULL)
		die("cannot execute '%s'.", command);
	strbuf_reset(input);
	while ((ctags_x = strbuf_fgets(input, PIPE, STRBUF_NOCRLF)) != NULL) {
		SPLIT ptable;
		char buf[MAXBUFLEN];
		int is_php = 0;
		const char *last, *lang, *suffix;

		if (split(ctags_x, 4, &ptable) < 4) {
			recover(&ptable);
			die("too small number of parts in makefileindex().");
		}
		if ((suffix = locatestring(ptable.part[PART_PATH].start, ".", MATCH_LAST)) != NULL
		    && (lang = decide_lang(suffix)) != NULL
		    && strcmp(lang, "php") == 0)
			is_php = 1;
		last = extract_lastname(ptable.part[PART_LINE].start, is_php);
		if (last == NULL || (inc = get_inc(last)) == NULL)
			continue;
		recover(&ptable);
		/*
		 * s/^[^ \t]+/$last/;
		 */
		{
			const char *p;
			char *q = buf;

			for (p = last; *p; p++)
				*q++ = *p;
			for (p = ctags_x; *p && *p != ' ' && *p != '\t'; p++)
				;
			for (; *p; p++)
				*q++ = *p;
			*q = '\0';
		}
		put_included(inc, buf);
	}
	if (pclose(PIPE) != 0)
		die("terminated abnormally '%s' (errno = %d).", command, errno);

	for (inc = first_inc(); inc; inc = next_inc()) {
		const char *last = inc->name;
		int no = inc->id;
		FILEOP *fileop_INCLUDE;
		FILE *INCLUDE;

		if (inc->count > 1) {
			char path[MAXPATHLEN];

			snprintf(path, sizeof(path), "%s/%s/%d.%s", distpath, INCS, no, HTML);
			fileop_INCLUDE = open_output_file(path, 0);
			INCLUDE = get_descripter(fileop_INCLUDE);
			fputs_nl(gen_page_begin(last, SUBDIR), INCLUDE);
			fputs_nl(body_begin, INCLUDE);
			fputs_nl(verbatim_begin, INCLUDE);
			{
				const char *filename = strbuf_value(inc->contents);
				int count = inc->count;

				for (; count; filename += strlen(filename) + 1, count--) {
					fputs(gen_href_begin_with_title_target(upperdir(SRCS), path2fid(filename), HTML, NULL, NULL, target), INCLUDE);
					fputs(removedotslash(filename), INCLUDE);
					fputs_nl(gen_href_end(), INCLUDE);
				}
			}
			fputs_nl(verbatim_end, INCLUDE);
			fputs_nl(body_end, INCLUDE);
			fputs_nl(gen_page_end(), INCLUDE);
			close_file(fileop_INCLUDE);
			html_count++;
			/*
			 * inc->contents == NULL means that information already
			 * written to file.
			 */
			strbuf_close(inc->contents);
			inc->contents = NULL;
		}
		if (!inc->ref_count)
			continue;
		if (inc->ref_count == 1) {
			SPLIT ptable;
			char buf[1024];

			if (split(strbuf_value(inc->ref_contents), 4, &ptable) < 4) {
				recover(&ptable);
				die("too small number of parts in makefileindex().");
			}
			snprintf(buf, sizeof(buf), "%s %s", ptable.part[PART_LNO].start, decode_path(ptable.part[PART_PATH].start));
			recover(&ptable);
			strbuf_reset(inc->ref_contents);
			strbuf_puts(inc->ref_contents, buf);
		} else {
			char path[MAXPATHLEN];

			snprintf(path, sizeof(path), "%s/%s/%d.%s", distpath, INCREFS, no, HTML);
			fileop_INCLUDE = open_output_file(path, 0);
			INCLUDE = get_descripter(fileop_INCLUDE);
			fputs_nl(gen_page_begin(last, SUBDIR), INCLUDE);
			fputs_nl(body_begin, INCLUDE);
			fputs_nl(gen_list_begin(), INCLUDE);
			{
				const char *line = strbuf_value(inc->ref_contents);
				int count = inc->ref_count;

				for (; count; line += strlen(line) + 1, count--)
					fputs_nl(gen_list_body(upperdir(SRCS), line, NULL), INCLUDE);
			}
			fputs_nl(gen_list_end(), INCLUDE);
			fputs_nl(body_end, INCLUDE);
			fputs_nl(gen_page_end(), INCLUDE);
			close_file(fileop_INCLUDE);
			html_count++;
			/*
			 * inc->ref_contents == NULL means that information already
			 * written to file.
			 */
			strbuf_close(inc->ref_contents);
			inc->ref_contents = NULL;
		}
	}
	strbuf_close(input);
}
Beispiel #5
0
void
memory_error(char *object_name)
{
	printf("Error: could not allocate memory for %s\n", object_name);
	close_file();
}
Beispiel #6
0
/* store the contents of this packet to its place in its file */
void store_packet(flow_t flow, flow_state_t *state, const u_char *data,
		  u_int32_t length, u_int32_t seq, int syn_set)
{
  tcp_seq offset;
  long fpos;

  /* If we got a SYN reset the sequence number */
  if (syn_set) {
    DEBUG(50) ("resetting isn due to extra SYN");
    state->isn = seq - state->pos + 1;
  }

  /* if we're done collecting for this flow, return now */
  if (IS_SET(state->flags, FLOW_FINISHED))
    return;

  /* calculate the offset into this flow -- should handle seq num
   * wrapping correctly because tcp_seq is the right size */
  offset = seq - state->isn;

  /* I want to guard against receiving a packet with a sequence number
   * slightly less than what we consider the ISN to be; the max
   * (though admittedly non-scaled) window of 64K should be enough */
  if (offset >= 0xffff0000) {
    DEBUG(2) ("dropped packet with seq < isn on %s", flow_filename(flow));
    return;
  }

  /* reject this packet if it falls entirely outside of the range of
   * bytes we want to receive for the flow */
  if (bytes_per_flow && (offset > bytes_per_flow))
    return;

  /* if we don't have a file open for this flow, try to open it.
   * return if the open fails.  Note that we don't have to explicitly
   * save the return value because open_file() puts the file pointer
   * into the structure for us. */
  if (state->fp == NULL) {
    if (open_file(state) == NULL) {
      return;
    }
  }

  /* We are go for launch!  Everything's ready for us to do a write. */

  /* reduce length if it goes beyond the number of bytes per flow */
  if (bytes_per_flow && (offset + length > bytes_per_flow)) {
    SET_BIT(state->flags, FLOW_FINISHED);
    length = bytes_per_flow - offset;
  }

  /* if we're not at the correct point in the file, seek there */
  if (offset != state->pos) {
    fpos = offset;
    FSETPOS(state->fp, &fpos);
  }

  /* write the data into the file */
  DEBUG(25) ("%s: writing %ld bytes @%ld", flow_filename(state->flow),
	  (long) length, (long) offset);

  if (fwrite(data, length, 1, state->fp) != 1) {
    /* sigh... this should be a nice, plain DEBUG statement that
     * passes strerrror() as an argument, but SunOS 4.1.3 doesn't seem
     * to have strerror. */
    if (debug_level >= 1) {
      DEBUG(1) ("write to %s failed: ", flow_filename(state->flow));
      perror("");
    }
  }
  fflush(state->fp);

  /* remember the position for next time */
  state->pos = offset + length;

  if (IS_SET(state->flags, FLOW_FINISHED)) {
    DEBUG(5) ("%s: stopping capture", flow_filename(state->flow));
    close_file(state);
  }
}
Beispiel #7
0
int
main(int argc, char **argv, char **envp)
{
	int	i;

	scale_init(argc, argv);

#define ALIGNMENTOFFSET 2 /* adjust alignment */
        i = sizeof(workStruct_t)*
            (narrays+ALIGNMENTOFFSET);
        element = memalign(64, i);
	if ( element == NULL ) {
	    perror("calloc( narrays, sizeof(workStruct_t) )");
	    exit(1);
	}
        compute_set(element);
        memset(element, 0, i);
        element+=ALIGNMENTOFFSET;

#ifdef SELFTEST
	start_prof();
#endif

	fid = open_output("mttest.acct");
	if (job_index == -1) {
		i = (sizeof(scripttab)/sizeof( struct scripttab) -1 );
	} else {
		i = 1;
	}
	fprintf(fid, "Number of tests: %d  Repeat count: %d\n",
		i, repeat_count);

	fprintf(fid, "MHz: %d\n", get_clock_rate() );

	fprintf(fid,
	    "X    Incl. Total   Incl. CPU   Incl. Sync. Wait   Name (%s)\n",
		model);
	fflush(fid);
  
	name = strdup(argv[0]);

	init_micro_acct();
#if OS(Solaris) 
	if(uniprocessor != 0) {
	    /* call processor_bind to force single CPU */
	    processor_bind(P_PID, P_MYID, cpuid, NULL);
	}
#endif /* OS(Solaris) */

#ifdef SOLARIS
	sema_init(&global_sema_lock, count, USYNC_THREAD, NULL);
#endif
#ifdef POSIX
	pthread_attr_init(&attr);

    #ifdef BOUND
	pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
    #endif

	sem_init(&global_sema_lock, 0, count);
#endif

#if 0
	if ((s5_sema_id = semget(IPC_PRIVATE, 1, 0600)) == -1)
		perror("semget: IPC_PRIVATE");

	arg.val = count;
	if (semctl(s5_sema_id, 0, SETVAL, arg) == -1)
		perror("semctl: SETVAL");
#endif

	resolve_symbols();

	i = locktest();
#if 0
	if (semctl(s5_sema_id, 0, IPC_RMID) == -1)
		perror("semctl: IPC_RMID");
#endif

	close_file(fid);

#ifdef SELFTEST
        finish_prof();
#endif

	return 0;
}
Beispiel #8
0
/*
 * Scan an initial sequence of comment lines looking for font and memory
 * usage specifications.  This does not handle the "atend" construction.
 */
void
scanfontcomments(const char *filename)
{
   char p[500];
   char *r;
   FILE *f;
   integer truecost = pagecost;
   Boolean trueknown = 0;
   fontdesctype *oldcf = curfnt;

#ifdef DEBUG
      if (dd(D_FONTS))
         fprintf(stderr,
		       "Checking for fonts in '%s'\n",filename);
#endif  /* DEBUG */

   if (*filename == '`') {
/*
 *   Allow scanning of ` commands.  Better return same results both times.
 */
      f = popen(filename+1, "r");
      SET_BINARY(fileno(f));
      to_close = USE_PCLOSE;
   } else {
      f = search(figpath, filename, READ);
   }
   if (f) {
     SET_BINARY(fileno(f));
     fc_state = 0;
     check_atend = 0;
     while (fgets(p,500,f) && p[0]=='%' &&
            (p[1]=='!' || p[1]=='%' || p[1]=='*')) {
       if (strncmp(p, "%*Font:", 7) == 0) {
	 scan1fontcomment(p+7);
       } else if (strncmp(p, "%%VMusage:", 9) == 0) {
	 truecost += scanvm(p+10);
	 trueknown = 1;
       }
       scanfontusage(p,filename);
     }
     if (trueknown)
       pagecost = truecost;

     if(check_atend) {
#ifdef DEBUG
       if (dd(D_FONTS))
         fprintf(stderr,
		       "Checking for (atend) fonts in '%s'\n",filename);
#endif  /* DEBUG */

       fc_state = 0;

       fseek(f,-4096,2); /* seek to 4096 bytes before EOF. */
       fgets(p,500,f); /* throw away a partial line. */

       /* find %%Trailer */
       while((r=fgets(p,500,f)) && strncmp(p,"%%Trailer",9));

       /* look for specs that were deferred to the trailer. */
       if(r != NULL) {
	 while(fgets(p,500,f)) {
	   if(p[0]=='%' && p[1]=='%') scanfontusage(p,filename);
	 }
       }
#ifdef DEBUG
       else { /* r == NULL */
	 if (dd(D_FONTS))
         fprintf(stderr,
		       "Did not find %%%%Trailer in included file '%s'.\n",
		       filename);
       }
#endif  /* DEBUG */
     }
     close_file(f);
   }
   curfnt = oldcf;
}
Beispiel #9
0
bool
output_sgf (const char *filename)
{
    int current = -1;
    union prop_data_t temp_data;
    int saved = current_node;

    sgf_fd = create_or_open_file (filename);

    if (sgf_fd < 0)
    {
        return false;
    }

    DEBUGF ("outputting to: %s (%d)\n", filename, sgf_fd);

    empty_stack (&parse_stack);

    rb->lseek (sgf_fd, 0, SEEK_SET);
    rb->ftruncate (sgf_fd, 0);

    if (sgf_fd < 0)
    {
        return false;
    }

    if (tree_head < 0)
    {
        close_file (&sgf_fd);
        return false;
    }

    push_int_stack (&parse_stack, tree_head);

    while (pop_int_stack (&parse_stack, &current))
    {
        int var_to_process = 0;
        int temp_prop =
            get_prop_sgf (current, PROP_VARIATION_TO_PROCESS, NULL);

        if (temp_prop >= 0)
        {
            var_to_process = get_prop (temp_prop)->data.number;
        }

        current_node = current;

        if (var_to_process > 0)
        {
            write_char (sgf_fd, ')');
        }

        if (var_to_process == stupid_num_variations ())
        {
            delete_prop_sgf (current, PROP_VARIATION_TO_PROCESS);

            continue;
        }
        else
        {
            write_char (sgf_fd, '\n');
            write_char (sgf_fd, '(');

            /* we need to do more processing on this branchpoint, either
               to do more variations or to output the ')' */
            push_int_stack (&parse_stack, current);

            /* increment the stored variation to process */
            temp_data.number = var_to_process + 1;
            add_or_set_prop_sgf (current,
                                 PROP_VARIATION_TO_PROCESS, temp_data);
        }

        rb->yield ();

        /* now we did the setup for sibling varaitions to be processed so
           do the actual outputting of a game tree branch */

        go_to_variation_sgf (var_to_process);
        output_gametree ();
    }

    current_node = saved;
    close_file (&sgf_fd);
    DEBUGF ("done outputting, file closed\n");
    return true;
}
Beispiel #10
0
hdf5io::~hdf5io()
{
     close_file();
}
Beispiel #11
0
int main(void)
{
  u32 cc,bb;
  u16 COUNT;
  u8 a,ATTR,j;
  u8 HANDLE1; 
  u8 buf[65535];
  u8 ddd[] = "c:\\ok\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAaaaaaaaaa.rar";
  
  //初始化虚拟磁盘的驱动
  flash_management_sysinit();
  FAT_filesystem_autoformat(0,FAT16,483328);
  FAT_filesystem_initialiation();

  //调用函数volume_inquiry,查询分区容量和剩余空间
  volume_inquiry('c',&cc,&bb);

  //打印虚拟磁盘分区容量和剩余空间
  printf("Volume Capacity: %ld\n",cc);
  printf("Volume FreeSpace: %ld\n",bb);
  scanf("%c",&a);

  /*建立目录CREATE_FOLDER_TEST,用于测试建立目录函数create_floder()*/

  create_floder("CREATE_FOLDER_TEST");
  create_floder("CREATE_FOLDER_TEST");//目录再建失败, 不可以建重复的目录


  /*目录建立测试*/
  create_floder("a");
  create_floder("a\\b");
  create_floder("a\\b\\c");
  create_floder("a\\b\\c\\d");


  /*建文件在目录CREATE_FOLDER_TEST下,用于测试建立文件函数create_file()*/
  
  create_file("C:\\CREATE_FOLDER_TEST\\created_file.txt");

  create_file("C:\\CREATE_FOLDER_TEST\\created_file.txt");//文件再建失败,不可以建重复的文件


  /* 重命名文件CREATE_FOLDER_TEST\\created_file.txt为"created_file_new.txt",用于测试文件重命名函数rename_file() */
  rename_file("C:\\CREATE_FOLDER_TEST\\created_file.txt","created_file_new.txt");
	
  /*  读取目录CREATE_FOLDER_TEST下面的所有ENTRY,打印出来到屏幕*/
  cd_folder("CREATE_FOLDER_TEST",0);
 
  a = 0; //枚举模式初始设定
  while(folder_enumeration(buf,a,&ATTR) == SUCC)
  { 
      //打印读取的Directory ENTRY及其attribute
	  printf("\nreaded entry=%s Attr = %x",buf,ATTR);

     if(a == 0)
	   a = 1;//枚举模式修改为枚举继续
  }

  scanf("%c",&a);	

  cd_folder(" ",1); //返回到根目录

  /*  读取根目录的所有ENTRY,打印出来到屏幕  */

  a = 0;//枚举模式初始设定
  while(folder_enumeration(buf,a,&ATTR) == SUCC)
  { 
	  //打印读取的Directory ENTRY及其attribute
     printf("\nreaded entry=%s Attr = %x",buf,ATTR);

     if(a == 0)
	   a = 1;//枚举模式修改为枚举继续
  }

  scanf("%c",&a);	 

  /* 建立一个OK目录,之后向其写文件readed.rar,直到虚拟盘被写满 */ 
  create_floder("OK");

  j = 0;
  COUNT = 0;
  do{
  for(a = 0;a<25;a++)
  {
  COUNT++;
  //调用create_file()往磁盘上建立文件 
  if(create_file(ddd) == SUCC)
  {
   printf("Create file %s successfully\n",ddd);
   
   HANDLE1 = open_file(ddd);//打开刚刚完成建立的文件

   //打开readed.rar,作为写入源文件
   if ((file2 = fopen("readed.rar","rb+")) == NULL)
     {
      return 0;
     }
   if(HANDLE1 != FAIL)
	{   
		//将readed.rar拷入刚刚建立的文件   
		printf("\nOpen File %s successfully",ddd);
		do{
            printf("x");
			//从readed.rar里读数据
            cc = fread(buf,1,40000,file2);  
	        //读数据后拷入刚刚建立的文件 
			write_file(HANDLE1,buf, cc);
		    if(cc < 40000)
			    break;
		}while(1);
		//拷贝整个文件到结束,之后关闭文件
		close_file(HANDLE1);   
		fclose(file2);
	}

  }
  else
   printf("Create file %s failed\n",ddd);
   ddd[6+j] ++; 
  }
  j++;
 }while(j< 40);



  /*把虚拟磁盘上的所有的文件与目录分离到WINDOWS下*/
 
  a = 0;//枚举模式初始设定
  while(disk_enumeration(buf,a,&ATTR) == SUCC)
  { 
     printf("\nreaded entry=%s Attr = %x",buf,ATTR);
     
     if(a == 0)
	   a = 1;	//枚举模式修改为枚举继续

	 if(ATTR & ATTR_DIRECTORY)
	 { 
	   //mkdir(buf+3);
	   continue;
	 }
	 else
     {   //在windows当前目录下建立一个文件,文件名与当前枚举的文件名一致*/
		 if ((file2 = fopen(buf+3,"wb+")) == NULL)
		 {  
            return 0;
		 }    
	     else 
		     HANDLE1 = open_file(buf);
	 }//读数据后拷入刚刚建立的文件 
	if(HANDLE1 != FAIL)
		do{	
	    //从当前的文件读取数据
	    cc = read_file(HANDLE1,buf+400,50000);
		printf("\nreaded chars = %ld ",cc);
        //读数据后拷入刚刚建立的文件
		fwrite(buf+400,1,cc,file2);
		if(cc != 50000)
		{ 
			close_file(HANDLE1);
		    break;   
		}   
	
	}while(1);
    else{
	}
    fclose(file2);	 
  }

  scanf("%c",&a);	
}
Beispiel #12
0
LRESULT CALLBACK view_context_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static HWND grippy=0;
	int lines,dir,do_scroll=FALSE,update_scroll_pos=TRUE;
	static int divider_drag=FALSE,org_row_width=90,row_width=90,last_pos=0;
#ifdef _DEBUG
	if(FALSE)
//	if(message!=0x200&&message!=0x84&&message!=0x20&&message!=WM_ENTERIDLE)
//	if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_DRAWITEM
//		&&msg!=WM_CTLCOLORBTN&&msg!=WM_CTLCOLOREDIT&&msg!=WM_CTLCOLORSCROLLBAR)
	if(msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		printf("v");
		print_msg(msg,lparam,wparam);
		tick=GetTickCount();
	}
#endif	
	switch(msg)
	{
	case WM_INITDIALOG:
		grippy=create_grippy(hwnd);
		init_context_win_anchor(hwnd);
		get_ini_value("CONTEXT_WINDOW","row_width",&row_width);
		set_context_divider(hwnd,row_width);
		restore_context_rel_pos(hwnd);

		SendDlgItemMessage(hwnd,IDC_CONTEXT_SCROLLBAR,SBM_SETRANGE,0,10000);
		{
			int tabstop=21; //4 fixed chars
			SendDlgItemMessage(hwnd,IDC_CONTEXT,EM_SETTABSTOPS,1,&tabstop);
		}
		set_context_font(hwnd);
		open_file(&gfh);
		if(gfh==0){
			WCHAR str[MAX_PATH*2];
			_snwprintf(str,sizeof(str)/sizeof(WCHAR),L"cant open %s",fname);
			str[sizeof(str)/sizeof(WCHAR)-1]=0;
			MessageBoxW(hwnd,str,L"error",MB_OK);
			EndDialog(hwnd,0);
			return 0;
		}
		get_file_size(gfh,&fsize);
		_fseeki64(gfh,start_offset,SEEK_SET);
		set_scroll_pos(hwnd,IDC_CONTEXT_SCROLLBAR,gfh);
		SetFocus(GetDlgItem(hwnd,IDC_CONTEXT_SCROLLBAR));
		line_count=get_number_of_lines(hwnd,IDC_CONTEXT);
		fill_context(hwnd,IDC_CONTEXT,gfh);
		close_file(&gfh);
		last_pos=-1;
		orig_edit=SetWindowLong(GetDlgItem(hwnd,IDC_CONTEXT),GWL_WNDPROC,subclass_edit);
		orig_scroll=SetWindowLong(GetDlgItem(hwnd,IDC_CONTEXT_SCROLLBAR),GWL_WNDPROC,subclass_scroll);
		SetWindowTextW(hwnd,fname);
		return 0;
	case WM_DESTROY:
		save_context_rel_pos(hwnd);
		break;
	case WM_HELP:
		context_help(hwnd);
		return TRUE;
		break;
	case WM_SIZE:
		grippy_move(hwnd,grippy);
		set_context_divider(hwnd,row_width);
		line_count=get_number_of_lines(hwnd,IDC_CONTEXT);
		open_file(&gfh);
		fill_context(hwnd,IDC_CONTEXT,gfh);
		set_scroll_pos(hwnd,IDC_CONTEXT_SCROLLBAR,gfh);
		close_file(&gfh);
		break;
	case WM_RBUTTONDOWN:
	case WM_LBUTTONUP:
		ReleaseCapture();
		if(divider_drag){
			write_ini_value("CONTEXT_WINDOW","row_width",row_width);
			divider_drag=FALSE;
		}
		break;
	case WM_LBUTTONDOWN:
		SetCapture(hwnd);
		SetCursor(LoadCursor(NULL,IDC_SIZEWE));
		divider_drag=TRUE;
		org_row_width=row_width;
		break;
	case WM_MOUSEFIRST:
		{
			int x=LOWORD(lparam);
			SetCursor(LoadCursor(NULL,IDC_SIZEWE));
			if(divider_drag){
				RECT rect;
				GetClientRect(hwnd,&rect);
				if((rect.right-x)>25 && x>5){
					row_width=x;
					set_context_divider(hwnd,row_width);
				}
			}
		}
		break;
	case WM_MOUSEWHEEL:
		{
			short wheel=HIWORD(wparam);
			int flags=LOWORD(wparam);
			if(wheel>0){
				dir=-1;
				if(flags&MK_RBUTTON)
					lines=line_count-2;
				else
					lines=3+1;
			}
			else{
				dir=1;
				if(flags&MK_RBUTTON)
					lines=line_count-2-1;
				else
					lines=3;
			}
			do_scroll=TRUE;
		}
		break;
	case WM_VSCROLL:
		{
		int pos=HIWORD(wparam);
		switch(LOWORD(wparam)){
		case SB_TOP:
			if(GetKeyState(VK_CONTROL)&0x8000){
				last_offset=0;
				current_line=1;
			}
			else{
				last_offset=start_offset; //_fseeki64(f,start_offset,SEEK_SET);
				current_line=start_line;
			}
			lines=dir=0;
			do_scroll=TRUE;
			break;
		case SB_PAGEUP:
			dir=-1;
			lines=line_count-2;
			if(lines<=0)
				lines=1;
			do_scroll=TRUE;
			break;
		case SB_PAGEDOWN:
			dir=1;
			lines=line_count-2-1;
			if(lines<=0)
				lines=1;
			do_scroll=TRUE;
			break;
		case SB_LINEUP:
			dir=-1;
			lines=2;
			do_scroll=TRUE;
			break;
		case SB_LINEDOWN:
			dir=1;
			lines=1;
			do_scroll=TRUE;
			break;
		case SB_THUMBTRACK:
			//printf("pos=%i last_pos=%i scroll_pos=%i line_count=%i\n",HIWORD(wparam),last_pos,scroll_pos,line_count);
			if(pos<last_pos){
				dir=-1;
				lines=line_count/4;
				if(lines<=1)
					lines=2;
				do_scroll=TRUE;
			}
			else if(pos>last_pos){
				dir=1;
				lines=line_count/4;
				if(lines==0)
					lines=1;
				do_scroll=TRUE;
			}
			if(last_pos==-1)
				do_scroll=FALSE;
			last_pos=pos;
			update_scroll_pos=FALSE;
			break;
		case SB_THUMBPOSITION: //dragged and released
			dir=lines=0;
			do_scroll=TRUE;
			break;
		case SB_ENDSCROLL:
			last_pos=-1;
			break;
		}
		}
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDCANCEL:
			if(divider_drag){
				divider_drag=FALSE;
				ReleaseCapture();
				set_context_divider(hwnd,org_row_width);
				row_width=org_row_width;
				return 0;
			}
			if(gfh!=0)
				fclose(gfh);
			gfh=0;
			if(orig_edit!=0)SetWindowLong(GetDlgItem(hwnd,IDC_CONTEXT),GWL_WNDPROC,orig_edit);
			EndDialog(hwnd,0);
			return 0;
		}
		break;
	}
	if(do_scroll)
		do_scroll_proc(hwnd,lines,dir,update_scroll_pos);
	return 0;
}
Beispiel #13
0
int main(int argc, char *argv[])
{
   char *pname, *tagfile1, *tagfile2, *outtag, *history;
   Real **tags1, **tags2, **new_tags, *this_tag;
   int n_volumes1, n_volumes2, n_tag_points1, n_tag_points2;
   int ipoint1, ipoint2, icoord, near_tag;
   STRING *labels1, *labels2, *new_labels, this_label;
   double min_distsq, distsq, diff, maximum_distsq;
   size_t string_length;
   FILE *fp;
   char dist_string[64];

   /* Save history */
   history = time_stamp(argc, argv);

   /* Parse arguments */
   pname = argv[0];
   if (ParseArgv(&argc, argv, argTable, 0) || (argc != 4)) {
      (void) fprintf(stderr, 
                     "\nUsage: %s [<options>] infile1.tag file2.tag outfile2.tag\n\n",
                     pname);
      exit(EXIT_FAILURE);
   }
   tagfile1 = argv[1];
   tagfile2 = argv[2];
   outtag = argv[3];
   maximum_distsq = maximum_distance * maximum_distance;

   /* Read in first tag file */
   if ((open_file_with_default_suffix(tagfile1,
                  get_default_tag_file_suffix(),
                  READ_FILE, ASCII_FORMAT, &fp) != OK) ||
       (input_tag_points(fp, &n_volumes1, &n_tag_points1, 
                         &tags1, NULL, 
                         NULL, NULL, NULL, &labels1) != OK)) {
      (void) fprintf(stderr, "%s: Error reading tag file %s\n", 
                     pname, tagfile1);
      exit(EXIT_FAILURE);
   }
   (void) close_file(fp);


   /* Read in second tag file */
   if ((open_file_with_default_suffix(tagfile2,
                  get_default_tag_file_suffix(),
                  READ_FILE, ASCII_FORMAT, &fp) != OK) ||
       (input_tag_points(fp, &n_volumes2, &n_tag_points2, 
                         &tags2, NULL, 
                         NULL, NULL, NULL, &labels2) != OK)) {
      (void) fprintf(stderr, "%s: Error reading tag file %s\n", 
                     pname, tagfile2);
      exit(EXIT_FAILURE);
   }
   (void) close_file(fp);

   /* Allocate space for output tags */
   new_tags = MALLOC(n_tag_points1 * sizeof(*new_tags));
   new_labels = MALLOC(n_tag_points1 * sizeof(*new_labels));

   /* Loop through tags in first file */
   for (ipoint1=0; ipoint1 < n_tag_points1; ipoint1++) {

      /* Look for nearest tag in second file */
      min_distsq = 0.0;
      for (ipoint2=0; ipoint2 < n_tag_points2; ipoint2++) {

         /* Calculate distance-squared */
         distsq = 0;
         for (icoord=0; icoord < WORLD_NDIMS; icoord++) {
            diff = tags1[ipoint1][icoord] - tags2[ipoint2][icoord];
            distsq += diff * diff;
         }

         /* Check if this is the minimum */
         if ((ipoint2 == 0) || (min_distsq > distsq)) {
            near_tag = ipoint2;
            min_distsq = distsq;
         }

      }

      /* Save the nearest tag */
      if (min_distsq <= maximum_distsq) {
         this_tag = tags2[near_tag];
         this_label = labels2[near_tag];
      }
      else {
         this_tag = tags1[ipoint1];
         this_label = "not found";
      }
      (void) sprintf(dist_string, " (%.2f mm)", sqrt(min_distsq));
      new_tags[ipoint1] = this_tag;
      string_length = strlen(labels1[ipoint1]) + strlen(this_label) + 
         strlen(SEP_STRING) + strlen(dist_string) + 1;
      new_labels[ipoint1] = MALLOC(string_length);
      (void) strcpy(new_labels[ipoint1], labels1[ipoint1]);
      (void) strcat(new_labels[ipoint1], SEP_STRING);
      (void) strcat(new_labels[ipoint1], this_label);
      (void) strcat(new_labels[ipoint1], dist_string);

   }

   if (output_tag_file(outtag, history, 2, n_tag_points1, 
                       tags1, new_tags, 
                       NULL, NULL, NULL, new_labels) != OK) {
      (void) fprintf(stderr, "Error writing out labels\n");
      return EXIT_FAILURE;
   }
   return EXIT_SUCCESS;
}
Beispiel #14
0
int file_set_dosmode(connection_struct *conn, struct smb_filename *smb_fname,
		     uint32_t dosmode, const char *parent_dir, bool newfile)
{
	int mask=0;
	mode_t tmp;
	mode_t unixmode;
	int ret = -1, lret = -1;
	uint32_t old_mode;
	struct timespec new_create_timespec;
	files_struct *fsp = NULL;
	bool need_close = false;
	NTSTATUS status;

	if (!CAN_WRITE(conn)) {
		errno = EROFS;
		return -1;
	}

	/* We only allow READONLY|HIDDEN|SYSTEM|DIRECTORY|ARCHIVE here. */
	dosmode &= (SAMBA_ATTRIBUTES_MASK | FILE_ATTRIBUTE_OFFLINE);

	DEBUG(10,("file_set_dosmode: setting dos mode 0x%x on file %s\n",
		  dosmode, smb_fname_str_dbg(smb_fname)));

	unixmode = smb_fname->st.st_ex_mode;

	get_acl_group_bits(conn, smb_fname->base_name,
			   &smb_fname->st.st_ex_mode);

	if (S_ISDIR(smb_fname->st.st_ex_mode))
		dosmode |= FILE_ATTRIBUTE_DIRECTORY;
	else
		dosmode &= ~FILE_ATTRIBUTE_DIRECTORY;

	new_create_timespec = smb_fname->st.st_ex_btime;

	old_mode = dos_mode(conn, smb_fname);

	if ((dosmode & FILE_ATTRIBUTE_OFFLINE) &&
	    !(old_mode & FILE_ATTRIBUTE_OFFLINE)) {
		lret = SMB_VFS_SET_OFFLINE(conn, smb_fname);
		if (lret == -1) {
			if (errno == ENOTSUP) {
				DEBUG(10, ("Setting FILE_ATTRIBUTE_OFFLINE for "
					   "%s/%s is not supported.\n",
					   parent_dir,
					   smb_fname_str_dbg(smb_fname)));
			} else {
				DEBUG(0, ("An error occurred while setting "
					  "FILE_ATTRIBUTE_OFFLINE for "
					  "%s/%s: %s", parent_dir,
					  smb_fname_str_dbg(smb_fname),
					  strerror(errno)));
			}
		}
	}

	dosmode  &= ~FILE_ATTRIBUTE_OFFLINE;
	old_mode &= ~FILE_ATTRIBUTE_OFFLINE;

	smb_fname->st.st_ex_btime = new_create_timespec;

	/* Store the DOS attributes in an EA by preference. */
	if (lp_store_dos_attributes(SNUM(conn))) {
		/*
		 * Don't fall back to using UNIX modes. Finally
		 * follow the smb.conf manpage.
		 */
		if (!set_ea_dos_attribute(conn, smb_fname, dosmode)) {
			return -1;
		}
		if (!newfile) {
			notify_fname(conn, NOTIFY_ACTION_MODIFIED,
				     FILE_NOTIFY_CHANGE_ATTRIBUTES,
				     smb_fname->base_name);
		}
		smb_fname->st.st_ex_mode = unixmode;
		return 0;
	}

	unixmode = unix_mode(conn, dosmode, smb_fname, parent_dir);

	/* preserve the file type bits */
	mask |= S_IFMT;

	/* preserve the s bits */
	mask |= (S_ISUID | S_ISGID);

	/* preserve the t bit */
#ifdef S_ISVTX
	mask |= S_ISVTX;
#endif

	/* possibly preserve the x bits */
	if (!MAP_ARCHIVE(conn))
		mask |= S_IXUSR;
	if (!MAP_SYSTEM(conn))
		mask |= S_IXGRP;
	if (!MAP_HIDDEN(conn))
		mask |= S_IXOTH;

	unixmode |= (smb_fname->st.st_ex_mode & mask);

	/* if we previously had any r bits set then leave them alone */
	if ((tmp = smb_fname->st.st_ex_mode & (S_IRUSR|S_IRGRP|S_IROTH))) {
		unixmode &= ~(S_IRUSR|S_IRGRP|S_IROTH);
		unixmode |= tmp;
	}

	/* if we previously had any w bits set then leave them alone 
		whilst adding in the new w bits, if the new mode is not rdonly */
	if (!IS_DOS_READONLY(dosmode)) {
		unixmode |= (smb_fname->st.st_ex_mode & (S_IWUSR|S_IWGRP|S_IWOTH));
	}

	/*
	 * From the chmod 2 man page:
	 *
	 * "If the calling process is not privileged, and the group of the file
	 * does not match the effective group ID of the process or one of its
	 * supplementary group IDs, the S_ISGID bit will be turned off, but
	 * this will not cause an error to be returned."
	 *
	 * Simply refuse to do the chmod in this case.
	 */

	if (S_ISDIR(smb_fname->st.st_ex_mode) && (unixmode & S_ISGID) &&
			geteuid() != sec_initial_uid() &&
			!current_user_in_group(conn, smb_fname->st.st_ex_gid)) {
		DEBUG(3,("file_set_dosmode: setgid bit cannot be "
			"set for directory %s\n",
			smb_fname_str_dbg(smb_fname)));
		errno = EPERM;
		return -1;
	}

	ret = SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode);
	if (ret == 0) {
		if(!newfile || (lret != -1)) {
			notify_fname(conn, NOTIFY_ACTION_MODIFIED,
				     FILE_NOTIFY_CHANGE_ATTRIBUTES,
				     smb_fname->base_name);
		}
		smb_fname->st.st_ex_mode = unixmode;
		return 0;
	}

	if((errno != EPERM) && (errno != EACCES))
		return -1;

	if(!lp_dos_filemode(SNUM(conn)))
		return -1;

	/* We want DOS semantics, ie allow non owner with write permission to change the
		bits on a file. Just like file_ntimes below.
	*/

	if (!can_write_to_file(conn, smb_fname)) {
		errno = EACCES;
		return -1;
	}

	/*
	 * We need to get an open file handle to do the
	 * metadata operation under root.
	 */

	status = get_file_handle_for_metadata(conn,
					      smb_fname,
					      &fsp,
					      &need_close);
	if (!NT_STATUS_IS_OK(status)) {
		errno = map_errno_from_nt_status(status);
		return -1;
	}

	become_root();
	ret = SMB_VFS_FCHMOD(fsp, unixmode);
	unbecome_root();
	if (need_close) {
		close_file(NULL, fsp, NORMAL_CLOSE);
	}
	if (!newfile) {
		notify_fname(conn, NOTIFY_ACTION_MODIFIED,
			     FILE_NOTIFY_CHANGE_ATTRIBUTES,
			     smb_fname->base_name);
	}
	if (ret == 0) {
		smb_fname->st.st_ex_mode = unixmode;
	}

	return( ret );
}
Beispiel #15
0
int main(int argc, char *argv[])
{

  static ML mst[NPTS];              /* mst of at most NPTS points */

  object_struct 
    *obj;
  lines_struct  
    *lines;
  Point 
    p;
  FILE 
    *fp;
  VIO_Status 
    stat;
  VIO_progress_struct
    progress;

  long int
    i, count, total;

  if (argc!=3) {
    print("usage: %s in_mst output.obj\n", argv[0]);
    exit(EXIT_FAILURE);
  }

  stat = open_file( argv[1] , READ_FILE, ASCII_FORMAT, &fp);
  if (stat != OK) {
    print("error: cannot open %s for input.\n", argv[1]);
    exit(EXIT_FAILURE);
  }

  count = 0L;
  total = 0L;
  while( fscanf( fp, "%d%d%f%f%f%f", 
                &mst[total].index,
                &mst[total].parent_index,
                &mst[total].xyz[0],
                &mst[total].xyz[1],
                &mst[total].xyz[2],
                &mst[total].err) != EOF ) {
    ++total;
    if ( total >= NPTS ) {
      printf("\ntoo much data!");
      fclose( fp );
      exit( 0 );
    }
  }
  if ( close_file( fp ) != OK ){
    print("error: cannot close %s.\n", argv[1]);
    exit(EXIT_FAILURE);
  }

  
  stat = open_file( argv[2] , WRITE_FILE, BINARY_FORMAT, &fp);
  if (stat != OK) {
    print("error: cannot open %s for output.\n", argv[2]);
    exit(EXIT_FAILURE);
  }
  
  obj   = create_object(LINES);
  lines = get_lines_ptr(obj);
  initialize_lines(lines, YELLOW);


  initialize_progress_report(&progress, FALSE, total+1,
                             "Building vectors");
  


  for(i=1; i<total; i++) {

  start_new_line(lines);
  
  count = mst[i].index;
  fill_Point(p, mst[count].xyz[0],mst[count].xyz[1],mst[count].xyz[2]);
  add_point_to_line(lines, &p);

  count = mst[i].parent_index;
  fill_Point(p, mst[count].xyz[0],mst[count].xyz[1],mst[count].xyz[2]);
  add_point_to_line(lines, &p);
  
  update_progress_report( &progress, i );
        
  }
  
  terminate_progress_report(&progress);
  
  print ("Saving data...\n");
  
  
  output_object(fp, ASCII_FORMAT, obj);

  close_file(fp);
  
  delete_object(obj);
  
  exit(EXIT_SUCCESS);
}
Beispiel #16
0
void menu_items_treatment (GtkWidget *Widget, guint Op)
{
  gint CurrentPage, i;

  CurrentPage = gtk_notebook_get_current_page (GTK_NOTEBOOK(MainNotebook));
  switch(Op)
    {
    case NEW                  : new_file ();                   break;
    case OPEN                 : open_file ();                  break;
    case SAVE                 : save_file ();                  break;
    case SAVE_ALL             : save_all ();                   break;
    case SAVE_AS              : save_file_as ();               break;
    case PRINT                : print_buffer ();               break;
    case CLOSE                : close_file ();                 break;
    case CLOSE_ALL            : close_all ();                  break;
    case QUIT                 : quit ();                       break;
    case UNDO                 :
      if (OpenedFilesCnt)
	{
	  proceed_undo ();
	  break;
	 } 
    case REDO                 :
      if (OpenedFilesCnt)
	{
	  proceed_redo ();
	  break;
	}
    case CUT                  :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  gtk_editable_cut_clipboard (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
	  print_msg ("Selection cut to Clipboard...");
	}
      break;
    case COPY                 :
      if (OpenedFilesCnt)
	{
	  gtk_editable_copy_clipboard
	    (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
	  print_msg ("Selection copied to Clipboard...");
	}
	break;
    case PASTE                :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  gtk_editable_paste_clipboard
	    (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
	  print_msg ("Text pasted from Clipboard...");
	}
      break;
    case CLEAR                :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  gtk_editable_delete_text
	    (GTK_EDITABLE(FPROPS(CurrentPage, Text)), 0, -1);
	  print_msg ("Buffer cleared...");
	}
      break;
    case SELECT_ALL           :
      if (OpenedFilesCnt)
	{
	  gtk_editable_select_region
	    (GTK_EDITABLE(FPROPS(CurrentPage, Text)), 0, -1);
	  print_msg ("All Text selected...");
	}
      break;
    case COMPLETE             :
      if (OpenedFilesCnt)
	auto_completion (GTK_TEXT(FPROPS(CurrentPage, Text)));
      break;
    case FIND                 :
      if (OpenedFilesCnt)
	search (FALSE);
      break;
    case REPLACE              :
      if (OpenedFilesCnt)
	search (TRUE);
      break;
    case LINE                 :
      if (OpenedFilesCnt)
	goto_line ();
      break;
    case READONLY             : toggle_readonly ();            break;
    case CONVERTER            : converter ();                  break;
    case COLOR                : color_picker ();               break;
    case INSERT_TIME          : insert_time (CurrentPage);     break;
    case TO_UPPER             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  change_case (1);
	  print_msg ("Selection converted to upper Case...");
	}
      break;
    case TO_LOWER             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  change_case (2);
	  print_msg ("Selection converted to Lower Case...");
	}
      break;
    case CAPITALIZE           :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  change_case (3);
	  print_msg ("Selection Capitalized...");
	}
      break; 
    case INVERT_CASE          :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  change_case (4);
	  print_msg ("Case inverted...");
	}
      break;
    case UNIX_DOS             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_unix_to_dos ();
	}
      break;
    case UNIX_MAC             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_unix_to_mac ();
	}
      break;
    case DOS_UNIX             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_dos_to_unix ();
	}
      break;
    case DOS_MAC              :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_dos_to_mac ();
	}
      break;
    case MAC_DOS              :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_mac_to_dos ();
	}
      break;
    case MAC_UNIX             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_mac_to_unix ();
	}
      break;
    case UNIX_DOS_ALL             :
      convert_all(conv_unix_to_dos);
      break;
    case UNIX_MAC_ALL             :
      convert_all(conv_unix_to_mac);
      break;
    case DOS_UNIX_ALL             :
      convert_all(conv_dos_to_unix);
      break;
    case DOS_MAC_ALL              :
      convert_all(conv_dos_to_mac);
      break;
    case MAC_DOS_ALL              :
      convert_all(conv_mac_to_dos);
      break;
    case MAC_UNIX_ALL             :
      convert_all(conv_mac_to_unix);
      break;
    case FILE_INFO            : file_info (CurrentPage);       break;
    case TOOLBAR              :
      if ((!ToolBarToggleDisplay) && (TOOLBAR_DISPLAY))
	ToolBarToggleDisplay = TRUE;
      else
	{
	  if (TOOLBAR_DISPLAY)
	    {
	      TOOLBAR_DISPLAY = FALSE;
	      hide_toolbar ();
	      print_msg ("Hide Tool Bar...");
	    }
	  else
	    {
	      TOOLBAR_DISPLAY = TRUE;
	      show_toolbar ();
	      if (!ToolBarToggleDisplay) ToolBarToggleDisplay = TRUE;
	      print_msg ("Display Tool Bar...");
	    }
	}
      break;
    case MSGBAR               :
      if ((!MsgBarToggleDisplay) && (MSGBAR_DISPLAY))
	MsgBarToggleDisplay = TRUE;
      else
	{
	  if (MSGBAR_DISPLAY)
	    {
	      MSGBAR_DISPLAY = FALSE;
	      hide_msgbar ();
	    }
	  else
	    {
	      MSGBAR_DISPLAY = TRUE;
	      show_msgbar ();
	      if (!MsgBarToggleDisplay) MsgBarToggleDisplay = TRUE;
	      print_msg ("Display Msg Bar...");
	    }
	}
      break;
    case WORDWRAP        :
     if ((!ToggleWordwrap) && (TOGGLE_WORDWRAP))
	ToggleWordwrap = TRUE;
      else
	{
	  if (TOGGLE_WORDWRAP)
	    {
	      TOGGLE_WORDWRAP = FALSE;
	      for (i = 0; i < OpenedFilesCnt; i++)
		gtk_text_set_word_wrap (GTK_TEXT(FPROPS(CurrentPage, Text)),
					FALSE);
	      print_msg ("Wordwrap disabled...");
	    }
	  else
	    {
	      TOGGLE_WORDWRAP = TRUE;
	      for (i = 0; i < OpenedFilesCnt; i++)
		gtk_text_set_word_wrap (GTK_TEXT(FPROPS(CurrentPage, Text)),
					TRUE);
	      if (!ToggleWordwrap) ToggleWordwrap = TRUE;
	      print_msg ("Wordwrap enabled...");
	    }
	}
      break;
    case TAB_POS_TOP          :
      TAB_POSITION = 1;
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_TOP);
      break;
    case TAB_POS_BOTTOM       :
      TAB_POSITION = 2;
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_BOTTOM);
      break;
    case TAB_POS_LEFT         :
      TAB_POSITION = 3;
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_LEFT);
      break;
    case TAB_POS_RIGHT        :
      TAB_POSITION = 4;
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_RIGHT);  
      break;
    case SCROLLBAR_POS_LEFT   :
      SCROLLBAR_POSITION = 1;
      for (i = 0; i < OpenedFilesCnt; i++)
	gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW
					   (gtk_notebook_get_nth_page
					    (GTK_NOTEBOOK(MainNotebook), i)),
					   GTK_CORNER_TOP_RIGHT);
      break;
    case SCROLLBAR_POS_RIGHT  :
      SCROLLBAR_POSITION = 2;
      for (i = 0; i < OpenedFilesCnt; i++)
	gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW
					   (gtk_notebook_get_nth_page
					    (GTK_NOTEBOOK(MainNotebook), i)),
					   GTK_CORNER_TOP_LEFT);
      break;
    case PREFS                : display_prefs (&Settings);     break;
    case HELP                 :
      print_msg ("No help available yet...");
      break;
    case ABOUT                : about ();                      break;
    }
  (void)Widget; /* avoid the "unused parameter" warning */
}
Beispiel #17
0
int
main(int argc, char *argv[])
{
	/* These are static so that they're initially zero.  */
	static char *		abbrev;
	static size_t		abbrevsize;

	register int		i;
	register bool		vflag;
	register bool		Vflag;
	register char *		cutarg;
	register char *		cuttimes;
	register time_t		cutlotime;
	register time_t		cuthitime;
	time_t			now;
	bool iflag = false;

	cutlotime = absolute_min_time;
	cuthitime = absolute_max_time;
#if HAVE_GETTEXT
	setlocale(LC_ALL, "");
#ifdef TZ_DOMAINDIR
	bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
#endif /* defined TEXTDOMAINDIR */
	textdomain(TZ_DOMAIN);
#endif /* HAVE_GETTEXT */
	progname = argv[0];
	for (i = 1; i < argc; ++i)
		if (strcmp(argv[i], "--version") == 0) {
			printf("zdump %s%s\n", PKGVERSION, TZVERSION);
			return EXIT_SUCCESS;
		} else if (strcmp(argv[i], "--help") == 0) {
			usage(stdout, EXIT_SUCCESS);
		}
	vflag = Vflag = false;
	cutarg = cuttimes = NULL;
	for (;;)
	  switch (getopt(argc, argv, "c:it:vV")) {
	  case 'c': cutarg = optarg; break;
	  case 't': cuttimes = optarg; break;
	  case 'i': iflag = true; break;
	  case 'v': vflag = true; break;
	  case 'V': Vflag = true; break;
	  case -1:
	    if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0))
	      goto arg_processing_done;
	    /* Fall through.  */
	  default:
	    usage(stderr, EXIT_FAILURE);
	  }
 arg_processing_done:;

	if (iflag | vflag | Vflag) {
		intmax_t	lo;
		intmax_t	hi;
		char *loend, *hiend;
		register intmax_t cutloyear = ZDUMP_LO_YEAR;
		register intmax_t cuthiyear = ZDUMP_HI_YEAR;
		if (cutarg != NULL) {
			lo = strtoimax(cutarg, &loend, 10);
			if (cutarg != loend && !*loend) {
				hi = lo;
				cuthiyear = hi;
			} else if (cutarg != loend && *loend == ','
				   && (hi = strtoimax(loend + 1, &hiend, 10),
				       loend + 1 != hiend && !*hiend)) {
				cutloyear = lo;
				cuthiyear = hi;
			} else {
				fprintf(stderr, _("%s: wild -c argument %s\n"),
					progname, cutarg);
				return EXIT_FAILURE;
			}
		}
		if (cutarg != NULL || cuttimes == NULL) {
			cutlotime = yeartot(cutloyear);
			cuthitime = yeartot(cuthiyear);
		}
		if (cuttimes != NULL) {
			lo = strtoimax(cuttimes, &loend, 10);
			if (cuttimes != loend && !*loend) {
				hi = lo;
				if (hi < cuthitime) {
					if (hi < absolute_min_time)
						hi = absolute_min_time;
					cuthitime = hi;
				}
			} else if (cuttimes != loend && *loend == ','
				   && (hi = strtoimax(loend + 1, &hiend, 10),
				       loend + 1 != hiend && !*hiend)) {
				if (cutlotime < lo) {
					if (absolute_max_time < lo)
						lo = absolute_max_time;
					cutlotime = lo;
				}
				if (hi < cuthitime) {
					if (hi < absolute_min_time)
						hi = absolute_min_time;
					cuthitime = hi;
				}
			} else {
				fprintf(stderr,
					_("%s: wild -t argument %s\n"),
					progname, cuttimes);
				return EXIT_FAILURE;
			}
		}
	}
	gmtzinit();
	INITIALIZE (now);
	if (! (iflag | vflag | Vflag))
	  now = time(NULL);
	longest = 0;
	for (i = optind; i < argc; i++) {
	  size_t arglen = strlen(argv[i]);
	  if (longest < arglen)
	    longest = arglen < INT_MAX ? arglen : INT_MAX;
	}

	for (i = optind; i < argc; ++i) {
		timezone_t tz = tzalloc(argv[i]);
		char const *ab;
		time_t t;
		struct tm tm, newtm;
		bool tm_ok;
		if (!tz) {
		  perror(argv[i]);
		  return EXIT_FAILURE;
		}
		if (! (iflag | vflag | Vflag)) {
			show(tz, argv[i], now, false);
			tzfree(tz);
			continue;
		}
		warned = false;
		t = absolute_min_time;
		if (! (iflag | Vflag)) {
			show(tz, argv[i], t, true);
			t += SECSPERDAY;
			show(tz, argv[i], t, true);
		}
		if (t < cutlotime)
			t = cutlotime;
		tm_ok = my_localtime_rz(tz, &t, &tm) != NULL;
		if (tm_ok) {
		  ab = saveabbr(&abbrev, &abbrevsize, &tm);
		  if (iflag) {
		    showtrans("\nTZ=%f", &tm, t, ab, argv[i]);
		    showtrans("-\t-\t%Q", &tm, t, ab, argv[i]);
		  }
		}
		while (t < cuthitime) {
		  time_t newt = ((t < absolute_max_time - SECSPERDAY / 2
				  && t + SECSPERDAY / 2 < cuthitime)
				 ? t + SECSPERDAY / 2
				 : cuthitime);
		  struct tm *newtmp = localtime_rz(tz, &newt, &newtm);
		  bool newtm_ok = newtmp != NULL;
		  if (! (tm_ok & newtm_ok
			 ? (delta(&newtm, &tm) == newt - t
			    && newtm.tm_isdst == tm.tm_isdst
			    && strcmp(abbr(&newtm), ab) == 0)
			 : tm_ok == newtm_ok)) {
		    newt = hunt(tz, argv[i], t, newt);
		    newtmp = localtime_rz(tz, &newt, &newtm);
		    newtm_ok = newtmp != NULL;
		    if (iflag)
		      showtrans("%Y-%m-%d\t%L\t%Q", newtmp, newt,
				newtm_ok ? abbr(&newtm) : NULL, argv[i]);
		    else {
		      show(tz, argv[i], newt - 1, true);
		      show(tz, argv[i], newt, true);
		    }
		  }
		  t = newt;
		  tm_ok = newtm_ok;
		  if (newtm_ok) {
		    ab = saveabbr(&abbrev, &abbrevsize, &newtm);
		    tm = newtm;
		  }
		}
		if (! (iflag | Vflag)) {
			t = absolute_max_time;
			t -= SECSPERDAY;
			show(tz, argv[i], t, true);
			t += SECSPERDAY;
			show(tz, argv[i], t, true);
		}
		tzfree(tz);
	}
	close_file(stdout);
	if (errout && (ferror(stderr) || fclose(stderr) != 0))
	  return EXIT_FAILURE;
	return EXIT_SUCCESS;
}
Beispiel #18
0
int main(int argc, char **argv)
{
    int    use_stdout = FALSE;
    int    use_stdin = FALSE;
    char  *input_name = NULL;
    char  *output_name = NULL;
    int    had_input_name = FALSE;
    int    had_output_name = FALSE;
    char  *action_switch = "None";

    EXTRACT   extract = EXTRACT_VIDEO; // What we're meant to extract
    int       input   = -1;    // Our input file descriptor
    FILE     *output  = NULL;  // The stream we're writing to (if any)
    int       max     = 0;     // The maximum number of TS packets to read (or 0)
    uint32_t  pid     = 0;     // The PID of the (single) stream to extract
    int       quiet   = FALSE; // True => be as quiet as possible
    int       verbose = FALSE; // True => output diagnostic/progress messages
    int       use_pes = FALSE;

    int    err = 0;
    int    ii = 1;

    if (argc < 2)
    {
        print_usage();
        return 0;
    }

    while (ii < argc)
    {
        if (argv[ii][0] == '-')
        {
            if (!strcmp("--help",argv[ii]) || !strcmp("-h",argv[ii]) ||
                    !strcmp("-help",argv[ii]))
            {
                print_usage();
                return 0;
            }
            else if (!strcmp("-verbose",argv[ii]) || !strcmp("-v",argv[ii]))
            {
                verbose = TRUE;
                quiet = FALSE;
            }
            else if (!strcmp("-quiet",argv[ii]) || !strcmp("-q",argv[ii]))
            {
                verbose = FALSE;
                quiet = TRUE;
            }
            else if (!strcmp("-max",argv[ii]) || !strcmp("-m",argv[ii]))
            {
                CHECKARG("ts2es",ii);
                err = int_value("ts2es",argv[ii],argv[ii+1],TRUE,10,&max);
                if (err) return 1;
                ii++;
            }
            else if (!strcmp("-pes",argv[ii]) || !strcmp("-ps",argv[ii]))
            {
                use_pes = TRUE;
            }
            else if (!strcmp("-pid",argv[ii]))
            {
                CHECKARG("ts2es",ii);
                err = unsigned_value("ts2es",argv[ii],argv[ii+1],0,&pid);
                if (err) return 1;
                ii++;
                extract = EXTRACT_PID;
            }
            else if (!strcmp("-video",argv[ii]))
            {
                extract = EXTRACT_VIDEO;
            }
            else if (!strcmp("-audio",argv[ii]))
            {
                extract = EXTRACT_AUDIO;
            }
            else if (!strcmp("-stdin",argv[ii]))
            {
                use_stdin = TRUE;
                had_input_name = TRUE;  // so to speak
            }
            else if (!strcmp("-stdout",argv[ii]))
            {
                use_stdout = TRUE;
                had_output_name = TRUE;  // so to speak
                redirect_output_stderr();
            }
            else if (!strcmp("-err",argv[ii]))
            {
                CHECKARG("ts2es",ii);
                if (!strcmp(argv[ii+1],"stderr"))
                    redirect_output_stderr();
                else if (!strcmp(argv[ii+1],"stdout"))
                    redirect_output_stdout();
                else
                {
                    fprint_err("### ts2es: "
                               "Unrecognised option '%s' to -err (not 'stdout' or"
                               " 'stderr')\n",argv[ii+1]);
                    return 1;
                }
                ii++;
            }
            else
            {
                fprint_err("### ts2es: "
                           "Unrecognised command line switch '%s'\n",argv[ii]);
                return 1;
            }
        }
        else
        {
            if (had_input_name && had_output_name)
            {
                fprint_err("### ts2es: Unexpected '%s'\n",argv[ii]);
                return 1;
            }
            else if (had_input_name)  // shouldn't do this if had -stdout
            {
                output_name = argv[ii];
                had_output_name = TRUE;
            }
            else
            {
                input_name = argv[ii];
                had_input_name = TRUE;
            }
        }
        ii++;
    }

    if (!had_input_name)
    {
        print_err("### ts2es: No input file specified\n");
        return 1;
    }

    if (!had_output_name)
    {
        fprint_err("### ts2es: "
                   "No output file specified for %s\n",action_switch);
        return 1;
    }

    // ============================================================
    // Testing PES output
    if (use_pes && extract == EXTRACT_PID)
    {
        print_err("### ts2es: -pid is not supported with -pes\n");
        return 1;
    }
    if (use_pes && use_stdout)
    {
        print_err("### ts2es: -stdout is not supported with -pes\n");
        return 1;
    }
    if (use_pes && use_stdin)
    {
        print_err("### ts2es: -stdin is not supported with -pes\n");
        return 1;
    }
    if (use_pes)
    {
        err = extract_av_via_pes(input_name,output_name,(extract==EXTRACT_VIDEO),
                                 quiet);
        if (err)
        {
            print_err("### ts2es: Error writing via PES\n");
            return 1;
        }
        return 0;
    }
    // ============================================================

    // Try to stop extraneous data ending up in our output stream
    if (use_stdout)
    {
        verbose = FALSE;
        quiet = TRUE;
    }

    if (use_stdin)
        input = STDIN_FILENO;
    else
    {
        input = open_binary_file(input_name,FALSE);
        if (input == -1)
        {
            fprint_err("### ts2es: Unable to open input file %s\n",input_name);
            return 1;
        }
    }
    if (!quiet)
        fprint_msg("Reading from %s\n",(use_stdin?"<stdin>":input_name));

    if (had_output_name)
    {
        if (use_stdout)
            output = stdout;
        else
        {
            output = fopen(output_name,"wb");
            if (output == NULL)
            {
                if (!use_stdin) (void) close_file(input);
                fprint_err("### ts2es: "
                           "Unable to open output file %s: %s\n",output_name,
                           strerror(errno));
                return 1;
            }
        }
        if (!quiet)
            fprint_msg("Writing to   %s\n",(use_stdout?"<stdout>":output_name));
    }

    if (!quiet)
    {
        if (extract == EXTRACT_PID)
            fprint_msg("Extracting packets for PID %04x (%d)\n",pid,pid);
        else
            fprint_msg("Extracting %s\n",(extract==EXTRACT_VIDEO?"video":"audio"));
    }

    if (max && !quiet)
        fprint_msg("Stopping after %d TS packets\n",max);

    if (extract == EXTRACT_PID)
        err = extract_pid(input,output,pid,max,verbose,quiet);
    else
        err = extract_av(input,output,(extract==EXTRACT_VIDEO),
                         max,verbose,quiet);
    if (err)
    {
        print_err("### ts2es: Error extracting data\n");
        if (!use_stdin)  (void) close_file(input);
        if (!use_stdout) (void) fclose(output);
        return 1;
    }

    // And tidy up when we're finished
    if (!use_stdout)
    {
        errno = 0;
        err = fclose(output);
        if (err)
        {
            fprint_err("### ts2es: Error closing output file %s: %s\n",
                       output_name,strerror(errno));
            (void) close_file(input);
            return 1;
        }
    }
    if (!use_stdin)
    {
        err = close_file(input);
        if (err)
            fprint_err("### ts2es: Error closing input file %s\n",input_name);
    }
    return 0;
}
Beispiel #19
0
/**
 * This function reads the input file and perform operation as per the
 * instruction given on each line.
 */
void read_input_file(char *filename) {
	int child, i = 0;
	char buff[MAXSIZE], first[15], second[80], port_no[6], second_name[80];
	memset(buff, 0, sizeof(buff));
	memset(first, 0, sizeof(first));
	memset(second, 0, sizeof(second));

	//open file
	FILE* fp = open_file(filename, "r");
	if (fp == NULL) {
		perror("Error opening the file. Exiting!!");
		exit(0);
	}

	while (read_line(fp, buff, sizeof(buff))) {
		//printf("Data read from file Line #%d: %s\n", i, buff);
		if (buff[0] == '#')
			continue;

		//parse each line and perform appropriate operation
		sscanf(buff, "%s %s", first, second);
		/*
		 * Key for switch case:
		 * if sum(first)== 532	=> stage
		 * if sum(first)== 531	=> nonce
		 * if sum(first)== 1292	=> start_client
		 * if sum(first)== 557	=> store
		 * if sum(first)== 630	=> search
		 */
		switch (status = sum(first)) {
		case 532:
			stage = atoi(second);
			memset(output_filename, 0, sizeof(output_filename));
			sprintf(output_filename, "stage%d.manager.out", stage);
			//open file in output stream
			out_file_stream = open_file(output_filename, "w");
			fprintf(out_file_stream, "manager port: %u\n", ntohs(tmp.sin_port));
			fflush(out_file_stream);
			break;
		case 531:
			nonce = atol(second);
			break;
		case 1292:
			printf("read_input_file: start_client %s\n", second);
			if ((child = fork()) == 0) {
				do_client();
				exit(0);
			} else {
				//non-blocking wait
				waitpid(child, 0, WNOHANG);
				if (i == 0) {
					sprintf(port_no, "%d", 0);
					memcpy(second_name, second, sizeof(second));
					memcpy(client1_name, second, sizeof(second));
				} else {
					sprintf(port_no, "%d", client_udp_ports[0]);
					memcpy(second_name, client1_name, sizeof(client1_name));
				}
				int sock_fd = handle_client(i, stage, nonce, second, port_no,
						second_name);
				if (i == 0) {
					client1_tcp_sock_fd = sock_fd;
				}
				i++;
			}
			break;
		case 557:
			/*if(stage>3)
			 sleep(1);*/
			printf("read_input_file: store %s\n", second);
			send_command_to_client(557, second);
			break;
		case 630:
			if (stage > 3)
				sleep(1);
			printf("read_input_file: search %s\n", second);
			send_command_to_client(630, second);
			break;
		}

		memset(first, 0, sizeof(first));
		memset(second, 0, sizeof(second));
	}

	//TODO incoroprate some check on the input parameters defined in the file
	/*if(!(a[0]&&a[1]&&a[2])){
	 printf("Malformed input parameter file. Exiting!!\n");
	 exit(0);
	 }*/

	//close the file stream
	close_file(fp);
}
Beispiel #20
0
int save_snapshot(struct teach_params *teach, long iter)
{
  struct entries *codes = teach->codes;
  struct snapshot_info *shot = teach->snapshot;
  struct data_entry *entry;
  eptr p;
  char filename[1024]; /* hope this is enough */
  struct file_info *fi = NULL;
  int retcode = 0;
  int bg = shot->flags & SNAPFLAG_BACKGROUND;
  int ko = shot->flags & SNAPFLAG_KEEPOPEN;

  shot->counter++;
  if (ko)
    if ((fi = shot->fi) == NULL)
      {
	if ((shot->fi = open_file(shot->filename, "w")) == NULL)
	  return 1;
	
	fi = shot->fi;
      }
    else
      fi = shot->fi;

#ifndef NO_BACKGROUND_SNAP
  if (bg)
    {
      if (shot->pid > 0)
	{
	  int statptr;
	  if (!(shot->flags & SNAPFLAG_NOWAIT))
	    {
	      /* fprintf(stderr, "Snap: waiting for pid %d\n", (int)shot->pid); */
	      /* wait for previous child before forking a new one */
	      waitpid(shot->pid, &statptr, 0);
	      shot->pid = -1;
	    }
	}

      if ((shot->pid = fork()) < 0)
	{
	  perror("save_snapshot(background):");
	  return 1;
	}
      if (shot->pid == 0)
	{
	  /* fprintf(stderr, "saving snapshot\n"); */
	}
      else
	{
	  /* fprintf(stderr, "forked pid %d\n", (int)shot->pid); */
	  return 0;
	}
    }
#endif /* NO_BACKGROUND_SNAP */

  if (fi == NULL)
    {
      /* make filename */
      sprintf(filename, shot->filename, iter);
      if ((fi = open_file(filename, "w")) == NULL)
	return 1;
    }

  if (ko)
    fprintf(fi2fp(fi), "#start %d\n", shot->counter);

  if (write_header(fi, codes))
    {
      fprintf(stderr, "save_snapshot: Error writing headers\n");
      close_file(shot->fi);
      shot->fi = NULL;
      return 1;
    }

  /* open file for writing */

  ifverbose(3)
    fprintf(stderr, "saving snapshot: file '%s', type '%s'\n", filename, 
	    get_str_by_id(snapshot_list, shot->type));

  fprintf(fi2fp(fi), "#SNAPSHOT FILE\n#iterations: %ld/%ld\n",
	  iter, teach->length);

  for (entry = rewind_entries(codes, &p); entry != NULL; entry = next_entry(&p))
    {
      if (write_entry(fi, codes, entry))
	{
	  fprintf(stderr, "save_entries: Error writing entry, aborting\n");
	  retcode = 1;
	  break;
	}
    }

  if (ko)
    {
      fprintf(fi2fp(fi), "#end\n");
      fflush(fi2fp(fi));
    }
  else
    close_file(fi);
  
#ifndef NO_BACKGROUND_SNAP
  if (bg)
    exit(retcode);
  else
#endif
    return(retcode);
}
Beispiel #21
0
static int
print_directory(int level, char *basedir)
{
	const char *path;
	FILEOP *fileop = NULL;
	FILE *op = NULL;
	int flist_items = 0;
	int count = 0;

	if (level > 0) {
		char name[MAXPATHLEN];

		snprintf(name, sizeof(name), "%s/files/%s.%s", distpath, path2fid(basedir), HTML);
		fileop = open_output_file(name, 0);
		op = get_descripter(fileop);
		print_directory_header(op, level, basedir);
		if (tree_view) {
			char *target = (Fflag) ? "mains" : "_top";

			strbuf_puts(files, dir_begin);
			strbuf_puts(files, gen_href_begin_with_title_target("files", path2fid(basedir), HTML, NULL, NULL, target));
			strbuf_puts(files, full_path ? removedotslash(basedir) : lastpart(basedir));
			strbuf_puts(files, gen_href_end());
			strbuf_puts_nl(files, dir_title_end);
			strbuf_puts_nl(files, "<ul>");
		}
	}
	while ((path = getpath()) != NULL) {
		const char *p, *local = localpath(path, basedir);

		/*
		 * Path is outside of basedir.
		 */
		if (local == NULL) {
			ungetpath();	/* read again by upper level print_directory(). */
			break;
		}
		/*
		 * Path is inside of basedir.
		 */
		else {
			char *slash = strchr(local, '/');

			if (table_flist && flist_items++ % flist_fields == 0)
				PUT(fline_begin);
			/*
			 * Print directory.
			 */
			if (slash) {
				int baselen = strlen(basedir);
				char *q, *last = basedir + baselen;
				int subcount;

				if (baselen + 1 + (slash - local)  > MAXPATHLEN) {
					fprintf(stderr, "Too long path name.\n");
					exit(1);
				}
				/*
				 * Append new directory to the basedir.
				 */
				p = local;
				q = last;
				*q++ = '/';
				while (p < slash)
					*q++ = *p++;
				*q = '\0';
				/*
				 * print tree for this directory.
				 */
				ungetpath();	/* read again by lower level print_directory(). */
				subcount = print_directory(level + 1, basedir);
				PUT(print_directory_name(level, basedir, subcount));
				count += subcount;
				/*
				 * Shrink the basedir.
				 */
				*last = '\0';
			}
			/*
			 * Print file.
			 */
			else {
				const char *file_name = print_file_name(level, path);

				if (tree_view) {
					int size = filesize(path);
					char *target = (Fflag) ? "mains" : "_top";
					char tips[80];

					if (size > 1)
						snprintf(tips, sizeof(tips), "%s bytes", insert_comma(size));
					else
						snprintf(tips, sizeof(tips), "%s byte", insert_comma(size));
					strbuf_sprintf(files, "%s%s%s%s%s\n",
						file_begin,
						gen_href_begin_with_title_target(SRCS, path2fid(path), HTML, NULL, tips, target),
						full_path ? removedotslash(path) : lastpart(path),
						gen_href_end(),
						file_end);
				}
				PUT(file_name);
				if (filemap_file)
					fprintf(FILEMAP, "%s\t%s/%s.%s\n", removedotslash(path), SRCS, path2fid(path), HTML);
				count++;
			}
			if (table_flist && flist_items % flist_fields == 0)
				PUT(fline_end);
		}
	}
	if (flist_items % flist_fields != 0)
		PUT(fline_end);
	if (level > 0) {
		print_directory_footer(op, level, basedir);
		close_file(fileop);
		if (tree_view) {
			strbuf_puts_nl(files, "</ul>");
			strbuf_puts_nl(files, dir_end);
		}
	}
	html_count++;
	return count;
}
Beispiel #22
0
void init_desc_array(void)
{
	int c, l;

	DESC* desc = (DESC*) calloc(1, sizeof(*desc));

	FILE* f = NULL;
	FILE* f_desc = NULL;
	
	char desc_filename[256];
	char buffer[256];
	char* filename = "descs/desc.all";
	
	char* plugin_filename = (char* ) calloc(80, sizeof(*plugin_filename));

	DEBUG_MSG("Init desc files parsing");

	f = fopen(filename, "r");
	if (!f)
		exit(EXIT_FAILURE);

	l = get_file_lines_count(f);

	DEBUG_MSG("%d files in list", l);

	/* allocate memory */
	DESC_ARRAY_LENGTH = l;
	DESC_ARRAY = calloc(DESC_ARRAY_LENGTH, sizeof(DESC));

	fseek(f, 0, 0);

	/* parse files */
	c = 0;
	while (fgets(buffer, sizeof(buffer), f) != 0) {
	
		sscanf(buffer, "%s", buffer);
		strcpy(desc_filename, "descs/");
		strcat(desc_filename, buffer);

		if (is_desc_file(desc_filename)) {

			f_desc = open_file(desc_filename);

			if (f_desc) {
				if (parse_desc_file(f_desc, desc) == PARSE_SUCCESS) {

					DEBUG_MSG("%s parsing succeeds", desc_filename);

					sprintf(plugin_filename, "descs/%s.so", desc->name);
			
					lower_string(plugin_filename);

					/* load .so */
					if (load_desc_so(plugin_filename, desc)) {
						DEBUG_MSG("%s loaded", plugin_filename);
					}

					DESC_ARRAY[c] = *desc;

				} 
				else {
					WARNING_MSG("parsing fails for %s", desc_filename);
				}
				close_file(f_desc);
				c++;
			}
		}
	}

	fclose(f);

	/* free the mallocs */
	free(plugin_filename);
	free(desc);

	DEBUG_MSG("End desc files parsing");
}
/* read input graph and construct cell, net arrays */
void read_graph(char fname[],
                int  nocells,
                int  nonets,
                int  noparts,
                int *totsize,
                int *totcellsize,
                int *max_density,
                int *max_cweight,
                int *max_nweight,
                cells_t cells[],
                nets_t  nets[],
                corn_t  cnets[])
{
    FILE *fp;
    open_file(&fp, fname, "r");

    /* graph size is already read so re-read and discard. */
    int ignore1, ignore2;
    if (fscanf(fp, "%d%d", &ignore1, &ignore2) == EOF) {
        printf("Error: Cannot read from %s: errno= %d error= %s\n", fname, errno, strerror(errno));
        close_file(&fp);
        exit(1);
    } 

    /* initialize cells array */
    init_cells(nocells, cells);

    /* read nets */
    *max_nweight = -1;
    *totsize = 0;
    for (int i = 0; i < nonets; i++) {
        int ignore;  /* this is the number of pins on this net; it
                        makes sense for hypergraphs; for graphs, it is
                        always 2. */
        if (fscanf(fp, "%d%d%d%d", &nets[i].nweight, &ignore, &nets[i].ncells[0], &nets[i].ncells[1]) == EOF) {
            printf("Error: Cannot read from %s: errno= %d error= %s\n", fname, errno, strerror(errno));
            close_file(&fp);
            exit(1);
        }
        /* temp for reading 2, the net degree */
        cells[nets[i].ncells[0]].cno_nets++;
        cells[nets[i].ncells[1]].cno_nets++;
        *totsize += nets[i].nweight;
        if (nets[i].nweight > (*max_nweight)) {
            *max_nweight = nets[i].nweight;
        }
    }   /* for */

    /* set netlist pointers */
    *max_density = -1;
    *max_cweight = -1;
    *totcellsize = 0;
    int part_sum = 0;
    for (int i = 0; i < nocells; i++) {
        if (fscanf(fp, "%d", &cells[i].cweight) == EOF) {
            printf("Error: Cannot read from %s: errno= %d error= %s\n", fname, errno, strerror(errno));
            close_file(&fp);
            exit(1);
        }
        (*totcellsize) += cells[i].cweight;
        if (cells[i].cweight > (*max_cweight)) { 
            *max_cweight = cells[i].cweight;
        }
        if (cells[i].cno_nets > (*max_density)) {
            *max_density = cells[i].cno_nets;
        }
        cells[i].netlist = part_sum;
        part_sum += cells[i].cno_nets;
    }   /* for */

    close_file(&fp);

    /* create netlists */
    init_netlist(nonets, cells, nets, cnets);
}   /* read_graph */
Beispiel #24
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ftp_process, ev, data)
{
  u16_t ipaddr[2], *ipaddrptr;
  
  PROCESS_BEGIN();
    
  ftpc_init();
  
  memset(statustext, 0, sizeof(statustext));
  memset(remotefiles, 0, sizeof(remotefiles));
  memset(localfiles, 0, sizeof(localfiles));
  memset(leftptr, 0, sizeof(leftptr));
  memset(midptr, 0, sizeof(midptr));	    
  memset(rightptr, 0, sizeof(rightptr));
  
  ptrstate = PTRSTATE_REMOTEFILES;
  localptr = remoteptr = 0;
  
  connection = NULL;
  
  ctk_window_new(&window,
		 3 + FILES_WIDTH * 2, 3 + FILES_HEIGHT,
		 "FTP Client");
  
  CTK_WIDGET_ADD(&window, &localtextlabel);
  CTK_WIDGET_ADD(&window, &remotetextlabel);
  
  CTK_WIDGET_ADD(&window, &leftptrlabel);
  CTK_WIDGET_ADD(&window, &localfileslabel);
  CTK_WIDGET_ADD(&window, &midptrlabel);
  CTK_WIDGET_ADD(&window, &remotefileslabel);
  CTK_WIDGET_ADD(&window, &rightptrlabel);
  
  CTK_WIDGET_ADD(&window, &reloadbutton);
  CTK_WIDGET_ADD(&window, &connectionbutton);
  CTK_WIDGET_ADD(&window, &quitbutton);
  
  CTK_WIDGET_ADD(&window, &statuslabel);
  
  CTK_WIDGET_FOCUS(&window, &connectionbutton);
  ctk_window_open(&window);
  
  showptr();
  
  start_loaddir();

  while(1) {

    PROCESS_WAIT_EVENT();
    
    if(ev == PROCESS_EVENT_CONTINUE) {
      if(cfs_readdir(&dir, &dirent) == 0 &&
	 localfileptr < FILES_HEIGHT) {
	strncpy(&localfiles[localfileptr * FILES_WIDTH],
		dirent.name, FILES_WIDTH);
	CTK_WIDGET_REDRAW(&localfileslabel);
	++localfileptr;
	process_post(&ftp_process, PROCESS_EVENT_CONTINUE, NULL);
      } else{
	cfs_closedir(&dir);
      }   
    } else if(ev == PROCESS_EVENT_EXIT) {
      quit();
    } else if(ev == tcpip_event) {
      ftpc_appcall(data);
#if UIP_UDP
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 (ipaddrptr = resolv_lookup((char *)data)) != NULL) {
	connection = ftpc_connect(ipaddrptr, HTONS(21));
	show_statustext("Connecting to ", hostname);
      } else {
	show_statustext("Host not found: ", hostname);
      }
#endif /* UIP_UDP */
    } else if(
#if CTK_CONF_WINDOWCLOSE
	      ev == ctk_signal_window_close &&
#endif /* CTK_CONF_WINDOWCLOSE */
	      data == (process_data_t)&window) {
      quit();
    } else if(ev == ctk_signal_widget_activate) {
      if((struct ctk_button *)data == &quitbutton) {
	quit();
      } else if((struct ctk_button *)data == &cancelbutton) {
	ctk_dialog_close();
      } else if((struct ctk_button *)data == &downloadbutton) {
	ctk_dialog_close();
	close_file();
	fd = cfs_open(localfilename, CFS_WRITE);
	if(fd != -1) {
	  show_statustext("Downloading ", remotefilename);
	  ftpc_get(connection, remotefilename);
	} else {
	  show_statustext("Could not create ", localfilename);
	}
      } else if((struct ctk_button *)data == &reloadbutton) {	
	start_loaddir();
      } else if((struct ctk_button *)data == &connectionbutton) {	
	make_connectionwindow();
	ctk_dialog_open(&connectionwindow);
      } else if((struct ctk_button *)data == &closebutton) {
	ctk_dialog_close();
      } else if((struct ctk_button *)data == &anonymousbutton) {
	strcpy(username, "ftp");
	strcpy(password, "contiki@ftp");
	CTK_WIDGET_REDRAW(&userentry);
	CTK_WIDGET_REDRAW(&passwordentry);
      } else if((struct ctk_button *)data == &closeconnectionbutton) {
	ctk_dialog_close();
	ftpc_close(connection);
      } else if((struct ctk_button *)data == &connectbutton) {
	ctk_dialog_close();
#if UIP_UDP
	if(uiplib_ipaddrconv(hostname, (unsigned char *)ipaddr) == 0) {
	  ipaddrptr = resolv_lookup(hostname);
	  if(ipaddrptr == NULL) {
	    resolv_query(hostname);
	    show_statustext("Resolving host ", hostname);
	    break;
	  }
	  connection = ftpc_connect(ipaddrptr, HTONS(21));
	  show_statustext("Connecting to ", hostname);
	} else {
	  connection = ftpc_connect(ipaddr, HTONS(21));
	  show_statustext("Connecting to ", hostname);
	}
#else /* UIP_UDP */
	uiplib_ipaddrconv(hostname, (unsigned char *)ipaddr);
	connection = ftpc_connect(ipaddr, HTONS(21));
	show_statustext("Connecting to ", hostname);
#endif /* UIP_UDP */
      } 
      /*      if((struct ctk_button *)data == &closebutton) {
	ftpc_close(connection);
	}*/
    } else if(ev == ctk_signal_keypress) {
      /* if((ctk_arch_key_t)data == ' ') {
	if(ptrstate == PTRSTATE_LOCALFILES) {
	  ptrstate = PTRSTATE_REMOTEFILES;
	} else {
	  ptrstate = PTRSTATE_LOCALFILES;
	}
      } else */ if((ctk_arch_key_t)(size_t)data == CH_CURS_UP) {
	clearptr();
	if(ptrstate == PTRSTATE_LOCALFILES) {
	  if(localptr > 0) {
	    --localptr;
	  }
	} else {
	  if(remoteptr > 0) {
	    --remoteptr;
	  }
	}
      } else if((ctk_arch_key_t)(size_t)data == CH_CURS_DOWN) {
	clearptr();
	if(ptrstate == PTRSTATE_LOCALFILES) {
	  if(localptr < FILES_HEIGHT - 1) {
	    ++localptr;
	  }
	} else {
	  if(remoteptr < FILES_HEIGHT - 1) {
	    ++remoteptr;
	  }
	}
      } else if((ctk_arch_key_t)(size_t)data == CH_ENTER) {	
	if(ptrstate == PTRSTATE_LOCALFILES) {
	  strncpy(localfilename,
		  &localfiles[localptr * FILES_WIDTH], FILES_WIDTH);
	  strncpy(remotefilename,
		  &localfiles[localptr * FILES_WIDTH], FILES_WIDTH);
	  make_uploaddialog();
	  ctk_dialog_open(&dialog);
	} else {
	  strncpy(localfilename,
		  &remotefiles[remoteptr * FILES_WIDTH], FILES_WIDTH);
	  strncpy(remotefilename,
		  &remotefiles[remoteptr * FILES_WIDTH], FILES_WIDTH);
	  ftpc_cwd(connection, remotefilename);
	  /*	  make_downloaddialog();
		  ctk_dialog_open(&dialog);*/
	}
      } else if((ctk_arch_key_t)(size_t)data == 'u') {
	ftpc_cdup(connection);
      }
      
      showptr();
    }
  }

  PROCESS_END();
}
Beispiel #25
0
//------------------------------close_files------------------------------------
void ArchDesc::close_files(int delete_out)
{
  if (_ADL_file._fp) fclose(_ADL_file._fp);

  close_file(delete_out, _CPP_file);
  close_file(delete_out, _CPP_CLONE_file);
  close_file(delete_out, _CPP_EXPAND_file);
  close_file(delete_out, _CPP_FORMAT_file);
  close_file(delete_out, _CPP_GEN_file);
  close_file(delete_out, _CPP_MISC_file);
  close_file(delete_out, _CPP_PEEPHOLE_file);
  close_file(delete_out, _CPP_PIPELINE_file);
  close_file(delete_out, _HPP_file);
  close_file(delete_out, _DFA_file);
  close_file(delete_out, _bug_file);

  if (!_quiet_mode) {
    printf("\n");
    if (_no_output || delete_out) {
      if (_ADL_file._name) printf("%s: ", _ADL_file._name);
      printf("No output produced");
    }
    else {
      if (_ADL_file._name) printf("%s --> ", _ADL_file._name);
      printf("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s",
             _CPP_file._name,
             _CPP_CLONE_file._name,
             _CPP_EXPAND_file._name,
             _CPP_FORMAT_file._name,
             _CPP_GEN_file._name,
             _CPP_MISC_file._name,
             _CPP_PEEPHOLE_file._name,
             _CPP_PIPELINE_file._name,
             _HPP_file._name,
             _DFA_file._name);
    }
    printf("\n");
  }
}
Beispiel #26
0
static int read_config_file(const char *name)
{
  FILE *fp;
  char tmp[PATH_MAX], *w[MAXWORDS], *cp;
  ToneBank *bank=0;
  int i, j, k, line=0, words;
  static int rcf_count=0;

  if (rcf_count>50)
   {
    ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
      "Probable source loop in configuration files");
    return (-1);
   }

  if (!(fp=open_file(name, 1, OF_VERBOSE)))
   return -1;

  while (fgets(tmp, sizeof(tmp), fp))
  {
    line++;
    w[words=0]=strtok(tmp, " \t\r\n\240");
    if (!w[0] || (*w[0]=='#')) continue;
    while (w[words] && (words < MAXWORDS))
      {
        w[++words]=strtok(0," \t\r\n\240");
        if (w[words] && w[words][0]=='#') break;
      }
    if (!strcmp(w[0], "map")) continue;
    if (!strcmp(w[0], "dir"))
    {
      if (words < 2)
       {
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
          "%s: line %d: No directory given\n", name, line);
        return -2;
       }
      for (i=1; i<words; i++)
        add_to_pathlist(w[i]);
    }
  else if (!strcmp(w[0], "source"))
  {
    if (words < 2)
      {
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
          "%s: line %d: No file name given\n", name, line);
        return -2;
     }
    for (i=1; i<words; i++)
      {
        rcf_count++;
      read_config_file(w[i]);
        rcf_count--;
      }
  }
      else if (!strcmp(w[0], "default"))
  {
    if (words != 2)
      {
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL, 
        "%s: line %d: Must specify exactly one patch name\n",
          name, line);
        return -2;
      }
    strncpy(def_instr_name, w[1], 255);
    def_instr_name[255]='\0';
  }
    else if (!strcmp(w[0], "drumset"))
  {
    if (words < 2)
      {
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
          "%s: line %d: No drum set number given\n", 
          name, line);
      return -2;
      }
    i=atoi(w[1]);
    if (i<0 || i>127)
     {
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL, 
          "%s: line %d: Drum set must be between 0 and 127\n",
        name, line);
        return -2;
     }
    if (!drumset[i])
      {
        drumset[i]=safe_malloc(sizeof(ToneBank));
      memset(drumset[i], 0, sizeof(ToneBank));
     }
    bank=drumset[i];
  }
    else if (!strcmp(w[0], "bank"))
  {
    if (words < 2)
     {
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
          "%s: line %d: No bank number given\n", 
        name, line);
        return -2;
     }
    i=atoi(w[1]);
    if (i<0 || i>127)
      {
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL, 
          "%s: line %d: Tone bank must be between 0 and 127\n",
        name, line);
        return -2;
      }
    if (!tonebank[i])
     {
      tonebank[i]=safe_malloc(sizeof(ToneBank));
        memset(tonebank[i], 0, sizeof(ToneBank));
      }
    bank=tonebank[i];
  }
      else {
  if ((words < 2) || (*w[0] < '0' || *w[0] > '9'))
    {
     ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
        "%s: line %d: syntax error\n", name, line);
     return -2;
    }
  i=atoi(w[0]);
  if (i<0 || i>127)
    {
      ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
        "%s: line %d: Program must be between 0 and 127\n",
        name, line);
      return -2;
    }
  if (!bank)
    {
      ctl->cmsg(CMSG_ERROR, VERB_NORMAL, 
       "%s: line %d: Must specify tone bank or drum set "
        "before assignment\n",
        name, line);
     return -2;
    }
  if (bank->tone[i].name)
    free(bank->tone[i].name);
  strcpy((bank->tone[i].name=safe_malloc(strlen(w[1])+1)),w[1]);
  bank->tone[i].note=bank->tone[i].amp=bank->tone[i].pan=
    bank->tone[i].strip_loop=bank->tone[i].strip_envelope=
      bank->tone[i].strip_tail=-1;

  for (j=2; j<words; j++)
    {
      if (!(cp=strchr(w[j], '=')))
        {
    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: bad patch option %s\n",
      name, line, w[j]);
    return -2;
        }
      *cp++=0;
      if (!strcmp(w[j], "amp"))
      {
    k=atoi(cp);
    if ((k<0 || k>MAX_AMPLIFICATION) || (*cp < '0' || *cp > '9'))
      {
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, 
          "%s: line %d: amplification must be between "
         "0 and %d\n", name, line, MAX_AMPLIFICATION);
       return -2;
      }
    bank->tone[i].amp=k;
        }
      else if (!strcmp(w[j], "note"))
        {
    k=atoi(cp);
    if ((k<0 || k>127) || (*cp < '0' || *cp > '9'))
      {
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, 
         "%s: line %d: note must be between 0 and 127\n",
          name, line);
        return -2;
      }
    bank->tone[i].note=k;
      }
     else if (!strcmp(w[j], "pan"))
      {
    if (!strcmp(cp, "center"))
      k=64;
    else if (!strcmp(cp, "left"))
      k=0;
    else if (!strcmp(cp, "right"))
      k=127;
    else
      k=((atoi(cp)+100) * 100) / 157;
    if ((k<0 || k>127) ||
       (k==0 && *cp!='-' && (*cp < '0' || *cp > '9')))
      {
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, 
         "%s: line %d: panning must be left, right, "
         "center, or between -100 and 100\n",
         name, line);
       return -2;
      }
    bank->tone[i].pan=k;
      }
     else if (!strcmp(w[j], "keep"))
      {
    if (!strcmp(cp, "env"))
      bank->tone[i].strip_envelope=0;
    else if (!strcmp(cp, "loop"))
      bank->tone[i].strip_loop=0;
    else
      {
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
          "%s: line %d: keep must be env or loop\n", name, line);
       return -2;
      }
      }
     else if (!strcmp(w[j], "strip"))
      {
    if (!strcmp(cp, "env"))
      bank->tone[i].strip_envelope=1;
    else if (!strcmp(cp, "loop"))
      bank->tone[i].strip_loop=1;
    else if (!strcmp(cp, "tail"))
      bank->tone[i].strip_tail=1;
    else
      {
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
         "%s: line %d: strip must be env, loop, or tail\n",
         name, line);
       return -2;
      }
      }
     else
      {
    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: line %d: bad patch option %s\n",
      name, line, w[j]);
    return -2;
      }
    }
    }
   }
  if (ferror(fp))
   {
    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Can't read from %s\n", name);
    close_file(fp);
    return -2;
   }
  close_file(fp);
  return 0;
}
Beispiel #27
0
static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
				uint16_t in_flags,
				uint64_t in_file_id_volatile,
				DATA_BLOB *outbody)
{
	NTSTATUS status;
	struct smb_request *smbreq;
	connection_struct *conn = req->tcon->compat_conn;
	files_struct *fsp;
	struct smb_filename *smb_fname = NULL;
	struct timespec mdate_ts, adate_ts, cdate_ts, create_date_ts;
	uint64_t allocation_size = 0;
	uint64_t file_size = 0;
	uint32_t dos_attrs = 0;
	uint16_t out_flags = 0;
	bool posix_open = false;

	ZERO_STRUCT(create_date_ts);
	ZERO_STRUCT(adate_ts);
	ZERO_STRUCT(mdate_ts);
	ZERO_STRUCT(cdate_ts);

	DEBUG(10,("smbd_smb2_close: file_id[0x%016llX]\n",
		  (unsigned long long)in_file_id_volatile));

	smbreq = smbd_smb2_fake_smb_request(req);
	if (smbreq == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	fsp = file_fsp(smbreq, (uint16_t)in_file_id_volatile);
	if (fsp == NULL) {
		return NT_STATUS_FILE_CLOSED;
	}
	if (conn != fsp->conn) {
		return NT_STATUS_FILE_CLOSED;
	}
	if (req->session->vuid != fsp->vuid) {
		return NT_STATUS_FILE_CLOSED;
	}

	posix_open = fsp->posix_open;
	status = copy_smb_filename(talloc_tos(),
				fsp->fsp_name,
				&smb_fname);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	status = close_file(smbreq, fsp, NORMAL_CLOSE);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(5,("smbd_smb2_close: close_file[%s]: %s\n",
			 fsp_str_dbg(fsp), nt_errstr(status)));
		return status;
	}

	if (in_flags & SMB2_CLOSE_FLAGS_FULL_INFORMATION) {
		int ret;
		if (posix_open) {
			ret = SMB_VFS_LSTAT(conn, smb_fname);
		} else {
			ret = SMB_VFS_STAT(conn, smb_fname);
		}
		if (ret == 0) {
			out_flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
			dos_attrs = dos_mode(conn, smb_fname);
			mdate_ts = smb_fname->st.st_ex_mtime;
			adate_ts = smb_fname->st.st_ex_atime;
			create_date_ts = get_create_timespec(conn, NULL, smb_fname);
			cdate_ts = get_change_timespec(conn, NULL, smb_fname);

			if (lp_dos_filetime_resolution(SNUM(conn))) {
				dos_filetime_timespec(&create_date_ts);
				dos_filetime_timespec(&mdate_ts);
				dos_filetime_timespec(&adate_ts);
				dos_filetime_timespec(&cdate_ts);
			}
			if (!(dos_attrs & FILE_ATTRIBUTE_DIRECTORY)) {
				file_size = get_file_size_stat(&smb_fname->st);
			}

			allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
		}
	}

	SSVAL(outbody->data, 0x00, 0x3C);	/* struct size */
	SSVAL(outbody->data, 0x02, out_flags);	/* flags */
	SIVAL(outbody->data, 0x04, 0);		/* reserved */
	put_long_date_timespec(conn->ts_res,
		(char *)&outbody->data[0x8],create_date_ts); /* creation time */
	put_long_date_timespec(conn->ts_res,
		(char *)&outbody->data[0x10],adate_ts); /* last access time */
	put_long_date_timespec(conn->ts_res,
		(char *)&outbody->data[0x18],mdate_ts); /* last write time */
	put_long_date_timespec(conn->ts_res,
		(char *)&outbody->data[0x20],cdate_ts); /* change time */
	SBVAL(outbody->data, 0x28, allocation_size);/* allocation size */
	SBVAL(outbody->data, 0x30, file_size);	/* end of file */
	SIVAL(outbody->data, 0x38, dos_attrs);	/* file attributes */

	return NT_STATUS_OK;
}
void main(){

 FILE *infile,*outfile;
 char currch,nextch,*ch,chp[100];
 staggered_list *listpointer,*root=create_list_with_file("B:keywords");
 int dat,length_of;
 TOKEN *token,t;
 


                int g2_001_DATA_A;
                int g3_001_DOUBLE_SUBTREE_A;
                int g4_001_SINGLE_SUBTREE_A;
                int g5_001_KEYWORD_OR_WORD_A;
      /**************************************************************************/
      /**************************************************************************/
      /******************** DRIVING PROCEDURE    B:\ALSCAN *********************/
      /**************************************************************************/
       PROCEDURE_DIVISION:
      /**/
      /** takes the output from allinescan*/
      /** which is one line with all the cobol*/
      /** details on it, rather than cobol details*/
      /** */
      /** being spread across a number of lines*/
      /**/
       C1_001_SCAN:
           goto C1_002_SCAN_START;
       C1_002_SCAN_START_EX:
           goto C1_003_LINES;
       C1_003_LINES_EX:
           goto C1_013_EOF;
       C1_013_EOF_EX:
           goto veryend;
      /**/
       C1_002_SCAN_START:
  /*001*/      infile=open_input("b:\\testout.dat");
  /*003*/      currch=getc(infile);
           if(currch!=EOF) nextch=getc(infile);
  /*033*/      token=&t;
  /*021*/      outfile=open_output("b:\\testout2.dat");
           goto C1_002_SCAN_START_EX;
      /**/
       C1_003_LINES:
       C1_004_LINE_EX:
           if(!(
  /*C01*/         (currch==EOF)
))
                   goto C1_004_LINE;
           goto C1_003_LINES_EX;
      /**/
       C1_004_LINE:
           goto C1_005_LINE_START;
       C1_005_LINE_START_EX:
           goto C1_006_CHUNKS;
       C1_006_CHUNKS_EX:
           goto C1_012_BACKSLASH_N;
       C1_012_BACKSLASH_N_EX:
           goto C1_004_LINE_EX;
      /**/
       C1_005_LINE_START:
  /*016*/      /*printf("START OF LINE\n");*/
           goto C1_005_LINE_START_EX;
      /**/
       C1_006_CHUNKS:
       C1_007_CHUNK_EX:
           if(!(
  /*C02*/         (currch=='\n')
))
                   goto C1_007_CHUNK;
           goto C1_006_CHUNKS_EX;
      /**/
       C1_007_CHUNK:
           goto C1_008_START_CHUNK;
       C1_008_START_CHUNK_EX:
           goto C1_009_BLANKS;
       C1_009_BLANKS_EX:
           goto C1_011_DATA;
       C1_011_DATA_EX:
           goto C1_007_CHUNK_EX;
      /**/
       C1_008_START_CHUNK:
  /*005*/      ch=chp;
           goto C1_008_START_CHUNK_EX;
      /**/
       C1_009_BLANKS:
       C1_010_BLANK_EX:
           if(!(
  /*C03*/         (currch!=' ')
))
                   goto C1_010_BLANK;
           goto C1_009_BLANKS_EX;
      /**/
       C1_010_BLANK:
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C1_010_BLANK_EX;
      /**/
       C1_011_DATA:
                g2_001_DATA_A=0;
           goto C2_001_DATA;
       C2_001_EXIT01:
           goto C1_011_DATA_EX;
      /**/
       C1_012_BACKSLASH_N:
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
  /*015*/      /*printf("END LINE TOKEN\n");*/
           /*getchar();*/
           goto C1_012_BACKSLASH_N_EX;
      /**/
       C1_013_EOF:
  /*002*/      close_file(infile);
  /*022*/      close_file(outfile);
           goto C1_013_EOF_EX;
      /**/
       C2_001_DATA:
           goto C2_002_DATA;
       C2_002_DATA_EX:
       C2_001_DATA_A:
                switch(g2_001_DATA_A){
                case 0 : goto C2_001_EXIT01;break;
                }
      /**/
       C2_002_DATA:
           if((
  /*C06*/         (currch=='"' || currch=='\'')
))
                   goto C2_003_NON_NUMERI_C_LITERAL;
           if((
  /*C07*/         (currch=='(')
))
                   goto C2_008_OPEN_BRACE;
           if((
  /*C08*/         (currch==')')
))
                   goto C2_010_CLOSE_BRACE;
           if((
  /*C15*/         (currch=='.')
))
                   goto C2_012_FULLSTOP;
           if((
  /*C09*/         (currch!='"' &&
               currch!='\'' &&
               currch!='(' &&
               currch!=')' &&
               currch!='.' &&
               currch!='\n')
))
                   goto C2_014_WORD;
       C2_003_NON_NUMERI_C_LITERAL_EX:
       C2_008_OPEN_BRACE_EX:
       C2_010_CLOSE_BRACE_EX:
       C2_012_FULLSTOP_EX:
       C2_014_WORD_EX:
           goto C2_002_DATA_EX;
      /**/
       C2_003_NON_NUMERI_C_LITERAL:
           if((
  /*C04*/         (currch=='"')
))
                   goto C2_004_DOUBLE_QUOTE;
           if((
  /*C05*/         (currch=='\'')
))
                   goto C2_006_SINGLE_QUOTE;
       C2_004_DOUBLE_QUOTE_EX:
       C2_006_SINGLE_QUOTE_EX:
           goto C2_003_NON_NUMERI_C_LITERAL_EX;
      /**/
       C2_004_DOUBLE_QUOTE:
           goto C2_005_DOUBLE_SUBTREE;
       C2_005_DOUBLE_SUBTREE_EX:
           goto C2_004_DOUBLE_QUOTE_EX;
      /**/
       C2_005_DOUBLE_SUBTREE:
                g3_001_DOUBLE_SUBTREE_A=0;
           goto C3_001_DOUBLE_SUBTREE;
       C3_001_EXIT01:
           goto C2_005_DOUBLE_SUBTREE_EX;
      /**/
       C2_006_SINGLE_QUOTE:
           goto C2_007_SINGLE_SUBTREE;
       C2_007_SINGLE_SUBTREE_EX:
           goto C2_006_SINGLE_QUOTE_EX;
      /**/
       C2_007_SINGLE_SUBTREE:
                g4_001_SINGLE_SUBTREE_A=0;
           goto C4_001_SINGLE_SUBTREE;
       C4_001_EXIT01:
           goto C2_007_SINGLE_SUBTREE_EX;
      /**/
       C2_008_OPEN_BRACE:
           goto C2_009_BRACE;
       C2_009_BRACE_EX:
           goto C2_008_OPEN_BRACE_EX;
      /**/
       C2_009_BRACE:
  /*008*/      /*printf("open brace\n");*/
  /*024*/      token->token_type=OPEN_BRACE; 
           token->value.keyword_number=OPEN_BRACE;
  /*023*/      write_token(outfile,token);
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C2_009_BRACE_EX;
      /**/
       C2_010_CLOSE_BRACE:
           goto C2_011_PARENTHESI;
       C2_011_PARENTHESI_EX:
           goto C2_010_CLOSE_BRACE_EX;
      /**/
       C2_011_PARENTHESI:
  /*009*/      /*printf("close brace\n");*/
  /*025*/      token->token_type=CLOSE_BRACE; 
           token->value.keyword_number=CLOSE_BRACE;
  /*023*/      write_token(outfile,token);
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C2_011_PARENTHESI_EX;
      /**/
       C2_012_FULLSTOP:
           goto C2_013_PERIOD;
       C2_013_PERIOD_EX:
           goto C2_012_FULLSTOP_EX;
      /**/
       C2_013_PERIOD:
  /*014*/      /*printf("fullstop\n");*/
  /*026*/      token->token_type=FULLSTOP; 
           token->value.keyword_number=FULLSTOP;
  /*023*/      write_token(outfile,token);
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C2_013_PERIOD_EX;
      /**/
       C2_014_WORD:
           goto C2_015_KEYWORD_OR_WORD;
       C2_015_KEYWORD_OR_WORD_EX:
           goto C2_014_WORD_EX;
      /**/
       C2_015_KEYWORD_OR_WORD:
                g5_001_KEYWORD_OR_WORD_A=0;
           goto C5_001_KEYWORD_OR_WORD;
       C5_001_EXIT01:
           goto C2_015_KEYWORD_OR_WORD_EX;
      /**/
       C3_001_DOUBLE_SUBTREE:
           goto C3_002_START_QUOTE;
       C3_002_START_QUOTE_EX:
           goto C3_003_THE_IN_BETWEEN;
       C3_003_THE_IN_BETWEEN_EX:
           goto C3_007_END_QUOTE;
       C3_007_END_QUOTE_EX:
       C3_001_DOUBLE_SUBTREE_A:
                switch(g3_001_DOUBLE_SUBTREE_A){
                case 0 : goto C3_001_EXIT01;break;
                }
      /**/
       C3_002_START_QUOTE:
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
  /*011*/      length_of=0;
  /*005*/      ch=chp;
  /*006*/      *ch='\0';
           goto C3_002_START_QUOTE_EX;
      /**/
       C3_003_THE_IN_BETWEEN:
       C3_004_CHAR_SEQUENCE_EX:
           if(!(
  /*C11*/         (currch=='"' && nextch!='"')
))
                   goto C3_004_CHAR_SEQUENCE;
           goto C3_003_THE_IN_BETWEEN_EX;
      /**/
       C3_004_CHAR_SEQUENCE:
           if((
  /*C13*/         (currch=='"' && nextch=='"')
))
                   goto C3_005_QUOTE_QUOTE;
           if(!(
  /*C13*/         (currch=='"' && nextch=='"')
))
                   goto C3_006_ANY_OTHER;
       C3_005_QUOTE_QUOTE_EX:
       C3_006_ANY_OTHER_EX:
           goto C3_004_CHAR_SEQUENCE_EX;
      /**/
       C3_005_QUOTE_QUOTE:
  /*012*/      length_of++;
  /*030*/      *ch=currch;
  /*031*/      ch++;
  /*006*/      *ch='\0';
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C3_005_QUOTE_QUOTE_EX;
      /**/
       C3_006_ANY_OTHER:
  /*012*/      length_of++;
  /*030*/      *ch=currch;
  /*031*/      ch++;
  /*006*/      *ch='\0';
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C3_006_ANY_OTHER_EX;
      /**/
       C3_007_END_QUOTE:
  /*013*/      token->token_type=NON_NUMERIC_LITERAL_LENGTH;
           token->value.keyword_number=length_of;
  /*023*/      write_token(outfile,token);
  /*007*/      /*printf("string token for %s\n",chp);*/
  /*029*/      token->token_type=NON_NUMERIC_LITERAL; 
           token->value.string=chp;
  /*023*/      write_token(outfile,token);
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C3_007_END_QUOTE_EX;
      /**/
       C4_001_SINGLE_SUBTREE:
           goto C4_002_START_QUOTE;
       C4_002_START_QUOTE_EX:
           goto C4_003_THE_IN_BETWEEN;
       C4_003_THE_IN_BETWEEN_EX:
           goto C4_007_END_QUOTE;
       C4_007_END_QUOTE_EX:
       C4_001_SINGLE_SUBTREE_A:
                switch(g4_001_SINGLE_SUBTREE_A){
                case 0 : goto C4_001_EXIT01;break;
                }
      /**/
       C4_002_START_QUOTE:
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
  /*011*/      length_of=0;
  /*005*/      ch=chp;
  /*006*/      *ch='\0';
           goto C4_002_START_QUOTE_EX;
      /**/
       C4_003_THE_IN_BETWEEN:
       C4_004_CHAR_SEQUENCE_EX:
           if(!(
  /*C12*/         (currch=='\'' && nextch!='\'')
))
                   goto C4_004_CHAR_SEQUENCE;
           goto C4_003_THE_IN_BETWEEN_EX;
      /**/
       C4_004_CHAR_SEQUENCE:
           if((
  /*C14*/         (currch=='\'' && nextch=='\'')
))
                   goto C4_005_SIN_QUOTE_SIN_QUOTE;
           if(!(
  /*C14*/         (currch=='\'' && nextch=='\'')
))
                   goto C4_006_ANY_OTHER;
       C4_005_SIN_QUOTE_SIN_QUOTE_EX:
       C4_006_ANY_OTHER_EX:
           goto C4_004_CHAR_SEQUENCE_EX;
      /**/
       C4_005_SIN_QUOTE_SIN_QUOTE:
  /*012*/      length_of++;
  /*030*/      *ch=currch;
  /*031*/      ch++;
  /*006*/      *ch='\0';
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C4_005_SIN_QUOTE_SIN_QUOTE_EX;
      /**/
       C4_006_ANY_OTHER:
  /*012*/      length_of++;
  /*030*/      *ch=currch;
  /*031*/      ch++;
  /*006*/      *ch='\0';
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C4_006_ANY_OTHER_EX;
      /**/
       C4_007_END_QUOTE:
  /*013*/      token->token_type=NON_NUMERIC_LITERAL_LENGTH;
           token->value.keyword_number=length_of;
  /*023*/      write_token(outfile,token);
  /*007*/      /*printf("string token for %s\n",chp);*/
  /*029*/      token->token_type=NON_NUMERIC_LITERAL; 
           token->value.string=chp;
  /*023*/      write_token(outfile,token);
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C4_007_END_QUOTE_EX;
      /**/
       C5_001_KEYWORD_OR_WORD:
           goto C5_002_KEYWORD_WORD_BCKTR;
       C5_002_KEYWORD_WORD_BCKTR_EX:
       C5_001_KEYWORD_OR_WORD_A:
                switch(g5_001_KEYWORD_OR_WORD_A){
                case 0 : goto C5_001_EXIT01;break;
                }
      /**/
       C5_002_KEYWORD_WORD_BCKTR:
           goto C5_003_KEYWORD;
       C5_003_KEYWORD_EX:
       C5_008_NON_KEYWORD_EX:
           goto C5_002_KEYWORD_WORD_BCKTR_EX;
      /**/
       C5_003_KEYWORD:
           goto C5_004_KEYWORD_START;
       C5_004_KEYWORD_START_EX:
           goto C5_005_KEYWORD_CHARS;
       C5_005_KEYWORD_CHARS_EX:
           goto C5_007_KEYWORD_END;
       C5_007_KEYWORD_END_EX:
           goto C5_003_KEYWORD_EX;
      /**/
       C5_004_KEYWORD_START:
  /*005*/      ch=chp;
  /*011*/      length_of=0;
  /*017*/      listpointer=root;
  /*030*/      *ch=currch;
  /*031*/      ch++;
  /*006*/      *ch='\0';
  /*018*/      listpointer=check_pointer(listpointer,currch);
  /*012*/      length_of++;
           if((
  /*Q01*/         (!isupper(currch)) && currch!='-'
))
                   goto C5_008_NON_KEYWORD;
           if((
  /*Q02*/         listpointer==NULL
))
                   goto C5_008_NON_KEYWORD;
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C5_004_KEYWORD_START_EX;
      /**/
       C5_005_KEYWORD_CHARS:
       C5_006_KEYWORD_CHAR_EX:
           if(!(
  /*C10*/         (currch==' ' || currch=='\n' || 
               currch=='(' || currch==')' ||
               currch=='.')
))
                   goto C5_006_KEYWORD_CHAR;
           goto C5_005_KEYWORD_CHARS_EX;
      /**/
       C5_006_KEYWORD_CHAR:
  /*030*/      *ch=currch;
  /*031*/      ch++;
  /*006*/      *ch='\0';
  /*012*/      length_of++;
  /*018*/      listpointer=check_pointer(listpointer,currch);
           if((
  /*Q01*/         (!isupper(currch)) && currch!='-'
))
                   goto C5_008_NON_KEYWORD;
           if((
  /*Q02*/         listpointer==NULL
))
                   goto C5_008_NON_KEYWORD;
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C5_006_KEYWORD_CHAR_EX;
      /**/
       C5_007_KEYWORD_END:
  /*019*/      dat=get_data(listpointer);
           if((
  /*Q03*/         dat==NULL
))
                   goto C5_008_NON_KEYWORD;
  /*020*/      /*printf("keyword - %s number %d",chp,dat);*/
  /*027*/      token->token_type=KEYWORD; 
           token->value.keyword_number=dat;
  /*023*/      write_token(outfile,token);
           goto C5_007_KEYWORD_END_EX;
      /**/
       C5_008_NON_KEYWORD:
           goto C5_009_START_NON;
       C5_009_START_NON_EX:
           goto C5_010_CHARS;
       C5_010_CHARS_EX:
           goto C5_012_END_WORD;
       C5_012_END_WORD_EX:
           goto C5_008_NON_KEYWORD_EX;
      /**/
       C5_009_START_NON:
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C5_009_START_NON_EX;
      /**/
       C5_010_CHARS:
       C5_011_CHAR_EX:
           if(!(
  /*C10*/         (currch==' ' || currch=='\n' || 
               currch=='(' || currch==')' ||
               currch=='.')
))
                   goto C5_011_CHAR;
           goto C5_010_CHARS_EX;
      /**/
       C5_011_CHAR:
  /*030*/      *ch=currch;
  /*031*/      ch++;
  /*006*/      *ch='\0';
  /*012*/      length_of++;
  /*004*/      currch=nextch;
           if(nextch!=EOF) nextch=getc(infile);
           goto C5_011_CHAR_EX;
      /**/
       C5_012_END_WORD:
  /*010*/      /*printf("word token for %s\n",chp);*/
  /*032*/      token->token_type=NON_KEYWORD_LENGTH;
           token->value.keyword_number=length_of;
  /*023*/      write_token(outfile,token);
  /*028*/      token->token_type=NON_KEYWORD; 
           token->value.string=chp;
  /*023*/      write_token(outfile,token);
  /*013*/      token->token_type=NON_NUMERIC_LITERAL_LENGTH;
           token->value.keyword_number=length_of;
           goto C5_012_END_WORD_EX;
      /**/
      /*   Data Analysis Map*/
      /**/
      /*                         ------------- Data Analysis By -------------*/
      /**/
      /*                         BOX TYPE               OPERATION  ALLOCATION*/
      /*  Tree name: SCAN*/
      /**/
      /*                         Leaf      :   6          Operations:  11*/
      /*                                                  Quits     :   0*/
      /*                         Selections:   0*/
      /*                         Sequences :   3*/
      /*                         Iterations:   3*/
      /*                         Backtracks:   0*/
      /*                         Subtrees  :   1   -->    DATA*/
      /**/
      /*  Tree name: DATA*/
      /**/
      /*                         Leaf      :   3          Operations:  12*/
      /*                                                  Quits     :   0*/
      /*                         Selections:   2*/
      /*                         Sequences :   7*/
      /*                         Iterations:   0*/
      /*                         Backtracks:   0*/
      /*                         Subtrees  :   3   -->    DOUBLE-SUBTREE*/
      /*                                                  SINGLE-SUBTREE*/
      /*                                                  KEYWORD_OR-WORD*/
      /**/
      /*  Tree name: DOUBLE-SUBTREE*/
      /**/
      /*                         Leaf      :   4          Operations:  21*/
      /*                                                  Quits     :   0*/
      /*                         Selections:   1*/
      /*                         Sequences :   1*/
      /*                         Iterations:   1*/
      /*                         Backtracks:   0*/
      /*                         Subtrees  :   0*/
      /**/
      /*  Tree name: SINGLE-SUBTREE*/
      /**/
      /*                         Leaf      :   4          Operations:  21*/
      /*                                                  Quits     :   0*/
      /*                         Selections:   1*/
      /*                         Sequences :   1*/
      /*                         Iterations:   1*/
      /*                         Backtracks:   0*/
      /*                         Subtrees  :   0*/
      /**/
      /*  Tree name: KEYWORD_OR-WORD*/
      /**/
      /*                         Leaf      :   6          Operations:  31*/
      /*                                                  Quits     :   5*/
      /*                         Selections:   0*/
      /*                         Sequences :   3*/
      /*                         Iterations:   2*/
      /*                         Backtracks:   1*/
      /*                         Subtrees  :   0*/
      /**/
      /**/
      /**/
veryend: ;
}
Beispiel #29
0
csdbparser::~csdbparser()
{
    close_file();
}
Beispiel #30
0
RotatedFileLogger::~RotatedFileLogger() {
	close_file();
}