Exemple #1
0
/*
 * check_mbinaw
 *
 * check if tag occures in allowed context with other tags
 */
static BOOL check_mbinaw(HSCPRC * hp, HSCTAG * tag)
{
    BOOL ok = TRUE;

    /* check for tags that must be called before */
    if (tag->mbi)
    {
        DLNODE *nd = hp->container_stack->first;
        LONG found = 0;

        while (nd && !found)
        {
            HSCTAG *ctag = (HSCTAG *) nd->data;

            found = strenum(ctag->name, tag->mbi, '|', STEN_NOCASE);
            nd = nd->next;

        }

        if (!found)
        {
            hsc_message(hp, MSG_MBI,
                        "%T must be inside %t", tag, tag->mbi);
            ok = FALSE;
        }
    }

    /* check for tags that are not to be called before */
    if (tag->naw)
    {
        DLNODE *nd = hp->container_stack->last;
        LONG found = 0;

        while (nd)
        {
            HSCTAG *ctag = (HSCTAG *) nd->data;

            found = strenum(ctag->name, tag->naw, '|', STEN_NOCASE);
            if (found)
            {
                hsc_message(hp, MSG_NAW,
                            "%T not allowed within %T", tag, ctag);

                ok = FALSE;
            }
            nd = dln_prev(nd);
        }
    }
    return ok;
}
Exemple #2
0
/*
*This function recursively enumerates through a char array
* of a given length.
*It compares each enumeration with both its final goal and
* the cryptographic hash. If one is a match the function
* returns or exits respectively.
*/
int strenum(char *s,char *sp, char *f,struct crypt_data data){
   int r;
   while( ((*sp)%97) < 26){
      char *hash;
      hash = crypt_r(s,salt,&data); 
      //You have found the hash.
      if (strcmp(hash,target) == 0){
         printf("%s\n",s);   
         exit(1);
      }
      //Check if its equal to final.
      if (strcmp(s,f) == 0){
         return 1; 
      }
      //Uses the NULL char to find end of current string.
      if (*(sp+1) != '\0'){
         r = strenum(s,sp+1,f,data);
         if(r==1){
            return 1;
         }
	 *(sp+1)='a'; //Reset the value of the last changed char.
      }
      (*sp)++;
   }
   return 0;
}
Exemple #3
0
/*
 * arg_mode
 *
 * argument handler for values that are passed
 * to "MODE=..". this one resets all ignored
 * messages.
 */
static STRPTR arg_mode_CB(STRPTR arg)
{
    STRPTR errmsg = NULL;
    size_t mode = strenum(arg, MODE_ENUMSTR, '|', STEN_NOCASE);
    HSCPRC *hp = arg_hp;

    D(fprintf(stderr, DHSC "args: mode=%s\n", arg));

    if (!mode)
        errmsg = "unknown mode";
    else if (mode == MODE_PEDANTIC)
    {                           /* pedantic */
        /* enable all messages */
        HSCMSG_ID i;

        for (i = 0; i < MAX_MSGID; i++)
            hsc_set_msg_ignore(hp, i, FALSE);
    }
    else if (mode == MODE_NORMAL)
    {                           /* normal */
        /* ignore note messages */
        arg_mode_CB(MODE_PEDANTIC_STR);
        arg_ignore_CB(IGNORE_NOTES_STR);
        hsc_set_msg_ignore(hp, MSG_MISS_REQTAG, TRUE);
        hsc_set_msg_ignore(hp, MSG_WRONG_HEADING, TRUE);
        hsc_set_msg_ignore(hp, MSG_EXPT_H1, TRUE);
        hsc_set_msg_ignore(hp, MSG_LF_IN_COMMENT, TRUE);
    }
    else if (mode == MODE_RELAXED)
    {                           /* relaxed */
        arg_mode_CB(MODE_NORMAL_STR);
        arg_ignore_CB(IGNORE_BADSTYLE_STR);
        arg_ignore_CB(IGNORE_PORTABILITY_STR);
        arg_ignore_CB(IGNORE_JERKS_STR);
        hsc_set_msg_ignore(hp, MSG_TAG_OBSOLETE, TRUE);
        hsc_set_msg_ignore(hp, MSG_TAG_TOO_OFTEN, TRUE);
        hsc_set_msg_ignore(hp, MSG_CTAG_NESTING, TRUE);
        hsc_set_msg_ignore(hp, MSG_EXPT_SEMIK, TRUE);
    }
    else
    {
        /* ignore message # */
        LONG ignnum;

        if (!str2long(arg, &ignnum))
            errmsg = "illegal argument";
        else
            hsc_set_msg_ignore(hp, ignnum, TRUE);
    }
    return (errmsg);
}
Exemple #4
0
/*
*The function that each thread calls.
*Uses strenum to enumerate through a given
* set of strings.
*If the string needs to be lengthen in resets
* the string adds an 'a' and again calls strenum.
*/
void *bruteforce(bounds *b){
   char *sp = (*b).s;
   struct crypt_data data;
   data.initialized = 0;
   while(strenum((*b).s,sp,(*b).f,data) != 1){
      //SP is @ same pos. as S.
      while(*sp != '\0'){
         *sp = 'a';
         ++sp;
      }
      *(sp) = 'a';
      sp = (*b).s;
   }
   pthread_exit(NULL);
}
nsresult
nsCommandLine::EnumerateHandlers(EnumerateHandlersCallback aCallback, void *aClosure)
{
  nsresult rv;

  nsCOMPtr<nsICategoryManager> catman
    (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
  NS_ENSURE_TRUE(catman, NS_ERROR_UNEXPECTED);

  nsCOMPtr<nsISimpleEnumerator> entenum;
  rv = catman->EnumerateCategory("command-line-handler",
                                 getter_AddRefs(entenum));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIUTF8StringEnumerator> strenum (do_QueryInterface(entenum));
  NS_ENSURE_TRUE(strenum, NS_ERROR_UNEXPECTED);

  nsAutoCString entry;
  bool hasMore;
  while (NS_SUCCEEDED(strenum->HasMore(&hasMore)) && hasMore) {
    strenum->GetNext(entry);

    nsCString contractID;
    rv = catman->GetCategoryEntry("command-line-handler",
				  entry.get(),
				  getter_Copies(contractID));
    if (NS_FAILED(rv))
      continue;

    nsCOMPtr<nsICommandLineHandler> clh(do_GetService(contractID.get()));
    if (!clh) {
      LogConsoleMessage(u"Contract ID '%s' was registered as a command line handler for entry '%s', but could not be created.",
                        contractID.get(), entry.get());
      continue;
    }

    rv = (aCallback)(clh, this, aClosure);
    if (rv == NS_ERROR_ABORT)
      break;

    rv = NS_OK;
  }

  return rv;
}
nsresult
nsCommandLine::EnumerateValidators(EnumerateValidatorsCallback aCallback, void *aClosure)
{
  nsresult rv;

  nsCOMPtr<nsICategoryManager> catman
    (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
  NS_ENSURE_TRUE(catman, NS_ERROR_UNEXPECTED);

  nsCOMPtr<nsISimpleEnumerator> entenum;
  rv = catman->EnumerateCategory("command-line-validator",
                                 getter_AddRefs(entenum));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIUTF8StringEnumerator> strenum (do_QueryInterface(entenum));
  NS_ENSURE_TRUE(strenum, NS_ERROR_UNEXPECTED);

  nsAutoCString entry;
  bool hasMore;
  while (NS_SUCCEEDED(strenum->HasMore(&hasMore)) && hasMore) {
    strenum->GetNext(entry);

    nsXPIDLCString contractID;
    rv = catman->GetCategoryEntry("command-line-validator",
				  entry.get(),
				  getter_Copies(contractID));
    if (!contractID)
      continue;

    nsCOMPtr<nsICommandLineValidator> clv(do_GetService(contractID.get()));
    if (!clv)
      continue;

    rv = (aCallback)(clv, this, aClosure);
    if (rv == NS_ERROR_ABORT)
      break;

    rv = NS_OK;
  }

  return rv;
}
Exemple #7
0
BOOL skip_until_tag(HSCPRC * hp, EXPSTR * tagfound, STRPTR tagstoplist, STRPTR tagnest)
{
    UBYTE state = STATE_TEXT;   /* */
    INFILE *inpf = hp->inpf;    /* input file */
    LONG nesting = 0;           /* tag-nesting */
    LONG nesting_comment = 0;   /* comment-nesting */
    STRPTR nw = NULL;
    BOOL quit = FALSE;          /* flag: exit from skipping */
    EXPSTR *ungetstr = init_estr(32);

    clr_estr(tagfound);

    do
    {
        /* get next word or tag-id */
        if (state != STATE_TAG)
            nw = infgetw(inpf);
        else
        {
            nw = infget_tagid(hp);
            if (nw)
            {
                app_estr(ungetstr, infgetcws(inpf));
                app_estr(ungetstr, infgetcw(inpf));
                if (strcmp(nw, "/"))
                {
                    DS(fprintf(stderr, DHLS "start-tag <%s>\n", nw));
                    state = STATE_TAGNAME;      /* tag detected */
                }
                else
                {
                    nw = infget_tagid(hp);
                    DS(fprintf(stderr, DHLS "end-tag </%s>\n", nw));
                    app_estr(ungetstr, infgetcws(inpf));
                    app_estr(ungetstr, infgetcw(inpf));
                    state = STATE_ENDTAGNAME;   /* end-tag detected */
                }
            }
        }

        if (nw)
        {
            switch (state)
            {

                /* check if tag starts */
            case STATE_TEXT:
                if (!strcmp(nw, "<"))
                {
                    DS(fprintf(stderr, DHLS "tag\n"));
                    set_estr(ungetstr, nw);
                    state = STATE_TAG;
                }
                break;

                /* check which tag it is and how to act */
            case STATE_TAGNAME:
                {
                    /* check, if nesting-tag should be incr. */
                    if (!upstrcmp(nw, tagnest))
                    {
                        DS(fprintf(stderr, DHLS "nest-tag (%ld)\n", nesting));
                        state = STATE_TAGATTR;
                        nesting++;
                    }
                    /* check, if stop-tag reached */
                    else if (!nesting
                             && strenum(nw, tagstoplist, '|', STEN_NOCASE))
                    {
                        DS(fprintf(stderr, DHLS "stop-tag `%s'\n", nw));
                        set_estr(tagfound, nw);
                        quit = TRUE;
                    }
                    /* check, if commant-tag reached */
                    else if (!strcmp(nw, HSC_COMMENT_STR))
                    {
                        DS(fprintf(stderr, DHLS "comment-tag (0)\n"));
                        state = STATE_COMMENT;
                    }
                    /* any tag; just skip attributes */
                    else
                    {
                        DS(fprintf(stderr, DHLS "any tag\n"));
                        state = STATE_TAGATTR;
                    }
                    break;
                }

            case STATE_ENDTAGNAME:
                {
                    if (!upstrcmp(nw, tagnest))
                    {
                        if (nesting)
                        {
                            nesting--;
                            DS(fprintf(stderr, DHLS "nest-tag (%ld)\n", nesting));
                        }
                        else
                        {
                            DS(fprintf(stderr, DHLS "nest-tag ending\n"));
                            quit = TRUE;
                        }
                    }
                    else
                        state = STATE_TEXT;     /* no attr for endtag */

                    break;
                }

                /*
                 * process tag attributes
                 */
            case STATE_TAGATTR:
                {
                    if (!strcmp(nw, "="))
                        state = STATE_TAGATTR_EQ;
                    else if (!strcmp(nw, ">"))
                    {
                        DS(fprintf(stderr, DHLS "back to text\n"));
                        state = STATE_TEXT;
                    }
                    break;
                }

            case STATE_TAGATTR_EQ:
                {
                    if (!strcmp(nw, "\""))
                    {
                        DS(fprintf(stderr, DHLS "tagarg (double quote)\n"));
                        state = STATE_TAGATTR_DQUOTE;
                    }
                    else if (!strcmp(nw, "'"))
                    {
                        DS(fprintf(stderr, DHLS "tagarg (single quote)\n"));
                        state = STATE_TAGATTR_SQUOTE;
                    }
                    else
                        state = STATE_TAGATTR;
                    break;
                }

            case STATE_TAGATTR_DQUOTE:
                {
                    if (!strcmp(nw, "\""))
                    {
                        DS(fprintf(stderr, DHLS "end tagarg (double quote)\n"));
                        state = STATE_TAGATTR;
                    }
                    break;
                }

            case STATE_TAGATTR_SQUOTE:
                {
                    if (!strcmp(nw, "'"))
                    {
                        DS(fprintf(stderr, DHLS "end tagarg (single quote)\n"));
                        state = STATE_TAGATTR;
                    }
                    break;
                }

                /*
                 * comment processing
                 */
            case STATE_COMMENT:
                {
                    /* check for <" */
                    if (!strcmp(nw, "<"))
                        state = STATE_COMMENT_TAG;
                    else if (!strcmp(nw, HSC_COMMENT_STR))
                        state = STATE_COMMENT_STAR;
                    break;
                }

            case STATE_COMMENT_TAG:
                {
                    /* check for comment-nesting */
                    if (!strcmp(nw, HSC_COMMENT_STR))
                    {
                        nesting_comment++;
                        DS(fprintf(stderr, DHLS "comment-tag (%ld)\n", nesting_comment));
                        state = STATE_COMMENT;
                    }
                    else
                        state = STATE_COMMENT;

                    break;
                }

            case STATE_COMMENT_STAR:
                {
                    /* check for end comment */
                    if (!strcmp(nw, ">"))
                        if (nesting_comment)
                        {
                            nesting_comment--;
                            DS(fprintf(stderr, DHLS "end comment-tag (%ld)\n", nesting_comment));
                            state = STATE_COMMENT;
                        }
                        else
                        {
                            DS(fprintf(stderr, DHLS "end comment-tag (%ld)\n", nesting_comment));
                            state = STATE_TEXT;
                        }
                    else
                        state = STATE_COMMENT;
                    break;
                }

                /*
                 * unhandled tag
                 */
            default:
                panic("unhandled state");
                break;
            }
        }
    }
    while (nw && !quit && !(hp->fatal));

    if (nw)
    {
        inungets(estr2str(ungetstr), inpf);
    }
    else
    {
        EXPSTR *tagstr = init_estr(0);

        set_estr(tagstr, "</");
        app_estr(tagstr, tagnest);
        app_estr(tagstr, "> expected");
        hsc_msg_eof(hp, estr2str(tagstr));

        del_estr(tagstr);
    }

    del_estr(ungetstr);

    return ((BOOL) (nw != NULL));
}
Exemple #8
0
/*
 * hsc_parse_text
 */
BOOL hsc_parse_text(HSCPRC * hp)
{
    INFILE *inpf = hp->inpf;
    STRPTR nw = infgetcw(inpf);

    if (nw && hp->suppress_output)
        hp_enable_output(hp, "some text");

    if (nw)
    {                           /* do test below only if not end-of-file */
        /*
         * check unmatched ">"
         */
        if (!strcmp(nw, ">"))
        {
            BOOL rplc = hp->smart_ent;  /* TRUE, if ">" should be replaced */

            if (rplc)
            {
                /*
                 * test if char before and
                 * after ">" is white-space
                 */
                int ch = infgetc(inpf);

                inungetc(ch, inpf);

                if (!(hsc_whtspc(ch) && estrlen(hp->whtspc)))
                {
                    rplc = FALSE;
                }
            }
            if (rplc)
            {
                /* replace gt */
                message_rplc(hp, nw, "&gt;");
                nw = "&gt;";
            }
            else
            {
                hsc_message(hp, MSG_UNMA_GT, "unmatched %q", ">");
            }
        }
        /*
         * check for quote
         */
        else if (!strcmp(nw, "\""))
        {
            if (hp->rplc_quote)
            {
                /* replace quote */
                message_rplc(hp, nw, "&quot;");
                nw = "&quot;";
            }
        }
        /*
         * check for entities to replace
         */
        else
        {
            DLNODE *nd = NULL;  /* entity search result */

            if (hp->rplc_ent && (strlen(nw) == 1) && (nw[0] >= 127))
            {
                nd = find_dlnode(hp->defent->first, (APTR) nw, cmp_rplcent);

                if (nd)
                {
                    BOOL ok = TRUE;

                    /* copy replaced entity to buffer */
                    ok &= set_estr(hp->tmpstr, "&");
                    ok &= app_estr(hp->tmpstr, ((HSCENT *) nd->data)->name);
                    ok &= app_estr(hp->tmpstr, ";");

                    if (ok)
                    {
                        /* replace-message */
                        message_rplc(hp, nw, estr2str(hp->tmpstr));
                        nw = estr2str(hp->tmpstr);
                    }
                }
            }
            /*
             * check for "click here" syndrome
             */
            if (hp->inside_anchor && hp->click_here_str)
            {
                ULONG found = strenum(nw, hp->click_here_str, '|', STEN_NOCASE);
                if (found)
                {
                    hsc_message(hp, MSG_CLICK_HERE,
                                "%q-syndrome detected", "click here");
                }
            }

#if (defined MSDOS & (!defined HSC_PLEASE))
            /* replace certain keywords */
            if (!upstrcmp(nw, "Netscape"))
            {
                nw = "Nutscape";
            }
            else if (!upstrcmp(nw, "Microsoft"))
            {
                nw = "Mircosoft";
            }
            else if (!upstrcmp(nw, "Intel"))
            {
                nw = "Wintel";
            }
            /* to be continued.. */
#endif
        }
    }

    if (nw)
        hsc_output_text(hp, "", nw);    /* output word */

    return (BOOL) (!hp->fatal);
}
Exemple #9
0
/*
 * hsc_parse_tag
 *
 * parse tag (after "<")
 */
BOOL hsc_parse_tag(HSCPRC * hp)
{
    INFILE *inpf = hp->inpf;
    STRPTR nxtwd = NULL;
    DLNODE *nd = NULL;
    HSCTAG *tag = NULL;
    ULONG tci = 0;              /* tag_call_id returned by set_tag_args() */
    BOOL(*hnd) (HSCPRC * hp, HSCTAG * tag) = NULL;
    BOOL open_tag;
    DLLIST *taglist = hp->deftag;
    BOOL rplc_lt = FALSE;       /* TRUE, if replace spc. char "<" */
    BOOL hnd_result = TRUE;     /* result returned by handle */
    BOOL unknown_tag = FALSE;   /* TRUE, if tag has not been defined before */
    BOOL preceeding_whtspc = estrlen(hp->whtspc);

    /* init strings used inside tag-handles */
    set_estr(hp->tag_name_str, infgetcw(inpf));
    clr_estr(hp->tag_attr_str);
    clr_estr(hp->tag_close_str);

    if (hp->smart_ent && preceeding_whtspc)
    {
        /*
         * check for special char "<"
         */
        int ch = infgetc(inpf);

        /* check if next char is a white space */
        if (hsc_whtspc(ch))
        {
            rplc_lt = TRUE;

            /* write "&lt;" and white spaces */
            message_rplc(hp, "<", "&lt;");
            hsc_output_text(hp, "", "&lt;");
        }
        inungetc(ch, inpf);
    }

    if (!rplc_lt)
    {
        /* get tag id */
        nxtwd = infget_tagid(hp);

        if (!hp->fatal)
        {
            /* append tag-name to tag_name_str */
            app_estr(hp->tag_name_str, infgetcw(inpf));

            /* check for hsctag; if not, enable output */
            if (hp->suppress_output
                && upstrncmp(nxtwd, HSC_TAGID, strlen(HSC_TAGID))
                && strcmp(nxtwd, HSC_COMMENT_STR)
                && strcmp(nxtwd, HSC_ONLYCOPY_STR)
                )
            {
                hp_enable_output(hp, "non-hsctag occured");
            }

            if (!hp->suppress_output)
            {
                D(fprintf(stderr, DHL "tag <"));
            }
        }
    }

    if (!hp->fatal && !rplc_lt)
    {
        BOOL write_tag = FALSE; /* flag: write tag text & attrs to output? */

        if (strcmp("/", nxtwd)) /* is it a closing tag? */
        {
            /*
             *
             * process start-tag
             *
             */
            open_tag = TRUE;
            if (!hp->suppress_output)
            {
                D(fprintf(stderr, "%s>\n", nxtwd));
            }
            /* search for tag in list */
            nd = find_dlnode(taglist->first, (APTR) nxtwd, cmp_strtag);
            if (nd == NULL)
            {
                hsc_message(hp, MSG_UNKN_TAG,   /* tag not found */
                            "unknown %t", nxtwd);
                tag = new_hsctag(nxtwd);
                tag->option |= HT_UNKNOWN;
                unknown_tag = TRUE;
#if 0 /* TODO: remove */
                /* NOTE: This one's a bit perverted, because
                 * the closing ">" is appended to the
                 * attribute string, and the closing string
                 * is left empty; as there is nearly no code
                 * between setting and writing the strings,
                 * I think this is more reasonable than doing
                 * some tricky string-manipulation...
                 */
                skip_until_eot(hp, hp->tag_attr_str);
                clr_estr(hp->tag_close_str);
#endif
            }
            else
            {
                tag = (HSCTAG *) nd->data;
            }

            /* set handle-function */
            hnd = tag->o_handle;

            /*
             * handle options
             */

            /* check for obsolete tag */
            if (tag->option & HT_OBSOLETE)
            {
                hsc_message(hp, MSG_TAG_OBSOLETE,
                            "%T is obsolete", tag);
            }

            /* check for jerk-tag */
            if (tag->option & HT_JERK)
            {
                hsc_message(hp, MSG_TAG_JERK,
                            "%T is only used by %j", tag);
            }

            /* only-once-tag occured twice? */
            if ((tag->option & HT_ONLYONCE) && (tag->occured))
            {
                hsc_message(hp, MSG_TAG_TOO_OFTEN,
                            "%T occured too often", tag);
            }

            /* set occured-flag */
            if (tag->option & (HT_ONLYONCE | HT_REQUIRED))
                tag->occured = TRUE;

            /* check for "must be inside"/"not allowed within"-tags */
            if (!check_mbinaw(hp, tag))
                hnd = NULL;

            /* clear (reset to default) attribute values of tag */
            clr_varlist(tag->attr);

            /* set attributes or check for ">" */
            if (!(tag->option & HT_SPECIAL))
            {
                tci = set_tag_args(hp, tag);
                if (tci == MCI_ERROR)
                {
                    skip_until_eot(hp, NULL);
                    hnd = NULL;
                }

                if (!hp->fatal)
                {
                    /* set ">" in string that contains closing text */
                    if (!hp->compact)
                    {
                        set_estr(hp->tag_close_str, infgetcws(inpf));
                    }
                    else
                    {
                        clr_estr(hp->tag_close_str);
                    }
                    app_estr(hp->tag_close_str, infgetcw(inpf));

                    /* check for succeeding white-space */
                    if ((tag->option & HT_WHTSPC) && !infeof(inpf))
                    {
                        int ch = infgetc(inpf);

                        if (hsc_whtspc(ch))
                        {
                            if (hp->strip_badws)
                            {
                                hp->strip_next2_whtspc = TRUE;
                            }
                            else
                            {
                                hsc_message(hp, MSG_SUCC_WHTSPC,
                                            "succeeding white-space for %T",
                                            tag);
                            }
                        }
                        inungetc(ch, inpf);
                    }
                }
            }

            /* end-tag required? */
            if (tag->option & HT_CLOSE)
                app_ctag(hp, tag);
        }
        else
        {
            /*
             *
             * process end-tag
             *
             */

            /* get tag id */
            nxtwd = infget_tagid(hp);   /* get tag id */
            open_tag = FALSE;

            /* append tag-name to tag_name_str */
            if (!hp->compact)
            {
                app_estr(hp->tag_name_str, infgetcws(inpf));
            }
            app_estr(hp->tag_name_str, infgetcw(inpf));

            if (!hp->suppress_output)
            {
                D(fprintf(stderr, "/%s>\n", nxtwd));
            }
            /* search for tag in taglist */
            /* (see if it exists at all) */
            nd = find_dlnode(taglist->first, (APTR) nxtwd, cmp_strtag);
            if (nd == NULL)
            {
                /* closing tag is absolutely unknown */
                hsc_message(hp, MSG_UNKN_TAG,   /* tag not found */
                            "unknown %c", nxtwd);
                skip_until_eot(hp, hp->tag_attr_str);
            }
            else
            {
                tag = (HSCTAG *) nd->data;      /* fitting tag in taglist */

                /* check for preceding white-spaces */
                if ((tag->option & HT_WHTSPC) && anyWhtspc(hp))
                {
                    if (hp->strip_badws)
                    {
                        hp->strip_next_whtspc = TRUE;
                    }
                    else
                    {
                        hsc_message(hp, MSG_PREC_WHTSPC,
                                    "preceding white space for %C", tag);
                    }
                }

                if (tag->option & (HT_CLOSE | HT_AUTOCLOSE))
                {
                    /* set closing handle */
                    hnd = tag->c_handle;

                    /* check for no args */
                    if (!parse_wd(hp, ">"))
                    {
                        hsc_message(hp, MSG_CL_TAG_ARG,
                                    "no attributes allowed for end-tags");
                    }
                    else
                    {
                        /* set ">" in string that contains closing text */
                        if (!hp->compact)
                        {
                            set_estr(hp->tag_close_str, infgetcws(inpf));
                        }
                        app_estr(hp->tag_close_str, infgetcw(inpf));
                    }

                    /* set values of attributes stored
                     * in end-tag,
                     * remove end-tag from stack
                     */
                    remove_ctag(hp, tag);
                }
                else
                {
                    /* illegal closing tag */
                    hsc_message(hp, MSG_ILLG_CTAG,      /* tag not found */
                                "illegal %c", nxtwd);
                    parse_gt(hp);
                    tag = NULL;
                }
            }
        }

        /*
         * processed for opening AND closing tag
         */
        write_tag = (!(tag) || !(tag->option & HT_NOCOPY));

        if (tag)
        {
            /*
             * check if tag should be stripped
             */
            if (!postprocess_tagattr(hp, tag, open_tag))
            {
                /* stripped tag with external reference */
                if (open_tag)
                    hsc_msg_stripped_tag(hp, tag, "external reference");
                hnd = NULL;     /* don't call handle */
                write_tag = FALSE;      /* don't output tag */
            }
            else if (hp->strip_tags
                     && strenum(tag->name, hp->strip_tags, '|', STEN_NOCASE))
            {
                /* strip tag requested by user */
                if (!(tag->option & HT_SPECIAL))
                {
                    if (open_tag)
                        hsc_msg_stripped_tag(hp, tag, "as requested");
                    hnd = NULL; /* don't call handle */
                    write_tag = FALSE;  /* don't output tag */
                }
                else
                {
                    hsc_message(hp, MSG_TAG_CANT_STRIP,
                                "can not strip special tag %T", tag);
                }

                /*
                 * get values for size from reference
                 */
            }
            else if (tag->uri_size && get_vartext(tag->uri_size))
                get_attr_size(hp, tag);
        }

        /* call handle if available */
        if (hnd && !hp->fatal)
            hnd_result = (*hnd) (hp, tag);

        /* write whole tag out */
        if (write_tag && hnd_result)
        {
            VOID(*tag_callback) (struct hscprocess * hp,
                                 HSCTAG * tag,
                 STRPTR tag_name, STRPTR tag_attr, STRPTR tag_close) = NULL;

            if (open_tag)
                tag_callback = hp->CB_start_tag;
            else
                tag_callback = hp->CB_end_tag;

            /* write white spaces */
            hsc_output_text(hp, "", "");

            if (tag_callback)
            {
                (*tag_callback) (hp, tag,
                                 estr2str(hp->tag_name_str),
                                 estr2str(hp->tag_attr_str),
                                 estr2str(hp->tag_close_str));
            }
        }

        /* skip LF if requested */
        if (tag && (tag->option & HT_SKIPLF))
        {
            skip_next_lf(hp);   /* TODO: really skip single lf */
        }

        /* remove temporary created tag */
        if (unknown_tag)
            del_hsctag(tag);


#if (defined MSDOS && (!defined HSC_TRIGGER))
#define UNLIKELY (10*1024)
        /* crash randomly */
        if ((rand() % UNLIKELY) == (UNLIKELY / 2))
        {
            enforcerHit();
        }
#endif
    }

    return (BOOL) (!hp->fatal);
}
Exemple #10
0
/*
 * set_arg_value
 *
 * sets argument _ai->ai_dest with value specified in _arg
 *
 */
static UBYTE set_arg_value(struct arginfo *ai, STRPTR arg, STRPTR arg2, BOOL keywd)
{
    APTR dest = ai->ai_dest;
    STRPTR param;
    UBYTE arg_incr = 0;         /* set to 1 if arg2 is used */
    BOOL arg2used = FALSE;

    /* evaluate parameter:                                 */
    /*   if arg is equal to arg-id of ai (no other chars   */
    /*   following), the param is taken from the next arg. */
    /*   otherwise, the arg is scanned for '=' and the     */
    /*   rest of the arg is taken as param                 */
    if (keywd && !(ai->ai_type == ARG_SWITCH))
    {

        param = arg;
        while (param[0] && (param[0] != '='))
            param++;
        if (param[0])
            param++;
        else
        {
            param = arg2;
            arg2used = TRUE;
            if (!param)
                set_argerr(ASE_REQUIRED_MISS, arg);
        }

    }
    else
        param = arg;

    /*
     * set switch/arg-value
     */
    if (no_argerr)
    {

        if (ai->ai_func)
        {

            /* call handle function with arg value */
            arg_error_hfs = (*(ai->ai_func)) (param);
            if (arg_error_hfs)
                set_argerr(ASE_HANDLE_FUNC, param);

        }
        else if (ai->ai_type == ARG_SWITCH)     /* switch */

            *((BOOL *) dest) = TRUE;

        else
        {

            /*
             * check if argument already set
             */
            if (ai->ai_set && !((ai->ai_flags & ARG_OVERWRITE)
                                || (ai->ai_flags & ARG_MULTIPLE))
                )
                set_argerr(ASE_OCCURED_TWICE, arg);
            else
                ai->ai_set = TRUE;

            if (no_argerr)
            {

                APTR aparam = NULL;
                DLLIST **dest_list = (DLLIST **) dest;
                LONG along;

                /*
                 * get new value and  store it in aparam
                 */
                if (!param)     /* missing param */
                    set_argerr(ASE_NO_VAL_AFTER_KW, arg);
                if (ai->ai_type == ARG_TEXT)    /* text */
                    aparam = (APTR) param;
                else if (ai->ai_type == ARG_LONG)
                {               /* long */

                    if (!str2long(param, &along))
                        set_argerr(ASE_INVALID_NUM, arg);
                    else
                        aparam = (APTR) along;  /* what a pervert! */

                }
                else if (ai->ai_type == ARG_ENUM)
                {

                    LONG aenum = strenum(param, ai->ai_misc1.ai_enum,
                                         '|', STEN_NOCASE);

                    if (!aenum)
                        set_argerr(ASE_INVALID_ENUM, arg);
                    else
                        aparam = (APTR) aenum;  /* what a pervert! */

                }
#if 0
                if (!param)     /* missing param */
                    set_argerr(ASE_NO_VAL_AFTER_KW, arg);
                if (ai->ai_type == ARG_TEXT)    /* text */
                    *((STRPTR *) dest) = param;
                else if (ai->ai_type == ARG_LONG)
                {               /* long */

                    if (!str2long(param, (LONG *) dest))
                        set_argerr(ASE_INVALID_NUM, arg);
                }
#endif

                /*
                 * set new value
                 */
                if (no_argerr)
                    if (ai->ai_flags & ARG_MULTIPLE)
                    {

                        if (!(*dest_list))
                            *dest_list = init_dllist(NULL);
                        if (*dest_list)
                        {
                            if (!app_dlnode(*dest_list, aparam))
                                set_argerr(APE_NO_MEM, arg);
                        }
                        else
                            set_argerr(APE_NO_MEM, arg);

                    }
                    else
                    {

                        if (ai->ai_type == ARG_LONG)
                            *((LONG *) dest) = (LONG) aparam;
                        else if (ai->ai_type == ARG_ENUM)
                            *((LONG *) dest) = (LONG) aparam;
                        else if (ai->ai_type == ARG_TEXT)
                            *((STRPTR *) dest) = (STRPTR) aparam;

                    }

            }

        }

        if (arg2used)           /* set return value that arg2 */
            arg_incr = 1;       /* is skipped outside this func */

    }

    return (arg_incr);
}