Example DEMIME64.PRT
; DEMIME64
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; This program decodes the specified file (encoded according to Mime Base 64)
; into the original file. If the file exists, it is overwritten;
; only single section files are allowed.

; Implicit parameters: input and output are NULL
;!proteus -z

IF ISEMPTY(ARGV(5))
  CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) \
            " [filename [destination]]"
  CONSOLELN ""
  CONSOLELN "Purpose: decode a Mime Base 64-encoded file."
  CONSOLELN "If destination file exists, it is overwritten."
  CONSOLELN "If \"destination\" is specified, that name is " \
            "used for destination."
  CONSOLELN "Only single section files are allowed."
  ABORT 0
FI
H = FOPEN(ARGV(5), 1)
IF EQ(H, -1)
  CONSOLELN "File \"" ARGV(5) "\" not found."
  ABORT 1
FI
Found = 0
Status = 0
B64Par = VECCREATE(0, 0, 0)
WHILE NOT(FEOF(H))
  ; Find two lines starting with "Content"
  S = FREADLN(H)
  IF IMATCH(S, "Content*")
    IF ISNOTEMPTY(ARGV(6))
      DstName = ARGV(6)
    ELSE
      REXIMATCH(S, "name=")
      DstName = RESTFROM(S, ADD(R_START, R_LENGTH))
      ALLTRIM(@DstName, " ")
      STRIPQUOTES(@DstName)
    FI
    S = FREADLN(H)
    IF IMATCH(S, "Content*")
      ; Find the first non-empty line
      S = ""
      WHILE AND(NOT(FEOF(H)), ISEMPTY(S))
        S = FREADLN(H)
      LOOP
      IF FEOF(H)
        CONSOLELN "Unexpected end of file in \"" ARGV(5) "\"."
        ABORT 1
      FI
      HD = FOPEN(DstName, 26)
      IF EQ(HD, -1)
        CONSOLELN "Could not create \"" DstName "\"."
        ABORT 1
      FI
      WHILE ISNOTEMPTY(S)
        DEMIME64(@S, @Status, B64Par)
        FWRITE(HD, S)
        SWITCH Status
          ON -2
            CONSOLELN "Error decoding file \"" ARGV(5) "\"."
            ABORT 0
          ON 1
            BREAK
          ON 0
            S = FREADLN(H)
        OFF
      LOOP
      Found = 1
      BREAK
    FI
  FI
LOOP
VECFREE(B64Par)
FCLOSE(H)
IF Found
  CONSOLELN "File \"" DstName "\" created."
ELSE
  CONSOLELN "No Mime Base 64 section found into \"" ARGV(5) "\"."
  ABORT 1
FI
ABORT 0
Samples index Next example Previous example Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell