Beispiel #1
0
/*
 * Name:    save_strokes
 * Purpose: save strokes to a file
 * Date:    April 1, 1992
 * Passed:  window:  pointer to current window
 */
int  save_strokes( WINDOW *window )
{
FILE *fp;                       /* file to be written */
char name[MAX_COLS+2];          /* file name */
char line_buff[(MAX_COLS+1)*2]; /* buffer for char and attribute  */
register int rc;
int  prompt_line;
int  fattr;

   name[0] = '\0';
   prompt_line = window->bottom_line;
   save_screen_line( 0, prompt_line, line_buff );
   /*
    * name for macro file
    */
   if ((rc = get_name( main19, prompt_line, name,
                 g_display.message_color )) == OK  &&  *name != '\0') {

      /*
       * make sure it is OK to overwrite any existing file
       */
      rc = get_fattr( name, &fattr );
      if (rc == OK) {
         /*
          * overwrite existing file
          */
         set_prompt( main20, prompt_line );
         if (get_yn( ) != A_YES  ||  change_mode( name, prompt_line ) == ERROR)
            rc = ERROR;
      }
      if (rc != ERROR) {
         if ((fp = fopen( name, "wb" )) != NULL) {
            fwrite( &macro.first_stroke[0], sizeof(int), MAX_KEYS, fp );
            fwrite( &macro.strokes[0], sizeof(STROKES), STROKE_LIMIT, fp );
            fclose( fp );
         }
      }
   }
   restore_screen_line( 0, prompt_line, line_buff );
   return( OK );
}
Beispiel #2
0
/*
 * Name:    validate_path
 * Purpose: make sure we got a valid search pattern or subdirectory
 * Date:    February 13, 1992
 * Passed:  dname: search path entered by user
 *          stem:  directory stem is returned
 * Returns: successful or not
 * Notes:   we need to validate the search path or pattern.  if the search
 *            pattern is valid, then we need to get the search stem.
 *          the user may enter a subdirectory or some kind of search pattern.
 *             if the user enters a subdirectory, then there are a few things
 *             we need to take care of  1) find out if the subdirectory is
 *             the root, 2) append a '\' to the subdirectory so we can create
 *             a search pattern for the subdirectory, 3) don't append '\' to
 *             the root, it already has a '\'.
 *          if the user enters a search pattern, then we need to dissect the
 *             search path.  we must create a stem from the search pattern.
 */
int  validate_path( char *dname, char *stem )
{
int  rc;
DTA  dta;               /* temp disk transfer struct for findfirst, etc. */
int  fattr;
int  i;
int  len;
char *p;
char temp[MAX_COLS+2];  /* directory stem */

   /*
    * if path name is void then the current working directory is implied.
    */
   if (dname[0] == '\0') {

      assert( strlen( stardotstar ) < MAX_COLS );

      strcpy( dname, stardotstar );
      stem[0] = '\0';
      rc = OK;
   } else {

      /*
       * get the attributes of the search pattern, so we can determine if
       * this is a pattern or subdirectory.
       */
      rc = get_fattr( dname, &fattr );

      if (rc == OK && (fattr & SUBDIRECTORY)) {
         assert( strlen( dname ) < MAX_COLS );
         strcpy( stem, dname );

         /*
          * if this is the root directory ( \ ), don't append '\' to it.
          * user entered a subdirectory - append *.* to get contents of
          * subdirectory.
          */
         len = strlen( stem );
         if (stem[len-1] != '\\') {
            strcat( stem, "\\" );
            strcat( dname, "\\" );
         }
         strcat( dname, stardotstar );

      /*
       * not a subdirectory.  let's see if any files match the search
       * pattern.
       */
      } else if (rc != ERROR) {
         if ((rc = my_findfirst( &dta, dname, NORMAL | READ_ONLY | HIDDEN |
                              SYSTEM | SUBDIRECTORY | ARCHIVE )) == OK) {

            /*
             * copy dname to "temp" so we can use "temp" to find the stem.
             *    we need to search the pattern backwards to figure the stem.
             */

            assert( strlen( dname ) < MAX_COLS );

            strcpy( temp, dname );
            len = strlen( dname );
            for (i=len,p=temp+len; i>=0; i--) {
               /*
                *  if we run into the '\' or the ':', then we got a stem.
                */
               if (*p == '\\' || *p == ':') {
                  p = temp + i;
                  *(p+1) = '\0';
                  break;
               /*
                * if we're at the beginning of the string, stem == '\0'
                */
               } else if (i == 0) {
                  *p = '\0';
                  break;
               }
               --p;
            }

            assert( strlen( temp ) < MAX_COLS );

            strcpy( stem, temp );
         } else
            rc = ERROR;

      /*
       * user did not enter a valid subdirectory name or search pattern.
       */
      } else
         rc = ERROR;
   }
   return( rc );
}
Beispiel #3
0
void torvol()
{
  facet_id f_id;    /* main facet iterator */
  body_id b_id;
  body_id b0_id,b1_id;    /* facet adjacent bodies */

#ifdef NEWTORVOL
struct qinfo f_info; /* for calling q_facet_torus_volume */
q_info_init(&f_info,METHOD_VALUE);
#endif

  /* adjust body volumes to the invariant constant for each */
  FOR_ALL_BODIES(b_id)
    set_body_volume(b_id,get_body_volconst(b_id),NOSETSTAMP);
  if ( web.representation == STRING )
    FOR_ALL_FACETS(f_id)
      set_facet_area(f_id,0.0);

  FOR_ALL_FACETS(f_id)
  {
    REAL t;     /* accumulator for this facet */

    if ( get_fattr(f_id) & NONCONTENT ) continue;

    /* find adjacent bodies */
    b0_id = get_facet_body(f_id);
    b1_id = get_facet_body(facet_inverse(f_id));
    if ( !valid_id(b0_id) && !valid_id(b1_id) ) continue;

#ifdef NEWTORVOL
    f_info.id = f_id;
    q_facet_setup(NULL,&f_info,NEED_SIDE|TORUS_MODULO_MUNGE|ORIENTABLE_METHOD);
    t = q_facet_torus_volume(&f_info);
    if ( valid_id(b0_id) )
        add_body_volume(b0_id,t);
    if ( valid_id(b1_id) )
        add_body_volume(b1_id,-t);
#else
    REAL *v[FACET_VERTS];  /* pointers to three vertex coordinates */
    facetedge_id fe;
    int i;
    REAL adj[FACET_EDGES][MAXCOORD];  /* torus wrap adjustments for edge */
    /* get basic info */
    fe = get_facet_fe(f_id);
    for ( i = 0 ; i < FACET_EDGES ; i ++ )
    {
      v[i] = get_coord(get_fe_tailv(fe));
      get_edge_adjust(get_fe_edge(fe),adj[i]); 
      fe = get_next_edge(fe);
    }

    /* basic tetrahedron */
    t = triple_prod(v[0],v[1],v[2]);

    /* torus wrap corrections */
    for ( i = 0 ; i < FACET_EDGES ; i++ )
    {
      /* two-vertex term */
      t += triple_prod(adj[(i+1)%FACET_EDGES],v[i],v[(i+1)%FACET_EDGES])/2;
      t -= triple_prod(adj[(i+2)%FACET_EDGES],v[i],v[(i+1)%FACET_EDGES])/2;

      /* one-vertex term */
      t += triple_prod(v[i],adj[(i+2)%FACET_EDGES],adj[i]);
    }

    if ( valid_id(b0_id) )
       add_body_volume(b0_id,t/6);
    if ( valid_id(b1_id) )
       add_body_volume(b1_id,-t/6);
#endif
        }
#ifdef NEWTORVOL
q_info_free(&f_info);
#endif
}