• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X PCB Editor
  3. need tips and examples for reading a text file

Stats

  • Replies 4
  • Subscribers 158
  • Views 15572
  • Members are here 0
More Content

need tips and examples for reading a text file

archive
archive over 17 years ago

I'm writing some axlSkill that reads the variants.lst file.
The statement xx = infile("variants.lst") opens the file for reading.
The statement gets(s xx) gets the first line written to a string object s.
Now I'm trying to use a getchar call to look at each character of the string and then decide what to do with the line. Specifically I'm looking for strings that start with "(" (for example).
I try getchar(s 1) == "(" hoping for a return value of t. But even though the first character of string s is ( the getchar call returns nil.
I'm guessing there is an easy way to parse a string and I haven't found it.
Help?


Originally posted in cdnusers.org by AshCan
  • Sign in to reply
  • Cancel
  • archive
    archive over 17 years ago

    getchar returns a character not a string so do
    getchar(s 1) == '\(

    also since a paren is special in Skill it needs to be escaped by a backslash, to match a 'd' all you would need is a 'd


    Originally posted in cdnusers.org by fxf
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • archive
    archive over 17 years ago

    Some other options:
    1) use substring instead of getchar.
    substring(s 1 1) == "("
    2) convert the getchar result to a string
    get_string(getchar(s 1)) == "("


    Originally posted in cdnusers.org by Randy R.
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • archive
    archive over 17 years ago

    Thanks! Another - even more general - question.
    I've got a major brain freeze going here.

    I'm using a while to read a text file (the variants.lst file). In this example I look at the first character of each line and  see if it is an open paren.

         xx = infile("variants.lst")
         count = 0
         while(xx
             gets(s xx)
             lineno = count++
             if(substring(s 1 1)=="("
                then
                printf("Line #%d starts with a \"(\"\n" lineno)
                else
                printf("Line #%d doesn't start with a \"(\"\n" lineno)
             ); end if
         ); end while

    Problem is that after the last line of the infile is read I get:
    E- *Error* substring:
    argument #1 should be either a string or a symbol (type template = "Sx") - nil

    The last gets statement has returned a string that is nil.

    If I put in an if loop  if(s != nil  after the gets statement the while loop goes forever. How do I evaluate the result of the gets statement before trying to use it?


    Originally posted in cdnusers.org by AshCan
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • archive
    archive over 17 years ago

    See if this works:
    if( xx = infile("variants.lst") ; make sure we can open the file
    then
    count = 0
    while( gets(s xx)
    lineno = count++
    if(substring(s 1 1)=="("
    then
    printf("Line #%d starts with a \"(\"\n" lineno)
    else
    printf("Line #%d doesn't start with a \"(\"\n" lineno)
    ); end if
    ); end while
    close(xx); close out the input port
    ); end if


    Originally posted in cdnusers.org by Randy R.
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information