Exemplo n.º 1
0
Arquivo: txt.c Projeto: aahls/txt
void mode_tag_edit(int argc, char **argv, note_db_t *db, int remove){
    int i, tag_i=0, id_i=0;
    char **tags=(char **) malloc(sizeof(char *)*(argc-optind));
    int *ids=(int *) malloc(sizeof(int *)*(argc-optind));
    for(i=optind;i<argc;i++){
        if(argv[i][0]=='#'){
            //Point to characters just after the hash
            tags[tag_i]=argv[i]+1;
            tag_i++;
        }else if((ids[id_i]=atoi_altfail(argv[i]))!=-1){
            id_i++;
        }else{
            printf("%s is neither a tag (specified with a # sign) or an ID. Ignoring.\n", argv[i]);
        }
    }

    for(i=0;i<id_i;i++){
        int j;
        note_t *note=get_note_id(db, ids[i]);
        for(j=0;j<tag_i;j++){
            if(remove) del_tag(note, tags[j]);
            else add_tag(note, tags[j]);
        }
    }

    free(tags);
    free(ids);
}
Exemplo n.º 2
0
/*
** new_hsctag
**
** alloc & init a new hsctag
*/
HSCTAG *new_hsctag( STRPTR newid )
{

    HSCTAG *newtag = (HSCTAG*) malloc( sizeof(HSCTAG) );

    if (newtag) {

        /* init new tag item */
        newtag->name        = upstr( strclone(newid) );        /* set id */
        newtag->option      = 0;
        newtag->vers        = 0;
        newtag->o_handle    = NULL;       /* no handle functions */
        newtag->c_handle    = NULL;
        newtag->occured     = FALSE;
        newtag->op_text     = NULL;
        newtag->cl_text     = NULL;
        newtag->attr        = init_dllist( del_var );
        newtag->mbi         = NULL;
        newtag->naw         = NULL;

        if ( !( newtag->name && newtag->attr ) ) {

            del_tag( newtag );
            newtag = NULL;
        }

    }

    return (newtag);
}
Exemplo n.º 3
0
int main(int argc, string argv[])
{
  string prog, itags[MaxBodyFields], otags[MaxBodyFields];
  stream xstr, ostr;
  bodyptr btab = NULL;
  int nbody;
  real tnow;

  initparam(argv, defv);
  exprs[0] = getparam("weight");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  new_field(&WeightField, RealType, "Weight");
  new_field(&WeightField + 1, NULL, NULL);
  while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE)) {
    snaprect(btab, nbody);
    del_tag(otags, itags, "Weight");
    put_snap(ostr, &btab, &nbody, &tnow, otags);
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getargv0(), prog);
  return (0);
}
Exemplo n.º 4
0
int main(int argc, string argv[])
{
  string prog, coords, itags[MaxBodyFields], otags[MaxBodyFields];
  stream xstr, ostr;
  bodyptr btab = NULL, bp;
  int nbody;
  real tnow;
  vector cmpos, cmvel, cmacc;

  initparam(argv, defv);
  exprs[0] = getparam("weight");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  coords = getparam("coords");
  new_field(&WeightField, RealType, "Weight");
  new_field(&WeightField + 1, NULL, NULL);
  while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE, NULL)) {
    if (scanopt(coords, PosTag) && set_member(itags, PosTag)) {
      snapcmpos(cmpos, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Pos(bp), Pos(bp), cmpos);
      }
      eprintf("[%s: centroid position: %f,%f,%f]\n", getprog(),
	      cmpos[0], cmpos[1], cmpos[2]);
    }
    if (scanopt(coords, VelTag) && set_member(itags, VelTag)) {
      snapcmvel(cmvel, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Vel(bp), Vel(bp), cmvel);
      }
      eprintf("[%s: centroid velocity: %f,%f,%f]\n", getprog(),
	      cmvel[0], cmvel[1], cmvel[2]);
    }
    if (scanopt(coords, AccTag) && set_member(itags, AccTag)) {
      snapcmacc(cmacc, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Acc(bp), Acc(bp), cmacc);
      }
      eprintf("[%s: cen. acceleration: %f,%f,%f]\n", getprog(),
	      cmacc[0], cmacc[1], cmacc[2]);
    }
    del_tag(otags, itags, "Weight");
    put_snap(ostr, &btab, &nbody, &tnow, otags);
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getprog(), prog);
  return (0);
}
Exemplo n.º 5
0
/*
** app_tag
**
** create a new tag and append it to tag-list
**
** params: tagid..name of the new tag (eg "IMG")
** result: ptr to the new tag or NULL if no mem
*/
HSCTAG *app_tag( DLLIST *taglist, STRPTR tagid )
{
    HSCTAG *newtag;

    newtag = new_hsctag( tagid );
    if ( newtag ) {
        if (app_dlnode( taglist, newtag ) == NULL ) {

            del_tag( (APTR) newtag );
            newtag = NULL;

        }
    } else
        err_mem( NULL );

    return (newtag);
}
Exemplo n.º 6
0
/*
** app_ctag
**
** create closing tag and append it to tag-list;
** also clone options & attribute list of parent
** tag, if tag is a macro and has a closing tag.
**
** params: tagid..name of the new tag (eg "IMG")
** result: ptr to the new tag or NULL if no mem
*/
HSCTAG *app_ctag( DLLIST *taglist, HSCTAG *tag )
{
    HSCTAG *ctag;

    ctag = new_hsctag( tag->name );
    if ( ctag ) {

        BOOL    ok = TRUE;
        DLNODE *nd = NULL;

        /* copy important data of tag */
        ctag->option = tag->option;

        /* clone attributes, if tag is a
        ** macro tag and has a closing tag
        */
        if ( (tag->option & HT_MACRO)
                && (tag->option & HT_CLOSE) )
        {

            ok = copy_local_varlist(
                     ctag->attr, tag->attr, MCI_APPCTAG );

        }

        /* insert tag in list */
        if ( ok ) {

            nd = app_dlnode( taglist, ctag );
            if ( !nd ) {

                del_tag( (APTR) ctag );
                ctag = NULL;

            }
        }
    }

    return (ctag);
}