Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Code "Tab Stripper" Program

Status
Not open for further replies.

Mike - K8LH

Well-Known Member
I use tabs in my source files but the forum software doesn't like them in the code you place between <code> tags in a post. Instead of manually typing in spaces to maintain a 'clean' format for posted code I decided to finally write a little program to do it for me using the 'free' JustBASIC compiler.

The program doesn't alter your source file. It simply prints each source line to the console after replacing tabs with spaces. Select and copy the cleaned up code from the console then paste it via the clipboard between code tags in your forum post.

Enjoy, Mike

Code:
'
'  Forum Code-Tag-Fix v1.1 by Mike McLaren, K8LH
'
'  replaces <tab> characters with spaces (tabs = 8).  
'  does not alter your source file.
'
'  Instructions
'
'  1 - select your source file from the File Dialog
'  2 - select output text displayed in console window
'  3 - copy to clipboard using <ctrl-C> or <edit> <copy>
'  4 - paste between code tags in your Forum post
'
'  JustBASIC v1.01
'

   filedialog "Source File?", "*.asm", fileName$

   if fileName$ <> "" then
     open fileName$ for input as #f
     while eof(#f) > -1
       line input #f, aLine$ : hpos=1
       for x = 1 to len(aLine$)
         if (mid$(aLine$,x,1)<>chr$(9)) then
           print mid$(aLine$,x,1); : hpos=hpos+1
         else
           while hpos MOD 8 <> 0
             print " "; : hpos=hpos+1
           wend
           print " "; : hpos=hpos+1
         end if
       next x
       print
     wend
     close #f
   end if
   end
 
Mike,

The code tag expands tabs correctly for me. I have tabs set to 8 and this maybe why. I do however like the look of that free basic and am downloading it as I type.

Mike.
 
That's interesting Mike.

Here's unprocessed code with tabs = 8;
Code:
;******************************************************************
;*                                                                   *
;*    Interrupt Service Routine                      *
;*                                                                *
;*    TMR2 interrupts generated every 104-usec              *
;*                                  *
;*  - process RS-232 TX & RX each interrupt (9600 baud)          *
;*  - process Speaker/Keyer timers every 8th interrupt (1200 hz)  *
;*                                                                *
;******************************************************************

    org    0x0004

ISR    movwf    W_ISR        ;save W-reg              |B0
    swapf    STATUS,W    ;doesn't change STATUS bits      |B0
    movwf    S_ISR        ;save STATUS reg          |B0
    clrf    STATUS        ;bank 0                  |B0
    movf    PCLATH,W    ;get PCLATH              |B0
    movwf    P_ISR        ;save PCLATH              |B0
    clrf    PCLATH        ;ISR is in bank 0          |B0
And here's the same code run through my Tab Stripper;
Code:
;******************************************************************
;*                                                                *
;*    Interrupt Service Routine                                   *
;*                                                                *
;*    TMR2 interrupts generated every 104-usec                    *
;*                                                                *
;*  - process RS-232 TX & RX each interrupt (9600 baud)           *
;*  - process Speaker/Keyer timers every 8th interrupt (1200 hz)  *
;*                                                                *
;******************************************************************

        org     0x0004

ISR     movwf   W_ISR           ;save W-reg                       |B0
        swapf   STATUS,W        ;doesn't change STATUS bits       |B0
        movwf   S_ISR           ;save STATUS reg                  |B0
        clrf    STATUS          ;bank 0                           |B0
        movf    PCLATH,W        ;get PCLATH                       |B0
        movwf   P_ISR           ;save PCLATH                      |B0
        clrf    PCLATH          ;ISR is in bank 0                 |B0
Wierd, huh?

I hope you enjoy the JustBASIC compiler. That's what I used to write the stand-alone SPBRG Calc application and other stuff (below).

Regards, Mike
 

Attachments

  • Button Console.JPG
    Button Console.JPG
    14.2 KB · Views: 145
I only tried the preview. Maybe it's different when posted.
Code:
interupt	movwf	int_work
		swapf	STATUS,W
		movwf	int_status;		status is nibble swaped
		bcf	STATUS,RP0;			+1 = 6
		bcf	STATUS,RP1;			+1 = 7
		movfw	PCLATH;				+1 = 8
		movwf	int_pclath;			+1 = 9
		clrf	PCLATH;				+1 = 10
		movfw	FSR;				+1 = 11
		movwf	int_fsr;			+1 = 12
That was with PFE - Programmers file editor.

Now with MPLAB
Code:
		line with 2 tabs
                line with 16 spaces

No idea why it's different when I post.

Mike
Edit, changed the above to real code.
 
Last edited:
It looks like you only have one or two leading tabs per line in each example. Perhaps it has something to do with mutiple tabbed columns or perhaps it's my FireFox browser. Who knows?
 
Not to change the part about expanding tabs. But the JustBASIC. I had to check it out.

It looks like it is a cool language for windows. But it is not compiled code. So you must load their software on your computer to use the programs (source or their output file). I will see if the $30 liberty basic gets around that.

For $30 would be great for scripting if you can send a stand alone program with a runtime engine or real binary. And not a lot of bloat. Like O'basic, which was a great idea (but the bloat).

I use PowerBASIC. And they do milk you for the money. But it is a good product if you need to write Windows programs.
 
You're right about "bloat". I used IE Express Installer to combine the SPBRG Calculator program and JustBASIC run-time files into a single-file executable. It's about 1-Mbyte in size.

JustBASIC was also the only "free" language I came across that had serial port support.

**broken link removed**
 
Last edited:
I once used a very good "free" open source basic language compiler called XBLite.
I know it supports the serial port, as my program had to use it and work with XP or win98.
see: **broken link removed**
It produced a good compact executable and only needed a few small dlls to run.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top